Re: namespaces

2005-07-31 Thread George Sakkis
Paolino wrote: > Steven D'Aprano wrote: > > > def translate(text): > > import string > > all=string.maketrans('','') > > badcars=all.translate(all,string.letters+string.digits) > > table=string.maketrans(badcars,'_'*len(badcars)) > > return text.translate(table) > > > > No pollu

Re: namespaces

2005-08-01 Thread George Sakkis
Paolino wrote: > >>Even worse I get with methods and function namespaces. > > > > What is "even worse" about them? > > > For my thinking, worse is to understand how they derive their pattern > from generic namespaces. > Methods seems not to have a writeble one,while functions as George and > Rob r

Re: Getting not derived members of a class

2005-08-01 Thread George Sakkis
Franz Steinhaeusler wrote: > Hello NG, > > I want to retrieve the members of a class > with a baseclass. > But the problem is, how to get the non derived > members. > > class a: > def who(self): > print "who" > def __init__(self): > self._a = 3 > > class b(a): > def who

Re: Getting not derived members of a class

2005-08-01 Thread George Sakkis
Franz Steinhaeusler wrote: > Is there any possibility to simply get out > the classes and baseclasses of a class? > > somfunc (y) => class A, B (where B is last). If you use "new-style" classes, i.e. classes inheriting from object, it is trivial: class X(object): pass class Y1(X): pass

Re: fully-qualified namespaces?

2005-09-12 Thread George Sakkis
"Lenny G." <[EMAIL PROTECTED]> wrote: > Suppose I have a python module named Hippo. In the Hippo module is a > class named Crypto. The Crypto class wants to 'from Crypto.Hash import > SHA' which refers to the module/classes in python-crypto. Other > classes in the Hippo module want to 'import C

Re: Simplifying imports?

2005-09-13 Thread George Sakkis
"Terry Hancock" <[EMAIL PROTECTED]> wrote: > On Monday 12 September 2005 10:09 pm, [EMAIL PROTECTED] wrote: > > I like to keep my classes each in a separate file with the same name of > > the class. The problem with that is that I end up with multiple imports > > in the beginning of each file, lik

Re: Simplifying imports?

2005-09-13 Thread George Sakkis
"Terry Hancock" <[EMAIL PROTECTED]> wrote: > On Tuesday 13 September 2005 12:46 pm, George Sakkis wrote: > > Or even better, forget about the braindead java restriction of one > > class per file and organize your code as it makes more sense to you. > > W

Re: Python Doc Problem Example: os.path.split

2005-09-18 Thread George Sakkis
Another epileptic seizure on the keyboard. Apart from clue deficit disorder, this guy seems to suffer from some serious anger management problems...*plonk* "Xah Lee" <[EMAIL PROTECTED]> wrote: > Python Doc Problem Example > > Quote from: > http://docs.python.org/lib/module-os.path.html >

Re: Creating a list of Mondays for a year

2005-09-18 Thread George Sakkis
"Chris" <[EMAIL PROTECTED]> wrote: > Is there a way to make python create a list of Mondays for a given year? > > For example, > > mondays = ['1/3/2005','1/10/2005','1/17/2005','1/24/2005', > '1/31/2005','2/7/2005', ... ] Get the dateutil package (https://moin.conectiva.com.br/DateUtil): impor

Re: How am I doing?

2005-09-18 Thread George Sakkis
"Jason" <[EMAIL PROTECTED]> wrote: > Please don't laugh, this is my FIRST Python script where I haven't > looked at the manual for help... Sooner or later you should ;) > import string Don't need it it modern python; use string methods instead. > import random > > class hiScores: The common c

Re: Creating a list of Mondays for a year

