Re: Python version(s) for new project?

2009-03-26 Thread andrew cooke
Philip Semanchuk wrote: > Hi all, > I'm about to start a new job at which I and others will build a > project largely in Python. I'm trying to figure out which Python > versions to use and support. I can't use Python 3.x, but I want to > prepare for it even if it is a long way off yet. > > My idea

Re: Python version(s) for new project?

2009-03-26 Thread andrew cooke
Philip Semanchuk wrote: > [...]. I just want to > leverage the -3 switch on Python 2.6 to keep an eye on how many 3.x- > incompatible features I'm using. Some will be unavoidable -- print > versus print() comes to mind -- but ideally when the time comes to > support 3.x, we can just run 2to3 and be

Re: Introducing Python to others

2009-03-26 Thread andrew cooke
David C. Ullrich wrote: > In article , > "Paddy O'Loughlin" wrote: > > Here's my favorite thing about Python (you'd of course > remark that it's just a toy example, doing everything > in as dumb but easily understood way as possible): > > x=[1,2] > > print x+x > > class Vector(): > def __init__

Re: Puzzling: local variable in recursive function made global?

2009-03-26 Thread andrew cooke
it's not global, it's mutable. you are passing THE SAME FRICKING OBJECT to is_terminal and appending values to it. instead, make a new copy: branch.next.is_terminal(list(seen_nodes)) sorry for the shouting, but someone asks this EVERY DAY AND I CAN'T TAKE ANY MORE. andrew Daniel Oberski

Re: Puzzling: local variable in recursive function made global?

2009-03-26 Thread andrew cooke
Diez B. Roggisch wrote: > That's not a local variable, that is a default argument. Which is in > fact only created once for each function, yes. > > http://effbot.org/pyfaq/why-are-default-values-shared-between-objects.htm a nice way of handling this was posted here just yesterday, which isn't in t

Re: Puzzling: local variable in recursive function made global?

2009-03-26 Thread andrew cooke
Peter Otten wrote: > I would be surprised by the behaviour of Andrew's variant: > def append(item, items=None): > ... items = items or [] > ... items.append(item) > ... return items > ... a = [] append("x", a) > ['x'] ah that's a good point. andrew -- http://mail.

Re: Code anntotations (copyright, autor, etc) in your code

2009-03-26 Thread andrew cooke
mattia wrote: > Hi all, which are the usual comments that you put at the beginning of your code to explain e.g. the author, the usage, the license etc? the GPL has guidelines at http://www.fsf.org/licensing/licenses/gpl-howto.html andrew -- http://mail.python.org/mailman/listinfo/pytho

Re: Any way to use a range as a key in a dictionary?

2009-03-26 Thread andrew cooke
Mudcat wrote: > I would like to use a dictionary to store byte table information to > decode some binary data. The actual number of entries won't be that > large, at most 10. That leaves the other 65525 entries as 'reserved' > or 'other' but still need to be somehow accounted for when > referenced.

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread andrew cooke
Aahz wrote: > Excuse me? What decline of this newsgroup? Hmmm. It's hard to respond to this without implicitly criticising others here, which wasn't my point at all. But my personal impression is that over the years various people who used to post here now stay pretty firmly in the dev group, w

Re: c.l.py dead, news at 11 (was Re: Mangle function name with decorator?)

2009-03-27 Thread andrew cooke
Erik Max Francis wrote: [...] > And made all purdy-like: > > http://www.alcyone.com/tmp/python-list%20traffic.pdf That's very pretty, but neither the volume of posts, nor the quality of the people posting here is really what I was talking about. I don't think I explained very well, but seei

Re: Any way to use a range as a key in a dictionary?

2009-03-27 Thread andrew cooke
andrew cooke wrote: > i don't completely follow what you are doing, but i currently use the > following to find a transition in a finite automaton for a regular > expression, and i suspect it's similar to what you want. i get the impression the original poster went away,

Re: Unladen-Swallow: A faster python

2009-03-28 Thread andrew cooke
Tim Roberts wrote: > [...] IronPython has certainly shown that Python can be successfully > implemented in a JIT compiled VM in a performant way, but it has issues > running C extension modules. > > I'll be curious to see where this project goes. given the comments on python-dev i wonder if this

