A class with built-in doctest feature ?

2006-02-01 Thread Runsun Pan
I intend to use the doctect heavily. For this I am thinking of
coding a class that comes with a built-in doctest functionality.
I'd like to seek for input before I start.

The idea is to have a class MyObj from where all my other
classes will subclass.

lets say:

   class C(MyObj):
''' This C
  (some doctest here)  doctest.1
'''
def func1(self):
 ''' This is C.func1
(some doctest here) --- doctest.2
 '''
 blah blah blah
 return blah

Now, after the above class defintion, I can just do:

C( ).doctest( )

and it will go through doctest.1 and doctest.2 and report the
test results

What is the better way to make such a MyObj ?

The applications of this sort of built-ins are not limited to
a doctest. Similar to the built-in __doc__ that offers some sort
of documentation, a mechnism like what I am proposing can
provide "customization on the fly" feature to allow manipulations
of the doctext at run-time. For example,

C( ).toHtml( )

to convert the __doc__ to a webpage by converting it throu
reStructuredText.

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: OT: Re: Using non-ascii symbols

2006-01-31 Thread Runsun Pan
>From 1387-1814, a ~430 years period, that's quite a long time.
About the total recountable history of Taiwan... :)

In her 400 some history Taiwan has been occupied by several
foreign powers, including Dutch, Tsing Dynasty from China, Japan,
and KMT party from China again. The long time fight against foreign
powers were all futile, resulted in a 'macro-personality' of getting used
to be slaves.

The mentality of being slaves is that when you have the chance to
play master yourself, you still look up to the old master to either get
approval or beg for mercy. This resulted in a bizzard situation in current
Taiwan that even a local-based, democratic government was elected,
the old foreign power is still the underground power that truly control
all aspects of Taiwan. They reject whatever policies the democratic
government plan. Many nation-wide constructions that the old power
planned and supported when they were in power, they turn their positions
into rejecting those them.

The slave mentality of the public is something that help those old power
to paralize the society. With that, a language reform to reduce the cultural
influence of the foreign power is therefore hopeless in Taiwan (at least
currently).

Maybe Norwegians have some sort of that mentality too ? Considering
that they rather to elect people from the old foreign power ...


On 1/29/06, Magnus Lycka <[EMAIL PROTECTED]> wrote:
> Runsun Pan wrote:
> > The simplified chinese exists due to the call for modernization of
> > language decades ago. That involved the 'upside-down' of almost
> > entire culture
> This is in some ways quite the opposite compared to Nynorsk
> in Norway, which was an attempt to revive the old and pure
> Norwegian, after being dominated (in politics as well as in
> grammar) by Denmark from 1387-1814. (I guess it was a
> complicating factor that the end of the union with Denmark
> led to a union with Sweden. The Norwegians probably had some
> difficulties deciding what neighbour they disliked most. When
> they broke out of the union with Sweden in 1905, they actually
> elected a Danish prince to be their king.) Anyway, only a
> fraction of the Norwegians use Nynorsk today, and the majority
> still speak the Danish-based bokmål. On the other hand, the
> spelling of bokmål has also been modernized a lot, with a
> series of spelling reforms of both languages.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


A class with eventhandlers ?

2006-01-29 Thread Runsun Pan
Is it possible to code a class that raise exception
automatically when an error occurs?

We usually use try-except pair at where we expect an
error might occur. What am thinking is a class that
has built in error handling so we can do this:

c=MyClass()
c.onError = some_hook

or

c.onError('IndexError', IndexErrorHook)

or, more specific, a function/method-specific error
handling feature:

c.load.onError( IOErrorHook)
c.load( filename )

Is there such a mechnism around? If not, is it possible
to make such a thing ?

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using non-ascii symbols

2006-01-27 Thread Runsun Pan
On 1/27/06, Terry Hancock <[EMAIL PROTECTED]> wrote:
> Well, let's just say, I think there should be different
> standards for "write once / read once" versus "write once /
> read many".  The mere use of written language once implied
> the latter, but I suppose text messaging breaks that rule.

