I am currently working on exposing data from legacy system over the web. I have a (legacy) server application that sends and receives data over UDP. The software uses UDP to send sequential updates to a given set of variables in (near) real-time (updates every 5-10 ms). thus, I do not need to capture all UDP data -- it is sufficient that...
I've got this function, which I modified from material in chapter 1 of the online NLTK book. It's been very useful to me but, despite reading the chapter on Unicode, I feel just as lost as before.
def openbookreturnvocab(book):
fileopen = open(book)
rawness = fileopen.read()
tokens = nltk.wordpunct_tokenize(rawness)
nltk...
In several places I have to retrieve some value from a dict, but need to check if the key for that value exists, and if it doesn't I use some default value :
if self.data and self.data.has_key('key'):
value = self.data['key']
else:
value = self.default
....
One thing I like about python, is that and/or bool...
I'm baffled by this one. I tried moving the QPainter to it's own def as some have suggested, but it gives the exact same error. Here's the def I created.
def PaintButtons(self):
solid = QtGui.QPixmap(200, 32)
paint = QtGui.QPainter()
paint.begin(solid)
paint.setPen(QtGui.Qcolor(255,255,255))
paint.setBrush(QtGui.QCol...
Hi.
I have a following scenario:
A user fills in a URL to an image in a form (plain text field). In the form's model I also have ThumbnailField but it's hidden in the form.
image = ThumbnailField(editable=False, upload_to='media/images/products/', blank=True, null=True, size=(300, 300),
extra_thumbnails={
'icon': {'size': ...
I have 2 lists of dictonaries and want to return items which have the same id but different title. i.e.
list1 = [{'id': 1, 'title': 'title1'}, {'id': 2, 'title': 'title2'}, {'id': 3, 'title': 'title3'}]
list2 = [{'id': 1, 'title': 'title1'}, {'id': 2, 'title': 'title3'}, {'id': 3, 'title': 'title4'}]
Would return [{'id': 2, 'title': ...
Hi
query level: beginner
as part of a learning exercise i have written code that must check if a string (as it is build up through raw_input) matches the beginning of any list item and if it equals any list item.
wordlist = ['hello', 'bye']
handlist = []
letter = raw_input('enter letter: ')
handlist.append(letter)
hand = "".joi...
So, that's the question:
How to make a class serializable?
a simple class:
class FileItem:
def __init__(self, fname):
self.fname = fname
What should I do to be able to get output of:
json.dumps()
without an error (FileItem instance at ... is not JSON serializable)
...
I have the following python code:
import pty
import subprocess
os=subprocess.os
from subprocess import PIPE
import time
import resource
pipe=subprocess.Popen(["cat"], stdin=PIPE, stdout=PIPE, stderr=PIPE, \
close_fds=True)
skip=[f.fileno() for f in (pipe.stdin, pipe.stdout, pipe.stderr)]
pid, child_fd = pty.fork()...
I have correctly initialized YouTubeService. I can move/delete/rename playlist entries, but when I try to delete playlist I get unhelpfull exception:
_service = None
def get_service():
global _service
if _service is None:
_service = YouTubeService()
gdata.alt.appengine.run_on_appengine(_service)
_servic...
I know that you can get the SQL of a given QuerySet using
print query.query
but as we know from a previous question ( http://stackoverflow.com/questions/2926483/potential-django-bug-in-queryset-query ) the returned SQL is not properly quoted. See http://code.djangoproject.com/browser/django/trunk/django/db/models/sql/query.py
Is ther...
I found the following mistake in my code this week:
import datetime
d = datetime.date(2010,9,24)
if d.isoweekday == 5:
pass
Yes, it should be d.isoweekday() instead.
I know, if I had had a test-case for this I would have been saved.
Comparing a function with 5 is not very useful. Oh, I'm not blaming Python for this.
My question...
i just try this
import facebook
fb = facebook.Facebook('YOUR_API_KEY', 'YOUR_SECRET_KEY')
fb.auth.createToken()
fb.login()
fb.auth.getSession()
fb.set_status('Checking out StackOverFlow.com')
and got this
gunslinger@c0debreaker:~$ python Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41) [GCC 4.3.3] on linux2 Type "help", "copy...
Im trying to create a class called Record, though when I try to use it, something goes wrong. Im sure im overlooking something simple. Does anyone mind taking a look?
class Record:
def __init__(self, model):
self.model= model
self.doc_date = []
self.doc_pn = []
pri...
Hi, I'm working with SharePoint and ProjectServer 2007 via PSI with Python.
I can't find any documentation on how Filter Class (Microsoft.Office.Project.Server.Library) objects work internally to emulate its behaviour in Python.
Any ideas?
...
I'm looking for a way to use importlib in Python 2.x to rewrite bytecode of imported modules on-the-fly. In other words, I need to hook my own function between the compilation and execution step during import. Besides that I want the import function to work just as the built-in one.
I've already did that with imputil, but that library ...
Is it possible to perform a subquery on a QuerySet using another QuerySet?
For example:
q = Something.objects.filter(x=y).extra(where=query_set2)
...
I'm not sure if my post question makes lots of sense; however, I'm building an input array for a class/function that takes in a lot of user inputed data and outputs a numpy array.
# I'm trying to build an input array that should include following information:
'''
* zone_id - id from db - int
* model size - int
* type of analysis - o...
I am trying to use python's imaplib to create an email and send it to a mailbox with specific name, e.g. INBOX. Anyone has some great suggestion :).
...
I could really use some help with a Python regular expression problem. You'd expect the result of
import re
re.sub("s (.*?) s", "no", "this is a string")
to be "this is no string", right? But in reality it's "thinotring". The sub function uses the entire pattern as the group to replace, instead of just the group I actually want to r...