I'm trying to execute a file with Python commands from within the interpreter.
EDIT: I'm trying to use variables and settings from that file, not to invoke a separate process.
Several ways.
From the shell
python someFile.py
From inside IDLE, hit F5.
If you're typing interactively, try this: (Python 2 only!)
>>> variables= {}
>>> execfile( "someFile.py", variables )
>>> print variables # globals from the someFile module
For Python3, use:
>>> exec(open("filename.py").read())
python
does not work if you are running python 3,python3
is used instead.Execfile no longer exists in python3, and exec() doesn't seem to be working somehow...not sure what I'm doing wrong. could you update the answer?
is there any way to provide
stdin
from a file like using<
to the executing script with in theexecfile()
.? @s-lott@pzkpfw python can point to any version of python. I have seen environments with only python v3 where
python
points topython3
.@pzkpfw That depends on what
python
executable the system finds when looking through the folders in the environment variablePATH
.