lllllIllIlllI 178 Veteran Poster

This will do the adding of the default value:

self.inputTxtThree = self.textbox('Starting at what hour? 6? 24 hr clock-\n or immediate start just accept 99.','99', bmp)



def textbox(self, label_str, default_value= "99", bmp = None):
		if bmp:
			bitmap = wx.StaticBitmap(self.panel, wx.ID_ANY, bmp)
			
		#label = wx.StaticText(self.panel,wx.ID_ANY, label_str,style=wx.TE_MULTILINE)
		label = wx.StaticText(self.panel,wx.ID_ANY, label_str)
		tbox = wx.TextCtrl(self.panel, wx.ID_ANY,size=(55, -1))
                tbox.SetValue(default_value)
		input_sizer   = wx.BoxSizer(wx.HORIZONTAL)
		input_sizer.Add((20,20), proportion=-1)  # this is a spacer
		if bmp:
			input_sizer.Add(bitmap, 0, wx.ALL, 5)
		input_sizer.Add(label, 0, wx.ALL|wx.ALIGN_RIGHT, 0,wx.TE_DONTWRAP)
		#self.gridSizer.Add(input_sizer, 1, wx.ALIGN_RIGHT, wx.TE_DONTWRAP)
		self.gridSizer.Add(input_sizer, 1, wx.ALIGN_RIGHT, wx.TE_DONTWRAP)

		self.gridSizer.Add(tbox, 0)
		return tbox
lllllIllIlllI 178 Veteran Poster

Here is an example of how one works:

import  wx
import  wx.lib.scrolledpanel as scrolled

class TestPanel(scrolled.ScrolledPanel):
    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent, -1)

        vbox = wx.BoxSizer(wx.VERTICAL)
        desc = wx.StaticText(self, -1,
                            "ScrolledPanel extends wx.ScrolledWindow, adding all "
                            "the necessary bits to set up scroll handling for you.\n\n"
                            "Here are three fixed size examples of its use. The "
                            "demo panel for this sample is also using it -- the \nwxStaticLine "
                            "below is intentionally made too long so a scrollbar will be "
                            "activated."
                            )
        desc.SetForegroundColour("Blue")
        vbox.Add(desc, 0, wx.ALIGN_LEFT|wx.ALL, 5)

      

        self.SetSizer(vbox)
        self.SetAutoLayout(1)
        self.SetupScrolling()


app = wx.App(0)
frame = wx.Frame(None, wx.ID_ANY)
fa = TestPanel(frame)
frame.Show()
app.MainLoop()

Hope that helps you out!:)

lllllIllIlllI 178 Veteran Poster

if you are using wx then just go:

text.SetValue("Default Value Here")

Where text is your wx.TextCtrl

lllllIllIlllI 178 Veteran Poster

Dont worry, this can be lots easier. First we can find the minimun of a list by using the min function, the max by using the max function!

So :

li = [1,2,3,4,5,6,7,8,9,1,11,5,0,64]
print min(li) #0
print max(li) #64
print li.index(max(li))  #position 13
print li.index(min(li))   #position 12

To get the numbers you can use a loop like this:

li = []
value = '-1'
while value != '':
    li.append(int(raw_input("Enter a number please, just press enter to stop")))

Then for the average you just need another loop, this time a for loop:

sum = 0
for item in list:
    sum += item
print "average is:", (sum*1.0)/;en(li)

That should help you out, just try piece it together for what you need to do.

lllllIllIlllI 178 Veteran Poster

There certainly is a way!

import os

