Skip to content Skip to sidebar Skip to footer

How To Use Script In Interactive Shell

I wrote following python program #! /usr/bin/python def checkIndex(key): if not isinstance(key, (int, long)): raise TypeError if key<0: raise IndexError class Arithmeti

Solution 1:

Put your file my.py in PYTHONPATH then

from my importArithmeticSequence
s=ArithmeticSequence(1,2)

Solution 2:

The command that you want to run is:

python -i my.py

That will parse my.py and define the name ArithmeticSequence, and drop you into the Python shell where you can use your objects interactively:

>>>s=ArithmeticSequence(1,2)>>>

Solution 3:

Well you either have to run this as a program using

if __name__ == 'main':
    # Your code goes here. This will run when called from command line.

or if you are in the python interpreter you have to import "my" with:

>>>import my

Post a Comment for "How To Use Script In Interactive Shell"