I have a python script that parses a large set of data into an internal memory structure, and implements various fetch functions on the structure.
I want to built a simple web frontend for this script, with the condition that the data is only initialized/loaded once (since re-loading upon each fetch would consume too much time/resources...
Here's the simplest way to explain this. Here's what I'm using:
re.split('\W', 'foo/bar spam\neggs')
-> ['foo', 'bar', 'spam', 'eggs']
Here's what I want:
someMethod('\W', 'foo/bar spam\neggs')
-> ['foo', '/', 'bar', ' ', 'spam', '\n', 'eggs']
The reason is that I want to split a string into tokens, manipulate it, then put it back ...
Hello everyone,
How do you handle errors in SQLAlchemy? I am relatively new to SQLAlchemy and do not know yet.
Before I used SQLAlchemy, I would do things like
status = db.query("INSERT INTO users ...")
if (!status):
raise Error, db.error
But now I am coding in SQLAlchemy and I do things like
user = User('Boda Cydo')
session.ad...
I'm still new to Python and Programming in general, so I need simple explanations! I don't even know what this dictionary thing you'r talking about is!
I'm trying to create a game for my little sister. It is a Virtual Pet sort of thing and the Pet has toys to play with.
I created a class Toy and want to create a function, getNewToy(nam...
Possible Duplicate:
Get last n lines of a file with Python, similar to tail
Hello,
How can I have Python return the last n lines of a file without reading it line by line?
...
I wrote a script that will help a Windows user in her daily life. I want to simply send her the .exe and not ask her to install python, dlls or have to deal with any additional files.
I've read plenty of the stackoverflow entries regarding compiling Python scripts into executable files. I am a bit confused as there are many options but ...
I have a named pipe created via the os.mkfifo() command. I have two different Python processes accessing this named pipe, process A is reading, and process B is writing. Process A uses the select function to determine when there is data available in the fifo/pipe. Despite the fact that process B flushes after each write call, process A's...
I have a cpu intensive code which uses a heavy dictionary as data (around 250M data). I have a multicore processor and want to utilize it so that i can run more than one task at a time. The dictionary is mostly read only and may be updated once a day.
How can i write this in python without duplicating the dictionary?
I understand that p...
Is there any way to write unittests or doctests for innerfunc?
def outerfunc():
def innerfunc():
do_something()
return innerfunc()
...
from django.db import models
from django.contrib.auth.models import User
class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 30)
lot_no = models.CharField(max_length = 30)
inventory = models.IntegerField()
commited = models.IntegerField()
available ...
I have a database of which products every user has viewed and I want to recommend a product based on what similar users have viewed. Is there a Python library that can achieve this? I don't need Netflix quality results, just products that are probably of interest. Any ideas?
...
I am trying to find a way to prevent users from double-submitting my forms. I have javascript that disables the submit button, but there is still an occasional user who finds a way to double-submit.
I have a vision of a re-usable library that I could create to protect from this.
In my ideal library, the code block would look somethi...
I have a class Parent. I want to define a __new__ for Parent so it does some magic upon instantiation (for why, see footnote). I also want children classes to inherit from this and other classes to get Parent's features. The Parent's __new__ would return an instance of a subclass of the child class's bases and the Parent class.
This is ...
I set up a process that read a queue for incoming urls to download but when urllib2 open a connection the system hangs.
import urllib2, multiprocessing
from threading import Thread
from Queue import Queue
from multiprocessing import Queue as ProcessQueue, Process
def download(url):
"""Download a page from an url.
url [str]: url...
I'm making a python URL grabber program. For my purposes, I want it to time out really really fast, so I'm doing
urllib2.urlopen("http://.../", timeout=2)
Of course it times out correctly as it should. However, it doesn't bother to close the connection to the server, so the server thinks the client is still connected. How can I ask url...
I'm writing a music player in python, with a cli using urwid. I intend to have the current playlist in a simpleListWalker, wrapped by a listbox, then columns, a pile, and finally a frame.
How do I replace the entire contents of this listbox (or simpleListWalker) with something else?
Relevant code:
class mainDisplay(object):
...
d...
Can anyone help me to set up Python to run on Wampserver. From what I've read so far you would need to use a combination of Wampser, Python, mod_pyhton, and adjustment to the Apache http.conf file. I've tried it but i belive i am having conflict when it comes to versions. Does anyone know of a cobination of versions that can work so that...
I have a application written in PyGtk. I need to convert a particular line number into its corresponding window co-ordinates in a GtkTextView. How can this be done?
...
import re
import sys
import inspect
import testcases
testClass = re.compile(r'.*Case$')
testMethod = re.compile(r'.*Test$')
for class_name, class_obj in inspect.getmembers(testcases, inspect.isclass):
if testClass.match(class_name):
for method_name, method_obj in inspect.getmembers(class_obj, inspect.ismethod):
...
Is it possible to implement in Scala something equivalent to the python yield statement where it remembers the local state of the function where it is used and "yields" the next value each time it is called?
I wanted to have something like this to convert a recursive function into an iterator. Sort of like this:
# this is python
def fo...