Re: custom classes in sets
vegetax wrote: How can i make my custom class an element of a set? class Cfile: def __init__(s,path): s.path = path def __eq__(s,other): print 'inside equals' return not os.popen('cmp %s %s' % (s.path,other.path)).read() def __hashcode__(s): return s.path.__hashcode__() the idea is that it accepts file paths and construct a set of unique files (the command "cmp" compares files byte by byte.),the files can have different paths but the same content but the method __eq__ is never called Seems to be called fine for me: py> class Cfile: ... def __eq__(self, other): ... print 'inside equals' ... return False ... def __hash__(self): ... return 0 ... py> {Cfile():1, Cfile():2} inside equals {<__main__.Cfile instance at 0x01166490>: 1, <__main__.Cfile instance at 0x01166760>: 2} Note that __eq__ won't be called if the hashes are different: py> class Cfile: ... hash = 0 ... def __eq__(self, other): ... print 'inside equals' ... return False ... def __hash__(self): ... Cfile.hash += 1 ... return Cfile.hash ... py> {Cfile():1, Cfile():2} {<__main__.Cfile instance at 0x01166918>: 1, <__main__.Cfile instance at 0x011668A0>: 2} Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler
Hello Ilias, > d) Is it really neccessary that I dive into such adventures, to be able > to do the most natural thing like: "developing python extensions with > MinGW"? Writing a setup.py and running python setup.py build_ext --compiler=mingw32 works for me *without* any more work. Things can't get much simpler. Bye. -- Miki Tebeka <[EMAIL PROTECTED]> http://tebeka.bizhat.com The only difference between children and adults is the price of the toys -- http://mail.python.org/mailman/listinfo/python-list
RE: custom classes in sets
Delaney, Timothy C (Timothy) wrote: > vegetax wrote: > >> def __hashcode__(s): return s.path.__hashcode__() > > Try __hash__ ... > > Tim Delaney sorry about the typo, it is indead __hash__() that i tried -- http://mail.python.org/mailman/listinfo/python-list
RE: custom classes in sets
vegetax wrote: > def __hashcode__(s): return s.path.__hashcode__() Try __hash__ ... Tim Delaney -- http://mail.python.org/mailman/listinfo/python-list
custom classes in sets
How can i make my custom class an element of a set? class Cfile: def __init__(s,path): s.path = path def __eq__(s,other): print 'inside equals' return not os.popen('cmp %s %s' % (s.path,other.path)).read() def __hashcode__(s): return s.path.__hashcode__() the idea is that it accepts file paths and construct a set of unique files (the command "cmp" compares files byte by byte.),the files can have different paths but the same content but the method __eq__ is never called -- http://mail.python.org/mailman/listinfo/python-list
FS: O'Reilly Python Pocket Reference
I am offering for sale a copy of O'Reilly's _Python Pocket Reference_. It is the second edition, covering Python 2. It is in fine condition, with no broken spine or dog-earned pages. One might even believe it just came out of the bookstore. Asking price is US$4 plus shipping (USPS Media Mail within the US, airmail internationally), payable by check or money order in the US, or Paypal elsewhere. Christopher Culver [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Wow!, This chick is HOT! LZl6:Tu
. -- Want to get laid tonight?? Find local girls now http://www.youandmeswing.com/index.php?ref_id=130 -- ,iy^3aQvw -- http://mail.python.org/mailman/listinfo/python-list
[FREE!] Swingers Websites! U@wvqqN
. -- Want to get laid tonight?? Find local girls now http://www.youandmeswing.com/index.php?ref_id=130 -- ,iy^3aQvw -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
Quoth Dave Brueck <[EMAIL PROTECTED]>: ... | Another related benefit is that a lot of application state is implicitly and | automatically managed by your local variables when the task is running in a | separate thread, whereas other approaches often end up forcing you to think in | terms of a state machine when you don't really care* and as a by-product you | have to [semi-]manually track the state and state transitions - for some | problems this is fine, for others it's downright tedious. I don't know if the current Stackless implementation has regained any of this ground, but at least of historical interest here, the old one's ability to interrupt, store and resume a computation could be used to As you may know, it used to be, in Stackless Python, that you could have both. Your function would suspend itself, the select loop would resume it, for something like serialized threads. (The newer version of Stackless lost this continuation feature, but for all I know there may be new features that regain some of that ground.) I put that together with real OS threads once, where the I/O loop was a message queue instead of select. A message queueing multi-threaded architecture can end up just as much a state transition game. I like threads when they're used in this way, as application components that manage some device-like thing like a socket or a graphic user interface window, interacting through messages. Even then, though, there tend to be a lot of undefined behaviors in events like termination of the main thread, receipt of signals, etc. Donn Cave, [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
FCGI Help?
Hi All - I'm trying to develop web applications using python / Cheetah. I'm also trying to experiment with lighttpd (see www.lighttpd.net), which supports fast-cgi. So, I downloaded Robin Dunn's fcgi.py file (http://alldunn.com/python/fcgi.py), and everything is up and running nicely. Except, I'm a complete dummy - totally new to fast-cgi development. Therefore, when I run lighttpd and direct it to use fcgi as my fast-cgi app, it starts the _test() function w/in fcgi.py which simply prints some nice information about my request / environment. I then tried to develop my own app/server that inherits from fcgi, and then maps uri requests to my classes (for example, www.mysite.com/users/new_week maps to class user(), method new_week()). I *somewhat* got this working (at least, it doesn't shut down on me immediately, but doesn't do much else either)...but every request has to have a file associated with it (which obviously isn't the case since I'm trying to map into a class/method, not a file). So it doesn't work :( Anyway, I'm completely frustrated on how to use fast-cgi. I've also checked out fast-cgi.com, but they only seem to give trivial examples on how to use fast-cgi (unless I didn't search / read enough, but I've been looking for a few days on and off). My questions are: 1. Can anyone point me to a good resource on how to create fast-cgi apps (real world examples??) or how to use fcgi.py properly? 2. I've thought about creating a fast-cgi app that simply spawns python interpreters and then runs the scripts from the request uri - is this possible / easy to do? I know I could use Apache's mod_python or something similar, but I'm clearly a glutton for punishment :) I'm also hoping to use something a little less daunting than Apache if possible. Thanks for your help, and sorry for such a long post! Kevin T. Ryan -- http://mail.python.org/mailman/listinfo/python-list
Re: OS env for Windows
Cool thanks a lot. Always wanted to use win32api module too. "Tony Meyer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> Is there any other way >> of distinguishing between XP and 2000 I wonder? > > WinXP SP2: > import win32api major, minor, spack, platform, ver_str = win32api.GetVersionEx() print major, minor, spack, platform, ver_str > 5 1 2600 2 Service Pack 2 > > WinNT SP4: > import win32api major, minor, spack, platform, ver_str = win32api.GetVersionEx() print major, minor, spack, platform, ver_str > 5 0 2195 2 Service Pack 4 > > =Tony.Meyer > -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Peter Hansen schreef: > Given the clear "units='bytes'" default above, and my restricting > my comments to "the rest of the computer world", it should be > clear I was talking about a very limited subset of the planet. > > A subset, however, which has an extremely strong attachment to > 1024 instead of 1000 (for very good reasons), and which is > less likely to abandon backwards compatibility and widely accept > 1000 than the US is likely to adopt metric widely in the near > future... The problem is that that 'subset' uses kilo for both 1000 (at least hard disks & some network transmission speeds) and 1024 in computer science. -- JanC "Be strict when sending and tolerant when receiving." RFC 1958 - Architectural Principles of the Internet - section 3.9 -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie help
Sorry about the code: Google Groups screwed up the formatting, but I hope you get the picture. -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Peter Hansen wrote: Martin v. Löwis wrote: Peter Hansen wrote: For the rest of the computer world, unless I've missed a changing of the guard or something, "kilo" is 1024 and "mega" is 1024*1024 and so forth... In case this isn't clear yet: you have missed a changing of the guard or something. "kibi" is 1024, "mebi" is 1024*1024 and so forth. "kilo" is 1000. Yeah, saw the link. The IEC doesn't speak for me, I'm afraid. And as the wikipedia notes, "As of 2005 this naming convention has not gained widespread use." I suspect I and many others will go to our graves not being comfortable mebbling and gibbling over our bytes, though we'll probably spend a lot of time kibbling over the issue... Indeed - it's a little early to say that we've missed a changing of the guard! :) Multiple definitions aside, "kilo" and "mega" are far too entrenched - even if I could manage to say "kibibyte" with a straight face, I'd get nothing but blank stares in return. -Dave -- http://mail.python.org/mailman/listinfo/python-list
Re: Newbie help
You need to put the "You guessed it..." block inside a conditional (if guess == number) so that it only executes if the guess is right. (You also need to break out of the loop in that case.) As written, the "You guessed it..." block executes the first time through the loop regardless of the guess. Also, if the initial guess is right, then the while guess != number block never executes, and the message is never displayed. What you need is an infinite loop that breaks on a correct guess or upon reaching the maximum number of tries. Here's a corrected version: # import random # # print "\tWelcome to 'Guess My Number'!" # print "\nI'm thinking of a number between 1 and 100." # print "You Only Have Five Guesses.\n" # # # set the initial values # number = random.randrange(100) + 1 # guess = int(raw_input("Go Ahead and Take a guess: ")) # tries = 1 # max_tries = 5 # # # guessing loop # while True: # if guess == number: # # Guess is right! # print "You guessed it! The number was", number # print "And it only took you", tries, "tries!\n" # break # elif tries == max_tries: # print "Sorry You Lose" # print "The Number was ", number # break # elif guess > number: # print "Guess Lower..." # elif guess < number: # print "Guess Higher..." # guess = int(raw_input("Take Another guess: ")) # tries += 1 # # raw_input("\n\nPress the enter key to exit.") Michael -- Michael D. Hartl, Ph.D. Chief Technology Officer http://quarksports.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
Mike Meyer wrote: [EMAIL PROTECTED] (Aahz) writes: In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: Here here. I find that threading typically introduces worse problems than it purports to solve. Threads are also good for handling blocking I/O. Actually, this is one of the cases I was talking about. I find it saner to convert to non-blocking I/O and use select() for synchronization. That solves the problem, without introducing any of the headaches related to shared access and locking that come with threads. This whole tangent to the original thread intrigues me - I've found that if you're going to use threads in any language, Python is the one to use because the GIL reduces so many of the problems common to multithreaded programming (I'm not a huge fan of the GIL, but its presence effectively prevents a pure Python multithreaded app from corrupting the interpreter, which is especially handy for those just learning Python or programming). I've done a lot of networking applications using select/poll (usually for performance reasons) and found that going that route *can* in some cases simplify things but it requires looking at the problem differently, often from perspectives that seem unnatural to me - it's not just an implementation detail but one you have to consider during design. One nice thing about using threads is that components of your application that are logically separate can remain separate in the code as well - the implementations don't have to be tied together at some common dispatch loop, and a failure to be completely non-blocking in one component doesn't necessarily spell disaster for the entire app (I've had apps in production where one thread would die or get hung but I was relieved to find out that the main service remained available). Another related benefit is that a lot of application state is implicitly and automatically managed by your local variables when the task is running in a separate thread, whereas other approaches often end up forcing you to think in terms of a state machine when you don't really care* and as a by-product you have to [semi-]manually track the state and state transitions - for some problems this is fine, for others it's downright tedious. Anyway, if someone doesn't know about alternatives to threads, then that's a shame as other approaches have their advantages (often including a certain elegance that is just darn *cool*), but I wouldn't shy away from threads too much either - especially in Python. -Dave * Simple case in point: a non-blocking logging facility. In Python you can just start up a thread that pops strings off a Queue object and writes them to an open file. A non-threaded version is more complicated to implement, debug, and maintain. -- http://mail.python.org/mailman/listinfo/python-list
Help with embedding fully qualified script name
I'm trying to call a method in a script file given a fully qualified file name, e.g. c:\myscript\test.py. I find that PyImport_Import("test") works fine, with c:\myscript is set as the first item in the PYTHONPATH. I tried PyRun_Simple and that does run my specific file, but then when I try to use the calls below that I used on PyImport_Import, I get a null function returned. I've tried the other methods that use a FILE and they do the same thing. pDict = PyModule_GetDict ( pModule ); pFunc = PyDict_GetItemString ( pDict, "MyFunction" ); I also tried doing things like creating a new module, etc. since I thought that may work, but suspect that I was missing some steps. The basic flow I want to do is this, with only the first step being my problem. 1) Load the script file ?? 2) Get the function "MyFunction" from the script (PyModule_GetDict, PyDict_GetItemString) 3) Call that function PyObject_CallObject I appreciate any help since I've spent quite a bit of time searching and trying things. Jim W. -- http://mail.python.org/mailman/listinfo/python-list
Re: SCons build tool speed
On Sun, Feb 13, 2005 at 08:39:10PM -0500, Peter Hansen wrote: > That answer, combined with Mike's response pointing out > that tools more sophisticated than basic "make" actually > can delve into the source and identify the dependencies, Argh argh argh. Of course you can write a makefile to "delve into the source and identify the dependencies". And, by the way, there's no need for make to be recursive when a project spans multiple directories. (the other popular misconception about make) Below is a GNU makefile that I use to build a small program. I re-organized the file a bit before posting to clearly separate the two sections of the makefile, and it's possible I broke something in the process. Since my system has subsecond file timestamps and I do not build with source or object files on network filesystems, the "timestamp comparison" method works just fine to decide whether a target must be rebuilt or not. What programs like SCons *do* is include nice built-in definitions of stuff like the 'obj/%.d: %.cc' rule (often with a built-in parser which you can bet will not be 100% compatible with your compiler!), built-in inclusion of dependency lists with no extra programmer action, and the features I don't need like the use of cryptographic hashes to compare files. A larger system I work on uses GNU make to build around 6000 object files into a single executable. A "do-nothing" make takes around 8 seconds on a 2.8GHz machine. This involves parsing about 6000 lines of Makefiles and Submakefiles (per-directory lists of source files), and about 650klines of dependency information. I don't know how this measures up to "modern" tools like SCons. I'd be curious to know. But it's my opinion that a well-designed "make library" and/or "make preprocessor" to go with GNU Make would be right up there with SCons in its "power", while avoiding the need for a tool that most people have never heard of and don't already have installed on their system (yes, a pretty Linux-centric view). One criticism of Make that I'd take seriously is that it's a domain-specific language and usually I say those are terrible ideas. I still have to refer to the manual to remember which of $*, $@, $^ or $< I need, sometimes, even though I've been a GNU Make power user for two years now. Jeff # # This section of the makefile names the source files (one in this case) # and other complier options. It also has a rule for linking the target # program default: stippler LFLAGS := -L/usr/X11R6/lib LIBS := -lGL -lGLU -lglut -lXi -lXmu -lX11 -lm -lnetpbm SRCS := main.cc CFLAGS := -mcpu=pentium4 -O0 -g -DOUTPUT_POSTSCRIPT stippler: $(OBJS) $(CCLD) $(LFLAGS) -o $@ $^ $(LIBS) # # This section, which is essentially boilerplate, says how to generate # the list of dependencies or the object file from a given source file. # It also transforms the list of sources into a list of objects, and # includes all the necessary dependency lists ("dot d files") # # The definition of OBJS would be more complex if source files of # different types exist (.c and .cc files, for example) OBJS := $(patsubst %.cc, obj/%.o, $(SRCS)) CCLD := $(CC) include $(patsubst %.o,%.d,$(OBJS)) obj/%.d: %.cc mkdir -p $(dir $@) $(CC) -MM -MG -MT "$@ $(patsubst obj/%.d,obj/%.o,$@)" \ $(CFLAGS) $< -o [EMAIL PROTECTED] && mv -f [EMAIL PROTECTED] $@ obj/%.o: %.cc $(CC) $(CFLAGS) -c $< -o [EMAIL PROTECTED] && mv -f [EMAIL PROTECTED] $@ # pgpDEaSoxYP3D.pgp Description: PGP signature -- http://mail.python.org/mailman/listinfo/python-list
Newbie help
Hey guys, Hope you can help me again with another problem. I am trying to learn Python on my own and need some help with the following. I am writing a program that lets has the pc pick a number and the user has five guess to get the number. 1. BUG: If the number is say 35 and I guess 41 the program tells me that I guessed the correct number and tells me I guessed 31. 2.When I do get the correct number I can not get the program to stop asking me for the number. Your help is greatly appreciated. Chad # Five Tries to Guess My Number # # The computer picks a random number between 1 and 100 # The player gets Five tries to guess it and the computer lets # the player know if the guess is too high, too low # or right on the money # # Chad Everett 2/10/2005 import random print "\tWelcome to 'Guess My Number'!" print "\nI'm thinking of a number between 1 and 100." print "You Only Have Five Guesses.\n" # set the initial values number = random.randrange(100) + 1 guess = int(raw_input("Go Ahead and Take a guess: ")) tries = 1 # guessing loop while guess != number: if (guess > number): print "Guess Lower..." else: print "Guess Higher..." guess = int(raw_input("Take Another guess: ")) tries += 1 print "You guessed it! The number was", number print "And it only took you", tries, "tries!\n" if tries == 5: print "Sorry You Lose" print "The Number was ", number raw_input("\n\nPress the enter key to exit.") THIS IS WHAT THE RESULTS LOOKS LIKE WHEN I RUN THE PROGRAM Welcome to 'Guess My Number'! I'm thinking of a number between 1 and 100. You Only Have Five Guesses. Go Ahead and Take a guess: 99 Guess Lower... Take Another guess: 98 You guessed it! The number was 85 And it only took you 2 tries! Guess Lower... Take Another guess: 44 You guessed it! The number was 85 And it only took you 3 tries! Guess Higher... Take Another guess: 55 You guessed it! The number was 85 And it only took you 4 tries! Guess Higher... Take Another guess: 33 You guessed it! The number was 85 And it only took you 5 tries! Sorry You Lose The Number was 85 Guess Higher... Take Another guess: -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
Mike Meyer wrote: [EMAIL PROTECTED] (Aahz) writes: Threads are also good for handling blocking I/O. Actually, this is one of the cases I was talking about. I find it saner to convert to non-blocking I/O and use select() for synchronization. That solves the problem, without introducing any of the headaches related to shared access and locking that come with threads. Use a communicating sequential processes model for the threading and you don't have many data synchronisation problems because you have barely any shared access - no application data is ever shared between threads, they only send messages to each other via message queues. Most threads simply block on their incoming message queue permanently. Those doing blocking I/O set an appropriate timeout on the I/O call so they can check for messages occasionally. Conveniently, you end up with an architecture that supports switching to multiple processes, or even multiple machines just by changing the transport mechanism used by the message system. (We did exactly this for a GUI application - detached the GUI so it talked to a server via CORBA instead of via direct DLL calls. This meant the server could be ported to a different platform without having to port the far more platform specific GUI. This would have been much harder if we weren't already using a CSP model for communication between different parts of the system) Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Peter Hansen wrote: I'll be one of the last holdouts, too... it's really not so hard to work in powers of two if you try... The difficulty isn't with working in powers of 1024, it's that the terms are used inconsistently even within the computing industry. Memory is measured in kibibytes, but disk space is measured in kilobytes. Something as basic as "1 meg" has different numeric meanings depending on whether you're talking about memory or disk space or metered bandwidth usage. And a 1.44 MB isn't 1000^2 bytes or 1024^2 bytes, but rather 1024*1000 bytes! -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis The decree is the Sultan's; the mountains are ours. -- Dadaloglu -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Nick Coghlan wrote: My mistake - IEC, not ISO :) For all intents and purposes an IEC standard should be as good as an ISO one. They usually develop standards for different areas, or jointly if it is an overlapping area (but ISO/IEC standards are usually referred to as "ISO standards"). -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: It would be a lot simpler if it was included in the distribution. I would be willing to add it (even though it is completely trivial). I think it would go fine in itertools (I would even put them as builtins, but I'm not going to go there because probably not everyone uses it as often as I do). What do people think? I have never done this, would I just write up a PEP? I've posted a question to py-dev about it. If Raymond (the itertools maintainer) is supportive, then a PEP may not be needed. If not. . . yeah, a PEP would probably be required. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: Considering python - have a few questions.
I would want the program to run in Windows for sure. If it could work on a Mac and other systems, that would be a plus. btw - I have the database designed (and the program info database filled) in Access If running on a Mac really is a goal, ditch Access, its windows only. You'd want to look into MySQL, PostgreSQl or some such for inter-platform use. -- http://mail.python.org/mailman/listinfo/python-list
Re: Alternative to raw_input ?
Francis Girard wrote: [den]: import msvcrt msvcrt.getch() I frequently had the problem to have something similar but *portable*. Something as short and simple. This has been brought up many times on this newsgroup. The answer is that there is no simple way to do this portably. You could use Python's exception handling to create a version that runs on multiple systems though, falling back to another method if msvcrt can't be imported. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler
Ilias Lazaridis wrote: a) Why does the Python Foundation not provide additionally a binary version, compiled with MinGW or another open-source compiler? I use a binary version of Python compiled with an open-source compiler on Windows that was provided by someone else. b) Why does the Python Foundation not ensure, that the python source-code is directly compilable with MinGW? Why should they? It already runs on Windows with a freely available compiler. f) Are there any official (Python Foundation) statements / rationales available, which explain why the MinGW compiler is unsupported, although parts of the community obviously like to use it? Not to my knowledge. But I would guess because supporting it would obviously be a lot of work and the core developers have other things to do they consider more important. They are volunteers, you know. Why don't you solve this problem and produce a patched version of Python that does what you want. [google is _not_ a fried here. I like to have a stable development environment, which is supported by the official projects, thus it can pass quality-assurance without beeing afraid about every next release.] Then you have several options: a) use a supported development environment b) do the work yourself to support MinGW c) pay someone else to do the work But don't act like the volunteers who develop Python owe you a version of Python that runs out of the box on MinGW. They don't, anymore than you owe *me* a version of Python that runs out of the box on MinGW. Now why haven't *you* produced a version of Python that is directly compileable with MinGW? Time's a-wasting. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: OS env for Windows
If Cary Grant's ghost was into Python and saw this good info, he'd say: "That's just ducky." But he's probably not. Ok Thanks Tony - I've always wanted to try out win32api module. Just what I need. "Tony Meyer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] >> Is there any other way >> of distinguishing between XP and 2000 I wonder? > > WinXP SP2: > import win32api major, minor, spack, platform, ver_str = win32api.GetVersionEx() print major, minor, spack, platform, ver_str > 5 1 2600 2 Service Pack 2 > > WinNT SP4: > import win32api major, minor, spack, platform, ver_str = win32api.GetVersionEx() print major, minor, spack, platform, ver_str > 5 0 2195 2 Service Pack 4 > > =Tony.Meyer > -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
In article <[EMAIL PROTECTED]>, Frans Englich <[EMAIL PROTECTED]> wrote: > >Personally I need a solution which touches this discussion. I need to run >multiple processes, which I communicate with via stdin/out, simultaneously, >and my plan was to do this with threads. Any favorite document pointers, >common traps, or something else which could be good to know? Threads and forks tend to be problematic. This is one case I'd recommend against threads. -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death." --GvR -- http://mail.python.org/mailman/listinfo/python-list
Re: [PATCH] Re: frozenset() without arguments should return a singleton
"Stefan Behnel" > I generally believe that many programmers will > silently expect frozenset() to be (and become) more efficient than set() - in > whatever regard: processing, memory, etc. That belief is without foundation. Except for mutating methods and hashing methods, both set() and frozenset() share the same underlying code and data structure. In this respect, they differ from list() and tuple() which have no shared code and has two substantially different data structures. Raymond Hettinger -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Martin v. Löwis wrote: Peter Hansen wrote: For the rest of the computer world, unless I've missed a changing of the guard or something, "kilo" is 1024 and "mega" is 1024*1024 and so forth... In case this isn't clear yet: you have missed a changing of the guard or something. "kibi" is 1024, "mebi" is 1024*1024 and so forth. "kilo" is 1000. Yeah, saw the link. The IEC doesn't speak for me, I'm afraid. And as the wikipedia notes, "As of 2005 this naming convention has not gained widespread use." I suspect I and many others will go to our graves not being comfortable mebbling and gibbling over our bytes, though we'll probably spend a lot of time kibbling over the issue... -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Alan Kennedy wrote: [Peter Hansen] For the rest of the computer world, unless I've missed a changing of the guard or something, "kilo" is 1024 and "mega" is 1024*1024 and so forth... Maybe you missed these? http://en.wikipedia.org/wiki/Kibibyte http://en.wikipedia.org/wiki/Mebibyte http://en.wikipedia.org/wiki/Gibibyte Definitely missed them, in the sense of "didn't see them yet". I must say I'm somewhat astounded that anyone bothered to do this. Don't miss them at all, in the sense of "have no plans to use them and am not stressed in the least over the fact that they are lacking in my life." kilo-mega-giga-etc-should-be-powers-of-10-ly y'rs, Maybe, but they aren't always... that's just the way it is. I take a descriptive view rather than a prescriptive one. Google for the usage of the above and you'll find the following ratios for the numbers of pages that use the two forms: kibibyte vs. kilobyte: 1:60 (impressively high, I admit) mebibyte vs. megabyte: 1:234 gibibyte vs. gigabyte: 1:2082 I strongly suspect that the vast majority of the former set of pages are of the form "use this instead of kilo!", but perhaps I really have been asleep while much of the computing world converted. I'll be one of the last holdouts, too... it's really not so hard to work in powers of two if you try... -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Second posting - Howto connect to MsSQL
You can also use pymssql. I've used it before on a little project. It looks like it works on linux too. http://pymssql.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: SCons build tool speed
[EMAIL PROTECTED] wrote: You're right that build times are dominated by the external commands when rebuilds occur. If nothing needs to be rebuilt, though, the wall-clock time is obviously dominated by how long it takes for the build tool to decide that. A build tool that doesn't decide whether or not targets are up-to-date *and* dispatch the commnds to rebuild them reasonably quickly and efficiently doesn't do a good job of serving its users. That answer, combined with Mike's response pointing out that tools more sophisticated than basic "make" actually can delve into the source and identify the dependencies, removes my confusion. Thanks. :) -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Mike Meyer wrote: From what I found http://physics.nist.gov/cuu/Units/binary.html , it's not clear those are ISO prefixes yet - but they have been adapted by some standards agencies. Possibly you have better references? My mistake - IEC, not ISO :) And I did get one wrong in my sample code - it's 'exbi' not 'ebi': http://en.wikipedia.org/wiki/Binary_prefix#IEC_standard_prefixes Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --- http://boredomandlaziness.skystorm.net -- http://mail.python.org/mailman/listinfo/python-list
Re: win32 extension install hiccup
MM said the following on 2/13/2005 4:50 PM: Hi, I downloaded the latest win32all build 202 and tried to install under win2000 with Py2.4. Install complains about 'couldn't open py2.4 to run script pywin32-preinstall.py'. I checked the directories and there was no sign of this file (preinstall.py) so I presume this is why it bombed. How do I fix this? Thanks, matthew. Add the location of Python.exe to the Path (System Properties->Advanced->Environment Variables) and run your win32all install. It will work like a charm! -- http://mail.python.org/mailman/listinfo/python-list
RE: OS env for Windows
> Is there any other way > of distinguishing between XP and 2000 I wonder? WinXP SP2: >>> import win32api >>> major, minor, spack, platform, ver_str = win32api.GetVersionEx() >>> print major, minor, spack, platform, ver_str 5 1 2600 2 Service Pack 2 WinNT SP4: >>> import win32api >>> major, minor, spack, platform, ver_str = win32api.GetVersionEx() >>> print major, minor, spack, platform, ver_str 5 0 2195 2 Service Pack 4 =Tony.Meyer -- http://mail.python.org/mailman/listinfo/python-list
Re: help please
gargonx wrote: let's take the word "dogs" ext = dict("D":"V1", "O":"M1", "G":"S1") std = dict("S":"H") encode("DOGS") # proc() we'll get: "V1M1S1H" let's say i want to do just the opposite word: "V1M1S1H" decode("V1M1S1H") #how do i decode "V1" to "D", how do i keep the "V1" together? and get: "DOGS" If you can make some assumptions about the right-hand sides of your dicts, you can probably tokenize your string with a simple regular expression: py> import re py> charmatcher = re.compile(r'[A-Z][\d]?') py> py> ext = dict(D="V1", O="M1", G="S1") py> std = dict(S="H") py> py> decode_replacements = {} py> decode_replacements.update([(std[key], key) for key in std]) py> decode_replacements.update([(ext[key], key) for key in ext]) py> py> def decode(text): ... return ''.join([decode_replacements.get(c, c) ... for c in charmatcher.findall(text)]) ... py> py> decode("V1M1S1H") 'DOGS' So, instead of using for c in text I use for c im charmatcher.findall(text) That gives me the correct tokenization, and i can just use the inverted dicts to map it back. Note however that I've written the regular expression to depend on the fact that the values in std and ext are either single uppercase characters or single uppercase characters followed by a single digit. Steve -- http://mail.python.org/mailman/listinfo/python-list
OS env for Windows
Hi, have wxHtmlWindow question here. On my OnLinkClicked handler, I do the following: --- def OnLinkClicked(self,linkinfo): f = wx.TheMimeTypesManager.GetFileTypeFromExtension('.html') if not f: return try: cmd = wx.FileType.GetOpenCommand(f,linkinfo.GetHref()) wx.Execute(cmd) except: wxMessageBox("Something unexpected happened","MyApp",wxOK|wxICON_INFORMATION ) --- If I'm on my Windows 2000 machine at work, when I attempt to execute the default browser action, with wx.Execute, I first get a freeze on my app ( with the About box showing, where I have the html window situated). And the browser is trying to open, but instead, after a long delay: "dde execute request failed: a request for a synchronous execute transaction has timed out" On my XP system at home, Firefox comes up fine, and very quickly. Main question: I tried to add an If condition, to test for the 'OS' env variable, but this won't work I realize,after noticing that *both* 2000 and XP have the value: WINDOWS_NT. Is there any other way of distinguishing between XP and 2000 I wonder? Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
On Monday 14 February 2005 00:53, Aahz wrote: > In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: > >[EMAIL PROTECTED] (Aahz) writes: > >> In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: > >>>Here here. I find that threading typically introduces worse problems > >>>than it purports to solve. > >> > >> Threads are also good for handling blocking I/O. > > > >Actually, this is one of the cases I was talking about. I find > >it saner to convert to non-blocking I/O and use select() for > >synchronization. That solves the problem, without introducing any of > >the headaches related to shared access and locking that come with > >threads. > > It may be saner, but Windows doesn't support select() for file I/O, and > Python's threading mechanisms make this very easy. If one's careful > with application design, there should be no locking problems. (Have you > actually written any threaded applications in Python?) Hehe.. the first thing a google search on "python non-blocking io threading" returns "Threading is Evil". Personally I need a solution which touches this discussion. I need to run multiple processes, which I communicate with via stdin/out, simultaneously, and my plan was to do this with threads. Any favorite document pointers, common traps, or something else which could be good to know? Cheers, Frans -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic poker client
[EMAIL PROTECTED] writes: > I'm assuming that I need to figure out the port it uses, find the > server, analyze the packets for commands, and then build an app that > masquerades as the real client. > > Anyone have any experience with this? If you mean you want to write your own real-money poker client (e.g. PartyPoker), I wouldn't advise it unless you really know what you're doing, since those sites go nuts detecting bots and banning their users. The bot authors in turn use fancier and fancier methods to escape detection, etc. I don't play online poker or use these products myself, but as a security geek I have some technical interest in this. (Also some friends of mine play online poker all the time, so I hear about it). Take a look at http://www.winholdem.net for one of the bots currently involved in such an arms race. The winholdem folks also run their own online poker room where bots of all persuasions are welcome, but nobody is supposed to play for real money there. That might be a good place to develop and test your client. I see now that Winholdem now has a "Team edition" which sounds like it's now supporting outright collusion between (perhaps virtual) players, rather than just being a bot attempting to play well. I suppose this is inevitable since that kind of thing has been happening between live players for years. It's currently still possible for good players to win money steadily at these sites (since there are so many weak players) but I wonder how long that situation will last. -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: >[EMAIL PROTECTED] (Aahz) writes: >> In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: >>> >>>Here here. I find that threading typically introduces worse problems >>>than it purports to solve. >> >> Threads are also good for handling blocking I/O. > >Actually, this is one of the cases I was talking about. I find >it saner to convert to non-blocking I/O and use select() for >synchronization. That solves the problem, without introducing any of >the headaches related to shared access and locking that come with >threads. It may be saner, but Windows doesn't support select() for file I/O, and Python's threading mechanisms make this very easy. If one's careful with application design, there should be no locking problems. (Have you actually written any threaded applications in Python?) -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death." --GvR -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
Mike Meyer <[EMAIL PROTECTED]> writes: > > Threads are also good for handling blocking I/O. > > Actually, this is one of the cases I was talking about. I find it > saner to convert to non-blocking I/O and use select() for > synchronization. That solves the problem, without introducing any of > the headaches related to shared access and locking that come with > threads. It's just a different style with its own tricks and traps. Threading for blocking i/o is a well-accepted idiom and if Python supports threads at all, people will want to use them that way. -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: Previous discussion on this topic: http://groups-beta.google.com/group/comp.lang.python/msg/a76b4c2caf6c435c Michael OK, well then. That's really the exact same thing, down to the names of the functions. So what ever happened to that? I don't recall: probably http://www.google.com/search?sourceid=mozclient&ie=utf-8&oe=utf-8&q=alltrue+site%3Amail.python.org+python-dev would lead you to the answer That was over a year ago! I > don't see any mention of it in PEP 289? > No, PEP289 was for generator expressions - the any/all discussion arose as one application of those/itertools Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Pythonic poker client
[EMAIL PROTECTED] wrote: I'm assuming that I need to figure out the port it uses, find the server, analyze the packets for commands, and then build an app that masquerades as the real client. Anyone have any experience with this? If you're using one of the major sites, what you are trying to do is essentially impossible. It is very likely that the transmissions are encrypted via SSL. Furthermore, such sites may well actively check for clients sending invalid data -- something your client will almost certainly do at first even if you did somehow manage to crack the encryption -- as a tipoff to modified clients and bots. -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis If love is the answer, could you rephrase the question? -- Lily Tomlin -- http://mail.python.org/mailman/listinfo/python-list
Re: PyQt and Python 2.4 - also WinXP LnF?
After building with MSVC6 (Python 2.3.5 and 2.4 versions) I've noticed that the ToolTips don't seem to work in the GPL version. MSVC6 is about twice as fast to build as MinGW. -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
>Actually, this is one of the cases I was talking about. I find it >saner to convert to non-blocking I/O and use select() for >synchronization. That solves the problem, without introducing any of >the headaches related to shared access and locking that come with >threads. Threads aren't always the right entity for dealing with asynchronicity, one might say. C// -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
> Previous discussion on this topic: > http://groups-beta.google.com/group/comp.lang.python/msg/a76b4c2caf6c435c > > Michael > OK, well then. That's really the exact same thing, down to the names of the functions. So what ever happened to that? That was over a year ago! I don't see any mention of it in PEP 289? http://www.python.org/peps/pep-0289.html It would be hard to imagine such a trivial change being rejected, if it were in its own namespace. Did it just happen that no one implemented it? Or it looks like no one could agree on the names? From that thread, I see any/all, anytrue/alltrue, forall/exists. Either of the first two is fine with me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterator / Iteratable confusion
"Francis Girard" <[EMAIL PROTECTED]> wrote in message an "iterator" doesn't have to support the "__iter__" method Terry Reedy wrote: Yes it does. iter(iterator) is iterator is part of the iterater protocol for the very reason you noticed... But, notwithstanding the docs, it is not essential that iter(iterator) is iterator >>> class A(object): ... def __iter__(self): ... return AnIterator() ... ... >>> class AnIterator(object): # an iterator that copies itself ... def next(self): ... return "Something" ... def __iter__(self): ... return AnIterator() ... >>> a=A() >>> i = iter(a) ... >>> i.next() 'Something' >>> j = iter(i) >>> j.next() 'Something' >>> i is j False >>> Michael -- http://mail.python.org/mailman/listinfo/python-list
Your message to RT-Announce awaits moderator approval
Your mail to 'RT-Announce' with the subject Delivery service mail Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://lists.bestpractical.com/cgi-bin/mailman/confirm/rt-announce/e66d287ed65ec6d7a8c42491896433657fa0c0a6 -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: Yeah, as we can see there are a million ways to do it. But none of them are as desirable as just having a library function to do the same thing. I'd argue that since there are so many different ways, we should just collapse them into one: any() and all(). That is more in keeping with the python philosophy I suppose -- having one canonical way to do things. Otherwise you could see any of these several ways of doing it in any program, and each time you have to make sure it's doing what you think. Each of them requies more examination than is justified for such a trivial operation. And this definitely hurts the readability of the program. Previous discussion on this topic: http://groups-beta.google.com/group/comp.lang.python/msg/a76b4c2caf6c435c Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: Second posting - Howto connect to MsSQL
John Fabiani wrote: > Hi, > Since this is (sort of) my second request it must not be an easy solution. > Are there others using Python to connect MsSQL? At the moment I'd accept > even a windows solution - although, I'm looking for a Linux solution. > > John Thanks all - it looks like it will work with windows at least. John -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterator / Iteratable confusion
Francis Girard wrote: """ Example 8 Running after your tail with itertools.tee The beauty of it is that recursive running after their tail FP algorithms are quite straightforwardly expressed with this Python idiom. """ def Ex8_Fibonacci(): print "Entering Ex8_Fibonacci" def _Ex8_Fibonacci(): print "Entering _Ex8_Fibonacci" yield 1 yield 1 fibTail.next() # Skip the first one for n in (head + tail for (head, tail) in izip(fibHead, fibTail)): yield n fibHead, fibTail, fibRes = tee(_Ex8_Fibonacci(), 3) return fibRes print print sEx8Doc print print list(islice(Ex8_Fibonacci(), 5)) Absolutely: ever since you brought up the Hamming sequence I've been interested in this approach. However, if iterators could be extended in place, these solutions would be even more attractive. Here are some examples for infinite series constructed with an extendable iterator. This iterator is returned by an iterable class 'Stream', shown below the examples: def factorial(): """ >>> f = factorial() >>> f.tolist(10) [1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880] """ factorial = Stream([1]) factorial.extend(factorial * it.count(1)) return factorial def fib(): """Example: >>> f = fib() >>> f.tolist(10) [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]""" fib = Stream([1,1]) fib.extend(x+y for x, y in it.izip(fib, fib[1:])) return fib def multimerge(*iterables): """Yields the items in iterables in order, without duplicates""" cache = {} iterators = map(iter,iterables) number = len(iterables) exhausted = 0 while 1: for it in iterators: try: cache.setdefault(it.next(),[]).append(it) except StopIteration: exhausted += 1 if exhausted == number: raise StopIteration val = min(cache) iterators = cache.pop(val) yield val def hamming(): """ Example: >>> h = hamming() >>> list(h[20:40]) [40, 45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 96, 100, 108, 120, 125, 128, 135, 144] >>> h[1] 288555831593533440L """ hamming = Stream([1]) hamming.extend(i for i in multimerge(2 * hamming, 3 * hamming, 5 * hamming)) return hamming def compounds(): """Extension of Hamming series to compounds of primes(2..13) Example: >>> c = compounds() >>> list(c[20:30]) [24, 25, 26, 27, 28, 30, 32, 33, 35, 36]""" compounds = Stream([1]) compounds.extend(i for i in multimerge(2 * compounds, 3 * compounds, 5 * compounds, 7 * compounds, 9 * compounds, 11 * compounds, 13 * compounds)) return compounds # Stream class for the above examples: import itertools as it import operator as op class Stream(object): """Provides an indepent iterator (using tee) on every iteration request Also implements lazy iterator arithmetic""" def __init__(self, *iterables, **kw): """iterables: tuple of iterables (including iterators). A sequence of iterables will be chained kw: not used in this base class""" self.queue = list(iterables) self.itertee = it.tee(self._chain(self.queue))[0] # We may not need this in every case def extend(self,other): """extend(other: iterable) => None appends iterable to the end of the Stream instance """ self.queue.append(other) def _chain(self, queue): while queue: for i in self.queue.pop(0): self.head = i yield i # Iterator methods: def __iter__(self): """Normal iteration over the iterables in self.queue in turn""" return self.itertee.__copy__() def _binop(self,other,op): """See injected methods - __add__, __mul__ etc..""" if hasattr(other,"__iter__"): return (op(i,j) for i, j in it.izip(self,other)) else: return (op(i,other) for i in self) def __getitem__(self,index): """__getitem__(index: integer | slice) index: integer => element at position index index: slice if slice.stop is given => Stream(it.islice(iter(self), index.start, index.stop, index.step or 1))) else: consumes self up to start then => Stream(iter(self)) Note slice.step is ignored in this case """ if isinstance(index, slice): if index.stop: return (it.islice(iter(self), index.start or 0, index.stop, index.step or 1)) else: iterator = iter(self) for i in range(index.start): iterator.next() return iterator else: return it.islice(iter(self), index,index
Re: builtin functions for and and or?
Yeah, as we can see there are a million ways to do it. But none of them are as desirable as just having a library function to do the same thing. I'd argue that since there are so many different ways, we should just collapse them into one: any() and all(). That is more in keeping with the python philosophy I suppose -- having one canonical way to do things. Otherwise you could see any of these several ways of doing it in any program, and each time you have to make sure it's doing what you think. Each of them requies more examination than is justified for such a trivial operation. And this definitely hurts the readability of the program. <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > In Python there are so many ways to do things... > This looks like another one, I haven't tested it: > > not False in imap(pred, iterable) > > As usual tests are required to measure the faster one. > I agree with Roose, there are are some "primitive" operations (like > this, and flatten, partition, mass removal of keys from a dictionary, > and few others) that can be added to the language (but I'm still not > capabable of doing it myself, and Python is free, so it's not right to > ask people to work for free for us). > > Bear hugs, > Bearophile > -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
"Diez B. Roggisch" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > So usually I just write a little function any( L, boolean_function = > > identity ) or all( ... ). But I am kind of sick of doing that all the > > time -- does it exist anywhere in the Python libraries? It seems really > > common to me. > > Put things into your own module and add it to your python path. Then you > only have to write it once. Well it's not as convenient as having it built in. The thing is I'm not just writing for myself. I used it at my old job, and now I'm using it at my new job. There's a requirement that the user shouldn't have to modify his setup beyond installing Python to run any scripts. At my first job we had one way of dealing with this. Now there is another way. And then I need a way to deal with it at home with my personal stuff. Also the stuff typically doesn't go under the Python dir, because that is not mapped to source control. And anyway people don't like mixing in our code with 3rd party code. The result that the path of least resistance is just to copy in a 4 line function or two into the program and be done with it, even though it goes against my sense of aesthetics. It would be a lot simpler if it was included in the distribution. I would be willing to add it (even though it is completely trivial). I think it would go fine in itertools (I would even put them as builtins, but I'm not going to go there because probably not everyone uses it as often as I do). What do people think? I have never done this, would I just write up a PEP? > > > The first way isn't satisfactory because it takes so many lines for what > > is > > essentially one "primitive" operation. The second way isn't great because > > it is not as readable and many readers don't like to see reduce, even if > > it > > is a common idiom like that. Also I don't believe it short circuits. > > It doesn't but so doesn't your loop example. Put a break in there once > Result is False. > > -- > Regards, > > Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Re: win32 extension install hiccup
MM wrote: > Hi, > > I downloaded the latest win32all build 202 and tried to install under > win2000 with Py2.4. Install complains about 'couldn't open py2.4 to run > script pywin32-preinstall.py'. I checked the directories and there was > no sign of this file (preinstall.py) so I presume this is why it bombed. > How do I fix this? Thanks, matthew. Build 202 is not the latest build. Build 203 is available at Sourceforge http://sourceforge.net/projects/pywin32/ -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
George Sakkis wrote: You're right, it doesn't short circuit, as most of the examples posted above. Here's one that it does: ... I also looked into taking advantage of itertools' dropwhile, but the all and any recipes included in the itertools documentation do short-circuit and don't require the setup of a try/except/else. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: Iterator / Iteratable confusion
"Francis Girard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > An ""iteratable"" class is a class supporting the __iter__ method which > should > return an ""iterator"" instance, that is, an instance of a class > supporting > the "next" method. Not quite right, see below. > An iteratable, strictly speaking, doesn't have to support the "next" > method An iterable with a next method is, usually, an iterator. > an "iterator" doesn't have to support the "__iter__" method Yes it does. iter(iterator) is iterator is part of the iterater protocol for the very reason you noticed... >(but this breaks the iteration protocol as we will later see). Iterators are a subgroup of iterables. Being able to say iter(it) without having to worry about whether 'it' is just an iterable or already an iterator is one of the nice features of the new iteration design. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
In Python there are so many ways to do things... This looks like another one, I haven't tested it: not False in imap(pred, iterable) As usual tests are required to measure the faster one. I agree with Roose, there are are some "primitive" operations (like this, and flatten, partition, mass removal of keys from a dictionary, and few others) that can be added to the language (but I'm still not capabable of doing it myself, and Python is free, so it's not right to ask people to work for free for us). Bear hugs, Bearophile -- http://mail.python.org/mailman/listinfo/python-list
Pythonic poker client
Hi all, My PC finally went belly up last week and I'm looking forward to playing with my new Mac. However, I play a bit of online poker, and there is no Mac client for my poker room. Ideally, instead of running Virtual PC, I'd much rather build a custom poker client with Python. It's an idea I've been kicking around for a while, as it would let me create logs and better analyze my playing. I'm hoping it would also help me improve my Python coding skills. I've mostly done web development, so I'm a little out of my element here, but I would certainly appreciate any help someone could offer. How would one go about porting a client like this? I'm assuming that I need to figure out the port it uses, find the server, analyze the packets for commands, and then build an app that masquerades as the real client. Anyone have any experience with this? Many thanks! Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: AES crypto in pure Python?
[EMAIL PROTECTED] wrote: I'm looking for an implementation of AES (the Advanced Encryption Standard) in pure Python. I'm aware of pycrypto, but that uses C code. I'm hoping to find something that only uses Python...I'm willing to trade speed for portability, since my application is designed for several different platforms. Anyone know if this has been done? Thanks, -AF Google -- http://mail.python.org/mailman/listinfo/python-list
Your message to RT-Announce awaits moderator approval
Your mail to 'RT-Announce' with the subject You are made active Is being held until the list moderator can review it for approval. The reason it is being held: Post by non-member to a members-only list Either the message will get posted to the list, or you will receive notification of the moderator's decision. If you would like to cancel this posting, please visit the following URL: http://lists.bestpractical.com/cgi-bin/mailman/confirm/rt-announce/57983dcbe673221226d200cf131c55023d34b811 -- http://mail.python.org/mailman/listinfo/python-list
Re: win32 extension install hiccup
MM wrote: > Hi, > > I downloaded the latest win32all build 202 and tried to install under > win2000 with Py2.4. Install complains about 'couldn't open py2.4 to run > script pywin32-preinstall.py'. I checked the directories and there was > no sign of this file (preinstall.py) so I presume this is why it bombed. You presume triply incorrectly. (1) The error message explicitly says it couldn't find the Python executable. (2) The file that Python would have run is pywin32-preinstall.py, not preinstall.py. (3) You shouldn't expect to find an install script lying around after an install, successful or failed, if the installer is cleaning up after itself. > How do I fix this? Thanks, matthew. Install Python 2.4 in C:\Python24 and try again. -- http://mail.python.org/mailman/listinfo/python-list
Re: help please
let's take the word "dogs" ext = dict("D":"V1", "O":"M1", "G":"S1") std = dict("S":"H") encode("DOGS") # proc() we'll get: "V1M1S1H" let's say i want to do just the opposite word: "V1M1S1H" decode("V1M1S1H") #how do i decode "V1" to "D", how do i keep the "V1" together? and get: "DOGS" #everything gets changed to uppercase -- http://mail.python.org/mailman/listinfo/python-list
Tkinter option_add for menu radiobutton
Root.option_add("*Menu.Font", "Veranda 9") as an example, works fine in my program. Root.option_add("*Radiobutton*selectColor", "black") also works fine for regular radiobuttons. What I can't do is get the selectColor of the radiobutton's in the menu to be black...the x.add_radiobutton() ones. Root.option_add("*Menu.Radiobutton*selectColor", "black")...nope Root.option_add("*Menu*selectColor", "black")...no change Others...no luck yet. What would the correct command be? I can do a selectcolor = "black" in the declaration of each button, but... Thanks! Bob -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
"Roose" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I need this a lot: a one line way to do a n-ary and or 'or'. > > e.g., > > result = True > for x in L: > if not boolean_function(x): > result = False > > or > > >>> reduce(operator.__and__, [boolean_function(x) for x in L) > > So usually I just write a little function any( L, boolean_function = > identity ) or all( ... ). But I am kind of sick of doing that all the > time -- does it exist anywhere in the Python libraries? It seems really > common to me. > > The first way isn't satisfactory because it takes so many lines for what is > essentially one "primitive" operation. The second way isn't great because > it is not as readable and many readers don't like to see reduce, even if it > is a common idiom like that. Also I don't believe it short circuits. You're right, it doesn't short circuit, as most of the examples posted above. Here's one that it does: from itertools import ifilter, dropwhile def any(pred, iterable): try: ifilter(pred,iterable).next() except StopIteration: return False else: return True def all(pred, iterable): try: dropwhile(pred,iterable).next() except StopIteration: return True else: return False George -- http://mail.python.org/mailman/listinfo/python-list
AES crypto in pure Python?
I'm looking for an implementation of AES (the Advanced Encryption Standard) in pure Python. I'm aware of pycrypto, but that uses C code. I'm hoping to find something that only uses Python...I'm willing to trade speed for portability, since my application is designed for several different platforms. Anyone know if this has been done? Thanks, -AF -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Steven Bethard wrote: Another alternative: not False in (bool(x) for x in L) Note that this should short-circuit, where min won't. Steve Whoops, for some reason the thought that short-circuiting didn't apply to And entered my mind while trying to post a nice solution. Hard to say why considering I have to do stuff like this on a daily basis! Ignore mine except as a novelty, then. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Michael Hartl wrote: > I warmly recommend downloading Peter Norvig's Python utilities file > (http://aima.cs.berkeley.edu/python/utils.py) and putting it on your > Python path. (E.g., in bash, put a line like > > export PYTHONPATH="/path/to/utilities_directory" > > in your .bashrc file.) The utils.py file defines many useful > functions, including the ones you want: > > # def every(predicate, seq): > # """True if every element of seq satisfies predicate. > # Ex: every(callable, [min, max]) ==> 1; every(callable, [min, 3]) > ==> 0 > # """ > # for x in seq: > # if not predicate(x): return False > # return True > # > # def some(predicate, seq): > # """If some element x of seq satisfies predicate(x), return > predicate(x). > # Ex: some(callable, [min, 3]) ==> 1; some(callable, [2, 3]) ==> 0 > # """ > # for x in seq: > # px = predicate(x) > # if px: return px > # return False > What an interesting mixed API design. The every() function returns True or False. However the "some" function returns the FIRST fat result if it's true in the non-boolean sense, otherwise False. Looks like there could theoretically be scope for two pairs of functions, one returning strictly True/False, and the other pair emulating chains of Python 'and's and 'or's. I.e. False or 0 or [] evaluates to [] 0 or 5 or 6 evaluates to 5 42 and None and True evaluates to None 4 and 5 and 6 evaluates to 6 All very nice, but useful? Dubious. PEPpable? Nah, two thumbs down. Diez's advice to the OP is sound: if it bothers you that much, mine the net for, or write, routines that do exactly what you want, and put them in your own utilities module. -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Brian Beck wrote: Roose wrote: I need this a lot: a one line way to do a n-ary and or 'or'. Here's a one-liner for the n-ary and: bool(min(bool(x) for x in L)) py> bool(min(bool(x) for x in [1, 1, 1, 0])) False py> bool(min(bool(x) for x in [1, 1, 1, 1])) True py> bool(min(bool(x) for x in ['a', '', 'b', 'c'])) False py> bool(min(bool(x) for x in ['a', 'b', 'c', 'd'])) True Another alternative: not False in (bool(x) for x in L) py> not False in (bool(x) for x in [1, 1, 1, 0]) False py> not False in (bool(x) for x in [1, 1, 1, 1]) True py> not False in (bool(x) for x in ['a', '', 'b', 'c']) False py> not False in (bool(x) for x in ['a', 'b', 'c', 'd']) True Note that this should short-circuit, where min won't. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Second posting - Howto connect to MsSQL
On Sun, 13 Feb 2005 17:57:34 GMT, John Fabiani <[EMAIL PROTECTED]> wrote: >Are there others using Python to connect MsSQL? Hi, direct your attention to http://www.object-craft.com.au/projects/mssql/ I once tried it as a little test - it worked. I would love to use it these days - unfortunately the (Windows) binaries for Python24 are missing. Somebody succeeded in compiling? Please let me know, if the binaries are somewhere out there. mb - Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Kill GIL
[EMAIL PROTECTED] (Aahz) writes: > In article <[EMAIL PROTECTED]>, Mike Meyer <[EMAIL PROTECTED]> wrote: >> >>Here here. I find that threading typically introduces worse problems >>than it purports to solve. > Threads are also good for handling blocking I/O. Actually, this is one of the cases I was talking about. I find it saner to convert to non-blocking I/O and use select() for synchronization. That solves the problem, without introducing any of the headaches related to shared access and locking that come with threads. http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: win32 extension install hiccup
MM wrote: I downloaded the latest win32all build 202 and tried to install under win2000 with Py2.4. Install complains about 'couldn't open py2.4 to run script pywin32-preinstall.py'. I checked the directories and there was no sign of this file (preinstall.py) so I presume this is why it bombed. How do I fix this? Most likely, by not installing Python into a path that has spaces in it. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Nick Coghlan <[EMAIL PROTECTED]> writes: > Peter Hansen wrote: >> Only for hard drive manufacturers, perhaps. >> For the rest of the computer world, unless I've missed >> a changing of the guard or something, "kilo" is 1024 >> and "mega" is 1024*1024 and so forth... > > Given that there are perfectly good ISO prefixes for the multiples of > 2**10, I don't see any reason to continue misusing the 10**3 prefixes > for the purpose. >From what I found http://physics.nist.gov/cuu/Units/binary.html >, it's not clear those are ISO prefixes yet - but they have been adapted by some standards agencies. Possibly you have better references? http://www.mired.org/home/mwm/ Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information. -- http://mail.python.org/mailman/listinfo/python-list
Re: help please
gargonx wrote: Well that seems to work like a champion, but my prob then would be; how do i get the double character values of ext to turn back to the single character keys. The reversed (decode if you will). It's unclear what you want to do here. If you have say: ext = dict(aa='A', ab='B', bb='C') then how should 'aaabb' be decoded? Some possibilities: 'ABb' 'AaC' 'aAC' Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: I need this a lot: a one line way to do a n-ary and or 'or'. Here's a one-liner for the n-ary and: bool(min(bool(x) for x in L)) py> bool(min(bool(x) for x in [1, 1, 1, 0])) False py> bool(min(bool(x) for x in [1, 1, 1, 1])) True py> bool(min(bool(x) for x in ['a', '', 'b', 'c'])) False py> bool(min(bool(x) for x in ['a', 'b', 'c', 'd'])) True -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Brian Beck wrote: def all(seq, pred=bool): "Returns True if pred(x) is True for every element in the iterable" for elem in ifilterfalse(pred, seq): return False return True def any(seq, pred=bool): "Returns True if pred(x) is True for at least one element in the iterable" for elem in ifilter(pred, seq): return True return False I should probably note, you'll have to from itertools import ifilter, ifilterfalse to use these. -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: I need this a lot: a one line way to do a n-ary and or 'or'. e.g., result = True for x in L: if not boolean_function(x): result = False or reduce(operator.__and__, [boolean_function(x) for x in L) Can you use itertools? py> def boolfn(x): ... print "boolfn: %r" % x ... return bool(x) ... py> True in itertools.imap(boolfn, ['a', '', 'b']) boolfn: 'a' True py> True in itertools.imap(boolfn, ['', '', '']) boolfn: '' boolfn: '' boolfn: '' False py> False in itertools.imap(boolfn, ['a', '', 'b']) boolfn: 'a' boolfn: '' True py> False in itertools.imap(boolfn, ['a', 'a', 'b']) boolfn: 'a' boolfn: 'a' boolfn: 'b' False It even shortcircuits when appropriate. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
Roose wrote: I need this a lot: a one line way to do a n-ary and or 'or'. Looks like there are itertools recipes for those, similar to what Michael just posted. Taken from here: http://docs.python.org/lib/itertools-recipes.html def all(seq, pred=bool): "Returns True if pred(x) is True for every element in the iterable" for elem in ifilterfalse(pred, seq): return False return True def any(seq, pred=bool): "Returns True if pred(x) is True for at least one element in the iterable" for elem in ifilter(pred, seq): return True return False -- Brian Beck Adventurer of the First Order -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
I warmly recommend downloading Peter Norvig's Python utilities file (http://aima.cs.berkeley.edu/python/utils.py) and putting it on your Python path. (E.g., in bash, put a line like export PYTHONPATH="/path/to/utilities_directory" in your .bashrc file.) The utils.py file defines many useful functions, including the ones you want: # def every(predicate, seq): # """True if every element of seq satisfies predicate. # Ex: every(callable, [min, max]) ==> 1; every(callable, [min, 3]) ==> 0 # """ # for x in seq: # if not predicate(x): return False # return True # # def some(predicate, seq): # """If some element x of seq satisfies predicate(x), return predicate(x). # Ex: some(callable, [min, 3]) ==> 1; some(callable, [2, 3]) ==> 0 # """ # for x in seq: # px = predicate(x) # if px: return px # return False Michael -- Michael D. Hartl, Ph.D. Chief Technology Officer http://quarksports.com/ -- http://mail.python.org/mailman/listinfo/python-list
win32 extension install hiccup
Hi, I downloaded the latest win32all build 202 and tried to install under win2000 with Py2.4. Install complains about 'couldn't open py2.4 to run script pywin32-preinstall.py'. I checked the directories and there was no sign of this file (preinstall.py) so I presume this is why it bombed. How do I fix this? Thanks, matthew. -- http://mail.python.org/mailman/listinfo/python-list
Re: Q: Portable Way to Make Files Read Only
On Sun, Feb 13, 2005 at 01:25:02PM -0600, Efrat Regev wrote: > I would like to recurse through a directory and make files (which match > a specific criteria) read only. From searching the Internet, I found > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/303343 > which shows how to change file attributes to read only using the > win32api module. That's great, but I was hoping there's a more portable way > to do so. Is there a more portable API call to make files read only? assuming the variable "path" is set to a string indicating the file in question, try the following: import os import stat # get the current file mode mode = os.stat(path)[stat.ST_MODE] # set it so it is not user, group, or other writable os.chmod(path, mode & ~stat.S_IWUSR & ~stat.S_IWGRP & ~stat.S_IWOTH) #or os.chmod(path,mode & ~0222) Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: help please
Well that seems to work like a champion, but my prob then would be; how do i get the double character values of ext to turn back to the single character keys. The reversed (decode if you will). Thanks a lot Steve this has been a great learning! -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
Denis S. Otkidach wrote: You are right. But isalpha behavior looks strange for me anyway: why cyrillic character '\u0430' is recognized as alpha one for de_DE locale, but is not for C? In glibc, all "real" locales are based on /usr/share/locale/i18n/locales/i18n, e.g. for de_DE through LC_CTYPE copy "i18n" i18n includes U+0430 as a character, through lower / ... % TABLE 11 CYRILLIC/ ..;..(2)..;/ This makes U+0430 a letter in all locales including i18n (unless locally overridden). This entire approach apparently is based on ISO 14652, which, in section 4.3.3, introduces the "i18n" LC_CTYPE category. Why the C locale does not use i18n, I don't know. Most likely, the intention is that the "C" locale works without any additional data files - you should ask the glibc developers. OTOH, there is a definition file POSIX for what appears to be the POSIX locale. I'd like to point out that this implementation is potentially in violation of ISO 14652; annex A.2.2 says that the notion of a POSIX locale is replaced with the i18n FDCC-set. So accordingly, I would expect that i18n is used in POSIX as well - see for yourself that it isn't in glibc 2.3.2. Again, I suggest to ask the glibc developers as to why this is so. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Dan Bishop wrote: They must have gotten the idea from floppy disks, which also use a 1024000-byte "megabyte". It's pretty common industry-wide. Memory is measured in binary prefixes (x 1024), but disk space and bandwidth are measured in decimal prefixes (x 1000). -- Erik Max Francis && [EMAIL PROTECTED] && http://www.alcyone.com/max/ San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis I'm not worried about anything. I'm not fearing any man. -- Dr. Martin Luther King, Jr. -- http://mail.python.org/mailman/listinfo/python-list
Re: builtin functions for and and or?
> So usually I just write a little function any( L, boolean_function = > identity ) or all( ... ). But I am kind of sick of doing that all the > time -- does it exist anywhere in the Python libraries? It seems really > common to me. Put things into your own module and add it to your python path. Then you only have to write it once. > The first way isn't satisfactory because it takes so many lines for what > is > essentially one "primitive" operation. The second way isn't great because > it is not as readable and many readers don't like to see reduce, even if > it > is a common idiom like that. Also I don't believe it short circuits. It doesn't but so doesn't your loop example. Put a break in there once Result is False. -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
builtin functions for and and or?
I need this a lot: a one line way to do a n-ary and or 'or'. e.g., result = True for x in L: if not boolean_function(x): result = False or >>> reduce(operator.__and__, [boolean_function(x) for x in L) So usually I just write a little function any( L, boolean_function = identity ) or all( ... ). But I am kind of sick of doing that all the time -- does it exist anywhere in the Python libraries? It seems really common to me. The first way isn't satisfactory because it takes so many lines for what is essentially one "primitive" operation. The second way isn't great because it is not as readable and many readers don't like to see reduce, even if it is a common idiom like that. Also I don't believe it short circuits. -- http://mail.python.org/mailman/listinfo/python-list
Re: changing __call__ on demand
Thanks; I didn't read close enough. :) -- Alan McIntyre ESRG LLC http://www.esrgtech.com Michael Hoffman wrote: Alan McIntyre wrote: >>>class test(object): ...def __call1(self): ...print 1 ...__call__ = __call1 Is that what you were looking for? That still only allows him to have one call function per class. -- http://mail.python.org/mailman/listinfo/python-list
Re: RFC 2965 cookies, cookielib, and mailman.
For the record, re http://mail.python.org/pipermail/python-list/2004-December/257422.html and http://www.gossamer-threads.com/lists/python/python/380607 cheers, --titus - Forwarded message from John J Lee <[EMAIL PROTECTED]> - X-Original-To: [EMAIL PROTECTED] From: John J Lee <[EMAIL PROTECTED]> To: Titus Brown <[EMAIL PROTECTED]> Subject: Re: RFC 2965 cookies, cookielib, and mailman. X-Spam-Status: No, hits=0.0 tagged_above=-10.0 required=5.0 tests= X-Spam-Level: If you don't mind, could you forward this reply to python-list@python.org and [EMAIL PROTECTED], for the record? On Sun, 6 Feb 2005, Titus Brown wrote: [...] > -> > In any case, the way to make the cookielib example work for mailman is > -> > like so: > -> > > -> > policy = cookielib.DefaultCookiePolicy(rfc2965=True) > -> > cj = cookielib.LWPCookieJar('cookies.lwp', policy=policy) > -> > -> Hmm, cookielib should work if IE and Mozilla do, so that's a bug :( > -> You shouldn't need to turn on 2965 handling. > -> > -> Do you have a script that demonstrates the problem, so I can fix it? > > Attached. By the by, thanks for fixing that cookiejar bug back in [...] > In the attached code, just change the True/False setting of the rfc2965 > flag in the DefaultCookiePolicy and you'll see that in one case a > cookie is correctly handled and in the other it is not. You're welcome > to try the same URL with browsers: [...snip details...] Thanks for the bug report, Titus. Damn, I wish I'd seen this bug before 2.4.0 was released. Workaround, as you illustrate above, is to switch on RFC 2965 handling. Looking at it, the problem seems blindingly obvious: I'm treating what is in fact an RFC 2109 (not 2965) cookie from MailMan as though it were a 2965 cookie instead of as a Netscape cookie (a deliberate choice). This didn't cause trouble in ClientCookie 0.4. when 2965 handling was on by default. Now that it's off by default in cookielib and ClientCookie 1.0, though (because 2965, and 2109 also, pretty much, are simply unimplemented in popular browsers: ie. Firefox and MSIE), it breaks apps like Mailman that, naively or stubbornly, send version=1 cookies. Real browsers treat RFC 2109 cookies as Netscape cookies (which, ad-hoc as Netscape cookies are, effectively include a few bits and pieces from the 2109 standard), so this behaviour is just plain wrong. The fix is easy, will upload a patch to SF. Bah. John - End forwarded message - -- http://mail.python.org/mailman/listinfo/python-list
Re: help please
gargonx wrote: yes the items in std are always single to single, and ext single to double. basicly the ext are refernce to the std itmes. the second character in ext is a number depending on how far it is from the item in std. this is just a simple encoding program. If your keys are always single characters (as this description seems to suggest) then the last code I posted should do what you want. Repeated here for your enjoyment: # merge mappings: # std has highest precedence, then ext, then punc replacements = {} replacements.update(punc) replacements.update(ext) replacements.update(std) # define encoding procedure def proc(text): # replace each character with its replacement # or leave character unchanged if not in the mapping return ''.join([replacements.get(c, c) for c in text]) Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Dan Bishop schreef: Nick Craig-Wood wrote: Peter Hansen <[EMAIL PROTECTED]> wrote: Only for hard drive manufacturers, perhaps. For the rest of the computer world, unless I've missed a changing of the guard or something, "kilo" is 1024 and "mega" is 1024*1024 and so forth... Yes. Unless you work in the telcoms industry, where, for example if you order a 2 Mbit/s line you'll get 2 * 1024 * 1000 bits / s They must have gotten the idea from floppy disks, which also use a 1024000-byte "megabyte". Not really. It is actually related to the bandwidth of individual telephony speech connections. These channels have a bandwith of 64 kb/sec, where the k-prefix is used in the proper (SI) way. So this bandwidth really is exactly 64,000 bits/sec (8,000 samples/sec, each sample having 8 bits). The M in a 2Mb/s connection is neither an SI prefix, noris it identical to Mi. It's just sloppy language. A 2 Mb/s connection is just a bundling of 32 such 64 kb/s channels, resulting in a bandwidth of 32*64,000 = 2,048,000 bits/sec. Cheers, Ruud -- http://mail.python.org/mailman/listinfo/python-list
Re: For American numbers
Peter Hansen wrote: For the rest of the computer world, unless I've missed a changing of the guard or something, "kilo" is 1024 and "mega" is 1024*1024 and so forth... In case this isn't clear yet: you have missed a changing of the guard or something. "kibi" is 1024, "mebi" is 1024*1024 and so forth. "kilo" is 1000. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: help please
yes the items in std are always single to single, and ext single to double. basicly the ext are refernce to the std itmes. the second character in ext is a number depending on how far it is from the item in std. this is just a simple encoding program. -- http://mail.python.org/mailman/listinfo/python-list
Re: sre is broken in SuSE 9.2
Serge Orlov wrote: Emphasis is mine. So how many libc implementations with non-unicode wide-character codes do we have in 2005? Solaris has supported 2-byte wchar_t implementations for many years, and so I believe did HP-UX and AIX. ISO C99 defines a constant __STDC_ISO_10646__ which an implementation can use to indicate that wchar_t uses Unicode (aka ISO 10646) in all locales. Very few implementations define this constant at this time, though. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Second posting - Howto connect to MsSQL
John Fabiani wrote: Hi, Since this is (sort of) my second request it must not be an easy solution. Are there others using Python to connect MsSQL? At the moment I'd accept even a windows solution - although, I'm looking for a Linux solution. On Windows, you can use http://sourceforge.net/projects/adodbapi Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: changing __call__ on demand
Stefan Behnel wrote: Hi! This somewhat puzzles me: Python 2.4 (#1, Feb 3 2005, 16:47:05) [GCC 3.3.4 (pre 3.3.5 20040809)] on linux2 Type "help", "copyright", "credits" or "license" for more information. .>>> class test(object): ... def __init__(self): ... self.__call__ = self.__call1 ... def __call1(self): ... print 1 ... def __call__(self): ... print 2 ... .>>> t = test() .>>> t() 2 It works the way you want if test is an old-style class: >>> class test: ... def __init__(self): ...self.__call__ = self.__call1 ... def __call1(self): ...print 1 ... def __call__(self): ...print 2 ... >>> t=test() >>> t() 1 Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: A great Alan Kay quote
Le dimanche 13 Février 2005 19:05, Arthur a écrit : > On Sun, 13 Feb 2005 18:48:03 +0100, Francis Girard > > > >My deepest apologies, > > > >Francis Girard > > Sorry if I helped get you into this, Francis. > No, no, don't worry. I really expressed my own opinions and feelings. At the same time, I certainly understand that these opinions might had upset some of the readers. I am sorry for this as I don't think this is the right discussion group for such opinions. Therefore it is useless to hurt people with something that is not a positive contribution. That's all. I will try to refrain in the future. I am just not used to talk to so many people at the same time. Regards, Francis Girard -- http://mail.python.org/mailman/listinfo/python-list
Re: Second posting - Howto connect to MsSQL
John Fabiani wrote: > Hi, > Since this is (sort of) my second request it must not be an easy solution. > Are there others using Python to connect MsSQL? At the moment I'd accept > even a windows solution - although, I'm looking for a Linux solution. Use unix-odbc and a mssql driver for unxi-odbc. Its called ftl or tls or something. As always: Google is your friend... -- Regards, Diez B. Roggisch -- http://mail.python.org/mailman/listinfo/python-list
Iterator / Iteratable confusion
Hi, I wrote simple dummy examples to teach to myself iterators and generators. I think that the iteration protocol brings a very neat confusion between the iterator and what it iterates upon (i.e. the iteratable). This is outlined in "example 3" in my dummy examples. What are your feelings about it ? Regards Francis Girard BEGINNING OF EXAMPLES from itertools import tee, imap, izip, islice import sys import traceback sEx1Doc = \ """ Example 1: An ""iteratable"" class is a class supporting the __iter__ method which should return an ""iterator"" instance, that is, an instance of a class supporting the "next" method. An iteratable, strictly speaking, doesn't have to support the "next" method and an "iterator" doesn't have to support the "__iter__" method (but this breaks the iteration protocol as we will later see). The ""for ... in ..."" construct now expect an iteratable instance in its second argument place. It first invoke its __iter__ method and then repeatedly invoke the ""next"" method on the object returned by ""__iter__"" until the ""StopIteration"" exception is raised. The designing goal is to cleanly separate a container class with the way we iterate over its internal elements. """ class Ex1_IteratableContClass: def __init__(self): print "Ex1_IteratableContClass.__init__" self._vn = range(0,10) def elAt(self, nIdx): print "Ex1_IteratableContClass.elAt" return self._vn[nIdx] def __iter__(self): print "Ex1_IteratableContClass.__iter__" return Ex1_IteratorContClass(self) class Ex1_IteratorContClass: def __init__(self, cont): print "Ex1_IteratorContClass.__init__" self._cont = cont self._nIdx = -1 def next(self): print "Ex1_IteratorContClass.next" self._nIdx += 1 try: return self._cont.elAt(self._nIdx) except IndexError: raise StopIteration print print sEx1Doc print for n in Ex1_IteratableContClass(): print n, sys.stdout.flush() sEx2Doc = \ """ Example 2: Let's say that we want to give two ways to iterate over the elements of our example container class. The default way is to iterate in direct order and we want to add the possibility to iterate in reverse order. We simply add another ""iterator"" class. We do not want to modify the container class as, precisely, the goal is to decouple the container from iteration. """ class Ex2_IteratableContClass: def __init__(self): print "Ex2_IteratableContClass.__init__" self._vn = range(0,10) def elAt(self, nIdx): print "Ex2_IteratableContClass.elAt" return self._vn[nIdx] def __iter__(self): print "Ex2_IteratableContClass.__iter__" return Ex1_IteratorContClass(self) class Ex2_RevIteratorContClass: def __init__(self, cont): print "Ex2_RevIteratorContClass.__init__" self._cont = cont self._nIdx = 0 def next(self): print "Ex2_RevIteratorContClass.next" self._nIdx -= 1 try: return self._cont.elAt(self._nIdx) except IndexError: raise StopIteration print print sEx2Doc print print "Default iteration works as before" print for n in Ex2_IteratableContClass(): print n, sys.stdout.flush() print print "But reverse iterator fails with an error : " print cont = Ex2_IteratableContClass() try: for n in Ex2_RevIteratorContClass(cont): print n, sys.stdout.flush() except: traceback.print_exc() sEx3Doc = \ """ Example 3. The previous example fails with the "iteration over non sequence" error because the "Ex2_RevIteratorContClass" iterator class doesn't support the __iter__ method. We therefore have to supply one, even at the price of only returning ""self"". I think this is ugly because it baffles the distinction between iterators and iteratables and we artificially have to add an ""__iter__"" method to the iterator itself, which should return ... well, an iterator, which it already is ! I presume that the rationale behind this is to keep the feature that the second argument place of the ""for ... in ..."" should be filled by a container (i.e. an iteratable), not an iterator. Another way that Python might have done this without breaking existing code is to make the ""for ... in ..."" construct invoke the __iter__ method if it exists, otherwise, directly call the ""next"" method on the supplied object. But this is only a minor quirk as the decoupling of the iterator from the iteratable is nonetheless achieved at the (small) price of adding an "almost" useles
Re: Zope: Adding a layer causes valid output to become an object reference?
"Junkmail" <[EMAIL PROTECTED]> writes on 10 Feb 2005 18:26:52 -0800: > I've been playing with Zope for about a year and took the plunge last > week into making a product. You should send Zope related questions to the Zope mailing list. You will need to subcribe. You can do this at "http://www.zope.org";. > ... > What doesn't work is when I refer to an object I've created from a > dtml-var or a tal:content or tal:replace statement. Instead of the > proper output I receive: where TextileClass is > my class name and home is the Object ID I'm referencing. There is a fundamental difference when you "call" an object with ZPublisher (i.e. via the Web) and when you use it in a template. ZPublisher effectively "calls" "index_html" and if this is "None", it calls the object. A template (usually) calls the object (if it is callable) and then converts the result into a string. Apparently, your ZInstance is not callable. Therefore, it is converted into a string. Apparently, it does not have a custom "__str__", therefore, you get the standard string conversion for instances (that's what you see). > The fact that > the < and > surround the output make it invisible in the browser and > had me chasing ghosts for a while. I'd bet I'm not groking something > here. This should not happen in ZPT (unless you use "structure"). > So if I call /home I get the proper HTML output: "What I am looking > for" but when in another object I reference I get: > "". > > Any thoughts are appreciated. Call a method on your ZInstance. To get the same result as via ZPublisher (the Web), call its "index_html". This may need arguments (I do not know). Dieter -- http://mail.python.org/mailman/listinfo/python-list
[EVALUATION] - E02 - Support for MinGW Open Source Compiler
I'm a newcomer to python: [EVALUATION] - E01: The Java Failure - May Python Helps? http://groups-beta.google.com/group/comp.lang.python/msg/75f0c5c35374f553 - I've download (as suggested) the python 2.4 installer for windows. Now I have problems to compile python extension that some packages depend on. I use the MinGW open-source compiler. - My questions: a) Why does the Python Foundation not provide additionally a binary version, compiled with MinGW or another open-source compiler? b) Why does the Python Foundation not ensure, that the python source-code is directly compilable with MinGW? c) Why are the following efforts not _directly_ included in the python source code base? http://jove.prohosting.com/iwave/ipython/pyMinGW.html above link found in this thread: http://groups-beta.google.com/group/comp.lang.python/msg/c9f0444c467de525 d) Is it really neccessary that I dive into such adventures, to be able to do the most natural thing like: "developing python extensions with MinGW"? http://starship.python.net/crew/kernr/mingw32/Notes.html e) Is there any official statement available regarding the msvcr71.dll and other MS licensing issues? [see several threads "[Python-Dev] Is msvcr71.dll re-redistributable?"] http://mail.python.org/pipermail/python-dev/2005-February/thread.html f) Are there any official (Python Foundation) statements / rationales available, which explain why the MinGW compiler is unsupported, although parts of the community obviously like to use it? http://groups-beta.google.com/group/comp.lang.python/msg/dc3474e6c8053336 - I just want to understand. Thankfull for any pointer to official documents / statements. [google is _not_ a fried here. I like to have a stable development environment, which is supported by the official projects, thus it can pass quality-assurance without beeing afraid about every next release.] . -- http://lazaridis.com -- http://mail.python.org/mailman/listinfo/python-list