Since we are on this, let me share with you guys a little 'ice-tip'
for how the younger generations in Taiwan communicate:

  A: why did you tell av8d that I am a bmw ?
  B: Well, you are just like one of those ogs or obs ...
  A: oic, you think you are much q than I ?
  B: ...
  A: I would 3q if you stop doing so.
  B: ok.
  A: Orz
  B: 88
  A: 881

Can you guys figure out the details ?

Here is the decoded version:

  A: why did you tell av8d that I am a bmw ?
[8 in our language is pronounced as "ba", so av8d = everybody]

  B: Well, you are just like one of those ogs or obs ...
[ogs= oh-ji-sang, obs=oh-ba-sang, Japanese, means old guy, old
woman, respectively]

  A: oic, you think you are much q than I ?
[oic=Oh I see; q = cute]

  A: I would 3q if you stop doing so.
[ 3q = thank you ]

  B: ok.

  A: Orz
[ appreciate very much --- it looks like a guy knee down when seeing an Empire ]

  B: 88
[ bye-bye ]

  A: 881
[ bye-bye with a tone, sometimes 886 = bye-bye-loh ]

The above example is just an extremely simple one. In the real world,
they combined all sort of language sources --- mandarine, japanese,
english, taiwanese ... as well as "shape" like Orz.

This kind of mixture-of-everything is widely used in young
generations, sometimes called "net terms", sometimes called "Martian
words". It faciliates the online activities among youngists, but
creates huge 'generation gaps' --- some dictionaries were published
for high school teachers to study in order for them to talk and
understand their students.

IMO, a language is a living organism, it has its own life and often
evolves with unexpected turns. Maybe in the future some of those
Martian Words will become part of formal Taiwanese, who knows ? :)

> First of all, they are, much more than Western alphabets,
> strict about stroke order and direction (technically the
> Roman alphabet is supposed to be drawn a certain way, but
> many people "cheat" -- I think that's harder to get away
> with with Asian characters, because they tend not to look
> right when drawn wrong).  And when you have the actual
> stroke sequence data as input, recognition is easier and
> more reliable (I think that was the point behind the
> "graffiti" system for the Palm Pilot).

But ... to my knowledge, all of the input tablets that using OCR has a
training feature. You can teach the program to recognize your own
order of strokes. The ability to train (be trained) is a very key
element of such an input device.

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using non-ascii symbols

2006-01-27 Thread Runsun Pan
On 1/27/06, Magnus Lycka <[EMAIL PROTECTED]> wrote:
> > After taking a couple of semesters of Japanese, though, I've
> > come to appreciate why they are preferred.  Getting rid of
> > them would be like convincing English people to kunvurt to
> > pur fonetik spelin'.
> >
> > Which isn't happening either, I can assure you. ;-)
> The Germans just had a spelling reform. Norway had a major
> language reform in the mid 19th century to get rid of the old
> Danish influences (and still have two completely different ways
> of spelling everything). You never know what will happen. You
> are also embracing the metric system, inch by inch... ;)

The simplified chinese exists due to the call for modernization of
language decades ago. That involved the 'upside-down' of almost
entire culture --- nowadays people in China can't even read most of
the documents written just 70~80 years ago. Imagine its damage
to the 'historical sense' of modern chinese !!! The "anti-simplification"
force was thus imaginaribly huge. Actually, not only the original
plan of simplification wasn't completed (only proceded to the 1st
stage; the 2nd stage was put off), there are calls for reversal -- back
to the traditional forms -- lately. Obviously, language reform is not
trivial; Especially, for asian countries, it is probably not as easy as it
is for western countries.

China is still a central authoritarian country. Even with that government
they were unable to push this thru. If any one would even dream about
language reform in democratic Taiwan, I bet the proposal won't even
pass the first step in the congress.

> Actually, it seems that recent habit of sending text messages
> via mobile phones is the prime driver for reformed spelling
> these days.

Well, to solve the problem you can either (1) reform the spelling
of a language to meet the limitation of mobile phones, or (2)
advancing the input device on the mobile phones such that they
can input the language of your choice. For most asian languages,
(1) is certainly out of question.

