I wanted to add a StackOverflow-style tag input to a blog model of mine. This is a model that has a lot of data already in it.
class BlogPost(models.Model):
# my blog fields
try:
tagging.register(BlogPost)
except tagging.AlreadyRegistered:
pass
I thought that was all I needed so I went through my old database of blog post...
Google's heavy usage of Python, is it just a matter of taste or does it give them a competitive advantage?
...
I have a function that calls itself to increment and decrement a stack.
I need to call it a number of times, and I'd like it to work the same way in subsequent calls
but, as expected, it doesn't re-use the default value.
I've read that this is a newbie trap and I've seen suggested solutions, but I haven't been able
to make any soluti...
in the python console the following statement works perfectly fine (i guess using eval that way is not really good, but its just for testing purpose in this case and will be replaced with proper parsing)
$ python
>>> import subprocess
>>> r = subprocess.Popen(['/pathto/plugin1.rb'], stdout=subprocess.PIPE, close_fds=True).communicate()[...
I'm working through O'Reilly's "Learning Python" and having a problem with classes. I think I understand the concept, but in practice have stumbled upon this problem.
Fron page 88-89:
>>> class Worker:
def __innit__(self, name, pay):
self.name=name
self.pay=pay
def lastName(self):
return self.name.split()[-1]
de...
Hi all
Is there a Python equivalent of PHP's mysql_real_escape_string?
I'm trying to insert some strings into a MySQL db direct from Python, and keep getting tripped up by quotes in the strings.
mysql_string = "INSERT INTO candidate (name, address) VALUES "
for k, v in v_dict.iteritems():
mysql_string += " ('" + v_dict['name'] ...
I have a wxPython based app which I am porting to Mac OS X, in that I need to show some alerts which should look like native mac alerts, so I am using pyobjc for that e.g.
import Cocoa
import wx
app = wx.PySimpleApp()
frame = wx.Frame(None, title="mac alert test")
app.SetTopWindow(frame)
frame.Show()
def onclick(event):
Cocoa.CFU...
My dynamic language experience is solely PHP. I want to learn Python now to broaden my career opportunities and just because I like programming. :)
When learning Java, I used a site (lost the URL/real name now), something like "Java for PHP developers" that had all on one side of the page the PHP code, and on the other side the Java cod...
I was wondering if there was any key mapping in VIM to allow me to indent certain lines of code (whether those lines have been selected in visual mode, or n lines above/below current cursor position).
So basically something that converts the following
def my_fun(x, y):
return x + y
to
#def my_fun(x, y):
# return x + y
I am...
Hi I am new to Python and as a part of my assignment I have written the following class
import nltk.stem.api
class BanglaStemmer(nltk.stem.api.StemmerI):
suffixList = ['\xef\xbb\xbf\xe0\xa6\xbf\xe0\xa7\x9f\xe0\xa7\x87\xe0\xa6\x9b\xe0\xa6\xbf\xe0\xa6\xb2\xe0\xa6\xbe\xe0\xa6\xae\n', '\xe0\xa6\xbf\xe0\xa7\x9f\xe0\xa7\x87\xe0\xa6\x9b...
Assuming that I cannot run something like this with Fabric:
run("svn update --password 'password' .")
how's the proper way to pass to Fabric the password for the remote interactive command line?
The problem is that the repo is checked out as svn+ssh and I don't have a http/https/svn option
...
Hi,
I've been browsing documentation, but haven't been able to find a straightforward tutorial, so I apologize if this is a really simple question.
Anyway, I have eclipse with pydev installed on MAC OSX, and I want configure wxPython to work with eclipse, how do I do this? Once I've downloaded wxpython, what steps do I take to allow wx...
Hi,
I'm going to write the web portal using Cassandra databases.
Can you advise me which python interface to use? thrift, lazygal or pycassa?
Are there any benefits to use more complicated thrift then cleaner pycassa?
What about performace - is the same (all of them are just the layer)?
Thanks for any advice.
...
Hi,
I'm using the following to execute a process and hide its output from Python. It's in a loop though, and I need a way to block until the sub process has terminated before moving to the next iteration.
subprocess.Popen(["scanx", "--udp", host], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Thanks for any ...
Hi guys,
I'm making a website that mail users when a movie or a pc game has released. It isn't too complex - users can sign up, choose movies/music or a genre and save the settings. When the movie/music is released - it mails the user. Some other functionality too but this is the jist.
Now, I've been working with Python for a bit but m...
Say I've got an integer, 13941412, that I wish to separate into bytes (the number is actually a color in the form 0x00bbggrr). How would you do that? In c, you'd cast the number to a BYTE and then shift the bits. How do you cast to byte in Python?
...
Hi, everyone
I'm looking for an easy way of packing/unpacking data structures for sending over the network:
on client just before sending:
a = ((1,2),(11,22,),(111,222))
message = pack(a)
and then on server:
a = unpack(message)
Is there a library that could do pack/unpack magic?
Thanks in advance
...
Subj. In particular, I want to add XMPP notifications (over my own XMPP message sending facilities), with some possible non-simple features (like selecting a message source jid or considering user's current XMPP status).
Or I should create a wrapper for notification's send() after all?
...
This is a rather dumb question but i'am looking at a bizarre situation.
I am running fedora and have python 2.6.5 installed. The other day i installed MySQL-python using yum (because i do not have the setuptools module so i cannot build it from source).
Anyway yesterday i wrote my entire data access layer in python and it was running f...
it works fine on 64 bit machines but for some reason will not work on python 2.4.3 on a 32-bit instance.
i get the error
'utf8' codec can't decode bytes in position 76-79: invalid data
for the code
try:
str(sourceresult.sourcename).encode('utf8','replace')
except:
raise Exception( repr(sourceresult.sourcename ) )
...