python

Does Python's heapify() not play well with list comprehension and slicing?

I found an interesting bug in a program that I implemented somewhat lazily, and wondered if I'm comprehending it correctly. The short version is that Python's heapq implementation doesn't actually order a list, it merely groks the list in a heap-centric way. Specifically, I was expecting heapify() to result in an ordered list that facili...

Accessing a PHP-set memcache key from Python

I'm storing a value in memcached using PHP's Memcache extension and trying to retrieve it in a daemon written in Python sitting behind my webapp. But, it keeps returning None or throwing "local variable 'val' referenced before assignment". I'm sure I'm looking for the same key, and there's only one mc server available to either app (lo...

Can a slow network cause a Python app to use *more* CPU?

Let's say we have a system like this: ______ { application instances ---network--- (______) { application instances ---network--- | | requests ---> load balancer { application instances ---network--- | ...

What to do after starting simple_server?

For some quick background, I'm an XHTML/CSS guy with some basic PHP knowledge. I'm trying to dip my feet into the Python pool, and so far understand how to start simple_server and access a simple Hello World return in the same .py file. This is the extent of what I understand though, heh. How do I integrate the simple_server and your ba...

Overriding "+=" in Python

Is it possible to override += in Python? ...

Chat comet site using python and twisted

i want to build a site similar to www.omegle.com. can any one suggest me some ideas. I think its built usning twisted , orbiter comet server. ...

Easiest way to persist a data structure to a file in python?

Let's say I have something like this: d = { "abc" : [1, 2, 3], "qwerty" : [4,5,6] } What's the easiest way to progammatically get that into a file that I can load from python later? Can I somehow save it as python source (from within a python script, not manually!), then import it later? Or should I use JSON or something? ...

orbited coment server problem

i tried installing orbited on vista . but i get following errror when i try to run the orbited server.When i type on twisted cmd prompt orbited i get following o/p. C:\>orbited Traceback (most recent call last): File "C:\Python26\scripts\orbited-script.py", line 8, in load_entry_point('orbited==0.7.9', 'console_scripts', 'orbite...

Retrieving a tuple from a collection of tuples based on a contained value

I have a data structure which is a collection of tuples like this: things = ( (123, 1, "Floogle"), (154, 33, "Blurgle"), (156, 55, "Blarg") ) The first and third elements are each unique to the collection. What I want to do is retrieve a specific tuple by referring to the third value, eg: >>> my_thing = things.get( value(3) == "Blur...

MS Access library for python

Is there a library for using MS Access database in python? The win32 module is not as easy as the MySQL library. Is there a simpler way to use MS Access with Python? ...

How to use dict in python?

10 5 -1 -1 -1 1 1 0 2 ... If I want to count the number of occurrences of each number in a file, how do I use python to do it? ...

PHP Sockets or Python, Perl, Bash Sockets?

I'm trying to implement a socket server that will run in most shared PHP hosting. The requirements are that the Socket server can be installed, started and stopped from PHP automatically without the user doing anything. It doesn't matter what language the socket server is written in, as long as it will run on the majority of shared host...

How to sort on number of visits in Django app?

In Django (1.0.2), I have 2 models: Lesson and StatLesson. class Lesson(models.Model): contents = models.TextField() def get_visits(self): return self.statlesson_set.all().count() class StatLesson(models.Model): lesson = models.ForeignKey(Lesson) datetime = models.DateTimeField(default=datetime.datetime.now()) ...

How to parse for tags with '+' in python

I'm getting a "nothing to repeat" error when I try to compile this: search = re.compile(r'([^a-zA-Z0-9])(%s)([^a-zA-Z0-9])' % '+test', re.I) The problem is the '+' sign. How should I handle that? ...

Problem deploying Python program (packaged with py2exe)

I have a problem: I used py2exe for my program, and it worked on my computer. I packaged it with Inno Setup (still worked on my computer), but when I sent it to a different computer, I got the following error when trying to run the application: "CreateProcess failed; code 14001." The app won't run. (Note: I am using wxPython and the mult...

Resize images in directory

Hey, I have a directory full of images that I would like to resize to around 60% of their original size. How would I go about doing this? Can be in either Python or Perl Cheers Eef ...

Python and PGP/encryption

i want to make a function using python to encrypt password by the public key. at the user end i need to install PGP software which will generate the key pair .i want to use public key only for encryption and private key for decryption. The problem is coming with the encryption function(how to use key for encryption) and also in pgp insta...

Display row count from another table in Django

Hello. I have the following classes in my models file class HardwareNode(models.Model): ip_address = models.CharField(max_length=15) port = models.IntegerField() location = models.CharField(max_length=50) hostname = models.CharField(max_length=30) def __unicode__(self): return self.hostname class Subscripti...

How do I link a combo box and a command button?

This is my combo box code: self.lblname = wx.StaticText(self, -1,"Timeslot" ,wx.Point(20,150)) self.sampleList = ['09.00-10.00','10.00-11.00','11.00-12.00'] self.edithear=wx.ComboBox(self, 30, "", wx.Point(150,150 ), wx.Size(95, -1), self.sampleList, wx.CB_DROPDOWN) and this is my command button code: def OnClick(self,event): s...

wxPython SplitterWindow does not expand within a Panel

Hi, I'm trying a simple layout and the panel divided by a SplitterWindow doesn't expand to fill the whole area, what I want is this: [button] <= (fixed size) --------- TEXT AREA } ~~~~~~~~~ <= (this is the splitter) } this is a panel TEXT AREA } The a...