Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python how to change the global variables [duplicate]

Tags:

python

I would like to get some kind of confirmation that the upload is success, I have my methods defined similar to the following. However the value of global variable is not changing. Please help

global upload_confirm
upload_confirm = False

def confirm_upload():
    upload_confirm = True

def start_new_upload():
    confirm_upload()
    while (upload_confirm != True):
        print "waiting for upload to be true"
        time.sleep(5)
    if (upload_confirm == True):
        print "start Upload"

start_new_upload()
like image 834
Anup Singh Avatar asked May 19 '26 20:05

Anup Singh


1 Answers

You could try this:

def confirm_upload():
    global upload_confirm
    upload_confirm = True

Since you are doing upload_confirm = True in a local scope, Python treat it like a local variable. Hence, your global variable stays the same.

like image 126
Pablo Santa Cruz Avatar answered May 22 '26 09:05

Pablo Santa Cruz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!