bumsfeld 413 Nearly a Posting Virtuoso

You can expand on that:

# safe numeric input function
# all() needs Python25 or higher

def input_num(prompt="Enter number: "):
    """
    prompt the user for numeric input
    prompt again if the input is not numeric
    return integer or float
    """
    while True:
        # coded for Python3, Python2 uses raw_input()
        # strip() removes any leading or trailing whitespace
        num_str = input(prompt).strip()
        # make sure that all char are of typical number
        if all(c in '+-.0123456789' for c in num_str):
            break
    # float contains period (US)
    if '.' in num_str:
        return float(num_str)
    else:
        return int(num_str)

# testing ...
n = input_num()
print( n, type(n) )
bumsfeld 413 Nearly a Posting Virtuoso

Here is a typical example that might work for you:

# using Tkinter's Optionmenu() as a combobox
# allows one item to be selected
# use trace() and globalgetvar(name) to show selected choice

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

def show_choice(name, index, mode):
    sf = "value is %s" % root.globalgetvar(name)
    root.title(sf)


root = tk.Tk()

choices = ['red', 'green', 'blue', 'yellow','white']
color = tk.StringVar(root)
color.trace('w', show_choice)
# optionally preselect a choice
color.set(choices[2])
color_option = tk.OptionMenu(root, color, *choices)
color_option.pack(padx=70, pady=10)

root.mainloop()
bumsfeld 413 Nearly a Posting Virtuoso

Wit this:

import math

print(math.cos((2*math.pi)/3))         # -0.5
print(0.5 + math.cos((2*math.pi)/3))   # 2.22044604925e-16
print(-0.5 + math.cos((2*math.pi)/3))  # -1.0

x = math.cos((2*math.pi)/3)
print(x)        # -0.5
print([x])      # [-0.4999999999999998]
print([-0.5 + x])   # [-0.9999999999999998]

Strange?

bumsfeld 413 Nearly a Posting Virtuoso

You could add screen as one more argument to function question(q, a, b, c, d, screen).

bumsfeld 413 Nearly a Posting Virtuoso

It is my understanding the xpath is more for XML document searches.

bumsfeld 413 Nearly a Posting Virtuoso

People from the future will think that television is what we made convicted criminals watch.

bumsfeld 413 Nearly a Posting Virtuoso

And many new ones have cell phones pre-installed and ready to go any time day or night.

Are you talking about wife or girlfriend?

bumsfeld 413 Nearly a Posting Virtuoso

I don't like l as variable name (looks too much like number one), so I changed it a little:

import os
import fnmatch


for fn in os.listdir("C:/Bilder"):
    print fn  # test
    if fnmatch.fnmatch(fn, 'IMG*'):
        fn = fn.replace(fn, "HH")
        print fn

"""my result -->
IMG100_0015.jpg
HH
"""
bumsfeld 413 Nearly a Posting Virtuoso

What does your code look like?

bumsfeld 413 Nearly a Posting Virtuoso

Try to write your code files and run them from the IDE that comes with the Python installation (called IDLE). The IDE will connect the working directory (where your code file is located) with Python.exe

See http://www.daniweb.com/forums/thread20774.html

bumsfeld 413 Nearly a Posting Virtuoso

Something like this?

# plot of log line

from tkinter import *
import math

def particleCount(decay, p0, time):
        p = (p0*math.e)**(-(decay*time))
        return (p)

# define root window
root = Tk()
root.title("Radioactive Decay Graph")

# create frame to put control buttons onto
frame = Frame(root, bg='grey', width=400, height=40)
frame.pack(fill='x')
button1 = Button(frame, text='Button1')
button1.pack(side='left', padx=10)
button2 = Button(frame, text='Button2')
button2.pack(side='left')

# set canvas properties
width = 400
height = 400
center = height*(5/6)
x_increment = 1

# invoke canvas
c = Canvas(root, width=width, height=height, bg='black')
c.pack()
# add string
str1 = "Logarithmic decay graph"
c.create_text(10, 20, anchor=SW, text=str1)

#       line width stretch
x_factor = 1
#       line height stretch
y_amplitude = -300
center_line = c.create_line(0, center +1, width, center+1, fill='green')

