Re: Article of interest: Python pros/cons for the enterprise

2008-02-22 Thread Bruno Desthuilliers
Nicola Musatti a écrit : On Feb 22, 9:03 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: Nicola Musatti a écrit : [...] So, yes, your big company is likely to be safer with newbie C++ programmers than with Python newbie programmers. Sorry but I don't buy your arguments. I

Re: PHP Developer highly interested in Python (web development) with some open questions...

2008-02-25 Thread Bruno Desthuilliers
Diez B. Roggisch a écrit : It's also some kind of a Rube Goldberg thingie... http://en.wikipedia.org/wiki/Rube_Goldberg_machine If you're into web applications, better to have a look at Pylons or Django IMHO. You are entitled to your opinion, but calling Zope a Rube-Goldberg-machine is

Re: Function Overloading and Python

2008-02-25 Thread Bruno Desthuilliers
Allen Peloquin a écrit : I have a personal project that has an elegant solution that requires both true multiple inheritance of classes (which pretty much limits my language choices to C++ and Python) and type-based function overloading. Now, while this makes it sound like I have to resign

Re: Newbie: How can I use a string value for a keyword argument?

2008-02-25 Thread Bruno Desthuilliers
Doug Morse a écrit : Hi, My apologies for troubling for what is probably an easy question... it's just that can't seem to find an answer to this anywhere (Googling, pydocs, etc.)... I have a class method, MyClass.foo(), that takes keyword arguments. For example, I can say: x =

Re: Array of functions, Pythonically

2008-02-25 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : My parser has found an expression of the form CONSTANT_INTEGER OPERATOR CONSTANT_INTEGER. I want to fold this into a single CONSTANT_INTEGER. The OPERATOR token has an intValue attribute, '+' == 0, '-'== 1, etc. In C I'd put functions Add, Subtract, ... into an

Re: Return value of an assignment statement?

2008-02-27 Thread Bruno Desthuilliers
Jeff Schwab a écrit : [EMAIL PROTECTED] wrote: What you can't do (that I really miss) is have a tree of assign-and-test expressions: import re pat = re.compile('some pattern') if m = pat.match(some_string): do_something(m) else if m =

Re: Return value of an assignment statement?

2008-02-27 Thread Bruno Desthuilliers
Jeff Schwab a écrit : (snip) This is apparently section 1.9 of the Python Cookbook: http://www.oreilly.com/catalog/pythoncook2/toc.html Martelli suggests something similar to the thigamabob technique I use (he calls it DataHolder). It's really more like the xmatch posted by Paul Rubin.

Re: Return value of an assignment statement?

2008-02-27 Thread Bruno Desthuilliers
Paddy a écrit : On 21 Feb, 23:33, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: What you can't do (that I really miss) is have a tree of assign-and-test expressions: import re pat = re.compile('some pattern') if m = pat.match(some_string): do_something(m)

Re: joining strings question

