python

Is there any way to affect locals at runtime?

I actually want to create a new local. I know it sounds dubious, but I think I have a nice use case for this. Essentially my problem is that this code throws "NameError: global name 'eggs' is not defined" when I try to print eggs: def f(): import inspect frame_who_called = inspect.stack()[1][0] frame_who_called.f_locals['egg...

Editing MP3 metadata on a file-like object in Python?

We're generating MP3 files on the fly in Python, and need to edit the ID3 headers in-memory using a file-like object. All the ID3 libraries on PyPI appear to require you to pass a filesystem path as a string. I find this rather frustrating! Writing our generated MP3 out to disk (or ramdisk) just to add ID3 tags is unacceptable for a ...

Python object intialization bug. Or am I misunderstanding how objects work?

1 import sys 2 3 class dummy(object): 4 def __init__(self, val): 5 self.val = val 6 7 class myobj(object): 8 def __init__(self, resources): 9 self._resources = resources 10 11 class ext(myobj): 12 def __init__(self, resources=[]): 13 #myobj.__init__(self, resources) 14 ...

C++ or Python for C# programmer?

I am a corporate C# programmer. I found some time to invest into myself and stumbed upon a dilemma. Where to go from now? C#/.NET is easy to learn, develop for, etc. In future I would want to apply to Microsoft or Google, and want to invest spare time wisely, so what I will learn will flourish in future. So: Python or C++ for a C# progr...

Convert Variable Name to String?

I would like to convert a python variable name into the string equivalent as shown. Any ideas how? var = {} print ??? # Would like to see 'var' something_else = 3 print ??? # Would print 'something_else' ...

Can I sort text by its numeric value in Python?

I have dict in Python with keys of the following form: mydict = {'0' : 10, '1' : 23, '2.0' : 321, '2.1' : 3231, '3' : 3, '4.0.0' : 1, '4.0.1' : 10, '5' : 11, # ... etc '10' : 32, '11.0' : 3, '11.1' : 243...

Does a Python 3 SOAP client module exist?

I couldn't find one that works with Python 3.1. Any suggestions for a WSDL-consuming Python 3 SOAP client module/library? ...

Creating a program to be broadcasted by avahi

I'm trying to write a program that outputs data that can be served over a network with avahi. The documentation I've looked at seems to say I have to register the service with dbus and then connect it to avahi, but the documentation to do this is pretty sparse. Does anyone know of good documentation for it? I've been looking at these: ...

Attribute as dict of lists using middleman table with SQLAlchemy

My question is about SQLAlchemy but I'm having troubles explaining it in words so I figured I explain it with a simple example of what I'm trying to achieve: parent = Table('parent', metadata, Column('parent_id', Integer, primary_key=True), Column('name', Unicode), ) parent_child = Table('parent_child', metadata, Column('par...

Calling a RPC function in a running Windows service (process) using Python

I have Windows service (acts as a server) that I want to test using Python scripts. This service is written in C++ and exposes several RPC functions that other services consume. I want to mock those other services using my Python program and call those RPC functions from the script. This is the first stage. The second stage happens when ...

How to remove these duplicates in a list (python)

biglist = [ {'title':'U2 Band','link':'u2.com'}, {'title':'ABC Station','link':'abc.com'}, {'title':'Live Concert by U2','link':'u2.com'} ] I would like to remove the THIRD element inside the list...because it has "u2.com" as a duplicate. I don't want duplicate "link" element. What is the most efficient code to do t...

Need a workaround: Python's select.select() doesn't work with subprocess' stdout?

From within my master python program, I am spawning a child program with this code: child = subprocess.Popen(..., stdout=subprocess.PIPE, stdin=subprocess.PIPE) FWIW, the child is a PHP script which needs to communicate back and forth with the python program. The master python program actually needs to listen for communication from s...

How to transform Python 3 script to Mac OS application bundle?

Is there currently a way to create an application bundle from Py3k script? py2app uses Carbon package and therefore, as far as I understand, cannot be ported to py3k - Carbon development was terminated. ...

How to trim a list in Python

Suppose I have a list with X elements [4,76,2,8,6,4,3,7,2,1...] I'd like the first 5 elements. Unless it has less than 5 elements. [4,76,2,8,6] How to do that? ...

Jump to Model/View/Controller in emacs

Most rails modes for emacs have this kind of functionality. You are in a controller file over a function "kaboosh" in "app/controller/bla.rb" and with a keyboard shortcut you switch to "app/views/kaboosh.erb" or to app/models/bla.rb". A similar functionality exists for .c and .h files using ff-find-other-file. I checked jump.el and fin...

How to write an efficient hit counter for websites

I want to write a hit counter script to keep track of hits on images on a website and the originating IPs. Impressions are upwards of hundreds of thousands per day, so the counters will be incremented many times a second. I'm looking for a simple, self-hosted method (php, python scripts, etc.). I was thinking of using MySQL to keep tra...

Python instance method making multiple instance method calls

Here is some snippet code. I have tested the methods listed and they work correctly, yet when I run and test this method (countLOC) it only seems to initialize the first variable that has an instance method call (i = self.countBlankLines()). Anyone know the obvious reason I'm obviously missing? def countLOC(self): i = self.count...

Python: How to print a class or objects of class using print()?

I am learning the ropes in Python. When I try to print an object of class Foobar using the print() function, I get an output like this: <__main__.Foobar instance at 0x7ff2a18c> Is there a way I can set the printing behaviour (or the string representation) of a class and its objects? For instance, when I call print() on a class object,...

Resource scheduling application

I'm trying to implement an application that coordinates multiple users who are scheduling exclusive resources. The schedule data must maintain strong consistency over a network with a single master node. The scheduled resources could be anything from a conference room to a worker on a job site. We assume the conference room cannot be sc...

Python Documentation Refers You To Docs for "the C function wait." Where is that?

There's multiple places in the Python documentation where it refers you to the C function "wait." For instance: "The exit status for the command can be interpreted according to the rules for the C function wait," in the commands and subprocess modules. Where can I find this documentation? Apparently my Google-fu is not strong enough, or...