Re: map/filter/reduce/lambda opinions and background unscientific mini-survey
Steven D'Aprano wrote: On Sat, 02 Jul 2005 20:26:31 -0700, Devan L wrote: Claiming that sum etc. do the same job is the whimper of someone who doesn't want to openly disagree with Guido. Could you give an example where sum cannot do the job(besides the previously mentioned product situation? There is an infinite number of potential lambdas, and therefore an infinite number of uses for reduce. sum only handles a single case, lambda x,y: x+y product adds a second case: lambda x,y: x*y So sum and product together cover precisely 2/infinity, or zero percent, of all possible uses of reduce. But together, sum and product, probably cover about 90% of situations in which you would use reduce. Getting a total (sum) from a list probably covers 80% of the situations reduce would be used on it's own. (I can't think of any real uses of product at the moment. It's late.) I'm just estimating, but I think that is the gist of adding those two in exchange for reduce. Not that they will replace all of reduce use cases, but that sum and product cover most situations and can be implemented more efficiently than using reduce or a for loop to do the same thing. The other situations can easily be done using for loops, so it's really not much of a loss. Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Will Guido's Python Regrets ever get implemented/fixed?
Thanks! Even the fact that these ideas have been organized into a PEP is exciting to methere is hope that they may *someday* be implemented. Maybe sooner than people think. Another reason to love Python like no other. Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: What's wrong with this code?
Hi all, Sure I'm able to publish the code, only the previous version though. If you want the first version; find Josh Cogliati, and ask him. It didn't have a random function, though. I got the idea to improve it from my computer course. Here is the code: #Plays the guessing game higher or lower # (originally written by by Josh Cogliati, improved by Quique) #This should actually be something that is semi random like the last digits of the time or something else. number = 78 guess = 0 while guess != number: guess =input(Guess a number: ) if guess number: print Too high elif guess number: print Too low print Just right HTH, Nathan Pinno John Machin [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Nathan Pinno wrote: Hi all, What's wrong with the following code? It says there is name error, that random is not defined. How do I fix it? Others have already answered that question. This posting is a pre-emptive strike to head off the next half-a-dozen questions. # Plays the guessing game higher or lower. # Originally written by Josh Cogliati, improved first by Quique, then by Nathan Pinno. Some of us are interested in the process by which great pieces of code arise, how they are meticulously honed and polished, which craftpersons contributed what ... is it possible for you to publish the earlier versions? print Higher or Lower print number = random.choice(range(100)) number will refer to one of: 0, 1, .., 98, 99 guess = 0 so you'll get a strange result by using zero here; try -1 instead while guess != number: guess = input(Guess a number: ) guess will refer to a string e.g. 42 which will *not* compare equal to the integer 42. Also you should use raw_input, not input. so do this: guess = int(raw_input(Guess a number: )) if guess number: print Too high guess = input(Guess a number: ) This will cause your program to ask TWICE per trip around the loop. Lose it. elif guess number: print Too low guess = input(Guess a number: ) ... and again. print Just right General advice: 1. Look on the Python web site (http://www.python.org) for an introduction to Python for non-programmers. 2. Join the Python tutor list. 3. In this news group, read a little more than the threads that you have started; this guessing game was discussed in a thread started by somebody calling themselves ChuckDubya on 29 June!! Homework?? HTH, John -- Posted via UsenetRevolution.com - Revolutionary Usenet ** HIGH RETENTION ** Specializing in Large Binaries Downloads ** http://www.UsenetRevolution.com -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientific mini-survey
Ron Adam wrote: But together, sum and product, probably cover about 90% of situations in which you would use reduce. Getting a total (sum) from a list probably covers 80% of the situations reduce would be used on it's own. (I can't think of any real uses of product at the moment. It's late.) It's not uncommon in mathematics to do repeated products. If you're familiar with the capital Greek letter sigma notation, if it's replaced with a capital Greek letter pi, then it's an iterated product, rather than an iterated sum: http://mathworld.wolfram.com/Product.html In general, pretty much _any_ operator can be replaced in this symbol to indicate a repeated operation. Function composition, set unions and intersections, logical conjunctions and disjunctions, direct sums and products, the list goes on and on. I'm just estimating, but I think that is the gist of adding those two in exchange for reduce. Not that they will replace all of reduce use cases, but that sum and product cover most situations and can be implemented more efficiently than using reduce or a for loop to do the same thing. The other situations can easily be done using for loops, so it's really not much of a loss. I really don't understand this reasoning. You essentially grant the position that reduce has a purpose, but you still seem to approve removing it. Let's grant your whole point and say that 90% of the use cases for reduce are covered by sum and product, and the other 10% are used by eggheads and are of almost no interest to programmers. But it still serves a purpose, and a useful one. That it's not of immediate use to anyone is an argument for moving it into a functional module (something I would have no serious objection to, though I don't see its necessity), not for removing it altogether! Why would you remove the functionality that already exists _and is being used_ just because? What harm does it do, vs. the benefit of leaving it in? I'm not myself a huge functional programming guy, but I'm certainly not in favor of the proposal to remove map, filter, reduce, and lambda. For map and filter, I can at least see the argument, because they truly are expressible with list comprehensions (which I do use myself, of course). lambda I also don't buy, but at least there, yes, you can just define a local function and use it locally, although I think expressively that it skirts the line between expressivity and verbosity (if you know what lambda is, straightforward use of lambda is not at all unclear, in fact it's quite clear). So at least there's something to that, but I don't follow it the whole way. But removing reduce is just removing functionality for no other reason, it seems, than spite. -- Erik Max Francis [EMAIL PROTECTED] http://www.alcyone.com/max/ San Jose, CA, USA 37 20 N 121 53 W AIM erikmaxfrancis Who knows whether any of us will be around in 1972? -- John F. Kennedy -- http://mail.python.org/mailman/listinfo/python-list
How to get 4 numbers from the user in one line for easy comparision?
I saw that great idea from Steven, and I appreciate it. I think it will work. Just need to figure out how to get 4 numbers from the player on one line for easy comparison, e.g. telling whether the number is correct position and number, incorrect position and correct number, or both are incorrect. If anyone has any advice in how to code this, I will gladly appreciate the help. Sorry if I seem like a newbie, but I am! :) Nathan Pinnohttp://www.npinnowebsite.ca/ -- http://mail.python.org/mailman/listinfo/python-list
a question
when I type sys.ps2 after import sys, I got the message like: Traceback (most recent call last): File pyshell#10, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' why does it happen? -- http://mail.python.org/mailman/listinfo/python-list
debugger?
I have read a lot of posts discussing python IDEs, but most of them focus on the editor, GUI builder, project management, customizability, etc Some talked about debugging capability, but only on an available/unavailable level. I use vim to edit my code, wxGlade to build the GUI or hand-code it, and I still prefer that. So, until now, I haven't tried many IDEs. However, while I use pdb or inserting print statement to debug my apps, sometimes it is a pain. I think I need a good GUI debugger to help me. The debugger should meet _most_ of the following requirements: 1. can debug wxPython applications (and other GUI lib). 2. an intuitive way to set/clear/enable/disable breakpoints. 3. can set conditional breakpoints (i.e. break when some condition satisfied). 4. variable watch list, namescope watching (local, global) 5. evaluate expression, change variable values, etc within debugging. 6. change the running routine, (i.e. go directly to a statement, skip some statements, etc) 7. clever way to express objects, not just a string returned by repr() 8. perform profiling 9. a clear interface. 10. cross-platform. 11. free, or better, open source. What debugger will you suggest? Or what more polish feature you want to see in an ideal python debugger? -- hope this thread will help IDE developers to fill their todo list with some shining ideas :) -- Qiangning Hong Get Firefox! http://www.spreadfirefox.com/?q=affiliatesamp;id=67907amp;t=1 -- http://mail.python.org/mailman/listinfo/python-list
Re: debugger?
Qiangning Hong wrote: I have read a lot of posts discussing python IDEs, but most of them focus on the editor, GUI builder, project management, customizability, etc Some talked about debugging capability, but only on an available/unavailable level. I use vim to edit my code, wxGlade to build the GUI or hand-code it, and I still prefer that. So, until now, I haven't tried many IDEs. However, while I use pdb or inserting print statement to debug my apps, sometimes it is a pain. I think I need a good GUI debugger to help me. The debugger should meet _most_ of the following requirements: 1. can debug wxPython applications (and other GUI lib). 2. an intuitive way to set/clear/enable/disable breakpoints. 3. can set conditional breakpoints (i.e. break when some condition satisfied). 4. variable watch list, namescope watching (local, global) 5. evaluate expression, change variable values, etc within debugging. 6. change the running routine, (i.e. go directly to a statement, skip some statements, etc) 7. clever way to express objects, not just a string returned by repr() 8. perform profiling 9. a clear interface. 10. cross-platform. 11. free, or better, open source. What debugger will you suggest? Or what more polish feature you want to see in an ideal python debugger? -- hope this thread will help IDE developers to fill their todo list with some shining ideas :) Eric3 should be compliant with your list. Try it at http://www.die-offenbachs.de/detlev/eric3.html Regards, Detlev -- Detlev Offenbach [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite non-python language trick?
On Sun, 03 Jul 2005 00:39:19 -0400, Christopher Subich wrote: Devan L wrote: sum(sequence[0] + [1/element for element in sequence[1:]]) I think that should work. That won't work, because it misses the x*y part of the expression (x[n]*x[n+1] + 1/x[n+1], for people who haven't immediately read the grandparent). Personally, I think demanding that it be writable as a sum (or product, or any, or all) is a false standard -- nobody's claimed that these would replace all cases of reduce, just the most common ones. Er, excuse me, but that is EXACTLY what Devan claimed. Quote: With the exception of reduce(lambda x,y:x*y, sequence), reduce can be replaced with sum, and Guido wants to add a product function. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
how to retrive highlighted text in a browser?
Hello group, When browsing websites, quite often I have to look up words in dictionary. I'm hoping that I can come up with a python program that does the following: When I highlight some text in browser and right-click, besides the default options such as COPY, PASTE, etc, I want an option that says Send to file, something like that. The file is a text file, with fixed path. When I select this option, the highlighted text will be appended to the text file. This way, I can collect those words phrases that I don't know. Is this going to be a difficult task? I'm a newbie in python. TIA for your help. - wcc -- http://mail.python.org/mailman/listinfo/python-list
Re: a question
On Sun, 03 Jul 2005 03:19:45 -0400, Xinyue Ye wrote: when I type sys.ps2 after import sys, I got the message like: Traceback (most recent call last): File pyshell#10, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' why does it happen? It works for me. import sys sys.ps2 '... ' Can you cut and past the relevant lines from your interactive session? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Favorite non-python language trick?
Steven D'Aprano wrote: How do you replace: reduce(lambda x,y: x*y-1/y, sequence) with sum? missing = object() def my_reduce(f, items, first=missing): class adder: def __init__(self, value): self.value = value def __add__(self, other): return adder(f(self.value, other)) if first is missing: items = iter(items) try: first = items.next() except StopIteration: raise TypeError return sum(items, adder(first)).value if __name__ == __main__: sequence = map(float, range(10)) r = reduce(lambda x, y: x*y-1/y, sequence) s = my_reduce(lambda x, y: x*y-1/y, sequence) assert r == s :-) Peter -- http://mail.python.org/mailman/listinfo/python-list
question about raw_input
Hello group, After searching free IDE for a while, i picked PyScripter(http://mmm-experts.com/Products.aspx). It is neat. I like it. But I always get error when using raw_input function. Please see below. raw_input(Press ENTER to continue...) Press ENTER to continue...Traceback (most recent call last): File interactive input, line 1, in ? EOFError: EOF when reading a line I don't see this error when using the IDE from python or activepython. Thanks for your time, - wcc -- http://mail.python.org/mailman/listinfo/python-list
website catcher
Hello, I'm busy to build some kind of webpage framework written in Python. But there's a small problem in this framework. This framework should open a page, parse it, take some other information out of it and should store it in some kind of fast storage. This storage need to be very fast so every one who will ask for this page will get a parsed page returned from this storage (catcher?). But how could I design a good webcatcher? Is this possible in python, because it should always run. Which won't work with cgi-bin pages because the quit after the execute something. Or should it be build in c and imported as a module or something? Thank you, Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: debugger?
Detlev Offenbach wrote: Qiangning Hong wrote: I have read a lot of posts discussing python IDEs, but most of them focus on the editor, GUI builder, project management, customizability, etc Some talked about debugging capability, but only on an available/unavailable level. I use vim to edit my code, wxGlade to build the GUI or hand-code it, and I still prefer that. So, until now, I haven't tried many IDEs. However, while I use pdb or inserting print statement to debug my apps, sometimes it is a pain. I think I need a good GUI debugger to help me. The debugger should meet _most_ of the following requirements: 1. can debug wxPython applications (and other GUI lib). 2. an intuitive way to set/clear/enable/disable breakpoints. 3. can set conditional breakpoints (i.e. break when some condition satisfied). 4. variable watch list, namescope watching (local, global) 5. evaluate expression, change variable values, etc within debugging. 6. change the running routine, (i.e. go directly to a statement, skip some statements, etc) 7. clever way to express objects, not just a string returned by repr() 8. perform profiling 9. a clear interface. 10. cross-platform. 11. free, or better, open source. What debugger will you suggest? Or what more polish feature you want to see in an ideal python debugger? -- hope this thread will help IDE developers to fill their todo list with some shining ideas :) Eric3 should be compliant with your list. Try it at http://www.die-offenbachs.de/detlev/eric3.html Regards, Detlev Eric3 need pyqt so it is not free under windows platform. -- Qiangning Hong _ / Humanity has advanced, when it has advanced, not because it \ | has been sober, responsible, and cautious, but because it | | has been playful, rebellious, and immature. | | | \ -- Tom Robbins / - \ ,, \ /()` \ \ \___ / | /- _ `-/ ' (/\/ \ \ /\ / / | `\ O O ) /| `-^--'` ' (_.) _ ) / `.___/`/ `-' / . __ / __ \ |O)))==) \) / '`--' `.__,' \ || \ / __( (_ / \__ ,' ,-' |\ `--{__)\/ -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientific mini-survey
On Sat, Jul 02, 2005 at 08:26:31PM -0700, Devan L wrote: Also, map is easily replaced. map(f1, sequence) == [f1(element) for element in sequence] How do you replace map(f1,sequence1, sequence2) especially if the sequences are of unequal length ? I didn't see it mentioned yet as a candidate for limbo, but the same question goes for: zip(sequence1,sequence2) -- Egbert Bouwman - Keizersgracht 197 II - 1016 DS Amsterdam - 020 6257991 -- http://mail.python.org/mailman/listinfo/python-list
question
IDLE 1.0.3 import sys sys.ps2 Traceback (most recent call last): File pyshell#1, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' where is the problem? -- Forwarded message -- From: Steven D'Aprano [EMAIL PROTECTED] To: python-list@python.org Date: Sun, 03 Jul 2005 18:51:07 +1000 Subject: Re: a question On Sun, 03 Jul 2005 03:19:45 -0400, Xinyue Ye wrote: when I type sys.ps2 after import sys, I got the message like: Traceback (most recent call last): File pyshell#10, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' why does it happen? It works for me. import sys sys.ps2 '... ' Can you cut and past the relevant lines from your interactive session? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: a question
Xinyue Ye wrote: when I type sys.ps2 after import sys, I got the message like: Traceback (most recent call last): File pyshell#10, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' why does it happen? sys.ps2 is defined in an interactive session only as precised in the doc [1]: $ python Python 2.3.5 (#2, May 29 2005, 00:34:43) [GCC 3.3.6 (Debian 1:3.3.6-5)] on linux2 Type help, copyright, credits or license for more information. import sys print sys.ps2 ... compared to: $ cat ps2.py import sys print sys.ps2 $ python ps2.py Traceback (most recent call last): File ps2.py, line 2, in ? print sys.ps2 AttributeError: 'module' object has no attribute 'ps2' $ [1] http://docs.python.org/lib/module-sys.html -- http://mail.python.org/mailman/listinfo/python-list
Re: how to retrive highlighted text in a browser?
I don't know how hard this would be to do in Python - appending text to a file is straightforward, but it sounds like you'd need to extend the browser itself to get the functionality you want. The most obvious choice if you want an extensible browser is Mozilla Firefox (http://www.mozilla.org/products/firefox/), but AFAIK its extensions are written in C++, and I'm not sure how easy it would be to get Python into the mix. If you do get this working, I'd love to hear about it! I've wanted this feature in browers for a long time. -- http://mail.python.org/mailman/listinfo/python-list
Tkinter Checkbutton initialization problem
Python 2.4, Windows XP. If I say: f = Frame() f.grid() v = IntVar() c = Checkbutton(f, text='hi there', variable=v) c.grid() f.mainloop() then the checkbutton should initially display as being checked. But it doesn't. It shows up unchecked, even though v.get() returns 1. The select operation DOES update the display if there's no variable. It works properly under Linux with (I think) Python 2.3. I don't have a 2.4.1 Windows installation to try right now. Is this a known bug? Is it fixed in 2.4.1? Is there a simple workaround, that lets me initialize a checkbutton and still be able to read its state? Thanks. -- http://mail.python.org/mailman/listinfo/python-list
what is the difference between command prompt and IDLE?
what is the difference between command prompt and IDLE? -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code
On Sat, 2 Jul 2005 03:04:09 -0700 (PDT), Ralf W. Grosse-Kunstleve [EMAIL PROTECTED] wrote: Hi fellow Python coders, I often find myself writing:: class grouping: def __init__(self, x, y, z): self.x = x self.y = y self.z = z # real code, finally This becomes a serious nuisance in complex applications with long argument lists, especially if long variable names are essential for managing the complexity. Therefore I propose that Python includes built-in support for reducing the ``self.x=x`` clutter. With some help from new-style classes you can get more than just removing the self.x = x clutter. I'm not an expert of these low-level python tricks, but you can download from http://www.gripho.it/objs.py a small example that allows you to write class MyClass(Object): x = Float(default = 0.0, max = 1E20) y = Float(min = 1.0) and you can get in addition of redudancy removal also parameter checking. You can also have an __init__ method that gets called with attributes already set up. HTH Andrea -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Sun, 3 Jul 2005, Steven D'Aprano wrote: On Sun, 03 Jul 2005 02:22:23 +0200, Fredrik Johansson wrote: On 7/3/05, Tom Anderson [EMAIL PROTECTED] wrote: That's one way. I'd do: root = value ** 0.5 Does that mean we can expect Guido to drop math.sqrt in py3k? :) I'd rather like to see a well implemented math.nthroot. 64**(1/3.0) gives 3.9996, and this error could be avoided. py math.exp(math.log(64)/3.0) 4.0 Success!!! Eeenteresting. I have no idea why this works. Given that math.log is always going to be approximate for numbers which aren't rational powers of e (which, since e is transcendental, is all rational numbers, and therefore all python floats, isn't it?), i'd expect to get the same roundoff errors here as with exponentiation. Is it just that the errors are sufficiently smaller that it looks exact? Note how much simpler this would be if we could guarantee proper infinities and NaNs in the code. We could turn a 23-line block to a one-liner. YES! This is something that winds me up no end; as far as i can tell, there is no clean programmatic way to make an inf or a NaN; in code i write which cares about such things, i have to start: inf = 1e300 ** 1e300 nan = inf - inf Every bloody time. I'm going to be buggered if python ever rolls out some sort of bigfloat support. And then god forbid i should actually want to test if a number is NaN, since, bizarrely, (x == nan) is true for every x; instead, i have to write: def isnan(x): return (x == 0.0) and (x == 1.0) The IEEE spec actually says that (x == nan) should be *false* for every x, including nan. I'm not sure if this is more or less stupid than what python does! And while i'm ranting, how come these expressions aren't the same: 1e300 * 1e300 1e300 ** 2 And finally, does Guido know something about arithmetic that i don't, or is this expression: -1.0 ** 0.5 Evaluated wrongly? tom -- Please! Undo clips before opening handle. -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
John Roth wrote: Robert Kern [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] map and filter are being removed *because of* list comprehensions. Did you even read Guido's articles about this issue? Your understanding of why these changes are planned is incorrect; consequently your projection based on that understanding is not on firm footing. May I most respectfully point out that you've got it backwards. Part of the justification for list comprehensions was that they could be used to replace map and filter. The jihad against the functional constructs has been going on for a long time, and list comprehensions are only one piece of it. Many people believe that the functional constructs in Python exist to enhance Python's support of functional programming, but that's wrong. They exist to enhance support of procedural programming. In other words, the functional elements were added not because Python embraced functional programming, but because discreet use of functional code can make procedural programs simpler and more concise. Listcomps et al. cannot do everything map, lambda, filter, and reduce did. Listcomps are inferior for functional programming. But, you see, functional is not the point. Streamlining procedural programs is the point, and I'd say listcomps do that far better, and without all the baroque syntax (from the procedural point of view). Jihad? I'd say it's mostly just indifference to the functional programming cause. -- CARL BANKS -- http://mail.python.org/mailman/listinfo/python-list
No sys.ps2 in IDLE (was Re: question)
yipusi wrote: IDLE 1.0.3 import sys sys.ps2 Traceback (most recent call last): File pyshell#1, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' where is the problem? The problem is that you are using IDLE (and an old version at that), which doesn't use sys.ps2. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: No sys.ps2 in IDLE (was Re: question)
What should I do to correct the errors accordingly? On 7/3/05, Michael Hoffman [EMAIL PROTECTED] wrote: yipusi wrote: IDLE 1.0.3 import sys sys.ps2 Traceback (most recent call last): File pyshell#1, line 1, in -toplevel- sys.ps2 AttributeError: 'module' object has no attribute 'ps2' where is the problem? The problem is that you are using IDLE (and an old version at that), which doesn't use sys.ps2. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: debugger?
Qiangning Hong wrote: Detlev Offenbach wrote: Qiangning Hong wrote: I have read a lot of posts discussing python IDEs, but most of them focus on the editor, GUI builder, project management, customizability, etc Some talked about debugging capability, but only on an available/unavailable level. I use vim to edit my code, wxGlade to build the GUI or hand-code it, and I still prefer that. So, until now, I haven't tried many IDEs. However, while I use pdb or inserting print statement to debug my apps, sometimes it is a pain. I think I need a good GUI debugger to help me. The debugger should meet _most_ of the following requirements: 1. can debug wxPython applications (and other GUI lib). 2. an intuitive way to set/clear/enable/disable breakpoints. 3. can set conditional breakpoints (i.e. break when some condition satisfied). 4. variable watch list, namescope watching (local, global) 5. evaluate expression, change variable values, etc within debugging. 6. change the running routine, (i.e. go directly to a statement, skip some statements, etc) 7. clever way to express objects, not just a string returned by repr() 8. perform profiling 9. a clear interface. 10. cross-platform. 11. free, or better, open source. What debugger will you suggest? Or what more polish feature you want to see in an ideal python debugger? -- hope this thread will help IDE developers to fill their todo list with some shining ideas :) Eric3 should be compliant with your list. Try it at http://www.die-offenbachs.de/detlev/eric3.html Regards, Detlev Eric3 need pyqt so it is not free under windows platform. If you use it together with the free windows port of Qt and PyQt, than it is free. Detlev -- Detlev Offenbach [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: what is the difference between command prompt and IDLE?
start reading here: http://www.python.org/idle/doc/idlemain.html, although it is not up to date most of the information still holds up -- http://mail.python.org/mailman/listinfo/python-list
Re: question
see the answer on your previous post ( http://groups-beta.google.com/group/comp.lang.python/browse_frm/thread/8e132d9c734907b/87fd1f579a362e71?q=rnum=2hl=en#87fd1f579a362e71), to get an interactive session open a command window and type ' python' -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
You can catch the content of an url like this: http://www.python.org/doc/current/lib/node478.html, from here you can parse it, and the store the result e.g. in dictionary, you will have a very well performing solution like this. -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
Thank you, but it's not what I mean. I don't want some kind of client parser thing. But I mean the page is already been parsed and ready to be read. But I want to store this page for more use. I need some kind of database that won't exit if the cgi-bin script has finished. This database need to be open all the time and communicate very easily with the cgi-bin framwork main class. -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
jwaixs wrote: Thank you, but it's not what I mean. I don't want some kind of client parser thing. But I mean the page is already been parsed and ready to be read. But I want to store this page for more use. I need some kind of database that won't exit if the cgi-bin script has finished. This database need to be open all the time and communicate very easily with the cgi-bin framwork main class. Why does it need to be open? Store it in a pickled file, an load read that pickle when you need it. Or not even as pickle, just as file in the FS. Basically what you are talking about is a webserver - so just use that. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python, mysql, floating point values question
Dennis Lee Bieber wrote: Considering how often this has come up, I've sort of lost faith in CS programs at colleges. Now, this might be an unfair statement as I don't know if any of those bringing up the question ever had college CS courses... But the fluff of floating point data was something I vaguely recall had been covered in my second FORTRAN class [1976-77; I ran FORTRAN, Advanced FORTRAN, and Assembly in my first year] (since COBOL used packed decimal, it wasn't a candidate for the behavior -- not problem, as it is not erroneous behavior, just something one needs to learn about). A book that may be out of print Real Numbers Made Real (hope I recalled the name) covers some of this. Almost -- the book is Real Computing Made Real: Preventing Errors in Scientific and Engineering Calculations, by Forman S. Acton -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
If I should put the parsedwebsites in, for example, a tablehash it will be at least 5 times faster than just putting it in a file that needs to be stored on a slow harddrive. Memory is a lot faster than harddisk space. And if there would be a lot of people asking for a page all of them have to open that file. if that are 10 requests in 5 minutes there's no real worry. If they are more that 10 request per second you really have a big problem and the framework would probably crash or will run uber slow. That's why I want to open the file only one time and keep it saved in the memory of the server where it don't need to be opened each time some is asking for it. Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
Re: Python, mysql, floating point values question
Use DECIMAL columns with MySQLdb-1.2.0 and Python-2.4 and you should get values back using Python's new decimal type. http://docs.python.org/whatsnew/node9.html This avoids floating point inaccuracies. -- http://mail.python.org/mailman/listinfo/python-list
Re: Will Guido's Python Regrets ever get implemented/fixed?
Robert Kern [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Guido gave a nice Python Regrets Power Point talk at OSCON few years ago. I was wondering if the plan is to ever implement these ideas. e.g. Guido said he'd prefer 'print' to be a *function* with perhaps a 'println' version IIRC. He also had a ton of stuff he'd rather see become iterators. As currently being (re)discussed at tedious length in recent threads here, changes would will only be realized in Python 3.0 (aka Python 3000 in facetious reference to when we can expect to see such a beast). I believe the current plan is to make compatible changes in the next few releases, and then make the incompatable changes in Python 3.0 See PEP 3000 for details. http://www.python.org/peps/pep-3000.html What this means is that there is a good chance that a print() built-in function or method on a file object may show up in a future release, the print statment won't go away until Python 3.0. John Roth -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: debugger?
You might also look at Boa. http://boa-constructor.sourceforge.net/ While I haven't tried all the things on your list, I've been able to do all the things I've wanted to do in the debugger. It is also an IDE for wxPython, so it works well for that, but I don't know about other GUI libraries. Qiangning Hong wrote: snip ...The debugger should meet _most_ of the following requirements: 1. can debug wxPython applications (and other GUI lib). 2. an intuitive way to set/clear/enable/disable breakpoints. 3. can set conditional breakpoints (i.e. break when some condition satisfied). 4. variable watch list, namescope watching (local, global) 5. evaluate expression, change variable values, etc within debugging. 6. change the running routine, (i.e. go directly to a statement, skip some statements, etc) 7. clever way to express objects, not just a string returned by repr() 8. perform profiling 9. a clear interface. 10. cross-platform. 11. free, or better, open source. What debugger will you suggest? Or what more polish feature you want to see in an ideal python debugger? -- hope this thread will help IDE developers to fill their todo list with some shining ideas :) Frank LaFond http://www.effectiveqa.com -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
jwaixs wrote: If I should put the parsedwebsites in, for example, a tablehash it will be at least 5 times faster than just putting it in a file that needs to be stored on a slow harddrive. Memory is a lot faster than harddisk space. And if there would be a lot of people asking for a page all of them have to open that file. if that are 10 requests in 5 minutes there's no real worry. If they are more that 10 request per second you really have a big problem and the framework would probably crash or will run uber slow. That's why I want to open the file only one time and keep it saved in the memory of the server where it don't need to be opened each time some is asking for it. I don't think that's correct. An apache serves static pages with high speed - and slow hardrives means about 32MByte/s nowadays. Which equals 256MBit/s - is your machine connected to a GBit connection? And if it's for internet usage, do you have a GBit connection - if so, I envy you... And if your speed has to have that high, I wonder if python can be used at all. BTW, 10 reqeuest per seconds of maybe 100KB pages is next to nothing - just 10MBit. It's not really fast. And images and the like are also usually served from HD. You are of course right that memory is faster than harddrives. but HDs are (ususally) faster than network IO - so that's your limiting factor, if at all. And starting CGI subrpocesses introduces also lots of overhead - better use fastcgis then. I think that we're talking about two things here: - premature optimization on your side. Worry about speed later, if it _is_ an issue. Not now. - what you seem to want is a convenient way of having data serverd to you in a pythonesque way. I personally don't see anything wrong with storing and retrieving pages from HD - after all, that's where they end up anyway ebentually. So if you write yourself a HTMLRetrieval class that abstratcs that for you and 1) takes a piece of HTML and stores that, maybe associated with some metadata 2) can retrieve these chunks of based on some key you are pretty much done. If you want, you can back it up using a RDBMS, hoping that it will do the in-memory-caching for you. But remember that there will be no connection pooling using CGIs, so that introduces overhead. Or you go for your own standalone process that serves the pages through some RPC mechanism. Or you ditch CGIs at all and use some webframework that serves from an permanenty running python process with several worker threads - then you can use in-process memory by global variables to store that memory. For that, I recommend twisted. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Will Guido's Python Regrets ever get implemented/fixed?
[EMAIL PROTECTED] wrote: Thanks! Even the fact that these ideas have been organized into a PEP is exciting to methere is hope that they may *someday* be implemented. Maybe sooner than people think. Given that the latest 2.x python will be 2.9 and that 3.0 may be released in parallel with 2.5-2.9 (http://www.python.org/doc/essays/ppt/euro2004/euro2004.ppt), I guess this *someday* will be no later than 2015-16, probably sooner than that. George -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Sun, 03 Jul 2005 10:56:42 +0100, Tom Anderson wrote: On Sun, 3 Jul 2005, Steven D'Aprano wrote: On Sun, 03 Jul 2005 02:22:23 +0200, Fredrik Johansson wrote: On 7/3/05, Tom Anderson [EMAIL PROTECTED] wrote: That's one way. I'd do: root = value ** 0.5 Does that mean we can expect Guido to drop math.sqrt in py3k? :) I'd rather like to see a well implemented math.nthroot. 64**(1/3.0) gives 3.9996, and this error could be avoided. py math.exp(math.log(64)/3.0) 4.0 Success!!! Eeenteresting. I have no idea why this works. Given that math.log is always going to be approximate for numbers which aren't rational powers of e (which, since e is transcendental, is all rational numbers, and therefore all python floats, isn't it?), i'd expect to get the same roundoff errors here as with exponentiation. Is it just that the errors are sufficiently smaller that it looks exact? I have no idea :-) Unfortunately, floating point maths is a bit of a black art. Try this simple calculation: py 4.0/3 - 5.0/6 0.49989 Should be 0.5 exactly. Many numbers which you can write exactly in decimal cannot be stored exactly in floating point. Even something as simple as one tenth 0.1 doesn't have an exact representation in binary: py 1.0/10 0.10001 Note how much simpler this would be if we could guarantee proper infinities and NaNs in the code. We could turn a 23-line block to a one-liner. YES! This is something that winds me up no end; as far as i can tell, there is no clean programmatic way to make an inf or a NaN; in code i write which cares about such things, i have to start: inf = 1e300 ** 1e300 nan = inf - inf Every bloody time. I'm going to be buggered if python ever rolls out some sort of bigfloat support. It fails for me: py inf = 1e300 ** 1e300 Traceback (most recent call last): File stdin, line 1, in ? OverflowError: (34, 'Numerical result out of range') But this works: py inf = float(inf) py inf inf And then god forbid i should actually want to test if a number is NaN, since, bizarrely, (x == nan) is true for every x; Well dip me in chocolate and call me a Tim Tam, you're right. That is bizarre. No, that's not the word I want... that behaviour is broken. instead, i have to write: def isnan(x): return (x == 0.0) and (x == 1.0) The IEEE spec actually says that (x == nan) should be *false* for every x, including nan. I'm not sure if this is more or less stupid than what python does! Well, no, the IEEE standard is correct. NaNs aren't equal to anything, including themselves, since they aren't numbers. Okay, infinity isn't a number either. But there are rules for arithmetic for infinity, based on limit calculations, so it makes sense to treat infinity as a number where possible. Apple Computer had a maths library that implemented a superset of IEEE arithmetic. It allowed for 254 different NaNs (twice that if you looked at the sign bit, which you weren't supposed to do). This wasn't a deliberate feature as such, it merely fell out naturally from the bit-patterns that represented NaNs, but it was useful since Apple took advantage of it by specifying certain particular NaNs for certain failure modes. Eg NaN(1) might represent the square root of a negative number, but NaN(2) might be INF-INF. Furthermore, you could easily query the class of a number (zero, normalised, denormalised, infinity, NaN), so you would test for a NaN by doing something like: if Kind(x) == NanKind: ... or if isNaN(x): ... And while i'm ranting, how come these expressions aren't the same: 1e300 * 1e300 1e300 ** 2 Because this is floating point, not real maths :-) I get inf and Overflow respectively. What do you get? And finally, does Guido know something about arithmetic that i don't, or is this expression: -1.0 ** 0.5 Evaluated wrongly? No, it is evaluated according to the rules of precedence. It is equivalent to -(1.0**0.5). You are confusing it with (-1.0)**0.5 which fails as expected. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: No sys.ps2 in IDLE (was Re: question)
shisa wrote: What should I do to correct the errors accordingly? What error? IDLE appears to be behaving as designed. Also, please don't top-post--it makes responding to your message in a way that others can understand more difficult. http://en.wikipedia.org/wiki/Top-posting -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
How to dump an interpreter image?
Hi, is it possible to save a state of the python interpreter to disk and load it later? Thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] How to get 4 numbers from the user in one line for easycomparision?
I Just need to figure out how to get 4 numbers from the player on one line for easy comparison, Unless there is a set of batteries somewhere that I don't know about I think you have to rely on reading the line as a string and then splitting it. line = raw_input('Type 4 numbers separated by spaces: ') numbers = [int(n) for n in line.split(' ')] HTH, Alan G. -- http://mail.python.org/mailman/listinfo/python-list
Re: question about raw_input
wcc wrote: Hello group, After searching free IDE for a while, i picked PyScripter(http://mmm-experts.com/Products.aspx). It is neat. I like it. But I always get error when using raw_input function. Please see below. raw_input(Press ENTER to continue...) Press ENTER to continue...Traceback (most recent call last): File interactive input, line 1, in ? EOFError: EOF when reading a line I don't see this error when using the IDE from python or activepython. Then it's probably a problem with PyScripter, not Python. You'd be better off asking the PyScripter people than asking here. -- Michael Hoffman -- http://mail.python.org/mailman/listinfo/python-list
Re: How to dump an interpreter image?
VansMll wrote: Hi, is it possible to save a state of the python interpreter to disk and load it later? Should be doable in stackless python. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Mon, 4 Jul 2005, Steven D'Aprano wrote: On Sun, 03 Jul 2005 10:56:42 +0100, Tom Anderson wrote: On Sun, 3 Jul 2005, Steven D'Aprano wrote: On Sun, 03 Jul 2005 02:22:23 +0200, Fredrik Johansson wrote: On 7/3/05, Tom Anderson [EMAIL PROTECTED] wrote: That's one way. I'd do: root = value ** 0.5 Does that mean we can expect Guido to drop math.sqrt in py3k? :) I'd rather like to see a well implemented math.nthroot. 64**(1/3.0) gives 3.9996, and this error could be avoided. py math.exp(math.log(64)/3.0) 4.0 Success!!! Eeenteresting. I have no idea why this works. Given that math.log is always going to be approximate for numbers which aren't rational powers of e (which, since e is transcendental, is all rational numbers, and therefore all python floats, isn't it?), i'd expect to get the same roundoff errors here as with exponentiation. Is it just that the errors are sufficiently smaller that it looks exact? I have no idea :-) Unfortunately, floating point maths is a bit of a black art. Try this simple calculation: py 4.0/3 - 5.0/6 0.49989 Should be 0.5 exactly. Many numbers which you can write exactly in decimal cannot be stored exactly in floating point. Even something as simple as one tenth 0.1 doesn't have an exact representation in binary: py 1.0/10 0.10001 I realise that - but all that argues that your example shouldn't work either! I think there would be a lot less confusion over the alleged inaccuracy of floating point if everyone wrote in hex - indeed, i believe that C99 has hex floating-point literals. C has always been such a forward-thinking language! Note how much simpler this would be if we could guarantee proper infinities and NaNs in the code. We could turn a 23-line block to a one-liner. YES! This is something that winds me up no end; as far as i can tell, there is no clean programmatic way to make an inf or a NaN; in code i write which cares about such things, i have to start: inf = 1e300 ** 1e300 nan = inf - inf Every bloody time. I'm going to be buggered if python ever rolls out some sort of bigfloat support. It fails for me: py inf = 1e300 ** 1e300 Traceback (most recent call last): File stdin, line 1, in ? OverflowError: (34, 'Numerical result out of range') Oops. I meant to write 1e300 * 1e300 - multiplication, not exponentiation. My bad. But this works: py inf = float(inf) py inf inf True. Still, i'd rather not have to rely on string parsing to generate a fairly fundamental arithmetic quantity. And then god forbid i should actually want to test if a number is NaN, since, bizarrely, (x == nan) is true for every x; Well dip me in chocolate and call me a Tim Tam, you're right. That is bizarre. No, that's not the word I want... that behaviour is broken. instead, i have to write: def isnan(x): return (x == 0.0) and (x == 1.0) The IEEE spec actually says that (x == nan) should be *false* for every x, including nan. I'm not sure if this is more or less stupid than what python does! Well, no, the IEEE standard is correct. NaNs aren't equal to anything, including themselves, since they aren't numbers. I don't buy that. Just because something isn't a number doesn't mean it can't be equal to something else, does it? I mean, we even say x == None if x is indeed None. Moreover, this freaky rule about NaNs means that this is an exception to the otherwise absolutely inviolate law that x == x. I'd rather have that simple, fundamental logical consistency than some IEEE rocket scientist's practical-value-free idea of mathematical consistency. Apple Computer had a maths library that implemented a superset of IEEE arithmetic. It allowed for 254 different NaNs (twice that if you looked at the sign bit, which you weren't supposed to do). This wasn't a deliberate feature as such, it merely fell out naturally from the bit-patterns that represented NaNs, but it was useful since Apple took advantage of it by specifying certain particular NaNs for certain failure modes. Eg NaN(1) might represent the square root of a negative number, but NaN(2) might be INF-INF. Furthermore, you could easily query the class of a number (zero, normalised, denormalised, infinity, NaN), so you would test for a NaN by doing something like: if Kind(x) == NanKind: ... or if isNaN(x): ... We should add that to python - although it would one one small step for NaN, one giant leap for NanKind. Sorry. And while i'm ranting, how come these expressions aren't the same: 1e300 * 1e300 1e300 ** 2 Because this is floating point, not real maths :-) I get inf and Overflow respectively. What do you get? The same. They really ought to give the same answer. And finally, does Guido know something about arithmetic that i don't, or is this expression: -1.0 ** 0.5 Evaluated wrongly? No, it is evaluated according to the rules of precedence. It is
Re: math.nroot [was Re: A brief question.]
Steven D'Aprano [EMAIL PROTECTED] wrote: Unfortunately, floating point maths is a bit of a black art. Try this simple calculation: py 4.0/3 - 5.0/6 0.49989 Should be 0.5 exactly. Many numbers which you can write exactly in decimal cannot be stored exactly in floating point. Even something as simple as one tenth 0.1 doesn't have an exact representation in binary: py 1.0/10 0.10001 Given that 0.5 *can* be represented exactly in binary (try 0.3/0.6), your first example illustrates something worse about floating point arithmetic: not only many decimal numbers cannot be represented exactly as binary floating point, but that the kind and the order of operations in arithmetic expressions affects the accuracy of the result. *Even worse* than that, errors can be accumulated over a sequence of operations, so that even if each individual error is typically very small, the overall error might be non-trivial. There's a whole area studying the analysis and control of error in floating point arithmetic so it's not quite black art for everyone; e.g. see http://docs.sun.com/source/806-3568/ncg_goldberg.html, http://http.cs.berkeley.edu/~demmel/cs267/lecture21/lecture21.html for more. George -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
Tom Anderson [EMAIL PROTECTED] wrote: And finally, does Guido know something about arithmetic that i don't, or is this expression: -1.0 ** 0.5 Evaluated wrongly? No, it is evaluated according to the rules of precedence. It is equivalent to -(1.0**0.5). You are confusing it with (-1.0)**0.5 which fails as expected. Ah. My mistake. I submit that this is also a bug in python's grammar. There's probably some terribly good reason for it, though. How about 'conformance with standard mathematic notation', does this count for a terribly good reason ? What would one expect to be the result of 5^2 - 2^2, 29 or 21 ? Would you expect 5^2 + - 2^2 to be different, even if you write it as 5^2 + -2 ^ 2 ? White space is not significant in math AFAIK ;-) George -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
egbert wrote: On Sat, Jul 02, 2005 at 08:26:31PM -0700, Devan L wrote: Also, map is easily replaced. map(f1, sequence) == [f1(element) for element in sequence] How do you replace map(f1,sequence1, sequence2) especially if the sequences are of unequal length ? I didn't see it mentioned yet as a candidate for limbo, but the same question goes for: zip(sequence1,sequence2) OK, you guys are picking on what reduce cannot do. The first is [f1(*args) for args in itertools.izip(iter1, iter2)] How to _you_ use map to avoid making all the intermediate structures? I never saw anything about making zip go away. It is easy to explain. Now reduce maps to what I was taught to call foldl. How do you express foldr? How do you express: _accum = initial() for elem in iterable: _accum = func(elem, _accum, expr) ... If you want functional programming in python, you have at least three big problems: 1) Python has side effect like mad, so order of evaluation matters. I'd claim any useful language is like that (I/O to a printer is kind of hard to do out-of-order), but I'd get sliced to death by a bunch of bullies wielding Occam's razors. 2) Python's essential function call is not a single-argument function which might be a tuple, it is a multi-argument function which is not evaluated in the same way. The natural duality of a function taking pairs to a function taking an arg and returning a function taking an arg and returning a result breaks down in the face of keyword args, and functions that take an indeterminate number of arguments. Also, because of (1), there is a big difference between a function taking no args and its result. 3) Python doesn't have a full set of functional primitives. Fold-right is one example, K-combinator is another, Why pick on reduce as-is to keep? There is another slippery slope argument going up the slope adding functional primitives. --Scott David Daniels [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get 4 numbers from the user in one line for easycomparision?
Alan G [EMAIL PROTECTED] wrote: I Just need to figure out how to get 4 numbers from the player on one line for easy comparison, Unless there is a set of batteries somewhere that I don't know about I think you have to rely on reading the line as a string and then splitting it. line = raw_input('Type 4 numbers separated by spaces: ') numbers = [int(n) for n in line.split(' ')] Or if you want to assign these 4 numbers to separate variables, you can use tuple unpacking: a,b,c,d = map(int, raw_input('Type 4 numbers separated ' 'by spaces:').split()) If you want to do error handling later, you may need to split this line into two steps so that you can distinguish between invalid values and wrong count of values (less or more than 4). George -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Checkbutton initialization problem
Paul Rubin wrote: Python 2.4, Windows XP. If I say: f = Frame() f.grid() v = IntVar() v.set(1) # Might help. v.get() at this point returned 0 for me. c = Checkbutton(f, text='hi there', variable=v) c.grid() f.mainloop() -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
Well, thank you for your advice. So I have a couple of solutions, but it can't become a server at its own so this means I will deal with files. Thank you for your advice, I'll first make it work... than the server. Noud Aldenhoven -- http://mail.python.org/mailman/listinfo/python-list
How do you program in Python?
My question isn't as all-encompassing as the subject would suggest... I am almost a Python newbie, but I have discovered that I don't get along with IDLE, as i can't work out how to run and rerun a routine without undue messing about. What I would really like is something like an old-style BASIC interpreter, in which I could list, modify and test-run sections of code, to see the effects of tweaks, without having to save it each time, or re-typing it over and over (I haven't even worked out how to cut and paste effectively in the IDLE environment). I see lots of alternate IDEs etc, but which would allow me the simple interface that I have described? - I really don't know about IDEs in general, and I suspect I would be out of my depth with one of those. Thanks, and feel free to mock ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: website catcher
maybe look at Harvestman http://cheeseshop.python.org/HarvestMan/1.4%20final -- http://mail.python.org/mailman/listinfo/python-list
Re: Assigning to None
François Pinard wrote: [Rocco Moretti] foo, bar, _ = gen_tuple(stuff) as '_' is already special cased (last result in interactive mode), and is already used for don't care sematics in Prolog. `_' is also the `gettext' function in internationalised programs. It so seems that `_' is in great demand! :-) Hm, then assigning to '_' might not be the best idea in internationalized programs, then. Well, you still have '_'*2, '_'*3, '_'*4, etc. -- http://mail.python.org/mailman/listinfo/python-list
A Policy for Inclusion in the Standard Library: was Modules for inclusion in standard library?
Terry Reedy wrote: Colin J. Williams [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Isn't this where the discussion should start? There should be some general policy guiding the types of modules which should be in the standard library. A couple of times, Guido has given his general policy as generally useful; best-of-breed, tested and accepted by the community; and backed by a developer who will adapt it and its doc up to stdlib standards (if necessary) and commit to maintainence for a few years. Terry J. Reedy This is a good base. Presumably accepted by the community means with some minimum number of ongoing users. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you program in Python?
anthonyberet wrote: My question isn't as all-encompassing as the subject would suggest... I am almost a Python newbie, but I have discovered that I don't get along with IDLE, as i can't work out how to run and rerun a routine without undue messing about. What I would really like is something like an old-style BASIC interpreter, in which I could list, modify and test-run sections of code, to see the effects of tweaks, without having to save it each time, or re-typing it over and over (I haven't even worked out how to cut and paste effectively in the IDLE environment). I see lots of alternate IDEs etc, but which would allow me the simple interface that I have described? - I really don't know about IDEs in general, and I suspect I would be out of my depth with one of those. The property of basic to have explicit linenumbering is the reason you've been able to work in that style of programming, as you could simply overwrite parts of the program. But that's close to undoable in all other languages. Python has the interactive REPL that you can use to toy around interactively and is very helpful to me - especially when enriched with rlcompleter2. - You can even replace functions or classes while working and toying around. But the amount of reasonable editing work that can be done in the interpreter is pretty limited. You _need_ a decent editor for that. So what I usually do is to create a test.py that contains the code I want to tinker with, and simply run that in a shell - cygwin on windows, but usually I work in *NIX-style environments, so it's even easier. As there is no compilation or whatsoever required, that works pretty well for me. Diez -- http://mail.python.org/mailman/listinfo/python-list
How execute a .py in this way?
If it's a executable file, a .exe file, you can launch it in this way, xxx.exe input.txt. The text file input.txt will be considered as the standard input. But when I use this trick on python, it doesn't work. The only way to do so is like this python xxx.py input.txt. But this method has a problem, that you have to include the full path of xxx.py unless it's in your current folder even if xxx.py is in a folder which has been include in the eviorment variable path on windows. Thus, you can execute you py program anywhere by using the command xxx.py, but when you want to use an exsiting file as it's input, you have to use something like pythong xxx.py input.txt. It's very inconvenient as I tried to make my python programs cowork with vim. Sorry for my poor english! delete -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
[Fredrik Johansson] I'd rather like to see a well implemented math.nthroot. 64**(1/3.0) gives 3.9996, and this error could be avoided. [Steven D'Aprano] math.exp(math.log(64)/3.0) 4.0 Success!!! [Tom Anderson] Eeenteresting. I have no idea why this works. Given that math.log is always going to be approximate for numbers which aren't rational powers of e (which, since e is transcendental, is all rational numbers, and therefore all python floats, isn't it?), i'd expect to get the same roundoff errors here as with exponentiation. Is it just that the errors are sufficiently smaller that it looks exact? Writing exp(log(x)*y) rather than x**y is in _general_ a terrible idea, but in the example it happens to avoid the most important rounding error entirely: 1./3. is less than one-third, so 64**(1./3.) is less than 64 to the one-third. Dividing by 3 instead of multiplying by 1./3. is where the advantage comes from here: 1./3. # less than a third 0.1 64**(1./3.) # also too small 3.9996 exp(log(64)/3) # happens to be on the nose 4.0 If we feed the same roundoff error into the exp+log method in computing 1./3., we get a worse result than pow got: exp(log(64) * (1./3.)) # worse than pow's 3.9991 None of this generalizes usefully -- these are example-driven curiousities. For example, let's try 2000 exact cubes, and count how often the right answer is delivered: c1 = c2 = 0 for i in range(1, 2001): p = i**3 r1 = p ** (1./3.) r2 = exp(log(p)/3) c1 += r1 == i c2 += r2 == i print c1, c2 On my box that prints 3 284 so a wrong answer is overwhelmingly more common either way. Fredrik is right that if you want a library routine that can guarantee to compute exact n'th roots whenever possible, it needs to be written for that purpose. ... YES! This is something that winds me up no end; as far as i can tell, there is no clean programmatic way to make an inf or a NaN; All Python behavior in the presence of infinities, NaNs, and signed zeroes is a platform-dependent accident, mostly inherited from that all C89 behavior in the presence of infinities, NaNs, and signed zeroes is a platform-dependent crapshoot. in code i write which cares about such things, i have to start: inf = 1e300 ** 1e300 nan = inf - inf That would be much more portable (== would do what you intended by accident on many more platforms) if you used multiplication instead of exponentiation in the first line. ... And then god forbid i should actually want to test if a number is NaN, since, bizarrely, (x == nan) is true for every x; instead, i have to write: def isnan(x): return (x == 0.0) and (x == 1.0) The result of that is a platform-dependent accident too. Python 2.4 (but not eariler than that) works hard to deliver _exactly_ the same accident as the platform C compiler delivers, and at least NaN comparisons work as intended (by IEEE 754) in 2.4 under gcc and MSVC 7.1 (because those C implementations treat NaN comparisons as intended by IEEE 754; note that MSVC 6.0 did not): inf = 1e300 * 1e300 nan == nan nan = inf - inf nan == 1.0 False nan 1.0 False nan 1.0 False nan == nan False nan nan False nan nan False nan != nan True So at the Python level you can do x != x to see whether x is a NaN in 2.4+(assuming that works in the C with which Python was compiled; it does under gcc and MSVC 7.1). The IEEE spec actually says that (x == nan) should be *false* for every x, including nan. I'm not sure if this is more or less stupid than what python does! Python did nothing on purpose here before Python 2.4. And while i'm ranting, how come these expressions aren't the same: 1e300 * 1e300 1e300 ** 2 Because all Python behavior in the presence of infinities, NaNs and signed zeroes is a platform-dependent accident. And finally, does Guido know something about arithmetic that i don't, Probably yes, but that's not really what you meant to ask wink. or is this expression: -1.0 ** 0.5 Evaluated wrongly? Read the manual for the precedence rules. -x**y groups as -(x**y). -1.0 is the correct answer. If you intended (-x)**y, then you need to insert parentheses to force that order. -- http://mail.python.org/mailman/listinfo/python-list
Re: debugger?
Qiangning Hong ha scritto: Eric3 need pyqt so it is not free under windows platform. Eric3 has had a free version for months now on windows, since the kde on win32 project recompiled the free versions on windows. And qt4 now has a GPL version free on windows too. -- Renato Usi Fedora? Fai un salto da noi: http://www.fedoraitalia.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter Checkbutton initialization problem
Scott David Daniels [EMAIL PROTECTED] writes: Paul Rubin wrote: Python 2.4, Windows XP. If I say: f = Frame() f.grid() v = IntVar() v.set(1) # Might help. v.get() at this point returned 0 for me. Yeah, I tried that too. Further reorganization of the code in some other way suddenly made it start working. I'll have to examine it to see what I did since I wasn't paying attention to that particular problem at the time. I had checked sf.net for a bug report on this and didn't see one, but maybe didn't check carefully enough. I'll look a little more and then file one, I guess. -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Sun, 03 Jul 2005 15:46:35 +0100, Tom Anderson wrote: I think there would be a lot less confusion over the alleged inaccuracy of floating point if everyone wrote in hex - indeed, i believe that C99 has hex floating-point literals. C has always been such a forward-thinking language! No, all that would do is shift the complaint from Python has a bug when you divide 10 into 1.0 to Python has a bug when you convert 0.1 into hex. [snip] But this works: py inf = float(inf) py inf inf True. Still, i'd rather not have to rely on string parsing to generate a fairly fundamental arithmetic quantity. What happens when your Python script is running on a platform that can deal with 1e300*1e300 giving 1e600 without overflow? Okay, maybe no such platform exists today (or does it?), but it could exist, and your code will fail on those systems. I believe that the IEEE standard specifies that float(inf) should give an infinity, just as float(0.0) should give a zero. For production code, I'd wrap float(inf) in a try...except and only fall back on your method if it raised an exception, and then I'd actually test that your result was a real inf (eg by testing that inf+inf=inf). [snip] The IEEE spec actually says that (x == nan) should be *false* for every x, including nan. I'm not sure if this is more or less stupid than what python does! Well, no, the IEEE standard is correct. NaNs aren't equal to anything, including themselves, since they aren't numbers. I don't buy that. Just because something isn't a number doesn't mean it can't be equal to something else, does it? I mean, we even say x == None if x is indeed None. Yes, but None does equal None, since there is only one None, and by definition, a thing is equal to itself. But NaNs are _not_ things. That is the whole point! Yes, we _represent_ INF-INF as a particular bit-pattern and call it NaN, but mathematically subtracting infinity from infinity is not defined. There is no answer to the question what is infinity subtracted from infinity?. We pretend that the answer is NaN, but that isn't right. The NaN is just there as a placeholder for there is no answer, so that we don't have to sprinkle our code with a thousand and one tests. Since INF-INF doesn't have an answer, we can't do this: x = inf - inf y = inf - inf and expect that x == y. Moreover, this freaky rule about NaNs means that this is an exception to the otherwise absolutely inviolate law that x == x. Yes. So what? Remove the NaN shorthand: The non-existent answer to this question is the same non-existent answer to this other question. It doesn't make sense to say that a non-thing is equal to anything -- even to itself, since itself doesn't exist. (Remember, a NaN is just an illusionary placeholder, not a number.) I'd rather have that simple, fundamental logical consistency than some IEEE rocket scientist's practical-value-free idea of mathematical consistency. Ah, from a _programmer's_ perspective, there is an argument that the simplicity of just testing NaNs with equality outweighs the logical silliness of doing such a thing. But, apart from testing whether a float is a NaN, why would you ever want to do an equality test? The only usage case I can think of is would be something like this: def isNaN(x): return x == SOME_KNOWN_NAN But that won't work, because there are lots of different NaNs. 254 of them, or twice that if you include signed NaNs (which you shouldn't, but you do have to allow for them in equality testing). Any good IEEE compliant system should already have a built-in function that tests for NaNs. [snip] And while i'm ranting, how come these expressions aren't the same: 1e300 * 1e300 1e300 ** 2 Because this is floating point, not real maths :-) I get inf and Overflow respectively. What do you get? The same. They really ought to give the same answer. In real numbers, yes they should. In floating point, that is too much to expect. In mathematics, the order you do your calculation shouldn't matter. But in floating point, where there is rounding errors and finite precision issues, it does. The aim of the High Level Language designer is to insulate the programmer from the ickiness of actual hardware implementation. Unfortunately, in the case of floating point, you can't get away from the hardware limitations. And finally, does Guido know something about arithmetic that i don't, or is this expression: -1.0 ** 0.5 Evaluated wrongly? No, it is evaluated according to the rules of precedence. It is equivalent to -(1.0**0.5). You are confusing it with (-1.0)**0.5 which fails as expected. Ah. My mistake. I submit that this is also a bug in python's grammar. There's probably some terribly good reason for it, though. Yes. You generally want exponentiation to have the highest precedence. 2*3**4 should give 162, not 1296. Think about how you would write that mathematically, with pencil and paper: the 4 is written
Re: Favorite non-python language trick?
Steven D'Aprano wrote: On Sun, 03 Jul 2005 00:39:19 -0400, Christopher Subich wrote: Personally, I think demanding that it be writable as a sum (or product, or any, or all) is a false standard -- nobody's claimed that these would replace all cases of reduce, just the most common ones. Er, excuse me, but that is EXACTLY what Devan claimed. Quote: With the exception of reduce(lambda x,y:x*y, sequence), reduce can be replaced with sum, and Guido wants to add a product function. Okay, then... not many people have claimed that sum is a universal replacement for reduce, only the most common cases. It's further argued that the uncommon cases are more flexible and (again, mostly) anywhere from only slightly less readable to significantly more readable in for-loop form. The only corner case that isn't, so far as I know, is when the reduce() has no default initial value and the sequence/generator might possibly have 0 elements. But that's a TypeError anyway. -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
[Steven D'Aprano] ... But this works: py inf = float(inf) py inf inf Another platform-dependent accident. That does not work, for example, on Windows. In fact, the Microsoft C float-string routines don't support any way to spell infinity that works in the string-float direction. -- http://mail.python.org/mailman/listinfo/python-list
Re: how to retrive highlighted text in a browser?
wcc wrote: Hello group, When browsing websites, quite often I have to look up words in dictionary. I'm hoping that I can come up with a python program that does the following: When I highlight some text in browser and right-click, besides the default options such as COPY, PASTE, etc, I want an option that says Send to file, something like that. The file is a text file, with fixed path. When I select this option, the highlighted text will be appended to the text file. This way, I can collect those words phrases that I don't know. Is this going to be a difficult task? I'm a newbie in python. TIA for your help. - wcc Firefox doesn't provide the file capture function you seek but, using a readily available extension, does permit dictionary lookup using the American Heritage Dictionary - the response comes with copious advertising which is not overly intrusive. Colin W. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you program in Python?
anthonyberet wrote: What I would really like is something like an old-style BASIC interpreter, in which I could list, modify and test-run sections of code, to see the effects of tweaks, without having to save it each time, or re-typing it over and over (I haven't even worked out how to cut and paste effectively in the IDLE environment). I do all my work using Scite (a nice free editor that was built to demonstrate the Scintilla plugin that can also be used in Python programs through things like the StructuredTextControl in wxPython), with the auto-save-on-loss-of-focus feature enabled, and a command prompt open in another window. I edit in the Scite window, hit Alt-Tab (under Windows XP) to change focus to the cmd console (and instantly all my modified files are saved), press the Cursor Up key to retrieve the previous command (which is generally the name of my script, or a command like python myscript.py), and hit Enter to execute it. So, any time I need to test the changes, I hit four keys (which at this point is understandably more like a chord that I hit without direct awareness of it) and I'm done. Sounds pretty close to old-style BASIC and since I've come that route too (in the distant past), this may not be a coincidence. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: How execute a .py in this way?
Peter Cai wrote: Thus, you can execute you py program anywhere by using the command xxx.py, but when you want to use an exsiting file as it's input, you have to use something like pythong xxx.py input.txt. This is apparently a bug or limitation of Windows command prompts and may not be fixed any time soon. Past threads have discussed it and a recent one even gave pointers to some web pages that explain it further. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
On Sun, 03 Jul 2005 08:14:28 -0700, Scott David Daniels wrote: egbert wrote: On Sat, Jul 02, 2005 at 08:26:31PM -0700, Devan L wrote: Also, map is easily replaced. map(f1, sequence) == [f1(element) for element in sequence] How do you replace map(f1,sequence1, sequence2) especially if the sequences are of unequal length ? I didn't see it mentioned yet as a candidate for limbo, but the same question goes for: zip(sequence1,sequence2) OK, you guys are picking on what reduce cannot do. The first is [f1(*args) for args in itertools.izip(iter1, iter2)] And now we get messier and messier... Compare these two idioms: Map function f1 to each pair of items from seq1 and seq2. Build a list comprehension by calling function f1 with the unpacked list that you get from a list built by zipping seq1 and seq2 together in pairs. Good thing that removing reduce is supposed to make code easier to understand, right? How to _you_ use map to avoid making all the intermediate structures? I don't understand the question. Presumably the sequences already exist. That's not the point. I never saw anything about making zip go away. It is easy to explain. I don't find map any less clear than zip. Except for the arbitrary choice that zip truncates unequal sequences while map doesn't, zip is completely redundant: def my_zip(*seqs): return map(lambda *t: t, *seqs) Zip is just a special case of map. I find it disturbing that Guido is happy to fill Python with special case built-ins like sum, zip and (proposed) product while wanting to cut out more general purpose solutions. [snip] If you want functional programming in python, you have at least three big problems: 1) Python has side effect like mad, so order of evaluation matters. Not if you *just* use functional operations. Not that I would ever do that. The point isn't to turn Python into a purely functional language, but to give Python developers access to functional tools for when it is appropriate to use them. 2) Python's essential function call is not a single-argument function which might be a tuple, it is a multi-argument function which is not evaluated in the same way. And I'm sure that makes a difference to the functional programming purists. But not to me. 3) Python doesn't have a full set of functional primitives. Fold-right is one example, K-combinator is another, Why pick on reduce as-is to keep? There is another slippery slope argument going up the slope adding functional primitives. My car isn't amphibious, so I can't go everywhere with it. Should I throw it away just because I can't drive under water? No, of course not. Just because Python isn't a purely functional language doesn't mean that we should reject what functional idioms (like list comps, and zip, and reduce) it does have. Personally, I'd like to learn more about about fold-right and K-combinator, rather than dump reduce and map. Frankly, I find this entire discussion very surreal. Reduce etc *work*, right now. They have worked for years. If people don't like them, nobody is forcing them to use them. Python is being pushed into directions which are *far* harder to understand than map and reduce (currying, decorators, etc) and people don't complain about those. And yet something as simple and basic as map is supposed to give them trouble? These are the same people who clamoured for zip, which is just a special case of map? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Using regular expressions in internet searches
What is the best way to use regular expressions to extract information from the internet if one wants to search multiple pages? Let's say I want to search all of www.cnn.com and get a list of all the words that follow Michael. (1) Is Python the best language for this? (Plus is it time-efficient?) Is there already a search engine that can do this? (2) How can I search multiple web pages within a single location or path? TIA, Mike -- http://mail.python.org/mailman/listinfo/python-list
C parser with spark
Hi, Has anybody already implemented a full ANSI C parser with John Aycock's spark module ? (spark : http://pages.cpsc.ucalgary.ca/~aycock/spark/) Cheers, SB -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
Carl Banks wrote: Listcomps et al. cannot do everything map, lambda, filter, and reduce did. Listcomps are inferior for functional programming. But, you see, functional is not the point. Streamlining procedural programs is the point, and I'd say listcomps do that far better, and without all the baroque syntax (from the procedural point of view). I've heard this said a couple times now -- how can listcomps not completely replace map and filter? I'd think that: mapped = [f(i) for i in seq] filtered = [i for i in seq if f(i)] The only map case that doesn't cleanly reduce is for multiple sequences of different length -- map will extend to the longest one (padding the others with None), while zip (izip) truncates sequences at the shortest. This suggests an extension to (i)zip, possibly (i)lzip ['longest zip'] that does None padding in the same way that map does. Reduce can be rewritten easily (if an initial value is supplied) as a for loop: _accum = initial for j in seq: _accum=f(_accum,j) result = _accum (two lines if the result variable can also be used as the accumulator -- this would be undesirable of assigning to that can trigger, say, a property function call) Lambdas, I agree, can't be replaced easily, and they're the feature I'd probably be least happy to see go, even though I haven't used them very much. -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
Scott David Daniels wrote: egbert wrote: How do you replace map(f1,sequence1, sequence2) especially if the sequences are of unequal length ? I didn't see it mentioned yet as a candidate for limbo, but the same question goes for: zip(sequence1,sequence2) OK, you guys are picking on what reduce cannot do. The first is [f1(*args) for args in itertools.izip(iter1, iter2)] How to _you_ use map to avoid making all the intermediate structures? Not quite -- zip an izip terminate at the shortest sequence, map extends the shortest with Nones. This is resolvable by addition of an lzip (and ilzip) function in Python 2.5 or something. And egbert's Chicken Littling with the suggestion that 'zip' will be removed. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using regular expressions in internet searches
[EMAIL PROTECTED] wrote: What is the best way to use regular expressions to extract information from the internet if one wants to search multiple pages? Let's say I want to search all of www.cnn.com and get a list of all the words that follow Michael. (1) Is Python the best language for this? (Plus is it time-efficient?) Is there already a search engine that can do this? (2) How can I search multiple web pages within a single location or path? You'd probably better off using htdig. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
Steven D'Aprano wrote: Frankly, I find this entire discussion very surreal. Reduce etc *work*, right now. They have worked for years. If people don't like them, nobody is forcing them to use them. Python is being pushed into directions which are *far* harder to understand than map and reduce (currying, decorators, etc) and people don't complain about those. I find it surreal too, for a different reason. Python *works*, right now. It has worked for years. If people don't like the direction it's going, nobody is forcing them to upgrade to the new version (which is not imminent anyway). In the unlikely event that the latest and greatest Python in, what, five years or more?, is so alien that one can't handle it, one has the right to fork Python and maintain a tried-and-true-and-still-including-reduce- -filter-and-map version of it, or even just to stick with the most recent version which still has those features. And that's assuming it's not acceptable (for whatever bizarre reason I can't imagine) to use the inevitable third-party extension that will provide them anyway. I wonder if some of those who seem most concerned are actually more worried about losing the free support of a team of expert developers as those developers evolve their vision of the language, than about losing access to something as minor as reduce(). -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Inheriting from object
On Sat, 02 Jul 2005 12:26:49 -0700, Scott David Daniels [EMAIL PROTECTED] wrote: Bengt Richter wrote: On Thu, 30 Jun 2005 08:54:31 -0700, Scott David Daniels [EMAIL PROTECTED] wrote: Or, perhaps: class foo(object): def __init__(self, *args, **kwargs): super(foo, self).__init__(self, *args, **kwargs) ... Doesn't super(foo, self).__init__ return a bound method, so you don't need to pass self again? I.e., super(foo, self).__init__(*args, **kwargs) Yes, of course (a silly cut-o / paste-o). BTW, there's something about referring to type(self) by its not always dependably bound (though usually global) name that bothers me. I wonder if the above common use of super could be implemented as a property of object, so you'd normally inherit it and be able to write self.super.__init__(*args, **kwargs) # (maybe spell it self.__super__.__init__(...) I suppose) I.e., self.__super__ would effectively return the equivalent of super(type(self), self) The problem with this is: class A(object): def __init__(self, *args, **kwargs): print 'Set A(*%r, **%r)' % (args, kwargs) class B(A): def __init__(self, *args, **kwargs): print 'Set B(*%r, **%r)' % (args, kwargs) super(B, self).__init__(*args, **kwargs) class C(B): def __init__(self, *args, **kwargs): print 'Set C(*%r, **%r)' % (args, kwargs) super(C, self).__init__(*args, **kwargs) class D(A): def __init__(self, *args, **kwargs): print 'Set D(*%r, **%r)' % (args, kwargs) super(type(self), self).__init__(*args, **kwargs) class E(D): def __init__(self, *args, **kwargs): print 'Set E(*%r, **%r)' % (args, kwargs) super(type(self), self).__init__(*args, **kwargs) You'll see the problem when you attempt to create an instance of E. All of the others work just fine. Ok, I had a brain-o ;-) If we had class decorators analogous to function decorators, we could write @deco(args) class X: ... instead of class X: ... X = deco(args)(X) below, but anyway (untested beond what you see), using your example, have a look: super_cls_deco.py --- # super_cls_deco.py -- bokr 2005-07-03 from ut.presets import presets # function local presets decorator def preset_super_ubm(target_method_name, super_method_name, alias=None): class decorator to preset an unbound super-method as a local alias name in a target method of the decorated class. if alias is None: alias = 'SUPER'+super_method_name # for local name in target method def super_deco(cls): if not getattr(cls, target_method_name): raise ValueError, 'class %s does not have a %s method' %( cls.__name__, target_method_name) for base in cls.mro()[1:]: if hasattr(base, super_method_name): ubm = getattr(base, super_method_name) setattr(cls, target_method_name, presets(**{alias:ubm})( cls.__dict__[target_method_name])) return cls raise ValueError, '%s not found as super-method' % super_method_name return super_deco def test(): class A(object): def __init__(self, *args, **kwargs): print 'Set A(*%r, **%r)' % (args, kwargs) SUPER__init__(self, *(('from A:',)+args), **kwargs) A = preset_super_ubm('__init__', '__init__')(A) class B(A): def __init__(self, *args, **kwargs): print 'Set B(*%r, **%r)' % (args, kwargs) SUPER__init__(self, *(('from B:',)+args), **kwargs) #super(B, self).__init__(*args, **kwargs) B = preset_super_ubm('__init__', '__init__')(B) class C(B): def __init__(self, *args, **kwargs): print 'Set C(*%r, **%r)' % (args, kwargs) SUPER__init__(self, *(('from C:',)+args), **kwargs) #super(C, self).__init__(*args, **kwargs) C = preset_super_ubm('__init__', '__init__')(C) class D(A): def __init__(self, *args, **kwargs): print 'Set D(*%r, **%r)' % (args, kwargs) SUPER__init__(self, *(('from D:',)+args), **kwargs) #super(type(self), self).__init__(*args, **kwargs) D = preset_super_ubm('__init__', '__init__')(D) class E(D): def __init__(self, *args, **kwargs): print 'Set E(*%r, **%r)' % (args, kwargs) SUPER__init__(self, *(('from E:',)+args), **kwargs) #super(type(self), self).__init__(*args, **kwargs) E = preset_super_ubm('__init__', '__init__')(E) print '... from creating instance %s\n' % A('some', 'args', a='keyword') print '... from creating instance %s\n' % B('some', 'args', a='keyword') print '... from creating instance %s\n' % C('some', 'args', a='keyword') print '... from
Re: map/filter/reduce/lambda opinions and background unscientificmini-survey
On Sun, 03 Jul 2005 14:43:14 -0400, Peter Hansen [EMAIL PROTECTED] wrote: Steven D'Aprano wrote: Frankly, I find this entire discussion very surreal. Reduce etc *work*, right now. They have worked for years. If people don't like them, nobody is forcing them to use them. Python is being pushed into directions which are *far* harder to understand than map and reduce (currying, decorators, etc) and people don't complain about those. I find it surreal too, for a different reason. Python *works*, right now. It has worked for years. If people don't like the direction it's going, nobody is forcing them to upgrade to the new version (which is not imminent anyway). In the unlikely event that the latest and greatest Python in, what, five years or more?, is so alien that one can't handle it, one has the right to fork Python and maintain a tried-and-true-and-still-including-reduce- -filter-and-map version of it, or even just to stick with the most recent version which still has those features. And that's assuming it's not acceptable (for whatever bizarre reason I can't imagine) to use the inevitable third-party extension that will provide them anyway. I wonder if some of those who seem most concerned are actually more worried about losing the free support of a team of expert developers as those developers evolve their vision of the language, than about losing access to something as minor as reduce(). This is a specious line of reasoning. Here's why: Lots of people use Python, like Python, want to keep using Python. Moreover, they want Python to improve, rather than the reverse. Different people have different ideas about what improve means. Guido has his ideas, and since he's the BDFL, those are the ideas most likely to influence the direction of Python's development. However, Guido isn't the only person with ideas, nor are his ideas the only ones that should be allowed to influence the direction of Python's development. Guido himself wouldn't even be silly enough to take this position. He knows he is not the ultimate source of wisdom in the world on all matters programming related. So when people disagree with him, suggesting that they should leave the Python community is ridiculous. Just like Guido (and the overwhelming majority of the Python community - heck, maybe even all of it), these people are trying to improve the language. Leaving the community isn't going to improve the language. Continuing to operate actively within it just might. For my part, I lack the time and energy to participate in many of these discussions, but anyone who knows me knows I'm not silent because I see eye to eye with Guido on every issue :) I'm extremely greatful to the people who do give so much of their own time to try to further the Python language. Suggesting people can like it or lump it is a disservice to everyone. (Sorry to single you out Peter, I know you frequently contribute great content to these discussions too, and that there are plenty of other people who respond in the way you have in this message, but I had to pick /some/ post to reply to) Jp -- http://mail.python.org/mailman/listinfo/python-list
Re: Using regular expressions in internet searches
Python would be good for this, but if you just want a chuck an rumble solution might be. bash $wget -r --ignore-robots -l 0 -c -t 3 http://www.cnn.com/ bash $ grep -r Micheal.* ./www.cnn.com/* Or you could do a wget/python mix like import sys import re sys.os.command(wget -r --ignore-robots -l 0 -c -t 3 http://ww.cnn.com/;) re_iraq=re.compile(iraq .+?,re.IGNORECASE) while file in dirs under ./www.cnn.com/ iraqs = re_iraq.findall(file.read()) print iraqs -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you program in Python?
anthonyberet wrote: My question isn't as all-encompassing as the subject would suggest... I am almost a Python newbie, but I have discovered that I don't get along with IDLE, as i can't work out how to run and rerun a routine without undue messing about. What I would really like is something like an old-style BASIC interpreter, in which I could list, modify and test-run sections of code, to see the effects of tweaks, without having to save it each time, or re-typing it over and over (I haven't even worked out how to cut and paste effectively in the IDLE environment). I think you're missing something about IDLE if you are re-typing. For example: IDLE 1.1a3 for i in range(25): print i, When you type the above, you get 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Now let's say you want to re-run that with 10 instead of 25. You don't have to re-type it. Click to place your cursor anywhere in the original block of code and hit return. Idle will re-type the entire block for you: for i in range(25): print i, The cursor will be at the very end of the block so you can re-run it by hitting enter twice. But you'll get the same output. Instead of hitting enter twice, use your cursor keys (or mouse) to move to the 25 in the range function and edit it to 10. Once edited, move the cursor back to end of the block and hit enter twice to execute for i in range(10): print i, 0 1 2 3 4 5 6 7 8 9 It sounds worse than it is, just takes a little getting used to. Once you're happy with that code fragment, edit it again and add a definition at the start. [1] click in the block and hit enter, Idle re-types the block for i in range(10): print i, [2] place cursor in front of the 'for' and add a function name and change the 'for' to use the parameter instead of a constant def t(n): for i in range(n): print i, [3] hit enter (here we do want to insert a line) and IDLE will show you this (indents adjust automatically) def t(n): for i in range(n): print i, [4] move cursor to the end of the block (after the comma) and hit enter twice Nothing happens. You have defined a function, but did not execute it. To execute it, type its name with some value of n. t(8) 0 1 2 3 4 5 6 7 Now you can try it out with different values of n without having to edit the whole block. Now if you want to change the function definition, say we want each number output on a seperate line, do the same thing we did before. Click anywhere in the block and hit enter. The entire block is re-typed for you. Make your change (remove the comma) and hit enter twice. def t(n): for i in range(n): print i Again, the function is not executed. And you can always simply click on the previously typed line t(8) and hit enter twice t(8) 0 1 2 3 4 5 6 7 I see lots of alternate IDEs etc, but which would allow me the simple interface that I have described? - I really don't know about IDEs in general, and I suspect I would be out of my depth with one of those. Thanks, and feel free to mock ;) -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Sun, 3 Jul 2005, George Sakkis wrote: Tom Anderson [EMAIL PROTECTED] wrote: And finally, does Guido know something about arithmetic that i don't, or is this expression: -1.0 ** 0.5 Evaluated wrongly? No, it is evaluated according to the rules of precedence. It is equivalent to -(1.0**0.5). You are confusing it with (-1.0)**0.5 which fails as expected. Ah. My mistake. I submit that this is also a bug in python's grammar. There's probably some terribly good reason for it, though. How about 'conformance with standard mathematic notation', does this count for a terribly good reason? Yes. However, it's an excellent reason why python's precedence rules are wrong - in conventional mathematical notation, the unary minus, used to denote the sign of a literal number, does indeed have higher precedence than exponentiation: -1^2 evaluates to 1, not -1. What would one expect to be the result of 5^2 - 2^2, 29 or 21? 21. Would you expect 5^2 + - 2^2 to be different, even if you write it as 5^2 + -2 ^ 2 ? Yes: 5^2 + -2^2 is 29, however you write it. White space is not significant in math AFAIK ;-) No, but there's a very big difference between unary and binary minus. tom -- When you mentioned INSERT-MIND-INPUT ... did they look at you like this? -- http://mail.python.org/mailman/listinfo/python-list
Re: Using regular expressions in internet searches
On 3 Jul 2005 10:49:03 -0700, [EMAIL PROTECTED] wrote: What is the best way to use regular expressions to extract information from the internet if one wants to search multiple pages? Let's say I want to search all of www.cnn.com and get a list of all the words that follow Michael. (1) Is Python the best language for this? (Plus is it time-efficient?) Is there already a search engine that can do this? (2) How can I search multiple web pages within a single location or path? TIA, Mike Is a google search for site:cnn.com Michael not up to the task? Jp -- http://mail.python.org/mailman/listinfo/python-list
need to get an index for an item in a list
hey there, i need to be able to get the index for an item in a list. the list is a list of lines read from a text file. like this: file = open(/home/somefile.text, r) lines = file.readlines() file.close() now, i want to see if a certain string is == to one of the lines and if so, i need to know the index of that line. any ideas? thanks -- http://mail.python.org/mailman/listinfo/python-list
Re: Assigning to None (was Re: Question about Python)
On Sun, 03 Jul 2005 11:47:07 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote: On Fri, 01 Jul 2005 12:59:20 -0400, François Pinard wrote: [Peter Hansen] Mike Meyer wrote: Yes. I once grabbed an old program that did assignments to None. But that's always been a bad idea. What was the use case!? People used to assign None to itself as a keyword argument in function headers. The goal was to make a local copy of the reference, which was then accessed faster than the global thing. Can you say premature optimization is the root of all evil? I'd like to see the profiling that demonstrated that this made a significant -- or even measurable -- speed-up in anything but the most unusual cases. The difference between local and global access is definitely measurable, though there's no reason to use None as the local name if you want to do that kind of optimization (not possible in 2.4+) from time import clock def test(): ... none = None # local ... t0 = clock() ... for i in xrange(10**6): v = None ... t1 = clock() ... for i in xrange(10**6): v = none ... t2 = clock() ... print 't1-t0 = %f, t2=t1 = %f, ratio = %f' %(t1-t0, t2-t1, (t1-t0)/(t2-t1)) ... test() t1-t0 = 0.971914, t2=t1 = 0.766901, ratio = 1.267327 about 25% longer to get a global (AND bind it locally, which the two timings share) than to do the same for a local, it seems. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: Accepted Summer of Code proposals
On 7/2/05, Reinhold Birkenfeld [EMAIL PROTECTED] wrote: A.M. Kuchling wrote: For anyone who's interested: the Python wiki now contains a list of the PSF-mentored proposals that were accepted for Google's Summer of Code: http://wiki.python.org/moin/SummerOfCode Is it right that two Wax proposals were accepted? Or that Wax is being promoted over Dabo, which wraps wxPython just as elegantly in its UI tier, and which is further along (more controls supported) than Wax, is more powerful (data binding is built in), and is still being actively developed? I looked at Wax, but it seems to be at best a side project to Hans, with no goal in sight. Dabo blew me away with just how easy it is to create UI apps without all that C++ cruft that wxPython inherits from wxWidgets. # p.d. -- http://mail.python.org/mailman/listinfo/python-list
Re: PIL question: keeping metadata
Ilpo Nyyssönen napisał(a): Is there any way of keeping this info in PIL? I don't think so... when I investigated in the past, I think I discovered that the PIL can't write EXIF data (I might be wrong, though, or my information might be outdated). There is this: http://mail.python.org/pipermail/image-sig/2004-September/002931.html It would be nice to have general EXIF module, the one that is able to read and write image metadata. Consider such case: you want to rotate some image from digital camera, but don't want to remove completely the whole EXIF metadata -- modifying one field would be sufficient. -- Jarek Zgoda http://jpa.berlios.de/ -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Sun, 3 Jul 2005, Tim Peters wrote: [Fredrik Johansson] I'd rather like to see a well implemented math.nthroot. 64**(1/3.0) gives 3.9996, and this error could be avoided. [Steven D'Aprano] math.exp(math.log(64)/3.0) 4.0 Success!!! None of this generalizes usefully -- these are example-driven curiousities. I was afraid of that. Thanks for shedding some light on it, though. YES! This is something that winds me up no end; as far as i can tell, there is no clean programmatic way to make an inf or a NaN; All Python behavior in the presence of infinities, NaNs, and signed zeroes is a platform-dependent accident, mostly inherited from that all C89 behavior in the presence of infinities, NaNs, and signed zeroes is a platform-dependent crapshoot. Okay. That's a shame. in code i write which cares about such things, i have to start: inf = 1e300 ** 1e300 nan = inf - inf That would be much more portable (== would do what you intended by accident on many more platforms) if you used multiplication instead of exponentiation in the first line. Yes - that's what i meant to write, but i must have got carried away with the asterisks. Sorry about that. And then god forbid i should actually want to test if a number is NaN, since, bizarrely, (x == nan) is true for every x; instead, i have to write: def isnan(x): return (x == 0.0) and (x == 1.0) The result of that is a platform-dependent accident too. Python 2.4 (but not eariler than that) works hard to deliver _exactly_ the same accident as the platform C compiler delivers, and at least NaN comparisons work as intended (by IEEE 754) in 2.4 under gcc and MSVC 7.1 (because those C implementations treat NaN comparisons as intended by IEEE 754; note that MSVC 6.0 did not): So at the Python level you can do x != x to see whether x is a NaN in 2.4+(assuming that works in the C with which Python was compiled; it does under gcc and MSVC 7.1). I see. I have to confess that i'm using 2.3. So, is there a way of generating and testing for infinities and NaNs that's portable across platforms and versions of python? If not, could we perhaps have some constants in the math module for them? math.inf and math.nan should do nicely (although there is the question of just _which_ nan that should be ...). It wouldn't help with old versions of python, but it'd solve the problem for the future. or is this expression: -1.0 ** 0.5 Evaluated wrongly? Read the manual for the precedence rules. -x**y groups as -(x**y). -1.0 is the correct answer. If you intended (-x)**y, then you need to insert parentheses to force that order. So i see. Any idea why that precedence order was chosen? It goes against conventional mathematical notation, as well as established practice in other languages. Also, would it be a good idea for (-1.0) ** 0.5 to evaluate to 1.0j? It seems a shame to have complex numbers in the language and then miss this opportunity to use them! tom -- When you mentioned INSERT-MIND-INPUT ... did they look at you like this? -- http://mail.python.org/mailman/listinfo/python-list
Re: need to get an index for an item in a list
[EMAIL PROTECTED] wrote: i need to be able to get the index for an item in a list. any ideas? Fire up the interactive interpreter and learn to use it to help yourself. In this case, the most useful thing might be to know about the dir() builtin method, which you can use on a list like so: dir([]) Note in the output the presence of the index method... I'll leave it up to you to read the docs to learn more about how to use it, or you can just experiment at the prompt to see how it works. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: map/filter/reduce/lambda opinions and background unscientific mini-survey
Erik Max Francis wrote: Ron Adam wrote: I'm just estimating, but I think that is the gist of adding those two in exchange for reduce. Not that they will replace all of reduce use cases, but that sum and product cover most situations and can be implemented more efficiently than using reduce or a for loop to do the same thing. The other situations can easily be done using for loops, so it's really not much of a loss. I really don't understand this reasoning. You essentially grant the position that reduce has a purpose, but you still seem to approve removing it. Let's grant your whole point and say that 90% of the use cases for reduce are covered by sum and product, and the other 10% are used by eggheads and are of almost no interest to programmers. But it still serves a purpose, and a useful one. That it's not of immediate use to anyone is an argument for moving it into a functional module (something I would have no serious objection to, though I don't see its necessity), not for removing it altogether! Why would you remove the functionality that already exists _and is being used_ just because? What harm does it do, vs. the benefit of leaving it in? There are really two separate issues here. First on removing reduce: 1. There is no reason why reduce can't be put in a functional module or you can write the equivalent yourself. It's not that hard to do, so it isn't that big of a deal to not have it as a built in. 2. Reduce calls a function on every item in the list, so it's performance isn't much better than the equivalent code using a for-loop. *** (note, that list.sort() has the same problem. I would support replacing it with a sort that uses an optional 'order-list' as a sort key. I think it's performance could be increased a great deal by removing the function call reference. *** Second, the addition of sum product: 1. Sum, and less so Product, are fairly common operations so they have plenty of use case arguments for including them. 2. They don't need to call a pre-defined function between every item, so they can be completely handled internally by C code. They will be much much faster than equivalent code using reduce or a for-loop. This represents a speed increase for every program that totals or subtotals a list, or finds a product of a set. But removing reduce is just removing functionality for no other reason, it seems, than spite. No, not for spite. It's more a matter of increasing the over all performance and usefulness of Python without making it more complicated. In order to add new stuff that is better thought out, some things will need to be removed or else the language will continue to grow and be another visual basic. Having sum and product built in has a clear advantage in both performance and potential frequency of use, where as reduce doesn't have the same performance advantage and most poeple don't use it anyway, so why have it built in if sum and product are? Why not just code it as a function and put it in your own module? def reduce( f, seq): x = 0 for y in seq: x = f(x,y) return x But I suspect that most people would just do what I currently do and write the for-loop to do what they want directly instead of using lambda in reduce. x = 1 for y in seq: x = x**y If performance is needed while using reduce with very large lists or arrays, using the numeric module would be a much better solution. http://www-128.ibm.com/developerworks/linux/library/l-cpnum.html Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: need to get an index for an item in a list
In article [EMAIL PROTECTED], [EMAIL PROTECTED] wrote: hey there, i need to be able to get the index for an item in a list. the list is a list of lines read from a text file. like this: file = open(/home/somefile.text, r) lines = file.readlines() file.close() now, i want to see if a certain string is == to one of the lines and if so, i need to know the index of that line. Assuming you're already read the lines from the file with the above code, something along the lines of the following will work: for lineNumber, line in enumerate (lines): whatever But, starting from scratch, it'll be more efficient to do: for lineNumber, line in enumerate (file (filename)): whatever because it'll read lines one at a time as needed, instead of gulping them all in at once and buffering them in memory. For small files (say, less than a few hundred lines), it probably won't make any appreciable difference, but for big files, it can be substantial. BTW, enumerate() starts counting from 0; you might want to add 1 to what it returns to get a file line number. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accepted Summer of Code proposals
Peter Decker wrote: On 7/2/05, Reinhold Birkenfeld [EMAIL PROTECTED] wrote: Is it right that two Wax proposals were accepted? Or that Wax is being promoted over Dabo Promoted? Do you know if any Dabo proposals were even made? And how good the proposals were? The money goes to those who are actually willing to do some work, and to those projects for which willing mentors are available. Perhaps one of these things wasn't present in Dabo's case... -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: need to get an index for an item in a list
In article [EMAIL PROTECTED], Peter Hansen [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: i need to be able to get the index for an item in a list. any ideas? Fire up the interactive interpreter and learn to use it to help yourself. In this case, the most useful thing might be to know about the dir() builtin method, which you can use on a list like so: dir([]) Note in the output the presence of the index method... I'll leave it up to you to read the docs to learn more about how to use it, or you can just experiment at the prompt to see how it works. -Peter I certainly agree that dir() is a very handy tool to know about, and that poking around with it in the interactive interpreter is a great way to learn what's possible. That being said, index() isn't isn't going to work if there are duplicate lines in the file; it'll return the index of the first one. -- http://mail.python.org/mailman/listinfo/python-list
Re: Accepted Summer of Code proposals
Peter Decker wrote: On 7/2/05, Reinhold Birkenfeld [EMAIL PROTECTED] wrote: A.M. Kuchling wrote: For anyone who's interested: the Python wiki now contains a list of the PSF-mentored proposals that were accepted for Google's Summer of Code: http://wiki.python.org/moin/SummerOfCode Is it right that two Wax proposals were accepted? Or that Wax is being promoted over Dabo, which wraps wxPython just as elegantly in its UI tier, and which is further along (more controls supported) than Wax, is more powerful (data binding is built in), and is still being actively developed? I would suggest not speculating on biased or malicious intentions. It is possible that no one applied with a proposal to work on Dabo, or that such a proposal was poorly written, or that the author had too little experience, or any number of other things. (Disclosure: I am now a co-mentor on an unrelated SoC project, but I wasn't part of the group rating and selecting proposals.) -- Robert Kern [EMAIL PROTECTED] In the fields of hell where the grass grows high Are the graves of dreams allowed to die. -- Richard Harter -- http://mail.python.org/mailman/listinfo/python-list
Re: need to get an index for an item in a list
Roy Smith wrote: That being said, index() isn't isn't going to work if there are duplicate lines in the file; it'll return the index of the first one. It will still work, if you are willing to do a bit of work to help it: l = range(10) + [5] l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5] l.index(5) 5 l.index(5, 5+1) 10 As with str.index(), the one for list takes a second argument that specifies the index at which to start the search, allowing you to skip past items that have already been checked. That said, other approaches (such as Roy suggested in his other post) may well be more appropriate depending on the context. -Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Proposal: reducing self.x=x; self.y=y; self.z=z boilerplate code
On Sat, 02 Jul 2005 13:50:25 GMT, Andrew Koenig [EMAIL PROTECTED] wrote: Ralf W. Grosse-Kunstleve [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] class grouping: def __init__(self, .x, .y, .z): # real code right here Emulation using existing syntax:: def __init__(self, x, y, z): self.x = x del x self.y = y del y self.z = z del z I think this is a bad idea, for a subtle reason. In Python, unlike many other languages, the names of formal parameters are part of a function's interface. For example: def f(x, y): return x-y Now f(3, 4) is -1 and f(y=3,x=4) is 1. The names of instance variables are generally not part of a class' interface--they are part of its implementation. This proposed feature, whenever used, would tie a class' implementation to the interface of every method that uses the feature. As far as I can see, it is impossible to use the feature without constraining the implementation in this way. For this reason, I would much rather have the mapping between parameter names and instance variables be explicit. What if parameter name syntax were expanded to allow dotted names as binding targets in the local scope for the argument or default values? E.g., def foometh(self, self.x=0, self.y=0): pass would have the same effect as def foometh(self, self.y=0, self.x=0): pass and there would be a persistent effect in the attributes of self (whatever object that was), even with a body of pass. I'm not sure about foo(self, **{'self.x':0, 'self.y':0}), but if you didn't capture the dict with a **kw formal parameter, IWT you'd have to be consistent and effect the attribute bindings implied. (Just a non-thought-out bf here, not too serious ;-) Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: How do you program in Python?
Peter Hansen wrote: anthonyberet wrote: What I would really like is something like an old-style BASIC interpreter, in which I could list, modify and test-run sections of code, to see the effects of tweaks, without having to save it each time, or re-typing it over and over (I haven't even worked out how to cut and paste effectively in the IDLE environment). I do all my work using Scite (a nice free editor that was built to demonstrate the Scintilla plugin that can also be used in Python programs through things like the StructuredTextControl in wxPython), with the auto-save-on-loss-of-focus feature enabled, and a command prompt open in another window. I edit in the Scite window, hit Alt-Tab (under Windows XP) to change focus to the cmd console (and instantly all my modified files are saved), press the Cursor Up key to retrieve the previous command (which is generally the name of my script, or a command like python myscript.py), and hit Enter to execute it. So, any time I need to test the changes, I hit four keys (which at this point is understandably more like a chord that I hit without direct awareness of it) and I'm done. Sounds pretty close to old-style BASIC and since I've come that route too (in the distant past), this may not be a coincidence. Just curious. Why do you Alt-Tab to a console when you can just hit F5 in SciTE? That's just 1 key instead of 4. And yes, SciTE can autosave here too. -- http://mail.python.org/mailman/listinfo/python-list
Re: math.nroot [was Re: A brief question.]
On Mon, 4 Jul 2005, Steven D'Aprano wrote: On Sun, 03 Jul 2005 15:46:35 +0100, Tom Anderson wrote: I think there would be a lot less confusion over the alleged inaccuracy of floating point if everyone wrote in hex - indeed, i believe that C99 has hex floating-point literals. C has always been such a forward-thinking language! No, all that would do is shift the complaint from Python has a bug when you divide 10 into 1.0 to Python has a bug when you convert 0.1 into hex. Ah, but since the programmer would have to do that conversion themself, they wouldn't be able to blame python got it! But this works: py inf = float(inf) py inf inf True. Still, i'd rather not have to rely on string parsing to generate a fairly fundamental arithmetic quantity. What happens when your Python script is running on a platform that can deal with 1e300*1e300 giving 1e600 without overflow? Then i lose. Okay, maybe no such platform exists today (or does it?), but it could exist, and your code will fail on those systems. I believe that the IEEE standard specifies that float(inf) should give an infinity, just as float(0.0) should give a zero. I think it's been pointed out that this fails on (some versions of?) windows. For production code, I'd wrap float(inf) in a try...except and only fall back on your method if it raised an exception, and then I'd actually test that your result was a real inf (eg by testing that inf+inf=inf). Okay, let's try this ... def mkinf(): try: return float(inf) except ValueError: x = 1e300 while ((x + x) != x): x = x * x return x inf = mkinf() Is that a portable solution? The IEEE spec actually says that (x == nan) should be *false* for every x, including nan. I'm not sure if this is more or less stupid than what python does! Well, no, the IEEE standard is correct. NaNs aren't equal to anything, including themselves, since they aren't numbers. I don't buy that. Just because something isn't a number doesn't mean it can't be equal to something else, does it? I mean, we even say x == None if x is indeed None. Yes, but None does equal None, since there is only one None, and by definition, a thing is equal to itself. Yes. But NaNs are _not_ things. I disagree. A NaN _is_ a thing; it's not a floating-point number, for sure, but it is a symbol which means there is no answer, or i don't know, and as such, it should follow the universal rules which apply to all things. That is the whole point! Yes, we _represent_ INF-INF as a particular bit-pattern and call it NaN, but mathematically subtracting infinity from infinity is not defined. There is no answer to the question what is infinity subtracted from infinity?. There is a value at large in my programs, represented however, meaning whatever, and with whatever name, and it should follow the same fundamental rules as every single other value in the entire programmatic universe. Yes, NaN is a special case, but special cases aren't special enough to break the rules. We pretend that the answer is NaN, but that isn't right. The NaN is just there as a placeholder for there is no answer, so that we don't have to sprinkle our code with a thousand and one tests. In the same way as None is a placeholder for there is no thing. These placeholders are themselves things! Since INF-INF doesn't have an answer, we can't do this: x = inf - inf y = inf - inf and expect that x == y. I think we can. Both x and y have the same value, a value of indeterminacy. NaN is a rigidly defined value of doubt and uncertainty! Moreover, this freaky rule about NaNs means that this is an exception to the otherwise absolutely inviolate law that x == x. Yes. So what? Remove the NaN shorthand: The non-existent answer to this question is the same non-existent answer to this other question. Make sense to me. It doesn't make sense to say that a non-thing is equal to anything -- even to itself, since itself doesn't exist. (Remember, a NaN is just an illusionary placeholder, not a number.) If you think it's illusionary, i invite you to inspect the contents of my variables - i have a real, live NaN trapped in one of them! I'd rather have that simple, fundamental logical consistency than some IEEE rocket scientist's practical-value-free idea of mathematical consistency. Ah, from a _programmer's_ perspective, there is an argument that the simplicity of just testing NaNs with equality outweighs the logical silliness of doing such a thing. Yes. It may not be mathematically pure (although i argue that it is, in fact, as long as you don't think of floats as being real numbers), it is practical, and practicality beats purity. But, apart from testing whether a float is a NaN, why would you ever want to do an equality test? By definition, never. Isn't that usage reason enough? The only
Re: Determining actual elapsed (wall-clock) time
On Sat, 2 Jul 2005 19:44:19 -0400, Tim Peters [EMAIL PROTECTED] wrote: [Peter Hansen] Hmmm... not only that, but at least under XP the return value of time.time() _is_ UTC. At least, it's entirely unaffected by the daylight savings time change, or (apparently) by changes in time zone. On all platforms, time.time() returns the number of seconds since the epoch. All POSIX systems agree on when the epoch began, but that doesn't really matter to your use case. Number of seconds since the epoch is insensitive to daylight time, time zone, leap seconds, etc.=20 Users can nevertheless make it appear to jump (into the future or the past) by changing their system clock. If you need an absolute measure of time immune to user whims, you need to connect to special hardware, or to an external time source. For the latter, Peter, you can probably adapt Paul Rubin' setclock.py found at http://www.nightsong.com/phr/python/setclock.py Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list
Re: A Policy for Inclusion in the Standard Library: was Modules forinclusion in standard library?
Colin J. Williams [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Terry Reedy wrote: A couple of times, Guido has given his general policy as generally useful; best-of-breed, tested and accepted by the community; and backed by a developer who will adapt it and its doc up to stdlib standards (if necessary) and commit to maintainence for a few years. This is a good base. Presumably accepted by the community means with some minimum number of ongoing users. Yes. Users also indicate practical (versus theoretical) usefullness and also test beyond what a developer might (especially documentation). Of course, modules written by the inner core group of active developers or on their behalf may bypass these criteria, but the context of my answer was discussion of inclusion of existing modules mostly or all written by other people. Part of the maintainence requirement is a willingness to work compatibly with the Python release cycle. Related to that is something I left out on the other side: willingness to license the module to the PSF for inclusion. Some people seem to assume that everyone 'of course' wants their stuff included and that it is just Guido blocking inclusion, but that just is not so. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list
Re: Accepted Summer of Code proposals
On 7/3/05, Robert Kern [EMAIL PROTECTED] wrote: I would suggest not speculating on biased or malicious intentions. It is possible that no one applied with a proposal to work on Dabo, or that such a proposal was poorly written, or that the author had too little experience, or any number of other things. I wasn't implying malicious intentions; if that's the way it read, I apologize. I only meant to express surprise. I know that there was a proposal from Dabo, but I don't know much more than that. I've simply been following both projects for some time now, and find that the Dabo folks have done so much more in much less time, and that their stuff seems so much more straightforward. Wax seems to be slowly drifting along, while Dabo is moving ahead steadily. -- http://mail.python.org/mailman/listinfo/python-list
Re: What are the other options against Zope?
Christopher Subich [EMAIL PROTECTED] writes: That, and the file format definitely isn't robust to bit-rot that happened too often on FAT16/32 filesystems. From where I sit, the critical difference between the registry and a set of .ini files (or Unix rc files) is that the registry requires special tools to tweak if it gets so busted you can't boot the system. The .ini (rc) files require nothing more complicated than an editor. Editors you sort of have to know - so fixing the .ini (rc) files doesn't require learning anything beyond the configuration system. To add insult to injury, the tools for hacking the Windows registry all require you to bring up a GUI, which means your rescue disk has to include a GUI. Note that Unix isn't immune to things like the registry. AIX(*) puts all the configuration information in an object database, that require special tools to manipulate. At least AIX provides CLI and curses-based tools to do the work. mike *) I know, some people don't consider AIX to be Unix. But it at least reminds you of Unix... -- Mike Meyer [EMAIL PROTECTED] 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: need to get an index for an item in a list
Hey, thanks, this has worked out for me. i am trying to do as much of this as possible in IDLE because it lets me know on the fly what is messed up. thanks for your help shawn -- http://mail.python.org/mailman/listinfo/python-list