> > I'm not sure I understand how this works, but surely if
> > Python can provide readline support in the interactive
> > shell, it ought to be able to handle "phrase input"/"kanji
> > input."  Come to think of it, you probably can do this by
> > running the interpreter in a kanji terminal -- but Python
> > just doesn't know what to do with the characters yet.
> I'm sure the same principles could be used to make a very fast
> and less misspelling prone editing environment though. That
> could actually be a reason to step away from vi or Emacs (but
> I assume it would soon work in Emacs too...)

True. Actually Google, Answers.com and some other desktop
applications use 'auto-complete' feature already. It might seem
impressive to most western users but, from where I was from
(Taiwan), this 'phrase-input', as well as "showing up in the order
of the most-frequently-use for any specific user", have been
around for about 20 years.

>> I would like to point out also, that as long as Chinese
>> programmers don't go "hog wild" and use obscure characters,
>> I suspect that I would have much better luck reading their
>> programs with han characters, than with, say, the Chinese
>> phonetic names!  Possibly even better than what they thought
>> were the correct English words, if their English isn't that
>> good.
> You certainly have a point there. Even when I don't work in an
> English speaking environment as I do now, I try to write all
> comments and variable names etc in English. You never know when
> you need to show a code snippet to people who don't read Swedish.
> Also, ASCII lacks three of our letters and properly translated
> is often better than written with the wrong letters.

If there will be someday that any programming language can
be input with some form like Big5, I believe its intended target
will ONLY be people using only Big5. That means, if it exists, the
chance of showing it to other-language-users probably be extremely
nil, Think about this: there are still a whole lot of people who don't
know English at all. If no such a 'Big5-specific' programming
tool around, their chances of learning programming is completely
rid off.

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mining strings from a HTML document.

2006-01-26 Thread Runsun Pan
>def extract(text,s1,s2):
>''' Extract strings wrapped between s1 and s2.
>
>>>> t="""this is a test for extract()
>that does multiple extract """
>>>> extract(t,'','')
>['test', 'extract()', 'does multiple extract']
>
>'''
>beg = [1,0][text.startswith(s1)]
>tmp = text.split(s1)[beg:]
>end = [len(tmp), len(tmp)+1][ text.endswith(s2)]
>return [ x.split(s2)[0] for x in tmp if len(x.split(s2))>1][:end]

> Could you/anyone explain the 4 lines of code to me though? A crash
> course in Python shorthand? What does it mean when you use two sets of
> brackets as in : beg = [1,0][text.startswith(s1)] ?

The idea is using .split( ) to cut the string in different manners.
For a string:

 -AderickBArunsunB--

first cut at A gives you  [-, derickB--, runsunB-]   (line-1,2)
2nd cut at B gives you  [ derick, runsun ](line-3,4)

The function uses list comprehension heavily. As Magnus already explained,
line-1 is just a switch. Same as line-3. These two lines exist to solve the
difference between

 -AderickBArunsunB--
 AderickBArunsunB--

or

 -AderickBArunsunB--
 -AderickBArunsunB

That is, if the original raw string startswith or ends with s1 or s2, special
consideration should be taken.

Line-2 and -4 are just common practice of list slicing that u should be
able to find in any python tutorial.

Let us know if it's still not clear.

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using non-ascii symbols

2006-01-26 Thread Runsun Pan
On 1/26/06, Terry Hancock <[EMAIL PROTECTED]> wrote:
> On Thu, 26 Jan 2006 01:12:10 -0600
> Runsun Pan <[EMAIL PROTECTED]> wrote:
> > Error) in python. I'd love to see if I can use han char
> > for all those keywords like import, but it doesn't work.
>
> Yeah, I'm pretty sure we're talking about the future here.

How do you like this (see below) as a python program ?
 :) :)

#-- han python
輸入 操作系統
顯示 操作系統.path.realpath( 操作系統.目前目錄 )
a 等於 3 加 15
顯示 a

