Re: Replace one element of a tuple (LONG)

2006-06-02 Thread Bruno Desthuilliers
Captain Dondo a écrit : (snip) > c=masterDB.cursor() > c.execute("""SELECT title, subtitle, starttime FROM recorded""") > > # build our dialog checkbox > > d = dialog.Dialog(dialog="dialog") > d.add_persistent_args(["--backtitle", "Myth2Go"]) > > recordings=[] > for listing in c.fetchall(): >

Re: Initializing an attribute that needs the object

2006-06-02 Thread Bruno Desthuilliers
David Pratt a écrit : > Hi. I want to have different handlers to do perform logic. The problem > is the Handler requires an instance of the factory since it will use its > own methods in conjunction with methods of the factory. > > Once I have got a Factory instance I can give it a new handler (

Re: Initializing an attribute that needs the object

2006-06-03 Thread Bruno Desthuilliers
David Pratt a écrit : David, please, don't top-post (fixed) > > Bruno Desthuilliers wrote: > (snip) >> >> Hint : Python classes are objects too. >> >> >> class Factory(object): >>def __init__(self, handler_class): >> self.hand

Re: after del list , when I use it again, prompt 'not defined'.how could i delete its element,but not itself?

2006-06-03 Thread Bruno Desthuilliers
Piet van Oostrum a écrit : >>SuperHik <[EMAIL PROTECTED]> (S) escribió: > > >>S> [EMAIL PROTECTED] wrote: >> python wrote: >after del list , when I use it again, prompt 'not defined'.how could i >delete its element,but not itself? This is a way: >>>a = range

Re: re beginner

2006-06-04 Thread Bruno Desthuilliers
SuperHik a écrit : > hi all, > > I'm trying to understand regex for the first time, and it would be very > helpful to get an example. I have an old(er) script with the following > task - takes a string I copy-pasted and wich always has the same format: > > >>> print stuff > Yellow hat2

Re: re beginner

2006-06-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : >>strings = islice(data2, 0, len(data), 2) >>numbers = islice(data2, 1, len(data), 2) > > > This probably has to be: > > strings = islice(data2, 0, len(data2), 2) > numbers = islice(data2, 1, len(data2), 2) try with islice(data2, 0, None, 2) -- http://mail.python.or

Re: mutable member, bug or ...

2006-06-04 Thread Bruno Desthuilliers
Sambo a écrit : > By accident I assigned int to a class member 'count' which was > initialized to (empty) string and had no error till I tried to use it as > string, obviously. Why was there no error on assignment( near the end ). Python is dynamically typed - which means that it's not the name

Re: [OT] in python , could I accomplish the purpose that "a=Console.read()" used in C?

2006-06-04 Thread Bruno Desthuilliers
python a écrit : > in python , could I accomplish the purpose that "a=Console.read()" used > in C? There's nothing like "Console.read()" in ansi-C. (see Dennis's post for the answer to your question) -- http://mail.python.org/mailman/listinfo/python-list

Re: Proposed new PEP: print to expand generators

2006-06-04 Thread Bruno Desthuilliers
James J. Besemer a écrit : > (snip) > > PEP -- EXTEND PRINT TO EXPAND GENERATORS > > NUTSHELL > > I propose that we extend the semantics of "print" such that if the > object to be printed is a generator then print would iterate over the > resulting sequence of sub-objects and recursively prin

Re: Using print instead of file.write(str)

2006-06-04 Thread Bruno Desthuilliers
Tim Roberts a écrit : > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > > >>Sion Arrowsmith a écrit : >> (snip) >>>"more flexible"? More convenient, yes. More powerful, maybe. But I >>>don't see more flexible. Everything print can t

Re: Using print instead of file.write(str)

2006-06-04 Thread Bruno Desthuilliers
John Machin a écrit : (snip) > ... or was that a rhetorical question? It was. -- http://mail.python.org/mailman/listinfo/python-list

