Re: [Python-ideas] Re: Magnitude and ProtoMagnitude ABCs — primarily for argument validation

2020-03-10 Thread Tim Peters via Python-list
[Marco Sulla ] > Excuse me, Tim Peters, what do you think about my (probably heretical) > proposal of simply raising an exception instead of return a NaN, like > Python already do for division by zero? Sorry, I'm missing context. I don't see any other message(s) from you in th

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Tim] >> Sorry, I'm not arguing about this any more. Pickle doesn't work at >> all at the level of "count of bytes followed by a string". [Random832 ] > The SHORT_BINBYTES opcode consists of the byte b'C', followed by *yes > indeed* "count of bytes followed by a string". Yes, some individual opc

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Random832 ] > Would allowing a 16-byte string in the future have increased the storage > occupied by a 10-byte string today? Would allowing a third argument in > the future have increased the storage occupied by two arguments today? > As far as I can tell the pickle format for non-primitive types

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Tim] >> Because all versions of Python expect a very specific pickle layout >> for _every_ kind of pickled object (including datetimes).. Make any >> change to the pickle format of any object, and older Pythons will >> simply blow up (raise an exception) when trying to load the new pickle >> - or

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Random832 ] > A) I'm still not sure why, but I was talking about adding an int, not a > timedelta and a string. > > B) Older python versions can't make use of either utcoffset or fold, but > can ignore either of them. I don't even see why they couldn't ignore a > timedelta and a string if we felt

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Tim] >> It depends on how expensive .utcoffset() >> is, which in turn depends on how the tzinfo author implements it. [Alex] > No, it does not. In most time zones, UTC offset in seconds can be computed > by C code as a 4-byte integer Which is a specific implementation of .utcoffset(). Which li

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Random832 ] Whether or not datetimes stored tm_gmtoff and tm_zone workalikes has no effect on semantics I can see. If, in your view, they're purely an optimization, they're just a distraction for now. If you're proposing to add them _instead_ of adding `fold`, no, that can't work, for the pick

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Tim] >> It would be nice to have! .utcoffset() is an expensive operation >> as-is, and being able to rely on tm_gmtoff would make that dirt-cheap >> instead. [Alex] > If it is just a question of optimization, Yes. If it's more than just that, then 495 doesn't actually solve the problem of get

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Tim] >> So, on your own machine, whenever daylight time starts or ends, you >> manually change your TZ environment variable to specify the newly >> appropriate eternally-fixed-offset zone? Of course not. [Random832 ] > No, but the hybrid zone isn't what gets attached to the individual > struct t

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Guido] >> Wouldn't it be sufficient for people in Creighton to set their timezone to >> US/Central? IIUC the Canadian DST rules are the same as the US ones. Now, >> the question may remain how do people know what to set their timezone to. >> But neither pytz nor datetime can help with that -- it i

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-14 Thread Tim Peters
[Tim] >> pytz solves it by _never_ creating a hybrid tzinfo. It only uses >> eternally-fixed-offset tzinfos. For example, for a conceptual zone >> with two possible total UTC offsets (one for "daylight", one for >> "standard"), there two distinct eternally-fixed-offset tzinfo objects >> in pytz.

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-13 Thread Tim Peters
[Guido] > Wouldn't it be sufficient for people in Creighton to set their timezone to > US/Central? IIUC the Canadian DST rules are the same as the US ones. Now, > the question may remain how do people know what to set their timezone to. > But neither pytz nor datetime can help with that -- it is up

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-13 Thread Tim Peters
[Tim] >> Whatever time zone the traveler's railroad schedule uses, so long as >> it sticks to just one [Laura] > This is what does not happen. Which is why I have written a python > app to perform conversions for my parents, in the past. So how did they get the right time zone rules for Creighto

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-13 Thread Tim Peters
[Laura] >>> But I am not sure how it is that a poor soul who just wants to print a >>> railway schedule 'in local time' is supposed to know that Creighton is >>> using Winnipeg time. [Tim] >> I'm not sure how that poor soul would get a railway schedule >> manipulable in Python to begin with ;-) [

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-13 Thread Tim Peters
[Tim] >> Hi, Laura! By "zoneinfo" here, we mean the IANA (aka "Olson") time >> zone database, which is ubiquitous on (at least) Linux: >> >>https://www.iana.org/time-zones >> >>So "will a wrapping of zoneinfo handle XYZ?" isn't so much a question >>about the wrapping as about what's in the IAN

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-13 Thread Tim Peters
[Alex] >>I will try to create a zoneinfo wrapping prototype as well, but I will >>probably "cheat" and build it on top of pytz. [Laura Creighton] > My question, is whether it will handle Creighton, Saskatchewan, Canada? > Creighton is an odd little place. Like all of Saskatchewan, it is > in the

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-12 Thread Tim Peters
[Alex] >>> I will try to create a zoneinfo wrapping prototype as well, but I will >>> probably "cheat" and build it on top of pytz. [Tim] >> It would be crazy not to ;-) Note that Stuart got to punt on "the >> hard part": .utcoffset(), since pytz only uses fixed-offset classes. >> For a prototy

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-12 Thread Tim Peters
[Tim] >> Me too - except I think acceptance of 495 should be contingent upon >> someone first completing a fully functional (if not releasable) >> fold-aware zoneinfo wrapping. [Alex] > Good idea. How far are you from completing that? In my head, it was done last week ;-) In real life, I'm runn

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-12 Thread Tim Peters
[Guido] >> Those pytz methods work for any (pytz) timezone -- astimezone() with a >> default argument only works for the local time zone. {Alex] > That's what os.environ['TZ'] = zonename is for. The astimezone() method > works for every timezone installed on your system. Try it - you won't even

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-12 Thread Tim Peters
>>> If there are not, maybe the intended semantics should go >> > by the wayside and be replaced by what pytz does. >> Changing anything about default arithmetic behavior is not a >> possibility. This has been beaten to death multiple times on this >> mailing list already, and I'm not volunteerin

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-12 Thread Tim Peters
[] > My context is that I am working on an idea to include utc offsets in > datetime objects (or on a similar object in a new module), as an > alternative to something like a "fold" attribute. and since "classic > arithmetic" is apparently so important, Love it or hate it, it's flatly impossible t

