Re: How to define a db file for sqlite?
On Mar 8, 6:32 pm, Muddy Coder cosmo_gene...@yahoo.com wrote: Hi Folks, I just downloaded and installed pysqlite, and I can import sqlite3 smoothly. Then, I need to connect sqlite by syntax: conn = sqlite3.connect('adirectory/db') I wish the data will be stored into directory --- adirectory, with a file named in db. But I got kicked out with an error message as: Unable to open database file I wonder: does pysqlite open a database file db for me? Yes, provided that adirectory exists and you have write permission. It won't make a directory for you. Same applies to open('adirectory/ db', 'wb') Ensure that adirectory exists, and try it again. If that fails, try the open() -- you may get a more informative error message. Or, do I need to create an empty file inside adirectory with my text editor? No. However, try that and remember what happens. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
Grant Edwards gra...isi.com wrote: There you go: a 30-second psychological diagnosis by an electrical engineer based entirely on Usenet postings. It doesn't get much more worthless than that... Oh it is not entirely worthless - as a working hypothesis, it seems to cover and explain the observed facts, so it should be accepted until a simpler theory comes along. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing unicode (devanagari) text with xml.dom.minidom
Regarding minidom, you might be happier with the xml.etree package that comes with Python2.5 and later (it's also avalable for older versions). It's a lot easier to use, more memory friendly and also much faster. OTOH, choice of XML library is completely irrelevant for the issue at hand. If the OP is happy with minidom, we shouldn't talk him into using something else. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython fast and slow
On Mar 6, 6:52 pm, Mike Driscoll kyoso...@gmail.com wrote: ... Can you post a sample application so we can try to figure out what's wrong? You might also cross-post this to thewxPythonmailing list. They might know. Mike- Hide quoted text - - Show quoted text - Hi, thanks for your reply Here is a sample application: -- import wx import time class My_frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Moving panel') self.surface = p = wx.Panel(self, size=(300, 130)) self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30)) self.square.Bind(wx.EVT_PAINT, self.on_paint_square) btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0)) self.Bind(wx.EVT_BUTTON, self.move_panel, btn_move) self.Fit() def move_panel(self, evt): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x for x in gen(): self.square.SetPosition((x, 30)) time.sleep(0.005) def on_paint_square(self, evt): square = evt.GetEventObject() dc = wx.BufferedPaintDC(square) dc.Pen = wx.Pen('blakc', 2) dc.Brush = wx.Brush('light blue') dc.DrawRectangle(0, 0, *square.GetSize()) app = wx.PySimpleApp() My_frame().Show() app.MainLoop() -- Press the button and the panel moves to the right and then back to the left. While PyScripter is running the panel moves at a certain speed. You can run the application from the Windows explorer with the same speed. You don't need to run it from PyScripter. When PyScripter is closed, the application runs much less quickly. I experienced this on two PC-s. Maybe this behavior is not even related to wxPython but to the sleep command. I don't know... Thanks iu2 -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up reading files (possibly with cython)
per wrote: i have a program that essentially loops through a textfile file thats about 800 MB in size containing tab separated data... my program parses this file and stores its fields in a dictionary of lists. for line in file: split_values = line.strip().split('\t') # do stuff with split_values currently, this is very slow in python, even if all i do is break up each line using split() and store its values in a dictionary, indexing by one of the tab separated values in the file. is this just an overhead of python that's inevitable? do you guys think that switching to cython might speed this up, perhaps by optimizing the main for loop? or is this not a viable option? For the general approach and the overall speed of your program it does matter what you want to do with the data once you've read it -- can you tell us a bit about that? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing/Crawler Questions - solution
On Mar 7, 9:56 pm, bruce bedoug...@earthlink.net wrote: and this solution will somehow allow a user to create a web parsing/scraping app for parising links, and javascript from a web page? not just parsing the links and the static javascript, but: * actually executing the javascript, giving the quotes page quotes a chance to actually _look_ like it would if it was being viewed as a quotes real quotes web browser. so any XMLHTTPRequests will _actually_ get executed, _actually_ result in _actually_ having the content of the web page _properly_ modified. so, e.g instead of seeing a Loader page on gmail you would _actually_ see the user's email and the adverts (assuming you went to the trouble of putting in the username/password) because the AJAX would _actually_ get executed by the WebKit engine, and the DOM model accessed thereafter. * giving the user the opportunity to call DOM methods such as getElementsByTagName and the opportunity to access properties such as document.anchors. in webkit-glib gdom bindings, that would be: * anchor_list = gdom_document_get_elements_by_tag_name(doc, a); or * g_object_get(doc, anchors, anchor_list, NULL); which in pywebkitgtk (thanks to python-pygobject auto-generation of python bindings from gobject bindings) translates into: * doc.get_elements_by_tag_name(a) or * doc.props.anchors which in pyjamas-desktop, a high-level abstraction on top of _that_, turns into: * from pyjamas import DOM anchor_list = DOM.getElementsByTagName(doc, a) or * from pyjamas import DOM anchor_list = DOM.getAttribute(doc, anchors) answer: yes. l. -Original Message- From: python-list-bounces+bedouglas=earthlink@python.org [mailto:python-list-bounces+bedouglas=earthlink@python.org]on Behalf Oflkcl Sent: Saturday, March 07, 2009 2:34 AM To: python-l...@python.org Subject: Re: Parsing/Crawler Questions - solution On Mar 7, 12:19 am, rounderwe...@gmail.com wrote: So, it sounds like your update means that it is related to a specific url. I'm curious about this issue myself. I've often wondered how one could properly crawl anAJAX-ish site when you're not sure how quickly the data will be returned after the page has been. you want to look at the webkit engine - no not the graphical browser - the ParseTree example - and combine it with pywebkitgtk - no not the original version, the one which has DOM-manipulation bindings through webkit-glib. the webkit parse tree example is, despite it being based on the GTK port as they like to call it in webkit (which just means that it links with GTK not QT4 or wxWidgets), is a console-based application. in other words, despite it being GTK, it still does NOT output graphical crap to the screen, yet it still *executes* the javascript on the page. dummy functions for mouse, keyboard, console errors are given as examples and are left as an exercise for the application writer to fill-in-the-blanks. combining this parse tree example with pywebkitgtk (see demobrowser.py) would provide a means by which web pages can be executed AT THE CONSOLE NOT AS A GUI APP, then, thanks to the glib / gobject bindings, a python app will be able to walk the DOM tree as expected. i _just_ fixed pyjamas-desktop's iterators in the pyjamas.DOM module for someone, on the pyjamas-dev mailing list. http://github.com/lkcl/pyjamas-desktop/tree/8ed365b89efe5d1d3451c3e3c... dd014540 so, actually, you may be better off starting from pyjamas-desktop and then cutting out the fire up the GTK window bit, from pyjd.py. pyjd.py is based on pywebkitgtk's demobrowser.py the alternative to webkit is to use python-hulahop - it will do the same thing, but just using python bindings to gecko instead of python- bindings-to-glib-bindings-to-webkit. l. --http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing unicode (devanagari) text with xml.dom.minidom
Martin v. Löwis wrote: Regarding minidom, you might be happier with the xml.etree package that comes with Python2.5 and later (it's also avalable for older versions). It's a lot easier to use, more memory friendly and also much faster. OTOH, choice of XML library is completely irrelevant for the issue at hand. For the described problem, maybe. But certainly not for the application. The background was parsing the XML dump of an entire web site, which I would expect to be larger than what minidom is designed to handle gracefully. Switching to cElementTree before major code gets written is almost certainly a good idea here. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
Xah Lee xah...@gmail.com writes: Of interest: • Why Can't You Be Normal? http://xahlee.org/Netiquette_dir/why_cant_you_be_normal.html • Ban Xah Lee http://xahlee.org/Netiquette_dir/ban_Xah_Lee.html I consider this post relevant because i've been perennially gossiped about in comp.lang.* groups today and in the past 5 or 10 years, many of the threads mentioning my name are not started by me nor did i ever participate. Plain text version one of the above article follows. --- Ban Xah Lee Xah Lee, 2009-03-07 This page is a short collection of online communities that banned me, in a way that i don't consider just. It illustrates the political nature among the tech geeking males. HARASSMENT BY JOHN BOKMA I was harassed by a newsgroup poster John Bokma (a regular of comp.lang.perl.misc) to have my web hosting service provider kick me off. This happened in 2006. Summary: I was posting relevant but controversial opinions in a rude manner to “comp.lang.*” newsgroups. I was using Google's newsgroup service to post it, and has nothing to do with my web hosting service provider, other than my signature containing my website or links to relevant articles on my website. However, this guy digs up my web hosting provider, and lobbied people to send complains to kick me off. Detailed account: DreamHost.com and A Incidence of Harassment WIKIPEDIA My Wikipedia account P0lyglut is banned by Wikipedia admins in ~2008-06 for a month or so. Summary: i was editing articles on Tibet, Human sacrifice, Dalai Lama, citing info from Chinese historian Li Ao, and was fighting with those who revert me in a non-conformal way. They banned me for editing, and subsequently banned me from editing my talk page, and removed the defense i gave on my talk page. The original reason for reverting my editing was that i linked to my own website (which contains the collected videos of Li Ao's program on youtube, with English translation and summary). Subsequently, because i did not behave in a way that seems “polite” to them, and kept on fighting, the reason they cited to ban me was spreading propaganda. For some account of this incident, see bottom of: Why Can't You Be Normal?. The fighting and discussion can be seen on my talk page, at: User talk:P0lyglut. The writing where i defended my edit, that got removed from my talk page, is here: Wikipedia User talk:P0lyglut ... 2008-07. Local copy of these at: Wikipedia_ban_2008-06.zip. FREENODE IRC EMACS CHANNEL I'm banned on Freenode's irc emacs channel since about 2006-10, and the ban was never lifted as of 2009-03. The ban is primarily, and single-handedly executed by John Sullivan (aka johnsu01). Some detail: Emacs Irc Channel Ban On Xah Lee. HACKER NEWS “Hacker News” website, at http://news.ycombinator.com/, banned me around 2009-02 or earlier. Someone posted a question about why some sites seem to be banned, titled “Ask PG- What is the list of banned sites and why are they banned”. He asked for reasons or a public list. The url is at Source. (local archive: Hacker_News_xahlee.org_ban.zip) Then, someone posted the list of domains/sub-domains that are banned, which contains my site “xahlee.org”. No explicit reason is given. It appears to me, it was banned because one of my essay: Why Software Suck, has been submitted to the site in 2009-02, then in the discussion, someone mentioned i am a troll, then admin placed my site on ban. There are other bans that i consider unjust. This page is a start to list them. I'll try to add more when i have time. Don't worry, Xah. At least, my minds is running on your rails. Please do not stop. BTW, what do you think about using Gnus instead of G2/1.0? Sincerely, -- Byung-Hee HWANG b...@izb.knu.ac.kr ∑INTERNET: URL:http://izb.knu.ac.kr/~bh/ -- http://mail.python.org/mailman/listinfo/python-list
help with printing to stdout...
Hi, I've got a program here that prints out a percentage of it's completion. Currently with my implimentation it prints like this: 0% 1% 2% 3% 4% etc taking up lots and lots of lines of output... So, how can I make it write the percentage on the same line eg. while working: print percent every time the line print percent is ran it should delete the old percentage from the screen, replacing it with the new one, so as to only use up one line... Basically I'm just printing a string of text to the screen and every time my print command is ran I would like the old text to be removed and my new text added (talking about the one line of the screen here)... This is a command line program, under linux... Thanks, Daniel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing unicode (devanagari) text with xml.dom.minidom
For the described problem, maybe. But certainly not for the application. The background was parsing the XML dump of an entire web site, which I would expect to be larger than what minidom is designed to handle gracefully. Switching to cElementTree before major code gets written is almost certainly a good idea here. I think minidom is designed to handle the very same documents taht cElementTree is designed to handle (namely, documents that fit into memory). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: help with printing to stdout...
On Sun, Mar 8, 2009 at 1:37 AM, Daniel Dalton d.dal...@iinet.net.au wrote: Hi, I've got a program here that prints out a percentage of it's completion. Currently with my implimentation it prints like this: 0% 1% 2% 3% 4% etc taking up lots and lots of lines of output... So, how can I make it write the percentage on the same line eg. while working: print percent Use the carriage return character to overwrite the line (you'll need to forego `print`): from sys import stdout while working: stdout.write('\r'+percent) Note that you'll need to ensure that `percent` has constant length throughout the loop. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
comparing (c)ElementTree and minidom (was: Parsing unicode (devanagari) text with xml.dom.minidom)
Martin v. Löwis wrote: The background was parsing the XML dump of an entire web site, which I would expect to be larger than what minidom is designed to handle gracefully. Switching to cElementTree before major code gets written is almost certainly a good idea here. I think minidom is designed to handle the very same documents taht cElementTree is designed to handle (namely, documents that fit into memory). I do not doubt that a machine running a cElementTree application can handle exactly the same documents as a machine with, say, ten times as much memory that runs a minidom application. However, when deciding which library to choose for a new application, it does matter what hardware you want to use it on. And if you can handle multiple times larger documents on the same hardware, that might be as much of reason to choose cElementTree as the (likely) shorter and more readable code (which usually translates into shorter development and debugging times) and the higher execution speed. Honestly, I haven't seen a reason in a while why preferring minidom over any of the ElementTree derivates would be a good idea when starting a new application. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up reading files (possibly with cython)
On Mar 7, 3:06 pm, per perfr...@gmail.com wrote: hi all, i have a program that essentially loops through a textfile file thats about 800 MB in size containing tab separated data... my program parses this file and stores its fields in a dictionary of lists. When building a very large structure like you're doing, the cyclic garbage collector can be a bottleneck. Try disabling the cyclic garbage collector before building the large dictionary, and re- enabling it afterwards. import gc gc.disable() try: for line in file: split_values = line.strip().split('\t') # do stuff with split_values finally: gc.enable() Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython fast and slow
On Mar 8, 1:52 am, iu2 isra...@elbit.co.il wrote: On Mar 6, 6:52 pm, Mike Driscoll kyoso...@gmail.com wrote: ... Can you post a sample application so we can try to figure out what's wrong? You might also cross-post this to thewxPythonmailing list. They might know. Mike- Hide quoted text - - Show quoted text - Hi, thanks for your reply Here is a sample application: -- import wx import time class My_frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Moving panel') self.surface = p = wx.Panel(self, size=(300, 130)) self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30)) self.square.Bind(wx.EVT_PAINT, self.on_paint_square) btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0)) self.Bind(wx.EVT_BUTTON, self.move_panel, btn_move) self.Fit() def move_panel(self, evt): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x for x in gen(): self.square.SetPosition((x, 30)) time.sleep(0.005) def on_paint_square(self, evt): square = evt.GetEventObject() dc = wx.BufferedPaintDC(square) dc.Pen = wx.Pen('blakc', 2) dc.Brush = wx.Brush('light blue') dc.DrawRectangle(0, 0, *square.GetSize()) app = wx.PySimpleApp() My_frame().Show() app.MainLoop() -- Press the button and the panel moves to the right and then back to the left. While PyScripter is running the panel moves at a certain speed. You can run the application from the Windows explorer with the same speed. You don't need to run it from PyScripter. When PyScripter is closed, the application runs much less quickly. I experienced this on two PC-s. Maybe this behavior is not even related to wxPython but to the sleep command. I don't know... It's not a good idea to call time.sleep inside a loop inside an event handler, which is what you are doing here. wx has a mechanism to call some sort of callback at timed intervals. (I don't know what it is but I know it has one.) Instead of animating the box move inside the button callback, have it request that a callback be called after x seconds pass, and draw a single frame inside that callback. Then invoke it again until you're done drawing. Here's a rough idea of what that might look like: class My_frame(wx.Frame): # ... among other things ... def move_panel(self,evt): self.square_pos = 0 wx.set_timed_callback_of_some_sort( self.draw_frame,0.005) def draw_frame(self): self.square.SetPosition((self.square_pos, 30)) self.square_pos += 1 if self.square_pos 200: wx.set_timed_callback_of_some_sort( self.draw_frame,0.005) As for why it works fine in PyScripter but not when started from Explorer, well, let's just say that when you abuse callbacks like you did, you shouldn't expect reasonable behavior. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Help cleaning up some code
odeits wrote: On Mar 7, 1:07 pm, Scott David Daniels scott.dani...@acm.org wrote: odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another contraint saying that all of the ni have to be the same. Well, the obvious way to get your constraint is by changing your SQL, but if you are going to do it by fetching rows, try: FIELDS = 'ni adid rundateid rundate city state status'.split() ni = UNSET = object() # use None unless None might be the value stack = [] rows = self.con.execute(adquerystring, (user,STACK_SIZE)).fetchall() for row in rows: ad = dict() for field in FIELDS: ad[field] = row[field] for field in 'city', 'state': if ad[field] is None: ad[field] = 'None' if ni != ad['ni']: if ni is UNSET: ni = ad['ni'] else: break stack.append(ad) --Scott David Daniels scott.dani...@acm.org Taking from several suggestions this is what i have come up with for now: for row in ifilter(lambda r: r['ni'] == rows[0]['ni'],rows): not sure what version of python you're using, but it would be more natural in recent python to write that as: for row in (r for r in rows if r['ni'] == rows[0]['ni']): (the () create a generator for you). andrew ad = dict() keys = row.keys() # if python 2.6 keys = ['ni','adid','rundateid','rundate','city','state','status'] # if python 2.5 for index in row.keys(): if row[index] is None: ad[index] = 'None' else: ad[index] = row[index] stack.append(ad) print row the test to see if the ad is valid is placed in the ifilter so that I dont build the dictionary unnecessarily. and the None special case is fairly simple to read now. The None case would even be irrelevant if i could get the damn xmlrpc to allow null. sigh. anyhow. thanks for all of your input, it is definitely better than it was ;) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Help cleaning up some code
andrew cooke wrote: odeits wrote: On Mar 7, 1:07 pm, Scott David Daniels scott.dani...@acm.org wrote: odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another contraint saying that all of the ni have to be the same. Well, the obvious way to get your constraint is by changing your SQL, but if you are going to do it by fetching rows, try: FIELDS = 'ni adid rundateid rundate city state status'.split() ni = UNSET = object() # use None unless None might be the value stack = [] rows = self.con.execute(adquerystring, (user,STACK_SIZE)).fetchall() for row in rows: ad = dict() for field in FIELDS: ad[field] = row[field] for field in 'city', 'state': if ad[field] is None: ad[field] = 'None' if ni != ad['ni']: if ni is UNSET: ni = ad['ni'] else: break stack.append(ad) --Scott David Daniels scott.dani...@acm.org Taking from several suggestions this is what i have come up with for now: for row in ifilter(lambda r: r['ni'] == rows[0]['ni'],rows): not sure what version of python you're using, but it would be more natural in recent python to write that as: for row in (r for r in rows if r['ni'] == rows[0]['ni']): or even just for row in rows: if row['ni'] == rows[0]['ni']: (unfortunately it seems that putting that on a single line is not valid syntax) andrew (the () create a generator for you). andrew ad = dict() keys = row.keys() # if python 2.6 keys = ['ni','adid','rundateid','rundate','city','state','status'] # if python 2.5 for index in row.keys(): if row[index] is None: ad[index] = 'None' else: ad[index] = row[index] stack.append(ad) print row the test to see if the ad is valid is placed in the ifilter so that I dont build the dictionary unnecessarily. and the None special case is fairly simple to read now. The None case would even be irrelevant if i could get the damn xmlrpc to allow null. sigh. anyhow. thanks for all of your input, it is definitely better than it was ;) -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up reading files (possibly with cython)
If that's the problem, the solution is: get more memory. Or maybe think about algorithm, which needs less memory... My experience tells me, that each time when you want to store a lot of data into dict (or other structure) to analyze it then, you can find a way not to store so much amount of data %) -- http://mail.python.org/mailman/listinfo/python-list
Re: /a is not /a ?
Mel wrote: wrote: Steven D'Aprano st...@pearwood.info writes: It is never correct to avoid using is when you need to compare for identity. When is it ever necessary to compare for identity? Ho-hum. MUDD game. def broadcast (sender, message): for p in all_players: if p is not sender: p.tell (message)# don't send a message to oneself Since in a MUD game, a player would always have a unique username, I'd rather compare with that. It doesn't rely on some internals. There is very, very rare case where 'is' is really, really needed. -- http://mail.python.org/mailman/listinfo/python-list
Re: /a is not /a ?
Robert Kern wrote: On 2009-03-07 08:14, Christian Heimes wrote: Steven D'Aprano wrote: Yes. Floating point NANs are required to compare unequal to all floats, including themselves. It's part of the IEEE standard. As far as I remember that's not correct. It's just the way C has interpreted the standard and Python inherited the behavior. But you may proof me wrong on that. Mark, you are the expert on IEEE 754. Steven is correct. The standard defines how boolean comparisons like ==, !=, , etc. should behave in the presence of NaNs. Table 4 on page 9, to be precise. The rationale behind the standard was because NaN can be returned by many distinct operations, thus one NaN may not be equal to other NaN. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with printing to stdout...
On Sun, 8 Mar 2009 01:59:03 -0800 Chris Rebert c...@rebertia.com wrote: etc taking up lots and lots of lines of output... So, how can I make it write the percentage on the same line eg. Use the carriage return character to overwrite the line (you'll need to forego `print`): Why do you say that? from sys import stdout while working: stdout.write('\r'+percent) while working: print '\r'+percent, Note that you'll need to ensure that `percent` has constant length throughout the loop. Nope. You just need to make sure that it never gets shorter which is the case here. If it wasn't then: while working: print '\r'+percent+' ', -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: help with printing to stdout...
Daniel Dalton d.dal...@iinet.net.au wrote: I've got a program here that prints out a percentage of it's completion. Currently with my implimentation it prints like this: 0% 1% 2% 3% 4% etc taking up lots and lots of lines of output... So, how can I make it write the percentage on the same line eg. while working: print percent every time the line print percent is ran it should delete the old percentage from the screen, replacing it with the new one, so as to only use up one line... Basically I'm just printing a string of text to the screen and every time my print command is ran I would like the old text to be removed and my new text added (talking about the one line of the screen here)... This is a command line program, under linux... Play with the following: put a comma after the print, like this: print percent,#This keeps it on the same line Then put a carriage return at the start, like this: print '\r',percent, or like this: print '\r'+str(percent), Then make sure it gets sent out, like this: sys.stdout.flush() Alternatively, you can play with backspaces instead of the carriage return: print '\b\b\b\b', print percent, sys.stdout.flush() And see what happens. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: help with printing to stdout...
Chris Rebert wrote: On Sun, Mar 8, 2009 at 1:37 AM, Daniel Dalton d.dal...@iinet.net.au wrote: Hi, I've got a program here that prints out a percentage of it's completion. Currently with my implimentation it prints like this: 0% 1% 2% 3% 4% etc taking up lots and lots of lines of output... So, how can I make it write the percentage on the same line eg. while working: print percent Use the carriage return character to overwrite the line (you'll need to forego `print`): from sys import stdout while working: stdout.write('\r'+percent) Note that you'll need to ensure that `percent` has constant length throughout the loop. or erase the previous character first with whitespace stdout.write('\r\r%s%%' % percent). curse might be more reliable for this kind of thing (though it is definitely an overkill) Note: \r doesn't work on IDLE -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Sun, 08 Mar 2009 18:38:24 +0900 Byung-Hee HWANG b...@izb.knu.ac.kr wrote: Xah Lee xah...@gmail.com writes: [snip] Don't worry, Xah. At least, my minds is running on your rails. Please do not stop. BTW, what do you think about using Gnus instead of G2/1.0? So you are going to repeat his postings in their entirety so that those that block him will see them anyway, right? Wrong. We'll just block your posts too. *plonk* -- D'Arcy J.M. Cain da...@druid.net | Democracy is three wolves http://www.druid.net/darcy/| and a sheep voting on +1 416 425 1212 (DoD#0082)(eNTP) | what's for dinner. -- http://mail.python.org/mailman/listinfo/python-list
Re: speeding up reading files (possibly with cython)
Steven D'Aprano wrote: per wrote: currently, this is very slow in python, even if all i do is break up each line using split() ** and store its values in a dictionary, ** indexing by one of the tab separated values in the file. If that's the problem, the solution is: get more memory. Steven caught the and store its values in a dictionary (which I missed previously and accentuated in the above quote). The one missing pair of factors you omitted: 1) how many *lines* are in this file (or what's the average line-length). You can use the following code both to find out how many lines are in the file, and to see how long it takes Python to skim through an 800 meg file just in terms of file-I/O: i = 0 for line in file('in.txt'): i += 1 print %i lines % i 2) how much overlap/commonality is there in the keys between lines? Does every line create a new key, in which case you're adding $LINES keys to your dictionary? or do some percentage of lines overwrite entries in your dictionary with new values? After one of your slow runs, issue a print len(my_dict) to see how many keys are in the final dict. If you end up having millions of keys into your dict, you may be able to use the bdb module to store your dict on-disk and save memory. Doing access to *two* files may not get you great wins in speed, but you at least won't be thrashing your virtual memory with a huge dict, so performance in the rest of your app may not experience similar problems due to swapping into virtual memory. This has the added advantage that, if your input file doesn't change, you can simply reuse the bdb database/dict file without the need to rebuild its contents. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython fast and slow
def move_panel(self, evt): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x for x in gen(): self.square.SetPosition((x, 30)) time.sleep(0.005) I can't help with the performance problem, but you don't really need a generator for your x-values. This works: def move_panel(self, evt): for i in xrange(400): x = 200-abs(i-200) self.square.SetPosition((x, 30)) time.sleep(0.005) The generator *does* make for clearer code, though! -John -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython fast and slow
On Mar 8, 3:52 am, iu2 isra...@elbit.co.il wrote: On Mar 6, 6:52 pm, Mike Driscoll kyoso...@gmail.com wrote: ... Can you post a sample application so we can try to figure out what's wrong? You might also cross-post this to thewxPythonmailing list. They might know. Mike- Hide quoted text - - Show quoted text - Hi, thanks for your reply Here is a sample application: -- import wx import time class My_frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Moving panel') self.surface = p = wx.Panel(self, size=(300, 130)) self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30)) self.square.Bind(wx.EVT_PAINT, self.on_paint_square) btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0)) self.Bind(wx.EVT_BUTTON, self.move_panel, btn_move) self.Fit() def move_panel(self, evt): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x for x in gen(): self.square.SetPosition((x, 30)) time.sleep(0.005) def on_paint_square(self, evt): square = evt.GetEventObject() dc = wx.BufferedPaintDC(square) dc.Pen = wx.Pen('blakc', 2) dc.Brush = wx.Brush('light blue') dc.DrawRectangle(0, 0, *square.GetSize()) app = wx.PySimpleApp() My_frame().Show() app.MainLoop() -- Press the button and the panel moves to the right and then back to the left. While PyScripter is running the panel moves at a certain speed. You can run the application from the Windows explorer with the same speed. You don't need to run it from PyScripter. When PyScripter is closed, the application runs much less quickly. I experienced this on two PC-s. Maybe this behavior is not even related to wxPython but to the sleep command. I don't know... Thanks iu2 You probably want to use wx.Timer rather than using time.sleep. You could use wx.Sleep() too. I don't really understand why you're doing what you're doing though. Did you re-post to the wxPython group? Mike -- http://mail.python.org/mailman/listinfo/python-list
Callback from c thread with ctypes
Hi, I am going to develop a c library binding with ctypes. That c library will call callback from worker threads it created. Here comes the problem : Will the GIL be acquired before it goes into Python function? I got a little try.. DSPPROC = WINFUNCTYPE(None, DWORD, DWORD, c_void_p, DWORD, c_void_p) def test(handle, channel, buffer, length, user): print handle, channel, buffer, length, user dsp = BASS_ChannelSetDSP(stream, DSPPROC(test), None, 123) I got access violation when I run it... It seems that the ctypes did't acquire GIL before it call the python callback. As the document says. WINFUNCTYPE will release GIL during the call But it does not mention callback about Python function? How about a call from another thread? Could somebody help me? Thanks. Victor Lin. -- http://mail.python.org/mailman/listinfo/python-list
Re: can't print the exception cause/context in Python3.0?
En Sat, 07 Mar 2009 21:18:22 -0200, BigHand hewei...@gmail.com escribió: On 3月7日, 下午11时21分, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Sat, 07 Mar 2009 11:46:08 -0200, BigHand hewei...@gmail.com escribió: I want the exception printted like this: File pyshell#14, line 2, in module a() File pyshell#6, line 2, in a b() File pyshell#9, line 2, in b return tuple()[0] Put your code in a true module stored in a file, so the source lines can be retrieved. I don't understand you.could you give me more details? C:\TEMPtype tbtest.py import sys import traceback def a(): b() def b(): raise ValueError print(\none\n) try: a() except: exc_typ, exc_val, exc_tb = sys.exc_info() traceback.print_tb(exc_tb) print(\ntwo\n) try: a() except: exc_typ, exc_val, exc_tb = sys.exc_info() traceback.print_tb(exc_tb) print(\nthree\n) a() C:\TEMPpython30 tbtest.py one File tbtest.py, line 9, in module try: a() File tbtest.py, line 4, in a def a(): b() File tbtest.py, line 6, in b def b(): raise ValueError two File tbtest.py, line 15, in module try: a() File tbtest.py, line 4, in a def a(): b() File tbtest.py, line 6, in b def b(): raise ValueError three Traceback (most recent call last): File tbtest.py, line 21, in module a() File tbtest.py, line 4, in a def a(): b() File tbtest.py, line 6, in b def b(): raise ValueError ValueError C:\TEMP -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback from c thread with ctypes
Victor Lin schrieb: Hi, I am going to develop a c library binding with ctypes. That c library will call callback from worker threads it created. Here comes the problem : Will the GIL be acquired before it goes into Python function? I got a little try.. DSPPROC = WINFUNCTYPE(None, DWORD, DWORD, c_void_p, DWORD, c_void_p) def test(handle, channel, buffer, length, user): print handle, channel, buffer, length, user dsp = BASS_ChannelSetDSP(stream, DSPPROC(test), None, 123) I got access violation when I run it... It seems that the ctypes did't acquire GIL before it call the python callback. As the document says. WINFUNCTYPE will release GIL during the call But it does not mention callback about Python function? How about a call from another thread? Could somebody help me? The releasing takes only place when entering a c-function. A python-callback acquires the GIL, see callbacks.c in the python source. The access violation has nothing to do with that I presume, that's just a general programming error as it happens with ctypes during development. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 3.1 alpha 1
Benjamin Peterson wrote: On behalf of the Python development team and the Python community, I'm happy to announce the first alpha release of Python 3.1. Python 3.1 focuses on the stabilization and optimization of features and changes Python 3.0 introduced. The new I/O system has been rewritten in C for speed. Other features include a ordered dictionary implementation and support for ttk Tile in Tkinter. Please note that these are alpha releases, and as such are not suitable for production environments. We continue to strive for a high degree of quality, but there are still some known problems and the feature sets have not been finalized. These alphas are being released to solicit feedback and hopefully discover bugs, as well as allowing you to determine how changes in 3.1 might impact you. If you find things broken or incorrect, please submit a bug report at http://bugs.python.org For more information and downloads, see the Python 3.1 website: http://www.python.org/download/releases/3.1/ See PEP 375 for release schedule details: http://www.python.org/dev/peps/pep-0361/ Enjoy, -- Benjamin Benjamin Peterson benjamin at python.org Release Manager (on behalf of the entire python-dev team) Do you have any schedule for a Windows binary release? Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback from c thread with ctypes
Victor Lin wrote: Hi, I am going to develop a c library binding with ctypes. That c library will call callback from worker threads it created. Here comes the problem : Will the GIL be acquired before it goes into Python function? I got a little try.. DSPPROC = WINFUNCTYPE(None, DWORD, DWORD, c_void_p, DWORD, c_void_p) def test(handle, channel, buffer, length, user): print handle, channel, buffer, length, user dsp = BASS_ChannelSetDSP(stream, DSPPROC(test), None, 123) I got access violation when I run it... It seems that the ctypes did't acquire GIL before it call the python callback. As the document says. WINFUNCTYPE will release GIL during the call But it does not mention callback about Python function? How about a call from another thread? Could somebody help me? You can't call Python code from an arbitrary thread. Before you are allowed to call a Python function from a thread, you must enable Python's threading subsystem and register the thread. Python need to store information (like the exception information) in a thread local variable (TLS). I can't tell you how to register your thread with Python, though. Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
On Mar 8, 2:16 pm, farsi...@gmail.com wrote: 4 / 5.0 0.84 0.8 * 5 4.0 python 2.6.1 on mac. What the hell is going on here? Pure curiosity prompted me to try the following: 40 / 5.0 8.0 Strange... -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback from c thread with ctypes
On 3月8日, 下午9時56分, Diez B. Roggisch de...@nospam.web.de wrote: Victor Lin schrieb: Hi, I am going to develop a c library binding with ctypes. That c library will call callback from worker threads it created. Here comes the problem : Will the GIL be acquired before it goes into Python function? I got a little try.. DSPPROC = WINFUNCTYPE(None, DWORD, DWORD, c_void_p, DWORD, c_void_p) def test(handle, channel, buffer, length, user): print handle, channel, buffer, length, user dsp = BASS_ChannelSetDSP(stream, DSPPROC(test), None, 123) I got access violation when I run it... It seems that the ctypes did't acquire GIL before it call the python callback. As the document says. WINFUNCTYPE will release GIL during the call But it does not mention callback about Python function? How about a call from another thread? Could somebody help me? The releasing takes only place when entering a c-function. A python-callback acquires the GIL, see callbacks.c in the python source. The access violation has nothing to do with that I presume, that's just a general programming error as it happens with ctypes during development. Diez Hi, Thanks your replying, I try it again, found that my program only crash when I call it from python's IDLE. If I click it, namely execute it with python directly, it works fine. Why the program will crash within IDLE? -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback from c thread with ctypes
On 3月8日, 下午10時20分, Christian Heimes li...@cheimes.de wrote: Victor Lin wrote: Hi, I am going to develop a c library binding with ctypes. That c library will call callback from worker threads it created. Here comes the problem : Will the GIL be acquired before it goes into Python function? I got a little try.. DSPPROC = WINFUNCTYPE(None, DWORD, DWORD, c_void_p, DWORD, c_void_p) def test(handle, channel, buffer, length, user): print handle, channel, buffer, length, user dsp = BASS_ChannelSetDSP(stream, DSPPROC(test), None, 123) I got access violation when I run it... It seems that the ctypes did't acquire GIL before it call the python callback. As the document says. WINFUNCTYPE will release GIL during the call But it does not mention callback about Python function? How about a call from another thread? Could somebody help me? You can't call Python code from an arbitrary thread. Before you are allowed to call a Python function from a thread, you must enable Python's threading subsystem and register the thread. Python need to store information (like the exception information) in a thread local variable (TLS). I can't tell you how to register your thread with Python, though. Christian I know I have to call PyEval_InitThreads if my module create threads that will contact python stuff, for example, call a python callback function from threads. But however, it is ctypes. I have no idea should I do that for the imported dll? If it is, how? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
En Sun, 08 Mar 2009 12:22:50 -0200, farsi...@gmail.com escribió: On Mar 8, 2:16 pm, farsi...@gmail.com wrote: 4 / 5.0 0.84 0.8 * 5 4.0 python 2.6.1 on mac. What the hell is going on here? Pure curiosity prompted me to try the following: 40 / 5.0 8.0 Strange... See http://docs.python.org/tutorial/floatingpoint.html -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback from c thread with ctypes
Victor Lin wrote I know I have to call PyEval_InitThreads if my module create threads that will contact python stuff, for example, call a python callback function from threads. But however, it is ctypes. I have no idea should I do that for the imported dll? If it is, how? You have to initialize the thread state for the current thread, too. See Python/pystate.c:PyThreadState_New() -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
farsi...@gmail.com wrote: On Mar 8, 2:16 pm, farsi...@gmail.com wrote: 4 / 5.0 0.84 This one is a common FAQ. Basically floating point is never to be trusted. This issue is quite language agnostic, however some language decided to hide the issue, python does not. For more information on floating point and its intricacies: http://docs.python.org/tutorial/floatingpoint.html 0.8 * 5 4.0 python 2.6.1 on mac. What the hell is going on here? Pure curiosity prompted me to try the following: 40 / 5.0 8.0 Strange... Strange, I don't see anything strange with that... Perhaps you meant, python returns 4.0 instead of 4? It's because in division with at least one of the divisor or the dividend a floating point will return a floating point value. Perhaps you're confusing it with integer division, in which both divisor and dividend are integers. In python 2.6, this will still return integers, but this will change (edit: have changed) in python 3.x, division of integer by integer will always result in floating point even if the result can be represented exactly by an integer. You can do 'from __future__ import division' to use the new division semantic in python 2.x -- http://mail.python.org/mailman/listinfo/python-list
Re: Callback from c thread with ctypes
Victor Lin wrote: On 3月8日, 下午9時56分, Diez B. Roggisch de...@nospam.web.de wrote: Victor Lin schrieb: Hi, I am going to develop a c library binding with ctypes. That c library will call callback from worker threads it created. Here comes the problem : Will the GIL be acquired before it goes into Python function? I got a little try.. DSPPROC = WINFUNCTYPE(None, DWORD, DWORD, c_void_p, DWORD, c_void_p) def test(handle, channel, buffer, length, user): print handle, channel, buffer, length, user dsp = BASS_ChannelSetDSP(stream, DSPPROC(test), None, 123) I got access violation when I run it... It seems that the ctypes did't acquire GIL before it call the python callback. As the document says. WINFUNCTYPE will release GIL during the call But it does not mention callback about Python function? How about a call from another thread? Could somebody help me? The releasing takes only place when entering a c-function. A python-callback acquires the GIL, see callbacks.c in the python source. The access violation has nothing to do with that I presume, that's just a general programming error as it happens with ctypes during development. Diez Hi, Thanks your replying, I try it again, found that my program only crash when I call it from python's IDLE. If I click it, namely execute it with python directly, it works fine. Why the program will crash within IDLE? Usually because IDLE is written in python and Tkinter. IDLE doesn't give a completely isolated environment for your program to run in, this causes python program that uses Tkinter often causes various undescribable oddities. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
On Mar 8, 7:22 pm, farsi...@gmail.com wrote: On Mar 8, 2:16 pm, farsi...@gmail.com wrote: 4 / 5.0 0.84 0.8 * 5 4.0 python 2.6.1 on mac. What the hell is going on here? Pure curiosity prompted me to try the following: 40 / 5.0 8.0 Strange... Please see http://docs.python.org/library/decimal.html for explanation of why this happens. To get the proper values, try Decimal(4)/Decimal(5.0) Decimal(0.8) -- http://mail.python.org/mailman/listinfo/python-list
Re: create boolean
Scott David Daniels wrote: Lie Ryan wrote: Fencer wrote: The literal translation of that would be: if n is not None and n != []: b = True else: b = False it is a bit verbose, so one might want to find something shorter b = True if n is not None and n != [] else False I always feel if and in-line if to be easier and more readable than short-circuited operations. How about: b = None is not n != [] It is amazing to think about how rarely we consider is / is not as a comparison operator. Also, and more reasonably, we often don't consider chaining comparisons that are intransitive. The fact that chaining operator is possible doesn't mean it must be used. The only place I would use chained operator is for comparing ranges of integer: 5 x 10, other than that, its use often reduce readability. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
Thanks all, that's very helpful, sorry to waste your time with a common question. I have tried the decimal module and will definitely keep using it if I need to do this kind of calculation again. I have 1 more question that the floating point article that was linked didn't really answer: x = 0.8 x 0.804 x * 5 4.0 Shouldn't I be expecting something like 4.2 ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Guidance - Professional Python Development
RT wrote: cut Can you recommend any books or articles that you have found offer useful advice on program structure, design and use of classes or any other features or best practices that you feel are important for professional Python development. cut In my opinion, 'professional development' has surprisingly less to do with the chosen programming language but more so with project management. Although opinions differs quite, I like a documented approach based on unit-testing. Which means I need, project description, project scope, project specification, functional design, technical design first. Then I write the unit-test and finally solve them. Of course you use a repository to keep your work in and use a Lint tool to check for convention. There are loads of other stuff that affect your environment, testing, documentation, quality control, release management and time-keeping. Using an IDE (I use Eclipse with PyDev) can help you manage all these aspects although it's more important that you feel comfortable with your chosen tools. Perhaps this paper might be interesting: http://dcuktec.googlecode.com/svn/DCUK%20Technologies%20LTD/papers/DITDD/deliverables/DITDD.pdf Though I would request that other people, especially with different opinions would give their point of view and hopefully a more direct answer to your question then I did. -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
farsi...@gmail.com wrote: Thanks all, that's very helpful, sorry to waste your time with a common question. I have tried the decimal module and will definitely keep using it if I need to do this kind of calculation again. Try to remember though that the decimal module simply replaces one source of inaccuracies with another one: Decimal(1)/Decimal(3) Decimal('0.') _ * 3 Decimal('0.') 1./3. 0.1 _ * 3 1.0 Sometimes you want floating point, sometimes you want Decimal. You need to understand the advantages and drawbacks of each in order to make an informed choice. I have 1 more question that the floating point article that was linked didn't really answer: x = 0.8 x 0.804 x * 5 4.0 Shouldn't I be expecting something like 4.2 ? You should certainly expect that the final result may be a little bit away from the 'exact' result but rounding errors can work in your favour just as well as they work against. -- http://mail.python.org/mailman/listinfo/python-list
Re: 2.6.1 - simple division
Thanks duncan, thats very helpful. I'll be more careful with floating point numbers in future. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which Lisp to Learn?
Xah Lee wrote: For those of you imperative programers who kept on hearing about lisp and is tempted to learn, then, ... You: * consider yourself unfairly treated by various communities * post a long drivel about various Lisp flavors to newsgroups that are not in any way Lisp related ? There seems to be a disconnect somewhere. Arne -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 3.1 alpha 1
Colin J. Williams cjw at ncf.ca writes: Do you have any schedule for a Windows binary release? They should materialize on Monday. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Mar 8, 7:50 am, D'Arcy J.M. Cain da...@druid.net wrote: So you are going to repeat his postings in their entirety so that those that block him will see them anyway, right? Wrong. We'll just block your posts too. *plonk* This is to all usenet readers who think they own c.l.py! === This especially concerns D'Arcy, Bruno, and Steven D'Aprro! All three of which who's wibbling, and chastinations of fellow readers has plagued this group for far too long. I hereby declare these readers viral infestations, in the name of freedom of purity. You should really stop reading usnet thru email or some asinine news reader, this will solve all your problems and stop your obnoxious quibbling for which i am getting tired of listening to. I am sick of hearing cry babys like you say don't quote a post because i do not wish to read it. Look idiot, if you don't want to read it, for christ sake DONT F'IN READ IT AND SHUT THE HELL UP!! I don't know if you are aware of this but you are in no way forced to read anything. I know you wish to live in a world completely under your control with the mantra My way or the highway, but it does not work like that. And let me tell you another thing bozo, just because you have been reading usenet since 1972 from your mommas basement with one hand on your Oscar Myer, does not mean you own it or have any power to tell others how, what, or when they should read or not read this group or post to this group. SHUT UP AND READ OR JUST SHUT UP! Go choke yourself while watching some gay porn so you might be happy for 10 minutes and spare us you infantile whining. School time for old burnouts: = The best reader for Usenet is Google groups. There is no need to read miles of quoted text because it all gets stuffed in a nice little link called show quoted text -- believe it or not :) Because i use the wonderful Google Groups I also don't have my email or reader clogged with hundreds of messages for which i do not care to read. I just skim the subject lines here in the group and decide in a micro second whether or not i will read it. Dump those useless newsreades and move into the 21st century people. Are you still playing Atari for Christ sake? Newsreaders are like Newspapers. I have no use for them either. Just like a newspaper i have to plow thru miles of useless crap just to get to the one thing i might be interested in, not to mention walking to the curb to pick the damn thing up! In the age of 24 hour news networks and instant internet news, a newspaper is only good for one thing, wiping my backside! So wake up and smell the coffee burnouts, the end of your useless and tyrannical reign is nigh, the future is upon us and the sun is shining bright! The invasion of the normies has happened. No longer shall the meek rule, but all shall be contributors to the digital revolution. If you think that this is bad for you now, just wait a few more years!! hahahahahhaahaha -- Evolution rules! -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Mar 7, 5:52 pm, Xah Lee xah...@gmail.com wrote: HARASSMENT BY JOHN BOKMA I was harassed by a newsgroup poster John Bokma (a regular of comp.lang.perl.misc) to have my web hosting service provider kick me off. This happened in 2006. I know the feeling. I have this super geek with nothing but time on his hands constantly following me around like a flies on an elephants crack. This lowlife has nothing better to do with his time. But, i guess at least this give his poor miserable life some meaning. It's nice to know i can help those poor saps less fortunate than me :) -- http://mail.python.org/mailman/listinfo/python-list
Re: /a is not /a ?
On Mar 7, 2:14 pm, Christian Heimes li...@cheimes.de wrote: Steven D'Aprano wrote: Yes. Floating point NANs are required to compare unequal to all floats, including themselves. It's part of the IEEE standard. As far as I remember that's not correct. It's just the way C has interpreted the standard and Python inherited the behavior. But you may proof me wrong on that. Steven's statement sounds about right to me: IEEE 754 (the current 2008 version of the standard, which supersedes the original 1985 version that I think Robert Kern is referring to) says that every NaN compares *unordered* to anything else (including itself). A compliant language is required to supply twenty-two(!) comparison operations, including a 'compareQuietEqual' operation with compareQuietEqual(NaN, x) being False, and also a 'compareSignalingEqual' operation, such that compareSignalingEqual(NaN, x) causes an 'invalid operation exception'. See sections 5.6.1 and 5.11 of the standard for details. Throughout the above, 'NaN' means quiet NaN. A comparison involving a signaling NaN should always cause an invalid operation exception. I don't think Python really supports signaling NaNs in any meaningful way. I wonder what happens if you create an sNaN using struct.unpack(suitable_byte_string) and then try to do arithmetic on it in Python... Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Gabriel Genellina wrote: En Fri, 06 Mar 2009 06:52:00 -0200, dan.erik.peter...@gmail.com escribió: I have succeeded in building Python 2.6.1 from source under Windows XP by running Visual C++ 2008 Express on the PCbuild/pcbuild.sln file both from the Visual C++ application as well as from the commandline [...] I would like to move this Python installation in a clean manner over to another location outside the unpackaged source directory (e.g. from C:\Python-2.6.1 to C:\custom_path\python). Is there already some automatic command that can perform this? If not, which files do I move where and what should the structure be? How do ensure all the Python code related to the install is byte-compiled and ready for use? Create an installer (pythonXXX.msi) and use it to install wherever you want. See Tools\msi in the source tree. If you built using VS2008 Express Edition, probably don't have cabarc.exe - download it from http://support.microsoft.com/kb/310618/en-us and make sure the bin directory is in your PATH before running msi.py A small caveat here: I've just done this myself and I had to patch one or two things very slightly. I have the htmlhelp libraries in a non-standard place and the make.bat helper file in the doc\ directory hardcodes its location. The patch from this tracker issue: http://bugs.python.org/issue2421 solves that (with the help of an env var). The other thing is that the instructions in the pcbuild/readme.txt and the corresponding code in Tools\buildbot\external-common.bat export the external tcl/tk libraries under the name tcl-8* and tk-8* whereas the msi.py code is expecting to find them under tcl8* and tk8*. In addition, msi.py is looking for a tix-* directory which doesn't seem to come from anywhere. I don't know if that constitutes a bug in msi.py or one in the pcbuild / external-common.bat or neither of the two. Happy to produce a patch if needed. In addition, the CVS version of pywin32 which I built in order to run the msi.py script has a small bug in genpy which prevents it from generating COM support in the way in which msi.py does it. I've reported it as issue 2672514 on the pywin32 tracker: http://sourceforge.net/tracker/index.php?func=detailaid=2672514group_id=78018atid=551954 Anyhow, at the end I have a working Python 2.7a0 running under Windows. TJG -- http://mail.python.org/mailman/listinfo/python-list
Set Frozenset?
Could you help me ? How could I take an elemment from a set or a frozenset .-) ? From a string (unicode? Python3), or from a tuple,or from a list: Element by index or slice. From a dict: by key. But what concerning a set or frozenset! hope somebody can help! -- Hans Larsen Galgebakken Sønder 4-11A DK-2620 Albertslund Danmark/Danio begin 666 Hans Larsen.vcf M0D5'24XZ5D-!4D0-E9%4E-)3TXZ,BXQ#0I..DQAG-E;CM(86YS#0I3CI( M86YS($QAG-E;@T*14U!24P[4%)%1CM)3E1%4DY%5#IJ;V-J;T!M86EL+F1K C#0I2158Z,C P.3 S,#A4,3T-C,y...@t*14y$.e9#05)$#0H` ` end -- http://mail.python.org/mailman/listinfo/python-list
Re: RELEASED Python 3.1 alpha 1
On Mar 7, 6:59 pm, Carl Banks pavlovevide...@gmail.com wrote: I see that Brett Canon's importlib has finally made it into Python standard library. Congrats there (if you still read this list), I am struggling with Python's arcane import semantics (for something ridiculously silly) now and I feel your pain. Hi Carl, Could you please give a couple quick examples of these current arcane import semantics (or at least point me in the right direction)? I don't know what you mean, and would like to understand what Brett's importlib fixes. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help cleaning up some code
On Mar 8, 4:48 am, andrew cooke and...@acooke.org wrote: odeits wrote: On Mar 7, 1:07 pm, Scott David Daniels scott.dani...@acm.org wrote: odeits wrote: I am looking to clean up this code... any help is much appreciated. Note: It works just fine, I just think it could be done cleaner. The result is a stack of dictionaries. the query returns up to STACK_SIZE ads for a user. The check which i think is very ugly is putting another contraint saying that all of the ni have to be the same. Well, the obvious way to get your constraint is by changing your SQL, but if you are going to do it by fetching rows, try: FIELDS = 'ni adid rundateid rundate city state status'.split() ni = UNSET = object() # use None unless None might be the value stack = [] rows = self.con.execute(adquerystring, (user,STACK_SIZE)).fetchall() for row in rows: ad = dict() for field in FIELDS: ad[field] = row[field] for field in 'city', 'state': if ad[field] is None: ad[field] = 'None' if ni != ad['ni']: if ni is UNSET: ni = ad['ni'] else: break stack.append(ad) --Scott David Daniels scott.dani...@acm.org Taking from several suggestions this is what i have come up with for now: for row in ifilter(lambda r: r['ni'] == rows[0]['ni'],rows): not sure what version of python you're using, but it would be more natural in recent python to write that as: for row in (r for r in rows if r['ni'] == rows[0]['ni']): (the () create a generator for you). andrew ad = dict() keys = row.keys() # if python 2.6 keys = ['ni','adid','rundateid','rundate','city','state','status'] # if python 2.5 for index in row.keys(): if row[index] is None: ad[index] = 'None' else: ad[index] = row[index] stack.append(ad) print row the test to see if the ad is valid is placed in the ifilter so that I dont build the dictionary unnecessarily. and the None special case is fairly simple to read now. The None case would even be irrelevant if i could get the damn xmlrpc to allow null. sigh. anyhow. thanks for all of your input, it is definitely better than it was ;) -- http://mail.python.org/mailman/listinfo/python-list This function is very time critical so i went with itertools for efficient looping and i am runing 2.5 -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Hans Larsen schrieb: Could you help me ? How could I take an elemment from a set or a frozenset .-) ? From a string (unicode? Python3), or from a tuple,or from a list: Element by index or slice. From a dict: by key. But what concerning a set or frozenset! hope somebody can help! You iterate over them. If you only want one value, use iter(the_set).next() Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the PyString_AsString in Python 3.0?
BigHand wrote: I know that there is no PyString_AsString in Python3.0, could you guys give me instruction about how can I do with the following ? PyObject *exc_type = NULL, *exc_value = NULL, *exc_tb = NULL; PyErr_Fetch(exc_type, exc_value, exc_tb); how do I transfer the exc_type in a char* ? Are you sure you want the exc_type and not the exc_value? The only major thing I'd do with the type of an exception is to let Python check for it using PyErr_ExceptionMatches(). Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: where is the PyString_AsString in Python 3.0?
BigHand wrote: Finally I got the results now. This did take me 10 hours to solve this. the docs of 3.0.. You will have to get used to Unicode. The code you used against the C-API mimics almost exactly the steps you'd use at the Python level. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
r wrote: This is to all usenet readers who think they own c.l.py! [snip abusive, anti-social rant] Well, after kill-filing this kiddie for a few months, I thought I'd give him a chance. By pure luck I chose this post to read. Good news r, you've earned yourself a permanent kill-filing. I'll be enjoying the silence from you. *plonk* -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Diez B. Roggisch wrote: Hans Larsen schrieb: Could you help me ? How could I take an elemment from a set or a frozenset .-) ? From a string (unicode? Python3), or from a tuple,or from a list: Element by index or slice. From a dict: by key. But what concerning a set or frozenset! hope somebody can help! You iterate over them. If you only want one value, use iter(the_set).next() or the_set.pop () TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Set Frozenset?
Tim Golden wrote: Diez B. Roggisch wrote: Hans Larsen schrieb: Could you help me ? How could I take an elemment from a set or a frozenset .-) ? From a string (unicode? Python3), or from a tuple,or from a list: Element by index or slice. From a dict: by key. But what concerning a set or frozenset! hope somebody can help! You iterate over them. If you only want one value, use iter(the_set).next() or the_set.pop () Which will, in addition, remove it from the set. (May not be what you want :) ). TJG -- http://mail.python.org/mailman/listinfo/python-list
Sharing objects between processes
I have been using the 'threading' library and decided to try swapping it out for 'processing'... while it's awesome that processing so closely mirrors the threading interface, I've been having trouble getting my processes to share an object in a similar way. Using the 'with' keyword didn't work, and using normal locks doesn't result in the expected behavior (I can get an object to be accessible in more than one process, and Python indicates that the instances are living at the same address in memory, but changes in one process are not reflected in the other[s]). I'm sure this is because my expectations are incorrect. :) The problem, as briefly as possible: I have three processes which need to safely read and update two objects. I've been working with processing, multiprocessing, and parallel python, trying to get this working... I suspect it can be accomplished with managers and/or queues, but if there's an elegant way to handle it, I have thus far failed to understand it. I don't particularly care which library I use; if someone has done this or can recommend a good method they're aware of, it'd be incredibly helpful. Thank you! -- http://mail.python.org/mailman/listinfo/python-list
Re: Sharing objects between processes
ET wrote: Using the 'with' keyword didn't work... Just an aside here for any multiprocessing maintainers watching ;) . I expect that the didn't work here refers to this bug: http://bugs.python.org/issue5261 Altho' if the OP cares to clarify, it might be something else. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Sharing objects between processes
On Mar 8, 1:36 pm, ET p...@2drpg.org wrote: I have been using the 'threading' library and decided to try swapping it out for 'processing'... while it's awesome that processing so closely mirrors the threading interface, I've been having trouble getting my processes to share an object in a similar way. Using the 'with' keyword didn't work, and using normal locks doesn't result in the expected behavior (I can get an object to be accessible in more than one process, and Python indicates that the instances are living at the same address in memory, but changes in one process are not reflected in the other[s]). I'm sure this is because my expectations are incorrect. :) The problem, as briefly as possible: I have three processes which need to safely read and update two objects. I've been working with processing, multiprocessing, and parallel python, trying to get this working... I suspect it can be accomplished with managers and/or queues, but if there's an elegant way to handle it, I have thus far failed to understand it. I don't particularly care which library I use; if someone has done this or can recommend a good method they're aware of, it'd be incredibly helpful. Thank you! There is POSH: Python Object Sharing, which I learned about a while ago, but never used much. http://poshmodule.sourceforge.net/ It's UNIX only. -- http://mail.python.org/mailman/listinfo/python-list
Re: Chandler, Python, speed
On Sat, 2009-03-07 at 22:05 +, Ville M. Vainio wrote: Alan G Isaac wrote: 3. Chandler is not really an email client. So specifically, which of its functionalities is it slow, and what evidence if any is there that Python is causing this? I remember reading somewhere that the cause of slowness is/was architectural - perhaps it was that chandler was persisting too much stuff to disk, or something. In any case, this might help you google for more detail. I've been using it, and the only major issue I've got is the long shutdown times, which is caused by backing up a copy of _Everything_ to disk, so that upgrades can happen cleanly - sure that's going to be fixed though. Startup time is a bit slow too, but it's designed to be left open all the time, and it's fairly zippy once it's open IMO. Tim Wintle -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython fast and slow
On Mar 8, 1:42 pm, Carl Banks pavlovevide...@gmail.com wrote: On Mar 8, 1:52 am, iu2 isra...@elbit.co.il wrote: On Mar 6, 6:52 pm, Mike Driscoll kyoso...@gmail.com wrote: ... Can you post a sample application so we can try to figure out what's wrong? You might also cross-post this to thewxPythonmailing list. They might know. Mike- Hide quoted text - - Show quoted text - Hi, thanks for your reply Here is a sample application: -- import wx import time class My_frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Moving panel') self.surface = p = wx.Panel(self, size=(300, 130)) self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30)) self.square.Bind(wx.EVT_PAINT, self.on_paint_square) btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0)) self.Bind(wx.EVT_BUTTON, self.move_panel, btn_move) self.Fit() def move_panel(self, evt): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x for x in gen(): self.square.SetPosition((x, 30)) time.sleep(0.005) def on_paint_square(self, evt): square = evt.GetEventObject() dc = wx.BufferedPaintDC(square) dc.Pen = wx.Pen('blakc', 2) dc.Brush = wx.Brush('light blue') dc.DrawRectangle(0, 0, *square.GetSize()) app = wx.PySimpleApp() My_frame().Show() app.MainLoop() -- Press the button and the panel moves to the right and then back to the left. While PyScripter is running the panel moves at a certain speed. You can run the application from the Windows explorer with the same speed. You don't need to run it from PyScripter. When PyScripter is closed, the application runs much less quickly. I experienced this on two PC-s. Maybe this behavior is not even related towxPythonbut to the sleep command. I don't know... It's not a good idea to call time.sleep inside a loop inside an event handler, which is what you are doing here. wx has a mechanism to call some sort of callback at timed intervals. (I don't know what it is but I know it has one.) Instead of animating the box move inside the button callback, have it request that a callback be called after x seconds pass, and draw a single frame inside that callback. Then invoke it again until you're done drawing. Here's a rough idea of what that might look like: class My_frame(wx.Frame): # ... among other things ... def move_panel(self,evt): self.square_pos = 0 wx.set_timed_callback_of_some_sort( self.draw_frame,0.005) def draw_frame(self): self.square.SetPosition((self.square_pos, 30)) self.square_pos += 1 if self.square_pos 200: wx.set_timed_callback_of_some_sort( self.draw_frame,0.005) As for why it works fine in PyScripter but not when started from Explorer, well, let's just say that when you abuse callbacks like you did, you shouldn't expect reasonable behavior. Carl Banks Hi, Here is the timer version. It works even more slowly, even with PyScripter active: -- import wx import time class My_frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Moving panel') self.surface = p = wx.Panel(self, size=(300, 130)) self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30)) self.square.Bind(wx.EVT_PAINT, self.on_paint_square) btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0)) self.Bind(wx.EVT_BUTTON, self.move_panel, btn_move) self.Fit() def on_paint_square(self, evt): square = evt.GetEventObject() dc = wx.BufferedPaintDC(square) dc.Pen = wx.Pen('blakc', 2) dc.Brush = wx.Brush('light blue') dc.DrawRectangle(0, 0, *square.GetSize()) def move_panel(self, evt): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x self.track = gen() self.timer = wx.Timer(self) self.Bind(wx.EVT_TIMER, self.on_timer_square, self.timer) self.timer.Start(milliseconds=1) def on_timer_square(self, evt): try: x = self.track.next() self.square.SetPosition((x, 30)) except StopIteration: self.timer.Stop() app = wx.PySimpleApp() My_frame().Show() app.MainLoop() - I actually tried this one first. Due to the slow speed I changed to looping inside the event. I don't understand why it takes so long to move that square with wx.Timer set to 1 ms
Re: Chandler, Python, speed
Ville M. Vainio wrote: Alan G Isaac wrote: 3. Chandler is not really an email client. So specifically, which of its functionalities is it slow, and what evidence if any is there that Python is causing this? I remember reading somewhere that the cause of slowness is/was architectural - perhaps it was that chandler was persisting too much stuff to disk, or something. In any case, this might help you google for more detail. Here's the somewhere: http://blog.chandlerproject.org/2008/05/21/rick-rawson-on-why-i-use-chandler-and-what-would-make-me-stop/ QQQ Alex, you’re right that VM usage is a big factor, although there are cases where the CPU is doing too much, too. So far as why this is, there are many contributions. The biggest one is that architectural decisions taken early on in the project meant that way too much data is being persisted. For example, the app persists all schema and GUI layout information, leading to on-disk and mapped memory bloat. (There is also redundancy in the data stored on disk that leads to more of this kind of bloat). QQQ -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
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. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
In addition, the CVS version of pywin32 which I built in order to run the msi.py script has a small bug in genpy which prevents it from generating COM support in the way in which msi.py does it. I'm using Python 2.4 to run msi.py; that has always worked fine for me. Regards, Martin P.S. Don't forget to run merge.py after msi.py -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
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. The current trunk calls itself 2.7a0. I think you might be referring to 3.0a1. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Martin v. Löwis wrote: In addition, the CVS version of pywin32 which I built in order to run the msi.py script has a small bug in genpy which prevents it from generating COM support in the way in which msi.py does it. I'm using Python 2.4 to run msi.py; that has always worked fine for me. Interesting. Didn't even think of that. Well, it works ok with my micro-patches anyway. Regards, Martin P.S. Don't forget to run merge.py after msi.py What does the merge do? I can't find mention of it in the docs. Thanks for the input, by the way. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
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. No; 2.7a0 is the version number of the svn HEAD. 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. There used to be nightly .msi builds, don't remember where; if Martin (or someone) doesn't chip in with something, I'll happily provide an unofficial build. In fact, I might do it anyway if I can get my act together. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Eclipse And PyDev
Thanks. I noticed that when I was on my windows box at work and I would check it and click apply then ok and when I go back to those prefs and it isn't checked. I did that a few times. I will try it on my Linux box tomorrow at home and see if I have the same results. If it doesn't work for you, please report a bug (saying which are the specific versions of eclipse/pydev you're using. See: http://pydev.sourceforge.net/faq.html#how_do_i_report_a_bug ) Thanks, Fabio -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
What does the merge do? I can't find mention of it in the docs. It merges the msvcrt merge module into the installer (and then monkey patches it, to revert the msm decision of setting ALLUSERS). I tried to integrate it originally as a step after creating the msi. Unfortunately, the merge object refused to open the database, claiming that the file is in use (even though I had closed it). Hence I need to processes. If you can figure out how to combine them into one, again, that would be much appreciated. If you don't merge the CRT, the resulting Python installation will fail on systems were a) VS 2008 is not installed (nor has the stand-alone CRT installer been run, nor has anything else been installed that comes with the CRT), and b) Python is installed for all users (else a private copy of msvcr90.dll gets installed) Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
On Mar 8, 1:24 pm, Steven D'Aprano st...@pearwood.info wrote: r wrote: This is to all usenet readers who think they own c.l.py! [snip abusive, anti-social rant] Well, after kill-filing this kiddie for a few months, I thought I'd give him a chance. By pure luck I chose this post to read. Good news r, you've earned yourself a permanent kill-filing. I'll be enjoying the silence from you. *plonk* -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Martin v. Löwis wrote: What does the merge do? I can't find mention of it in the docs. It merges the msvcrt merge module into the installer (and then monkey patches it, to revert the msm decision of setting ALLUSERS). I tried to integrate it originally as a step after creating the msi. Unfortunately, the merge object refused to open the database, claiming that the file is in use (even though I had closed it). Hence I need to processes. If you can figure out how to combine them into one, again, that would be much appreciated. At the moment, I'm struggling to make it work at all :) First, it relies on config.py whose existence msi.py optionally ignores. I've created a dummy, based on the settings in msi.py. Then I get a COM error, reproduced below. I've got to go and do something else at the moment but I'll look into it afterwards. I'll dump the traceback here in case it rings any bells. TJG dump Opened Log Traceback (most recent call last): File merge.py, line 79, in module merge(msi, SharedCRT, TARGETDIR, modules) File merge.py, line 27, in merge m.OpenDatabase(msi) File COMObject Msm.Merge2.1, line 2, in OpenDatabase pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024786), None) [33419 refs] /dump TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
En Sun, 08 Mar 2009 18:08:50 -0200, Martin v. Löwis mar...@v.loewis.de escribió: What does the merge do? I can't find mention of it in the docs. It merges the msvcrt merge module into the installer (and then monkey patches it, to revert the msm decision of setting ALLUSERS). I tried to integrate it originally as a step merge.py attempts to import config.py but I can't find it... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Themed TK (tk Tile) at last?!
Python Nutter wrote: Looks like we finally get tkinter GUI based programs according to Issue# 2983 in Python 3.1a so our programs don't look like something out of early 1980's Please don't confuse History gratuitously. Make that mid 90's. Cheers, BB -- http://mail.python.org/mailman/listinfo/python-list
last and final attempt to search for python ods library.
hello all, Sorry for the frustrated mail. This is my last attempt to search for a nice python library for creating open document spreadsheet. I tryed python-ooolib but did not find a few features like merging cells (may be I am missing out some thing stupid ). I have asked for some help before on this topic but seems there is no such library in python. Pritty strange that python can't do this much. So please tell me if any one knows of a good solution for my problem else I am forced to give up python for my task. happy hacking/ Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ban Xah Lee
seconded. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
merge.py attempts to import config.py but I can't find it... Just create an empty one. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
First, it relies on config.py whose existence msi.py optionally ignores. Feel free to create a patch for that. File COMObject Msm.Merge2.1, line 2, in OpenDatabase pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024786), None) This is 0x8007006e; 0x6E, in turn, might be ERROR_OPEN_FAILED. Did you pass the file name of the MSI file? If not, it computed one, and may have done so incorrectly. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing unicode (devanagari) text with xml.dom.minidom
On Mar 8, 12:42 am, Stefan Behnel stefan...@behnel.de wrote: rpar...@gmail.com wrote: I am trying to process an xml file that contains unicode characters (seehttp://vyakarnam.wordpress.com/). Wordpress allows exporting the entire content of the website into an xml file. Using xml.dom.minidom, I wrote a few lines of python code to parse out the xml file, but am stuck with the following error: import xml.dom.minidom dom = xml.dom.minidom.parse(wordpress.2009-02-19.xml) titles = dom.getElementsByTagName(title) for title in titles: ... print childNode = , title.childNodes ... childNode = [DOM Text node Sanskrit N...] childNode = [DOM Text node Sanskrit N...] childNode = [] childNode = [] childNode = [DOM Text node 1-1-1] childNode = Traceback (most recent call last): File stdin, line 2, in module UnicodeEncodeError: 'ascii' codec can't encode characters in position 16-18: ordinal not in range(128) That's because you are printing it out to your console, in which case you need to make sure it's encoded properly for printing. repr() might also help. Regarding minidom, you might be happier with the xml.etree package that comes with Python2.5 and later (it's also avalable for older versions). It's a lot easier to use, more memory friendly and also much faster. Stefan Thanks for the reply. I didn't realize that printing to console was causing the problem. I am now able to parse out the relevant portions of my xml file. Will also look at the xml.etree module. Regards -- http://mail.python.org/mailman/listinfo/python-list
Re: last and final attempt to search for python ods library.
Krishnakant wrote: This is my last attempt to search for a nice python library for creating open document spreadsheet. I tryed python-ooolib but did not find a few features like merging cells (may be I am missing out some thing stupid ). You could add that feature to python-ooolib. I have asked for some help before on this topic but seems there is no such library in python. Pritty strange that python can't do this much. Python can do it. (Maybe nobody using programming the libraries that you tried ever needed it, so they didn't implement it, but that's something different.) So please tell me if any one knows of a good solution for my problem else I am forced to give up python for my task. You could use python-uno (it's included with OOo by default, and should be able to do everything OOo can do.) -- JanC -- http://mail.python.org/mailman/listinfo/python-list
factory functions methods
Hello, I am creating a container. I have some types which are built to be members of the container. The members need to know which container they are in, as they call methods on it, such as finding other members. I want help with the syntax to create the members. Currently, the container has to be a parameter to the instantiation methods. I want the option to create members with attribute syntax instead. Currently, I have: cA= Container( ) obA= SomeType( cA ) obB= OtherType( cA, otherarg ) I want: cA= Container( ) obA= cA.SomeType( ) obB= cA.OtherType( otherarg ) What are my options? P.S. The container and members are C extension types, not pure Python. -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Martin v. Löwis wrote: merge.py attempts to import config.py but I can't find it... Just create an empty one. Won't quite work: merge tries to find full_current_version which is determined (if None) in msi.py from the rather involved current version stuff. I'm going to give up on this for tonight, but one possibility is to turn msi.py into an importable module and for msilib to import it and pull the config values from there. TJG -- http://mail.python.org/mailman/listinfo/python-list
How to extract some text?
I'm at a loss to figure out how to extract some text from a string. Here is a string: setTimeout(location.href='http://youtube.example.com/login.aspx', 5000); and I want to only retrieve the URL from above i.e I only want this http://youtube.example.com/login.aspx from the above string. Any ideas/ help is highly appreciated. Thanks, Oltmans -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract some text?
On Sun, Mar 8, 2009 at 2:18 PM, Oltmans rolf.oltm...@gmail.com wrote: I'm at a loss to figure out how to extract some text from a string. Here is a string: setTimeout(location.href='http://youtube.example.com/login.aspx', 5000); and I want to only retrieve the URL from above i.e I only want this http://youtube.example.com/login.aspx from the above string. Any ideas/ help is highly appreciated. Learn about the methods of the string class (str): http://docs.python.org/library/stdtypes.html#id4 You'll probably be most interested in .split() Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Windows install to custom location after building from source
Just create an empty one. Won't quite work: merge tries to find full_current_version which is determined (if None) in msi.py from the rather involved current version stuff. Only if you don't pass an msi file on the command line. So I recommend that you do that. I'm going to give up on this for tonight, but one possibility is to turn msi.py into an importable module and for msilib to import it and pull the config values from there. Please, no. The only way I could accept that if merge.py would be run at the end of msi.py (i.e. merge.py disappears). Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract some text?
On Sun, Mar 8, 2009 at 5:18 PM, Oltmans rolf.oltm...@gmail.com wrote: I'm at a loss to figure out how to extract some text from a string. Here is a string: setTimeout(location.href='http://youtube.example.com/login.aspx', 5000); and I want to only retrieve the URL from above i.e I only want this http://youtube.example.com/login.aspx from the above string. Any ideas/ help is highly appreciated. Thanks, Oltmans If x is your string: pos = x.find(') + 1 x[pos:x.find(', pos)] 'http://youtube.example.com/login.aspx' Find the first single quote, then get the character range between that and the next single quote. Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython fast and slow
iu2 wrote: Here is the timer version. It works even more slowly, even with PyScripter active: ... I actually tried this one first. Due to the slow speed I changed to looping inside the event. I don't understand why it takes so long to move that square with wx.Timer set to 1 ms interval. Perhaps its minimum interval is actually 10 ms (as in Windows) so 100 steps really take 1 second. But in that case, I really want to move the square in a tight loop inside the wx.EVT_BUTTON event. So allow me to rephrase my question: Is there a way to move that square quickly and smoothly? Should 400 one-pixel moves should take so long on a 2.8 GHz core duo? There is certainly something wrong in the code I wrote which I need your help to figure out. Can it be related to recurring paint events? If so how should I change the code? Thanks Here is a too-fast version you could fiddle around with: import wx class My_frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, 'Moving panel') self.surface = p = wx.Panel(self, size=(300, 130)) self.square = wx.Panel(p, -1, size=(100, 100), pos=(0, 30)) self.square.Bind(wx.EVT_PAINT, self.on_paint_square) btn_move = wx.Button(p, -1, 'Move panel', pos=(0, 0)) self.Bind(wx.EVT_BUTTON, self.startcalls, btn_move) self.Fit() def startcalls(self, evt=None): def gen(): for x in range(200): yield x for x in range(200, 0, -1): yield x self.track = gen().next wx.CallAfter(self.stepcall) def stepcall(self, evt=None): try: x = self.track() except StopIteration: pass else: self.square.SetPosition((x, 30)) wx.CallAfter(self.stepcall) def on_paint_square(self, evt): square = evt.GetEventObject() dc = wx.BufferedPaintDC(square) dc.Pen = wx.Pen('black', 2) dc.Brush = wx.Brush('light blue') dc.DrawRectangle(0, 0, *square.GetSize()) if __name__ == '__main__': app = wx.PySimpleApp() My_frame().Show() app.MainLoop() -- http://mail.python.org/mailman/listinfo/python-list
Re: factory functions methods
Aaron Brady wrote: Hello, I am creating a container. I have some types which are built to be members of the container. The members need to know which container they are in, as they call methods on it, such as finding other members. I want help with the syntax to create the members. Currently, the container has to be a parameter to the instantiation methods. I want the option to create members with attribute syntax instead. Currently, I have: cA= Container( ) obA= SomeType( cA ) obB= OtherType( cA, otherarg ) I want: cA= Container( ) obA= cA.SomeType( ) obB= cA.OtherType( otherarg ) What are my options? maybe there'sa simpler way, but i think this is what you want, if the container is the first arg to the other constructors: def foo(x): ... print x ... from types import MethodType class Bar: ... def __init__(self): ... self.foo = MethodType(foo, self) ... b = Bar() b.foo() __main__.Bar instance at 0x7f35edb091b8 above is with 3.0. for some odd reason i thing the order of teh args to MethodType may have changed recently, so be careful. andrew P.S. The container and members are C extension types, not pure Python. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: factory functions methods
andrew cooke wrote: above is with 3.0. for some odd reason i thing the order of teh args to MethodType may have changed recently, so be careful. sorry, no, had 2.6 running there... andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: How to extract some text?
On Mar 9, 3:37 am, Chris Rebert c...@rebertia.com wrote: Learn about the methods of the string class (str):http://docs.python.org/library/stdtypes.html#id4 You'll probably be most interested in .split() OK, thanks I got it. I was trying to use Regex but .split() just worked like a charm. Thank you ;) Cheers, Chris -- I have a blog:http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
NEWB: dividing numbers
I just tried python first time. 2/3 the result is zero I want the result to be .333... How do I get this? Thanks a lot L -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: dividing numbers
Lo schrieb: I just tried python first time. 2/3 the result is zero I want the result to be .333... Well, that's not going to happen - 2/3 is .666 if not done with integers... How do I get this? Use floating points. 2.0 / 3.0 0.3 Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: dividing numbers
On 2009-03-08, Lo gr...@congstar.de wrote: I just tried python first time. 2/3 the result is zero I want the result to be .333... How odd. How do I get this? 1./3 -- Grant -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: dividing numbers
On Sun, Mar 8, 2009 at 3:08 PM, Lo gr...@congstar.de wrote: I just tried python first time. 2/3 the result is zero I want the result to be .333... How do I get this? Add the following to the top of your program: from __future__ import division That tells Python to use the proper kind of division, which is now the default in Python 3.0. Cheers, Chris -- I have a blog: http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: dividing numbers
Lo pisze: I just tried python first time. 2/3 the result is zero Float type must be specified explicitly: 2/3.0 or 2.0/3 In Python 3.x operators behave differently and '2/3' would give float number as a result. I want the result to be .333... Than try: 1/3.0 because 2/3.0 will never show you that ;) Michal -- http://mail.python.org/mailman/listinfo/python-list
Re: NEWB: dividing numbers
Lo wrote: I just tried python first time. 2/3 the result is zero I want the result to be .333... How do I get this? That's integer division (integer divided by integer is integer). If you want the result to be floating point then make one of them floating point: 2.0 / 3 or do this first: from __future__ import division In the future and in Python 3.x / will always return floating point. For an integer result use // instead. BTW, 2.0/3.0 still isn't 0.333... ;-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Guidance - Professional Python Development
RT wrote: I have been doing Python development at work for several years. I started with the official documentation and tutorial, by necessity, the examples tend to be rather simple and none of them really explain the process of developing complete, industrial strength Python applications. Can you recommend any books or articles that you have found offer useful advice on program structure, design and use of classes or any other features or best practices that you feel are important for professional Python development. Very Python-Technical: I'd go with the Python Cookbook if you haven't read through it. Read it sequentially, leaving a section only once you are sure it won't tell you anything interesting. The introductions to the sections are great. More general purpose: I've read some of Expert Python Programming (not enough to have a solid opinion about it (except to know I feel it is neither junk nor perfect). You might see if it is to your liking (check Table of Contents, read sample chapter). Even more general purpose: As Martin P. Hellwig has already commented, learning unit-test based programming can be a huge step forward. Another extra-language critical decision is source control. If you don't do it now, learn and use it (it can make you more fearless when refactoring). I certainly like doing agile development to the extent I can get to teams where I can do that. Try any parts of it that you can (especially those parts that seem the most wrong to you). Your goal in trying agile practices (to my way of thinking) is to get to the point that you know in your bones why these practices work. Once you know why they work, you will be in a position to reject some of them, but introspection without trying will have you skipping too many good ideas. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: create boolean
On Sat, 07 Mar 2009 05:03:08 -, Grant Edwards gra...@visi.com wrote: On 2009-03-07, Rhodri James rho...@wildebst.demon.co.uk wrote: On Fri, 06 Mar 2009 15:34:08 -, Grant Edwards inva...@invalid wrote: On 2009-03-06, Fencer no.s...@plz.ok wrote: Hi, I need a boolean b to be true if the variable n is not None and not an empty list, otherwise b should be false. I ended up with: b = n is not None and not not n I'd do it like this: b = (n is not None) and (n != []) The second comparison isn't actually necessary, since an empty list is True and a non-empty one False. b = (n is not None) and n Putting the comparison in does make the code slightly less magic, though, so it's not a bad idea to do it! Putting in the second comparison in makes the code match the stated requirement. Otherwise you have to start making assumptions about what n might be besides None or the empty list. The OP stated that we *could* assume that n was None or a list, so I stand by what I said. -- Rhodri James *-* Wildebeeste Herder to the Masses -- http://mail.python.org/mailman/listinfo/python-list