[Tutor] basic python question/getting values
Kent Johnson
kent37 at tds.net
Tue Jan 2 20:54:14 CET 2007
Joe M wrote:
> I have a few scripts that will return a value ie here I am testing to see
> if a database is alive (script is called dbping.py):
>
> def db_alive():
> dbRunning = '0'
> try:
> con = pg.connect(dbname='xxx', host='localhost', user
> ='xxx',port = xxx)
> pass
> except pg.InternalError:
> dbRunning = '1'
> return dbRunning
>
> This should return a value of 1 if the db is not running else it will
> return a value of 0.
>
> Ok, now I want to call this from another script and have it write
> to a file with the return value (and other values to be added later, but
> right now all I am interested in in getting the return values)
>
> I tried this sort of thing but it doesn't work (I will be writing to a
> file later, but right now getting it to print the value of dbRunning would
> be nice)
>
> import dbping
> l = dbping.db_run(db_run.dbRunning)
> print l
>
> NameError: name 'db_run' is not defined
What is db_run? What happens if you try
l = dbping.db_alive()
??
Kent
More information about the Tutor
mailing list