Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
use of global
#3
Thx for the very quick reply. I had read that information already before, and I think that my "test" scripts are in line with what is recommended there. Still, it does not function as intended.
I have attached here my two scripts (the main script that is ran, and the imported script with the functions:
# this is file "testglobalsextmain.py"

from testglobalsextimport import *

global a,b,c

a = "a"
b = "b"
c = "c"
x = "?"

print ("main ",a,b,c,x)
    
d=f1(a)
d=f2(a)
b = "b2"
d=f2(a)

print ("end  ",a,b,c,x)

#and

# this is file "testglobalsextimport.py"

def f1(x):
    global a,b,c
    b = "f1b"
    c = "f1c"
    print ("f1   ",a,b,c,x)
    
def f2(x):
    global a,b,c
    print ("f2   ",a,b,c,x)
When I run the "main" script, I get this output:
Output:
>>> RESTART: G:\UserData\Willy\Documents\Willys_Programmas\Test_routines\testglobalsextmain.py main a b c ? Traceback (most recent call last): File "G:\UserData\Willy\Documents\Willys_Programmas\Test_routines\testglobalsextmain.py", line 14, in <module> d=f1(a) File "G:\UserData\Willy\Documents\Willys_Programmas\Test_routines\testglobalsextimport.py", line 7, in f1 print ("f1 ",a,b,c,x) NameError: name 'a' is not defined >>> Can anybody please tell me what I did wrong?
Reply


Messages In This Thread
use of global - by wpo - Sep-30-2019, 08:53 AM
RE: use of global - by buran - Sep-30-2019, 09:00 AM
RE: use of global - by wpo - Sep-30-2019, 09:13 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 10:28 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 10:34 AM
RE: use of global - by buran - Sep-30-2019, 10:33 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 12:48 PM
RE: use of global - by wpo - Sep-30-2019, 10:38 AM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 10:55 AM
RE: use of global - by buran - Sep-30-2019, 10:43 AM
RE: use of global - by wpo - Sep-30-2019, 11:56 AM
RE: use of global - by buran - Sep-30-2019, 12:47 PM
RE: use of global - by wpo - Sep-30-2019, 01:27 PM
RE: use of global - by newbieAuggie2019 - Sep-30-2019, 02:14 PM
RE: use of global - by ichabod801 - Sep-30-2019, 01:43 PM
RE: use of global - by wpo - Sep-30-2019, 03:06 PM
RE: use of global - by buran - Sep-30-2019, 03:21 PM
RE: use of global - by ichabod801 - Sep-30-2019, 03:30 PM
RE: use of global - by stullis - Sep-30-2019, 07:45 PM
RE: use of global - by micseydel - Oct-02-2019, 10:06 PM
RE: use of global - by steve_shambles - Oct-17-2019, 04:21 AM
RE: use of global - by buran - Oct-17-2019, 06:13 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Global variable does not seem to be global. Columbo 6 5,328 Jul-15-2019, 11:00 PM
Last Post: Columbo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020