ANN: PyEnchant 1.1.5
Hi Everyone, I'm pleased to announce the release of PyEnchant version 1.1.5. This is a bugfix release to address some hangs when running on MS Windows. Specifically: * Fix hang in included MySpell (Windows distribution) * Workaround for some MySpell/unicode problems * Update to latest setuptools ez_setup.py Users of previous versions are encouraged to upgrade. Also, my attempts to announce version 1.1.4 on python-announce seem to have bounced, so I'm including the 1.1.4 ChangeLog below. Cheers, Ryan About: -- Enchant (http://www.abisource.com/enchant/) is the spellchecking package behind the AbiWord word processor, is being considered for inclusion in the KDE office suite, and is proposed as a FreeDesktop.org standard. It's completely cross-platform because it wraps the native spellchecking engine to provide a uniform interface. PyEnchant brings this simple, powerful and flexible spellchecking engine to Python: http://pyenchant.sourceforge.net/ It also provides extended functionality including classes for tokenizing text and iterating over the spelling errors in it, as well as a ready-to-use text interface and wxPython dialog. Current Version: 1.1.4 Licence: LGPL with exemptions, as per Enchant itself ChangeLog for 1.1.4: * No longer need to use the registry under Windows * Moved to setuptools for managing distribution * Registered at the Cheese Shop, with Eggs available for Windows users * Implemented unittest TestCases, works with `python setup.py test` * Plugins on Windows moved to enchant subdirectory * SpellChecker now coerces to/from unicode automatically * Use python default encoding rather than UTF-8 where appropriate * Various documentation cleanups * bug fixes: * (1230151): count of live instances done by normalized key * Accept unicode strings as broker orderings -- Ryan Kelly http://www.rfk.id.au | This message is digitally signed. Please visit [EMAIL PROTECTED]| http://www.rfk.id.au/ramblings/gpg/ for details signature.asc Description: This is a digitally signed message part -- http://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations.html
Re: web crawling.
S Borg wrote: Hello, I have been writing very simple Python programs that parse HTML and such, mainly just to get a better feel for the language. Here is my question: If I parsed an HTML page into all of the image files listed on that page, how could I request all of those images and download them into some specified folder? I am sure this is quite easy, but I am stuck. Thank you very much. Burgeoning Pythonista http://sig.levillage.org/?p=588 -- http://mail.python.org/mailman/listinfo/python-list
Re: Arithmetic sequences in Python
Op 2006-01-19, Alex Martelli schreef [EMAIL PROTECTED]: What should list(list(1,2,3)) be? Should list really work completely differently depending on whether it has a single arg or multiple args? It works just fine for max and min, why should list be different? Well IMO it works fine for max and min because people rarely want the minimum or maximum over a sequence of tuples or lists. But how would you make the following list: [(1,3)] As far as I understand that would have to become: list(((1,3),)) And [[3]] would have to become: list((list((3,)),)) In my opinion the bracket notation wins the clarity contest handsdown in this case and IMO these cases occure frequently enough. -- Antoon Pardon -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Shalabh Chaturvedi wrote: Tim the Taller (I presume he's taller; he's Dutch) and the other critics fail to realize is that no one reads content. I disagree completely. I wouldn't touch a new language or technology without first reading content. Neither would my boss, or any other manager for that matter. This is not a watch, a garment, a toothpaste or a burger. It is a software product, which needs a lot of content. The few words in captions should indeed be conveying the message. Which brings up a good question - what message does python.org want to convey? Is beta.python.org doing that? What puzzles me (and scares me) is that some people seem to think that anyone would go to python.org and expect a corporate fluff site. It's like when I asked a suit friend with long industry experience to check the python marketing list; his spontaneous reaction after reading some of the we must do this because non-programmers think like this discussion was one big WTF-are-these-guys-talking-about-why-do-they-hate-python ? The current site needs an incremental style overhaul, a less cluttered front page, and some signs that python.org's actually using modern Python tools for the site. And it needs to be more alive, both style-wise and content- wise. It does not need to treat its target audience (be it developers nor managers) as simpletons. Companies in the Python space don't do that, so why should python.org ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Roger Upole wrote: Alex Martelli [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Steven D'Aprano [EMAIL PROTECTED] wrote: ... I mean, when you read He sat on the chair do you need to look up the dictionary to discover that chairs can have arm rests or not, they can be made of wood or steel or uphostered springs, be on legs or coasters, fixed or movable? If it mattered, a good author will tell you, and if it doesn't matter, it doesn't matter. But if in their dialects of English chair strongly implies a hard, straight-backed, no-arms sitting-device, they won't elaborate, even if it DOES matter, exactly because it's already implied in the word they used. Not sure if this is true of any dialect of English, today, but it might be in Italian (for sedia, the exact translation of chair). So, you've just learned that He chose to sit in a chair rather than a sofa; depending on subtle nuances of the English dialect used (varying with time and space), this may have very different implications in defining the character and mood of this individual... Alex Hmm, and what if your context for chair was that unless you were to confess, you would be placed in a comfy one ? And furthermore, what if you were told that while in this chair thing, you would be seeing the sketch about the penguin on the telly ? Lets see, sketch means a rough line drawing, and the only telly I know of is Telly Savalas, but I'm fairly sure I know what a penguin is. So while in this chair I am to be shown a crudely drawn picture of a bald man with a fat flightless bird perched upon his overlarge head. Torture indeed . No, not the comfy chair! -- 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: New Python.org website ?
JW wrote: I don't agree. I read websites in search for information (content), not to find advertisements. Yes, and I read Playboy for the interviews ;) if you want the glossy stuff, go to python.com. In another post, you mention http://www.joelonsoftware.com/ which appears to be some sort of blog (the current bane of the internet). I immediately noticed something when visiting Joel using Firefox. **Scrollbars**. The page wouldn't even fit on the screen! I started to read it, but my face went numb before I needed to use the scrollbar. OK for blogging -- not so cool for a book cover. Of course, I'm a minimalist. minimalist? you sound like some guy who read a book about web design in the late nineties, and who've missed virtually everything that has happened since then. that's not minimalist, that's ignorant. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: 10060, 'Operation timed out'
Hi Steve, this is the trace I have got:- Traceback (most recent call last): File sumit1.py, line 39, in ? ftp.connect(host,port) File C:\programs\packages\python24\lib\ftplib.py, line 129, in connect raise socket.error, msg socket.error: (10060, 'Operation timed out') -- http://mail.python.org/mailman/listinfo/python-list
Re: Arithmetic sequences in Python
Antoon Pardon [EMAIL PROTECTED] writes: And [[3]] would have to become: list((list((3,)),)) In my opinion the bracket notation wins the clarity contest handsdown in this case and IMO these cases occure frequently enough. I'm convinced now. Until that, I could have gone either way. -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Shalabh Chaturvedi wrote: Tim Parkin wrote: Well apart from the front page and a couple of pages providing content specific to different types of usersm the whole site is the same as it was before. Do you have a problem with marketing python or with the content of the python site? Could you expand on why you think the beta site looks 'phony'? The pictures are too big, too many and in your face (boastful, as someone else mentioned). Even in most commercial product sites I see a single company name/logo or a single quote in a corner somewhere. For example www.ironport.com, www.informatica.com, www.basecamphq.com... One great open source site is www.postgresql.org. Everything including documentation has the same look and feel. I'm looking at it as someone who is skeptical or knows only little about Python. What? Google, NASA! (click, click.. nothing.. or a single quote) Bah! this is bogus. People want to know how something will help them and why should they use it. It would be awesome if we can pull all the pythonology success stories into python.org and link exactly one on the main page (again see www.postgresql.org). Anything less than a case study does not warrant a picture with a 'learn why..' on it. My gripes with the whole thing: 1. Learn why.., Learn why.., Learn more..? Unless each one takes you directly to a great success story, these should be removed. These will link directly to success stories. Good, but I think there should be only one with a smaller link to case studies and/or quotes. Python has been an important part of Google since the beginning, and remains so as the system grows and evolves. Today dozens of Google engineers use Python, and we're looking for more people with skills in this language. said Peter Norvig, director of search quality at Google, Inc. thats what it says on the old site right at the top of the page... So the google link on the home page should perhaps go to this quote instead of google.com. 4. I have a lot of respect for GvR, but there ought to be more advertising of the fact that the language is not supported by just one person. There is an great dev team behind it and a stable PSF organization. Anyone reading 'developed by one person' is not left with the fuzzy feeling of a mature, well-supported product that is here to stay. So you think we should add some copy that creates a more positive impression of python? Thanks for your suggestion to rewrite the copy regarding the team behind python. Could you come up with some alternative for this? Sure, I will work on this. Hopefully most of these will get fixed as people 'convert' the site and fill in content. I would urge people to do some 'user' testing - get persons not very familiar with Python and get their honest opinion on the site. We have done... The feedback was that some pictures would help engage people who view the website for the first time. This was especially true of non-programmers who may be assessing python as part of a business decition (who will probably not get further than the home page). I think logos might be more effective. Again with links to success stories with pull quotes highlighting Python's strengths. Pretty pictures by themselves don't do much. People want to know how it is different from other things, why it is better and *where* it is better. Most developers tended to want to jump straight into bookmarked parts of the site or just check the updated news. People wanting to learn about python would try to find a 'for beginners' link (hence the prominence of this). These links are very important. A couple of nitpicks about presentation: 1. Why are there two 'documentation' sections on the left? 2. Why does the 'about' section show 3 sub-headings on the main page, but grows to 6 when clicked? A summary of questions whose answers may help us: Do you have a problem with the way we are trying to 'market' python? I like that you are trying to market Python. I think the way it is being done may be ineffective, or worse, may backfire. Which content in particular do you have an objection to? The 3 edited (or stock?) pictures occupying majority of the real estate. Missing success stories or case studies. Could you expand on why you think the beta site looks 'phony'? See top of email. Could you tell me what about the site makes you think it looks 'cool' or 'flashy'? The big pictures are too flashy. The colors and fonts etc. give make it somewhat cool. Cool is a good thing. But not without content. Could you come up with some alternative for the intro copy about python? Sure. In fact I think the front page intro should be very minimal with 2 or 3 specifically targeted intros in the about section. Is the current www.python.org written in HTML? If not where can I get the source? Cheers, Shalabh The current site is mostly HTML, so you can use
Re: New Python.org website ?
Tim Parkin wrote: the design is alright (if a bit too bland business), but the little I've seen of the information architecture and the backend infrastructure feels like 1998 (which, I suppose, was when the project started...) Could you expand on why the backend infrastructure and information architecture feel like 1998? (it's a bit of an abstract comment and doesn't offer anything constructive). it's the kind of tools that people built around then: a bunch of text files, and a make-style build templating system. to use the tools, you log in to the web server via a back channel. An example of a site info architecture that feels like 2005 would be good. Also an example of a backend architecture that isn't like 1998 would be good too. anything that supports edit-though-the-web and does the final composition by composing HTML information sets would be more 2006. the easiest way to get there would be to use a MoinMoin instance to main- tain the content, and a separate renderer to generate static pages for the main site (possibly using Cheetah or Kid as template languages). /F -- http://mail.python.org/mailman/listinfo/python-list
Re: tools to manipulate PDF document?
Try reportlab PDF library (www.reportlab.org). Many things for graphs but also basic handling. Works fast reliably for my requirements. -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Steve Holden said unto the world upon 11/01/06 04:44 AM: http://beta.python.org A few minor points about the design: The Using Python for . . . for section on the right is expectation violating in several ways: 1) Each two lines have 3 separate links, but all go to the same place. Much better, I think, to make the entire two lines one link. 2) Alternating lines in slightly different colours briefly made me wonder if a visited/not visited distinction was being marked. The difference is also a bit too subtle; I wasn't entirely sure it was there at first. 3) The second line of every pair seems badly spaced, e.g. ServersPeer to Peer. (This is with Firefox 1.07 running on Linux.) 4) Even if the first and second lines are kept as separate parallel links, that there are two links in the second line, and that they break on subject seems wrong as the whitespace makes the link chunks and text chunks fail to coincide. None of that is critical, but all of it is a bit puzzling. A suggestion: I think it would be a good thing if the wiki were prominently linked somewhere. Perhaps not on the main page, but surely in somewhere such as the community or documentation navigation submenus. Best to all, Brian vdB -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website?
Obaid R. wrote: Steve Holden: The history of this choice is lost in the mists of time. Many other proposals were made and discussed at around the same time, to the extent that it became clear no one choice could win universal approval. You are the first person to my knowledge to point out that it is shaped like a cross. There is no significance in this shape. Is there, I ask with some trepidation, a specific point to this question? Thanks for the clarification. A pleasure. I hope it is not counted against me that I am the first one to point out that the logo is shaped like a cross. There might be many explanations for this; but sooner or later a person with a different background than the ones you knew would have likely noted the same. With that said, however, none of this affects the point that the logo is indeed shaped like I note. (Even the red cross of the International Committee of the Red Cross is shaped like a plus sign: http://www.icrc.org/). I suppose someone had to point it out, so the fact that you are the first certainly won't be held against you in *this* reader's mind anyway. And I cannot deny that the outline of the logo is that of a cross - there would be little point denying a simple truth. And why ask with any trepidation, Steve? People of different backgrounds have dissimilar sensitivities. I hope you agree that it would be unfair to blame people for such deeply personal affairs. If trepidation on the part of even the Red Cross was enough to cancel such sensitivities, we would not have had a Red Crescent or a cooperation between them. If not proving one's subscription to some set of beliefs, such symbols at least disprove the same for others. The trepidation was accounted for solely by a concern that Python would become involved in any kind of religious controversy, or that someone of extreme views might claim that Python was associated with, or against, a particular religious belief. Quite apart from the fact that language choice should not be a religious issue (:-), you are correct in saying that we must be mindful of sensitivities; as I mentioned, the outline of the logo hasn't been raised in the year since it was first mooted. I hope this doesn't mean we need *two* Python logos! I do realize that I have no say in the decisions affecting Python's current and future plans. But it makes sense to think that like any other marketed product, Python must take into consideration the nature of its target audience. And if it is to appeal to international users, then points of deep contention are better avoided. Don't you agree? I am glad the shape has no significance and I thank you for patience. Absolutely happy to help. You have as much say in Python's affairs as any other user, and are just as entitled to comment. I certainly wouldn't want to limit its popularity in any part of the world simply because of a poor choice of graphic. Perhaps when a further redesign is mooted we can ensure that corners are even more rounded ;-) 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: Can a simple a==b 'hang' in and endless loop?
Fredrik Lundh wrote: Dave Hansen wrote: Fuzzyman wrote: I'm not familiar with the C basic datatypes - I assume it has an array or list like object. Would it contain a sequence of poitners to the members ? In which case they would only be equal if the pointers are the same. In this case : a = ['some string'] b = ['somestring'] a == b False (probably) Incorrectly using Python syntax for a C example of course :-) That depends, the C syntax is like this : char *a=hello; char *b=hello; assert(a==b); // true, the compiler knows the two hello are the same and assign the same address(sort of id() in python) to a and b No. The C standard says the compiler is _allowed_ to re-use character literal constants, but is not _required_ to do so. I could have sworn that fuzzyman's example contained a literal string in an array, and an array comparision, so why are you talking about com- paring string literals ? a compiler for which char* a[] = { some string }; char* b[] = { some string }; ... if (a == b) printf(True\n); prints True is definitely broken. /F Exactly this is what Python does under the hood when writing a = some string b = some string where a and b are actually, in terms of C, pointer to Python object data structures which provide strings as arrays where it is possible to say a[0], but ... if here if(a==b): print True _does not_ print True, the Python engine is definitely broken. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: getopt.gnu_getopt: incorrect documentation
Giovanni Bajo wrote: Hello, The official documentation for getopt.gnu_getopt does not mention the version number in which it was introduced (so I assumed it was introduced back when getopt was added). This is wrong, though: I was informed that Python 2.2 does not have this function, and a quick google search turned up that its addition was mentioned in Python 2.3 release notes. This should be fixed in the documentation. Thanks! Giovanni: Sadly this post is unlikely to change anything. Can you please email the address shown in the documentation ([EMAIL PROTECTED]), or by using the Python bug tracker? 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: why is my hash being weird??
pycraze wrote: I do the following Steps to the .c file to create the .py file 1 cc -o s s.c 2 ./s (input) test.py 3 python test.py You are appending to the test file. How many times have you appended to it? Once? Twice? A dozen times? Just what is in the file test.py after all this time? When i run python to this .py file , i find that this process eats lots of virtual memory of my machine. I can give detailed examples to what heights can the virtual memory can go , when i do a top , with the inputs given to the c file 1. input is 10 VIRT is 119m The dictionary you create is going to be quite small: at least 780KB. Call it a megabyte. (What's a dozen or two K between friends?) Heck, call it 2MB. That still leaves a mysterious 117MB unaccounted for. Some of that will be the Python virtual machine and various other overhead. What else is there? Simple: you created a function summa with 10 lines of code. That's a LOT of code to go into one object. Normally, 100,000 lines of code will be split between dozens, hundreds of functions and multiple modules. But you've created one giant lump of code that needs to be paged in and out of memory in one piece. Ouch! def summa(): ... global hash ... hash[0] = 0 ... hash[1] = 1 ... import dis # get the byte-code disassembler dis.dis(summa) # and disassemble the function 3 0 LOAD_CONST 1 (0) 3 LOAD_GLOBAL 0 (hash) 6 LOAD_CONST 1 (0) 9 STORE_SUBSCR 4 10 LOAD_CONST 2 (1) 13 LOAD_GLOBAL 0 (hash) 16 LOAD_CONST 2 (1) 19 STORE_SUBSCR 20 LOAD_CONST 0 (None) 23 RETURN_VALUE That's how much bytecode you get for two keys. Now imagine how much you'll need for 100,000 keys. You don't need to write the code from C, just do it all in Python: hash = {} def summa(i): global hash for j in range(i): hash[j] = j import sys summa(sys.argv[1]) Now run the script: python test.py 10 -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Claudio Grondi wrote: Exactly this is what Python does under the hood when writing a = some string b = some string where a and b are actually, in terms of C, pointer to Python object data structures which provide strings as arrays where it is possible to say a[0], but ... if here if(a==b): print True _does not_ print True, the Python engine is definitely broken. Why are you comparing C behaviour to Python behaviour? What is the point of the discussion? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: Arithmetic sequences in Python
Alex Martelli wrote: I much prefer the current arrangement where dict(a=b,c=d) means {'a':b, 'c':d} -- it's much more congruent to how named arguments work for every other case. Would you force us to quote argument names in EVERY functioncall...?! Hmmm... should these two forms give different results? a = 0 b = 1 A = {a: b} B = dict(a=b) A, B ({0: 1}, {'a': 1}) I feel very uncomfortable about that. Am I alone? -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
Hello Steve, Roger and Pete, Nice to read your reply. Well, I can do an assert check for integers and then filter out hazardous SQL injection characters for varchars and do a direct substitution of the filtered values with the SQL statement. But by using ADO, input strings can be treated as what they are intended to be by adding values to the CreateParameter statement whe we do an Execute. This way I thought I need not care about what kind of input I get from the client, and I will be able to use them blindly to form a dynamic query. Thus producing a more general solution for SQL injection prone areas. Also, when it comes to filtering of hazardous characters, I think its better to allow only those characters one needs than to filter out SQL injection specific characters. But the problem is we have all kinds of special characters stored in our DB and filtering out characters will only result in wrong output. So, I have to rule out this case. With the DB API, yes I had a quick look at the code and the dynamic formation of the SQL statement does not seem to have support for IN statements. I am not sure about the LIKE statement though. Maybe, they do support it. So, I need to take a closer look at the adoapi.py file before concluding. To the concerned: value = '%raj%' select * from table_name where firstname LIKE '%s' % value works just fine, the result set contains all the first names that contains 'raj' How should we do this using createparameter in python? There should be a wasy toa chieve this in ADO using python. C# has a way to do this using ADO.Net. Please keep providing inputs, in the mean time I will also do some research on this problem and get back to you if I find a solution. Thanks! /Raja Raman -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Steve Holden wrote: This critique is all very well, but it tends to rely rather heavily on the words I think. You are, of course, entitled to your opinion, but please don't think that this new design was created on a whim. you keep saying that, but whenever the analysis that led up to the suggested approach (which is broken in multiple ways) was made, it wasn't very recently. what makes you so sure that what was perceived as correct among a small group of self-selected python marketers in 2002-2003 is still the best way to handle Python's most valuable web asset ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: tools to manipulate PDF document?
Thanks a lot tooper. I will check it out. - wcc -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Steven D'Aprano wrote: Claudio Grondi wrote: Exactly this is what Python does under the hood when writing a = some string b = some string where a and b are actually, in terms of C, pointer to Python object data structures which provide strings as arrays where it is possible to say a[0], but ... if here if(a==b): print True _does not_ print True, the Python engine is definitely broken. Why are you comparing C behaviour to Python behaviour? What is the point of the discussion? The point is to find a way to create in Python two indentifiers a and b without manipulating any of the __eq__ and to __eq__ related functions in a way, that the simple if a==b: print 'a==b' statement results in an endless loop. To my knowledge this is not possible to achieve in C, but is probably achievable in Python. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
This does not seem to work well Roger value = '%raj%' cmd.CommandText = select * from table_name where firstname LIKE ? result is 0 where I expected 4 /Raja Raman -- http://mail.python.org/mailman/listinfo/python-list
Re: 10060, 'Operation timed out'
Sumit Acharya wrote: Hi Steve, this is the trace I have got:- Traceback (most recent call last): File sumit1.py, line 39, in ? ftp.connect(host,port) File C:\programs\packages\python24\lib\ftplib.py, line 129, in connect raise socket.error, msg socket.error: (10060, 'Operation timed out') So the FTP server is refusing your connection, I suspect. There's no way the client can control the time it takes to do that. 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
Announcement Study Group Essentials of Programming Languages
Since there have been some interest, a reading group has been started at http://groups.yahoo.com/group/csg111 I must warn you that the programming language used in Essentials of Programming Languages is Scheme, which is variant of Lisp. Now this course is not a course in Scheme but about powerful programming techniques, but Scheme is used to illustrate many points. Also it can't harm to know a bit of Lisp. As Eric Steven Raymond said in How To Become A Hacker (http://www.catb.org/~esr/faqs/hacker-howto.html): LISP is worth learning for a different reason - the profound enlightenment experience you will have when you finally get it. That experience will make you a better programmer for the rest of your days, even if you never actually use LISP itself a lot. Cheers Bob -- This is a part of the Welcome mesage given at the link above Hello fellow programmers :) We are starting the virtual Principles of Programming Languages study group. The physical course is given at neu (short for Northeastern University) is described on http://www.ccs.neu.edu/course/csg111/index.html The course is starting 17:th January 2006. We, the unfortunate ones, which do not have the possibility to attend the physical course will study virtually at distance. The instructor at neu is Mitchell Wand, the co-author of Essentials of Programming Languages (EoPL for short), the textbook that will be used. The book is not free so you have to buy it :(. Edition 3 is not available but it's OK with edition 2. It seems that some material will be put on the neu web-site, and maybe it will be possible to follow along without the book, but I doubt it. The textbook is a classic. Here's what one reader (Ravi Mohan) of the book said: By the time you finish the book you will have built interpreters which demonstrate recursion, call-by-value/reference/need and name semantics, class based and prototype based OO, type inference, continuations etc . Very Hands on . You are taught how programming languages work by actually building intrepreters (in other words an Operational Semantics is used). This is the best way to learn . This is an incredible book and should be part of the library of every programmer interested in learning how languages work. As far as i know there isn't a single other book that can do better in conveying how various features of languages really work and interact . While this book may not be suitable for an undergraduate course of study (withoout an excellent teacher to help students get over the difficult bits) it is ideal for the self taught programmer. The reading group pace will be at least one week behind of the physical class. We do *not* want to discuss/share homework solutions until after the homework is due. That way students in the physical class won't be tempted to get answers from the reading group. If the professor has a problem with students getting answers on the Internet, then he might stop making his course public. -- http://mail.python.org/mailman/listinfo/python-list
Python on an embedded platform
Hi, I am looking to port Python to an embedded platform (an ARM7 device with fairly limited memory, capable of running an RTOS, but not an OS, such as Linux). I came across DePython from a few years ago, but it seems to have died a death. Does anybody have advice? I am looking for any tricks, features I can disable, etc so I can get the python core to be a small as possible (100k would be good). Thanks -- Derek -- http://mail.python.org/mailman/listinfo/python-list
Re: 10060, 'Operation timed out'
Ok, so need to see on the server side. -- http://mail.python.org/mailman/listinfo/python-list
Efficient implementation of deeply nested lists
I want to manipulate a deeply nested list in a generic way at a determined place. Given a sequence of constant objects a1, a2, ..., aN and a variable x. Now construct a list from them recursively: L = [a1, [a2, [[aN, [x]]...]] The value of x is the only one to be changed. With each value of x a new instance of L is needed so that we actually have a function: L = lambda x: [a1, [a2, [[aN, [x]]...]] I'm seeking for an efficient implementation that does not recompute the whole list each time. Any ideas? Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: tools to manipulate PDF document?
Yes, reportlad is a good tool for creating pdf and images -- http://mail.python.org/mailman/listinfo/python-list
Re: Arithmetic sequences in Python
Steven D'Aprano wrote: I much prefer the current arrangement where dict(a=b,c=d) means {'a':b, 'c':d} -- it's much more congruent to how named arguments work for every other case. Would you force us to quote argument names in EVERY functioncall...?! Hmmm... should these two forms give different results? a = 0 b = 1 A = {a: b} B = dict(a=b) A, B ({0: 1}, {'a': 1}) I feel very uncomfortable about that. Am I alone? yes. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Steven D'Aprano wrote: On Wed, 18 Jan 2006 15:29:24 +0100, Claudio Grondi wrote: The problem here is, that I mean, that in Python it makes no sense to talk about a value of an object, because it leads to weird things when trying to give a definition what a value of an object is. Python object: 1 The value of that Python object: the int 1 Python object 4.7 The value of that Python object: the float 4.7 Python object abc The value of that Python object: a string consisting of characters a, b and c. Python object [1, 4.7, abc] The value of that Python object: a list containing objects 1, 4.7 and abc. Where's the problem? My problem is, that I don't know if it is possible and if yes how to overwrite the __eq__() methods of the built-in types. With not built-in types I can do: class classWithWeirdEqualityBehaviour: def __init__(self, value) self.value = value def __eq__(self, other): return False a = classWithWeirdEqualityBehaviour(1) b = classWithWeirdEqualityBehaviour(1) a==b # gives False It seems, that in Python there is a lack of operator able to compare values as it is the case in C and Javascript, simply because in Python there are no really such things as values, so there is no need to compare them. 1 == 1 True 4.7 == 1 False Works for me. The higher level of abstraction/indirection in Python results in making the concepts of 'value', 'having a value' or 'comparing values' useless, where it helps in C to express the difference between address and content at that address and to distinguish between the information telling _what_ is stored in memory and the information about _where_ it is stored. In Python, you never care _where_ anything is stored. The id() function returns the unique ID of an object, which as an implementation detail may be the actual memory address, but that's just an implementation detail. In any case, given a memory address, you can't do anything with that knowledge. The question here is, if this a handicap or a welcome feature? From the one side I am glad that Python cares about memory allocation for me, but on the other side I have trouble to accept, that I have no direct access to the memory area where data are stored in order to manipulate them. Having this possibility would enormously speed up some conversions, because it were possible to get them down to a redefinition of the data structure without being forced to loop over the actual content or use a special extension library written in C for doing that. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem getting MoinMoin going
Howdy, I got it going--apparently, it's an incompatability between MoinMoin 1.5.0 and Python 2.3.4. Python 2.3.5 and greater works. There's a patch for MoinMoin 1.5.0 at : http://moinmoin.wikiwikiweb.de/MoinMoinBugs/DeepCopyError This will be included in all future MoinMoin releases, so it's only necessary for this particular Python/MoinMoin combination. Walter Gildersleeve Freiburg, Germany __ http://linkfrog.net URL Shortening Free and easy, small and green. -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Fredrik Lundh wrote: What puzzles me (and scares me) is that some people seem to think that anyone would go to python.org and expect a corporate fluff site. It's like when I asked a suit friend with long industry experience to check the python marketing list; his spontaneous reaction after reading some of the we must do this because non-programmers think like this discussion was one big WTF-are-these-guys-talking-about-why-do-they-hate-python ? If you'd followed the conversation, we actually asked a sample of non-programmers and a few company decision makers what there expectations were.. You may have seen a few ill informed comments on the python list (but tell me what list you can go on that doesn't). The current site needs an incremental style overhaul, a less cluttered front page, and some signs that python.org's actually using modern Python tools for the site. And it needs to be more alive, both style-wise and content- wise. Thats what we've done. It does not need to treat its target audience (be it developers nor managers) as simpletons. Companies in the Python space don't do that, so why should python.org ? I haven't got a clue what you are on about with the simpleton thing.. Is this related to another conversation it's the kind of tools that people built around then: a bunch of text files, and a make-style build templating system. to use the tools, you log in to the web server via a back channel. In most circles it is considered a 'good thing' that data is stored in a format that can be edited by hand. Of course we could have stuffed it all in a database or stored it as xml.. would this have been more 2006. anything that supports edit-though-the-web and does the final composition by composing HTML information sets would be more 2006. the easiest way to get there would be to use a MoinMoin instance to maintain the content, and a separate renderer to generate static pages for the main site (possibly using Cheetah or Kid as templateanguages). It would be apparent to you if you'd read around (even within this list) that the website is ultimately intended to have 'through the web' editing tools. You'd also know that one of the biggest acheivements so far is the separation of template from data from content so that 'information sets' actually exist in the first place. This also means that when someone designs a better template (as they may well do) it can be easily changed in the future. We also don't really want to have a proliferation of text formats and as a lot of the website is already written using restructured text, this is the format thats been recommended. A wiki is not a website and to try to shoehorn a wiki into a content management system is not a good final goal. We are adding facilities to use the wiki to manage some pages in near future as part of migration. However, the priority was to do certain things first. 1) Separate content from data from presentation is as complete a way as possible (for which nevow templates, which contain no programmatic componenets are suitable). 2) Ensure that the system is usable using basic text editing tools 3) Build the website using the latest techniques ensuring accessibility and usability. The site is XHTML and uses CSS for layout. It also offers legacy style sheets for netscape and has been tested in speech readers and text browsers. how quaint.. 4) Needed someone to actually do something The last item seems to be the one that has hit the most hurdles. As I remember you were a member of the marketing list and have had many opportunities to contribute constructively at planning time. If you could choose to be constructive in either offering useful changes that would make sense at this point in time or offereing to provide help that would be greatly appreciated. I'm afraid I won't be able to respond at length to any more posts.. There is still a lot of work to be done to get the website live. Tim Parkin -- http://mail.python.org/mailman/listinfo/python-list
Re: Being unjust
Paul Boddie wrote: Adrian Holovaty wrote: Fuzzyman wrote: web.py has the great advantage that (allegedly) you can migrate apps from CGI to FastCGI, mod_python, WSGI. This isn't an advantage of web.py over other frameworks. You can do the same thing with Django, because it has a WSGI backend; people run Django with mod_python, FastCGI, etc. I believe the same flexibility applies to TurboGears. Generally, most frameworks now seem to offer *CGI, either via or in addition to WSGI. (One could uncharitably refer to WSGI as one of the *CGIs, I suppose.) Other server support generally seems to be a bonus, although I note that some WSGI implementations are attempting to support something more exotic than the *CGIs. Meanwhile, the main thing web.py has going for it is brevity - it otherwise seems like a fairly ad-hoc mash-up of various full stack components whose standard library inclusion would probably leave many other framework developers howling in protest (and not without reason, either). And given that some in the Python community squeal when software is made available to them under something other than a permissive MIT-style licence, I would honestly wonder what those people would make of web.py's licence. There are a few fundamental philosophy differences in web apps which makes it a bit of a religious war. This means getting something into the standard library is likely to be the cause of intractable discussions. *sigh* As much as I'd like to see the core bits of Django (which wouldn't require a database or include other fancy high-level features) included in the standard library, I do think it'd devolve into a religious war inevitably. Here's my biased perception of the Web-SIG process, since any standardisation discussion supposedly starts there: first, everyone attempts to nail down request and response objects, reaching no particular consensus; then, the WSGI specification gets discussed for seven or eight months; then, everyone panics at the sight of the Rails juggernaut [1]; finally, I unsubscribe, but the archives seem to suggest a range of not-particularly-convincing attempts at moving the original cause forward. But with regard to the standard library, here's an interesting quote from a Web-SIG posting back in 2004: I suspect that most web frameworks will bypass the 'cgi' module as much as possible; it's too messy to deal with and too difficult to clean up. [2] Sadly, most frameworks (in my experience in wrapping them up under a layer of cleaner functionality) do use the cgi module in some way or other, and I'd argue (and I believe always argued) that the best route forward would be to wean everyone off using that module directly in applications/frameworks and onto something more abstract and easier to use, possibly whilst tidying up the cgi module and making sure it works reliably for all the low-level parsing that it's still going to be responsible for doing. Sadly, WSGI hasn't addressed this issue at all, as far as I am aware: it just lets the frameworks battle it out at a marginally higher level. Funny reading ! I don't want to know what happens when the BDFL gets hitten by a bus ;) A pro pos BDFL. Citing his recent blog entry on Artima seems to indicate that religious wars will sooner or later be inevitable: I actually don't think Google uses Zope (contradicting my own statement above! :-). I just spoke to Mark Shuttleworth who also expressed concern about the lack of a de-facto standard Python web framework. I hope to be working on this issue somewhat, but it'll take a long time, and I doubt it'll involve open-sourcing Google code that is curently proprietary. From: GvR: Re: Python Status Update Posted: Jan 13, 2006 4:30 PM http://www.artima.com/forums/flat.jsp?forum=106thread=143947 -- http://mail.python.org/mailman/listinfo/python-list
Re: web crawling.
Use BeautifulSoup to get all the image tags out of the html. You'll need to join the urls of the images to the url of the page (urlparse.urljoin off the top of my head). If you look at BeautifulSoup you will see how to get the 'src' reference of each image tag. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: Determine the IP address of an eth interface
[billie] | Hi all. I'm searching for a module that permits me to | low-level interact | with ethernet interfaces of my system. | I would like to determine at least the first of the followings values: | | 1 - IP address assigned to the interface | 2 - subnet mask | 3 - default gateway | 4 - primary and secondary dns | 5 - default wins server | 6 - mac address | 7 - broadcast address Not a cross-platform solution (I doubt if there is one, strictly) but you can use WMI on win32 to get most of what you want. I'm not sure about the broadcast address, but some Googling around might help to solve that: (wmi module from http://timgolden.me.uk/python/wmi.html) code import wmi c = wmi.WMI () for eth in c.Win32_NetworkAdapterConfiguration (IPEnabled=True): print eth /code TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Fredrik Lundh wrote: Steve Holden wrote: This critique is all very well, but it tends to rely rather heavily on the words I think. You are, of course, entitled to your opinion, but please don't think that this new design was created on a whim. you keep saying that, but whenever the analysis that led up to the suggested approach (which is broken in multiple ways) was made, it wasn't very recently. what makes you so sure that what was perceived as correct among a small group of self-selected python marketers in 2002-2003 is still the best way to handle Python's most valuable web asset ? We're not but they were the only people that were bothered to do anything.. If I remember, you were one of the people that had an opportunity to contribute but didn't... As for self selected, anybody was free to join and help and it was even posted to the mailing list and mentioned on numerous blogs. How about designing a website and showing us what you think would be a good idea? Or suggesting some way of managing all of the content and building the system. Or taking a screenshot of what is there and modifying it to show how you would like it changed. You are coming across has having a chip on your shoulder about something but you are not being clear exactly what it is? Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: getopt.gnu_getopt: incorrect documentation
Steve Holden wrote: The official documentation for getopt.gnu_getopt does not mention the version number in which it was introduced (so I assumed it was introduced back when getopt was added). This is wrong, though: I was informed that Python 2.2 does not have this function, and a quick google search turned up that its addition was mentioned in Python 2.3 release notes. This should be fixed in the documentation. Thanks! Giovanni: Sadly this post is unlikely to change anything. Can you please email the address shown in the documentation ([EMAIL PROTECTED]), or by using the Python bug tracker? Sure, I'll use e-mail. My previous attempt at using the Python bug tracker was a failure (totally ignored after years) so I'm keen on trying some other way. Thanks! -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Determine the IP address of an eth interface
billie wrote: Hi all. I'm searching for a module that permits me to low-level interact with ethernet interfaces of my system. I would like to determine at least the first of the followings values: 1 - IP address assigned to the interface 2 - subnet mask 3 - default gateway 4 - primary and secondary dns 5 - default wins server 6 - mac address 7 - broadcast address On python cookbook I found this usefuls script that returns the IP address of a specified interface but it only works on unix platforms. I was wondering if exist a specific module that could solve this kind of problems. Best regards. import socket import fcntl import struct def get_ip_address(ifname): s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) return socket.inet_ntoa(fcntl.ioctl( s.fileno(), 0x8915, # SIOCGIFADDR struct.pack('256s', ifname[:15]) )[20:24]) get_ip_address('lo') '127.0.0.1' get_ip_address('eth0') '38.113.228.130' On win... you may call ipconfig: os.popen('ipconfig /all','r') - if ipconfig on your default path, otherwise specify full path - and retrieve the information you want from the output. Have fun Michael -- http://mail.python.org/mailman/listinfo/python-list
Re: tools to manipulate PDF document?
have you seen http://www.pdfhacks.com/pdftk/ -- http://mail.python.org/mailman/listinfo/python-list
Multiple modules with database access + general app design?
Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules (replacement for PHP's include() statement). My problem is, in PHP if you open a database connection it's always in scope for the duration of the script. Even if you use an abstraction layer ($db = DB::connect(...)) you can `global $db` and bring it in to scope, but in Python I'm having trouble keeping the the database in scope. At the moment I'm having to push the database into the module, but I'd prefer the module to bring the database connection in (pull) from its parent. Eg: import modules modules.foo.c = db.cursor() modules.foo.Bar() Can anyone recommend any cleaner solutions to all of this? As far as I can see it, Python doesn't have much support for breaking down large programs in to organisable files and referencing each other. Another problem is I keep having to import modules all over the place. A real example is, I have a module webhosting, a module users, and a module common. These are all submodules of the module modules (bad naming I know). The database connection is instantiated on the db variable of my main module, which is yellowfish (a global module), so get the situation where: (yellowfish.py) import modules modules.webhosting.c = db.cursor() modules.webhosting.Something() webhosting needs methods in common and users: from modules import common, users However users also needs common: from modules import common And they all need access to the database (users and common) from yellowfish import db c = db.cursor() Can anyone give me advice on making this all a bit more transparent? I guess I really would like a method to bring all these files in to the same scope to make everything seem to be all one application, even though everything is broken up in to different files. One added complication in this particular application: I used modules because I'm calling arbitrary methods defined in some XML format. Obviously I wanted to keep security in mind, so my application goes something like this: import modules module, method, args = getXmlAction() m = getattr(modules, module) m.c = db.cursor() f = getattr(m, method) f(args) In PHP this method is excellent, because I can include all the files I need, each containing a class, and I can use variable variables: ?php $class = new $module; // can't remember if this works, there are // alternatves though $class-$method($args); ? And $class-$method() just does global $db; $db-query(...);. Any advice would be greatly appreciated! Cheers -Robin Haswell -- http://mail.python.org/mailman/listinfo/python-list
Re: Returning a tuple-struct
[EMAIL PROTECTED] wrote: time.localtime() (2006, 1, 18, 21, 15, 11, 2, 18, 0) time.localtime()[3] 21 time.localtime().tm_hour 21 Anyway, I guess there's a few of ways to do this. In the case above, it would seem reasonable to override __getitem__() and other things to get that result. I have a generic solution for this (never submitted to the cookbook... should I?) import operator def NamedTuple(*args, **kwargs): class named_tuple_class(tuple): pass values = [] idx = 0 for arg in args: for name in arg[:-1]: setattr(named_tuple_class, name, property(operator.itemgetter(idx))) values.append(arg[-1]) idx += 1 for name,val in kwargs.iteritems(): setattr(named_tuple_class, name, property(operator.itemgetter(idx))) values.append(val) idx += 1 return named_tuple_class(values) t = NamedTuple((x, 12), (y, 18)) t (12, 18) t[0] 12 t.x 12 t[1] 18 t.y 18 t.z Traceback (most recent call last): File stdin, line 1, in ? AttributeError: 'named_tuple_class' object has no attribute 'z' t = NamedTuple((p, pos, position, 12.4)) t (12.4,) t.p 12.4 t.pos 12.4 t.position 12.4 t = NamedTuple((p, pos, 12.4), length=foo) t (12.4, 'foo') t.p 12.4 t.pos 12.4 t.length 'foo' -- Giovanni Bajo -- http://mail.python.org/mailman/listinfo/python-list
Re: Retrieve a GIF's palette entries using Python Imaging Library (PIL)
Stuart wrote: I see that the 'Image' class has a 'palette' attribute which returns an object of type 'ImagePalette'. However, the documentation is a bit lacking regarding how to maniuplate the ImagePalette class to retrieve the palette entries' RGB values. ImagePalette.getdata() should do it. There seems to be some kind of bug, however, where Images lose their ImagePalettes after being convert()ed to paletted images (eg. using Image.ADAPTIVE). For this reason I personally use the getpalette() method from the wrapped image object, which seems to contain the proper raw palette data. For example to get a list of [r,g,b] colour lists: def chunk(seq, size): return [seq[i:i+size] for i in range(0, len(seq), size)] palette= image.im.getpalette() colours= [map(ord, bytes) for bytes in chunk(palette, 3)] -- And Clover mailto:[EMAIL PROTECTED] http://www.doxdesk.com/ -- http://mail.python.org/mailman/listinfo/python-list
Decimal vs float
I wonder why this expression works: decimal.Decimal(5.5)**1024 Decimal(1.353299876254915295189966576E+758) but this one causes an error 5.5**1024 Traceback (most recent call last): File interactive input, line 1, in ? OverflowError: (34, 'Result too large') Another quirk is the follwoing: decimal.Decimal(5.5) Traceback (most recent call last): ... TypeError: Cannot convert float to Decimal. First convert the float to a string If Mr. interpreter is as slick as he is why doesn't he convert the float by himself? This is at most a warning caused by possible rounding errors of float. Instead of dealing with awkward wrappers, I wonder if literals currently interpreted as floats could not be interpreted as Decimal objects in future? Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Tim Parkin wrote: How about designing a website and showing us what you think would be a good idea? Or suggesting some way of managing all of the content and building the system. I think I just did that: the easiest way to get there would be to use a MoinMoin instance to main- tain the content, and a separate renderer to generate static pages for the main site (possibly using Cheetah or Kid as template languages). to which you responded A wiki is not a website and to try to shoehorn a wiki into a content manage- ment system is not a good final goal. which is an interesting thing to say at a time when wikipedia has joined google and blog as the internet things that everyone has heard about... Or taking a screenshot of what is there and modifying it to show how you would like it changed. I have opinions about the backend, and you're turning it into a front- page design issue ? or did you wonder what the backend could look like ? http://moinmoin.wikiwikiweb.de /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal vs float
Kay Schluehr wrote: I wonder why this expression works: decimal.Decimal(5.5)**1024 Decimal(1.353299876254915295189966576E+758) The result is a Decimal type, which can have *very high* values. but this one causes an error 5.5**1024 Traceback (most recent call last): File interactive input, line 1, in ? OverflowError: (34, 'Result too large') Because the result is a float, which values are limited by your hardware (CPU). Another quirk is the follwoing: decimal.Decimal(5.5) Traceback (most recent call last): ... TypeError: Cannot convert float to Decimal. First convert the float to a string If Mr. interpreter is as slick as he is why doesn't he convert the float by himself? This is at most a warning caused by possible rounding errors of float. floating points are always imprecise, so you wouldn't want them as an input parameter for a precise Decimal type. Because if your nice Decimal type would then look like this: Decimal(5.499) you would complain too, right? For more enlightenment, you can start with the PEP http://www.python.org/peps/pep-0327.html#explicit-construction Instead of dealing with awkward wrappers, I wonder if literals currently interpreted as floats could not be interpreted as Decimal objects in future? No, because a software Decimal type is orders of magnitude slower than floating point types, for which there is hardware support by your CPU. If you're asking for additional Python decimal literals like mydecimal = 5.5d or whatever, that's a different question. I don't know if anything like this is planned. FWIW I don't think it's necessary. using the Decimal constructor is explicit too and we don't really need syntactic sugar for decimal literals. -- Gerhard -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient implementation of deeply nested lists
Kay Schluehr wrote: I want to manipulate a deeply nested list in a generic way at a determined place. Given a sequence of constant objects a1, a2, ..., aN and a variable x. Now construct a list from them recursively: L = [a1, [a2, [[aN, [x]]...]] The value of x is the only one to be changed. With each value of x a new instance of L is needed so that we actually have a function: L = lambda x: [a1, [a2, [[aN, [x]]...]] I'm seeking for an efficient implementation that does not recompute the whole list each time. Any ideas? Is the sequence of a1 to aN fixed ? I assume you want a new list each time ? You can create a reference list once but keep a reference to the most deeply nested part that contains x. Each time you need a new copy, insert hte new value of x and use copy.deepcopy to produce your new list. ***WARNING UNTESTED def listmaker(consts, x): global finalref out = [] if not consts: finalref = [x] return finalref entry = consts.pop() out.append(entry) out.append(listmaker(consts, x)) return out listmaker recursively builds the list structure and creates a global reference to the list holding x. You can build this once as a 'generic' list. When you need a copy do : del finalref[0] finalref.append(newx) newlist = copy.deepcopy(reference_list) I hope that helps, it may need debugging. :-) Because lists are mutable, you can't avoid the copy operation - but it is *probably* quicker than recomputing hte list. You should test this - as it might not be the case. Fuzzyman http://www.voidspace.org.uk/python/index.shtml Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Paul Rubin wrote: For an absolutely amazing translation feat, try Michael Kandel's Polish-to-English translation of Stanislaw Lem's The Cyberiad. Returning to the original book, why did they write a lot of it (at least the first few pages until I gave up, after having trouble understanding formulas about concepts I have no such trouble with when framed in less jargonized from) in unintelligible mathemathical notation when there's Python? I prefer a nice Python function over some strange latech symbols. If not Python there's always pseudo code or good old natural language. Don't tell me those math formulas are what it 'really' is, or even that it's more precise that way. The old trick of 'but there are some things that cannot be expressed in any other way than by using formulas' doesn't get one many optimization points in my world. Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Claudio Grondi wrote: Steven D'Aprano wrote: Claudio Grondi wrote: Exactly this is what Python does under the hood when writing a = some string b = some string where a and b are actually, in terms of C, pointer to Python object data structures which provide strings as arrays where it is possible to say a[0], but ... if here if(a==b): print True _does not_ print True, the Python engine is definitely broken. Why are you comparing C behaviour to Python behaviour? What is the point of the discussion? The point is to find a way to create in Python two indentifiers a and b without manipulating any of the __eq__ and to __eq__ related functions in a way, that the simple if a==b: print 'a==b' statement results in an endless loop. To my knowledge this is not possible to achieve in C, but is probably achievable in Python. So finally we understand what you are looking for (though not why ...). a = [1] a.append(a) a [1, [...]] b = [1] b.append(b) a == b Traceback (most recent call last): File stdin, line 1, in ? RuntimeError: maximum recursion depth exceeded in cmp Is this what you seek? Not quite an endless loop, but probably as close as you are going to get given the necessariliy recursive data structures required to induce 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: Can a simple a==b 'hang' in and endless loop?
Claudio Grondi wrote: Steven D'Aprano wrote: [...] The higher level of abstraction/indirection in Python results in making the concepts of 'value', 'having a value' or 'comparing values' useless, where it helps in C to express the difference between address and content at that address and to distinguish between the information telling _what_ is stored in memory and the information about _where_ it is stored. In Python, you never care _where_ anything is stored. The id() function returns the unique ID of an object, which as an implementation detail may be the actual memory address, but that's just an implementation detail. In any case, given a memory address, you can't do anything with that knowledge. The question here is, if this a handicap or a welcome feature? A welcome feature, absolutely no doubt about it. From the one side I am glad that Python cares about memory allocation for me, but on the other side I have trouble to accept, that I have no direct access to the memory area where data are stored in order to manipulate them. Having this possibility would enormously speed up some conversions, because it were possible to get them down to a redefinition of the data structure without being forced to loop over the actual content or use a special extension library written in C for doing that. Well, if this isn't a case of premature optimization I've never seen one. You apparently haven't yet written a single line of your appliction, yet you are already concerned about its efficiency. 1. First, make it work. 2. Then, if it doesn;t work fast enough, make it work faster. 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: how to find not the next sibling but the 2nd sibling or find sibling a OR sinbling b
[EMAIL PROTECTED] wrote: i have some html which looks like this where i want to scrape out the href stuff (the www.cnn.com part) div class=noFoodCheese/div div class=foodBlue/div a class=btn href = http://www.cnn.com; so i wrote this code which scrapes it perfectly: for incident in row('div', {'class':'noFood'}): b = incident.findNextSibling('div', {'class': 'food'}) print b n = b.findNextSibling('a', {'class': 'btn'}) print n link = n['href'] + ',' problem is that sometimes the 2nd tag , the div class=food tag , is sometimes called food, sometimes called drink. Apparently you are using Beautiful Soup. The value in the attribute dictionary can be a callable; try this: def isFoodOrDrink(attr): return attr in ['food', 'drink'] b = incident.findNextSibling('div', {'class': isFoodOrDrink}) Alternately you could omit the class spec and check for it in code. Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
(If I understand correctly...) The reason he is looking for it, is in order to assert that Python 'comparison' is broken. Part of this is because of his assertation that the term 'value' has no meaning in Python. He bases this on the fact that Java and C define 'value' to mean the pointer when the object is mutable. In fact Python defines value much more clearly. Value is *obviously* type dependent. (This is why in Python you can implement your own comparison methods). For integers and floats, Python defines the value to be the numerical value. For strings it defines it to be the contents of the string. For mutable objects it defines it to be the contents of the object, if the object types are the same. i.e. [1] == [1], [1] != (1,) For user defined classes, you are able to build your own definition of value into the object - this doesn't prevent stupidity. Python doesn't have a comparison operator analagous to his reference languages - but IMHO Python is better here. He can achieve what he wants by subclassing the built in datatypes and overriding the comparison methods to behave as he desires. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Tim Parkin wrote: Fredrik Lundh wrote: [various stuff] It would be apparent to you if you'd read around (even within this list) that the website is ultimately intended to have 'through the web' editing tools. You'd also know that one of the biggest acheivements so far is the separation of template from data from content so that 'information sets' actually exist in the first place. This also means that when someone designs a better template (as they may well do) it can be easily changed in the future. We also don't really want to have a proliferation of text formats and as a lot of the website is already written using restructured text, this is the format thats been recommended. A wiki is not a website and to try to shoehorn a wiki into a content management system is not a good final goal. We are adding facilities to use the wiki to manage some pages in near future as part of migration. However, the priority was to do certain things first. 1) Separate content from data from presentation is as complete a way as possible (for which nevow templates, which contain no programmatic componenets are suitable). 2) Ensure that the system is usable using basic text editing tools 3) Build the website using the latest techniques ensuring accessibility and usability. The site is XHTML and uses CSS for layout. It also offers legacy style sheets for netscape and has been tested in speech readers and text browsers. how quaint.. 4) Needed someone to actually do something The last item seems to be the one that has hit the most hurdles. As I remember you were a member of the marketing list and have had many opportunities to contribute constructively at planning time. If you could choose to be constructive in either offering useful changes that would make sense at this point in time or offereing to provide help that would be greatly appreciated. I'm afraid I won't be able to respond at length to any more posts.. There is still a lot of work to be done to get the website live. The most valid point that Fredrik makes is the convenience and desirability of through-the-web editing. I hope he'll use some of his undoubted energy to examine the current systems design and produce a through-the-web interface for us. Once the new documentation site is up and running, that is :-) Seriously, I'm not aware of anything about the current design that would prohibit through-the-web editing. Neither am I aware of anyone spending the time to produce it. As you indicated, there are other priorities just at the moment. 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: Sudoku solver: reduction + brute force
Anton, Do you think it is possible to reduce the set of all possible solutions to a small enough set? I personally doubt it, but IF that was the case an efficient solver could be easily created. In reducing the set of all solutions for instance you could always swap the numbers (3rd axis) so that the first submatrix reads [[1,2,3],[4,5,6],[7,8,9]]. By this we reduced the set of solutions by 362880. You can then always move blocks, columns and rows to fix the following elements (1,4)=4, (4,1)=2, (9,9)=9. Further reductions are still possible, but I do not know how far can this go and if the end result is a small enough set. Just my 2c. -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal vs float
Kay Schluehr wrote: I wonder why this expression works: decimal.Decimal(5.5)**1024 Decimal(1.353299876254915295189966576E+758) but this one causes an error 5.5**1024 Traceback (most recent call last): File interactive input, line 1, in ? OverflowError: (34, 'Result too large') Because the Decimal type can represent a larger range of values than the float type. Your first expression give a Decimal result, your second attempts to give a float result. Another quirk is the follwoing: decimal.Decimal(5.5) Traceback (most recent call last): ... TypeError: Cannot convert float to Decimal. First convert the float to a string If Mr. interpreter is as slick as he is why doesn't he convert the float by himself? This is at most a warning caused by possible rounding errors of float. Indeed, as the documentation says: This serves as an explicit reminder of the details of the conversion (including representation error). Otherwise you would get numpties using constructions like Decimal(0.1) and then asking why the result was the same as Decimal(0.10001) (or something similar). Who needs it? Certainly not Mr. interpreter, or his c.l.py friends. Instead of dealing with awkward wrappers, I wonder if literals currently interpreted as floats could not be interpreted as Decimal objects in future? That would be a very large change in the behaviour of the interpreter, and unfortunately it doesn't take account of the need in decimal to specify the context in which a calculation takes place.You need to be able to specify precision, rounding and a number of other values to make your computations completely specified. What would you use as the default context? 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: New Python.org website?
Steve Holden wrote: The trepidation was accounted for solely by a concern that Python would become involved in any kind of religious controversy, or that someone of extreme views might claim that Python was associated with, or against, a particular religious belief. I'm sure there are a number of places where people without extreme views react strongly to christian symbols--whether the reasons for this are well founded or not. ASEA, the A-part of the ABB group, stopped using their old logo in 1933. They realized that what used to be a symbol for electrical motors in schematic diagrams had become associated with something entirely different. In 1933 the general opinion on nazis weren't nearly as negative as it is now, but whatever you thought about politics, ASEA's old logo no longer gave the right associations to people. On the other hand, people on Bali don't seem to worry a bit about the swastikas on their shrines and temples. Different context. We can obviously argue on how much we should worry about the assocations people in various corners of thge world get, whatever we intended. In Sweden, the python snake has for some reason become associated with bad smells. (I think it was Pippi Longstocking who used an expresion that got stuck in the souls of the Swedes--it's all Astrid Lindgren's fault.) I don't expect Guido to rename Python for that reason (Monty would feel fairly neutral in Sweden), but it sometimes seem to be a disadvantage. I think some people I've tried to convince would have been more impressed if Python had been called XYZ or whatever... Here at work, our conference rooms are named after old norse gods, and the new room that was named Vile, was rapidly renamed Vili, when people thought about the meaning of vile in English. Actually, considering the status snakes have in christian tradition, I guess you could claim that the snakes neutralize the cross! Personally, I think it looks more like plus sign than like a cross. Quite apart from the fact that language choice should not be a religious issue (:-), you are correct in saying that we must be mindful of sensitivities; as I mentioned, the outline of the logo hasn't been raised in the year since it was first mooted. I hope this doesn't mean we need *two* Python logos! It's probably possible to make a Python logo that doesn't look like any religious symbol. I think the plus sign shaped logo had some advantages though. It's not very pretty, but it's simple and a plus is something positive, something that adds value... -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Anton Vredegoor wrote: Returning to the original book, why did they write a lot of it (at least the first few pages until I gave up, after having trouble understanding formulas about concepts I have no such trouble with when framed in less jargonized from) in unintelligible mathemathical notation when there's Python? Because the intended audience is probably reads formulas better than they read Python. The 1st sentence of the Introduction: This book is aimed at senior undergraduates and graduate students in Engineering, Science, Mathematics and Computing. Last month I spent about an hour trying to explain why a*2.5e-8 = x raises a SyntaxError and why it should be written x = a*2.5e-8 The guy who wrote the 1st line has MSc in Physics from Cambridge (UK). In mathematics, there is no difference between the two lines. I prefer a nice Python function over some strange latech symbols. If not Python there's always pseudo code or good old natural language. Don't tell me those math formulas are what it 'really' is, or even that it's more precise that way. The old trick of 'but there are some things that cannot be expressed in any other way than by using formulas' doesn't get one many optimization points in my world. Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple modules with database access + general app design?
Robin Haswell [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules (replacement for PHP's include() statement). My problem is, in PHP if you open a database connection it's always in scope for the duration of the script. Even if you use an abstraction layer ($db = DB::connect(...)) you can `global $db` and bring it in to scope, but in Python I'm having trouble keeping the the database in scope. At the moment I'm having to push the database into the module, but I'd prefer the module to bring the database connection in (pull) from its parent. Eg: import modules modules.foo.c = db.cursor() modules.foo.Bar() Can anyone recommend any cleaner solutions to all of this? Um, I think your Python solution *is* moving in a cleaner direction than simple sharing of a global $db variable. Why make the Bar class have to know where to get a db cursor from? What do you do if your program extends to having multiple Bar() objects working with different cursors into the db? The unnatural part of this (and hopefully, the part that you feel is unclean) is that you're trading one global for another. By just setting modules.foo.c to the db cursor, you force all Bar() instances to use that same cursor. Instead, make the database cursor part of Bar's constructor. Now you can externally create multiple db cursors, a Bar for each, and they all merrily do their own separate, isolated processing, in blissful ignorance of each other's db cursors (vs. colliding on the shared $db variable). -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Arithmetic sequences in Python
Paul Rubin wrote: [EMAIL PROTECTED] (Alex Martelli) writes: I see no credibly simple and readable alternative to {a:b, c:d} dictionary display syntax, for example; dict(((a,b),(c,d))) just wouldn't cut it, because of the parentheses overload (double entendre intended). dict(a=b,c=d) I don't really see why keyword arg names have to be identifiers either. foo(3=4) can pass a **kwargs containing {3:4}. The keywords need to be parseable; what would be the keyword form of { '3=4, 5=' : 6 } or { '3=4); print gotcha; dict(6=' : 7 } ? Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Python/C API
On Thu, 18 Jan 2006, pycraze wrote: Hi! I don't really understand what you need/want. Can you explain in more details? I Need to know how do i create a dictionary... eg: n = pali_hash n={} n={1:{ } } - i need to know how to make a key of a dictionary, to a dictionary using Python/C API's Catalin -- == We are what we repeatedly do. Excellence, therefore, is not an act but a habit. == -- http://mail.python.org/mailman/listinfo/python-list
Re: Sudoku solver: reduction + brute force
Your reduction-first approach makes short work of them, though. On the other hand, my version probably didn't take as long to write! Well, I started from the reduction-only algorithm so by the time I implemented the brute force solver I already had the code. Anyway the full code is just above 100 lines, it could be shorter (and it was in its first incarnation) but I strived to make it clean and more object oriented following the LinuxJournal article and by avoiding index operations (only contained in the __init__ methods). I like the idea of estimating difficulty... But for a subjective mesure from the point of view of the solver you probably need to give weights to the reduction techniques required to eliminatre cells, since those are the ones used by human beings. Some puzzles might be easy to solve by reduction but difficult to solve by brute force only. In this context for instance, a weight of 1 could be used every time one or more cells are eliminated thanks to Cell.Solve (the easiest approach), a weight of 2 when Cell.Skim was used to eliminate cells (more complex), and a weight of 3 every time BruteForce needs to be invoked (i.e. solutions must be guessed). One thing that my solver lacks is the ability to recognize multiple solutions. It will simply stop at the first admissible one whether it is unique or not. I am not sure what is an efficient way to detect it. -- http://mail.python.org/mailman/listinfo/python-list
Re: simple pythonpath query
[EMAIL PROTECTED] | I've downloaded the hypertext module and put it in the c:\python24\lib | folder. I would have thought that since the lib directory is in the | Pythonpath,I would be able to import python scripts from | C:\Python24\Lib\HyperText. I also tried including | C:\Python24\Lib\HyperText to | HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\2.4\PythonPath but no | joy. Am I missing something very simple here? Thanks, Marc I take it that's Andy Dustman's HyperText package? One thing to bear in mind (given that you haven't said what happened when you tried) is that the package itself offers little -- ie if you do import HyperText you won't get much; you need to do something like from HyperText import HTML. That said, I have it installed under site-packages (ie c:\python24\lib\site-packages) which is more designed for external modules/packages. The lib directory itself is rather for Python-supplied modules. Not sure if that all helps, but if you want to offer a traceback or error message, we might see some more. TJG -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Tim Peters wrote: [Paul Rubin] I wouldn't have figured out that a car park was a parking lot. I might have thought it was a park where you go to look at scenery from inside your car. Sort of a cross between a normal park and a drive-in movie. [Grant Edwards[ ;) That's a joke, right? Probably not, if Paul's American. For example, here in the states we have Python Parks, where you go to look at scenery from inside your python. They're actually one and the same thing: http://v8rx7.com/python_by_fibercan.htm Cheers, Nicola Musatti P.S. The way Google can find anything you look for, no matter how far out, is sort of scary. -- http://mail.python.org/mailman/listinfo/python-list
Re: simple pythonpath query
Cheers Tim, that sorted it. I need to re-read the modules section and namespaces. Everydays a schoolday. MW. -- http://mail.python.org/mailman/listinfo/python-list
Re: Ordering numbers
yawgmoth7 wrote: I have a dictonary here: seq = {8:0x13AC9741, 10:0x27592E8, 4:0x4EB25D, 5:0x9D64B, 7:0x13AC9, 1:0x2759, 11:0x4EB, 3:0x9D, 9:0x13, 2:0x2, 0:0x0, 6:0x0} Python always prints them in order, from least to greatest. But I wanna have it show them in hte order that I put in. Thanks for all your help http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/438823 Kent -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
Ok guys! The problem seems to be much easier to be solved than first thought. --Shoot-- Using the correct CreateParameter statement seems to do the trick. For example creating the parameter as cmd.CreateParameter(name,const.adVarChar, const.adParamInput, Size=16, Value=value[i]) # Name, Type, Direction, Size, Value works pretty good with the LIKE statement For the IN statement I have not yet found a good way. As of now in am looping through the values and creating various parameters Snippet: ## ##Global initialization ## typeMap= { types.IntType: const.adInteger, types.LongType: const.adBigInt, } query = SELECT * FROM tb_name WHERE firstname IN %(in_params) ## ##add parameters and construct the ? values for the in statements ##Note the code below is a pseudo type thing and can contain syntax errors ## in_parameters = [1,2,3,4,5] n_index = 0 in_params = '' for i in in_parameters: in_params += '?,' name = 'name_%s' % i p=cmd.CreateParameter(name, typeMap[type(i)], const.adParamInput, Size=16, Value=i) # Name, Type, Direction, Value cmd.Parameters.Append(p) query = query % {'in_params': in_params[:-1]} Any inputs to improve the IN statement logic? My dream is to use just one create parameter for the SQL list so that the query looks like query = SELECT * FROM tb_name WHERE firstname IN ? Nice and easy... :-) Thanks in advance! /Raja Raman -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Juho Schultz wrote: Last month I spent about an hour trying to explain why a*2.5e-8 = x raises a SyntaxError and why it should be written x = a*2.5e-8 The guy who wrote the 1st line has MSc in Physics from Cambridge (UK). In mathematics, there is no difference between the two lines. Some time ago I tried to 'sell' Python to a mathematician. The crucial point was that it was not (in standard Python) possible to have a matrix A and a matrix B and then do for example: A = A * B and have a matrix multiplication performed. Since the whole conversation started because there was a need to use this notation for a standard mathematics course this didn't result in adopting Python for it. Meanwhile there has been some progress in Python use there, and of course there are specialized Python packages that enable this kind of notation, but it remains true that there *is* an abyss between computer science and mathematics. Mathematics should change ;-) But that doesn't mean that I wouldn't like standard Python to have A*B for matrices. The problem is that so called 'conventional' mathematical notations leave many options for interpretation, depending on the context and on mutual understanding between mathematicians, excluding non-mathematicians very effectively. A (Python) interpreter has no such problems and will allow precise inspection of what is meant by a piece of code. It has additional advantages in that it can function as a kind of mathematical spellchecker for people like me who often miscode things. Some mathematicians I know can write formulas page after page, while I, if I were to write (or read) a page of formulas there would be at least one mistake throwing me of course for the rest of the document, so that I would need to go back again and again. Does that make me a bad mathematician or does it signify that mathematical notation should change? For me the answer is clear, but that could be because I can't read the stuff without the documentation, and the documentation (mathematics) is considered to be known to everyone (with a math education of course) but I doubt if that is really the case and, even if it were the case it doesn't imply that being explicit (in giving the procedures in computer and human readable form at the same time, for example in Python) wouldn't be even better. Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: Registering COM python based components when not admin
Thanks for the hint ! -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
Thanks. Please keep us posted. For some of my potentially exposed areas I was just doing regex lookups against the input parameter to filter out possible SQL injection keywords. Obviously not as elegant and efficient as using ADO parameters to strictly define the data that should be coming into the SQL statement. Playing around with the code you provided yesterday I had problems using an ADO parameter as a condition of the SQL LIKE statement. Not sure if that's an ADO limitation, a Python ADO limitation, or my relative ignorance :-) -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple modules with database access + general app design?
On Thu, 19 Jan 2006 12:23:12 +, Paul McGuire wrote: Robin Haswell [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules (replacement for PHP's include() statement). My problem is, in PHP if you open a database connection it's always in scope for the duration of the script. Even if you use an abstraction layer ($db = DB::connect(...)) you can `global $db` and bring it in to scope, but in Python I'm having trouble keeping the the database in scope. At the moment I'm having to push the database into the module, but I'd prefer the module to bring the database connection in (pull) from its parent. Eg: import modules modules.foo.c = db.cursor() modules.foo.Bar() Can anyone recommend any cleaner solutions to all of this? Um, I think your Python solution *is* moving in a cleaner direction than simple sharing of a global $db variable. Why make the Bar class have to know where to get a db cursor from? What do you do if your program extends to having multiple Bar() objects working with different cursors into the db? The unnatural part of this (and hopefully, the part that you feel is unclean) is that you're trading one global for another. By just setting modules.foo.c to the db cursor, you force all Bar() instances to use that same cursor. Instead, make the database cursor part of Bar's constructor. Now you can externally create multiple db cursors, a Bar for each, and they all merrily do their own separate, isolated processing, in blissful ignorance of each other's db cursors (vs. colliding on the shared $db variable). Hm if truth be told, I'm not totally interested in keeping a separate cursor for every class instance. This application runs in a very simple threaded socket server - every time a new thread is created, we create a new db.cursor (m = getattr(modules, module)\n m.c = db.cursor() is the first part of the thread), and when the thread finishes all its actions (of which there are many, but all sequential), the thread exits. I don't see any situations where lots of methods will tread on another method's cursor. My main focus really is minimising the number of connections. Using MySQLdb, I'm not sure if every MySQLdb.connect or db.cursor is a separate connection, but I get the feeling that a lot of cursors = a lot of connections. I'd much prefer each method call with a thread to reuse that thread's connection, as creating a connection incurs significant overhead on the MySQL server and DNS server. -Rob -- Paul -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal vs float
Steve Holden wrote: If Mr. interpreter is as slick as he is why doesn't he convert the float by himself? This is at most a warning caused by possible rounding errors of float. Indeed, as the documentation says: This serves as an explicit reminder of the details of the conversion (including representation error). Otherwise you would get numpties using constructions like Decimal(0.1) and then asking why the result was the same as Decimal(0.10001) (or something similar). Who needs it? Certainly not Mr. interpreter, or his c.l.py friends. The stringification of floats seems to work accurately just like the error message tells: Decimal(str(0.1)) Decimal(0.1) This is interesting. If we define def f(): print str(1.1) and disassemble the function, we get: dis.dis(f) 2 0 LOAD_GLOBAL 0 (str) 3 LOAD_CONST 1 (1.1001) # huh? 6 CALL_FUNCTION1 9 PRINT_ITEM 10 PRINT_NEWLINE 11 LOAD_CONST 0 (None) 14 RETURN_VALUE But when we call f, we receive f() 1.1 Mr. Interpreter seems to have a higher level of awareness :) Instead of dealing with awkward wrappers, I wonder if literals currently interpreted as floats could not be interpreted as Decimal objects in future? That would be a very large change in the behaviour of the interpreter, and unfortunately it doesn't take account of the need in decimal to specify the context in which a calculation takes place. I don't see this as a big obstacle. With the current implementation the compiler has to generate a decimal object from a NUMBER token instead of a float object. The context of a calculation is still the decimal module object and it's attributes. Why should it be changed? Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
The IN statement logic is a good mind exercise if there are multiple parameters that needed to be brought in. Below is the code that fixed the LIKE statement logic where you needed an ADO parameterized query used. Apparently the percent signs don't have to be referenced anywhere in the code, as my tests ran successfully without them: - import win32com.client from adoconstants import * conn = win32com.client.Dispatch(r'ADODB.Connection') conn.ConnectionString = Driver={SQL Server};Server=(local);Database=myDB;Trusted_Connection=yes; conn.Open() if conn.state == adStateOpen: print Connected to database... else: print Not connected! exit cmd=win32com.client.Dispatch(r'ADODB.Command') cmd.ActiveConnection=conn name = '@fname' value = 'raj' param=cmd.CreateParameter(name, adVarChar, adParamInput, 200, value) cmd.Parameters.Append(param) cmd.CommandText = SELECT first, last FROM myTable WHERE first like ? cmd.CommandType = adCmdText (rs, dummy) = cmd.Execute() rowCount = 0 while not rs.EOF: print rs.Fields('first').Value, rs.Fields('last').Value rowCount=rowCount+1 rs.MoveNext() print %s records returned. % rowCount rs.Close() -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Steve Holden wrote: Claudio Grondi wrote: Steven D'Aprano wrote: Claudio Grondi wrote: Exactly this is what Python does under the hood when writing a = some string b = some string where a and b are actually, in terms of C, pointer to Python object data structures which provide strings as arrays where it is possible to say a[0], but ... if here if(a==b): print True _does not_ print True, the Python engine is definitely broken. Why are you comparing C behaviour to Python behaviour? What is the point of the discussion? The point is to find a way to create in Python two indentifiers a and b without manipulating any of the __eq__ and to __eq__ related functions in a way, that the simple if a==b: print 'a==b' statement results in an endless loop. To my knowledge this is not possible to achieve in C, but is probably achievable in Python. So finally we understand what you are looking for (though not why ...). I will intentionally not elaborate here about the why, as my experience with this thread has already shown, that this is not only not helpful in getting the answer to the actual question, but results in 'hiding' the goal to the reader which needs to be revealed as it gets lost in the explanation. a = [1] a.append(a) a [1, [...]] b = [1] b.append(b) a == b Traceback (most recent call last): File stdin, line 1, in ? RuntimeError: maximum recursion depth exceeded in cmp Is this what you seek? Not quite an endless loop, but probably as close as you are going to get given the necessariliy recursive data structures required to induce it. Wow! I haven't got this evil idea myself yet (even if as I understand there is no problem to achieve similar thing also in C), so I have learned a bit more about Python again. Am I right supposing, that this becomes possible because the .append() goes not that far to try to generate the actual list (getting trapped in the endless loop) and only lets the second list element point to the object with the list itself. The trouble with it becomes apparent later when working with such bad defined list as it is the case when applying the '==' operator to it. Thank you for sharing this with me, but again ... this is still _not_ what I am looking for, because Python detects here the problem and throws an exception. What I am looking for is an endless loop where there is no any response from Python about a problem. Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: PyHtmlGUI Project is looking for developers
Good Morning everybody. Maybe it didn't get clear in the previous discussion: We didn't choose Qt as GUI API, we build an own GUI which is able to produce XML and html output, but whose structure is close to Qt. We even built a basic factory which produces PyHtmlGUI widgets from a Qt Designer .ui file, but it is still in development. The GUI is used by another project (a data management framework for Zope) which hasn't been anounced yet, but could generally be used for any python based webapplication (it enfolds its full capacity when it comes to forms, dialogs and wizards). The lack of client-side functionality (Javascript etc.) didn't cause any urgent problems, so we decided to postpone that, but since there are almost no constraints on widget customization, it is even now possible to build in javascript while building a layout, we just didn't try. The main goal of the project is to have a real GUI creating html and thus to avoid something like dtml, jsp or php etc., where you have to fiddle code into html. It's the other way around and since the css update it is even looking nice ;) Have a nice day, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple modules with database access + general app design?
Robin Haswell wrote: cursor for every class instance. This application runs in a very simple threaded socket server - every time a new thread is created, we create a new db.cursor (m = getattr(modules, module)\n m.c = db.cursor() is the first part of the thread), and when the thread finishes all its actions (of which there are many, but all sequential), the thread exits. I don't If you use a threading server, you can't put the connection object into the module. Modules and hence module variables are shared across threads. You could use thread local storage, but I think it's better to pass the connection explicitely as a parameter. separate connection, but I get the feeling that a lot of cursors = a lot of connections. I'd much prefer each method call with a thread to reuse that thread's connection, as creating a connection incurs significant overhead on the MySQL server and DNS server. You can create several cursor objects from one connection. There should be no problems if you finish processing of one cursor before you open the next one. In earlier (current?) versions of MySQL, only one result set could be opened at a time, so using cursors in parallel present some problems to the driver implementor. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Dom or MiniDom example
Hi, i'm searching for a dom or a minidom examples. I'm building a GUI. This gui should create a XML string. What's the best way to implement this? Dom, minidom or another way?Thanks.-- Sbaush -- Sbaush -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal vs float
Kay Schluehr wrote: Steve Holden wrote: If Mr. interpreter is as slick as he is why doesn't he convert the float by himself? This is at most a warning caused by possible rounding errors of float. Indeed, as the documentation says: This serves as an explicit reminder of the details of the conversion (including representation error). Otherwise you would get numpties using constructions like Decimal(0.1) and then asking why the result was the same as Decimal(0.10001) (or something similar). Who needs it? Certainly not Mr. interpreter, or his c.l.py friends. The stringification of floats seems to work accurately just like the error message tells: Decimal(str(0.1)) Decimal(0.1) This is interesting. If we define def f(): print str(1.1) and disassemble the function, we get: dis.dis(f) 2 0 LOAD_GLOBAL 0 (str) 3 LOAD_CONST 1 (1.1001) # huh? 6 CALL_FUNCTION1 9 PRINT_ITEM 10 PRINT_NEWLINE 11 LOAD_CONST 0 (None) 14 RETURN_VALUE But when we call f, we receive f() 1.1 Mr. Interpreter seems to have a higher level of awareness :) Mr. Interpreter (I see we are affording him capitals) has had his gonads stamped on when it comes to converting flots into strings, and so is exceedingly cautious when presenting them to users. This would not be a good idea when converting floats into other numeric representations. Instead of dealing with awkward wrappers, I wonder if literals currently interpreted as floats could not be interpreted as Decimal objects in future? That would be a very large change in the behaviour of the interpreter, and unfortunately it doesn't take account of the need in decimal to specify the context in which a calculation takes place. I don't see this as a big obstacle. With the current implementation the compiler has to generate a decimal object from a NUMBER token instead of a float object. The context of a calculation is still the decimal module object and it's attributes. Why should it be changed? Kay Well besides the fact that people would complain about the (lack of) speed I don't think I want to start having to explain to beginners how to handle precision and rounding settings to get the results they think they want. 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: Efficient implementation of deeply nested lists
Kay Schluehr wrote: I want to manipulate a deeply nested list in a generic way at a determined place. Given a sequence of constant objects a1, a2, ..., aN and a variable x. Now construct a list from them recursively: L = [a1, [a2, [[aN, [x]]...]] The value of x is the only one to be changed. With each value of x a new instance of L is needed so that we actually have a function: L = lambda x: [a1, [a2, [[aN, [x]]...]] I'm seeking for an efficient implementation that does not recompute the whole list each time. Any ideas? I'd say you are nesting the wrong way. items = make_list(range(10)) def make_list(items): ... return reduce(lambda *args: args, items) ... def update_value(items, value): ... return items[0], value ... items = make_list(range(10)) items (0, 1), 2), 3), 4), 5), 6), 7), 8), 9) update_value(items, 42) (0, 1), 2), 3), 4), 5), 6), 7), 8), 42) Obviously I must be missing something. What? Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Decimal vs float
Kay Schluehr wrote: This is interesting. If we define def f(): print str(1.1) and disassemble the function, we get: dis.dis(f) 2 0 LOAD_GLOBAL 0 (str) 3 LOAD_CONST 1 (1.1001) # huh? huh huh? str(1.1) '1.1' repr(1.1) '1.1001' %.10g % 1.1 '1.1' %.20g % 1.1 '1.1001' %.30g % 1.1 '1.1001' %.10f % 1.1 '1.10' %.20f % 1.1 '1.1001' %.30f % 1.1 '1.100100' more here: http://docs.python.org/tut/node16.html /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple modules with database access + general app design?
On Thu, 19 Jan 2006 14:37:34 +0100, Daniel Dittmar wrote: Robin Haswell wrote: cursor for every class instance. This application runs in a very simple threaded socket server - every time a new thread is created, we create a new db.cursor (m = getattr(modules, module)\n m.c = db.cursor() is the first part of the thread), and when the thread finishes all its actions (of which there are many, but all sequential), the thread exits. I don't If you use a threading server, you can't put the connection object into the module. Modules and hence module variables are shared across threads. You could use thread local storage, but I think it's better to pass the connection explicitely as a parameter. Would you say it would be better if in every thread I did: m = getattr(modules, module) b.db = db ... def Foo(): c = db.cursor() ? separate connection, but I get the feeling that a lot of cursors = a lot of connections. I'd much prefer each method call with a thread to reuse that thread's connection, as creating a connection incurs significant overhead on the MySQL server and DNS server. You can create several cursor objects from one connection. There should be no problems if you finish processing of one cursor before you open the next one. In earlier (current?) versions of MySQL, only one result set could be opened at a time, so using cursors in parallel present some problems to the driver implementor. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: Clicking at a certain x,y position in python? (Mac OSX)
Nainto wrote: I have been searching and searching and cannot find a way to click at a certain position in python. What for? There's a few ways it might be done, but what's best depends on what you're trying to achieve. -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
Hi Gregarican, Thanks for sharing your code. One needs to add the % signs if one wants to do wildcard searches using LIKE in the SQL server. Do as Roger and Steve suggested '%raj%', now you can find the names containing the word raj anywhere in the column. just value = 'raj' is only going to fetch you fnames that == 'raj' Originally my problem was using the LIKE statement itself. But I guess you already know. /Raja Raman -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Fredrik Lundh wrote: Steve Holden wrote As you indicated, there are other priorities just at the moment. you're complaining about the lack of manpower, and still think that lowering the threshold for contributions is not a priority ? at this point, this should be your *only* priority. I mean, getting this from a long-time python contributor that decided to help out My first attempt ended almost immediately. Too much software to download and install for anything like casual use. should be a rather strong indicator that the project isn't on the right track. Or that the instructions being followed were those for producing a local copy of the website rather than editing the beta site content (mea culpa, since I believe 'twas I who gave the instructions). (and it sure isn't the only indicator; I still claim that the analysis is flawed, and that the www.python.org front-page asset shouldn't be reserved for a target audience that doesn't exist. but that's a separate problem; if you solve the threshold problem, we can deal with that later. if you don't, we might get stuck with the new design for as long as we've had the old one). I don't think it's *reserved* for anyone. The idea is to try and offer a system that allows easy changes to the content while maintaining a relatively clean design. Once the new documentation site is up and running, that is :-) that's an interesting comparision: it took me about 30 minutes to convert 10+ megabytes of reference material into a usable (X)HTML infoset (that is, with isolated content and structural information derived from the source material), and a few hours to get old source-new source-render tool- chain to a state where most conversion bugs turns out to be typos in the original documents (aka the 80% of the remaining 20% level). if converting the old content is and has been the biggest problem in the beta.python.org project, it seems to me as if you might not be doing things in the easiest possible way... Well I can't disagree with that. Want to help? 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: OT: excellent book on information theory
Terry Hancock wrote: Tim Peters [EMAIL PROTECTED] wrote: UK:Harry smiled vaguely back US:Harry smiled back vaguely Terry Hancock wrote: I know you are pointing out the triviality of this, since both US and UK English allow either placement -- but is it really preferred style in the UK to put the adverb right before the verb? In US English, the end of the clause (or the beginning) is probably more common. I appreciate your desire to put the thread on (Python) topic, but as I see this discussion, it really has to do with respect for the author, but also respect for the reader. The UK version is most likely the way the author intended it to be. Then that is the way the text should be, regardless if it is preferred style or not, under the assumption that English is English is English. One question here is: Are US English and UK English different languages or not? If they are, a translation is in place. If they are not, the text should have been left as is. I guess the answer is: -Well, sort of... And that is probably the reason why opinions differ here, and also the reason why the American publisher has made some changes, but left most parts unchanged. A related important question is: Does the US version communicate the same thing (meaning aswell as feeling) to the American reader as the UK version communicates to the British reader? That should always be the objective for any translator. It also means that if the author in the UK version uses non-standard UK English, then the US version should use non-standard US English. /MiO -- http://mail.python.org/mailman/listinfo/python-list
Re: MSSQL LIKE and IN statements in ADO problem
Raja Raman Sundararajan wrote: [...] Any inputs to improve the IN statement logic? My dream is to use just one create parameter for the SQL list so that the query looks like query = SELECT * FROM tb_name WHERE firstname IN ? Nice and easy... Some DBAPI modules will indeed allow you to use a list or set parameter for this purpose, but not all. 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: PyHtmlGUI Project is looking for developers
Veri wrote: Good Morning everybody. Maybe it didn't get clear in the previous discussion: We didn't choose Qt as GUI API, we build an own GUI which is able to produce XML and html output, but whose structure is close to Qt. We even built a basic factory which produces PyHtmlGUI widgets from a Qt Designer .ui file, but it is still in development. The GUI is used by another project (a data management framework for Zope) which hasn't been anounced yet, but could generally be used for any python based webapplication (it enfolds its full capacity when it comes to forms, dialogs and wizards). The lack of client-side functionality (Javascript etc.) didn't cause any urgent problems, so we decided to postpone that, but since there are almost no constraints on widget customization, it is even now possible to build in javascript while building a layout, we just didn't try. The main goal of the project is to have a real GUI creating html and thus to avoid something like dtml, jsp or php etc., where you have to fiddle code into html. It's the other way around and since the css update it is even looking nice ;) So you'e creating a Python API to a GUI, which generates HTML interfaces with appropriate callbacks to the relevant widgets. This API *resembles* the Qt API. What would be nice is a compatibility layer which means that the same application could be created for the Web or the desktop, just using the appropriate GUI toolkit (web or desktop). This wasa what I thought you were doing. With appropriate AJAX type calls it's not unfeasible. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml Have a nice day, Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: socket.ssl with key files?
thanks for the info. 1) Am I correct that I should just be splitting the files? 2) The passphrase question was in the back of my mind, but I guess I need to move it to the front. Hopefully someone here will have an idea. (I wonder if M2Crypto handles that?) I guess it's better to know that the code is fairly untested, rather than finding that out on my own. -Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: Sudoku solver: reduction + brute force
ago wrote: Do you think it is possible to reduce the set of all possible solutions to a small enough set? I personally doubt it, but IF that was the case an efficient solver could be easily created. No I don't think so, but it's a great idea :-) . Iff we would have some ultimate symmetry detector we could reduce all positions to variations of a few base types and start *generating* solutions from there in stead of checking possible mistakes. In reducing the set of all solutions for instance you could always swap the numbers (3rd axis) so that the first submatrix reads [[1,2,3],[4,5,6],[7,8,9]]. By this we reduced the set of solutions by 362880. You can then always move blocks, columns and rows to fix the following elements (1,4)=4, (4,1)=2, (9,9)=9. Further reductions are still possible, but I do not know how far can this go and if the end result is a small enough set. I think one could reduce more than just a factor 9! . A 3-dim cube has 48 symmetric mirror images and we could multiply 9! by this. Then there are the horizontal slice swaps and the whole 3-slice swaps. Anyway I wasn't thinking about a grand unified theory but more about limiting the search space (in a depth first tree) early. If for example some field would allow only 2 values it would pay off to check that field first in the search (before fields that can have say 9 values) because that would be the next best thing to having that value as a fixed starting value. Similarly if we would only check a subtree position once (by using the hash) it could save some computations, but I have no idea how effective it would be, all this mirrorring could be expensive too. On the other hand this is done on the single leaf level, perhaps cutting off whole branches, so it might indeed pay off very much. Remember that some subtrees can be identical even though the routes to get to there were different. Here's the idea to make all the mirrors (I have the code at home, but I can't reach it now, but it should be easy to code): Say one has dimension x with values [0,1,,8] Now rescale this to [-4,-3,...,+4] Then do this for all x,y and z coordinates. Now to generate all mirrors, make all 6 permutations and all +- variations of all coordinate points x,y,z for each mirror. So x,y,z gives 6 permutations and doing +-x,+-y,+-z for each of these makes for 48 (6*2**3) mirror images of each point. for example a coordinate [-3,-2,-1] mirrored through mirror [z,-x,y] would give coordinate point [-1,3,-2]. Do this for all points. Repeat for each mirror. Now convert back to [0,1,..8] coordinates and select the smallest mirrored cube. Eh, maybe math notation wouldn't be such a bad idea after all, only then I wouldn't be able to read what I wrote here. I hope you can :-) Anton -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Claudio Grondi wrote: Steve Holden wrote: Claudio Grondi wrote: Steven D'Aprano wrote: Claudio Grondi wrote: Exactly this is what Python does under the hood when writing a = some string b = some string where a and b are actually, in terms of C, pointer to Python object data structures which provide strings as arrays where it is possible to say a[0], but ... if here if(a==b): print True _does not_ print True, the Python engine is definitely broken. Why are you comparing C behaviour to Python behaviour? What is the point of the discussion? The point is to find a way to create in Python two indentifiers a and b without manipulating any of the __eq__ and to __eq__ related functions in a way, that the simple if a==b: print 'a==b' statement results in an endless loop. To my knowledge this is not possible to achieve in C, but is probably achievable in Python. So finally we understand what you are looking for (though not why ...). I will intentionally not elaborate here about the why, as my experience with this thread has already shown, that this is not only not helpful in getting the answer to the actual question, but results in 'hiding' the goal to the reader which needs to be revealed as it gets lost in the explanation. a = [1] a.append(a) a [1, [...]] b = [1] b.append(b) a == b Traceback (most recent call last): File stdin, line 1, in ? RuntimeError: maximum recursion depth exceeded in cmp Is this what you seek? Not quite an endless loop, but probably as close as you are going to get given the necessariliy recursive data structures required to induce it. Wow! I haven't got this evil idea myself yet (even if as I understand there is no problem to achieve similar thing also in C), so I have learned a bit more about Python again. Am I right supposing, that this becomes possible because the .append() goes not that far to try to generate the actual list (getting trapped in the endless loop) and only lets the second list element point to the object with the list itself. The trouble with it becomes apparent later when working with such bad defined list as it is the case when applying the '==' operator to it. Thank you for sharing this with me, but again ... Yes, clearly Python is able to create recursive data structures of this type, just as C and Java are. As you can see when the interpreter prints the representation of such lists, the __repr__() method does indeed detect such recursion and places ellipses (...) in the output to indicate it. When you say Python goes not so far as to try to generate the actual list you reveal a misunderstanding about Python. The interpreter responds to the statement a.append(a) just as it responds to every other append() method call: it adds a new item to the list and binds (i.e. stores a reference to) the argument (in this case the list as itself) to that new item. No special cases are required here, this is what the interpreter always does. this is still _not_ what I am looking for, because Python detects here the problem and throws an exception. What I am looking for is an endless loop where there is no any response from Python about a problem. Ah, I see. So you want Python to be a worse language than it actually is. I don't think you are going to find what you are looking for. 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: New Python.org website ?
Fredrik Lundh wrote: Tim Parkin wrote: How about designing a website and showing us what you think would be a good idea? Or suggesting some way of managing all of the content and building the system. I think I just did that: the easiest way to get there would be to use a MoinMoin instance to main- tain the content, and a separate renderer to generate static pages for the main site (possibly using Cheetah or Kid as template languages). to which you responded A wiki is not a website and to try to shoehorn a wiki into a content manage- ment system is not a good final goal. which is an interesting thing to say at a time when wikipedia has joined google and blog as the internet things that everyone has heard about... Well I happen to agree whole-heartedly with Tim on that one. I can't stand trying to navigate some of these Wiki-trying-to-be-website pages. It is impossible to find anything on most of them (notice I didn't say all..there are exceptions). It seems like they cater to people who: a) Get some sort of sick pleasure out of searching webpages by manually constructing regular expressions. b) Love the fact that every other word is a link and end up in a 3 hour link-clinking session until they have visited every link. Navigating a Wiki to me feels more like trying to find the proverbial needle in a haystack, or perhaps it is more like painting a wall by flinging paint at it with a spoon. But maybe that's just me. I sometimes have a compulsion for methodically checking everything in a sane order. That's probably just my code review skills, or dungeon-crawling instincts kicking in. ;o) M. -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
whisper If you build it, they will come. /whisper -- http://mail.python.org/mailman/listinfo/python-list
Re: Efficient implementation of deeply nested lists
Peter Otten wrote: Kay Schluehr wrote: I want to manipulate a deeply nested list in a generic way at a determined place. Given a sequence of constant objects a1, a2, ..., aN and a variable x. Now construct a list from them recursively: L = [a1, [a2, [[aN, [x]]...]] The value of x is the only one to be changed. With each value of x a new instance of L is needed so that we actually have a function: L = lambda x: [a1, [a2, [[aN, [x]]...]] I'm seeking for an efficient implementation that does not recompute the whole list each time. Any ideas? I'd say you are nesting the wrong way. The structure of the sequence is *not* optional. items = make_list(range(10)) def make_list(items): ... return reduce(lambda *args: args, items) ... def update_value(items, value): ... return items[0], value ... items = make_list(range(10)) items (0, 1), 2), 3), 4), 5), 6), 7), 8), 9) update_value(items, 42) (0, 1), 2), 3), 4), 5), 6), 7), 8), 42) Obviously I must be missing something. What? The structure of the sequence is *not* optional. Of course you can also take the original sequence and apply: L = list([a1, [a2, [[aN, [x]]...]]) # shallow copy L[0] = b but it is intended to change the most inner element. I guess there is no way in doing it without a deepcopy / full list construction. Kay -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Mikael Olofsson wrote: A related important question is: Does the US version communicate the same thing (meaning aswell as feeling) to the American reader as the UK version communicates to the British reader? That should always be the objective for any translator. fwiw, the Swedish Dan Brown translator fixed lots of glitches and inconsistencies without even checking with Brown; the sheer number of trivial errors made it ob- vious to him that it wasn't some clever literary device; Brown had just been careless. now, does a cleaned-up Brown communicate the same meaning/feeling to a Swede (or other european) as an inaccurate Brown does to an American ? has Brown's works been translated to British English, btw ? /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Can a simple a==b 'hang' in and endless loop?
Claudio Grondi wrote: [snip..] Wow! I haven't got this evil idea myself yet (even if as I understand there is no problem to achieve similar thing also in C), so I have learned a bit more about Python again. Am I right supposing, that this becomes possible because the .append() goes not that far to try to generate the actual list (getting trapped in the endless loop) and only lets the second list element point to the object with the list itself. I think you've got this. a = [] Here a is a reference to a list object. a.append(a) As mentioend previously - you pass around references (names), not values. Here you've put a reference to the list object a as the first member of the list a. The trouble with it becomes apparent later when working with such bad defined list as it is the case when applying the '==' operator to it. Thank you for sharing this with me, but again ... this is still _not_ what I am looking for, because Python detects here the problem and throws an exception. What I am looking for is an endless loop where there is no any response from Python about a problem. Loops tend to be caused by function or method calls - so they add frames to the stack and get detected as recursion. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml Claudio -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Markus Wankus wrote: Well I happen to agree whole-heartedly with Tim on that one. I can't stand trying to navigate some of these Wiki-trying-to-be-website pages. It is impossible to find anything on most of them (notice I didn't say all..there are exceptions). It seems like they cater to people who: Nobody's expecting the *user* to navigate wiki pages. It's a tool for the content providers. And they don't have to navigate anything either; an edit link (or sym- bol) in a convenient location on each page is all you need. /F -- http://mail.python.org/mailman/listinfo/python-list
Re: Need Help with Python/C API
On Thu, 2006-01-19 at 00:44, pycraze wrote: Hi guys, I Need to know how do i create a dictionary... eg: n = pali_hash n={} n={1:{ } } - i need to know how to make a key of a dictionary, to a dictionary using Python/C API's You can either use Py_BuildValue (See http://docs.python.org/api/arg-parsing.html#l2h-214) or PyDict_New and PyDict_SetItem (See http://docs.python.org/api/dictObjects.html) to construct a dictionary. Good luck, Carsten. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple modules with database access + general app design?
Robin Haswell wrote: Hey people I'm an experience PHP programmer who's been writing python for a couple of weeks now. I'm writing quite a large application which I've decided to break down in to lots of modules (replacement for PHP's include() statement). My problem is, in PHP if you open a database connection it's always in scope for the duration of the script. Even if you use an abstraction layer ($db = DB::connect(...)) you can `global $db` and bring it in to scope, but in Python I'm having trouble keeping the the database in scope. At the moment I'm having to push the database into the module, but I'd prefer the module to bring the database connection in (pull) from its parent. This is what I do. Create a separate module to contain your global variables - mine is called 'common'. In common, create a class, with attributes, but with no methods. Each attribute becomes a global variable. My class is called 'c'. At the top of every other module, put 'from common import c'. Within each module, you can now refer to any global variable as c.whatever. You can create class attributes on the fly. You can therefore have something like - c.db = MySql.connect(...) All modules will be able to access c.db As Daniel has indicated, it may not be safe to share one connection across multiple threads, unless you can guarantee that one thread completes its processing before another one attempts to access the database. You can use threading locks to assist with this. HTH Frank Millman -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiple modules with database access + general app design?
Robin Haswell wrote: On Thu, 19 Jan 2006 14:37:34 +0100, Daniel Dittmar wrote: If you use a threading server, you can't put the connection object into the module. Modules and hence module variables are shared across threads. You could use thread local storage, but I think it's better to pass the connection explicitely as a parameter. Would you say it would be better if in every thread I did: m = getattr(modules, module) b.db = db ... def Foo(): c = db.cursor() I was thinking (example from original post): import modules modules.foo.Bar(db.cursor ()) # file modules.foo def Bar (cursor): cursor.execute (...) The same is true for other objects like the HTTP request: always pass them as parameters because module variables are shared between threads. If you have an HTTP request object, then you could attach the database connection to that object, that way you have to pass only one object. Or you create a new class that encompasses everything useful for this request: the HTTP request, the database connection, possibly an object containing authorization infos etc. I assume that in PHP, global still means 'local to this request', as PHP probably runs in threads under Windows IIS (and Apache 2.0?). In Python, you have to be more explicit about the scope. Daniel -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
Fredrik Lundh wrote: Steve Holden wrote As you indicated, there are other priorities just at the moment. you're complaining about the lack of manpower, and still think that lowering the threshold for contributions is not a priority ? at this point, this should be your *only* priority. If you want to contribute, then do so.. If we had more people offering to contribute then this would be a priority. However despite trying to get people to contribute for over two years, I still ended up doing pretty much everything myself. And despite continued calls for people to help and offers of optimising the install process and writing additional documentation if they wanted to, we've only had four offers of help, of which only myself, Steve Holden and Andrew Kuchling have been doing anything significant. It would be loveley to have a large team of volunteers producing a consensus on approach to the website build. It would also be greate to have lots of people to put the effort into it. I think the same can be said for any open source project. However, just like open source projects, you have to choose based more on who is willing to do anything than on who is offering the ideal solution. (there are normally a lot more of the latter than of the former) I mean, getting this from a long-time python contributor that decided to help out My first attempt ended almost immediately. Too much software to download and install for anything like casual use. should be a rather strong indicator that the project isn't on the right track. I think the follow on post saying maybe I misread the directions and the fact that you can edit/contribute content without having to use the full build tool should be noted (you can use a text editor if you like... how 1976). The project is on the right track as it's the only track that anybody was bothered to lay. (and it sure isn't the only indicator; I still claim that the analysis is flawed, and that the www.python.org front-page asset shouldn't be reserved for a target audience that doesn't exist. but that's a separate problem; if you solve the threshold problem, we can deal with that later. if you don't, we might get stuck with the new design for as long as we've had the old one). I don't think the front page is reserved for an audience that doesn't exist. The front page is trying to serve many purposes for many audiences. If you had read the documents that had been available online during the extensive initial discussions, you would know what the estimated split in the audience was and also know why the balance of content on the home page is the way it is. The 'threshold problem' I think you are talking about (it would help if you could be more specific about what a 'threshold problem' really is) is more relevant to managing content than design and templating. Once the new documentation site is up and running, that is :-) that's an interesting comparision: it took me about 30 minutes to convert 10+ megabytes of reference material into a usable (X)HTML infoset (that is, with isolated content and structural information derived from the source material), and a few hours to get old source-new source-render tool- chain to a state where most conversion bugs turns out to be typos in the original documents (aka the 80% of the remaining 20% level). if converting the old content is and has been the biggest problem in the beta.python.org project, it seems to me as if you might not be doing things in the easiest possible way... Good and congratulations, it shows that the source code is well formatted/consistent - I wish the rest of the website html/data were so. If you are suggesting that your skills can do this with the rest of the site content then please, please help!! In fact I will ask you now, publicly, if you are willing to offer your services to help convert the documentation and exsiting content over to the new website? If you are then your services will be greatly appreciated and I'm sure we can take the discussion of the balance of the home page and future web based management of the content elsewhere and invite anyone who wishes to participate to join us. We can then post our conclusions once we've reached some consensus. If we can get the rest of the content (which doesn't include fancy pictures) over to the new site then we'll have a great foundation for making further additions and I'd really like a few more people to help get us there. I really can't afford a lot of time to discuss issues that have already been discussed far too many times. If we can get down to specifics of what you are offering and what you expect other people to do to help you, then we should be able to keep conversations a lot shorter. Tim -- http://mail.python.org/mailman/listinfo/python-list
Re: OT: excellent book on information theory
Hi Paul, Dr MacKay was my information studies lecturer and 4th year degree project mentor at university, about 5 years ago, and I think that this book is basically the course notes we used then! He is an excellent lecturer, and if the book is as good as the course, it should be very interesting, particularly the error correcting stuff. Very off topic I know, but it's always interesting when two areas of interest collide (my time at university, and my love of python!) Cheers, Ben Paul Rubin wrote: I came across this while looking up some data compression info today. David J.C. MacKay Information Theory, Inference, and Learning Algorithms Full text online: http://www.inference.phy.cam.ac.uk/mackay/itila/ It's a really excellent book, on the level of SICP but about information theory, probability, error correcting codes, etc. Very readable, and geeky (in a good way) at the same time. The writing style is perhaps along the lines of Numerical Recipes, though the format is more conventional. The whole text is online as a pdf, which is very nice. The printed version is somewhat expensive, but according to the following analysis it's a better bargain than Harry Potter and the Philosopher's Stone: http://www.inference.phy.cam.ac.uk/mackay/itila/Potter.html -- http://mail.python.org/mailman/listinfo/python-list