Re: A better way to timeout a class method?
On Mon, 9 Mar 2009, Nick Craig-Wood wrote: John O'Hagan resea...@johnohagan.com wrote: Is there a concise Pythonic way to write a method with a timeout? I did this: class Eg(object): def get_value(self, timeout): from threading import Timer self.flag = True def flag_off(): self.flag = False timer = Timer(timeout, flag_off) timer.start() while self.flag: #do stuff for a long time to get some value if condition: #if we ever get the value self.value = value break but it seems hackish to have a special flag attribute just to manage the timeout within the the method. How about something like this from threading import Timer class Duration(object): def __init__(self, duration): self.running = True self.timer = Timer(duration, self.set_finished) self.timer.setDaemon(True) self.timer.start() def set_finished(self): self.running = False def __nonzero__(self): return self.running Nifty! Works for threads too because they can have access to the Duration object. I guess it works on a similar principle to my attempt (setting a flag with a timer) but is cleaner by keeping everything inside the method. So my original method would look like this: class ExIt(object): def __init__(self, iter_func, args=None): self.iter_func = iter_func self.args = args self.length = None def get_length(self, timeout=None): Try to get length of iterator within a time limit if self.length is None: from threading import Thread, Timer timer=Duration(timeout) def count(): gen = self.iter_func(self.args) length = 0 while timer: try: gen.next() length += 1 except StopIteration: self.length = length break getlen = Thread(target=count) getlen.setDaemon(True) getlen.start() Which does exactly what I want: runs a time-consuming task in the background and can optionally time it out. In fact that's so handy, I think it would be nice if there was a standard timer object which is True while running, then False. Or maybe there is? Thanks, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
On 3/9/09, bearophileh...@lycos.com bearophileh...@lycos.com wrote: See here Daniel Fetchinson: http://groups.google.com/group/comp.lang.python/browse_thread/thread/a973de8f3562675c But be quite careful in using that stuff, it has some traps. Thanks a lot for all the helpful replies! Yes, I should name the unnamed lambda function, or better, just use 'def'. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Graph Dates and Values
I am trying to plot dates and values on a graph using matplotlib. Below is the code. I can run this and it works great, until I get to about 2000 rows from the DB. Things really start to slow down. I have successfully plotted up to 5000 rows from the DB, but it is very slow. I am attempting to plot values for a day, which would be equal to 84600 records. Is there a more efficient may to accomplish this? import os import psycopg2 import matplotlib.pyplot as plt import matplotlib.dates as mdates import pylab import dateutil from datetime import datetime conn = psycopg2.connect(dbname='db' user='user' password='somepass' host='localhost') spo2_cur = conn.cursor() sql = (SELECT System_Time, val1 FROM data WHERE DATE(System_Time) ='2009-01-07' AND Inst_Num='12345';) data_cur.execute(sql) value_data = data_cur.fetchall() data_cur.close() conn.close() num_rows = len(value_data) print There are,num_rows,rows in the database datesFmt = mdates.DateFormatter('%H:%M') plt.figure(figsize=(14,3)) for s in value_data: dates = mdates.date2num([s[0]]) plt.plot([dates],[s[1]], 'bo', ms=6) plt.ylim(60,100) plt.axhline(y=90, linewidth=2, color='r') ax1= plt.gca() ax1.xaxis.set_major_formatter(datesFmt) for label in ax1.xaxis.get_ticklabels(): label.set_color('black') label.set_rotation(45) label.set_fontsize(8) for label in ax1.yaxis.get_ticklabels(): label.set_fontsize(8) plt.show() plt.close() Any help would be great! Thanks B -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
farsi...@gmail.com wrote: 4 / 5.0 0.84 0.8 * 5 4.0 Start here: http://docs.python.org/tutorial/floatingpoint.html Play with these: 4/5.0 0.84 print 4/5.0 0.8 print repr(4/5.0) 0.84 str(4/5.0) '0.8' repr(4/5.0) '0.80004' And learn more here: http://www.lahey.com/float.htm http://en.wikipedia.org/wiki/Floating-point -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: xml input sanitizing method in standard lib?
Gabriel Genellina wrote: En Mon, 09 Mar 2009 15:30:31 -0200, Petr Muller a...@afri.cz escribió: Thanks for response and sorry for I wasn't clear first time. I have a heap of data (logs), from which I build a XML document using xml.dom.minidom. In this data, some xml invalid characters may occur - form feed (\x0c) character is one example. I don't know what else is illegal in xml, so I've searched if there's some method how to prepare strings for insertion to a xml doc before I start research on a xml spec and write such function on my own. You don't have to; Python already comes with xml support. Using ElementTree to build the document is usually easier and faster: http://effbot.org/zone/element-index.htm While I usually second that, this isn't the problem here. This thread is about unallowed characters in XML. The set of allowed characters is defined here: http://www.w3.org/TR/xml/#charsets And, as Terry Reedy pointed out, the unicode.translate method should get you where you want. Just define a dict that maps the characters that you want to remove to whatever character you want to use instead (or None) and pass that into .translate(). Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: last and final attempt to search for python ods library.
On Mon, 2009-03-09 at 15:55 -0400, Terry Reedy wrote: I think you are confusing process and result. The result is a cell that spans more than one column or row *when displayed*, thus hiding the cells that would otherwise be displayed. This is, I am 99.9% sure, controlled by an attribute of the visually expanded cell. That might be the case imho, But I tried increasing the width of the column using python-ooolib and i could not get the effect of a merged cells. I am now trying odfpy and hope it will do what I want. In OOCalc, the process is to mark a block of cells and select Format / Merge Cells. But still, the result will be a change in the upper left attribute. Thus I suggested you make a .ods file with expanded cells and then read the xml to see what cell element attribute is set thereby. Any decent odf library will be able to set element attributes. What did you mean by the upper left attribute, are you asuming that the merged cells are in the top row? In my case that's actually the case beacuse because I want my python script to generate an ods file with the cells in the top row merged from let's say a1 to d1. Talking about the xml, which file should I look at to see the effect of merging cells? If the about-to-be hidden cells are not empty, OOCcalc gives you the option of converting all cell contents to strings and joining them into one string in the expanded cell. If you create .ods from scratch, you should never need to do this. If you edit an existing .ods, something like ' '.join(str(cell.contents for cell in merge_group)) possibly in a function that also sets the attribute, should be easy enough to write. And, of course, you will be able to do things other than the one option OOCalc gives you. This is exactly what I was trying to achieve with the python-ooolib module but could not do it. The library did have a cet_cell_property function but did not allow for merging. In other words, I do not think you *need* an existing cell-merge function. But the library I use does not allow me to try the method you suggested. Seems that I will have to look at the xml and write my own module. Do you know how I can work around this? See above. I tryed searching for py2odf but did ont find any results. Whoops. odfpy at http://opendocumentfellowship.com/development/projects/odfpy but I strongly suspect you can do what you want with python-ooolib. No buddy, I tryed with ooolib but now given up unless some one points out what I am missing. happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On Mar 9, 5:57 pm, MRAB goo...@mrabarnett.plus.com wrote: Explore_Imagination wrote: Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have these four variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( (lll), a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. Any Suggestions? Split the 64-bit values into 2 x 32-bit values? I have tried by splitting 64-bit values but still it doesn't make any difference :( -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On Mar 9, 5:57 pm, MRAB goo...@mrabarnett.plus.com wrote: Explore_Imagination wrote: Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have these four variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( (lll), a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. Any Suggestions? Split the 64-bit values into 2 x 32-bit values? I have tried by splitting 64-bit values but still it doesn't make any difference :( -- http://mail.python.org/mailman/listinfo/python-list
Re: last and final attempt to search for python ods library.
On Tue, 2009-03-10 at 00:27 -0400, Terry Reedy wrote: In any case, api-for-odfpy.odt has I am going through the documentation for odfpy but finding it pritty complex right now. 5.17.12 table.CoveredTableCell Requires the following attributes: No attribute is required. Allows the following attributes: booleanvalue, contentvalidationname, currency, datevalue, formula, numbercolumnsrepeated, protect, stringvalue, stylename, timevalue, value, valuetype. These elements contain table.CoveredTableCell: table.TableRow. The following elements occur in table.CoveredTableCell: dr3d.Scene, draw.A, draw.Caption, ... So merged cells are refered to as covered cells is it? so odfpy, at least, can create such elements. Do you have any code sample done in odfpy which I can browse throu and run it to see the results. Here's an example of 2 merged ranges: A1:C2 contains the text foo and D1:D2 contains bar table:table-row table:style-name=ro1 - table:table-cell table:style-name=ce1 office:value-type=string table:number-columns-spanned=3 table:number-rows-spanned=2 text:pfoo/text:p /table:table-cell table:covered-table-cell table:number-columns-repeated=2 / - table:table-cell table:style-name=ce1 office:value-type=string table:number-columns-spanned=1 table:number-rows-spanned=2 text:pbar/text:p /table:table-cell /table:table-row - table:table-row table:style-name=ro1 table:covered-table-cell table:number-columns-repeated=4 / /table:table-row Aside: If you are wondering where the cell addresses (D1 etc) are, they're in the reader's current_row and current_col variables :-) Perhaps this was intended to save space, but what of table:number- columns-repeated=4 ?? I guess I got the point, but still can't figure out how I could actually implement this because I find the documentation of odfpy pritty complex and does not have the kind of example which shows what you explained in the above code. And the problem is that I got a bit confused in the above code because my merging happens only in the top row and spanns columns not rows. I would be very happy if I could get the code wich creates a set of merged cells in a single row with some data in it. I managed to do the odt part in the odfpy because the examples were there and well documented. happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On Mar 9, 5:57 pm, MRAB goo...@mrabarnett.plus.com wrote: Explore_Imagination wrote: Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have these four variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( (lll), a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. Any Suggestions? Split the 64-bit values into 2 x 32-bit values? I have tried by splitting 64-bit values but still it doesn't make any difference :( -- http://mail.python.org/mailman/listinfo/python-list
Mapping 64 bit int from C to Python-2.2 ?????
Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have following variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( (lll), a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. I have tried by splitting 64-bit values but still it doesn't make any difference :( Any Suggestions? -- http://mail.python.org/mailman/listinfo/python-list
Re: creating a list of all imported modules
mat...@gmail.com wrote: for i in dir() : ... t = eval( 'type(' + i + ')' ) ... if re.match('.*module.*',str(t)) : print i, t ... If you think you need eval stop and think again. You don't. If you think you need regular expressions stop and think again. You usually don't. def imported(namespace=None): from types import ModuleType if namespace is None: namespace = globals() for n, v in namespace.iteritems(): if isinstance(v, ModuleType): print n imported() re __builtins__ sys os types -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
BTW what are your feelings on a patch to msi.py to change the names of the directories it's looking for to pick up the Tk licenses? It's a bit of a grey area since the only canonical reference I can find is the externals checkout from within tools\buildbot: you might as well argue that it's *that* which should be changed. Never touch a running system :-) If I can leave the tcl directories where I have them, and just check them out a second time (or perhaps just the license), that would be fine with me. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2 ?????
Any Suggestions? Read all of the responses you got the last time you posted the very same article. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Mapping 64 bit int from C to Python-2.2
On 10/03/2009 2:51 AM, Explore_Imagination wrote: Hi I want to map 64 bit integers from C to python. I must use Python 2.2 BUT There is no support for 64 bits integers in Python2.2 (Supported in 2.5). Now the problem is that I have these four variables: unit32_t a,b,c; uint64_t w,x,y,z; I use this funtion to map values: Py_BuildValue( (lll), a,b,c,w,x,y,z ); As I access 32 bit values in Python it works fine BUT 64 bit intergers in Pythong give garbage values . I think there may be a case of overflow when 64 bit values in C are mapped to python. Any Suggestions? pywin32 had this requirement, and although support was recently removed, if you look at: http://pywin32.cvs.sourceforge.net/viewvc/pywin32/pywin32/win32/src/PyLARGE_INTEGER.cpp?revision=1.11view=markup you should find routines that work without 'longlong' support in Python itself. Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Martin v. Löwis wrote: BTW what are your feelings on a patch to msi.py to change the names of the directories it's looking for to pick up the Tk licenses? It's a bit of a grey area since the only canonical reference I can find is the externals checkout from within tools\buildbot: you might as well argue that it's *that* which should be changed. Never touch a running system :-) If I can leave the tcl directories where I have them, and just check them out a second time (or perhaps just the license), that would be fine with me. OK; I've added a step to my process which does a svn export with the other name, specifying a depth of files-only. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: a potential pep to extend the syntax of for loops
This idea has already been proposed and rejected. But discuss away as you wish ;=). tjr Where is that? I didn't see any related pep's. Could you post a link? -- http://mail.python.org/mailman/listinfo/python-list
Re: Packaging Survey
Robert Kern wrote: On 2009-03-09 13:52, R. David Murray wrote: The web _really, really_ needs some sort of mechanism for a site to say I'm not claiming anything about my identity, I'm just providing you an https channel over which to talk to me securely. If I don't claim an identity and provide a way for you to authenticate that claim, the channel is vulnerable to a man-in-the-middle attack and, therefore, is not secure. It would provide moderate protection against naive eavesdropping, though. Is that what you meant? There might be a way to authenticate that claim: if you know who this site is supposed to be owned by, you can call them and ask them to read the fingerprint over the phone. Or they could print it on all their paper communication, which would be even better. Once (back in 2000) I had to order a signed certificate for a company that didn't exist (yet), and to my surprise it worked (and this was from a very well-known CA). That was the last day I really trusted certificates signed by (most) commercial CAs... So my conclusion is: the only way to be really sure if a certificate is good is the same for both types (self-signed or signed by a trusted CA). -- JanC -- http://mail.python.org/mailman/listinfo/python-list
Determining from which web page a cgi script is invoked?
Given a webpage test.html that has a form with a cgi script, how can you determine inside the cgi script the name of the webpage that invoked the script? I have many different html pages that use a common cgi script for form processing and want to determine the name of the webpage. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Montag, 9. März 2009, r wrote: Long answer: 'Ye%s' %'s'*1000 simplified long answer: 'Yes' * 1000 or did you mean 'Ye%s' %('s'*1000) -- Wolfgang -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Mon, 2009-03-09 at 21:28 -0700, Luis Gonzalez wrote: C'mon guys, Xha Lee always wins, because fools like you get mad at him instead of ignoring him. Here here! -- http://mail.python.org/mailman/listinfo/python-list
Number Sequencing, Grouping and Filtering
Hi I was hoping someone would be able to point me in the direction of some good documentation regarding sequencing, grouping and filtering and in which order they should be done. As a small example it is easy to create the range of numbers 1 to 20. But if I wanted to group all possible combinations of sets of 4 numbers within this range is there already an in uilt function for this I am searching the module docs with number sequencing and number grouping but cannot find info. Then if I wanted to refine this results further eg no consecutive numbers to be contained in sets. Is it best to create all sets and then filter the sets for things matching this criteria or to set this condition in a creation. Creating sets and then filtering would soon become unwieldy with a larger range I would imagine.. An ideas, pointers to docs or better search terms to help me explore this further would be appreciated. Thanks Sayth -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining from which web page a cgi script is invoked?
davidgo...@davidgould.com wrote: Given a webpage test.html that has a form with a cgi script, how can you determine inside the cgi script the name of the webpage that invoked the script? I have many different html pages that use a common cgi script for form processing and want to determine the name of the webpage. Not that this has anything to do with python...but you're interested in the standard referrer/referer field[1] in your request headers. Note that this field IS OPTIONAL. Firefox makes it easy to keep the referrer private, so it's never sent. -tkc [1] http://en.wikipedia.org/wiki/Referer -- http://mail.python.org/mailman/listinfo/python-list
Re: Number Sequencing, Grouping and Filtering
On Tue, Mar 10, 2009 at 2:54 AM, flebber flebber.c...@gmail.com wrote: Hi I was hoping someone would be able to point me in the direction of some good documentation regarding sequencing, grouping and filtering and in which order they should be done. As a small example it is easy to create the range of numbers 1 to 20. But if I wanted to group all possible combinations of sets of 4 numbers within this range is there already an in uilt function for this I am searching the module docs with number sequencing and number grouping but cannot find info. I think itertools (http://docs.python.org/library/itertools.html) combined with list comprehensions (http://docs.python.org/dev/tutorial/datastructures.html#list-comprehensions) should be able to accomplish what you want. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Number Sequencing, Grouping and Filtering
On Mar 10, 8:54 pm, flebber flebber.c...@gmail.com wrote: Hi I was hoping someone would be able to point me in the direction of some good documentation regarding sequencing, grouping and filtering and in which order they should be done. As a small example it is easy to create the range of numbers 1 to 20. But if I wanted to group all possible combinations of sets of 4 numbers within this range is there already an in uilt function for this I am searching the module docs with number sequencing and number grouping but cannot find info. Then if I wanted to refine this results further eg no consecutive numbers to be contained in sets. Is it best to create all sets and then filter the sets for things matching this criteria or to set this condition in a creation. Creating sets and then filtering would soon become unwieldy with a larger range I would imagine.. An ideas, pointers to docs or better search terms to help me explore this further would be appreciated. Thanks Sayth I have just found itertools is this acheivable using combinations() and groupby() in itertools? -- http://mail.python.org/mailman/listinfo/python-list
Re: Number Sequencing, Grouping and Filtering
On Tue, Mar 10, 2009 at 3:00 AM, flebber flebber.c...@gmail.com wrote: On Mar 10, 8:54 pm, flebber flebber.c...@gmail.com wrote: Hi I was hoping someone would be able to point me in the direction of some good documentation regarding sequencing, grouping and filtering and in which order they should be done. As a small example it is easy to create the range of numbers 1 to 20. But if I wanted to group all possible combinations of sets of 4 numbers within this range is there already an in uilt function for this I am searching the module docs with number sequencing and number grouping but cannot find info. Then if I wanted to refine this results further eg no consecutive numbers to be contained in sets. Is it best to create all sets and then filter the sets for things matching this criteria or to set this condition in a creation. Creating sets and then filtering would soon become unwieldy with a larger range I would imagine.. An ideas, pointers to docs or better search terms to help me explore this further would be appreciated. Thanks Sayth I have just found itertools is this acheivable using combinations() and groupby() in itertools? Yes; indeed, those were the functions your post brought to mind and which led me to suggest itertools. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
On Mar 10, 6:38 am, Daniel Fetchinson fetchin...@googlemail.com wrote: On 3/9/09, bearophileh...@lycos.com bearophileh...@lycos.com wrote: See here Daniel Fetchinson: http://groups.google.com/group/comp.lang.python/browse_thread/thread/... But be quite careful in using that stuff, it has some traps. Thanks a lot for all the helpful replies! Yes, I should name the unnamed lambda function, or better, just use 'def'. Cheers, Daniel -- Psss, psss, put it down! -http://www.cafepress.com/putitdown Sort of tangenitally; is there any real difference between the outcome of the two following pieces of code? a = lambda x: x+2 def a(x): return x+2 Iain -- http://mail.python.org/mailman/listinfo/python-list
how to maximize a window with pygame
Hello I want to have a maximized window with pygame how can I know the resolution of the screen to create de pygame window with the good size? thanks and regards Jonathan Chacón -- http://mail.python.org/mailman/listinfo/python-list
Re: creating a list of all imported modules
On Mar 10, 11:01 am, Tim Michelsen timmichel...@gmx-topmail.de wrote: Hello, how do I create a list of all modules imported by my module/script and which are present in the namespace? I am looking for something like %who in Ipython. My aim is to create a file for the documentation that shows all dependencies of my script on external (3rd party) libraries. To sort out which imported modules are supplied by Python, by you, and by 3rd parties it would help a lot if you knew where the modules are being loaded from. Put this code at the end of your script: import sys info = [(module.__file__, name) for (name, module) in sys.modules.iteritems() if hasattr(module, '__file__')] info.sort() import pprint pprint.pprint(info) AFAIK unless someone has been messing with sys.modules, this gives you all modules that have been imported during the running of your script, except for built-ins (no __file__ attribute). Warning: I've not tried this with eggs and zips. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
Xah Lee schrieb: Christian fakem...@xyz.de wrote: On Mar 9, 1:22 pm, Christian fakem...@xyz.de wrote: XahLeeschrieb: Of interest: • Why Can't You Be Normal? http://xahlee.org/Netiquette_dir/why_cant_you_be_normal.html IMHO the point that you never reply to responds is what makes it problematic. I have seen 10 or more threads started by you and in not a single one of those I have seen any sort of second post by you. Also the other thing that makes you appear like a troll is that the only posts where you are visible on the usenet are your own! Usenet is there for discussion. What you do seems to be mostly doing a often highly intelligent monologue and awaiting comment on it. Its not the purpose of Usenet. Simply calling you a troll is wrong. You are after all better than that. Though I think you are misusing the Usenet. For what you do you should rather write a weblog so people interested in your monologues could follow them in a place where they are by definition on topic. Christian In the article you quoted: http://xahlee.org/Netiquette_dir/why_cant_you_be_normal.html contains this passage: « Some people says that i don't participate in discussion, and this is part of the reason they think i'm a so-called “troll”. Actually i do, and read every reply to my post, as well have replied to technical questions other posted. Most replies to my posts are attacks or trivial (of few sentences) i don't consider worthy to reply. A few, maybe 10% replies to my unconventional posts, i consider having some value. But if i don't have sufficiently remarkable opinion on what they remarked, i don't reply. Also, if all i wanted to say is “thanks”, i tend to avoid posting such trivial posts too. (i used to reply by personal email in such cases, I still do sometimes now, but today that can be considered intrusive.) » I have read the passage though the 10% replies does not reflect my own experience with your posts. Thats why I pointed out that you never reply to the posts, at least not to the ones I have seen. Truly Your Superior, Do you really think that of yourself? Now I really am disappointed of you. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: A parser for S.W.I.F.T. MT940 Files (for banking transactions)
On 9 mar, 14:59, Saki sakal...@gmail.com wrote: Hello, I need an MT940 file parses. It can be either a pure python library or a binding/wrapper, no matter. Almost all european banks provide transactions extract in MT940 format. There are parsers around, but none of them are for python. Any help is greatly appreciated. Thanks, Saki I have written some parser for electronic payment file, but not for MT940, sorry... For this kind of task I always use Construct (http:// construct.wikispaces.com/) which is a truly wonderful parser builder for Python. Hope it could help. -- http://mail.python.org/mailman/listinfo/python-list
Re: last and final attempt to search for python ods library.
any ways thanks for your reply, Right now I am stuck very badly. The problem is that I am trying python-ooolib and did find the library pritty good. There's another one called ooolib-python; have you had a look at that? Can you provide the url? Actually I think I saw this library but it seems it is not well maintained and the author is no more active. I think it is supporting old formats if I am talking about the same library. So please send me the link so that I confirm my doubts. But the problem is that library is missing a major feature from my requirement context. I need to merge cells in a spreadsheet and this library won't do that. Do you know how I can work around this? Here's a radical suggestion: Ask the author directly, or pop a note in the suggestion box on the sourceforge tracker [hint: don't use your mail client for this]. I did send him a message but did not get any reply for the email. I will put this request on sourceforge.net as per your suggestion any how. I tryed searching for py2odf but did ont find any results. Do you want me to continue on the previous thread (I will try and dig that out ). Nah, just hijack a third thread :-) Thanks for that suggestion, I am not that multi threaded *smile*. I have fixt my mail problem now so every things seems to be fine (untill i hyjak another thread by accident LOL!). happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: xml input sanitizing method in standard lib?
En Tue, 10 Mar 2009 05:40:10 -0200, Stefan Behnel stefan...@behnel.de escribió: Gabriel Genellina wrote: En Mon, 09 Mar 2009 15:30:31 -0200, Petr Muller a...@afri.cz escribió: I don't know what else is illegal in xml, so I've searched if there's some method how to prepare strings for insertion to a xml doc before I start research on a xml spec and write such function on my own. You don't have to; Python already comes with xml support. Using ElementTree to build the document is usually easier and faster: http://effbot.org/zone/element-index.htm While I usually second that, this isn't the problem here. This thread is about unallowed characters in XML. The set of allowed characters is defined here: http://www.w3.org/TR/xml/#charsets Ouch. Sorry, I was under the false impression that a) control characters were allowed, and b) ElementTree would escape them. Both are wrong, and I stand corrected. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: last and final attempt to search for python ods library.
On 10/03/2009 10:35 PM, Krishnakant wrote: any ways thanks for your reply, Right now I am stuck very badly. The problem is that I am trying python-ooolib and did find the library pritty good. There's another one called ooolib-python; have you had a look at that? Can you provide the url? Actually I think I saw this library but it seems it is not well maintained and the author is no more active. I think it is supporting old formats if I am talking about the same library. So please send me the link so that I confirm my doubts. http://ooolib.sourceforge.net/ calls it ooolib-python, but in topsy-turvy land (http://packages.debian.org/unstable/python/python-ooolib) it's called python-ooolib but all you need in the end is import ooolib. Three are one and one is three :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
Iain King iaink...@gmail.com wrote: Sort of tangenitally; is there any real difference between the outcome of the two following pieces of code? a = lambda x: x+2 def a(x): return x+2 a.__name__ As for why that matters, try a(None) and see which gives the more informative traceback. -- \S under construction -- http://mail.python.org/mailman/listinfo/python-list
Re: A Dangling Tk Entry
Rhodri James wrote: On Tue, 10 Mar 2009 04:14:51 -, W. eWatson notval...@sbcglobal.net wrote: Marc 'BlackJack' Rintsch wrote: On Mon, 09 Mar 2009 04:22:57 -0700, W. eWatson wrote: Marc 'BlackJack' Rintsch wrote: On Sun, 08 Mar 2009 22:20:09 -0700, W. eWatson wrote: You didn't answer my question why entry is necessary at all. The original author thought it was necessary to return entry. I'll give you a peek at a segment of the code I'm working with here: class Enter_Data_Dialog(tkSimpleDialog.Dialog): def __init__(self, parent, sdict): self.sdict = sdict tkSimpleDialog.Dialog.__init__(self, parent) def body(self,master): self.title(Set a Number Entry Dialog) Label( master, text=Number ).grid(row=0, sticky=W) self.anumberVar = StringVar() entry = Entry(master, width=10, textvariable=self.anumberVar).grid(row=0, column=1) self.anumberVar.set( %d % self.sdict[anumber] ) return entry `entry` is unnecessary here. But that was not obvious from your previous example, as you trimmed the code. Now it is clear that `entry` is always `None` because that's what `grid()` returns. But according to the docs this method should return the widget, that should get the focus, so maybe the author really wanted to return the `Entry` instance here, instead of `None`. He's got to return something, because he uses it upon return, as here: `entry` is always `None`, so it is the same as returning nothing because every function has an implicit ``return None`` at the end. def Set_Enter_Data(self): sdict = {} sdict[ ok ] = False sdict[ anumber ] = self.anumber dialog = Enter_Data_Dialog( self.master, sdict ) --- returning That's not a call to the `body()` method so that ``return`` is irrelevant here. Here an instance of `Enter_Data_Dialog` is created. No ``return`` involved. BTW if this is really just a dialog to enter a number, the functions `askinteger()` or `askfloat()` from the `tkSimpleDialog` module can be used. Ciao, Marc 'BlackJack' Rintsch What you are seeing here as an example, is a paired down version of the 2000 line program to focus on the particular problem at hand. The full code uses up to 20 variable of various types, via the dialog object. It uses them successfully to get the values the user has entered. How can it be irrelevant if it works? The author thought this was the way to do it. It's not my invention. It's no fluke. He does the same thing in another dialog that brings back about 6 values. def body(self,master): [snip] You're misunderstanding. The line that you arrowed above has absolutely nothing whatsoever to do with the method body(), so keeping on showing us ever fuller version of that isn't going to prove anything. Now if you were to show us a line like something = dialog.body(something_else) then you might be onto something, but personally I suspect you're going to find that rather hard. I'd be happy to comply. Perhaps I'm mistaken as what I was responding to in the entanglement of responses, but I think I was making a point (again) that the technique by the author works. This should clear matters up completely. Here's the full 80+ lines of the example code. Note wrapped lines. from Tkinter import * import tkSimpleDialog import tkMessageBox class IntVar_GUI: def __init__(self, master): master.title('Control Variable Fun') self.frame = Frame(master,takefocus=1, highlightthickness=2, highlightcolor='blue') self.frame.configure(height=200,width=200) self.frame.pack() #self.frame.bind(KeyPress, self.HandleKey) self.anumber = 123 # Want name and value to be configurable self.master = master menu = Menu(master) master.config(menu=menu) self.mainMenu = Menu(menu) menu.add_cascade(label=My Menu,menu=self.mainMenu) self.mainMenu.add_command(label=Enter Data, command=self.Set_Enter_Data) self.mainMenu.add_command(label=Exit,underline=1,command=self.Quit) self.Focus() def Set_Enter_Data(self): sdict = {} sdict[ ok ] = False sdict[ anumber ] = self.anumber dialog = Enter_Data_Dialog( self.master, sdict ) self.Focus() print Howdy, set data. Number is:, dialog.anumberVar.get() print dict:, dialog.sdict if not dialog.sdict[ok]: return try: self.anumber = int(eval(dialog.anumberVar.get())) print OK except: print Not OK pass print self.anumber:, self.anumber def Quit(self): self.running = False #self.master.quit() self.master.destroy() def Focus( self ): self.frame.focus_set() class
Re: A Dangling Tk Entry
OK, here is a slightly cleaned up version of this horrible code. I did not change too much at one time for fear of confusing you. The main problem is you did not explicitly grid the entry like i told you earlier, and why you are using eval is beyond any measure of sanity... from Tkinter import * import tkSimpleDialog class IntVar_GUI: def __init__(self, master): self.master = master master.title('Control Variable Fun') self.frame = Frame(master, height=200, width=200, takefocus=1, highlightthickness=2, highlightcolor='blue') self.frame.pack() #self.frame.bind(KeyPress, self.HandleKey) self.anumber = 123 # Want name and value to be configurable menu = Menu(master) master.config(menu=menu) self.mainMenu = Menu(menu) menu.add_cascade(label=My Menu,menu=self.mainMenu) self.mainMenu.add_command(label=Enter Data, command=self.Set_Enter_Data) self.mainMenu.add_command (label=Exit,underline=1,command=self.Quit) self.Focus() def Set_Enter_Data(self): sdict = {ok:False, anumber:self.anumber} dialog = Enter_Data_Dialog(self.master, sdict) self.Focus() print Howdy, set data. Number is:, dialog.anumberVar.get() print dict:, dialog.sdict if not dialog.sdict[ok]: return try: self.anumber = int(dialog.anumberVar.get())#why the heck where you using eval here? print OK except: print Not OK pass print self.anumber:, self.anumber def Quit(self): self.running = False #self.master.quit() self.master.destroy() def Focus( self ): self.frame.focus_set() class Enter_Data_Dialog(tkSimpleDialog.Dialog): def __init__(self, parent, sdict): self.sdict = sdict tkSimpleDialog.Dialog.__init__(self, parent) def body(self,master): self.title(Set a Number Entry Dialog) Label( master, text=Number ).grid(row=0, sticky=W) self.anumberVar = StringVar() entry = Entry(master, width=10, textvariable=self.anumberVar) entry.grid(row=0, column=1) #i told you to explicitly grid a widget you want to call later entry.insert(0,11) self.anumberVar.set( %d % self.sdict[anumber] ) return entry def apply(self): self.sdict[ok] = True def Process(): root = Tk() app = IntVar_GUI(root) root.mainloop() if __name__ == __main__: Process() The next message i send will be a rewrite of this code in a proper Pythonic fashion, this frankly is a plate of spaghetti! -- http://mail.python.org/mailman/listinfo/python-list
Re: Menu Interface Problem.
En Tue, 10 Mar 2009 03:48:07 -0200, Paulo Repreza pxrepr...@gmail.com escribió: # Program exits until 'menu_item = 9' while menu_item != 9: print '-' print '1. Print the list.' print '2. Add a name to the list.' print '3. Remove a name from the list.' print '4. Change an item in the list.' print '9. Quit' menu_item = input('Pick an item from the menu: ') # TO-DO for option '1'. if menu_item == 1: input() is rather confusing (and is gone in Python 3). It does two things: - retrieve some text typed by the user - evaluate it as if it were an expresion That means that typing 1+2 works (and will choose option 3), but typing f will raise an exception (there is no f variable). I suggest you forget about input and use raw_input instead: menu_item = raw_input('Pick an item from the menu: ') This returns a string (like '1'). So change all your if statements accordingly: # TO-DO for option '1'. if menu_item == '1': -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
Xah Lee schrieb (and how...) For Google Groups users, there is a kill file implementation for Firefox / Greasemonkey: http://www.penney.org/ggkiller.html hth, Tom -- http://mail.python.org/mailman/listinfo/python-list
error compiling 2.5
I am compiling 2.5 on Solaris 10 SPARC. I edited Modules/Setup to try and enable tkinter. ranlib claims that it cannot find libtk8.4.so even though I have a -L option pointing to it. ranlib libpython2.5.a /usr/sfw/bin/gcc -o python \ Modules/python.o \ libpython2.5.a -lsocket -lnsl -lrt -ldl -L/ opt/csw/lib -ltk8.4 -ltcl8.4 -L/usr/openwin/lib -lX11-L/home/ jonsoons/lib -lz -lm case $MAKEFLAGS in \ *-s*) CC='/usr/sfw/bin/gcc' LDSHARED='/usr/sfw/bin/gcc - shared' OPT='-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes' ./ python -E ./setup.py -q build;; \ *) CC='/usr/sfw/bin/gcc' LDSHARED='/usr/sfw/bin/gcc -shared' OPT='-DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes' ./python -E ./ setup.py build;; \ esac ld.so.1: python: fatal: libtk8.4.so: open failed: No such file or directory Killed make: *** [sharedmods] Error 137 mis /home/jonsoons/Python-2.5.4 # glocate libtk8.4.so /opt/csw/lib/libtk8.4.so mis /home/jonsoons/Python-2.5.4 # file /opt/csw/lib/libtk8.4.so /opt/csw/lib/libtk8.4.so: ELF 32-bit MSB dynamic lib SPARC Version 1, dynamically linked, stripped mis /home/jonsoons/Python-2.5.4 # Did I screw up Modules/Setup? Thanks jon soons -- http://mail.python.org/mailman/listinfo/python-list
RE: Eject a Removable USB drive
def do_magic(): from staples import easy_button result = easy_button.press() return result :) In all seriousness that code did the trick but only after a short delay. I noticed when I first ran it, there was no effect. But when I ran it interactively, it succeeded. Is there any way to check that the drive is still showing up in explorer and then re-run the code? Something like: while drive_exists: shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, F:\\) Right now I've got: time.sleep(1) shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, F:\\) Thanks for your help! -Kyle Rickey -Original Message- From: python-list-bounces+kyle.rickey=bakerhughes@python.org [mailto:python-list-bounces+kyle.rickey=bakerhughes@python.org] On Behalf Of Aaron Brady Sent: Monday, March 09, 2009 6:15 PM To: python-list@python.org Subject: Re: Eject a Removable USB drive On Mar 9, 6:08 pm, Mark Hammond skippy.hamm...@gmail.com wrote: On 10/03/2009 8:20 AM, Rickey, Kyle W wrote: Thanks for the link! That code has got me on the right track. I've almost got it working with one small kink. After the code runs my drive still shows up on Windows Explorer but as a removable drive. If I try to double click on it, it tells me to insert a disk (see screenshot). So it seems my code is unmounting my volume, but not the actual device. Any ideas? I've attached the code I've got so far. Adding the following after your eject code runs: from win32com.shell import shell, shellcon shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, F:\\) seems to work for me (well - I actually did the above interactively after your code ran, and the disk magically vanished from explorer...) Yay, magically! import crystalball? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: A Dangling Tk Entry
Alright try this code. The only thing that i left out was inheriting from Frame, but since i cannot see your entire progam i did not want to do that for fear of breaking some other code. You had a lot of useless code in there and more code that was just a spaghetti mess. If you want to return a dict instead of a tuple like i did feel free :) from Tkinter import * import tkSimpleDialog class EnterDataDialog(tkSimpleDialog.Dialog): def __init__(self, parent, sdict): self.sdict = sdict tkSimpleDialog.Dialog.__init__(self, parent) def body(self, master): self.title(Set a Number) Label( master, text=Number ).grid(row=0, sticky=W) self.v = IntVar() entry = Entry(master, width=10, textvariable=self.v) entry.grid(row=0, column=1) #i told you to explicitly grid a widget you want to call later self.v.set( %d % self.sdict[anumber] ) return entry #return widget that recieves focus def validate(self): try: self.v.get() except: return 0 return 1 def apply(self): self.result = self.v.get() class IntVar_GUI(): def __init__(self, master): self.master = master master.title('Control Variable Fun') frame = Frame(master, height=200, width=200, takefocus=1, highlightthickness=2, highlightcolor='blue') frame.pack() self.anumber = 123 # Want name and value to be configurable menu = Menu(master) master.config(menu=menu) mainMenu = Menu(menu) menu.add_cascade(label=My Menu, menu=mainMenu) mainMenu.add_command(label=Enter Data, command=self.Set_Enter_Data) self.master.protocol(WM_DELETE_WINDOW, self.onQuit) frame.focus_set() def Set_Enter_Data(self): sdict = {anumber:self.anumber} d = EnterDataDialog(self.master, sdict) if d.result: print User Entered: , d.result else: print 'The idiot pressed cancel!' def onQuit(self): self.running = False self.master.destroy() if __name__ == __main__: root = Tk() app = IntVar_GUI(root) root.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
Iain King iaink...@gmail.com wrote: Sort of tangenitally; is there any real difference between the outcome of the two following pieces of code? a = lambda x: x+2 def a(x): return x+2 Disassemble it to see. The functions themselves have identical code bytes, the only difference is the name of the code objects (and that carries through to a difference in the function names). def f(): a = lambda x: x+2 def b(x): return x+2 dis(a) dis(b) from dis import dis dis(f) 2 0 LOAD_CONST 1 (code object lambda at 0119FDA0, file pyshell#10, line 2) 3 MAKE_FUNCTION0 6 STORE_FAST 0 (a) 3 9 LOAD_CONST 2 (code object b at 0119FDE8, file pyshell#10, line 3) 12 MAKE_FUNCTION0 15 STORE_FAST 1 (b) 5 18 LOAD_GLOBAL 0 (dis) 21 LOAD_FAST0 (a) 24 CALL_FUNCTION1 27 POP_TOP 6 28 LOAD_GLOBAL 0 (dis) 31 LOAD_FAST1 (b) 34 CALL_FUNCTION1 37 POP_TOP 38 LOAD_CONST 0 (None) 41 RETURN_VALUE f() 2 0 LOAD_FAST0 (x) 3 LOAD_CONST 0 (2) 6 BINARY_ADD 7 RETURN_VALUE 4 0 LOAD_FAST0 (x) 3 LOAD_CONST 1 (2) 6 BINARY_ADD 7 RETURN_VALUE -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Martin v. Löwis wrote: First, it relies on config.py whose existence msi.py optionally ignores. Feel free to create a patch for that. http://bugs.python.org/issue5467 TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On 2009-03-10, Tim Wintle tim.win...@teamrubber.com wrote: On Mon, 2009-03-09 at 21:28 -0700, Luis Gonzalez wrote: C'mon guys, Xha Lee always wins, because fools like you get mad at him instead of ignoring him. Here here! Hear hear! -- Grant Edwards grante Yow! FROZEN ENTREES may at be flung by members of visi.comopposing SWANSON SECTS ... -- http://mail.python.org/mailman/listinfo/python-list
Re: creating a list of all imported modules
Put this code at the end of your script: import sys info = [(module.__file__, name) for (name, module) in sys.modules.iteritems() if hasattr(module, '__file__')] info.sort() import pprint pprint.pprint(info) AFAIK unless someone has been messing with sys.modules, this gives you all modules that have been imported during the running of your script, except for built-ins (no __file__ attribute). Warning: I've not tried this with eggs and zips. Thanks, exactly what I was lokking for: I added this: additional_mods = [] for i in info: module_path = i[0] substr = '\site-packages' if module_path.find(substr) != -1: additional_mods.append(module_path) pprint.pprint(additional_mods) Unfortunately, it does include more than the actually included module. Eg. if I only import pytz the list also shows: pastescript-1.7.3-py2.5.egg\\paste\\__init__.pyc', pbp.scripts-0.2.5-py2.5.egg\\pbp\\__init__.pyc', pytz-2009a-py2.5.egg\\pytz\\__init__.py', pytz-2009a-py2.5.egg\\pytz\\tzfile.py', pytz-2009a-py2.5.egg\\pytz\\tzinfo.py', rst2pdf-0.9-py2.5.egg\\rst2pdf\\__init__.pyc', traitsgui-3.0.3-py2.5.egg\\enthought\\__init__.pyc', I am sure that pytz does not need pastescript to work... Any idea? -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Matt Nordhoff wrote: Alan G Isaac wrote: Hans Larsen schrieb: How could I take an elemment from a set or a frozenset On 3/8/2009 2:06 PM Diez B. Roggisch apparently wrote: You iterate over them. If you only want one value, use iter(the_set).next() I recall a claim that for result in myset: break is the most efficient way to get one result. Is this right? (It seems nearly the same.) Alan Isaac Checking Python 2.5 on Linux, your solution is much faster, but seeing as they both come in under a microsecond, it hardly matters. It's unexpected... timeit.timeit('res=iter(myset).next()', 'myset=range(100)') 0.8894412399647 timeit.timeit('res=myset.next()', 'myset=range(100); myset=iter(myset)') 0.4916552002516 timeit.timeit('for res in myset: break', 'myset=range(100)') 0.3293300797699 I'd never expect that for-loop assignment is even faster than a precreated iter object (the second test)... but I don't think this for-looping variable leaking behavior is guaranteed, isn't it? Note: the second one exhausts the iter object. -- http://mail.python.org/mailman/listinfo/python-list
PyEval_EvalCode(...) problem
Hi! I have a problem with PyEval_EvalCode(...) I compile the following code and execute them with PyEval_EvalCode (...) class MyClass(mod.Upper): pass register(MyClass) #just the type, not the instance Thats all. So register(...) is a Python C API method so i take the type and store it in a global variable. PyEval_EvalCode(...) returns not NULL and I do not decref the dictionary, just the returnvalue. After PyEval_EvalCode(..) is executed I would like to create an instance of MyClass which crashes because information of the inherited types are corrupt. If I call PyObject_CallObject(obj, NULL) in register(..) where PyEval_EvalCode (..) is still active everything works fine but when I call it after PyEval_EvalCode, even I did not decref anything) its not working. Can anyone of you help me? The refcounts of the MyClass type are 0. Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph Dates and Values
En Tue, 10 Mar 2009 05:08:41 -0200, brianrpsgt1 brianl...@cox.net escribió: I am trying to plot dates and values on a graph using matplotlib. Below is the code. I can run this and it works great, until I get to about 2000 rows from the DB. Things really start to slow down. I have successfully plotted up to 5000 rows from the DB, but it is very slow. I am attempting to plot values for a day, which would be equal to 84600 records. Is there a more efficient may to accomplish this? (isn't it 86400?) for s in value_data: dates = mdates.date2num([s[0]]) plt.plot([dates],[s[1]], 'bo', ms=6) Without looking at the matplotlib docs, the above [] suggests that both date2num and plt.plot take a list of values to act upon, and you're feeding one point at a time. Probably you end up creating one series per point (instead of a single series with many points). I guess something like this should work: x, y = zip(*value_data) # transpose dates = mdates.date2num(x) plt.plot(dates, y, 'bo', ms=6) (totally untested) -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Martin v. Löwis wrote: I also see that it fails to add custom actions into InstallExecuteSequence. I find that puzzling - apparently, it tries to merge the twice. Are you sure you didn't run it twice? It will certainly fail the second time. Just to confirm: I'm certainly only running this once. Still getting the same errors. Log attached for completeness. However, the .msi installs (and Python runs) without issue on a virgin VirtualXP. And it passes the basic test suite ok. This isn't surprising if it's just a case of I've already done that; I'm not doing it again as you suggest. But I'm not sure what's causing it. Not worth worrying about too much, I expect. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: creating a list of all imported modules
En Tue, 10 Mar 2009 12:29:28 -0200, Timmie timmichel...@gmx-topmail.de escribió: Put this code at the end of your script: import sys info = [(module.__file__, name) for (name, module) in sys.modules.iteritems() if hasattr(module, '__file__')] info.sort() import pprint pprint.pprint(info) AFAIK unless someone has been messing with sys.modules, this gives you all modules that have been imported during the running of your script, except for built-ins (no __file__ attribute). Warning: I've not tried this with eggs and zips. Thanks, exactly what I was lokking for: I added this: additional_mods = [] for i in info: module_path = i[0] substr = '\site-packages' if module_path.find(substr) != -1: additional_mods.append(module_path) pprint.pprint(additional_mods) Unfortunately, it does include more than the actually included module. Eg. if I only import pytz the list also shows: pastescript-1.7.3-py2.5.egg\\paste\\__init__.pyc', pbp.scripts-0.2.5-py2.5.egg\\pbp\\__init__.pyc', pytz-2009a-py2.5.egg\\pytz\\__init__.py', pytz-2009a-py2.5.egg\\pytz\\tzfile.py', pytz-2009a-py2.5.egg\\pytz\\tzinfo.py', rst2pdf-0.9-py2.5.egg\\rst2pdf\\__init__.pyc', traitsgui-3.0.3-py2.5.egg\\enthought\\__init__.pyc', I am sure that pytz does not need pastescript to work... It is imported somewhere; look for site.py, sitecustomize.py, PYTHONSTARTUP variable, .pth files... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
MRAB wrote: (lambda arg: arg) == (lambda arg: arg) False curious... I somehow thinked that, whereas (lambda: 0) is (lambda: 0) should be False (obviously) (lambda: 0) == (lambda: 0) could be True... maybe because `{} == {} and {} is not {}` (also for []) -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list
Re: PyEval_EvalCode(...) problem
En Tue, 10 Mar 2009 12:32:00 -0200, googler.1.webmas...@spamgourmet.com escribió: Hi! I have a problem with PyEval_EvalCode(...) I compile the following code and execute them with PyEval_EvalCode (...) class MyClass(mod.Upper): pass register(MyClass) #just the type, not the instance Thats all. So register(...) is a Python C API method so i take the type and store it in a global variable. ...and increment its reference count, of course, because you store a new reference, ok? PyEval_EvalCode(...) returns not NULL and I do not decref the dictionary, just the returnvalue. Which dictionary? The return value should be None, I presume. You should post the code. By far, the most frequent error using the Python API is getting reference counts wrong. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
In comp.lang.lisp Xah Lee xah...@gmail.com wrote: Some people says that i don't participate in discussion, and this is part of the reason they think i'm a so-called ?troll?. Actually i do, and read every reply to my post, as well have replied to technical questions other posted. Most replies to my posts are attacks or trivial (of few sentences) i don't consider worthy to reply. Hmmm. What does that say about your posts? ;-) Actually, short replies need not be, and often aren't, trivial. A few, maybe 10% replies to my unconventional posts, i consider having some value. But if i don't have sufficiently remarkable opinion on what they remarked, i don't reply. Also, if all i wanted to say is ?thanks?, i tend to avoid posting such trivial posts too. Saying thanks isn't trivial. It gives feedback to the other poster, confirming that what he's written has been read by you, and that it is useful, or at least appreciated. It indicates to the group what level of answers is useful to you, what your level of sophistication is. It makes the group work better. if you didn't start your message with ?IMHO?, which indicated to me that at least you are sincere, i would not have replied. (no offense intended) Nearly every Usenet post is an IMHO. This one certainly is. The lack of an explicit IMHO doesn't imply any lack of sincerity. Btw, i'm not some kind of saint. You (guys) do whatever chatty style you want, i write or choose to reply in my abstruse ascetic manners. Just don't accuse when my style is not compatible your drivels. (insult intentional) Ascetic manners! That's wonderful, almost on a par with Sir Robert Armstrong's being economical with the truth. :-) Also, thanks to many supporters over the past years. Hey, you're not going away, are you? Xah -- Alan Mackenzie (Nuremberg, Germany). -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
En Tue, 10 Mar 2009 13:00:18 -0200, Vito De Tullio zak.mc.kra...@libero.it escribió: MRAB wrote: (lambda arg: arg) == (lambda arg: arg) False curious... I somehow thinked that, whereas (lambda: 0) is (lambda: 0) should be False (obviously) (lambda: 0) == (lambda: 0) could be True... maybe because `{} == {} and {} is not {}` (also for []) Neither {} nor [] have any attributes by their own; people is only interested in their contents. Even a bare object() (that has no attributes) compare unequal to another instance: py object() == object() False But functions (and lambda is just syntactic sugar for an anonymous function) have many attributes: __dict__, func_dict __doc__, func_doc __module__ __name__, func_name func_closure func_code func_defaults func_globals '==' should compare all of them, and hash() should take them into account too... Too much effort just for the very few cases when two functions actually would compare equal - and, who cares? -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph Dates and Values
On Mar 10, 7:40 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 10 Mar 2009 05:08:41 -0200, brianrpsgt1 brianl...@cox.net escribió: I am trying to plot dates and values on a graph using matplotlib. Below is the code. I can run this and it works great, until I get to about 2000 rows from the DB. Things really start to slow down. I have successfully plotted up to 5000 rows from the DB, but it is very slow. I am attempting to plot values for a day, which would be equal to 84600 records. Is there a more efficient may to accomplish this? (isn't it 86400?) for s in value_data: dates = mdates.date2num([s[0]]) plt.plot([dates],[s[1]], 'bo', ms=6) Without looking at the matplotlib docs, the above [] suggests that both date2num and plt.plot take a list of values to act upon, and you're feeding one point at a time. Probably you end up creating one series per point (instead of a single series with many points). I guess something like this should work: x, y = zip(*value_data) # transpose dates = mdates.date2num(x) plt.plot(dates, y, 'bo', ms=6) (totally untested) -- Gabriel Genellina Gabriel :: Thanks for the notes. That is exactly what I thought the problem was. Here is an update. I put a limit to 100 on the SQL Query to test. When I run your code, I get the data returned, however, I get the same return equal to the limit I set. In other words, when I run with a limit of 100, I get the same result 100 times. Which would mean that when I try to run a whole day (86400 :) - it was late!), I am getting the same result 86400 times and then it is tyring to plot that. Output below: [ 733414.06489583 733414.06490741 733414.06491898 733414.06493056 733414.06494213 733414.0649537 733414.06496528 733414.06497685 733414.06498843 733414.065 733414.06501157 733414.06502315 733414.06503472 733414.0650463 733414.06505787 733414.06506944 733414.06508102 733414.06509259 733414.06510417 733414.06511574 733414.06512731 733414.06513889 733414.06515046 733414.06516204 733414.06517361 733414.06518519 733414.06519676 733414.06520833 733414.06521991 733414.06523148 733414.06524306 733414.06525463 733414.0652662 733414.06527778 733414.06528935 733414.06530093 733414.0653125 733414.06532407 733414.06533565 733414.06534722 733414.0653588 733414.06537037 733414.06538194 733414.06539352 733414.06540509 733414.06541667 733414.06542824 733414.06543981 733414.06545139 733414.06546296 733414.06547454 733414.06548611 733414.06549769 733414.06550926 733414.06552083 733414.06553241 733414.06554398 733414.0656 733414.06556713 733414.0655787 733414.06559028 733414.06560185 733414.06561343 733414.065625 733414.06563657 733414.06564815 733414.06565972 733414.0656713 733414.06568287 733414.06569444 733414.06570602 733414.06571759 733414.06572917 733414.06574074 733414.06575231 733414.06576389 733414.06577546 733414.06578704 733414.06579861 733414.06581019 733414.06582176 733414.0658 733414.06584491 733414.06585648 733414.06586806 733414.06587963 733414.0658912 733414.06590278 733414.06591435 733414.06592593 733414.0659375 733414.06594907 733414.06596065 733414.06597222 733414.0659838 733414.06599537 733414.06600694 733414.06601852 733414.06603009 733414.06604167] (95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 94, 94, 94, 94, 94, 94, 94, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, 94) If I run this code: for s in value_data: x = mdates.date2num([s[0]]) y = [s[1]] print [x, y] The results returned are the following: There are 100 rows in the database [ 733414.06489583] [95] [ 733414.06490741] [95] [ 733414.06491898] [95] [ 733414.06493056] [95] [ 733414.06494213] [95] [ 733414.0649537] [95] [ 733414.06496528] [95] [ 733414.06497685] [95] [ 733414.06498843] [95] [ 733414.065] [95] [ 733414.06501157] [95] [ 733414.06502315] [95] [ 733414.06503472] [95] [ 733414.0650463] [95] [ 733414.06505787] [95] [ 733414.06506944] [95] [ 733414.06508102] [95] [ 733414.06509259] [95] [ 733414.06510417] [95] [ 733414.06511574] [95] [ 733414.06512731] [95] [ 733414.06513889] [95] [ 733414.06515046] [95] [ 733414.06516204] [95] [ 733414.06517361] [95] [ 733414.06518519] [95] [ 733414.06519676] [95] [ 733414.06520833] [95] [ 733414.06521991] [95] [ 733414.06523148] [95] [ 733414.06524306] [95] [ 733414.06525463] [95] [ 733414.0652662] [95] [ 733414.06527778] [95] [ 733414.06528935] [95] [ 733414.06530093] [95] [ 733414.0653125] [95] [ 733414.06532407] [95] [ 733414.06533565] [95] [ 733414.06534722] [95] [ 733414.0653588] [95] [ 733414.06537037] [95] [ 733414.06538194]
Re: Candidate for a new itertool
On Mar 9, 6:55 pm, Raymond Hettinger pyt...@rcn.com wrote: [prueba] The data often contains objects with attributes instead of tuples, and I expect the new namedtuple datatype to be used also as elements of the list to be processed. But I haven't found a nice generalized way for that kind of pattern that aggregates from a list of one datatype to a list of key plus output datatype that would make it practical and suitable for inclusion in the standard library. Looks like you've searched the possibilities thoroughly and no one aggregation function seems to meet all needs. That's usually a cue to not try to build one and instead let simple python loops do the work for you (that also saves the awkward itemgetter() calls in your examples). To my eyes, all three examples look like straight-forward, easy-to-write, easy-to-read, fast plain python: d = defaultdict(int) for color, n, info in data: ... d[color] += n d.items() [('blue', 6), ('yellow', 3), ('red', 4)] d = defaultdict(list) for color, n, info in data: ... d[color].append(n) d.items() [('blue', [5, 1]), ('yellow', [3]), ('red', [2, 2])] d = defaultdict(set) for color, n, info in data: ... d[color].add(n) d.items() [('blue', set([1, 5])), ('yellow', set([3])), ('red', set([2]))] I don't think you can readily combine all three examples into a single aggregator without the obfuscation and awkwardness that comes from parameterizing all of the varying parts: def aggregator(default_factory, adder, iterable, keyfunc, valuefunc): d = defaultdict(default_factory) for record in iterable: key = keyfunc(record) value = valuefunc(record) adder(d[key], value) return d.items() aggregator(list, list.append, data, itemgetter(0), itemgetter(1)) [('blue', [5, 1]), ('yellow', [3]), ('red', [2, 2])] aggregator(set, set.add, data, itemgetter(0), itemgetter(1)) [('blue', set([1, 5])), ('yellow', set([3])), ('red', set([2]))] Yuck! Plain Python wins. Raymond P.S. The aggregator doesn't work so well for: aggregator(int, operator.iadd, data, itemgetter(0), itemgetter(1)) [('blue', 0), ('yellow', 0), ('red', 0)] The problem is that operator.iadd() doesn't have a way to both retrieve and store back into a dictionary. Yes thinking about this more, one probably needs to have two code paths depending if the type returned by default_factory is mutable or immutable. But you are probably right that the ratio of redundancy/ variability is pretty low for such a function and the plain written out for loop is not too painful. The only redundancy is the creation and manipulation of the dictionary and the explicit looping. -- http://mail.python.org/mailman/listinfo/python-list
Re: A Dangling Tk Entry
Down, Fang! Down, boy. Down. -- Soupy Sales, Comedian, talking to his imaginary animal, circa 1960. Thank you very much. One more quote before I continue. A favorite. The trouble with most folks isn't their ignorance. It's knowin' so many things that ain't so. by Josh Billings, a 19th century humorist (and not Mark Twain). I could quote my wife next, but I'll skip it. As I believe I've repeatedly said, (aren't those interesting words? Sort of sound huffy, don't they?), I am not the author of the code. If I didn't mention it before, I am not about to wholesale change his code for the purposes I have at hand, so I try to remain faithful to what was written. As far as taking your grid suggestions, I believe I did, very likely in the 2000 lines of father code (the author's original code.) For whatever reason, they didn't work. Yes, even I am as a lowly newcomer to Python and Tkinter have heard the eval story. Again, I do not want diversions while I'm adding to this program. Just to be clear about what I'm adding, the program needed, IMHO, a configuration file. I've already added a menu item in other parts of the code to save it, and to initialize the 'global' values the author uses in IntVar_GUI. That's the alias here for Sentinel_GUI in the big program. Now I can proceed to initialize the dialog and others without using control variables. This config effort I could have skipped, but thought it's now or never. I have things to add to the program that are way more interesting than this, and will have big payoffs to the users (a closed group of about 40 users). Despite my no messing with code technique policy, I may have to take into consideration some of your changes here, and your follow up. And, yes, I think I can now begin to tune up my geometry knowledge of Tkinter. So again, thanks for your help. (I hope you don't mind my repetition here.) :-) r wrote: OK, here is a slightly cleaned up version of this horrible code. I did not change too much at one time for fear of confusing you. The main problem is you did not explicitly grid the entry like i told you earlier, and why you are using eval is beyond any measure of sanity... from Tkinter import * import tkSimpleDialog class IntVar_GUI: def __init__(self, master): self.master = master master.title('Control Variable Fun') self.frame = Frame(master, height=200, width=200, takefocus=1, highlightthickness=2, highlightcolor='blue') self.frame.pack() #self.frame.bind(KeyPress, self.HandleKey) self.anumber = 123 # Want name and value to be configurable menu = Menu(master) master.config(menu=menu) self.mainMenu = Menu(menu) menu.add_cascade(label=My Menu,menu=self.mainMenu) self.mainMenu.add_command(label=Enter Data, command=self.Set_Enter_Data) self.mainMenu.add_command (label=Exit,underline=1,command=self.Quit) self.Focus() def Set_Enter_Data(self): sdict = {ok:False, anumber:self.anumber} dialog = Enter_Data_Dialog(self.master, sdict) self.Focus() print Howdy, set data. Number is:, dialog.anumberVar.get() print dict:, dialog.sdict if not dialog.sdict[ok]: return try: self.anumber = int(dialog.anumberVar.get())#why the heck where you using eval here? print OK except: print Not OK pass print self.anumber:, self.anumber def Quit(self): self.running = False #self.master.quit() self.master.destroy() def Focus( self ): self.frame.focus_set() class Enter_Data_Dialog(tkSimpleDialog.Dialog): def __init__(self, parent, sdict): self.sdict = sdict tkSimpleDialog.Dialog.__init__(self, parent) def body(self,master): self.title(Set a Number Entry Dialog) Label( master, text=Number ).grid(row=0, sticky=W) self.anumberVar = StringVar() entry = Entry(master, width=10, textvariable=self.anumberVar) entry.grid(row=0, column=1) #i told you to explicitly grid a widget you want to call later entry.insert(0,11) self.anumberVar.set( %d % self.sdict[anumber] ) return entry def apply(self): self.sdict[ok] = True def Process(): root = Tk() app = IntVar_GUI(root) root.mainloop() if __name__ == __main__: Process() The next message i send will be a rewrite of this code in a proper Pythonic fashion, this frankly is a plate of spaghetti! -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A Dangling Tk Entry
On Mar 10, 10:52 am, W. eWatson notval...@sbcglobal.net wrote: [snip: biting the hand that feeds] This is not the first time you have come to c.l.py with hat in hand seeking help and then scoffed at suggestions made by well respected posters. I should have known you would just do the same again. I don't know what you want but help is defiantly not it although that is exactly what you need! If I didn't mention it before, I am not about to wholesale change his code for the purposes I have at hand, so I try to remain faithful to what was written. As far as taking your grid suggestions, I believe I did, very likely in the 2000 lines of father code (the author's original code.) For whatever reason, they didn't work. Yes, even I am as a lowly newcomer to Python and Tkinter have heard the eval story. Again, I do not want diversions while I'm adding to this program. [snip: non-sensical rambling] You think my changes where wholesale. I untangled your spaghetti code and showed you how it should be done with the same output you originally had(while at the same time trying hard not to confuse you by making the code too perfect), only unlike your mess, my code doesn't throw 10 exceptions. There is nothing in there that will break compatibility with your code, heck you said it was broken to start. Just to be clear about what I'm adding, the program needed, IMHO, a configuration file. I've already added a menu item in other parts of the code to save it, and to initialize the 'global' values the author uses in IntVar_GUI. That's the alias here for Sentinel_GUI in the big program. Now I can proceed to initialize the dialog and others without using control variables. This config effort I could have skipped, but thought it's now or never. I have things to add to the program that are way more interesting than this, and will have big payoffs to the users (a closed group of about 40 users). If this 80 line code you posted actually is a line by line copy paste from your suposedly high and mighty original author's code, you would be much better off trashing this garbage and starting from scratch, because apparently he had no idea what he was doing either. Using naming conventions like IntVar_GUI instead of IntVarGui, and Enter_Data_Dialog instead of EnterDataDialog . Not to mention this redundant stupidity sdict = {} sdict[ ok ] = False sdict[ anumber ] = self.anumber Only a complete noob would do something like that! Not to mention that he created a Focus method that calls one line of code. This is a classic case of the blind leading the blind. good day pal... and oh yea, good luck! -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph Dates and Values
En Tue, 10 Mar 2009 13:32:10 -0200, brianrpsgt1 brianl...@cox.net escribió: On Mar 10, 7:40 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 10 Mar 2009 05:08:41 -0200, brianrpsgt1 brianl...@cox.net escribió: I am trying to plot dates and values on a graph using matplotlib. Below is the code. I can run this and it works great, until I get to about 2000 rows from the DB. Things really start to slow down. I have successfully plotted up to 5000 rows from the DB, but it is very slow. I am attempting to plot values for a day, which would be equal to 84600 records. Is there a more efficient may to accomplish this? Without looking at the matplotlib docs, the above [] suggests that both date2num and plt.plot take a list of values to act upon, and you're feeding one point at a time. Probably you end up creating one series per point (instead of a single series with many points). I guess something like this should work: x, y = zip(*value_data) # transpose dates = mdates.date2num(x) plt.plot(dates, y, 'bo', ms=6) Thanks for the notes. That is exactly what I thought the problem was. Here is an update. I put a limit to 100 on the SQL Query to test. When I run your code, I get the data returned, however, I get the same return equal to the limit I set. In other words, when I run with a limit of 100, I get the same result 100 times. Which would mean that when I try to run a whole day (86400 :) - it was late!), I am getting the same result 86400 times and then it is tyring to plot that. Output below: [ 733414.06489583 733414.06490741 733414.06491898 733414.06493056 ... 733414.06600694 733414.06601852 733414.06603009 733414.06604167] (95, 95, 95, 95, ... 95, 95, 95, 94) If I run this code: for s in value_data: x = mdates.date2num([s[0]]) y = [s[1]] print [x, y] The results returned are the following: There are 100 rows in the database [ 733414.06489583] [95] [ 733414.06490741] [95] [ 733414.06491898] [95] [ 733414.06493056] [95] ... [ 733414.06600694] [95] [ 733414.06601852] [95] [ 733414.06603009] [95] [ 733414.06604167] [94] Well, both look the same values to me... what's wrong? Why do you say the same results 100 times. Oh, the code fragment I posted is suposed to *replace* the original for loop. Don't put it inside a loop. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: parallel/concurrent process in python
On Mon, Mar 9, 2009 at 2:47 PM, ommer.sim...@gmail.com wrote: I'm trying to figure out parallel process python code. Something similar to fork funtion in C. For example, I using sniff tool in scapy to capture packets but i want this to run in the background: --- from scapy.all import * import subprocess import netsnmp pkts=sniff(iface=eth0,filter=UDP,count=100) # This should run in the background print Next Code.' - Next Code. should be printed out right away and does not have to wait for pkts=sniff(...) to finish. Any ideas? Why not use os.fork(), it is the same as C's fork? if os.fork(): # Returns 0 to child, non-zero to parent # Do parent stuff else: # Do child stuff -- Thanks, Minesh Patel -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Tim Golden wrote: However, the .msi installs (and Python runs) without issue on a virgin VirtualXP. And it passes the basic test suite ok. I lied. test_zipfile fails because the new(ish) zipdir.zip doesn't get carried across to the install. Patched in: http://bugs.python.org/issue5470 A couple of other tests fail (test_platform test_pep352) when running regrest, but I can't get them to fail otherwise. TJG -- http://mail.python.org/mailman/listinfo/python-list
can python import class or module directly from a zip package
can python import class or module directly from a zip package ,just like jave does from jar package without extracting the class file into directory so far as i know ,python module should be unzip to file system in order to use them, -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentations and future evolution of languages
Kay Schluehr wrote: On 6 Mrz., 02:53, bearophileh...@lycos.com wrote: This is an interesting post, it shows me that fitness plateau where design of Python syntax lives is really small, you can't design something just similar: http://unlimitednovelty.com/2009/03/indentation-sensitivity-post-mort... Living on a small fitness plateau isn't good, even if it's very high, because it's evolutionary unstable :-( Indentation-wise Haskell syntax seems one of the very few local maxima that is close enough to the little fitness plateau where Python is. Bye, bearophile Here is a somewhat longer comment: http://fiber-space.de/wordpress/?p=121 Take it with a grain of salt and have much fun. Python already has nested functions. So anything for which you really need a lambda function can already be done. You just have to name the function. This isn't a popular feature, because in a language with no declarations to determine scope, having too many nested scopes is confusing. But it's there. As for Python indentation, that seems to work reasonably well. The only complaint I have there is that mixing tabs and spaces for indentation should be detected and treated as a syntax error. (Whether to use tabs or spaces is a religious argument, but mixing them is clearly wrong, and results in non-visible bugs. CPython should enforce that.) John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: can python import class or module directly from a zip package
Flank wrote: can python import class or module directly from a zip package Yes, just put the .zip file into your PYTHONPATH. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentations and future evolution of languages
John The only complaint I have there is that mixing tabs and spaces for John indentation should be detected and treated as a syntax error. Guido's time machine strikes again (fixed in Python 3.x): % python3.0 ~/tmp/mixed.py File /home/titan/skipm/tmp/mixed.py, line 3 print(a) ^ TabError: inconsistent use of tabs and spaces in indentation Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: [!! SPAM] can python import class or module directly from a zip package
Flank wrote: can python import class or module directly from a zip package ,just like jave does from jar package without extracting the class file into directory so far as i know ,python module should be unzip to file system in order to use them, -- http://mail.python.org/mailman/listinfo/python-list See http://peak.telecommunity.com/DevCenter/PythonEggs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Graph Dates and Values
On Mar 10, 9:44 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 10 Mar 2009 13:32:10 -0200, brianrpsgt1 brianl...@cox.net escribió: On Mar 10, 7:40 am, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 10 Mar 2009 05:08:41 -0200, brianrpsgt1 brianl...@cox.net escribió: I am trying to plot dates and values on a graph using matplotlib. Below is the code. I can run this and it works great, until I get to about 2000 rows from the DB. Things really start to slow down. I have successfully plotted up to 5000 rows from the DB, but it is very slow. I am attempting to plot values for a day, which would be equal to 84600 records. Is there a more efficient may to accomplish this? Without looking at the matplotlib docs, the above [] suggests that both date2num and plt.plot take a list of values to act upon, and you're feeding one point at a time. Probably you end up creating one series per point (instead of a single series with many points). I guess something like this should work: x, y = zip(*value_data) # transpose dates = mdates.date2num(x) plt.plot(dates, y, 'bo', ms=6) Thanks for the notes. That is exactly what I thought the problem was. Here is an update. I put a limit to 100 on the SQL Query to test. When I run your code, I get the data returned, however, I get the same return equal to the limit I set. In other words, when I run with a limit of 100, I get the same result 100 times. Which would mean that when I try to run a whole day (86400 :) - it was late!), I am getting the same result 86400 times and then it is tyring to plot that. Output below: [ 733414.06489583 733414.06490741 733414.06491898 733414.06493056 ... 733414.06600694 733414.06601852 733414.06603009 733414.06604167] (95, 95, 95, 95, ... 95, 95, 95, 94) If I run this code: for s in value_data: x = mdates.date2num([s[0]]) y = [s[1]] print [x, y] The results returned are the following: There are 100 rows in the database [ 733414.06489583] [95] [ 733414.06490741] [95] [ 733414.06491898] [95] [ 733414.06493056] [95] ... [ 733414.06600694] [95] [ 733414.06601852] [95] [ 733414.06603009] [95] [ 733414.06604167] [94] Well, both look the same values to me... what's wrong? Why do you say the same results 100 times. Oh, the code fragment I posted is suposed to *replace* the original for loop. Don't put it inside a loop. -- Gabriel Genellina Gabriel :: Thank you very much!!! That was it, I had it in the loop. I works great now!! Graphs are coming up right away. B -- http://mail.python.org/mailman/listinfo/python-list
Re: parallel/concurrent process in python
Why not use os.fork(), it is the same as C's fork? os.fork is not cross platform. It is *nix only. Subprocess runs on Windows also. The OP never specified his platform. -Corey -- http://mail.python.org/mailman/listinfo/python-list
Re: last and final attempt to search for python ods library.
Hi John, I tryed this same library to begin with. python-ooolib is very good except that it misses a major feature of cell merging (spanning ). That is the point from which I started the thread. I even thought the author of that library will respond back but did not happen. Seams it is a very old library and no development happens on it. happy hacking. Krishnakant. On Tue, 2009-03-10 at 23:44 +1100, John Machin wrote: On 10/03/2009 10:35 PM, Krishnakant wrote: any ways thanks for your reply, Right now I am stuck very badly. The problem is that I am trying python-ooolib and did find the library pritty good. There's another one called ooolib-python; have you had a look at that? Can you provide the url? Actually I think I saw this library but it seems it is not well maintained and the author is no more active. I think it is supporting old formats if I am talking about the same library. So please send me the link so that I confirm my doubts. http://ooolib.sourceforge.net/ calls it ooolib-python, but in topsy-turvy land (http://packages.debian.org/unstable/python/python-ooolib) it's called python-ooolib but all you need in the end is import ooolib. Three are one and one is three :-) -- http://mail.python.org/mailman/listinfo/python-list
[JOB] Short-term python programming consultant - funds expire soon!
Dear Pythonistas, Our open-source software project (PyDSTool) has money to hire an experienced Python programmer on a short-term, per-task basis as a technical consultant (i.e., no fringe benefits offered). The work can be done remotely and will be paid after the satisfactory completion of the objectives. The work must be completed by the end of April, when the current funds expire. The basic work plan and design documents are already laid out from previous work on these tasks, but the finer details will be negotiable. We plan to pay approximately $2-3k per task, depending on the exact code design and amount of time required. Prospective consultants could be professionals or students but must have proven experience with SWIG and both python and numpy distutils, and be willing to write a short document about the completed work for future maintenance purposes. We have a template for a simple contract and invoices can be relatively coarse-grained. As an open-source project, all contributed code will be BSD licensed as part of our project, although it will retain attribution of your authorship. We have two objectives for this work, which could be satisfied by two individual consultants but more likely by one: (1) This objective involves completing the implementation of automated compilation of C code into DLLs. These DLLs are dynamically created from a user's specification in python. The DLLs can be updated and reloaded if the user changes specifications at the python level. This functionality is crucial to providing fast solving of differential equations using legacy solvers written in C and Fortran. This functionality is relatively independent from the inner workings of our project so there should be minimal overhead to completing this task. We need to complete the integration of an existing code idea for this objective with the main trunk of our project. The existing code works as a stand-alone test for our C legacy solver but is not completed for our Fortran legacy solver (so that numpy's distutils needs to be used instead of python distutils) and needs to be integrated into the current SVN trunk. The design document and implementation for the C solver should be a helpful template for the Fortran solver. (2) We need a setup.py package installer for our project that automatically compiles the static parts of the legacy differential equation solvers during installation according to the directory structure and SWIG/distutils implementation to be completed in objective (1). If the consultant is experienced with writing python package installers, he/she may wish to negotiate working on a more advanced system such as an egg installer. PyDSTool (pydstool.sourceforge.net) is a multi-platform, open-source environment offering a range of library tools and utilities for research in dynamical systems modeling for scientists and engineers. Please contact Dr. Rob Clewley (rclewley) at (@) the Department of Mathematics, Georgia State University (gsu.edu) for more information. -- Robert H. Clewley, Ph.D. Assistant Professor Department of Mathematics and Statistics and Neuroscience Institute Georgia State University 720 COE, 30 Pryor St Atlanta, GA 30303, USA tel: 404-413-6420 fax: 404-413-6403 http://www2.gsu.edu/~matrhc http://brainsbehavior.gsu.edu/ -- http://mail.python.org/mailman/listinfo/python-list
Re: A Dangling Tk Entry
r wrote: On Mar 10, 10:52 am, W. eWatson notval...@sbcglobal.net wrote: [snip: biting the hand that feeds] This is not the first time you have come to c.l.py with hat in hand seeking help and then scoffed at suggestions made by well respected posters. I should have known you would just do the same again. I don't know what you want but help is defiantly not it although that is exactly what you need! If I didn't mention it before, I am not about to wholesale change his code for the purposes I have at hand, so I try to remain faithful to what was written. As far as taking your grid suggestions, I believe I did, very likely in the 2000 lines of father code (the author's original code.) For whatever reason, they didn't work. Yes, even I am as a lowly newcomer to Python and Tkinter have heard the eval story. Again, I do not want diversions while I'm adding to this program. [snip: non-sensical rambling] You think my changes where wholesale. I untangled your spaghetti code and showed you how it should be done with the same output you originally had(while at the same time trying hard not to confuse you by making the code too perfect), only unlike your mess, my code doesn't throw 10 exceptions. There is nothing in there that will break compatibility with your code, heck you said it was broken to start. Just to be clear about what I'm adding, the program needed, IMHO, a configuration file. I've already added a menu item in other parts of the code to save it, and to initialize the 'global' values the author uses in IntVar_GUI. That's the alias here for Sentinel_GUI in the big program. Now I can proceed to initialize the dialog and others without using control variables. This config effort I could have skipped, but thought it's now or never. I have things to add to the program that are way more interesting than this, and will have big payoffs to the users (a closed group of about 40 users). If this 80 line code you posted actually is a line by line copy paste from your suposedly high and mighty original author's code, you would be much better off trashing this garbage and starting from scratch, because apparently he had no idea what he was doing either. Using naming conventions like IntVar_GUI instead of IntVarGui, and Enter_Data_Dialog instead of EnterDataDialog . Not to mention this redundant stupidity sdict = {} sdict[ ok ] = False sdict[ anumber ] = self.anumber Only a complete noob would do something like that! Not to mention that he created a Focus method that calls one line of code. This is a classic case of the blind leading the blind. good day pal... and oh yea, good luck! Pardon me, it was White Fang. -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: parallel/concurrent process in python
On Mar 10, 10:06 am, Minesh Patel min...@gmail.com wrote: On Mon, Mar 9, 2009 at 2:47 PM, ommer.sim...@gmail.com wrote: I'm trying to figure out parallel process python code. Something similar to fork funtion in C. For example, I using sniff tool in scapy to capture packets but i want this to run in the background: --- from scapy.all import * import subprocess import netsnmp pkts=sniff(iface=eth0,filter=UDP,count=100) # This should run in the background print Next Code.' - Next Code. should be printed out right away and does not have to wait for pkts=sniff(...) to finish. Any ideas? Why not use os.fork(), it is the same as C's fork? if os.fork(): # Returns 0 to child, non-zero to parent # Do parent stuff else: # Do child stuff -- Thanks, Minesh Patel Thanks,It works perfectly. -- http://mail.python.org/mailman/listinfo/python-list
Re: A parser for S.W.I.F.T. MT940 Files (for banking transactions)
On Mar 10, 3:09 am, andrew cooke and...@acooke.org wrote: a month is more than enough - i would expect to have something in a week. if possible, a data size of 1GB or more would be useful, but A gigabyte of SWIFT messages as test data? please remember that this is a best efforts attempt only. i have no previous experience with this file format, or with banking data, and the result will come with no warranty. you may want to continue to investigate other solutions. i have no idea what your final application is, but you should at the very least test any parser (and related libraries) thoroughly before using it in a critical application. Like sending a few million dollars over the wire around the world? -- http://mail.python.org/mailman/listinfo/python-list
Re: Determining from which web page a cgi script is invoked?
davidgo...@davidgould.com escribió: Given a webpage test.html that has a form with a cgi script, how can you determine inside the cgi script the name of the webpage that invoked the script? I have many different html pages that use a common cgi script for form processing and want to determine the name of the webpage. quickdirty: Add a hidden form var with the page/form name Regards, Carlos. -- http://mail.python.org/mailman/listinfo/python-list
Re: PyEval_EvalCode(...) problem
http://rafb.net/p/Uyb5Ps45.html Pelase note, when I call PyObject_CallObject(...) in the wrapped C register(..) method it works fine. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Mar 9, 6:37 pm, Wolfgang Rohdewald wolfg...@rohdewald.de wrote: On Montag, 9. März 2009, r wrote: Long answer: 'Ye%s' %'s'*1000 simplified long answer: 'Yes' * 1000 ♦ Sure that works too but sounds like your stu..stu..studdering. or did you mean 'Ye%s' %('s'*1000) ♦ Oops, must test snippets before submitting :) -- http://mail.python.org/mailman/listinfo/python-list
Re: a potential pep to extend the syntax of for loops
pang wrote: This idea has already been proposed and rejected. But discuss away as you wish ;=). tjr Where is that? py-dev and/or python-ideas lists within last year I didn't see any related pep's. Though helpful, not too many people write PEPs to document rejections. Could you post a link? Sorry, no. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Lie Ryan wrote: I recall a claim that for result in myset: break is the most efficient way to get one result. I'd never expect that for-loop assignment is even faster than a precreated iter object (the second test)... but I don't think this for-looping variable leaking behavior is guaranteed, isn't it? It is an intentional, documented feature: Names in the target list are not deleted when the loop is finished, but if the sequence is empty, it will not have been assigned to at all by the loop. -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Terry Reedy tjre...@udel.edu writes: I'd never expect that for-loop assignment is even faster than a precreated iter object (the second test)... but I don't think this for-looping variable leaking behavior is guaranteed, isn't it? It is an intentional, documented feature: ... I prefer thinking of it as a documented bug. It is fixed in 3.x. I usually avoid the [... for x in xiter] listcomp syntax in favor of list(... for x in xiter) just as an effort to be a bit less bug-prone. -- http://mail.python.org/mailman/listinfo/python-list
Re: a potential pep to extend the syntax of for loops
Sorry, no. tjr well, thank you Even now it's difficult to find the discussion, but at least I know about python-ideas. Thanks to all that replied. -- http://mail.python.org/mailman/listinfo/python-list
Re: Packaging Survey
Hi Tarek, I'm an academic. What do I put down for Q #1? ;) (I put down pro developer) --t On Mon, Mar 09, 2009 at 06:44:02AM +0100, Tarek Ziad? wrote: - The Python Langage Summit is coming up. To prepare this event, I have - put online a survey you can take to tell us a bit more about you and - how you package your Python applications. - - * Who should take the survey : any Python developer that packages - and distributes his code, no matter how. - * Take the survey: http://tinyurl.com/package-survey - - Thanks to all the people that helped building the survey, and a - special thanks to Massimo Di Pierro who created the application that - runs the Survey and helped me to set this up. - - Regards - Tarek - -- - Tarek Ziad? | Association AfPy | www.afpy.org - Blog FR | http://programmation-python.org - Blog EN | http://tarekziade.wordpress.com/ - -- - http://mail.python.org/mailman/listinfo/python-announce-list - - Support the Python Software Foundation: - http://www.python.org/psf/donations.html - -- C. Titus Brown, c...@msu.edu -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Tue, 10 Mar 2009 01:15:19 -0400, Lew wrote: s...@netherlands.com wrote: On Mon, 09 Mar 2009 22:08:54 -0400, Lew no...@lewscanon.com wrote: Larry Gates wrote: For me, the worst thing is when I'm programming, and a bug *actually* gets on my monitor. In real life, I'm this tough person: a rugged tradesmen. I'm so phobic of bugs that I'll run away screaming like a girl. I had a smudge on my monitor some years ago. It was on the frame, not the screen itself, but visible on the side. The person next to me pointed at it, ^ He said: I work so close to you we must be telemarketers, does my body odor bother you? Uh ... There's nothing quite as Europaen as B.O. Europe: where they have the means to use soap but not the inclination. -- larry gates I'm not consistent about consistency, you see, except when I am... And I try to believe six foolish consistencies before breakfast each day. :-) -- Larry Wall in 20050307164019.ga14...@wall.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Eject a Removable USB drive
On 11/03/2009 12:39 AM, Rickey, Kyle W wrote: def do_magic(): from staples import easy_button result = easy_button.press() return result :) In all seriousness that code did the trick but only after a short delay. I noticed when I first ran it, there was no effect. But when I ran it interactively, it succeeded. Is there any way to check that the drive is still showing up in explorer and then re-run the code? Something like: It is possible to register for device removal notifications - it's possible you need to wait until Windows reports the ejection process is complete before sending the shell notification. Cheers, Mark while drive_exists: shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, F:\\) Right now I've got: time.sleep(1) shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, F:\\) Thanks for your help! -Kyle Rickey -Original Message- From: python-list-bounces+kyle.rickey=bakerhughes@python.org [mailto:python-list-bounces+kyle.rickey=bakerhughes@python.org] On Behalf Of Aaron Brady Sent: Monday, March 09, 2009 6:15 PM To: python-list@python.org Subject: Re: Eject a Removable USB drive On Mar 9, 6:08 pm, Mark Hammondskippy.hamm...@gmail.com wrote: On 10/03/2009 8:20 AM, Rickey, Kyle W wrote: Thanks for the link! That code has got me on the right track. I've almost got it working with one small kink. After the code runs my drive still shows up on Windows Explorer but as a removable drive. If I try to double click on it, it tells me to insert a disk (see screenshot). So it seems my code is unmounting my volume, but not the actual device. Any ideas? I've attached the code I've got so far. Adding the following after your eject code runs: from win32com.shell import shell, shellcon shell.SHChangeNotify(shellcon.SHCNE_DRIVEREMOVED, shellcon.SHCNF_PATH, F:\\) seems to work for me (well - I actually did the above interactively after your code ran, and the disk magically vanished from explorer...) Yay, magically! import crystalball? -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Paul Rubin wrote: Terry Reedy tjre...@udel.edu writes: I'd never expect that for-loop assignment is even faster than a precreated iter object (the second test)... but I don't think this for-looping variable leaking behavior is guaranteed, isn't it? It is an intentional, documented feature: ... I prefer thinking of it as a documented bug. It is fixed in 3.x. Nope to both. We are talking about for-loop statements. -- http://mail.python.org/mailman/listinfo/python-list
Python 2.7 MSI / pywin32 snapshots [was: Windows install to custom location ...]
Scott David Daniels wrote: Tim Golden wrote: ... Anyhow, at the end I have a working Python 2.7a0 running under Windows. Do you mean 3.1a0? As far as I know, 2.7a0 requires the use of the time machine, as it is expected to be 3 months out. If you do get an installer built, even having a semi-official copy around for those of us not on the MS compiler upgrade train to do a little alpha (and/or beta) testing as well. I've uploaded a couple of installers here: http://timgolden.me.uk/python/downloads/snapshots/ Currently, there's the Python Subversion trunk (py2.7) and the corresponding pywin32, built from the latest CVS. I believe I've got everything in there, altho' the platform test was failing irreproducibly when I last looked. I'm building the py3k branch now, so if there are no problems I'll upload that later tonight. Please take them for a spin and let me know if they work. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentations and future evolution of languages
On Tue, Mar 10, 2009 at 12:39 PM, s...@pobox.com wrote: John The only complaint I have there is that mixing tabs and spaces for John indentation should be detected and treated as a syntax error. Guido's time machine strikes again (fixed in Python 3.x): % python3.0 ~/tmp/mixed.py File /home/titan/skipm/tmp/mixed.py, line 3 print(a) ^ TabError: inconsistent use of tabs and spaces in indentation Or just use the '-tt' command line switch to force indentation consistency: ksm...@work:~/tmp [366]$ python2.5 -tt mixed.py File mixed.py, line 6 print a ^ TabError: inconsistent use of tabs and spaces in indentation Kurt -- http://mail.python.org/mailman/listinfo/python-list
Re: [JOB] Short-term python programming consultant - funds expire soon!
Rob Clewley wrote: Dear Pythonistas, Our open-source software project (PyDSTool) has money to hire an experienced Python programmer on a short-term, per-task basis as a technical consultant (i.e., no fringe benefits offered) Please see http://www.python.org/community/jobs/ for where to post this most effectively. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentations and future evolution of languages
2009/3/8 Tim Roberts t...@probo.com: Tim Rowe digi...@gmail.com wrote: I don't think the article is right that it's silly to have some expression/statement groupings indentation based and some grouped by enclosing tokens -- provided it's done right. The OCAML-based language F# accepts OCAML enclosing tokens, but if you mark the groups with indentation they're not necessary (but still legal). That seems to me to work pretty cleanly. Boy, I really want to like F# -- a lot of smart people have worked on it -- but every program I write is completely incomprehensible to me a week later. The more I look around, the more I like Python. Indentation works just fine in Python, too, just in case anybody hadn't noticed ;-) My point was that Python isn't alone on that whitespace-significant plateau. F# is up here too. And so is FORTRAN, of course. We try to ignore FORTRAN, but the distance we are able to edge away from it goes to show how big the plateau is. -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
Re: creating a list of all imported modules
On Mar 11, 1:29 am, Timmie timmichel...@gmx-topmail.de wrote: Put this code at the end of your script: import sys info = [(module.__file__, name) for (name, module) in sys.modules.iteritems() if hasattr(module, '__file__')] info.sort() import pprint pprint.pprint(info) AFAIK unless someone has been messing with sys.modules, this gives you all modules that have been imported during the running of your script, except for built-ins (no __file__ attribute). Warning: I've not tried this with eggs and zips. Thanks, exactly what I was lokking for: I added this: additional_mods = [] for i in info: module_path = i[0] substr = '\site-packages' if module_path.find(substr) != -1: additional_mods.append(module_path) pprint.pprint(additional_mods) Unfortunately, it does include more than the actually included module. Eg. if I only import pytz the list also shows: pastescript-1.7.3-py2.5.egg\\paste\\__init__.pyc', pbp.scripts-0.2.5-py2.5.egg\\pbp\\__init__.pyc', pytz-2009a-py2.5.egg\\pytz\\__init__.py', pytz-2009a-py2.5.egg\\pytz\\tzfile.py', pytz-2009a-py2.5.egg\\pytz\\tzinfo.py', rst2pdf-0.9-py2.5.egg\\rst2pdf\\__init__.pyc', traitsgui-3.0.3-py2.5.egg\\enthought\\__init__.pyc', I am sure that pytz does not need pastescript to work... Any idea? has imported != needed to import ... I've see a module that imported Tkinter and never used it. BTW, what gives you the surety that third-party modules can only be imported from a path that includes site packages? What gives you the surety that you need to import all modules whose path does not include site-packages? Perhaps you should scrutinise *all* of the loaded- from-file entries in sys.modules. -- http://mail.python.org/mailman/listinfo/python-list
ipython / vs \ in readline on MS Windows (and ipython help grepper)
Q1/ I run a standard python ditribution with ipython and readline under cygwin. The tab filename completion works fine in the OS (bash shell) as expected, and tab filename completion at the ipython command line works, but with MS style path separators (backslash: run examples \test.py) which the run command itself interprets unix style ERROR: File `examplestest.py` not found. Also Q2/ can I less or grep the output from help(my_fun) Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] IPython 0.8.4 -- An enhanced Interactive Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
I think the point is that function objects compare by object identity, so the two lambdas you use above are not equal even though they have the same code. it raises an interesting question about why doesn't it. I can think of practical answers to that, obviously, but in principle, if a function compiles to exactly the same byte code, you obviously do not need two copies of it, and like strings shouldn't an identical function have the same id? This is merely philosophical, I don't see the value in making this so (a slight optimizaton and perhaps better conformity to other python features), but I do think it's an interesting question. cheers. -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
Craig Allen callen...@gmail.com writes: it raises an interesting question about why doesn't it. I can think of practical answers to that, obviously, but in principle, if a function compiles to exactly the same byte code, you obviously do not need two copies of it, and like strings shouldn't an identical function have the same id? Identical strings don't necessarily have the same id: a = a*1000 b = a*1000 id(a),id(b) (137143648, 137144680) a==b True -- http://mail.python.org/mailman/listinfo/python-list
Question about xml.com
Dear all, I have loaded an xml file into xmldoc. I would have expected that print commandlet.childNodes[0].toxml() would contain the content but that's only at print commandlet.childNodes[1].toxml() The same for print commandlet.childNodes[2].toxml() Why are commandlet.childNodes[0] and commandlet.childNodes[2] empty? Thanks in advance! J print xmldoc.firstChild.toxml() 0.1 Beta test just a test somebody linux2 0 3.19 commandlet=xmldoc.firstChild print commandlet.firstChild.toxml() print commandlet.childNodes[0].toxml() print commandlet.childNodes[1].toxml() 0.1 Beta test just a test somebody linux2 0 3.19 print commandlet.childNodes[2].toxml() print commandlet.childNodes[3].toxml() -- http://mail.python.org/mailman/listinfo/python-list
Re: a potential pep to extend the syntax of for loops
En Tue, 10 Mar 2009 18:28:10 -0200, pang pablo.ang...@uam.es escribió: Even now it's difficult to find the discussion, but at least I know about python-ideas. Try http://blog.gmane.org/gmane.comp.python.ideas -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Number Sequencing, Grouping and Filtering
On Mar 10, 9:07 pm, Chris Rebert c...@rebertia.com wrote: On Tue, Mar 10, 2009 at 3:00 AM, flebber flebber.c...@gmail.com wrote: On Mar 10, 8:54 pm, flebber flebber.c...@gmail.com wrote: Hi I was hoping someone would be able to point me in the direction of some good documentation regarding sequencing, grouping and filtering and in which order they should be done. As a small example it is easy to create the range of numbers 1 to 20. But if I wanted to group all possible combinations of sets of 4 numbers within this range is there already an in uilt function for this I am searching the module docs with number sequencing and number grouping but cannot find info. Then if I wanted to refine this results further eg no consecutive numbers to be contained in sets. Is it best to create all sets and then filter the sets for things matching this criteria or to set this condition in a creation. Creating sets and then filtering would soon become unwieldy with a larger range I would imagine.. An ideas, pointers to docs or better search terms to help me explore this further would be appreciated. Thanks Sayth I have just found itertools is this acheivable using combinations() and groupby() in itertools? Yes; indeed, those were the functions your post brought to mind and which led me to suggest itertools. Cheers, Chris -- I have a blog:http://blog.rebertia.com the only issue i can see is that i am using python 2.54 currently as ifelt it more supported by other programs than 2.6 or 3.0. After searching it seems that itertools has had a upgrade in 2.61 -- http://mail.python.org/mailman/listinfo/python-list
Re: Is python worth learning as a second language?
On Mar 9, 12:43 am, ZikO ze...@op.pl wrote: Hi I hope I won't sound trivial with asking my question. I am a C++ programmer and I am thinking of learning something else because I know second language might be very helpful somehow. I have heard a few positive things about Python but I have never writen any single line in python so I do not know this language at all. Do you think python would be good complementary language for C++? Do you think it's worth learning it or let's say try Java? and how difficult it would be for me if I know C++ pretty well I would say? Thanks I'm not even going to read the replies first because I have my own. I was a C and C++ programmer exclusively for over a decade. During that time I had a whatever tool for the problem approach to language selection but C++ continued to be the best for the sort of thing I was doing. During that time I continued to learn other languages at least enough to consider them. I appreciated the role of interpreted languages were filling, but also never felt comfortable in them. Python, imo, is an excellent language to learn as a C++ programmer. It is relatively easy to extend with C/C++ and so works together well. When you find yourself writing some configuration language, you'll be able to use python instead. Also, I have found that Python helped open my mind a bit about object orientation and to realize that while the compile-time decisions in C++ are great for the C/C++ linking model, and provides a certain sort of power and control, that it also really does (as many had complained to me) take a few blows at how you really want OO to work. So I love python's OO and things which can be done structurally in C++ (like metaclass programming) but with which the C++ syntax is not cooperative, and which is very much harder to safely extend modularity too (I could go into detail but why bother here, it's either already clear what I mean or isn't that important)... Finally, Python is a multiparadigmed language, like C++. It very much seems to believe in Bjarne's original trust the programmer outlook on languages. As a C++ programmer I enjoyed the responsibility and power of choosing one's paradigms at the outset of a project. Such choices are best made consciously, one learns a lot about their project and develops a lot of philosophical standards for the design and implementation by having to think first what models and programming paradigms will we adopt. It makes you think what sort of code you will be writing often, and which idioms will be efficient and maintainable. Honestly, I've become more of a Python fan than I am really comfortable with... it can't be as good as I think. -craig -- http://mail.python.org/mailman/listinfo/python-list
Re: ipython / vs \ in readline on MS Windows (and ipython help grepper)
More info: import readline ? readline c:\python25\lib\site-packages\ipython\rlineimpl.py $Id: Magic.py 1096 2006-01-28 20:08:02Z vivainio $ sys.platform 'win32' sys.getfilesystemencoding() 'mbcs' sys.winver '2.5' $more /usr/local/bin/ipython #!/bin/bash C:/Python25/python.exe C:\Python25\scripts\ipython -pylab $* (Same problem if I use the windows Start menu Ipython IPython and pysh) On Mar 11, 7:34 am, bdb112 boyd.blackw...@gmail.com wrote: Q1/ I run a standard python ditribution with ipython and readline under cygwin. The tab filename completion works fine in the OS (bash shell) as expected, and tab filename completion at the ipython command line works, but with MS style path separators (backslash: run examples \test.py) which the run command itself interprets unix style ERROR: File `examplestest.py` not found. Also Q2/ can I less or grep the output from help(my_fun) Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] IPython 0.8.4 -- An enhanced Interactive Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: parallel/concurrent process in python
os.fork is not cross platform. It is *nix only. Subprocess runs on Windows also. The OP never specified his platform. Just out of curiosity, how is one able to replace an os.fork() call with subprocess and have the child execute multiple statements? I typically see subprocess used for spawning a shell command, piping, etc... -- Thanks, Minesh Patel -- http://mail.python.org/mailman/listinfo/python-list
Re: Why is lambda allowed as a key in a dict?
it raises an interesting question about why doesn't it. I can think of practical answers to that, obviously, but in principle, if a function compiles to exactly the same byte code, you obviously do not need two copies of it, and like strings shouldn't an identical function have the same id? Having the same code is certainly not sufficient for the functions to compare the same: py def a(x): ... return 3*x ... py def b(x): ... return 4*x ... py a.func_code.co_code == b.func_code.co_code True So they do have the same byte code, namely: py dis.dis(a) 2 0 LOAD_CONST 1 3 LOAD_FAST0 6 BINARY_MULTIPLY 7 RETURN_VALUE The difference is what constant 1 means: 3 in one case, and 4 in the other. So they should have the constants also to compare the same, right? Those above don't: py a.func_code.co_code == b.func_code.co_code and a.func_code.co_consts == b.func_code.co_consts False Now, you could also ask that many other code attributes should be the same, such as co_argcount, co_stacksize, co_varnames, ... If you ask that *all* code attributes are the same, you find a good reason why the code objects shouldn't compare the same: they might have different values for co_filename, or, if those are the same, different values for co_firstlineno. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list