tnoel999888
tnoel999888

Reputation: 654

Terminal Prompt Not Changing To '>>>' When Executing Python File

I am running the following command on terminal:

python SpellingCorrector.py

No error is thrown by terminal and it simply progresses to the next line with the same prompt showing my current working directory, rather than the Python '>>>' terminal prompt.

I would like to run a function within the program with an argument and I only have the option to attempt that as such:

[my/current/directory/]$ correction('speling')

This then throws the error

bash: syntax error near unexpected token `'speling'`

I'm guessing I need to run it with this prompt in order for it to work:

>>> correction('speling')

The Python version is 2.7.5. Does anyone know why the prompt is not changing when I run the program or how I can run the function?

Upvotes: 1

Views: 208

Answers (3)

Eugene Yarmash
Eugene Yarmash

Reputation: 150031

The python script.py command simply executes the script and returns control to the shell, which is not what you want.

You could use ipython's %run command to run a python script from inside the interpeter:

%run ./script.py

This is similar to running at a system prompt python file args, but with the advantage of giving you IPython’s tracebacks, and of loading all variables into your interactive namespace for further use.

Upvotes: 0

Michal Polovka
Michal Polovka

Reputation: 650

You are launching the program instead of launching python interpreter.

To use interpreter, launch it as follows (without arguments):

python

then use import SpellingCorrectorto import your program to interpreter. Now you can use its functions etc.

Please note, that import statement has no .py extension.

Upvotes: 4

marsouf
marsouf

Reputation: 1147

you need to execute your script in the interactive mode, like the following :

python -i SpellingCorrector.py

and then execute your function from there :

correction('speling')

Upvotes: 8

Related Questions