Re: Can you pass functions as arguments?

2005-12-18 Thread Paul Rubin
[EMAIL PROTECTED] writes: I want to calculate f(0) + f(1) + ...+ f(100) over some function f which I can change. So I would like to create a function taking f as argument giving back the sum. How do you do that in Python? You can just pass f as an argument. The following is not the most

Re: Accessing next/prev element while for looping

2005-12-19 Thread Paul Rubin
Joseph Garvin [EMAIL PROTECTED] writes: And this way I can keep referring to j instead of myarray[i], but I'm still forced to use myarray[i-1] and myarray[i+1] to refer to the previous and next elements. Being able to do j.prev, j.next seems more intuitive. Is there some other builtin

Re: Accessing next/prev element while for looping

2005-12-19 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: elts = iter(myarray) prev,cur,next = elts.next(),elts.next(),elts.next() for next2 in elts: do_something_with (prev, cur, next) prev,cur,next = cur, next, next2 Of course these fail when there's less than 3 elements. Ehh

Re: Can you pass functions as arguments?

2005-12-19 Thread Paul Rubin
[EMAIL PROTECTED] (Bengt Richter) writes: or if the OP actually wants the specific function, def sum100a(f): return sum(imap(f, xrange(101))) ... sum100a(square) 338350 Similarly with generator comprehension, if I have the syntax right: def sum100c(f): return sum(f(i) for i in

Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Paul Rubin
Russell E. Owen [EMAIL PROTECTED] writes: I disagree. Once you've picked a database (not trivial in itself, of course), you typically only have a few options for talking to in in Python. Also, typically either: - One stands out (because others have been abandoned or whatever), so there's

Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Paul Rubin
Mike Meyer [EMAIL PROTECTED] writes: What makes me think I need a database is a requirement that says multiple simultaneous writers. I'd go a little further and say multiple simultaneous writers doing multi-step transactions with steps that can have high latency, e.g. transactions that have to

Re: Which Python web framework is most like Ruby on Rails?

2005-12-19 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: If the transactions are simple and low-latency, then it can be enough to have a single process own the whole database, and have every client send all its requests to the db process. Meant to say: it can be enough to let the clients lock the database

Re: adding vectors

2005-12-19 Thread Paul Rubin
Andy Leszczynski [EMAIL PROTECTED] writes: Short question: why (1,abc,0.3)+(2,def,10.2) != (3,abcdef,10.5)? How to elegantly achieve (3,abcdef,10.5) as a result of addition ... tuple([(a+b) for a,b in zip((1,abc,0.3),(2,def,10.2))]) -- http://mail.python.org/mailman/listinfo/python-list

Re: adding vectors

2005-12-19 Thread Paul Rubin
Mike Meyer [EMAIL PROTECTED] writes: map(operator.add, (1, abc, 0.3), (2, def, 10.2)) [3, 'abcdef', 10.5] Not having to do the zip is win. operator.add is a lose. I'm not sure either is what I'd call elegant. Yeah, I didn't bother checking whether you could pass dyadic functions to map.

Re: Do you recommend a good artificial intelligence book?

2005-12-20 Thread Paul Rubin
Tolga [EMAIL PROTECTED] writes: Is there anybody here interested in artificial intelligence (AI)? Yes, perhaps this thread would be more suitable for an AI usenet group and I have also posted my question there, but I want to know Python community's opinion. Could you recommend me please a good

Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Luis M. Gonzalez [EMAIL PROTECTED] writes: Perhaps you can tell us what's the problem with GPL and, if possible, propose an alternative... See: http://www.gnu.org/philosophy/pragmatic.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Raw images

2005-12-20 Thread Paul Rubin
Tuvas [EMAIL PROTECTED] writes: I have an image that is in a raw format, Do you mean a RAW file from a digital camera? Those files have complex and sometimes secret formats. Google dcraw.c for a decoding program that works for many cameras. --

Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Kent Johnson [EMAIL PROTECTED] writes: I chose CherryPy in part because its license allows this. I would have considered Karrigell if it had a different license. Have you had to modify CherryPy in some substantive way that you needed to keep proprietary, as opposed to simply developing content

Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Kent Johnson [EMAIL PROTECTED] writes: I did make some changes to CherryPy. I wouldn't mind sharing those changes back with the CherryPy community. But the product was the server itself, not the web site. As I understand the GPL the server software would be a work based on the [GPL-licensed]

Re: Which Python web framework is most like Ruby on Rails?

2005-12-20 Thread Paul Rubin
Kent Johnson [EMAIL PROTECTED] writes: You've lost me here. The server certainly would contain Karrigell code, it wouldn't function without it. I don't understand the analogy to GCC, the web site is not something that is compiled with Karrigell. Karrigell is a library or framework that is an

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes: However the work I do is commercial and proprietary and I doubt I could get approval to release it under GPL. I see the GPL is a problem in this environment, and you are clearly aware of the issues it raises. Do be aware, though, that not all GPL

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Pierre Quentel [EMAIL PROTECTED] writes: I am Karrigell's author. I have chosen the GPL licence almost at random (I saw that the Python licence was GPL-compatible), so I don't mind switching to another Open Source licence if the GPL is liable to cause problems. Which one would you advice : BSD

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes: Indeed. But most software authors aren't lawyers and aren't likely to trust their own judgment about these matters unless the situation is pretty unambiguous. I suspect this may be evidence that Microsoft's viral propaganda has had some effect. Hmm,

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Ben Sizer [EMAIL PROTECTED] writes: Unfortunately, that doesn't really satisfy the GPL's concerns. The work arguably contains or is derived from Karrigell, I don't see that. The web app gets run by Karrigell like a CGI script is run by Apache, like a Linux app is run by the Linux kernel. The

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
Richie Hindle [EMAIL PROTECTED] writes: A good solution would be multiple-licensing. You state that the code is (for example) triple-licensed under the GPL, LGPL and BSD licenses. The user of your code decides which license to obey. It's no more work for you, and you can please almost

Re: How to check if a string is an int?

2005-12-21 Thread Paul Rubin
Kent Johnson [EMAIL PROTECTED] writes: Maybe so, but '15'.isdigit() == True: isdigit(...) S.isdigit() - bool Return True if all characters in S are digits and there is at least one character in S, False otherwise. Auh!! --

Re: Which Python web framework is most like Ruby on Rails?

2005-12-21 Thread Paul Rubin
(Responding to several posts) Ben Sizer [EMAIL PROTECTED] writes: I don't see that. The web app gets run by Karrigell like a CGI script is run by Apache, like a Linux app is run by the Linux kernel. The web app uses parts of Karrigell though - things like the QUERY variable or or Session

Re: How to check if a string is an int?

2005-12-21 Thread Paul Rubin
Erik Max Francis [EMAIL PROTECTED] writes: The primary purpose of the .isdigit, etc. methods is to test whether a single character has a certain property. There is, however, no special character data type in Python, and so by necessity those methods must be on strings, not characters. Right,

Re: Tk not displaying correctly

2005-12-21 Thread Paul Rubin
Tuvas [EMAIL PROTECTED] writes: What (I think) will happen is when you hit the button, until x=100, the display will stop updating, and when the command has left it's thread, it will return to updating again. Is there a way to make it so it always will update, irreguardless if it's in a

Re: Which Python web framework is most like Ruby on Rails?

2005-12-22 Thread Paul Rubin
Richie Hindle [EMAIL PROTECTED] writes: Paul, you keep making comparisons between Python web frameworks and the Linux kernel. Are you aware that there is a special note attached to the Linux GPL[1] explaining that user-space code is not considered a derived work of the Linux kernel? Without

Re: serialize object in jython, read into python

2005-12-22 Thread Paul Rubin
py [EMAIL PROTECTED] writes: Noah wrote: You can give up on pickle, because pickle is only guaranteed to work with the exact same version of the Python interpreter. :( No that's confusing pickle with marshal. Pickle is supposed to work across versions, though it has recently grown a

Re: Interesting little gotcha with generators

2005-12-22 Thread Paul Rubin
[EMAIL PROTECTED] (Aahz) writes: What's wrong with def foo(): if False: yield None Does the following work? def foo(): raise StopIteration -- http://mail.python.org/mailman/listinfo/python-list

Re: Which Python web framework is most like Ruby on Rails?

2005-12-22 Thread Paul Rubin
Jeff Rush [EMAIL PROTECTED] writes: Your only solution would be a proprietary license that states you purchased this program and don't have the right to pass it on to others, similar to ActiveState or somesuch. It sounds like that's what Kent wants to do with the apps that he's building.

Re: Which Python web framework is most like Ruby on Rails?

2005-12-23 Thread Paul Rubin
Robert Kern [EMAIL PROTECTED] writes: RMS has said precisely the opposite, in fact. http://lists.debian.org/debian-legal/2002/11/msg00217.html I guess you mean: [RMS:] As for the more general question, we think that a program that uses Emacs facilities needs to be GPL-covered, but a program

Re: How to check if a string is an int?

2005-12-23 Thread Paul Rubin
Fredrik Lundh [EMAIL PROTECTED] writes: no, but all characters in the string belongs to the digit character class, which is what the is predicates look for. That description is not quite right. All characters in the empty string belong to the digit character class, but isdigit returns false

Re: How to check if a string is an int?

2005-12-23 Thread Paul Rubin
Fredrik Lundh [EMAIL PROTECTED] writes: A: are there any blue cars on the street? B: no. not a single one. A: you're wrong! all cars on the street are blue! B and A are both correct. It's just logic ;-). -- http://mail.python.org/mailman/listinfo/python-list

Re: sorting with expensive compares?

2005-12-23 Thread Paul Rubin
Kent Johnson [EMAIL PROTECTED] writes: [a] - [ (hash(a), a) ] This won't work - elements with different hashes will sort by hash and elements with the same hash will still be compared which is exactly what the OP is trying to avoid. ds = sorted([(hash(c), i) for i,c in enumerate(a)]) dsu =

Re: sorting with expensive compares?

2005-12-23 Thread Paul Rubin
Dan Stromberg [EMAIL PROTECTED] writes: I've been using the following compare function, which in short checks, in order: 1) device number 2) inode number 3) file length 4) the beginning of the file 5) an md5 hash of the entire file 6) the entire file (If #1 and #2 are identical, then

Re: sorting with expensive compares?

2005-12-23 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: http://www.iusmentis.com/technology/encryption/pgp/pgpattackfaq/hash/ the expected number of random unique files you would need to compare before finding a single collision in the MD5 hashes is (very roughly) 10**70, or ten billion trillion trillion

Re: sorting with expensive compares?

2005-12-23 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: There are also known ways of deliberately constructing md5 collisions (i.e. md5 is broken). Whether the OP should care about that depends on the application. Sure, but I don't he is deliberately trying to sabotage his own files :-) He might have

Re: Timing out arbitrary functions

2005-12-24 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: How do others handle something like this? What should I be looking for? I'm after a lightweight solution, if any such thing exists. Is something stopping you from using sigalarm? -- http://mail.python.org/mailman/listinfo/python-list

Re: Timing out arbitrary functions

2005-12-24 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: Is something stopping you from using sigalarm? Pure ignorance of its existence. Thanks, I'll check it out. Two things to keep in mind: - You can have only ONE alarm pending for the whole process. If different things in the program need timeouts

Re: sorting with expensive compares?

2005-12-25 Thread Paul Rubin
Thomas Wouters [EMAIL PROTECTED] writes: But the odds of such a message having the same MD5 as an existing song on his disk is quite a lot higher than 2**64, unless he has a really, really large music collection ;) In the case you propose, two files don't just need to have the same MD5, but

