- Mastering Python Networking
- Eric Chou
- 411字
- 2021-07-02 21:42:31
Running a Python program
Python programs are executed by an interpreter, which means the code is fed through this interpreter to be executed by the underlying operating system, and results are displayed . There are several different implementation of the interpreter by the Python development community, such as IronPython and Jython. In this book, we will refer to the most common Python interpreter, CPython, which is in use today.
One way you can use Python is by taking the advantage of the interactive prompt. This is useful when you want to quickly test a piece of Python code or concept without writing a whole program. This is typically done by simply typing in the Python keyword:
Python 3.5.2 (default, Nov 17 2016, 17:05:23)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for
more information.
>>> print("hello world")
hello world
>>>
The interactive mode is one of the Python's most useful features. In the interactive shell, you can type any valid statement or sequence of statements and immediately get a result back. I typically use this to explore around a feature or library that I am not familiar with. Talk about instant gratification!
A more common way to run the Python program, however, is to save your Python file and run via the interpreter after. This will save you from typing the same statements over and over again such as in the interactive shell. Python files are just regular text files that are typically saved with the .py extension. In the *Nix world, you can also add the shebang (#!) line on top to specify the interpreter that is used to run the file. The # character can be used to specify comments that will not be executed by the interpreter. The following file, helloworld.py, has the following statements:
# This is a comment
print("hello world")
This can be executed as follows:
echou@pythonicNeteng:~/Master_Python_Networking/
Chapter1$ python helloworld.py
hello world
echou@pythonicNeteng:~/Master_Python_Networking/
Chapter1$
- Extending Jenkins
- Python快樂編程:人工智能深度學(xué)習(xí)基礎(chǔ)
- GraphQL學(xué)習(xí)指南
- Visual FoxPro程序設(shè)計教程
- Java高并發(fā)核心編程(卷2):多線程、鎖、JMM、JUC、高并發(fā)設(shè)計模式
- 自己動手寫Java虛擬機
- 從程序員到架構(gòu)師:大數(shù)據(jù)量、緩存、高并發(fā)、微服務(wù)、多團隊協(xié)同等核心場景實戰(zhàn)
- BeagleBone Media Center
- Reactive Programming With Java 9
- Julia Cookbook
- Expert Data Visualization
- 利用Python進行數(shù)據(jù)分析(原書第3版)
- C程序設(shè)計實踐教程
- Visual Basic程序設(shè)計實驗指導(dǎo)(第二版)
- Processing創(chuàng)意編程指南