Re: [Tutor] Difference between %f and %F string formatting?

2017-04-26 Thread Tim Peters
[boB Stepp , on %i/%d and %f/%F] > Hmm. I'm surprised this slight distinction was worth keeping two > format codes that otherwise do the same thing. Is there an actual > need for these due to Python being implemented behind the scenes in C? The implementation is irrelevant to this. What is rele

Re: [Tutor] Difference between %f and %F string formatting?

2017-04-26 Thread Tim Peters
[boB Stepp ] > My Google-fu must be weak tonight. Look here: https://en.wikipedia.org/wiki/Printf_format_string > I cannot find any discernible > difference between '%f' % and '%F' % > . Is there any or do they duplicate > functionality? If the latter, why are there two ways of doing the

Re: [Tutor] Question about the memory manager

2016-01-10 Thread Tim Peters
[Albert-Jan Roskam ] > I just found a neat trick to free up an emergency stash of memory in > a funtion that overrides sys.excepthook. The rationale is that all > exceptions, including MemoryErrors will be logged. > The code is below. My question: is that memory *guaranteed* to be > freed right aft

Re: [Tutor] Faster list searching?

2009-11-18 Thread Tim Peters
[Luke Paireepinart] >> This is really just a round-about way of using sets. >> I don't really want to give a code-sample unless he's confirmed he's not >> doing this as homework, but the set version is much more simple (shorter >> code that makes more sense) and extremely quick as well.  If you're

Re: [Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread Tim Peters
[kb1...@aim.com] > I'm running a test to find what the experimental average of a d20 is, I don't know what "a d20" is, but your code is picking integers uniformly at random between 1 and 18 inclusive. The expected value is therefore (1+18)/2.0 = 9.5. > and came across a strange bug in my code. >

Re: [Tutor] Is my style OK in this elementary student exercise?

2009-07-05 Thread Tim Peters
[Angus Rogers, suffering eval-angst] > ... > On the other hand, so long as I AM only executing the function > myself, I am no more at risk than I already am every single time > I type a command into a Python interpreter, of any description. > (A somewhat Existentialist thought, perhaps!  Virtual su

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Tim Peters
[Angus Rodgers] > ... > If I started to agitate for changes to a marginal and little-used > feature of the language within days of starting to learn it, might > I not quickly earn a reputation as a crank?  8-P If that's your /goal/, it would be easier to rant about some imagined flaw in the ring o

Re: [Tutor] Floor and modulus for complex arguments

2009-07-03 Thread Tim Peters
[Angus Rodgers] > I'm a little confused by: (i) the definition of the modulus and > floor division functions for complex arguments; Perhaps you're confused by the current definitions simply because they don't make good sense. > (ii) the fact that these functions for complex arguments are > now "

Re: [Tutor] How trustworthy are pseudo-random numbers?

2008-10-02 Thread Tim Peters
[Alec Henriksen] > How trustworthy is the "randomness" generated by the random module? Python uses the Mersenne Twister algorithm for generating pseudo-random numbers, and that's one of the highest-quality methods known. You can read more about it, e.g., here: http://en.wikipedia.org/wiki/Me

Re: [Tutor] 6x6 word square solver too slow

2008-04-28 Thread Tim Peters
[Jeff Younker] >> I'd suggest googling for 'trie'. Tries are method of >> indexing sets of strings by prefix. [R. Alan Monroe] > Ah, will look it up. Or you can puzzle it out from the attached program ;-) > ... > In the meantime, my current version is > much improved - it caches rejects, so

Re: [Tutor] Rounding a float to n significant digits

2006-11-30 Thread Tim Peters
[Dick Moores] > ... > But isn't there a PRECISE answer to my question? Of course ;-) > Or is it OT? Well, it's really more a question about your machine's floating-point hardware than about Python. Good explanations of exact limits for IEEE-754 floating-point hardware can be found many places o

Re: [Tutor] A Million Sevens

2006-11-17 Thread Tim Peters
[Thomas] > Earlier today I typed the following into my pythonwin interactive > interpreter in windows xp: > > >>> int('7' * 10 ** 6) > > I expected either an error message Unlikely, if your box has enough RAM to run WinXP :-) > or it to get stuck and require me to stop the process manually. Not

Re: [Tutor] Equivalent to perl -e

2006-10-15 Thread Tim Peters
[Chris Lasher] > My professor and advisor has been "inspired" by me to give Python a > try. He's an avid Perl user, and challenged me with the following: > > What is the Python equivalent to perl -e ''? The initally attractive but unsatisfying answer is: python -c '' The reason it's "unsatis

Re: [Tutor] What are these things urandom() returns?

2006-10-11 Thread Tim Peters
[Tim Peters] >> If you want /true/ randomness, you can buy a certified hardware random >> number generator, based on non-deterministic physical processes (like >> timing radioactive decay, or measuring thermal noise). [Terry Carroll] > Why buy when you can borrow?: Speed

Re: [Tutor] What are these things urandom() returns?

2006-10-10 Thread Tim Peters
[Dick Moores] >>> Would this be a better random source than choice([0,1]), which uses >>> random()? [Tim Peters] >> "Better" as measured against what criteria? [Dick] > I meant would it be closer to true randomness than random(), even if > much slower? D

Re: [Tutor] What are these things urandom() returns?

2006-10-10 Thread Tim Peters
[Dick Moores] ... > I'm thinking that just for the hell of it I could use urandom() as a > source of random decimal digits. You could, yes. > Or in a coin tossing program. Here's a list of 7817 '1's and 0's > generated by urandom(): Note that the length of the list will vary from run to run. Si

Re: [Tutor] Can my code be optimized any further (speed-wise)?

2006-10-08 Thread Tim Peters
[Geoframer] > The last few days i've been learning python and have been doing this by > trying to solve problems for a programming competition. I assume you're talking about: http://www.spoj.pl/problems/FCTRL/ If so, you'll note that I'm tied for the fastest Python solution there ;-) The /g

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Tim Peters
[Tim Peters] >> You would in this case, and that would be wrong. In fp you'd get an >> approximation to the exact n * (1./5 + 1./5**2 + ...) == n/4. (use >> the rule for the sum of an infinite geometric series). For example, >> that way you'd compute that 4

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Tim Peters
[Tim Peters] >> For a fun :-) exercise, prove that the number of trailing zeroes in n! >> is the sum, from i = 1 to infinity, of n // 5**i (of course as soon as >> you reach a value of i such that n < 5**i, the quotient is 0 at that i >> and forever after). >> >

