Re: date diff calc

2004-11-29 Thread Tim Peters
[Skip Montanaro] > ... > The datetime.date object already exposes a strftime method for > generating a formatted string output and will create date objects > from both time.time() output (fromtimestamp) and "proleptic > Gregorian ordinal"s (fromordinal). Looking at the datetime module > docs, it's

Re: Struggling with struct.unpack() and "p" format specifier

2004-11-30 Thread Tim Peters
[Geoffrey <[EMAIL PROTECTED]>] > I am trying to read data from a file binary file and then unpack the > data into python variables. Some of the data is store like this; > > xbuffer: '\x00\x00\xb9\x02\x13EXCLUDE_CREDIT_CARD' > # the above was printed using repr(xbuffer). > # Note that int(0x13) =

Re: date diff calc

2004-11-30 Thread Tim Peters
[Skip Montanaro] >>> I think inputs from strings would be much more common. [Tim Peters] >> Me too, although it's a bottomless pit. >> >> guess-6-intended-meanings-for-1/2/3-before-breakfast-ly y'rs [Peter Hansen] > I think Skip was intending that the for

Re: Python 3000 and "Python Regrets"

2004-12-01 Thread Tim Peters
[EMAIL PROTECTED] > I just came across the slides for Guido van Rossum's "Python > Regrets" talk, given in 2002. It worries me that much of my Python > code would be broken if all of his ideas were implemented. Actually, none of it would break, provided you don't change the Python implementation y

Re: access to generator state

2004-12-02 Thread Tim Peters
[Neal D. Becker] > ... > Only one problem. Is there any way to access the state of a > generator externally? In other words, the generator saves all it's > local variables. Can an unrelated object then query the values of > those variables? (In this case, to get at intermediate results) It's

Re: assymetry between a == b and a.__eq__(b)

