Re: new forum -- homework help/chit chat/easy communication
Lasse Vågsæther Karlsen wrote: In other words, what is the difference between a scripting language and a programming language. here's one useful way to look at things: Unlike mainstream component programming, scripts usually do not introduce new components but simply wire existing ones. Scripts can be seen as introducing behavior but no new state. /.../ Of course, there is nothing to stop a scripting language from introducing persistent state -- it then simply turns into a normal programming language. -- Clemens Szyperski, in Component Software: /F -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.setdefaulttimeout()
rtilley wrote: Perhaps this is a dumb question... but here goes. Should a socket client and a socket server each have different values for socket.setdefaulttimeout() what happens? Does the one with the shortest timeout period end first? the timeout is a local setting, so the each process will time out according to its own settings. (but in reality, since sockets are about communication between two parties, it's quite likely that the other end has already given up when your side times out.) /F -- http://mail.python.org/mailman/listinfo/python-list
Here I am again, same old arguments
Okay, same program, different issue. Thanks to the help that I was given I was able to complete my program to find variables in a list that were repeated, and display them once, and how many times they appeared in the list. And it worked great! But, being the perfectionist that I am, I wanted to make the proggie allow any size of list, and not have to be recoded every time. So step one was to not make the program reliant on the list itself being of X length all the time. Well, for some reason, the FOR loop is altering two of my lists. Using PRINT magic, I was able to narrow down the lines that were causing it. But the question remains: Why is it doing this? I'm sure there's a simple answer that I just overlooked in the manual or something. So without further ado, the code: #setup variables grub=[3,25,3,5,3,a,a,BOB,3,3,45,36,26,25,a,3,3,3,bob,BOB,67] grubrpt=grub cntro=0 cntrt=0 rpt=0 skipped=0 #set up for variable length of grub ttllen=len(grub)-1 print The heck is this for loop doing? for point in range(0,ttllen,1): print Here's Grub=,grub print And grubrpt=,grubrpt grubrpt[point]=blk #Makes sure that there are not multiple prints. def alrdy_dn(grub,grubrpt): if grub[cntro] in grubrpt: return grubrpt else: print grub[cntro],appears in list,rpt,times. grubrpt[grubrpt.index(blk)]=grub[cntro] return grubrpt #removes display of variables not repeated def no_rpts(skipped,grubrpt): if rpt==0: skipped=skipped+1 else: grubrpt=alrdy_dn(grub,grubrpt) return skipped #Main body of code print The List is:,grub while cntrolen(grub)-1: if grub[cntro]==grub[cntrt]: rpt=rpt+1 cntrt=cntrt+1 else: cntrt=cntrt+1 if cntrt==len(grub): skipped=no_rpts(skipped,grubrpt) cntro=cntro+1 cntrt=0 rpt=-1 print skipped,list elements are unique. And the award winning Output: The heck is this for loop doing? Here's Grub= [3, 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] And grubrpt= [3, 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] Here's Grub= ['blk', 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] And grubrpt= ['blk', 25, 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] Here's Grub= ['blk', 'blk', 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] And grubrpt= ['blk', 'blk', 3, 5, 3, 'a', 'a', 'BOB', 3, 3, 45, 36, 26, 25, 'a', 3, 3, 3, 'bob', 'BOB', 67] It goes on like that, I'm not going to put all of it here for obvious reasons. But, if I take out the whole for loop and the lines relating to it and statically assign grubrpt as [blk,blk...] then the program runs wonderfully. From what I understand, you can never have too many functions, so I tried to make the grub blk a function and got the same result. I'm still nailing them down, so if my functions look a little weird you know why. Also, I do realize that there is an easier way to do this, I just created a little project for myself to learn the basics of the language. Thanks for all the help! -CJ -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
[EMAIL PROTECTED] wrote: These 3 intermediate variables used to improve readability can introduce bugs : you have to check that b, c and d are not used anywhere else in the code. if you have a fear of introducing new local variables, you have problems that cannot be solved by syntax. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 23:33:13 GMT, Rich Teer [EMAIL PROTECTED] wrote or quoted : WHat the hell has that got to do with HTML email? Sending photos is an example of what attachments are for. Normally you send photos to grandma with captions under each photo. That is far more convenient for the technopeasant receiver than dealing with multiple attachments. People keep thinking of email as a techie preserve. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On 8 Oct 2005 23:39:27 GMT, John Bokma [EMAIL PROTECTED] wrote or quoted : Yeah, yeah, and 640K is enough for everybody. Same song, different tune. For how long. Surely attachments are a stop gap. Can you imagine people sharing images that way 100 years from now? Why should we wait for the future? The problems blocking easy to use photo sharing are not technological but social. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 04:44:25 -, [EMAIL PROTECTED] (Gordon Burditt) wrote or quoted : And how do you fix the problem of unsolicited USENET articles? (*ALL* of them are unsolicited to someone). Or unsolicited email? Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html I talk around those problems. It requires a fresh start. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 19:56:50 -0400, Mike Meyer [EMAIL PROTECTED] wrote or quoted : Show us *examples*! Do you create a style sheet for every site you visit that overrides there classes? What? Why don't you download a copy of Opera, see http://mindprod.com/jgloss/opera.html Then try out the feature. Click View | style | user -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Here I am again, same old arguments
CJ wrote: Well, for some reason, the FOR loop is altering two of my lists. Using PRINT magic, I was able to narrow down the lines that were causing it. But the question remains: Why is it doing this? I'm sure there's a simple answer that I just overlooked in the manual or something. here you create a list, and name it grub: grub=[3,25,3,5,3,a,a,BOB,3,3,45,36,26,25,a,3,3,3,bob,BOB,67] here you add a new name for that list: grubrpt=grub after this operation, grubrpt and grub are two names for the same object, not two distinct objects. in Python, variables are names, not small boxes in memory than contain stuff. you can add print id(grub), id(grubrpt) to see the object identities. required reading: http://effbot.org/zone/python-objects.htm (short version, available in english, french, and czech) http://starship.python.net/crew/mwh/hacks/objectthink.html (long version, with ascii art!) some common patterns: to copy a list, use grubrpt = grub[:] or the copy module. to build a new list from an old one, use new_list = [] for item in old_list: ... do something ... new_list.append(item) for some cases, a list comprehension can be a nicer way to write that: new_list = [... item ... for item in old_list ...] etc. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 23:35:40 GMT, Rich Teer [EMAIL PROTECTED] wrote or quoted : If people want me to read their email, they should send it to me in an open, universal format, which for email is plain text. It's as simple as that. This is pulling a King Canute. There is not even a mechanism in email protocols to warn your correspondents of your demand. I have been bugging Eudora for years for at least a bit in the address book to record the recipient's preference for plain or formatted emails. They have so far ignored me. There is nothing wrong with formatted text. You are confusing formatted text with spam. You think you hated formatted text, but you really hate spam. If your lover sent you a message with photo, and even musical accompaniment, I doubt you would feel offended. It is the CONTENT bugging you, not the HTML. You imagine that the two are inexplicably linked. That is just because the technology is immature. There is no fundamental reason that formatted spam should have an easier time penetrating your defenses than plain text spam. I am using Spamnix. It think it leaks about 50/50 formatted and plain text spam. Eudora warns you of deceptive links in HTML. There are many more such things that have yet to be done to deal with malicious emails. I think we should focus on those rather than reverting to the days of the TTY.I don't think it would buy you much. Formatted emails can't hurt you if you don't allow them to automatically run any code. It is unfair to blame formatting for the foolish practice off allowing untrusted code to run without even an ok. They have nothing to do with each other. -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On 08 Oct 2005 18:59:39 -0700, Paul Rubin http://[EMAIL PROTECTED] wrote or quoted : I read mail over an ssh connection to a Unix shell. I have no easy way to read html email with a graphics browser. So the rest of the world should forgo rich communication because of your obsolete software? How could anything every evolve with that attitude? -- Canadian Mind Products, Roedy Green. http://mindprod.com Again taking new Java programming contracts. -- http://mail.python.org/mailman/listinfo/python-list
Re: Using command line args on Windows
Duncan Booth [EMAIL PROTECTED] wrote: Fredrik Lundh wrote: footnote: if you'd prefer to type myscript myarg instead, you might want to check out this tool: http://effbot.org/zone/exemaker.htm or even just do: SET PATHEXT=.py;%PATHEXT% and then myscript myarg will work for all scripts on your path without compiling (if you don't set PATHEXT then myscript.py myarg will still work, and tab completion means you don't generally need to type the .py for scripts in the current directory). The downside to this is that there is a bug in the NT/2K/XP command interpreter which will prevent redirecting from stdin in that case. That is: C:\Tmptype x.py import sys print sys.stdin.readline() C:\Tmpecho 123 | python x.py 123 C:\Tmpecho 123 | x.py The process tried to write to a nonexistent pipe. C:\Tmppython x.py x.py import sys C:\Tmpx.py x.py C:\Tmp -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Matching zero only once using RE
Mike Meyer [EMAIL PROTECTED] wrote: I think it's time to form a Committee for the Prevention of Regular Expression Abuse. As I learned from personal experience, this is a disease which one contracts when moving to Python from Perl. Perl teaches you that the entire world is a string, and every operation is a regular expression match upon that string. -- - Tim Roberts, [EMAIL PROTECTED] Providenza Boekelheide, Inc. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In article [EMAIL PROTECTED], Roedy Green [EMAIL PROTECTED] wrote: I take it then you avoid browsers or use Lynx? No you FIX the problems rather than wear a hair shirt. Same for email. Why should rich expressions only be permitted to those with websites. Between consenting adults, yes, but for general use **in emails**, no. Some people use email PRIMARILY for sharing photos. I do, frequently, without any need for HTML. -- David Wild using RISC OS on broadband -- http://mail.python.org/mailman/listinfo/python-list
import socket error
Hi, I am following this tutorial https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=dw-linux-pysocksS_TACT=105AGX59S_CMP=GRca=dgr-lnxw07PythonSockets ( free reg. req. ) The article told me to do this: [camus]$ python Python 2.4 (#1, Feb 20 2005, 11:25:45) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type help, copyright, credits or license for more information. import socket socket.gethostbyname('www.ibm.com') '129.42.19.99' When I try it, I get this error: import socket Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.4/socket.py, line 1, in ? # Wrapper module for _socket, providing some additional facilities File /usr/lib/python2.4/SocketServer.py, line 274, in ? class TCPServer(BaseServer): File /usr/lib/python2.4/SocketServer.py, line 317, in TCPServer address_family = socket.AF_INET AttributeError: 'module' object has no attribute 'AF_INET' Why? Thank you. -- http://mail.python.org/mailman/listinfo/python-list
Question about StringIO
Hi all I understand that StringIO creates a file-like object in memory. Is it possible to invoke another program, using os.system() or os.popen(), and use the redirect operator, so that the other program reads my StringIO object as its input? I will provide more details if required, but hopefully this is enough for a simple yes or no answer, and if so, how. BTW, I have tried using popen2() and passing my data via stdin, but the other program (psql) does not react well to this - again, I will give more info if necessary. Thanks Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: import socket error
[EMAIL PROTECTED] wrote: I am following this tutorial https://www14.software.ibm.com/webapp/iwm/web/preLogin.do?source=dw-linux-pysocksS_TACT=105AGX59S_CMP=GRca=dgr-lnxw07PythonSockets ( free reg. req. ) The article told me to do this: [camus]$ python Python 2.4 (#1, Feb 20 2005, 11:25:45) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)] on linux2 Type help, copyright, credits or license for more information. import socket socket.gethostbyname('www.ibm.com') '129.42.19.99' When I try it, I get this error: import socket Traceback (most recent call last): File stdin, line 1, in ? File /usr/lib/python2.4/socket.py, line 1, in ? # Wrapper module for _socket, providing some additional facilities File /usr/lib/python2.4/SocketServer.py, line 274, in ? class TCPServer(BaseServer): File /usr/lib/python2.4/SocketServer.py, line 317, in TCPServer address_family = socket.AF_INET AttributeError: 'module' object has no attribute 'AF_INET' Why? Thank you. your Python installation is broken. what OS are you using? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
On Sat, 08 Oct 2005 15:20:12 +0200, Lasse Vågsæther Karlsen wrote: Ok, so I thought, how about creating a decorator that caches the function results and retrieves them from cache if possible, otherwise it calls the function and store the value in the cache for the next invokation. This is what I came up with so far: def cache_function(fn): cache = {} def cached_result(*args, **kwargs): if args in cache: return cache[args] result = fn(*args, **kwargs) cache[args] = result return result return cached_result I'm curious... where does cache live after you use cache_function to memoize some function? It doesn't appear to be an attribute of the newly memoized function, nor does it look like a global variable. The solution would have to consider fibonacci(50) and fibonacci(idx = 50) as the same call and thus retrieve the second one from the cache. In general, you probably can't do that without lots and lots of really clever code searching through the function argument lists. If you know that your function will always have the same keyword, then you can do something like this: if args in cache: return cache[args] elif kwargs.keys() == idx: return cache[kwargs[idx]] but that's a special case and you really don't want to do it *wink* Otherwise, just accept that you may be caching multiple copies of the same data, and do something like this: if args in cache: return cache[args] elif kwargs.items() in cache: return cache[kwargs.items()] with the appropriate changes to the rest of the code. You may also find that you could get a slight performance increase by using the idiom try: return cache[args] except: # calculate the result and store it in the cache. instead of testing for membership. As always, timing some test functions is your friend... -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Mike Meyer: Paul Rubin: I read mail over an ssh connection to a Unix shell. I have no easy way to read html email with a graphics browser. You don't need a grahics browser - you just need a browser. I read mail in emacs, and use emacs-w3m to view html in the mailer. Works for most things, and doesn't have the nasty side effect of letting the sender know I read it by fetching images from their web site. I occasionally get html email that I want to read. I save it in a file and read it with lynx, which so far works perfectly well. I find html email to be a PITA and as someone else said, html in email is an almost sure sign that it's a message that I want to trash without reading it. Unfortunately, I've found that HTML email comes in two flavors: That which sets content-type to text/html in the headers, and that which sets it to some form of multipart in the headers. I used to bounce all mail of either form. Then I discovered that the AOL client - used by my relatives - could *not* be set to not send HTML email. At least it sends text/plain as well. On investigation, most legit email does sends multipart/mixed, so I only reject mail whose sole content is text/html. Let procmail make all those decisions and transformations for you. I have a maildir called 'raw' where I keep a copy of all non-spammish mail. Copies of the same messages also get delivered in the right mailboxes, by procmail. A message that contains only html, is piped though lynx -dump -stdin. A message containing both HTML and a plain/text-part, is de-mime-d, leaving only the plain/text-part (unless that part contains only a silly remark). Footers and long signatures are limited or even deleted. Etc., etc. (I like my mail cooked.) One of the reasons that I started with Perl, is that I want to rewrite procmail in Perl. -- Affijn, Ruudhttp://www.pandora.com/?sc=sh770781cmd=tunermini Gewoon is een tijger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python's Performance
On Sat, 08 Oct 2005 10:14:25 -0700, Phillip J. Eby wrote: So, without meaning to, the benchmark author has demonstrated something important about Python, which is that writing the obvious thing in Python tends to work correctly, even if it sometimes takes longer to run than it would take for another language to produce the wrong answer. :) Which is of course demonstrates two different strategies of programming. The first is, I don't care what answer I get, so long as I get it quickly!. The second is, I don't care how long it takes, so long as I get the right answer! The smart programmer will understand that both strategies can be the right one in different circumstances. For instance, the Apollo landers didn't have the computing power to calculate the right answer quickly enough to prevent the lander from burying itself deep beneath the moon's surface, so they used a strategy of calculating the wrong answer quickly, then incrementally improving it. I'm told that the Apollo 11 lander's computer rebooted something like 20 times in the few minutes it took to go from orbit to the surface. It would crash, reboot, and just pick up the calculations from the last one that completed. Try doing that with Wintel! :-) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Pythoncard-users] Re: Pythoncard mental block
Gregory Piero wrote: The Python-Card guys are really helpful, [EMAIL PROTECTED], you may have to register on sourceforge to get on their list. In the meantime I went ahead and cc'd them on this. Python-Card guys, make sure to cc Steven as he may not be on the list. Thanks Greg. Hi!! I am working on a school project and I decided to use PythonCard and wxPython for my GUI development. I need a password window that will block unwanted users from the system. I got the pop-up password question to work... I haven't seen any replies to this, so even though I don't actually use Pythoncard I'll take a wild shot in the dark. def on_openBackground(self, event): result = dialog.textEntryDialog(self, 'System', 'Please enter your password: ', '') .but I don't exactly remember how to check if the entered password is correct. Say I hard code the password to be 'hello', then how would I check if this was the input or if it wasn't??? Usually, you'll do something like ... result = dialog.textEntryDialog(self, 'Enter your password:', 'Password', '', wx.TE_PASSWORD) if result.accepted and result.text != '': self.pwd = result.text else: do something appropriate if you don't have a password to use Note the last parameter wx.TE_PASSWORD - this ensures that the characters typed are echoed as starts (or bullets, or something) so they can't be read by anyone overlooking the user. [you may need to add an "import wx" to use this] The Text Entry Dialog has both an "OK" and a "Cancel" button (and can be simply closed), so it's important to check that result.accepted is True before using any text entered. The sampleLauncher of small demos and samples that comes with PythonCard has a an example of usage for every kind of dialog, and most of the components, so it can be a good source for questions like this. Also, you can often find what you need by using the FindFiles utility (comes with PythonCard) to find examples of usage within the PythonCard samples subdirectory. Lastly, I might not have used Pythoncard, but years ago I used to use Hypercard rather a lot. In Hypercard, the password dialog would use a one-way hash function to encrypt the typed response into a large integer value. I assume Pythoncard is designed to do the same thing as Hypercard. The parallels with Hypercard aren't that strong. :-) In this case, PythonCard is more versatile (i.e. less helpful) - it just returns the string entered, leaving it up to you whether to one-way hash it, encrypt it, use it as an MD5 key phrase, or whatever. -- Alex Tweedly http://www.tweedly.net No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.344 / Virus Database: 267.11.13/123 - Release Date: 06/10/2005 -- http://mail.python.org/mailman/listinfo/python-list
Re: Weighted random selection from list of lists
On Sat, 08 Oct 2005 12:48:26 -0400, Jesse Noller wrote: Once main_list is populated, I want to build a sequence from items within the lists, randomly with a defined percentage of the sequence coming for the various lists. For example, if I want a 6 item sequence, I might want: 60% from list 1 (main_list[0]) 30% from list 2 (main_list[1]) 10% from list 3 (main_list[2]) If you are happy enough to match the percentages statistically rather than exactly, simply do something like this: pr = random.random() if pr 0.6: list_num = 0 elif pr 0.9: list_num = 1 else: list_num = 2 return random.choice(main_list[list_num]) or however you want to extract an item. On average, this will mean 60% of the items will come from list1 etc, but for small numbers of trials, you may have significant differences. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
Fredrik Lundh a écrit : if you have a fear of introducing new local variables, you have problems that cannot be solved by syntax. Dear Fredrik, I have read the original messages on fr.comp.lang.python, and I don't understand your answer. It is not about a fear of introducing new local variables, but for me it is an elegant solution to a common problem, to avoid creation of useless variables (what in french we call variables muettes, like indexes in loops who are just there because some langages level is too low). It also avoid the increase of parenthesis depth, and so the readability is enhanced. And it solve a problem that in all object oriented langages, a method that process 2 or more different classes of objets belongs just to one of those classes. All this kind of problems appears often to me (and in different langages), and contrarily to you, I'm very impressed by the compacity and elegance of the solution. I think it would be nice if implemented in different langages (because it breaks nothing), and firstly Python. Best regards, Al PS : sorry for my approximative english, but my natural langage is french. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Steven D'Aprano [EMAIL PROTECTED] writes: def cache_function(fn): cache = {} def cached_result(*args, **kwargs): if args in cache: return cache[args] result = fn(*args, **kwargs) cache[args] = result return result return cached_result I'm curious... where does cache live after you use cache_function to memoize some function? It doesn't appear to be an attribute of the newly memoized function, nor does it look like a global variable. It's in the closure returned by cache_function. cached_result doesn't change the value of 'cache' (it only changes the boxed content), cached_result finds it in the outer scope, so you can get away with that in Python. You couldn't do something like: def counter(): n = 0 def k(): n += 1# rebinds n, so Python thinks n is local, oops return n return k Since k changes the value of n, Python thinks n is local to k, and you get a NameError when you try to increment it the first time. That you can't set the value of a closure variable is something of a Python wart and is one of the things that makes me want a local declaration in Python. Closures are a Scheme idiom and Pythonistas tend to use class instances instead, but both techniques are useful. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 20:43:12 +, Roedy Green wrote: I liken it more to hating all viruses because some of them install keyloggers. I take it then you avoid browsers or use Lynx? No you FIX the problems rather than wear a hair shirt. No, I avoid browsers that are broken, e.g. those that have ActiveX. If people send a link to a website that includes ActiveX, then no matter how great the advantages, the disadvantages are more. Likewise I avoid emails that are broken. If it looks like it will contain web-bugs, javascript exploits, or badly formatted unreadable text, then I avoid any mail client that can't display it in plain text. And by looks like, I mean contains any HTML. Same for email. Why should rich expressions only be permitted to those with websites. Because the disadvantages of HTML email are greater than the advantages. If people mail me HTML mail, I make a snap judgement -- trash it or read it? It is usually trash it. There are only so many emails with purple text on indigo backgrounds that a man can read before deciding that the tasteless, clueless masses should never been given the ability to format text. Some people use email PRIMARILY for sharing photos. Which you can do by attaching the photo to the email. Even mutt or pine can attach binary files to an email. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 20:44:12 +, Roedy Green wrote: On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote or quoted : Yes it is. HTML means that after I've specified my email client use my favourite font, in the size I like, people send me emails that over-ride my choice. Invariably they use a font I don't even have. I would suggest then a better solution is to implement CSS in email, the way you do in browsers to deal with that same problem. Are you volunteering? Good. Let me know when your done, I'd love to see it. In the meantime, I'll continue viewing emails in plain text, and if they contain HTML I'll choose for myself whether to render it, or trash it, or manually read through the code looking for content. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Roedy Green [EMAIL PROTECTED] writes: On Sun, 09 Oct 2005 04:44:25 -, [EMAIL PROTECTED] (Gordon Burditt) wrote or quoted : And how do you fix the problem of unsolicited USENET articles? (*ALL* of them are unsolicited to someone). Or unsolicited email? Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html I talk around those problems. Actually, you present a design that forces a solution that makes them do what you want down their throats, never mind what they want, or what they've been doing. It shows an amazing ignorance about the internet and how people behave on it. Like most antispam proposals, it won't actually stop spam, just force spammers to concentrate on different channels. You seem to have randomly broken quoting for people who download mail and read it offline, and for any medium that's unreliable or doesn't reliably deliver messages in order - which includes mail and news. Virus writers will love the ability to change peoples address books remotely. The problem of differing character sets is technically solved. Practically, the solution doesn't work because people implementing the software ignore the standards. What's your server going to do when it gets messages with characters in them that aren't valid in the charset that it's declared as being? Better yet, what's it going to do when the characters are valid, but the declared charset isn't the one the author actually used? You implementation sketch only covers the client talking to the first server (in that it requires the client to encrypt a challange phrase with the private key belonging the email id, which is presumably what 2822 uses for the envelope sender). Most mail on the internet goes through at least two servers, and news is much worse. For instance, your messages apparently passed through 10 servers getting to me. You really have to deal with store and forward, or convince a large number of corporations that potentially hostile users should be allowed to talk directly to their mail servers, which isn't very likely. Kudos for recognizing that spam needs to be dealt with by people with guns, but you lose half of them for making ISPS liable for it. I also read the comment about wanting an automated Ask them to run my browser in my favorite configuration, which is equally naive. A lot of sites have such cruft on them already. I find them funny - I surf the web on three different platforms, none of them Windows. Any pointer to download a new browser or plugin for Windows just impresses me with the authors lack of skills. The only browser I know of that runs on all three platforms is Opera, and it's something radically different on one of the three. Even should you get the platform right, almost nobody is going to bother upgrading following the download links. The very small percentage of users who are real geeks will silently thank you for the notice, and update their software. Most users will ignore it so long as the page isn't obviously broken. For those for whom it's broken, all but small percentage will simply find some other site to visit. I'd suggest that anyone thinking about writing It requires a fresh start. You think you're the only person - and probably not the first - to propose such? People a lot smarter than either of us, with a lot more pull and a lot more reason to want it to happen have worked on this - and it ain't happened yet. I wouldn't bet on it happening anytime soon. mike -- 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: Jargons of Info Tech industry
On Sat, 08 Oct 2005 20:44:44 +, Roedy Green wrote: On Wed, 05 Oct 2005 09:38:49 +1000, Steven D'Aprano [EMAIL PROTECTED] wrote or quoted : Even more invariably, they set the point size directly rather than in relative terms, and they are on Windows, where point sizes are about 20% oversized. that is like giving up Java because there was a bug in the Windows JVM. FIX THE BUG. Only Microsoft can do that. They designed their font system in such a way that it ignored real typesetters measurements, probably so it would be deliberately incompatible with font sizes on the Mac. Either that or just through incompetence. Now, it is almost certainly unfixable in Win9x and XP -- it would break too many people's Word documents and web pages. Microsoft could maybe fix it in Vista, if they care too. As if it matters what they put in Vista. But that isn't going to stop lusers setting the font size to 5pt or 55pt just because they think it is kewl. Until we can send fatal electric shocks through the Internet, there is little we can do to stop that. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 00:03:05 +0200, Lasse Vågsæther Karlsen wrote: Now, if you want to get into a big huff because someone you knows use a font that is slightly oversized because of Windows, then I think you missed the point of the email altogether, which was probably to convey a message. Talk about missing the point, pun intended. The point isn't that there is some tiny difference in font sizes. It is that small font sizes which are just readable under Windows are unreadably small on Linux and Mac. If you want to convey a message, it helps if the recipient can actually read the damn thing without having to get out a magnifying glass. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Oh, and another point... On Sun, 09 Oct 2005 00:03:05 +0200, Lasse Vågsæther Karlsen wrote: But trying to keep your email world into a pure text-based no-formatting-whatsoever world, that's a fantasy bubble that is bound to burst, sooner rather than later. Nonsense. I can easily set up a filter to dump non-plain text email straight into the trash. If I choose, I never need see a HTML mail. Ever. In fact, since the single strongest predictor of spam is the use of HTML, I predict that a lot more people than you think have HTML emails either deleted or dumped in a spam folder. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Daisy Daisy, give me your answer do
On Saturday 08 October 2005 23:39, Xah Lee wrote: Dear Michael Goettsche, why don't you lead the pack to be on-topic for a change, huh? Xah Because you are a moron. Unsubscribe from this list please and never come back. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 22:25:23 +, Roedy Green wrote about HTML emails: Just how long do you want to stall evolution? Evolution doesn't mean use whatever broken solution Microsoft and Hotmail popularized, just because all my friends are using it. If and when somebody puts out a good rich text email format, I'll use it. Until then, I won't use HTML. Do you imagine people 200 years from now will be still be using pure ASCII text unable to find a solution to JavaScript viruses (turn off JS), pop-up( disable popups) etc.? Firstly, I don't care what people will be using in 200 years. I don't care if in 200 years the default email format is so big and bloated that it takes three weeks to download even a single sentence, because I won't be around to suffer. If you think that people will be using the current data formats for email in two centuries, you're crazy. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
def cache_function(fn): cache = {} def cached_result(*args, **kwargs): if args in cache: return cache[args] result = fn(*args, **kwargs) cache[args] = result return result return cached_result I'm curious... where does cache live after you use cache_function to memoize some function? It doesn't appear to be an attribute of the newly memoized function, nor does it look like a global variable. It's part of the closure - as well as fn, btw. So it is per-decorated-function. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
al wrote: Fredrik Lundh a écrit : if you have a fear of introducing new local variables, you have problems that cannot be solved by syntax. Dear Fredrik, I have read the original messages on fr.comp.lang.python, and I don't understand your answer. It is not about a fear of introducing new local variables, but for me it is an elegant solution to a common problem, to avoid creation of useless variables (what in french we call variables muettes, like indexes in loops who are just there because some langages level is too low). It also avoid the increase of parenthesis depth, and so the readability is enhanced. And it solve a problem that in all object oriented langages, a method that process 2 or more different classes of objets belongs just to one of those classes. All this kind of problems appears often to me (and in different langages), and contrarily to you, I'm very impressed by the compacity and elegance of the solution. I think it would be nice if implemented in different langages (because it breaks nothing), and firstly Python. Best regards, Al PS : sorry for my approximative english, but my natural langage is french. It seems to me that what you proposed was a solution, that seems obvious only to you, to a problem perceived only by you. I am afraid you would have to work rather harder to persuade me that there is a problem, let alone that you have found the solution to it. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Roedy Green [EMAIL PROTECTED] writes: I read mail over an ssh connection to a Unix shell. I have no easy way to read html email with a graphics browser. So the rest of the world should forgo rich communication because of your obsolete software? How could anything every evolve with that attitude? There is nothing obsolete about lynx. It completely conforms to the w3 standard. Anyway, email is a text medium and attempts to evolve it almost always make it worse. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 07:19:29 +, Roedy Green wrote: On Sat, 08 Oct 2005 23:33:13 GMT, Rich Teer [EMAIL PROTECTED] wrote or quoted : WHat the hell has that got to do with HTML email? Sending photos is an example of what attachments are for. Normally you send photos to grandma with captions under each photo. No, normally YOU send photos to grandma with captions under each photo. My grandma doesn't put captions in her photo album, and she doesn't need captions on her photos in email. That is far more convenient for the technopeasant receiver than dealing with multiple attachments. Only if your photos are so obscure and confusing that they need captions. Here's Johnny with the dog. Here is Johnny with the dog again. This one is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog again -- that's the dog on the left, in case it isn't clear. Just for a change, this is Johnny wearing a hat. It is blue with a feather in it, in case you couldn't tell from, oh I don't know, looking at the actual picture. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Roedy Green [EMAIL PROTECTED] writes: On Sat, 08 Oct 2005 19:56:50 -0400, Mike Meyer [EMAIL PROTECTED] wrote or quoted : Show us *examples*! Do you create a style sheet for every site you visit that overrides there classes? What? Why don't you download a copy of Opera, see http://mindprod.com/jgloss/opera.html What makes you think I don't have a copy of Opera? Just so happens I've got a registred copy on my newest computer. Then try out the feature. Click View | style | user My copy of Opera doesn't have that menu entry. I suspect you're making platform-specific suggestions. Trying it on a different platform, it looks like it does what I said earlier: user mode simply disables the authors style sheets. None of the merging you suggested was going on is actually happening Can you demonstrate this merging you talked about? For example, show me how to get the Opera help page to display with the authors layout but my fonts. mike -- 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: Question about StringIO
Frank Millman wrote: Hi all I understand that StringIO creates a file-like object in memory. Is it possible to invoke another program, using os.system() or os.popen(), and use the redirect operator, so that the other program reads my StringIO object as its input? I will provide more details if required, but hopefully this is enough for a simple yes or no answer, and if so, how. BTW, I have tried using popen2() and passing my data via stdin, but the other program (psql) does not react well to this - again, I will give more info if necessary. Unfortunately the StringIO module only creates instances inside the process they are called: these objects have no existence to the operating system or to other processes, and so can't be used for inter-process communication. regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC www.holdenweb.com PyCon TX 2006 www.python.org/pycon/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 07:40:55 +, Roedy Green wrote: There is nothing wrong with formatted text. You are confusing formatted text with spam. No. YOU are confusing HTML email (broken, dangerous, bad) with formatted text (maybe good, maybe bad). I've hated HTML emails well before I received my first spam. I still hate it, long after I've got my spam problem under control. If and when somebody comes up with a non-broken, non-dangerous way of allowing formatting in emails, I'll consider it. But HTML is not and never will be that format. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 07:42:18 +, Roedy Green wrote: On 08 Oct 2005 18:59:39 -0700, Paul Rubin http://[EMAIL PROTECTED] wrote or quoted : I read mail over an ssh connection to a Unix shell. I have no easy way to read html email with a graphics browser. So the rest of the world should forgo rich communication because of your obsolete software? How could anything every evolve with that attitude? Hardly obsolete, any more than hammers are obsolete just because we have Concords. (The Concord... now *there* is an obsolete technology.) You may have noticed that even Microsoft have acknowledged the power and flexibility of text-based shells, and will be (if they get the technology right in time) building one into Vista. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 23:39:27 +, John Bokma wrote: Rich Teer [EMAIL PROTECTED] wrote: On Sat, 8 Oct 2005, Roedy Green wrote: Some people use email PRIMARILY for sharing photos. WHat the hell has that got to do with HTML email? The photo doesn't have to be included (as in attached)? with the email? I'll repeat the question: what do attachments have to do with HTML emails? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Roedy Green [EMAIL PROTECTED] writes: There is no fundamental reason that formatted spam should have an easier time penetrating your defenses than plain text spam. Formatted spam can include pictures of words. That's a common spam tactic - send a multipart/alternative with a text part that look like a letter from aunt jane - and mention that you're sending a picture. The picture part is basically a jpeg of a flyer for the spam companies product. If you've got a spam filter that can determine that a picture of words is spam, I'd like to know about it. mike -- 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: Daisy Daisy, give me your answer do
Michael Goettsche wrote: cut You're asking tech geekers and morons to do this job? Isn't that a task for somebody more professional like you? I think he's doing a shot to the position of open-source leader, judging on the replies he has got till so far, that shot was not really effective. In dutch we have a saying for these kind of people, it goes like this: 12 ambachten, 13 ongelukken. -- mph -- http://mail.python.org/mailman/listinfo/python-list
Re: Question about StringIO
Frank Millman wrote: Hi all I understand that StringIO creates a file-like object in memory. Is it possible to invoke another program, using os.system() or os.popen(), and use the redirect operator, so that the other program reads my StringIO object as its input? No. Processes don't share memory - thus you have to either use a temp file, or pipes. BTW, I have tried using popen2() and passing my data via stdin, but the other program (psql) does not react well to this - again, I will give more info if necessary. Better do so :) Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: import socket error
Fedora Core 4. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Dr.Ruud [EMAIL PROTECTED] writes: Let procmail make all those decisions and transformations for you. I prefer qmail dot-commands. It provides an architecture for controlling the delivery of email, and lets you write the smarts of the mail processing in whatever language you want. I have a maildir called 'raw' where I keep a copy of all non-spammish mail. I call mine archives. I also remove duplicate email before it gets to the mailbox. Copies of the same messages also get delivered in the right mailboxes, by procmail. Yup, qmail does that for me. A message that contains only html, is piped though lynx -dump -stdin. I build a bounce message explaing that it wasn't read, and send that back to the sender. A message containing both HTML and a plain/text-part, is de-mime-d, leaving only the plain/text-part (unless that part contains only a silly remark). Footers and long signatures are limited or even deleted. Etc., etc. (I like my mail cooked.) I don't do those things. Then again - my mail reader makes deals with them on request. One of the reasons that I started with Perl, is that I want to rewrite procmail in Perl. Try qmail - it may solve the problem with a lot less work. mike -- 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: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
Fredrik Lundh a écrit : [EMAIL PROTECTED] wrote: These 3 intermediate variables used to improve readability can introduce bugs : you have to check that b, c and d are not used anywhere else in the code. if you have a fear of introducing new local variables, you have problems that cannot be solved by syntax. /F Before to introduce a new variable named x, you have to take care of the fact the name x is not defined elsewhere and visible in the present scope. It is not a fear, but something you must keep in mind, otherwise it can be a source of errors. If you have a syntax in which you use less variables names to do the same thing, with the same (or better?) readability, that seems better for me. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
On Sun, 09 Oct 2005 02:49:38 -0700, Paul Rubin wrote: I'm curious... where does cache live after you use cache_function to memoize some function? It doesn't appear to be an attribute of the newly memoized function, nor does it look like a global variable. It's in the closure returned by cache_function. What's a closure? Googling on define:closure isn't very useful. There are a *lot* of different meanings for closure, none of them to do with programming. No, wait, I tell a lie -- Wikipedia to the rescue again: http://en.wikipedia.org/wiki/Closure_(programming) I notice that type(some_closure) and type(ordinary_function) both return the same result, type 'function'. I also notice that both the closure and ordinary functions have an attribute func_closure. Is there a way to tell which is a closure and which is not? In my tests, the ordinary function has func_closure == None, but I don't know if that will always be the case of just for my tests. If I wanted to inspect the value of cache, where would I find it? In other words, if I say some_closure.SOMETHING I would get cache... what should SOMETHING be set to? That assumes that cache can be seen in this way. If it can't, is this a way to create really private variables in Python? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Daisy Daisy, give me your answer do
Xah Lee [EMAIL PROTECTED] writes: there is a MacPerl program posted in 1998 that uses Mac's speech synth to sing Daisy Bell. See: http://bumppo.net/lists/macperl/1998/11/msg00412.html can anyone modify it so it runs out of the box on today's OS X? For pre-Tiger OS versions you'll need to install the Mac::Carbon module from CPAN, if you haven't done so already. Tiger ships with it pre-installed. Aside from that, only trivial modification are needed to update the script. Just Replace #!perl with #!/usr/bin/perl, and remove the last line, which calls MacPerl::Quit(). sherm-- -- Cocoa programming in Perl: http://camelbones.sourceforge.net Hire me! My resume: http://www.dot-app.org -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sat, 08 Oct 2005 22:39:38 GMT Roedy Green [EMAIL PROTECTED] wrote: So from an aesthetic point of view, once people learn how it works, CSS lets sender and receiver compromise on what the message looks like. No other medium gives ANY control to the receiver about how a message is formatted. My mail reader renders HTML as text. Usually, that gets the message through without the impediments the sender included. Of course one can render anything in one's computer exactly the way one wants, given comptence and time. Mutual agreement on a CSS is possible, but for widespread usage it needs to be a standardised CSS, and then we're back in the featuritis spiral. One of the most important changes in the ability to select special fonts for the those without prefect vision and larger fonts. That's exactly why I don't want people to muck with the presentation of an email. I've set up my machine to render standard ASCII emails execatly the way I want, with the font that I can read, in a size that optimises ease and visible text. I don't care that someone would like to inline a 5000x3000 JPEG from their 15 megapixel camera, or render text in white on black, or any other silly format. If they want me to see a document in _exactly_ the way they prepared it, let them use PDF. It's there, and it works well. There is also the philosophical question. When my nephew sends me a message, do I have a right to warp his intent even if I don't like the aesthetics? That is part of his message. That question is answered above - if your nephew wants you to see exactly what he produced, let him use the format specifically designed for the purpose. And yes, philosophically speaking the recipient can do anything they like with the message, including not reading it at all. Anything else would be preposterous. Should my email reader fix the spelling mistakes in the emails sent me by angry US soldiers? Or is that part of the message? If you want it to do that, yes. Wheter including the corrected message in the reply is a good idea is another question (mostly related to how the relation is, how it should be, and how big the soldier in question is). There are three different issues getting muddled together: 1. avoiding spam Which happens to use HTML to obfuscate the message and avoid getting caught by filters. 2. making mail from well meaning but inept friends more readable. Who happen to use HTML because they don't have a clue. 3. what constitutes a good general style for general correspondence. How should you use rich text appropriately. Which happens to be largely superfluous as far as conveying intent is concerned. Email works well without rich text, especially when combined with attachments that use a format sender and recipient have agreed to. We don't need more, and we shouldn't assume that more complex technology equates to an improvement. Example: it's not because we can use a gazillion typefaces in pastel colours that documents that we should do so. Take care, -- Stefaan -- As complexity rises, precise statements lose meaning, and meaningful statements lose precision. -- Lotfi Zadeh -- http://mail.python.org/mailman/listinfo/python-list
Re: What is executed when in a generator
[ I've got no idea of your skill level, but since you say you feel a bit lost I'll take baby steps here. Apologies if it's too low or high :-) I'm also taking baby steps because less people understand generators than they might. After all, most new programmers often want something like generators when they start programming, but life gets in their way. ] Jerzy Karczmarczuk wrote: Could you tell me please where can I read something in depth about the semantics of generators? I feel a bit lost. Watch what happens if you take your example (I'm not convinced it's the best example for this, but it is your example :-) on the python shell: gl=0 def gen(x): ... global gl ... gl=x ... yield x ... s=gen(1) Clearly this has done something. What you haven't understood by the looks of things is what and why. Let's take this session a bit further. Let's find out the value of s: s generator object at 0x40397a8c OK, so the call to the generator function returned a generator. That should make sense to you. This will hopefully make more sense if we make a few more calls to 'gen' and look at their values. t=gen(2) t generator object at 0x40397bec As you'd expect the next call *also* creates a generator object. You'll note that it has a different location ( at 0x. ) meaning they're different objects. Do that a few more times and we see the same: u=gen(3) u generator object at 0x403979ec v=gen(4) v generator object at 0x40397c0c What this is doing is creating a generator object which can then be asked repeatedly to run, and yield values. A more accurate term might be iterating over the generator object. However the /idea/ is that you create the object wrapping a context of/for running that can suspend its own control and return intemediate values. Clearly the generator also needs a way of telling us its finished iterating. Let's make that more concrete. You call the .next() method of the object, and when it's done it raises a StopIteration exception. The way we do this with your code is as follows: s.next() 1 Yay! That's the 1 that you were expecting to see. In your function you also updated a global gl. This is probably not a wise idea, but hey, let's look at what happened to that value: gl 1 Again, this is what you should have expected - since it's what you were after. Again, looking at your function, yield x was the last statement, so you should be wondering what happens next: s.next() Traceback (most recent call last): File stdin, line 1, in ? StopIteration As you can see we get told that it's dropped off the end. If we try calling again: s.next() Traceback (most recent call last): File stdin, line 1, in ? StopIteration If we retry with the generator objects created above, we can see: t=gen(2) u=gen(3) v=gen(4) t.next() 2 gl 2 v.next() 4 gl 4 u.next() 3 gl 3 Hopefully that's a clearer explanation of what's actually going on with your code. A more complex example is based on the example in the PEP: def configurable_fib(base1=1, base2=1): a, b = base1, base2 while 1: yield a a,b = b, a+b def configurable_fib(base1=1, base2=1): ... a, b = base1, base2 ... while 1: ... yield a ... a,b = b, a+b normal_fib = configurable_fib(1,1) normal_fib.next() 1 normal_fib.next() 1 normal_fib.next() 2 normal_fib.next() 3 We can then create another one and ask that for values: normal_fib2 = configurable_fib(1,1) normal_fib.next(), normal_fib2.next() (5, 1) normal_fib.next(), normal_fib2.next() (8, 1) normal_fib.next(), normal_fib2.next() (13, 2) Or we can create a few, with unusual bases for the fibonacci sequence and find their first few values. Let's take the bases of 1 to 10. fibs = [ configurable_fib(x,x) for x in range(1,11) ] print [ x.next() for x in fibs ] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print [ x.next() for x in fibs ] [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] print [ x.next() for x in fibs ] [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] print [ x.next() for x in fibs ] [3, 6, 9, 12, 15, 18, 21, 24, 27, 30] print [ x.next() for x in fibs ] [5, 10, 15, 20, 25, 30, 35, 40, 45, 50] This shows that returning a generator *object* rather than just a value when you call the generator function is a useful behaviour, even if initially when learning generators it's slightly counter intuitive. One way to really understand them though is to try building something with a whole load of generators. For those purposes, I wrote a tutorial for our project which is based very much around having lots of generators. The tutorial is made up of a set of learning exercises: * http://kamaelia.sourceforge.net/MiniAxon/ We've tested this tutorial on a couple of novices at work (they learn python one week and get this tutorial the next), and they've found it relatively simple. The first hadn't done any programming before, except a small amount of VB - he was a pre-university trainee. The second was a university vacation
Re: new forum -- homework help/chit chat/easy communication
Fredrik Lundh wrote: snip Unlike mainstream component programming, scripts usually do not introduce new components but simply wire existing ones. Scripts can be seen as introducing behavior but no new state. /.../ Of course, there is nothing to stop a scripting language from introducing persistent state -- it then simply turns into a normal programming language. -- Clemens Szyperski, in Component Software: snip That description seems to describe whatever is written more than whatever it is written in, or in other words, it describes the difference between a script and a program, not between a scripting language and a programming language. I think that at one time, scripting languages was something that lived within other programs, like Office, and couldn't be used by themselves without running it inside that program, and as thus was a way to add minor functions and things to that program. Nowadays a lot of the scripting languages have turned programming languages so I think the difference is small. -- Lasse Vågsæther Karlsen http://usinglvkblog.blogspot.com/ mailto:[EMAIL PROTECTED] PGP KeyID: 0x2A42A1C2 -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Mike Meyer: Try qmail - it may solve the problem with a lot less work. I checked my .procmailrc, and saw that mail with qmail anywhere in the headers, goes to a spambox here. ;) -- Affijn, Ruudhttp://www.pandora.com/?sc=sh770781cmd=tunermini Gewoon is een tijger. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Steven D'Aprano wrote: I notice that type(some_closure) and type(ordinary_function) both return the same result, type 'function'. I also notice that both the closure and ordinary functions have an attribute func_closure. Is there a way to tell which is a closure and which is not? In my tests, the ordinary function has func_closure == None, but I don't know if that will always be the case of just for my tests. closure != function. (did you read the wikipedia page? the closure is a combination of the function code itself, the information needed to call it, and the context it was defined in. in Python, the full closure includes stuff you can reach via assorted attributes on the function object; most notably func_closure and func_globals) If I wanted to inspect the value of cache, where would I find it? nowhere. at least no officially; see Rebinding names in enclosing scopes in the design document for a discussion: http://www.python.org/peps/pep-0227.html That assumes that cache can be seen in this way. If it can't, is this a way to create really private variables in Python? no, because Python doesn't prevent you from digging into the internals: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440515 /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Here I am again, same old arguments
On Sun, 09 Oct 2005 07:02:52 +, CJ wrote: Okay, same program, different issue. Thanks to the help that I was given I was able to complete my program to find variables in a list that were repeated, and display them once, and how many times they appeared in the list. And it worked great! But, being the perfectionist that I am, I wanted to make the proggie allow any size of list, and not have to be recoded every time. So step one was to not make the program reliant on the list itself being of X length all the time. First off -- don't use a for loop with an index as you are doing. #setup variables grub=[3,25,3,5,3,a,a,BOB,3,3,45,36,26,25,a,3,3,3,bob,BOB,67] grubrpt=grub cntro=0 cntrt=0 rpt=0 skipped=0 You are doing too much manual work! Let Python do the lion's share of the work for you! #set up for variable length of grub ttllen=len(grub)-1 Why are you subtracting one from the length of the list? print The heck is this for loop doing? for point in range(0,ttllen,1): Using point as a loop index is generally a bad idea. The result coming from range is not a point, it is an integer, so why call it a point? You are also over-specifying the input arguments to range. If the step size is one, you don't need to specify it -- that's the default. You just make it harder to read, for no reason. Likewise the initial starting value of zero. Just use range(ttllen). This, by the way, will return a list [0, 1, 2, ... , length of list - TWO] because you already subtracted one from the length. print Here's Grub=,grub print And grubrpt=,grubrpt grubrpt[point]=blk As others have pointed out, grub and grubrpt are both names for the same list. Changing one changes the other. #Makes sure that there are not multiple prints. def alrdy_dn(grub,grubrpt): if grub[cntro] in grubrpt: Ew!!! Global variables!!! Bad programmer! No biscuit!!! *wink* Global variables are almost always a BAD idea. return grubrpt else: print grub[cntro],appears in list,rpt,times. grubrpt[grubrpt.index(blk)]=grub[cntro] return grubrpt This is a strange function. What exactly is it meant to do? It combines user interface (printing the number of times each item appears) and functionality (counting the number of times each item appears) and side effects (changing the list), before returning one of the input arguments again. At least two of those things (counting the items, and printing the results) should be separated into different functions for ease of comprehension. I'm going to skip the rest of your code, because I don't understand it and am too lazy, er, I mean busy, to spend the time trying to decipher it. Especially since the function you are trying to duplicate manually is so easy to do if you work with Python instead of against it. def count_item(L, item): Count the number of times item appears in list L. return L.count(item) Or wait... that's too easy :-) If you want to roll your own, then do it like this: def count_item(L, item): Count the number of times item appears in list L by reinventing the wheel. n = 0 for obj in L: if obj == item: n += 1 return n Notice that we don't change the list at any time. Why change it? That just adds complexity to our program and adds extra places to make bugs. Of which you have many :-) Now you use it like this: grub=[3,25,3,5,3,a,a,BOB,3,3,45,36,26,25,a,3,3,3,bob,BOB,67] for item in grub: n = count_item(grub, item) print item, appears in list, n, times. And you are done. No, not quite -- my code has a bug in it. You want to print the count for each *unique* item. Mine prints the count for each item, regardless of whether it is unique or not. So what we need to keep track of which items have been counted before. Here is one way of doing it: grub=[3,25,3,5,3,a,a,BOB,3,3,45,36,26,25,a,3,3,3,bob,BOB,67] already_seen = [] for item in grub: if item not in already_seen: n = count_item(grub, item) print item, appears in list, n, times. already_seen.append(item) Notice that rather than *deleting* from a copy of the original list, we *add* to a new list that started off empty. Here is another way: grub=[3,25,3,5,3,a,a,BOB,3,3,45,36,26,25,a,3,3,3,bob,BOB,67] unique_counts = {} # use a dictionary, not a list for item in grub: n = count_item(grub, item) unique_counts[item] = n for item, n in unique_counts.items(): print item, appears in list, n, times. The second version has a disadvantage that the objects in your list can't be lists themselves, because lists can't be keys of dictionaries. It also has what appears to be a disadvantage that it stores the item count in the dictionary, even if that count has already been stored. Wasted work! But wait... it might not be wasted. It takes work to test if your item has already been seen. That work might be more than it would take to just blindly store the
assigning in nested functions
Hi I have code # BEGIN CODE def test(): def x(): print a a=2 # *** a=1 x() print a test() # END CODE This code fails (on statement print a in def x), if I omit line marked ***, it works (it prints 1\n1\n). It look like when I assign variable in nested function, I cannot access variable in container function. I need to assign variable in container function, is any way to do this? Thanks a lot for your help Jena -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
On Sun, 09 Oct 2005 13:43:38 +0200, Fredrik Lundh wrote: Steven D'Aprano wrote: I notice that type(some_closure) and type(ordinary_function) both return the same result, type 'function'. I also notice that both the closure and ordinary functions have an attribute func_closure. Is there a way to tell which is a closure and which is not? In my tests, the ordinary function has func_closure == None, but I don't know if that will always be the case of just for my tests. closure != function. (did you read the wikipedia page? Yes I did. Did you read my post? If you create a closure, using a memoization technique as per the original post, and then call type() on that closure, Python reports type 'function'. If you use dir() on that closure-that-Python-calls-a-function, it tells you that there is an attribute func_closure. But ordinary functions that aren't closures also have that attribute. According to my tests, ordinary functions have None as the func_closure attribute, but I don't know if that will always be the case, or just the few examples I tested it. With a sample size of three, I have no confidence that I've found a bullet-proof test. Other that that, thank you for the links. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
If you create a closure, using a memoization technique as per the original post, and then call type() on that closure, Python reports type 'function'. Because it is. The closure is only sort of an extension to the locals() available to that function. Not more, not less. If you use dir() on that closure-that-Python-calls-a-function, it tells you that there is an attribute func_closure. But ordinary functions that aren't closures also have that attribute. Because there is no difference between them - a function _can_ have a closure, the same way a HttpRequest _can_ have POST-data or not. That doesn't make it different. You are of course right that one _could_ have implemented this with different classes. But as it happens, it isn't. According to my tests, ordinary functions have None as the func_closure attribute, but I don't know if that will always be the case, or just the few examples I tested it. With a sample size of three, I have no confidence that I've found a bullet-proof test. See this small testscript how to expose the closures content -- however I'm not familiar with the mechanics the bind some_variable to the cell-objects content. But actually I don't care... def closure_test(): some_variable = {} print %x % id(some_variable) def get(x): return some_variable[x] def set(x,v): some_variable[x] = v return get, set g, s = closure_test() s(10, 20) print g(10) print s.func_closure[0] Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: new forum -- homework help/chit chat/easy communication
Lasse Vågsæther Karlsen wrote: snip Unlike mainstream component programming, scripts usually do not introduce new components but simply wire existing ones. Scripts can be seen as introducing behavior but no new state. /.../ Of course, there is nothing to stop a scripting language from introducing persistent state -- it then simply turns into a normal programming language. -- Clemens Szyperski, in Component Software: snip That description seems to describe whatever is written more than whatever it is written in, or in other words, it describes the difference between a script and a program, not between a scripting language and a programming language. well, yes and no. it basically implies that if a language doesn't have the internal mechanisms required to implement persistent storage on its own, it's a scripting language. examples are shell languages, the Windows BAT language, javascript running in certain environments, and the myriad of application-specific command languages that were popular in the old days. Nowadays a lot of the scripting languages have turned programming languages so I think the difference is small. I think the trend is that when people are faced with a scripting problem (e.g. when they need command languages or other kinds of basic pro- grammability), it's no longer fashionable to invent yet another language. integrating an existing runtime is a lot easier. Tcl is an early example of a something that started as a reusable command language and turned into a real programming language along the way: http://www.tcl.tk/advocacy/tclHistory.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: assigning in nested functions
jena wrote: Hi I have code # BEGIN CODE def test(): def x(): print a a=2 # *** a=1 x() print a test() # END CODE This code fails (on statement print a in def x), if I omit line marked ***, it works (it prints 1\n1\n). It look like when I assign variable in nested function, I cannot access variable in container function. I need to assign variable in container function, is any way to do this? No. You can access them, but not rebind them. That's a crucial difference. So, if a contains a mutable, you can alter that: def test(): a = {foo: bar} def x(): a[foo] = pillepalle x() print a Or you return that value: def test() a = 10 def x(): return a * 10 a = x() Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: assigning in nested functions
jena wrote: I have code # BEGIN CODE def test(): def x(): print a a=2 # *** a=1 x() print a test() # END CODE This code fails (on statement print a in def x), if I omit line marked ***, it works (it prints 1\n1\n). It look like when I assign variable in nested function, I cannot access variable in container function. I need to assign variable in container function, is any way to do this? no. see Rebinding names in enclosing scopes in the design document for a discussion (and a workaround): http://www.python.org/peps/pep-0227.html /F -- http://mail.python.org/mailman/listinfo/python-list
Creating internet shortcuts
I've seen the python.faqts page: http://www.faqts.com/knowledge_base/view.phtml/aid/4475/fid/538 on how to create windows shortcuts using Python. Does anyone know if this be adapted to create internet shortcuts on windows? (as used for Favorites). Thank you, -- Richard -- http://mail.python.org/mailman/listinfo/python-list
Re: dis.dis question
Ron Adam wrote: Can anyone show me an example of of using dis() with a traceback? Examples of using disassemble_string() and distb() separately if possible would be nice also. [cliped] But I still need to rewrite disassemble_string() and need to test it with tracebacks. Cheers, Ron It seems I've found a bug in dis.py, or maybe a expected non feature. When running dis from a program it fails to find the last traceback because sys.last_traceback doesn't get set. (a bug in sys?) It works ok from the shell, but not from the program. Changing it to to get sys.exc_info()[2], fix's it in a program, but then it doesn't work in the shell. So I replaced it with the following which works in both. try: if hasattr(sys,'last_traceback'): tb = sys.last_traceback else: tb = sys.exc_info()[2] except AttributeError: raise RuntimeError, no last traceback to disassemble I'm still looking for info on how to use disassemble_string(). Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: new forum -- homework help/chit chat/easy communication
Lasse Vågsæther Karlsen [EMAIL PROTECTED] writes: Fredrik Lundh wrote: snip Unlike mainstream component programming, scripts usually do not introduce new components but simply wire existing ones. Scripts can be seen as introducing behavior but no new state. /.../ Of course, there is nothing to stop a scripting language from introducing persistent state -- it then simply turns into a normal programming language. -- Clemens Szyperski, in Component Software: snip That description seems to describe whatever is written more than whatever it is written in, or in other words, it describes the difference between a script and a program, not between a scripting language and a programming language. It also pretty solidly capture what a shell script does. I think that at one time, scripting languages was something that lived within other programs, like Office, and couldn't be used by themselves without running it inside that program, and as thus was a way to add minor functions and things to that program. That's certainly one kind of scripting language. But I don't think it's ever been the only kind - shells have always been stand-alone applications. What they have in common with your definition is that both types of languages are used to capture user actions for later repetition. And that's what makes a scripting language: it's a language in which one writes scripts that describe actions - normally taken by a user - so that a series of them can be performed automatically. For my take on the ontology of scripting languages, see URL: http://www.mired.org/home/mwm/scripting/what.html . mike -- 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: assigning in nested functions
jena [EMAIL PROTECTED] writes: # BEGIN CODE def test(): def x(): print a a=2 # *** a=1 x() print a test() # END CODE This code fails (on statement print a in def x), if I omit line marked ***, it works (it prints 1\n1\n). It look like when I assign variable in nested function, I cannot access variable in container function. I need to assign variable in container function, is any way to do this? No, this is a big bug in Python, there's no way to specify what scope you want. The compiler implicitly decides that since you set a to something inside x(), a must be a local variable. The principle that explicit is better than implicit was ignored here. There's a kludgy workaround which is to box the variable: def test(): def x(): print a[0] a[0] = 2 a = [1] print a[0] However, the arbiters of Python style would prefer that you use a class instance instead. -- http://mail.python.org/mailman/listinfo/python-list
Re: When someone from Britain speaks, Americans hear a British accent...
Steve Holden wrote: Steve Horsley wrote: [...] The one that always makes me grit my teeth is You have got to, don't you?. Well no, I do NOT got to, actually. Shudder! Shouldn't that be I don't have to got to? regards Steve Yes it should. -- http://mail.python.org/mailman/listinfo/python-list
Re: new forum -- homework help/chit chat/easy communication
Fredrik Lundh [EMAIL PROTECTED] writes: Tcl is an early example of a something that started as a reusable command language and turned into a real programming language along the way: Yes, that's why tcl is such an awful language. And it happens all the time. It's better to just start with a powerful language, e.g., Python, Guile, etc. From the Guile blurb: http://www.gnu.org/software/guile/guile.html#whatisit The true cost of doing it yourself == When you get to the point in your project where you need a scripting language or a configuration file format and reader, the normal course of things is to say ``I'll just do something clean and simple.'' This is a good decision. Adding a full programming language is just a distraction from your project. But simple languages don't seem capable of staying simple. For example, early releases of PHP, a language for generating web pages dynamically, enjoyed its minute memory footprint and simplicity. However over time PHP has grown, with the latest releases giving PHP an object system and other features that have grown it to a much larger size. Compare Tcl from its 1988 origins with the modern, sizable language. Broadly, the same progression has occurred with Perl. ... Guile has the fundamentals you need; you simply specialize it for your application. It has arrays and lists; modules; objects; and first-class functions. It has garbage collection --- which makes using Guile especially simple. Using Guile, your application has a full-featured scripting language right from the beginning, so you can focus your manpower on the novel and attention-getting parts of your application. -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
Fredrik Lundh a écrit : [EMAIL PROTECTED] wrote: These 3 intermediate variables used to improve readability can introduce bugs : you have to check that b, c and d are not used anywhere else in the code. if you have a fear of introducing new local variables, you have problems that cannot be solved by syntax. /F There's something i don't understand : I've posted the original message you reply to yesterday, but I still cannot see it in comp.lang.python, while I can see your reply, and my reply to your reply. I tried with two different providers to get the messages, but with the same result. Is it possible that this msg could have been throwned away by moderators of this list ?? But in this case, you wouldn't have been able to read it... Daniel delay -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Steven D'Aprano wrote: Yes I did. Did you read my post? given that the wikipedia page says a closure is an abstraction representing a function, plus the lexical environment (see static scoping) in which the function was created. and you're still focussing on type(function), it sure looks as if you missed certain parts of that explanation. let's take it again, with emphasis on some important words: a closure is an ABSTRACTION representing a function, PLUS the lexical ENVIRONMENT (see static scoping) in which the function was created. If you create a closure, using a memoization technique as per the original post, and then call type() on that closure, Python reports type 'function'. that's because closure is an abstract concept. there is no closure object in Python, just as there is no program object. function objects always con- tain all the information they need about their context, and the sum of that is what forms the closure. If you use dir() on that closure-that-Python-calls-a-function, it tells you that there is an attribute func_closure. But ordinary functions that aren't closures also have that attribute. ordinary functions also have closures: the global context is also part of the function's environment, and therefore part of the closure (in Python, it can be argued that all attributes of the function object are part of the closure) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
There's something i don't understand : I've posted the original message you reply to yesterday, but I still cannot see it in comp.lang.python, while I can see your reply, and my reply to your reply. I tried with two different providers to get the messages, but with the same result. Is it possible that this msg could have been throwned away by moderators of this list ?? But in this case, you wouldn't have been able to read it... It can be seen on gmane, but not with my news-reader. Apart from that, I don't think your proposal does any good - it is ugly (or at least not less ugly than the things you want to fix) and confuses the reader because of the colliding use of . for attribute access. E.g. your own example f(g(h(j(x))) becomes x.(j(?)).(h(?)).(g(?)).(h(?)) Not x.(j).(h).(g).(h), as you told us. And certainly way uglier than the above way of doing. Besides, you reasoning by comparing with the mathematical o-operator is misleading: the operator creates a new function, that will apply it's parametesr (e.g. f and g) after each other to the argument. Paul Rubin asked for ways to do that, and has been shown some ways to do so - actually not overly nice looking, but they'd allow for (f * g * h)(x) which beats your solution on readability, too :) Overall, it tries to obfuscate code - by creating perl-like magic variables. And that is not what Python is known for. I too have some convoluted constructs as your html-joining example. But if the get too complicated, replacing them by some explicit lines is better than trying to cough up a scheme that makes them work. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Steven D'Aprano [EMAIL PROTECTED] wrote or quoted: On Sun, 09 Oct 2005 07:19:29 +, Roedy Green wrote: Rich Teer [EMAIL PROTECTED]: WHat the hell has that got to do with HTML email? Sending photos is an example of what attachments are for. Normally you send photos to grandma with captions under each photo. No, normally YOU send photos to grandma with captions under each photo. My grandma doesn't put captions in her photo album, and she doesn't need captions on her photos in email. That is far more convenient for the technopeasant receiver than dealing with multiple attachments. Only if your photos are so obscure and confusing that they need captions. Here's Johnny with the dog. Here is Johnny with the dog again. This one is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog again -- that's the dog on the left, in case it isn't clear. Just for a change, this is Johnny wearing a hat. It is blue with a feather in it, in case you couldn't tell from, oh I don't know, looking at the actual picture. What have you got against captions? Giving photos captions is a *very* common practice. -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Mike Meyer [EMAIL PROTECTED] wrote or quoted: The technial problems have been solved for over a decade. NeXT shipped systems that used text/richtext, which has none of the problems that HTML has. The problems are *social* - you've got to arrange for people to use mail/news readers that understand a rich text format that isn't a vector for viruses. It's not HTML that has problems, it's Microsoft's crappy software. Writing virus-free HTML renderers is not hard - but of course Microsoft can still screw it up. Don't blame HTML for viruses - *every* document format Microsoft has anything to do with becomes a vector for viruses. They *even* managed to get virulent spreadsheets and word processor documents! -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Mike Meyer [EMAIL PROTECTED] wrote or quoted: Roedy Green [EMAIL PROTECTED] writes: Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html I talk around those problems. Actually, you present a design that forces a solution that makes them do what you want down their throats, never mind what they want, or what they've been doing. It shows an amazing ignorance about the internet and how people behave on it. Like most antispam proposals, it won't actually stop spam, just force spammers to concentrate on different channels. You seem to have randomly broken quoting for people who download mail and read it offline, and for any medium that's unreliable or doesn't reliably deliver messages in order - which includes mail and news. Virus writers will love the ability to change peoples address books remotely. Since - in Roedy's essay - messages are digitally signed, authority to advise about any email address updates would presumably be confined to those people with access to the sender's private key. Even /without/ any form of authentication, a standard change-of-address message - which is understood by mail readers - is a fine and sensible idea. -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
It seems to me that what you proposed was a solution, that seems obvious only to you, to a problem perceived only by you. I am afraid you would have to work rather harder to persuade me that there is a problem, let alone that you have found the solution to it. Hello, I never said there is a problem, since you can do whithout it. I just said that in some cases, it's better and cleaner to do it in another way, and also that this solution is a complement : it does not replace or break nothing. Regards, Al -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Tim Tyler wrote: snip Only if your photos are so obscure and confusing that they need captions. Here's Johnny with the dog. Here is Johnny with the dog again. This one is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog again -- that's the dog on the left, in case it isn't clear. Just for a change, this is Johnny wearing a hat. It is blue with a feather in it, in case you couldn't tell from, oh I don't know, looking at the actual picture. What have you got against captions? Giving photos captions is a *very* common practice. Perhaps he has a search engine that can find blue hats in an image and recognize people? -- Lasse Vågsæther Karlsen http://usinglvkblog.blogspot.com/ mailto:[EMAIL PROTECTED] PGP KeyID: 0x2A42A1C2 -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Roedy Green [EMAIL PROTECTED] wrote or quoted: Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html FYI, this bit: ``Like ICQ, someone cannot send you mail without your prior permission. They can't send you mail because they don't have your public key to encrypt the mail.'' ...is pretty confusing - because public key is a term with a technical meaning in cryptography - and a public key really *is* public. If you want to allow email only from a list of senders, then you use a simple white list. Cryptography is not needed or desirable if this is the intended goal. -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Paul Boddie [EMAIL PROTECTED] wrote or quoted: Roedy Green wrote: Just how long do you want to stall evolution? Do you imagine people 200 years from now will be still be using pure ASCII text unable to find a solution to JavaScript viruses (turn off JS), pop-up( disable popups) etc.? People in their sky-cars turning off JavaScript in their browsers: what a thought! Javascript can be turned off in *mail readers* - by their manufacturers. -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Mike Meyer [EMAIL PROTECTED] wrote or quoted: Roedy Green [EMAIL PROTECTED] writes: On Sat, 08 Oct 2005 19:56:50 -0400, Mike Meyer [EMAIL PROTECTED] wrote Show us *examples*! Do you create a style sheet for every site you visit that overrides there classes? What? Why don't you download a copy of Opera, see http://mindprod.com/jgloss/opera.html What makes you think I don't have a copy of Opera? Just so happens I've got a registred copy on my newest computer. Then try out the feature. Click View | style | user My copy of Opera doesn't have that menu entry. I suspect you're making platform-specific suggestions. Trying it on a different platform, it looks like it does what I said earlier: user mode simply disables the authors style sheets. None of the merging you suggested was going on is actually happening. The user mode uses style sheets you specify. There's a whole bunch of built-in ones - and you can cascade them: ``User style sheets ``There is also the inclusion of 12 packaged user style sheets and an easy menu application interface (View Style). These sheets can be cascaded together, with or without the page's styles. They are mostly for accessibility, accessible web design and plain coolness: Emulate text browser, Nostalgia, Accessibility Layout, Show images and links only, High contrast, Hide non-linking images, Disable tables and Use default forms design. There are also three style sheets that are worth mentioning specially: Hide certain-sized elements, Debug with outline, and Show structural elements. Hide certain-sized elements is basically that CSS-powered inline ad-killer that Eric A. Meyer came up with a few years ago. Debug with outline uses the newly added support for the outline property to display key elements. Finally, Show structural elements, which with the acrobatic use of generated content, attribute selectors and counters, shows the HTML tags inline, as well as the meta and link data, and a report on the number of font tags and nested tables. Now this is cool!'' - http://www.evolt.org/article/Opera_7_Released/1/54851/ -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
In comp.lang.java.programmer Mike Meyer [EMAIL PROTECTED] wrote or quoted: Roedy Green [EMAIL PROTECTED] writes: On Sat, 08 Oct 2005 17:41:38 -0400, Mike Meyer [EMAIL PROTECTED] wrote: If you've got a browser with a better solution, what's the browser, and what's the solution? Try Opera. You can merge the two. Merge the two CSS files? Most browsers do that - that's why they call them cascading style sheets. Got a sample style sheet that you use that prevernts authors from overriding things? Custom style sheets are usually applied after those in the document - when they are both being applied. That way, the custom style sheet has the final word. -- __ |im |yler http://timtyler.org/ [EMAIL PROTECTED] Remove lock to reply. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Steven D'Aprano wrote: On Sat, 08 Oct 2005 15:20:12 +0200, Lasse Vågsæther Karlsen wrote: Ok, so I thought, how about creating a decorator that caches the function results and retrieves them from cache if possible, otherwise it calls the function and store the value in the cache for the next invokation. This is what I came up with so far: def cache_function(fn): cache = {} def cached_result(*args, **kwargs): if args in cache: return cache[args] result = fn(*args, **kwargs) cache[args] = result return result return cached_result I'm curious... where does cache live after you use cache_function to memoize some function? It doesn't appear to be an attribute of the newly memoized function, nor does it look like a global variable. If I understand this correctly... if args in cache: Creates a local binding to the cache object that gets returned with the cashed_result function the same as... result = fn(*args, **kwargs) ... the function 'fn' does here. So they remain local bindings to objects in the scope they were first referenced from even after the function is returned. In effect, 'cache' and 'fn' are replaced by the objects they reference before the cached_result function is returned. Is this correct? Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
On Sun, 09 Oct 2005 14:27:32 +0200, Fredrik Lundh wrote: Steven D'Aprano wrote: Yes I did. Did you read my post? given that the wikipedia page says a closure is an abstraction representing a function, plus the lexical environment (see static scoping) in which the function was created. and you're still focussing on type(function), it sure looks as if you missed certain parts of that explanation. let's take it again, with emphasis on some important words: a closure is an ABSTRACTION representing a function, PLUS the lexical ENVIRONMENT (see static scoping) in which the function was created. If you create a closure, using a memoization technique as per the original post, and then call type() on that closure, Python reports type 'function'. that's because closure is an abstract concept. So are functions, modules, classes, instances, ints and strings. there is no closure object in Python, just as there is no program object. Clearly there is no DISTINCT closure object. If there were, I wouldn't need to ask how one can tell them apart, because type() would just report that one was a function and one was a closure. I don't have a problem with that. But read on... function objects always con- tain all the information they need about their context, and the sum of that is what forms the closure. If what you say is true, then all functions are closures, and closure is just a synonym for function, and there is no difference between a function and a closure. Then why bother to create the term? Clearly, whoever invented the term did so to distinguish the two. At a practical, Python level, there is a difference between a function before and after it gets made into a closure using, e.g. the original poster's memoization technique. In Python at least, it is not true that a function and a function-turned-into-closure is the same thing. See, for example, this:- def closefy(fn): ... def do_nothing(*args, **kwargs): ... return fn(*args, **kwargs) ... return do_nothing ... def spam1(): ... return 0 ... spam2 = closefy(spam1) spam1() 0 spam2() 0 spam2 is spam1 False spam1.func_closure is None True spam2.func_closure (cell at 0xf70a2734: function object at 0xf6e0a144,) hex(id(spam1)) '0xf6e0a144' In one case, the raw function has None stored in its func_closure attribute. In the other, it has a tuple containing at least one object of type cell. That cell object appears to contain a reference back to the original raw function. Now, I'll tell you what I think is going on: spam1() obviously has lexical scope, but that scope doesn't need to be saved with the function because it is implicitly understood by Python. The output of closefy(), on the other hand, has scope different from the normal Python scope. So its output has to package up enough information to re-create it's lexical scope in a cell object, and that gets stored in the output's func_closure attribute. So no, there is no abstract difference between a closure and a raw function, but there is a practical difference. Now perhaps in some other languages there is no practical difference either, but (as far as I can see) Python is not that language. Am I close? Here are another two code snippets that show something of what Python is doing:- def thingo(): ... def shrubbery(): ... return 0 ... return shrubbery ... spam3 = thingo() spam3() 0 spam3.func_closure is None True def thingy(): ... n = 0 ... def shrubbery(): ... return n ... return shrubbery ... spam4 = thingy() spam4.func_closure (cell at 0xf70a2b24: int object at 0x901a158,) -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 9 Oct 2005 13:44:42 GMT Tim Tyler [EMAIL PROTECTED] wrote: In comp.lang.java.programmer Roedy Green [EMAIL PROTECTED] wrote or quoted: Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html It's gone :-) FYI, this bit: ``Like ICQ, someone cannot send you mail without your prior permission. They can't send you mail because they don't have your public key to encrypt the mail.'' ...is pretty confusing - because public key is a term with a technical meaning in cryptography - and a public key really *is* public. If you want to allow email only from a list of senders, then you use a simple white list. Cryptography is not needed or desirable if this is the intended goal. But what is desirable is the possibility to authenticate the sender of the message as genuine, given the ease with which SMTP headers can be spoofed. Maybe this is suggested in Mr Green's essay, but cryptographically signed email (using the originator's _private_ key), where the signature and hence the originator of the mail can be verified independently, would be very useful. The problem is to get everyone to use digital signatures, and to ensure that such a signature can be linked to an individual or business. I've no illusions here. Take care, -- Stefaan -- As complexity rises, precise statements lose meaning, and meaningful statements lose precision. -- Lotfi Zadeh -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 13:36:26 +, Tim Tyler wrote: Since - in Roedy's essay - messages are digitally signed, authority to advise about any email address updates would presumably be confined to those people with access to the sender's private key. If I have the sender's private key, then I can pretend to be him. That would mean that when you received an email from the sender, you couldn't be sure if it actually came from him or not, thus defeating the purpose of having a private key. Even /without/ any form of authentication, a standard change-of-address message - which is understood by mail readers - is a fine and sensible idea. So any random person -- or bot -- could send an email to my business associates, telling them that my email address had changed to [EMAIL PROTECTED], please send all your confidential information directly there thank you very much. Yeah. Fine *and* sensible. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 13:44:42 +, Tim Tyler wrote: In comp.lang.java.programmer Roedy Green [EMAIL PROTECTED] wrote or quoted: Read my essay. http://mindprod.com/projects.html/mailreadernewsreader.html FYI, this bit: ``Like ICQ, someone cannot send you mail without your prior permission. They can't send you mail because they don't have your public key to encrypt the mail.'' ...is pretty confusing - because public key is a term with a technical meaning in cryptography - and a public key really *is* public. The term you want is wrong, not confusing. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Ron Adam wrote: In effect, 'cache' and 'fn' are replaced by the objects they reference before the cached_result function is returned. not really; accesses to free variables always go via special cell objects (rather than direct object references), and the compiler uses special byte codes for all accesses to such objects. this snippet illustrates the differences: def func1(): return a def func2(a): return a def wrapper(a): def func3(): return a return func3 def decode(func): import dis print func.__name__ + : dis.dis(func) print co_freevars =, func.func_code.co_freevars print func_closure =, func.func_closure print decode(func1) decode(func2) decode(wrapper(10)) if you run this on a recent version of Python, you get something like: func1: 2 0 LOAD_GLOBAL 0 (a) 3 RETURN_VALUE co_freevars = () func_closure = None func2: 5 0 LOAD_FAST0 (a) 3 RETURN_VALUE co_freevars = () func_closure = None func3: 9 0 LOAD_DEREF 0 (a) 3 RETURN_VALUE co_freevars = ('a',) func_closure = (cell at 0x0092C970: int object at 0x008A537C,) note the use of LOAD_DEREF for the variable access. Other opcodes include STORE_DEREF (that updates a local variable through a cell, used inside the defining scope), and MAKE_CLOSURE (which sets up the function object for functions that actually uses nested scopes; this is where the func_closure attribute is initialized). (now, if I weren't limited to plain text, I could have drawn a nice little diagram for you, but that's an entirely different thread...) /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 09 Oct 2005 15:50:12 +0200, Lasse Vågsæther Karlsen wrote: Tim Tyler wrote: snip Only if your photos are so obscure and confusing that they need captions. Here's Johnny with the dog. Here is Johnny with the dog again. This one is Johnny on his own. Here is the dog. Oh look, it is Johnny with the dog again -- that's the dog on the left, in case it isn't clear. Just for a change, this is Johnny wearing a hat. It is blue with a feather in it, in case you couldn't tell from, oh I don't know, looking at the actual picture. What have you got against captions? Giving photos captions is a *very* common practice. Perhaps he has a search engine that can find blue hats in an image and recognize people? Yes. It is called eyes. I look at the image, and miracle upon miracles, I recognise Johnny wearing a hat. Then, if I have any need to save that image rather than trash it, I name it and file it in a directory appropriately, so that I can instantly find it later without needing to call up a search engine. Honestly, anyone would think that photos and photo albums never existed before Google. Why force one particular bad technological solution on everyone for the sake of something which many people don't even perceive as a problem? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: [Info] PEP 308 accepted - new conditional expressions
On Fri, 7 Oct 2005 01:05:12 -0500, Terry Hancock [EMAIL PROTECTED] wrote: GvR's syntax has the advantage of making grammatical sense in English (i.e. reading it as written pretty much makes sense). I know, let's re-write Python to make it more like COBOL! That's bound to be a winner! -- Email: zen19725 at zen dot co dot uk -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
On Sun, 09 Oct 2005 13:43:38 +0200, Fredrik Lundh wrote: If I wanted to inspect the value of cache, where would I find it? nowhere. at least no officially; see Rebinding names in enclosing scopes in the design document for a discussion: http://www.python.org/peps/pep-0227.html That's interesting to read, and does clarify a few things that weren't straight in my head, but I notice that the author, Jeremy Hylton, distinguishes between Python creating function definitions that are closures from those that aren't: Each def or lambda expression that is executed will create a closure if the body of the function or any contained function has free variables. Presumably that means that if there are no free variables, no closure is created. That assumes that cache can be seen in this way. If it can't, is this a way to create really private variables in Python? no, because Python doesn't prevent you from digging into the internals: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440515 That's blackest voodoo, and as the warning says, could cause Python to sigfault if you get the opcodes wrong. I think that this is close enough to really private to satisfy most people. Maybe even Paul Rubin *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Steven D'Aprano wrote: let's take it again, with emphasis on some important words: a closure is an ABSTRACTION representing a function, PLUS the lexical ENVIRONMENT (see static scoping) in which the function was created. If you create a closure, using a memoization technique as per the original post, and then call type() on that closure, Python reports type 'function'. that's because closure is an abstract concept. So are functions, modules, classes, instances, ints and strings. they're hardly abstract; they all have distinct object implementations in the Python runtime. there's an include file and a main implementation file for each one of them, and you can access the type objects for each one of them from Python code. any implementation of Python has to implement them. there's no such thing for closures; they're the sum of a lot of different parts, all of which can be implemented in many different ways. If what you say is true, then all functions are closures, and closure is just a synonym for function, and there is no difference between a function and a closure. having something isn't the same thing as being something. if you replace function with function object, you get a bit closer to the truth. e.g. in this snippet def wrapper(a): def func3(): return a return func func and wrapper are functions, but if you call wrapper twice, you get two different function objects, each with it's own distinct closure. (to see this in action, take the snippet I posted in an earlier post and add f = wrapper(10); decode(f) f = wrapper(10); decode(f) to the end. this prints: func3: 9 0 LOAD_DEREF 0 (a) 3 RETURN_VALUE 4 LOAD_CONST 0 (None) 7 RETURN_VALUE co_freevars = ('a',) func_closure = (cell at 0x0083EE50: int object at 0x00798250,) func3: 9 0 LOAD_DEREF 0 (a) 3 RETURN_VALUE 4 LOAD_CONST 0 (None) 7 RETURN_VALUE co_freevars = ('a',) func_closure = (cell at 0x0083EDB0: int object at 0x0079A960,) ) same function, same code, different closures. (note that in CPython, functions only exist on the syntax level; when you writing something that you think is a function, the CPython com- piler will turn this into a code object and translate def to bytecode; the actual function object isn't created until you execute those byte- codes) At a practical, Python level, there is a difference between a function before and after it gets made into a closure using, e.g. the original poster's memoization technique. In Python at least, it is not true that a function and a function-turned-into-closure is the same thing. function or function object? all instances of the latter have a global en- vironment (func_globals), some also have default arguments (func_defaults), some also have references to nested scopes (func_freevars). all of them have all these attributes; that they're set to None when empty is just an memory optimization. spam1.func_closure is None True spam2.func_closure (cell at 0xf70a2734: function object at 0xf6e0a144,) hex(id(spam1)) '0xf6e0a144' In one case, the raw function has None stored in its func_closure attribute. In the other, it has a tuple containing at least one object of type cell. That cell object appears to contain a reference back to the original raw function. func_closure is the name of an attribute. it contains information about a certain part of a function object's closure (free variables in an existing outer scope), but, despite its name, it's not *the* closure. So no, there is no abstract difference between a closure and a raw function, but there is a practical difference. only if you're obsessed with CPython implementation details. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Continuous system simulation in Python
Hello Phil, I'm currently looking to see if I can build upon SimPy, thus making it an hybrid system simulator. That would be a great step for the community. Main difficulty would be to build a framework which isn't clumsy, like you said. I have close to no experience in Python and object oriented development, but I'm fairly advanced in C and procedural development, and of course in continuous sytem simulator. I'll keep you informed of my investigations... I've downloaded your zip files, but unfortunately I have no access to Windows. Are you able to send me only the sources ? Thanks in advance, *** REPLY SEPARATOR *** On 8 Oct 2005 21:36:05 -0700, [EMAIL PROTECTED] wrote : Nicholas, I have a particular interest in this subject as well. I've also used the Python/Scipy combination, and it is a tantalizing combination, but I found it to be a bit more clumsy than I'd like. Plus, my need for continuous-time simulation is not as great as it has been in the past. That said, I've been down this path before (see http://custom.lab.unb.br/pub/asme/DYNAMICS/BUFORD1.zip), and I would be interested in helping to develop something. I agree that Python would be a great foundation to build upon. -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Clearly there is no DISTINCT closure object. If there were, I wouldn't need to ask how one can tell them apart, because type() would just report that one was a function and one was a closure. I don't have a problem with that. But read on... function objects always con- tain all the information they need about their context, and the sum of that is what forms the closure. If what you say is true, then all functions are closures, and closure is just a synonym for function, and there is no difference between a function and a closure. Then why bother to create the term? Clearly, whoever invented the term did so to distinguish the two. You seem to still not getting to it: they aren't supposed to be distinguished - a function is a function. But it _can_ have a closure, which (shortly spoken) enriches it's local variables lookup. Speaking in terms of is a could be seen as some inheritance relation. Which functions and functions with a closure _could_ have if one wanted to. But that is true for other OO-concepts two. See below. At a practical, Python level, there is a difference between a function before and after it gets made into a closure using, e.g. the original poster's memoization technique. In Python at least, it is not true that a function and a function-turned-into-closure is the same thing. See, for example, this:- snip Nope. You mix things here. spam1 is a function. spam2 is actually bound to the function-object created by do_nothing - a function that has a closure because it is nested in closefy, and accesses variables from its outer lexical scope - thus i needs a closure. Part of do_nothing's closure is spam1 (or, better to say, the function reference that has been originally bound to spam1 - spam1 is just a name). Important is that the closure gets created at runtime, so each returned instance of do_nothing has its own. But the original spam1 implementation is untouched contrary to what you state above. It still is teh same thing, and has no closure. Consider this: class Foo(object): pass f = Foo() g = Foo() g.bar = whatever f and g are both Foo - but one has a different attribute set. And if Foo had some semantics that did something different based on bar, would you also say they're supposed have two different classes? You could in fact do that - create one class for each incarnation of possible state. But then the concept of classes and objects gets somewhat blurred, as each instance would have its own class. The same is true for functions. So no, there is no abstract difference between a closure and a raw function, but there is a practical difference. Now perhaps in some other languages there is no practical difference either, but (as far as I can see) Python is not that language. Am I close? Closer :) Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Steven D'Aprano wrote: Each def or lambda expression that is executed will create a closure if the body of the function or any contained function has free variables. Presumably that means that if there are no free variables, no closure is created. you're quoting selectively; the word closure isn't used anywhere in the design document except for a section that talks about flat closures, which is an implementation approach used in CPython (as the sentence before the one you quoted explains). I don't think it's necessarily a good idea to treat a reference to an algorithm and an attribute on an object in a specific implementation as the definition of an computer term... /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Steven D'Aprano wrote: On Sat, 08 Oct 2005 23:39:27 +, John Bokma wrote: Rich Teer [EMAIL PROTECTED] wrote: On Sat, 8 Oct 2005, Roedy Green wrote: Some people use email PRIMARILY for sharing photos. WHat the hell has that got to do with HTML email? The photo doesn't have to be included (as in attached)? with the email? I'll repeat the question: what do attachments have to do with HTML emails? His reply wasn't exactly clear, but I that he means that wen you use HTM mail, you don't have to attach the photo with the email. You can also use the HTML to refer to an image somewhere on a webserver. Doesn't seem such a good idea to me, since the possibility of external images gives spammers the possibility to track who opens their mails. -- If I have been able to see further, it was only because I stood on the shoulders of giants. -- Isaac Newton Roel Schroeven -- http://mail.python.org/mailman/listinfo/python-list
Re: What about letting x.( ... ? ... ) be equivalent to ( ... x ... )
Diez B. Roggisch a écrit : Apart from that, I don't think your proposal does any good - it is ugly (or at least not less ugly than the things you want to fix) and confuses the reader because of the colliding use of . for attribute access. There is no ambiguity ( in one case . is followed by a name, in another case it is followed by a parenthesis) but there is a similarity that I wanted and that I try here to illustrate : #** # Classical way : you need to evaluate # something for few instances of a class # so you write a mumber function #** class Rectangle : def area(self): return self.height * self.width ... (... an expression).area() #** # Alternative way : you need only once to evaluate something, # and you work on a big expression #** (... an expression).( this.height * this.width ) But one of the advantages of this syntax is the ability to compose very easily those expressions : (... an expression).(..expr 1..).(..expr 2..).(..expr 3..) etc... E.g. your own example f(g(h(j(x))) becomes x.(j(?)).(h(?)).(g(?)).(h(?)) Not x.(j).(h).(g).(h), as you told us. And certainly way uglier than the above way of doing. Besides, you reasoning by comparing with the mathematical o-operator is misleading: the operator creates a new function, that will apply it's parametesr (e.g. f and g) after each other to the argument. I agree the comparison to the mathematical o-operator is misleading, it was just to say sometimes, it can be usefull introduce new syntax to avoid too many nested parenthesis Paul Rubin asked for ways to do that, and has been shown some ways to do so - actually not overly nice looking, but they'd allow for (f * g * h)(x) which beats your solution on readability, too :) This is usefull when you need to compose few already defined functions, but I more often have to compose few expressions, which is the goal of my proposition. Overall, it tries to obfuscate code - by creating perl-like magic variables. And that is not what Python is known for. The wildcard ? does does not sound very pythonic, but a few too magic. Perhaps a keyword like this is better, that's what I used in the above example. In fact it has nothing to do with magical expression : this will represent the value of the current expression you work on, in the same way self represent the value of the object you work on. I too have some convoluted constructs as your html-joining example. But if the get too complicated, replacing them by some explicit lines is better than trying to cough up a scheme that makes them work. Regards, Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 9 Oct 2005, Roedy Green wrote: Normally you send photos to grandma with captions under each photo. That is far more convenient for the technopeasant receiver than dealing with multiple attachments. And even more convenient is Hey grandma, check out the latest photos on my web site: www.example.com/rich/photos. People keep thinking of email as a techie preserve. Worse, people keep misusing email. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
Tim Tyler wrote: Javascript can be turned off in *mail readers* - by their manufacturers. Yes, mail readers, browsers, combined mail reading and Web browsing suites, or whatever combination of functions you care to consider. In any case, in the not-exactly-unknown mail reader I use, I can't seem to find a setting that will turn JavaScript on. Meanwhile, HTML mail is flagged and presented as plain text with a prominent warning about viewing the message as HTML - an acceptable tradeoff which only slightly delays the viewing of the very few legitimate messages I get sent in that format. Of course, the most excitable manufacturers of mail readers with respect to enabling a rich experience are those pitching enterprise functionality, although a full treatment of their mistakes (amplifying my previous rant) would take this discussion even further away from the tenuous connection it has with Python, related discussions on type safety, private/protected/public, using Python in Mozilla, and the disappearance of the Bastion module notwithstanding. Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Jargons of Info Tech industry
On Sun, 9 Oct 2005, Roedy Green wrote: This is pulling a King Canute. There is not even a mechanism in email protocols to warn your correspondents of your demand. I have been Yes there is: the message my server sends someone sending me HTML says so quite plainly. That Outhouse (and presumably other WIndoze email clients) choses to not display the real message and put up some other generic, user friendly (but totally techie useless) message besides the point. There is nothing wrong with formatted text. You are confusing formatted text with spam. You think you hated formatted text, but you really hate spam. Please don't presume to think for me. I've been using email and the Internet for over 10 years, and I think I can differentiate between spam and formatted text. I hate spam, that's a given. But I hate spam that's in plain text as well as formatted text. I hate HTML email for several reasons, including: 1. it's wasteful of bandwidth 2. it enourages people to put form over content 3. it doesn't display properly on my email client of choice, which, BTW, I've been using in various versions for 10+ years. There are probably others, but you get my drift. You'll also notice that I deliberately didn't list the security issues. HTML is for web sites, not email. If your lover sent you a message with photo, and even musical accompaniment, I doubt you would feel offended. It is the CONTENT bugging you, not the HTML. No it isn't. And my wife knows better than to do that. When she sends me virtual boquets, she does so in the correctmanner: she sends me a plain text link to a web site that does all the fancy stuff, including background music. That is how it should be. You imagine that the two are inexplicably linked. That is just because No I don't. Eudora warns you of deceptive links in HTML. There are many more such I am fortuanate enough to not use Windoze. unfair to blame formatting for the foolish practice off allowing untrusted code to run without even an ok. They have nothing to do with each other. Agreed. But as I said above, I have many other issues with HTML emails, over and above the security concerns. -- Rich Teer, SCNA, SCSA, OpenSolaris CAB member President, Rite Online Inc. Voice: +1 (250) 979-1638 URL: http://www.rite-group.com/rich -- http://mail.python.org/mailman/listinfo/python-list
Re: [regex] case-splitting strings in unicode
John Perks and Sarah Mount wrote: I have to split some identifiers that are casedLikeThis into their component words. In this instance I can safely use [A-Z] to represent uppercase, but what pattern should I use if I wanted it to work more generally? I can envisage walking the string testing the unicodedata.category of each char, but is there a regex'y way to denote uppercase? In this form, it is currently not implemented, although it should be (written as [[:upper:]], I believe); contributions are welcome (make sure you read the Unicode consortium's guidelines on regular expressions before attempting to implement it). Until then, the best way is to use a regular character class, precomputed or computed at runtime. uni_upper = [unichr(i) for i in range(sys.maxunicode) if unichr(i).isupper()] uni_re = u[+u.join(uni_upper)+u] On my machine, this takes approximately one second to compute, which may or may not be too much as a startup cost. To speed this up, you could dump the resulting uni_re into a Python source file. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
Fredrik Lundh wrote: Ron Adam wrote: In effect, 'cache' and 'fn' are replaced by the objects they reference before the cached_result function is returned. not really; accesses to free variables always go via special cell objects (rather than direct object references), and the compiler uses special byte codes for all accesses to such objects. this snippet illustrates the differences: def func1(): return a def func2(a): return a def wrapper(a): def func3(): return a return func3 def decode(func): import dis print func.__name__ + : dis.dis(func) print co_freevars =, func.func_code.co_freevars print func_closure =, func.func_closure print decode(func1) decode(func2) decode(wrapper(10)) if you run this on a recent version of Python, you get something like: func1: 2 0 LOAD_GLOBAL 0 (a) 3 RETURN_VALUE co_freevars = () func_closure = None func2: 5 0 LOAD_FAST0 (a) 3 RETURN_VALUE co_freevars = () func_closure = None func3: 9 0 LOAD_DEREF 0 (a) 3 RETURN_VALUE co_freevars = ('a',) func_closure = (cell at 0x0092C970: int object at 0x008A537C,) note the use of LOAD_DEREF for the variable access. Other opcodes include STORE_DEREF (that updates a local variable through a cell, used inside the defining scope), and MAKE_CLOSURE (which sets up the function object for functions that actually uses nested scopes; this is where the func_closure attribute is initialized). (now, if I weren't limited to plain text, I could have drawn a nice little diagram for you, but that's an entirely different thread...) /F Thanks Fred, That's something useful to know when working with decorators I think. And it should answer Stevens question too. Abstract terminology is great once you already know the things and concepts it refers to. But if you don't, finding where the abstract connects to reality is sometimes not easy. There's nothing better than a good example to illistrate the concept. ;-) Cheers, Ron -- http://mail.python.org/mailman/listinfo/python-list
Re: Function decorator that caches function results
On Sun, 09 Oct 2005 18:00:13 +0200, Fredrik Lundh wrote: Steven D'Aprano wrote: Each def or lambda expression that is executed will create a closure if the body of the function or any contained function has free variables. Presumably that means that if there are no free variables, no closure is created. you're quoting selectively; the word closure isn't used anywhere in the design document except for a section that talks about flat closures, which is an implementation approach used in CPython (as the sentence before the one you quoted explains). Given that when I asked about closures, you pointed me at that document for further information, I thought maybe I could take it as authoritative. I don't think it's necessarily a good idea to treat a reference to an algorithm and an attribute on an object in a specific implementation as the definition of an computer term... Are you suggesting that Jeremy Hylton got it wrong? That's fine if he did, but it would help if you said so rather than beating around the bush. Is it correct to say that Python creates closures *ever*? Is it correct to say that Python creates closures when a def or lambda statement is executed? Is it correct to say that Python *always* creates a closure whenever a def or lambda is executed? Or is it only for *certain* defs/lambdas? Is it correct to talk about functions *having* closures, or that they *are* closures, or that the function is *part of* a closure? If all functions are closures, what does it mean to say that some languages (e.g. Java, C++, C#) don't have closures but merely simulate them? Are there any languages that don't have closures? Thanks for your patience, I'm sure I'll get there eventually. -- Steven. -- http://mail.python.org/mailman/listinfo/python-list