lllllIllIlllI 178 Veteran Poster

Well what i would do is make a hell of a lot of buttons.. well only 32, then i would use a loop to make a list of all of them something like:

for f in range(64):
    buttons.append(wx.Button(self, wx.ID_ANY, label = str(f)))

That takes care of making the buttons. Then i would make sizers!

horsizers = []
mainsizer = wx.BoxSizer(wx.VERTICAL)
index = 0
for f in range(8):
    size = wx.BoxSizer()
    for g in range(8):
        size.Add(buttons[index], proportion = 0)
        index += 1
    horsizers.append(size)

for size in horsizers:
    mainsizer.Add(size, proportion = 0)

self.SetSizer(mainsizer)

That just gives a general outline of how to do this... im not actually sure if it works.

lllllIllIlllI 178 Veteran Poster

Well this is probably a really stupid question but i was doing pygame tutorial and i dont know what a vector is and they keep talking about them, there were special vector classes and things like that, im rather confused, so if someone could teach me what a vector is i would greatly appreciate that.

Cheers

lllllIllIlllI 178 Veteran Poster

Try printing out what the answer is meant to be and what you are getting through the raw_input() that will show what is wrong quite easily.

SoulMazer commented: Continued, fantastic support. S/he followed through well, also. +1
lllllIllIlllI 178 Veteran Poster

This should work.. i think the r was in the wrong place

def vocabtest():
    word  = words.keys()
    random.shuffle(word)
    for w in word:
        a = words[w]
        print "What word does the following definition correspond with?"
        print a
        answer = raw_input("> ")
        if w.lower() == answer.lower():
            print "Correct!"
        else:
            print "Fail"

Here's to hoping that works!

lllllIllIlllI 178 Veteran Poster

woops i see my mistake. Just replace the line

word = words.items()
##WITH
word = word.keys()

My mistake there.

lllllIllIlllI 178 Veteran Poster

Your problem is that you go random.shuffle(words.items())
You cant change words.items. It is a function. So what you have to do instead is make a list of the keys and then shuffle those

def vocabtest():
    word  = words.items()
    random.shuffle(word)
    for w in word:
        a = words[w]
        print "What word does the following definition correspond with?"
        print a
        answer = raw_input("> ")
        if words[answer] == r:
            print "Correct!"
        else:
            print "Fail"
lllllIllIlllI 178 Veteran Poster

Whats wrong, are you getting errors? Or do you just want to make it look cleaner?

Oh and for the spaces, try using something like
print ' '*whatever number,
print 'Craps'

lllllIllIlllI 178 Veteran Poster

Woops i stuffed up a bit, scuse me.
Here is the new code:

import random

d = {'1':1,'2':2}
keys= d.keys()
random.shuffle(keys)
for f in keys:
    print d[f], f
lllllIllIlllI 178 Veteran Poster

EDIT: Woops, accidentaly just posted basically the same as the above. Sorry

lllllIllIlllI 178 Veteran Poster

Here is an easy way!

import random
d = {}#put your dic here

for f in random.shuffle(d.keys()):
    print d[f], f

That shuffles the keys up and then you just access the values from the dictionary with the keys.

lllllIllIlllI 178 Veteran Poster

Try this:

All i did was put a random number at the start of main and when they guess the correct number

import random

def main():
    answer = 'y'
    number = random.randint(1, 1000)
    while answer == 'y' or answer == 'Y':
        
        print 'I have a number between 1 and 1000'
        print 'Can you guess the right number'
        print number 
        guess = input('Enter  your number')
        
        if number > guess:
            print "Too low.  Guess again"
            guess
        elif number < guess:
            print "Too high.  Guess again"
            guess
        elif number == guess:
            print 'You won!!!'
            number = random.randint(1, 1000)
            answer = raw_input("Do you want to play again? (Enter y for yes): ") 
main()
lllllIllIlllI 178 Veteran Poster

The print statement in python (except python 3) automatically adds a newline at the end.

Wait, i think that in python 3 there is an automatic \n at the end of lines. Here are the default args for print()

print - sep = ' ', end = '\n', file = sys.stdout

So that seems to point towards print actually adding a new line to the end.

