Re: Code Generator written in python

2010-01-14 Thread Arnaud Delobelle
trzewiczek writes: > On 01/13/2010 05:09 PM, Arnaud Delobelle wrote: [...] >> Sure, here are some example of self-evaluating python objects, >> i.e. for each v below, >> >> v == eval(v) >> >> I'm quite proud of the last one. [...] >> v =

Re: Writing a string.ishex function

2010-01-14 Thread Arnaud Delobelle
"D'Arcy J.M. Cain" writes: > On Thu, 14 Jan 2010 09:07:47 -0800 > Chris Rebert wrote: >> Even more succinctly: >> >> def ishex(s): >> return all(c in string.hexdigits for c in s) > > I'll see your two-liner and raise you. :-) > > ishex = lambda s: all(c in string.hexdigits for c in s) I's

Re: Writing a string.ishex function

2010-01-14 Thread Arnaud Delobelle
MRAB writes: > Arnaud Delobelle wrote: >> "D'Arcy J.M. Cain" writes: >> >>> On Thu, 14 Jan 2010 09:07:47 -0800 >>> Chris Rebert wrote: >>>> Even more succinctly: >>>> >>>> def ishex(s): >>>

Re: Changing Lutz's mydir from Edition 2, Learning Python

2010-01-17 Thread Arnaud Delobelle
"W. eWatson" writes: > See Subject. The code is below with a few changes I made at the bottom > by inserting > import string > import numpy > > module = raw_input("Enter module name: ") replace this line with: module_name = raw_input("Enter module name: ") module = __i

Re: not and is not problem

2010-01-18 Thread Arnaud Delobelle
On 18 Jan, 15:43, superpollo wrote: > hi: > > #!/usr/bin/env python > data = "seq=123" > name , value = data.split("=") > print name > print value > if not name == "seq": >      print "DOES NOT PRINT OF COURSE..." > if name is not "seq": >      print "WTF! WHY DOES IT PRINT?" > > help please. > >

Re: Python decorator syntax limitations

2010-01-18 Thread Arnaud Delobelle
a...@pythoncraft.com (Aahz) writes: > In article <4b54998...@dnews.tpgi.com.au>, > Lie Ryan wrote: >> >>If you are sure you can put up a convincing argument for lifting this >>restriction, and you are willing to put some time arguing, you are >>welcome to start a thread in the python-dev mailing

Re: using super

2010-01-18 Thread Arnaud Delobelle
Jean-Michel Pichavant writes: [...] > Then is there a reason why return super(Subclass, self).parrot() > would be prefered over the "classic" return Base.parrot(self) > ? > > Or is it just a matter of preference ? Using super() calls the next method in the class's Method Resolution O

Re: Performance of lists vs. list comprehensions