對於 i 在 (範圍(5)): 顯示 '(%s)'%(i 加 4)
#-- end

The following file does work:

##   test_hanzi.py  BEGIN

charmap={
'顯示': 'print',
'輸入': 'import',
'加'  : '+',
'在'  : 'in',
'等於': '=',
'目前目錄': 'curdir',
'操作系統': 'os',
'對於': 'for',
'範圍': 'range',
}

file = 'c:/t/test_hanzi_script.py'

def convert(raw, charmap=charmap):
for k,v in charmap.items():
raw = raw.replace( k,v)
return raw

def exehan(raw):
doc = convert(raw)
print '-'*20,'\n','Converted doc:'
print doc
print '-'*20
open(file, 'w').write( doc )
s = os.popen('python '+ file, 'r').read()
print 'Output of the raw:\n'
print s
    return s

#--

raw='''
輸入 操作系統
顯示 操作系統.path.realpath( 操作系統.目前目錄 )
a 等於 3 加 15
顯示 a

對於 i 在 (範圍(5)): 顯示 '(%s)'%(i 加 4)
'''

exehan(raw)

##   test_hanzi.py END


Certainly, this kind of approach is not very practical.

--
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
Runsun Pan, PhD
[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/
~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Using non-ascii symbols

2006-01-25 Thread Runsun Pan
I am not Chinese but I can read and write han characters (in Traditional 
Chinese format (Big5 encoding) that is basically popular in Taiwan ). 
 
For the tests that I tried earlier, using han characters as the variable 
names doesn't seem to be possible (Syntax Error) in python. I'd love
to see if I can use han char for all those keywords like import, but it
doesn't work.   
On 1/25/06, Christoph Zwerschke <[EMAIL PROTECTED]> wrote:
These were some interesting remarks, Terry.I just asked myself how Chinese programmers feel about this. I don't
know Chinese, but probably they could write a whole program using onlyone-character names for variables, and it would be still readable (atleast for Chinese)... Would this be used or would they rather prefer to
write in English on account of compatibilty issues (technical and humanreadability in international projects) or because typing these chars ismore cumbersome than ascii chars? Any Chinese here?
 
That depends. People with ages in the middle or older probably have very
rare experience of typing han characters. But with the popularity of computer
as well as the development of excellent input packages, and most importantly,
the online-chats that many teenagers hooking to, next several geneartions 
can type han char easily and comfortably.  
 
One thing that is lack in other languages is the "phrase input" almost every 
han input package provides this customizable feature. With all these combined, 
many of youngesters can type as fast as they talk. I believe many of them input 
han characters much faster than inputting English.
  
The "side effect" of this technology advance might be that in the future the 
simplified chinese characters might deprecate, 'cos there's no need to simplify 
any more.
 
-- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Runsun Pan, PhD[EMAIL PROTECTED]Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Being unjust

2006-01-22 Thread Runsun Pan
On 22 Jan 2006 20:35:17 -0800, Ian Bicking <[EMAIL PROTECTED]> wrote:
understandably slow release schedule of Python itself.  I think thestandard library is only appropriate for solved problems, where the
area is well understood.  Just look at how much time it took to getdecimal and datetime in, both of which cover *very* well understoodareas.
That's one of the reasons that I suggested earlier for a "bare gui core" (BGC)-- a core that only deals with all the common features a gui should have, like positions, sizes, color, font, event ... just a frame for how these elements connect to the objects internally, but didn't deal with the real style/event rendering. This core should be designed in a way that they can be easily wrapped or connected to some major gui packages that deal with the real painting, sizing ... stuff.

 
Therefore, a current python gui programming flow:
 
   python --> gui package(s)   #  "belief" wars fighting among packages
   #   if one of them would be chosen as py lib
 
would become:
 
   python --> bare core  --> gui package(s)
 
Since this core also provides mechnisms to channel to popular gui packages:
 
   core.toGui( 'html' )    
   core.toGui( 'wxPython' )
   core.toGui( 'webware' ) 
   ... 
 
So, users don't have to worry about learning a whole bunch of different packages, yet they have all the convinience of using any packages of their choice. This would also make the comparison of packages much easier --- write one set of code, test which packages fit you best. 

 
And, this BGC doesn't have to wait until the concept mature. The concept of gui on desktop has already pretty much matured. This BGC can take the advantage of desktop gui and grow with web gui.
 
Another "might-be-very-useful" of BGC is that: if any package provides a "reversed toGui" that converts the package-specific code back to BGC, then users can take, for example, a wxpython code, convert to html page in one step. For the package developers, if this 'to html' is what they have in mind, now they only have to worry about converting their code to BGC, but not all those html-specific details.
-- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Runsun Pan, PhD[EMAIL PROTECTED]Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: LocaWapp: localhost web applications (v.03 - 2005 Dec 31)

2006-01-22 Thread Runsun Pan

On 1 Jan 2006 08:15:42 -0800, LocaWapp <[EMAIL PROTECTED]> wrote:
http://cheeseshop.python.org/packages/source/L/LocaWapp/locawapp-03.tar.gz

 
 

Not Found
The requested URL /packages/source/L/LocaWapp/locawapp-03.tar.gz was not found on this server.
 
-- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Runsun Pan, PhD[EMAIL PROTECTED]
Nat'l Center for Macromolecular Imaginghttp://ncmi.bcm.tmc.edu/ncmi/~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Read from Serial Port

2006-01-21 Thread Runsun Pan
How about reading from the USB ports ?-- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Runsun Pan, PhD[EMAIL PROTECTED]Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Being unjust

2006-01-18 Thread Runsun Pan
I would prefer to see a core gui library that has a dom like structure and the core lib doesn't really define the interface but only serves as "an interface to other interfaces". 
 
For example, a button class in this library will work like this :
 
   b = Button('Submit')
   b.setStyles( {'backgroundColor': 'yellow', 'fontSize': 20} ) 
   ( which can also be done with: 
  b.style.backgroundColor='yellow'
  b.style.fontSize = 20
   )
   # Define the style change when mouse over it
   b.onMouseOver.style = { 'backgroundColor':'red', 'fontColor':'blue' }   
 
   # Define what happen when mouse over it
   b.onMouseOver.action = "" 'Click to submit the article' )
 