Re: [Tutor] puzzled again by decimal module

2006-08-18 Thread Tim Peters
[Dick Moores, computes 100 factorial as 9332621544394415268169923885626670049071596826438162146859296389521753229915608941463976156518286253697920827223758251185210916864 but worries about all the trailing zeros] > Yes, I'm sure you are. I'd forgotten about all tho

Re: [Tutor] bounced email

2006-06-06 Thread Tim Peters
[Kermit Rose] > My last email to you bounced. > > > Why? > > From: [EMAIL PROTECTED] > Date: 06/06/06 20:30:49 > To: [EMAIL PROTECTED] > Subject: The results of your email commands > > > The results of your email command are provided below. Attached is your > original message. > > - Unprocessed: >

Re: [Tutor] checking diagonals on a chessboard

2006-04-13 Thread Tim Peters
es a row #, col #, and diag #. > > Scratching your head over how to number the diagonals I'll leave to you. > They counted 30 diagonals, so if you come up with a different count, you > either have an original approach or have blundered somewhere. > > (Hopefully that was the k

Re: [Tutor] Doctest, object references and the use of ellipses

2006-04-01 Thread Tim Peters
[Tim Peters] >> That "should work", provided there aren't differences in whitespace >> that are invisible to us in this medium. For example, if, in your >> source file, there's actually a (one or more) trailing space on your >> line of expected output,

Re: [Tutor] Doctest, object references and the use of ellipses

