python

Passing multiple arguments to C function within Python

Let's say I have a c library that manipulates a world somehow. I want to use this library with python. I want to be able to write simple python scripts that represent different scenarios of world management. I have functions that create and destroy a world: void* create(void); int destroy(void* world); Here is some python code: impor...

Mac 10.6 Universal Binary scipy: cephes/specfun "_aswfa_" symbol not found

Hi folks, I can't get scipy to function in 32 bit mode when compiled as a i386/x86_64 universal binary, and executed on my 64 bit 10.6.2 MacPro1,1. My python setup With the help of this answer, I built a 32/64 bit intel universal binary of python 2.6.4 with the intention of using the arch command to select between the architectures. ...

What questions should every good Python developer be able to answer?

What questions do you think should a good Python programmer be able to respond to? PS: I have seen this question based on other languages but not Python! ...

Python: Need to replace a series of different substrings in HTML template with additional HTML or database results

Situation: I am writing a basic templating system in Python/mod_python that reads in a main HTML template and replaces instances of ":value:" throughout the document with additional HTML or db results and then returns it as a view to the user. I am not trying to replace all instances of 1 substring. Values can vary. There is a finite...

Django thumbnails from urls

Hello, I have this Wordpress.com site with thumbnails of themes. I thought about creating a similar site with Django. Instead of using the thumbnail images from the Wordpress gallery as in the page above, I want to have thumbnails of actual blogs. Is there a way to display thumbnails from urls? Thank you. ...

Django Haystack exact filtering

I have a haystack search which has the following SearchIndex: class GrantIndex(indexes.SearchIndex): """ This provides the search index for the Grant application. """ text = indexes.CharField(document=True, use_template=True) year = indexes.IntegerField(model_attr='year__year') date = indexes.DateField(model_att...

How to create a django model field that has a default value if ever set to null

Given a model class Template(models.Model): colour = models.CharField(default="red", blank = True, null=True) How can I arrange it so that any access to colour either returns the value stored in the field, or if the field is blank/null then it returns red? The default=red will put "red" in the field when it's first created, but i...

exe generated with py2exe can't find pywinauto

Hi there: I've been trying to pack my app with py2exe. The application works fine but it keeps failing to find/use pywinauto. I been googling but I get nothing, I'm now I'm totally lost... Here's the packing script: from distutils.core import setup setup( windows = ["mainForm.py"], data_files=[ ('', ['mainForm.ui']), ...

Python: How can I increment a char?

I'm new to Python, coming from Java and C. How can I increment a char? In Java or C, chars and ints are practically interchangeable, and in certain loops, it's very useful to me to be able to do increment chars, and index arrays by chars. How can I do this in Python? It's bad enough not having a traditional for(;;) looper - is there an...

Python: Accessing an attribute using a variable

How do I reference this_prize.left or this_prize.right using a variable? from collections import namedtuple import random Prize = namedtuple("Prize", ["left", "right"]) this_prize = Prize("FirstPrize", "SecondPrize") if random.random() > .5: choice = "left" else: choice = "right" #retrieve the value of "left" or "right" d...

Calling An Inherited Class Method From Java

In Python, class methods can be inherited. e.g. >>> class A: ... @classmethod ... def main(cls): ... return cls() ... >>> class B(A): pass ... >>> b=B.main() >>> b <__main__.B instance at 0x00A6FA58> How would you do the equivalent in Java? I currently have: public class A{ public void show(){ System.out.println("A");...

Python GIL and globals

In python, I have a global variable defined that gets read/incremented by different threads. Because of the GIL, will this ever cause problems without using any kind of locking mechanism? ...

In ASP - Why is it that I can call python functions from vbscript but not vice-versa?

I'm planning on writting some new code for a legacy ASP application in Python, and I ran into some odd behavior. If I write a function in python I can easily call it from a VBScript block. However, if I try to call a function defined in VBScript from python, I get an error: Python ActiveX Scripting Engine error '80020009' Traceback (...

Change the color of a node or an edge

I want to redraw a Graph g with only the color of a node or edge changed. How do I do that? ...

Python code for determining which normal form tabular data is in

I'm looking for Python code that can take tabular data and establish which normal form(s) it is in (if any) and show any functional dependencies, etc. ...

Python: Using namedtuple._replace with a variable as a fieldname.

Can I reference a namedtuple fieldame using a variable? from collections import namedtuple import random Prize = namedtuple("Prize", ["left", "right"]) this_prize = Prize("FirstPrize", "SecondPrize") if random.random() > .5: choice = "left" else: choice = "right" #retrieve the value of "left" or "right" depending on the ch...

How do I access a python list from a django templatetag?

I have created a templatetag that loads a yaml document into a python list. In my template I have {% get_content_set %}, this dumps the raw list data. What I want to be able to do is something like {% for items in get_content_list %} <h2>{{items.title}}</h2> {% endfor %}` ...

How do I build an WSGI apps built with CherryPyWSGIServer that support both HTTP and HTTPS?

I built a WSGI app and created a standalone wrapper using CherryPyWSGIServer. I see that CherryPyWSGIServer supports HTTPS but I am not sure how to support both HTTP and HTTPS together as it looks like the first server.start() blocks. How would I create two servers, one HTTP and one HTTPS, and start them both? Here is what I have now: ...

Python regex split, integer of arbitrary length

I'm trying to do a simple regex split in Python. The string is in the form of FooX where Foo is some string and X is an arbitrary integer. I have a feeling this should be really simple, but I can't quite get it to work. On that note, can anyone recommend some good Regex reading materials? ...

drop into python interpreter while executing function

i have a python module with a function: def do_stuff(param1 = 'a'): if type(param1) == int: # enter python interpreter here do_something() else: do_something_else() is there a way to drop into the command line interpreter where i have the comment? so that if i run the following in python: >>> import m...