That means, b.onMouseOver returns an "Event" object that has .style and .action.
 
   b.onClick.action = "" 
 
   b.stickTo( 'right-top' )   # stick to the right-top corner of its parent (whatever it's parent is)
 
   p = Panel( )
   p.add( b ) # This also defines b.parent= p, so b will stick to right-top of p
   ..
   ...
The above are the 'core style and behavior', doesn't define to where those style and behavior will apply. 
 
Now comes the real fun part: 
 
Define a mechnism to allow this "core styles and actions" be applied to different "faces" the choice of users. 
 
For example, 
 
   print p.toGui( face = 'html')   # generate a webpage
   
   p.toGui( face = 'wxPython' ).run  # generate a desktop program, using wxpython
 
There are many advantages for this sort of "universal gui core". At least, a user will only need to learn one set of gui approach.
 
 
-- ~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~Runsun Pan, PhD[EMAIL PROTECTED]Nat'l Center for Macromolecular Imaging
http://ncmi.bcm.tmc.edu/ncmi/~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~ 
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: list-comprehension and map question (simple)

2005-03-30 Thread runsun pan
Thx, Robert. I did some tests:

>>> xs = range(1)
>>> ys = range(0,2,2)
>>> def m1(x, count=100):
... for c in range(count):
...y = map(float, x)
... return y
>>> def L1(x, count=100):
... for c in range(count):
...y = [float(z) for z in x]
... return y
>>> def m2(xs, yx, count=100):
... for c in range(count):
... y = map(lambda x,y: x+y, xs, ys)
... return y
>>> def L2(xs, yx, count=100):
... for c in range(count):
... y =[x+y for x,y in itertools.izip(xs, ys)]
... return y

>>> profile.run('m1(xs)')
 105 function calls in 0.991 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1000.4840.0050.4840.005 :0(map)
