0

File ex.py:

print('hello,word')

Trial run:

>>> d:\learning\python\ex.py

SyntaxError: invalid syntax
2
  • @sheepez The problem we see here has nothing to do with print... Commented Nov 4, 2015 at 8:04
  • @glglgl Very true, I will delete that comment. Commented Nov 4, 2015 at 9:09

2 Answers 2

3

On the command line, outside the Python console, type:

python D:\learning\python\ex.py
Sign up to request clarification or add additional context in comments.

2 Comments

Im using windows 7 and python is not recognised as an internal or external command
Okay, then type C:\Python27\python.exe or whatever the path is
2

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

1 Comment

>>> import ex Traceback (most recent call last): File "<pyshell#3>", line 1, in <module> import ex ImportError: No module named 'ex' >>>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.