1.2. Your computer#
Before diving into coding with Python, it’s crucial to understand the organization of your computer. So far, you might be used to working in apps or cloud platforms like Google Docs or OneDrive, which hide the underlying folder structure. But as a programmer, you will need to know how to navigate and manage the file system of your computer.
Whether you’ll be saving data, reading a data file, or organizing your project, you’ll constantly deal with files, as well as with folders (also called directories).
1.2.1. Files vs. folders#
Think of folders like drawers in a filing cabinet, and files like sheets of paper you store inside.
Fig. 1.6 “Hand in filing cabinet” by Watty62 is licensed under CC BY-SA.#
A file is a container for data. It can be a text document (.txt), a Word document (.docx), a Python script (.py), a spreadsheet (.xlsx), an image (.png), or any other kind of data. As you notice within the brackets for each of these example, different types of files carry different extensions. Therefore, by checking the extension, you can directly know that, e.g., a file called Cat.png is an image.
A folder is a container for files and other folders. Folders help you organize files in a structured way. For instance, you may want to have a folder called Nanobiology on your computer, in which you have one subfolder for each course you’re taking. Each of these subfolders can then contain all the files that are related to a given course, or even further subfolders for more detailed organization. You can navigate the folders in your File explorer (Windows OS), Finder (macOS), or a file manager such as Nautilus or Dolphin (Linux). Alternatively, we will be using terminal (more on this later).
Fig. 1.7 An example of the folder structure (also called “repository tree”, refering to the hierarchical structure). Does this structure seem clear and intuitive to you?#
1.2.2. Avoid special characters#
When creating folders and files for your projects, stick to simple, safe names. Avoid using special characters like:
! @ # $ % ^ & * ( ) + = { } [ ] : ; " ' < > , ? /
These characters can confuse your operating system or Python, leading to errors when reading, writing, or importing files.
Best practices for naming folders and files:
Use only letters, numbers, hyphens (
-), and underscores (_).Keep names short but meaningful (e.g.,
data_analysis,project_notes.txt,week1_assignment.py).Avoid spaces: use underscores instead (e.g., use
my_projectrather thanmy project).
🚫 Bad Examples |
✅ Good Examples |
|---|---|
My Project |
my_project |
final_version! |
final_version |
data#1.txt |
data_1.txt |
project(backup) |
project_backup |
March-Report$ |
march_report |
test_home.py |
1.2.3. What is a “normal” folder?#
When working on coding projects, always create and use a normal folder on your computer, such as:
Documents/Nanobiology/Programming_Foundations
Note that with the notation using /, we mean that Programming_Foundations folder is located within Nanobiology folder, which is located in Documents. In other words, Nanobiology is a subfolder of Documents, and Programming_Foundations a subfolder of Nanobiology. This is also called a path (more on it in a later chapter).
Avoid using these:
OneDrive, Google Drive, or iCloud folders: They may automatically sync or move your files, sometimes making them temporarily unavailable or read-only.
Read-only folders: If you can’t edit or save files in a folder, your Python programs may fail when trying to write to files.
Network drives or USB drives: These can introduce file permission or path issues.
1.2.4. What is a zip file?#
A zip file is a compressed container that can hold one or more files and folders. Its extension is .zip. Note that even though zips can contain multiple files and folders, they are files and not folders.
Zip files are commonly used for sharing many files at once. To access its contents, you must extract (unzip) a zip file. You will encounter some zip files in the exercises in this book.