2005-09-18 Thread George Sakkis
"Peter Hansen" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > "Chris" <[EMAIL PROTECTED]> wrote: > >>Is there a way to make python create a list of Mondays for a given year? > > > > Get the dateutil package (https://moin.cone

Re: How to write this iterator?

2005-09-19 Thread George Sakkis
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Sorry, my description was not very good, I meant something behaving as: > > >>>example=Liter("abc","12345","XY") > >>>for x in example: print x, > > a 1 X b 2 Y c 3 4 5 > > or for that append() method, > > >>>example=Liter("abc", "12345"

Re: How to write this iterator?

2005-09-20 Thread George Sakkis
"Jordan Rastrick" <[EMAIL PROTECTED]> wrote: > I've written this kind of iterator before, using collections.deque, > which personally I find a little more elegant than the list based > approach: Nice, that's *much* more elegant and simple ! Here's the class-based version with append; note that i

Re: Chronological Processing of Files

2005-09-21 Thread George Sakkis
"Peter Hansen" <[EMAIL PROTECTED]> wrote: > yoda wrote: > > This feels like a stupid question but I'll ask it anyway. > > > > How can I process files chronologically (newest last) when using > > os.walk()? > > Do you want the ordering to apply just to files within each directory, > or to all the f

Re: Intermediate to expert book

2005-09-21 Thread George Sakkis
"Tony Houghton" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Can anyone recommend a good book for intermediate up to expert level? > I'm an experienced C programmer and I learnt Python from the "Learning > Python" O'Reilly book because it had good reviews. I was disappointed > th

Re: Name of type of object

2005-02-09 Thread George Sakkis
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Randall Smith wrote: > > Jive Dadson wrote: > > > >> The traceback routine prints out stuff like, > >> > >> NameError: global name 'foo' is not defined > >> > >> NameError is a standard exception type. > >> > >> Wha

Re: check if object is number

2005-02-11 Thread George Sakkis
"Steven Bethard" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Is there a good way to determine if an object is a numeric type? > Generally, I avoid type-checks in favor of try/except blocks, but I'm > not sure what to do in this case: > > def f(i): > ... > i

Re: check if object is number

2005-02-11 Thread George Sakkis
"Michael Hartl" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > As luck would have it, isnumber is a built-in Python function: > > >>> isnumber(1) > True > >>> isnumber(1.0) > True > >>> isnumber('1') > False > > Michael > > -- > Michael D. Hartl, Ph.D. > Chief Technology Officer > h

Re: check if object is number

2005-02-11 Thread George Sakkis
> George Sakkis wrote: > > "Steven Bethard" <[EMAIL PROTECTED]> wrote in message > > news:[EMAIL PROTECTED] > > > >>Is there a good way to determine if an object is a numeric type? > > > > In your example, what does your application consid

Re: check if object is number

2005-02-12 Thread George Sakkis
> > So what you're saying is that 3 <= "3.0" should not be allowed, but > > 3 <= SomeUserDefinedNumericClass(3) is ok, although your program knows > > nothing a priori about SomeUserDefinedNumericClass. The idea suggested > > before, try if "x+1" fails or not does not get you far; any class that >

Re: Python in EDA

2005-02-12 Thread George Sakkis
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hi, > > I am new to Python and coming from the EDA/VLSI Design background. > > I wanted to know if there are some active projects going on EDA modules > written in Python. > > Usually, use of scripting tools in VLSI Design is on a per-pr

Re: builtin functions for and and or?

2005-02-13 Thread George Sakkis
"Roose" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I need this a lot: a one line way to do a n-ary and or 'or'. > > e.g., > > result = True > for x in L: > if not boolean_function(x): > result = False > > or > > >>> reduce(operator.__and__, [boolean_function(x) for x in L)

Re: Distutils: relative paths

2005-02-19 Thread George Sakkis
"Frans Englich" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > Hello, > > I have trouble installing a data directory which is not a child of my package > directory in the source directory. > > My source directory looks like this: > > ./setup.py > schemas/*.xsd > foo/*.py > > And w

Re: [ANN] Python 2.4 Quick Reference available

2005-02-19 Thread George Sakkis
"David M. Cooke" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > "Pete Havens" <[EMAIL PROTECTED]> writes: > > > The is awesome! Thanks. I did notice one thing while reading it. In the > > "File Object" section, it states: > > > > "Created with built-in functions open() [preferred] o

Re: How Do I get Know What Attributes/Functions In A Class?

2005-02-20 Thread George Sakkis
<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Thank you Hans. Could you give me a simple sample of using inspect? > http://www.python.org/doc/current/lib/module-inspect.html George -- http://mail.python.org/mailman/listinfo/python-list

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-21 Thread George Sakkis
"Ilias Lazaridis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Nick Vargish wrote: > > You can excuse yourself from this one and stop replying to comments, > > but you don't get to unilaterally declare a discussion over. > [...] > > The discussion is over. > > At least the in-topi

Re: [EVALUATION] - E02 - Support for MinGW Open Source Compiler

2005-02-23 Thread George Sakkis
"Ilias Lazaridis" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Grant Edwards wrote: > [...] > > Um, you realize that nobody in this thread takes you the least > > bit seriously and people are just poking you with a stick to > > watch you jump? > > jump: > > [EVALUATION] - E02 - Sup

Re: survey

2005-03-04 Thread George Sakkis
"Dave Zhu" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Hello All, > > Is there any survey on scripting languages? I would > like to get information on several scripting languages > including Python, Perl, Ruby, Tcl, etc. > > Thanks > > Dave After a little googling, that's what I

Re: Integer From A Float List?!?

2005-03-04 Thread George Sakkis
"Bill Mill" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On Fri, 4 Mar 2005 22:35:48 +0100, [EMAIL PROTECTED] > <[EMAIL PROTECTED]> wrote: > > Hello NG, > > > > I was wondering if there is a way to obtain, from a list of floats, > > a list of integers without loops. Probably i

Start new process by function ?

2005-03-10 Thread George Sakkis
Is it possible to start a new process by specifying a function call (in similar function to thread targets) instead of having to write the function in a separate script and call it through os.system or os.spawn* ? That is, something like def foo(): pass os.spawn(foo) Thanks in advance, George

S-exression parsing

2005-03-11 Thread George Sakkis
The S-expression parser below works, but I wonder if it can be simplified; it's not as short and straightforward as I would expect given the simplicity of S-expressions. Can you see a simpler non-recursive solution ? George # usage >>> parseSexpression("(a (b c) (d))") ['a', ['b', 'c'], ['d']]

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
"Raymond Hettinger" <[EMAIL PROTECTED]> wrote: > [Jeff Epler] > > Maybe something for sets like 'appendlist' ('unionset'?) > > While this could work and potentially be useful, I think it is better to keep > the proposal focused on the two common use cases. Adding a third would reduce > the chance

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
"Aahz" <[EMAIL PROTECTED]> wrote: > In article <[EMAIL PROTECTED]>, > Raymond Hettinger <[EMAIL PROTECTED]> wrote: > > > >The proposed names could possibly be improved (perhaps tally() is more active > >and clear than count()). > > +1 tally() -1 for count(): Implies an accessor, not a mutator. -1

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
> -1 form me. > > I'm not very glad with both of them ( not a naming issue ) because i > think that the dict type should offer only methods that apply to each > dict whatever it contains. count() specializes to dict values that are > addable and appendlist to those that are extendable. Why not > su

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
Michael Spencer wrote: > Raymond Hettinger wrote: > > I would like to get everyone's thoughts on two new dictionary methods: > > > > def count(self, value, qty=1): > > try: > > self[key] += qty > > except KeyError: > > self[key] = qty

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
"John Machin" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > George Sakkis wrote: > > +1 on this. The new suggested operations are meaningful for a subset > of all valid dicts, so they > > should not be part of the base dict API. If any v

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
> > +1 on this. The new suggested operations are meaningful for a subset > of all > > valid dicts, so they > > should not be part of the base dict API. If any version of this is > approved, > it will clearly be an > > application of the "practicality beats purity" zen rule, and the > > justificatio

Re: Pre-PEP: Dictionary accumulator methods

2005-03-19 Thread George Sakkis
"Michael Spencer" <[EMAIL PROTECTED]> wrote: > I could imagine a class: accumulator(mapping, default, incremetor) such that: > >>> my_tally = accumulator({}, 0, operator.add) > or > >>> my_dict_of_lists = accumulator({}, [], list.append) > or > >>> my_dict_of_sets = accumulator({}, set(),

For loop extended syntax

2005-03-20 Thread George Sakkis
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for in" syntax so that X can include default arguments ? This would be very useful for list/generator comprehensions, for example being able to write something like: [x*y-z fo

Re: For loop extended syntax

2005-03-20 Thread George Sakkis
"Kay Schluehr" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > > This would be very > > useful for list/generator comprehensions, for example being able to > write something like: > > > > [x*y-z for (x,y,z=0) in (1,2,3), (4,5), (6,7,8)]

Re: For loop extended syntax

2005-03-20 Thread George Sakkis
"Matteo Dell'Amico" <[EMAIL PROTECTED]> wrote: > George Sakkis wrote: > > I'm sure there must have been a past thread about this topic but I don't > > know how to find it: How > > about extending the "for in" syntax so that X can

Re: For loop extended syntax

2005-03-20 Thread George Sakkis
"Heiko Wundram" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > On Sunday 20 March 2005 20:47, George Sakkis wrote: > > Not always. Say for example that you're doing some 2D geometry stuff, and > > later you have to extend it to 3D. In this

Re: For loop extended syntax

2005-03-20 Thread George Sakkis
"Heiko Wundram" <[EMAIL PROTECTED]> wrote: > Am Sonntag, 20. März 2005 22:22 schrieb George Sakkis: > > Once more, the 2D/3D example was just that, an example; my point was not to > > find a specific solution to a specific problem. > > And my point being:

Re: missing? dictionary methods

2005-03-21 Thread George Sakkis
"Antoon Pardon" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Well at least I find them missing. > > For the moment I frequently come across the following cases. > > 1) Two files, each with key-value pairs for the same dictionary. > However it is an error if the second file contains

Re: For loop extended syntax

2005-03-21 Thread George Sakkis
"Ron" <[EMAIL PROTECTED]> wrote: > How would this examples work? > > for x=5,y,z in (123),(4,5),(6,7,8,9) > > Would the x default over ride the first value? > Should, the 4 element in the third tuple be dropped without an error? It has already been clarified twice in the thread that the default v

Re: Pre-PEP: Dictionary accumulator methods

2005-03-21 Thread George Sakkis
"Michele Simionato" <[EMAIL PROTECTED]> wrote: > FWIW, here is my take on the defaultdict approach: > > def defaultdict(defaultfactory, dictclass=dict): > class defdict(dictclass): > def __getitem__(self, key): > try: > return super(defdict, self).__getitem_

Set literals

2005-03-21 Thread George Sakkis
How about overloading curly braces for set literals, as in >>> aSet = {1,2,3} - It is the standard mathematic set notation. - There is no ambiguity or backwards compatibility problem. - Sets and dicts are in many respects similar data structures, so why not share the same delimiter ? *ducks*

Re: Set literals

2005-03-21 Thread George Sakkis
> - There is no ambiguity or backwards compatibility problem. ...at least if it wasn't for the empty set.. hmm... -- http://mail.python.org/mailman/listinfo/python-list

Re: Set literals

2005-03-21 Thread George Sakkis
"Delaney, Timothy C (Timothy)" <[EMAIL PROTECTED]> wrote: > > How about overloading curly braces for set literals, as in > > > aSet = {1,2,3} > > > > - It is the standard mathematic set notation. > > - There is no ambiguity or backwards compatibility problem. > > - Sets and dicts are in many

Re: Set literals

2005-03-21 Thread George Sakkis
[EMAIL PROTECTED]> wrote: > +1 from me. > > The other possible meaning for {1,2,3} would be {1:None,2:None,3:None}, > but that is usually meant to be a set anyway (done with a dict). > > So what is this: {1:2, 3, 4 } (apart from "nearly useless") ? Syntax error; you'll have to decide whether you

Re: sorting a dictionary?

2005-03-21 Thread George Sakkis
"Anthony Liu" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > --- Scott David Daniels <[EMAIL PROTECTED]> wrote: > > Anthony Liu wrote: > > > mydict = {'the':358, 'they':29, 'went':7, > > 'said':65} > > > Is there an easy to sort this dictionary and get a > > > list like the followi

Re: Anonymus functions revisited

2005-03-22 Thread George Sakkis
"Ron" <[EMAIL PROTECTED]> wrote: > On Tue, 22 Mar 2005 21:56:57 GMT, Ron <[EMAIL PROTECTED]> wrote: > > >Why should a function not create a local varable of an argument if the > >varable doesn't exist and a default value is given? > > ok... thought it out better. :) > > Getting a default into a fun

Re: Anonymus functions revisited

2005-03-23 Thread George Sakkis
"bruno modulix" <[EMAIL PROTECTED]> wrote: in message news:[EMAIL PROTECTED] > Ron wrote: > >>The problem here is that Kay's proposition mixes two points: flexible > >>tuple unpacking and a new syntax for anonymous functions. > > > > > > Yes, two different problems. I don't think anything needs to

Re: Pattern matching from a text document

2005-03-23 Thread George Sakkis
B "Ben" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > I'm currently trying to develop a demonstrator in python for an > ontology of a football team. At present all the fit players are > exported to a text document. > > The program reads the document in and splits each line into a st

Re: Anonymus functions revisited : tuple actions

2005-03-24 Thread George Sakkis
"Kay Schluehr" <[EMAIL PROTECTED]> wrote: > [snipped] > > Wouldn't it be fun to use in Python? > > Only drawback: does not look like executable pseudo-code anymore :( > > > Regards Kay I don't know if it would be fun, but it certainly doesn't look accessible to mere mortals :-) I'm not sure if th

Re: An Abridged Python Tutorial

2005-03-24 Thread George Sakkis
"Michael Spencer" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > An Abridged Python Tutorial > > There are tips for the novice and tricks > that will add to your programming kicks. > But the cardinal rule > that you must learn at school > is that spaces and tabs never mix.

Re: Anonymus functions revisited : tuple actions

2005-03-25 Thread George Sakkis
"Kay Schluehr" <[EMAIL PROTECTED]> wrote: > To make my intention clear for another time, also for George who > mistrusts these exercises alltogether. I want to derive a syntax and > semantics for anonymus functions ( called "tuple-actions" ) that are > generalizations of rules that are already use

Re: Anonymus functions revisited

2005-03-25 Thread George Sakkis
"Ron_Adam" <[EMAIL PROTECTED]> wrote: > On 25 Mar 2005 10:09:50 GMT, Duncan Booth > <[EMAIL PROTECTED]> wrote: > > > >I've never found any need for an is_defined function. If in doubt I just > >make sure and initialise all variables to a suitable value before use. > >However, I'll assume you have

Re: left padding zeroes on a string...

2005-03-25 Thread George Sakkis
"cjl" <[EMAIL PROTECTED]> wrote: > Hey all: > > I want to convert strings (ex. '3', '32') to strings with left padded > zeroes (ex. '003', '032'), so I tried this: > > string1 = '32' > string2 = "%03s" % (string1) > print string2 > > >32 > > This doesn't work. Actually in this case string2 is pad

str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread George Sakkis
"M.E.Farmer" <[EMAIL PROTECTED]> wrote: > > [snipped] > > Be sure to study up on string methods, it will save you time and > sanity. > Py> dir('') > ['__add__', '__class__', '__contains__', '__delattr__', '__doc__', > '__eq__', '__ge__', '__getattribute__', '__getitem__', '__getslice__', > '__gt__'

Re: str vs dict API size (was 'Re: left padding zeroes on a string...')

2005-03-25 Thread George Sakkis
"Larry Bates" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Once it is in everyone is hesitant to take it out for fear of > breaking someone's code that uses it (no matter how obscure). > Putting in new methods should be difficult and require lots > of review for that reason and so

Re: itertools to iter transition (WAS: Pre-PEP: Dictionary accumulator methods)

2005-03-29 Thread George Sakkis
"Steven Bethard" <[EMAIL PROTECTED]> wrote: > > [snip] > > I guess the real questions are[1]: > * How much does iter feel like a type? > * How closely are the itertools functions associated with iter? > > STeVe > > [1] There's also the question of how much you believe in OO tenets like > "functions

Re: itertools to iter transition (WAS: Pre-PEP: Dictionaryaccumulator methods)

2005-03-29 Thread George Sakkis
"Terry Reedy" <[EMAIL PROTECTED]> wrote: > > "Steven Bethard" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > True it's not a huge win. But I'd argue that for the same reasons that > > dict.fromkeys is a dict classmethod, the itertools methods could be iter > > classmethods (or s

Re: Decorater inside a function? Is there a way?

2005-04-02 Thread George Sakkis
It turns out it's not a "how to inflate tires with a hammer" request; I've actually written an optional type checking module using decorators. The implementation details are not easy to grok, but the usage is straightforward: from typecheck import * @returns(listOf(int, size=3)) @expects(x=str, y=

Re: Help with splitting

2005-04-02 Thread George Sakkis
Jeremy Bowers wrote: > On Fri, 01 Apr 2005 14:20:51 -0800, RickMuller wrote: > > > I'm trying to split a string into pieces on whitespace, but I want to > > save the whitespace characters rather than discarding them. > > > > For example, I want to split the string '12' into ['1',' ','2']. > > I

Re: Decorater inside a function? Is there a way?

2005-04-03 Thread George Sakkis
Yes, it is possible to turn off type checking at runtime; just add this in the beginning of your define: def define(func): if not ENABLE_TYPECHECKING: return lambda func: func # else decorate func where ENABLE_TYPECHECKING is a module level variable that can be exposed to the modu

Re: Decorater inside a function? Is there a way?

2005-04-03 Thread George Sakkis
>def define(func): >if not ENABLE_TYPECHECKING: >return lambda func: func ># else decorate func A small correction: The argument of the decorator is not 'func' but the parameter checks you want to enforce. A template for define would be: def define(inputTypes, outputType): if

Testing threading

2005-04-05 Thread George Sakkis
How one goes on testing a threaded program, apart from doing a few successful runs and crossing his fingers that it at least follows the 'correct 99.% of the time' rule ? I've written a stripped-down python version of Doug Lea's PooledExecutor thread pool class (http://gee.cs.oswego.edu/dl/clas

Puzzling OO design problem

2005-04-08 Thread George Sakkis
I'm looking for a design to a problem I came across, which goes like this (no, it's not homework): 1. There is a (single inheritance) hierarchy of domain classes, say A<-B<-..<-Z (arrows point to the parent in the inheritance tree). 2. This hierarchy evolved over time to different versions for eac

Re: Puzzling OO design problem

2005-04-08 Thread George Sakkis
> Err, you might want to explain what these things do instead of an > abstract description of how you are doing it. It looks like you are > using inheritance in the normal way _and_ you are using it to handle > versioning of some kind (maybe stable interface releases? I don't know). > > Let us kno

Re: Puzzling OO design problem

2005-04-08 Thread George Sakkis
> I'm not sure if it was clear to you, but my problem is the dummy WorldModel_v1.MovableObject class. It doesn't do anything by itself, but it has to be in the inheritance chain to make its descendants work properly. > Are you using the *_v1 naming convention for backwards compatibility? > Backw

Re: Python Equivalent to Java Interfaces?

2005-04-08 Thread George Sakkis
"Brian Kazian" wrote: > I want to insure that all subclasses implement a certain method, but could > not find anything that would do this for me. Is there anyway in Python to > implement this check? Thanks! Check out PyProtocols (http://peak.telecommunity.com/PyProtocols.html). Protocols in a

Re: Puzzling OO design problem

2005-04-09 Thread George Sakkis
"Michael Spencer" <[EMAIL PROTECTED]> wrote: > > George, > > since you explicit allowed metaprogramming hacks :-), how about something like > this (not tested beyond what you see): > > [snipped] > Nice try, but ideally all boilerplate classes would rather be avoided (at least being written explici

Re: Puzzling OO design problem

2005-04-09 Thread George Sakkis
> On second thought, I had doubts. Consider the following scenario: > >A2 | f <- A3 >^ ^ >| | >B2 | f <- B3 >^ ^ >| | >C2 <- C3 | g > > Assume g calls f. Since f is defined in B version 2, it should taken >

Re: Puzzling OO design problem

2005-04-09 Thread George Sakkis
> Have you considered a 'macro' solution composing source? If I were handling so > many versions, I would want a complete class definition for each version rather > than having to scan many sources for each implementation. Can you elaborate on this a little ? You mean something like a template-ba

Re: Puzzling OO design problem

2005-04-11 Thread George Sakkis
"Bengt Richter" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > See if this does what you want: > > [snipped] > Yes, that's pretty much what I had in mind. I particularly liked the idea of mirroring automagically the nested class inheritance in each version. So I tried to refine th

Re: Global Variables

2005-04-12 Thread George Sakkis
Use 'global': def change_filename(): global filename filename=raw_input() def change_path(): global path path=raw_input() Even better, don't use globals at all; in 99% if the time, there are better ways to achieve the same effect. George -- http://mail.python.org/mailman/listinf

Re: def a((b,c,d),e):

2005-04-19 Thread George Sakkis
François Pinard wrote: > The most useful place for implicit tuple unpacking, in my experience, > is likely at the left of the `in' keyword in `for' statements (and > it is even nicer when one avoids extraneous parentheses). ... and would be nicest (IMO) if default arguments and *varargs were all

Re: def a((b,c,d),e):

2005-04-19 Thread George Sakkis
"François Pinard" wrote: > > I started recently to study the R system and language, and saw many good > ideas in there about argument passing. Translated in Python terms, it > would mean that `*varargs' and `**keywords' are not necessary last, > that named keywords may be intermixed with positiona

Re: def a((b,c,d),e):

2005-04-19 Thread George Sakkis
"François Pinard" wrote: > > > keywords may be abbreviated, and much more hairy, > > > Hmm.. -1 on this. It may save a few keystrokes, but it's not good for > > readability and maintenability. > > That was my first impression too. Yet, interactively, I found that > feature very convenient. Alread

Decorator pattern for new-style classes ?

2005-04-23 Thread George Sakkis
Searching the archives for something related to the title, I found a few relevant threads (e.g. http://tinyurl.com/avyg6 or http://tinyurl.com/b5b6v); however they don't seem to give a satisfactory answer, so here it goes again: What's the equivalent new-style Delegate class ? class Delegate:

Re: HTML cleaner?

2005-04-24 Thread George Sakkis
Probably you're looking for Beautiful Soup: http://www.crummy.com/software/BeautifulSoup/ George -- http://mail.python.org/mailman/listinfo/python-list

Injecting code into a function

2005-04-25 Thread George Sakkis
Is there a general way of injecting code into a function, typically before and/or after the existing code ? I know that for most purposes, an OO solution, such as the template pattern, is a cleaner way to get the same effect, but it's not always applicable (e.g. if you have no control over the desi

Re: Injecting code into a function

2005-04-25 Thread George Sakkis
"Lonnie Princehouse" wrote: > I expect you could combine the following with decorators as an easy way > to grab a function's locals just before it exits... you could also use > exec or eval to execute code in the function's local namespace. > --- > > # Try it:

Re: Pythonic way to do static local variables?

2005-04-25 Thread George Sakkis
> I've a function that needs to maintain an ordered sequence between > calls. > > In C or C++, I'd declare the pointer (or collection object) static at > the function scope. > > What's the Pythonic way to do this? > > Is there a better solution than putting the sequence at module scope? Yes, there

Re: Quote-aware string splitting

2005-04-25 Thread George Sakkis
> "J. W. McCall" <[EMAIL PROTECTED]> writes: > > > > I need to split a string as per string.strip(), but with a > > modification: I want it to recognize quoted strings and return them as > > one list item, regardless of any whitespace within the quoted string. > > > > For example, given the string:

Re: Quote-aware string splitting

2005-04-25 Thread George Sakkis
> import re > regex = re.compile(r''' >'.*?' | # single quoted substring >".*?" | # double quoted substring >\S+ # all the rest >''', re.VERBOSE) Oh, and if your strings may span more than one line, replace re.V

Re: Injecting code into a function

2005-04-25 Thread George Sakkis
> Oh, I overlooked this. Then the solution becomes simple: > >sys._getframe().f_trace > > Test: > > >>> an = Analyzer() > >>> sys.settrace(an.trace_returns) > >>> sys._getframe().f_trace > 0x010015D0>> Does this work for you non-interactively ? I tried running it from a script or importing it

Re: Injecting code into a function

2005-04-25 Thread George Sakkis
> I'm not clear on what your real goal is, but if you just want a snapshot > of what locals() is just before exiting func, that could be done with > a byte-code-hacking decorator with usage looking something like > > #func defined before this > func_locals = {} > @getlocals(func, func_l

Komodo syntax checking for python2.4

2005-04-26 Thread George Sakkis
I downloaded the latest Komodo (3.1) and configured it for python 2.4 so that it doesn't show decorators and genexps as syntax errors, but background syntax checking doesn't seem to work at all for python 2.4. Even for correct files, it shows a "Syntax checking error: Error checking syntax: retval

Re: Komodo syntax checking for python2.4

2005-04-26 Thread George Sakkis
"Trent Mick" wrote: > George, > > My suspicion is that the difference is that you are using a Cygwin > Python and it is using Un*x-style process return values. What do the > following return for your Python. > > For me on Windows (with ActivePython 2.4): > >>> import os > >>> os.system("ex

Re: Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you are, nor if you are a church member, but are you saved? Are you sure you will go to Heaven when you die? GOOGLE·NEWSGROUP·POST·151

2005-04-27 Thread George Sakkis
wrote in message news:[EMAIL PROTECTED] > Reports to [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED], > [EMAIL PROTECTED], [EMAIL PROTECTED] > > And do not feed the troll! I'm afraid he's not a troll. He's just a lame spammer, doesn't need feeding to survive... In any case, the hell with

Numeric/Numarray equivalent to zip ?

2005-04-30 Thread George Sakkis
What's the fastest and most elegant equivalent of zip() in Numeric/Numarray between two equally sized 1D arrays ? That is, how to combine two (N,)-shaped arrays to one (N,2) (or (2,N)) shaped ? I expect the fastest and the most elegant idiom to be identical, as it is usually the case in this excell

Re: search multiple dictionaries efficiently?

2006-01-17 Thread George Sakkis
Livin wrote: > I'm a noobie so please be easy on me. I have searched a ton and did not find > anything I could understand. > > I'm using py2.3 > > I've been using Try/Except but this gets long with multiple dictionaries. > > I found some code on web pages and such but cannot get them to work. Any

Re: A simpler more pythonic approach to adding in

2006-01-18 Thread George Sakkis
A cleaner, though not shorter, rewriting could be: from itertools import chain def ancestors(path): while True: yield path parent = os.path.dirname(path) if parent == path: break path = parent for dir in chain([os.environ['HOME']],

Re: OT: What's up with the starship?

2006-10-15 Thread George Sakkis
[EMAIL PROTECTED] wrote: > Robert Hicks wrote: > > [EMAIL PROTECTED] wrote: > > > T. Bryan wrote: > > > > Thomas Heller wrote: > > > > > > > > > I cannot connect to starship.python.net: neither http, nor can I login > > > > > interactively with ssl (and the host key seems to have changed as > > >

Re: python's OOP question

2006-10-15 Thread George Sakkis
neoedmund wrote: > python use multiple inheritance. > but "inheritance" means you must inherite all methods from super type. > now i just need "some" methods from one type and "some" methods from > other types, > to build the new type. > Do you think this way is more flexible than tranditional inh

Re: string splitting

2006-10-17 Thread George Sakkis
[EMAIL PROTECTED] wrote: > Hello, > I have thousands of files that look something like this: > > wisconsin_state.txt > french_guiana_district.txt > central_african_republic_province.txt > > I need to extract the string between the *last* underscore and the > extention. > So based on the files abov

Re: creating many similar properties

2006-10-18 Thread George Sakkis
Michele Simionato wrote: > Lee Harr wrote: > > I understand how to create a property like this: > > > > class RC(object): > > def _set_pwm(self, v): > > self._pwm01 = v % 256 > > def _get_pwm(self): > > return self._pwm01 > > pwm01 = property(_get_pwm, _set_pwm) > > > >

Re: creating many similar properties

2006-10-18 Thread George Sakkis
Carl Banks wrote: > Lee Harr wrote: > > I understand how to create a property like this: > > > > class RC(object): > > def _set_pwm(self, v): > > self._pwm01 = v % 256 > > def _get_pwm(self): > > return self._pwm01 > > pwm01 = property(_get_pwm, _set_pwm) > > > > > > But

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