Global in multiple files
rnd at onego.ru
Sun Jun 10 09:21:18 EDT 2001
On 10 Jun 2001, Artur Skura wrote:
>I'm not a fan of OO but I decided to give it a try. After all, Python
>makes it elegant.
>So I wrote a program usuing classes, methods etc. All nice. Then it
>grew up and I decided to split it in several files - one class into
>each class as Guido asked us to do.
>And then, I came across my first problem: I had had a global variable
>(just one!) and it wouldn't work anymore. At all. Any 'global'
>declarations wouldn't help, and without it I'm lost.
Probably, you have 3 different globals: one per module.
>So, I thought I might be smarter than it. I would pass this
>variable to where I need it, but... it stil obstinately refuses to
>work. But then, my ex-global is a list of instances of a class,
>and methods in instances of another class won't accept it as
Why do you need global variable in the OOP design anyway?
Maybe, it belongs to os.environ or some container class?
I blame myself each time I maintain code with global variables:
the code can't be easily reconfigured, creates other problems.
Globals are allright only in short scripts which has no chance
to grow larger.
>So, any ideas how I should cope with that and be able to use my
>global variable in different clases in different files?
Sincerely yours, Roman Suzi
_/ Russia _/ Karelia _/ Petrozavodsk _/ rnd at onego.ru _/
_/ Sunday, June 10, 2001 _/ Powered by Linux RedHat 6.2 _/
_/ "Computers make very fast, very accurate mistakes." _/
More information about the Python-list