Python How To’s
A collection of small, useful, how to’s for Python.
How to Create a Thread in Python
Introduction to Python threads What are threads? Simply put, try to imagine them as running several programs concurrently, in a single process. When you create one or more threads in your program, they get executed simultaneously, independent of each other, and most importantly, they can share information among them without any extra difficulty. These features […]
Read MoreHow to Create a Python Package
When you’ve got a large number of Python classes (or “modules”), you’ll want to organize them into packages. When the number of modules (simply stated, a module might be just a file containing some classes) in any project grows significantly, it is wiser to organize them into packages – that is, placing functionally similar modules/classes in the same directory. […]
Read MoreHow to Install Virtualenv (Python)
Note: Edited comments about the –no-site-packages argument now being default, thanks to @dideler on Twitter. Python is a very powerful scripting language. The language has lots of Python packages you can install and use in your projects. Sometimes, you may have different projects that need different versions of the same package/module. For example, let’s say […]
Read MoreAdd Python to the PATH Environmental Variable (‘python’ is not recognized as an internal or external command)
Many developers install Python on their Windows machine, and when they try to run the console command python.exe, they get the following error message: ‘python’ is not recognized as an internal or external command . We’ll show you how to install Python, and fix this error. By adding Python to the PATH environmental variable. Step […]
Read MoreHow to Run a Python Script via a File or the Shell
If you can’t execute or run a Python script, then programming is pointless. When you run a Python script, the interpreter converts a Python program into something that that the computer can understand. Executing a Python program can be done in two ways: calling the Python interpreter with a shebang line, and using the interactive […]
Read MoreCheck if a String is a Number in Python with str.isdigit() (and Unicode)
Edit 1: This article has been revised to show the differences between str.isdigit() and the custom solution provided. Edit 2: The sample also supports Unicode! Often you will want to check if a string in Python is a number. This happens all the time, for example with user input, fetching data from a database (which […]
Read More