Ready? Set. Python!
Python is a very powerful language. In some of my past articles, I went over how you could create your own languages using python, and how you could leverage more power with for loops. In this article, I go over other powerful features of Python.
1. You can create a for loop, without actually using a for loop!
In python, you can use the exec
function along with string multiplication to create a for loop, like so:
2. You can send emails using Python
This is a little more complicated. You’ll need to set up a gmail account and turn on less secure apps for the account.
Then, you need to write a python script using smtplib
and email
in the python libraries.
There are many different ways to send the email, the easiest of which is here, but my personal favorite is below:
3. You can turn your python files into exe files
Long-time Python coders may know that python runs on C++. This is why it may come as a surprise that Python doesn’t provide a built-in way to compile to an exe.
However, there are plenty of workarounds.
Open a new terminal or cmd window, and type in the following commands:
pip install cx_Freez
pip install idna
These 2 libraries are needed for converting .py files to .exe files. Next, create a python script as follows:
And that is it!
4. You can run Python without a CMD window
If you aren’t interested in turning your python file into an exe, instead you can simply change the file extension.
If your file was named name.py
, rename it to name.pyw
. Now, double click on the file, and it will run without a window. This type of file is called a “Python File (no console)”.
5. You can run commands with Python
Using python, you can write to the command line directly. So, you can call other python files from within python:
That is it for this article. I hope you learned something new!t