Skip to content Skip to sidebar Skip to footer

Call A Function In Python Script Then Check If Condition

I have this function: def ContentFunc(): storage = StringIO() c = pycurl.Curl() c.setopt(c.URL, url) c.setopt(c.WRITEFUNCTION, storage.write)

Solution 1:

In your function

def ContentFunc():
    ...
    content = storage.getvalue()

This defines contentwithin the scope of that function. The function then ends, and that name (and the object assigned to it) is discarded. Instead, return from the function:

def ContentFunc():
    ...
    return storage.getvalue()

and assign the name in the calling function:

content = ContentFunc()

Post a Comment for "Call A Function In Python Script Then Check If Condition"