coordinates = []
coord = []
for x in range(0, 600):
    # x coordinates
    coord.append((x * x_increment) * x_factor)

    # y coordinates
    y = particleCount((1.16*(10**-3)), (5*(10**6)), x)
    coord.append((y * y_amplitude) + center)

    coordinates.append(coord)
    coord = []


log_line = c.create_line(coordinates, fill='red')

root.mainloop()
bumsfeld 413 Nearly a Posting Virtuoso

It's probably easier to pull the data you need for plotting out of a list:

raw_data = """\
google.com {'facebook.com': 230, 'yahoo.com': 9, 'fifa.org': 67, 'msn.com': 3}
yahoo.com {'apps.facebook.com': 13, 'msn.com': 9, 'myp2p.eu': 2}"""

filename = "aadata.txt"
# save to test file
fout = open(filename, "w")
fout.write(raw_data)
fout.close()
# read the test file line by line and process
# save each line list in data_lines list
data_lines = []
for line in open(filename):
    line = line.rstrip()
    # remove the following characters
    line = line.replace('{', '')
    line = line.replace('}', '')
    line = line.replace(':', '')
    line = line.replace(',', '')
    line = line.replace('\'', '')
    
    #print line, type(line)  # test
    print line.split()
    
    data_lines.append(line.split())
    
'''my result -->
['google.com', 'facebook.com', '230', 'yahoo.com', '9', 'fifa.org', '67', 'msn.com', '3']
['yahoo.com', 'apps.facebook.com', '13', 'msn.com', '9', 'myp2p.eu', '2']
'''
bumsfeld 413 Nearly a Posting Virtuoso
bumsfeld 413 Nearly a Posting Virtuoso

You can also do string slicing:

s = 'hello'
print(s[:1])  # h

# more
print(s[:2])  # he
print(s[:4])  # hell
bumsfeld 413 Nearly a Posting Virtuoso

The only example I could find was this one ...

'''
Python31 includes the Tkinter Tile extension Ttk.
Ttk comes with 17 widgets, 11 of which already exist in Tkinter: 
Button, Checkbutton, Entry, Frame, Label, LabelFrame, Menubutton, 
PanedWindow, Radiobutton, Scale and Scrollbar 
The 6 new widget classes are: 
Combobox, Notebook, Progressbar, Separator, Sizegrip and Treeview
'''

import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

img1 = tk.PhotoImage("frameFocusBorder", data="""
R0lGODlhQABAAPcAAHx+fMTCxKSipOTi5JSSlNTS1LSytPTy9IyKjMzKzKyq
rOzq7JyanNza3Ly6vPz6/ISChMTGxKSmpOTm5JSWlNTW1LS2tPT29IyOjMzO
zKyurOzu7JyenNze3Ly+vPz+/OkAKOUA5IEAEnwAAACuQACUAAFBAAB+AFYd
QAC0AABBAAB+AIjMAuEEABINAAAAAHMgAQAAAAAAAAAAAKjSxOIEJBIIpQAA
sRgBMO4AAJAAAHwCAHAAAAUAAJEAAHwAAP+eEP8CZ/8Aif8AAG0BDAUAAJEA
AHwAAIXYAOfxAIESAHwAAABAMQAbMBZGMAAAIEggJQMAIAAAAAAAfqgaXESI
5BdBEgB+AGgALGEAABYAAAAAAACsNwAEAAAML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FCh1QH5jQIW3xugwSzD4QvIIH
4s/PUgiQYcCG4BkC5P/ObpaBhwreq18nb3Z79+8Dwo9nL9I8evjWsdOX6D59
fPH71Xeef/kFyB93/sln4EP2Ebjegg31B5+CEDLUIH4PVqiQhOABqKFCF6qn
34cHcfjffCQaFOJtGaZYkIkUuljQigXK+CKCE3po40A0trgjjDru+EGPI/6I
Y4co7kikkAMBmaSNSzL5gZNSDjkghkXaaGIBHjwpY4gThJeljFt2WSWYMQpZ
5pguUnClehS4tuMEDARQgH8FBMBBBExGwIGdAxywXAUBKHCZkAIoEEAFp33W
QGl47ZgBAwZEwKigE1SQgAUCUDCXiwtQIIAFCTQwgaCrZeCABAzIleIGHDD/
oIAHGUznmXABGMABT4xpmBYBHGgAKGq1ZbppThgAG8EEAW61KwYMSOBAApdy
pNp/BkhAAQLcEqCTt+ACJW645I5rLrgEeOsTBtwiQIEElRZg61sTNBBethSw
CwEA/Pbr778ABywwABBAgAAG7xpAq6mGUUTdAPZ6YIACsRKAAbvtZqzxxhxn
jDG3ybbKFHf36ZVYpuE5oIGhHMTqcqswvyxzzDS/HDMHEiiggQMLDxCZXh8k
BnEBCQTggAUGGKCB0ktr0PTTTEfttNRQT22ABR4EkEABDXgnGUEn31ZABglE
EEAAWaeN9tpqt832221HEEECW6M3wc+Hga3SBgtMODBABw00UEEBgxdO+OGG
J4744oZzXUEDHQxwN7F5G7QRdXxPoPkAnHfu+eeghw665n1vIKhJBQUEADs=""")

