[Tutor] Connecting to DB

Alan Gauld alan.gauld at freenet.co.uk
Thu Mar 9 00:55:47 CET 2006

Please use meangingful subject lines. I've changed this one.

>I need help to connect to db on Linux machine.
> When I do it manually -all right, try to execute script does not work.

I'm not quite sure what you expect here but...

> My script is simple:
> -------------------------------------------------------
> def Connect3():
>    #arg=os.system('sql.py --prompt qa2:adsdb
> inbl27,inbl27,inbl27:root:adsgoogle:qa2ads0,qa2ads1')
>    arg=os.popen('sql.py --prompt qa2:adsdb
> inbl27,inbl27,inbl27:root:adsgoogle:qa2ads0,qa2ads1')
> Connect3() 

Your script is simple but does nothing useful. 
It calls popen with a command line(which is the one I assume you 
used at the command line?) and stores the pipe returned by popen 
in arg. It then exits the function which deletes arg and therefore 
the pipe and its connection.

At no point do you try to read the output from your commandline, 
nor do you return anything to the outer part of your script. And of 
course we have no idea what sql.py does inside, so I'll just assume 
it works as intended for now

What did you think this would do?

Alan G
Author of the learn to program web tutor

More information about the Tutor mailing list