Re: is there a better way?

2006-02-11 Thread Alex Martelli
Charles Krug [EMAIL PROTECTED] wrote: On 2006-02-11, Alex Martelli [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's

Re: appending to a list via properties

2006-02-11 Thread Alex Martelli
Carl Banks [EMAIL PROTECTED] wrote: ... class better_list (list): tail = property(None, list.append) This is an impressive, spiffy little class. Yes, nice use of property. growing_lists = foo,qux while some_condition: for (s,x) in

Re: PySizeof: almost useful

2006-02-11 Thread Alex Martelli
Ian Leitch [EMAIL PROTECTED] wrote: ... 2. I'm at a loss as how to calculate the size of a long object -- any tips? #include longintrepr.h (from the Python sources). Then, given a PyLongObject *l, abs(l-ob_size) is the number of digits, each taking SHIFT bits. Many thanks to anyone bored

Re: ordered sets operations on lists..

2006-02-11 Thread Alex Martelli
Raymond Hettinger [EMAIL PROTECTED] wrote: ... The intersection step is unnecessary, so the answer can be simplified a bit: filter(set(l2).__contains__, l1) [5, 3] filter(set(l1).__contains__, l2) [3, 5] ...and if one has time to waste, setification being only an optimization, it can

Re: python 2.5 and hashlib

2006-02-11 Thread Alex Martelli
rtilley [EMAIL PROTECTED] wrote: Is there a road map for python a 2.5 releases yet? I'd like to begin testing the new hashlib module with some old scripts I have that currently use the md5 and sha modules. http://python.org/peps/pep-0356.html -- but it's still a draft, being discussed in

Re: appending to a list via properties

2006-02-11 Thread Alex Martelli
Xavier Morel [EMAIL PROTECTED] wrote: Alex Martelli wrote: Carl Banks [EMAIL PROTECTED] wrote: ... class better_list (list): tail = property(None, list.append) This is an impressive, spiffy little class. Yes, nice use of property. Alex I don't know, I

Re: Scientific Computing with NumPy

2006-02-10 Thread Alex Martelli
David M. Cooke [EMAIL PROTECTED] wrote: linda.s [EMAIL PROTECTED] writes: where to download numpy for Python 2.3 in Mac? Thanks! Linda I don't know if anybody's specifically compiled for 2.3; I think most of the developers on mac are using 2.4 :-) However, what comes with MacOSX is

Re: is there a better way?

2006-02-10 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Problem: You have a list of unknown length, such as this: list = [X,X,X,O,O,O,O]. You want to extract all and only the X's. You know the X's are all up front and you know that the item after the last X is an O, or that the list ends with an X.

Re: Is Python good for web crawlers?

2006-02-09 Thread Alex Martelli
John J. Lee [EMAIL PROTECTED] wrote: ... I wonder if that little outfit has considered open-sourcing any of their web client code? What they've open-sourced so far is listed at http://code.google.com/projects.html -- of these, the only crawl/spider is Könguló, so far. Alex --

Re: Question about idioms for clearing a list

2006-02-09 Thread Alex Martelli
Bryan Olson [EMAIL PROTECTED] wrote: ... I agree that emptying is logically the same thing for all of these types. Beyond that, they don't seem to have a lot in common. It's ... Do you really have a usecase for this? It seems to me that your argument is pretty hollow. Sure:

Re: Undergraduate project :: python ToDo list

2006-02-08 Thread Alex Martelli
Joao Macaiba [EMAIL PROTECTED] wrote: Hi. I would like to know if there's any todo list on python project. My interest in doing a undergraduate project. It could be anything in the python core interpreter. I program C/C++. The PEP index shows several PEPs approved but not implemented

Re: Python threading, and processes

2006-02-08 Thread Alex Martelli
Robin Haswell [EMAIL PROTECTED] wrote: ... Cheers for that info. The thread's main tasks are getting webpages (spidering), the actual amount of processing done in each thread is minimal - that's why I'm confused by the CPU usage. BTW, spidering is a great use case for async (even-driven)