style = ttk.Style()

style.element_create("RoundedFrame", "image", "frameBorder",
    ("focus", "frameFocusBorder"), border=16, sticky="nsew")

style.layout("RoundedFrame", [("RoundedFrame", {"sticky": "nsew"})])
style.configure("TEntry", borderwidth=0)

frame = ttk.Frame(style="RoundedFrame", padding=10)
frame.pack(fill='x')

frame2 = ttk.Frame(style="RoundedFrame", padding=10)
frame2.pack(fill='both', expand=1)

entry = ttk.Entry(frame)
entry.pack(fill='x')
entry.bind("<FocusIn>", lambda evt: frame.state(["focus"]))
entry.bind("<FocusOut>", lambda evt: frame.state(["!focus"]))

text = tk.Text(frame2, borderwidth=0, bg="white", highlightthickness=0)
text.pack(fill='both', expand=1)
text.bind("<FocusIn>", lambda evt: frame2.state(["focus"]))
text.bind("<FocusOut>", lambda evt: frame2.state(["!focus"]))

root.mainloop()

Looks menacingly complex!

bumsfeld 413 Nearly a Posting Virtuoso

In Python3 input() will give you string. You can use eval(input()) to get numbers, but I would make sure that the string you are using with eval() does not contain any nasty commands.

bumsfeld 413 Nearly a Posting Virtuoso

Here you go:

# tested with Python 3.1.1

import fractions

a = 10
b = 25
cd = fractions.gcd(a, b)

sf = "the greatest common divisor of the integers %d and %d is %d"
print( sf % (a, b, cd) )

"""my result
the greatest common divisor of the integers 10 and 25 is 5
"""
bumsfeld 413 Nearly a Posting Virtuoso

So, what is the effort on your part?
See:
http://www.daniweb.com/forums/announcement114-2.html

bumsfeld 413 Nearly a Posting Virtuoso

You are using the Python shell.

>>> f = open ('myflie.txt', 'w')
>>> f.write ('12345')
5

The Python shell is for testing of short code ideas. Use the editor to write programs.

bumsfeld 413 Nearly a Posting Virtuoso

This is the way I installed PyQt on my Windows XP machine and it works fine.
For Python26 download (latest versions as of 4/3/2010):
python-2.6.5.msi
Windows installer from
http://www.python.org/download/releases/2.6.5/

PyQt-Py2.6-gpl-4.7.2-1.exe
Windows installer from
http://www.riverbankcomputing.co.uk/software/pyqt/download

This was my little test program:

# pqt_Slider_LCD.py
# create PyQt form with slider and LCD readout
# get changing slider values for potentially other uses

# for easier syntax import this way
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class MyForm(QWidget):
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setWindowTitle('show slider value')
        self.resize(250,150)

        self.lcd = QLCDNumber(self)
        # default slider values are 0 to 99
        self.slider = QSlider(Qt.Horizontal, self)

        # use vertical layout
        vbox = QVBoxLayout()
        vbox.addWidget(self.lcd)
        vbox.addWidget(self.slider)
        self.setLayout(vbox)

        # connects the slider to the lcd number in change_value()
        # and also allows access to the slider value as it changes
        self.connect(self.slider, SIGNAL('valueChanged(int)'),
            self.change_value)

    def change_value(self, event):
        """show the changing slider value in the LCD display"""
        val = self.slider.value()
        print(val, type(val))  # test
        # display value in the LCD widget
        self.lcd.display(val)


