magicrebirth


Member since 12/07/2009

53 snippets

18796 profile views

1 Comment(s) Posted

View their favorites

Profile

Achievement

first submission:submitting first snipplet popular snippet:having a snipplet with 20 favorites

magicrebirth's Recent Python Snippets



« Prev 1 2
You need to convert Python source code into HTML markup, rendering comments, keywords, operators, and numeric and string literals in different colors. tokenize.generate_tokens does most of the work. We just need to loop over all tokens it finds, to...
0 1654 posted 14 years ago by magicrebirth
[from the author's website] I wrote this to better understand the relationship between RGB colors. Running it will generate a fairly large HTML file with all sorts of color transitions on it so you can see what is happening as colors are tweaked in...
0 1520 posted 14 years ago by magicrebirth
0 1630 posted 14 years ago by magicrebirth
0 1544 posted 14 years ago by magicrebirth
0 1557 posted 14 years ago by magicrebirth
2 1964 posted 14 years ago by magicrebirth
1 1334 posted 14 years ago by magicrebirth
The resulting tree is represented through a dict where each father gets a key (with all the children as args)
0 1532 posted 15 years ago by magicrebirth
save as a file and run....
0 2567 posted 15 years ago by magicrebirth
0 1206 posted 15 years ago by magicrebirth
0 1231 posted 15 years ago by magicrebirth
Dictionaries cant be sorted, so you need to transform it into a list and sort that one!
0 1028 posted 15 years ago by magicrebirth
Turning a dictionary into a list or an iterator is easy. To get a list of keys, you can just cast the dict into a list. It's cleaner, though to call .keys() on the dictionary to get a list of the keys, or .iterkeys() to get an iterator. Similarly, yo...
0 1162 posted 15 years ago by magicrebirth
ElementTree is provided as part of the standard Python libs. ElementTree is pure python, and cElementTree is the faster C implementation: Here's an example usage, where I'm consuming xml from a RESTful web service:
0 1033 posted 15 years ago by magicrebirth
1 1049 posted 15 years ago by magicrebirth
1 1254 posted 15 years ago by magicrebirth
Now that you have set up your ManyToManyField to use your intermediary model (Membership, in this case), you're ready to start creating some many-to-many relationships. You do this by creating instances of the intermediate model:
0 1442 posted 15 years ago by magicrebirth
0 1439 posted 15 years ago by magicrebirth
« Prev 1 2