Also if you do not want this then just go

print ("Hello there", end = '')
lllllIllIlllI 178 Veteran Poster

Sorry i didnt test it as i do not have the files. Try this:

import os


fileNames = []

for f in os.listdir(os.getcwd()):
    if f.startswith('pcp'):
        fileNames.append(f)
        
ofh = open("pre5.txt", "w")
lines = []
for fileName in fileNames:
    f = open(fileName)
    #do what you need to.

    for line in f.readlines():
        if not line.startswith('Year'):
            lines.append(line)


#Doing the years
s = 'Year        '
for f in range(int(lines[0].split()[0]),
               len(lines)+int(lines[0].split()[0])):
    s += "      "+str(f)

ofh.write(s+'\n')

#the month collumn
s = 'Month        '
for f in lines:
    s += '      '+f.split()[1]

ofh.write(s+'\n')

#date
s = "Date       "
for f in lines:
    s += '      '+f.split()[2]

ofh.write(s+'\n')

#value
s = "Value        "
for f in lines:
    s += '        '+f.split()[3]

ofh.write(s+'\n')





        
ofh.close()
f.close()
lllllIllIlllI 178 Veteran Poster

Yet on that note, if you want to import something it is usually a lot better to have a main() function as then you can go:

if __name__ == '__main__':
    main()

And i find that a lot more readable then

if __name__ == '__main__':
    #every part of main would go here

I guess its just general preference, what works for you?

lllllIllIlllI 178 Veteran Poster

Well i did a bit of fiddling and came up with this, its not the most efficient code ever by a long shot but i think it should help:

import os


fileNames = []

for f in os.listdir(os.getcwd()):
    if f.startswith('pcp'):
        fileNames.append(f)
        
ofh = open("pre5.txt", "w")

for fileName in fileNames:
    f = open(fileName)
    #do what you need to.

    for line in f.readlines():
        if not line.startswith('Year'):
            lines.append(line)


#Doing the years
s = 'Year        '
for f in range(int(lines[0].split()[0]),
               len(lines)+int(lines[0].split()[0])):
    s += "      "+str(f)

ofh.write(s+'\n')

#the month collumn
s = 'Month        '
for f in lines:
    s += '      '+f.split()[1]

ofh.write(s+'\n')

#date
s = "Date       "
for f in lines:
    s += '      '+f.split()[2]

ofh.write(s+'\n')

#value
s = "Value        "
for f in lines:
    s += '        '+f.split()[3]

ofh.write(s+'\n')





        
ofh.close()
f.close()
lllllIllIlllI 178 Veteran Poster

Okay here is a version with a lot of things fixed:

def main():
    books = getBooks()  #Remember those () otherwise the functions are not called
    points = getPoints(books) #again
    printPoints(books, points)

def getBooks():
    books = input("enter the books purchased")
    return books

def getPoints(books):
    if books <= 0:
        points = 0
    elif books <= 1:
        points = 5
    elif books <= 2:
        points = 15
    elif books <= 3:
        points = 30
    elif books <= 4:
        points =60
    return points

def printPoints(books,points):
    print ("you bought" ,books, "you now have ",points) #Remeber to split up the string


main()
lllllIllIlllI 178 Veteran Poster

Here we go:

def main():
    books = getBooks
    points = getPoints
    printPoints

def getBooks():
    books = input("enter the books purchased")
    return books

def getPoints(books):
    if books <= 0:
        points = 0
    elif books <= 1:
        points = 5
    elif books <= 2:
        points = 15
    elif books <= 3:
        points = 30
    elif books <= 4:
        points =60
    return points

def printPoints(books,points):
    print ("you bought ,books, you now have ,points,")


main()
lllllIllIlllI 178 Veteran Poster

This code will let you open ALL files that start with pcp and then have a for loop that lets you do whatever you want with the files.

import os

fileNames = []

for f in os.listdir(os.getcwd()):
    if f.startswith('pcp'):
        filesNames.append(f)

for fileName in fileNames:
    f = open(fileName)
    #do what you need to.

Hope thats handy!

lllllIllIlllI 178 Veteran Poster

This post is over a year old. Just let it die.

lllllIllIlllI 178 Veteran Poster

