Today I am going to show you how to create 7οΈβ£ different file types with #Python:
π Text file
π CSV
π XML
π JSON
π Tar file
π PDF
π Excel
Join me for this fun π§΅π
1οΈβ£ Creating a text file with #Python is a breeze! The recommended method is to use Python's `with` statement as it will automatically close the file for you
That means you can create a text file with TWO lines of code if you want to:
2οΈβ£ Creating a CSV file with #Python can be accomplished using the `csv` module
When using a class in #Python, you may notice that the first argument in all the class's methods is "self"
What is up with that? Well, let's talk about it!
π§΅ππ
First of all, "self" is a convention that refers to the instance that is created when you instantiate a class. You don't have to name it "self", but that is best practice
Here is an example where "self" is replaced with "this"
You use "self" to be able to access instance attributes across methods in a #Python class.
Here is an example where you initialize (__init__) `self.name` and then use `https://t.co/O7h9e3XIVz` later on when you call the `walk()` method:
To configure logging in #Python using a file, you will need to create a file that looks a lot like an INI config file.
This file will set the logger name, the handlers and formatters and then define which formatter goes with which handler.
Here is an example config file:
To use a file config with #Python's `logging` module, you need to import `logging.config` and then call `logging.config.fileConfig()` with the path to the config file
Using a file config makes your code much easier to read:
If you're new to #Python and you want to install a Python package from the Python Package Index, you will probably want to use pip
Pip comes with Python (except where Python is preinstalled, like Linux)
I'm going to talk a little about what you can do with pip
π§΅π
Installing a #Python package with pip is usually as simple as running the following:
Sometimes you may want to install multiple #Python πpackages. You can run the command for each package or you can separate the names of the packages with spaces: