Parallelization in Python at the Regular Toronto and Area Python User's Group September 15th
We'll be having our regular Toronto Area Python User's group meeting at Linux Caffe on Tuesday the 15th of September at 7:05pm. Parallelization in Python: Code Samples, Experiences and Advocacy Unlike functional languages (Haskel, Erlang), where parallelization is baked into the language, Python programmers often have to do a bit of work to get their code to run in parallel. We have a huge number of libraries that allow you to run your code concurrently, so this month we're going to collect code samples and descriptions of how you go about making your code run in parallel, and when each approach is appropriate. So, to participate, spelunk through your codebases and try to find a few examples of parallel programming, whether it be threads, multiprocessing, database-based concurrency, file-base concurrency, grid systems, GPGPU code, continuations, green-threads, MPI, RPC, Twisted, asyncore, raw sockets/pipes or any of the dozens of other approaches. If possible, have a piece of code that shows how it works in practice and maybe consider how to answer these questions: * How does it (the mechanism of parallelization) work (loosely)? * What benefits does it give you? * What problems does it introduce? * How does it scale (up/down)? * What level of granularity makes sense for it? * How does it handle communication between code? * How parallel can you get effectively? (10s of nodes? 10s of thousands? millions?) * Does it handle contention/locking/conflicts? * How stable/reliable is it? We'll try to keep the discussion lively and interesting. Venue details, maps and the like on the web-site: http://www.pygta.org We'll also likely have a discussion about putting together a series of 1/2 or 1-day classes (in a more formal classroom-like setting) for new Python users. Have fun all, Mike -- Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
[ANN] Chicago Python User Group ChiPy September Meeting
Chicago Python User Group = History, Tradition, Technology and Journalism meet this Thursday at one of our nations most historical landmarks, Tribune Tower--right off the Chicago River on the Magnificent Mile. This *new* venue speaks to the movement of journalism into technology and technology into Python. So, this will be one of most interesting venues and will provide a solid platform for the best user group meeting in the history of newspapers. We may even channel DjangoCon going on at the same time on the West coast. Bring a friend. This will is going to be great! RSVP Right NOW to: brian (at) hackerjournalist.net if you even think you might make it. Topics -- * (30 min) Somewhat Advanced SQLAlchemy - Daniel Griffin * (30 min) Python port of Geo::StreetAddress::US library - Joe Germuska * (30 min) Not using AMQP to super charge your Django apps! -- Garrett Smith * (15 min) Hello, and Beyond -- Clyde Forrester When Thursday, September 10th, ~7pm Location Tribune Tower, 435 N. Michigan Ave. RSVP to brian (at) hackerjournalist.net Other Meetings -- (before) Kinzie Chop House (some plan to gather around 4:30) (after) Billy Goat is obvious (and with merit) OR CND Gyros Lounge About ChiPy --- ChiPy is a group of Chicago Python Programmers, l33t, and n00bs. Meetings are held monthly at various locations around Chicago. Also, ChiPy is a proud sponsor of many Open Source and Educational efforts in Chicago. Stay tuned to the mailing list for more info. ChiPy website: http://chipy.org ChiPy Mailing List: http://mail.python.org/mailman/listinfo/chicago ChiPy Announcement *ONLY* Mailing List: http://mail.python.org/mailman/listinfo/chipy-announce Python website: http://python.org -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Distribute 0.6.1 released
Hello I am happy to announce the release of Distribute 0.6.1. - What is Distribute ? Distribute is a friendly fork of the Setuptools project. More info at http://pypi.python.org/pypi/distribute and http://bitbucket.org/tarek/distribute/wiki/ - Changes: * zip_ok is now True by default. * package_index.urlopen now catches BadStatusLine and malformed url errors. * Fixed invalid URL error catching. * Fixed invalid bootstraping with easy_install installation. Thanks to Florian Shchulze for the help * Removed buildout/bootstrap.py. A new repository at bitbucket.org will create a specific bootstrap.py script. * The bootstrap process leave setuptools alone if detected in the system and --root, --user or --prefix is provided, but is not in the same location. The next release of the 0.6 series will try to adress all remaining bugs in the tracker, The first 0.7 release, which targets Python 3, is still under heavy work. Cheers Tarek -- Tarek Ziadé | http://ziade.org | オープンソースの岩! -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: Leo 4.7 beta 1 released
Leo 4.7 beta 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html This version of Leo is labeled a beta version because it contains some new, relatively untested plugins. However, Leo's core should be quite reliable. In particular, Leo 4.7 beta 1 fixes a bug that caused Leo 4.6 releases to crash if .leoID.txt did not exist. Usually this file does exist, but Leo will prompt for the contents of this file (a user id) the very first time somebody uses Leo. Alas, an unfortunate reversion of code caused Leo to crash. Not exactly the best introduction to Leo! The highlights of Leo 4.7: -- - A major simplification of internal data model: the so-called one-node world. Note: this is **disabled** in the beta 1 release. - A new executable Windows installer, whose manifest is created from the files that bzr actively manages. - Leo no longer adds directories to sys.path on startup. - New plugins. - The usual assortment of bug fixes. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Forum:http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: edream...@yahoo.com Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: dh, the daemon helper 2009-09-04
dh, the daemon helper The daemon helper starts any program or script as a daemon. It's a small C program with a simple interface and a liberal license. ftp://ftp.isp2dial.com/users/jak/src/dh/ Get the files and do: make install clean To build and install dh. Don't try to run the Sh.install script directly, it must be invoked using the Makefile. I use dh for starting scripts which read fifos fed by syslog. They block on read until syslog provides data to work on. They never end, and need help to start as daemons. But that's just one example. There are many other potential uses for the daemon helper. dh is its name; a natural companion to sh. I use dh on Linux, but was curious about portability. With some minor changes, I compiled and installed it on NetBSD 5.0.1 x86. So now it's portable. Wheee! It's a cool tool, it reports problems encountered when trying to exec the target daemon program or script. Debian's start-stop-deamon can't do that, nor can any other daemon tool I know of. It's minimal, with only one command line option, -p. Avoiding unneeded bells and whistles was my intentional design. In six months time, I could lose interest in computers, start a new career, and the work would be lost forever. Someone who likes C more than I do should adopt dh and help it grow. But if you do, don't believe what Stevens wrote about ignoring SIGHUP before the second fork(). It's not true, so don't write voodoo code to handle it! See the thread in c.u.p with the subject Orphaned process groups, daemon startup, SIGHUP. If you can't adopt dh, but have ideas for patches, send them. But if I don't respond, well then, you're on your own. There is no man page for dh, but the README explains how to use it. If there is enough interest, maybe someday I will give dh an official version number and use some version control. But for now, the date of last modification is all there is. -- Webmail for Dialup Users http://www.isp2dial.com/freeaccounts.html -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: Class variable inheritance
http://docs.python.org/reference/datamodel.html#new-style-and-classic... - search for 'method resolution order' for other hits in that document. First of all, that's the LR for Python 2, I'm with Python 3. Second of all, there's one single passage containing the phrase method resolution order in the Python 3 LR, and it's one that I've already quoted -- and discarded -- previously in this thread. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
And by the way, the reason I've come across this problem at all is because I have something like this: class A: class X: n = 'a' x = X() class B(A): class X(A.X): n = 'b' # x = X() The line commented out was originally not there, but I found out I had to add it if I wanted B().x.n to be 'b' instead of 'a'. I might be wrong, but aren't there some (non-obscure) OOP language in which the equivalent code (without the out-commented line) would have made B().x an object of type B.X instead of A.X? -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Tue, 08 Sep 2009 13:14:42 -0700, HPJ wrote: I could, but I will let you read and find what it says about class attributes. You think I would have asked specifically about the Language Reference if I hadn't read it and failed to find what I was looking for? You must be new to the Internet *wink* Of course people ask without having made the effort themselves. Please sir, will you do my work for me? is practically the norm on Internet forums. Only without the please. The closest thing I was able to find was section 3.2. The standard type hierarchy, subsection Custom classes, where it says: When the attribute name is not found [in its namespace dictionary], the attribute search continues in the base classes. This search of the base classes uses the C3 method resolution order [...] That tells me how the lookup works, which I already knew. But it doesn't tell me what happens when a class is inherited. The inheriting class has its base class set, and the MRO (method resolution order), and that's pretty much it as far as I can tell. Seems to me that the documentation is a little incomplete in this regard. It looks to me like one of those language lawyer details that needs fleshing out. Out of curiosity, are there languages where inheritance means copy? -- Steven -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Sep 8, 8:51 pm, HPJ henrypija...@gmail.com wrote: Conceptually, Python checks for the presence of B.foo, and if it's not there it checks for foo's presence in the base classes. Yes, I have no problem believing you guys that this is what Python does. Still, my question remains about where in the Language Reference this is specified. And if the answer is nowhere, than the LR needs to be amended, for obviously the way inheritance is done is no small matter and its understanding should not be left to the user's own intuition. Well, I don't know if this detail alone is all that grave an omission-- it'll matter to very few users--but it does seem the LRM could use a subsection on inheritance in general. I'm sure the doc maintainers would welcome a contribution. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
I should also mention--and I should have realized this much sooner--that each of the BaseN classes are themselves each going to have at least one common base which will define method_x, so each BaseN will be calling that if it defines its own method_x. Again, sorry I didn't mention that sooner. For some reason it didn't occur to me that it would be important. I feel dumb now... :P Here is the updated current example: class CommonBase(object): def method_x(self, a, b c): ... no call to superclass' method_x is needed here ... class MyMixin(object): def method_x(self, a, b, c): get_other_base(self).method_x(self, a, b, c) ... class BaseA(CommonBase): def method_x(self, a, b, c): super(BaseA, self).method_x(a, b, c) ... class BaseB(CommonBaset): ... class BaseC(CommonBase): def method_x(self, a, b, c): super(BaseC, self).method_x(a, b, c) ... class FooX(MyMixin, BaseA): ... class FooY(MyMxin, BaseB): ... class FooZ(MyMixin, BaseC): ... -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Sep 8, 11:05 pm, HPJ henrypija...@gmail.com wrote: And by the way, the reason I've come across this problem at all is because I have something like this: class A: class X: n = 'a' x = X() class B(A): class X(A.X): n = 'b' # x = X() You've nested classes here, that's a whole new layer of complexity. I would strongly recommend against nesting classes in Python, unless the inner class is a smallish class (such as a custom exception type) that doesn't interact with the outer class. It's just that nested classes don't ever seem to behave like anyone expects them to. Also you can't take advantage of Python's lexical scoping with nested classes (unlike, for instance, Java) so there really isn't much benefit to nesting them. The line commented out was originally not there, but I found out I had to add it if I wanted B().x.n to be 'b' instead of 'a'. Hm, even if class B did get copies of class A's attributes, B().x.n would still return 'a'. It seems as if you expect class B to re- execute A's statements in B's context, or something. That's not how it works at all. (Now if you define self.x=X() inside of __init__, that's a different story.) I might be wrong, but aren't there some (non-obscure) OOP language in which the equivalent code (without the out-commented line) would have made B().x an object of type B.X instead of A.X? Maybe. For some languages this might be an obvious behavior, but Python would have different circumstances so it isn't so obvious (or possible) there. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Tue, Sep 8, 2009 at 11:30 PM, Steven D'Apranoste...@remove.this.cybersource.com.au wrote: snip Out of curiosity, are there languages where inheritance means copy? I think some prototype-based ones handle it that way... Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I post to the wxPython mailing list?
PythonAB: No, but it means that more of my data goes into the same company. There's no way to use my own email accounts from my own domain, and I don't have a choice anymore. I just checked and it allowed me to use an account from my domain so I expect it will work with yours. In other words, if i want to be able to get the wxPython list mail, I'm forced to use a google account, am I not? Yes, just as you set up an account with a Mailman server when subscribing to a Mailman list. Neil -- http://mail.python.org/mailman/listinfo/python-list
Re: Why does this group have so much spam?
In article mailman.837.1251890913.2854.python-l...@python.org, Tino Wildenhain t...@wildenhain.de wrote: SNIP Here is another idea: for spam senders pointing to servers under=20 jurisdiction, size the server and check all incoming requests from users - if they try to do a deal, prosecute a few of them in the public for supporting a crime. (And of course if possible get hold of the spammers too). Sure there would be corner cases where for example a competitor might try to discredit a company, but in most cases, cui bono should be the spammer after all. You know what that is: terror. Those in power just picks just somebody, punish them in a way that is beyond reason, to scare the crap out of everybody. This is what the western justice system is supposed to prevent. This is the exact opposite of what the Free West is supposed to mean. Terrorised by government, or by interest groups, is as bad as terrorised by Scientology Church or street punks. Think about it. Hitler came legally to power, and was able to transform Germany in a police state based on laws that were very liberal compared to what we have today. (Only later he went far beyond that.) Of course a lot of Jewish business men weren't honest. (No business men is.). So being Jewish is probably criminal. Were does it end? Groetjes Albert -- -- Albert van der Horst, UTRECHT,THE NETHERLANDS Economic growth -- being exponential -- ultimately falters. alb...@spearc.xs4all.nl =n http://home.hccnet.nl/a.w.m.van.der.horst -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
On Sep 8, 4:33 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:53 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Within the file are a list of files, e.g. TOTAL FILES: 2 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf FILESIZE: 11028908 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml FILESIZE: 18975 and what i want to do is get the ftp address from the file and collect these files to pull down from the web e.g. MOD13A2.A2007033.h17v08.005.2007101023605.hdf MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml Thus far I have #!/usr/bin/env python import sys import re import urllib email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) m = re.findall(rMOD\.\.h..v..\.005\..\ \, s) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir for i in xrange(len(m)): print i, ':', len(m) file1 = m[i][:-4] # remove xml bit. file2 = m[i] urllib.urlretrieve(url, file1) urllib.urlretrieve(url, file2) which works, clearly my match for the MOD13A2* files isn't ideal I guess, but they will always occupt those dimensions, so it should work. Any suggestions on how to improve this are appreciated. Suppose the file contains your example text above. Using 'readlines' returns a list of the lines: f = open(email, 'r') lines = f.readlines() lines ['TOTAL FILES: 2\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\n', '\t\tFILESIZE: 11028908\n', '\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml\n', '\t\tFILESIZE: 18975\n'] Using 'str' on that list then converts
Re: Re: Distutils - can user designate install directory for windows installer?
Mark Hammond wrote: div class=moz-text-flowed style=font-family: -moz-fixedOn 9/09/2009 1:57 AM, Timothy W. Grove wrote: I have successfully built a windows installer for my python program using distutils, (python setup.py bdist_wininst), but is there a way to do it that will allow a user ('user' == 'boss', in this case!) to designate the installation directory, rather than being forced to install into /Python/Lib/site-packages ? Thanks for any help. bdist_wininst is for packaging python modules or packages and so depends on Python itself being installed. As a result, it only installs into where Python libs and modules are generally installed. It sounds like you are looking for something to create a stand-alone version of your program - in that case you are probably looking for py2exe to create the application itself, and something like Inno or NSYS to create an installer which allows the user to specify where they want it installed and doesn't depend on Python already being installed. Cheers, Mark Your advice sounds like the direction I may have to go. It was just that when I run the distutils installer, I'm presented with a setup dialog which shows the install directory as /Python26 /site-packages/ in an uneditable text field. I thought that there might be an easy way to make that editable in order to change the path to a user defined directory, although I might also want to drop a .pth file into the site-packages directory so python knows where the application really is installed. Thanks for your advice. Best regards, Tim /div -- http://mail.python.org/mailman/listinfo/python-list
uses for setup.cfg and extracting data from it
Hi All, Do people generally source control their package's setup.cfg? http://docs.python.org/distutils/configfile.html sort of implies it should be editable by the person installing the package, but I've never personally used a package where that's the case... Assuming the distutils docs are out of date and this file is really owned by the package maintainer, how do I extract information from it in setup.py (and elsewhere for that matter!) I'm looking for somewhere consistent to store the following for all my packages: - mailing lists url - issue tracker url - change log url - documentation url ...such that I can generate a sensible long_description for use on PyPI but also such that I can include the information in the Sphinx docs... cheers, Chris -- Simplistix - Content Management, Batch Processing Python Consulting - http://www.simplistix.co.uk -- http://mail.python.org/mailman/listinfo/python-list
How can I format unicode strings?
return u{}.format(self.name) this one doesn't work on unicode strings. I there a not old formatting style possibilty for unicode strings? Note: self.name can be unicode string! -- http://mail.python.org/mailman/listinfo/python-list
[Tkinter] messed callbacks
i have this test program (that i already posted on it.comp.lang.python) [ test.py ] from Tkinter import * def output(s): print s def doit(fr,lst): for c1,c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') Button(subframe,text='',command=lambda: output(c1+'-'+c2)).pack() Button(subframe,text='',command=lambda: output(c2+'-'+c1)).pack() subframe.pack(fill='x',expand=1) root=Tk() fr=Frame(root,relief='raised',borderwidth=5).pack(fill='both',expand=1) doit(fr,['pippo','pluto','paperino','zio_paperone']) Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x') root.mainloop() when i execute it from the command line, click on the 4 buttons from top to bottom and quit (you can do the same), this is what i get aiuole: python test.py gray-black black-gray gray-black black-gray aiuole: as you see, the button 0 and 1 have callbacks different from my expectations, as my script was intended to give cyan-blue blue-cyan gray-black black-gray why the messed callbacks? what's the right thing to do? tia, g -- l'amore e' un sentimento a senso unico. a volte una via comincia dove finisce un'altra e viceversa -- Caldana, in IFQ -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tkinter] messed callbacks
Giacomo Boffi wrote: i have this test program (that i already posted on it.comp.lang.python) [ test.py ] from Tkinter import * def output(s): print s def doit(fr,lst): for c1,c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') Button(subframe,text='',command=lambda: output(c1+'-'+c2)).pack() Button(subframe,text='',command=lambda: output(c2+'-'+c1)).pack() subframe.pack(fill='x',expand=1) root=Tk() fr=Frame(root,relief='raised',borderwidth=5).pack(fill='both',expand=1) doit(fr,['pippo','pluto','paperino','zio_paperone']) Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x') root.mainloop() when i execute it from the command line, click on the 4 buttons from top to bottom and quit (you can do the same), this is what i get aiuole: python test.py gray-black black-gray gray-black black-gray aiuole: as you see, the button 0 and 1 have callbacks different from my expectations, as my script was intended to give cyan-blue blue-cyan gray-black black-gray why the messed callbacks? what's the right thing to do? Closures in python contain names, not the objects they refer to. So when you rebind that name (as you do above in your loop), the created callbacks will only refer to the last bound value of a name. Create new closures, or bind arguments as defaults: funcs = [] def create_func(i): return lambda: i for i in xrange(10): funcs.append(lambda i=i: i) funcs.append(create_func(i)) for f in funcs: print f() Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I format unicode strings?
gentlestone tibor.b...@hotmail.com writes: return u{}.format(self.name) this one doesn't work on unicode strings. I there a not old formatting style possibilty for unicode strings? It looks like you're trying to mix python 3.1 and 2.6. In 2.6 you have to put a number inside the {} to tell it which argument to use. In 3.1 all strings are unicode. Apparently when 2.7 is released it will backport the empty {} feature from 3.1. Until then return u'{0}'.format(self.name) is what you should probably use. Tim. -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
Maybe. For some languages this might be an obvious behavior, but Python would have different circumstances so it isn't so obvious (or possible) there. Which means this topic definitely needs to be handled in detail by the LR, and preferably also in the Tutorial. Otherwise there is no way anyone coming to Python could know which of the many ways of inheritance Python follows. -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I format unicode strings?
gentlestone schrieb: return u{}.format(self.name) u{0}.format(ublah) works for me with python-2.6.2 Maybe your format string is wrong. - Patrick -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I format unicode strings?
On 9. Sep., 12:31 h., Tim Northover t.p.northo...@sms.ed.ac.uk wrote: gentlestone tibor.b...@hotmail.com writes: return u{}.format(self.name) this one doesn't work on unicode strings. I there a not old formatting style possibilty for unicode strings? It looks like you're trying to mix python 3.1 and 2.6. In 2.6 you have to put a number inside the {} to tell it which argument to use. In 3.1 all strings are unicode. Apparently when 2.7 is released it will backport the empty {} feature from 3.1. Until then return u'{0}'.format(self.name) is what you should probably use. Tim. I have python 2.5 return u'{0}'.format(self.name) doesn't work eigther the error message i've got is: 'unicode' object has no attribute 'format' is the new formatting style newer then python 2.5? -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I format unicode strings?
On 9 Sep, 12:49, gentlestone tibor.b...@hotmail.com wrote: I have python 2.5 return u'{0}'.format(self.name) doesn't work eigther the error message i've got is: 'unicode' object has no attribute 'format' is the new formatting style newer then python 2.5? Yes. The new string formatting appeared in python 2.6. Perhaps there is some __future__ stuff you can import to get it to work, don't know. If not you are stuck with the old string formatting until you upgrade to 2.6 or newer: print u'Hello %s!' % u'world' Hello world! /Niklas Norrthon -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I format unicode strings?
gentlestone tibor.b...@hotmail.com wrote: the error message i've got is: 'unicode' object has no attribute 'format' is the new formatting style newer then python 2.5? Have you tried reading the documentation? It generally tells you which version of Python introduced a feature: http://docs.python.org/library/stdtypes.html#string-methods str.format(format_string, *args, **kwargs)¶ Perform a string formatting operation. The format_string argument can contain literal text or replacement fields delimited by braces {}. Each replacement field contains either the numeric index of a positional argument, or the name of a keyword argument. Returns a copy of format_string where each replacement field is replaced with the string value of the corresponding argument. The sum of 1 + 2 is {0}.format(1+2) 'The sum of 1 + 2 is 3' See Format String Syntax for a description of the various formatting options that can be specified in format strings. This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in String Formatting Operations in new code. New in version 2.6. -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tkinter] messed callbacks
Diez B. Roggisch de...@nospam.web.de writes: Giacomo Boffi wrote: def doit(fr,lst): for c1,c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') Button(subframe,text='',command=lambda: output(c1+'-'+c2)).pack() Button(subframe,text='',command=lambda: output(c2+'-'+c1)).pack() subframe.pack(fill='x',expand=1) why the messed callbacks? what's the right thing to do? Closures in python contain names, not the objects they refer to. So when you rebind that name (as you do above in your loop), sorry, i'm not conscient of rebinding a name... what do you mean by rebind that name exactly? the created callbacks will only refer to the last bound value of a name. Create new closures, or bind arguments as defaults: funcs = [] def create_func(i): return lambda: i for i in xrange(10): funcs.append(lambda i=i: i) funcs.append(create_func(i)) for f in funcs: print f() i tried to understand, and maybe i have understood a thing or two... funcs = [] def create_func(i): return lambda: i for i in xrange(10): funcs.append(lambda i=i: i) funcs.append(create_func(i)) funcs.append(lambda: i)# this is my addition for f in funcs: print f() ok, i'll try again following your advice thank you very much g -- It will be rain tonight. Let it come down. -- http://mail.python.org/mailman/listinfo/python-list
Some issue with easy_install and PIL/Imaging
Hi, I would like to insert Imaging dependence in my setup.py file. Resume : 1. first question : why PIL package in pypi don't work ? 2. second question : when I add PIL dependence in my setup.py and I do python setup.py develop, I've this error : error: Could not find required distribution Imaging. Why ? Full explication : First, I test manualy installation : :: (env1)skl...@eee-sklein:$ easy_install pil Searching for pil Reading http://pypi.python.org/simple/pil/ Reading http://www.pythonware.com/products/pil Reading http://effbot.org/zone/pil-changes-115.htm Reading http://effbot.org/downloads/#Imaging No local packages or download links found for pil error: Could not find suitable distribution for Requirement.parse('pil') This command fail ! Now, I try with Imaging package name : :: (env1)skl...@eee-sklein:$ easy_install Imaging Searching for Imaging Reading http://pypi.python.org/simple/Imaging/ Couldn't find index page for 'Imaging' (maybe misspelled?) Scanning index of all packages (this may take a while) Reading http://pypi.python.org/simple/ No local packages or download links found for Imaging error: Could not find suitable distribution for Requirement.parse('Imaging') This command fail also. Now, I add --find-links parameter to easy_install : :: (env1)skl...@eee-sklein:$ easy_install --find-links http://www.pythonware.com/products/pil/ Imaging Searching for Imaging Reading http://www.pythonware.com/products/pil/ Best match: Imaging 1.1.6 Downloading http://effbot.org/downloads/Imaging-1.1.6.tar.gz Processing Imaging-1.1.6.tar.gz Running Imaging-1.1.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-rF1PG1/Imaging-1.1.6/egg-dist-tmp-Xtv8GV libImaging/Effects.c:210: attention : ‘perlin_init’ defined but not used libImaging/File.c: In function ‘ImagingOpenPPM’: libImaging/File.c:112: attention : ignoring return value of ‘fread’, declared with attribute warn_unused_result libImaging/File.c:119: attention : ignoring return value of ‘fread’, declared with attribute warn_unused_result libImaging/Geometry.c:236: attention : ‘quadratic_transform’ defined but not used libImaging/Quant.c:311: attention : ‘test_sorted’ defined but not used libImaging/Quant.c:676: attention : ‘checkContained’ defined but not used libImaging/QuantHash.c:136: attention : ‘_hashtable_test’ defined but not used PIL 1.1.6 BUILD SUMMARY version 1.1.6 platform linux2 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] *** TKINTER support not available (Tcl/Tk 8.5 libraries needed) --- JPEG support ok --- ZLIB (PNG/ZIP) support ok --- FREETYPE2 support ok To add a missing option, make sure you have the required library, and set the corresponding ROOT variable in the setup.py script. To check the build, run the selftest.py script. zip_safe flag not set; analyzing archive contents... Image: module references __file__ Adding PIL 1.1.6 to easy-install.pth file Installing pilprint.py script to /home/sklein/tests/test_eggs_pil/env1/bin Installing pilfile.py script to /home/sklein/tests/test_eggs_pil/env1/bin Installing pilconvert.py script to /home/sklein/tests/test_eggs_pil/env1/bin Installing pilfont.py script to /home/sklein/tests/test_eggs_pil/env1/bin Installing pildriver.py script to /home/sklein/tests/test_eggs_pil/env1/bin Installed /home/sklein/tests/test_eggs_pil/env1/lib/python2.6/site-packages/PIL-1.1.6-py2.6-linux-i686.egg Skipping dependencies for PIL 1.1.6 This command work very well. First question : why PIL package in pypi don't work ? Now, I remove PIL in my virtualenv to test setup.py installation : :: (env1)skl...@eee-sklein:$ rm /home/sklein/tests/test_eggs_pil/env1/lib/python2.6/site-packages/PIL-1.1.6-py2.6-linux-i686.egg/ -rf (env1)skl...@eee-sklein:$ cat setup.py from setuptools import setup, find_packages import sys, os version = '0.0' setup(name='test_pil', version=version, description=, long_description=\ , classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers keywords='', author='', author_email='', url='', license='', packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True, zip_safe=False, dependency_links=['http://www.pythonware.com/products/pil/'], install_requires=[
Re: [Tkinter] messed callbacks
Giacomo Boffi giacomo.bo...@polimi.it writes: ok, i'll try again following your advice ,[ test.py ] | from Tkinter import * | | def output(s): | print s | | def create_cb(a,b): | return lambda: output(a+'-'+b) | | def doit(fr,lst): | for c1,c2 in zip(lst[::2], lst[1::2]): | subframe=Frame(fr) | Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') | Button(subframe,text='',command=create_cb(c1,c2)).pack() | Button(subframe,text='',command=create_cb(c2,c1)).pack() | subframe.pack(fill='x',expand=1) | | root=Tk() | doit(root,['cyan','blue','gray','black']) | Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x') | root.mainloop() ` works ok, now i have to fully understand my previous error again, thanks you very much g -- Yes you who must leave everything that you cannot control. It begins with your family, but soon it comes around to your soul. -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Mart. wrote: On Sep 8, 4:33 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:53 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Within the file are a list of files, e.g. TOTAL FILES: 2 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf FILESIZE: 11028908 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml FILESIZE: 18975 and what i want to do is get the ftp address from the file and collect these files to pull down from the web e.g. MOD13A2.A2007033.h17v08.005.2007101023605.hdf MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml Thus far I have #!/usr/bin/env python import sys import re import urllib email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) m = re.findall(rMOD\.\.h..v..\.005\..\ \, s) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir for i in xrange(len(m)): print i, ':', len(m) file1 = m[i][:-4] # remove xml bit. file2 = m[i] urllib.urlretrieve(url, file1) urllib.urlretrieve(url, file2) which works, clearly my match for the MOD13A2* files isn't ideal I guess, but they will always occupt those dimensions, so it should work. Any suggestions on how to improve this are appreciated. Suppose the file contains your example text above. Using 'readlines' returns a list of the lines: f = open(email, 'r') lines = f.readlines() lines ['TOTAL FILES: 2\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\n', '\t\tFILESIZE: 11028908\n', '\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml\n', '\t\tFILESIZE: 18975\n'] Using 'str' on that list then converts it to s string _representation_ of that list: str(lines) ['TOTAL FILES: 2\\n', '\\t\\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\\n', '\\t\\tFILESIZE: 11028908\\n', '\\n',
\r\n or \n notepad editor end line ???
Hey Terry, That was a very useful tip I got about the Escape Sequences.. \r and \n Regards, Sphoorti Digambar Patil Software Engineer * SunGard * Technology Services * Embassy Icon 3, Infantry Road, Bangalore India * HOME - (205)969-1798*Tel +91-80--0501 * Extn 3154 * Fax +91-80--0511 * Mobile +91-9900538933 www.sungard.com/sts http://www.sungard.com/sts P Think before you print CONFIDENTIALITY: This email (including any attachments) may contain confidential, proprietary and privileged information, and unauthorized disclosure or use is prohibited. If you received this email in error, please notify the sender and delete this email from your system. Thank you -- http://mail.python.org/mailman/listinfo/python-list
Re: [Guppy-pe-list] An iteration idiom (Was: Re: loading files containing multiple dumps)
Sverker Nilsson wrote: But I don't think I would want to risk breaking someone's code just for this when we could just add a new method. I don't think anyone will be relying on StopIteration being raised. If you're worried, do the next release as a 0.10.0 release and explain the backwards incompatible change in the release announcement. Or we could have an option to hpy() to redefine load() as loadall(), but I think it is cleaner (and easier) to just define a new method... -1 to options to hpy, +1 to loadall but also -1 to lead load() as broken as it is... As the enclosing class or frame is deallocated, so is its attribute h itself. Right, but as long as the h hangs around, it hangs on to all the memory it's used to build its stats, right? This caused me problems in my most recent use of guppy... themselves, but I am talking about more severe data that can be hundreds of megabytes or more). Me too ;-) I've been profiling situations where the memory usage was over 1GB for processing a 30MB file when I started ;-) For example, the setref() method sets a reference point somewhere in h. Further calls to heap() would report only objects allocated after that call. But you could use a new hpy() instance to see all objects again. Multiple threads come to mind, where each thread would have its own hpy() object. (Thread safety may still be a problem but at least it should be improved by not sharing the hpy() structures.) Even in the absence of multiple threads, you might have an outer invocation of hpy() that is used for global analysis, with its specific options, setref()'s etc, and inner invocations that make some local analysis perhaps in a single method. Fair points :-) http://guppy-pe.sourceforge.net/heapy-thesis.pdf I'm afraid, while I'd love to, I don't have the time to read a thesis... But it is (an important) part of the documentation. That may be, but I'd wager a fair amount of beer that buy far the most common uses for heapy are: - finding out what's using the memory consumed by a python process - log how what the memory consumption is made up of while running a large python process - finding out how much memory is being used ...in that order. Usually on a very tight deadline and with unhappy users breathing down their necks. At times like that, reading a thesis doesn't really figure into it ;-) I'm afraid, while I'd love to, I don't have the time to duplicate the thesis here...;-) I don't think that would help. Succinct help and easy to use functions to get those 3 cases above solved is all that's needed ;-) Do you mean we should actually _remove_ features to create a new standalone system? Absolutely, why provide more than is used or needed? You are free to wrap functions as you find suitable; a minimal wrapper module could be just like this: # Module heapyheap from guppy import hpy h=hpy() heap=heap() I don't follow this.. did you mean heap = h.heap()? If so, isn't that using all the gubbinz in Use, etc, anyway? Less minor rant: this applies to most things to do with heapy... Having __repr__ return the same as __str__ and having that be a long lump of text is rather annoying. If you really must, make __str__ return the big lump of text but have __repr__ return a simple, short, item containing the class, the id, and maybe the number of contained objects... I thought it was cool to not have to use print but get the result directly at the prompt. That's fine, that's what __str__ is for. __repr__ should be short. No, it's the other way around: __repr__ is used when evaluating directly at the prompt. The docs give the idea: http://docs.python.org/reference/datamodel.html?highlight=__repr__#object.__repr__ I believe you big strings would be classed as informal and so would be computed by __str__. Yeah, but an item in a set is not a set. __getitem__ should return an item, not a subset... Usually I think it is called an 'element' of a set rather than an 'item'. Python builtin sets can't even do indexing at all. ...'cos it doesn't make sense ;-) Likewise, Heapy IdentitySet objects don't support indexing to get at the elements directly. ...then they shouldn't have a __getitem__ method! The index (__getitem__) method was available so I used it to take the subset of the i'ths row in the partition defined by its equivalence order. That should have another name... I don't know what a partition or equivalence order are in the contexts you're using them, but I do know that hijacking __getitem__ for this is wrong. The subset indexing, being the more well-defined operation, and also IMHO more generally useful, thus got the honor to have the [] syntax. Except it misleads anyone who's programmed in Python for a significant period of time and causes problems when combined with the bug in .load :-( It would just be another syntax. I don't see the conceptual problem since e.g. indexing works just fine like this with
Re: uses for setup.cfg and extracting data from it
Chris Withers ch...@simplistix.co.uk writes: Do people generally source control their package's setup.cfg? Yes. I prefer the distribution metadata to be declarative, for the reasons you touch on later in your message. So where it makes sense I store it in ‘setup.cfg’ or some other declarative file, and put it under VCS like any other file needed for generating the distribution. http://docs.python.org/distutils/configfile.html sort of implies it should be editable by the person installing the package Yes, that's part of its purpose: to allow customisation of the various actions of distutils. but I've never personally used a package where that's the case... I don't understand. When you, as the person installing the distribution, get the sdist for that distribution, you can edit (or create, if it didn't exist) the ‘setup.cfg’. What's stopping you from doing so? Assuming the distutils docs are out of date and this file is really owned by the package maintainer If the distribution maintainer generates and distributes sdist files, then they can “own” the ‘setup.cfg’ file without hindering the recipient's customisation of the same file at installation time. how do I extract information from it in setup.py (and elsewhere for that matter!) That's one of the pain points of the current distutils capability: there's no standard-library way to extract that information. Various efforts are under way to try to change that, but the legacy of existing distributions is heavy and long. You'll probably be interested in the discussions currently ongoing in the Distutils SIG, regarding how to get the distribution metadata so it's stored declaratively to make it easier to extract. -- \ “I have yet to see any problem, however complicated, which, | `\ when you looked at it in the right way, did not become still | _o__)more complicated.” —Paul Anderson | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Rapid GUI Programming with Python and Qt source code
On Wed Sep 9 07:11:26 CEST 2009, Steven Woody wrote: *I've searched google and cannot find a valid link for the source code of the book Rapid GUI Programming with Python and Qt. Could anyone please give me a non-broken URL?* See this page for the links: http://www.qtrac.eu/pyqtbook.html David -- http://mail.python.org/mailman/listinfo/python-list
Open Position: Software/System Engineer....Python....
Hello All I do not know if this is the correct forum. I am looking for a Software/System Engineer with Python experience in the Cleveland, OH area. The skill set looks like this: Skills/Qualifications: • Working in a dynamic, self motivated environment with minimal supervision in a small fast growing company. • Expertise in M/S Windows, Red Hat Linux Operating Systems, MySQL database development and Apache server setup. • Expertise in Languages: Python • Knowledge of the Django framework and working in a web development environment. Interested individuals can submit resumes to employm...@globalww.com. If this is not the place for this type of posting, if someone could suggest an area, I would appreciate the guidance. Thanks James -- http://mail.python.org/mailman/listinfo/python-list
Re: Open Position: Software/System Engineer....Python....
James wrote: Hello All I do not know if this is the correct forum. I am looking for a Software/System Engineer with Python experience in the Cleveland, OH area. The skill set looks like this: Skills/Qualifications: • Working in a dynamic, self motivated environment with minimal supervision in a small fast growing company. • Expertise in M/S Windows, Red Hat Linux Operating Systems, MySQL database development and Apache server setup. • Expertise in Languages: Python • Knowledge of the Django framework and working in a web development environment. Interested individuals can submit resumes to employm...@globalww.com. If this is not the place for this type of posting, if someone could suggest an area, I would appreciate the guidance. It's ok to post here IMHO, but don't forget to check out http://python.org/jobs as well. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Open Position: Software/System Engineer....Python....
Diez B. Roggisch wrote: James wrote: Hello All I do not know if this is the correct forum. I am looking for a Software/System Engineer with Python experience in the Cleveland, OH area. The skill set looks like this: Skills/Qualifications: • Working in a dynamic, self motivated environment with minimal supervision in a small fast growing company. • Expertise in M/S Windows, Red Hat Linux Operating Systems, MySQL database development and Apache server setup. • Expertise in Languages: Python • Knowledge of the Django framework and working in a web development environment. Interested individuals can submit resumes to employm...@globalww.com. If this is not the place for this type of posting, if someone could suggest an area, I would appreciate the guidance. It's ok to post here IMHO, but don't forget to check out http://python.org/jobs http://www.python.org/community/jobs/ it is. Sorry. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Open Position: Software/System Engineer....Python....
On Sep 9, 10:06 am, Diez B. Roggisch de...@nospam.web.de wrote: Diez B. Roggisch wrote: James wrote: Hello All I do not know if this is the correct forum. I am looking for a Software/System Engineer with Python experience in the Cleveland, OH area. The skill set looks like this: Skills/Qualifications: • Working in a dynamic, self motivated environment with minimal supervision in a small fast growing company. • Expertise in M/S Windows, Red Hat Linux Operating Systems, MySQL database development and Apache server setup. • Expertise in Languages: Python • Knowledge of the Django framework and working in a web development environment. Interested individuals can submit resumes to employm...@globalww.com. If this is not the place for this type of posting, if someone could suggest an area, I would appreciate the guidance. It's ok to post here IMHO, but don't forget to check out http://python.org/jobs http://www.python.org/community/jobs/ it is. Sorry. Diez Diez Thanks, I will check out. James -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tkinter] messed callbacks
Giacomo Boffi wrote: Giacomo Boffi giacomo.bo...@polimi.it writes: ... | def create_cb(a,b): | return lambda: output(a+'-'+b) | | def doit(fr,lst): | for c1,c2 in zip(lst[::2], lst[1::2]): | subframe=Frame(fr) | Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') | Button(subframe,text='',command=create_cb(c1,c2)).pack() | Button(subframe,text='',command=create_cb(c2,c1)).pack() | subframe.pack(fill='x',expand=1) ... works ok, now i have to fully understand my previous error This is really why functools.partial exists. Now that you know what was going wrong, you can understand its value. You can accomplish the same thing as above with: from functools import partial ... def doit(fr,lst): for c1, c2 in zip(lst[::2], lst[1::2]): subframe = Frame(fr) Label(subframe, text=c1 + ' - ' + c2 ).pack(side='left', expand=1, fill='both') Button(subframe, text='', command=partial(output, c1 + '-' + c2)).pack() Button(subframe, text='', command=partial(output, c2 + '-' + c1)).pack() subframe.pack(fill='x', expand=1) ... Also note from Pep 8, spaces are cheap and make the code easier to read. --Scott David Daniels scott.dani...@acm.org -- http://mail.python.org/mailman/listinfo/python-list
Re: [Distutils] uses for setup.cfg and extracting data from it
At 11:25 PM 9/9/2009 +1000, Ben Finney wrote: That's one of the pain points of the current distutils capability: there's no standard-library way to extract that information. If you're talking about setup.cfg (and all the other distutils .cfg files), all you need to do is create a Distribution object and call parse_config_files() on it, then access the appropriate attributes. Take you maybe 3 or 4 lines of code. If you're talking about setup.py, all you need to do is use the distutils functions that allow you to run a setup.py without executing any of its commands. (Of course, you then need to be able to deal with badly-behaved setup scripts, and it's true there's no stdlib support for that.) -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On Sep 9, 3:27 am, sturlamolden sturlamol...@yahoo.no wrote: On 9 Sep, 00:24, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: A decent vendor-supplied implementation will include error checking that you otherwise would need to implement yourself, so yes. Not for code like this: import numpy as np n = np.arange(101) w = 0.5*(1.0-np.cos(2*np.pi*n/(100.))) Well, I went and dug into NumPy. They write it as 0.5 - 0.5 * cos (...), and special case N = 1, and properly error check N 1. Still, probably because of differences in dictionary look ups (because of namespace scopes), np.hanning, on average, takes a wee bit over half as long as your case, and yours is only a shade faster than window = [0.5 - math.cos(2 * x * math.pi /100.) for x in range(101)] (Yes, I know I should've used xrange instead of range) -- http://mail.python.org/mailman/listinfo/python-list
ANNOUNCE: Leo 4.7 beta 1 released
Leo 4.7 beta 1 is now available at: http://sourceforge.net/project/showfiles.php?group_id=3458package_id=29106 Leo is a text editor, data organizer, project manager and much more. See: http://webpages.charter.net/edreamleo/intro.html This version of Leo is labeled a beta version because it contains some new, relatively untested plugins. However, Leo's core should be quite reliable. In particular, Leo 4.7 beta 1 fixes a bug that caused Leo 4.6 releases to crash if .leoID.txt did not exist. Usually this file does exist, but Leo will prompt for the contents of this file (a user id) the very first time somebody uses Leo. Alas, an unfortunate reversion of code caused Leo to crash. Not exactly the best introduction to Leo! The highlights of Leo 4.7: -- - A major simplification of internal data model: the so-called one-node world. Note: this is **disabled** in the beta 1 release. - A new executable Windows installer, whose manifest is created from the files that bzr actively manages. - Leo no longer adds directories to sys.path on startup. - New plugins. - The usual assortment of bug fixes. Links: -- Leo: http://webpages.charter.net/edreamleo/front.html Forum:http://groups.google.com/group/leo-editor Download: http://sourceforge.net/project/showfiles.php?group_id=3458 Bzr: http://code.launchpad.net/leo-editor/ Quotes: http://webpages.charter.net/edreamleo/testimonials.html Edward K. Ream email: edream...@yahoo.com Leo: http://webpages.charter.net/edreamleo/front.html -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On Sep 9, 3:46 pm, pdpi pdpinhe...@gmail.com wrote: On Sep 9, 3:27 am, sturlamolden sturlamol...@yahoo.no wrote: On 9 Sep, 00:24, Steven D'Aprano ste...@remove.this.cybersource.com.au wrote: A decent vendor-supplied implementation will include error checking that you otherwise would need to implement yourself, so yes. Not for code like this: import numpy as np n = np.arange(101) w = 0.5*(1.0-np.cos(2*np.pi*n/(100.))) Well, I went and dug into NumPy. They write it as 0.5 - 0.5 * cos (...), and special case N = 1, and properly error check N 1. Still, probably because of differences in dictionary look ups (because of namespace scopes), np.hanning, on average, takes a wee bit over half as long as your case, and yours is only a shade faster than window = [0.5 - math.cos(2 * x * math.pi /100.) for x in range(101)] (Yes, I know I should've used xrange instead of range) Sorry, should've been smarter than this. Raising this to 1 million, rather than 100, nodes in the window, the timing difference between your version and NumPy's is tiny (but numpy still edges you out, but just barely), but they trounce my naive version, being around 7 or 8 times faster the list comprehension I suggested. So implementing this in vanilla python instead of using numpy would hurt performance a fair bit, and odds are the OP is going to put this to use somewhere that involves more maths, which makes learning about numpy well worth having asked the question here. -- http://mail.python.org/mailman/listinfo/python-list
logging sound / speech handler?
Hi, For an application in an industrial environment where the workers are not always sitting in front of the monitor, but are within earshot of the PC I would need an sound / speech handler for the standard logging system. It should beep or better say the logging message. (with standard filtering etc.) I google search was not successfull. Does anybode know of such a handler? -- Gregor -- http://mail.python.org/mailman/listinfo/python-list
Less APIs or more encapsulation?
2 class, B contains C. When user want to use some service of C, there are two choice: First, more encapsulation: = class B: def newMethod(self): self.c.newMethod() class C: def newMethod(self): #do something pass b.newMethod() == Sencond : Call seice of f c directly: = class B: pass class C: def newMethod(self): # somethining pass b.c.newMethod() = Generally, what I learned from books told me that 1st choice is better. But when C has many many methods to expose to outer user, 2nd choice seems to be more reasonable I In the first design, B.newMethod did nothing really useful. ctaully, , there are D/E/F, etc. in B we methodhod has to be exposed to user code, which makes encapsulation more tedious. In fact, these classes, C/D/E/F all have different jobs, but they all belongs to a real world object B, B is only a container of C/D/E/F. What do you think about it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Less APIs or more encapsulation?
一首诗 wrote: 2 class, B contains C. When user want to use some service of C, there are two choice: First, more encapsulation: = class B: def newMethod(self): self.c.newMethod() class C: def newMethod(self): #do something pass b.newMethod() == Sencond : Call seice of f c directly: = class B: pass class C: def newMethod(self): # somethining pass b.c.newMethod() = Generally, what I learned from books told me that 1st choice is better. But when C has many many methods to expose to outer user, 2nd choice seems to be more reasonable I In the first design, B.newMethod did nothing really useful. ctaully, , there are D/E/F, etc. in B we methodhod has to be exposed to user code, which makes encapsulation more tedious. In fact, these classes, C/D/E/F all have different jobs, but they all belongs to a real world object B, B is only a container of C/D/E/F. What do you think about it? This is a problem the Law of Demeter is concerned with: http://en.wikipedia.org/wiki/Law_of_Demeter Generally speaking, you should favor solution a over b. If you really have so many instances that expose their services through a container, you might consider creating code that makes declaration of pure delegates easier. Or maybe even redesign your code - if it would be ok for other code to work like this: work_with_c(b.c) without intermittently referring to b, I think it's ok. If not, you should delegate, because then functionality obviously depends on some new behavior. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tkinter] messed callbacks
Giacomo Boffi wrote: Diez B. Roggisch de...@nospam.web.de writes: Giacomo Boffi wrote: def doit(fr,lst): for c1,c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') Button(subframe,text='',command=lambda: output(c1+'-'+c2)).pack() Button(subframe,text='',command=lambda: output(c2+'-'+c1)).pack() subframe.pack(fill='x',expand=1) why the messed callbacks? what's the right thing to do? Reedy's Lambda Rule: if you have a problem with code that uses lambda expressions, rewrite with equivalent def statements and then review. Untested revision: def doit(fr,lst): for c1,c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' -'+c2) .pack(side='left',expand=1,fill='both') def cb12(): return output(c1+'-'+c2) def cb21(): return output(c2+'-'+c1) Button(subframe,text='',command=cb12).pack() Button(subframe,text='',command=cb21).pack() subframe.pack(fill='x',expand=1) For most people, it somehow seems more obvious with the def form that only the nonlocal names are captured, not the objects. In other words, the function objects created in each iteration are duplicates of each other. Since they are duplicates, one will do as well. The above should work even if you move the def statements out of the loop and put them *before* the for statement: (again, untested) def doit(fr,lst): def cb12(): return output(c1+'-'+c2) def cb21(): return output(c2+'-'+c1) for c1,c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' -'+c2) .pack(side='left',expand=1,fill='both') Button(subframe,text='',command=cb12).pack() Button(subframe,text='',command=cb21).pack() subframe.pack(fill='x',expand=1) Now it should be *really* obvious that the def statements only capture names: there *are no objects* to be captured when they are compiled! A simpler example. def f(): def g(): return i for i in 1,2,3: pass print(g()) f() # prints 3! The reason this can work is because the interpreter scans a function code block twice: first to find the names, second to generate code based on the findings of the first pass. So when it compiles def g(): return i, it has already looked ahead to discover that 'i' is local to f and not a module global name. Closures in python contain names, not the objects they refer to. So when you rebind that name (as you do above in your loop), sorry, i'm not conscient of rebinding a name... what do you mean by rebind that name exactly? Each iteration of the for loop rebinds the doit local names c1, c2 to a new pair of values from the zip. When the loop finishes, they are bound to the last pair of objects and these are the ones used when the callbacks are called. the created callbacks will only refer to the last bound value of a name. Capturing different objects within a function object for each iteration, which you want, requires additional code that creates a new and *different* (not duplicate) function object for each iteration. Create new closures, or bind arguments as defaults: funcs = [] def create_func(i): return lambda: i Or, as Scott D. D. pointed out, use functools.partial. for i in xrange(10): funcs.append(lambda i=i: i) funcs.append(create_func(i)) for f in funcs: print f() Terry Jan Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: a question about numpy
On 2009-09-08 20:45 PM, hi_roger wrote: hello, i want to ask a question about numpy. i know how to select a submatrix using the slice object in numpy. But how can i select a submatrix A[i1,i2,i3;j1,j2,j3] (elements in A on line i1,i2,i3 and column j1,j2,j3 , and i1,i2,i3,j1,j2,j3 are all arbitrary numbers ) The submatrix must share data memory with original matrix. Any one help? thank you Sturla is almost correct. What you really want is this: i = [[i1], [i2], [i3]] j = [[j1, j2, j3]] B = A[i, j] http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer If you have more numpy questions, please ask on the numpy mailing list. http://www.scipy.org/Mailing_Lists -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Extracting patterns after matching a regex
Mart. wrote: On Sep 8, 4:33 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:53 pm, MRAB pyt...@mrabarnett.plus.com wrote: Mart. wrote: On Sep 8, 3:14 pm, Andreas Tawn andreas.t...@ubisoft.com wrote: Hi, I need to extract a string after a matching a regular expression. For example I have the string... s = FTPHOST: e4ftl01u.ecs.nasa.gov and once I match FTPHOST I would like to extract e4ftl01u.ecs.nasa.gov. I am not sure as to the best approach to the problem, I had been trying to match the string using something like this: m = re.findall(rFTPHOST, s) But I couldn't then work out how to return the e4ftl01u.ecs.nasa.gov part. Perhaps I need to find the string and then split it? I had some help with a similar problem, but now I don't seem to be able to transfer that to this problem! Thanks in advance for the help, Martin No need for regex. s = FTPHOST: e4ftl01u.ecs.nasa.gov If FTPHOST in s: return s[9:] Cheers, Drea Sorry perhaps I didn't make it clear enough, so apologies. I only presented the example s = FTPHOST: e4ftl01u.ecs.nasa.gov as I thought this easily encompassed the problem. The solution presented works fine for this i.e. re.search(r'FTPHOST: (.*)',s).group(1). But when I used this on the actual file I am trying to parse I realised it is slightly more complicated as this also pulls out other information, for example it prints e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r\n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/ 0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', etc. So I need to find a way to stop it before the \r slicing the string wouldn't work in this scenario as I can envisage a situation where the string lenght increases and I would prefer not to keep having to change the string. If, as Terry suggested, you do have a tuple of strings and the first element has FTPHOST, then s[0].split(:)[1].strip() will work. It is an email which contains information before and after the main section I am interested in, namely... FINISHED: 09/07/2009 08:42:31 MEDIATYPE: FtpPull MEDIAFORMAT: FILEFORMAT FTPHOST: e4ftl01u.ecs.nasa.gov FTPDIR: /PullDir/0301872638CySfQB Ftp Pull Download Links: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB Down load ZIP file of packaged order: ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB.zip FTPEXPR: 09/12/2009 08:42:31 MEDIA 1 of 1 MEDIAID: I have been doing this to turn the email into a string email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) To me that seems a strange thing to do. You could just read the entire file as a string: f = open(email, 'r') s = f.read() so FTPHOST isn't the first element, it is just part of a larger string. When I turn the email into a string it looks like... 'FINISHED: 09/07/2009 08:42:31\r\n', '\r\n', 'MEDIATYPE: FtpPull\r\n', 'MEDIAFORMAT: FILEFORMAT\r\n', 'FTPHOST: e4ftl01u.ecs.nasa.gov\r\n', 'FTPDIR: /PullDir/0301872638CySfQB\r\n', 'Ftp Pull Download Links: \r \n', 'ftp://e4ftl01u.ecs.nasa.gov/PullDir/0301872638CySfQB\r\n', 'Down load ZIP file of packaged order:\r\n', So not sure splitting it like you suggested works in this case. Within the file are a list of files, e.g. TOTAL FILES: 2 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf FILESIZE: 11028908 FILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml FILESIZE: 18975 and what i want to do is get the ftp address from the file and collect these files to pull down from the web e.g. MOD13A2.A2007033.h17v08.005.2007101023605.hdf MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml Thus far I have #!/usr/bin/env python import sys import re import urllib email = sys.argv[1] f = open(email, 'r') s = str(f.readlines()) m = re.findall(rMOD\.\.h..v..\.005\..\ \, s) ftphost = re.search(r'FTPHOST: (.*?)\\r',s).group(1) ftpdir = re.search(r'FTPDIR: (.*?)\\r',s).group(1) url = 'ftp://' + ftphost + ftpdir for i in xrange(len(m)): print i, ':', len(m) file1 = m[i][:-4] # remove xml bit. file2 = m[i] urllib.urlretrieve(url, file1) urllib.urlretrieve(url, file2) which works, clearly my match for the MOD13A2* files isn't ideal I guess, but they will always occupt those dimensions, so it should work. Any suggestions on how to improve this are appreciated. Suppose the file contains your example text above. Using 'readlines' returns a list of the lines: f = open(email, 'r') lines = f.readlines() lines ['TOTAL FILES: 2\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\n', '\t\tFILESIZE: 11028908\n', '\n', '\t\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf.xml\n', '\t\tFILESIZE: 18975\n'] Using 'str' on that list then converts it to s string _representation_ of that list: str(lines) ['TOTAL FILES: 2\\n', '\\t\\tFILENAME: MOD13A2.A2007033.h17v08.005.2007101023605.hdf\\n', '\\t\\tFILESIZE: 11028908\\n', '\\n',
Re: a question about numpy
On 2009-09-08 22:03 PM, sturlamolden wrote: On 9 Sep, 03:45, hi_rogerrechardc...@gmail.com wrote: i know how to select a submatrix using the slice object in numpy. But how can i select a submatrix A[i1,i2,i3;j1,j2,j3] (elements in A on line i1,i2,i3 and column j1,j2,j3 , and i1,i2,i3,j1,j2,j3 are all arbitrary numbers ) You just pass an array of ints for each dimension. If you want a 3x3 submatrix, you must pass in two 3x3 arrays of indices. Oops! I just responded to the OP saying that you were almost correct; but I was just thinking of your latter 1D example rather than this correct statement. My apologies. -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
python and openSSL
Hi all. I need a trick to do something like this: openssl smime -decrypt -verify -inform DER -in ReadmeDiKe.pdf.p7m -noverify -out ReadmeDike.pdf To unwrap a p7m file and read his content. I know that I could use somthing like: import os os.system('openssl ') but i would use a python library to wrap openssl. I've already install pyOpenSSL, but I can not understand how to run the same command. Can someone help me? Thx to all. -- http://mail.python.org/mailman/listinfo/python-list
Re: Rapid GUI Programming with Python and Qt source code
On Sep 9, 2:33 pm, David Boddie dbod...@trolltech.com wrote: On Wed Sep 9 07:11:26 CEST 2009, Steven Woody wrote: *I've searched google and cannot find a valid link for the source code of the book Rapid GUI Programming with Python and Qt. Could anyone please give me a non-broken URL?* See this page for the links: http://www.qtrac.eu/pyqtbook.html David Thanks David, I completely missed the original message:-) BTW The URL is given on page 5 in the Introduction, but lots of people seem to miss it---I'll try to make the URL more prominent in future books. -- http://mail.python.org/mailman/listinfo/python-list
Function to apply superset of arguments to a function
Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? Cheers, Andrey 1. http://gist.github.com/183375 -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
On Sep 9, 1:47 am, The Music Guy music...@alphaios.net wrote: I should also mention--and I should have realized this much sooner--that each of the BaseN classes are themselves each going to have at least one common base which will define method_x, so each BaseN will be calling that if it defines its own method_x. Again, sorry I didn't mention that sooner. For some reason it didn't occur to me that it would be important. I feel dumb now... :P Here is the updated current example: class CommonBase(object): def method_x(self, a, b c): ... no call to superclass' method_x is needed here ... class MyMixin(object): def method_x(self, a, b, c): get_other_base(self).method_x(self, a, b, c) ... class BaseA(CommonBase): def method_x(self, a, b, c): super(BaseA, self).method_x(a, b, c) ... class BaseB(CommonBaset): ... class BaseC(CommonBase): def method_x(self, a, b, c): super(BaseC, self).method_x(a, b, c) ... class FooX(MyMixin, BaseA): ... class FooY(MyMxin, BaseB): ... class FooZ(MyMixin, BaseC): ... OK, how about this? class CommonBase(object): def method_x(self, a, b, c): print CommonBase class MyMixin(object): def method_x(self, a, b, c): print MyMixin, super(MyMixin, self).method_x(a, b, c) class BaseA(CommonBase): def method_x(self, a, b, c): print BaseA, super(BaseA, self).method_x(a, b, c) class BaseB(CommonBase): def method_x(self, a, b, c): print BaseB, super(BaseB, self).method_x(a, b, c) class BaseC(CommonBase): def method_x(self, a, b, c): print BaseC, super(BaseC, self).method_x(a, b, c) class FooX(MyMixin, BaseA): def method_x(self, a, b, c): print FooX, super(FooX, self).method_x(a, b, c) class FooY(MyMixin, BaseB): def method_x(self, a, b, c): print FooY, super(FooY, self).method_x(a, b, c) class FooZ(MyMixin, BaseC): # Supposing this class doesn't require a specialized method_x. pass FooX().method_x(1, 2, 3) # Prints 'FooX MyMixin BaseA CommonBase' FooY().method_x(1, 2, 3) # Prints 'FooY MyMixin BaseB CommonBase FooZ().method_x(1, 2, 3) # Prints 'MyMixin BaseC CommonBase' --- Each method_x implementation uses super() to ensure that the next base class method_x is called. The exception is CommonBase, which is presumed to be the hierarchy root. http://www.python.org/download/releases/2.2.3/descrintro/#cooperation http://www.python.org/download/releases/2.3/mro -- http://mail.python.org/mailman/listinfo/python-list
Re: logging sound / speech handler?
On Sep 9, 11:03 am, Gregor Horvath g...@gregor-horvath.com wrote: Hi, For an application in an industrial environment where the workers are not always sitting in front of the monitor, but are within earshot of the PC I would need an sound / speech handler for the standard logging system. It should beep or better say the logging message. (with standard filtering etc.) I google search was not successfull. Does anybode know of such a handler? -- Gregor Its Java, but JFugue and Log4JFugue show an interesting take on log sonification -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorovanfedo...@gmail.com wrote: Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? Cheers, Andrey 1. http://gist.github.com/183375 -- http://mail.python.org/mailman/listinfo/python-list What is your use-case for using this? It seems really odd to me. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tkinter] messed callbacks
snip def cb12(): return output(c1+'-'+c2) def cb21(): return output(c2+'-'+c1) I think these can be simplified, e.g: def cb12(): output(c1+'-'+c2) But I'd go with the functools.partial approach. You can save some code by making output() do more of the work: #--- from Tkinter import * from functools import partial def output(x,y,op): if op == : print x, ---, y elif op == : print x, ---, y else: print Operation argument error! def doit(fr,lst): for c1, c2 in zip(lst[::2], lst[1::2]): subframe=Frame(fr) Label(subframe,text=c1+' - '+c2).pack(side='left',expand=1,fill='both') for op in ('', ''): Button(subframe,text=op, command=partial(output, c1, c2, op)).pack() subframe.pack(fill='x',expand=1) root=Tk() doit(root,['pippo','pluto','paperino','zio_paperone']) Button(root,text='Q',command=root.destroy).pack(expand=1,fill='x') root.mainloop() #--- -John -- http://mail.python.org/mailman/listinfo/python-list
HTTP POST File without cURL
I'm working with an API that allows me to POST a zip file via HTTP and the documentation uses a cURL example. cURL works, but when I try to POST the file via python it fails. I don't want to use cURL (since I'm trying to be transparent and dependency-less), but I can't find anything online that works. When I use multipart/form-data methods (found here http://code.activestate.com/recipes/146306/), the recipient cannot decipher the attached file. This is about the most difficult thing I've had to do with python and yet it is supposed to be the very basics of HTTP. Example cURL command: curl -v -u username:passwd --data-binary @/home/jdgiotta/test.zip -H Content-Type: application/zip https://host/selector Is there a valid way to do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: hanning python
On 9 Sep, 16:57, pdpi pdpinhe...@gmail.com wrote: Raising this to 1 million, rather than 100, nodes in the window, the timing difference between your version and NumPy's is tiny (but numpy still edges you out, but just barely), but they trounce my naive version, being around 7 or 8 times faster the list comprehension I suggested. Premature optimization is the root of all evil in computer programming. Speed is not the issue here. -- http://mail.python.org/mailman/listinfo/python-list
Re: logging sound / speech handler?
Gregor Horvath wrote: Hi, For an application in an industrial environment where the workers are not always sitting in front of the monitor, but are within earshot of the PC I would need an sound / speech handler for the standard logging system. It should beep or better say the logging message. (with standard filtering etc.) I google search was not successfull. Does anybode know of such a handler? -- Gregor if you're on windows, you can use the windows speech api: import win32com.client s = win32com.client.Dispatch(SAPI.SpVoice) s.Speak('Is this punthoofd ') cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
When a web request is made, my Django views are called with argument `user_id' present if someone is logged in, and set to None if the request is anonymous. The response varies based on this argument - someone pulling a team's information will get their relationship to the team if they are logged in, but not if they are anonymous. I'd like the views to remain agnostic to this functionality, because most of them don't care if a particular user is calling them. Hence, I don't want to include `user_id=None' in all of their definitions. However, to support the views that *do* differentiate based on user, and to minimize effort required to go from being user-agnostic to user-specific, I'd like my authentication mechanism to pass `user_id' (among other things) only if they are present. I suppose this is an IoC principle or something - where methods declare what information they need in their argument list. Another example of this application is in accepting POST variables - I use a decorator @acceptsPOST which uses `apply_some' to pass all POST variables into a view, and let it ignore the ones it doesn't need. For example: @acceptsPOST def login(request, user_name, password): ... Instead of: def login(request): user_name = request.POST['user_name'] if 'user_name' in request.POST else None password = request.POST['password'] if 'password' in request.POST else None ... This is especially useful both when adding/removing POST variables, and when there end up being a lot of them. Cheers, Andrey On Wed, Sep 9, 2009 at 1:40 PM, David Stanek dsta...@dstanek.com wrote: On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorovanfedo...@gmail.com wrote: Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? Cheers, Andrey 1. http://gist.github.com/183375 -- http://mail.python.org/mailman/listinfo/python-list What is your use-case for using this? It seems really odd to me. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
On Sep 8, 10:47 pm, The Music Guy music...@alphaios.net wrote: I should also mention--and I should have realized this much sooner--that each of the BaseN classes are themselves each going to have at least one common base which will define method_x, so each BaseN will be calling that if it defines its own method_x. Again, sorry I didn't mention that sooner. For some reason it didn't occur to me that it would be important. I feel dumb now... :P Here is the updated current example: class CommonBase(object): def method_x(self, a, b c): ... no call to superclass' method_x is needed here ... class MyMixin(object): def method_x(self, a, b, c): get_other_base(self).method_x(self, a, b, c) ... What is get_other_base? Just use a regular super call here, get_other_base and hacks like that are what gets you into trouble. You seem to be overthinking this. You don't need to. Just use super () in MyMixin, and in all the other classes, consistently, and mind the order of the bases. And if I were you I wouldn't keep making updates to a current example because first you do questionable things define a get_other_base method, then you try to apply my advice without reverting to the original form you posted. Well of course you're going to have issues if you do that. Instead, start from scratch, and try to get a small example working, using your orginial post and my original suggestion. Once that works then try to apply it to your working example. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Class variable inheritance
On Sep 9, 3:32 am, HPJ henrypija...@gmail.com wrote: Maybe. For some languages this might be an obvious behavior, but Python would have different circumstances so it isn't so obvious (or possible) there. Which means this topic definitely needs to be handled in detail by the LR, and preferably also in the Tutorial. As I said, I'm sure the doc maintainers would likey welcome your contributions. Otherwise there is no way anyone coming to Python could know which of the many ways of inheritance Python follows. Mo way? You are definitely overstating things here. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Sep 9, 10:45 am, Andrey Fedorov anfedo...@gmail.com wrote: Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? Cheers, Andrey 1.http://gist.github.com/183375 It sounds like all you are doing is moving type checking out of the original function and into another function. In scripting languages, like python, type checking is frowned upon. The accepted idiom is to use try-except. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTP POST File without cURL
On Wed, Sep 9, 2009 at 1:57 PM, John D Giottajdgio...@gmail.com wrote: I'm working with an API that allows me to POST a zip file via HTTP and the documentation uses a cURL example. cURL works, but when I try to POST the file via python it fails. I don't want to use cURL (since I'm trying to be transparent and dependency-less), but I can't find anything online that works. When I use multipart/form-data methods (found here http://code.activestate.com/recipes/146306/), the recipient cannot decipher the attached file. This is about the most difficult thing I've had to do with python and yet it is supposed to be the very basics of HTTP. Example cURL command: curl -v -u username:passwd --data-binary @/home/jdgiotta/test.zip -H Content-Type: application/zip https://host/selector Is there a valid way to do this? Without seeing code it is hard to tell what is happening. What I would do is capture the HTTP traffic and compare Python to cURL. Then you'll know how to change you script. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: HTTP POST File without cURL
On 2009-09-09, John D Giotta jdgio...@gmail.com wrote: I'm working with an API that allows me to POST a zip file via HTTP and the documentation uses a cURL example. cURL works, but when I try to POST the file via python it fails. I don't want to use cURL (since I'm trying to be transparent and dependency-less), but I can't find anything online that works. When I use multipart/form-data methods (found here http://code.activestate.com/recipes/146306/), the recipient cannot decipher the attached file. This is about the most difficult thing I've had to do with python and yet it is supposed to be the very basics of HTTP. Example cURL command: curl -v -u username:passwd --data-binary @/home/jdgiotta/test.zip -H Content-Type: application/zip https://host/selector Is there a valid way to do this? Maybe, but reading from curl manpage it seems that that is doing POST /selector ... Content-type: application/zip data The backend is broken, they should have used PUT for that. Search for python http put and adapt, or lookt at urllib(2)/httplib and roll your own. -- Jarkko Torppa -- http://mail.python.org/mailman/listinfo/python-list
Re: start default application for read a pdf from python
Thenks for this suggestion, at the end I find this solution import os . . #then where I decide to show the file in the default application I put this #file_name the name I construct with path and all necessary #recor contain all the data of one record end the 4th position #the name of the file #for example file_name = os.path.join('document',str(record[3]) + .pdf) #the joun function make the separator from ducoment to the file #name relative to operatin system (windows '\') , (unix '/') #then where I call the default program if os.name == nt: os.filestart(%s % nome_file) elif os.name == posix: os.system(/usr/bin/xdg-open %s % nome_file) Other nice solution is import webbrowser . . . webbrowser.open(file_name) The difference is in unix sistem, the first call the default program for read the file of type, in this case pdf, this meens okular, acroread, or whatever, the second open the konqueror in kde desktop, in windows the function os.filestart call the default application for thet type of file interesting discussion about this I find in : http://ubuntuforums.org/showthread.php?t=1003198 very thenks to all Angelo Albert Hopkins ha scritto: The (most) portable way to do so in Linux (not necessarily Unix) is to use the xdg-open command. Ex, subprocess.Popen(['xdg-open', 'my-document.pdf']) -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPI upload documentation
Sorry to write again, but really nobody on the Python list knows how to get in touch with the people running PyPI's website in an effective way? Thanks! Dan On Tue, Sep 8, 2009 at 6:25 PM, Dan Yamins dyam...@gmail.com wrote: Dear all: I'm trying to upload documentation to the PyPI site for a project I'm working on (there's a new feature on the PyPI site that allows admins of projects to upload a zip file of the pages of documentation.) If you have admin access to a PyPI project, you can see this on the admin page for that project, at the bottom. However, it's failing do to what appears to be a permissions error. When I press Upload documentation, I get the following error: Forbidden You don't have permission to access /tabular/ on this server. -- Apache/2.2.9 (Debian) mod_fastcgi/2.4.6 mod_python/3.3.1 Python/2.5.2 mod_wsgi/2.3 Server at packages.python.org Port 80 If anyone could clue me into what's going wrong, that would be great. I know that this list might not be the right thing to write to -- I tried writing to the python.org webmester, but got only the automated reply. If there's a more appropriate list that I should write to instead, I'd be happy to learn of it. Thanks, Dan -- http://mail.python.org/mailman/listinfo/python-list
Re: Q on explicitly calling file.close
On Sat, 05 Sep 2009 23:41:08 +, Steven D'Aprano wrote: On Sat, 05 Sep 2009 16:14:02 +, kj wrote: Finally, I was under the impression that Python closed filehandles automatically when they were garbage-collected. [...] (3) For quick and dirty scripts, or programs that only use one or two files, relying on the VM to close the file is sufficient (although lazy in my opinion *wink*) Many years ago I read some big Python guy say something to the effect that you didn't need to close files, but if you don't it will bite you eventually. So I learned to type close(). Of course I wouldn't worry about that in quick and dirty scripts. Then there was that quick and dirty script that gradually mutated into a not-so-quick and filthy monstrosity that a certain project depended on. Stopped working one day. Me being dim, it took almost a day to find the problem... (I don't recall how exactly an open file caused a problem, it was still just three or four files altogether.) These days I've actually got the syntax and spelling memorized - I can type close() without needing to look it up! but for long-running applications using many files, or for debugging, you may want more control over what happens when. -- http://mail.python.org/mailman/listinfo/python-list
Python server locks up
I have a server running Python 2.6x64 which after running for about a month decides to lock up and become unresponsive to all threads for several minutes at a time. While it is locked up Python proceeds to consume large amounts of continually increasing memory. The basic function of the server is to serve a large dictionary - somewhat like a database. I have a couple theories as to why it locks up, but I'm not sure how to test them. Theories: Python is resizing the large dictionary Python is garbage collecting How would you suggest to figure out what is the problem? -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPI upload documentation
On 2009-09-09 15:14 PM, Dan Yamins wrote: Sorry to write again, but really nobody on the Python list knows how to get in touch with the people running PyPI's website in an effective way? http://www.python.org/community/sigs/current/catalog-sig/ -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Python server locks up
Zac Burns wrote: I have a server running Python 2.6x64 which after running for about a month decides to lock up and become unresponsive to all threads for several minutes at a time. While it is locked up Python proceeds to consume large amounts of continually increasing memory. The basic function of the server is to serve a large dictionary - somewhat like a database. I have a couple theories as to why it locks up, but I'm not sure how to test them. Theories: Python is resizing the large dictionary Python is garbage collecting How would you suggest to figure out what is the problem? If it has been running continuously all that time then it might be that the dictionary has grown too big (is that possible?) or that it's a memory fragmentation problem. In the latter case it might be an idea to restart Python every so often; perhaps it could do that automatically during a quiet time, eg at midnight every Sunday. -- http://mail.python.org/mailman/listinfo/python-list
Re: Q on explicitly calling file.close
On Sep 9, 3:18 pm, David C Ullrich dullr...@sprynet.com wrote: (snip) These days I've actually got the syntax and spelling memorized - I can type close() without needing to look it up! +1 You are so right David! I think some people around here need to look up code reuse. Here are a couple of simple templates for our friends to study... def read_file(fname, mode='rb'): '''open file and return contents''' try: f = open(fname, mode) s = f.read() return s except: return 0 finally: f.close() def write_file(fname, s, mode='wb'): '''open file, truncate, and write string''' try: f = open(fname, mode) f.write(s) return 1 except: return 0 finally: f.close() s = read_file(fname) if s: ... s += 'morecrap' write_file(s) #-- Extra Credit --# Create an append_file() function that takes a filename and string as args and appends to the file returning 1 on success, and 0 on failure. #-- Double Extra Creidit --# Create a backup_file() function that takes filename as arg and creates a copy of the file with the extension .bak... backup_file('C:\test.txt') - 'C:\test.bak' -- def get_enlightened(): import webbrowser url = 'http://jjsenlightenments.blogspot.com/' webbrowser.open(url) -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
David Stanek wrote: On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorovanfedo...@gmail.com wrote: I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - [ ... ] What is your use-case for using this? It seems really odd to me. I may have run into one possible use. I have a program that uses DB-API 2.0 to work with a database, sometimes SQLite3, sometimes PostgreSQL. Connect parameters are built up in a dict from a combination of defaults, environment values, and command-line arguments. This dictionary has to be pruned down before calling connect, because sqlite3.connect doesn't take the wide assortment of arguments that are needed for PostgreSQL. The existing program does this by hand, being programmed in advance to know which parameters are acceptable to which database module. Mel. -- http://mail.python.org/mailman/listinfo/python-list
Re: Q on explicitly calling file.close
r wrote: [snip] #-- Double Extra Creidit --# Create a backup_file() function that takes filename as arg and creates a copy of the file with the extension .bak... backup_file('C:\test.txt') - 'C:\test.bak' You should've used raw strings. :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Q on explicitly calling file.close
On Sep 9, 2009, at 4:50 PM, r wrote: On Sep 9, 3:18 pm, David C Ullrich dullr...@sprynet.com wrote: (snip) These days I've actually got the syntax and spelling memorized - I can type close() without needing to look it up! +1 You are so right David! I think some people around here need to look up code reuse. Here are a couple of simple templates for our friends to study... def read_file(fname, mode='rb'): '''open file and return contents''' try: f = open(fname, mode) s = f.read() return s except: return 0 finally: f.close() def write_file(fname, s, mode='wb'): '''open file, truncate, and write string''' try: f = open(fname, mode) f.write(s) return 1 except: return 0 finally: f.close() Unfortunately, both of these simple templates have the following problem -- if open fails, a NameError will be raised from the finally block. def read_file(fname, mode='rb'): '''open file and return contents''' f = open(fname, mode) try: return f.read() finally: f = f.close() I removed the except block because I prefer exceptions to error codes. def write_file(fname, s, mode='wb'): '''open file, truncate, and write string''' f = open(fname, mode) try: f.write(s) finally: f = f.close() In addition to fixing the latent bug in the second simple template, I took the opportunity to correct your heinous violation of command- query separation. Charles Yeomans -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Wed, Sep 9, 2009 at 5:03 PM, Melmwil...@the-wire.com wrote: David Stanek wrote: On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorovanfedo...@gmail.com wrote: I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - [ ... ] What is your use-case for using this? It seems really odd to me. I may have run into one possible use. I have a program that uses DB-API 2.0 to work with a database, sometimes SQLite3, sometimes PostgreSQL. Connect parameters are built up in a dict from a combination of defaults, environment values, and command-line arguments. This dictionary has to be pruned down before calling connect, because sqlite3.connect doesn't take the wide assortment of arguments that are needed for PostgreSQL. The existing program does this by hand, being programmed in advance to know which parameters are acceptable to which database module. The way I would normally do it is to use the URI format and based on the scheme choose a handler. For example: mysql://u...@host:server/db, would translate to a mysql specific function that knows what to do. Adding support for new schemes does mean an additional function, but I like the control. And it's explicit. I worry about the magic of the OP's approach. In your example generate a dictionary in a generic way and apply it to a set of functions. What happens if in the future if connect_mysql adds adds a parameter with the same name as one in connect_postgres, but different semantics. Now the magic is broken and you have an ugly special case. -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
search term parsing like Google/Gmail
I am looking for a string parser that works kind of like Google's or Gmail's advanced search capabilities. So it would turn something like this: (subject:hi there from:[tim, tom, -fred]) or (subject:foobar from:sam) into a python structure that could be used. I don't really care so much about the search syntax except that easy and intuitive is best for users. Does something like this exist? -- -- Randy Syring Intelicom 502-644-4776 Whether, then, you eat or drink or whatever you do, do all to the glory of God. 1 Cor 10:31 -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Sep 9, 10:40 am, David Stanek dsta...@dstanek.com wrote: On Wed, Sep 9, 2009 at 12:45 PM, Andrey Fedorovanfedo...@gmail.com wrote: Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? What is your use-case for using this? It seems really odd to me. Use case seems perfectly obvious to me. You have a set of functions that use different strategies to accomplish a task, and there is a lot of overlap in the arguments used but no consistency. You want to be able to swap in different functions so as to try different strategies (either while editing, or programmatically). Instead of dealing with arguments that change everytime you want to swap in a different function, you can use this filter and work with a single argument set. The example that pops to my mind is numerical optimization. Many numerical optimizers have similar overall strategies but differ in underlying details, so they will tend to take different options. An argument filter like the OP wrote would be quite handy here. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Sep 9, 11:47 am, 7stud bbxx789_0...@yahoo.com wrote: On Sep 9, 10:45 am, Andrey Fedorov anfedo...@gmail.com wrote: Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? Cheers, Andrey 1.http://gist.github.com/183375 It sounds like all you are doing is moving type checking out of the original function and into another function. I'm not sure where you got the idea that he was doing type checking, unless you just saw the word TypeError and made a knee-jerk assumption about what was he was doing. If you'd have bothered trying to understand the post you would have seen that he was filtering arguments by name. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Function to apply superset of arguments to a function
On Sep 9, 9:45 am, Andrey Fedorov anfedo...@gmail.com wrote: Hi all, I've written a function [1] called apply_some which takes a set of keywords arguments, filters only those a function is expecting, and calls the function with only those arguments. This is meant to suppress TypeErrors - a way to abstract the logic which checks what arguments a passed-in function accepts. For example: def foo(x=1, y=2): return (x,y) apply_some(foo, y=0, z=hi) // calls foo(y=0) - (1,0) I'd like to expand this to fill undefined arguments with None, but before I do, does anyone know of any packages/libraries which either do something similar or would make this code cleaner? I don't know of any, but I would be surprised of the code you posted could be made any cleaner. Even if it's possible to improve your implementation of apply_some, your usage is as clean and straightforward as it gets. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Q on explicitly calling file.close
On Sep 9, 4:19 pm, Charles Yeomans char...@declaresub.com wrote: (snip:) Unfortunately, both of these simple templates have the following problem -- if open fails, a NameError will be raised from the finally block. (snip) I removed the except block because I prefer exceptions to error codes. how will the caller know an exception has occurred? What if logic depends on the validation that a file *had* or *had not* been written too, huh? In addition to fixing the latent bug in the second simple template, I took the opportunity to correct your heinous violation of command- query separation. Charles Yeomans Oh I see! But what happens if the filename does not exist? What then? open will blow chucks thats what! Here is a version for our paranoid- schizophrenic-sadomasochist out there... def egor_read_file(fname, mode='rb'): print 'yes, master' try: f = open(fname, mode=mode) except IOError: return (0, 'But, the file no open master!') try: s = f.read() except NameError: return (0, 'the file still no open master!') try: f.close() except: print 'That file sure is tricky master! return (s, 'Whew! here is the file contents, master') MRAB wrote: You should've used raw strings. :-) rats!, you got me on that one :-) -- free beer tomorrow @ http://jjsenlightenments.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list
how to log connection refused attempt with python-paramiko
hello all, I am getting to grips with paramiko. I am trying to open a ssh connection to my server 127.0.0.1 using paramiko and want to specify the password via the program itself. I want to generate and change passwds via the program very frequently and hence am avoiding a key based approach. I am using [code] def send_ssh(ip): ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='username', password='thispasswd', port=22) [/code] and I get Traceback (most recent call last): File ./client.py, line 76, in module send_ssh(ip) File ./client.py, line 46, in send_ssh ssh.connect('127.0.0.1', username='username', password='thispasswd', port=22) File /var/lib/python-support/python2.5/paramiko/client.py, line 299, in connect self._policy.missing_host_key(self, hostname, server_key) File /var/lib/python-support/python2.5/paramiko/client.py, line 83, in missing_host_key raise SSHException('Unknown server %s' % hostname) paramiko.SSHException: Unknown server 127.0.0.1 The screen just hangs, looks like it is waiting/timing-out and then if I use ctrl-C, it ouputs Exception exceptions.KeyboardInterrupt in module 'threading' from '/ usr/lib/python2.5/threading.pyc' ignored In case I specify a different port, like 5. I got a socket.error: (111, 'Connection refused') . Is there a log file where this is recorded. I looked up /var/log/auth.log and syslog, messages but could not find a reference to this erroneous login attempt. [code] def send_ssh(ip): ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='testusername', password='thisshouldbethepasswd', port=5) [/code] -- http://mail.python.org/mailman/listinfo/python-list
Re: how to log connection refused attempt with python-paramiko
On Sep 9, 3:35 pm, nickname thebiggestbangthe...@gmail.com wrote: hello all, I am getting to grips with paramiko. I am trying to open a ssh connection to my server 127.0.0.1 using paramiko and want to specify the password via the program itself. I want to generate and change passwds via the program very frequently and hence am avoiding a key based approach. I am using [code] def send_ssh(ip): ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='username', password='thispasswd', port=22) [/code] and I get Traceback (most recent call last): File ./client.py, line 76, in module send_ssh(ip) File ./client.py, line 46, in send_ssh ssh.connect('127.0.0.1', username='username', password='thispasswd', port=22) File /var/lib/python-support/python2.5/paramiko/client.py, line 299, in connect self._policy.missing_host_key(self, hostname, server_key) File /var/lib/python-support/python2.5/paramiko/client.py, line 83, in missing_host_key raise SSHException('Unknown server %s' % hostname) paramiko.SSHException: Unknown server 127.0.0.1 The screen just hangs, looks like it is waiting/timing-out and then if I use ctrl-C, it ouputs Exception exceptions.KeyboardInterrupt in module 'threading' from '/ usr/lib/python2.5/threading.pyc' ignored In case I specify a different port, like 5. I got a socket.error: (111, 'Connection refused') . Is there a log file where this is recorded. I looked up /var/log/auth.log and syslog, messages but could not find a reference to this erroneous login attempt. [code] def send_ssh(ip): ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='testusername', password='thisshouldbethepasswd', port=5) [/code] Update: I tried restarting ssh from /etc/init.d/ but no luck -- http://mail.python.org/mailman/listinfo/python-list
Re: how to log connection refused attempt with python-paramiko
On Sep 9, 3:37 pm, nickname thebiggestbangthe...@gmail.com wrote: On Sep 9, 3:35 pm, nickname thebiggestbangthe...@gmail.com wrote: hello all, I am getting to grips with paramiko. I am trying to open a ssh connection to my server 127.0.0.1 using paramiko and want to specify the password via the program itself. I want to generate and change passwds via the program very frequently and hence am avoiding a key based approach. I am using [code] def send_ssh(ip): ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='username', password='thispasswd', port=22) [/code] and I get Traceback (most recent call last): File ./client.py, line 76, in module send_ssh(ip) File ./client.py, line 46, in send_ssh ssh.connect('127.0.0.1', username='username', password='thispasswd', port=22) File /var/lib/python-support/python2.5/paramiko/client.py, line 299, in connect self._policy.missing_host_key(self, hostname, server_key) File /var/lib/python-support/python2.5/paramiko/client.py, line 83, in missing_host_key raise SSHException('Unknown server %s' % hostname) paramiko.SSHException: Unknown server 127.0.0.1 The screen just hangs, looks like it is waiting/timing-out and then if I use ctrl-C, it ouputs Exception exceptions.KeyboardInterrupt in module 'threading' from '/ usr/lib/python2.5/threading.pyc' ignored In case I specify a different port, like 5. I got a socket.error: (111, 'Connection refused') . Is there a log file where this is recorded. I looked up /var/log/auth.log and syslog, messages but could not find a reference to this erroneous login attempt. [code] def send_ssh(ip): ssh = paramiko.SSHClient() ssh.connect('127.0.0.1', username='testusername', password='thisshouldbethepasswd', port=5) [/code] Update: I tried restarting ssh from /etc/init.d/ but no luck Solved the problem using info from http://ubuntuforums.org/showthread.php?t=743119 -- http://mail.python.org/mailman/listinfo/python-list
Re: logging sound / speech handler?
For an application in an industrial environment where the workers are not always sitting in front of the monitor, but are within earshot of the PC I would need an sound / speech handler for the standard logging system. It should beep or better say the logging message. (with standard filtering etc.) I google search was not successfull. Does anybode know of such a handler? I think this would end up being an OS-specific thing. On Win32, Stef suggests using SAPI (which may need to be installed for older versions such as Win2k). I've not used Win32 TTS for a while, and don't have ready access to a Win32 box with sound to run some tests. On *nix, there's the Festival/Flite/Mbrola suite of TTS tools. You might be able to have one of their toolkit listen on a pipe to read whatever comes in, and then just log to that FIFO target as a file. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPI upload documentation
On Wed, Sep 9, 2009 at 4:29 PM, Robert Kern robert.k...@gmail.com wrote: On 2009-09-09 15:14 PM, Dan Yamins wrote: Sorry to write again, but really nobody on the Python list knows how to get in touch with the people running PyPI's website in an effective way? http://www.python.org/community/sigs/current/catalog-sig/ I'm sorry to be a dunce -- but I'm not sure how this addresses my question. I've been having a problem with a feature of the PyPI website (the feature which is supposed to allow me to upload documentation as a .zip file of html documentation of my project), but I can't get the python webmaster to reply to me.Are you saying that I should look at PEP 301? Or write to catalog-...@python.org? Or are you saying that I should be using my distutils to do this? Sorry for not understanding, Dan -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
lxml question
I would like to click on an image in a web page that I retrieve using urllib in order to trigger an event. Here is the piece of code with the image that I want to click: input type=image style=border-width: 0px; height: 22px; width: 49px; onclick=return checkPhoneField(document.contactFrm, 'mobile'); alt=sms src=images/button_sms.bmp id=smsToMobile name=smsToMobile/ I don't know how to do it (I'm trying using lxml, but any suggestion can help). Thanks, Mattia -- http://mail.python.org/mailman/listinfo/python-list
Re: PyPI upload documentation
On 2009-09-09 18:14 PM, Dan Yamins wrote: On Wed, Sep 9, 2009 at 4:29 PM, Robert Kern robert.k...@gmail.com mailto:robert.k...@gmail.com wrote: On 2009-09-09 15:14 PM, Dan Yamins wrote: Sorry to write again, but really nobody on the Python list knows how to get in touch with the people running PyPI's website in an effective way? http://www.python.org/community/sigs/current/catalog-sig/ I'm sorry to be a dunce -- but I'm not sure how this addresses my question. I've been having a problem with a feature of the PyPI website (the feature which is supposed to allow me to upload documentation as a .zip file of html documentation of my project), but I can't get the python webmaster to reply to me.Are you saying that I should look at PEP 301? Or write to catalog-...@python.org mailto:catalog-...@python.org? Or are you saying that I should be using my distutils to do this? Write to catalog-...@python.org . -- Robert Kern I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth. -- Umberto Eco -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
On Wed, Sep 9, 2009 at 1:21 PM, Carl Bankspavlovevide...@gmail.com wrote: On Sep 8, 10:47 pm, The Music Guy music...@alphaios.net wrote: What is get_other_base? Just use a regular super call here, get_other_base and hacks like that are what gets you into trouble. You seem to be overthinking this. You don't need to. Just use super () in MyMixin, and in all the other classes, consistently, and mind the order of the bases. And if I were you I wouldn't keep making updates to a current example because first you do questionable things define a get_other_base method, then you try to apply my advice without reverting to the original form you posted. Well of course you're going to have issues if you do that. Instead, start from scratch, and try to get a small example working, using your orginial post and my original suggestion. Once that works then try to apply it to your working example. get_other_base() is supposed to return the other superclass (base) that is being used in conjunction with the current superclass. So if FooX inherits from MyMixin and BaseB, and get_other_base(self) is called from a method defined in MyMixin, BaseB is returned. In any case, that function is merely psuedocode, not an actual part of the implementation. Its purpose in my example was merely to show the effect I was trying to acheive. I used it because I'm having trouble understanding exactly how the super() function works; it always seems to do something I didn't expect, or not do something that I did expect. (I say this after having read the online documentation, btw.) Anyway, Ryles' last suggestion helped a lot. Thanks, Ryles. (And Carl and Scott, too, of course.) Here's the code I'm going with: def main(): basea = BaseA() baseb = BaseB() basec = BaseC() foox = FooX() fooy = FooY() fooz = FooZ() basea.method_x(I, Am, BaseA!); print baseb.method_x(One, Two, Three); print basec.method_x(Ay, Bee, See); print print foox.method_x(I, AM, X) print fooy.method_x(ESTOY, Y, !) print fooz.method_x(100, 200, 300) class MyMixin(object): def method_x(self, a, b, c): super(MyMixin, self).method_x(a, b, c) print MyMixin.method_x(%s, %s, %s, %s) % (repr(self), repr(a), repr(b), repr(c)) class CommonBase(object): def method_x(self, a, b, c): print CommonBase.method_x(%s, %s, %s, %s) % (repr(self), repr(a), repr(b), repr(c)) class BaseA(CommonBase): def method_x(self, a, b, c): super(BaseA, self).method_x(a, b, c) print BaseA.method_x(%s, %s, %s, %s) % (repr(self), repr(a), repr(b), repr(c)) class BaseB(CommonBase): def method_x(self, a, b, c): super(BaseB, self).method_x(a, b, c) print BaseB.method_x(%s, %s, %s, %s) % (repr(self), repr(a), repr(b), repr(c)) class BaseC(CommonBase): pass class FooX(MyMixin, BaseA): def method_x(self, a, b, c): super(FooX, self).method_x(a, b, c) print FooX.method_x(%s, %s, %s, %s) % (repr(self), repr(a), repr(b), repr(c)) class FooY(MyMixin, BaseB): pass class FooZ(MyMixin, BaseC): def method_x(self, a, b, c): super(FooZ, self).method_x(a, b, c) print FooZ.method_x(%s, %s, %s, %s) % (repr(self), repr(a), repr(b), repr(c)) if __name__ == '__main__': main() Output: CommonBase.method_x(__main__.BaseA object at 0xb7d0d42c, 'I', 'Am', 'BaseA!') BaseA.method_x(__main__.BaseA object at 0xb7d0d42c, 'I', 'Am', 'BaseA!') CommonBase.method_x(__main__.BaseB object at 0xb7d0d44c, 'One', 'Two', 'Three') BaseB.method_x(__main__.BaseB object at 0xb7d0d44c, 'One', 'Two', 'Three') CommonBase.method_x(__main__.BaseC object at 0xb7d0d46c, 'Ay', 'Bee', 'See') CommonBase.method_x(__main__.FooX object at 0xb7d0d48c, 'I', 'AM', 'X') BaseA.method_x(__main__.FooX object at 0xb7d0d48c, 'I', 'AM', 'X') MyMixin.method_x(__main__.FooX object at 0xb7d0d48c, 'I', 'AM', 'X') FooX.method_x(__main__.FooX object at 0xb7d0d48c, 'I', 'AM', 'X') CommonBase.method_x(__main__.FooY object at 0xb7d0d4ac, 'ESTOY', 'Y', '!') BaseB.method_x(__main__.FooY object at 0xb7d0d4ac, 'ESTOY', 'Y', '!') MyMixin.method_x(__main__.FooY object at 0xb7d0d4ac, 'ESTOY', 'Y', '!') CommonBase.method_x(__main__.FooZ object at 0xb7d0d4cc, 100, 200, 300) MyMixin.method_x(__main__.FooZ object at 0xb7d0d4cc, 100, 200, 300) FooZ.method_x(__main__.FooZ object at 0xb7d0d4cc, 100, 200, 300) You may notice that MyMixin calls the super's method before doing anything of its own. This is intentional--MyMixin's job cannot be done correctly until the other bases have done their part. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
Btw, Carl, please forgive me if I frustrate you, because I'm trying my best not to. I'm trying to keep track of what I did and what you did and what Ryles and Scott did, while at the same time trying to keep a firm grasp of exactly what it is I'm trying to acheive. Besides that, I'm not a professional programmer--just a hobbyist. And of course, there's all the other IRL things I'm trying to deal with simultaneously with this...hopefully you can see how I would make mistakes. -- http://mail.python.org/mailman/listinfo/python-list
Re: search term parsing like Google/Gmail
I am looking for a string parser that works kind of like Google's or Gmail's advanced search capabilities. So it would turn something like this: (subject:hi there from:[tim, tom, -fred]) or (subject:foobar from:sam) into a python structure that could be used. I don't really care so much about the search syntax except that easy and intuitive is best for users. Does something like this exist? You might want to look at pyparsing. HTH, Daniel -- Psss, psss, put it down! - http://www.cafepress.com/putitdown -- http://mail.python.org/mailman/listinfo/python-list
ANN: dh, the daemon helper
dh, the daemon helper The daemon helper starts any program or script as a daemon. It's a small C program with a simple interface and a liberal license. ftp://ftp.isp2dial.com/users/jak/src/dh/ Get the files and do: make install clean To build and install dh. Don't try to run the Sh.install script directly, it must be invoked using the Makefile. I use dh for starting scripts which read fifos fed by syslog. They block on read until syslog provides data to work on. They never end, and need help to start as daemons. But that's just one example. There are many other potential uses for the daemon helper. I use dh on Linux, but was curious about portability. With some minor changes, I compiled and installed it on NetBSD 5.0.1 x86. So now it's portable. Wheee! It's a cool tool, it reports problems encountered when trying to exec the target daemon program or script. Debian's start-stop-deamon can't do that, nor can any other daemon tool I know of. It's minimal, with only one command line option, -p. Avoiding unneeded bells and whistles was my intentional design. In six months time, I could lose interest in computers, start a new career, and the work would be lost forever. Someone who likes C more than I do should adopt dh and help it grow. But if you do, don't believe what Stevens wrote about ignoring SIGHUP before the second fork(). It's not true, so don't write voodoo code to handle it! See the thread in c.u.p with the subject Orphaned process groups, daemon startup, SIGHUP. If you can't adopt dh, but have ideas for patches, send them. But if I don't respond, well then, you're on your own. There is no man page for dh, but the README explains how to use it. If there is enough interest, maybe someday I will give dh an official version number and use some version control. But for now, the date of last modification is all there is. dh is its name; a natural companion to sh. -- Webmail for Dialup Users http://www.isp2dial.com/freeaccounts.html -- http://mail.python.org/mailman/listinfo/python-list
Re: lxml question
On Wed, Sep 9, 2009 at 4:11 PM, mattiager...@gmail.com wrote: I would like to click on an image in a web page that I retrieve using urllib in order to trigger an event. Here is the piece of code with the image that I want to click: input type=image style=border-width: 0px; height: 22px; width: 49px; onclick=return checkPhoneField(document.contactFrm, 'mobile'); alt=sms src=images/button_sms.bmp id=smsToMobile name=smsToMobile/ I don't know how to do it (I'm trying using lxml, but any suggestion can help). You need to hook into an actual web browser since the event is JavaScript code. Cheers, Chris -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple inheritance - How to call method_x in InheritedBaseB from method_x in InheritedBaseA?
On Sep 9, 4:37 pm, The Music Guy music...@alphaios.net wrote: On Wed, Sep 9, 2009 at 1:21 PM, Carl Bankspavlovevide...@gmail.com wrote: On Sep 8, 10:47 pm, The Music Guy music...@alphaios.net wrote: What is get_other_base? Just use a regular super call here, get_other_base and hacks like that are what gets you into trouble. You seem to be overthinking this. You don't need to. Just use super () in MyMixin, and in all the other classes, consistently, and mind the order of the bases. And if I were you I wouldn't keep making updates to a current example because first you do questionable things define a get_other_base method, then you try to apply my advice without reverting to the original form you posted. Well of course you're going to have issues if you do that. Instead, start from scratch, and try to get a small example working, using your orginial post and my original suggestion. Once that works then try to apply it to your working example. get_other_base() is supposed to return the other superclass (base) that is being used in conjunction with the current superclass. So if FooX inherits from MyMixin and BaseB, and get_other_base(self) is called from a method defined in MyMixin, BaseB is returned. In any case, that function is merely psuedocode, not an actual part of the implementation. Ah, but see unless you tell us that, we will not know and will give you inappropriate advice. Moral of the story: post the code that you actually ran. And if you take anyone's advice, apply it to the actual code they were advising you on. Its purpose in my example was merely to show the effect I was trying to acheive. I used it because I'm having trouble understanding exactly how the super() function works; it always seems to do something I didn't expect, or not do something that I did expect. (I say this after having read the online documentation, btw.) super() is unfortunately misnamed after the analogous feature of Java; the analogy breaks down under multiple inheritance. Think of super as more like call next method, where the next method could be from a base class or a sister class. However it always works left to right in the list of bases, which is why it was important for MyMixin to be listed first. Anyway, Ryles' last suggestion helped a lot. Thanks, Ryles. (And Carl and Scott, too, of course.) Here's the code I'm going with: I'm glad it worked out. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: Python server locks up
If it has been running continuously all that time then it might be that the dictionary has grown too big (is that possible?) or that it's a memory fragmentation problem. In the latter case it might be an idea to restart Python every so often; perhaps it could do that automatically during a quiet time, eg at midnight every Sunday. -- http://mail.python.org/mailman/listinfo/python-list I did some testing with the dictionary size and ruled that out. Memory fragmentation is an interesting idea. Is there a way to check python's fragmentation or run a defragment periodically? My first thought there would be that a defragment would invalidate ids... err... -- Zachary Burns (407)590-4814 Aim - Zac256FL Production Engineer (Digital Overlord) Zindagi Games -- http://mail.python.org/mailman/listinfo/python-list
Re: Less APIs or more encapsulation?
On Wed, Sep 9, 2009 at 10:08 AM, 一首诗newpt...@gmail.com wrote: But when C has many many methods to expose to outer user, 2nd choice seems to be more reasonable I In the first design, B.newMethod did nothing really useful. Is there any reason you can't do something like the following? class B(object): def __init__(self, c): self.__c = c; def __getattr__(self, name): return self.__c.__getattribute__(name) class C(object): def sayHi(self): print c says hi So that when you call B and it doesn't have the attribute, it looks at it's instance of C? \t -- http://mail.python.org/mailman/listinfo/python-list
Re: a question about numpy
Robert Kern wrote: On 2009-09-08 20:45 PM, hi_roger wrote: hello, i want to ask a question about numpy. i know how to select a submatrix using the slice object in numpy. But how can i select a submatrix A[i1,i2,i3;j1,j2,j3] (elements in A on line i1,i2,i3 and column j1,j2,j3 , and i1,i2,i3,j1,j2,j3 are all arbitrary numbers ) The submatrix must share data memory with original matrix. Any one help? thank you Sturla is almost correct. What you really want is this: i = [[i1], [i2], [i3]] j = [[j1, j2, j3]] B = A[i, j] http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer If you have more numpy questions, please ask on the numpy mailing list. http://www.scipy.org/Mailing_Lists wow..., thank you all :) but it seems it is impossible to make the submatrix share data with the original matrix in pure numpy code ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python server locks up
On Wed, Sep 9, 2009 at 4:28 PM, Zac Burnszac...@gmail.com wrote: How would you suggest to figure out what is the problem? I don't think you said your OS so I'll assume Linux. Sometimes it is more noise than value, but stracing the process may shed light on what system calls are being made. This in turn may help you narrow your focus. I find strace helps me a ton in some really tough problems. Are you watching for swapping, CPU usage, etc.? -- David blog: http://www.traceback.org twitter: http://twitter.com/dstanek -- http://mail.python.org/mailman/listinfo/python-list
Re: python and openSSL
On 9 Sep, 01:30 pm, luca...@gmail.com wrote: Hi all. I need a trick to do something like this: openssl smime -decrypt -verify -inform DER -in ReadmeDiKe.pdf.p7m -noverify -out ReadmeDike.pdf To unwrap a p7m file and read his content. I know that I could use somthing like: import os os.system('openssl ') but i would use a python library to wrap openssl. I've already install pyOpenSSL, but I can not understand how to run the same command. pyOpenSSL wraps the parts of OpenSSL which deal with S/MIME. I think that M2Crypto does, though I haven't used those parts of it myself. Jean-Paul -- http://mail.python.org/mailman/listinfo/python-list