Re: integer to binary...

2006-06-04 Thread Bruno Desthuilliers
Grant Edwards a écrit : > On 2006-06-02, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > >>Grant Edwards a écrit : >> >>>On 2006-06-01, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: >>> >>>>does anyone know a module or something to con

Re: re beginner

2006-06-05 Thread Bruno Desthuilliers
John Machin a écrit : > On 5/06/2006 10:38 AM, Bruno Desthuilliers wrote: > >> SuperHik a écrit : >> >>> hi all, >>> (snip) >>> I have an old(er) script with the >>> following task - takes a string I copy-pasted and wich always has the

Re: check for dictionary keys

2006-06-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > hi > in my code, i use dict(a) to make to "a" into a dictionary , "a" comes > from user input, so my program does not know in the first place. Then > say , it becomes > > a = { '-A' : 'value1' , '-B' : "value2" , "-C" : "value3" , '-D' : > 'value4' } > > somewhere ne

Re: re beginner

2006-06-05 Thread Bruno Desthuilliers
Fredrik Lundh a écrit : > John Machin wrote: > >> Fantastic -- at least for the OP's carefully copied-and-pasted input. >> Meanwhile back in the real world, there might be problems with >> multiple tabs used for 'prettiness' instead of 1 tab, non-integer >> values, etc etc. > > > yeah, that's

Re: in python , could I accomplish the purpose that "a=Console.read()" used in C?

2006-06-05 Thread Bruno Desthuilliers
Ravi Teja a écrit : > Bruno Desthuilliers wrote: > >>python a écrit : >> >>>in python , could I accomplish the purpose that "a=Console.read()" used >>>in C? >> >> >>There's nothing like "Console.read()" in ansi-

Re: Adding attribute to objetcs

