bloody freshman question regarding strings

Max M maxm at mxm.dk
Sun Jun 23 06:22:43 EDT 2002


Christian Guenther wrote:

> My biggest question at the moment is why can't I do something like this:
> 
> def mailmsg(severity message opts target recipient):
> 	# first create the message body
> 	msgbody="computer: " + COMPUTER + "\n
> 	         system:   " + SYSTEMTYPE + "\n
> 		 cpu:      " + CPUTYPE + "\n
> 		 kernel:   " + KERNELVER + "\n
> 		 date:     " + DATE + "\n
> 		 \n
> 		 severity: " + severity + "\n
> 		 message:  " + message + "\n\n"
> 
> 
> I want to generate messages - to concole and to mail-recipients - that
> show the status of user-processing. This message should include all the
> information you see above - they are stored in global vars - a severity
> and of course a message itself. Let alone, it just doesn't work and I
> know I do this in a nodo way, I just don't have alot of time left ;-)


A few approaches:

def mailmsg(severity, message, opts, target, recipient):
     # first create the message body
     msgbody = "computer: %s\n" % COMPUTER)
     "system:   %s\n" % SYSTEMTYPE)
     "cpu:      %s\n" % CPUTYPE)
     "kernel:   %s\n" % KERNELVER)
     "date:     %s\n\n" % DATE)

     "severity: %s\n" % severity)
     "message:  %s\n\n" % message


def mailmsg(severity, message, opts, target, recipient):
     # first create the message body
     bodyParts = []
     a = body.append
     a("computer: %s\n" % COMPUTER)
     a("system:   %s\n" % SYSTEMTYPE)
     a("cpu:      %s\n" % CPUTYPE)
     a("kernel:   %s\n" % KERNELVER)
     a("date:     %s\n\n" % DATE)
     a("severity: %s\n" % severity)
     a("message:  %s\n\n" % message
     msgbody = ''.join(bodyParts)


def mailmsg(severity, message, opts, target, recipient):
     # first create the message body
     msgbody = """computer: %(COMPUTER)s
system:   %(SYSTEMTYPE)s
cpu:      %(CPUTYPE)s
kernel:   %(KERNELVER)s
date:     %(DATE)s

severity: %(severity)s
message:  %(message)s

""" % vars()

regards Max M




More information about the Python-list mailing list