24 Reusable Code Snippet Topics

Remove Filter
Member Avatar for bumsfeld

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 …

Member Avatar for bucefala
0
2K
Member Avatar for bumsfeld

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.

Member Avatar for rubberman
1
279
Member Avatar for bumsfeld

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).

Member Avatar for sujit.shakya.3
2
2K
Member Avatar for bumsfeld

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.

Member Avatar for bumsfeld
2
630
Member Avatar for bumsfeld

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!

Member Avatar for TrustyTony
0
2K
Member Avatar for bumsfeld

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.

0
492
Member Avatar for bumsfeld

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 …

0
2K
Member Avatar for bumsfeld

The FlashWindow component of wxPython will play those nice animated flash files found on the internet. They have file extension .swf usually.

Member Avatar for akennedy93612
0
422
Member Avatar for bumsfeld

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.

0
729
Member Avatar for bumsfeld

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.

0
213
Member Avatar for bumsfeld

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.

0
223
Member Avatar for bumsfeld

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.

0
153
Member Avatar for bumsfeld

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).

0
715
Member Avatar for bumsfeld

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.

0
2K
Member Avatar for bumsfeld

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.

Member Avatar for Begjinner
0
2K
Member Avatar for bumsfeld

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.

0
626
Member Avatar for bumsfeld

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!

0
4K
Member Avatar for bumsfeld

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.

1
3K
Member Avatar for bumsfeld

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.

0
417
Member Avatar for bumsfeld
Member Avatar for bumsfeld

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.

0
1K
Member Avatar for bumsfeld

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.

Member Avatar for bofarull
1
164
Member Avatar for bumsfeld

Just a colorful ten second countdown to New Year. Hope you can learn some code from it.

0
3K
Member Avatar for bumsfeld

My first experience with pointers. Learned how to spell a string foreward and backward using pointers. I hope you can learn too!

1
119

The End.