What is a good way to implement keyboard handling? In any language, where I write a keyboard-interactive program (such as a tetris game), I end up having some code that looks like this:
for event in pygame.event.get():
if event.type == KEYDOWN:
if False: pass #make everything an elif
elif rotating: pass
...
I have been trying to find information on how to retrieve attachments from a gmail account in either python or PHP, I'm hoping that someone here can be of some help, thanks.
Related:
How can I download all emails with attachments from Gmail?
...
I have a list of arbitrary length, and I need to split it up into equal size chunks and operate on it. There are some obvious ways to do this, like keeping a counter and two lists, and when the second list fills up, add it to the first list and empty the second list for the next round of data, but this is potentially extremely expensive....
Greetings,
I'm trying to use pylucene in Python 2.6. Since there's no windows build for 2.6, I try to build the source code.
First of all, I build JCC (windows, using cygwin)
python setup.py build
running build
running build_py
[...]
building 'jcc' extension
error: None
python setup.py install
running install
[...]
copying jcc\confi...
I am trying to get pylons to debug in Eclipse under Ubuntu.
Specifically. I am not sure what to use for the 'Main Module' on the Run configurations dialog.
(this is a similar question on stackoverflow, but I think it applies to windows as I can't find paster-script.py on my system)
Can anyone help?
...
if __name__=='__main__':
parser = OptionParser()
parser.add_option("-i", "--input_file",
dest="input_filename",
help="Read input from FILE", metavar="FILE")
(options, args) = parser.parse_args()
print options
result is
$ python convert.py -i video_*
{'input_filename': 'video_...
WARNING: I have been learning Python for all of 10 minutes so apologies for any stupid questions!
I have written the following code, however I get the following exception:
Message File
Name Line Position Traceback Node
31
exceptions.TypeError: this constructor takes no arguments
class Computer:
n...
What is the Python equivalent of the following code in Ruby?
def loop
cont=nil
for i in 1..4
puts i
callcc {|continuation| cont=continuation} if i==2
end
return cont
end
> c=loop
1
2
3
4
> c.call
3
4
Reference: Secrets of lightweight development success, Part 9: Continuations-based frameworks
...
I want to add some Ajax-niceness to my Django-coded website.
In my Django code, I use the @login_required decorator from django.contrib.auth.decorators to mark which view requires authentication. The default behavior when a not authenticated user clicks it is to redirect him/her to login page, and then pass the target page.
What I sa...
I need to run a simple request/response python module under an
existing system with windows/apache/FastCGI.
All the FastCGI wrappers for python I tried work for Linux only
(they use socket.fromfd() and other such shticks).
Is there a wrapper that runs under windows?
...
Hello,
(Django 1.x, Python 2.6.x)
I have models to the tune of:
class Animal(models.Model):
pass
class Cat(Animal):
def __unicode__(self):
return "This is a cat"
class Dog(Animal):
def __unicode__(self):
return "This is a dog"
class AnimalHome(models.Model):
animal = models.ForeignKey(Animal)
I have instantiated n...
The background
I'm building a fair-sized web application with a friend in my own time, and we've decided to go with the Django framework on Python. Django provides us with a lot of features we're going to need, so please don't suggest alternative frameworks.
The only decision I'm having trouble with, is whether we use Python or Jyth...
I'm new to Python and am running to a problem I can't google my way out of. I've built a GUI using wxPython and ObjectiveListView. In its very center, the GUI has a list control displaying data in X rows (the data is loaded by the user) and in five columns.
When the user selects multiple entries from the list control (pressing CTRL or s...
Hello there,
I'm trying to build python 2.5.2 on Solaris 8 using gcc 3.4.2. I can't see any immediate errors in the ./configure step but, once built and i enter the python shell doing an import time errors with :
Python 2.5.2 (r252:60911, Nov 21 2008, 18:45:42)
[GCC 3.4.2] on sunos5
Type "help", "copyright", "credits" or "license" for...
Is it possible?
By debug I mean setting breakpoints, inspect values and advance step by step.
...
tldr: Can someone show me how to properly format this Python iMAP example so it works?
from
http://www.python.org/doc/2.5.2/lib/imap4-example.html
"
import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetc...
I have a nice and lovely Django site up and running, but have noticed that my error.log file was getting huge, over 150 MB after a couple of months of being live. Turns out a bunch of spambots are looking for well known URL vulnerabilities (or something) and hitting a bunch of sub-directories like http://mysite.com/ie or http://mysite.co...
I am having some difficulty writing a function that will search through a directory for a file that matches a specific regular expression (which I have compiled using 're.compile'). So my question is: How do I search through a directory (I plan to use os.walk) for a file that matches a specific regular expression? An example would be ver...
I am trying to write Reversi game in Python. Can anyone give me some basic ideas and strategy which are simple, good and easy to use?
I would appreciate for any help because I've gone to a little far but is stucked between codes and it became more complex too. I think I overdid in some part that should be fairly simple. So....
...
Does anyone know if there's a way to automatically expand a list in Python, separated by commas? I'm writing some Python code that uses the MySQLdb library, and I'm trying to dynamically update a list of rows in a MySQL database with certain key values.
For instance, in the code below, I'd like to have the numeric values in the record_...