Re: object vs class oriented -- xotcl

2008-01-31 Thread neumann
On 29 Jan., 19:22, William Pursell <[EMAIL PROTECTED]> wrote:
>  I
> believe "per object mixin" is the correct
> term for such an animal.  The first several google
> hits on that phrase all reference xotcl, so I'm
> not sure if that is an xotcl inspired vocabulary
> that isn't really standard.

well, it depends, what you mean by "standard" when it comes
to mixins. We coined the term to distinguish between per
object and per class mixins, where the per objects mixins
have much in common with the decorator design pattern (see
e.g. http://nm.wu-wien.ac.at/research/publications/xotcl-objpattern.pdf)

We have as well a paper showing that the approach based on
intersection
classes does not scale well, especially when multiple supplemental
classes should be mixed in, and some of the behavior should be as well
mixed out (see e.g. section 3.3 in 
http://nm.wu-wien.ac.at/research/publications/xotcl-mixin.pdf)

If you are interested in the matter, we have as well a recent paper
http://nm.wu-wien.ac.at/research/publications/b613.pdf providing
declarative semantics for mixins, and there is many more related
papers in the publications section of media.wu-wien.ac.at
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: While loop - print several times but on 1 line.

2006-01-26 Thread Stefan Neumann


Danny wrote:
> How could I make this print: texttexttexttexttext?
> Ive researched and looked through google and so far I can't find 
> anything that will help (or revelent for that matter).

I am not quite sure, if I simplify the problem but i thought about
something like that:

>>> print "text"*5
texttexttexttexttext

cheers

Stefan

pgp470Yem6sNX.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Daemon terminates unexpected

2006-02-06 Thread Stefan Neumann
I have written a daemon which should run endlessly. The structure looks
like this:

- start-stop-daemon forks my python program

then:

if __name__=="__main__":
try:
main()
except Exception,e


def main():
# I need a starter to use the program also from the unittests
starter=starter()
starter.start()

while True:
#TODO: Catch kill signal
# I know, dirty
sleep(10)

class Starter(Thread):

def __init__():
Thread.__init__(self)

self.setDaemon(True)

def run(self):
try:


The problem is now that the SMTP-Server quits donig its work. First I
thought, there will be an exception be thrown but actually, after
catching all global exceptions there is no log entry for it.

I really don't know why my program terminates. It happens nearly
regularly after five days.

Why I think, everything works correctly (correct me, if I am wrong):

Main will actually live forever because of the endless loop.
It starts a thread, which is set as daemon. This daemon will live until
all non daemon threads have terminated. So why does this program end?

I have read somethong about double-fork, can someone explain, why to use
this way for starting a daemon?

Thanks in advanced.

Stefan

pgpWIkZJooXfQ.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: removing characters before writing to file

2006-02-09 Thread Stefan Neumann
[EMAIL PROTECTED] wrote:
> hi
> i have some output that returns a lines of tuples eg
>
> ('sometext1', 1421248118, 1, 'P ')
> ('sometext2', 1421248338, 2, 'S ')
> and so on
> 
>

If the braces are always at the begining and at the end of the string,
you could also use:

>>> "('sometext1', 1421248118, 1, 'P ')"[1:-1]
"'sometext1', 1421248118, 1, 'P '"

cheers
Stefan

pgpEdJ9SLHXXB.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: recall function definition from shell

2010-05-18 Thread René 'Necoro7; Neumann
Am 18.05.2010 20:55, schrieb superpollo:
> 
> yes python does not, but maybe the *shell* does, or so i thought. i just
> wanted to dump the code for the function in a file, after i tested in
> the shell...

You might want to have a look at the IPython shell [1]. I personally do
not use it myself, but I thought to remember that it had some feature
like this (perhaps not dump _one function_, but all the input, which you
then only need to cleanup).

A quick glance revealed f.ex. the history and edit functionality [2] --
a bit more digging might really show up the thing you are looking for.

- René

[1] http://ipython.scipy.org/
[2]
http://ipython.scipy.org/doc/manual/html/interactive/tutorial.html#source-code-handling-tips




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-19 Thread René 'Necoro7; Neumann
Am 19.05.2010 21:58, schrieb superpollo:
> ... how many positive integers less than n have digits that sum up to m:
> 
> In [197]: def prttn(m, n):
> tot = 0
> for i in range(n):
> s = str(i)
> sum = 0
> for j in range(len(s)):
> sum += int(s[j])
> if sum == m:
> tot += 1
> return tot
>.:
> 
> In [207]: prttn(25, 1)
> Out[207]: 348
> 
> any suggestion for pythonizin' it?
> 
> bye

An idea would be:

>>> def prttn(m, n):
... return sum(1 for x in range(n) if sum(map(int, str(x))) == m)

A small oneliner :)

(I first had "return len([x for x in ...])" but the above avoids
creating an intermediate list)

- René



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: function that counts...

2010-05-19 Thread René 'Necoro7; Neumann
Am 19.05.2010 22:58, schrieb superpollo:
> 
> In [277]: prttn(25, 1)
> Out[277]: 348
> 
> In [278]: prttn2(25, 1)
> Out[278]: 348
> 
> In [279]: prttn3(25, 1)
> Out[279]: 348
> 
> ok, bye!

Just because I was curios:

nec...@zakarumiy ~ % python -m timeit "import test; test.prttn(25,1)"
10 loops, best of 3: 108 msec per loop

nec...@zakarumiy ~ % python -m timeit "import test; test.prttn2(25,1)"
10 loops, best of 3: 157 msec per loop

nec...@zakarumiy ~ % python -m timeit "import test; test.prttn3(25,1)"
10 loops, best of 3: 137 msec per loop

Note: This is probably not representative ... just a quick check to get
a raw feeling.

- René



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list