Making extension modules play nice with help()?
I've always provided doc strings through PyMethodDef in the past, without paying much attention to what happens in help() - they print fine when you just use the doc string. However, in help, you end up with methods that have an indeterminate signature. We generally make doc strings that look like: get_root_calls() - [ptv.Call, ...] Returns all root calls for transactions in the trace. Which works fine if you just print get_root_calls().__doc__ or somesuch, but works out quite lousy if you use help(): | get_root_calls(...) | get_root_calls() - [ptv.Call, ...] | Returns all root calls for transactions in the trace. So we end up with the method signature twice - once from help(), which is meaningless (assuming a non-empty argument list), and once from the doc string, which is actually useful. Is there any way to either a) teach the proper method signature to help(), or b) override it. Also, while PyMethodDef has a nice place to put a doc string, PyMappingMethods and tp_iter have no such place, and so we end up with things like: | __getitem__(...) | x.__getitem__(y) == x[y] | | __iter__(...) | x.__iter__() == iter(x) Which is decidedly unhelpful. Can I grab the Type after it has been readied and replace some attributes somewhere to put new strings in these places? Of course, I can always cover the C extension module in a thin veneer of python, but that starts to become a significant performance problem (not to mention a maintenance nightmare). -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on Leopard issues
On Nov 8, 2007 4:59 PM, Nicholas Bastin [EMAIL PROTECTED] wrote: Also, Apple distributes the standard library in a zip file, so you won't find all the packages just lying around. They should all be stored in /Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip. I'll eat my words on this one. In Leopard the standard library is all .py files in /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Python on Leopard issues
On Nov 8, 2007 4:13 PM, Chris [EMAIL PROTECTED] wrote: Are others having fundamental issues on OSX 10.5 with python 2.5.1? I was excited that Python 2.5 was included, but this excitement was very short lived. Almost nothing works. Upon startup I get this message: 'import site' failed; use -v for traceback and sure enough, all of the built-in packages are non-existent. I'm not sure why Apple bothered including an improperly-configured version. Does anyone have an easy fix for this, or should I go to ActiveState and install a version that works? A fresh full install of leopard does not have this problem, nor does my machine with a simple upgrade. Typically when import site fails, your environment is screwed up. Does 'which python' give you: /Library/Frameworks/Python.framework/Versions/Current/bin/python? Also, Apple distributes the standard library in a zip file, so you won't find all the packages just lying around. They should all be stored in /Library/Frameworks/Python.framework/Versions/2.5/lib/python25.zip. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Carl Banks [EMAIL PROTECTED] wrote: Now, a C++ API for CPython would necessarily be built on top of the C API, which carries some limitations relative to the OOP abilities of C++ itself. It wouldn't have to be, although it'd be much more of a maintenance nightmare if it poked into the Python internals. But you shouldn't expect anything like the ability to freely inherit between C++ and Python classes. You can do this with Boost.Python. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: C++ version of the C Python API?
On 10/21/07, Robert Dailey [EMAIL PROTECTED] wrote: On 10/21/07, Martin v. Löwis [EMAIL PROTECTED] wrote: No, I literally meant that the Python C API is object-oriented. You don't need an object-oriented language to write object-oriented code. I disagree with this statement. C is not an object oriented language, and I've seen attempts to make it somewhat object oriented, however it failed miserably in readability and manageability overhead. However, this isn't the place to discuss such a thing so I've got nothing more to say than that. Object-oriented programming is a design choice, not a language feature. You can write straight procedural code in C++, and you can write object oriented code in C. Sure, C++ has some language features which facilitate object-oriented programming, but it doesn't magically make your code object-oriented. You can certainly write basic object-oriented code in C and hide most of the implementation in preprocessor macros if you so desire. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz has so many timezones!
On 10/9/07, Sanjay [EMAIL PROTECTED] wrote: It's not clear at all from the OPs post exactly what functionality he is trying to derive from the timezone. Since timezones (obviously) contain more information than just the GMT offset (otherwise we wouldn't even have them), he may very well want to use the timezone given by the user to display correct local time to them. In this case, the actual, correct, political timezone is important, not just the GMT offset. I am developing a website which would be accessed by members all over the world. They can exchange data having some time fields, say 'schedule for next meeting'. Whenever somebody feeds some time field, my application converts it to UTC and stores in the database. Later, when the data is to be displayed to some member, the application converts it to his local time, and displays the data. Yeah, you are, unfortunately, probably going to have to deal with the entirety of this time zone data in this case. You can obviously elide some information for countries you don't intend to support, but there's no particular reason to exclude a potential market. I would say the easiest way to get people to choose their own time zone is to ask them their country, and then filter their choices by that. (That would get you down to less than a dozen choices in almost every country in the world). -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz has so many timezones!
On 10/9/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Oct 8, 8:27?pm, Nicholas Bastin [EMAIL PROTECTED] wrote: On 10/8/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Because they publish maps? I'm not sure what this has to do with it. Maybe you've never had to navigate? I don't often find the need to navigate by time zone. Nor do cartographers consider themselves experts on time, but rather geography. WHY must we accomodate the ignorant? Why not cut them off from the Internet until they get their act together? Don't people get mad at Microsoft for breaking standards? People like you are to blame for accomodating broken standards. Oh, no, we can't afford to lose those three potential customers who live on an island in Kiribati! There's no broken standard here. I'd advise you to refrain from painting other people with your own ignorant brush. If I schedule a meeting with someone in Indiana, and I'm in Ohio, they're in the same military time zone, but they don't observe daylight savings time, so in fact our times are different. Users probably want our applications to handle these problems. Isn't that what they call a locale? No. If we spoke a different language or used a different script, that'd be a different locale. Of course, we might still be in the same time zone. Since timezones (obviously) contain more information than just the GMT offset Of course. But the GMT offset could be used to filter his list of 400 choices, couldn't it? Sortof. First, your user has to understand what GMT is, And you start that education by learning the 25 timezones. Then when you understand that, you can then learn about locales. Just because NATO thinks there's 25 time zones doesn't mean that they're any more correct than all of the local entities which have defined their own time zones. And again, your usage of the word 'locale' bears no relationship to the actual definition, in computer science terms. so that's already going to cause problems. Secondly, you need to handle time zones which drift from different GMT offsets depending on the time of year. It helps to know what you're drifting from. You're drifting from UTC. UTC which has no bearing nor controlling influence on time zone definitions. Just because government entities reference +/- UTC in time zone definitions does not mean that they're substantially related. At the very least your algorithm needs to be greedy. How good an algorithm do you think the OP will come up with if he doesn't understand why his list has 400 items or has any clue how to reduce it? I didn't presume the OP was an idiot. I felt that it was much more reasonable to explain how the 400 differed then to paint for him a fairy tale of 25 magical time zones, which had no bearing on his application. There are many ways to filter the 400 based on the needs of each application, and I leave it as an exercise to the OP to either deduce the appropriate ones, or ask more questions. Why not teach him the truth, starting from the top level? Shouldn't you teach him to fish rather than just give him one? Because the truth is that there are upwards of 400 different time zones, Locales. No, locale has already been defined by the computer science community, and it doesn't involve time zones. There are, realistically, less than 400 locales. Do not confuse the two. (Locales can be consistent across many time zones - see en_US for a trivial example). Locales are coded by language, script, country, and a variant, and do not contain time zone information. There is no central authority which defines global time zones. The functional definition of a time zone is merely a geographical area of the earth that has adopted the same local time rules. So, you can live your life with functional definations, never bothering to learn any theory? Is code monkey all you aspire to? Well, I certainly don't aspire to be a stuck up ass, which is apparently what you've been working towards. There is no magical theory behind time zones. There is no one truth, and there is no controlling global regulation. Does NATO have a simple time zone implementation? Absolutely. Is that relevant to most consumer applications? Absolutely not. When you write applications for the military, feel free to adhere to their standards. When you write applications for an international community, you might want to put the bigotry aside and cater to their actual needs. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Mixing Python and C classes in a module
On 10/9/07, Chris Mellon [EMAIL PROTECTED] wrote: On 09 Oct 2007 16:56:30 +0200, Stefan Arentz [EMAIL PROTECTED] wrote: Is it possible to mix classes defined in both Python and C in the same module? Ideally I would like to be able to do: from some.module import MyPythonClass, MyCClass I guess that would mean that this would look like this on disk: some/ __init__.py module.py (contains MyPythonClass) module.so (contains MyCClass) But would this work? No, you'll need to make module a package, and import from (differently named) implementation packages. Nah, you can do it, just not in this way. You can either futz with ihooks, or name module.py something like _module.py, import it into C, and then re-export as 'module', after attaching all your C types. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: pytz has so many timezones!
On 10/8/07, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: What do you mean by the military and why do you think they're authoritative on the topic of timezones? Because they publish maps? I'm not sure what this has to do with it. but as far as I know they don't define timezones. Ok, maybe they don't define them. But they get them from somewhere and the zones are labeled A-Z (don't ask which letter isn't used). Zone Z is equivalent to GMT and the time is refered to as Zulu time. They get them from NATO. NGO's outside of NATO do not use NATO time zones for describing time data, mostly because NATO doesn't care about daylight savings time. Works fine for the military, but not so well for your civilian users. That's 25 zones, not 400. Under that system there are no half-hour offset zones, no zones based on sunset and no lunatic GMT+13 zones. Yes, but lucky for us, we live in the real world, so we have to deal with 400 time zones. The reality is that people LIVE in those 'lunatic' time zones, and software needs to address that. If I schedule a meeting with someone in Indiana, and I'm in Ohio, they're in the same military time zone, but they don't observe daylight savings time, so in fact our times are different. Users probably want our applications to handle these problems. Since timezones (obviously) contain more information than just the GMT offset Of course. But the GMT offset could be used to filter his list of 400 choices, couldn't it? Sortof. First, your user has to understand what GMT is, so that's already going to cause problems. Secondly, you need to handle time zones which drift from different GMT offsets depending on the time of year. At the very least your algorithm needs to be greedy. Agreed. But if someone gave me a list of 400 choices, I would look for some way to reduce the list to a manageable choice. Isn't that what the OP wants? Why not teach him the truth, starting from the top level? Shouldn't you teach him to fish rather than just give him one? Because the truth is that there are upwards of 400 different time zones, accounting for local custom and law. The military can conveniently ignore that, but we as application writers cannot. There is no central authority which defines global time zones. The functional definition of a time zone is merely a geographical area of the earth that has adopted the same local time rules. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross platform way of finding number of processors on a machine?
On 10/6/07, Lawrence Oluyede [EMAIL PROTECTED] wrote: John [EMAIL PROTECTED] wrote: Is there a way to find the number of processors on a machine (on linux/ windows/macos/cygwin) using python code (using the same code/cross platform code)? From processing http://cheeseshop.python.org/pypi/processing/0.34 : A few reiterated notes inline, from my previous message. def cpuCount(): ''' Returns the number of CPUs in the system ''' if sys.platform == 'win32': try: num = int(os.environ['NUMBER_OF_PROCESSORS']) The user can do bad things to this environment variable, but it's probably ok most of the time. (Hey, they change it, they pay the consequences). else: try: num = os.sysconf('SC_NPROCESSORS_ONLN') This is really bad on linux. You really want to parse /proc/cpuinfo because HT 'cpus' are almost useless, and can be bad in situations where you try to treat them as general purpose cpus. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: supplying password to subprocess.call('rsync ...'), os.system('rsync ...')
On 05 Oct 2007 16:23:50 GMT, Stargaming [EMAIL PROTECTED] wrote: On Fri, 05 Oct 2007 08:37:05 -0700, timw.google wrote: I can't ssh w/o supplying a password. That's the way the security is set up here. How do I use python to do this, or do I just have to write a zsh script? Thanks. I wrote a zsh script to do what I wanted, but I'd still like to know how to do it in Python. `subprocess.Popen` has a keyword argument called `stdin` -- what takes the password, I guess. Assigning `subprocess.PIPE` to it and using `Popen.communicate` should do the trick. SSH doesn't read passwords off of stdin. If you want to supply a password to SSH, then you need to control a pty directly. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem using subprocess.Popen on windows
On 10/7/07, jorma kala [EMAIL PROTECTED] wrote: from subprocess import * p1 = Popen([dir], stdout=PIPE) output = p1.communicate()[0] But I get a WindowsError : [Error 2] File Not Found Tim answered your actual question, but why are you doing this in the first place? The Python standard library provides all the functionality that dir will provide and you don't have to parse the output... Look into http://www.python.org/doc/lib/os-file-dir.html, and specifically, os.listdir(path). -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Cross platform way of finding number of processors on a machine?
On 10/4/07, John [EMAIL PROTECTED] wrote: Is there a way to find the number of processors on a machine (on linux/ windows/macos/cygwin) using python code (using the same code/cross platform code)? There's no single call that will give you the same info on every platform, but you can obviously write this yourself and switch based on os.uname()[0] in most cases. For Darwin, you can just use the subprocess module to call 'sysctl hw.logicalcpu'. I'm not sure if there's a more direct way in python to use sysctl. (hw.logicalcpu_max is what the hardware maximally supports, but someone may have started their machine with OF blocking some of the processors and you should probably respect that decision) For Linux you can read /proc/cpuinfo and parse that information. Be somewhat careful with this, however, if your processors support HT, they will show as 2, and that may or may not be what you want. You can deterministically parse this information out if you know which processor families are truly multi-core, and which are HT. For Win32, the cheap and dirty way is to read the NUMBER_OF_PROCESSORS environment variable. 99% of the time, this will be correct, so it might be sufficient for your purposes. There is a system call available on windows that will net you the true number of virtual cpus, but I don't know what it is. I don't have a cygwin install laying around, but my guess is there's a sysctl option there too. One note: *all* of these methods will tell you the virtual number of CPUs in a machine, not the physical number. There's almost no reason why you care about the distinction between these two numbers, but if you do, you'll have to go to great lengths to probe the actual hardware on each platform. (And pre-WinXP, Windows doesn't actually know the difference - all processors are presumed to be physical). Also, Darwin and Linux will easily allow you to get the speed of the processors, but on x86 these numbers are not the maximums due to C1E and EIST (x86 processors from all vendors are capable of changing speeds depending on load). -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 3.0 migration plans?
On 9/27/07, Steve Holden [EMAIL PROTECTED] wrote: I wondered if a straw poll could get some idea of readers' thoughts about when they will be migrating to 3.0 on, so I used the new widget on Blogger to add a poll for that. I'd appreciate if if you would go to http://holdenweb.blogspot.com/ and register your vote on your intended migration timescale. The options should have all been relative to the release date. Options one and two might very well be the same (yes, I know, but shit happens). Also, you're relying on people knowing the current timeframe for 3.0. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Howto Launch a windows application ?
On 10/3/07, stef mientki [EMAIL PROTECTED] wrote: hello, I'm trying to launch a windows application, but as many others on this list, I've some trouble. I read some other threads about this topic, but sorry, I still don't understand all this (never heard of pipes). When I use a batch file, I can launch the bat-file from python, and the windows application launched from the batchfile is run perfectly. Now when I try to run the same windows application from Popen or call, nothing happens (or at least it's very fast and produces not the expected output). Please enlighten me, preferable in windows-terminology ;-) thanks, Stef Mientki from subprocess import * cmd =[] cmd.append ( 'D:\\PIC-tools\\JALxxx\\jalv2_3.exe' ) cmd.append ( '-long-start' ) cmd.append ( '-d') cmd.append ( '-clear' ) cmd.append ( '-sD:\\PIC-tools\\JAL\\libs2' ) cmd.append ( 'd:\\pic-tools\\jal\\programs\\test_rs232\\test_rs232_hw.jal' ) cmd.append ( 'd:\\data_actueel\\d7_test_browser\\temp.log' ) # DOESN'T WORK result = call ( cmd ) # Both Popen and call work cmd = [ 'd:\\data_actueel\\d7_test_browser\\JALcc.bat' ] #output = Popen ( cmd ) result = call ( cmd ) print result First, call is a convenience function, but in your case, it's probably not that convenient. Use the actual Popen constructor so you can get at the output directly. Also, ditch the output redirector and use a pipe: p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (out, err) = p.stdout, p.stderr rcode = p.wait() print out, err, rcode Try that and see what happens. When it doesn't work, look carefully in out and err and see if anything interesting is in there. I was able to open notepad.exe in this way with no problems so my guess is you're having some other problem, but avoiding the use of the convenience function will give you stdout and stderr to look at. -- Nick -- http://mail.python.org/mailman/listinfo/python-list
Re: Real time plot
On 10/4/07, Jean-Francois Canac [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] I would draw dots on a suitably sized Tkinter canvas, after drawing a schematic of the race track (laborious). 20 per second will be no problem, provided the machine is half decent. What is the speed at which the com port runs? - Hendrik The com port run at 19.2 kb/s. My pb is more the real time aspect: to see the plot changing in real time than the com aspect as the installation is already running with programs in c++. The PC on which it is running is good enought For me the interest is to migrate all taht on python to be able to make fast changes when it is of interest The success of this will have more to do with design than programming language. Any GUI toolkit which allows partial screen updates can be made to update at least as fast as your screen refresh rate, even in python. -- Nick -- http://mail.python.org/mailman/listinfo/python-list