python

How to impress developers with IronPython/Python

I need an IronPython\Python example that would show C#/VB.NET developers how awesome this language really is. I'm looking for an easy to understand code snippet or application I can use to demo Python's capabilities. Any thoughts? ...

Meaning of using commas and underscores with Python assignment operator?

Reading thru Peter Norvig's Solving Every Sudoku Puzzle essay, I've encounted a few Python idioms that I've never seen before. I'm aware that a function can return a tuple/list of values, in which case you can assign multiple variables to the results, such as >>> def f(): ... return 1,2 >>> a, b = f() But what is the meaning of...

Which DHT implementations are compatible Python 3.x?

Following on from this question about DHTs in Python, my question is the same except that I'm developing on Python 3.x - I only want to know about implementations of the DHT concept which are known to be stable on Python 3. There seem to be plenty of DHT products, for example Khashmir, however as far as I'm aware nobody has bothered to...

Use a Descriptor (EDIT: Not a single decorator) for multiple attributes?

Hi, Python 2.5.4. Fairly new to Python, brand new to decorators as of last night. If I have a class with multiple boolean attributes: class Foo(object): _bool1 = True _bool2 = True _bool3 = True #et cetera def __init__(): self._bool1 = True self._bool2 = False self._bool3 = True #et ...

Is there code out there to subclass set in Python for big xranges?

I'm trying to write some Python code that includes union/intersection of sets that potentially can be very large. Much of the time, these sets will be essentially set(xrange(1<<32)) or something of the kind, but often there will be ranges of values that do not belong in the set (say, 'bit 5 cannot be clear'), or extra values thrown in. F...

python: list vs tuple, when to use each?

In Python, when should you use lists and when tuples? Sometimes you don't have a choice, for example if you have "hello %s you are %s years old" % x then x must be a tuple. But if I am the one who designs the API and gets to choose the data types, then what are the guidelines? ...

convert decimal to hex python

Hi All, Im building a server in python, i need to convert a decimal value to hex like this : let's say the packet start by 4 bytes which define the packet lenght : 00 00 00 00 if the len(packet) = 255 we would send : 00 00 00 ff Now my problem is that sometimes the packet is bigger than 256 as for example 336, then it would be : 00 00...

Combining two record arrays

I have two Numpy record arrays that have exactly the same fields. What is the easiest way to combine them into one (i.e. append one table on to the other)? ...

Python OCR library or handwritten character recognition engine

Could you recommend some python libraries or source code for OCR and handwritten character recognition? ...

Python/Django Model overriding the cleaned data

Hello I am currently working on a django project, in one of my Models I have a file upload and image upload, with the parameters of these two fields both are set to blank=True, however there is a stipulatation with this and it is that field can only be blank if one of the two is not, so for example, if the imagefield is complete then the...

python/scons help: maintaining lists of source files + object files

I know next to nothing about Python and I'm using scons. (if you're reading this and know Python but not scons, you can probably help me!) Could someone help me out and explain how I could have a variable that contains two lists? I'm not sure of the syntax. Is this right? buildinfo = // how do you initialize a variable that has fields?...

receving socket python

Hi Alls, Im using the SocketServer module for a tcp server. I'm experiencing some issue here with the recv() function, because the incoming packets always have a different size, so if i specify recv(1024) (i tried with bigger value, and smaller), it get stock after 2 or 3 requests because the packet length will be smaller (i think), and...

Automatic font recognition with Python

As you may have heard of, there is an online font recognition service call WhatTheFont I'm curious about the tech behind this tool. I think basically we can seperate this into two parts: Generate images from font files of various format, refer to http://www.fileinfo.com/filetypes/font for a list of font file extensions. Compare submit...

Class Objects and comparing specific attributes

Hi all I have the following code. class person(object): def __init__(self, keys): for item in keys: setattr(self, item, None) def __str__(self): return str(self.__dict__) def __eq__(self, other) : return self.__dict__ == other.__dict__ Now I want to take this code and only do...

Does anyone have examples of integrating Haystack/Solr with Django?

Note: This question originally applied to Xapian, but due to cross-platform issues and poor understanding of Xapian I (our team) chose Solr instead. I'm looking for snippets, tricks, tips, links, and anything to watch out for (gotchas). My technology stack includes: MySQL 5.1 (Not really pertinent) Red Hat and Windows configurations w...

What does 'u' mean in a list?

This is the first time I've came across this. Just printed a list and each element seems to have a u in front of it i.e. [u'hello', u'hi', u'hey'] What does it mean and why would a list have this in front of each element? As I don't know how common this is, if you'd like to see how I came across it, I'll happily edit the post...

getting started with django-cms: error on page_submit_row

I am getting started with django-cms and I am facing an exception when I try to edit a page in the admin inteface. A TemplateSyntaxError exception is raised due to the {% page_submit_row %} templatetag. TemplateSyntaxError at /admin/cms/page/1/ Caught an exception while rendering: admin/page_submit_line.html Request Method: GET Req...

How can I sort a coordinate list for a rectangle counterclockwise?

I need to sort a coordinate list for a rectangle counterclockwise, and make the north-east corner the first coordinate. These are geographic coordinates (i.e. Longitude, Latitude) in decimal form.1 For example, here are the 4 corners of a rectangle, starting with the north-west corner and moving clockwise: [ { "lat": 34.495239, "lng"...

Run nosetests with warnings as errors?

When running nosetests from the command line, how do you specify that 'non-ignored' warnings should be treated as errors? By default, warnings are printed, but not counted as failures: [snip]/service/accounts/database.py:151: SADeprecationWarning: Use session.add() self.session.save(state) [snip]/service/accounts/database.py:97: SADe...

PyQt: translating standard buttons

How can I easily translate standard buttons (Yes, No) from QMessageBox? I can't use self.tr on those arguments, so I would like to achieve it in some other simple way. Do I have to use whole translation system? ...