Re: dynamic unittest
Oleg Paraschenko wrote: > Hello, > > I decided to re-use functionality of "unittest" module for my purposes. > More precisely, I have a list of folders. For each folder, code should > enter to the folder, execute a command and assert the output. It's > reasonable to use "unittest" here, but the problem is that "unittest" > doesn't support (== I haven't found how) dynamic creation of tests. > > I thought it would be very easy, but due to lack of closures in Python > (more precisely, closures do exist, but they are counter-intuitive for > lisp programmers), I failed. Finally, I found a way using a global > variable. I exploit the fact that "unittest" uses "cmp" to arrange test > cases. Therefore, if we have an array of test names and sequential > number of running the common function, we know the name of the current > test. Here is a sample code: > > --- > > import sys, unittest > test_names = ['aaa', 'ddd', 'bbb'] > test_names.sort() > test_index = 0 > > class DynamicTestCase(unittest.TestCase): > def one_test(self): > global test_index > test_name = test_names[test_index] > test_index = test_index + 1 > # Ok for 'aaa' and 'bbb', failure for 'ddd' > assert test_name in ['aaa', 'bbb'] > > for test_name in test_names: > func_name = 'test_' + test_name > setattr(DynamicTestCase, func_name, DynamicTestCase.one_test) > > suite = unittest.makeSuite(DynamicTestCase, 'test_') > if not unittest.TextTestRunner().run(suite).wasSuccessful(): > sys.exit(1) > > --- > > I think this code might help others, so I post it to the group. > Comments are welcome. Here's what your code might look like with closures: import sys import unittest test_names = ['aaa', 'ddd', 'bbb'] test_names.sort() class DynamicTestCase(unittest.TestCase): pass def make_test(test_name): def one_test(self): self.assert_(test_name in ['aaa', 'bbb']) return one_test for test_name in test_names: setattr(DynamicTestCase, 'test_' + test_name, make_test(test_name)) if __name__ == "__main__": unittest.main() Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Cool Python Ebooks Site
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On 17 Jul 2006 01:39:27 GMT, John Bokma <[EMAIL PROTECTED]> > declaimed the following in comp.lang.python: > >> But everything to make a little AdSense money no? How would you like >> it if everybody who read your message clicks 10 times on each ad? > > Why take the time... This is Python, is it not... Let's create a > script that does the "clicking", one per second, and run it in the > background... (86400 seconds per day... let it run for a while...) Why use Python when one has wget :-D -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
Re: General Hash Functions In Python
"Arash Partow" <[EMAIL PROTECTED]> writes: > I've ported various hash functions to python if anyone is interested: Are these useful for any particular interoperability purposes? Otherwise I'd say just one such hash is plenty, or maybe don't even bother, since Python's built-in dicts are sufficient for most applications that call for hashing, and the cryptographic hashes are available for when you really care about uniformity of the hash output. > for i in range(len(key)): > hash = hash * a + ord(key[i]) > a = a * b As a stylistic issue, I'd write this: for c in key: hash = hash * a + ord(c) a *= b and similarly for the other similar loops. -- http://mail.python.org/mailman/listinfo/python-list
General Hash Functions In Python
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a= 378551 b= 63689 hash = 0 for i in range(len(key)): hash = hash * a + ord(key[i]) a = a * b return (hash & 0x7FFF) def JSHash(key): hash = 1315423911 for i in range(len(key)): hash ^= ((hash << 5) + ord(key[i]) + (hash >> 2)) return (hash & 0x7FFF) def PJWHash(key): BitsInUnsignedInt = 4 * 8 ThreeQuarters = long((BitsInUnsignedInt * 3) / 4) OneEighth = long(BitsInUnsignedInt / 8) HighBits = (0x) << (BitsInUnsignedInt - OneEighth) hash = 0 test = 0 for i in range(len(key)): hash = (hash << OneEighth) + ord(key[i]) test = hash & HighBits if test != 0: hash = (( hash ^ (test >> ThreeQuarters)) & (~HighBits)); return (hash & 0x7FFF) def ELFHash(key): hash = 0 x= 0 for i in range(len(key)): hash = (hash << 4) + ord(key[i]) x = hash & 0xF000 if x != 0: hash ^= (x >> 24) hash &= ~x return (hash & 0x7FFF) def BKDRHash(key): seed = 131 # 31 131 1313 13131 131313 etc.. hash = 0 for i in range(len(key)): hash = (hash * seed) + ord(key[i]) return (hash & 0x7FFF) def SDBMHash(key): hash = 0 for i in range(len(key)): hash = ord(key[i]) + (hash << 6) + (hash << 16) - hash; return (hash & 0x7FFF) def DJBHash(key): hash = 5381 for i in range(len(key)): hash = ((hash << 5) + hash) + ord(key[i]) return (hash & 0x7FFF) def DEKHash(key): hash = len(key); for i in range(len(key)): hash = ((hash << 5) ^ (hash >> 27)) ^ ord(key[i]) return (hash & 0x7FFF) def APHash(key): hash = 0 for i in range(len(key)): if ((i & 1) == 0): hash ^= ((hash << 7) ^ ord(key[i]) ^ (hash >> 3)) else: hash ^= (~((hash << 11) ^ ord(key[i]) ^ (hash >> 5))) return (hash & 0x7FFF) print RSHash ('abcdefghijklmnopqrstuvwxyz1234567890') print JSHash ('abcdefghijklmnopqrstuvwxyz1234567890') print PJWHash ('abcdefghijklmnopqrstuvwxyz1234567890') print ELFHash ('abcdefghijklmnopqrstuvwxyz1234567890') print BKDRHash('abcdefghijklmnopqrstuvwxyz1234567890') print SDBMHash('abcdefghijklmnopqrstuvwxyz1234567890') print DJBHash ('abcdefghijklmnopqrstuvwxyz1234567890') print DEKHash ('abcdefghijklmnopqrstuvwxyz1234567890') print APHash ('abcdefghijklmnopqrstuvwxyz1234567890') Arash Partow Be one who knows what they don't know, Instead of being one who knows not what they don't know, Thinking they know everything about all things. http://www.partow.net -- http://mail.python.org/mailman/listinfo/python-list
dynamic unittest
Hello, I decided to re-use functionality of "unittest" module for my purposes. More precisely, I have a list of folders. For each folder, code should enter to the folder, execute a command and assert the output. It's reasonable to use "unittest" here, but the problem is that "unittest" doesn't support (== I haven't found how) dynamic creation of tests. I thought it would be very easy, but due to lack of closures in Python (more precisely, closures do exist, but they are counter-intuitive for lisp programmers), I failed. Finally, I found a way using a global variable. I exploit the fact that "unittest" uses "cmp" to arrange test cases. Therefore, if we have an array of test names and sequential number of running the common function, we know the name of the current test. Here is a sample code: --- import sys, unittest test_names = ['aaa', 'ddd', 'bbb'] test_names.sort() test_index = 0 class DynamicTestCase(unittest.TestCase): def one_test(self): global test_index test_name = test_names[test_index] test_index = test_index + 1 # Ok for 'aaa' and 'bbb', failure for 'ddd' assert test_name in ['aaa', 'bbb'] for test_name in test_names: func_name = 'test_' + test_name setattr(DynamicTestCase, func_name, DynamicTestCase.one_test) suite = unittest.makeSuite(DynamicTestCase, 'test_') if not unittest.TextTestRunner().run(suite).wasSuccessful(): sys.exit(1) --- I think this code might help others, so I post it to the group. Comments are welcome. -- Oleg Parashchenko olpa@ http://xmlhack.ru/ XML news in Russian http://uucode.com/blog/ Generative Programming, XML, TeX, Scheme XSieve at XTech 2006: http://xtech06.usefulinc.com/schedule/detail/44 -- http://mail.python.org/mailman/listinfo/python-list
Using Bandwidth throtlling with python!
Hi, I am using python2.4 for one of my application where I need to use paramiko for doing sftp. My application sftp to a server and get all the data needed locally. Now I have a utility names TRICKLE which does bandwidth throtlling. i.e. it control the data flow. Now if I use trickle with my python script it does not throttle the bandwith, but if I run it standalone i.e. if I do sftpp directly using trickle I can do it easily. The same code is working fine in linux but not in Sun solaris machine. I am running it on sun sparc V240. Can anyone please help me with this problem. I have done all I can do but it seems the problem is with paramiko. I might be wrong also. Please help Manpreet -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Andreas Rossberg <[EMAIL PROTECTED]> writes: >Uh, aliasing all over the place! Actually, I think that logic >programming, usually based on deep unification, brings by far the worst >incarnation of aliasing issues to the table. I agree that deep unification, as implemented in Prolog, brings with it lots of aliasing problems. However, these problems have been recognized from the seventies, and people have tried to solve them. There have been a huge variety of mode systems added to various dialects of Prolog over the years, which each attempt to tackle (various parts of) the aliasing problem, none of them fully successfully in my view, since their designers usually actually *wanted* to retain at least *some* of the expressive power of the logic variable. Some non-Prolog logic languages have departed from this approach, the earliest being the Relational Language. To tie this message to another thread, the Relational Language had a strict mode system that is as identical as possible to the notion of typestate in NIL and Hermes given the limitations of comparing declarative apples with imperative oranges, but significantly earlier, 1979 vs 1986 IIRC. Marshall wrote: >I have explored the OO path to its bitter end and am >convinced it is not the way. So what is left? Uniqueness >types and logic programming, I suppose. I enjoy logic >programming but it doesn't seem quite right. But notice: >no pointers there! And it doesn't seem to suffer from the >lack. Of course, the main logic programming language today that disallows the use of unification for arbitrary aliasing is Mercury. It enforces this through a strong mode system. Our motivation for the design of this mode system was precisely to eliminate the problems Andreas identified above. However it has also turned out to be an excellent foundation for Mercury's notion of unique modes, its equivalent of uniqueness types, which Mercury uses to express I/O. Zoltan Somogyi <[EMAIL PROTECTED]> http://www.cs.mu.oz.au/~zs/ Department of Computer Science and Software Engineering, Univ. of Melbourne -- http://mail.python.org/mailman/listinfo/python-list
Re: embedding executable code in a regular expression in Python
Avi Kak wrote: > Does regular expression processing in Python allow for executable > code to be embedded inside a regular expression? > > For example, in Perl the following two statements > > $regex = qr/hello(?{print "saw hello\n"})mello(?{print "saw > mello\n"})/; > "jellohellomello" =~ /$regex/; > > will produce the output > > saw hello > saw mello > > Is it possible to do the same in Python with any modules that come > with the standard distribution, or with any other modules? Just in case you were referring to security concerns: Sufficiently complex REs can take ages to compile and run and eat tons of memory, so there are always issues involved here. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: compiling 2.3.5 on ubuntu
Py PY wrote: > (Apologies if this appears twice. I posted it yesterday and it was held > due to a 'suspicious header') > > I'm having a hard time trying to get a couple of tests to pass when > compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's > not too far removed from the desktop edition but, clearly, I need to > tweak something or install some missling libs. Why are you compiling a package that is already built for you? -- - Justin -- http://mail.python.org/mailman/listinfo/python-list
unsynchronized text streams in OGG (lyrics)
Hi, I heard somewhere that OGG container format is capable of storing arbitrary long text streams inside OGG container. I would love to use it for storing lyrics inside the .ogg files. Is it true? Could anybody provide more information how to do it? Is there any Python code for doing this? Thanks, Matej Cepl -- http://mail.python.org/mailman/listinfo/python-list
Re: how to know if socket is still connected
cool enough, thanks ! -sk Grant Edwards wrote: > On 2006-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > >> If the server has closed the connection, then a recv() on the > >> socket will return an empty string "", and a send() on the > >> socket will raise an exception. > > > like this ? > > databack = aeris_sockobj.recv(2048) > > if databack: > > view_msg = 'caught request acknowlage %s bytes \n' % > > len(databack) > > else: > > view_msg = 'fail to recieve data from aeris server\n' > > > > then put the reconnect in the else: block ? > > Yes, if the problem is that the host closes the connection, > that should work. Modulo the broken indentation and > line-wrapping. ;) > > -- > Grant Edwards grante Yow! My mind is a potato > at field... >visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Calling python functions from C
On 17/07/2006 6:47 AM, [EMAIL PROTECTED] wrote: > Could anybody tell me how to call python modules from C. > > e.g. my Python module : > def add(a,b) > return(a+b) > > How can I call "add.py" from C? Please post any simple example. I've never contemplated embedding before, but have done some extending. Your post made me curious. Here are my expedition notes: 1. Simple example (more elaborate than what you want to do) found in the documentation: section 5.3 of the Extending and Embedding Manual. [about 1 minute] 2. Mucked about getting an executable created. [Windows, tried bcc32 first, gave up, got mingw's gcc to do it, total about 30 minutes] This worked: C:\devel\embed>gcc -mno-cygwin -O -Wall -Ic:\python24\include Ic:\python24\PC -c runfunc.c -o runfunc.o runfunc.c: In function `main': runfunc.c:6: warning: unused variable `pDict' C:\devel\embed>gcc -mno-cygwin -s runfunc.o -Lc:\python24\libs -Lc:\python24\PCBuild -lpython24 -lmsvcr71 -o runfunc.exe 3. Created a test file [about 1 minute] C:\devel\embed>type arith.py def plus(a, b): return a + b def minus(a, b): return a - b def times(a, b): return a * b 4. Some tests [about two minutes] C:\devel\embed>runfunc Usage: call pythonfile funcname [args] C:\devel\embed>runfunc arith add 1 2 AttributeError: 'module' object has no attribute 'add' Cannot find function "add" C:\devel\embed>runfunc arith plus 1 2 Result of call: 3 C:\devel\embed>runfunc arith minus 1 2 Result of call: -1 C:\devel\embed>runfunc arith times 1 2 Result of call: 2 C:\devel\embed>runfunc arith times 6 7 Result of call: 42 > > I have read Python embedding in Python Manual but I get "ImportError" > all the time? Sorry, my parser throws a syntax error on that; is it meant to be a question or a statement? If you are getting "ImportError" without any following text, something is gravely wrong. If you are getting "ImportError" *with* following text but not divulging that text, you are implicitly asking your audience to play guessing games. Your audience may have better ways of amusing themselves. At best, after one or two desultory attempts they would probably give up. Here's my first attempt: C:\devel\embed>runfunc arith.py times 6 7 ImportError: No module named py Failed to load "arith.py" Well, am I hot/warm/cold? > > Any help would be appreciated ! Self-help is often fastest to arrive. Cheers, John -- http://mail.python.org/mailman/listinfo/python-list
Re: Cool Python Ebooks Site
[EMAIL PROTECTED] wrote: > Here is a cool site were you can preview python ebooks. It would be more cool if your spamvertized sites had the links to the actual sites that host the free books, like Dive into Python and had no links at all to clear copyright infringements. Instead of contributing to the Python community you take away. Some people make some money with writing books. But everything to make a little AdSense money no? How would you like it if everybody who read your message clicks 10 times on each ad? -- John MexIT: http://johnbokma.com/mexit/ personal page: http://johnbokma.com/ Experienced programmer available: http://castleamber.com/ Happy Customers: http://castleamber.com/testimonials.html -- http://mail.python.org/mailman/listinfo/python-list
urllib (in thread) never returns
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I've been having an intermittent problem with urllib. With an interval of around 15 minutes (i.e.: this is run every 15m) this code runs fine for about 1-2 weeks, but then gets it's knickers in a twist, and never seems to return, nor except. try: log("ABOUT TO USE urllib TO FETCH ["+self.url+"]") f = urllib.urlopen(self.url) temp_xml = f.read() [1] log("DONE! GOT %d bytes for [%s]" % (len(str(temp_xml)),self.url)) f.close() refreshed = True except: [2] log("Error: fetching ["+self.url+"], retrying ... ") ... In the 'broken' state, I never see the log message [1] or [2], it just sits in either the urlopen() or read() forever. The code is running in a separate thread. TCP timeout is set to 45 seconds. Running on Linux (gentoo) What I think is wrong, is that the server is sitting behind a somewhat-dodgey ADSL connection. The server it's contacting is also on a dodgey ADSL connection. I'm guessing that the socket is opened with the ADSL modem is NATing the connection, but when the backend internet connection bounces, the NAT'ed connection somehow stays up, leaving the connection somehow dangling; alive, but dead too... I would have thought that some urllib-internal timeout would fix this?! I could watch the thread from another thread, implementing my own timeout... But then (AFAIK) there's no way to terminate a mis-behaving thread anyways. Any suggestions? thanks, - -Kingsley -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.4 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFEut+ISo2jKyi4JlgRApIdAJ4iIWDLXR9am659XAS1ajLv1ry12wCfeOiI FUNbrisdyo4j3Yle4zN2ESk= =EPU2 -END PGP SIGNATURE- -- http://mail.python.org/mailman/listinfo/python-list
Re: how to know if socket is still connected
On 2006-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >> If the server has closed the connection, then a recv() on the >> socket will return an empty string "", and a send() on the >> socket will raise an exception. > like this ? > databack = aeris_sockobj.recv(2048) > if databack: > view_msg = 'caught request acknowlage %s bytes \n' % > len(databack) > else: > view_msg = 'fail to recieve data from aeris server\n' > > then put the reconnect in the else: block ? Yes, if the problem is that the host closes the connection, that should work. Modulo the broken indentation and line-wrapping. ;) -- Grant Edwards grante Yow! My mind is a potato at field... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: compiling 2.3.5 on ubuntu
Sorry to be a pest but is there anybody that could help me understand a) if any of this is a problem; and b) where I can learn how to fix it. Thank you very much for any pointers. On 2006-07-10 11:45:51 -0400, Py PY <[EMAIL PROTECTED]> said: > (Apologies if this appears twice. I posted it yesterday and it was held > due to a 'suspicious header') > > I'm having a hard time trying to get a couple of tests to pass when > compling Python 2.3.5 on Ubuntu Server Edition 6.06 LTS. I'm sure it's > not too far removed from the desktop edition but, clearly, I need to > tweak something or install some missling libs. > > uname -a > > Linux server 2.6.15-23-server #1 SMP Tue May 23 15:10:35 UTC 2006 i686 > GNU/Linux > > When I compile Python I get these failing > > 4 skips unexpected on linux2: > test_dbm test_mpz test_bsddb test_locale > > I've got libgdbm-dev and libgdbm3 packages installed. > > Help! -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Darren New <[EMAIL PROTECTED]> wrote: > I'm not sure what linear or uniqueness typing is. It's typestate, and if > I remember correctly the papers I read 10 years ago, the folks at > TJWatson that invented Hermes also invented the concept of typestate. > They at least claim to have coined the term. Coining the term is one thing, but I feel pretty confident that the idea was not invented in 1986 with the Hermes language, but rather far earlier. Perhaps they may have invented the concept of considering it any different from other applications of types, though. I still have trouble delineating how to consider "typestate" different from ordinary types in formal terms, unless I make the formal model complex enough to include some kind of programmer-defined identifiers such as variables. The distinction is not at all relevant to common type system models based on the lambda calculus. While acknowledging, on the one hand, that the word "typestate" is used to describe this, I also object that types have *always* been assigned to expressions in differing type environments. Otherwise, it would be impossible to assign types to lambda abstractions in the simply typed lambda calculus, the simplest of all generally studied type systems. What is being named here is the overcoming of a limitation that programming language designers imposed upon themselves, whether from not understanding the theoretical research or not believing it important, I don't know. -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
Re: Cool Python Ebooks Site
are not most (or all) of these copywrite protected ? thats why i have not pulled some of them myself, you can get most of them used from amazon for about $10 [EMAIL PROTECTED] wrote: > http://cooldogebooks.blogspot.com/2006/05/python-ebooks.html > > Here is a cool site were you can preview python ebooks. > > Here are just a few listed > > Advanced_Python_programming.pdf 20-Oct-2004 14:23 194K > EP2003CppExtensions.pdf 20-Oct-2004 14:25 2.0M > GUI Programming with Python.zip 20-Oct-2004 14:36 16M > Game_Programming_with_Python.pdf 20-Oct-2004 14:26 67K > How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002.pdf > 20-Oct-2004 14:37 863K > How_to_think_like_a_computer_scientist.pdf 20-Oct-2004 14:36 720K > New Riders - Jython for Java Programmers.chm 20-Oct-2004 14:38 713K > OReilly - Core Python Programming.pdf 20-Oct-2004 14:43 7.8M > OReilly - Learning Python.chm 20-Oct-2004 14:44 967K > OReilly - Programming Python 2nd Ed.chm 20-Oct-2004 14:48 6.4M > OReilly - Python & XML.pdf 20-Oct-2004 14:49 2.0M > OReilly - Python Cookbook.chm 20-Oct-2004 14:49 1.0M > OReilly - Python Developer's Handbook.rar 20-Oct-2004 14:50 1.6M > OReilly - Python In A Nutshell eBook-LiB.chm 20-Oct-2004 14:51 1.1M > OReilly - Python Programming on Win32.chm 20-Oct-2004 14:52 2.1M > OReilly - Python Standard Library.chm 20-Oct-2004 14:52 356K > Python???rar 20-Oct-2004 16:09 64M > Python.pdf 20-Oct-2004 14:59 391K > Python 2.1 Bible.pdf 20-Oct-2004 14:58 6.3M > Python Essential Reference, Second Edition.rar 20-Oct-2004 14:58 536K > Python Pocket Reference.chm 20-Oct-2004 14:59 175K > PythonWindowsTutorial.doc 20-Oct-2004 16:10 1.9M > Python_Programming_with_the_JavaT_Class_Libraries_-_Addison_Wesley_-_2002.chm > 20-Oct-2004 15:00 1.8M CD-ROM > Sams - Teach Yourself Python In 24 Hours.rar 20-Oct-2004 15:52 2.4M > Thinking in python.chm 20-Oct-2004 14:21 178K > an-introduction-to-tkinter.pdf 20-Oct-2004 14:23 733K > diveintopython-pdf-4.3.zip 20-Oct-2004 14:24 519K > iconcrib.pdf 20-Oct-2004 14:37 152K > icongraphics.pdf 20-Oct-2004 14:37 138K > mailgate/ 26-Oct-2004 02:27 - > modpython.pdf 20-Oct-2004 14:38 164K > pil-handbook.pdf 20-Oct-2004 14:53 486K > pil.pdf 20-Oct-2004 14:53 232K > portal.tar.gz 20-Oct-2004 14:53 45K tar xvfz filename > pygtk2tutorial.tar.gz 20-Oct-2004 14:54 1.6M tar xvfz filename > pygtk2tutorial.tgz 20-Oct-2004 14:54 775K tar xvfz filename > pyref_cn.zip 20-Oct-2004 14:55 314K > pyscponly.py 20-Oct-2004 14:55 815 > pyshell.txt 20-Oct-2004 14:55 1.1K > python_wdsl.pdf 20-Oct-2004 15:00 134K > python network programming.pdf 20-Oct-2004 14:59 309K ?§ > tkinter.chm 20-Oct-2004 14:21 315K > tkinter.pdf 20-Oct-2004 14:22 415K > tutorial python.pdf 20-Oct-2004 14:22 268K > Advanced_Python_programming [miex.org].pdf > An Introduction to Tkinter.chm > Dive into Python [miex.org].pdf > GUI_Programming_with_Python_-_QT_Edition [miex.org].chm > Game Scripting in Python [miex.org].doc > How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002 > [miex.org].pdf > How_to_think_like_a_computer_scientist [miex.org].pdf > Instant_Hacking_With_Python [miex.org].zip > New Riders - Jython for Java Programmers [miex.org].chm > New Riders - Python Essential Reference, 2Nd Ed - 2001 [miex.org].chm > OReilly - Core Python Programming [miex.org].pdf > OReilly - Learning Python ed2 [miex.org].chm > OReilly - Programming Python ed2 [miex.org].chm > OReilly - Python & XML [miex.org].pdf > OReilly - Python In A Nutshell [miex.org].chm > OReilly - Python Pocket Reference,2001 ed2 [miex.org].chm > OReilly - Python Programming on Win32 [miex.org].chm > OReilly - Python Standard Library [miex.org].chm > Preiss,_B.R._-_Data_Structures_and_Algorithms_in_Python_(2004) > [miex.org].chm > Premier.Press,.Python.Programming.for.the.Absolute.Beginner.(2003).LiB.ShareConnector > [miex.org].chm > Prentice Hall - Core Python Programming (Fixed).chm > Python network programming.pdf > Python[1].Cookbook.2nd.chm > Python_2.1_bible_(idg_2001)_[pdf] [miex.org].zip > Python_Developer's_Handbook_(2000) [miex.org].chm > Race_Evolution_Behavior.pdf > Sams - Teach Yourself Python In 24 Hours.rar > SciTE editor for Python > Scientific Computing in Python [miex.org].pdf > Text_Processing_in_Python_(Addison_Wesley-2003) [miex.org].chm > Thinking in Python [miex.org].chm > VIM editor for Python > mec.Python Programming with the Java Class Libraries.2002 > [miex.org].chm > modpython [miex.org].pdf > numpy_tutorial [miex.org].pdf > python-doc-2.4.chm > skip4Python [miex.org].chm > OReilly - Learning Python 17-Dec-2005 04:49 > OReilly - Programming Python 2nd Ed 17-Dec-2005 04:50 > Oreilly.Learning.Python.2nd.Edition.eBook-LiB 17-Dec-2005 04:53 > Oreilly.Python.In.A.Nutshell.eBook-LiB 17-Dec-2005 04:58 > Sams - Teach Yourself Python In 24 Hours 17-Dec-2005 05:43 > Thinking in python 17-Dec-2005 05:43 > dive in to python 17-Dec-2005 04:46 > instant-hacking.php 17-Dec-2005 04:47 > Advanced_Python_programming.pdf 28-Apr-2004 16:36 194K > Bourne S
Re: how to know if socket is still connected
Grant Edwards wrote: > On 2006-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > > > serverhost = 'xxx.xxx.xxx.xxx' > > serverport = 9520 > > aeris_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > > aeris_sockobj.connect((serverhost,serverport)) > > > > while 1: > > do this or that with socket, > > send and receive info. > > yadda yadda yadda > > > > works well, but sometimes the server drops the connection. so, > > what i need is something that will let me know if the > > connection is still ok, if not will reconnect. > > If the server has closed the connection, then a recv() on the > socket will return an empty string "", and a send() on the > socket will raise an exception. > > > what i thought, since it only lets you connect on a certain > > port one at a time, that i could use a try-except to connect > > every time, if it could not connect (because it already is) > > then i would just continue on. But if it is not connected, it > > would reconnect. that is what brings me here. Seems like it > > would work, but is there a better way? > > I don't see why the normal send() and recv() semantics aren't > sufficient. > > -- > Grant Edwards grante Yow! I'm an East Side > at TYPE... >visi.com like this ? databack = aeris_sockobj.recv(2048) if databack: view_msg = 'caught request acknowlage %s bytes \n' % len(databack) else: view_msg = 'fail to recieve data from aeris server\n' then put the reconnect in the else: block ? thanks thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
David Hopwood <[EMAIL PROTECTED]> wrote: > Chris Smith wrote: > > If checked by execution, yes. In which case, I am trying to get my head > > around how it's any more true to say that functional languages are > > compilable postconditions than to say the same of imperative languages. > > A postcondition must, by definition [*], be a (pure) assertion about the > values that relevant variables will take after the execution of a subprogram. Okay, my objection was misplaced, then, as I misunderstood the original statement. I had understood it to mean that programs written in pure functional languages carry no additional information except for their postconditions. -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Joachim Durchholz wrote: > Marshall schrieb: > > > > Good point. Perhaps I should have said "relational algebra + > > variables with assignment." It is interesting to consider > > assignment vs. the more restricted update operators: insert, > > update, delete. > > Actually I see it the other way round: assignment is strictly less > powerful than DML since it doesn't allow creating or destroying > variables, while UPDATE does cover assignment to fields. Oh, my. Well, for all table variables T, there exists some pair of values v and v', such that we can transition the value of T from v to v' via assignment, but not by any single insert, update or delete. The reverse is not true. I would consider that a solid demonstration of which one is more powerful. Further, it is my understanding that your claim of row identity *depends* on the restricted nature of DML; if the only mutator operation is assignment, then there is definitely no record identity. > (However, it's usually new+assignment+delete vs. INSERT+UPDATE+DELETE, > at which point there is not much of a difference.) I am not sure what this means. Delete can be expressed in terms of assignment. (As can insert and update.) (Assignment can also be expressed in terms of insert and delete.) I don't know what "new" would be in a value-semantics, relational world. So I would say it's assignment vs. INSERT+UPDATE+DELETE, but perhaps I'm not understanding what you mean. Assignment by itself is complete. Insert and delete together are complete. > > Okay. At this point, though, the term aliasing has become extremely > > general. I believe "i+1+1" is an alias for "i+2" under this definition. > No, "i+1+1" isn't an alias in itself. It's an expression - to be an > alias, it would have to be a reference to something. > > However, a[i+1+1] is an alias to a[i+2]. Not that this is particularly > important - 1+1 is replacable by 2 in every context, so this is > essentially the same as saying "a[i+2] is an alias of a[i+2]", which is > vacuously true. > >>> > >>> To me, the SQL with the where clause is like i+2, not like a[2]. > >> I'd say WHERE is like [i+2]: neither is valid on its own, it's the > >> "selector" part of a reference into a table. > > > > Is it possible you're being distracted by the syntax? > > I think that's very, very unlikely ;-) Well, I just thought I'd ask. :-) > > WHERE is a > > binary operation taking a relation and a filter function. I don't > > think of filters as being like array indexing; do they appear > > analogous to you? > > Yes. > > Filters are just like array indexing: both select a subset of variables > from a collection. I can't agree with this wording. A filter produces a collection value from a collection value. I don't see how variables enter in to it. One can filter either a collection constant or a collection variable; if one speaks of filtering a collection variable, on is really speaking of filtering the collection value that the variable currently contains; filtering is not an operation on the variable as such, the way the "address of" operator is. Note you can't update the result of a filter. > In SQL, you select a subset of a table, in a > programming language, you select a subset of an array. > > (The SQL selection mechanism is far more flexible in the kinds of > filtering you can apply, while array indexing allows filtering just by > ordinal position. However, the relevant point is that both select things > that can be updated.) When you have been saying "select things that can be updated" I have been assuming you meant that one can derive values from variables, and that some other operation can update that variable, causing the expression, if re-evaluated, to produce a different value. However the phrase also suggests that you mean that the *result* of the select can *itself* be updated. Which one do you mean? (Or is there a third possibility?) > >> I admit that identity cannot be reliably established in SQL. The > >> identity of a record isn't available (unless via OID extensions). > >> However, it is there and it can have effect. > > > > Yes, I think I see what you mean now. This is in part a consequence > > of the restricted update operators. > > I don't think so. You can update SQL records any way you want. > The unavailability of a record identity is due to the fact that, well, > it's unavailable in standard SQL. I disagree. The concept of record-identity is quite tenuous, and depends on specifics of SQL semantics. (In fact I'm not entirely convinced it's definitely there even in SQL.) It certainly does not hold in, say, set theory. Set elements do not have identity; they only have value. If we have a set-semantics language that supports set variables with assignment, we still do not have element-identity. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: how to know if socket is still connected
On 2006-07-16, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > serverhost = 'xxx.xxx.xxx.xxx' > serverport = 9520 > aeris_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM) > aeris_sockobj.connect((serverhost,serverport)) > > while 1: > do this or that with socket, > send and receive info. > yadda yadda yadda > > works well, but sometimes the server drops the connection. so, > what i need is something that will let me know if the > connection is still ok, if not will reconnect. If the server has closed the connection, then a recv() on the socket will return an empty string "", and a send() on the socket will raise an exception. > what i thought, since it only lets you connect on a certain > port one at a time, that i could use a try-except to connect > every time, if it could not connect (because it already is) > then i would just continue on. But if it is not connected, it > would reconnect. that is what brings me here. Seems like it > would work, but is there a better way? I don't see why the normal send() and recv() semantics aren't sufficient. -- Grant Edwards grante Yow! I'm an East Side at TYPE... visi.com -- http://mail.python.org/mailman/listinfo/python-list
Re: How to lock files (the easiest/best way)?
In article <[EMAIL PROTECTED]>, Jim Segrave <[EMAIL PROTECTED]> wrote: >except OSError, e: >if e.errno != errno.EEXIST: this should read: if e.errno != errno.ENOENT: (it was left with EEXIST from testing this code by forcing an error, as the code for this failure requires a very tight race condition to test) >sys.exit("%s exists but stat() failed: %s" % > (lockfile, e.strerror)) ># we didn't create the lockfile, so it did exist, but it's -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: How to lock files (the easiest/best way)?
In article <[EMAIL PROTECTED]>, Eric S. Johansson <[EMAIL PROTECTED]> wrote: >Elmo Mäntynen wrote: >> Is there something better than using fnctl? It seems a bit intimidating >> with a quick look. > >try the portlocker wrapper from the active state cookbook. I have a >version which has been slightly updated for more modern pythons. I >really need to make my darcs repository visible so you could get it. > >Alternatively, you can try the makedir trick. Creating directories are >atomic operations if it exists, you will get error message. If it >doesn't, you will get a directory and thereby capture the lock. You >delete the directory when you release the lock. > >crude but effective. I used it in building a file based queue system. >You know, I really should learn how to build eggs because I have a whole >bunch of little pieces of software that would probably be useful to others. Here's a more complete file locking scheme which uses a lockfile with the O_CREAT and O_EXCL flags to make the creation atomic. If it gets the lock, it writes its PID in readable form in the file. It also does two other things: If you know that no process should lock the file for more than a fixed period of time, it will retry once/second as long as the lock file is not older than that fixed period of time. If it is older, it will report the problem, including the PID of the locking process and exit. This caters for a process which has set the lock file and then terminates without removing it (which can happen do to an application or server crash). -- import os import errno import sys import time import stat # the maximum reasonable time for aprocesstobe max_wait = 10 lockfile = "/tmp/mylock" while True: try: fd = os.open(lockfile, os.O_EXCL | os.O_RDWR | os.O_CREAT) # we created the lockfile, so we're the owner break except OSError, e: if e.errno != errno.EEXIST: # should not occur raise try: # the lock file exists, try to stat it to get its age # and read it's contents to report the owner PID f = open(lockfile, "r") s = os.stat(lockfile) except OSError, e: if e.errno != errno.EEXIST: sys.exit("%s exists but stat() failed: %s" % (lockfile, e.strerror)) # we didn't create the lockfile, so it did exist, but it's # gone now. Just try again continue # we didn't create the lockfile and it's still there, check # its age now = int(time.time()) if now - s[stat.ST_MTIME] > max_wait: pid = f.readline() sys.exit("%s has been locked for more than " \ "%d seconds (PID %s)" % (lockfile, max_wait, pid)) # it's not been locked too long, wait a while and retry f.close() time.sleep(1) # if we get here. we have the lockfile. Convert the os.open file # descriptor into a Python file object and record our PID in it f = os.fdopen(fd, "w") f.write("%d\n" % os.getpid()) f.close() -- Jim Segrave ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Re: embedding executable code in a regular expression in Python
On 2006-07-16, Avi Kak <[EMAIL PROTECTED]> wrote: > Folks, > > Does regular expression processing in Python allow for executable > code to be embedded inside a regular expression? > > For example, in Perl the following two statements > > $regex = qr/hello(?{print "saw hello\n"})mello(?{print "saw > mello\n"})/; > "jellohellomello" =~ /$regex/; > > will produce the output > > saw hello > saw mello > > Is it possible to do the same in Python with any modules that come > with the standard distribution, or with any other modules? You can use sub and make the replacement pattern a function (or any "callable" thing) and it gets called back with the match object: import re def f(mo): if "hello" in mo.groups(): print "saw hello" if "mello" in mo.groups(): print "saw mello" re.sub(r'(hello)(mello)', f, "jellohellomello") Actually I didn't know you could do that in Perl. The time I've found this useful in Python is substitutions to convert e.g. "background-color" into "backgroundColor"; a function turns the c into C. I always assumed in Perl you would need to use eval for this, but perhaps there is another way. -- http://mail.python.org/mailman/listinfo/python-list
Re: embedding executable code in a regular expression in Python
- Original Message - From: "Avi Kak" <[EMAIL PROTECTED]> Newsgroups: comp.lang.python To: Sent: Sunday, July 16, 2006 11:05 PM Subject: embedding executable code in a regular expression in Python > Folks, > > Does regular expression processing in Python allow for executable > code to be embedded inside a regular expression? > > For example, in Perl the following two statements > > $regex = qr/hello(?{print "saw hello\n"})mello(?{print "saw > mello\n"})/; > "jellohellomello" =~ /$regex/; > > will produce the output > > saw hello > saw mello > > Is it possible to do the same in Python with any modules that come > with the standard distribution, or with any other modules? > > Thanks in advance for any help, > > Avi Kak ([EMAIL PROTECTED]) > > -- > http://mail.python.org/mailman/listinfo/python-list There's a new module out that can do it like this: import SE Stream_Editor = SE.SE (' "~[hm]ello~=print \'saw =\'\n" ') for line in Stream_Editor ('yellomellojellohello').split ('\n'): exec ("%s" % line) saw mello saw hello You'll find SE in the Cheese Shop. It has been commented favorably. I wouldn't comment it, because I wrote it. Regards Frederic -- http://mail.python.org/mailman/listinfo/python-list
Cool Python Ebooks Site
http://cooldogebooks.blogspot.com/2006/05/python-ebooks.html Here is a cool site were you can preview python ebooks. Here are just a few listed Advanced_Python_programming.pdf 20-Oct-2004 14:23 194K EP2003CppExtensions.pdf 20-Oct-2004 14:25 2.0M GUI Programming with Python.zip 20-Oct-2004 14:36 16M Game_Programming_with_Python.pdf 20-Oct-2004 14:26 67K How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002.pdf 20-Oct-2004 14:37 863K How_to_think_like_a_computer_scientist.pdf 20-Oct-2004 14:36 720K New Riders - Jython for Java Programmers.chm 20-Oct-2004 14:38 713K OReilly - Core Python Programming.pdf 20-Oct-2004 14:43 7.8M OReilly - Learning Python.chm 20-Oct-2004 14:44 967K OReilly - Programming Python 2nd Ed.chm 20-Oct-2004 14:48 6.4M OReilly - Python & XML.pdf 20-Oct-2004 14:49 2.0M OReilly - Python Cookbook.chm 20-Oct-2004 14:49 1.0M OReilly - Python Developer's Handbook.rar 20-Oct-2004 14:50 1.6M OReilly - Python In A Nutshell eBook-LiB.chm 20-Oct-2004 14:51 1.1M OReilly - Python Programming on Win32.chm 20-Oct-2004 14:52 2.1M OReilly - Python Standard Library.chm 20-Oct-2004 14:52 356K Python???rar 20-Oct-2004 16:09 64M Python.pdf 20-Oct-2004 14:59 391K Python 2.1 Bible.pdf 20-Oct-2004 14:58 6.3M Python Essential Reference, Second Edition.rar 20-Oct-2004 14:58 536K Python Pocket Reference.chm 20-Oct-2004 14:59 175K PythonWindowsTutorial.doc 20-Oct-2004 16:10 1.9M Python_Programming_with_the_JavaT_Class_Libraries_-_Addison_Wesley_-_2002.chm 20-Oct-2004 15:00 1.8M CD-ROM Sams - Teach Yourself Python In 24 Hours.rar 20-Oct-2004 15:52 2.4M Thinking in python.chm 20-Oct-2004 14:21 178K an-introduction-to-tkinter.pdf 20-Oct-2004 14:23 733K diveintopython-pdf-4.3.zip 20-Oct-2004 14:24 519K iconcrib.pdf 20-Oct-2004 14:37 152K icongraphics.pdf 20-Oct-2004 14:37 138K mailgate/ 26-Oct-2004 02:27 - modpython.pdf 20-Oct-2004 14:38 164K pil-handbook.pdf 20-Oct-2004 14:53 486K pil.pdf 20-Oct-2004 14:53 232K portal.tar.gz 20-Oct-2004 14:53 45K tar xvfz filename pygtk2tutorial.tar.gz 20-Oct-2004 14:54 1.6M tar xvfz filename pygtk2tutorial.tgz 20-Oct-2004 14:54 775K tar xvfz filename pyref_cn.zip 20-Oct-2004 14:55 314K pyscponly.py 20-Oct-2004 14:55 815 pyshell.txt 20-Oct-2004 14:55 1.1K python_wdsl.pdf 20-Oct-2004 15:00 134K python network programming.pdf 20-Oct-2004 14:59 309K ?§ tkinter.chm 20-Oct-2004 14:21 315K tkinter.pdf 20-Oct-2004 14:22 415K tutorial python.pdf 20-Oct-2004 14:22 268K Advanced_Python_programming [miex.org].pdf An Introduction to Tkinter.chm Dive into Python [miex.org].pdf GUI_Programming_with_Python_-_QT_Edition [miex.org].chm Game Scripting in Python [miex.org].doc How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002 [miex.org].pdf How_to_think_like_a_computer_scientist [miex.org].pdf Instant_Hacking_With_Python [miex.org].zip New Riders - Jython for Java Programmers [miex.org].chm New Riders - Python Essential Reference, 2Nd Ed - 2001 [miex.org].chm OReilly - Core Python Programming [miex.org].pdf OReilly - Learning Python ed2 [miex.org].chm OReilly - Programming Python ed2 [miex.org].chm OReilly - Python & XML [miex.org].pdf OReilly - Python In A Nutshell [miex.org].chm OReilly - Python Pocket Reference,2001 ed2 [miex.org].chm OReilly - Python Programming on Win32 [miex.org].chm OReilly - Python Standard Library [miex.org].chm Preiss,_B.R._-_Data_Structures_and_Algorithms_in_Python_(2004) [miex.org].chm Premier.Press,.Python.Programming.for.the.Absolute.Beginner.(2003).LiB.ShareConnector [miex.org].chm Prentice Hall - Core Python Programming (Fixed).chm Python network programming.pdf Python[1].Cookbook.2nd.chm Python_2.1_bible_(idg_2001)_[pdf] [miex.org].zip Python_Developer's_Handbook_(2000) [miex.org].chm Race_Evolution_Behavior.pdf Sams - Teach Yourself Python In 24 Hours.rar SciTE editor for Python Scientific Computing in Python [miex.org].pdf Text_Processing_in_Python_(Addison_Wesley-2003) [miex.org].chm Thinking in Python [miex.org].chm VIM editor for Python mec.Python Programming with the Java Class Libraries.2002 [miex.org].chm modpython [miex.org].pdf numpy_tutorial [miex.org].pdf python-doc-2.4.chm skip4Python [miex.org].chm OReilly - Learning Python 17-Dec-2005 04:49 OReilly - Programming Python 2nd Ed 17-Dec-2005 04:50 Oreilly.Learning.Python.2nd.Edition.eBook-LiB 17-Dec-2005 04:53 Oreilly.Python.In.A.Nutshell.eBook-LiB 17-Dec-2005 04:58 Sams - Teach Yourself Python In 24 Hours 17-Dec-2005 05:43 Thinking in python 17-Dec-2005 05:43 dive in to python 17-Dec-2005 04:46 instant-hacking.php 17-Dec-2005 04:47 Advanced_Python_programming.pdf 28-Apr-2004 16:36 194K Bourne Shell, shell.pdf 01-Sep-2004 09:14 185K How_To_Think_Like_A_Computer_Scientist-Learning_With_Python-2002.pdf 28-Apr-2004 16:36 863K Mastering_Regular_Expressions.pdf 25-Apr-2003 18:33 5.8M OReilly - ProgrammingPython2ndEd.chm 28-Apr-2004 16:37 6.4M OReilly - Python Standard Library.chm 28-Apr-2004 16:37 356K OReilly.Learning.the.bash.Shell.2nd.Edition.chm 24-Feb-2005 10:14 636K
Re: Embedding exe file
Hi! This script : import base64 data=open("D:\\toto.exe","rb").read() data64='''import base64,os data="""'''+base64.b64encode(data)+'''""" f=open(r"C:\\temporaire.exe","wb").write(base64.b64decode(data)) os.system(r"C:\\temporaire.exe") ''' f=open("64exe.py","w").write(data64) Create a script (ascii file) "64exe.py" with the exe "D:\toto.exe" The script "64exe.py" (re)-create C:\temporaire.exe and run it. It's a little basic template, for your answer. *sorry for my bad english* Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
After some consideration that is the approach I will head actually. Thank you for the help swaying my decision. "Sybren Stuvel" > In that case, I'd really go with Mark's idea of turning it into a web > service. You could use XML-RPC over SSL to secure the communication > between a client program and the (secret-code) server. > > Of course, you could also go the 100% web approach, but that has the > downside that you have to work with HTML instead of a proper GUI like > Qt, and that you'll have to support all kinds of different browsers > (MSIE is really bad with CSS support, for instance.) > > Sybren > -- > The problem with the world is stupidity. Not saying there should be a > capital punishment for stupidity, but why don't we just take the > safety labels off of everything and let the problem solve itself? > Frank Zappa -- http://mail.python.org/mailman/listinfo/python-list
embedding executable code in a regular expression in Python
Folks, Does regular expression processing in Python allow for executable code to be embedded inside a regular expression? For example, in Perl the following two statements $regex = qr/hello(?{print "saw hello\n"})mello(?{print "saw mello\n"})/; "jellohellomello" =~ /$regex/; will produce the output saw hello saw mello Is it possible to do the same in Python with any modules that come with the standard distribution, or with any other modules? Thanks in advance for any help, Avi Kak ([EMAIL PROTECTED]) -- http://mail.python.org/mailman/listinfo/python-list
Calling python functions from C
Could anybody tell me how to call python modules from C. e.g. my Python module : def add(a,b) return(a+b) How can I call "add.py" from C? Please post any simple example. I have read Python embedding in Python Manual but I get "ImportError" all the time? Any help would be appreciated ! R. -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.modules and __main__ obscureness
Fuzzyman wrote: > That was a quick response. :-) > > Thanks very much. Sigh.. When I'm drowning in arcane win32 c++ crap, I tend to jump on anything interesting on python-list. It feels like a breath of fresh air! [sreeram;] signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: How to lock files (the easiest/best way)?
Elmo Mäntynen wrote: > Is there something better than using fnctl? It seems a bit intimidating > with a quick look. try the portlocker wrapper from the active state cookbook. I have a version which has been slightly updated for more modern pythons. I really need to make my darcs repository visible so you could get it. Alternatively, you can try the makedir trick. Creating directories are atomic operations if it exists, you will get error message. If it doesn't, you will get a directory and thereby capture the lock. You delete the directory when you release the lock. crude but effective. I used it in building a file based queue system. You know, I really should learn how to build eggs because I have a whole bunch of little pieces of software that would probably be useful to others. ---eric -- http://mail.python.org/mailman/listinfo/python-list
Re: insert method in ElementTree
[EMAIL PROTECTED] wrote: > My request for advice is this: instead of creating a second XML > document that represents the output, would it be possible to expand the > input XML document as needed? I was thinking that the program could > iterate through all the elements. As it is iterating, it would check > for the createAnotherWhenCondition attribute. If encountered and if > the condition were true, the program would: > - make a copy of the parent element (perhaps with copy.copy) > - use the insert method to insert the just-created copy > Where I'm struggling is figuring out what the index argument should > be in the insert method. I recommend not using the insert method; instead, build a new list of elements and set the parent to the new list. Another problem is that you have to have the parent node around, since children don't indicate their parents. Using getiterator won't work. I recommend a recursive function instead. Something like this should do it: def expand_children(parent): if len(parent) == 0: return newchildren = [] for child in parent: expand_children(child) # recursively process child nodes if : newchildren.append(child) # or copy.copy(child) newchildren.append(child) parent[:] = newchildren # slice assign So, basically, for each node, you build a list of children in parallel, making duplicates as necessary, then use slice assignment to set the parent's children to be the new list. No more mucking around with indexes. Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall schrieb: > > Good point. Perhaps I should have said "relational algebra + > variables with assignment." It is interesting to consider > assignment vs. the more restricted update operators: insert, > update, delete. Actually I see it the other way round: assignment is strictly less powerful than DML since it doesn't allow creating or destroying variables, while UPDATE does cover assignment to fields. (However, it's usually new+assignment+delete vs. INSERT+UPDATE+DELETE, at which point there is not much of a difference.) > Okay. At this point, though, the term aliasing has become extremely > general. I believe "i+1+1" is an alias for "i+2" under this definition. No, "i+1+1" isn't an alias in itself. It's an expression - to be an alias, it would have to be a reference to something. However, a[i+1+1] is an alias to a[i+2]. Not that this is particularly important - 1+1 is replacable by 2 in every context, so this is essentially the same as saying "a[i+2] is an alias of a[i+2]", which is vacuously true. >>> >>> To me, the SQL with the where clause is like i+2, not like a[2]. >> I'd say WHERE is like [i+2]: neither is valid on its own, it's the >> "selector" part of a reference into a table. > > Is it possible you're being distracted by the syntax? I think that's very, very unlikely ;-) > WHERE is a > binary operation taking a relation and a filter function. I don't > think of filters as being like array indexing; do they appear > analogous to you? Yes. Filters are just like array indexing: both select a subset of variables from a collection. In SQL, you select a subset of a table, in a programming language, you select a subset of an array. (The SQL selection mechanism is far more flexible in the kinds of filtering you can apply, while array indexing allows filtering just by ordinal position. However, the relevant point is that both select things that can be updated.) >> I admit that identity cannot be reliably established in SQL. The >> identity of a record isn't available (unless via OID extensions). >> However, it is there and it can have effect. > > Yes, I think I see what you mean now. This is in part a consequence > of the restricted update operators. I don't think so. You can update SQL records any way you want. The unavailability of a record identity is due to the fact that, well, it's unavailable in standard SQL. Regards, Jo -- http://mail.python.org/mailman/listinfo/python-list
how to know if socket is still connected
lo there, i have a simple app that connects to a socket to get info from a server i looks like this serverhost = 'xxx.xxx.xxx.xxx' serverport = 9520 aeris_sockobj = socket.socket(socket.AF_INET, socket.SOCK_STREAM) aeris_sockobj.connect((serverhost,serverport)) while 1: do this or that with socket, send and receive info. yadda yadda yadda works well, but sometimes the server drops the connection. so, what i need is something that will let me know if the connection is still ok, if not will reconnect. what i thought, since it only lets you connect on a certain port one at a time, that i could use a try-except to connect every time, if it could not connect (because it already is) then i would just continue on. But if it is not connected, it would reconnect. that is what brings me here. Seems like it would work, but is there a better way ? this kinda seems like a dirty hack. any opinions ? thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.modules and __main__ obscureness
K.S.Sreeram wrote: > Fuzzyman wrote: > > This code behaves differently when entered into an interactive > > interpreter session. When run as a program you will see that module and > > namespace have both become None !! > > Thats because the reference count to the current '__main__' module goes > to 0, and the module object gets deleted along with its globals 'module' > and 'namespace'. The code keeps working because the codeobject is > retained by the interpreter. > > To make it work, simply retain a reference to the existing module, > before overwriting with the new module. > > sys.blahblah = sys.modules['__main__'] > sys.modules['__main__'] = module > > [sreeram;] That was a quick response. :-) Thanks very much. Fuzzyman http://www.voidspace.org.uk/python/index.shtml > > > --enigF3B976014D166081569F1C89 > Content-Type: application/pgp-signature > Content-Disposition: inline; > filename="signature.asc" > Content-Description: OpenPGP digital signature > X-Google-AttachSize: 253 -- http://mail.python.org/mailman/listinfo/python-list
Re: Very simple speed benchmark of few string substitions ways
Rafal Zawadzki wrote: > I was curious of performance new Python 2.4 "Simpler String Substitutions" > so I decided to benchmark it. What I get > > [EMAIL PROTECTED]:~/python/benchmarks$ python template.py > Normal python string substition = 0.017546 seconds >PEP 292: Simpler String Substitutions = 0.243750 seconds >Jinja template system = 0.821844 seconds > Cheetah template system = 26.842872 seconds That's interesting. You know what? I compared my swiss knife and my spoon recently and found that my swiss knife is slower in handling as it requires additional opening. So I decided to stop using it. I just don't get why they keep producing these things. Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: sys.modules and __main__ obscureness
Fuzzyman wrote: > This code behaves differently when entered into an interactive > interpreter session. When run as a program you will see that module and > namespace have both become None !! Thats because the reference count to the current '__main__' module goes to 0, and the module object gets deleted along with its globals 'module' and 'namespace'. The code keeps working because the codeobject is retained by the interpreter. To make it work, simply retain a reference to the existing module, before overwriting with the new module. sys.blahblah = sys.modules['__main__'] sys.modules['__main__'] = module [sreeram;] signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: insert method in ElementTree
[EMAIL PROTECTED] wrote: > Where I'm struggling is figuring out what the index argument should > be in the insert method. Using the example above > > # assume rootElement is the root of the input XML > xList = rootElement.getiterator() > idx = 0 > for x in xList: > # mix of pseudo-code and Python code > if (this element has createAnotherWhenCondition attribute) > and > (y is true): > jcopy = copy.copy(x) > ??.insert(??, jcopy) > idx = idx + 1 ElementTree does not have parent pointers. You have to look one element level ahead to add the child. You can use a parent stack for this, although getiterator() is not very helpful in that case as it does not tell you when it backtracks. If you want to use lxml instead, you can either * access the parent directly (element.getparent()) and add the child there or * use the iterwalk() function to add the child when backtracking up the tree or * implement the whole thing in XSLT (with a custom evaluator function in Python). There may also be other ways to do it. Just give it a try: http://codespeak.net/lxml/ http://cheeseshop.python.org/pypi/lxml/1.1alpha Stefan -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall <[EMAIL PROTECTED]> wrote: > Is it possible you're being distracted by the syntax? WHERE is a > binary operation taking a relation and a filter function. I don't > think of filters as being like array indexing; do they appear > analogous to you? (Always a difficult question because often > times A and B share some qualities and not others, and > what does one call that?) This is definitely a good question. Nevertheless, I think we're fooling ourselves if we decide that we've made progress by defining part of the problem out of existence. The original problem was that when there are several ways of getting access to something that is identical (rather than just equal), this causes problems for invariant checking. These several ways of accessing data are being called 'aliasing' -- I have no comment on whether that's standard usage or not, because I don't know. I suspect that aliasing is normally used for something closer to the physical level. The point is that whatever "aliasing" really means, what we're discussing is having two paths by which one may access identical data. So there are infinitely complex ways in which this can occur. I can have pointers that are aliased. I can have integers, which by themselves are just plain values, but can alias each other as indices into an array. I can have strings that do the same thing for an associative array. I can, of course, have arbitrarily more complex data structures with exactly the same issue. I can also have two different WHERE clauses, which when applied to the same relation yield exactly the same set of tuples. The problem arises when code is written to update some value (or set of tuples, in the SQL case, since definitions differ there) using one pointer/int/string/WHERE clause/etc, and at the same time an invariant was written using the other pointer/int/WHERE/etc, the result is that either of: a) The compiler has to be able to prove that the two are not aliased b) The compiler has to re-evaluate the invariant from scratch when this operation is performed. (Yeah, there's actually a whole continuum between a and b, based on more limited abilities of the compiler to prove things. I'm oversimplifying, and I think it's rather benign in this case.) So in this sense, a WHERE clause is a binary operation in exactly the same way that an array indexing expression is a binary operation, and both are capable of aliasing in at least this logical sense. Now it's certainly true that languages with unrestricted pointers are less successful at limiting the scope of re-evaluation of invariants. In the array or SQL relation cases, there's a limited set of value/tuple modifications that might cause the invariant to need rechecking (specifically those that point to the same array, or to the relation or one of its views). A language with unrestricted untyped pointers, if it doesn't get lucky with the capture analysis, may have to re-evaluate all invariants in the application on any given assignment. Nevertheless, the re-evaluation of the invariant still needs to be done. -- Chris Smith - Lead Software Developer /Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
sys.modules and __main__ obscureness
Hello all, I am messing with namespaces, so that code I exec thinks it is executing in the __main__ module. I have the following code : import imp import sys # can't call the module '__main__' or 'new_module' returns the real one module = imp.new_module('_') namespace = module.__dict__ namespace['__name__'] = '__main__' # next put things into the names # e.g. : namespace['variable'] = 3 sys.modules['__main__'] = module print module print namespace import __main__ print __main__.__dict__['variable'] This code behaves differently when entered into an interactive interpreter session. When run as a program you will see that module and namespace have both become None !! However the code works, but to get access to the namespace again I have to import __main__. I just wondered why ? All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
We Chris's stick together, as always. Marshall <[EMAIL PROTECTED]> wrote: > > Unfortunately, they are the right level. Actually,the right level > > might even be lower, the fields within a record, but that's moving > > even farther away from the direction you wish to go. The right level > > is the lowest level at which the programmer can see and manipulate > > values. > > But how is this not always "the bit"? First of all, we should be consistent in speaking about the logical language semantics, which may not include bits anyway. That said, if bits were the primitive concept of data in a language, then we'd be able to get away with talking about higher-level concepts because we agree to always manipulate a larger structure (a byte, for example) as a pure value. If we were using bitwise operators, then we wouldn't be able to get away with it, for example. That said, it's also quite possible to consider aliasing on higher levels as well; it's just not possible to point out the lack of aliasing for higher levels of abstraction, and thus conclude that no aliasing exists. Aliasing is still possible for entities within those layers of abstraction. -- Chris Smith - Lead Software Developer / Technical Trainer MindIQ Corporation -- http://mail.python.org/mailman/listinfo/python-list
insert method in ElementTree
O/S: Win2K Vsn of Python: 2.4 Example: text for c text for d text for f text for g> text for i text for k text for l text for m Python script reads XML document above into ElementTree. The script outputs an XML document that is based on the XML document above. The output XML will contain all of the elements in the XML document above. If there is a parent element that does not have the createAnotherWhencondition attribute, then that element and its descendants will be part of the output XML. If there is a parent element with atribute createAnotherWhenCondition and that condition is true, then the output XML should contain another instance of the parent element below the original instance. For example if x were true when the script ran, the output XML document would be: text for c text for d text for c text for d text for f text for g> text for i text for k text for l text for m> The example attempts to illustrate that the createAnotherWhenCondition attribute may appear in parent elements that are at different levels in the hierarchy; the element is at the 2nd level in the hierarchy, and the element is at the 3rd level. There will never be 'nesting', i.e. a parent element with the createAnotherWhenCondition attribute that is a descendant of a parent element with a createAnotherWhenCondition attribute. I'm pretty sure I can figure out how to create the output XML by creating a second XML document. It would be created by iterating through the input XML. When a new element is encountered, an element or subelement would be created in the output XML. When a parent element with the createAnotherWhenCondition is encountered and that condition is true, I think I can figure out how to propagate another instance of that parent element and all its descendants. My request for advice is this: instead of creating a second XML document that represents the output, would it be possible to expand the input XML document as needed? I was thinking that the program could iterate through all the elements. As it is iterating, it would check for the createAnotherWhenCondition attribute. If encountered and if the condition were true, the program would: - make a copy of the parent element (perhaps with copy.copy) - use the insert method to insert the just-created copy Where I'm struggling is figuring out what the index argument should be in the insert method. Using the example above # assume rootElement is the root of the input XML xList = rootElement.getiterator() idx = 0 for x in xList: # mix of pseudo-code and Python code if (this element has createAnotherWhenCondition attribute) and (y is true): jcopy = copy.copy(x) ??.insert(??, jcopy) idx = idx + 1 If the program were run when y was true, then I believe it would encounter the element when idx has a value of 9. Conceptually, I think that jcopy should be inserted after the element and before the element. But I'm not sure that 9 (the index in the list created from rootElement.getiterator()) has any relevance for this insert task. Assuming that I want to insert jcopy after the element and before the element: a) would the insert need to be done relative to the element, which is the parent of b) if so, would the index argument in the insert method be relative index within the element? -- http://mail.python.org/mailman/listinfo/python-list
RE: Regular Expression problem
> > Less is more: > > pat = re.compile(r'href="([^"]+)') > pat.search(your_link) > > Be sure to also catch: And it's not certain whether the OP is interested in tags like: -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Chris F Clark wrote: > "Marshall" <[EMAIL PROTECTED]> wrote: > > In general, I feel that "records" are not the right conceptual > > level to think about. > > Unfortunately, they are the right level. Actually,the right level > might even be lower, the fields within a record, but that's moving > even farther away from the direction you wish to go. The right level > is the lowest level at which the programmer can see and manipulate > values. But how is this not always "the bit"? > > I do not see that they have > > any identity outside of their value. We can uniquely identify > > any particular record via a key, but a table may have more > > than one key, and an update may change the values of one > > key but not another. So it is not possible in general to > > definitely and uniquely assign a mapping from each record > > of a table after an update to each record of the table before > > the update, and if you can't do that, then where > > is the record identity? > > I don't know if your point of having two keys within one table amkes a > difference. If one can uniquely identify a record, then it has > identity. The fact that there is another mapping where one may not be > able to uniquely identify the record is not necessarily relevant. The issue with two keys is that the keys may not *agree* on the mapping before vs. after the update. > > For example, we might ask in C, if we update a[i], will > > the value of b[j] change? And we can't say, because > > we don't know if there is aliasing. But in Fortran, we > > can say that it won't, because they are definitely > > different variables. > > Unfortunately, your statement about FORTRAN is not true, if a and b > are parameters to a subroutine (or members of a common block, or > equivalenced, or ...), then an update of a[i] might change b[j]. Ah, common blocks. How that takes me back! But your point is a good one; I oversimplified. > Marshall again: > > Fair enough. I could only remember three, but I was sure someone > > else could name more. :-) > > There actual are some more, but very rare, for example there was call- > by-text-string, which is sort of like call-by-name, but allows a > parameter to reach into the calling routine and mess with local > variables therein. Most of the rare ones have really terrible > semantics, and are perhaps best forgotten except to keep future > implementors from choosing them. For example, call-by-text-string is > really easy to implement in a naive interpreter that reparses each > statement at every invocation, but but it exposes the implementation > properties so blatantly that writing a different interpretor is nearly > impossible. > > If I recall correctly, there are also some call-by- methods that take > into account networks and addressing space issues--call-by-reference > doesn't work if one cannot see the thing being referenced. Of coruse, > one must then ask whether one considers "remote-procedure-call" and/or > message-passing to be the same thing as a local call. > > One last nit, Call-by-value is actually call-by-copy-in-copy-out when > generalized. > > There are some principles that one can use to organize the parameter > passing methods. However, the space is much richer than people > commonly know about (and that is actually a good thing, that most > people aren't aware of the richness, simplicity is good). Fair enough. Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Joachim Durchholz wrote: > Marshall schrieb: > > > But what you descrbe is certainly *not* possible in the > > relational algebra; alas that SQL doesn't hew closer > > to it. Would you agree? > > Yup, SQL (particularly its update semantics) aren't relational semantics. > Still, it's SQL we've been talking about. > > > Would you also agree that > > if a language *did* adhere to relation semantics, > > then relation elements would *not* have identity? > > (Under such a language, one could not have two > > equal records, for example.) > > Any identity that one could define within relational semantics would be > just equality, so no, it wouldn't be very helpful (unless as part of a > greater framework). > However, that's not really a surprise. Aliasing becomes relevant (even > observable) only when there's updates, and relational algebra doesn't > have updates. Good point. Perhaps I should have said "relational algebra + variables with assignment." It is interesting to consider assignment vs. the more restricted update operators: insert, update, delete. I think I see what you mean about the restricted update operators working on identity. > >>> Okay. At this point, though, the term aliasing has become extremely > >>> general. I believe "i+1+1" is an alias for "i+2" under this definition. > >> No, "i+1+1" isn't an alias in itself. It's an expression - to be an > >> alias, it would have to be a reference to something. > >> > >> However, a[i+1+1] is an alias to a[i+2]. Not that this is particularly > >> important - 1+1 is replacable by 2 in every context, so this is > >> essentially the same as saying "a[i+2] is an alias of a[i+2]", which is > >> vacuously true. > > > > To me, the SQL with the where clause is like i+2, not like a[2]. > > I'd say WHERE is like [i+2]: neither is valid on its own, it's the > "selector" part of a reference into a table. Is it possible you're being distracted by the syntax? WHERE is a binary operation taking a relation and a filter function. I don't think of filters as being like array indexing; do they appear analogous to you? (Always a difficult question because often times A and B share some qualities and not others, and what does one call that?) > > However the situation in SQL strikes me as being different. > > If one is speaking of base tables, and one has two queries, > > one has everything one needs to know simply looking at > > the queries. If views are involved, one must further examine > > the definition of the view. > > Sure. Usually, SQL itself is enough abstract that no additional > abstraction happens; so even if you have aliasing, you usually know > about it. > I.e. when compared to what you were saying about Java: "It is possible > to have multiple references to a single Java mutable object and > not know it.", the "and not know it" part is usually missing. Yes! > The picture changes as soon as the SQL statements get hidden behind > layers of abstraction, say result sets and prepared query handles. > > ... Um... let me also restate the preconditions for aliasing become a > problem. You need three elements for that: > 1) Identities that can be stored in multiple places. > 2) Updates. > 3) Abstraction (of updatable entities). > > Without identities, there cannot be aliasing. > Without updates, the operation that makes aliasing problematic is excluded. > Without abstraction, you may have aliasing but can clearly identify it, > and don't have a problem. Aha! That description works very well for me. > I admit that identity cannot be reliably established in SQL. The > identity of a record isn't available (unless via OID extensions). > However, it is there and it can have effect. Yes, I think I see what you mean now. This is in part a consequence of the restricted update operators. Thanks, Marshall -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem Solved
dylpkls91 wrote: > Thank you all for your responses. > > I have managed to figure out a solution using XML RPC which fits my > needs perfectly. Mind posting it for us lesser beings? ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Chris F Clark schreef: > If you have a fixed database, and you do two selects which specify the > same sets of fields to be selected and the same keys to select records > with, one expects the two selects to return the same values. When your "fixed" means read-only, or (fully) locked, then yes. Modern databases also have modes without locks, so without special attention (like maybe your "fixed") the two selects do not necessarily return the same set of records. > Further, if you > do an update, you expect certain fields of certain records to change > (and be reflected in subsequent selects). Doesn't your "fixed" block updates? > However, therein lies the rub, if you do a select on some records, and > then an update that changes those records, the records you have from > the select have either changed or show outdated values. Not necessarily outdated: values can be fixed in time for a purpose. Example: calculating interest is done once per day, but the whole process takes more than a day. Some systems implemented a lock plus requery just before the update, to check for unacceptable changes in the stored data; this to prevent having to keep locks while waiting. > If there is > some way to refer to the records you first selected before the update, > then you have an aliasing problem, but maybe one can't do that. One > could also have an aliasing problem, if one were allowed to do two > updates simultaneously, so that one update could changed records in > the middle of the other changing the records. Some databases allow you to travel back in time: run this query on the data of 1 year ago. All previous values are kept "behind" the current value. -- Affijn, Ruud "Gewoon is een tijger." -- http://mail.python.org/mailman/listinfo/python-list
Embedding exe file
hi how i can Embed an exe file in python program ? i want read an exe file then convert it to base64 and store in a string format and Embedd in python code such this : Exe='''R0lGODdhFQAVAPMAAAQ2PESapISCBASCBMTCxPxmNCQiJJya/ISChGRmzPz+/PxmzDQyZ DQyZDQyZDQyZCwAFQAVAAAElJDISau9Vh2WMD0gqHHelJwnsXVloqDd2hrMm8pYYiSHYfMMRm 53ULlQHGFFx1MZCciUiVOsPmEkKNVp3UBhJ4Ohy1UxerSgJGZMMBbcBACQlVhRiHvaUsXHgywTdyc ...''' then i want execute it without converting and saving it in a separate exe file . in the other hand i want Embedding exe file ... how i can do it ?? ThanX for Answers ...!! First Iranian Python Community --> www.python.ir -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
Daniel Nogradi wrote: > > > What is the simplest way to instantiate all classes that are > > > subclasses of a given class in a module? > > > > > > More precisely I have a module m with some content: > > > > > > # m.py > > > class A: > > > pass > > > class x( A ): > > > pass > > > class y( A ): > > > pass > > > # all kinds of other objects follow > > > # end of m.py > > > > > > and then in another module I have currently: > > > > > > # n.py > > > import m > > > x = m.x( ) > > > y = m.y( ) > > > # end of n.py > > > > > > and would like to automate this in a way that results in having > > > instances of classes from m in n whose names are the same as the > > > classes themselves. But I only would like to do this with classes that > > > are subclasses of A. > > > > > > Any ideas? > > > > It's pretty easy > > > > > > import m > > from inspect import getmembers, isclass, getmro > > > > t = '%s = m.%s()' > > > > for name, class_ in getmembers(m, isclass): > > if class_ is m.A: > > continue > > if m.A in getmro(class_): > > exec t % (name, name) > > > > Actually, this variant also suffers from the broken isclass implementation. > > (Simon, sorry for the double post.) Not a problem, I haven't used inspect much so I've not been bitten by this bug before. It's good to know! (I would have assumed that isclass() would have been implemented as isinstance(obj, (types.ClassType, type)) anyway. I'm surprised it's not, and that it's so broken..) Thanks. -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
"Marshall" <[EMAIL PROTECTED]> wrote: > In general, I feel that "records" are not the right conceptual > level to think about. Unfortunately, they are the right level. Actually,the right level might even be lower, the fields within a record, but that's moving even farther away from the direction you wish to go. The right level is the lowest level at which the programmer can see and manipulate values. Thus, since a programmer can see and manipulate fields within records in SQL that is the level we need to concern ourselves with when talking about aliasing in SQL. In other words, since a SELECT (or UPDATE) statement can talk about specific fields of specific records within the table (not directly, but reliably, which I'll explain in a moment) then those are the "primitive objects" in SQL that can be aliased. What I meant by "not directly, but reliably": If you have a fixed database, and you do two selects which specify the same sets of fields to be selected and the same keys to select records with, one expects the two selects to return the same values. You do not necessarily expect the records to be returned in the same order, but you do expect the same set of records to be returned and the records to have the same values in the same fields. Further, if you do an update, you expect certain fields of certain records to change (and be reflected in subsequent selects). However, therein lies the rub, if you do a select on some records, and then an update that changes those records, the records you have from the select have either changed or show outdated values. If there is some way to refer to the records you first selected before the update, then you have an aliasing problem, but maybe one can't do that. One could also have an aliasing problem, if one were allowed to do two updates simultaneously, so that one update could changed records in the middle of the other changing the records. However, I don't know if that's allowed in the relational algebra either. (I think I finally see your point, and more on that later.) > I do not see that they have > any identity outside of their value. We can uniquely identify > any particular record via a key, but a table may have more > than one key, and an update may change the values of one > key but not another. So it is not possible in general to > definitely and uniquely assign a mapping from each record > of a table after an update to each record of the table before > the update, and if you can't do that, then where > is the record identity? I don't know if your point of having two keys within one table amkes a difference. If one can uniquely identify a record, then it has identity. The fact that there is another mapping where one may not be able to uniquely identify the record is not necessarily relevant. > But what you descrbe is certainly *not* possible in the > relational algebra; alas that SQL doesn't hew closer > to it. Would you agree? Would you also agree that > if a language *did* adhere to relation semantics, > then relation elements would *not* have identity? > (Under such a language, one could not have two > equal records, for example.) Ok, here I think I will explain my understanding of your point. If we treat each select statement and each update statements as a separate program, i.e. we can't save records from one select statement to a later one (and I think in the relational algebra one cannot), then each single (individual) select statement or update statement is a functional program. That is we can view a single select statement as doing a fold over some incoming data, but it cannot change the data. Similarly, we can view an update statement as creating a new copy of the table with mutations in it, but the update statement can only refer to the original immutable table that was input. (Well, that's atleast how I recall the relational algebra.) It is the second point, about the semantics of the update statement which is important. There are no aliasing issues because in the relational algebra one cannot refer to the mutated values in an update statement, every reference in an update statement is refering to the unmutated input (again, that's my recollection). (Note, if my recollection is off, and one can refer to the mutated records in an update statement, perhaps they can explain why aliasing is not an issue in it.) Now for some minor points: > For example, we might ask in C, if we update a[i], will > the value of b[j] change? And we can't say, because > we don't know if there is aliasing. But in Fortran, we > can say that it won't, because they are definitely > different variables. Unfortunately, your statement about FORTRAN is not true, if a and b are parameters to a subroutine (or members of a common block, or equivalenced, or ...), then an update of a[i] might change b[j]. This is in fact, an important point, it is in subroutines (and subroutine like things), where we have local names for things (bindings) that are actu
Very simple speed benchmark of few string substitions ways
I was curious of performance new Python 2.4 "Simpler String Substitutions" so I decided to benchmark it. What I get [EMAIL PROTECTED]:~/python/benchmarks$ python template.py Normal python string substition = 0.017546 seconds PEP 292: Simpler String Substitutions = 0.243750 seconds Jinja template system = 0.821844 seconds Cheetah template system = 26.842872 seconds [EMAIL PROTECTED]:~/python/benchmarks$ To get i wrote small soft: http://wiki.bluszcz.net/PythoneTemplatingSystemsSpeedBenchmark Cheers, -- Rafał つた Zawadzki http://bluszcz.net http://wiki.bluszcz.net -- http://mail.python.org/mailman/listinfo/python-list
Re: InteractiveConsole History on Linux
[EMAIL PROTECTED] wrote: > Chris> Yeah, "import readline" works just fine. My problem isn't hard to > Chris> replicate. Can anyone else on Linux get command history to work > Chris> with the following code? Note, it should be saved and run from a > Chris> file. > > Command history across sessions or just command recall from the current > session? On my Mac your script works just fine for me (no import readline > as Robert Kern indicated in his reply) to do command recall from the the > current session, but more is needed if you expect to get command history > across sessions. I was just looking for recall in the current session, although the stdlib docs have an example of recall across sessions ( http://docs.python.org/lib/readline-example.html ). On Linux, it seems you have to explicitly import readline in order to get command history, although my application was also redirecting sys.stdout, which was also causing problems. -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
> > What is the simplest way to instantiate all classes that are > > subclasses of a given class in a module? > > > > More precisely I have a module m with some content: > > > > # m.py > > class A: > > pass > > class x( A ): > > pass > > class y( A ): > > pass > > # all kinds of other objects follow > > # end of m.py > > > > and then in another module I have currently: > > > > # n.py > > import m > > x = m.x( ) > > y = m.y( ) > > # end of n.py > > > > and would like to automate this in a way that results in having > > instances of classes from m in n whose names are the same as the > > classes themselves. But I only would like to do this with classes that > > are subclasses of A. > > > > Any ideas? > > It's pretty easy > > > import m > from inspect import getmembers, isclass, getmro > > t = '%s = m.%s()' > > for name, class_ in getmembers(m, isclass): > if class_ is m.A: > continue > if m.A in getmro(class_): > exec t % (name, name) > Actually, this variant also suffers from the broken isclass implementation. (Simon, sorry for the double post.) -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
> > >>> from inspect import isclass > > >>> > > >>> class x: > > ... def __getattr__( self, attr ): > > ... pass > > ... > > >>> y = x( ) > > >>> isclass( y ) > > True > > Which reinforces Michael Spencer's instinct that the inspect.isclass() > implementation is a bit too clever Wouldn't the word 'broken' be more appropriate? :) > > isinstance(obj, (types.ClassType, type)) > Thanks a lot this indeed works. -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
Daniel Nogradi wrote: > Thanks, this looks pretty good. However there is some wierdness with > isclass: whenever a class has a __getattr__ method an instance of it > will be detected by isclass as a class (although it is not). > > >>> from inspect import isclass > >>> > >>> class x: > ... def __getattr__( self, attr ): > ... pass > ... > >>> y = x( ) > >>> isclass( y ) > True Which reinforces Michael Spencer's instinct that the inspect.isclass() implementation is a bit too clever (see http://mail.python.org/pipermail/python-list/2006-July/351448.html). > If there is no __getattr__ method isclass works as expected. Am I > misunderstanding something here or isclass should return False for any > instance of any class including those with a __getattr__ method? It certainly should, and I believe that the obvious test isinstance(obj, (types.ClassType, type)) will work. Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Accessors in Python (getters and setters)
On 2006-07-15 19:46:16, Ben C wrote: > There isn't any practical difference, as you say, if all the setter does > is set. But it might easily do a few other subtle things, in particular > wait for a good moment to actually effect the change. I agree. But even then, for me there's no practical difference between calling a setter that does those other subtle things, or setting an attribute, and by this triggering the associated property handler than then does what in the other case the setter would do. Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
> > More precisely I have a module m with some content: > > > > # m.py > > class A: > > pass > > class x( A ): > > pass > > class y( A ): > > pass > > # all kinds of other objects follow > > # end of m.py > > > > and then in another module I have currently: > > > > # n.py > > import m > > x = m.x( ) > > y = m.y( ) > > # end of n.py > > > > and would like to automate this in a way that results in having > > instances of classes from m in n whose names are the same as the > > classes themselves. But I only would like to do this with classes that > > are subclasses of A. > > > > Any ideas? > > Just go through the objects in the module, test if they are classes, > subclasses of `A` and not `A` itself: > > from inspect import isclass > import test > > instances = dict() > for name in dir(test): > obj = getattr(test, name) > if isclass(obj) and issubclass(obj, test.A) and obj is not test.A: > instances[name] = obj() Thanks, this looks pretty good. However there is some wierdness with isclass: whenever a class has a __getattr__ method an instance of it will be detected by isclass as a class (although it is not). >>> from inspect import isclass >>> >>> class x: ... def __getattr__( self, attr ): ... pass ... >>> y = x( ) >>> isclass( y ) True >>> If there is no __getattr__ method isclass works as expected. Am I misunderstanding something here or isclass should return False for any instance of any class including those with a __getattr__ method? -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
Daniel Nogradi wrote: > What is the simplest way to instantiate all classes that are > subclasses of a given class in a module? > > More precisely I have a module m with some content: > > # m.py > class A: > pass > class x( A ): > pass > class y( A ): > pass > # all kinds of other objects follow > # end of m.py > > and then in another module I have currently: > > # n.py > import m > x = m.x( ) > y = m.y( ) > # end of n.py > > and would like to automate this in a way that results in having > instances of classes from m in n whose names are the same as the > classes themselves. But I only would like to do this with classes that > are subclasses of A. > > Any ideas? It's pretty easy import m from inspect import getmembers, isclass, getmro t = '%s = m.%s()' for name, class_ in getmembers(m, isclass): if class_ is m.A: continue if m.A in getmro(class_): exec t % (name, name) Peace, ~Simon -- http://mail.python.org/mailman/listinfo/python-list
Re: instantiate all subclasses of a class
In <[EMAIL PROTECTED]>, Daniel Nogradi wrote: > More precisely I have a module m with some content: > > # m.py > class A: > pass > class x( A ): > pass > class y( A ): > pass > # all kinds of other objects follow > # end of m.py > > and then in another module I have currently: > > # n.py > import m > x = m.x( ) > y = m.y( ) > # end of n.py > > and would like to automate this in a way that results in having > instances of classes from m in n whose names are the same as the > classes themselves. But I only would like to do this with classes that > are subclasses of A. > > Any ideas? Just go through the objects in the module, test if they are classes, subclasses of `A` and not `A` itself: from inspect import isclass import test instances = dict() for name in dir(test): obj = getattr(test, name) if isclass(obj) and issubclass(obj, test.A) and obj is not test.A: instances[name] = obj() -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
"Boomshiki" <[EMAIL PROTECTED]> writes: > I am aware that someone can recreate what we have done, but for them > to cut, paste, sell is kind of a rip off. Unless you factor that into your business model, and create compelling value that doesn't depend on the secrecy of something you place under the customer's control. -- \ "Try to learn something about everything and everything about | `\ something." -- T.H. Huxley | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
"Boomshiki" <[EMAIL PROTECTED]> writes: > I don't mean to be the dick who does not support open source, but > the rent does not pay itself these days. Non sequitur. The license terms for the software are orthogonal to whether one charges money for it. Viz the numerous businesses worldwide happily selling free software and making a profit. http://www.fsf.org/licensing/essays/selling.html> -- \ "If we don't believe in freedom of expression for people we | `\ despise, we don't believe in it at all." -- Noam Chomsky | _o__) | Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQT installation /configuration
[EMAIL PROTECTED] wrote: > David Boddie wrote: > > > However, you will have difficulty using the examples in that book > > because it was written for PyQt3. > > Ah yes, it doesn't recognise "QApplication" now. Never mind. QApplication is still there. You can access it via the Qt module and create an application object in the following way: import sys from PyQt4 import Qt app = Qt.QApplication(sys.argv) > > Work is underway to "port" the book > > to PyQt4, but it will take some time. (You can help with this and learn > > about PyQt4 at the same time, if you want.) > > Er...you might be overestimating my potential unless there's some > *really* entry-level material to be dealt with there. Though they do > say it's a good way to learn. Is there a forum? Yes, it's at http://mats.imk.fraunhofer.de/mailman/listinfo/pykde > > There's plenty of learning material for Qt 4; the official > > documentation at http://doc.trolltech.com/4.1 contains examples > > and overviews that are readable if you already know C++. > > One of the reasons I chose Python was so I wouldn't have to, alas. Much of the example code for Qt is readable even if you only know Python. Some of the main differences between Qt and PyQt are described in this document: http://www.riverbankcomputing.com/Docs/PyQt4/pyqt4ref.html Good luck! David -- http://mail.python.org/mailman/listinfo/python-list
Re: reading specific lines of a file
John Machin wrote: >> 'sed' is not recognized as an internal or external command, >> operable program or batch file. > > aarrbejaysus #2: Download the installer from > > http://gnuwin32.sourceforge.net/packages/sed.htm in a way, this kind of advice reminds me of http://thedailywtf.com/forums/thread/80949.aspx -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
Boomshiki wrote: > And trust me, I am not worried about 16 yr olds using it without paying, why > would they want to? I am worried about them cracking in to where their > grades are kept. what does "hiding your source code" has to do with that ? -- http://mail.python.org/mailman/listinfo/python-list
IDLE built-in help in Linux vs Windows
In Windows if you click the Help dropdown, IDLE launches a help window as it should. The help contents are included in the installation. In Linux, clicking Help launches a web browser, which is a perfectly good UI for viewing help. However, instead of loading a static HTML file from the disk like the Windows version does, it visits the doc directory on python.org over the internet. Is there any reason for that? It's noticably slower even over broadband, painful over dialup, and unusable if you're not connected to the net at all. -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
"Boomshiki" <[EMAIL PROTECTED]> writes: > And trust me, I am not worried about 16 yr olds using it without paying, why > would they want to? I am worried about them cracking in to where their > grades are kept. You should assume they have the source code in that case. In fact you're better off releasing the code, so people can spot security problems. See: http://en.wikipedia.org/wiki/Kerckhoffs_principle -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
Boomshiki wrote: > And trust me, I am not worried about 16 yr olds using it without paying, why > would they want to? I am worried about them cracking in to where their > grades are kept. what you need is data security... *not* code obfuscation.. [sreeram;] signature.asc Description: OpenPGP digital signature -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
I am aware that someone can recreate what we have done, but for them to cut, paste, sell is kind of a rip off. And trust me, I am not worried about 16 yr olds using it without paying, why would they want to? I am worried about them cracking in to where their grades are kept. -- http://mail.python.org/mailman/listinfo/python-list
instantiate all subclasses of a class
What is the simplest way to instantiate all classes that are subclasses of a given class in a module? More precisely I have a module m with some content: # m.py class A: pass class x( A ): pass class y( A ): pass # all kinds of other objects follow # end of m.py and then in another module I have currently: # n.py import m x = m.x( ) y = m.y( ) # end of n.py and would like to automate this in a way that results in having instances of classes from m in n whose names are the same as the classes themselves. But I only would like to do this with classes that are subclasses of A. Any ideas? -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
"Boomshiki" <[EMAIL PROTECTED]> writes: > Now the big issue at hand is how well will I be able to mask my source code? Not all that well, but it really doesn't matter. Someone who sees what the program does can write another one like it, without seeing your source code. -- http://mail.python.org/mailman/listinfo/python-list
Re: Commercial Programming
In <[EMAIL PROTECTED]>, Boomshiki wrote: > Now the big issue at hand is how well will I be able to mask my source code? > After all I wouldn't want some someone walking off to the bank with our hard > work. That and almost any 16 yr old can look at Python source and know what > it is talking about (I exadurate, but you get my point). > > So my question is how much can Python do for me in the sense of hiding my > source code while still maintaining portibility? Forget it. And even if you can hide the source this does not stop the 16 year olds from using and spreading the software without permission from you. The only secure way is to put the software on a server under your control and offer your program as web service. Ciao, Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
Re: InteractiveConsole History on Linux
Chris> Yeah, "import readline" works just fine. My problem isn't hard to Chris> replicate. Can anyone else on Linux get command history to work Chris> with the following code? Note, it should be saved and run from a Chris> file. Command history across sessions or just command recall from the current session? On my Mac your script works just fine for me (no import readline as Robert Kern indicated in his reply) to do command recall from the the current session, but more is needed if you expect to get command history across sessions. Skip -- http://mail.python.org/mailman/listinfo/python-list
Commercial Programming
I don't mean to be the dick who does not support open source, but the rent does not pay itself these days. What I got is a huge undertaking that will change the way teachers handing their grading sytem (that is as far as I can go without breaking my terms in the contract). Now I have a variety of languages I can set the team up with, leaning more on Java(unlikely as you will read my issue) and some cross platform BASICs(such as RealBASIC). Now the big issue at hand is how well will I be able to mask my source code? After all I wouldn't want some someone walking off to the bank with our hard work. That and almost any 16 yr old can look at Python source and know what it is talking about (I exadurate, but you get my point). So my question is how much can Python do for me in the sense of hiding my source code while still maintaining portibility? -- http://mail.python.org/mailman/listinfo/python-list
Python Data Explorer
Does anybody know some GUI (preferably QT) application which can be use to explore pickled python objects? Similar functionality has a PyDev Debugger in Eclipse, but I would like to have a standalone application. I know that it is not hard to write it, but I don't want to again invent a wheel ;o) Thanks for any help -- http://mail.python.org/mailman/listinfo/python-list
Re: Regular Expression problem
On 13 Jul 2006 23:12:05 -0700, Paul McGuire <[EMAIL PROTECTED]> wrote: Pyparsing is also good for recognizing basic HTML tags and theirattributes, regardless of the order of the attributes.-- PaultestText = """sldkjflsa;fajhere it would be 'mystylesheet.css'. I used the following regex to getthis value(I dont know if itI thought I was doing fine until I got stuck by this tag >> : sametag but with 'href=''href="">pat.search(your_link) -- http://mail.python.org/mailman/listinfo/python-list
Re: Python for Embedded Systems?
Carl J. Van Arsdall wrote: > This raises a good question. Is there a need for python to change > somewhat to work better in an embedded profile? When I asked this question last on python-dev, there was exactly one response, and that was "yes, it needs to change". The natural question then is "in what way?". To this, the answer was surprising: It needs better support for cross-compilation. Apparently, cross-compiling Python is very painful, and I guess cross-compiling distutils-based packages even more so. Contributions in that direction are welcome. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: newbie graphing recommendations ?
Bryan: > do you think that pygame would be a good alternative to matplotlib to create > some graphs such simple bar and line graphs? For graphs MatPlotLib is usually better, and its antialiasing library (Anti-Grain Geometry) is wonderful. Pygame gives a bit more freedom but you have to do all for yourself. > i want to animate them as new data comes comes in. I think MatPlotLib can do this too, if your computer is fast enough. >i would also like to have the bars and graphs have nice shading > if possible to give it a really attractive look. Remember what Edward Tufte (www.edwardtufte.com) says, often too much elaborations makes graphs them less than useless. Bye, bearophile -- http://mail.python.org/mailman/listinfo/python-list
Re: What is a type error?
Marshall schrieb: > Joachim Durchholz wrote: >> Marshall schrieb: >>> I would say, records in SQL have value, and their >>> identity is exactly their value. >> >> Definitely not. You can have two equal records and update just one of >> them, yielding non-equal records; by my definition (and by intuition), >> this means that the records were equal but not identical. > > This sort of thing comes up when one has made the mistake of > not defining any keys on one's table and needs to rectify the > situation. It is in fact considered quite a challenge to do. > My preferred technique for such a situation is to create > a new table with the same columns and SELECT DISTINCT ... > INTO ... then recreate the original table. So that way doesn't > fit your model. I was mentioning multiple equal records just as an example where the records have an identity that's independent of the record values. > How else might you do it? I suppose there are nonstandard > extensions, such as UPDATE ... LIMIT. And in fact there > might be some yucky thing that made it in to the standard > that will work. Right, it might be difficult to update multiple records that are exactly the same. It's not what SQL was intended for, and difficult to do anyway - I was thinking of LIMIT (I wasn't aware that it's nonstandard), and I agree that there may be other ways to do it. However, I wouldn't overvalue that case. The Jane/John Doe example posted elsewhere in this thread is strictly within the confines of what SQL was built for, yet there is aliasing. > But what you descrbe is certainly *not* possible in the > relational algebra; alas that SQL doesn't hew closer > to it. Would you agree? Yup, SQL (particularly its update semantics) aren't relational semantics. Still, it's SQL we've been talking about. > Would you also agree that > if a language *did* adhere to relation semantics, > then relation elements would *not* have identity? > (Under such a language, one could not have two > equal records, for example.) Any identity that one could define within relational semantics would be just equality, so no, it wouldn't be very helpful (unless as part of a greater framework). However, that's not really a surprise. Aliasing becomes relevant (even observable) only when there's updates, and relational algebra doesn't have updates. >> > I do not see that they have >>> any identity outside of their value. We can uniquely identify >>> any particular record via a key, but a table may have more >>> than one key, and an update may change the values of one >>> key but not another. So it is not possible in general to >>> definitely and uniquely assign a mapping from each record >>> of a table after an update to each record of the table before >>> the update, and if you can't do that, then where >>> is the record identity? >> Such a mapping is indeed possible. Simply extend the table with a new >> column, number the columns consecutively, and identify the records via >> that column. > > That doesn't work for me. It is one thing to say that for all > tables T, for all elements e in T, e has identity. It is a different > thing to say that for all tables T, there exists a table T' such > that for all elements e in T', e has identity. Let me continue that argument: Records in T' have identity. From an SQL point-of-view, there's no difference between the records in T' and records in other tables, so they must share all properties, in particular that of having an identity. (I agree that's not as convincing as seeing aliasing in action. See below.) >> But even if you don't do that, there's still identity. It is irrelevant >> whether the programs can directly read the value of the identity field; >> the adverse effects happen because updates are in-place. (If every >> update generated a new record, then we'd indeed have no identity.) >> >>> Okay. At this point, though, the term aliasing has become extremely >>> general. I believe "i+1+1" is an alias for "i+2" under this definition. >> No, "i+1+1" isn't an alias in itself. It's an expression - to be an >> alias, it would have to be a reference to something. >> >> However, a[i+1+1] is an alias to a[i+2]. Not that this is particularly >> important - 1+1 is replacable by 2 in every context, so this is >> essentially the same as saying "a[i+2] is an alias of a[i+2]", which is >> vacuously true. > > To me, the SQL with the where clause is like i+2, not like a[2]. I'd say WHERE is like [i+2]: neither is valid on its own, it's the "selector" part of a reference into a table. > A query is simply an expression that makes mention of a variable. > However I would have to admit that if SQL table elements have > identity, it would be more like the array example. OK. > (The model of SQL I use in my head is one with set semantics, > and I am careful to avoid running in to bag semantics by, for > example, always defining at least one key, and using SELECT > DISTINCT where necessary. But it is true that t
Re: reading specific lines of a file
On 16/07/2006 5:16 PM, Fredrik Lundh wrote: > Bill Pursell wrote: > >> Some might argue that this is not really doing >> it in Python. In fact, I would argue that! But if >> you're at a command prompt and you want to >> see line 7358, it's much easier to type >> % sed -n 7358p aarrbejaysus #1: You *don't* type the '%', you *do* need to specify an input file somehow. >> than it is to write the python one-liner. > > 'sed' is not recognized as an internal or external command, > operable program or batch file. aarrbejaysus #2: Download the installer from http://gnuwin32.sourceforge.net/packages/sed.htm -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQT installation /configuration
On Sunday 16 July 2006 1:09 am, [EMAIL PROTECTED] wrote: > [EMAIL PROTECTED] wrote: > > Phil Thompson wrote: > > > For Qt4 use the binary installer from... > > > > > > http://www.trolltech.com/developer/downloads/qt/windows > > > > > > For PyQt4 use the binary installer from... > > > > > > http://www.riverbankcomputing.co.uk/pyqt/download.php > > > > Ah thanks, I'm a dork. Why didn't I see that before ? > > Waitaminute, didn't you write it? Oh dear. > > I've got another problem, I'm afraid - I've installed Qt 4.1.4 and PyQt > GPL v4.0 over Python 2.4, and the demos for both run happily enough, > but when I try to run the first example (in IDLE) from Boudewijn > Rempt's GUI Programming with Python: QT Edition I just get > "ImportError: No module named qt". Is there something I need to add to > my sys.path here? > > Sorry to bother you with the newbie questions. Boudewijn's book describes Qt/PyQt v3. Phil -- http://mail.python.org/mailman/listinfo/python-list
Re: reading specific lines of a file
In message <[EMAIL PROTECTED]>, Yi Xing wrote: > I want to read specific lines of a huge txt file (I know the line #). > Each line might have different sizes. Is there a convenient and fast > way of doing this in Python? Thanks. file("myfile.txt").readlines()[LineNr] Convenient, yes. Fast, no. :) -- http://mail.python.org/mailman/listinfo/python-list
Re: reading specific lines of a file
In message <[EMAIL PROTECTED]>, Fredrik Lundh wrote: > Bill Pursell wrote: > >> Some might argue that this is not really doing >> it in Python. In fact, I would argue that! But if >> you're at a command prompt and you want to >> see line 7358, it's much easier to type >> % sed -n 7358p >> than it is to write the python one-liner. > > 'sed' is not recognized as an internal or external command, > operable program or batch file. You're not using Windows, are you? -- http://mail.python.org/mailman/listinfo/python-list
Re: Configuring IDLE on Linux
On 2006-07-14, Adonis <[EMAIL PROTECTED]> wrote: > Satya Kiran wrote: >> Hello, >> I have upgraded to Python2.4 on my Red Hat 9.0 Linux box. >> I want to work with IDLE and ran a search to check it's presence. >> Here is what I get. >> >> [EMAIL PROTECTED] bin]# find / -iname idlelib >> /usr/local/lib/python2.4/idlelib >> >> [EMAIL PROTECTED] bin]# cd /usr/local/lib/python2.4/idlelib >> [EMAIL PROTECTED] idlelib]# python PyShell.py >> ** IDLE can't import Tkinter. Your Python may not be configured for Tk. ** >> >> How do I resolve this and get IDLE working? >> >> thanks in advance, >> Kiran Satya > > You must have the Tk libraries present in your system for Python to > compile Tkinter. Go to your distribution's site and try to see if they > offer a TCL/TK package and install it (being that it is Redhat they most > definitely must have one). Then recompile Python. This is exactly right, on a SUSE system (at least) it's the tk-devel and tcl-devel packages you need to have installed, because you're building Python and it needs to link against those things, not just use them. So although tcl/tk on its own it usually installed by default, you don't always get those -devel packages in a default setup. -- http://mail.python.org/mailman/listinfo/python-list
Re: reading specific lines of a file
Bill Pursell wrote: > Some might argue that this is not really doing > it in Python. In fact, I would argue that! But if > you're at a command prompt and you want to > see line 7358, it's much easier to type > % sed -n 7358p > than it is to write the python one-liner. 'sed' is not recognized as an internal or external command, operable program or batch file. -- http://mail.python.org/mailman/listinfo/python-list
ANN: wxPython 2.6.3.3
Announcing -- The 2.6.3.3 release of wxPython is now available for download at http://wxpython.org/download.php. This is a mostly bug fix release and also includes builds for Python 2.5 on Mac and also Windows. A summary of other changes is listed below and at http://wxpython.org/recentchanges.php. What is wxPython? - wxPython is a GUI toolkit for the Python programming language. It allows Python programmers to create programs with a robust, highly functional graphical user interface, simply and easily. It is implemented as a Python extension module that wraps the GUI components of the popular wxWidgets cross platform library, which is written in C++. wxPython is a cross-platform toolkit. This means that the same program will usually run on multiple platforms without modifications. Currently supported platforms are 32-bit Microsoft Windows, most Linux or other Unix-like systems using GTK2, and Mac OS X 10.2+, in most cases the native widgets are used on each platform. Changes in 2.6.3.3 -- wx.lib.pubsub updates from Oliver Schoenborn: - fixed the hash problem with non-hashable objects - now supports listeners that use \*args as an argument (listener(\*args) was not passing the validity test) - corrected some mistakes in documentation - added some clarifications (hopefully useful for first time users) - changed the way singleton is implemented since old way prevented pydoc etc from extracting docs for Publisher DocView and ActiveGrid IDE updates from Morgan Hua: New Features: In Tab-View mode, Ctrl-number will take the user to the numbered tab view. Modified files now show an '*' astrisk in the view title. Debugger framework can now support PHP debugging. Not important for python development, but at least that means the debugger framework is more generalized. wx.lib.mixins.listctrl.TextEditMixin: Fixed the double END_LABEL_EDIT event problem in TextEditMixin by checking if the editor was already hidden before continuing with the CloseEditor method. Also added code to OpenEditor to send the BEGIN_LABEL_EDIT event and to not allow the opening of the editor to continue if the event handler doesn't allow it. Undeprecated wx.GetNumberFromUser and added wx.NumberEntryDialog. Made necessaary changes for building wxPython for Python 2.5. There may still be some issues related to the new Py_ssize_t type and 64-bit machines, but at least all compile errors and warnings related to it have been resolved. -- Robin Dunn Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython! -- http://mail.python.org/mailman/listinfo/python-list