Forum: Python 5 Days Ago |
| Replies: 3 Views: 173 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 5 Days Ago |
| Replies: 3 Views: 173 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 7 Days Ago |
| Replies: 7 Views: 265 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 7 Days Ago |
| Replies: 3 Views: 261 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 8 Days Ago |
| Replies: 5 Views: 245 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 9 Days Ago |
| Replies: 3 Views: 235 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 9 Days Ago |
| Replies: 4 Views: 218 You probably still have the wrong indentation for the line
status = staticmethod(status). |
Forum: Python 9 Days Ago |
| Replies: 4 Views: 218 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 10 Days Ago |
| Replies: 3 Views: 286 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 13 Days Ago |
| Replies: 5 Views: 257 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 13 Days Ago |
| Replies: 2 Views: 195 theIndex[124] is a list, so you can just write
theIndex[124].append("m") |
Forum: Python 15 Days Ago |
| Replies: 7 Views: 7,103 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 16 Days Ago |
| Replies: 8 Views: 285 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 18 Days Ago |
| Replies: 5 Views: 323 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 20 Days Ago |
| Replies: 6 Views: 280 You can write
if colour in ("Green", "Blue", "Red"):
... # do something
else:
... # do something else |
Forum: Python 21 Days Ago |
| Replies: 9 Views: 311 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 21 Days Ago |
| Replies: 6 Views: 367 This may work
SP.Popen("c:\\program files\\webteh\\bsplayerpro\\bsplayer.exe d:\\rodin\\rodin.mp4 -stime"+str(d), shell=True) |
Forum: Python 21 Days Ago |
| Replies: 6 Views: 367 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 22 Days Ago |
| Replies: 3 Views: 213 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 23 Days Ago |
| Replies: 11 Views: 479 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 23 Days Ago |
| Replies: 6 Views: 280 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 23 Days Ago |
| Replies: 6 Views: 280 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 26 Days Ago |
| Replies: 7 Views: 289 Yes, you should have written 'and' istead of 'or'. |
Forum: Python 26 Days Ago |
| Replies: 7 Views: 289 You can try
while rounds > max(player_point, cpu_point) |
Forum: Python 27 Days Ago |
| Replies: 16 Views: 397 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 27 Days Ago |
| Replies: 16 Views: 397 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 27 Days Ago |
| Replies: 16 Views: 397 The parameters p1 and p2 should not become P1 ad P2 the next line. Also, what does pyhon say ? |
Forum: Python 27 Days Ago |
| Replies: 16 Views: 397 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 28 Days Ago |
| Replies: 14 Views: 561 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',... |
Forum: Python 28 Days Ago |
| Replies: 16 Views: 397 According to your previous post, I think that you are using the "graphics.py" module like this one (http://mcsp.wartburg.edu/zelle/python/). In that case, since p1 and p2 are not numbers but Points,... |
Forum: Python 29 Days Ago |
| Replies: 8 Views: 267 I ran pylint (http://www.logilab.org/project/pylint) on this code. Here is the result (note that this depends on my personal configuration of pylint, it may give a different result on your system)
... |
Forum: Python 29 Days Ago |
| Replies: 11 Views: 467 Yes, I knew there was a function like this, but I couldn't remember where it was. Thanks. |
Forum: Python 30 Days Ago |
| Replies: 4 Views: 224 You can also use format
message = "z's value is {z:0{digits}n}".format(z=2, digits=3)
print(message) |
Forum: Python 30 Days Ago |
| Replies: 9 Views: 258 The answer to "Can Python do this ?" is usually Yes.
"I need help" often means it's homework due in 2 hours. |
Forum: Python 31 Days Ago |
| Replies: 5 Views: 260 |
Forum: Python 31 Days Ago |
| Replies: 5 Views: 260 Did you place a 'graphics.py' (good) or a 'graphic.pyc' (bad) in the site-packages folder ? Try to remove the '.pyc' and run again, it may work. Otherwise, you can attach graphics.py to a post, so... |
Forum: Python 31 Days Ago |
| Replies: 5 Views: 260 A simple thing to do is to put the file "graphics.py" in a folder named "site-packages" which is a subfolder of your python Lib folder. You should locate it easily on your computer.
Another... |
Forum: Python 31 Days Ago |
| Replies: 6 Views: 361 Here is a script which should work for 1 .pdb file and many .pd files. It creates the new versions of the .pd files (with less lines) in a separate output directory. See the usage at the end of the... |
Forum: Python 31 Days Ago |
| Replies: 14 Views: 414 You can also do this without a loop
#!/usr/bin/env python
import re
nonletters = re.compile("[^a-zA-Z]+")
def letters_only(mystring):
return nonletters.sub(lambda m: '', mystring) |
Forum: Python 31 Days Ago |
| Replies: 6 Views: 361 If you have 10 file1 and 2000 file2, it makes 20000 file3 (output files). You should explain clearly what you want:
* Are the file1 in a separate directory ? How do you recognize that a file is a... |