Re: Is Python good for web crawlers?

2006-02-08 Thread Alex Martelli
that. Goo...can't remember. See http://www-db.stanford.edu/~backrub/google.html Yeah, I've heard of them, too. They've also employed some clever Python programmers, such as Greg Stein, Alex Martelli (isn't he a bot?) and some obscure dutch mathematician called Guido van something. It seems

Re: Detecting line endings

2006-02-07 Thread Alex Martelli
Fuzzyman [EMAIL PROTECTED] wrote: ... Open the file with 'rU' mode, and check the file object's newline attribute. Do you know if this works for multi-byte encodings ? Do files have You mean when you open them with the codecs module? metadata associated with them showing the

Re: The problem of anonymity with decorators

2006-02-07 Thread Alex Martelli
Franck Pommereau [EMAIL PROTECTED] wrote: ... import new def rename (fun, name) : return new.function(fun.func_code, {}, name) You need to make a new code object too: def int_result(fun) : def wrapped(*largs, **kwargs) : result = fun(*largs, **kwargs) if

Re: Detecting line endings

2006-02-07 Thread Alex Martelli
Fuzzyman [EMAIL PROTECTED] wrote: ... I can't open with a codec unless an encoding is explicitly supplied. I still want to detect UTF16 even if the encoding isn't specified. As I said, I ought to test this... Without metadata I wonder how Python determines it ? It doesn't. Python

Re: how to copy a Python object

2006-02-07 Thread Alex Martelli
Schüle Daniel [EMAIL PROTECTED] wrote: ... class X(object): ... def __init__(self,lst): ... self.lst = lst ... def copy(self): ... return X(self.lst[:]) ... def __str__(self): ... return lst has id %i % id(self.lst) ... ... anyone?

Re: Detecting line endings

2006-02-06 Thread Alex Martelli
Fuzzyman [EMAIL PROTECTED] wrote: Hello all, I'm trying to detect line endings used in text files. I *might* be decoding the files into unicode first (which may be encoded using Open the file with 'rU' mode, and check the file object's newline attribute. My worry is that if '\n' *doesn't*

Re: numeric expression from string?

2006-02-06 Thread Alex Martelli
Brian Blais [EMAIL PROTECTED] wrote: someone might accidentally do damage to their system with an unchecked eval. Nah, it takes malice and deliberation to damage a system from an eval. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Learning Python

2006-02-05 Thread Alex Martelli
Byte [EMAIL PROTECTED] wrote: http://docs.python.org/tut/node6.html#SECTION00610 I think you're confusing the tutorial's use of: int(raw_input(... which means get a string from the user and turn it into an integer (a very common idiom), with your use of:

Re: Learning Python

2006-02-05 Thread Alex Martelli
Byte [EMAIL PROTECTED] wrote: Thanks, never knew that, but they are using raw_input as a stack, aren't they? No. raw_input is a function object, using it as a stack is a rather meaningless phrase. You can use a list as a stack, but that's totally and absolutely unrelated to that spot in the

Re: Get System Date?

2006-02-05 Thread Alex Martelli
Dustan [EMAIL PROTECTED] wrote: Is it possible to get the system date on a Windows XP machine? Most Convenient would to retrieve , MM, and DD as seperate variables. When I say system date, I'm thinking of the small clock in the lower-right hand corner, which has date as well as time,

Re: Reverse of map()?

2006-02-05 Thread Alex Martelli
Phillip Sitbon [EMAIL PROTECTED] wrote: Hello there, I have a situation where a list of functions need to be called with a single set of parameters and the result constructed into a tuple. I know there's simple ways to do it via list comprehension: Result = tuple( [ fn(* Args, ** Kwds)

Re: Newbie Help!

2006-02-05 Thread Alex Martelli
Stephen [EMAIL PROTECTED] wrote: Hi All, im new to python i just have a few questions and was wondering if you could help me?? 1. what programming langaugue does python use? or which is most popular? Python _is_ a programming language, so your question is not clear. If you're

