This is one of my most common questions when I am coding Python (I was fed Perl as a baby and am forever trying to get rid of that affliction) and I wanted to put it out there on stack overflow so that next time I search for 'chomp python' on google, I get a useful answer.
...
I'm writing a url rewrite in django that when a person goes to http://mysite.com/urlchecker/http://www.google.com it sends the url: http://ww.google.com to a view as a string variable.
I tried doing:
(r'^urlchecker/(?P<url>\w+)/$', 'mysite.main.views.urlchecker'),
But that didn't work. Anyone know what I'm doing wrong?
Also, gene...
I have a string that is html encoded:
<img class="size-medium wp-image-113"
style="margin-left: 15px;" title="su1"
src="http://blah.org/wp-content/uploads/2008/10/su1-300x194.jpg&quot;
alt="" width="300" height="194" />
I want to change that to:
<img...
My friend produced a small proof-of-concept assembler that worked on x86. I decided to port it for x86_64 as well, but I immediately hit a problem.
I wrote a small piece of program in C, then compiled and objdumped the code. After that I inserted it to my python script, therefore the x86_64 code is correct:
from ctypes import cast, CFU...
In a latin-1 database i have '\222\222\223\225', when I try to pull this field from the django models I get back u'\u2019\u2019\u201c\u2022'.
from django.db import connection
(Pdb)
cursor = connection.cursor()
(Pdb)
cursor.execute("SELECT Password from campaignusers WHERE UserID=26")
(Pdb)
row = cursor.fetchone()
So I step into that an...
I'm starting a web project that likely should be fine with SQLite. I have SQLObject on top of it, but thinking long term here -- if this project should require a more robust (e.g. able to handle high traffic), I will need to have a transition plan ready. My questions:
How easy is it to transition from one DB (SQLite) to another (MySQ...
Using IMDbPy it is painfully easy to access movies from the IMDB site:
import imdb
access = imdb.IMDb()
movie = access.get_movie(3242) # random ID
print "title: %s year: %s" % (movie['title'], movie['year'])
However I see no way to get the picture or thumbnail of the movie cover. Suggestions?
...
I was looking at the Python documentation and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc.
Apart from the fact that some include stderr while others don't, what are the differences between them and when would you use each one? The documentation didn't really explain it very well.
...
I tried to import mechanize module to my python script like this,
from mechanize import Browser
But, Google appengine throws HTTP 500 when accessing my script.
To make things more clear, Let me give you the snapshot of my package structure,
root
....mechanize(where all the mechanize related files there)
....main.py
....app.yaml
....
How can I do remote debugging of a multi threaded Python application, running on an Embedded Linux based system, from Windows XP or Vista?
So far I have only come across PyScripter based remote debugging. How does it perform?
...
What's your preferred way of getting current system status (current CPU, RAM, free disk space, etc.) in Python? Bonus points for *nix and Windows platforms.
There seems to be a few possible ways of extracting that from my search:
Using a library such as PSI (http://www.psychofx.com/psi/trac/wiki/ -- that currently seems not actively d...
Is there any example code of a cpython (not IronPython) client which can call Windows Communication Foundation (WCF) service?
...
Hey guys,
I tried playing a .wav file using pyaudio. It works great on windows, but doesn't work in Ubuntu when another device is using sound.
The error is "IOError: [Errorno
Invalid output device (no default
output device)] -9996
Is there another library I could try to use? Another method?
...
Is it possible for me to see the amount of processor usage (% of maximum) that the current, python, app is using?
Scenario:
My host will allow me to run my app as long as it does not consume more then X% of the CPU power, so I would like it to 'keep an eye on itself' and slowdown. So how can I know how much CPU the app is using?
Targ...
When a webpage has moved to a new location, how do I show the moved web page AND return a 301 permanent redirect HTTP response status code in Django?
...
I'm trying to do the following in my Django template:
{% for embed in embeds %}
{% embed2 = embed.replace("<", "<") %}
{{embed2}}<br />
{% endfor %}
However, I always get an invalid block or some syntax error when I do anything like that (by that I mean {% %} code inside a loop). Python doesn't have {} to si...
How can I convert PDF files to HTML with Python?
I was thinking something alone the lines of what Google does (or seems to do) to index PDF files.
My final goal is to setup Apache to show the HTML for the PDF files, so anything leading me in that direction would also be appreciated.
...
So let's say I'm using Python 2.5's built-in default sqlite3 and I have a Django model class with the following code:
class SomeEntity(models.Model):
some_field = models.CharField(max_length=50, db_index=True, unique=True)
I've got the admin interface setup and everything appears to be working fine except that I can create two Som...
Is it possible to import a python file more than once in a python script because i run a loop back to my driver file in a function by using the import command but it only works once? thanks
edit: Resolved myself thanks
...
I'm currently working on a project were I had to wrap the C++ classes with Python to be able to script the program. So my specific experience also involved embedding the Python interpreter in our program.
The alternatives I tried were:
Boost.Python
I liked the cleaner API produced by Boost.Python, but the fact that it would have requ...