vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Samsung might be a good spot.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I keep a rather comprehensive data base of good code examples. Search by keywords. It makes coding life easier.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Maybe your depression is more deep-rooted and shows through in your applications. You might want to look for medical help.

iamthwee commented: nods +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A flashback in history ...
First you read through people's mail, then you make them disappear in the middle of the night.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
try:
    # for Python2
    import Tkinter as tk
    import tkFileDialog as tkfd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.filedialog as tkfd
Gribouillis commented: good help +14
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Using the PySide GUI toolkit will make selecting, copying and pasting encrypted and decrypted text somewhat easier. Not ideal yet, but it will be a good start for those of you who are not very familiar with GUI programming.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

In today's environment where just about anyone can snoop around your e-mail, it is prudent to securely encrypt your more private writings. This little Python program will make it easier to do so.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Python3 has modernized the language and has thrown some roadblocks too when it comes to unicode ...

''' encrypt106_py23.py
using the Python module base64 to encode and decode text
or any binary data like images
modified to work with Python2/3
tested with Python27, Python33 and IronPython273
'''

import base64

def encrypt106(text):
    '''
    use base64 encoding
    '''
    try:
        # Python2
        return base64.encodestring(text)
    except TypeError:
        # Python3
        return base64.encodestring(text.encode("utf8")).decode("utf8")

def decrypt106(e_text):
    '''
    use base64 decoding
    '''
    try:
        # Python2
        return base64.decodestring(e_text)
    except TypeError:
        # Python3
        return base64.decodestring(e_text.encode("utf8")).decode("utf8")

text = '''\
I keep pressing the Home button on my
smartphone, but I am still stuck at work.'''

encrypted = encrypt106(text)
print("encrypted:\n{}".format(encrypted))

print('-'*50)

decrypted = decrypt106(encrypted)
print("decrypted:\n{}".format(decrypted))

''' my result ...
encrypted:
SSBrZWVwIHByZXNzaW5nIHRoZSBIb21lIGJ1dHRvbiBvbiBteQpzbWFydHBob25lLCBidXQgSSBh
bSBzdGlsbCBzdHVjayBhdCB3b3JrLg==

--------------------------------------------------
decrypted:
I keep pressing the Home button on my
smartphone, but I am still stuck at work.
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Not sure how to handle the comma that is used in some countries as a decimal point.
We have to make sure the numeric string can be converted to a float.
For instance in the US the comma is a "thousand separator".

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

One more option ...

# use Tkinter's simple dialogs (pop-up) to ask for input
# minvalue and maxvalue are optional

try:
    # Python2
    import Tkinter as tk
    import tkSimpleDialog as tksd
except ImportError:
    # Python3
    import tkinter as tk
    import tkinter.simpledialog as tksd

root = tk.Tk()
# show input dialogs without the Tkinter window
root.withdraw()

# if a non-numeric value is entered, will prompt again
# integer entries are converted to floats
price = tksd.askfloat("Price", "Enter the price of the item:")

print(price)
TrustyTony commented: Nice! +12
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The Vigenère cipher is a method of encrypting alphabetic text by using a series of different Caesar ciphers based on the letters of a keyword. See this example ...
http://www.daniweb.com/software-development/python/code/382803/one-line-vigener-single-decryptencrypt-function-with-generator

See also ...
http://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another simple crypt is the swap crypt ...
http://www.daniweb.com/software-development/python/code/448055/encrypt-and-decrypt-with-the-swap-crypt

Easy to use in combination with some of the other encryption methods.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Uses the PySide GUI toolkit's QtMultimedia module to play a specified sound. You can change frequency/pitch and volume of the sine wave.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The PySide (PyQT) GUI toolkit can be used to play wave sound files.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

For added security we can employ a password ...

''' encrypt107.py
using the Python module base64 to encode and decode text
also added XOR crypting against a password
tested with Python27
'''

import base64
import io
import operator

def encrypt107(text, password):
    '''
    use base64 encoding
    '''
    x_text = XOR_crypt(text, password)
    return base64.encodestring(x_text)

def decrypt107(e_text, password):
    '''
    use base64 decoding
    '''
    b64_text = base64.decodestring(e_text)
    return XOR_crypt(unicode(b64_text), password)

def XOR_crypt(text, password):
    # create two streams in memory the size of the text
    # stream sr to read the text from and
    # stream sw to write XOR crypted bytes to
    sr = io.StringIO(text)
    sw = io.StringIO(text)
    # make sure to start both streams at start position
    sr.seek(0)
    sw.seek(0)
    n = 0
    for k in range(len(text)):
        # loop through password start to end and repeat
        if n >= len(password) - 1:
            n = 0
        p = ord(password[n])
        n += 1
        # read one character from stream sr
        c = sr.read(1)
        b = ord(c)
        # xor byte with password byte
        t = operator.xor(b, p)
        z = chr(t)
        # advance position to k in stream sw then write one character
        sw.seek(k)
        sw.write(unicode(z))
    # reset stream sw to beginning
    sw.seek(0)
    # read all the bytes in stream sw
    text_out = sw.read()
    sr.close()
    sw.close()
    return text_out

# unicode string needed for Python27
text = u'''\
It has been a rough day. I got up this morning and put on my
shirt and a button fell off. I picked up my briefcase and
the handle came off. …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another simple way to decode a text that can be send via email. The receiving party has to have the same program ...