2008-02-29 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hi all, I have some data with some categories, titles, subtitles, and a link to their pdf and I need to join the title and the subtitle for every file and divide them into their separate groups. So the data comes in like this: data = ['RULES',

Re: Beautiful Code in Python?

2008-03-03 Thread Bruno Desthuilliers
js a écrit : Hi, Have you ever seen Beautiful Python code? Zope? Django? Python standard lib? or else? Please tell me what code you think it's stunning. FormEncode has some very interesting parts IMHO. -- http://mail.python.org/mailman/listinfo/python-list

Re: Exception or not

2008-03-03 Thread Bruno Desthuilliers
Monica Leko a écrit : Suppose you have some HTML forms which you would like to validate. Every field can have different errors. For example, this are the forms: username password etc And you want to validate them with some class. This is what the FormEncode package is for. --

Re: Difference between 'function' and 'method'

2008-03-04 Thread Bruno Desthuilliers
?? a écrit : Howdy everyone, This is a big problem puzzles me for a long time. The core question is: How to dynamically create methods on a class or an instance? class Foo(object): pass def bar(self, arg): print in bar : self == % - arg == %s % (self, str(arg)) def baaz(self,

Re: multiplication of lists of strings

2008-03-05 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) That reminds me: Is there a generic 'relation' pattern/recipie, such as finding a computer that's paired with multiple users, each of who are paired with multiple computers, without maintaining dual- associativity? Yes : use a relational database. --

Re: Using re module better

2008-03-05 Thread Bruno Desthuilliers
Mike a écrit : I seem to fall into this trap (maybe my Perl background) where I want to simultaneously test a regular expression and then extract its match groups in the same action. For instance: if (match = re.search('(\w+)\s*(\w+)', foo)): field1 = match.group(1) field2 =

Re: Altering imported modules

2008-03-05 Thread Bruno Desthuilliers
Tro a écrit : Hi, list. I've got a simple asyncore-based server. However, I've modified the asyncore module to allow me to watch functions as well as sockets. The modified asyncore module is in a specific location in my project and is imported as usual from my classes. Now I'd like to

Re: Checking if a variable is a dictionary

2008-03-06 Thread Bruno Desthuilliers
Guillermo a écrit : Hello, This is my first post here. I'm getting my feet wet with Python and I need to know how can I check whether a variable is of type dictionary. What makes you say you need to know this ? Except for a couple corner cases, you usually don't need to care about this. If

Re: Hi

2008-03-06 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hello can u plz tell how to send and read msg from device(telit-863-GPS) and the coding is in python. if this can happen then plz send the source code to my mail account You'll find relevant code and examples here:

Re: Checking if a variable is a dictionary

2008-03-06 Thread Bruno Desthuilliers
Sam a écrit : Hello if type(a) is dict: print a is a dictionnary! class MyDict(dict): pass a = MyDict() type(a) is dict = False -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking if a variable is a dictionary

2008-03-06 Thread Bruno Desthuilliers
Guillermo a écrit : Wow, I think I'm gonna like this forum. Thank you all for the prompt answers! Welcome onboard !-) What makes you say you need to know this ? Except for a couple corner cases, you usually don't need to care about this. If you told us more about the actual problem (instead

Re: Checking if a variable is a dictionary

2008-03-06 Thread Bruno Desthuilliers
Jeffrey Seifried a écrit : (snip) if type(a)==type({}): print 'a is a dictionary' This instanciates a dict, call type() on it, and discard the dict - which is useless since the dict type is a builtin. Also, when you want to test identity, use an identity test. if type(a) is dict:

Re: What is a class?

2008-03-06 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : And white to play. What does exec( open( 'modA.py' ).read() ) do? RTFM -- http://mail.python.org/mailman/listinfo/python-list

Re: Checking if a variable is a dictionary

2008-03-10 Thread Bruno Desthuilliers
Guillermo a écrit : Mamma mia! My head just exploded. I've seen the light. So you only need to ·want· to have a protocol? That's amazing... Far beyond the claim that Python is easy. You define protocols in writing basically! Even my grandma could have her own Python protocol. Okay, so I

Re: Python PDF + Pictures

2008-03-11 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hi, dear Python Masters! I wanna ask about the Python and PDF creating. I have many photos, and I wanna make some presentation from these photos, a thumbnail like document with one image per one page. If I wanna make one document now I do this: I execute a

Re: Class Inheritance

2008-03-13 Thread Bruno Desthuilliers
Andrew Rekdal a écrit : I am trying to bring functions to a class by inheritance... for instance in layout_ext I have.. --- layout_ext.py- class Layout() def...some function that rely on css in Layout.py It shouldn't, definitively. The Layout instance should have a

Re: List mutation method gotcha - How well known?

2008-03-13 Thread Bruno Desthuilliers
Hendrik van Rooyen a écrit : Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice question - no RTFM, no playing at the interactive prompt: Given the

Re: Is there Python equivalent to Perl BEGIN{} block?

2008-03-13 Thread Bruno Desthuilliers
Alex a écrit : (sni) First of all thanks all for answering! I have some environment check and setup in the beginning of the code. I would like to move it to the end of the script. Why ? (if I may ask...) But I want it to execute first, so the script will exit if the environment is not

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Dave Kuhlman a écrit : Arnaud Delobelle wrote: 4. Both points above follow from the fact that foo.bar is really a function call that returns a (potentially) new object: in fact what really happens is something like Arnaud and Imri, too - No. foo.bar is *not* really a function/method

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Mel a écrit : (snip) (What Diez said.) From what I've seen, f.bar creates a bound method object by taking the unbound method Foo.bar and binding its first parameter with f. Nope. it's Foo.__dict__['bar'] (that is, the function bar defined in the namespace of class Foo) that creates a

Re: getattr(foo, 'foobar') not the same as foo.foobar?

2008-03-14 Thread Bruno Desthuilliers
Erik Max Francis a écrit : Dave Kuhlman wrote: Basically, the above code is saying that foo.foobar is not the same as getattr(foo, 'foobar'). Python promises that the behavior is the same. It does not promise that the _objects_ will be the same, which is what `is` determines. That is,

Re: Need Help Starting Out

2008-03-19 Thread Bruno Desthuilliers
jmDesktop a écrit : Hi, I would like to start using Python, but am unsure where to begin. I know how to look up a tutorial and learn the language, but not what all technologies to use. I saw references to plain Python, Django, and other things. I want to use it for web building with

Re: Prototype OO

2008-03-20 Thread Bruno Desthuilliers
sam a écrit : Some time ago (2004) there were talks about prototype-based languages and Prothon emerged. Can someone tell me why class-based OO is better that Prototype based, For which definition of better ?-) especially in scripting langage with dynamic types as Python is? Here

Re: Prototype OO

2008-03-21 Thread Bruno Desthuilliers
sam a écrit : Bruno Desthuilliers napisał(a): Most of the arguments in favor of prototypes seems to come to, mainly: 1/ it lets you customize behaviour on a per-object base 2/ it removes the mental overhead of inheritance, classes etc Point 1. is a non-problem in Python, since you can

Re: Breaking the barrier of a broken paradigm... part 1

2008-03-25 Thread Bruno Desthuilliers
john s. a écrit : On Mar 24, 9:39 pm, Ryan Ginstrom [EMAIL PROTECTED] wrote: On Behalf Of john s. import os, sys, string, copy, getopt, linecache from traceback import format_exception #The file we read in... fileHandle = /etc/passwd srcFile = open(fileHandle,'r') srcList =

Re: Beta testers needed for a high performance Python application server

2008-03-26 Thread Bruno Desthuilliers
Minor Gordon a écrit : (snip otherwise intersting stuff) Background: I'm in this to help write a story for Python and web applications. Everyone likes to go on about Ruby on Rails, and as far as I can tell there's nothing that approaches Rails in Python. You may have missed Django and

Re: Prototype OO

2008-03-26 Thread Bruno Desthuilliers
sam a écrit : Bruno Desthuilliers napisał(a): In dynamically typed language when you create object A that is inherited from another object B, than object A knows that B is his predecessor. So when you reference A.prop, then prop is looked in A first, then in B, then in predecessors

Re: Partial Function Application and implicit self problem

2008-03-27 Thread Bruno Desthuilliers
Gabriel Rossetti a écrit : Gabriel Rossetti wrote: Hello, I am using Partial Function Application in a class and I've come up with a problem, when the method is called it tries to pass self to the curried/partial function, but this should be the first argument in reality, but since the

Re: A question on decorators

2008-03-27 Thread Bruno Desthuilliers
Tim Henderson a écrit : Hello I am writing an application that has a mysql back end and I have this idea to simplify my life when accessing the database. The idea is to wrap the all the functions dealing with a particular row in a particular in a particular table inside a class. So if you

Re: Why does python behave so? (removing list items)

2008-03-27 Thread Bruno Desthuilliers
Thomas Dybdahl Ahle a écrit : On Wed, 2008-03-26 at 23:04 +0100, Michał Bentkowski wrote: Why does python create a reference here, not just copy the variable? Python, like most other oo languages, will always make references for =, unless you work on native types (numbers and strings).

Re: Partial Function Application and implicit self problem

2008-03-27 Thread Bruno Desthuilliers
Gabriel Rossetti a écrit : Bruno Desthuilliers wrote: Gabriel Rossetti a écrit : (snip) registerServiceAtomic = partial(__registerService, True) registerServiceNonAtomic = partial(__registerService, False) I should pass self when applying partial, but then I can't do that since self

Re: dynimac code with lambda function creation

2008-03-27 Thread Bruno Desthuilliers
Justin Delegard a écrit : So I am trying to pass an object's method call I assume you mean to pass an object's method, since I don't get what passing an object's method call could mean. to a function that requires a function pointer. s/pointer/object/ There's nothing like a pointer in

Re: singleton decorator

2008-03-27 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hallo, playing with the decorators from PEP 318 I found the elegant singleton decorator. def singleton(cls): instances = {} def getinstance(): if cls not in instances: instances[cls] = cls() return instances[cls]

Re: And the reverse? Does os also import os.path?

2008-03-27 Thread Bruno Desthuilliers
Wilbert Berendsen a écrit : If i do import os os.path.abspath(bla) '/home/wilbert/bla' it seems that just import os also makes available al os.path functions. But is that always true? Nope. Not all packages expose their sub-packages. --

Re: Getting back an Object

2008-03-28 Thread Bruno Desthuilliers
Gary Herron a écrit : (snip) One other word of warning. It is best to not use a variable named string as Python has a builtin type of that name which would become inaccessible if you redefine. Good advice, except that the builtin string type is actually named 'str', not 'string' !-) --

