itools 0.13.3 released
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 itools is a Python library, it groups a number of packages into a single meta-package for easier development and deployment: itools.catalogitools.i18n itools.uri itools.cmsitools.ical itools.web itools.csvitools.resourcesitools.workflow itools.datatypes itools.rss itools.xhtml itools.gettextitools.schemas itools.xliff itools.handlers itools.stl itools.xml itools.html itools.tmx Changes: CSV - Be strict when parsing CSV files (check all lines have the same number of columns), by Piotr Macuk. [#263] Catalog - New format, much more compact. CMS - Speed-up write operations. - Add datatype Enumerate, by Hervé Cauwelier. [#304] - Update the French translation, by Hervé Cauwelier. [#303] Resources - - Download http://download.ikaaro.org/itools/itools-0.13.3.tar.gz Home http://www.ikaaro.org/itools Mailing list http://in-girum.net/mailman/listinfo/ikaaro Bug Tracker http://bugs.ikaaro.org - -- J. David Ibáñez Itaapy http://www.itaapy.com Tel +33 (0)1 42 23 67 45 9 rue Darwin, 75018 Paris Fax +33 (0)1 53 28 27 88 -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFET0A3qTbdUBYy+tIRAnbXAJ0ckpSdKW5oWgwUI1RBz+E+8J6+9gCggTQb 5oCka7wodMckiAyeqi8LYbI= =kYG0 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: how to browse using urllib2 and cookeilib the correct way
[EMAIL PROTECTED] wrote: can anybody explain, in the first case why i need to do two attempts. I would guess it's because redhat requires your browser to submit a session cookie with the login form. In the urllib2 example, the first request you make tries to submit login form data directly. Since it's your first hit on their site, you don't have a cookie yet. People browsing interactively would at least load the login page first before submitting it. Your twill example takes care of this by requesting a page before trying to login. That would be my guess. -- http://mail.python.org/mailman/listinfo/python-list
Introspection Class/Instance Name
Hello there, what method would you use to return the name of the class and/or instance introspectively eg. class Bollocks: def __init__( self ): print self.__method_that_returns_class_name__() print self.__method_that_returns_instance_name__() instance_of_bollocks= Bollocks() # Which outputs 'Bollocks' 'instance_of_bollocks' I have been scouring the 2.4 docs ... I am sure it is frustratingly simple thx in advance ** -- http://mail.python.org/mailman/listinfo/python-list
Re: how to browse using urllib2 and cookeilib the correct way
ok , got it . Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Introspection Class/Instance Name
*binarystar* wrote: Hello there, what method would you use to return the name of the class and/or instance introspectively eg. class Bollocks: def __init__( self ): print self.__method_that_returns_class_name__() print self.__method_that_returns_instance_name__() instance_of_bollocks= Bollocks() # Which outputs 'Bollocks' 'instance_of_bollocks' I have been scouring the 2.4 docs ... I am sure it is frustratingly simple thx in advance ** Hi, take a look at self.__class__.__name__ for the Class-name. HtH, Roland -- http://mail.python.org/mailman/listinfo/python-list
Re: Zope 3
This looks more or less like what I am looking for to learn Zope3! As is mentioned elsewhere in this thread Zope3 is *nothing* like Zope2 and after starting to learn the one, I knew nothing about the other. *Everything* is different - from the interface to the design methodologies. One thing Zope seems to keep pushing is extreme programming - until recently, I thought it is a joke, like extreme ironing, but it seems like a very popular style of programming. I am astounded by how much I need to learn to call myself a programmer! Anyway - If some of you can give me a little insight to what you use to develop on the web using Python, I'd appreciate it. I've heard good things about cherrypy, django, mod_python, zope, etc., etc. There is just so little time - I'd gladly sacrifice a little power / flexibility for an easier learning curve. This will be my first python web project... Thanks for the feedback - it helps a lot :) Derick -- http://mail.python.org/mailman/listinfo/python-list
Re: How to avoid using files to store intermediate results
André wrote: Now, I want to be able to test the code using the doctest module. I can't use exec as doctest.testmod() will be testing my entire application, not simply the code in the input window! While this works, I find it messy, as it creates some intermediate files. I was wondering if there was a better way to do things all in memory, in an OS independent way. Here's a manual setup you might be able to adapt: import doctest from cStringIO import StringIO sample = print hello hello hello 'hello' globs = {} out = StringIO() parser = doctest.DocTestParser() test = parser.get_doctest(sample, globs, noname, nofile, 0) runner = doctest.DocTestRunner(verbose=True) runner.run(test, out=out.write) print out.getvalue() Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Introspection Class/Instance Name
What about: py class A: py. def __init__(self): py. print self.__class__.__name__ py. print str(self) py. def __str__(self): py. return 'instance of %s' % self.__class__.__name__ py. py a = A() A instance of A py -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Alex Martelli wrote: What I think I'm trying to get at is that I believe that most situations where someone actually tries to do something in the base initialiser which requires calling a virtual method are probably also cases where the initialiser is doing too much: i.e. separating the construction/initialisation from actually doing something is usually a good idea. But why should that be? Template Method is perhaps the MOST generally useful design pattern -- why would it be any less useful in initialization than elsewhere?! Because it is error prone? Any method which is called from the constructor/initialiser has to operate correctly on an object which at that point is not fully constructed/initialised. So instead of having to write a method on a Foo object, your template method has to operate on a partial Foo. The danger is that you haven't clearly defined the partial Foo interface sufficiently and the method tries to use other parts of the object which haven't yet been set up. That situation gets worse when you have a class hierarchy as the subclass needs to know that it has to do complete its own initialisation before constructing the base class instead of afterwards, and if you are going to document that requirement, why not do it properly and split the construction in two? That's why I would go for the 2-phase construction: after the first phase you have an object which is fully initialised, just not yet used/connected/running. For example httplib.HTTPConnection does this: you construct the object with a host and port, but the actual connection is triggered by a separate object. I would suggest your example of a database connection belongs in that category: it should have an initial unconnected idle state and a separate connection. I think your example of a composite window building subwindows is the sort of use case I was asking for: it does sound tempting to construct the window and all its subwindows together. I'm happy to concede on that one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Zope 3
Derick van Niekerk wrote: Anyway - If some of you can give me a little insight to what you use to develop on the web using Python, I'd appreciate it. I've heard good things about cherrypy, django, mod_python, zope, etc., etc. There is just so little time - I'd gladly sacrifice a little power / flexibility for an easier learning curve. working through the Django tutorial shouldn't take you more than an hour or two (*): http://www.djangoproject.com/documentation/ turbogears also have some good tutorials: http://www.turbogears.org/docs/index.html /F *) depending on how much time you need to get things set up. if you just want to tinker, and are using windows, you can easily do it in 5-15 minutes: http://effbot.org/zone/django.htm#installing -- http://mail.python.org/mailman/listinfo/python-list
Re: Introspection Class/Instance Name
*binarystar* wrote: class Bollocks: def __init__( self ): print self.__method_that_returns_class_name__() print self.__method_that_returns_instance_name__() instance_of_bollocks = Bollocks() # Which outputs 'Bollocks' 'instance_of_bollocks' class Bollocks(object): def name_of_instance(self): return self instance_of_bollocks = Bollocks() print instance_of_bollocks.__class__.__name__ Bollocks print instance_of_bollocks.name_of_instance() self At the time when the method is called, 'self' is a perfectly valid name for the instance. Seriously though, how do you expect a method to decide if you do: another_name = instance_of_bollocks print another_name.name_of_instance() ??? which name should appear here ??? more = [another_name]*5 print more[2] ??? and what name here ??? and did you want a global name, or a local variable from some function and if so which function and at which stack level? Python does actually give you sufficient introspection to do this, but you have to write some fairly complex code to iterate through the namespaces you are interested in searching for the object. A much more reasonable solution is to give your object a name attribute: class Bollocks(object): def __init__(self, name): self.name = name instance_of_bollocks = Bollocks('Archimedes') print instance_of_bollocks.name Archimedes -- http://mail.python.org/mailman/listinfo/python-list
Nested Lists Assignment Problem
I wanna use nested lists as an array, but here's the problem: a = [[0]*3]*3 a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] a[0][0] = 1 a [[1, 0, 0], [1, 0, 0], [1, 0, 0]] Could anybody please explain to me why three values were change? I'm bewildered. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Lists Assignment Problem
Le Mercredi 26 Avril 2006 10:13, Licheng Fang a écrit : I wanna use nested lists as an array, but here's the problem: a = [[0]*3]*3 a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] a[0][0] = 1 a [[1, 0, 0], [1, 0, 0], [1, 0, 0]] Could anybody please explain to me why three values were change? I'm bewildered. Thanks! I guess is a probleme of reference. Write that instead: l = [ [0]*3 for i in xrange(3) ] cordialement, -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Lists Assignment Problem
Dennis Lee Bieber wrote: On 26 Apr 2006 01:13:20 -0700, Licheng Fang [EMAIL PROTECTED] declaimed the following in comp.lang.python: Could anybody please explain to me why three values were change? I'm bewildered. Thanks! http://www.aifb.uni-karlsruhe.de/Lehrangebot/Winter2000-01/E-Shop/Python/Doku/The%20Whole%20Python%20FAQ.htm#4.50 -- == [EMAIL PROTECTED] | Wulfraed Dennis Lee Bieber KD6MOG [EMAIL PROTECTED] | Bestiaria Support Staff == Home Page: http://www.dm.net/~wulfraed/ Overflow Page: http://wlfraed.home.netcom.com/ Thank you very much! But I still wonder why a nested assignment a = [[0]*3]*3 generates 3 references to the same list, while the commands below apparently do not. a = [0] * 2 a [0, 0] a[0] = 1 a [1, 0] -- http://mail.python.org/mailman/listinfo/python-list
Type-Def-ing Python
Dear Python Community, I have been trying to research how to type-def python. I want to type-def python so that I can use it as a static analyzer to check for bugs. I have been going over research on this field and I came upon Brett Cannon's thesis in which he tweaks the compiler and shows that type-defing python would not help the compiler achieve a 5% performace increase. Brett Cannon, Localized Type Inference of Atomic Types in Python: http://www.ocf.berkeley.edu/~bac/thesis.pdf I was wondering if anyone had his contact information so that I could might ask him for his source code and try to use type-defing as a bug-finder. With thanks, Brian -- http://mail.python.org/mailman/listinfo/python-list
Re: Type-Def-ing Python
If you are interested in static analysis for bug hunting purposes, then you might want to have a look at Pylint. Cheers, Aurélien. -- http://mail.python.org/mailman/listinfo/python-list
Python UPnP on Linux?
I am writing some client software that needs to accept connections from the Internet. So I am looking for a UPnP implementation for a client of an Internet gateway so I can request the NAT binding. Googling on this I have found win32 implementations and Twisted implementations yet I am looking for a way to do it on Linux WITHOUT Twisted. Who knows a pointer? Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Coming from delphi - looking for an IDE - willing to spend money
Eric3 is great IMHO. http://www.die-offenbachs.de/detlev/eric3.html -- http://mail.python.org/mailman/listinfo/python-list
logging problem
HI All, I am having an app that needs to display a lot of msgs. These msgs need to kept ina log. I have written it as : D EBUG =1 if DEBUG: import logging logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename='x.log', filemode='w') def DBG (s): if DEBUG: logging.debug(s) Then whereever i need i tried calling DBG(x) but i am getting error as: Traceback (most recent call last): File C:\Python24\lib\logging\__init__.py, line 712, in emit self.stream.write(fs % msg)ValueError: I/O operation on closed file Can anyone help me..i am new to python so plz help-- Regards,Shine Anne -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing Exceptions Across Threads
have you tried replacing : main = threading._MainThread() with main = threading.currentThread() ? (not sure if that will be sufficient) Well your way to pass exception between threads looks like I would have done myself. But I am no expert. Have you considered using stackless Python ? It provides a much safer and efficient threading model (thinking about your physics simulator). Of course, if you want not to block on blocking calls (socket stuff), real threads are a way to go. -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Duncan Booth wrote: Alex Martelli wrote: What I think I'm trying to get at is that I believe that most situations where someone actually tries to do something in the base initialiser which requires calling a virtual method are probably also cases where the initialiser is doing too much: i.e. separating the construction/initialisation from actually doing something is usually a good idea. But why should that be? Template Method is perhaps the MOST generally useful design pattern -- why would it be any less useful in initialization than elsewhere?! Because it is error prone? Programming *is* error prone. Any method which is called from the constructor/initialiser has to operate correctly any method has to operate correctly anyway !-) on an object which at that point is not fully constructed/initialised. In Python, when the __init__ method is called, the object is at least fully constructed. So instead of having to write a method on a Foo object, your template method has to operate on a partial Foo. The danger is that you haven't clearly defined the partial Foo interface sufficiently and the method tries to use other parts of the object which haven't yet been set up. If so, the worse thing that can happen is an exception - and you'll surely spot the problem really soon. That situation gets worse when you have a class hierarchy as the subclass needs to know that it has to do complete its own initialisation before constructing the base class instead of afterwards, and if you are going to document that requirement, why not do it properly and split the construction in two? It's *already* split : __new__ construct the object, __init__ initialize it. That's why I would go for the 2-phase construction: But that's already what you have. after the first phase you have an object which is fully initialised, just not yet used/connected/running. For example httplib.HTTPConnection does this: you construct the object with a host and port, but the actual connection is triggered by a separate object. If you look at file objects, they do try and open the file at init time. Is a net or db connection that different ? (snip) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Duncan Booth wrote: Alex Martelli wrote: What I think I'm trying to get at is that I believe that most situations where someone actually tries to do something in the base initialiser which requires calling a virtual method are probably also cases where the initialiser is doing too much: i.e. separating the construction/initialisation from actually doing something is usually a good idea. But why should that be? Template Method is perhaps the MOST generally useful design pattern -- why would it be any less useful in initialization than elsewhere?! Because it is error prone? Any method which is called from the constructor/initialiser has to operate correctly on an object which at that point is not fully constructed/initialised. So instead of having to write a method on a Foo object, your template method has to operate on a partial Foo. The danger is that you haven't clearly defined the partial Foo interface sufficiently and the method tries to use other parts of the object which haven't yet been set up. In Python, if you try to use an uninitialized member you get an AttributeError; I really don't see too much inherent danger here. If you make a mistake, the language tells you and you fix it. C++ and Java are worse since accessing uninitialized variables is a silent mistake, so it makes sense to avoid that kind thing in those languages. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
KeybordInterrupts and friends
Hello, I have a problem with the following code fragment : import sys while True: try: raw_input() except EOFError: print C-d except KeyboardInterrupt: print C-c The following behaviour seems bogus to me : [EMAIL PROTECTED]:~$ python test.py C-c C-c C-d C-d Traceback (most recent call last): File test.py, line 5, in ? raw_input() KeyboardInterrupt The crash happens when I type C-c another time (always *after* atleast one C-d has been issued). What's wrong ? My expectations ? CPython (2.3 and 2.4 on debian exhibit the same problem). Is this a FAQ ? Thanks, Aurélien. -- http://mail.python.org/mailman/listinfo/python-list
Re: Counting elements in a list wildcard
Edward Elliott wrote: John Machin wrote: On 25/04/2006 6:26 PM, Iain King wrote: iain = re.compile((Ia(i)?n|Eoin)) steven = re.compile(Ste(v|ph|f)(e|a)n) IMHO, the amount of hand-crafting that goes into a *general-purpose* phonetic matching algorithm is already bordering on overkill. Your method using REs would not appear to scale well at all. Also compare the readability of regular expressions in this case to a simple list: [Steven, Stephen, Stefan, Stephan, ...] Somehow I'm the advocate for REs here, which: erg. But you have some mighty convenient elipses there... compare: steven = re.compile(Ste(v|ph|f|ff)(e|a)n) steven = [Steven, Stephen, Stefen, Steffen, Stevan, Stephan, Stefan, Steffan] I know which I'd rather type. 'Course, if you can use a ready-built list of names... Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
bruno at modulix wrote: It's *already* split : __new__ construct the object, __init__ initialize it. That's why I would go for the 2-phase construction: But that's already what you have. Very good point. after the first phase you have an object which is fully initialised, just not yet used/connected/running. For example httplib.HTTPConnection does this: you construct the object with a host and port, but the actual connection is triggered by a separate object. If you look at file objects, they do try and open the file at init time. Is a net or db connection that different ? Well, yes, since the whole point is that we are discussing overriding methods and I bet you haven't subclassed Python file objects recently. For network or database connections you do want to supply your own handlers for things like authentication. -- http://mail.python.org/mailman/listinfo/python-list
Re: MS VC++ Toolkit 2003, where?
Robert Kern [EMAIL PROTECTED] writes: Martin v. Löwis wrote: Robert Kern wrote: Oh, that's right, you need an import library for Python24.dll . That shouldn't be a problem: that library is included with Python. For mingw, too? I.e. a .a not a .lib? It is possible to load a .dll in mingw. -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk -- http://mail.python.org/mailman/listinfo/python-list
Re: Drawing charts and graphs.
I'm quite satisfied with MatPlotLib for scientific plotting. ReportLab has also a very good package for high quality PDF production incl. graphics. For more interactive, Grace plotter has a good Graceplot.py python front-end. -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Lists Assignment Problem
Licheng Fang wrote: I wanna use nested lists as an array, but here's the problem: a = [[0]*3]*3 a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] a[0][0] = 1 a [[1, 0, 0], [1, 0, 0], [1, 0, 0]] Could anybody please explain to me why three values were change? I'm bewildered. Thanks! http://pyfaq.infogami.com/how-do-i-create-a-multidimensional-list /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Nested Lists Assignment Problem
Licheng Fang wrote: But I still wonder why a nested assignment a = [[0]*3]*3 generates 3 references to the same list, while the commands below apparently do not. that's because they're replacing a list item, rather than modifying it. a = [0] * 2 a [0, 0] - now you have two references to the same integer. a[0] = 1 - now you've *replaced* the first integer with another integer. a [1, 0] if you do the same thing with lists, it behaves in exactly the same way: a = [[0]*3]*3 a [[0, 0, 0], [0, 0, 0], [0, 0, 0]] -- three references to the same list a[0] = [1, 2, 3] -- replace the first list a [[1, 2, 3], [0, 0, 0], [0, 0, 0]] however, if you modify the *shared* object, the modification will of course be visible everywhere that object is used: a[1][0] = hello -- modified the first item in the shared list a [[1, 2, 3], ['hello', 0, 0], ['hello', 0, 0]] /F -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Duncan Booth wrote: bruno at modulix wrote: It's *already* split : __new__ construct the object, __init__ initialize it. That's why I would go for the 2-phase construction: But that's already what you have. Very good point. after the first phase you have an object which is fully initialised, just not yet used/connected/running. For example httplib.HTTPConnection does this: you construct the object with a host and port, but the actual connection is triggered by a separate object. If you look at file objects, they do try and open the file at init time. Is a net or db connection that different ? Well, yes, since the whole point is that we are discussing overriding methods and I bet you haven't subclassed Python file objects recently. And you win !-) Anyway, I didn't suggest that opening a connection to whatever should be done in the __init__ - I just wanted to point that acquiring a resource in the initializer (and freeing it in the finalizer) can sometimes be perfectly sensible. wrt/ initializer as a template method, I still fail to see why this should be a problem. The fact that one should avoid doing anything else than initialization in the initializer is just plain old common sense IMHO - the use of calls to other methods that can possibly be overriden in a subclass is orthogonal. And if the guy writing the subclass do stupid things when overridding these methods, well, too bad for him - but as the author of the base class, that's definitively not my problem (given proper documentation of course) Trying to protect stupid programmers from doing stupid things is a total waste of time anyway. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: how to save python interpreter's command history
If you're using an operating system supporting the readline utility try: http://www.python.org/doc/current/tut/node15.html I am using a slightly modified version of the given example. The last time I checked the size of my history file it had 4k+ entries. Regards, Patrick -- 2 does not equal 3. Even for large values of 2. -- http://mail.python.org/mailman/listinfo/python-list
not quite 1252
I'm trying to import text from an open office document (save as .sxw and read the data from content.xml inside the sxw-archive using elementtree and such tools). The encoding that gives me the least problems seems to be cp1252, however it's not completely perfect because there are still characters in it like \93 or \94. Has anyone handled this before? I'd rather not reinvent the wheel and start translating strings 'by hand'. Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: The whitespaceless frontend
Edward Elliott [EMAIL PROTECTED] wrote: If compactness is all you want, shorten self to s. Personally I like 'me' as it's both shorter and more vernacular: def do_GET (me): me.send_response (200, ok) Absolutely. I've written quite a lot of code (which I wasn't expecting anyone else to maintain) using 'I' for the same reasons. Plus, it's even shorter in terms of characters (if not keystrokes), stands out reasonably well, and for how I read it makes for better English grammar (eg I.send_response(...) -- I guess it depends on whether you're doing the mental transformation of method call to message passing). I stopped doing this when I started (a) maintaining other people's Python code, and having them maintain mine and (b) using editors whose Python syntax highlighting coloured self as special. Readability counts wins over a couple of extra characters. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- 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: KeybordInterrupts and friends
[EMAIL PROTECTED] wrote: Hello, I have a problem with the following code fragment : import sys while True: try: raw_input() except EOFError: print C-d except KeyboardInterrupt: print C-c The following behaviour seems bogus to me : [EMAIL PROTECTED]:~$ python test.py C-c C-c C-d C-d Traceback (most recent call last): File test.py, line 5, in ? raw_input() KeyboardInterrupt The crash happens when I type C-c another time (always *after* atleast one C-d has been issued). What's wrong ? My expectations ? CPython (2.3 and 2.4 on debian exhibit the same problem). Is this a FAQ ? maybe consider signal.signal(signal.SIGINT,... -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing Exceptions Across Threads
Adam Mullins wrote: Hello, I'm writing a physics simulator back-end with a built-in, threaded server that for the moment is quite simple. I've faced a few problems in writing this code, however, as it's the first time I've played with threading. For the moment, everything works decently, but I need (or rather, want) a method for passing caught exceptions in sub-threads to the main thread to be raised there. Although this solution isn't the only one, I feel it will be the most elegant (the thread/class will be called inside the main module within a try/except structure, which makes the program a bit more modular, in my opinion, and cleaner). Here is my code so far: http://rafb.net/paste/results/UESOWB24.html You can see near the top where I clumsily tried to a hack a function into threading._MainThread, in the hopes that if it were called from a sub-thread it would execute in the main thread. This is seemingly not so. Many thanks for any help. The CallQueue and BackgroundCall.get_return() do that exception transfer already by default: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491281 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491280 -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: I have problems with creating the classic game Wumpus. the file: http://esnips.c
I have sent it to you now. Thanks for looking at it. -- http://mail.python.org/mailman/listinfo/python-list
Re: I have problems with creating the classic game Wumpus. the file: http://esnips.c
i just mailed it to you. Thanks for looking at it. -- http://mail.python.org/mailman/listinfo/python-list
Re: help finding
Gary Wessle wrote: Hi I am going through some tutorials, how do I find out about running a script from the python prompt? is there a online ref and how to access it? if you really don't want to start from OS prompt do execfile('myscript.py') -robert -- http://mail.python.org/mailman/listinfo/python-list
win32com short path name on 2k
Hi people, Using win32com on 2k SP3... import win32com.client as w32c fc = w32c.Dispatch('Featurecam.Application') fc.InstallPath u'C:\\PROGRA~1\\FEATUR~1' Using win32com on XP Professional SP2... import win32com.client as w32c fc = w32c.Dispatch('Featurecam.Application') fc.InstallPath u'C:\\Program Files\\FeatureCAM' Why the short vs long names? -- bytecolor -- http://mail.python.org/mailman/listinfo/python-list
Re: win32com short path name on 2k
bytecolor wrote: Hi people, Using win32com on 2k SP3... import win32com.client as w32c fc = w32c.Dispatch('Featurecam.Application') fc.InstallPath u'C:\\PROGRA~1\\FEATUR~1' Using win32com on XP Professional SP2... import win32com.client as w32c fc = w32c.Dispatch('Featurecam.Application') fc.InstallPath u'C:\\Program Files\\FeatureCAM' Why the short vs long names? That depends on how the com application was registered. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: KeybordInterrupts and friends
Thanks Robert. But I'm not trying something at all with this, only asking if it is a bug (and it looks like one). I suspect too, that it is related to signal handling. Cheers, Aurélien. -- http://mail.python.org/mailman/listinfo/python-list
wxpython warnings
I have a wxpython program that displays TIF images. Sometimes it will encounter a tag the tiff loader cant handle. Rather than silently ignoring it, it pops up a window: Python Warning unknown field with tag blah blah I don't want it to do this, but I can't work out how to turn it off. Anyone know? Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: Introspection Class/Instance Name
*binarystar* wrote: Hello there, what method would you use to return the name of the class and/or instance introspectively eg. class Bollocks: def __init__( self ): print self.__method_that_returns_class_name__() print self.__method_that_returns_instance_name__() instance_of_bollocks= Bollocks() # Which outputs 'Bollocks' 'instance_of_bollocks' self.__class__ is good for getting instance's top class yet Python is weak on introspecting the namespace of its definitions - funcs and classes. it stops at sys._getframe().f_code.co_name thus, e.g. for things like super() you need always to re-type the class name where you just write in!? maybe Py3K brings more ? Maybe There could be compiler-variables like __CLASS__ , __FUNC__ for things like super(), recursion etc. (compare http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/491265 ) -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: not quite 1252
Anton Vredegoor wrote: I'm trying to import text from an open office document (save as .sxw and read the data from content.xml inside the sxw-archive using elementtree and such tools). The encoding that gives me the least problems seems to be cp1252, however it's not completely perfect because there are still characters in it like \93 or \94. Has anyone handled this before? this might help: http://effbot.org/zone/unicode-gremlins.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: KeybordInterrupts and friends
[EMAIL PROTECTED] wrote: Thanks Robert. But I'm not trying something at all with this, only asking if it is a bug (and it looks like one). I suspect too, that it is related to signal handling. Cheers, Aurélien. you not protected all the time during the loop -robert -- http://mail.python.org/mailman/listinfo/python-list
Re: Building a Dynamic Library (libpython.so) for Python 2.4.3 Final
Dean wrote: I've been trying to make python a dynamic library. I downloaded Python 2.4.3 Final from the Python web site and I cannot get it to create the library. I've tried using the directive: --enable-shared and --enable-shared=yes and both of them had the same effect of creating a bunch of parts of the python interpreter in .so format but not in creating a single libpython2.4.so.X.Y file. I could probably hack something together using ar but I would prefer to do it correctly by setting some options. I'm compiling under OpenBSD 3.5. Well, I just confirmed that ./configure --enable-shared results in a libpython2.4.so.1 (and a libpython2.4.so) on FreeBSD 4.x. The result runs the regression test suite without significant problems (the test box didn't have a 2.4 installation). A quick look at the configure script suggests that --enable-shared should work on OpenBSD. While I believe that there's actually an OpenBSD based Python buildbot (though OpenBSD 3.[89] I think) running, I doubt that this configuration is tested there. If you don't get any other responses, send me a copy of the full make log (ie make make.log 21) and I'll compare it to the log from my test build. - Andrew I MacIntyre These thoughts are mine alone... E-mail: [EMAIL PROTECTED] (pref) | Snail: PO Box 370 [EMAIL PROTECTED] (alt) |Belconnen ACT 2616 Web:http://www.andymac.org/ |Australia -- http://mail.python.org/mailman/listinfo/python-list
Inherit from array
Hi there. I'm trying to create a simple class called Vector which inherit from array. class Vector(array): def __init__(self,length): initialize a vector of random floats of size length. floats are in interval [0;1] array.__init__(self,'f') for _ in xrange(length): self.apprend(random()) but then : v = Vector(10) TypeError: array() argument 1 must be char, not int Well, I guess it means array's __init__ method is not called with proper arguments ... It seems there is a problem with __init__ overloading, like when I call Vector(x), it directly calls __init__ method from array rather than the one defined in Vector class. Anyone got an idea on this ? -- http://mail.python.org/mailman/listinfo/python-list
pyumlgraph for multiple files.
Hello, I had used pyumlgraph to generate dot files for single python script. Is it possible to use pyumlgraph to generate dot files for multiple python scripts ??? Or is it automatically done if i generate a dot file for the final python script that imports all other files? Thanks Deepan Chakravarthy N www.codeshepherd.com -- http://mail.python.org/mailman/listinfo/python-list
Importing modules through directory shortcuts on Windows
Recently, I became responsible for maintaining some Python code, which was organized as follows: user/pylib ui ... project2/pylib ui ... project3/pylib ui ... python-packages/user = /user/pylib project2 = /project2/pylib project3 = /project3/pylib The idea is that python-packages is added to sys.path and then every project can import the library package from every other project. NOTE: I think that this structure is crazy but I'm just the poor maintenance programmer. Anyway, the problem is that Windows does not have a symlink facility to accommodate this (AFAIK) and the Python import mechanism does not resolve shortcuts. Therefore, I wrote a very simple import hook to get around that problem. If you are interested, the code is here: http://www.sweetapp.com/shortcut/shortcutimporter.py BTW, does anyone else think that this functionality should be part of core Python? Cheers, Brian -- http://mail.python.org/mailman/listinfo/python-list
scipy and py2exe
I am trying to package my application with py2exe. Unfortunately it uses both scipy/numpy and numarray so I'm having to jump through a lot of hoops to get it going. I'm getting problems packaging an app that uses only scipy. See below. Thanks! Janto ===setup.py=== from distutils.core import setup import py2exe import sys sys.argv.append('py2exe') setup( windows = [{ script: test.py, }], options = dict( py2exe = dict( ascii=1, skip_archive = 1, packages = [scipy], excludes = [ '_gtkagg', '_tkagg', 'tcl', 'Tkconstants', 'Tkinter', 'tcl', ], ) ), ) ===test.py=== import time import scipy print scipy.array([1,2,3]) time.sleep(1) ===error file=== import core - failed: No module named _internal import lib - failed: 'module' object has no attribute '_ARRAY_API' import linalg - failed: 'module' object has no attribute '_ARRAY_API' import dft - failed: 'module' object has no attribute '_ARRAY_API' import random - failed: 'module' object has no attribute 'dtype' Traceback (most recent call last): File test.py, line 2, in ? File scipy\__init__.pyc, line 25, in ? numpy name space File numpy\__init__.pyc, line 49, in ? File numpy\add_newdocs.pyc, line 2, in ? `ï¾Cc File numpy\lib\__init__.pyc, line 5, in ? File numpy\lib\type_check.pyc, line 8, in ? File numpy\core\__init__.pyc, line 6, in ? File numpy\core\umath.pyc, line 12, in ? File numpy\core\umath.pyc, line 10, in __load AttributeError: 'module' object has no attribute '_ARRAY_API' -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
TG wrote: Hi there. I'm trying to create a simple class called Vector which inherit from array. Which array ? [EMAIL PROTECTED] ~ $ python Python 2.4.2 (#1, Feb 9 2006, 02:40:32) [GCC 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type help, copyright, credits or license for more information. array Traceback (most recent call last): File stdin, line 1, in ? NameError: name 'array' is not defined -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing modules through directory shortcuts on Windows
Brian Quinlan wrote: Recently, I became responsible for maintaining some Python code, which was organized as follows: user/pylib ui ... project2/pylib ui ... project3/pylib ui ... python-packages/user = /user/pylib project2 = /project2/pylib project3 = /project3/pylib The idea is that python-packages is added to sys.path and then every project can import the library package from every other project. NOTE: I think that this structure is crazy but I'm just the poor maintenance programmer. Anyway, the problem is that Windows does not have a symlink facility to accommodate this (AFAIK) and the Python import mechanism does not resolve shortcuts. Therefore, I wrote a very simple import hook to get around that problem. If you are interested, the code is here: http://www.sweetapp.com/shortcut/shortcutimporter.py BTW, does anyone else think that this functionality should be part of core Python? I wonder (but haven't yet figured out) if something similar can be achived with pkgutil and one or more .pkg files. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW and Python
Alex Martelli wrote: sturlamolden [EMAIL PROTECTED] wrote: Robert Kern wrote: Dunno. Depends on the machine. Depends on the program. Depends on how the interpreter and any extension modules and underlying libraries were built. Depends on which Linux and which Windows. I'm sorry, but your question is a non sequitur. I don't understand its relevance to this thread. The relevance: Python is built with GCC on Linux. Do you or do you not see a performance hit on Linux? MinGW is GCC. Will you get a performance hit when building Python with MinGW? I cannot predict this, though it would be great if somebody who does have both VS2003 and mingw could give it a try. What I did just post on another thread over the last couple of days is about MacOSX, which also uses gcc: 14% faster pybench using Python 2.4.3 under Win2000 under Parallels Workstation beta, compared to 2.4.3 Universal directly on MacOSX -- the standard build of 2.4.3 in either cause, i.e., the one built with MS compilers on Windows, vs the one built with Apple's gcc on MacOSX. Alex Please when quoting such benchmarks include gcc version. gcc = 4.1 is supposed to have a lot of performance improvements. This is the current release. Since mingw is usually current, I haven't checked, but they may be using 4.1 now. -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython warnings
I had a similar but simple problem (the file was missing) and had to check by hand before calling wxPython. Can you check the tag by hand before calling wxPython ? Philippe Iain King wrote: I have a wxpython program that displays TIF images. Sometimes it will encounter a tag the tiff loader cant handle. Rather than silently ignoring it, it pops up a window: Python Warning unknown field with tag blah blah I don't want it to do this, but I can't work out how to turn it off. Anyone know? Iain -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
from array import array class Vector(array): def __init__(self,size): print pouet array.__init__('f') print pouet v = Vector('c') print repr(v) will output : pouet pouet array('c') -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
I think he did from array import * Philippe bruno at modulix wrote: TG wrote: Hi there. I'm trying to create a simple class called Vector which inherit from array. Which array ? [EMAIL PROTECTED] ~ $ python Python 2.4.2 (#1, Feb 9 2006, 02:40:32) [GCC 3.4.5 (Gentoo 3.4.5, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 Type help, copyright, credits or license for more information. array Traceback (most recent call last): File stdin, line 1, in ? NameError: name 'array' is not defined -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW and Python
Neal Becker wrote: What I did just post on another thread over the last couple of days is about MacOSX, which also uses gcc: 14% faster pybench using Python 2.4.3 under Win2000 under Parallels Workstation beta, compared to 2.4.3 Universal directly on MacOSX -- the standard build of 2.4.3 in either cause, i.e., the one built with MS compilers on Windows, vs the one built with Apple's gcc on MacOSX. Please when quoting such benchmarks include gcc version. gcc = 4.1 is supposed to have a lot of performance improvements. This is the current release. Since mingw is usually current, I haven't checked, but they may be using 4.1 now. does the standard build of 2.4.3 in either case do you have trouble understanding ? (what makes you think that 2.4.3 for windows is compiled with the best possible compiler for the windows environment?) /F -- http://mail.python.org/mailman/listinfo/python-list
blob problems in pysqlite
Hi there. I'm a long-time lurker and (I think) first time poster. Only relatively new to python, and I'm trying to get pysqlite to work with binary data, and having a tough time of it. I want to set up a table with: - a URL, - some filenames related to that URL, - and some simple generated HTML. Problem is, when I try to do this, and query, say, the filenames from the filename field 'Images', I'm not getting a result. Just []... I've been googling this one for days (documentation for this seems really scant), and I've tried a whole bunch of things, but my code as it is now is attached. Can anyone give me some idea what i'm doing wrong (or if this is indeed possible)? Any and all help much appreciated. Cheers, Al. #script starts from pysqlite2 import dbapi2 as sqlite HTMLoutputFile = open('ImageResults.html', 'wb') cPickle.dump(OutputHTML, HTMLoutputFile) # outputHTML is a standard html page HTMLoutputFile.close() DBfilelistFile = open('DBFilesList.txt', 'wb') cPickle.dump(DBfilelist, DBfilelistFile) # DBfileList is a list of filenames in the form ['XXX.jpg', 'XXX.jpg' etc] DBfilelistFile.close() DBURL = 'http://www.myhomepage.html' blobdata = open('ImageResults.html', 'rb').read() blobfiles = open('DBFilesList.txt', 'rb').read() db = sqlite.connect(ImageInfoDatabase.db) c = db.cursor() try: c.execute(create table FileURLInfo (URL CHAR(100), Images, HTML)) except: print 'database exists' c.execute(INSERT INTO FileURLInfo VALUES (?,?,?);, (DBURL, sqlite.Binary(blobfiles), sqlite.Binary(blobdata)),) c.execute(select Images from FileURLInfo where URL = 'http://www.myhomepage.html',) DBImageResult = c.fetchall() print DBImageResult #script ends -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW and Python
Neal Becker wrote: What I did just post on another thread over the last couple of days is about MacOSX, which also uses gcc: 14% faster pybench using Python 2.4.3 under Win2000 under Parallels Workstation beta, compared to 2.4.3 Universal directly on MacOSX -- the standard build of 2.4.3 in either cause, i.e., the one built with MS compilers on Windows, vs the one built with Apple's gcc on MacOSX. Please when quoting such benchmarks include gcc version. gcc = 4.1 is supposed to have a lot of performance improvements. This is the current release. Since mingw is usually current, I haven't checked, but they may be using 4.1 now. what part of the standard build of 2.4.3 in either case do you have trouble understanding ? (what makes you think that 2.4.3 for windows is compiled with the best possible compiler for the windows environment?) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython warnings
Philippe Martin wrote: I had a similar but simple problem (the file was missing) and had to check by hand before calling wxPython. Can you check the tag by hand before calling wxPython ? Philippe Hi, also I have the same problem with g3/g4 images. My solution was convert that image *before* to .png before... Very bad hack, but work. I think that is an internal wxWidgets message (warning), passed to the wxPython subsystem. Have you tried to wrote to the wxpython ml? Michele -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
Obviously, there is something I didn't catch in python's inheritance. from array import array class Vector(array): def __init__(self,size): print self.typecode array.__init__(self,'f') v = Vector('c') c Here, it says the typecode is 'c' - I thought such an information was initalized during the array.__init__(self,'f') but obviously I was wrong. Maybe the typecode is defined before, during the call to __new__ method ... But here i'm getting lost. -- http://mail.python.org/mailman/listinfo/python-list
Re: blob problems in pysqlite
[EMAIL PROTECTED] wrote: Hi there. I'm a long-time lurker and (I think) first time poster. Only relatively new to python, and I'm trying to get pysqlite to work with binary data, and having a tough time of it. [...] It seems to me that you're using pysqlite correctly. Where exactly is the problem? Is the fetchall() not delivering what you think it should? If so, please explain what exactly it yields, and what you expect it to yield. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
A defense for bracket-less code
Found in a style guide (http://www.artlogic.com/careers/styleguide.html) --- Another case where unnecessary braces should be used is when writing an empty while loop: while (*p++ = *q++) { // this loop intentionally left empty... } instead of the form that is more commonly found: while (*p++ = *q++); By prohibiting this common loop format, we can easily check for cases where legal (but wrong) code like: int i = 0; while (i++ kLoopLimit); { myBuffer[i] = 0; } performs a loop with no body, then executes the intended body of the loop exactly once. Python programmers can stop chuckling now. --- Don. -- http://mail.python.org/mailman/listinfo/python-list
Re: I have problems with creating the classic game Wumpus. the file: http://esnips.c
connyledin wrote: Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file: http://esnips.com/webfolder/b71bfe95-d363-4dd3-bfad-3a9e36d0 What i have the biggest problems with now is between line 8 and 23. Perhaps you could post those lines so we get an idea of what's going wrong. You also really need to explain what exactly you are hoping to achieve, and in what way it isn't working. I don't think anybody is likely to give you a full solution because that would defeat the object. -- Ben Sizer -- http://mail.python.org/mailman/listinfo/python-list
Re: Importing modules through directory shortcuts on Windows
Brian Quinlan wrote: Anyway, the problem is that Windows does not have a symlink facility to accommodate this (AFAIK) and the Python import mechanism does not resolve shortcuts. Windows does have the equivalent of symlinks provided you are running on NTFS with Windows 2000 or later (Google for 'XP junction'). However, by default the system provides no support for manipulating junction points, so they are only really useful in an environment where you can control the tools on the system, not something you can expect to use on arbitrary systems. -- http://mail.python.org/mailman/listinfo/python-list
RE: blob problems in pysqlite
[EMAIL PROTECTED] | I'm a long-time lurker and (I think) first time poster. | Only relatively new to python, and I'm trying to get pysqlite to work | with binary data, and having a tough time of it. | I want to set up a table with: | - a URL, | - some filenames related to that URL, | - and some simple generated HTML. | | Problem is, when I try to do this, and query, say, the filenames from | the filename field 'Images', I'm not getting a result. Just []... | I've been googling this one for days (documentation for this seems | really scant), and I've tried a whole bunch of things, but my code as | it is now is attached. Just to confirm, I slightly reformatted your code so that it would run without your data, guessing from your comments what the input data would be, and it ran fine. I'm a little bemused at the way you're doing things, but as Gerhard said elsewhere, you don't seem to be doing anything wrong. code import cPickle from pysqlite2 import dbapi2 as sqlite # # TJG: Added sample inputs, hopefully representative # # outputHTML is a standard html page OutputHTML = htmlbody/body/html # DBfileList is a list of filenames in the form ['XXX.jpg', 'XXX.jpg' etc] DBfilelist = ['xxx.jpg', 'yyy.jpg'] HTMLoutputFile = open('ImageResults.html', 'wb') cPickle.dump(OutputHTML, HTMLoutputFile) HTMLoutputFile.close() DBfilelistFile = open('DBFilesList.txt', 'wb') cPickle.dump(DBfilelist, DBfilelistFile) DBfilelistFile.close() DBURL = 'http://www.myhomepage.html' blobdata = open('ImageResults.html', 'rb').read() blobfiles = open('DBFilesList.txt', 'rb').read() # # TJG: Used :memory: db to simplify slightly # db = sqlite.connect(:memory:) c = db.cursor() c.execute(create table FileURLInfo (URL CHAR(100), Images, HTML)) c.execute(INSERT INTO FileURLInfo VALUES (?,?,?);, (DBURL, sqlite.Binary(blobfiles), sqlite.Binary(blobdata)),) c.execute(select Images from FileURLInfo where URL = 'http://www.myhomepage.html',) DBImageResult = c.fetchall() print DBImageResult /code gives me: [(read-write buffer ptr 0x00AD47D8, size 36 at 0x00AD47B8,)] Can you clarify a bit, give some sample of your data, etc? TJG This e-mail has been scanned for all viruses by Star. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Python UPnP on Linux?
Paul Sijben enlightened us with: Googling on this I have found win32 implementations and Twisted implementations yet I am looking for a way to do it on Linux WITHOUT Twisted. Twisted is Open Source, so you could browse the source and see how they do it. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
wxPython and twisted problem
Hi, I'm a university student creating a python Chat server and client using twisted. The server works great. However I'm trying to create the client with a gui using wxpython and twisted. The code for the client is attached bellow. I'm working with a partner and he already tried posting our problem on comp.lang.python but we didn't receive a successful reply so I thought I would try the mailing list. Here's the problem: I can get my client to connect to my server, but can't get it to disconnect or send messages to the server.I am getting the following error when I click on the 'Disconnect' button - AttributeError: 'NoneType' object has no attribute 'loseConnection'I have attached the code for the client below this.We are both fairly new to Python so would appreciate any help anyone can offer.Thanks, Chris Peter client.py--from wxPython.wx import *import wxfrom twisted.internet import wxreactorwxreactor.install()from twisted.internet import reactorfrom twisted.internet.protocol import Protocol, ClientCreatorclass imApp(wxApp, Protocol): def buildMe(self): frame = wx.Frame(None, title=IM Client, size=(800, 550)) bkg = wx.Panel(frame) global ipAdd global portNo global messages global newMsg ipAddLab = wx.StaticText(bkg, -1, 'IP Address: ') ipAdd = wx.TextCtrl(bkg) ipAdd.SetToolTipString('Please enter the server IP addresshere.') spacer1 = wx.StaticText(bkg, -1, ' ') portNoLab = wx.StaticText(bkg, -1, 'Port No: ') portNo = wx.TextCtrl(bkg) portNo.SetToolTipString('Please enter the port number theserver is using here.') spacer2 = wx.StaticText(bkg, -1, ' ') connectButton = wx.Button(bkg, label='Connect') connectButton.SetToolTipString('Click this button to connect tothe server.') connectButton.Bind(wx.EVT_BUTTON, self.connectMe) disconnectButton = wx.Button(bkg, label='Disconnect') disconnectButton.SetToolTipString('Click this button todisconnect from the server.') disconnectButton.Bind(wx.EVT_BUTTON, self.disconnectMe) messages = wx.TextCtrl(bkg, style=(wx.TE_MULTILINE |wx.HSCROLL)) newMsg = wx.TextCtrl(bkg) sendButton = wx.Button(bkg, label='Send') sendButton.SetToolTipString('Click this button to send amessage to the server.') sendButton.Bind(wx.EVT_BUTTON, self.sendMe) hbox1 = wx.BoxSizer() hbox1.Add(ipAddLab, proportion=0, flag=wx.EXPAND) hbox1.Add(ipAdd, proportion=0, flag=wx.EXPAND) hbox1.Add(spacer1, proportion=0, flag=wx.EXPAND) hbox1.Add(portNoLab, proportion=0, flag=wx.EXPAND) hbox1.Add(portNo, proportion=0, flag=wx.EXPAND) hbox1.Add(spacer2, proportion=0, flag=wx.EXPAND) hbox1.Add(connectButton, proportion=0, flag=wx.LEFT, border=5) hbox1.Add(disconnectButton, proportion=0, flag=wx.LEFT,border=5) hbox2 = wx.BoxSizer() hbox2.Add(newMsg, proportion=1, flag=wx.EXPAND | wx.LEFT |wx.LEFT | wx.LEFT, border=5) hbox2.Add(sendButton, proportion=0, flag=wx.LEFT, border=5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(hbox1, proportion=0, flag=wx.EXPAND | wx.ALL,border=5) vbox.Add(messages, proportion=1, flag=wx.EXPAND | wx.LEFT |wx.LEFT | wx.LEFT, border=5) vbox.Add(hbox2, proportion=1, flag=wx.EXPAND | wx.ALL,border=5) bkg.SetSizer(vbox) ipAdd.WriteText('localhost') portNo.WriteText('1234') frame.Show(true) return true def sendMe(self, e): msg = newMsg.GetValue() + '\n' messages.WriteText(msg) newMsg.SetValue('') def disconnectMe(self, e): messages.WriteText('Disconnecting from server...\n') self.transport.loseConnection() def connectMe(self, e): messages.WriteText('Connecting to server...\n') c = ClientCreator(reactor, imApp) ip = str(ipAdd.GetValue()) port = int(portNo.GetValue()) c.connectTCP(ip, port)def mainProg(): app = imApp(0) app.buildMe() reactor.registerWxApp(app) reactor.run()if __name__ == '__main__': mainProg() -- http://mail.python.org/mailman/listinfo/python-list
Re: not quite 1252
Fredrik Lundh wrote: Anton Vredegoor wrote: I'm trying to import text from an open office document (save as .sxw and read the data from content.xml inside the sxw-archive using elementtree and such tools). The encoding that gives me the least problems seems to be cp1252, however it's not completely perfect because there are still characters in it like \93 or \94. Has anyone handled this before? this might help: http://effbot.org/zone/unicode-gremlins.htm Thanks a lot! The code below not only made the strange chars go away, but it also fixed the xml-parsing errors ... Maybe it's useful to someone else too, use at own risk though. Anton from gremlins import kill_gremlins from zipfile import ZipFile, ZIP_DEFLATED def repair(infn,outfn): zin = ZipFile(infn, 'r', ZIP_DEFLATED) zout = ZipFile(outfn, 'w', ZIP_DEFLATED) for x in zin.namelist(): data = zin.read(x) if x == 'contents.xml': zout.writestr(x,kill_gremlins(data).encode('cp1252')) else: zout.writestr(x,data) zout.close() def test(): infn = .sxw outfn = 'dg.sxw' repair(infn,outfn) if __name__=='__main__': test() -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyrex installation on windows XP: step-by-step guide
Julien Fiore wrote: Do you wand to install Pyrex on Windows ? Here is a step-by-step guide explaining: A) how to install Pyrex on Windows XP. B) how to compile a Pyrex module. Julien Fiore, U. of Geneva Thanks. One detail missing : for this (step b3) to work smoothly, one needs to make sure that (a copy of) eg python24.dll resides in Python24\libs\ --- ### A) Pyrex installation on Windows XP ### # step A.1 # Install Python (we used version 2.4.2) # step A.2 # Run the windows installer for Pyrex (e.g. Pyrex-0.9.3.1.win32.exe), available on the Pyrex homepage (http://www.cosc.canterbury.ac.nz/~greg/python/Pyrex/) # step A.3 # Install Mingw, the gcc compiler for Windows, available at http://www.mingw.org/download.shtml. (we downloaded the file MinGW-5.0.2.exe and installed only the base tool (this includes mingw-runtime 3.9, w32api-3.6, binutils 2.15.91 and gcc-core 3.4.2). Add Mingw path (C:\MinGW\bin) to the Windows Path environment variable. If you already have cygwin installed, add C:\MinGW\bin before the Cygwin path. # step A.4 # Create or edit the file c:/Python2x/Lib/distutils/distutils.cfg and put the following into it: [build] compiler = mingw32 --- ### B) Create a Pyrex module ### # step B.1 # Create a working directory (e.g. D:\pyrex_module\). Write a pyrex module and save it with a pyx extension (e.g. primes.pyx, code available on the Pyrex homepage) # step B.2 # Write the following python script and save it as setup.py in your working directory. from distutils.core import setup from distutils.extension import Extension from Pyrex.Distutils import build_ext setup( name = PyrexGuide, ext_modules=[ Extension(primes, [primes.pyx]) ], cmdclass = {'build_ext': build_ext} ) If you want to compile several modules, duplicate the line starting with Extension and replace primes by your module names. # step B.3 # In your working directory, create a batch file called build_and_install.bat containing the following lines, where PythonXX should be replaces by your Python version (e.g. Python24). C:\Python24\python.exe setup.py build_ext install pause To run the batch, double-click the file. You will see many Warning messages during the building process: do not worry, it is normal. # step B.4 # Mission completed. The file primes.pyd (a pyd is a Python Extension DLL, equivalent of .so in Unix) is now located in C:\Python24\Lib\site-packages and the primes module is available in Python. In your working directory, you can delete the file primes.c and the build folder created by the building process. Test your new module at the python shell: import primes primes.primes(10) [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] -- http://mail.python.org/mailman/listinfo/python-list
Re: A defense for bracket-less code
wrong group -- http://mail.python.org/mailman/listinfo/python-list
Re: KeybordInterrupts and friends
I know it is racey, but the bug is not the race (iow : it is not a matter of pressing twice C-c very quickly). It happens all the time. I let enough time between the key strokes to let the program wait on raw_input. Or maybe you have something else in mind. Care to expand ? Thanks, Aurélien. -- http://mail.python.org/mailman/listinfo/python-list
Query : sys.excepthook exception in Python
Hi, Sometimes during execution of python scripts below mentioned error string is displayed on the console. Unhandled exception in thread started by Error in sys.excepthook: Original exception was: The scripts are not terminated, they continue to execute normally. Is this is a problem with python? Is there any known solution. I am using Python 2.4. Thanks in Advance With Best Regards, Pramod TK -- http://mail.python.org/mailman/listinfo/python-list
Query regarding support for IPv6 in python
Hello All, I have some queries related to python support for IPv6. Can you kindly clarify the doubts which I have - 1. Does python support IPv6? [128 bit IP addresses?] 2. Does it support setting of QoS flags? 3. Does it support tunneling of IPv6 on a IPv4 network? 4. If an IPv4 address is given, does it support this on a IPv6 network? If not can you kindly let me know, Are there any plans for supporting these features in future? For Example - In IPv4 we have gethostbyname() function, which is deprecated in IPv6. In IPv6, getaddrinfo() and new data structure like struct addrinfo is introduced. Is this new function getaddrinfo() of IPv6 is supported in Win32 Extensions for python. Thanks in Advance, Pramod TK -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW and Python
Neal Becker [EMAIL PROTECTED] writes: release. Since mingw is usually current, I haven't checked, but they may be using 4.1 now. It is not, it is 3.4.2. http://www.mingw.org/download.shtml#hdr2 -- Brian (remove the sport for mail) http://www.et.web.mek.dtu.dk/Staff/be/be.html http://www.rugbyklubben-speed.dk -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
TG wrote: Obviously, there is something I didn't catch in python's inheritance. Nope. Obviously, array.array doesn't respect the usual rules. from array import array class Vector(array): def __init__(self,size): print self.typecode array.__init__(self,'f') v = Vector('c') c Here, it says the typecode is 'c' - I thought such an information was initalized during the array.__init__(self,'f') but obviously I was wrong. Maybe the typecode is defined before, during the call to __new__ method I think this must be something along this line. ... But here i'm getting lost. Let's see : from array import array class Vector(array): def __new__(cls, size): v = super(Vector, cls).__new__(cls, 'f') #print v is %s % v return v def __init__(self, size): self.size = size v = Vector(42) print v HTH -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython and twisted problem
[Chris] [we] already tried posting our problem on comp.lang.python but we didn't receive a successful reply so I thought I would try the mailing list. [A bit OT but worth pointing out] The mailing list and the newsgroup gateway to each other - everything sent to one also goes to the other (in theory at least 8-) -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
Philippe Martin wrote: bruno at modulix wrote: TG wrote: Hi there. I'm trying to create a simple class called Vector which inherit from array. Which array ? I think he did from array import * oops ! Sorry, I forgot this was in the standard lib (well, I never used this module, so) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython warnings
Michele Petrazzo wrote: Philippe Martin wrote: I had a similar but simple problem (the file was missing) and had to check by hand before calling wxPython. Can you check the tag by hand before calling wxPython ? Philippe Hi, also I have the same problem with g3/g4 images. My solution was convert that image *before* to .png before... Very bad hack, but work. I think that is an internal wxWidgets message (warning), passed to the wxPython subsystem. This is actually exactly what I did. (well, I converted to jpg, because they're going to end up as jpg anyway). bah Iain -- http://mail.python.org/mailman/listinfo/python-list
Twisted and wxPython integration problems
Hi, Im a university student creating a python Chat server and client using twisted. The server works great. However Im trying to create the client with a gui using wxpython and twisted. The code for the client is attached bellow. Im working with a partner and he already tried posting our problem on comp.lang.python but we didnt receive a successful reply so I thought I would try the mailing list. Heres the problem: I can get my client to connect to my server, but cant get it to disconnect or send messages to the server. I am getting the following error when I click on the 'Disconnect' button - AttributeError: 'NoneType' object has no attribute 'loseConnection' I have attached the code for the client below this. We are both fairly new to Python so would appreciate any help anyone can offer. Thanks, Chris Peter client.py -- from wxPython.wx import * import wx from twisted.internet import wxreactor wxreactor.install() from twisted.internet import reactor from twisted.internet.protocol import Protocol, ClientCreator class imApp(wxApp, Protocol): def buildMe(self): frame = wx.Frame(None, title=IM Client, size=(800, 550)) bkg = wx.Panel(frame) global ipAdd global portNo global messages global newMsg ipAddLab = wx.StaticText(bkg, -1, 'IP Address: ') ipAdd = wx.TextCtrl(bkg) ipAdd.SetToolTipString('Please enter the server IP address here.') spacer1 = wx.StaticText(bkg, -1, ' ') portNoLab = wx.StaticText(bkg, -1, 'Port No: ') portNo = wx.TextCtrl(bkg) portNo.SetToolTipString('Please enter the port number the server is using here.') spacer2 = wx.StaticText(bkg, -1, ' ') connectButton = wx.Button(bkg, label='Connect') connectButton.SetToolTipString('Click this button to connect to the server.') connectButton.Bind(wx.EVT_BUTTON, self.connectMe) disconnectButton = wx.Button(bkg, label='Disconnect') disconnectButton.SetToolTipString('Click this button to disconnect from the server.') disconnectButton.Bind(wx.EVT_BUTTON, self.disconnectMe) messages = wx.TextCtrl(bkg, style=(wx.TE_MULTILINE | wx.HSCROLL)) newMsg = wx.TextCtrl(bkg) sendButton = wx.Button(bkg, label='Send') sendButton.SetToolTipString('Click this button to send a message to the server.') sendButton.Bind(wx.EVT_BUTTON, self.sendMe) hbox1 = wx.BoxSizer() hbox1.Add(ipAddLab, proportion=0, flag=wx.EXPAND) hbox1.Add(ipAdd, proportion=0, flag=wx.EXPAND) hbox1.Add(spacer1, proportion=0, flag=wx.EXPAND) hbox1.Add(portNoLab, proportion=0, flag=wx.EXPAND) hbox1.Add(portNo, proportion=0, flag=wx.EXPAND) hbox1.Add(spacer2, proportion=0, flag=wx.EXPAND) hbox1.Add(connectButton, proportion=0, flag=wx.LEFT, border=5) hbox1.Add(disconnectButton, proportion=0, flag=wx.LEFT, border=5) hbox2 = wx.BoxSizer() hbox2.Add(newMsg, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.LEFT | wx.LEFT, border=5) hbox2.Add(sendButton, proportion=0, flag=wx.LEFT, border=5) vbox = wx.BoxSizer(wx.VERTICAL) vbox.Add(hbox1, proportion=0, flag=wx.EXPAND | wx.ALL, border=5) vbox.Add(messages, proportion=1, flag=wx.EXPAND | wx.LEFT | wx.LEFT | wx.LEFT, border=5) vbox.Add(hbox2, proportion=1, flag=wx.EXPAND | wx.ALL, border=5) bkg.SetSizer(vbox) ipAdd.WriteText('localhost') portNo.WriteText('1234') frame.Show(true) return true def sendMe(self, e): msg = newMsg.GetValue() + '\n' messages.WriteText(msg) newMsg.SetValue('') def disconnectMe(self, e): messages.WriteText('Disconnecting from server...\n') self.transport.loseConnection() def connectMe(self, e): messages.WriteText('Connecting to server...\n') c = ClientCreator(reactor, imApp) ip = str(ipAdd.GetValue()) port = int(portNo.GetValue()) c.connectTCP(ip, port) def mainProg(): app = imApp(0) app.buildMe() reactor.registerWxApp(app) reactor.run() if __name__ == '__main__': mainProg() -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
TG [EMAIL PROTECTED] wrote [something like]: from array import array class Vector(array): def __init__(self,size): array.__init__('f') v = Vector('c') print repr(v) will output : array('c') Is this a case of new-sytle classes being confusing? Because I'm certainly confused. I guess what's needed is: class Vector(array): def __new__(cls, size): self = array.__new__(array, 'f') ... return self But how does one determine what classes need to have __init__ overridden and which __new__ when subclassing? -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- 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: A defense for bracket-less code
[EMAIL PROTECTED] wrote: wrong group why? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: A defense for bracket-less code
On Wed, 26 Apr 2006 10:20:57 -0400 in comp.lang.python, Don Taylor [EMAIL PROTECTED] wrote: Found in a style guide (http://www.artlogic.com/careers/styleguide.html) --- Another case where unnecessary braces should be used is when writing an empty while loop: while (*p++ = *q++) { // this loop intentionally left empty... } FWIW, I usually code this like while (*p++ = *q++) continue; instead of the form that is more commonly found: while (*p++ = *q++); PC-lint picks this up (as well as the erroneous code in the elided example), but will allow the continue form shown above. [...] loop exactly once. Python programmers can stop chuckling now. --- On 26 Apr 2006 07:54:38 -0700 in comp.lang.python, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: wrong group Not really. It was mostly a lead-in to that last sentence. Problems like this couldn't happen in Python. So it's an opportunity to get a giggle at the expense of programmers using a language that gives you enough rope to shoot yourself in the foot... Regards, -=Dave -- Change is inevitable, progress is not. -- http://mail.python.org/mailman/listinfo/python-list
Re: Query regarding support for IPv6 in python
Pramod TK enlightened us with: 1. Does python support IPv6? [128 bit IP addresses?] Yes. 2. Does it support setting of QoS flags? No idea. 3. Does it support tunneling of IPv6 on a IPv4 network? IIRC that's the OS's job, not Python's. 4. If an IPv4 address is given, does it support this on a IPv6 network? It does if you use the compatability notation :::127.0.0.1 Is this new function getaddrinfo() of IPv6 is supported in Win32 Extensions for python. I don't know anything about windows. Sybren -- The problem with the world is stupidity. Not saying there should be a capital punishment for stupidity, but why don't we just take the safety labels off of everything and let the problem solve itself? Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
Re: KeybordInterrupts and friends
Precision : it does not happen when running interactively. -- http://mail.python.org/mailman/listinfo/python-list
Events in Python?
Here is another non-pythonic question from the Java Developer. (I beg for forgiveness...) Does Python have a mechanism for events/event-driven programming? I'm not necessarily talking about just GUIs either, I'm interested in using events for other parts of an application as well. If there isn't some sort of event mechanism built into Python, where might I find some information about implementing one? Thanks, Scott Huey -- http://mail.python.org/mailman/listinfo/python-list
Re: Events in Python?
[EMAIL PROTECTED] wrote: Here is another non-pythonic question from the Java Developer. (I beg for forgiveness...) Does Python have a mechanism for events/event-driven programming? I'm not necessarily talking about just GUIs either, I'm interested in using events for other parts of an application as well. If there isn't some sort of event mechanism built into Python, where might I find some information about implementing one? In python 2.5, generators accept parameters. That might be a good starting-point for an event-system. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah's Edu Corner: Criticism vs Constructive Criticism
Xah Lee wrote: Criticism versus Constructive Criticism Xah Lee, 2003-01 A lot intelligent people are rather confused about criticism, especially in our “free-speech” free-for-all internet age. When they say “constructive criticisms are welcome” they mostly mean “bitching and complaints not welcome”. Rarely do people actually mean that “criticism without suggestion of possible solutions are not welcome” or “impolite criticism not welcome”. Such discernment is important. Wanton bitching as internet-using geeks are used to is not criticism is any form. People can be respected and make a living out of criticisms, called critics, but not bitching. And when one really value opinions, you often want criticism without qualifications. Just be happy that valuable criticisms may come to you free from the experts in the public. The instant you qualify what kind of feedback are welcome, your feedback is compromised. (this is particularly so for political or controversial subjects) One easy way for many of the unix geeks to understand this is the cryptology industry. If one really desires valuable criticisms that is polite or with solutions or “constructive” (whatever that means), one usually have to pay. This post is archived at: http://xahlee.org/UnixResource_dir/writ/criticism.html Xah [EMAIL PROTECTED] ∑ http://xahlee.org/ Oh, God, not another one. -- The science of economics is the cleverest proof of free will yet constructed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Events in Python?
[EMAIL PROTECTED] schrieb: Does Python have a mechanism for events/event-driven programming? Probably this is something for you: http://twistedmatrix.com/trac/ -- Servus, Gregor http://www.gregor-horvath.com -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Bruno Desthuilliers said unto the world upon 25/04/06 06:52 PM: Duncan Booth a écrit : bruno at modulix wrote: class Base(object): def __init__(self, arg1): self.attr1 = arg1 self.dothis() def dothis(self): return self.attr1 class Derived(Base): def __init__(self, arg1, arg2=0): self.attr2 = arg2 Base.__init__(self, arg1) def dothis(self): return self.attr1 + self.attr2 (snip) Perhaps if the base __init__ calls an overridden method, but at that point it sounds to me like something wants refactoring. Why so ? This is a well-known pattern (template method). I don't see what's wrong with it. Apart from the fact that you can delete the method 'dothis' from both classes with no effect on the code? Mmmm... Oh, I see. Agreed, this is not a very good example. snip This hobbyist isn't seeing Duncan's point. Wouldn't deleting the dothis method from both classes lead to an AttributeError as Base.__init__ calls self.dothis()? Is the point that one could refactor out the self.dothis() from the __init__? Or something else altogether? (I assume it can't be that dothis isn't doing real work as it is in the context of a toy example.) Enlightenment gratefully received. Best to all, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: Events in Python?
[EMAIL PROTECTED] wrote: Here is another non-pythonic question from the Java Developer. (I beg for forgiveness...) Does Python have a mechanism for events/event-driven programming? I'm not necessarily talking about just GUIs either, I'm interested in using events for other parts of an application as well. If there isn't some sort of event mechanism built into Python, where might I find some information about implementing one? Thanks, Scott Huey Technically this is a question more of perception than capability. All programming languages are event driven. Calling a function is an event, for instance. What I suspect you mean is an event management system, which is what OO state machines are all about. If you actually mean something akin in function to GUI event systems, you're really talking about message passing. In the case of message passing you just need to build a simple event manager class that echoes a message to all subscribed listening objects. In python that message can be a function, object, arguments, text, etc. This is easily done without threading, in case you're worried about that. The function of the event manager that is used for the purpose of initiating events can simply call a particular method of all subscribing objects held in a list. Simple as can be :) ~Brendan Kohler -- http://mail.python.org/mailman/listinfo/python-list
Re: I have problems with creating the classic game Wumpus. the file: http://esnips.c
Ben Sizer wrote: connyledin wrote: Im trying to create a version of the game Wumpus. Mine is called Belzebub. But im STUCK! And its due tuesday 2 maj. Im panicing! Can some one help me?? here is the file: http://esnips.com/webfolder/b71bfe95-d363-4dd3-bfad-3a9e36d0 What i have the biggest problems with now is between line 8 and 23. Perhaps you could post those lines so we get an idea of what's going wrong. You also really need to explain what exactly you are hoping to achieve, and in what way it isn't working. I don't think anybody is likely to give you a full solution because that would defeat the object. I have trouble to get rid of the impression, that the (hidden from direct detection) goal of the original posting is some kind of promotion. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: wxpython warnings
On 26 Apr 2006 05:32:19 -0700, Iain King [EMAIL PROTECTED] wrote: I have a wxpython program that displays TIF images. Sometimes it will encounter a tag the tiff loader cant handle. Rather than silently ignoring it, it pops up a window: Python Warning unknown field with tag blah blah I don't want it to do this, but I can't work out how to turn it off. Anyone know? This is actually an error generated by libtiff, which wxWidgets traps raises. It is shown via the wxLog mechanism so you can supress it by wrapping your call in calls to wx.Log.EnableLogging. Note that this will suppress *all* warning and error messages that libtiff (or wx) might raise. Iain -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Inherit from array
Sion Arrowsmith wrote: TG [EMAIL PROTECTED] wrote [something like]: from array import array class Vector(array): def __init__(self,size): array.__init__('f') v = Vector('c') print repr(v) will output : array('c') Is this a case of new-sytle classes being confusing? Nope. FWIW, array is coded in C, and seems not to follow all standard conventions... Because I'm certainly confused. I guess what's needed is: class Vector(array): def __new__(cls, size): self = array.__new__(array, 'f') ... return self Yes. But how does one determine what classes need to have __init__ overridden and which __new__ when subclassing? It's the first exemple I see of a mutable type needing this. NB : http://www.python.org/doc/2.4.2/ref/customization.html __new__() is intended mainly to allow subclasses of immutable types (like int, str, or tuple) to customize instance creation. Usually, overriding __init__ is the way to go. -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: OOP / language design question
Brian van den Broek wrote: Bruno Desthuilliers said unto the world upon 25/04/06 06:52 PM: Duncan Booth a écrit : (snip) Apart from the fact that you can delete the method 'dothis' from both classes with no effect on the code? Mmmm... Oh, I see. Agreed, this is not a very good example. snip This hobbyist isn't seeing Duncan's point. Wouldn't deleting the dothis method from both classes lead to an AttributeError as Base.__init__ calls self.dothis()? Yes, of course. But Duncan (implicitely) meant deleting the method *and* the calls to the method. The point is that dothis() returns a value (that is not used), and doesn't modify the state of self. Or at least, this what *I* understood. Is the point that one could refactor out the self.dothis() from the __init__? Or something else altogether? (I assume it can't be that dothis isn't doing real work as it is in the context of a toy example.) Seems like you are assuming too much !-) -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
SimpleXMLRPCServer runnning as a Windows Service using win32serviceutil
I am trying to create a Windows service using SimpleXMLRPCServer and win32serviceutil. The service itself seems to be working properly (starts, stops, etc) and I can connect using an XMLRPC client from the localhost. However when I connect from a remote client, I either get a socket error or an xmlrpclib.ProtocolError error. If I use serve_forever() rather than handle_request(), the remote clients can connect but it breaks the Windows service functionality (can't stop the service). I have tried the same code without the service and that works, both locally and remotely. It would seem that the problem is related to the way the service handles remote connections, but I cannot figure out what the problem is. I have searched around, but can't find any example code. Hopefully someone can point me in the right direction. thanks, John ## XML-RPC Service import win32serviceutil import win32service import win32event import win32evtlogutil import win32file import servicemanager import SimpleXMLRPCServer class OBJECT: def hello(self): return Hello World class XMLRPCSERVICE(win32serviceutil.ServiceFramework): _svc_name_ = XMLRPCSERVICE _svc_display_name_ = XMLRPCSERVICE _svc_description_ = XMLRPCSERVICE def __init__(self, args): win32evtlogutil.AddSourceToRegistry(self._svc_display_name_, sys.executable, Application) win32serviceutil.ServiceFramework.__init__(self, args) self.hWaitStop = win32event.CreateEvent(None, 0, 0, None) self.hSockEvent = win32event.CreateEvent(None, 0, 0, None) def SvcStop(self): self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING) win32event.SetEvent(self.hWaitStop) def SvcDoRun(self): ## Write a started event servicemanager.LogMsg( servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, ' (%s)' % self._svc_name_)) server = SimpleXMLRPCServer.SimpleXMLRPCServer((, 8080)) object = OBJECT() server.register_instance(object) while 1: win32file.WSAEventSelect(server, self.hSockEvent,win32file.FD_ACCEPT) rc = win32event.WaitForMultipleObjects((self.hWaitStop,self.hSockEvent), 0, win32event.INFINITE) if rc == win32event.WAIT_OBJECT_0: break else: win32file.WSAEventSelect(server,self.hSockEvent, 0) server.handle_request() #server.serve_forever() ## Works, but breaks the Windows service functionality ## Write a stopped event win32evtlogutil.ReportEvent(self._svc_name_, servicemanager.PYS_SERVICE_STOPPED,0, servicemanager.EVENTLOG_INFORMATION_TYPE, (self._svc_name_,)) if __name__ == '__main__': win32serviceutil.HandleCommandLine(XMLRPCSERVICE) ##XML-RPC Server without service, this works using handle_request() import SimpleXMLRPCServer #The server object class OBJECT: def hello(self): return Hello World object = OBJECT() server = SimpleXMLRPCServer.SimpleXMLRPCServer((, 8080)) server.register_instance(object) #Go into the main listener loop print Listening on port 8080 while 1: server.handle_request() ## XML-RPC Client import xmlrpclib server = xmlrpclib.ServerProxy(http://remoteserver:8080;) print server.hello() -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW and Python
Edward Elliott wrote: Well, there is no native C library on Microsoft Windows: the system simply doesn't include an official C library (I know there is crtdll.dll and msvcrt.dll, but these aren't endorsed system C libraries). don't know what you mean by endorsed. does it lack features of the C89 ANSI standard? There isn't an import library for these DLLs anywhere, and Microsofts documents it (msvcrt.dll) as not intended for application use: http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx 'The msvcrt.dll is now a known DLL, meaning that it is a system component owned and built by Windows. It is intended for future use only by system-level components.' For Windows, that would require not to use any of the standard C functionality, since the system doesn't provide that functionality out of the box. That would be a problem then. So what happens when you compile python with msvc, and why can't mingw just replicate that? I link with msvcr71.dll (currently). To distribute Python, I need to include a copy of msvcr71.dll, which I can, because the MSVC license allows me to redistribute that DLL. When I link with mingw, I have a choice of DLLs to link with, including msvcrt.dll, msvcrt4.dll, msvcr71.dll, and perhaps others - I don't even need the DLLs on my system to link with them. However, I cannot redistribute these DLLs when I compile with MingW (unless I also have a copy of VS.NET - I would have to reread its license to find out whether it requires that the application is actually built with MSVC to allow for redistribution). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: MinGW and Python
Ross Ridge wrote: MSVCRT.DLL has been a standard system compent of Windows since at least Windows 98. Many other system components depend on it. Essentially, MSVCRT.DLL is an undocumented part of the Windows API. It's not exactly endorsed, Microsoft would rather you use it's current compiler and runtime, but it is the standard official Windows system C library. See http://msdn2.microsoft.com/en-us/library/abx4dbyh(VS.80).aspx 'The msvcrt.dll is now a known DLL, meaning that it is a system component owned and built by Windows. It is intended for future use only by system-level components.' The SDK stopped including an import library for it (I believe earlier versions of the SDK still had an import library). Regardless, there is no version of the MS C++ library that links against msvcrt.dll. So if Python is linked against msvcrt.dll, you can't really build C++ extensions anymore (with MSVC), unless you are certain that mixing CRTs causes no harm for your application. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
CoderWiki.com - A free online reference manual
Anyone interested in helping me build the ultimate programming manual? http://www.coderwiki.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Events in Python?
redefined == redefined horizons [EMAIL PROTECTED] writes: redefined Here is another non-pythonic question from the Java redefined Developer. (I beg for forgiveness...) redefined Does Python have a mechanism for events/event-driven redefined programming? The enthought traits package has built-in support for event handling, among other things http://code.enthought.com/traits/ Here is an example from the web page: from enthought.traits import Delegate, HasTraits, Int, Str, Instance from enthought.traits.ui import View, Item class Parent(HasTraits): first_name = Str('') # INITIALIZATION: last_name = Str('') # 'first_name' and # 'last_name' are # initialized to '' class Child(HasTraits): age = Int father = Instance(Parent) # VALIDATION: 'father' must # be a Parent instance first_name = Str('') last_name = Delegate('father') # DELEGATION: # 'last_name' is # delegated to # father's 'last_name' def _age_changed(self, old, new): # NOTIFICATION: # This method is # called when 'age' # changes print 'Age changed from %s to %s ' % (old, new) traits_view = View(Item(name='first_name'), # TRAITS UI: Define Item(name='last_name', # the default window style='readonly'),# layout Item(name='age'), Item(name='father')) # Make and manipulate objects from the classes above joe = Parent() joe.last_name = 'Johnson' # DELEGATION in action moe = Child() moe.father = joe print Moe's last name is %s % (moe.last_name) # NOTIFICATION in action moe.age = 10 #VISUALIZATION: Display the UI moe.configure_traits() The DELEGATION and NOTIFICATION segments in the above example yield the following command-line output: Moe's last name is Johnson Age changed from 0 to 10 -- http://mail.python.org/mailman/listinfo/python-list