2006-06-05 Thread Bruno Desthuilliers
faulkner a écrit : (please, don't top-post - corrected) > > Miguel Galves wrote: > >>Hello, >> >>I`m starting to learn python, and I hava a very good background in Java >>and C/C++ programming. I was reading Dive into python chapter about >>OO and I saw that in python we can do the following: >>

Re: follow-up to FieldStorage

2006-06-05 Thread Bruno Desthuilliers
John Salerno a écrit : > If I want to get all the values that are entered into an HTML form and > write them to a file, is there some way to handle them all at the same > time, or must FieldStorage be indexed by each specific field name? AFAIK, FieldStorage is a somewhat dict-like object, but I'

Re: strategy pattern and non-public virtual functions

2006-06-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Hi python experts > > In C++ I can do something like this: > class Base { > public: > void f() { this->f_(); } > private: > virtual void f_() = 0; > }; > > class Derived : public Base { > private: > void f_() { // Do something } > }; > > int main()

Re: [OT] Most elegant way to generate 3-char sequence

2006-06-12 Thread Bruno Desthuilliers
John Machin a écrit : > On 10/06/2006 7:49 AM, Rob Cowie wrote: (snip) >> >> def generator(): >> for char in alpha: > > > Why stop at two spaces? One-space indentation is syntactically correct :-) I very often uses 2-spaces indent when posting here, to avoid problems with wrapping. -- http:

Re: Most elegant way to generate 3-char sequence

2006-06-12 Thread Bruno Desthuilliers
James Stroud a écrit : > SuperHik wrote: > >> and the winner is... :D >> David Isaac wrote: >> >>> alpha = string.lowercase >>> x=(a+b+c for a in alpha for b in alpha for c in alpha) >> >> >> >> > > Not necessarily vying for winner, but David's solution is highly > specific as it doesn't do so w

Re: Iteration over recursion?

2006-06-20 Thread Bruno Desthuilliers
Nick Maclaren wrote: (snip) > Tail recursion removal can often eliminate the memory drain, but the > code has to be written so that will work - and I don't know offhand > whether Python does it. It doesn't. Technical possible, but BDFL's decision... -- bruno desthu

Re: [OT] code is data

2006-06-20 Thread Bruno Desthuilliers
simply dismiss my ideas with 'you can already do that easily > with this standard python construct'. This strategy was also eloquently > refuted by some other poster, so I don't need to repeat it :-) > > I've gotten a lot of things to think about, so thanks

Re: Iteration over recursion?

2006-06-20 Thread Bruno Desthuilliers
Sudden Disruption a écrit : > Bruno, > > >>It doesn't. Technical possible, but BDFL's decision... > > > Sure. But why bother? Because I do like recursion, and would personnally prefer tail-recursion optimisation over nice tracebacks. But I'm not in position to decide anything here. > Anyth

Re: __getattribute__ doesn't work on 'type' type for '__class__'

2006-06-20 Thread Bruno Desthuilliers
Barry Kelly a écrit : > I'm running this version of Python: > > Python 2.4.3 (#1, May 18 2006, 07:40:45) > [GCC 3.3.3 (cygwin special)] on cygwin > > I read in the documentation that these two expressions are > interchangeable: > > x.__getattribute__('name') <==> x.name I wouldn't say th

Re: Newbie Question

2006-06-20 Thread Bruno Desthuilliers
Saint Malo a écrit : > BTW my program isn't about red blue yellow etc. I'm just using it as > an example. I guess i didn't asked the question correctly or am not > expressing myself correctly. Let me try one more. > > Ok. > > Contents of text file follow: > > red blue purble > yellow blue gr

Re: Python is fun (useless social thread) ;-)

2006-06-21 Thread Bruno Desthuilliers
gt; I appreciate the tips. I'll do a couple tutorials and read my books and > then come back with any OO questions. You're welcome. FWIW, a good exercice would be to take one of your own programs and try to gradually transform dicts+related funcs to classes. My 2 cents -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: separation events

2006-06-21 Thread Bruno Desthuilliers
se of > sqlalchemy is a good thing? > Thanks a lot > > Ghido > -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: What's the best way to wrap a whole script in try..except?

2006-06-21 Thread Bruno Desthuilliers
;notifyme(traceback) > Would work, but... > How you you handle this? I don't put the main logic at the top level - I use a main() function. import def notifyme(e): # code here... def main(*args): try: # code here return 0 except Exception, e: notifyme(e) re

Re: How to override the doc of an object instance.

2006-06-21 Thread Bruno Desthuilliers
> or is it a bad coding habit to embed > objects inside classes ? Since everything in Python is OO (classes, functions and modules included), I fail to see how one could do otherwise... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w

Re: python + postgres psql + os.popen

2006-06-22 Thread Bruno Desthuilliers
db modules ? > can anyone help me? http://www.python.org/dev/peps/pep-0249/ http://initd.org/projects/psycopg1 -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Is it possible to split a class definition?

2006-06-22 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > Hi, > > Is it possible to split a Class definition over two or more text files? Yes, but not directly. Could you tell us why you think you have such a need ? > (if so, how:) Please answer my previous question first !-) -- bruno desthuilliers pyth

Re: Help req: Problems with MySQLdb

2006-06-22 Thread Bruno Desthuilliers
etting the program crash with full traceback would be much much better - at least you'd have a chance to get some usefull informations about what went wrong. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Registry of Methods via Decorators

2006-06-22 Thread Bruno Desthuilliers
go thru all this mess ? class DeadSimple(object): @classmethod def methods(cls): return [name for name in dir(cls) \ if not name.startswith('__') \ and callable(getattr(cls, name))] My 2 cents... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: VPW: T-Shirt design contest

2006-06-22 Thread Bruno Desthuilliers
Brian Quinlan wrote: > Bruno Desthuilliers submitted this really cool rant/essay/something from > Tim Lesher that I hadn't seen before. I think that the original source is: > > http://apipes.blogspot.com/2005/01/choose-python.html > (snip) > I think that it might be a

