Forum: Python 5 Days Ago |
| Replies: 10 Views: 297 Congratulations ! Can you mark the thread as solved ? |
Forum: Python 6 Days Ago |
| Replies: 10 Views: 297 Perhaps your problem comes from the fact that you are trying to access an attribute. You should try to define an accessor method
class RFAMessageWrapper {
...
??? getService(){
... |
Forum: Python 6 Days Ago |
| Replies: 10 Views: 297 You didn't understand my design above. It's not a singleton, the variable is only used temporarily when wrapping an object (by the way, I should have used RFAMessageWrapper instead of RFAMessage).
... |
Forum: Python 7 Days Ago |
| Replies: 10 Views: 297 I don't know the solution, but I once designed a hack which you should try: You declare a static variable somewhere and an accessor function without arguments for this variable like this
... |
Forum: Python 7 Days Ago |
| Replies: 10 Views: 297 Im not sure, but I think you should wrap msg2 into a new python object yourself with SWIG_NewPointerObj. You can put only python objects in a call to a python function. Try to google for use examples... |
Forum: Python 12 Days Ago |
| Replies: 10 Views: 316 You should not write except: clauses without targeting a specific exeption. For example if you're reading user input and you're expecting a number and the user types "hello", then float("hello") will... |
Forum: Python 14 Days Ago |
| Replies: 3 Views: 219 Note that since you're only copying the file, you should consider using shutil.copy like this
import shutil
maxValue = 20
for i in range( 1, maxValue + 1 ):
shutil.copy("filename.txt",... |
Forum: Python 14 Days Ago |
| Replies: 6 Views: 213 It's also in the python documentation (http://docs.python.org/reference/datamodel.html#emulating-container-types) :) |
Forum: Python 14 Days Ago |
| Replies: 6 Views: 213 Well, super has been around for some time now, but it's not very useful. Better call the parent class directly. |
Forum: Python 14 Days Ago |
| Replies: 3 Views: 219 You don't even need the readlines(). You can iterate on the file object directly. On the other hand, after the file has been read, the file position is at the end of the file, so you must use seek... |
Forum: Python 14 Days Ago |
| Replies: 6 Views: 213 You must overwrite the __setitem__ method
class mydict(dict):
def __setitem__(self, key, value):
doStuff()
return dict.__setitem__(self, key, value) |
Forum: Python 16 Days Ago |
| Replies: 7 Views: 352 There is nothing very clever here. You must learn to think about algorithms. You want to output a series of blocks of lines; each block is indexed by the the number k in file<k>.tcl. So the structure... |
Forum: Python 16 Days Ago |
| Replies: 3 Views: 366 You should also read the documentation of the standard lib module atexit which gives example of how you can register functions to be executed at program termination. |
Forum: Python 17 Days Ago |
| Replies: 5 Views: 294 You can speed this up:
def sine(x):
term = float(x)
result = term # avoid 'sum' which is the name of a builtin function
u = - term * term # this is minus (x squared)
n = 0 #... |
Forum: Python 18 Days Ago |
| Replies: 3 Views: 308 I have a small collection of receipes found on the web a long time ago. See if one of them can help you
# linux, mac
os.kill(pid, signal.SIGKILL)
killedpid, stat = os.waitpid(pid, os.WNOHANG)... |
Forum: Python 18 Days Ago |
| Replies: 4 Views: 274 You probably still have the wrong indentation for the line
status = staticmethod(status). |
Forum: Python 18 Days Ago |
| Replies: 4 Views: 274 The indentation is bad. The code should read
# Classy Critter
# Demonstrates class attributes and static methods
class Critter(object):
"""A virtual pet"""
total = 0 |
Forum: Python 19 Days Ago |
| Replies: 3 Views: 353 I don't know ubuntu very well, but if your launcher is related to a bash script, the script must be somewhere in the filesystem, so locate the script and call os.system(path_to_script) or... |
Forum: Python 20 Days Ago |
| Replies: 14 Views: 626 The standard pattern in python is that when you want different copies of similar things, you don't use modules but class instances. I think your agents should aggregate objects having the desired... |
Forum: Python 22 Days Ago |
| Replies: 5 Views: 297 I modified your code so that it prints the file name and the destination name instead of renaming the file. Run it and modifiy it until it gives the correct values, then uncomment the 'rename' line.... |
Forum: Python 22 Days Ago |
| Replies: 2 Views: 211 theIndex[124] is a list, so you can just write
theIndex[124].append("m") |
Forum: Python 25 Days Ago |
| Replies: 7 Views: 7,245 You can write
from os.path import join as pjoin
targetfolder = raw_input('enter a target folder:\n').strip()
newname = raw_input('enter a new base name:\n')
newname = pjoin(targetfolder,... |
Forum: Python 25 Days Ago |
| Replies: 8 Views: 309 First, if it's crashing your program, there must be an exception traceback.
Also why don't you simply create a normal class and a single instance of the class ? |
Forum: Python 28 Days Ago |
| Replies: 5 Views: 373 Google found a patch for scapy.all..sniff, wich allows to stop the sniff function programmatically. You should try this http://trac.secdev.org/scapy/wiki/PatchSelectStopperTimeout |
Forum: Python 29 Days Ago |
| Replies: 6 Views: 309 You can write
if colour in ("Green", "Blue", "Red"):
... # do something
else:
... # do something else |
Forum: Python 30 Days Ago |
| Replies: 9 Views: 331 Note that in python 3, there are no 'old style class', so that your class is implicitely a subclass of object. Here is a small experiment with python 2.6 and python 3.1
Python 2.6.4 (r264:75706,... |
Forum: Python 30 Days Ago |
| Replies: 6 Views: 382 This may work
SP.Popen("c:\\program files\\webteh\\bsplayerpro\\bsplayer.exe d:\\rodin\\rodin.mp4 -stime"+str(d), shell=True) |
Forum: Python 30 Days Ago |
| Replies: 6 Views: 382 The str(d) in the argument doesn't work. I suggest that you use the subprocess module
import subprocess as SP
SP.Popen(["c:\\program files\\webteh\\bsplayerpro\\bsplayer.exe", "-stime="+str(d),... |
Forum: Python 31 Days Ago |
| Replies: 14 Views: 626 Is this what you mean ?
class Agent:
def __init__(self):
exec "import random" in self.__dict__
ag = Agent()
print ag.random.randrange(100) # this works |
Forum: Python 31 Days Ago |
| Replies: 3 Views: 240 You can make a list with your functions
import random
funcs = [func0, func1,func2,func3,func4,func5,func6,func7,func8,func9,]
funcs[random.randrange(10)]() # <- call a random function... |
Forum: Python 32 Days Ago |
| Replies: 11 Views: 526 The author of the article meant that the "property" function replaces getters and setters. In fact python's "property" encapsulates the attribute, and also encapsulates getters and setters ! |
Forum: Python 32 Days Ago |
| Replies: 6 Views: 309 You can add a loop in eyePicker until the user enters a valid colour:
from graphics import *
eye_colours = set("""green brown blue""".strip().split())
def drawCircle(win, centre, radius,... |
Forum: Python 32 Days Ago |
| Replies: 6 Views: 309 I modified your code to give you a first running version
from graphics import *
def drawCircle(win, centre, radius, colour):
circle = Circle(centre, radius)
circle.setFill(colour)
... |
Forum: Python Nov 9th, 2009 |
| Replies: 7 Views: 300 Yes, you should have written 'and' istead of 'or'. |
Forum: Python Nov 9th, 2009 |
| Replies: 7 Views: 300 You can try
while rounds > max(player_point, cpu_point) |
Forum: Python Nov 8th, 2009 |
| Replies: 16 Views: 469 you forgot the return statement. This is python, not pascal :)
from graphics import *
import math
def distanceBetweenPoints(p1, p2):
x1, y1 = p1.getX(), p1.getY()
x2, y2 = p2.getX(),... |
Forum: Python Nov 8th, 2009 |
| Replies: 16 Views: 469 add
from graphics import *
at the top of your file. Also please use code tags (http://www.daniweb.com/forums/announcement114-3.html) to post your python code. And also post python error... |
Forum: Python Nov 8th, 2009 |
| Replies: 16 Views: 469 The parameters p1 and p2 should not become P1 ad P2 the next line. Also, what does pyhon say ? |
Forum: Python Nov 8th, 2009 |
| Replies: 16 Views: 469 For example
def myfunction(pointA, pointB):
xa, ya = pointA.getX(), pointA.getY()
xb, yb = pointB.getX(), pointB.getY()
do_something_with(xa, ya, xb, yb) |
Forum: Python Nov 8th, 2009 |
| Replies: 14 Views: 581 You can use the 'key' argument to 'sort' or 'sorted'. Here, Data is a list. You can write
def my_key(item):
return item[1][1] # this returns 3.1 if item is ('1023', ['Name', '3.1',... |