vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

For those who are afraid of lycanthropes and full moons, here is a way to figure out the phase of the moon.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A common mistake beginners make is to name their code/script file the same as a Python module they need to import. For instace random.py will screw up the random module.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is an example ....

''' pqt_thread_test102.py
test Qthread threading
time delay works properly

modified from ...
http://joplaete.wordpress.com/2010/07/21/threading-with-pyqt4/
'''

import sys, time
from PyQt4 import QtCore, QtGui

class GenericThread(QtCore.QThread):
    def __init__(self, function, *args, **kwargs):
        QtCore.QThread.__init__(self)
        self.function = function
        self.args = args
        self.kwargs = kwargs

    def __del__(self):
        self.wait()

    def run(self):
        self.function(*self.args, **self.kwargs)
        return


class MyApp(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.threadPool = []

        self.setGeometry(300, 300, 280, 420)
        self.setWindowTitle('QThread test')

        self.layout = QtGui.QVBoxLayout(self)

        self.testButton = QtGui.QPushButton("test")
        self.connect(self.testButton, QtCore.SIGNAL("released()"),
                     self.test)
        self.listwidget = QtGui.QListWidget(self)

        self.layout.addWidget(self.testButton)
        self.layout.addWidget(self.listwidget)

    def add(self, text):
        """ Add item to list widget """
        #print("Add: " + text)  # test print
        self.listwidget.addItem(text)
        self.listwidget.sortItems()

    def addBatch(self, text="test", iters=10, delay=1.5):
        """ Add several items to list widget """
        for i in range(1, iters):
            # time delay works best with threading
            time.sleep(delay)
            self.add(text + " " + str(i))

    def test(self):
        self.listwidget.clear()
        # apply threading to self.addBatch()
        self.genericThread = GenericThread(self.addBatch,
                                "using generic thread ", delay=0.5)
        self.genericThread.start()


app = QtGui.QApplication(sys.argv)
test = MyApp()
test.show()
app.exec_()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Another approach ...

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

specifically replace whole words only
will replace I but not change Italy
note that this replacement is case sensitive
attached quotes and punctuation marks are neutral
'''

import re

def re_replacer(match_obj):
    '''
    this function will be called for each key_word
    in the text during substitution/translation
    '''
    word = match_obj.group(0)
    return replace_dict.get(word, word)

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*")

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

A working example ...

''' tk_Canvas_BGImage1.py
use a Tkinter canvas for a background image
for result see http://prntscr.com/12p9ux
'''

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

root = tk.Tk()
root.title('background image')

# pick a .gif image file you have in the working directory
fname = "Flowers.gif"
bg_image = tk.PhotoImage(file=fname)
# get the width and height of the image
w = bg_image.width()
h = bg_image.height()

# size the window so the image will fill it
root.geometry("%dx%d+50+30" % (w, h))

cv = tk.Canvas(width=w, height=h)
cv.pack(side='top', fill='both', expand='yes')

cv.create_image(0, 0, image=bg_image, anchor='nw')

# add canvas text at coordinates x=15, y=20
# anchor='nw' implies upper left corner coordinates
cv.create_text(15, 20, text="Python Greetings", fill="red", anchor='nw')

# now add some button widgets
btn1 = tk.Button(cv, text="Click")
btn1.pack(side='left', padx=10, pady=5, anchor='sw')

btn2 = tk.Button(cv, text="Quit", command=root.destroy)
btn2.pack(side='left', padx=10, pady=5, anchor='sw')

root.mainloop()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

can I import a file from the very same folder as the file I want to run?

Yes, this is one way Python can find the import file.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Try ...
wordlist.sort()
then ...
wordlist.sort(key=len)

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Swaroop C.H. has rewritten his excellent beginning Python tutorial for Python3:
http://swaroopch.com/notes/python/

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Hint ...
sentence.split() will give you a list of words.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Would you take a job that goes for 14 days, where on the first day you make 1 cent, on the second day you double to 2 cents, on the third day you double this to 4 cents and so on?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

How to play a sound file in C.

ernie.cordell commented: That would make an interesting autotools project: There are many approaches to achieve this (I now realise after having done it from scratch before discovering several libraries). Since it varies from platform to platform, the GNU community would probab +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

You can do something like that ...

''' infile_test.py
data processing from a file

file infile.txt has content ...
taxon1
ACCGTGGATC
CCTATTGATT
GGATATTATC
taxon2
TTCATATGTA
GGATTTCATA
GATGGCCCCC 
'''

fname = "infile.txt"

with open(fname) as fin:
    s2 = ""
    for line in fin:
        line = line.rstrip()
        if "taxon" in line:
            # add a space
            line += ' '
            # might need to adjust this value
            if len(s2) > 10:
                s2 += '\n'
        s2 += line
    print(s2)

''' result ...
taxon1 ACCGTGGATCCCTATTGATTGGATATTATC
taxon2 TTCATATGTAGGATTTCATAGATGGCCCCC
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Hint ...

s = '''\
taxon1
ACCGTGGATC
CCTATTGATT
GGATATTATC
'''

s2 = ""
for ix, line in enumerate(s.split('\n')):
    line = line.rstrip()
    if ix == 0:
        # add a space
        line += ' '
    s2 += line

print(s2)

''' result ...
taxon1 ACCGTGGATCCCTATTGATTGGATATTATC
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Works just fine for me. BTW, line 17 is the continuation of line 16.
If you use an older version of Python (older than 2.7), it may not have dictionary comprehension yet.

As of this date please upgrade your Python2 version to 2.7.4
and Python3 version to 3.3.1

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

On an analog clock calculate the angle between the hour hand and the minute hand at a given time of hh:mm, let's say 11:25.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The key word argument **kw indicates a dictionary of variable number of key:val arguments

Used when the number of arguments is not known ahead of time, an example ...

def make_dic(**kw):
    print(vars())  # show local dictionary
    return kw

d = make_dic(dg='dog', bw='bow', ct='cat')
print('-'*50)
print(d)

''' result ...
{'kw': {'dg': 'dog', 'bw': 'bow', 'ct': 'cat'}}
--------------------------------------------------
{'dg': 'dog', 'bw': 'bow', 'ct': 'cat'}
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Not sure which version of Python you are using, but this should work with Python27 and Python33 ...

''' file_read103.py

assume mynames.txt has these content lines ...
Fred
Mary
Lisa
Amy
'''

fname = "mynames.txt"
with open(fname) as fin:
    k = 1
    for name in fin:
        # rstrip() removes trailing newline char
        print("{}: {}".format(k, name.rstrip()))
        k += 1

''' result ...
1: Fred
2: Mary
3: Lisa
4: Amy
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

A simple test of PySide's QFileDialog widget and its method getOpenFileNames. Use method getOpenFileName if you want just one file name.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Expanding on snippsat's code ...

''' word_frequency102.py

file your.txt has data ...
I love the python programming
How love the python programming?
We love the python programming
Do you like python for kids?
I like Hello World Computer Programming for Kids and Other Beginners.
'''

import re
from collections import Counter

# read the text file and create a list of all words
# in lower case and without the punctuation marks
with open('your.txt') as f:
    no_punct = re.findall(r'\w+', f.read().lower())

#print(no_punct)  # test

# create a list of (word, fequency) tuples
# count has a default sort of most common frequency first
count = Counter(no_punct).most_common()

for word, freq in count:
    print("{} {}".format(freq, word))

''' result ...
4 programming
4 python
3 love
3 the
2 kids
2 like
2 for
2 i
1 and
1 do
1 we
1 how
1 hello
1 beginners
1 computer
1 world
1 other
1 you
'''

print('-'*30)  # line of 30 dashes

# sorted() defaults to first element in tuple (word, frequency)
for word, freq in sorted(count):
    print("{} {}".format(freq, word))

''' result ...
1 and
1 beginners
1 computer
1 do
2 for
1 hello
1 how
2 i
2 kids
2 like
3 love
1 other
4 programming
4 python
3 the
1 we
1 world
1 you
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is an example ...

''' Tk_Entry_numbers1.py
a general Tkinter program to enter two data items
process the data and display the result
tested with Python27/33
'''

try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk

def calculate():
    """
    in this case the data items are floating point numbers
    that are simply added in the example data process
    the result is displayed in a label
    """
    try:
        x = float(enter1.get())
        y = float(enter2.get())
        # the process step, customize to your needs ...
        s = str(x + y)
        # display the result
        label3.config(text=s)
    except ValueError:
        label3.config(text='Enter numeric values for x and y')

def setfocus2(event):
    enter2.focus_set()


# create the root window
root = tk.Tk()

# create all the components/widgets
label1 = tk.Label(root, text='Enter number x:', width=28)
enter1 = tk.Entry(root, bg='yellow')
label2 = tk.Label(root, text='Enter number y:')
enter2 = tk.Entry(root, bg='yellow')
button1 = tk.Button(root, text='Add the numbers', command=calculate)
# the result label
label3 = tk.Label(root, text='', bg='green')

# pack widgets vertically in the root window in that order
label1.pack(side='top', fill='x')
enter1.pack(side='top', fill='x')
label2.pack(side='top', fill='x')
enter2.pack(side='top', fill='x')
button1.pack(side='top')
label3.pack(side='top', fill='x')

# cursor in enter1
enter1.focus()
# return key in enter1 sets focus to enter2
enter1.bind("<Return>", func=setfocus2)

# start the event loop
root.mainloop()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This example calculates timed x, y points of a projectile motion that can be used for plotting or other calculations.

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

Download what from where?
Upload what to where?

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This seems to work ...

message = 'your mother wears army socks'
shift = 1

def cipher(message, shift):
    result = ''
    for letter in message:
        x = ord(letter)
        if letter.isalpha():
            x = x + shift
            offset = 65
            if letter.islower():
                offset = 97
            while x < offset:
                x += 26
            while x > offset+25:
                x -= 26
        result += chr(x)
    return result

encoded = cipher(message, shift)
decoded = cipher(encoded, -shift)

print encoded
print decoded

''' result..
zpvs npuifs xfbst bsnz tpdlt
your mother wears army socks
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Similiar to the snippet posted at:
http://www.daniweb.com/software-development/python/code/449036/display-an-image-from-the-web-tkinter
but this time we use PIL to resize the image from the internet keeping its aspect ratio to fit a specific display area/box.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is another way to approach this without a record style class ...

''' namedtuple_Billing101.py
file data1.csv looks like this:
A233;Apple;FOOD;1;5.00
A345;Blanck CD 10;DATA;10;0.25
B453;Pasta;FOOD;1;12.00
T545;USB-Memory 16GB;DATA;1;25

each line represents:
identity, name, category, quantity, price
'''

from collections import namedtuple
#import pprint

# read the data file into a string
with open("data1.csv") as fin:
    data_str = fin.read()

# create a list of [id, name, cat, quant, price] lists
data_list = [line.split(';') for line in data_str.split('\n') if line]

# create the named tuple object
Billing = namedtuple('bill', 'id, name, cat, quant, price')

# create a list of Billing instances
bill_list = [Billing(id, name, cat, int(quant), float(price))\
             for id, name, cat, quant, price in data_list]

# test output ...
print("------------------  F O O D  -------------------")
header = ('Product', 'Qty', 'Price/each', 'Price total')
print("%-18s %-5s %-6s %-10s" % (header))
total_food = 0
for bill in bill_list:
    if bill.cat == "FOOD":
        totalprice = bill.quant * bill.price
        sf = "%-18s %2d %10.2f %12.2f"
        print(sf % (bill.name, bill.quant, bill.price, totalprice))
        total_food += totalprice

print("Total food = %0.2f" % total_food)

print('-'*48)

print("------------------  D A T A  -------------------")
header = ('Product', 'Qty', 'Price/each', 'Price total')
print("%-18s %-5s %-6s %-10s" % (header))
total_data = 0
for bill in bill_list:
    if bill.cat == "DATA":
        totalprice = bill.quant * bill.price
        sf = "%-18s %2d %10.2f %12.2f"
        print(sf % (bill.name, bill.quant, bill.price, totalprice))
        total_data += totalprice

print("Total data = %0.2f" % total_data)

''' result ...
------------------  F O O D  -------------------
Product            Qty   Price/each Price total
Apple               1       5.00         5.00
Pasta …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The problem is your data lines don't split nicely into identity, name, category, price fields.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you use Tkinter, you can do this ...

"""
tk_setup2.exe

Using cx_Freeze with Python32 to package a Tkinter GUI toolkit
program to an executable file (.exe in Windows OS).  Module
cx_Freeze also is available for Unix systems.

Put this setup program and your Tkinter 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.2'
containing all the files needed for distribution including the
.exe file named after the Tkinter program file.

The total distribution has a size of about 13.5 MB

The Python32 version works much better now with tkinter code.

I used:
http://cx-freeze.sourceforge.net/
cx_Freeze-4.2.3.win32-py3.2.msi
"""

import sys
from cx_Freeze import setup, Executable

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

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

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(
    name = "Calculator2",
    version = "1.0",
    description = "cx_Freeze Tkinter script",
    executables = [Executable(filename, base=base)])
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just a few more hints ...

s = "abcdefg"

for x in range(1, len(s)+1):
    print(s[-x:])
    print(list(s[-x:]))
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Had to test this ...

try:
    # for Python2
    import Tkinter as tk
    import tkFileDialog as tkfd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.filedialog as tkfd


def list_dir():
    dirname = tkfd.askdirectory(parent=root, initialdir="/",
        title='Please select a folder/directory')
    root.title(dirname)  # test only
    myvar.set('Current Folder Selected is: ' + dirname)


root = tk.Tk()

myvar = tk.StringVar()
myvar.set('-----------')
label = tk.Label(root, textvariable=myvar, width=40, bg='yellow')
label.pack(side='left')
button = tk.Button(root, text=" Get Folder ", command=list_dir)
button.pack()

root.mainloop()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Translating too closely doesn't allow you to take adavantage of the chosen language's true power/elegance.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Starting with Python version 2.6 a permutate function has been added in the module itertools in the form of a generator itertools.permutations(iterable, r=None) ...

''' itertools_permutations.py
itertools.permutations(iterable, r=None) is a generator

If r is not specified or is None, then r defaults to the length of
the iterable and all possible full-length permutations are generated
'''

# needs Python26 or higher
from itertools import permutations

for p in permutations('art'):
    # join tuple p to a string
    print("".join(p))

''' result ...
art
atr
rat
rta
tar
tra
'''
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Simple code to show you how to display an image from a Web URL using the Tkinter Python GUI toolkit, the Python Image Library (PIL) and the data_stream created with io.BytesIO().

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Bear will kill you, but beer and wine are fine.

LastMitch commented: lol +0
Nick Evan commented: Agreed +0
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Commenting the obvious is rather distracting in code.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Your code has a handful of mistakes and misconceptions. I corrected some of them to get this to work ...

class Account:
    '''Wells Fargo.'''
    #global balance 
    def __init__(self, name, pin_number, balance):
        self.name = name
        self.pin_number = pin_number
        self.balance = balance

    def alter_pin(self, enter_a_pin):
        '''needs work'''
        '''To be used a later revision, changes a pin number.'''
        ID_List = []
        ID_List.append(enter_a_pin) 

    def ID_Pin(self):
        '''needs work'''
        pin = 0000
        return pin  

    def get_balance(self, pin_number): 
        if pin_number == self.pin_number:
            print("%s has balance: %d" % (self.name, self.balance))
        else:
            print("Access denied: Incorrect PIN.")

    def withdraw(self,pin_number, amount):
        if pin_number == self.pin_number:
            self.balance -= amount
            print("Withdrew  %d. New Balance: %d" % (amount, self.balance))
        else:
            print("Access denied: Incorrect PIN.")

    def deposit(self, pin_number, amount):
        if pin_number == self.pin_number:
            self.balance += amount
            print("Deposited %d. New Balance: %d" % (amount, self.balance)) 
            if self.balance <= 0:
                print("Balance limit reached!")
        else:
            print("Access denied: Incorrect PIN.") 

# create unique account instances ...
jimmy = Account("Jim", 0000, 100) 
jimmy.get_balance(0000)
jimmy.deposit(0000, 50000)

print('-'*40)

betsy = Account("Elisabeth", 1234, 777) 
betsy.get_balance(1234)
betsy.deposit(1234, 7000)

''' result ...
Jim has balance: 100
Deposited 50000. New Balance: 50100
----------------------------------------
Elisabeth has balance: 777
Deposited 7000. New Balance: 7777
'''

Note that self is a reference to the particular instance of the class.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

The bubble sort is slow and I thought it would be interesting to visualize the progress as it sorts an array of integers.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This snippet allows you to find the number of ordered permutations of items taken from a population of known size. It uses the well know algorithm with factorials. For very large populations you may want to use an approximation of factorials.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

If you want to know the number of combinations of x things taken n at a time, you can use the Python module gmpy. The module gmpy is a C-coded Python extension module that supports fast multiple-precision arithmetic, very handy if x things reach a large number.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Access the source code of Tkinter widgets ...

''' tk_button_inspect101.py
since Tkinter is written in Python you can access the source code
of a specified class with Python module inspect
'''

import inspect
try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk


root = tk.Tk()

t_btn = tk.Button(text="Hello World", width=25, bg='green')
t_btn.pack(padx=5, pady=5)

# get the Tkinter class Button source code ...
print(inspect.getsource(tk.Button))

root.mainloop()

'''
class Button(Widget):
    """Button widget."""
    def __init__(self, master=None, cnf={}, **kw):
        """Construct a button widget with the parent MASTER.

        STANDARD OPTIONS

            activebackground, activeforeground, anchor,
            background, bitmap, borderwidth, cursor,
            disabledforeground, font, foreground
            highlightbackground, highlightcolor,
            highlightthickness, image, justify,
            padx, pady, relief, repeatdelay,
            repeatinterval, takefocus, text,
            textvariable, underline, wraplength

        WIDGET-SPECIFIC OPTIONS

            command, compound, default, height,
            overrelief, state, width
        """
        Widget.__init__(self, master, 'button', cnf, kw)

    def tkButtonEnter(self, *dummy):
        self.tk.call('tkButtonEnter', self._w)

    def tkButtonLeave(self, *dummy):
        self.tk.call('tkButtonLeave', self._w)

    def tkButtonDown(self, *dummy):
        self.tk.call('tkButtonDown', self._w)

    def tkButtonUp(self, *dummy):
        self.tk.call('tkButtonUp', self._w)

    def tkButtonInvoke(self, *dummy):
        self.tk.call('tkButtonInvoke', self._w)

    def flash(self):
        """Flash the button.

        This is accomplished by redisplaying
        the button several times, alternating between active and
        normal colors. At the end of the flash the button is left
        in the same normal/active state as when the command was
        invoked. This command is ignored if the button's state is
        disabled.
        """
        self.tk.call(self._w, 'flash')

    def invoke(self):
        """Invoke the command associated with the button.

        The return value is the return value from the command,
        or an empty string if there is no command associated with
        the button. This command is ignored if the button's state …
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

“The best thing about the future is that it comes only one day at a time.”
... Abraham Lincoln

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Note:
Don't overdo private class variables and methods too much, since they will not be inherited by other classes.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Here is an example ...

''' class_private101.py
class variables and methods can be made private to the class
'''

class C(object):
    '''
    inheriting object is automatic in Python3
    '''
    # k is public to all instances of class C
    k = 1234
    # variable names with double underline prefix like
    # __m or __m_ will be private to the class
    # (now Python uses _classname__m here _C__m internally)
    __m = 5678
    # _n or _n_ or _n__ or __n__ will be public
    __n__ = 999

    def __init__(self, v):
        '''
        __init__() will be used first, if it's there
        '''
        self.value = v

    def add(self, x):
        return self.value + x

    def __subtract(self, y):
        '''
        double underline prefix makes this method private to class
        '''
        return self.value - y

    def deduct(self, y):
        return self.__subtract(y)


a = C(7)    # implies C.__init__(a, 7)
print(C)    # <class '__main__.C'>
print(a)    # <__main__.C object at 0x009FCB50>

print(a.add(2))     # 9
print(a.deduct(4))  # 3
print(a.value)      # 7
print(a.k)          # 1234
print(a.__n__)      # 999

# note that variable __m and
# method __subtract() are private to the class and
# give AttributeError: 'C' object has no attribute '__m'
# or AttributeError: 'C' object has no attribute '__subtract'
#print(a.__m)
#print(a.__subtract(4))
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

About 6 hours during the week and 2 hours on the weekend. I don't watch much TV, but spend time outside.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

In other words, game in your code is just one combination. To get a list of all combinations you have to append to an empty list (as shown by Lucaci Andrew) or use the list(combinations()) approach (shown by Griboullis) ...

from itertools import combinations

numbers = [1,2,3,4,5,6,7,8,9,10]
games = []
for game in combinations(numbers, 6):
    print game
    games.append(game)

# length of last game tuple
print len(game)   # 6
# length of list of all game combinations
print len(games)  # 210

# or

games2 = list(combinations(numbers, 6))
print len(games2)  # 210
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

This Python snippet shows how to control a VPython visual 3D sphere with Tkinter GUI toolkit button clicks.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Actually, Nimrod uses a syntax mix that reminds me of Python and C. Looks like it translates nimrod source code to C code and then uses a common C compiler like GCC to produce the executable file.

Shades of BCX that used a similar approach for Basic --> C --> exectuable.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

"Gravitation can not be held responsible for people falling in love."
... Albert Einstein

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Just a typical example ...

''' mp_barchart_horizontal2.py
make a simple horizontal bar chart

downloaded Windows installer (Python 3.3 version)
matplotlib-1.2.0.win32-py3.3.exe
from
http://matplotlib.org/downloads.html

tested with Python33
for result see: http://prntscr.com/theqs
'''

from pylab import *

# names of sales persons
persons = ['Tom', 'Jean', 'Paul', 'Mike', 'Beth']
# monthly sales numbers for each the above sales persons
x = [12600, 13400, 16350, 17100, 14700]
# centers the bars on the y axis
y = [0.5, 1.5, 2.5, 3.5, 4.5]

# horizontal bar is barh()
barh(y, x, align='center')
yticks(y, persons)
xlabel('$ sales')
title('Weekly Sales Numbers May 2012')
grid(True)

show()
vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

I would use the Python third party module matplot (pylab), free from:
http://matplotlib.org/contents.html

For a nice example see:
http://matplotlib.org/examples/mplot3d/bars3d_demo.html

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Python has been written to have a clear and readable syntax.

Ruby allows for a lot of symbolism similar to Perl. It saves you some typing, but makes things harder to read and understand.

Much of the use of Ruby can be attributed to a web development framework called Rails, or ‘Ruby On Rails’.

For all around programming Python has the better features and support.