15,181 Topics

Member Avatar for
Member Avatar for vegaseat

Small image files can be embedded in Python code using the base64 encoded string of the image. If you have to present a number of small fixed images in your program, embedding might be easier than including a set of image files. Attached files can be lost, and than your …

2
4K
Member Avatar for vegaseat

Here is a generator function using find() to do a search for all the occurances of a substring in a text. It will give you all the positions/indexes within the text where the substring is located. The sample text here can be replaced by text read in from a file.

0
166
Member Avatar for vegaseat

This snippet takes a look at Python file handling. Different ways to write and read text files, zipped files and memory streams. Investigates how to access only part of a file. Also explores the "read" of a binary image file and performs a hex-dump of the data.

0
564
Member Avatar for vegaseat

For loops in Python are quite versatile. The little keyword "in" allows you to loop through the elements of all kinds of sequences, may the elements be numbers, characters, strings, objects like tuples and more. Here is an example comparing range(), xrange() and a generator similar to xrange().

Member Avatar for vegaseat
0
2K
Member Avatar for vegaseat

Years ago I wrote a little screen-saver in Delphi that randomly put colorful circles all over the screen. A hit with the secretaries in the office. I modified a simple Tkinter based snippet to put the same colorful circles all over a window form at random locations, random radii and …

0
1K
Member Avatar for vegaseat

VPython's fame is with 3D animated modeling, but it's plotting abilities, while not flashy, are easy to understand and very useful. This program uses VPython to plot math functions y = sin(x) and y = cos(x) and y = sin(x)*cos(x).

2
301
Member Avatar for G-Do

Here's a cute little encipher/decipher program with a Tkinter GUI I wrote a while back. It's an implementation of a derivative of the Vigenere algorithm; the algorithm is taken from Laurence Smith's Cryptography: The Science of Secret Writing, Amazon link here. It's a dated book (and the technique itself is …

0
230
Member Avatar for vegaseat

Python has a module specifically made for timing built-in or owner coded functions. This code snippet explains how to use this feature.

1
241
Member Avatar for vegaseat

The psyco module has been around for a while and has been used to speed up the Python interpreter. For those of you who think speed is all important, take a look at a typical example. Psyco is similar to Java's just in time compiler. How does psyco do it? …

0
224
Member Avatar for vegaseat

Python24 introduces the function decorator that lends itself nicely to the timing of a function. As a sample function we are using the ever popular and rather stodgy prime number generator. The prime number generator seems to exist only to fluster students and to make niggling comparisons of the speed …

Member Avatar for vegaseat
1
2K
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 vegaseat

The Python module zlib allows you to compress a typical text string to about one half its original size. A handy feature when you have to transmit or save a large amount of text or data. It saves you time both writing and later reading back the compressed file. The …

0
1K
Member Avatar for vegaseat

Python uses C syntax to perform bitwise operations. Take a look at code that introduces you to bitwise operations at the binary level.

1
296
Member Avatar for vegaseat

If you have a Windows computer you can play musical beeps through the internal speaker. In this case it will sound like a very tiny Big Ben, brought to you by the module winsound and its method Beep().

2
2K
Member Avatar for vegaseat

Did you ever want to know how how many square inches are in a square meter? This short Python code allows you to get the answer. It uses a dictionary to simplify the conversions. Could be the start of a nice GUI program using radio buttons.

Member Avatar for vegaseat
2
3K
Member Avatar for vegaseat

The Python list container can be used for many practical things. In this somewhat light-hearted introspection of modern day politics we are looking at two lists and attempt to clear out elements that shouldn't be in both lists. No offense to anyone is intended, the outcome with the sets was …

Member Avatar for vegaseat
2
223
Member Avatar for vegaseat

A while ago I created a code snippet in C for the same question. Solving this question with Python is a lot simpler, and on top of that Python takes care of impossible dates with the appropriate error message.

Member Avatar for Lingson
2
223
Member Avatar for yuppie
Member Avatar for vegaseat

Jumping through a few extra hoops allows you to display the common image format jpeg on a panel of the wxPython GUI window. All you need to do is to read in the image file as a binary, convert to a byte stream image and then to a bitmap. Now …

Member Avatar for Erik Vandamme
0
3K
Member Avatar for vegaseat

The other day I was looking at my family tree. There are my parents Antonio and Lucy Vegaseat, then my grandparents Alfonso and Ludmilla Vegaseat on my father's side and Roland and Helga Gruenspan on my mother's side. Then come my great grandparents, by now there are eight of those. …

Member Avatar for vegaseat
0
194
Member Avatar for vegaseat

While the calculation of the total resistance of two resistors in parallel is simple, this code shows you how to trap a number of potential errors that come with the entry of the required data. All is wrapped easily into a colorful GUI program, due to the simplicity of the …

2
3K
Member Avatar for vegaseat

The wxNotebook method from the wxPython module allows you to show a lot of data in a limited window space. It brings up tabbed pages you can click on to open each page. Enough said, run the code and experience the possibilities this humble method gives you.

Member Avatar for vegaseat
0
297
Member Avatar for yuppie

A small script which converts Microsoft Office Documents (Word, Excel, Powerpoint) to Posscript. You can build your own PDF Converter with this script. More Python/Pywin32 examples can be found at [url]http://www.win32com.de[/url] and Python based PDF Converter (for server and client usage) can be found at [url]http://www.goermezer.de[/url] .

0
377
Member Avatar for vegaseat

This is another GUI program using the Tkinter module. It shows you how to change the background and foreground color of a component/widget. In this case it is a button. The button itself is used to toggle the color selection via a color dialog box. Enough comments have been added …

0
890
Member Avatar for iacobus

Here are five simple snippets, to be used as an introduction to the use of unicode. This is, of course, an on-going thing, and hopefully additional snippets and comments will be forthcoming from the members.

Member Avatar for vegaseat
0
155
Member Avatar for vegaseat

I was looking for a somewhat meaningful and interesting example to explain the Python class to beginners. A room full of multilingual students makes this phrase translator a good choice. You can experiment with it and add more languages and phrases.

Member Avatar for vartotojas
1
203
Member Avatar for vegaseat

Python's Tkinter module can be used to create a Graphics User Interface (GUI). This sample code creates a windows type form and positions a label and a canvas on the form. A simple shape is drawn on the canvas.

0
230
Member Avatar for vegaseat

A common way to represent an inventory is with a list of tuples. Each tuple represents the item name and the item count. You can sort this inventory list by item name or item count. Here is an example to pick a sort key. It's your summer job to run …

1
577
Member Avatar for vegaseat

The module datetime allows you to call several functions that can do computation with dates and times. How many days since my birth? How many days till Xmas? What's the date 77 days from now? The code snippet should give you a flavor, enough to explore on your own.

2
814
Member Avatar for vegaseat

The wxPython library allows Python to create Windows GUI programs. Here is a look at the listbox component. Click a button to load the listbox with names, select the name by clicking on it on the list, and display it in the title bar of the window frame. Another button …

Member Avatar for vegaseat
2
3K

The End.