2010-01-19 Thread Arnaud Delobelle
Gerald Britton writes: > [snip] > >> >> Yes, list building from a generator expression *is* expensive. And >> join has to do it, because it has to iterate twice over the iterable >> passed in: once for calculating the memory needed for the joined >> string, and once more to actually do the join (

Re: Performance of lists vs. list comprehensions

2010-01-19 Thread Arnaud Delobelle
Gerald Britton writes: > That's surprising. I wouldn't implement it that way at all. I'd use a > dynamically-expanding buffer as I suggested. That way you get a > single pass and don't have to calculate anything before you begin. In > the best case, you'd use half the memory (the result just f

Re: Py 3: How to switch application to Unicode strings?

2010-01-19 Thread Arnaud Delobelle
Gnarlodious writes: > Well, Python 3 is supposed to be all Unicode by default. I shouldn't > even need to say > # coding:UTF-8 > > And, the file is saved as Unicode. > When a filed is saved, shouldn't it be in a specific encoding? I don't see how you can save your file 'as unicode'. You should

Re: Closures in metaclasses

2010-01-21 Thread Arnaud Delobelle
Falcolas writes: > I'm running into an issue with closures in metaclasses - that is, if I > create a function with a closure in a metaclass, the closure appears > to be lost when I access the final class. I end up getting the text > 'param' instead of the actual tags I am expecting: > > ALL_TAGS

Re: Closures in metaclasses

2010-01-21 Thread Arnaud Delobelle
On Jan 21, 6:37 pm, Falcolas wrote: > On Jan 21, 11:24 am, Arnaud Delobelle wrote: > > > > > > > Falcolas writes: > > > I'm running into an issue with closures in metaclasses - that is, if I > > > create a function with a closure in a metacla

Re: Sorted dictionary

2010-01-21 Thread Arnaud Delobelle
"Jan Kaliszewski" writes: > Dnia 21-01-2010 o 09:27:52 Raymond Hettinger napisał(a): > >> On Jan 20, 5:02 pm, "Jan Kaliszewski" wrote: > >>> http://code.activestate.com/recipes/576998/ > >> Using an underlying list to track sorted items >> means that insertion and deletion take O(n) time. >> Th

Re: Closures in metaclasses

2010-01-21 Thread Arnaud Delobelle
Falcolas writes: > On Jan 21, 12:10 pm, Arnaud Delobelle wrote: [...] >> Or you could override __getattr__ >> >> -- >> Arnaud > > I tried overriding __getattr__ and got an error at runtime (the > instance did not have xyz key, etc), and the Tag dict is no

Re: Rounding up to the next 100

2010-01-21 Thread Arnaud Delobelle
noydb writes: > If one has a floating number as a string, is there a spiffy way to > round that string-number UP to the nearest 100? > > XstrNmbr = 3579.127893 -- would want to round that to 3600. > > Thanks for any help! >>> XstrNmbr = 3579.127893 >>> round(float(XstrNmbr), -2) 3600.0 >>> HTH

Re: Rounding up to the next 100

2010-01-21 Thread Arnaud Delobelle
Arnaud Delobelle writes: > >>> XstrNmbr = 3579.127893 I meant >>> XstrNmbr = "3579.127893" > >>> round(float(XstrNmbr), -2) > 3600.0 -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Consume an iterable

2010-01-22 Thread Arnaud Delobelle
Muhammad Alkarouri writes: > In the python help for itertools, the following function is provided: > > def consume(iterator, n): > "Advance the iterator n-steps ahead. If n is none, consume > entirely." > collections.deque(islice(iterator, n), maxlen=0) > > What is the advantage of using

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-22 Thread Arnaud Delobelle
Gilles Ganault writes: > On Fri, 22 Jan 2010 09:49:32 -0500, Dave Angel wrote: >>Seems to me the other solutions I've seen so far are more complex than >>needed. I figure you either want an unordered list, in which case you >>could use random.shuffle(), or you want a list that's sorted, but s

Re: Consume an iterable

2010-01-22 Thread Arnaud Delobelle
Muhammad Alkarouri writes: > In the python help for itertools, the following function is provided: > > def consume(iterator, n): > "Advance the iterator n-steps ahead. If n is none, consume > entirely." > collections.deque(islice(iterator, n), maxlen=0) > > What is the advantage of using

Re: list.pop(0) vs. collections.dequeue

2010-01-22 Thread Arnaud Delobelle
Steve Howell writes: > On Jan 22, 12:14 pm, Chris Rebert wrote: >> On Fri, Jan 22, 2010 at 11:14 AM, Steve Howell wrote: >> > The v2.6.4 version of the tutorial says this: >> >> > ''' >> > It is also possible to use a list as a queue, where the first element >> > added is the first element retr

Re: Using dictionary key as a regular expression class

2010-01-22 Thread Arnaud Delobelle
Chris Jones writes: > I was writing a script that counts occurrences of characters in source > code files: > > #!/usr/bin/python > import codecs > tcounters = {} > f = codecs.open('/home/gavron/git/screen/src/screen.c', 'r', "utf-8") > for uline in f: > lline = [] > for char in uline[:-1]: >

Re: list.pop(0) vs. collections.dequeue

2010-01-23 Thread Arnaud Delobelle
Dave Angel writes: > Arnaud Delobelle wrote: >> Steve Howell writes: >> >> >>> On Jan 22, 12:14 pm, Chris Rebert wrote: >>> >> I made the comment you quoted. In CPython, it is O(n) to delete/insert >> an element at the st

Re: medians for degree measurements

2010-01-23 Thread Arnaud Delobelle
Steve Howell writes: > I just saw the thread for medians, and it reminded me of a problem > that I need to solve. We are writing some Python software for > sailing, and we need to detect when we've departed from the median > heading on the leg. Calculating arithmetic medians is > straightforwar

Re: iterating lists

2010-01-23 Thread Arnaud Delobelle
ceciliasei...@gmx.de writes: > As you were talking about list.pop()... > > Is anyone able to reproduce the following and explain why this happens > by chance? (Using 3.1.1) > > l1 = ["ready", "steady", "go"] > l2 = ["one", "two", "tree"] > l3 = ["lift off"] > > for w in l1: >print(l1.pop()) #

Re: how can i know if a python object have a attribute such as 'attr1'?

2010-01-23 Thread Arnaud Delobelle
thinke365 writes: > for example, i may define a python class: > class A: > def sayHello(): > print 'hello' > > a = A() > a.attr1 = 'hello' > a.attr2 = 'bb' > > b = A() > a.attr2 = 'aa' > > how can i know whether an object have an attribute named attr1? hasattr(a, 'attr1') -- Arn

Re: how to generate random numbers that satisfy certain distribution

2010-01-23 Thread Arnaud Delobelle
thinke365 writes: > such as uniform distribution, Normal distribution or poisson distribution. > is there any package that can be used to generate such random numbers. It's all in the standard library, the module is called -surprisingly- 'random'. - use random.uniform for the uniform distributi

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-24 Thread Arnaud Delobelle
Gilles Ganault writes: > On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault > wrote: >>To avoid users from creating login names that start with digits in >>order to be listed at the top, I'd like to sort the list differently >>every minute so that it'll start with the next letter, eg. display th

Re: [2.5.1.1/dictionary] Change sorting order?

2010-01-24 Thread Arnaud Delobelle
Arnaud Delobelle writes: > Gilles Ganault writes: > >> On Fri, 22 Jan 2010 13:17:44 +0100, Gilles Ganault >> wrote: >>>To avoid users from creating login names that start with digits in >>>order to be listed at the top, I'd like to sort the list differ

Re: list.pop(0) vs. collections.dequeue

2010-01-25 Thread Arnaud Delobelle
Steve Howell writes: [...] > My algorithm does exactly N pops and roughly N list accesses, so I > would be going from N*N + N to N + N log N if switched to blist. Can you post your algorithm? It would be interesting to have a concrete use case to base this discussion on. -- Arnaud -- http://m

Re: list.pop(0) vs. collections.dequeue

2010-01-26 Thread Arnaud Delobelle
Steve Howell writes: > On Jan 25, 1:32 pm, Arnaud Delobelle wrote: >> Steve Howell writes: >> >> [...] >> >> > My algorithm does exactly N pops and roughly N list accesses, so I >> > would be going from N*N + N to N + N log N if switched to blist.

Re: Generic proxy (that proxies methods like __iter__)

2010-01-27 Thread Arnaud Delobelle
On 27 Jan, 14:41, D HANNEY wrote: [...] > >>> class NoGuardProxy(object): > > ... def __init__(self, t): > ... self.t = t > ... def __enter__(self): > ... return self > ... def __exit__(self, type, value, traceback): > ... ret

Re: site.py confusion

2010-01-27 Thread Arnaud Delobelle
George Trojan writes: > Inspired by the 'Default path for files' thread I tried to use > sitecustomize in my code. What puzzles me is that the site.py's main() > is not executed. My sitecustomize.py is > def main(): > print 'In Main()' > main() > and the test program is > import site > #site.

Re: List weirdness - what the heck is going on here?

2010-01-27 Thread Arnaud Delobelle
Rotwang writes: > Hi all, I've been trying to make a class with which to manipulate > sound data, and have run into some behaviour I don't understand which > I hope somebody here can explain. The class has an attribute called > data, which is a list with two elements, one for each audio channel,

Re: Need help with a program

2010-01-28 Thread Arnaud Delobelle
nn writes: > On Jan 28, 10:50 am, evilweasel wrote: >> I will make my question a little more clearer. I have close to 60,000 >> lines of the data similar to the one I posted. There are various >> numbers next to the sequence (this is basically the number of times >> the sequence has been found i

Re: Need help with a program

2010-01-28 Thread Arnaud Delobelle
nn writes: > After posting I was thinking I should have posted a more > straightforward version like the one you wrote. Now there is! It > probably is more efficient too. I just have a tendency to think in > terms of pipes: "pipe this junk in here, then in here, get output". > Probably damage from

Re: slicing return iter?

2009-10-17 Thread Arnaud Delobelle
On Oct 17, 3:40 pm, StarWing wrote: > hello everyone, I'm new here :-) > > sometimes I want to iterate a part of a sequence. but don't want to > copy it. i.e. > > a = list(...) > # now a is a list, and a[:] is another list, and so a[m:n] > # now we do something with the 0~len(a)-3 elements of a >

Re: slicing return iter?

2009-10-17 Thread Arnaud Delobelle
On Oct 17, 6:05 pm, StarWing wrote: > On 10月17日, 下午11时56分, Arnaud Delobelle wrote: > > thanks for attention :-) > > > Check the itertools module. > > > HTH > > > -- > > Arnaud > > I had checked it for serval times. maybe it's my inattent

Re: Python and Ruby

2010-01-31 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Sun, 31 Jan 2010 04:28:41 -0800, Ed Keith wrote: > >> In most functional languages you just name a function to access it and >> you do it ALL the time. >> >> for example, in if you have a function 'f' which takes two parameters to >> call the function and get the res

Re: Iterating over a function call

2010-02-01 Thread Arnaud Delobelle
Gerald Britton writes: > Hi -- I have many sections of code like this: > > for value in value_iterator: > value_function(value) > > I noticed that this does two things I don't like: > > 1. looks up "value_function" and "value" for each iteration, but > "value_function" doesn't change

Re: No return to the parent function

2010-02-02 Thread Arnaud Delobelle
Joan Miller writes: > I've a main function called i.e. *foo()* which has a block of code > that is repetead several times (for the error catching code and error > reporting), but that code has a return to exit of *foo()* > > --- > foo(): > ... > if self.background: > _log.ex

Re: What's this vText() annotation mean?

2010-02-02 Thread Arnaud Delobelle
tinn...@isbd.co.uk writes: > What does this vText() annotation mean in a returned list:- > > [['Apr 19', vText(u'PAYE'), ''], It means your list contains an instance of a class whose __repr__() method returns "vText(u'PAYE')". If it follows common practice, the class is probably named "vTex

Re: Your beloved python features

2010-02-04 Thread Arnaud Delobelle
On 4 Feb, 23:03, Julian wrote: > Hello, > > I've asked this question at stackoverflow a few weeks ago, and to make > it clear: this should NOT be a copy of the stackoverflow-thread > "hidden features of Python". > > I want to design a poster for an open source conference, the local > usergroup wil

Re: Dreaming of new generation IDE

2010-02-05 Thread Arnaud Delobelle
Robert Kern writes: > I prefer Guido's formulation (which, naturally, I can't find a direct > quote for right now): if you expect that a boolean argument is only > going to take *literal* True or False, then it should be split into > two functions. So rather than three boolean arguments, would y

Re: Code snippet: dualmethod descriptor

2010-02-06 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Thu, 04 Feb 2010 00:09:02 -0300, Gabriel Genellina wrote: > >> En Sat, 30 Jan 2010 03:06:18 -0300, Steven D'Aprano >> escribió: >> >>> class dualmethod(object): > [...] > >> Seems useful! >> Perhaps a better place to post it would be >>

Re: Dreaming of new generation IDE

2010-02-06 Thread Arnaud Delobelle
"Gabriel Genellina" writes: > En Fri, 05 Feb 2010 19:22:39 -0300, bartc escribió: >> "Steve Holden" wrote in message >> news:mailman.1998.1265399766.28905.python-l...@python.org... >>> Arnaud Delobelle wrote: >>>> Robert Kern writes: &

Re: Modifying Class Object

2010-02-07 Thread Arnaud Delobelle
"Alf P. Steinbach" writes: > * Chris Rebert: >> On Sun, Feb 7, 2010 at 5:05 PM, T wrote: >>> Ok, just looking for a sanity check here, or maybe something I'm >>> missing. I have a class Test, for example: >>> >>> class Test: >>>def __init__(self, param1, param2, param3): >>>self.par

EAFP gone wrong

2010-02-09 Thread Arnaud Delobelle
Hi all, Hi have a set of classes that represent mathematical objects which can be represented as a string using a 'latex' method (after Knuth's famous typesetting system). As I want to be able to typeset some builtin types as well, I have a generic function, latex(), as follows: def latex(val):

Re: EAFP gone wrong

2010-02-10 Thread Arnaud Delobelle
Malte Helmert writes: > Arnaud Delobelle wrote: > >> This means that EAFP made me hide a typo which would have been obviously >> detected had I LBYLed, i.e. instead of >> >> try: >> return val.latex() >> except AttributeError: >>

Re: Creating formatted output using picture strings

2010-02-10 Thread Arnaud Delobelle
pyt...@bdurham.com writes: > Original poster here. > > Thank you all for your ideas. I certainly learned some great techniques > by studying everyone's solutions!! > > I was thinking that there was a built-in function for this common(?) use > case which is why I shied away from writing my own in t

Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Wed, 10 Feb 2010 10:08:47 -0500, John Posner wrote: > >>> This won't work correctly, because old_f still tries to refer to itself >>> under the name "f", and things break very quickly. >> >> They didn't break immediately for me -- what am I missing?: > > The original

Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
Steven D'Aprano writes: > On Wed, 10 Feb 2010 18:31:23 +, Arnaud Delobelle wrote: > >> It's not ideal, but you can use a decorator like this to solve this >> problem: >> >> def bindfunction(f): >> def bound_f(*args, **kwargs): >>

Re: Function attributes

2010-02-10 Thread Arnaud Delobelle
MRAB writes: > Does this mean that Python needs, say, __function__ (and perhaps also > __module__)? See PEP 3130 "Access to Current Module/Class/Function" (rejected) (http://www.python.org/dev/peps/pep-3130/) -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Modifying Class Object

2010-02-11 Thread Arnaud Delobelle
"Alf P. Steinbach" writes: [...] > That's bullshit. [...] > not any that you know about. [...] > yet another ad hominem attack [...] > It also reflects rather badly on you. [...] > - Alf Alf, The above was extracted from the last post from you but I could have picked almost any of your recent e

Re: calculating a string equation

2010-02-11 Thread Arnaud Delobelle
Astan Chee writes: > Hi, > I have some variables in my script that looks like this: > vars = {'var_a':'10','var_b':'4'} > eqat = "(var_a/2.0) <= var_b" > result = "(var_a+var_b)/7" > What I'm trying to do is to plug in var_a and var_b's values from vars > into eqat and see if eqat returns true or

Re: Function attributes

2010-02-11 Thread Arnaud Delobelle
"Gabriel Genellina" writes: > En Thu, 11 Feb 2010 00:25:00 -0300, Terry Reedy > escribió: >> On 2/10/2010 4:49 PM, Gabriel Genellina wrote: >> >>> I've written a decorator for "injecting" a __function__ name into the >>> function namespace, but I can't find it anywhere. I think I implemented >>>

Re: constructor overwrite

2010-02-15 Thread Arnaud Delobelle
Mug writes: > hi ,i had a problem on constructor overwrite: > i have something like: > > class obj: > def __init__(self, x=100, y=None): > if y is None: > self.x=x > else: > self.y=y > so i can call : > objet = obj() # x=100 y=None > or > objet = obj(40) # x= 40 y=Non

Re: Loop problem while generating a new value with random.randint()

2010-02-15 Thread Arnaud Delobelle
Jean-Michel Pichavant writes: > Paulo Repreza wrote: >> Greetings, >> >> I'm having problems with a little script that I'm trying to finish, >> I don't know if I'm in the right track but I know somebody is going >> to help me. >> >> The script: >> >> # Import modules random for function randint >

Re: Modifying Class Object

2010-02-15 Thread Arnaud Delobelle
John Posner writes: [...] >> x = s[0] [...] > assigns the name *x* to the object that *s[0]* refers to s[0] does not refer to an object, it *is* an object (once evaluated of course, otherwise it's just a Python expression). -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: finding contents from string

2010-02-16 Thread Arnaud Delobelle
danin writes: > Hi all, > I am looking for particular solution. I am having one string > say: > string- "http://maps.google.co.in/maps/ms? > hl=en&ie=UTF8&msa=0&msid=106178526636832397420.00047fb46fa8d02481f09&ll=20.730428,86.456909&spn=2.178194,3.526611&z=8 > " > and from this

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Arnaud Delobelle
"W. eWatson" writes: > See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. Here are a few ways. >>> a = [1,4,9,3] >>> max_index = max(xrange(len(a)), key=a.__getitem__) >>> max_index 2 >>> # Or: ... max_index = max((n, i) for i, n in enumerate(a))[1] >>> max_index 2 >>> # Or: ... from

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Arnaud Delobelle
Arnaud Delobelle writes: > "W. eWatson" writes: > >> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. > > Here are a few ways. [...] My copy past went wrond and I forgot the first one: >>> a = [1,4,9,3] >>> max_index = a.inde

Re: Using class attributes

2010-02-16 Thread Arnaud Delobelle
Leo Breebaart writes: > Chris Rebert writes: > >> On Mon, Feb 15, 2010 at 10:29 AM, Leo Breebaart wrote: >> >> > I have a base class Foo with a number of derived classes FooA, >> > FooB, FooC, etc. Each of these derived classes needs to read >> > (upon initialisation) text from an associated te

Re: Implicit __init__ execution in multiple inheritance

2010-02-16 Thread Arnaud Delobelle
rludwinowski writes: > class A: > def __init__(self): > print("A__init__") > > class B: > def __init__(self): > print("B__init__") > > class C(A, B): > pass > > C() > >>> A__init__ > > Why __init__ class B will not be automatic executed? Because it's documented behavi

Re: Using class attributes

2010-02-16 Thread Arnaud Delobelle
Jean-Michel Pichavant writes: [...] > While all these proposals are giving interesting technical anwsers to > the OP problem, I think that the OP original code is still the best > (_imo_). > > class Foo(object): > def __init__(self): > self.template_filename = "%s.tmpl" % self.__cla

Re: Is there a simple way to find the list index to the max value?

2010-02-16 Thread Arnaud Delobelle
a...@pythoncraft.com (Aahz) writes: > In article <4b7a91b1.6030...@lonetwin.net>, steve wrote: >>On 02/16/2010 05:49 PM, W. eWatson wrote: >>> >>> See Subject. a = [1,4,9,3]. Find max, 9, then index to it, 2. >> >>The most obvious would be a.index(max(a)). Is that what you wanted ? > > The disad

Re: Replacement for e.message() in python 2.6

2010-02-17 Thread Arnaud Delobelle
Nandakumar Chandrasekhar writes: > Dear Folks, > > In previous versions of Python I used to use e.message() to print out > the error message of an exception like so: > > try: > result = x / y > except ZeroDivisionError, e: > print e.message() > > Unfortunately in Python 2.6 the messag

Re: Over(joy)riding

2010-02-17 Thread Arnaud Delobelle
mk writes: > Found in Dive into Python: > > """Guido, the original author of Python, explains method overriding > this way: "Derived classes may override methods of their base > classes. Because methods have no special privileges when calling other > methods of the same object, a method of a base

Re: Is automatic reload of a module available in Python?

2010-02-17 Thread Arnaud Delobelle
"R (Chandra) Chandrasekhar" writes: > Dear Folks, > > I am currently developing a python program, let us call it > "generic.py", and I am testing out the functions therein by testing > them out interactively in the python interpreter by invoking python > and doing > > import generic > > Once I hi

Re: Referring to class methods in class attributes

2010-02-17 Thread Arnaud Delobelle
Bruno Desthuilliers writes: [...] > class Foo(object): > def bar(self): > return "baaz" > > print Foo.__dict__.keys() > print type(Foo.__dict__['bar']) > > > So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The > answer is : attribute lookup rules and the descriptor pro

Re: Using class attributes

2010-02-18 Thread Arnaud Delobelle
Leo Breebaart writes: > Arnaud Delobelle writes: > >> Descriptors to the rescue :) >> >> def read_body_from(filename): >> print "** loading content **" >> return "" % filename >> >> # This is a kind of class property

Re: Help with lambda

2010-02-18 Thread Arnaud Delobelle
lallous writes: > Hello, > > I am still fairly new to Python. Can someone explain to me why there > is a difference in f and g: > > def make_power(n): > return lambda x: x ** n > > # Create a set of exponential functions > f = [lambda x: x ** n for n in xrange(2, 5)] > g = [make_power(n) for

Re: How to make an empty generator?

2010-02-18 Thread Arnaud Delobelle
On 18 Feb, 23:33, Ben Finney wrote: [...] > No need to define functions or classes; let a generator expression take > care of it for you:: > >     >>> foo = (x for x in list()) >     >>> foo.next() >     Traceback (most recent call last): >       File "", line 1, in >     StopIteration What abou

Re: How to make an empty generator?

2010-02-19 Thread Arnaud Delobelle
Ben Finney writes: > Arnaud Delobelle writes: > >> What about >> foo = iter('') > > That doesn't return a generator. > > >>> foo = iter('') > >>> foo > > > Whether the OP needs to create a gen

Re: Executing Python code on another computer

2010-02-19 Thread Arnaud Delobelle
On 19 Feb, 15:52, SiWi wrote: > Hello community, > I googled for an answer of the following problem, but I couldn't find > anything. > I've got a netbook and my fast workstation compter, which I usually > use for developing. > But I'd also like to take my netbook around the house and to develop >

Re: Avoid converting functions to methods in a class

2010-02-20 Thread Arnaud Delobelle
On 20 Feb, 03:33, Steven D'Aprano wrote: > I have a convention when writing unit tests to put the target of the test > into a class attribute, as follows: > > class MyTest(unittest.TestCase): >     target = mymodule.someclass > >     def test_spam(self): >         """Test that someclass has a spam

Re: Scalable python dict {'key_is_a_string': [count, some_val]}

2010-02-20 Thread Arnaud Delobelle
On 20 Feb, 06:36, krishna wrote: > I have to manage a couple of dicts with huge dataset (larger than > feasible with the memory on my system), it basically has a key which > is a string (actually a tuple converted to a string) and a two item > list as value, with one element in the list being a co

Re: Pure virtual functions in Python?

2010-02-20 Thread Arnaud Delobelle
lallous writes: > Hello > > How can I do something similar to pure virtual functions in C++ ? > > Let us consider this: > > class C1: > > # Pure virtual > def cb(self, param1, param2): > """ > This is a callback > > @param param1: ... > @param param2: ... >

Re: Efficiently building ordered dict

2010-02-22 Thread Arnaud Delobelle
Bryan writes: > I am looping through a list and creating a regular dictionary. From > that dict, I create an ordered dict. I can't think of a way to build > the ordered dict while going through the original loop. Is there a > way I can avoid creating the first unordered dict just to get the >

Re: Efficiently building ordered dict

2010-02-22 Thread Arnaud Delobelle
On 22 Feb, 21:29, Bryan wrote: > Sorry about the sorted != ordered mix up.  I want to end up with a > *sorted* dict from an unordered list.  *Sorting the list is not > practical in this case.*  I am using python 2.5, with an ActiveState > recipe for an OrderedDict. Why does the dict need to be so

Re: Signature-based Function Overloading in Python

2010-02-23 Thread Arnaud Delobelle
Michael Rudolf writes: > Just a quick question about what would be the most pythonic approach > in this. > > In Java, Method Overloading is my best friend, but this won't work in > Python: > def a(): > pass def a(x): > pass a() > Traceback (most recent call last): > F

Re: Creating variables from dicts

2010-02-23 Thread Arnaud Delobelle
vsoler writes: > Hi, > > I have two dicts > > n={'a', 'm', 'p'} > v={1,3,7} These are sets, not dicts. > and I'd like to have > > a=1 > m=3 > p=7 As sets are unordered, you may as well have a = 3 m = 7 p = 1 or any other permutation. You need some sequences instead. E.g. n = [

Re: while loop with the condition used in the body

2010-02-24 Thread Arnaud Delobelle
Ulrich Eckhardt wrote: > Hi! > > I'm looking for a way to write code similar to this C code: > > while(rq = get_request(..)) { > handle_request(rq); > } > > Currently I'm doing > > while True: > rq = get_request(...) > if not rq: > break > handle_request(rq)

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread Arnaud Delobelle
Nomen Nescio wrote: > Hello, > > Can someone help me understand what is wrong with this example? > > class T: > A = range(2) > B = range(4) > s = sum(i*j for i in A for j in B) > > It produces the exception: > > : global name 'j' is not defined It's due to scoping rules for classes and/or

Re: Spam from gmail

2010-02-24 Thread Arnaud Delobelle
a...@pythoncraft.com (Aahz) writes: > In article <87sk8r5v2f@benfinney.id.au>, > Ben Finney wrote: >>a...@pythoncraft.com (Aahz) writes: >>> >>> Joan Miller is a regular poster; this is off-topic, but it's not spam. >> >>Non sequitur. Spam is spam, not by who authors or posts it, but by its

Re: scope of generators, class variables, resulting in global na

2010-02-24 Thread Arnaud Delobelle
dontspamleo writes: > @Arnaud: I tried to find your earlier post -- googled "Arnaud lambda" > -- but couldn't. I remembered after posting that I sent this to python-ideas. Here is the first message in the thread: http://mail.python.org/pipermail/python-ideas/2007-December/001260.html In this t

Re: Spam from gmail

2010-02-25 Thread Arnaud Delobelle
Steven D'Aprano wrote: > (That last response is aimed at a generic You, not Ben specifically. > Stupid English language, why can't we have a word for generic you?) I thought the word was "one". -- Arnaud -- http://mail.python.org/mailman/listinfo/python-list

Re: Walking lists

2010-02-25 Thread Arnaud Delobelle
lallous wrote: > Hello > > > I am still learning Python, and have a question, perhaps I can shorten > the code: > > L = ( > (1, 2, 3), > (4,), > (5,), > (6, 7) > ) > > for x in L: > print x > > What I want, is to write the for loop, something like this: > > for (first_element, the_res

Re: The best way to check if two lists have identical values

2010-02-25 Thread Arnaud Delobelle
mk wrote: > Hello everyone, > > I have stumbled upon this seemingly trivial problem: the answer is not > there in http://www.python.org/doc/faq/programming/, and googling does > not return many references really (at least for me). > > I have come up with this: > > def qips_identical(q, oldq): >

Re: scope of generators, class variables, resulting in global na

2010-02-25 Thread Arnaud Delobelle
dontspamleo writes: > Hi Arnaud et al, > > Here is the link to the bug report from which the discussion in PEP > 289 was extracted: > > http://bugs.python.org/issue872326 > > It looks like they were fixing a bunch of bugs and that this > discussion was one of the many in that thread. > > Here is

Re: help with Python installation

2010-02-27 Thread Arnaud Delobelle
On 28 Feb, 01:48, gujax wrote: > Hi, > I have been trying to install python on my Win ME system for over two > years - gave up for a while and now I am back with a resolve to solve > the problem. I tried all versions of python but having installation > problems for all. Installation does not proce

Re: Printing the arguments of an attribute in a class

2010-02-28 Thread Arnaud Delobelle
vsoler writes: > I have a class that is a wrapper: > > class wrapper: > def __init__(self, object): > self.wrapped = object > def __getattr__(self, attrname): > print 'Trace: ', attrname > #print arguments to attrname, how? > return getattr(self.wrapped, at

Re: Looking for an Application

2010-03-01 Thread Arnaud Delobelle
Greg Lindstrom writes: > A few months ago there was a post dealing with an application that > would power scripts based on graphical snippets of the screen. > Essentially, the script would "look" for a match with what you pasted > into it. I don't recall the name of the application, but would li

Re: Draft PEP on RSON configuration file format

2010-03-01 Thread Arnaud Delobelle
Erik Max Francis writes: > Patrick Maupin wrote: >> On Feb 28, 9:18 pm, Steven D'Aprano > Wait a minute... if JSON is too >> hard to edit, and RSON is a *superset* of >>> JSON, that means by definition every JSON file is also a valid RSON file. >>> Since JSON is too hard to manually edit, so is R

Re: Generic singleton

2010-03-03 Thread Arnaud Delobelle
mk writes: [...] > hashable > .. > All of Python’s immutable built-in objects are hashable, while no > mutable containers (such as lists or dictionaries) are. > > Well ok, hashable they're not; but apparently at least dict and list > have id()? lists and dicts are not hashable, but their type

Re: Sort Big File Help

2010-03-03 Thread Arnaud Delobelle
MRAB writes: > mk wrote: >> John Filben wrote: >>> I am new to Python but have used many other (mostly dead) languages >>> in the past. I want to be able to process *.txt and *.csv files. >>> I can now read that and then change them as needed – mostly just >>> take a column and do some if-then t

Re: isinstance(False, int)

2010-03-05 Thread Arnaud Delobelle
mk writes: isinstance(False, int) > True isinstance(True, int) > True > > Huh? > issubclass(bool, int) > True > > Huh?! > > Regards, > mk Yes, and: >>> True + False 1 In fact: >>> 1 == True True >>> 0 == False True So what's your question? -- Arnaud -- http://mail

Re: Slicing [N::-1]

2010-03-05 Thread Arnaud Delobelle
Joan Miller writes: > What does a slice as [N::-1] ? > > It looks that in the first it reverses the slice and then it shows > only N items, right? > > Could you add an example to get the same result without use `::` to > see it more clear? > > Thanks in advance >>> l = range(10) >>> l [0, 1, 2,

Re: imap vs map

2010-03-05 Thread Arnaud Delobelle
mk writes: > Hello everyone, > > I re-wrote more "slowly" an example at the end of > http://wordaligned.org/articles/essential-python-reading-list > > > This example finds anagrams in the text file. > > > from itertools import groupby, imap > from operator import itemgetter > > from string i

Re: negative "counts" in collections.Counter?

2010-03-07 Thread Arnaud Delobelle
Vlastimil Brom writes: > Hi all, > I'd like to ask about the possibility of negative "counts" in > collections.Counter (using Python 3.1); > I believe, my usecase is rather trivial, basically I have the word > frequencies of two texts and I want do compare them (e.g. to see what > was added and r

Re: strange behavor....

2010-11-14 Thread Arnaud Delobelle
Steve Holden writes: > On 11/14/2010 8:29 AM, Emile van Sebille wrote: > [...] >> We all know that _everything_ is a disguised method call and we call the >> disguised method call that resembles a statement where the LHS is >> separated from the RHS by a single equals sign assignment. > > I think

<    5   6   7   8   9   10   11   12   >