Re: - Removing Need For Repeated Definition of __str__

2006-04-03 Thread Dylan Moreland
Ilias Lazaridis wrote: > I have some python code which looks similar to this: > > class Car(BaseClass) : >manufacturer = factory.string() >model = factory.string() >modelYear = factory.integer() > >def __str__(self): >return '%s %s %s' % (self.modelYear,

Re: Getting a list of all classes derived from a base class

2006-04-03 Thread Dylan Moreland
Alex Martelli wrote: > Vijairaj R <[EMAIL PROTECTED]> wrote: >... > > class Test: > > do not use old-style classes: they exist ONLY for backwards > compatibility. > > Make you class Test new-style: > > class Test(object): >... > > > and you can call Test.__subclasses__() to get a list of a

Re: Getting a list of all classes derived from a base class

2006-04-02 Thread Dylan Moreland
Vijairaj R wrote: > Hi, > I have a requirement to findout all the classes that are derived from a > single base class. > > This is how I do it currently. > > class Test: > case = [] > > class Test1(Test): > Test.case.append("Test1") > > class Test2(Test): > Test.case.append("Test2") >

Re: general coding issues - coding style...

2006-02-18 Thread Dylan Moreland
calmar wrote: > On 2006-02-18, Diez B. Roggisch <[EMAIL PROTECTED]> wrote: > > - why are these {{{ thingies there? > > markers for folding for vim > http://www.calmar.ws/tmp/sc.png I would look into one of the many Vim scripts which automatically fold most large blocks without the ugly {{{. --

Re: looping over more than one list

2006-02-16 Thread Dylan Moreland
> def lowest(s1,s2): > s = "" > for c1,c2 in [x for x in zip(s1,s2)]: > s += lowerChar(c1,c2) > return s > > but it's hardly any more elegant than using a loop counter, and I'm > guessing it's performance is a lot worse - I assume that the zip > operation is extra work? > > Iain

Re: how to write a C-style for loop?

2006-02-14 Thread Dylan Moreland
John Salerno wrote: > I assume this is the way for loops are written in C, but if it helps to > be specific, I'm referring to C# for loops. The Python for loop seems to > be the same (or similar) to C#'s foreach loop: > > foreach int i in X > > But how would you write a C# for loop in Python? Do y

Re: Splitting a string

2006-02-14 Thread Dylan Moreland
Woops! Thanks for the correction. I was assuming greediness for some reason. Fredrik Lundh wrote: > Dylan Moreland wrote: > > > So I would try something like: > > > > pat = re.compile(r" (?:AND|OR|AND NOT) ") > > pat.split(string) > > footnote: this y

Re: Splitting a string

2006-02-14 Thread Dylan Moreland
Take a look at: http://docs.python.org/lib/node115.html#l2h-878 So I would try something like: pat = re.compile(r" (?:AND|OR|AND NOT) ") pat.split(string) Compile the regular expression with re.IGNORECASE if you like. Nico Grubert wrote: > Dear Python users, > > I'd like to split a string wher

Re: Newbie Q: dynamically assigning object attribute

2006-02-09 Thread Dylan Moreland
No problem. There are, in fact, ugly class-based methods of doing this. You could assign to an instance's __dict__ dictionary, or -- if the class is a new-style class -- you can call the __setattr__(self, name, value) method. -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie Q: dynamically assigning object attribute

2006-02-09 Thread Dylan Moreland
Take a look at the built-in function setattr: http://ftp.python.org/doc/lib/built-in-funcs.html#l2h-64 -- http://mail.python.org/mailman/listinfo/python-list

Re: how to remove using replace function?

2006-02-08 Thread Dylan Moreland
[EMAIL PROTECTED] wrote: > nope didn't work Could you be more specific about the error? Both my example and yours work perfectly on my box. -- http://mail.python.org/mailman/listinfo/python-list

Re: how to remove using replace function?

2006-02-08 Thread Dylan Moreland
I think you want to use the replace method of the string instance. Something like this will work: # See http://docs.python.org/lib/string-methods.html#l2h-196 txt = "an unfortunate in the middle" txt = txt.replace("", "") -- http://mail.python.org/mailman/listinfo/python-list

Re: What editor shall I use?

2006-02-08 Thread Dylan Moreland
Radek Kubicek wrote: > > What editor shall I use if my Python script must contain utf-8 > > characters? > > I use XP > > vim :-) > > > Thank you for reply > > l.b. > > not for all :-) I myself have just begun using vim. Does anyone have any tips/convenient tweaks for python programming with it?

Re: A __getattr__ for class methods?

2006-02-08 Thread Dylan Moreland
Michael Spencer wrote: > Dylan Moreland wrote: > > I'm trying to implement a bunch of class methods in an ORM object in > > order to provide functionality similar to Rails' ActiveRecord. This > > means that if I have an SQL table mapped to the class "Person&quo

A __getattr__ for class methods?

2006-02-08 Thread Dylan Moreland
I'm trying to implement a bunch of class methods in an ORM object in order to provide functionality similar to Rails' ActiveRecord. This means that if I have an SQL table mapped to the class "Person" with columns name, city, and email, I can have class methods such as: Person.find_by_name