I’m a beginner, so forgive any stupidity in advance. I’m using Flask (and by extension Jinja2) to create a simple web app — one that basically lets you type a movie into a web form, which adds it to a SQLite database. I’ve gotten Flask to very nicely iterate through all the movies in t…
Tag: python
UnicodeDecodeError: ‘ascii’ codec can’t decode byte 0xd1 in position 2: ordinal not in range(128)
I am attempting to work with a very large dataset that has some non-standard characters in it. I need to use unicode, as per the job specs, but I am baffled. (And quite possibly doing it all wrong.) I open the CSV using: Then, I attempt to encode it with: I’m encoding everything except the lat and lng b…
Matplotlib different size subplots
I need to add two subplots to a figure. One subplot needs to be about three times as wide as the second (same height). I accomplished this using GridSpec and the colspan argument but I would like to do this using figure so I can save to PDF. I can adjust the first figure using the figsize argument in the
How to use can_add_related in Django Admin
I’ve read about the can_add_related feature here: https://code.djangoproject.com/ticket/9071 I tried using it this way: But this throws a TypeError and I don’t know how to solve this. Can someone point me in the right direction? Thank you. Answer This is probably coming in late. But for other view…
How to create a user in Django?
I’m trying to create a new User in a Django project by the following code, but the highlighted line fires an exception. Any help? Answer The correct way to create a user in Django is to use the create_user function. This will handle the hashing of the password, etc..
Python Matplotlib Y-Axis ticks on Right Side of Plot
I have a simple line plot and need to move the y-axis ticks from the (default) left side of the plot to the right side. Any thoughts on how to do this? Answer Use ax.yaxis.tick_right() for example:
How to put a variable into Python docstring
So I’m trying to create a “dynamic” docstring which is something like this: to basically let the docstring for @param animalType show whatever ANIMAL_TYPES has; so that when this variable is updated, the docstring will be updated automatically. Unfortunately, it doesn’t seem to work. D…
How to generate SOPInstance UID for DICOM file?
I am developing a system which will be able to create structured report for PACS. Obviously in order to create a DICOM instance (file containing Report data), I need three UIDs for Study, Series and Instance. StudyUID and SeriesUID must be the same as that of study and series that report is created for. But f…
Python: setting memory limit for a particular function call
In a Python script, I want to set a memory limit for a certain function call. I looked at how to limit heap size; however, I don’t want to limit the memory of the entire running Python process — i.e. setting the memory limit before and after the function call. Is there any way to make a function c…
How to convert `ctime` to `datetime` in Python?
For me at the moment, t is ‘Sat Apr 21 11:58:02 2012’. I have more data like this. My question is: How to convert t to datetime in Python? Are there any modules to to it? I tried to make a time dict and then convert t, but feel like that’s not the best way to do it in Python.