Newbie's unsurmountable pb with IO stream trick

Gerhard Häring gerhard.haering at
Tue Sep 3 10:45:52 CEST 2002

"Spendius" wrote:
> Peter Hansen <peter at> wrote in message...
>> And what does not declaring variables have to do with the "global
>> keyword issue" (whatever that is)?
> I kept getting the error message # UnboundLocalError: local variable
> 'cpt' referenced before assignment where I really didn't expect to get
> such an error, and noticed in this forum a lot of guys who know Python
> complain and talk themselves about a "mess" (my 'cpt' var. is a counter
> incremented every time a method gets called and I must sometimes
> re-initialize it to 0 inside an 'if' statement: merely IMPOSSIBLE). 

def setToZero():
    global cpt
    cpt = 0

Merely impossible.

>> If you have an SQL database to access, why not use one of the
>> standard DBAPI modules to get to it?  You might be doing a lot
>> of extra work when you don't have to.
> And why not ? Anyway SQL*Plus contains plenty of built-in commands
> that allow you to format your output how you like:

Probably still easier to do with Python code.

> I'd like to keep that functionality. And let's say that I want to do that
> for the sole purpose of learning the handling of IO streams in Python!

The popen functions should be useful to interface SQL Plus. I just tried to
do so, but didn't succeed.

>> If you're just learning Python, you've taken on a fairly
>> complicated and large task right at the beginning.  Why not
> I admit it. But I did *exactly* the same with Java (writing the app I'm
> trying to port) but never got stuck into problems that blocking...

Having to use multithreading in Java to get the desired behaviour doesn't
sound too sexy for me.

-- Gerhard

More information about the Python-list mailing list