Re: Quick Question

2006-06-22 Thread Bruno Desthuilliers
xkenneth a écrit : > I want to be able to cycle through an array and print something in > hexadecimal. Such as this > thisArray = ["AF","0F","5F"] > for x in range(len(thisArray)): >print "\x" + thisArray[x] > > However python chokes on the escaped identifier, how can I get around > th

Re: Status of optional static typing in Python?

2006-06-22 Thread Bruno Desthuilliers
Christian Convey a écrit : > Hi guys, > > I'm looking at developing a somewhat complex system, and I think some > static typing will help me keep limit my confusion. Then I think you're suffering from an alas too common delusion. Static typing (at least declarative static typing) will only ma

Re: Specifing arguments type for a function

2006-06-22 Thread Bruno Desthuilliers
George Sakkis a écrit : > Maric Michaud wrote: > > >>Le Mardi 20 Juin 2006 13:28, Maric Michaud a écrit : >> >>>if not getattr(arg, '__iter__') and not getattr(arg, '__getitem__') : >>>raise ValueError('Function accepts only iterables') # or error handling >>>code >> >>oops, hasattr of course

Re: Network Programming in Python

2006-06-22 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I have Python 2.4.2 on windows and Linux both. I got an import error. > how can we obtain the twisted libraries ? Is google down ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Status of optional static typing in Python?

2006-06-22 Thread Bruno Desthuilliers
Christian Convey a écrit : > Perhaps I'm deluded but I don't think so. . You are. > I'll tell you my situation > and I'd appreciate your take on it... > > I'm looking into the design a network simulator. The simulator has a > few requirements: > > (1) I need to be able to swap in a variety

Re: Help req: Problems with MySQLdb

2006-06-23 Thread Bruno Desthuilliers
he same result - with a more accurate error message - by not handling the exception at all. > > It's generally very difficult to figure out what's going wrong without > the traceback in front of you. indeed. > Also, try an empty string (i.e. "") as your hostname,

Re: Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

2006-06-23 Thread Bruno Desthuilliers
ing dumb. From what I see here, you just can add the extra informations on the object in the initializer. What's your *real* use case ? -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Using metaclassed to dynamically generate a class based on a parameter to the objects init function.

2006-06-23 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > Bruno Desthuilliers wrote: > >>[EMAIL PROTECTED] wrote: >> >>>Hi >>> >>>I'd like to use metaclasses to dynamically generate a class based on a >>>parameter to the objects init function. >> >>Do yo

Re: * in Python

2006-06-23 Thread Bruno Desthuilliers
/ref/calls.html >>and http://docs.python.org/ref/function.html > > > so * basically means that args is a list A tuple IIRC > containing more arguments that > can change in size, whereas ** means that args is a dictionary of > key=value arguments? > Why don&

Re: Specifing arguments type for a function

2006-06-23 Thread Bruno Desthuilliers
you used (ie strings and tuples), it's quite easy to detect'em without testing the concrete type. As you said, what is to be considered as scalar and what's to be considered as sequence highly depends on the problem at hand. But doing the distinction does not always implies tes

Re: Specifing arguments type for a function

2006-06-23 Thread Bruno Desthuilliers
.. > > > Applications that don't need to treat strings as iterables of > characters wouldn't do so even if strings were mutable. Atomicity has > to do with whether something is considered to be composite or not, not > whether it can be modified. Sure. Do you have any generic

Re: code is data

2006-06-23 Thread Bruno Desthuilliers
rammers without browsers > needing to understand Python. Like Jython, but now as separately > distributed functions from different servers. > > Anton -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in

Re: * in Python

2006-06-23 Thread Bruno Desthuilliers
Duncan Booth wrote: > Bruno Desthuilliers wrote: > > >>>so * basically means that args is a list >> >>A tuple IIRC > > > In a function definition * means that any remaining position arguments will > be passed in as a tuple. In a function call the * m

