MySQLdb-1.2.3 beta 1 released
After almost two years of not so much going on, I've released MySQLdb-1.2.3 beta 1, the first of a couple of betas before PyCon 2009. Highlights: * Compatible with Python-2.6 (but not yet 3.0) * Fixed some parameter substitution problems * Fixed some build problems on certain platforms * Other stuff I don't remember Eggs are available at the usual place for Python-2.5 and 2.6 on i386, i.e. use ez_install. This is a beta, but it should actually work better than 1.2.2, if you were having problems. Otherwise there are no new features yet. However, It is a test release, so if you do try it, be prepared to report bugs. Patches/tests appreciated. I'm planning a sprint for PyCon 2009 though due to personal commitments, I may only be able to stay for one day. If all the 1.2 bugs are sorted out, I might work more on 1.3 (the current SVN trunk, and future 2.0). http://sourceforge.net/projects/mysql-python/ http://pypi.python.org/pypi/MySQL-python/ http://mysql-python.blogspot.com/ -- Patriotism means to stand by the country. It does not mean to stand by the president. -- T. Roosevelt MANDATED GOVERNMENT HEALTH WARNING: Government mandates may be hazardous to your health. This message has been scanned for memes and dangerous content by MindScanner, and is believed to be unclean. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: GOZERBOT 0.9 RELEASED
Finally gozerbot 0.9 has been released. This is a huge step forward to version 1.0 and contains a number of changes: * use json as the format to save data in instead of pickles * let config files also use json, this makes them more readable and human editable * remove popen usage from the bot core * remove execfile() calls from the bot core * rewrite the gozerbot package into several subpackages * use sqlaclhemy to provide database backend (sqlite3 is default) * require python2.5 * move most of the plugins into their own package * restructure the gozerdata layout so its more readable All these changes makes upgrading from older versions of gozerbot necessary so a gozerbot-upgrade program is provided (upgrading from 0.7 is not supported yet, will follow soon). See http://gozerbot.org on how to install gozerbot 0.9 About GOZERBOT: 0.9 Requirements * a shell * python 2.5 or higher * gnupg * simplejson * sqlalchemy * xmpppy Why gozerbot? * provide both IRC and Jabber support * user management by userhost .. bot will not respond if it doesn't know you (see USER) * fleet .. use more than one bot in a program (list of bots) (see FLEET) * use the bot through dcc chat * fetch rss feeds (see RSS) * remember items * relaying between bots (see RELAY) * program your own plugins (see PROGRAMPLUGIN) * query other bots with json REST (see CLOUD) * serve as a udp - irc or jabber notification bot (see UDP * sqlalchemy support Bart -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
CrunchyFrog 0.3.3 released
After a really short period here's a bug fix release for CrunchyFrog. CrunchyFrog 0.3.3 fixes a bunch of minor and some major bugs that slipped into the last release. Download: http://crunchyfrog.googlecode.com/files/crunchyfrog-0.3.3.tar.gz The package archive on Launchpad is already up to date. Visit the project page hosted on Google Code for more information. Changes in 0.3.3 Bug Fixes * Statement splitting with SQLite and SQLServer and explain view works again (issue27). * Use F1 instead of Ctrl-H for Help (issue26). * Oracle plugin now installs properly (issue28). * An error dialog is displayed when connecting to SQL Server fails. * Confirm save dialog works again when a window is closed. Complete change log: http://crunchyfrog.googlecode.com/svn/tags/0.3.3/CHANGES What is CrunchyFrog === CrunchyFrog is a database navigator and SQL client. Currently PostgreSQL, MySQL, Oracle, SQLite3, MS-SQL databases and LDAP servers are supported for browsing and querying. More databases and features can be added using the plugin system. CrunchyFrog is licensed under the GPLv3 and is written in Python and uses PyGTK for it's user interface. Homepage:http://crunchyfrog.googlecode.com/ Screenshots: http://picasaweb.google.com/albrecht.andi/CrunchyFrogScreenshots Download:http://code.google.com/p/crunchyfrog/downloads/list Discussions: http://groups.google.com/group/crunchyfrog Issues/Bugs: http://code.google.com/p/crunchyfrog/issues/list Regards, Andi -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Webware for Python 1.0.1 released
Webware for Python 1.0.1 has been released. This is the first bugfix release for Webware for Python release 1.0, mainly fixing a problem that could appear when communicating with the threaded application server over a network connection. See the WebKit release notes for details. Webware for Python is a suite of Python packages and tools for developing object-oriented, web-based applications. The suite uses well known design patterns and includes a fast Application Server, Servlets, Python Server Pages (PSP), Object-Relational Mapping, Task Scheduling, Session Management, and many other features. Webware is very modular and easily extended. Webware for Python is well proven and platform-independent. It is compatible with multiple web servers, database servers and operating systems. Check out the Webware for Python home page at http://www.w4py.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Fastest database solution
I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. My simple benchmarks show that sqlite3 is an average of 3.5 times faster at inserting a file, and on average less than a tenth of a second slower than psycopg2 at matching a file. I expected postgresql to be a lot faster ... is there some peculiarity in psycopg2 that could be causing slowdown? Are these performance results typical? Any suggestions on what to try from here? I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. Any advice is appreciated. -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 performance on windows, usb connection
dq d...@gmail.com wrote: This runs great on Ubuntu. I get DL speeds of about 1.5 Mb/s on the SATA HD or on a usb-connected iPod, but if I run the same program on Windows (with a 2 GHz core 2 duo, 7200 rpm sata drive---better hardware specs than the Ubuntu box), it maxes out at about 500 kb/s. Worse, if I DL directly to my iPod in disk mode, I'm lucky if I even hit 100 kb/s. So does anyone know what the deal is with this? Why is the same code so much slower on Windows? Hope someone can tell me before a holy war erupts :-) Just a guess, but are you running any kind of virus scanning software on Windows? That could have a massive impact on the speed of writing to disc. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Curt Hash wrote: I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. SQLite is in the same process. Communication with postgres is via another process so marshalling the traffic and context switches will impose overhead as you found. I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. It doesn't sound like a database is the best solution to your issue anyway. A better solution would likely be some form of hashing the lines and storing something that gives quick hash lookups. The hash would have to do things like not care what variable names are used etc. There are already lots of plagiarism detectors out there so it may be more prudent using one of them, or at least learn how they do things so your own system could improve on them. Roger -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmL/wgACgkQmOOfHg372QTAmACg0INMfUKA10Uc6UJwNhYhDeoV EKwAoKpDMRzr7GzCKeYxn93TU69nDx4X =4r01 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: Is c.l.py becoming less friendly?
On Feb 6, 6:23 am, Hendrik van Rooyen m...@microcorp.co.za wrote: I think this thread has buggered up a perfectly ^^^ Such language. I'm appalled. Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
Hi Curt, Curt Hash wrote: I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. My simple benchmarks show that sqlite3 is an average of 3.5 times faster at inserting a file, and on average less than a tenth of a second slower than psycopg2 at matching a file. I expected postgresql to be a lot faster ... is there some peculiarity in psycopg2 that could be causing slowdown? Are these performance results typical? Any suggestions on what to try from here? I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. Off hand thats hard to tell w/o any details on what you are actually doing. At least an outline what kind of data you are storing and of course details of your database configuration would be helpful. Please note that postgres is quite good at handling concurrent load - this does not mean its best or every desk top database application. Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Question on Strings
Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? Any help in this regard is appreciated. Thank you. Regards Kalyan -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
-On [20090206 09:11], Curt Hash (curt.h...@gmail.com) wrote: I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. Maybe CouchDB [1] is more in line with what you need. [1] http://couchdb.apache.org/ -- Jeroen Ruigrok van der Werven asmodai(-at-)in-nomine.org / asmodai イェルーン ラウフロック ヴァン デル ウェルヴェン http://www.in-nomine.org/ | http://www.rangaku.org/ | GPG: 2EAC625B Earth to earth, ashes to ashes, dust to dust... -- http://mail.python.org/mailman/listinfo/python-list
Re: i have an query regarding pyodbc
On Feb 6, 3:53 pm, Rahul r.warhe...@gmail.com wrote: On Feb 6, 11:27 am, Rahul r.warhe...@gmail.com wrote: hello all, I have installed pyodbc on my red hat enterprise 4 linux machine but when i go to use that using statement, import pyodbc through python console it gives me error as ImportError : dynamic module does not define init function (initpyodbc) and when i do 'nm pyodbc.so' command i get output as [r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start 03ec t call_gmon_start 1600 b completed.1 14fc d __CTOR_END__ 14f8 d __CTOR_LIST__ w __cxa_finalize@@GLIBC_2.1.3 04a8 t __do_global_ctors_aux 0410 t __do_global_dtors_aux 15f8 d __dso_handle 1504 d __DTOR_END__ 1500 d __DTOR_LIST__ 150c A _DYNAMIC 1600 A _edata 1604 A _end 04d8 T _fini 046c t frame_dummy 04f4 r __FRAME_END__ 15e8 A _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 03b4 T _init 1508 d __JCR_END__ 1508 d __JCR_LIST__ w _Jv_RegisterClasses 15fc d p.0 which means there is no init function. So what might be the cause for that? I have build that pyodbc twice. Any help regarding this will be greatly appreciated. Thanks Regards Rahul this problem was due to not proper building of pyodbc Now my problem was, i have two versions of python installed at different locations but when i use import statement from psp pages it displays the error as ImportError : dynamic module does not define init function(initpyodbc) this error was due to pointing to older version of python. So, i want to know how to point my import statements to the new version of python. Thanks regards Rahul -- http://mail.python.org/mailman/listinfo/python-list
Changing return of type(obj)
Hello, I am attempting to fully-simulate an 'int' object with a custom object type. It is part of a library I am creating for python futures and promises. Is there anyway such that type(my_object) can return type 'int'? Or for that matter, any other primitive? I do not care how dirty the solution might possibly be; Could there be a way through the C API? Though I predict it will cause a mess with the interpreter. Thanks, Ken Elkabany -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing return of type(obj)
On Fri, Feb 6, 2009 at 3:03 AM, Ken Elkabany k...@elkabany.com wrote: Hello, I am attempting to fully-simulate an 'int' object with a custom object type. It is part of a library I am creating for python futures and promises. Is there anyway such that type(my_object) can return type 'int'? Or for that matter, any other primitive? I do not care how dirty the solution might possibly be; Could there be a way through the C API? Though I predict it will cause a mess with the interpreter. Any particular reason why subclassing 'int' wouldn't be good enough? (You did know you can do that, right?) I know you can subclass int at the Python level and I would think you should be able to do it at the C level also (if not, the design just gets only slightly more involved). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: kinterbasdb + firebird 1.5 with python 2.6 ?
Laszlo Nagy wrote: Uwe Grauer írta: Laszlo Nagy wrote: Get it from here: http://www.firebirdsql.org/index.php?op=develsub=python Thanks. Unfortunately, this does not support Firebird 1.5 anymore. I can only find Python 2.5 + Firebird 1.5. But not for Python 2.6. I'm going to downgrade. :-( Can you point me to where you read about stopped support for FB 1.5? Could it be that you have to just compile it against FB 1.5 libs to get a working version? Uwe -- http://mail.python.org/mailman/listinfo/python-list
Re: sorting for recursive folder rename
ianaré wrote: On Dec 16 2008, 7:36 pm, Rhodri James rho...@wildebst.demon.co.uk wrote: On Tue, 16 Dec 2008 18:20:52 -, ianaré ian...@gmail.com wrote: Hello all, I trying to recursivelyrenamefolders and files, and am looking for some ideas on the best way of doing this. The problem is that the given list of items can be in order, and one to all items may be renamed. Here is some preliminary code I have, but which does not work very well. self.toRename has the following structure : [ [original_name, new_name, os.path.isdir] .. ] # define these here for faster processing def split(item): return os.path.split(item) def addSep(path): return os.sep + path + os.sep def recursiveFolderSort(x,y): return cmp(y[0], x[0]) sortedRename = sorted(self.toRename) # make a list of all folders that will be processed foldersToAdjust = [] for item in sortedRename: if item[2] is False: oF = split(item[0])[1] # original folder name nF = split(item[1])[1] # new folder name if oF is not nF: foldersToAdjust.append((oF, nF)) # replace all occurences of folders in path for i in range(len(self.toRename)): for f in foldersToAdjust: oF = addSep(f[0]) # original folder name nF = addSep(f[1]) # new folder name self.toRename[i][0] = self.toRename[i][0].replace(oF,nF) self.toRename[i][1] = self.toRename[i][1].replace(oF,nF) if progressDialog.update(i) is False: error = 'cancelled' break # make sure renaming will be in correct order ! self.toRename.sort(recursiveFolderSort) import os for item in self.toRename: os.renames(item[0], item[1]) That's it. os.renames will take care of all the intermediate directory creation so you don't even need to sort the list. -- Rhodri James *-* Wildebeeste Herder to the Masses It's been a while since I decided to work on this again ... Anyway, if only it were that easy !! Traceback (most recent call last): File /home/ianare/Desktop/file-folder-ren/metamorphose2/Source/ MainWindow.py, line 1477, in renameItems os.renames(original[0], renamed[0]) File /usr/lib/python2.5/os.py, line 213, in renames rename(old, new) OSError: [Errno 2] No such file or directory The problem is that if a directory is changed, all lower instances need to be changed as well. given the following directory structure ... recursive | |_1 | |_1 | | |_1.txt | | |_2.txt | |_2 | |_1.txt | |_2.txt |_2 |_1 | |_1.txt | |_2.txt |_2 |_1.txt |_2.txt ... and assuming I want to change : recursive/2/2/2.txt -- recursive/2/2/14.txt but, I ALSO want to change : recursive/2 -- recursive/04 it means that the first operation is really : recursive/04/2/2.txt -- recursive/04/2/14.txt os.renames will work, but it needs to have the correct path, so it comes down to the same thing. IOW, I need a way of : A) adjusting paths taking into consideration all changes up and down the tree B) sorting normalized paths so they are renamed in the proper sequence (depends on point 'A', obviously) I'm pretty sure I can take care of 'B' with the following sorting method: # order by path depth def recursiveFolderSort(x, y): x = x[0].count(os.sep) y = y[0].count(os.sep) return cmp(x, y) self.toRename.sort(recursiveFolderSort) but I still need a way of generating the correct names. I don't see the problem. Just rename the deepest files and directories first. # untested def old_depth((old, new)): p = os.path.abspath(old) return p.count(os.sep) - p.endswith(os.sep) # don't count trailing slash pairs = sorted(self.toRename, key=old_depth, reverse=True) for old, new in pairs: os.rename(old, new) Because recursive/2/2/2.txt has more slashes it will be processed before recursive/2 and thus when the latter is processed the former's path will change implicitly. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing return of type(obj)
Ken Elkabany schrieb: I would simply subclass 'int', but this object needs to be general enough to pretend to be an 'int', 'NoneType', 'str', etc... A long shot: Can I change the base class on an instance by instance basis depending on the need? Well, now I can imagine having a class factory that will spawn for me the class that inherits the correct base type. Any other solutions? No, it's not possible. The type is an inherent part of an object. Python looks up methods and other attributes by looking at the type. The method call obj.method() is implemented as type(obj).method(obj). Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
On Feb 6, 9:24 pm, Chris Rebert c...@rebertia.com wrote: On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan soft_sm...@yahoo.com wrote: Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? Neither. IIRC, Depends on what the build settings were when CPython was compiled. UTF-16 is the default. Unicode strings are held as arrays of 16-bit numbers or 32-bit numbers [of which only 21 are used]. If you must use an acronym, use UCS-2 or UCS-4. The UTF-n siblings are *external* representations. 2.x: a_unicode_object.decode('UTF-16') - an_str_object 3.x: an_str_object.decode('UTF-16') - a_bytes_object By the way, has anyone come up with a name for the shifting effect observed above on str, and also with repr, range, and the iter* family? If not, I suggest that the language's association with the best of English humour be widened so that it be dubbed the Mad Hatter's Tea Party effect. -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
On 2009-02-06 09:10, Curt Hash wrote: I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. My simple benchmarks show that sqlite3 is an average of 3.5 times faster at inserting a file, and on average less than a tenth of a second slower than psycopg2 at matching a file. I expected postgresql to be a lot faster ... is there some peculiarity in psycopg2 that could be causing slowdown? Are these performance results typical? Any suggestions on what to try from here? I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. Any advice is appreciated. In general, if you do bulk insert into a large table, you should consider turning off indexing on the table and recreate/update the indexes in one go afterwards. But regardless of this detail, I think you should consider a filesystem based approach. This is going to be a lot faster than using a database to store the source code line by line. You can still use a database for the administration and indexing of the data, e.g. by storing a hash of each line in the database. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 06 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 slow file IO
Thanks a lot for all the responses. I'll move back to Python 2.5 for compatibility with SciPY and some other third party packages. I'll leave the compilation process for some other day, for now I'm a happy user, mayve In the future I would like to contribute to the developmental process.. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is difference between ADO and RDO
On 6 fév, 10:56, Agile Consulting agile.scrapp...@gmail.com wrote: Explain ADO and RDO RU a bot ? Olivier -- http://mail.python.org/mailman/listinfo/python-list
Re: is python Object oriented??
On Jan 31, 1:54 am, Christian Heimes li...@cheimes.de wrote: Michael Torrie schrieb: It all depends on implementation, I think even we can make C object oriented with proper implementation. Indeed, any code based on gobject libraries can be object-oriented in design and function. The Python C API is a good example for well designed and object oriented C code. Christian hello -- http://mail.python.org/mailman/listinfo/python-list
Re: Skipping bytes while reading a binary file?
On Feb 5, 11:51 pm, Lionel lionel.ke...@gmail.com wrote: On Feb 5, 3:35 pm, Lionel lionel.ke...@gmail.com wrote: On Feb 5, 2:56 pm, Lionel lionel.ke...@gmail.com wrote: On Feb 5, 2:48 pm, MRAB goo...@mrabarnett.plus.com wrote: Lionel wrote: Hello, I have data stored in binary files. Some of these files are huge...upwards of 2 gigs or more. They consist of 32-bit float complex numbers where the first 32 bits of the file is the real component, the second 32bits is the imaginary, the 3rd 32-bits is the real component of the second number, etc. I'd like to be able to read in just the real components, load them into a numpy.ndarray, then load the imaginary coponents and load them into a numpy.ndarray. I need the real and imaginary components stored in seperate arrays, they cannot be in a single array of complex numbers except for temporarily. I'm trying to avoid temporary storage, though, because of the size of the files. I'm currently reading the file scanline-by-scanline to extract rows of complex numbers which I then loop over and load into the real/ imaginary arrays as follows: self._realData = numpy.empty((Rows, Columns), dtype = numpy.float32) self._imaginaryData = numpy.empty((Rows, Columns), dtype = numpy.float32) floatData = array.array('f') for CurrentRow in range(Rows): floatData.fromfile(DataFH, (Columns*2)) position = 0 for CurrentColumn in range(Columns): self._realData[CurrentRow, CurrentColumn] = floatData[position] self._imaginaryData[CurrentRow, CurrentColumn] = floatData[position+1] position = position + 2 The above code works but is much too slow. If I comment out the body of the for CurrentColumn in range(Columns) loop, the performance is perfectly adequate i.e. function call overhead associated with the fromfile(...) call is not very bad at all. What seems to be most time-consuming are the simple assignment statements in the CurrentColumn for-loop. [snip] Try array slicing. floatData[0::2] will return the real parts and floatData[1::2] will return the imaginary parts. You'll have to read up how to assign to a slice of the numpy array (it might be self._realData[CurrentRow] = real_parts or self._realData[CurrentRow, :] = real_parts). BTW, it's not the function call overhead of fromfile() which takes the time, but actually reading data from the file. Very nice! I like that! I'll post the improvement (if any). L- Hide quoted text - - Show quoted text - Okay, the following: self._realData[CurrentRow] = floatData[0::2] self._imaginaryData[CurrentRow] = floatData[1::2] gives a 3.5x improvement in execution speed over the original that I posted. That's much better. Thank you for the suggestion. L- Hide quoted text - - Show quoted text - Correction: improvement is around 7-8x. I had similar issues while Slicing Network packets (TCP/UDP) on a real time basis. I was using 're' and found it a lot more time and resource consuming, than 'normal' string slicing as suggested by MRAB. K -- http://mail.python.org/mailman/listinfo/python-list
Re: Scanning a file character by character
On Wed, 4 Feb 2009 22:48:13 -0800 (PST), Spacebar265 spacebar...@gmail.com wrote: Hi. Does anyone know how to scan a file character by character and have each character so I can put it into a variable. I am attempting to make a chatbot and need this to read the saved input to look for spelling mistakes and further analysis of user input. That does not follow. To analyze a text, the worst possible starting point is one variable for each character (what would you call them -- character_1, character_2, ... character_65802 ?) /Jorgen -- // Jorgen Grahn grahn@Ph'nglui mglw'nafh Cthulhu \X/ snipabacken.se R'lyeh wgah'nagl fhtagn! -- http://mail.python.org/mailman/listinfo/python-list
Re: Skipping bytes while reading a binary file?
You might also want to have a look at a numpy memmap viewed as a recarray. from numpy import dtype, memmap, recarray # Define your record in the file, 4bytes for the real value, # and 4 bytes for the imaginary (assuming Little Endian repr) descriptor = dtype([(r, f4), (i, f4)]) # Now typecast a memap (a memory efficient array) onto the file in read only mode # Viewing it as a recarray means the attributes data.r and data.i are acessible as # ordinary numpy array data = memmap(filename, dtype=descriptor, mode='r').view(recarray) print First 100 real values:, data.r[:100] --Slaunger -- http://mail.python.org/mailman/listinfo/python-list
Re: programming by evolution?
Xah Lee wrote: Pascal Constanza is a Common Lisp fanatic. It's Costanza, not Constanza. Thank you, Pascal -- ELS'09: http://www.european-lisp-symposium.org/ My website: http://p-cos.net Common Lisp Document Repository: http://cdr.eurolisp.org Closer to MOP ContextL: http://common-lisp.net/project/closer/ -- http://mail.python.org/mailman/listinfo/python-list
WIn32api
Hi, I have a python script that I want to run in the system tray and system tray only (windows system). I am looking at the win32gui_taskbar.py demo file but am having trouble making sense of what parts do. I understand what the whole does but I want to actually learn what it is doing so I can apply it, not just copy and paste parts to make it work the way I want. I have searched for some kind of explanation or tutorial on this and have come up empty. Is there anything out there? Thanks. Kevin -- http://mail.python.org/mailman/listinfo/python-list
Distributing simple tasks
Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it's slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Thanks, Noam -- http://mail.python.org/mailman/listinfo/python-list
ANN: SuPy - Script Sketchup with Python
SuPy 1.0 SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. http://www.cosc.canterbury.ac.nz/SuPy/ This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- Greg Ewing greg.ew...@canterbury.ac.nz -- http://mail.python.org/mailman/listinfo/python-list
Re: updating nntplib
Travis wrote: Hello all, There are some notable deficiencies in nntlib. Here are two: [...] Be sure to add a bug report/patch to the Python bug tracker. http://bugs.python.org/ Anything else will most likely be overlooked or forgotten. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
John Machin s...@le..n.net wrote: By the way, has anyone come up with a name for the shifting effect observed above on str, and also with repr, range, and the iter* family? If not, I suggest that the language's association with the best of English humour be widened so that it be dubbed the Mad Hatter's Tea Party effect. The MHTP effect. Sounds educated, almost like a network protocol. +1 - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: SuPy - Script Sketchup with Python
greg schrieb: SuPy 1.0 SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. Great, will give it a try. http://www.cosc.canterbury.ac.nz/SuPy/ I think you meant to write http://www.cosc.canterbury.ac.nz/~greg/SuPy/ This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. cheers Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: self-aware list of objects able to sense constituent member alterations?
On Jan 28, 4:37 am, John O'Hagan m...@johnohagan.com wrote: On Tue, 27 Jan 2009, Reckoner wrote: I'm not sure this is possible, but I would like to have a list of objects A=[a,b,c,d,...,z] where, in the midst of a lot of processing I might do something like, A[0].do_something_which_changes_the_properties() which alter the properties of the object 'a'. The trick is that I would like A to be mysteriously aware that something about the object 'a' has changed so that when I revisit A, I will know that the other items in the list need to be refreshed to reflect the changes in A as a result of changing 'a'. Even better would be to automatically percolate the subsequent changes that resulted from altering 'a' for the rest of the items in the list. [...] Interesting question. Maybe this is too simple for your purpose (or maybe just wrong!), but could you subclass list and give it an update method which keeps a dictionary of the state of its members and/or calls another method that makes the appropriate changes in the other members when a change occurs, something like: class SelfAwareList(list): state_dict = {} def update(self): for i in self: if i.state == 'some_condition': self.do_stuff_to_other_members() self.state_dict[i] = i.state def do_stuff_to_other_members(self): print 'doing stuff...' ? You could manually call update() on the SelfAwareList instance after calling a method on a SelfAwareList member, or even build it into the members' methods so that it was automatic. HTH, John Hi Reckoner John O'Hagan, Great thread, very interesting. John, I haven't seen anything like your class that uses list instead of object and refers to state directly (i.state in self). Could you elaborate? Here would be my implementation of your idea: class SelfAwareList2(object): def __init__(self, l): self.l = l self.changed = [False for element in l] def __str__(self): return str(self.l) def update(self, index, value): self.l[index] = value self.changed[index] = True def do_stuff_to_other_members(self): for i in self.changed: if i==False: self.l[i] += 1 Here you can print and whenever you update your list, self.changed keeps track of what changed. Later on you can call do_stuff_to_others which in this case adds 1 to each other element. I assume that your class replaces the awkwardness of l.update(0, 5) with l[0] = 5, but I can't quite wrap my mind around it. Luther. -- http://mail.python.org/mailman/listinfo/python-list
Re: database wrapper ?
On Feb 1, 5:56 pm, Stef Mientki stef.mien...@gmail.com wrote: Is SQLalchemy the best / most popular database wrapper ? Are there any alternatives ? As others have confirmed, SQLAlchemy is far and away the most popular Python ORM. Another one to have a look at though is Dejavu (http://www.aminus.net/ dejavu). The user community isn't nearly as large but the software itself is quite good. One of its distinctives is that you can treat multiple disparate data stores as one cohesive relational structure. It also isn't bound to SQL databases. There are storage implementations included for file system, Shelve and in-memory storage. The 2.0 alpha code in trunk also has a memcached storage implementation. HTH, Christian http://www.dowski.com -- http://mail.python.org/mailman/listinfo/python-list
Re: database wrapper ?
On Feb 6, 10:17 am, Christian christ...@dowski.com wrote: One of its distinctives is that ... Not sure how I forgot this, but Dejavu also lets you write your datastore queries in a LINQ-like syntax. Robert Brewer, the author, is giving a talk [1] about it at this year's PyCon in the US. Christian http://www.dowski.com [1] http://pycon.org/2009/conference/talks/#proposal_link_91 -- http://mail.python.org/mailman/listinfo/python-list
Re: Using cPickle
mmcclaf wrote: Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line for line in stuff: Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First NameEmail Address Doe John j...@doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. Make sure you use modes rb and wb when you open the pickle files. If you are running on Windows this can make a difference. 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
Object explorer for python ?
Is there a (stand alone ?) object explorer for python objects such as the PyQt4 collection ? How else could I find out what is in PyQt4.QtCore, .QtGui and .QtWebKit ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Power Point Slides
On Fri, Feb 6, 2009 at 7:09 AM, Steve Holden st...@holdenweb.com wrote: Tehseen Siddiqui wrote: DISCLAIMER: The information in this email is confidential and may be legally privileged. [... etc.] What information? We can't tell you. It's confidential. :) -- http://mail.python.org/mailman/listinfo/python-list
RE: Distributing simple tasks
Hi, The delta between the finishing times of each machine is insignificant compared to the actual runtime, thus I don't feel it's necessary at the moment. Anyway, I want to keep it simple until I understand how to distribute tasks J Thanks! From: Thomas Raef [mailto:tr...@ebasedsecurity.com] Sent: Friday, February 06, 2009 4:01 PM To: Noam Aigerman; python-list@python.org Subject: RE: Distributing simple tasks Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it's slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Thanks, Noam I would suggest maybe a separate queue machine that would hand out each next function. That way if one machine takes a little longer, the faster machine can keep picking off functions and running them, while the slower machine can finish it's task. Just a thought. -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: SuPy - Script Sketchup with Python
Hi Greg, Hm... SuPy not found on this sever. ;-( Is there a better URL.. or did I just check too soon? thanks, -steve On Feb 5, 2009, at 11:56 PM, greg wrote: SuPy 1.0 SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. http://www.cosc.canterbury.ac.nz/SuPy/ This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- Greg Ewing greg.ew...@canterbury.ac.nz -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter w.pack()?
... The use of letmegooglethatforyou (not my video tool, by the way) is to point out that with the right search string you could have answered the question for yourself. Since you didn't appear to know that Google allowed you to search a single site (something I perhaps take for granted) I am glad that point wasn't lost. Yes, you can just search the PIL documentation. Isn't the Internet great? ;-) regards Steve Yes, I agree on the internet, and I now see letme...com. So, I've now tried in my browser's link window: site:effbot.org/tkinterbook tkfiledialog, and get site is not a registered protocol. If I put the site:... in the Google window,it works fine. In fact it's quite clever. I thought some months ago, I found Google commands that would operate in the browser link window. Guess not. BTW, isn't there an O'Reilly book on Google hacks of this sort? Where else does one find out about these Google tools? -- W. eWatson (121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time) Obz Site: 39° 15' 7 N, 121° 2' 32 W, 2700 feet Web Page: www.speckledwithstars.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing return of type(obj)
I would simply subclass 'int', but this object needs to be general enough to pretend to be an 'int', 'NoneType', 'str', etc... A long shot: Can I change the base class on an instance by instance basis depending on the need? Well, now I can imagine having a class factory that will spawn for me the class that inherits the correct base type. Any other solutions? Thanks Chris. On Fri, Feb 6, 2009 at 3:42 AM, Chris Rebert c...@rebertia.com wrote: On Fri, Feb 6, 2009 at 3:03 AM, Ken Elkabany k...@elkabany.com wrote: Hello, I am attempting to fully-simulate an 'int' object with a custom object type. It is part of a library I am creating for python futures and promises. Is there anyway such that type(my_object) can return type 'int'? Or for that matter, any other primitive? I do not care how dirty the solution might possibly be; Could there be a way through the C API? Though I predict it will cause a mess with the interpreter. Any particular reason why subclassing 'int' wouldn't be good enough? (You did know you can do that, right?) I know you can subclass int at the Python level and I would think you should be able to do it at the C level also (if not, the design just gets only slightly more involved). Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
RE: Distributing simple tasks
Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it's slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Thanks, Noam I would suggest maybe a separate queue machine that would hand out each next function. That way if one machine takes a little longer, the faster machine can keep picking off functions and running them, while the slower machine can finish it's task. Just a thought. -- http://mail.python.org/mailman/listinfo/python-list
Re: i have an query regarding pyodbc
On Feb 6, 11:27 am, Rahul r.warhe...@gmail.com wrote: hello all, I have installed pyodbc on my red hat enterprise 4 linux machine but when i go to use that using statement, import pyodbc through python console it gives me error as ImportError : dynamic module does not define init function (initpyodbc) and when i do 'nm pyodbc.so' command i get output as [r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start 03ec t call_gmon_start 1600 b completed.1 14fc d __CTOR_END__ 14f8 d __CTOR_LIST__ w __cxa_finalize@@GLIBC_2.1.3 04a8 t __do_global_ctors_aux 0410 t __do_global_dtors_aux 15f8 d __dso_handle 1504 d __DTOR_END__ 1500 d __DTOR_LIST__ 150c A _DYNAMIC 1600 A _edata 1604 A _end 04d8 T _fini 046c t frame_dummy 04f4 r __FRAME_END__ 15e8 A _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 03b4 T _init 1508 d __JCR_END__ 1508 d __JCR_LIST__ w _Jv_RegisterClasses 15fc d p.0 which means there is no init function. So what might be the cause for that? I have build that pyodbc twice. Any help regarding this will be greatly appreciated. Thanks Regards Rahul this problem was due to not proper building of pyodbc -- http://mail.python.org/mailman/listinfo/python-list
thread-local data
Hi everybody, Assuming a snippet such as: threadLocalData = threading.local() threadLocalData.myDictionary = self.myDictionary is it correct to say that threadLocalData.myDictionary is NOT a thread- local -copy- of self.myDictionary but it's actually pointing to the same object? If that's the case, and assuming I want to iterate over the dictionary without it changing under my nose while I'm in the loop, would it be better to encase the whole loop in lock-protected section or would it be better to make a copy of the dictionary first and then iterate over that one? Given that in this particular thread I do not want to modify the dictionary, conceptually a copy would work. But would making thread-local copy be just as slow as making the whole loop thread safe? Thanks for your help! Manu -- http://mail.python.org/mailman/listinfo/python-list
Using cPickle
Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line for line in stuff: Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First NameEmail Address Doe John j...@doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Power Point Slides
Tehseen Siddiqui wrote: DISCLAIMER: The information in this email is confidential and may be legally privileged. [... etc.] What information? -- 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: ANN: SuPy - Script Sketchup with Python
greg wrote: SuPy 1.0 SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. http://www.cosc.canterbury.ac.nz/SuPy/ That URL fails with a 404 - not found. (At least for me at this moment in time.) This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: WIn32api
I have come up with what I need and will try tweaking some things that hopefully will help me learn what some of this stuff does. In the meantime, I am having an issue: class *KeepAlive*(threading.Thread): def *__init__*(*self*): *self*.count = 0 *self*.ie=win32com.client.Dispatch(*'internetexplorer.application'*) *self*.ie.Visible=0 threading.Thread.__init__(*self*) def *run*(*self*): *self*.ie.Navigate(URL) sleep(5) while True: sleep(1) *self*.count += 1 *self*.timeLeft = str((300 - *self*.count)/60) + *:* + str(( 300 - *self*.count)%60) + * until next refresh * print *self*.timeLeft if *self*.count == 300: *self*.ie.Refresh() *self*.count = 0 This works if I call run() specifically. But when I try to initiate the thread with .start() I get the following error Exception in thread Thread-1: Traceback (most recent call last): File C:\Python25\lib\threading.py, line 486, in __bootstrap_inner self.run() File C:\app.py, line 104, in run self.ie.Navigate(URL) File C:\Python25\lib\site-packages\win32com\client\dynamic.py, line 500, in __getattr__ raise AttributeError, %s.%s % (self._username_, attr) AttributeError: internetexplorer.application.Navigate What does this mean? Why is it only happening when I am trying to do this in a thread? Thanks for any help. Kevin -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
John Machin wrote: On Feb 6, 9:24 pm, Chris Rebert c...@rebertia.com wrote: On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan soft_sm...@yahoo.com wrote: Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? Neither. IIRC, Depends on what the build settings were when CPython was compiled. UTF-16 is the default. Unicode strings are held as arrays of 16-bit numbers or 32-bit numbers [of which only 21 are used]. If you must use an acronym, use UCS-2 or UCS-4. The UTF-n siblings are *external* representations. 2.x: a_unicode_object.decode('UTF-16') - an_str_object 3.x: an_str_object.decode('UTF-16') - a_bytes_object By the way, has anyone come up with a name for the shifting effect observed above on str, and also with repr, range, and the iter* family? If not, I suggest that the language's association with the best of English humour be widened so that it be dubbed the Mad Hatter's Tea Party effect. Bitwise shifts and rotates are collectively referred to as skew operations. I therefore suggest the term skewing. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
On Fri, Feb 6, 2009 at 1:49 AM, Kalyankumar Ramaseshan soft_sm...@yahoo.com wrote: Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? IIRC, Depends on what the build settings were when CPython was compiled. UTF-16 is the default. b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? No. They are implicitly converted to ASCII in such cases. To properly handle non-ASCII Unicode characters, you need to encode/decode the strings to/from bytes manually by specifying the encoding. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
Hi, Kalyankumar Ramaseshan wrote: Hi, Excuse me if this is a repeat question! I just wanted to know how are strings represented in python? It depents on if you mean python2.x or python3.x - the model changed. Python 2.x knows str and unicode - the former a sequence of single byte characters and unicode depending on configure options either 16 or 32 bit per character. str in python3.x replaces unicode and what formerly used to be like str is now bytes (iirc). I need to know in terms of: a) Strings are stored as UTF-16 (LE/BE) or UTF-32 characters? It uses an internal fixed length encoding for unicode, not UTF b) They are converted to utf-8 format when it is needed for e.g. when storing the string to disk or sending it through a socket (tcp/ip)? Nope. You need to do this explicitely. Default encoding for python2.x implicit conversion is ascii. In python2.x you would use unicodestr.encode('utf-8') and simplestr.decode('utf-8') to convert an utf-8 encoded string back to internal unicode. There are many encodings available to select from. Any help in this regard is appreciated. Please see also pythons documentation which is very good and just try it out in the interactive interpreter Regards Tino smime.p7s Description: S/MIME Cryptographic Signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Object explorer for python ?
On Feb 6, 9:49 am, Linuxguy123 linuxguy...@gmail.com wrote: Is there a (stand alone ?) object explorer for python objects such as the PyQt4 collection ? How else could I find out what is in PyQt4.QtCore, .QtGui and .QtWebKit ? Thanks I like WingWare for this sort of thing, but you might like eric. Links are below: http://eric-ide.python-projects.org/index.html http://www.wingware.com/ Other editors: http://wiki.python.org/moin/PythonEditors Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter w.pack()?
W. eWatson wrote: ... The use of letmegooglethatforyou (not my video tool, by the way) is to point out that with the right search string you could have answered the question for yourself. Since you didn't appear to know that Google allowed you to search a single site (something I perhaps take for granted) I am glad that point wasn't lost. Yes, you can just search the PIL documentation. Isn't the Internet great? ;-) regards Steve Yes, I agree on the internet, and I now see letme...com. So, I've now tried in my browser's link window: site:effbot.org/tkinterbook tkfiledialog, and get site is not a registered protocol. If I put the site:... in the Google window,it works fine. In fact it's quite clever. I thought some months ago, I found Google commands that would operate in the browser link window. Guess not. BTW, isn't there an O'Reilly book on Google hacks of this sort? Where else does one find out about these Google tools? Google? :-) http://www.google.com/support/websearch/bin/answer.py?hl=enanswer=136861 -- http://mail.python.org/mailman/listinfo/python-list
Re: thread-local data
Emanuele D'Arrigo wrote: Hi everybody, Assuming a snippet such as: threadLocalData = threading.local() threadLocalData.myDictionary = self.myDictionary is it correct to say that threadLocalData.myDictionary is NOT a thread- local -copy- of self.myDictionary but it's actually pointing to the same object? If that's the case, and assuming I want to iterate over the dictionary without it changing under my nose while I'm in the loop, would it be better to encase the whole loop in lock-protected section or would it be better to make a copy of the dictionary first and then iterate over that one? Given that in this particular thread I do not want to modify the dictionary, conceptually a copy would work. But would making thread-local copy be just as slow as making the whole loop thread safe? It depends on how long it takes to iterate over the dict compared with how long it takes to copy the dict. Other threads will/should be denied access during the iteration/copying and therefore block, reducing throughput. I'd probably use the snapshot approach (take a copy). -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter w.pack()?
W. eWatson wrote: ... The use of letmegooglethatforyou (not my video tool, by the way) is to point out that with the right search string you could have answered the question for yourself. Since you didn't appear to know that Google allowed you to search a single site (something I perhaps take for granted) I am glad that point wasn't lost. Yes, you can just search the PIL documentation. Isn't the Internet great? ;-) regards Steve Yes, I agree on the internet, and I now see letme...com. So, I've now tried in my browser's link window: site:effbot.org/tkinterbook tkfiledialog, and get site is not a registered protocol. If I put the site:... in the Google window,it works fine. In fact it's quite clever. I thought some months ago, I found Google commands that would operate in the browser link window. Guess not. BTW, isn't there an O'Reilly book on Google hacks of this sort? Where else does one find out about these Google tools? I seem to pick them up as I go along. This group is actually a great source of google-fu enhancements - I believe this is where I found out about letmegooglethatforyou. Of course you can do any Google search and then look at what Google puts in your Location: bar. Saving that URL means you can repeat the same search later, but you can also analyze it to find out about some useful tricks (and letme... uses the same everything except for the domain name). So your site search would also work with http://www.google.com/search?q=site%3Aeffbot.org+tkinterbook%2Bpack Of course it would be relatively easy to write a Python program that used the browser module to do this kind of search ... 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: Is c.l.py becoming less friendly?
On Feb 5, 8:02 am, Dan Upton up...@virginia.edu wrote: On Thu, Feb 5, 2009 at 11:00 AM, mk mrk...@gmail.com wrote: (duck) 542 comp.lang.python rtfm 467 comp.lang.python shut+up 263 comp.lang.perl rtfm 45 comp.lang.perl shut+up But over how many messages for each group? Wouldn't the percentage of messages containing those be more interesting than the raw number? ;p As would the percent of threads that ultimately have GIL within the last, oh, say 20% of their messages :) -- http://mail.python.org/mailman/listinfo/python-list
Re: thread-local data
Emanuele D'Arrigo schrieb: Hi everybody, Assuming a snippet such as: threadLocalData = threading.local() threadLocalData.myDictionary = self.myDictionary is it correct to say that threadLocalData.myDictionary is NOT a thread- local -copy- of self.myDictionary but it's actually pointing to the same object? Yes, it's pointing to the same object, and it thus makes the whole purpose of threadlocal moot. Use a global. If that's the case, and assuming I want to iterate over the dictionary without it changing under my nose while I'm in the loop, would it be better to encase the whole loop in lock-protected section or would it be better to make a copy of the dictionary first and then iterate over that one? Given that in this particular thread I do not want to modify the dictionary, conceptually a copy would work. But would making thread-local copy be just as slow as making the whole loop thread safe? As MRAB pointed out - it depends. My gut feeling on this is that the copy-approach is fastest. Or even faster, if you can cope with keys getting lost while processing them: for key in self.myDictionary.keys(): try: value = self.myDictionary[key] except KeyError: pass Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: thread-local data
Diez B. Roggisch schrieb: Emanuele D'Arrigo schrieb: Hi everybody, Assuming a snippet such as: threadLocalData = threading.local() threadLocalData.myDictionary = self.myDictionary is it correct to say that threadLocalData.myDictionary is NOT a thread- local -copy- of self.myDictionary but it's actually pointing to the same object? Yes, it's pointing to the same object, and it thus makes the whole purpose of threadlocal moot. Use a global. Scratch the use a global - that's of course nonsense. Use self.myDictionary directly, or wherever the dict comes from. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
John Machin wrote: The UTF-n siblings are *external* representations. 2.x: a_unicode_object.decode('UTF-16') - an_str_object 3.x: an_str_object.decode('UTF-16') - a_bytes_object That should be .encode() to bytes, which is the coded form. .decode is bytes = str/unicode -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing return of type(obj)
Ken Elkabany wrote: Hello, I am attempting to fully-simulate an 'int' object with a custom object type. It is part of a library I am creating for python futures and promises. Is there anyway such that type(my_object) can return type 'int'? Or for that matter, any other primitive? I do not care how dirty the solution might possibly be; Could there be a way through the C API? Though I predict it will cause a mess with the interpreter. type(o) == o.__class__ o.__class__ can only be rebound if and only if it is a user-class (heap type) and then only to another (compatible) user-class (heap type). -- http://mail.python.org/mailman/listinfo/python-list
Re: i have an query regarding pyodbc
Rahul schrieb: On Feb 6, 3:53 pm, Rahul r.warhe...@gmail.com wrote: On Feb 6, 11:27 am, Rahul r.warhe...@gmail.com wrote: hello all, I have installed pyodbc on my red hat enterprise 4 linux machine but when i go to use that using statement, import pyodbc through python console it gives me error as ImportError : dynamic module does not define init function (initpyodbc) and when i do 'nm pyodbc.so' command i get output as [r...@dbserver site-packages]# nm pyodbc.so 1600 A __bss_start 03ec t call_gmon_start 1600 b completed.1 14fc d __CTOR_END__ 14f8 d __CTOR_LIST__ w __cxa_finalize@@GLIBC_2.1.3 04a8 t __do_global_ctors_aux 0410 t __do_global_dtors_aux 15f8 d __dso_handle 1504 d __DTOR_END__ 1500 d __DTOR_LIST__ 150c A _DYNAMIC 1600 A _edata 1604 A _end 04d8 T _fini 046c t frame_dummy 04f4 r __FRAME_END__ 15e8 A _GLOBAL_OFFSET_TABLE_ w __gmon_start__ 03b4 T _init 1508 d __JCR_END__ 1508 d __JCR_LIST__ w _Jv_RegisterClasses 15fc d p.0 which means there is no init function. So what might be the cause for that? I have build that pyodbc twice. Any help regarding this will be greatly appreciated. Thanks Regards Rahul this problem was due to not proper building of pyodbc Now my problem was, i have two versions of python installed at different locations but when i use import statement from psp pages it displays the error as ImportError : dynamic module does not define init function(initpyodbc) this error was due to pointing to older version of python. So, i want to know how to point my import statements to the new version of python. The problem are not the imports, the problem is the used interpreter. How is PSP integrated into your webserver? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: What is difference between ADO and RDO
OdarR wrote: On 6 fév, 10:56, Agile Consulting agile.scrapp...@gmail.com wrote: Explain ADO and RDO RU a bot ? I expect someone is experimenting with their spam generator. -- http://mail.python.org/mailman/listinfo/python-list
Re: Have you ever thought to know your intelligence level?
His IQ must suck considering all the spelling errorsor is that not also a measure of one's IQ? I'm pretty sure there is a legasthenic nobel prize winner out there... so *if* it were a measure of IQ, it would make the whole affair even more braindead. I'd rather say he is of limited intelligence because he tries to convince us that his spam actually *isn't* spam... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Distributing simple tasks
Noam Aigerman wrote: Hi, Suppose I have an array of functions which I execute in threads (each thread get a slice of the array, iterates over it and executes each function in it’s slice one after the other). Now I want to distribute these tasks between two machines, i.e give each machine half of the slices and let it run them in threads as described above. Is there an easy way, or an article on this matter you can point me to? Here is a standard approach that is slightly more general than you specified. It will work with more than two cores or machines. Write master/server program that reads data, listens to socket for calls from worker/client programs, splits work into multiple tasks, sends them out to workers, and collects and re-assembles the results. After a timeout, it should be able to reassign tasks not returned. Write worker/client program than calls master, gets task, completes it, and returns result. Assume all data is on machine A. Start master and worker on machine A. Start worker(s) on other cores or machines. You can either use socket module directly or use networking modules built on top of it. Twisted and pyro are two that come to mind immediately. I have seen code examples but do not remember where. Note: I do not see any advantage to having multiple compute-bound threads, as you seem to describe. Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Returning a variable number of things...
Hi There, I have a function that uses *args to accept a variable number of parameters and I would like it to return a variable number of objects. I could return a list but I would like to take advantage of tuple unpacking with the return values e.g. def unpack_struct( a_string, *args ): output_vars = [] for each in *args: build a list of output values return the tuple equivalent of this list ip, meat, zipcode = unpack_struct( 192.168.001.001Ham22132, 15, 3, 5 ) Thanks, Roger. -- http://mail.python.org/mailman/listinfo/python-list
Re: updating nntplib
Gerhard Häring wrote: Travis wrote: Hello all, There are some notable deficiencies in nntlib. Here are two: [...] Be sure to add a bug report/patch to the Python bug tracker. http://bugs.python.org/ Anything else will most likely be overlooked or forgotten. It is my impression that nntplib was and maybe still is a bit flakey on 3.0. 3.0.1 will be out this month and may or may not have improvements. I am fairly sure that updating it to a newer RFC would be welcome. Such upgrades have happened to other protocol modules when there has been someone willing to do the work. Please do check the tracker for existing nntplib issues and add one if appropriate. tjr -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning a variable number of things...
On Fri, Feb 6, 2009 at 10:50 AM, r0g aioe@technicalbloke.com wrote: Hi There, I have a function that uses *args to accept a variable number of parameters and I would like it to return a variable number of objects. I could return a list but I would like to take advantage of tuple unpacking with the return values e.g. Despite its name, tuple unpacking works with lists too. Cheers, Chris -- Follow the path of the Iguana... http://rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning a variable number of things...
On Fri, Feb 6, 2009 at 10:50 AM, r0g aioe@technicalbloke.com wrote: Hi There, I have a function that uses *args to accept a variable number of parameters and I would like it to return a variable number of objects. I could return a list but I would like to take advantage of tuple unpacking with the return values e.g. Just return the list :) It'll unpack any sequence, not just tuples. --S -- http://mail.python.org/mailman/listinfo/python-list
Re: Using cPickle
On Feb 6, 10:25 am, Steve Holden st...@holdenweb.com wrote: mmcclaf wrote: Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line for line in stuff: Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First Name Email Address Doe John j...@doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. Make sure you use modes rb and wb when you open the pickle files. If you are running on Windows this can make a difference. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ I've tried both rb and wb as well as r and w, there appears to be no difference in the running of the code. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is difference between ADO and RDO
On 6 fév, 19:36, Scott David Daniels scott.dani...@acm.org wrote: OdarR wrote: On 6 fév, 10:56, Agile Consulting agile.scrapp...@gmail.com wrote: Explain ADO and RDO RU a bot ? I expect someone is experimenting with their spam generator. An agile one :) Olivier -- http://mail.python.org/mailman/listinfo/python-list
Parallel port interfacing in python on Vista x64
I have done some googling on this topic, but I haven't found anything thats really working on Vista x64. The most promising result I found was the Inpout32.dll: http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html But when using some code like that, I can't measure I differing state on my breadboard circurity: from ctypes import windll p = windll.inpout32 p.Inp32(0x378) #default 255(all high) on my pc p.Out32(0x378, 0) #put all low on port 2-9 Is it even possible to interface the Parallel Port on Vista64, and if so, how does one do that? -- http://mail.python.org/mailman/listinfo/python-list
Installation directory for extensions on Unix
I have written an extension (a.k.a. plugin or add-on, not C-extension) system for my application and I'm going to ship two extensions with it. Each extension is in a directory of its own and that directory contains Python files and various data files, e.g. Glade XML files and PNG icons. Where should I install these extension directories on a Unix system? $PREFIX/share/foo or $PREFIX/lib/foo? How do I handle compiling with distutils if installing Python code outside the default site-packages directory? Importing these extensions is handled by listing the contents of the extension directory and using __import__ on the specified files, so the installation directory does not need to be anywhere near $PYTHONPATH. -- Osmo Salomaa otsal...@cc.hut.fi -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: SuPy - Script Sketchup with Python
On Fri, Feb 6, 2009 at 8:27 AM, Gary Herron gher...@islandtraining.com wrote: greg wrote: SuPy 1.0 SuPy is a plugin for the Sketchup 3D modelling application that lets you script it in Python. http://www.cosc.canterbury.ac.nz/SuPy/ That URL fails with a 404 - not found. (At least for me at this moment in time.) This is a first version and is highly experimental. Let me know if it works for you and whether you have any problems. -- http://mail.python.org/mailman/listinfo/python-list This URL works: http://www.cosc.canterbury.ac.nz/greg.ewing/SuPy/ -- http://mail.python.org/mailman/listinfo/python-list
Re: thread-local data
Thank you both MRAB and Diez. I think I'll stick to making copies inside a thread-protected section unless I need to speed up things, at which point I might go for the key exception path. Thank you again! Manu -- http://mail.python.org/mailman/listinfo/python-list
Re: Parallel port interfacing in python on Vista x64
SiWi schrieb: I have done some googling on this topic, but I haven't found anything thats really working on Vista x64. The most promising result I found was the Inpout32.dll: http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_port_Interfacing.html But when using some code like that, I can't measure I differing state on my breadboard circurity: from ctypes import windll p = windll.inpout32 p.Inp32(0x378) #default 255(all high) on my pc p.Out32(0x378, 0) #put all low on port 2-9 Is it even possible to interface the Parallel Port on Vista64, and if so, how does one do that? Did you try pyparallel? Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
On Fri, Feb 6, 2009 at 2:12 AM, Roger Binns rog...@rogerbinns.com wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Curt Hash wrote: I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. SQLite is in the same process. Communication with postgres is via another process so marshalling the traffic and context switches will impose overhead as you found. I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. It doesn't sound like a database is the best solution to your issue anyway. A better solution would likely be some form of hashing the lines and storing something that gives quick hash lookups. The hash would have to do things like not care what variable names are used etc. There are already lots of plagiarism detectors out there so it may be more prudent using one of them, or at least learn how they do things so your own system could improve on them. Currently, I am stripping extra whitespace and end-of-line characters from each line of source code and storing that in addition to its hash in a table. That table is used for exact-match comparisons. I am also passing the source code through flex/bison to canonicalize identifiers -- the resulting lines are also hashed and stored in a table. That table is used for structural matching. Both tables are queried to find matching hashes. I'm not sure how I could make the hash lookups faster... On my small test dataset, this solution has detected all of the plagiarism with high confidence. It's also beneficial to me to use this Python application as I can easily integrate it with other Python scripts I use to prepare code for review. Roger -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmL/wgACgkQmOOfHg372QTAmACg0INMfUKA10Uc6UJwNhYhDeoV EKwAoKpDMRzr7GzCKeYxn93TU69nDx4X =4r01 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Parallel port interfacing in python on Vista x64
On Feb 6, 8:55 pm, Diez B. Roggisch de...@nospam.web.de wrote: SiWi schrieb: I have done some googling on this topic, but I haven't found anything thats really working on Vista x64. The most promising result I found was the Inpout32.dll: http://logix4u.net/Legacy_Ports/Parallel_Port/A_tutorial_on_Parallel_... But when using some code like that, I can't measure I differing state on my breadboard circurity: from ctypes import windll p = windll.inpout32 p.Inp32(0x378) #default 255(all high) on my pc p.Out32(0x378, 0) #put all low on port 2-9 Is it even possible to interface the Parallel Port on Vista64, and if so, how does one do that? Did you try pyparallel? Diez Yep, but when trying to make a instance of the Parallel class I get an windows error. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using cPickle
mmcclaf wrote: On Feb 6, 10:25 am, Steve Holden st...@holdenweb.com wrote: mmcclaf wrote: Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line for line in stuff: Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First NameEmail Address Doe John j...@doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. Make sure you use modes rb and wb when you open the pickle files. If you are running on Windows this can make a difference. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ I've tried both rb and wb as well as r and w, there appears to be no difference in the running of the code. cPickle.dump(work,output) writes a string and stuff=cPickle.load(input) just reads that string, so for line in stuff: is iterating through the characters if the string. You need to use cPickle.load() to read each string (line). -- http://mail.python.org/mailman/listinfo/python-list
Re: Fastest database solution
On Fri, Feb 6, 2009 at 5:19 AM, M.-A. Lemburg m...@egenix.com wrote: On 2009-02-06 09:10, Curt Hash wrote: I'm writing a small application for detecting source code plagiarism that currently relies on a database to store lines of code. The application has two primary functions: adding a new file to the database and comparing a file to those that are already stored in the database. I started out using sqlite3, but was not satisfied with the performance results. I then tried using psycopg2 with a local postgresql server, and the performance got even worse. My simple benchmarks show that sqlite3 is an average of 3.5 times faster at inserting a file, and on average less than a tenth of a second slower than psycopg2 at matching a file. I expected postgresql to be a lot faster ... is there some peculiarity in psycopg2 that could be causing slowdown? Are these performance results typical? Any suggestions on what to try from here? I don't think my code/queries are inherently slow, but I'm not a DBA or a very accomplished Python developer, so I could be wrong. Any advice is appreciated. In general, if you do bulk insert into a large table, you should consider turning off indexing on the table and recreate/update the indexes in one go afterwards. But regardless of this detail, I think you should consider a filesystem based approach. This is going to be a lot faster than using a database to store the source code line by line. You can still use a database for the administration and indexing of the data, e.g. by storing a hash of each line in the database. I can see how reconstructing source code from individual lines in the database would be much slower than a filesystem-based approach. However, what is of particular importance is that the matching itself be fast. While the original lines of code are stored in the database, I am performing matching based on only hashes. Would storing the original code in the same table as the hash cause significant slowdown if I am querying by hash only? I think I may try this approach anyways, just to make retrieving the original source code after finding a match faster, but I am still primarily concerned with the speed of the hash lookups. -- Marc-Andre Lemburg eGenix.com Professional Python Services directly from the Source (#1, Feb 06 2009) Python/Zope Consulting and Support ...http://www.egenix.com/ mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/ mxODBC, mxDateTime, mxTextTools ...http://python.egenix.com/ ::: Try our new mxODBC.Connect Python Database Interface for free ! eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48 D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg Registered at Amtsgericht Duesseldorf: HRB 46611 http://www.egenix.com/company/contact/ -- http://mail.python.org/mailman/listinfo/python-list
Trouble sorting a list of objects by attributes
Hello again, I've found myself stumped when trying to organize this list of objects. The objects in question are timesheets which i'd like to sort by four attributes: class TimeSheet: department = string engagement = string date = datetime.date stare_hour = datetime.time My ultimate goal is to have a list of this timesheet objects which are first sorted by departments, then within each department block of the list, have it organized by projects. Within each project block i finally want them sorted chronologically by date and time. To sort the strings i tried: timesheets.sort(key=operator.attrgetter('string')) which is not doing anything to my list unfortunately; it leaves it untouched. Giving up on that i tried to sort the dates or times using: def sorter_time(a,b): if a.engagement == engagement: # I only want sorting done within each engagement block return cmp(a.start, b.start) return 0 timesheets.sort(sorter_time) But this also did nothing to my list, and at this point i'm incredibly confused. From what i know of the involved functions, i would think that these lines of code (while they wouldn't do exactly what i want yet) would at least do something to my lists. Any explanations, or suggestions for a different approach would be greatly appreciated. My brain might explode if i continue. -- http://mail.python.org/mailman/listinfo/python-list
Trouble sorting a list of objects by attributes
Quoth Robocop btha...@physics.ucsd.edu: Hello again, I've found myself stumped when trying to organize this list of objects. The objects in question are timesheets which i'd like to sort by four attributes: class TimeSheet: department = string engagement = string date = datetime.date stare_hour = datetime.time My ultimate goal is to have a list of this timesheet objects which are first sorted by departments, then within each department block of the list, have it organized by projects. Within each project block i finally want them sorted chronologically by date and time. To sort the strings i tried: timesheets.sort(key=operator.attrgetter('string')) which is not doing anything to my list unfortunately; it leaves it untouched. Python 2.6.1 (r261:67515, Jan 7 2009, 17:09:13) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. class Timesheet(object): ... def __init__(self, department): self.department=department ... def __repr__(self): return Timesheet(%s) % self.department ... timesheets = [Timesheet('abc'), Timesheet('def'), Timesheet('acd')] timesheets [Timesheet(abc), Timesheet(def), Timesheet(acd)] import operator timesheets.sort(key=operator.attrgetter('department')) timesheets [Timesheet(abc), Timesheet(acd), Timesheet(def)] The key bit here being the argument to attrgetter, which is the name of the attribute to use as they key. --RDM -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
I've found myself stumped when trying to organize this list of objects. The objects in question are timesheets which i'd like to sort by four attributes: class TimeSheet: department = string engagement = string date = datetime.date stare_hour = datetime.time My ultimate goal is to have a list of this timesheet objects which are first sorted by departments, then within each department block of the list, have it organized by projects. Within each project block i finally want them sorted chronologically by date and time. Python natural sort for tuples is doing the right thing for you, for example: from operator import attrgetter from random import randint class Point: def __init__(self, x, y): self.x = x self.y = y def __repr__(self): return (%s, %s) % (self.x, self.y) points = [Point(randint(1, 10), randint(1, 10)) for i in range(10)] print points points.sort(key=attrgetter(x, y)) print points Gave me: [(2, 3), (1, 4), (4, 4), (6, 6), (2, 10), (3, 5), (7, 1), (3, 6), (4, 1), (9, 6)] [(1, 4), (2, 3), (2, 10), (3, 5), (3, 6), (4, 1), (4, 4), (6, 6), (7, 1), (9, 6)] Points first sorted by 'x' and then by 'y'. HTH, -- Miki miki.teb...@gmail.com http://pythonwise.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: subprocess returncode windows
On Feb 5, 9:17 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Thu, 05 Feb 2009 17:34:29 -0200, Andrew andrew.replo...@gmail.com escribió: On Dec 16 2008, 5:11 pm, Gabriel Genellina gagsl-...@yahoo.com.ar wrote: En Tue, 16 Dec 2008 17:21:35 -0200, Andrew andrew.replo...@gmail.com escribió: On Dec 16, 12:50 pm, Christian Heimes li...@cheimes.de wrote: Andrew schrieb: I'm running into a strange situation with getting incorrect returncodes / exit status from python subprocess.call. I'm using a python script (runtime 2.6.1 on windows) to automate the deploy of java applications to glassfish application server. Below is an example I've tried this several ways now. It seems to be something specific with python and asadmin.bat. I've tried the following manually in the cmd.exe prompt: [examples showing %ERRORLEVEL% correctly set when running from the command line, but subprocess.call doesn't get it] Notice how python never gets the correct returncode from asadmin.bat but I can get the correct returncode from the shell every time. Can anyone tell me why Python wouldn't be able to get the correct returncode for asadmin? The last exit code set by a command *should* propagate as the exit code of the whole .bat, then as the exit code of the cmd.exe instance that runs it, and finally Python *should* receive that value. Some old Windows versions didn't behave like that, but AFAIK XP does the right thing here. Unless asadmin.bat is playing tricks with %ERRORLEVEL% or something. Can you post the contents of asadmin.bat? Without looking into it, I can think of a few alternatives: - rewrite asadmin.bat in Python, if feasible. Some scripts just check/set a few environment variables and execute some process at the end, and that's all; in this case it should be easy to emulate the same thing in Python. - try using another layer of your own, e.g., my_asadmin.bat: call asadmin.bat %* exit /b %ERRORLEVEL% - variation: write the exit code somewhere: call asadmin.bat %* echo %ERRORLEVEL% asadmin.err and read asadmin.err from Python. (I've used something like this in a chain Win32 process -- 16 bits GUI application -- .bat script -- old DOS executable) -- Gabriel Genellina Thanks Gabriel, Someone on the glassfish forums also pointed out the exit /B %ERRORLEVEL% for the bottom of the batch file and that corrected the issue for me. As well as not using that and removing endlocal which I admit I have no clue what that does. Removing endlocal seems to cause the batch script to pass out the correct returncode. Thanks everyone for your input and assistance =] Andrew -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department, engagement, date, stare_hour)) My brain might explode if i continue. Relax. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Ordered dict by default
On 05Feb2009 01:47, bearophileh...@lycos.com bearophileh...@lycos.com wrote: | [...] But even if the average performance becomes a | little worse I think making the default Python dict as ordered is a | positive change for Python too, because built-ins are meant to be as | flexible as possible, even if they aren't the fastest ones or the less | memory hungry ones I like the builtins to be as fast as possible. If I'm not abusing a built in facility I like to have the peace of mind that there's no point being concerned about the performance of the built-in - it will be optimal or close to it. So I feel no temptation to reimplement the wheel and can devote my energies to the code using the wheel. So if a dictionary has a performance weakness to add a non-widely-needed behaviour, it's not longer a pure mapping and I will feel unhappy using it. | (and keeping dicts ordered decreases the surprises | a newbie finds, makes some code cleaner, and doctests become simpler | to write because the order of items may be more defined). I read this as: - increases the unrealised assumptions about mappings in general which a newbie may acquire, causing them pain/complaint later with other mappings - makes some code shorter - making tests slightly simpler to write; it's not very hard to track insert order for purposes of a test short that be needed, is it? it seems a small gain for a loss in every production scenario | Once the default dicts are ordered, it can be possible to add an | unordereddict to the collections module to be used by programmers when | max performance or low memory usage is very important :-) I would much rather keep dictionaries as performant as possible, as a bare mapping, and add an odict for when order matters. Cheers, -- Cameron Simpson c...@zip.com.au DoD#743 http://www.cskk.ezoshosting.com/cs/ The wireless music box has no imaginable commercial value. Who would pay for a message sent to nobody in particular? --David Sarnoff's associates in response to his urgings for investment in the radio in the 1920s. -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 performance on windows, usb connection
Martin v. Löwis wrote: So does anyone know what the deal is with this? Why is the same code so much slower on Windows? Hope someone can tell me before a holy war erupts :-) Only the holy war can give an answer here. It certainly has *nothing* to do with Python; Python calls the operating system functions to read from the network and write to the disk almost directly. So it must be the operating system itself that slows it down. To investigate further, you might drop the write operating, and measure only source.read(). If that is slower, then, for some reason, the network speed is bad on Windows. Maybe you have the network interfaces misconfigured? Maybe you are using wireless on Windows, but cable on Linux? Maybe you have some network filtering software running on Windows? Maybe it's just that Windows sucks?-) If the network read speed is fine, but writing slows down, I ask the same questions. Perhaps you have some virus scanner installed that filters all write operations? Maybe Windows sucks? Regards, Martin Thanks for the ideas, Martin. I ran a couple of experiments to find the culprit, by downloading the same 20 MB file from the same fast server. I compared: 1. DL to HD vs USB iPod. 2. AV on-access protection on vs. off 3. source. read() only vs. file.write( source.read() ) The culprit is definitely the write speed on the iPod. That is, everything runs plenty fast (~1 MB/s down) as long as I'm not writing directly to the iPod. This is kind of odd, because if I copy the file over from the HD to the iPod using windows (drag-n-drop), it takes about a second or two, so about 10 MB/s. So the problem is definitely partially Windows, but it also seems that Python's file.write() function is not without blame. It's the combination of Windows, iPod and Python's data stream that is slowing me down. I'm not really sure what I can do about this. I'll experiment a little more and see if there's any way around this bottleneck. If anyone has run into a problem like this, I'd love to hear about it... thanks again, --danny -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Strings
On Feb 7, 5:23 am, Terry Reedy tjre...@udel.edu wrote: John Machin wrote: The UTF-n siblings are *external* representations. 2.x: a_unicode_object.decode('UTF-16') - an_str_object 3.x: an_str_object.decode('UTF-16') - a_bytes_object That should be .encode() to bytes, which is the coded form. .decode is bytes = str/unicode True. I guess that makes me the Dohmouse :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Flattening lists
On Feb 5, 1:16 pm, Michele Simionato michele.simion...@gmail.com wrote: On Feb 5, 7:24 pm, a...@pythoncraft.com (Aahz) wrote: In article a22c77c4-a812-4e42-8972-6f3eedf72...@l33g2000pri.googlegroups.com, Michele Simionato michele.simion...@gmail.com wrote: Looks fine to me. In some situations you may also use hasattr(el, '__iter__') instead of isinstance(el, list) (it depends if you want to flatten generic iterables or only lists). Of course, once you do that, you need to special-case strings... Strings are iterable but have no __iter__ method, which is fine in this context, since I would say 99.9% of times one wants to treat them as atomic objects, so no need to special case. Don't worry, that little oddity was fixed for you: Python 3.0+ (unknown, Dec 8 2008, 14:26:15) [GCC 4.3.2] on linux2 Type help, copyright, credits or license for more information. str.__iter__ slot wrapper '__iter__' of 'str' objects bytes.__iter__ slot wrapper '__iter__' of 'bytes' objects bytearray.__iter__ slot wrapper '__iter__' of 'bytearray' objects I'm in the why do you need more than 1 depth? camp. Dispatching based on your own type should be given an extra look. Dispatching based passed in types should be given three extra looks. I didn't realize itertools.chain(*iterable) worked. I guess that needs to be pushed as the canonical form. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using cPickle
On Feb 6, 3:09 pm, MRAB goo...@mrabarnett.plus.com wrote: mmcclaf wrote: On Feb 6, 10:25 am, Steve Holden st...@holdenweb.com wrote: mmcclaf wrote: Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line for line in stuff: Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First Name Email Address Doe John j...@doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. Make sure you use modes rb and wb when you open the pickle files. If you are running on Windows this can make a difference. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ I've tried both rb and wb as well as r and w, there appears to be no difference in the running of the code. cPickle.dump(work,output) writes a string and stuff=cPickle.load(input) just reads that string, so for line in stuff: is iterating through the characters if the string. You need to use cPickle.load() to read each string (line). Ok, so I just modified that section to: [code] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff input.close() [/code] And now it's printing it out ok, but then I get an EOFError at stuff=cPickle.load(onput) at line 45. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ordered dict by default
Cameron Simpson wrote: On 05Feb2009 01:47, bearophileh...@lycos.com bearophileh...@lycos.com wrote: | [...] But even if the average performance becomes a | little worse I think making the default Python dict as ordered is a | positive change for Python too, because built-ins are meant to be as | flexible as possible, even if they aren't the fastest ones or the less | memory hungry ones [snip] I would much rather keep dictionaries as performant as possible, as a bare mapping, and add an odict for when order matters. +1 -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 performance on windows, usb connection
dq wrote: Martin v. Löwis wrote: So does anyone know what the deal is with this? Why is the same code so much slower on Windows? Hope someone can tell me before a holy war erupts :-) Only the holy war can give an answer here. It certainly has *nothing* to do with Python; Python calls the operating system functions to read from the network and write to the disk almost directly. So it must be the operating system itself that slows it down. To investigate further, you might drop the write operating, and measure only source.read(). If that is slower, then, for some reason, the network speed is bad on Windows. Maybe you have the network interfaces misconfigured? Maybe you are using wireless on Windows, but cable on Linux? Maybe you have some network filtering software running on Windows? Maybe it's just that Windows sucks?-) If the network read speed is fine, but writing slows down, I ask the same questions. Perhaps you have some virus scanner installed that filters all write operations? Maybe Windows sucks? Regards, Martin Thanks for the ideas, Martin. I ran a couple of experiments to find the culprit, by downloading the same 20 MB file from the same fast server. I compared: 1. DL to HD vs USB iPod. 2. AV on-access protection on vs. off 3. source. read() only vs. file.write( source.read() ) The culprit is definitely the write speed on the iPod. That is, everything runs plenty fast (~1 MB/s down) as long as I'm not writing directly to the iPod. This is kind of odd, because if I copy the file over from the HD to the iPod using windows (drag-n-drop), it takes about a second or two, so about 10 MB/s. So the problem is definitely partially Windows, but it also seems that Python's file.write() function is not without blame. It's the combination of Windows, iPod and Python's data stream that is slowing me down. I'm not really sure what I can do about this. I'll experiment a little more and see if there's any way around this bottleneck. If anyone has run into a problem like this, I'd love to hear about it... You could try copying the file to the iPod using the command line, or copying data from disk to iPod in, say, C, anything but Python. This would allow you to identify whether Python itself has anything to do with it. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using multiprocessing from a Windows service
On 6/02/2009 4:21 PM, Volodymyr Orlenko wrote: In the patch I submitted, I simply check if the name of the supposed module ends with .exe. It works fine for my case, but maybe this is too general. Is there a chance that a Python module would end in .exe? IIRC, py2exe may create executables where sys.argv[0] is the executable itself. Maybe if we consider and handle both these cases a patch to mp might be looked upon in a better light... Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: WIn32api
On 7/02/2009 3:28 AM, K-Dawg wrote: You might like to seek out the python-win32 mailing list for stuff like this where more people tend to pay attention to windows problems. This works if I call run() specifically. But when I try to initiate the thread with .start() I get the following error Unfortunately threads and COM are tricky. The short story is that you can't, in the general case, pass a COM object from one thread to another. You need to google COM threading models, and if you *really* want to pass objects between threads, the impressively named MSCOM function CoMarshalInterThreadInterfaceInStream (exposed via the pythoncom module). The above mailing list has had a number of threads on this issue over the years... Cheers, Mark -- http://mail.python.org/mailman/listinfo/python-list
Re: Using cPickle
mmcclaf wrote: On Feb 6, 3:09 pm, MRAB goo...@mrabarnett.plus.com wrote: mmcclaf wrote: On Feb 6, 10:25 am, Steve Holden st...@holdenweb.com wrote: mmcclaf wrote: Hi there, I have to make a small database using cPickle. I'm having troubles trying to read in the information if it's more than one line. I'm pretty sure it's in the line for line in stuff: Can anyone help me out? Basically the end result is wanting it to look something like what is down below when list is typed in: Last name First NameEmail Address Doe John j...@doe.com [code] # @author: Ocdt Murray McClafferty 24656 # This will manage a small database using the cPickle module. # It must maintain a list of last names, first names and email addresses, and must let a user interact with the program # #!usr/bin/python # -*- coding: utf-8 -*- import sys import cPickle # format = '%s %s %s' try: filename = sys.argv[1] input = open(filename, 'r') except IOError: print 'File is not available, will create a new file now' lastName='Last Name' firstName='First Name' email= 'Email' #input.close() output=open (filename, 'w') total = format%(lastName, firstName, email) cPickle.dump(total,output) #cPickle.dump(firstName,output) #cPickle.dump(email,output) output.close() except EOFError: print 'File is empty' #datas = cPickle.load(input) while True: command=sys.stdin.readline()[:-1] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff print line input.close() if command=='exit' or command=='quit' : #NEVER forget the exit!!! print 'Save changes? y for Yes, n for No' commandSave=sys.stdin.readline()[:-1] if commandSave =='y': #if the user wants to save output=open(filename, 'w') cPickle.dump(work,output) output.close() sys.exit(0) if commandSave =='n': #no save input.close() sys.exit(0) if command=='add': #adds an entity to the file print 'Last name?' lastName=sys.stdin.readline()[:-1] print 'First name?' firstName=sys.stdin.readline()[:-1] print 'Email address?' email=sys.stdin.readline()[:-1] work = format%(lastName, firstName, email) #output=open(filename, 'w') #data=cPickle.load(output) #data.append(work) #output.close() output=open(filename, 'a') cPickle.dump(work,output) output.close() [/code] All help would be appreciated. I am new to Python and this seems to be quite a challenge for me. Make sure you use modes rb and wb when you open the pickle files. If you are running on Windows this can make a difference. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ I've tried both rb and wb as well as r and w, there appears to be no difference in the running of the code. cPickle.dump(work,output) writes a string and stuff=cPickle.load(input) just reads that string, so for line in stuff: is iterating through the characters if the string. You need to use cPickle.load() to read each string (line). Ok, so I just modified that section to: [code] if command=='list': #lists the data in the file input = open(filename, 'r') stuff=cPickle.load(input) for line in stuff: You're still iterating over the string. #firstName=cPickle.load(input) #email=cPickle.load(input) #print repr (lastName).rjust(10), repr(firstName).rjust(20), repr (email).rjust(20) stuff=cPickle.load(input) print stuff input.close() [/code] And now it's printing it out ok, but then I get an EOFError at stuff=cPickle.load(onput) at line 45. You can just keep reading until EOFError occurs, at which point you know you've reached the end of the file: input = open(filename, 'rb') try: while True: stuff = cPickle.load(input) print stuff except EOFError: pass input.close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department, engagement, date, stare_hour)) My brain might explode if i continue. Relax. Bye, bearophile Projects was meant to be engagements. All these suggestions are great, let me see what i can make happen right now. Thanks all! -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department, engagement, date, stare_hour)) My brain might explode if i continue. Relax. Bye, bearophile UH OH GUYS! line 110, in sorter timesheets.sort(key=attrgetter(department, engagement, date,start)) TypeError: attrgetter expected 1 arguments, got 4 -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
On Feb 6, 2:17 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department, engagement, date, stare_hour)) My brain might explode if i continue. Relax. Bye, bearophile UH OH GUYS! line 110, in sorter timesheets.sort(key=attrgetter(department, engagement, date,start)) TypeError: attrgetter expected 1 arguments, got 4 I think there may have been a misunderstanding. I was already using attrgetter, my problem is that it doesn't appear to be sorting by the argument i give it. How does sort work with strings? How about with datetime.time or datetime.date? So far i can get it sorting strictly by the datetime objects, but i need all of this sorting done within the constraints imposed by doing sorts via department and engagements. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
On Feb 6, 2:20 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 2:17 pm, Robocop btha...@physics.ucsd.edu wrote: On Feb 6, 1:03 pm, bearophileh...@lycos.com wrote: Robocop: then within each department block of the list, have it organized by projects. I don't know what does it means. timesheets.sort(key=operator.attrgetter('string')) Try something like: timesheets.sort(key=attrgetter(department, engagement, date, stare_hour)) My brain might explode if i continue. Relax. Bye, bearophile UH OH GUYS! line 110, in sorter timesheets.sort(key=attrgetter(department, engagement, date,start)) TypeError: attrgetter expected 1 arguments, got 4 I think there may have been a misunderstanding. I was already using attrgetter, my problem is that it doesn't appear to be sorting by the argument i give it. How does sort work with strings? How about with datetime.time or datetime.date? So far i can get it sorting strictly by the datetime objects, but i need all of this sorting done within the constraints imposed by doing sorts via department and engagements. Any ideas? I'm stuck with python 2.4 right now:( -- http://mail.python.org/mailman/listinfo/python-list
Re: Trouble sorting a list of objects by attributes
Robocop wrote: UH OH GUYS! line 110, in sorter timesheets.sort(key=attrgetter(department, engagement, date,start)) TypeError: attrgetter expected 1 arguments, got 4 Um... what version of Python are you running? Alway specify. (Too many people do not). In 3.0 from operator import attrgetter f=attrgetter(department, engagement,date,start) runs fine as per the doc. operator.attrgetter(attr[, args...]) Return a callable object that fetches attr from its operand. If more than one attribute is requested, returns a tuple of attributes. After, f = attrgetter('name'), the call f(b) returns b.name. After, f = attrgetter('name', 'date'), the call f(b) returns (b.name, b.date). -- http://mail.python.org/mailman/listinfo/python-list