Skip to content
Advertisement

Tag: python-2.7

WTForms-JSON not working with FormFields

Nested forms (FormFields) doesn’t get populated with data when I use WTForms-JSON. I can’t spot my mistake, see example below. I send the following JSON-request but the print after form.from_json(request.json) reveals that the address object is never populated with data (also, the “appropriate” errors are returned from the route). Print output: {‘name’: u’Alex’, ‘address’: {‘street’: u”, ‘number’: None}} I’m using

How can you slice with string keys instead of integers on a python OrderedDict?

Since an OrderedDict has the features of both a list (with ordered elements), and a dictionary (with keys instead of indexes), it would seem natural that you could slice using keys. What’s interesting about this is that it’s not the error you’d see due to OrderedDictionary.__getslice__ not being implemented. I tried adding my own __getslice__ method to OrderedDict, but I

Dynamically creating Django models with `type`

I have 20+ MySQL tables, prm_a, prm_b, … with the same basic structure but different names, and I’d like to associate them with Django model classes without writing each one by hand. So, feeling ambitious, I thought I’d try my hand at using type() as a class-factory: The following works: But if I try to generate the model classes as

How to get PID by process name?

Is there any way I can get the PID by process name in Python? For example I need to get 3110 by chrome. Answer You can get the pid of processes by name using pidof through subprocess.check_output: check_output([“pidof”,name]) will run the command as “pidof process_name”, If the return code was non-zero it raises a CalledProcessError. To handle multiple entries and

nltk download url authorization issue

I tried to update my nltk data with nltk.download() but I got HTTP Error 401: Authorization Required. When I traced the url in question, I found it in downloader.py DEFAULT_URL = ‘http://nltk.googlecode.com/svn/trunk/nltk_data/index.xml’ I then copied that URL and ran it in my browser to find out that it’s asking me for a username and password. Does anyone know how to

ImportError: No module named scipy

I am using Python 2.7 and trying to get PyBrain to work. But I get this error even though scipy is installed – I have installed scipy using this command – I get – What should I do? Answer Try to install it as a python package using pip. You said you already tried: Now run: I ran both and

Advertisement