Re: [ANN] PyScript 0.5 released
Hi ! The good URL is : http://pyscript.sourceforge.net :-) -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: global variable, ok for string, bad for int
francisl [EMAIL PROTECTED] wrote: I have a problem when I declare global variable. If it is string, dict, array or tuple, everything goes fine, but with int, I get an used before declaration error. Excuse me for being dubious, but I don't believe you. Both of the examples you posted work fine in Python 2.3 on Windows XP. Please type the EXACT script you ran, and show us the EXACT error message you get. You can cut-and-paste from the cmd shell script to make sure we see the right output. here a sample : vardict = {'un':1, 'deux':2} def print_value(): print vardict['un'] # ok, that works #!/bin/python varint = 1 def print_value(): print varint # ok, that failed python 2.3.4 - windows2000 (it works in linux!) -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Freezing a mutable (was Re: lambda)
Op 2005-01-21, Bengt Richter schreef [EMAIL PROTECTED]: On 20 Jan 2005 14:07:57 GMT, Antoon Pardon [EMAIL PROTECTED] wrote: Would you like a dictionary that acts as you want and takes care of all problems internally, and accepts keys and values of any type without wrapping or other modification -- or do you want a wrapper that can make any object suitable for use as key or value in python's curent definition of dict? Just DYFR please. You still haven't you know ;-) My feeling is that I'm hungry and would like to eat and you ask whether my requirements are a sandwhich or a bowl of soup. :-) The real requirement IMO is that any attempt to mutate an object wont result in a mutated key. Both proposals seem to solve that. The second is at the moment for me the most interesting to discuss, since it is a new approach to me, and most likely to learn me something new. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best python web-developer's editor
On Thu, 20 Jan 2005 18:47:53 +, andy [EMAIL PROTECTED] wrote: Anybody like to comment on which editor they use for python web app development - for both discrete and mixed python and html code, and why? I use DrPython, because: It is open source, written in python and wxPython and use wx.stc. It is extensible via plugins and script, you have a python prompt, free shortcut assignments, ... It is developed heavily. I'm a member of the project :) http://sourceforge.net/projects/drpython/ I'm comfortable with IDLE (used it for years) but of course it lacks ftp or webDAV abilities, obviously because it's not intended for that type of use. What do you mean with ftp abilities exactly? Saving and opening files directly over ftp? [...] regards, -- Franz Steinhaeusler -- http://mail.python.org/mailman/listinfo/python-list
RE: Print to Windows default Printer
[Samantha] | Thanks for the URL. I finally am able to print the temp file. | Not exactly | what I wanted, but it will work. The code I used to print was this: | | os.system (start /min notepad /P temp.txt) | | Thanks ALL! | S Glad you got it sorted. What you describe is, in fact, the slightly more specific version of this technique: http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html#shellexecute which relies on the fact that .txt files are bound to notepad.exe for printing. (Or that they're bound to *something* for printing, since you don't care what it is, so long as it prints!) 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: tkinter socket client ?
On 20 Jan 2005 22:25:52 -0800, rumours say that Tonino [EMAIL PROTECTED] might have written: [tkinter gui for a socket client, lots of data from the socket] NOW - HOW do I get the server's sent data to continuiosly print in the Text() widget ? You need to use: yourTextWidget.insert(Tkinter.END, data) # to insert the data yourRootWindow.update_idletasks() # to update the GUI -- TZOTZIOY, I speak England very best. Be strict when sending and tolerant when receiving. (from RFC1958) I really should keep that in mind when talking with people, actually... -- http://mail.python.org/mailman/listinfo/python-list
Graph and Table implementation
could anyone please help me! what and how is the best implementation of creating a table based on data coming from the serial port ? and also how would i be able to create graphs (2D) based on these data? opinions and suggestion are most highly welcome. thanks. jr -- http://mail.python.org/mailman/listinfo/python-list
TypeError error on tkinter.createfilehandler dummy example
Hi, I'm getting the following error: Traceback (most recent call last): File "..\kk.py", line 37, in ? tkinter.createfilehandler(filex, tkinter.READABLE, _dispatch) TypeError: 'NoneType' object is not callable when executing this code on my Windows box: from Tkinter import * def _dispatch(self, *args): print "voila" filex = open('d:\\zz.txt', 'r') tkinter.createfilehandler(filex, tkinter.READABLE, _dispatch) Any ideas? What am I missing? I've been searching for something like this with no luck. I cannot imagine a simpler code for testing tkinter.createfilehandler functionality but it does not work :( TIA -- David Santiago -- http://mail.python.org/mailman/listinfo/python-list
DevX: Processing EDI Documents into XML with Python
You don't have to rely on expensive and proprietary EDI conversion software to parse, validate, and translate EDI X12 data to and from XML; you can build your own translator with any modern programming language, such as Python. by Jeremy Jones http://www.devx.com/enterprise/Article/26854 Excerpt: Python is an object-oriented, byte-compiled language with a clean syntax, clear and consistent philosophy, and a strong user community. These attributes (both of the language and the community) make it possible to quickly write working, maintainable code, which in turn makes Python an excellent choice for nearly any programming task. Processing any flavor of EDI is no exception. Hi, just wanted to share with you, that the last issue of the DevX newsletter comes with a Python related article as first item in the list of subjects. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: [ANN] PyScript 0.5 released
http://sourceforge.net/project/showfiles.php?group_id=50346 shows the date of release of pyscript-0.5 as: 2004-05-11 07:00 What is then the reason for this [ANN] ? Claudio Paul Cochrane [EMAIL PROTECTED] schrieb im Newsbeitrag news:[EMAIL PROTECTED] PyScript is a python module for producing high quality postscript graphics. Rather than use a GUI to draw a picture, the picture is programmed using python and the PyScript objects. Some of the key features are: * All scripting is done in python, which is a high level, easy to learn, well developed scripting language. * All the objects can be translated, scaled, rotated, ... in fact any affine transformation. * Plain text is automatically kerned. * You can place abritrary LaTeX expressions on your figures. * You can create your own figure objects, and develop a library of figure primitives. * Output is publication quality. LICENSE: Released under the GPL The major change in this release is a complete rewrite of the Path object. The internals have completely changed and there have been some incompatible changes with previous versions but it's now much closer to what was envisaged for the object. There have also been many bug fixes and minor other improvements. For details see the PyScript web page: a href=http://pyscript.sourceforge.net;pyscript.sourceforge.net/a. PA HREF=http://pyscript.sourceforge.net;PyScript 0.5/A - a python module for producing high quality postscript graphics; rather than use a GUI to draw a picture, the picture is programmed using python and the pyscript objects. (10-Jan-05) -- [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and SOAP
I'd like to write a SOAP client and a SOAP server in Python. Is SOAPy still the way to go, or are there better methods? If you really need SOAP, Nelson did answer your question. But if you are only communicating between two python processes, I suggest pyro. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading ctor doesn't work?
Martin Häcker [EMAIL PROTECTED] wrote: Now I thought, just overide the ctor of datetime so that year, month and day are static and everything should work as far as I need it. That is, it could work - though I seem to be unable to overide the ctor. :( Why is that? Its a bug! http://sourceforge.net/tracker/index.php?func=detailaid=720908group_id=5470atid=105470 However its been fixed in a recent Python 2.3. (I was bitten by the same thing which used to fail but now works after an upgrade of python 2.3!) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
RE: Class introspection and dynamically determining function arguments
From: Mark English [EMAIL PROTECTED] I'd like to write a Tkinter app which, given a class, pops up a window(s) with fields for each attribute of that class. The user could enter values for the attributes and on closing the window would be returned an instance of the class. The actual application I'm interested in writing would either have simple type attributes (int, string, etc.), or attributes using types already defined in a c-extension, although I'd prefer not to restrict the functionality to these requirements. From: Diez B. Roggisch [EMAIL PROTECTED] whatfor is it planned? From: Nick Coghlan [EMAIL PROTECTED] If this only has to work for classes created for the purpose (rather than for an arbitrary class): Although I'm writing it for a specific need with a specific set of classes, I was asking here to find a more general, robust approach. So handling an arbitrary class would be preferable. This is the only way to go, as python has no attribute declarations as static compiled languages have The classes I'm dealing with do have attributes since they're C-Extension types with attributes provided in the tp_getset slot. So this is one case where I can query the class for attributes without having to create an instance. Thanks for making me think of that, since looking in the class's __dict__ pretty much gives me what I want. I'm not sure that that's something I can rely on though which is exactly the sort of issue where I'd like to know if there's a right way (e.g. an existing module) to ask a class for its attributes, without poking around in __dict__ directly and doing some type checking. I guess in a way I'm asking for introspection with a greater degree of granularity than dir. --- The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies. --- -- http://mail.python.org/mailman/listinfo/python-list
Re: Overloading ctor doesn't work?
Nick Craig-Wood wrote: Martin Häcker [EMAIL PROTECTED] wrote: Now I thought, just overide the ctor of datetime so that year, month and day are static and everything should work as far as I need it. That is, it could work - though I seem to be unable to overide the ctor. :( Its a bug! http://sourceforge.net/tracker/index.php?func=detailaid=720908group_id=5470atid=105470 However its been fixed in a recent Python 2.3. My example was developed in Python 2.4. The problem was the immutability of datetime. Kent (I was bitten by the same thing which used to fail but now works after an upgrade of python 2.3!) -- http://mail.python.org/mailman/listinfo/python-list
how to write a tutorial
i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Here are some quick critique: quick example: If the input string is too long, they don't truncate it, but return it unchanged; this will mess up your column lay-out but that's usually better than the alternative, which would be lying about a value. (If you really want truncation you can always add a slice operation, as in x.ljust( n)[:n]. better: If the input string is too long, they don't truncate it, but return it unchanged; - delete: Reverse quotes (``) are equivalent to repr(), but their use is discouraged. - similarly, many places mentioning uncritical info such as warning or reference to other languages should be deleted. the tutorial should be simple, concise, to the point, stand along. Perhaps 1/5th length of the tutorial should be deleted for better. Follow the above principles. at places often a whole paragraph on some so called computer science jargons should be deleted. They are there more to showcase inane technicality than do help the reader. (related, many passages with jargons should be rewritten sans inane jargon. e.g. mutable object.) one easy way to understand these principles is to compare perl's documentation or unix man pages to Python's. The formers are often irrelevant, rambling on, not stand-along (it is written such that it unnecessarily requires the reader to be knowledgable of lots of other things). Python docs are much better, but like many computer language manuals, also suffers from verbiage of tech jargons. (these jargons or passages about them are usually there to please the authors themselves). A exemplary writing in this direction is the Mathematica manual by Stephen Wolfram. Any intelligent layman sans computer science degree can read it straightforwardly, and learn unhindered a language that is tantamount to features of lisp languages. Such documentation is not difficult to write at all. (contrary to the lot of computer scientists or IT pundits morons.) All it take is some simple principles outlined above. Xah [EMAIL PROTECTED] http://xahlee.org/PageTwo_dir/more.html -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a tutorial
Xah Lee wrote: i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Finally! It was about time... Here are some quick critique: Given that you seem to be totally inert to critique yourself - e.g. your continued posting of useless language comparison, and the plethorea of posts requesting to stop that and limit yourself to your mailing list - I doubt you'll get much attention for that. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
RE: Class introspection and dynamically determining function arguments
The classes I'm dealing with do have attributes since they're C-Extension types with attributes provided in the tp_getset slot. So this is one case where I can query the class for attributes without having to create an instance. Thanks for making me think of that, since looking in the class's __dict__ pretty much gives me what I want. I'm not sure that that's something I can rely on though which is exactly the sort of issue where I'd like to know if there's a right way (e.g. an existing module) to ask a class for its attributes, without poking around in __dict__ directly and doing some type checking. I guess in a way I'm asking for introspection with a greater degree of granularity than dir. According to this http://www-106.ibm.com/developerworks/library/l-pyint.html not really - and there are no special moduls neccessary, as everything is at your hands using __dict__ and so on. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Is there a library to parse Mozilla mork documents?
John Reese wrote: Mozilla, Firefox, Thunderbird, and so forth use this awful format called MORK to store all kinds of things: which messages you've read in a newsgroup, headers and indexes into the mbox file of messages in a mail folder, and address books. It's documented to some extent here: http://www.mozilla.org/mailnews/arch/mork/primer.txt Hmmm. Wasn't David McCusker working for the OSA Foundation on Chandler at some point? Anyway, given the references to LDIF (and the fact that I have in the past exported address books from Netscape Communicator in LDIF format), the following specification might help: http://www.faqs.org/rfcs/rfc2849.html Does anyone know of a Python library for parsing these files? A single file basically just stores the equivalent of a nested dictionary with text that can be declared separately and interpolated. jwz has an over-specific perl version at http://www.jwz.org/hacks/marginal.html, which I might have to try to translate if there's nothing already available in Python. I'd look at the python-ldap project: http://python-ldap.sourceforge.net/ The ldif module might be of relevance, but there isn't an example in the documentation which would confirm my suspicions. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter socket client ?
just one problem - I do not know how to sit in a loop accepting messages on the socket connection - writting them to the Text() widget - refreshing the the GUI - and then starting all over where do I put the loop for the socket ? Another thread? Or use twisted, it comes with a tkinter-aware exec-loop: http://twistedmatrix.com/documents/howto/choosing-reactor#auto16: -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
map in Python
I have recently switched over to Python from Perl. I want to do something like this in Python: @test = (a1, a2, a3); map {s/[a-z]//g} @test; print @test; However, I take it there is no equivalent to $_ in Python. But in that case how does map pass the elements of a sequence to a function? I tried the following, but it doesn't work because the interpreter complains about a missing third argument to re.sub. import re test = [a1, a2, a3] map(re.sub([a-z], ), test) print test Thanks in advance. Regards, Stuart stuart AT zapata DOT org -- http://mail.python.org/mailman/listinfo/python-list
Re: map in Python
On 21 Jan 2005 04:25:27 -0800, Stu [EMAIL PROTECTED] wrote: I have recently switched over to Python from Perl. I want to do something like this in Python: @test = (a1, a2, a3); map {s/[a-z]//g} @test; print @test; However, I take it there is no equivalent to $_ in Python. But in that case how does map pass the elements of a sequence to a function? I tried the following, but it doesn't work because the interpreter complains about a missing third argument to re.sub. import re test = [a1, a2, a3] map(re.sub([a-z], ), test) print test This what you want? import re test = [a1, a2, a3] test = [re.sub([a-z], , item) for item in test] test ['1', '2', '3'] -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter socket client ?
thanks for the info - but I really do not want to learn twisted before I can understand Tkinter ;) another thread seems the way - will try that ... Thanks Tonino -- http://mail.python.org/mailman/listinfo/python-list
Re: map in Python
On Fri, 21 Jan 2005 12:37:46 +, Simon Brunning [EMAIL PROTECTED] wrote: This what you want? import re test = [a1, a2, a3] test = [re.sub([a-z], , item) for item in test] test ['1', '2', '3'] Or, if you *must* use map, you can do: test = map(lambda item: re.sub([a-z], , item), test) test ['1', '2', '3'] I much prefer the first list comprehension form myself, but reasonable men can differ... -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: map in Python
You have three ways to do what you want : First wayt is to use lambda. Then, you want to write : map(lambda x: re.sub([a-z], , x), test) Second is to use regular named function : def remove_letters( s ): ... re.sub([a-z], , s) map(remove_letters, test) A third way would be to use the pseudo-currying described there : http://www.python.org/moin/PythonDecoratorLibrary In fact, you need a small generalisation : class curried(object): ... def __init__(self, func, *a, **kw): ... self.func = func ... self.args = a ... self.kwords = kw ... def __call__(self, *a, **kw): ... args = self.args + a ... kwords = dict(self.kwords) ... kwords.update(kw) ... if len(args)+len(kwords) self.func.func_code.co_argcount: ... return curried(self.func, *args, **kwords) ... else: ... return self.func(*args, **kwords) The difference is you can handle the kwords with that version ! Then you want to write this : curried_sub = curried(re.sub) map(curried_sub([a-z], , count=0), test) My opinion is : the simplest and best solution more pythonic is the second one ! The third one is interesting but work only for functions written in Python ! (Hopefully the re.sub function is written in Python). The biggest problem with the first one is that lambda are planned to disappear in future Python versions ... Pierre Stu a écrit : I have recently switched over to Python from Perl. I want to do something like this in Python: @test = (a1, a2, a3); map {s/[a-z]//g} @test; print @test; However, I take it there is no equivalent to $_ in Python. But in that case how does map pass the elements of a sequence to a function? I tried the following, but it doesn't work because the interpreter complains about a missing third argument to re.sub. import re test = [a1, a2, a3] map(re.sub([a-z], ), test) print test Thanks in advance. Regards, Stuart stuart AT zapata DOT org -- http://mail.python.org/mailman/listinfo/python-list
Re: What's the best python web-developer's editor
Emacs For both discrete and mixed python and html code, and why? There's no reason to use anything else. Although I tested and will keep testing other editors/ide, I also went back to emacs and am quite happy with it. However, I sometimes use snavigator (http://sourceforge.net/projects/sourcenav) when I need to browse through a project (although I could use emacs TAGS, I find snavigator to be the best free solution out there to parse large projects) Regards, Philippe -- *** Philippe C. Martin SnakeCard LLC www.snakecard.com *** -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCon Preliminary Program Announced!
On Thu, 20 Jan 2005 22:52:13 -0500, Tim Peters [EMAIL PROTECTED] wrote: The web page needs better formatting. In general, there are no more Suggestions for improvement are welcome. Perhaps the Wiki version of the schedule, at http://www.python.org/moin/PyConDC2005/Schedule, may be better. --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: Zen of Python
Paul Rubin wrote: You snipped out the examples I gave, like [x*x for x in range(5)] leaving unnecessary residue in the name space. Was it not obvious from the beginning that that was a kludge? If it was obviously a kludge, was it not obvious that there would be reason to want to fix it someday? I'm saying that if some new feature is going to need a fix later, it's better to fix it before releasing it in the first place. The scoping problem isn't the the least bit obvious, since the equivalent for loop also happens at local scope: Py lst = [] Py for x in range(5): ... lst.append(x*x) ... Py print x 4 Py lst2 = [y*y for y in range(5)] Py print y 4 However experience has shown that while having the iteration variable visible after a for loop is useful (due to the existence of the break and raise statements), with a list comprehension the identical behaviour is nothing more than namespace pollution (since you can't use list comprehensions for alternate control flow based searches). So Python 2.4's generator expressions are quite happily evaluated in a separate frame, and the fact that the iteration variable is hidden from the containing scope is viewed as a feature. But knowing a priori that copying the for loop semantics exactly would turn out to be a misfeature? I'll go with Steve's assessment of psychic powers ;) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCon Preliminary Program Announced!
I don't care much for parallel tracks myself, because I want to hear basically everything. But we had more proposals of higher quality this year than ever before, so it came down to scheduling more talks in parallel than ever before too, or rejecting perfectly good proposals. Will there be recordings of any of these presentations? There are quite a few times when I want to be at all three tracks at the same time. -- http://mail.python.org/mailman/listinfo/python-list
need help on generator...
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = [1,2,3,4] would like to produce : [1,2], [2,3], [3,4], [1,2,3], [2,3,4] but unfortunately can not, i guess i can do it by using sub generator and maybe enumerate, please if you help could you explain a bit the trick ? looks like this sub generator thing mess me up. (i think it should may be also have [1,], [2,], [3,], [1,2,3,4] , and then be filtered) bests -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph and Table implementation
Jan Rienyer Gadil wrote: could anyone please help me! what and how is the best implementation of creating a table based on What is a table, to you? It could mean anything from something you intend to print, to a GUI-based representation similar to a spreadsheet, to a simple two-dimensional array of data in memory. data coming from the serial port ? and also how would i be able to create graphs (2D) based on these data? Platform? GUI framework, if you've chosen one? etc. etc. I might suggest using wxPython, with a wx.Grid and wxPyPlot, but given how little useful information you've provided, that could well be far from suitable. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on generator...
On 21 Jan 2005 05:58:03 -0800 [EMAIL PROTECTED] (Joh) wrote: i'm trying to understand how i could build following consecutive sets from a root one using generator : l = [1,2,3,4] would like to produce : [1,2], [2,3], [3,4], [1,2,3], [2,3,4] def consecutive_sets(l): ... for i in xrange(2, len(l)): ... for j in xrange(0, len(l)-i+1): ... yield l[j:j+i] ... list(consecutive_sets([1,2,3,4])) [[1, 2], [2, 3], [3, 4], [1, 2, 3], [2, 3, 4]] -- Denis S. Otkidach http://www.python.ru/ [ru] -- http://mail.python.org/mailman/listinfo/python-list
Re: TypeError error on tkinter.createfilehandler dummy example
Hi, The createfilehandler is not supported on Windows since Tcl/TK 8.0. tkinter.createfilehandler is None, so you get the NoneType is not callable error. I wrote a simple module with a mix-in class to solve this problem. I had a lote of code using it on linux and needed to run it on Windows. I can send it to you in pvt, if you want. Pedro Werneck On Fri, 21 Jan 2005 10:27:20 +0100 David [EMAIL PROTECTED] wrote: Hi, I'm getting the following error: Traceback (most recent call last): File ..\kk.py, line 37, in ? tkinter.createfilehandler(filex, tkinter.READABLE, _dispatch) TypeError: 'NoneType' object is not callable when executing this code on my Windows box: from Tkinter import * def _dispatch(self, *args): print voila filex = open('d:\\zz.txt', 'r') tkinter.createfilehandler(filex, tkinter.READABLE, _dispatch) Any ideas? What am I missing? I've been searching for something like this with no luck. I cannot imagine a simpler code for testing tkinter.createfilehandler functionality but it does not work :( TIA -- David Santiago -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCon Preliminary Program Announced!
Timothy Fitz wrote: I don't care much for parallel tracks myself, because I want to hear basically everything. But we had more proposals of higher quality this year than ever before, so it came down to scheduling more talks in parallel than ever before too, or rejecting perfectly good proposals. Will there be recordings of any of these presentations? There are quite a few times when I want to be at all three tracks at the same time. There are currently loose plans to have each session recorded. This will, however, require massive volunteer effort which so far nobody has offered to coordinate, so unless someone steps up to the plate with a sound plan to ensure that at least the initial capture takes place this may remain a pipe dream (there are limits to the chairman's powers that he is starting to treat as actual rather than theoretical ;-) What's actually required? Someone needs to start a resource, with a copy of the schedule ( and a Wiki page might do, its source can be lifted directly from the Wiki source of http://www.python.org/moin/PyConDC2005/Schedule) that allows volunteers to sign up to record specific sessions. We also need a release form that speakers can sign to allow the recording to take place and for it to be published under a suitable Creative Commons license. We need advice on file formats and software for Linux, Windows and Mac (plus any other platforms that may be used): experience says that apparently it's possible to make acceptable recordings with an external microphone such as a lapel mike from the front of the room, without involving the University. If someone wants to liaise about electronic feeds I'll certainly facilitate interaction with GWU as long as the cost is acceptable (zero would be best). Finally we need someone coordinating at the conference to make sure this all happens, that the release forms are collected, and that the sound files are made available - probably on www.python.org. This is a /community conference/, guys. I *know* the Python community can collectively take this task and eat it for breakfast, but please don't believe it will happen as a result of a few newsgroup posts saying what a nice idea it would be. Things don't happen that way, and I have the grey hairs to prove it. Please, make this happen! regards Steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: Example of resolving an alias using Carbon.File module?
Problem solved: from Carbon.File import * fs, _, _ = ResolveAliasFile('/some/path', 1) print fs.as_pathname() -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter socket client ?
You are probably looking for Tkinter.createfilehandler(). Here are some snippets to get you started: tk_reactor = Tkinter._tkinter self.sd = socket(AF_INET, SOCK_STREAM) self.sd.connect((HOST, PORT)) tk_reactor.createfilehandler(self.sd, Tkinter.READABLE, self.handle_input) def handle_input(self, sd, mask): data = self.sd.recv(SIZE) (Sorry if the formatting is busted, blame google groups.) HTH, Neal -- http://mail.python.org/mailman/listinfo/python-list
Dynamic properties
Hello again, I have a dictionary with the following content : 'LZ': {'type': 'N', 'bytes': '8'}, 'LVI000': {'type': 'N', 'bytes': '10'} This could be seen as a interface description to deal with an external program that needs a 18 Byte communication area. 8 and 18 Bytes have to be interpreted as a Number String representation. eg like '018000200' means LZ = 180 and LVI000 = 200 I am now thinking about doing the following class a def some_crap () ... for key in dict.keys (): setattr (self, key, value) so that pgm = a () pgm.LZ = 300 would cause the rekonstruktion of the byte field. === Properties My first try is : fget = lambda self: mygetattr(self, attrname) fset = lambda self, value: mysetattr (self, attrname, value) fdel = lambda self: mydelattr(self, attrname) # fget, fset, fdel are used to reconstruct the byte field setattr (self, key, property (fget, fset, fdel)) :-) This inserts me pgm.LZ and pgm.LVI000 but when trying to access print pgm.LZ it gives me property object at 0x4028102c What am I doing wrong here Regards Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Print a string in binary format
neutrino wrote: Greetings to the Python gurus, I have a binary file and wish to see the raw content of it. So I open it in binary mode, and read one byte at a time to a variable, which will be of the string type. Now the problem is how to print the binary format of that charater to the standard output. It seems a common task but I just cannot find the appropriate method from the documentation. Thanks a lot. FWIW, I work with serial data a lot, and I find the following list comprehension to be a handy output tool for binary data: print .join([%0.2X % ord(c) for c in data]) The space between each byte helps keep things from degenerating into a meaningless mass of numbers, and using 2-digit hex instead of binary works towards the same purpose. (I actually currently use the hex() builtin, but the above just occurred to me, and it will give nicer formatting, and avoids the C-style 0x prefixing each byte) Here's an interesting twiddle, though (there's probably already something along these lines in the cookbook): Py def show_base(val, base, min_length = 1): ... chars = 0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ ... if base 2: raise ValueError(2 is minimum meaningful base) ... if base len(chars): raise ValueError(Not enough characters for base) ... new_val = [] ... while val: ... val, remainder = divmod(val, base) ... new_val.append(chars[remainder]) ... result = .join(reversed(new_val)) ... return (0 * (min_length - len(result))) + result ... Py show_base(10, 2) '1010' Py show_base(10, 2, 8) '1010' Py show_base(10, 16, 2) '0A' Py show_base(254, 16, 2) 'FE' Py show_base(0, 16) '0' Py for base in range(2, 36): ... for testval in range(1000): ... assert testval == int(show_base(testval, base), base) ... Py Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree.findtext()
[me] print tree.findtext(html/head/title) None I realised what the problem was the second after I hit Send (why is it never the second *before*?) The tree represents the top-level html element, so of course searching within it for 'html' fails. What I should say is this: print tree.findtext(head/title) The title Sorry to waste people's time! -- Richie Hindle [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a tutorial
Xah == Xah Lee [EMAIL PROTECTED] writes: Xah at places often a whole paragraph on some so called computer Xah science jargons should be deleted. They are there more to Xah showcase inane technicality than do help the Xah reader. (related, many passages with jargons should be Xah rewritten sans inane jargon. e.g. mutable object.) The concept of mutable objects is extremely important in python, and understanding is the key to answering two recurring newbie questions * Why can't lists or dictionaries be keys to dictionaries? * Why does using a list as a default value for a keyword argument in a function definition often lead to unexpected results? So it is definitely appropriate material in a tutorial. As for jargon, it is hard to argue that object is inane jargon in python. In fact, the base class for new-styled classes is indeed object, and if you want to write one of these classes yourself, you need to do 'class MyClass(object)'. So object is not inane jargon in an object oriented programming language. You still with me? OK, now on to mutable. mutable means changeable, albeit it's a little more of an obscure word than changeable, but it does roll off the tongue a bit more easily. Perhaps 'changeable object' would be more accessible to some readers, but it doesn't flow as well. So the python tutorial should perhaps define mutable when it introduces it. Which it does somewhat implicitly; the first time mutable is mentioned in the docs, in the context of strings Unlike strings, which are immutable, it is possible to change individual elements of a list: And now for my last musing on a new topic How to write a critique: It is much more constructive to suggest new text for documentation than to brand it inane. JDH -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter socket client ?
hi there , yeah - had a look at createfilehandler() - was a bit confusing - but your example helps ;) Thanks Tonino -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a tutorial
drewc [EMAIL PROTECTED] wrote: What does this have to do with Lisp? (i'm in c.l.l). he is a troll, but one who confess this fact: http://www.xahlee.org/Netiquette_dir/troll.html -- Frank Buß, [EMAIL PROTECTED] http://www.frank-buss.de, http://www.it4-systems.de -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on need help on generator...
Hi, I recently read David Mertz (IBM DeveloperWorks) about generators and got excited about using lazy constructs in my Python programming. But besides the fact that generators are either produced with the new yield reserved word or by defining the __new__ method in a class definition, I don't know much about them. In particular, I don't know what Python constructs does generate a generator. I know this is now the case for reading lines in a file or with the new iterator package. But what else ? Does Craig Ringer answer mean that list comprehensions are lazy ? Where can I find a comprehensive list of all the lazy constructions built in Python ? (I think that to easily distinguish lazy from strict constructs is an absolute programmer need -- otherwise you always end up wondering when is it that code is actually executed like in Haskell). Thank you Francis Girard FRANCE Le vendredi 21 Janvier 2005 15:38, Craig Ringer a crit: On Fri, 2005-01-21 at 17:14 +0300, Denis S. Otkidach wrote: On 21 Jan 2005 05:58:03 -0800 [EMAIL PROTECTED] (Joh) wrote: i'm trying to understand how i could build following consecutive sets from a root one using generator : l = [1,2,3,4] would like to produce : [1,2], [2,3], [3,4], [1,2,3], [2,3,4] def consecutive_sets(l): ... for i in xrange(2, len(l)): ... for j in xrange(0, len(l)-i+1): ... yield l[j:j+i] Since you have a much faster brain than I (though I ended up with exactly the same thing barring variable names) and beat me to posting the answer, I'll post the inevitable awful generator expression version instead: consecutive_sets = ( x[offset:offset+subset_size] for subset_size in xrange(2, len(x)) for offset in xrange(0, len(x) + 1 - subset_size) ) -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on generator...
On Fri, 2005-01-21 at 22:38 +0800, Craig Ringer wrote: consecutive_sets = ( x[offset:offset+subset_size] for subset_size in xrange(2, len(x)) for offset in xrange(0, len(x) + 1 - subset_size) ) Where 'x' is list to operate on, as I should've initially noted. Sorry for the reply-to-self. I did say awful for a reason ;-) -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
wx.BoxSizer problem
Hi All, Here is the code of a frame: import wx class PanelDatabaseDefinition(wx.Panel): def __init__(self,parent): wx.Panel.__init__(self,parent) self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) self.sizer.Add(wx.Button(self,label=test1),flag=wx.EXPAND,proportion=1) self.sizer.Add(wx.Button(self,label=test2),flag=wx.EXPAND,proportion=1) class FrameDatabaseDefinition(wx.Frame): def __init__(self,parent,title): wx.Frame.__init__(self,parent,title=title) self.panel = PanelDatabaseDefinition(self) self.sizer = wx.BoxSizer(wx.VERTICAL) self.SetSizer(self.sizer) self.sizer.Add(self.panel,flag=wx.EXPAND,proportion=1) self.Layout() I would like to use the panel PanelDatabaseDefinition on the frame FrameDatabaseDefinition, but I should also be able to use the panel on other frames. (A la Delphi frames.) My problem is that only one of the buttons is visible and that one is not expanded. (System: Windows, Python 2.3.4, wxPython 2.5.3) Best, Laci -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic properties
michael wrote: My first try is : fget = lambda self: mygetattr(self, attrname) fset = lambda self, value: mysetattr (self, attrname, value) fdel = lambda self: mydelattr(self, attrname) # fget, fset, fdel are used to reconstruct the byte field setattr (self, key, property (fget, fset, fdel)) setattr creates entries in the instance dictionary of the object that is passed in. Properties need to be stored in the object type's dictionary in order to work their magic. I also believe it is required that the class be a new-style class. So try something like (Python 2.4): Py def mygetattr(self, attr): ... print Getting %s from %s % (str(attr), str(self)) ... Py def mysetattr(self, attr, value): ... print Setting %s to %s on %s % (str(attr), str(value), str(self)) ... Py def mydelattr(self, attr): ... print Deleting %s from %s % (str(attr), str(self)) ... Py class C(object): ... @classmethod ... def make_properties(cls, attrs): ... for attr in attrs: ... # Use default arguments to bind attr *now*, not at call time ... def _get(self, attr=attr): ... return mygetattr(self, attr) ... def _set(self, value, attr=attr): ... mysetattr(self, attr, value) ... def _del(self, attr=attr): ... mydelattr(self, attr) ... setattr(cls, attr, property(_get, _set, _del)) ... Py properties = [x, y] Py C.make_properties(properties) Py C.x property object at 0x00A9D3F0 Py c = C() Py c.x Getting x from __main__.C object at 0x00A9A990 Py c.x = 1 Setting x to 1 on __main__.C object at 0x00A9A990 Py del c.x Deleting x from __main__.C object at 0x00A9A990 Py c.y Getting y from __main__.C object at 0x00A9A990 Py c.y = 1 Setting y to 1 on __main__.C object at 0x00A9A990 Py del c.y Deleting y from __main__.C object at 0x00A9A990 The decorator syntax is the only 2.4'ism I'm aware of in that code, so porting to 2.3 or even 2.2 shouldn't be an issue. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: PyCon Preliminary Program Announced!
[A.M. Kuchling] Suggestions for improvement are welcome. Perhaps the Wiki version of the schedule, at http://www.python.org/moin/PyConDC2005/Schedule, may be better. It is, but the 2004 schedule was really what I had in mind (very readable!): http://www.python.org/pycon/dc2004/schedule.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph and Table implementation
Jan Rienyer Gadil [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] could anyone please help me! what and how is the best implementation of creating a table based on data coming from the serial port ? and also how would i be able to create graphs (2D) based on these data? opinions and suggestion are most highly welcome. thanks. If you want to use existing tools, it is hard to beat a spreadsheet with a scatter plot graph object. If you are on the Microsoft side of the fence, Excel is perfect for this. There is an easy to use MSCOMM32.OCX object to control the serial port. This reduces your problem to moving the serial port data to an [x,y] column that is attached to a scatter plot. This is easy to do with Excel's built in VBA so I assume it would also be easy to do with Python, given that you can use Python to manipulate the Excel object model . On the Linux/Unix side. Gnumeric seems to serve very well although I don't yet have sufficient personal experience with it to know about the gotcha's you might encounter. I am also guessing that the Open Office spreadsheet would work too. Thomas Bartkus -- http://mail.python.org/mailman/listinfo/python-list
ANN: P4Python 0.5 - Interface to Perforce
Have just released this to PyPI. http://www.python.org/pypi?:action=displayname=P4Pythonversion=0.5 Name: P4Python Version: 0.5 Author: Robert Cowham Author email: robert at vaccaperna co uk Home page: http://public.perforce.com/guest/robert_cowham/perforce/API/python/index .html Download URL: UNKNOWN Summary: P4Python - Python interface to Perforce API License: http://public.perforce.com/guest/robert_cowham/perforce/API/python/main/ LICENSE.txt Description: Perforce is the fast SCM system at www.perforce.com. This package provides a simple interface from Python wrapping the Perforce C++ API to gain performance and ease of coding. Similar to interfaces available for Ruby and Perl. Platform: UNKNOWN Classifiers: Development Status :: 4 - Beta Intended Audience :: Developers License :: Freely Distributable Operating System :: Microsoft :: Windows Operating System :: Unix Programming Language :: Python Topic :: Software Development Topic :: Software Development :: Libraries :: Python Modules Topic :: Software Development :: Version Control Topic :: Utilities Currently at 0.5 because haven't had too many people using it yet, but it seems fine on my projects! -- Robert Cowham -- http://mail.python.org/mailman/listinfo/python-list
Configuring Python for Tk on Mac
On my desk here at work I have a Mac G4 running Mac OS X v10.2.8. When I go into a terminal and type python up comes a nice python interface and all seems great. However when I type import Tkinter I'm greeted by the following error. import Tkinter Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.2/lib-tk/Tkinter.py, line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter So I guess something about this implementation is not appropriately configured. I'm guessing this is the default behaviour since I don't think anyone did anything special about python when they set up my machine. What do I do to set it up so I can use Tkinter? Thanks... and sorry if this is an FAQ... but I couldn't find the info easily. Yours, Martyn -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on need help on generator...
On Fri, 2005-01-21 at 16:05 +0100, Francis Girard wrote: I recently read David Mertz (IBM DeveloperWorks) about generators and got excited about using lazy constructs in my Python programming. Speaking of totally great articles, and indirectly to lazyness (though not lazyily evaluated constructs), I was really impressed by this fantastic article on metaclasses: http://gnosis.cx/publish/programming/metaclass_1.html http://gnosis.cx/publish/programming/metaclass_2.html which shows that they're really just not that hard. That saved me an IMMENSE amount of utterly tedious coding just recently. But besides the fact that generators are either produced with the new yield reserved word or by defining the __new__ method in a class definition, I don't know much about them. They can also be created with a generator expression under Python 2.4. A generator expression works much like a list comprehension, but returns a generator instead of a list, and is evaluated lazily. (It also doesn't pollute the outside namespace with its working variables). print [ x for x in range(1,10)] [1, 2, 3, 4, 5, 6, 7, 8, 9] print ( x for x in xrange(1,10) ) generator object at 0x401e40ac print list(( x for x in xrange(1,10) )) [1, 2, 3, 4, 5, 6, 7, 8, 9] Not the use of xrange above for efficiency in the generator expressions. These examples are trivial and pointless, but hopefully get the point across. In particular, I don't know what Python constructs does generate a generator. As far as I know, functions that use yield, and generator expressions. I was unaware of the ability to create them using a class with a __new__ method, and need to check that out - I can imagine situations in which it might be rather handy. I'm not sure how many Python built-in functions and library modules return generators for things. I know this is now the case for reading lines in a file or with the new iterator package. But what else ? Does Craig Ringer answer mean that list comprehensions are lazy ? Nope, but generator expressions are, and they're pretty similar. Where can I find a comprehensive list of all the lazy constructions built in Python ? (I think that to easily distinguish lazy from strict constructs is an absolute programmer need -- otherwise you always end up wondering when is it that code is actually executed like in Haskell). I'm afraid I can't help you with that. I tend to take the view that side effects in lazily executed code are a bad plan, and use lazy execution for things where there is no reason to care when the code is executed. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
Tarfile module error
Hello, I'm using Python to automate admin tasks on my job. We use Windoze 2000 as desktop platform. When executing this daily backup scripts I get the following error: Traceback (most recent call last): File C:\UTILS\backup.py, line 8, in ? TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2') File C:\Python23\lib\tarfile.py, line 875, in open return func(name, filemode, fileobj) File C:\Python23\lib\tarfile.py, line 980, in bz2open raise ReadError, not a bzip2 file tarfile.ReadError: not a bzip2 file Here's the code: import tarfile from datetime import datetime DirBackup = r'\\skpdc01\Backups' DirOrig = r'C:\WUTemp' NewBackupFilename = DirBackup + '\\' + '%s' % (datetime.today()) + '.tar.bz2' TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2') TarFileBackup.add(DirOrig) TarFileBackup.close() What am I doing wrong? From the error message I gues the library is expecting the bzip file to exists, but I am explicitly open it whit 'w:bz2' Any ideas? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Python-enterprise (integration) SIG/mailinglist/etc.?
Hello, Python seems to be used quite a lot for (the integration of) enterprise applications. Just as an example, there are at least three (projects for the implementation of) ERP systems in Python: - GNUenterprise - ERP5 - TinyERP There are also a lot of different modules already available which supply useful functionalities for (the integration of) enterprise applications, such as PEAK, Twisted, OmniORBpy, Modeling, etc... However, what seems to be missing is some kind of coordination/communication resource and/or (link) repository for such modules, so that one can find out easily what exists already, whether it fits one's requirements and if not, where to find other people who would participate in the implementation of what's missing. So, here's the question: How about creating a Python-Enterprise(-Integration)-SIG/-mailinglist/whatever? Such a group could also start standardisation for such things as a Python Messaging System, a Python Component Model and maybe (reference) implementations could be included in the Python distribution some day (no I don't think it should be called PEE :-). TIA, Wolfgang Keller -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on generator...
Le vendredi 21 Janvier 2005 16:06, Craig Ringer a crit: On Fri, 2005-01-21 at 22:38 +0800, Craig Ringer wrote: consecutive_sets = ( x[offset:offset+subset_size] for subset_size in xrange(2, len(x)) for offset in xrange(0, len(x) + 1 - subset_size) ) Where 'x' is list to operate on, as I should've initially noted. Sorry for the reply-to-self. I did say awful for a reason ;-) -- Craig Ringer First, I think that you mean : consecutive_sets = [ x[offset:offset+subset_size] for subset_size in xrange(2, len(x)) for offset in xrange(0, len(x) + 1 - subset_size)] (with square brackets). Second, this is not lazy anymore (like Denis S. Otkidach previous answer was) because the __whole__ list get constructed __before__ any other piece of code have a chance to execute. The type of consecutive_sets is simply a list, not a generator. I'm just trying to understand and obviously I'm missing the point. Thank you Francis Girard FRANCE -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on need help on generator...
Really, thank you Craig Ringer for your great answer. I'm afraid I can't help you with that. I tend to take the view that side effects in lazily executed code are a bad plan, and use lazy execution for things where there is no reason to care when the code is executed. I completly agree with this. But this is much more true in theory than in practice. In practice you might end up with big big memory usage with lazy constructs as the system has to store intermediate results (the execution context in the case of Python). These kinds of phenomena happen all the time in a language like Haskell -- at least for a beginner like me -- if you don't pay attention to it ; and this makes the language a lot more difficult to master. Thus you have to keep an eye on performance even though, in FP, you shoould just have to declare your intentions and let the system manage the execution path. http://gnosis.cx/publish/programming/metaclass_1.html http://gnosis.cx/publish/programming/metaclass_2.html Thank you, I'll read that. Francis Girard FRANCE Le vendredi 21 Janvier 2005 16:42, Craig Ringer a crit: On Fri, 2005-01-21 at 16:05 +0100, Francis Girard wrote: I recently read David Mertz (IBM DeveloperWorks) about generators and got excited about using lazy constructs in my Python programming. Speaking of totally great articles, and indirectly to lazyness (though not lazyily evaluated constructs), I was really impressed by this fantastic article on metaclasses: http://gnosis.cx/publish/programming/metaclass_1.html http://gnosis.cx/publish/programming/metaclass_2.html which shows that they're really just not that hard. That saved me an IMMENSE amount of utterly tedious coding just recently. But besides the fact that generators are either produced with the new yield reserved word or by defining the __new__ method in a class definition, I don't know much about them. They can also be created with a generator expression under Python 2.4. A generator expression works much like a list comprehension, but returns a generator instead of a list, and is evaluated lazily. (It also doesn't pollute the outside namespace with its working variables). print [ x for x in range(1,10)] [1, 2, 3, 4, 5, 6, 7, 8, 9] print ( x for x in xrange(1,10) ) generator object at 0x401e40ac print list(( x for x in xrange(1,10) )) [1, 2, 3, 4, 5, 6, 7, 8, 9] Not the use of xrange above for efficiency in the generator expressions. These examples are trivial and pointless, but hopefully get the point across. In particular, I don't know what Python constructs does generate a generator. As far as I know, functions that use yield, and generator expressions. I was unaware of the ability to create them using a class with a __new__ method, and need to check that out - I can imagine situations in which it might be rather handy. I'm not sure how many Python built-in functions and library modules return generators for things. I know this is now the case for reading lines in a file or with the new iterator package. But what else ? Does Craig Ringer answer mean that list comprehensions are lazy ? Nope, but generator expressions are, and they're pretty similar. Where can I find a comprehensive list of all the lazy constructions built in Python ? (I think that to easily distinguish lazy from strict constructs is an absolute programmer need -- otherwise you always end up wondering when is it that code is actually executed like in Haskell). I'm afraid I can't help you with that. I tend to take the view that side effects in lazily executed code are a bad plan, and use lazy execution for things where there is no reason to care when the code is executed. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on generator...
On Fri, 2005-01-21 at 16:54 +0100, Francis Girard wrote: First, I think that you mean : consecutive_sets = [ x[offset:offset+subset_size] for subset_size in xrange(2, len(x)) for offset in xrange(0, len(x) + 1 - subset_size)] (with square brackets). I'm just trying to understand and obviously I'm missing the point. Yep. This: ( x for x in xrange(10) ) will return a generator that calculates things as it goes, while this: [ x for x in xrange(10) ] will return a list. Check out: http://www.python.org/peps/pep-0289.html http://docs.python.org/whatsnew/node4.html http://www.python.org/dev/doc/newstyle/ref/genexpr.html for details. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a tutorial
Xah Lee wrote: i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Here are some quick critique: This has absolutely nothing to do with c.l.c, nor most of the cross-posted groups. F'ups set. Why did you do such a foul cross-posting in the first place. -- If you want to post a followup via groups.google.com, don't use the broken Reply link at the bottom of the article. Click on show options at the top of the article, then click on the Reply at the bottom of the article headers. - Keith Thompson -- http://mail.python.org/mailman/listinfo/python-list
circular iteration
hi, is there a faster way to build a circular iterator in python that by doing this: c=['r','g','b','c','m','y','k'] for i in range(30): print c[i%len(c)] thanks, Flávio -- http://mail.python.org/mailman/listinfo/python-list
Re: circular iteration
Flavio codeco coelho wrote: hi, is there a faster way to build a circular iterator in python that by doing this: c=['r','g','b','c','m','y','k'] for i in range(30): print c[i%len(c)] thanks, Flávio import itertools c=['r','g','b','c','m','y','k'] circ = itertools.cycle(c) for i in range(30): print circ.next(), r g b c m y k r g b c m y k r g b c m y k r g b c m y k r g -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with duplicating and slicing an array
Yun Mao wrote: Thanks for the help. numarray doesn't provide what I look for either. e.g. a = array( [[1,2,3],[4,5,6]] ) I sometimes what this: a[ [1,0], :], or even a[ [1,0], [0,1] ] , which should give me [[4, 5], [1,2]] I think Fortran 90 and 95 have the array slicing you want. For example, if imat = 111213 212223 then imat([2,1,2],:)) = 212223 111213 212223 and imat([2,1,2],[1,3]) = 2123 1113 2123 Like Matlab, Fortran arrays by default start with 1, and x(i:j) gives a slice of elements including x(j). There are free compilers g95 (in beta) and gfortran (in alpha). -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a tutorial
Xah Lee wrote: i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html What does this have to do with Perl, Lisp, Scheme, or C? -- MJF -- http://mail.python.org/mailman/listinfo/python-list
Re: circular iteration
On 21 Jan 2005 08:31:02 -0800, Flavio codeco coelho [EMAIL PROTECTED] wrote: hi, is there a faster way to build a circular iterator in python that by doing this: c=['r','g','b','c','m','y','k'] for i in range(30): print c[i%len(c)] I don''t know if it's faster, but: import itertools c=['r','g','b','c','m','y','k'] for i in itertools.islice(itertools.cycle(c), 30): ... print i -- Cheers, Simon B, [EMAIL PROTECTED], http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: need help on generator...
Thank you, I immediately download version 2.4, switching from version 2.3. Francis Girard FRANCE Le vendredi 21 Janvier 2005 17:34, Craig Ringer a crit: On Fri, 2005-01-21 at 16:54 +0100, Francis Girard wrote: First, I think that you mean : consecutive_sets = [ x[offset:offset+subset_size] for subset_size in xrange(2, len(x)) for offset in xrange(0, len(x) + 1 - subset_size)] (with square brackets). I'm just trying to understand and obviously I'm missing the point. Yep. This: ( x for x in xrange(10) ) will return a generator that calculates things as it goes, while this: [ x for x in xrange(10) ] will return a list. Check out: http://www.python.org/peps/pep-0289.html http://docs.python.org/whatsnew/node4.html http://www.python.org/dev/doc/newstyle/ref/genexpr.html for details. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
Re: Zen of Python
Steve The fact that a bright bunch like the Python developers didn't Steve realize that it would be sensible to have a local scope for the Steve list comprehension variable is a perfect demonstration of that Steve point. Actually, I seem to recall that the topic came up, but at the time the goal was that list comprehensions be semantically the same as for loops, so the fact that the loop variable survived to pollute the namespace was deemed okay. Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: ElementTree.findtext()
Richie I realised what the problem was the second after I hit Send (why Richie is it never the second *before*?) So you could enlighten those of us who didn't realize what the problem was, even ten seconds later than that... Richie The tree represents the top-level html element, so of course Richie searching within it for 'html' fails. Thanks... Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Funny Python error messages
Peter Hansen wrote: My first one (i'm learning, i'm learning) is TypeError: 'callable-iterator' object is not callable # it = iter(lambda:0, 0) # it() # TypeError: 'callable-iterator' object is not callable Given that the supposed humour depends on the *name* of the object, which is callable-iterator, I'd say it's probably not hard to come up with lots of funny error messages this way. note that will didn't name the type himself. someone callously thought it would be a cool idea to have a non-callable type called callable in python, rather than, say, call it iterator-that-dances-with-callables. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: circular iteration
Flavio codeco coelho wrote: is there a faster way to build a circular iterator in python that by doing this: c=['r','g','b','c','m','y','k'] for i in range(30): print c[i%len(c)] have you benchmarked this, and found it lacking, or are you just trying to optimize prematurely? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Zen of Python
Skip Montanaro wrote: Steve The fact that a bright bunch like the Python developers didn't Steve realize that it would be sensible to have a local scope for the Steve list comprehension variable is a perfect demonstration of that Steve point. Actually, I seem to recall that the topic came up, but at the time the goal was that list comprehensions be semantically the same as for loops, so the fact that the loop variable survived to pollute the namespace was deemed okay. Skip Thanks, Skip. I remember the discussions on python-dev, but I don't think that invalidates my point. I wasn't suggesting nobody realized there would be name-droppings, simply that nobody realized that a later goal of namespace purity would take priority over the initial one of for-loop compatibility. Similar issues surrounded nested scopes, if I remember, and even there the jury's still out. Which is why I accused Paul Rubin of requiring psychic powers from language developers when he said So once we can see where it's going, why not proceed to the finish line immediately instead of bothering with the intermediate steps? we-can't-always-see-where-we're-going-ly y'rs - steve -- Steve Holden http://www.holdenweb.com/ Python Web Programming http://pydish.holdenweb.com/ Holden Web LLC +1 703 861 4237 +1 800 494 3119 -- http://mail.python.org/mailman/listinfo/python-list
Re: Tarfile module error
Your NewBackupFilename contains : which is not a valid character in a filename in Windows. You could do something like this: NewBackupFilename = DirBackup + '\\' + '%s' % str(datetime.today()).replace(':', '-') + '.tar.bz2' NewBackupFilename 'c:skpdc01Backups\\2005-01-21 12-26-21.373000.tar.bz2' TarFileBackup = tarfile.open(NewBackupFilename, 'w:bz2') # Works! I changed your DirBackup to 'C:\skpdc01\Backups' Thanks, --Kartic -- http://mail.python.org/mailman/listinfo/python-list
Re: DevX: Processing EDI Documents into XML with Python
Claudio Grondi wrote: You don't have to rely on expensive and proprietary EDI conversion software to parse, validate, and translate EDI X12 data to and from XML; you can build your own translator with any modern programming language, such as Python. by Jeremy Jones http://www.devx.com/enterprise/Article/26854 Excerpt: Python is an object-oriented, byte-compiled language with a clean syntax, clear and consistent philosophy, and a strong user community. These attributes (both of the language and the community) make it possible to quickly write working, maintainable code, which in turn makes Python an excellent choice for nearly any programming task. Processing any flavor of EDI is no exception. Hi, just wanted to share with you, that the last issue of the DevX newsletter comes with a Python related article as first item in the list of subjects. Claudio Anyone interested in processing EDI with Python will probably be interested in giving it a read. Please feel free to scrutinize the code mercilessly. I plan on creating a project on Sourceforge with the code that is attached to that article (and hopefully with modifications coming from user input in the ensuing months). Comments are greatly appreciated. Thanks for posting this, Claudio. Jeremy Jones -- http://mail.python.org/mailman/listinfo/python-list
Re: wx.BoxSizer problem
On Jan 21, 2005, at 10:07 AM, Laszlo Zsolt Nagy wrote: My problem is that only one of the buttons is visible and that one is not expanded. (System: Windows, Python 2.3.4, wxPython 2.5.3) Works as expected on Mac OS X 10.3.7, python 2.3.4, wxPython 2.5.2.8. ___/ / __/ / / Ed Leafe http://leafe.com/ http://dabodev.com/ -- http://mail.python.org/mailman/listinfo/python-list
RE: Class introspection and dynamically determining function arguments
Diez B. Roggisch wrote: According to this http://www-106.ibm.com/developerworks/library/l-pyint.html not really - and there are no special moduls neccessary, as everything is at your hands using __dict__ and so on. Thanks for the link. I'd read that article but found it was too introductory (what is help, what is sys, etc.). It didn't even deal with inspect. As such, I didn't think it was definitive about Python's existing introspection code. This was much more the level of sophistication I was looking for, albeit aimed at (static) declared function syntax, rather than (dynamic) instance or class attributes: http://www.sff.net/people/neelk/open-source/Signature.py Also, I know the class __dict__ (which is actually a proxy object) may have class attributes currently, but that seems implementation dependent. At the moment it lists the attributes defined by *this* type, regardless of attributes defined in base types. Again, this happens to be what I want but I don't know that this behaviour is defined anywhere, and therefore it may be subject to change. It would be nice if I could ask a class if there are any attributes defined for it in tp_getset, although that's just a small step along the path of attribute discovery... (Apologies for interchangeable use of the words type/class) Nick Coghlan wrote Perhaps the simplest way is to require all such classes to have a getExample class method that produces a fully populated example instance Thanks Nick. This was the kind of approach I've ended up going with (sorta). Still hunting for ideas... --- The information contained in this e-mail is confidential and solely for the intended addressee(s). Unauthorised reproduction, disclosure, modification, and/or distribution of this email may be unlawful. If you have received this email in error, please notify the sender immediately and delete it from your system. The views expressed in this message do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary companies. --- -- http://mail.python.org/mailman/listinfo/python-list
Re: xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 ~From your experience, do you think that if this wrong XML code could be meant to be read only by somekind of Microsoft parser, the error will not occur? I'll try to explain: xml producer writes the code in Windows platform and 'thinks' that every client will read/parse the code with a specific Windows parser. Could that (wrong) XML code parse correctly in that kind of specific Windows client? Or in other words: Do you know any windows parser that could turn that erroneous encoding to a xml tree, with four or five inner levels of tags? I'd like to thank everyone for taking the time to answer me. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB8UIOHn4UHCY8rB8RAgK4AKCiHjPdkCKnirX4gEIawT9hBp3HmQCdGoFK 3IEMLLXwMZKvNoqA4tISVnI= =jvOU -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: xml parsing escape characters
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 ~From your experience, do you think that if this wrong XML code could be meant to be read only by somekind of Microsoft parser, the error will not occur? I'll try to explain: xml producer writes the code in Windows platform and 'thinks' that every client will read/parse the code with a specific Windows parser. Could that (wrong) XML code parse correctly in that kind of specific Windows client? Or in other words: Do you know any windows parser that could turn that erroneous encoding to a xml tree, with four or five inner levels of tags? I'd like to thank everyone for taking the time to answer me. Luis -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFB8UIOHn4UHCY8rB8RAgK4AKCiHjPdkCKnirX4gEIawT9hBp3HmQCdGoFK 3IEMLLXwMZKvNoqA4tISVnI= =jvOU -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Simple (newbie) regular expression question
Sorry for the simple question, but I find regular expressions rather intimidating. And I've never needed them before ... How would I go about to 'define' a regular expression that would identify strings like __alphanumerical__ as in __init__ (Just to spell things out, as I have seen underscores disappear from messages before, that's 2 underscores immediately followed by an alphanumerical string immediately followed by 2 underscore; in other words, a python 'private' method). Simple one-liner would be good. One-liner with explanation would be better. One-liner with explanation, and pointer to 'great tutorial' (for future reference) would probably be ideal. (I know, google is my friend for that last part. :-) Andre -- http://mail.python.org/mailman/listinfo/python-list
Re: What YAML engine do you use?
rm wrote: well, I did look at it, and as a text format is more readable than XML is. judging from http://yaml.org/spec/current.html (750k), the YAML designers are clearly insane. that's the most absurd software specification I've ever seen. they need help, not users. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Funny Python error messages
Peter Hansen wrote: Will Stuyvesant wrote: Perhaps this will even be a useful thread, to brighten the life of the brave people doing the hard work of providing us with error messages. My first one (i'm learning, i'm learning) is TypeError: 'callable-iterator' object is not callable # it = iter(lambda:0, 0) # it() # TypeError: 'callable-iterator' object is not callable Given that the supposed humour depends on the *name* of the object, which is callable-iterator, I'd say it's probably not hard to come up with lots of funny error messages this way. The mildly amusing nature of this error message is due to Will's finding a name, callable-iterator (where callable is a name, not a description), appearing in a different context from where it was coined that causes us to parse it differently (where callable is a description, not a name), and accidentally stating an absurdity. I'd say it's actually a nice bit of subtlety. -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list
why am I getting a segmentation fault?
I have a short multi-threaded script that checks web images to make sure they are still there. I get a segmentation fault everytime I run it and I can't figure out why. Writing threaded scripts is new to me so I may be doing something wrong that should be obvious :( google messes up the python code so here is a link to it. http://kracomp.com/~jay/py.txt This is the output of the script. [EMAIL PROTECTED] scripts]$ ./py.py update item set goodImage = 'yes' where productId='12603' update item set goodImage = 'yes' where productId='18272' update item set goodImage = 'yes' where productId='1927' update item set goodImage = 'no' where productId='12709' update item set goodImage = 'yes' where productId='32087' update item set goodImage = 'no' where productId='25803' Segmentation fault Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: What YAML engine do you use?
On Fri, 21 Jan 2005 18:30:47 +0100, rm [EMAIL PROTECTED] wrote: Nowadays, people are trying to create binary XML, XML databases, graphics in XML (btw, I'm quite impressed by SVG), you have XSLT, you have XSL-FO, ... . Which is an argument in favor of XML -- it's where the activity is, so it's quite likely you'll encounter the need to know XML. Few projects use YAML, so the chance of having to know its syntactic details is small. --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: xml parsing escape characters
Luis P. Mendes wrote: xml producer writes the code in Windows platform and 'thinks' that every client will read/parse the code with a specific Windows parser. Could that (wrong) XML code parse correctly in that kind of specific Windows client? not if it's an XML parser. Do you know any windows parser that could turn that erroneous encoding to a xml tree, with four or five inner levels of tags? any parser *can* do that, but I doubt many parsers will do it unless you ask it to (by extracting the string and parsing it again). here's the elementtree version: from elementtree.ElementTree import parse, XML wrapper = parse(urllib.urlopen(url)) dataset = XML(wrapper.findtext({http://www..}string;)) /F -- http://mail.python.org/mailman/listinfo/python-list
short programming projects for kids
I will be teaching an Introduction to Programming class to some middle school aged children and will be using Python, obviously. Does anyone have suggestions for simple little programs to create and analyze with them after I get past turtle graphics? Turtle graphics will be plenty for the first session, and I will leave time to ask them what they'd like to do in later sessions, but I was curious if anyone on the list has experience picking pedagogical programming examples appropriate for twelve-year-olds' attention spans. thanks, Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuring Python for Tk on Mac
I googled around and it looks like it might be a permissions error: http://mail.python.org/pipermail/pythonmac-sig/2002-November/006809.html I don't have a Mac, tho', so I have no idea if it works... HTH -- http://mail.python.org/mailman/listinfo/python-list
Re: Dynamic properties
On Fri, 21 Jan 2005 23:27:28 +0800, Craig Ringer wrote: The chances are that whatever you want to do with dynamically created properties is better done with __getattr__ and __setattr__ instead. Rather than post my own comment, I'd like to highlight this, emphasize it, and underline it twice. The two other repliers I see were nice to explain how to do what you were trying to do, but you probably shouldn't do it that way. class DictWrap(object): def __init__(self, dictToWrap): self.__dict__['dictToWrap'] = dictToWrap def __getattr__(self, key): return self.__dict__['dictToWrap'][key] def __setattr__(self, key, value): self.__dict__['dictToWrap'][key] = value def __delattr__(self, key): del self.__dict__['dictToWrap'][key] Note the direct use of __dict__, which bypasses the *attr machinery. This implements a full dict wrap; adjust as needed. Be sure to read about *attr in the Python manual so you understand what they do. You can do more in getattr if you want, but it doesn't sound like you want much else. Python 2.3.4 (#1, Oct 26 2004, 20:13:42) [GCC 3.4.2 (Gentoo Linux 3.4.2-r2, ssp-3.4.1-1, pie-8.7.6.5)] on linux2 Type help, copyright, credits or license for more information. class DictWrap(object): ... def __init__(self, dictToWrap): ... self.__dict__['dictToWrap'] = dictToWrap ... def __getattr__(self, key): ... return self.__dict__['dictToWrap'][key] ... def __setattr__(self, key, value): ... self.__dict__['dictToWrap'][key] = value ... def __delattr__(self, key): ... del self.__dict__['dictToWrap'][key] ... a = {'LV1': .5, 'LV10': 5, 'LV100': 50} d = DictWrap(a) d.LV1 0.5 d.LV1 = Hello! d.LV5 = 2.5 d.__dict__ {'dictToWrap': {'LV5': 2.5, 'LV10': 5, 'LV100': 50, 'LV1': 'Hello!'}} del d.LV100 d.__dict__ {'dictToWrap': {'LV5': 2.5, 'LV10': 5, 'LV1': 'Hello!'}} -- http://mail.python.org/mailman/listinfo/python-list
Re: how to write a tutorial
On Fri, 21 Jan 2005 03:08:50 -0800, Xah Lee wrote: i've started to read python tutorial recently. http://python.org/doc/2.3.4/tut/tut.html Here are some quick critique: You don't have the respect points for anyone to give a damn. Step one would be demonstrating that you understand the language enough to have a valid opinion, which we're all still waiting on. -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuring Python for Tk on Mac
On Fri, 2005-01-21 at 07:39 -0800, Martyn Quick wrote: On my desk here at work I have a Mac G4 running Mac OS X v10.2.8. When I go into a terminal and type python up comes a nice python interface and all seems great. However when I type import Tkinter I'm greeted by the following error. import Tkinter Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.2/lib-tk/Tkinter.py, line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter So I guess something about this implementation is not appropriately configured. In general, that error means that Python can't find the C extension module used to provide the low-level interface for Tkinter. It's not installed, can't be found (library path or python path issues), can't be opened (permissions), etc. Note the comment in the error message to that effect. I've just checked the OSX 10.3 machine here, and it fails to import tkinter there too. I'd say Apple just don't build Python with Tk support. What do I do to set it up so I can use Tkinter? Try Google - this seems to be a moderately FAQ for MacOS/X. -- Craig Ringer -- http://mail.python.org/mailman/listinfo/python-list
Re: Unbinding multiple variables
thanks everyone for the replies! John Hunter, yep, this is Johnny Lin in geosci :). re using return: the problem i have is somewhere in my code there's a memory leak. i realize return is supposed to unbind all the local variables, but since the memory leak is happening despite return, i thought it might help me track down the leak if i unbound everything explicitly that i had defined in local scope before i returned. or if anyone has recomm. on plugging leaks, would be thankful for any pointers there too. my understanding about locals() from the nutshell book was that i should treat that dictionary as read-only. is it safe to use it to delete entries? thanks again! -- http://mail.python.org/mailman/listinfo/python-list
Re: What YAML engine do you use?
On Fri, 21 Jan 2005 18:54:50 +0100, Fredrik Lundh [EMAIL PROTECTED] wrote: judging from http://yaml.org/spec/current.html (750k), the YAML designers are clearly insane. that's the most absurd software specification I've ever seen. they need help, not users. IMHO that's a bit extreme. Specifications are written to be detailed, so consequently they're torture to read. Seen the ReStructured Text spec lately? The basic idea -- a data dumping format that's human-readable -- isn't a bad one. OTOH, I can't recall wanting such a thing -- when I want readable output I'm happy using unreadable pickle files, unpickling the object and calling a .dump() or .as_text() method.) But YAML seems to have started out with the goal of being human-writable, something you would write in Emacs, and that seems to have gotten lost; the format is now just as complicated as Restructured Text, but more cryptic (the URI namespacing for tags, for example), not really simpler than XML and in some ways weaker (e.g. only two encodings supported, more complicated escaping rules). For a pure Python application, I can't see a need for YAML; use pickle/cPickle instead, because they're already there. Exchanging serialized objects between Python/Perl/Ruby scripts might be a good use case for YAML, but XML has wider software support and S-expressions are simpler, so my inclination would be to use them instead of YAML. --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: Funny Python error messages
Will Stuyvesant wrote: Add your funny or surprising Python error messages to this thread. A requirement is that you should also show (minimal) code that produces the message. Put the code below, so people can think about how to generate the message first, a little puzzle if you like. Perhaps this will even be a useful thread, to brighten the life of the brave people doing the hard work of providing us with error messages. I always liked: ValueError: insecure string pickle This error message is not strange if you think of insecure, string and pickle as programming terms, but it's hugely mystifying to someone who isn't a programmer, since all of these words have different meanings in real life. Some code to produce it: import cPickle x = cPickle.dumps([1,2,3,ratsj]) y = x[:18] + ? + x[18:] cPickle.loads(y) Traceback (most recent call last): File input, line 1, in ? ValueError: insecure string pickle -- Hans Nowak http://zephyrfalcon.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Print a string in binary format
Stephen Thorne wrote: On Fri, 21 Jan 2005 01:54:34 GMT, Kartic [EMAIL PROTECTED] wrote: Aha..I guess I posted too soon. You might want to take a look at this cookbook entry: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/219300 Defines lambdas to convert integer to binary. The one you probably want is - bstr = lambda n, l=16: n0 and binarystr((2Ll)+n) or n and bstr(n1).lstrip('0')+str(n1) or '0' bstr(ord('a')) '111' Death to inappropriate usage of lambda. First of all, that lambda is buggy, it doesn't work for negative numbers, but you can't immediately see that because of the compressed nature of the code. [snip how to write better code without lambdas] Your discussion here was nicely illustrative. You might consider adding something to the Overuse of Lambda discussion in: http://www.python.org/moin/DubiousPython Steve -- http://mail.python.org/mailman/listinfo/python-list
make install with python
Hi, I am writing a Python application and use the GNU auto-tools to compile what needs compilation (i.e. Qt's .ui files). However, I don't know how to write an automake file that installs the main file (lmc.py) and some library files (i.e. ClassA.py, ClassB.py) into the appropriate directories. Any tips there? Thanks Uwe -- http://mail.python.org/mailman/listinfo/python-list
Re: Zen of Python
[Paul Rubin] You snipped out the examples I gave, like [x*x for x in range(5)] leaving unnecessary residue in the name space. Was it not obvious from the beginning that that was a kludge? If it was obviously a kludge, was it not obvious that there would be reason to want to fix it someday? I'm saying that if some new feature is going to need a fix later, it's better to fix it before releasing it in the first place. [Steve Holden] Well no, I certainly have never thought the name droppings from list comprehensions to be anything other than a wart. But my parting shot was simply to point out that you don't always know where you're going until you're at least part of the way there. Until the feature exists, how do you know it needs fixing? The fact that a bright bunch like the Python developers didn't realize that it would be sensible to have a local scope for the list comprehension variable is a perfect demonstration of that point. Well, language design issues aren't really that mysterious. It was, for example, _always_ obvious that Scheme-heads would complain about the way listcomps got implemented (wrt the scope of the iteration vrbl). But at that time, Python didn't have lexical scoping, and it wasn't clear that it ever would. So what's the bigger wart? Making listcomps exactly equivalent to an easily-explained Python for-loop nest, or introducing a notion of lexical scope unique to listcomps, hard to explain in terms of the way the rest of the language worked? The former was thought to be the lesser evil at the time, and for truly obvious reasons. Except, perhaps, to those looking at Python as if it were a flawed approximation to some other language -- as Lispers and Schemers are notoriously prone to do, even wrt each others' favorite dialects. At the time, the right decision was made. -- http://mail.python.org/mailman/listinfo/python-list
Re: make install with python
Uwe Mayer wrote: Hi, I am writing a Python application and use the GNU auto-tools to compile what needs compilation (i.e. Qt's .ui files). However, I don't know how to write an automake file that installs the main file (lmc.py) and some library files (i.e. ClassA.py, ClassB.py) into the appropriate directories. The regular way is to use distutils and a setup.py file (google for documentation). Reinhold -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuring Python for Tk on Mac
Martyn Quick wrote: On my desk here at work I have a Mac G4 running Mac OS X v10.2.8. When I go into a terminal and type python up comes a nice python interface and all seems great. However when I type import Tkinter I'm greeted by the following error. import Tkinter Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.2/lib-tk/Tkinter.py, line 35, in ? import _tkinter # If this fails your Python may not be configured for Tk ImportError: No module named _tkinter So I guess something about this implementation is not appropriately configured. I'm guessing this is the default behaviour since I don't think anyone did anything special about python when they set up my machine. What do I do to set it up so I can use Tkinter? Thanks... and sorry if this is an FAQ... but I couldn't find the info easily. Yours, Martyn You probably need to install Tcl/Tk Aqua: http://tcltkaqua.sourceforge.net After downloading and installing on my Mac running OS X v 10.2, I am able to open IDLE and other Tk apps. HTH, Jim Sizelove -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple (newbie) regular expression question
André Roberge wrote: Sorry for the simple question, but I find regular expressions rather intimidating. And I've never needed them before ... How would I go about to 'define' a regular expression that would identify strings like __alphanumerical__ as in __init__ (Just to spell things out, as I have seen underscores disappear from messages before, that's 2 underscores immediately followed by an alphanumerical string immediately followed by 2 underscore; in other words, a python 'private' method). Simple one-liner would be good. One-liner with explanation would be better. One-liner with explanation, and pointer to 'great tutorial' (for future reference) would probably be ideal. (I know, google is my friend for that last part. :-) Andre Firstly, some corrections: (1) google is your friend for _all_ parts of your question (2) Python has an initial P and doesn't have private methods. Read this: pat1 = r'__[A-Za-z0-9_]*__' pat2 = r'__\w*__' import re tests = ['x', '__', '', '_', '__!__', '__a__', '__Z__', '__8__', '__xyzzy__', '__plugh'] [x for x in tests if re.search(pat1, x)] ['', '_', '__a__', '__Z__', '__8__', '__xyzzy__'] [x for x in tests if re.search(pat2, x)] ['', '_', '__a__', '__Z__', '__8__', '__xyzzy__'] I've interpreted your question as meaning valid Python identifier that starts and ends with two [implicitly, or more] underscores. In the two alternative patterns, the part in the middle says zero or more instances of a character that can appear in the middle of a Python identifier. The first pattern spells this out as capital letters, small letters, digits, and underscore. The second pattern uses the \w shorthand to give the same effect. You should be able to follow that from the Python documentation. Now, read this: http://www.amk.ca/python/howto/regex/ HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph and Table implementation
Jan == Jan Rienyer Gadil [EMAIL PROTECTED] writes: Jan could anyone please help me! what and how is the best Jan implementation of creating a table based on data coming from Jan the serial port ? and also how would i be able to create Jan graphs (2D) based on these data? Jan opinions and suggestion are most highly welcome. thanks. matplotlib can handle most kinds of 2D plots -- it even has a table command for including simple tabular data in your graph http://matplotlib.sourceforge.net/screenshots.html#table_demo so for heavy duty tables you'll probably want to use a GUI widget. JDH -- http://mail.python.org/mailman/listinfo/python-list
Re: Xah Lee's Unixism
Patrick, I maintain the web page that Rupert mentions in responce to your message about Nextstep and Mach. (http://www.macos.utah.edu/Documentation/MacOSXClasses/macosxone/unix.html) I'm curious to learn more about the development of Mach and its use in Nextstep. Can you point me to your sources -- preferably online so I can put them in the Bibliography section -- especially those that mention when Mach was turned into a Microkernel? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a library to parse Mozilla mork documents?
On Thu, 20 Jan 2005 23:48:34 -0800, Tim Roberts [EMAIL PROTECTED] wrote: John Reese [EMAIL PROTECTED] wrote: Mozilla, Firefox, Thunderbird, and so forth use this awful format called MORK to store all kinds of things: which messages you've read in a newsgroup, headers and indexes into the mbox file of messages in a mail folder, and address books. Yes. What a crock that is. The MORK format is a great way to compress tabular information, IF the information consists of the same pieces of data over and over. E-mail boxes do not fit into that class, so I have no doubt that the typical Thunderbird MORK file is singificantly LARGER than the same file would be in, say, INI format. I wrote a Python script to parse it, but it isn't terribly robust. I was able to produce a dictionary, but I didn't do anything with the results. You're welcome to take a look: http://www.probo.com/timr/parsemsf.py Thanks, I'll work with this. I have to say that this has all been worth it just to read about Jamie Zawinski railing against this file format. I think your comment at the top sums it up well: # Why am I doing this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple (newbie) regular expression question
John Machin wrote: André Roberge wrote: Sorry for the simple question, but I find regular expressions rather intimidating. And I've never needed them before ... How would I go about to 'define' a regular expression that would identify strings like __alphanumerical__ as in __init__ (Just to spell things out, as I have seen underscores disappear from messages before, that's 2 underscores immediately followed by an alphanumerical string immediately followed by 2 underscore; in other words, a python 'private' method). Simple one-liner would be good. One-liner with explanation would be better. One-liner with explanation, and pointer to 'great tutorial' (for future reference) would probably be ideal. (I know, google is my friend for that last part. :-) Andre Firstly, some corrections: (1) google is your friend for _all_ parts of your question (2) Python has an initial P and doesn't have private methods. Read this: pat1 = r'__[A-Za-z0-9_]*__' pat2 = r'__\w*__' import re tests = ['x', '__', '', '_', '__!__', '__a__', '__Z__', '__8__', '__xyzzy__', '__plugh'] [x for x in tests if re.search(pat1, x)] ['', '_', '__a__', '__Z__', '__8__', '__xyzzy__'] [x for x in tests if re.search(pat2, x)] ['', '_', '__a__', '__Z__', '__8__', '__xyzzy__'] I've interpreted your question as meaning valid Python identifier that starts and ends with two [implicitly, or more] underscores. In the two alternative patterns, the part in the middle says zero or more instances of a character that can appear in the middle of a Python identifier. The first pattern spells this out as capital letters, small letters, digits, and underscore. The second pattern uses the \w shorthand to give the same effect. You should be able to follow that from the Python documentation. Now, read this: http://www.amk.ca/python/howto/regex/ HTH, John Thanks for it all. It does help! André -- http://mail.python.org/mailman/listinfo/python-list
Tuple size and memory allocation for embedded Python
Hi Folks, Python seems unstable, when allocating big memory. For example, the following C++ code creates a tuple of tuples: PyObject* arCoord = PyTuple_New(n); double d = 1.5; for(int i=0; in; i++) { PyObject* coord = PyTuple_New(2); PyTuple_SetItem(coord,0, PyFloat_FromDouble(d));//x PyTuple_SetItem(coord,1, PyFloat_FromDouble(d));//y PyTuple_SetItem(arCoord,i, coord); } When the n is small, say 100, the code works fine. when n is big, say 10,000, Python has trouble allocating memory, saying: Exception exceptions.IndexError: 'tuple index out of range' in 'garbage collection' ignored Fatal Python error: unexpected exception during garbage collection Aborted Could anyone please give me some insight or a fix for this? Thanks in advance for your answer. Jinming Xu _ Is your PC infected? Get a FREE online computer virus scan from McAfee® Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- http://mail.python.org/mailman/listinfo/python-list
Python 2.4 on FreeBSD 5.3 and ncurses
Hello, I just installed a new FreeBSD 5.3-RELEASE System (Base System) and the first additional Packet I wanted to install was Python. While configuring I gon an error about (n)curses.h and was asked to report this to the Python list: configure: WARNING: ncurses.h: present but cannot be compiled configure: WARNING: ncurses.h: check for missing prerequisite headers? configure: WARNING: ncurses.h: see the Autoconf documentation configure: WARNING: ncurses.h: section Present But Cannot Be Compiled configure: WARNING: ncurses.h: proceeding with the preprocessor's result configure: WARNING: ncurses.h: in the future, the compiler will take precedence configure: WARNING: ## - ## configure: WARNING: ## Report this to the python lists. ## configure: WARNING: ## - ## If you need further Information please reply to poster - I'm not on the list. Max Dornseif The full config run: titan# (cd /usr/ports/lang/python ; make BATCH=YES package clean) === Vulnerability check disabled, database not found = Python-2.4.tgz doesn't seem to exist in /usr/ports/distfiles/python. = Attempting to fetch from http://www.python.org/ftp/python/2.4/. Python-2.4.tgz100% of 8982 kB 210 kBps 00m00s === Extracting for python-2.4 = Checksum OK for python/Python-2.4.tgz. /usr/bin/sed -e '1s,^.*$,#!/usr/local/bin/python2.4,' /usr/ports/lang/python/work/Python-2.4/Tools/scripts/pydoc /usr/ports/lang/python/work/pydoc2.4 /usr/bin/sed -e '1s,^.*$,#!/usr/local/bin/python2.4,' /usr/ports/lang/python/work/Python-2.4/Tools/scripts/idle /usr/ports/lang/python/work/idle2.4 /usr/bin/sed -e '1s,^.*$,#!/usr/local/bin/python2.4,' /usr/ports/lang/python/work/Python-2.4/Lib/smtpd.py /usr/ports/lang/python/work/smtpd2.4.py === Patching for python-2.4 /usr/bin/sed -i.bak -e 's,/usr/doc/python-docs-,/usr/local/share/doc/python,g' /usr/ports/lang/python/work/Python-2.4/Lib/pydoc.py /usr/bin/sed -i.bak -e 's|^\( *prefixes = .*\)\]$|\1, /usr/X11R6]|g' /usr/ports/lang/python/work/Python-2.4/Lib/site.py /bin/mkdir -p /usr/ports/lang/python/work/Python-2.4/Lib/plat-freebsd6 /bin/cp /usr/ports/lang/python/work/Python-2.4/Lib/plat-freebsd5/regen /usr/ports/lang/python/work/Python-2.4/Lib/plat-freebsd6/ === Applying FreeBSD patches for python-2.4 === Configuring for python-2.4 checking MACHDEP... freebsd5 checking EXTRAPLATDIR... checking for --without-gcc... no checking for --with-cxx=compiler... no checking for c++... c++ checking for C++ compiler default output file name... a.out checking whether the C++ compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for gcc... cc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ANSI C... none needed checking how to run the C preprocessor... cc -E checking for egrep... grep -E checking for AIX... no checking for --with-suffix... checking for case-insensitive build directory... no checking LIBRARY... libpython$(VERSION).a checking LINKCC... $(PURIFY) $(CXX) checking for --enable-shared... no checking for --enable-profiling... checking LDLIBRARY... libpython$(VERSION).a checking for ranlib... ranlib checking for ar... ar checking for a BSD-compatible install... /usr/bin/install -c -o root -g wheel checking for --with-pydebug... no checking whether cc accepts -fno-strict-aliasing... yes checking whether cc accepts -OPT:Olimit=0... no checking whether cc accepts -Olimit 1500... no checking whether pthreads are available without options... yes checking whether c++ also accepts flags for thread support... no checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking curses.h usability... no checking curses.h presence... yes configure: WARNING: curses.h: present but cannot be compiled configure: WARNING: curses.h: check for missing prerequisite headers? configure: WARNING: curses.h: see the Autoconf documentation configure: WARNING: curses.h: section Present But Cannot Be Compiled configure: WARNING: curses.h: proceeding with the preprocessor's result configure: WARNING: curses.h: in the future, the compiler will take precedence configure: WARNING: ## - ## configure: WARNING: ## Report this to the python lists. ## configure: WARNING: ## - ## checking for curses.h... yes checking
Re: why am I getting a segmentation fault?
Jay donnell [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have a short multi-threaded script that checks web images to make sure they are still there. I get a segmentation fault everytime I run it and I can't figure out why. Writing threaded scripts is new to me so I may be doing something wrong that should be obvious :( snip Here is a code excerpt from your link (the main routine, omits the class definition for ImageChecker, which extends threading.Thread): db = MySQLdb.connect(host=localhost, user=xxx, passwd=xxx, db=xxx) cursor = db.cursor() query = select * from item order by rand() limit 0, 100 #query = select * from item cursor.execute(query) result = cursor.fetchall() maxThreads = 5 for r in result: while(threading.activeCount() maxThreads): pass flag='good' #pass #print str(r[0]) + ', ' + str(r[7]) tmp = r[7].split('/') filename = tmp[-1] #print 'filename ' + filename filename = '/tmp/'+filename threadList = [] #r[7] is the url of the image #r[0] is the id for the row imageChecker = ImageChecker(r[7], filename, r[0]) imageChecker.start() threadList.append(imageChecker) -- 1. What happens after you fall out of the loop for r in result? Shouldn't you wait for the remaining threads to finish? Perhaps you need another busy-loop to wait for the threads to finish, something like while threading.activeCount() 0: pass 2. Is this the best way to busy-wait? What about some kind of thread.join()? At least throw a sleep call in there or something, or this loop will churn and churn, diverting CPU from your threads that are actually trying to do some real work. 3. I find it easier to work with named variables than numeric subscripts. At the top of your for loop, try something like: id,height,width,numBytes,whatever,slkdjf1,slkdjf2,url = r This way you have much more meaningful names than r[0] and r[7], which you later have to comment to explain whats going on! 4. filename=r[7].split('/')[-1] is not terribly portable. See if there is a standard module for parsing filespecs (I'll bet there is). -- Paul -- http://mail.python.org/mailman/listinfo/python-list