Forum: Python 4 Hours Ago |
| Replies: 8 Views: 88 A complete answer requires to browse python's source code. However, consider a piece of python code like this
x = aValue()
F( G(), x )
Since the value returned by G() is a new reference, it... |
Forum: Python 5 Hours Ago |
| Replies: 8 Views: 88 Steal means that the item will be referenced in the tuple, but without increasing it's reference count. When the tuple is deleted, the object will be decrefed.
For example if you create a python... |
Forum: Python 10 Hours Ago |
| Replies: 2 Views: 97 See also this (http://en.wikipedia.org/wiki/Primitive_type) |
Forum: Python 17 Hours Ago |
| Replies: 2 Views: 76 Try to run the loop 1 000 000 times instead of 1000. On my machine, it takes 0.0818829536438 seconds for 1 million times. See also the module timeit. |
Forum: Python 1 Day Ago |
| Replies: 2 Views: 106 You could write something like
from time import sleep
import os
def wait_file(filename):
cnt = 3 * 60
while cnt > 0:
if os.path.isfile(filename):
return |
Forum: Python 1 Day Ago |
| Replies: 3 Views: 107 If your compile can't find Python.h, you must add an include directory. On my system, I get
>>> from distutils import sysconfig
>>> sysconfig.get_python_inc()
'/usr/include/python2.6'
So for... |
Forum: Python 1 Day Ago |
| Replies: 7 Views: 6,844 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 1 Day Ago |
| Replies: 8 Views: 211 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 3 Days Ago |
| Replies: 0 Views: 172 This snippet defines a context to execute a block of statements in a different working directory (with the help of the with statement). After the block is exited, the initial working directory is... |
Forum: Python 4 Days Ago |
| Replies: 5 Views: 190 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 6 Days Ago |
| Replies: 6 Views: 224 You can write
if colour in ("Green", "Blue", "Red"):
... # do something
else:
... # do something else |
Forum: Python 6 Days Ago |
| Replies: 4 Views: 235 For a crash reference, there is PQRC (http://www.limsi.fr/Individu/pointal/python/pqrc/versions/PQRC-2.4-A4-latest.pdf).
There is also another one (http://home.uchicago.edu/~gan/file/python.pdf)... |
Forum: Python 6 Days Ago |
| Replies: 9 Views: 237 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 7 Days Ago |
| Replies: 6 Views: 283 This may work
SP.Popen("c:\\program files\\webteh\\bsplayerpro\\bsplayer.exe d:\\rodin\\rodin.mp4 -stime"+str(d), shell=True) |
Forum: Python 7 Days Ago |
| Replies: 6 Views: 243 That's a problem with these code snippet. In the active state snippets, people can update their code long after the initial post. |
Forum: Python 7 Days Ago |
| Replies: 6 Views: 243 nice, it looks like a kind of 'scanf' for python. |
Forum: Python 7 Days Ago |
| Replies: 6 Views: 283 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 7 Days Ago |
| Replies: 7 Views: 244 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 8 Days Ago |
| Replies: 3 Views: 162 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 8 Days Ago |
| Replies: 2 Views: 120 This one (http://blog.doughellmann.com/2007/07/pymotw-subprocess.html) perhaps ? |
Forum: Python 8 Days Ago |
| Replies: 5 Views: 171 It seems worth trying. In any case, if there is a significant difference in performance, it's a good idea to find out where it comes from. The cProfile module allows you to spot the function calls... |
Forum: Python 8 Days Ago |
| Replies: 5 Views: 171 You could replace threads with processes to get parallelism, using the multiprocessing module. |
Forum: Python 8 Days Ago |
| Replies: 5 Views: 171 Perhaps you could use the cProfile module to find out where time is spent ? |
Forum: Python 8 Days Ago |
| Replies: 7 Views: 178 It's true, suppose that mypackage contains __init__.py, foo.py, bar.py and baz.py. You could have this in __init__.py
import foo
import bar
import baz
then, if you simply write import... |
Forum: Python 8 Days Ago |
| Replies: 7 Views: 178 When the package system was added to python, the idea was that a folder could be a python module and it could have submodules. If the folder is a module, you need some place to put python code which... |
Forum: Python 8 Days Ago |
| Replies: 1 Views: 149 What they mean is that you must run these commands
patch-p1-i clammwin/patches/wxPython-2424.maskededit.patch
patch-p1-i clamwin/patches/wxPython-2424.throbber.patch
patch-p1-i... |
Forum: Python 8 Days Ago |
| Replies: 7 Views: 178 You could go this way, assuming that you have a folder named 'mypackage' wich contains a file '__init__.py'
# tested with py 2.6
import os
import mypackage
def module_names(package):
#... |
Forum: Python 8 Days Ago |
| Replies: 11 Views: 362 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 8 Days Ago |
| Replies: 13 Views: 290 When you call Py_Initialize, the program creates the module __main__ where your commands are run, and allocates all the memory it needs for the __builtin__ module, etc, exactly as if you were... |
Forum: Python 8 Days Ago |
| Replies: 6 Views: 224 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 8 Days Ago |
| Replies: 13 Views: 290 No, the interpreter runs in the main thread. Its role is to execute python code. For example, you can call PyImport_ImportModule, and this will run the python code contained in the given module.... |
Forum: Python 8 Days Ago |
| Replies: 2 Views: 159 Notice getpass.getuser() which finds your login name (does it work on mac ?). |
Forum: Python 8 Days Ago |
| Replies: 6 Views: 224 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 8 Days Ago |
| Replies: 13 Views: 290 Few people write C programs for python 3. I think you should experiment a while with these functions. I interface C++ and python 2.6, but for the main part, I use Py++... |
Forum: Python 9 Days Ago |
| Replies: 5 Views: 175 I think that Van Rossum prefers OSX, and he works for Google, which makes 2 other obstacles. |
Forum: Python 9 Days Ago |
| Replies: 16 Views: 791 Good luck with your struggle ! |
Forum: Python 10 Days Ago |
| Replies: 16 Views: 791 |
Forum: Python 10 Days Ago |
| Replies: 16 Views: 791 I don't mean to win anything, I think this is a place to discuss python programming, with people having different levels, who like and learn this language. Hundreds of threads here are about... |
Forum: Python 10 Days Ago |
| Replies: 16 Views: 791 I think it's pure paranoia to suspect someone from stealing someone else's property just because he is extracting data from their web page. Why not jail people who post in the web development forums... |
Forum: Python 10 Days Ago |
| Replies: 13 Views: 290 The implementation of PyBytes_asString in python 3.1.1 is
char *
PyBytes_AsString(register PyObject *op)
{
if (!PyBytes_Check(op)) {
PyErr_Format(PyExc_TypeError,
"expected bytes,... |