Building PIL under Cygwin & Python 2.5
This has apparently been a problematic thing for a while now, as the following article indicates. I first ran into the error message about not being able to remap C:\cygwin\bin\tk84.dll to be the same address as it's parent. Using that information, Google helped me find this article: http://blog.datahammer.info/2008/11/install-pil-under-cygwin-python-25.html After following it's advice and running: $ ./rebase -b 0x10 tk84.dll I was able to get the PIL build to proceed, but when it was done, it said that there was no support built for Tk, and I then noticed that basic Tkinter functionality was broken from the Python interpreter. I went back to Cygwin setup, and had it reinstall the tcl/tk package, and then Tkinter (import from the interactive interp.) got fixed. Googling some more, I found this article (which implied datahammer isn't quite right): http://www.pythonchallenge.com/forums/viewtopic.php?t=135 I ran /usr/bin/rebaseall (from ash)(and if you end up doing this yourself, be aware that it takes a while - I was afraid that process had hung and I was going to have to rebuild the whole Cygwin shooting match from scratch, but it eventually completed (silently)). After this, I checked that Tkinter still worked from Python (it did), and then tore out the whole PIL directory (Imaging-1.1.6) I had tried to install from before, re-extracted the tar file to get a clean install directory, and then again attempted to build PIL. Now, instead of getting the failure message about not being able to remap the dll, the build just hangs: $ python setup.py build_ext -i running build_ext building '_imaging' extension creating build creating build/temp.cygwin-1.5.25-i686-2.5 creating build/temp.cygwin-1.5.25-i686-2.5/libImaging gcc -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict- prototypes -DHAVE_LIBJPEG -DHAVE_LIBZ -I/usr/include/freetype2 - IlibImaging -I/usr/include -I/home/ej/python/PIL/jpeg-6b -I/usr/ include/python2.5 -c _imaging.c -o build/temp.cygwin-1.5.25-i686-2.5/ _imaging.o Now, I'm rather stuck and I'm thinking "This really shouldn't be that hard." So, rebasing (rebaseall'ing) the cygwin system as outlined in the datahammer blog entry (along with the ash advice of the pychallenge article) still doesn't seem to be enough to get a clean build. I think this is an issue that probably needs to be addressed by PIL maintainers that fully understand the root of the problem (and it should probably go in the PIL FAQ), but in the meantime does anyone out there know how to get around this issue? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: array{uint32}
"Daniel Nogradi" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > I have a function that returns a array{uint32}, is there any way to output > > that to screen in a more user friendly format? At the moment when I print it > > by itself it appears as [65541L], which isn't much used to anyone. > > I'm not sure I understand your question precisely but this might help: > > >>> mylist = [65541L] > >>> mylist > [65541L] > >>> mylist[0] > 65541L > >>> int(mylist[0]) > 65541 > >>> Right, so getting rid of the 'L' is one improvement. You might also check out the pprint module: >>> l = range(30) >>> l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 2 2, 23, 24, 25, 26, 27, 28, 29] >>> from pprint import pprint >>> pprint(l) [0, 1, 2, 3, 28, 29] >>> You can use C-like print formatting statements: >>> l = [-3, 0, 101320, 67] >>> pprint(l) [-3, 0, 101320, 67] >>> for i in l: ... print i ... -3 0 101320 67 >>> for i in l: ... print '%6i' % i ... -3 0 101320 67 >>> # the above probably doesn't disply correctly unless you are viewing with a monospaced font) You could sort the list, then split it up into N separate lists so that you can format multiple columns of sorted integers... You haven't given any real information about your idea of a "user friendly format", but maybe this will help also. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess "handle is invalid" error
"Grant Edwards" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > How does one troubleshoot errors that happen three layers deep > in the subprocess module? I think the problem is more likely in how your py2exe is getting bundled, rather than any real problem with the subprocess module. I have been on the py2exe email list but not really paying much attention... If I recall correctly, there are some special considerations when using gnuplot with py2exe? I would suggest digging through the py2exe email archives to see if you can locate emails on that subject (one copy of which I believe can be found at: http://sourceforge.net/mailarchive/forum.php?forum_name=py2exe-users), and if that doesn't work, to direct your question to the py2exe users list at: [EMAIL PROTECTED] (I believe the current home page of the py2exe project is at: http://sourceforge.net/projects/py2exe/) Hope that helps, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Python editor/IDE on Linux?
"7stud" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Jack wrote: > > I wonder what everybody uses for Python editor/IDE on Linux? > > I use PyScripter on Windows, which is very good. Not sure if > > there's something handy like that on Linux. I need to do some > > development work on Linux and the distro I am using is Xubuntu. > > Everybody uses vim. And not just on Linux! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: rexec & Bastion ?
I mean, of course, rexec (not recec) and Bastion -- http://mail.python.org/mailman/listinfo/python-list
recec & Bastion ?
The documentation for these two modules says that they were disabled in Python 2.3 due to security holes not easily fixable. I have not worked with them, but I can still import them under Python 2.4, so I'm not clear on whether the security problems were fixed in Python itself, or whether the modules remain deprecated (disabled?)? How are/were they actually disabled? Any place that documents what the problems are? Any alternatives? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: SimpleXMLRPCServer and Threading
"Achim Domma" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > is SimpleXMLRPCServer multithreaded or how does it handle multiple > clients? I want to implement a simple server which will be queried by > multiple processes for work to be done. The server will simply hold a > queue with files to process. The clients will ask for the next file. > > Do I have to sync access to the queue or is the server not threaded at all? I don't claim to know much about the internals of the module, but it imports BaseHTTPServer which I am sure is multithreaded. I did not test this with functions, but when you register an object in the server, different clients are accessing the same object: (The following example is modified from that given in the module documentation: http://docs.python.org/lib/module-SimpleXMLRPCServer.html) $ cat server.py #!/usr/bin/env python from SimpleXMLRPCServer import SimpleXMLRPCServer # Create server server = SimpleXMLRPCServer(("localhost", 8000)) server.register_introspection_functions() # Register pow() function; this will use the value of # pow.__name__ as the name, which is just 'pow'. server.register_function(pow) # Register a function under a different name def adder_function(x,y): return x + y server.register_function(adder_function, 'add') # Register an instance; all the methods of the instance are # published as XML-RPC methods (in this case, just 'div'). class MyObj: SEQ = None def __init__(self): self.SEQ = range(1) self.index = 0 def next_seq(self): n = self.SEQ[self.index] self.index += 1 return n server.register_instance(MyObj()) # Run the server's main loop server.serve_forever() # First client calls: >>> import xmlrpclib >>> url = 'http://localhost:8000' >>> s = xmlrpclib.Server(url) >>> s.next_seq() 0 >>> s.next_seq() 1 >>> s.next_seq() 2 # second client calls >>> import xmlrpclib >>> url = 'http://localhost:8000' >>> s = xmlrpclib.Server(url) >>> s.next_seq() 3 I did not programmatically drive these calls at the same time to try to force simultaneous access from separate requests, but my intuition is that it's a pretty good bet that SimpleXMLRPCServer has taken care of re-entrant issues. It may be instructive for you to run that test yourself and explicitly verify requests do not interact. Alternatively, if you really want to know for sure... Python is an open-source project. You can dig around in SimpleXMLRPCServer.py yourself and figure out exactly what it is doing: >>> import SimpleXMLRPCServer >>> SimpleXMLRPCServer >>> [EMAIL PROTECTED] ~ $ vi /usr/lib/python2.4/SimpleXMLRPCServer.py see also: http://docs.python.org/lib/module-BaseHTTPServer.html http://docs.python.org/lib/module-SocketServer.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Numeric Soup
"Robert Kern" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > http://www.scipy.org/History_of_SciPy > > numpy is the current array package and supercedes Numeric and numarray. scipy > provides a bunch of computational routines (linear algebra, optimization, > statistics, signal processing, etc.) built on top of numpy. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fortran vs Python - Newbie Question
"Steven D'Aprano" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Sheesh. Do Java developers go around telling everybody that Java is an > interpreted language? I don't think so. > > What do you think the "c" in ".pyc" files stands for? "Cheese"? On the contrary... Sun is very careful to make sure you understand that Java is *COMPILED*! Remember, remember, always remember: Java is COMPILED! See that: the java "compiler": javac. You have to call it explicitly when you build your Java software so that it compiles Java source code (that way Java executes really fast)!! (And don't forget, Java source is *compiled*, just like C++.) What's a JVM? Why would you need one since Java is *compiled*, remember? But seriously... I'm not a language or architecture guru. Is there any real difference between a JVM and an interpreter? I mean, I have some general feel that bytecode is a lower-level, more direct and more efficient thing to be interpreting that Java or Python source, but at the bottom level, you are still running an interpreter which is going to be (significantly?) more inefficient than executing native machine instructions directly on the CPU, right? Why is Python able to automatically compile source into bytecode on the fly (when needed) but Java still forces you to do so explicitly? I don't mean to bash Java - I think it has it's place as well, but I mean to note that Java is very carefully marketed whereas Python's image is not managed by a major, international corporation. -- http://mail.python.org/mailman/listinfo/python-list
Numeric Soup
I am just starting to explore doing some scientific type data analysis using Python, and am a little confused by the different incarnations of modules (e.g., try Google("Python numeric"). There is SciPy, NumPy, NumArray, Numeric... I know some of these are related and some are separate, some are oudated, etc. but can someone sort of give a general run-down in layman's terms of what's what, what's used for what, what depends on what, and what's current? At this point my interest is just sort of general, fast array manipulation and DSP. Thanks! -- http://mail.python.org/mailman/listinfo/python-list
Re: Help in Placing Object in Memory
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > What do you mean by that? They can both load a pickled object, yes. But they > can't share it as a at-runtime object, where changes in one script are > immediately are known to the other. > > To do such a thing, look at pyro. Or not natively (i.e., that battery isn't included). I believe it can still be done, though: http://poshmodule.sourceforge.net/ (I haven't used the module - just used Google to locate it) You could, of course, roll-your-own solution using shared memory and/or other interprocess communication (http://docs.python.org/lib/ipc.html) Hope that helps, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Fortran vs Python - Newbie Question
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > OK... > I've been told that Both Fortran and Python are easy to read, and are > quite useful in creating scientific apps for the number crunching, but > then Python is a tad slower than Fortran because of its a high level > language nature, so what are the advantages of using Python for > creating number crunching apps over Fortran?? > Thanks > Chris So, after reading much of animated debate here, I think few would suggest that Python is going to be faster than FORTRAN when it comes to raw execution speed. Numeric and SciPy are Python modules that are geared towards numerical computing and can give substantial performance gians over plain Python. A reasonable approach (which has already been hinted at here), is to try to have the best of both world by mixing Python and FORTRAN - doing most of the logic and support code in Python and writing the raw computing routines in FORTRAN. A reasonable approach might be to simply make your application work in Python, then use profiling to identify what parts are slowest and move those parts into a complied language such as FORTRAN or C if overall performance is not fast enough. Unless your number crunching project is truly massive, you may find that Python is a lot faster than you thought and may be plenty fast enough on it's own. So, there is a tradeoff of resources between development time, execution time, readability, understandability, maintainability, etc. psyco is a module I haven't seen mentioned here - I don't know a lot about it, but have seen substantial increases in performance in what little I have used it. My understanding is that it produces multiple versions of functions tuned to particular data types, thus gaining some advantage over the default, untyped bytecode Python would normally produce. You can think of it as a JIT compiler for Python (but that's not quite what it is doing). The home page for that module is here: http://psyco.sourceforge.net/ Hope that help, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: calling class instances and their methods
"spohle" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > hi, > > i created an instance of a my own class which has methods and all. now > i get an outside function called, which is unfortunatly not aware of > the instace at all (i don't control how this outside function is > called). but i would like to get access back to my instance and it's > methods. > > is there any clean way of doing this ? > > thanks in advance Ummm... I'm not exactly sure what you mean by "an outside function", but let's refer to that function as f(). Are you saying you want to re-implement f() to use your new object but don't want to (or can't) change calls to f()? If so, then you can either use a global reference to your new object if it is the sort of thing you want to keep around between invocations of f() (i.e., create your object somewhere and then save in a scope that f() can access). Otherwise, you can simply instantiate your object inside of f() as a local variable and use it. If you mean something else, I guess you will have to clarify. -- http://mail.python.org/mailman/listinfo/python-list
Re: Been a while...
"James Stroud" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hawk this list and try to pick off easy answers before anyone else. > That's what I do. The pressure is to be right, because if you're not, > you hear about it in a hurry. That is actually an excellent suggestion. Even if you can't answer a question, finding interesting and comprehanesible questions and then studying the various follow up posts is an excellent way to sharpen your Python skills, and broaden your knowledge about not only Python syntax and common pitfalls but about what modules are typically applied to various kinds of problems. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Been a while...
"Michael Bentley" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > On Mar 22, 2007, at 10:34 AM, John Salerno wrote: > > > Hi guys. It's been a while since I've used Python, so I got a little > > rusty, but I really want to start using it again, just out of habit > > and > > for fun. Can anyone suggest a book or a website with little projects I > > could work on to keep me busy? > > http://www.pythonchallenge.com There is also a slew of interesting (and challenging) problems at SPOJ (Sphere Online Judge: https://www.spoj.pl/) which you can solve and submit your Python (or one of about 30 other languages) solution to for automatic and (almost) immediate judging. There is a slew of programming contest problems at http://acm.uva.es/problemset/ , an ACM-sponsored site which does not accept postings in Python, but you can always dig through the problems to find an interesting one to work on. You'll have to decide for yourself if you've solved it correctly / satisfactorily. Good luck, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 idea: reversing the order of chained assignments
Actually, after studying this a bit more: http://docs.python.org/ref/assignment.html I guess that makes sense. Sorry if I muddied the water for anyone else in my boat: n1 = n1.next = n2 The first thing that happens is the expression list is evaluated which is the thing on the far right, n2. That is a simple object reference which is then assigned to each of the target lists, left to right, of which there are two: n1 and n1.next. So, first, n1 is assigned the same value n2 has. Next, n1.next is assigned n2 (The object n1 refers to, which is also now n2, is assigned a new attribute, that value of which is n2). So, yeah... as Terry Reedy said: better to be explicit about what you want to happen first and not mash them together into one line. That would be... how do you say... "Pythonic"? (God, I feel so much better now. LOL) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3000 idea: reversing the order of chained assignments
"Virgil Dupras" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > class Node: > > > ... pass > > > ... > > node = Node() > > nextnode = Node() > > backup_node = node > > node = node.next = nextnode > > node.next is node > > > True > > hasattr(backup_node,'next') > > > False Well, I think I am thoroughly confused now. I am a lot less experienced that most of the people posting in this thread, so perhaps that is to be expected, but I actually thought I understood Python fairly well. Maybe I am fooling myself... Let me rename some variables in the code above to something a little easier to follow: >>> class Node: pass ... >>> n1 = Node() >>> n2 = Node() >>> n3 = n1 At this point I beleive I've got the same thing above, just with different reference names. Namely, I have two objects, and three references, the first and third reference now both referring to the first object, the second reference referring to the second object: >>> n1 <__main__.Node instance at 0x7ff1d20c> >>> n2 <__main__.Node instance at 0x7ff1d10c> >>> n3 <__main__.Node instance at 0x7ff1d20c> The discussion is about multiple assignments. Virgil's example should be equivalent to: n1 = n1.next = n2 If assignment were left to right, (i.e., n1 = n1.next, followed by n1.next = n2), then I would expect to get an attribute error because n1 hasn't had the 'next' attribute attached to it yet. That's not what happens, so the other interpretation is that the statement above is equivalent to: n1.next = n2; n1= n1.next (except that n1.next is only evaluated once, but that doesn't matter here). Right? That is, first object 'n1' gets a new attribute, the value of which is a reference to object n2, and then, the name 'n1' is rebound to be a reference to object n2 (note that the object n1 was previously referencing should still be available via name 'n3', and being a mutable object, the new attribute should be visible via 'n3', right? I didn't yet execute the statement above (I just typed it in this post) - let's first check the objects and attributes for what we have prior to this confusing statement: >>> n1 <__main__.Node instance at 0x7ff1d20c> >>> n2 <__main__.Node instance at 0x7ff1d10c> >>> n3 <__main__.Node instance at 0x7ff1d20c> >>> dir(n1) ['__doc__', '__module__'] >>> dir(n2) ['__doc__', '__module__'] >>> dir(n3) ['__doc__', '__module__'] Right... no suprises there. Let's execute that funky statement... >>> n1 = n1.next = n2 >>> We would expect n1 to reference n2 now (my object at ...d10c), which it does: >>> n1 <__main__.Node instance at 0x7ff1d10c> And we would expect n3 to still be referencing the object at ...d20c, which it also still does: >>> n3 <__main__.Node instance at 0x7ff1d20c> And we would expect (or I should say "I would expect") n3 to now have a 'next' attribute: >>> dir(n3) ['__doc__', '__module__'] It doesn't, which is what Virgil previously pointed out. I'm not quite following the whole discussion (nor the syntax diagrams), so sorry if this was already explined - could someone try again: why is it that n3 here doesn't get the 'next' attribute? Now here's the part that totally floors me: what would you expect to be the attributes on n2 (the object on the far-right of the multi-way assignment statement)? We've made no assigment statements to anything about n2. They should be the same as before, right? >>> dir(n2) ['__doc__', '__module__', 'next'] >>> n2.next <__main__.Node instance at 0x7ff1d10c> >>> n2 <__main__.Node instance at 0x7ff1d10c> >>> DUH I'm about speechless... Is it just me being dense, or is there some obvious reason why one would expect this? -- http://mail.python.org/mailman/listinfo/python-list
tracking memory usage
Sort of two questions here: The first is about the internal view: are there Python introspection functions that can be called such that a running script can keep tabs on how much memory is being used? And the second is about using either os or system calls on Windows such that a Python script could get similar information about other processes (i.e., external)? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Tools for GUI/graphics
> You can use ReportLab Graphics to generate the > graphs as .JPG files and display them in a > browser window with simple HTML. That is one option. As best as I recall, CherryPy is a simple but fully functional web framework. If your primary focus is programmatically generating graphs from data, some other options may be: Go ahead and use Tkinter's Canvas (I foget exactly how, but you can export graphic files). Do a similar thing with wxPython (www.wxpython.org) Use Frekrik Lundh's Python Image Library (PIL) - (http://www.pythonware.com/products/pil/) Chart Director is a product I have a little experience with which has Python bindings (http://www.advsofteng.com/). Technically a commercial product (~$100), it has a very liberal demo policy: demo versions display a small banner at the bottom of the graphic. This is a fairly professional looking package that can do nice stuff like automatically scales axes, get them labelled with ticks, etc. It may be worth you time to use something like that. Searching the Python Cheese Shop for Scientific/Engineering Visualization turns up a good deal of others: http://www.python.org/pypi?:action=browse&show=all&c=399&c=385 HTH, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: struct.pack oddity
"Dave Opstad" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is the lack of a struct.error when the byte-order mark is at the start > of the format intentional? This seems like a bug to me, but maybe > there's a subtlety here I'm not seeing. I am by no means any sort of expert on this module, but for what it's worth, the behaviour is basically the same for my Python 2.4.3 under Cygwin (except that there is no deprecation warning) and I agree with you: this seems like a bug to me. Or maybe not technically a bug, but the behaviour could be improved. I would expect to get the same struct.error in all three cases: $ python Python 2.4.3 (#1, May 18 2006, 07:40:45) [GCC 3.3.3 (cygwin special)] on cygwin Type "help", "copyright", "credits" or "license" for more information. >>> from struct import * >>> pack('H', 10) Traceback (most recent call last): File "", line 1, in ? struct.error: short format requires 0<=number<=USHRT_MAX >>> pack('>H', 10) '\x86\xa0' >>> pack('>> There used to be a form at the bottom left of the main site: www.python.org for reporting bugs, but that now seems to be used only for reporting stuff about the web site itself. The struct module comes from struct.dll, so I can't see any comments about who wrote or maintains that module. Barring anyone else disagreeing with classifying it as a bug, I would suggest reporting it. Proper procedure for reporting a bug appears to be covered in section B of the Python Library Reference: http://docs.python.org/lib/reporting-bugs.html Hope that helps, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question : "grep"
Sorry, I forgot to paste the modified version of my code in the post:. I think this is the same behaviour: for line in lines: if "placed" in line: if "i_a/i_b/ROM/" in line: pos = (line.split()[4]).split("_")[1] found = False for (tag, (start, end)) in tags: if tag in line: found = True print "i_a/i_b/ROM/%s [%i:%i] LOC =" %\ (pos, tag, start, end) break if not found: print "Error" -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie Question : "grep"
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > - If I increase number of elements I am searching for, then I have > more elif...elif. Is there a cleaner solution? I'm not sure exactly what your lines look like, but this script implies that every line that matches 'i_a/i_b/ROM' is one of the known list you are looking for. Maybe that's exactly right... Below is some code that I think is an incremental improvement over writing lots of alternative if-statements. I beleive it has the same behaviour, though it is totally untested: tags = [ ['B18', (7, 6)], ['B14', (5, 4)], ['B10', (3, 2)], ['B6', (1, 0)], ] for line in lines: if "placed" in line: if "i_a/i_b/ROM/" in line: pos = (line.split()[4]).split("_")[1] found = False for (tag, (start, end)) in tags: if tag in line: found = True print "i_a/i_b/ROM/%s [%i:%i] LOC =" %\ (pos, tag, start, end) break This way, you just need to maintain your data structure (tags), instead of writing lots of repettitive code. If there is a definite pattern to the part that looks like a slice (what I am calling (start, end)), then you could programmatically generate that as well, of course. The list of things you are looking for could be in a separate file, etc. The sensible thing to do sort of depends on how big this list of stuff you are looking for is going to grow and how much you are going to use this program. Do what makes sense for you. You may want to explore the 're' module as well (regular expressions) http://docs.python.org/modindex.html , which may or may not improve performance, readability, maintainability, etc. See also section 10.10 of the Python Tutorial if you are interested in code performance issues: http://docs.python.org/tut/tut.html Hope that helps, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Tell me the truth
"Duncan Booth" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > [EMAIL PROTECTED] wrote: > > > After much head scrating and experimenting with dis.dis() I have found > > that chaining comparisons (with is or ==) a == b == c in Python is > > never a good idea. It is interpreted as > > ( a == b ) and ( b == c) > > Such a magic is fine when we write: > > if 0.0 <= x < 1.0: > > but it renders the outcome of if a == b == c: somewhat confusing. > > I don't understand why it is confusing. What other meaning would you > expect? I can see how one might get themselves confused. I think it simply boils down to thinking that A == B == C is shorthand for: (A == B) == C It's not. You're asserting that A is equivalent to B and B is equivalent to C, NOT that the value of comparing A to B is equivalent to C: >>> False is False True >>> False is False is True False If what you want is the second form, a pair of parenthesis forcing order of evaluation will give it to you. >>> (False is False) is True True -ej -- http://mail.python.org/mailman/listinfo/python-list
subclassing a module: misleading(?) error message
I ran into a problem I didn't understand at first. I got part of it figured out. Let me first demonstrate the original problem: > cat Super.py class Super(object): def __init__(self): self._class = 'Super' def hello(self): print "%s says 'Hello'" % self._class > cat Sub.py import Super class Sub(Super): def __init__(self): self._class = 'Sub' > > python Python 2.3.4 (#1, Feb 7 2005, 15:50:45) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from Super import Super >>> from Sub import Sub Traceback (most recent call last): File "", line 1, in ? File "Sub.py", line 4, in ? class Sub(Super): TypeError: function takes at most 2 arguments (3 given) >>> My question is NOT "What's wrong here?" (The answer to that is that the import in Sub.py should be: from Super import Super i.e., I tried to use the module itself where I meant to subclass the class defined in that module). My questions are: Why does python complain about a function here? (it's a class definition statement, right?) Is there really a function being called here? If so: What function was called? What two arguments is it expecting? What three were given? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Reverse of SendKeys??
Aside from the obvious security issues such a program would represent (and your name and signature are curious in that respect as well), you are basically asking for functionality (i.e., a key logger) I believe to be outside what is offered by Python and/or the API of most operating systems. Perhaps you should take up assembly programming? -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary containing instances of classes behaving oddly
"Ben" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Yes- I can see that my_list and mops, being outside def __init__() > only get created once, hence the confusion. > > Surely def __init__() gets called each time an instance is created > however? But the snag is that if they have default values set these are > shared between all instances, even if they are, for instance, lists...? I don't think I quite understand the confusion, and I think I might have said something misleading. The def statement itself is only executed once, as are any object initializers contained within it. Your record.__init__() is not using a default initializer, and here: class record: my_list =[] mops=[] def __init__(self,mops): self.mops=mops mops as the second argument to __init__ is a formal vairable, not a reference to record.mops. If you pass the same list reference to each constructor, then each record object shares the same list. You previously said: I had thought that then each time I created an instance of the record class as an element of my dictionary: self.mop_list[record_number]=record(self.mops[:]) I would create a brand new instance of the record class.It would have a mops list initialized with mops (because the def__init__ constructor is called when the class is instantiated), and an empty, individual list my_list. I beleive this is basically correct - by using the slice notation in self.mops[:] you are passing a copy of that list as the value. The difference is demonstrated here: >>> class Foo: ... X = [99] ... def __init__(self, X): # X is formal variable here, not Foo.X! ... self.X = X ... >>> y = [1,2,3] >>> f1 = Foo(y) >>> f1.X [1, 2, 3] >>> Foo.X [99] >>> f1.X.append(42) >>> f1.X [1, 2, 3, 42] >>> y [1, 2, 3, 42] >>> Foo.X [99] >>> f2 = Foo(y[:]) >>> f2.X [1, 2, 3, 42] >>> y [1, 2, 3, 42] >>> Foo.X [99] >>> f2.X.append('something else') >>> f2.X [1, 2, 3, 42, 'something else'] >>> f1.X [1, 2, 3, 42] >>> y [1, 2, 3, 42] >>> Foo.X [99] >>> So, I guess I don't see exactly where the problem is, and without all your source, I am kinda poking in the dark. But from the behaviour observed in your record objects, you are obviously ending up with shared list references where you intend to get per-object individual lists. Generally the way to do that is to assign a new, empty list in the body of the object initializer and then populate that list as needed. Good luck. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary containing instances of classes behaving oddly
"Ben" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > class record: > my_list =[] > mops=[] > > def __init__(self,mops): > self.mops=mops Similar to the example I gave, the lists my_list and mops shown above are executed just once: when your class definition is first parsed. The statement: def __init__(self,mops): is also executed just once, and the value for mops at that time is the value assigned to object attributes during object construction - a reference to record.mops, in your case. So, there are really only two lists here, class attributes record.my_list and record.mops. Each of your constructed objects is assigned a reference to record.mops. They all share that list. If you want a record object to have it's own list, give it a new, empty one and then populate it appropriately. -- http://mail.python.org/mailman/listinfo/python-list
Re: xml bug?
"Imbaud Pierre" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Now my points are: > - how do I spot the version of a given library? There is a __version__ >attribute of the module, is that it? Yes, the module maintainer should be incrementing this version for each new release and so it should properly correspond to the actual revision of code. > - How do I access to a given library buglist? Maybe this one is known, >about to be fixed, it would then be useless to report it. Not exactly sure, but this is probably a good place to start: http://docs.python.org/modindex.html > - How do I report bugs, on a standard lib? I found this link: http://sourceforge.net/tracker/?group_id=5470&atid=105470 by looking under the "help" item at www.python.org (an excellent starting place for all sorts of things). > - I tried to copy the lib somewhere, put it BEFORE the official lib in >"the path" (that is:sys.path), the stack shown by the traceback >still shows the original files being used. Is there a special >mechanism bypassing the sys.path search, for standard libs? (I may >be wrong on this, it seems hard to believe...) My understanding is sys.path is searched in order. The first entry is usually the empty string, interpreted to mean the current directory. If you modify sys.path to put the directory containing your modified code in front of where the standard library is found, your code should be the one used. That is not the case? > - does someone know a good tool to validate an xml file? Typing "XML validator" into google returns a bunch. I think I would start with the one at w3.org: http://validator.w3.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary containing instances of classes behaving oddly
"Ben" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > This seems to work without any errors. But bizzarely I find that > whatever my record number, the instance of "my_class" is appended to > every list. So in this case > > self.mop_list[0].my_list.append(my_class(Some data for the > constructor)) > > I would expect to append an instance of my_class to > self.mop_list[0].my_list > > But annoyingly > > self.mop_list[0].my_list > self.mop_list[3].my_list > self.mop_list[7].my_list > > all have an instance of my_class created and appended to them. This is > really confusing and quite annoying - I don't know whether anyone out > there can make head or tail of what I'm doing wrong? Well, it's a little bit difficult, but I think I actually know what's going on. You probably need some code that looks something like this, to ensure each object has it's own, independent list: class record: def __init__(self, init_list=None): self.my_list = [] if init_list is not None: self.my_list.extend(init_list) Here's what I think you are doing, and below should make it clear why that doesn't work: class record: def __init__(self, init_list=[]): That list above, the default initializer is constructed just once (when the def statement executes)! >>> class record: ... def __init__(self, init_list=[]): ... self.my_list = init_list ... >>> r1 = record() >>> r1.my_list [] >>> r2 = record() >>> r2.my_list [] >>> r2.my_list.append('boo!') >>> r1.my_list ['boo!'] >>> >>> l1 = range(1, 4) >>> l1 [1, 2, 3] >>> r1 = record(l1) >>> r2 = record(l1) >>> r1.my_list [1, 2, 3] >>> r2.my_list [1, 2, 3] >>> r1.my_list.append(42) >>> l1 [1, 2, 3, 42] >>> r1.my_list [1, 2, 3, 42] >>> r2.my_list [1, 2, 3, 42] >>> -- http://mail.python.org/mailman/listinfo/python-list
Re: DOS, UNIX and tabs
"Ben Finney" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Sebastian 'lunar' Wiesner" <[EMAIL PROTECTED]> writes: > > > Just a tip for you: In python you never use tabs for indentation. > > For some value of "you". > > > The python style guide [1] recommends four spaces per indentation > > level. > > > > [1] http://www.python.org/dev/peps/pep-0008/ > > It's not quite absolute on the topic: > > For new projects, spaces-only are strongly recommended over tabs. Even if were, read the Introduction. This is a coding standard intended to apply to code which is going to checked in as part of the core python build, not all Python! It's probably a pretty good standard to be following in general, but come on... If Guido really wanted this enforced across the board he could simply call anything that doesn't meet this standard to the letter a SyntaxError and just stop there. For example, the standard states: - Imports should usually be on separate lines, e.g.: Yes: import os import sys No: import sys, os >>> import sys, os Traceback (most recent call last): File "", line 1, in ? ImportError: Sorry, only one module per import line! I'm sure that's not Guido's intention. ;) -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: persistant gloabl vars (very newbie) ?
> but it's still not quit handy > > # initialization file (init1.py) > import time; > xx = 44 > > # main file was > print xx > x=time.time() > > # main file should become > print init1.xx > x=init1.time.time() > > so even for the "standard" functions like "time" I've to include the > preceeding module "init1" :-( Ummm... does this help? /src/python/Foo> cat init.py #! /usr/local/bin/python from time import time xx = 44 /src/python/Foo> python Python 2.3.4 (#1, Feb 7 2005, 15:50:45) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from init import * >>> dir() ['__builtins__', '__doc__', '__file__', '__name__', 'time', 'xx'] >>> xx 44 >>> time >>> time() 1167262478.6845641 >>> xx = 42 # this does not change the init module's value! >>> import init >>> init.xx 44 As Piet points out, you get a copy of variables defined in a module when using the from module import * syntax (as is demonstrated by the assignment above). (And I stand corrected on the notion that you could execute "from module import *" in other than module level scope.) If it is your intention to use those variables defined in init to communicate with other modules making the same sort of import, then you probably don't want to use "from module import *" syntax. In that case, you can import just the module, and make assignments into that module's namespace. (e.g., init.xx = 3) If all you care about is getting some "stuff" into your global namespace in a convenient and repeatable way, then I think what I showed both above and originally is fine. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterating over several lists at once
"Gal Diskin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > > On Dec 13, 3:47 pm, "Gal Diskin" <[EMAIL PROTECTED]> wrote: > > Hi, > > I am writing a code that needs to iterate over 3 lists at the same > > time, i.e something like this: > > > > for x1 in l1: > > for x2 in l2: > > for x3 in l3: > > print "do something with", x1, x2, x3 > > > > What I need to do is go over all n-tuples where the first argument is > > from the first list, the second from the second list, and so on... I don't see your previous article. Not sure if you are still looking for a solution, but here's one: >>> [(x, y, z) for x in [1,2,3] for y in list('abc') for z in list('XY')] [(1, 'a', 'X'), (1, 'a', 'Y'), (1, 'b', 'X'), (1, 'b', 'Y'), (1, 'c', 'X'), (1, 'c', 'Y'), (2, 'a', 'X'), (2, 'a', 'Y'), (2, 'b', 'X'), (2, 'b', 'Y'), (2, 'c', 'X'), (2, 'c', 'Y'), (3, 'a', 'X'), (3, 'a', 'Y'), (3, 'b', 'X'), (3, 'b', 'Y'), (3, 'c', 'X'), (3, 'c', 'Y')] This is a bit more compact, but I don't see anything wrong with what you have. -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a process's PID
"eldorado" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] > >>> h = h[:-1] > >>> h > [] Oh, sorry... h is a list here because you are using readlines(). I am used to doing this: fd = os.popen('ps -ef | grep python') s = fd.read() to get a single string. You can do something like s = h[0] and then operate on s, or you can use read() in place of readlines() to get h as a single string, or you can operate on the first element of h: >>> h = ['87334\012'] >>> h[0][:-1] '87334' >>> h[0].rstrip('\n') '87334' All the error handling to do in the case where you actually have multiple processes being matched is up to you. ;) -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: persistant gloabl vars (very newbie) ?
"Stef Mientki" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there a way to run the initialization code from a script(file) once, > to achieve the same effect ? Certainly. This is what Python modules are all about. You should probably read up on those a bit here: http://docs.python.org/tut/node8.html But briefly, probably what you want to do is put some code in a file, say init.py: # init.py X = 3 Y = 5 # A bunch of other stuff And then in your main program, execute from init import * That will take all the module-scoped variables defined in init.py and place them in the namespace of the import statement (whcih could be global, the interactive interpreter, or otherwise) See also the 'global' statement as it relates to modifying global variables in an inner scope. Good luck, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: getting a process's PID
"eldorado" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello, > > I am trying to get python to give me the PID of a process (in this case > HUB). I have it working, except for the fact that the output includes > \012 (newline). Is there a way to ask python not to give me a newline? > > Python 1.4 (Oct 14 1997) [C] > Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam > >>> import os > >>> g = os.popen("ps -ef | grep HUB | grep -v grep | awk '{ print $2 }'") > >>> h = g.readlines() > >>> g.close() > >>> h > ['87334\012'] There's more than one way to do it! (Oh, sorry, that's Perl...) The two most standard ways would be to call strip() on your string to get one sans both leading and trialing whitespace print h.strip() or if you know exactly what you've got (i.e., the newline you don't want is just the last character), you can just get rid of it: h = h[:-1] HTH, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: One module per class, bad idea?
There are arguments of preference to be made on both sides. I think the question largely comes down to what is "workable" and "maintainable". To answer the original question, I think it is not necessarily a bad idea to have one class per file. But if your classes are small, or certain classes are logically related to other classes (e.g., one class is a subclass of another, or one class is implemented in terms of another, or the two classes work together to accomplish some task and it wouldn't make much sense to be using just one of the classes), it makes a lot of sense to keep them together in the same file. If your classes are only a few dozen lines, making lots of files may be more of a pain than having the code together in one file. Where I work, we started with a set of classes that provided a layer of abstraction and encapsulation to accessing our database tables. An object was basically just a loaded DB record and generally didn't provide a lot else. As time went on, we started to code more and more logic into these classes that provided various functions to make it easy to load records, do certain kinds of computations and filtering with them, to generate the SQL to do the insert for the record, etc. The file has now grown into a 6800 line beast (including docstring, whitespace, and CVS history). Pretty much any time we implement some new functionality, there are at least a few changes in that file. When you have multiple developers working on different projects, and they all need to be making changes to that file, the chances for someone making a merge error goes up. So, we are obviously at a point where that file needs to be split up, but there are lots of other files that import and use the one file, so it is a task that has been put off. In retrospect, I wish I has started things under a one class per file strategy, but at the time, it didn't make a lot of sense to split those things up and I didn't anticipate the code getting that big. So... there's no magic "one size fits all" answer here - do what makes sense. As Carl points out, decent editors should be able to handle dispaying different files. I use vim and know I can split the window (both horizontally and vertically), editing either different sections of the same file or different files and can cut and paste between the two windows. In practice, I usually just jump between places in the same file under a single window, or I textually cut and paste between two separate vim sessions, but if that's something you need to do a lot, you might want to invest a bit in learning how to use split windows in your editor. Some of the documentation for doing this under vim can be found here: http://vimdoc.sourceforge.net/htmldoc/windows.html#:split and here: http://vimdoc.sourceforge.net/htmldoc/usr_08.html (I'm sure emacs can do this as well, but I don't know emacs.) If your editor can't handle similar tasks, you might want to consider getting a better editor. HTH, -ej "Carl Banks" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Kent Johnson wrote: > > Carl Banks wrote: > > > Now, I think this is the best way to use modules, but you don't need to > > > use modules to do get higher-level organization; you could use packages > > > instead. It's a pain if you're working on two different classes in the > > > same system you have to keep switching files; but I guess some people > > > prefer to switch files rather than to scroll for some reason. > > > > That would be me. I strongly prefer to switch files rather than scroll. > > I use an editor that makes it easy to switch files. For me it is much > > easier to switch between files than to scroll between two parts of a > > file, and I don't lose my place when I switch back. I like to be able to > > see things side by side. > > Man, I don't know you do it. > > Say I'm sitting there concentrating on programming something, and I see > that I'll have to make a change in another file. All of a sudden, I > have to recall some filename out of thin air. Totally breaks my train > of thought, sometimes I space out trying to think of it because I have > to cold-start an entirely different part of my brain. It's less of a > mental distraction to just scroll. > > I'm in the habit of changing things as soon as the need arises. If I'm > editing A and I see that I'll have to make a change in B, I stop > editing A, change B, then come back to A. For me, it results in MUCH > fewer forgotten changes (YMMV). But it also means a lot of switching. > Consequently, trying to minimize distraction during switches is > important to me. Maybe it isn't if you switch less frequently, and > rarely while in the middle of somthing. I wonder if there's any > correlation between how often one switches location, and preferrence > (tolerance) for file size. I bet the more often one switches location, > the more likely they are to prefer larger files. > > (BTW, any decent editor will let
Re: preemptive OOP?
> class MyNotebook(wx.Notebook): > def __init__(self, parent): > wx.Notebook.__init__(self, parent) > So my question in general is, is it a good idea to default to an OOP > design like my second example when you aren't even sure you will need > it? I know it won't hurt, and is probably smart to do sometimes, but > maybe it also just adds unnecessary code to the program. My feeling is that there is no good reason to add the complexity of your own custom classes if they provide no additional data or behaviour. If you know you have plans to add your own attributes and/or methods to MyNotebook soon, there's no harm in doing this now, but why? You can always create your own custom subclass at the point when you have something of value to add and through the mircale of polymorphism, it will function everywhere a Notebook would. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: how do you know if open failed?
"tobiah" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > SpreadTooThin wrote: > > f = open('myfile.bin', 'rb') > > > > How do I know if there was an error opening my file? > > > try: > open('noexist') > except: > print "Didn't open" That's a way to trap any exception. I think a better answer to the question is "You'll know if it didn't work because Python throws exceptions when it runs into problems." You can catch exceptions and try to do something about them if you want to. Uncaught exceptions cause the interpreter to exit with a stack trace. Sometimes that's the most logical thing to do. >>> fd = open('doesnt_exist', 'rb') Traceback (most recent call last): File "", line 1, in ? IOError: [Errno 2] No such file or directory: 'doesnt_exist' It would throw a different exception if there were a permission problem, for example. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: using the email module
"Sybren Stuvel" wrote: > If the HTML document should really be attached, give it a > Content-Disposition: Attachment > header. Check out the accompanying headers as well, by simply emailing > yourself an attached HTML file and examining the email source. html = """\ ... """ attachment = MIMEText(html, 'html') attachment['Content-Disposition'] = 'attachment; filename="sample.html"' msg.attach(attachment) # Ah! Yes, that works! Thank you! ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: help tranlating perl expressions
"David Bear" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > my $klen = length($key); > my $blen = 64; > my $ipad = chr(0x36)x$blen; > my $opad = chr(0x5c)x$blen; > > I don't know if I ever seen any way in python of created a fixed size > string. Can anyone show me how to implement the same statements in python? Certainly, you can create fixed-length strings in python: >>> n = 7 >>> chr(0x36) * n '666' > I when python XOR's strings, is it the same as when perl xor's them? No, XOR is a bitwise operation that does not apply to strings. >>> 5 ^ 0 5 >>> 5 ^ 0xF 10 >>> 'a' ^ 'b' Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for ^: 'str' and 'str' See also the 'struct' module: http://docs.python.org/lib/module-struct.html -- http://mail.python.org/mailman/listinfo/python-list
using the email module
THE GOAL: I need to send an email with a simple ASCII text body and an attached HTML file. I have scripts that send basic emails via the smtplib module that don't have any attachements and that seems to work fine. I first looked at the mimetools modules but it says it is depreceated since 2.3, so I started trying to use the email module. Here is a script that basically follows the second example given in section 7.1.13 of the Python Library Reference (http://docs.python.org/lib/node162.html). (***Note that there are some mistakes in that documentation about module names.***) When I run this and view the email I receive in MS Outlook Express, what I see is the HTML rendered in the body of the message, my body is not seen anywhere and there is no attachment. (Note: I like to bash MS as much as anyone: the reality is I need to work with this client - save it) I have not read the whole spec for RFC 822 and don't profess to understand it, but that's the point of having modules like email, right? Am I misunderstanding something about how I am using 'email' here or is this module not working right? Does this give you an email with an HTML file attachement on your client? Can someone kindly point out what I've done wrong or give me a working example? Thanks! -ej Here's the script (put in your own email and server if you want to run it), and the text (with some identifying info stripped) of the email I receive is below that: #!/usr/bin/env python import smtplib from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart # GLOBAL DATA #= MAIL_SERVER = 'your_server.com' MAIL_SUBJECT = "Python.SMTP email test" MAIL_TO = '[EMAIL PROTECTED]' MAIL_FROM= "Python.SMTP email test" # Create a text/plain message Body = """\ This is intended to be the body of my email. The HTML below should not be seen directly in the body but should be a separate attachment. """ msg = MIMEMultipart() msg['Subject'] = MAIL_SUBJECT msg['From']= MAIL_FROM msg['To'] = MAIL_TO msg.preamble = Body html = """\ Sample HTML File Can you see this? This is a short paragraph. """ msg.attach(MIMEText(html, 'html')) # print msg.as_string() # Send the message via our own SMTP server, but don't include the # envelope header. smtp = smtplib.SMTP(MAIL_SERVER) smtp.sendmail(MAIL_FROM, [MAIL_TO], msg.as_string()) smtp.close() # end of python script Here's the text of the email I received: Return-Path: Delivered-To: [EMAIL PROTECTED] Content-Type: multipart/mixed; boundary="===1669450343==" MIME-Version: 1.0 Subject: Python.SMTP email test From: Python.SMTP email test To: [EMAIL PROTECTED] This is intended to be the body of my email. The HTML below should not be seen directly in the body but should be a separate attachment. --===1669450343== Content-Type: text/html; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sample HTML File Can you see this? This is a short paragraph. --===1669450343==-- -- http://mail.python.org/mailman/listinfo/python-list
Re: __getattr__ and functions that don't exist
Thanks for your reply, Nick. My first thought was "Ahhh, now I see. That's slick!", but after playing with this a bit... >>> class Foo: ... def __getattr__(self, attr): ... def intercepted(*args): ... print "%s%s" % (attr, args) ... return intercepted ... >>> f = Foo() >>> f __repr__() Traceback (most recent call last): File "", line 1, in ? TypeError: __repr__ returned non-string (type NoneType) my thought is "Oh... that is some nasty voodoo there!" Especially if one wants to also preserve the basic functionality of __getattr__ so that it still works to just get an attribute where no arguments were given. I was thinking it would be clean to maintain an interface where you could call things like f.set_Spam('ham') and implement that as self.Spam = 'ham' without actually having to define all the set_XXX methods for all the different things I would want to set on my object (as opposed to just making an attribute assignment), but I am starting to think that is probably an idea I should just simply abandon. I guess I don't quite follow the error above though. Can you explain exactly what happens with just the evaluation of f? Thanks, -ej "Nick Smallbone" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Erik Johnson wrote: > > Maybe I just don't know the right special function, but what I am wanting to > > do is write something akin to a __getattr__ function so that when you try to > > call an object method that doesn't exist, it get's intercepted *along with > > it's argument*, in the same manner as __getattr__ intercepts attributes > > references for attributes that don't exist. > > > > > > This doesn't quite work: > > > > >>> class Foo: > > ... def __getattr__(self, att_name, *args): > > ... print "%s%s" % (att_name, str(tuple(*args))) > > ... > > >>> f = Foo() > > The problem is that the call to f.bar happens in two stages: the > interpreter calls getattr(f, "foo") to get a function, and then it > calls that function. When __getattr__ is called, you can't tell what > the parameters of the function call will be, or even if it'll be called > at all - someone could have run "print f.bar". > > Instead, you can make __getattr__ return a function. Then *that* > function will be called as f.bar, and you can print out its arguments > there: > > class Foo: > def __getattr__(self, attr): > def intercepted(*args): > print "%s%s" % (attr, args) > return intercepted > -- http://mail.python.org/mailman/listinfo/python-list
__getattr__ and functions that don't exist
Maybe I just don't know the right special function, but what I am wanting to do is write something akin to a __getattr__ function so that when you try to call an object method that doesn't exist, it get's intercepted *along with it's argument*, in the same manner as __getattr__ intercepts attributes references for attributes that don't exist. This doesn't quite work: >>> class Foo: ... def __getattr__(self, att_name, *args): ... print "%s%s" % (att_name, str(tuple(*args))) ... >>> f = Foo() >>> f.bar bar() >>> f.bar(1,2,3) bar() Traceback (most recent call last): File "", line 1, in ? TypeError: 'NoneType' object is not callable >>> f.bar() bar() Traceback (most recent call last): File "", line 1, in ? TypeError: 'NoneType' object is not callable Is there some other special function like __getattr__ that does what I want? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
cgi: getting at raw POST data?
I am trying to work with a program that is trying make an HTTP POST of text data without any named form parameter. (I don't know - is that a normal thing to do?) I need to write a CGI program that accepts and processes that data. I'm not seeing how to get at data that's not a named form parameter. I wrote a simple CGI program to echo a string representation of the cgi.FieldStorage class that's recevied, and one to make an HTTP POST to it (once with the way I normally encode a "standard" HTML form, and once with just a multiline string). It doesn't look to me like the FieldStorage class is exposing anything for me to grab ahold of in the latter case. I don't see any other likely looking candidates in the cgi module. My program code is below. Anyone have any suggestions about how to get at raw POST data (as a CGI program)? Thanks for taking the time to read my article! :) -ej results of running 'post' each way: > post form FieldStorage(None, None, [MiniFieldStorage('buckle', 'my shoe'), MiniFieldStorage('one', 'two')]) > post other FieldStorage(None, None, []) #! /usr/local/bin/python "post" import os, sys, time, string import httplib, urllib what = sys.argv[1] server = "localhost" url= "/test_POST" conn = httplib.HTTPConnection(server) conn.putrequest('POST', url) if what == 'form': form = { 'one' : 'two', 'buckle' : 'my shoe' } DATA = urllib.urlencode(form) else: DATA = """\ line 1 this is my little stream of raw data put into POST without any parameter name. """ conn.putheader('Content-Length', str(len(DATA)) ) conn.endheaders() conn.send(DATA) response = conn.getresponse() text = response.read() conn.close() # done with current machine print text #! /usr/bin/python "test_POST" # Python STANDARD INCLUDES import sys import cgi import cgitb; cgitb.enable() # MAIN # get stuff out of POST parameters if __name__ == "__main__": # dump out a web page print """\ Content-type: text/html %s """ % str(cgi.FieldStorage(keep_blank_values=True)) -- http://mail.python.org/mailman/listinfo/python-list
Re: exception handling for a function returning several values
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I try to use y or z inappropriately when they are None, the program > will stop. An alternative is to return an error flag in addition to y > and z from function foo and check the value of the error flag in the > calling program. This seems a bit awkward. It seems to me you would be undermining the intent of exceptions here. If there is some reason foo() can't proceed with x, then either some sort of a "standard exception" gets thrown as a result of trying to, or you can detect the condition within foo() and raise a custom exception which adequately decribes the problem. Smart callers of foo() are then coded with the knowledge that not all values of 'x' are guaranteed to produce the "normal" results, and have one or more 'except' clauses for them to do whatever it is they think is most appropriate with that exception. HTH! :) -ej -- http://mail.python.org/mailman/listinfo/python-list
PHP session equivalent?
There are a lot of things about PHP I was not too keen on and hence why my company is primarily doing Python these days, but one thing I was quite impressed with was the ease with which it provided session functionality... And then in another CGI script do basically the same thing and get the value of $my_var back. Setting of a session ID cookie happens automagically. This is quite handy and simple. I don't think it's quite so simple in Python (which is not to say I think PHP is better than Python). Doing a little extra work is no big deal, but could someone be so kind as to lay out what needs to be done for a Python CGI script to get essentially the same functionality? Are there Python modules that implement a lot of this already? We are currently running under an Apache server (on SuSE Linux 8.2). I'm not clear on whether some session functionality is provided there? We may be moving to Zope before too long (trying to find some time to evaluate it), so a method that is not strictly dependent on Apache would be preferable (in the short term that may suffice). Thanks for taking the time to read my post! :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Commerical graphing packages?
Thank you both for your input. I will check them out. :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Commerical graphing packages?
I am wanting to generate dynamic graphs for our website and would rather not invest the time in developing the code to draw these starting from graphics primitives. I am looking for something that is... "fairly robust" but our needs are relatively modest: X-Y scatter plots w/ data point symbols, multiple data set X-Y line plots, bar charts, etc. Preferably this would come from a company that can provide support & decent documentation, and a package that can be installed without a bunch of extra hassle (e.g., needs Numeric Python, needs to have the GD library installed, needs separate JPEG encoders, font libraries, etc.) I am aware of ChartDirector (http://www.advsofteng.com/ ) which explicitly supports python and seems to be about the right level of sophistication. I don't really know of any other packages in this space, do you? I am seeking feedback and reccomendations from people who have used this package or similar ones. I am particularly interested to hear about any limitations or problems you ran into with whatever package you are using. Thanks for taking the time to read my post! :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Tkinter.Canvas saved as JPEG?
I want to draw some simple (dynamic) graphs and get these saved as a JPEG file to reference in a web link. I am aware of PIL (Python Image Library), but unfortunatley my system does not have it built. After looking at the README for it and seeing it depends on two separate packages to support JPEG and TrueType font, I though maybe there was an easier way. Tkinter is currently built and working on my Python 2.2.2 installation. Is there some simple path to take a Tkinter.Canvas with some stuff drawn on it and get it into a file as a JPEG (without anything from PIL, preferably just using standard libraries)? (I have John Grayson's book. I haven't read the whole thing but I'm not having much luck readily finding a way to do this, though it may be there somewhere. Feel free to cite page numbers there if that helps.) Thanks for taking the time to read my post. :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy Q: dealing with object type
> Steven Bethard <[EMAIL PROTECTED]> wrote: > > py> class A: > > ... pass > > ... > > py> class B: > > ... pass > > ... > > py> a = A() > > py> a.__class__ == A > > True > > py> a.__class__ == B > > False "Just" <[EMAIL PROTECTED]> wrote > Uh, isinstance(a, A) works for both new-style and old-style classes. > Heck, isinstance() even works in Python 1.5.2... Oh, there! Not that there is anything wrong with new classes, but that is just the sort of thing that I expected to find. No, neither of these is bad at all. I was looking for something like the obj.__class__ attribute, but I couldn't see it under dir(obj). So, why is _class__ magically tucked away where you can't see it? That doesn't seem very "Pythonic". I also looked in my two python books for instance(), or instanceof() functions - wasn't seeing anything. Actually, now that I check the indices of "Learning Python" 1E & "Programming Python" 2E, I don't see isinstance() either. How unfortunate. :( As an aside, I notice a lot of other people's interpreters actually print 'True' or 'False' where my system prints 0 or 1. Is that a configuration that can easily set somewhere? Thanks for your help! -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: streaming a file object through re.finditer
Is it not possible to wrap your loop below within a loop doing file.read([size]) (or readline() or readlines([size]), reading the file a chunk at a time then running your re on a per-chunk basis? -ej "Erick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ack, typo. What I meant was this: > cat a b c > blah > > >>> import re > >>> for m in re.finditer('\w+', file('blah')): > > ... print m.group() > ... > Traceback (most recent call last): > File "", line 1, in ? > TypeError: buffer object expected > > Of course, this works fine, but it loads the file completely into > memory (right?): > >>> for m in re.finditer('\w+', file('blah').read()): > ... print m.group() > ... > a > b > c > -- http://mail.python.org/mailman/listinfo/python-list
Re: Easy Q: dealing with object type
"Erick" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Ah, you're running into the "old-style classes vs. new style classes". > Try subclassing from "object". > > For example: > > >>> class A(object): That works! :) I guess I am fortunate to be running 2.2 - looks kinda ugly prior to that. > Check out the following article, it should answer your questions: > http://www.python.org/doc/2.2.3/whatsnew/sect-rellinks.html#SECTION00031 Thank you both for your replies! :) -ej -- http://mail.python.org/mailman/listinfo/python-list
Easy Q: dealing with object type
I quickly browsed through section 9 of the Tutorial, tried some simple Google searches: I'm not readily seeing how to test class type. Given some object (might be an instance of a user-created class, might be None, might be list, might be some other "standard" type object instance), how do you test its type? Python 2.2.2 (#1, Mar 17 2003, 15:17:58) [GCC 3.3 20030226 (prerelease) (SuSE Linux)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class A: ... pass ... >>> obj = A() >>> obj <__main__.A instance at 0x81778d4> # Here, it's fairly obvious its an A-type object. A as defined in module '__main__'. # Some of the comparisons against "Python primitives", work as you might expect... >>> int >>> type(3) == int 1 >>> ls = range(3) >>> ls [0, 1, 2] >>> type(ls) >>> type(ls) == list 1 >>> type({}) == dict 1 >>> type(3.14) == float 1 # but this doesn't seem to extend to user-defined classes. >>> dir(obj) ['__doc__', '__module__'] >>> obj.__module__ '__main__' >>> type(obj) >>> type(obj) == A 0 >>> type(obj) is A 0 # The following "works", but I don't want to keep a set of instances to compare against >>> obj2 = A() >>> type(obj) == type(obj2) 1 -- http://mail.python.org/mailman/listinfo/python-list
SUCCESS!
- Original Message - From: "Peter Otten" <[EMAIL PROTECTED]> > According to http://cnswww.cns.cwru.edu/php/chet/readline/CHANGES the > features you missed were introduced in readline 4.0 and 4.2, so version 4.3 > should be sufficient. So let me ask you again, you have both the readline > and the readline-devel package installed? If yes, and configure still > complains, it may be time to look for something entirely different... Sorry! Sorry! I made a mistake - I went and checked whether readline was installed and not readline-devel. I installed readline-devel. (Thank you for re-asking that question.) Interestingly, configure *still* says... [EMAIL PROTECTED]:~/Python-2.3.4> ./configure | grep readline checking for rl_pre_input_hook in -lreadline... no checking for rl_completion_matches in -lreadline... no And the readline module is still not configured by default: #readline readline.c -lreadline -ltermcap But... if I change the line (in Modules/Setup) above to: readline readline.c -lreadline I get a clean compile and my up-arrow is now fixed! Thank you so much for your help, Peter! :) I don't know how to look at what is in a .so file, and I'm not clear on whether /usr/lib/libreadline.a and the /usr/include/readline headers existed prior to installing readline-devel or not (I would guess not), but it would seem that version 4.3 definitely *should* be sufficient (as you pointed out). [EMAIL PROTECTED]:/usr/lib> ls *readline* libguilereadline-v-12.a libguilereadline-v-12.so.12 libreadline.so libguilereadline-v-12.la libguilereadline-v-12.so.12.3.0 libguilereadline-v-12.so libreadline.a [EMAIL PROTECTED]:/usr/lib> nm libreadline.a | grep letion_match 08d0 t gen_completion_matches 1c60 T rl_completion_matches 0070 T completion_matches U rl_completion_matches [EMAIL PROTECTED]:/usr/lib> nm libreadline.a | grep input_hook 0030 B rl_pre_input_hook [EMAIL PROTECTED]:/usr/lib> cd /usr/include/readline/ [EMAIL PROTECTED]:/usr/include/readline> ls chardefs.h keymaps.h rlconf.h rltypedefs.h history.h readline.h rlstdc.h tilde.h [EMAIL PROTECTED]:/usr/include/readline> grep input_hook * readline.h:extern rl_hook_func_t *rl_pre_input_hook; [EMAIL PROTECTED]:/usr/include/readline> grep rl_completion_matches * readline.h:extern char **rl_completion_matches PARAMS((const char *, rl_compentry_func_t *)); So, there still seems to be a misbehaviour in the configure script. I'm sure there must be other people on similar systems that would like to just type: ./configure make make install and be done with it, running v2.3.4 (or other?) with command line editing working! Looks like a bug worth reporting, yeah? Thanks again for your help! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: building Python: up arrow broken on SuSE Linux 8.2
"Peter Otten" <[EMAIL PROTECTED]> wrote... > Have you ensured (with yast) that readline-devel is actually installed? I had not previously, but (not surprisingly) version 4.3 is installed. :) Good idea - I thought maybe I would be able to do an online update (YOU) to it, but it is taking forever to get a patch list. I don't understand it, we have a pretty decent internet connection (DSL). I now have the readline version 5.0 library built locally. Can someone give me some clues about how to get it statically linked? Thanks, -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: building Python: up arrow broken on SuSE Linux 8.2
"Erik Johnson" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > So I downloaded & built libreadline version 5.0. I have libreadline.a > and shlib/libreadline.so.5.0 files. Having done Python & other scripting > languages for a while, I have sort of forgotten all the ugly details about C > compilation. I'm trying to figure out how to get Python2.3.4. statically > linked with the .a file and not muck with the system shared libraries and > let other applications fend for themselves. Any advice on how to statically > link in this library so the Python build is happy? What I thought might be obvious and easy does not work, BTW... In the Modules/Setup file I put this... readline readline.c -I/home/ej/readline-5.0 -L/home/ej/readline-5.0 -lreadline re-ran configure and tried the make again. No joy. :( Now I remember why I ended up using things like Perl & Python in the first place... [EMAIL PROTECTED]:~/Python-2.3.4> make gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototyp es -I. -I./Include -DPy_BUILD_CORE -o Modules/config.o Modules/config.c gcc -pthread -c -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototyp es -I. -I./Include -DPy_BUILD_CORE -DPYTHONPATH='":plat-linux2:lib-tk"' \ -DPREFIX='"/usr/local"' \ -DEXEC_PREFIX='"/usr/local"' \ -DVERSION='"2.3"' \ -DVPATH='""' \ -o Modules/getpath.o ./Modules/getpath.c gcc -pthread -fno-strict-aliasing -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -I. -I./Include -DPy_BUILD_CORE -I/home/ej/readline-5.0 -c ./Modules/readline.c -o Modules/readline.o Modules/readline.c:26:31: readline/readline.h: No such file or directory Modules/readline.c:27:30: readline/history.h: No such file or directory Modules/readline.c: In function `parse_and_bind': Modules/readline.c:49: warning: implicit declaration of function `rl_parse_and_bind' Modules/readline.c: In function `read_init_file': Modules/readline.c:68: warning: implicit declaration of function `rl_read_init_file' Modules/readline.c: In function `read_history_file': Modules/readline.c:89: warning: implicit declaration of function `read_history' Modules/readline.c: In function `write_history_file': Modules/readline.c:111: warning: implicit declaration of function `write_history' Modules/readline.c:113: warning: implicit declaration of function `history_truncate_file' Modules/readline.c: In function `set_completer_delims': Modules/readline.c:287: error: `rl_completer_word_break_characters' undeclared (first use in this function) Modules/readline.c:287: error: (Each undeclared identifier is reported only once Modules/readline.c:287: error: for each function it appears in.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Where can I find Mk4py.dll for python24 ?
I don't know what metakit or the file you are looking for is, but a simple search on google turns up the following article where a guy built it for Python 2.2 and was willing to mail that to people. Try contacting him: http://www.equi4.com/pipermail/metakit/2002-March/000560.html HTH, -ej "Jose Rivera" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I installed the new release and I have not been able to make work metakit. > > Please give me some help to enjoy metakit and python 24. > > Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: building Python: up arrow broken on SuSE Linux 8.2
> Do you have the GNU readline library installed and within Python's > reach (lib in LD_LIBRARY_PATH or in /etc/ld.so.conf with subsequent > call of ldconfig)? I think you are on the right path. I later found an Apple article online that answered essentially my question saying libreadline wasn't included on the Apple Python distribution the OP was asking about. I now notice this in the output of configure: checking for rl_pre_input_hook in -lreadline... no checking for rl_completion_matches in -lreadline... no My system has /lib/libreadline.so.4.3. I guess it does not define these newer functions and so that is why the readline module was not configured in Setup to start with? That is the presumption I am working on. So I downloaded & built libreadline version 5.0. I have libreadline.a and shlib/libreadline.so.5.0 files. Having done Python & other scripting languages for a while, I have sort of forgotten all the ugly details about C compilation. I'm trying to figure out how to get Python2.3.4. statically linked with the .a file and not muck with the system shared libraries and let other applications fend for themselves. Any advice on how to statically link in this library so the Python build is happy? Thanks, -ej - Original Message - From: "Peter Maas" <[EMAIL PROTECTED]> Newsgroups: comp.lang.python Sent: Wednesday, January 26, 2005 3:22 AM Subject: Re: building Python: up arrow broken on SuSE Linux 8.2 > Erik Johnson schrieb: > > I am trying to upgrade my Python installation. After downloading > > sources and building Python 2.3.4, I am unable to use the command > > history editing feature in the interactive interpreter (where the > > up-arrow would previously give you the last command line to edit, > > it now just prints "^[[A".) > > > -- > --- > Peter Maas, M+R Infosysteme, D-52070 Aachen, Tel +49-241-93878-0 > E-mail 'cGV0ZXIubWFhc0BtcGx1c3IuZGU=\n'.decode('base64') > --- -- http://mail.python.org/mailman/listinfo/python-list
Re: python without OO
"Davor" <[EMAIL PROTECTED]> wrote > I do not hate OO - I just do not need it for the project size I'm > dealing with - and the project will eventually become open-source and > have additional developers... If you think your project is valuable enough to eventually be "Open Source", you can bet that one of the first criticisms it will face is that it is not OO if it is perceived that there would be any advantage to being so. If your question is "Can I write useful Python code without writing my own classes, without creating a class inheritance heirarchy, etc.?" then the answer is definitely "Yes!" Python has lots of very useful and practical libraries to allow you to do all sorts of cool things. Many of those interfaces though are presented in an OO manner (to varying degrees). >so I would prefer that we all stick to > "simple procedural" stuff rather than having to deal with a developer > that will be convincing me that his 50 layers inheritance hierarchy is > good since it exists in some weird pattern that he saw somewhere on > some Java design patterns discussion board :-) and other "proper" OO > design issues... If your question is "Can I somehow hobble Python so that there are no objects anywhere and it is not possible for other developers to even think about creating something I can't understand?" then I would ask how is it you are leading a team of other programmers that is apparently not afraid of OO concepts? You can write lot's of code that is just functions, and have functions call other functions, but what does a 'def' statement (python's syntax for function definition) do? It instantiates a function object. That function can be copied (well, the reference to it, anyway), passed to other functions, returned from functions, stored in variables, etc. You may or may not see any practical use for that, but Python was (very wisely) designed to be OO right from the very start - it definitely wasn't something that was added on later. You might want to spend a little time pondering why that is. If you don't understand the difference between pop(mylist) and mylist.pop(), it would be a wise career move to invest a little time to understand what the difference is and why the state of software development has come to prefer one over the other. At the bottom, practically everything in Python is an object... >>> dir(42) ['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__getattribute__', '__hash__', '__hex__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__str__', '__sub__', '__truediv__', '__xor__'] there's just no getting around it. If you want to set down the groundrules for your project that you will stick to basically just procedural code, fine - that's a project management issue. If you are insistent there can be no objects anywhere in your implementation, Python is definitely the WRONG choice. Well... there is no choice. It would be impossible with Python. Note also that Perl is definitely out, as is JavaScript and even PHP. ANSI C might work and (as pointed out earlier), some other likely candidates are sh, bash, csh, ksh... I don't know a lot about Tcl/Tk - I think it implements some rather OO'ish stuff, but worth consideration. Good luck. -ej -- http://mail.python.org/mailman/listinfo/python-list
building Python: up arrow broken on SuSE Linux 8.2
I am trying to upgrade my Python installation. After downloading sources and building Python 2.3.4, I am unable to use the command history editing feature in the interactive interpreter (where the up-arrow would previously give you the last command line to edit, it now just prints "^[[A".) This is a feature I use often, and it kinda nullifies that warm fuzzy feeling you get when things are otherwise working as expected. Python 2.2.2 was installed via YaST (standard SuSE distribution) and works fine. Unfortunately, several modules I need are not part of that installation and there doesn't seem to be a newer installation via that route (that I know of). I downloaded source and built Python 2.3.4 in my local directory. There were a lot of warnings like this: Objects/intobject.c:1125: warning: comparison between signed and unsigned Objects/intobject.c:1135: warning: comparison between signed and unsigned I don't know exactly what "normal" output is, but things seem to have gone pretty well, as this is the output after 'make test': ... test_zlib 226 tests OK. 29 tests skipped: test_aepack test_al test_bsddb test_bsddb185 test_bsddb3 test_cd test_cl test_curses test_dbm test_email_codecs test_gdbm test_gl test_imgfile test_linuxaudiodev test_macfs test_macostools test_nis test_normalization test_ossaudiodev test_pep277 test_plistlib test_scriptpackages test_socket_ssl test_socketserver test_sunaudiodev test_timeout test_urllibnet test_winreg test_winsound 3 skips unexpected on linux2: test_dbm test_gdbm test_bsddb (I'm not doing anything with DBM stuff, so I don't think I care about the three skipped tests.) I thought the problem may have had something to do with the curses module, which is apparently not enabled by default. In the Modules/Setup file, I changed this: # First, look at Setup.config; configure may have set this for you. #_curses _cursesmodule.c -lcurses -ltermcap # Wrapper for the panel library that's part of ncurses and SYSV curses. #_curses_panel _curses_panel.c -lpanel -lncurses to this (my system has /usr/lib/libncurses.so.5.3): # First, look at Setup.config; configure may have set this for you. #_curses _cursesmodule.c -lcurses -ltermcap _curses _cursesmodule.c -lncurses # Wrapper for the panel library that's part of ncurses and SYSV curses. #_curses_panel _curses_panel.c -lpanel -lncurses I got a clean compile and the test_curses.py file executes silently: sand:~/Python-2.3.4/Lib/test> ../../python ./test_curses.py sand:~/Python-2.3.4/Lib/test> Unfortunately, that didn't solve the problem. Has anyone else seen this problem? Or, more importantly, can someone tell me how to fix this? Thanks for taking the time to read my post. -ej -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie questions
> do yo have any idea of what is causing this problem? > is it possible to do self.SortiesAnimeTitreLabel = [] to reset the var? (it > seems to work outside of the sub, but I believe that the var I'm erasing is > not the one I want but a local copy. Yeah. I'm no Python guru, but I have a pretty good idea. Your intuition is correct - you're killing a local copy. Functions (and methods) have their own namespace. Variables declared within a function are local that that function's name space, as well as formal variables that appear on the function declartion (definition) line. >>> z = 'z' >>> def f(x): ... print dir() ... del x ... print dir() ... >>> z 'z' >>> f(z) ['x'] [] >>> z 'z' >>> Secondly, within a class method, x and self.x are two different things. The first is just a variable within the method namespace, the second is an object attribute. So, for your example, there probably is no reason to go kill each list element individually (unless perhaps other code is accessing that list NOT through the object.) Within an object method, if you honestly don't want to kill the variable, you could just say: self.SortiesAnimeTitreLabel = [] and that replaces that object's list with an empty one. Unless there are other references to that same list, hte garbage collector will take it. Other code accessing the list through this object's handle will see the new, empty list, which I think is what you want in this case. HTH, -ej -- http://mail.python.org/mailman/listinfo/python-list
GUIs: wxPython vs. Tkinter (and others)
I am looking for some input on GUI libraries. I want to build a Python-driven GUI, but don't really understand the playing field very well. I have generally heard good things about wxPython. I happen to already own John Grayson's book about Tkinter programming, so that is rather handy if I decide to use Tkinter. I have done some things slightly more involved than "Hello World" in Tkinter - I have never used wxPython. So, basically the points I am looking to have illuminated are: o What features does wxPython offer that Tkinter cannot (and vice versa)? o Is the general programming methodology pretty much the same between the two (e.g., the general program structure - using callbacks & Frames, etc. is the same, it's just a question of calling different widgets with their own arguments)? o Do you have a strong preference for one over the other (or some other toolkit)? Why? o Are there any platform and/or performance issues I should be aware of? o Is animation and graphics particularly better suited to one over the other? o Other important contrasts/similarities I should be aware of? So... I know this question must come up fairly often. I did do a search for "wxPython" and "Tkinter" - of the articles I currently have visibility of, I saw one bug in wxPython discussed and nothing about Tkinter. Anything else than can contribute to a "bird's eye view" understanding of the two (or other) toolkits would be appreciated. Thanks for taking the time to read my post. Sincerely, -ej -- http://mail.python.org/mailman/listinfo/python-list