[Tutor] basic python question/getting values

Carroll, Barry Barry.Carroll at psc.com
Tue Jan 2 21:22:44 CET 2007


Joe:

See below:

> -----Original Message-----
> Date: Tue, 2 Jan 2007 19:16:33 +0000 (UTC)
> From: Joe M <moray at sdf.lonestar.org>
> Subject: [Tutor] basic python question/getting values
> To: tutor at python.org
> Message-ID: <Pine.NEB.4.62.0701021857340.23688 at sdf.lonestar.org>
> Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed
> 
> I apologize in advanced as I know this is basic information, but I
cannot
> seem to figure it.
> 
> 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
> 
<<snip>>
> 
> import dbping
> l = dbping.db_run(db_run.dbRunning) # 
> print l
> 
> NameError: name 'db_run' is not defined

You are not calling the function you defined. The name and number of
parameters are both wrong.  To match your function definition, your
assignment should be:

>>> l = dbping.db_alive()

Note, also, that the "pass" statement in dbping.db_alive will cause a
syntax error.  "pass" is only used when a code block is required but has
no executable statements.  For example:

>>> intval = 0
    .
    .
    .
    try:
        intval = int(strval)
    except ValueError:
        pass
        # strval is not a valid string representation of an integer.
        # intval remains 0.
        # Suppress the error and continue the program.  


> 
> Thanks for any pointers
> 
> moray at sdf.lonestar.org
> SDF Public Access UNIX System - http://sdf.lonestar.org
> 

HTH.

Regards,
 
Barry
barry.carroll at psc.com
541-302-1107
________________________
We who cut mere stones must always be envisioning cathedrals.

-Quarry worker's creed





More information about the Tutor mailing list