Re: Line replace

2006-01-01 Thread Paul Rubin
DarkBlue [EMAIL PROTECTED] writes: Now our authorized clients register themselves automatically with computername,id and ip address via a small python script which sends this information to a firebird database on our server... Every client has a marker in the hosts.allow file so if a change

Re: Line replace

2006-01-01 Thread Paul Rubin
DarkBlue [EMAIL PROTECTED] writes: The markers are just there to have a static way to find the line after the marker, which is the one which might have to be changed. OK, why don't you store those changing lines in the database? Can you arrange for those changeable lines to be fixed length,

Re: Hypergeometric distribution

2006-01-01 Thread Paul Rubin
Raven [EMAIL PROTECTED] writes: Yes I am calculating hundreds of hypergeometric probabilities so I need fast calculations Can you use Stirling's approximation to get the logs of the factorials? -- http://mail.python.org/mailman/listinfo/python-list

Re: how to scrape url out of href

2006-01-01 Thread Paul Rubin
[EMAIL PROTECTED] writes: does anyone have sample code for scraping the actual url out of an href like this one a href=http://www.cnn.com; target=_blank If you've got the tag by itself like that, just use a regexp to get the href out. -- http://mail.python.org/mailman/listinfo/python-list

Re: itertools.izip brokeness

2006-01-03 Thread Paul Rubin
[EMAIL PROTECTED] writes: The problem is that sometimes, depending on which file is the shorter, a line ends up missing, appearing neither in the izip() output, or in the subsequent direct file iteration. I would guess that it was in izip's buffer when izip terminates due to the exception on