Re: Importing a class, please help...

2006-02-05 Thread Alex Martelli
anon [EMAIL PROTECTED] wrote: Xavier Yes I meant Python. I have also been using Jython and I am VERY WELL aware what a JAR is. Jython has the ability to call methods stored in classes in a JAR. I was only asking if this could be done with Python also. Classic Python is able to import

Re: Literal Escaped Octets

2006-02-05 Thread Alex Martelli
Chason Hayes [EMAIL PROTECTED] wrote: ... easily in c/c++ but I need to do it in python. I am not sure how to read and evaluate the binary value of a byte in a long string when it is a non printable ascii value in python. If you have a bytestring (AKA plain string) s, the binary value of

Re: OO conventions

2006-02-04 Thread Alex Martelli
Daniel Nogradi [EMAIL PROTECTED] wrote: ... So after all, what is a 'factory' or 'factory function'? A brief explanation in Python terms is at http://www.aleax.it/ep03_pydp.pdf -- pages (slides) 37-44 (the rest of the presentation is about an even more fundamental design pattern, template

Re: OO conventions

2006-02-04 Thread Alex Martelli
Blair P. Houghton [EMAIL PROTECTED] wrote: ... It is (search for 'staticmethod' and 'classmethod'). But there's not much use for 'static methods' in Python - we usually just use plain functions ('classmethods' are another beast - much more useful than staticmethods) Does it make any

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
Magnus Lycka [EMAIL PROTECTED] wrote: ... which isn't needed at all. So far, the existence of x.y somewhere in Python always implied that x was already introduced explicitly in the program, and you suggest that we violate that both in the Almost... import (and from) statements are

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: ... Why shouldn't def self.x(): declare two new identifiers (x and self), too? Sure, but now the call foo.bar call? has special meaning inside a def statement than elsewhere. Elsewhere, foo.bar is an attribute access, looking up attribute

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: ... would be. Token? Too specific. Maybe it would have been better to just have just said ...but now foo.bar has Agreed. model I have is y is a label in some namespace x, and you have to (in some sense) look up where y should go regardless of

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... your idea. Could you summarize how exactly f(x,y=z) should be resolved, i.e. where it should look for f? Lexically: local scope, outer functions outwards, globals, builtins. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Another try at Python's selfishness

2006-02-03 Thread Alex Martelli
Terry Reedy [EMAIL PROTECTED] wrote: ... As was once pointed out to me some years ago, when I wrote something similar, a.f() is not just a shortcut for A.f(a) [a.__class__.f(a)]. The latter only looks for f in the class A namespace while the former also looks in superclass namespaces.

Re: OO conventions

2006-02-02 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: image = Image( ) Now you have an image object. What is it? Answer: it isn't an image at all, not in the plain English sense. (Or if it is, it is an arbitrary default image picked by the class designer.) No doubt (presumably some kind of as-yet

Re: How do I dynamically create functions without lambda?

2006-02-02 Thread Alex Martelli
Alan Morgan [EMAIL PROTECTED] wrote: ... Since there are a lot more stupid people than clever people out there I think the more likely scenario is having to maintain unmaintainable code written by a complete idiot whose programming knowledge comes solely from books whose titles end with

Re: How do I dynamically create functions without lambda?

2006-02-02 Thread Alex Martelli
Benji York [EMAIL PROTECTED] wrote: Alex Martelli wrote: Disagree -- far more people THINK they're clever, than really ARE clever. According to a recent article in the Financial Times, over 40% of a typical financial firm's employees firmly believe they are among the 5% best employees

Re: locals() and dictionaries

2006-02-01 Thread Alex Martelli
JerryB [EMAIL PROTECTED] wrote: ... is it possible to access the individual members of a dictionary using % locals() when creating a string? Not by using the built-in locals(); you'd have to override locals to mean someting different (not recommended). Alex --

Re: How do I dynamically create functions without lambda?

