0

When testing in python shell, I always have to type some import like:

Python 2.5.4 (r254:67916, Jun 24 2010, 15:23:27) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>import sys
>>>import datetime

Can someone help me to automatically finish these? It means I run some command to enter python shell it has already done import for me, and a python shell waiting for me to continue type command.

Thanks.

2 Answers 2

3

Try:

python -i -c "import sys; import datetime;"

More info:

-i     : inspect interactively after running script; forces a prompt even
         if stdin does not appear to be a terminal; also PYTHONINSPECT=x

&

-c cmd : program passed in as string (terminates option list)
Sign up to request clarification or add additional context in comments.

Comments

1

Create a file with the commands you want to execute during startup, and set the environment variable PYTHONSTARTUP to the location of that file. The interactive interpreter will then load and execute that file. See http://docs.python.org/tutorial/interpreter.html#the-interactive-startup-file

On a sidenote, you might want to consider ipython as an improved Python shell when working in interactive mode.

1 Comment

That's the way always run when startup, i just want to specify it sometimes, maybe my question is not clear, but thanks anyway.

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.