Pyzor 0.5 Released
The Pyzor team is pleased to announce release 0.5 of Pyzor. The previous release was made in September of 2002, so it has obviously been a while! With this release, we have aimed to resolve all the outstanding reported bugs and incorporate submitted patches (many of which are also from some time ago). The hope is that this, along with the recent improvements to the public Pyzor server, revitalises the Pyzor project. We are aiming to release the next version of Pyzor, which will include new features, around the end of June (2009!). If you'd like to have input into that release, please subscribe to the pyzor-users mailing list, or monitor the SourceForge tickets for the Pyzor project. We are very keen to have as much input from the user-base as possible. The majority of the improvements in the 0.5 release were submitted from the Debian Pyzor package. Many thanks to them for pushing these back 'upstream' - if you have any improvements that you are running locally, please consider doing the same and contributing these as patches to the main Pyzor package (open a ticket on the SourceForge site). Main changes include: * Man pages for pyzor and pyzord. * Changing back to signals for database locking, rather than threads. It is likely that signals will be removed again in the future, but the existing threading changes caused problems. * Basic checks on the results of discover. * Extended mbox support throughout the library. * Better handling on unknown encodings. * Added a --log option to log to a file. * Better handling of command-line options. * Improved error handling. You can get the release (via the 'download' link on the left), as well as information about the mailing lists and other news, at: http://pyzor.org Enjoy the new release and your reduced spam mail :) As always, thanks to everyone involved in this release! Tony. (on behalf of the Pyzor team) --- What is Pyzor? --- Pyzor is a collaborative, networked system to detect and block spam using identifying digests of messages. Pyzor initially started out to be merely a Python implementation of Razor, but due to the protocol and the fact that Razor's server is not Open Source or software libre, Frank Tobin decided to implement Pyzor with a new protocol and release the entire system as Open Source and software libre. Since the entire system is released under the GPL, people are free to host their own independent servers, although there is a well-maintained public server available (public.pyzor.org), which anyone is welcome to use. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
[RELEASED] Python 3.1 beta 1
On behalf of the Python development team, I'm thrilled to announce the first and only beta release of Python 3.1. Python 3.1 focuses on the stabilization and optimization of features and changes Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. [1] Other features include an ordered dictionary implementation and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/dev/py3k/whatsnew/3.1.html or Misc/NEWS in the Python distribution. Please note that this is a beta release, and as such is not suitable for production environments. We continue to strive for a high degree of quality, but there are still some known problems and the feature sets have not been finalized. This beta is being released to solicit feedback and hopefully discover bugs, as well as allowing you to determine how changes in 3.1 might impact you. If you find things broken or incorrect, please submit a bug report at http://bugs.python.org For more information and downloadable distributions, see the Python 3.1 website: http://www.python.org/download/releases/3.1/ See PEP 375 for release schedule details: http://www.python.org/dev/peps/pep-0375/ Enjoy, -- Benjamin Benjamin Peterson benjamin at python.org Release Manager (on behalf of the entire python-dev team and 3.1's contributors) -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Why there is a parameter named self for classmethod function?
On Thu, 07 May 2009 00:39:28 -0400, Terry Reedy wrote: Functions that refer to neither the class nor an instance thereof can usually be moved outside the class altogether. Python is not Java. I believe staticmethod() was mainly added because it is needed for .__new__(), at least in some appearances. Can be, but if there's reason enough to keep it with a class, there's no reason not to. Sometimes I have a class with a few methods that share common code, but that code happens to not include self (or cls). Since the common code is only of interest to that class, even though it doesn't need the instance, I factor the common code out into a method. This would be a good candidate for a staticmethod, only due to laziness I don't usually bother :) -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging exceptions to a file
In message 597627b8- d30b-4b74-9202-9cd46fb1d...@s28g2000vbp.googlegroups.com, Pierre GM wrote: ... I'd like to record (possibly unhandled) exceptions in the logfile. python myscript.py 2error.log -- http://mail.python.org/mailman/listinfo/python-list
Which python version do I use with virtualenv?
I have Windows Vista Home Premium. As a non-techy, I want to use virtualenv I had Python 2.6 on my laptop. I needed easyinstall to install virtualenv. During installation of easyinstall, I got the message Python 2.5 not found So I installed Python 2.5, then installed virtualenv So I now have c:\Python 2.5 and c:\Python 2.6 On the virtualenv web site, the instructions for use are: $ python virtualenv.py ENV My question is, which python should I use on this command line: 2.5 or 2.6? BTW: I am currently running a Python app using 2.6. I want to install a beta upagrade of this app, without interfering with my current setup, so the app developer recommends using virtualenv. -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading and GIL
Hi, thats the reason why its not working. Imagine the end() method of the thread object is called so the C++ Function is opened where the code for this method is in. At a line the Code ...-End() is called which waits that the C++ Thread class is finished. BUT here is the problem: In the Method of the C++ class which is in threaded mode can't run because its still waiting that the GIL is released by the thread which executed the -End() command. So the app has a deadlock when it arrives at -End() and PyGILState_Ensure function. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASED] Python 3.1 beta 1
On behalf of the Python development team, I'm thrilled to announce the first and only beta release of Python 3.1. .. Other features include an ordered dictionary implementation Are there plans for backporting this to python 2.x just as multiprocessing has been? I know that there are several ordered dictionary implementations for 2.x but they are all a little bit different from the one going into 3.1, hence my question. Cheers, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking for required arguments when instantiating class.
On May 6, 3:36 pm, Chris Rebert c...@rebertia.com wrote: On Wed, May 6, 2009 at 5:24 AM, Piet van Oostrum p...@cs.uu.nl wrote: Lacrima lacrima.ma...@gmail.com (L) wrote: L Hello! L For example I have two classes: class First: L def __init__(self, *args, **kwargs): L pass class Second: L def __init__(self, somearg, *args, **kwargs): L self.somearg = somearg L How can I test that First class takes 1 required argument and Second L class takes no required arguments? L So that I could instantiate them in a for loop. a = [First, Second] for cls in a: L instance = cls() L Traceback (most recent call last): L File pyshell#22, line 2, in module L instance = cls() L TypeError: __init__() takes at least 2 arguments (1 given) L Of course, I can do like this: for cls in a: L try: L instance = cls() L except TypeError: L instance = cls('hello') print instance.somearg L hello L But what if I have to instantiate any class with 3 or 4 required L arguments? How can I do it? cls.__init__.im_func.__code__.co_argcount This will include self, so it will be 1 in First and 2 in Second. AFAICT, that would count non-required arguments too, which isn't strictly what the OP requested. However this is very dirty trickery and should not be recommended. It may also change in future versions and other implementations of Python. Very much agreed. I think it would be cleaner to put a class attribute in the classes that defines how they should be initialized (e.g. just the number of required arguments or more specific information) or have a special factory method for this use case. Seconded. I'd recommend the latter personally, though it's impossible to give a definitive answer without more context. Cheers, Chris --http://blog.rebertia.com Thanks for all of you! I think I'll try to write a special method for this case and will report you result. -Max -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
On Thu, 07 May 2009 00:03:11 -0700, OldGrantonian wrote: So I now have c:\Python 2.5 and c:\Python 2.6 On the virtualenv web site, the instructions for use are: $ python virtualenv.py ENV My question is, which python should I use on this command line: 2.5 or 2.6? I'm not an expert on virtualenv, nor do I use Windows, but I'd start off with this: $ c:\Python 2.5\python.exe vitualenv.py ENV and if that doesn't do what you expect, report the precise error you get and hopefully somebody who knows more about Windows can help. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple way of handling errors
TomF wrote: As a relative newcomer to Python, I like it a lot but I'm dismayed at the difficulty of handling simple errors. In Perl if you want to anticipate a file-not-found error you can simply do: open($file) or die(open($file): $!); and you get an intelligible error message. In Python, to get the same thing it appears you need at least: try: f=open(file) except IOError, err: print open(%s): got %s % (file, err.strerror) exit(-1) Is there a simpler interface or idiom for handling such errors? I appreciate that Python's exception handling is much more sophisticated but often I don't need it. -Tom While you are making the transition you could write from perl_idioms import open_or_die f = open_or_die(does-not-exist) with the perl_idioms module looking like import sys def open_or_die(*args): try: return open(*args) except IOError, e: sys.exit(e) Peter -- http://mail.python.org/mailman/listinfo/python-list
idea
Redirect sys.stderr to the log file in ANUGA logging. This might catch unexpected exceptions. -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension question
Steven D'Aprano wrote: If you’ve got the stomach for it, list comprehensions can be nested. They are a powerful tool but – like all powerful tools – they need to be used carefully, if at all. How does this discourage the use of list comprehensions? At most, it warns that complicated list comps are tricky. Complicated *anything* are tricky. and In real world, you should prefer builtin functions to complex flow statements. That's ridiculous. The example given is a special case. That's like saying Loops are hard, so in the real world, if you want a loop, find a builtin function that does what you want instead. What's the builtin function we're supposed to prefer over a complex flow statement like this? # split text into word fragments of length = 3 sentence = a sentence is a series of words new = [word[i:i+3] for word in sentence.split() for i in range(0, len(word), 3)] I often found list comprehension *more* readable than the equivalent for-loop because of its density. Seeing complex for-loop requires one step of thinking for each line, but in list comprehension I can skip some of the steps because I know what list comprehension would roughly look like. i.e. when I process this: lst = [] #1 for i in range(10): #2 lst.append(i) #3 I do 3 steps of thinking for each line but seeing this is only one step, since I know it is going to create new list (skipping step #1) and I know i will be appended to that list (skipping step #3) -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension question
Lie Ryan wrote: Steven D'Aprano wrote: If you’ve got the stomach for it, list comprehensions can be nested. They are a powerful tool but – like all powerful tools – they need to be used carefully, if at all. How does this discourage the use of list comprehensions? At most, it warns that complicated list comps are tricky. Complicated *anything* are tricky. and In real world, you should prefer builtin functions to complex flow statements. That's ridiculous. The example given is a special case. That's like saying Loops are hard, so in the real world, if you want a loop, find a builtin function that does what you want instead. What's the builtin function we're supposed to prefer over a complex flow statement like this? # split text into word fragments of length = 3 sentence = a sentence is a series of words new = [word[i:i+3] for word in sentence.split() for i in range(0, len(word), 3)] I often found list comprehension *more* readable than the equivalent for-loop because of its density. Seeing complex for-loop requires one step of thinking for each line, but in list comprehension I can skip some of the steps because I know what list comprehension would roughly look like. i.e. when I process this: lst = [] #1 for i in range(10): #2 lst.append(i) #3 I do 3 steps of thinking for each line but seeing this is only one step, since I know it is going to create new list (skipping step #1) and I know i will be appended to that list (skipping step #3) I don't know what I was thinking before sending that last line, here is what it was supposed to be: but in list comprehension I see this in only one step, since I know it is going to create new list (skipping step #1) and I know 'i' will be appended to that list (skipping step #3) and this also continues to nested list comprehensions -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
On May 7, 8:03 am, OldGrantonian oldgranton...@googlemail.com wrote: ... I had Python 2.6 on my laptop. I needed easyinstall to install virtualenv. During installation of easyinstall, I got the message Python 2.5 not found So I installed Python 2.5, then installed virtualenv So I now have c:\Python 2.5 and c:\Python 2.6 ... Sounds like you've downloaded the Python 2.5 version of Easy Install. If I were you I'd uninstall Python 2.5, and re-install easy_install using the correct exe for Python 2.6. Check that typing 'python' on the commandline still works, as installing and uninstalling 2.5 may have messed up your path. if it has, either manually add the Python install directory to the path, or reinstall Python 2.6. Note: have you changed the default install folder? I haven't got Vista, but on XP it installs to c:\Python26 not C:\Python 2.6. I'd be carefull of changing the default install directory of Python, particularly if you are non-techy as some packages installers may look for Python in the default location. -- Ant -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension question
Scott David Daniels wrote: John Posner wrote: Shane Geiger wrote: if type(el) == list or type(el) is tuple: A tiny improvement: if type(el) in (list, tuple): or (even better) if isinstance(el, (list, tuple)) However, it is my contention that you shouldn't be flattening by type -- you should know where, explicitly to flatten. If I have 3-D points as triples, a tree of points would, by this code, get flattened into a a list of numbers. If, however, I create a class with the same elements, but a method or two, suddenly flatten will produce a list of points. It is my contention that the tree abstraction should be responsible for producing its leaves, rather than a blunderbus that doesn't know where one container abstraction ends, and its contents begin. In other words, I'd like to see thigs like flatten one layer. Maybe that is why some modules like PIL or pygame accepts list of coordinates in flattened list of number instead of nested (i.e. they accepts [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] and do the grouping themself). -- http://mail.python.org/mailman/listinfo/python-list
Statically linked extension and relative import
Hi, I am trying to build a 3rd party extension and link it statically to python. I managed to get things working by customizing Setup.local in python source tree, but I have a problem for imports of the 'foo.bar' form. For example, let's say the 3rd party module is laid out as follows: foo/__init__.py foo/bar.so and __init__.py contains: import foo.bar I can build the bar extension and link it statically to python such as from python, import bar works. But how can I make it recognize from foo import bar ? I tried to understand how this works at the C level in import.c, but I am a bit lost in the code. The ultimate goal is to manage to get code coverage of the C code of the extension through gcov, which does not support coverage of shared libraries ATM. thanks, David -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging exceptions to a file
Pierre GM wrote: All, I need to log messages to both the console and a given file. I use the following code (on Python 2.5) import logging # logging.basicConfig(level=logging.DEBUG,) logfile = logging.FileHandler('log.log') logfile.setLevel(level=logging.INFO) logging.getLogger('').addHandler(logfile) # mylogger = logging.getLogger('mylogger') # mylogger.info(an info message) So far so good, but I'd like to record (possibly unhandled) exceptions in the logfile. * Do I need to explicitly trap every single exception ? * In that case, won't I get 2 log messages on the console (as illustrated in the code below: try: 1/0 except ZeroDivisionError: mylogger.exception(:() raise Any comments/idea welcomed Cheers. Although it is usually not recommended to use a catch-all except, this is the case where it might be useful. JUST DON'T FORGET TO RE-RAISE THE EXCEPTION. if __name__ == '__main__': try: main(): except Exception, e: # log('Unhandled Exception', e) raise -- http://mail.python.org/mailman/listinfo/python-list
About Odfpy links
hey all, For my project, i am using ODFpy open office spreadsheets. I am creating ledgers in python ie.ledger.py. So when i run ledger.py, spreadsheet will be opened in open office. since ledger is made of number of accounts, i am creating multiple tables for all accounts in single spreadsheet. So, there are number of tables in one spreadsheet. Now i want create links in each table of spreadsheet so that i can connect multiple tables. SO can anyone please tell me how to create links in odfpy.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python-list Digest, Vol 68, Issue 79
3. Re: About ODFPY links (Terry Reedy) -- Forwarded message -- From: Terry Reedy tjre...@udel.edu To: python-list@python.org Date: Wed, 06 May 2009 19:02:59 -0400 Subject: Re: About ODFPY links shruti surve wrote: hey all, For my project, i am using ODFpy open office spreadsheets. I am creating ledgers in python ie.ledger.py http://ie.ledger.py. So when i run ledger.py, spreadsheet will be opened in open office. since ledger is made of number of accounts, i am creating multiple tables for all accounts in single spreadsheet. So, there are number of tables in one spreadsheet. Now i want create links in each table of spreadsheet so that i can connect multiple tables. SO can anyone please tell me how to create links in odfpy.. The general answer to such questions is to make a minimal doc in some ODF application such of OOo that has the desired feature, save, open the doc as a zip file (unless saved as xml) and extract the pieces as xml. Then find the text that represents that feature. There is a close correspondance between the xml and the internal document object model created by odfpy (and OOo, etc). In your case, make a spreadsheet with two table. Give one one literal entry. Give the other one entry that links to the first. Then look in the xml to see how links are presented. That should give a hint as to how to do the same in odfpy. Then try to recreate the minimal doc with odfpy and look at the xml *it* produces. If it looks similar enough, open with OOo to see what you get. tjr hi i have tried that and i found text:ptext:a xlink:href=#Sheet2 office:target-frame-name=_selfInvestments/text:a/text:p...so in my ledger.py i have written: para = P(text=lst_debit[i][0]) lan=A(href=lst_debit[i][0],targetframename=_self,text=lst_debit[i][0]) lan.addElement(para) tc.addElement(lan) tr.addElement(tc) (where lst_debit[i][0] is my account name coming from database) but still its not coming erroris : in addElement odf.element.IllegalChild: text:p is not allowed in text:a i have tried it with: tc.addElement(P(text=lst_credit[i][0]),A(href=lst_debit[i][0],targetframename=_self)) but still its not coming, it is not giving any error, but not creating link, giving simple text field.. so i basically i am not getting how to manage P and A properties of cell together Regards shruti surve -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple way of handling errors
If it fails, you get both a straight-forward error message and a useful traceback: Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'foomanchu' The only reason you would bother going to the time and effort of catching the error, printing your own error message, and then exiting, is if you explicitly want to hide the traceback from the user. Unfortunately, I find that even halfway technically trained (not necessarily naturally inclined or talented, but trained) users are utterly unable to read tracebacks in real world situations. I had to put up a rather big guide on how to read and interpret even the simplest ones complete with color coding, how to pick out a traceback visually, what line to focus your attention on (the last), and how trying to /read/ it instead of immediately sending it to me as if it were an opaque symbol containing secret knowledge only I can make sense of, generally saves you time in debugging issues. I'm not talking about esoteric tracebacks either resulting from real bugs and stuff. I'm talking about 'file not found' 'permission denied' IO/OS level ones that should give serious hints at things people should check/diagnose themselves. There's a serious, oh my god, traceback, /eyes glazed over/ reaction all around. Now these aren't unix people or command line people (except my rote), but still. I don't quite find printing out tracebacks to stdout or stderr ever acceptable :( Especially if its an expected error condition (file not found is a very good example of that). I route all my tracebacks into log files for diagnosing later (people also can not be relied upon to say anything but 'traceback' when they see one: so storing it for later is vital. They read the first word and stop. The thought of most-significant-information at the bottom is a difficult thing, alas) Anyways. ;-) That's just my experience. As to the OP: try/except is how you do it in Python. There's no shorter or easier way; exceptions are how Python handles failure-states (even soft/expected errors quite often) and it does so pervasively (but not universally). --S -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple way of handling errors
On Wed, 06 May 2009 20:21:38 -0700, TomF wrote: The only reason you would bother going to the time and effort of catching the error, printing your own error message, and then exiting, is if you explicitly want to hide the traceback from the user. Well, to me, exposing the user to such raw backtraces is unprofessional, which is why I try to catch user-caused errors. But I suppose I have an answer to my question. That depends on your audience. Not every program is written to be used for a technical incompetent audience. Some users actually *want* to see the errors. But certainly there are large classes of applications where you do want to suppress the traceback. That's why I said if you explicitly want to hide the traceback from the user rather than don't do this. The idiom I use is to wrap the *entire* application in a single try...except block, and then put all your user-friendly error handling in one place, instead of scattered over the entire application: try: main(sys.argv[1:]) except KeyboardInterrupt, SystemExit: raise except Exception, e: log(e) print sys.stderr, str(e) sys.exit(1) Hope this helps. -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: idea
r-w wrote: Redirect sys.stderr to the log file in ANUGA logging. This might catch unexpected exceptions. brillant. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
Thanks to both Steven D'Aprano and Ant :) Sounds like you've downloaded the Python 2.5 version of Easy Install. There's no Python 2.6 version of EasyInstall :( For 2.5, there is: setuptools-0.6c9.win32-py2.5.exe But for 2.6, it's: setuptools-0.6c9-py2.6.egg For any other egg file, I would use EasyInstall, but I don't think I can use EasyInstall to install EasyInstall :) -- http://mail.python.org/mailman/listinfo/python-list
Re: The Fujitsu Lifebook A6120
Does it run Python? (sorry, could not resist) You could at least resist to quote the spammers url, so it doesn't get higher pagerank. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Why there is a parameter named self for classmethod function?
On May 7, 1:29 am, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: On Thu, 07 May 2009 00:39:28 -0400, Terry Reedy wrote: Functions that refer to neither the class nor an instance thereof can usually be moved outside the class altogether. Python is not Java. I believe staticmethod() was mainly added because it is needed for .__new__(), at least in some appearances. Can be, but if there's reason enough to keep it with a class, there's no reason not to. Sometimes I have a class with a few methods that share common code, but that code happens to not include self (or cls). Since the common code is only of interest to that class, even though it doesn't need the instance, I factor the common code out into a method. This would be a good candidate for a staticmethod, only due to laziness I don't usually bother :) -- Steven It's also useful if you want to access the function using the syntax of attributes, as in 'self.amethod' where 'amethod' is a static method. If I understand correctly, no bound method is created if the function is static, and as such, the decorator can increase performance. Can be, but if there's reason enough to keep it with a class, there's no reason not to. That's a bit of hyperbole; the usual reasons such as code bloat, namespace bloat, maintainability etc. all weigh against it. It's just that the benefits weigh heavier. There is something that is 'correct' about it IMO, that is, provides syntax to what is valid semantics in an OO context. That may just be another way of stating the thesis though. -- http://mail.python.org/mailman/listinfo/python-list
Re: Statically linked extension and relative import
David Cournapeau wrote: Hi, I am trying to build a 3rd party extension and link it statically to python. I managed to get things working by customizing Setup.local in python source tree, but I have a problem for imports of the 'foo.bar' form. For example, let's say the 3rd party module is laid out as follows: foo/__init__.py foo/bar.so and __init__.py contains: import foo.bar I can build the bar extension and link it statically to python such as from python, import bar works. But how can I make it recognize from foo import bar ? I tried to understand how this works at the C level in import.c, but I am a bit lost in the code. The ultimate goal is to manage to get code coverage of the C code of the extension through gcov, which does not support coverage of shared libraries ATM. If you link the bar extension statically, it is not in the foo package namespace (which is why import bar works), so should be imported as bar in foo's __init__.py. from foo import bar should then work from other code by virtue of the package namespace (instantiated by __init__.py) then having a bar symbol. -- - Andrew I MacIntyre These thoughts are mine alone... E-mail: andy...@bullseye.apana.org.au (pref) | Snail: PO Box 370 andy...@pcug.org.au (alt) |Belconnen ACT 2616 Web:http://www.andymac.org/ |Australia -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
OldGrantonian oldgranton...@googlemail.com wrote: Thanks to both Steven D'Aprano and Ant :) Sounds like you've downloaded the Python 2.5 version of Easy Install. There's no Python 2.6 version of EasyInstall :( I wonder what I've been running then? For 2.5, there is: setuptools-0.6c9.win32-py2.5.exe But for 2.6, it's: setuptools-0.6c9-py2.6.egg For any other egg file, I would use EasyInstall, but I don't think I can use EasyInstall to install EasyInstall :) No, but you can use ez_setup. Go to http://peak.telecommunity.com/dist/ez_setup.py and save the content of that file as ez_setup.py (cut and paste into your favourite editor may be the simplest way) then run it with your chosen Python. It will find and install the appropriate version of easy install. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Statically linked extension and relative import
On Thu, May 7, 2009 at 8:34 PM, Andrew MacIntyre andy...@bullseye.apana.org.au wrote: David Cournapeau wrote: Hi, I am trying to build a 3rd party extension and link it statically to python. I managed to get things working by customizing Setup.local in python source tree, but I have a problem for imports of the 'foo.bar' form. For example, let's say the 3rd party module is laid out as follows: foo/__init__.py foo/bar.so and __init__.py contains: import foo.bar I can build the bar extension and link it statically to python such as from python, import bar works. But how can I make it recognize from foo import bar ? I tried to understand how this works at the C level in import.c, but I am a bit lost in the code. The ultimate goal is to manage to get code coverage of the C code of the extension through gcov, which does not support coverage of shared libraries ATM. If you link the bar extension statically, it is not in the foo package namespace (which is why import bar works), Yes, I understand this. so should be imported as bar in foo's __init__.py. from foo import bar But then I have to modify the 3rd party package for statically linked versions. This means in particular that the same source cannot be used for static and dynamic builds ? cheers, David -- http://mail.python.org/mailman/listinfo/python-list
ply and threads
I have two threads that exchange information by passing messages. I wanted to parse those messages with ply. I'd prefer using two independent parsers so that I can avoid using locks. Can somebody explain how to do this with ply? Ply seems to be doing a lot of odd things, such as reading the the python file that imported it, reading doc strings of it's functions, etc, so I'm not sure how to make this thread safe. This is from yacc.py: # The current implementation is only somewhat object-oriented. The # LR parser itself is defined in terms of an object (which allows multiple # parsers to co-exist). However, most of the variables used during table # construction are defined in terms of global variables. Users shouldn't # notice unless they are trying to define multiple parsers at the same # time using threads (in which case they should have their head examined). It would seem that creating two parsers in the main thread, and then passing one of them to the other thread, is all I need to do to be thread safe? But then again I'm not even sure how to create two parsers. Examples I've seen just call yacc.yacc() at the end, and do not even access yacc instances. Any help is appreciated and thanks in advance. Dean -- http://mail.python.org/mailman/listinfo/python-list
Open the franchisee of Karvy
Karvy stock broking introduces, Karvy Fortune a business opportunity for individuals in similar business from Karvy, it gives the opportunity to associate with “Karvy Family” as Franchisee, Remisser, or as an Independent Financial Advisors. Karvy Stock Broking Ltd ranks among 5 stock brokers in India, it ranks among top 5 Depositary Participants in India, with the huge net work of over 500 branches in 375 locations across India and overseas at Dubai, executes 150,000+ trades in NSE/BSE. Karvy Has a top notch research team, advisory team, technology support team to serve it’s customers in 24/7 manner. http://www.karvy.com/v2/fortune/fortunegroups/index.asp -- http://mail.python.org/mailman/listinfo/python-list
How should I use grep from python?
I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir that contain the string foo. I'm looking for the one obvious way to do it and instead I found no consensus. I could os.popen, commands.getstatusoutput, the subprocess module, backticks, etc. As of May 2009, what is the recommended way to run an external process like grep and capture STDOUT and the error code? TIA Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Code works fine except...
John Yeung wrote: On May 7, 12:30 am, Ross ross.j...@gmail.com wrote: If I were to set up a dictionary that counted players used in the bye list and only allowed players to be added to the bye list if they were within 2 of the least used player, would this be a good approach for managing bye selection or would using a dictionary in this manner be unnecessary/redundant? I certainly have not proved it, but I think you don't need to resort to anything fancy if you are OK with the maximum byes being within two of the minimum byes. (Maybe this needs to be larger with larger numbers of players.) Try using your original shuffle but instead of selecting matches to throw away each week, just use the matches you need (to fill up the courts) and pick up where you left off the next week. For example, with 10 players, each round ideally consists of five matches. If you only have four courts, don't throw away the fifth match; save it as the first match next week. To be honest, I didn't look too carefully at your original shuffle. It may be good enough. It's a little different than the standard rotation as presented on Wikipedia: http://en.wikipedia.org/wiki/Round-robin_tournament#Scheduling_algorithm The one on Wikipedia happened to pass my casual tests with no more than a 2-bye difference between the most-played and least-played players, and didn't run into the problem of scheduling the same player for two matches the same week. But I have to stress I only tried a few starting values, which all worked; I didn't try to break it, or run an extensive battery of tests. It might be an idea to run an exhaustive test on small, but not too small, values in order to see whether the minimum difference can, in fact, be one. If the minimum difference turns out to be two then you might as well stick to a simple algorithm, as long as its minimum difference is two. -- http://mail.python.org/mailman/listinfo/python-list
Re: Checking for required arguments when instantiating class.
Chris Rebert c...@rebertia.com (CR) wrote: CR On Wed, May 6, 2009 at 5:24 AM, Piet van Oostrum p...@cs.uu.nl wrote: Lacrima lacrima.ma...@gmail.com (L) wrote: L But what if I have to instantiate any class with 3 or 4 required L arguments? How can I do it? cls.__init__.im_func.__code__.co_argcount This will include self, so it will be 1 in First and 2 in Second. CR AFAICT, that would count non-required arguments too, which isn't CR strictly what the OP requested. If you mean, parameters with default values, yes. Of course you can find out how many of these there are from cls.__init__.func_defaults, but this will get dirtier and dirtier. -- Piet van Oostrum p...@cs.uu.nl URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4] Private email: p...@vanoostrum.org -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASED] Python 3.1 beta 1
Daniel Fetchinson wrote: Other features include an ordered dictionary implementation Are there plans for backporting this to python 2.x just as multiprocessing has been? Why not grab the 3.1 code and do it yourself for your 2.X's? It should be far less work than attempting something as fidgety as multiprocessing. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I use grep from python?
Matthew Wilson wrote: I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir that contain the string foo. I'm looking for the one obvious way to do it and instead I found no consensus. I could os.popen, commands.getstatusoutput, the subprocess module, backticks, etc. As of May 2009, what is the recommended way to run an external process like grep and capture STDOUT and the error code? subprocess. Which becomes pretty clear when reading it's docs: The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several other, older modules and functions, such as: os.system os.spawn* os.popen* popen2.* commands.* Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging exceptions to a file
On May 7, 5:32 am, Lie Ryan lie.1...@gmail.com wrote: Pierre GM wrote: All, I need to log messages to both the console and a given file. I use the following code (on Python 2.5) import logging # logging.basicConfig(level=logging.DEBUG,) logfile = logging.FileHandler('log.log') logfile.setLevel(level=logging.INFO) logging.getLogger('').addHandler(logfile) # mylogger = logging.getLogger('mylogger') # mylogger.info(an info message) So far so good, but I'd like to record (possibly unhandled) exceptions in the logfile. * Do I need to explicitly trap every single exception ? * In that case, won't I get 2 log messages on the console (as illustrated in the code below: try: 1/0 except ZeroDivisionError: mylogger.exception(:() raise Any comments/idea welcomed Cheers. Although it is usually not recommended to use a catch-all except, this is the case where it might be useful. JUST DON'T FORGET TO RE-RAISE THE EXCEPTION. if __name__ == '__main__': try: main(): except Exception, e: # log('Unhandled Exception', e) raise OK for a simple script, but the (unhandled) exceptions need to be caught at the module level. Any idea? -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I use grep from python?
I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir that contain the string foo. I'm looking for the one obvious way to do it and instead I found no consensus. I could os.popen, commands.getstatusoutput, the subprocess module, backticks, etc. While it doesn't use grep or external processes, I'd just do it in pure Python: def files_containing(location, search_term): for fname in os.listdir(location): fullpath = os.path.join(location, fname) if os.isfile(fullpath): for line in file(fullpath): if search_term in line: yield fname break for fname in files_containing('/tmp', 'term'): print fname It's fairly readable, you can easily tweak the search methods (case sensitive, etc), change it to be recursive by using os.walk() instead of listdir(), it's cross-platform, and doesn't require the overhead of an external process (along with the which call do I use to spawn the function questions that come with it :) However, to answer your original question, I'd use os.popen which is the one I see suggested most frequently. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: [Python-Dev] [RELEASED] Python 3.1 beta 1
On Thu, May 7, 2009 at 9:12 AM, Scott David Daniels scott.dani...@acm.org wrote: Daniel Fetchinson wrote: Other features include an ordered dictionary implementation Are there plans for backporting this to python 2.x just as multiprocessing has been? Why not grab the 3.1 code and do it yourself for your 2.X's? It should be far less work than attempting something as fidgety as multiprocessing. --Scott David Daniels scott.dani...@acm.org Don't worry, we gave multiprocessing some ADHD meds :) -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I use grep from python?
On Thu 07 May 2009 09:09:53 AM EDT, Diez B. Roggisch wrote: Matthew Wilson wrote: As of May 2009, what is the recommended way to run an external process like grep and capture STDOUT and the error code? subprocess. Which becomes pretty clear when reading it's docs: Yeah, that's what I figured, but I wondered if there was already something newer and shinier aiming to bump subprocess off its throne. I'll just stick with subprocess for now. Thanks for the feedback! -- http://mail.python.org/mailman/listinfo/python-list
Get Into The World Of YOUSUF JUSANI
Get The Most Valuable and Best For Investment Properties IN ASIA, !! Real Estate Builders.. Real Estate Dealer Buy, Sell REAL EASTAE IN GULF ,DUBAI AND AUSTRIA FOR MORE INFO http://www.yousufjusani.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I use grep from python?
On Thu 07 May 2009 09:25:52 AM EDT, Tim Chase wrote: While it doesn't use grep or external processes, I'd just do it in pure Python: Thanks for the code! I'm reluctant to take that approach for a few reasons: 1. Writing tests for that code seems like a fairly large amount of work. I think I'd need to to either mock out lots of stuff or create a bunch of temporary directories and files for each test run. I don't intend to test that grep works like it says it does. I'll just test that my code calls a mocked-out grep with the right options and arguments, and that my code behaves nicely when my mocked-out grep returns errors. 2. grep is crazy fast. For a search through just a few files, I doubt it would matter, but when searching through a thousand files (which is likely) I suspect that an all-python approach might lag behind. I'm speculating here, though. 3. grep has lots and lots of cute options. I don't want to think about implementing stuff like --color, for example. If I just pass all the heavy lifting to grep, I'm already done. On the other hand, your solution is platform-independent and has no dependencies. Mine depends on an external grep command. Thanks again for the feedback! Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I use grep from python?
Matthew Wilson wrote: consensus. I could os.popen, commands.getstatusoutput, the subprocess module, backticks, etc. Backticks do_not_do what you think they do. And with py3k they're also as dead as a dead parrot. -- http://mail.python.org/mailman/listinfo/python-list
pyMPI error on mpi.barrier()
Hello there I am trying to paralleize GA code using pyMPI. part of the code and and the error message is as below. i write the new positions in a file by root (which is mpi.rank = 0) then other processes are suppose to wait until the written in the file finishes to start evaluating the objective. the problem arises in the barrier method... any ideas on how to do this would be very much appreciated.. Thanks very much Dina for i in xrange(max_iter): if (mpi.rank == 0): update_positions() save_pso_pops_iter() mpi.barrier() error is here evaluate_objective() mpi.barrier() error message: mpi.barrier() mpi.MPIError: MPI_Error_string: invalid communicator: Input/output error (pyMPI_comm_io.c:367) -- http://mail.python.org/mailman/listinfo/python-list
Re: [RELEASED] Python 3.1 beta 1
On May 7, 9:12 am, Scott David Daniels scott.dani...@acm.org wrote: Daniel Fetchinson wrote: Other features include an ordered dictionary implementation Are there plans for backporting this to python 2.x just as multiprocessing has been? Why not grab the 3.1 code and do it yourself for your 2.X's? It should be far less work than attempting something as fidgety as multiprocessing. --Scott David Daniels scott.dani...@acm.org If OrderedDict winds up being backported, will you include it in 2.x? Geremy Condra -- http://mail.python.org/mailman/listinfo/python-list
ANN: Python process utility (psutil) 0.1.2 released
Hi, I'm pleased to announce the 0.1.2 release of psutil: http://code.google.com/p/psutil === About === psutil is a module providing an interface for retrieving information on running processes and system utilization (CPU, memory) in a portable way by using Python, implementing many functionalities offered by tools like ps, top and Windows task manager. It currently supports Linux, OS X, FreeBSD and Windows. === Enhancements === Aside from fixing some bugs psutil 0.1.2 includes the following major enhancements: * per-process CPU user/kernel times * per-process create time * per-process CPU utilization percentage * per-process memory usage (bytes) * per-process memory utilization (percent) * total, used and free system physical/virtual memory As of now psutil is released to the general public, and should be considered a beta release implementing basic functionality. With this third release we'd like to receive feedback from users and suggestions for additional functionality. Patches and volunteers to test/develop for additional platforms welcome! === Links === * Home page: http://code.google.com/p/psutil * Mailing list: http://groups.google.com/group/psutil/topics * Source tarball: http://psutil.googlecode.com/files/psutil-0.1.2.tar.gz * OS X installer: http://psutil.googlecode.com/files/psutil-0.1.2-py2.6-macosx10.4.dmg * Windows Installer (Python 2.6): http://psutil.googlecode.com/files/psutil-0.1.2.win32-py2.6.exe * Api Reference: http://code.google.com/p/psutil/wiki/Documentation Thanks --- Giampaolo Rodola' http://code.google.com/p/pyftpdlib http://code.google.com/p/psutil/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Parsing text
iainemsley iainemsley at googlemail.com writes: Hi, I'm trying to write a fairly basic text parser to split up scenes and acts in plays to put them into XML. I've managed to get the text split into the blocks of scenes and acts and returned correctly but I'm trying to refine this and get the relevant scene number when the split is made but I keep getting an NoneType error trying to read the block inside the for loop and nothing is being returned. I'd be grateful for some suggestions as to how to get this working. for scene in text.split('Scene'): num = re.compile(^\s\[0-9, i{1,4}, v], re.I) textNum = num.match(scene) if textNum: print textNum else: print No scene number m = 'div type=scene' m += scene m += '\div' print m Thanks, Iain -- http://mail.python.org/mailman/listinfo/python-list Are you trying to match Roman numerals? As others have said, it is difficult to make any suggestions without knowing the input to your program. You may want to look at PyParsing (http://pyparsing.wikispaces.com/) to parse the text file without messing with regular expressions. Regards, Suraj -- http://mail.python.org/mailman/listinfo/python-list
Re: FLV download script works, but I want to enhance it
In article mailman.5134.1241579669.11746.python-l...@python.org, The Music Guy music...@alphaios.net wrote: After I download the files, I usually want to convert them to another video format using command line tools, and I usually convert each one in a separate terminal since that way they can all be converted at the same time rather than one-by-one. Oddly enough, converting tends to take longer than downloading, but converting multiple files at once is faster than converting them one-by-one. Here's my download script to get you started figuring this out, it does the wget in the background so that several downloads can run in parallel from a single terminal window: #!/bin/bash echo Downloading $1 wget $1 /dev/null 21 -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ It is easier to optimize correct code than to correct optimized code. --Bill Harlan -- http://mail.python.org/mailman/listinfo/python-list
Re: How should I use grep from python?
Matthew Wilson m...@tplus1.com wrote: I'm writing a command-line application and I want to search through lots of text files for a string. Instead of writing the python code to do this, I want to use grep. This is the command I want to run: $ grep -l foo dir In other words, I want to list all files in the directory dir that contain the string foo. I'm looking for the one obvious way to do it and instead I found no consensus. I could os.popen, commands.getstatusoutput, the subprocess module, backticks, etc. backticks is some other language ;-) As of May 2009, what is the recommended way to run an external process like grep and capture STDOUT and the error code? This is the one true way now-a-days from subprocess import Popen, PIPE p = Popen([ls, -l], stdout=PIPE) for line in p.stdout: ... print line ... total 93332 -rw-r--r-- 1 ncw ncw 181 2007-10-18 14:01 - drwxr-xr-x 2 ncw ncw 4096 2007-08-29 22:56 10_files -rw-r--r-- 1 ncw ncw 124713 2007-08-29 22:56 10.html [snip] p.wait() # returns the error code 0 There was talk of removing the other methods from public use for 3.x. Not sure of the conclusion. -- Nick Craig-Wood n...@craig-wood.com -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
I have another question in this same context. I have python 2.6 and want to set up a vertualenv in /opt/turbogears/python2.5. Then use this for all the things a turbogears based application would need for project execution. so I have decided that I will download python 2.5 and compile it with ./configure --prefix=/opt/turbogears/python2.5 and then install turbogears. Is this possible? will this kind of python compilation help me to create a vertualenv in the place where I have python2.5? or is there any other way to do this? I really need vertualenv and would want to use python2.5 because I feel easy install won't work with python2.6 happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
Krishnakant wrote: I have another question in this same context. I have python 2.6 and want to set up a vertualenv in /opt/turbogears/python2.5. Then use this for all the things a turbogears based application would need for project execution. so I have decided that I will download python 2.5 and compile it with ./configure --prefix=/opt/turbogears/python2.5 and then install turbogears. Is this possible? will this kind of python compilation help me to create a vertualenv in the place where I have python2.5? You are confusing virtualenv with a custom-build python. You can of course use VE with a custom-build python, but then there isn't as much use for it, as you then have a distinct python-instance already - unless you are going to share it amongst projects, which then leads to the question why you don't use VE *without* the custom-build python. or is there any other way to do this? I really need vertualenv and would want to use python2.5 because I feel easy install won't work with python2.6 Feelings are a fine thing in bed, on weddings or other social contexts. Usually, they don't belong in the more mundane world of computers, and in this case it's an outright wrong feeling. Easy_install works just fine with py2.6 It might be though that there are some 3rd-party-libs that don't. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
You are confusing virtualenv with a custom-build python. You can of course use VE with a custom-build python, but then there isn't as much use for it, as you then have a distinct python-instance already - unless you are going to share it amongst projects, which then leads to the question why you don't use VE *without* the custom-build python. Well, Turbogears works perfectly with python2.5, although there are people who use it with 2.6 as well. I have to keep 2.6 because my screen reader orca giave me some problem with 2.5. So I have no option but to keep a seperate python2.5 in some different directory and have ve use it. would just like to know how I can get ve to use that installation and not the one on my system by default. happy hacking. Krishnakant. -- http://mail.python.org/mailman/listinfo/python-list
Re: Which python version do I use with virtualenv?
Krishnakant wrote: You are confusing virtualenv with a custom-build python. You can of course use VE with a custom-build python, but then there isn't as much use for it, as you then have a distinct python-instance already - unless you are going to share it amongst projects, which then leads to the question why you don't use VE *without* the custom-build python. Well, Turbogears works perfectly with python2.5, although there are people who use it with 2.6 as well. I have to keep 2.6 because my screen reader orca giave me some problem with 2.5. So I have no option but to keep a seperate python2.5 in some different directory and have ve use it. would just like to know how I can get ve to use that installation and not the one on my system by default. By *using* it? /opt/my_python/bin/python2.5 and you're done. If you e.g. download ez_setup.py execute that through your custom python, you'll end up with an easy_install in /opt/my_python/bin, which you then can use to e.g. install VE. Diez -- http://mail.python.org/mailman/listinfo/python-list
tkinter and widget placement after resizing
Hello, I've got a fairly simple GUI that places pmw.EntryFields into a window starting in the upper left corner. When the first column is filled with these widgets I'd like to start a new column and continue placement, and so on. It is working now with the grid manager if I explicitly set the max number of widgets per column, but if I resize the main window there is wasted space as the number of widgets per column is fixed. I'd like to find a design that could change the number of widgets per column when the window is resized. Any suggestions? i.e. start out with a window like this: [1][4][7] [2][5][8] [3][6][9] make the main window larger and end up with this: [1][6] [2][7] [3][8] [4][9] [5] -- http://mail.python.org/mailman/listinfo/python-list
Re: Self function
Scheme is arguably the programming language with the most support for recursion, including the most complete support for tail-call optimization, constructs like letrec to define collections of multiply-recursive functions (which get used very frequently -- by no means is it an uncommon situation, as you suggest in your initial post), and hardly any iterative loops. Yet -- scheme does not provide out-of-the-box support for your proposed let-a-function-implicitly- refer-to-itself idea. This suggests that the idea itself runs counter to more important aspects of a programming language. In the special case of a self-recursive function, you would like re- naming to just work. Out of morbid curiosity, I am compelled to ask... why do you expect that re-naming anything --- a function, a class, a module, a variable, anything --- in just one place but not all the others should ever, under any circumstances, just work ? -- http://mail.python.org/mailman/listinfo/python-list
Unable to build libpython2.5.so on OS X 10.4
Hi all. I'm trying to build some internal code that needs to link against libpython2.5.so on a OS X 10.4 (Tiger) machine. It seems that no matter what combination of options and environment variables I give to the configure script from python 2.5.1, all I get is the libpython2.5.a (the static library). I've googled the problem and searched the comp.lang.python archives, but I have been unable to find anything that works. Is there some special magic I have to invoke to do this? I've not done any Mac development, so there may be some obvious point I am missing. The Python README file and configure script comments are not getting me very far. TIA, Eric Winter NASA GSFC Fermi Gamma-Ray Space Telescope Science Support Center -- http://mail.python.org/mailman/listinfo/python-list
P2P text chat engine
If you have the source code of a p2p text chat engine please send to me -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple way of handling errors
On 2009-05-07 01:01:57 -0700, Peter Otten __pete...@web.de said: TomF wrote: As a relative newcomer to Python, I like it a lot but I'm dismayed at the difficulty of handling simple errors. In Perl if you want to anticipate a file-not-found error you can simply do: open($file) or die(open($file): $!); and you get an intelligible error message. In Python, to get the same thing it appears you need at least: try: f=open(file) except IOError, err: print open(%s): got %s % (file, err.strerror) exit(-1) Is there a simpler interface or idiom for handling such errors? I appreciate that Python's exception handling is much more sophisticated but often I don't need it. -Tom While you are making the transition you could write from perl_idioms import open_or_die f = open_or_die(does-not-exist) with the perl_idioms module looking like import sys def open_or_die(*args): try: return open(*args) except IOError, e: sys.exit(e) Peter Thanks. Rolling my own error module for common errors may be the best way to go. -Tom -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to build libpython2.5.so on OS X 10.4
Eric Winter schrieb: Hi all. I'm trying to build some internal code that needs to link against libpython2.5.so on a OS X 10.4 (Tiger) machine. It seems that no matter what combination of options and environment variables I give to the configure script from python 2.5.1, all I get is the libpython2.5.a (the static library). I've googled the problem and searched the comp.lang.python archives, but I have been unable to find anything that works. Is there some special magic I have to invoke to do this? I've not done any Mac development, so there may be some obvious point I am missing. The Python README file and configure script comments are not getting me very far. You have to start with a clean plate and use the --enable-shared option to configure: make distclean ./configure --enable-unicode=ucs4 --enable-shared make That will give you a libpython2.5.dylib. The suffix for shared libraries is .dylib on On Mac OS X, not .so! Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: SQL and CSV
On May 5, 8:27 pm, Tim Golden m...@timgolden.me.uk wrote: Nick wrote: Part of the problem is that the 'selection' needs to be in a config file. I can put the if row['status'] != 'Cancelled': return True into a config, read it and eval it, but its not quite as clean as ansql route. Still not clear what the restriction is. If you were writingSQLyou'd have to read *something* from your config file, unless you're suggesting that the config file is in fact aSQLfile. Which is one way of doing it, but then you might just as well have your config file as a Python file and import it. Have I missed the point somewhere here? Can you give an example -- even a fictional one -- of what you couldn't do using, say, the example I gave earlier? TJG Solution found. In the end I used SQLite to read from a csv file, and now I can query the CSV file. The file is read using the csv module First create a function def fraction(p, denom): num, frac = p.split ('-') return float (num) + float (frac) / denom for use within queries. Now build the class. self.filename = filename self.dialect = dialect self.query = query reader = csv.reader (open (filename, 'r')) self.connection = sqlite.connect(:memory:) self.connection.create_function(fraction, 2, fraction) # Adds in function self.cursor = self.connection.cursor() first = True for row in reader: if first: headers = [] for r in row: n = r.strip().replace (' ', '_').replace ('-','_') headers.append (n) command = 'create table csv (%s)' % ','.join (headers) self.cursor.execute (command) first = False else: command = 'insert into csv values (%s)' % ','.join (row) self.cursor.execute (command) and then I can use this self.cursor.execute (self.query) rows = self.cursor.fetchall() headers = [] for r in self.cursor.description: headers.append (r[0]) results = Results.Results (headers, self.name, {}) i = 0 for row in rows: results.add (row, i) i = i + 1 return results to query the results. Results.Results is one of my classes that's reused in lots of places. The query then looks somethign like this select Client_Reference_Number as TrdNbr, Asset_Number as ISIN, Quantity as Qty, status from csv where status in (CANCELLED) union select Client_Reference_Number as TrdNbr, Asset_Number as ISIN, Quantity as Qty, status from csv where status not in (CANCELLED) All incredibly neat and the first time I've used SQLite. nick -- http://mail.python.org/mailman/listinfo/python-list
Re: [RELEASED] Python 3.1 beta 1
CTO wrote: ... If OrderedDict winds up being backported, will you include it in 2.x? I see it in the 2.7 sources. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to build libpython2.5.so on OS X 10.4
Christian, Thanks for the response. I knew about the .dylib suffix, but that's not being built either, even when I supply the --enable-shared option to configure. I also tried the --enable-unicode configure option, but no joy. Might there be some additional OS X package I need to install to get this to work? Thanks, Eric On May 7, 11:45 am, Christian Heimes li...@cheimes.de wrote: Eric Winter schrieb: Hi all. I'm trying to build some internal code that needs to link against libpython2.5.so on a OS X 10.4 (Tiger) machine. It seems that no matter what combination of options and environment variables I give to the configure script from python 2.5.1, all I get is the libpython2.5.a (the static library). I've googled the problem and searched the comp.lang.python archives, but I have been unable to find anything that works. Is there some special magic I have to invoke to do this? I've not done any Mac development, so there may be some obvious point I am missing. The Python README file and configure script comments are not getting me very far. You have to start with a clean plate and use the --enable-shared option to configure: make distclean ./configure --enable-unicode=ucs4 --enable-shared make That will give you a libpython2.5.dylib. The suffix for shared libraries is .dylib on On Mac OS X, not .so! Christian -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.1 beta 1
I appreciate the tables Infinite Iterators and Iterators terminating on the shortest input sequence at the top of the itertools module, they are quite handy. I'd like to see similar summary tables at the top of other docs pages too (such pages are often quite long), for example the collections docs page. collections.Counter and collections.OrderedDict: very nice and useful. Is the order inside OrderedDict kept with a double linked list of the items? Counter.most_common([n]): a good idea. If I need a dictionary that is both ordered and has a default too I can't combine their qualities (but I can use the __missing__(key) hook). Equality tests between OrderedDict objects are order-sensitive and are implemented as list(od1.items())==list(od2.items()). Equality tests between OrderedDict objects and other Mapping objects are order-insensitive very nice idea. The OrderedDict constructor and update() method both accept keyword arguments, but their order is lost because Python's function call semantics pass-in keyword arguments using a regular unordered dictionary. This is unfortunate :-( Well, I'd like function call semantics pass-in keyword arguments to use OrderedDicts then... :-) Several mathematical operations are provided for combining Counter objects to produce multisets Very nice. itertools.count(): when increments are non-integer I hope the results are computed with a multiplication instead an interated sum, to increase precision. Issue 4688 and the work by Antoine Pitrou: interesting GC optimization. The performance difference of the BinaryTrees benchmark is big. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to build libpython2.5.so on OS X 10.4
In article fde3b1d5-8a52-4ff1-9093-9ed470b4f...@g20g2000vba.googlegroups.com, Eric Winter elwin...@verizon.net wrote: Hi all. I'm trying to build some internal code that needs to link against libpython2.5.so on a OS X 10.4 (Tiger) machine. It seems that no matter what combination of options and environment variables I give to the configure script from python 2.5.1, all I get is the libpython2.5.a (the static library). I've googled the problem and searched the comp.lang.python archives, but I have been unable to find anything that works. Perhaps I misunderstand, but if you are trying to build a C extension for an existing Python 2.5 installation, using Distutils from that installation should take care of everything for you. Is there a setup.py file by any chance? Are you using a standard python installation (i.e. python.org installer for instance)? More details might help. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
What would YOU like to see in a txt to html converter?
As you might have mentioned I'm just working on a txt to html converter called thc. This project is intended for me to learn Python and now pyQT4 to which I changed a few days ago (started with Tkinter). I have implemented the following features so far: - Giving a title for the html - Choose whether it's Transitional or Strict Doctype - Select a background color - Show the converted file with the standard browser - Working on a font size slider I don't really know if this is of any use for anybody but it's just a fun project by a beginner :-) Now I'd like to know what kind of features you'd like to see in version 0.3 of thc!? Please post them... Have fun! Listick http://www.lictick.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging exceptions to a file
So far so good, but I'd like to record (possibly unhandled) exceptions in the logfile. * Do I need to explicitly trap every single exception ? * In that case, won't I get 2 log messages on the console (as illustrated in the code below: Check out sys.excepthook, something vaguely like: import sys def handle_exceptions(exctype, value, traceback): logging.exception(An unhandled exception was detected.) sys.excepthook = handle_exceptions -- http://mail.python.org/mailman/listinfo/python-list
Re: Self function
Luis Alberto Zarrabeitia Gomez ky...@uh.cu writes: A bit offtopic: a while ago I think I saw a recipe for a decorator that, via bytecode hacks, would bind otherwise global names to the local namespace of the function. Can anyone remember it/point me to it? An @bind decorator that would 'localize' all the global names, including the still unexistent but already know function name, would guarantee that at least recursion calls the same function instead of whatever happens to be bound to their name at runtime. If it wasn't a hack, anyway. I remember a discussion on python-ideas, and I wrote this decorator at the time: def new_closure(vals): args = ','.join('x%i' % i for i in range(len(vals))) f = eval(lambda %s:lambda:(%s) % (args, args)) return f(*vals).func_closure def localize(f): f_globals = dict((n, f.func_globals[n]) for n in f.func_code.co_names) f_closure = ( f.func_closure and new_closure([c.cell_contents for c in f.func_closure]) ) return type(f)(f.func_code, f_globals, f.func_name, f.func_defaults, f_closure) Unfortunately it fails for recursive functions: @localize ... def fac(n): ... return 1 if n = 1 else n*fac(n - 1) ... Traceback (most recent call last): File stdin, line 1, in module File localize.py, line 7, in localize f_globals = dict((n, f.func_globals[n]) for n in f.func_code.co_names) File localize.py, line 7, in genexpr f_globals = dict((n, f.func_globals[n]) for n in f.func_code.co_names) KeyError: 'fac' It can be fixed, but not very easily precisely because the function is recursive. I've hacked a quick way to do it below. def reclocalize(f): def wrapper(*args, **kwargs): return recf(*args, **kwargs) def getglobal(name): return wrapper if name == f.__name__ else f.func_globals[name] f_globals = dict((n, getglobal(n)) for n in f.func_code.co_names) f_closure = ( f.func_closure and new_closure([c.cell_contents for c in f.func_closure]) ) recf = type(f)(f.func_code, f_globals, f.func_name, f.func_defaults, f_closure) return wrapper Now it works as intended: @reclocalize ... def fac(n): ... return 1 if n = 1 else n*fac(n - 1) ... fac(10) 3628800 foo = fac del fac foo(10) 3628800 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: Logging exceptions to a file
On May 7, 1:19 pm, Pierre GM pierregmc...@gmail.com wrote: On May 7, 5:32 am, Lie Ryan lie.1...@gmail.com wrote: Pierre GM wrote: All, I need to log messages to both the console and a given file. I use the following code (on Python 2.5) import logging # logging.basicConfig(level=logging.DEBUG,) logfile = logging.FileHandler('log.log') logfile.setLevel(level=logging.INFO) logging.getLogger('').addHandler(logfile) # mylogger = logging.getLogger('mylogger') # mylogger.info(an info message) So far so good, but I'd like to record (possibly unhandled) exceptions in the logfile. * Do I need to explicitly trap every single exception ? * In that case, won't I get 2 log messages on the console (as illustrated in the code below: try: 1/0 except ZeroDivisionError: mylogger.exception(:() raise Any comments/idea welcomed Cheers. Although it is usually not recommended to use a catch-all except, this is the case where it might be useful. JUST DON'T FORGET TO RE-RAISE THE EXCEPTION. if __name__ == '__main__': try: main(): except Exception, e: # log('Unhandled Exception', e) raise OK for a simple script, but the (unhandled) exceptions need to be caught at the module level. Any idea? Override sys.excepthook. http://docs.python.org/library/sys.html#sys.excepthook -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to build libpython2.5.so on OS X 10.4
Hi Ned. The Python module I am building is actually the Python module for ROOT, a large package from CERN. However, the problem arises before that code enters the picture, when I am building Python itself. All I want to do is create libpython2.5.dylib, or its equivalent, and I can't seem to make that happen on Tiger. Thanks, Eric On May 7, 12:41 pm, Ned Deily n...@acm.org wrote: In article fde3b1d5-8a52-4ff1-9093-9ed470b4f...@g20g2000vba.googlegroups.com, Eric Winter elwin...@verizon.net wrote: Hi all. I'm trying to build some internal code that needs to link against libpython2.5.so on a OS X 10.4 (Tiger) machine. It seems that no matter what combination of options and environment variables I give to the configure script from python 2.5.1, all I get is the libpython2.5.a (the static library). I've googled the problem and searched the comp.lang.python archives, but I have been unable to find anything that works. Perhaps I misunderstand, but if you are trying to build a C extension for an existing Python 2.5 installation, using Distutils from that installation should take care of everything for you. Is there a setup.py file by any chance? Are you using a standard python installation (i.e. python.org installer for instance)? More details might help. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Wing vs Netbeans IDE?
Dear Colleagues, I have been using NetBeans for a month or so now and am reasonably happy with it. I'm considering other options, and ran across Wing. I'm interested in opinions about NetBeans and Wing as IDE for Python. Thanks, Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: list comprehension question
Steven D'Aprano ste...@remove.this.cybersource.com.au writes: On Wed, 06 May 2009 09:48:51 -0400, J Kenneth King wrote: Emile van Sebille em...@fenx.com writes: On 5/5/2009 9:15 AM J Kenneth King said... List comprehensions can make a reader of your code apprehensive because it can read like a run-on sentence and thus be difficult to parse. The Python documentation discourages their use and I believe for good reason. Can you provide a link for this? I'd like to see specifically what's being discouraged, as I'd be surprised to find routine usage frowned upon. Emile http://docs.python.org/tutorial/datastructures.html#nested-list- comprehensions If you’ve got the stomach for it, list comprehensions can be nested. They are a powerful tool but – like all powerful tools – they need to be used carefully, if at all. How does this discourage the use of list comprehensions? At most, it warns that complicated list comps are tricky. Complicated *anything* are tricky. They are tricky and need to be used carefully, *if at all*. IMO this means that if there's a way to do it without a nested list comprehension, then that solution should be preferred. and In real world, you should prefer builtin functions to complex flow statements. That's ridiculous. The example given is a special case. That's like saying Loops are hard, so in the real world, if you want a loop, find a builtin function that does what you want instead. What's the builtin function we're supposed to prefer over a complex flow statement like this? It's not ridiculous and says nothing of the sort. You're jumping to conclusions. If you have a problem with it, I suggest you complain to the Python documentation people. I don't make this stuff up. Just look at many of the example solutions provided in this thread to the OP's problem. The examples in the link I provided are also good as are ones provided in the itertools documentation. Keep in mind that nested comprehensions are still available because they do have a use case that justifies their existence. However, I think the Python documentation warns against their use because people might rely on them for problems where they aren't necessary and since they are difficult to read... it can lead to difficult to read code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wing vs Netbeans IDE?
I've tried Wing but not NetBeans. I would personally recommend Eclipse with the PyDev plugin. I prefer it to Wing by *far* and if you prefer Eclipse to NetBeans for Java then it might be worth your while checking it out. If you take a few minutes to learn a few of the shortcuts in Eclipse you can really cut down the time to do a lot of administrative/organisational tasks. On Windows I remember Eclipse + Pydev being a bit of a memory hog but on OS X and Linux it works smoothly. On Thu, May 7, 2009 at 6:24 PM, Lawrence Hanser lhan...@gmail.com wrote: Dear Colleagues, I have been using NetBeans for a month or so now and am reasonably happy with it. I'm considering other options, and ran across Wing. I'm interested in opinions about NetBeans and Wing as IDE for Python. Thanks, Larry -- http://mail.python.org/mailman/listinfo/python-list -- http://www.unprotectedhex.com http://www.smashthestack.org -- http://mail.python.org/mailman/listinfo/python-list
Re: What would YOU like to see in a txt to html converter?
As you might have mentioned I'm just working on a txt to html converter called thc. This project is intended for me to learn Python and now pyQT4 to which I changed a few days ago (started with Tkinter). I have implemented the following features so far: - Giving a title for the html - Choose whether it's Transitional or Strict Doctype Don't give this choice. What benefit does this give the user? - Select a background color - Show the converted file with the standard browser That should probably be valid [X]HTML and be done with it. - Working on a font size slider This should be a browser feature, not a page feature. Use the default sizes of the HTML elements, and let the UA override those defaults as the user sees fit ot configure it. If you think that there should be a font size slider, then file a feature request at the bug tracker of your favourite browser. I don't really know if this is of any use for anybody but it's just a fun project by a beginner :-) Now I'd like to know what kind of features you'd like to see in version 0.3 of thc!? You should probably convert the text to UTF-8 and make sure to declare that with a meta tag. You might want to look at markdown for a nice way to have hyperlink support. Lists conversion, like these: * item one * item two * item three 1. item one 2. item two 3. item three -- Dotan Cohen http://what-is-what.com http://gibberish.co.il -- http://mail.python.org/mailman/listinfo/python-list
Re: Unable to build libpython2.5.so on OS X 10.4
In article 0e05eca2-b460-4e01-aa54-cc1055f51...@q14g2000vbn.googlegroups.com, elwinter elwin...@verizon.net wrote: The Python module I am building is actually the Python module for ROOT, a large package from CERN. However, the problem arises before that code enters the picture, when I am building Python itself. All I want to do is create libpython2.5.dylib, or its equivalent, and I can't seem to make that happen on Tiger. Any chance you can use the python.org installer for 2.5.4? Or the Macports version? They both are supported on Tiger. http://www.python.org/download/releases/2.5.4/ http://www.macports.org/ Again, I may be missing something but libpythonx.x by itself is not very useful, i.e. it's not your usual standalone lib. You'll almost certainly need the whole python installation. There are a number of ways to build python on OS X (google will find them or ask on the Mac python sig) but, unless you have some special requirement, use an existing python installation and build the ROOT Python module with that. -- Ned Deily, n...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
RE: Wing vs Netbeans IDE?
I'd love to see an updated shootout between these three, as I cannot for the life of me seem to be able to settle down with one of them. Things I don't like: Wing's lack of integrated mercurial/svn support. The clunkiness and scattered plugin approach of Eclipse (the latter is relavent when starting work on new machines all the time). Netbeans project browser doesn't show class or functions inside the files. Netbeans autocompletion doesn't seem immediately impressive. But... Wing has mentioned future support of svn,git,bazaar,mercurial,etc in the future. QT designer is integrated with Eclipse. So is Photran, which is convenient for some of science types. It seems that there are reasons to be optimistic about the future of netbeans. It seems to be well put together so far, but the least mature. I know that this comes up time and again, but I think a feature-specific debate over these might be worth revisiting for a lot of newcomers. Ben Racine -- http://mail.python.org/mailman/listinfo/python-list
Updating an Imported Function
Hello, I'm new to Python and have what is probably a very basic question. I am writing a helloWorld() function within a file called helloWorld.py: def helloWorld(): print 'hi' Now, I can import and run this function: import helloWorld helloWorld.helloWorld() Which will print 'hi' as expected. Now, I'd like to update this function in my text editor so it is: def helloWorld(): print 'hello world' Without having to exit my Python interpreter, how can I import this revised function? If I do the import again: import helloWorld And run helloWorld.helloWorld() it will still print out just 'hi'. I've tried deleting this function (a weird concept to me as I come from a C++ background) using del helloWorld and than importing again, but the function will still print out just 'hi'. Can this be done? How so? Thanks for any and all help. Cheers, Donovan -- http://mail.python.org/mailman/listinfo/python-list
Re: What would YOU like to see in a txt to html converter?
Dotan Cohen wrote: As you might have mentioned I'm just working on a txt to html converter called thc. This project is intended for me to learn Python and now pyQT4 to which I changed a few days ago (started with Tkinter). I have implemented the following features so far: - Giving a title for the html - Choose whether it's Transitional or Strict Doctype Don't give this choice. What benefit does this give the user? - Select a background color - Show the converted file with the standard browser That should probably be valid [X]HTML and be done with it. - Working on a font size slider This should be a browser feature, not a page feature. Use the default sizes of the HTML elements, and let the UA override those defaults as the user sees fit ot configure it. If you think that there should be a font size slider, then file a feature request at the bug tracker of your favourite browser. I don't really know if this is of any use for anybody but it's just a fun project by a beginner :-) Now I'd like to know what kind of features you'd like to see in version 0.3 of thc!? You should probably convert the text to UTF-8 and make sure to declare that with a meta tag. You might want to look at markdown for a nice way to have hyperlink support. Lists conversion, like these: * item one * item two * item three 1. item one 2. item two 3. item three Actually I would like to see a good HTML to txt or odt converter. Perhaps someone you know has the time and inclination to make one. In Unix, grep is a fantastic search tool. Since HTML's today seem to be one page one file, trying to search a help collection for a phrase is useless in the practical sense. I mean no offense to your effort. There are many who wish a good version of such a converter. It's just that I personally wish HTMLs used for Help and Documentation were banned from the universe. To me, a well written, easily understood, no frills, fully grep'able text file that covers the subject well is a truly fantastic thing to be well cherished. Steve -- http://mail.python.org/mailman/listinfo/python-list
Downloading most recently modified files
I am trying to code a script that will allow me to go to ftp site and download files based on most recently modified file (date, time). I am brand new to programming. Any and all help is appreciated. -- View this message in context: http://www.nabble.com/Downloading-most-recently-modified-files-tp23432457p23432457.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: What would YOU like to see in a txt to html converter?
Florian == Florian Wollenschein florian.wollensch...@fernuni-hagen.de writes: Florian As you might have mentioned I'm just working on a txt to html converter called Florian thc. This project is intended for me to learn Python and now pyQT4 to which I Florian changed a few days ago (started with Tkinter). Florian I have implemented the following features so far: Florian - Giving a title for the html Florian - Choose whether it's Transitional or Strict Doctype Florian - Select a background color Florian - Show the converted file with the standard browser Florian - Working on a font size slider Florian I don't really know if this is of any use for anybody but it's just a fun Florian project by a beginner :-) Florian Now I'd like to know what kind of features you'd like to see in version 0.3 of Florian thc!? Florian Please post them... Florian Have fun! Florian Listick Florian http://www.lictick.org You could learn something from emacs-muse. That plugin can help emacs to convert txt to html, tex, pdf, docbook and some other document format. In emacs-muse, the title and subtitle is defined like this: *emphasis* **strong emphasis** ***very strong emphasis*** _underlined_ =verbatim and monospace= emacs-muse : http://mwolson.org/projects/EmacsMuse.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Updating an Imported Function
Donovan Parks schrieb: Hello, I'm new to Python and have what is probably a very basic question. I am writing a helloWorld() function within a file called helloWorld.py: def helloWorld(): print 'hi' Now, I can import and run this function: import helloWorld helloWorld.helloWorld() Which will print 'hi' as expected. Now, I'd like to update this function in my text editor so it is: def helloWorld(): print 'hello world' Without having to exit my Python interpreter, how can I import this revised function? If I do the import again: import helloWorld And run helloWorld.helloWorld() it will still print out just 'hi'. I've tried deleting this function (a weird concept to me as I come from a C++ background) using del helloWorld and than importing again, but the function will still print out just 'hi'. Can this be done? How so? reload(helloWorld) But there are some caveats, and IMHO reloading isn't worth the trouble - it is *so* easy to write a second script, test.py or whatever, that you just call from a shell. And this has the added benefit that you can create even somewhat more elaborate toy-code. If one wants to play around with objects created, either do python -i test.py or try to use pdb, the python debugger, through import pdb; pdb.set_trace() to get an interactive prompt at whatever point you want. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Threading and GIL
On May 7, 12:20 am, googler.1.webmas...@spamgourmet.com wrote: thats the reason why its not working. Imagine the end() method of the thread object is called so the C++ Function is opened where the code for this method is in. You're going to have to post some code if you want better help; this description is unintelligible. I don't know what you mean by end() method, nor whether it's a Python method or C++ method, nor what exactly you mean by thread object (C++ or Python object?) or C++ Function. At a line the Code ...-End() is called which waits that the C++ Thread class is finished. BUT here is the problem: In the Method of the C++ class which is in threaded mode can't run because its still waiting that the GIL is released by the thread which executed the -End() command. So the app has a deadlock when it arrives at -End() and PyGILState_Ensure function. So you have to release the GIL before calling End(). Just surround End () by Py_BEGIN_ALLOW_THREADS and Py_END_ALLOW_THREADS. (Presumably you know the thread state when you call End(); if you don't then surround the calls to Py_{BEGIN,END}_ALLOW_THREADS with calls to PyGILState_{Ensure,Release}. Yes, that means you acquire the GIL just so you can be sure that you've released it. I know of no other way to be sure you don't have the GIL.) If you are trying to kill a different thread, and I can't quite tell if that's what you're doing, then be aware that it is very tricky to do right and most think it to be a bad idea. If you don't allow the thread you're killing to clean up it can deadlock, and even if you do, you have to be careful to clean up properly and you have to be constantly on guard for what might happen in a thread is killed in the middle of something. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Newcomer to Python tutorial question
I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list
Get Into The World Of YOUSUF JUSANI
Get The Most Valuable and Best For Investment Properties IN ASIA, !! Real Estate Builders.. Real Estate Dealer Buy, Sell REAL EASTAE IN GULF ,DUBAI AND AUSTRIA FOR MORE INFO http://www.yousufjusani.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
On Thu, May 7, 2009 at 11:35 AM, Alan Cameron alan.came...@iname.com wrote I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? Because it's *not a sequence* at all, it's a set. Sets are unordered and contain no duplicate items, hence why the output ordering is arbitrary and only the unique subset of original elements is present. Further info: http://docs.python.org/3.0/library/stdtypes.html#set-types-set-frozenset Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Alan Cameron alan.came...@iname.com writes: I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? A set is an unordered container, but due to the nature of an object representation (which is a sequence of characters), its representation has to list the elements in a certain order. However, this order is not significant. -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
Re: What would YOU like to see in a txt to html converter?
Will Wang wrote: Florian == Florian Wollenschein florian.wollensch...@fernuni-hagen.de writes: Florian As you might have mentioned I'm just working on a txt to html converter called Florian thc. This project is intended for me to learn Python and now pyQT4 to which I Florian changed a few days ago (started with Tkinter). Florian I have implemented the following features so far: Florian - Giving a title for the html Florian - Choose whether it's Transitional or Strict Doctype Florian - Select a background color Florian - Show the converted file with the standard browser Florian - Working on a font size slider Florian I don't really know if this is of any use for anybody but it's just a fun Florian project by a beginner :-) Florian Now I'd like to know what kind of features you'd like to see in version 0.3 of Florian thc!? Florian Please post them... Florian Have fun! Florian Listick Florian http://www.lictick.org You could learn something from emacs-muse. That plugin can help emacs to convert txt to html, tex, pdf, docbook and some other document format. In emacs-muse, the title and subtitle is defined like this: *emphasis* **strong emphasis** ***very strong emphasis*** _underlined_ =verbatim and monospace= emacs-muse : http://mwolson.org/projects/EmacsMuse.html Thank you for this information. I already thought of using dots or asterisks or whatever to let the user format the text instead of using html tags (this would be quite paradox ;-) Please keep on posting ideas... Thanks again, Listick http://www.listick.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Alan Cameron wrote: I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? A set is not ordered and eliminates duplicate elements. So the output is random in terms of the order and only shows each single item once... Correct me if I'm wrong :-) Listick http://www.listick.org -- http://mail.python.org/mailman/listinfo/python-list
Re: What would YOU like to see in a txt to html converter?
Florian Wollenschein wrote: As you might have mentioned I'm just working on a txt to html converter called thc. This project is intended for me to learn Python and now pyQT4 to which I changed a few days ago (started with Tkinter). I have implemented the following features so far: - Giving a title for the html - Choose whether it's Transitional or Strict Doctype - Select a background color - Show the converted file with the standard browser - Working on a font size slider I don't really know if this is of any use for anybody but it's just a fun project by a beginner :-) Now I'd like to know what kind of features you'd like to see in version 0.3 of thc!? Please post them... Have fun! Listick http://www.lictick.org I would first think about your personal requirements / use cases. What kind of texts do you want to convert? I think there's already quite some text to html converters, which you could take as inspiration. Most of them were written for a specific purpose though and started from text files with some 'formatting syntax' Exanples: man2html converts man pages to html pod2html covnerts perl online documentation to html There's also converters from certain wiki formats to html. There's also source code formatters for certain programming languages or log file to html converters which color certain message types If it is just for plain text with no special formattings, then you need probably only: - escape all characters, which have to be escap for html. (but there is probably already a function for it. ) - seperate paragraphs (at double new lines or at single new lines. This could be an option) - additionally you could allow to specify a html prefix (before the converted text) and a html post fix after the converted text. - I would handle settings lik color / font size etc with style sheets and not within the generated html. If you want you could autgenerate style sheets from some function arguments. They could contain Font color / background color / font formatting . . . . - you could add a configuration, that automatically tags certain words with certain tags, to allow simle keyword hihglighting. It all depends on your use case. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Alan Cameron alan.came...@iname.com wrote in message news:hrfml.50224$tb.4...@newsfe07.ams2... I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? Thanks to all who replied. I assume therefore that the order in which the items of the set are printed could vary each time it is printed? -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Alan Cameron wrote: I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? As already said by others, the order of items in a set is not part of the concept of a set. You can even have sets with equal contents that display differently: Python 3.0.1+ (r301:69556, Apr 15 2009, 17:25:52) [GCC 4.3.3] on linux2 Type help, copyright, credits or license for more information. a = {'orange', 'banana', 'apple', 'orange', 'pear', 'apple'} b = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} a == b True repr(a) == repr(b) False a {'orange', 'pear', 'apple', 'banana'} b {'orange', 'pear', 'banana', 'apple'} Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Could this expression parser be more 'Pythonic'?
Hi John, Thanks for the tips, I will check them out. --Amr -- http://mail.python.org/mailman/listinfo/python-list
subprocess.Popen howto?
Hi, I have problems understanding the subprocess.Popen object. I have a iterative calculation in a process running and I want to pipe the output (stdout) from this calculation to a Python script. Let me include a simple code that simulates the calculating process: /* This code simulates a big iterative calculation */ #include stdio.h #include math.h int main() { float val[2] = { M_PI, M_E }; int i; for ( i = 0; i 2 i++) { sleep( 15 ); /* It's a hard calculation. It take 15 seconds */ printf(Value: %5.6f\n, val[i] ); fflush( stdout ); } return 0; } let's compile this to mycalc: gcc -o mycalc calc.c ... (untested code) In C I have this code which starts the mycalc process and handles the output from it: #include stdio.h #include assert.h #define BUF_SIZE 256 int main() { FILE *pip; char line[BUF_SIZE]; pip = popen(mycalc, r); assert( pip != NULL ); while ( fgets( line, BUF_SIZE, pip )) { printf( Hello; I got: %s \n, line ); fflush( stdout ); } pclose( pip ); return 0; } How can I make such while-loop in Python? I assume I should use subprocess.Popen(), but I can't figure out how? -Øystein --- The information contained in this message may be CONFIDENTIAL and is intended for the addressee only. Any unauthorised use, dissemination of the information or copying of this message is prohibited. If you are not the addressee, please notify the sender immediately by return e-mail and delete this message. Thank you. -- http://mail.python.org/mailman/listinfo/python-list
[RELEASED] Python 3.1 beta 1
On behalf of the Python development team, I'm thrilled to announce the first and only beta release of Python 3.1. Python 3.1 focuses on the stabilization and optimization of features and changes Python 3.0 introduced. For example, the new I/O system has been rewritten in C for speed. File system APIs that use unicode strings now handle paths with undecodable bytes in them. [1] Other features include an ordered dictionary implementation and support for ttk Tile in Tkinter. For a more extensive list of changes in 3.1, see http://doc.python.org/dev/py3k/whatsnew/3.1.html or Misc/NEWS in the Python distribution. Please note that this is a beta release, and as such is not suitable for production environments. We continue to strive for a high degree of quality, but there are still some known problems and the feature sets have not been finalized. This beta is being released to solicit feedback and hopefully discover bugs, as well as allowing you to determine how changes in 3.1 might impact you. If you find things broken or incorrect, please submit a bug report at http://bugs.python.org For more information and downloadable distributions, see the Python 3.1 website: http://www.python.org/download/releases/3.1/ See PEP 375 for release schedule details: http://www.python.org/dev/peps/pep-0375/ Enjoy, -- Benjamin Benjamin Peterson benjamin at python.org Release Manager (on behalf of the entire python-dev team and 3.1's contributors) -- http://mail.python.org/mailman/listinfo/python-list
Re: Simple way of handling errors
Steven D'Aprano wrote: On Wed, 06 May 2009 20:21:38 -0700, TomF wrote: The only reason you would bother going to the time and effort of catching the error, printing your own error message, and then exiting, is if you explicitly want to hide the traceback from the user. Well, to me, exposing the user to such raw backtraces is unprofessional, which is why I try to catch user-caused errors. But I suppose I have an answer to my question. That depends on your audience. Not every program is written to be used for a technical incompetent audience. Some users actually *want* to see the errors. But certainly there are large classes of applications where you do want to suppress the traceback. That's why I said if you explicitly want to hide the traceback from the user rather than don't do this. The idiom I use is to wrap the *entire* application in a single try...except block, and then put all your user-friendly error handling in one place, instead of scattered over the entire application: try: main(sys.argv[1:]) except KeyboardInterrupt, SystemExit: That should be: except (KeyboardInterrupt, SystemExit): ;-D raise except Exception, e: log(e) print sys.stderr, str(e) sys.exit(1) Hope this helps. -- -- http://mail.python.org/mailman/listinfo/python-list
Re: hex(dummy)[2:] - issue...
Tim Chase wrote: I need some advice :-) I'm using hex(dummy)[2:] to represent a color in hexadecimal format for the bgcolor in an html file. dummy is the color value in RGB of course... Now, if there's an R, G or B value of zero, this command only prints one single 0 instead of two. What's wrong with the code? You can try PLACES = 2 # 6? hex(dummy)[2:].zfill(PLACES) Alternatively, you can output decimal numbers in HTML/CSS with rgb(r, g, b) such as style=rgb(255,0,0) However, I recommend doing this via CSS unless you have a strong reason to sully your HTML with style information. -tkc hey tkc, I used your first alternative. This did it! Thanks a lot. I think I will write the style stuff into a .css file in the next few days but until then I'm just working on get my program to work... Listick http://www.listick.org -- http://mail.python.org/mailman/listinfo/python-list
Re: P2P text chat engine
Navanjo schrieb: If you have the source code of a p2p text chat engine please send to me I found that a pot of gold under my bed. Care to give me your address so that I can send it to you? SCNR, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Self function
Francis Carr: I don't know who are you talking to, but I can give you few answers anyway. collections of multiply-recursive functions (which get used very frequently -- by no means is it an uncommon situation, as you suggest in your initial post), They may be frequent in Scheme (because it's often used as an almost pure language), but in Python code they are quite rare. I have used two mutual recursive functions only once in non-toy Python code in two or more years. Yet -- scheme does not provide out-of-the-box support for your proposed let-a-function-implicitly- refer-to-itself idea. This suggests that the idea itself runs counter to more important aspects of a programming language. I see. It's not a very implicit thing, because you have to call a function anyway, it's just it has a fixed name, like __func__. I think it doesn't runs counter to Python D languages (I have asked for a similar feature in D2 too, and the designers seem to have accepted the idea, already suggested there by another person in the past). Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
On Thu, May 7, 2009 at 11:58 AM, Alan Cameron alan.came...@iname.com wrote: Alan Cameron alan.came...@iname.com wrote in message news:hrfml.50224$tb.4...@newsfe07.ams2... I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? Thanks to all who replied. I assume therefore that the order in which the items of the set are printed could vary each time it is printed? Due to the underlying dict-based implementation, the order will stay the same until you modify the set (i.e. add or remove an element), at which point it may change; it's basically the same behavior as with printing a dict. So this will always print the same thing twice: print basket print basket Whereas this might not: print basket #modify the set basket.discard(banana) basket.add(banana) print basket Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: What would YOU like to see in a txt to html converter?
Florian Wollenschein wrote: Will Wang wrote: *emphasis* **strong emphasis** ***very strong emphasis*** _underlined_ =verbatim and monospace= emacs-muse : http://mwolson.org/projects/EmacsMuse.html Thank you for this information. I already thought of using dots or asterisks or whatever to let the user format the text instead of using html tags (this would be quite paradox ;-) First thing I'd look at is actually docutils' RestructuredText (ReST). Stefan -- http://mail.python.org/mailman/listinfo/python-list
RE: Wing vs Netbeans IDE?
On Thu, 2009-05-07 at 10:49 -0700, Benjamin J. Racine wrote: I'd love to see an updated shootout between these three, as I cannot for the life of me seem to be able to settle down with one of them. Things I don't like: Wing's lack of integrated mercurial/svn support. Wing *does* have integrated SVN support already, but nothing for the distributed systems yet. I just purchased a Wing license this past week. So far I'm very happy with it, though I can't speak to a comparison with other IDEs. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newcomer to Python tutorial question
Chris Rebert c...@rebertia.com wrote in message news:mailman.5238.1241723354.11746.python-l...@python.org... On Thu, May 7, 2009 at 11:58 AM, Alan Cameron alan.came...@iname.com wrote: Alan Cameron alan.came...@iname.com wrote in message news:hrfml.50224$tb.4...@newsfe07.ams2... I am not sure of this is the right place to ask a question about the tutorial http://docs.python.org/3.0/tutorial/datastructures.html#sets why is the printed result of basket = {'apple', 'orange', 'apple', 'pear', 'orange', 'banana'} print(basket) {'orange', 'banana', 'pear', 'apple'} in the sequence given? Thanks to all who replied. I assume therefore that the order in which the items of the set are printed could vary each time it is printed? Due to the underlying dict-based implementation, the order will stay the same until you modify the set (i.e. add or remove an element), at which point it may change; it's basically the same behavior as with printing a dict. So this will always print the same thing twice: print basket print basket Whereas this might not: print basket #modify the set basket.discard(banana) basket.add(banana) print basket Cheers, Chris Thanks Chris, It appears that I used a reserved term when I used 'sequence'. I just had not reached that far in the tutorial. I have many years of programming (roughly 50) and want to learn new languages. I find tutorials always fraught with problems due to the knowledge of the writer exceeding the knowledge of the reader and using terms and examples not yet covered in the tutorial thus far. I am persevering with my initial foray into Python. -- Alan Cameron -- http://mail.python.org/mailman/listinfo/python-list