RE: Python Worship
Wow! That must have been a pretty early beta. > -Original Message- > From: Nick [mailto:[EMAIL PROTECTED] > Sent: 30 November 2006 17:16 > To: python-list@python.org > Subject: Python Worship > > http://www.sciencedaily.com/releases/2006/11/061130081347.htm > > World's Oldest Ritual Discovered -- Worshipped The Python 70,000 Years > Ago > > Nick > > > ** The information contained in, or attached to, this e-mail, may contain confidential information and is intended solely for the use of the individual or entity to whom they are addressed and may be subject to legal privilege. If you have received this e-mail in error you should notify the sender immediately by reply e-mail, delete the message from your system and notify your system manager. Please do not copy it for any purpose, or disclose its contents to any other person. The views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of the company. The recipient should check this e-mail and any attachments for the presence of viruses. The company accepts no liability for any damage caused, directly or indirectly, by any virus transmitted in this email. ** -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
In article <[EMAIL PROTECTED]>, "Paul McGuire" <[EMAIL PROTECTED]> wrote: > "Carl Banks" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > > A straightforward, Pythonic way to do it would be to create an > > intermediate representation that understands both the existing class > > interfaces and the RDB stuff, but that could lead to synchronizing > > problems and a big hit in performance. And it's probably a lot of work > > compared to tacking on methods. OTOH, it could help with hairiness you > > mention. (I recently did something similar in one of my projects, > > though the intermediary was transient.) > > > I would second Carl's recommendation that you find some way to persist an > interim version of these expensive-to-create objects, so you can quickly > load debuggable instances to accelerate your development process. With > luck, you can get by with out-of-the-box marshal/unmarshal using the pickle > module. We've done this several times in my office with objects that an > application creates only after some extensive GUI interaction - it just > slows down development too much without some quick import of debuggable > instances. > > Even though this seems like a sidetrack, it's a pretty direct shortcut, > without too much unusual technology or design work. These objects can be parts of huge networks of massively linked data structures. They are in constant flux. It is not uncommon to hit a bug after many minutes, sometimes hours, of computation. Having to store the whole shlemobble after every operation would slow things down by orders of magnitude. And writing code to be clever and only store the dirty bits would be a pain in the ass. I think I'll stick with Plan A. rg -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
In article <[EMAIL PROTECTED]>, Ron Garret <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > > > "Ron Garret" <[EMAIL PROTECTED]> wrote: > > > > > > > > > > One of the things I find annoying about Python is that when you make a > > > change to a method definition that change is not reflected in existing > > > instances of a class (because you're really defining a new class when > > > you reload a class definition, not actually redefining it). So I came > > > up with this programming style: > > > > I would have thought that not changing yesterday was the very essence of > > dynamism (dynamicness ??) - but that when you change something - it applies > > from that point in time forwards... > > I don't want to get into a philosophical debate. Actually, I changed my mind. Consider: def g(): print 'G' def h(): print 'H' def f(): g() class C1: def m1(self): f() class C2: def m1(self): g() c1 = C1() c2 = C2() def f(): h() class C2: def m1(self): h() c1.m1() # Prints H c2.m1() # Prints G On what principled basis can you justify two different outputs in this case? Why should I be able to change the definition of f and not have to go back and recompile all references to it, but not m1? rg -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
In article <[EMAIL PROTECTED]>, "Hendrik van Rooyen" <[EMAIL PROTECTED]> wrote: > "Ron Garret" <[EMAIL PROTECTED]> wrote: > > > > > > One of the things I find annoying about Python is that when you make a > > change to a method definition that change is not reflected in existing > > instances of a class (because you're really defining a new class when > > you reload a class definition, not actually redefining it). So I came > > up with this programming style: > > I would have thought that not changing yesterday was the very essence of > dynamism (dynamicness ??) - but that when you change something - it applies > from that point in time forwards... I don't want to get into a philosophical debate. I'll just point you to CLOS as an example of an object system that already works this way. > What do you propose to do about the outputs from such classes that have > already happened? The ability to change methods on the fly will be used mainly for debugging I expect. rg -- http://mail.python.org/mailman/listinfo/python-list
Re: EasyInstall under Windows - strange behaviour
[EMAIL PROTECTED] schrieb: > > I'm no expert, but it sounds like you associated the .py file extension > with the pythonwin program, so that's what's being used to open it > (instead of the desired python.exe). See > http://support.microsoft.com/kb/320033 for more information. > > hth, > Don Thank you for the tip, but I checked this and this is not the case. I presume that I missed a step in the ez_setup process. Thanks again Norbert -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Question About Compiling.
yndesai wrote: > Is it that no compiling facility is hindering the growth of python > in commercial circuit . . . ? good thing most commercial Python developers haven't noticed this, then. if you don't know that some random guy on the internet thinks that some- thing doesn't exist, there's nothing that keeps you from using it ;-) (why are you blaming you inability to use Linux installation tools on Python, btw? most basic Python libraries are only an apt-get away if you're using a sane Linux distribution.) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python spam?
Tim Peters wrote: > It's been going on for years. The most frequent forged "Python > related" sender address I've seen is actually [EMAIL PROTECTED], > followed (but not closely) by /F's [EMAIL PROTECTED] Spammers > harvest legit addresses to forge via scraping web pages and via > Trojans scouring newbies' address books. when you get this kind of "clustering" effect, chances are that it's a trojan on someone's computer that's actually sending the mails, using mail addresses found on the infected computer (address books and browser caches are good sources for this). (so in your cases, it's probably just some poor python-dev reader who hasn't updated his virus checker lately...) -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are slice indices the way they are in python?
Michael Torrie wrote: > Forgive me for my ignorance, but isn't "2006-12-31 23:59:59" actually > one entire second earlier than "2007-01-01 00:00:00"? Hence they are > two different dates are they not? given the context, maybe the poster meant that he's storing date *ranges* as [start, stop) (i.e. including start but not including stop). -- http://mail.python.org/mailman/listinfo/python-list
RE: Python Question About Compiling.
I got attracted to python since I heard about PythonCAD, while I used Fortran and Basic during graduation days & VBA for some macros in Office. I liked the python as it seems smart. But without compiling it is a trouble to end user. I downloaded PythonCAD and am still searching for the libraries GLIB GTK PYGTK and what not. Then there are dependancies issues of these libs on LINUX. I am scratching my head on how I would get the PythonCAD running. Is it that no compiling facility is hindering the growth of python in commercial circuit . . . ? -- http://mail.python.org/mailman/listinfo/python-list
Re: Python25.zip
Colin J. Williams wrote: > As part of the Python initialization, C:\Windows\System32\Python25.zip > is set up in the path. > > I haven't seen any documentation on the use or purpose of the zip file. http://docs.python.org/lib/module-zipimport.html http://www.python.org/peps/pep-0273.html -- http://mail.python.org/mailman/listinfo/python-list
Re: Python spam?
"Aahz" <[EMAIL PROTECTED]> wrote: > Anyone else getting "Python-related" spam? So far, I've seen messages > "from" Barry Warsaw and Skip Montanaro (although of course header > analysis proves they didn't send it). > -- not like that - just the normal crud from people giving me get rich quick tips on the stock market that is aimed at mobilising my money to follow theirs to help influence the price of a share... - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
"Ron Garret" <[EMAIL PROTECTED]> wrote: > > One of the things I find annoying about Python is that when you make a > change to a method definition that change is not reflected in existing > instances of a class (because you're really defining a new class when > you reload a class definition, not actually redefining it). So I came > up with this programming style: I would have thought that not changing yesterday was the very essence of dynamism (dynamicness ??) - but that when you change something - it applies from that point in time forwards... What do you propose to do about the outputs from such classes that have already happened? confused - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Worship
"Thomas Ploch" <[EMAIL PROTECTED]> wrote: > Nick schrieb: > > http://www.sciencedaily.com/releases/2006/11/061130081347.htm > > > > World's Oldest Ritual Discovered -- Worshipped The Python 70,000 Years > > Ago > > > > Nick > > > > That's really interesting since there is an indio tribe in the amazonas > jungle which also worships python. > > That just tells me Python is right. Whatever angle you look at it. > > :-D > > Thomas Not too sure about this - in fact I find it worrying that there can be 70 000 years of continuous Python worship and not a wheel to be seen. There may be a message on the sinister side here... ;-) - Hendrik -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Soup Question: Filtering Images based on their width and height attributes
Chris Mellon wrote: >> I want to extract some image links from different html pages, in >> particular i want extract those image tags which height values are >> greater than 200. Is there an elegant way in BeautifulSoup to do this? > > Most image tags "in the wild" don't have height attributes, you have > to download the image to see what size it is. or at least a small portion of it; see the example at the bottom of this page for one way to get the size without downloading more than 1k or so: http://effbot.org/zone/pil-image-size.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: Pimping the 'cgi' module (was: Re: python gaining popularity according to a study)
Christoph Haas <[EMAIL PROTECTED]> writes: > On Thursday 23 November 2006 21:29, robert wrote: > > When a LAMP programmer comes to Python, there are so many different > > confusing things. It starts with a 'non-documented' cgi module - a > > 'High-Level-Interface', that cannot even iterate over the form items. A > > name ZOPE in focus which reveals to be a monster system with 2-year > > learning-curve, ready for running an article editorial system for TOP-10 > > newspaper companies, but unable to make simple things simple. A handful > > of different Djangos - choose one for each weekday and programmer ... > > And Ruby made it with this single-known simple URL-to-method-router (And > > possibly when coming from PHP & Perl one recognizes ::@$_$%§§%/&... and > > the old namespace dirt) If there would have been a good cgi-system and a > > somewhat comfortable advanced URL-to-OO-router (beyond the socket > > wrapper HTTPServer) well exposed in the Python standard lib, the numbers > > would be probably very different today ... > > I can fully second that. Coming from Perl and being used to the CGI module > that is de-facto standard and already doing things much better than > Python's equivalent my first thought was: "Does Python really expect me to > re-invent the wheel to write basic CGIs?" So I started creating > cookie-based session handlers, form field handling etc. > > The reason of my posting it not only to complain though. My Python skills > are average but I would really like to help contribute some code on this > topic. I don't know Ruby-on-Rails myself but I have worked with CGIs for > ten years both in C (yuk) and Perl (Perl=semi-yuk / Perl-CGI=yum) and > think I know what people coming from Perl expect. And I'm not speaking of > Zope or Django or huge frameworks. I try to avoid frameworks wherever I > can (I want to write Python - not Zope or Django). I rather rely on the > standard library unless it's really saving me time and worth learning > another language. Are frameworks perhaps even telling that the standard > library is still lacking in some way? > > I'm thinking of features like: > - cookie handling > - cookie-session handling (similar to PHP or Perl's CGI::Session; combined > with database backends or simple text files) > - handling of form fields (Perl's CGI class can easily redisplay what > has been entered in the fields when they got submitted through a ) > - accessing parameters (honestly I haven't yet understood why I need to use > .value on FielStorage dictionaries - why isn't it just a plain > dictionary?) > - state keeping (storing the contents of all form fields on disk > to retrieve it later) > - creating form elements easily (option lists for example from > dictionaries and lists like in Perl) > - creating standard HTML elements (or do you remember how DOCTYPE > looks without looking it up?) > - handling of file uploads (which is just a recipe on ActivePython > at the moment) > - controlling HTTP headers (expires, redirections, charset) > - convenience functions e.g. for getting the client IP address without > needing to read ENV['REMOTE_ADDR'] > > Well, of course there are modules like 'cgi' or 'cookielib' and others may > argue that everything is already there. And there is a 'Web.py' already (I > assume every CGI programmer has written their own Web.py already). But > can't we come closer to what other scripting languages provide? Something > common? Can't a simple form-based CGI just be a matter of a dozen lines? > When it comes to CGIs Python loses its elegance for no reason. > > I'm ready to invest work and ideas if anyone else is interested. Perhaps > some day it makes it into the standard library or at least gives us > something between the features of the standard library and huge framework > monsters - something people can be pointed at when starting with Python > and CGIs. I'll probably do that anyway because my web projects all use > their own reinvented wheel and I'm losing the overview. And even Perl has > come that route - it started with a cgi-lib.pl which later became > the 'CGI' standard module. > > Is it just a matter of lacking resources or interest? Even if there is no > interest I'll probably read "man CGI" and "man CGI::Session" again and > start implementing something nifty for ex-perlies like myself. Hmmm, > batteries included even for CGI programmers, a man can dream. :) > > Cheers > Christoph When I came from Perl, I too missed perl-isms and specifically CGI.pm, so wrote my own: http://www.seanet.com/~hgg9140/comp/index.html http://www.seanet.com/~hgg9140/comp/pyperlish/doc/manual.html http://www.seanet.com/~hgg9140/comp/cgipm/doc/index.html Others on this newsgroup said I'd be better off just doing it in raw python. After a while, I realized that was true. You do triple-quoted templates with normal python idioms. Throw in some persistence mechanisms to deal with maintaining state across trans
Re: UTF8 & HTMLParser
Jan Danielsson wrote: >However, I would like to convert the "text" (which is utf8) > to latin-1. How do I do that? How about: latin = unicode(text, 'utf-8').encode('iso-8859-1') Please see help(u''.encode) for details about error handling. You might also want to trap errors in a try-except statement. Cheers, -- Klaus Alexander Seistrup http://klaus.seistrup.dk/ -- http://mail.python.org/mailman/listinfo/python-list
Re: UTF8 & HTMLParser
Jan Danielsson wrote: > Hello all, > >I'm writing a python script which fetches a HTML-page (using wget), > and then parses the retrieved page using a custom htmllib HTMLParser. > >The page I fetch is encoded in utf8, and my text-handler currently > looks like this: > >def handle_data(self, text): > if self.inOption: > self.currentName = text > >However, I would like to convert the "text" (which is utf8) to > latin-1. How do I do that? I've been trying to figure it out for some > time now, and I'm just getting frustrated. :-( I should have mentioned: The problem appears to be that I can't seem to find a way to make python understand that "text" (the above argument) is in fact already utf-8. -- Kind Regards, Jan Danielsson Te audire non possum. Musa sapientum fixa est in aure. -- http://mail.python.org/mailman/listinfo/python-list
UTF8 & HTMLParser
Hello all, I'm writing a python script which fetches a HTML-page (using wget), and then parses the retrieved page using a custom htmllib HTMLParser. The page I fetch is encoded in utf8, and my text-handler currently looks like this: def handle_data(self, text): if self.inOption: self.currentName = text However, I would like to convert the "text" (which is utf8) to latin-1. How do I do that? I've been trying to figure it out for some time now, and I'm just getting frustrated. :-( -- Kind Regards, Jan Danielsson Te audire non possum. Musa sapientum fixa est in aure. -- http://mail.python.org/mailman/listinfo/python-list
Re: v2.3, 2.4, and 2.5's GUI is slow for me
It's not slow for me. It's not like Python's inherently slow. Try turning off your virus scanner (temporarily and while not doing anything dangerous, of course). Cheers, -T g4rlik wrote: > No one can help? This is seriously bugging me to no end. > > g4rlik wrote: > > > > I've been asking all over the place, namely different forums. I even > > e-mailed [EMAIL PROTECTED] about my problem, but they couldn't assist me too > > much. > > > > My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run very > > sluggishly. When I type in them or move them around my desktop, it's very > > slow. I have figured out that this is because of the subprocesses > > running. > > > > To cope with this problem, I created an idle.txt file, and added this to > > the first line of it: > > > > c:\python25\python c:\python25\Lib\idlelib\idle.py -n > > > > After that I saved the extension to .bat and now when I run that file, the > > Python GUI opens without any subprocesses running and I have no problem. > > However, I'd still really like to know how I could fix this problem even > > more. I honestly don't understand why the GUI is so sluggish for me. The > > GUIs for Python version 2.2 and below run fine for me. My system specs > > are as follows: > > > > Windows XP Home Edition > > AMD Athlon XP 2800 > > nVidia 6800GT > > 1 gig of RAM > > > > If anyone else could help, that would be great. > > > > > > ***EDIT*** > > > > When starting up Python's v2.5 GUI, I noticed this message. > > > > "Personal firewall software may warn about the connection IDLE > > makes to its subprocess using this computer's internal loopback > > interface. This connection is not visible on any external > > interface and no data is sent to or received from the Internet." > > > > Maybe a firewall is interfering somehow? I'm behind a hardware firewall > > with my Linksys router. > > > > -- > View this message in context: > http://www.nabble.com/v2.3%2C-2.4%2C-and-2.5%27s-GUI-is-slow-for-me-tf2735011.html#a7631564 > Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
"Carl Banks" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > A straightforward, Pythonic way to do it would be to create an > intermediate representation that understands both the existing class > interfaces and the RDB stuff, but that could lead to synchronizing > problems and a big hit in performance. And it's probably a lot of work > compared to tacking on methods. OTOH, it could help with hairiness you > mention. (I recently did something similar in one of my projects, > though the intermediary was transient.) > I would second Carl's recommendation that you find some way to persist an interim version of these expensive-to-create objects, so you can quickly load debuggable instances to accelerate your development process. With luck, you can get by with out-of-the-box marshal/unmarshal using the pickle module. We've done this several times in my office with objects that an application creates only after some extensive GUI interaction - it just slows down development too much without some quick import of debuggable instances. Even though this seems like a sidetrack, it's a pretty direct shortcut, without too much unusual technology or design work. -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Why are slice indices the way they are in python?
On Thu, 2006-11-30 at 08:58 -0800, [EMAIL PROTECTED] wrote: > And if talking about dates, then I suggest NEVER use 2006-12-31 > 23:59:59 in data, always 2007-01-01 00:00:00 instead. Forgive me for my ignorance, but isn't "2006-12-31 23:59:59" actually one entire second earlier than "2007-01-01 00:00:00"? Hence they are two different dates are they not? Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Open and closing files
John Machin wrote: > Thomas Ploch wrote: > > Is it defined behaviour that all files get implicitly closed when not > > assigning them? > > > > Like: > > > > def writeFile(fName, foo): > > open(fName, 'w').write(process(foo)) > > > > compared to: > > > > > > def writeFile(fName, foo): > > fileobj = open(fName, 'w') > > fileobj.write(process(foo)) > > fileobj.close() > > > > Which one is the 'official' recommended way? > > No such thing as an 'official' way. > > Nothing happens until the file object is garbage-collected. GC is > generally not under your control. > > Common sense suggests that > (a) when you are reading multiple files, you close each one explicitly > (b) when you are writing a file, you close it explicitly as soon as you > are done with it. That way you can trap any error condition and do > something moderately sensible -- better than getting an error condition > during GC when your Python process is shutting down. > > HTH, > John Not to mention you can get bitten on the ass by a few characters sitting in a buffer someplace when you expect your file to have been fully written. Close the thing. Cheers, -T -- http://mail.python.org/mailman/listinfo/python-list
Re: Open and closing files
Thomas Ploch wrote: > Is it defined behaviour that all files get implicitly closed when not > assigning them? > > Like: > > def writeFile(fName, foo): > open(fName, 'w').write(process(foo)) > > compared to: > > > def writeFile(fName, foo): > fileobj = open(fName, 'w') > fileobj.write(process(foo)) > fileobj.close() > > Which one is the 'official' recommended way? No such thing as an 'official' way. Nothing happens until the file object is garbage-collected. GC is generally not under your control. Common sense suggests that (a) when you are reading multiple files, you close each one explicitly (b) when you are writing a file, you close it explicitly as soon as you are done with it. That way you can trap any error condition and do something moderately sensible -- better than getting an error condition during GC when your Python process is shutting down. HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Open 16-bit/24-bit windows bitmap using PIL
Hi there, I'm trying to open a 256-colour windows BMP and a 24-bit windows BMP with PIL usiing the following command: Image.open("image.bmp") When I try and open the 24-bit BMP the error I get is: Traceback (most recent call last): File "", line 1, in im = Image.open("lightbulb.bmp") File "C:\Python25\lib\site-packages\PIL\Image.py", line 1730, in open return factory(fp, filename) File "C:\Python25\lib\site-packages\PIL\ImageFile.py", line 82, in __init__ self._open() File "C:\Python25\lib\site-packages\PIL\BmpImagePlugin.py", line 164, in _open self._bitmap(offset=offset) File "C:\Python25\lib\site-packages\PIL\BmpImagePlugin.py", line 96, in _bitmap raise IOError("Unsupported BMP header type (%d)" % len(s)) IOError: Unsupported BMP header type (108) When I try and open the 256-colour BMP the error I get is: Traceback (most recent call last): File "", line 1, in im = Image.open("lightbulb2.bmp") File "C:\Python25\lib\site-packages\PIL\Image.py", line 1730, in open return factory(fp, filename) File "C:\Python25\lib\site-packages\PIL\ImageFile.py", line 82, in __init__ self._open() File "C:\Python25\lib\site-packages\PIL\BmpImagePlugin.py", line 164, in _open self._bitmap(offset=offset) File "C:\Python25\lib\site-packages\PIL\BmpImagePlugin.py", line 120, in _bitmap raise IOError("Unsupported BMP compression (%d)" % compression) IOError: Unsupported BMP compression (1) I can open a windows monochrome bitmap fine using PIL but the colour options are more desirable. I am using Windows 2000 if that is any help and I am saving the different BMP's using Microsoft Paint. If you could help that would be great. Craig -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
Ron Garret wrote: > In article <[EMAIL PROTECTED]>, > "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > > > Ron Garret schrieb: > > > One of the things I find annoying about Python is that when you make a > > > change to a method definition that change is not reflected in existing > > > instances of a class (because you're really defining a new class when > > > you reload a class definition, not actually redefining it). So I came > > > up with this programming style: > > > > > > def defmethod(cls): > > > return lambda (func): type.__setattr__(cls, func.func_name, func) > > > > > > class c1(object): pass > > > > > > @defmethod(c1) > > > def m1(self, x): ... > > > > > > > > > Now if you redefine m1, existing instances of c1 will see the change. > > > > > > My question is: is there a reason not to do this? Does it screw > > > something up behind the scenes? Is it unpythonic? Why isn't this > > > standard operating procedure? 1. Do you mean, is there an "it'll crash the interpreter" reason? No. 2. Not for most ordinary cases. There are a few gotchas (for example, use of __private variables), but they're minor. 3. Yes. 4. Because it's unPythonic. But don't worry too much if you do something unPythonic occasionally. Python says there's should be one--and preferably only one--obvious way to do it. So if there's no obvious way to do it, you probably have to do something unPythonic. (Or consult someone with more experience. :) [snip] > I have two motivations. > > First, I'm dealing with some classes whose instances take a long time to > construct, which makes for a long debug cycle if I have to reconstruct > them after every code change. > > Second, the design just naturally seems to break down that way. I have > a library that adds functionality (persistence) to a set of existing > classes. The persistence code stores the objects in a relational DB, so > it's pretty hairy code, and it has nothing to do with the functionality > that the classes actually provide. The original classes are useful even > with the persistence code, and I'm trying to keep things lightweight. Seems like a reasonable use case to me. > If there's a better way to accomplish all this I'm all ears. A straightforward, Pythonic way to do it would be to create an intermediate representation that understands both the existing class interfaces and the RDB stuff, but that could lead to synchronizing problems and a big hit in performance. And it's probably a lot of work compared to tacking on methods. OTOH, it could help with hairiness you mention. (I recently did something similar in one of my projects, though the intermediary was transient.) You might be able to create a set of augmented subclasses to use instead. The main problem with this is that base classes often don't know about the augmented versions. You'd have to override code that requires an ordinary object with code that allows an augmented object. This is sometimes very inconvenient (like when the code requiring an ordinary object is one line smack in the middle of a 100-line function). It actually sounds like Aspect Oriented Programming might be helpful here (if you care to learn another wholly different programming paradigm, that is). You have a concern (persistence) that's pretty much off in another dimension from the purpose of the classes. Or maybe the best way is just to teach an old class new tricks. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Weekly Python Patch/Bug Summary
Patch / Bug Summary ___ Patches : 407 open ( +1) / 3484 closed ( +5) / 3891 total ( +6) Bugs: 936 open ( +5) / 6363 closed (+14) / 7299 total (+19) RFE : 246 open ( +1) / 244 closed ( +0) / 490 total ( +1) New / Reopened Patches __ sys.id() and sys.intern() (2006-11-23) http://python.org/sf/1601678 opened by Georg Brandl clarify comparison return values (2006-11-24) http://python.org/sf/1602128 opened by Jim Jewett non-framework built python fails to define environ properly (2006-11-23) http://python.org/sf/1602133 opened by paul Suggest a textlist() method for ElementTree (2006-11-24) http://python.org/sf/1602189 opened by Raymond Hettinger subprocess: error redirecting i/o from non-console process (2006-11-27) http://python.org/sf/1603907 opened by Oren Tirosh Performance boost for array repeat (2006-11-28) CLOSED http://python.org/sf/1605020 opened by Mike Klaas Make Imap Error more helpful (2006-11-29) http://python.org/sf/1605192 opened by Thomas Guettler vendor-packages directory. (2005-09-22) http://python.org/sf/1298835 reopened by loewis Patches Closed __ __bool__ instead of __nonzero__ (2006-11-21) http://python.org/sf/1600346 closed by jackdied SRE engine do not release the GIL (2005-11-25) http://python.org/sf/1366311 closed by eric_noyau Implement lazy read for sockets (2003-12-04) http://python.org/sf/853963 closed by loewis Disable POSIX for certain/older NetBSD versions (2003-12-05) http://python.org/sf/854796 closed by loewis Performance boost for array repeat (2006-11-28) http://python.org/sf/1605020 closed by mklaas New / Reopened Bugs ___ using python extension(wxPython) in c (2006-11-23) CLOSED http://python.org/sf/1601607 opened by jolleydtan getopt Documentation improvement (2006-11-23) CLOSED http://python.org/sf/1601630 opened by Thomas Guettler Incorrect docs for bisect_left (2006-11-24) http://python.org/sf/1602378 opened by Daniel Eloff itemconfigure returns incorrect text property of text items (2006-11-25) http://python.org/sf/1602742 opened by Wojciech Mula wave module forgets to close file on exception (2006-11-26) http://python.org/sf/1603150 opened by amerinese wave module forgets to close file on exception (2006-11-26) CLOSED http://python.org/sf/1603246 opened by amerinese pstats module (profiler) doens't support unicode paths (2006-11-26) CLOSED http://python.org/sf/1603321 opened by Adal Chiriliuc def foo(((x))) segfault (2006-11-26) CLOSED http://python.org/sf/1603332 opened by Tony Lownds f=open fails with TypeError (2006-11-26) CLOSED http://python.org/sf/1603336 opened by Gibholio f=open fails with TypeError (2006-11-26) CLOSED http://python.org/sf/1603412 opened by Gibholio subprocess.py (py2.5) wrongly claims py2.2 compatibility (2006-11-27) http://python.org/sf/1603424 opened by Tim Wegener Python socket library confused by IPV6 notation in /etc/host (2006-11-27) http://python.org/sf/1603527 opened by Eric S. Raymond SaveConfigParser.write() doesn't quote %-Sign (2006-11-27) http://python.org/sf/1603688 opened by Rebecca Breu grammatical error in Python Library Reference::Tkinter (2006-11-27) CLOSED http://python.org/sf/1603789 opened by Gabriel M. Elder subprocess.Popen closes fds for sys.stdout or sys.stderr (2006-11-28) http://python.org/sf/1604851 opened by Nishkar Grover _CRT_SECURE_NO_DEPRECATE macro redefinition with VC++ 8 (2006-11-28) CLOSED http://python.org/sf/1604862 opened by William Fulton logging %(module)s reporting wrong modules (2006-11-29) http://python.org/sf/1605110 opened by Mad-Marty csv module broken for unicode (2006-11-30) http://python.org/sf/1606092 opened by JettLogic readline on popen3 file returns empty string before end (2006-11-30) http://python.org/sf/1606233 opened by Bill Wallace Bugs Closed ___ utf_8_sig decode fails with buffer input (2006-11-23) http://python.org/sf/1601501 closed by doerwalter using python extension(wxPython) in c (2006-11-23) http://python.org/sf/1601607 closed by loewis getopt Documentation improvement (2006-11-23) http://python.org/sf/1601630 closed by gbrandl ctypes Structure allows recursive definition (2006-11-17) http://python.org/sf/1598620 closed by theller 2.4 & 2.5 can't create win installer on linux (2006-10-04) http://python.org/sf/1570417 closed by loewis wave module forgets to close file on exception (2006-11-26) http://python.org/sf/1603246 closed by gbrandl pstats module (profiler) doens't support unicode paths (2006-11-26) http://python.org/sf/1603321 closed by gbrandl def foo(((x))) segfault (2006-11-26) http://python.org/sf/1603
*** A BRIEF summary of criminal methods used by FBI Mother Fuckers ***
http://www.monitor.net/monitor/9905a/jbcointelpro.html just search google for cointelpro A Short History of FBI COINTELPRO by Mike Cassidy and Will Miller The FBI and police used secret and systematic methods of fraud and force [Editor's note: More information on COINTELPRO in the Bari case is available at the Monitor Judi Bari index. Much of the following was taken from Brian Glick's book War At Home: Covert Action Against U.S. Activists and What We Can Do About It, (South End Press; Boston, 1989), a source for detailed and documented information on the history of domestic covert action against movements for social change.] In early 1971, the FBI's domestic counterintelligence program (code named "COINTELPRO") was brought to light when a "Citizens Committee to Investigate the FBI" removed secret files from an FBI office in Media, PA and released them to the press. Agents began to resign from the Bureau and blow the whistle on covert operations. That same year, publication of the Pentagon Papers, the Pentagon's top-secret history of the Vietnam War, exposed years of systematic official lies about the war. Soon after, it was discovered that a clandestine squad of White House "plumbers" broke into Daniel Ellsberg's psychiatrist's office in an effort to smear the former Pentagon staffer who leaked the top-secret papers to the press. The same "plumbers" were later caught burglarizing the Watergate offices of the Democratic National Committee. By the mid-1970's Senate and House committees launched formal and lengthy inquiries into government intelligence and covert activities. These investigations revealed extensive covert and illegal counterintelligence programs involving the FBI, CIA, U.S. Army intelligence, the White House, the Attorney General, and even local and state law enforcement, directed against opponents of government domestic and foreign policy. Since then, many more instances of these "dirty tricks" have been revealed. When congressional investigations, political trials and other traditional legal methods of repression failed to counter the growing movements of the 1950s, '60s and '70s, and even helped fuel them, the FBI and police moved outside the law. They used secret and systematic methods of fraud and force, far beyond mere surveillance, to sabotage constitutionally protected political activity. The purpose of the program was, in FBI Director J. Edgar Hoover's own words, to "expose, disrupt, misdirect, discredit and otherwise neutralize" specific groups and individuals. Its targets in this period included the American Indian Movement, the Communist Party, the Socialist Worker's Party, Black Nationalist groups, and many members of the New Left (SDS, and a broad range of anti-war, anti-racist, feminist, lesbian and gay, environmentalist and other groups). Many other groups and individuals seeking racial, gender and class justice were targets who came under attack, including Martin Luther King, Cesar Chavez, the NAACP, the National Lawyer's Guild, SANE-Freeze, American Friends Service Committee, and many, many others. The Reagan Administration reinvigorated covert action The public exposure of COINTELPRO and other government abuses resulted in a flurry of apparent reform in the 1970s, but domestic covert action did not end. It has persisted, and seems a permanent feature of our government. Much of today's domestic covert action can also be kept concealed because of government secrecy that has been restored. The Freedom of Information Act (FOIA), a source of major disclosures of COINTELPRO and other such activities, was drastically narrowed in the 1980s through administrative and judicial reinterpretation, as well as legislative amendment. While restoring such secrecy, the Reagan Administration also reinvigorated covert action, embracing its use at home and abroad. They endorsed it, sponsored it, and even legalized it to a great extent. Much of what was done outside the law under COINTELPRO was later legalized by Executive Order 12333 (12/4/81). There is every reason to believe that even what was not legalized is still going on as well. Lest we forget, Lt. Col. Oliver North funded and orchestrated from the White House basement break-ins and other "dirty tricks" to defeat congressional critics of U.S. policy in Central America and to neutralize grassroots protest. Special Prosecutor Walsh found evidence that North and Richard Secord (architect of the 1960s covert actions in Cambodia) used Iran-Contra funds to harass the Christic Institute, a church-funded public interest group specializing in exposing government misconduct. North also helped other administration officials at the Federal Emergency Management Administration develop contingency plans for suspending the Constitution, establishing martial law, and holding political dissidents in concentration camps in the event of "national opposition against a U.S. military invasion abroad." There were repo
Re: PythonTidy
Thomas Heller wrote this on Thu, Nov 30, 2006 at 09:50:25PM +0100. My reply is below. > The two things that bother me at the moment are how the comments are > formatted (dunno if that can be customized or changed easily), and > it would be good if the script took command line args instead of > working as a filter only. Thank you for trying PythonTidy. o Command-line args: Please give an example of a standard command that I might emulate w.r.t. standard argument use. o Comments: Input is parsed twice: I use *tokenize.generate_tokens* to extract the comments and *compiler.parse* to generate the Abstract Syntax Tree (AST). Other applications usually use the AST to generate bytecode, so it contains no information about comments. The tokens list identifies keywords (and comments and some whitespace) but doesn't group them into statements. I need both: comments *and* functional grouping. Fortunately both the AST and the tokens list carry line numbers to reference the source. Unfortunately the AST line numbers are relative to functional groups and do not necessarily apply to the particular keywords that introduce each group. This makes fixing the position of comments relative to reconstructed code a bit of a challenge. For example, when a comment has a line number in the beginning/ending range of what would normally be considered one command, I have to assume it is an inline comment regardless of how it may have appeared in the original code. Out-of-line comments should appear pretty much as they did in the original code, however. Can you provide an example where they do not? Would you prefer that they be left justified or wrapped? >-~ Doc strings (for modules, class declarations, and functions) are another matter. PythonTidy should not mess with them (unless LEFTJUST_DOC_STRINGS is True). They should appear exactly as originally written. I was taught that code ought to be self documenting and that comments more often than not diminish readability by padding the code beyond what can be comprehended on one page (screen). I use them only minimally and am not greatly inconvenienced when they are moved around a little. -- .. Chuck Rhode, Sheboygan, WI, USA .. Weather: http://LacusVeris.com/WX .. 21° — Wind N 8 mph -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
Noah Rawlins wrote: > > >>> strList = [] > >>> strList.append('this is an example of a thing i would like to have') > >>> strList.append('another example of something else i would like to > have') > >>> strList.append('and this is another " example " but of something ; > now i would still like to have') > >>> [word for word in strList[0].split() if word in reduce(lambda x, y: > x.intersection(y), [set(str.split()) for str in strList])] > ['example', 'of', 'i', 'would', 'like', 'to', 'have'] > I think that ends up doing the set reduction over and over for every word in the first string, so you probably want to move that outside the list comprehension noah -- http://mail.python.org/mailman/listinfo/python-list
Trying to send keystrokes to NES emulator
Hi, I am trying to send keystrokes to the NES emulator nester[1]. The idea was to be able to use a standard NES controller whose "state" I can read in using Python and then conveying that to the emulator. Unfortunately, all the attempts I have made so far have failed. It looks like the emulator is using some extremely low-level function to read keystrokes and I cannot get in before it. So far, I have tried the following functions from Python's win32api and using ctypes: 1. SendInput http://mail.python.org/pipermail/python-win32/2005-April/003131.html 2. keybd_event win32api.keybd_event(90, 0, 0, 0) This should have sent the 'z' key to the emulator which in Contra makes the little guy shoot. However, the emulator just sits there. 3. SendKeys import win32api import win32com.client shell = win32com.client.Dispatch("WScript.Shell") shell.AppActivate("nester") shell.SendKeys('s') My suspicion is that nester is using something lower-level than where these functions change stuff. I read about GetAsyncKeyState. However, I couldn't figure out for the life of me how to force the return value of the GetAsyncKeyState function. I would really appreciate any help in this regard :) Thanks! Srinath (speaking only on behalf of myself) PS: Does anyone know of a good way to play old NES games on the PC using the classic NES controllers? [1] http://nester.dranalli.com/ -- http://mail.python.org/mailman/listinfo/python-list
Open and closing files
Is it defined behaviour that all files get implicitly closed when not assigning them? Like: def writeFile(fName, foo): open(fName, 'w').write(process(foo)) compared to: def writeFile(fName, foo): fileobj = open(fName, 'w') fileobj.write(process(foo)) fileobj.close() Which one is the 'official' recommended way? Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
Robert R. wrote: > Hello, > > i would like to write a piece of code to help me to align some sequence > of words and suggest me the ordered common subwords of them > > s0 = "this is an example of a thing i would like to have".split() > s1 = "another example of something else i would like to have".split() > s2 = 'and this is another " example " but of something ; now i would > still like to have'.split() > ... > alist = (s0, s1, s2) > > result should be : ('example', 'of', 'i', 'would', 'like', 'to', 'have' > > but i do not know how should i start, may be have you a helpful > suggestion? > a trouble i have if when having many different strings my results tend > to be nothing while i still would like to have one of the, or maybe, > all the best matches. > > best. > Your requirements are a little vague... how are these three strings handled? s1 = "hello there dudes" s2 = "dudes hello there" s3 = "there dudes hello" they all share the 3 words, but what order do you want them back? here is a simplistic approach using sets that results in a list of words that are in all strings ordered arbitrarily by their order in the first string ( it also doesn't worry about matches (or lack of) due to punctuation and case and crap like that) >>> strList = [] >>> strList.append('this is an example of a thing i would like to have') >>> strList.append('another example of something else i would like to have') >>> strList.append('and this is another " example " but of something ; now i would still like to have') >>> [word for word in strList[0].split() if word in reduce(lambda x, y: x.intersection(y), [set(str.split()) for str in strList])] ['example', 'of', 'i', 'would', 'like', 'to', 'have'] but you still have issues with mutiple matches and how they are handled etc... noah -- http://mail.python.org/mailman/listinfo/python-list
Re: shtoom making PC2Phone calls
Forgot to include, Check out pyserial-2-2 at sourceforge.net/ by Chris Liechti On Thursday 30 November 2006 21:07, jim-on-linux wrote: > On Thursday 30 November 2006 12:35, Croteam wrote: > > Hello, > > > > Can somebody give me shtoom examples or > > source code for making PC2Phone calls and pc > > to pc calls. (if you give me source > > code,please give me full url to that source > > or send me to email: [EMAIL PROTECTED]) > > > >Thanks,I will > > really appreciate that > > Try, > http://pyserial.sourceforge.net/ > > Many examples. I've used some of the examples > to connect pc to pc. And with phone attached, > you can to talk with someone on the other end. > > Search using serial port. > > > jim-on-linux > http://www.inqvista.com -- http://mail.python.org/mailman/listinfo/python-list
Re: shtoom making PC2Phone calls
On Thursday 30 November 2006 12:35, Croteam wrote: > Hello, > > Can somebody give me shtoom examples or source > code for making PC2Phone calls and pc to pc > calls. (if you give me source code,please give > me full url to that source or send me to email: >[EMAIL PROTECTED]) > >Thanks,I will really > appreciate that Try, http://pyserial.sourceforge.net/ Many examples. I've used some of the examples to connect pc to pc. And with phone attached, you can to talk with someone on the other end. Search using serial port. jim-on-linux http://www.inqvista.com -- http://mail.python.org/mailman/listinfo/python-list
Re: urllib2 spinning CPU on read
"kdotsky" <[EMAIL PROTECTED]> writes: > > I didn't try looking at your example, but I think it's likely a bug > > both in that site's HTTP server and in httplib. If it's the same one > > I saw, it's already reported, but nobody fixed it yet. > > > > http://python.org/sf/1411097 > > > > > > John > > Thanks. I tried the example in the link you gave, and it appears to be > the same behavior. > > Do you have any suggestions on how I could avoid this in the meantime? Yes: read the recent messages on the tracker I linked to, and apply the fix I suggest there. John -- http://mail.python.org/mailman/listinfo/python-list
Python/Flash integration
Hello, I've been able to use makepy to create a wrapper around flash8.ocx and I have a wx app that serves as a container. I can get this simple case to run a flash swf, and I can also receive fscommands from the flash movie to the container. However, I've seen commercial flash containers that provide new Actionscript functions (not fscommands) that can be called from the flash movie to do something at the os level. How can I do this? Any insights would be appreciated! Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL throws exception when reading bitmap/pnm data
Cameron Walsh wrote: > Hi all, > > I'm trying to extract the data from a bitmap or .pnm file using the > following code: > > import Image > img = Image.open("test.bmp","r") > data=img.getdata() > > Unfortunately I get the following exception on Linux, but not on Windows: > data=img.getdata() > Traceback (most recent call last): > File "", line 1, in > File "/usr/local/lib/python2.5/site-packages/PIL/Image.py", line 796, > in getdata > self.load() > File "/usr/local/lib/python2.5/site-packages/PIL/ImageFile.py", line > 147, in load > self.map = mmap.mmap(file.fileno(), size) > EnvironmentError: [Errno 19] No such device > > > > Thanks and regards, > > Cameron. Hi all, It turns out the problem only arose when the file was on an NTFS drive mounted as NTFS-3g. Copying it to my home directory fixed the problem. Who do I send the bug report to, the ntfs-3g or the PIL guys? Regards, Cameron. -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatters with variable argument length
Fredrik Tolf wrote: > On Thu, 2006-11-30 at 16:26 -0800, John Machin wrote: > > Fredrik Tolf wrote: > [...] > > > The thing is, I want to get format strings from the user, and I don't > > > want to require the user to consume all the arguments. docs.python.org > > > doesn't seem to have any clues on how to achieve this, and I can't think > > > of what to google for. > > > > Three approaches spring to mind. In descending order of my preference: > > > > (a) don't do that > > It would be a possibility, since all current uses actually do have the > right number of parameters. I would just like to keep the option > available. > > > (b) parse the format string, counting the number of args required. If > > the user has supplied more, throw them away. > > I was thinking of that, but it just seems far too ugly. what's ugly about this: [untested]: def count_format_args(s): pending = False count = 0 for c in s: if c == "%": # doubled % chars aren't counted pending = not pending elif pending: count += 1 pending = False return count output = format % arglist[:count_format_args(format)] > > > (c) wrap your execution of format_string % args in a try/except > > bracket. If you get a TypeError with that message [not guaranteed to > > remain constant in the future], throw away the last arg and go around > > again. > > That might be a good possibility. Thanks for the idea! I do consider it > quite a bit ugly, but that often happens when languages try to police > programmers... :P > > > As a matter of curiosity, why don't you want the user to consume all > > the arguments? Don't they get even a teensy-weensy warning message? Are > > you writing a Perl interpreter in Python? > > Well basically, I'm rewriting a autodownloader for a file-sharing > network in Python (previously written as a bash script, using the printf > command), and I have a number of files scattered over my hard drive > specifying search expressions, into which a potentially optional episode > number can be inserted using sprintf-like arguments (using > fsexpr="`printf "$sexpr" "$curep"`" in bash). I would like to keep it as > a printf parameter, in order to be able to write e.g. %02i, and I would > like to keep it optional, for downloading non-episoded stuff. > > I couldn't help noticing that the named variant of the % operator (using > a dict, that is) doesn't require all its arguments to be consumed. Using > that would require me to rewrite *all* the existing files, though. So offer the named variant as an option for new users or new uses by old users. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatters with variable argument length
> Could it be as I fear, that it is impossible? p'shaw, you underestimate the power of the Python... I think this is a poor solution (I would go with the solution in John Machin's second post) but here it is anyway since it does essentially what you asked for: [code] def print_data(fmtstr): data = (10,11,12,13) for i in xrange(len(data)): try: print fmtstr %data[:i+1] break except: pass [/code] -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
In article <[EMAIL PROTECTED]>, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > Ron Garret schrieb: > > One of the things I find annoying about Python is that when you make a > > change to a method definition that change is not reflected in existing > > instances of a class (because you're really defining a new class when > > you reload a class definition, not actually redefining it). So I came > > up with this programming style: > > > > def defmethod(cls): > > return lambda (func): type.__setattr__(cls, func.func_name, func) > > > > class c1(object): pass > > > > @defmethod(c1) > > def m1(self, x): ... > > > > > > Now if you redefine m1, existing instances of c1 will see the change. > > > > My question is: is there a reason not to do this? Does it screw > > something up behind the scenes? Is it unpythonic? Why isn't this > > standard operating procedure? > > What are you doing that needs this permanent redefinition? I like the > repl, yet usually - especially when dealing with classes - I write a > text file containing code. So, i just run that on a command line again, > if I made some changes, recreating whatever objects I want again. > > Even if I'd not do that, but used a long-running interpreter inside an > IDE (which is what I presume you are doing) - why do you _care_ about > the old objects the first place? I mean, you obviously changed the > classes for a reason. So, you are not being productive here, but still > programming. Which means that you don't _have_ to care about old, > unchanged objects too much. > > But in the end - it's your code. It will run slower, it looks kinda > weird as someone who's reading it has to know what it is for, but if it > suits your needs - do it. > > Diez I have two motivations. First, I'm dealing with some classes whose instances take a long time to construct, which makes for a long debug cycle if I have to reconstruct them after every code change. Second, the design just naturally seems to break down that way. I have a library that adds functionality (persistence) to a set of existing classes. The persistence code stores the objects in a relational DB, so it's pretty hairy code, and it has nothing to do with the functionality that the classes actually provide. The original classes are useful even with the persistence code, and I'm trying to keep things lightweight. If there's a better way to accomplish all this I'm all ears. rg -- http://mail.python.org/mailman/listinfo/python-list
Re: v2.3, 2.4, and 2.5's GUI is slow for me
No one can help? This is seriously bugging me to no end. g4rlik wrote: > > I've been asking all over the place, namely different forums. I even > e-mailed [EMAIL PROTECTED] about my problem, but they couldn't assist me too > much. > > My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run very > sluggishly. When I type in them or move them around my desktop, it's very > slow. I have figured out that this is because of the subprocesses > running. > > To cope with this problem, I created an idle.txt file, and added this to > the first line of it: > > c:\python25\python c:\python25\Lib\idlelib\idle.py -n > > After that I saved the extension to .bat and now when I run that file, the > Python GUI opens without any subprocesses running and I have no problem. > However, I'd still really like to know how I could fix this problem even > more. I honestly don't understand why the GUI is so sluggish for me. The > GUIs for Python version 2.2 and below run fine for me. My system specs > are as follows: > > Windows XP Home Edition > AMD Athlon XP 2800 > nVidia 6800GT > 1 gig of RAM > > If anyone else could help, that would be great. > > > ***EDIT*** > > When starting up Python's v2.5 GUI, I noticed this message. > > "Personal firewall software may warn about the connection IDLE > makes to its subprocess using this computer's internal loopback > interface. This connection is not visible on any external > interface and no data is sent to or received from the Internet." > > Maybe a firewall is interfering somehow? I'm behind a hardware firewall > with my Linksys router. > -- View this message in context: http://www.nabble.com/v2.3%2C-2.4%2C-and-2.5%27s-GUI-is-slow-for-me-tf2735011.html#a7631564 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatters with variable argument length
On Thu, 2006-11-30 at 16:26 -0800, John Machin wrote: > Fredrik Tolf wrote: [...] > > The thing is, I want to get format strings from the user, and I don't > > want to require the user to consume all the arguments. docs.python.org > > doesn't seem to have any clues on how to achieve this, and I can't think > > of what to google for. > > Three approaches spring to mind. In descending order of my preference: > > (a) don't do that It would be a possibility, since all current uses actually do have the right number of parameters. I would just like to keep the option available. > (b) parse the format string, counting the number of args required. If > the user has supplied more, throw them away. I was thinking of that, but it just seems far too ugly. > (c) wrap your execution of format_string % args in a try/except > bracket. If you get a TypeError with that message [not guaranteed to > remain constant in the future], throw away the last arg and go around > again. That might be a good possibility. Thanks for the idea! I do consider it quite a bit ugly, but that often happens when languages try to police programmers... :P > As a matter of curiosity, why don't you want the user to consume all > the arguments? Don't they get even a teensy-weensy warning message? Are > you writing a Perl interpreter in Python? Well basically, I'm rewriting a autodownloader for a file-sharing network in Python (previously written as a bash script, using the printf command), and I have a number of files scattered over my hard drive specifying search expressions, into which a potentially optional episode number can be inserted using sprintf-like arguments (using fsexpr="`printf "$sexpr" "$curep"`" in bash). I would like to keep it as a printf parameter, in order to be able to write e.g. %02i, and I would like to keep it optional, for downloading non-episoded stuff. I couldn't help noticing that the named variant of the % operator (using a dict, that is) doesn't require all its arguments to be consumed. Using that would require me to rewrite *all* the existing files, though. Anyway, thanks! Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list
*** 911 WAS AN INSIDE JOB. YOU WILL GET ALL SCIENTIFIC EVIDENCE ON st911.org ***
911 WAS AN INSIDE JOB. YOU WILL GET ALL SCIENTIFIC EVIDENCE ON st911.org The written apology reads: "The United States of America apologizes to Mr. Brandon Mayfield and his family for the suffering caused by the FBI's misidentification of Mr. Mayfield's fingerprint and the resulting investigation of Mr. Mayfield, including his arrest as a material witness in connection with the 2004 Madrid train bombings and the execution of search warrants and other court orders in the Mayfield family home and in Mr. Mayfield's law office." He and his family later sued the U.S. government for damages. "We lived in 1984," Mayfield told reporters Wednesday. "I'm talking about the George Orwell, frightening brave new world in which Big Brother is constantly watching you." (Watch Mayfield discuss the case Video) "I, myself, have dark memories of stifling paranoia, of being monitored, followed, watched, tracked," he said, choking back emotion. "I've been surveilled, followed, targeted primarily because I've been an outspoken critic of this administration and doing my job to defend others who can't defend themselves, to give them their day in court, and mostly for being a Muslim." The government refused, he said, to tell him where they put their cameras and surveillance devices, leaving his family wondering if their private conversations and intimate moments were on display. "The days and weeks and months following my arrest were some of the hardest and darkest that myself and my family have ever had to endure," he said. "And all because of this government's ill-conceived war on terror. ... What I really want is for this not to happen to anyone else." Wednesday's settlement includes not only a $2 million payment and an apology, but also an agreement by the government to destroy communications intercepts conducted by the FBI against Mayfield's home and office during the investigation. The written apology reads: "The United States of America apologizes to Mr. Brandon Mayfield and his family for the suffering caused by the FBI's misidentification of Mr. Mayfield's fingerprint and the resulting investigation of Mr. Mayfield, including his arrest as a material witness in connection with the 2004 Madrid train bombings and the execution of search warrants and other court orders in the Mayfield family home and in Mr. Mayfield's law office." A Justice Department statement released Wednesday said Mayfield was not targeted because of his Muslim faith and that the FBI had taken steps to improve its fingerprint identification process "to ensure that what happened to Mr. Mayfield does not happen again." "Mr. Mayfield and his family felt it was in their best interest to get on with their lives," said Mayfield's attorney, Elden Rosenthal. "No amount of money can compensate Mr. Mayfield for being held as a prisoner and being told he faced the death penalty [for the Madrid bombings]." Mayfield said his suit was not about money. "It's about regaining our civil rights, our freedom and most important, our privacy," he said. He and his attorneys said the settlement will allow him to continue the portion of his lawsuit challenging the constitutionality of the Patriot Act. Mayfield contends that his home was searched under provisions of the Patriot Act. Criminal, Rogue and RACIST elements have penetrated all the branches of USA and world governments. We know that on 911 FBI bastards ran all over in the neighborhood of Pentagon trying to confiscate EVIDENCE of the 911 crime that no Boeing Passenger Airliner hit Pentagon. They have stil not released the evidence. 911 was inside job. FBI is the BEST of the criminal branches ... THERE ARE MORE EVIL AND BIGGER ROGUES IN CIA, NSA, Mossad, PENTAGON AND THE WHITE HOUSE. Dont forget that BASTARD, NIXON and JOHNSON who sank USS LIBERTY and KILLED AMERICANS with the help of ISRAEL ... FBI is the BEST of the criminal branches ... THERE ARE MORE EVIL AND BIGGER ROGUES IN CIA, NSA, PENTAGON AND THE WHITE HOUSE. Dont forget that BASTARD, NIXON and JOHNSON who sank USS LIBERTY and KILLED AMERICANS with the help of ISRAEL ... THE ONLY ONLY REASON FBI DID THIS IS BECAUSE THEIR CRIME WAS UNCONCEALABLE. UNDER THE PRETEXT OF SELF-DEFENSE, MANY OF THESE AGENCY OFFICIALS HAVE COVERED THEIR CRIMES AND DESTROYED EVIDENCE OF THEIR CRIMES. FBI COVERED UP A CHILD PEDOPHILIA RING THAT WAS LINED TO REAGAN AND HERBERT WALKER BUSH. There is a VIDEO on google of the investigation. === www.nkusa.org Name: www.nkusa.org Nickname: www.st911.org Location: WTC Building 7 Title: Pentagon Videos Industry: Non-Profit Email address: [EMAIL PROTECTED] Website or Blog: www.infowars.com www.prisonplanet.org www.counterpunch.org Quote: On 911, the only buildings that were demolished were the ones that belonged to Larry Silverstein. Building 7 Committed suicide even though no plane had hit it. Within minutes, FBI
Re: String formatters with variable argument length
John Machin wrote: > Fredrik Tolf wrote: > > I've been trying to get the string formatting operator (%) to work with > > more arguments than the format string requires, but I can find no way to > > do that. For example: > > > > >>> "%i" % 10 > > '10' > > >>> "i" % 10 > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: not all arguments converted during string formatting > > > > The thing is, I want to get format strings from the user, and I don't > > want to require the user to consume all the arguments. docs.python.org > > doesn't seem to have any clues on how to achieve this, and I can't think > > of what to google for. > > > > Could it be as I fear, that it is impossible? > > > > Three approaches spring to mind. In descending order of my preference: > > (a) don't do that > > (b) parse the format string, counting the number of args required. If > the user has supplied more, throw them away. > > (c) wrap your execution of format_string % args in a try/except > bracket. If you get a TypeError with that message [not guaranteed to > remain constant in the future], throw away the last arg and go around > again. > > As a matter of curiosity, why don't you want the user to consume all > the arguments? Don't they get even a teensy-weensy warning message? Are > you writing a Perl interpreter in Python? > Another approach: instead of the "%s %.2f %.5f%%" style, give the users a list of names of each possible arg so that they can do e.g. "The rate for %(name)s is %(rate).5f%%" or "Amount borrowed: $%(amount).2f; borrower: %(name)s" HTH, John -- http://mail.python.org/mailman/listinfo/python-list
Multiple FTP download using Muliti thread
I have taken a look at the code that dose one download at time, in multi threaded manner: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465531 What I wanted to do is, make it download multiple files at the same time. I am new to python and have gone over "Dive In To Python" yesterday. Can some give a idea what I need to do. Once I understand the big picture, then I can piece together. -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
> This is my first solution try, surely there are faster, shorter, better > solutions... > It creates a graph with the paths of words, then sorts the graph > topologically, Beside possible inefficiencies, this "solution" breaks if words aren't in the correct order, the topological sort can't work... I'll have to think about better solutions, if possible. Sorry, bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatters with variable argument length
Fredrik Tolf wrote: > I've been trying to get the string formatting operator (%) to work with > more arguments than the format string requires, but I can find no way to > do that. For example: > > >>> "%i" % 10 > '10' > >>> "i" % 10 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not all arguments converted during string formatting > > The thing is, I want to get format strings from the user, and I don't > want to require the user to consume all the arguments. docs.python.org > doesn't seem to have any clues on how to achieve this, and I can't think > of what to google for. > > Could it be as I fear, that it is impossible? > Three approaches spring to mind. In descending order of my preference: (a) don't do that (b) parse the format string, counting the number of args required. If the user has supplied more, throw them away. (c) wrap your execution of format_string % args in a try/except bracket. If you get a TypeError with that message [not guaranteed to remain constant in the future], throw away the last arg and go around again. As a matter of curiosity, why don't you want the user to consume all the arguments? Don't they get even a teensy-weensy warning message? Are you writing a Perl interpreter in Python? Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: String formatters with variable argument length
How do you know which ones to use? Your best bet is to write a handler for the TypeError and give a meaningful error message. Fredrik Tolf wrote: > I've been trying to get the string formatting operator (%) to work with > more arguments than the format string requires, but I can find no way to > do that. For example: > > >>> "%i" % 10 > '10' > >>> "i" % 10 > Traceback (most recent call last): > File "", line 1, in ? > TypeError: not all arguments converted during string formatting > > The thing is, I want to get format strings from the user, and I don't > want to require the user to consume all the arguments. docs.python.org > doesn't seem to have any clues on how to achieve this, and I can't think > of what to google for. > > Could it be as I fear, that it is impossible? > > Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list
Re: XML blooming
Concerning #2, Microsoft has released a tool for XSD Inference. It can't generate the exact XSD file, but it can guess what it was... http://download.microsoft.com/download/8/0/f/80fca9f1-292e-4b50-b512-ccf004d4b58e/xsdinference.exe Paddy wrote: > (That is bloom as in http://www.wmhelp.com/xmlpad2.htm ;-) > > Suddenly, OK, over a number of months, our design environment at work > has sprouted a wealth of XML configuration files, DTD's etc. The time > has come when I need to loose my XML cherry. > So , I guess I need to learn Elementtree. > > In supporting our design environment I think I will need > 1) An editor that can read in a DTD or XML Schema Definition, (XSD), > as well as an XML file, and help me to write conforming XML. > 2) A tool to extract an XSD from XML examples. > > Hmm, I'm also thinking about a Python project along the lines of > something that could translate between the world of the Traits package > (http://code.enthought.com/traits/), and XSD/DTD/XML. Has anyone done > this before? > > Thanks in advance, Paddy. -- http://mail.python.org/mailman/listinfo/python-list
String formatters with variable argument length
I've been trying to get the string formatting operator (%) to work with more arguments than the format string requires, but I can find no way to do that. For example: >>> "%i" % 10 '10' >>> "i" % 10 Traceback (most recent call last): File "", line 1, in ? TypeError: not all arguments converted during string formatting The thing is, I want to get format strings from the user, and I don't want to require the user to consume all the arguments. docs.python.org doesn't seem to have any clues on how to achieve this, and I can't think of what to google for. Could it be as I fear, that it is impossible? Fredrik Tolf -- http://mail.python.org/mailman/listinfo/python-list
Re: Ruby/Python/REXX as a MUCK scripting language
In article <[EMAIL PROTECTED]>, Laurent Pointal <[EMAIL PROTECTED]> wrote: >Fred Bayer a écrit : >> >> Tony Belding wrote: >>> I'm interested in using an off-the-shelf interpreted language as a >>> user-accessible scripting language for a MUCK. I'm just not sure if I . . . >>> there's the security issue that really worries me. . . I have to be >>> able to limit what the interpreter can execute. I can't have my users >>> running scripts that access the console, access the filesystem or >>> sockets directly, or call libraries or other binaries outside the MUCK. >>> >>> Is this practical? I'm thinking of Ruby or Python for this, if they >>> can meet the requirements. >>> >> >> Don't forget Lua: www.lua.org >> It fulfills your requirements and is easily embedable. >> > >I Agree with F.Bayer, when reading OP post, I immediatly think about Lua. > > > Does Lua have an appropriate security model--a sandbox or such? Fond though I am of Lua, such would be news to me. -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
Robert R.: > i would like to write a piece of code to help me to align some sequence > of words and suggest me the ordered common subwords of them [...] > a trouble i have if when having many different strings my results tend > to be nothing while i still would like to have one of the, or maybe, > all the best matches. This is my first solution try, surely there are faster, shorter, better solutions... from collections import defaultdict from itertools import chain from graph import Graph # http://sourceforge.net/projects/pynetwork/ def commonOrdered(*strings): lists = [[w for w in string.lower().split() if w.isalpha()] for string in strings] freqs = defaultdict(int) for w in chain(*lists): freqs[w] += 1 g = Graph() for words in lists: g.addPath(words) len_strings = len(strings) return [w for w in g.toposort() if freqs[w]==len_strings] s0 = "this is an example of a thing i would like to have" s1 = "another example of something else i would like to have" s2 = 'and this is another " example " but of something ; now i would still like to have' print commonOrdered(s0, s1, s2) It creates a graph with the paths of words, then sorts the graph topologically, then takes only the words of the sorting that are present in all the original strings. With a bit of work the code can be used if it contains words like "example" instead of " example ". An xtoposort method too can be added to the Graph class... Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
gratuity sharply
"It's clear Brad is being a jerk. This blog is for people who want to think about how they manage people, projects, and risk. For me, project management planning is the identification of release criteria and other prose about the project. But we don't always have all the clues, as I didn't in this conversation. But by not asking for help earlier, I might cause that to happen. I'm not sure why that was so hard to do. Is this a good time to talk? Even when I edit, I add more. " If anyone asks about Brad's jerkiness problems, you say, "Brad has decided to pursue career opportunities elsewhere. And in most circumstances, I manage to straight-talk without hurting anyone, even myself. Even when I edit, I add more. And some of us jump to conclusions quickly with the clues we have. But when I hook it up to my computer for scanning to a file, it falls apart. I have a picture that I want to simplify but I don't know Omnigraffle well enough to do so. Ok, I quit all the applications and leave my computer alone to install. Even when I edit, I add more. And some of us jump to conclusions quickly with the clues we have. I now know how to do this for the next time. Check out the Gifts with Purchase page too! You create a lack of trust by commenting about other people. Implicit requirements are still requirements. But that wasn't the case earlier this week. " We went on from there. I can do other things while I'm downloading. Well, I'm only sort-of happy. So does the swapping back in, if it's been a long time since I last worked on this task. Even though I managed to accomplish the tasks I needed, the time it took me to accomplish them and the foreign approach to the UI made me not happy. I was ready to throw the damn thing out the window when I thought, "Huh, I bet other people have this problem. If you're in flow, this is surprisingly high. I was able to start scanning and save my files. Luckily, Nice Person seemed to have taken it well. Even though I managed to accomplish the tasks I needed, the time it took me to accomplish them and the foreign approach to the UI made me not happy. Certainly, for some tasks, it's fairly trivial. So instead of making myself crazy trying to write more good stuff for you, I decided you should read these. Those implicit requirements are still requirements. And if you have to fire Brad, you say something like, "Brad has decided to pursue career opportunities elsewhere. I started to download. Ok, I'm a smart person, I can figure this out. anthem.gif Description: GIF image -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
> i would like to write a piece of code to help me to align some sequence > of words and suggest me the ordered common subwords of them Im not sure what you want, but in case you are guy who knows how quicksort and Djikstra algorithms work :) and wants to find out more. There are many algorithms out there, discovered on "Text algorithms" univesity course. The first one does not directly solve your problem - "edit distance" (Levenshtein distance) http://en.wikipedia.org/wiki/Levenshtein_distance I mention it here only because it is simple and shows basic idea of Dynamic Programming http://en.wikipedia.org/wiki/Dynamic_programming If you scroll down you'll see "Longest common subsequence problem" with implementation in Python for 2 sequences. If you dont understand how it works just look into "edit distance" idea and see it is exactly the same algorithm with changed rules. Oleg -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
Paul McGuire wrote: > "John Henry" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > > > John Henry wrote: > > > >> > >> Further, if splitUp is a sub-class of string, then I can do: > >> > >> alist, blist, clist, dlist = "ABCDEFGHIJ".slice((1,1,3,None)) > >> > >> Now, can I override the slice operator? > > > > Maybe like: > > > > alist, blist, clist, dlist = newStr("ABCDEFGHIJ")[1,1,3,None] > > > > No need to contort string, just expand on your earlier idea. I changed your > class name to SplitUp to more more conventional (class names are usually > capitalized), and changed slice to __call__. Then I changed the lens arg to > *lens - note the difference in the calling format. Pretty close to what you > have above. Also, reconsider whether you want the __init__ function > list-ifying the input src - let the caller decide what to send in. > In fact, should be possible to make that any object the caller want to send in... > -- Paul > > class SplitUp(object): >def __init__(self,src): >self._src=list(src) >def __call__(self, *lens): > ret = [] > cur = 0 > for length in lens: > if length is not None: > ret.append( self._src[cur:cur+length] ) > cur += length > else: > ret.append( self._src[cur:] ) > return ret > > alist, blist, clist, dlist = SplitUp("ABCDEFGHIJ")(1,1,3,None) > print alist, blist, clist, dlist > > Prints: > ['A'] ['B'] ['C', 'D', 'E'] ['F', 'G', 'H', 'I', 'J'] Thanks for the help, -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there a reason not to do this?
Ron Garret schrieb: > One of the things I find annoying about Python is that when you make a > change to a method definition that change is not reflected in existing > instances of a class (because you're really defining a new class when > you reload a class definition, not actually redefining it). So I came > up with this programming style: > > def defmethod(cls): > return lambda (func): type.__setattr__(cls, func.func_name, func) > > class c1(object): pass > > @defmethod(c1) > def m1(self, x): ... > > > Now if you redefine m1, existing instances of c1 will see the change. > > My question is: is there a reason not to do this? Does it screw > something up behind the scenes? Is it unpythonic? Why isn't this > standard operating procedure? What are you doing that needs this permanent redefinition? I like the repl, yet usually - especially when dealing with classes - I write a text file containing code. So, i just run that on a command line again, if I made some changes, recreating whatever objects I want again. Even if I'd not do that, but used a long-running interpreter inside an IDE (which is what I presume you are doing) - why do you _care_ about the old objects the first place? I mean, you obviously changed the classes for a reason. So, you are not being productive here, but still programming. Which means that you don't _have_ to care about old, unchanged objects too much. But in the end - it's your code. It will run slower, it looks kinda weird as someone who's reading it has to know what it is for, but if it suits your needs - do it. Diez -- http://mail.python.org/mailman/listinfo/python-list
Python25.zip
As part of the Python initialization, C:\Windows\System32\Python25.zip is set up in the path. I haven't seen any documentation on the use or purpose of the zip file. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
Robert R. wrote: > Hello, > > i would like to write a piece of code to help me to align some sequence > of words and suggest me the ordered common subwords of them > > a trouble i have if when having many different strings my results tend > to be nothing while i still would like to have one of the, or maybe, > all the best matches. "align"? Anyway, for finding the commonest words, you'll be best off counting how many times each word appears: lst = ["foo bar baz", "qux foo foo kaka", "one foo and kaka times qux"] for line in lst: for word in line.split(): count[word] = count.get(word,0) + 1 Now you go for the ones with the highest count: for (word, n) in sorted(d.items(), key = lambda x: x[1], reverse = True): print word, 'appears', n, 'times' Untested. If you want to count the number of lines a word appears in (as opposed to the number of times it appears at all), add an extra condition before count[word] = ... -- http://mail.python.org/mailman/listinfo/python-list
v2.3, 2.4, and 2.5's GUI is slow for me
I've been asking all over the place, namely different forums. I even e-mailed [EMAIL PROTECTED] about my problem, but they couldn't assist me too much. My problem is..the GUI for versions 2.3, 2.4, and 2.5 of Python run very sluggishly. When I type in them or move them around my desktop, it's very slow. I have figured out that this is because of the subprocesses running. To cope with this problem, I created an idle.txt file, and added this to the first line of it: c:\python25\python c:\python25\Lib\idlelib\idle.py -n After that I saved the extension to .bat and now when I run that file, the Python GUI opens without any subprocesses running and I have no problem. However, I'd still really like to know how I could fix this problem even more. I honestly don't understand why the GUI is so sluggish for me. The GUIs for Python version 2.2 and below run fine for me. My system specs are as follows: Windows XP Home Edition AMD Athlon XP 2800 nVidia 6800GT 1 gig of RAM If anyone else could help, that would be great. -- View this message in context: http://www.nabble.com/v2.3%2C-2.4%2C-and-2.5%27s-GUI-is-slow-for-me-tf2735011.html#a7630074 Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to align words?
Robert R. schrieb: > Hello, > > i would like to write a piece of code to help me to align some sequence > of words and suggest me the ordered common subwords of them > > s0 = "this is an example of a thing i would like to have".split() > s1 = "another example of something else i would like to have".split() > s2 = 'and this is another " example " but of something ; now i would > still like to have'.split() > ... > alist = (s0, s1, s2) > > result should be : ('example', 'of', 'i', 'would', 'like', 'to', 'have' > > but i do not know how should i start, may be have you a helpful > suggestion? > a trouble i have if when having many different strings my results tend > to be nothing while i still would like to have one of the, or maybe, > all the best matches. > > best. > As far as I can see, you want to have the words, that all three lists have in common, right? s0 = "this is an example of a thing i would like to have".split() s1 = "another example of something else i would like to have".split() s2 = 'and this is another " example " but of something ; now i would still like to have'.split() def findCommons(s0, s1, s2): res = [] for word in s0: if word in s1 and word in s2: res.append(word) return res >>>print findCommons(s0,s1,s2) ['example', 'of', 'i', 'would', 'like', 'to', 'have'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
"John Henry" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > John Henry wrote: > >> >> Further, if splitUp is a sub-class of string, then I can do: >> >> alist, blist, clist, dlist = "ABCDEFGHIJ".slice((1,1,3,None)) >> >> Now, can I override the slice operator? > > Maybe like: > > alist, blist, clist, dlist = newStr("ABCDEFGHIJ")[1,1,3,None] > No need to contort string, just expand on your earlier idea. I changed your class name to SplitUp to more more conventional (class names are usually capitalized), and changed slice to __call__. Then I changed the lens arg to *lens - note the difference in the calling format. Pretty close to what you have above. Also, reconsider whether you want the __init__ function list-ifying the input src - let the caller decide what to send in. -- Paul class SplitUp(object): def __init__(self,src): self._src=list(src) def __call__(self, *lens): ret = [] cur = 0 for length in lens: if length is not None: ret.append( self._src[cur:cur+length] ) cur += length else: ret.append( self._src[cur:] ) return ret alist, blist, clist, dlist = SplitUp("ABCDEFGHIJ")(1,1,3,None) print alist, blist, clist, dlist Prints: ['A'] ['B'] ['C', 'D', 'E'] ['F', 'G', 'H', 'I', 'J'] -- http://mail.python.org/mailman/listinfo/python-list
best way to align words?
Hello, i would like to write a piece of code to help me to align some sequence of words and suggest me the ordered common subwords of them s0 = "this is an example of a thing i would like to have".split() s1 = "another example of something else i would like to have".split() s2 = 'and this is another " example " but of something ; now i would still like to have'.split() ... alist = (s0, s1, s2) result should be : ('example', 'of', 'i', 'would', 'like', 'to', 'have' but i do not know how should i start, may be have you a helpful suggestion? a trouble i have if when having many different strings my results tend to be nothing while i still would like to have one of the, or maybe, all the best matches. best. -- http://mail.python.org/mailman/listinfo/python-list
Re: detecting that a SQL db is running
Sorry if i did not make myself clear. let me try again. 1. I have a series of servers running windows server 2003. 2 on each server there is an application running that communicates with remote devices using email. 3. this application is made up from a series of modules that also extract data from a local MSDE db. 4. this application pulls emails from remote devices, interrogates a the DB, then passes on an XML message to a central server. 5. I am intercepting these XML messages to insert additional data that I extract from the DB, and then forward on to another application. Call this my local app. The problem that I have is that the original application occasionally hangs, causing the DB to stop. I have ASR routines in place to re-boot the server when this happens. I can detect when the db is up and not responding, however, if the DB does not start at all, my local application hangs. I need to find a way to determine if the DB has started, that's all. if any of you have any insight into how I can detect that the DB has started as is running, that would be very useful. any contributions, most gratefully received. kind regards bill -- http://mail.python.org/mailman/listinfo/python-list
Re: Python spam?
[Aahz] >>> Anyone else getting "Python-related" spam? So far, I've seen messages >>> "from" Barry Warsaw and Skip Montanaro (although of course header >>> analysis proves they didn't send it). [Thomas Heller] >> I'm getting spam not only from Barry, but also from myself ;-) with >> forged headers. But I'm not sure what you mean with Python-related... >> Not the contents, IIRC. [Aahz[ > Thing is, I don't usually get spam "from" people I know (or at least it > gets filtered before I see it), so someone is clearly using some resource > of Python-related email addresses. Just seems rather odd, and I wonder > whether it's some kind of DoS attack or what. It's been going on for years. The most frequent forged "Python related" sender address I've seen is actually [EMAIL PROTECTED], followed (but not closely) by /F's [EMAIL PROTECTED] Spammers harvest legit addresses to forge via scraping web pages and via Trojans scouring newbies' address books. The latter probably accounts for the very high rate of [EMAIL PROTECTED] forgeries. Via the former, anyone with a "public" email address can expect to see it get forged sooner or later. About two years ago I sent a polite email to a porn vendor asking them to please stop forging one of my email addresses as the sender of their spam. They didn't reply, but within a few days I stopped receiving porn spam claiming to come from me. Frankly, I miss it :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python spam?
In article <[EMAIL PROTECTED]>, Thomas Heller <[EMAIL PROTECTED]> wrote: >Aahz schrieb: >> >> Anyone else getting "Python-related" spam? So far, I've seen messages >> "from" Barry Warsaw and Skip Montanaro (although of course header >> analysis proves they didn't send it). > >I'm getting spam not only from Barry, but also from myself ;-) with >forged headers. But I'm not sure what you mean with Python-related... >Not the contents, IIRC. Thing is, I don't usually get spam "from" people I know (or at least it gets filtered before I see it), so someone is clearly using some resource of Python-related email addresses. Just seems rather odd, and I wonder whether it's some kind of DoS attack or what. -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ Member of the Groucho Marx Fan Club -- http://mail.python.org/mailman/listinfo/python-list
Re: Beautiful Soup Question: Filtering Images based on their width and height attributes
On 30 Nov 2006 12:43:45 -0800, PicURLPy <[EMAIL PROTECTED]> wrote: > Hello, > > I want to extract some image links from different html pages, in > particular i want extract those image tags which height values are > greater than 200. Is there an elegant way in BeautifulSoup to do this? > Most image tags "in the wild" don't have height attributes, you have to download the image to see what size it is. > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Remarkable results with psyco and sieve of Eratosthenes
Klaus Alexander Seistrup wrote: > Pekka Karjalainen wrote: > > > You can omit the call to math.sqrt if you test this instead. > > > > y*y > x > > > > in place of if y > maxfact: . > > Or use > > sqrt = lambda x: x ** .5 Test it: $ python -m timeit -s "from math import sqrt" "sqrt(5.6)" 100 loops, best of 3: 0.445 usec per loop $ python -m timeit -s "sqrt = lambda x: x**.5" "sqrt(5.6)" 100 loops, best of 3: 0.782 usec per loop Note that this overhead is almost entirely in function calls; calling an empty lambda is more expensive than a c-level sqrt: $ python -m timeit -s "sqrt = lambda x: x" "sqrt(5.6)" 100 loops, best of 3: 0.601 usec per loop Just math ops: $ python -m timeit -s "x = 5.6" "x*x" 1000 loops, best of 3: 0.215 usec per loop $ python -m timeit -s "x = 5.6" "x**.5" 100 loops, best of 3: 0.438 usec per loop Of course, who knows that psyco does with this under the hood. -Mike -- http://mail.python.org/mailman/listinfo/python-list
Re: How can I change the icon
Boneh wrote: > Is it possible to change the icon "Tk" of the windows popped up ? I am using tkinter for widgets, thanks :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter
Fredrik Lundh wrote: > Boneh wrote: > >> The module is not found on the system, althouhg I can use python2.4. i > >> am using fedoralinux5 > > > > > > I see lots of question marks, but I don't see a question. are you > asking why a module you haven't installed isn't installed? have you > tried installing it? > > Thanks, I installed tkinter and it works again fine. True! Heh -- http://mail.python.org/mailman/listinfo/python-list
How can I change the icon
Is it possible to change the icon "Tk" of the windows popped up ? -- http://mail.python.org/mailman/listinfo/python-list
Re: PythonTidy
Chuck Rhode schrieb: > I couldn't find a routine to clean up, regularize, and reformat Python > code, so I wrote one: > > http://www.lacusveris.com/PythonTidy/PythonTidy.python > > Now, I'm looking for beta-testers. Compensation is a bit on the low > side. In fact it's limited to the satisfaction of helping out. > Thanks. > This looks very good, to me. The two things that bother me at the moment are how the comments are formatted (dunno if that can be customized or changed easily), and it would be good if the script took command line args instead of working as a filter only. Thanks, Thomas -- http://mail.python.org/mailman/listinfo/python-list
Beautiful Soup Question: Filtering Images based on their width and height attributes
Hello, I want to extract some image links from different html pages, in particular i want extract those image tags which height values are greater than 200. Is there an elegant way in BeautifulSoup to do this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
Thomas Ploch wrote: > > John Henry schrieb: > > > Thomas Ploch wrote: > > > > >> >> I had a little bit of fun while writing this: > >> >> > >> >> itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and > >> >> itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. > >> >> > > > > > > Huh? What's a,b,d5? > > > > > Can be any object, as you had in your example in your mail: > Oh, sorry. -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry schrieb: > Thomas Ploch wrote: > >> I had a little bit of fun while writing this: >> >> itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and >> itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. >> > > Huh? What's a,b,d5? > John Henry schrieb: > > Thomas Ploch wrote: > > >> >> I had a little bit of fun while writing this: >> >> >> >> itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and >> >> itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. >> >> > > > > Huh? What's a,b,d5? > > Can be any object, as you had in your example in your mail: >>>If I have a list of say, 10 elements and I need to slice it into >>> irregular size list, I would have to create a bunch of temporary >>> variables and then regroup them afterwords, like: >>> >>> # Just for illustration. Alist can be any existing 10 element list >>> a_list=("",)*10 >>> (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list >>> alist=(a,) >>> blist=(b,) >>> clist=(c1,c2,c3) >>> dlist=(d2,d3,d4,d5) >> def getSlices(aCount, bCount, cCount, dCount, items): >> a,b,c,d = (items[0:aCount], >> items[aCount:aCount+bCount], >> items[aCount+bCount:aCount+bCount+cCount], >> item[aCount+bCount+cCount:aCount+bCount+cCount+dCount]) > > You meant "items" here, right? > >> return list(a),list(b),list(c),list(d) >> > a,b,c,d = getSlices(1,1,3,5,itemList) > print a,b,c,d >> ['a'] ['b'] ['c1', 'c2', 'c3'] ['d1', 'd2', 'd3', 'd4', 'd5'] >> > a,b,c,d = getSlices(3,1,1,0,itemList2) > print a,b,c,d >> ['a1', 'a2', 'a3'] ['b'] ['c'] [] >> >> %-) >> >> Thomas > -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 does not marshal infinity floating point properly under Win32
Pierre Rouleau schrieb: > Is this considered an important enough bug to fix it in Python 2.4? To the contrary - it's not considered a bug at all. Python didn't make any promises about "unregular" floating point values, so things like that just may happen. The fix that made Python offer stronger guarantees in 2.5 cannot be ported back to 2.4, since it would break the marshal format of that release. Finally, it's not very likely that *any* additional 2.4.x releases are made at all; only 2.5.x is still actively maintained. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.4 does not marshal infinity floating point properly under Win32
On 2006-11-30, Pierre Rouleau <[EMAIL PROTECTED]> wrote: > When using Python 2.4.x on a Win32 box, > marshal.loads(marshal.dumps(1e6)) returns 1.0 instead of infinity > as it should and does under Python 2.5 (also running on Win32 ). > > This problem was reported in another thread here by Peter Hansen > http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/5c2b4b2a88c8df4/f216739705c9304f?lnk=gst&q=simplejson&rnum=5#f216739705c9304f > > Is this considered an important enough bug to fix it in Python 2.4? This must be at least the third thread on this topic so far this week. And I didn't start _any_ of them (this week). :) -- Grant Edwards grante Yow! Imagine--a WORLD at without POODLES... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
Thomas Ploch wrote: > > I had a little bit of fun while writing this: > > itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and > itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. > Huh? What's a,b,d5? > def getSlices(aCount, bCount, cCount, dCount, items): > a,b,c,d = (items[0:aCount], > items[aCount:aCount+bCount], > items[aCount+bCount:aCount+bCount+cCount], > item[aCount+bCount+cCount:aCount+bCount+cCount+dCount]) You meant "items" here, right? > return list(a),list(b),list(c),list(d) > > >>>a,b,c,d = getSlices(1,1,3,5,itemList) > >>>print a,b,c,d > ['a'] ['b'] ['c1', 'c2', 'c3'] ['d1', 'd2', 'd3', 'd4', 'd5'] > > >>>a,b,c,d = getSlices(3,1,1,0,itemList2) > >>>print a,b,c,d > ['a1', 'a2', 'a3'] ['b'] ['c'] [] > > %-) > > Thomas -- http://mail.python.org/mailman/listinfo/python-list
Python 2.4 does not marshal infinity floating point properly under Win32
Hi all, When using Python 2.4.x on a Win32 box, marshal.loads(marshal.dumps(1e6)) returns 1.0 instead of infinity as it should and does under Python 2.5 (also running on Win32 ). This problem was reported in another thread here by Peter Hansen http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/5c2b4b2a88c8df4/f216739705c9304f?lnk=gst&q=simplejson&rnum=5#f216739705c9304f Is this considered an important enough bug to fix it in Python 2.4? The following script exercise the problem when executed:: #---test_marshal.py-- import marshal INFINITY = 1e6 inf = 1e300 * 1e300 nan = inf - inf def show(title, msg): print '%-10s : ' % title, msg2 = '' count = 0 for chr in msg: count += 1 val = ord(chr) print hex(val), if 31 < val < 128: msg2 += chr else: msg2 += '.' print ' ' * (9-count), ' : ', msg2 show('Nan', marshal.dumps(nan)) show('Infinity', marshal.dumps(INFINITY)) show('Infinity', marshal.dumps(inf)) show('Infinity', marshal.dumps(1e666)) val = marshal.loads(marshal.dumps(1e666)) print val val = marshal.loads(marshal.dumps(INFINITY)) print val assert val==INFINITY #--- When running the script on Win32 box with Python 2.4.3 or 2.4.4 I get:: D:\dev\python\test>t_marshal Nan: 0x66 0x7 0x2d 0x31 0x2e 0x23 0x49 0x4e 0x44 : f.-1.#IND Infinity : 0x66 0x6 0x31 0x2e 0x23 0x49 0x4e 0x46: f.1.#INF Infinity : 0x66 0x6 0x31 0x2e 0x23 0x49 0x4e 0x46: f.1.#INF Infinity : 0x66 0x6 0x31 0x2e 0x23 0x49 0x4e 0x46: f.1.#INF 1.0 1.0 Traceback (most recent call last): File "D:\dev\python\test\t_marshal.py", line 33, in ? assert val==INFINITY AssertionError But when running the same script on a Win32 box, using Python 2.5, I get:: C:\dev\python\test>t_marshal Nan: 0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf8 0xff : g Infinity : 0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf0 0x7f : g...¦ Infinity : 0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf0 0x7f : g...¦ Infinity : 0x67 0x0 0x0 0x0 0x0 0x0 0x0 0xf0 0x7f : g...¦ 1.#INF 1.#INF #- -- Pierre Rouleau -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry wrote: > > Further, if splitUp is a sub-class of string, then I can do: > > alist, blist, clist, dlist = "ABCDEFGHIJ".slice((1,1,3,None)) > > Now, can I override the slice operator? Maybe like: alist, blist, clist, dlist = newStr("ABCDEFGHIJ")[1,1,3,None] where newStr is a sub-class of str, with a __repr__ that takes a variable list of arguments? (No clue how to code that yet, still pretty new to this) Maybe they should make this a standard slicing feature -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry schrieb: > If I have a list of say, 10 elements and I need to slice it into > irregular size list, I would have to create a bunch of temporary > variables and then regroup them afterwords, like: > > # Just for illustration. Alist can be any existing 10 element list > a_list=("",)*10 > (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list > alist=(a,) > blist=(b,) > clist=(c1,c2,c3) > dlist=(d2,d3,d4,d5) > > That obviously work but do I *really* have to do that? > > BTW: I know you can do: > alist=a_list[0] > blist=a_list[1] > clist=a_list[2:5] > dlist=a_list[5:] > > but I don't see that it's any better. > > Can I say something to the effect of: > > (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work > > ?? > > I am asking this because I have a section of code that contains *lots* > of things like this. It makes the code very unreadable. > > Thanks, > I had a little bit of fun while writing this: itemList = (a,b,c1,c2,c3,d1,d2,d3,d4,d5) and itemList2 = (a1,a2,a3,b,c,d1,d2,d3,d4,d5) the next time. def getSlices(aCount, bCount, cCount, dCount, items): a,b,c,d = (items[0:aCount], items[aCount:aCount+bCount], items[aCount+bCount:aCount+bCount+cCount], item[aCount+bCount+cCount:aCount+bCount+cCount+dCount]) return list(a),list(b),list(c),list(d) >>>a,b,c,d = getSlices(1,1,3,5,itemList) >>>print a,b,c,d ['a'] ['b'] ['c1', 'c2', 'c3'] ['d1', 'd2', 'd3', 'd4', 'd5'] >>>a,b,c,d = getSlices(3,1,1,0,itemList2) >>>print a,b,c,d ['a1', 'a2', 'a3'] ['b'] ['c'] [] %-) Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Python spam?
Aahz schrieb: > Anyone else getting "Python-related" spam? So far, I've seen messages > "from" Barry Warsaw and Skip Montanaro (although of course header > analysis proves they didn't send it). I'm getting spam not only from Barry, but also from myself ;-) with forged headers. But I'm not sure what you mean with Python-related... Not the contents, IIRC. Thomas -- http://mail.python.org/mailman/listinfo/python-list
Is there a reason not to do this?
One of the things I find annoying about Python is that when you make a change to a method definition that change is not reflected in existing instances of a class (because you're really defining a new class when you reload a class definition, not actually redefining it). So I came up with this programming style: def defmethod(cls): return lambda (func): type.__setattr__(cls, func.func_name, func) class c1(object): pass @defmethod(c1) def m1(self, x): ... Now if you redefine m1, existing instances of c1 will see the change. My question is: is there a reason not to do this? Does it screw something up behind the scenes? Is it unpythonic? Why isn't this standard operating procedure? rg -- http://mail.python.org/mailman/listinfo/python-list
Re: DDE (eSignal)
Thomas Heller wrote: > Looks like a bug, either in the dde module or the dde server. > But it's easy to find a workaround: > '1402.6700\x00\x12\x00*\x00\x00\x004\xfb\x12\x00\xfd\x1a\xd9w4\xc1\x00'.split("\0")[0] > '1402.6700' float(last.split("\0")[0]) works for me. Thanks for that! jab -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry wrote: > Paul McGuire wrote: > > "Paul McGuire" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > "John Henry" <[EMAIL PROTECTED]> wrote in message > > > news:[EMAIL PROTECTED] > > snip > > > > G... that's what I get for not keeping editor and interpreter windows in > > sync. My post was referencing vars I had defined in the interpreter, but > > which the function had no clue of. !!! Here's a working version. > > > > -- Paul > > > > > > def splitUp(src,lens): > > ret = [] > > cur = 0 > > for length in lens: > > if length is not None: > > ret.append( src[cur:cur+length] ) > > cur += length > > else: > > ret.append( src[cur:] ) > > return ret > > > > origlist = list("ABCDEFGHIJ") > > alist, blist, clist, dlist = splitUp( origlist, (1,1,3,None) ) > > print alist, blist, clist, dlist > > > Nice. > > While we are at it, why not: > > class splitUp(object): >def __init__(self,src): >self._src=list(src) >def slice(self, lens): > ret = [] > cur = 0 > for length in lens: > if length is not None: > ret.append( self._src[cur:cur+length] ) > cur += length > else: > ret.append( self._src[cur:] ) > return ret > > alist, blist, clist, dlist = splitUp("ABCDEFGHIJ").slice((1,1,3,None)) > print alist, blist, clist, dlist > > Now, that's readable! Further, if splitUp is a sub-class of string, then I can do: alist, blist, clist, dlist = "ABCDEFGHIJ".slice((1,1,3,None)) Now, can I override the slice operator? -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
Paul McGuire wrote: > "Paul McGuire" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > "John Henry" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > snip > > G... that's what I get for not keeping editor and interpreter windows in > sync. My post was referencing vars I had defined in the interpreter, but > which the function had no clue of. !!! Here's a working version. > > -- Paul > > > def splitUp(src,lens): > ret = [] > cur = 0 > for length in lens: > if length is not None: > ret.append( src[cur:cur+length] ) > cur += length > else: > ret.append( src[cur:] ) > return ret > > origlist = list("ABCDEFGHIJ") > alist, blist, clist, dlist = splitUp( origlist, (1,1,3,None) ) > print alist, blist, clist, dlist Nice. While we are at it, why not: class splitUp(object): def __init__(self,src): self._src=list(src) def slice(self, lens): ret = [] cur = 0 for length in lens: if length is not None: ret.append( self._src[cur:cur+length] ) cur += length else: ret.append( self._src[cur:] ) return ret alist, blist, clist, dlist = splitUp("ABCDEFGHIJ").slice((1,1,3,None)) print alist, blist, clist, dlist Now, that's readable! -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
[EMAIL PROTECTED] wrote: > John Henry wrote: > > Can I say something to the effect of: > > > > (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work > > Your best bet is probably: > > x = [...some list...] > a,b,c,d = x[:1],x[1:2],x[2:5],x[5:] > Dude! Why didn't I think of that (tunnel vision). Thanks, > > I am asking this because I have a section of code that contains *lots* > > of things like this. It makes the code very unreadable. > > Of course, if you're always slicing up lists the same way (say, into > 1,1,3,5 element sections) then you could improve readability by writing > a function that takes the list and returns a tuple of the pieces, such > as: > > def slice_list(x): > return x[:1],x[1:2],x[2:5],x[5:] > > a,b,c,d = slice_list(first_list) > e,f,g,h = slice_list(second_list) > > -Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
"Paul McGuire" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "John Henry" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] snip G... that's what I get for not keeping editor and interpreter windows in sync. My post was referencing vars I had defined in the interpreter, but which the function had no clue of. !!! Here's a working version. -- Paul def splitUp(src,lens): ret = [] cur = 0 for length in lens: if length is not None: ret.append( src[cur:cur+length] ) cur += length else: ret.append( src[cur:] ) return ret origlist = list("ABCDEFGHIJ") alist, blist, clist, dlist = splitUp( origlist, (1,1,3,None) ) print alist, blist, clist, dlist -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
"John Henry" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > If I have a list of say, 10 elements and I need to slice it into > irregular size list, I would have to create a bunch of temporary > variables and then regroup them afterwords, like: > > # Just for illustration. Alist can be any existing 10 element list > a_list=("",)*10 > (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list > alist=(a,) > blist=(b,) > clist=(c1,c2,c3) > dlist=(d2,d3,d4,d5) > > That obviously work but do I *really* have to do that? > > BTW: I know you can do: > alist=a_list[0] > blist=a_list[1] > clist=a_list[2:5] > dlist=a_list[5:] > > but I don't see that it's any better. The slicing notation is about the best general solution. If you are doing this a lot, you should write some sort of "break up the list function". Here's one that takes a list of list lengths to break the list into. -- Paul def splitUp(src,lens): ret = [] cur = 0 for var,length in varmap: if length is not None: ret.append( a_list[cur:cur+length] ) cur += length else: ret.append( a_list[cur:] ) return ret origlist = list("ABCDEFGHIJ") alist, blist, clist, dlist = splitUp( origlist, (1,1,3,None) ) print alist, blist, clist, dlist Prints ['A'] ['B'] ['C', 'D', 'E'] ['F', 'G', 'H', 'I', 'J'] -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
On 2006-11-30, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2006-11-30, John Henry <[EMAIL PROTECTED]> wrote: >> If I have a list of say, 10 elements and I need to slice it into >> irregular size list, I would have to create a bunch of temporary >> variables and then regroup them afterwords, like: >> >> # Just for illustration. Alist can be any existing 10 element list >> a_list=("",)*10 >> (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list >> alist=(a,) >> blist=(b,) >> clist=(c1,c2,c3) >> dlist=(d2,d3,d4,d5) >> >> That obviously work but do I *really* have to do that? > > Please post actual code we can run, rather than text that is > almost, but not quite, entirely unlike Python code. Ummm... that comment is withdrawn. :-O -- Neil Cerutti -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
On 2006-11-30, John Henry <[EMAIL PROTECTED]> wrote: > If I have a list of say, 10 elements and I need to slice it into > irregular size list, I would have to create a bunch of temporary > variables and then regroup them afterwords, like: > > # Just for illustration. Alist can be any existing 10 element list > a_list=("",)*10 > (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list > alist=(a,) > blist=(b,) > clist=(c1,c2,c3) > dlist=(d2,d3,d4,d5) > > That obviously work but do I *really* have to do that? Please post actual code we can run, rather than text that is almost, but not quite, entirely unlike Python code. > BTW: I know you can do: > alist=a_list[0] > blist=a_list[1] Note that alist and blist are not necessarily lists, as you did not use slice notation. > clist=a_list[2:5] > dlist=a_list[5:] > > but I don't see that it's any better. I think it looks much better, personally. If you are iterating through that sequence of slices a lot, consider using a generator that yields the sequence. >>> def parts(items): ... yield items[0:1] ... yield items[1:2] ... yield items[2:5] ... yield items[5:] >>> for seq in parts(range(10)): ... print seq [0] [1] [2, 3, 4] [5, 6, 7, 8, 9] -- Neil Cerutti I guess there are some operas I can tolerate and Italian isn't one of them. --Music Lit Essay -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry wrote: > Can I say something to the effect of: > > (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work Your best bet is probably: x = [...some list...] a,b,c,d = x[:1],x[1:2],x[2:5],x[5:] > I am asking this because I have a section of code that contains *lots* > of things like this. It makes the code very unreadable. Of course, if you're always slicing up lists the same way (say, into 1,1,3,5 element sections) then you could improve readability by writing a function that takes the list and returns a tuple of the pieces, such as: def slice_list(x): return x[:1],x[1:2],x[2:5],x[5:] a,b,c,d = slice_list(first_list) e,f,g,h = slice_list(second_list) -Matt -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
Well, pardoon me. Next. Thomas Ploch wrote: > John Henry schrieb: > > If I have a list of say, 10 elements and I need to slice it into > > irregular size list, I would have to create a bunch of temporary > > variables and then regroup them afterwords, like: > > > > # Just for illustration. Alist can be any existing 10 element list > > a_list=("",)*10 > > (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list > > alist=(a,) > > blist=(b,) > > clist=(c1,c2,c3) > > dlist=(d2,d3,d4,d5) > > > > That obviously work but do I *really* have to do that? > > > > BTW: I know you can do: > > alist=a_list[0] > > blist=a_list[1] > > clist=a_list[2:5] > > dlist=a_list[5:] > > > > but I don't see that it's any better. > > > > Can I say something to the effect of: > > > > (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work > > > > ?? > > > > I am asking this because I have a section of code that contains *lots* > > of things like this. It makes the code very unreadable. > > > > Thanks, > > > > Nothing in your code actually __is__ a list. they are all tuples... > A list is: > aList = [a,b,c1,c2,c3,d1,d2,d3,d4,d5] > > Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: DDE (eSignal)
BBands schrieb: > I have a Python ap that needs current stock prices, which I want to get > from eSignal's DDE server. Following the win32all example: > > import win32ui > import dde > server = dde.CreateServer() > server.Create("eSignalDDE") > conversation = dde.CreateConversation(server) > conversation.ConnectTo("WINROS", "Last") > last = conversation.Request("$spx") > print last > > Which almost works. The return in PythonWin is the correct price as a > string with some extra chartacters appended. > > '1402.6700\x00\x12\x00*\x00\x00\x004\xfb\x12\x00\xfd\x1a\xd9w4\xc1\x00' > > Any thoughts on this? > > TIA, > > jab > Looks like a bug, either in the dde module or the dde server. But it's easy to find a workaround: >>> '1402.6700\x00\x12\x00*\x00\x00\x004\xfb\x12\x00\xfd\x1a\xd9w4\xc1\x00'.split("\0")[0] '1402.6700' >>> Thomas -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
On 11/30/06, Thomas Ploch <[EMAIL PROTECTED]> wrote: > John Henry schrieb: > > If I have a list of say, 10 elements and I need to slice it into > > irregular size list, I would have to create a bunch of temporary > > variables and then regroup them afterwords, like: > > > > # Just for illustration. Alist can be any existing 10 element list > > a_list=("",)*10 > > (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list > > alist=(a,) > > blist=(b,) > > clist=(c1,c2,c3) > > dlist=(d2,d3,d4,d5) > > > > That obviously work but do I *really* have to do that? > > > > BTW: I know you can do: > > alist=a_list[0] > > blist=a_list[1] > > clist=a_list[2:5] > > dlist=a_list[5:] > > > > but I don't see that it's any better. > > > > Can I say something to the effect of: > > > > (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work > > > > ?? > > > > I am asking this because I have a section of code that contains *lots* > > of things like this. It makes the code very unreadable. > > > > Thanks, > > > > Nothing in your code actually __is__ a list. they are all tuples... > A list is: > aList = [a,b,c1,c2,c3,d1,d2,d3,d4,d5] > True but not relevant, really, he should have said "sequence". But more importantly, you don't show what you do with alist, blist,clist,dlist. Without knowing what the end result is, nobody is going to be able to help you eliminate the middle steps. > Thomas > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
Re: Is there an easier way to express this list slicing?
John Henry schrieb: > If I have a list of say, 10 elements and I need to slice it into > irregular size list, I would have to create a bunch of temporary > variables and then regroup them afterwords, like: > > # Just for illustration. Alist can be any existing 10 element list > a_list=("",)*10 > (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list > alist=(a,) > blist=(b,) > clist=(c1,c2,c3) > dlist=(d2,d3,d4,d5) > > That obviously work but do I *really* have to do that? > > BTW: I know you can do: > alist=a_list[0] > blist=a_list[1] > clist=a_list[2:5] > dlist=a_list[5:] > > but I don't see that it's any better. > > Can I say something to the effect of: > > (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work > > ?? > > I am asking this because I have a section of code that contains *lots* > of things like this. It makes the code very unreadable. > > Thanks, > Nothing in your code actually __is__ a list. they are all tuples... A list is: aList = [a,b,c1,c2,c3,d1,d2,d3,d4,d5] Thomas -- http://mail.python.org/mailman/listinfo/python-list
Python spam?
Anyone else getting "Python-related" spam? So far, I've seen messages "from" Barry Warsaw and Skip Montanaro (although of course header analysis proves they didn't send it). -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ Usenet is not a democracy. It is a weird cross between an anarchy and a dictatorship. -- http://mail.python.org/mailman/listinfo/python-list
Is there an easier way to express this list slicing?
If I have a list of say, 10 elements and I need to slice it into irregular size list, I would have to create a bunch of temporary variables and then regroup them afterwords, like: # Just for illustration. Alist can be any existing 10 element list a_list=("",)*10 (a,b,c1,c2,c3,d1,d2,d3,d4,d5)=a_list alist=(a,) blist=(b,) clist=(c1,c2,c3) dlist=(d2,d3,d4,d5) That obviously work but do I *really* have to do that? BTW: I know you can do: alist=a_list[0] blist=a_list[1] clist=a_list[2:5] dlist=a_list[5:] but I don't see that it's any better. Can I say something to the effect of: (a,b,c[0:2],d[0:5])=a_list# Obviously this won't work ?? I am asking this because I have a section of code that contains *lots* of things like this. It makes the code very unreadable. Thanks, -- http://mail.python.org/mailman/listinfo/python-list
DDE (eSignal)
I have a Python ap that needs current stock prices, which I want to get from eSignal's DDE server. Following the win32all example: import win32ui import dde server = dde.CreateServer() server.Create("eSignalDDE") conversation = dde.CreateConversation(server) conversation.ConnectTo("WINROS", "Last") last = conversation.Request("$spx") print last Which almost works. The return in PythonWin is the correct price as a string with some extra chartacters appended. '1402.6700\x00\x12\x00*\x00\x00\x004\xfb\x12\x00\xfd\x1a\xd9w4\xc1\x00' Any thoughts on this? TIA, jab -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter
Boneh wrote: >> The module is not found on the system, althouhg I can use python2.4. i >> am using fedoralinux5 > > I see lots of question marks, but I don't see a question. are you asking why a module you haven't installed isn't installed? have you tried installing it? -- http://mail.python.org/mailman/listinfo/python-list
Re: extremely slow array indexing?
John Machin wrote: > Hi Grace, > What Will McGugan said, plus: > 1. Post *much* more of your code e.g. all relevant parts :-) Note that Grace has also posted this to numpy-discussion and with prompting provided the following snippet as a distillation of the key slow part: from numpy import * componentcount = 30 currSum = zeros(componentcount) row = zeros(componentcount) #current row rowcount = 5 for i in range(1,rowcount): row[:] = 1 currSum = currSum + row; As it is, the OP gets through 1000 rows every 7 seconds or so on their machine, and I get about the same on mine. Changing the last line to "currSum += row" gets a 3x speedup. Dropping the "row[:] = 1" line as it's a really just a time-consuming no-op in the example and probably not an accurate reflection of what's going on in the real code gets you another 2x speedup. -- 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