445 Topics
Python programming can have its lighter moments. Here we use one of those moments to draw an optical illusion using the Tkinter canvas to draw a rectangle, some lines and circles. | |
Do I have to spell it out for you? This short C code will do just that. It will spell out an integer number in English words. The banks do that on large checks, and it would be nice to get one of those every now and then. | |
The code is shamefully short, but here it is. Now you can listen to the many sound files in wave (.wav) format and boing, chirp, chime, bark, booh, laugh and mooh at the people around you. | |
A simple program to count the words, lines and sentences contained in a text file. The assumptions are made that words are separated by whitespaces, and sentences end with a period, question mark or exclamation mark. | |
The wxPython GUI toolkit makes a very nice plotting component/widget available. You can select line or marker plotting, or a combination of both. All you have to supply is a list of x,y point tuples. Other features include zooming and printing. | |
Write a Python program that creates upside down sentences, like [B] upside down --> umop apisdn [/B] The sentence above is flipped 180 degrees around the end. Some freedom allowed, like an 'a' upside down and reversed is the closest thing to an 'e'. Conversely a 'w' would be a … | |
Let Python do the work for you and figure out the roman numerals for a given integer. I have to ask you to keep the integer values somewhat reasonably low (from 1 to 4999), since roman numerals from 5000 on use characters with an overline and most PCs don't have … | |
Just spent about an hour removing [B]Antispyware Soft[/B], a small miserable program that comes in on e-mail or certain church sponsored web sites. It deposits a random named executable in your Windows OS (XP through Windows7) and then takes over the registry to a point where you can not run … | |
Starting with version 2.6 Python has introduced a new container called the named tuple. You can use it similar to a class based record structure, but it has the memory efficiency of a tuple. | |
The Python module 'tarfile' is more flexible then it's counterpart 'zipfile'. It allows you to simply archive files without compression, or use the gzip format of compression, or the super compression format bzip2. Here is code to show you the use of the module. | |
A short look at creating lists of file names or full path names using the versatile Python module glob. Glob follows the standard wildcard protocol. | |
A little late for April 1, but here is the secret code ... [code]searchEngineNames = [] for c in range(ord('A'), ord('Z')+1): name = chr(c)+'ing' searchEngineNames.append(name) # pick #1 print(searchEngineNames[1]) [/code] | |
Looking at the First In First Out (FIFO) data situation. Just like a line at the grocery store check-out. Its counterpart FILO would be like a stack of dinner plates. | |
A demo of the Tkinter listbox widget that shows you how to create the listbox, make it scrollable, position it within a grid, load it with data from a file, select a line of data with the mouse and display it. Also, sort the lines, add a line, delete a … | |
We take a look at the various functions of module time, counting seconds and milliseconds, measuring the time a simple for-loop takes, inspect a list of time data and ways to display it in a useful manner. An attempt is made to find the day of the week, given a … | |
You can use Python modules math, wave, and struct to create and save a synthetic sine wave of given frequency and duration (size) ... | |
Wallpaper or tile images are small images that can be spread across a background repetitively. A common practice on web pages. The surface created with wx.PaintDC() can be used for this effect and still allows other widgets to be put on top of the wallpaper. The small tile image is … | |
A lotto simulator with a twist, you pick the winning numbers and the computer buys the lotto tickets. Anyway, the computer at least generates the tickets and checks how many of them would match the winning numbers you selected. Let's assume you would be the state lotto commissioner and your … | |
Convert a decimal (denary) integer to a binary string. An exercise in do ... while and while loops. | |
There is also "1001 ways to spam for liquid roofs" or similar title. | |
This is an update of an earlier version. In this version the string containing the approximated pi value is created directly from the iteration of the generator. This way the program is simplified and can be used with Python2 and Python3 ... | |
Python uses the Mersenne Twister as the core random generator. The module random contains a fair number of methods (or functions) that help you to do random things. Here are some examples ... | |
The module tkSnack from our friends at KTH in Stockholm, Sweden allows you to play a variety of sound files using the Tkinter GUI. Supported sound files are WAV, MP3, AU, SND and AIFF formats. | |
Here we apply the module difflib to compare two texts line by line and show the lines of the first text that are different from the second text. | |
This program uses the Python win32 extension module to get information on disk or flash drives for Windows machines. Specify the drive with its letter. If no drive letter is specified, the current drive is applied. | |
The World is due another attempt at a universal language. So what are your ideas? My proposal: Easy to learn (simple grammar). Use a simple alphabet (no umlauts please). Make the most common words the shortest words. The words should be unique in sound and somewhat melodic. Pronunciation should make … | |
This code snippet shows you how to sort more complicated objects like a list of lists (or tuples) by selecting an index of the item to sort by. | |
Here is an example I was thinking of ... [code=python]import random import time def delay(seconds): time.sleep(seconds) def shuffle_hitlists(my_hitlist, mo_hitlist): """shuffle the two lists and return the result""" random.shuffle(my_hitlist) random.shuffle(mo_hitlist) return my_hitlist, mo_hitlist def battle(my_hitlist, mo_hitlist, my_strength, mo_strength): # player starts swinging first for k in range(len(my_hitlist)): my_hit = my_hitlist[k] mo_hit … | |
A function that takes a string and returns the number of words in the string. An example of using pointers in Pascal. | |
Python can use its COM support and the OCX of the WindowsMediaPlayer to play mp3 music files. Make sure that your Python installation has the win32com folder. Check [url]http://starship.python.net/crew/mhammond/win32/Downloads.html[/url] for the latest win32com support. [COLOR="Red"]This code relies on file WMPlayer.OCX which MS has removed on newer versions of Windows. See … | |
This shows how to create, load and access a ListBox. BCX was used to create the original code which was then modified to work with the Dev C++ (really GCC/G++) compiler, compile as a Windows Application. | |
A small Windows Application to show you how to play a wave (.wav) sound file. I am using the C# IDE from SharpDevelop and the runtime dotnetfx 1.1 from Microsoft, both free downloads. This forms a small and fast student system to write and debug C# programs. From there you … | |
Python has some powerful functions, like the math expression evaluator eval(). You can embed this function and others in your Development C++ code. All you need to do, is to download and install the free Python Development Pak and feed the Python code in the form of a string to … | |
Tired of the Tk icon in the corner of the form. It's easy to replace with any fancy icon you have. Here is the code ... | |
An example of a range generator that handles floating point numbers, appropriately called frange(). The function range() or the generator xrange() can only be used for integers. Note that xrange() now is range() in Python3. | |
Ever since I upgraded to IE8 I have noticed the beast freezing up more frequently than the usual Windows software. I have switched to Firefox and found that web browser a lot more stable than even IE7. Is there any software for converting "IE favorites" to something useful like an … | |
Here is an example how to write a program to convert between units of distance, area, volume, weight, pressure, and energy. The wxPython GUI toolkit's wx.NoteBook() widget is used to make good use of the limited frame/window space available. | |
A variation of the previous bouncing ball code. This time the upper left corner of the image rectangle simply follows the position of each mouse click. Use an image you have, in my case I used a small red ball in a black background. A simple code to experiment with. | |
Text to speech can be implemented in its simplest form using Microsoft's Component Object Model (COM) connecting to the Speech API (SAPI). The attached Python code shows you how to do this. | |
This short Python snippet shows you how to read mouse wheel events with the Tkinter GUI toolkit. Windows and Linux have different bindings and read different events, but can be included in the same program code for use with either operating system. | |
This well commented Python snippet uses wxPython's plotting widget to graph the projectile motion of two different firing angles on the same plotting canvas. | |
Sometimes you want to accomplish something with a minimum ammount of code. Here is an example of using modern Python concepts of lambda, list comprehension and all() to create an anonymous function that returns a prime list from 2 to n. | |
A simple example of applying a font to a text displayed with wxPython's wx.StaticText widget. | |
Just bouncing a red ball within the frame of a window, the twist here is that the image is stored within the code as a base64 encoded string of the gif image. This way you only have to distribute one file. The Python code is heavily commented, so you can … | |
Using count() from Python's itertools module and the Tkinter GUI toolkit's after() function, you can create a simple counter that counts up the seconds until the Stop button is pressed. | |
The wxPython wx.lib.fancytext widget allows you to display super and subscripts in texts, and allows you to change fonts and colours too. All this is done with XML coded strings. XML documentation code is tag based and not that difficult to understand. It looks rather similar to the older HTML … | |
The wxPython GUI toolkit has a number of calendar widgets, but the one that is most customizable is the wx.lib.calendar widget. Here we expanded it to colour the weekends and the holidays supplied by a dictionary of 'month: list of holiday dates in month' pairs. Since some holiday dates can … | |
Just a little mathematical exercise in geography, namely the use of longitude and latitiude coordinates to calculate the distance between two given cities. You can obtain the coordinates for just about any earthly city from [URL="http://www.ASTRO.COM"]WWW.ASTRO.COM[/URL]. The coordinates are in a format like 35n13 (35 degrees, 13 minutes north). The … | |
There are times when you have to layout widgets on a window area fairly well spaced apart. To do this with pack() or grid() will be more than frustrating, for these occasions place() with its absolute coordinates comes to the rescue. Here is some Python/Tkinter GUI code showing you how … | |
A short C# code snippet to get the US Naval Observatory Master Clock Time from: [URL]http://tycho.usno.navy.mil/cgi-bin/timer.pl[/URL] The snippet displays the raw HTML code with the time infomation and then extracts one specific US time zone. |
The End.