python

Emacs Python-Mode: Sending statements to a subprocess does not lead to REPL-style evaluation.

After selecting 1 + 1 and issuing python-send-region, my subprocess buffer shows no results. I have to evaluate print 1 + 1, instead. How can I force the python-send-* commands to print the value of the respective statements rather than echoing their stdout? ...

Get the executing file's path from an installed package?

If one installs a python package using setuptools, then executes a method in that package from a standard python script, is it possible to get the file path of the calling/executing file? For instance, the file I'm executing is /usr/foo/bar.py, which looks like this: import baz baz.get_current_path() # should print /usr/foo/bar.py an...

How to disable screen update in matplotlib

I have a loop that is adding a line to a plot on each iteration. Right now this is horribly slow as it seems to redraw the the whole graph each time. Is it possible to disable screen updates for a graph while it is being set up then re-enable them afterwards. Here's the code: for rr,dd in zip(angles,dists): if dd == inf: ...

youtube data api comment paging

Hi, I'm struggling a little bit with the syntax for iterating through all comments on a youtube video. I'm using the python and have found little documentation on the GetYouTubeVideoCommentFeed() function. What I'm really trying to do is search all comments of a video for an instance of a word and increase a counter (eventually the com...

The following code in python (and why)

I am learning python because it looks very nice and i know a bit of ruby and perl. The following is a C program to plot 3d points onto the screen. I used this as an example because it uses arrays, structures and function calls. I left out classes because i believe that sort of (OOP) thing is used simularly in all languages (correct me i...

Django template and the locals trick

The django books gives the local trick in order to avoid to type a long list of parameters as context dictionnary http://www.djangobook.com/en/2.0/chapter04/ It recommends this to lazy programmers but points out some overhead which may have an impact on performance. I would like to know if some of you are using the locals trick on real...

vim and python scripts debugging

Good day! Are there any ways to debug python scripts not leaving vim in *nix systems (executing the script, setting up breakpoints, showing variables in watch-list, etc)? Thanks for feedback. ...

Solr Facet Range with Integers

My index contains peoples information, name, age, phone email etc. I am faceting on Age. I group ages kinda like Date Range functionality. My ranges are: 0 to 10 11 to 20 21 to 30 31 to 40 etc etc When I do a query: ?q=*:*&facet=true&fq=age:[21+TO+30] It returns all the ages I want in the range 21 to 30, but ...

What is the standard sort order for Python release/version numbers?

Python's pip and easy_install follow some rules to sort packages by their release numbers. What are the rules for numbering beta/release/bugfix releases so these tools will know which is the newest? ...

Best python XMPP / Jabber client library?

What are your experiences with Python Jabber / XMPP client libraries? What do you recommend? ...

Python/Linux - A function callback every time a key is pressed (regardless of which window has focus)?

I want to write a programme (in python) on Linux (Ubuntu Linux 9.10) that will keep track of how many key presses per second/minute I make. This includes normal letter keys, and control/shift/space/etc. Is there some way to hook into X so that I can say "when a key is pressed call this function?". Since I want to have this running in th...

[python] How do I disable Nagle's algoritm for sockets?

Hi! I'm writing some python and are stuck at the moment. I think this "Nagle algoritm" is the problem since my packages are delayed some time for some reason to the client. I've tried this on both client and server but it doesn't seems to work (or there's another problem causing it): socketobj.setsockopt(socket.IPPROTO_TCP, socket.TCP_...

Django Admin app: building a dynamic list of admin actions

I am trying to dynamically build a list of admin actions using the get_actions() method on a ModelAdmin. Each action relates to a particular instance of another model, and as new instances may be added or removed, I want to make sure the list of actions reflects that. Here's the ModelAdmin: class PackageAdmin(admin.ModelAdmin): lis...

How to implement time event scheduler in python?

In python how to implement a thread which runs in the background (may be when the module loads) and calls the function every minute Monday to Friday 10 AM to 3 PM. For example the function should be called at: 10:01 AM 10:02 AM 10:03 AM . . 2:59 PM Any pointers? Environment: Django Thanks ...

How to properly remove a specific ManyToMany relationship?

I have a ManyToMany relationship with one of my Models. On deleting a child, I want to remove the relationship but leave the record as it might be being used by other objects. On calling the delete view, I get an AttributeError error: Exception Value: 'QuerySet' object has no attribute 'clear' This is my models.py: class Feed(...

How to add a variable to the module I import from?

What I want to do is something like this: template.py def dummy_func(): print(VAR) # more functions like this to follow fabfile.py # this gets called by fabric (fabfile.org) # safe to think of it as ant build.xml import template template.VAR = 'some_val' from template import * Namely I have a template module other modules shoul...

context within a query filter?

I have a very basic contact model. The model has the following fields: class Entry(models.Model): name = models.CharField(max_length=64, unique=False) organization = models.CharField(max_length=100, unique=False, blank=True, null=True) team = models.CharField(max_length=64, unique=False, blank=True, null=True) position ...

Running Django Tests with a Precommit Hook

Hello, I would like to run all my django tests using mercurial's precommit hook. Whenever a test fails the commit will be aborted. The goal is to block build-breaking commits as often as possible. edit: Ended up using the external script route. Here is the reletant portion of my hgrc: [hooks] precommit = python ./pinax/projects/lgr/m...

How do I chain object instantiation with its methods?

For example this chunk of code: new_log = ActivityLog(user=self.user, activity=activity) new_log.save() Can I chain it to be like new_log = ActivityLog(...).save() ? I believe I tried the above, but it doesn't work. Is there a way to make it a 1 liner? ...

Potential errors with my makeValidFilename function?

It is inspired by "How to make a valid Windows filename from an arbitrary string?", I've written a function that will take arbitrary string and make it a valid filename. My function should technically be an answer to this question, but I want to make sure I've not done anything stupid, or overlooked anything, before posting it as an ans...