Re: converting a string to a function parameter

2009-03-28 Thread andrew cooke
I'm a bit late to the party, but LEPL 2.2, just released, can now handle this too. I suspect email may mangle this, so you can also read it at http://www.acooke.org/lepl/examples.html#parsing-a-python-argument-list from lepl import * comma = Drop(',') none = Literal('None')

Re: Creating Linked Lists in Python

2009-03-28 Thread andrew cooke
J-Burns wrote: [...] > and to node 2 with the value of "b". Trying to make something like an > NFA. Where id be changing regular expressions to NFAs. > > How can I do this? And if I could do this by some other way than using > linked lists than do tell me about that as well. Just been reminded of

Re: Creating Linked Lists in Python

2009-03-28 Thread andrew cooke
Aahz wrote: > In article , > andrew cooke wrote: >>(I've just noticed that the comments in Sequence are incorrect, >>unfortunately - please ignore any mention of "index"). > > s/comments/lies/ per my .sig ;-) [...] > "At Resolver we've found i

Re: PyFits for Windows?

2009-03-29 Thread andrew cooke
W. eWatson wrote: > I downloaded the tar file, and untarred it with IZarc. That's a strange > way > to package it, that is, for Windows. This almost suggests not many Win > users > are using it. > > One of the pages, , > has a lot of tutorial ma

Re: Help with dict and iter

2009-03-29 Thread andrew cooke
mattia wrote: > Hi all, I a list of jobs and each job has to be processed in a particular > order by a list of machines. > A simple representation is: > # Ordering of machines > JOB1 = [3, 1, 2, 4] > JOB2 = [2, 3, 1, 4] > JOBS = [JOB1, JOB2] > NJOBS = len(JOBS) > Now, I have a list of jobs and I wa

Re: Help with dict and iter

2009-03-29 Thread andrew cooke
mattia wrote: >[i wrote]: >> don't you just want to have a new job machine? >> >> for job_list in job_list_list: >> job_machine = dict((x+1, iter(JOBS[x])) for x in range(NJOBS)) for x >> in job_list: >> print(next(job_machine[x])) ok - btw you can probably simplify the code. this might w

Re: PyFits for Windows?

2009-03-29 Thread andrew cooke
W. eWatson wrote: [...] > Along these lines, there was an astronomy python site at the U of > Washington > not many months ago. The link is broken. Any idea where it went? I sent > the > astro dept a msg about it a few hours ago. NASA has one too, but it's not > loading today. The govt. sites seem

Re: Installing PLPython - Version Problem

2009-03-29 Thread andrew cooke
i haven't got much of a clue about python's binary api, but what you are doing sounds absolutely crazy to me. i guess you are using a binary prebuilt to use a certain python version (ie 2.5). your simplest solution is to install that python version (it is possible to have more than one version o

Re: Caught out by daylight saving :-(

2009-03-30 Thread andrew cooke
these are utilities i use that might help: def parse_utc_date(day, formats=None): ''' Return the epoch for a given UTC date. ''' if day is None: return time() if formats is None: formats = ('%Y-%m-%d %H:%M:%S %Z', '%Y-%m-%d %Z', '%Y-%B-%d %Z') day = day.str

Re: Re. suid/sudo in python

2009-03-30 Thread andrew cooke
Rustom Mody wrote: > Ben Finney wrote >> The key thing to realise is that, having relinquished privilege, the >> same process can't get it back again as easily. So if you need to >> do some tasks as a privileged user, do those *very* early and then drop >> the privileges for the rest of the life of

Re: Deleteing empty directories

2009-03-30 Thread andrew cooke
CinnamonDonkey wrote: > Hi All, > > I've been scratching my head all afternoon trying to work out the best/ > quickest way is to delete empty directories within a tree (Windows). > > I've looked at os.walk() but it seems to traverse the directory tree > in the wrong order (is it possible to reverse

Re: Authorize.net integration problem

2009-03-31 Thread andrew cooke
have you printed msg and checked it is formatted correctly? i have node idea what the protocol is, but your use of join and string concatenation in the generation of msg looks unusual to me. andrew Lakshman wrote: > I am trying to integrate Authorize.net SIM API into django views. > > I am faci

Re: regex negative lookbehind assertion not working correctly?

2009-03-31 Thread andrew cooke
it is working - it's making the final "8" not be matched. don't you want lookahead rather than lookbehind? or force an end of string? andrew Gabriel Rossetti wrote: > Hello everyone, > > I am trying to write a regex pattern to match an ID in a URL only if it > is not a given ID. Here's an ex

Re: Introducing Python to others

2009-03-31 Thread andrew cooke
David C. Ullrich wrote: > In article , > Scott David Daniels wrote: > >> Mensanator wrote: >> > On Mar 26, 11:42 am, "andrew cooke" wrote: >> >> ... >> >> that's cute, but if you show them 2.6 or 3 it's even cuter

Re: Printing Out Called Function Calls

2009-03-31 Thread andrew cooke
Victor Subervi wrote: > Hi; > Due to screwy problems at my server farm that they refuse to fix, I need > to > call lines that execute code from other files, like this: > theContent += `tidBits[i][y][:-2]` > but what that returns is this (as an example): > tableTop(348,180) > when I need it to e

Re: python for loop

2009-03-31 Thread andrew cooke
Lada Kugis wrote: > I'm coming from fortran and *** c *** > background so I'm certainly biased by > them. But if you could explain one thing to me: but this is exactly the same behaviour as the standard way of doing things in c! int a[5]; for (i = 0; i < 5; ++i) { a[i] = 0; }

Re: Python Goes Mercurial

2009-03-31 Thread andrew cooke
Lawrence D'Oliveiro wrote: > > > So what were these "strong antipathies" towards Git, exactly? you're at the wrong group. there's a lot of interesting discussion in python-dev about this (see

Re: Python Goes Mercurial

2009-03-31 Thread andrew cooke
Lawrence D'Oliveiro wrote: > In message , andrew > cooke wrote: > >> Lawrence D'Oliveiro wrote: >>> <http://arstechnica.com/open-source/news/2009/03/python-adopts-the- > mercurial-version-control-system.ars> >>> >>> So what were these &q

Re: Stripping non-numbers from a file parse without nested lists?

2009-03-31 Thread andrew cooke
Rhodri James wrote: > On Tue, 31 Mar 2009 06:51:33 +0100, wrote: > >> There has got to be a better way of doing this: >> >> I'm reading in a file that has a lot of garbage, but eventually has >> something that looks similar to: >> (some lines of garbage) >> dip/dir. >> (some more lines of garbage)

Re: List of paths

2009-04-01 Thread andrew cooke
>>> def filter(values): ... last = None ... for value in values: ... if last is None or not value.startswith(last): ... yield value ... last = value ... >>> for x in filter(['/notebook', ]): ... print(x) ... /notebook /desktop /server/hp/proliant andrew Nico Grubert wr

Re: A design problem I met again and again.

2009-04-01 Thread andrew cooke
Ò»Ê×Ê« wrote: > 3. completely move codes in service to business classes. Initialize > these classes and pass them to protocol classes. > These protocol classes calls these instances of business classes > instead of call service. These means whenever I add a new business > class. I have to add a

Re: python for loop

2009-04-01 Thread andrew cooke
something i don't think has been mentioned much - if you're using "range()" in your python code then you're almost always doing it wrong. i just grepped lepl and i use range 20 times in 9600 lines of code. out of those, all but 3 are in "quick and dirty" tests or experimental code, not in the ma

Re: python for loop

2009-04-01 Thread andrew cooke
andrew cooke wrote: [...] > so in a small/moderate size library of 600 lines (including blanks and 6000 > comments, but excluding tests and exploratory code) the only time i have > used range with array indices i was either unhappy with the

Re: Regex trouble

2009-04-01 Thread andrew cooke
".*?" is a "not greedy" match, which is significantly more difficult to handle than a normal ".*". so the performance will depend on quite complex details of how the regular expression engine is implemented. it wouldn't surprise me if perl was better here, because it comes from a background with

Re: Regex trouble

2009-04-01 Thread andrew cooke
more exactly, my guess is perl has a special case for this that avoids doing a search over all possible matchers via the pushdown stack. andrew cooke wrote: > > ".*?" is a "not greedy" match, which is significantly more difficult to > handle than a normal ".*&qu

Re: List of paths

2009-04-01 Thread andrew cooke
Nico Grubert wrote: >> May be not so much pythonic, but works >> >> for i in range(len(q)): >> for x in q[i:]: >>if x.startswith(q[i]) and x!=q[i]: >>q.remove(x) > > ...but works fine. Thanks, Eugene. > Also thanks to Andrew. Your example works fine, too. Thanks to remind me

Re: python for loop

2009-04-01 Thread andrew cooke
MRAB wrote: > Steven D'Aprano wrote: >> On Wed, 01 Apr 2009 04:58:48 +0200, Lada Kugis wrote: >> >>> Why do we try to create languages that are intuitive to humans, then ? >> >> Because of the foolish hope that sufficiently easy syntax will make >> excellent programmers out of average people. >> >>

Re: Beazley on Generators

2009-04-01 Thread andrew cooke
Kay Schluehr wrote: > There is just one thing I find disappointing. Since the talk is almost > a compendium of advanced uses of generators I'm missing a reference to > Peter Thatchers implementation of monads: > > http://www.valuedlessons.com/2008/01/monads-in-python-with-nice-syntax.html > > Peter

Re: Alpha/For Discussion: RPMs for around 3,000 PyPI packages.

2009-04-01 Thread andrew cooke
Sean Reifschneider wrote: > At PyCon I got this idea in my head to try building packages for > everything > in the cheeseshop. I've had some success, getting over 3,000 packages > built on Fedora 10 (and fewer on CentOS 5 and fewer still on 4). This is > out of 6176 packages. neat idea. the inf

Re: A design problem I met again and again.

2009-04-02 Thread andrew cooke
Lawrence D'Oliveiro wrote: >> What are the average size of source files in your project? If it's >> far lower than 15,000, don't feel it's a little unbalance? > > Why? one reason is that it becomes inefficient to find code. if you structure code as a set of nested packages, then a module, and

Re: simple iterator question

2009-04-02 Thread andrew cooke
Neal Becker wrote: > How do I interleave 2 sequences into a single sequence? > > How do I interleave N sequences into a single sequence? don't know if there's a better way, but from itertools import izip def interleave(*doodahs): for together in izip(*doodahs): for single in together:

Re: Class methods read-only by default?

2009-04-02 Thread andrew cooke
Emanuele D'Arrigo wrote: > Hi Everybody! > > I just tried this: > class C(object): > ...def method(self): > ...pass > ... c = C() delattr(c, "method") > > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'C' object attribute 'method' is read-o

Re: simple iterator question

2009-04-02 Thread andrew cooke
Sion Arrowsmith wrote: > Neal Becker wrote: >>How do I interleave 2 sequences into a single sequence? >> >>How do I interleave N sequences into a single sequence? > > itertools.chain(*itertools.izip(*Nsequences)) aha! thanks. andrew -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Goes Mercurial

2009-04-02 Thread andrew cooke
Echo wrote: > 2009/4/2 Jeremiah Dodds > >> The one thing that makes me want to use git more than any other dvcs is >> that you don't have to create a new directory for branches. This may be >> possible in other dvcs's , but git is the only one I've seen advertise >> the >> capability. [...] > That

Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-02 Thread andrew cooke
Chris Withers wrote: > Martin v. Löwis wrote: >> I propose the following PEP for inclusion to Python 3.1. >> Please comment. > > Would this support the following case: > > I have a package called mortar, which defines useful stuff: > > from mortar import content, ... > > I now want to distribute la

Re: [Python-Dev] PEP 382: Namespace Packages

2009-04-02 Thread andrew cooke
andrew cooke wrote: > Chris Withers wrote: >> Martin v. Löwis wrote: >>> I propose the following PEP for inclusion to Python 3.1. >>> Please comment. >> >> Would this support the following case: >> >> I have a package called mortar, which def

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: > Give the following code.. > class it: > ...def __init__(self): > ...self.count = -1 > ...def next(self): > ...self.count +=1 > ...if self.count < 4: > ...return self.count > ...else: > ...raise StopIterati

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: > >> >> in summary: iterator is bound to one instance of "it", while some_func() >> returns a new instance each time it is called. >> >> BUT >> >> while what you are doing is interesting, it is not the same as Python's >> iterators, which use "yield" from a function and don't

Re: Iteratoration question

2009-04-02 Thread andrew cooke
Robert Kern wrote: >> replace return with yield and it might work. >> >> i have to go eat, but if it doesn't read the python docs on iterators - >> for example http://docs.python.org/reference/expressions.html#index-1825 > > No, .next() needs to be a regular function that returns a value. What he >

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: > Okay, I was thinking more about this. I think this is also what is > irking me. Say I have the following.. > a = [1,2,3,4] for x in a: > ... print x > ... > 1 > 2 > 3 > 4 > > Would 'a' somehow call __iter__ and next()? If so, does python just > perform th

Re: Iteratoration question

2009-04-02 Thread andrew cooke
grocery_stocker wrote: > Okay, I was thinking more about this. I think this is also what is > irking me. Say I have the following.. > a = [1,2,3,4] for x in a: > ... print x > ... > 1 > 2 > 3 > 4 > > Would 'a' somehow call __iter__ and next()? If so, does python just > perform th

Re: Iteratoration question

2009-04-02 Thread andrew cooke
Rhodri James wrote: > On Fri, 03 Apr 2009 02:07:38 +0100, grocery_stocker > wrote: >> Would 'a' somehow call __iter__ and next()? If so, does python just >> perform this magically? > > No. It's "for" that invokes the iteration protocol; that's pretty > much the definition of it. You have read th

Re: A design problem I met again and again.

2009-04-03 Thread andrew cooke
Emile van Sebille wrote: >>> Whether you (generic you) choose to do so or not is a separate issue. > > Also agreed - and that is really my point. Doing so feels to me like > continuing to look for a lost object once you've found it. i can see your point here, but there's two things more to consid

Re: Module caching

2009-04-03 Thread andrew cooke
are you an experienced python programmer? a lot of newbies post here with problems related to unexpected results because they make "the usual" mistakes about list mutability and default function arguments. i suspect that's not the case here, but it seemed worth mentioning, just in case. andrew

Re: A design problem I met again and again.

2009-04-04 Thread andrew cooke
Note sure who wrote: >> > Consolidate existing functions? >> >> > I've thought about it. >> >> > For example, I have two functions: >> >> > #= >> >> > def startXXX(id): >> > pass >> >> > def startYYY(id): >> > pass >> > #= >> >> > I could turn

Re: A design problem I met again and again.

2009-04-04 Thread andrew cooke
andrew cooke wrote: [...] >>> > #= >>> > def start(type, id): >>> > if(type == "XXX"): >>> > pass >>> > else if(type == "YYY"): >>> > pass >>> >

Re: Testing dynamic languages

2009-04-04 Thread andrew cooke
grkunt...@gmail.com wrote: > If I am writing in Python, since it is dynamically, but strongly > typed, I really should check that each parameter is of the expected > type, or at least can respond to the method I plan on calling ("duck" > typing). Every call should be wrapped in a try/except stateme

Re: Testing dynamic languages

2009-04-04 Thread andrew cooke
andrew cooke wrote: > if you are going to do that, stay with java. seriously - i too, am a java > developer about half the time, and you can make java pretty dynamic if you > try hard enough. look at exploiting aspects and functional programming > libraries, for example. also, of c

Re: Why doesn't StopIteration get caught in the following code?

2009-04-04 Thread andrew cooke
grocery_stocker wrote: while True: > ...i = gen.next() > ...print i > ... > 0 > 1 > 4 python's magic isn't as magic as you hope. roughly speaking, it only does the necessary rewriting (writing the equivalent code with next etc etc) when you define a function or a method that contains

Re: Spring-like IoC in python?

2009-04-05 Thread andrew cooke
David Stanek wrote: [...] > The documentation is a little lacking, but that will be changing in > the next few days. Examples of using snake-guice with CherryPy, Django > and TurboGears are just a few days off as well. The API tests[3] show > simple clear examples. [...] > 3. > http://code.google.c

Re: speed of string chunks file parsing

2009-04-06 Thread andrew cooke
[disclaimer - this is just guessing from general knowledge of regular expressions; i don't know any details of python's regexp engine] if your regular expression is the bottleneck rewrite it to avoid lazy matching, references, groups, lookbacks, and perhaps even counted repeats. with a little th

Re: Best way to start

2009-04-06 Thread andrew cooke
Avi wrote: > What is a good way to learn Python? > > Do you recommend going by a book (suggestions welcome) or learning > with tutorials? Both? how do you like to learn and how much experience do you have programming in other languages? andrew -- http://mail.python.org/mailman/listinfo/python-l

Re: Returning different types based on input parameters

2009-04-06 Thread andrew cooke
George Sakkis wrote: > That's more of a general API design question but I'd like to get an > idea if and how things are different in Python context. AFAIK it's > generally considered bad form (or worse) for functions/methods to > return values of different "type" depending on the number, type and/o

Re: Returning different types based on input parameters

2009-04-06 Thread andrew cooke
andrew cooke wrote: > George Sakkis wrote: >> That's more of a general API design question but I'd like to get an >> idea if and how things are different in Python context. AFAIK it's >> generally considered bad form (or worse) for functions/methods to

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
Carl Banks wrote: > import collections > import itertools > > def createInitialCluster(fileName): > fixedPoints = [] > # quantization is a dict that assigns sequentially-increasing > numbers > # to values when reading keys that don't yet exit > quantization = defaultdict.collections

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
convert('1,2,red') [1.0, 2.0, 0] >>> convert('1,2,blue') [1.0, 2.0, 1] >>> convert('1,2,blue,blue') [1.0, 2.0, 1, 0] andrew cooke wrote: > Carl Banks wrote: >> import collections >> import itertools >> >> def createIniti

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
R. David Murray wrote: >> [...] >> try: >> dimensions.append(float(s)) >> except: >> dimensions.append(float(quantization[s])) > > No, no, no; never use a bare except! :) can you explain why? i can't think of any reason why the code would be better catching a specific exception. as

Re: in place list modification necessary? What's a better idiom?

2009-04-07 Thread andrew cooke
MRAB wrote: > andrew cooke wrote: >> R. David Murray wrote: >>>> [...] >>>> try: >>>> dimensions.append(float(s)) >>>> except: >>>> dimensions.append(float(quantization[s])) >>> No, no, no; never use a b

Re: Creating Linked Lists in Python

2009-04-07 Thread andrew cooke
J-Burns wrote: > How can I do this? And if I could do this by some other way than using > linked lists than do tell me about that as well. replying to this dead thread mainly for anyone using google. there's now a python regular expression engine in lepl and the source code can be seen via http:/

Re: Why does Python show the whole array?

2009-04-08 Thread andrew cooke
Gilles Ganault wrote: > On Wed, 08 Apr 2009 12:11:55 +0200, Ulrich Eckhardt > wrote: >>find() returns the index where it is found or -1 if it is not found. Both >> an >>index>0 or a -1 evaluate to True when used as conditional expression. > > Thanks everyone. I shouldn't have assumed that "if test

Re: nested looping

2009-04-08 Thread andrew cooke
bit late here, but if it's as simple as you say, i think it would be much more efficient (because you only scan checklist and alist once each) to do: known = set() for check in checklist: known.add(check[0:-1]) missing = filter(lambda alpha: alpha not in known, alist) andrew PK wrote: > Exce

Re: Retrieving a specific object from a list?

2009-04-09 Thread andrew cooke
andrew cooke wrote: [...] > but when you need to access instances by more than one value (.bar and > .baz) then typically that's a hard problem, and there's a trade-off > somewhere. you might find writing a special container that contains two > dicts is useful. if so, you

Re: Retrieving a specific object from a list?

2009-04-09 Thread andrew cooke
Jeremiah Dodds wrote: > I've been looking over some of my code, and I've found something I do that > has a bit of a smell to it. I've searched the group and docs, and haven't > found much of anything that solves this particular problem, although I may > just not be searching correctly. > > Anyhow,

Re: Re: Why does Python show the whole array?

2009-04-09 Thread andrew cooke
Peter Otten wrote: > John Posner wrote: > >> Given how common string maniuplations are, I guess I'm surprised that >> Python hasn't yet made "contains()" into both a "string"-module function >> *and* a string-object method. > > Could you explain why you prefer 'contains(belly, beer)' > or 'belly.co

Re: Scrap Posts

2009-04-09 Thread andrew cooke
are you on the mailing list (python-list@python.org) or reading via google groups? groups is full of junk, but the list is filtered. the (filtered) list is also available via gmane and similar. (disclaimer - i also use spamassasin so it's possible that is cleaning the mail up, but this discussi

Re: Recommendations on Pythonic tree data structure design techniques

2009-04-09 Thread andrew cooke
pyt...@bdurham.com wrote: > Any recommendations on Python based tree data structures that I > can study? I'm working on an application that will model a basic > outline structure (simple tree) and am looking for ideas on > Pythonic implementation techniques. By outline I mean a > traditional hierar

Re: Why is it that *dbm modules don't provide an iterator? (Language design question)

2009-04-09 Thread andrew cooke
"Martin v. Löwis" wrote: >> I assumed there were some decisions behind this, rather than it's just >> not implemented yet. > > I believe this assumption is wrong - it's really that no code has been > contributed to do that. But doesn't the issue at http://bugs.python.org/issue662923 imply that the

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread andrew cooke
Arnaud Delobelle wrote: > I do this: > > binops = ['add', 'sub', 'mul', 'div', 'radd', 'rsub'] # etc > unops = ['neg', 'abs', invert'] # etc > > binop_meth = """ > def __%s__(self, other): > return type(self)(int.__%s__(self, other)) > """ > > unop_meth = """ > def __%s__(self): > return ty

Re: Automatically generating arithmetic operations for a subclass

2009-04-14 Thread andrew cooke
Arnaud Delobelle wrote: > "andrew cooke" writes: >> Arnaud Delobelle wrote: >>> class MyInt(int): >>> for op in binops: >>> exec binop_meth % (op, op) >>> for op in unops: >>> exec unop_meth % (op,

Re: [OT] large db question about no joins

2009-04-17 Thread andrew cooke
on the more general point about exactly how to handle large data sets, i found this article interesting - http://highscalability.com/unorthodox-approach-database-design-coming-shard andrew -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there a maximum size to a Python program?

2009-04-27 Thread andrew cooke
not sure i've read all the posts on this, and i don't fully understand the problem, but someone's mentioned sqlalchemy, so here's my experience with that and large updates using mapped objects. 1 - don't commit each object as you modify it. instead, process a whole pile in memory and then (perha

Re: The whole story

2009-04-28 Thread andrew cooke
Paul Hemans wrote: > Hi Andrew, > The reason I am using mapped objects is that I need to abstract from the > database implementation allowing the replication to target a number of > different platforms. This will definitely slow things down. have you looked at sqlalchemy's generic sql support? yo

Re: SQL and CSV

2009-05-08 Thread andrew cooke
Lawrence D'Oliveiro wrote: > In message , Peter Otten wrote: > >> While it may not matter here using placeholders instead of manually >> escaping user-provided values is a good habit to get into. > > Until you hit things it can't deal with. The post you are replying to was talking about using the

Re: SQL and CSV

2009-05-08 Thread andrew cooke
o be some kind of cryptic argument against parameters. andrew Nick wrote: > On May 8, 1:49 pm, "andrew cooke" wrote: >> Lawrence D'Oliveiro wrote: >> > In message , Peter Otten wrote: >> >> >> While it may not matter here using placeholders instead

Re: Generic web parser

2009-05-18 Thread andrew cooke
http://groups.google.com/group/beautifulsoup/browse_thread/thread/d416dd19fdaa43a6 http://jjinux.blogspot.com/2008/10/python-some-notes-on-lxml.html andrew -- http://mail.python.org/mailman/listinfo/python-list

method-wrapper?

2008-05-31 Thread andrew cooke
Hi, Within Python (2.5): >>> help("__str__") Help on method-wrapper object: __str__ = class method-wrapper(object) | Methods defined here: | | __call__(...) | x.__call__(...) <==> x(...) | | __cmp__(...) | x.__cmp__(y) <==> cmp(x,y) [...] What is "method-wrapper"?

Dynamic use of property() fails

2008-04-14 Thread andrew cooke
Hi, This is my first attempt at new classes and dynamic python, so I am probably doing something very stupid... After reading the how-to for descriptors at http://users.rcn.com/python/download/Descriptor.htm I decided I would make an object that returns attributes on read, but on setting calls an

Re: Dynamic use of property() fails

2008-04-14 Thread andrew cooke
[Gabriel:] > The "magic" happens when the descriptor is found in the *class*, not in > the instance. I think it's detailed in Hettinger's document. > Do you actually want "per-instance" defined properties? ah! ok. yes, you're right: i want instance values but class properties, so i'll rethink th

Re: Dynamic use of property() fails

2008-04-15 Thread andrew cooke
On Apr 15, 4:06 am, Bruno Desthuilliers wrote: > The canonical solution is to use a custom descriptor instead of a property: > > class Field(object): >def __init__(self, name, onchange): > self.name = name > self.onchange = onchange > >def __get__(self, instance, cls): > if

Re: Dynamic use of property() fails

2008-04-15 Thread andrew cooke
ignore that - i was mistaken (my test was too complex). the problem seems to be that the attribute is deleted even though __delete__ is defined. i'll look at it tomorrow. thanks again, andrew On Apr 15, 4:50 am, andrew cooke <[EMAIL PROTECTED]> wrote: > i tried code very similar

Re: Dynamic use of property() fails

2008-04-15 Thread andrew cooke
OK, fixed my bug - it does work. Now sleep... Thanks again, Andrew -- http://mail.python.org/mailman/listinfo/python-list

Metaprogramming Example

2008-04-16 Thread andrew cooke
Hi, Thanks for the help a couple of days ago. I completed what I was doing and wrote a summary which I've posted at http://acooke.org/cute/PythonMeta0.html (it's kind of long to post here). I hope it might be useful to someone else - it's complete code for a simple metaprogramming task that us

Re: Metaprogramming Example

2008-04-17 Thread andrew cooke
On Apr 17, 7:12 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: [...] Thanks very much! These are useful pointers. I'll update my code accordingly. At one point you pointed out I didn't need parentheses and I agree - I was using them to avoid having a line continuation backslash (I think I r

Re: Metaprogramming Example

2008-04-17 Thread andrew cooke
bruno: > Ho, and yes : one day, you'll get why it's such a good thing to unite > functions and methods !-) me: > PS Is there anywhere that explains why Decorators (in the context of > functions/methods) are so good? I've read lots of things saying they > are good, but no real justification of why

Re: Metaprogramming Example

2008-04-19 Thread andrew cooke
On Apr 18, 4:48 am, Bruno Desthuilliers wrote: [...] > Practically, this means that (amongst other niceties) : > - you can define functions outside classes and use them as instance or > class methods > - you can add/replaces methods dynamically on a per-class or > per-instance basis > - you can ac

Logging ancestors ignored if config changes?

2008-04-25 Thread andrew cooke
Hi, I am seeing some odd behaviour with logging which would be explained if loggers that are not defined explicitly (but which are controlled via their ancestors) must be created after the logging system is configured via fileConfig(). That's a bit abstract, so here's the problem itself: I defi

Re: Logging ancestors ignored if config changes?

2008-04-26 Thread andrew cooke
One way to handle this is to make creation of module-level Loggers lazy, and make sure that logging initialisation occurs before any other logging is actually used (which is not so hard - just init log at the start of the application). Of course, there's a performance hit... For example: class L

Function name unchanged in error message

2010-01-29 Thread andrew cooke
Is there any way to change the name of the function in an error message? In the example below I'd like the error to refer to bar(), for example (the motivation is related function decorators - I'd like the wrapper function to give the same name) >>> def foo(): ... return 7 ... >>> foo.__name

<    1   2   3   4   >