Re: itertools.izip brokeness

2006-01-03 Thread Paul Rubin
[EMAIL PROTECTED] writes: But that is exactly the behaviour of python iterator, I don't see what is broken. What's broken is the iterator interface is insufficient to deal with this cleanly. And because python iterator can only go in one direction, those consumed do lose in the zip/izip

Re: itertools.izip brokeness

2006-01-03 Thread Paul Rubin
[EMAIL PROTECTED] writes: map(None,[1,2,3],[4,5]) gives [(1,4),(2,5),(3,None)] I didn't know that until checking the docs just now. Oh man, what a hack! I always thought Python should have a built-in identity function for situations like that. I guess it does the above instead. Thanks. Jeez

Re: itertools.izip brokeness

2006-01-03 Thread Paul Rubin
Diez B. Roggisch [EMAIL PROTECTED] writes: No. If you want that, use list(iterable) Then you have random access. If you _know_ there will be only so much data needed to unget, write yourself a buffered iterator like this: You can't use list(iterable) in general because the iterable may be

Re: Calling GPL code from a Python application

2006-01-03 Thread Paul Rubin
Michel Sanner [EMAIL PROTECTED] writes: A google search about GPL and dynamic linking came up with an equal number of pages saying that dynamic linking of GPL code into non GPL applications is allowed as it is the end user who cretes the derived work, as pages saying the opposite ! So does

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Paul Rubin
Dr. Colombes [EMAIL PROTECTED] writes: I'm looking for a good Python way to generate (enumerate) the 2**N tuples representing all vertices of the unit hypercube in N-dimensional hyperspace. For example, for N=4 the Python code should generate the following 2**N = 16 tuples: Here's a

