I am trying to create a 'mask' of a numpy.array by specifying certain criteria. Python even has nice syntax for something like this:
>> A = numpy.array([1,2,3,4,5])
>> A > 3
array([False, False, False, True, True])
But if I have a list of criteria instead of a range:
>> A = numpy.array([1,2,3,4,5])
>> crit = [1,3,5]
I can't do this...
Possible Duplicate:
Least Astonishment in Python: The Mutable Default Argument
can anyone explain me this?
class Strange(object):
def mutate(self, x=[]):
x.append(1)
return x
obj = Strange()
print obj.mutate()
another_obj = Strange()
print another_obj.mutate()
>> [1]
>> [1, 1]
mutate() is called with...
Hello,
To implement a simple protocol in python, I've used a thread to monitor acknowledgements send by the receiver. To do this, I use a thread in a function
def ackListener(self):
while self.waitingforack:
ack = self.socket_agent.recv(4)
...
exit()
where self.waitingforack is a boolean I set to False when I...
What's the best way to integrate erlang and python?
We need to call python functions in erlang and call erlang functions in python. At this moment we are trying to use SOAP as a intermediate layer between these two languages, but we have a lot of "not compatible" troubles. Could you advise the best way to perform integration?
...
I'm trying to create a 'fillable' PDF form. I have code that draws rectangles and text onto an existing PDF when given a list of coordinates and data, but I need to build (or find!) a tool to generate these lists of coordinates. I want to be able to draw a rectangle and save the coordinates and size of it. (If this were a raster image, i...
I'm setting up a data model in django using multiple-table inheritance (MTI) like this:
class Metric(models.Model):
account = models.ForeignKey(Account)
date = models.DateField()
value = models.FloatField()
calculation_in_progress = models.BooleanField()
type = models.CharField( max_length=20, choices= METRIC_TYPES )...
I have the following piece of code:
NameX.functionA(functionB(Dictionary["___"]))
Instead of _ I would like to make a reference to NameX in the form of a string, so that the program interprets it as
NameX.functionA(functionB(Dictionary["NameX"]))
How can I do this? I tried to use str(self), but it is clearly wrong.
Thanks
...
Hi! How are you doing today?
I'm writing because I have a database problem. I am trying to migrate a Grok/Zope application from ZopeDB to MySql, and I don't know exactly how to specify one of the relationships between tables... I am using “megrok.rdb” and “sqlalchemy”.
I have four classes involved:
A record with some information (l...
In the code below row is a tuple of 200 elements (numbers) and listOfVars is a tuple of 200 strings that are variable names in the testTable. tupleForm is a list of tuples, 200 elements in each tuple.
The following code does not work. It returns a syntax error:
for row in tupleForm:
cmd = '''INSERT INTO testTable listOfVars values...
I wanted to provide unique ID for different categories of models in my db. So I've introduced a dummy model :
class GUUID(models.Model):
guuid = models.PositiveSmallIntegerField(_(u"Dummy GUUID"), default=1)
and in model that I want to have unique ID:
class Event(models.Model):
unique = models.IntegerField(blank=False, edita...
I have pretty simple problem. I have a large file that goes through three steps, a decoding step using an external program, some processing in python, and then recoding using another external program. I have been using subprocess.Popen() to try to do this in python rather than forming unix pipes. However, all the data are buffered to ...
Python 2.7 (32-bit) Windows: We're experimenting with Python 2.7's support for themed Tkinter (ttk) for simple GUI's and have come away very impressed!! The one area where the new theme support seems to have come up short is how OS specific common dialogs are wrapped.
Corrected: In other words, the MessageBox and ColorChooser common dia...
Hey can anyone help me with my homework question to do with python and running time please? This is the question below:
In each code fragment given below, determine the number of steps and describe what the
code accomplishes, i.e., what value of x has been output based on the value of the integer
n. Assume the value of n has already b...
Is there a way to globally trap MemoryError exceptions so that a library can clear out caches instead of letting a MemoryError be seen by user code?
I'm developing a memory caching library in Python that stores very large objects, to the point where it's common for users to want to use all available RAM to simplify their scripts and/or ...
hello.
how to create file names from a number plus a suffix??.
for example I am using two programs in python script for work in a server, the first creates a file x and the second uses the x file, the problem is that this file can not overwrite.
no matter what name is generated from the first program. the second program of be taken e...
I have read the documentation but I don't understand.
Why do I have to use distutils to install python modules ?
Why do I just can't save the modules in python path ?
...
Possible Duplicates:
Open source Python project to contribute to
What are good open source projects in Python for which I can be a contributor?
Hi,
I was wondering what are some open source projects that are easy to code for and contribute to for a beginner. I obviously don't expect to get into feature development, since I'...
I have a model with a unique integer that needs to increment with regards to a foreign key, and the following code is how I currently handle it:
class MyModel(models.Model):
business = models.ForeignKey(Business)
number = models.PositiveIntegerField()
spam = models.CharField(max_length=255)
class Meta:
unique_to...
Please advise me some command line utility or may be a function/method in JavaScript, Python or some other language to quickly convert SASS to CSS. I am going to use it with my text editor and want to work with SASS, then quickly convert this file to CSS.
Thanks.
...
I have a python applicaiton that need to luanch a word document .
is there any option to luanch a word document with read mode only from python ?
...