Re: Plugins accessing parent state

2008-03-28 Thread Bruno Desthuilliers
André a écrit : On Mar 28, 6:39 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: On Mar 28, 1:58 am, Diez B. Roggisch [EMAIL PROTECTED] wrote: (snip) But to be honest: you are thinking much to far there - after all, it's all *your* code, and inside one interpreter. A real isolation isn't

Re: Newbie Question - Overloading ==

2008-04-01 Thread Bruno Desthuilliers
Duncan Booth a écrit : [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Surely an A isn't equal to every other object which just happens to have the same attributes 'a' and 'b'? And why not ?-) I would have thoughts the tests want to be something like: class A: def __eq__(self,other):

Re: Prototype OO

2008-04-01 Thread Bruno Desthuilliers
sam a écrit : Steven D'Aprano napisał(a): I can see that Python and Javascript inheritance model is almost the same. Both languages are dynamically typed. And it seems that using classes in Python makes some things more complicated then it is necessary (eg functions, methods and lambdas are

Re: Homework help

2008-04-01 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hey guys I haev this homework assignment due today Isn't it a bit too late to worry about it then ? -- http://mail.python.org/mailman/listinfo/python-list

Re: Python in High School

2008-04-01 Thread Bruno Desthuilliers
sprad a écrit : I'm a high school computer teacher, and I'm starting a series of programming courses next year (disguised as game development classes to capture more interest). The first year will be a gentle introduction to programming, leading to two more years of advanced topics. I was

Re: Python in High School

2008-04-01 Thread Bruno Desthuilliers
sprad a écrit : On Apr 1, 11:41 am, mdomans [EMAIL PROTECTED] wrote: Python needs no evangelizing but I can tell you that it is a powerfull tool. I prefer to think that flash is rather visualization tool than programing language, and java needs a lot of typing and a lot of reading. On the

Re: object-relational mappers

2008-04-02 Thread Bruno Desthuilliers
hdante a écrit : On Apr 1, 5:40 pm, Aaron Watters [EMAIL PROTECTED] wrote: I've been poking around the world of object-relational mappers and it inspired me to coin a corellary to the the famous quote on regular expressions: You have objects and a database: that's 2 problems. So: get an

Re: object-relational mappers

2008-04-02 Thread Bruno Desthuilliers
Aaron Watters a écrit : I've been poking around the world of object-relational mappers and it inspired me to coin a corellary to the the famous quote on regular expressions: You have objects and a database: that's 2 problems. So: get an object-relational mapper: now you have 2**3 problems.

Re: Prototype OO

2008-04-02 Thread Bruno Desthuilliers
sam a écrit : Bruno Desthuilliers napisał(a): Sam, seriously, why don't start with *learning* about Python's object model ? Seriously ? Not that it's perfect, not that you have to like it Ok -- thank you for your time and your strong opinions about current solutions. Don't

Re: Python in High School

2008-04-03 Thread Bruno Desthuilliers
Jan Claeys a écrit : (snip) I learned about pointers while learning Pascal (and later embedded assembler) using Borland's tools. Later I learned C (and even later C++), and I've always been wondering why those languages were making simple things so complicated... Similar pattern here :

Re: Prototype OO

2008-04-03 Thread Bruno Desthuilliers
sam a écrit : [EMAIL PROTECTED] napisał(a): So, while I often use Python's lambdas, the imposed limitations is ok to me since I wouldn't use it for anything more complex. Also - as a side note - while the syntax is a bit different, the resulting object is an ordinary function. And

Re: who said python can't be obsfucated!?

2008-04-03 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : def s(c):return[]if c==[]else s([_ for _ in c[1:]if _c[0]])+[c[0]] +s([_ for _ in c[1:]if _=c[0]]) Anyone else got some wonders...? Nothing as bad, but: sig=lambda m:'@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in m.split('@')]) --

Re: What motivates all unpaid volunteers at Pycon?

2008-04-03 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : On Apr 1, 11:45 am, Ed Leafe [EMAIL PROTECTED] wrote: Assuming that people get nothing back by participating in a community, yes, it would be curious. My experience, though, is that I get a lot more out of it than I could ever contribute. IOW, it's a great example

Re: Prototype OO

2008-04-03 Thread Bruno Desthuilliers
sam a écrit : Bruno Desthuilliers napisał(a): Ok, I'm going to be a bit harsh, but this time I'll assume it. Sam, you started this thread by asking about prototype vs class based minor syntactic points that, whether you like them or not (and I think I will get back to this discussion

Re: who said python can't be obsfucated!?

2008-04-03 Thread Bruno Desthuilliers
Marco Mariani a écrit : Bruno Desthuilliers wrote: sig=lambda m:'@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in m.split('@')]) Pff... you call that a quicksort? Nope, only somewhat obfuscated Python. And it seems it's at least obfuscated enough for you to believe

Re: object-relational mappers

2008-04-03 Thread Bruno Desthuilliers
Luis M. González a écrit : I have come to the same conclusion. ORMs make easy things easier, but difficult things impossible... Not my experience with SQLAlchemy. Ok, I still not had an occasion to test it against stored procedures, but when it comes to complex queries, it did the trick so

Re: How easy is it to install python as non-root user?

2008-04-03 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Does python install fairly easily for a non-root user? I have an ssh login account onto a Linux system that currently provides Python 2.4.3 and I'd really like to use some of the improvements in Python 2.5.x. So, if I download the Python-2.5.2.tgz file is it

Re: object-relational mappers

2008-04-03 Thread Bruno Desthuilliers
Jarek Zgoda a écrit : Bruno Desthuilliers napisał(a): Now my own experience is that whenever I tried this approach for anything non-trivial, I ended up building an ad-hoc, informally-specified bug-ridden slow implementation of half of SQLAlchemy. Which BTW is not strictly an ORM

Re: Is there an official way to add methods to an instance?

2008-04-04 Thread Bruno Desthuilliers
Paul Rubin a écrit : Brian Vanderburg II [EMAIL PROTECTED] writes: I've checked out some ways to get this to work. I want to be able to add a new function to an instance of an object. Ugh. Avoid that if you can. Why so ? OO is about objects, not classes, and adding methods on a

Re: Is there an official way to add methods to an instance?

2008-04-04 Thread Bruno Desthuilliers
Peter Otten a écrit : (snip) Anyway, here is one more option to add too the zoo: class A(object): ... def __init__(self, f, x): ... self._f = f ... self.x = x ... @property ... def f(self): ... return self._f.__get__(self) ... def __del__(self):

Re: Python in High School

2008-04-04 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip) I think I agree with all of the positive, supporting posts about Python. I would just like to add that Python (and PyGame) are open source And run on most common platforms AFAIK. and so your students can download it at home and have fun exploring it on

Re: from __future__ import print

2008-04-11 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Am I the only one that thinks this would be useful? :) I'd really like to be able to use python 3.0's print statement in 2.x. nitpick mode=pedantic FWIW, the whole point is that in 3.0, print stop being a statement to become a function... /nitpick --

