File ex.py:
print('hello,word')
Trial run:
>>> d:\learning\python\ex.py
SyntaxError: invalid syntax
File ex.py:
print('hello,word')
Trial run:
>>> d:\learning\python\ex.py
SyntaxError: invalid syntax
You need to import the module:
>>> import ex
See the documentation about modules
The module has to be on your path or in the current working directory. You can change directories using chdir:
>>> import os
>>> os.chdir(r'd:\learning\python')
>>> import ex
hello,word
Or, in the command prompt, you can set PYTHONPATH=d:\learning\python, for example, before you start python, and d:\learning\python will get added to sys.path.
Instead, you could add it programatically:
>>> import sys
>>> sys.path.insert(0, r'd:\learning\python')
>>> import ex
hello,word