python

How do I use context_instance in my template

Hi Guys, Django newbie here, I'm using render_to_response('example.html', { 'error_message': error_message, }, context_instance=RequestContext(request)) How do I use the request in the template? (e.g. the request.host etc.) ...

Safest way to convert float to integer in python?

Hi, Python's math module contain handy functions like floor & ceil. These functions take a floating point number and return the nearest integer bellow or above it. However these functions return the answer as a floating point number. For example: In [1]: import math In [2]: f=math.floor(2.3) In [3]: f Out[3]: 2.0 What is the safest w...

using SWIG with C++

HI all I am trying to use SWIG to export C++ code to Python. The C sample I read on the web site does work but I have problem with C++ code. Here are the lines I call swig -c++ -python SWIG_TEST.i g++ -c -fPIC SWIG_TEST.cpp SWIG_TEST_wrap.cxx -I/usr/include/python2.4/ gcc --shared SWIG_TEST.o SWIG_TEST_wrap.o -o _SWIG_TEST.so -lstdc+...

How to do a group by/count(*) pr year, month and day in django based on a datetime database field?

I have a table describing files with a datetime field. I want to somehow create a report that gives me the number of files grouped by each year, number of files grouped by each year and month and number of files grouped by each year, month and day. I just want records where count(*) > 0. Preferably using the ORM in django or if that`s no...

Python: How to "perfectly" override a dict

How can I make as "perfect" a subclass of dict as possible? The end goal is to have a simple dict in which the keys are lowercase. It would seem that should be some tiny set of primitives I can override to make this work, but all my research and attempts have made it seem like this isn't the case: If I override __getitem__/__setitem__...

Add to python path mac os x

I thought import sys sys.path.append("/home/me/mydir") is appending a dir to my pythonpath if I print sys.path my dir is in there. Then I open a new command and it is not there anymore. But somehow Python cant import modules I saved in that dir. What Am I doing wrong? I read .profile or .bash_profile will do the trick. Do I hav...

object_detail() got multiple values for keyword argument 'queryset' while inputting only one

from django.conf.urls.defaults import * from django.conf import settings from Website.Blog.models import Post # Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() index = { 'queryset': Post.objects.all(), 'date_field': 'created_on', 'template_name':...

Problems with process created using 32bit python on Debian 5.0 IA-64

So, the problem is with creating processes - all of them immediately return with exit code -9. I tried to use subprocess.Popen module and os.popen2, os.system and some other. Nothing helps. I'm using python 2.5. I have a python binary executable built on 32bit platform with 32bit python using pyinstaller. This is very important and I kn...

Library for electrical network simulation

I'm searching for a free and open source library for electrical network simulation. In (Per preference order) : Python, Ruby, Javascript, PHP, C++ (with Qt if it exist) or bash (ahah). Do you know one ? ...

Check if a package is installed

Hello, Is there an elegant and more Python-like way to check if a package is installed on Debian? In a bash script, I'd do: dpkg -s packagename | grep Status Suggestions to do the same in a Python script? Thanks, ...

Django, Python, Mysql

This is the settings.py file for python. I set mysql up via macports (mysql5 & mysqldb) The problem is that I am unsure if I have settings.py configuration correct before I sync the db. Should the PORT be left blank? I believe it should. I know on my Mamp install I have it set to 3306. Thanks.... DATABASES = { 'default': { '...

ModelAdmin thread-safety/caching issues

Ultimately, my goal is to extend Django's ModelAdmin to provide field-level permissions—that is, given properties of the request object and values of the fields of the object being edited, I would like to control whether or not the fields/inlines are visible to the user. I ultimately accomplished this by adding a can_view_field() method ...

Python - difference between os.access and os.path.exists?

def CreateDirectory(pathName): if not os.access(pathName, os.F_OK): os.makedirs(pathName) versus: def CreateDirectory(pathName): if not os.path.exists(pathName): os.makedirs(pathName) I understand that os.access is a bit more flexible since you can check for RWE attributes as well as path existence, but is th...

Does gzip work on the development server?

Does gzip work on the python development server for appengine? How can I test this in the future? Note: I've used Firebug to look at my HTTP requests from the browser, and I see that Accept-Encoding is set to "gzip,deflate". ...

Django model group by datetime's date

Hello Assume I have a such model: class Entity(models.Model): start_time = models.DateTimeField() I want to regroup them as list of lists which each list of lists contains Entities from the same date (same day, time should be ignored). How can this be achieved in a pythonic way ? Thanks ...

Extended call-syntax: Passing parameters

Hi, I have a function that looks like this: def getColumn(self, name, type, **args): Now I would like to have a function def getColumns(self, columns) where I can pass a tuple that contains a tuple, where each entry in that tuple represents the arguments to be passed go getColumn. However, I'd like not to have to use named paramete...

Exception: Failed to start new browser session: Error while launching browser Selenium in Python

I am getting the following errors when running a basic Selenium test script in Python: ====================================================================== ERROR: test_untitled (__main__.TestTesting) ---------------------------------------------------------------------- Traceback (most recent call last): File "TestTesting.py", line ...

Python if statements question

I've tried Google, but I can't find the answer to this simple question. I hate myself for not being able to figure this out, but here we go. How do I write an if statement with or in it? For example: if raw_input=="dog" or "cat" or "small bird": print "You can have this animal in your house" else: print "I'm afraid you can't h...

What purpose does a python backend serve?

I am primarily a PHP developer, and I have been browsing the source code of a few open-source applications recently(Mozilla Bespin in particular), to find that some of them use a Python "back-end." I was just wondering what the purpose of this back-end is. I am assuming it is the same thing as the model in an MVC framework and is used ...

How to get the IPv6 address of an interface under linux

Hi there, Do you know how I could get one of the IPv6 adress of one of my interface in python2.6. I tried something with the socket module which lead me nowhere. Thanks. ...