EPD Py25 v4.1.30101_beta2 available for testing
Hello, The Enthought Python Distribution's (EPD) early access program website is now hosting the beta 2 build of the upcoming EPD Py25 v4.1.301 release. We would very much appreciate your assistance in making EPD as stable and reliable as possible! Please join us in our efforts by downloading an installer for Windows, Mac OS X, or RedHat EL versions 3, 4, and 5 from the following website: http://www.enthought.com/products/epdearlyaccess.php The release notes for the beta2 build are available here: https://svn.enthought.com/epd/wiki/Py25/4.1.301/Beta2 Please provide any comments, concerns, or bug reports via the EPD Trac instance at https://svn.enthought.com/epd or via e-mail to epd-supp...@enthought.com. -- Dave About EPD - The Enthought Python Distribution (EPD) is a kitchen-sink-included distribution of the Python™ Programming Language, including over 60 additional tools and libraries. The EPD bundle includes NumPy, SciPy, IPython, 2D and 3D visualization, database adapters, and a lot of other tools right out of the box. http://www.enthought.com/products/epd.php It is currently available as a single-click installer for Windows XP (x86), Mac OS X (a universal binary for OS X 10.4 and above), and RedHat 3, 4, and 5 (x86 and amd64). EPD is free for academic use. An annual subscription and installation support are available for individual commercial use. Various workgroup, departmental, and enterprise level subscription options with support and training are also available. Contact us for more information! -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Resolver One Spreadsheet Challenge - win $17000
Resolver One is the Python powered spreadsheet created by Resolver Systems. Resolver One is a highly programmable spreadsheet program built with IronPython. It is capable of creating powerful spreadsheet systems, but is easy to program with Python and .NET libraries. We’re convinced that Resolver One allows people to create astonishing things that simply aren’t possible in a traditional spreadsheet environment. And we want to prove it. Enter the Resolver One Spreadsheet Challenge: http://www.resolversystems.com/competition/ The Resolver One Challenge We're so confident about the revolutionary potential of Resolver One that we've set up the $25,000 Resolver One Challenge. Every month between now and May, we will be giving away $2,000 for the best spreadsheet we receive. And in late May, we'll be handing over $15,000 for the best of the best. Let your imagination run wild Build a blogging engine directly in Resolver One. Hook Resolver One up to existing .NET or Python libraries in unusual ways. Build the game of life, or a Mandelbrot viewer directly into the grid. Get Infocom adventure games running inside a spreadsheet; or for that matter, have a conversation with Eliza. Make a music player that does visualisations in the cells. Or something more businesslike? Use the sophisticated web integration to pull of stock prices, or integrate your spreadsheet with Google Maps. (Perhaps you could build a spreadsheet that plots a map, showing in which part of the country stock or house prices are rising or falling the most.) Build an election predictor (and use a combination of Monte Carlo analysis and the web front end to make it really special). In other words: Resolver One gives you the tools, you just need to use your imagination, and your Python and spreadsheet skills! Resolver One is free to try and for non-commercial and Open Source uses. You can download it from: http://www.resolversystems.com/download/ To get you started with Resolver One we have a new tutorial. It takes you through all the major features, with examples to try: http://www.resolversystems.com/documentation/index.php/Tutorial.html Michael Foord Software Developer Resolver Systems -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: importing csv file into sqlite
On Wed, Dec 17, 2008 at 11:20 PM, klia alwaseem307s...@yahoo.com wrote: klia wrote: hey guys, i have a hug .csv file which i need to insert it into sqlite database using python. my csv data looks like this Birthday2,12/5/2008,HTC,this is my birthday Sea,12/3/2008,kodak,sea birthday4,14/3/2009,samsung,birthday love,17/4/2009,SONY,view of island can any one give me a head start codes. thanks in advance guys so far i came out with this but i get this error was...@linux:~/Project2$ python experment.py Traceback (most recent call last): File experment.py, line 13, in module curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 4, and there are 1 supplied. here's the codes import sqlite3 import csv f = open('/home/waseem/Project2/photos.txt') csv.field_size_limit(10) #see below! input = csv.reader(f, delimiter='\t') conn = sqlite3.connect('/home/waseem/Project2/picutres.db') curse = conn.cursor() curse.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date INTEGER, Make VARCHAR(50), Tag VARCHAR(100))') for item in input: curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) I believe you need to change 'item' to '*item' to expand the list in the call so that the function gets 4 additional args rather than 1 additional arg that happens to be a list. But as I've never used the DB-API before, this is just a guess. Also, you should rename 'input' so that you don't shadow a built-in function, and you might want to rename 'item' to something like 'row' to emphasize that it is itself a list of items. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com curse.commit() -- http://mail.python.org/mailman/listinfo/python-list
Re: importing csv file into sqlite
@klia: You could have had this done hours ago had you taken my suggestion, used my tool and just piped it into sqlite3 on the command line. --JamesMills -- -- Problems are solved by method -- http://mail.python.org/mailman/listinfo/python-list
Re: importing csv file into sqlite
Chris Rebert wrote: klia wrote: for item in input: curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) I believe you need to change 'item' to '*item' to expand the list in the call so that the function gets 4 additional args rather than 1 additional arg that happens to be a list. But as I've never used the DB-API before, this is just a guess. No, the execute() method call is correct. There must be a malformed row in the csv with only one field. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: socket and subprocess problem
James Mills wrote: subprocess process: #1. When my subprocess process has successfully started notify the parent. #2. When my subprocess process has successfully created a listening socket, notify the parent. parent process: #1. When our subprocess process has successfully started a listening socket initiate a connection. I'd swear James copied my response, except his came first. Even the formatting came out similar. I hadn't seen his response when I wrote mine, and wouldn't have bothered posing the same thing again. -- --Bryan -- http://mail.python.org/mailman/listinfo/python-list
Re: socket and subprocess problem
On Thu, Dec 18, 2008 at 8:00 PM, Bryan Olson fakeaddr...@nowhere.org wrote: I'd swear James copied my response, except his came first. Even the formatting came out similar. I hadn't seen his response when I wrote mine, and wouldn't have bothered posing the same thing again. Great minds think alike huh :) You should check out my circuits (1) library! cheers James 1: http://trac.softcircuit.net.au/circuits/ -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Binary tree logarithms properties
2008/12/17 Terry Reedy tjre...@udel.edu: Nodes only have single number indexes if you arrange them linearly. Then the index depends on how you arrange them, whether you start the array indexes with 0 or 1, and whether you start the level numbers with 0 or 1. Call the breadth-first sequence bf. Then the 1-based slice for 1-first level k is bf[2**(k-1):2**k)]. Again, proof by induction. Yes, I was referring to the heap numeration. Anyway, Francesco Guerrieri answered me in a private message and explained me the formula. But actually I was searching for other similar properties. -- http://mail.python.org/mailman/listinfo/python-list
Re: cx_Oracle issues
On Dec 16, 12:17 pm, huw_at1 huwdjo...@gmail.com wrote: On Dec 15, 12:59 pm, ron.re...@gmail.com ron.re...@gmail.com wrote: On Dec 15, 2:44 am, huw_at1 huwdjo...@gmail.com wrote: On Dec 11, 5:34 pm, ron.re...@gmail.com ron.re...@gmail.com wrote: On Dec 10, 9:48 am, huw_at1 huwdjo...@gmail.com wrote: Hey all. When usingcx_Oracleto run a procedure like: cursor.execute(select (obj.function(value)) from table where id=blah) I am getting the following error: ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1 Looking at cursor.description I get: [('(obj.function(value))', type 'cx_Oracle.STRING', 4000, 4000, 0, 0, 1)] Any tips - i have never seen this error before but am guessing that the value being returned is too big for the buffer size set for the cursor. the procedure fetches data from a LOB. Any suggestions/confirmations? Many thanks This error is a problem with the PL/SQL, notcx_Oracle. You need to debug obj.function to see what kind of data is being accessed and then a data analysis of that data to understand why this error occurs. I can tell you the function is most likely expecting characters from a column that are numeric [0 .. 9] and is getting alpha characters. -- Ron Reidy Sr. Oracle DBA Hi thanks for the responses. Unfortunately the procedure in question is from a third party vendor so I can't really debug it so I'd say I was fairly stumped. Just out of interest how do you increase the output buffer size withcx_Oracle? Many thanks- Hide quoted text - - Show quoted text - Hi, Sure you can. You can see the PL/SQL source from the ditionary view ALL_SOURCE: select text from all_source where name = 'NAME_OF_FUNCTION'; From there, reverse engineeer which table(s) and column(s) are being accesses and do the data analysis. -- Ron Reidy Hi all, So I tried Rons query but unfortunately I got 0 records returned. However I can confirm that running the select query from a client does indeed generate the same error. Is there anything else I could try? Otherwise I'll just get in touch with the vendor I guess. Hi again. A further update to these issues is that I found some java executable which seemed to execute the SQL query without hitch. My Java isn't great but from what I could make out it seems that the query is broken down from: select (obj.function(value)) from table where id=blah to: select value from table where id=blah obj.function(value) So make two queries. In the first retrieve the BLOB (value) and store it in a java.sql.blob object. Then pass this back in to the stored procedure. I'm a bit puzzled as to why this way would work over just performing the straight select statement. Culd it be the jdbc connector handles BLOBs better? Anyway I was wondering if I could implement something similar using cx_Oracle. however I am a bit stuck on how to pass a BLOB in to the second query - specifically: cursor.execute(obj.function(value)) where value is the BLOB. I get an error: cx_Oracle.NotSupportedError: Variable_TypeByValue(): unhandled data type cx_Oracle.LOB So I wonder if I need to set something for the input type but I do not know how to do this. Any suggestions? Many thanks again. -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen inheriting
On Dec 17, 7:16 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 17 Dec 2008 22:46:32 -0200, Aaron Brady castiro...@gmail.com escribió: On Dec 17, 5:05 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 17 Dec 2008 12:21:38 -0200, Jeremy Sanders jeremy+complangpyt...@jeremysanders.net escribió: It would be nice if Python created pipes that are properly inheritable by default by child processes, as they're mostly used for IPC. I'd say it is a bug in os.pipe implementation; they should be inheritable by default, as in posix (after all, the code is in posixmodule.c). The code looks like this: ok = CreatePipe(read, write, NULL, 0); Py_END_ALLOW_THREADS if (!ok) return win32_error(CreatePipe, NULL); read_fd = _open_osfhandle((Py_intptr_t)read, 0); write_fd = _open_osfhandle((Py_intptr_t)write, 1); 'If lpPipeAttributes is NULL, the handle cannot be inherited.' You could populate a 'SECURITY_ATTRIBUTES' structure, or call DuplicateHandle on both of them. A patch would look like this: SECURITY_ATTRIBUTES sattribs; sattribs.nLength = sizeof(sattribs); sattribs.lpSecurityDescriptor = NULL; sattribs.bInheritHandle = TRUE; ok = CreatePipe(read, write, sattribs, 0); Yes, that's exactly how os.popen does it (in posixmodule.c) This still doesn't answer whether the file descriptor return by '_open_osfhandle' can be inherited too. It doesn't matter. The OS only cares about file handles, not C RTL structures. -- Gabriel Genellina Ah, I see. Was it an executive decision about what is Pythonic, or just a bug? Do you think the patch would be accepted? I probably ought to mimic a small Python embedding to see if it needs anything else. -- http://mail.python.org/mailman/listinfo/python-list
Best Practice using Glade/Python
Hi, I was wondering which is the best practice using glade/python, and, of course, especially the connect (both side). I didn't found that much documentation on the net ( too noisy), and the best thing I've found was http://www.linuxjournal.com/article/7558 which is a bit old now (2004). The article is very interesting BTW, but I was concerned by the fact it might be a little outdated. It smells like I'm missing something here, and that there have been a clean way to connect both (the autoconnect stuff does not seem that clean to me) for a long time now. So here is the question, do you practive galde/python, which is your practice ? Thanks Eric http://codeslash.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: Binary tree logarithms properties
On Dec 18, 4:34 am, Mr.SpOOn mr.spoo...@gmail.com wrote: 2008/12/17 Terry Reedy tjre...@udel.edu: Nodes only have single number indexes if you arrange them linearly. Then the index depends on how you arrange them, whether you start the array indexes with 0 or 1, and whether you start the level numbers with 0 or 1. Call the breadth-first sequence bf. Then the 1-based slice for 1-first level k is bf[2**(k-1):2**k)]. Again, proof by induction. Yes, I was referring to the heap numeration. Anyway, Francesco Guerrieri answered me in a private message and explained me the formula. But actually I was searching for other similar properties. A tree with one node A, can have two children A CD C and D can each have two children A CD EF GH Taking 'x' to be the level number, each level can have 2**x members. Each member is a child of the higher level. You see the pattern, 1, 2, 4... then 8, 16, etc. The total number of nodes at a level is 2**x plus its earlier levels. 2**x + 2**(x-1) + ... + 2**0. = 2**(x+1) - 1. Taking the log2 of both sides, we have: log2 count_of_nodes = log2( 2**(x+1) - 1 ) Better yet: log2 ( count_of_nodes + 1 ) = log2( 2**(x+1) ) log2 ( count_of_nodes + 1 ) = x+1 -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
On 18 дек, 03:51, Aaron Brady castiro...@gmail.com wrote: (snip) How did you get a reference to the original string object, with which to increment its reference count? Use the O! format instead of s: PyObject *pystr; ... PyArg_ParseTuple(args, O!, PyStringObject, pystr) ... Then you can use PyString_AS_STRING explicitly, and control ref. counts yourself. How do you know its length to copy it into your own buffer? Use the s# format, as Gabriel has said. Ivan -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
On 18 дек, 14:09, Ivan Illarionov ivan.illario...@gmail.com wrote: ... PyArg_ParseTuple(args, O!, PyStringObject, pystr) ... Sorry, I must have said PyString_Type, not PyStringObject -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] The pywinauto Can't select the MDI's menu using the MenuItems() which return [].
This problem also use the following discription:How to use pywinauto to open WORD and select its Menu. I can't do that and have no idea why! Looking forward your help,Thanks! 2008/12/17 为爱而生 boyee...@gmail.com I can't use the MenuItems() in my MDI application. Any example is very nice Thanks a lot! -- OpenBookProject-开放图书计划邮件列表 详情: http://groups.google.com/group/OpenBookProject 维基: http://wiki.woodpecker.org.cn/ -- OpenBookProject-开放图书计划邮件列表 详情: http://groups.google.com/group/OpenBookProject 维基: http://wiki.woodpecker.org.cn/ -- http://mail.python.org/mailman/listinfo/python-list
Re: importing csv file into sqlite
On Dec 18, 6:20 pm, klia alwaseem307s...@yahoo.com wrote: klia wrote: hey guys, i have a hug .csv file which i need to insert it into sqlite database using python. my csv data looks like this Birthday2,12/5/2008,HTC,this is my birthday Sea,12/3/2008,kodak,sea birthday4,14/3/2009,samsung,birthday love,17/4/2009,SONY,view of island can any one give me a head start codes. thanks in advance guys so far i came out with this but i get this error was...@linux:~/Project2$ python experment.py Traceback (most recent call last): File experment.py, line 13, in module curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 4, and there are 1 supplied. here's the codes import sqlite3 import csv f = open('/home/waseem/Project2/photos.txt') csv.field_size_limit(10) #see below! I see nothing below that looks at all like an attempt to justify setting the field size limit to 10 -- why are you doing that? Tends to make one suspect a problem with your delimiter and/or your line separator. input = csv.reader(f, delimiter='\t') Why \t??? Your data examples show commas -- could this be why you are getting one field per line (as Peter has pointed out)? conn = sqlite3.connect('/home/waseem/Project2/picutres.db') Is it really called picutres instead of pictures, or are you typing the code that you ran again from (your) memory? curse = conn.cursor() curse.execute('CREATE TABLE photos (Name VARCHAR(100) PRIMARY KEY, Date INTEGER, Make VARCHAR(50), Tag VARCHAR(100))') [OT but to save the next question] The column named Date is defined to be INTEGER but the data from the CSV file will be a str object e.g. 12/5/2008 ... I know sqlite cheerfully regards column types as vague reminders rather than enforceable constraints on your input, but wouldn't you like to convert your dates to e.g. 2008-05-12 before you poke them in? You may want to use ORDER BY Date at some stage, and so that ORDER BY isn't whacked and GROUP BY doesn't give ludicrous results, wouldn't it be a good idea to crunch 12/5/2008 and 12/05/2008 into a common format so that they compare equal? for item in input: I strongly suggest that you try to get a clue about exactly what you are getting from the csv reader e.g. for line_num, item in enumerate(input_renamed_as_suggested_by_anor): print line_num, repr(item) curse.execute('INSERT INTO photos VALUES (?,?,?,?)',item) curse.commit() HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Selecting a different superclass
On 17 Dec, 20:33, Chris Rebert c...@rebertia.com wrote: superclass = TraceablePointSet if tracing else PointSet Perfect - many thanks. Good to know I'm absolved from evil, also ;) Peter -- http://mail.python.org/mailman/listinfo/python-list
www.webhizmetlerim.com
Dear Readers; If you write us our web site's queue and page number at google then three of you can get prices from us.We are going to have a sweepstake for this. If you send more mails,you have more chance to win. Our competition is going to finish at 1 February 2009. Please write google 'web tasarım' then write us that which queue and which page our web site www.webhizmetlerim.com is. Also you can help to hear your friends at your list by sending them mails for the competition. PRİCES 1.NOTEBOOK 2.MP4 3.MP3 Write us your name,surname and mail adress to www.webhizmetlerim.com communication part,then get the prize. And send this mail to your friends then they will get the prices too.Send mails every day and have more chance. -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
On Dec 18, 5:09 am, Ivan Illarionov ivan.illario...@gmail.com wrote: On 18 ÄÅË, 03:51, Aaron Brady castiro...@gmail.com wrote: (snip) How did you get a reference to the original string object, with which to increment its reference count? Use the O! format instead of s: PyObject *pystr; ... PyArg_ParseTuple(args, O!, PyStringObject, pystr) ... edit: PyString_Type Then you can use PyString_AS_STRING explicitly, and control ref. counts yourself. How do you know its length to copy it into your own buffer? Use the s# format, as Gabriel has said. Ivan I see. Do I read correctly that 's' is only useful when the argument's position is known? Otherwise you can't know its length or change its reference count. -- http://mail.python.org/mailman/listinfo/python-list
Re: help I'm getting delimited
On 18 dec, 00:06, John Machin sjmac...@lexicon.net wrote: On Dec 18, 3:15 am, aka alexoploca...@gmail.com wrote: Do you mean that this file was created by whatever.UnicodeWriter? If so, did you just now discover this information? How do you know that the UnicodeWriter is functioning perfectly? What does functioning perfectly mean to you? In particular, what encoding is it using? Which do you mean: (a) you typed those lines into Notepad yourself (b) you took a copy of a file created by whatever.UnicodeWriter, opened it with Notepad, trimmed off some rows and columns, and saved it again ? Here's a likely hypothesis: the file was written in utf16. In that case: either (i) you really want utf16 (why?), so: (1) the csv module will not cope with it, and is not expected to cope with it (2) the whatever.UnicodeReader should (in order of preference): (a) be allowed to find out for itself that 'utf16' is the go (b) be told explicitly that 'utf16' is the go (c) be served with a bug report OR (ii) you really want utf8, so: (1) the csv module should be happy (2) the whatever.UnicodeWriter should be told to use 'utf8' (3) the whatever.UnicodeReader should (in order of preference): [as above but s/16/8/] The csv file originally was created by the UnicodeWriter class and was used for a mailmerge function with Microsoft Word which all functioned perfectly. The reverse did not: read back the outputted file so at last I editted it in Notepad, cutting off columns, but I didn't know that the encoding would remain even after that because it still caused problems. Now after testing from the Python command line with a csv file generated from Excel I could get it working so it had to be the encoding. Because the write side of my code, which uses the UnicodeWriter, was ok I didn't pay attention to the fact that I had changed the UW class from UTF-8 to UTF-16 because of difficulties with dutch characters like ë and ö. Then at last I tried changing back to UTF-8 and noticed both out -and input was working, including those special characters, so it was my unjustifiable conclusion that I couldn't get around these special characters at the write side without UTF-16 which ultimately got me in trouble with the read side. With your help I got it straight. Once again minimizing the problem to its bare basics and to prevent big steps is the key. Thanks a lot for your help John. BTW, the TurboGears code by the way is not very different from Python, it just uses some extra identifiers. -- http://mail.python.org/mailman/listinfo/python-list
Re: help I'm getting delimited
On 18 dec, 00:06, John Machin sjmac...@lexicon.net wrote: - Tekst uit oorspronkelijk bericht niet weergeven - - Tekst uit oorspronkelijk bericht weergeven - On Dec 18, 3:15 am, aka alexoploca...@gmail.com wrote: Do you mean that this file was created by whatever.UnicodeWriter? If so, did you just now discover this information? How do you know that the UnicodeWriter is functioning perfectly? What does functioning perfectly mean to you? In particular, what encoding is it using? Which do you mean: (a) you typed those lines into Notepad yourself (b) you took a copy of a file created by whatever.UnicodeWriter, opened it with Notepad, trimmed off some rows and columns, and saved it again ? Here's a likely hypothesis: the file was written in utf16. In that case: either (i) you really want utf16 (why?), so: (1) the csv module will not cope with it, and is not expected to cope with it (2) the whatever.UnicodeReader should (in order of preference): (a) be allowed to find out for itself that 'utf16' is the go (b) be told explicitly that 'utf16' is the go (c) be served with a bug report OR (ii) you really want utf8, so: (1) the csv module should be happy (2) the whatever.UnicodeWriter should be told to use 'utf8' (3) the whatever.UnicodeReader should (in order of preference): [as above but s/16/8/] The csv file originally was created by the UnicodeWriter class and was used for a mailmerge function with Microsoft Word which all functioned perfectly. The reverse did not: read back the outputted file so at last I editted it in Notepad, cutting off columns, but I didn't know that the encoding would remain even after that because it still caused problems. Now after testing from the Python command line with a csv file generated from Excel I could get it working so it had to be the encoding. Because the write side of my code, which uses the UnicodeWriter, was ok I didn't pay attention to the fact that I had changed the UW class from UTF-8 to UTF-16 because of difficulties with dutch characters like ë and ö. Then at last I tried changing back to UTF-8 and noticed both out -and input was working, including those special characters, so it was my unjustifiable conclusion that I couldn't get around these special characters at the write side without UTF-16 which ultimately got me in trouble with the read side. With your help I got it straight. Once again minimizing the problem to its bare basics and to prevent big steps is the key. Thanks a lot for your help John. BTW, the TurboGears code is not very different from Python, it just uses some extra identifiers around the Python code. -- http://mail.python.org/mailman/listinfo/python-list
Re: help I'm getting delimited
On Dec 18, 3:15 am, aka alexoploca...@gmail.com wrote: Do you mean that this file was created by whatever.UnicodeWriter? If so, did you just now discover this information? How do you know that the UnicodeWriter is functioning perfectly? What does functioning perfectly mean to you? In particular, what encoding is it using? Which do you mean: (a) you typed those lines into Notepad yourself (b) you took a copy of a file created by whatever.UnicodeWriter, opened it with Notepad, trimmed off some rows and columns, and saved it again ? Here's a likely hypothesis: the file was written in utf16. In that case: either (i) you really want utf16 (why?), so: (1) the csv module will not cope with it, and is not expected to cope with it (2) the whatever.UnicodeReader should (in order of preference): (a) be allowed to find out for itself that 'utf16' is the go (b) be told explicitly that 'utf16' is the go (c) be served with a bug report OR (ii) you really want utf8, so: (1) the csv module should be happy (2) the whatever.UnicodeWriter should be told to use 'utf8' (3) the whatever.UnicodeReader should (in order of preference): [as above but s/16/8/] The csv file originally was created by the UnicodeWriter class and was used for a mailmerge function with Microsoft Word which all functioned perfectly. The reverse did not: read back the outputted file so at last I editted it in Notepad, cutting off columns, but I didn't know that the encoding would remain even after that because it still caused problems. Now after testing from the Python command line with a csv file generated from Excel I could get it working so it had to be the encoding. Because the write side of my code, which uses the UnicodeWriter, was ok I didn't pay attention to the fact that I had changed the UW class from UTF-8 to UTF-16 because of difficulties with dutch characters like ë and ö. Then at last I tried changing back to UTF-8 and noticed both out -and input was working, including those special characters, so it was my unjustifiable conclusion that I couldn't get around these special characters at the write side without UTF-16 which ultimately got me in trouble with the read side. With your help I got it straight. Once again minimizing the problem to its bare basics and preventing too large steps is the key. Thanks a lot for your help John. BTW, the TurboGears code is not very different from Python, it just uses some extra identifiers. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Help] The pywinauto Can't select the MDI's menu using the MenuItems() which return [].
2008/12/18 为爱而生 boyee...@gmail.com: This problem also use the following discription: How to use pywinauto to open WORD and select its Menu. I can't do that and have no idea why! Looking forward your help,Thanks! Word can be automated with COM. My golden rule is that automation via GUI driving is always a last resort. -- Cheers, Simon B. si...@brunningonline.net -- http://mail.python.org/mailman/listinfo/python-list
re.match() performance
Hi everybody! I've written the code below to test the differences in performance between compiled and non-compiled regular expression matching but I don't quite understand the results. It appears that the performance difference is only around 2%, even if I run the import re import time ## Setup pattern = a(.*)/a compiledPattern = re.compile(pattern) longMessage = a+ a * 10 +/a numberOfRuns = 1000 ## TIMED FUNCTIONS startTime = time.clock() for i in range(0, numberOfRuns): re.match(pattern, longMessage) patternMatchingTime = time.clock() - startTime startTime = time.clock() for i in range(0, numberOfRuns): compiledPattern.match(longMessage) compiledPatternMatchingTime = time.clock() - startTime ratioCompiledToNot = compiledPatternMatchingTime / patternMatchingTime ## PRINT OUTS print() print( Pattern Matching Time: + str(patternMatchingTime)) print((Compiled) Pattern Matching Time: + str (compiledPatternMatchingTime)) print() print(Ratio Compiled/NotCompiled: + str(ratioCompiledToNot)) print() -- http://mail.python.org/mailman/listinfo/python-list
re.match() performance
Sorry for the previous post, hit the Enter button by mistake... here's the complete one: Hi everybody! I've written the code below to test the differences in performance between compiled and non-compiled regular expression matching but I don't quite understand the results. It appears that the compiled the pattern only takes 2% less time to process the match. Is there some caching going on in the uncompiled section that prevents me from noticing its otherwise lower speed? Manu import re import time ## Setup pattern = a(.*)/a compiledPattern = re.compile(pattern) longMessage = a+ a * 10 +/a numberOfRuns = 1000 ## TIMED FUNCTIONS startTime = time.clock() for i in range(0, numberOfRuns): re.match(pattern, longMessage) patternMatchingTime = time.clock() - startTime startTime = time.clock() for i in range(0, numberOfRuns): compiledPattern.match(longMessage) compiledPatternMatchingTime = time.clock() - startTime ratioCompiledToNot = compiledPatternMatchingTime / patternMatchingTime ## PRINT OUTS print() print( Pattern Matching Time: + str(patternMatchingTime)) print((Compiled) Pattern Matching Time: + str (compiledPatternMatchingTime)) print() print(Ratio Compiled/NotCompiled: + str(ratioCompiledToNot)) print() -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
Aaron Brady wrote: I see. Do I read correctly that 's' is only useful when the argument's position is known? I assume you meant length. Otherwise you can't know its length or change its reference count. The internal representation of Python byte strings is 0 terminated, so strlen() will work. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: something else instead of PIL?
On Dec 17, 3:48 pm, Reimar Bauer r.ba...@fz-juelich.de wrote: Hi what has happened to PIL? No updates since two years. Or does one know an alternative lib for resizing images? cheers Reimar I have found the FreeImage library with the Python bindings quite workable. I work with multi-page TIF images and this seemed to be the best option. The FreeImage library seems to be actively maintained too (Last release in July 08 with updates to many of the image processing plug- ins). The python bindings took me a bit to understand as they try to emulate PIL, however they are implemented using ctypes, so you can change/manage yourself if needed. I found working directly with the functions exported from the .dll the best option and gave the best performance. Freeimage site: http://freeimage.sourceforge.net/ Python bindings: http://freeimagepy.sourceforge.net/ Hope that helps. Good luck. Working with images/graphics can make my brain hurt sometimes. g. -- http://mail.python.org/mailman/listinfo/python-list
confused about __str__ vs. __repr__
Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! -- http://mail.python.org/mailman/listinfo/python-list
Re: something else instead of PIL?
s...@pobox.com schrieb: Reimar Hi what has happened to PIL? No updates since two years. It's well-written, stable code. As far as I know it does what people want (at least it's done everything I've needed when I've used it). Why should it matter that there hasn't been an official release in two years? I am interested to get some new features added e.g. some special conversion routines for colorblind people. http://scien.stanford.edu/class/psych221/projects/05/ofidaner/colorblindness_project.htm How can that be archieved? cheers Reimar -- http://mail.python.org/mailman/listinfo/python-list
Re: something else instead of PIL?
imageguy schrieb: On Dec 17, 3:48 pm, Reimar Bauer r.ba...@fz-juelich.de wrote: Hi what has happened to PIL? No updates since two years. Or does one know an alternative lib for resizing images? cheers Reimar I have found the FreeImage library with the Python bindings quite workable. I work with multi-page TIF images and this seemed to be the best option. The FreeImage library seems to be actively maintained too (Last release in July 08 with updates to many of the image processing plug- ins). The python bindings took me a bit to understand as they try to emulate PIL, however they are implemented using ctypes, so you can change/manage yourself if needed. I found working directly with the functions exported from the .dll the best option and gave the best performance. Freeimage site: http://freeimage.sourceforge.net/ Python bindings: http://freeimagepy.sourceforge.net/ Hope that helps. Good luck. Working with images/graphics can make my brain hurt sometimes. g. thanks! Reimar -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: re.match() performance
Emanuele D'Arrigo wrote: Sorry for the previous post, hit the Enter button by mistake... here's the complete one: Hi everybody! I've written the code below to test the differences in performance between compiled and non-compiled regular expression matching but I don't quite understand the results. It appears that the compiled the pattern only takes 2% less time to process the match. Is there some caching going on in the uncompiled section that prevents me from noticing its otherwise lower speed? [snip] Yes, the regular expression is compiled and cached internally. -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
Stefan Behnel wrote: Aaron Brady wrote: I see. Do I read correctly that 's' is only useful when the argument's position is known? I assume you meant length. Otherwise you can't know its length or change its reference count. The internal representation of Python byte strings is 0 terminated, so strlen() will work. But remember that a bytestring can contain a zero byte (chr(0) in Python 2.x). -- http://mail.python.org/mailman/listinfo/python-list
Re: re.match() performance
Emanuele D'Arrigo wrote: Sorry for the previous post, hit the Enter button by mistake... here's the complete one: Hi everybody! I've written the code below to test the differences in performance between compiled and non-compiled regular expression matching but I don't quite understand the results. It appears that the compiled the pattern only takes 2% less time to process the match. Is there some caching going on in the uncompiled section that prevents me from noticing its otherwise lower speed? Yes. There is even a purge-function to clear that cache, for whatever reason. To answer that question yourself, you could have taken a look into the python library, it's not as scary as you might think :) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Tino Wildenhain wrote: Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! Because the __str__ of dict uses __repr__. Do a print x to see that print itself does use __str__. BTW, could you configure your newsreader to not put the GMANE-group as follow-up? NNTP doesn't work for that. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: re.match() performance
Emanuele D'Arrigo man...@gmail.com wrote: I've written the code below to test the differences in performance between compiled and non-compiled regular expression matching but I don't quite understand the results. It appears that the compiled the pattern only takes 2% less time to process the match. Is there some caching going on in the uncompiled section that prevents me from noticing its otherwise lower speed? Running your sample i got also a 2% the first time, but next time i got a different speed : 4 time faster. Running 1st time Pattern Matching Time: 0.122432 (Compiled) Pattern Matching Time: 0.12012 Ratio Compiled/NotCompiled: 0.981116048092 2nd time and more Pattern Matching Time: 0.00257 (Compiled) Pattern Matching Time: 0.000619 Ratio Compiled/NotCompiled: 0.240856031128 Config python 2.5.1 / MacOS X 10.5 -- Pierre-Alain Dorangehttp://microwar.sourceforge.net/ Ce message est sous licence Creative Commons by-nc-sa-2.0 http://creativecommons.org/licenses/by-nc-sa/2.0/fr/ -- http://mail.python.org/mailman/listinfo/python-list
Re: re.match() performance
Emanuele D'Arrigo wrote: I've written the code below to test the differences in performance between compiled and non-compiled regular expression matching but I don't quite understand the results. It appears that the compiled the pattern only takes 2% less time to process the match. Is there some caching going on in the uncompiled section that prevents me from noticing its otherwise lower speed? Yes: import re re._cache {} re.match(yadda, ) re._cache {(class 'str', 'yadda', 0): _sre.SRE_Pattern object at 0x2ac6e66e9e70} Hint: questions like this are best answered by the source code, and Python is open source. You don't even have to open an editor: import inspect print(inspect.getsource(re.match)) def match(pattern, string, flags=0): Try to apply the pattern at the start of the string, returning a match object, or None if no match was found. return _compile(pattern, flags).match(string) print(inspect.getsource(re._compile)) def _compile(*key): # internal: compile pattern cachekey = (type(key[0]),) + key p = _cache.get(cachekey) if p is not None: return p pattern, flags = key if isinstance(pattern, _pattern_type): if flags: raise ValueError( Cannot process flags argument with a compiled pattern) return pattern if not sre_compile.isstring(pattern): raise TypeError(first argument must be string or compiled pattern) p = sre_compile.compile(pattern, flags) if len(_cache) = _MAXCACHE: _cache.clear() _cache[cachekey] = p return p Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: ... So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Minor Typo in doc
Hi There is a minor typo in the new doc in: http://www.python.org/doc/2.6/library/signal.html -- signal.SIG_DFL¶ This is one of two standard signal handling options; it will simply perform the default function for the signal. For example, on most systems the default action for SIGQUIT is to dump core and exit, while the default action for SIGCLD is to simply ignore it. -- SIGCLD should be SIGCHLD Should I make a bug report in http://bugs.python.org? Grüessli -- Kurt Müller, m...@problemlos.ch -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
On Dec 18, 6:43 am, Stefan Behnel stefan...@behnel.de wrote: Floris Bruynooghe wrote: I'm slightly confused about some memory allocations in the C API. If you want to reduce the number of things you have to get your head around, learn Cython instead of the raw C-API. It's basically Python, does all the reference counting for you and also reduces the amount of memory handling you have to care about. http://cython.org/ Sure that is a good choice in some cases. Not in my case currently though, it would mean another build dependency on all our build hosts and I'm just (trying to) stop an existing extension module from leaking memory, no way I'm going to re-write that from scratch. But interesting discussion though, thanks! Floris -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Tino Wildenhain wrote: Neal Becker wrote: ... So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino First, I'd like to know if there is a rationale for the current design. Am I correct in thinking this is a defect? -- http://mail.python.org/mailman/listinfo/python-list
Re: something else instead of PIL?
Reimar I am interested to get some new features added e.g. some special Reimar conversion routines for colorblind people. Reimar http://scien.stanford.edu/class/psych221/projects/05/ofidaner/colorblindness_project.htm Reimar How can that be archieved? Contact Fredrik Lundh? http://effbot.org/ Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: help I'm getting delimited
On Wed, 2008-12-17 at 06:28 -0800, aka wrote: Hi John, thanks. You're right, I didn't past the method header because I thought it didn't matter when the input filename is hardcoded. The try/except isn't very helpful indeed so I commented it out. You're right I wrongly referred to the UnicodeReader class in my first post because that's ultimately where I want to go so I outcommented it here for you to see. The fact is that neither csv.reader nor the UnicodeReader will read the file, while writing with the UnicodeWriter works like a charm. That's why I put str() around roles to see any content. I simplified the csv-file by cutting off columns without result. The file looks now like: id;company;department 12;Cadillac;Research 11;Ford;Accounting 10;Chrysler;Sales The dictionary on the return is because this code is part of my TurboGears application. The entire method is: import csv from utilities.urw import UnicodeWriter, UnicodeReader @expose(allow_json=True) def import_roles(self, input=None, *args, **kwargs): inp = 'C:/temp/test.csv' roles = [] msg = '' ## try: fp = open(inp, 'rb') reader = csv.reader(fp, dialect='excel', delimiter=';') ## reader = UnicodeReader(fp, dialect='excel', delimiter=';') for r in reader: roles.append(r[0]) fp.close() ## except: ## msg = Something's wrong with the csv.reader return dict(filepath=inp, roles=str(roles), msg=msg) csv.reader results in: for r in reader: Error: line contains NULL byte Use of UnicodeReader results in: UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 0: unexpected code byte This looks like the problem might be in your choice of codec. A UTF-8 file will never have 0xff in it, and would be unlikely to have 0x00 either. My guess is that you will need to decode your input from UTF-16. (and then use the UnicodeReader). Will post only complete code from now on thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
On Thu, 18 Dec 2008 09:51:01 -0500, Neal Becker ndbeck...@gmail.com wrote: Tino Wildenhain wrote: Neal Becker wrote: ... So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino First, I'd like to know if there is a rationale for the current design. Am I correct in thinking this is a defect? There is a rationale. Consider: class strit(object): ... def __init__(self, it): ... self.it = it ... def __repr__(self): ... return str(self.it) ... This will let us see what a dict.__str__ which called __str__ on the objects in it would look like. So first, something simple: print str({strit(['foo']): 'bar'}) {['foo']: 'bar'} Mildly confusing - you can't use a list as a dict key! But it could be worse: print str({strit(1: 2, 3): 'bar'}) {1: 2, 3: 'bar'} Wait - *how* many items are in that dictionary? Hopefully that makes the rationale clear - when a human is looking at the str of a dict (and a human is ostensibly the intended audience) - using the __repr__ of the contained objects makes it easier for the human to understand what's in the dict. Using __str__ would make it much harder in many cases. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: ... So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino First, I'd like to know if there is a rationale for the current design. Am I correct in thinking this is a defect? I don't think so. First of all, there is no generic way of printing a collection. And the current implementation tries to give an overview what is contained in the collection, without trying to make it fancy - any such thing needed to be hand-coded anyway. Using repr for that is better suited, as for example string keys are printed with quotes around them - making clear what they are, and not irritating the user through potentially contained spaces or even things that look as if they are python objects. For example, if repr *wasn't* used, { {foo=bar} : baz} would be printed {{foo=bar} : baz} Which is *not* what the dictionary actually contains! The same goes for unicode-objects. They appear with their funny characters as \xXX-codes - instead of bailing out on you with unicode-errors. So, IMHO the current behavior is desired. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Selecting a different superclass
On Dec 18, 4:36 am, psaff...@googlemail.com psaff...@googlemail.com wrote: On 17 Dec, 20:33, Chris Rebert c...@rebertia.com wrote: superclass = TraceablePointSet if tracing else PointSet Perfect - many thanks. Good to know I'm absolved from evil, also ;) Peter Another way would be to have a factory function that builds the appropriate instance: class PointSet(object): @staticmethod def Create_Instance(*args, **keyargs): if TRACE_DATA: return TraceablePointSet(*args, **keyargs) else: return PointSet(*args, **keyargs) # Normal release class body goes here. class TraceablePointSet(object): # Normal debug class body goes here point_set = PointSet.Create_Instance() This is the way you'd do things if you wanted a mix of your release class instances and debug class instances. Perhaps there's only a certain set of initial arguments that need to be checked, or maybe the TRACE_DATA global can change. Inside the body you could also explicitly check for a trace parameter, like so: if keyargs.get( 'trace_data', False ): # Create debug instance That would allow you to create debug instances only when you want them. A variation on Chris Rebert's option is also possible: class _PointSet(object): # Normal body definition here class _TraceablePointSet(object): # Traceable body definition here if TRACE_DATA: PointSet = _TraceablePointSet else: PointSet = _PointSet Hope this helps. Python's dynamic nature loves you! --Jason -- http://mail.python.org/mailman/listinfo/python-list
Re: Minor Typo in doc
Kurt Mueller wrote: Hi There is a minor typo in the new doc in: http://www.python.org/doc/2.6/library/signal.html -- signal.SIG_DFL¶ This is one of two standard signal handling options; it will simply perform the default function for the signal. For example, on most systems the default action for SIGQUIT is to dump core and exit, while the default action for SIGCLD is to simply ignore it. -- SIGCLD should be SIGCHLD Should I make a bug report in http://bugs.python.org? Yes. The documentation give you a link to follow from the bottom of each page. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Extracting data from XML containing CDATA and store data in a .dbf file
I am looking for advice/efficient script to extract data from XML containing CDATA. I wish to extract all the data and store it in a .dbf file. Regards. David -- http://mail.python.org/mailman/listinfo/python-list
psycopg2 and large queries
psycopg2 is said to be db api 2.0 compilant, but apparent it is buggy. By default, when I create a cursor with cur = conn.cursor() then it creates a cursor that will fetch all rows into memory, even if you call cur.fetchone() on it. (I tested it, see below.) I was looking for psycopg2 documentation, but I found nothing. However, I found some posts telling that named cursors do support fetching a single row at a time. Here is how to create a named cursor: cur = conn.cursor('mycursor') This is very strange, because DB API 2.0 does not have this feature. Why this feature was created, and how to use it? Not documented. Anyway, I wrote a program that uses named/nameless cursors, sets cur.arraysize to different values before callig cur.execute, then fetches all rows with fetchone(). I used the following query on a bigger table: select name from product limit 100 Here are the test results for fetchone(): Named cursor, arraysize=12613 rec/sec, query opens in 0.005 sec, uses only a few memory Named cursor, arraysize=10002831 rec/sec, query opens in 0.005 sec, uses only a few memory Nameless cursor, arraysize=1 41335 rec/sec, query opens in 28 sec, uses 100MB+ memory Nameless cursor, arraysize=1 39602 rec/sec, query opens in 25.8 sec, uses 100MB+ memory It is clear that named cursors have very bad performance, I cannot use them. Nameless cursors cannot be used either, because they are stressing the system, put 100% disk I/O and big memory usage, without any good reason. The only one solution I found is to use named cursors, and use fetchmany(100) instead of fetchone(). This results in fast opening (0.005 sec) of the cursor, and good speed (30 000 rec/sec, about 75% of the nameless version). (Do I really need to implement buffering in Python to be efficient???) However, this is also not usable, because named cursors do not have a .description property! You can try this: cur = conn.cursor('mycursor') cur.execute('select name from product limit 100') print repr(cur.description) # - None This is unacceptable! This is not DB API 2.0 compilant. I have to know the names of the columns, how can I do that? What am I doing wrong? Please help me! Thanks, Laszlo p.s.: I tried to subscribe to the psycopg mailing list, but the confirmation email did not arrive in 6 hours... -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Diez B. Roggisch wrote: Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: ... So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino First, I'd like to know if there is a rationale for the current design. Am I correct in thinking this is a defect? I don't think so. First of all, there is no generic way of printing a collection. And the current implementation tries to give an overview what is contained in the collection, without trying to make it fancy - any such thing needed to be hand-coded anyway. Using repr for that is better suited, as for example string keys are printed with quotes around them - making clear what they are, and not irritating the user through potentially contained spaces or even things that look as if they are python objects. For example, if repr *wasn't* used, { {foo=bar} : baz} would be printed {{foo=bar} : baz} Which is *not* what the dictionary actually contains! The same goes for unicode-objects. They appear with their funny characters as \xXX-codes - instead of bailing out on you with unicode-errors. So, IMHO the current behavior is desired. So if I want to overload something in my custom class, so that I get a nice string whether it's printed directly, or as part of a container, what is the recommendation? Overload both __str__ and __repr__? -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Diez B. Roggisch wrote: Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: ... So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino First, I'd like to know if there is a rationale for the current design. Am I correct in thinking this is a defect? I don't think so. First of all, there is no generic way of printing a collection. And the current implementation tries to give an overview what is contained in the collection, without trying to make it fancy - any such thing needed to be hand-coded anyway. Using repr for that is better suited, as for example string keys are printed with quotes around them - making clear what they are, and not irritating the user through potentially contained spaces or even things that look as if they are python objects. For example, if repr *wasn't* used, { {foo=bar} : baz} would be printed {{foo=bar} : baz} Which is *not* what the dictionary actually contains! The same goes for unicode-objects. They appear with their funny characters as \xXX-codes - instead of bailing out on you with unicode-errors. So, IMHO the current behavior is desired. So if I want to overload something in my custom class, so that I get a nice string whether it's printed directly, or as part of a container, what is the recommendation? Overload both __str__ and __repr__? Yep. And it's easy enough if you don't care about them being different.. def __repr__(self): return str(self) BTW, you newsreader still produces bogus follow-ups, which makes replying to you unnerving. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Diez B. Roggisch wrote: Yep. And it's easy enough if you don't care about them being different.. def __repr__(self): return str(self) If I ever wanted __str__ and __repr__ to return the same thing, I would make them equal: def __str__(self): return 'whatever you want' __repr__ = __str__ That makes it more obvious to me what's going on. As a bonus, it saves one method call for every repr call. /MiO -- http://mail.python.org/mailman/listinfo/python-list
Is this pythonic?
x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Quoth Diez B. Roggisch de...@nospam.web.de: Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: ... That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. [...] Every class is free on how to best implement __str__, you will find the same behavior on tuple and list as well. Maybe its discussable to change the implementation sensibly, best if you would come with a proposal? Perhaps pprint.pprint is a starting point? Regards Tino First, I'd like to know if there is a rationale for the current design. Am I correct in thinking this is a defect? I don't think so. First of all, there is no generic way of printing a collection. And the current implementation tries to give an overview what is contained in the collection, without trying to make it fancy - any such thing needed to be hand-coded anyway. Using repr for that is better suited, as for example string keys are printed with quotes around them - making clear what they are, and not irritating the user through potentially contained spaces or even things that look as if they are python objects. For example, if repr *wasn't* used, { {foo=bar} : baz} would be printed {{foo=bar} : baz} Which is *not* what the dictionary actually contains! The same goes for unicode-objects. They appear with their funny characters as \xXX-codes - instead of bailing out on you with unicode-errors. Note that this last is no longer true in Python 3.0. There, repr prints into the current encoding of the output, and so you may get decode errors. This is an accepted usability tradeoff, as it allows people using these character sets (and who therefore will have terminals set to display them!) to actually see the characters in their data. If you need the old behavior you use 'ascii'. --RDM -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this pythonic?
ipyt...@gmail.com a écrit : x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? functional programming addicts might say yes. But as far as I'm concerned, I find it a bit too nested... -- http://mail.python.org/mailman/listinfo/python-list
mysql with python
can anybody give me the link where I can directly download the _mysql.dll file required by MySQLdb for Python 2.6. I tried to build MySQL db but there is error: None. Is there a need for me to step down to Python 2.5 ?? Further any comments on the best ORM for Python ?? -- http://mail.python.org/mailman/listinfo/python-list
Tkinter unbinding
I've done a lot of googling for this topic and I fear that it's not possible. I have a widget that is overloaded with several bindings. I want to be able to unbind one method form the same Event without destroying all the other bindings to the same event that's associated to the same widget. For example: import Tkinter def test(): print 'test' def test2(): print 'test2' root = Tkinter.Tk() funcid1 = root.bind(1, lambda e: test()) funcid2 = root.bind(1, lambda e: test2(), add='+') root.unbind(1, funcid2) root.mainloop() When run neither 1 binding will exist against the root because the unbind will unbind all the functions associated with that event. However, in this example, I only want to unbind test2 not test1. Any help is greatly appreciated. Thanks! Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
w.unbind ( sequence, funcid=None ) This method deletes bindings on w for the event described by sequence. If the second argument is a callback bound to that sequence, that callback is removed and the rest, if any, are left in place. If the second argument is omitted, all bindings are deleted. see http://infohost.nmt.edu/tcc/help/pubs/tkinter/universal.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
funcid1 = root.bind(1, lambda e: test()) funcid2 = root.bind(1, lambda e: test2(), add='+') root.unbind(1, funcid2) Isn't this what I've done in my example code? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this pythonic?
ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? You should try LISP. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
Yea, my answer was really not a helping answer(sorry) just showing exactly why this will not work with w.unbind(). Why do you need two separate functions to bind the same event?? You cannot combine the two?? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this pythonic?
On Dec 18, 11:08 am, ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? Lisp and Scheme programmers love that style. You can tell by the number of parentheses :-). In Python people usually use an intermediate variable to break things up a bit but the amount of acceptable nesting is a matter of personal style. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
On Dec 18, 11:40 am, r rt8...@gmail.com wrote: Yea, my answer was really not a helping answer(sorry) just showing exactly why this will not work with w.unbind(). Why do you need two separate functions to bind the same event?? You cannot combine the two?? I can't combine the two in my app unfortunately. The binding is to a custom widget that upon it being destroyed the binding is no longer valid. I can work around this by being hacky but I prefer to delete the one binding itself which would make things cleaner. -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Basically because there are too many right ways to format the resulting report. Space separated? Tab separated? One per line? Boxes around them? As HTML definition lists? Creating a standard report form would take a lot of work and wouldn't, finally, solve very many peoples' problems. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Location HTTP Header
On Dec 17, 6:47 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 17 Dec 2008 20:52:42 -0200, ptn tn.pa...@gmail.com escribió: I tried this stupid script on my server: #! /usr/bin/env python print 'Location:http://www.google.com\n' and it didn't work, I get a blank page. I first tried the Location header in another script, and when execution got to that point, it would just sort of ignore it, because the script would keep running to the end of the code (or stop at some unhandled exception). I assume this is a cgi script. For the Location field to be relevant, the Status should be a 3xx (like 307 Temporary Redirect, or 302 Found) In your case, your server probably has already sent a 200 OK response, so Location is ignored. Try adding a Status line -before Location above- like: print 'Status: 302 Found Any ideas? I'd use a different protocol other than CGI... -- Gabriel Genellina M no, that didn't do it. The script now is: #! /usr/bin/env python print 'Status: 302 Found' print 'Location: http://www.google.com\n' but still nothing happens, I get the same blank page. Since the sscript is so simple, maybe it is a matter of server configuration? Is that possible? -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 and large queries
On 18 Des, 16:34, Laszlo Nagy gand...@shopzeus.com wrote: psycopg2 is said to be db api 2.0 compilant, but apparent it is buggy. By default, when I create a cursor with cur = conn.cursor() then it creates a cursor that will fetch all rows into memory, even if you call cur.fetchone() on it. (I tested it, see below.) Yes, I filed a bug against psycopg2 on this very subject, although the project doesn't seem to have a bug-tracker any more. I was looking for psycopg2 documentation, but I found nothing. However, I found some posts telling that named cursors do support fetching a single row at a time. Here is how to create a named cursor: cur = conn.cursor('mycursor') This is very strange, because DB API 2.0 does not have this feature. Why this feature was created, and how to use it? Not documented. The reason is that PostgreSQL supports server-side cursors through a DECLARE ... CURSOR statement, but that statement can only be used with certain SQL statements. Other DB-API modules employ simple but imperfect tricks to guess whether the statement being issued is compatible with DECLARE ... CURSOR before automatically creating a cursor, but the psycopg2 maintainers refused to introduce such a feature as part of the default behaviour. I didn't pursue the avenue of making a suitable set of patches to satisfy both them and myself, and I subsequently went back to using pyPgSQL instead. [...] It is clear that named cursors have very bad performance, I cannot use them. Nameless cursors cannot be used either, because they are stressing the system, put 100% disk I/O and big memory usage, without any good reason. The only one solution I found is to use named cursors, and use fetchmany(100) instead of fetchone(). This results in fast opening (0.005 sec) of the cursor, and good speed (30 000 rec/sec, about 75% of the nameless version). (Do I really need to implement buffering in Python to be efficient???) You really don't want to be traversing large data sets using fetchone, anyway. My approach (using pyPgSQL) involves fetchmany and then looping over each batch of results, if I really have to process the data in Python; most of the time I can do the processing in the database itself. However, this is also not usable, because named cursors do not have a .description property! You can try this: cur = conn.cursor('mycursor') cur.execute('select name from product limit 100') print repr(cur.description) # - None This is unacceptable! This is not DB API 2.0 compilant. I have to know the names of the columns, how can I do that? What am I doing wrong? Please help me! I'm not really a user of the description property, so I can't advise you there. Strictly, psycopg2 is DB-API compliant, but the interaction between result sets and cursors really doesn't live up to what the specification suggests is possible. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
Maybe someone will chime in with an answer, sorry i could not help. ponder this, i must... -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 and large queries
Paul Boddie wrote: [...] You really don't want to be traversing large data sets using fetchone, anyway. My approach (using pyPgSQL) involves fetchmany and then looping over each batch of results, if I really have to process the data in Python; most of the time I can do the processing in the database itself. Hmm, pypgsql doesn't provide a 2.5 Windows installer. I take it you aren't a Windows user ... ? regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Mel wrote: Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Basically because there are too many right ways to format the resulting report. Space separated? Tab separated? One per line? Boxes around them? As HTML definition lists? Creating a standard report form would take a lot of work and wouldn't, finally, solve very many peoples' problems. Mel. Thanks, but the question of how to format the container is different from how to format the primitive elements of the container. I was suggesting that printing an element of a container should be consistent with printing the element without the container, i.e., print [a] should be consistent with print a -- http://mail.python.org/mailman/listinfo/python-list
Adjusting filename and line number
Hello, I'm working with some embedded python and would like to be able to adjust the reported filename and line number of some embedded user- written code so that errors returned coincide with things the user might actually be familiar with. In perl I could do this by adjusting the filename and line within a script like so: foo.pl -- #!/usr/bin/env perl #line 1000 myfile.txt this is a syntax error $ perl foo.pl Can't locate object method a via package syntax (perhaps you forgot to load syntax?) at myfile.txt line 1000. For what it's worth, the same directive also works as a C preprocessor macro. I have searched for ways of managing this in python, but so far have not found any way of accomplishing this. Anyone know how it could be done? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Is this pythonic?
On Dec 18, 8:45 am, prueba...@latinmail.com wrote: On Dec 18, 11:08 am, ipyt...@gmail.com wrote: x.validate_output(x.find_text(x.match_filename (x.determine_filename_pattern(datetime.datetime.now() Is it even good programming form? Lisp and Scheme programmers love that style. You can tell by the number of parentheses :-). In Python people usually use an intermediate variable to break things up a bit but the amount of acceptable nesting is a matter of personal style. I'd say it's fine but breaking up the statement once or twice is a good idea just because if one of the function calls in this nested thing throws an exception, a smaller statement with fewer calls makes for a far more readable traceback. And I hope that this whole statement all lives inside of a method in the same x class, or is a higher-level class that makes use of this behavior? If not, you may want to consider doing so. class X(object): @property def todays_filepattern(self): return self.match_filename( self.determine_filename_pattern( datetime.datetime.now())) def validate_todays_files(self): return self.validate_output(self.find_text (self.todays_filepattern)) -- http://mail.python.org/mailman/listinfo/python-list
how to dock another application under Linux ?
hello, Under windows it's fairly easy to capture an application and dock in to your own wxPython application, something like this: - start the external application from within wxPython - give the caption of the application a special name - find de windows handler of the applications mainform - tell the applications mainform, that some wxpanel is the parent I use this to dock VPython in wxPython. Is there a similar solution for Linux ( and Mac) ? thanks, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
On Dec 18, 12:49 pm, r rt8...@gmail.com wrote: Maybe someone will chime in with an answer, sorry i could not help. ponder this, i must... Regardless, thanks for your help! I truly appreciate it. Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
On Dec 18, 12:49 pm, r rt8...@gmail.com wrote: Maybe someone will chime in with an answer, sorry i could not help. ponder this, i must... Regardless, thanks for your help! I truly appreciate it. Roger. -- http://mail.python.org/mailman/listinfo/python-list
IDLE cursor color
I am working with IDLE, version 1.2.2 I've changed the colors theme using the Options Configure IDLE... menu option. I've chosen a black background for all the items, so now my work area is black, and everything is OK, except for the fact that I can't see where the cursor is located, I mean, I don't know in which part of the window I am going to write. The cursor is blinking black, but I don't know how to change it. Please, any suggestion, hint, tip or clue?? Thank you in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Location HTTP Header
use LiveHTTPHeaders with firefox and show us browser-server interaction -- http://mail.python.org/mailman/listinfo/python-list
Factoring Polynomials
I am trying to write a simple application to factor polynomials. I wrote (simple) raw_input lines to collect the a, b, and c values from the user, but I dont know how to implement the quadratic equation x = (-b +or- (b^2 - 4ac)^1/2) / 2a into python. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
On Dec 18, 12:49 pm, r rt8...@gmail.com wrote: Maybe someone will chime in with an answer, sorry i could not help. ponder this, i must... Regardless, thanks for your help! I truly appreciate it. Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
On Dec 18, 12:49 pm, r rt8...@gmail.com wrote: Maybe someone will chime in with an answer, sorry i could not help. ponder this, i must... Regardless, thanks for your help! I truly appreciate it. Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE cursor color
in IDLE go to: Options - Configure IDLE - Highlightingtab... 1.) in the box click the word cursor 2.) press the button that says Choose Color for 3.) Pick a color and save the changes viola! you did it! :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Factoring Polynomials
On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: I am trying to write a simple application to factor polynomials. I wrote (simple) raw_input lines to collect the a, b, and c values from the user, but I dont know how to implement the quadratic equation x = (-b +or- (b^2 - 4ac)^1/2) / 2a into python. Any ideas? with numpy: from numpy import * s=[1,-1] x = -b+s*sqrt( b**2-4*a*c )/(2*a) Eric http://codeslash.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE cursor color
On 18 dic, 20:52, r rt8...@gmail.com wrote: in IDLE go to: Options - Configure IDLE - Highlightingtab... 1.) in the box click the word cursor 2.) press the button that says Choose Color for 3.) Pick a color and save the changes viola! you did it! :) Thank you! I don't understand... I have tried that before and it didn't work. Now it does!! :-S Previously, I changed the cursor color to green, but nothing happened. That's why I sent the message to the list. Now I've changed it again to pink, and now I can see it, blinking and blinking... :-) Thanks again! -- Vicent -- http://mail.python.org/mailman/listinfo/python-list
Re: Factoring Polynomials
On Dec 18, 11:52 am, eric e...@ericaro.net wrote: On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: I am trying to write a simple application to factor polynomials. I wrote (simple) raw_input lines to collect the a, b, and c values from the user, but I dont know how to implement the quadratic equation x = (-b +or- (b^2 - 4ac)^1/2) / 2a into python. Any ideas? with numpy: from numpy import * s=[1,-1] x = -b+s*sqrt( b**2-4*a*c )/(2*a) Erichttp://codeslash.blogspot.com Ahh. Great.. thank you. I didnt know about the sqrt function.. saves me from doing ^1/2. Thanks again. -CD -- http://mail.python.org/mailman/listinfo/python-list
Re: IDLE cursor color
also try the python forum, great place for beginners... http://www.python-forum.org/pythonforum/index.php -- http://mail.python.org/mailman/listinfo/python-list
Re: Factoring Polynomials
On Thu, 2008-12-18 at 11:52 -0800, eric wrote: On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: I am trying to write a simple application to factor polynomials. I wrote (simple) raw_input lines to collect the a, b, and c values from the user, but I dont know how to implement the quadratic equation x = (-b +or- (b^2 - 4ac)^1/2) / 2a into python. Any ideas? with numpy: from numpy import * s=[1,-1] x = -b+s*sqrt( b**2-4*a*c )/(2*a) Eric Without the Nump. def polynomial(a, b, c): N = ((b**2 - 4*a*c)**.5) / 2*a return (-b + N, -b - N) -- http://mail.python.org/mailman/listinfo/python-list
Re: Factoring Polynomials
eric wrote: On Dec 18, 8:37 pm, collin.da...@gmail.com wrote: ... I dont know how to implement the quadratic equation ... with numpy: from numpy import * s=[1,-1] x = -b+s*sqrt( b**2-4*a*c )/(2*a) Numpy is pretty heavyweight for this. For built in modules you have a few choices: For real results: from math import sqrt For complex results: from cmath import sqrt or you can simply use: (value) ** .5 Then you can do something like: def quadsolve(a, b, c): try: discriminant = sqrt(b**2 - 4 * a * c) except ValueError: return () # No results at all. if discriminant: # two results return ((-b - discriminant) / (2 * a), (-b + discriminant) / (2 * a)) else: # a single result (discriminant is zero) return (-b / (2 * a),) --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
On Thu, 2008-12-18 at 13:35 -0500, Neal Becker wrote: Mel wrote: Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Basically because there are too many right ways to format the resulting report. Space separated? Tab separated? One per line? Boxes around them? As HTML definition lists? Creating a standard report form would take a lot of work and wouldn't, finally, solve very many peoples' problems. Mel. Thanks, but the question of how to format the container is different from how to format the primitive elements of the container. I was suggesting that printing an element of a container should be consistent with printing the element without the container, i.e., print [a] should be consistent with print a Well, first of all, an object is an object. Whether it is a container or not is a matter of semantic convenience. And how an object prints itself is up to that object and that object alone. If the object chooses to recursively call __str__ on its elements, it is free to do so, but since that causes ambiguity (as many people have pointed out), python has (wisely) chosen to use repr instead. If I wanted to implement a list-like class that doesn't show it's elements at all when printed, but instead shows its length, I am free to do so. For example: hl = HiddenList(1,2,3) hl HiddenList object: length=3 hl[1] 2 (Implementation of HiddenList left as an exercise for the reader.) If you want to implement a list-like object that returns the str of its elements, go right ahead, or implement a function that digs into containers and creates its own list representation for them. But that's not how python works by default, nor should it be, for reasons already explained by others. Cheers, Cliff -- http://mail.python.org/mailman/listinfo/python-list
Re: Factoring Polynomials
On Dec 18, 8:47 pm, Scott David Daniels scott.dani...@acm.org wrote: else: # a single result (discriminant is zero) return (-b / (2 * a),) Maybe make that (-b / (2. * a)) to avoid getting funny results when a and b are integers. (Or do a from __future__ import division, or use Python 3.0, or ) And to make the function more bullet-proof, you might want to do something like (untested): from math import copysign [rest of example as in Scott's post] if discriminant: # two results root1 = (-b - copysign(discriminant, b))/(2*a) root2 = c/(a*root1) return (root1, root2) to avoid numerical problems when b*b is much larger than abs(a*c). Compare with the results of the usual formula when a = c = 1, b = 10**9, for example. But that still doesn't help you when the computation of the discriminant underflows or overflows... Isn't floating-point a wonderful thing! :) Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 and large queries
On 18 Des, 19:09, Steve Holden st...@holdenweb.com wrote: Hmm, pypgsql doesn't provide a 2.5 Windows installer. I take it you aren't a Windows user ... ? Well, there are plenty of PostgreSQL modules around these days, and even if pyPgSQL isn't suitable, I'm sure that there must be one which can be made to work on Windows and to support server-side cursors. See here for more: http://wiki.python.org/moin/PostgreSQL Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Mikael Olofsson wrote: Diez B. Roggisch wrote: Yep. And it's easy enough if you don't care about them being different.. def __repr__(self): return str(self) If I ever wanted __str__ and __repr__ to return the same thing, I would make them equal: def __str__(self): return 'whatever you want' __repr__ = __str__ That makes it more obvious to me what's going on. As a bonus, it saves one method call for every repr call. Or just define __repr__(). str() falls back to __repr__() if __str__() is not defined. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
J. Cliff Dyer wrote: ... how an object prints itself is up to that object and that object alone If I wanted to implement a list-like class that doesn't show it's elements at all when printed, but instead shows its length, I am free to do so. For example: hl = HiddenList(1,2,3) hl HiddenList object: length=3 hl[1] 2 (Implementation of HiddenList left as an exercise for the reader.) And just so some of you who wonder how hard this implementation is: (2.4.X, 2.5.X, 2.6.X): class HiddenList(list): def __repr__(self): return '%s object: length=%s' % ( type(self).__name__, len(self)) (3.0): class HiddenList(list): def __repr__(self): return '{0} object: length={1}'.format( type(self).__name__, len(self)) --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 and large queries
Well, there are plenty of PostgreSQL modules around these days, and even if pyPgSQL isn't suitable, I'm sure that there must be one which can be made to work on Windows and to support server-side cursors. See here for more: http://wiki.python.org/moin/PostgreSQL I'm just looking for something that can replace psycopg2, because of the bug mentioned in my original post. Here are my options: - psycopg1: development stalled - psycopg2: memory bug and/or not db api compilant (see my original post) - pyPgSQL: looks like that the last release was in mid 2006 (and it depends on mxDateTime - licensing problems) - mxODBC: commercial - PyGresSQL: apparently, it does not support fetching one row, only fetching all rows (see: http://www.pygresql.org/pg.html#getresult-get-query-values-as-list-of-tuples), so this is not an option. (Yes, it also has a db api compilant module, but it is only a wrapper around pgqueryobject, and it does not support server side cursors...) So there are many options, but do we have one that: 1. supports server side cursors (fetch some rows after opening the query, but not all of them) 2. open source, with no licensing problems 3. actively maintained Thanks, Laszlo -- http://mail.python.org/mailman/listinfo/python-list
Re: confused about __str__ vs. __repr__
Neal Becker wrote: Mel wrote: Neal Becker wrote: Tino Wildenhain wrote: Neal Becker wrote: Reading some FAQ, I see that __str__ is meant for human eyes. But it seems that: class X(object): def __str__(self): return str def __repr__(self): return repr x = X() d = {0 : x} print d {0: repr} So if __str__ is meant for human eyes, then why isn't print using it! it is: print x str but dict just uses repr() for all its childs to print. T. That makes no sense to me. If I call 'print' on a container, why wouldn't it recursively print on the contained objects? Since print means call str, printing a container should recursively call str on the objects. Basically because there are too many right ways to format the resulting report. Space separated? Tab separated? One per line? Boxes around them? As HTML definition lists? Creating a standard report form would take a lot of work and wouldn't, finally, solve very many peoples' problems. Mel. Thanks, but the question of how to format the container is different from how to format the primitive elements of the container. I was suggesting that printing an element of a container should be consistent with printing the element without the container, i.e., print [a] should be consistent with print a Indeed, but that only demonstrates that you have failed to take the point of the more perspicacious replied to your query. Python is trying to avoid throwing away useful information. The only people who would want to see a representation of a data structure such as a list are programmers: if you want to show a list of values to a regular user you format it in some required way. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: C API and memory allocation
On Dec 18, 7:54 am, Stefan Behnel stefan...@behnel.de wrote: Aaron Brady wrote: I see. Do I read correctly that 's' is only useful when the argument's position is known? I assume you meant length. No, position in the argument list. Otherwise you can't change its reference count; in which case, a pointer to the string object's contents (a char*) is useless after control leaves the caller's scope. Otherwise you can't know its length or change its reference count. The internal representation of Python byte strings is 0 terminated, so strlen() will work. As MRAB said, Python strings can contain null bytes, since they carry their lengths. Therefore strlen will always succeed, but isn't always right. len( abc\x00def ) 7 'strlen' says '3'. So, with 's', you are limited to the operations preceding null bytes in the current scope (with the GIL held). I hold this is strong enough to put the burden of proof on the defenders of having 's'. What is its use case? -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter unbinding
On Dec 18, 1:48 pm, Roger rdcol...@gmail.com wrote: On Dec 18, 12:49 pm, r rt8...@gmail.com wrote: Maybe someone will chime in with an answer, sorry i could not help. ponder this, i must... Regardless, thanks for your help! I truly appreciate it. Roger. 'no problema mi amigo!'.to_english(no problem my friend!) :) -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess.Popen inheriting
On Dec 17, 7:16 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 17 Dec 2008 22:46:32 -0200, Aaron Brady castiro...@gmail.com escribió: On Dec 17, 5:05 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Wed, 17 Dec 2008 12:21:38 -0200, Jeremy Sanders jeremy+complangpyt...@jeremysanders.net escribió: It would be nice if Python created pipes that are properly inheritable by default by child processes, as they're mostly used for IPC. I'd say it is a bug in os.pipe implementation; they should be inheritable by default, as in posix (after all, the code is in posixmodule.c). The code looks like this: ok = CreatePipe(read, write, NULL, 0); Py_END_ALLOW_THREADS if (!ok) return win32_error(CreatePipe, NULL); read_fd = _open_osfhandle((Py_intptr_t)read, 0); write_fd = _open_osfhandle((Py_intptr_t)write, 1); 'If lpPipeAttributes is NULL, the handle cannot be inherited.' You could populate a 'SECURITY_ATTRIBUTES' structure, or call DuplicateHandle on both of them. A patch would look like this: SECURITY_ATTRIBUTES sattribs; sattribs.nLength = sizeof(sattribs); sattribs.lpSecurityDescriptor = NULL; sattribs.bInheritHandle = TRUE; ok = CreatePipe(read, write, sattribs, 0); Yes, that's exactly how os.popen does it (in posixmodule.c) This still doesn't answer whether the file descriptor return by '_open_osfhandle' can be inherited too. It doesn't matter. The OS only cares about file handles, not C RTL structures. Sorry for the multiple posts. File handles are inheritable by child processes, if the permissions are right. File descriptors are not. Is there a way that we can get the handles of a pipe into code, so that we can pass them to a subprocess? Will it take calling 'CreatePipe' from ctypes directly if on Windows? Or can 'os.pipe' be made to abstract that? If Windows can't inherit descriptors, 'os.pipe' should return handles, and 'os.read' co. should accept them. It is a fairly large patch. -- http://mail.python.org/mailman/listinfo/python-list
Re: psycopg2 and large queries
On Thu, 18 Dec 2008 22:28:23 +0100 Laszlo Nagy gand...@shopzeus.com wrote: - PyGresSQL: apparently, it does not support fetching one row, only fetching all rows (see: http://www.pygresql.org/pg.html#getresult-get-query-values-as-list-of-tuples), so this is not an option. (Yes, it also has a db api compilant module, but it is only a wrapper around pgqueryobject, and it does not support server side cursors...) I'm not sure where you get that. The DB-API compliant execute function uses server side cursors with fetch. -- 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
Which sparse matrix package?
Hi: I am writing a spreadsheet application in Python http://pyspread.sf.net which currently uses numpy.array for: + storing object references (each array element corresponds to one grid cell) + slicing (read and write) + mapping from/to smaller numpy.array + searching and replacing + growing and shrinking + transpose operation. While fast and stable, this is really memory inefficient for large grids (i.e. larger than 1E7 rows and columns), so that I am looking into dicts and sparse matrices. The dict that I tried out is of the type: {(1,2,3): 2323, (1,2,545): 2324234, ... } It is too slow for my application when it grows. One slicing operation with list comprehensions takes about 1/2 s on my computer for 1E6 elements. Therefore, I looked into sparse matrices and found scipy.sparse and pysparse. I tried out both lil_matrix objects. (I wrote a wrapper that turns them into Python object arrays.) scipy.sparse.lil_matrix allowed __getitem__ slicing only for one of the dimensions and used much memory when increasing the number of columns above 1E7. pysparse.spmatrix.ll_mat was faster, uses less space and allows slicing for both dimensions. However, its methods are not documented well and I am not able to compile it in Debian testing due to some g77 dependencies. Even though the deb package works well, I am concerned about having a dependency to a problematic package. Now my questions: Is there a better suited / maintained module for such sparse matrices (or multi-dim arrays)? Should I use another type of matrix in scipy.sparse? If yes which? Does a different data-structure suit my above-stated needs better? Best Regards Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Which sparse matrix package?
On Fri, Dec 19, 2008 at 8:18 AM, Martin Manns mma...@gmx.net wrote: Hi: Hi, I am writing a spreadsheet application in Python What's wrong with pyspread ? [ ... snip ... ] The dict that I tried out is of the type: {(1,2,3): 2323, (1,2,545): 2324234, ... } It is too slow for my application when it grows. One slicing operation with list comprehensions takes about 1/2 s on my computer for 1E6 elements. Let me get this straight. It's taking 0.5s to slice your matrix of 1E7 (1000.0 rows/columns) Are you mad ? This is TEN Millions and you required it faster than 0.5s ? Am I missing something here ? cheers James -- http://mail.python.org/mailman/listinfo/python-list