''' encrypt106.py
using the Python module base64 to encode and decode text
or any binary data like images/pictures
tested with Python27
'''

import base64

def encrypt106(text):
    '''
    use base64 encoding
    '''
    return base64.encodestring(text)

def decrypt106(e_text):
    '''
    use base64 decoding
    '''
    return base64.decodestring(e_text)

text = '''\
I keep pressing the Home button on my
smartphone, but I am still stuck at work.'''

encrypted = encrypt106(text)
print("encrypted:\n{}".format(encrypted))

print('-'*50)

decrypted = decrypt106(encrypted)
print("decrypted:\n{}".format(decrypted))

''' my result ...
encrypted:
SSBrZWVwIHByZXNzaW5nIHRoZSBIb21lIGJ1dHRvbiBvbiBteQpzbWFydHBob25lLCBidXQgSSBh
bSBzdGlsbCBzdHVjayBhdCB3b3JrLg==

--------------------------------------------------
decrypted:
I keep pressing the Home button on my
smartphone, but I am still stuck at work.
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Very nice effort, here is the modernized code ...

# -*- coding: cp1252 -*-
''' encrypt105.py
modified code from james.lu.75491856 (James Lu)
'''

# needs to be at beginning of program code
# allows Python27 to use PYthon3 print() options
from __future__ import print_function
import string

def crypt(text, code):
    ''' encodes or decodes '''
    e_text = ""
    for c in text:
        e_text += code.get(c, c)
    return e_text    

# establish letter code dictionary
code = dict(zip(string.letters, string.letters[::-1]))

text = '''\
Man who run in front of car, get tired.
Man who run behind car, get exhausted.
'''

encrypted = crypt(text, code)
print("encrypted:\n{}".format(encrypted))

print('-'*50)

decrypted = crypt(encrypted, code)
print("decrypted:\n{}".format(decrypted))

''' my result ...
encrypted:
òäÖ ÍÝÕ ÒÏÖ ÜÖ ßÒÕÖÐ Õß âäÒ, ÞàÐ ÐÜÒàá.
òäÖ ÍÝÕ ÒÏÖ ãàÝÜÖá âäÒ, ÞàÐ àÌÝäÏÑÐàá.

