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

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: 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