From 8d8d8b58809908dab854e2bafe15a079e1ce188b Mon Sep 17 00:00:00 2001 From: Kristian Rother Date: Sun, 11 Feb 2024 23:55:36 +0100 Subject: [PATCH] clean up reference chapters --- reference/basics.rst | 2 +- reference/print.rst | 1 + reference/reading_files.rst | 13 ++++++------- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/reference/basics.rst b/reference/basics.rst index c3b1aa1..a937345 100644 --- a/reference/basics.rst +++ b/reference/basics.rst @@ -9,8 +9,8 @@ A Python program is simply a text file that contains Python statements. To execute a Python program, you run it from the command line with: +:: - :::bash python my_program.py For those unfamiliar with the command line all Python editors have diff --git a/reference/print.rst b/reference/print.rst index e9d5930..f08b77f 100644 --- a/reference/print.rst +++ b/reference/print.rst @@ -16,6 +16,7 @@ operations separated by commas. Examples for print statements: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +.. code:: python3 print('Hello World\n') print(3 + 4) diff --git a/reference/reading_files.rst b/reference/reading_files.rst index e9de1d1..cbee6c4 100644 --- a/reference/reading_files.rst +++ b/reference/reading_files.rst @@ -40,8 +40,8 @@ Reading a table with multiple columns Frequently you have data in text files separated into multiple columns, like this: +:: - :::bash Emily;Smith;23 Charlie;Parker;45 @@ -62,7 +62,7 @@ finally breaks the line into a list of items at the ``;`` character (``split``). The ``str.strip()`` function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +---------------------------- With the string function ``strip()``, you chop off whitespace characters (spaces, newline characters and tabs) from both ends of a string. The @@ -105,27 +105,27 @@ When opening files, you often need to specify a directory name as well. You can use both full or relative directory names. A full file name contains the entire path from the root directory, e.g.: +:: - :::bash /home/kristian/Desktop/myfile.txt or on Windows +:: - :::bash C:/Python3/python.exe A relative directory name starts from the current working directory, often the directory in which your program is started: +:: - :::bash data/my_file.txt or go one directory level up, then move into the folder below: +:: - :::bash ../data/my_file.txt Slashes versus Backslashes @@ -161,7 +161,6 @@ The modern way to open files in Python is using a **Context Manager** (a code block started by ``with``). The ``with`` statement takes care of closing the file automatically: - .. code:: python3 with open('my_file.txt') as f: