Re: DRY and class variables

2011-09-08 Thread egbert
On Thu, Sep 08, 2011 at 12:22:33PM +0200, Thomas Jollans wrote:
> You should be able to do this with a metaclass (almost certainly
> overkill), or with a class decorator (Python 2.6+):
> 
> def with_metadata (cls):
> cls.m = Metadata (cls.__name__)
> cls.m.do_something ()
> return cls
> 
> @with_metadata
> class TableOne:
># foo
>pass
Overnight I have become a decorator fan.
I can postpone the study of metaclasses.
Thanks.
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


DRY and class variables

2011-09-08 Thread egbert
My classes correspond to sql tables.
In these classes I want to have several class variables
that refer to data that are common to all instances.

The assignment statements for the class variables are the same
in all classes, except that of these instructions needs the name
of the class itself. That name is used to read a file with meta-data.

So what I have now is something like this (simplified):

class TableOne(object):
m = Metadata('TableOne')
m.do_something()
def __init__(self):
etc

class TableTwo(object):
m = Metadata('TableTwo')
m.do_something()
def __init__(self):
etc

I have tried:
- to eliminate the class name argument, but in this phase of the
  object creation __class__ and __name__ are not available
- to move the two statements to a superclass, but the class variables
  come in the superclass namespace, not in the subclass namespace.

Any ideas ?
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python IDE/text-editor

2011-04-17 Thread egbert
In http://docs.python.org/using/unix.html#editors
you can read:
Geany is an excellent IDE with support for a lot of languages.
For more information, read: http://geany.uvena.de/

I followed that suggestion, and am very happy with Geany.
But I confess that I am not a sophisticated user.

Why does nobody mention Geany ?
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: When the first line of a file tells something about the other lines

2010-08-16 Thread egbert
On Mon, Aug 16, 2010 at 11:59:57AM +0200, Peter Otten wrote:
> 
> with open(filename) as lines:
> first_line = next(lines, "")
> if special(first_line):
> # ...
> else:
> lines = itertools.chain([first_line], lines)
> for line in lines:
> # ...

Beautiful. And a nice suggestion to read the itertools docs.
egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


When the first line of a file tells something about the other lines

2010-08-16 Thread Egbert Bouwman
Often the first line of a file tells how to read or interpret the other
lines.
Depending on the result, you then have to ...
- skip the first line, or
- treat the first line in another special way, or
- treat the first line in the same way as the other lines.

I can handle this by opening the file twice,
the first time for reading the first line only.
I suppose there exists a more elegant solution.
Below is the structure of what I do now.
Please comment.

f = open(file_name,"r")# eerste opening
file_line  = f.readline()
special = True if some_condition else False
f.close()

f = open(file_name,"r")# tweede opening
if not special:
# use first line, read previously
stripped_line = file_line.strip()
else:
# skip first file_line, or treat in another special way:
f.next()
# read other lines:
for file_line in f:
stripped_line = file_line.strip()
# now do something with stripped_line
f.close()

egbert
-- 
Egbert Bouwman  
Keizersgracht 197-II
1016 DS  Amsterdam  
Tel 0(031)20 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List-type attributes and name strings

2010-07-01 Thread egbert
On Thu, Jul 01, 2010 at 02:28:37PM +0200, Bruno Desthuilliers wrote:
 
> Either I failed to understand you or you overlooked some other
> problem in you code and jumped to the wrong conclusions.
> 
In my problem the the name of the list or dict to mutate arrives in namestring,
so I could not use the hard coding of attr1 and attr2 like you did.
And because of a blind spot for getattr() I modified __dict__.
Thanks to you, Chris and Lie it will not happen again, I promise.
egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: List-type attributes and name strings

2010-07-01 Thread egbert
On Thu, Jul 01, 2010 at 04:02:49AM -0700, Chris Rebert wrote:

> switch to getattr() as demonstrated above.
> 
Thanks for opening my eyes, Chris.
egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


List-type attributes and name strings

