Re: Adding through recursion
"[EMAIL PROTECTED]" <[EMAIL PROTECTED]> writes: > There is problaly a really simple answer to this, but why does this > function print the correct result but return "None": > > def add(x, y): > if x == 0: > print y > return y > else: > x -= 1 > y += 1 > add(x, y) > > print add(2, 4) > > result: > 6 > None Perhaps this hint will help: >>> print add(0,6) 6 6 -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Of course a weed-puller isn't of much *use* in the Garden of Eden, but it takes a while to figure that out. - Tim Peters -- http://mail.python.org/mailman/listinfo/python-list
Re: Documentation suggestions
Steven Bethard <[EMAIL PROTECTED]> writes: > [EMAIL PROTECTED] wrote: > > Iain> I like the Global Module Index in general - it allows quick access > > Iain> to exactly what I want. I would like a minor change to it though > > Iain> - stop words starting with a given letter rolling over to another > > Iain> column (for example, os.path is at the foot of one column, while > > Iain> ossaudiodev is at the head of the next), and provide links to each > > Iain> initial letter at the top of the page. > > > > I know it's not what you asked for, but give > > > > http://staging.musi-cal.com/modindex/ > > > > a try. See if by dynamically migrating the most frequently requested > > modules to the front of the section it becomes more manageable. > > That's pretty cool. What I don't know is how it would look after > thousands of people using it. I know that I probably only have 10 > modules or so that I consistently need to check the docs for. Your hack > above would conveniently place those all at the top if I was the only > user. But are those 10 modules the same 10 modules that other folks > need? I don't know... > > Of course, the only way to find out is to try... Or you can just look up the module you need to write a 'bot to constantly look up the docs for your favorite 10 modules. . . . -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson If it made sense, that would be a very powerful idea. - Bruce Eric Kaplan -- http://mail.python.org/mailman/listinfo/python-list
Re: global variables
Steve Holden <[EMAIL PROTECTED]> writes: > M.E.Farmer wrote: > > > Ok it has been a long day, > > In my reply to Steven Bethard , Steve should read Steven ;) > > > > M.E.Farmer > > > Well, since he signs himself "Steve" too I guess we'll just have to put > up with the ambiguities. Or perhaps, given my (lack of) typing skill, I > should just start signing myself "Stvev"? What's this doing *here*? I thought the discussion of the pitfalls of name rebinding was taking place in the "variable declaration" thread. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson People who write obscurely are either unskilled in writing or up to mischief. - Sir Peter Medawar -- http://mail.python.org/mailman/listinfo/python-list
Re: Tricky Dictionary Question from newbie
"Ric Da Force" <[EMAIL PROTECTED]> writes: > It is hard to explain but this is what I mean: > > Dict = {'rt': 'This is repeated', 'sr': 'This is repeated', 'gf': 'This is > not'} > > I want this to return a new dict with string keys and lists containing the > previous keys for repeated values. > > NewDict = {'This is repeated':['rt','sr'],'This is not':['gf']} NewDict = {} for x in Dict.keys(): try: NewDict[Dict[x]].append(x) except KeyError: NewDict[Dict[x]] = [x] -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson It is difficult for men in high office to avoid the malady of self-delusion.- Calvin Coolidge -- http://mail.python.org/mailman/listinfo/python-list
Re: Interleave merge pdf files
"Chirayu Krishnappa" <[EMAIL PROTECTED]> writes: > Hi, > > I need to scan documents with pages having printed matter on both > sides. It is easiest to stack them in the autosheet feeder and let it > scan. I end up with one file (say A.pdf) containing the odd pages in > sequence. Similarly, I can end up with B.pdf containing the even pages. > I want to combine them into result.pdf which contains A.1, B.1, A.2, > B.2, A.3, B.3, ... (A.1 = page 1 of A.pdf). > > Does someone know a simple way to achieve this? I noticed the other > thread on this newsgroup about merging lots of pdf files and > multivalent tools and pdftk were mentioned. However, I could not find a > way to do this using them. I am interested in another free tool or a < > 25 lines python script (which may use any freeware library) to do the > same. I face exactly the same problem. Based on examination of the pdftk man page I *think* it can be done by something like (untested): pdftk A.pdf burst output %04d_A.pdf pdftk B.pdf burst output %04d_B.pdf pdftk *_?.pdf cat output combined.pdf assuming fewer than 10,000 pages per document, of course. I would be interested in an alternative approach which does not generate a ton of intermediate pdfs. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson It is difficult for men in high office to avoid the malady of self-delusion.- Calvin Coolidge -- http://mail.python.org/mailman/listinfo/python-list
Re: negative integer division
Imbaud Pierre <[EMAIL PROTECTED]> writes: > integer division and modulo gives different results in c and python, > when negative numbers > are involved. take gdb as a widely available c interpreter > print -2 /3 > 0 for c, -1 for python. > more amazing, modulos of negative number give negative values! (in c). > from an algebraic point of view, python seems right, but I thought > python conformity to the underlying c compiler was a strong commitment, AIUI the C standard is silent on the issue, and hence the C behavior is implementation-dependent. Anyway back in 2000 I found and fixed a Y2K-related problem in an open-source C program (xvtdl) which was down to precisely this misbehavior. While diagnosing the problem I implemented the algorithm in Python for test purposes, and was led astray for a while by the fact that it *didn't* fail! A: 42 Q: What multiple of 7 did I add to the critical expression in the Zeller algorithm so it would remain nonnegative for the next few centuries? -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson People who write obscurely are either unskilled in writing or up to mischief. - Sir Peter Medawar -- http://mail.python.org/mailman/listinfo/python-list
Re: negative integer division
[EMAIL PROTECTED] (John Machin) writes: > [EMAIL PROTECTED] (Mark Jackson) wrote in message news:<[EMAIL PROTECTED]>... > > > > A: 42 > > > > Q: What multiple of 7 did I add to the critical expression in the Zeller > > algorithm so it would remain nonnegative for the next few centuries? > > What are you calling "the Zeller algorithm", and what is the "critical > expression"? A C function in calendar.c, encountered in the source code for xvtdl: int zeller (month, day, year) int month, day, year; { int century; month -= 2; /* Years start on March 1 so adjust standard date */ if (month < 1) { month += 12; year--; } century = year / 100; year = (int)year % (int)100; return ((int)((2.6 * month - 0.1) + day + year + year / 4 + century / 4 - century * 2) % 7); } The expression upon which "% 7" acts is negative when "year" is small. This caused errors beginning in March 2000; which could be deferred by adding a suitably-large multiple of 7 to the expression. The choice was obvious. :-) > I've no doubt you came across a stuffed-up date-to-days calculation > routine and fixed it, but it's a bit unfair to lumber Zeller with the > blame. If it was a days-to-date routine, then Zeller is not even > standing next to the real target. Fair enough, although I'm not responsible for having named the function (which appears to date from 1991). The original author is identified in the code (available at http://www.alumni.caltech.edu/~mjackson/xvtdl.html) and is findable via the Web; you might take the matter up with him. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson People who write obscurely are either unskilled in writing or up to mischief. - Sir Peter Medawar -- http://mail.python.org/mailman/listinfo/python-list
Re: How did you learn Python?
[EMAIL PROTECTED] (John Machin) writes: > "Jeffrey Maitland" <[EMAIL PROTECTED]> wrote in message news:<[EMAIL > PROTECTED]>... > > Well I would suggest the Python in a Nutshell and the Python Cookbook both > > by O'Reilly as references. They are great for a desktop reference and I > > check them first before I google/search else where for answers. Being they > > are reference books they or more on aide then a teaching device however I > > have learned from those books how to use certain standard classes, such as > > the re class for example. > > Somebody called O'Reilly taught you that Python has "standard > classes", one of which is "re"??? Hmmm, can't have been O'Reilly the > publisher; must have been O'Reilly the builder. Or possibly O'Reilly the pundit. Lucky he didn't tell you Python has falafels. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson You should always save hyperbole until you really need it. - Hobbes (Bill Watterson) -- http://mail.python.org/mailman/listinfo/python-list
Re: Filename case-insensitivity on OS X
Dan Lowe <[EMAIL PROTECTED]> writes: > Think about it - how many things used by average people are case > sensitive? Passwords? That's about it. (And judging by most user > passwords I have seen, they're almost all lowercase anyway.) Email > addresses, URLs, the search box in Google, your AOL or Jabber buddy > list: all case-insensitive. Not all URLs. Compare, for example: http://www.python.org/doc/Summary.html http://www.python.org/doc/summary.html -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Those who can make you believe absurdities can make you commit atrocities. - Voltaire -- http://mail.python.org/mailman/listinfo/python-list
Re: Indentation for code readability
"DE" <[EMAIL PROTECTED]> writes: > Hello, > > Here is what I do in C++ and can not right now in python : > > pushMatrix() > { > drawStuff(); > > pushMatrix(); > { > drawSomeOtherStuff() > } > popMatrix(); > } > popMatrix(); > > The curly brackets have no functional meaning but increase the > readability significantly. You are e. e. cummings, and I claim my £5. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson Every 10 years we say to ourselves, "If only we had done the right thing 10 years ago." - Thomas Friedman -- http://mail.python.org/mailman/listinfo/python-list
Re: Characters contain themselves?
Rene Pijlman <[EMAIL PROTECTED]> writes: > WENDUM Denis 47.76.11 (agent): > >While testing recursive algoritms dealing with generic lists I stumbled > >on infinite loops which were triggered by the fact that (at least for my > >version of Pyton) characters contain themselves. > > No, strings contain characters. And 'a' is a string consisting of one > character. > > "The items of a string are characters. There is no separate character > type; a character is represented by a string of one item." > http://docs.python.org/ref/types.html > > (One item of what type, one might ask) Good point. ". . .represented by a string of length one" would be better. -- Mark Jackson - http://www.alumni.caltech.edu/~mjackson An information system based on theory isolated from reality is bound to fail. - Mitch Kabay -- http://mail.python.org/mailman/listinfo/python-list