title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Use Mercurial API to Get Changes to a Repository For a Given Changeset
2,352,129
<p>How can I use the Mercurial API to determine the changes made to a repository for each changeset? I am able to get a list of files relevant to a particular revision, but I cannot figure out how to tell what happened to that file.</p> <p>How can I answer these questions about each file in a changeset:</p> <ul> <li>...
3
2010-02-28T18:36:44Z
2,352,180
<p><code>localrepo.status()</code> can take contexts as argument (<code>node1</code> and <code>node2</code>).</p> <p>See <a href="http://hg.intevation.org/mercurial/crew/file/6505773080e4/mercurial/localrepo.py#l973" rel="nofollow">http://hg.intevation.org/mercurial/crew/file/6505773080e4/mercurial/localrepo.py#l973</...
4
2010-02-28T18:51:13Z
[ "python", "mercurial", "dvcs", "changeset", "mercurial-extension" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
2,352,195
<p>Derive from dict and and implement <code>__getattr__</code> and <code>__setattr__</code>.</p> <p>Or you can use <a href="http://code.activestate.com/recipes/52308-the-simple-but-handy-collector-of-a-bunch-of-named/">Bunch</a> which is very similar.</p> <p>I don't think it's possible to monkeypatch built-in dict cl...
47
2010-02-28T18:55:03Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
2,352,219
<p>Don't. Attribute access and indexing are separate things in Python, and you shouldn't want them to perform the same. Make a class (possibly one made by <code>namedtuple</code>) if you have something that should have accessible attributes and use <code>[]</code> notation to get an item from a dict.</p>
5
2010-02-28T19:01:51Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
7,534,478
<p>The language itself doesn't support this, but sometimes this is still a useful requirement. Besides the Bunch recipe, you can also write a little method which can access a dictionary using a dotted string:</p> <pre><code>def get_var(input_dict, accessor_string): """Gets data from a dictionary using a dotted acc...
4
2011-09-23T20:30:34Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
9,205,155
<p>I tried this:</p> <pre><code>class dotdict(dict): def __getattr__(self, name): return self[name] </code></pre> <p>you can try __getattribute__ too.</p> <p>make every dict a type of dotdict would be good enough, if you want to init this from a multi-layer dict, try implement <strong>init</strong> too.</p>
7
2012-02-09T03:50:46Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
12,187,277
<p>Building on Kugel's answer and taking Mike Graham's words of caution into consideration, what if we make a wrapper? </p> <pre class="lang-py prettyprint-override"><code>class DictWrap(object): """ Wrap an existing dict, or create a new one, and access with either dot notation or key lookup. The attribu...
4
2012-08-29T22:15:20Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
23,689,767
<p>I've always kept this around in a util file. You can use it as a mixin on your own classes too.</p> <pre><code>&gt;&gt;&gt; class dotdict(dict): ... """dot.notation access to dictionary attributes""" ... __getattr__ = dict.get ... __setattr__ = dict.__setitem__ ... __delattr__ = dict.__delitem__ ......
36
2014-05-15T22:29:39Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
28,463,329
<p>Install <code>dotmap</code> via <code>pip</code></p> <pre><code>pip install dotmap </code></pre> <p>It does everything you want it to do and subclasses <code>dict</code>, so it operates like a normal dictionary:</p> <pre><code>from dotmap import DotMap m = DotMap() m.hello = 'world' m.hello m.hello += '!' # m.he...
24
2015-02-11T19:57:52Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
31,569,236
<p>I ended up trying BOTH the <a href="https://github.com/bcj/AttrDict" rel="nofollow">AttrDict</a> and the <a href="https://github.com/dsc/bunch" rel="nofollow">Bunch</a> libraries and found them to be way to slow for my uses. After a friend and I looked into it, we found that the main method for writing these librar...
1
2015-07-22T16:46:05Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
32,107,024
<p>You can do it using this class I just made. With this class you can use the <code>Map</code> object like another dictionary(including json serialization) or with the dot notation. I hope to help you:</p> <pre><code>class Map(dict): """ Example: m = Map({'first_name': 'Eduardo'}, last_name='Pool', age=24...
44
2015-08-19T23:03:39Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
33,884,563
<p>This solution is a refinement upon the one offered by <a href="http://stackoverflow.com/a/32107024/805357">epool</a> to address the requirement of the OP to access nested dicts in a consistent manner. The solution by epool did not allow for accessing nested dicts.</p> <pre><code>class YAMLobj(dict): def __init__(se...
0
2015-11-24T02:45:55Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
35,123,198
<pre><code>def dict_to_object(dick): # http://stackoverflow.com/a/1305663/968442 class Struct: def __init__(self, **entries): self.__dict__.update(entries) return Struct(**dick) </code></pre> <p>If one decides to permanently convert that <code>dict</code> to object this should do. You...
1
2016-02-01T04:52:54Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
35,203,958
<p>I'd like to throw my own solution into the ring:</p> <p><a href="https://github.com/skorokithakis/jsane" rel="nofollow">https://github.com/skorokithakis/jsane</a></p> <p>It allows you to parse JSON into something you can access <code>with.attribute.lookups.like.this.r()</code>, mostly because I hadn't seen this an...
0
2016-02-04T14:41:36Z
[ "python", "dictionary" ]
How to use a dot "." to access members of dictionary?
2,352,181
<p>How do I make Python dictionary members accessible via a dot "."?</p> <p>For example, instead of writing <code>mydict['val']</code>, I'd like to write <code>mydict.val</code>.</p> <p>Also I'd like to access nested dicts this way. For example, <code>mydict.mydict2.val</code> would refer to <code>mydict = { 'mydict2...
82
2010-02-28T18:51:42Z
36,968,114
<p>If you want to pickle your modified dictionary, you need to add few state methods to above answers:</p> <pre><code>class dotdict(dict): """dot.notation access to dictionary attributes""" def __getattr__(self, attr): return self.get(attr) __setattr__= dict.__setitem__ __delattr__= dict.__deli...
2
2016-05-01T15:03:26Z
[ "python", "dictionary" ]
What is the proper way to pass errors from classes to rendered html in python
2,352,201
<p>I'm performing all my form validation in a class, and would like to be able to get the errors from the class to the rendered html. One approach I was thinking about was to create a global variable "c" that would store all the errors and to set them from within the class, as I still want the individual methods to re...
1
2010-02-28T18:56:15Z
2,352,479
<p>I like to use a dictionary to hold the errors and warnings. Then I can either show all errors at the top of the form or inline. I also define <code>error</code> and <code>warning</code> variables so I can easily tell the two apart.</p> <pre><code>class User(object): def __init__(self): self.messages =...
1
2010-02-28T20:10:26Z
[ "python", "pylons", "mako" ]
What is the proper way to pass errors from classes to rendered html in python
2,352,201
<p>I'm performing all my form validation in a class, and would like to be able to get the errors from the class to the rendered html. One approach I was thinking about was to create a global variable "c" that would store all the errors and to set them from within the class, as I still want the individual methods to re...
1
2010-02-28T18:56:15Z
2,352,485
<p>Yes, definitely, and my suggestion is to avoid returning status codes at all.</p> <p>Generally speaking, there is a lot of literature against using status codes and global variables to hold details for handling errors in a high level environment like Python.<br> Ned Batchelder has written a <a href="http://nedbatch...
1
2010-02-28T20:11:54Z
[ "python", "pylons", "mako" ]
What is the proper way to pass errors from classes to rendered html in python
2,352,201
<p>I'm performing all my form validation in a class, and would like to be able to get the errors from the class to the rendered html. One approach I was thinking about was to create a global variable "c" that would store all the errors and to set them from within the class, as I still want the individual methods to re...
1
2010-02-28T18:56:15Z
2,352,714
<p>In the context of a web application you could just populate <code>tmpl_context</code>.</p> <pre><code>from pylons import tmpl_context as c from yourproject.lib.base import BaseController, render class MyController(BaseController): def index(self): c.error = 'Invalid e-mail address' return rende...
1
2010-02-28T21:19:05Z
[ "python", "pylons", "mako" ]
Printing out Japanese (Chinese) characters
2,352,234
<p>I read Japanese, and want to try processing some Japanese text. I tried this using Python 3:</p> <pre><code>for i in range(1,65535): print(chr(i), end='') </code></pre> <p>Python then gave me tons of errors. What went wrong? </p> <pre><code> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ...
1
2010-02-28T19:05:14Z
2,352,261
<p>You're attempting to encode a character (\x80) that isn't defined by your codec; there is no correct mapping so charmap_encode raises an exception. You could wrap the print statement in a try: block, then catch and ignore the exception to only print the characters that you can encode.</p>
0
2010-02-28T19:11:20Z
[ "python", "unicode" ]
Printing out Japanese (Chinese) characters
2,352,234
<p>I read Japanese, and want to try processing some Japanese text. I tried this using Python 3:</p> <pre><code>for i in range(1,65535): print(chr(i), end='') </code></pre> <p>Python then gave me tons of errors. What went wrong? </p> <pre><code> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ...
1
2010-02-28T19:05:14Z
2,352,281
<p>You problem is your default terminal (output) encoding. Probably latin-1 or even the perennial Python default, ASCII. Those can't encode japanese characters (since it's assumed that the terminal can't display them).</p> <p>If your terminal does UTF-8 (the most often used Unicode encoding in the western world), yo...
2
2010-02-28T19:17:01Z
[ "python", "unicode" ]
Printing out Japanese (Chinese) characters
2,352,234
<p>I read Japanese, and want to try processing some Japanese text. I tried this using Python 3:</p> <pre><code>for i in range(1,65535): print(chr(i), end='') </code></pre> <p>Python then gave me tons of errors. What went wrong? </p> <pre><code> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ...
1
2010-02-28T19:05:14Z
2,352,317
<p>No need to try all 65536 codes of the BMP. Just use the <a href="http://www.fontspace.com/unicode/block" rel="nofollow">code blocks</a> used for Japanese text</p>
0
2010-02-28T19:28:37Z
[ "python", "unicode" ]
Printing out Japanese (Chinese) characters
2,352,234
<p>I read Japanese, and want to try processing some Japanese text. I tried this using Python 3:</p> <pre><code>for i in range(1,65535): print(chr(i), end='') </code></pre> <p>Python then gave me tons of errors. What went wrong? </p> <pre><code> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ...
1
2010-02-28T19:05:14Z
2,352,742
<p>If as you say you read Japanese, you must be aware that Japanese is written using FOUR different types of characters: (1) kanji (Chinese characters) (2) Katakana (3) Hiragana (4) Romaji ("Roman" letters). There are many tens of thousands of kanji of which only a few thousand are in common use.</p> <p>Your code, had...
9
2010-02-28T21:24:59Z
[ "python", "unicode" ]
Printing out Japanese (Chinese) characters
2,352,234
<p>I read Japanese, and want to try processing some Japanese text. I tried this using Python 3:</p> <pre><code>for i in range(1,65535): print(chr(i), end='') </code></pre> <p>Python then gave me tons of errors. What went wrong? </p> <pre><code> !"#$%&amp;'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ...
1
2010-02-28T19:05:14Z
28,407,739
<pre><code>for i in range(0x3040, 0x30a0): print unichr(i), </code></pre> <p>This above is for the Hiragana charset. You can use the same utf-8 encoding above for Katakana, and Kanji as well.</p> <p>Keep in mind that the average japanese uses around 2000-2500 Kanji charachters. However, chinese is probably around 500...
-1
2015-02-09T10:34:58Z
[ "python", "unicode" ]
How to use dicts in Mako templates?
2,352,252
<p>Whenever I pass a complicated data structure to Mako, it's hard to iterate it. For example, I pass a dict of dict of list, and to access it in Mako, I have to do something like:</p> <p><code>% for item in dict1['dict2']['list']: ... %endfor</code></p> <p>I am wondering if Mako has some mechanism that could replace...
2
2010-02-28T19:09:23Z
2,352,316
<pre><code>class Bunch(dict): def __init__(self, d): dict.__init__(self, d) self.__dict__.update(d) def to_bunch(d): r = {} for k, v in d.items(): if isinstance(v, dict): v = to_bunch(v) r[k] = v return Bunch(r) </code></pre> <p>Pass dict1 to <code>to_bunch<...
2
2010-02-28T19:28:01Z
[ "python", "templates", "mako" ]
How to use dicts in Mako templates?
2,352,252
<p>Whenever I pass a complicated data structure to Mako, it's hard to iterate it. For example, I pass a dict of dict of list, and to access it in Mako, I have to do something like:</p> <p><code>% for item in dict1['dict2']['list']: ... %endfor</code></p> <p>I am wondering if Mako has some mechanism that could replace...
2
2010-02-28T19:09:23Z
2,352,421
<p>Simplification of Łukasz' example:</p> <pre><code>class Bunch: def __init__(self, d): for k, v in d.items(): if isinstance(v, dict): v = Bunch(v) self.__dict__[k] = v print Bunch({'a':1, 'b':{'foo':2}}).b.foo </code></pre> <p>See also: <a href="http://code.act...
7
2010-02-28T19:56:20Z
[ "python", "templates", "mako" ]
The difference between python dict and tr1::unordered_map in C++
2,352,342
<p>I have a question related to understanding of how python dictionaries work. </p> <p>I remember reading somewhere strings in python are immutable to allow hashing, and it is the same reason why one cannot directly use lists as keys, i.e. the lists are mutable (by supporting .append) and hence they cannot be used as ...
9
2010-02-28T19:35:36Z
2,352,356
<p>Keys in all C++ map/set containers are const and thus immutable (after added to the container).</p> <p>Notice that C++ containers are not specific to string keys, you can use any objects, but the constness will prevent modifications after the key is copied to the container.</p>
7
2010-02-28T19:38:57Z
[ "c++", "python", "dictionary", "hashmap", "tr1" ]
Calculating the area underneath a mathematical function
2,352,499
<p>I have a range of data that I have approximated using a polynomial of degree 2 in Python. I want to calculate the area underneath this polynomial between 0 and 1.</p> <p>Is there a calculus, or similar package from numpy that I can use, or should I just make a simple function to integrate these functions?</p> <p>I...
4
2010-02-28T20:18:09Z
2,352,526
<p>If you're integrating only polynomials, you don't need to represent a general mathematical function, use <code>numpy.poly1d</code>, which has an <code>integ</code> method for integration.</p> <pre><code>&gt;&gt;&gt; import numpy &gt;&gt;&gt; p = numpy.poly1d([2, 4, 6]) &gt;&gt;&gt; print p 2 2 x + 4 x + 6 &gt;&g...
8
2010-02-28T20:25:47Z
[ "python", "polynomial-math", "numerical-integration" ]
Calculating the area underneath a mathematical function
2,352,499
<p>I have a range of data that I have approximated using a polynomial of degree 2 in Python. I want to calculate the area underneath this polynomial between 0 and 1.</p> <p>Is there a calculus, or similar package from numpy that I can use, or should I just make a simple function to integrate these functions?</p> <p>I...
4
2010-02-28T20:18:09Z
2,352,651
<p>'<strong>quad</strong>' in scipy.integrate is the general purpose method for integrating functions of a single variable over a definite interval. In a simple case (such as the one described in your question) you pass in your function and the lower and upper limits, respectively. 'quad' returns a tuple comprised of t...
1
2010-02-28T20:59:22Z
[ "python", "polynomial-math", "numerical-integration" ]
Calculating the area underneath a mathematical function
2,352,499
<p>I have a range of data that I have approximated using a polynomial of degree 2 in Python. I want to calculate the area underneath this polynomial between 0 and 1.</p> <p>Is there a calculus, or similar package from numpy that I can use, or should I just make a simple function to integrate these functions?</p> <p>I...
4
2010-02-28T20:18:09Z
2,352,875
<p>It might be overkill to resort to general-purpose numeric integration algorithms for your special case...if you work out the algebra, there's a simple expression that gives you the area.</p> <p>You have a polynomial of degree 2: <strong>f(x) = ax<sup>2</sup> + bx + c</strong></p> <p>You want to find the area under...
4
2010-02-28T22:08:05Z
[ "python", "polynomial-math", "numerical-integration" ]
Calculating the area underneath a mathematical function
2,352,499
<p>I have a range of data that I have approximated using a polynomial of degree 2 in Python. I want to calculate the area underneath this polynomial between 0 and 1.</p> <p>Is there a calculus, or similar package from numpy that I can use, or should I just make a simple function to integrate these functions?</p> <p>I...
4
2010-02-28T20:18:09Z
2,352,980
<p>Look, Ma, no imports!</p> <pre><code>&gt;&gt;&gt; coeffs = [2., 4., 6.] &gt;&gt;&gt; sum(coeff / (i+1) for i, coeff in enumerate(reversed(coeffs))) 8.6666666666666661 &gt;&gt;&gt; </code></pre> <p>Our guarantee: Works for a polynomial of any positive degree or your money back!</p> <p>Update from our research lab:...
5
2010-02-28T22:38:37Z
[ "python", "polynomial-math", "numerical-integration" ]
Calculating the area underneath a mathematical function
2,352,499
<p>I have a range of data that I have approximated using a polynomial of degree 2 in Python. I want to calculate the area underneath this polynomial between 0 and 1.</p> <p>Is there a calculus, or similar package from numpy that I can use, or should I just make a simple function to integrate these functions?</p> <p>I...
4
2010-02-28T20:18:09Z
4,448,896
<p>If one is integrating quadratic or cubic polynomials from the get-go, an alternative to deriving the explicit integral expressions is to use Simpson's rule; it is a deep fact that this method <em>exactly</em> integrates polynomials of degree 3 and lower.</p> <p>To borrow Mike Graham's example (I haven't used Python...
1
2010-12-15T10:25:01Z
[ "python", "polynomial-math", "numerical-integration" ]
Xerces + Python?
2,352,512
<p>Does anyone know if there's an available python library compatible with Python2.6 that exposes the Xerces functionality and its XML DOM capabilities?</p> <p>I would define the desired capabilities as: XML DOM select by Xpath &amp; XSLT processor.</p>
1
2010-02-28T20:20:43Z
2,352,778
<p><a href="http://sourceforge.net/projects/pirxx/" rel="nofollow">pirxx</a> in theory could match your requirements, but it hasn't been maintained in several years so I'd expect some minor incompatibilities with 2.6 to be likely to show up. However, it might still be worth your while to try it -- perhaps fixing those...
1
2010-02-28T21:34:23Z
[ "python", "xml", "xslt", "xpath", "xerces" ]
How to write modern Python tests?
2,352,516
<p>What is the latest way to write Python tests? What modules/frameworks to use?</p> <p>And another question: are <code>doctest</code> tests still of any value? Or should all the tests be written in a more modern testing framework?</p> <p>Thanks, Boda Cydo.</p>
11
2010-02-28T20:22:23Z
2,352,575
<p>The usual way is to use the builtin <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a> module for creating unit tests and bundling them together to test suites which can be run independently. <code>unittest</code> is very similar to (and inspired by) jUnit and thus very easy to use.</...
11
2010-02-28T20:37:38Z
[ "python", "testing" ]
How to write modern Python tests?
2,352,516
<p>What is the latest way to write Python tests? What modules/frameworks to use?</p> <p>And another question: are <code>doctest</code> tests still of any value? Or should all the tests be written in a more modern testing framework?</p> <p>Thanks, Boda Cydo.</p>
11
2010-02-28T20:22:23Z
2,352,580
<p>I don't know much about doctests, but at my university, nose testing is taught and encouraged.</p> <p>Nose can be installed by following this procedure (I'm assuming you're using a PC - Windows OS):</p> <ol> <li>install <a href="http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c8.win32-py2.5.exe#md5=...
5
2010-02-28T20:39:17Z
[ "python", "testing" ]
How to write modern Python tests?
2,352,516
<p>What is the latest way to write Python tests? What modules/frameworks to use?</p> <p>And another question: are <code>doctest</code> tests still of any value? Or should all the tests be written in a more modern testing framework?</p> <p>Thanks, Boda Cydo.</p>
11
2010-02-28T20:22:23Z
2,352,607
<p>Using the built-in <code>unittest</code> module is as relevant and easy as ever. The other unit testing options, <code>py.test</code>,<code>nose</code>, and <code>twisted.trial</code> are mostly compatible with <code>unittest</code>. </p> <p>Doctests are of the same value they always were—they are great for <em>t...
9
2010-02-28T20:48:03Z
[ "python", "testing" ]
How to write modern Python tests?
2,352,516
<p>What is the latest way to write Python tests? What modules/frameworks to use?</p> <p>And another question: are <code>doctest</code> tests still of any value? Or should all the tests be written in a more modern testing framework?</p> <p>Thanks, Boda Cydo.</p>
11
2010-02-28T20:22:23Z
2,353,003
<p>In my current project I'm using <a href="http://docs.python.org/library/unittest.html" rel="nofollow">unittest</a>, <a href="http://blog.ianbicking.org/minimock.html" rel="nofollow">minimock</a>, <a href="http://somethingaboutorange.com/mrl/projects/nose/0.11.1/" rel="nofollow">nose</a>. In the past I've made heavy ...
2
2010-02-28T22:43:32Z
[ "python", "testing" ]
How to write modern Python tests?
2,352,516
<p>What is the latest way to write Python tests? What modules/frameworks to use?</p> <p>And another question: are <code>doctest</code> tests still of any value? Or should all the tests be written in a more modern testing framework?</p> <p>Thanks, Boda Cydo.</p>
11
2010-02-28T20:22:23Z
2,353,883
<p>The important thing to remember about doctests is that the tests are based on string comparisons, and the way that numbers are rendered as strings will vary on different platforms and even in different python interpreters.</p> <p>Most of my work deals with computations, so I use doctests only to test my examples an...
0
2010-03-01T04:33:44Z
[ "python", "testing" ]
What special method in Python handles AttributeError?
2,352,630
<p>What special method(s?) should I redefine in my class so that it handled <code>AttributeError</code>s exceptions and returned a special value in those cases?</p> <p>For example,</p> <pre><code>&gt;&gt;&gt; class MySpecialObject(AttributeErrorHandlingClass): a = 5 b = 9 pass &gt;&gt;&gt; &gt;&gt;&...
2
2010-02-28T20:55:35Z
2,352,643
<p>Your question isn't clear to me, but it sounds like you are looking for <code>__getattr__</code> and possibly for <code>__setattr__</code>, and <code>__delattr__</code>.</p>
1
2010-02-28T20:58:15Z
[ "python", "attributeerror" ]
What special method in Python handles AttributeError?
2,352,630
<p>What special method(s?) should I redefine in my class so that it handled <code>AttributeError</code>s exceptions and returned a special value in those cases?</p> <p>For example,</p> <pre><code>&gt;&gt;&gt; class MySpecialObject(AttributeErrorHandlingClass): a = 5 b = 9 pass &gt;&gt;&gt; &gt;&gt;&...
2
2010-02-28T20:55:35Z
2,352,647
<p>You have do override <code>__getattr__</code>, it works like this:</p> <pre><code>class Foo(object): def __init__(self): self.bar = 'bar' def __getattr__(self, attr): return 'special value' foo = Foo() foo.bar # calls Foo.__getattribute__() (defined by object), returns bar foo.baz # call...
1
2010-02-28T20:58:49Z
[ "python", "attributeerror" ]
What special method in Python handles AttributeError?
2,352,630
<p>What special method(s?) should I redefine in my class so that it handled <code>AttributeError</code>s exceptions and returned a special value in those cases?</p> <p>For example,</p> <pre><code>&gt;&gt;&gt; class MySpecialObject(AttributeErrorHandlingClass): a = 5 b = 9 pass &gt;&gt;&gt; &gt;&gt;&...
2
2010-02-28T20:55:35Z
2,352,768
<p>The example of how to use <code>__getattr__</code> by Otto Allmendinger overcomplicates its use. You would simply define all the other attributes and—if one is missing—Python will fall back on <code>__getattr__</code>.</p> <p>Example:</p> <pre><code>class C(object): def __init__(self): self.foo = "...
3
2010-02-28T21:31:33Z
[ "python", "attributeerror" ]
What is a good way to handle database objects in python classes?
2,352,661
<p>Should I access global db object directly from within the methods of each class? Or from each method, should I instantiate an instance of the db object? </p> <p>One of my database objects changes depending on the id of the info being accessed so it is created through a function connectToDatabase(id). Should I ma...
2
2010-02-28T21:03:38Z
2,352,710
<p>In this case, like in many others, I prefer <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="nofollow">dependency injection</a>: have your class (e.g in its <code>__init__</code>) accept the DB connection as an argument.</p> <p>This makes it easier and cleaner to test, lets you switch strategies as ...
2
2010-02-28T21:18:01Z
[ "python", "sqlalchemy", "pylons" ]
What is a good way to handle database objects in python classes?
2,352,661
<p>Should I access global db object directly from within the methods of each class? Or from each method, should I instantiate an instance of the db object? </p> <p>One of my database objects changes depending on the id of the info being accessed so it is created through a function connectToDatabase(id). Should I ma...
2
2010-02-28T21:03:38Z
2,352,823
<p>SQLAlchemy suggests that a function which creates the session be global.</p> <p><a href="http://www.sqlalchemy.org/docs/reference/orm/sessions.html#sqlalchemy.orm.sessionmaker" rel="nofollow">http://www.sqlalchemy.org/docs/reference/orm/sessions.html#sqlalchemy.orm.sessionmaker</a></p> <blockquote> <p>It is inte...
1
2010-02-28T21:49:11Z
[ "python", "sqlalchemy", "pylons" ]
How to simplify creating huge data structures in Python
2,352,793
<p>I am writing some and I need to pass a complicated data structure to some function.</p> <p>The data structure goes like this:</p> <pre><code>{ 'animals': [ 'cows', 'moose', { 'properties': [ 9, 26 ] } ] 'fruits': { 'land': [ 'strawberries', 'other berries' ], 'space': [ 'apples', 'cherries' ] } } </cod...
4
2010-02-28T21:40:05Z
2,352,828
<ol> <li>Use objects. You are working with basic types like strings and dictionaries while objects are more powerful.</li> <li>Use function arguments. You can pass the the first-level keys in your dictionary as arguments to your function:</li> </ol> <pre> def yourfunction(animals, fruits) # do things with fruits a...
2
2010-02-28T21:50:19Z
[ "python", "data-structures" ]
How to simplify creating huge data structures in Python
2,352,793
<p>I am writing some and I need to pass a complicated data structure to some function.</p> <p>The data structure goes like this:</p> <pre><code>{ 'animals': [ 'cows', 'moose', { 'properties': [ 9, 26 ] } ] 'fruits': { 'land': [ 'strawberries', 'other berries' ], 'space': [ 'apples', 'cherries' ] } } </cod...
4
2010-02-28T21:40:05Z
2,352,859
<p>Other languages would solve this problem with objects or structs-- so, something like:</p> <pre><code>class whatever: animals = AnimalObject() fruits = FruitObject() class AnimalObject: animals = ['cows','moose'] properties = [9,26] class FruitObject: land = ['strawberries', 'other berries'] ...
5
2010-02-28T22:01:57Z
[ "python", "data-structures" ]
Parsing broken XML with lxml.etree.iterparse
2,352,840
<p>I'm trying to parse a huge xml file with lxml in a memory efficient manner (ie streaming lazily from disk instead of loading the whole file in memory). Unfortunately, the file contains some bad ascii characters that break the default parser. The parser works if I set recover=True, but the iterparse method doesn't ...
10
2010-02-28T21:55:58Z
2,353,026
<p>Edit your question, stating what happens (exact error message and traceback (copy/paste, don't type from memory)) to make you think that "bad unicode" is the problem.</p> <p>Get <a href="http://chardet.feedparser.org/" rel="nofollow">chardet</a> and feed it your MySQL dump. Tell us what it says.</p> <p>Show us the...
0
2010-02-28T22:50:13Z
[ "python", "xml", "sax", "lxml" ]
Parsing broken XML with lxml.etree.iterparse
2,352,840
<p>I'm trying to parse a huge xml file with lxml in a memory efficient manner (ie streaming lazily from disk instead of loading the whole file in memory). Unfortunately, the file contains some bad ascii characters that break the default parser. The parser works if I set recover=True, but the iterparse method doesn't ...
10
2010-02-28T21:55:58Z
2,389,762
<p>I solved the problem by creating a class with a File like object interface. The class' read() method reads a line from the file and replaces any "bad characters" before returning the line to iterparse.</p> <pre><code>#psudo code class myFile(object): def __init__(self, filename): self.f = open(filenam...
4
2010-03-05T20:33:35Z
[ "python", "xml", "sax", "lxml" ]
Parsing broken XML with lxml.etree.iterparse
2,352,840
<p>I'm trying to parse a huge xml file with lxml in a memory efficient manner (ie streaming lazily from disk instead of loading the whole file in memory). Unfortunately, the file contains some bad ascii characters that break the default parser. The parser works if I set recover=True, but the iterparse method doesn't ...
10
2010-02-28T21:55:58Z
9,050,454
<p>The currently accepted answer is, well, not what one should do. The question itself also has a bad assumption:</p> <blockquote> <p>parser = lxml.etree.XMLParser(recover=True) <em>#recovers from bad characters.</em></p> </blockquote> <p>Actually <code>recover=True</code> is for recovering <em>from misformed XML</...
25
2012-01-29T02:36:19Z
[ "python", "xml", "sax", "lxml" ]
Running a python script from webpy
2,352,870
<p>I setup a lighttpd server along with webpy and fastcgi. I am trying to simply run a python script everytime the wenpy app is accessed. Though it seems even when I give the normal python code to execute the script it does nothing. So Id like to be able to run this script, any idea would be helpful.</p> <pre><code...
3
2010-02-28T22:04:59Z
2,353,067
<p>Assuming your method runs my top concern would be that an error is occurring and you are not getting standard output explaining the problem (os.system will get the return value, e.g. exit code). Python docs recommend replacing it with subprocess, I like to do this: </p> <pre><code>from subprocess import Popen, PIPE...
3
2010-02-28T23:08:37Z
[ "python", "web.py" ]
Running a python script from webpy
2,352,870
<p>I setup a lighttpd server along with webpy and fastcgi. I am trying to simply run a python script everytime the wenpy app is accessed. Though it seems even when I give the normal python code to execute the script it does nothing. So Id like to be able to run this script, any idea would be helpful.</p> <pre><code...
3
2010-02-28T22:04:59Z
2,362,275
<p>I eventually found that calling the script as an object of the webpy app works great, but executing it externally simply decides never to work. </p>
0
2010-03-02T10:03:52Z
[ "python", "web.py" ]
Running a python script from webpy
2,352,870
<p>I setup a lighttpd server along with webpy and fastcgi. I am trying to simply run a python script everytime the wenpy app is accessed. Though it seems even when I give the normal python code to execute the script it does nothing. So Id like to be able to run this script, any idea would be helpful.</p> <pre><code...
3
2010-02-28T22:04:59Z
4,953,061
<p>Probably, the reason it doesn't work is that lighttpd is a daemon, and daemons close their stdin/stdout/stderr file descriptors. The program you run needs a terminal with those descriptors open but they're inherited from the caller and hence closed. So, when calling an external program you should provide them yourse...
0
2011-02-10T03:30:03Z
[ "python", "web.py" ]
Running a python script from webpy
2,352,870
<p>I setup a lighttpd server along with webpy and fastcgi. I am trying to simply run a python script everytime the wenpy app is accessed. Though it seems even when I give the normal python code to execute the script it does nothing. So Id like to be able to run this script, any idea would be helpful.</p> <pre><code...
3
2010-02-28T22:04:59Z
18,721,082
<p>What you're looking for to see what your operation resulted in is:</p> <p><code>print proc.stdout.read()</code></p> <p>After your <code>Popen</code> command</p>
0
2013-09-10T14:04:21Z
[ "python", "web.py" ]
Are python functions threadsafe? (Particularly this one?)
2,352,934
<p>Before answering, please understand I do NOT want you to do the work for me. I would rather appreciate a worded answer as to why my (possibly theoretical) problem exists, and an explanation of the process to go about fixing it. I find it harder to learn properly when someone just does the work for me. Thank you i...
2
2010-02-28T22:26:12Z
2,352,954
<blockquote> <p>A more simple form of the question: If I call this function from a multi-threaded environment, will I have problems, </p> </blockquote> <p>Yes it is thread-safe from what I can tell </p> <blockquote> <p>or do I need to move it into its own class?</p> </blockquote> <p>Thread safety has nothing to ...
7
2010-02-28T22:31:17Z
[ "python", "multithreading", "scope" ]
Are python functions threadsafe? (Particularly this one?)
2,352,934
<p>Before answering, please understand I do NOT want you to do the work for me. I would rather appreciate a worded answer as to why my (possibly theoretical) problem exists, and an explanation of the process to go about fixing it. I find it harder to learn properly when someone just does the work for me. Thank you i...
2
2010-02-28T22:26:12Z
2,352,964
<p>Builtin functions <code>len()</code>, <code>str()</code> that is used in your function can be monkey-patched in other threads.</p>
0
2010-02-28T22:33:55Z
[ "python", "multithreading", "scope" ]
Are python functions threadsafe? (Particularly this one?)
2,352,934
<p>Before answering, please understand I do NOT want you to do the work for me. I would rather appreciate a worded answer as to why my (possibly theoretical) problem exists, and an explanation of the process to go about fixing it. I find it harder to learn properly when someone just does the work for me. Thank you i...
2
2010-02-28T22:26:12Z
9,512,656
<p>It is not so easy because every <code>get*()</code> function could use caches. So every call could leat into data changes. -> problem</p>
0
2012-03-01T08:10:28Z
[ "python", "multithreading", "scope" ]
Have to Restart Apache When Using Django On Apache with mod_wsgi
2,353,012
<p>I'm creating a web app with Django. Since I'm very familiar with Apache I setup my development environment to have Django run through Apache using mod_wsgi. The only annoyance I have with this is that I have to restart Apache everytime I change my code. Is there a way around this?</p>
11
2010-02-28T22:48:18Z
2,353,038
<p>mod_wsgi is great for production but I think the included server is better for development.</p> <p>Anyway you should read <a href="http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode">this</a> about automatic reloading of source code.</p>
15
2010-02-28T22:55:04Z
[ "python", "django", "apache", "mod-wsgi", "restart" ]
Have to Restart Apache When Using Django On Apache with mod_wsgi
2,353,012
<p>I'm creating a web app with Django. Since I'm very familiar with Apache I setup my development environment to have Django run through Apache using mod_wsgi. The only annoyance I have with this is that I have to restart Apache everytime I change my code. Is there a way around this?</p>
11
2010-02-28T22:48:18Z
2,353,081
<p>I feel like this is really just one of those things most people deal with. It's really not that big of a deal. I made a bash script to make this as easy as possible. I name it 'ra' (reload apache) so it's short and quick. The following works for most apache installs (on UNIX-based systems):</p> <pre><code>#!/bin/ba...
-4
2010-02-28T23:13:24Z
[ "python", "django", "apache", "mod-wsgi", "restart" ]
Installing PIL on Snow Leopard
2,353,099
<p>Hey, i have a problem installing PIL on Snow. </p> <p>I have a clean installation of macports after the upgrade to SL and installed from source the jpeg library following the OS specific installation instructions. Installing PIL with pip goes well but when i try to import the _imaging module i get the following me...
5
2010-02-28T23:20:56Z
2,353,182
<p>I'm not entirely certain (I use a PC myself), but I think that you might find something interesting <a href="http://www.cdf.toronto.edu/~csc108h/fall/python.shtml" rel="nofollow">here</a></p> <p>May the force be with you</p>
0
2010-02-28T23:51:11Z
[ "python", "python-imaging-library" ]
Installing PIL on Snow Leopard
2,353,099
<p>Hey, i have a problem installing PIL on Snow. </p> <p>I have a clean installation of macports after the upgrade to SL and installed from source the jpeg library following the OS specific installation instructions. Installing PIL with pip goes well but when i try to import the _imaging module i get the following me...
5
2010-02-28T23:20:56Z
2,357,280
<p>PIL on Mac OS X has been a pain point for many of my friends. These instructions seem to often help speedup the enlightenment process:</p> <p><a href="http://passingcuriosity.com/2009/installing-pil-on-mac-os-x-leopard/" rel="nofollow">http://passingcuriosity.com/2009/installing-pil-on-mac-os-x-leopard/</a></p> <p...
2
2010-03-01T16:28:21Z
[ "python", "python-imaging-library" ]
Installing PIL on Snow Leopard
2,353,099
<p>Hey, i have a problem installing PIL on Snow. </p> <p>I have a clean installation of macports after the upgrade to SL and installed from source the jpeg library following the OS specific installation instructions. Installing PIL with pip goes well but when i try to import the _imaging module i get the following me...
5
2010-02-28T23:20:56Z
2,359,307
<p>MacPorts already has a PIL port that will do all the work for you!</p> <pre><code>sudo port install py26-pil </code></pre> <p>You should first go into the site-packages directory and elsewhere to remove the stuff you installed manually, though. MacPorts will install all the necessary dependent libraries.</p>
3
2010-03-01T21:48:26Z
[ "python", "python-imaging-library" ]
Installing PIL on Snow Leopard
2,353,099
<p>Hey, i have a problem installing PIL on Snow. </p> <p>I have a clean installation of macports after the upgrade to SL and installed from source the jpeg library following the OS specific installation instructions. Installing PIL with pip goes well but when i try to import the _imaging module i get the following me...
5
2010-02-28T23:20:56Z
6,846,152
<p>I had the same problems, and actually created a small tutorial on how to resolve this. getting a working copy of PIL, libjpeg and Imaging on Snow Leopard or even Lion</p> <p>My default version of Python was still on 2.6 so I had to switch to 2.7</p> <pre><code>defaults write com.apple.versioner.python Version 2.7 ...
1
2011-07-27T14:32:26Z
[ "python", "python-imaging-library" ]
Anybody know how to toggle caps lock on/off in Python?
2,353,112
<p>I'm trying to toggle caps lock on/off when the two shift buttons are held down for a second. I've tried using the virtkey module, but it's not working. That module does work for other keys though, so I don't think I'm using the module incorrectly.</p> <p>Does anybody have a way for doing this?</p> <p>Just to be cl...
3
2010-02-28T23:24:13Z
2,353,172
<p>Funny thing. I gave virtkey a try in the interpreter, and it seemed like it was working. After calling <code>press_keycode(50)</code>, my machine acts like caps lock has been pressed (Ubuntu 9.10, python-virtkey .50ubuntu2). If I release the key- <code>release_keycode(50)</code>- it acts like nothing has happened...
0
2010-02-28T23:46:49Z
[ "python", "linux", "keyboard", "capslock" ]
Anybody know how to toggle caps lock on/off in Python?
2,353,112
<p>I'm trying to toggle caps lock on/off when the two shift buttons are held down for a second. I've tried using the virtkey module, but it's not working. That module does work for other keys though, so I don't think I'm using the module incorrectly.</p> <p>Does anybody have a way for doing this?</p> <p>Just to be cl...
3
2010-02-28T23:24:13Z
2,353,256
<p>This works for me (turns the led on and off as well as enable/disable caps)</p> <pre><code>import virtkey v = virtkey.virtkey() v.press_keycode(66) v.release_keycode(66) # first release doesn't release it v.release_keycode(66) </code></pre> <p>Here are some more examples</p> <pre><code>v.press_keycode(66) # ...
4
2010-03-01T00:16:46Z
[ "python", "linux", "keyboard", "capslock" ]
GAE python database object design for simple list of values
2,353,135
<p>I'm really new to database object design so please forgive any weirdness in my question. Basically, I am use Google AppEngine (Python) and contructing an object to track user info. One of these pieces of data is 40 Achievement scores. Do I make a list of ints in the User object for this? Or do I make a separate ...
0
2010-02-28T23:32:02Z
2,353,232
<p>I like the simple idea of keeping the list of 40 <code>int</code>s, but you can't force feed it into App Engine's existing <a href="http://code.google.com/appengine/docs/python/users/userobjects.html" rel="nofollow">User</a> class, whose layout is determined by the GAE API (and doesn't include those 40 <code>int</co...
2
2010-03-01T00:06:51Z
[ "python", "database", "design", "google-app-engine", "object" ]
Django sending e-mail u'' around headers
2,353,136
<p>I wrote a simple contact form for a client in Django. However, whenever it sends e-mail, it wraps the header values in u'' objects. For example, the From: header is</p> <pre><code>From: (u'my@email.com',) </code></pre> <p>Here's the code that sends the message:</p> <p>The form:</p> <pre><code>class ContactForm(f...
1
2010-02-28T23:32:52Z
2,353,183
<p>Lose the trailing commas here:</p> <pre><code> elif form.is_valid(): name = form.cleaned_data['name'] sender = form.cleaned_data['sender'] subject = form.cleaned_data['subject'] message = form.cleaned_data['message'] </code></pre>
6
2010-02-28T23:51:19Z
[ "python", "django", "email" ]
Python 3 object construction: which is the most Pythonic / the accepted way?
2,353,140
<p>Having a background in Java, which is very verbose and strict, I find the ability to mutate Python objects as to give them with fields other than those presented to the constructor really "ugly".</p> <p>Trying to accustom myself to a Pythonic way of thinking, <strong>I'm wondering how I should allow my objects to b...
8
2010-02-28T23:34:28Z
2,353,165
<p>The first you describe is very common. Some use the shorter</p> <pre><code>class Foo: def __init__(self, foo, bar): self.foo, self.bar = foo, bar </code></pre> <p>Your second approach isn't common, but a similar version is this:</p> <pre><code>class Thing: def __init__(self, **kwargs): self.so...
8
2010-02-28T23:43:18Z
[ "python-3.x", "python", "conventions" ]
Python 3 object construction: which is the most Pythonic / the accepted way?
2,353,140
<p>Having a background in Java, which is very verbose and strict, I find the ability to mutate Python objects as to give them with fields other than those presented to the constructor really "ugly".</p> <p>Trying to accustom myself to a Pythonic way of thinking, <strong>I'm wondering how I should allow my objects to b...
8
2010-02-28T23:34:28Z
2,353,170
<p>I’ve not seen many of your <code>field_map</code>s in real life. I think that would only make sense if you were to use the <code>field_map</code> at some other place in your code as well.</p> <p>Concerning your third example: Even though you don’t need to assign to them (other than <code>None</code>), it is com...
3
2010-02-28T23:45:56Z
[ "python-3.x", "python", "conventions" ]
Sorting based on the count in a related field in Django
2,353,205
<p>I have two models, <code>Image</code> and <code>Tag</code>. Each Image object can have more than one Tag associated with it, and I want to find my most frequently used tags. How would I go about this? It seems easy enough but I can't seem to figure it out.</p>
1
2010-02-28T23:56:33Z
2,353,214
<p>Django has (only recently) acquired Aggregate support, so now you could do something like this:</p> <pre><code>from django.db.models import Count Tag.objects.annotate(img_count=Count('image')).order_by('img_count') </code></pre>
1
2010-03-01T00:01:25Z
[ "python", "sql", "django", "relational-algebra" ]
No module named urls
2,353,416
<p>I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03">http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03</a> and I'm getting a "No module named urls" error message.</p> <p>Wh...
16
2010-03-01T01:29:17Z
2,353,646
<p>Is there an <code>__init__.py</code> inside mysite/polls/ directory?</p>
4
2010-03-01T02:57:05Z
[ "python", "django" ]
No module named urls
2,353,416
<p>I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03">http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03</a> and I'm getting a "No module named urls" error message.</p> <p>Wh...
16
2010-03-01T01:29:17Z
2,353,867
<p>I can't re-produce the import error on my machine using your project files (Windows 7, Django 1.1.1, Python 2.6.4). Everything imported fine but the urls were not specified properly (like the tutorial shows). Fixing the code:</p> <p>/mysite/urls.py:</p> <pre><code>from django.conf.urls.defaults import * from djan...
5
2010-03-01T04:25:47Z
[ "python", "django" ]
No module named urls
2,353,416
<p>I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03">http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03</a> and I'm getting a "No module named urls" error message.</p> <p>Wh...
16
2010-03-01T01:29:17Z
4,715,125
<p>I did exactly the same thing. Python newbie mistake by reading ahead. I created a file call "polls.url" thinking it was some sort of special django template file.</p> <p>I misunderstood the text: "Now that we've decoupled that, we need to decouple the polls.urls URLconf by removing the leading "polls/" from each ...
1
2011-01-17T15:58:06Z
[ "python", "django" ]
No module named urls
2,353,416
<p>I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03">http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03</a> and I'm getting a "No module named urls" error message.</p> <p>Wh...
16
2010-03-01T01:29:17Z
6,154,486
<p>I had a similar problem in my project root ... django complained that it couldn't find the module mysite.urls.</p> <p>Turns out my ROOT_URLCONF variable in settings.py, which was set up using the default values, was set incorrect. Instead of "mysite.urls", it should have been simply "urls"</p> <p>I changed it, and...
39
2011-05-27T15:32:00Z
[ "python", "django" ]
No module named urls
2,353,416
<p>I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03">http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03</a> and I'm getting a "No module named urls" error message.</p> <p>Wh...
16
2010-03-01T01:29:17Z
6,841,068
<p>I also had a weird problem with "No module named mysite.urls". The admin site was down and the my whole site.</p> <p>The solution, after a few hours of searching the web, was on my side : Django is caching some of the settings in a file that he knows from an environment variable.</p> <p>I just closed my terminal i...
3
2011-07-27T07:49:43Z
[ "python", "django" ]
No module named urls
2,353,416
<p>I'm following the Django Tutorials, I'm at the end of part 3, at Decoupling the URLconfs, at <a href="http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03">http://docs.djangoproject.com/en/1.1/intro/tutorial03/#intro-tutorial03</a> and I'm getting a "No module named urls" error message.</p> <p>Wh...
16
2010-03-01T01:29:17Z
40,059,207
<p>Like Ryan Bagwell, problem was (at least temporarily) solved by changing ROOT_URLCONF in myproject/myproject/settings.py. I had to add "myproject" to ROOT_URLCONF to have there this: "%s.myproject.urls" % PROJECT_APP</p>
0
2016-10-15T12:48:29Z
[ "python", "django" ]
CPython - Internally, what is stored on the stack and heap?
2,353,552
<p>In C#, Value Types (eg: int, float, etc) are stored on the stack. Method parameters may also be stored on the stack as well. Most everything else, however, is stored on the heap. This includes Lists, objects, etc.</p> <p>I was wondering, does CPython do the same thing internally? What does it store on the stack, an...
14
2010-03-01T02:18:56Z
2,353,565
<p>Python's runtime only deals in references to objects (which all live in the heap): what goes on Python's stack (as operands and results of its bytecode operations) are always <strong>references</strong> (to values that live elsewhere).</p>
10
2010-03-01T02:22:37Z
[ "python", "memory-management" ]
CPython - Internally, what is stored on the stack and heap?
2,353,552
<p>In C#, Value Types (eg: int, float, etc) are stored on the stack. Method parameters may also be stored on the stack as well. Most everything else, however, is stored on the heap. This includes Lists, objects, etc.</p> <p>I was wondering, does CPython do the same thing internally? What does it store on the stack, an...
14
2010-03-01T02:18:56Z
2,353,568
<p>All Python objects in the CPython implementation go on the heap. You can read in detail how Python's memory management works <strong><a href="http://docs.python.org/c-api/memory.html">here</a></strong> in the documentation:</p> <blockquote> <p>Memory management in Python involves a private heap <strong>containing...
19
2010-03-01T02:22:49Z
[ "python", "memory-management" ]
How do I get the URL of an HTTP redirect's target?
2,353,689
<p>I am writing client-side Python unit tests to verify whether the HTTP 302 redirects on my Google App Engine site are pointing to the right pages. So far, I have been calling <code>urllib2.urlopen(my_url).geturl()</code>. However, I have encountered 2 issues:</p> <ol> <li>the URL returned by geturl() does not appear...
3
2010-03-01T03:13:25Z
2,353,718
<p>Use <a href="http://docs.python.org/library/httplib.html?highlight=httplib#module-httplib" rel="nofollow">httplib</a> (and look at the return status and Location header of the response) to avoid the "auto-follow redirects" that's impeding your testing. There's a good example <a href="http://diveintopython.net/http_...
5
2010-03-01T03:22:57Z
[ "python", "http", "google-app-engine", "redirect" ]
How do I get the URL of an HTTP redirect's target?
2,353,689
<p>I am writing client-side Python unit tests to verify whether the HTTP 302 redirects on my Google App Engine site are pointing to the right pages. So far, I have been calling <code>urllib2.urlopen(my_url).geturl()</code>. However, I have encountered 2 issues:</p> <ol> <li>the URL returned by geturl() does not appear...
3
2010-03-01T03:13:25Z
2,355,228
<p>Supply <code>follow_redirects=False</code> to the <a href="http://code.google.com/appengine/docs/python/urlfetch/fetchfunction.html" rel="nofollow">fetch function</a>, then retrieve the location of the first redirect from the 'location' header in the response, like so:</p> <pre><code>response = urlfetch.fetch(your_...
4
2010-03-01T10:48:14Z
[ "python", "http", "google-app-engine", "redirect" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
2,353,808
<p>If you need extra validation using more than one field from a form, override the .clean() method. But if it's just for one field, you can create a clean_field_name() method.</p> <p><a href="http://docs.djangoproject.com/en/1.1/ref/forms/validation/#ref-forms-validation" rel="nofollow">http://docs.djangoproject.com/...
0
2010-03-01T04:04:03Z
[ "python", "django", "django-forms" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
2,353,816
<p>I guess you need to use JavaScript to hide or remove the text from the container.</p>
-2
2010-03-01T04:07:29Z
[ "python", "django", "django-forms" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
2,357,014
<p>Someone showed me how to do this. This method is working for me:</p> <p><code>post_vars = {}<br> post_vars.update(request.POST)<br> form = MyForm(post_vars, auto_id='my-form-%s')<br> form.data['fieldname'] = ''<br> form.data['fieldname2'] = ''</code></p>
2
2010-03-01T15:50:42Z
[ "python", "django", "django-forms" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
2,851,699
<p>Can't you just delete the password data from the form's cleaned_data during validation?</p> <p>See <a href="http://docs.djangoproject.com/en/1.1/ref/forms/validation/#cleaning-and-validating-fields-that-depend-on-each-other" rel="nofollow">the Django docs for custom validation</a> (especially the second block of co...
0
2010-05-17T18:32:01Z
[ "python", "django", "django-forms" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
7,731,374
<p>Regarding the immutable QueryDict error, your problem is almost certainly that you have created your form instance like this:</p> <pre><code>form = MyForm(request.POST) </code></pre> <p>This means that form.data <em>is</em> the actual QueryDict created from the POST vars. Since the request itself is immutable, you...
6
2011-10-11T19:25:19Z
[ "python", "django", "django-forms" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
12,200,610
<p>I just created the form again.</p> <p>Just try: </p> <pre><code>form = AwesomeForm() </code></pre> <p>and then render it.</p>
0
2012-08-30T15:40:51Z
[ "python", "django", "django-forms" ]
Clearing Django form fields on form validation error?
2,353,732
<p>I have a Django form that allows a user to change their password. I find it confusing on form error for the fields to have the *'ed out data still in them.</p> <p>I've tried several methods for removing form.data, but I keep getting a <code>This QueryDict instance is immutable</code> exception message.</p> <p>Is t...
6
2010-03-01T03:27:48Z
30,134,966
<p>Django has a widget that does that: <a href="https://docs.djangoproject.com/en/1.8/ref/forms/widgets/#passwordinput" rel="nofollow">https://docs.djangoproject.com/en/1.8/ref/forms/widgets/#passwordinput</a></p> <p>now if you are not working with passwords you can do something like this:</p> <pre><code>class NonceI...
0
2015-05-09T01:18:37Z
[ "python", "django", "django-forms" ]
How can I convert string to "command" in Python?
2,353,736
<p>How can I convert this so it could execute?</p> <pre><code>Traceback (most recent call last): File "C:\Users\Shady\Desktop\tet.py", line 14, in &lt;module&gt; exec test File "&lt;string&gt;", line 1 print "hello world" ^ IndentationError: unexpected indent </code></pre> <p>source:</p> <pre><code>te...
2
2010-03-01T03:29:59Z
2,353,738
<p>You might need to use <code>lstrip()</code> on the string to get rid of any leading whitespace before passing it to <code>exec</code>.</p>
3
2010-03-01T03:31:26Z
[ "python", "string" ]
Python: How to find if a path exists between 2 nodes in a graph?
2,353,768
<p>I am using networkx package of Python.</p>
13
2010-03-01T03:41:47Z
2,353,771
<p><ul> <li><a href="http://networkx.lanl.gov/reference/generated/networkx.algorithms.shortest_paths.weighted.dijkstra_path.html" rel="nofollow"><code>dijkstra_path(G, source, target)</code></a></p> <blockquote> <p>Returns the shortest path from source to target in a weighted graph G.</li> </ul></p> </blockquote>
3
2010-03-01T03:43:59Z
[ "python", "networkx" ]
Python: How to find if a path exists between 2 nodes in a graph?
2,353,768
<p>I am using networkx package of Python.</p>
13
2010-03-01T03:41:47Z
2,353,783
<pre><code>&gt;&gt;&gt; import networkx as nx &gt;&gt;&gt; G=nx.empty_graph() &gt;&gt;&gt; G.add_edge(1,2) &gt;&gt;&gt; G.add_edge(2,3) &gt;&gt;&gt; G.add_edge(4,5) &gt;&gt;&gt; nx.path.bidirectional_dijkstra(G,1,2) (1, [1, 2]) &gt;&gt;&gt; nx.path.bidirectional_dijkstra(G,1,3) (2, [1, 2, 3]) &gt;&gt;&gt; nx.path.bidir...
10
2010-03-01T03:51:53Z
[ "python", "networkx" ]
Python: How to find if a path exists between 2 nodes in a graph?
2,353,768
<p>I am using networkx package of Python.</p>
13
2010-03-01T03:41:47Z
2,353,789
<p>Use </p> <pre><code>shortest_path(G, source, target) </code></pre> <p>or one of the Shortest Path methods. Stay clear of the methods which return paths between all nodes however if you merely have two specific nodes to test for connectivity.</p>
6
2010-03-01T03:52:41Z
[ "python", "networkx" ]
Python: How to find if a path exists between 2 nodes in a graph?
2,353,768
<p>I am using networkx package of Python.</p>
13
2010-03-01T03:41:47Z
5,665,794
<p>Using a disjoint set data structure:</p> <p>Create a singleton set for every vertex in the graph, then union the sets containing each of the pair of vertices for every edge in the graph.</p> <p>Finally, you know a path exists between two vertices if they are in the same set.</p> <p>See the <a href="http://en.wiki...
8
2011-04-14T15:38:29Z
[ "python", "networkx" ]
Python: How to find if a path exists between 2 nodes in a graph?
2,353,768
<p>I am using networkx package of Python.</p>
13
2010-03-01T03:41:47Z
19,620,496
<p>To check whether there is a path between two nodes in a graph - </p> <pre><code>&gt;&gt;&gt; import networkx as nx &gt;&gt;&gt; G=nx.Graph() &gt;&gt;&gt; G.add_edge(1,2) &gt;&gt;&gt; G.add_edge(2,3) &gt;&gt;&gt; nx.has_path(G,1,3) True &gt;&gt;&gt; G.add_edge(4,5) &gt;&gt;&gt; nx.has_path(G,1,5) False </code></pre>...
12
2013-10-27T16:36:54Z
[ "python", "networkx" ]
Python: How to find if a path exists between 2 nodes in a graph?
2,353,768
<p>I am using networkx package of Python.</p>
13
2010-03-01T03:41:47Z
32,194,907
<p>Perhaps this is a newer command, but I'm surprised no-one provided it when the question was originally asked. <code>all_simple_paths</code> provides a generator with all simple paths.</p> <pre><code>def path_exists(G,source,target): for path in nx.all_simple_paths(G,source,target): return True #if it...
0
2015-08-25T03:04:46Z
[ "python", "networkx" ]
How can I verify and create values on the Windows registry with Python?
2,353,833
<p>How is the simpler way to verify if the value is already created or create Windows registry values ?</p>
1
2010-03-01T04:14:31Z
2,353,855
<p>Use the standard Python library module <a href="http://docs.python.org/library/_winreg.html" rel="nofollow">_winreg</a> (it's renamed to <code>winreg</code>, no leading <code>_</code>, if you're using Python 3).</p> <p>You always start with one of the constant keys named <code>_winreg.HKEY</code>something; to see t...
3
2010-03-01T04:20:08Z
[ "python", "registry" ]
How can I verify and create values on the Windows registry with Python?
2,353,833
<p>How is the simpler way to verify if the value is already created or create Windows registry values ?</p>
1
2010-03-01T04:14:31Z
2,353,886
<p>you can use _winreg. here's an example enumerating the startup(Run)</p> <pre><code>import _winreg j=0 startup = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run") while 1: try: print _winreg.EnumValue(startup,j) j+=1 except : break </code></pre...
1
2010-03-01T04:35:03Z
[ "python", "registry" ]
How move the program itself to another location in Python?
2,353,902
<p>How can I make the program verify if it's already on the targeted locations, and if not, move itself to another location?</p>
-1
2010-03-01T04:41:57Z
2,353,944
<p><code>os.path.abspath(__file__)</code> is the absolute path to the current module's (or main script's) present location, and <a href="http://docs.python.org/library/os.html?highlight=os.rename#os.rename" rel="nofollow">os.rename</a> is a way to move a file (not to a location where another file of the same name is al...
0
2010-03-01T04:57:52Z
[ "python", "windows", "move" ]
How move the program itself to another location in Python?
2,353,902
<p>How can I make the program verify if it's already on the targeted locations, and if not, move itself to another location?</p>
-1
2010-03-01T04:41:57Z
28,967,135
<p>An alternative to <code>os.path.abspath(__file__)</code> that works with py2exe is <code>sys.executable</code>. if you say <code>filename = sys.executable.rsplit('\\',1)[1]</code> filename would be your files name. this only works if you compile your programs with py2exe though since otherwise it will just display p...
0
2015-03-10T15:03:16Z
[ "python", "windows", "move" ]
do i need 32bit libxml2 for python on snow leopard?
2,353,957
<p>i'm having a hell of a time installing scrapy on my sl mbp. it requires libxml2, so i set about installing that. installing it from macports doesn't seem to pull down the python binding.</p> <p>installing it from source through scrapy's instructions (<a href="http://doc.scrapy.org/intro/install.html#intro-install-s...
3
2010-03-01T05:00:27Z
2,359,255
<p>From the paths in your traceback, it appears you have installed and are trying to use the python.org python 2.6.4 (installed to <code>/Library/Frameworks/Python.frameworks</code> ...). That python is 32-bit only. By default on 10.6, MacPorts tries to install 64-bit versions of packages. You can change that for m...
5
2010-03-01T21:38:25Z
[ "python", "osx", "osx-snow-leopard", "libxml2" ]
do i need 32bit libxml2 for python on snow leopard?
2,353,957
<p>i'm having a hell of a time installing scrapy on my sl mbp. it requires libxml2, so i set about installing that. installing it from macports doesn't seem to pull down the python binding.</p> <p>installing it from source through scrapy's instructions (<a href="http://doc.scrapy.org/intro/install.html#intro-install-s...
3
2010-03-01T05:00:27Z
2,378,807
<p>Trying to install but still struggling. When I:</p> <pre><code>sudo /opt/local/bin/easy_install-2.6 scrapy </code></pre> <p>I get error message and it stops</p> <pre><code>AttributeError: 'NoneType' object has no attribute 'get' </code></pre> <p>Instead I build Scrapy from scratch which works fine.</p> <p>Then...
0
2010-03-04T11:22:59Z
[ "python", "osx", "osx-snow-leopard", "libxml2" ]
do i need 32bit libxml2 for python on snow leopard?
2,353,957
<p>i'm having a hell of a time installing scrapy on my sl mbp. it requires libxml2, so i set about installing that. installing it from macports doesn't seem to pull down the python binding.</p> <p>installing it from source through scrapy's instructions (<a href="http://doc.scrapy.org/intro/install.html#intro-install-s...
3
2010-03-01T05:00:27Z
2,380,713
<p>Credit to @Ned Deily</p> <p>These steps seem to work if you want to run Scrapy 0.8 on OS X 10.6. It uses Macports install of Python 2.6 rather than the one bundled with the OS. Steps assume Macports is not installed yet. </p> <p>Get latest MacPorts installer from here and install:</p> <p><a href="http://www.macpo...
0
2010-03-04T16:02:46Z
[ "python", "osx", "osx-snow-leopard", "libxml2" ]
do i need 32bit libxml2 for python on snow leopard?
2,353,957
<p>i'm having a hell of a time installing scrapy on my sl mbp. it requires libxml2, so i set about installing that. installing it from macports doesn't seem to pull down the python binding.</p> <p>installing it from source through scrapy's instructions (<a href="http://doc.scrapy.org/intro/install.html#intro-install-s...
3
2010-03-01T05:00:27Z
3,663,811
<p>I have a small note to contribute. While attempting to follow-along on this post, I began with three installs of Python:</p> <ol> <li>The default Apple Python 2.5.1 located at: /usr/bin/python</li> <li>A version located: /Library/Frameworks/Python.framework/Versions/2.7</li> <li>And a Macport version located: /opt/...
1
2010-09-08T00:44:54Z
[ "python", "osx", "osx-snow-leopard", "libxml2" ]
Automate Windows GUI operations with Python
2,353,963
<p>I want to make a Python script that automates the process of setting up a VPN server in Windows XP, but the only way I know how to do it is using the Windows GUI dialogs. How would I go about figuring out what those dialogs are doing to the system and designing a Python script to automate it?</p>
10
2010-03-01T05:02:35Z
2,353,989
<p>You could use <a href="http://www.rutherfurd.net/python/sendkeys/" rel="nofollow">SendKeys</a> to send keystrokes to the dialogs in question, and <a href="http://kvance.livejournal.com/985732.html" rel="nofollow">a few extra tricks</a> if you also need mouse actions.</p> <p>Or, you could use <a href="http://www.int...
1
2010-03-01T05:08:16Z
[ "python", "winapi" ]
Automate Windows GUI operations with Python
2,353,963
<p>I want to make a Python script that automates the process of setting up a VPN server in Windows XP, but the only way I know how to do it is using the Windows GUI dialogs. How would I go about figuring out what those dialogs are doing to the system and designing a Python script to automate it?</p>
10
2010-03-01T05:02:35Z
2,354,011
<p>Find out how to do what you want using commands (on the command line) and script these commands instead.</p>
1
2010-03-01T05:13:30Z
[ "python", "winapi" ]