python

Best way to write a Python function that integrates a gaussian?

In attempting to use scipy's quad method to integrate a gaussian (lets say there's a gaussian method named gauss), I was having problems passing needed parameters to gauss and leaving quad to do the integration over the correct variable. Does anyone have a good example of how to use quad w/ a multidimensional function? But this led me t...

How to call a python function from a foreign language thread (C++)

Hi, I am developing a program that use DirectShow to grab audio data from media files. DirectShow use thread to pass audio data to the callback function in my program, and I let that callback function call another function in Python. I use Boost.Python to wrapper my library, the callback function : class PythonCallback { private: ...

creating blank field and receving the INTEGER PRIMARY KEY with sqlite, python

I am using sqlite with python. When i insert into table A i need to feed it an ID from table B. So what i wanted to do is insert default data into B, grab the id (which is auto increment) and use it in table A. Whats the best way receive the key from the table i just inserted into? ...

How do I use django mptt?

I have a model: class Company(models.Model): name = models.CharField( max_length=100) parent = models.ForeignKey('self', null=True, blank=True, related_name='children') mptt.register(Company, order_insertion_by=['name']) and class Financials(models.Model): year = models.IntegerField() revenue = models.DecimalField(ma...

How can I make a time delay in Python?

I want to know how to put delay in a Python script. ...

Python read a single character from the user

Is there a way of reading one single character from the user input? For instance, they press one key at the terminal and it is returned. Sort of like getch(). I know that there is a function in windows for it, but I'd like something that is cross-platform. Thanks. ...

Is there a way to get the current ref count of an object in Python?

Is there a way to get the current ref count of an object in Python? ...

Using Python Ctypes for ssdeep's fuzzy.dll but receive Error [SOLVED]

I am trying to use python and ctypes to use the fuzzy.dll from ssdeep. So far all I have tried fails with and access violation error. Here is what I do after changing to the proper directory which contains the fuzzy.dll and fuzzy.def files. >>> import os,sys >>> from ctypes import * >>> fn = create_string_buffer(os.path.abspath("fuzzy...

Spawn subprocess that expects console input without blocking?

Hello, I am trying to do a CVS login from Python by calling the cvs.exe process. When calling cvs.exe by hand, it prints a message to the console and then waits for the user to input the password. When calling it with subprocess.Popen, I've noticed that the call blocks. The code is subprocess.Popen(cvscmd, shell = True, stdin = subp...

How to write a functional test for a DBUS service written in Python?

(Title was: "How to write a unit test for a DBUS service written in Python?") I've started to write a DBUS service using dbus-python, but I'm having trouble writing a test case for it. Here is an example of the test I am trying to create. Notice that I have put a GLib event loop in the setUp(), this is where the problem hits: import u...

Getting the class name of an instance in Python

Hi, How do I find out a name of class that created an instance of an object in Python if the function I am doing this from is the base class of which the class of the instance has been derived? Was thinking maybe the inspects module might have helped me out here, but it doesn't seem to give me what I want and short of parsing the __cla...

How can I tell python which version of libmysqlclient.so to use?

Hi, I'm running a python script on a shared hosting server which until this morning had MySQL version 4. Now it has version 5. My python script can no longer connect to MySQL, as it can't find libmysqlclient_r.so.14: $ python my_script.py Traceback (most recent call last): File "my_script.py", line 6, in ? import MySQLdb File "/home/l...

How to print a string without including '\n' in Python

Suppose my string is ' Hai Hello\nGood eve\n' How to eliminate the '\n' in between and make a string print like : Hai Hello Good eve ??? ...

Django Installed Apps Location

Hi, I am an experienced PHP programmer using Django for the first time, and I think it is incredible! I have a project that has a lot of apps, so I wanted to group them in an apps folder. So the structure of the project is: /project/ /project/apps/ /project/apps/app1/ /project/apps/app2 Then in Django settings I have put this: INS...

Combined Python & Ruby extension module

I have a C extension module for Python and I want to make it available to Rubyists. The source has a number of C modules, with only one being Python-dependent. The rest depend only on each other and the standard library. I can build it with python setup.py build in the usual way. I've been experimenting with adding Ruby support using n...

Why doesn't PyRun_String evaluate bool literals?

I need to evaluate a Python expression from C++. This code seems to work: PyObject * dict = PyDict_New(); PyObject * val = PyRun_String(expression, Py_eval_input, dict, 0); Py_DECREF(dict); Unfortunately, it fails horribly if expression is "True" of "False" (that is, val is 0 and PyErr_Occurred() returns true). What am I doing wrong? ...

How to copy a directory and its contents to an existing location using Python?

I'm trying to copy a directory and all its contents to a path that already exists. The problem is, between the os module and the shutil module, there doesn't seem to be a way to do this. the shutil.copytree() function expects that the destination path not exist beforehand. The exact result I'm looking for is to copy an entire folder s...

How to access templates in Python ?

Sometimes, for a program with a lot of data, it is common to place the data in an external file. An example is a script that produces an HTML report, using an external file to hold a template. In Java, the most recommended way to retrieve a resource of the program is to use getClass().getClassLoader().getResource() or getClass().getClas...

gedit plugin development in python

Does anyone know where information about writing gedit plugins can be found ? I'm interested in writing them in Python. I know of Gedit/PythonPluginHowTo , but it isn't very good . Besides the code of writing a plugin that does nothing , I can't seem to find more information . I started to look at other people's code , but I think this ...

memory use in large data-structures manipulation/processing

I have a number of large (~100 Mb) files which I'm regularly processing. While I'm trying to delete unneeded data structures during processing, memory consumption is a bit too high. so, I was wondering is there a way to 'efficiently' manipulate large data, e.g.: def read(self, filename): fc = read_100_mb_file(filename) self.proc...