Re: Java or C++?

2008-04-14 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Hello, I was hoping to get some opinions on a subject. I've been programming Python for almost two years now. Recently I learned Perl, but frankly I'm not very comfortable with it. Now I want to move on two either Java or C++, but I'm not sure which. Which one do

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
andrew cooke a écrit : 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

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit : (snip) As others explained, descriptors are called for descriptors found in class attributes, not in ones in instance attributes. (snip) However, if you know what you're doing, you can simply customize your class's __getattribute__ to do what *you* want for your

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
andrew cooke a écrit : On Apr 15, 4:06 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: The canonical solution is to use a custom descriptor instead of a property: (snip code) i tried code very similar after reading the first replies and found that it did not work as expected

Re: Dynamic use of property() fails

2008-04-15 Thread Bruno Desthuilliers
Hrvoje Niksic a écrit : Bruno Desthuilliers [EMAIL PROTECTED] writes: However, if you know what you're doing, you can simply customize your class's __getattribute__ to do what *you* want for your objects. op But bear in mind that, beside possible unwanted side-effectn, you'll get a non

Re: Image handling - stupid question

2008-04-16 Thread Bruno Desthuilliers
Jumping Arne a écrit : I'm going to try to write some imange manipulation code (scaling, reading EXIF and IPTC info) and just want to ask if PIL is *THE* library to use? I looked at http://www.pythonware.com/products/pil/ and noticed that the latest version is from Dec 2006. In my