Re: * in Python

2006-06-23 Thread Bruno Desthuilliers
placid wrote: > Bruno Desthuilliers wrote: > (snip) >>Why don't you try by yourself in the Python shell ? One of the nice >>things with Python is that it's quite easy to explore and experiment. > > > i did try it in a Python shell after i learnt what it wa

Re: what exceptions may file() and read() throw?

2006-06-23 Thread Bruno Desthuilliers
;KeyboardInterrupt. More obscurely, if you reused file as a global variable >>you could generate any exception at all. > > > I undestand now, so it would be better to let it in the code > in case it's triggered Nope. Let it propagate, so you have a full traceback. traceb

Re: Python in HTML

2006-06-23 Thread Bruno Desthuilliers
abase, but rather for a functional script to be called when a user > clicks on a link to open a page. If it's client-side scripting, javascript is the only option. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.&

Re: templating languages for webdev

2006-06-24 Thread Bruno Desthuilliers
a wrote: > cheetah vs django vs kid You forgot SimpleTal and Myghty (and many others). I don't like cheetah's syntax at all. I'm not in love with Django templates choices for markup ( '{% tag %}' and '{{ var }}'), but it can be customised, and I found the

Re: Python web server

2006-06-24 Thread Bruno Desthuilliers
nds on your web server. But there's very probably all the needed documention somewhere, and I'm pretty confident google will find it. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROT

Re: Mix-In Class Methods At Run-Time

2006-06-26 Thread Bruno Desthuilliers
it the other way round : the *only* benefit of oldstyle classes is compatibility with pre-2.2 Python versions. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: error with string (beginner)

2006-06-26 Thread Bruno Desthuilliers
'')" stuff - use isinstance(something, basestring) instead. > else: print "I am an impostor!" > [/code] (snip) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Python question

2006-06-26 Thread Bruno Desthuilliers
FWIW, it *is* a list of tuples. > What command What's a 'command' ? > do I use to get the value corresponding to 'min'? (see below...) > This object seems to be non-indexable It is - just like any other list. Try : print row[0] print row[1] # etc... Now if y

Re: About python 2.5 and its try statement.

2006-06-26 Thread Bruno Desthuilliers
onical use case is resource aquisition/release. > Or have I understood > something wrong? Seems so - unless it's me misunderstading your question. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Mix-In Class Methods At Run-Time

2006-06-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] wrote: > Bruno Desthuilliers wrote: > >>[EMAIL PROTECTED] wrote: (snip) >>>and 2) what's the reason to use newstyle classes >>>versus the old? >> >>All this is explained on python.org (there's a menu entry for this in >&g

Re: Replace Whole Object Through Object Method

2006-06-26 Thread Bruno Desthuilliers
> Okay, so the mixin function becomes part of whatever class I choose and > hence its instances, but the problem is that the way I currently have > it setup mixin() returns a new object, instead of replacing whatever > class instance that calls it into that new object. I hope I'

Re: Replace Whole Object Through Object Method

2006-06-26 Thread Bruno Desthuilliers
..) # code here def mix(cls, mixincls): for name in dir(mixincls): attr = getattr(mixincls, name) if callable(attr) and mixable(attr): setattr(cls, name, attr) Of course, one can do much better... -- bruno desthuilliers python -c "print '@'.join(['

Re: Replace Whole Object Through Object Method

2006-06-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Bruno Desthuilliers wrote: (snip) >> >>Instead of exposing problems with your solution, you may want to expose >>the real use case ? > > > I'm working with a team that's doing social modeling, and for example, > I need

Re: replace a method in class: how?

2006-06-26 Thread Bruno Desthuilliers
Brian Blais a écrit : > Hello, > > I want to replace a method in a class during run-time with another > function. I tried the obvious, but it didn't work: > > class This(object): > def update(self,val): > print val > > def another_update(obj,val): > print "another",val > > t=T

