Re: Simple Python problem...

Tom Jones (tom@cs.su.oz.au)
16 Feb 1995 23:23:12 +1100

In article <D3yrLt.DLC@triple-i.com>, Douglas Harber <dh@triple-i.com> wrote:
>..but of course, I've been unable to solve it!
>
>I'm under the impression that I should be able to use a global value
>a function defined in a module, but for the life of me I can't get it
>to work! I know I must be missing something trivially stupid, so could
>somebody set me straight.
>
>In a module, say foo.py, I've got:
>
>import sys
>
>seqno = 0
>
>def SomeFunc():
> print 'Using serial #' + seqno
> seqno = seqno+1
>
>Thanks for any and all help!
>Doug Harber
>

It is simple!

If you are going to reference a global variable
in a function, you must put a line such as:

def SomeFunc():
global seqno
print 'Using serial ' + `seqno`:

Notice also that you can't print an integer type
you must convert it to a string......
(Thus the back-quotes)

tom

---------------------------------------------------------------
Thomas J. Jones | PHONE : +61 2 351-3503 | FAX: +61 2 351-3838
Basser Department of Computer Science, Sydney University
We have tamed lightning and used it to teach sand to think.
---------------------------------------------------------------