ANN: twill 0.9b1 released
ANNOUNCING twill v0.9b1. twill is a simple language for browsing the Web. It's designed for automated testing of Web sites, but it can be used to interact with Web sites in a variety of ways. In particular, twill supports form submission, cookies, redirects, and HTTP authentication. This release of twill is officially Pretty Dang Stable. A twill script to use the I'm feeling lucky button on Google looks like this: setlocal query twill Python go http://www.google.com/ fv 1 q $query submit btnI # use the I'm feeling lucky button show (Note that using this script abuses Google's Terms of Service. So don't.) You can install the latest release of twill with easy_install, easy_install twill or download this release at http://darcs.idyll.org/~t/projects/twill-0.9b1.tar.gz Documentation is included in the .tar.gz and is also online at http://twill.idyll.org/ Miscellaneous details: twill is implemented in Python and uses pyparsing and mechanize. In addition to the existing simple command language, twill can easily be extended with Python. twill also provides a fairly simple and well-documented wrapper around mechanize. twill does not understand JavaScript, I'm sorry to say. --- Significant changes with 0.9b1 * Switched to MIT license. * twill tests now work under Windows and cygwin (switch to subprocess). Fixed a variety of Windows-specific bugs in the process ;). * Complete integration with latest mechanize, including global form access. * Added Seo Sanghyeon's patch to enable form element TAB completion on 'formvalue' command. * twill-sh now gathers scripts from subdirectories. * Added paste.lint test into wsgi_intercept test code. * Cleared up confusing test output when test server didn't run. * Started using the BeautifulSoup code included with mechanize. * Added TWILL_TEST_PORT for running tests on something other than port 8080. * Added Andy Chamber's patch to the formfill extension module. * Fixed DNS tests to be reliant on name records I control. * Removed ClientCookie dependencies. * Defended my PhD. * Added newline '\n' processing in arguments. -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: Project organization and import
On Mar 5, 10:06 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: My favorite way of working: add a test (or a limited set of tests) for the new or changed feature, run it, check that it fails, change the code, rerun the test, check that the test now runs, rerun all tests to see that nothing broke, add and run more tests to make sure the new code is excellently covered, rinse, repeat. Occasionally, to ensure the code stays clean, stop to refactor, rerunning tests as I go. From the way you describe your workflow, it sounds like you spend very little time working interactively in the interpreter. Is that the case or have I misunderstood? Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: persistent fifo queue class
David Bear schrieb: I'm looking to see if there are any examples or prewritting fifo queue classes. I know this is a broad topic. I'm looking to implement a simple application where a web server enqueue and pickle using a local socket on to a 'queue server' -- and then I will have another application dequeue the pickles again using a local socket. Why don't you use a DB for that? If you want pickles, use a blob column. But all the rest - a defined protocol, stable server, transactions - you get for free. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto pass exceptions between threads
John Nagle schrieb: Alexander Eisenhuth wrote: Hallo Alltogether, I've searched in this mailing list, but it seems to me that there is no general approach to pass exceptions from one thread to another. Very few languages have that. Actually, it could be made to work for Python, but it would have to be carefully designed. Something that raises an exception in another thread the next time the thread blocks would have relatively sane semantics. You couldn't raise an exception on a compute-bound thread, only at block points (locks, I/O, long system calls.) John Nagle Yes you're right, it must be well designed with a clear responsibility delegation. I can imgagine the following points: - Thread termination with termination handler (for Thread instance) - Main Thread information / synchronisation - Default/Customized main thread exception handler -- http://mail.python.org/mailman/listinfo/python-list
Re: Any way to determine test success from inside tearDown()?
Christopher Corbell [EMAIL PROTECTED] wrote: What I'm after is a specialized clean-up approach for error/failure cases. How about decorating the tests with something which tracks the status? Something like (completely untested): def track_failure(f): def test(self): try: f(self) self.testResult = 'pass' except AssertionError: self.testResult = 'fail' raise except: self.testResult = 'error' raise return test and then either decorate the tests directly when you define then, or perhaps easier just iterate over all the methods in the test class and decorate anything beginning 'test_'. Alternatively try subclassing (or monkey patching) TestResult: the TestResult has methods addSuccess, addFailure and addError which are called at a suitable point, with the test as an argument. You could set a flag in the test at that point and check it during the cleanup. If you subclass TextTestRunner and override _makeResult you can substitute in your own TestResult class at that point. -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
En Tue, 06 Mar 2007 04:57:18 -0300, Martin Unsal [EMAIL PROTECTED] escribió: On Mar 5, 10:06 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: My favorite way of working: add a test (or a limited set of tests) for the new or changed feature, run it, check that it fails, change the code, rerun the test, check that the test now runs, rerun all tests to [...] From the way you describe your workflow, it sounds like you spend very little time working interactively in the interpreter. Is that the case or have I misunderstood? FWIW, I only work interactively with the interpreter just to test some constructs, or use timeit, or check code posted here... Never to develop production code. That's why I don't care at all about reload(), by example. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
image processing
Hi, We are are pleased to announce the version 3.0 of the image processing library 'Filters'. You can use it in Python, and we have provided tutorials and samples in Python, with for exemple conversion from/to PIL image format. Have a look at : http://filters.sourceforge.net/ it's open source of course regards edurand -- http://mail.python.org/mailman/listinfo/python-list
pytz2007c error
Hi, Why this error ? from pytz import timezone eastern = timezone('US/Eastern') Traceback (most recent call last): File interactive input, line 1, in module File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \__init__.py, line 93, in timezone File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \tzfile.py, line 33, in build_tzinfo for trans in data[:timecnt]] File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \tzinfo.py, line 27, in memorized_datetime dt = datetime.utcfromtimestamp(seconds) ValueError: timestamp out of range for platform localtime()/gmtime() function I'm running python 2.5 on WinXP French with the egg from CheeseShop. Same error with all timezone (like timezone('Europe/Zurich'), timezone('Europe/Amsterdam'), ...) except a few one: print timezone('UTC') UTC Is this a pytz problem or something I didn't understand ? -- http://mail.python.org/mailman/listinfo/python-list
Re: image processing
edurand [EMAIL PROTECTED] writes: You can use it in Python, and we have provided tutorials and samples in Python, with for exemple conversion from/to PIL image format. Have a look at : http://filters.sourceforge.net/ Looks interesting, however the example screen shot is shrunk down so the text on it can't be read. Also there are a bunch of sample filters with example images, but no explanation at all of what the filters do. Finally, it keeps mentioning things like dll which suggests this is a Windows library. Is it? Maybe it can be ported to other OS's or maybe it's already multi-platform, but the web site should make the situation clear either way. -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question
[EMAIL PROTECTED] typed: Tommy Grav schrieb: For this case, there are list comprehensions (or map, but you shouldn't use it any longer): I didn't see anything in the docs about this. Is map going away or is it considered un-Pythonic now? Most everywhere I've read about map() and filter() seemed to discourage their use stating that they're becoming depreciated (with the exception of Dive Into Python which advocates use of these two functions in preference to even list comprehensions, if I've read it properly). -- Ayaz Ahmed Khan Falling in love makes smoking pot all day look like the ultimate in restraint. -- Dave Sim, author of Cerebus. -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
In article [EMAIL PROTECTED], Martin Unsal [EMAIL PROTECTED] wrote: That too... although I think that's unfortunate. If reload() were reliable, would you use it? Do you think it's inherently unreliable, that is, it couldn't be fixed without fundamentally breaking the Python language core? I wrote a module that wraps __import__ and tracks the dependencies of imports. It then allows you to unload any modules whose source have changed. That seemed to work out nicely for multi-module projects. However, one problem I ran into was that dynamic libraries don't get reloaded, so if you are doing hybrid C++/Python development then this doesn't help - you still have to restart the whole python process to pick up changes in your C++ code. I also didn't do a ton of testing. It worked for a few small projects I was working on, but I stopped using it once I ran into the dynamic library thing, and at this point I'm used to just restarting python each time. I'm sure there are some odd things that some python modules could do that would interfere with the automatic reloading code I wrote. If you're interested in the code, drop me an email. Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz2007c error
On Mar 6, 9:51 am, looping [EMAIL PROTECTED] wrote: Hi, Why this error ? from pytz import timezone eastern = timezone('US/Eastern') Traceback (most recent call last): File interactive input, line 1, in module File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \__init__.py, line 93, in timezone File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \tzfile.py, line 33, in build_tzinfo for trans in data[:timecnt]] File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \tzinfo.py, line 27, in memorized_datetime dt = datetime.utcfromtimestamp(seconds) ValueError: timestamp out of range for platform localtime()/gmtime() function I'm running python 2.5 on WinXP French with the egg from CheeseShop. Same error with all timezone (like timezone('Europe/Zurich'), timezone('Europe/Amsterdam'), ...) except a few one: print timezone('UTC') UTC Is this a pytz problem or something I didn't understand ? OK, the error come from datetime.utcfromtimestamp that doesn't support negative value. pytz try to pass -1633280400 to this function. Is this a problem from Windows ? -- http://mail.python.org/mailman/listinfo/python-list
Any module to parse httpd.conf?
Hello, Does anyone know of an existing module to parse httpd.conf files? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz2007c error
En Tue, 06 Mar 2007 06:41:59 -0300, looping [EMAIL PROTECTED] escribió: On Mar 6, 9:51 am, looping [EMAIL PROTECTED] wrote: from pytz import timezone eastern = timezone('US/Eastern') I'm running python 2.5 on WinXP French with the egg from CheeseShop. Same error with all timezone (like timezone('Europe/Zurich'), timezone('Europe/Amsterdam'), ...) except a few one: print timezone('UTC') UTC Is this a pytz problem or something I didn't understand ? OK, the error come from datetime.utcfromtimestamp that doesn't support negative value. pytz try to pass -1633280400 to this function. Is this a problem from Windows ? Perhaps it's a problem in pytz trying to go too far in the past... -1633280400 refers to a date around 1919. -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Martin Unsal a écrit : On Mar 5, 3:11 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Your own experience *with Python* ? No, my experience with Visual Basic. ;) Of course my experience with Python! Sorry but this was really not obvious. Sorry, I can continue writing snarky replies to your snarky comments but that won't get us anywhere productive. You're right - sorry. Instead I think the following really gets to the crux of the issue. May I say that the problem here comes from your insistance on putting each class in a single module ? No, it doesn't. It really doesn't matter how many classes you have in a module; either you use from foo import bar, or you are stuck with a file structure that is isomorphic to your design namespace. The former breaks reload; imho Which is not a problem. reload() is of very limited use for any non-trivial stuff. /imho -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie question
En Tue, 06 Mar 2007 06:15:03 -0300, Ayaz Ahmed Khan [EMAIL PROTECTED] escribió: [EMAIL PROTECTED] typed: Tommy Grav schrieb: For this case, there are list comprehensions (or map, but you shouldn't use it any longer): I didn't see anything in the docs about this. Is map going away or is it considered un-Pythonic now? Most everywhere I've read about map() and filter() seemed to discourage their use stating that they're becoming depreciated (with the exception of Dive Into Python which advocates use of these two functions in preference to even list comprehensions, if I've read it properly). reduce() will disappear on Python 3.0; map and filter may stay. See http://www.python.org/dev/peps/pep-3100/ and http://www.artima.com/weblogs/viewpost.jsp?thread=98196 -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
IPython on Windows dir problem
Hi all, I have a small problem with IPython shell on Windows. If I run 'python C:\python\scripts\ipython -p pysh' from cmd.exe or directly from Run dialog, I don't get any output from 'shell' commands like ddir. If I run ipython shell from 4NT, ddir and similar commands work fine. Python version is 2.4.3 and IPython version is 0.6.15. 4NT doesn't set any new environment variables or modify existing ones (like PATH) Any ideas? Thnx, -- Marko ICQ: 5990814 I'm not under the alkafluence of inkahol that some thinkle peep I am. It's just the drunker I sit here the longer I get. -- http://mail.python.org/mailman/listinfo/python-list
Good handling of input data (was Re: Newbie question)
On Mar 5, 2007, at 12:47 PM, Larry Bates wrote: Tommy Grav wrote: Hi list, this is somewhat of a newbie question that has irritated me for a while. I have a file test.txt: 0.3434 0.5322 0.3345 1.3435 2.3345 5.3433 and this script lines = open(test.txt,r).readlines() for line in lines: (xin,yin,zin) = line.split() x = float(xin) y = float(yin) z = float(zin) Is there a way to go from line.split() to x,y,z as floats without converting each variable individually? Cheers Tommy Using a list comprehension you would write this as: for line in lines: xin, yin, zin=[float(x) for x in line.split()] This if course expects your data to be perfect. If you want error handling (e.g. less or more than 3 values, values that cause exception when passed to float, etc.) you will have to handle that differently. Thanks for the great response. So how would you handle this type of error handling? My main problem is that occasionally there is an entry in the list that is a string: 0.9834 134.4933 78.009 run11 27 Again I would like to avoid having to individually parse the 3 floats, while still easily handling the string, but a list comprehension will not work as far as I can tell. Is there a module that handles this type of flat ascii tables? Something like: (x,y,z,id,n) = ParseFile(float,float,float,string,int) would be great, and I guess (x,y,z,id,n) = PaseFile2(%f %f %f %s %d) would be even better. Cheers Tommy -- http://mail.python.org/mailman/listinfo/python-list
Try to get help on pymat
I am trying to get my pymat to work. The Python script did not interface to matlab yet. What are the required script to get the interface to work? Please send me email at [EMAIL PROTECTED] Chris Chew -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
[EMAIL PROTECTED] (Alex Martelli) writes: Bruno Desthuilliers [EMAIL PROTECTED] wrote: I don't reload... When my investigative tests gets bigger I write a script and run it with the interpreter. It is easy since my text editor can call Python on a buffer (I use Emacs). That's interesting, is this workflow pretty universal in the Python world? I don't know, but that's also mostly how I do work. My favorite way of working: add a test (or a limited set of tests) for the new or changed feature, run it, check that it fails, change the code, rerun the test, check that the test now runs, rerun all tests to see that nothing broke, add and run more tests to make sure the new code is excellently covered, rinse, repeat. Occasionally, to ensure the code stays clean, stop to refactor, rerunning tests as I go. I believe this is a distinct case. When we write tests we're worried with the system itself. When using the interactive interpreter we're worried with how to best use the language. There might be some feature of the system related to that investigation, but there might be not. For example: what are the methods provided by this object? or which approach is faster for this loop? I won't write a test case to test loop speed. But I'd poke with the interpreter and if the environment gets a bit big to setup then I'd go to the text editor as I said. -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Device Drivers in python(kernel modules)
I am not much of a kernel programmer , I have a requirement to shift a python code to work as a kernel module. So I was just wondering whether we can write a kernel module in python. A thought is that if we can somehow convert python code into a C object code then it can be done. Can some one suggest something..anything -- Regards-- Rishi Pathak National PARAM Supercomputing Facility Center for Development of Advanced Computing(C-DAC) Pune University Campus,Ganesh Khind Road Pune-Maharastra -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Martin Unsal [EMAIL PROTECTED] writes: On Mar 5, 11:06 am, Chris Mellon [EMAIL PROTECTED] wrote: I never advocated big files with many functional units - just files that are just big enough. Then we're in total agreement. I'm not sure why you thought my opinions were the result of baggage from other languages when you don't seem to actually disagree with me. I believe the reason was that you were advocating one class per file. big enough might be more classes. Or fewer... :-) I agree that there is some subtlety there, and I appreciate your example. However the fact that Python's module system essentially forces you to use from foo import * and that reload is almost entirely imcompatible with from foo import *, I would say that reload is essentially useless. The don't force you to that... There are many modules that do, but they are generally glueing your Python code to some other language (usually C) written code. This is common for GUI development, for example. In fact, it is rare to me -- mathematics, statistics, database, web development, testing -- to use this construction. There are no modules that demand that. And you can also write: from foo import Bar, Baz or even from foo import Bar as B1, Baz as B2 # OUCH! ;-) Well from foo import Foo is just a special case of from foo import *. :) It still breaks reload. It still means you're restarting your interpreter even to do the most trivial development cycle. That's what you get when you're working with instances of Foo... I believe that for classmethods this would work right. So, again, it depends on your code, how it is structured (and how it can be structured), etc. Here's an analogy. In C, you can do an incremental build and run your modified application without having to first reboot your computer. In Python, where reload() is essentially the incremental build process, and the interpreter is essentially a virtual machine, you guys are saying that my best option is to just reboot the virtual machine to make sure I have a clean slate. It may be the path of least resistance, but to say that it is necessary or inevitable is 1960s mainframe thinking. How can you reload C code that would affect already running code -- ie. existing data, pointers, etc. -- without reloading the full program? Even changing and reloading a dynamic library wouldn't do that to already existing code, so you'd have to reboot your application as well. -- Jorge Godoy [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: CherryPy + Database questions
SQLite isn't really a DBMS at all, it's just a library. Where is the difference? From the DB-API-side none. And there are plenty of DBs out there that work similar, like MS Access. Show me where it is written that a DBMS has to run as separate server process. According to their FAQ (http://www.sqlite.org/faq.html#q8) it is only threadsafe as long as you aren't changing the same DB in separate threads (so no, not threadsafe at all). I'm not sure if I share your POV. According to the DB API threadsafty attribtue, it's safe to have multiple threads working on a single DB if each has his own connection. Which is a common idiom anyway. And AFAIK e.g. TurboGears doesn't perform any special measures to synchronize cherrypy worker threads when using sqlite, albeit I'm not 100% sure on this. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz2007c error
looping wrote: On Mar 6, 9:51 am, looping [EMAIL PROTECTED] wrote: Hi, Why this error ? from pytz import timezone eastern = timezone('US/Eastern') Traceback (most recent call last): File interactive input, line 1, in module File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \__init__.py, line 93, in timezone File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \tzfile.py, line 33, in build_tzinfo for trans in data[:timecnt]] File C:\Python25\lib\site-packages\pytz-2007c-py2.5.egg\pytz \tzinfo.py, line 27, in memorized_datetime dt = datetime.utcfromtimestamp(seconds) ValueError: timestamp out of range for platform localtime()/gmtime() function I'm running python 2.5 on WinXP French with the egg from CheeseShop. Same error with all timezone (like timezone('Europe/Zurich'), timezone('Europe/Amsterdam'), ...) except a few one: print timezone('UTC') UTC Is this a pytz problem or something I didn't understand ? OK, the error come from datetime.utcfromtimestamp that doesn't support negative value. pytz try to pass -1633280400 to this function. Is this a problem from Windows ? Looks like it. I've opened a bug. https://bugs.beta.launchpad.net/pytz/+bug/90096 Current workaround is to use an earlier release. This will be fixed as pytz needs to remain cross platform. -- Stuart Bishop [EMAIL PROTECTED] http://www.stuartbishop.net/ signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Interface Implementation in Python
'Lo, I think I know what you're asking: I would like to know the interface concept in Python.How the Interface is defined and implemented in Python?. I assume you're talking about the what Java calls an interface - and the simple answer is that we don't have an equivalent in Python. This is because in the Python system of classes, interface inheritance would be unenforceable (because methods can be arbitrarily added at runtime). How to access the interface fromn Client? I'm not completely sure what you mean here... client class, client of some protocol? Assuming you mean the client class, my answer above should suffice (and if not then I am completely missing the question). Regards, Johannes Woolard -- http://mail.python.org/mailman/listinfo/python-list
Re: Device Drivers in python(kernel modules)
rishi pathak schrieb: I am not much of a kernel programmer , I have a requirement to shift a python code to work as a kernel module. So I was just wondering whether we can write a kernel module in python. A thought is that if we can somehow convert python code into a C object code then it can be done. Can some one suggest something..anything http://wiki.python.org/moin/elmer This tool is able to run Python Code as if it was written in C. Perhaps this might help you, but I am not pretty sure since it had to be included in the kernel tree. Thomas -- http://mail.python.org/mailman/listinfo/python-list
SPE python IDE: Call for testers!
I've been working a lot on fixing SPE and upgrading it with the latest plugins. The winpdb debugger no longer fails and wxGlade crashes are history. Is that not great? Are you eager to try it out yourself? Please do! Get it from subversion and test it for any critical bug, so I can iron it out. I have been patching a lot for Ubuntu users, who will be very pleased with this release, and I'd like to thank Jurjen a lot for his work on Mac issues. This is a definitely a release everyone should upgrade to, wether you use windows, mac or linux! SPE is both suitable for newbies and experienced python programmers. Read more and comment here: http://pythonide.stani.be Thanks for your interest, Stani -- http://mail.python.org/mailman/listinfo/python-list
Re: Good handling of input data (was Re: Newbie question)
On Tue, 06 Mar 2007 05:57:43 -0500, Tommy Grav wrote: So how would you handle this type of error handling? My main problem is that occasionally there is an entry in the list that is a string: 0.9834 134.4933 78.009 run11 27 How do you want to deal with such an occasional string? What do you expect the code to do? The way I see it, if you're expecting five floats, and you get four floats and a string, that's an error. Do you ignore the entire line, or replace the string with zero, or what? Again I would like to avoid having to individually parse the 3 floats, while still easily handling the string, but a list comprehension will not work as far as I can tell. Is there a module that handles this type of flat ascii tables? Something like: (x,y,z,id,n) = ParseFile(float,float,float,string,int) would be great, and I guess (x,y,z,id,n) = PaseFile2(%f %f %f %s %d) would be even better. How about this? def parse_line(line, types): items = line.split() return [t(s) for (t, s) in zip(types, items)] line = 4.5 6.723-1 fred 7.9 parse_line(line, (float, float, int, int, str, float)) [4.5, 6.7002, 23, -1, 'fred', 7.9004] -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
askstring Window to the top under Windows
Hi, I tryed askstring to input some text in my script, but some ugly empty Window appears with the Input-Window behind and all together behind my Console showing my script. So all have to brought to the top first by the user - very unconfortable -- http://mail.python.org/mailman/listinfo/python-list
Re: Good handling of input data (was Re: Newbie question)
Tommy Grav kirjoitti: snip Thanks for the great response. So how would you handle this type of error handling? My main problem is that occasionally there is an entry in the list that is a string: 0.9834 134.4933 78.009 run11 27 Again I would like to avoid having to individually parse the 3 floats, while still easily handling the string, but a list comprehension will not work as far as I can tell. Is there a module that handles this type of flat ascii tables? Something like: (x,y,z,id,n) = ParseFile(float,float,float,string,int) would be great, and I guess (x,y,z,id,n) = PaseFile2(%f %f %f %s %d) would be even better. Cheers Tommy Being just on the first step of the ladder of total clairvoyance, I can't disambiguate the word occasionally. I'm assuming that you have two types of rows: the ones with 3 floats and the ones with 3 floats, a string and an integer. Here's a possible solution: #=== conv = {'f':float, 'i':int, 's':str} lines = ['0.3434 0.5322 0.3345\n', '0.9834 134.4933 78.009 run11 27\n', '1.3435 2.3345 5.3433\n'] for line in lines: line = line.split() if len(line) == 3: pat = 'fff' (x, y, z) = [conv[p](x) for p,x in zip(pat, line)] print x, y, z print type(x), type(y), type(z) else: pat = 'fffsi' (x, y, z, s, i) = [conv[p](x) for p,x in zip(pat, line)] print x, y, z, s, i print type(x), type(y), type(z), type(s), type(i) #=== HTH, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: Good handling of input data (was Re: Newbie question)
Steven D'Aprano a écrit : On Tue, 06 Mar 2007 05:57:43 -0500, Tommy Grav wrote: So how would you handle this type of error handling? My main problem is that occasionally there is an entry in the list that is a string: 0.9834 134.4933 78.009 run11 27 How do you want to deal with such an occasional string? What do you expect the code to do? The way I see it, if you're expecting five floats, and you get four floats and a string, that's an error. Do you ignore the entire line, or replace the string with zero, or what? Again I would like to avoid having to individually parse the 3 floats, while still easily handling the string, but a list comprehension will not work as far as I can tell. Is there a module that handles this type of flat ascii tables? Something like: (x,y,z,id,n) = ParseFile(float,float,float,string,int) would be great, and I guess (x,y,z,id,n) = PaseFile2(%f %f %f %s %d) would be even better. How about this? def parse_line(line, types): items = line.split() return [t(s) for (t, s) in zip(types, items)] Since the OP mention of last items being here occasionnaly, I'd go for this instead (nb: ad-hoc implementation - yours is of course better as a general solution): def parse_line(line, *types): items = line.split() return [t(s) for (s, t) in zip(items, types)] My 2 cents -- http://mail.python.org/mailman/listinfo/python-list
Re: image processing
On Mar 6, 9:57 am, Paul Rubin http://[EMAIL PROTECTED] wrote: edurand [EMAIL PROTECTED] writes: You can use it in Python, and we have provided tutorials and samples in Python, with for exemple conversion from/to PIL image format. Have a look at :http://filters.sourceforge.net/ Looks interesting, however the example screen shot is shrunk down so the text on it can't be read. Also there are a bunch of sample filters with example images, but no explanation at all of what the filters do. Finally, it keeps mentioning things like dll which suggests this is a Windows library. Is it? Maybe it can be ported to other OS's or maybe it's already multi-platform, but the web site should make the situation clear either way. It's a DLL, so yes, it run on Windows. If someone would like to port it on other OS, why not. To test it, you can download the software 'FiltersTest', for Windows of course -- http://mail.python.org/mailman/listinfo/python-list
Re: Good handling of input data (was Re: Newbie question)
On Mar 6, 2007, at 8:14 AM, Jussi Salmela wrote: Tommy Grav kirjoitti: snip Thanks for the great response. So how would you handle this type of error handling? My main problem is that occasionally there is an entry in the list that is a string: 0.9834 134.4933 78.009 run11 27 Again I would like to avoid having to individually parse the 3 floats, while still easily handling the string, but a list comprehension will not work as far as I can tell. Is there a module that handles this type of flat ascii tables? Something like: (x,y,z,id,n) = ParseFile(float,float,float,string,int) would be great, and I guess (x,y,z,id,n) = PaseFile2(%f %f %f %s %d) would be even better. Cheers Tommy Being just on the first step of the ladder of total clairvoyance, I can't disambiguate the word occasionally. I'm assuming that you have two types of rows: the ones with 3 floats and the ones with 3 floats, a string and an integer. Here's a possible solution: #=== conv = {'f':float, 'i':int, 's':str} lines = ['0.3434 0.5322 0.3345\n', '0.9834 134.4933 78.009 run11 27\n', '1.3435 2.3345 5.3433\n'] for line in lines: line = line.split() if len(line) == 3: pat = 'fff' (x, y, z) = [conv[p](x) for p,x in zip(pat, line)] print x, y, z print type(x), type(y), type(z) else: pat = 'fffsi' (x, y, z, s, i) = [conv[p](x) for p,x in zip(pat, line)] print x, y, z, s, i print type(x), type(y), type(z), type(s), type(i) #=== I should have been more specific by saying that all the lines in the file have the same format. But occasionally I will have a file that is just not all floats, hence my question for handling a multi-type line. Since I am the one generating the files I always know which types the columns in the file have which makes it easier :) Your answer, together with Steven's has given my much better understanding of the issue of parsing in tables like this. Thanks to the both of you! Cheers Tommy -- http://mail.python.org/mailman/listinfo/python-list
Re: askstring Window to the top under Windows
iwl kirjoitti: Hi, I tryed askstring to input some text in my script, but some ugly empty Window appears with the Input-Window behind and all together behind my Console showing my script. So all have to brought to the top first by the user - very unconfortable Are you asking about the function AskString in the EasyDialogs module of Macintosh? If so, I can't help you. I'm just confused because the subject of your post contains the word Windows which could mean Microsoft Windows on which Python hasn't the EasyDialogs module. Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: askstring Window to the top under Windows
Jussi Salmela wrote: iwl kirjoitti: Hi, I tryed askstring to input some text in my script, but some ugly empty Window appears with the Input-Window behind and all together behind my Console showing my script. So all have to brought to the top first by the user - very unconfortable Are you asking about the function AskString in the EasyDialogs module of Macintosh? If so, I can't help you. I'm just confused because the subject of your post contains the word Windows which could mean Microsoft Windows on which Python hasn't the EasyDialogs module. Not that I've used it, but... http://www.averdevelopment.com/python/EasyDialogs.html TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Is every number in a list in a range?
On Mon, 05 Mar 2007 14:03:50 -0500, Steven W. Orr wrote: I have a list ll of intergers. I want to see if each number in ll is within the range of 0..maxnum I can write it but I was wondering if there's a better way to do it? No, the way you wrote it is the absolute best way. Or possibly the worst way. It's kinda hard to tell since you don't tell us *how* you do it, so in the spirit of there are no stupid questions, only stupid answers here's my stupid solution to the problem. def all_in_range(alist, n1, n2=None): Returns True if all the items in alist of numbers are in the range n1 through n2 inclusive, using a silly, obfuscated algorithm. if n2 is None: n1, n2 = 0, n1 low, high = n1, n2 all_in = True i = -1 - len(alist) if ((i + 1 + len(alist)) len(alist)) is True: done = False else: done = True while not done is True: i = 1 + i x = alist[i + len(alist)] p = min(low, x) == low q = max(high, x) != high flag = ((not p and not q) or (p and q)) or (not p and q) all_in = all_in and not flag if (not (i + len(alist) + 2 len(alist))) is True: done = False else: done = True if ((all_in is True) is False) is True: return False elif (not (all_in is False)) is True: return True -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: askstring Window to the top under Windows
On Mar 6, 1:13 pm, iwl [EMAIL PROTECTED] wrote: Hi, I tryed askstring to input some text in my script, but some ugly empty Window appears with the Input-Window behind and all together behind my Console showing my script. So all have to brought to the top first by the user - very unconfortable It's not clear whether you're talking about the usual Why do I get a DOS window when I run my python script? question -- to which the answer is, in essence, change your script's extension to .pyw or use the pythonw.exe executable -- or Why _when I use askstring_ do I get an empty window?. If it's the latter, then I don't know, but can you provide a small example script which exhibits the behaviour. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting external IP address
On Mon, 05 Mar 2007 09:02:44 +, Duncan Booth wrote: Try running it interactively and looking at the data you receive: conn = HTTPConnection('xml.showmyip.com') conn.request('GET', '/') resp = conn.getresponse() print resp httplib.HTTPResponse instance at 0x00C58350 data = resp.read() print data htmlheadtitleObject moved/title/headbody h2Object moved to a href=http://www.showmyip.com/xml/;here/a. /h2 /body/html Ah! That's the clue I needed -- thanks. If you try connecting to 'www.showmyip.com' and requesting '/xml/' it should work. Thank you muchly! That seems to do the trick. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Try to get help on pymat
CHRIS CHEW [EMAIL PROTECTED] writes: I am trying to get my pymat to work. The Python script did not interface to matlab yet. What are the required script to get the interface to work? Please send me email at [EMAIL PROTECTED] You might want to have a look at http://mlabwrap.sf.net. cheers, 'as -- http://mail.python.org/mailman/listinfo/python-list
Re: Python GUI + OpenGL
I didn't say so. I just pointed out an alternative, as the OP had issues with obtaining binary packages for wx + py2.5 I believe he was having trouble with binary packages for PyOpenGL, wxPython has 2.5 binaries and has since it was released. Ah, I didn't read it that way as the OP didn't say exactly _what_ package he was missing. Obviously if it's PyOpenGL then using Qt won't buy him much... Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: ANN: PyDSTool now compatible with numpy 1.0.1, scipy 0.5.2 and 64-bit CPUs.
On Mar 5, 10:17 pm, Rob Clewley [EMAIL PROTECTED] wrote: I have a different and admittedly limited view of hybrid systems as part of dynamical systems theory. In principle, I would love to have time to write an interface to something like Modelica, but PyDSTool isn't intended as an industrial-scale simulation package: it is intended for applied dynamical systems research involving small systems that people want to analyze with tools like bifurcation theory and parameter estimation. ... Sorry to be taking a short-term view here (I try to avoid that), but we're just a couple of guys trying to concentrate on our day jobs... As long as these are your stated objectives I certainly can't take any issue with them. In fact, I qualified my statement with I don't know your ultimate goals for precisely this reason. Without knowing your goals I certainly can't made a valid argument about your approach. I am glad that you appear to have understood the spirit of the comment. If you ever do decide to consider larger scale models, you might want to look into OpenModelica (an open source implementation from Linkoeping University). It includes a compiler that can take Modelica code and generate flat Modelica (processing inheritance, hierarchy, replaceable components, etc. down to just variables and equations). One final note on perspective. The main driver for my comment is that I am an industrial user but I would love to have these kinds of analysis capabilities. I see that as one of the remaining opportunities in Modelica (i.e. the ability to build niche analysis capabilities, which commercial vendors perhaps could not justify, around a standard description). Having it done within a Python framework would be icing on the cake. :-) Rob -- Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 5 Mar 2007 23:35:00 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 5, 11:06 am, Chris Mellon [EMAIL PROTECTED] wrote: I never advocated big files with many functional units - just files that are just big enough. Then we're in total agreement. I'm not sure why you thought my opinions were the result of baggage from other languages when you don't seem to actually disagree with me. Because you're advocating single class per file. A scan through the standard library may be instructive, where there are some modules that expose a single class (StringIO, pprint) and others that expose many, and some that expose none at all. smallest unit that it makes sense to work on and single class are totally different things. In any case, as I hinted at, I prefer an organic, developer driven approach to deciding these things, not handed down from above style guidelines. You know your modules are broken up enough when you no longer have conflicts. Fewer dependencies between compilation units means a faster rebuild-test turnaround. I know all about incremental builds and I just don't think people use small compilation units in C++ to make their builds faster. It certainly never been the reason why I subdivided a source file. Faster compile/debug/edit cycle is the main justification I've heard for single class per file. The others are variations of your RCS argument, which I don't think is justifiable for the above reasons. It smells of the kind of my developers are stupid short sighted management that kills projects. Sure, but whats your goal here? If you're just testing something as you work, then this works fine. If you're testing large changes, that affect many modules, then you *need* to reload your world, because you want to make sure that what you're testing is clean. I don't think reload works for anything but trivial scripts. The moment you use from foo import bar reload is broken. The semantics of exactly what reload should do are tricky. Pythons reload works in a sensible but limited way. I agree that there is some subtlety there, and I appreciate your example. However the fact that Python's module system essentially forces you to use from foo import * and that reload is almost entirely imcompatible with from foo import *, I would say that reload is essentially useless. I'm still not sure why you believe this, since several counterexamples where given. As an intellectual exercise, though, lets assume that reload is totally broken and you just can't use it. Pretend it will reformat your machine if you ever call it. Can you really think of no other reason to use Python? You still haven't given any justification for why a magic reload is essential to Python development when a) all existing python development works fine without it and b) all existing development in every other language works fine without it. That said, nothing prevents you from using from foo import Foo if Foo is all you need (or need most - you can combine this with import foo). Well from foo import Foo is just a special case of from foo import *. :) It still breaks reload. It still means you're restarting your interpreter even to do the most trivial development cycle. You're totally fixated on reload. I don't understand this. I'm totally positive that your traditional development experience has not been in an environment where you could effortlessly slot in new code to a running image. Why do you demand it from Python? Also, the difference between from foo import Bar and from foo import * is that the former is limited in scope (you're adding a limited set of explicit names to your namespace) and is futureproof (additional names exported from foo won't clash with vars in the importing module with unknown effects). The reason why one is common and accepted and the other is frowned upon has nothing to do with reload(). I wonder what environments you worked in before that actually had a reliable and gotcha free version of reload? I'm perfectly well aware that I'm not going to be able to reload a widget in the middle of a running GUI app, for example. I'm not looking for gotcha free, I'll settle for minimally useful. Then reload() as is is what you want. Here's an analogy. In C, you can do an incremental build and run your modified application without having to first reboot your computer. In Python, where reload() is essentially the incremental build process, and the interpreter is essentially a virtual machine, you guys are saying that my best option is to just reboot the virtual machine to make sure I have a clean slate. It may be the path of least resistance, but to say that it is necessary or inevitable is 1960s mainframe thinking. But you do need to restart the application image. The python interpreter is not an emulator. You're drawing incompatible analogies and making unjustified assumptions based on them. reload() is not an incremental build process, and
Re: Any module to parse httpd.conf?
I looked at http://www.python.org/pypi/httpdrun not so long ago, it might be able to do what you want. I think it was a bit hard to read. Remember that with Apache you (may) also need to worry about configuration merges and whatnot (Directory, VirtualHost, .htaccess, and so on...). What specifically do you want to do? There are a lot of ways to do a lot of things with Apache. If you're looking to create virtual hosts, take a look at mod_vhost_alias or some RewriteRule magic. You're configuration could be pretty simplified and reduced to updating a gdbm file or creating a directory? Jeff On 6 Mar 2007 02:03:33 -0800, Gerard Flanagan [EMAIL PROTECTED] wrote: Hello, Does anyone know of an existing module to parse httpd.conf files? Thanks. -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Interface Implementation in Python
[EMAIL PROTECTED] wrote: Hi, I would like to know the interface concept in Python.How the Interface is defined and implemented in Python?. How to access the interface fromn Client? Thanks PSB You might want to look at how Zope 3 implements interfaces. http://wiki.zope.org/zope3/FrontPage http://wiki.zope.org/zope3/programmers_tutorial.pdf -Larry -- http://mail.python.org/mailman/listinfo/python-list
Re: Squisher -- a lightweight, self-contained alternative to eggs?
On Mar 5, 12:31 am, Adam Atlas [EMAIL PROTECTED] wrote: Right now I'm just testing and polishing up the code... in the meantime, any comments? How does this work with compiled extension modules? -- http://mail.python.org/mailman/listinfo/python-list
Re: Interface Implementation in Python
On 5 Mar 2007 16:25:03 -0800, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I would like to know the interface concept in Python.How the Interface is defined and implemented in Python?. How to access the interface fromn Client? You have a class with methods and data. You write many unit tests for that class which defines the behaviour of your interface. Make sure your class passes all those tests. When you are done, not only does your unit tests specify an interface, you also have a concrete class that implements that interface. Now replace the original class with another class. If that class also passes all your tests, then you can conclude that it also implements the same interface. -- mvh Björn -- http://mail.python.org/mailman/listinfo/python-list
Re: askstring Window to the top under Windows
On 6 Mrz., 14:48, Tim Golden [EMAIL PROTECTED] wrote: On Mar 6, 1:13 pm, iwl [EMAIL PROTECTED] wrote: It's not clear whether you're talking about the usual Why do I get a DOS window when I run my python script? question -- to which the answer is, in essence, change your script's extension to .pyw or use the pythonw.exe executable -- or Why _when I use askstring_ do I get an empty window?. If it's the latter, then I don't know, but can you provide a small example script which exhibits the behaviour. TJG import tkSimpleDialog tkSimpleDialog.askstring(a,b) at the python Console under XP (not pythonw). - instead of only showing the Inputwindow at the top, some additional empty window is shown, both not on top. -- http://mail.python.org/mailman/listinfo/python-list
Wrong exist status for os.system, os.poepen, etc.
Subject: python2.4: Wrong exist status for os.system, os.poepen, etc. Package: python2.4 Version: 2.4.4-2 Severity: normal -- System Information: Debian Release: 4.0 APT prefers testing APT policy: (800, 'testing'), (70, 'stable'), (60, 'unstable') Architecture: i386 (i686) Shell: /bin/sh linked to /bin/bash Kernel: Linux 2.6.18-3-k7 Locale: LANG=it_IT.UTF-8, LC_CTYPE=it_IT.UTF-8 (charmap=UTF-8) I send this to python-list also, so someone can tell if he/she can (not) reproduce the same behavior The os.system() (but all the other funciont with similar behavior) reports wrong exit status. I can reproduce the bug in the following way create /tmp/x.c: #include stdlib.h int main(void){ exit(20); } $ cd /tmp $ make x $./x $echo $? 20 $ python give the following commands: import os os.system(/tmp/x) 5120 the same for x=os.popen(/tmp/x) x.read() '' x.close() 5120 Greetings PAolo Versions of packages python2.4 depends on: ii libbz2-1.0 1.0.3-6 high-quality block-sorting file co ii libc6 2.3.6.ds1-10 GNU C Library: Shared libraries ii libdb4.44.4.20-8 Berkeley v4.4 Database Libraries [ ii libncursesw55.5-5Shared libraries for terminal hand ii libreadline55.2-2GNU readline and history libraries ii libssl0.9.8 0.9.8c-4 SSL shared libraries ii mime-support3.39-1 MIME files 'mime.types' 'mailcap ii python2.4-minimal 2.4.4-2 A minimal subset of the Python lan python2.4 recommends no packages. -- no debconf information -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Martin Unsal [EMAIL PROTECTED] wrote: On Mar 5, 10:06 pm, [EMAIL PROTECTED] (Alex Martelli) wrote: My favorite way of working: add a test (or a limited set of tests) for the new or changed feature, run it, check that it fails, change the code, rerun the test, check that the test now runs, rerun all tests to see that nothing broke, add and run more tests to make sure the new code is excellently covered, rinse, repeat. Occasionally, to ensure the code stays clean, stop to refactor, rerunning tests as I go. From the way you describe your workflow, it sounds like you spend very little time working interactively in the interpreter. Is that the case or have I misunderstood? I often do have an interpreter open in its own window, to help me find out something or other, but you're correct that it isn't where I work; I want all tests to be automated and repeatable, after all, so they're better written as their own scripts and run in the test-framework. I used to use a lot of doctests (often produced by copy and paste from an interactive interpreter session), but these days I lean more and more towards unittest and derivatives thereof. Sometimes, when I don't immediately understand why a test is failing (or, at times, why it's unexpectedly succeeding _before_ I have implemented the feature it's supposed to test!-), I stick a pdb.set_trace() call at the right spot to look around (and find out how to fix the test and/or the code) -- I used to use print a lot for such exploration, but the interactive interpreter started by pdb is often handier (I can look at as many pieces of data as I need to find out about the problem). I still prefer to run the test[s] within the test framework, getting interactive only at the point where I want to be, rather than running the tests from within pdb to set breakpoints manually -- not a big deal either way, I guess. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Jorge Godoy [EMAIL PROTECTED] wrote: ... My favorite way of working: add a test (or a limited set of tests) for the new or changed feature, run it, check that it fails, change the code, rerun the test, check that the test now runs, rerun all tests to see that nothing broke, add and run more tests to make sure the new code is excellently covered, rinse, repeat. Occasionally, to ensure the code stays clean, stop to refactor, rerunning tests as I go. I believe this is a distinct case. When we write tests we're worried with the system itself. Not sure I get what you mean; when I write tests, just as when I write production code, I'm focused (not worried:-) about the application functionality I'm supposed to deliver. The language mostly gets out of my way -- that's why I like Python, after all:-). When using the interactive interpreter we're worried with how to best use the language. There might be some feature of the system related to that investigation, but there might be not. For example: what are the methods provided by this object? or which approach is faster for this loop? I do generally keep an interactive interpreter running in its own window, and help and dir are probably the functions I call most often there. If I need to microbenchmark for speed, I use timeit (which I find far handier to use from the commandline). I wouldn't frame this as worried with how to best use the language though; it's more akin to a handy reference manual (I also keep a copy of the Nutshell handy for exactly the same reason -- some things are best looked up on paper). I won't write a test case to test loop speed. But I'd poke with the interpreter and if the environment gets a bit big to setup then I'd go to the text editor as I said. I don't really see getting a bit big to setup as the motivation for writing automated, repeatable tests (including load-tests, if speed is such a hot topic in your case); rather, the key issue is, will you ever want to run this again? For example, say you want to check the relative speeds of approaches A and B -- if you do that in a way that's not automated and repeatable (i.e., not by writing scripts), then you'll have to repeat those manual operations exactly every time you refactor your code, upgrade Python or your OS or some library, switch to another system (HW or SW), etc, etc. Even if it's only three or four steps, who needs the aggravation? Almost anything worth doing (in the realm of testing, measuring and variously characterizing software, at least) is worth automating, to avoid any need for repeated manual labor; that's how you get real productivity, by doing ever less work yourself and pushing ever more work down to your computer. Alex -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython import error...
On 4 Mar 2007 16:42:07 -0800, king kikapu [EMAIL PROTECTED] wrote: Hi, i am just completed installing Python/Pydev/Eclipse/wxPython on an Ubuntu system and all are running fine except program that contains references to wx It gives me: ImportError: /usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/ _core_.so: undefined symbol: PyUnicodeUCS4_FromEncodedObject I installed the wx packages the way the wx web site says, especially for Ubuntu. Can anyone help with this as i have been searching the net for this with no luck... Is your pythonpath configured correctly within pydev (and not just in the system?) -- see http://fabioz.com/pydev/manual_101_interpreter.html Cheers, Fabio -- http://mail.python.org/mailman/listinfo/python-list
Re: Squisher -- a lightweight, self-contained alternative to eggs?
Doesn't seem to work. I guess zipimport doesn't support that by default... but if I remember correctly, Setuptools adds that. Maybe I'll take a look at how it does it (I think by extracting the .so to / tmp?) and see how easy it would be to integrate it here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrong exist status for os.system, os.poepen, etc.
On 6 Mar, 16:39, Paolo Pantaleo [EMAIL PROTECTED] wrote: The os.system() (but all the other funciont with similar behavior) reports wrong exit status. I can reproduce the bug in the following way I think you should look at some previous threads related to this (obtained by searching Google Groups for os.system exit status code): grabbing return codes from os.system() call http://groups.google.com/group/comp.lang.python/browse_frm/thread/efeab8a50ff16975/ please help me understand os.system() result http://groups.google.com/group/comp.lang.python/browse_frm/thread/4a9ab6d5a609e9ca/ os.system() 8 ? http://groups.google.com/group/comp.lang.python/browse_frm/thread/f12ccab6389f482c/ In short, the returned code is actually a combination of two values, and you need to extract the expected status code by shifting the result 8 bits to the right. It may actually be more complicated than that, but the man page for system (man 3 system) explains this in more detail. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Wrong exist status for os.system, os.poepen, etc.
On 6 Mar, 16:51, Paul Boddie [EMAIL PROTECTED] wrote: On 6 Mar, 16:39, Paolo Pantaleo [EMAIL PROTECTED] wrote: The os.system() (but all the other funciont with similar behavior) reports wrong exit status. I can reproduce the bug in the following way I think you should look at some previous threads related to this (obtained by searching Google Groups for os.system exit status code): grabbing return codes from os.system() callhttp://groups.google.com/group/comp.lang.python/browse_frm/thread/efe... please help me understand os.system() resulthttp://groups.google.com/group/comp.lang.python/browse_frm/thread/4a9... os.system() 8 ?http://groups.google.com/group/comp.lang.python/browse_frm/thread/f12... In short, the returned code is actually a combination of two values, and you need to extract the expected status code by shifting the result 8 bits to the right. It may actually be more complicated than that, but the man page for system (man 3 system) explains this in more detail. Paul Sorry, for the mistake, I just missed the words encoded in the format specified for wait() in the documentation of popen() Thnx for the immediate answer PAolo -- http://mail.python.org/mailman/listinfo/python-list
Re: wxPython import error...
On 4 Mar 2007 16:42:07 -0800, king kikapu [EMAIL PROTECTED] wrote: Hi, i am just completed installing Python/Pydev/Eclipse/wxPython on an Ubuntu system and all are running fine except program that contains references to wx It gives me: ImportError: /usr/lib/python2.4/site-packages/wx-2.8-gtk2-unicode/wx/ _core_.so: undefined symbol: PyUnicodeUCS4_FromEncodedObject I installed the wx packages the way the wx web site says, especially for Ubuntu. Can anyone help with this as i have been searching the net for this with no luck... Thanks for any help -- This looks like you somehow installed the Redhat packages instead - Redhat builds their Python with UCS4, everyone else uses UCS2. Did you download the RPMs and convet them rather than adding the wxCommunity repo to your sources.lst? -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Bruno Desthuilliers wrote: imho Which is not a problem. reload() is of very limited use for any non-trivial stuff. /imho Now that I've heard this from 5 different people it might be sinking in. :) :) I really do appreciate all of you taking the time to explain this to me. When I started using Python a few years ago I was very excited about the fact that it was an interpreted language and offered a more interactive workflow than the old compile-link-test workflow. As my project has grown to be pretty sizeable by Python standards, I tried to continue taking advantage of the tight, reload-based, interpreted- language workflow and it's become really cumbersome, which is disappointing. However y'all are right, giving up on reload() doesn't mean Python is inadequate for large projects, just that it doesn't live up entirely to what I perceived as its initial promise. Once I adjust my mindset and workflow for a life without reload(), I'll probably be better off. I'd like to point out something though. More than one of the people who responded have implied that I am bringing my prior-language mindset to Python, even suggesting that my brain isn't built for Python. ;) In fact I think it's the other way around. I am struggling to take full advantage of the fact that Python is an interpreted language, to use Python in the most Pythonic way. You guys are telling me that's broken and I should go back to a workflow that is identical in spirit, and not necessarily any faster than I would use with a compiled language. While that might be the right answer in practice, I don't feel like it's a particularly good answer, and it confirms my initial impression that Python package management is broken. I think you should be asking yourselves, Did we all abandon reload() because it is actually an inferior workflow, or just because it's totally broken in Python? I have one question left but I'll ask that in a separate post. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphviz Python Binding for Python 2.5 on Windows?
On Mar 6, 8:39 am, Nick Vatamaniuc [EMAIL PROTECTED] wrote: On Mar 5, 5:16 pm, Alex Li [EMAIL PROTECTED] wrote: Hello, I would like to use Python 2.5 on Windows with Graphviz to generate graphs. I used yapgvb but it only requires Python 2.4 (won't work with Python 2.5). Other packages like pydot seems to be unmaintained or requires custom building to be used on Windows (pygraphviz), which I tried to avoid. Any suggestions? Thanks in advance, Alex Alex, You can always pipe your dot file directly to the dot or neato executables using the subprocess method then read the output. This way you don't have to install yapgvb or other adapters and it will work with Python 2.5. But you will need to compose your dot file as a giant character buffer... -Nick V. Not really a solution, but you can always install a virtual machine with Ubuntu (or other linux flavour) where pydot is available for python2.5 (sudo apt-get install python-pydot). Stani -- http://mail.python.org/mailman/listinfo/python-list
Re: Device Drivers in python(kernel modules)
Thomas Ploch wrote: rishi pathak schrieb: I am not much of a kernel programmer , I have a requirement to shift a python code to work as a kernel module. So I was just wondering whether we can write a kernel module in python. A thought is that if we can somehow convert python code into a C object code then it can be done. Can some one suggest something..anything 1. For what operating system? 2. WHY? 3. This is probably a bad idea. If it doesn't have to go in the operating system kernel, it shouldn't go in the kernel. John Nagle -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 5, 2:18 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Martin Unsal a écrit : For example, say you want to organize the widgets package as follows: widgets/scrollbar/*.py widgets/form/*.py widgets/common/util.py Other than messing around with PYTHONPATH, which is horrible, I don't see how to import util.py from the widget code. Some of us still manage to do so without messing with PYTHONPATH. How exactly do you manage it? The only way I can see to do it is to have widgets/__init__.py look something like this: from common import util from scrollbar import Scrollbar from form import Form Then Scrollbar.py doesn't have to worry about importing util, it just assumes that util is already present in its namespace. BUT ... this means that Scrollbar.py can only be loaded in the interpreter as part of package widgets. You can't run an interpreter and type import widgets.scrollbar.Scrollbar and start going to town, because Scrollbar doesn't import its own dependencies. So what I want to clarify here: Do Python programmers try to design packages so that each file in the package can be individually loaded into the interpreter and will automatically import its own dependencies? Or do you design packages so they can only be used by importing from the top level and running the top level __init__.py? I hope that made sense. :) Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
I'd like to point out something though. More than one of the people who responded have implied that I am bringing my prior-language mindset to Python, even suggesting that my brain isn't built for Python. ;) In fact I think it's the other way around. I am struggling to take full advantage of the fact that Python is an interpreted language, to use Python in the most Pythonic way. You guys are telling me that's broken and I should go back to a workflow that is identical in spirit, and not necessarily any faster than I would use with a compiled language. While that might be the right answer in practice, I don't feel like it's a particularly good answer, and it confirms my initial impression that Python package management is broken. I think you should be asking yourselves, Did we all abandon reload() because it is actually an inferior workflow, or just because it's totally broken in Python? Sorry, but I fail to see the point of your argumentation. Reloading a module means that you obviously have some editor open you code your module in, and an interactive interpreter running where you somehow have to make the reload(module) line (re-)appear, and then most probably (unless the pure reloading itself triggers some testing code) some other line that e.g. instantiates a class defined in module Now how exactly does that differ from having a test.py file containing import module do-something and a commandline sitting there with a python test.py waiting to be executed, easily brought back by a single key-stroke. Especially if do-something becomes more that some easy lines brought back by the command line history. I've been writing python for a few years now, to programs the size of a few K-lines, and _never_ felt the slightest need to reload anything. And as there have been quite a few discussions like this in the past few years, IMHO reload is a wart and should be removed. Diez -- http://mail.python.org/mailman/listinfo/python-list
[CfP] Dynamic Languages Symposium 2007
* * * Dynamic Languages Symposium 2007 * *at ooPSLA 2007 - http://www.oopsla.org * * * * Montreal, Quebec, Canada, October 22, 2007 * * * * http://www.swa.hpi.uni-potsdam.de/dls07/ * * * Important dates: * Submission of papers: June 1, 2007 *hard deadline* * Author notification: June 30, 2007 * Final versions due: July 7, 2007 * DLS 2007: October 22, 2007 * OOPSLA 2007: October 21-25, 2007 Scope: ** The Dynamic Languages Symposium (DLS) at OOPSLA 2007 in Montreal, Canada, is a forum for discussion of dynamic languages, their implementation and application. While mature dynamic languages including Smalltalk, Lisp, Scheme, Self, and Prolog continue to grow and inspire new converts, a new generation of dynamic scripting languages such as Python, Ruby, PHP, and JavaScript are successful in a wide range of applications. DLS provides a place for researchers and practitioners to come together and share their knowledge, experience, and ideas for future research and development. DLS 2007 invites high quality papers reporting original research, innovative contributions or experience related to dynamic languages, their implementation and application. Accepted Papers will be published in the OOPSLA conference companion and the ACM Digital Library. Areas of interest include but are not limited to: * * Innovative language features and implementation techniques * Development and platform support, tools * Interesting applications * Domain-oriented programming * Very late binding, dynamic composition, and runtime adaptation * Reflection and meta-programming * Software evolution * Language symbiosis and multi-paradigm languages * Dynamic optimization * Hardware support * Experience reports and case studies * Educational approaches and perspectives * Object-oriented, aspect-oriented, and context-oriented programming Submissions and proceedings *** We invite original contributions that neither have been published previously nor are under review by other refereed events or publications. Research papers should describe work that advances the current state of the art. Experience papers should be of broad interest and should describe insights gained from substantive practical applications. The program committee will evaluate each contributed paper based on its relevance, significance, clarity, and originality. Papers are to be submitted electronically at http://www.dcl.hpi.uni-potsdam.de/dls2007/ in PDF format. Submissions must not exceed 12 pages and need to use the ACM format, templates for which can be found at http://www.acm.org/sigs/pubs/proceed/template.html. Program chairs: *** * Pascal Costanza, Programming Technology Lab, Vrije Universiteit Brussel, Belgium * Robert Hirschfeld, Hasso-Plattner-Institut, University of Potsdam, Germany Program committee: ** * Gilad Bracha, Cadence Design Systems, USA * Johan Brichau, Universite Catholique de Louvain, Belgium * William Clinger, Northeastern University, USA * William Cook, University of Texas at Austin, USA * Pascal Costanza, Vrije Universiteit Brussel, Belgium * Stephane Ducasse, Universite de Savoie, France * Brian Foote, Industrial Logic, USA * Robert Hirschfeld, Hasso-Plattner-Institut Potsdam, Germany * Jeremy Hylton, Google, USA * Shriram Krishnamurthi, Brown University, USA * Michele Lanza, University of Lugano, Switzerland * Michael Leuschel, Universitaet Duesseldorf, Germany * Henry Lieberman, MIT Media Laboratory, USA * Martin von Loewis, Hasso-Plattner-Institut Potsdam, Germany * Philippe Mougin, OCTO Technology, France * Oscar Nierstrasz, University of Berne, Switzerland * Kent Pitman, PTC, USA * Ian Piumarta, Viewpoints Research Institute, USA * Nathanael Schaerli, Google, Switzerland * Anton van Straaten, AppSolutions.com, USA * Dave Thomas, Bedarra Research Labs, Canada * Dave Ungar, USA * Allen Wirfs-Brock, Microsoft, USA * Roel Wuyts, IMEC Unversite Libre de Bruxelles, Belgium -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 6 Mar 2007 08:42:00 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 5, 2:18 pm, Bruno Desthuilliers [EMAIL PROTECTED] wrote: Martin Unsal a écrit : For example, say you want to organize the widgets package as follows: widgets/scrollbar/*.py widgets/form/*.py widgets/common/util.py Other than messing around with PYTHONPATH, which is horrible, I don't see how to import util.py from the widget code. Some of us still manage to do so without messing with PYTHONPATH. How exactly do you manage it? The only way I can see to do it is to have widgets/__init__.py look something like this: from common import util from scrollbar import Scrollbar from form import Form Then Scrollbar.py doesn't have to worry about importing util, it just assumes that util is already present in its namespace. BUT ... this means that Scrollbar.py can only be loaded in the interpreter as part of package widgets. You can't run an interpreter and type import widgets.scrollbar.Scrollbar and start going to town, because Scrollbar doesn't import its own dependencies. So what I want to clarify here: Do Python programmers try to design packages so that each file in the package can be individually loaded into the interpreter and will automatically import its own dependencies? Or do you design packages so they can only be used by importing from the top level and running the top level __init__.py? I hope that made sense. :) Scrollbar *can't* assume that util will be present in its namespace, because it won't be unless it imports it. Scrollbar needs to import its own dependencies. But why do you think thats a problem? Martin -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphviz Python Binding for Python 2.5 on Windows?
Thanks all for your suggestions. Nick: I am trying to avoid generate the dot file manually so that I can minimize bugs coz by me ;) SPE: Unfortunately that may be too radical ;) I work in a corporate environment (read: MS shop) and my group wants to generate a dependency graph of our system. I was trying to take this opportunity to introduce some python to the group. They were amazed when I came up with the script in a few hours and were willing to try it out by installing python, yapgvb, and graphviz. But it won't work on python 2.5! It's kind of a bummer to tell them to install an older version of python. On second look, I will try pydot again. Despite no release for a long time, it seems to be reasonably complete. Now, I am sure we will redo it in C# after my prototype; but that will just prove the advantages of python in terms of code size and productivity :) -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 6, 6:07 am, Chris Mellon [EMAIL PROTECTED] wrote: Because you're advocating single class per file. What I actually said was Smallest practical functional block. I never said one class per file, in fact I generally have more than one class per file. Nonetheless I frequently have a class which has the same name as the file it's contained in, which is where I start having trouble. What you said was A scan through the standard library may be instructive, where there are some modules that expose a single class (StringIO, pprint) and others that expose many, and some that expose none at all. AHA! Here we see the insidious Python package system at work! ;) I said file and you assume that I am talking about the exposed namespace. Files should not have to be isomorphic with namespace! A package that exposes many classes may still use one class per file if it wants to. In any case, as I hinted at, I prefer an organic, developer driven approach to deciding these things, not handed down from above style guidelines. PRECISELY. And in the case of Python, package stucture is dictated, not by a style guideline, but by the design flaws of Python's package system. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting external IP address
Steven D'Aprano [EMAIL PROTECTED] wrote: I have a PC behind a firewall, and I'm trying to programmatically determine the IP address visible from outside the firewall. [ ... ] Can anyone help me fix that code snippet, or suggest another (better) way to get the externally visible IP address? Depending on your circumstances, it may be possible to just ask the firewall. You'll probably need some kind of administrator login, and may well have to parse HTML if it's only got a web interface, but it does mean that you don't have to connect to anything in the outside world. -- \S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/ ___ | Frankly I have no feelings towards penguins one way or the other \X/ |-- Arthur C. Clarke her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 6 Mar 2007 09:09:13 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 6, 6:07 am, Chris Mellon [EMAIL PROTECTED] wrote: Because you're advocating single class per file. What I actually said was Smallest practical functional block. I never said one class per file, in fact I generally have more than one class per file. Nonetheless I frequently have a class which has the same name as the file it's contained in, which is where I start having trouble. You do? Or do you only have trouble because you don't like using from foo import Foo because you need to do more work to reload such an import? What you said was A scan through the standard library may be instructive, where there are some modules that expose a single class (StringIO, pprint) and others that expose many, and some that expose none at all. AHA! Here we see the insidious Python package system at work! ;) I said file and you assume that I am talking about the exposed namespace. Files should not have to be isomorphic with namespace! A package that exposes many classes may still use one class per file if it wants to. What makes you think that the exposed namespace has to be isomorphic with the filesystem? Further, why do you think doing so is bad? People do it because it's convenient and simple, not because its necessary. Why don't you like filesystems? In any case, as I hinted at, I prefer an organic, developer driven approach to deciding these things, not handed down from above style guidelines. PRECISELY. And in the case of Python, package stucture is dictated, not by a style guideline, but by the design flaws of Python's package system. What design flaws are those? Is it because you're trying to have packages as part of your project without installing them on your PYTHONPATH somewhere? If you want to break a module internally into multiple files, then make it a package. To an importer, they're almost indistinguishable. If you want to break a module into multiple packages and then stick the files that make up the package in bizarre spots all over the filesystem, can you give a reason why? -- http://mail.python.org/mailman/listinfo/python-list
Re: Dialog with a process via subprocess.Popen blocks forever
In article [EMAIL PROTECTED], Gabriel Genellina [EMAIL PROTECTED] wrote: En Fri, 02 Mar 2007 14:38:59 -0300, Donn Cave [EMAIL PROTECTED] escribió: In article [EMAIL PROTECTED], Gabriel Genellina [EMAIL PROTECTED] wrote: On http://docs.python.org/lib/popen2-flow-control.html there are some notes on possible flow control problems you may encounter. It's a nice summary of one problem, a deadlock due to full pipe buffer when reading from two pipes. The proposed simple solution depends too much on the cooperation of the child process to be very interesting, though. The good news is that there is a real solution and it isn't terribly complex, you just have to use select() and UNIX file descriptor I/O. The bad news is that while this is a real problem, it isn't the one commonly encountered by first time users of popen. More bad news: you can't use select() with file handles on Windows. Bad news about UNIX I/O on Microsoft Windows is not really news. I am sure I have heard of some event handling function analogous to select, but don't know if it's a practical solution here. If you have no control over the child process, it may be safer to use a different thread for reading its output. Right - `I used threads to solve my problem, and now I have two problems.' It can work for some variations on this problem, but not the majority of them. Any pointers on what kind of problems may happen, and usual solutions for them? On Windows one could use asynchronous I/O, or I/O completion ports, but neither of these are available directly from Python. So using a separate thread for reading may be the only solution, and I can't see why is it so bad. (Apart from buffering on the child process, which you can't control anyway). I wouldn't care to get into an extensive discussion of the general merits and pitfalls of threads. Other than that ... let's look at the problem: - I am waiting for child process buffered output - I have no control over the child process Therefore I spawn a thread to do this waiting, so the parent thread can continue about its business. But assuming that its business eventually does involve this dialogue with the child process, it seems that I have not resolved that problem at all, I've only added to it. I still have no way to get the output. Now if you want to use threads because you're trying to use Microsoft Windows as some sort of a half-assed UNIX, that's a different issue and I wouldn't have any idea what's best. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 6, 8:56 am, Chris Mellon [EMAIL PROTECTED] wrote: Scrollbar *can't* assume that util will be present in its namespace, because it won't be unless it imports it. Scrollbar needs to import its own dependencies. But why do you think thats a problem? OK, maybe I'm totally missing something here, but you can't do import ../util/common in Python can you? Look at the directory structure in my original post. How does Scrollbar.py import its dependencies from common.py, without relying on PYTHONPATH? Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 6 Mar 2007 09:24:32 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 6, 8:56 am, Chris Mellon [EMAIL PROTECTED] wrote: Scrollbar *can't* assume that util will be present in its namespace, because it won't be unless it imports it. Scrollbar needs to import its own dependencies. But why do you think thats a problem? OK, maybe I'm totally missing something here, but you can't do import ../util/common in Python can you? Look at the directory structure in my original post. How does Scrollbar.py import its dependencies from common.py, without relying on PYTHONPATH? It assumes that util.common is a module thats on the PYTHONPATH. The common way to ensure that this is the case is either to handle util as a separate project, and install it into the system site-packages just as you would any third party package, or to have it (and all your other application packages and modules) off a single root which is where your your application base scripts live. This, and other intra-package import issues are affected by the relative/absolute import changes that were begun in Python 2.5, you can read about them here: http://www.python.org/dev/peps/pep-0328/ Note that using relative imports to import a package that happens to be share a common higher level directory would be frowned upon. The blessed mechanism would still be to use an absolute import, and to install the other package on the PYTHONPATH in one of any number of ways. -- http://mail.python.org/mailman/listinfo/python-list
Re: askstring Window to the top under Windows
iwl kirjoitti: On 6 Mrz., 14:48, Tim Golden [EMAIL PROTECTED] wrote: On Mar 6, 1:13 pm, iwl [EMAIL PROTECTED] wrote: It's not clear whether you're talking about the usual Why do I get a DOS window when I run my python script? question -- to which the answer is, in essence, change your script's extension to .pyw or use the pythonw.exe executable -- or Why _when I use askstring_ do I get an empty window?. If it's the latter, then I don't know, but can you provide a small example script which exhibits the behaviour. TJG import tkSimpleDialog tkSimpleDialog.askstring(a,b) at the python Console under XP (not pythonw). - instead of only showing the Inputwindow at the top, some additional empty window is shown, both not on top. I assumed that by python Console you mean the IDLE editor/interpreter. I entered your 2 lines and the behaviour is the same on Win XP. I doubt it has nothing to do with the OS, though. (A word of warning but don't tell anyone: I've never used Tkinter, I use wxPython!) Every GUI implementation has a command loop and things to initiate the correct execution environment. I think that's what you are missing here and that's causing the odd behaviour. I found an example (16.1.2.2 A Simple Hello World Program) in Python 2.4 and modified as shown: #=== from Tkinter import * import tkSimpleDialog # === modification here class Application(Frame): def say_hi(self): print hi there, everyone! def createWidgets(self): self.QUIT = Button(self) self.QUIT[text] = QUIT self.QUIT[fg] = red self.QUIT[command] = self.quit self.QUIT.pack({side: left}) self.hi_there = Button(self) self.hi_there[text] = Hello, self.hi_there[command] = self.say_hi self.hi_there.pack({side: left}) def __init__(self, master=None): Frame.__init__(self, master) self.pack() self.createWidgets() root = Tk() app = Application(master=root) app.mainloop() tkSimpleDialog.askstring(a,b) # === modification here root.destroy() #=== If you run it, it first shows the Hello dialog and after clicking the QUIT button, your askstring gets run. So: nothing wrong with Python, Tkinter or tkSimpleDialog.askstring. Just carry on having fun with Python! HTH, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: askstring Window to the top under Windows
Jussi Salmela kirjoitti: snip Every GUI implementation has a command loop and things to initiate the OOPS: an EVENT loop Cheers, Jussi -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Diez B. Roggisch a écrit : I'd like to point out something though. More than one of the people who responded have implied that I am bringing my prior-language mindset to Python, even suggesting that my brain isn't built for Python. ;) In fact I think it's the other way around. I am struggling to take full advantage of the fact that Python is an interpreted language, to use Python in the most Pythonic way. You guys are telling me that's broken and I should go back to a workflow that is identical in spirit, and not necessarily any faster than I would use with a compiled language. While that might be the right answer in practice, I don't feel like it's a particularly good answer, and it confirms my initial impression that Python package management is broken. I think you should be asking yourselves, Did we all abandon reload() because it is actually an inferior workflow, or just because it's totally broken in Python? Sorry, but I fail to see the point of your argumentation. Reloading a module means that you obviously have some editor open you code your module in, and an interactive interpreter running where you somehow have to make the reload(module) line (re-)appear, and then most probably (unless the pure reloading itself triggers some testing code) some other line that e.g. instantiates a class defined in module Now how exactly does that differ from having a test.py file containing import module do-something and a commandline sitting there with a python test.py Actually, make it python -i test.py Then you have test.py executed, and your interactive interpreter up and ready in the desired state. -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 6, 9:19 am, Chris Mellon [EMAIL PROTECTED] wrote: You do? Or do you only have trouble because you don't like using from foo import Foo because you need to do more work to reload such an import? More work, like rewriting __import__ and reload??? :) There's a point where you should blame the language, not the programmer. Are you saying I'm lazy just because I don't want to mess with __import__? What makes you think that the exposed namespace has to be isomorphic with the filesystem? I don't; you do! I was clearly talking about files and you assumed I was talking about namespace. That's Pythonic thinking... and I don't mean that in a good way! If you want to break a module into multiple packages and then stick the files that make up the package in bizarre spots all over the filesystem, can you give a reason why? Because I have written a project with 50,000 lines of Python and I'm trying to organize it in such a way that it'll scale up cleanly by another order of magnitude. Because I've worked on projects with millions of lines of code and I know about how such things are organized. It's funny, I'm a newbie to Python but it seems like I'm one of the only people here thinking about it as a large scale development language rather than a scripting language. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 6, 9:46 am, Dennis Lee Bieber [EMAIL PROTECTED] wrote: The only usage I've ever made of reload() has been during interactive debugging: Modify the module, then reload it at the interactive prompt so I could create an instance of the modified code, and manually manipulate it. That's exactly what I want to do. That's exactly what I'm having trouble with. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 6 Mar 2007 09:49:55 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 6, 9:19 am, Chris Mellon [EMAIL PROTECTED] wrote: You do? Or do you only have trouble because you don't like using from foo import Foo because you need to do more work to reload such an import? More work, like rewriting __import__ and reload??? :) There's a point where you should blame the language, not the programmer. Are you saying I'm lazy just because I don't want to mess with __import__? You have to reload the importing module as well as the module that changed. That doesn't require rewriting the import infrastructure. It's only an issue because you're changing things at one level but you're trying to use them at a level removed from that. I never work that way, because I only have any need or desire to reload when I'm working interactively and I when I'm doing that I work directly with the modules I'm changing. The interfaces are what my unit tests are for. If you're doing stuff complicated and intricate enough in the interpreter that you need reload() to do very much more than its doing, then you're working poorly - that sort of operation should be in a file you can run and test automatically. What makes you think that the exposed namespace has to be isomorphic with the filesystem? I don't; you do! I was clearly talking about files and you assumed I was talking about namespace. That's Pythonic thinking... and I don't mean that in a good way! All the files on the PYTHONPATH will map into the namespace. However, you can have items in the namespace that do not map to files. The main reasons to do so are related to deployment, not development though so I wonder why you want to. If you want to break a module into multiple packages and then stick the files that make up the package in bizarre spots all over the filesystem, can you give a reason why? Because I have written a project with 50,000 lines of Python and I'm trying to organize it in such a way that it'll scale up cleanly by another order of magnitude. Because I've worked on projects with millions of lines of code and I know about how such things are organized. It's funny, I'm a newbie to Python but it seems like I'm one of the only people here thinking about it as a large scale development language rather than a scripting language. Thats not answering the question. Presumably you have some sort of organization for your code in mind. What about that organization doesn't work for Python? If you want multiple files to map to a single module, make them a package. -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 6, 9:34 am, Chris Mellon [EMAIL PROTECTED] wrote: It assumes that util.common is a module thats on the PYTHONPATH. Now we're getting somewhere. :) The common way to ensure that this is the case is either to handle util as a separate project, and install it into the system site-packages just as you would any third party package, This breaks if you ever need to test more than one branch of the same code base. I use a release branch and a development branch. Only the release branch goes into site-packages, but obviously I do most of my work in the development branch. or to have it (and all your other application packages and modules) off a single root which is where your your application base scripts live. This has SERIOUS scaling problems. This, and other intra-package import issues are affected by the relative/absolute import changes that were begun in Python 2.5, you can read about them here:http://www.python.org/dev/peps/pep-0328/ Awesome! Thanks. I'll take a look. Note that using relative imports to import a package that happens to be share a common higher level directory would be frowned upon. What if it shares a common higher level directory by design? :) Relative imports aren't ideal, but I think in some cases it's better than relying on PYTHONPATH which is global state (an environment variable no less). Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Using string as file
On Mar 5, 8:13 pm, Florian Lindner [EMAIL PROTECTED] wrote: Hello, I have a function from a library thast expects a file object as argument. How can I manage to give the function a string resp. have the text it would have written to file object as a string? Thanks, Florian You can also look at example 3 here: http://en.wikipedia.org/wiki/Doctest#Example_3:_unique_words.py - Paddy. -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
Martin Unsal [EMAIL PROTECTED] wrote: We could discuss this till we're blue in the face but it's beside the point. For any given project, architecture, and workflow, the developers are going to have a preference for how to organize the code structurally into files, directories, packages, etc. The language itself should not place constraints on them. I agree. For example, say you want to organize the widgets package as follows: widgets/scrollbar/*.py widgets/form/*.py widgets/common/util.py One possibility is to have one module for each namespace that you want, and compose each module out of multiple files by using execfile(). -M- -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 6 Mar 2007 10:30:03 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 6, 9:34 am, Chris Mellon [EMAIL PROTECTED] wrote: It assumes that util.common is a module thats on the PYTHONPATH. Now we're getting somewhere. :) The common way to ensure that this is the case is either to handle util as a separate project, and install it into the system site-packages just as you would any third party package, This breaks if you ever need to test more than one branch of the same code base. I use a release branch and a development branch. Only the release branch goes into site-packages, but obviously I do most of my work in the development branch. Theres a number of solutions. They do involve manipulation of PYTHONPATH or creation of infrastructure, though. I find that I generally work against only one version of package at a time, so it's not any trouble for me to create a local directory that has all the version I'm working against. Testing infrastructure manipulates PYTHONPATH to ensure it's testing the version its supposed to. or to have it (and all your other application packages and modules) off a single root which is where your your application base scripts live. This has SERIOUS scaling problems. If you have lots of modules used by lots of things it can be. Not necessarily though, it depends on how you package and deploy them. It's often the best solution to the above issue when it comes to testing, though. This, and other intra-package import issues are affected by the relative/absolute import changes that were begun in Python 2.5, you can read about them here:http://www.python.org/dev/peps/pep-0328/ Awesome! Thanks. I'll take a look. Note that using relative imports to import a package that happens to be share a common higher level directory would be frowned upon. What if it shares a common higher level directory by design? :) Then its a subpackage of a parent package. That's different than just walking up to wherever your did your RCS checkout. Relative imports aren't ideal, but I think in some cases it's better than relying on PYTHONPATH which is global state (an environment variable no less). Environment and manipulation of it is the job of the top level script/application/whatever. Modules/packages/whatever should rely on PYTHONPATH being sane. Martin -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting external IP address
I have a PC behind a firewall, and I'm trying to programmatically determine the IP address visible from outside the firewall. Steven Following is another alternative that might at least be worth consideration I use the lynx command shown as a command-line alias under Debian linux import os pipe_in = os.popen( 'lynx --dump http://checkip.dyndns.org' ) ip_addr = pipe_in.readlines() for this in ip_addr : ... print this ... Current IP Address: 65.39.92.38 -- Stanley C. Kitching Human Being Phoenix, Arizona == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On Mar 6, 10:13 am, Chris Mellon [EMAIL PROTECTED] wrote: You have to reload the importing module as well as the module that changed. That doesn't require rewriting the import infrastructure. As far as I can tell, the moment you use from foo_module import bar, you've broken reload(). Reloading higher level packages doesn't help. The only practical solution I can see is to rewrite __import__ and reload. Thats not answering the question. Presumably you have some sort of organization for your code in mind. I already gave a simple example. I thought you were asking why I would want to organize code that way, and the only short answer is experience. I'd prefer not to try to formulate a long answer because it would be time consuming and somewhat off topic, but we can go there if necessary. Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: When will 2.5.1 be released?
On Mar 4, 2:49 pm, Nile [EMAIL PROTECTED] wrote: This is not a big deal but I would like to use Tix with 2.5. My understanding is this bug will be fixed in the 2.5.1 release. Does And while we're waiting for 2.5.1, can somebody post a clear (as opposed to the one that comes with Tix ;)) explanation of how to manually install Tix into python 2.5? It should be possible... -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
On 6 Mar 2007 10:58:14 -0800, Martin Unsal [EMAIL PROTECTED] wrote: On Mar 6, 10:13 am, Chris Mellon [EMAIL PROTECTED] wrote: You have to reload the importing module as well as the module that changed. That doesn't require rewriting the import infrastructure. As far as I can tell, the moment you use from foo_module import bar, you've broken reload(). Reloading higher level packages doesn't help. The only practical solution I can see is to rewrite __import__ and reload. Example: a.py AExport = object() b.py from a import AExport class Object(object): pass BExport = Object() BExport.a = AExport interpreter session: import b b.AExport object object at 0x009804A8 b.BExport.a object object at 0x009804A8 import a a.AExport object object at 0x009804A8 changed a.py such that AExport = list() 'changed a.py such that AExport = list()' reload(b) module 'b' from 'b.pyc' b.AExport object object at 0x009804A8 note no change 'note no change' reload(a) module 'a' from 'a.py' b.AExport object object at 0x009804A8 note still no change 'note still no change' reload(b) module 'b' from 'b.pyc' b.AExport [] now its changed 'now its changed' b.BExport.a [] -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting external IP address
The above suggestions seem nice, but I find this one easier: import urllib2 ext_ip = urllib2.urlopen('http://whatismyip.org/').read() print ext_ip The nice thing about the above code is that http://whatismyip.org/ only contains exactly what you want (the ip, nothing more, nothing less), so no parsing is necessary Best, Sergio On 3/6/07, Cousin Stanley [EMAIL PROTECTED] wrote: I have a PC behind a firewall, and I'm trying to programmatically determine the IP address visible from outside the firewall. Steven Following is another alternative that might at least be worth consideration I use the lynx command shown as a command-line alias under Debian linux import os pipe_in = os.popen( 'lynx --dump http://checkip.dyndns.org' ) ip_addr = pipe_in.readlines() for this in ip_addr : ... print this ... Current IP Address: 65.39.92.38 -- Stanley C. Kitching Human Being Phoenix, Arizona == Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News== http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups = East and West-Coast Server Farms - Total Privacy via Encryption = -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: Descriptor/Decorator challenge
On 5 Mar, 18:59, Arnaud Delobelle [EMAIL PROTECTED] wrote: [snip] Well in fact I couldn't help but try to improve it a bit. Objects now don't need a callerclass attribute, instead all necessary info is stored in a global __callerclass__. Bits that didn't work now do. OK that wasn't really thought through. Because I changed the design mid-way through writing it __callerclass__ wasn't doing the right thing. I've sorted the issues I could see and made it (hopefully) thread-safe. I'm not going to pollute this list again with my code so I've put it at the following address: http://marooned.org.uk/local.py The problem is that all normal functions need to be decorated with '@function' for it to work completely: if I understand correctly the snippet below should raise an exception. It only does so if 'f' is decorated with '@function' as below. -- @function def f(x): x.l() class C(Object): @localmethod def l(self): print Shouldn't get here def v(self): return f(self) C().v() # Raises LocalMethod exception -- PS: in fact I'm not sure it's a good idea to decorate local methods: what about local attributes which are not methods? They have to be treated differently as only functions can be decorated. What about functions / classes which are local to a module? -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list
using python to query active directory
Is it possible to use python to make calls agains microsoft active directory? I suppose this should be qualified by what is needed to do it from windows (I assume the win32all package) and from linux (if possible). Any code samples would be great. -- David Bear -- let me buy your intellectual property, I want to own your thoughts -- -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
In article [EMAIL PROTECTED], Martin Unsal [EMAIL PROTECTED] wrote: I'm using Python for what is becoming a sizeable project and I'm already running into problems organizing code and importing packages. I feel like the Python package system, in particular the isomorphism between filesystem and namespace, doesn't seem very well suited for big projects. However, I might not really understand the Pythonic way. I'm not sure if I have a specific question here, just a general plea for advice. 1) Namespace. Python wants my namespace heirarchy to match my filesystem heirarchy. I find that a well organized filesystem heirarchy for a nontrivial project will be totally unwieldy as a namespace. I'm either forced to use long namespace prefixes, or I'm forced to use from foo import * and __all__, which has its own set of problems. 1a) Module/class collision. I like to use the primary class in a file as the name of the file. However this can lead to namespace collisions between the module name and the class name. Also it means that I'm going to be stuck with the odious and wasteful syntax foo.foo everywhere, or forced to use from foo import *. The issue of module names vs contained class names is one thing I find a bit frustrating about python. Fortunately it is fairly easy to work around. My own solution has been to import up just one level. So for example: pkg/subpkg/foo.py defines class foo and associated stuff pkg/subpkg/bar.py defines class bar pkt/subpkg/__init__.py contains: from foo import * from bar import * To use this I then do: import pkg.subpkg myfoo = pkg.subpkg.foo(...) But that's the only from x import that I do. I never raise stuff from a sub-package to a higher level. Once you do this (or in some other way eliminate the foo.foo problem), I think you will find that python namespaces work very well for large projects. Overall I personally like having the namespace follow the file structure (given that one has to use source files in the first place; my smalltalk roots are showing). Java reportedly does much the same thing and it is very helpful for finding code. I'm sure it's partly what you're used to that counts. C++ experts probably enjoy the freedom of C++ namespaces, but to me it's just a pain that they are totally independent of file structure. 1b) The Pythonic way seems to be to put more stuff in one file, but I believe this is categorically the wrong thing to do in large projects. The moment you have more than one developer along with a revision control system, you're going to want files to contain the smallest practical functional blocks. I feel pretty confident saying that put more stuff in one file is the wrong answer, even if it is the Pythonic answer. I don't personally find that python encourages lots of code per file. I think this perception only stems from (1a) and once you solve that you'll find it's fine to divide your code into small files. 2) Importing and reloading. I want to be able to reload changes without exiting the interpreter. This pretty much excludes from foo import *, unless you resort to this sort of hack: http://www.python.org/search/hypermail/python-1993/0448.html Has anyone found a systematic way to solve the problem of reloading in an interactive interpreter when using from foo import *? I totally agree here. This is a real weakness to python and makes it feel much more static than it ought to be. I know of no solution other than restarting. That tends to be fast, but it can be a pain to get back to where you were. Smalltalk solved this problem long ago in a way that makes for very dynamic development and debugging. Unfortunately few languages have followed suit. The Smalltalk development environment is the one feature I really miss in all other languages I've used (I certainly don't miss its quirky syntax for control flow :)). -- Russell -- http://mail.python.org/mailman/listinfo/python-list
calendar (date) iterator?
Hi, I'm looking for useful starting points, suggestions, and sample code, to implement a calendar iterator. Simply, the iterator is seeded with an initial calendar date, e.g., 03-12-2006, and then subsequent calls to next return subsequent dates. The seed could be a standard calendar/datetime object. iter = calendarIterator(03-12-2006) print iter.next() 03-12-2006 A useful extension would be to allow specifiation of iter intervals, e.g., iter = calendarIterator(03-12-2006 01:00:00, minutes) print iter.next() 03-12-2006 01:01:00 Thanks in advance for pointers and suggestions! -- http://mail.python.org/mailman/listinfo/python-list
Re: Interface Implementation in Python
I would like to know the interface concept in Python.How the Interface is defined and implemented in Python?. One way I have implemented interfaces, is as follows: class MyInterface(object): def someMethod(self, argument): raise NotImplementedError() If anybody ever uses that class directly, or subclasses it without implementing a real version of that method, a runtime error can be expected. This bridges both interfaces and abstract classes. As others have pointed out, this isn't quite like a Java interface, but I have found it useful to state my intentions up front, and that is how I do it. The only way to truly enforce this is by following up with lots of good test cases, run often. -- http://mail.python.org/mailman/listinfo/python-list
Re: calendar (date) iterator?
Oops-- the iter needs to work better than I do! :) iter = calendarIterator(03-12-2006) print iter.next() 03-12-2006 ^^ 03-13-2006 iter = calendarIterator(03-12-2006 01:00:00, minutes) print iter.next() 03-12-2006 01:01:00 ^^ 03-13-2006 -- http://mail.python.org/mailman/listinfo/python-list
Re: using python to query active directory
On Mar 6, 1:34 pm, David Bear [EMAIL PROTECTED] wrote: Is it possible to use python to make calls agains microsoft active directory? I suppose this should be qualified by what is needed to do it from windows (I assume the win32all package) and from linux (if possible). Any code samples would be great. Tim Golden is your man. http://tgolden.sc.sabren.com/python/active_directory.html HTH ... Jay Graves -- http://mail.python.org/mailman/listinfo/python-list
Re: This web site creates a *popup window* = how fetch contents in a script?
On Mar 5, 10:38 pm, Gabriel Genellina [EMAIL PROTECTED] wrote: En Tue, 06 Mar 2007 03:18:23 -0300, [EMAIL PROTECTED] [EMAIL PROTECTED] escribió: The following web page puts a report in a *popup window* by clicking the Generate Report button http://moneycentral.msn.com/investor/research/printrep.asp?Symbol=BBBY How can I grab this pop window page in a python script? (It doesn't seem to have a URL!?!) Of course it has:http://moneycentral.msn.com/investor/research/sreport.asp?Symbol=BBBY... If your browser don't let you know the actual URL... try a better browser :) -- Gabriel Genellina Sure I can grab the aforementioned URL's contents but what about the NEW contents in the NEW popup window that appears AFTER you press some form buttons? How grab *that* ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Project organization and import
In article [EMAIL PROTECTED], Martin Unsal [EMAIL PROTECTED] wrote: On Mar 6, 9:34 am, Chris Mellon [EMAIL PROTECTED] wrote: It assumes that util.common is a module thats on the PYTHONPATH. Now we're getting somewhere. :) The common way to ensure that this is the case is either to handle util as a separate project, and install it into the system site-packages just as you would any third party package, This breaks if you ever need to test more than one branch of the same code base. I use a release branch and a development branch. Only the release branch goes into site-packages, but obviously I do most of my work in the development branch. This is an interesting point that we are just facing. If you have a big package for all your stuff and you want to separately version components of it, you do run into problems. The solution we are adopting is to write a custom import hook, but a simpler solution is to make sure each separately versioned component is a top-level package (in which case you can manipulate PYTHONPATH to temporarily install a test version). -- Russell -- http://mail.python.org/mailman/listinfo/python-list
Re: How to Read Bytes from a file
Gabriel Genellina [EMAIL PROTECTED] writes: En Fri, 02 Mar 2007 08:22:36 -0300, Bart Ogryczak [EMAIL PROTECTED] escribió: On Mar 1, 7:36 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks Bart. That's perfect. The other suggestion was to precompute count1 for all possible bytes, I guess that's 0-256, right? 0-255 actually. It'd be worth it, if accessing dictionary with precomputed values would be significantly faster then calculating the lambda, which I doubt. I suspect it actually might be slower. Dictionary access is highly optimized in Python. In fact, using a precomputed dictionary is about 12 times faster: Why using a dictionary and not a list? Matthias -- http://mail.python.org/mailman/listinfo/python-list
Re: calendar (date) iterator?
Marcus I'm looking for useful starting points, suggestions, and sample Marcus code, to implement a calendar iterator. Have you looked at dateutil? http://labix.org/python-dateutil from dateutil.rrule import rrule, DAILY from dateutil.parser import parse rule = rrule(DAILY, count=5, dtstart=parse(2006-03-12)) for d in rule: ... print d ... 2006-03-12 00:00:00 2006-03-13 00:00:00 2006-03-14 00:00:00 2006-03-15 00:00:00 2006-03-16 00:00:00 Skip -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphviz Python Binding for Python 2.5 on Windows?
On Mar 5, 5:16 pm, Alex Li [EMAIL PROTECTED] wrote: I tried to avoid. Any suggestions? try the networkx package, it includes the pygraphviz module that can generate dot files: https://networkx.lanl.gov/wiki Istvan -- http://mail.python.org/mailman/listinfo/python-list
Re: Graphviz Python Binding for Python 2.5 on Windows?
On Mar 6, 3:18 pm, Istvan Albert [EMAIL PROTECTED] wrote: try the networkx package, it includes the pygraphviz module that can generate dot files: https://networkx.lanl.gov/wiki should've checked it before posting, it seems nowadays is actually a separate package https://networkx.lanl.gov/wiki/pygraphviz -- http://mail.python.org/mailman/listinfo/python-list
Re: This web site creates a *popup window* = how fetch contents in a script?
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: Sure I can grab the aforementioned URL's contents but what about the NEW contents in the NEW popup window that appears AFTER you press some form buttons? How grab *that* ? Usually it's from some fixed url with possibly some query parameters. Just figure out the url from your Properties in your browser, or by studying the javascript that popped up the window. There are various ways the popup sites can make this difficult but it's rare for them to bother. -- http://mail.python.org/mailman/listinfo/python-list
Re: Webserver balance load
Johny [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Can anyone suggest a way how to balance load on Apache server where I have Python scripts running? For example I have 3 webservers( Apache servers) and I would like to sent user's request to one of the three server depending on a load on the server. Thank you . L. I believe you can do this with mod_proxy and mod_proxy_balancer within apache itself. I have not tried it, but the documentation is here: http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting external IP address
On Tue, 06 Mar 2007 14:40:37 -0500, Sergio Correia wrote: The above suggestions seem nice, but I find this one easier: [snip] Thanks to everybody who replied, that's great. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list