2006-04-01 Thread Tim Peters
[Don Taylor] > I am trying to use Doctest and am having trouble using the ellipsis > feature when trying to match an object reference. > > Here is the code: > > def add_change_listener(self, listener): > ''' > > Returns list of listeners just for testing. > >>> def m

Re: [Tutor] [Python-Dev] small floating point number problem

2006-02-08 Thread Tim Peters
[Raymond Hettinger] > ... > The asymmetric handling of denormals by the atof() and ftoa() functions is > why you see a difference. A consequence of that asymmetry is the breakdown > of the expected eval(repr(f))==f invariant: Just noting that such behavior is a violation of the 754 standard for s

Re: [Tutor] remove from mailing list

2006-01-28 Thread Tim Peters
[kristi holsinger] > please remove [EMAIL PROTECTED] from the mailing list! thank you This is self-service. You need to go to http://mail.python.org/mailman/listinfo/tutor and unsubscribe youself (look for the "Unsubscribe or edit options" button near the bottom of the page). _

Re: [Tutor] Python RE uses DFA or NFA for string check?

2006-01-10 Thread Tim Peters
[Intercodes] > This question is just out of curiosity. I am working with this dragon book. > From what I have learnt so far, RE uses either NFA or DFA to check whether > the string is accepted or not. (Correct?) In the world of "computer science" regular expressions, yes. But the things _called_

Re: [Tutor] is mxDateTime recommended?

2005-10-21 Thread Tim Peters
[Lance E Sloan] > ... > (I think it's a little too bad that the timedelta class represents all > deltas as days and seconds. And microseconds. > That must be why they don't support months, since months have > different lengths. IMHO...) That's right. It's hard to argue about what days, seconds

Re: [Tutor] Struct headspinner

2005-10-12 Thread Tim Peters
[Liam Clarke] > Erm, can someone please aid me? I'm using Windows XP, haven't tested > this code on Linux yet, but, well watch this... > > '<' indicates little-endian, @ indicates native. i is an integer, Yes x 3. > q is a long. No. q in native mode is C "long long" on Linux, or "_int64" on Win

Re: [Tutor] Strange XP stdin behaviour.

2005-08-27 Thread Tim Peters
[Alan Gauld] > Thanks Danny, interesting link in that it shows a solution I > didn't know about in the one-liner at the bottom of the discussion. > > But really I was hoping someone could explain *why* there is a > difference. If PATHEXT can detect that intest.py needs to be run > through Python w

Re: [Tutor] quick PIL question

2005-06-02 Thread Tim Peters
[Max Noel] > ... > This is where the palette comes into play. Each 256-color image > has a palette, which is basically an array of length 256, where each > element is a (24-bit RGB) color. The color data for each pixel in the > image is actually an index in this array. Adding a bit of detail,

Re: [Tutor] character format

2005-05-11 Thread Tim Peters
[D. Hartley] > Max - yep, and the hint was "BUSY" (... BZ...)... > > Unfortunately that hint doesnt lead me anywhere (except to bz2, which > involves compression, and didnt seem very likely). > > I went through and removed all the \x## 's that represented > 'unprintable'/carraigereturn/etc characte

Re: [Tutor] Python riddles

2005-05-08 Thread Tim Peters
[Jacob S.] > Ok, I'm stuck on #4 > > I tried using urllib like the source hints... but, when I run my automation > of the process of typing in the new nothing, I run through about 15 pages, > then I notice that they add an extra number in the text. > 60167 or something like that > This is encouragi

Re: [Tutor] python challenges

2005-05-06 Thread Tim Peters
[Max Noel] ... > In fact, I am (and will probably give up) at number 9. I was > able to do #7 without using PIL, but it seems that it is once again > necessary for #9, and I'm not gonna be able to use a workaround this > time. What do you have against PIL ? Processing images has played no par

Re: [Tutor] Subract Month From Date

2005-05-03 Thread Tim Peters
[Gooch, John] > Thank you for the idea, I could have been more clear that days part of the > date isn't important. Here is what I came up with: > >currentDate = datetime.datetime.fromtimestamp( time.time() ) Easier: today = datetime.date.today() >archMonth = 0 >archYear = 0 >

Re: [Tutor] str.split and quotes

2005-04-07 Thread Tim Peters
[Tony Meyer] ... >> Somewhat ironically, one of the tenets of Python is "there should be one-- >> and preferably only one --obvious way to do it." (type "import this" at an [Marilyn Davis] > In this case, there is: regular expressions. :^) > > "Obvious" doesn't mean we can, necessarily, all see i

Re: [Tutor] Unexpected result from decimal

2005-01-19 Thread Tim Peters
[Jacob S.] >I'm having a problem that is ticking me off. (to put it lightly) > Why does decimal do this -- I thought that getcontext().prec > was number of decimal places? It's unclear what you mean by "decimal places". From context, you _appear_ to mean "number of decimal digits after the r

Re: [Tutor] Faster procedure to filter two lists . Please help

2005-01-15 Thread Tim Peters
[Alan Gauld] > OK, The timbot's word is good enough for me, I won't bother > looking at the code, I'll revert to my previous assumption! :-) It's educational to look at the code anyway . Here it is, from Python's listobject.c: static int list_length(PyListObject *a) { return a->ob_size;

Re: [Tutor] Faster procedure to filter two lists . Please help

2005-01-15 Thread Tim Peters
[Gonçalo Rodrigues] > It this correct? Python lists are not linked-lists (as in Scheme, for > example). They are more like arrays (or vectors in C++/Java) with a > little more sofistication built into them to allow, for example, to > amortize over time a sequence of append operations. But in a nuts

Re: [Tutor] am I missing another simpler structure?

2004-12-15 Thread Tim Peters
[Brian van den Broek] > in Marc's check_range thread, I had proposed: > > def check_in_range(value): > > in_range = False > if 9 < value < 90: > in_range = True > return in_range > > and DogWalker suggested the better: > > def check_in_range(value): > return 9 < value < 90

Re: [Tutor] turning a number into a formated string

2004-12-15 Thread Tim Peters
[Ertl, John] > I need to take a number and turn it into a formatted string. > The final output needs to look like when the X is the > integer part padded on the left and Y is the decimal part padded > on the right. > I figured I could split the number at "." and then use zfill or > some

Re: [Tutor] Complex roots

2004-12-12 Thread Tim Peters
[Dick Moores] >>> Actually, I'm trying to write a Python script that computes all 3 >>> roots of a cubic equation. Do you happen to have one tucked >>> away in your store of wisdom and tricks? (One for real coefficients >>> will do). [Tim Peters] >>

Re: [Tutor] Complex roots

2004-12-10 Thread Tim Peters
[Dick Moores] > Aw, that's just amazing. Well, complex numbers are amazing in many ways. The code is actually obvious, if you understand the motivation. Polar coordinates are more natural for complex * / and **. If you a view a complex number c as a vector in the complex plane (from the origin

Re: [Tutor] Complex roots

2004-12-09 Thread Tim Peters
[Dick Moores] > VERY helpful, Matt. Thanks. > > One question: This seems to not compute accurately at all > when the imaginary part of number=complex() is other than 0. That's just because the math was wrong . Starting with theta = 0.0 *assumed* the imaginary part is 0, although I can't guess wh

Re: [Tutor] Re: Could I have used time or datetime modules here?

2004-12-07 Thread Tim Peters
[Dick Moores] ... > Brian, where did you learn about the ".seconds". And > the .year, .month,.day of > > "alarm_datetime = datetime.datetime(now.year + 4, now.month, > now.day, alarm_hour, alarm_minute)"? > > Does this come from a general knowledge of OOP, or is it > somewhere in the Pytho

Re: [Tutor] Re: Could I have used time or datetime modules here?

2004-12-07 Thread Tim Peters
[Brian van den Broek] ... > Or, so I thought. I'd first tried getting the alarm datetime by simply > taking the date component of datetime.datetime.now() and adding > to the day value. That works fine, provided you are not on the last > day of the month. But, when checking boundary cases before > p

Re: [Tutor] Accuracy of time.sleep()

2004-12-04 Thread Tim Peters
[Dave S <[EMAIL PROTECTED]>] > OK I may be pushing it, ;-) Yup . > I need a script to sleep from any point to 8:05AM when in needs to > re-start. > > So I calculate the number of seconds with the following > > def secs_till_805(): ># Returns the number of seconds till 8:05AM > >s