A common task when working with files is to walk through a directory, that is, recursively get every file in every directory starting in some location. The Python 3 os module has several functions useful for working with files and directories. One in particular, os.walk() is useful for recursively going through a directory and getting the contents in a structured way. These examples will show you a couple options for walking a directory recursively.
In Python, when building a framework or code generation tool, you might need to programmatically build a string representing the name of a module you want to import. How would you import a module if you have it's name as a string? Here's how to do it with importlib! Note that this feature was introduced in Python 3.1 but there is a 2.7 version of importlib though less featured.
In Python sometimes you need to figure out where a function lives on the hard disk, or what file is calling your function. The os module provides tools for getting file and directory information and the inspect module provides the ability to inspect the stack and see what module is calling your function.
This tutorial covers how to use standard ANSI escape codes to colorize and style terminal output. We'll cover the basics of escape characters, using them to clear the screen and set foreground and background colors, and how to get them working in Windows using the colorama package.
The curses package is part of the Python standard library and is useful for creating text-based user interfaces and generally controlling the screen and keyboard input. The big problem is that it doesn't work out-of-the-box on Windows. This show you how to get curses working in Windows. This was tested in Windows 10 with Python 3.6.
Copy and paste operations are most often associated with text, but you can also copy and paste images and other formats. This example demonstrates how to pull an image off of the system clipboard using the Pillow package in Python. It has a convenient method for pulling images from the clipboard. There are a few ways you might get an image in your clipboard. For example, if you used your Grab or Snipping Tool to capture a section of your screen, but you haven't actually saved it yet, you can CTRL-C to copy the image to your clipboard. Or, if you right click an image in a web browser and choose "Copy Image".
This tutorials demonstrates how to use Python for text-to-speech using a cross-platform library, pyttsx3. This lets you synthesize text in to audio you can hear. This package works in Windows, Mac, and Linux. It uses native speech drivers when available and works completely offline. We will walk through how to install, convert text-to-speech, and switch between voices and languages.
ASCII art has a long history in the hacker culture. If you check out any Phrack article and there is almost guaranteed to be some form of ASCII art in there. In this example we are specifically talking about ASCII art fonts that can be used to make banner text for command-line applications, network services, documentation, web pages, etc.
Nginx, pronounced "engine X", is a fast and lightweight web server, that can be used to serve static files, but is often used as a reverse proxy. It has some very nice features like load balancing and rate limiting. We'll cover some common use cases like serving files, creating a directory listing, reverse proxying to pass incoming traffic to a local web server, adding SSL encryption, and how to require https and www on your site. This guide is for someone who needs a quick reference to setting up a simple nginx server. For the latest documentation always check out the official website https://www.nginx.com/ and the source mirror at https://github.com/nginx/nginx.
If you need a quick-and-dirty HTTP server that doesn't need fancy configuration, try some of these one-line HTTP servers in languages like Python, Ruby, and PHP. Some examples include a small script that allows you to embed the server in to your program and add more customization. These are not intended for production use.