Question:
Programming in Python: Scripting mode?
Schillinger Joseph
2012-09-08 06:31:12 UTC
Hello, I've been reading book about python
And here is the question
Type the following statements in the Python interpreter to see what they do:
5
x = 5
x + 1
Now put the same statements into a script and run it. What is the output? Modify the script by transforming each expression into a print statement and then run it again.

I did the first thing on the interpreter, But how do I "activate" the script mode??
Three answers:
radicalbiscuit
2012-09-08 07:45:05 UTC
A script is simply a text file. You will put the same statements into a text file, name it anything.py, and tell Python to run that file by sending the command "python anything.py" from your command prompt.



I assume you're using Windows. If not, use the "additional information" feature on Yahoo! Answers to let me know what OS you are using. But if you are, this link will take you to a very informative official Python page about how to use Python on Windows. You'll want to read through the first section, "How do I run a Python program under Windows?" and you might want to watch the "Adding Python to DOS Path" video, linked to from the right side of the page.



The link will take you to a brief ad first, then click "Skip This Ad": http://b2809775.theseforums.com



Let me know through email if you're still having a lot of trouble. Good luck!
husoski
2012-09-08 07:54:12 UTC
The "script" is simply a text file with Python statements in it. In other words, it's a Python source program. So, open up an editor, type in those lines, and save the result as "runme.py", or pick your own name. The ".py" suffix means that the file contains Python source code.



Run that source file ("script") from the a terminal or command prompt window with:



python runme.py



If you don't see any output, don't worry. That's expected. Python doesn't automatically print out result values for each line in a running program the way it does when single lines are executed in the "interpreter". Go ahead and convert the statements to print statements, then re-save and run. You should see then.
?
2016-10-23 06:07:59 UTC
inspect the print function it really is outfitted into python and one yet another programing lang. print("a million + a million is ", a million+a million) Will demonstrate: a million+a million is two print("print reflects issues on the demonstrate") is likewise the document kept as filename.py Did you chmod 755 filename.py Or chmod +x filename.py Are you operating the document like such python filename.py or ./filename.py


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...