Elisa Media Center 0.5.3 Release
Dear Elisa users, This mail announces the release of Elisa Media Center 0.5.3 codenamed Attraction. Installers and sources can be downloaded from http://elisa.fluendo.com/download/ Features added since 0.5.2: - iPod support has been improved: it shows the available Artists then the Albums of the selected artist. - Pluggable devices support on Linux has been fixed: USB hard drives, iPods and such are browsable from Elisa - The Music section hierarchy has been reworked and now starts with Music Library containing entries to browse your music collection by albums, artists, genres, release date, or folders - A new playlists entry has been added to the Music section containing automatically created playlists: Most Listened Tracks, Most Recently Added Tracks, Most Recently Listened Tracks - Shoutcast radio station names are now automatically cleaned up based on custom heuristics - GNOME screensaver is automatically deactivated when Elisa is playing - Important improvements were made in the performance department most notably on all the list and grid widgets There are still some known issues in this release and we are working on solving them as fast as possible: - Audio Visualization does not work on Windows - Audio CD are not detected - DAAP support missing Have a nice day, The Elisa team Elisa 0.5.3 Attraction This is Elisa 0.5.3, second release of the 0.5 branch. Features added since 0.5.2: - iPod support has been improved: it shows the available Artists then the Albums of the selected artist. - Pluggable devices support on Linux has been fixed: USB hard drives, iPods and such are browsable from Elisa - The Music section hierarchy has been reworked and now starts with Music Library containing entries to browse your music collection by albums, artists, genres, release date, or folders - A new playlists entry has been added to the Music section containing automatically created playlists: Most Listened Tracks, Most Recently Added Tracks, Most Recently Listened Tracks - Shoutcast radio station names are now automatically cleaned up based on custom heuristics - GNOME screensaver is automatically deactivated when Elisa is playing - Important improvements were made in the performance department most notably on all the list and grid widgets Bugs fixed since 0.5.2: - 250494 filesystem browsing of localized version - 250805 Sounds For A Video Plays After Elisa Quits - 251585 [Win32] Elisa (re)deadlocks at exit - 251880 Metadata slave not restarted on ConnectionLost - 232958 local media fails on wrong encoding in filename - 233757 .srt subtitles are not shown - 244625 double click messes with history - 249070 [win32] closing the window does not close elisa - 249527 poblesec history management improvements - 249896 media scanner issue with empty tags - 250780 Locking of the Pigment rendering thread - 250787 Leaked controllers causing performance issues - 232631 Media scanning progress reports - 249145 Apple remote does not work for Imac and macbook on windows - 250785 pigment.graph.drawable slowness - 250791 Continued list and grid widgets scrolling slowness - 246245 [win32] EXIT button press on the remote freezes Elisa - 249392 Warnings when trying to add directories - 248758 hal plugin doesn't mount devices anymore when they are hotplugged - 249066 [win32] hide crash report of sub processes - 249130 new lirc_input provider - 251129 elisa.core.pattern_matcher.PatternMatcher matches things it shouldn't Download You can find source releases of Elisa in the download directory: http://elisa.fluendo.com/download Elisa Homepage More details can be found on the project's website: http://elisa.fluendo.com Support and Bugs We use an issue tracker for bug reports and feature requests: https://bugs.launchpad.net/elisa/+filebug Developers All code is in a Bazaar branch and can be checked out from there. It is hosted on Launchpad: https://code.launchpad.net/elisa Contributors to this release: - Alessandro Decina - Benjamin Kampmann - David McLeod - Florian Boucault - Gernot Klimscha - Guido Amoruso - Gunnar Holmberg - Jesús Corrius - Joshua Eichen - Lionel Martin - Olivier Tilloy - Philippe Normand -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Attack a sacred Python Cow
On Jul 27, 10:32 pm, Terry Reedy [EMAIL PROTECTED] wrote: Derek Martin wrote: Furthermore, as you described, defining the function within the scope of a class binds a name to the function and then makes it a method of the class. Once that happens, *the function has become a method*. If you mean that a user-defined function object becomes a different class of object when bound to a class attribute name, that is wrong. Once a function, always a function. It may be called an 'instance method' but it is still a function. Any function object can be an attribute of multiple classes, without inheritance, or of none. When a function attribute is accessed via an instance of the class, it is *wrapped* with a bound method object that basically consists of references to the function and instance. When the 'bound method' is called, the instance is inserted in front of the other arguments to be matched with the first parameter. In 2.0, functions accessed through the class were rather uselessly wrapped as an 'unbound method', but those wrappers have been discarded in 3.0. To be perfectly honest, the idea that an object method can be defined outside the scope of an object (i.e. where the code has no reason to have any knowledge of the object) seems kind of gross to me... I happen to like the simplicity that def statements (and lambda expressions) create function objects. Period. ... It does indeed -- it does more than imply. It states outright that the function is defined within the namespace of that object, True. and as such that it is inherently part of that object. False. That does not follow. Python objects generally exist independently of each other. Think of them as existing in a nameless dataspace if you want. Collection/container objects collect/contain references to their members, just as a club roster does, but they only metaphorically 'contain' their members. Any object can be a member of any number of collections, just as humans can join any number of clubs and groups. In mathematical set theory, membership is also non-exclusive. So why should it need to be explicitly told about the object of which it is already a part? Because it is not a 'part' of a class in the sense you seem to mean. What is true is that functions have a read-only reference to the global namespace of the module in which they are defined. But they do not have to be a member of that namespace. Terry Jan Reedy This whole discussion reminds me of discussions I saw on comp.lang.ada several years ago when I had a passing interest in Ada. My memory on this is a bit fuzzy, but IFIRC Ada 95 did not support standard OO dot syntax of the form myObject.myFunction(args) Instead, myfunction was just a regular function that took myObject and args as arguments. It was called as myFunction(myObject, args) It was put into the appropriate package or subpackage where it belonged rather than in a class definition. Namespaces were defined by a package hierarchy rather than by classes (which is actually more logical, but that's another topic). Well, so many people demanded the dot notation that it was finally implemented in Ada 2005. So now user can use the more familiar dot notation, but my understanding is that it is just syntactic sugar for the old notation. So when Python people go out of their way to point out that class methods in Python are implemented as regular functions, that seems fairly obvious to me -- but perhaps only because of my passing familiarity with Ada. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 27, 10:55 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 26, 6:47 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 24, 5:01 am, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* The reason is quite simple. Python is not truly an object-oriented language. It's sufficiently close to fool those accustomed to OO ways of doing things, but it doesn't force you to do things that way. You still have the choice. An implicit self would take away that choice. By that logic, C++ is not OO. Yes it is, because it has this. You mean the keyword this? It's just a feature. How does that make a difference on being or not being OO? Because it was one of the things the OP was complaining about (see above). Wrong. What the OP complains about has no relevance on what makes a language OO or not. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 27, 5:14 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sat, 26 Jul 2008 15:58:16 -0700, Carl Banks wrote: On Jul 26, 5:07 pm, Terry Reedy [EMAIL PROTECTED] wrote: Whether or not one should write 'if x' or 'if x != 0' [typo corrected] depends on whether one means the general 'if x is any non-null object for which bool(x) == True' or the specific 'if x is anything other than numeric zero'. The two are not equivalent. Ditto for the length example. Can you think of any use cases for the former? And I mean something where it can't be boiled down to a simple explicit test for the sorts of arguments you're expecting; something that really takes advantage of the all objects are either true or false paradigm. But why do you need the explicit test? I asked you first, buddy. [snip attempt to reverse argument] The best thing I can come up with out of my mind is cases where you want to check for zero or an empty sequence, and you want to accept None as an alternative negative as well. But that's pretty weak. You might find it pretty weak, but I find it a wonderful, powerful feature. Powerful? You've got to be kidding me. If I have a function create_object(name) where one creates an anonymous object by passing an empty string, behold! now I can also create an anonymous object by passing None. You call that powerful? I call it simple convenience, and not something that we'd suffer much for for not having. But it's still the one thing I can think of that can't be replaced by a simple explicit test. I recently wrote a method that sequentially calls one function after another with the same argument, looking for the first function that claims a match by returning a non-false result. It looked something like this: def match(arg, *functions): for func in functions: if func(arg): return func I wanted the function itself, not the result of calling the function. I didn't care what the result was, only that it was something (indicates a match) or nothing (no match). In one application, the functions might return integers or floats; in another they might return strings. In a third, they might return re match objects or None. I don't need to care, because my code doesn't make any assumptions about the type of the result. Couldn't you write the function to return None on no match, then test if func(arg) is None? That way would seem a lot more natural to me. As an added bonus, you don't have to return some sort of wrapped object if suddenly you decide that you want to match a zero. Sorry, can't give it credit for the use case I was asking for. I want something where if x will do but a simple explicit test won't. Carl Bannks -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 27, 10:55 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 26, 6:47 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 24, 5:01 am, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* The reason is quite simple. Python is not truly an object-oriented language. It's sufficiently close to fool those accustomed to OO ways of doing things, but it doesn't force you to do things that way. You still have the choice. An implicit self would take away that choice. By that logic, C++ is not OO. Yes it is, because it has this. You mean the keyword this? It's just a feature. How does that make a difference on being or not being OO? Because it was one of the things the OP was complaining about (see above). Wrong. Reread what the OP said. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python program as daemon?
Lawrence D'Oliveiro schrieb: In message [EMAIL PROTECTED], sturlamolden wrote: Basically it forks twice ... What's the advantage of forking twice over forking once and calling setsid? http://code.activestate.com/recipes/278731/ See the comments. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
castironpi [EMAIL PROTECTED] writes: I think you misunderstood him. What he wants is to write class foo: def bar(arg): self.whatever = arg + 1 instead of class foo: def bar(self, arg) self.whatever = arg + 1 so 'self' should *automatically* only be inserted in the function declaration, and *manually* be typed for attributes. There's a further advantage: class A: def get_auxclass( self, b, c ): class B: def auxmeth( self2, d, e ): #here, ... return B In auxmeth, self would refer to the B instance. In get_auxclass, it would refer to the A instance. If you wanted to access the A instance in auxmeth, you'd have to use class A: def get_auxclass(b, c ): a_inst = self class B: def auxmeth(d, e ): self # the B instance a_inst # the A instance return B This seems pretty natural to me (innermost scope takes precedence), and AFAIR this is also how it is done in Java. Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
We programming
Hi, Could someone suggest me better python modules for developing web programming related projects like web-pages download and uopload?? Thanks, Srini Explore your hobbies and interests. Go to http://in.promos.yahoo.com/groups/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Michael Torrie [EMAIL PROTECTED] writes: Colin J. Williams wrote: def fun( ., cat): I don't see the need for the comma in fun. It (the entire first variable!) is needed because a method object is constructed from a normal function object: def method(self,a,b): pass class MyClass(object): pass MyClass.testmethod=method That's precisely the same as if you'd defined method inside of the class to begin with. A function becomes a method when the lookup procedure in the instance object looks up the attribute and returns (from what I understand) essentially a closure that binds the instance to the first variable of the function. The result is known as a bound method, which is a callable object: instance=MyClass() instance.testmethod bound method MyClass.testmethod of __main__.instance object at xxx How would this work if there was not first parameter at all? In short, unlike what most of the implicit self advocates are saying, it's not just a simple change to the python parser to do this. It would require a change in the interpreter itself and how it deals with classes. Thats true. But out of curiosity: why is changing the interpreter such a bad thing? (If we suppose for now that the change itself is a good idea). Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Fri, 25 Jul 2008 08:08:57 -0700, Iain King wrote: On Jul 25, 3:39 pm, Suresh Pillai [EMAIL PROTECTED] wrote: That's a good comparison for the general question I posed. Thanks. Although I do believe lists are less than ideal here and a different data structure should be used. To be more specific to my case: As mentioned in my original post, I also have the specific condition that one does not know which nodes to turn ON until after all the probabilities are calculated (lets say we take the top m for example). In this case, the second and third will perform worse as the second one will require a remove from the list after the fact and the third will require another loop through the nodes to build the new list. So you need to loops through twice regardless? i.e. loop once to gather data on off nodes, do some calculation to work out what to turn on, then loop again to turn on the relevant nodes? If so, then I think the functions above remain the same, becoming the 2nd loop. Every iteration you do a first loop over the off_nodes (or them all for (1)) to gather the data on them, perform your calculation, and then perform one of the above functions (minus the setup code at the begining; basically starting at the 'for') as a second loop, with the goes_on function now returning a value based on the calculation (rather than the calculation itself as I had it). Performance should be similar. Iain If do I settle on an explicit loop to remove the nodes turned ON, then I realised this weekend that I could do this in the next iteration of the simulation (first loop above) and save some iteration overhead (the if checking will still be there of course). And thanks for pointing out that constructing a new list, for long lists, is faster than simple removal. It's obvious but I never really thought of it; good tip. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Bruno Desthuilliers [EMAIL PROTECTED] writes: The fact that a function is defined within a class statement doesn't imply any magic, it just creates a function object, bind it to a name, and make that object an attribute of the class. You have the very same result by defining the function outside the class statement and binding it within the class statement, by defining the function outside the class and binding it to the class outside the class statement, by binding the name to a lambda within the class statement etc... But why can't the current procedure to resolve method calls be changed to automatically define a 'self' variable in the scope of the called function, instead of binding its first argument? Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Russ P. [EMAIL PROTECTED] writes: The issue here has nothing to do with the inner workings of the Python interpreter. The issue is whether an arbitrary name such as self needs to be supplied by the programmer. All I am suggesting is that the programmer have the option of replacing self.member with simply .member, since the word self is arbitrary and unnecessary. Otherwise, everything would work *EXACTLY* the same as it does now. This would be a shallow syntactical change with no effect on the inner workings of Python, but it could significantly unclutter code in many instances. The fact that you seem to think it would change the inner functioning of Python just shows that you don't understand the proposal. So how would you translate this into a Python with implicit self, but without changing the procedure for method resolution? def will_be_a_method(self, a) # Do something with self and a class A: pass a = A() a.method = will_be_a_method It won't work unless you change the interpreter to magically insert a 'self' variable into the scope of a function when it is called as a method. I'm not saying that that's a bad thing, but it certainly requires some changes to Python's internals. Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Michael Torrie [EMAIL PROTECTED] writes: I think the biggest reason why an implicit self is bad is because it prevents monkey-patching of existing class objects. Right now I can add a new method to any existing class just with a simple attribute like so (adding a new function to an existing instance object isn't so simple, but ah well): def a(self, x, y): self.x = x self.y = y class Test(object): pass Test.setxy = a b = Test() b.setxy(4,4) print b.x, b.y If self was implicit, none of this would work. No, but it could work like this: def a(x, y): self.x = x self.y = y class Test(object): pass Test.setxy = a b = Test() # Still all the same until here # Since setxy is called as an instance method, it automatically # gets a 'self' variable and everything works nicely b.setxy(4,4) # This throws an exception, since self is undefined a(4,4) Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Fri, 25 Jul 2008 05:46:56 -0700, Iain King wrote: or 3. build a new list every iteration intead of deleting from the old one: while processing: new_off_list = [] for x in off_list: if goes_on(x): on_list.append(x) else: new_off_list.append(x) off_list = new_off_list generation += 1 Iain Or 4, since the order of my nodes doesn't matter: swap the node to be deleted with the last node in the list and then remove the last node of the list. This is the fastest to date, if using native structures, for low number nodes being deleted per cycle (def if only deleting one). -- http://mail.python.org/mailman/listinfo/python-list
Re: write unsigned integer 32 bits to socket
Michael Torrie was kind enough to say: Of course any time you send coherent numbers over the network, I highly recommend you use what's called network byte order. In C, you'd use the htonl() call, and then when pulling it off the wire on the other end you'd use ntohl(). If you don't then you will have problems when the endianness is different between the hosts. Standard convention (even in the MS word) is to use big-ending across the network. I'm sure python has some convention in the struct module for dealing with this. Not in the struct module; such functions are available in the socket module, and should be employed indeed. -- Alan Franzoni [EMAIL PROTECTED] - Remove .xyz from my email in order to contact me. - GPG Key Fingerprint: 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E -- http://mail.python.org/mailman/listinfo/python-list
Callback Python procedure from Delphi DLL
Hi! I have a component, and a tool in Delphi. I wanna call it from Python. I can implement all things I need into a Delphi generated DLL. It is ok, I can use this DLL from Python, but the DLL procedure needs a callback procedure to return the partially output, and needs a python passed variable to check terminate/abort signal. For example: procedure ProcessFiles(InputFiles : string; CallBackProc: ); export; begin CallBackProc(ProcessedFiles, Percentage, NeedToAbort); if NeedToAbort then Exit; end; def CallBackProc(ProcessedFiles, Percentage, NeedToAbort): ... But I don't know, how to call back this procedure, and how to pass variables. The other way is a ActiveX. This time I don't load the DLL, I only construct the Delphi based Com Object, and I start the process. But in this way I also don't know how to implement the callback, because the main code uses callback events, and I need to use too... Thanks for every usable help! dd -- http://mail.python.org/mailman/listinfo/python-list
Re: Command line arguements
En Mon, 28 Jul 2008 01:43:52 -0300, Henry Chang [EMAIL PROTECTED] escribió: try optparse :) http://docs.python.org/lib/module-optparse.html (optparse might be too much for a single argument) On Sun, Jul 27, 2008 at 9:13 PM, aditya shukla [EMAIL PROTECTED]wrote: in other words i do not want to do hard code the name of the file in my code every time i need to read it. I was reading about the sys module and i guess sys.argv would take the input from the command line whenever i run the python script . Exactly. Try this: import sys print sys.argv with no arguments, one, and several, and see what happens. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 28, 1:55 am, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 27, 10:55 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 26, 6:47 pm, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: On Jul 24, 5:01 am, Lawrence D'Oliveiro [EMAIL PROTECTED] central.gen.new_zealand wrote: In message [EMAIL PROTECTED], Jordan wrote: Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of *every single method argument list.* The reason is quite simple. Python is not truly an object-oriented language. It's sufficiently close to fool those accustomed to OO ways of doing things, but it doesn't force you to do things that way. You still have the choice. An implicit self would take away that choice. By that logic, C++ is not OO. Yes it is, because it has this. You mean the keyword this? It's just a feature. How does that make a difference on being or not being OO? Because it was one of the things the OP was complaining about (see above). Wrong. Reread what the OP said. Stop quoting only portions of my posts that lead to misinterpretation of them. Next time you quote, be sure to quote this (which I also mentioned in the previous post): What the OP complains about has no relevance on what makes a language OO or not. Do you believe otherwise? -- http://mail.python.org/mailman/listinfo/python-list
Module clarification
Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? What is the equivalent of modules in Java? Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback Python procedure from Delphi DLL
[EMAIL PROTECTED] wrote: Hi! I have a component, and a tool in Delphi. I wanna call it from Python. I can implement all things I need into a Delphi generated DLL. It is ok, I can use this DLL from Python, but the DLL procedure needs a callback procedure to return the partially output, and needs a python passed variable to check terminate/abort signal. For example: procedure ProcessFiles(InputFiles : string; CallBackProc: ); export; begin CallBackProc(ProcessedFiles, Percentage, NeedToAbort); if NeedToAbort then Exit; end; def CallBackProc(ProcessedFiles, Percentage, NeedToAbort): ... But I don't know, how to call back this procedure, and how to pass variables. The other way is a ActiveX. This time I don't load the DLL, I only construct the Delphi based Com Object, and I start the process. But in this way I also don't know how to implement the callback, because the main code uses callback events, and I need to use too... Thanks for every usable help! ctypes allows to create callbacks. See the module-docs. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Nikolaus Rath wrote: No, but it could work like this: def a(x, y): self.x = x self.y = y Frankly this would make reading and debugging the code by a third party to be a nightmare. Rather than calling the variable self as I did in my example, I could it in a much better way: def method(my_object, a, b): my_object.a = a my_object.b = b Now if I saw this function standalone, I'd immediately know what it was doing. In fact, I can even unit test this function by itself, without even having to know that later on it's monkey-patched into an existing class. With your idea, I might get the picture this function should be used as a method in some object because of the self reference, but I can't test the method by itself. Trying to call it would instantly result in an exception. And if this was a large function, I might not even see the self reference right away. -- http://mail.python.org/mailman/listinfo/python-list
os.symlink()
Hello, From `pydoc os`: symlink(...) symlink(src, dst) Create a symbolic link pointing to src named dst. Is there any reason why this is so deliberately confusing? Why is the target of the symlink, the think where it points *to*, called the `src`? It seems to me that the names of the parameters should be reversed. Puzzled, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: os.symlink()
Nikolaus Rath wrote: Hello, From `pydoc os`: symlink(...) symlink(src, dst) Create a symbolic link pointing to src named dst. Is there any reason why this is so deliberately confusing? Why is the target of the symlink, the think where it points *to*, called the `src`? It seems to me that the names of the parameters should be reversed. I used the command the other day, and didn't feel the slightest confusion. To me, the process of creating a symlink is like a virtual copy. Which the above parameter names reflect perfectly. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 28, 3:07 pm, Russ P. [EMAIL PROTECTED] wrote: What was suggested in rejected on the thread you pointed me to was not what I suggested. Not even close. Get it, genius? *sigh* Clearly I don't have better things to do right now than waste my time. You wrote: So why not allow something like this?: class MyClass: def func( , xxx, yyy): .xxx = xxx local = .yyy The self argument is replaced with nothing, but a comma is used as a placeholder. Philip Eby suggested in the thread I linked to: def .aMethod(arg1, arg2): return .otherMethod(arg1*2+arg2) In other words, 'self' here is uniformly replaced by an empty string. So you honestly see no similarity between your suggestion and the latter? Or do you seriously think that placing an errant comma in the argument list is somehow substantively different from placing a period before the function name? Or are you trying to say that 'self argument is replaced with nothing' is in no way the same suggestion as 'self' here is uniformly replaced by an empty string? And do you -really- believe that Guido's rejection reasons of * you're proposing to hide a fundamental truth in Python, that methods are just functions whose first argument can be supplied using syntactic sugar * that's a lot of new syntax for no gain in readability. You just need to get your head around the fundamental truth ...somehow don't apply to your suggestion? Did you even read the thread? -- http://mail.python.org/mailman/listinfo/python-list
Re: method decorators and more on decorators
En Sun, 27 Jul 2008 15:26:39 -0300, Themistoklis Bourdenas [EMAIL PROTECTED] escribió: Hi, is there any possible way to get the class or class name inside a method decorator? For example in the code sample below: def decorate(func): print type(func) return func class myclass: @decorate def foo(self): pass The output of this program will be the type of the supplied func in decorate, i.e. method foo. However, the type is function foo, a free function, not an instance method myclass.foo. Because the decorator is applied when the function is defined - and as you already noted, foo is a plain function (stored into myclass's namespace). Only when, later, the name foo is searched in the class, the descriptor protocol comes into play and a method object is built from the function and the myclass instance. On a related note, as the actual instance method of myclass is not foo but decorate(foo), why are they called method decorators? This does not decorate methods, they decorate functions and eventually the decorated functions become methods. The name method decorator sounds a bit misleading to me. Where have you found it? I've always seen the expression function decorator or just decorator, not method decorator. So returning to my original question is there any way I can get the class inside decorate()? I guess there is not, but just asking to make sure. the class inside decorate? What do you mean? The type of the x instance in an x.foo() call? That should be determined inside the wrapped function -when it is actually called-. Speaking of decorators I'd also like to ask on the pending class decorators that should be coming in a following version of the language. Are they going to be in 2.6 or just 3.0? In the following example: Both versions come with class decorators. In essence what is the order of application of class decorators compared to the function decorators of their methods? I couldn't find any mention of that issue in any of the PEPs. I guess it would be the latter, following the behavior of metaclasses, but better be certain than speculate :) I don't have a 2.6/3.0 Python at hand to check, but the (decorated) functions must be built before the class is created (because they are contained in the class's namespace). So the function decorators should be aplied before the class decorator... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Protecting instance variables
Hi, Sorry for replying so late. Your MUA apparently messes up the References:, so I saw you reply only now and by coincidence. Diez B. Roggisch [EMAIL PROTECTED] writes: Nikolaus Rath schrieb: Hello, I am really surprised that I am asking this question on the mailing list, but I really couldn't find it on python.org/doc. Why is there no proper way to protect an instance variable from access in derived classes? I can perfectly understand the philosophy behind not protecting them from access in external code (protection by convention), but isn't it a major design flaw that when designing a derived class I first have to study the base classes source code? Otherwise I may always accidentally overwrite an instance variable used by the base class... Here we go again... http://groups.google.com/group/comp.lang.python/browse_thread/thread/188467d724b48b32/ To directly answer your question: that's what the __ (double underscore) name mangling is for. I understand that it is desirable not to completely hide instance variables. But it seems silly to me that I should generally prefix almost all my instance variables with two underscores. I am not so much concerned about data hiding, but about not accidentally overwriting a variable of the class I'm inheriting from. And, unless I misunderstood something, this is only possible if I'm prefixing them with __. How is this problem solved in practice? I probably don't have a representative sample, but in the libraries that I have been using so far, there were a lot of undocumented (in the sense of: not being part of the public API) instance variables not prefixed with __. I have therefore started to first grep the source of all base classes whenever I introduce a new variable in my derived class. Is that really the way it's supposed to be? What if one of the base classes introduces a new variable at a later point? Best, -Nikolaus -- »It is not worth an intelligent man's time to be in the majority. By definition, there are already enough people to do that.« -J.H. Hardy PGP fingerprint: 5B93 61F8 4EA2 E279 ABF6 02CF A9AD B7F8 AE4E 425C -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
Suresh Pillai: Or 4, since the order of my nodes doesn't matter: swap the node to be deleted with the last node in the list and then remove the last node of the list. This is the fastest to date, if using native structures, for low number nodes being deleted per cycle (def if only deleting one). Using Psyco this suggestion may lead to code as fast as it gets in Python :-) Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
SOAPpy WSDL problem: namespace of schema and import match error
I am trying to use a webservice with SOAPpy: import SOAPpy intact_wsdl = http://www.ebi.ac.uk/intact/binary-search-ws/binarysearch?wsdl; intact_serv = SOAPpy.WSDL.Proxy(intact_wsdl) The resulting error message is posted below. If I understand it right, XMLSchema.py complains about the imported XSD namespace being the same as the existing targetNamespace. Perl and Java have no problems with the WSDL document (see sample code at http://www.ebi.ac.uk/~intact/devsite/remote/binarysearch_ws.html) My question: - Is there a problem with the WSDL file being not valid? - Is there a problem with the Python SOAP/WSDL implementation? Any suggestions? Christof Traceback (most recent call last): File testEBIIntactWebservice.py, line 3, in module intact_serv = SOAPpy.WSDL.Proxy(intact_wsdl) File /var/lib/python-support/python2.5/SOAPpy/WSDL.py, line 62, in __init__ self.wsdl = reader.loadFromStream(stream, wsdlsource) File /var/lib/python-support/python2.5/SOAPpy/wstools/WSDLTools.py, line 34, in loadFromStream wsdl.load(document) File /var/lib/python-support/python2.5/SOAPpy/wstools/WSDLTools.py, line 260, in load schema = reader.loadFromNode(WSDLToolsAdapter(self), item) File /var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py, line 80, in loadFromNode schema.load(reader) File /var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py, line 1076, in load tp.fromDom(node) File /var/lib/python-support/python2.5/SOAPpy/wstools/XMLSchema.py, line 1177, in fromDom raise SchemaError, 'namespace of schema and import match' SOAPpy.wstools.XMLSchema.SchemaError: namespace of schema and import match -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes - unloading implicitly loaded dlls
pigmartian [EMAIL PROTECTED] wrote: I'm writing a program that uses functionality from two different sets of cdlls which reside in two different directories, call them 'libA.dll' and 'libB.dll'. Although I don't directly use it, both directories contain a dll with the same name, although they aren't in fact identical. Call them, libC.dll. However, the c-functions I call from the clls I do use seem to implicitly use libC.dll. The problem that occurs after I load one dll and call functions in it, when I try to load the second dll I get windows errors because the second dll tries to call a function in its version of libC.dll, but it finds the version meant for libB.dll, which doesn't contain that function. Oy, I hope some sample code makes it clearer: def demo(): A = ctypes.cdll.LoadLibrary('/path1/libA.dll') A.foo() # implicitly uses '/path1/libC.dll' _ctypes.FreeLibrary(A._handle) # CRASH! B = ctypes.cdll.LoadLibrary('/path2/libB.dll') # The procedure entry point some_func could not be located # in the dynamic link library libC.dll.: # libB.dll wants to use code from '/path2/libC.dll', but # instead it finds '/path1/libC.dll' already loaded # in memory, which doesn't # contain the function call it wants. Assuming my understanding of things is correct, then I believe what I need to do is to remove /path1/libC.dll from memory before I try loading libB.dll, but I haven't found any way of doing that. Can anyone offer my some suggestions? Or, am I S.O.L.? You could try loading C explicitly with ctypes.LoadLibrary() before loading A, then you'll have a handle to unload it before you load B. I think I'd probably split the code into two or three processes though. Perhaps use http://pypi.python.org/pypi/processing to communicate between them. That should get you out of DLL Hell! (Don't load any of the DLLs before you start the worker processes off.) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Google Group: architectgurus
Dear Guru, Sudhakar Chavali wrote: Hi I have created a group called architectgurus (http://groups.google.com/ group/architectgurus) or [EMAIL PROTECTED] . Irrespective of technology, vendor, domain I will be discussing and share my thoughts in homogenous and harmonious way. If you are interested *even you* can join and contribute your thoughts in this group. My intention doing these activities is to spread the knowledge and thoughts across the globe. What? even me? That's really nice of you. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Raw Strings (I Think)
En Thu, 24 Jul 2008 12:02:00 -0300, Lanny [EMAIL PROTECTED] escribió: I've used glob.glob to get a list of files in a directory and now I want to use os.system to execute one of those files, the problem is that python automatically puts a escape charater infront of the back slashes so the os.system gets X:\\\\\\ and is useless, I think I need to convert my string to a raw string but I don't know how. Those \\ represent a SINGLE character. That is, they LOOK duplicated in code and when you use repr(...) but it's actually a single backslash: path = X:\\abc path 'X:\\abc' print path X:\abc len(path) 6 Probably you have another issue - please post a short but complete failing code... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Google Group: architectgurus
Gerhard Häring wrote: Dear Guru, Sudhakar Chavali wrote: Hi I have created a group called architectgurus (http://groups.google.com/ group/architectgurus) or [EMAIL PROTECTED] . Irrespective of technology, vendor, domain I will be discussing and share my thoughts in homogenous and harmonious way. If you are interested *even you* can join and contribute your thoughts in this group. My intention doing these activities is to spread the knowledge and thoughts across the globe. What? even me? That's really nice of you. It's amazing - all his thoughts can be summarized in 2 lines of postings + a PDF-link to thoughts of *other* people. Lively discussions are to emerge pretty soon I'm sure.. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
On Jul 28, 9:54 am, Hussein B [EMAIL PROTECTED] wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? An importable or runable (i.e. script) collection of classes, functions, variables etc... What is the equivalent of modules in Java? Don't know. Not even sure if it exists, but my Java is old and never been great. Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Indeed, you can now access things defined in Wow as Wow.foo Regards Floris -- http://mail.python.org/mailman/listinfo/python-list
Proxy server?
I've seen examples for HTTP and FTP use, but not for simply any TCP data on any port, which is what I require. Can anyone please point me in the right direction? TIA -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
On Jul 28, 6:55 am, Floris Bruynooghe [EMAIL PROTECTED] wrote: On Jul 28, 9:54 am, Hussein B [EMAIL PROTECTED] wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? An importable or runable (i.e. script) collection of classes, functions, variables etc... What is the equivalent of modules in Java? Don't know. Not even sure if it exists, but my Java is old and never been great. Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Indeed, you can now access things defined in Wow as Wow.foo Regards Floris If I have a couple of modules, is there a way to package them? or there is no such a thing in Python? -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
Hussein B wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? What is the equivalent of modules in Java? Read the docs: http://docs.python.org/tut/node8.html And read about eggs, the jars of python: http://peak.telecommunity.com/DevCenter/PythonEggs Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Michael Torrie wrote: Colin J. Williams wrote: def fun( ., cat): I don't see the need for the comma in fun. It (the entire first variable!) is needed because a method object is constructed from a normal function object: def method(self,a,b): pass class MyClass(object): pass MyClass.testmethod=method That's precisely the same as if you'd defined method inside of the class to begin with. A function becomes a method when the lookup procedure in the instance object looks up the attribute and returns (from what I understand) essentially a closure that binds the instance to the first variable of the function. The result is known as a bound method, which is a callable object: instance=MyClass() instance.testmethod bound method MyClass.testmethod of __main__.instance object at xxx How would this work if there was not first parameter at all? In short, unlike what most of the implicit self advocates are saying, it's not just a simple change to the python parser to do this. It would require a change in the interpreter itself and how it deals with classes. An interesting example. I would think that, for the common case, where a method is defined within a class statement, this would not be difficult. Others have suggested a pre-processor to illustrate this. OTOH, the assignment of a function to a class, so that it becomes a method does seem more difficult. My play script is below. Colin W. # tz,py def myFunc(a= None, b= None): print a, b pass class MyClass: pass def myMethod1(): print 'in myMethod' MyClass.myMethod0= myFunc print MyClass.myMethod0 print MyClass.myMethod1 myInstance= MyClass() print MyClass.myMethod0(myInstance) -- http://mail.python.org/mailman/listinfo/python-list
Re: Proxy server?
Gary wrote: I've seen examples for HTTP and FTP use, but not for simply any TCP data on any port, which is what I require. Can anyone please point me in the right direction? For what? How to use such a thing, a transparent proxy? There is nothing to it, just plug it between your router and the internet, that's all. Or do you want to know how to capture all traffic using some other process, for analysis? Use wireshark. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: write unsigned integer 32 bits to socket
Alan Franzoni wrote: Michael Torrie was kind enough to say: Of course any time you send coherent numbers over the network, I highly recommend you use what's called network byte order I'm sure python has some convention in the struct module for dealing with this. Not in the struct module; such functions are available in the socket module, and should be employed indeed. Please don't pass this misinformation along. In the struct module document, see the section on the initial character: Character Byte order Size and alignment @ nativenative = native standard little-endian standard big-endian standard !network (= big-endian) standard and notes @ is the default. print struct.pack('lh', 3,4) print struct.pack('lh', 3,4) print struct.pack('lh', 3,4) print struct.pack('!lh', 3,4) -- http://mail.python.org/mailman/listinfo/python-list
Re: write unsigned integer 32 bits to socket
On Mon, Jul 28, 2008 at 5:45 AM, Scott David Daniels [EMAIL PROTECTED] wrote: Alan Franzoni wrote: Michael Torrie was kind enough to say: Of course any time you send coherent numbers over the network, I highly recommend you use what's called network byte order I'm sure python has some convention in the struct module for dealing with this. Not in the struct module; such functions are available in the socket module, and should be employed indeed. Please don't pass this misinformation along. In the struct module document, see the section on the initial character: Character Byte order Size and alignment @ nativenative = native standard little-endian standard big-endian standard !network (= big-endian) standard and notes @ is the default. print struct.pack('lh', 3,4) print struct.pack('lh', 3,4) print struct.pack('lh', 3,4) print struct.pack('!lh', 3,4) thanks for clarifying, and just to make sure, i am using '!' format from the struct package... i had this even in my previous email what am doing below is fine right? this is short struct.pack('!h',3) '\x00\x03' this is integer struct.pack('!i',3) '\x00\x00\x00\x03' this is long struct.pack('!l',3) '\x00\x00\x00\x03' -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Mon, 28 Jul 2008 10:44:18 +0200, Suresh Pillai wrote: Since I am doing A LOT of loops over the nodes and the number of nodes is also huge, my concern using sets is that in order to iterate over the set in each step of my simulation, the set items need to be converted to a list every time. So while removal from a set is much cheaper than say from a list, what about this conversion overhead in order to iterate over the items. I could of course use the old trick of using a dictionary with 'None' values and then using iterkeys(). But I thought sets were supposed to replace this. So maybe I should be asking a more basic question: is there any way to iterate over the items in a set other than converting to a list or using the pop() method. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to upload files to google code filesection ?
On Jul 26, 12:43 pm, Stef Mientki [EMAIL PROTECTED] wrote: hello, In a program I want to download (updated) files from google code (not the svn section). I could find a python script to upload files, but not for downloading. Anyone has a hint or a solution ? thanks, Stef Mientki You should be able to use urllib to do that. The following link has a recipe: http://code.activestate.com/recipes/496685/ If you need to search Google Code, there's an API that appears to be exposed through their gdata module. Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Python program as daemon?
On 25 Jul, 20:05, sturlamolden [EMAIL PROTECTED] wrote: On Jul 25, 8:37 pm, Johny [EMAIL PROTECTED] wrote: Is it possible to run a Python program as daemon? Thanks Here is an example on how to run a Python script as a Unix daemon: http://svn.plone.org/svn/collective/bda.daemon/trunk/bda/daemon/daemo... Basically it forks twice and redirects open file descriptors to /dev/ null. On Windows, 'daemons' are called services. You can write Windows services in Python using the Pywin32 extension. See Mark Hammond's book for an explanation. Also, on Windows, you can get good results using srvany http://support.microsoft.com/kb/137890 I've set this up to run Pyhton for a couple of scripts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
Hussein B [EMAIL PROTECTED] wrote: If I have a couple of modules, is there a way to package them? or there is no such a thing in Python? It sounds rather as though you haven't yet gone through the Python tutorial. You really should read it, even if you just skim through it to see what topics are covered. The tutorial explains both modules and packages: http://docs.python.org/tut/node8.html What it doesn't cover is that you can import modules or packages directly from a zip file. Then read about eggs. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
ctypes and how to copy data passed to callback
Hi, I'm trying to handle data passed to Py Callback which is called from C dll. Callback passes data to another thread using Queue module and there the data are printed out. If data is printed out in a callback itself it's ok. If I put on queue and next get from queue in another thread script prints some trash. Looks like the data is released when callback returned. I tired to make d = copy.deepcopy(data), but it does not work - I got nothing. Any idea why it's happening ? - main thread def callback(data, size): myqueue.put((data, size)) mydll = cdll.MyDLL cbproto = CFUNCTYPE(c_int, POINTER(c_char), c_int) mycallback = cbproto(callback) mydll.RegisterCallback(mycallback) -- thread listener -- while True: data, size = myqueue.get() print ***, data[:size] -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
Russ P. a écrit : On Jul 27, 12:39 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Derek Martin a écrit : On Sun, Jul 27, 2008 at 08:19:17AM +, Steven D'Aprano wrote: You take the name down to a single letter. As I suggested in an earlier post on this thread, why not take it down to zero letters? The question isn't why not, but why. The status quo works well as it is, even if it isn't perfect. Prove that implicit self is a good idea -- or at least prove that it is an idea worth considering. Come on, this sounds like a schoolyard argument. This comes down to a matter of style, and as such, is impossible to prove. It's largely a question of individual preference. That said, the argument in favor is rather simple: 1. This is an extremely common idiom in Python 2. It is completely unnecessary, and the language does not suffer for making it implicit 3. Making it implicit reduces typing, reduces opportunities for mistakes, and arguably increases consistency. arguably, indeed, cf below. As for the latter part of #3, self (or some other variable) is required in the parameter list of object methods, It's actually the parameter list of the *function* that is used as the implementation of a method. Not quite the same thing. And then, consistency mandates that the target object of the method is part of the parameter list of the *function*, since that's how you make objects availables to a function. however when the method is *called*, it is omitted. Certainly not. You need to lookup the corresponding attribute *on a given object* to get the method. Whether you write some_object.some_method() or some_function(some_object) you still need to explicitely mention some_object. It is implied, supplied by Python. Neither. The target object is passed to the function by the method object, which is itself returned by the __get__ method of function objects, which is one possible application of the more general descriptor protocol (the same protocol that is used for computed attributes). IOW, there's nothing specific to 'methods' here, just the use of two general features (functions and the descriptor protocol). FWIW, you can write your own callable, and write it so it behave just like a function here: import types class MyCallable(object): def __call__(self, obj): print calling %s with %s % (self, obj) def __get__(self, instance, cls): return types.MethodType(self.__call__, instance, cls) class Foo(object): bar = MyCallable() print Foo.bar f = Foo() f.bar() Thus when an object method is called, it must be called with one fewer arguments than those which are defined. This can be confusing, especially to new programmers. This is confusing as long as you insist on saying that what you defined is a method - which is not the case. It can also be argued that it makes the code less ugly, though again, that's a matter of preference. It's not enough to show that a change isn't bad -- you have to show that it is actively good. But he did... he pointed out that *it saves work*, without actually being bad. Benefit, without drawback. Sounds good to me! Don't need to look at the method signature is not an argument in favour of implicit self. Yes, actually, it is. It isn't, since there's no method signature to look at !-) If there is a well-defined feature of Python which provides access to the object within itself, The point is that you don't get access to the object within itself. You get access to an object *within a function*. The fact that a function is defined within a class statement doesn't imply any magic, it just creates a function object, bind it to a name, and make that object an attribute of the class. You have the very same result by defining the function outside the class statement and binding it within the class statement, by defining the function outside the class and binding it to the class outside the class statement, by binding the name to a lambda within the class statement etc... then the opportunities for mistakes when someone decides to use something else are lessened. You don't need to look at the method signature when you're using an explicit self either. That isn't necessarily true. If you're using someone else's code, and they didn't use self -- or worse yet, if they chose this variable's name randomly throughout their classes -- then you may well need to look back to see what was used. It's bad programming, but the world is full of bad programmers, and we don't always have the choice not to use their code. Isn't one of Python's goals to minimize opportunities for bad programming? Nope. That's Java's goal. Python's goals are to maximize opportunities for good programming, which is quite different. Providing a keyword equivalent to self and removing the need to name it in object methods is one way to do that. It's also a way to make Python more complicated than it needs to be. At least with the current state, you
Re: Attack a sacred Python Cow
Russ P. a écrit : On Jul 27, 3:11 pm, Russ P. [EMAIL PROTECTED] wrote: On Jul 27, 12:39 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Derek Martin a écrit : On Sun, Jul 27, 2008 at 08:19:17AM +, Steven D'Aprano wrote: You take the name down to a single letter. As I suggested in an earlier post on this thread, why not take it down to zero letters? The question isn't why not, but why. The status quo works well as it is, even if it isn't perfect. Prove that implicit self is a good idea -- or at least prove that it is an idea worth considering. Come on, this sounds like a schoolyard argument. This comes down to a matter of style, and as such, is impossible to prove. It's largely a question of individual preference. That said, the argument in favor is rather simple: 1. This is an extremely common idiom in Python 2. It is completely unnecessary, and the language does not suffer for making it implicit 3. Making it implicit reduces typing, reduces opportunities for mistakes, and arguably increases consistency. arguably, indeed, cf below. As for the latter part of #3, self (or some other variable) is required in the parameter list of object methods, It's actually the parameter list of the *function* that is used as the implementation of a method. Not quite the same thing. And then, consistency mandates that the target object of the method is part of the parameter list of the *function*, since that's how you make objects availables to a function. however when the method is *called*, it is omitted. Certainly not. You need to lookup the corresponding attribute *on a given object* to get the method. Whether you write some_object.some_method() or some_function(some_object) you still need to explicitely mention some_object. It is implied, supplied by Python. Neither. The target object is passed to the function by the method object, which is itself returned by the __get__ method of function objects, which is one possible application of the more general descriptor protocol (the same protocol that is used for computed attributes). IOW, there's nothing specific to 'methods' here, just the use of two general features (functions and the descriptor protocol). FWIW, you can write your own callable, and write it so it behave just like a function here: import types class MyCallable(object): def __call__(self, obj): print calling %s with %s % (self, obj) def __get__(self, instance, cls): return types.MethodType(self.__call__, instance, cls) class Foo(object): bar = MyCallable() print Foo.bar f = Foo() f.bar() Thus when an object method is called, it must be called with one fewer arguments than those which are defined. This can be confusing, especially to new programmers. This is confusing as long as you insist on saying that what you defined is a method - which is not the case. It can also be argued that it makes the code less ugly, though again, that's a matter of preference. It's not enough to show that a change isn't bad -- you have to show that it is actively good. But he did... he pointed out that *it saves work*, without actually being bad. Benefit, without drawback. Sounds good to me! Don't need to look at the method signature is not an argument in favour of implicit self. Yes, actually, it is. It isn't, since there's no method signature to look at !-) If there is a well-defined feature of Python which provides access to the object within itself, The point is that you don't get access to the object within itself. You get access to an object *within a function*. The fact that a function is defined within a class statement doesn't imply any magic, it just creates a function object, bind it to a name, and make that object an attribute of the class. You have the very same result by defining the function outside the class statement and binding it within the class statement, by defining the function outside the class and binding it to the class outside the class statement, by binding the name to a lambda within the class statement etc... then the opportunities for mistakes when someone decides to use something else are lessened. You don't need to look at the method signature when you're using an explicit self either. That isn't necessarily true. If you're using someone else's code, and they didn't use self -- or worse yet, if they chose this variable's name randomly throughout their classes -- then you may well need to look back to see what was used. It's bad programming, but the world is full of bad programmers, and we don't always have the choice not to use their code. Isn't one of Python's goals to minimize opportunities for bad programming? Nope. That's Java's goal. Python's goals are to maximize opportunities for good programming, which is quite different. Providing a keyword equivalent to self and removing the need to name it in object methods is one way to do that. It's also a way to make Python more complicated than it needs to be.
Python FTP - NameError: name 'mydpa' is not defined
Hi there. I am trying to download a file(sn.last) from a public FTP server with the following code: from ftplib import FTP ftp=FTP('tgftp.nws.noaa.gov') ftp.login() ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf') ftp.retrbinar('RETR sn.last', open(mydpa,'wb').write) ftp.quit() but got an error message, which I think is normal: Traceback (most recent call last): File pyshell#13, line 1, in module ftp.retrbinary('RETR sn.last', open(mydpa,'wb').write) NameError: name 'mydpa' is not defined I don't know much about python, but just try to use the code to download data. I don't know where the file will be saved to. Is the mydata a file name or a folder name? where will it be saved to even if it's working? Please help be fixed the problem step by step? I am using 2.5.2 by the way. I really appreciate your help. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes and how to copy data passed to callback
waldek wrote: Hi, I'm trying to handle data passed to Py Callback which is called from C dll. Callback passes data to another thread using Queue module and there the data are printed out. If data is printed out in a callback itself it's ok. If I put on queue and next get from queue in another thread script prints some trash. Looks like the data is released when callback returned. I tired to make d = copy.deepcopy(data), but it does not work - I got nothing. Any idea why it's happening ? - main thread def callback(data, size): myqueue.put((data, size)) mydll = cdll.MyDLL cbproto = CFUNCTYPE(c_int, POINTER(c_char), c_int) mycallback = cbproto(callback) mydll.RegisterCallback(mycallback) -- thread listener -- while True: data, size = myqueue.get() print ***, data[:size] -- You need to allocate e.g. a bytebuffer using ctypes and then copy the memory area you get passed into that buffer. Otherwise I presume whoever invokes the callback releases the originaly memory block after the callback terminated. Diez -- http://mail.python.org/mailman/listinfo/python-list
Getting python 2.4 dll
Hi there, Is it possible to get a 2.4 dll of python for Windows easily? I need it to use python as scripting language for Vim. Regards, Guillermo -- http://mail.python.org/mailman/listinfo/python-list
Re: Where is the correct round() method?
On Jul 28, 12:34 am, Gary Herron [EMAIL PROTECTED] wrote: This will work as you wish: math.floor(x+0.5) This works fine for positive x but what about negative: round(2.5) 3.0 floor(2.5 + 0.5) 3.0 round(-2.5) -3.0 floor(-2.5 + 0.5) -2.0 Maybe: def round2(x): return math.floor(x + (0.5 if x = 0 else -0.5)) -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
On Jul 28, 4:54 am, Hussein B [EMAIL PROTECTED] wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? What is the equivalent of modules in Java? I'm new myself, coming from Perl and Java. Take my comments with the appropriate salt. Here's my understanding: 1) JARs are a bit of a Java oddity. The other languages I've worked with don't really combine their packaging method for transport with their packaging method of access. Put another way, you may get a zipfile or tarball of library files, but they aren't USED in that format, they are just transported in that format. You unzip them and use the compiled libraries directly. Java appears to be unusual there. I could be wrong (it's a big world), but such is my experience in the C and Perl worlds. 2) Java also dictates a single class per file (basically). Other languages do not have that restriction which leads to different collections. A file in Python (a module) may have several classes, or just one, or none. A package in Python is a directory containing modules (and possibly other packages) as well as a __init__.py file. This means that you cannot have the Java case of two packages offering the same fully qualified resource, because the namespace is tied to the filesystem (note you can alter this when importing the packages). 3) Java uses import to create a shortcut to the namespace, a convenience for the programmer that has little to no bearing on the execution of the code. Namespace is determined by the classloader. Python uses import to declare how a namespace is used by the code itself, which can be very significant, (For example, Java can access any fully qualified package without an import statement. Python cannot access any package until it has been made available by import.) Hope that helps and is remotely accurate. I'm sure someone will correct me if I'm wrong. -- http://mail.python.org/mailman/listinfo/python-list
Boolean tests [was Re: Attack a sacred Python Cow]
Cutting to the crux of the discussion... On Sun, 27 Jul 2008 23:45:26 -0700, Carl Banks wrote: I want something where if x will do but a simple explicit test won't. Explicit tests aren't simple unless you know what type x is. If x could be of any type, you can't write a simple test. Does x have a length? Is it a number? Maybe it's a fixed-length circular length, and the length is non-zero even when it's empty? Who knows? How many cases do you need to consider? Explicit tests are not necessarily simple for custom classes. Testing for emptiness could be arbitrarily complex. That's why we have __nonzero__, so you don't have to fill your code with complex expressions like (say) if len(x.method()[x.attribute]) -1 Instead you write it once, in the __nonzero__ method, and never need to think about it again. In general, you should write if x instead of an explicit test whenever you care whether or not x is something (true), as opposed to nothing (false), but you don't care what the type-specific definition of something vs. nothing actually is. To put it another way... using if x is just a form of duck-typing. Let the object decide itself whether it is something or nothing. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes and how to copy data passed to callback
waldek schrieb: Hi, I'm trying to handle data passed to Py Callback which is called from C dll. Callback passes data to another thread using Queue module and there the data are printed out. If data is printed out in a callback itself it's ok. If I put on queue and next get from queue in another thread script prints some trash. Looks like the data is released when callback returned. I tired to make d = copy.deepcopy(data), but it does not work - I got nothing. Any idea why it's happening ? - main thread def callback(data, size): myqueue.put((data, size)) mydll = cdll.MyDLL cbproto = CFUNCTYPE(c_int, POINTER(c_char), c_int) mycallback = cbproto(callback) mydll.RegisterCallback(mycallback) -- thread listener -- while True: data, size = myqueue.get() print ***, data[:size] -- I guess your code would work if you change it in this way: def callback(data, size): myqueue.put(data[:size]) while True: data = myqueue.get() print ***, data Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
On Jul 28, 8:11 am, Duncan Booth [EMAIL PROTECTED] wrote: Hussein B [EMAIL PROTECTED] wrote: If I have a couple of modules, is there a way to package them? or there is no such a thing in Python? It sounds rather as though you haven't yet gone through the Python tutorial. You really should read it, even if you just skim through it to see what topics are covered. The tutorial explains both modules and packages:http://docs.python.org/tut/node8.html What it doesn't cover is that you can import modules or packages directly from a zip file. Then read about eggs. -- Duncan Boothhttp://kupuguy.blogspot.com I'm reading Learning Python, 3rd Edition What do you think about it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
Suresh Pillai [EMAIL PROTECTED] wrote: [ ... ] is there any way to iterate over the items in a set other than converting to a list or using the pop() method. Er, how about directly iterating over the set? -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ Frankly I have no feelings towards penguins one way or the other -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
QOTW [was Re: Attack a sacred Python Cow]
On Sun, 27 Jul 2008 21:42:37 -0700, Russ P. wrote: +1 QOTW Do you realize what an insult that is to everyone else who has posted here in the past week? Actually I don't. I hadn't realised that when a person believes that somebody has made an especially clever, witty, insightful or fun remark, that's actually a put-down of all the other people whose remarks weren't quite as clever, witty, insightful or fun. But now that I've had this pointed out to me, why, I see insults everywhere! Tonight, my wife said to me that she liked my new shirt, so I replied What's the matter, you think my trousers are ugly? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Mon, 28 Jul 2008 15:04:43 +0200, Suresh Pillai wrote: I could of course use the old trick of using a dictionary with 'None' values and then using iterkeys(). But I thought sets were supposed to replace this. So maybe I should be asking a more basic question: is there any way to iterate over the items in a set other than converting to a list or using the pop() method. Yes, just do it. for i in set([1,2,3]): ... print i ... 1 2 3 -- Steven -- http://mail.python.org/mailman/listinfo/python-list
GUID Generation
Chaps, I've been looking at the following recipe for generating a GUID http://code.activestate.com/recipes/163604/ however I note that its about 6 years old. Has python since adopted an internal module for GUID generation? Or is this 3rd part module still the best option? Cheers, Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: os.symlink()
On 2008-07-28, Nikolaus Rath [EMAIL PROTECTED] wrote: Hello, From `pydoc os`: symlink(...) symlink(src, dst) Create a symbolic link pointing to src named dst. Is there any reason why this is so deliberately confusing? Why is the target of the symlink, the think where it points *to*, called the `src`? It seems to me that the names of the parameters should be reversed. I never looked at the names of the parameters. I just know that they're in the same order as they are when you do ln -s at a shell prompt. It's like you're copying a file (except the new one isn't really a copy, it's a link). -- Grant Edwards grante Yow! PEGGY FLEMMING is at stealing BASKET BALLS to visi.comfeed the babies in VERMONT. -- http://mail.python.org/mailman/listinfo/python-list
Re: GUID Generation
Robert Rawlins wrote: I’ve been looking at the following recipe for generating a GUID http://code.activestate.com/recipes/163604/ however I note that its about 6 years old. Has python since adopted an internal module for GUID generation? Or is this 3^rd part module still the best option? Not only is the answer, Yes: http://docs.python.org/lib/module-uuid.html but it's just featured as Doug Hellmann's module of the Week: http://blog.doughellmann.com/2008/07/pymotw-uuid.html TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: xml.dom's weirdness?
Stefan Behnel [EMAIL PROTECTED] wrote: Using my system Python (2.5.1 on Ubunutu Gutsy): $ strace -e open python -c '' 21 | wc -l 551 $ strace -e open python -c '' 21 | wc -l 4631 Using a self-built Python I have lying around: $ strace -e open python2.3 -c '' 21 | wc -l 210 $ strace -e open python2.3 -c '' 21 | wc -l 214 $ strace -e open python2.6 -c '' 21 | wc -l 138 $ strace -e open python2.6 -c '' 21 | wc -l 142 Blame Ubuntu/Debian. I'd be wary about including Debian in that blame. Using 4.0 here, with a 2.4.4 default and a 2.5.0 straight from the package: $ strace -e open python -c '' 21 | wc -l 171 $ strace -e open python -c '' 21 | wc -l 175 $ strace -e open python2.5 -c '' 21 | wc -l 105 $ strace -e open python2.5 -c '' 21 | wc -l 109 -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ Frankly I have no feelings towards penguins one way or the other -- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
RE: GUID Generation
Not only is the answer, Yes: http://docs.python.org/lib/module-uuid.html but it's just featured as Doug Hellmann's module of the Week: http://blog.doughellmann.com/2008/07/pymotw-uuid.html TJG Thanks Tim, Perfect! Robert -- http://mail.python.org/mailman/listinfo/python-list
Re: ActiveState Code (the new Python Cookbook) has been launched
Trent Mick [EMAIL PROTECTED] wrote: I happy to announce that ActiveState Code has been taken out of beta. This is the new site replacing the ASPN Cookbooks -- in particular the Python Cookbook. http://code.activestate.com/ Looks great and much faster than the old site! Mind telling us how it is implemented? I'm guessing python/django by the url and the fact that you have python stuff on your home pages but I could be wrong! -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Execution speed question
On Mon, 28 Jul 2008 15:04:43 +0200, Suresh Pillai wrote: On Mon, 28 Jul 2008 10:44:18 +0200, Suresh Pillai wrote: Since I am doing A LOT of loops over the nodes and the number of nodes is also huge, my concern using sets is that in order to iterate over the set in each step of my simulation, the set items need to be converted to a list every time. So while removal from a set is much cheaper than say from a list, what about this conversion overhead in order to iterate over the items. I could of course use the old trick of using a dictionary with 'None' values and then using iterkeys(). But I thought sets were supposed to replace this. So maybe I should be asking a more basic question: is there any way to iterate over the items in a set other than converting to a list or using the pop() method. Okay, please consider this my one absolutely stupid post for the year. I'd like to pretend it never happened but unfortunately the web doesn't allow that. Having never used sets, I unfort read something that lead to it, but ... -- http://mail.python.org/mailman/listinfo/python-list
multiple inheritance and __getattr__
Hi there, I have the following situation (I tryed to minimize the code to concentrate on the issue): class A(object): def __getattr__(self, name): print 'A.__getattr__' if name == 'a': return 1 raise AttributeError('%s not found in A' % name) class B(object): def __getattr__(self, name): print 'B.__getattr__' if name == 'b': return 1 raise AttributeError('%s not found in B' % name) Both classes have a __getattr__ method. Now I want to have a class that inherits from both so I write: class C(B,A): pass The problem arise when I try something like this: c=C() c.a A.__getattr__ 1 c.b A.__getattr__ Traceback (most recent call last): File pyshell#47, line 1, in module c.b File pyshell#42, line 5, in __getattr__ raise AttributeError('%s not found in A' % name) AttributeError: b not found in A I was expecting, after a fail in A.__getattr__, a call to the __getattr__ method of B but it seems that after A.__getattr__ fails the exception stops the flow. So, if I did understand well, B.__getattr__ will be never called automatically. I don't know if this has a reason, if it is a design choice or what else, any explanation is welcome. Since A and B are not written by me I can only work on C. The solution that comes to my mind is to define a __getattr__ also in C and write something like: class C(A,B): def __getattr__(self, name): try: return A.__getattr__(self, name) except AttributeError: return B.__getattr__(self, name) c=C() c.a A.__getattr__ 1 c.b A.__getattr__ B.__getattr__ 1 A better solution is welcome. Many thanks, Enrico -- http://mail.python.org/mailman/listinfo/python-list
Re: QOTW [was Re: Attack a sacred Python Cow]
On 28 Jul 2008 14:07:44 GMT, Steven D'Aprano [EMAIL PROTECTED] wrote: On Sun, 27 Jul 2008 21:42:37 -0700, Russ P. wrote: +1 QOTW Do you realize what an insult that is to everyone else who has posted here in the past week? Actually I don't. I hadn't realised that when a person believes that somebody has made an especially clever, witty, insightful or fun remark, that's actually a put-down of all the other people whose remarks weren't quite as clever, witty, insightful or fun. But now that I've had this pointed out to me, why, I see insults everywhere! Tonight, my wife said to me that she liked my new shirt, so I replied What's the matter, you think my trousers are ugly? -- Steven It is difficult to not offend the insult-sensitive. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python FTP - NameError: name 'mydpa' is not defined
On Jul 28, 2:27 pm, Harry [EMAIL PROTECTED] wrote: Hi there. I am trying to download a file(sn.last) from a public FTP server with the following code: from ftplib import FTP ftp=FTP('tgftp.nws.noaa.gov') ftp.login() ftp.cwd('SL.us008001/DF.of/DC.radar/DS.81dpr/SI.kbuf') ftp.retrbinar('RETR sn.last', open(mydpa,'wb').write) open(mydpa,'wb') would open the file to which you're saving the data, but you haven't defined to mydpa, so Python will complain. ftp.quit() but got an error message, which I think is normal: Traceback (most recent call last): File pyshell#13, line 1, in module ftp.retrbinary('RETR sn.last', open(mydpa,'wb').write) NameError: name 'mydpa' is not defined Yep! I don't know much about python, but just try to use the code to download data. I don't know where the file will be saved to. Is the mydata a file name or a folder name? where will it be saved to even if it's working? Please help be fixed the problem step by step? I am using 2.5.2 by the way. You need to tell it where to save the data by defining mydpa. I really appreciate your help. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: We programming
srinivasan srinivas wrote: Hi, Could someone suggest me better python modules for developing web programming related projects like web-pages download and uopload?? Thanks, Srini Explore your hobbies and interests. Go to http://in.promos.yahoo.com/groups/ urllib, urllib2, httplib All depends on what you want to do with them. -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding for Devanagari Script.
Hi Fredrik and Terry, Well I got this on IDLE I think I have done something wrong. import codecs f = open(C:\Documents and Settings\admin\My Documents\corpus\dainaikAikya collected by sushant.txt,r, utf_8) Traceback (most recent call last): File pyshell#1, line 1, in module f = open(C:\Documents and Settings\admin\My Documents\corpus \dainaikAikya collected by sushant.txt,r, utf_8) TypeError: an integer is required after that I tried the read binary mode and tried reading the firt 32 bytes and this is what I got. f = open(C:\Documents and Settings\\admin\\My Documents\\corpus\\dainaikAikya collected by sushant.txt,rb) f.read(32) '\xef\xbb\xbf\xe0\xa4\xa8\xe0\xa4\xb5\xe0\xa5\x80 \xe0\xa4\xa6\xe0\xa4\xbf\xe0\xa4\xb2\xe0\xa5\x8d \xe0\xa4\xb2\xe0\xa5\x80,' Now based on my knowledge of Unicode I think this is a utf-8 file (the first 3 bytes \xef\xbb\xbf), please correct me if I am wrong. How do I read this? Atul. PS: the above code I wrote using the information from the Library Reference pdf section 4.8 Codecs. Something wrong I am doing? Please do let me know. On Jul 25, 6:21 am, Terry Reedy [EMAIL PROTECTED] wrote: Atul. wrote: Hello All, I wanted to know what encoding should I use to open the files with Devanagaricharacters. I was thinking of UTF-8 but was not sure, any leads on this? Anyone used it earlier? You cannot hurt your machine by giving that a try. This is a general comment for all beginners. Before posting, open the interactive interpreter (or IDLE) and try something(s). If the result puzzles you, copy and paste into a post. Or if more appropriate, open the Python manuals and search a bit, or try a search engine. -- http://mail.python.org/mailman/listinfo/python-list
Re: xml.dom's weirdness?
On 28 Jul, 16:15, Sion Arrowsmith [EMAIL PROTECTED] wrote: Stefan Behnel [EMAIL PROTECTED] wrote: Blame Ubuntu/Debian. I'd be wary about including Debian in that blame. Using 4.0 here, with a 2.4.4 default and a 2.5.0 straight from the package: [...] I can imagine that some of the Python Eggs magic could quite easily inflate the number of files opened when doing imports. Information on things like the state of site-packages, .pth files, the length of PYTHONPATH and so on should surely accompany the numbers before fingers are pointed. Paul -- http://mail.python.org/mailman/listinfo/python-list
Using Python Modules from JAVA
Hi all, I'd like to use the pygments syntax highlighting module from within a JAVA application. While I understand how to use Jython to execute a script file or interpret single statements, I don't know how I can use a whole module (i.e. the several files pygments consists of). In order to deploy the application easily I don't want to install Jython or anything else on the system and then call pygment's installer from the shell. I imagine being able to just copy a jar (e.g. jython.jar) and an egg file to the target system and load the module in JAVA. Is this possible? Has anybody any experience with that? Thanks in advance for your help, raymi -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding for Devanagari Script.
Atul. wrote: Hi Fredrik and Terry, Well I got this on IDLE I think I have done something wrong. import codecs f = open(C:\Documents and Settings\admin\My Documents\corpus\dainaikAikya collected by sushant.txt,r, utf_8) Traceback (most recent call last): File pyshell#1, line 1, in module f = open(C:\Documents and Settings\admin\My Documents\corpus \dainaikAikya collected by sushant.txt,r, utf_8) TypeError: an integer is required PS: the above code I wrote using the information from the Library Reference pdf section 4.8 Codecs. Something wrong I am doing? Please do let me know. Only slightly. You're importing the codecs module but you're not using it. So you're *actually* using the built-in open function, which doesn't have an encoding parameter. It does have a third param which is to do with the buffer size. Just change your code to use codecs.open (...) and, I suggest, either use raw strings for your filename (rc:\docume...) or use the other kind of slash (c:/documen...). Otherwise you might run into some problems. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: multiple inheritance and __getattr__
In article [EMAIL PROTECTED], Enrico [EMAIL PROTECTED] wrote: Hi there, I have the following situation (I tryed to minimize the code to concentrate on the issue): class A(object): def __getattr__(self, name): print 'A.__getattr__' if name == 'a': return 1 raise AttributeError('%s not found in A' % name) class B(object): def __getattr__(self, name): print 'B.__getattr__' if name == 'b': return 1 raise AttributeError('%s not found in B' % name) Both classes have a __getattr__ method. Now I want to have a class that inherits from both so I write: class C(B,A): pass The problem arise when I try something like this: c=C() c.a A.__getattr__ 1 c.b A.__getattr__ Traceback (most recent call last): File pyshell#47, line 1, in module c.b File pyshell#42, line 5, in __getattr__ raise AttributeError('%s not found in A' % name) AttributeError: b not found in A I was expecting, after a fail in A.__getattr__, a call to the __getattr__ method of B but it seems that after A.__getattr__ fails the exception stops the flow. So, if I did understand well, B.__getattr__ will be never called automatically. I don't know if this has a reason, if it is a design choice or what else, any explanation is welcome. Well, it's simply the way it works. When you say C(A, B) then A is searched first for a given attribute and if A has no such attribute then B is searched. If you really want to do something like this then yes, you have to do something as below. I suspect that the people who feel expert enough to talk about what you should and shouldn't want are going to say that you shouldn't want something like this - with things set up the way you have them you really can't tell what's going to happen with c.__getattr__ unless you look at all the code in all the subclasses. Since A and B are not written by me I can only work on C. The solution that comes to my mind is to define a __getattr__ also in C and write something like: class C(A,B): def __getattr__(self, name): try: return A.__getattr__(self, name) except AttributeError: return B.__getattr__(self, name) c=C() c.a A.__getattr__ 1 c.b A.__getattr__ B.__getattr__ 1 A better solution is welcome. Many thanks, Enrico -- David C. Ullrich -- http://mail.python.org/mailman/listinfo/python-list
Re: write unsigned integer 32 bits to socket
Scott David Daniels was kind enough to say: Alan Franzoni wrote: Please don't pass this misinformation along. In the struct module document, see the section on the initial character: Character Byte order Size and alignment @ nativenative = native standard little-endian standard big-endian standard !network (= big-endian) standard Sure, that's is one way to do it... but I was answering Micheal Torrie, who said: htonl() call, and then when pulling it off the wire on the other end you'd use ntohl(). If you don't then you will have problems when the htonl() and ntohl() are available in Python in the socket module, so: 1) i was just pointing the OP to the right place where to find such functions 2) they work just the same way, hence I can't see why the struct way should be the preferred one while the socket way should be misinformation :P Bye! -- Alan Franzoni [EMAIL PROTECTED] - Remove .xyz from my email in order to contact me. - GPG Key Fingerprint: 5C77 9DC3 BD5B 3A28 E7BC 921A 0255 42AA FE06 8F3E -- http://mail.python.org/mailman/listinfo/python-list
Suggestions for creating a PDF table
Short question: Is there a good library for generating HTML-style tables with the equivalent of colspans, automatically sized columns, etc. that can render directly to PDF? Longer question: I'm re-doing a big chunk of locally-written code. I have a report-generating function that takes a list of lists of lists as input and returns either a PDF, an HTML table, or an Excel spreadsheet as requested. For example, input might look like: makereport('html', headers=['Invoice number', 'Customer', 'Price'], data=[ [['123', 'John Doe', '$50.00'], ['Ordered on 2008-01-01 via the website']], [['124', 'Peter Bilt', '$25.99'], ['Mail via African swallow']] ]) This would result in HTML like: table tr thInvoice number/th thCustomer/th thPrice/th /tr tr class=lightbackground td123/td tdJohn Doe/td td$50.00/td /tr tr class=lightbackground td colspan=3Ordered on 2008-01-01 via the website/td /tr tr class=darkerbackground td124/td tdPeter Bilt/td td$25.99/td /tr tr class=darkerbackground td colspan=3Mail via African swallow/td /tr /table Note particularly how the explanatory notes for each invoice are similar in appearance to the primary report lines they're associated with. Now, I have a similar transformation to PDF via pdflatex. This works fairly well but requires a bunch of temp files and subprocesses, and I've never been 100% happy with the LaTeX output (you have to calculate your own column widths, for instance). Since I plan to re-write this anyway, I'd like to find a more widely used library if one was available. ReportLab seemed *almost* perfect, except that it doesn't support colspans. As I hope I demonstrated in the example, most of our reports depend on that ability. So, again, any thoughts on a PDF generator that can generate tables with the same kind of flexibility as HTML? -- Kirk Strauser -- http://mail.python.org/mailman/listinfo/python-list
Re: SOAPpy WSDL problem: namespace of schema and import match error
Christof Winter wrote, On 28.07.2008 12:32: I am trying to use a webservice with SOAPpy: import SOAPpy intact_wsdl = http://www.ebi.ac.uk/intact/binary-search-ws/binarysearch?wsdl; intact_serv = SOAPpy.WSDL.Proxy(intact_wsdl) [...] My question: - Is there a problem with the WSDL file being not valid? I just figured out that this could indeed be true. The WSDL document contains an XML Schema import that probably should be an XML Schema include: The import element is used to add multiple schemas with different target namespace to a document. http://www.w3schools.com/schema/el_import.asp The include element is used to add multiple schemas with the same target namespace to a document. http://www.w3schools.com/schema/el_include.asp Maybe I should post this to comp.text.xml Christof -- http://mail.python.org/mailman/listinfo/python-list
Re: with statement for two files
braver [EMAIL PROTECTED] writes: with open(src) as readin, open(dst,w) as writin: # WRONG: comma doesn't work ... -- so that you have transactional safety for two file descriptors? use contextlib.nexted(). -- http://mail.python.org/mailman/listinfo/python-list
Re: Encoding for Devanagari Script.
Thanks, Tim that did work. I will proceed with my playing around now. Thanks a ton. Atul. Only slightly. You're importing the codecs module but you're not using it. So you're *actually* using the built-in open function, which doesn't have an encoding parameter. It does have a third param which is to do with the buffer size. Just change your code to use codecs.open (...) and, I suggest, either use raw strings for your filename (rc:\docume...) or use the other kind of slash (c:/documen...). Otherwise you might run into some problems. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: How to figure out if the platform is 32bit or 64bit?
Manuel Vazquez Acosta wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Just test for maxint value: from sys import maxint if maxint 33: print more than 32 bits # probably 64 else: print 32 bits I believe that was already suggested in this thread. That test will just tell you if the Python *build* is 32-bit or 64-bit. If the answer is 32-bit, then that doesn't tell you if this is a 32-bit Python running on a 64-bit OS. Trent -- Trent Mick trentm at activestate.com -- http://mail.python.org/mailman/listinfo/python-list
Re: ActiveState Code (the new Python Cookbook) has been launched
Nick Craig-Wood wrote: Trent Mick [EMAIL PROTECTED] wrote: I happy to announce that ActiveState Code has been taken out of beta. This is the new site replacing the ASPN Cookbooks -- in particular the Python Cookbook. http://code.activestate.com/ Looks great and much faster than the old site! Thanks! Mind telling us how it is implemented? I'm guessing python/django by the url and the fact that you have python stuff on your home pages but I could be wrong! Yup, it is a Django-based site -- a pleasure to work with, that. Using django-tagging, django-template-utils universal feedparser (for hooking in Atom content for News section on home page), django-voting, python-markdown2 (for rendering comments, discussion/descriptions), recaptcha-client (for feedback when not logged in), pygments (for syntax coloring). I've just submitted the site to http://www.djangosites.org/ I hope to do some blog posts about some parts of the site soon and release the small re-usable feedback app I've put together for getting feedback on the site. Cheers, Trent -- Trent Mick trentm at activestate.com -- http://mail.python.org/mailman/listinfo/python-list
Re: with statement for two files
Paul Rubin wrote: braver [EMAIL PROTECTED] writes: with open(src) as readin, open(dst,w) as writin: # WRONG: comma doesn't work ... -- so that you have transactional safety for two file descriptors? use contextlib.nexted(). You mean contextlib.nested I guess. Didn't know about that module, cool! However, the fundamental problem stays: rolling back only works if the innermost context fails. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On 28 Jul., 06:42, Russ P. [EMAIL PROTECTED] wrote: On Jul 27, 8:58 pm, castironpi [EMAIL PROTECTED] wrote: On Jul 27, 2:39 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Derek Martin a écrit : It's bad programming, but the world is full of bad programmers, and we don't always have the choice not to use their code. Isn't one of Python's goals to minimize opportunities for bad programming? Nope. That's Java's goal. Python's goals are to maximize opportunities for good programming, which is quite different. Oh, gosh, that is so clever. What a bunch of crap. +1 QOTW Do you realize what an insult that is to everyone else who has posted here in the past week? Nothing glues a community together so well as a common enemy. Or even better: two enemies i.e. Perl and Java in Pythons case. On the other hand, some enemies have to be ignored or declared to be not an enemy ( Ruby ), although oneself is clearly an enemy for them. The same antisymmetry holds for Python and Java. Java is an enemy for Python but Python is not worth for Java to be an enemy as long as it can be ignored. C++ and Java are enemies for each other. Same holds for Java and C#. -- http://mail.python.org/mailman/listinfo/python-list
Re: write unsigned integer 32 bits to socket
On 2008-07-28, Alan Franzoni [EMAIL PROTECTED] wrote: Scott David Daniels was kind enough to say: Alan Franzoni wrote: Please don't pass this misinformation along. In the struct module document, see the section on the initial character: Character Byte order Size and alignment @ nativenative = native standard little-endian standard big-endian standard !network (= big-endian) standard Sure, that's is one way to do it... but I was answering Micheal Torrie, who said: htonl() call, and then when pulling it off the wire on the other end you'd use ntohl(). If you don't then you will have problems when the htonl() and ntohl() are available in Python in the socket module, so: 1) i was just pointing the OP to the right place where to find such functions 2) they work just the same way, hence I can't see why the struct way should be the preferred one while the socket way should be misinformation Yes, the socket module does have ntohX and htonX calls. But they're superfluous, since you still have to call struct.pack/unpack to convert integer objects to/from the byte-strings that are transferred via send() and recv() calls. Changing the initial = in the format string to a ! eliminates the need to pass the integer objects though calls to socket.ntohX() and socket.htonX() -- Grant Edwards grante Yow! Do you have exactly at what I want in a plaid visi.compoindexter bar bat?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Suggestions for creating a PDF table
Kirk Strauser wrote: Short question: Is there a good library for generating HTML-style tables with the equivalent of colspans, automatically sized columns, etc. that can render directly to PDF? Longer question: I'm re-doing a big chunk of locally-written code. I have a report-generating function that takes a list of lists of lists as input and returns either a PDF, an HTML table, or an Excel spreadsheet as requested. For example, input might look like: makereport('html', headers=['Invoice number', 'Customer', 'Price'], data=[ [['123', 'John Doe', '$50.00'], ['Ordered on 2008-01-01 via the website']], [['124', 'Peter Bilt', '$25.99'], ['Mail via African swallow']] ]) This would result in HTML like: table tr thInvoice number/th thCustomer/th thPrice/th /tr tr class=lightbackground td123/td tdJohn Doe/td td$50.00/td /tr tr class=lightbackground td colspan=3Ordered on 2008-01-01 via the website/td /tr tr class=darkerbackground td124/td tdPeter Bilt/td td$25.99/td /tr tr class=darkerbackground td colspan=3Mail via African swallow/td /tr /table Note particularly how the explanatory notes for each invoice are similar in appearance to the primary report lines they're associated with. Now, I have a similar transformation to PDF via pdflatex. This works fairly well but requires a bunch of temp files and subprocesses, and I've never been 100% happy with the LaTeX output (you have to calculate your own column widths, for instance). Since I plan to re-write this anyway, I'd like to find a more widely used library if one was available. ReportLab seemed *almost* perfect, except that it doesn't support colspans. As I hope I demonstrated in the example, most of our reports depend on that ability. So, again, any thoughts on a PDF generator that can generate tables with the same kind of flexibility as HTML? It does support the equivalent of colspans. See page 75 of the userguide manual. -Larry -- http://mail.python.org/mailman/listinfo/python-list
python lists and newline character
Hello all, I am using os.popen to get a list returned of vpopmail users, something like this x = os.popen('/home/vpopmail/bin/vuserinfo -n -D mydomain.com).readlines() x returns a list, of usernames, and I am trying to append the usernames with the domain like so for line in x: print line + '@' + domain but instead of getting [EMAIL PROTECTED] im getting a newline character like: user @domain.com User @comain.com User2 @domain.com Is there some way I can get this list without the newline characters being added. or somehow remove the newline characters. Any help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: binding names doesn't affect the bound objects (was: print doesn't respect file inheritance?)
On Jul 26, 7:08 am, D'Arcy J.M. Cain [EMAIL PROTECTED] wrote: On Sat, 26 Jul 2008 14:07:52 +1000 Ben Finney [EMAIL PROTECTED] wrote: sys.stdout = n Re-binds the name 'sys.stdout' to the object already referenced by the name 'n'. No objects are changed by this; only bindings of names to objects. I do agree that the object formerly known as sys.stdout hasn't changed. print Testing: 1, 2, 3... Doesn't rely at all on the name 'sys.stdout', so isn't affected by all the binding of names above. Hmm. Are you saying that the following doesn't work? $ python f = open(test, w) import sys sys.stdout = f print test message sys.exit(0) $ cat test test message In other words, you can't change the object used by the 'print' statement only by re-binding names (which is *all* that is done by the '=' operator). Apparently I can. You can, however, specify which file 'print' should use URL:http://www.python.org/doc/ref/print.html. Which contains this statement. Standard output is defined as the file object named stdout in the built-in module sys. I suppose that there might be some ambiguity there but the proof, as they say, is in the pudding. -- D'Arcy J.M. Cain [EMAIL PROTECTED] | Democracy is three wolveshttp://www.druid.net/darcy/ | and a sheep voting on +1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner. Thanks for backing me up. Nobody here thinks it's strange that print uses *none* of the attributes or methods of sys.stdout to do its job? The implementation seems to bypass the whole python system and use C-level FILE* pointers directly instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: Easier way to get the here path?
On Jul 26, 9:19 am, Andrew [EMAIL PROTECTED] wrote: bukzor wrote: from os.path import abspath, realpath realpath(path.__file__.rstrip(c)) '/home/bgolemon/python/symlinks/path.py' realpath(abspath(path.__file__.rstrip(c))) '/home/bgolemon/python/symlinks/symlinks/path.py' -- http://mail.python.org/mailman/listinfo/python-list I find it interesting that I get something different: In [1]: import path path.pyc In [2]: path.__file__ Out[2]: 'path.pyc' In [3]: path.__file__.rstrip(c) Out[3]: 'path.py' In [4]: from os.path import abspath, realpath In [5]: realpath(path.__file__.rstrip(c)) Out[5]: '/home/andrew/sym/sym/path.py' In [6]: realpath(abspath(path.__file__.rstrip(c))) Out[6]: '/home/andrew/sym/sym/path.py' I get the same thing for realpath() and realpath(abspath()) It seems to me you can just use: In [1]: import path path.pyc In [2]: from os.path import abspath In [3]: realpath(path.__file__.rstrip(c)) Out[3]: '/home/andrew/sym/sym/path.py' By the way, I am in /home/andrew/sym and path is symlinked from /home/andrew/sym/sym/path.py to /home/andrew/sym/path.py -- Andrew As you can see above, I get the wrong think if I do that. It's very strange that we're getting different things. I'm using python 2.4, maybe it was updated in 2.5? -- http://mail.python.org/mailman/listinfo/python-list
Re: python lists and newline character
domain.strip() Assuming domain is the string with the newline. -Steve Johnson On Jul 28, 2008, at 1:32 PM, Support Desk wrote: Hello all, I am using os.popen to get a list returned of vpopmail users, something like this x = os.popen('/home/vpopmail/bin/vuserinfo -n -D mydomain.com).readlines() x returns a list, of usernames, and I am trying to append the usernames with the domain like so for line in x: print line + [EMAIL PROTECTED] + domain but instead of getting [EMAIL PROTECTED] im getting a newline character like: user @domain.com User @comain.com User2 @domain.com Is there some way I can get this list without the newline characters being added. or somehow remove the newline characters. Any help would be appreciated. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: python lists and newline character
Support Desk wrote: Hello all, I am using os.popen to get a list returned of vpopmail users, something like this x = os.popen('/home/vpopmail/bin/vuserinfo -n -D mydomain.com).readlines() x returns a list, of usernames, and I am trying to append the usernames with the domain like so for line in x: print line + [EMAIL PROTECTED] + domain but instead of getting [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] im getting a newline character like: user @domain.com User @comain.com User2 @domain.com Is there some way I can get this list without the newline characters being added. or somehow remove the newline characters. Any help would be appreciated. The problem has nothing to do with lists. The readlines() function returns each line *with* its newline. To strip it off, use line.strip() Gary Herron -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: ActiveState Code (the new Python Cookbook) has been launched
On 28 Jul., 18:55, Trent Mick [EMAIL PROTECTED] wrote: Nick Craig-Wood wrote: Trent Mick [EMAIL PROTECTED] wrote: I happy to announce that ActiveState Code has been taken out of beta. This is the new site replacing the ASPN Cookbooks -- in particular the Python Cookbook. http://code.activestate.com/ Looks great and much faster than the old site! Thanks! Mind telling us how it is implemented? I'm guessing python/django by the url and the fact that you have python stuff on your home pages but I could be wrong! Yup, it is a Django-based site -- a pleasure to work with, that. Using django-tagging, django-template-utils universal feedparser (for hooking in Atom content for News section on home page), django-voting, python-markdown2 (for rendering comments, discussion/descriptions), recaptcha-client (for feedback when not logged in), pygments (for syntax coloring). I've just submitted the site tohttp://www.djangosites.org/ I hope to do some blog posts about some parts of the site soon and release the small re-usable feedback app I've put together for getting feedback on the site. Cheers, Trent -- Trent Mick trentm at activestate.com Hmm... overview is lost on the new site. My 15 notebook does not even display 3 full recipes in a firefox browser window ( with some tabs being opened ). I didn't check out the site on my 12 notebook but I suspect it tends to be close to 1. Otherwise the whole screen is filled with administrative debris which is a pitty. The dialogs seem to be pretty responsive and straightforward though. I used submit recipe, typed my login data and got the input form immediately - instead of the main page (!) in the old system which was gruesome in this respect. -- http://mail.python.org/mailman/listinfo/python-list
Re: like py2exe, but on a mac
On 28 jul 2008, at 03.59, William McBrine wrote: On Sun, 13 Jul 2008 00:58:59 +0200, Python.Arno wrote: http://undefined.org/python/py2app.html py2app bundles Python itself into the app, right? I wonder, is there no way to create an app bundle that relies on the existing installation of Python, since OS X already comes with Python? I have a tiny little program (~20k) that I'd like to make into an app bundle, if only to suppress the console window, and I'd rather not lump in the whole Python interpreter if I can avoid it. -- 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on -- http://mail.python.org/mailman/listinfo/python-list There is Platypus, a general open source program to wrap a script in an Macintosh (GUI) Application. Platypus 4.0 software download - Mac OS X - VersionTracker.webloc Description: Binary data -- Skinheads are so tired of immigration, that they are going to move to a country that don't accept immigrants! Tommy Nordgren [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
Hi Hussein, Basically a module is a FILE and is considered as a singleton model. Yes ur wow.py assumption is correct. I recommend getting Mark Lutz Learning Python book to get you started. Marcus.CM Hussein B wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? What is the equivalent of modules in Java? Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: We programming
Hi , I hope this doesnt invite flames.but for webpages i suggest stick with php... I'm outta here.wooosh srinivasan srinivas wrote: Hi, Could someone suggest me better python modules for developing web programming related projects like web-pages download and uopload?? Thanks, Srini Explore your hobbies and interests. Go to http://in.promos.yahoo.com/groups/ -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Easier way to get the here path?
On Jul 28, 10:34 am, bukzor [EMAIL PROTECTED] wrote: On Jul 26, 9:19 am, Andrew [EMAIL PROTECTED] wrote: bukzor wrote: from os.path import abspath, realpath realpath(path.__file__.rstrip(c)) '/home/bgolemon/python/symlinks/path.py' realpath(abspath(path.__file__.rstrip(c))) '/home/bgolemon/python/symlinks/symlinks/path.py' -- http://mail.python.org/mailman/listinfo/python-list I find it interesting that I get something different: In [1]: import path path.pyc In [2]: path.__file__ Out[2]: 'path.pyc' In [3]: path.__file__.rstrip(c) Out[3]: 'path.py' In [4]: from os.path import abspath, realpath In [5]: realpath(path.__file__.rstrip(c)) Out[5]: '/home/andrew/sym/sym/path.py' In [6]: realpath(abspath(path.__file__.rstrip(c))) Out[6]: '/home/andrew/sym/sym/path.py' I get the same thing for realpath() and realpath(abspath()) It seems to me you can just use: In [1]: import path path.pyc In [2]: from os.path import abspath In [3]: realpath(path.__file__.rstrip(c)) Out[3]: '/home/andrew/sym/sym/path.py' By the way, I am in /home/andrew/sym and path is symlinked from /home/andrew/sym/sym/path.py to /home/andrew/sym/path.py -- Andrew As you can see above, I get the wrong think if I do that. It's very strange that we're getting different things. I'm using python 2.4, maybe it was updated in 2.5? After doing a little testing, it seems that realpath was in fact improved between 2.4 and 2.5. I need to stick with 2.4, so the abspath() call is still necessary for me. Regardless, the answer to my question is that there's no good built-in way to do this. Even the code above fails for some cases (say the symlink is named just c), making the problem non-trivial. To me, this is a failure of python's batteries included. Is this worthy of a PEP? I'd like to add something like __absfile__ or maybe os.path.absolute_script_path(). Sample implementation: def scriptpath(): from inspect import currentframe file = currentframe().f_back.f_locals.get('__file__', None) if file.endswith(.pyc): file = file.rstrip(c) from os.path import realpath, abspath return realpath(abspath(file)) Testing: ~/pythonls -l foo.py* c sym/* lrwxrwxrwx1 bgolemon asic 10 Jul 28 10:46 c - sym/ bar.py* lrwxrwxrwx1 bgolemon asic 10 Jul 28 10:38 foo.py - sym/ bar.py* -rw-rw-r--1 bgolemon asic 149 Jul 28 10:57 foo.pyc -rwxrwx---1 bgolemon asic 76 Jul 28 10:53 sym/bar.py* -rw-rw-r--1 bgolemon asic 149 Jul 28 10:58 sym/bar.pyc ~/pythoncat sym/bar.py #!/usr/bin/env python from scriptpath import scriptpath print scriptpath() ~/python./c /home/bgolemon/python/sym/bar.py ~/python./sym/bar.py /home/bgolemon/python/sym/bar.py ~/python./foo.py /home/bgolemon/python/sym/bar.py ~/pythonpython import foo /home/bgolemon/python/sym/bar.py ~/pythoncd sym/ ~/python/sympython import bar /home/bgolemon/python/sym/bar.py --Buck -- http://mail.python.org/mailman/listinfo/python-list
Re: Module clarification
I would recommend dive into python. Its available free online (just google it) and it tries to teach you python, not programming which unfortunately many books try to do. It assumes that you already have some experience with C++ or Java and contradicts python syntax/semantics to those languages. Very useful and fast if you already know how to program. Cheers, Themis On Mon, Jul 28, 2008 at 6:57 PM, Marcus.CM [EMAIL PROTECTED]wrote: Hi Hussein, Basically a module is a FILE and is considered as a singleton model. Yes ur wow.py assumption is correct. I recommend getting Mark Lutz Learning Python book to get you started. Marcus.CM Hussein B wrote: Hi. I'm a Java guy and I'm playing around Python these days... In Java, we organize our classes into packages and then jarring the packages into JAR files. What are modules in Python? What is the equivalent of modules in Java? Please correct me if I'm wrong: I saved my Python code under the file Wow.py Wow.py is now a module and I can use it in other Python code: import Wow Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: We programming
On Tue, 29 Jul 2008 02:00:54 +0800 Marcus.CM [EMAIL PROTECTED] wrote: I hope this doesnt invite flames.but for webpages i suggest stick with php... Oh, come on. You're just asking for it. :-) [Turns flame thrower to low setting] OK, here is why I don't like PHP. When I am creating dynamic web content, chances are that it is part of a larger system. I may have command line utilities, server software and cron jobs all working on the same (usually database backed) systems. As a result it is really convenient to be able to reuse modules. Python gives me that quite easily. PHP, not so much. I am not going to write a server in PHP, for example. I also don't much care for PHP as a language anyway but that's actually a secondary consideration. I'll go put on my flame-retardent underwear now. -- D'Arcy J.M. Cain [EMAIL PROTECTED] | 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Attack a sacred Python Cow
On Jul 28, 2:26 am, Nikolaus Rath [EMAIL PROTECTED] wrote: castironpi [EMAIL PROTECTED] writes: I think you misunderstood him. What he wants is to write class foo: def bar(arg): self.whatever = arg + 1 instead of class foo: def bar(self, arg) self.whatever = arg + 1 so 'self' should *automatically* only be inserted in the function declaration, and *manually* be typed for attributes. There's a further advantage: class A: def get_auxclass( self, b, c ): class B: def auxmeth( self2, d, e ): #here, ... return B In auxmeth, self would refer to the B instance. In get_auxclass, it would refer to the A instance. If you wanted to access the A instance in auxmeth, you'd have to use class A: def get_auxclass(b, c ): a_inst = self class B: def auxmeth(d, e ): self # the B instance a_inst # the A instance return B This seems pretty natural to me (innermost scope takes precedence), and AFAIR this is also how it is done in Java. True. Net keystrokes are down in this method. Consider this: class A: def get_auxclass(b, c ): a_inst = self class B: @staticmethod #--- change def auxmeth(d, e ): self # -NOT- the B instance a_inst # the A instance return B What are the semantics here? Error, No 'self' allowed in staticmethod- wrapped functions. Or, the a instance, just like a_inst? Do you find no advantage to being able to give 'self' different names in different cases? -- http://mail.python.org/mailman/listinfo/python-list
Re: like py2exe, but on a mac
On Mon, 28 Jul 2008 19:51:26 +0200, Tommy Nordgren wrote: There is Platypus, a general open source program to wrap a script in an Macintosh (GUI) Application. Thanks. I tried Platypus, and it's close to what I want. But I still can't seem to get rid of the small Console window that pops up behind my Tkinter app. -- 09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0 -- pass it on -- http://mail.python.org/mailman/listinfo/python-list
Re: QOTW [was Re: Attack a sacred Python Cow]
On Jul 28, 9:07 am, Steven D'Aprano [EMAIL PROTECTED] cybersource.com.au wrote: On Sun, 27 Jul 2008 21:42:37 -0700, Russ P. wrote: +1 QOTW Do you realize what an insult that is to everyone else who has posted here in the past week? Actually I don't. I hadn't realised that when a person believes that somebody has made an especially clever, witty, insightful or fun remark, that's actually a put-down of all the other people whose remarks weren't quite as clever, witty, insightful or fun. But now that I've had this pointed out to me, why, I see insults everywhere! Tonight, my wife said to me that she liked my new shirt, so I replied What's the matter, you think my trousers are ugly? -- Steven No insult was intended. The writer stated that where Java minimizes bad, Python maximizes good. This is a non-trivial truth, and a non- trivial observation. Also, clever. I agreed and said so, and compliments go a long way. Do you? everywhere! Tonight, my wife said to me that she liked my new shirt, so I replied What's the matter, you think my trousers are ugly? Arf, arf. -- For my special power, I want immunity to insults. -- http://mail.python.org/mailman/listinfo/python-list