2006-02-01 Thread Alex Martelli
Alan Morgan [EMAIL PROTECTED] wrote: ... Excessive cleverness can lead to unmaintainable code. So can excessive stupidity. +1 QOTW. Since there are a lot more stupid people than clever people out there I think the more likely scenario is having to maintain unmaintainable code written by

Re: nDimensional sparse histogram in python.

2006-02-01 Thread Alex Martelli
KraftDiner [EMAIL PROTECTED] wrote: ... histo = {[0,0,0]:1, [0,0,1]:2} Would indicate that there is one sample at 0,0,0 and two samples at 0,0,1 but python tells me TypeError: list objects are unhashable So any suggestions would be welcome. Use tuples, not lists, as your keys: histo =

Re: nDimensional sparse histogram in python.

2006-02-01 Thread Alex Martelli
KraftDiner [EMAIL PROTECTED] wrote: Cool. Ok so my histogram class had two methods 1) To increment a point and 2) to get the point. def class histo: def __init__(self): histo = {} def update(point): '''searches the dictionary for point and if it exists increment the value.

Re: nDimensional sparse histogram in python.

2006-02-01 Thread Alex Martelli
KraftDiner [EMAIL PROTECTED] wrote: Many thanks everyone. One last quick question... The dictionary, I believe, is sorted by the key. Dictionaries are NOT sorted -- they're hashtables. Is there a way to sort it by the value? Say I wanted to put out a list of the frequency sorted by

Re: instance references?

2006-01-30 Thread Alex Martelli
Scott David Daniels [EMAIL PROTECTED] wrote: Alex Martelli wrote: My favourite way to use weakref is slightly different: I would have aptbase.drawables = weakref.WeakValueDictionary typo here: aptbase.drawables = weakref.WeakValueDictionary() then in each __init__

Re: about spawn flag

2006-01-30 Thread Alex Martelli
Sinan Nalkaya [EMAIL PROTECTED] wrote: hi, i am using os.spawn function, it works well but i need a flag that allows function return the process id with exit/error code, is there any or how can i do it, i can replace spawn with fork/exec if necessary. os.P_WAIT waits until the spawned

Re: Using non-ascii symbols

2006-01-30 Thread Alex Martelli
Dave Hansen [EMAIL PROTECTED] wrote: On Fri, 27 Jan 2006 20:27:40 -0500 in comp.lang.python, Dan Sommers [EMAIL PROTECTED] wrote: On Fri, 27 Jan 2006 22:29:20 GMT, Neil Hodgson [EMAIL PROTECTED] wrote: ... I'm so used to / for division that ÷ now looks strange. Indeed, I don't think

Re: Python vs C for a mail server

2006-01-29 Thread Alex Martelli
Jens Theisen [EMAIL PROTECTED] wrote: ... Indeed, especially Eckels article shed some light about testing as an alternative to static typing. I still can't quite understand why you can't do both. Clearly unit tests should be part of any software, not only Python software. Clearly. Given

Re: Python vs C for a mail server

2006-01-29 Thread Alex Martelli
Jay Parlar [EMAIL PROTECTED] wrote: ... Because in all of my own industry experience, it's been MUCH easier to jump into someone else's Python code than someone else's C++ code (and at my last job, I had to do a lot of both). I find Python to be much more self-documenting, because there's

Re: Hostname

2006-01-29 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi Iam new in Python. I want to know for my first Project in Python how i can get the Hostname from a URL? import urlparse urlparse.urlsplit('http://foo.bar.com/zapzap') ('http', 'foo.bar.com', '/zapzap', '', '') As you may notice, the hostname

Re: Hostname

2006-01-29 Thread Alex Martelli
[EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Wow! This was a fast answer and it works. That's why we used to joke about Guido's time machine: somebody would express a need (sometimes phrased as a suggestion for an enhancement), and Guido would zip back in time and implement the needed

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... temp_buf = StringIO() for x in various_pieces_of_output(): v = go_figure_out_some_string() temp_buf += v final_string = temp_buf.getvalue() here, temp_buf += v is supposed to be the same as temp_buf.write(v). So the

Re: Returning a value from code string

2006-01-29 Thread Alex Martelli
Fried Egg [EMAIL PROTECTED] wrote: ... Why does anyone care about why people do things when they ask a specific technical question on a newsgroup? Maybe op is risking his Because experienced techies have learned that people (including other techies) often ask the wrong specific technical

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... In StringIO's case, it's nice to be able to use the above idiom to concatenate Unicode strings just as easily as plain ones, for example -- cStringIO (like file objects) wants plain bytestrings. I wasn't aware of that limitation--maybe

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: But why can't I have perfectly polymorphic append a bunch of strings together, just like I can now (with ''.join of a list of strings, or StringIO), without caring whether the strings are Unicode

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Scott David Daniels [EMAIL PROTECTED] wrote: Alex Martelli wrote: It would be nice (in Py3k, when backwards compatibility can be broken) to make the plain-named, default modules those coded in C, since they're used more often, and find another convention to indicate pure Python

Re: Python vs C for a mail server

2006-01-29 Thread Alex Martelli
Jay Parlar [EMAIL PROTECTED] wrote: ... From Lib/compiler/visitor.py: meth = getattr(self.visitor, 'visit' + className, 0) ... I even said you can do some very powerful things with getattr, by which I meant something exactly like you did. What did you think I meant by that?

Re: Language Semantics: @ symbol??

2006-01-29 Thread Alex Martelli
Enigma Curry [EMAIL PROTECTED] wrote: ... @somefunction() def a_newfunction(): What does it mean and what does it do? It means and does exactly the same thing as having a_newfunction = somefunction()(a_newfunction) right after the end of a_newfunction's body.

Re: instance references?

2006-01-29 Thread Alex Martelli
bytecolor [EMAIL PROTECTED] wrote: ... So how can I tell if an instance of point, line or circle has actually been assigned to a variable? You can't really distinguish whether an object has been assigned to a variable, an item in a list, an attribute, etc etc -- all of these assignments are

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... ''.join with a list (rather than a generator) arg may be plain worse than python StringIO. Imagine building up a megabyte string one character at a time, which means making a million-element list and a million temporary one-character strings

Re: Storing lines from a text file

2006-01-29 Thread Alex Martelli
[EMAIL PROTECTED] wrote: I keep getting an error when I try to use what you said Mr. McDonald. I think I've got something wrong, but take a look if you can. log = open('C:\log_0.txt') lines = log.getlines() for line in lines: print line When I debug it the error I get is the

Re: Python vs C for a mail server

2006-01-29 Thread Alex Martelli
Paul Boddie [EMAIL PROTECTED] wrote: ... The context was whether you can know before running the program whether the function you're attempting to call exists, along with where it is defined. Obviously, it's a struggle to think of cases where one would do this for the sake of it (especially

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... Absolutely wrong: ''.join takes less for a million items than StringIO takes for 100,000. That depends on how much ram you have. You could try a billion items. Let's see you try it -- I have better things to do than to trash around

Re: Concerning Regular Expressions

2006-01-29 Thread Alex Martelli
Tempo [EMAIL PROTECTED] wrote: I've been reading a bunch of articles and tutorials on the net, but I cannot quite get ahold of the whole regular expression process. I have a list that contains about thirty strings, each in its own spot in the list. What I want to do is search the list, say

Re: instance references?

2006-01-29 Thread Alex Martelli
bytecolor [EMAIL PROTECTED] wrote: Thanks Alex, the weak references *seem* to be doing what I want for now. In each __init__() I use: aptbase.drawables.append(weakref.ref(self)) Then in show(): for d in aptbase.drawables: o = d() if o is not None: # render it Looks

Re: Python loading library containing embedded python...

2006-01-29 Thread Alex Martelli
Brennus [EMAIL PROTECTED] wrote: ... I have solved my problem, or at least part of it by downgrading to Visual Studio 2003. For whatever reason, the same steps applied to Visual Studio 2005 result in massive problems. Even the python.exe compiled by VS 2005 throws A/Vs on startup. I

Re: A class with eventhandlers ?

2006-01-29 Thread Alex Martelli
Runsun Pan [EMAIL PROTECTED] wrote: ... or, more specific, a function/method-specific error handling feature: c.load.onError( IOErrorHook) c.load( filename ) Is there such a mechnism around? If not, is it possible to make such a thing ? Never heard of one, but you could surely make a

Re: Sql Parser

2006-01-29 Thread Alex Martelli
Sergey Eizner [EMAIL PROTECTED] wrote: Does anybody know python module for sql parsing? http://gadfly.sourceforge.net/gadfly.html has one. Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Concerning Regular Expressions

2006-01-29 Thread Alex Martelli
Tempo [EMAIL PROTECTED] wrote: You are right that my move towards regular expressions was way premature, but also this post may too turn out to be a little premature. I guessed and checked myself a way to accomplish what I needed and I will include it in this post. But first Alex (doesn't

Re: Python vs C for a mail server

2006-01-29 Thread Alex Martelli
Donn Cave [EMAIL PROTECTED] wrote: Quoth [EMAIL PROTECTED] (Alex Martelli): | ... Therefore, | if the inability to verify that a function named 'foobar' is in fact | never called anywhere is a weakness, it's a weakness shared by all of | these languages. The originator of this thread

Re: StringIO proposal: add __iadd__

2006-01-29 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: And is making += a synonym for write() on other file objects really that bad an idea? It would be like C++'s use of for file objects and could make some code nicer if you like that kind of thing. Not really: 's point is to allow chaining, fabc. +=

Re: python success story

2006-01-29 Thread Alex Martelli
Max M. Stalnaker [EMAIL PROTECTED] wrote: I urged a friend from Boeing to use python on a personal project. He liked it and repeatedly urged a Boeing developer to use it. Python is on the list of approved languages at Boeing. The developer wrote a thousand line enterprise level program in

Re: Python vs C for a mail server

2006-01-28 Thread Alex Martelli
Jens Theisen [EMAIL PROTECTED] wrote: ... Please don't be offended, but if anyone could make a point of how Python's disadvantages in these regards could be alleviated, I'd be very interested. http://www.artima.com/weblogs/viewpost.jsp?thread=4639 http://www.mindview.net/WebLog/log-0025

Re: User login system

2006-01-28 Thread Alex Martelli
Jorge Godoy [EMAIL PROTECTED] wrote: sophie_newbie [EMAIL PROTECTED] writes: Can anyone recommend an open source user login system already written in Python that I could use with my site? Simplicity is the most important factor, but the ability to track users using cookies would be

Re: Builder Pattern

2006-01-28 Thread Alex Martelli
Jason [EMAIL PROTECTED] wrote: Hi I really need an example of a builder pattern in python, the closest I could find to something resembling builder was on this thread... http://groups.google.co.uk/group/it.comp.lang.python/browse_thread/threa

Re: Nitpicking - slightly misleading traceback

2006-01-26 Thread Alex Martelli
Sybren Stuvel [EMAIL PROTECTED] wrote: ... if data[x][y] 0 or datadict.has_key(key): This might even make things fit on one line again ;-) Particularly if you code it idiomatically: if data[x][y] 0 or key in datadict: Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Assigning to self.__class__

2006-01-26 Thread Alex Martelli
Heiko Wundram [EMAIL PROTECTED] wrote: bruno at modulix wrote: Paul McGuire wrote: or am I taking advantage of a fortuitous accident, which may get undone at a future time? It's certainly not a fortuitous accident. And even the (printed) cookbook has examples which assign to

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Tim Chase [EMAIL PROTECTED] wrote: ... I'm not quite sure what your intent here is, as the resulting find would obviously be aaa, of length 3. But that would also match ''; I think he wants negative loobehind and lookahead assertions around the 'aaa' part. But then there's the spec

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Tim Chase [EMAIL PROTECTED] wrote: Sorry for the confusion. The correct pattern should reject all strings except those in which the first sequence of the letter 'a' that is followed by the letter 'b' has a length of exactly three. Ah...a little more clear. r =

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Christoph Conrad [EMAIL PROTECTED] wrote: Hello Roger, since the length of the first sequence of the letter 'a' is 2. Yours accepts it, right? Yes, i misunderstood your requirements. So it must be modified essentially to that what Tim Chase wrote: m = re.search('^[^a]*a{3}b',

Re: Match First Sequence in Regular Expression?

2006-01-26 Thread Alex Martelli
Christoph Conrad [EMAIL PROTECTED] wrote: Hallo Alex, r = re.compile([^a]*a{3}b+(a+b*)*) matches = [s for s in listOfStringsToTest if r.match(s)] Unfortunately, the OP's spec is even more complex than this, if we are to take to the letter what you just quoted; e.g. aazaaab SHOULD

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Alex Martelli
Tim Chase [EMAIL PROTECTED] wrote: ... To get the item, i had to resort to methods that feel less than the elegance I've come to expect from python: item = [x for x in s][0] A shorter, clearer expression of the same idea: item = list(s)[0] or item = list(s).pop() or the more

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Alex Martelli
Fredrik Lundh [EMAIL PROTECTED] wrote: ... the obvious solution is item = list(s)[0] but that seems to be nearly twice as slow as [x for x in s][0] under 2.4. hmm. Funny, and true on my laptop too: helen:~ alex$ python -mtimeit -s's=set([23])' 'x=list(s)[0]' 10 loops, best

Re: Best way to extract an item from a set of len 1

2006-01-25 Thread Alex Martelli
Rene Pijlman [EMAIL PROTECTED] wrote: Peter Otten: s = set([one-and-only]) item, = s ... The comma may easily be missed, though. You could write: (item,) = s But I'm not sure if this introduces additional overhead. Naah...: helen:~ alex$ python -mtimeit -s's=set([23])'

Re: Loop exception catching

2006-01-24 Thread Alex Martelli
Aldo Cortesi [EMAIL PROTECTED] wrote: ... this means that your pet cat could make your script exit due to an uncaught exception by simply walking accross your keyboard. If your cat is sufficiently clever, it could also empty your bank account, email your entire porn collection to your

Re: Loop exception catching

2006-01-24 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: [EMAIL PROTECTED] (Alex Martelli) writes: I thought I knew some pretty evil cats, but I see my experience with felines was nothing compared to yours! Catbert? He'd sure empty your bank account and hard drive, but even he wouldn't send your porn

Re: new.instancemethod as a form of partial()

2006-01-22 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... thanks. So in this special case, None is being treated as a flag rather than just an instance(I just read the doc) like any other instance and the behaviour is intended. Is there any reason why it is designed this way ? I didn't yet know Python back when it was

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Kay Schluehr [EMAIL PROTECTED] wrote: ... range(3)**2 [(0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2)] ... But why isn't this interpreted as [0, 1, 4] like it is in Mathematica? Since range(3)*2 is [0, 1, 2, 0, 1, 2], it would be horribly, painfully inconsistent if **2

Re: Catching very specific exceptions

2006-01-22 Thread Alex Martelli
Harlin Seritt [EMAIL PROTECTED] wrote: except socket.error: code goes here... Of course, though, these are two separate error messages under the same error handler though. I've tried: except socket.error, (10061, 'Connection refused'): and except (socket.error, 10061, 'Connection

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: ... given length. You could get a 6/49 lotto tip with something like: choice(set(range(49)).powerset(6)) And that would be better than the current random.sample(range(49),6) in WHAT ways, exactly...? Alex --

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: ... What advantage is there to creating a list with cartesian product subclass of list? Essentially, syntax sugar -- for some people, being able to code a*b rather than product(a,b) takes on a huge significance; Python chooses to support this syntax

Re: Some thougts on cartesian products

2006-01-22 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: Alex Martelli schrieb: Christoph Zwerschke [EMAIL PROTECTED] wrote: ... given length. You could get a 6/49 lotto tip with something like: choice(set(range(49)).powerset(6)) And that would be better than the current random.sample(range

Re: Arithmetic sequences in Python

2006-01-22 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: Steve Holden [EMAIL PROTECTED] writes: The current list function is supposed to be something like a typecast: list() isn't a function, it's a type. I'm not sure what the distinction is supposed to be. list is anyway You can subclass a

Re: Arithmetic sequences in Python

2006-01-22 Thread Alex Martelli
Christoph Zwerschke [EMAIL PROTECTED] wrote: ... These are valid points, but they lead me to the opposite conclusion: Why not let {a,b,c} stand for set([a,b,c])? That would be very intuitive As syntax sugar goes, that would be on a par with the current dict display notation, at least.

Re: Dynamic website content

2006-01-21 Thread Alex Martelli
Christoph Haas [EMAIL PROTECTED] wrote: On Saturday 21 January 2006 20:42, sophie_newbie wrote: To give you a better explaination of what I want, you could visit www.pat2pdf.org. Type in 123456 as the patent number, you see what it does? It tells the user that it is requesting the

Re: new.instancemethod as a form of partial()

2006-01-21 Thread Alex Martelli
[EMAIL PROTECTED] wrote: ... So it seems that instancemethod() don't like None as the instance. bound methods and unbound methods are instance of the same type, distinguished by one thing: the im_self of an unbound method is None, the im_self of a bound method is anything else. So, when you

Re: OT: excellent book on information theory

2006-01-18 Thread Alex Martelli
Rocco Moretti [EMAIL PROTECTED] wrote: Alex Martelli wrote: Terry Hancock [EMAIL PROTECTED] wrote: ... due to the Evil Conspiracy of region-coding, I couldn't watch the British DVD even if I were to import it (Well, yeah I could, but it would be painful, and probably illegal, I

Re: Arithmetic sequences in Python

2006-01-18 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... Well, [...] notation for regular lists (as opposed to list comprehensions) is also unnecessary since we could use list((a,b,c)). Indeed, there's no reason list couldn't accept multiple arguments as an alternative to one sequence argument, just

Re: OT: excellent book on information theory

2006-01-18 Thread Alex Martelli
Terry Hancock [EMAIL PROTECTED] wrote: ... Nothing at all. But I still prefer tales of people who have hacked their DVD players to be multi-region :-) It isn't illegal in Canada anyway. And yes, it would be possible for me to pay a very high price to get a region-free player in the

Re: Arithmetic sequences in Python

2006-01-18 Thread Alex Martelli
Paul Rubin http://[EMAIL PROTECTED] wrote: ... What should the output of print list(1,2,3) be? Is there a really good reason to make it different from the input syntax? If we assume that str and repr must keep coinciding for lists (and why not), no reason -- just like, say, today: print

Re: OT: excellent book on information theory

2006-01-18 Thread Alex Martelli
Steven D'Aprano [EMAIL PROTECTED] wrote: ... I mean, when you read He sat on the chair do you need to look up the dictionary to discover that chairs can have arm rests or not, they can be made of wood or steel or uphostered springs, be on legs or coasters, fixed or movable? If it

Re: web crawling.

2006-01-18 Thread Alex Martelli
S Borg [EMAIL PROTECTED] wrote: Hello, I have been writing very simple Python programs that parse HTML and such, mainly just to get a better feel for the language. Here is my question: If I parsed an HTML page into all of the image files listed on that page, how could I request all of

Re: OT: excellent book on information theory

2006-01-17 Thread Alex Martelli
Terry Hancock [EMAIL PROTECTED] wrote: ... due to the Evil Conspiracy of region-coding, I couldn't watch the British DVD even if I were to import it (Well, yeah I could, but it would be painful, and probably illegal, I have a region-free DVD player here in CA -- considering that I brought

<    5   6   7   8   9   10   11   12   13   14   >