path = "path here"
seconds = os.path.getmtime(path)
print time.strftime('%Y-%m-%d %H:%M', time.localtime(seconds)
#it will output the time last modified!
lllllIllIlllI 178 Veteran Poster

Just press space 4 times, then you have it indented the right amount. Do this for all of them, not the actual if statement but the stuff afterwards.
So

>>>if stuff == True:
...     print "stuff" #i pressed space 4 times
... else:
...     print 'no'
lllllIllIlllI 178 Veteran Poster

Okay, i see you are using wing IDE, well in that case go to stack and go to the Call Stack, Click on them one by one and at one of them you will get something do with the actual problem, not just the function that called the problem.

So tht way you will be able to give greater detail as to whats going on.

lllllIllIlllI 178 Veteran Poster

I would say to replace this:

if delete=="yes":
                del records[entry]["Title"]
                del records[entry]["Director"]
                del records[entry]["Year"]
                del entry

With this

if delete=="yes":
                del records[entry]
                del entry

That will remove it from the records *completley* so you shouldnt have it still looking for it when it comes to re-print all the records.

Hope that helps.

lllllIllIlllI 178 Veteran Poster

Well can you post the whole error because that usually also shows what line it is on, it makes it easy to debug. But ill give you an example of something that would get that error:

f = open("infile.txt")
f()            #here i would get my error. The file variable is not callable
f.close()
lllllIllIlllI 178 Veteran Poster

What you are doing is trying to delete a string. that is impossible, you can delete a variable, here is an example:

del "hello" #will not work
h = "hello"
del h   #works
h = [1,2,3,4,5]
del h  #works

h = {"1":1,"2":2}
del h #also works

del 1   #will not work

So for your code:

if delete=="yes":
    
    del records[entry]["Title"]
    del records[entry]["Director"]
    del entry

That will now delete those records from the dictionary records and also the variable entry.

Hope that works better

lllllIllIlllI 178 Veteran Poster

I think i solved this problem once by just going str(stringvar) . Im not quite sure if it definitley works.. it might have been something else.

lllllIllIlllI 178 Veteran Poster

A statement in python is something that is already set as what is does, if is a statement, break is another, print is a statement.

An expression is something that evaluates to something. Such as adding numbers or strings together evaluates to something.

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

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

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

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

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

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

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

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

i += 1

OR

i = i+1
lllllIllIlllI 178 Veteran Poster

Well using python 2.5 it runs without a hitch.

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

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

You could easily make a class called Book and have a list of that. It could go:

class Book(object):
    def __init__(self):
        self.Title = name
        self.Author = author
        self.ISBN = ISBN

    def getAuthor(self,author):
        if author == self.Author:
            return self
            #you could have other such methods for ISBN and Title

books = []
b1 = Book("Marlie and Me","John Grogan",1234)
b2 = Book("The Northern Lights", "Phillip Pullman",4321)

for f in books:
    if f.getAuthor("Phillip Pullman"):
        print f.Title

I think that works.. i haven't put it into IDLE or anything, but generally classes are a very good way to go.

lllllIllIlllI 178 Veteran Poster

There is no problem with python. What it does is that it prints the first two, tries to add to the i.third and finds it cant. Then it goes to the except: statement and that prints out, in exception

Oh and to get the reason i think it is;

except Exception,e:
    print e
lllllIllIlllI 178 Veteran Poster

When using a richTextCtrl on a Panel often comes up with problems such as when you press Enter\Return to make a new line nothing happens. Here is an example to show people who have no idea what problem i am taking about. Try using this code and then making a new line. It will not work.

iimport wx
import wx.richtext as rc

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, size = (120,140))
        self.panel = wx.Panel(self)   #Notice you cant press enter and get a new line?
        
        self.rich = rc.RichTextCtrl(self.panel, size = (100,100))
        self.Show()
        
        
app = wx.App(0)
frame = MainFrame()
app.MainLoop()

But to fix it! Just add a style of 0 to the panel!

import wx
import wx.richtext as rc

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, size = (120,140))
        self.panel = wx.Panel(self, style = 0)   #Yay it works
        
        self.rich = rc.RichTextCtrl(self.panel, size = (100,100))
        self.Show()
        
        
app = wx.App(0)
frame = MainFrame()
app.MainLoop()

Hope that helps anyone that had that problem, i know it stumped me for hours!

lllllIllIlllI 178 Veteran Poster

For readability please wrap your code in

#your code here

it makes it a lot easier to read

Can you give us more details of the error, such as what line it was and stuff like that. See that error means your doing something like this:

s = "hello world"
s()
#error made, string object is not callable, so you cant try and call a function with it.
lllllIllIlllI 178 Veteran Poster

Ah wait, update! I found whats wrong. The colour that is green in this is not perfect green just like mk said, but its quite a way off. The green in your image is (0,128,0). That would explain why your program is not getting it.

lllllIllIlllI 178 Veteran Poster

I know that to get a list of all the pixels in the image i used image.getdata. This gave me an object and i could iterate over it, so i could go:

import Image
i = Image.open('stuff.bmp')

for pixel in i.getdata():
    print pixel

Hope that helps

lllllIllIlllI 178 Veteran Poster

Q6 - __name__ is as it says the name of the program, when you run the program that program is given the name '__main__' as it is the main program, but other things that you import are given different names, so the reason people do this is so that if you ever want to import that program into another that the original program dosent run.

Q7 - The for keyword is used to iterate through values, so if myvalues was a list then a loop would begin where the variable item would start off being the first value of myvalues then the loop would run through, then the next value of myvalues would replace the current value of item with its own.
So for example you know a range() makes a range of numbers fror a-b. SO

for num in range(1,11):
    print(num, end = "")
#it would print
#12345678910

So did you see that it ran the loop for every value in the range? cause thats what it does.

Oh delimiter is just a string, so you can have a list lets say like this:

ourList = ["hello", "World", "Its","a","nice","day]
#and then we can go
print(''.join(ourList)
#that will join every item in the list my adding them all together with nothing in the middle 
#HelloWorlditsaniceday
#we can use a string variable to
delimiter = '-'
print(delimiter.join(ourList))
#this will print
#Hello-World-its-a-nice-day

!= means does not equal, so if so and so does not equal minue one …

lllllIllIlllI 178 Veteran Poster
lllllIllIlllI 178 Veteran Poster

Q1 - Whatever you put in the inputs brackets are made into the prompt given to the user when it asks for the input.

Q2 - For a while loop, the loop goes while the value given is true, so run is equal to True so therefore it will run UNTIL the value of run is changed to False

Q3 - Continue, that keyword is used in loops, what is does is skip the rest of the loop and start on the next iteration.

Q4 - x is a global and local variable, it is in the global scope as well as in the function, you supply the value x so in the function is starts as x being 50 but then you change it to x, but that dosent change the value of x outside the function.

Q5 - In the last one it had x in the arguments needed for the function, but then in the next one you dont need to supply x because you make it global with the global x thing, now x in the function is the SAME x as x in the rest of the program.

Hope that helps