Re: Database vs Data Structure?

2008-04-18 Thread Bruno Desthuilliers
erikcw a écrit : Hi, I'm working on a web application where each user will be creating several projects in there account, each with 1,000-50,000 objects. Each object will consist of a unique name, an id, and some meta data. The number of objects will grow and shrink as the user works with

Re: Newbie question about for...in range() structure

2008-04-18 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : (snip - already answered) def fact(n): total = 0 n = int(n) while n 0: total *= n n -=1 return total You may be interested in a very different way to get the same result: from operator import mul def

Re: Metaprogramming Example

2008-04-18 Thread Bruno Desthuilliers
andrew cooke a écrit : 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

Re: Can't do a multiline assignment!

2008-04-18 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : On Apr 17, 12:34 pm, Michael Torrie [EMAIL PROTECTED] wrote: Another thing to consider is that referencing a member of a class or instance already *is* a dictionary lookup. It's how python works. Thus dictionaries are optimized to be fast. Since strings are

Re: str class inheritance prob?

2008-04-18 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : so I’m trying to create a class that inherits from str, but I want to run some code on the value on object init. this is what I have: Others already gave you the technical solution (use __new__, not __init__). A couple remarks still: 1/ class Path(str):

Re: question about the mainloop

2008-04-21 Thread Bruno Desthuilliers
globalrev a écrit : in C?? java etc there is usually: procedure 1 procedure 2 procedure 3 main { procedure 1 procedure 2 procedure 3 } i dont get the mainloop() in python. The 'main' function (resp. method) in C and Java has nothing to do with a mainloop - it's just the program

