From rellikmaet at gmail.com Fri Apr 1 00:07:26 2011 From: rellikmaet at gmail.com (haha doh) Date: Thu, 31 Mar 2011 21:07:26 -0700 (PDT) Subject: FBI wants public help solving encrypted notes from murder mystery References: Message-ID: On Mar 31, 3:15?pm, Joe Snodgrass wrote: > On Mar 30, 10:18?pm, "Stretto" wrote: > > > > > > > "Joe Snodgrass" wrote in message > > >news:c37e8e0b-a825-4ac5-9886-8828ab1faf94 at x8g2000prh.googlegroups.com... > > > > FBI cryptanalysis hasn?t decrypted notes from 1999 murder mystery > > > >http://tinyurl.com/4d56zsz > > > > The FBI is seeking the public's help in breaking the encrypted code > > > found in two notes discovered on the body of a murdered man in 1999. > > > > The FBI says that officers in St. Louis, Missouri discovered the body > > > of 41-year-old Ricky McCormick on June 30, 1999 in a field and the > > > clues regarding the homicide were two encrypted notes found in the > > > victim's pants pockets. > > > > The FBI says that despite extensive work by its Cryptanalysis and > > > Racketeering Records Unit (CRRU), and the American Cryptogram > > > Association, the meanings of those two coded notes remain a mystery > > > and McCormick's murderer has never been found. One has to wonder > > > though, if the FBI can't figure this out, who can? But I digress. > > > > From the FBI: "The more than 30 lines of coded material use a > > > maddening variety of letters, numbers, dashes, and parentheses. > > > McCormick was a high school dropout, but he was able to read and write > > > and was said to be 'street smart.' According to members of his family, > > > McCormick had used such encrypted notes since he was a boy, but > > > apparently no one in his family knows how to decipher the codes, and > > > it's unknown whether anyone besides McCormick could translate his > > > secret language. Investigators believe the notes in McCormick's > > > pockets were written up to three days before his death." > > > > "Standard routes of cryptanalysis seem to have hit brick walls," said > > > CRRU chief Dan Olson in a statement. To move the case forward, > > > examiners need another sample of McCormick's coded system-or a similar > > > one-that might offer context to the mystery notes or allow valuable > > > comparisons to be made. Or, short of new evidence, Olson said, "Maybe > > > someone with a fresh set of eyes might come up with a brilliant new > > > idea." > > > > The FBI says it has always relied on public tips and other assistance > > > to solve crimes though breaking a code may represent a special > > > circumstance. > > > > For larger images of the notes go here. [LINK] > > > > If you have an idea how to break the code, have seen similar codes, or > > > have any information about the Ricky McCormick case, write to CRRU at > > > the following address: > > > > FBI Laboratory > > > Cryptanalysis and Racketeering Records Unit > > > 2501 Investigation Parkway > > > Quantico, VA 22135 > > > Attn: Ricky McCormick Case > > > > There is no reward being offered, just the knowledge that you may be > > > solving an intriguing murder mystery, the FBI stated. > > > No other information about the guy? It might help. If the note is of any use > > then people and places would be in it. If that is the case then it would > > help to know where he lived and some of the names of people he knows. > > > The note seems like it may not be just encrypted but a sort of > > compression(or rather shorthand/jargon) was used. Was the guy a drug dealer? > > It could be a list of "clients" or information about where he sold drugs(the > > numbers look like street addresses or amounts. > > > If these kinda notes were so common from this guy then surely the FBI should > > have many more? > > > Seems like the FBI could do more if they wanted it really solved... > > As to which crime was being committed, I'm going with numbers running > or loan sharking. ?There's no reason for any crook to keep any record > of any other crime, except prostitution, where phone books come in > handy. > > Thievery is not an honest business, and records of what went down, > where and with whom can only hurt you. ?Unless of course, it's a grand > list of felonies that he was using to blackmail the participants. > > But I can't see gathering that much info from blackmail. ?I always > thought it involved one guy blackmailing one victim. ?This would imply > a factory scale process, and he'd need some way to lure his prey into > the trap. > > Of course, that WOULD be a good way to get murdered. This is him http://img851.imageshack.us/i/4d93ac54b10bcimage.jpg/ From tjreedy at udel.edu Fri Apr 1 00:18:56 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 00:18:56 -0400 Subject: Extracting subsequences composed of the same character In-Reply-To: <4D95366D.9010706@tim.thechases.com> References: <4d952008$0$3943$426a74cc@news.free.fr> <4D95366D.9010706@tim.thechases.com> Message-ID: On 3/31/2011 10:20 PM, Tim Chase wrote: > On 03/31/2011 07:43 PM, candide wrote: >> "pyyythhooonnn ---> ++++" >> >> and you search for the subquences composed of the same character, here >> you get : >> >> 'yyy', 'hh', 'ooo', 'nnn', '---', '++++' > > Or, if you want to do it with itertools instead of the "re" module: > > >>> s = "pyyythhooonnn ---> ++++" > >>> from itertools import groupby > >>> [c*length for c, length in ((k, len(list(g))) for k, g in > groupby(s)) if length > 1] > ['yyy', 'hh', 'ooo', 'nnn', '---', '++++'] Slightly shorter: [r for r in (''.join(g) for k, g in groupby(s)) if len(r) > 1] -- Terry Jan Reedy From kushal.kumaran+python at gmail.com Fri Apr 1 01:33:31 2011 From: kushal.kumaran+python at gmail.com (Kushal Kumaran) Date: Fri, 1 Apr 2011 11:03:31 +0530 Subject: Behaviour of subprocess.Popen, ssh and nohup I don't understand In-Reply-To: <4D9523EF0200001B00016CE4@smtp.nfra.nl> References: <4D9523EF0200001B00016CE4@smtp.nfra.nl> Message-ID: On Fri, Apr 1, 2011 at 4:31 AM, Adriaan Renting wrote: > L.S. > > I have a problem that a background process that I'm trying to start with > subprocess.Popen gets interrupted and starts waiting for input no matter > what I try to do to have it continue to run. It happens when I run it > with nohup in the background. > I've tried to find a solution searching the internet, but found none. > I've written a small test script that reproduces the problem and hope > maybe here there is someone who can tell me what's going wrong. Any > suggestions are welcome. > > (renting)myhost> cat test.py > #!/usr/bin/python > # script to test subprocess problem > import subprocess, sys, time > > for f in range(3): > ?command = ["ssh", "-T", "localhost", "uptime"] > ?comm = subprocess.Popen(command, shell=False, stdin=None, > stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True) > ?print ?'1' > ?if comm.returncode: > ? ?print "error: %i" % (comm.return_code) > ?else: > ? ?print ?'2' > ? ?(output, output2) = comm.communicate(input=None) > ? ?print output > ? ?print output2 > ?print ?'3' > ?time.sleep(3) > > (renting)myhost> python --version > Python 2.5.2 > > (renting)myhost> nohup ./test.py -O2 & > [1] 15679 > > (renting)myhost> 1 > 2 > ?22:40:30 up 24 days, ?7:32, ?1 user, ?load average: 0.00, 0.00, 0.00 > > None > 3 > 1 > 2 > > [1] ?+ Suspended (tty input) ? ? ? ? ./test.py -O2 > (renting)myhost> fg > ./test.py -O2 > > ?22:40:35 up 24 days, ?7:32, ?1 user, ?load average: 0.00, 0.00, 0.00 > > None > 3 > 1 > 2 > ?22:40:56 up 24 days, ?7:32, ?1 user, ?load average: 0.00, 0.00, 0.00 > > None > 3 > > (renting)myhost> > > Now as you can see, it suspends on the second time through the for loop, > until I bring it to the foreground and hit . > What you don't see, is that I make it do this by pushing the arrow keys > a couple of times. The same happens when I would exit the shell, despite > it running with nohup. > I don't need to exit to make it suspend, any combination of a few random > keystrokes makes it do this. It seems depending on the timing though, > during the sleep(3) it seems to ignore me, only when subprocess is > actually running will it suspend if I generate keystrokes. > If the ssh command is executed without -T option it suspends directly, > so I think it's related to the ssh command. I log in with a > public/private key pair to avoid having to enter a password. > > Any suggestions are welcome, > What operating system is this? Try with stdin=open(os.devnull, 'rb') to the Popen call instead. Also, this seems to be similar: http://stackoverflow.com/questions/1365653/calling-fgets-on-popen-of-ssh-is-flushing-the-beginning-of-stdin-of-the-cal The "Suspended (tty input)" message means that a background process tried to read from stdin, so got suspended. This is part of the job control mechanism. -- regards, kushal From harrismh777 at charter.net Fri Apr 1 02:13:04 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 01 Apr 2011 01:13:04 -0500 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano wrote: > The difference between implementation and interface is > not specific to object-oriented code -- When I speak of implementation vs interface I am speaking from a strictly object oriented philosophy, as pedigree, from Grady Booch, whom I consider to be the father of Object Oriented Analysis and Design (Booch, OO A&D with apps, 1994). He makes this remarkable statement: "The interface of a class is the one place where we assert all of the assumptions that a client may make about any instances [objects] of the class; the implementation encapsulates details about which no client may make assumptions" (Booch, p50, 1994). The Class interface holds a "special" firmness which fosters the client relationship of trust and assumption, without which OOA&D is pointless. The interface of a Class must not change once advertised, and once in production. This is specific to OOA&D. Encapsulation of the abstractions must reside within the implementation about which no one may make assumptions. This is also where all of the "cruft" (if any) resides. Cruft never resides at the interface, only in the encapsulation of the Class abstractions, and only if the Class was poorly designed. To put my advice in MY other words, here are my two rules about Class interface based on Booch, but in terms that are mine, and which are way simpler to put into practice: Rule 1: Never change an advertised Class interface. Corollary 1)a The Class interface never encapsulates cruft. Corollary 1)b The Class implementation usually encapsulates cruft. Corollary 1)c Only the Class implementation may be changed. Rule 2: If an advertised Class interface must be changed to remove cruft, please re-read Rule #1, and review corollaries 1)a, 1)b, and 1)c. ---- As an aside, but in response to your straw man argument regarding obscure "cruft," none of the bickering regarding this cmp issue is about obscure code. We are discussing one of the primary methods of one of the primary Class objects are the lovely heart of Python--- the list.sort(). This is NOT obscure. Guido arbitrarily altered the interface to one of the MOST important Class objects in all of the Python language. This is not good, and it does violate the spirit of OOA&D. If the interface changes had been left to type promotion on integer divide, and the print() method, then folks would probably not be in such an uproar over 3x. But Guido over reached the bounds of credulity by altering a Class method that *many* people find useful, desirable, efficacious and easy... they use it and the love it (right or wrong). The client(s) are making assumptions about the List Class interface and they have an OOA&D right to do so... and they are left with their rear-ends handing out in the breeze because their assumptions are false. Not good. Kind regards, m harris From rosuav at gmail.com Fri Apr 1 02:30:08 2011 From: rosuav at gmail.com (Chris Angelico) Date: Fri, 1 Apr 2011 17:30:08 +1100 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 1, 2011 at 5:13 PM, harrismh777 wrote: > ? ?Corollary 1)a The Class interface never encapsulates cruft. Provably false. Even a well-designed interface, if it is asked to deal with a changing implementation and changing requirements, will eventually either acquire cruft, or be found too rigid to be of use. The only interface immune to this is the transparent interface (effectively: "just package up the parameters in a single string and pass it through"), which isn't really an interface at all, it just exposes something else. In everything else, cruft is a reality that must be dealt with. Chris Angelico From harrismh777 at charter.net Fri Apr 1 02:44:11 2011 From: harrismh777 at charter.net (harrismh777) Date: Fri, 01 Apr 2011 01:44:11 -0500 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> Message-ID: <0velp.864$YL5.58@newsfe05.iad> Terry Reedy wrote: > Python 3 was announced and as a mildly code breaking version at least 5 > years before it came out. I appreciate the spirit of your arguments overall, and I do not necessarily disagree with much of what you are saying. I would like to challenge you to see this from a little different perspective, if I may. There are two distinct ways for looking at this "mild code breakage," and it might be good to think about how we approach changes in the future based on an understanding of both perspectives, and consideration for the clients. In the possible perspective of the Python language developers 3x changes are mild (in fact, overall, probably even insignificant percentage-wise). Ok, we removed the cmp comparison keyword from list.sort(), made the print() method consistent with the rest of the language, and correctly promoted integer divide 1/2 to float so that the answer is something greater than zero! Fine. Looks like just a couple little changes, no big deal, stop your whining. The perspective of the Class client is something quite different. They do not look at the overall percentage of Python language definition that has changed (tiny percentage, right) they look at the overall percentage of their own projects that have just "broken" and need to be rewritten to accommodate the disruption in the advertised Class interface. And to the client-- these tiny changes are magna-bodacious! (nobbled thinking) You guys have changed integer divide---! the PRINT print() functionality is diff e r e n t ---! and for crying out loud.... you changed S O R T ( ) !!! I wonder if folks like google need to do in-place sorts over lists very often ...? I wonder how mnay Python scripts call the list.sort() method with the cmp keyword specified... ? (could it be thousands, or millions?) All the hoorah you guys are getting, as well all of this incessant bickering over cmp, is some of the answer to these questions. When you get ready to change an advertised Class interface in the future, please consider my interface rules (I gave them to Steven) and please take into account your client base---the ones who are making valid assumptions about your Class interfaces. Its easy, and its most considerate. king regards, m harris From timr at probo.com Fri Apr 1 03:19:12 2011 From: timr at probo.com (Tim Roberts) Date: Fri, 01 Apr 2011 00:19:12 -0700 Subject: call php function from python References: <0d2bf776-899c-4257-a78c-c24ac90f5747@s33g2000vbb.googlegroups.com> Message-ID: CrabbyPete wrote: > >I have a python script that automatically loads wordpress, up to the >point that it asks for the admin password. >that is a php function call > >function wp_install( $blog_title, $user_name, $user_email, $public, >$deprecated = '', $user_password = '' ) > >Is there a way to call this function from python? Are you running this script on the web server, or are you invoking this over a socket using something like urllib? If you are running remotely, then PHP does not exist. All you have are HTTP requests. You need to make yourself look exactly like a human being at a browser. Fortunately, that's not too hard. -- Tim Roberts, timr at probo.com Providenza & Boekelheide, Inc. From no.email at nospam.invalid Fri Apr 1 03:45:24 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Apr 2011 00:45:24 -0700 Subject: Guido rethinking removal of cmp from sort method References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7x8vvue7or.fsf@ruckus.brouhaha.com> Chris Angelico writes: > Provably false. Even a well-designed interface, if it is asked to deal > with a changing implementation and changing requirements, will > eventually either acquire cruft, or be found too rigid to be of use. What happens then is you define a new interface. In Microsoft-speak if the IWhatever interface needs an incompatible extension like new parameters, they introduce IWhatever2 which supports the new parameters. They change the implementation of IWhatever so it becomes a wrapper for IWhatever2 setting the new parameters to default values, to keep implementing the old behavior. Removing cmp certainly isn't the most disruptive change of Python 3, but it seems like the one with the least benefit. From eryksun at gmail.com Fri Apr 1 05:11:41 2011 From: eryksun at gmail.com (eryksun ()) Date: Fri, 1 Apr 2011 02:11:41 -0700 (PDT) Subject: A problem about ipython In-Reply-To: <43e40bbd-ae57-47dd-9e03-2d480278e4b6@j11g2000prn.googlegroups.com> Message-ID: <8530f617-ac64-46e4-8d02-ebfeb88d137e@glegroupsg2000goo.googlegroups.com> On Thursday, March 31, 2011 9:48:27 PM UTC-4, Vincent Ren wrote: > > when I run this(from Programming Python 3rd) in ipython, I'll > get a NameError: > .... > > /usr/lib/python2.6/profile.pyc in runctx(self, cmd, globals, locals) > 460 sys.setprofile(self.dispatcher) > 461 try: > --> 462 exec cmd in globals, locals > 463 finally: > 464 sys.setprofile(None) > > /usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in () > > NameError: name 'timer' is not defined > .... > What's going wrong here? Try this instead: profile.runctx('timer.test(100, settime.setops, set.Set)', globals=globals(), locals=locals()) From jeanmichel at sequans.com Fri Apr 1 05:54:06 2011 From: jeanmichel at sequans.com (Jean-Michel Pichavant) Date: Fri, 01 Apr 2011 11:54:06 +0200 Subject: Alias for an attribute defined in a superclass In-Reply-To: <787d36b9-e31d-4b61-a14e-770337cfc280@a11g2000pro.googlegroups.com> References: <87sju3ndjo.fsf@benfinney.id.au> <787d36b9-e31d-4b61-a14e-770337cfc280@a11g2000pro.googlegroups.com> Message-ID: <4D95A0BE.3040903@sequans.com> Raymond Hettinger wrote: > On Mar 31, 3:14 pm, Ben Finney wrote: > >> Howdy all, >> >> I want to inherit from a class, and define aliases for many of its >> attributes. How can I refer to ?the attribute that will be available by >> name ?spam? once this class is defined?? >> >> class Foo(object): >> def spam(self): >> pass >> >> def eggs(self): >> pass >> >> class Bar(Foo): >> beans = Foo.spam >> mash = Foo.eggs >> >> Is that the right way to do it? >> > > For methods, that will work just fine. For attributes, you will need > to make @property accessors that get and set the underlying attribute. > > > Raymond > For attributes you could also override __getattribute__ & __setattr__ to wrap Bar's names into Foo's names. Could work also for methods, but for methods your current idea is much more simple. class Foo(object): def __init__(self): self.spam = 'someSpam' self.eggs = 'fewEggs' def vanilla(self): return self.spam class Bar(Foo): _map = { 'beans': 'spam', 'mash': 'eggs', 'chocolate': 'vanilla', } def __getattribute__(self, attribute): getSafely = object.__getattribute__ _map = getSafely(self, '_map') if attribute in _map: return getSafely(self, _map[attribute]) else: return getSafely(self, attribute) Bar().chocolate() 'someSpam' Bar().mash 'fewEggs' JM From michael at stroeder.com Fri Apr 1 07:11:15 2011 From: michael at stroeder.com (=?ISO-8859-1?Q?Michael_Str=F6der?=) Date: Fri, 01 Apr 2011 13:11:15 +0200 Subject: New mailing list for python-ldap Message-ID: HI! The old SF mailing list python-ldap-dev was shut down today. I'd be happy to see you on the new mailing list for http://python-ldap.org under the umbrella of python.org. List info here: http://mail.python.org/mailman/listinfo/python-ldap All announcements, discussion and support related to python-ldap can be posted there. Ciao, Michael. From austin.bingham at gmail.com Fri Apr 1 07:36:52 2011 From: austin.bingham at gmail.com (Austin Bingham) Date: Fri, 1 Apr 2011 13:36:52 +0200 Subject: Compiling python without ssl? Message-ID: Is there any way to compile python (3.1.3, in case it matters) without ssl support? OpenSSL is on my system, and configure finds it, but I can't find a way to tell configure to explicitly ignore it. I need a version of python without ssl for trade compliance reasons (I don't make the dumb rules, I just follow 'em), and we used to be able to just remove the ssl module after the build. With more recent releases, though, this approach causes problems with e.g. hashlib. Ideally I'd like something like "configure --disable-ssl", but I can also do surgery on configure or something if that's what it takes. Thanks in advance! Austin From nirina.raseliarison at gmail.com Fri Apr 1 08:35:36 2011 From: nirina.raseliarison at gmail.com (nirinA) Date: Fri, 01 Apr 2011 15:35:36 +0300 Subject: py 2.7.1 & openssl In-Reply-To: <6ab0c9c7-b9da-4a7a-a146-d84172e67936@l2g2000prg.googlegroups.com> References: <84bb4467-97dd-4ed6-a2a0-dcbaf6904746@r4g2000prm.googlegroups.com> <6ab0c9c7-b9da-4a7a-a146-d84172e67936@l2g2000prg.googlegroups.com> Message-ID: hi, > Yes, _md5 is enabled but I get a very long list under > Failed to build these modules: > ... list of mostly all extension modules ... > This list was empty earlier. at some point, the compilation failed to detect needed headers or libraries files. i suggest you to try something simple in order to see what is wrong in the compilation step. first, when compiling openssl. your wrote in original post: > I installed openssl-1.0.0d.tar.gz on my RHEL 5 box using: > ./config --prefix=/usr/local --openssldir=/usr/local/openssl > shared zlib > make > sudo make install just try: ./config make make install and nothing else. do su root, when you install, not sudo. don't use any --prefix=xxx nor --openssldir=xxx. use the default location, that is /usr/local/ssl as this is the location where Python looks for ssl headers and libraries. don't use shared. Python uses static libraries and as far as i can tell, shared libraries are not supported yet on x86_64 platform. with openssl-1.0.0d, i think you don't even need to specify the -fPIC flag, but using it doesn't hurt. you also wrote: > And, the following files are created in /usr/local/lib64: > libssl.a, libssl.so, libcrypto.a, libcrypto.so. Also, the binary > openssl is created in the bin directory. these files aren't used at all, unless you change the setup.py file to build _ssl extension. i repeat: Python uses /usr/local/ssl directory (or /usr/contrib/ssl/) to look for ssl headers and libraries. secondly, when compiling Python: > Then I installed python 2.7.1 using > PYHOME=/usr/local/Python-2.7.1; export PYHOME > LD_RUN_PATH=$PYHOME/lib; export LD_RUN_PATH > LDFLAGS="-L /usr/local/lib64 -L /usr/local/lib"; export > LDFLAGS > CPPFLAGS="-I /usr/local/include -I /usr/local/include/ > openssl"; export CPPFLAGS > ./configure --enable-shared --prefix=$PYHOME > log_cfg 2>&1 > make > log_mk 2>&1 > sudo make install > log_mk_i 2>&1 try something simple instead of these messy configurations! just try: ./configure make make install if you want to install Python in a specific directory, e.g. /usr/local/Python-2.7.1 , use: make install DESTDIR=/usr/local/Python-2.7.1 and then, you play with: export LD_LIBRARY_PATH=/usr/local/Python-2.7.1/lib /usr/local/Python-2.7.1/bin/python if you really want to specify some libraries and include files, but usually you don't, Python is smart enough to find them, don't use : > LDFLAGS="-L /usr/local/lib64 -L /usr/local/lib"; export > LDFLAGS > CPPFLAGS="-I /usr/local/include -I /usr/local/include/ > openssl"; export CPPFLAGS pass them in the configuration line instead: CPPFLAGS="-I/usr/local/include/openssl" \ LDFLAGS="-L/usr/local/lib64" \ ./configure notice that there is no space between the -I or -L and the directory name. and the backslash to continue long line. finally, don't use sudo. try to log as root if possible. may be you cannot access some files needed for compilation as a simple user. and some LD*** and CPP*** flags are reset when you use sudo. hope this helps nirinA -- Simple is better than complex. From steve+comp.lang.python at pearwood.info Fri Apr 1 08:49:17 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2011 12:49:17 GMT Subject: In List Query -> None Case Sensitive? References: <4d951179$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: <4d95c9cd$0$29992$c3e8da3$5496439d@news.astraweb.com> On Fri, 01 Apr 2011 11:01:07 +1100, Chris Angelico wrote: > Microsoft Word is not the best > tool for... well, anything, probably. Since I raised the issue of MS Word, I should throw in a defense for it. After a break from using Word for about five years, when I exclusively used OpenOffice for word processing, I had an work project where I had to use Word extensively. I wouldn't say that Word is perfect by any means, but its usability is *much* more polished than OpenOffice Writer. I find myself cursing OpenOffice Writer for getting the little things wrong *all the time*, while Word gets them right nearly always, and only occasionally wrong. Word also has a deepness and richness of power that I've only just begun to use, but is quite simple once you know where to look. I don't know if Word is "the best" word processor, but it's surely the champion to beat. (Even if it does generate masses of bad HTML.) On the other hand, Excel's usability is a dog. Give me OpenOffice's spreadsheet any day. (In fairness, I haven't used OpenOffice 3 much, so perhaps it is better.) Anyway, these things are quite sensitive to tiny improvements and breakages in the user-interface between versions and platforms, so YMMV. -- Steven From mahalingamramu000 at gmail.com Fri Apr 1 08:50:31 2011 From: mahalingamramu000 at gmail.com (surya maha) Date: Fri, 1 Apr 2011 05:50:31 -0700 (PDT) Subject: EARN 1000 DOLLARS PER DAY - WITHOUT INVESTMENT - CLICK HERE Message-ID: <28262129-8cc3-4964-afb5-66479f7cacdd@j11g2000prn.googlegroups.com> http://earnforextoday.blogspot.com http://earnforextoday.blogspot.com http://earnforextoday.blogspot.com http://earnforextoday.blogspot.com http://earnforextoday.blogspot.com From nirina.raseliarison at gmail.com Fri Apr 1 08:55:56 2011 From: nirina.raseliarison at gmail.com (nirinA) Date: Fri, 01 Apr 2011 15:55:56 +0300 Subject: Compiling python without ssl? In-Reply-To: References: Message-ID: [Austin Bingham] > Is there any way to compile python (3.1.3, in case it matters) without > ssl support? OpenSSL is on my system, and configure finds it, but I > can't find a way to tell configure to explicitly ignore it. > > I need a version of python without ssl for trade compliance reasons (I > don't make the dumb rules, I just follow 'em), and we used to be able > to just remove the ssl module after the build. With more recent > releases, though, this approach causes problems with e.g. hashlib. > > Ideally I'd like something like "configure --disable-ssl", but I can > also do surgery on configure or something if that's what it takes. > Thanks in advance! > > Austin you can change or erase the list of include and library files related to ssl in setup.py before configuring. but, as you say, this may break hashlib. and probably the socket module, and may be other things, like idle. nirinA From Bryan.Fodness at itt.com Fri Apr 1 08:56:32 2011 From: Bryan.Fodness at itt.com (Fodness, Bryan C - GS) Date: Fri, 1 Apr 2011 08:56:32 -0400 Subject: Mathematical Operations on Array Message-ID: <3573139D2D5DBF468087E68083D59B2702F48FEC7E@USFWA1EXMBX4.itt.net> I am loading text into an array and would like to convert the values. from math import * from numpy import * from pylab import * data=loadtxt('raw.dat') mincos=degrees(acos(data[:,0])) minazi=degrees(data[:,1]) minthick=data[:,2]/0.006858 I am not sure why degrees() works, but acos() does not. I receive the following Traceback (most recent call last): File "C:\ test.py", line 6, in ? mincos=degrees(acos(float(data[:,0]))) TypeError: only length-1 arrays can be converted to Python scalars Can anyone tell me what I am doing wrong? ________________________________ This e-mail and any files transmitted with it may be proprietary and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender. Please note that any views or opinions presented in this e-mail are solely those of the author and do not necessarily represent those of ITT Corporation. The recipient should check this e-mail and any attachments for the presence of viruses. ITT accepts no liability for any damage caused by any virus transmitted by this e-mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: From steve+comp.lang.python at pearwood.info Fri Apr 1 08:57:11 2011 From: steve+comp.lang.python at pearwood.info (Steven D'Aprano) Date: 01 Apr 2011 12:57:11 GMT Subject: a basic bytecode to machine code compiler References: <4j7lp.5204$sS4.1784@newsfe11.iad> Message-ID: <4d95cba6$0$29992$c3e8da3$5496439d@news.astraweb.com> On Thu, 31 Mar 2011 18:33:36 -0400, Rouslan Korneychuk wrote: > I'm aware that PyPy already has a working JIT compiler, but I figure it > will be a long time before they have a version of Python that is ready > for everybody to use, so this could be useful in the mean time. PyPy is ready to use *now*, if you are happy writing code that targets Python 2.5 and don't need C extensions. [...] > What do people think? Would I be wasting my time going further with > this? Depends on what your ultimate aim is. If it is to learn things yourself, then it is never a waste of time to learn new things. If your aim is to get a good working project that you can be proud to put on your CV, then go right ahead. If your aim is to contribute to a Python compiler that will actually be used by people other than yourself, I'm not so sure... personally, I expect that PyPy is the future of Python optimizing compilers, but I could be wrong. I suggest you check out the competitors: Shedskin is a Python to C++ compiler; Psyco is a JIT specialising compiler; Nuitka claims to be a C++ implementation that compiles to machine code; Berp claims to be a Haskell implementation that does the same; Compyler claims to be a native x86 assembly compiler; UnPython claims to be an experimental Python to C compiler. Of the six, as far as I know only Shedskin and Psyco are widely used. Good luck, and remember: Release early, release often, and let the community know when you do! -- Steven From bryan.fodness at gmail.com Fri Apr 1 09:35:59 2011 From: bryan.fodness at gmail.com (Bryan.Fodness@gmail.com) Date: Fri, 1 Apr 2011 06:35:59 -0700 (PDT) Subject: Mathematical Operations on Array Message-ID: I am loading text into an array and would like to convert the values. from math import * from numpy import * from pylab import * data=loadtxt('raw.dat') mincos=degrees(acos(data[:,0])) minazi=degrees(data[:,1]) minthick=data[:,2]/0.006858 I am not sure why degrees() works, but acos() does not. I receive the following Traceback (most recent call last): File "C:\ test.py", line 6, in ? mincos=degrees(acos(float(data[:,0]))) TypeError: only length-1 arrays can be converted to Python scalars Can anyone tell me what I am doing wrong? From __peter__ at web.de Fri Apr 1 09:52:55 2011 From: __peter__ at web.de (Peter Otten) Date: Fri, 01 Apr 2011 15:52:55 +0200 Subject: Mathematical Operations on Array References: Message-ID: Bryan.Fodness at gmail.com wrote: > I am loading text into an array and would like to convert the values. > > from math import * > from numpy import * > from pylab import * > > data=loadtxt('raw.dat') > mincos=degrees(acos(data[:,0])) > minazi=degrees(data[:,1]) > minthick=data[:,2]/0.006858 > > I am not sure why degrees() works, but acos() does not. > > I receive the following > > Traceback (most recent call last): > File "C:\ test.py", line 6, in ? > mincos=degrees(acos(float(data[:,0]))) > TypeError: only length-1 arrays can be converted to Python scalars > > Can anyone tell me what I am doing wrong? Using star-imports. Among other things it makes it hard to keep track of where things are coming from: >>> from math import * >>> from numpy import * >>> degrees >>> acos >>> acos.__module__ 'math' >>> arccos From devivithyamaha at gmail.com Fri Apr 1 09:56:06 2011 From: devivithyamaha at gmail.com (devi vithya) Date: Fri, 1 Apr 2011 06:56:06 -0700 (PDT) Subject: DATING TIPS FOR GUYS - DATING FOR HOT GIRLS - FREE ONLINE CHATTING HERE Message-ID: http://datinggirls9.blogspot.com/ http://datinggirls9.blogspot.com/ http://datinggirls9.blogspot.com/ http://datinggirls9.blogspot.com/ http://datinggirls9.blogspot.com/ From bryan.fodness at gmail.com Fri Apr 1 10:00:31 2011 From: bryan.fodness at gmail.com (Bryan.Fodness@gmail.com) Date: Fri, 1 Apr 2011 07:00:31 -0700 (PDT) Subject: Mathematical Operations on Array References: Message-ID: <5964b78e-8791-4f3c-8d87-5caef177b28c@v8g2000yqb.googlegroups.com> On Apr 1, 9:52?am, Peter Otten <__pete... at web.de> wrote: > Bryan.Fodn... at gmail.com wrote: > > I am loading text into an array and would like to convert the values. > > > from math import * > > from numpy import * > > from pylab import * > > > data=loadtxt('raw.dat') > > mincos=degrees(acos(data[:,0])) > > minazi=degrees(data[:,1]) > > minthick=data[:,2]/0.006858 > > > I am not sure why degrees() ?works, but acos() does not. > > > I receive the following > > > Traceback (most recent call last): > > ? File "C:\ test.py", line 6, in ? > > ? ? mincos=degrees(acos(float(data[:,0]))) > > TypeError: only length-1 arrays can be converted to Python scalars > > > Can anyone tell me what I am doing wrong? > > Using star-imports. > > Among other things it makes it hard to keep track of where things are coming > from: > > >>> from math import * > >>> from numpy import * > >>> degrees > > >>> acos > > >>> acos.__module__ > 'math' > >>> arccos > > - Hide quoted text - > > - Show quoted text - Thank you. From not.my.email at somehing.com Fri Apr 1 10:04:46 2011 From: not.my.email at somehing.com (vm) Date: Fri, 1 Apr 2011 14:04:46 +0000 (UTC) Subject: Addition problems Message-ID: I'm analyzing some data in python. I have stumbled across unusual problem: I have the function... def fun1(params_used_below_except_lk_and_lk2): lk = 0.0 lk2 = 0.0 for raw_data, hist, freq in raw_data_hist_list: lk2 = lk2 + fun2(some_constants_and_params_from_this_scope) q = fun2(same_args_as_before) lk = lk + q print lk, lk2 For some set of input parameters, This function with specific input prints out the same constant twice (as expected): 15377.7424582 15377.7424582 (twice the same value) If I comment out lines q = fun2.... and lk = lk + q, fun1, with the same parameters, prints: 0.0 3.3469936856 First value is expected, but I cannot understand how come the second value is different in these two cases! Thanks in advance! fun1 source: def process_measurements_beta_lk(x, raw_data_hist_list): lk = 0.0 lk2 = 0.0 (p,q,loc,scale) = x for raw_data, hist, freq in raw_data_hist_list: lk2 = lk2 + get_beta_func_fit_quality_hist_lk('beta', (p,q,loc,scale), raw_data, hist) # q = get_beta_func_fit_quality_hist_lk('beta',(p,q,loc,scale), raw_data, hist) # lk = lk + q print lk, lk2 retrun lk From jtim.arnold at gmail.com Fri Apr 1 10:25:17 2011 From: jtim.arnold at gmail.com (Tim) Date: Fri, 1 Apr 2011 07:25:17 -0700 (PDT) Subject: python2.7.1 freebsd development version Message-ID: <879683e0-d002-41b1-8400-f58d096a699d@f18g2000yqd.googlegroups.com> hi, I can't seem to find the development version of python2.7.1; maybe there isn't one any longer, but according to this post, there was a bug in the configure script that affects freebsd machines; the patch to fix it was made, but I think I'm not picking that fix up. http://bugs.python.org/file19836/freebsd_ldshared.patch Where should I look for the updated version? thanks, --Tim Arnold From kamal2222ahmed at gmail.com Fri Apr 1 10:48:20 2011 From: kamal2222ahmed at gmail.com (kahmed) Date: Fri, 1 Apr 2011 07:48:20 -0700 (PDT) Subject: ValueError: need more than 2 values to unpack Message-ID: When running nosetests i get error: test_many_errors.test_value_two ... SKIP: (, ValueError(), ) test_many_errors.test_good_one ... ok test_many_errors.test_good_two ... ok Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/Current/bin/ nosetests", line 10, in sys.exit(run_exit()) File "/Library/Frameworks/Python.framework/Versions/6.3/lib/ python2.6/site-packages/nose/core.py", line 117, in __init__ **extra_args) File "/Library/Frameworks/Python.framework/Versions/6.3/lib/ python2.6/unittest.py", line 817, in __init__ self.runTests() File "/Library/Frameworks/Python.framework/Versions/6.3/lib/ python2.6/site-packages/nose/core.py", line 196, in runTests result = self.testRunner.run(self.test) File "/Library/Frameworks/Python.framework/Versions/6.3/lib/ python2.6/site-packages/nose/core.py", line 63, in run result.printErrors() File "/Library/Frameworks/Python.framework/Versions/6.3/lib/ python2.6/site-packages/nosetrim-0.1.dev_r13-py2.6.egg/nosetrim/ nosetrim.py", line 136, in printErrors lambda i: get_error_count(self._error_lookup, i)) File "/Library/Frameworks/Python.framework/Versions/6.3/lib/ python2.6/site-packages/nosetrim-0.1.dev_r13-py2.6.egg/nosetrim/ nosetrim.py", line 142, in printErrorList for test, err, capt in errors: ValueError: need more than 2 values to unpack / --------------------- >> end captured stdout << ---------------------- line 142 is: "for test, err, capt in errors:" Here is the code snippet: def get_error_count(lookup, index): if index in lookup: ename = lookup[index] return _errormap[ename] self.printErrorList('ERROR', self.errors, lambda i: get_error_count(self._error_lookup, i)) self.printErrorList('FAIL', self.failures, lambda i: get_error_count(self._failure_lookup, i)) def printErrorList(self, flavor, errors, get_error_count): i = 0 for test, err, capt in errors: self.stream.writeln(self.separator1) self.stream.writeln("%s: %s" % (flavor,self.getDescription(test))) self.stream.writeln(self.separator2) self.stream.writeln("%s" % err) #count = get_error_count(i) count = get_error_count(i) if count > 1: self.stream.writeln(self.separator2) self.stream.writeln("+ %s more" % (count-1)) self.stream.writeln(self.separator2) if capt is not None and len(capt): self.stream.writeln(ln('>> begin captured stdout <<')) self.stream.writeln(capt) self.stream.writeln(ln('>> end captured stdout <<')) i += 1 How do i resolve this ? Thanks, -Kamal. From david250 at videotron.ca Fri Apr 1 10:54:13 2011 From: david250 at videotron.ca (David Bernier) Date: Fri, 01 Apr 2011 10:54:13 -0400 Subject: FBI wants public help solving encrypted notes from murder mystery In-Reply-To: References: Message-ID: haha doh wrote: > On Mar 31, 3:15 pm, Joe Snodgrass wrote: [...] >> As to which crime was being committed, I'm going with numbers running >> or loan sharking. There's no reason for any crook to keep any record >> of any other crime, except prostitution, where phone books come in >> handy. >> >> Thievery is not an honest business, and records of what went down, >> where and with whom can only hurt you. Unless of course, it's a grand >> list of felonies that he was using to blackmail the participants. >> >> But I can't see gathering that much info from blackmail. I always >> thought it involved one guy blackmailing one victim. This would imply >> a factory scale process, and he'd need some way to lure his prey into >> the trap. >> >> Of course, that WOULD be a good way to get murdered. > This is him > http://img851.imageshack.us/i/4d93ac54b10bcimage.jpg/ True indeed! , according to a story posted on March 30 on the website of the St. Louis Post-Dispatch: < http://www.stltoday.com/news/local/metro/ad567e00-5b13-11e0-8ed4-00127992bc8b.html> . That web page has a link to a 1999 article on the discovery of the body: < http://www.stltoday.com/news/article_bcc02074-5b1a-11e0-b199-0017a4a78c22.html > . An officer with the local Major Case Squad unit is quoted there. I quote from the 1999 story: << "We cannot find any motive for his death, " he said. "We're not absolutely sure that this is a homicide." >> . David Bernier From mail at timgolden.me.uk Fri Apr 1 10:55:50 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 01 Apr 2011 15:55:50 +0100 Subject: python2.7.1 freebsd development version In-Reply-To: <879683e0-d002-41b1-8400-f58d096a699d@f18g2000yqd.googlegroups.com> References: <879683e0-d002-41b1-8400-f58d096a699d@f18g2000yqd.googlegroups.com> Message-ID: <4D95E776.6000409@timgolden.me.uk> On 01/04/2011 15:25, Tim wrote: > hi, > I can't seem to find the development version of python2.7.1; maybe > there isn't one any longer, but according to this post, there was a > bug in the configure script that affects freebsd machines; the patch > to fix it was made, but I think I'm not picking that fix up. > http://bugs.python.org/file19836/freebsd_ldshared.patch > > Where should I look for the updated version? This is the Mercurial repo: http://hg.python.org/cpython/ Look for the 2.7 named branch which tracks 2.7.x development TJG From kb1pkl at aim.com Fri Apr 1 11:07:15 2011 From: kb1pkl at aim.com (Corey Richardson) Date: Fri, 01 Apr 2011 11:07:15 -0400 Subject: The Magick of __call__ (Or, Digging Deeper Than I Ought To) Message-ID: <4D95EA23.10802@aim.com> All callables (things you can foo(bar)) are really just objects that implement the __call__ method, as far as I understand. Well then, that would appear to make methods themselves callable, so let's do a little playing around... lavos at lavos ~ $ python Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... def __call__(self, foo): ... self.name(foo) ... def name(self, bar): ... print "Name: {0}".format(bar) ... >>> foo = Foo() >>> foo("Me!") Name: Me! Ok, nothing out of the ordinary. But what happens if.... >>> foo.name.__call__("Corey") Name: Corey >>> eval("foo.name" + (".__call__" * 9001) + "('Corey')") Name: Corey >>> foo.name.__call__.__call__.__call__.__call__.__call__("Corey") Name: Corey >>> eval("foo.name" + (".__call__" * 100000000) + "('Corey')") ^C^Z [1]+ Stopped python (Which was then followed by a ps aux and a kill -9...it ate all my memory and then moved on to my swap.) I've been told that much magick lies in the CALL_FUNCTION bytecode, and that if I really cared I could look at ceval.c. I don't speak enough C or know enough of Python's C API for it to be of any use (yes I looked!). Would looking at something such as PyPy's version of it be good for me / does anyone else have insights? -- Corey Richardson From robert.kern at gmail.com Fri Apr 1 11:16:38 2011 From: robert.kern at gmail.com (Robert Kern) Date: Fri, 01 Apr 2011 10:16:38 -0500 Subject: A problem about ipython In-Reply-To: <43e40bbd-ae57-47dd-9e03-2d480278e4b6@j11g2000prn.googlegroups.com> References: <43e40bbd-ae57-47dd-9e03-2d480278e4b6@j11g2000prn.googlegroups.com> Message-ID: On 3/31/11 8:48 PM, Vincent Ren wrote: > Hey, everyone, I'm trying to use ipython recently. It's very nice, > however, when I run this(from Programming Python 3rd) in ipython, I'll > get a NameError: > > > In [1]: import settime, timer, set > > In [2]: import profile > > In [3]: profile.run('timer.test(100, settime.setops, set.Set)') > --------------------------------------------------------------------------- > NameError Traceback (most recent call > last) > > /home/vincent/hacking/python/ in() > > /usr/lib/python2.6/profile.pyc in run(statement, filename, sort) > 68 prof = Profile() > 69 try: > ---> 70 prof = prof.run(statement) > 71 except SystemExit: > 72 pass > > /usr/lib/python2.6/profile.pyc in run(self, cmd) > 454 import __main__ > 455 dict = __main__.__dict__ > --> 456 return self.runctx(cmd, dict, dict) > 457 > 458 def runctx(self, cmd, globals, locals): > > /usr/lib/python2.6/profile.pyc in runctx(self, cmd, globals, locals) > 460 sys.setprofile(self.dispatcher) > 461 try: > --> 462 exec cmd in globals, locals > 463 finally: > 464 sys.setprofile(None) > > /usr/lib/pymodules/python2.6/IPython/FakeModule.pyc in() > > NameError: name 'timer' is not defined In order to support pickling and its %run feature, IPython makes a fake __main__ module. It looks like profile.run() explicitly imports __main__ to try to run the statement there. Honestly, it's been a thorn in our side for a long time, but it's a confusing bit of the code. Most interactive shells actually written in Python are going to have a similar need to do a workaround, since they already have a __main__. The regular shell is not written in Python, so it has no problem. You will want to ask on the IPython list for future IPython questions. http://mail.scipy.org/mailman/listinfo/ipython-user -- 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 From rosuav at gmail.com Fri Apr 1 11:17:54 2011 From: rosuav at gmail.com (Chris Angelico) Date: Sat, 2 Apr 2011 02:17:54 +1100 Subject: The Magick of __call__ (Or, Digging Deeper Than I Ought To) In-Reply-To: <4D95EA23.10802@aim.com> References: <4D95EA23.10802@aim.com> Message-ID: On Sat, Apr 2, 2011 at 2:07 AM, Corey Richardson wrote: > All callables (things you can foo(bar)) are really just objects that > implement the __call__ method, as far as I understand. Well then, that > would appear to make methods themselves callable, so let's do a little > playing around... Interesting. >>> def Foo(): pass >>> Foo >>> Foo.__call__ >>> Foo.__call__.__call__ >>> Foo.__call__.__call__.__call__ I'd have thought that it would simply use Foo.__call__ == Foo, for simplicity. It's not. >>> a=[Foo] >>> a.append(a[-1].__call__) # repeat above line as many times as desired - builds a list of the recursion >>> a[-1]==a[-2] False So at no point does it ever actually cycle onto itself. >>> import sys >>> [sys.getsizeof(q) for q in a] [60, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32] The function object takes 60 bytes, everything else 32. >>> [q.__hash__() for q in a] [18502128, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592, 10666040, 29287592] None of the elements compare equal to each other, but apparently there's only two hash values possible for them! Fascinating. I don't know that it's any use, but fascinating! ChrisA From markrrivet at aol.com Fri Apr 1 11:29:10 2011 From: markrrivet at aol.com (Manatee) Date: Fri, 1 Apr 2011 08:29:10 -0700 (PDT) Subject: PyVISA Message-ID: <70adf37c-d18a-404b-8127-6c870508d196@a17g2000yqn.googlegroups.com> I have unpacked the PyVISA files into the Python/lib/site-packages dir and from the IDLE GUI I get and error import visa Traceback (most recent call last): File "", line 1, in import visa ImportError: No module named visa There must be more to just putting the files in the correct directory. Need help configuring PyVISA to work. My ultimate goal is to control electronic instruments with Python through visa. From nagle at animats.com Fri Apr 1 11:31:19 2011 From: nagle at animats.com (John Nagle) Date: Fri, 01 Apr 2011 08:31:19 -0700 Subject: ValueError: need more than 2 values to unpack In-Reply-To: References: Message-ID: <4d95efc3$0$10578$742ec2ed@news.sonic.net> On 4/1/2011 7:48 AM, kahmed wrote: > > line 142 is: > > "for test, err, capt in errors:" Somewhere in "errors" is a value that is not of length 3. Try this to find out what's wrong: for errorentry in errors : try : (test, err, capt) = errorentry # try to unpack except ValueError as message : # unpack failed raise(ValueError("%s: bogus entry in 'errors': %s" % (message, repr(errorentry)))) ... John Nagle From jtim.arnold at gmail.com Fri Apr 1 11:34:53 2011 From: jtim.arnold at gmail.com (Tim) Date: Fri, 1 Apr 2011 08:34:53 -0700 (PDT) Subject: python2.7.1 freebsd development version References: <879683e0-d002-41b1-8400-f58d096a699d@f18g2000yqd.googlegroups.com> Message-ID: <28d89f62-79e4-4bb3-854d-905a6f66bdef@dr5g2000vbb.googlegroups.com> On Apr 1, 10:55?am, Tim Golden wrote: > On 01/04/2011 15:25, Tim wrote: > > > hi, > > I can't seem to find the development version of python2.7.1; maybe > > there isn't one any longer, but according to this post, there was a > > bug in the configure script that affects freebsd machines; the patch > > to fix it was made, but I think I'm not picking that fix up. > >http://bugs.python.org/file19836/freebsd_ldshared.patch > > > Where should I look for the updated version? > > This is the Mercurial repo: > > ? ?http://hg.python.org/cpython/ > > Look for the 2.7 named branch which tracks 2.7.x development ? ? > > TJG hi Tim, thanks -- just what I was looking for, just couldn't find it on my own at all! --T From hwfwguy at gmail.com Fri Apr 1 11:38:27 2011 From: hwfwguy at gmail.com (Brad) Date: Fri, 1 Apr 2011 08:38:27 -0700 (PDT) Subject: Python CPU Message-ID: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Hi All, I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL or Verilog? -Brad From stefan_ml at behnel.de Fri Apr 1 11:45:39 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 01 Apr 2011 17:45:39 +0200 Subject: a basic bytecode to machine code compiler In-Reply-To: <4d95cba6$0$29992$c3e8da3$5496439d@news.astraweb.com> References: <4j7lp.5204$sS4.1784@newsfe11.iad> <4d95cba6$0$29992$c3e8da3$5496439d@news.astraweb.com> Message-ID: Steven D'Aprano, 01.04.2011 14:57: > I suggest you check out the competitors: > > Shedskin is a Python to C++ compiler; > Psyco is a JIT specialising compiler; > Nuitka claims to be a C++ implementation that compiles to machine code; > Berp claims to be a Haskell implementation that does the same; > Compyler claims to be a native x86 assembly compiler; > UnPython claims to be an experimental Python to C compiler. > > > Of the six, as far as I know only Shedskin and Psyco are widely used. Erm, yes, right. If you want to exclude Cython, which arguably is the only static Python compiler that actually has a large user base, then those may really be the only two that are widely used. Except that Psyco is certainly being used a lot more often than Shedskin, mainly because it actually allows you to execute Python code. Stefan From mail at timgolden.me.uk Fri Apr 1 11:49:18 2011 From: mail at timgolden.me.uk (Tim Golden) Date: Fri, 01 Apr 2011 16:49:18 +0100 Subject: python2.7.1 freebsd development version In-Reply-To: <28d89f62-79e4-4bb3-854d-905a6f66bdef@dr5g2000vbb.googlegroups.com> References: <879683e0-d002-41b1-8400-f58d096a699d@f18g2000yqd.googlegroups.com> <28d89f62-79e4-4bb3-854d-905a6f66bdef@dr5g2000vbb.googlegroups.com> Message-ID: <4D95F3FE.8000107@timgolden.me.uk> On 01/04/2011 16:34, Tim wrote: > On Apr 1, 10:55 am, Tim Golden wrote: >> On 01/04/2011 15:25, Tim wrote: >> >>> hi, >>> I can't seem to find the development version of python2.7.1; maybe >>> there isn't one any longer, but according to this post, there was a >>> bug in the configure script that affects freebsd machines; the patch >>> to fix it was made, but I think I'm not picking that fix up. >>> http://bugs.python.org/file19836/freebsd_ldshared.patch >> >>> Where should I look for the updated version? >> >> This is the Mercurial repo: >> >> http://hg.python.org/cpython/ >> >> Look for the 2.7 named branch which tracks 2.7.x development >> >> TJG > > hi Tim, thanks -- just what I was looking for, just couldn't find it > on my own at all! This is probably the best starting point (recently published): http://docs.python.org/devguide/ (first hit for: Python development) Look down that page is "Source code" TJG From yashwinkanchan at gmail.com Fri Apr 1 11:52:43 2011 From: yashwinkanchan at gmail.com (Yashwin Kanchan) Date: Fri, 1 Apr 2011 16:52:43 +0100 Subject: PyVISA In-Reply-To: <70adf37c-d18a-404b-8127-6c870508d196@a17g2000yqn.googlegroups.com> References: <70adf37c-d18a-404b-8127-6c870508d196@a17g2000yqn.googlegroups.com> Message-ID: Hi Have you installed the module after unzipping it? python setup.py install Got it from the README file in the downloaded tar. Regards Yashwin Kanchan On 1 April 2011 16:29, Manatee wrote: > I have unpacked the PyVISA files into the Python/lib/site-packages dir > and from the IDLE GUI I get and error > > import visa > > Traceback (most recent call last): > File "", line 1, in > import visa > ImportError: No module named visa > > > > There must be more to just putting the files in the correct directory. > Need help configuring PyVISA to work. > My ultimate goal is to control electronic instruments with Python > through visa. > -- > http://mail.python.org/mailman/listinfo/python-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jkn_gg at nicorp.f9.co.uk Fri Apr 1 11:59:00 2011 From: jkn_gg at nicorp.f9.co.uk (jkn) Date: Fri, 1 Apr 2011 08:59:00 -0700 (PDT) Subject: Python CPU References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: <0ab0f106-de49-4925-99ed-8e395b95795b@dr5g2000vbb.googlegroups.com> On Apr 1, 4:38?pm, Brad wrote: > Hi All, > > I've heard of Java CPUs. And Forth CPUs as well, I suspect ;-) > Has anyone implemented a Python CPU in VHDL > or Verilog? > I don't think so - certainly not in recent memory. If you look at the documentation for the python byte code, for example: http://docs.python.org/release/2.5.2/lib/bytecodes.html you can see why. It starts off nicely enough, and then ... HTH J^n From eryksun at gmail.com Fri Apr 1 12:34:58 2011 From: eryksun at gmail.com (eryksun ()) Date: Fri, 1 Apr 2011 09:34:58 -0700 (PDT) Subject: PyVISA In-Reply-To: <70adf37c-d18a-404b-8127-6c870508d196@a17g2000yqn.googlegroups.com> Message-ID: <57ebc34d-40bf-41c4-a4dc-89f0ec43418d@glegroupsg2000goo.googlegroups.com> On Friday, April 1, 2011 11:29:10 AM UTC-4, Manatee wrote: > I have unpacked the PyVISA files into the Python/lib/site-packages dir > and from the IDLE GUI I get and error > > import visa > > Traceback (most recent call last): > File " > ", line 1, in > import visa > ImportError: No module named visa > > > There must be more to just putting the files in the correct directory. > Need help configuring PyVISA to work. > My ultimate goal is to control electronic instruments with Python > through visa. If you're on Windows, they have a win32 executable installer available on SourceForge. Otherwise you can just easy_install the egg. http://sourceforge.net/projects/pyvisa/files/PyVISA/1.3/ You'll also need a VISA library (.dll or .so file) for your GPIB adapter. From nobody at nowhere.com Fri Apr 1 12:52:11 2011 From: nobody at nowhere.com (Nobody) Date: Fri, 01 Apr 2011 17:52:11 +0100 Subject: Python CPU References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: On Fri, 01 Apr 2011 08:38:27 -0700, Brad wrote: > I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL > or Verilog? Java is a statically-typed language which makes a distinction between primitive types (bool, int, double, etc) and objects. Python is a dynamically-typed language which makes no such distinction. Even something as simple as "a + b" can be a primitive addition, a bigint addition, a call to a.__add__(b) or a call to b.__radd__(a), depending upon the values of a and b (which can differ for different invocations of the same code). This is one of the main reasons that statically-typed languages exist, and are used for most production software. From tjreedy at udel.edu Fri Apr 1 12:59:05 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 12:59:05 -0400 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: <7x8vvue7or.fsf@ruckus.brouhaha.com> References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> <7x8vvue7or.fsf@ruckus.brouhaha.com> Message-ID: On 4/1/2011 3:45 AM, Paul Rubin wrote: > Removing cmp certainly isn't the most disruptive change of Python 3, That was almost certainly the ascii to unicode switch for strings. It is still not quite complete in 3.2 but should be pretty well ironed out in 3.3. > but it seems like the one with the least benefit. Since the set of changes was finite, there *must* be (at least) one with the lowest benefit/cost ratio. The removal of list.sort(cmp) may well be that one. Certainly, reasonable people can disagree as to whether the ratio is above or below 1.0. If cmp had not been removed, some other change would have been the worst in this respect, and possibly the subject of a thread like this. -- Terry Jan Reedy From stefan_ml at behnel.de Fri Apr 1 13:00:53 2011 From: stefan_ml at behnel.de (Stefan Behnel) Date: Fri, 01 Apr 2011 19:00:53 +0200 Subject: Python CPU In-Reply-To: References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: Nobody, 01.04.2011 18:52: > Java is a statically-typed language which makes a distinction between > primitive types (bool, int, double, etc) and objects. Python is a > dynamically-typed language which makes no such distinction. Even something > as simple as "a + b" can be a primitive addition, a bigint addition, a > call to a.__add__(b) or a call to b.__radd__(a), depending upon the values > of a and b (which can differ for different invocations of the same code). > > This is one of the main reasons that statically-typed languages exist, and > are used for most production software. I doubt that the reason they are "used for most production software" is a technical one. Stefan From vijay.nori at gmail.com Fri Apr 1 13:03:08 2011 From: vijay.nori at gmail.com (V N) Date: Fri, 1 Apr 2011 10:03:08 -0700 (PDT) Subject: py 2.7.1 & openssl References: <84bb4467-97dd-4ed6-a2a0-dcbaf6904746@r4g2000prm.googlegroups.com> <6ab0c9c7-b9da-4a7a-a146-d84172e67936@l2g2000prg.googlegroups.com> Message-ID: I tried all your suggestions. No success. On Apr 1, 8:35?am, nirinA wrote: > hi, > > > Yes, _md5 is enabled but I get a very long list under > > ?Failed to build these modules: > > ... list of mostly all extension modules ... > > This list was empty earlier. > > at some point, the compilation failed to detect > needed headers or libraries files. > i suggest you to try something simple in order to > see ?what is wrong in the compilation step. From tjreedy at udel.edu Fri Apr 1 13:06:03 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 13:06:03 -0400 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On 4/1/2011 2:13 AM, harrismh777 wrote: > When I speak of implementation vs interface I am speaking from a > strictly object oriented philosophy, as pedigree, from Grady Booch, whom > I consider to be the father of Object Oriented Analysis and Design > (Booch, OO A&D with apps, 1994). Python is object based but not object oriented in the Booch sense. > The Class interface holds a "special" firmness which fosters the client > relationship of trust and assumption, without which OOA&D is pointless. > The interface of a Class must not change once advertised, and once in > production. This is specific to OOA&D. Right, and Python is not OOA&D based. > Never change an advertised Class interface. In Python, class interfaces are no more sacred than module or function interfaces. If one takes 'no interface change' literally, then Python would have to be frozen. Even bug fixes change a defacto interface. If you want frozon, stick with one particular release. There are lots available. -- Terry Jan Reedy From debatem1 at gmail.com Fri Apr 1 13:12:24 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 1 Apr 2011 10:12:24 -0700 Subject: Python CPU In-Reply-To: References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: On Fri, Apr 1, 2011 at 10:00 AM, Stefan Behnel wrote: > Nobody, 01.04.2011 18:52: >> >> Java is a statically-typed language which makes a distinction between >> primitive types (bool, int, double, etc) and objects. Python is a >> dynamically-typed language which makes no such distinction. Even something >> as simple as "a + b" can be a primitive addition, a bigint addition, a >> call to a.__add__(b) or a call to b.__radd__(a), depending upon the values >> of a and b (which can differ for different invocations of the same code). >> >> This is one of the main reasons that statically-typed languages exist, and >> are used for most production software. > > I doubt that the reason they are "used for most production software" is a > technical one. I also suspect that there's some confusion between duck typing and typelessness going on here. Geremy Condra From drsalists at gmail.com Fri Apr 1 13:29:27 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 1 Apr 2011 10:29:27 -0700 Subject: Python CPU In-Reply-To: References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: On Fri, Apr 1, 2011 at 10:00 AM, Stefan Behnel wrote: > Nobody, 01.04.2011 18:52: > > Java is a statically-typed language which makes a distinction between >> primitive types (bool, int, double, etc) and objects. Python is a >> dynamically-typed language which makes no such distinction. Even something >> as simple as "a + b" can be a primitive addition, a bigint addition, a >> call to a.__add__(b) or a call to b.__radd__(a), depending upon the values >> of a and b (which can differ for different invocations of the same code). >> >> This is one of the main reasons that statically-typed languages exist, and >> are used for most production software. >> > > I doubt that the reason they are "used for most production software" is a > technical one. > > Agreed. In school, I was taught by a VHDL expert that the distinction between what gets done in hardware and what gets down in software is largely arbitrary - other than hardware often being faster than software, and hardware being less mutable than software. Lisp machines exist, or at least did at one time - from there, a Python machine doesn't seem much of stretch. -------------- next part -------------- An HTML attachment was scrubbed... URL: From prog at vtr.net Fri Apr 1 14:03:59 2011 From: prog at vtr.net (craf) Date: Fri, 01 Apr 2011 15:03:59 -0300 Subject: Another location of the PyGTK tutorial Message-ID: <1301681039.9363.2.camel@cristian-desktop> Hi. Anyone know if the pygtk tutorial that was in this direction http://www.learnpygtk.org/pygtktutorial/index.html, can be located elsewhere. Regards. Cristian From gd.usenet at spamfence.net Fri Apr 1 14:05:55 2011 From: gd.usenet at spamfence.net (=?UTF-8?Q?G=C3=BCnther?= Dietrich) Date: Fri, 01 Apr 2011 20:05:55 +0200 Subject: PyVISA References: <70adf37c-d18a-404b-8127-6c870508d196@a17g2000yqn.googlegroups.com> Message-ID: Manatee wrote: >I have unpacked the PyVISA files into the Python/lib/site-packages dir >and from the IDLE GUI I get and error > >import visa > >Traceback (most recent call last): > File "", line 1, in > import visa >ImportError: No module named visa > > > >There must be more to just putting the files in the correct directory. Yes, there is more: - DON'T unpack the files into any site-packages folder. If you already have done it, remove them. - Unpack the PyVISA archive to any other folder. - On the command line, change into the PyVISA folder. There you should find - among others - the two files setup.py and setup.cfg (at least if you use PyVISA-1.3.tar.gz). - Now, it depends on what variant of python you use and want to install PyVISA for and on the configuration of your PYTHONPATH rsp. sys.path and the folders they point to. You can simply try: 'sudo python ./setup install' If you are lucky, that's it. If not, you have to decide, where the installation script has to put the files to. For example, for my python 2.6, I chose '/Library/Frameworks/Python.framework/Versions/2.6/'. In this path, there is a folder 'lib/site-packages', which is pointed to by sys.path, and where .pth files are evaluated. - Edit the file setup.cfg. Near the end, in section '[install]', you will find the line 'prefix=/usr'. Replace the '/usr' by your chosen path. - Save the file and retry the install (see above). Best regards, G?nther From emile at fenx.com Fri Apr 1 14:28:22 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 01 Apr 2011 11:28:22 -0700 Subject: Python CPU In-Reply-To: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: On 4/1/2011 8:38 AM Brad said... > Hi All, > > I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL > or Verilog? > > -Brad http://code.google.com/p/python-on-a-chip/ Emile From emile at fenx.com Fri Apr 1 14:35:44 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 01 Apr 2011 11:35:44 -0700 Subject: Python CPU In-Reply-To: References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: On 4/1/2011 11:28 AM Emile van Sebille said... > On 4/1/2011 8:38 AM Brad said... >> Hi All, >> >> I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL >> or Verilog? >> >> -Brad > > > http://code.google.com/p/python-on-a-chip/ Sorry - wrong url in the cut'n paste buffer - http://tsheffler.com/software/python/ > > Emile > > From ott at mirix.org Fri Apr 1 14:37:35 2011 From: ott at mirix.org (Matthias-Christian Ott) Date: Fri, 1 Apr 2011 20:37:35 +0200 Subject: Location of data files Message-ID: <20110401183735.GA2276@qp> Hi, I want to include data files with a python package. With distutils it seems common to specifiy these files in the data_files argument with a non-portable location (e.g. data_files=[('share/example', 'icon.png')]). Another approach is to include the file in the Python module of the package (e.g. example/data) and specify the submodule in package_data argument and load them via pkgutil or pkg_ressources. This method seems portable, but doesn't allow customisation and doesn't conform to the FHS. What is the recommended way to allow easy platform-specific packaging (e.g. data files are installed to /usr/share when requested), portability and customisation (i.e. data files can be replaced by the user or alternative locations can be specified)? Regards, Matthias-Christian From tjreedy at udel.edu Fri Apr 1 14:57:48 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 14:57:48 -0400 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: <7x8vvue7or.fsf@ruckus.brouhaha.com> References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> <7x8vvue7or.fsf@ruckus.brouhaha.com> Message-ID: On 4/1/2011 3:45 AM, Paul Rubin wrote: > What happens then is you define a new interface. Like key= versus cmp= > In Microsoft-speak if > the IWhatever interface needs an incompatible extension like new > parameters, they introduce IWhatever2 which supports the new parameters. > They change the implementation of IWhatever so it becomes a wrapper for > IWhatever2 setting the new parameters to default values, to keep > implementing the old behavior. If cmp had been left (or were reinstated) but its implementation changed internally to use cmp_to_key to make it a wrapper for key, you would be happy? 2to3 could probably gain a fixer to change .sort(cmp=f) # to import functools import cmp_to_key .sort(key=functools.cmp_to_key(f)) I know some would not like this because interface change is not their real concern. -- Terry Jan Reedy From tjreedy at udel.edu Fri Apr 1 15:13:54 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 15:13:54 -0400 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: <0velp.864$YL5.58@newsfe05.iad> References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <0velp.864$YL5.58@newsfe05.iad> Message-ID: On 4/1/2011 2:44 AM, harrismh777 wrote: > Terry Reedy wrote: >> Python 3 was announced and as a mildly code breaking version at least 5 >> years before it came out. > > I appreciate the spirit of your arguments overall, and I do not > necessarily disagree with much of what you are saying. I would like to > challenge you to see this from a little different perspective, if I may. I have, but I consider your perspective, as I understand it, unrealistic > There are two distinct ways for looking at this "mild code breakage," > and it might be good to think about how we approach changes in the > future based on an understanding of both perspectives, and consideration > for the clients. Guido especially and the other developers, generally, try to balance benefit and cost. What some may not know is that we consider benefits over several years, and benefits to future users as well as current users. We hope and expect the former to outnumber the latter in not too many years. The decision, about the time of 2.2, to put off most non-bugfix code-breaking changes until 3.0, rather than spread them over the remainder of 2.x, was in large part based on the expressed wishes of at least some users. (I myself would have preferred sooner and more spread out.) > In the possible perspective of the Python language developers 3x changes > are mild Compared to the changes to both the language and implementation Guido once considered, they are! But the Perl 6 fiasco and an article by Joel Spolsky advocating evolutionary, not revolutionary, software change prompted him toward mininal change that would meet objectives. Many proposed changes were rejected. > The perspective of the Class client is something quite different. There is no 'Class' in Python. Module and function clients have the same perspective. Python classes are just instances of class 'type'. Modules, instances of class 'module', are sometimes regarded as singleton classes. Functions are instances of various classes. Methods are functions until bound as instances of bound-method classes. Functions are sometimes an alternative to classes, one favored by those of a more functional rather than strictly OOP bent. In any case, you seem to include the interface of class attributes (such as the list.sort function) as part of the class interface. Since anything can be a class attribute, freezing 'class interfaces' freezes everything. > When you get ready to change an advertised Class interface in the > future, please consider my interface rules Taken strictly, they pretty much prohibit anything but implementation changes. If we allow the addition of numbered versions of modules, classes, and functions, with nothing ever deleted, then we would have massive bloat, with attendant maintenance and documentation problems. Some modules might be up to v20 by now. Certainly, the switch from ascii to unicode as the default text encoding (and I am not sure your rules would allow that) changed the interface of nearly every module and a large fraction of classes. Let me reiterate that PSF and Python are not Microsoft and Office. Resources are primarily voluntary and limited, but code and even binaries are available indefinitely, so no one is forced by *us* to switch any particular Python program to any other version of the language. If you think your rules are workable, try developing a fork that obeys them.... but wait, maybe there already is one: 2.7, which will only get bugfixes and invisible implementation changes for several years. Of course, implementation changes must be screened carefully because in the real world, as opposed to the imagined Booch world, it is all to0 easy to accidentally introduce an interface change for some corner case. Also, an implementation change that exchanges space for time will be seen an an interface change by somebody. Do you include space-time behavior in *your* definition of interface (that should not be changed)? Indeed, some object to the removal of cmp precisely on this basis, not on the fairly trivial code rewrite it entails. This was the case with the Google example that prompted this thread. The Googler may well have written fresh code, as code breakage was *not* the issue. If the list.sort change had been purely an implementation change, if cmp remained but its had been changed to use cmp_to_key internally, there would have been many of the same objections expressed on this thread anyway. So why is there a problem with cmp? Because there are people who want most of the changes that break your rules, but not this particular one. -- Terry Jan Reedy From drsalists at gmail.com Fri Apr 1 15:17:08 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 1 Apr 2011 12:17:08 -0700 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Fri, Apr 1, 2011 at 10:06 AM, Terry Reedy wrote: > On 4/1/2011 2:13 AM, harrismh777 wrote: > > When I speak of implementation vs interface I am speaking from a >> strictly object oriented philosophy, as pedigree, from Grady Booch, whom >> I consider to be the father of Object Oriented Analysis and Design >> (Booch, OO A&D with apps, 1994). >> > > Python is object based but not object oriented in the Booch sense. > Actually, IINM: 1) C++, Java, and Python are object oriented in common vernacular and the Booch sense. 2) Ada and Modula-2 are object based in common vernacular and the Booch sense. References: http://en.wikipedia.org/wiki/Object-based http://www.dotnetspider.com/forum/153678-Object-Based-Vs-Object-oriented-language.aspx -------------- next part -------------- An HTML attachment was scrubbed... URL: From nagle at animats.com Fri Apr 1 15:18:11 2011 From: nagle at animats.com (John Nagle) Date: Fri, 01 Apr 2011 12:18:11 -0700 Subject: Python CPU In-Reply-To: References: <01bd055b-631d-45f0-90a7-229da4a9a362@t19g2000prd.googlegroups.com> Message-ID: <4d9624ef$0$10603$742ec2ed@news.sonic.net> On 4/1/2011 11:35 AM, Emile van Sebille wrote: > On 4/1/2011 11:28 AM Emile van Sebille said... >> On 4/1/2011 8:38 AM Brad said... >>> Hi All, >>> >>> I've heard of Java CPUs. Has anyone implemented a Python CPU in VHDL >>> or Verilog? >>> >>> -Brad >> >> >> http://code.google.com/p/python-on-a-chip/ > > Sorry - wrong url in the cut'n paste buffer - > > http://tsheffler.com/software/python/ > >> >> Emile Neither of those is a hardware implementation of Python. "Python on a chip" is a small Python-subset interpreter for microcontrollers. That could be useful if it's not too slow. Sheffler's software is a means for controlling and extending Verilog simulations in Python. (Often, you're simulating some hardware at the gate level which interfaces with other existing hardware, say a disk, which can be simulated at a much coarser level. Being able to write the simulator for the external devices in Python is useful.) John Nagle From no.email at nospam.invalid Fri Apr 1 15:22:59 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Apr 2011 12:22:59 -0700 Subject: Guido rethinking removal of cmp from sort method References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> <7x8vvue7or.fsf@ruckus.brouhaha.com> Message-ID: <7xfwq1srn0.fsf@ruckus.brouhaha.com> Terry Reedy writes: >> What happens then is you define a new interface. > Like key= versus cmp= Well, in an untyped language like Python, adding a feature to an interface doesn't require defining a new interface unless you change something incompatibly. key= is very useful but it can be added without breaking cmp= . > 2to3 could probably gain a fixer to change > .sort(cmp=f) # to > > import functools import cmp_to_key > .sort(key=functools.cmp_to_key(f)) > > I know some would not like this because interface change is not their > real concern. Looks like a good idea. There is an efficiency hit from the above in some situations, but at least it prevents code from breaking, so unless there's some drawback I'm not currently spotting, it's better than nothing and I'd endorse adding such a wrapper. 2to3 should show some kind of diagnostic and maybe put a comment into the output code, when it does that particular transformation, since most of the time there's probably a better way to write the key function. From no.email at nospam.invalid Fri Apr 1 15:28:16 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Apr 2011 12:28:16 -0700 Subject: Guido rethinking removal of cmp from sort method References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> Message-ID: <7xbp0psre7.fsf@ruckus.brouhaha.com> Terry Reedy writes: >> Never change an advertised Class interface. > > In Python, class interfaces are no more sacred than module or function > interfaces. If one takes 'no interface change' literally, then Python > would have to be frozen. Even bug fixes change a defacto interface. Oh come on, a interface is advertised if it's documented in the manual, which cmp is. There are some undocumented (what you call defacto) interfaces that you sometimes have to be pragmatically a bit careful about messing with because people rely on them, but it's almost always more legitimate to break an undocumented interface than a documented one. From rouslank at msn.com Fri Apr 1 15:31:58 2011 From: rouslank at msn.com (Rouslan Korneychuk) Date: Fri, 01 Apr 2011 15:31:58 -0400 Subject: a basic bytecode to machine code compiler In-Reply-To: <4j7lp.5204$sS4.1784@newsfe11.iad> References: <4j7lp.5204$sS4.1784@newsfe11.iad> Message-ID: Thanks for all the replies. I wasn't aware of some of these alternatives. Most of these seem to transform Python code/bytecode into another language. I was already well aware of Cython. On the Nuitka blog, I notice it says "Compiling takes a lot [sic] time, ...". Compyler seems to generate assembly and then parse the assembly to generate a Windows exe. Berp turns python into Haskell, not directly into machine code. The closest thing to mine seems to be Psyco. It tries to do something more ambitious. It analyzes the program while it's running to create specialized versions of certain functions. High memory usage seems to be an issue with Psyco. My approach is to simply translate the bytecode into raw machine code as directly as possible, quickly and without using much memory. Basically I was going for a solution with no significant drawbacks. It was also meant to be very easy to maintain. The machine code is generated with a series of functions that very closely mirrors AT&T syntax (same as the default syntax for the GNU assembler) with some convenience functions that make it look like some kind of high-level assembly. For example, here is the implementation for LOAD_GLOBAL: @hasname def _op_LOAD_GLOBAL(f,name): return ( f.stack.push_tos(True) + [ ops.push(address_of(name)), ops.push(GLOBALS) ] + call('PyDict_GetItem') + if_eax_is_zero([ discard_stack_items(1), ops.push(BUILTINS) ] + call('PyDict_GetItem') + if_eax_is_zero([ discard_stack_items(1), ops.push(pyinternals.raw_addresses[ 'GLOBAL_NAME_ERROR_MSG']), ops.push(pyinternals.raw_addresses['PyExc_NameError']) ] + call('format_exc_check_arg') + [ goto(f.end) ]) ) + [ discard_stack_items(2) ]) To make sense of it, you just need to ignore the square brackets and plus signs (they are there to create a list that gets joined into one byte string at the very end) and imagine it's assembly code (I should probably just write a variadic function or use operator overloading to make this syntactically clearer). Any time a new version of Python is released, you would just run diff on Python-X.X/Python/ceval.c and see which op codes need updating. You wouldn't need to make a broad series of changes because of a minor change in Python's syntax or bytecode. And that's just one of the larger op code implementations. Here's the one for LOAD_CONST: @hasconst def _op_LOAD_CONST(f,const): return f.stack.push_tos() + [f.stack.push(address_of(const))] Anyway, It was certainly interesting working on this. I'll probably at least implement looping and arithmetic so I can have something meaningful to benchmark. From tjreedy at udel.edu Fri Apr 1 15:37:34 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 15:37:34 -0400 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: <7x8vvue7or.fsf@ruckus.brouhaha.com> References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> <7x8vvue7or.fsf@ruckus.brouhaha.com> Message-ID: On 4/1/2011 3:45 AM, Paul Rubin wrote: > What happens then is you define a new interface. In Microsoft-speak if > the IWhatever interface needs an incompatible extension like new > parameters, they introduce IWhatever2 which supports the new parameters. > They change the implementation of IWhatever so it becomes a wrapper for > IWhatever2 setting the new parameters to default values, to keep > implementing the old behavior. Now you have two versions, and eventually many more, to maintain and document. That takes resources we currently do not have. Some problems in addition to the benefits of this approach: 1. The users of IWhatever will not gain the benefits of IWhatever2. 2. Upgrading to IWhatever2 requires a change of name as well as off parameters. 3. If only some users are upgraded, the IWhatever and IWhatever2 users may become incompatible even though they were before, thus breaking code without changing the old interface. Example: Python2 added str2 (= unicode) on top of str. This had all the problems listed above. Since CPython uses str internally, in particular for identifiers, CPython users were stuck with the limitations of str. Rebinding str to mean str2 has many benefits, especially in the future, in addition to current costs. -- Terry Jan Reedy From candide at free.invalid Fri Apr 1 15:39:14 2011 From: candide at free.invalid (candide) Date: Fri, 01 Apr 2011 21:39:14 +0200 Subject: Extracting subsequences composed of the same character In-Reply-To: <4d952008$0$3943$426a74cc@news.free.fr> References: <4d952008$0$3943$426a74cc@news.free.fr> Message-ID: <4d962a3e$0$14990$426a34cc@news.free.fr> Thanks, yours responses gave me the opportunity to understand the "backreference" feature, it was not clear in spite of my intensive study of the well known RE howto manual. From markrrivet at aol.com Fri Apr 1 15:40:23 2011 From: markrrivet at aol.com (Manatee) Date: Fri, 1 Apr 2011 12:40:23 -0700 (PDT) Subject: PyVISA References: <70adf37c-d18a-404b-8127-6c870508d196@a17g2000yqn.googlegroups.com> Message-ID: <1508f9e4-79eb-4b45-9015-356fb6ac12d9@w21g2000yqm.googlegroups.com> On Apr 1, 2:05?pm, "G?nther Dietrich" wrote: > Manatee wrote: > >I have unpacked the PyVISA files into the Python/lib/site-packages dir > >and from the IDLE GUI I get and error > > >import visa > > >Traceback (most recent call last): > > ?File "", line 1, in > > ? ?import visa > >ImportError: No module named visa > > >There must be more to just putting the files in the correct directory. > > Yes, there is more: > > - DON'T unpack the files into any site-packages folder. If you already > ? have done it, remove them. > - Unpack the PyVISA archive to any other folder. > - On the command line, change into the PyVISA folder. There you should > ? find - among others - the two files setup.py and setup.cfg (at least > ? if you use PyVISA-1.3.tar.gz). > - Now, it depends on what variant of python you use and want to install > ? PyVISA for and on the configuration of your PYTHONPATH rsp. sys.path > ? and the folders they point to. > ? You can simply try: 'sudo python ./setup install' > ? If you are lucky, that's it. If not, you have to decide, where the > ? installation script has to put the files to. For example, for my > ? python 2.6, I chose > ? '/Library/Frameworks/Python.framework/Versions/2.6/'. In this path, > ? there is a folder 'lib/site-packages', which is pointed to by > ? sys.path, and where .pth files are evaluated. > - Edit the file setup.cfg. Near the end, in section '[install]', you will > ? find the line 'prefix=/usr'. Replace the '/usr' by your chosen path. > - Save the file and retry the install (see above). > > Best regards, > > ? G?nther Well, ok, I'll try some of that. But I am running window 7, not Linux. The "sudo" command sounds like Linux. From tjreedy at udel.edu Fri Apr 1 15:40:54 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 15:40:54 -0400 Subject: Compiling python without ssl? In-Reply-To: References: Message-ID: On 4/1/2011 7:36 AM, Austin Bingham wrote: > Is there any way to compile python (3.1.3, in case it matters) without > ssl support? OpenSSL is on my system, and configure finds it, Can you temporarily disguise (rename) it? -- Terry Jan Reedy From john at castleamber.com Fri Apr 1 15:42:11 2011 From: john at castleamber.com (John Bokma) Date: Fri, 01 Apr 2011 13:42:11 -0600 Subject: Guido rethinking removal of cmp from sort method References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <0velp.864$YL5.58@newsfe05.iad> Message-ID: <87sju1iwrw.fsf@castleamber.com> Terry Reedy writes: > But the Perl 6 fiasco Perl 6 a complete failure? Wow, must be coming from a clueless Python zealot. If Perl 6 is a fiasco, so is Python 3. Both are not considered production ready, and both can be downloaded and used today: http://rakudo.org/ Next release is planned for later this month. Did Perl 6 take a long time? Sure. But confusing it with Python 2 -> Python 3 is just plainly stupid. It's a complete rewrite of Perl, and it's much easier to think of it as a complete new language instead of similar to Perl 4 -> 5 and comparable to Python 2 -> 3. But if you had any idea what you were talking about, you already knew that. -- John Bokma j3b Blog: http://johnbokma.com/ Facebook: http://www.facebook.com/j.j.j.bokma Freelance Perl & Python Development: http://castleamber.com/ From tjreedy at udel.edu Fri Apr 1 15:45:24 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 15:45:24 -0400 Subject: Mathematical Operations on Array In-Reply-To: <3573139D2D5DBF468087E68083D59B2702F48FEC7E@USFWA1EXMBX4.itt.net> References: <3573139D2D5DBF468087E68083D59B2702F48FEC7E@USFWA1EXMBX4.itt.net> Message-ID: On 4/1/2011 8:56 AM, Fodness, Bryan C - GS wrote: > I am loading text into an array and would like to convert the values. > from math import * > from numpy import * > from pylab import * > data=loadtxt('raw.dat') > mincos=degrees(acos(data[:,0])) > minazi=degrees(data[:,1]) > minthick=data[:,2]/0.006858 > > I am not sure why degrees() works, but acos() does not. It is not clear how you know that. > I receive the following > > Traceback (most recent call last): > File "C:\ test.py", line 6, in ? > mincos=degrees(acos(float(data[:,0]))) > > TypeError: only length-1 arrays can be converted to Python scalars This does not say where in the expression the problem arose. to be sure a = float(data([:,0]) b = acod(a) c = degrees(b) > Can anyone tell me what I am doing wrong? Numpy questions get better answers on the numpy list where numpy experts hang out. -- Terry Jan Reedy From tjreedy at udel.edu Fri Apr 1 15:49:11 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 15:49:11 -0400 Subject: Mathematical Operations on Array In-Reply-To: References: Message-ID: On 4/1/2011 9:35 AM, Bryan.Fodness at gmail.com wrote: > Can anyone tell me what I am doing wrong? Posting the same question twice is a bad idea, as it splits answers and may lead to duplication. I answered your first post without seeing Peter's response to you second post, which is further down the list. -- Terry Jan Reedy From 8213543GGXNVJXACA at kabelmail.de Fri Apr 1 15:52:24 2011 From: 8213543GGXNVJXACA at kabelmail.de (Karl) Date: Fri, 1 Apr 2011 21:52:24 +0200 Subject: newbie question Message-ID: Hello, one beginner question: aList = [0, 1, 2, 3, 4] bList = [2*i for i in aList] sum = 0 for j in bList: sum = sum + bList[j] print j 0 2 4 IndexError: 'list index out of range' Why is j in the second run 2 and not 1 in the for-loop?? I think j is a control variable with 0, 1, 2, 3, ... Thanks! Karl -------------- next part -------------- An HTML attachment was scrubbed... URL: From drsalists at gmail.com Fri Apr 1 16:05:42 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 1 Apr 2011 13:05:42 -0700 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: References: <20110323151426.GB5668@trout.vub.ac.be> <20110324092323.GC5668@trout.vub.ac.be> <4d8bd8a1$0$29977$c3e8da3$5496439d@news.astraweb.com> <20110325092135.GF5668@trout.vub.ac.be> <4d8d19c3$0$29977$c3e8da3$5496439d@news.astraweb.com> <4d90726c$0$30000$c3e8da3$5496439d@news.astraweb.com> <7xpqpavgam.fsf@ruckus.brouhaha.com> Message-ID: On Mon, Mar 28, 2011 at 10:11 PM, Dan Stromberg wrote: > > On Mon, Mar 28, 2011 at 6:58 PM, Paul Rubin wrote: > >> DSU is a clever and useful design pattern, but comparison >> sorting is what all the sorting textbooks are written about. >> > > Actually, even though I wrote one program that could almost benefit from > cmp sorting that might have trouble with key sorting, I think it was > probably the right decision to remove cmp sorting. > I must (partially) recant this. It's not clear to me this was a good decision. Key sorting gives a nice performance boost (because it frequently allows a sort to be run without any calls to python code), but it's not a complete replacement for cmp sorting because cmp sorting does not require exposing implementation detail (at least, not without some foresight and extra typing) to a module's client. I like fast, but not so much that I think we should make abstractions impure. I don't care that much about modifying code across 2.x to 3.x, but modifying client code now and then in 3.x because of a misfeature - that bothers me. If we must have just one, cmp sorting is probably better - just for code beauty. I'm not sure having both would be a bad thing really. They seem distinct enough from one another, as well as complementary enough, that IMO it'd be justified. It strikes me as "there's more than one way to do it" only if you define "it" rather broadly. On the other hand... What if the key function were to become something other than a callable? Like a tuple of (list.use_cmp_fn, cmp_fn)? It's ugly, but it'd allow you to have the fast sorting normally, and fall back on something more general when the need surfaces - without requiring a change in client code. -------------- next part -------------- An HTML attachment was scrubbed... URL: From eryksun at gmail.com Fri Apr 1 16:05:55 2011 From: eryksun at gmail.com (eryksun ()) Date: Fri, 1 Apr 2011 13:05:55 -0700 (PDT) Subject: PyVISA In-Reply-To: <1508f9e4-79eb-4b45-9015-356fb6ac12d9@w21g2000yqm.googlegroups.com> Message-ID: <3c44dcf1-9cdd-485b-ad06-1c013b9145b4@glegroupsg2000goo.googlegroups.com> On Friday, April 1, 2011 3:40:23 PM UTC-4, Manatee wrote: > > Well, ok, I'll try some of that. But I am running window 7, not Linux. > The "sudo" command sounds like Linux. Again, there's a win32 exe installer available here: http://sourceforge.net/projects/pyvisa/files/PyVISA/1.3/PyVISA-1.3.win32.exe/download If your account is a standard user and the installer doesn't load a UAC prompt, you'll probably have to right-click it and choose to "Run as administrator". From markrrivet at aol.com Fri Apr 1 16:22:03 2011 From: markrrivet at aol.com (Manatee) Date: Fri, 1 Apr 2011 13:22:03 -0700 (PDT) Subject: PyVISA References: <3c44dcf1-9cdd-485b-ad06-1c013b9145b4@glegroupsg2000goo.googlegroups.com> Message-ID: On Apr 1, 4:05?pm, "eryksun ()" wrote: > On Friday, April 1, 2011 3:40:23 PM UTC-4, Manatee wrote: > > > Well, ok, I'll try some of that. But I am running window 7, not Linux. > > The "sudo" command sounds like Linux. > > Again, there's a win32 exe installer available here: > > http://sourceforge.net/projects/pyvisa/files/PyVISA/1.3/PyVISA-1.3.wi... > > If your account is a standard user and the installer doesn't load a UAC prompt, you'll probably have to right-click it and choose to "Run as administrator". Aaaaahhhhhh... now we are getting somewhere. I had the wrong version. Ok, let me try accessing a simple instrument. From ott at mirix.org Fri Apr 1 16:47:45 2011 From: ott at mirix.org (Matthias-Christian Ott) Date: Fri, 1 Apr 2011 22:47:45 +0200 Subject: Location of data files In-Reply-To: <20110401183735.GA2276@qp> References: <20110401183735.GA2276@qp> Message-ID: <20110401204745.GB2276@qp> On Fri, Apr 01, 2011 at 08:37:35PM +0200, Matthias-Christian Ott wrote: > I want to include data files with a python package. With distutils it > seems common to specifiy these files in the data_files argument with a > non-portable location (e.g. data_files=[('share/example', 'icon.png')]). > Another approach is to include the file in the Python module of the > package (e.g. example/data) and specify the submodule in package_data > argument and load them via pkgutil or pkg_ressources. This method seems > portable, but doesn't allow customisation and doesn't conform to the > FHS. > > What is the recommended way to allow easy platform-specific packaging > (e.g. data files are installed to /usr/share when requested), portability and > customisation (i.e. data files can be replaced by the user or > alternative locations can be specified)? It seems distutils2 will support this: http://distutils2.notmyidea.org/setupcfg.html#resources Regards, Matthias-Christian From eryksun at gmail.com Fri Apr 1 16:48:44 2011 From: eryksun at gmail.com (eryksun ()) Date: Fri, 1 Apr 2011 13:48:44 -0700 (PDT) Subject: newbie question In-Reply-To: Message-ID: Regarding the format of your post, please use plain text only. On Friday, April 1, 2011 3:52:24 PM UTC-4, Karl wrote: > > aList = [0, 1, 2, 3, 4] > bList = [2*i for i in aList] > sum = 0 > for j in bList: > sum = sum + bList[j] > print j > > 0 > 2 > 4 > > IndexError: list index out of range > > Why is j in the second run 2 and not 1 in the for-loop?? I think > j is a control variable with 0, 1, 2, 3, ... The for loop yields the elements of bList, not their index (it's like a foreach statement in other languages). Here's the full printout: In [1]: aList = [0, 1, 2, 3, 4] In [2]: bList = [2*i for i in aList] In [3]: for j in bList: ...: print j 0 2 4 6 8 Since bList is 5 elements long, bList[6] is indeed "out of range". Here's a more direct way to accomplish this task: In [4]: b_sum = sum(bList) In [5]: b_sum Out[5]: 20 Note that I'm not overwriting the name of the built-in function 'sum'. Try to avoid doing that. It's pretty simple to type the name in the interpreter and see if it's already bound to something you might want to keep around. Here's one way to get the index in a loop: In [6]: b_sum = 0 In [7]: for j, b in enumerate(bList): ...: b_sum += b ...: print j 0 1 2 3 4 In [9]: b_sum Out[9]: 20 The enumerate function returns an iterable that's a tuple of the index and item. A for loop iterates over an iterable object such as a sequence. From candide at free.invalid Fri Apr 1 16:54:53 2011 From: candide at free.invalid (candide) Date: Fri, 01 Apr 2011 22:54:53 +0200 Subject: Extracting repeated words Message-ID: <4d963bfa$0$1584$426a34cc@news.free.fr> Another question relative to regular expressions. How to extract all word duplicates in a given text by use of regular expression methods ? To make the question concrete, if the text is ------------------ Now is better than never. Although never is often better than *right* now. ------------------ duplicates are : ------------------------ better is now than never ------------------------ Some code can solve the question, for instance # ------------------ import re regexp=r"\w+" c=re.compile(regexp, re.IGNORECASE) text=""" Now is better than never. Although never is often better than *right* now.""" z=[s.lower() for s in c.findall(text)] for d in set([s for s in z if z.count(s)>1]): print d, # ------------------ but I'm in search of "plain" re code. From candide at free.invalid Fri Apr 1 16:55:28 2011 From: candide at free.invalid (candide) Date: Fri, 01 Apr 2011 22:55:28 +0200 Subject: Extracting "true" words Message-ID: <4d963c1d$0$1584$426a34cc@news.free.fr> Back again with my study of regular expressions ;) There exists a special character allowing alphanumeric extraction, the special character \w (BTW, what the letter 'w' refers to?). But this feature doesn't permit to extract true words; by "true" I mean word composed only of _alphabetic_ letters (not digit nor underscore). So I was wondering what is the pattern to extract (or to match) _true_ words ? Of course, I don't restrict myself to the ascii universe so that the pattern [a-zA-Z]+ doesn't meet my needs. From wbrehaut at mcsnet.ca Fri Apr 1 16:55:34 2011 From: wbrehaut at mcsnet.ca (Wayne Brehaut) Date: Fri, 01 Apr 2011 14:55:34 -0600 Subject: newbie question References: Message-ID: <88ecp61ljec5ftcgj10fpjpo4tcu0n71dh@4ax.com> On Fri, 1 Apr 2011 21:52:24 +0200, Karl <8213543GGXNVJXACA at kabelmail.de> wrote: >Hello, > >one beginner question: > >aList = [0, 1, 2, 3, 4] >bList = [2*i for i in aList] >sum = 0 >for j in bList: > sum = sum + bList[j] > print j > >0 >2 >4 >IndexError: 'list index out of range' >Why is j in the second run 2 and not 1 in the for-loop?? I think j is a >control variable with 0, 1, 2, 3, ... No--to see what 'j' is, comment out your "sum = sum + bList[j]" statement and run again. The name 'j' refers in order to the 0th, 1st, etc., value in bList, and it's therefore just 'j' (i.e., the value that j now refers to) you want to add to the sum. To get "the usual" (in many oter PLs) indexing instead you would use: for j in range(len(bList)): sum = sum + bList[j] And if you again comment out the "sum =..." and add: print j, bList[j] you'll see the difference. wwwayne > >Thanks! > >Karl From candide at free.invalid Fri Apr 1 16:55:42 2011 From: candide at free.invalid (candide) Date: Fri, 01 Apr 2011 22:55:42 +0200 Subject: Alphabetics respect to a given locale Message-ID: <4d963c2b$0$1584$426a34cc@news.free.fr> How to retrieve the list of all characters defined as alphabetic for the current locale ? From ian.g.kelly at gmail.com Fri Apr 1 17:00:36 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Apr 2011 15:00:36 -0600 Subject: newbie question In-Reply-To: References: Message-ID: On Fri, Apr 1, 2011 at 1:52 PM, Karl <8213543GGXNVJXACA at kabelmail.de> wrote: > Hello, > > one beginner question: > > aList = [0, 1, 2, 3, 4] > > bList = [2*i for i in aList] > > sum = 0 > > for j in bList: > > sum = sum + bList[j] > > ? ? print j > > 0 > > 2 > > 4 > > IndexError: 'list index out of range' > > Why is j in the second run 2 and not 1 in the for-loop?? I think j is a > control variable with 0, 1, 2, 3, ... No, j is not a control variable. It takes each value in the list in turn. If you really want the indexes rather than the values, do: for j in xrange(len(bList)): # do something Note that in Python 3 you should use range instead of xrange. If you want both the indexes and the values, then do this: for j, value in enumerate(bList): # do something Cheers, Ian From clp2 at rebertia.com Fri Apr 1 17:02:49 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Apr 2011 14:02:49 -0700 Subject: newbie question In-Reply-To: References: Message-ID: On Fri, Apr 1, 2011 at 12:52 PM, Karl <8213543GGXNVJXACA at kabelmail.de> wrote: > Hello, > > one beginner question: > > aList = [0, 1, 2, 3, 4] > > bList = [2*i for i in aList] Equivalently: bList = [0, 2, 4, 6, 8] > sum = 0 > > for j in bList: Note that you're iterating over *b*List here, as opposed to *a*List. I think you made a typo and intended "for j in aList:" instead. > sum = sum + bList[j] > > ? ? print j > > 0 > > 2 > > 4 > > IndexError: 'list index out of range' > > Why is j in the second run 2 and not 1 in the for-loop?? I think j is a > control variable with 0, 1, 2, 3, ... Your code, as written, iterates over the *elements* of *b*List, which, consistent with the behavior you're observing, are [0, 2, 4, 6, 8]. j will therefore equal 0, then 2, then 4, etc... Cheers, Chris -- http://blog.rebertia.com From 8213543GGXNVJXACA at kabelmail.de Fri Apr 1 17:03:03 2011 From: 8213543GGXNVJXACA at kabelmail.de (Karl) Date: Fri, 1 Apr 2011 23:03:03 +0200 Subject: newbie question References: Message-ID: Ah, all right. Thank you very much, eryksun! On 2011-04-01 22:48:44 +0200, eryksun () said: > Regarding the format of your post, please use plain text only. > > On Friday, April 1, 2011 3:52:24 PM UTC-4, Karl wrote: >> >> aList = [0, 1, 2, 3, 4] >> bList = [2*i for i in aList] >> sum = 0 >> for j in bList: >> sum = sum + bList[j] >> print j >> >> 0 >> 2 >> 4 >> >> IndexError: list index out of range >> >> Why is j in the second run 2 and not 1 in the for-loop?? I think >> j is a control variable with 0, 1, 2, 3, ... > > The for loop yields the elements of bList, not their index (it's like a > foreach statement in other languages). Here's the full printout: > > In [1]: aList = [0, 1, 2, 3, 4] > In [2]: bList = [2*i for i in aList] > In [3]: for j in bList: > ...: print j > > 0 > 2 > 4 > 6 > 8 > > Since bList is 5 elements long, bList[6] is indeed "out of range". > Here's a more direct way to accomplish this task: > > In [4]: b_sum = sum(bList) > In [5]: b_sum > Out[5]: 20 > > Note that I'm not overwriting the name of the built-in function 'sum'. > Try to avoid doing that. It's pretty simple to type the name in the > interpreter and see if it's already bound to something you might want > to keep around. > > Here's one way to get the index in a loop: > > In [6]: b_sum = 0 > In [7]: for j, b in enumerate(bList): > ...: b_sum += b > ...: print j > > 0 > 1 > 2 > 3 > 4 > > In [9]: b_sum > Out[9]: 20 > > The enumerate function returns an iterable that's a tuple of the index > and item. A for loop iterates over an iterable object such as a > sequence. From drsalists at gmail.com Fri Apr 1 17:06:30 2011 From: drsalists at gmail.com (Dan Stromberg) Date: Fri, 1 Apr 2011 14:06:30 -0700 Subject: newbie question In-Reply-To: References: Message-ID: On Fri, Apr 1, 2011 at 12:52 PM, Karl <8213543GGXNVJXACA at kabelmail.de>wrote: > Hello, > > > one beginner question: > > > aList = [0, 1, 2, 3, 4] > > bList = [2*i for i in aList] > > sum = 0 > > for j in bList: > This iterates over the values in bList, not its indices. > sum = sum + bList[j] > So instead of adding bList[0] .. bList[4], consecutively, you're adding bList[0] .. bList[8] skipping every other element - but there aren't that many elements. -------------- next part -------------- An HTML attachment was scrubbed... URL: From gherron at islandtraining.com Fri Apr 1 17:14:57 2011 From: gherron at islandtraining.com (Gary Herron) Date: Fri, 01 Apr 2011 14:14:57 -0700 Subject: newbie question In-Reply-To: References: Message-ID: <4D964051.3050808@islandtraining.com> On 04/01/2011 12:52 PM, Karl wrote: > > Hello, > > > one beginner question: > > > aList = [0, 1, 2, 3, 4] > > bList = [2*i for i in aList] > > sum = 0 > > for j in bList: > > sum = sum + bList[j] > Your j is already an element of bList. You don't need to index bList again. Instead do for b in bList: sum = sum+b > print j > > > 0 > > 2 > > 4 > > *IndexError:* 'list index out of range' > > Why is j in the second run 2 and not 1 in the for-loop?? I think j is > a control variable with 0, 1, 2, 3, ... > No, it's not a control variable, it's the actual elements of the list. If you want a control variable as an index you can do for j in range(len(bList)): sum = sum + bList[j] But that is less efficient > > Thanks! > > > Karl > -------------- next part -------------- An HTML attachment was scrubbed... URL: From rtw at rtw.me.uk Fri Apr 1 17:16:02 2011 From: rtw at rtw.me.uk (Rob Williscroft) Date: Fri, 1 Apr 2011 21:16:02 +0000 (UTC) Subject: Addition problems References: Message-ID: vm wrote in news:in4m1u$hsc$1 at news2.carnet.hr in gmane.comp.python.general: > def fun1(params_used_below_except_lk_and_lk2): > lk = 0.0 > lk2 = 0.0 > for raw_data, hist, freq in raw_data_hist_list: > lk2 = lk2 + fun2(some_constants_and_params_from_this_scope) > q = fun2(same_args_as_before) > lk = lk + q > print lk, lk2 > > For some set of input parameters, This function with specific input > prints out the same constant twice (as expected): > > 15377.7424582 15377.7424582 (twice the same value) > > If I comment out lines q = fun2.... and lk = lk + q, fun1, with the > same parameters, prints: > > 0.0 3.3469936856 > > First value is expected, but I cannot understand how come the second > value is different in these two cases! Clearly the value returned by fun2 (get_beta_func_fit_quality_hist_lk) is different the second time you call it. So it either depends on and modifies a global or a value referenced or contained in one of the arguments. Rob. From rschroev_nospam_ml at fastmail.fm Fri Apr 1 17:17:48 2011 From: rschroev_nospam_ml at fastmail.fm (Roel Schroeven) Date: Fri, 01 Apr 2011 23:17:48 +0200 Subject: Addition problems In-Reply-To: References: Message-ID: <1irlp.1331$bT6.927@newsfe05.ams2> Op 2011-04-01 16:04, vm schreef: > I'm analyzing some data in python. I have stumbled across unusual problem: > > I have the function... > > def fun1(params_used_below_except_lk_and_lk2): > lk = 0.0 > lk2 = 0.0 > for raw_data, hist, freq in raw_data_hist_list: > lk2 = lk2 + fun2(some_constants_and_params_from_this_scope) > q = fun2(same_args_as_before) > lk = lk + q > print lk, lk2 > > For some set of input parameters, This function with specific input > prints out the same constant twice (as expected): > > 15377.7424582 15377.7424582 (twice the same value) > > If I comment out lines q = fun2.... and lk = lk + q, fun1, with the same > parameters, prints: > > 0.0 3.3469936856 > > First value is expected, but I cannot understand how come the second > value is different in these two cases! Let's have a look at your source: > fun1 source: > > def process_measurements_beta_lk(x, raw_data_hist_list): > lk = 0.0 > lk2 = 0.0 > (p,q,loc,scale) = x > for raw_data, hist, freq in raw_data_hist_list: > lk2 = lk2 + get_beta_func_fit_quality_hist_lk('beta', > (p,q,loc,scale), raw_data, hist) > # q = get_beta_func_fit_quality_hist_lk('beta',(p,q,loc,scale), > raw_data, hist) > # lk = lk + q > print lk, lk2 > retrun lk The lie with "lk2 = " uses the value of q. In the version with commented lines, that value is never changed, while it is changed each iteration in the version with the lines uncommented. -- The saddest aspect of life right now is that science gathers knowledge faster than society gathers wisdom. -- Isaac Asimov Roel Schroeven From debatem1 at gmail.com Fri Apr 1 17:31:09 2011 From: debatem1 at gmail.com (geremy condra) Date: Fri, 1 Apr 2011 14:31:09 -0700 Subject: Guido rethinking removal of cmp from sort method In-Reply-To: <4d93e360$0$29996$c3e8da3$5496439d@news.astraweb.com> References: <4d8bd8a1$0$29977$c3e8da3$5496439d@news.astraweb.com> <4d8d1203$0$29977$c3e8da3$5496439d@news.astraweb.com> <4d90ac87$0$30000$c3e8da3$5496439d@news.astraweb.com> <20110329084657.GE26597@trout.vub.ac.be> <4d93e360$0$29996$c3e8da3$5496439d@news.astraweb.com> Message-ID: On Wed, Mar 30, 2011 at 7:13 PM, Steven D'Aprano wrote: > Or, an alternative approach would be for one of the cmp-supporters to > take the code for Python's sort routine, and implement your own sort-with- > cmp (in C, of course, a pure Python solution will likely be unusable) and > offer it as a download. For anyone who knows how to do C extensions, this > shouldn't be hard: just grab the code in Python 2.7 and make it a stand- > alone function that can be imported. > > If you get lots of community interest in this, that is a good sign that > the solution is useful and practical, and then you can push to have it > included in the standard library or even as a built-in. > > And if not, well, at least you will be able to continue using cmp in your > own code. I don't have a horse in this race, but I do wonder how much of Python could actually survive this test. My first (uneducated) guess is "not very much"- we would almost certainly lose large pieces of the string API and other builtins, and I have no doubt at all that a really significant chunk of the standard library would vanish as well. In fact, looking at the data I took from PyPI a while back, it's pretty clear that Python's feature set would look very different overall if we applied this test to everything. Geremy Condra From tjreedy at udel.edu Fri Apr 1 17:35:18 2011 From: tjreedy at udel.edu (Terry Reedy) Date: Fri, 01 Apr 2011 17:35:18 -0400 Subject: The Magick of __call__ (Or, Digging Deeper Than I Ought To) In-Reply-To: <4D95EA23.10802@aim.com> References: <4D95EA23.10802@aim.com> Message-ID: On 4/1/2011 11:07 AM, Corey Richardson wrote: > All callables (things you can foo(bar)) are really just objects that > implement the __call__ method, as far as I understand. > Well then, that would appear to make methods themselves callable, Method are just function objects that are class attributes. They are sometimes wrapped as method objects. Details are different between Py2 and Py3. >>>> class Foo(object): > ... def __call__(self, foo): > ... self.name(foo) A __call__ instance method makes instances of the class callable. > ... def name(self, bar): > ... print "Name: {0}".format(bar) > ... >>>> foo = Foo() >>>> foo("Me!") > Name: Me! > > Ok, nothing out of the ordinary. But what happens if.... > >>>> foo.name.__call__("Corey") > Name: Corey >>>> eval("foo.name" + (".__call__" * 9001) + "('Corey')") > Name: Corey >>>> foo.name.__call__.__call__.__call__.__call__.__call__("Corey") > Name: Corey >>>> eval("foo.name" + (".__call__" * 100000000) + "('Corey')") Yes, trying to create a string of 900 million chars may cause a problem, especially when you try to concatenate anything on the end, which requires another 900 million char string to be created before the temporary is freed. How much memory do you have? To find out if the strings creation, or compilation, every finished s = "foo.name" + (".__call__" * 100000000) + "('Corey')" print 's done' c = compile(s,'test','eval') print 'c done' eval(s) If s is created, the compiled bytecode will be 200 mil bytes, I believe. If eval ever starts, it will first create 100 million wrappers, as Chris showed, before calling the last. Each is 32 bytes in Py3.2. > looked!). Would looking at something such as PyPy's version of it be > good for me / does anyone else have insights? As to why method wrappers are not reused (explaining in Py3 terms): accessing a method through the class returns the function/method itself; accessing a method through an instance returns some type of bound method wrapper. There are several types of wrapper for the various types of callablesdef , but each has attributes that enable access to both the method and instance. The __call__ method for a particular type of wrapper knows how to call instances of that type of bound method. In other words, method attributes of instances are computed attributes, much like data properties. Functions are non-data descriptors, as explained in the descriptor HOW-TO. Every time a method is accessed through an instance, a new wrapper is created. Why? 1. If you want to reuse a bound methods, just bind it to a name or something and reuse it. 2. To automatically keep it for possible reuse, which normally is not too common, it wold have to be kept in some hidden dict which would grow indefinitely unless pruned occasionally. -- Terry Jan Reedy From no.email at nospam.invalid Fri Apr 1 17:37:20 2011 From: no.email at nospam.invalid (Paul Rubin) Date: Fri, 01 Apr 2011 14:37:20 -0700 Subject: Guido rethinking removal of cmp from sort method References: <4d7cbfcb$0$29971$c3e8da3$5496439d@news.astraweb.com> <4d94326c$0$30003$c3e8da3$5496439d@news.astraweb.com> <7x8vvue7or.fsf@ruckus.brouhaha.com> Message-ID: <7x39m1slf3.fsf@ruckus.brouhaha.com> Terry Reedy writes: >> IWhatever2 setting the new parameters to default values > Now you have two versions, and eventually many more, to maintain and > document. In the case of cmp= there's not two interfaces needed. Python2 does a perfectly good job supporting cmp and key with one interface. We do have urllib and urllib2 as separate interfaces (with separate implementations), and we keep some other legacy interfaces around too, like the sha and md5 modules (both of which are now subsumed by hashlib). > That takes resources we currently do not have. Well ok, but now you're making excuses for instability, which seems like a problem given Python's self-marketing as a stable, production-class system that competes with better-funded efforts like Java. > Example: Python2 added str2 (= unicode) on top of str. This had all > the problems listed above. Since CPython uses str internally, in > particular for identifiers, CPython users were stuck with the > limitations of str. Rebinding str to mean str2 has many benefits, > especially in the future, in addition to current costs. That really is a massive change, but a welcome one, because Python2 programs broke all the time due to missed conversions between str and unicode. It is the type of thing that a language transition (Python2 to Python3) is supposed to bring, that goes beyond Interface2 to Interface3. There's been a lot of experience gained in the decades since Python's creation and it's fine to do an overhaul after all these years. The issues are 1) don't break stuff unless there's a substantial benefit; and 2) don't do these major incompatible releases too often. There should not be any incompatible Python4 before 2020 or so. I actually think Python3 actually didn't go far enough in fixing Python2. I'd have frankly preferred delaying it by a few years, to allow PyPy to come to maturity and serve as the new main Python implementation, and have that drive the language change decisions. Instead we're going to have to give up a lot of possible improvements we could have gotten from the new implementation. From anikom15 at gmail.com Fri Apr 1 18:34:36 2011 From: anikom15 at gmail.com (Westley =?ISO-8859-1?Q?Mart=EDnez?=) Date: Fri, 01 Apr 2011 15:34:36 -0700 Subject: Running Websites with Python Message-ID: <1301697276.11139.10.camel@localhost.localdomain> I discovered this yesterday, and finished watching today. Just an interesting video. http://www.youtube.com/watch?v=4R-7ZO4I1pI It's a brief video on how a programmer has been using Python to manage his website. I found it interesting that he gradually moved components of his website from JavaScript to Python shortly after discovering the language. He also shows off his website quite a bit; I think he's a little narcissistic. From ian.g.kelly at gmail.com Fri Apr 1 18:42:51 2011 From: ian.g.kelly at gmail.com (Ian Kelly) Date: Fri, 1 Apr 2011 16:42:51 -0600 Subject: Extracting repeated words In-Reply-To: <4d963bfa$0$1584$426a34cc@news.free.fr> References: <4d963bfa$0$1584$426a34cc@news.free.fr> Message-ID: On Fri, Apr 1, 2011 at 2:54 PM, candide wrote: > Another question relative to regular expressions. > > How to extract all word duplicates in a given text by use of regular > expression methods ? ?To make the question concrete, if the text is > > ------------------ > Now is better than never. > Although never is often better than *right* now. > ------------------ > > duplicates are : > > ------------------------ > better is now than never > ------------------------ > > Some code can solve the question, for instance > > # ------------------ > import re > > regexp=r"\w+" > > c=re.compile(regexp, re.IGNORECASE) > > text=""" > Now is better than never. > Although never is often better than *right* now.""" > > z=[s.lower() for s in c.findall(text)] > > for d in set([s for s in z if z.count(s)>1]): > ? ?print d, > # ------------------ > > but I'm in search of "plain" re code. You could use a look-ahead assertion with a captured group: >>> regexp = r'\b(?P\w+)\b(?=.+\b(?P=dup)\b)' >>> c = re.compile(regexp, re.IGNORECASE | re.DOTALL) >>> c.findall(text) But note that this is computationally expensive. The regex that you posted is probably more efficient if you use a collections.Counter object instead of z.count. Cheers, Ian From eryksun at gmail.com Fri Apr 1 19:08:47 2011 From: eryksun at gmail.com (eryksun ()) Date: Fri, 1 Apr 2011 16:08:47 -0700 (PDT) Subject: Alphabetics respect to a given locale In-Reply-To: <4d963c2b$0$1584$426a34cc@news.free.fr> Message-ID: On Friday, April 1, 2011 4:55:42 PM UTC-4, candide wrote: > > How to retrieve the list of all characters defined as alphabetic for the > current locale ? Give this a shot: In [1]: import string In [2]: print string.letters abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ In [3]: import locale In [4]: locale.getlocale() Out[4]: (None, None) In [5]: locale.setlocale(locale.LC_ALL, 'English_Great Britain') Out[5]: 'English_United Kingdom.1252' In [6]: print string.letters ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ?SOZsozY???AAAA????E?EEIIIID?OOOO?OUUU?Y_ ????a????????????d????o?o????y_? The strings for locales are different for POSIX vs Windows systems. http://docs.python.org/library/locale.html From clp2 at rebertia.com Fri Apr 1 19:10:06 2011 From: clp2 at rebertia.com (Chris Rebert) Date: Fri, 1 Apr 2011 16:10:06 -0700 Subject: Extracting "true" words In-Reply-To: <4d963c1d$0$1584$426a34cc@news.free.fr> References: <4d963c1d$0$1584$426a34cc@news.free.fr> Message-ID: On Fri, Apr 1, 2011 at 1:55 PM, candide wrote: > Back again with my study of regular expressions ;) There exists a special > character allowing alphanumeric extraction, the special character \w (BTW, > what the letter 'w' refers to?). "Word" presumably/intuitively; hence the non-standard "[:word:]" POSIX-like character class alias for \w in some environments. > But this feature doesn't permit to extract > true words; by "true" I mean word composed only of _alphabetic_ letters (not > digit nor underscore). Are you intentionally excluding CJK ideographs (as not "letters"/alphabetic)? And what of hyphenated terms (e.g. "re-lock")? > So I was wondering what is the pattern to extract (or to match) _true_ words > ? Of course, I don't restrict myself to the ascii universe so that the > pattern [a-zA-Z]+ doesn't meet my needs. AFAICT, there doesn't appear to be a nice way to do this in Python using the std lib `re` module, but I'm not a regex guru. POSIX character classes are unsupported, which rules out "[:alpha:]". \w can be made Unicode/locale-sensitive, but includes digits and the underscore, as you've already pointed out. \p (Unicode property/block testing), which would allow for "\p{Alphabetic}" or similar, is likewise unsupported. Cheers, Chris -- http://blog.rebertia.com From python at mrabarnett.plus.com Fri Apr 1 19:15:22 2011 From: python at mrabarnett.plus.com (MRAB) Date: Sat, 02 Apr 2011 00:15:22 +0100 Subject: Extracting "true" words In-Reply-To: <4d963c1d$0$1584$426a34cc@news.free.fr> References: <4d963c1d$0$1584$426a34cc@news.free.fr> Message-ID: <4D965C8A.4040906@mrabarnett.plus.com> On 01/04/2011 21:55, candide wrote: > Back again with my study of regular expressions ;) There exists a > special character allowing alphanumeric extraction, the special > character \w (BTW, what the letter 'w' refers to?). But this feature > doesn't permit to extract true words; by "true" I mean word composed > only of _alphabetic_ letters (not digit nor underscore). > The 'w' refers to a 'word' character, although in regex it refers to letters, digits and the underscore character '_' due to its use in computer languages (basically, the characters of an identifier or name). > > So I was wondering what is the pattern to extract (or to match) _true_ > words ? Of course, I don't restrict myself to the ascii universe so that > the pattern [a-zA-Z]+ doesn't meet my needs. > Using the re module, you would have to create a character class out of all the possible letters, something like this: letter_class = u"[" + u"".join(unichr(c) for c in range(0x10000) if unichr(c).isalpha()) + u"]" Alternatively, you could try the new regex implementation here: http://pypi.python.org/pypi/regex which adds support for Unicode properties, and do something like this: words = regex.findall(ur"\p{Letter}+", unicode_text) From emile at fenx.com Fri Apr 1 19:16:33 2011 From: emile at fenx.com (Emile van Sebille) Date: Fri, 01 Apr 2011 16:16:33 -0700 Subject: Alphabetics respect to a given locale In-Reply-To: <4d963c2b$0$1584$426a34cc@news.free.fr> References: <4d963c2b$0$1584$426a34cc@news.free.fr> Message-ID: On 4/1/2011 1:55 PM candide said... > How to retrieve the list of all characters defined as alphabetic for the > current locale ? I think this is supposed to work, but not for whatever reason for me when I try to test after changing my locale (but I think that's a centos thing)... import locale locale.setlocale(locale.LC_ALL,'') import string print string.lowercase I don't see where else this might be for python. However, you can test if something is alpha: >>> val = u'caf' u'\xE9' >>> val.isalpha() True >>> ... and check its unicode category >>> import unicodedata >>> unicodedata.category(u'a') 'Ll' # Letter - lower case >>> unicodedata.category(u'A') 'Lu' # Letter - upper case >>> unicodedata.category(u'1') 'Nd' # Number - decimal? >>> unicodedata.category(u'\x01') 'Cc' # HTH, Emile From torriem at gmail.com Fri Apr 1 20:11:49 2011 From: torriem at gmail.com (Michael Torrie) Date: Fri, 01 Apr 2011 18:11:49 -0600 Subject: Running Websites with Python In-Reply-To: <1301697276.11139.10.camel@localhost.localdomain> References: <1301697276.11139.10.camel@localhost.localdomain> Message-ID: <4D9669C5.5010903@gmail.com> On 04/01/2011 04:34 PM, Westley Mart?nez wrote: > I discovered this yesterday, and finished watching today. Just an > interesting video. > >