Saeed
Saeed

Reputation: 2099

When to use python interpreter vs shell

I have a very basic question: If we want to run a script called script.py, we go to shell and type "python script.py". However, if we want to check, for example, if Django is installed or not, we first go into Python interpreter by typing "python" in the shell, and while we get the >>> then we type import Django. What is the conceptual difference? For example, in the second case, why directly running "python import Django" in the shell does not work?

Upvotes: 1

Views: 1177

Answers (2)

magexcustomer
magexcustomer

Reputation: 35

python launch interpreter. You can easly test script on it, and after create a file *.py that you can use on CRON (for ex)

When you type python and import Django it do

  1. Open Python interpreter
  2. Import Django library on it (to use it)

If an error raise, it seems than Django wasn't installed on computer

Upvotes: 0

chepner
chepner

Reputation: 532093

python import Django tries to run a Python script named import with an argument Django.

python -c 'import Django' would attempt to execute the Python statement import Django as if you had typed it from the Python interpreter directly.

Upvotes: 2

Related Questions