Forum: Python 1 Day Ago |
| Replies: 3 Views: 164 Something like this ...
from Tkinter import *
def exit():
# do cleanup code here
pass
root = Tk()
# respond to window title bar x click |
Forum: Python 2 Days Ago |
| Replies: 5 Views: 175 To approximate for instance the sine of x (x in radians) you can use the Taylor series expansion:
x - x**3/3! + x**5/5! - x**7/7! + ...
However, to get even a remotely accurate number the cutoff... |
Forum: Python 3 Days Ago |
| Replies: 5 Views: 162 Ouch!!!!!!!
A couple of hints ...
you still have to start with one function call from main
you need to pass your arguments to and from your functions
variable, function and class names are... |
Forum: Python 3 Days Ago |
| Replies: 15 Views: 361 For old stuff like that I recommend a careful study of the source of graphics.py you can get it from:
http://mcsp.wartburg.edu/zelle/python/graphics.py
Also study the elaborate documentation from:... |
Forum: Python 4 Days Ago |
| Replies: 6 Views: 233 Python relies on indentations for it's code blocks. Other computer languages use braces, begin, end and so on. So yes, if you want to code in Python, then poorly done indentations can be a real... |
Forum: Python 4 Days Ago |
| Replies: 9 Views: 314 To my knowledge the latest release version of PyQT is 4.6, so I doubt that any IDE will work on code completion for your super advanced version (4.9 ?). |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 285 According to your code fname is just the filename and b is the full pathname. Still, it will work with os.rename(fname, b).
My question was, what happens if someone enters a directory like this:... |
Forum: Python 5 Days Ago |
| Replies: 9 Views: 314 I tried the latest version of Eric (4.3.9). It assiste with PyQT syntax, but does not accept the newer connect style used with PyQT 4.5+. Somewhat irritating! |
Forum: Python 5 Days Ago |
| Replies: 10 Views: 285 I modified the program slightly for testing, but this work just fine ...
#!/usr/local/bin/python
import re, os
from os.path import join as pjoin, isdir
while True:
#targetfolder =... |
Forum: Python 6 Days Ago |
| Replies: 2 Views: 152 __str__() does operator overloading in a class and "hijacks" str() in any class instance operation that uses str(). So print crit1 will use it, because it uses str() to make it printable. Whereas... |
Forum: Python 6 Days Ago |
| Replies: 3 Views: 170 You are using old style Python code! Long ago it used to be like this ...
import string
a = "Why does string.split() not work?"
x = string.split(a)
print("SUCCESS!", x)
... now it's like this... |
Forum: Python 6 Days Ago |
| Replies: 10 Views: 330 You can use function exec() ...
# create variables num1, num2, num3 and num4 and set to 77
for n in range(1, 4):
exec( "%s = %d" % ('num' + str(n), 77) )
print(num1) # 77
print(num3) #... |
Forum: Python 6 Days Ago |
| Replies: 1 Views: 324 Take a look at the example at:
http://www.daniweb.com/forums/post1056184.html#post1056184 |
Forum: Python 7 Days Ago |
| Replies: 9 Views: 309 Will be less complex with a for loop and range(start, end, step) starting at the high value, ending at the low value (exclusive) and stepping -1 ...
n = 3
for x in range(n, 0, -1):
print... |
Forum: Python 7 Days Ago |
| Replies: 10 Views: 452 I assume the question is:
Who is foolish enough to do my homework for me? |
Forum: Python 7 Days Ago |
| Replies: 3 Views: 174 Also take a look at:
http://www.daniweb.com/forums/post1055261.html#post1055261
for a mildly more general version. |
Forum: Python 7 Days Ago |
| Replies: 10 Views: 340 You have to put your increase calculation in the loop. |
Forum: Python 8 Days Ago |
| Replies: 6 Views: 243 No need to be sorry, that kind of thing happens easily on any forum. |
Forum: Python 8 Days Ago |
| Replies: 6 Views: 243 When you use a.extend(b) or a.sort() then list a is changed, since both are inplace functions. Also when you pass a list to a function argument, be aware that the list is a mutable object and... |
Forum: Python 10 Days Ago |
| Replies: 3 Views: 246 If you make the regular polygon a square with side length = 1.0, you should get an area of 1.0. A simple test to see if the area formula is correct. |
Forum: Python 10 Days Ago |
| Replies: 4 Views: 210 You can play with this ...
# test Python command line arguments
import sys
if (len(sys.argv) >= 2):
# skip sys.argv[0]
commandline_args = sys.argv[1:]
print( commandline_args ) |
Forum: Python 10 Days Ago |
| Replies: 3 Views: 370 If you have a dictionary in your program and want to save and later reload it as a dictionary object, you have to use module pickle. Here is an example ...
# use module pickle to save/dump and load... |
Forum: Python 11 Days Ago |
| Replies: 5 Views: 252 A dictionary will serve you better ...
# create a large number of spheres referencing them
# with a (x, y):sphere_object dictionary pair
import visual as vs
spheres = {}
for x in range (0,... |
Forum: Python 12 Days Ago |
| Replies: 8 Views: 313 I assume your error is here ...
def print_list(names):
print 'Here are the names in the original order:'
for names in name_list: # <--------
print names
names.sort()
... |
Forum: Python 12 Days Ago |
| Replies: 9 Views: 293 Python3 will tolerate adding (object) to your class for a while at least.
After that just write a little Python utility that removes it. |
Forum: Python 12 Days Ago |
| Replies: 4 Views: 220 Here is the story:
In Python2 Tkinter is a Python module file named Tkinter.py a wrapper for the TCL code Tkinter is written in.
With the advent of Python3 Tkinter became a more modern package... |
Forum: Python 12 Days Ago |
| Replies: 6 Views: 280 If you want to start with the population after 1/2 year, then every year you have to change your code to this (Python2 or Python3) ...
def populationGrowth():
x = int(input("What is the current... |
Forum: Python 12 Days Ago |
| Replies: 5 Views: 225 In this case you have to create a new parent frame (size it for the image) for wx.StaticBitmap(frame, wx.ID_ANY, image)
Would be nice if I could test it out, but I simply don't have all the... |
Forum: Python 12 Days Ago |
| Replies: 5 Views: 225 Try something like this ...
#plt.show()
plt.savefig("test.png")
# create an internal image
image = wx.Bitmap("test.png")
# show the image as static... |
Forum: Python 13 Days Ago |
| Replies: 5 Views: 234 Why don't you just run the sample code I gave you with the image_file = "mars.jpg" and make sure you have the image file in the working directory or give it the full path.
Avoid the crap you added... |
Forum: Python 13 Days Ago |
| Replies: 5 Views: 253 First of all, do not call your function sum because there is already a built-in Python function sum() that will sum up the numbers in a numeric list. This also gives you the hint how to solve your... |
Forum: Python 13 Days Ago |
| Replies: 2 Views: 403 Use something like that ...
s = "My Title"
width = 70
s = s.center(width)
print( s ) |
Forum: Python 13 Days Ago |
| Replies: 5 Views: 232 os.path.exists(filename) will return True or False. |
Forum: Python 13 Days Ago |
| Replies: 5 Views: 234 Pygame can load quite a number of image formats. Here is an example ...
# experiments with module pygame
# free from: http://www.pygame.org/
# load and display an image using pygame
import... |
Forum: Python 13 Days Ago |
| Replies: 5 Views: 231 I trust that by now you have figured out that names in Python are case sensitive. |
Forum: Python 14 Days Ago |
| Replies: 9 Views: 293 Correct. Don't you admire the beauty of Python version changes? Right out of a Monty Python show!
Actually, most computer languages have had their fair share of version changes, they are always... |
Forum: Python 14 Days Ago |
| Replies: 5 Views: 232 There are certain characters a file name can not have, might depend on the OS. On Unix you have to have permission to write to some of the directories. |
Forum: Python 14 Days Ago |
| Replies: 9 Views: 293 The use of the new style class had a practical implication, it allowed the use of __slots__ as shown in this example ...
class Oldstyle:
def __init__(self):
self.a = 1
self.b... |
Forum: Python 16 Days Ago |
| Replies: 5 Views: 265 Another way to solve this is to use string function isdigit() ...
while True:
num = raw_input("Enter an integer: ")
if num.isdigit():
num = int(num)
break
print "Try... |
Forum: Python 16 Days Ago |
| Replies: 7 Views: 227 You need to test the logic in your if statements like
if mystr in accepted:
Here is a little test ...
accepted = '0123456789dr+-*/%^='
mystr = '2'
print(mystr in accepted) # True
mystr =... |