Travel in digital space is more limited than real space travel. Be aware.
Today's first topic is extracting external files with Python. Different types (syntaxes) of data cannot be accurately read in a single file, hence the need for segregation. In most real-life scenarios, said files are stored in files of lower hierarchies, necessitating specific fetch scripts just to access them.
In Python, you can only perform tasks with a file limited to its open() mode. When your file is opened with the r state, it can only be read/printed but not editable in this state.
Other open() states include:
w: overwrites existing content in the file with inputted data.
a: adds inputted data to the file.
r+: opens file for both reading and writing.
Trying to print a variable referencing an array alone will net you a bracketed list. If you want the comma-less contents in each list printed individually, I suggest you set up a for loop that scans for each filled index and separately prints them in new rows.
Back to the topic of file manipulation, if one does not wish to open a file, the write() function alone will add strings into the file instead.
Down here is a quick demo of the script above.
It is standard practice for modern websites to have functions written in separate Python files due to syntax complications (extra labels to specify Python syntax).
You can find other modules compatible to your version of Python at this index if you do not have the time or effort to spare.
Python classes act as a blueprint or template that defines the properties (attributes) and functionalities (methods) of objects. These objects represent real-world entities or concepts with specific characteristics and behaviors.
Additionally, classes enable code reusability. You can create a class once and use it to create multiple objects with the same structure and functionality. This saves you from writing repetitive code.
For example, you can create a car class that defines attributes like name, major, GPA, and probation status. Each instance (object) created from the student class can have its own unique values for these attributes and can call the defined methods to perform actions.
The final function for today is del, Python acronym for delete. What it does is straightforward: remove what is stated – be it variable or a line of string – from a dataset (see below). Should one attempt to fetch the deleted item, it will result in an error (NameError).