python

Is there a Python library than can simulate network traffic from different addresses

Is there a python library out there than can allow me to send UDP packets to a machine (sending to localhost is ok) from different source addresses and ports? I remember that one existed, but can't find it anymore. ...

python "'NoneType' object has no attribute 'encode'"

I wrote this tiny Python snippet that scrapes a feed and prints it out. When I run the code, something in the feed triggers the error message you see here as my question. Here's the complete console output on error: > Traceback (most recent call last): > File "/home/vijay/ffour/ffour5.py", > line 20, in <module> > myfeed() File ...

Django serialize to json

I have a django model (schedule) with the class of entity, that is the parent of activity, that is the parent of event. class Entity(models.Model): <...> class Activity(models.Model): <...> team_entity = models.ForeignKey(Entity) <...> class Event(models.Model): <...> activity = models.ForeignKey(Activity) ...

Add class to Django label_tag() output

I need some way to add a class attribute to the output of the label_tag() method for a forms field. I see that there is the ability to pass in an attrs dictionary and I have tested it in the shell and I can do something like: for field in form: print field.label_tag(attrs{'class':'Foo'}) I will see the class='Foo' in my output, ...

SQLAlchemy DateTime timezone

SQLAlchemy's DateTime type allows for a timezone=True argument to save a non-naive datetime object to the datbase, and to return it as such. Is there any way to modify the timezone of the tzinfo that SQLAlchemy passes in so it could be, for instance, UTC? I realize that I could just use default=datetime.datetime.utcnow; however, this is ...

can cherrypy receive multipart/mixed POSTs out of the box?

We're receiving some POST data of xml + arbitrary binary files (like images and audio) from a device that only gives us multipart/mixed encoding. I've setup a cherrypy upload/POST handler for our receiver end. I've managed to allow it to do arbitrary number of parameters using multipart/form-data. However when we try to send the multi...

Best way to create a simple python web service

I've been using python for years, but I have little experience with python web programming. I'd like to create a very simple web service that exposes some functionality from an existing python script for use within my company. It will likely return the results in csv. What's the quickest way to get something up? If it affects your sugges...

Why does gethostbyaddr(gethostname()) return my IPv6 IP?

I'm working on making a simple server application with python, and I'm trying to get the IP to bind the listening socket to. An example I looked at uses this: HOST = gethostbyaddr(gethostname()) With a little more processing after this, it should give me just the host IP as a string. This should return the IPv4 address. But when I ru...

How to get current time in Python

Can anybody tell what is the module/method used to get current time ??? ...

Big Web 2.0 sites written in Python?

Hulu, Twitter, Techcrunch, etc are written in Ruby. Yahoo, Facebook, and tons of big social networks are written in PHP. But what are some big top-name enterprise sites written in Python? I am going to spend my time investing in either Python (w/ Django) or Ruby (w/ Rails) to create a data-intensive web application that has a personali...

URLs: Binary Blob, Unicode or Encoded Unicode String?

I wish to store URLs in a database (MySQL in this case) and process it in Python. Though the database and programming language are probably not this relevant to my question. In my setup I receive unicode strings when querying a text field in the database. But is a URL actually text? Is encoding from and decoding to unicode an operation...

Filtering away nearby points from a list

I half-answered a question about finding clusters of mass in a bitmap. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to filter the list removing points from the same cluster. Then when thinking about that step I found that the solution didn't jump ...

Java Servlet Filter Equivalent in Ruby [on Rails] and PHP ?

Not sure if the terminology is correct, but are there rough equivalents to Java Servlet Filters in Ruby and PHP ? Are they actual concrete classes ? I assume there is also a number of common web app libraries/frameworks in Python. Is there an equivalent there ? Thanks. === ADDENDUM === On the good advice of Kevin Davis, I just want t...

Cross Platform SWF Playback with Python?

I'm looking for different solutions to playing back SWF files on Windows, OSX and Linux using Python. Ideally I'd like to embed the player inside a wxPython frame/window. One possibility I'm investigating is the Mozilla XPCOM framework since its used by FireFox to load the Flash plugin within the browser. ...

What does "|" sign mean in Django?

I often see something like that: something.property|escape something is an object, property is it's string property. escape - i don't know :) What does this mean? And what min python version it is used in? EDIT: The question was asked wrongly, it said "What does | mean in Python", so the bitwise or answers are correct, but irrelevan...

What does the “|” sign mean in Python?

This question originally asked (wrongly) what does "|" mean in Python, when the actual question was about Django. That question had a wonderful answer by Triptych I want to preserve. ...

How can I use Numerical Python with Python 2.6

I'm forced to upgrade to Python 2.6 and am having issues using Numerical Python (Numpy) with Python 2.6 in windows. I'm getting the following error... Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> from numpy.core.numeric import array,dot,all File "C:\svn\svn_urbansim\UrbanSimDev\Builds\working\urban...

Python: C++-like stream input

Hi! Is there a pythonic way of reading - say - mixed integer and char input without reading the whole input at once and without worrying about linebreaks? For example I have a file with whitespace-separated data of which I only know that there are x integers, then y chars and then z more integers. I don't want to assume anything about l...

Process size in XP from Python

I have a python script that can approach the 2 GB process limit under Windows XP. On a machine with 2 GB physical memory, that can pretty much lock up the machine, even if the Python script is running at below normal priority. Is there a way in Python to find out my own process size? Thanks, Gerry ...

Why does Python's string.printable contains unprintable characters?

I have two String.printable mysteries in the one question. First, in Python 2.6: >>> string.printable '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~ \t\n\r\x0b\x0c' Look at the end of the string, and you'll find '\x0b\x0c' sticking out like a sore-thumb. Why are they there? I am usin...