python

Unable to parse the output from HTTPConnection.debuglevel

Hi, I am trying to programmability check the output of a tcp stream. I am able to get the results of the tcp stream by turning on debug in HTTPConnection but how do I read the data and evaluate it with say a regular expression. I keep getting "TypeError: expected string or buffer". Is there a way to convert the result to a string? tha...

Amazon SNS with Python

Trying to get started with Amazon SNS. API is very simple REST. I seem to be hung up on the signature part of the call. The API example is: http://sns.us-east-1.amazonaws.com/ ?Subject=My%20first%20message &TopicArn=arn%3Aaws%3Asns%3Aus-east-1%3A698519295917%3AMy-Topic &Message=Hello%20world%21 &Action=Publish &SignatureVersion=2 &Signa...

Tkinter unexpected behaviour

Hi everyone, I've been writing a long GUI in Python using Tkinter. One thing that I don't understand is why I can't bind events to widgets in a loop. In the code below, binding works well if I do it manually (commented out code) but not in a for loop. Am I doing something wrong? import Tkinter root = Tkinter.Tk() b1 = Tkinter.Button(...

How to implement a FIFO queue that supports namespaces

I'm using the following approach to handle a FIFO queue based on Google App Engine db.Model (see this question). from google.appengine.ext import db from google.appengine.ext import webapp from google.appengine.ext.webapp import run_wsgi_app class QueueItem(db.Model): created = db.DateTimeProperty(required=True, auto_now_add=True) ...

Python+Celery: ignore task results on a per-invocation basis?

Is it possible to ignore task results on a per-invocation basis? For example, so I can ignore the results of tasks when they are being run during a web request, but wait for the result (which might have, eg, debug info) when I'm running the task interactively? I know that Tasks have the ignore_result flag, but I'm wondering specificall...

Are Python functions "compile" and "compiler.parse" safe (sandboxed)?

I plan to use those functions in web-environment, so my concern is if those functions can be exploited and used for executing malicious software on the server. Edit: I don't execute the result. I parse the AST tree and/or catch SyntaxError. This is the code in question: try: #compile the code and check for syntax errors compil...

Convert File to HEX String Python

How would I convert a file to a HEX string using Python? I have searched all over Google for this, but can't seem to find anything useful. ...

is there a limit to the (CSV) filesize that a Python script can read/write?

I will be writing a little Python script tomorrow, to retrieve all the data from an old MS Access database into a CSV file first, and then after some data cleansing, munging etc, I will import the data into a mySQL database on Linux. I intend to use pyodbc to make a connection to the MS Access db. I will be running the initial script in...

Boost Python and shared_ptr upcast

Sample code for dll/pyd: #include <boost/python.hpp> #include <iostream> class Base { public: Base() {} public: int getValue() { return 1; } }; typedef boost::shared_ptr<Base> BasePtr; class ParentA : public Base { public: ParentA() : Base() {} }; typedef boost::shared_ptr<ParentA> ParentAPtr; class Collector { public: Collect...

Mark File For Removal from Python?

In one of my scripts, I need to delete a file that could be in use at the time. I know that I can't remove the file that is in use until it isn't anymore, but I also know that I can mark the file for removal by the Operating System (Windows XP). How would I do this in Python? ...

Py2exe with Tkinter

I'm trying to convert a basic tkinter GUI program to an .exe using py2exe. However I've run into an error using the following conversion script. # C:\Python26\test_hello_con.py py2exe from distutils.core import setup import py2exe setup(windows=[r'C:\Python26\py2exe_test_tk.py']) C:\Python26\py2exe_test_tk.py is the following code ...

Why this request doesn't work ?

I want to make a simple stupid twitter app using Twitter API. If I request this page from my browser it does work: http://search.twitter.com/search.atom?q=hello&amp;rpp=10&amp;page=1 but if I request this page from python using urllib or urllib2 most of the times it doesn't work: response = urllib2.urlopen("http://search.twitter.com...

How can I ensure that my Python regular expression outputs a dictionary?

I'm using Beej's Python Flickr API to ask Flickr for JSON. The unparsed string Flickr returns looks like this: jsonFlickrApi({'photos': 'example'}) I want to access the returned data as a dictionary, so I have: photos = "jsonFlickrApi({'photos': 'test'})" # to match {'photos': 'example'} response_parser = re.compile(r'jsonFlickrApi\...

Find all files in directory with extension .txt with python

How can I find all files in directory with the extension .txt in python? Thanks. UPDATE: Thanks everyone, wide variety of examples for the next person that searches for this. ...

AttributeError Exception raised when trying to bulk delete items in Django

I'm trying to bulk delete all of the comments on a dev instance of my Django website and Django is raising an AttributeException. I've got the following code on a python prompt: >>> from django.contrib.comments.models import Comment >>> Comment.objects.all().delete() Traceback (most recent call last): File "<console>", line 1, in <mo...

how to write udpate sql in python elixir

i'm using elixir as my orm for mysql database, and it's hard for me to write a update sql under elixir "update products set price=NULL where id>100" class Product(Entity): using_options(tablename='model_product') name = Field(Unicode(200)) en_name = Field(Unicode(200)) price ...

How do you pass multiple arguments to __setstate__?

I am doing deepcopy on a class I designed, which has multiple lists as attributes to it. With a single list, this is solvable by overriding getstate to return that list, and setstate to set that list, but setstate seems unable to take multiple parameters. How is this accomplished? ...

No Longer a question, please delete

No longer a question, please delete ...

Polymorphism in Python

class File(object): def __init__(self, filename): if os.path.isfile(filename): self.filename = filename self.file = open(filename, 'rb') self.__read() else: raise Exception('...') def __read(self): raise NotImplementedError('Abstract method') class FileA(Fi...

Python: determine length of sequence of equal items in list

I have a list as follows: l = [0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,2,2,2] I want to determine the length of a sequence of equal items, i.e for the given list I want the output to be: [(0, 6), (1, 6), (0, 4), (2, 3)] (or a similar format). I thought about using a defaultdict but it counts the occurrences of each item and accumulates i...