Re: [Datetime-SIG] Are there any "correct" implementations of tzinfo?

2015-09-12 Thread Tim Peters
> I was trying to find out how arithmetic on aware datetimes is "supposed > to" work, and tested with pytz. When I posted asking why it behaves this > way I was told that pytz doesn't behave correctly according to the way > the API was designed. You were told (by me) that its implementation of tzi

Re: TopSort in Python?

2008-01-20 Thread Tim Peters
pyright (c) 1999-2008 Tim Peters Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,

Re: Signed zeros: is this a bug?

2007-03-11 Thread Tim Peters
[attribution lost] ... >>> Yup: the workaround seems to be as simple as replacing all occurrences >>> of -0.0 with -(0.0). I'm embarrassed that I didn't figure this out >>> sooner. >>> >>> >>> x, y = -(0.0), 0.0 >>> >>> x, y >>> (-0.0, 0.0) [Alex Martelli] >> Glad it works for you, but it's the

Re: doctest problem with null byte

2007-01-25 Thread Tim Peters
[Stuart D. Gathman] > I am trying to create a doctest test case for the following: > > def quote_value(s): > """Quote the value for a key-value pair in Received-SPF header > field if needed. No quoting needed for a dot-atom value. > > >>> quote_value(r'abc\def') > '"abcdef"

Re: Maths error

2007-01-13 Thread Tim Peters
[Nick Maclaren] >> ... >> Yes, but that wasn't their point. It was that in (say) iterative >> algorithms, the error builds up by a factor of the base at every >> step. If it wasn't for the fact that errors build up, almost all >> programs could ignore numerical analysis and still get reliable >> a

Re: Maths error

2007-01-10 Thread Tim Peters
[Tim Peters] ... >> Huh. I don't read it that way. If it said "numbers can be ..." I >> might, but reading that way seems to requires effort to overlook the >> "decimal" in "decimal numbers can be ...". [Nick Maclaren] > I wouldn'

Re: Maths error

2007-01-09 Thread Tim Peters
[Tim Peters] ... >|> Well, just about any technical statement can be misleading if not >|> qualified to such an extent that the only people who can still >|> understand it knew it to begin with <0.8 wink>. The most dubious >|> statement here to my eyes is the i

Re: Maths error

2007-01-09 Thread Tim Peters
[Rory Campbell-Lange] >>> Is using the decimal module the best way around this? (I'm >>> expecting the first sum to match the second). It seem >>> anachronistic that decimal takes strings as input, though. [Nick Maclaren] >> As Dan Bishop says, probably not. The introduction to the decimal >> mod

Re: Q: About a programming problem with Python!

2007-01-08 Thread Tim Peters
[followups set to comp.lang.python] [Danny] > I am just getting into OOP using Python and > because of the floating point of large integer (L) > square roots all the decimal expansions are truncated. > This has created a problem because I need these > decimal expansions in my algorithm other wise

Re: a question on python dict

2007-01-03 Thread Tim Peters
[Tim Peters] >> ... >> Taking my response out of context to begin with doesn't really change >> that I answered the question he asked ;-) [Fredrik Lundh] > welcome to comp.lang.python. > > Thanks for the welcome! It's tough to be a newbie here ;-) -- ht

Re: a question on python dict

2006-12-31 Thread Tim Peters
[Tim Peters] >>>> You should also note that copying a dict key or value (no matter of >>>> what type) consists in its entirety of copying one machine address (a >>>> 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] >>> Actually,

Re: a question on python dict

2006-12-31 Thread Tim Peters
[Tim Peters] >> You should also note that copying a dict key or value (no matter of >> what type) consists in its entirety of copying one machine address (a >> 4- or 8-byte pointer, depending on platform). [Lawrence D'Oliveiro] > Actually, no. It also consists of updatin

Re: a question on python dict

2006-12-20 Thread Tim Peters
[EMAIL PROTECTED] > Python dict is a hash table, isn't it? Yup. > I know that hashtable has the concept of "bucket size" and "min bucket > count" stuff, Some implementations of hash tables do. Python's does not. Python's uses what's called "open addressing" instead. > and they should be confi

Re: merits of Lisp vs Python

2006-12-13 Thread tim . peters
[Bill Atkins] >> (Why are people from c.l.p calling parentheses "brackets"?) [Kaz Kylheku] > Because that's what they are often called outside of the various > literate fields. For example, the English are "outside of the various literate fields"? FWIW, Python documentation consistently uses the

Re: not a big deal or anything, but, curiously:

2006-12-12 Thread Tim Peters
[Simon Schuster] > following this tutorial, Which tutorial? > I copied and pasted: > > from string import * > > cds = """atgagtgaacgtctgagcattagctccgtatatcggcgcacaaa > tttcgggtgccgacctgacgcgcccgttaagcgataatcagtttgaacagctttaccatgcggtg > ctgcgccatcaggtggtgtttctacgcgatcaagctattacgccgcagcagca