Re: manipulating class attributes from a decorator while the class is being defined

2008-04-21 Thread Bruno Desthuilliers
Wilbert Berendsen a écrit : Hi, is it possible to manipulate class attributes from within a decorator while the class is being defined? I want to register methods with some additional values in a class attribute. But I can't get a decorator to change a class attribute while the class is

Re: Opposite of repr() (kind of)

2008-04-21 Thread Bruno Desthuilliers
Guillermo a écrit : Hi there, How can I turn a string into a callable object/function? Depends on what's in your string. I have a = 'len', and I want to do: if callable(eval(a)): print callable, but that doesn't quite work the way I want. :) Works here: Python 2.5.1 (r251:54863, May 2

Re: Java or C++?

2008-04-22 Thread Bruno Desthuilliers
hdante a écrit : Summarizing the discussion (and giving my opinions), here's an algorithm to find out what language you'll leard next: 1. If you just want to learn another language, with no other essential concern, learn Ruby. 2. If you want to learn another language to design medium to

Re: Remove multiple inheritance in Python 3000

2008-04-22 Thread Bruno Desthuilliers
GD a écrit : Please remove ability to multiple inheritance in Python 3000. Please dont. Multiple inheritance is bad for design, rarely used and contains many problems for usual users. Don't blame the tool for your unability to use it properly. Every program can be designed only with

Re: Python Success stories

2008-04-22 Thread Bruno Desthuilliers
azrael a écrit : Hy guys, A friend of mine i a proud PERL developer which always keeps making jokes on python's cost. s/proud/stupid/ Please give me any arguments to cut him down about his commnets like :keep programing i python. maybe, one day, you will be able to program in VisualBasic

Re: Remove multiple inheritance in Python 3000

2008-04-22 Thread Bruno Desthuilliers
Carl Banks a écrit : On Apr 22, 10:36 am, George Sakkis [EMAIL PROTECTED] wrote: On Apr 22, 10:22 am, Carl Banks [EMAIL PROTECTED] wrote: Java (for example) allows a class to share behavior with only one other class, and that *severely* limits the opportunities to minimize redundancy. Not

Re: help needed with classes/inheritance

2008-04-23 Thread Bruno Desthuilliers
barbaros a écrit : Hello everybody, I am building a code for surface meshes (triangulations for instance). I need to implement Body objects (bodies can be points, segments, triangles and so on), then a Mesh will be a collection of bodies, together with their neighbourhood relations. I also need

Re: problem with dictionaries

2008-04-23 Thread Bruno Desthuilliers
kdwyer a écrit : On Apr 23, 12:16 pm, Simon Strobl [EMAIL PROTECTED] wrote: (snip) #!/usr/bin/python import sys frqlist = open('my_frqlist.txt', 'r') (snip) frq = {} for line in frqlist: line = line.rstrip() frequency, word = line.split('|') frq[word] = int(frequency) (snip)

Re: help needed with classes/inheritance

2008-04-23 Thread Bruno Desthuilliers
Andrew Lee a écrit : (snip) as a rule of thumb .. if you are using isinstance in a class to determine what class a parameter is ... you have broken the OO contract. Nope. Remember, every class ought to have a well defined internal state and a well defined interface to its state. I don't

Re: @classmethod question

2008-04-24 Thread Bruno Desthuilliers
Scott SA a écrit : Hi, I'm using the @classemethod decorator for some convenience methods and for some reason, either mental block or otherwise, can't seem to figure out how to elegantly detect if the call is from an instance or not. Well, the point is that a classmethod *always* receive the

Re: Python development tools

2008-04-24 Thread Bruno Desthuilliers
Torsten Bronger a écrit : Hallöchen! [EMAIL PROTECTED] writes: On 23 avr, 19:39, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Are there any completely free developent tools for python scripts like IDLE. I have used IDLE , but I want to try out others also. I saw stuff like PyCrust, but I

Re: help needed with classes/inheritance

2008-04-24 Thread Bruno Desthuilliers
barbaros a écrit : On Apr 23, 10:48 am, Bruno Desthuilliers bruno. [EMAIL PROTECTED] wrote: My question is: can it be done using inheritance ? Technically, yes: class OrientedBody(Body): def __init__(self, orient=1): Body.__init__(self) self.orient = 1 Now if it's the right

Re: function that accepts any amount of arguments?

2008-04-24 Thread Bruno Desthuilliers
Paul McNett a écrit : def avg(*args): return sum(args) / len(args) There are some dangers (at least two glaring ones) with this code, though, which I leave as an exercise for the reader. try: avg(toto, 42) except TypeError, e: print this is the first one : %s % e try: avg() except

Re: Python development tools

2008-04-24 Thread Bruno Desthuilliers
Torsten Bronger a écrit : Hallöchen! Bruno Desthuilliers writes: [...] and it ends multi-line strings at single quotes. it chokes on unbalanced single quotes in triple-single-quoted strings, and on unbalanced double-quotes in triple-double-quoted strings, yes. Given that I never use triple

Re: Class Inheritance - What am I doing wrong?

2008-04-25 Thread Bruno Desthuilliers
Brian Munroe a écrit : Ok, so thanks everyone for the helpful hints. That *was* a typo on my part (should've been super(B...) not super(A..), but I digress) I'm building a public API. Along with the API I have a few custom types that I'm expecting API users to extend, if they need too. If I

Re: function that accepts any amount of arguments?

2008-04-28 Thread Bruno Desthuilliers
Lie a écrit : On Apr 25, 2:12 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: (...) FWIW, I'd personnaly write avg as taking a sequence - ie, not using varargs - in which case calling it without arguments would a TypeError (so BTW please s/Value/Type/ in my previous post). The problem with

Re: list.reverse()

2008-04-29 Thread Bruno Desthuilliers
Mark Bryan Yu a écrit : This set of codes works: x = range(5) x.reverse() x [4, 3, 2, 1, 0] But this doesn't: x = range(5).reverse() print x None This works just as expected - at least for anyone having read the doc. Please explain this behavior. range(5) returns a list from 0 to 4

Re: Given a string - execute a function by the same name

2008-04-29 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : I'm parsing a simple file and given a line's keyword, would like to call the equivalently named function. There are 3 ways I can think to do this (other than a long if/elif construct): 1. eval() 2. Convert my functions to methods and use getattr( myClass, method

Re: list.reverse()

2008-04-29 Thread Bruno Desthuilliers
Roy Smith a écrit : (snip) The reasoning goes along the lines of, reverse in place is an expensive operation, so we don't want to make it too easy for people to do. At least that's the gist of what I got out of the argument the many times it has come up. IIRC, it's more along the line of

Re: @classmethod question

2008-04-30 Thread Bruno Desthuilliers
Scott SA a écrit : On 4/24/08, Bruno Desthuilliers ([EMAIL PROTECTED]) wrote: It is a series of convenience methods, in this case I'm interacting with a database via an ORM (object-relational model). out of curiosity : which one ? I'm rapidly becoming a django junkie^TM (snip

Re: Problem with variables assigned to variables???

2008-04-30 Thread Bruno Desthuilliers
n00m a écrit : for listmember in mylist: print listmember + .shp, eval(listmember) eval and exec are almost always the wrong solution. The right solution very often implies a dict or attribute lookup, either on custom dict or on one of the available namespaces (globals(), locals(), or a

Re: best way to host a membership site

2008-04-30 Thread Bruno Desthuilliers
Magdoll a écrit : Hi, I know this is potentially off-topic, but because python is the language I'm most comfortable with and I've previously had experiences with plone, I'd as much advice as possible on this. I want to host a site where people can register to become a user. They should be

Re: printing inside and outside of main() module

2008-04-30 Thread Bruno Desthuilliers
Peter Otten a écrit : korean_dave wrote: This allows me to see output: ---begin of try.py print Hello World --end of try.py This DOESN'T though... --begin of try2.py def main(): return Hello main() # add this --end of try2.py Can someone explain why??? Python doesn't call the main()

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