global variables or inheritence

Shae Erisson shae at webwitches.com
Wed Apr 26 23:40:16 CEST 2000


Thomas Rasmussen wrote:

> Well I still want to be able to do this....
> 
>   >>  testprog2.py: import os, sys, string, testprog1 def second():
>   >> print testprog1.myvar if __name__ == '__main__': print 'nope'
>   >>

> Well i'm programming a small admin tool, which must use the users
> $EDITOR for editing files. This works fine if the EDITOR sysenv is
> set, if not, then i want to ask the user which editor he want to use,
> and then pass this variable to the module that handles
> filemanipulation. This modules is also in another file if it
> matters... I must add that this is my first real program made in
> python...

this is untested code, but it might give you some ideas:

import os
import usefulmodule

def ask():
    usereditor = raw_input("What's your choice of editor?")
    return usereditor

try:
    usereditor = os.environ['EDITOR']
except KeyError:
    usereditor = askforeditor()

usefulmodule.dostuff(usereditor)

-- 
sHae mAtijs eRisson (sHae at wEbwitchEs.coM) gEnius fOr hIre
   bRing mE fIve sQuirrels aNd nO oNe wIll gEt hUrt
13:00pm up 1 season, 1 squirrel, load average: 1+1j 0.5+2j 0.2+0.5j



More information about the Python-list mailing list