Re: recv_into(bytearray) complains about a "pinned buffer"

2010-02-01 Thread Andrew Dalke
On Feb 2, 12:12 am, Martin v. Loewis wrote: > My recommendation would be to not use recv_into in 2.x, but only in 3.x. > I don't think that's the full solution. The array module should also > implement the new buffer API, so that it would also fail with the old > recv_into. Okay. But recv_into wa

Re: recv_into(bytearray) complains about a "pinned buffer"

2010-01-31 Thread Andrew Dalke
On Feb 1, 1:04 am, Antoine Pitrou wrote: > The problem is that socket.recv_into() in 2.6 doesn't recognize the new > buffer API which is needed to accept bytearray objects. > (it does in 3.1, because the old buffer API doesn't exist anymore there) That's about what I thought it was, but I don't k

recv_into(bytearray) complains about a "pinned buffer"

2010-01-31 Thread Andrew Dalke
hon 3.1.1 (r311:74480, Jan 31 2010, 23:07:16) [GCC 4.2.1 (Apple Inc. build 5646) (dot 1)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import socket >>> sock = socket.socket() >>&

Re: Update the sorting mini-howto

2005-11-29 Thread Andrew Dalke
I wrote: > Years ago I wrote the Sorting mini-howto, currently at > > http://www.amk.ca/python/howto/sorting/sorting.html Thanks to amk it's now on the Wiki at http://wiki.python.org/moin/HowTo/Sorting so feel free to update it directly. Andrew

Update the sorting mini-howto

2005-11-29 Thread Andrew Dalke
Years ago I wrote the Sorting mini-howto, currently at http://www.amk.ca/python/howto/sorting/sorting.html I've had various people thank me for that, in person and through email. It's rather out of date now given the decorate-sort-undecorate option and 'sorted' functions in Python 2.4. Hmmm,

Re: PEP on path module for standard library

2005-07-31 Thread Andrew Dalke
Peter Hansen wrote: > A scattered assortment of module-level global function names, and > builtins such as open(), make it extraordinarily difficult to do > effective and efficient automated testing with "mock" objects. I have been able to do this by inserting my own module-scope function that i

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
Peter Otten wrote: > Seems my description didn't convince you. So here's an example: Got it. In my test case the longest element happened to be the last one, which is why it didn't catch the problem. Thanks. Andrew [EMAIL PROTECTED

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
Scott David Daniels wrote: > Can I play too? How about: Sweet! Andrew [EMAIL PROTECTED] -- http://mail.python.org/mailman/listinfo/python-list

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
Me: >> Could make it one line shorter with > >> from itertools import chain, izip, repeat >> def fillzip(*seqs): >> def done_iter(done=[len(seqs)]): >> done[0] -= 1 >> if not done[0]: >> return [] >> return repeat(None) >> seqs = [chain(seq, done_iter()

Re: can list comprehensions replace map?

2005-07-29 Thread Andrew Dalke
Peter Otten wrote: > Combining your "clever" and your "elegant" approach to something fast > (though I'm not entirely confident it's correct): > > def fillzip(*seqs): > def done_iter(done=[len(seqs)]): > done[0] -= 1 > if not done[0]: > return > while 1: >

Re: os._exit vs. sys.exit

2005-07-28 Thread Andrew Dalke
Bryan wrote: > Why does os._exit called from a Python Timer kill the whole process while > sys.exit does not? On Suse. os._exit calls the C function _exit() which does an immediate program termination. See for example http://developer.apple.com/documentation/Darwin/Reference/ManPages/man2/_e

Re: can list comprehensions replace map?

2005-07-28 Thread Andrew Dalke
Christopher Subich wrote: > My naive solution: ... >for i in ilist: > try: > g = i.next() > count += 1 > except StopIteration: # End of iter > g = None ... What I didn't like about this was the extra overhead of all the StopIt

Re: can list comprehensions replace map?

2005-07-28 Thread Andrew Dalke
Me: > Here's a clever, though not (in my opinion) elegant solution ... > This seems a bit more elegant, though the "replace" dictionary is > still a bit of a hack Here's the direct approach without using itertools. Each list is iterated over only once. No test against a sequence element is ever

Re: can list comprehensions replace map?

2005-07-28 Thread Andrew Dalke
Steven Bethard wrote: > Here's one possible solution: > > py> import itertools as it > py> def zipfill(*lists): > ... max_len = max(len(lst) for lst in lists) A limitation to this is the need to iterate over the lists twice, which might not be possible if one of them is a file iterator. Here's

Re: can list comprehensions replace map?

2005-07-27 Thread Andrew Dalke
David Isaac wrote: > I have been generally open to the proposal that list comprehensions > should replace 'map', but I ran into a need for something like > map(None,x,y) > when len(x)>len(y). I cannot it seems use 'zip' because I'll lose > info from x. How do I do this as a list comprehension? (O

Re: how to write a line in a text file

2005-07-26 Thread Andrew Dalke
> [EMAIL PROTECTED] wrote: >> Well, it's what (R)DBMS are for, but plain files are not. Steven D'Aprano wrote: > This isn't 1970, users expect more from professional > programs than "keep your fingers crossed that nothing > bad will happen". That's why applications have multiple > levels of und

Re: [path-PEP] Path inherits from basestring again

2005-07-25 Thread Andrew Dalke
> Reinhold Birkenfeld wrote: >> Current change: >> >> * Add base() method for converting to str/unicode. Now that [:] slicing works, and returns a string, another way to convert from path.Path to str/unicode is path[:] Andrew [EMAIL

Re: [path-PEP] Path inherits from basestring again

2005-07-24 Thread Andrew Dalke
Reinhold Birkenfeld wrote: > Okay. While a path has its clear use cases and those don't need above methods, > it may be that some brain-dead functions needs them. "brain-dead"? Consider this code, which I think is not atypical. import sys def _read_file(filename): if filename == "-": # Ca

Re: unit test nested functions

2005-07-23 Thread Andrew Dalke
Andy wrote: > How can you unit test nested functions? I can't think of a good way. When I write a nested function it's because the function uses variables from the scope of the function in which it's embedded, which means it makes little sense to test it independent of the larger function. My te

Re: PEP on path module for standard library

2005-07-23 Thread Andrew Dalke
George Sakkis wrote: > That's why phone numbers would be a subset of integers, i.e. not every > integer would correspond to a valid number, but with the exception of > numbers starting with zeros, all valid numbers would be an integers. But it's that exception which violates the LSP. With numbers

Re: PEP on path module for standard library

2005-07-22 Thread Andrew Dalke
George Sakkis wrote: > Bringing up how C models files (or anything else other than primitive types > for that matter) is not a particularly strong argument in a discussion on > OO design ;-) While I have worked with C libraries which had a well-developed OO-like interface, I take your point. Stil

Re: Something that Perl can do that Python can't?

2005-07-22 Thread Andrew Dalke
Dr. Who wrote: > Well, I finally managed to solve it myself by looking at some code. > The solution in Python is a little non-intuitive but this is how to get > it: > > while 1: > line = stdout.readline() > if not line: > break > print 'LINE:', line, > > If anyone can do it th

Re: Iterators from urllib2

2005-07-22 Thread Andrew Dalke
Joshua Ginsberg wrote: > >>> dir(ifs) > ['__doc__', '__init__', '__iter__', '__module__', '__repr__', 'close', > 'fileno', 'fp', 'geturl', 'headers', 'info', 'next', 'read', > 'readline', 'readlines', 'url'] > > Yep. But what about in my code? I modify my code to print dir(ifs) > before cr

Re: Difference between " and '

2005-07-22 Thread Andrew Dalke
François Pinard wrote: > There is no strong reason to use one and avoid the other. Yet, while > representing strings, Python itself has a _preference_ for single > quotes. I use "double quoted strings" in almost all cases because I think it's easier to see than 'single quoted quotes'.

Re: PEP on path module for standard library

2005-07-22 Thread Andrew Dalke
George Sakkis wrote: > You're right, conceptually a path > HAS_A string description, not IS_A string, so from a pure OO point of > view, it should not inherit string. How did you decide it's "has-a" vs. "is-a"? All C calls use a "char *" for filenames and paths, meaning the C model file for the f

Re: PEP on path module for standard library

2005-07-22 Thread Andrew Dalke
Duncan Booth wrote: > Personally I think the concept of a specific path type is a good one, but > subclassing string just cries out to me as the wrong thing to do. I disagree. I've tried using a class which wasn't derived from a basestring and kept running into places where it didn't work well.

Re: PEP on path module for standard library

2005-07-22 Thread Andrew Dalke
Michael Hoffman wrote: > Having path descend from str/unicode is extremely useful since I can > then pass a path object to any function someone else wrote without > having to worry about whether they were checking for basestring. I think > there is a widely used pattern of accepting either a bas

Re: What is different with Python ?

2005-06-15 Thread Andrew Dalke
Terry Hancock wrote: > Of course, since children are vastly better at learning > than adults, perhaps adults are stupid to do this. ;-) Take learning a language. I'm learning Swedish. I'll never have a native accent and 6 year olds know more of the language than I do. But I make much more compl

Re: What is different with Python ?

2005-06-14 Thread Andrew Dalke
> (superstrings may be ? it was a name like that but I > don't really remember). If we had a machine that could reach Planck scale energies then I'm pretty sure there are tests. But we don't, by a long shot. Andrew Dalke -- http://mail.python.org/mailman/listinfo/python-list

Re: What is different with Python ?

2005-06-14 Thread Andrew Dalke
Peter Maas wrote: > Yes, but what did you notice first when you were a child - plants > or molecules? I imagine little Andrew in the kindergarten fascinated > by molecules and suddenly shouting "Hey, we can make plants out of > these little thingies!" ;) One of the first science books that really

Re: What is different with Python ?

2005-06-14 Thread Andrew Dalke
Andreas Kostyrka wrote: > On Tue, Jun 14, 2005 at 12:02:29AM +, Andrea Griffini wrote: >> Caching is indeed very important, and sometimes the difference >> is huge. ... > Easy Question: > You've got 2 programs that are running in parallel. > Without basic knowledge about caches, the naive answ

Re: "also" to balance "else" ?

2005-06-14 Thread Andrew Dalke
Terry Hancock wrote: > No, I know what it should be. It should be "finally". It's already > a keyword, and it has a similar meaning w.r.t. "try". Except that a finally block is executed with normal and exceptional exit, while in this case you would have 'finally' only called when the loop exite

Re: "also" to balance "else" ?

2005-06-14 Thread Andrew Dalke
Ron Adam wrote: > True, but I think this is considerably less clear. The current for-else > is IMHO is reversed to how the else is used in an if statement. As someone else pointed out, that problem could be resolved in some Python variant by using a different name, like "at end". Too late for an

Re: What is different with Python ?

2005-06-13 Thread Andrew Dalke
Andrea Griffini wrote: > This is investigating. Programming is more similar to building > instead (with a very few exceptions). CS is not like physics or > chemistry or biology where you're given a result (the world) > and you're looking for the unknown laws. In programming *we* > are building the

Re: "also" to balance "else" ?

2005-06-13 Thread Andrew Dalke
Ron Adam wrote: > It occurred to me (a few weeks ago while trying to find the best way to > form a if-elif-else block, that on a very general level, an 'also' > statement might be useful. So I was wondering what others would think > of it. > for x in : > BLOCK1 > if : break # do else

Re: What is different with Python ?

2005-06-13 Thread Andrew Dalke
Peter Maas wrote: > I think Peter is right. Proceeding top-down is the natural way of > learning (first learn about plants, then proceed to cells, molecules, > atoms and elementary particles). Why in the world is that way "natural"? I could see how biology could start from molecular biology - how

Re: new string function suggestion

2005-06-13 Thread Andrew Dalke
Andy wrote: > What do people think of this? > > 'prefixed string'.lchop('prefix') == 'ed string' > 'string with suffix'.rchop('suffix') == 'string with ' > 'prefix and suffix.chop('prefix', 'suffix') == ' and ' Your use case is > I get tired of writing stuff like: > > if path.startswith('html/'

Re: Dealing with marketing types...

2005-06-12 Thread Andrew Dalke
Paul Rubin wrote: > Andrew Dalke <[EMAIL PROTECTED]> writes: ... >> I found more details at >> http://jeremy.zawodny.com/blog/archives/001866.html >> >> It's a bunch of things - Perl, C, MySQL-InnoDB, MyISAM, Akamai, >> memcached. The linked

Re: Code documentation tool similar to what Ruby (on Rails?) uses

2005-06-12 Thread Andrew Dalke
Ksenia Marasanova responsded to Michele Simionato >> >>> print "%s" % inspect.getsource(os.makedirs) > > That's easy, thanks! I guess I'll submit a patch for Epydoc with the > functionality I've mentioned :) Before doing that, add a "cgi.escape()" to the text. Otherwise embedded [<>&] characters

Re: ElementTree Namespace Prefixes

2005-06-12 Thread Andrew Dalke
On Sun, 12 Jun 2005 15:06:18 +, Chris Spencer wrote: > Does anyone know how to make ElementTree preserve namespace prefixes in > parsed xml files? See the recent c.l.python thread titled "ElemenTree and namespaces" and started "May 16 2:03pm". One archive is at http://groups-beta.google.co

Re: Dealing with marketing types...

2005-06-11 Thread Andrew Dalke
Paul Rubin replied to me: > If you're running a web site with 100k users (about 1/3 of the size of > Slashdot) that begins to be the range where I'd say LAMP starts > running out of gas. Let me elaborate a bit. That claim of 100K from me is the entire population of people who would use bioinforma

Re: Dealing with marketing types...

2005-06-11 Thread Andrew Dalke
Paul Rubin wrote: > That article makes a lot of bogus claims and is full of hype. LAMP is > a nice way to throw a small site together without much fuss, sort of > like fancy xerox machines are a nice way to print a small-run > publication without much fuss. If you want to do something big, you >

Re: Python Developers Handbook

2005-06-10 Thread Andrew Dalke
Robert Kern wrote: > There is no moderator. We are all moderators. I am Spartacus! We are all Kosh. - Nicolas Bourbaki -- http://mail.python.org/mailman/listinfo/python-list

Re: Is pyton for me?

2005-06-10 Thread Andrew Dalke
Kent Johnson wrote: > Where do you find check_call()? It's not in the docs and I get > >>> import subprocess > >>> subprocess.check_call > Traceback (most recent call last): > File "", line 1, in ? > AttributeError: 'module' object has no attribute 'check_call' > > with Python 2.4.1. Interest

Re: Python Developers Handbook

2005-06-10 Thread Andrew Dalke
wooks wrote: > If I had posted or invited the group to look at my full list of items > rather than just the python book link then I could see where you are > coming from. Take a look at http://www.templetons.com/brad/spamterm.html for some of the first spams and reactions thereof. There's a 30+ y

Re: Is pyton for me?

2005-06-09 Thread Andrew Dalke
Mark de la Fuente wrote: > Here is an example of the type of thing I would like to be able to do. > Can I do this with python? How do I get python to execute command line > functions? ... > # simple script to create multiple sky files. > > foreach hour (10 12 14) > gensky 3 21 $ho

Re: tail -f sys.stdin

2005-06-09 Thread Andrew Dalke
garabik: > what about: > > for line in sys.stdin: > process(line) This does not meet the OP's requirement, which was >> I'd like to write a prog which reads one line at a time on its sys.stdin >> and immediately processes it. >> If there are'nt any new lines wait (block on input). It's a sub

Re: Incorrect number of arguments

2005-06-09 Thread Andrew Dalke
Steven D'Aprano wrote: > *eureka moment* > > I can use introspection on the function directly to see > how many arguments it accepts, instead of actually > calling the function and trapping the exception. For funsies, the function 'can_call' below takes a function 'f' and returns a new function

Re: Fast text display?

2005-06-08 Thread Andrew Dalke
Christopher Subich wrote: > You're off by a decimal, though, an 80-column line > at 20ms is 4kbytes/sec. D'oh! Yeah, I did hundredths of a second instead of thousands. > My guess is that any faster throughput than > 10kbytes/sec is getting amusing for a mud, which in theory intends for > most

Re: Fast text display?

2005-06-08 Thread Andrew Dalke
Christopher Subich wrote: > My first requirement is raw speed; none of what I'm doing is > processing-intensive, so Python itself shouldn't be a problem here. There's raw speed and then there's raw speed. Do you want to display, say, a megacharacter/second? > it's highly desirable to have very

Re: split up a list by condition?

2005-06-07 Thread Andrew Dalke
Reinhold Birkenfeld wrote: >>> So I think: Have I overlooked a function which splits up a sequence >>> into two, based on a condition? Such as >>> >>> vees, cons = split(wlist[::-1], lambda c: c in vocals) > This is clear. I actually wanted to know if there is a function which I > overlooked whic

Re: Creating file of size x

2005-06-06 Thread Andrew Dalke
Jan Danielsson wrote: >Is there any way to create a file with a specified size? Besides the simple def make_empty_file(filename, size): f = open(filename, "wb") f.write("\0" * size) f.close() ? If the file is large, try (after testing and fixing any bugs): def make_empty_file(filenam

Re: the python way?

2005-06-06 Thread Andrew Dalke
Reinhold Birkenfeld wrote: > To make it short, my version is: > > import random > def reinterpolate2(word, vocals='aeiouy'): > wlist = list(word) > random.shuffle(wlist) > vees = [c for c in wlist[::-1] if c in vocals] > cons = [c for c in wlist[::-1] if c not in vocals] Why the [

RE: About size of Unicode string

2005-06-06 Thread Andrew Dalke
Frank Abel Cancio Bello wrote: > Can I get how many bytes have a string object independently of its encoding? > Is the "len" function the right way of get it? No. len(unicode_string) returns the number of characters in the unicode_string. Number of bytes depends on how the unicode character are

Re: Software licenses and releasing Python programs for review

2005-06-06 Thread Andrew Dalke
max: >> For me, the fact >> that corporations are considered people by the law is ridiculous. Steven D'Aprano wrote: > Ridiculous? I don't think so. Take, for example, Acme Inc. Acme purchases > a new factory. Who owns the factory? The CEO? The Chairperson of the Board > of Directors? Split in e

Re: any macro-like construct/technique/trick?

2005-06-05 Thread Andrew Dalke
Mike Meyer wrote: > I've never tried it with python, but the C preprocessor is available > as 'cpp' on most Unix systesm. Using it on languages other than C has > been worthwhile on a few occasions. It would certainly seem to > directly meet the OP's needs. Wouldn't that prohibit using #comments i

Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements

2005-06-04 Thread Andrew Dalke
Steven Bethard wrote: > Ahh, so if I wanted the locking one I would write: > > with locking(mutex) as lock, opening(readfile) as input: > ... That would make sense to me. > There was another proposal that wrote this as: > > with locking(mutex), opening(readfile) as lock, inpu

Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements

2005-06-04 Thread Andrew Dalke
Nicolas Fleury wrote: > I think it is simple and that the implementation is as much > straight-forward. Think about it, it just means that: Okay, I think I understand now. Consider the following server = open_server_connection() with abc(server) with server.lock() do_something(server) server.

Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements

2005-06-04 Thread Andrew Dalke
On Sat, 04 Jun 2005 10:43:48 -0600, Steven Bethard wrote: > Ilpo Nyyssönen wrote: >> How about this instead: >> >> with locking(mutex), opening(readfile) as input: >> ... > I don't like the ambiguity this proposal introduces. What is input > bound to? It would use the same logic as the imp

Re: how to get name of function from within function?

2005-06-03 Thread Andrew Dalke
I'm with Steven Bethard on this; I don't know what you (Christopher J. Bottaro) are trying to do. Based on your example, does the following meet your needs? >>> class Spam(object): ... def funcA(self): ... print "A is called" ... def __getattr__(self, name): ... if name.startswith("_"

Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements

2005-06-03 Thread Andrew Dalke
Nicolas Fleury wrote: > There's no change in order of deletion, it's just about defining the > order of calls to __exit__, and they are exactly the same. BTW, my own understanding of this is proposal is still slight. I realize a bit better that I'm not explaining myself correctly. > As far as I

Re: For review: PEP 343: Anonymous Block Redux and Generator Enhancements

2005-06-03 Thread Andrew Dalke
Nicolas Fleury wrote: > What about making the ':' optional (and end implicitly at end of current > block) to avoid over-indentation? > > def foo(): > with locking(someMutex) > with opening(readFilename) as input > with opening(writeFilename) as output > ... > > would be equiva

RE: Formatting Time

2005-06-03 Thread Andrew Dalke
Coates, Steve (ACHE) wrote: import time t=36100.0 time.strftime('%H:%M:%S',time.gmtime(t)) > '10:01:40' But if t>=24*60*60 then H cycles back to 0 >>> import time >>> t=24*60*60 >>> time.strftime('%H:%M:%S',time.gmtime(t)) '00:00:00' >>> Andrew

Re: provide 3rd party lib or not... philosophical check

2005-06-02 Thread Andrew Dalke
Maurice LING wrote: > Just a philosophical check here. When a program is distributed, is it > more appropriate to provide as much of the required 3rd party libraries, > like SOAPpy, PLY etc etc, in the distribution itself or it is the > installer's onus to get that part done? Depends on who you

Re: Two questions

2005-06-02 Thread Andrew Dalke
Steven D'Aprano wrote: > The existence of one or two or a thousand profitable software packages > out of the millions in existence does not invalidate my skepticism that > some random piece of software will directly make money for the > developer. 'Tis true. I think (but have no numbers to back m

Re: Two questions

2005-06-02 Thread Andrew Dalke
Greg Ewing wrote: > Hmmm... if these are GPL weapons, if you want to fire > them at anyone you'll *have* to make them available to > all other countries as well... not good for > non-proliferation... I think the source code only needs to be sent to the country which receive the weapons. Include a

Re: Formatting Time

2005-06-02 Thread Andrew Dalke
Ognjen Bezanov wrote: > I have a float variable representing seconds, and i want to format it > like this: > > 0:00:00 (h:mm:ss) >>> def format_secs(t): ... m, s = divmod(t, 60) ... h, m = divmod(m, 60) ... return "%d:%02d:%02d" % (h, m, s) ... >>> format_secs(0) '0:00:00' >>> format_sec

Re: Two questions

2005-06-02 Thread Andrew Dalke
Steven D'Aprano wrote: > I can think of a number of reasons why somebody might want to hide their > code. In no particular order: > (3) You have create an incredibly valuable piece of code that will be > worth millions, but only if nobody can see the source code. Yeah right. - id software makes

Re: date and time range checking

2005-06-02 Thread Andrew Dalke
Maksim Kasimov wrote: > there are few of a time periods, for example: > 2005-06-08 12:30 -> 2005-06-10 15:30, > 2005-06-12 12:30 -> 2005-06-14 15:30 > > and there is some date and time value: > 2005-06-11 12:30 > what is the "pythonic" way to check is the date/time value in th

Re: any macro-like construct/technique/trick?

2005-06-01 Thread Andrew Dalke
Mac wrote: > After I wrote my post I realized I didn't provide enough context of > what I'm doing, [explanation followed] I have a similar case in mind. Some graph algorithms work with a handler, which is notified about various possible events: "entered new node", "doing a backtrack", "about to l

Re: any macro-like construct/technique/trick?

2005-06-01 Thread Andrew Dalke
Mac wrote: > Is there a way to mimic the behaviour of C/C++'s preprocessor for > macros? There are no standard or commonly accepted ways of doing that. You could do as Jordan Rastrick suggested and write your own sort of preprocessor, or use an existing one. With the new import hooks you can pro

Re: pickle alternative

2005-06-01 Thread Andrew Dalke
simonwittber wrote: > It would appear that the new version 1 format introduced in Python 2.4 > is much slower than version 0, when using the dumps function. Interesting. Hadn't noticed that change. Is dump(StringIO()) as slow? Andrew

Re: pickle alternative

2005-06-01 Thread Andrew Dalke
simonwittber posted his test code. I tooks the code from the cookbook, called it "sencode" and added these two lines dumps = encode loads = decode I then ran your test code (unchanged except that my newsreader folded the "value = ..." line) and got marshal enc T: 0.21 marshal dec T: 0.4 sencod

Re: pickle alternative

2005-05-31 Thread Andrew Dalke
simonwittber wrote: > marshal can serialize small structures very qucikly, however, using the > below test value: > > value = [r for r in xrange(100)] + > [{1:2,3:4,5:6},{"simon":"wittber"}] > > marshal took 7.90 seconds to serialize it into a 561 length string. > decode took 0.08 seconds

Re: pickle alternative

2005-05-31 Thread Andrew Dalke
simonwittber wrote: >>From the marhal documentation: > Warning: The marshal module is not intended to be secure against > erroneous or maliciously constructed data. Never unmarshal data > received from an untrusted or unauthenticated source. Ahh, I had forgotten that. Though I can't recall what

Re: pickle alternative

2005-05-31 Thread Andrew Dalke
simonwittber wrote: > I've written a simple module which serializes these python types: > > IntType, TupleType, StringType, FloatType, LongType, ListType, DictType For simple data types consider "marshal" as an alternative to "pickle". > It appears to work faster than pickle, however, the decode

Re: Exiting SocketServer: socket.error: (98, 'Address already in use')

2005-05-30 Thread Andrew Dalke
Magnus Lyckå wrote: > Why doesn't my socket > get released by the OS when I exit via my handle_error? Hi Magnus, I wrote about this at http://www.dalkescientific.com/writings/diary/archive/2005/04/21/using_xmlrpc.html The reason for it is described at http://hea-www.harvard.edu/~fine/Tech/ad

Re: searching substrings with interpositions

2005-05-24 Thread Andrew Dalke
Claudio Grondi wrote: > Note: code below is intended to help to clarify things only, > so that a bunch of examples can be tested. > If you need bugfree production quality code, maybe > someone else can provide it. Still not tested enough to ensure that it's bug free, but more concise. Here's one

Re: searching substrings with interpositions

2005-05-24 Thread Andrew Dalke
[EMAIL PROTECTED] wrote: > the next step of my job is to make limits of lenght of interposed > sequences (if someone can help me in this way i'll apreciate a lot) > thanx everyone. Kent Johnson had the right approach, with regular expressions. For a bit of optimization, use non-greedy groups. Tha

Re: performance of Nested for loops

2005-05-20 Thread Andrew Dalke
querypk wrote: > Is there a better way to code nested for loops as far as performance is > concerned. > > what better way can we write to improve the speed. > for example: > N=1 > for i in range(N): >for j in range(N): >do_job1 >for j in range(N): >do_job2 For this cas

Re: Is Python suitable for a huge, enterprise size app?

2005-05-18 Thread Andrew Dalke
Ivan Van Laningham wrote: > ... Oh, it's interpreted, is it? Interesting." You can > see Python going down the sewer pipes, right on their faces. Nahh, the right answer is "It's byte-compiled, just like Java." Andrew [EMAIL PROT

Re: Representing ambiguity in datetime?

2005-05-17 Thread Andrew Dalke
Ron Adam wrote: > This is a very common problem in genealogy research as well as other > sciences that deal with history, such as geology, geography, and archeology. .. > So it seems using 0's for the missing day or month may be how to do it. Except of course humans like to make things more com

Re: ElemenTree and namespaces

2005-05-16 Thread Andrew Dalke
Matthew Thorley wrote: > Does any one know if there a way to force the ElementTree module to > print out name spaces 'correctly' rather than as ns0, ns1 etc? Or is > there at least away to force it to include the correct name spaces in > the output of tostring? See http://online.effbot.org/2004_08

Re: Newbie : checking semantics

2005-05-16 Thread Andrew Dalke
Stefan Nobis wrote: > From time to time I teach some programming (in an institution > called "Volkshochschule" here in Germany -- inexpensive courses > for adults). My Python course is for absolute beginners with no > previous programming experience of any kind. I also taught a beginning programmi

Re: question about the id()

2005-05-16 Thread Andrew Dalke
Peter Dembinski wrote: > So, the interpreter creates new 'point in address space' every time > there is object-dot-method invocation in program? Yes. That's why some code hand-optimizes inner loops by hoisting the bound objection creation, as data = [] data_append = data.append for x in some_oth

Re: Newbie : checking semantics

2005-05-16 Thread Andrew Dalke
Stefan Nobis wrote: > The other point is a missing (optional) statement to end blocks > (so you optional don't have to mark block via whitespace). IMHO > this comes very handy in some cases (like mixing Python and HTML > like in PSP). From my experience i also would say beginners have > quite some

Re: question about the id()

2005-05-16 Thread Andrew Dalke
kyo guan wrote: > Can someone explain why the id() return the same value, and why > these values are changing? Thanks you. a=A() id(a.f) > 11365872 id(a.g) > 11365872 The Python functions f and g, inside of a class A, are unbound methods. When accessed through an instan

Re: Escape spaces in strings

2005-05-12 Thread Andrew Dalke
Florian Lindner wrote: > is there a function to escape spaces and other characters in string for > using them as a argument to unix command? In this case rsync > (http://samba.anu.edu.au/rsync/FAQ.html#10) It's best that you use the subprocess module and completely skip dealing with shell escapes.

Re: Unique Elements in a List

2005-05-12 Thread Andrew Dalke
Scott David Daniels wrote: > Again polynomial, not exponential time. Note that there is no > polynomial time algorithm with (k < 1), since it takes O(n) time > to read the problem. Being a stickler (I develop software after all :) quantum computers can do better than that. For example, Grover's

Re: Python features

2005-05-12 Thread Andrew Dalke
Peter Dembinski wrote: > If you want to redirect me to Google, don't bother. IMO ninety percent > of writings found on WWW is just a garbage. Sturgeon's law: Ninety percent of everything is crap. Andrew [EMAIL PROTECTED] -- http

Re: urllib download insanity

2005-05-12 Thread Andrew Dalke
Timothy Smith wrote: > ok what i am seeing is impossible. > i DELETED the file from my webserver, uploaded the new one. when my app > logs in it checks the file, if it's changed it downloads it. the > impossible part, is that on my pc is downloading the OLD file i've > deleted! if i download it

Re: pyvm -- faster python

2005-05-12 Thread Andrew Dalke
Paul Rubin wrote: > Yes, there are several Python compilers already ... > It's true that CPython doesn't have a compiler and that's a serious > deficiency. A lot of Python language features don't play that well > with compilation, and that's often unnecessary. So I hope the baseline > implem

Re: optparse

2005-05-11 Thread Andrew Dalke
Steven Bethard wrote: > Well one reason might be that it's easy to convert from an object's > attributes to a dict, while it's hard to go the other direction: ... > py> options['x'], options['y'] > ('spam', 42) > py> o = ??? # convert to object??? > ... > py> o.x, o.y > ('spam', 42) "hard" == "

RE: Need a little parse help

2005-05-11 Thread Andrew Dalke
Delaney, Timothy C (Timothy) wrote: > Remember, finalisers are not called when Python exits. So if you don't > explicitly close the file you are *writing* to, it may not be flushed > before being closed (by the OS because the process no longer exists). Wrong. % python Python 2.3 (#1, Sep 13 2003,

Re: lists in cx_Oracle

2005-05-10 Thread Andrew Dalke
Daniel Dittmar wrote: > Possible workarounds: ... > - create a class for this purpose. Statement are created on the fly, but > with placeholders so you don't run into the SQL Injection problem. As > it's an object, you could cache these generated statements base on the > size of the list > It

Re: A Faster Way...

2005-05-10 Thread Andrew Dalke
andrea.gavana wrote: > If I simplify the problem, suppose I have 2 lists like: > > a = range(10) > b = range(20,30) > > What I would like to have, is a "union" of the 2 list in a single tuple. In > other words (Python words...): > > c = (0, 20, 1, 21, 2, 22, 3, 23, 4, 24, 5, 25, . The 'yiel

Re: control precision for str(obj) output?

2005-05-03 Thread Andrew Dalke
Mike Meyer wrote: > Someone want to tell me the procedure for submitting FAQ entries, so I > can do that for this? You mean more than what already exists at http://www.python.org/doc/faq/general.html#why-are-floating-point-calculations-so-inaccurate which has a link to an even more detailed ch

Re: lists in cx_Oracle

2005-05-02 Thread Andrew Dalke
Steve Holden wrote: > Do you think this is a DB-API 3-ish kind of a thing, or would it layer > over DB-API 2 in a relatively platform-independent manner? ... > but-you-may-know-better-ly y'rs - steve I am a tyro at this. I had to find some tutorials on SQL to learn there even was an IN cla

Re: lists in cx_Oracle

2005-05-02 Thread Andrew Dalke
infidel wrote: > I think perhaps you are asking for something that the OCI doesn't > provide. But it doesn't need to be supported by the OCI. > And really, it all boils down to the list comprehension: > > in_clause = ', '.join([':id%d' % x for x in xrange(len(ids))]) And why can't the equivalen

Re: lists in cx_Oracle

2005-05-02 Thread Andrew Dalke
infidel wrote: > Something like this might work for you: > ids= ['D102', 'D103', 'D107', 'D108'] in_clause = ', '.join([':id%d' % x for x in xrange(len(ids))]) sql = "select * from tablename where id in (%s)" % in_clause import cx_Oracle as ora con = ora.connect('foo/[EMA

  1   2   >