newbie help ?

Fredrik Lundh fredrik at pythonware.com
Fri May 16 02:15:34 EDT 2003


"Beanie" wrote:

> a) what is wrong witht hescript - got to be something simple most of it is
> hacked from examples

all statements inside the else clause must start in the same
column (Python uses indentation to figure out what belongs
to the same block).

if the problem you're seeing is a "SyntaxError" on the write-
lines line, all you have to do is to fix the indentation:

>  host = context.MailHost
>  host.send( mail_text )
>
>  RESPONSE.redirect( '%s?portal_status_message=%s' % ( referer, "Your
> discount code has been sent. Thank you." ) );

move this line to the left:

>         file.writelines(strCodes) #rewrite the file with missing code
>
> file.close()# close the file

also note that readlines and writelines don't rewind the file;
you should probably add an explicit seek before rewriting the
file:

    file.seek(0) # rewind
    file.writelines(strCodes) # rewrite the file with missing code

(yet another thing to look out for is locking; I don't know if Plone
can run multiple response handlers in parallel, but if it does, you
may end up sending the same code to multiple clients, or with a
seriously messed up code file...)

> b) where to get good resources on python scripting

start here:

    http://www.python.org

</F>








More information about the Python-list mailing list