In the introduction to Bruce Eckel's Thinking In Java, he says, in 1998:
Programming is about managing
complexity: the complexity of the
problem you want to solve, laid upon
the complexity of the machine in which
it is solved. Because of this
complexity, most of our programming
projects fail. And yet, of all the
program...
I've got about 300k documents stored in a Postgres database that are tagged with topic categories (there are about 150 categories in total). I have another 150k documents that don't yet have categories. I'm trying to find the best way to programmaticly categorize them.
I've been exploring NLTK and its Naive Bayes Classifier. Seems li...
Using Python, how can I wait for a file to be uploaded (using ftp) before deleting it?
uploadFile(ftp, filepath,namef)
# ............Here, I need to wait........
os.remove(filepath)
Any ideas?
...
Hi all. I'm testing python subprocess and I keep getting this error:
$ python subprocess-test.py
Traceback (most recent call last):
File "subprocess-test.py", line 3, in <module>
p = subprocess.Popen(['rsync', '-azP', 'rsync://cdimage.ubuntu.com/cdimage/daily-live/current/maverick-desktop-amd64.iso', '/home/roaksoax/Desktop/iso']...
I'm beginning to learn some Hadoop/MapReduce, coming mostly from a PHP background, with a little bit of Java and Python.
But, it seems like most implementations of MapReduce out there are in Java, Ruby, C++ or Python.
I've looked, and it looks like there are some Hadoop/MapReduce in PHP, but the overwhelming body of the literature se...
I'm working on an app that communicates with Google App Engine to update and retrieve user information, but I can't think of a way to modify elements in the datastore.
For example, every user for my app is represented by a User object in the datastore. If this user inputs things like email, phone number, etc into fields inside the iPhon...
With Python, I could get the name of the exception easily as follows.
run the code, i.e. x = 3/0 to get the exception from python
"ZeroDivisionError: integer division or modulo by zero" tells me this is ZeroDivisionError
Modify the code i.e. try: x=3/0 except ZeroDivisionError: DO something
Is there any similar way to find the except...
I want to have a function in a different module, that when called, has access to all variables that its caller has access to, and functions just as if its body had been pasted into the caller rather than having its own context, basically like a C Macro instead of a normal function. I know I can pass locals() into the function and then it...
I found this today while looking at a library for an API .
def my_function(self, required_param=None):
assert(required_param)
... Do cool function stuff
Wouldn't it be easier to do this:
def my_function(self, required_param):
... Do cool function stuff
Or, am I missing something?
The assert() of course gives you one un...
how I can accomplish this without losing data? someone know how to do that? thanks to all.
...
look at that:
import urllib
print urllib.urlencode(dict(bla='Ã'))
the output is
bla=%C3%BC
what I want is simple, I want the output in ascii instead of utf-8, so I need the output:
bla=%C3
if I try:
urllib.urlencode(dict(bla='Ã'.decode('iso-8859-1')))
doesn't work (all my python files are utf-8 encoded):
'ascii' codec can't ...
I have a bunch of code that looks similar to this:
try:
auth = page.ItemAttributes.Author
except:
try:
auth = page.ItemAttributes.Creator
except:
auth = None
Is there a nicer w...
Currently I'm doing this:
try:
something = iterator.next()
# ...
except StopIteration:
# ...
But I would like an expression that I can place inside a simple if statement.
Is there anything built-in which would make this code look less clumsy?
any() returns False if an iterable is empty, but it will potentially iterate ove...
Hi, I have a time-consuming method with non-predefined number of iterations inside it that I need to test:
def testmethod():
objects = get_objects()
for objects in objects:
# Time-consuming iterations
do_something(object)
One iteration is sufficient to test for me. What is the best practice to test this method ...
I've got a version of the A* algorithm that builds a graph of the
UK road and cycle network in Python lists. It takes about 30 seconds
to initialise, but once done can very quickly find the shortest route
between any two vertices. The start and finish vertex ids are provided
by PHP.
I'm trying to work out the best way of communicating b...
Hello, I'm developing a skin for Plone 3.x. The skin have a lot of differences from the default theme, and i would like to keep the default skin in administration mode. I read some solutions like this http://maurits.vanrees.org/weblog/archive/2008/01/switch-your-skin-based-on-the-url . But I cannot use subdomains in my web, so I cannot u...
I'm using the PyDev for Eclipse plugin, and I'm trying to set a break point in some code that gets run in a background thread. The break point never gets hit even though the code is executing. Here's a small example:
import thread
def go(count):
print 'count is %d.' % count # set break point here
print 'calling from main thread:'
...
Hello world!
I'm testing a django app with selenium, and one of my pages uses the jquery ui tabs element. One of the tabs contains a simple table listing some users, and is loaded via ajax. When using the app, the tab works just fine, but when automating the test with selenium, the tab doesn't appear to load it's content!
I'm writing th...
I'm trying to create a epub uploader to iBook in python. I need a python lib to extract book information. Before implementing this by myself I wonder if anyone know a already made python lib that does it.
Thanks
...
Basically, we want to use no flash, and eschew php where possible (for marketing reasons).
Right now, I'm looking at Ruby on Rails and like what I see... but I'm not really a programmer, having working primarily with Wordpress, Drupal, and Joomla for the past 10 years.
Our sites need to have a lot of custom apps built into them (video ...