Python Automation Cookbook
上QQ阅读APP看书,第一时间看更新

Conventions used

There are a number of text conventions used throughout this book.

CodeInText: Indicates code words in text, object names, module names, folder names, filenames, file extensions, pathnames, dummy URLs and user input. Here is an example: "For this recipe, we need to import the requests module."

A block of code is set as follows:

# IMPORTS
from sale_log import SaleLog

def get_logs_from_file(shop, log_filename):
def main(log_dir, output_filename):
...

if __name__ == '__main__':
# PARSE COMMAND LINE ARGUMENTS AND CALL main()

Note that code may be edited for concision and clarity. Refer to the full code when necessary, which is available at GitHub.

Any command-line input or output is written as follows (notice the $ symbol):

$ python execute_script.py parameters

Any input in the Python interpreter is written as follows (notice the >>> symbol):

>>> import delorean
>>> timestamp = delorean.utcnow().datetime.isoformat()

To enter inside the Python interpreter, call the python3 command with no parameters:

$ python3 
Python 3.7.0 (default, Aug 22 2018, 15:22:33)
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Verify that the Python interpreter is Python 3.7 or higher. It may be necessary to call python or python3.7, depending on your operating system and installation options. See Chapter 1, Let Us Begin Our Automation Journey, specifically the Creating a virtual environment recipe—for further details about the use of different Python interpreters.

Bold: Indicates a new term, an important word, or words that you see onscreen. For example, words in menus or dialog boxes appear in the text like this. Here is an example: "Go to Account | Extras | API keys and create a new one:"

Warnings or important notes appear like this.
Tips and tricks appear like this.