--------------------------------------------------
decrypted:
Man who run in front of car, get tired.
Man who run behind car, get exhausted.
'''

Just a hint, don't use little l for names it looks too much like a one.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Going one step further and alternate up and down shift ..

''' encrypt104.py
shift ASCII values by one and alternate up/down encryption/decryption
makes cracking by analyzing the letter frequency pattern even harder
special consideration given to space to make printable character
'''

def encrypt104(text):
    '''
    alternate shifts of ASCII value of text up/down by one
    '''
    # replace space with '}' to give printable character
    space = ' '
    text = text.replace(space , '}')
    e_text = ""
    for ix, c in enumerate(text):
        if ix % 2:
            e_text += chr(ord(c) - 1)
        else:
            e_text += chr(ord(c) + 1)
    return e_text

def decrypt104(e_text):
    '''
    alternate shifts of ASCII value of e_text up/down by one
    '''
    text = ""
    for ix, c in enumerate(e_text):
        if ix % 2:
            text += chr(ord(c) + 1)
        else:
            text += chr(ord(c) - 1)
    space = ' '
    text = text.replace('}', space)
    return text

text = "Facebook or Twitter make privacy a thing of the past"

encrypted = encrypt104(text)
print("encrypted = {}".format(encrypted))

print('-'*50)

decrypted = decrypt104(encrypted)
print("decrypted = {}".format(decrypted))

''' my result ...
encrypted = G`ddcnpj~ns|Uvjsuds|n`ld~oshw`dx~`~sihof~ng|ugf|q`ts
--------------------------------------------------
decrypted = Facebook or Twitter make privacy a thing of the past
'''

If you have multiline code, then the newline character can be dealt with similar to the space character. Explore this option.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another way to make letter frequency analysis more difficult ...

''' encrypt103.py
shift every second ASCII value by one encryption/decryption
makes cracking by analyzing the letter frequency pattern harder
'''

def encrypt103(text):
    '''
    shift every second ASCII value of text up by one
    '''
    e_text = ""
    for ix, c in enumerate(text):
        if ix % 2:
            e_text += c
        else:
            e_text += chr(ord(c) + 1)
    return e_text

def decrypt103(e_text):
    '''
    shift every second ASCII value of text down by one
    '''
    text = ""
    for ix, c in enumerate(e_text):
        if ix % 2:
            text += c
        else:
            text += chr(ord(c) - 1)
    return text

text = "Facebook or Twitter make privacy a thing of the past"

encrypted = encrypt103(text)
print("encrypted = {}".format(encrypted))

print('-'*50)

decrypted = decrypt103(encrypted)
print("decrypted = {}".format(decrypted))

''' my result ...
encrypted = Gadecopk!os Uwjtues nale!psiwady!a!tiiog!og uhf qatt
--------------------------------------------------
decrypted = Facebook or Twitter make privacy a thing of the past
'''

You can easily turn this into a skip every third character or so on.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This will make the use of letter frequency a little harder for the snoop ...

''' encrypt102.py
simple shift ASCII value by one encryption/decryption
make analyzing the letter frequency pattern harder via substitution
change all 'q' to '}'  then change all 'e' to 'q'
'''

def encrypt102(text):
    '''
    replace 'q' with '}' and 'e' with 'q'
    shift ASCII values of text up by one
    '''
    text = text.replace('q', '}').replace('e', 'q')
    return "".join(chr(ord(c) + 1) for c in text) 

def decrypt102(e_text):
    '''
    shift ASCII values of text down by one
    then replace 'q' with 'e' and '}' with 'q'
    '''
    q_text = "".join(chr(ord(c) - 1) for c in e_text)
    text = q_text.replace('q', 'e').replace('}', 'q')
    return text


text = "Facebook or Twitter make privacy a thing of the past"

encrypted = encrypt102(text)
print("encrypted = {}".format(encrypted))

print('-'*50)

decrypted = decrypt102(encrypted)
print("decrypted = {}".format(decrypted))

''' my result ...
encrypted = Gbdrcppl!ps!Uxjuurs!nblr!qsjwbdz!b!uijoh!pg!uir!qbtu
--------------------------------------------------
decrypted = Facebook or Twitter make privacy a thing of the past
'''

You get the drift. Make it even more difficult to crack using your imagination.
A replace character scheme can also be applied to multiline text's newline characters.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

With just about everybody snooping around your emails today with the excuse of hunting the bad guys, coding to keep some resemblance of privacy is getting important. I will start out with some simple encryption examples to get this started. You are invited to give us your thoughts and codes. Hopefully, we can improve the code as time goes on.

The first example is very simplistic form of a Caesar cipher, simply increasing the ASCII values by one to encrypt and decreasing by one to decrypt. It would be easy to figure that scheme out by looking at the letter frequency. In the English language the most common letter is 'e' and suddenly it would be the next ASCII character 'f'. So, even a challenged snoop could see through that after a while.

''' encrypt101.py
simple shift ASCII value by one encryption/decryption
however simple to crack by analyzing the letter frequency pattern
'''

def encrypt101(text):
    '''
    shift ASCII values of text up by one
    '''
    return "".join(chr(ord(c) + 1) for c in text) 

def decrypt101(e_text):
    '''
    shift ASCII values of text down by one
    '''
    return "".join(chr(ord(c) - 1) for c in e_text) 

text = "Facebook or Twitter make privacy a thing of the past"

encrypted = encrypt101(text)
print("encrypted = {}".format(encrypted))

print('-'*50)

decrypted = decrypt101(encrypted)
print("decrypted = {}".format(decrypted))

''' my result ...
encrypted = Gbdfcppl!ps!Uxjuufs!nblf!qsjwbdz!b!uijoh!pg!uif!qbtu
--------------------------------------------------
decrypted = Facebook or Twitter make privacy a thing of the past
'''

This type of code does not need a password, …

Lardmeister commented: good idea +10
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Running behind a car can be exhausting!

Reverend Jim commented: Boo. +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

"The worst thing about being famous is the invasion of your privacy."
... Justin Timberlake

Note: Now we are finding out that we don't even need to be famous!

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

These two strings walk into a bar and sit down.
The bartender says, "So what'll it be?"
The first string says, "I think I'll have a beer quag fulk boorg jdkCjfdLk jk3s d#f67howeU r89nvyowmc63Dz x.xvcu"
"Please excuse my friend," the second string says, "He isn't null-terminated."

theguitarist commented: too good :D +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You never finish a program, you just stop working on it.
(true for any language)

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This code snppet uses the wx.lib.filebrowsebutton.FileBrowseButton widget to pick a file, in this case a '.wav' sound file, and plays it with the wx.Sound widget.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

At times the speed you can develop a program is important, that's where Python will be best.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

“Many of life's failures are men who did not realize how close they were to success when they gave up.”
I am thinking of the fellow who invented 6up.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The world's largest solar power plant is close to completion south of Las Vegas. It is a thermal design where where 340,000 large mirrors focus sunlight on three towers with boilers on top to produce up to 392 megawatt of electric power. Google is one of the investors in the project.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Imagine you were working for the government security agency and had to read large amounts of your fellow citizens' emails. Create a Python program that will help you to find certain words or combination of words to indicate foul play.

M.S. commented: nice project haha +4
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is an example ...

""" con_setup2.py

Using cx_freeze with Python33 to package a console
program to an executable file (.exe in Windows OS).

Might want to put a console-wait-line in at the end of your program.

Put this setup program and your console program file into the same
directory.  Change the filename in this setup program and also edit
name, version and description in setup() if you so desire.

A directory 'build' is created with a subdirectory 'exe.win32-3.3'
containing all the files needed for distribution including the
.exe file named after the console program file.

The total distribution has a size of about 4.8 Mb.
this includes the Python33.dll interpreter
and some small pyds and a zip file

I used:
http://cx-freeze.sourceforge.net/
cx_Freeze-4.3.1.win32-py3.3.msi

tested with Python33
"""

from cx_Freeze import setup, Executable
import sys

sys.argv.append("build")  # replaces commandline arg 'build'

# change the filename to your program file
filename = "HelloWorld.py"

setup(
    name = "Hello World",
    version = "1.0",
    description = "console cx_Freeze script",
    executables = [Executable(filename)])
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
If you have a Windows computer, you can use Portable Python.  Here are the latest updates ...
Portable Python installs a portable version of Python right on your USB flash drive (1GB+). 
You can use the flash drive now on any Windows computer that does not have Python installed. 
http://portablepython.com/wiki/PortablePython2.7.5.1
Package file size (compressed): 106MB
Installed size: based on selected packages, between 50MB and 545MB 
also contains these packages ...
NumPy 1.7.1
SciPy 0.12.0
Matplotlib 1.2.1
PyWin32 218
Django 1.5.1
PIL 1.1.7
Py2Exe 0.6.9
wxPython 2.9.4.0
PyScripter v2.5.3    
NetworkX 1.7
Lxml 2.3
PySerial 2.5
PyODBC 3.0.6
PyGame 1.9.1
PyGTK 2.24.2
PyQt 4.10.1
IPython 0.13.1
Pandas 0.11.0 

http://portablepython.com/wiki/PortablePython3.2.5.1
Package file size (compressed): 65MB
Installed size: based on selected packages, between 63MB and 260MB 
also contains these packages ...
PyScripter v2.5.3
NumPy 1.7.1
SciPy 0.12.0
Matplotlib 1.2.1
PyWin32 218
NetworkX 1.7
Lxml 2.3
PySerial 2.5
PyODBC 3.0.2
PyQt 4.9.6-1
IPython 0.13.1
Pandas 0.11.0 

Run the PyScripter IDE via PyScripter-Portable.exe
M.S. commented: thanks for the info +4
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The wxPython Phoenix project can be used with Python version 2 and version 3. The project applies pretty much the familiar wxPython code. Here we are testing a dragable borderless frame.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

In Las Vegas some worshippers at Sunday services will give casino chips rather than cash when the basket is passed.

Since they get chips from many different casinos, the churches have devised a method to collect the offerings.

They send all their collected chips to a nearby Franciscan Monastery for sorting. Then the chips are taken to the casinos of origin and cashed in.

These monks are called chip monks.

ddanbe commented: Great! +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you use the Windows OS and IronPython, then you can use the SharpDevelop4 IDE with its MS Studio like Formbuilder.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The above IronPython script can be compiled to a standalone .exe file this way ...

''' compile_ip1.py
compile an ironpython sript file to an executable file
creates a Windows .exe file and an associated .dll file
in this case ...
ip_ListBox_99BoB.exe  (3kb)
ip_ListBox_99BoB.dll  (13kb)

it is best to put this file into a special directory
together with the ironpython script file you want to compile

this code needs to be run with IronPython 2.7.3
'''

import subprocess

# the ironpython script file you want to compile ...
ip_scriptfile = "ip_ListBox_99BoB.py"

# location of ironpython and compile utility
ipython = "C:/IronPython2.7.3/ipy.exe"
utility = "C:/IronPython2.7.3/Tools/Scripts/pyc.py",
main = "/main:" + ip_scriptfile
target = "/target:winexe"
subprocess.call([ipython, utility, main, target])
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you use the Windows OS, then IronPython allows you to create a GUI program taking advantage of the .NET framework. You also have the option to compile the program into a standalone .exe file (and the needed .dll file).

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The average distance between Earth and Sun is about 150 million kilometers (93 million miles). Write a Python program the calculates the speed (km/hr or miles/hr) the Earth has around the Sun.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I wonder if it's better for a frequent traveler to store private stuff on the cloud (Sky Drive, iCloud) and access it via the internet at the destination.

diafol commented: love it +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Keep skunks and bankers at a distance.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just a code sample that allows you to play your midi or mp3 music files with Python and module pygame.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

To set a particular color transparent use ...

# set a particular color fully transparent
white = (255, 255, 255)
circle.set_colorkey(white)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This might work for you ...

''' re_sub_translate3.py
a simple and rough English to German translator

specifically replace whole words only
will replace I but not change Italy
attached quotes and punctuation marks are neutral
modified to handle capitalized words
'''

import re

def re_replacer(match_obj):
    '''
    this function will be called for each key_word
    in the text during substitution/translation
    tries to handle capitalized words
    '''
    word = match_obj.group(0)
    try:
        return replace_dict[word]
    except KeyError:
        try:
            print(word.lower())  #test
            return replace_dict[word.lower()]
        except KeyError:
            return replace_dict.get(word, word)

# note capitalized word 'BY'
eng_text = "Karl and I will travel BY car to Italy."

# create a dictionary of key_word:replace_with pairs
replace_dict = {
'and' : 'und',
'by' : 'mit',
'car' : 'Auto',
'I' : 'ich',
'Italy' : 'Italien',
'to' : 'nach',
'travel' : 'reisen',
'will' : 'werden'
}

# a regular expression matching all identifiers
pattern = re.compile(r"[A-Za-z]\w*")

# optional re.IGNORECASE does not work
#pattern = re.compile(r"[A-Za-z]\w*", re.IGNORECASE)

ger_text = pattern.sub(re_replacer, eng_text)

# show result
print("English text ...")
print(eng_text)
print('-'*50)
print("German text ...")
print(ger_text)

''' result -->
English text ...
Karl and I will travel BY car to Italy.
--------------------------------------------------
German text ...
Karl und ich werden reisen mit Auto nach Italien.
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Thanks RufusVS, you gave me the push to finally update this little gem to work with both versions of Python ...

""" PG_MidiBase64_py23.py
experiments with module pygame from: http://www.pygame.org/
play an embedded midi music file (base64 encoded)

use this short program to create the base64 encoded midi music string
(base64 encoding simply produces a readable string from binary data)
then copy and paste the result into your pygame program

Python2 code ...
import base64
mid_file = "FishPolka.mid"
b64_str = base64.encodestring(open(mid_file, 'rb').read())
print("mid64='''\\\n" + b64_str + "'''")

Python3 code ...
import base64
mid_file = "FishPolka.mid"
b64_str = base64.encodestring(open(mid_file, 'rb').read()).decode("utf8")
print("mid64='''\\\n" + b64_str + "'''")

updated to work with Python2 and Python3 by  vegaseat  16may2013
"""

import pygame
import base64
import io

def play_music(music_file):
    """
    stream music with mixer.music module in blocking manner
    this will stream the sound from disk while playing
    """
    pygame.mixer.music.load(music_file)
    clock = pygame.time.Clock()
    pygame.mixer.music.play()
    # check if playback has finished
    while pygame.mixer.music.get_busy():
        clock.tick(30)


mid64='''\
TVRoZAAAAAYAAQAGAJBNVHJrAAAAJwD/WAQEAhgIAP9ZAgAAAP9RAwfCOwD/BgpGaXNoLVBvbGth
AP8vAE1UcmsAAANoAP8hAQAA/wMOQWNjb3JkaW9uIEhpZ2gAwRUAsQd/ALEKQAD/AQpGaXNoIFBv
bGthAJFOZGhOAAFQYyNQAAFSZBdSADFQZCNQACVOYxdOADFMZCNMACVLYxdLADFJYyNJACVOZCNO
AAFNYyNNAAFOYyNOAAFQZCNQAAFOZCNOAAFMZCNMAAFLZCNLAAFHYyNHAAFLYyNLAAFKYyNKAAFL
YyNLAAFMZCNMAAFLZCNLAAFJZCNJAAFHYyNHAAFCYyNCAAE/YyM/AAFCYyNCAAFHZCNHAAFLZCNL
AAFOYxFOADdQYyNQACVQYyNQACVJYyNJACVJZIEPSQABTGQjTAABS2QjSwABTGMjTAABTmQjTgAB
TGMjTAABS2QjSwABSWMjSQABSGMjSAABSWQjSQABQmMjQgABRmQjRgABSWQjSQABTGQjTAABSWMj
SQABRmQjRgABRGQjRAABQmMjQgABRmQjRgABSWQjSQABTGMjTAABUmMRUgA3UGQjUAAlUGMjUAAl
S2MjSwAlS2SBD0sAAU5jI04AAU1kI00AAU5jI04AAVBjI1AAAU5jI04AAUxkI0wAAUtjI0sAAUdk
I0cAAUtjI0sAAUpkI0oAAUtkI0sAAUxjI0wAAUtkI0sAAUlkI0kAAUdjI0cAAUJjI0IAAT9kIz8A
AUJjI0IAAUdkI0cAAUtkI0sAAU5kI04AAUdjI0cAAUtjI0sAAU5kI04AAVBjgXtQACVQZCNQAAFP
YyNPAAFQZCNQAAFSYyNSAAFVYyNVAAFTYyNTAAFSYyNSAAFQYyNQAAFOYyNOAAFNYyNNAAFOZCNO
AAFPZCNPAAFQZCNQAAFOYyNOAAFMZCNMAAFLYyNLAAFMZCNMAAFLYyNLAAFMZCNMAAFNZCNNAAFO
ZCNOAAF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ZPASYADiZNASYADSZ6BCYAICZ5ACRtBCQAACYAQyZ6BCYARSZ5ACRsBCQAACYA
QiZ+BCYAFyZ8BCYADSZ/BCYAGCZ6AiRnAiYAAiQAQiZ/BCYARiRvAjluAiQAAjkAQip3BCoAQyRl
BCQARSpoBCoAQyRmBCQARSpqBCoAQyRoBCQARSpsBCoAQyRoBCQARSprBCoAQyRkBCQARSpuBCoA
QyRjBCQARSpkBCoAQyRmBCQARSppBCoAQyRmBCQARSpxBCoARCRmBCQARCp6BCoARCRoBCQARCpy
BCoARCRlBCQARCp/BCoARSRpBCQAQyp6BCoARCRqBCQAQyp6BCoARSRqBCQARCp6BCoARCRpBCQA
RCp/BCoARSRrBCQAQyV6ACp1BCoAQyUAASRnBCQARCV7ACp7BCoAQyUAASRlBCQARCV7ACp9BCoA
QyUAASRoBCQARCV7ACp1BCoAQyUAASRrBCQARCV6ACp+BCoAQyUAASRpBCQAQyp3ASV7ACRoAyoA
ASQAQyUAASRnBCQARCV7ACp6BCoAICV6IyUAAiRpBCQAHiUAJSV6ACp5BCoAQyUAASRrBCQARCV6
ACp4BCoAQyUAASRwBCQARCV6ACp8BCoAQyUAASRrBCQAQyp6ASV6AyoARCUAASRmBCQARCV6ACp9
BCoAQyUAASRpBCQARCV7ACp3BCoAQyUAASRqBCQARCV7ACp0BCoAQyUAASRqBCQARCV6ACp6BCoA
ICV6IyUAASRlBCQAHyUAJCp6ASV7AyoARCUAADlhAiR/AjkAAiQAH7kHdBG5B3ETmSV6ACp4BCoA
QyUAASRuBCQARCV6ACpuBCoAQyUAACRwBCQARCp3ASV7AyoARCUAASRnBCQAQyp2ASV7AyoARCUA
ASRuBCQARCV7ACp6BCoAQyUAASRtBCQAQyp6ASV7AyoARCUAASV6ACRsBCQAQiZ/ASUAAyYAFyZ8
BCYADSZ/BCYAGCZ5Ajl6ACRoAiYAAiQAgQs5AAD/LwA=
'''

# create a memory file object
try:
    # Python27
    midi_str = base64.b64decode(mid64)
    music_file = io.BytesIO(midi_str)
except TypeError:
    # Python3
    midi_bytes = …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Actually
base64.b64decode()
takes care of trailing newline characters

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Use this ...

# set alpha to 0 (fully transparent) to 255 (not transparent)
circle.set_alpha(150)
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You can draw a number of shapes directly on the PyGame window, and then save the drawing to an image file.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

An example might explain it better ...

# normal function declaration
def timestwo1(x):
  return x * 2

# using lambda (not anonymous)
timestwo2 = lambda x: x * 2

# test it ...
print(timestwo1(4))  # 8
print(timestwo2(4))  # 8

# or make it anonymous ('on the fly')
print((lambda x: x * 2)(4))  # 8
ABMorley commented: A great example. It's worth pointing out that the two functions timetwo1 and timetwo2 are identical. xxx = lambda ... is a perfectly valid way to create a function. Indeed in some languages it is the way it's done. +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You can run this simple code ...

''' names_reserved101.py
show all builtin functions/methods and keywords
avoid using any of those names for your variables, or
you will get conflicts, using keywords flag as error
'''

from keyword import kwlist

print("A list of Python's keywords:")
print('\n'.join(kwlist))

print('-'*60)

print("Show all Python builtin functions, classes and alike:")
# does a case insensitive sort first
print('\n'.join(sorted(dir(__builtins__), key=str.lower)))

There is also this ...

print("Show all the modules Python currently knows about:")
help("modules")