79120805

Date: 2024-10-24 07:30:54
Score: 4.5
Natty:
Report link

i have a similar problem but my global variable needs to be set in a function (f1 in my example) and recovered as is in a second one (f2). the value of the global is set by f0, witch is not editable. I have to send global n value with f0

in my test i did in a single file

class mytest():    
    def f1(value):
        global n
        n = value
        print('test f1 : '+n)

    def f2():
        print('test f2 : '+n)


def f0():
    mytest.f1("5")
    mytest.f2()
f0()

result is 5 for f1 and f2, as expected. now i split in 2 files (to reproduce my need. no choice here, it must be splitted)

file1

def f0():
    file2.mytest.f1("5")

file2

class mytest:    
    def f1(value):
        global n
        n = value
        print('test f1 : '+n)

    def f2():
        print('test f2 : '+n)


    f2()

error is : name 'n' is not defined

f1 is always run first by the app, then f2 is called I need f2 (and fX functions i need behind) to keep 'n' value from f1

thank you

Reasons:
  • Blacklisted phrase (0.5): thank you
  • Blacklisted phrase (1): i have a similar problem
  • Blacklisted phrase (0.5): I need
  • Blacklisted phrase (0.5): i need
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): i have a similar problem
  • Low reputation (0.5):
Posted by: William Eguienta