app = QApplication([])
mf = MyForm()
mf.show()
app.exec_()
bumsfeld 413 Nearly a Posting Virtuoso

Might have been incomplete uninstall.

bumsfeld 413 Nearly a Posting Virtuoso

Simply store the reference to the function in the variable. Here is example:

def one():
    print("hello from function one")

def two():
    print("hello from function two")

def three():
    print("hello from function three")

# stores the ref of function in variable
f1 = one
f2 = two
f3 = three
func_list = [f1, f2, f3]

for f in func_list:
    # show the function reference
    print(f)
    # call the function
    f()

"""my display -->
<function one at 0x01DFE150>
hello from function one
<function two at 0x01DFE198>
hello from function two
<function three at 0x01DFE108>
hello from function three
"""
bumsfeld 413 Nearly a Posting Virtuoso

If variables inside functions wouldn't be local, any code would be just loaded with hard to trace bugs!

bumsfeld 413 Nearly a Posting Virtuoso

Wow, I can't barely wait till
Python Coding Help Pt 3
cames around!

bumsfeld 413 Nearly a Posting Virtuoso

range(n+1) by default goes from zero to n in steps of one

bumsfeld 413 Nearly a Posting Virtuoso

Sorry, module graphics.py does not work with module PIL!
You can only use .gif image files.

bumsfeld 413 Nearly a Posting Virtuoso
d1 = {'a': 1, 'bc': 2, 'def': 3, 'gh': 4, 'ijkl': 5}

# make shallow copy of d and process the copy
d2 = d1.copy()
for key in d1.keys():
    if len(key) < 3:
        del d2[key]

print(d1)  # {'a': 1, 'ijkl': 5, 'gh': 4, 'def': 3, 'bc': 2}
print(d2)  # {'ijkl': 5, 'def': 3}
bumsfeld 413 Nearly a Posting Virtuoso

I use this little batch file to force IDLE to work with Python 3.1.1

REM batch file to force IDLE to run with Python 3.1
REM save as IDLE31.bat
C:\Python31\Pythonw.exe -u C:\Python31\Lib\idlelib\idle.pyw

For discussion on 32bit versus 64bit see:
http://www.daniweb.com/forums/thread267106.html

bumsfeld 413 Nearly a Posting Virtuoso

Really Pythonic (elegant) ...

mylist = [
'192.168.255.1 00:01:02',
'172.14.0.1 00:0f:01',
'172.14.0.2 00:0f:01',
'172.14.0.3 00:0f:01'
'172.14.0.4 01:ff:dd:34',
'192.168.255.3 00:dd:01:ff'
]

# your exclude substring
exclude = '172.14'
newlist = [item for item in mylist if not item.startswith(exclude)]
print(newlist)

"""output -->
['192.168.255.1 00:01:02', '192.168.255.3 00:dd:01:ff']
"""
bumsfeld 413 Nearly a Posting Virtuoso

Note that kg and pound are weight units of measurement.
Gallon and liter are volume units of measurement.
Don't mix them!

You can use this code:

kg = float(raw_input("Enter number of kg: "))
lb = kg * 2.205
print kg, "kg =", lb, "pounds"

Or you can use this code:

gallon = float(raw_input("Enter number of gallons: "))
liter = gallon * 3.785
print gallon, "gallons =", liter, "liters"

Or you can use a generic value:

value = float(raw_input("Enter a number: "))
lb = value * 2.205
print value, "kg =", lb, "pounds"
liter = value * 3.785
print value, "gallons =", liter, "liters"
bumsfeld 413 Nearly a Posting Virtuoso

You can use icons provided by wxPython:

# the start of one small text editor with toolbar and image icons
# image icons are from the wx.ArtProvider
# notice that the wx.TextCtrl() surface has already some advanced
# features: select text, right click to cut, copy and paste etc.
# Henri AB

import os
import wx

