NumPy 1.0.3 released
We are pleased to announce the release of NumPy 1.0.3 Hopefully, this release will work better with multiple interpreters as well as having some significant bugs fixed. Other changes include * x/y follows Python standard on mixed-sign division for array scalars and numpy arrays * iinfo added to provide information on integer data-types * improvements to SWIG typemaps, numpy.distutils, and f2py * improvements to separator handling in fromfile and fromstring * many, many bug fixes Thank you to everybody who contributed to the recent release. Best regards, NumPy Developers http://numpy.scipy.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
DFW Pythoneers: 4th Saturday Meeting THIS Sat
Although it is Memorial Day weekend, we're going to hold a meeting at Nerdbooks as usual. I've checked with the owner and the store is open, and hopefully some of you will show up, although I've not heard many replies as to whether you will/won't make it. As a result of work on the Forrester survey, we've got some source examples, designed to be clear and easy to understand, for us to walk through. - A mashup by Martin of placing temperature readings collected from one site using REST, onto a DFW Google map. - HTML page generation using Twisted Nevow/STAN, along with an RSS feed parser module to embed a list of the N most recent news stories. - Simple but powerful presentation and form validation using the Gizmo(QP) framework, which does the validation both in the server *and* in the browser using JavaScript. No big deal, until you realize the JavaScript in the browser is generated from the Python source, and the whole source fits on a couple of screens. - An RSS feed reader that pulls down all images linked to, from one of those photo sites, and the source is 15 lines of Python. - A cool module, NamedTuples, from the Python Cookbook site. - A couple of small programs that apply the screenscraping module BeautifulSoup to the task of extracting the set of mailing list, and associated archives, from a Mailman website. And if we need more, I've got PyFUSE, a Filesystem in Userspace in Python, where you can overlay a filesystem metaphor over your database, website or existing filesystem -- think autobackup-on-write. It looks quite powerful. And a silly program I whipped up one night to play with some Lisp-like atom ideas, where you can have bound and unbound names, without a lot of quoting syntax. A bit strange but small and introduces a new use for property descriptors. Hope to see you there, and bring your own topics or questions, along with your laptops. We may not get to everything but swimming in everyone's 'lightning talk'-like ideas is fun. Time and Place: Nerdbooks.com in Richardson (see the website for directions) 2pm until 5pm Oh, and all but the FUSE source examples are already in our club subversion repository, under the Projects/ directory. You can find a link to browse the source through the web at http://dfwpython.org, in the menu on the left. Jeff Rush DFW Pythoneers Organizer -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
First PyCon UK Conference
The first ever PyCon UK takes place in Birmingham on 8th 9th September 2007. Bookings are open at http://www.pyconuk.org/booking.html. An early bird rate is offered until 30th June. For more information please visit http://www.pyconuk.org/ CALL FOR PAPERS Want to share your expertise? PyConUK 2007 is looking for proposals to fill the formal presentation tracks. We will accept a broad range of presentations, from reports on academic and commercial projects to tutorials and case studies. As long as the presentation is interesting and potentially useful to the Python community, it will be considered for inclusion in the program. Can you show the conference-goers something new and useful? Can you show attendees how to: use a module? explore a Python language feature? package an application? Most talks will be 30 minutes, although 60 minutes may be allocated for a particularly valuable talk requiring an extended length of time. There will also be a dedicated Lightning Talk session for talks no longer than five minutes. PyconUK is a not for profit community conference, so we sadly cannot reward speakers (but what price on glory!). To submit a talk go to http://www.pyconuk.org/submit.html -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
ANN: Veusz-0.99.0 - a scientific plotting package
I am pleased to announce a new beta of a largely rewritten Veusz plotting package. This now uses Qt4 and numpy, adding support for Windows. Windows and Linux binaries are provided. For details see below: Veusz 0.99.0 (new Qt4/numpy beta) Velvet Ember Under Sky Zenith - http://home.gna.org/veusz/ Veusz is Copyright (C) 2003-2007 Jeremy Sanders [EMAIL PROTECTED] Licenced under the GPL (version 2 or greater). Veusz is a scientific plotting package written in Python, using PyQt4 for display and user-interfaces, and numpy for handling the numeric data. Veusz is designed to produce publication-ready Postscript/PDF output. The user interface aims to be simple, consistent and powerful. Veusz provides a GUI, command line, embedding and scripting interface (based on Python) to its plotting facilities. It also allows for manipulation and editing of datasets. Changes from 0.10: This is the first release of a much rewritten version of Veusz It has been updated to run under Qt4 and numpy, and now supports Windows The user interface is also signficantly easier to use Other useful features include: * Colorbars for images (better color scaling for images too) * Grids of graphs with different sized subgraphs * Much better import dialog * Antialiased screen output * Native PNG and PDF export * Separate formatting/properties dialog * Handling of INF/NaN in input data * Transparency of graphs (not for EPS output) Plus many more useful changes (see ChangeLog) Features of package: * X-Y plots (with errorbars) * Line and function plots * Contour plots * Images (with colour mappings and colorbars) * Stepped plots (for histograms) * Fitting functions to data * Stacked plots and arrays of plots * Plot keys * Plot labels * LaTeX-like formatting for text * EPS/PDF/PNG export * Scripting interface * Dataset creation/manipulation * Embed Veusz within other programs * Text, CSV and FITS importing Requirements: Python (2.3 or greater required) http://www.python.org/ Qt = 4.1 (free edition) http://www.trolltech.com/products/qt/ PyQt = 4.1 (SIP is required to be installed first) http://www.riverbankcomputing.co.uk/pyqt/ http://www.riverbankcomputing.co.uk/sip/ numpy = 1.0 http://numpy.scipy.org/ Microsoft Core Fonts (recommended for nice output) http://corefonts.sourceforge.net/ PyFITS = 1.1rc3 (optional for FITS import) http://www.stsci.edu/resources/software_hardware/pyfits For documentation on using Veusz, see the Documents directory. The manual is in pdf, html and text format (generated from docbook). Issues: * This is a new beta, so there are likely to be a number of bugs, even though it has been used by a couple of people for some time. * Can be very slow to plot large datasets if antialiasing is enabled. Right click on graph and disable antialias to speed up output. * Some older versions of Qt (4.2.2) can produce very large postscript output and random crashes. This may not be completely resolved (especially on windows). * The embedding interface appears to crash on exiting. If you enjoy using Veusz, I would love to hear from you. Please join the mailing lists at https://gna.org/mail/?group=veusz to discuss new features or if you'd like to contribute code. The latest code can always be found in the SVN repository. Jeremy Sanders -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Accessing iTunes with Python via the Windows SDK
On May 24, 12:17 am, Tony Meyer [EMAIL PROTECTED] wrote: On May 24, 4:23 pm, Denrael [EMAIL PROTECTED] wrote: I've been playing with the iTunes sdk on windows, and have come across a strange problem. With the following code: The object you get back from iTunes.CurrentTrack (the traceback shows this) is an IITTrack. If you check the iTunes SDK, you'll see that IITTrack objects don't have a SkippedCount attribute - IITFileOrCDTrack objects do (from memory, this excludes things like radio links). You need to conver the IITrack object to a IITFileOrCDTrack object (assuming that it is one); you can do this with win32com.client.CastTo, as follows: Cheers, Tony Thanks Tony! I had a suspicion it had to do with casting it, but I was missing some synapses to figure out exactly how to do that. Things have changed from my Assembly Language PL/1 and REXX days. :) I figure if I'm gonna learn a new language, Python's a lot more usable than VBS, and it has an elegance to it that I already appreciate. I'm working my way thru Learning Python ... I suppose I better find some doc on the Win32 COM stuff too. -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists vs tuples (newbie)
Neil Cerutti [EMAIL PROTECTED] wrote: I use tuples simply because of their mellifluous appellation. +1 QOTW. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Properties/Decorators [WAS: Can I reference 1 instance of an object by more names ? rephrase]
Diez B. Roggisch wrote: Deprecated doesn't mean it's not available. Is that so? ;) But it certainly means that some time in the not-too-distant future apply will vanish. And even if it goes away, you can simply write it yourself: def apply(f, *args, **kwargs): return f(*args, **kwargs) Do you know that feeling you have, when you've just been shown something really surprising but utterly simple, that blows you away so much that for a moment the whole world seems like magic and you feel you are just a mundane pencilhead? I get that a lot ... ;) W -- http://mail.python.org/mailman/listinfo/python-list
Re: too much memory use
rohit [EMAIL PROTECTED] wrote: i am making a program for desktop search. in order to make it more effective im implementing the records in the form of a tree(files starting with 'a','b','c'have different trees ..so 26 trees in all) in memory and writing it down in file. the max size file has 16000 records...now to implement the tree in list i'm using line no as index ..and empty child nodes are represented as \n all this work is going on in the memory.. problem is the system eats up my 512 mb RAM +1gb virtual store n hangs cant think of an effective way to implement tree in memory(i can compact it on disk by writing just the index no..along with the record from which tree in memory can be reconstructed, but i have to implement tree as previous to implement random access) Why don't you just use a database? That's what they're designed for. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: 0 == False but [] != False?
Rajarshi [EMAIL PROTECTED] wrote: This is a slightly naive question, but I know that 0 can be used to represent False. So 0 == False True But, I know I can use [] to represent False as in if not []: print 'empty' ... empty But then doing the following gives a surprising (to me!) result [] == False False Could anybody point out why this is the case? False is just a constant. 0, (), '', [], and False are all constants that happen to evaluate to a false value in a Boolean context, but they are not all the same. As a general rule, I've found code like if x == False to be a bad idea in ANY language. -- Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Python Uno Bridge Architecture
Hi, I am trying to write a bridge similar to Python- Uno bridge. I have read from these links about the PyUNO bridge. http://udk.openoffice.org/python/python-bridge.html But I haven't found information about the basic achitecture of the bridge. Eg: the basic requirements of the files, library, specific directory structure . Is there any document/tutorial available about the approach taken to write the bridge? Also can you tell me about the basic steps required to write a UNO bridge ? Thanks, Sneha -- http://mail.python.org/mailman/listinfo/python-list
ANN: Veusz-0.99.0 - a scientific plotting package
I am pleased to announce a new beta of a largely rewritten Veusz plotting package. This now uses Qt4 and numpy, adding support for Windows. Windows and Linux binaries are provided. For details see below: Veusz 0.99.0 (new Qt4/numpy beta) Velvet Ember Under Sky Zenith - http://home.gna.org/veusz/ Veusz is Copyright (C) 2003-2007 Jeremy Sanders [EMAIL PROTECTED] Licenced under the GPL (version 2 or greater). Veusz is a scientific plotting package written in Python, using PyQt4 for display and user-interfaces, and numpy for handling the numeric data. Veusz is designed to produce publication-ready Postscript/PDF output. The user interface aims to be simple, consistent and powerful. Veusz provides a GUI, command line, embedding and scripting interface (based on Python) to its plotting facilities. It also allows for manipulation and editing of datasets. Changes from 0.10: This is the first release of a much rewritten version of Veusz It has been updated to run under Qt4 and numpy, and now supports Windows The user interface is also signficantly easier to use Other useful features include: * Colorbars for images (better color scaling for images too) * Grids of graphs with different sized subgraphs * Much better import dialog * Antialiased screen output * Native PNG and PDF export * Separate formatting/properties dialog * Handling of INF/NaN in input data * Transparency of graphs (not for EPS output) Plus many more useful changes (see ChangeLog) Features of package: * X-Y plots (with errorbars) * Line and function plots * Contour plots * Images (with colour mappings and colorbars) * Stepped plots (for histograms) * Fitting functions to data * Stacked plots and arrays of plots * Plot keys * Plot labels * LaTeX-like formatting for text * EPS/PDF/PNG export * Scripting interface * Dataset creation/manipulation * Embed Veusz within other programs * Text, CSV and FITS importing Requirements: Python (2.3 or greater required) http://www.python.org/ Qt = 4.1 (free edition) http://www.trolltech.com/products/qt/ PyQt = 4.1 (SIP is required to be installed first) http://www.riverbankcomputing.co.uk/pyqt/ http://www.riverbankcomputing.co.uk/sip/ numpy = 1.0 http://numpy.scipy.org/ Microsoft Core Fonts (recommended for nice output) http://corefonts.sourceforge.net/ PyFITS = 1.1rc3 (optional for FITS import) http://www.stsci.edu/resources/software_hardware/pyfits For documentation on using Veusz, see the Documents directory. The manual is in pdf, html and text format (generated from docbook). Issues: * This is a new beta, so there are likely to be a number of bugs, even though it has been used by a couple of people for some time. * Can be very slow to plot large datasets if antialiasing is enabled. Right click on graph and disable antialias to speed up output. * Some older versions of Qt (4.2.2) can produce very large postscript output and random crashes. This may not be completely resolved (especially on windows). * The embedding interface appears to crash on exiting. If you enjoy using Veusz, I would love to hear from you. Please join the mailing lists at https://gna.org/mail/?group=veusz to discuss new features or if you'd like to contribute code. The latest code can always be found in the SVN repository. Jeremy Sanders -- http://mail.python.org/mailman/listinfo/python-list
Re: Can I reference 1 instance of an object by more names ? rephrase
Maric Michaud a écrit : Stef Mientki a écrit : (snip) # I need to read and write the individual bits of the byte object # so I can create 8 blocks of code like this, one for each bit position # I use it, like this #name1 = cpu_ports() #name1.p5 = True # or #name1.p[5] = True @apply # read / write bit 5 def p5(): def fset(self, value): index= 5 value= ( value 1L ) index mask = ( 1L ) index self._d = ( self._d ~mask ) | value def fget(self): index= 5 return ( self._d index ) 1 return property(**locals()) I can optimize the above code a little bit, but I've the feeling that I don't need to repeat this code 8 times. something like that should just work (untested) : def bit(): def fset(self, value): index= 5 value= ( value 1L ) index mask = ( 1L ) index self._d = ( self._d ~mask ) | value def fget(self): index= 5 return ( self._d index ) 1 return property(**locals()) class cpu_ports(object) : p1 = bit() p2 = bit() p3 = bit() p4 = bit() p5 = bit() As a side note, properties are just an example of objects using the descriptor protocol. You can build your own descriptors for more advanced use (think : 'smart' attributes): http://users.rcn.com/python/download/Descriptor.htm http://docs.python.org/ref/descriptors.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Call script which accepts com. line par. from another scriptand error control
Hi James, Thanks for that. That is exactly what i needed for the error control bit... What I still dont know though is how do I handle the fact that the first script is expecting command line parameters. I would like to be able to replace the command line parameters by a variable such that the second script can call: first_script.main(command line). Is this possible? If i can simply do whatever it is that parse_args() does but on a variable of my choosing.. Karim From: James Stroud [EMAIL PROTECTED] To: python-list@python.org Subject: Re: Call script which accepts com. line par. from another scriptand error control Date: Wed, 23 May 2007 17:21:47 -0700 Karim Ali wrote: def MAIN(expression2parse)- add a main so can call from other script Of course you don't mean you want another python interpreter to fire up and run the other script? Here is an example of the way to do what you are suggesting: # mod1.py def doit(param): if not param % 37: raise ValueError, 'Why u want to do dat?' else: print 'All right!' return 'Value is: %s' % param # end of mod1.py # mod2.py import mod1 print mod1.doit(20) print print mod1.doit(30) print try: print mod1.doit(37) except ValueError: print 'Gracefully handling 37' print print mod1.doit(37) # end of mod2 James -- http://mail.python.org/mailman/listinfo/python-list _ Fight Allergies With Live Search http://search.live.com/results.aspx?q=Remedies+For+Spring+Allergiesmkt=en-caFORM=SERNEP -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists vs tuples (newbie)
Duncan Booth [EMAIL PROTECTED] wrote: Hendrik van Rooyen [EMAIL PROTECTED] wrote: Aside from the hashing issue, there is nothing that a tuple can do that can't be done as well or better by a list. There are a few other cases where you have to use a tuple, for example in a try..except statement the exception specification must be an exception to be caught or a tuple of exception specifications: a list won't work to catch multiple exceptions. Esoteric - But I stand corrected... any other must use a tuple's ? Seems they all fall into a class that can be described as required by the language - I was thinking data. - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: [Fwd: Re: managed lists?]
@ Larry, As much as I like to follow the idiom that Python has, I do not see the usefulness of making an add function that checks the interface that other objects might need. Besides the fact it is a bit overhead and not to mention performance draining, in an application that I develop myself, without plugin architecture (not yet) etc, it is a bit much to do that. I agree with the writing C in Python, it is all I know, because that is the language I started with. This is my first big project and most certainly when evaluating this when it is finished I will come to the conclusion it was all for nothing ;-) I will change to extend() and maybe drop the type safety, but I do wish to keep the list functionality as I find it more logical to write song.categories.append() Then creating a method in song called AddCategory() and kind of duplicating the list functionality there. Thank you for the guide lines and the nice comments! They are really helpful. @ Bruno, list. The right solution IMHO is to *not* expose these lists as part of the interface - after all, the fact that tabs and tunes are stored in lists is an implementation detail -, and to add the necessary API to the Song object - ie : Song.add_tune, Song.add_tab, Song.iter_tunes, Song.iter_tabs, etc. Then you just have to add some assert statements in the add_XXX methods so you'll be warned at the right time when some part This is how I did it before, I created Song.AddTab, Song.DeleteTab, then there was a category class which also needed adding, deleting, clearing, and soon my whole Song object was filled with relational methods which were basically a copy of the list, with a check on the presence of the class in the list. Then I realized, a managed list with self-check capability solves this because I do not like to duplicate code, but now that I think of it, the type check might be a bit too much. Like said, the list solution you described and the solution I use, are basically the same, I encapsulated a list [] in a class, with some extra methods to warn the 'owner' of the list that something is changed. Oh, yes, while we're at it, and in case you don't know yet: the Python idiom for implementation attributes (including methods - remember, everything is an object) is to prefix them with a single underscore. Ok, but why is that? I do know semi-private symbols can be realised using two underscores, and if I wish to hide a list / index / etc so it cannot accidentally changed, would I not use double underscores? Thanks for your extensive help! - Jorgen -- http://mail.python.org/mailman/listinfo/python-list
Web Archtecture using tow layers in Phyton
Hello, I need to develop an web applications that meet the following requirements: - 2 layers: the first one is the user interface (browser) and the second one is the interaction with the operacional system of the server. - the second layer must be developed using Python. I'd like to know if it is possible to implement this system... making the second layer using python and the first layer using another web technologies like AJAX for example. Does anybody have any experience in developing python web applications? Maybe send me some links or documentation about it... The final goal is to make diferent user interfaces (layer 1) that can integrate with the second layer... for example, one web interface and one local interface using python+qt (example)... i don't know if this is possible and how can this be implemented... any help is aprreciated... Thanks in advance, Wagner. - AVISO LEGAL: Esta mensagem eletrônica (e qualquer anexo) é confidencial e endereçada ao(s) indivíduo(s) referidos acima e a outros que tenham sido expressamente autorizados à recebe-la. Se você não é o destinatário(a) desta mensagem, por favor não copie, use ou divulgue seu conteúdo à outros. Caso você tenha recebido esta mensagem equivocadamente, por favor apague esta mensagem e eventuais copias. LEGAL NOTICE: This e-mail communication (and any attachments) is confidential and is intended only for the individual(s) named above and others who have been specifically authorized to receive it. If you are not the intended recipient, please do not read, copy, use or disclose the contents of this communication to others. Please then delete the e-mail and any copies of it. AVISO LEGAL: Este mensaje electrónico (y cualquier anexo) es confidencial y está dirigido exclusivamente a su(s) destinatario(s) arriba indicados y aquellos que hayan sido expresamente autorizados a recibirlo. Si usted no es el destinatario(s) de este mensaje, por favor no copie, use o divulgue el contenido a terceros. En caso que usted haya recibido este mensaje por error, por favor proceda a su destrucción y al de las posibles copias. -- http://mail.python.org/mailman/listinfo/python-list
Different methods with same name but different signature?
william dy christin de los santos lynor laxina - Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos more. -- http://mail.python.org/mailman/listinfo/python-list
Re: Call script which accepts com. line par. from another scriptand error control
Karim Ali wrote: What I still dont know though is how do I handle the fact that the first script is expecting command line parameters. I would like to be able to replace the command line parameters by a variable such that the second script can call: first_script.main(command line). Is this possible? I think it is better to pass a list of arguments # first_script.py def main(args=None): parser = optparse.OptionParser() # add options options, positional_args = parser.parse_args(args) # process if __name__ == __main__: # will read options from the command line # if module is invoked as a standalone script main() # second_script.py import first_script first_script.main([-f, --bar, what, you want]) That way you don't have to deal with escaping spaces etc. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Inheriting from Python list object(type?)
On May 23, 10:07 pm, Mangabasi [EMAIL PROTECTED] wrote: This is the winner: class Point(list): def __init__(self, x, y, z = 1): super(Point, self).__init__([x, y, z]) self.x = x self.y = y self.z = z def __getattr__(self, name): if name == 'x': return self[0] elif name == 'y': return self[1] elif name == 'z': return self[2] else: return self.__dict__[name] def __setattr__(self, name, value): if name == 'x': self[0] = value elif name == 'y': self[1] = value elif name == 'z': self[2] = value else: self.__dict__[name] = value Inheritation is an is a relation. Point, however, is not a list. This adds some weird behaviour to Point: p = Point(1,2,3) p.append(4) print p[3] That makes no sense but your Point implementation allows it. This is probably even more surprasing behaviour: p = Point(1,2,3) + Point(4,5,6) print p One might expect the points to be added to Point(5,7,9), not into a list containing [1,2,3,4,5,6]. I'd suggest you don't inherit Point from anything, and just add an __iter__ member function that iterates through x,y and z. E.g. def __iter__(self): yield self.x yield self.y yield self.z Then you can convert a Point p to a list by doing list(p). Or to a tuple with tuple(p). __array__ could also be implemented for convenince with numpy (if I understood that correctly). -- http://mail.python.org/mailman/listinfo/python-list
The Relative Importance of Web Development
If you follow the evolution of software development on Internet, you may have the impression that every new development is Web based and that the main areas of concern are whether you should develop new application with Ruby on Rail or if you should choose Flash rather than Ajax for the interface. However, if you ask developers, you may find that the Web is not as ubiquitous in their work as you may think. Even if 66% of the participants develop the majority of their new applications with a browser as the interface, there is still a large portion of developers that are working today for operating contexts that are outside the Web world, like embedded software or Windows applications. Get the full results of this poll on http://www.methodsandtools.com/dynpoll/oldpoll.php?WebDev2 -- http://mail.python.org/mailman/listinfo/python-list
Locale case change not working
When using unicode the case change works: print u'É'.lower() é But when using the pt_BR.utf-8 locale it doesn't: locale.setlocale(locale.LC_ALL, 'pt_BR.utf-8') 'pt_BR.utf-8' locale.getlocale() ('pt_BR', 'utf') print 'É'.lower() É What am I missing? I'm in Fedora Core 5 and Python 2.4.3. # cat /etc/sysconfig/i18n LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 Regards, Clodoaldo Pinto Neto -- http://mail.python.org/mailman/listinfo/python-list
function nested
i have this function. def f(start): stack = [] def f1(start): for fname in os.listdir(startDir): path = os.path.join(startDir, fname) if os.path.isfile(path): stack.append(path) else: f1(path) return stack this is returning empty list, why? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Basic Class/Instance Question
On 2007-05-23, Wildemar Wildenburger [EMAIL PROTECTED] wrote: Antoon Pardon wrote: This is a FAQ. Default arguments are only evaled once - when the def statement is evaled (which is usually at import time). The solution is simple: don't use mutable objects as default arguments: An immutable object would have given the same behaviour in this case class A(object): def __init__(self, val = ()): self.val=val obj1 = A() obj2 = A() print obj1 is obj2 # False print obj1.val is obj2.val # True Yeah, but is that a problem? Since you can not change them anyway, there's no harm. I think it can make comprehension harder if you suggest in your explanation that a partcilular behaviour is linked to an object being mutable while that has nothing to do with it. You are correct that one can't mutate the val attribute but some code might depend on the distinction identical or not instead of equal or not. Not understanding this issue of default arguments could cause a bug in such code even if the default argument is not mutable. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: Locale case change not working
Clodoaldo wrote: When using unicode the case change works: print u'É'.lower() é But when using the pt_BR.utf-8 locale it doesn't: locale.setlocale(locale.LC_ALL, 'pt_BR.utf-8') 'pt_BR.utf-8' locale.getlocale() ('pt_BR', 'utf') print 'É'.lower() É What am I missing? I'm in Fedora Core 5 and Python 2.4.3. # cat /etc/sysconfig/i18n LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 Regards, Clodoaldo Pinto Neto str.lower() operates on bytes and therefore doesn't handle encodings with multibyte characters (like utf-8) properly: uÉ.encode(utf8) '\xc3\x89' uÉ.encode(latin1) '\xc9' import locale locale.setlocale(locale.LC_ALL, de_DE.utf8) 'de_DE.utf8' print unicode(\xc3\x89.lower(), utf8) É locale.setlocale(locale.LC_ALL, de_DE.latin1) 'de_DE.latin1' print unicode(\xc9.lower(), latin1) é I recommend that you forget about byte strings and use unicode throughout. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: function nested
Gigs_ wrote: i have this function. def f(start): stack = [] def f1(start): for fname in os.listdir(startDir): path = os.path.join(startDir, fname) if os.path.isfile(path): stack.append(path) else: f1(path) return stack this is returning empty list, why? Because f() doesn't invoke f1(). Peter -- http://mail.python.org/mailman/listinfo/python-list
Checking parameters prior to object initialisation
Fairly new to Python (and loving it!) In C++ (gack!) I got used to creating a helper function with each class to check the class object initialisation parameters prior to creating the object. In Python, this would be --- import example if example.ParametersOK(a, b, c, d): newObj = example.Example(a, b, c, d) else: print Error in parameters --- I presume this would still be considered good practise in Python, or is there some other, preferred, method? Cheers, Brett McSweeney -- http://mail.python.org/mailman/listinfo/python-list
Re: how to use imaageop.scale
On 23 May 2007 18:58:28 -0700, Bruce [EMAIL PROTECTED] wrote: On May 23, 5:31 pm, Amit Khemka [EMAIL PROTECTED] wrote: On 23 May 2007 00:02:34 -0700, Bruce [EMAIL PROTECTED] wrote: Hi, I want to compress a jpg file. e.g. a jpg file which has RGB band (24bit per pixel), 100 * 100 size to 50 * 50 size. I tried to use scale function in imageop module but failed. Any suggestions about this? Thanks! Were there any exceptions/error-messasges ? Do you jpeg libraries installed for hadling jpeg format ? Amit Marc, thank you very much. Now I used PIL instead and it works fine. But I still don't know how to complete this simple task with imageop module. I think imageop moudle can handle raw images only, so if you want to use imageop you will need to convert jpeg images to raw format. Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: function nested
def f(start): stack = [] def f1(start): for fname in os.listdir(start): path = os.path.join(start, fname) if os.path.isfile(path): stack.append(path) else: f1(path) f1(start) return stack i feel s stupid right now forgot to call f1 any comments how to make this better? -- http://mail.python.org/mailman/listinfo/python-list
Re: Locale case change not working
On May 24, 6:40 am, Peter Otten [EMAIL PROTECTED] wrote: Clodoaldo wrote: When using unicode the case change works: print u'É'.lower() é But when using the pt_BR.utf-8 locale it doesn't: locale.setlocale(locale.LC_ALL, 'pt_BR.utf-8') 'pt_BR.utf-8' locale.getlocale() ('pt_BR', 'utf') print 'É'.lower() É What am I missing? I'm in Fedora Core 5 and Python 2.4.3. # cat /etc/sysconfig/i18n LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 Regards, Clodoaldo Pinto Neto str.lower() operates on bytes and therefore doesn't handle encodings with multibyte characters (like utf-8) properly: uÉ.encode(utf8) '\xc3\x89' uÉ.encode(latin1) '\xc9' import locale locale.setlocale(locale.LC_ALL, de_DE.utf8) 'de_DE.utf8' print unicode(\xc3\x89.lower(), utf8) É locale.setlocale(locale.LC_ALL, de_DE.latin1) 'de_DE.latin1' print unicode(\xc9.lower(), latin1) é I recommend that you forget about byte strings and use unicode throughout. Now I understand it. Thanks. Regards, Clodoaldo Pinto Neto -- http://mail.python.org/mailman/listinfo/python-list
Re: function nested
On 5/24/07, Gigs_ [EMAIL PROTECTED] wrote: def f(start): stack = [] def f1(start): for fname in os.listdir(start): path = os.path.join(start, fname) if os.path.isfile(path): stack.append(path) else: f1(path) f1(start) return stack i feel s stupid right now forgot to call f1 any comments how to make this better? os.walk is just the way for you ! Cheers, Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: CP4E revival
Michael Tobis wrote: http://tinyurl.com/yr62r3 seems to short-circuit some pointless hoop-jumping to get you to the article. Hoop-jumping implemented to prevent just this kind of direct linking (and thus not saving of the PDF to local disk to view, and thus increasing the load on the server). Thanks for abusing the free service being provided to the Python Papers journal. Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking parameters prior to object initialisation
Brett_McS wrote: In C++ (gack!) I got used to creating a helper function with each class to check the class object initialisation parameters prior to creating the object. In Python, this would be --- import example if example.ParametersOK(a, b, c, d): newObj = example.Example(a, b, c, d) else: print Error in parameters --- I presume this would still be considered good practise in Python, or is there some other, preferred, method? Use exceptions to signal wrong parameters and move the parametersOk() test into the initializer class Example: def __init__(self, a, b, c, d): if a 0: raise ValueError(Negative length not allowed) #... Write a factory if - creating the Example instance carries too much overhead and wrong parameters are likely, or - the checks are costly and you often get parameters known to be OK. def make_example(a, b, c, d): if a 0: raise ValueError(Negative length not allowed) #... return Example(a, b, c, d) Example object creation then becomes try: newObj = example.Example(1,2,3,4) # or make_example(...) except ValueError, e: print e # you will get a specific message here If the checks still have to occur in multiple places in your code you are of course free to factor them out in a separate function. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: function nested
Gigs_ a écrit : i have this function. def f(start): stack = [] def f1(start): for fname in os.listdir(startDir): path = os.path.join(startDir, fname) if os.path.isfile(path): stack.append(path) else: f1(path) return stack this is returning empty list, why? Because that's what you are returning. Perhaps did you mean to actually *call* f1() after defining it ?-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking parameters prior to object initialisation
Brett_McS a écrit : Fairly new to Python (and loving it!) In C++ (gack!) I got used to creating a helper function with each class to check the class object initialisation parameters prior to creating the object. In Python, this would be --- import example if example.ParametersOK(a, b, c, d): newObj = example.Example(a, b, c, d) else: print Error in parameters --- I presume this would still be considered good practise in Python, I don't think so. or is there some other, preferred, method? If you really have to check, do it in the object's initializer (the __init__ method), and raise an exception if necessary. -- http://mail.python.org/mailman/listinfo/python-list
Hiring Lead Python Programmer for Mozilla-Based Project
We're a US-based start-up building new software with the Mozilla Platform and are at present seeking a lead programmer/architect for our project. At present, we're planning to build a team in India, so we'd need the lead to be on-site for 6 to 12 months. We may, however, end up developing in the US or elsewhere. We're also building websites (ideally in Python) which will work in conjunction with the client application. Our projects are quite challenging and exciting. They're motivated by the general transition to a net-based lifestyle--we need better tools to help organize and improve the functionality of critical web services. They thus have the potential to reach a lot of people, and involve a breadth of fun but difficult technical challenges. We're building a small team of extremely capable developers. We're seeking independently motivated, dedicated and generally brilliant programmers--the sort of programmers who coded a C compiler for fun in college. We offer a competitive salary, intense, challenging and rewarding work, and the potential for spectacular bonuses. If you're seeking a new challenge and would like to build exciting new products, please send us your CV or resume and a letter of interest in technology/programming. Thanks, Alok, MetaStart metastart at gmail.com -- http://mail.python.org/mailman/listinfo/python-list
Re: 0 == False but [] != False?
On Thu, 24 May 2007 06:59:32 +, Tim Roberts wrote: As a general rule, I've found code like if x == False to be a bad idea in ANY language. Surely that should be written as if (x == False) == True? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple omniORBpy example throws exception with error 0x41540002
On May 22, 6:53 pm, Duncan Grisby [EMAIL PROTECTED] wrote: I think ORBit is configured to only listen on its proprietary Unix domain socket protocol by default, not TCP, so omniORB doesn't know how to talk to it. You should either tell ORBit to listen on TCP (Google for how), or use omniORB's naming service, which listens on TCP by default. Yay, after replacing orbit2-nameserver by omniorb4-nameserver everything works fine. Thanks a lot for your comment! -Samuel -- http://mail.python.org/mailman/listinfo/python-list
Re: 0 == False but [] != False?
Steven D'Aprano : On Thu, 24 May 2007 06:59:32 +, Tim Roberts wrote: As a general rule, I've found code like if x == False to be a bad idea in ANY language. Surely that should be written as if (x == False) == True? Why compare to False? if not x : ... It really doesn't matter if x is False or if it evaluates to False. Many things evaluate to False like [], (), 0, , None and a few other things. def tf(thing): ... if thing : print True thing, thing ... elif not thing : print False thing,thing ... else : print No thing ... tf([]) False thing [] tf([1]) True thing [1] a = () tf(a) False thing () a=(0) tf(a) False thing 0 a= (1,2,3) tf(a) True thing (1, 2, 3) tf(abc) True thing abc tf() False thing -- http://mail.python.org/mailman/listinfo/python-list
Changing Unicode object to Tuple Type
Can we have change a unicode string Type object to a Tuple type object.. If so how -- http://mail.python.org/mailman/listinfo/python-list
Changing Unicode object to Tuple Type
Can we have change a unicode string Type object to a Tuple type object.. If so how -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing Unicode object to Tuple Type
[EMAIL PROTECTED] schrieb: Can we have change a unicode string Type object to a Tuple type object.. If so how Why? Are you getting an error that makes you think that's a good idea? Tuples are basically structs, unicode objects are strings. There is no canonical way to convert them. Tell us more about the problem you want to be solved, and we might help you better. diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing Unicode object to Tuple Type
On May 24, 9:45 pm, [EMAIL PROTECTED] wrote: Can we have change a unicode string Type object to a Tuple type object.. If so how x = u'fubar' y = tuple(x) y (u'f', u'u', u'b', u'a', u'r') type(x) type 'unicode' type(y) type 'tuple' But I'm quite sure that's not the question you should be asking :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing Unicode object to Tuple Type
On 24 May 2007 04:45:32 -0700, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Can we have change a unicode string Type object to a Tuple type object.. If so how *Loosely* speaking a tuple is a collection of multiple objects. So what are the objects that you want to put in that tuple ?! Or do you want to store the unicode string as one of the member in a tuple ? In which case you can just do it the obvious way (though i guess thats not the question you asked)! Cheers, Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Call script which accepts com. line par. from another scriptanderror control
Karim Ali wrote: What I still dont know though is how do I handle the fact that the first script is expecting command line parameters. I would like to be able to replace the command line parameters by a variable such that the second script can call: first_script.main(command line). Is this possible? I think it is better to pass a list of arguments # first_script.py def main(args=None): parser = optparse.OptionParser() # add options options, positional_args = parser.parse_args(args) # process if __name__ == __main__: # will read options from the command line # if module is invoked as a standalone script main() # second_script.py import first_script first_script.main([-f, --bar, what, you want]) That way you don't have to deal with escaping spaces etc. Peter -- http://mail.python.org/mailman/listinfo/python-list Thanks Peter. That does the trick! Karim _ New Windows Live Hotmail is here. Upgrade for free and get a better look. www.newhotmail.ca?icid=WLHMENCA150 -- http://mail.python.org/mailman/listinfo/python-list
Re: Web Archtecture using tow layers in Phyton
On 5/23/07, Wagner Garcia Campagner [EMAIL PROTECTED] wrote: Hello, I need to develop an web applications that meet the following requirements: - 2 layers: the first one is the user interface (browser) and the second one is the interaction with the operacional system of the server. - the second layer must be developed using Python. I'd like to know if it is possible to implement this system... making the second layer using python and the first layer using another web technologies like AJAX for example. Yes, It is very much possible and you will find the quite a few of such impementations . Does anybody have any experience in developing python web applications? Maybe send me some links or documentation about it... Search this news-group or web for python web framework and you can choose one based on your specific needs. ( some names that often pop up are: django, cherrypy, webware, pylons etc) The final goal is to make diferent user interfaces (layer 1) that can integrate with the second layer... for example, one web interface and one local interface using python+qt (example)... i don't know if this is possible and how can this be implemented... any help is aprreciated... Read the documentation of the framework ( if any) you choose to work with you may find templating system useful. For standalone app you can look at wxPython, which can communicate to your server at some port. Cheers, -- Amit Khemka -- onyomo.com Home Page: www.cse.iitd.ernet.in/~csd00377 Endless the world's turn, endless the sun's Spinning, Endless the quest; I turn again, back to my own beginning, And here, find rest. -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing Unicode object to Tuple Type
On May 24, 5:11 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] schrieb: Can we have change a unicode string Type object to a Tuple type object.. If so how Why? Are you getting an error that makes you think that's a good idea? Tuples are basically structs, unicode objects are strings. There is no canonical way to convert them. Tell us more about the problem you want to be solved, and we might help you better. diez ** I have to get few strings from an application(strings of different languages..ex: korean,japanese,french etc.,). The data returned by the application was in the format of the xml. Hence I was using pyRXP to get the data. I was not able to get all the strigs in different languages. Now I wanted to use pyRXPU to get all the strings of that application.When Iam using pyRXPU iam getting the following error. Traceback (most recent call last): File D:\LanguageScripts\Screens.py, line 106, in test_1_01_DoSomething TitlenSoftkeyfn() File D:\LanguageScripts\EventLog_Screens.py, line 66, in TitlenSoftkeyfn titleBar = root.TitleBar.currentText File D:\LanguageScripts\XmlWrapper.py, line 35, in __getattr__ tagName, attrs, children, spare = child ValueError: need more than 1 value to unpack Here the child is of the format unicode.. When pyRXP is used it was of the format tuple... I was just trying to find out if there is some way that I make this code work. -- http://mail.python.org/mailman/listinfo/python-list
installing cx_Oracle.
I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? sudo easy_install cx_Oracle did not easy_install cx_Oracle. http://www.python.org/pypi/cx_Oracle/4.3.1 doesn't give me any clue. I got the source from http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-4.3.1.tar.gz?download [EMAIL PROTECTED]:~/a/cx_Oracle-4.3.1$ python setup.py build Traceback (most recent call last): File setup.py, line 36, in ? oracleHome = os.environ[ORACLE_HOME] File /usr/lib/python2.4/UserDict.py, line 17, in __getitem__ def __getitem__(self, key): return self.data[key] KeyError: 'ORACLE_HOME' Now I don't really know whos problem this is. Carl K -- http://mail.python.org/mailman/listinfo/python-list
Re: converting text and spans to an ElementTree
On 2007-05-23, Steven Bethard [EMAIL PROTECTED] wrote: Neil Cerutti wrote: On 2007-05-22, Steven Bethard [EMAIL PROTECTED] wrote: Thanks a lot! This put me on the right track (though the devil's definitely in the details). It's working now:: tree = xmltools.text_and_spans_to_etree('aaa aaa aaaccc cccaaa', [ ... (etree.Element('a'), 0, 21), ... (etree.Element('b'), 11, 11), ... (etree.Element('c'), 11, 18), ... ]) etree.tostring(tree) ' aaa aaab / ccc/caaa/a' tree = xmltools.text_and_spans_to_etree('bbb\naaaccc\ncccaaa', [ ... (etree.Element('a'), 0, 17), ... (etree.Element('b'), 0, 4), ... (etree.Element('c'), 7, 14), ... (etree.Element('b'), 14, 14), ... ]) etree.tostring(tree) 'a\n/baaa\nccc/cb /aaa/a' tree = xmltools.text_and_spans_to_etree('abc', [ ... (etree.Element('a'), 0, 3), ... (etree.Element('b'), 0, 3), ... (etree.Element('c'), 0, 3), ... ]) etree.tostring(tree) 'abcabc/c/b/a' And for the sake of any poor soul who runs into a similar problem, here's the code I wrote using Gabriel's hints above:: When I saw you manually keeping a stack, I called Captain Recursion on my Red-Alert Recursion Phone. (I'm sorry he left out the Element stuff, which he doesn't know or use yet. The Captain's get_tree just returns the string) Heh heh. I actually thought about writing it recursively, but note that you need both recursive and non-recursive parts of this algorithm to do the ElementTree part right: You mean... I left out the hard part? Shucks. I had really hoped it didn't matter. * the recursive (or stack) part assigns children to parents * the non-recursive part assigns text or tail to the previous element (note that's previous in a sequential sense, not a recursive sense) I'm sure I could implement this recursively, passing around annother appropriate argument, but it wasn't obvious to me that the code would be any cleaner. Moreover, it looks like you have experience in writing that sort of code. I'd have never even attempted it without recursion, but that's merely exposing one of my limitations. ;) -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
RE:A few questions
Just wanted to send a quick Thank You! to everyone who helped answer my questions. This list is awesome!! I'm currently reading How to Think Like a Computer Scientist (thanks Basilisk96) and it's got some excellent tutorial info. I still want to take a look at Dive into Python as well as the other books you all mentioned. I'll continue working with wxPython and py2app too... these are some cool apps!! Again, thank you all for taking the time to help me with all this. I really appreciate it! Jay -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Carl K wrote: I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? It is indeed. sudo easy_install cx_Oracle did not easy_install cx_Oracle. http://www.python.org/pypi/cx_Oracle/4.3.1 doesn't give me any clue. I got the source from http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-4.3.1.tar.gz?download [EMAIL PROTECTED]:~/a/cx_Oracle-4.3.1$ python setup.py build Traceback (most recent call last): File setup.py, line 36, in ? oracleHome = os.environ[ORACLE_HOME] File /usr/lib/python2.4/UserDict.py, line 17, in __getitem__ def __getitem__(self, key): return self.data[key] KeyError: 'ORACLE_HOME' You have an oracle client installed, right? If not, go get an Instant Client: http://www.*oracle*.com/technology/software/tech/oci/*instant**client*/index.html Then you need to set an environment variable, ORACLE_HOME, to point to the root of the oracle client installation so that the cx_Oracle installer can find the oracle libraries to build with. Now I don't really know whos problem this is. Carl K -- http://mail.python.org/mailman/listinfo/python-list
configobj - use of
I assume that you know the module configobj. I use it like this: I have a config_file : [sec1] [[subsec1]] a = 1 b = 2 [[subsec2]] a = 3 b = 1 .. ans so on Then in the code I have c = configobj.ConfigObj(path_to_config file) then I go like for instance for s in c['sec1']: print c['sec1'][s]['a'] Just think its awkward that its neccessary to use the c['sec1'] again inside the loop, guess I`d like it to be like print s.a instead Is this the right way to use configobj? -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Carl K schrieb: I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? sudo easy_install cx_Oracle did not easy_install cx_Oracle. http://www.python.org/pypi/cx_Oracle/4.3.1 doesn't give me any clue. I got the source from http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-4.3.1.tar.gz?download [EMAIL PROTECTED]:~/a/cx_Oracle-4.3.1$ python setup.py build Traceback (most recent call last): File setup.py, line 36, in ? oracleHome = os.environ[ORACLE_HOME] File /usr/lib/python2.4/UserDict.py, line 17, in __getitem__ def __getitem__(self, key): return self.data[key] KeyError: 'ORACLE_HOME' yours. because you need the oracle OCI with libs and header files installed + the environment variable ORACLE_HOME pointing to the installation. I suggest you download the appropriat oracle instant client for your system. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Changing Unicode object to Tuple Type
[EMAIL PROTECTED] schrieb: On May 24, 5:11 pm, Diez B. Roggisch [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] schrieb: Can we have change a unicode string Type object to a Tuple type object.. If so how Why? Are you getting an error that makes you think that's a good idea? Tuples are basically structs, unicode objects are strings. There is no canonical way to convert them. Tell us more about the problem you want to be solved, and we might help you better. diez ** I have to get few strings from an application(strings of different languages..ex: korean,japanese,french etc.,). The data returned by the application was in the format of the xml. Hence I was using pyRXP to get the data. I was not able to get all the strigs in different languages. Now I wanted to use pyRXPU to get all the strings of that application.When Iam using pyRXPU iam getting the following error. Traceback (most recent call last): File D:\LanguageScripts\Screens.py, line 106, in test_1_01_DoSomething TitlenSoftkeyfn() File D:\LanguageScripts\EventLog_Screens.py, line 66, in TitlenSoftkeyfn titleBar = root.TitleBar.currentText File D:\LanguageScripts\XmlWrapper.py, line 35, in __getattr__ tagName, attrs, children, spare = child ValueError: need more than 1 value to unpack Here the child is of the format unicode.. When pyRXP is used it was of the format tuple... I was just trying to find out if there is some way that I make this code work. I don't know pyRXP and pyRXPU, and especially not how you use them. Who's responsible for writing that XmlWrapper.py? He or she obviously expected a tuple returned that was basically a DOM-tree (tag, attrs, childs and something called spare) But changing to pyRXPU seems to break the protocol here. But I can't judge that without seeing more code. diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Lists vs tuples (newbie)
Hendrik van Rooyen [EMAIL PROTECTED] wrote: Duncan Booth [EMAIL PROTECTED] wrote: Hendrik van Rooyen [EMAIL PROTECTED] wrote: Aside from the hashing issue, there is nothing that a tuple can do that can't be done as well or better by a list. There are a few other cases where you have to use a tuple, for example in a try..except statement the exception specification must be an exception to be caught or a tuple of exception specifications: a list won't work to catch multiple exceptions. Esoteric - But I stand corrected... any other must use a tuple's ? Seems they all fall into a class that can be described as required by the language - I was thinking data. There used to be several other situations where a tuple was required but I can't think of any others which still exist. So far as data is concerned, the same reason that exceptions require tuples could arise in your own code: If you look at the definition of the except clause expression (simplified to remove the deprecated string option): An object is compatible with an exception if it is the class or a base class of the exception object or a tuple containing an item compatible with the exception you'll see that it is impossible for this structure to contain any loops. An equivalent structure using lists instead of tuples could contain loops and any code which searched it for a match would have to account for this somehow. So, anywhere you want a tree structure with a guarantee that it does not contain any loops it may be appropriate to use tuples to represent the structure. -- http://mail.python.org/mailman/listinfo/python-list
Re: A few questions
[EMAIL PROTECTED] wrote: Just wanted to send a quick Thank You! to everyone who helped answer my questions. This list is awesome!! I'm finding the same, this list is amazing. There is a more welcome feeling than the C or C++ list I have seen. I'm currently reading How to Think Like a Computer Scientist (thanks Basilisk96) Me too, it is an amazing book and I am loving Python much better than C. I would just like to find some answers to the exercises to make sure I'm doing them correctly. I still want to take a look at Dive into Python as well as the other books you all mentioned. I put Dive into Python on my palm. Is it a good 2nd book to go through? -- Your friend, Scott Sent to you from a Linux computer using Kubuntu Version 7.04 (Feisty Fawn) -- http://mail.python.org/mailman/listinfo/python-list
Re: (Modular-)Application Framework / Rich-Client-Platform in Python
Maybe I'm missing the point but the mozilla platform doesn't meet you're needs? I know it's not a pure python solution but there's work in progress to use python as a scripting language instead of javascript to develop the components. I did not made anything on the python + XUL side but tested 2 years ago in javascript and it was neat. The book Creating Applicatin with Mozilla was very helpfull (BTW, if I'm not wrong thunderbird and firefox are both build using the mozilla platform/XPCOM/XUL) you can find the python reference in mozilla here: http://developer.mozilla.org/en/docs/Python and the book on mozilla platform: http://books.mozdev.org/html cheers Jorge -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Bill Scherer wrote: Carl K wrote: I am trying to use this: http://python.net/crew/atuining/cx_Oracle/html/cx_Oracle.html it is a real module, right? It is indeed. sudo easy_install cx_Oracle did not easy_install cx_Oracle. http://www.python.org/pypi/cx_Oracle/4.3.1 doesn't give me any clue. I got the source from http://prdownloads.sourceforge.net/cx-oracle/cx_Oracle-4.3.1.tar.gz?download [EMAIL PROTECTED]:~/a/cx_Oracle-4.3.1$ python setup.py build Traceback (most recent call last): File setup.py, line 36, in ? oracleHome = os.environ[ORACLE_HOME] File /usr/lib/python2.4/UserDict.py, line 17, in __getitem__ def __getitem__(self, key): return self.data[key] KeyError: 'ORACLE_HOME' You have an oracle client installed, right? If not, go get an Instant Client: http://www.*oracle*.com/technology/software/tech/oci/*instant**client*/index.html muh. Sorry for the mangled url. try this one instead: http://www.oracle.com/technology/software/tech/oci/instantclient/index.html Then you need to set an environment variable, ORACLE_HOME, to point to the root of the oracle client installation so that the cx_Oracle installer can find the oracle libraries to build with. Now I don't really know whos problem this is. Carl K -- http://mail.python.org/mailman/listinfo/python-list
problems to write a wav file
Hello, I have a small problem for writing a .wav file. I can't find in which format I have to pass my data in the writeframes function of the wave module. here's my code, I am just trying to open a wav file, extracting the data from it, and writing it in another wav file. The problem is that the sound I get in the second wav file isn't the same as from the firs file (in fact it is horrible). import wave, audioop, numpy from numpy.fft import * from math import * signal = wave.open('C:\demo.wav', 'rb' ) Nframes = float(signal.getnframes()) width = signal.getsampwidth() frameRate = signal.getframerate() frame = signal.readframes(1) power =[] while len(frame): power.append(audioop.rms( frame, width )) frame = signal.readframes(1) new_signal = wave.open('C:\demo2.wav', 'wb') new_signal.setsampwidth(width) new_signal.setframerate(frameRate) new_signal.setnchannels(signal.getnchannels()) for j in range(len(power)): data = hex(power[j])--- I guess that my problem is located at this line new_signal.writeframes(data) new_signal.close() thanks a lot, -- Gautier Krings [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Getting closer, thanks Bill and Diez. $ export ORACLE_HOME $ ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client $ python setup.py build $ sudo python setup.py install $ python -c import cx_Oracle Traceback (most recent call last): File string, line 1, in ? ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory guessing I need to add /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib/ to some path? btw - anyone know of a .deb that will install this? Carl K -- http://mail.python.org/mailman/listinfo/python-list
Re: 0 == False but [] != False?
On 2007-05-24, Rex Turnbull [EMAIL PROTECTED] wrote: Steven D'Aprano : On Thu, 24 May 2007 06:59:32 +, Tim Roberts wrote: As a general rule, I've found code like if x == False to be a bad idea in ANY language. Surely that should be written as if (x == False) == True? Why compare to False? That's a joke... I say, that's a joke, son! He was being sarcastic. -- Grant Edwards grante Yow! The FALAFEL SANDWICH at lands on my HEAD and I visi.combecome a VEGETARIAN ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
Peter Decker wrote: On 5/21/07, Paul McNett [EMAIL PROTECTED] wrote: Shameless plug: consider using Dabo on top of wxPython - we feel it makes wxPython even easier and more pythonic, but admittedly there's a bit of a learning curve there too. Even though Dabo is a full application framework originally meant for desktop database applications, it is modular and you can choose to only use the UI bits... http://dabodev.com I second this. I used (and struggled!) with wxPython for over a year. The results were great, but I hated coding it. I switched to the Dabo UI wrapper, and stuff that used to take me a day to create is now done in an hour or two. Hello, I'd like to ask the Python community about this, because it seems to me that there is a real need that is not being met very effectively. Almost everyone agrees that wxPython looks great and is very powerful, and for full-fledged cross-platform applications is nearly the best, if not *the* best, choice as far as *function* and *look* are concerned. The next sentence out of Python programmers seems to be ...but wx is written in C++ and definitely shows, even in the Python port. It's just not very pythonic. Then there is Dabo, which I personally have had problems with. I am looking for a pythonic, professional looking GUI framework. I first tried dabo with python 2.4, and had to install sqlite, which seemed a bit odd for trying to just get a GUI framework...I understand why, but when you're looking for one thing, having it tied to a completely different thing feels a little strange. I never got it working in Python2.5, either on Linux or OS X, and the problem is most definitely mine and I didn't have the patience to debug it. I am really not trying to diss dabo here, because there enough people who swear by it, that it must be doing many things right. My problem with Dabo is not what it is, it is what I am looking for...a pythonic GUI framework. Coming from Unix, I generally feel that a program should try to do one thing, and one thing well. To mix really different functionality seems to me to be a bad idea. If you can use the GUI parts separately, why not package it separately? One might find a lot of users who only what that. Finally, consider wax (http://zephyrfalcon.org/labs/wax.html). In my view, this is *exactly* what python needs, and its not being maintained anymore as far as I can tell. What I like about it is: 1) it is small...I can include the entire wax distribution in my app with only a 780k footprint. 2) it is a very thin layer on wx, so when something doesn't quite work, I can immediately fall back onto wx, mixing and matching wax and wx objects. it's just that the wax objects have more pythonic calling and use properties Is there a reason that the port of wxPython doesn't include wax, or something similar? It would seem pretty straightforward, when porting the wx to Python, to simply include such a wrapper. I wish I were more clever, and had more time, to take over the maintenance of wax because I think it is the most straightforward, practical, and pythonic solution out there. Do others think like me here? thanks, Brian Blais -- - [EMAIL PROTECTED] http://web.bryant.edu/~bblais -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Carl K wrote: Getting closer, thanks Bill and Diez. $ export ORACLE_HOME $ ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client $ python setup.py build $ sudo python setup.py install $ python -c import cx_Oracle Traceback (most recent call last): File string, line 1, in ? ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory guessing I need to add /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib/ to some path? You can `export LD_LIBRARY_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib` or (assuming a recent RedHat linux (or similar) now), put that path in a file, /etc/ld.so.conf.d/oracle.conf and run /sbin/ldconfig You'll find the latter operation to be persistent, and the former is not. btw - anyone know of a .deb that will install this? Carl K -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on Vista installation issues
Okay, I've figured it out. It's easy (but stupid)... right click the extension installer program, and choose Run as Administrator. Just posting this so the next Google search for an answer might actually find one. -- --- Chris Gonnerman [EMAIL PROTECTED] Owner, New Century Computers Phone 660-213-3822 Fax 660-213-3339 -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Bill Scherer wrote: Carl K wrote: Getting closer, thanks Bill and Diez. $ export ORACLE_HOME $ ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client $ python setup.py build $ sudo python setup.py install $ python -c import cx_Oracle Traceback (most recent call last): File string, line 1, in ? ImportError: libclntsh.so.10.1: cannot open shared object file: No such file or directory guessing I need to add /usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib/ to some path? You can `export LD_LIBRARY_PATH=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client/lib` or (assuming a recent RedHat linux (or similar) now), put that path in a file, /etc/ld.so.conf.d/oracle.conf and run /sbin/ldconfig You'll find the latter operation to be persistent, and the former is not. btw - anyone know of a .deb that will install this? Carl K bingo. [EMAIL PROTECTED]:~/a/cx_Oracle-4.3.1$ python Python 2.4.4c1 (#2, Oct 11 2006, 21:51:02) [GCC 4.1.2 20060928 (prerelease) (Ubuntu 4.1.1-13ubuntu5)] on linux2 Type help, copyright, credits or license for more information. import cx_Oracle connection = cx_Oracle.connect('testuserA', 'pw', 'nf55') cursor = connection.cursor() cursor.execute(select * from tbl1) [cx_Oracle.NUMBER with value None, cx_Oracle.FIXED_CHAR with value None, cx_Oracle.NUMBER with value None] rows=cursor.fetchall() rows [(1, 'a ', 1.01), (2, 'a ', 1.02), (3, 'a ', 1.03)] Thanks - now I can get to the real problem: client side join/order by :) But I have already done it in MySql, so this should be the easy part... Thanks again. Carl K -- http://mail.python.org/mailman/listinfo/python-list
Bootstrapping
I need some help with adding bootstrap code to the core of python, the idea is to leave a super base core inside a zip file (python25.zip works right out of the box) and leave the rest in separate zip modules. Making it more friendly with pendrives and more practical as a standalone runtime (ie, without install) and fully modular. The thing is that i need to modify the base importer to add this special site-packages . Any hints? thanks in advance (and a lot!) Martin Rene Vilugron Patagonia Argentina -- http://mail.python.org/mailman/listinfo/python-list
Invalid thread state for this thread
I know this has been seen before but it is not making too much sense (after reading many posts). It all appears to work fine but then dies after about 40 invocations. My app has Python embedded, it is embedded as part of a dll which initializes python and finalizes on load and unload (see below). When a script needs to be run, I create a new thread, let the script complete and close the thread. The thread contains the following type arrangement: PythonThread() { hScriptFile = OpenScriptFile(m_szActiveScript); PyEval_AcquireLock(); pInterpreter = Py_NewInterpreter(); Py_SetProgramName(szModuleFileName); PyRun_SimpleFile(hScriptFile,m_szActiveScript); PyErr_Clear(); Py_EndInterpreter(pInterpreter); PyEval_ReleaseLock(); } This appears to work fine accept that after around 30-40 invocations I always get the Invalid thread state for this thread. ie the app and dll stay loaded and I click my run button manually about 40 times. In this test it is a simple hello world type script. The size of the script does not appear to matter. The dll is coded something like this: DllLoad() { Py_Initialize(); PyEval_InitThreads(); m_mainThreadState = PyThreadState_Get(); PyEval_ReleaseLock(); } DllUnload() (not called as part of this test) { PyEval_AcquireLock(); PyThreadState_Swap(m_mainThreadState); Py_Finalize(); } The app has been designed to allow a second interpreter to run independently (thus the need for multiple thread support) and this also appears to work fine, but for this test only this one thread was used. I have a compiled version of 2.4.2. Any ideas would be appreciated. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On 2007-05-24, Brian Blais [EMAIL PROTECTED] wrote: I'd like to ask the Python community about this, because it seems to me that there is a real need that is not being met very effectively. [...] ...but wx is written in C++ and definitely shows, even in the Python port. It's just not very pythonic. Then there is Dabo, which I personally have had problems with. [...] I haven't tried Dabo, so I can't comment. Finally, consider wax (http://zephyrfalcon.org/labs/wax.html). In my view, this is *exactly* what python needs, and its not being maintained anymore as far as I can tell. What I like about it is: 1) it is small...I can include the entire wax distribution in my app with only a 780k footprint. 2) it is a very thin layer on wx, so when something doesn't quite work, I can immediately fall back onto wx, mixing and matching wax and wx objects. it's just that the wax objects have more pythonic calling and use properties I did try wax, and I liked it. It seemed much more Pythonic than bare wxPython, and resulted in cleaner, easier-to-read code. When I tried it, it was still early in its development, and there were still parts of it that needed to be fleshed out (a lot of stuff was still unwrapped). I contributed a little bit of code (wrapping one or two more things), but I didn't have enough time at that point to wrap and debug all the things I needed, so I switched back to plain wxPython (I had a mixture of wax and wx for a little while, but I that annoyed me too much). Is there a reason that the port of wxPython doesn't include wax, or something similar? It would seem pretty straightforward, when porting the wx to Python, to simply include such a wrapper. I wish I were more clever, and had more time, to take over the maintenance of wax because I think it is the most straightforward, practical, and pythonic solution out there. Do others think like me here? Yes. I thought wax was a good idea, and there was a a good start on an implementation. -- Grant Edwards grante Yow! My nose feels like a at bad Ronald Reagan movie ... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: configobj - use of
Bruce wrote: I assume that you know the module configobj. I use it like this: I have a config_file : [sec1] [[subsec1]] a = 1 b = 2 [[subsec2]] a = 3 b = 1 .. ans so on Then in the code I have c = configobj.ConfigObj(path_to_config file) then I go like for instance for s in c['sec1']: print c['sec1'][s]['a'] Just think its awkward that its neccessary to use the c['sec1'] again inside the loop, guess I`d like it to be like print s.a instead Is this the right way to use configobj? So bind a variable to the section, and write csec = c['sec1'] for s in csec: print csec[s]['a'] I don't think configobj support attribute-based access to the section values, in which case print csec[s].a won't work. regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden -- Asciimercial - Get on the web: Blog, lens and tag your way to fame!! holdenweb.blogspot.comsquidoo.com/pythonology tagged items: del.icio.us/steve.holden/python All these services currently offer free registration! -- Thank You for Reading -- http://mail.python.org/mailman/listinfo/python-list
What is an instance and what isn't?
I suppose I was lulled into complacency by how Python makes so many things look like classes, but I'm starting to realize that they're not, are they? I'm writing a C program which handles Python objects in different ways based on their type. I do a PyInstance_Check(PyObj) to determine if the PyObj is an instance, but it is returning 0 on a lot of stuff that I thought would be an instance. So I did the following simple test on three things that look like instances: Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. class a: pass ... type(a()) type 'instance' type(Exception()) type 'exceptions.Exception' class b(dict): pass ... type(b()) class '__main__.b' I was relieved that a() returns an instance, but I was surprised that Exceptions aren't really instances at all. And what's the deal with derving a class from a standard type like a dictionary? I thought for sure, that would be an instance, but this shows it is a class?!? Can anyone explain the last one and/or give me a simple test I can do in C to determine whether a Python object is instance-like? Many thanks, Gre7g -- http://mail.python.org/mailman/listinfo/python-list
Re: Bootstrapping
On May 24, 5:53 pm, Mauler [EMAIL PROTECTED] wrote: I need some help with adding bootstrap code to the core of python, the idea is to leave a super base core inside a zip file (python25.zip works right out of the box) and leave the rest in separate zip modules. Making it more friendly with pendrives and more practical as a standalone runtime (ie, without install) and fully modular. The thing is that i need to modify the base importer to add this special site-packages . Any hints? thanks in advance (and a lot!) Martin Rene Vilugron Patagonia Argentina http://pyinstaller.python-hosting.com/ ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and GUI
On May 24, 2007, at 10:22 AM, Brian Blais wrote: Then there is Dabo, which I personally have had problems with. I am looking for a pythonic, professional looking GUI framework. I first tried dabo with python 2.4, and had to install sqlite, which seemed a bit odd for trying to just get a GUI framework...I understand why, but when you're looking for one thing, having it tied to a completely different thing feels a little strange. FWIW, we made that decision only after Python itself committed to including SQLite as part of the standard distribution. While there may have been some problems during the transition, such as you apparently had, it made for a much better product in the long run. I never got it working in Python2.5, either on Linux or OS X, and the problem is most definitely mine and I didn't have the patience to debug it. I am really not trying to diss dabo here, because there enough people who swear by it, that it must be doing many things right. I checked the archives, and didn't find any messages from you asking for help. We know that the documentation is far from complete, and the installation process can be problematic, but one thing we pride ourselves on is quick response to help requests, and then fixing whatever it was that caused the initial problem. My problem with Dabo is not what it is, it is what I am looking for...a pythonic GUI framework. Coming from Unix, I generally feel that a program should try to do one thing, and one thing well. To mix really different functionality seems to me to be a bad idea. If you can use the GUI parts separately, why not package it separately? One might find a lot of users who only what that. We've thought about doing exactly that, but to be honest, it would take a large investment of time without a corresponding increase in value. Right now all you have to do is install Dabo, and then just use the dabo.ui classes. You never need to touch the database or business object layers if you don't want to. Also, I don't feel that we are mixing different functionality. Rather, we are creating an integrated environment for those wishing to create rich desktop apps. Nearly all such apps require displaying and persisting information, and that's what Dabo is designed to do. If you don't need persistent information, the display stuff works just fine. I'd encourage anyone who is curious about what dabo.ui offers to view the part of my recent PyCon presentation that discusses exactly this topic. Take a look at http://dabodev.com/pycon2007?3 to see an example of simpler and more Pythonic Dabo code is compared to what you would have to write in either raw wxPython or even Wax. -- Ed Leafe -- http://leafe.com -- http://dabodev.com -- http://mail.python.org/mailman/listinfo/python-list
How can I time a method of a class in python using Timeit
Hi, I am using timeit to time a global function like this t = timeit.Timer(timeTest(),from __main__ import timeTest) result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread): def aFunction(self): # do something def run(self): # how can I time how long does aFunction() take here? aFunction(); Thank you. -- http://mail.python.org/mailman/listinfo/python-list
of destructors, open files and garbage collection
Hi, Python 2.4, Kubuntu 6.06. I'm no professional programmer (I am a ph.d. student in biophysics) but I have a fair knowledge of Python. I have a for loop that looks like the following : for item in long_list: foo(item) def foo(item): item.create_blah() #--this creates item.blah; by doing that it opens a file and leaves it open until blah.__del__() is called Now, what I thought is that if I call del(item) it will delete item and also all objects created inside item. So I thought that item.blah.__del__() would have been called and files closed. Question 1: This is not the case. I have to call del(item.blah), otherwise files are kept open and the for loops end with a Too many open files error. Why isn't __del__() called on objects belonging to a parent object? Is it OK? So I thought: oh, ok, let's put del(self.blah) in item.__del__() Question 2: This doesn't work either. Why? Thanks a lot, M. -- http://mail.python.org/mailman/listinfo/python-list
Reading (and writing?) audio file tags
I'd like to write some scripts to analyze and manipulate my music files. The files themselves are in MP3 and FLAC format (mostly MP3, but FLAC where I ripped original CDs and wanted a lossless format). I've no idea what form of tags are used in the files (ID3v1, ID3v2, OGG, APE, ...) I just used whatever the program that set them up used. I'm completely confused by the various tag formats that exist - there seems to be little standardisation, and quite a few compatibility pitfalls. For example, I have files with tags using accented characters - I suspect that this causes some tools to switch format (because I've seen what looked like corrupt data at times, which turned out to be the program displaying the wrong format of tag). I've seen various Python libraries that talk about ID3 tag reading - but I'm not clear if they read other tag formats (many applications which call themselves ID3 readers actually handle multiple formats, but I don't know if that's true for (Python) libraries. Also, there seem to be few libraries that will *write* tags. Is there a good music file tag handling library for Python that's worth looking at? I use Windows, so it would have to be for that platform, and although I have a compiler, I don't really want to spend a lot of time collecting and porting/building support libraries, so I'd be looking for a binary distribution. In the absence of something suitable, I'll probably go back to dumping the tags via a generic MP3 tag reader program, then manipulate them as a text file, then try to do some sort of bulk reload. Thanks, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: Shared Memory Space - Accross Apps Network
In article [EMAIL PROTECTED], Tim Golden [EMAIL PROTECTED] wrote: . . . PyLinda - http://www-users.cs.york.ac.uk/~aw/pylinda/ This implements the tuplespace paradigm. It's great fun to use, but as far as I know this implementation was a PhD project and lacks the robustness and wide use of other things. That said, it works perfectly well within its remit and might be a good match for what you're trying to do. . . . Amen; part of Linda's charm is that it's pleasingly effective even with a simple, unmaintained implementation URL: http://www.unixreview.com/documents/s=10125/ur0704l/ . -- http://mail.python.org/mailman/listinfo/python-list
Re: of destructors, open files and garbage collection
On 24 May, 16:40, massimo s. [EMAIL PROTECTED] wrote: Now, what I thought is that if I call del(item) it will delete item and also all objects created inside item. Sort of, but it's a bit more subtle. You'll stop the name item from referring to your item - if nothing else refers to your item, it will be garbage collected (and __del__ will get called). But you can have other references, and in this case, __del__ is not called until *they* are released as well. Here's an example: class C: ... def __del__(self): ... print del called ... c = C() # Now we have one reference to the object, in c. So delete it: ... del c del called # Just as we want. ... # Let's create a new C, but store a second reference to it in a. ... c = C() a = c # Now we can delete c, but a still refers to the object, so it isn't collected ... del c # But if we delete a, it is! ... del a del called OK. Now in your case, it's a bit more complex. You delete item. Suppose that causes the item to be garbage collected (there are no other references). Then, the item will be collected. This removes the attribute item.blah, which refers to the blah object. So the blah object is collected - *as long as no other references exist to that item*. Here's another example: class B: ... def __init__(self): ... self.c = C() ... def __del__(self): ... print B's delete called ... b = B() del b B's delete called del called # But if we have a second reference to b.c, that causes the object to stay alive: ... b = B() a = b.c del b B's delete called del a del called See? Even though b was collected, its c attribute is still accessible under the name 'a', so it's kept alive. Question 1: This is not the case. I have to call del(item.blah), otherwise files are kept open and the for loops end with a Too many open files error. Why isn't __del__() called on objects belonging to a parent object? Is it OK? Did the above help to clarify? So I thought: oh, ok, let's put del(self.blah) in item.__del__() Question 2: This doesn't work either. Why? It's not needed - it's not the item.blah reference that's keeping the blah object alive, it's another one. You *can* fix this by tracking down all the references and explicitly deleting them one by one, but that's not really the best answer. You're micromanaging stuff the garbage collector is supposed to handle for you. Ultimately, you've got a design problem, as you're holding onto stuff you no longer need. Whether you use del, or add an explicit blah.close() method to close the filehandle, you've got to understand when you're finished with a filehandle - if you know that, you can close it at that point. Here's a final example that may help: a = [] for i in range(10): ... a.append(C()) ... # Lots of work, none of which uses a ... a = [] # or del a del called del called del called del called del called del called del called del called del called del called See how you finished with all of the C objects right after the for loop, but they didn't get deleted until later? I suspect that's what's happening to you. If you cleared out the list (my a = [] statement) as soon as you're done with it, you get the resources back that much sooner. Hope this helps, Paul. -- http://mail.python.org/mailman/listinfo/python-list
Module imports fine from interactive, not from script
Yes, I've read this: http://mail.python.org/pipermail/python-list/2006-August/395943.html That's not my problem. I installed PlanetPlanet http://www.planetplanet.org/ via the package's setup.py install command (as root). planet.py will not run, however, giving me this error: Traceback (most recent call last): File /usr/local/bin/planet.py, line 167, in ? main() File /usr/local/bin/planet.py, line 124, in main planet.logging.basicConfig() AttributeError: 'module' object has no attribute 'logging' But, from interactive session: [EMAIL PROTECTED]:~/www$ ls -l # to show that the modules are not in the current dir total 20 -rw-r--r-- 1 jkugler jkugler 2247 2007-05-22 15:26 atom.xml.tmpl -rw-r--r-- 1 jkugler jkugler 2089 2007-05-22 15:25 index.html.tmpl -rw-r--r-- 1 jkugler jkugler 564 2007-05-22 15:43 planet.ini -rw-r--r-- 1 jkugler jkugler 1128 2007-05-22 15:26 rss10.xml.tmpl -rw-r--r-- 1 jkugler jkugler 838 2007-05-22 15:26 rss20.xml.tmpl [EMAIL PROTECTED]:~/www$ python Python 2.4.3 (#2, Oct 6 2006, 07:52:30) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type help, copyright, credits or license for more information. import planet planet.logging module 'planet.logging' from '/usr/local/lib/python2.4/site-packages/planet/logging/__init__.py' planet.logging.basicConfig() The contents of /usr/local/lib/python2.4/site-packages/planet [EMAIL PROTECTED]:~/www$ ls -la /usr/local/lib/python2.4/site-packages/planet/ total 270 drwxr-sr-x 4 root staff 1024 2007-05-22 16:59 . drwxrwsr-x 4 root staff 1024 2007-05-22 15:18 .. -rw-r--r-- 1 root staff 4315 2006-07-26 15:53 atomstyler.py -rw-r--r-- 1 root staff 8887 2006-07-26 15:53 cache.py -rw-r--r-- 1 root staff 126446 2006-07-26 15:53 feedparser.py -rw-r--r-- 1 root staff 58705 2006-07-26 15:53 htmltmpl.py -rw-r--r-- 1 root staff 38145 2006-07-26 15:53 __init__.py drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 logging -rw-r--r-- 1 root staff 13904 2006-07-26 15:53 sanitize.py drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 tests -rw-r--r-- 1 root staff 12681 2006-07-26 15:53 timeoutsocket.py planet.py is simply executing: import planet . . . # Activate logging planet.logging.basicConfig() I've checked permissions, I've checked import statements, everything I know to check. Is there something terribly simple I'm missing? Thanks! j -- Joshua Kugler Lead System Admin -- Senior Programmer http://www.eeinternet.com PGP Key: http://pgp.mit.edu/ ID 0xDB26D7CE -- Posted via a free Usenet account from http://www.teranews.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading (and writing?) audio file tags
quoth the Paul Moore: I'd like to write some scripts to analyze and manipulate my music files. The files themselves are in MP3 and FLAC format (mostly MP3, but FLAC where I ripped original CDs and wanted a lossless format). I've no idea what form of tags are used in the files (ID3v1, ID3v2, OGG, APE, ...) Flac files use Vorbis comments, the same that Ogg Vorbis files use. As for MP3, they use ID3v2 or ID3v1, or both. Anyway, what you want is Mutagen. It handles both Flac and Mp3 tags, as well as many others: http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen I just used whatever the program that set them up used. I'm completely confused by the various tag formats that exist - there seems to be little standardisation, and quite a few compatibility pitfalls. For example, I have files with tags using accented characters - I suspect that this causes some tools to switch format (because I've seen what looked like corrupt data at times, which turned out to be the program displaying the wrong format of tag). I've seen various Python libraries that talk about ID3 tag reading - but I'm not clear if they read other tag formats (many applications which call themselves ID3 readers actually handle multiple formats, but I don't know if that's true for (Python) libraries. Also, there seem to be few libraries that will *write* tags. ID3 = MP3 only. A lot of people call _all_ tags 'id3' tags to save having to say 'Flac tags, and Vorbis tags, and Ape tags' etcthese people are the source of your confusion. Is there a good music file tag handling library for Python that's worth looking at? I use Windows, so it would have to be for that platform, and although I have a compiler, I don't really want to spend a lot of time collecting and porting/building support libraries, so I'd be looking for a binary distribution. From the read me: Mutagen works on Python 2.3+ and has no dependencies outside the CPython standard library so it should work on Windows I think. It is just pure Python so there you go... In the absence of something suitable, I'll probably go back to dumping the tags via a generic MP3 tag reader program, then manipulate them as a text file, then try to do some sort of bulk reload. Thanks, Paul. -d -- darren kirby :: Part of the problem since 1976 :: http://badcomputer.org ...the number of UNIX installations has grown to 10, with more expected... - Dennis Ritchie and Ken Thompson, June 1972 -- http://mail.python.org/mailman/listinfo/python-list
Re: of destructors, open files and garbage collection
In [EMAIL PROTECTED], massimo s. wrote: I have a for loop that looks like the following : for item in long_list: foo(item) def foo(item): item.create_blah() #--this creates item.blah; by doing that it opens a file and leaves it open until blah.__del__() is called Now, what I thought is that if I call del(item) it will delete item and also all objects created inside item. It will delete the *name* `item`. It does nothing to the object that was bound to that name. If the name was the only reference to that object, it may be garbage collected sooner or later. Read the documentation for the `__del__()` method for more details and why implementing such a method increases the chance that the object *won't* be garbage collected! Relying on the `__del__()` method isn't a good idea because there are no really hard guaranties by the language if and when it will be called. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: Module imports fine from interactive, not from script
On 23 May, 02:20, Joshua J. Kugler [EMAIL PROTECTED] wrote: Yes, I've read this:http://mail.python.org/pipermail/python-list/2006-August/395943.html That's not my problem. I installed PlanetPlanet http://www.planetplanet.org/ via the package's setup.py install command (as root). planet.py will not run, however, giving me this error: Traceback (most recent call last): File /usr/local/bin/planet.py, line 167, in ? main() File /usr/local/bin/planet.py, line 124, in main planet.logging.basicConfig() AttributeError: 'module' object has no attribute 'logging' Your problem is that your script is called planet.py, the same as the module you're trying to import. So from the script, import planet finds the script itself (the script's directory is always added to sys.path), and importing it as planet rather than importing the planet module from site-packages. The simplest fix is to not call the driver script planet.py. It's not exactly terribly simple, but it is quite a common mistake (I've certainly made it more than once...) Paul. -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Dennis Lee Bieber wrote: On Thu, 24 May 2007 09:07:07 -0500, Carl K [EMAIL PROTECTED] declaimed the following in comp.lang.python: Getting closer, thanks Bill and Diez. $ export ORACLE_HOME $ ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client Don't those lines need to be reversed? Set the variable in the current shell, and /then/ export it? Modern shells actually allow the single statement export ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden -- Asciimercial - Get on the web: Blog, lens and tag your way to fame!! holdenweb.blogspot.comsquidoo.com/pythonology tagged items: del.icio.us/steve.holden/python All these services currently offer free registration! -- Thank You for Reading -- http://mail.python.org/mailman/listinfo/python-list
Re: Module imports fine from interactive, not from script
Joshua J. Kugler wrote: Yes, I've read this: http://mail.python.org/pipermail/python-list/2006-August/395943.html That's not my problem. I installed PlanetPlanet http://www.planetplanet.org/ via the package's setup.py install command (as root). planet.py will not run, however, giving me this error: Traceback (most recent call last): File /usr/local/bin/planet.py, line 167, in ? main() File /usr/local/bin/planet.py, line 124, in main planet.logging.basicConfig() AttributeError: 'module' object has no attribute 'logging' But, from interactive session: [EMAIL PROTECTED]:~/www$ ls -l # to show that the modules are not in the current dir total 20 -rw-r--r-- 1 jkugler jkugler 2247 2007-05-22 15:26 atom.xml.tmpl -rw-r--r-- 1 jkugler jkugler 2089 2007-05-22 15:25 index.html.tmpl -rw-r--r-- 1 jkugler jkugler 564 2007-05-22 15:43 planet.ini -rw-r--r-- 1 jkugler jkugler 1128 2007-05-22 15:26 rss10.xml.tmpl -rw-r--r-- 1 jkugler jkugler 838 2007-05-22 15:26 rss20.xml.tmpl [EMAIL PROTECTED]:~/www$ python Python 2.4.3 (#2, Oct 6 2006, 07:52:30) [GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2 Type help, copyright, credits or license for more information. import planet planet.logging module 'planet.logging' from '/usr/local/lib/python2.4/site-packages/planet/logging/__init__.py' planet.logging.basicConfig() The contents of /usr/local/lib/python2.4/site-packages/planet [EMAIL PROTECTED]:~/www$ ls -la /usr/local/lib/python2.4/site-packages/planet/ total 270 drwxr-sr-x 4 root staff 1024 2007-05-22 16:59 . drwxrwsr-x 4 root staff 1024 2007-05-22 15:18 .. -rw-r--r-- 1 root staff 4315 2006-07-26 15:53 atomstyler.py -rw-r--r-- 1 root staff 8887 2006-07-26 15:53 cache.py -rw-r--r-- 1 root staff 126446 2006-07-26 15:53 feedparser.py -rw-r--r-- 1 root staff 58705 2006-07-26 15:53 htmltmpl.py -rw-r--r-- 1 root staff 38145 2006-07-26 15:53 __init__.py drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 logging -rw-r--r-- 1 root staff 13904 2006-07-26 15:53 sanitize.py drwxr-xr-x 2 root staff 1024 2007-05-22 16:59 tests -rw-r--r-- 1 root staff 12681 2006-07-26 15:53 timeoutsocket.py planet.py is simply executing: import planet . . . # Activate logging planet.logging.basicConfig() I've checked permissions, I've checked import statements, everything I know to check. Is there something terribly simple I'm missing? Thanks! j The directory containing the script you are executing is also added to sys.path. Since you are executing a script called planet ... regards Steve -- Steve Holden+1 571 484 6266 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://del.icio.us/steve.holden -- Asciimercial - Get on the web: Blog, lens and tag your way to fame!! holdenweb.blogspot.comsquidoo.com/pythonology tagged items: del.icio.us/steve.holden/python All these services currently offer free registration! -- Thank You for Reading -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I time a method of a class in python using Timeit
On May 24, 8:36 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am using timeit to time a global function like this t = timeit.Timer(timeTest(),from __main__ import timeTest) result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread): def aFunction(self): # do something def run(self): # how can I time how long does aFunction() take here? aFunction(); Thank you. Try this: def run(self): import time t1 = time.clock() aFunction(); t2 = time.clock() print aFunction took %d seconds % int(t2 - t1 + 1) (Code is not tested as I'm not at my PC right now). The int() is to round it off to an integer, and the +1 is to give a more accurate result - may not work in all cases, experiment, and check for a ceil/floor type function in Python. Vasudev Ram Dancing Bison Enterprises www.dancingbison.com -- http://mail.python.org/mailman/listinfo/python-list
need advice on building core code for python and PHP
All, I'm currently working with a small development company on a PHP application they already have. There are several processing tasks that could be scripted in Python and run in the background to modify a database, instead of the way they have it now, which waits for a webpage to return from processing. There is also the possibility of building client gui applications that work with the database as well, so I'm looking for a way I could create a code base that enables us to use the same functions and objects over and over again while building interfaces in Python, or PHP, or whatever. Is there a way I could code the base (core) code in Python and have PHP call it? I've really liked using SQLAlchemy and there are other great things like Pylons I could integrate for various tasks, but I first have to move some functionality out of PHP and into something more universal. What would you recommend? Any ideas are appreciated. Brian -- http://mail.python.org/mailman/listinfo/python-list
Re: Reading (and writing?) audio file tags
On 24 May, 17:22, darren kirby [EMAIL PROTECTED] wrote: quoth the Paul Moore: I'd like to write some scripts to analyze and manipulate my music files. The files themselves are in MP3 and FLAC format (mostly MP3, but FLAC where I ripped original CDs and wanted a lossless format). I've no idea what form of tags are used in the files (ID3v1, ID3v2, OGG, APE, ...) Flac files use Vorbis comments, the same that Ogg Vorbis files use. As for MP3, they use ID3v2 or ID3v1, or both. Anyway, what you want is Mutagen. It handles both Flac and Mp3 tags, as well as many others:http://www.sacredchao.net/quodlibet/wiki/Development/Mutagen Excellent! The web page you mentioned gave access denied, but I got to it via Google's cache, and the download link still worked :-) It does seem to build a Windows installer quite happily, so that's a great start. I'll see how it goes tonight. Thanks for the pointer. Paul. -- http://mail.python.org/mailman/listinfo/python-list
No file from stdin
Hi, suppose a script of python is waiting for a file from the stdin and none is given. How can I make the script to stop and, for example, print an error message? Sorry for the n00b question and thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: of destructors, open files and garbage collection
It will delete the *name* `item`. It does nothing to the object that was bound to that name. If the name was the only reference to that object, it may be garbage collected sooner or later. Read the documentation for the `__del__()` method for more details and why implementing such a method increases the chance that the object *won't* be garbage collected! Relying on the `__del__()` method isn't a good idea because there are no really hard guaranties by the language if and when it will be called. Ok, I gave a look at the docs and, in fact, relying on __del__ doesn't look like a good idea. Changing the code as to add an explicit method that closes dangling filehandles is easy. It would be somehow nice because -since that method would be added to a plugin API- it *forces* people writing plugins to ensure a way to close their dangling files, and this may be useful for a lot of future purposes. However I'd also like to track references to my objects -this would help debugging a lot. How can I do that? -- http://mail.python.org/mailman/listinfo/python-list
Re: of destructors, open files and garbage collection
Relying on the `__del__()` method isn't a good idea because there are no really hard guaranties by the language if and when it will be called. Ok, I read the __del__() docs and I understand using it is not a good idea. I can easily add a close_files() method that forces all dangling files to be closed. It would be useful in a number of other possible situations. However, as rightly pointed out by the exhaustive answer of Paul Moore, tracking references of my objects would be very useful. How can I do that? -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
Dennis Lee Bieber wrote: On Thu, 24 May 2007 09:07:07 -0500, Carl K [EMAIL PROTECTED] declaimed the following in comp.lang.python: Getting closer, thanks Bill and Diez. $ export ORACLE_HOME $ ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client Don't those lines need to be reversed? Set the variable in the current shell, and /then/ export it? whoops - I may have cut/pasted too fast. Carl K -- http://mail.python.org/mailman/listinfo/python-list
Re: Different methods with same name but different signature?
No. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
modifying values of List or Dictionary when iterating on them
Hello I just want to update the data inside List or Dictionary without adding or deleting object. is this correct ? l=[1, 2, 3] for i, v in enumerate(l): l[i]=v+1 d=dict(a=1, b=2, c=3) for k, v in d.iteritems(): d[k]=d[k]+1 Both works, but : are they correct ? are they optimum for big structure ? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Bootstrapping
I've seen it, but its different, the idea behind pyinstaller is to bundle python for a specific application, my idea is to modularize and compact the core of python and reuse the egg concept for extensions. The thing is that refuses to load the site-packages when the core is compressed. thanks again! On 24 mayo, 12:25, ici [EMAIL PROTECTED] wrote: On May 24, 5:53 pm, Mauler [EMAIL PROTECTED] wrote: I need some help with adding bootstrap code to the core of python, the idea is to leave a super base core inside a zip file (python25.zip works right out of the box) and leave the rest in separate zip modules. Making it more friendly with pendrives and more practical as a standalone runtime (ie, without install) and fully modular. The thing is that i need to modify the base importer to add this special site-packages . Any hints? thanks in advance (and a lot!) Martin Rene Vilugron Patagonia Argentina http://pyinstaller.python-hosting.com/? -- http://mail.python.org/mailman/listinfo/python-list
Re: No file from stdin
On 24 mai, 18:48, Tartifola [EMAIL PROTECTED] wrote: Hi, suppose a script of python is waiting for a file from the stdin and none is given. How can I make the script to stop and, for example, print an error message? Sorry for the n00b question and thanks import sys import os.path if len(sys.argv)2: print sys.stderr, 'Usage: %s filename' % (os.path.basename(sys.argv[0]),) sys.exit(1) print 'Your filename is %s' % (sys.argv[1],) -- http://mail.python.org/mailman/listinfo/python-list
Re: 0 == False but [] != False?
In article [EMAIL PROTECTED], Paul McGuire [EMAIL PROTECTED] wrote: This has *got* to rank up there among the VFAQ's of them all, along with the mysterious shared default empty list argument. I think this particular question has been asked in one form or another at least twice a week for the past month! Anyone who finds this surprising, might enjoy reading this article from the time several years ago when the feature was being considered. When you have some time - it's long, but interesting. The present confusion is more directly addressed towards the end. Yes, it's the Laura Creighton article again: http://groups.google.com/group/comp.lang.python/msg/2de5e1c8384c0360 Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: modifying values of List or Dictionary when iterating on them
d=dict(a=1, b=2, c=3) for k, v in d.iteritems(): d[k]=d[k]+1 You might as well do: d[k] = v + 1, like for the list. -- http://mail.python.org/mailman/listinfo/python-list
Re: CP4E revival
On May 24, 5:03 am, Richard Jones [EMAIL PROTECTED] wrote: Michael Tobis wrote: http://tinyurl.com/yr62r3 seems to short-circuit some pointless hoop-jumping to get you to the article. Hoop-jumping implemented to prevent just this kind of direct linking (and thus not saving of the PDF to local disk to view, and thus increasing the load on the server). Thanks for abusing the free service being provided to the Python Papers journal. Richard OK, oops, I'll take the tinyurl link down anywhere I can; I really didn't (and still don't) quite get the server side issue but so be it. (I thought it was a measure to ensure a license to view, which is not in fact required in this case.) On the other hand, given the modest reaction to the article (pro or con) I am not getting the sense that it has generated a lot of traffic. I'd prefer flames about the content, though. mt -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I time a method of a class in python using Timeit
On May 24, 9:36 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am using timeit to time a global function like this t = timeit.Timer(timeTest(),from __main__ import timeTest) result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread): def aFunction(self): # do something def run(self): # how can I time how long does aFunction() take here? aFunction(); Thank you. How about this: class Dog(object): def run(self): result = 10 * 20 + 3 import timeit t = timeit.Timer(d.run(), from __main__ import Dog; d = Dog()) print t.timeit() -- http://mail.python.org/mailman/listinfo/python-list
Re: need advice on building core code for python and PHP
Is there a way I could code the base (core) code in Python and have PHP call it? I've really liked using SQLAlchemy and there are other * quick and dirty solution: in a shell: $ python yourscript.py pipe_in pipe_out in the php script: fwrite(pipe_in, input_data); results = fread(pipe_out, sizeof_results); * simple and nice solution: do not ever use php -- http://mail.python.org/mailman/listinfo/python-list
Re: installing cx_Oracle.
On Thu, 2007-05-24 at 16:15 +, Dennis Lee Bieber wrote: On Thu, 24 May 2007 09:07:07 -0500, Carl K [EMAIL PROTECTED] declaimed the following in comp.lang.python: Getting closer, thanks Bill and Diez. $ export ORACLE_HOME $ ORACLE_HOME=/usr/lib/oracle/xe/app/oracle/product/10.2.0/client Don't those lines need to be reversed? Set the variable in the current shell, and /then/ export it? It also works the other way around, at least on the non-empty set of systems that contains my workstation. export simply marks the variable name for automatic export to the environment of subsequent commands. The value at that time doesn't matter. What matters is the value that the name has at the time the command is run: [EMAIL PROTECTED] ~]$ export FOOD [EMAIL PROTECTED] ~]$ FOOD=spam [EMAIL PROTECTED] ~]$ python -c import os; print os.environ['FOOD'] spam [EMAIL PROTECTED] ~]$ FOOD=eggs [EMAIL PROTECTED] ~]$ python -c import os; print os.environ['FOOD'] eggs Regards, -- Carsten Haese http://informixdb.sourceforge.net -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I time a method of a class in python using Timeit
On May 24, 11:30 am, 7stud [EMAIL PROTECTED] wrote: On May 24, 9:36 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I am using timeit to time a global function like this t = timeit.Timer(timeTest(),from __main__ import timeTest) result = t.timeit(); But how can i use timeit to time a function in a class? class FetchUrlThread(threading.Thread): def aFunction(self): # do something def run(self): # how can I time how long does aFunction() take here? aFunction(); Thank you. How about this: class Dog(object): def run(self): result = 10 * 20 + 3 import timeit t = timeit.Timer(d.run(), from __main__ import Dog; d = Dog()) print t.timeit() Actually, you could do this: class Dog(object): def aFunction(self): result = 20 + 2 def run(self): #do stuff aFunction() #do other stuff import timeit t = timeit.Timer(d.aFunction(), from __main__ import Dog; d = Dog()) print t.timeit() It doesn't matter if you call aFunction() directly if all you want to do is time aFunction(). -- http://mail.python.org/mailman/listinfo/python-list