I am a php programmer trying to understand python's for in syntax
I get the basic for in
for i in range(0,5):
in php would be
for ($i = 0; $i < 5; $i++){
but what does this do
for x, y in z:
and what would be the translation to php?
This is the full code i am translating to php:
def preProcess(self):
""" plan for the arra...
I am working at a bit lower level writing a small framework for creating test fixtures for my project in Python. In this I want to find out whether a particular variable is an instance of a certain class or a class itself and if it is a class, I want to know if it is a subclass of a certain class defined by my framework. How do I do it?
...
When I build a c extension using python setup.py build, the result is created under a directory named
build/lib.linux-x86_64-2.6/
where the part after lib. changes by the OS, CPU and Python version.
Is there a way I can access the appropriate string for my current architecture from python? Hopefully in a way that is guaranteed to mat...
i want to match StringProperty() with UserProperty & i cant change property so how i can achieve it?
Please help me out..................
...
Why such structure
class A:
def __init__(self, a):
self.a = a
def p(self, b=self.a):
print b
gives an error NameError: name 'self' is not defined?
...
I have two matrices. Both are filled with zeros and ones. One is a big one (3000 x 2000 elements), and the other is smaller ( 20 x 20 ) elements. I am doing something like:
newMatrix = (size of bigMatrix), filled with zeros
l = (a constant)
for y in xrange(0, len(bigMatrix[0])):
for x in xrange(0, len(bigMatrix)):
for b in...
I have downloaded mysqlDb, and while installing it I am getting errors like:
C:\Documents and Settings\naresh\Desktop\MySQL-python-1.2.3c1>setup.py build
Traceback (most recent call last):
File "C:\Documents and Settings\naresh\Desktop\MySQL-python-1.2.3c1
\setup.py",line15, in
metadata, options = get_config()
File "C:\Document...
Suppose a programmer has the following problem: he wants to start a new python project. He needs a basic layout of boilerplate stuff, like test directory, source directory, setuptools script etc.. How does he create all this stuff and layout with a single command ?
For example, paster (as suggested in one of the answers, provides you th...
I have some variables and I want to select the first one that evaluates to True, or else return a default value.
For instance I have a, b, and c. My existing code:
result = a if a else (b if b else (c if c else default))
Another approach I was considering:
result = ([v for v in (a, b, c) if v] + [default])[0]
But they both feel me...
I am working on embedded linux platform with limited system resources.
I want to do fullscreen slideshow with simple transistions (like slide in-out, fade in-out ).
I tried PyGtk+GTK+Cairo but its very slow, when I animate GTK image controls I get just two or three frames per second. But smplayer is playing video at good speed!
I did ...
hi all, how can I replace the NaN value in an array, zero if an operation is performed such that as a result instead of the NaN value is zero operations as
0 / 0 = NaN can be replaced by 0
...
Hi,
i'm writing a small script to tweet messages from the monitoring systems. The only issue i ran into so far is that i can't set the User-Agent correctly, all tweets show up as "from API" which ain't a huge deal but i wonder what I'm doing wrong.
An example to reproduce this behavior:
import sys
import twitter
USERNAME="twitteruser...
I need to control a program by sending commands in utf-8 encoding to its standard input. For this I run the program using subprocess.Popen():
proc = Popen("myexecutable.exe", shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
proc.stdin.write(u'ééé'.encode('utf_8'))
If I run this from a cygwin utf-8 console, it works. If I run it from ...
Hello SO, I have another question for you.
I have a python class with a list 'metainfo'. This list contains variable names that my class might contain. I wrote a __eq__ method that returns True if the both self and other have the same variables from metainfo and those variables have the same value.
Here is my implementation:
def __eq...
Ok so i have this piece of code:
def findNReplaceRegExp(file_name, regexp, replaceString, verbose=True, confirmationNeeded=True):
'''Replaces the oldString with the replaceString in the file given,\
returns the number of replaces
'''
# initialize local variables
cregexp = re.compile(regexp, re.MULTILINE | re.DOTALL)
somet...
Hi guys, the normal behavior of urllib/urllib2 is if an error code is sent in the header of the response (i.e 404) an Exception is raised.
How do you look for specific errors i.e (40x, or 50x) based on the different errors, do different things. Also, how do you read the actual data being returned HTML/JSON etc (The data usually has err...
Possible Duplicate:
Recognising tone of the audio
Hi I need to recognize what tone is being played on my mic which inputs in the pc from the mic, with python. What should I use?
...
as I can perform operations on arrays so that does nothing on the diagonal
is calculated such that all but the diagonal
array ([[0., 1.37, 1., 1.37, 1., 1.37, 1.]
[1.37, 0. , 1.37, 1.73, 2.37, 1.73, 1.37]
[1. , 1.37, 0. , 1.37, 2. , 2.37, 2. ]
[1.37, 1.73, 1.37, 0. , 1.37, 1.73, 2.37]
[1. , 2.37, 2...
I'm trying to make a pyaudio input stream but can't figure out how to make it.
What I did is:
a = pyaudio.PyAudio()
Then tried to call a.open() but I don't know the arguments I should type in. It asks me to check Stream.init for a reference, but I don't know what a PA_MANAGER is and the documentation isn't useful at all about it.
...
Is there any easy way to make 2 methods, let's say MethodA() and MethodB() run in 2 different cores? I don't mean 2 different threads. I'm running in Windows, but I'd like to know if it is possible to be platform independent.
edit: And what about
http://docs.python.org/dev/library/multiprocessing.html
and
parallel python ?
...