class MyEditor(wx.Frame):
    def __init__(self, title):
        wx.Frame.__init__(self, None, -1, title,
            size=(500, 300))
        self.control = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)

        # statusBar at the bottom of the window
        self.CreateStatusBar()
        self.SetStatusText(" Click on the icon")

        # ToolBar at the top of the window
        toolbar = wx.ToolBar(self, -1,
            style=wx.TB_HORIZONTAL|wx.NO_BORDER)
        toolbar.SetToolBitmapSize(size=(24,24))
        toolbar.AddSimpleTool(wx.ID_OPEN,
            self.getBMP(wx.ART_FILE_OPEN),
            "Load", " Load a text file")
        toolbar.AddSimpleTool(wx.ID_SAVE,
            self.getBMP(wx.ART_FILE_SAVE),
            "Save", " Save the text file")
        toolbar.AddSimpleTool(wx.ID_ABOUT,
            self.getBMP(wx.ART_INFORMATION),
            "About"," About message")
        toolbar.AddSeparator()
        toolbar.AddSimpleTool(wx.ID_EXIT, self.getBMP(wx.ART_QUIT),
            "Exit"," Exit the program")
        toolbar.Realize()
        self.SetToolBar(toolbar)

        # bind the various toolbar icon click events to some action
        self.Bind(wx.EVT_TOOL, self.onLoad, id=wx.ID_OPEN)
        self.Bind(wx.EVT_TOOL, self.onSave, id=wx.ID_SAVE)
        self.Bind(wx.EVT_TOOL, self.onAbout, id=wx.ID_ABOUT)
        self.Bind(wx.EVT_TOOL, self.onExit, id=wx.ID_EXIT)

    def getBMP(self, pic_id):
        """get the bitmap image from the wxPython art provider"""
        return wx.ArtProvider.GetBitmap(pic_id, wx.ART_TOOLBAR,
            wx.Size(24, 24))

    def onAbout(self, e):
        """the about box"""
        about = wx.MessageDialog( self, " Very simple text editor \n"
            " using the wxPython GUI toolkit", "About Simple Editor",
            wx.OK)
        about.ShowModal()
        about.Destroy()

    def onLoad(self, e):
        """open text file"""
        self.dirname = ''
        mask = "Text (.txt)|*.txt|All (.*)|*.*"
        dlg = wx.FileDialog(self, "Choose file to load",
            self.dirname, "", mask, wx.OPEN)
        if dlg.ShowModal() == wx.ID_OK:
            self.filename = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            f = open(os.path.join(self.dirname,self.filename),'r')
            self.control.SetValue(f.read())
            f.close()
        dlg.Destroy()

    def onSave(self, e):
        """Save text file"""
        self.dirname = ''
        mask …
bumsfeld 413 Nearly a Posting Virtuoso

And the error you are getting is?

bumsfeld 413 Nearly a Posting Virtuoso

People like to be popular, why not their password?

I use only popular words like racecar and spell them in reverse. :)

bumsfeld 413 Nearly a Posting Virtuoso

Interesting, I've never used 2D arrays in Python but I would have hacked it to be useable in 'C-like' manner:

class sphere():
    def __init__(self, x=0.0, y=0.0, z=0.0):
        self.x = x
        self.y = y
        self.z = z

    def __str__(self):
        return "Coords: %s %s %s"%(self.x,self.y,self.z)


n = 10
m = 10
myArray = []

for i in xrange(n):
    myArray.append(map(sphere, xrange(m)))
    for j in xrange(m):
        myArray[i][j] = sphere(float(i), float(j), 0.0)

print "i=2,j=3: %s"%myArray[2][3]
print "i=6,j=1: %s"%myArray[6][1]
print "i=4,j=9: %s"%myArray[4][9]

Would this be seen as unPythonic? Or is it bad for other reasons? Just curious...

You can create myarray[x][y][z], but you still have to associate with the sphere object, that is where the dictionary mapping comes in handy.

bumsfeld 413 Nearly a Posting Virtuoso

You can include coordinate z into your key tuple by simply expanding vegaseat's code:

# create a large number of spheres referencing them
# with a (x, y, z):sphere_object dictionary pair

import visual as vs

spheres = {}
for x in range (0, 100):
    for y in range (0, 100):
        z = 0
        spheres[(x, y, z)] = vs.sphere(pos=(x, y, z), radius=1)

# to select a particular sphere use
x = 45
y = 55
z = 0
spheres[(x, y, z)].color = vs.color.red
bumsfeld 413 Nearly a Posting Virtuoso

