ANN: PLY-2.1 (Python Lex-Yacc)
October 2, 2006 Announcing : PLY-2.1 (Python Lex-Yacc) http://www.dabeaz.com/ply I'm pleased to announce a significant new update to PLY---a 100% Python implementation of the common parsing tools lex and yacc. PLY-2.1 builds upon the reimplementation of LALR(1) parsing that appeared in PLY-2.0 and adds a number of significant new features. These include: - Elimination of internal limitations due to the use of Python's re module. - Better support for inherited attributes and embedded parsing actions. - Character literals (e.g., '+', '-') can now be included in grammar specifications. - Improved packaging. PLY is now a proper Python package. - Improved support for line number and column tracking. - Added diagnostics. - New examples including a program to convert tradition yacc/bison specifications to PLY. - A variety of minor enhancements and bug fixes. If you are new to PLY, here are a few highlights: - PLY is closely modeled after traditional lex/yacc. If you know how to use these or similar tools in other languages, you will find PLY to be comparable. - PLY provides very extensive error reporting and diagnostic information to assist in parser construction. The original implementation was developed for instructional purposes. As a result, the system tries to identify the most common types of errors made by novice users. - PLY provides full support for empty productions, error recovery, precedence rules, and ambiguous grammars. - Parsing is based on LR-parsing which is fast, memory efficient, better suited to large grammars, and which has a number of nice properties when dealing with syntax errors and other parsing problems. Currently, PLY can build its parsing tables using either SLR or LALR(1) algorithms. - PLY can be used to build parsers for large programming languages. Although it is not ultra-fast due to its Python implementation, PLY can be used to parse grammars consisting of several hundred rules (as might be found for a language like C). The lexer and LR parser are also reasonably efficient when parsing normal sized programs. More information about PLY can be obtained on the PLY webpage at: http://www.dabeaz.com/ply PLY is freely available and is licensed under the terms of the Lesser GNU Public License (LGPL). Cheers, David Beazley (http://www.dabeaz.com) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: How to get keyboard event in Linux console?
Jia,Lu enlightened us with: I want to deal keyboard event in Linux console. Example: I Create a deamon at background and when I press F1 key then print Hello at Console. Type who and see which PTY you're connected to: sybren pts/02006-10-04 07:55 (klappie.stuvel.eu) So I'm connected to pts/0. If you read from /dev/pts/0, you'll see everything I type. Sybren -- Sybren Stüvel Stüvel IT - http://www.stuvel.eu/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Paul Rubin schrieb: Martin v. Löwis [EMAIL PROTECTED] writes: It is a fork of an old version. Existence of this version hasn't helped a bit when we tried to get our data out of sf.net. Yeah, I'd guessed it might be a fork. Is there stuff in sf.net that a web robot can't retrieve? We ended up getting the data with a web robot. There were two problems: 1. SF times out all the time, and fetching the data takes quite some time (not sure how long Fredrik Lundh needed, but I recall that Richard Jones once needed several days to get all data). There is also the theory that SF will lock out clients that fetch data at a too-high rate, so when you get locked out, you need to wait some time until you can continue; what rate is acceptable is not documented. 2. The web view gets HTML wrong in many places; things are rendered as HTML entity references when really the character should be displayed itself; non-ASCII characters don't work well. It might be that having the raw data would allow for better quality. There used to be another problem that SF was inconsistent on displaying user names (sometimes, account names were displayed, and sometimes real names), but that seems not to be a problem anymore. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: What kind of program is this
Dennis Lee Bieber wrote: ##aJAPy = %s %s %s % ('J' 'A' 'Py','','') # That should fail -- three format codes, and five output values No. 'JAPy' is a single string, oddly written: 'J' 'A' 'Py' 'JAPy' Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: understanding htmllib
David Bear wrote: I'm trying to understand how to use the HTMLParser in htmllib but I'm not seeing enough examples. I just want to grab the contents of everything enclosed in a 'body' tag, i.e. items from where body begins to where /body ends. I start by doing class HTMLBody(HTMLParser): def __init__(self): self.contents = [] def handle_starttag().. Now I'm stuck. I cant see that there is a method on handle_starttag that would return everthing to the end tag. And I haven't seen anything on how to define my one handle_unknowntag.. htmllib is designed to be used together with a formatting object. if you just want to work with tags, use sgmllib instead. some variation of the SGMLFilter example on this page might be what you need: http://effbot.org/librarybook/sgmllib.htm if you want a DOM-like structure instead of an event stream, use http://www.crummy.com/software/BeautifulSoup/ usage: import BeautifulSoup as BS soup = BS.BeautifulSoup(open(page.html)) str(soup.body) 'body\nh1Body Title/h1\npParagraph/p\n/body' soup.body.renderContents() '\nh1Body Title/h1\npParagraph/p\n' /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Compiling binaries
Henrique Nakashima wrote: Hi, I'm trying to find a way to compile .py files into linux binaries, so that i can distribute a program without having the user install python itself. Is there a way to do that? http://effbot.org/zone/python-compile.htm /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help with syntax on inheritance.
On 3 Oct 2006 19:09:53 -0700, SpreadTooThin [EMAIL PROTECTED] wrote: If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import array class myClass(arrary.array): def __init__(self, now here I need to put array's constructor parameters..., then mine): array.array.__init__(self, typecode[, initializer]) self.mine = mine So I'm confused... array has a typecode parameter and an optional initiializer... So could you help me with the class construction here please? If you need to take the same parameters as your super-class, and it includes optional positional parameters, then simply call with keywords to avoid the optional parameter: myClass(typecode, mine=something) It has less to do with defining the parameters than calling the function. -- http://mail.python.org/mailman/listinfo/python-list
Re: Roundup Issue Tracker release 1.1.3
Richard Jones wrote: I'm proud to release version 1.1.3 of Roundup. five database back-ends (anydbm, sqlite, metakit, mysql and postgresql). That ORM is pretty impressive: http://roundup.sourceforge.net/doc-1.0/design.html#roundup-database I like how easy it is to specify m-to-n relations. Is it possible to have a table with a multi-column primary key? -- http://mail.python.org/mailman/listinfo/python-list
Re: switching to numpy and failing, a user story
[EMAIL PROTECTED] wrote: After using numeric for almost ten years, I decided to attempt to switch a large codebase (python and C++) to using numpy. Here's are some comments about how that went. - The code to automatically switch python stuff over just kind of works. But it was a 90% solution, I could do the rest by hand. Of course, the problem is that then the code is still using the old numeric API, so it's not a long term solution. Unfortunately, to switch to the numpy API one needs documentation, which is a problem; see below. I'm glad to hear of your experiences (good and bad). We need feedback exactly from users like you in order to improve things. Yep, the code converter is a 80% solution, but it does work. Improvements are always welcome. - Well, ok, the automatic switching code doesn't really work all that well... my uses of RandomArray still work, but they generate different numbers. The underlying random-number generator must have changed. I'm sure that it's better now, but it's different. This is a major pain for my regression tests that rely on seeding the random number generator and getting particular results. But that's ok, I can update the regressions for the new RNG. You definitely can't expect the same random number generator. The new one (thanks to Robert Kern) is quite good. - My extension modules just won't build because the new numpy stuff lives in a different location from where Numeric used to live. This is an easy one and is documented in lots of places on the new http://www.scipy.org site. Plus, people are always willing to help out if you just ask. The numpy-discussion list is quite active. Don't be shy. - I guess I should just buy the documentation. I don't like this idea, because I think it's counter-productive to the project to have payware docs (would Python be successful if you had to buy the documentation? I don't think so), but that's the way this project goes. It's probably better to call it complete documentation. Normal open-source documentation is available from http://www.scipy.org. There are lots of people who have helped it. I had to do something to at least pretend to justify the time NumPy took me to the people who care about how I spend my time (including my family). This was the best I could come up with. I'm doubly unhappy about it because they payment system is using Paypal and I don't like Paypal at all, but I guess that's just the way it goes. Oh, wait, I *can't* buy the docs because I'm not in the US and the payment page requires a US address. Is that really true? A lot of people not living in the U.S. have used Paypal successfully. When difficulties arise, communicating with me your difficulty is usually productive. I give up; I guess NumPy is only for people living in the US. Definitely not true. People in Singapore, Japan, Ghana, South Africa, France, Germany, New Zealand, Australia, and many other countries are using NumPy successfully. Gratefully, a few have contributed by buying the book, but a lot more have downloaded and are successfully using it. I'm sorry about your experience, you definitely don't *have* to buy the book to use NumPy. Just like you don't *have* to buy any Python book to use Python. The amount of documentation for NumPy is growing and I expect that trend to continue. There is a lot of information in the source file. I guess I'll come back to NumPy in 2010, when the docs are available. Or just ask on the mailing lists, use the numpy.oldnumeric interface (the differences are all documented in the first few pages of my book which is available for free now). Thanks, -Travis -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Martin v. Löwis wrote: I hope this recommendation from the PSF infrastructure committee is rejected. That is very very unlikely. Who would reject it, and why? The community, and I am impressed you do not want to understand the why. It is an extremely bad picture for an open source flag like Python to go to a vendor for such an easy requirement as a bug database. I am seriously concerned that the PSF infrastructure committee EVER considered non open-source applications for this. In fact, I thought that was an implicit requirement in the selection. There are many open source applications around. They might not be the best, but at least they are yours, and not of some third party software vendors with its own interests. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Fredrik Lundh wrote: that's just not true. lots of people have voiced concerns over using closed-sourced stuff originally designed for enterprise-level Java users for an application domain where Python has several widely used agile alternatives to chose from. Frankly, I don't give a damn about the language the application is coded in, as long as it is OUR application and not an application of a private company which we do not own. Even though you are totally right. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
[EMAIL PROTECTED] wrote: Giovanni Bajo wrote: Does this smell Bitkeeper fiasco to anyone else than me? I can't understand why people waste time arguing this stuff. Use whatever tool is best at it's job... if it's not written in Python it doesn't mean that Python is not good for the task, only that there hasn't been any Python programmer that applied himself to the problem hard enough. This is not against using a tool not written in Java. This is against using a tool which is not FLOSS. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
A.M. Kuchling wrote: ... using a non open source tracker (called JIRA - never heard before of course) for Python itself. Other projects do use it; see http://wiki.apache.org/general/ApacheJira for a partial list, and a link to the Apache Software Foundation's issue trackers. which, in my humble opinion, is just a list of other examples of projects which are misguided. People seem to have no idea when a company is sold, when a CEO is changed, or something like that. Hhistory's repeating, but hackers are not learning. Does this smell Bitkeeper fiasco to anyone else than me? The committee did expect this recommendation to be controversial. :) I guess :) In fact, I have a deepest hope that this recommendation was just a fake just to get people setup a roundup installation... -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Martin v. Löwis wrote: It's significantly different from the Bitkeeper fiasco in two important ways: 1. Bitkeeper is a source revisioning system, so it is similar to CVS and Subversion. This project here is just the bug tracker, which is of lesser importance. If we move to a different one some day, a certain amount of data lossage might be acceptable (e.g. we now likely lose the history of status changes and file attachments on each report). An export of all data is high on the requirements list, as Fredrik points out. I understand your point. OTOH, exactly because the tracker system is a far lesser importance, it's amazing there is *ever* a need to evaluate non-FLOSS solutions, when there are so many good free solutions around. Instead of recommending a closed source solution, you could have recommended Roundup *and* explained there is a need for funding and/or volunteers before the migration can happen. You might also be understimating how negative could be the reaction from the open-source community to such a move. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
Hi ! Thanks Jeremy. I am in the process of converting my stuff to use sets! I wouldn't have thought it would have made that big a deal! I guess it is live and learn. If you have simplified records with big amount of data, you can trying dbhash. With this you don't get out from memory... dd import dbhash import time import random import gc import sys itemcount = 25 db = dbhash.open('test.dbh','w') for i in range(itemcount): db[str(i)] = str(i) littlelist = [] littleset = set() while len(littlelist) 1000: x = str(random.randint(0, itemcount-1)) if not (x in littlelist): littlelist.append(x) littleset.add(x) def DBHash(): gc.collect() hk = db.has_key st = time.time() newlist = [] for val in littlelist: if hk(val): newlist.append(val) et = time.time() print Size, len(newlist) newlist.sort() print Hash, hash(str(newlist)) print Time, %04f%(et-st) print def Set(): gc.collect() largeset = set() for i in range(itemcount): largeset.add(str(i)) st = time.time() newset = largeset.intersection(littleset) newsetlist = [] while newset: newsetlist.append(newset.pop()) et = time.time() print Size, len(newsetlist) newsetlist.sort() print Hash, hash(str(newsetlist)) print Time, %04f%(et-st) DBHash() Set() -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-03, LaundroMat [EMAIL PROTECTED] wrote: Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to pass a value to f()? None doesn't seem to work.. Thanks in advance. One possible way to do what I think you want is to code as follows: class Default (object): pass def f(var=Default): if var is Default: var = 1 return var * 2 -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: What kind of program is this
John Smith wrote: what kind of program is this? http://en.wikipedia.org/wiki/JAPH /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Roundup Issue Tracker release 1.1.3
[EMAIL PROTECTED] wrote: Richard Jones wrote: I'm proud to release version 1.1.3 of Roundup. five database back-ends (anydbm, sqlite, metakit, mysql and postgresql). That ORM is pretty impressive: http://roundup.sourceforge.net/doc-1.0/design.html#roundup-database [snip] Is it possible to have a table with a multi-column primary key? No, it's not designed for that level of complexity. Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
Rob De Almeida wrote: LaundroMat wrote: Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to pass a value to f()? None doesn't seem to work.. If you *absolutely* want to pass a value and you don't know the default value (otherwise you could just pass it): import inspect v = inspect.getargspec(f)[3][0] # first default value f(v) 2 I have in fact a bunch of functions that all pass similar information to one main function. That function takes (amongst others) a template variable. If it's not being passed, it is set to a default value by the function called upon. For the moment, whenever a function calls the main function, I check whether the calling function has the template variable set: if template: return mainFunction(var, template) else: return mainFunction(var) Now, I thought this isn't the cleanest way to do things; so I was looking for ways to initialize the template variable, so that I could always return mainFunction(var, template). mainFunction() would then assign the default value to template. From your answers, this seems to be impossible. The minute my variable is initialised, there's no way I can have mainFunction() assign a value without explicitly asking it to do so. I guess the best way would then be to change mainFunction from: def mainFunction(var, template='base'): to def mainFunction(var, template): if len(template)=0: template = 'base' and have the calling functions call mainFunction (var, template) and initialise template to ''. I still have that nagging feeling nicer code could be written to solve this, but I won't try to lose any sleep over it. Thanks for all the replies. -- http://mail.python.org/mailman/listinfo/python-list
hex sending
s.send(abc) # send test string I need to send hex:10 06 00 0f 02 bc d1 instead of abc hoW? -- http://mail.python.org/mailman/listinfo/python-list
Re: Need help with syntax on inheritance.
SpreadTooThin wrote: If you are deriving a new class from another class, that you must (I assume) know the initializer of the other class. So in myClass import array class myClass(arrary.array): def __init__(self, now here I need to put array's constructor parameters..., then mine): array.array.__init__(self, typecode[, initializer]) self.mine = mine So I'm confused... array has a typecode parameter and an optional initiializer... So could you help me with the class construction here please? Normally you would do # won't work class Array(array.array): def __init__(self, typecode, initalizer=(), mine=None): array.array.__init__(self, typecode, initializer) self.mine = mine However, array.array is a bit harder to subclass: # should work class Array(array.array): def __new__(cls, typecode, initializer=(), mine=None): return array.array.__new__(cls, typecode, initializer) def __init__(self, typecode, initializer=(), mine=None): array.array.__init__(self, typecode, initializer) self.mine = mine See if you can get away by making the array an attribute of your class instead. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: was python implemented as a object oriented langage at the beginning ?
has wrote: Python's type/class distinction Which type/class distinction ? -- bruno desthuilliers python -c print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')]) -- http://mail.python.org/mailman/listinfo/python-list
Re: hex sending
hiroc wrote: s.send(abc) # send test string I need to send hex:10 06 00 0f 02 bc d1 instead of abc do you want to send seven binary bytes, or pairs of hexadecimal characters separated by whitespace ? how do you map from abc to 10 06 00 0f 02 bc d1, by the way? what encoding is that? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: hex sending
I want send pairs of hexadecimal characters, abc is only my test hex char is real Fredrik Lundh wrote: hiroc wrote: s.send(abc) # send test string I need to send hex:10 06 00 0f 02 bc d1 instead of abc do you want to send seven binary bytes, or pairs of hexadecimal characters separated by whitespace ? how do you map from abc to 10 06 00 0f 02 bc d1, by the way? what encoding is that? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: can't open chm files all of a sudden
John Salerno wrote: John Salerno wrote: Hi all. I apologize since this is only remotely Python related, but I hope someone might now the solution. I tried opening my Python chm docs just now, as well as the one for wxPython, and both are giving me an error dialog when I double-click them and I can't open them. This happened apparently for no reason, just today. I even reset but that didn't help. Does anyone know what might cause this, Many things might cause an error dialogue -- further info needed. and if it could affect the rest of Python or wxPython as well? It could. Depends on what it is. Have you noticed any symptoms of other problems? P.S. Here is part of the error, but not the long detailed section: AppName: hh.exeAppVer: 5.2.3790.2453 ModName: itss.dll ModVer: 5.2.3790.2453 Offset: 6bec The same thing shows up for both files. 1. This is like telling us only the last source file name and line number in a Python traceback -- not very useful, especially w/o the source. Care to tell us what the text of the error message was? 2. Are these events resulting in a dump in your Dr Watson file (C:\Documents and Settings\All Users\Application Data\Microsoft\Dr Watson\drwtsn32.log)? Each dump starts with something like this: Application exception occurred: App: C:\Program Files\Hewlett-Packard\HP OfficeJet T Series\Bin\HPOstr05.exe (pid=2172) When: 2/09/2006 @ 05:35:58.515 Exception number: c005 (access violation) ... search for hh.exe 3. Have you been installing other software since this last worked? Fiddling with your path? 4. Have you done a full virus and spy-ware scan? Do you regularly install Windows updates from Microsoft? 5. C:\windows\help has many .chm files -- pick a couple at random; do you get the same problem with them? 6. Fire up a Comamnd Prompt window, and type this in: \windows\hh \python25\doc\python25.chm \windows\hh \windows\help\whatever.chm Any difference to the results from double-click launch method? ... I suspect that this is a narrowly focussed problem, probably a stuffed DLL or a DLL conflict. I tried profiling hh.exe opening c:\python25\doc\python25.chm with the dependency walker, and it visited a kazillion DLLs before it got to itss.dll and another kazillion after that till it stopped awaiting user input. If we don't get a clue from your answers to the above questions, it would probably be worth doing that on your machine. You could even do it yourself: google dependency walker and follow your nose :-) HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Python/Tkinter crash.
Hi, I get the following: [EMAIL PROTECTED]:~/Controller/lib python display.py UpdateStringProc should not be invoked for type font Aborted and I am back at the bash prompt - this is most frustrating, as there is no friendly traceback to help me guess where its coming from. And what is worse, the script runs for a varying time before it simply exits like this. What can I do to dig deeper to try to find a clue? - I don't even know if its Python, Tkinter or Linux... Some background: The application is a prototype gui for a controller of an injection moulding machine. It has two rows of five buttons across the top, and a canvas containing various objects over the rest of the screen. Extensive use is made of configure to change the text of the buttons, as well as their command bindings, to keep the state of the system current - its quite a hack at this time, as I am still experimenting with getting the interface intuitive. On the canvas, there are multiple instances of a Meter class to show things like temperatures and pressures, as well as a schematic representation of the machine, created out of polygons and lines. The schematic, as well as the Meters, are crudely animated by deleting and redrawing the objects repetitively with slightly different parameters in response to button presses. This is done by starting different threads to implement the various motions, which repetitively call kill and draw methods in the main app, after which they (the threads) commit seppoku by returning. Everything seems to work fine. - there is a thread that runs to move the meter values around continuously, and this has been stable for some time now, and I can get the various machine parts to move around the screen by pushing the buttons. The trouble occurs when I put the machine into Auto mode, simulating the various motions in a loop, - it runs for anything from a few tens to a few hundreds of cycles before handing in its dinner pail like this. Any Ideas on what to do next to find the culprit? - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
Maybe the application should use sets instead of lists for these collections. What would sets do for me over lists? searching for an element in a list is O(n) searching for an element in a set is O(1) (for reasonable distributed elements) Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
So are you saying that using a dict means a faster search since you only need to look up one value? I would think that you would have to look through the keys and stop at the first key that matches since each key has to be uniq, so perhaps if it is nearer the front of the set of keys then perhaps it would be a quicker lookup? On the other hand, if it is nearer the end of the set of keys would it not be slower? Does this make it more dependent on the search order whether a list or a dict is faster? Or am I completely on the wrong track? -h Hari Sekhon Fredrik Lundh wrote: Hari Sekhon wrote: That is surprising since I read on this list recently that lists were faster than dicts depends on what you're doing with them, of course. It was one reason that was cited as to why local vars are better than global vars. L[int] is indeed a bit faster than D[string] (but not much), but that doesn't mean that you can loop over *all* items in a list faster than you can look up a single key in a dictionary. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter to mpeg
[EMAIL PROTECTED] (Cameron Laird) writes: In article [EMAIL PROTECTED], Thomas Jollans [EMAIL PROTECTED] wrote: On Mon, 02 Oct 2006 09:18:13 -0700, dug [EMAIL PROTECTED] let this slip: I have a small program that moves some shapes around a tkinter canvas. Is there any way to save the output in a movie file, maybe mpeg? you can record any app with special programs designed for the job, such as vnc2swf (which produces macromedia flash), vncrec (which produces a special format readable by transcode) or istanbul (which produces ogg/theora). I doubt Tk would have a special mechanism to do this. . I've actually been thinking about implementing just such a special mechanism. Let me know if there's sufficient interest. I think it would be most helpful to have a general way to dump the contents of a Tkinter canvas including animated elements to some sort of file. However, I would think that mpeg will look pretty bad compared to SVG. In fact, as SVG renders much prettier (anti-aliasing etc.) than Tkinter, the exported file would look much better. I actually started coding SVG output for Gato (http://gato.sf.net). Some of the things I realized: - SVG support is somewhat limited on *nix. - The SMIL type animations are even less supported. One would have to resort to javascript. There is SmilScript which implements a SMIL subset for Firefox 2.0? - Due to a bug in the SVG 1.1 specification multi-colored lines with same color arrow-heads are difficult to draw. Supposedly, this will be fixed in 1.2. - The geometry works differently in SVG compared to Tk. Arrow heads are stuck onto the end of a line for example. It would be trivial to wrap the Tkinter canvas in an object which records what function is called when. For the basic canvas items mapping this to SVG is quite straightforward. Alexander PS: There is some python code to output SVG, which I didn't use since I wanted to work on my applications abstraction level. http://www2.sfk.nl/svg http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/325823 -- Alexander Schliep [EMAIL PROTECTED] http://algorithmics.molgen.mpg.de -- http://mail.python.org/mailman/listinfo/python-list
Re: hex sending
hiroc wrote: I want send pairs of hexadecimal characters, abc is only my test hex char is real Possibly this code helps to you: import binascii binascii.hexlify('hello worlds') Output: '68656c6c6f20776f726c6473' -- http://mail.python.org/mailman/listinfo/python-list
Re: python html rendering
Pierre, Hi, Im looking for a way to display some python code in html: with correct indentation, possibly syntax hiliting, dealing correctly with multi-line comment, tongue - in - cheek - mode the usual way is to create your own web-framework /tongue - in - cheek - mode If it is just some Python code and you have to do it once, just look at scite. Scite can colour your code, and you can export it as HTML. Harald -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
LaundroMat [EMAIL PROTECTED] writes: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to pass a value to f()? None doesn't seem to work.. I don't understand your question. You can call f(var=1) just fine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Best way to handle large lists?
Hari Sekhon wrote: So are you saying that using a dict means a faster search since you only need to look up one value? I would think that you would have to look through the keys and stop at the first key that matches since each key has to be uniq, so perhaps if it is nearer the front of the set of keys then perhaps it would be a quicker lookup? http://en.wikipedia.org/wiki/Hash_table /F -- http://mail.python.org/mailman/listinfo/python-list
Equal to Anything
For the purposes of a little test utility that we use, I need an object that evaluates as equal to anything. (I realise that this is a bad idea in some ways, breaking the equals/hashcode invariant and so forth, but I'm hoping that I can get away with it in this case.) It seems a simple enough task at first: class EqualAnything(object): ... def __eq__(self, other): ... return True ... spam = EqualAnything() spam == 1 True spam == hello! True spam == datetime.datetime.now() True 1 == spam True hello! == spam True But... datetime.datetime.now() == spam False I'm fairly sure that I know what is going on here - the left hand side object is getting first stab at the equality test, and understandably, it's saying Nah. But is there anything that I can do about it? -- Cheers, Simon B, [EMAIL PROTECTED] http://www.brunningonline.net/simon/blog/ -- http://mail.python.org/mailman/listinfo/python-list
Re: switching to numpy and failing, a user story
Travis E. Oliphant wrote: Definitely not true. People in Singapore, Japan, Ghana, South Africa, France, Germany, New Zealand, Australia, and many other countries are using NumPy successfully. Gratefully, a few have contributed by buying the book, but a lot more have downloaded and are successfully using it. From the PayPal site for purchasing your book: Select Payment Type: Don't have a PayPal account? You don't need an account. Pay securely using your credit card. I bought the book from Norway using my credit card, and received the pdf file soon afterwards. Obviously the book can be bought without a PayPal account or a us billing address. NumPy is the most versatile array type I have worked with, including those of Matlab and Fortran 95. In particular, the explosive memory use of Matlab is avoided. Keep up the good work! -- http://mail.python.org/mailman/listinfo/python-list
Re: What kind of program is this
Fredrik Lundh wrote: John Smith wrote: what kind of program is this? http://en.wikipedia.org/wiki/JAPH You computer guys crack me up! :D wildemar -- http://mail.python.org/mailman/listinfo/python-list
Re: What kind of program is this
Fredrik http://en.wikipedia.org/wiki/JAPH That's an interesting JAPH written with only punctuation... Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: And i dunno what the case against Trac is (it looks a fine tool for my small projects) but probably it's not good enough for python.org Trac is really good in my experience. http://trac.edgewall.org/ Python.org has already moved to svn so trac is surely the next part of the equation. Having an integrated Bugtracker / Wiki / Svn repository browser is very helpful. We use it for all our commercial work. It is also in use by MythTV which judging by the volume of its mailing lists is about or more active a project than python. http://svn.mythtv.org/trac/ A nice extra is that it is written in python. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Equal to Anything
Simon Brunning [EMAIL PROTECTED] wrote: I'm fairly sure that I know what is going on here - the left hand side object is getting first stab at the equality test, and understandably, it's saying Nah. But is there anything that I can do about it? Not in general, no. If you could, and someone else created a NotEqualAnything class with the identical definition to EqualAnything except it returns False, then which would win? Sorry, but the left hand value wins unless it volunteers otherwise. -- http://mail.python.org/mailman/listinfo/python-list
Re: python html rendering
Fredrik Lundh wrote: Pierre Imbaud wrote: I rather thought of some module built on python parser, generating html or xml, ideally customizable. see colorizer.py and element_colorizer.py in this directory: http://svn.effbot.python-hosting.com/stuff/sandbox/pythondoc /F +1 for colorizer.py (-1 for the american spelling ;-) ) it works a treat. examples here: http://www.gflanagan.net/site/python/utils/htmlbuilder/index.html maybe the HTML generator on this page might be useful to you (OP), and there's a quick py2html there as well. (Thanks Fredrik!) Gerard -- http://mail.python.org/mailman/listinfo/python-list
Getting Pygopherd to work under Mac OS X
Hello, Could someone *please* show us poor Mac users how to install and run Pygopherd successfully under Mac OS X? The latest version 2.0.4, as found at http://freshmeat.net/projects/pygopherd/ is my bane. I think I talked to John Goerzen, the maintainer, a while back but nothing came of it. I've tried this twice now, following the instructions given and have found nothing but grief and many errors. For a Python app it seems to be rather platform dependant! Does Pygopherd need to be altered somehow to work under OS X? If Pygopherd is a lost cause, can someone recommend another *maintained* gopher daemon with instructions that would allow its' use under OS X? -- mattabat [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: python html rendering
GHUM [EMAIL PROTECTED] wrote: Hi, Im looking for a way to display some python code in html: with correct indentation, possibly syntax hiliting, dealing correctly with multi-line comment, tongue - in - cheek - mode the usual way is to create your own web-framework /tongue - in - cheek - mode Or you could use an existing web framework: Plone has the ability to colour python code built-in. If it is just some Python code and you have to do it once, just look at scite. Scite can colour your code, and you can export it as HTML. and if you need it more than once you can always find one of the existing chunks of colouring code and modify/reuse it. See Plone's PortalTransforms/transforms/python.py, or the MoinMoin code it was cribbed from. https://svn.plone.org/svn/archetypes/PortalTransforms/trunk/transforms/python.py -- http://mail.python.org/mailman/listinfo/python-list
Re: Manipulate PDFs
Cameron Laird wrote: URL: http://www.easysw.com/htmldoc/ . While we STRONGLY emphasize free software in our installations, HTMLDOC has worked out great for us. Easy Software has consistently provided good service. Well, HTMLDOC does appear to be available under the GPL, too: http://www.htmldoc.org/ Paul -- http://mail.python.org/mailman/listinfo/python-list
string: __iter__()?
Hello! Just for curiosity i'd like to know why strings don't support the iteration protocoll!? Is there some deeper reason for this? hasattr('SomeString', '__iter__') False In Python 2.5 it's actually simple to obtain one: myIter = (c for c in 'SomeString') myIter.next() 'S' Thanks for info! Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
mrquantum wrote: Just for curiosity i'd like to know why strings don't support the iteration protocoll!? really? iter(SomeString) works just fine for me. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: py2app console
Dave Opstad wrote: In article [EMAIL PROTECTED], James Stroud [EMAIL PROTECTED] wrote: Does anyone know of the most straightforward way to get rid of the intensely annoying console window that py2app feels so compelled to create? I include this code in my apps: if (sys.platform != win32) and hasattr(sys, 'frozen'): root.tk.call('console', 'hide') That hides the console in py2app applications. Dave Yes! Thank you! I just now have gotten a chance to try it. It works beautifully and simply. Again, many thanks for your help! James -- http://mail.python.org/mailman/listinfo/python-list
Re: python html rendering
Pierre Imbaud wrote: Hi, Im looking for a way to display some python code in html: with correct indentation, possibly syntax hiliting, dealing correctly with multi-line comment, and... generating valid html code if the python code itself deals with html (hence manipulates tag litterals. Thanks for your help! Take a look at Highlight [1], a program used successfully in the otherwise Python-based open source project ViewVC [2]. Messing around with IDEs (as others have suggested) just isn't necessary here. Paul [1] http://www.andre-simon.de/ [2] http://www.viewvc.org/ -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
mrquantum [EMAIL PROTECTED] writes: Just for curiosity i'd like to know why strings don't support the iteration protocoll!? Is there some deeper reason for this? hasattr('SomeString', '__iter__') False It is a little but odd. But at least in 2.3.4: Python 2.3.4 (#1, Feb 2 2005, 12:11:53) [GCC 3.4.2 20041017 (Red Hat 3.4.2-6.fc3)] on linux2 Type help, copyright, credits or license for more information. a = iter('hi there') a iterator object at 0xb7c7f8ec print [x for x in a] ['h', 'i', ' ', 't', 'h', 'e', 'r', 'e'] So it looks like the iter is still there, but comes from some older layer of the implementation. -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
Am Wed, 04 Oct 2006 12:03:41 +0200 schrieb Fredrik Lundh: really? iter(SomeString) works just fine for me. Hmm, right! But then why doesn't dir('SomeString') show an __iter__ method? Seems to be implmented differently than with e.g. lists? Know why? -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
Antoon Pardon wrote: The problem is like the following. def f(var=1): return var*2 def g(): arg = None try: arg = Try_Processing() / 3 + 1 except Nothing_To_Process: pass if arg is None: return f() else: return f(arg) Now in this case you could start by assigning arg the value 1 and eliminate the if test. However that only works if you know the default value for the argument. What he seems to be asking for is if there is an object, (let as call it Default), that would make code like: def f(var=1): Equivallent to: def f(var=Default) if var is Default) var = 1 So that we could write the following without the need of the f's default value. def g(): arg = Default try: arg = Try_Processing() / 3 + 1 except Nothing_To_Process: pass f(arg) -- Antoon Pardon Exactly. Thanks for helping out. -- http://mail.python.org/mailman/listinfo/python-list
Improving telnetlib
Hi, I use telnetlib in an app I am writing, and would like to add functionality to it to support interactive terminal sessions , IE: be able to 'vi' a file. Currently it seems telnetlib isnt quite sophisticated enoguh to support such a thing. The trouble is, I havent got a clue where to start and would appreciate a couple of pointers to get me going... Thanks, Matt. This email is confidential and may be privileged. If you are not the intended recipient please notify the sender immediately and delete the email from your computer. You should not copy the email, use it for any purpose or disclose its contents to any other person. Please note that any views or opinions presented in this email may be personal to the author and do not necessarily represent the views or opinions of Digica. It is the responsibility of the recipient to check this email for the presence of viruses. Digica accepts no liability for any damage caused by any virus transmitted by this email. UK: Phoenix House, Colliers Way, Nottingham, NG8 6AT UK Reception Tel: + 44 (0) 115 977 1177 Support Centre: 0845 607 7070 Fax: + 44 (0) 115 977 7000 http://www.digica.com SOUTH AFRICA: Building 3, Parc du Cap, Mispel Road, Bellville, 7535, South Africa Tel: + 27 (0) 21 957 4900 Fax: + 27 (0) 21 948 3135 http://www.digica.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Nick Craig-Wood wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: And i dunno what the case against Trac is (it looks a fine tool for my small projects) but probably it's not good enough for python.org Trac is really good in my experience. Trac was considered. A nice extra is that it is written in python. So are Roundup and Launchpad, two of the other three trackers considered. Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
Antoon Pardon [EMAIL PROTECTED] writes: Now in this case you could start by assigning arg the value 1 and eliminate the if test. However that only works if you know the default value for the argument. What he seems to be asking for is if there is an object, (let as call it Default), that would make code like: def f(var=1): Equivallent to: def f(var=Default) if var is Default) var = 1 Oh, I see. Yes, the OP should just use a distinct default value instead of 1. I usually do this with sentinel = object() def f(var=sentinel): if var is sentinel: # f was called without an arg -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
mrquantum wrote: Am Wed, 04 Oct 2006 12:03:41 +0200 schrieb Fredrik Lundh: really? iter(SomeString) works just fine for me. But then why doesn't dir('SomeString') show an __iter__ method? Seems to be implmented differently than with e.g. lists? The older pre-__iter__() iteration style relying on __getitem__() still works: class A: ... def __getitem__(self, index): ... return [3,2,1][index] ... for item in A(): ... print item ... 3 2 1 Know why? No idea. Perhaps nobody cared? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-04, Paul Rubin http wrote: LaundroMat [EMAIL PROTECTED] writes: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to pass a value to f()? None doesn't seem to work.. I don't understand your question. You can call f(var=1) just fine. The problem is like the following. def f(var=1): return var*2 def g(): arg = None try: arg = Try_Processing() / 3 + 1 except Nothing_To_Process: pass if arg is None: return f() else: return f(arg) Now in this case you could start by assigning arg the value 1 and eliminate the if test. However that only works if you know the default value for the argument. What he seems to be asking for is if there is an object, (let as call it Default), that would make code like: def f(var=1): Equivallent to: def f(var=Default) if var is Default) var = 1 So that we could write the following without the need of the f's default value. def g(): arg = Default try: arg = Try_Processing() / 3 + 1 except Nothing_To_Process: pass f(arg) -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
LaundroMat [EMAIL PROTECTED] wrote: I have in fact a bunch of functions that all pass similar information to one main function. That function takes (amongst others) a template variable. If it's not being passed, it is set to a default value by the function called upon. For the moment, whenever a function calls the main function, I check whether the calling function has the template variable set: if template: return mainFunction(var, template) else: return mainFunction(var) Now, I thought this isn't the cleanest way to do things; so I was looking for ways to initialize the template variable, so that I could always return mainFunction(var, template). mainFunction() would then assign the default value to template. From your answers, this seems to be impossible. The minute my variable is initialised, there's no way I can have mainFunction() assign a value without explicitly asking it to do so. I guess the best way would then be to change mainFunction from: def mainFunction(var, template='base'): to def mainFunction(var, template): if len(template)=0: template = 'base' and have the calling functions call mainFunction (var, template) and initialise template to ''. None is the traditional value to use for value not present, then you'd get this for the function def mainFunction(var, template=None): if template is None: template = 'base' And this for the calling bit if not_set_properly(template): template = None return mainFunction(var, template) -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
Antoon Pardon [EMAIL PROTECTED] wrote: One possible way to do what I think you want is to code as follows: class Default (object): pass I'd have written Default = object() def f(var=Default): if var is Default: var = 1 return var * 2 But yes, defining a sentinel like this is a good idea. -- Nick Craig-Wood [EMAIL PROTECTED] -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
Am Wed, 04 Oct 2006 11:59:07 +0200 schrieb mrquantum: Hello! Just for curiosity i'd like to know why strings don't support the iteration protocoll!? Is there some deeper reason for this? Sorry, was to hasty by saying ... don't support the iteration protocol'! Sure they do, as the iter('SomeString') function or the construction for c in 'SomeString' show. It's just not implemented by a __iter__ method of the string in question! -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-04, Paul Rubin http wrote: Antoon Pardon [EMAIL PROTECTED] writes: Now in this case you could start by assigning arg the value 1 and eliminate the if test. However that only works if you know the default value for the argument. What he seems to be asking for is if there is an object, (let as call it Default), that would make code like: def f(var=1): Equivallent to: def f(var=Default) if var is Default) var = 1 Oh, I see. Yes, the OP should just use a distinct default value instead of 1. I usually do this with sentinel = object() def f(var=sentinel): if var is sentinel: # f was called without an arg But that can only work if you are the author of f. Take the following code: def myrepeat(obj, times = xxx): return itertools.repeat(obj, times) What value do I have to substitue for xxx, so that myrepeat will have the exact same function as itertools.repeat? -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-04, Nick Craig-Wood [EMAIL PROTECTED] wrote: Antoon Pardon [EMAIL PROTECTED] wrote: One possible way to do what I think you want is to code as follows: class Default (object): pass I'd have written Default = object() def f(var=Default): if var is Default: var = 1 return var * 2 But yes, defining a sentinel like this is a good idea. The problem is that a lot of built in and library functions are not written this way. So when f is one of those, you are stuck. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: [IronPython] [ANN] IronPython Community Edition 1.0r2
Hello, And here's the license and the summary of applied patches: http://fepy.sourceforge.net/license.html http://fepy.sourceforge.net/patches.html Do the patches include the various extensions that are being shipped? Am wondering if you could distribute a IPCE that contains all the documentation and sources, because it might be good for us to switch to it from standard IronPython for our distribution purposes. -- http://mail.python.org/mailman/listinfo/python-list
py2app semi-standalone semi-works
Hello All, I am trying to create a semi-standalone with the vendor python on OS X 10.4 (python 2.3.5). I tried to include some packages with both --packages from the command and the 'packages' option in setup.py. While the packages were nicely included in the application bundle in both cases (at Contents/Resources/lib/python2.3/), they were not found by python when the program was launched, giving the error: ImportError: No module named [whatever module] Is this because semi-standalone is semi-broken or is it because I have semi-omitted something? Any advice on resolving this issue would be greatly appreciated and would greatly reduce the size of the download. James -- http://mail.python.org/mailman/listinfo/python-list
Python crash when trying to generate an Excel worksheet with VBA macros
Hi, I developed a script with a nice interface in Tkinter that allows me to edit some formulas and to generate an Excel worksheet with VBA macros within it. The script runs perfectlly in Office 2000, but in Office 2003 crash at line: wbc = workbook.VBProject.VBComponents.Add(1) Please help me :-( the code of the module that crash is (only in Excel 2003, in 2000 not): import os import string from win32com.client import Dispatch, constants str_code= Dim nrfunc As Integer Dim cursor As Integer Dim i As Integer Dim j As Integer Sub Fill() 'Aflu numaru de functii din XL i = 1 .. def createExcelReport(projectName,templateName,saveToPath): # acquire application object, which may start application application = Dispatch(Excel.Application) # create new file ('Workbook' in Excel-vocabulary) using the specified template workbook = application.Workbooks.Add(Template1.xls) # store default worksheet object so we can delete it later defaultWorksheet = workbook.Worksheets(1) worksheet1 = workbook.Worksheets(1) worksheet2 = workbook.Worksheets(2) worksheet3 = workbook.Worksheets(3) wbc = workbook.VBProject.VBComponents.Add(1) -- here is the problem wbc.Name=Module1 wbc.CodeModule.AddFromString(str_code) path=saveToPath+\\+projectName+_+templateName+.xls workbook.SaveAs(path) worksheet1 = workbook.Worksheets(1) # make stuff visible now. worksheet1.Activate() application.Visible = True -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
Antoon Pardon wrote: On 2006-10-04, Paul Rubin http wrote: Antoon Pardon [EMAIL PROTECTED] writes: Now in this case you could start by assigning arg the value 1 and eliminate the if test. However that only works if you know the default value for the argument. What he seems to be asking for is if there is an object, (let as call it Default), that would make code like: def f(var=1): Equivallent to: def f(var=Default) if var is Default) var = 1 Oh, I see. Yes, the OP should just use a distinct default value instead of 1. I usually do this with sentinel = object() def f(var=sentinel): if var is sentinel: # f was called without an arg But that can only work if you are the author of f. Take the following code: def myrepeat(obj, times = xxx): return itertools.repeat(obj, times) What value do I have to substitue for xxx, so that myrepeat will have the exact same function as itertools.repeat? There's no possible value. You'll have to write this like def myrepeat(obj, times=None): if times is None: return itertools.repeat(obj) else: return itertools.repeat(obj, times) Many functions implemented in C have this behavior. For all functions written in Python, you can look up the default value in the source. Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
Am Wed, 04 Oct 2006 12:24:48 +0200 schrieb Peter Otten: The older pre-__iter__() iteration style relying on __getitem__() still works: class A: ... def __getitem__(self, index): ... return [3,2,1][index] ... for item in A(): ... print item ... 3 2 1 Thanks! I see: class B: ... def __iter__(self): ... for i in xrange(3): ... yield [3,2,1][i] ... myIter = B().__iter__() myIter.next() 3 myIter.next() 2 myIter.next() 1 Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the defaultargument value?
Georg Brandl wrote: But that can only work if you are the author of f. Take the following code: def myrepeat(obj, times = xxx): return itertools.repeat(obj, times) What value do I have to substitue for xxx, so that myrepeat will have the exact same function as itertools.repeat? There's no possible value. You'll have to write this like def myrepeat(obj, times=None): if times is None: return itertools.repeat(obj) else: return itertools.repeat(obj, times) or: def myrepeat(*args): return itertools.repeat(*args) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-04, Georg Brandl [EMAIL PROTECTED] wrote: Antoon Pardon wrote: On 2006-10-04, Paul Rubin http wrote: Antoon Pardon [EMAIL PROTECTED] writes: Now in this case you could start by assigning arg the value 1 and eliminate the if test. However that only works if you know the default value for the argument. What he seems to be asking for is if there is an object, (let as call it Default), that would make code like: def f(var=1): Equivallent to: def f(var=Default) if var is Default) var = 1 Oh, I see. Yes, the OP should just use a distinct default value instead of 1. I usually do this with sentinel = object() def f(var=sentinel): if var is sentinel: # f was called without an arg But that can only work if you are the author of f. Take the following code: def myrepeat(obj, times = xxx): return itertools.repeat(obj, times) What value do I have to substitue for xxx, so that myrepeat will have the exact same function as itertools.repeat? There's no possible value. You'll have to write this like Yes, that was the point I wanted to make. def myrepeat(obj, times=None): if times is None: return itertools.repeat(obj) else: return itertools.repeat(obj, times) Many functions implemented in C have this behavior. Which is a pity and IMO makes the documentation of these functions a bit problematic. Take the itertool.repeat documentation: repeat(object[, times]) Make an iterator that returns object over and over again. Runs indefinitely unless the times argument is specified. ... My first impression from this, is that it is possible to call this as follows: repeat(None, times = 5) But that doesn't work either. For all functions written in Python, you can look up the default value in the source. That wont help much if you would like something like the following: def fun(f): arg = Default try: arg = Try_Processing() except Nothing_To_Process: pass f(arg) -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Resuming a program's execution after correcting error
MRAB wrote: Sheldon wrote: MRAB wrote: Sheldon wrote: Hi. Does anyone know if one can resume a python script at the error point after the error is corrected? I have a large program that take forever if I have to restart from scratch everytime. The error was the data writing a file so it seemed such a waste if all the data was lost and must be recalculated again. You could modify the program while you're debugging it so that instead of, say: calculate data write data you have: if saved data exists: load data else: calculate data save data write data The pickle module would be useful here. Matthew I like your idea Matthew but I don't know how to pickle the many variables in one file. Do I need to pickle each and every variable into a seperate file? var1,var2 pickle.dump(var1,f) pickle.dump(var2,f2) Using the 'pickle' module: # To store: f = open(file_path, wb) pickle.dump(var1, f) pickle.dump(var2, f) f.close() # To load f = open(file_path, rb) var1 = pickle.load(f) var2 = pickle.load(f) f.close() A more flexible alternative is to use the 'shelve' module. This behaves like a dict: # To store s = shelve.open(file_path) s[var1] = first s[var2] = [2, 3] s.close() # To load s = shelve.open(file_path) print s[var1] # This prints first print s[var2] # This prints [2, 3] s.close() Hope that helps Matthew Perfect Matthew! Much obliged! /Sheldon -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the defaultargument value?
On 2006-10-04, Fredrik Lundh [EMAIL PROTECTED] wrote: Georg Brandl wrote: But that can only work if you are the author of f. Take the following code: def myrepeat(obj, times = xxx): return itertools.repeat(obj, times) What value do I have to substitue for xxx, so that myrepeat will have the exact same function as itertools.repeat? There's no possible value. You'll have to write this like def myrepeat(obj, times=None): if times is None: return itertools.repeat(obj) else: return itertools.repeat(obj, times) or: def myrepeat(*args): return itertools.repeat(*args) Yes that works but I have the impression that this solution becomes complicated very fast once you want to do extra processing in the function body. Take the following def myrepeat(obj, times = xxx) newobj = Process(obj) return itertools.repeat(obj, times) I think it would become something like: def myrepeat(*args): obj = args[0] tail = args[1:] newobj = Process(obj) newargs = (newobj,) + tail return itertools.repeat(*newargs) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
Hendrik van Rooyen wrote: Hi, I get the following: [EMAIL PROTECTED]:~/Controller/lib python display.py UpdateStringProc should not be invoked for type font Aborted and I am back at the bash prompt - this is most frustrating, as there is no friendly traceback to help me guess where its coming from. And what is worse, the script runs for a varying time before it simply exits like this. What can I do to dig deeper to try to find a clue? - I don't even know if its Python, Tkinter or Linux... Some background: The application is a prototype gui for a controller of an injection moulding machine. It has two rows of five buttons across the top, and a canvas containing various objects over the rest of the screen. Extensive use is made of configure to change the text of the buttons, as well as their command bindings, to keep the state of the system current - its quite a hack at this time, as I am still experimenting with getting the interface intuitive. On the canvas, there are multiple instances of a Meter class to show things like temperatures and pressures, as well as a schematic representation of the machine, created out of polygons and lines. The schematic, as well as the Meters, are crudely animated by deleting and redrawing the objects repetitively with slightly different parameters in response to button presses. This is done by starting different threads to implement the various motions, which repetitively call kill and draw methods in the main app, after which they (the threads) commit seppoku by returning. Everything seems to work fine. - there is a thread that runs to move the meter values around continuously, and this has been stable for some time now, and I can get the various machine parts to move around the screen by pushing the buttons. The trouble occurs when I put the machine into Auto mode, simulating the various motions in a loop, - it runs for anything from a few tens to a few hundreds of cycles before handing in its dinner pail like this. Any Ideas on what to do next to find the culprit? - Hendrik Minimal source code to reproduce this error would help tremendously. -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
Antoon Pardon [EMAIL PROTECTED] writes: repeat(object[, times]) Make an iterator that returns object over and over again. Runs indefinitely unless the times argument is specified. ... My first impression from this, is that it is possible to call this as follows: repeat(None, times = 5) But that doesn't work either. The code and/or doc is wrong, you have to use a positional arg and not a named one. repeat(None, 5) does the right thing. That wont help much if you would like something like the following: def fun(f): arg = Default try: arg = Try_Processing() except Nothing_To_Process: pass f(arg) Write it like this: def fun(f): args = () try: args = (Try_Processing(),) except Nothing_To_Process: pass f(*args) -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the defaultargument value?
Antoon Pardon [EMAIL PROTECTED] writes: I think it would become something like: def myrepeat(*args): obj = args[0] tail = args[1:] newobj = Process(obj) newargs = (newobj,) + tail return itertools.repeat(*newargs) Too messy. Just write: def myrepeat(obj, *times): return itertools.repeat(Process(obj), *times) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
On 10/4/06, Richard Jones [EMAIL PROTECTED] wrote: Nick Craig-Wood wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: And i dunno what the case against Trac is (it looks a fine tool for my small projects) but probably it's not good enough for python.org Trac is really good in my experience. Trac was considered. A nice extra is that it is written in python. So are Roundup and Launchpad, two of the other three trackers considered. So, just out of curiosity, what were the pros/cons of Launchpad, specially compared to Roundup? R. Richard -- http://mail.python.org/mailman/listinfo/python-list -- Ramon Diaz-Uriarte Bioinformatics Unit Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz -- http://mail.python.org/mailman/listinfo/python-list
replacing all 'rng's in a buffer with consecutive r[1], r[2]'s
I read a file into a buffer and subject it to re.sub() I can replace every occurrence of a pattern with a fixed string but when I try to replace each occurrence with a string that changes (by having an incrementing number in it, (ie 'repTxt[1]','repTxt[2]'etc), I note that the incrementing number generator function, I'm calling in re.sub(), (which works fine outside it), seems to be evaluated only once and is therefore not incrementing the number. Can someone please show me a working eg of how to replace 'rng' in a file with 'r[1]', 'r[2]' etc. This is my first Python program so any help would be very gratefully received. Here's my code [CODE] #read orig file into buf close file import re infile = file('pyInfile', 'r') buf = infile.read() infile.close() print buf #replace all allocated streams with 'rng' print '=== orig buf '; print buf pat = re.compile('r\[\d+\]') buf = pat.sub(rng, buf, 0) #now replace all 'rng's with consecutive streams #=== def static_num(): ''' this is a generator function that avoids globals yield differentiates fn as generator fn which freezes ''' x = 0 while True: x += 1 yield str(x) static = static_num().next pat = re.compile('rng') #there is a problem in that static only seems to get called once. #need to invoke this every time you get a match for it to #increment buf = pat.subn('rng[' + static() + ']', buf, 0) print 'static() incrementing ok ' + static() print 'static() incrementing ok ' + static() print '=== changed to '; print buf[0] #outfile = file('pyOutfile', 'w') #outfile.write(buf) [/CODE] -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-03, LaundroMat [EMAIL PROTECTED] wrote: Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to pass a value to f()? None doesn't seem to work.. Thanks in advance. I think the only general solution for your problem would be to define a defaulter function. Something like the following: Default = object() def defaulter(f, *args): while args: if args[-1] is Default: args = args[:-1] else: break return f(*args) The call: defaulter(f, arg1, arg2, Default, ..., Default) would then be equivallent to: f(arg1, arg2) Or in your case you would call: defaulter(f, Default) -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Tk: filling a frame with a widget
I have this code from Tkinter import * root=Tk() Button(root).pack(fill=BOTH) root.mainloop() I would expect the button filling all the client draw area of the Frame, but when I resize the root window the button becomes wider, but not higher ( I get some empty space under the button). How could set the button to fill always all the space available? Well maybe some other solution exists, since my problem is this: I have a resizable window and i want to keep it filled with a Canvas displaying an image (PhotoImage). Can I get the in some way the size of the clien draw area of the window containig the canvas? Thnx PAolo -- if you have a minute to spend please visit my photogrphy site: http://mypic.co.nr -- http://mail.python.org/mailman/listinfo/python-list
SOAPpy
Hi, I'm just started playing around with Python to trigger a method in a web service. I've been using SOAPpy and it's incredibly badly documented so i'm not getting very far. What I need to do is create the following in my SOAP body: n1:myMethod xmlns:n1=http://www.csapi.org/schema/etc...; n1:address xmlns:n1=http://www.csapi.org/schema/etc...;MyAddress/n1:address /n1:myMethod I've managed to kinda do something similar to this with the following piece of code: from SOAPpy import SOAPProxy wsdlurl = 'http://192.168.30.91:6062/mywebservice' # define the namespace namespace = 'http://www.csapi.org/schema/etc...' server = SOAPProxy(wsdlurl) print 'Test: ' + server._ns(namespace).myMethod(address = MyAddress) This creates the following SOAP XML: ns1:myMethod xmlns:ns1=http://www.csapi.org/schema/etc...; SOAP-ENC:root=1 address xsi:type=xsd:stringMyAddress/address /ns1:myMethod I need to be able to add a namespace to the address parameter so it matches the previous SOAP XML above (n1:address, xmlns, etc.) and, what with Python being new to me and SOAPpy having awful docs, I can't figure out how to do this. Could anyone please help here? Cheers, Jon. Information contained in this e-mail and any attachments are intended for the use of the addressee only, and may contain confidential information of Ubiquity Software Corporation. All unauthorized use, disclosure or distribution is strictly prohibited. If you are not the addressee, please notify the sender immediately and destroy all copies of this email. Unless otherwise expressly agreed in writing signed by an officer of Ubiquity Software Corporation, nothing in this communication shall be deemed to be legally binding. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Giovanni Bajo wrote: A.M. Kuchling wrote: ... using a non open source tracker (called JIRA - never heard before of course) for Python itself. Other projects do use it; see http://wiki.apache.org/general/ApacheJira for a partial list, and a link to the Apache Software Foundation's issue trackers. which, in my humble opinion, is just a list of other examples of projects which are misguided. People seem to have no idea when a company is sold, when a CEO is changed, or something like that. Hhistory's repeating, but hackers are not learning. Does this smell Bitkeeper fiasco to anyone else than me? The committee did expect this recommendation to be controversial. :) I guess :) In fact, I have a deepest hope that this recommendation was just a fake just to get people setup a roundup installation... But sadly people are much happier complaining on c.l.py than exerting themselves to support the community with an open source issue tracker. Hello, Jira regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Richard Jones wrote: Nick Craig-Wood wrote: Trac is really good in my experience. Trac was considered. A nice extra is that it is written in python. So are Roundup and Launchpad, two of the other three trackers considered. It should be noted that most skepticism (that I'm aware of) about Launchpad is typically rooted in that service's closed source nature. People voicing such skepticism don't seem to cut it any slack just because it is apparently written in Python. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Roundup Issue Tracker release 1.1.3
[EMAIL PROTECTED] wrote: Richard Jones wrote: I'm proud to release version 1.1.3 of Roundup. five database back-ends (anydbm, sqlite, metakit, mysql and postgresql). That ORM is pretty impressive: http://roundup.sourceforge.net/doc-1.0/design.html#roundup-database I like how easy it is to specify m-to-n relations. Is it possible to have a table with a multi-column primary key? Of course you could redesign your database so the primary keys are all IDs, and the former keys become simple columns with a UNIQUE index covering them ... regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Where to I find files: gtk.py _gtk.py and GDK.py
Hello, Can you tell me where to I find exactly this files:gtk.py, _gtk.py and GDK.py I was look everywhere,and download package of gtk but I can't find this files THANKS -- http://mail.python.org/mailman/listinfo/python-list
Re: Python/Tkinter crash.
Not talking to myself - Added results of strace run at bottom Hendrik van Rooyen [EMAIL PROTECTED] wrote: Hi, I get the following: [EMAIL PROTECTED]:~/Controller/lib python display.py UpdateStringProc should not be invoked for type font Aborted and I am back at the bash prompt - this is most frustrating, as there is no friendly traceback to help me guess where its coming from. And what is worse, the script runs for a varying time before it simply exits like this. What can I do to dig deeper to try to find a clue? - I don't even know if its Python, Tkinter or Linux... Some background: The application is a prototype gui for a controller of an injection moulding machine. It has two rows of five buttons across the top, and a canvas containing various objects over the rest of the screen. Extensive use is made of configure to change the text of the buttons, as well as their command bindings, to keep the state of the system current - its quite a hack at this time, as I am still experimenting with getting the interface intuitive. On the canvas, there are multiple instances of a Meter class to show things like temperatures and pressures, as well as a schematic representation of the machine, created out of polygons and lines. The schematic, as well as the Meters, are crudely animated by deleting and redrawing the objects repetitively with slightly different parameters in response to button presses. This is done by starting different threads to implement the various motions, which repetitively call kill and draw methods in the main app, after which they (the threads) commit seppoku by returning. Everything seems to work fine. - there is a thread that runs to move the meter values around continuously, and this has been stable for some time now, and I can get the various machine parts to move around the screen by pushing the buttons. The trouble occurs when I put the machine into Auto mode, simulating the various motions in a loop, - it runs for anything from a few tens to a few hundreds of cycles before handing in its dinner pail like this. Any Ideas on what to do next to find the culprit? - Hendrik Ran it with strace - here is last bit of log: write(3, \30\2\0\35\0\300\2\0\2\0\34\0\300\0027\0\7\0\34\0\300..., 68) = 68 select(4, [3], [], [], {0, 0}) = 0 (Timeout) gettimeofday({1159960306, 369206}, {4294967176, 0}) = 0 futex(0x807b908, FUTEX_WAKE, 1) = 0 futex(0x80bad48, FUTEX_WAKE, 1) = 0 write(3, 5\30\4\0N\0\300\2 \0\300\2r\2\220\0F\0\5\0N\0\300\2\23..., 900) = 900 gettimeofday({1159960306, 371171}, {4294967176, 0}) = 0 select(4, [3], [], [], {0, 0}) = 0 (Timeout) gettimeofday({1159960306, 371386}, {4294967176, 0}) = 0 futex(0x807b908, FUTEX_WAKE, 1) = 0 select(0, NULL, NULL, NULL, {0, 2}) = 0 (Timeout) futex(0x80bad48, FUTEX_WAIT, 0, NULL) = 0 futex(0x80bad48, FUTEX_WAKE, 1) = 0 write(3, \30\2\0\34\0\300\2\0\2\0\35\0\300\0027\0\7\0\35\0\300..., 68) = 68 select(4, [3], [], [], {0, 0}) = 0 (Timeout) gettimeofday({1159960306, 396232}, {4294967176, 0}) = 0 futex(0x807b908, FUTEX_WAKE, 1) = 0 futex(0x80bad48, FUTEX_WAKE, 1) = 0 write(3, 5\30\4\0N\0\300\2 \0\300\2r\2\220\0F\0\5\0N\0\300\2\23..., 900) = 900 gettimeofday({1159960306, 398381}, {4294967176, 0}) = 0 select(4, [3], [], [], {0, 0}) = 0 (Timeout) gettimeofday({1159960306, 398597}, {4294967176, 0}) = 0 futex(0x807b908, FUTEX_WAKE, 1) = 0 select(0, NULL, NULL, NULL, {0, 2}) = 0 (Timeout) futex(0x80bad48, FUTEX_WAIT, 0, NULL) = 0 futex(0x80bad48, FUTEX_WAKE, 1) = 0 futex(0x807b908, FUTEX_WAIT, 0, NULL) = 0 write(3, 7\30\5\0\21\0\300\2:\0\300\2\4\0\0\0\377\0\0\0, 20) = 20 select(4, [3], [], [], {0, 0}) = 0 (Timeout) gettimeofday({1159960306, 420182}, {4294967176, 0}) = 0 futex(0x807b908, FUTEX_WAKE, 1) = 0 futex(0x80bad48, FUTEX_WAIT, 0, NULL) = 0 futex(0x80bad48, FUTEX_WAKE, 1) = 0 write(3, 5\30\4\0N\0\300\0029\0\300\2\207\0\210\0F\0\5\0N\0\300..., 708) = 708 gettimeofday({1159960306, 421944}, {4294967176, 0}) = 0 select(4, [3], [], [], {0, 0}) = 0 (Timeout) gettimeofday({1159960306, 422168}, {4294967176, 0}) = 0 futex(0x807b908, FUTEX_WAKE, 1) = 0 select(0, NULL, NULL, NULL, {0, 2}) = ? ERESTARTNOHAND (To be restarted) +++ killed by SIGABRT +++ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Steve Holden wrote: But sadly people are much happier complaining on c.l.py than exerting themselves to support the community with an open source issue tracker. you're not on the infrastructure list, I hear. python.org could still need a few more roundup volunteers, but it's not like nobody's prepared to con- tribute manhours. don't underestimate the community. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What value should be passed to make a function use the default argument value?
On 2006-10-04, Antoon Pardon [EMAIL PROTECTED] wrote: On 2006-10-03, LaundroMat [EMAIL PROTECTED] wrote: Suppose I have this function: def f(var=1): return var*2 What value do I have to pass to f() if I want it to evaluate var to 1? I know that f() will return 2, but what if I absolutely want to pass a value to f()? None doesn't seem to work.. Thanks in advance. I think the only general solution for your problem would be to define a defaulter function. Something like the following: Default = object() def defaulter(f, *args): while args: if args[-1] is Default: args = args[:-1] else: break return f(*args) The call: defaulter(f, arg1, arg2, Default, ..., Default) would then be equivallent to: f(arg1, arg2) Or in your case you would call: defaulter(f, Default) A little update, with the functools in python 2.5 you could turn the above into a decorator. Something like the following (not tested): def defaulting(f): return functools.partial(defaulter, f) You could then simply write: @defaulting def f(var=1): return var * 2 And for built in or library functions something like: from itertools import repeat repeat = defaulting(repeat) -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Where to I find files: gtk.py _gtk.py and GDK.py
[EMAIL PROTECTED] wrote: Hello, Can you tell me where to I find exactly this files:gtk.py, _gtk.py and GDK.py I was look everywhere,and download package of gtk but I can't find this files I would like to know what your definition of everywhere is. Google(python gtk) gives this as the first hit: http://www.pygtk.org/ How much would you like to bet, and at what odds, that that which you seek is not there? -- http://mail.python.org/mailman/listinfo/python-list
Re: filling a frame with a widget
Paolo Pantaleo wrote: I have this code from Tkinter import * root=Tk() Button(root).pack(fill=BOTH) root.mainloop() I would expect the button filling all the client draw area of the Frame, but when I resize the root window the button becomes wider, but not higher ( I get some empty space under the button). pack(fill=BOTH, expand=1) should do the trick. the pack geometry manager works by slicing off vertical or horizontal areas from the parent, one area per widget. the fill option controls how to place the widget inside that area, the expand option controls how to handle any extra space left in the parent. if expand isn't set for any child widget, the extra space is left un- used. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: string: __iter__()?
mrquantum wrote: Hello! Just for curiosity i'd like to know why strings don't support the iteration protocoll!? Is there some deeper reason for this? hasattr('SomeString', '__iter__') False In Python 2.5 it's actually simple to obtain one: myIter = (c for c in 'SomeString') myIter.next() 'S' Thanks for info! Chris Well, I see it as a feature. Typically I want to consider a string as an atomic object (and not as a sequence of characters) and I can check hasattr(obj, '__iter__') to distinguish (for instance) a list of strings from a single string (typically in recursive algorithms working on texts). Michele Simionato -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing all 'rng's in a buffer with consecutive r[1], r[2]'s
m g william wrote: I read a file into a buffer and subject it to re.sub() I can replace every occurrence of a pattern with a fixed string but when I try to replace each occurrence with a string that changes (by having an incrementing number in it, (ie 'repTxt[1]','repTxt[2]'etc), I note that the incrementing number generator function, I'm calling in re.sub(), (which works fine outside it), seems to be evaluated only once and is therefore not incrementing the number. Can someone please show me a working eg of how to replace 'rng' in a file with 'r[1]', 'r[2]' etc. This is my first Python program so any help would be very gratefully received. buf = pat.subn('rng[' + static() + ']', buf, 0) You'll have to repeat that to get the desired effect: pat = re.compile(rng) replacements = 1 while replacements: buf, replacements = pat.subn(r[ + static() + ], buf, 1) print buf but there is a more efficient alternative def fsub(match): return r[ + static() + ] buf = re.sub(rng, fsub, buf) that would still work if you were to replace 'rng' with 'rng[1]', 'rng[2]'... Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting Pygopherd to work under Mac OS X
[EMAIL PROTECTED] writes: Could someone *please* show us poor Mac users how to install and run Pygopherd successfully under Mac OS X? The latest version 2.0.4, as found at http://freshmeat.net/projects/pygopherd/ is my bane. I think I talked to John Goerzen, the maintainer, a while back but nothing came of it. I've tried this twice now, following the instructions given and have found nothing but grief and many errors. For a Python app it seems to be rather platform dependant! Does Pygopherd need to be altered somehow to work under OS X? If Pygopherd is a lost cause, can someone recommend another *maintained* gopher daemon with instructions that would allow its' use under OS X? Can you be more specific about what doesn't work? I'm not sure what you mean by platform dependent in this case. -- Cameron Kaiser * [EMAIL PROTECTED] * posting with a Commodore 128 personal page: http://www.armory.com/%7Espectre/ ** Computer Workshops: games, productivity software and more for C64/128! ** ** http://www.armory.com/%7Espectre/cwi/ ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
On Wed, 04 Oct 2006 07:37:47 GMT, Giovanni Bajo [EMAIL PROTECTED] wrote: I am seriously concerned that the PSF infrastructure committee EVER considered non open-source applications for this. In fact, I thought that was an implicit requirement in the selection. Being open source wasn't a requirement; minimal requirements were specified in the initial message requesting trackers (http://wiki.python.org/moin/OriginalCallForTrackers). --amk -- http://mail.python.org/mailman/listinfo/python-list
Re: Instantiating an object when the type is only known at runtime
On Tue, 2006-10-03 at 18:19, Samuel wrote: Thanks, that's what I was looking for. m = __import__( StringIO ) x = getattr( m, StringIO )() x StringIO.StringIO instance at 0x00A47710 For the records: If the module is already loaded, this also works: if my_type_is_not_yet_loaded: module = __import__(type) obj= getattr(module, type) else: obj= globals().get(type) resource = obj(my_arg1, my_arg2) You seem to be under the impression that importing an already imported module is a hideously expensive operation that must be avoided at all costs. It's not. If you import an already imported module, python simply returns the module object from sys.modules without executing any of the module's code. Your code will be much easier to read if you eliminate the my_type_is_not_yet_loaded check, whatever that may be under the hood, and always perform the __import__. It's also likely to be at least as fast, but I couldn't run a timing comparison even if I wanted to because you didn't post working code. -Carsten -- http://mail.python.org/mailman/listinfo/python-list
Re: replacing all 'rng's in a buffer with consecutive r[1], r[2]'s
m g william [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] snip #now replace all 'rng's with consecutive streams #=== def static_num(): ''' this is a generator function that avoids globals yield differentiates fn as generator fn which freezes ''' x = 0 while True: x += 1 yield str(x) static = static_num().next Also, check out itertools.count (one of many tools from the excellent itertools module), as in: static - itertools.count().next - no need to roll this function for yourself. You still need to call it for each substitution, though, as described elsewhere. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
A.M. Kuchling wrote: I am seriously concerned that the PSF infrastructure committee EVER considered non open-source applications for this. In fact, I thought that was an implicit requirement in the selection. Being open source wasn't a requirement; which is, indeed, shocking and amazing. minimal requirements were specified in the initial message requesting trackers (http://wiki.python.org/moin/OriginalCallForTrackers). Where does it mention that only trackers which have at least an existing installation and a group of people for maintenance will be considered? It could easily be assumed that PSF had already enough bandwidth, server, manpower to handle any bugtracker installation. In fact, are you absolutely positive that you need so much effort to maintain an existing bugtracker installation? I know for sure that GCC's Bugzilla installation is pretty much on its own; Daniel Berlin does some maintainance every once in a while (upgrading when new versions are out, applying or writing some patches for most requested features in the community, or sutff like that), but it's surely not his job, not even part-time. -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
dictionary of list from a file
Hi guys, this is my first post. my programming background is perlish scripting and now I am learning python. I need to create a dictionary of list from a file. Normally in perl I use to do like: while(IN){ @info=split(/ +/,$_); push (@{$tmp{$info[0]}},$info[1]); } and then foreach $key (keys %tmp){ print $key - @{$tmp{$key}}\n; } i get 2 - 1 2 3 4 7 - 7 8 9 10 in python I tried: b={} a=[] for line in fl.readlines(): info=lines.split() b[info[0]] = a.append(info[1]) and then for i in b: print i,b[i] i get 2 None 7 None data file is: 2 1 2 2 2 3 2 4 7 7 7 8 7 9 7 10 Any help?? Thanks in advance Best Regards Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary of list from a file
On 4 Oct 2006 06:09:21 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi guys, this is my first post. my programming background is perlish scripting and now I am learning python. I need to create a dictionary of list from a file. Normally in perl I use to do like: while(IN){ @info=split(/ +/,$_); push (@{$tmp{$info[0]}},$info[1]); } and then foreach $key (keys %tmp){ print $key - @{$tmp{$key}}\n; } i get 2 - 1 2 3 4 7 - 7 8 9 10 in python I tried: b={} a=[] for line in fl.readlines(): info=lines.split() b[info[0]] = a.append(info[1]) and then for i in b: print i,b[i] i get 2 None 7 None data file is: 2 1 2 2 2 3 2 4 7 7 7 8 7 9 7 10 Any help?? Thanks in advance Best Regards Andrea here is my program d = {} for line in file('test.txt'): line = line.strip() if line: k, v = line.strip().split() d.setdefault(k, []).append(v) print d Dict in Python has a setdefault method, if there is a key in dict, it'll return the value, and if there is not a key existed, it'll insert a key with the value supplied by the second parameter and return the value. So using setdefault will be very handy for inserting key. -- I like python! UliPad The Python Editor: http://wiki.woodpecker.org.cn/moin/UliPad My Blog: http://www.donews.net/limodou -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Giovanni Bajo wrote: In fact, are you absolutely positive that you need so much effort to maintain an existing bugtracker installation? I wonder what kinds of insights were sought from other open source projects. It's not as if there aren't any big open source projects having approachable community members willing to share their thoughts on running open source (or any other kind of) issue tracking software. KDE and GNOME don't use SourceForge and yet manage their own infrastructure - has anyone asked them how they do it? Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Python to use a non open source bug tracker?
Fredrik Lundh wrote: Steve Holden wrote: But sadly people are much happier complaining on c.l.py than exerting themselves to support the community with an open source issue tracker. you're not on the infrastructure list, I hear. python.org could still need a few more roundup volunteers, but it's not like nobody's prepared to con- tribute manhours. don't underestimate the community. No, I'm not on the infrastructure list, but I know that capable people *are*: and you know I am quite capable of donating my time to the cause, when I have it to spare (and sometimes even when I don't). Perhaps what I *should* have written was Sadly *many* people spend too much time bitching and moaning about those that roll their sleeves up, and not enough rolling their own sleeves up and pitching in. Sniping from the sidelines is far easier than hard work towards a goal. Kindly note that none of the above remarks apply to you. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary of list from a file
[EMAIL PROTECTED] wrote: snip perl example code in python I tried: b={} a=[] for line in fl.readlines(): info=lines.split() b[info[0]] = a.append(info[1]) and then for i in b: print i,b[i] i get 2 None 7 None data file is: 2 1 2 2 2 3 2 4 7 7 7 8 7 9 7 10 Any help?? Andrea, first the append method returns None, as you have discovered; it makes an inplace update (to a in your example) but does not return the list it has updated. This has surprised a few people in the past :-) Here is what I've used before for updating lists values in a dictionary. d[key] = d.get(key, []) + [value] where d is a dict(ionary) Hope this helps. Keir. -- http://mail.python.org/mailman/listinfo/python-list
Access to static members from inside a method decorator?
I'm developing a library at the moment that involves many classes, some of which have exposed capabilities. I'm trying to design a nice interface for both exposing those capabilities, and inspecting instances to find out what capabilities they have. At the moment, I'm leaning towards a superclass (Exposed) that defines a static method which is a decorator (expose) such that any derived class can mark a method with @Exposed.expose and it will then be later returned by getExposedMethods(), a la: class Exposed: @staticmethod def expose( f ): ... def getExposedMethods( self ): ... class Person( Exposed ): @Exposed.expose def talk( self, ... ): ... I'm trying to implement the decorator by having it populate a static member list of whatever class it's in with a reference to the method. getExposedMethods() would then return the contents of each of those lists from itself back to Exposed in the class hierarchy. The first problem was that having a reference to the method (i.e. talk()) does not allow you to get a reference to the enclosing class (I had hoped im_class would lead me there). The real hiccup was that explicitly passing the class as an argument to the decorator generates a undefined global name error, presumably because at that point of execution the class object hasn't been fully created/initialised. So how can this be done? It doesn't seem like it's possible to pass a reference to the enclosing class into the decorator, which in turn means that static tracking of the list of exposed methods is impossible (at least, if I want to use decorators). Any ideas that will enable my initial design, or suggestions for an elegant, workable alternative would be much appreciated. Cheers, Glen -- http://mail.python.org/mailman/listinfo/python-list
Re: dictionary of list from a file
On Wed, 04 Oct 2006 06:09:21 -0700, [EMAIL PROTECTED] let this slip: b={} a=[] for line in fl.readlines(): info=lines.split() b[info[0]] = a.append(info[1]) append does not return a value. you'll want something like d = {} for line in fl: key, value = line.strip().split() if key not in d: d[key] = [] d[key].append(value) or something with setdefault, as limodou suggested. for i in b: print i,b[i] you can also use: for k,v in d.iteritems(): print k,v if you're dealing with integers only, you'll want to convert the data when reading using int() and long(). i get 2 None 7 None data file is: 2 1 2 2 2 3 2 4 7 7 7 8 7 9 7 10 -- Thomas Jollans alias free-zombie -- http://mail.python.org/mailman/listinfo/python-list