2010-07-01 Thread egbert
Normally you use setattr() if the name of the attribute is in a
namestring: 
>>>> setattr(self, namestring, value)
But my attributes are lists or dictionaries, and I don't seem to be
able to use setattr anymore.
Now I use for a list something like:
>>> self.__dict__[namestring].append(value)
and for a dictionary:
>>> self.__dict__[namestring][keystring]=value
But I have the impression that I am cheating, because users should not
operate on __dict__ directly.
Is that true ? And are there better solutions ?
egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there a standard name for this tree structure?

2010-04-06 Thread egbert
On Sun, Apr 04, 2010 at 12:10:02PM +, Steven D'Aprano wrote:
 
> I can implement this tree using a flat dict:
> 
> root = object()
> data = {root: ['Mammal', 'Reptile'], 

What is the advantage, or thougth behind, using an instance
of object as the root of your flat tree ?
egbert

-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: from import and __init__.py

2010-03-25 Thread egbert
On Thu, Mar 25, 2010 at 12:43:13PM -0400, Terry Reedy wrote:
> On 3/25/2010 6:16 AM, egbert wrote:
> >When I do 'from some_package import some_module'
> >the __init__.py of some_package will be run.
> >However, there will not be anything like a  package-module,
> >and the effects of __init__.py seem all to be lost. Is that true ?
> 
> No. If you do
> 
> from sys import modules
> print(modules.keys())
> 
> you will see both some_package and some_package.some_module among
> the entries. 
Yes, you are right. And I can reach everything with
modules['some_package']
or variants thereof.
Thanks,
egbert

-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


from import and __init__.py

2010-03-25 Thread egbert
When I do 'from some_package import some_module'
the __init__.py of some_package will be run.
However, there will not be anything like a  package-module, 
and the effects of __init__.py seem all to be lost. Is that true ?
Or can I still do something useful with __init__.py ?  
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


SQLite's default ON CONFLICT algorithm

2008-08-18 Thread egbert
Yes, I know that this is off-topic, but I feel justified by sqlite3 
being a builtin.

The default ON CONFLICT algorithm in SQLite is ABORT.
The SQLite documentation ("ON CONFLICT clause") says that when
a constraint violation occurs under ABORT, no rollback is executed,
so changes from prior commands within the same transaction are
preserved.
Isn't this a strange choice for a default ? 
After all, you expect that either all changes within a transaction 
are preserved, or that nothing at all is preserved.

The Python Library Reference on sqlite3 says in paragraph 13.13.5
that I should not use the ROLLBACK conflict algorithm in my sql.
Instead I have to catch the IntegrityError and call the rollback method.
Does that mean that I have to wrap all multi-command transactions
in a try-except if I don't like the default ABORT choice ?
e

-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

--
http://mail.python.org/mailman/listinfo/python-list


Re: current week / weeks in year - best practice

2008-08-03 Thread egbert
On Sat, Aug 02, 2008 at 07:46:49PM -0700, Dennis Lee Bieber wrote:
>   
> 
What is the meaning of  ?
e.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

--
http://mail.python.org/mailman/listinfo/python-list


Re: formatting list -> comma separated (slightly different)

2008-07-09 Thread egbert
On Wed, Jul 09, 2008 at 10:25:33PM +0200, Michiel Overtoom wrote:
> Formatting a sequence of items such that they are separated by
> commas, except the last item, which is separated by the word 'and'.
> 
> For example:
> 
> Three friends have a dinner: Anne, Bob and Chris

row = ["Anne","Bob","Chris"]
txt = ", ".join(row)
pos = txt.rfind(", ")
new = "%s and %s" % (txt[0:pos], txt[pos+2:])

egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

--
http://mail.python.org/mailman/listinfo/python-list


Re: Java or C++?

2008-04-15 Thread egbert
What is the role or position of C# in this context ?
If I remember well, some people have said that C# is an improved
C++ or Java.
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for-else

2008-03-09 Thread egbert
On Sat, Mar 08, 2008 at 04:15:31PM -0500, Terry Reedy wrote:
> 
> I am sorry if you cannot appreciate such elegance 
> and can only spit on it as 'orwellian'.
> 
I admire the elegance of your examples and your explanation.
I will keep a copy of it in my Beazley,
for I am afraid I have to read it again.
As for orwellian, I must admit 
that I was quite happy when I thought of using that word, 
but that it was not my luckiest thought.

But I have to persist in my malice.

In the following snippet it is not at all clear
to the naive programmer (me) that the else refers to an 
iterator_is_exhausted condition,
whatever logical explanation you may offer.

.  for each_item in item_list:
.do_something()
.  else:
.do_else()

My temporary solution will be to accompany this else
with an appropriate comment: # exhausted

e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: for-else

2008-03-08 Thread egbert
The idea of the if-else is:
.  depending on some condition either do this or do something else, 
.  don't do them both.

If you approach a loop-else with this same idea, you get:
.  depending on the loop conditions either do the loop, 
.  or do something else, but not both.

However the loop-else really works more like this:
.  try to do the loop; 
.  if it starts but is interrupted by a break,
.  then do something else as well.

So they are completely different beasts, and if you try to use
or explain the one according to the rules of the other one,
you put a serious strain on your synapses.

The explanation that the if-else and the loop-else
follow the same pattern, runs more or less like this:
.  all conditions to run the loop to its completion were met,
.  which means that the loop-condition is not met (any more),
.  which means that we must do something else.
For me that is orwellian logic: success is failure.

The loop-else mechanism is not an easy one:
earlier in this thread Carl Banks turned it into an either/or construct
by omitting the crucial break; Jeffrey Barish initially found 
the loop-else surprising; Sion Arrowsmith found it comprehensible 
only after some hard thinking (as in the last paragraph).

The culprit is of course the keyword, else.
The idea of an easy follow-up after a loop is a good one.
But we need other keywords, I think at least three of them:
.  skipped - the loop did not run at all
.  broken - the loop was interrupted (by a break) 
.  exhausted - the loop ran to completion.
The last two as suggested by Laurence Tratt in his Convergence.
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 3.0 migration plans?

2007-09-28 Thread egbert
On Thu, Sep 27, 2007 at 09:17:30PM -0400, Steve Holden wrote:
> So what we need is a poll on what the questions should be. I *love* c.l.py.
I will switch as soon as Debian has all the tools for an easy conversion
available, and Python 3000 has reached the default release status.
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is it possible to give an instance a value?

2007-03-08 Thread egbert
On Thu, Mar 08, 2007 at 01:22:25PM +1100, Steven D'Aprano wrote:

> On Wed, 07 Mar 2007 16:02:05 +0100, egbert wrote:
> > My impression is that you can do everything you want to
> > by making your instance callable, and not using a but a().
 
> You can't do this:
> 
> >>> a() = "some value"

I didn't say that you can do that. 
But in my example you can do
>>>  a("some value")
and that seems to be near enough for manstey.
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is it possible to give an instance a value?

2007-03-07 Thread egbert
On Tue, 06 Mar 2007 14:45:45 -0800, manstey wrote:
> 
> class Test(object):
>  def __init__(self, val):
>self.val = val
> 
> a = Test('hello')

> Is there a way to make a have the value a.val when it is used as
> above, or as an argument (eg function(a, 10, 'sdf') etc)?
> 
My impression is that you can do everything you want to
by making your instance callable, and not using a but a().

This is just an example:

class Persoon(object):
def __init__(self, adres):
self.adres=adres

def __call__(self, new_adres=None):
if new_adres: self.adres = new_adres
return self.adres

a = Persoon("Sidney")
print "Living in " + a()
a("Canberra")
print "Living in " + a()
print "Now living in ", a("Amsterdam")
print "Type of a() is: %s" % type(a())
print "Now earning" , a(1234) + 500
print "Type of a() is: %s" % type(a())
print "string ? %s" % ["No","Yes"][isinstance(a(), basestring)]

The output is:

Living in Sidney
Living in Canberra
Now living in  Amsterdam
Type of a() is: 
Now earning 1734
Type of a() is: 
string ? No


e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python does not play well with others

2007-01-24 Thread egbert
On Wed, Jan 24, 2007 at 06:24:37AM +, Harry George wrote:
> 
> Perl - excellent modules and bindings for just about everything ...
> Java - a world of its own.  They reinvent the wheel instead of ...
> PHP - are we talking web scripts or serious programs?  Are you ...
> C - the portable assembler.  Solid, trusted, tunable ...
> C++ - objects tacked onto C; but that didn't work so invent ...
> Python - it just works.  Same scripts run on every platform ... 

What about C# ?
e
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE refuses.

2006-11-30 Thread egbert
On Wed, Nov 29, 2006 at 03:15:45PM -0800, SPE - Stani's Python Editor wrote:
> Do you have python-wxversion installed?
> 
> $sudo apt-get install python-wxversion
> 
That helped. But why isn't it included in the wxPython download ?
Anyway, the first screen looks great. I will explore spe.
Thanks.
e.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SPE refuses.

2006-11-29 Thread egbert
On Wed, Nov 29, 2006 at 11:31:27AM -0800, SPE - Stani's Python Editor wrote:
> If wxPython is rightly installed, which means that "import wx" works
> fine and "wx.VERSION" gives the right version, you can ignore the
> wxPython warning.
> 
In a Python shell the commands 'import wx' and 'wx.VERSION' give:
(2,6,3,2,'')

> Please cd do your site-packages directory and do "python SPE.py
> --debug" and see the error message.

In gnome-terminal  /usr/lib/python2.4/site-packages/_spe
the command: 'python SPE.py --debug' produces the same error:
You need to install at least wxPython v2.5.4.1 to run SPE.
Get it from http://www.python.org

Well, I got it from the debian repositories.

e.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


SPE refuses.

2006-11-29 Thread egbert
According to apt-show-versions I have installed:
python-wxgtk2.6 2.6.3.2.1.5
spe 0.8.2a+repack-1

However when I start SPE I get the message
You need to install at least wxPython v2.5.4.1 to run SPE

How do I tell SPE that I have the right wxPython ?
e.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Python as default Lexer in SciTE

2006-11-12 Thread egbert
Is it possible to set Python as the default language in SciTE?
Not all my python scripts have the .py extension, 
only the to_be_imported ones. And I use SciTE only for Python.
e.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Dispatcher experiment

2006-11-08 Thread egbert
As an exercise in the use of dispatcher 
I concocted a Zoo with some Animals, see below.
It works, but I think it is convoluted, obfuscated.

The idea is that in the Zoo each animal needs its own type of food,
and the Zoo should acknowledge a wish for that food,
as soon as the animal says it wants food.
The number and kind of animals (and their food) may vary.

The general problem is that you may have an unspecified number
of instances of some type, and that each instance must be recognized
and handled by the specific signal it sends into the world.

I would appeciate any comments or improvements on my design.
In a python shell you may test it with:
import dip
zoo = dip.Zoo()
zoo.animals["fish"].send_food_wish()
    
egbert

#!/usr/bin/env python
# dip.py := experiment with Patrick O'Brien's dispatcher 

import wx.py.dispatcher as disp

class Animal(object):
def __init__(self, animal_food):
self.animal_food = animal_food

def send_food_wish(self):
# started by some event outside this class.
disp.send(signal=self.animal_food, sender=self)

class Zoo(object):
def __init__(self):
# dummies for some gui that accepts names of animals and their food:
animal_list  = ["bird",  "lion", "fish"]
food_list= ["bread", "meat", "plankton"]

# zoo administration: register animals and their food;
self.animals = {}
for animal,food in zip(animal_list, food_list):
animal_food_signal = (animal, food)
self.animals[animal] = Animal(animal_food_signal)
disp.connect(self.listen_to_food_wish, signal=animal_food_signal)

def listen_to_food_wish(self, signal, sender=disp.Any):
print "sender %s is %s and wishes to eat %s now" % \
  (sender, signal[0], signal[1])

if __name__ == '__main__':
zoo = Zoo()
for animal in zoo.animals.values():
animal.send_food_wish()
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: invert or reverse a string... warning this is a rant

2006-10-20 Thread egbert
> > John Salerno wrote:
> >> I'm not steeped enough in daily programming to argue that it isn't 
> >> necessary, but my question is why do you need to reverse strings? Is it 
> >> something that happens often enough to warrant a method for it?

String reversal comes in handy when you do palindromes.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


set_focus_chain in pygtk and wxPython

2006-08-13 Thread egbert
In pygtk is available: set_focus_chain
Does wxPython have something similar ?
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Questions about the event loop

2006-05-16 Thread egbert
What does a gui_event_loop know ?

My gui is based on pygtk, 
but i suppose the mechanism is the same everywhere.

The gui is created within a class-instance within a function.
Normally, ie without a gui, everything that happens within
a function is forgotten as soon the function ends.

But in a gui_event_loop the callback-method within the function
can be called, and this callbacks calls another function
also within the same first function.
And that function already stopped.

Maybe somebody can explain what is going on, or where I can find
further explanations.

The structure of my gui script is as follows:
import gtk
def func():
def callback_helper():
...
class Klas(object):
def __init__(self):
...
# create gui with self.callback()
...
def callback(self, widget):
callback_helper()
...
klas = Klas()

func()
gtk.main()

egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can anyone advise me

2006-04-27 Thread egbert
On Thu, Apr 27, 2006 at 02:48:46AM -0700, [EMAIL PROTECTED] wrote:
> why the output of this code :
> x = 0
> while x < 10:
> z = 0
> print x
> x = x + 1
> while z < x:
> print z,
> z = z + 1
> 
> is
> 
> 0
> 0 1
> 0 1 2
> 0 1 2 3
> 0 1 2 3 4
> 0 1 2 3 4 5
> 0 1 2 3 4 5 6
> 0 1 2 3 4 5 6 7
> 0 1 2 3 4 5 6 7 8
> 0 1 2 3 4 5 6 7 8 9
> 0 1 2 3 4 5 6 7 8 9 < ---extra
> 
> 
> instead of :
> 0
> 0 1
> 0 1 2
> 0 1 2 3
> 0 1 2 3 4
> 0 1 2 3 4 5
> 0 1 2 3 4 5 6
> 0 1 2 3 4 5 6 7
> 0 1 2 3 4 5 6 7 8
> 0 1 2 3 4 5 6 7 8 9
> 
In your nested loop you are printing an x followed by zero or
more z's, but only after each x, including the first one,
you switch to a new line.
So the last digit on each line is an x, except for the last line,
which are z's printed after the 9 (an x) ending the line above it.

Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: An isalpha() that accepts underscores as well

2006-03-01 Thread egbert
In the discussion about isalpha()_mutants that accept 
underscores as well, we did not talk about regular expressions.

Afterwards I did some timings.
My first observation was that the whole experiment is rather futile,
because it takes only about a second to do a million tests.
If you take the trouble to collect a million words,
you might as well spend an extra second to analyze them.

Apart from that, a simple regular expression is often faster
than a test with replace. The last one, replace, does better
with shorter tokens without underscores. Nothing to replace.
Regular expressions are less sensitive to the length of the tokens.
Regular expressions are not monsters of inefficiency.

This is my script:

#!/usr/bin/env python
import sys
from timeit import Timer

import re
pat  = re.compile(r'^[a-zA-Z_]+$')

if len(sys.argv) > 1:
token = sys.argv[1]
else:
token = "contains_underscore"

t = Timer("''.join(token.split('_')).isalpha()", "from __main__ import token")
print t.timeit()  # 1.94

t = Timer("token.replace('_','X').isalpha()", "from __main__ import token")
print t.timeit()  # 1.36

t = Timer("pat.search(token)", "from __main__ import token, pat")
print t.timeit()  # 1.18

t = Timer("token.isalpha()", "from __main__ import token")
print t.timeit()  # 0.28

#egbert

-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


An isalpha() that accepts underscores as well

2006-02-26 Thread egbert
The string method isalpha() returns True when all characters in the
string are alphabetic. Unfortunately the underscore is not alphabetic.
A function that does what I need is:

def alfa_(w):
return "".join(w.split("_")).isalpha()

but for the kind of strings that I have this is about ten times
slower than isalpha() sec. Any suggestions ?
Thanks.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Pythonpath and gnome panel

2006-02-20 Thread egbert
My pygtk gui can not be started from a gnome panel, 
because, apparently, the panel doesn't know about my
modified PYTHONPATH. So how can I instruct the panel ?
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: checking if a string contains a number

2005-12-20 Thread egbert
On Tue, Dec 20, 2005 at 07:16:46PM +0530, Suresh Jeevanandam wrote:
>   s1 = '12e3'
>   s2 = 'junk'
>   Is there any other function which would return True for s1 and False 
> for s2.
> 

isinstance(12e3, (int, float))
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which feature of python do you like most?

2005-11-09 Thread egbert
python is almost pseudocode, 
so much so that you don't need pseudocode anymore.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: PyFLTK - an underrated gem for GUI projects

2005-11-07 Thread egbert
PyFLTK is not a debian package - yet. 
Is nobody interested, or is there a more specific reason ?
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Opaque documentation

2005-10-28 Thread egbert
Once in a while you come acros aline of documentation
that you have to, or that invites you to, read it again.
This is what I found in PyGTK:

The set_screen method sets the 'screen" property to 
the gtk.gdk.Screen specified by screen. The "screen" property
contains the screen that the window is displayed on.

The screen on the second line, before the period, is in italics, 
if that helps.

I like these texts. Prose should not disclose its secrets at once.
If you have other examples, please let us know.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


PyGTK color blackout

2005-10-23 Thread egbert
Without success I try to understand the color mechanism in PyGTK.
It's about the classes Color an Colormap, and their methods and
related functions and other paraphernalia.
If anyone knows about a tutorial-like systematic description, 
I will be very grateful.
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Hello gnome-terminal

2005-09-30 Thread egbert
When I start the following script in a gnome-terminal:

#!/usr/bin/env python
import os
print "hello gnome-terminal"
print os.environ["PYTHONPATH"]

I see the expected results in the same gnome-terminal window.

However starting this same script via a launcher in a panel,
a new gnome-terminal window is opened for output only,
and PYTHONPATH is an unknown entity.
How can I open a terminal over whose environment and
configuration I have more control ?
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python certification

2005-07-20 Thread egbert
On Wed, Jul 20, 2005 at 08:06:51AM -0700, Kay Schluehr wrote:
> Andreas Kostyrka schrieb:
> 
> > (These are the people look for Pearl and Pyhton programmers ;) )
> 
> Or Phyton :)

