conditional running of code portion
Hi, How can I implement something like C++'s conditional compile. if VERBOSE_MODE: print debug information else: do nothing But I don't want this condition to be checked during runtime as it will slow down the code. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: building extensions for Windows Python
Thanks to Michael and Nick, I can now cross-compile my Pyrex extensions for bog-standard Python 2.5. As I stumbled around in the dark trying to bump into a solution, I was bolstered by the belief that at least two other people had found the light at the end of the tunnel. I had been using a crufty old prebuilt MinGW that linked to MSVCRT.DLL but didn't include support for the newer VC runtime DLLs. I had to build the current version which adds support for MVCR71 (used by Python 2.5) and MSVCR80 (used by Microsoft's current ".NET" offering). (Note: The build script proffered by mingw.org fails really cryptically if you don't have the scanner tool, "flex", installed. But that's another story. After some hand-to-hand combat, I had a working MinGW, nee GCC 3.4.2.) Microsoft advises that it's very bad mojo to mix calls to MSVCRT.DLL and MSVCR71.DLL in one application, but http://tinyurl.com/ydndnn (or a page it references) advises how to avert such a disaster with a simple change to MinGW's "spec" file (which I never knew existed). The upshot is that I can now use Linux to cross-build my extension for Windows, and my preliminary testing (under WINE -- See the original post. I must adhere to my employment contract!) seems to show that it works. Had I not known someone else claimed success, I would have thrown up my hands in frustration. Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
building extensions for Windows Python
I have a lousy little Python extension, generated with the generous help of Pyrex. In Linux, things are simple. I compile the extension, link it against some C stuff, and *poof*! everything works. My employer wants me to create a Windows version of my extension that works with the vanilla Python 2.5 from python.org. My employment contract states that I won't be required to run Windows, and I desperately want to honor that clause. Ideally, I'd somehow MinGw cross compile like I do with C/C++ and *poof*!, out would pop a file I could hand out to someone who wanted to "import ". In Windows, things aren't so simple. I'm immediately bedazzled by a vast, unfamiliar nomenclature: "VC6", "VC7.1", "msvcrt", "msvcr71", "msvcr80", "VS2005", "VS2007", "MSVC2003", "MSVC2005", "Express Edition", ".NET SDK", etc. The python.org "recommended compiler" is apparently no longer available, but someone posted a link to an obscure Microsoft webpage artifact where it could still be obtained. Running it under WINE is less than ideal, but I decided to try and make it work. However, when I tried installing the compiler, it failed because my "Internet Explorer [was] out of date." I'm not sure how IE comes into the picture, but I'm just a programmer, after all. I am further confused by the python.org docs on using MinGw to build extensions: "These instructions only apply if you're using a version of Python prior to 2.4.1 with a MinGW prior to 3.0.0", but further on: "pcexports python25.dll >python25.def" seems to contradict that. It really makes no difference. The referenced webpage where the "pcexports" tool is found seems defunct. My main problem is that I don't really grasp the big picture. Can someone give me an overview of the requirements to build extensions for Windows Python, circa 2.5? Or, can I tell my employer she'll just have to hire/contract a Windows expert to do the mud wrestling? Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
Re: 2Qs
> > 2nd question: > [snip] > > if x>10 and y>10 and z>10 and summ(tritup(x,y,z)): print "OK" > > Others have already suggested you use the built-in sum() function. > > I'll suggest you don't need it at all, because it is redundant. > > If the sum is zero, either all three values are zero or at least one of > the values is negative. In either case the first test will fail. > > There are no circumstances where each of x, y and z are greater than 10 > but the sum is zero; nor are there any circumstances where the sum is > zero but x, y and z are still all greater than 10. Unless, of course, the function tritup returns negative values. My guess is that the "> 10" tests are protecting the tritup function, and possibly should be moved there. Without the details of the function, I can't tell, but it may be incorrect to remove those tests. Which brings us to the other bit of advice - unit tests protect you from yourself and from those who optimize too quickly. -- http://mail.python.org/mailman/listinfo/python-list
Re: MS VC++ Toolkit 2003, where?
On Sun, 23 Apr 2006 21:15:23 -0700, Alex Martelli wrote: > As suggested to me by David Rushby 10 hours ago, > > ... < huge URL snipped > ... Alas, somehow this URL was split in two, and all the kings horses and all the kings men can't seem to put it back together again (at least in my browser). Could someone post a tinyurl? > And, as an aside...: > > [Those] not willing to shell out mucho $$$ to MS for a pro VS > 2003) must go through such gyrations as these in order to be able to > build Python extensions on Windows. I'm sure my Windows-loving > colleagues in the PSF (who got several free copies of VS 2003 from > Microsoft, I believe -- at the time, I had zero Windows installations > and zero interest in Windows, so I didn't sign up for one) have fully > considered this recurring drama, and come to the decision of sticking > with VS 2003 (avoiding any free-as-in-beer compilers such as VS 2005 or > mingw) with thorough and wise deliberation. Well, so long as there's a way to get the requisite tools. I'm sure these Windows-loving colleagues confirmed these "free" tools worked under WINE, else how would us cheap programmers with Windows-less boxes avoid sending $$$ to the Great Satan? Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
Re: just one more question about the python challenge
You said: > Sorry to post here about this again, but the hint forums are dead, and > the hints that are already there are absolutely no help (mostly it's > just people saying they are stuck, then responding to themselves saying > the figured it out! not to mention that most of the hints require > getting past a certain point in the puzzle before they make sense, and > i'm just clueless). I just went to the hint forums: http://www.pythonchallenge.com/forums/index.php There are SEVEN pages of clues for level 12. The most recent post (to challenge 1) was on April 11, so the forums are most certainly not dead. Yes, the hints don't spell out what step they are refering to, and a certain level of obfuscation is required to avoid giving away hints. Many can not be solved in a day - they require reading hints, thinking hard, then doing something else (reading, working, sleeping) to let the subconscious chew over the clues. This is the fun of the challenge - there is no secret knowledge gained, other than a list of URLs and passwords. If this isn't your definition of fun, then you can go on to other things with a clear conscious. -- http://mail.python.org/mailman/listinfo/python-list
Re: Multiplying all the values in a dictionary
As long as you are optimizing, addition is slightly faster than multiplication: $ python2.4 -mtimeit 'h=1;h*=2' 100 loops, best of 3: 0.286 usec per loop $ python2.4 -mtimeit 'h=1;h=h+h' 100 loops, best of 3: 0.23 usec per loop Of course, that's only a 20% decrease, so it might not be worth the trouble. -- http://mail.python.org/mailman/listinfo/python-list
Re: doctest-alike for a unix shell?
1. Try os.popen: >>> import os >>> os.popen('echo Hello World').read() 'Hello World\n' 2. Try a test environment built for testing shell commands, such as DejaGnu: http://www.gnu.org/software/dejagnu/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Please, I Have A Question before I get started
Skipper wrote: > I can not believe that there isn't a GUI programing tool that will > allow me to build GUI apps - just like I use Dreamweaver to build a > web page ... a WYSIWYG builder that does a few simplet things and > calls other programs ... > > Oh well no silver bullet! If you are interested in programming, the best way is to find a motivating goal to learn. It sounds like you have a very motivating goal. However, it will probably take quite a long time for you to get to a point where you can make a useful tool for your son. While your problem description is straightforward, the implementation is not. One route you might consider is contacting your local engineering college for help. My alumnus recently solicited funds for a "Life Interaction Device" for Abigail, a 6 year old girl with Cerebral Palsy: http://www.ee.utulsa.edu/Abigail/index.html It sounds as if Abagail's needs are far greater than your son's, but your project would make an interesting design project for CS students at an undergraduate level. -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for help about python-sane
Sorry, I can't help much with the issue. You are getting a low-level hardware fault, and not much information is being propagated up throught the system. It's not a Python problem, but something with SANE, and the Python wrapper is just propagating the SANE error to you. I have a few suggestions: - Use a try block, and see if you can recover: try: grabImage(webcam) except _sane.Error, se: print se # but continue See if all you get is errors, or if it's just a once-in-a-while thing. Maybe you should sleep longer when you get an error, to give the system a chance to do something else. - Try to figure out if SANE is printing any logging message. Check the kernel log (dmesg), the normal system log, read SANE man pages, etc. - Read the sane-v4l man page. The one I found on the Internet says it is Alpha software, which means it is highly experimental, but maybe it has improved. - Try a similar task using the native sane tools (sane-find-scanner, scanimage, etc.). This may generate more useful error messages. - Post a question to the SANE mailing lists: http://www.sane-project.org/mailing-lists.html Once you have a happy SANE setup, then it should be trivial modify the Python code to do the same thing. Hope this is some help, JW -- http://mail.python.org/mailman/listinfo/python-list
Re: looking for help about python-sane
Every time, or just this run? -- http://mail.python.org/mailman/listinfo/python-list
Re: PEP 354: Enumerations in Python
It seems the concensus is that empty enums should be allowed for consistancy, and to support the loop that doesn't. I thought I'd find some data points in other languages as a guide: * C - builtin, empty enumerations not allowed * C++ - builtin, empty enumerations allowed. C++ doesn't have iteration over a enumeration, except as a side-effect of direct translation from elements to integerts (and then, only for a sequentially assigned enumeration). An enumeration is a type, so it can be thrown (raised) as an exception - http://oopweb.com/CPP/Documents/CPPAnnotations/Volume/cplusplus16.html#EMPTYENUM * Java - builtin, empty enumerations allowed previously to 1.5, but maybe not after - http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5081785 * OCaml - library, empty enumerations allowed as a consequence of being able to add and remove enumeration elememts: http://ocaml-lib.sourceforge.net/doc/Enum.html I realize this is a strange and short list, but it's all I can do with 5 min of Google and a little testing. -- http://mail.python.org/mailman/listinfo/python-list
Re: general coding issues - coding style...
About this line: 1585 if sys.path[0][-12:] == "\library.zip": #for py2exe pl... suggested: if sys.path[0].endswith( "\\library.zip" ): and said, "did you really mean one back-slash there?". You responded "yeah, one backslash", but I still don't believe you. In this case, it happens to work, but you should be aware that the back-slash is an escape character, which causes the next character to be interpreted differently. Try this in your interpreter: print "\a" # System bell - might cause your speaker to beep print "\t" # Tab character print "\n" # Newline character / sequence See http://www.python.org/doc/2.4.2/ref/strings.html for more details on the escape sequences that Python recognizes. Here's a summary: if the backslash + character is a special escape code, then replace it with that, otherwise assume the programmer meant a real backslash. That's dangerous, and will break when the name changes from one that starts with an L to one that starts with an A, B, F, N, etc. The safe way it to tell Python "Yes, I really want a backslash", which is indicated with the double backslash: print "\\library.zip" If you don't use the double backslash, you'll eventually have a problem, especially in Windows, which unfortunately uses the backslash as a directory seperator. You might also want to look at os.sep and the os.path.* functions, if you are interested in making your code work on different platforms. JW -- http://mail.python.org/mailman/listinfo/python-list
Re: Rethinking the Python tutorial
Here's my two cents - I started with the official tutorial. It seemed up to date to me. Things that changed from 2.4 to 2.5 changed in the tutorial as well. I still refer to it every few days, because it had been a useful reference for the basic data types. I like that it seemlessly links into the other documents, both online and in the local MS Help format. It took a couple of days to get through, and gave me enough of an introduction to the library that I could get started on the Python Challenge. I don't think it's broken enough to throw away completely. Bug reports filed at sf.net appear to be responded to quickly. I haven't tried "A Byte of Python", so I can't comment. I tried to learn from "Dive into Python", but I found that it went too quickly. I have a lot of C and C++ experience, but I needed the more basic stuff, like dictionaries, tuples, etc. explained in more detail. It was a very useful guide once I had the basics, but after my initial experience with it I put Python away for a few months. "Dive into Python" is not being kept up to date. The last revision was May 2004, and several things have changed since then. For instance, chapter 4, on introspection, creates a program called apihelper.py, which uses introspection and doc strings to print the usage of an object. This is all great stuff, which would be part of my toolkit, except that there is a built-in, help(), that does the same thing. I had to go to the downloaded source to find that out. In other cases, the tutorial still teaches to older versions of Python, sometimes with notes for the newer styles, sometimes without. Another downside is the use of internet sources for examples. For instance, his example for a web feed is http://diveintomark.org/xml/atom.xml, which replies with a "410 Gone". As you might guess, this was the author's server, and might have been removed because of all the people taking the tutorial. This would have to be fixed, to make chapters 11 and 12 make much sense. As for a wiki version of the tutorial, I think the MoinMoin docs are a good example. MoinMoin is a wiki engine running Python, and the documents are distributed with each engine. These documents can be seen on the project website, http://moinmoin.wikiwikiweb.de/HelpContents. There is a second wiki at http://moinmaster.wikiwikiweb.de/HelpContents , which contains the "master" documents. Those that want to help improve, correct, or translate documents do their work on this wiki. It lowers the number of pages that maintainers have to review, so that a consistant quality can be maintained. It also is a (slight) barrier to entry, so that casual users don't make random changes. I think the most important thing for a tutorial is a consistant style and a consistant idea of the user's capabilities. This is easiest with a single maintainer, but requires constant dilligence and a subdued ego for a collaborative document. -- http://mail.python.org/mailman/listinfo/python-list
Re: random playing soundfiles according to rating.
I think of it this way: you randomly pick a entry out of a dictionary, then roll a 100-side die to see if the pick is "good enough". Repeat until you find one, or give up. import random def rand_weighted_pick(weighted_picks): for i in range(100): name, prob = random.choice(weighted_picks) if prob >= random.randint(0,100): return name # Give up and return a random choice return random.choice(weighted_picks)[0] if __name__ == "__main__": test_vals = [("A",50),("B",30),("C",20)] dist = dict() for name, prob in test_vals: dist[name] = 0 for x in xrange(1000): dist[rand_weighted_pick(test_vals)] += 1 print "Expected: A = 500, B = 300, C = 200" print "Actual : A = %d, B = %d, C = %d"%(dist['A'], dist['B'], dist['C']) -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
On Wed, 18 Jan 2006 20:51:03 +, Roel Schroeven wrote: > I, Jim Wilson, schreef: >> >> I'm assured that in print ads the only "content" anyone reads is in >> picture captions, and you damn well better make sure your message is >> conveyed there. Any other "content" only wastes space. I see no reason >> to think that a web page should be designed using any other assumption. > > I don't agree. I read websites in search for information (content), not to > find advertisements. Yes, and I read Playboy for the interviews ;) > I agree that the information shouldn't be presented in an overly dense > way, Agreed. The main page should be like a slick book cover. It should grab you and leave you wanting more. I think the beta page does that pretty well. > but it should be there prominently and easily accessible. All you should have to do is open the book. Or click a link. > The site > should invite users to read the content, the contrary of many corporate > websites that seem to try to hide it, almost like the fineprint on a > contract. 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. I understand techy types want the details, but I don't doubt the details will be no more than two clicks away. Jim -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
On Wed, 18 Jan 2006 00:33:06 -0800, Tim N. van der Leeuw wrote: > What I especially dislike about the new website are the flashy pictures > on the front-page with no content and no purpose -- purely boasting but > nothing to back up your claims. > > (I wouldn't mind some sleek pictures there if they weren't desperatly > trying to advertise success-stories but instead would link to real > content!) 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'm assured that in print ads the only "content" anyone reads is in picture captions, and you damn well better make sure your message is conveyed there. Any other "content" only wastes space. I see no reason to think that a web page should be designed using any other assumption. If anything, Tim the Shorter (I presume he's shorter; he's not Dutch) has too much "content" and too few images. The beta page is a great improvement over the current "content-intensive" page. I recommend David Ogilvy's "Ogilvy on Advertising" for a enthusiastic but somewhat cynical view of the subject. It is a very old book, but nothing about human nature has changed since it was written. Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
On Sun, 15 Jan 2006 22:19:37 +, Tim Parkin wrote: > http://pyyaml.org/downloads/masterhtml/ > > Feedback appreciated ... Many thanks Again, with FF 1.0.7 (on FC4 Linux BTW), the left column no longer violates the right. However, "View>Page Style>large text" makes the button annotation smaller than "View>Page Style>Basic Page Style". Please understand, web programming is not my main axe. I'm in no way asserting my observations are meaningful ;). Jim Wilson Gainesville, FL -- http://mail.python.org/mailman/listinfo/python-list
Re: New Python.org website ?
On Fri, 13 Jan 2006 11:00:05 -0600, Tim Chase wrote: > http://tim.thechases.com/pythonbeta/pythonbeta.html > Very strange. With FF 1.0.7, I can just get the buttons to violate the next column if I "View>Page Style>Large Text", but I wouldn't have noticed it unless Tim had pointed it out. Tim's gifs are much worse than what I see. WIth ""View>Page Style>Basic Page Style", it looks really good. Jim Wilson Gainesvlle, FL -- http://mail.python.org/mailman/listinfo/python-list