How do you return object from "__main__" python function?

GlassGhost
def returnSomeObject(File):
    . . .
    SomeObject = loader.load(File)
    return SomeObject

if __name__ == "__main__":
    return returnSomeObject(sys.argv[1])

When trying to return an object from the "__main__" python function, I get:

SyntaxError: 'return' outside function
GlassGhost

turns out the file I was calling it from was the problem location, I needed to Replace

import returnSomeObject as returnSomeObject

with:

from returnSomeObject import returnSomeObject

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do you return an object from a function?

Return statement from if __name__ == "__main__"

How to break from `__main__` without exit()

How do you return multiple variables from a function in python

How to get filename of the __main__ module in Python?

How to run a separate function not included in if __name__=="__main__" from the command line?

How to execute code in `if __name__ == "__main__"` from another python file

Running function in __main__ .py from command line

Run setup function from setuptools only if __name__ == "__main__"?

call function from other file with if __name__ == "__main__":

What does if __name__ == "__main__": do in Python?

__main__ and scoping in python

Is there a way to submit functions from __main__ using Python RQ

How to search for a __main__ module using pyclbr in Python3?

How do you return a JSON object from a Java Servlet

How do you wait for a return from a function before moving on in node

How do you unwrap a Result on Ok or return from the function on Err?

Python global variable on __main__

python loggers as children of __main__

How do you mock a return value from PyMySQL for testing in Python?

How do you return specific information from a dictionary in python?

How do I return a hash object from a function in PHP?

How do I return an object property from a function within a constructor?

How do you return a specific JavaScript object?

yaml.constructor.ConstructorError: while constructing a Python object cannot find "module_name" in the module '__main__'

How to return && object from function?

exec(open) function in Pycharm 'Python Console' NOT executing 'if __name__ == '__main__' block

Run a python script from another python script using IF __name__ == "__main__" statement

Do you know how to input the object from the same class in python?