10.0000.0000.0000.000 :0(range)
10.4850.4850.4850.485 :0(setprofile)
10.0220.0220.5060.506 :1(m1)
10.0000.0000.5060.506 :1(?)
10.0000.0000.9910.991 profile:0(m1(xs))
00.000 0.000  profile:0(profiler)

>>> profile.run('L1(xs)')
 5 function calls in 0.724 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
10.0000.0000.0000.000 :0(range)
10.0000.0000.0000.000 :0(setprofile)
10.7240.7240.7240.724 :1(L1)
10.0000.0000.7240.724 :1(?)
10.0000.0000.7240.724 profile:0(L1(xs))
00.000 0.000  profile:0(profiler)

>>> profile.run('m2(xs, ys)')
 1000105 function calls in 6.171 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1003.3360.0336.1490.061 :0(map)
10.0000.0000.0000.000 :0(range)
10.0000.0000.0000.000 :0(setprofile)
10.0220.0226.1716.171 :1(m2)
  1002.8130.0002.8130.000 :3()
10.0000.0006.1716.171 :1(?)
10.0000.0006.1716.171 profile:0(m2(xs, ys))
00.000 0.000  profile:0(profiler)

>>> profile.run('L2(xs, ys)')
 5 function calls in 0.418 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
10.0000.0000.0000.000 :0(range)
10.0000.0000.0000.000 :0(setprofile)
10.4180.4180.4180.418 :1(L2)
10.0000.0000.4180.418 :1(?)
10.0000.0000.4180.418 profile:0(L2(xs, ys))
00.000 0.000  profile:0(profiler)

First of all, map(float, some_list_of_numbers) didn't seems to be
faster than [float(x) for x in some_list_of_numbers]. Maybe I did the
test in a wrong way ?

Secondly, [x+y for x,y in itertools.izip(xs, ys)] did go much faster
than map(lambda x,y: x+y, xs, ys). The latter is not only the slowest
one, but with an amazingly slow speed of 15 times slowdown.

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


Re: instance vs class attributes

2005-03-29 Thread runsun pan
>>> shy._Shy__mangled_method()
Ive been mangled!


Hi Brian,

can you explain how this could possibly work? First of all it's not
standard python usage,
and secondly it's not working on my computer... 

pan

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


Re: Overriding methods in classes you don't control

2005-03-28 Thread runsun pan
good point, andy.

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


Re: list-comprehension and map question (simple)

2005-03-28 Thread runsun pan
I remember reading somewhere that the map, filter, reduce are much
faster than list comp.

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


Re: Overriding methods in classes you don't control

2005-03-28 Thread runsun pan
Some untested idea:

1. find what is the base class of wxPython
2. x= subclass from that base class
3. make wxPython.__base__ = x

Don't know if this works, but this is what I would try if I were u
('cos its ease).

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


Re: Newbie Shell Editor Question

2005-03-28 Thread runsun pan
whatever you type after the >>> is either a statement that command
python to do something (like "print 'hello'"), or an object that might
or might not contain/return a value. The 'hello' you typed (the one
that caused error) is simply a word. It is not a command, it is not a
variable, it is not an object. Compare to this:

>>> print "Hello"
Hello
>>> hello=3   # assign 3 to a variable 'hello'
>>> hello   # Now hello is a variable containing 3
3

when you typed :

>>> hello

python will try to look for any variable named 'hello' in order to
investigate its content for return. But it can't find it because you
didn't define it.

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


Re: String Splitter Brain Teaser

2005-03-28 Thread runsun pan
For the fans of funtional programming:

>>> s='ATT/GATA/G'
>>> [y.split('/') for y in (' '.join([x for x in s]).replace(' / ',
'/')).split()]
[['A'], ['T'], ['T', 'G'], ['A'], ['T'], ['A', 'G']]

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


Re: tree data structure

2005-03-26 Thread runsun pan
couple of links for python tree:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/217212
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/201423
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305313
http://www.rexx.com/~dkuhlman/

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