I want to do something like this:
# models.py
class Model(models.Model):
name_in_my_model = models.CharField(max_length=100)
# later
fieldname = 'name_in_my_model'
# this is what I want to do somehow:
obj = Model.objects.get(pk=1)
obj.fieldname = 'new name'
obj.save()
Is this possible? I'm making a reusable application, and ...
I'm looking for a way to let multiple Python programs coexist on the same Windows machine.
Here's the problem: suppose program A needs Python 2.5, B needs 2.6, C needs 3, and each of them needs its own version of Qt, Wx or whatever other modules or whatever.
Trying to install all these dependencies on the same machine will break things...
The question is based on the thread, since I observed that Storm allows me reuse my SQL-schemas.
How can you solve the following error message in Storm?
The code is based on Jason's answer and on Storm's manual.
import os, pg, sys, re, psycopg2, storm
from storm.locals import *
from storm import *
class Courses():
subject = Unico...
Hello World Code
#include <boost/python.hpp>
using namespace boost::python;
struct World{
void set(std::string msg) { this->msg = msg; }
std::string greet() { return msg; }
std::string msg;
};
BOOST_PYTHON_MODULE(hello)
{
class_<World>("World")
.def("greet", &World::greet)
.def("set", &World::set)
;...
Hello all, hopefully someone here can shed some light on my issue :D
I've been creating a Windows XP service in python that is designed to monitor/repair selected Windows/Application/Service settings, atm I have been focusing on default DCOM settings.
The idea is to backup our default configuration within another registry key for refer...
What i need to do is to convert something like this
{'key1': [1, 2, 3], 'key2': [4, 5, 6]}
into
[{'key1':1, 'key2':4}, {'key1':2, 'key2':5}, {'key1':3, 'key2':6}]
The length of the value lists can vary!
What's the quickest way to do this (preferably without for loops)?
...
I really like Tornado and I would like to use it with Python 3, though it is written for Python versions 2.5 and 2.6.
Unfortunately it seems like the project's source doesn't come with a test suite. If I understand correctly the WSGI part of it wouldn't be that easy to port as it's spec is not ready for Python 3 yet (?), but I am rather...
After hearing the latest Stack Overflow podcast, Peter Norvig's compact Python spell-checker intrigued me, so I decided to implement it in Scala if I could express it well in the functional Scala idiom, and also to see how many lines of code it would take.
Here's the whole problem. (Let's not compare lines of code yet.)
(Two notes: You...
Greetings,
I have a question on how to update an existing row in my database when one of the fields is my primary key. I am using ModelForm and Django-Piston - my main goal here is to have RESTful Post send to my webservice. I am able to have initial Posts be sent correctly (i.e. that Primary key value doesn't exist yet). The problem is...
I have an object with a dictionary that I want to access via __getitem__ as well as iterate over (values only, keys don't matter) but am not sure how to do it.
For example:
Python 2.5.2 (r252:60911, Jul 22 2009, 15:33:10)
>>> class Library(object):
... def __init__(self):
... self.books = { 'title' : object, 'title2' : object, '...
Ok so I have the same python code locally and in the gae cloud.
when I store an entity locally, the ListProperty field of set element type datetime.datetime looks like so in the Datastore Viewer:
2009-01-01 00:00:00,2010-03-10 00:00:00
when I store same on the cloud, the viewer displays:
[datetime.datetime(2009, 1, 1, 0, 0), datetim...
Here's a fragment of code I'm prototyping that should, by all accounts, never see the light of day. I'll refactor it and clean it up before I merge it into my project.
However, it seems to be working and I happened to be listening to Arlo Guthrie when I was working on it.
#!/usr/bin/env python
import re
expr = re.compile(r'\[[0-9][-0...
If I make a list in Python and want to write a function that would return only odd numbers from a range 1 to x how would I do that?
For example, if I have list [1, 2, 3, 4] from 1 to 4 (4 ix my x), I want to return [1, 3].
...
If I have a list and I want to create a list with only even values of the original list, how would I do that?
I originally have:
list1 = [1,2,3,4,5]
list2 = []
for v in list1:
if v % 2 == 0:
list2 += v
print list2
...
First, a disclaimer. I'm not a CS grad nor a math major, so simplicity is important.
I have a four-character string (e.g. "isoy") that I need to pass as a single 32-bit integer field. Of course at the other end, I need to decode it back to a string. The string will only contain A-Z, and case is not important, if that helps.
The funny ...
I'm trying to print cards using their suit unicode character and their values. I tried doing to following:
def __str__(self):
return u'\u2660'.encode('utf-8')
like suggested in another thread, but I keep getting errors saying UnicodeEncodeError: ascii, ♠, 0, 1, ordinal not in range(128). What can I do to get those suit character t...
Hi Everybody,
I am developing a system for a customer which is displayed in a set of tabs, and shows a table in the centralwidget with data extracted from a database.
Depending on mouse events, the container (groupBox) must be removed from the centralwidget, or then added with new updated data for the table.
Here is a piece of the cod...
I'm just getting back into coding after a few year hiatus and I'm trying to model multi-tiered static forms in a way that lets me grab and perform operations on a specific form level or an entire sub-tree.
Example Form hierarchy:
MyForm
Question 1
Part 1
Question 1.1
Part 2
Question 2.1
SubPart 1
Question 2.1.1
Question 2.1.2
Q...
I'm just starting out with Python and have practiced so far in the IDLE interface. Now I'd like to configure Python with MAMP so I can start creating really basic webapps — using Python inside HTML, or well, vice-versa. (I'm assuming HTML is allowed in Python, just like PHP? If not, are there any modules/template engines for that?)
What...
I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to."
For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a workaround I thought maybe I'd...