python

String formatting: string specifier in a string constant

Is there a way to insert a string in a string constant/variable that contains a string specifier? Example: temp_body = 'Hello %s, please visit %s to confirm your registration.' body = temp_body % (name, url) But this raises a TypeError. ...

How do you invoke a python script inside a jar file using python ?

I'm working on an application that intersperses a bunch of jython and java code. Due to the nature of the program (using wsadmin) we are really restricted to Python 2.1 We currently have a jar containing both java source and .py modules. The code is currently invoked using java, but I'd like to remove this in favor of migrating as muc...

django send_mail from queryset

I am trying to use the django send_mail method. I am running into 2 issues, notably converting mail addresses from a list into a csv to be used in the recipients. The second issue is getting the list of user emails from the notifications model. my models class notifications(models.Model): notID = models.AutoField(primary_key=True) ...

How can I write this query in Django? (datetime)

| time_before | datetime | YES | MUL | NULL | | | time_after | datetime | YES | MUL | NULL | | the_tag = Tag.objects.get(id=tag_id) Log.objects.filter(blah).extra(where=['last_updated >'+the_tag.time_before, 'last_updated' < the_tag.time_after]) Ok. Basically, I have an object that's ca...

python mongokit Connection() AssertionError

just installed mongokit and can't figure out why I get AssertionError python console: >>> from mongokit import Connection >>> c = Connection() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python2.6/dist-packages/mongokit-0.5.3-py2.6.egg/mongokit/connection.py", line 35, in __init__ ...

Import C++ dll failed in Python

Following document in "Extending and Embedding the Python Interpreter", I created a VC project, and a dll file was successfully created with name "spam_d.dll" Main code was static PyObject * spam_system(PyObject *self, PyObject *args) { const char *command; int sts; if (!PyArg_ParseTuple(args, "s", &command)) retur...

Activestate python and MySQLdb

Hi, I have installed activestatepython and am trying to import MySQLdb import mySQLdb gives me an error stating "No module called MySQLdb" I have tried searching but all the resources out there explain how to set up the mySQLdb for unix, not for windows, can you please tell me how I can do that with Activestate python?...

Supported Audio Formats of Qt4 Phonon?

I am making a music player in PyQt4, and I am using Phonon to play the music itself. This application is aimed primarily at Windows, but I plan on also supporting Mac and Linux versions. What I want to know is which audio formats are supported by Phonon so that I can ensure that the user only enters those files. ...

How to extend/patch an existing module or package?

I want to extend some locale-specific features of a python application named OpenERP. All I need is implementing a third party module.function that would be called every time OpenERP calls locale.setlocale() function without changing neither OpenERP nor locale module source code. The only way I can imagine is provide a module named loca...

Hyphenate a random string to an exact format

Hello, I am creating a random ID using the below code: from random import * import string # The characters to make up the random password chars = string.ascii_letters + string.digits def random_password(): return "".join(choice(chars) for x in range(32)) This will output something like: 60ff612332b741508bc4432e34ec1d3e I wo...

Which programming language or a library can process Infinite Series ?

Which programming language or a library is able to process infinite series (like geometric or harmonic)? It perhaps must have a database of some well-known series and automatically give proper values in case of convergence, and maybe generate an exception in case of divergence. For example, in Python it could look like: sum = 0 sign =...

Python enumerate built-in error when using the start parameter

I'm modifying some code that calls enumerate on a list declared via a list comprehension e.g. self.groups = [Groups(self, idx) for idx in range(n_groups)] then later: for idx, group in enumerate(self.groups): # do some stuff but when I change the enumerate call to start at the 2nd list element via the start parameter e.g. for...

Hierarchical checked tree control with tri-state checkboxes in wxPython?

As per the title, is this possible? By tri-state, I mean the parent node is: Checked if all children are checked Unchecked if all children are unchecked Grey/Filled if some children are checked I have used them previously in C# but cannot find an equivalent control/implementation for wxPython. ...

Pylint only Global evaluation

In pylint I use this command --reports=n to disable the reports, but now I don't see the Global evaluation more. Is possible enable only the Global evaluation? ...

Copy whole SQL Server database into JSON from Python

I facing an atypical conversion problem. About a decade ago I coded up a large site in ASP. Over the years this turned into ASP.NET but kept the same database. I've just re-done the site in Django and I've copied all the core data but before I cancel my account with the host, I need to make sure I've got a long-term backup of the data s...

Missing multiprocessing module when freezing Python code

Hi Guys, I'm using cx_Freeze to freeze my Python code so I can distribute it as executable on Windows systems. It works fine but it's missing a few modules. I use some open-source libraries in my project e.g. BeautifulSoup and Periscope. They use some libraries for backward compatibility which i don't need to include as Python 2.6 has t...

Django JSON serializable error

With the following code below, There is an error saying File "/home/user/web_pro/info/views.py", line 184, in headerview, raise TypeError("%r is not JSON serializable" % (o,)) TypeError: <lastname: jerry> is not JSON serializable In the models code header(models.Model): firstname = models.ForeignKey(Firstname)...

How do I resolve this curl-related error?

please tell me the solution Traceback (most recent call last): File "<stdin>", line 1, in <module> File "build/bdist.linux-x86_64/egg/pycurl.py", line 7, in <module> File "build/bdist.linux-x86_64/egg/pycurl.py", line 6, in __bootstrap__ ImportError: libcurl.so.4: cannot open shared object file: No such file or directory ...

Django newbie question: can't start a new project

Hello. I'm totally new to django, and I'm using its documentation to get help on how to use it but seems like something is missing. i installed django using setup.py install command and i added the ( django/bin ) to system path variable but. i still cant start a new project i use the following syntax to start a project : django-admin....

Which files to distribute using cx_Freeze?

I'm using cx_freeze to freeze a Python script for distribution to other windows systems. I did everything as instructed and cx_freeze generated a build\exe.win32-2.6 folder in the folder containing my sources. This directory now contains a a bunch of PYD files, a library.zip file, the python DLL file and the main executable. Which of th...