Re: merits of Lisp vs Python

2006-12-11 Thread Tim Peters
[Paddy] >> http://en.wikipedia.org/wiki/Doctest [Kaz Kylheku] > I pity the hoplelessly anti-intellectual douche-bag who inflicted this > undergraduate misfeature upon the programming language. As a blind misshapen dwarf, I get far too much pity as it is, but I appreciate your willingness to sha

Re: Python spam?

2006-11-30 Thread Tim Peters
[Aahz] >>> Anyone else getting "Python-related" spam? So far, I've seen messages >>> "from" Barry Warsaw and Skip Montanaro (although of course header >>> analysis proves they didn't send it). [Thomas Heller] >> I'm getting spam not only from Barry, but also from myself ;-) with >> forged headers

Re: syntax error in sum(). Please explicate.

2006-11-18 Thread Tim Peters
[Matt Moriarity] >> try surrounding your sum argument in brackets: >> >> sum([phi(x // ps[i+1], i) for i in range(a)]) >> >> instead of: >> >> sum(phi(x // ps[i+1], i) for i in range(a)) [Michael Press] > Thank you. That makes it work. But is a wrong solution ;-) As others have suggested, it's a

Re: Decimal() instead of float?

2006-11-17 Thread Tim Peters
[Michael B. Trausch] >> Let's say that I want to work with the latitude 33.6907570. In Python, >> that number > can not be stored exactly without the aid of >> decimal.Decimal(). >> >> >>> 33.6907570 >> 33.6907568 >> >>> >> >> As you can see, it loses accuracy after the 6th decimal place.

Re: Is there a commas-in-between idiom?

2006-11-05 Thread Tim Peters
]Ernesto García García] > it's very common that I have a list and I want to print it with commas > in between. How do I do this in an easy manner, whithout having the > annoying comma in the end? > > > > list = [1,2,3,4,5,6] > > # the easy way > for element in list: >print element, ',', > > pr

Re: ZODB: single database, multiple connections

2006-10-30 Thread Tim Peters
[Petra Chong] > I am using Python 2.3 and ZODB (without the rest of Zope) with the > following pattern: > > * One process which writes stuff to a ZODB instance (call it test.db) > * Another process which reads stuff from the above ZODB instance > test.db > > What I find is that when the first proce

Re: Dealing with multiple sets

2006-10-25 Thread Tim Peters
[John Henry] > If I have a bunch of sets: > > a = set((1, 2, 3)) > b = set((2, 3)) > c = set((1, 3)) > > > What's the cleanest way to say: > > 1) Give me a list of the items that are in all of the sets? (3 in the > above example) list(a & b & c) > 2) Give me a list of the items that are not

Re: File read-write mode: problem appending after reading

2006-10-14 Thread Tim Peters
[Frederic Rentsch] > Thanks a lot for your input. I seemed to notice that everything > works fine without setting the cursor as long as it stops before the end > of the file. Is that also a coincidence that may not work? "if you want to read following a write, or write following a read, on

Re: File read-write mode: problem appending after reading

2006-10-13 Thread Tim Peters
[Frederic Rentsch] >Working with read and write operations on a file I stumbled on a > complication when writes fail following a read to the end. > > >>> f = file ('T:/z', 'r+b') > >>> f.write ('abcdefg') > >>> f.tell () > 30L > >>> f.seek (0) > >>> f.read () > 'abcdefg' > >>> f.flush ()

Re: hundreds of seconds?

2006-10-11 Thread Tim Peters
[EMAIL PROTECTED] > ... > G5-fiwihex:~ eur$ python > Python 2.3.5 (#1, Mar 20 2005, 20:38:20) > [GCC 3.3 20030304 (Apple Computer, Inc. build 1809)] on darwin > Type "help", "copyright", "credits" or "license" for more information. > >>> import time > >>> time.time() > 1160580871.258379 > >>> > > M

Re: Python license question

2006-10-08 Thread Tim Peters
[Martitza] > Mr. Peters: Na, my father's dead -- you can call me Uncle Timmy ;-) > Thank you for so kindly taking the time to resolve my misunderstandings > and to elaborate on the intent of the PSF. > > In particular, thank you for explaining in plain language how the > licenses stack. I'm sure

Re: Python license question

2006-10-08 Thread Tim Peters
[Martitza] |> Hi. I work for a small company (actually in process of forming) > interested in embedding or extending python as part of our commercial > non-open-source product. We have legal counsel, but are interested in > the spirit as well as the letter of the law. Not much seems to have > be

Re: Python to use a non open source bug tracker?

2006-10-07 Thread Tim Peters
[Giovanni Bajo] > I understand your concerns, but I have to remember you that most bug reports > submitted by users go totally ignored for several years, or, better, forever. > I > do not have a correct statistic for this, Indeed you do not. > but I'm confident that at least 80% of the RFE or pa

Re: Question about turning off garbage collection

2006-10-05 Thread Tim Peters
[David Hirschfield] > Question from a post to pygtk list...but it probably would be better > answered here: > > I encountered a nasty problem with an external module conflicting with > my python threads recently, and right now the only fix appears to be to > turn off garbage collection while the cr

Re: weakSet

2006-10-05 Thread Tim Peters
[EMAIL PROTECTED] > Has anyone ever think about a set wich references its elements weakly ? Yes, and there are excruciating subtleties. I only implemented as much of one as ZODB needed at the time: # A simple implementation of weak sets, supplying just enough of Python's # sets.Set interface for

Re: Python to use a non open source bug tracker?

2006-10-04 Thread Tim Peters
[Ben Finney] >> I don't see why you're being so obtuse [Terry Reedy] > I think name calling is out of line here. Name calling is always out of line on comp.lang.python. Unless it's done by Guido. Then it's OK. Anyone else, just remind them that even Hitler had better manners. That always calm

Re: Is this a bug? Python intermittently stops dead for seconds

2006-10-01 Thread Tim Peters
[Charlie Strauss] >>> level0: newly created objects >>> level1: objects that survived 1 round of garbage collection >>> level2: objects that survivied 2+ rounds of gargbage collection >>> >>> Since all of my numerous objects are level2 objects, and none of >>> them are every deallocated, then I

Re: Is this a bug? Python intermittently stops dead for seconds

2006-10-01 Thread Tim Peters
[charlie strauss] > Steve, digging into the gc docs a bit more, I think the behaviour I am seeing > is still > not expected. Namely, the program I offered has no obvious place where > objects > are deallocated. The way GC is supposed to work is thate there are three > levels of > objects > > l

Re: Is this a bug? Python intermittently stops dead for seconds

2006-10-01 Thread Tim Peters
[charlie strauss] > I want to clarify that, on my computer, the first instance of the gap occurs > way > before the memory if filled. (at about 20% of physical ram). Additionally the > process monitor shows no page faults. Python has no idea of how much RAM you have, or even of how much RAM it's

Re: Is this a bug? Python intermittently stops dead for seconds

2006-10-01 Thread Tim Peters
[Steve Holden, "pins the blame" for pauses on periodic cyclic gc] > ... > So basically what you have here is a pathological example of why it's > sometimes wise to disable garbage collection. Tim, did I miss anything? Nope! -- http://mail.python.org/mailman/listinfo/python-list

Re: Is this a bug? Python intermittently stops dead for seconds

2006-10-01 Thread Tim Peters
[charlie strauss] >>> Below is a simple program that will cause python to intermittently >>> stop executing for a few seconds. it's 100% reproducible on my >>> machine. [Giovanni Bajo] >> Confirmed with Python 2.4.2 on Windows. [Jorgen Grahn] > And Python 2.3.5 on Linux, amd64. In fact, it caus

Re: Is this a bug? Python intermittently stops dead for seconds

2006-10-01 Thread Tim Peters
[charlie strauss] > Below is a simple program that will cause python to intermittently > stop executing for a few seconds. it's 100% reproducible on my machine. Any program that creates a great many long-lived container objects will behave similarly during the creation phase. Others have explain

Re: Installing 2.5 with 2.4?

2006-09-20 Thread Tim Peters
[Duncan Booth] >> Windows is only smart enough to avoid duplicate entries if you tell it >> to do that. e.g. >> >> PATH c:\python25;c:\python25\scripts;%PATH:c:\python25;c:\python25\scripts;=% >> >> will add the two Python 2.5 folders to the head of the path without >> duplicating them. [John Mach

Re: Hardlinks on NTFS

2006-09-17 Thread Tim Peters
[Wildemar Wildenburger] >> I'm thinking of letting my program create hardlinks (or symlinks). I >> know python allows doing this for ext, reiser and the like, but >> apparently not for ntfs systems. >> Is there any package out there that lets me create links in a platform >> independent way? [Calv

Re: How to get the "longest possible" match with Python's RE module?

2006-09-16 Thread Tim Peters
[Tim Peters] >> [...] The most valuable general technique [Friedl] (eventually ;-) >> explained he called "unrolling", and consists of writing a regexp in >> the form: >> >>normal* (?: special normal* )* >> >> where the sets of character

Re: min() & max() vs sorted()

2006-09-15 Thread Tim Peters
t;> >>> L = ["four", "five"] >>> print min(L, key = len), max(L, key = len) >>> >>> The result is: >>> >>> ('four', 'four') [Tim Peters] >> min() and max() both work left-to-right, and return t

Re: how do you convert and array of doubles into floats?

2006-09-15 Thread Tim Peters
[Marc 'BlackJack' Rintsch] >> What about: >> >> b = array.array('f', a) [Diez B. Roggisch] > AFAIK d and f are synonym for arrays, as python doesn't distinguish > between these two on a type-level. And double it is in the end. While Python has no type of its own corresponding to the native C `flo

Re: min() & max() vs sorted()

2006-09-14 Thread Tim Peters
[MRAB] > Some time after reading about Python 2.5 and how the built-in functions > 'min' and 'max' will be getting a new 'key' argument, I wondered how > they would treat those cases where the keys were the same, for example: > > L = ["four", "five"] > print min(L, key = len), max(L, key = len) > >

Re: How to get the "longest possible" match with Python's RE module?

2006-09-12 Thread Tim Peters
[Bryan Olson] >>> Unfortunately, the stuff about NFA's is wrong. Friedl's awful >>> book [Tim Peters] >> Strongly disagree: [...] [Bryan] > I know I'm disagreeing with a lot of smart people in panning > the book. That's allowed :-) >>&

Re: How to get the "longest possible" match with Python's RE module?

2006-09-12 Thread Tim Peters
[Licheng Fang] >> Basically, the problem is this: >> >> >>> p = re.compile("do|dolittle") >> >>> p.match("dolittle").group() >> 'do' ... >> The Python regular expression engine doesn't exaust all the >> possibilities, but in my application I hope to get the longest possible >> match, starting fro

Re: How to get the "longest possible" match with Python's RE module?

2006-09-12 Thread Tim Peters
[Licheng Fang] >> Oh, please do have a look at the second link I've posted. There's a >> table comparing the regexp engines. The engines you've tested probably >> all use an NFA implementation. [Bryan Olson] > Unfortunately, the stuff about NFA's is wrong. Friedl's awful > book Strongly disagree:

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread Tim Peters
[Licheng Fang[ > ... > In fact, what I'm doing is handle a lot of regular expressions. I > wanted to build VERY LONG regexps part by part and put them all into a > file for easy modification and maintenance. The idea is like this: > > (*INT) = \d+ > (*DECIMAL) = (*INT)\.(*INT) > (*FACTION) = (*DECI

Re: How to get the "longest possible" match with Python's RE module?

2006-09-11 Thread Tim Peters
[Licheng Fang] > ... > I want to know if there is some way to make Python RE behave like grep > does, Not in general, no. The matching strategies couldn't be more different, and that's both deep and intentional. See Friedl's book for details: http://regex.info/ > or do I have to change to

Re: GC and security

2006-08-30 Thread Tim Peters
[Aahz] >> Assuming you're talking about CPython, strings don't really participate >> in garbage collection. Keep in mind that the primary mechanism for >> reaping memory is reference counting, and generally as soon as the >> refcount for an object goes to zero, it gets deleted from memory. [Les S

Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-29 Thread Tim Peters
[/T] >> OTOH, current versions of Python (and Perl) [/F] > just curious, but all this use of (& Perl) mean that the Perl folks have > implemented timsort ? A remarkable case of independent harmonic convergence: http://mail.python.org/pipermail/python-dev/2002-July/026946.html Come to think

Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-29 Thread Tim Peters
7;re interested in. >>> >>> If it's asymptotic behavior, then the O(logN) factor is a difference. >>> >>> If it's practical speed, a constant factor of 2 is far more relevant >>> than any O(logN) factor. [Tim Peters] >> Nope. Even if you

Re: A Sort Optimization Technique: decorate-sort-dedecorate

2006-08-29 Thread Tim Peters
[Joachim Durchholz] >>> Wikipedia says it's going from 2NlogN to N. If a sort is massively >>> dominated by the comparison, that could give a speedup of up to 100% >>> (approximately - dropping the logN factor is almost irrelevant, what >>> counts is losing that factor of 2). [Gabriel Genellina] >

Re: naive misuse? (of PyThreadState_SetAsyncExc)

2006-08-28 Thread Tim Peters
[EMAIL PROTECTED] >> The documentation for PyThreadState_SetAsyncExc says "To prevent naive >> misuse, you must write your own C extension to call this". Anyone care >> to list a few examples of such naive misuse? [and again] > No? I'll take that then as proof that it's impossible to misuse the >

Re: Misleading error message when opening a file (on Windows XP SP 2)

2006-08-28 Thread Tim Peters
[Claudio Grondi] > Here an example of what I mean > (Python 2.4.2, IDLE 1.1.2, Windows XP SP2, NTFS file system, 80 GByte > large file): > > >>> f = file('veryBigFile.dat','r') > >>> f = file('veryBigFile.dat','r+') > > Traceback (most recent call last): >File "", line 1, in -toplevel- >

Re: time.clock() going backwards??

2006-08-25 Thread Tim Peters
a floating point value which was "less than" the >> value returned by the previous invokation. The computer was a pretty fast >> one (P4 3Ghz I think, running Windows XP), and this happened only between >> very close invokations of time.clock(). [Terry Reed] > I se

Re: random writing access to a file in Python

2006-08-25 Thread Tim Peters
[Claudio Grondi] > I have a 250 Gbyte file (occupies the whole hard drive space) Then where is Python stored ;-)? > and want to change only eight bytes in this file at a given offset of appr. > 200 > Gbyte (all other data in that file should remain unchanged). > > How can I do that in Python? S

Re: pickling and endianess

2006-08-24 Thread Tim Peters
[Chandrashekhar kaushik] > Can an object pickled and saved on a little-endian machine be unpickled > on a big-endian machine ? Yes. The pickle format is platform-independent (native endianness doesn't matter, and neither do the native sizes of C's various integer types). > Does python handle thi

Re: _PyLong_FromByteArray

2006-08-12 Thread Tim Peters
[Dan Christensen] > My student and I are writing a C extension that produces a large > integer in binary which we'd like to convert to a python long. The > number of bits can be a lot more than 32 or even 64. My student found > the function _PyLong_FromByteArray in longobject.h which is exactly >

Re: Inconsistency producing constant for float "infinity"

2006-08-12 Thread Tim Peters
[Tim Peters] >... >> It has a much better chance of working from .pyc in Python 2.5. >> Michael Hudson put considerable effort into figuring out whether the >> platform uses a recognizable IEEE double storage format, and, if so, >> marshal and pickle take di

Re: Inconsistency producing constant for float "infinity"

2006-08-11 Thread Tim Peters
[Peter Hansen] >> I'm investigating a puzzling problem involving an attempt to >> generate a constant containing an (IEEE 754) "infinity" value. (I >> understand that special float values are a "platform-dependent >> accident" etc...) [also Peter] > ... > My guess about marshal was correct. Yup.

Re: datetime to timestamp

2006-08-11 Thread Tim Peters
[Simen Haugen] >>> How can I convert a python datetime to a timestamp? It's easy to convert >>> a timestamp to datetime (datetime.datetime.fromtimestamp(), but the >>> other way around...?) [John Machin] >> Is the timetuple() method what you want? >> >> #>>> import datetime >> #>>> n = datetime.da

Re: threading.Event usage causing intermitent exception

2006-08-08 Thread Tim Peters
[EMAIL PROTECTED] > Admittedly this problem causes no actual functional issues aside from > an occasional error message when the program exits. The error is: > > Unhandled exception in thread started by > Error in sys.excepthook: > Original exception was: > > Yes all that info is blank. That's ty

Re: Initializing the number of slots in a dictionary

2006-08-06 Thread Tim Peters
... [Jon Smirl] > I know in advance how many items will be added to the dictionary. Most > dictionary implementations I have previously worked with are more > efficient if they know ahead of time how big to make their tables. Richard Jones spent considerable time investigating whether "pre-sizing

Re: random shuffles

2006-07-21 Thread Tim Peters
[ Boris Borcic] > x.sort(cmp = lambda x,y : cmp(random.random(),0.5)) > > pick a random shuffle of x with uniform distribution ? Say len(x) == N. With Python's current sort, the conjecture is true if and only if N <= 2. > Intuitively, assuming list.sort() does a minimal number of comparisons to

Re: hash() yields different results for different platforms

2006-07-12 Thread Tim Peters
[Grant Edwards] >> ... >> The low 32 bits match, so perhaps you should just use that >> portion of the returned hash? >> >> >>> hex(12416037344) >> '0x2E40DB1E0L' >> >>> hex(-468864544 & 0x) >> '0xE40DB1E0L' >> >> >>> hex(12416037344 & 0x) >> '0xE40DB1E0L' >> >>> hex

Re: Valgrind memory-checker reports memory problems in Python

2006-07-04 Thread Tim Peters
[Nathan Bates] > Are the Python developers running Python under Valgrind? Please read Misc/README.valgrind (in your Python distribution). -- http://mail.python.org/mailman/listinfo/python-list

Re: how to stop python...

2006-07-02 Thread Tim Peters
[bruce] > perl has the concept of "die". does python have anything similar. how can a > python app be stopped? > > the docs refer to a sys.stop. Python docs? Doubt it ;-) > but i can't find anything else... am i missing something... >>> import sys >>> print sys.exit.__doc__ exit([status]) Exit

Re: Questions on Threading

2006-06-26 Thread Tim Peters
[j.c.sackett] > I'm using the threading module to accomplish some distributed processing on > a project, and have a basic (I hope) question that I can't find an answer to > elsewhere. > > I've noted that there's a lot of documentation saying that there is no > external way to stop a thread, True.

Re: Is Queue.Queue.queue.clear() thread-safe?

2006-06-22 Thread Tim Peters
[Russell Warren] >>> I'm guessing no, since it skips down through any Lock semantics, [Tim Peters] >> Good guess :-) It's also unsafe because some internal conditions must >> be notified whenever the queue becomes empty (else you risk deadlock). [Fredrik Lundh] &g

Re: Is Queue.Queue.queue.clear() thread-safe?

2006-06-22 Thread Tim Peters
[Russell Warren] > I'm guessing no, since it skips down through any Lock semantics, Good guess :-) It's also unsafe because some internal conditions must be notified whenever the queue becomes empty (else you risk deadlock). > but I'm wondering what the best way to clear a Queue is then. > > Ese

Re: Iteration over recursion?

2006-06-21 Thread Tim Peters
[MTD <[EMAIL PROTECTED]>] > I've been testing my recursive function against your iterative > function, and yours is generally a quite steady 50% faster on > factorizing 2**n +/- 1 for 0 < n < 60. If you're still not skipping multiples of 3, that should account for most of it. > I think that, for

Re: random.jumpahead: How to jump ahead exactly N steps?

2006-06-21 Thread Tim Peters
[Matthew Wilson] > The random.jumpahead documentation says this: > > Changed in version 2.3: Instead of jumping to a specific state, n steps > ahead, jumpahead(n) jumps to another state likely to be separated by > many steps.. > > I really want a way to get to the Nth value in a random

Re: Iteration over recursion?

2006-06-21 Thread Tim Peters
[Kay Schluehr] > You might use a separate prime generator to produce prime factors. The > factorize algorithm becomes quite simple and configurable by prime > generators. Alas, yours was _so_ simple that it always takes time proportional to the largest prime factor of n (which may be n) instead of

Re: Python SHA-1 as a method for unique file identification ? [help!]

2006-06-21 Thread Tim Peters
[EP <[EMAIL PROTECTED]>] > This inquiry may either turn out to be about the suitability of the > SHA-1 (160 bit digest) for file identification, the sha function in > Python ... or about some error in my script It's your script. Always open binary files in binary mode. It's a disaster on Windows

Re: Iteration over recursion?

2006-06-20 Thread Tim Peters
[MTD] > I've been messing about for fun creating a trial division factorizing > function and I'm naturally interested in optimising it as much as > possible. > > I've been told that iteration in python is generally more > time-efficient than recursion. Is that true? Since you heard it from me to b

Re: need helping tracking down weird bug in cPickle

2006-06-20 Thread Tim Peters
[Carl J. Van Arsdall] > Hey everyone, cPickle is raising an ImportError that I just don't quite > understand. When that happens, the overwhelmingly most likely cause is that the set of modules on your PYTHONPATH has changed since the pickle was first created, in ways such that a module _referenced

Re: PyObject_SetItem(..) *always* requires a Py_INCREF or not?

2006-06-17 Thread Tim Peters
[EMAIL PROTECTED] > I would think everytime you add an item to a list you must increase > reference count of that item. _Someone_ needs to. When the function called to add the item does the incref itself, then it would be wrong for the caller to also incref the item. > http://docs.python.org/api

Re: Numerics, NaNs, IEEE 754 and C99

2006-06-15 Thread Tim Peters
[Nick Maclaren] Firstly, a FAR more common assumption is that integers wrap in twos' complement - Python does not do that. [Grant Edwards] >>> It used to [Fredrik Lundh] >> for integers ? what version was that ? [Grant] > Am I remebering incorrectly? Mostly but not entirely. > Didn'

Re: math.pow(x,y)

2006-06-11 Thread Tim Peters
[Wojciech Muła] >> You have to use operator **, i.e. 34564323**456356 Or the builtin pow() instead of math.pow(). [Gary Herron] > That's not very practical. That computation will produce a value with > more than 3.4 million digits. Yes. > (That is, log10(34564323)*456356 = 3440298.) Python will

  1   2   3   4   >