Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to return a value from one Python file to another? [duplicate]

Tags:

python

I'm wondering if it is possible to run another file: os.startfile('File.py') and have that file return a value to the file that called the other file.

For example, you have File1. Is it possible for File1 to call and run File2 and have File2 return a value to File1?

like image 279
michaelblob Avatar asked May 30 '13 21:05

michaelblob


People also ask

How do you return a value from a Python script?

The Python return statement is a special statement that you can use inside a function or method to send the function's result back to the caller. A return statement consists of the return keyword followed by an optional return value. The return value of a Python function can be any Python object.


1 Answers

Why are you running Python scripts like that? the usual way is to import one module ("another file") in a Python script and invoke the public functions from there. That's what the module importing mechanism is for, please read the linked documentation.

As mentioned in the comments, this question has been asked before. Take a look at this answer for further help.

like image 111
Óscar López Avatar answered Oct 12 '22 09:10

Óscar López