官术网_书友最值得收藏!

Running Python programs from the operating system shell

Switch to a console with your operating system's shell prompt and change to the new pyfund directory:

$ cd pyfund

We can execute our module simply by calling Python and passing the module's filename:

$ python3 words.py

The command would be as follows if on Mac or Linux:

> python words.py

When on Windows.

When you press Enter, after a short delay you'll be returned to the system prompt. Not very impressive, but if you got no response then the program is running as expected. If, on the other hand, you saw some error out, then something it wrong. An HTTPError, for example, indicates there's a network problem, whilst other types of errors probably mean you have mistyped the code.

Let's add another for-loop to the end of the program to print out one word per line. Add this code to the end of your Python file:

for word in story_words:
print(word)

If you go to your command prompt and execute the code again, you should see some output. Now we have the beginnings of a useful program!

主站蜘蛛池模板: 江都市| 红原县| 辽中县| 景泰县| 五峰| 托克逊县| 五华县| 自贡市| 长子县| 微山县| 景泰县| 长白| 凤冈县| 郎溪县| 栖霞市| 荣昌县| 罗源县| 赞皇县| 郎溪县| 常德市| 白城市| 浪卡子县| 即墨市| 梁平县| 上蔡县| 乌拉特前旗| 乌海市| 满城县| 四会市| 阳曲县| 克东县| 青海省| 同江市| 烟台市| 金秀| 高邮市| 阿克苏市| 安多县| 曲靖市| 陆河县| 册亨县|