2004-12-04 Thread Tim Peters
[Mel Wilson] > :) Seems to: > > > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> class Eq(object): > ... def __eq__(self, other): > ... return True > ... > >>> class Neq(Eq

Re: [BUG] IMO, but no opinions? Uncle Tim? was: int(float(sys.maxint)) buglet ?

2004-12-06 Thread Tim Peters
[Bengt Richter] > Peculiar boundary cases: > > >>> 2.0**31-1.0 > 2147483647.0 > >>> int(2147483647.0) > 2147483647L > >>> int(2147483647L ) > 2147483647 > >>> > >>> -2.0**31 > -2147483648.0 > >>> int(-2147483648.0) > -2147483648L > >>> int(-2147483648L ) > -2147483648 > > some kind of one-off err

Re: Ptyon 2.3.5 probably coming in January; get your bugs/patches reported!

2004-12-06 Thread Tim Peters
[Brett C] >> Anthony Baxter, our ever-diligent release manager, mentioned this past week >> that Python 2.3.5 will most likely come to fruition some time in January >> (this is not guaranteed date). [Roy Smith] > Interesting. Does that mean that 2.3 and 2.4 will be maintained in > parallel for a

Re: [BUG] IMO, but no opinions? Uncle Tim? was: int(float(sys.maxint)) buglet ?

2004-12-07 Thread Tim Peters
[Tim Peters] >> ... there's no promise anywhere, e.g., that Python will return an int >> whenever it's physically possible to do so. [Bengt Richter] > Ok, I understand the expediency of that policy, but what is now the meaning > of int, in that case? Is it now just a v

Re: Python 2.3.5 ?

2004-12-07 Thread Tim Peters
[Luis M. Gonzalez] > I'm confussed... > Python 2.4 (final) hs been released a few days ago, but now I > see that Python 2.3.5 is being worked on. > Why? What does it mean? Just that enough volunteers exist interested in producing another bugfix release for the 2.3 line. It will probably be the la

Re: memoize factorial example (was Re: decorators ?)

2004-12-07 Thread Tim Peters
[Daniel 'Dang' Griffith] >> But the factorial example on the wiki has a defect. It incorrectly >> calculates factorial(0) as 0, when it should be 1. [Terry Reedy] > This is a matter of definition, and definitions apparently differ. > fact(0) == 0 is a backward projection from the definition f(1)

Re: results of division

2004-12-09 Thread Tim Peters
[Paul McGuire] ... > >>> print "%.2f" % 1.775 > 1.77 > > Hmmm, if we rounded, I would have expected 1.775 to round up > to 1.78. Platform-dependent. 1.775 isn't exactly representable regardless, but whether exactly-half-way numbers that are exactly representable round up or truncate varies across

Re: thread/queue bug

2004-12-11 Thread Tim Peters
[Peter Otten] > What I believe to be a minimal example: > > > import Queue > import threading > import time > > q = Queue.Queue(4) > > def proc(): >while True: >q.get(1) >Queue.Queue() >print "YADDA" > > threading.Thread(target=proc).start() > > while True: >pri

Re: thread/queue bug

2004-12-13 Thread Tim Peters
[Antoon Pardon] > I don't see why starting a thread as a side effect of importing is > bad thread practice. Sure python doesn't cater for it, but IMO > that seems to be python failing. Obviously, it's bad practice in Python because it can lead to deadlocks in Python. It's nearly tautological. Im

Re: Efficient grep using Python?

2004-12-15 Thread Tim Peters
["sf" <[EMAIL PROTECTED]>] >> I have files A, and B each containing say 100,000 lines (each >> line=one string without any space) >> >> I want to do >> >> " A - (A intersection B) " >> >> Essentially, want to do efficient grep, i..e from A remove those >> lines which are also present in file B.

Re: Efficient grep using Python?

2004-12-15 Thread Tim Peters
[Fredrik Lundh] >>> bdict = dict.fromkeys(open(bfile).readlines()) >>> >>> for line in open(afile): >>>if line not in bdict: >>>print line, >>> >>> [Tim Peters] >> Note that an open file is an iterable object, yi

Re: Efficient grep using Python?

2004-12-15 Thread Tim Peters
[Jane Austine] > fromkeys(open(f).readlines()) and fromkeys(open(f)) seem to be > equivalent. Semantically, yes; pragmatically, no, in the way explained before. > When I pass an iterator instance(or a generator iterator) to the > dict.fromkeys, it is expanded at that moment, I don't know what "e

Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Gabriel Cosentino de Barros] ... > for root, dirs, files in os.walk('t:\'): > # -- do stuff > print "working on", root > # -- stuff done > > print 'DEBUG: dirs =', dirs > for d in dirs: > # -- remove archive >

Re: os.walk bug?

2004-12-16 Thread Tim Peters
[Adam DePrince] > Each iteration of os.walk returns three parameters; one of those, > dirs, is a list of directories within the current directory pointed at > by root. Right. > Am I correct to assume that you beleve that by changing the > contents of dir you will affect how os.walk traverses the

Re: expression form of one-to-many dict?

2004-12-17 Thread Tim Peters
[Steven Bethard] > So I end up writing code like this a fair bit: > > map = {} > for key, value in sequence: > map.setdefault(key, []).append(value) > > This code basically constructs a one-to-many mapping -- each > value that a key occurs with is stored in the list for that key. > > This code'

Re: A rational proposal

2004-12-18 Thread Tim Peters
[Jp Calderone] ... > The Decimal type seems to define min and max so that NaNs > can be treated specially, but I glean this understanding from only > a moment of reading decimal.py. Perhaps someone more well > informed can declare definitively the purpose of these methods. To conform to the sema

Re: Boo who? (was Re: newbie question)

2004-12-20 Thread Tim Peters
[Doug Holton] ... > But I will not be intimidated by the likes of Fredrik Lundh. Trollers > will be held accountable. Doug, Doug, Doug. Fredrik isn't a troll. He's a Swede. Trolls are Norwegian. Lighten up, please. Fredrik is usually terse, and sometimes curt (although Americans seem to have

Re: Should I always call PyErr_Clear() when an exception occurs?

2004-12-20 Thread Tim Peters
[Jaime Wyant] > I've found that the code below will crash if I don't have the > PyErr_Clear() function call. Should I always call PyErr_Clear()? That's not the right approach. Nearly all Python C API calls can fail. They return a special value if they do, primarily NULL for a call that returns

Re: trouble building python2.4

2004-12-22 Thread Tim Peters
[Matthew Thorley] >> I have got to be the stupidest person on the face of the planet. [Steve Holden] > I'll have you know I don't welcome newcomers to this newsgroup > trying to steal my hard-won reputation, if you don't mind. In all fairness, Matthew did present evidence to support his claim. F

Re: test

2004-12-23 Thread Tim Peters
[Per Erik Stendahl <[EMAIL PROTECTED]>] > sdfdsafasd Generally speaking, yes, but not if you're concerned about Pythons before 1.5.2 too. If you are, a reasonable workaround is: try: sdfdsafasd except NameError: pass else: True = None is None and 1 != 2 False = None is not None o

Re: thread/queue bug

2005-01-02 Thread Tim Peters
[EMAIL PROTECTED] Note that python-bugs-list is a moderated list for use only by automated reports generated from SourceForge. I'm redirecting the reply to [EMAIL PROTECTED] > I have a very strange bug. A thread in a .pyc stops dead. > > This program has many threads and queues and has worked

Re: Restore a unified diff

2005-01-04 Thread Tim Peters
[Nick Allen] > After using ndiff from difflib, the function restore > would return the sequence that generated the delta. It can actually reproduce either sequence from which the delta was generated. But this is really trivial: ndiff was intended to produce diff output for humans to read, and in

Re: Restore a unified diff

2005-01-05 Thread Tim Peters
[Nick Allen] >>> Unfortunately, restore does not do the same for unified_diff. I do >>> not see any similar function that is intended for unified_diff. >>> Does anyone know how to "restore" from a unified diff generated >>> delta? [Tim Peters] >&g

Re: sorting on keys in a list of dicts

2005-01-07 Thread Tim Peters
[Nick Coghlan] ... > Python 2.3 has a stable sort, and Python 2.4 brought the guarantee that it > shall > remain that way. I'm not sure about Python 2.2 and earlier. No list.sort() implementation before 2.3 was stable. It was confusing, though, because the samplesort/binary_insertion_sort hybrid

Re: Returning same type as self for arithmetic in subclasses

2005-01-07 Thread Tim Peters
[Max M] > """ > I subclass datetime and timedelta > > >>> dt = myDatetime(1970,1,1) > >>> type(dt) > > > >>> td = myTimedelta(hours=1) > >>> type(td) > > > But when I do arithmetic with these classes, they return datetime and > timedelta, ... > >>> new_time = dt + td > >>> new_time > datetime.

Re: time module precision

2005-01-08 Thread Tim Peters
[Jane Austine] > What is the precision (and accuracy) of time module on a Windows XP > machine? There are many functions in the time module. You shouldn't assume that any two have similar behavior (because, in fact, they may not). > threading module depends on time module so it's precision(and >

Re: time module precision

2005-01-09 Thread Tim Peters
[Tim Peters] >> Python's time.sleep() calls the Win32 API Sleep() function on >> Windows. All behavior is inherited from the latter. See MS's docs: >> >> >> <http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/sleep.asp> [EM

Re: Writing huge Sets() to disk

2005-01-10 Thread Tim Peters
[Martin MOKREJÅ] > just imagine, you want to compare how many words are in English, German, > Czech, Polish disctionary. You collect words from every language and record > them in dict or Set, as you wish. Call the set of all English words E; G, C, and P similarly. > Once you have those Set's o

Re: Writing huge Sets() to disk

2005-01-10 Thread Tim Peters
[Martin MOKREJÅ] > ... > > I gave up the theoretical approach. Practically, I might need up > to store maybe those 1E15 keys. We should work on our multiplication skills here . You don't have enough disk space to store 1E15 keys. If your keys were just one byte each, you would need to have 4 th

Re: Writing huve ge Sets() to disk

2005-01-10 Thread Tim Peters
[Tim Peters] >> As I mentioned before, if you store keys in sorted text files, >> you can do intersection and difference very efficiently just by using >> the Unix `comm` utiltity. [Martin MOKREJÅ] > Now I got your point. I understand the comm(1) is written in C, but it stil

Re: Securing a future for anonymous functions in Python

2005-01-10 Thread Tim Peters
... [Anna] >> BTW - I am *quite* happy with the proposal for "where:" syntax - I >> think it handles the problems I have with lambda quite handily. [Steve Holden] > Whereas I find it to be an excrescence, proving (I suppose) that one > man's meat is another person's poison, or something. I've be

Re: Writing huge Sets() to disk

2005-01-10 Thread Tim Peters
[Istvan Albert] > #- I think that you need to first understand how dictionaries work. > #- The time needed to insert a key is independent of > #- the number of values in the dictionary. [Batista, Facundo] > Are you sure? > > I think that is true while the hashes don't collide. If you have co

Re: python 2.3.4 for windows: float("NaN") throws exception

2005-01-13 Thread Tim Peters
[EMAIL PROTECTED] > my python 2.3.4 for windows refuse to execute line float("NaN"). It > says: > > >>> float("NaN") > Traceback (most recent call last): > File "", line 1, in ? > ValueError: invalid literal for float(): NaN > > The same line works as expected on Linux and Solaris with python 2.3.

Re: python 2.3.4 for windows: float("NaN") throws exception

2005-01-13 Thread Tim Peters
[EMAIL PROTECTED] > C99 and Fortran 2003 have IEEE arithmetic. Not that simple (e.g., C99 doesn't *require* it; but it has a pile of specified IEEE behaviors a conforming C99 compiler can choose to support (or not), along with a preprocessor symbol those that do so choose can #define to advertise

Re: Pickled text file causing ValueError (dos/unix issue)

2005-01-14 Thread Tim Peters
[Aki Niimura] > I started to use pickle to store the latest user settings for the tool > I wrote. It writes out a pickled text file when it terminates and it > restores the settings when it starts. ... > I guess DOS text format is creating this problem. Yes. > My question is "Is there any elegant

Re: Writing huge Sets() to disk

2005-01-14 Thread Tim Peters
[Martin MOKREJÅ] > This comm(1) approach doesn't work for me. It somehow fails to > detect common entries when the offset is too big. > > file 1: > > A > F > G > I > K > M > N > R > V > AA > AI > FG > FR > GF > GI > GR > IG > IK > IN > IV > KI > MA > NG > RA > RI > VF > AIK > FGR > FRA > GFG > GIN

Re: Why 'r' mode anyway? (was: Re: Pickled text file causing ValueError (dos/unix issue))

2005-01-14 Thread Tim Peters
[Irmen de Jong] > I've been wondering why there even is the choice between binary mode > and text mode. Why can't we just do away with the 'text mode' ? > What does it do, anyways? At least, if it does something, I'm sure > that it isn't something that can be done in Python itself if > really requi

Re: Pickled text file causing ValueError (dos/unix issue)

2005-01-14 Thread Tim Peters
[Tim Peters] >>Yes: regardless of platform, always open files used for pickles >> in binary mode. ... [John Machin] > Tim, the manual as of version 2.4 does _not_ mention the need > to use 'b' on OSes where it makes a difference, not even in the > examples at the

Re: oddities in the datetime module

2005-01-14 Thread Tim Peters
[Max M] > ... > First of, it should be possible to easily convert between the > datetime objects. Why? All the conversions people asked for when the module was being designed were implemented. > And eg. the date object doesn't have a datetime() method. Which > it could easily have. But not a *s

Re: Why 'r' mode anyway?

2005-01-14 Thread Tim Peters
[Tim Peters] >> That differences may exist is reflected in the C >> standard, and the rules for text-mode files are more restrictive >> than most people would believe. [Irmen de Jong] > Apparently. Because I know only about the Unix <-> Windows > difference (wind

Re: python mode indentation problem

2005-01-15 Thread Tim Peters
[Xah Lee] ... > © who the fuck coded the python mode in emacs? The major contributors are listed at the top of python-mode.el. > fuckhead please peruse: > © http://xahlee.org/UnixResource_dir/writ/responsible_license.html OK, I read it, but have no idea what point you're trying to make here. If

Re: interpret 4 byte as 32-bit float (IEEE-754)

2005-01-16 Thread Tim Peters
[Bengt Richter] ... > But I don't know how to build QNaNs: You can subtract infinity from infinity. While all Python behavior in the presence of NaNs, infinities, and signed zeroes is a platform-dependent accident, it you're on a box that has such things, and figure out some (accidental!) way to

Re: Py_Object* Py_BuildValue, Py_INCREF necessary?

2005-01-17 Thread Tim Peters
[Torsten Mohr] > when i write an extension module in C and return a Py_Object* > that i've built with Py_BuildValue, do i need to use Py_INCREF > on that before i return it to python from my extension module > or not? The docs for Py_BuildValue() say it returns a new reference (and it does). So t

Re: Zen of Python

2005-01-19 Thread Tim Peters
different meaning. It's not that "Flat is better than > nested" it's that "Too flat is bad and too flat is nested so be as < nested (or as flat) as you have to be and no more." Perhaps Tim > Peters is far too concise for my feeble mind Always happy to help a fellow

Re: Zen of Python

2005-01-19 Thread Tim Peters
[Paul Rubin] > Huh? [1,2,[3,4,5],[6,7]],8 is a perfectly valid Python list. You're claiming not to know any relevant difference between Python lists and Lisp lists? Heh. > And you can break out of a containing loop from a nested loop > with try/raise. Heh heh. Yes, you can. I've neve

Re: why no time() + timedelta() ?

2005-01-20 Thread Tim Peters
[josh] > Why can't timedelta arithmetic be done on time objects? Obviously, because it's not implemented . > (e.g. datetime.time(5)-datetime.timedelta(microseconds=3) > > Nonzero "days" of the timedelta could either be ignored, or > trigger an exception. And if the result is less than 0, or >= 2

Re: PyCon Preliminary Program Announced!

2005-01-20 Thread Tim Peters
[Bryan] > can anyone tell me how the talks work? there are between 9 > and 12 talks for each time slot. do all talks start at the same > time? or are there just four talks at a time and the columns show > what talks are in a given room? The web page needs better formatting. In general, there ar

Re: PyCon Preliminary Program Announced!

2005-01-21 Thread Tim Peters
[A.M. Kuchling] > Suggestions for improvement are welcome. Perhaps the Wiki version of > the schedule, at http://www.python.org/moin/PyConDC2005/Schedule, > may be better. It is, but the 2004 schedule was really what I had in mind (very readable!): http://www.python.org/pycon/dc2004/schedule

Re: Zen of Python

2005-01-21 Thread Tim Peters
[Paul Rubin] >> You snipped out the examples I gave, like [x*x for x in range(5)] >> leaving unnecessary residue in the name space. Was it not >> obvious from the beginning that that was a kludge? If it was >> obviously a kludge, was it not obvious that there would be >> reason to want to fix it

Re: Tuple size and memory allocation for embedded Python

2005-01-21 Thread Tim Peters
[Jinming Xu] >> Python seems unstable, when allocating big memory. For >> example, the following C++ code creates a tuple of tuples: >> >> PyObject* arCoord = PyTuple_New(n); >> double d = 1.5; >> for(int i=0; i> { >> PyObject* coord = PyTuple_New(2); >> PyTuple_SetItem(coord

Re: Zen of Python

2005-01-22 Thread Tim Peters
[Tim Peters] >> But at that time, Python didn't have lexical scoping, and it wasn't >> clear that it ever would. So what's the bigger wart? Making >> listcomps exactly equivalent to an easily-explained Python for-loop >> nest, or introducing a notion of lex

Re: Classical FP problem in python : Hamming problem

2005-01-23 Thread Tim Peters
[Francis Girard] > ... > In the meantime, I couldn't resist to test the new Python features about > laziness on a classical FP problem, i.e. the "Hamming" problem. ... > Nevertheless, while the Haskell version prints Hamming sequence for as long as > I can stand it, and with very little memory cons

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-23 Thread Tim Peters
[Mike C. Fletcher] > I'm looking at rewriting parts of Twisted and TwistedSNMP to eliminate > __del__ methods (and the memory leaks they create). A worthy goal! > Looking at the docs for 2.3's weakref.ref, there's no mention of whether the > callbacks are held with a strong reference. A callback

Re: Memory Usage

2005-01-24 Thread Tim Peters
[<[EMAIL PROTECTED]>] > Would a Python process consume more memory on a PC with lots of > memory? > > For example, say I have the same Python script running on two WinXP > computers that both have Python 2.4.0. One computer has 256 MB of Ram > while the other has 2 GB of Ram. On the machine with le

Re: Weakref.ref callbacks and eliminating __del__ methods

2005-01-24 Thread Tim Peters
[Tim] >> I'll note that one fairly obvious pattern works very well for weakrefs >> and __del__ methods (mutatis mutandis): don't put the __del__ method >> in self, put it in a dead-simple object hanging *off* of self. Like >> the simple: >> >> class BTreeCloser: >> def __init__(self, btree):

Re: Classical FP problem in python : Hamming problem

2005-01-24 Thread Tim Peters
[Francis Girard] > For all the algorithms that run after their tail in an FP way, like the > Hamming problem, or the Fibonacci sequence, (but unlike Sieve of Eratosthene > -- there's a subtle difference), i.e. all those algorithms that typically > rely upon recursion to get the beginning of the gen

Re: threading.py Condition wait overflow error

2005-01-25 Thread Tim Peters
[Mark English] > Every once in a while since I moved to Python 2.4 I've been seeing the > following exception in threading.py Condition: > > File "mctest3.py", line 1598, in WaitForMessages >self.condResponses.wait(1.0) > File "C:\Program Files\Python24\lib\threading.py", line 221, in wait >

Re: python memory blow out

2005-01-26 Thread Tim Peters
[Simon Wittber] >> According to the above post: >>a) If the allocation is > 256 bytes, call the system malloc. >>b) If the allocation is < 256, use its own malloc implementation, which >> allocates memory in 256 kB chunks and never releases it. >> >> I imagine this means that large me

Re: threading.py Condition wait overflow error

2005-01-26 Thread Tim Peters
[Tim Peters] ... >> The most common cause for "impossible exceptions" > is flawed C code in an extension that fails to >> check a Python C API call for an error return. [Mark English] > Yes, I use a lot of C modules which I wrote. Then you know where to start lookin

Re: On benchmarks, heaps, priority queues

2005-01-27 Thread Tim Peters
[EMAIL PROTECTED], on ] > Yes I know in theory the insertion sort approach should be bad for > large enough values, but the weird thing is that if you mix inserts and > deletes (with enough deletes) even 1M elements is not a large enough > value. Anyway,

Re: Who should security issues be reported to?

2005-01-28 Thread Tim Peters
[EMAIL PROTECTED] > Who are the appropriate people to report security problems to > in respect of a module included with the Python distribution? > I don't feel it appropriate to be reporting it on general mailing > lists. The Python project has no non-public resources for this. Filing a bug repo

Re: pickle, cPickle, & HIGHEST_PROTOCOL

2005-01-30 Thread Tim Peters
[A.B., Khalid] > I wonder if someone can explain what is wrong here. I am pickling a > list of dictionaries (see code attached) and unpickling it back using > the HIGHEST_PROTOCOL of pickle and cPickle. ... > ... on Win98. Pickles are binary data. Therefore you should open pickle files in binary

Re: pythonic equivalent of Mathematica's FixedPoint function

2005-02-01 Thread Tim Peters
[jelle] > I now some hostility to functional programming is flaming up now and > then; still could someone suggest me a pythonic equivalent for > Mathematica's FixedPoint function? For those not familiar with > Mathematica: > > FixedPoint[f, expr] starts with expr, then applies f repeatedly until >

Re: Where are list methods documented?

2005-02-01 Thread Tim Peters
[Grant Edwards] > I'm trying to figure out how to sort a list, and I've run into > a problem that that I have tripped over constantly for years: > where are the methods of basic types documented? The methods on mutable sequence types are documented in the Library manual's section on mutable sequen

Re: Where are list methods documented?

2005-02-01 Thread Tim Peters
[Tim Peters] >> You could have found the above by, e.g., looking up "sort" in the >> Library manual's index. [Grant Edwards] > I did. I looked up sort in the library index, and it took me > to 3.3.5 Emulating container types, It doesn't for me.

Re: pickle/marshal internal format 'life expectancy'/backward compatibility

2005-02-05 Thread Tim Peters
[Philippe C. Martin] > I am looking into using the pickle format to store object/complex data > structures into a smart card as it would make the design of the embedded > application very simple. > > Yet the card might have to stay in the pocket of the customer for a few > years, during which the b

Re: Pickling and inheritance are making me hurt

2005-02-05 Thread Tim Peters
[Kirk Strauser] > I have a module that defines a Search class and a SearchResult class. Try posting a minimal self-contained code sample that fails. > I use these classes by writing other modules that subclass both of them as > needed to interface with particular search engines. > > My problem i

Re: Insane import behaviour and regrtest.py: heeelp

2005-02-06 Thread Tim Peters
[John J. Lee] > ... > I tried it, and I get the same results as before (the test modules from my > installed copy of Python are picked up instead of the local copies in > my CVS checkout's Lib/test, apparently entirely contrary to sys.path). Try running Python with -vv (that's two letter "v", not

Re: Insane import behaviour and regrtest.py: heeelp

2005-02-06 Thread Tim Peters
[John J. Lee] > I'm still puzzled, though. Reading the -vv output, I see that when > importing test_cookielib (which is currently the only line in my > regrtest.py -f file), Python doesn't appear to look in Lib/test to > find module "test.test_cookielib" (the actual string passed by > regrtest.py

Re: Hack with os.walk()

2005-02-12 Thread Tim Peters
[Frans Englich] ... > My problem, AFAICT, with using os.walk() the usual way, is that in order to > construct the /hierarchial/ XML document, I need to be aware of the directory > depth, and a recursive function handles that nicely; os.walk() simply > concentrates on figuring out paths to all files

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-14 Thread Tim Peters
[Ilias Lazaridis] ... > Let's see: > > The process would be: > > a) A Python Foundation official states: "of course we accept diversity > and of course we are intrested that our source-code-base compiles > directly with MinGW (and other compilers)". Well, I'm a Director of the Python Software Foun

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-15 Thread Tim Peters
[Tim Peters] >> Well, I'm a Director of the Python Software Foundation, and my view is >> "the more platforms the merrier". [Ilias Lazaridis] > I extract: "you are intrested, that the source-code-base compiles > directly with MinGW (and other compilers)"

Re: Whither datetime.date ?

2005-02-26 Thread Tim Peters
[Harald Hanche-Olsen] > I'm confused. I was going to try linkchecker, and it dies with a > traceback ending in > > File "/usr/local/lib/python2.4/calendar.py", line 32, in _localized_month >_months = [datetime.date(2001, i+1, 1).strftime for i in range(12)] > AttributeError: 'module' object h

Re: Regular Expressions: large amount of or's

2005-03-01 Thread Tim Peters
[André Søreng] > Given a string, I want to find all ocurrences of > certain predefined words in that string. Problem is, the list of > words that should be detected can be in the order of thousands. > > With the re module, this can be solved something like this: > > import re > > r = re.compile("wo

Re: Python 2.4 removes None data type?

2005-03-04 Thread Tim Peters
[EMAIL PROTECTED] > I just read in the 'What's New in Python 2.4' document that the None > data type was converted to a constant: > http://python.org/doc/2.4/whatsnew/node15.html > > """ > # None is now a constant; code that binds a new value to the name > "None" is now a syntax error. > """ > > S

Re: Licensing Python code under the Python license

2005-03-11 Thread Tim Peters
[Daniel Keep] > I'm currently working on a Python program, and was wondering if it's > possible to license the program, some associated tools, and a few other > libraries I've written under the Python license. > > I had a look at the new PSF Python license on the list of OSI-approved > licenses, bu

Re: Bug in threading.Thread.join() ?

2005-03-25 Thread Tim Peters
[Peter Hansen] > I'm still trying to understand the behaviour that I'm > seeing but I'm already pretty sure that it's either > a bug, or something that would be considered a bug if > it didn't perhaps avoid even worse behaviour. > > Inside the join() method of threading.Thread objects, > a Conditio

Re: math - need divisors algorithm

2005-03-30 Thread Tim Peters
[Philp Smith] > Does anyone have suggested code for a compact, efficient, elegant, most of > all pythonic routine to produce a list of all the proper divisors of an > integer (given a list of prime factors/powers) If the canonical factorization of N is the product of p_i**e_i, the number of diviso

Re: boring the reader to death (wasRe: Lambda: the Ultimate Design Flaw

2005-04-01 Thread Tim Peters
[Aahz] >> "The joy of coding Python should be in seeing short, concise, readable >> classes that express a lot of action in a small amount of clear code -- >> not in reams of trivial code that bores the reader to death." --GvR [Sunnan] > Can anyone please point me to the text that quote was taken

Re: Simple thread-safe counter?

2005-04-01 Thread Tim Peters
[Paul Rubin] > I'd like to have a function (or other callable object) that returns > 0, 1, 2, etc. on repeated calls. That is: > >print f() # prints 0 >print f() # prints 1 >print f() # prints 2 ># etc. > > There should never be any possibility of any number getting returned

Re: Simple thread-safe counter?

2005-04-02 Thread Tim Peters
[Paul Rubin] > I'm starting to believe the GIL covers up an awful lot of sloppiness > in Python. The GIL is highly exploitable, and much of CPython does exploit it. If you don't want to exploit it, that's fine: there was always an obvious approach using an explicit mutex here, and the only thing

Re: IronPython 0.7 released!

2005-04-05 Thread Tim Peters
[Thomas Gagne] > Does the Python community think Microsoft's embrace is a good or bad thing? All things in this world unfold exactly according to Guido's secret Master Plan. So it depends on whether you think Guido is good or bad. Members of the Python community are required to think Guido is go

Re: sorting a list and counting interchanges

2005-04-06 Thread Tim Peters
[RickMuller] > I have to sort a list, but in addition to the sorting, I need to > compute a phase factor that is +1 if there is an even number of > interchanges in the sort, and -1 if there is an odd number of > interchanges. So you want the parity ("sign") of the associated permutation. > I coul

Re: sorting a list and counting interchanges

2005-04-07 Thread Tim Peters
[Paul Rubin] > Writing a sorting function from scratch for this purpose seems like > reinventing the wheel. Yup! list.sort() is going to be mounds faster. > Tim's answer of simply counting the cycles (without having to pay > attention to their length) is really clever. I didn't realize you coul

Re: struct enhancements?

2005-04-07 Thread Tim Peters
[EMAIL PROTECTED] > I would like to be able to pack/unpack 8-byte longs, ... Have you tried struct's 'q' or 'Q' format codes? -- http://mail.python.org/mailman/listinfo/python-list

Re: Positions of regexp groups

2005-04-08 Thread Tim Peters
[Magnus Lie Hetland] > Just a quick question: Does anyone have a simple way of finding the > positions (start, end) of the groups in a regexp match? AFAICS, the re > API can only return the contents...? Read the docs for match objects, esp. the start(), end(), and span() methods. -- http://mail.p

Re: Python 2.4 killing commercial Windows Python development ?

2005-04-11 Thread Tim Peters
[Michael Kearns] > ... > Also, I don't believe that just 'owning' MSVC 7.1 is enough. From > cursory glances at the various redist files, I would also have to ship > the EULA, and as an end-user (of python) I can't just redistribute the > files - perhaps I could write a place holder application in

Re: Proposal: an unchanging URL for Python documentation

2005-04-18 Thread Tim Peters
[Steve] > I have a suggestion/request that will, I think, improve the Python > documentation. > > Currently, the Python documentation in HTML format is stored at URLs > that change with each new release of Python. That is, for example, the > documentation for the os module is at > http://python.or

Re: How to run Python in Windows w/o popping a DOS box?

2005-04-19 Thread Tim Peters
[Paul Rubin] > Dumb question from a Windows ignoramus: > > I find myself needing to write a Python app (call it myapp.py) that > uses tkinter, which as it happens has to be used under (ugh) Windows. > That's Windows XP if it makes any difference. Nope, the Windows flavor doesn't matter. > I put a

Re: time.strftime in 2.4.1 claims data out of range when not

2005-04-22 Thread Tim Peters
[Sheila King] > I have a web app that has been running just fine for several months under > Python 2.2.2. > > We are preparing to upgrade the server to run Python 2.4.1. > > However, part of my web app is throwing an error on this code (that has > previously worked without exception): > > >>> time.

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-30 Thread Tim Peters
[Mike Rovner] > 3 IS wrong because if you use any not BIG letter after bodyguard on both > sides, you get extra 'eCQQmSXK\n' which slow me down for 5 minutes. Get rid of the newlines first. On level 7, I'm not sure whether there's something more to do, or whether I'm looking at a bug in how IE di

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-03 Thread Tim Peters
[Chris McAloney] > Okay, so I've been working on level seven for a LONG time now. Hmm. I've been staring at that one 18 hours a day since last Friday, and still don't have the foggiest idea. I've counted boxes, counted pixels, broken it apart and rearranged it like a jigsaw puzzle, ran "strings"

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-03 Thread Tim Peters
[Tiziano Bettio] > PLEASE HELP... > > What the hell do i have to pronounce in puzzle 5 > > Some useful hints would be awesome That's a funny one: I didn't understand the "pronounce it" hint until long after I solved that one. Then again, Guido & I implemented PEP 307, so I knew what to do th

Re: Python Challenge ahead [NEW] for riddle lovers

2005-05-03 Thread Tim Peters
[Tim Peters, whines about level 7] [Dan Christensen, gives a huge hint] The first time I looked at it, I thought "hmm, I should use PIL for this". I kept thinking that too -- but for some reason wanted to see if there was a clear way to do it without something that "fancy"

Re: Inverse confusion about floating point precision

2005-05-09 Thread Tim Peters
[Skip Montanaro] > I understand why the repr() of float("95.895") is "95.8949996". > What I don't understand is why if I multiply the best approximation to > 95.895 that the machine has by 1 I magically seem to get the lost > precision back. To wit: > >% python >Python 2.3.4 (#

  1   2   3   4   >