Your area formula for regular polygons should be:

area = ((length**2) * numSides)/(4 * (math.tan(math.pi/numSides)))

Your result will be square units of whatever units of measurement your sides are. You cannot get degrees for the area!

bumsfeld 413 Nearly a Posting Virtuoso

Be aware that Python25 and Python26 use different MS C compilers and so do the modules they use. The C code syntax has to match these compilers, as they are not compatible.

bumsfeld 413 Nearly a Posting Virtuoso

Try self.SetSizerAndFit(sizer)

bumsfeld 413 Nearly a Posting Virtuoso

Are you usng Python2 or Python3?
Are your positive numbers integers or floats?

bumsfeld 413 Nearly a Posting Virtuoso

Why so complicated?
Using a similar english dictionary file:

# mydict.txt has one English word per line
# about 74500 in total
mydict  = open("mydict.txt", "r").readlines()

print(mydict[:10])

"""my display of some words in mydict -->
['aardvark\n', 'aardvarks\n', 'aaron\n', 'abaci\n', ... ]
"""

# strip the trailing newline char
mydict = [w.rstrip() for w in mydict]

print(mydict[:10])

"""my display -->
['aardvark', 'aardvarks', 'aaron', 'abaci', ... ]
"""

# test one word
word = 'aaron'

if word in mydict:
    print("word found")  # word found
bumsfeld 413 Nearly a Posting Virtuoso

The reason you want to make something private to the class is to keep it from easily spilling out into external code. So pseudo-private will do one good job. Remember it's called private, not secret!

bumsfeld 413 Nearly a Posting Virtuoso

Also with Python3 you don't have to use
fahrenheit = (9.0 / 5.0) * celsius + 32
you can just use
fahrenheit = (9 / 5) * celsius + 32
since '/' is now floating point division and '//' is integer division.

bumsfeld 413 Nearly a Posting Virtuoso
# staticmethod() and classmethod()
# make it easier to call one class method

class ClassA(object):
    def test(this):
        print this
    test = staticmethod(test)

ClassA.test(4)  # 4

class ClassB(object):
    @classmethod
    def test(self, this):
        print this

ClassB.test(4)  # 4

See:
http://www.techexperiment.com/2008/08/21/creating-static-methods-in-python/

bumsfeld 413 Nearly a Posting Virtuoso

One of the solutions is pretty straight forward, with easy logic:

list1 = [[1,2,3],[4,5,6],[7,8,9],[10,11,12]]
list2 = [1,2,3,4,11]

list3 = []
# q1 is each sublist in list1
for q1 in list1:
    # q2 is each item in list2
    for q2 in list2:
        # do not append if sublist is already in list3
        if q2 in q1 and q1 not in list3:
            list3.append(q1)

print(list3)

"""my output -->
[[1, 2, 3], [4, 5, 6], [10, 11, 12]]
"""

There may be better solutions.
Sorry, woooee already had this solution!!

bumsfeld 413 Nearly a Posting Virtuoso

how to save in the memory of the phone with rms + python

Vary bad manners to hijack this thread for such question.

Start your own thread and give more info!

bumsfeld 413 Nearly a Posting Virtuoso

Similar to jice's code:

# simply ignore index zero
pos = ['  '] * 11
print( pos )

POS = 1

pos[POS] = '->'
print( pos )

"""my display -->
['  ', '  ', '  ', '  ', '  ', '  ', '  ', '  ', '  ', '  ', '  ']
['  ', '->', '  ', '  ', '  ', '  ', '  ', '  ', '  ', '  ', '  ']
"""
bumsfeld 413 Nearly a Posting Virtuoso

At least for some time, it would be very nice if people indicated which version of Python they are using.

bumsfeld 413 Nearly a Posting Virtuoso

If this is truly your text file, I feel sorry for you!

bumsfeld 413 Nearly a Posting Virtuoso

Extension .pyd is used for C compiled library files for Python.

bumsfeld 413 Nearly a Posting Virtuoso

Is there a way to use a similar method with images instead of pixels? I know about all of that, but I need to load multiple images into PIL and tile them in a square...

Is it possible?

Looks like Sneekula wasted his time on you then.
I assume you also know all about img.getdata(), then you can put it together with img.putpixel().