Re: Replace Whole Object Through Object Method

2006-06-26 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > Bruno Desthuilliers wrote: > >>[EMAIL PROTECTED] a écrit : >> >>>Bruno Desthuilliers wrote: >> >>(snip) >> >>>>Instead of exposing problems with your solution, you may want to expose >>>>the r

Re: replace a method in class: how?

2006-06-26 Thread Bruno Desthuilliers
Maric Michaud a écrit : > Le mardi 27 juin 2006 05:05, Bruno Desthuilliers a écrit : > >>import types >>t.update = types.MethodType(another_update) > > > This works with : > > t.update = types.MethodType(another_update, t) oops ! too fast on the send button

Re: replace a method in class: how?

2006-06-26 Thread Bruno Desthuilliers
Maric Michaud a écrit : (snip) > In OOP Methods are defined in *classes* not in any arbitrary object Chapter and verse, please ? AFAIK, the first O in OOP stands for "object", not for "class" !-) Classes are just an implementation convenience, and the fact that the class-based model is the mos

Re: Replace Whole Object Through Object Method

2006-06-27 Thread Bruno Desthuilliers
lic dependancy between the object and it's roles, so you would have to use weakrefs. Dynamically creating new classes with the appropriate bases and assigning them to the object's __class__ attribute is another way to achieve the same result, and it's perfectly legal. Now I do agre

Re: replace a method in class: how?

2006-06-27 Thread Bruno Desthuilliers
Maric Michaud wrote: > Le mardi 27 juin 2006 06:21, Bruno Desthuilliers a écrit : > >>Maric Michaud a écrit : >>(snip) >> >> >>>In OOP Methods are defined in *classes* not in any arbitrary object >> >>Chapter and verse, please ? AFAIK, the f

Re: Replace Whole Object Through Object Method

2006-06-27 Thread Bruno Desthuilliers
gt; for role in self.roles: > try: > return getattr(role, attr) > except AttributeError: > pass > raise AttributeError(attr) This could as well be directly in __getattr__, and

Re: classes and interfaces

2006-06-27 Thread Bruno Desthuilliers
ritance or interface here. Note that we do have something like interfaces (in some third-part librairies), but with a somewhat different (and much more powerful) usage: http://peak.telecommunity.com/protocol_ref/ref.html But if you're new to OO, this may not be the best starting point !-)

Re: Replace Whole Object Through Object Method

2006-06-27 Thread Bruno Desthuilliers
Fredrik Lundh wrote: > Bruno Desthuilliers wrote: > > >>As a matter of fact, in Python, the class is an attribute of an object. > > > except when it isn't. Which are the cases where it isn't ? > >>>def add_role(self, role_class): >>>

Re: pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-27 Thread Bruno Desthuilliers
;local') # works fine > t.update2('python') # works fine > t.update3('pyrex') # gives a typeerror function takes exactly 2 > arguments (1 given) (snip) > > any ideas why the pyrex function fails? > I don't have much knowledge wrt/ pyrex, but I gu

Re: Python is fun (useless social thread) ;-)

2006-06-27 Thread Bruno Desthuilliers
ction Nope - and the site seems to be down actually. But thanks for the pointer anyway. > Thanks for the tip, Welcome to OO !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Unbound Local error? How?

2006-06-27 Thread Bruno Desthuilliers
y the error message. The traceback contains all needed informations (or at least all possible information at this point) to know what happened. But you did not post the traceback. Nor did you post the minimal runnable code snippet producing this error. > > How? How could we know ?

Re: file writing question

2006-06-27 Thread Bruno Desthuilliers
pen('computer_details.txt'): name, mac, ip = line.strip().split(':') # ... > Is there a neat way of writing to a file and not having "\n" ? Yes : don't add the newline after every line. But note that this may make the file a bit more difficult to

