24 Reusable Code Snippet Topics
Remove Filter Using the wx.lib.pdfwin.PDFWindow one can read Adobe PDF files (.pdf) with wxPython. The PDF file format is popular document file format allowing mixing of text and graphics. The GUI toolkit wxPython's newer wx.activex module allows one to use the ActiveX control, as if it would be one wx.Window. It actually … | |
A simple program to show you how to create a table of Fahrenheit and Celsius values using a for loop. You may be able to learn from this code. | |
This program uses Python module re for splitting a text file into words and removing some common punctuation marks. The word:frequency dictionary is then formed using try/except. In honor of 4th of July the text analyzed is National Anthem of USA (found via Google). | |
This shows the code for one simple crypt of text by swapping two adjoining characters each. You can make that more complex if you like. Can also be used for one nice riddle. | |
This Python snippet shows you how to take typical beginner's example of prime number function and work on improving its speed. The decorator function for timing is ideal tool to follow your progress you make. The improvements are commented and you are encouraged to make further improvements. Python is fun! | |
The Python module datetime allows you to calculate the days between two given dates with relative ease. I am using the US date format month/day/year, but you can change that by giving attention to the order of the extracted tuple. | |
The wxPython GUI toolkit has a nice numeric LED widget (LEDNumberCtrl from the wx.gizmos module) that is used here for displaying the current time in very visible 7 segment LED color display. It also shows the application of the time module and wx.Timer(). The code is simple as far as … | |
The FlashWindow component of wxPython will play those nice animated flash files found on the internet. They have file extension .swf usually. | |
The wxPython GUI tool makes it very simple to create nice looking analog clock. The analog clock component was put into simple dialog frame and can be moved about the screen. | |
Here we search a Python script file (or other text file) for one certain string, and copy any files containing this string to another folder. | |
Search for a file given its name and the starting search directory. The search is limited to a set depth of subdirectories. Python makes this easy to do. | |
This Python code will search for given filename starting with given directory. It will also search all the subdirectories in the given directory. The search will end at the first hit. | |
Code snippet to show you how to verify exit events from wxPython using dialog window. One event is from menu exit and the other from frame exit (x symbol in corner). | |
This short code shows how to indicate the mouse-over event on wxPython button, similar to the mouse-over in web pages. Button changes colour when mouse pointer is over its area. | |
The myth is around that while loop is faster than the corresponding for loop. I checked it out with Python module timeit, and came to surprising conclusion. This snippet can easily be modified to time any of your functions you write. | |
The program takes text and establishes dictionary of character:frequency. This dictionary is then presented sorted by character. Since it is important to show the most frequent characters, two methods are given to present dictionary sorted by frequency. Should all be very good for learning Python. | |
Do you think that people act demented during full moon nights? This small python program will tell you moon phase of a date you give it, so you can take precautions! | |
Question of wordcount program similar to Unix wc came up in the forum and I worked on a solution. Program shows number of lines, number of words, number of characters and text file's name. Good learning for commandline, file and string handling. | |
The little program allows eye patients to test their color skills. They are given a random color rectangle by the computer and are then asked to match the color as closely as they can using sliders of the three basic colors. An evaluation button examines the closeness of the results. | |
This program use a while loop to delete trailing spaces and tabs from a string. It is meant to be more of an example of the application of the while loop. | |
Commonly strings consist of ASCII characters, some are printable, some are in the backgrounds like the bell, carriage return, linefeed, tab and so forth. This code displays a table of ASCII characters and the corresponding decimal value. As always, you are encouraged to learn here. | |
Just a colorful ten second countdown to New Year. Hope you can learn some code from it. | |
My first experience with pointers. Learned how to spell a string foreward and backward using pointers. I hope you can learn too! |
The End.