For that you could also go:

notList = ["list vars here"]
if False not in [not var for var in notList]:
   #do stuff
lllllIllIlllI 178 Veteran Poster

Ah well im sure he will come to teach you them, everything you need can be done without functions without a fuss though so dont worry.

lllllIllIlllI 178 Veteran Poster

Functions are vital to programming, be sure to learn them. Here is a page on them:
http://www.penzilla.net/tutorials/python/functions/

lllllIllIlllI 178 Veteran Poster

Oh and for the other prob:

test= open("README.txt", "r").readlines()
#that makes a list
test = open("README.txt").read() 
#that makes a string
#now we can do test.lower() with the open("README.txt").read()
print test.lower() #DADA!
lllllIllIlllI 178 Veteran Poster

Just a tip, but for trailing '\n' characters in files, you can just use line.strip() function:

f = open('file.txt')
l = []
for line in file:
    l.append(line.strip())

Hope that helps you out later.

lllllIllIlllI 178 Veteran Poster

Ah ha! Thats perfect. A few examples would be absolutley lovely.

lllllIllIlllI 178 Veteran Poster

Well i would take a look at wx.ButtonPanel, it does the things you want, it can act like an awesome toolbar as well as having an image/gradient as the background. I would love to attach some code as an example but my computer has decided it really dosent want to co-operate right now.

But have a look at the wxPython demo. That shows it with a gradient, its soposedly not that hard to change that to a bmp.

lllllIllIlllI 178 Veteran Poster

Can you explain what is wrong with the speed of the car? It seems fine to me.

lllllIllIlllI 178 Veteran Poster

To make a number go up by one you either go:

i += 1

OR

i = i+1
lllllIllIlllI 178 Veteran Poster

Well using pickle is quite easy in some respects. Its a great tool. Here is an example of code using it:

#This saves a copy of the class Player.
import pickle

class Player():
    def __init__(self):
        self.last_location = (0,0)

    def setLocation(self,pos):
        self.last_location = pos



    #and so on

p = Player()
p.setLocation((10,10))

f = open("pickles.txt",'w')
pk = pickle.Pickler(f)

pk.dump(p)


f.close()
# and this re-loads it!
import pickle


class Player():
    def __init__(self):
        self.last_location = (0,0)

    def setLocation(self,pos):
        self.last_location = pos
        
        
f = open("pickles.txt")

pk = pickle.Unpickler(f)
p = pk.load()

print p.last_location #look it gets it right!

Hope that helps you out.

lllllIllIlllI 178 Veteran Poster

Well first,
what have you done so far?
How good are you at programming?
Do you want the backup to be in a zip file or anything special like that?
Is there any other information we would need to know about?

Adding information really helps questions get answered.

lllllIllIlllI 178 Veteran Poster

Oh yeah that worked a charm, i just realised my problem.. Thanks.

lllllIllIlllI 178 Veteran Poster

I rekon you could do something simillar in python, of course it would take a lot of time and care but to do such a thing you need a GUI as you said and there are really only 3 main ones used (4 if you count qt).
That is
Tkinter
wxPython
pyGame

Firstly i don't think pyGame does the job, as the name states its for games.

Tkinter is pretty basic and no fun to work with in my opinion and in the end i pretty much do most things in wxPython as it is easy and great looking with lots of widgets that you can use to make things look even better.

So i think yes, you can do it, and i would do it in wxPython if i were you.

lllllIllIlllI 178 Veteran Poster

Hey i was wondering if there was any way to convert a 24 bit Bitmap into a 256 colour bitmap using PIL or something simillar. I found something like:

image = image.convert("P",color = Image.ADAPTIVE)

But i couldn't work out how to make that work.
So yeah any way that you know would be lovely.

Cheers

lllllIllIlllI 178 Veteran Poster

I was interested in the program though and i made my own that tests a more real life scenario as in that it uses random numbers

import random
	
def getRoll():
    return [random.randrange(1,7) for f in range(4)]

def win(l):
    s = sum(l)
    if s < 12:
        return True
    else:
        return False
    
def main(times):
    money = 1000
    for f in range(times):
        money -=2
        if win(getRoll()):
            money += 12
    print "You ended up with %s dollars after %s turns" %(money, times)
        