In 2000 we had already the Phyththon Misspelling Contest.
I presented then a regexp that could check if we were talking
about the same language. However I must apologize.
It didn't cover Pyhton. This is an improved version:

pc=re.compile(r'\bph?(ph)*[iye]+h?(th?)+o?n+e?\b',re.I)

As you see it covers pitn, and also spellings like pythonne,
to accomodate the francophones. 
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: map/filter/reduce/lambda opinions and background unscientific mini-survey

2005-07-03 Thread egbert
On Sat, Jul 02, 2005 at 08:26:31PM -0700, Devan L wrote:
> 
> Also, map is easily replaced.
> map(f1, sequence) == [f1(element) for element in sequence]
> 
How do you replace
map(f1,sequence1, sequence2)
especially if the sequences are of unequal length ?

I didn't see it mentioned yet as a candidate for limbo,
but the same question goes for:
zip(sequence1,sequence2)

-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Controlling assignation

2005-06-13 Thread egbert
On Mon, Jun 13, 2005 at 03:52:14PM +0200, Xavier Décoret wrote:
> In other word, I would like to be able to use a=5 instead of a.set(5)

If a(5) is acceptable to you in stead of a=5
you can make your instance callable with the __call__ method:


class A(object):
def __init__(self):
self.var=0
def __call__(self,val=None):
self.var=val

a = A()
a(5)
print a.var  # gives 5

egbert
--
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list


[OT] SQL-records and OOP

2005-05-30 Thread egbert
Each row of an sql table may be the data_part_in_spe  
of some class_instance.
I try to think about, and am looking for, the do's and don'ts 
and caveat's and the right way of thinking about this transformation.
For me it is new territory.

For instance, my sql-query produces much more rows than I am 
interested in eventually. So I have to narrow this collection.

I can inspect the data while it is still a list of rows,
and make instances of only the rows I really need.
Or I may create an aggregate of full-blown instances derived
from all the selected rows.

I suppose Google has lots to offer, but I must be looking 
in the wrong direction.

egbert
-- 
Egbert Bouwman - Keizersgracht 197 II - 1016 DS  Amsterdam - 020 6257991

-- 
http://mail.python.org/mailman/listinfo/python-list