Re: [Pyrex] pyrex functions to replace a method (Re: replace a method in class: how?)

2006-06-28 Thread Bruno Desthuilliers
ls is not None) return self.func >>> class Foo(object): pass ... >>> Foo.isa = CFuncMethodType(isinstance) >>> Foo.isa(Foo(), Foo) True >>> f.isa(list) False >>> f.isa(Foo) True >>> -- bruno desthuilliers python -c "pri

Re: global name is not defined - error

2006-06-28 Thread Bruno Desthuilliers
nt map(func, arrayOfStrings) print "solution 2: with list comprehension" print [func(s) for s in arrayOfStrings] -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: how do i make an array global

2006-06-28 Thread Bruno Desthuilliers
l here. Also, and FWIW: - Python has lists, not arrays (there's an array type in some numerical package, but that's another beast) - 'l' is a very bad name - 'count' is a bad name for a list - 'counts' would be better (when I see the name 'count', I

Re: a class variable question

2006-06-28 Thread Bruno Desthuilliers
> def getvarValue(self): # return _var1 return self.__class__._var1 > I wanted var1 to be "global" inside Class A. The name is "class attribute". -- bruno desthuilliers python -c "print '@'.join(['.'.join([

Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
te >>> > The nearest approach to the > latter is to use the name hiding conventions. naming conventions are used to denote what's API and what's implementation. But this won't make an attribute read-only. If you want an attribute to be part of the API *but* read-o

Re: how do i make an array global

2006-06-28 Thread Bruno Desthuilliers
Georg Brandl wrote: > Bruno Desthuilliers wrote: > >>a wrote: >> >>>def fn(): >>> for i in range(l) >> >>l is not defined - you should have an error here. >> >> >>> global count >>> count[i]= ..

Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
> class alf : > def pete (self) : > print "Inside pete\n" > > b = alf() > b.pete() > > class fred : > @property > def joe (self) : > print "Inside /joe\n" properties dont work properly on old-style classes (lookup 

Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
Fredrik Lundh wrote: > Bruno Desthuilliers wrote: > > >>>class fred : >>>@property >>>def joe (self) : >>>print "Inside /joe\n" >> >> >>properties dont work properly on old-style classes (lookup 'new

Re: Generator naming convention?

2006-06-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > I use generators a lot. E.g. > > > def gen_words(text) > ... parse text ... > yield each word in text > > for word in gen_words(text): > print word > > > I don't like the name gen_xxx() very much. Nor do I. > Looking for some inspiration > to name generato

Re: Function to prune dictionary keys not working

2006-06-28 Thread Bruno Desthuilliers
Girish Sahani a écrit : > hi ppl, > Here is a simple function to remove those keys of a dictionary whose > values are less than some specified value. > > But it isnt working. "is not working" is the worst possible description of a problem. > def prune(d,cp): > l = [] > for rule,value in

Re: curiosity about the nature of identity (in python)

2006-06-28 Thread Bruno Desthuilliers
James Stroud a écrit : > Hello all, > > What /is/ identity in python? A unique identifier associated with each and every object in the process. What exactly is this identifier is left to the implementation - FWIW and IIRC, CPython uses the memory address of the C 'object' datastructure. > For

Re: for and while loops

2006-06-28 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : > i was wondering if anyone could point me to some good reading about the > for and while loops There's not much to say. while : will execute as long as is True. for in : will execute for each in . ie : for letter in ["a", "b", "c"]: do_something_wi

Re: Module executed twice when imported!

2006-06-28 Thread Bruno Desthuilliers
Michael Abbott a écrit : > It seems to be an invariant of Python (insofar as Python has invariants) > that a module is executed at most once in a Python session. I have a > rather bizzare example that breaks this invariant: can anyone enlighten > me as to what is going on? > > --- test.py ---

Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
Georg Brandl a écrit : > Nick Maclaren wrote: > >>In article <[EMAIL PROTECTED]>, >>"Fredrik Lundh" <[EMAIL PROTECTED]> writes: >>|> >>|> identical? you only applied @property to one of the methods, and then >>you're >>|> surprised that only one of the methods were turned into a property? >> >>

Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
Georg Brandl a écrit : > Steve Holden wrote: > > Thanks very much. And, what's more, I have even found its documentation! Whatsnew2.2. The 2.4.2 reference is, er, unhelpful. >>> >>> >>>Is it? >>> >>>http://docs.python.org/lib/built-in-funcs.html >>> >>>documents "property" quite well. >

Re: Immutability

2006-06-28 Thread Bruno Desthuilliers
Bruno Desthuilliers a écrit : > Georg Brandl a écrit : (snip) >> >> That's another sign that property isn't intended to be used as a >> decorator. >> Normally, decorators wrap functions with other functions. > > > Normally, decorators t

Re: for and while loops

2006-06-28 Thread Bruno Desthuilliers
Bayazee a écrit : > hi > > #Exercise 1 : > s=0 > while 1: > s+=input("Enter a num : ") > if s>=100: > print "The sum is greater than 100 : ",s > break Why do you manually check the condition when the construct is meant to take care of it ? the_sum = 0 while the_sum < 100: try:

Re: Python decompiler

2006-06-29 Thread Bruno Desthuilliers
vailable source distribution. -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Icono en wxpython

2006-06-29 Thread Bruno Desthuilliers
i wxPython, des microcontrolleurs, et des transmission RS232. Peut-être que si tu postais la question in English, ça aiderait un peu ?-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/mailman/listinfo/python-list

Re: Way for see if dict has a key

2006-06-30 Thread Bruno Desthuilliers
Michele Petrazzo wrote: > Hi ng, > what the preferred way for see if the dict has a key? > We have a lot of solutions: > > key in dict > key in dict.keys() > dict.has_key(key) > ... try: dict[key] except KeyError: ... else: ... > but what the better Depends

Re: Way for see if dict has a key

2006-06-30 Thread Bruno Desthuilliers
looping wrote: > Michele Petrazzo wrote: > >>Bruno Desthuilliers wrote: >> >>>>but what the better >>> >>>Depends on the context. >>> >> >>If know only one context: see if the key are into the dict... What other >>con

Re: Way for see if dict has a key

2006-06-30 Thread Bruno Desthuilliers
n. FWIW, I personaly didn't meant to present it as an optimisation - just as one more possible way to test the existence of a given key... > now, if the OP had been interested in the associated value, things might have > been a bit different. > > > > > -- bru

Re: list comprehension

2006-06-30 Thread Bruno Desthuilliers
r or visitor pattern ? I'd say it's bad style to call a function having side effects from within a list comp. List comps have a very declarative/functional style, while side effects are clearly on the imperative side. I never took time to think about this, but IIRC I've never

Re: Way for see if dict has a key

2006-06-30 Thread Bruno Desthuilliers
Fredrik Lundh wrote: > Bruno Desthuilliers wrote: > >>> on my machine, "key in dict" is about twice as fast as the full > >>> try/getitem construct when the key is present in the dict, > >> >> Doesn't it depends on the number of keys i

Re: Way for see if dict has a key

2006-06-30 Thread Bruno Desthuilliers
Georg Brandl wrote: > Bruno Desthuilliers wrote: > >> looping wrote: >> >>> Michele Petrazzo wrote: >>> >>>> Bruno Desthuilliers wrote: >>>> >>>>>> but what the better >>>>> >>>>> >

Re: Way for see if dict has a key

2006-06-30 Thread Bruno Desthuilliers
Fredrik Lundh wrote: > Bruno Desthuilliers wrote: > >> Seems that if "key in dict" do a simple linear search > > > that would be rather silly. > > hint: http://pyref.infogami.com/__contains__ Of course. It's just me being silly... :( Thanks

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