if __name__ == "__main__":
    times = int(raw_input("How many times would you like the test to be run?"))
    main(times)

This would output something like this

How many times would you like the test to be run?100000
You ended up with 89072 dollars after 100000 turns

After running it through a number of times i have found that i always seem to win, so if this game was real i think i would play!

lllllIllIlllI 178 Veteran Poster

Well using python 2.5 it runs without a hitch.

lllllIllIlllI 178 Veteran Poster

Hi
For one of my programs i want to be able to graph the performance of things in a graph. The thing is that this graph constantly made a little bit longer with every second that passes. So i was wondering what paintDC to use. And how to use it. Because i have looked at PaintDC, clientDC and BufferedDC but i cant work out how to make it so they remember what they have painted on them and only add the stuff i want to append on.

Cheers
Paul

lllllIllIlllI 178 Veteran Poster

Personally i understand the big deal. Its about WHY they are expensive. What is it about calling a function that makes it harder on the program and if you want to make a super amazingly quick program and it had to be in python then maybe this could even matter (i doubt it) but still it is an interesting topic i think.

lllllIllIlllI 178 Veteran Poster

If you are wanting video as well then you can use GUI toolkits such as wxPython. This has a wx.MediaCtrl that does the kind of thing you are talking about.

lllllIllIlllI 178 Veteran Poster

EDIT: Sorry wrong page i posted on.. missed where we were up to.

lllllIllIlllI 178 Veteran Poster

You cant go () after a string. i think you mean to use the [] signs. These allow you to select certain parts of a string so you would have:

b.write('yesplease'+l[0]+'\n')
lllllIllIlllI 178 Veteran Poster

From what i can see your code is not indented properly, so that could be because you are not using code tags when posting which means that indentation is normally lost.

CODE HERE

tags (without the space after the end one)
They mean that it is a lot easier to tell what is wrong.

lllllIllIlllI 178 Veteran Poster

I know this may not help.. but when i move something around i just move the rect that it has. So

rect = rect.move((newpos))

im not that good at pygame so im not positive that that will help, but anyway.

lllllIllIlllI 178 Veteran Poster

add

global p1move1
global p2move1

to the start of your program, that may help.

lllllIllIlllI 178 Veteran Poster

This one looks okay.
http://effbot.org/librarybook/urllib.htm
Short and sweet

lllllIllIlllI 178 Veteran Poster

1. http://www.zopelabs.com/cookbook/991178206, thats a tutorial/code snippet
2. i use wxPython, that is great and easy to use once you get used to it... http://zetcode.com/wxpython/
3. For this i use os.walk and look for filenames that are simillar to my query
4.mySQL is popular SQL Lite is packaged with python
5.THis is easily done in wxPython, use the wx.TextCtrl if it is just text, if you want a more powerful one, then use wx.richtext.RichTextCtrl
6.Depends, if you just want infomation such as the source code use urllib or urllib2

lllllIllIlllI 178 Veteran Poster

Im thinking that you might be stuck, they would only have a few letter codes if they only supported a few. I couldn't find a way around it.

And for the system question, i generally use startfile but i think its much of a muchness as to which is faster. I think there is a way to time the functions... search "timing" in this forum. That might get you a way to do it.

lllllIllIlllI 178 Veteran Poster

Just a though, but couldn't you make it a pyw file? That way there would be no python.exe window and the program wouldnt have to constantly minimise itself over and over. I dont know if i understand the problem correctly, if so then never mind me :P

lllllIllIlllI 178 Veteran Poster

Well im voting for the scanner. Thats how i learnt and thats how i go, i dont find anything wrong with it so i stay that way.. addmitedly i really dont know a thing about Buffered Reader anyway, so it could be loads better for all i know.

lllllIllIlllI 178 Veteran Poster

Please do not double post, the thread is already in the forum and only a couple of posts down, if someone knows then they can help you on the issue.

lllllIllIlllI 178 Veteran Poster

Never mind, i have found a solution in one of my old code snippets. I used the toolbar.SetToolBitmapSize((64,64)) to fix this issue and now all things are working perfectly!