Re: How to generate (enumerate) 2**N tuples representing all vertices of unit hypercube in N-dimensional hyperspace ?

2006-01-03 Thread Paul Rubin
Heiko Wundram [EMAIL PROTECTED] writes: def perm(n): rv = [] for i in xrange(2L**n): cur = [] for j in range(n): cur.append(1-2*(bool(i (1j # cur is in reversed order LSB first, but as you seemingly don't # care about order of the

Re: itertools.izip brokeness

2006-01-04 Thread Paul Rubin
Raymond Hettinger [EMAIL PROTECTED] writes: Feel free to submit a feature request to the SF tracker (surprisingly, this behavior has not been previously reported, nor have there any related feature requests, nor was the use case contemplated in the PEP discussions:

Re: Hypergeometric distribution

2006-01-04 Thread Paul Rubin
Raven [EMAIL PROTECTED] writes: The problem with Stirling's approximation is that I need to calculate the hypergeometric hence the factorial for numbers within a large range e.g. choose(14000,170) or choose(5,2) Stirling's approximation to second order is fairly accurate even at low values:

Re: Application architecture (long post - sorry)

2006-01-05 Thread Paul Rubin
[EMAIL PROTECTED] writes: All these web technologies I don't know where to start, have you got any suggestions for getting started in the world of web development, books maybe ? This is out of date but may help get started. http://philip.greenspun.com/panda/ --

Re: itertools.izip brokeness

2006-01-05 Thread Paul Rubin
Michael Spencer [EMAIL PROTECTED] writes: for i in range(10): result = [] ... Do you mean while True: ...? def izip2(*iterables, **kw): kw:fill. An element that will pad the shorter iterable fill = repeat(kw.get(fill)) Yet another attempt (untested, uses

Re: itertools.izip brokeness

2006-01-05 Thread Paul Rubin
[EMAIL PROTECTED] writes: def izip4(*iterables, **kw): kw:fill. An element that will pad the shorter iterable kw:infinite. Number of non-terminating iterators That's a really kludgy API. I'm not sure what to propose instead: maybe some way of distinguishing which iterables are

Re: itertools.izip brokeness

2006-01-06 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: # quit if only discardables are left dropwhile(lambda i,t: (not isinstance(i, Discardable)) and len(t)), izip(t, iterables)).next() Ehh, that should say dropwhile(lambda (t,i): ...) to use tuple unpacking and get

Re: How run web software *locally* easily?

2006-01-06 Thread Paul Rubin
[EMAIL PROTECTED] [EMAIL PROTECTED] writes: Is there some easy way to somehow perhaps embed a minimal web server in a Python tar ball Yes, sure, see any of the HTTP server classes in the stdlib. Just listen on a localhost socket and pop a browser to point to that socket. --

Re: itertools.izip brokeness

2006-01-06 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: def izip5(*iterables, fill=None): Doesn't work: keyword arguments must be listed before * and ** arguments. Eh, ok, gotta use **kw. def function(*iterators, **kwargs): if kwargs.keys() != [fill]: raise ValueError ... It

Re: Calling foreign functions from Python? ctypes?

2006-01-06 Thread Paul Rubin
Martin v. Löwis [EMAIL PROTECTED] writes: To my knowledge, ctypes has never been contributed to Python, either, so its author apparently has no plan, either. Has anyone from Python.org asked him or her? -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling foreign functions from Python? ctypes?

2006-01-06 Thread Paul Rubin
Neil Hodgson [EMAIL PROTECTED] writes: No. It is the responsibility of the extension author to ensure that there is no possibility of crashing Python. With ctypes, you have a generic mechanism that enables Python code to cause a crash. http://docs.python.org/lib/module-dl.html would seem

Re: Spelling mistakes!

2006-01-06 Thread Paul Rubin
Steven D'Aprano [EMAIL PROTECTED] writes: Duh. Next time I use a dictionary before freezing an API! Can you please explain what you mean by that? Use a dictionary how? Use a dictionary by looking up words in it to check the spelling. -- http://mail.python.org/mailman/listinfo/python-list

Re: Does Python allow access to some of the implementation details?

2006-01-06 Thread Paul Rubin
Claudio Grondi [EMAIL PROTECTED] writes: The question is if Python allows somehow access to the bytes of the representation of a long integer or integer in computers memory? No it doesn't, and that's a good thing, since the internal representation is a little bit surprising (it stores 15 bits

Re: download full sites?

2006-01-06 Thread Paul Rubin
[EMAIL PROTECTED] writes: hi, does anyone know of any package that will download a full site for offline viewing? It will change all url to match local urls and follow a logical structure (the site's structure would be suffice).. Please tell me if you have heard of such a package.. thanks alot

Re: Translate this to python?

2006-01-07 Thread Paul Rubin
Heiko Wundram [EMAIL PROTECTED] writes: I know this, and that's one of the reasons I'm a little at odds with Python 3000... some things are so basic (such as xrange) I wouldn't want to have to implement them every time I need such a beast. Itertools.count could be extended to replace xrange.

Re: Converting milliseconds to human time

2006-01-07 Thread Paul Rubin
Harlin Seritt [EMAIL PROTECTED] writes: I would like to take milliseconds and convert it to a more human-readable format like: 4 days 20 hours 10 minutes 35 seconds # To iterate is human; to recurse, divine. def dhms(m,t): if not t: return (m,) return rl(m//t[0], t[1:]) + (m % t[0],)

Re: Converting milliseconds to human time

2006-01-07 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: def dhms(m,t): if not t: return (m,) return rl(m//t[0], t[1:]) + (m % t[0],) Editing error, sigh. Meant of course to say return dhms(m//t[0], t[1:]) + (m % t[0],) -- http://mail.python.org/mailman/listinfo/python-list

Re: Help wanted with md2 hash algorithm

2006-01-07 Thread Paul Rubin
[EMAIL PROTECTED] writes: below you find my simple python version of MD2 algorithm as described in RFC1319 (http://rfc1319.x42.com/MD2). It produces correct results for strings shorter than 16 Bytes and wrong results for longer strings. Why do you want to use MD2? It's very slow and it's

Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-09 Thread Paul Rubin
Raymond Hettinger [EMAIL PROTECTED] writes: I am evaluating a request for an alternate version of itertools.izip() that has a None fill-in feature like the built-in map function: map(None, 'abc', '12345') # demonstrate map's None fill-in feature I think finding different ways to write it

Re: Help wanted with md2 hash algorithm

2006-01-09 Thread Paul Rubin
[EMAIL PROTECTED] writes: I want to understand it, and -- therefor ;-) -- I want to implement it in pure Pyhton. OK. It should be pretty easy to implement. You should find the official rfc at ietf.org. I remember there was some minor erratum in the original version that may or may not have

Re: Real-world use cases for map's None fill-in feature?

2006-01-09 Thread Paul Rubin
Raymond Hettinger [EMAIL PROTECTED] writes: The generator version is plain, simple, boring, and uninspirational. But it took only seconds to write and did not require a knowledge of advanced itertool combinations. It more easily explained than the versions with zip tricks. I had this cute

Re: Help wanted with md2 hash algorithm

2006-01-09 Thread Paul Rubin
[EMAIL PROTECTED] writes: I thought I had build a proper implementation in Python. The error you mention can be avoided by studying the C implementation in RFC 1319. BUT: Some of the test vectors failed. That's my problem ;-( And therefore I asked for help. You might check PyCrypt against the

Re: Help wanted with md2 hash algorithm

2006-01-09 Thread Paul Rubin
[EMAIL PROTECTED] writes: Already done before my first posting. But the problem was there. I studied the C sources of MD2 of that package, too. But all test cases with more than 16 bytes failed. Hmm, did the test cases work for the RFC 1319 reference code? What about OpenSSL? I thought when

Re: Help wanted with md2 hash algorithm

2006-01-09 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: Hmm, did the test cases work for the RFC 1319 reference code? What about OpenSSL? I just checked OpenSSL and all the test values it computes match the RFC. -- http://mail.python.org/mailman/listinfo/python-list

Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-10 Thread Paul Rubin
Raymond Hettinger [EMAIL PROTECTED] writes: iterator = check_empty(iterator) There are so many varieties of iterator that it's probably not workable to alter the iterator API for all of the them. In any case, a broad API change like this would need its own PEP. The hope was that it

Re: Failing unittest Test cases

2006-01-10 Thread Paul Rubin
Scott David Daniels [EMAIL PROTECTED] writes: Recently there was a checkin of a test that _should_ work but doesn't. The discussion got around to means of indicating such tests (because the effort of creating a test should be captured) without disturbing the development flow. Do you mean

Re: Failing unittest Test cases

2006-01-10 Thread Paul Rubin
Fredrik Lundh [EMAIL PROTECTED] writes: no, he means exactly what he said: support for expected failures makes it possible to add test cases for open bugs to the test suite, without 1) new bugs getting lost in the noise, and 2) having to re- write the test once you've gotten around to fix the

Re: try: except never:

2006-01-10 Thread Paul Rubin
Hallvard B Furuseth [EMAIL PROTECTED] writes: 'except None:' works for now, but I don't know if that's safe: for ex in ZeroDivisionError, None: try: 1/0 except ex: print Ignored first exception. class NeverRaised(Exception): pass for ex in

Re: try: except never:

2006-01-10 Thread Paul Rubin
Hallvard B Furuseth [EMAIL PROTECTED] writes: class NeverRaised(Exception): pass for ex in ZeroDivisionError, NeverRaised: Heh. Simple enough. Unless some obstinate person raises it anyway... Hmm, ok, how's this?: def NeverRaised(): class blorp(Exception): pass return blorp

Re: Efficient mechanism for str.startswith on a set.

2006-01-10 Thread Paul Rubin
Brian Cole [EMAIL PROTECTED] writes: This is obviously the least efficient manner to do this as I'll always be iterating over the entire 'strs'. I know I could make a binary tree out of 'strs' but that's a little more work that don't have time to do today. I know there should be something out

Re: Do you have real-world use cases for map's None fill-in feature?

2006-01-10 Thread Paul Rubin
Szabolcs Nagy [EMAIL PROTECTED] writes: there are iterators which has length: i = iter([1,2,3]) len(i) 3 now isn't there a way to make this length inheritible? I expect that's a __len__ method, which can be inherited. eg. generators could have length in this case: g = (x for x in

Re: Augmented generators?

2006-01-10 Thread Paul Rubin
Andrew Koenig [EMAIL PROTECTED] writes: Can anyone think of an easy technique for creating an object that acts like a generator but has additional methods? For example, it might be nice to be able to iterate through an associative container without having to index it for each element.

Re: Is 'everything' a refrence or isn't it?

2006-01-10 Thread Paul Rubin
Donn Cave [EMAIL PROTECTED] writes: But you're asking for more than that. We're not just talking about how people think about value, you want a definition that's suitable for a language reference. Whereupon you would indeed run into the kinds of questions you pose above, and more. I know

Re: Failing unittest Test cases

2006-01-10 Thread Paul Rubin
[EMAIL PROTECTED] writes: Got any ideas how that is to be accomplished short of jiggering the names so they sort in the order you want them to run? How about with a decorator instead of the testFuncName convention, i.e. instead of def testJiggle(): # test in the func name means it's a

Re: flatten a level one list

2006-01-11 Thread Paul Rubin
Robin Becker [EMAIL PROTECTED] writes: f([(x0,y0),(x1,y1),]) -- [x0,y0,x1,y1,] import operator a=[(1,2),(3,4),(5,6)] reduce(operator.add,a) (1, 2, 3, 4, 5, 6) -- http://mail.python.org/mailman/listinfo/python-list

Re: flatten a level one list

2006-01-11 Thread Paul Rubin
Paul Rubin http://[EMAIL PROTECTED] writes: import operator a=[(1,2),(3,4),(5,6)] reduce(operator.add,a) (1, 2, 3, 4, 5, 6) (Note that the above is probably terrible if the lists are large and you're after speed.) -- http://mail.python.org/mailman/listinfo/python-list

Re: Can dictionaries be nested?

2006-01-11 Thread Paul Rubin
[EMAIL PROTECTED] writes: First, can dictionaries contain dictionaries? Yes. Second, how to create each successive inner dictionary when populating it? Python doesn't have constructors and (having all of 4 weeks of Python experience) it isn't clear to me whether in nested while loops that

Re: Python Scripts to logon to websites

2006-01-11 Thread Paul Rubin
Peter Hansen [EMAIL PROTECTED] writes: My information about digest was either obsolete or simply wrong, as I didn't realize it had all the nonce and anti-replay support it appears to have. (I may have been remembering articles about how much of that wasn't supported widely at some time in the

Re: Python Scripts to logon to websites

2006-01-11 Thread Paul Rubin
Mike Meyer [EMAIL PROTECTED] writes: Only if the userid and password are part of the content. If you're doing the usual form-based authentication, then they are. If you're doing an HTTP-based authentication, then they aren't - the authentication information is in the headers, and can be

Re: Why keep identity-based equality comparison?

2006-01-12 Thread Paul Rubin
Antoon Pardon [EMAIL PROTECTED] writes: There is a use case for things like 1 (1,3) making sense and denoting a total order. When you have a hetergenous list, having a total order makes it possible to sort the list which will make it easier to weed out duplicates. So why don't you demand a

Re: flatten a level one list

2006-01-12 Thread Paul Rubin
Robin Becker [EMAIL PROTECTED] writes: reduce(operator.add,a) ... A fast implementation would probably allocate the output list just once and then stream the values into place with a simple index. That's what I hoped sum would do, but instead it barfs with a type error. So much for duck

Re: Python Scripts to logon to websites

2006-01-12 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes: Underlining your point, the difference between the two is that digest offers *strong* authentication (i.e. is not subject to replay attacks) As I mentioned in another post, that's really not enough, since digest still exposes the password hash to offline

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
[EMAIL PROTECTED] writes: Still, I'd love to hear how you guys would do it. Make a subclass of dict, or an object containing a dictionary, that has a special __setattr__ method that traps updates and sets that modification flag. There are contorted ways the caller can avoid triggering the flag,

Re: Hiding input charachters

2006-01-12 Thread Paul Rubin
Robert Hilkene [EMAIL PROTECTED] writes: Can any body help, I wanna to hide input characters from user (when he enters password)? http://docs.python.org/lib/module-getpass.html -- http://mail.python.org/mailman/listinfo/python-list

Re: Why keep identity-based equality comparison?

2006-01-12 Thread Paul Rubin
Antoon Pardon [EMAIL PROTECTED] writes: The bisect module doesn't have an alternate comparison function neither has the heapqueue module. They could be extended. Care to enter a feature request? 1) Python could provide a seperare total ordering, maybe with operators like '|' and '|' and

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
Brian van den Broek [EMAIL PROTECTED] writes: It's broken in at least one way: newmd = ModFlagDict(3=4, 1=5) SyntaxError: keyword can't be an expression newmd = ModFlagDict(**{3:4, 1:5}) -- http://mail.python.org/mailman/listinfo/python-list

Re: flatten a level one list

2006-01-12 Thread Paul Rubin
Sion Arrowsmith [EMAIL PROTECTED] writes: sum(sequence, start=0) - value If you're using sum() as a 1-level flatten you need to give it start=[]. Oh, right, I should have remembered that. Thanks. Figuring out whether it's quadratic or linear would still take an experiment or code

Re: How can I create a dict that sets a flag if it's been modified

2006-01-12 Thread Paul Rubin
Steve Holden [EMAIL PROTECTED] writes: Make a subclass of dict, or an object containing a dictionary, that has a special __setattr__ method that traps updates and sets that /__setattr__/__setitem__/ ? Yes, thinkographical error. Thanks. --

Re: Timeout at command prompt

2006-01-12 Thread Paul Rubin
Amit Khemka [EMAIL PROTECTED] writes: import signal TIMEOUT = 5 # number of seconds your want for timeout signal.signal(signal.SIGALRM, input) signal.alarm(TIMEOUT) def input(): try: foo = raw_input() return foo except: # timeout return This doesn't work with raw_input

Re: Real-world use cases for map's None fill-in feature?

2006-01-13 Thread Paul Rubin
Raymond Hettinger [EMAIL PROTECTED] writes: I see at least a few cases of map(None, field_names, values) but it's not clear what the expectation is for the size of the two lists. ... Thanks for the additional datapoint. I'm most interested in the code surrounding the few cases with

Re: Converting a string to an array?

2006-01-13 Thread Paul Rubin
Tim Chase [EMAIL PROTECTED] writes: The closest hack I could come up with was import random s = abcdefg a = [] a.extend(s) random.shuffle(a) s = .join(a) You could use import random s = list(abcdefg) random.shuffle(s) s

Re: dual processor

2005-09-05 Thread Paul Rubin
Nick Craig-Wood [EMAIL PROTECTED] writes: of is decrementing a reference count. Only one thread can be allowed to DECREF at any given time for fear of leaking memory, even though it will most often turn out the objects being DECREF'ed by distinct threads are themselves distinct.

<    1   2   3   4   5   6   7   8   9   10   >