Search Results

Showing results 1 to 40 of 408
Search took 0.03 seconds.
Search: Posts Made By: Gribouillis ; Forum: Python and child forums
Forum: Python 5 Days Ago
Replies: 10
Views: 297
Posted By Gribouillis
Congratulations ! Can you mark the thread as solved ?
Forum: Python 6 Days Ago
Replies: 10
Views: 297
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
You probably still have the wrong indentation for the line
status = staticmethod(status).
Forum: Python 18 Days Ago
Replies: 4
Views: 274
Posted By Gribouillis
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
Solved: ubuntu Launcher
Views: 353
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
theIndex[124] is a list, so you can just write

theIndex[124].append("m")
Forum: Python 25 Days Ago
Replies: 7
Views: 7,245
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Solved: drawing an eye?
Views: 309
Posted By Gribouillis
You can write

if colour in ("Green", "Blue", "Red"):
... # do something
else:
... # do something else
Forum: Python 30 Days Ago
Replies: 9
Views: 331
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Posted By Gribouillis
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
Solved: drawing an eye?
Views: 309
Posted By Gribouillis
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
Solved: drawing an eye?
Views: 309
Posted By Gribouillis
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
Posted By Gribouillis
Yes, you should have written 'and' istead of 'or'.
Forum: Python Nov 9th, 2009
Replies: 7
Views: 300
Posted By Gribouillis
You can try

while rounds > max(player_point, cpu_point)
Forum: Python Nov 8th, 2009
Replies: 16
Solved: Pythagoras?
Views: 469
Posted By Gribouillis
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
Solved: Pythagoras?
Views: 469
Posted By Gribouillis
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
Solved: Pythagoras?
Views: 469
Posted By Gribouillis
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
Solved: Pythagoras?
Views: 469
Posted By Gribouillis
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
Posted By Gribouillis
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',...
Showing results 1 to 40 of 408

 


About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC