python

Python Language Nuances

Possible Duplicate: Common Pitfalls in Python I'm learning Python and I come from a diverse background of programming languages. In the last five years, I've written quite a bit of Java, C++, VB.Net, and PHP. As many of you might agree, once you learn one programming language, learning another is just a mater of learning the d...

to add column values in a specific manner in a csv file using python

hi, i have a csv file similar to the following : title title2 h1 h2 h3 ... l1.1 l1 1 1 0 l1.2 l1 0 1 0 l1.3 l1 1 0 1 l2.1 l2 0 0 1 l2.2 l2 1 0 1 l3.1 l3 0 1 1 l3.2 l3 1 1 0 l3.3 l3 1 1 0 l3.4 l3 1 1 0 i want to be ab...

index in google app engine application

can anyone tell me how to do indexing in gql ...

Matching all records in a datastore query

Is there a way to substitute: def get_objects(attr1,attr2,..): objects = Entities.all() if attr1 != None: objects.filter('attr1',attr1) if attr2 != None: objects.filter('attr2',attr2) .... return objects With a single query: Entities.all().filter('attr1',attr1).filter('attr2',attr2) By using som...

expanding the image veiwer example of pyqt or QT

hello im trying to expand the pyqt image veiwer example to have a feature of drawing over images i added a couple of tested functions that takes mouse events and draw over image in the image viewer example my i chosed my painter to paint over imageLabel's pixmap def mousMoveEvent(self,event): painter = QtGui.QPainter(self.imageLab...

need help in understanding the code

class Problem: """ This class outlines the structure of a search problem, but doesn't implement any of the methods (in object-oriented terminology: an abstract class). """ def getStartState(self): """Returns the start state for the search problem""" sahan.raiseNotDefined() Now I want to know th...

Why is using thread locals in Django bad?

I am using thread locals to store the current user and request objects. This way I can have easy access to the request from anywhere in the programme (e.g. dynamic forms) without having to pass them around. To implement the thread locals storage in a middleware, I followed a tutorial on the Django site: http://code.djangoproject.com/wi...

What is the Pythonic Way of Differentiating Between a String and a List?

For my program I have a lot of places where an object can be either a string or a list containing strings and other similar lists. These are generally read from a JSON file. They both need to be treated differently. Right now, I am just using isinstance, but that does not feel like the most pythonic way of doing it, so does anyone have a...

Python not loading a specific function

Hi, I just run into a problem with the hamster's codebase where a module is loaded with one function and not the other. It's not my code, so I don't know many details, but I'd really like to learn how can such situation arise. There is a module called hamster which includes i18n.py which has two functions: setup_i18n and C_. There is no...

Cross-platform addressing of the config file

Simple case I have a Python program that I intend to support on both *nix and Windows systems. The program must be configurable, at least globally. Is there a cross-platform way to address the configuration file? I.e. I want to write instead of import platform if platform.system() == "Windows": configFilePath = "C:\MyProgram\mainc...

What is the best way to publish RSS Feed on Facebook ?

What is the best way to publish an rss feed or a sitemap to facebook? I am using google app engine as the platform and the python language ...

How to get sorted results in MongoKit?

How can I perform query like: db.articles.find().sort({created_at: -1}).limit(5); in MongoKit driver? Perhaps I'm blind, but I can't find it in manual. I want to retrieve 5 last products ordered by 'created_at'. MongoKit offers to sort result list (it's more then 2000 items) and slice it. It's unaccepable, I want to sort() and limit() o...

What is the dominant reason for Python's popularity as a systems and application programming language?

Coming from an enterprise systems background (think Java and Windows) - I'm surprised at the popularity of python as a prototyping language and am trying to put my finger on the precise reason for this. Examples include being listed as one of the four languages Google uses. Possible reasons include: enables rapid systems application pr...

Determine height of Coffee in the pot using Python imaging

This is a bit of a funny question but... We have a web-cam in our office kitchenette focused at our coffee maker. The coffee pot is clearly visible. Both the location of the coffee pot and the camera are static. Is it possible to calculate the height of coffee in the pot using image recognition? I've seen image recognition used for quit...

Inserting language characters in Django

I am following the link http://code.google.com/p/django-multilingual-model/ Basically i am trying to insert hindi characters into mysql db I have created the files in the test directory as in the above said link and using django version 1.1 an dpython version is 2.4.3 I geta error message as the following. from testlanguages import ...

Calling python code from VSTO excel addin

Hi, I am working on an excel2007 plugin in VSTO and am using VB for coding it. One of the item in the plugin is the button, pressing which should give a call to a python program which will add some data to the current worksheet. I would like to know 1 How can i call the python function from the VBA code 2 pass the active workbook to thi...

Django CMS logo change

hey guys, i was wondering if there was a way to change the Django CMS logo, for my own company logo ? ...

Strange Python behavior from inappropriate usage of 'is not' comparison?

I (incorrectly?) used 'is not' in a comparison and found this curious behavior: >>> a = 256 >>> b = int('256') >>> c = 300 >>> d = int('300') >>> >>> a is not b False >>> c is not d True Obviously I should have used: >>> a != b False >>> c != d False But it worked for a long time due to small-valued test-cases until I happened to u...

Python images display Django

Since my last question here: http://stackoverflow.com/questions/3166221/python-images-display I understood that from all the answers I got the glob.glob could be the only one in the direction I need. However where I am stuck right now is here: I can create a list with all the filenames in my media directory by using glob.glob: all = ...

Using PIL and NumPy to convert an image to Lab array, modify the values and then convert back

I am trying to convert a PIL image into an array using NumPy. I then want to convert that array into Lab values, modify the values and then convert the array back in to an image and save the image. I have the following code: import Image, color, numpy # Open the image file src = Image.open("face-him.jpg") # Attempt to ensure image is ...