Forum: Python 10 Days Ago |
| Replies: 78 Views: 14,748 Here is modified (also added needed delay) and commented code from the pygame tutorial that shows how to load one image onto rectangle object and move the object:
# use pygame to bounce/move loaded... |
Forum: Python 10 Days Ago |
| Replies: 7 Views: 251 If you use m==0 it will give you False unless m is zero. |
Forum: Python 10 Days Ago |
| Replies: 5 Views: 248 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. |
Forum: Python 10 Days Ago |
| Replies: 5 Views: 248 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... |
Forum: Python 10 Days Ago |
| Replies: 3 Views: 246 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... |
Forum: Python 10 Days Ago |
| Replies: 2 Views: 215 Vegaseat left this ttk code somewhere showing you the way module ttk should be imported and applied:
# exploring the Tkinter expansion module ttk notebook
# tested with Python 3.1 and Tkinter 8.5 ... |
Forum: Python 11 Days Ago |
| Replies: 3 Views: 204 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. |
Forum: Python 11 Days Ago |
| Replies: 7 Views: 251 Looking at your code you have quite a nightmare of errors in there and on top of that the all important indentations are all screwed up.
!) use the customary 4 space indentations, avoid tabs!!!!
... |
Forum: Python 16 Days Ago |
| Replies: 2 Views: 188 Try self.SetSizerAndFit(sizer) |
Forum: Python 16 Days Ago |
| Replies: 5 Views: 265 Are you usng Python2 or Python3?
Are your positive numbers integers or floats? |
Forum: Python 16 Days Ago |
| Replies: 4 Views: 173 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])... |
Forum: Python 16 Days Ago |
| Replies: 11 Views: 457 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... |
Forum: Python Oct 20th, 2009 |
| Replies: 12 Views: 636 import os
# works on windows nt (also xp and vista) or linux
os.system(['clear','cls'][os.name == 'nt'])
If [os.name == 'nt'] is True then this becomes effectively 1. So it picks item at index 1... |
Forum: Python Oct 20th, 2009 |
| Replies: 9 Views: 302 Read vegaseat's comment:
You need to move all those lines to the right by 4 spaces. |
Forum: Python Oct 20th, 2009 |
| Replies: 3 Views: 398 You may not want to add letters to the list that have zero count. |
Forum: Python Oct 20th, 2009 |
| Replies: 7 Views: 268 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... |
Forum: Python Oct 20th, 2009 |
| Replies: 3 Views: 696 If you are curious, also check this out:
http://www.daniweb.com/code/snippet216539.html |
Forum: Python Oct 20th, 2009 |
| Replies: 9 Views: 302 Did you download the code or retype it manually yourself?
There are some errors due to indentations and typos.
The return outside function error is really indentation error! |
Forum: Python Oct 20th, 2009 |
| Replies: 4 Views: 3,105 Seems to me that you also have to consider the time that re.compile() needs. |
Forum: Python Oct 19th, 2009 |
| Replies: 5 Views: 384 Some corrections:
num = 0
mylist = []
while num < 10:
num = num + 1
mylist.append(num)
print(mylist) |
Forum: Python Oct 19th, 2009 |
| Replies: 4 Views: 229 Asking questions is never stupid! :) |
Forum: Python Oct 19th, 2009 |
| Replies: 3 Views: 181 This will also trap number exceeding the index:
import string
def numtolet(num):
if num > 25: return
return string.ascii_uppercase[num]
print( numtolet(0) ) # A
print( numtolet(5)... |
Forum: Python Oct 19th, 2009 |
| Replies: 6 Views: 296 # 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 |
Forum: Python Oct 19th, 2009 |
| Replies: 8 Views: 210 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:
... |
Forum: Python Oct 12th, 2009 |
| Replies: 5 Views: 404 As performance is concerned, the file read from disk will be the slowest part by far! |
Forum: Python Oct 12th, 2009 |
| Replies: 5 Views: 6,901 Do you mean highest frequency first?
Simply add this to the end of the code:
print '-'*30
print "sorted by highest frequency first:"
# create list of (val, key) tuple pairs
freq_list2 =... |
Forum: Python Oct 12th, 2009 |
| Replies: 3 Views: 376 You are close:
fname = raw_input("enter a text file name: ")
fread = open(fname, "r")
# read the whole file into one string
text = fread.read()
fread.close()
# split the whole text string... |
Forum: Python Oct 12th, 2009 |
| Replies: 22 Views: 180,163 Vary bad manners to hijack this thread for such question.
Start your own thread and give more info! |
Forum: Python Oct 12th, 2009 |
| Replies: 5 Views: 1,065 You are in the wrong forum. Many of us went away from low level C to high level Python to solve such problems easily. |
Forum: Python Oct 12th, 2009 |
| Replies: 5 Views: 1,646 However, pyHook and pythoncom work only on Windows systems. Not too bad, since most computers in this world are using Windows. Tkinter is more cross-platform for the few odd folks that user other... |
Forum: Python Oct 11th, 2009 |
| Replies: 7 Views: 295 Similar to jice's code:
# simply ignore index zero
pos = [' '] * 11
print( pos )
POS = 1
pos[POS] = '->'
print( pos ) |
Forum: Python Oct 5th, 2009 |
| Replies: 6 Views: 266 At least for some time, it would be very nice if people indicated which version of Python they are using. |
Forum: Python Oct 5th, 2009 |
| Replies: 13 Views: 495 If this is truly your text file, I feel sorry for you! |
Forum: Python Oct 5th, 2009 |
| Replies: 4 Views: 335 I think you need to develop mask of your image to make this work. |
Forum: Python Aug 27th, 2009 |
| Replies: 6 Views: 452 Extension .pyd is used for C compiled library files for Python. |
Forum: Python Aug 26th, 2009 |
| Replies: 5 Views: 371 What is more efficient?
1) import math
2) from math import *
3) from math import sin, cos |
Forum: Python Aug 25th, 2009 |
| Replies: 78 Views: 14,748 It's like putting single image on PyGame "liquid canvas" giving an eerie visual effect. Here is short code:
# PyGame liquid effect on single image
# just old PyGame example modified
# module... |
Forum: Python Aug 25th, 2009 |
| Replies: 2 Views: 226 If you are familiar with C++, Java would be the way to go. Python is simply too uncomplicated. |
Forum: Python Aug 25th, 2009 |
| Replies: 2 Views: 251 Since you are already used to C++ I would say use Java. |
Forum: Python Aug 24th, 2009 |
| Replies: 7 Views: 530 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(). |