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
listlengths
1
5
How to walk up a linked-list using a list comprehension?
1,020,037
<p>I've been trying to think of a way to traverse a hierarchical structure, like a linked list, using a list expression, but haven't come up with anything that seems to work.</p> <p>Basically, I want to convert this code:</p> <pre><code>p = self.parent names = [] while p: names.append(p.name) p = p.parent print "...
1
2009-06-19T21:12:29Z
1,020,059
<p>The closest thing I can think of is to create a parent generator:</p> <pre><code># Generate a node's parents, heading towards ancestors def gen_parents(node): node = node.parent while node: yield node node = node.parent # Now you can do this parents = [x.name for x in gen_parents(node)] print '.'...
6
2009-06-19T21:18:08Z
[ "python", "list-comprehension" ]
How to walk up a linked-list using a list comprehension?
1,020,037
<p>I've been trying to think of a way to traverse a hierarchical structure, like a linked list, using a list expression, but haven't come up with anything that seems to work.</p> <p>Basically, I want to convert this code:</p> <pre><code>p = self.parent names = [] while p: names.append(p.name) p = p.parent print "...
1
2009-06-19T21:12:29Z
1,020,394
<p>Your LinkedList needs to be iterable for it to work properly. </p> <p><a href="http://heather.cs.ucdavis.edu/~matloff/Python/PyIterGen.pdf" rel="nofollow">Here's a good resource on it. (PDF warning)</a> It is very in depth on both iterators and generators.</p> <p>Once you do that, you'll be able to just do this:</...
1
2009-06-19T22:57:35Z
[ "python", "list-comprehension" ]
How to walk up a linked-list using a list comprehension?
1,020,037
<p>I've been trying to think of a way to traverse a hierarchical structure, like a linked list, using a list expression, but haven't come up with anything that seems to work.</p> <p>Basically, I want to convert this code:</p> <pre><code>p = self.parent names = [] while p: names.append(p.name) p = p.parent print "...
1
2009-06-19T21:12:29Z
1,020,488
<p>If you want your solution to be general, use a general techique. This is a fixed-point like generator:</p> <pre><code>def fixedpoint(f, start, stop): while start != stop: yield start start = f(start) </code></pre> <p>It will return a generator yielding start, f(start), f(f(start)), f(f(f(start)...
2
2009-06-19T23:38:10Z
[ "python", "list-comprehension" ]
Writing with Python's built-in .csv module
1,020,053
<p>[Please note that this is a different question from the already answered <a href="http://stackoverflow.com/questions/1019200/how-to-replace-a-column-using-pythons-built-in-csv-writer-module">How to replace a column using Python’s built-in .csv writer module?</a>]</p> <p>I need to do a find and replace (specific t...
7
2009-06-19T21:17:07Z
1,020,074
<p>the problem is you're trying to write to the same file you're reading from. write to a different file and then rename it after deleting the original.</p>
2
2009-06-19T21:22:24Z
[ "python", "file-io", "csv", "python-3.x" ]
Writing with Python's built-in .csv module
1,020,053
<p>[Please note that this is a different question from the already answered <a href="http://stackoverflow.com/questions/1019200/how-to-replace-a-column-using-pythons-built-in-csv-writer-module">How to replace a column using Python’s built-in .csv writer module?</a>]</p> <p>I need to do a find and replace (specific t...
7
2009-06-19T21:17:07Z
1,020,077
<p>You cannot read and write the same file.</p> <pre><code>source = open("PALTemplateData.csv","rb") reader = csv.reader(source , dialect) target = open("AnotherFile.csv","wb") writer = csv.writer(target , dialect) </code></pre> <p>The normal approach to ALL file manipulation is to create a modified COPY of the orig...
10
2009-06-19T21:23:05Z
[ "python", "file-io", "csv", "python-3.x" ]
Writing with Python's built-in .csv module
1,020,053
<p>[Please note that this is a different question from the already answered <a href="http://stackoverflow.com/questions/1019200/how-to-replace-a-column-using-pythons-built-in-csv-writer-module">How to replace a column using Python’s built-in .csv writer module?</a>]</p> <p>I need to do a find and replace (specific t...
7
2009-06-19T21:17:07Z
1,027,955
<p>Opening csv files as binary is just wrong. CSV are normal text files so You need to open them with</p> <pre><code>source = open("PALTemplateData.csv","r") target = open("AnotherFile.csv","w") </code></pre> <p>The error </p> <pre><code>_csv.Error: iterator should return strings, not bytes (did you open the file in...
3
2009-06-22T15:51:08Z
[ "python", "file-io", "csv", "python-3.x" ]
Self Referencing Class Definition in python
1,020,279
<p>is there any way to reference a class name from within the class declaration? an example follows:</p> <pre><code>class Plan(SiloBase): cost = DataField(int) start = DataField(System.DateTime) name = DataField(str) items = DataCollection(int) subPlan = ReferenceField(Plan) </code></pre> <p>i've ...
19
2009-06-19T22:14:40Z
1,020,291
<p><strong>Try this:</strong></p> <pre><code>class Plan(SiloBase): cost = DataField(int) start = DataField(System.DateTime) name = DataField(str) items = DataCollection(int) Plan.subPlan = ReferenceField(Plan) </code></pre> <p><strong>OR use <code>__new__</code> like this:</strong></p> <pre><code>cl...
21
2009-06-19T22:18:31Z
[ "python" ]
Self Referencing Class Definition in python
1,020,279
<p>is there any way to reference a class name from within the class declaration? an example follows:</p> <pre><code>class Plan(SiloBase): cost = DataField(int) start = DataField(System.DateTime) name = DataField(str) items = DataCollection(int) subPlan = ReferenceField(Plan) </code></pre> <p>i've ...
19
2009-06-19T22:14:40Z
1,020,296
<p>No, you can't do that. Think about what would happen if you did this:</p> <pre><code> OtherPlan = Plan other_plan = OtherPlan() </code></pre> <p>At instantiation of <code>other_plan</code>, what is the name of the class?</p> <p>Anyway, this sort of thing is best done in the <code>__new__</code> method, which tak...
0
2009-06-19T22:20:47Z
[ "python" ]
Self Referencing Class Definition in python
1,020,279
<p>is there any way to reference a class name from within the class declaration? an example follows:</p> <pre><code>class Plan(SiloBase): cost = DataField(int) start = DataField(System.DateTime) name = DataField(str) items = DataCollection(int) subPlan = ReferenceField(Plan) </code></pre> <p>i've ...
19
2009-06-19T22:14:40Z
1,020,302
<blockquote> <p>I understand what is happening, the name of the class isn't in scope inside the class.</p> </blockquote> <p>Not exactly. The name of the class <strong>is not yet defined</strong> when defining it's contents (e.g. scope).</p>
1
2009-06-19T22:23:54Z
[ "python" ]
Self Referencing Class Definition in python
1,020,279
<p>is there any way to reference a class name from within the class declaration? an example follows:</p> <pre><code>class Plan(SiloBase): cost = DataField(int) start = DataField(System.DateTime) name = DataField(str) items = DataCollection(int) subPlan = ReferenceField(Plan) </code></pre> <p>i've ...
19
2009-06-19T22:14:40Z
1,020,431
<blockquote> <p>i've got a metaclass that reads this information and does some setup</p> </blockquote> <p>Most frameworks that use metaclasses provide a way to resolve this. For instance, <a href="http://docs.djangoproject.com/en/1.0/ref/models/fields/#foreignkey">Django</a>:</p> <pre><code>subplan = ForeignKey('s...
8
2009-06-19T23:15:00Z
[ "python" ]
How to do PGP in Python (generate keys, encrypt/decrypt)
1,020,320
<p>I'm making a program in Python to be distributed to windows users via an installer.</p> <p>The program needs to be able to download a file every day encrypted with the user's public key and then decrypt it.</p> <p>So I need to find a Python library that will let me generate public and private PGP keys, and also de...
20
2009-06-19T22:28:46Z
1,020,334
<p>Some simple web searching turned up these results:</p> <ul> <li><a href="http://pyme.sourceforge.net/" rel="nofollow">Pyme</a></li> <li><a href="http://sourceforge.net/projects/pypgp/" rel="nofollow">Pypgp</a></li> </ul>
1
2009-06-19T22:33:53Z
[ "python", "encryption", "pgp", "gnupg" ]
How to do PGP in Python (generate keys, encrypt/decrypt)
1,020,320
<p>I'm making a program in Python to be distributed to windows users via an installer.</p> <p>The program needs to be able to download a file every day encrypted with the user's public key and then decrypt it.</p> <p>So I need to find a Python library that will let me generate public and private PGP keys, and also de...
20
2009-06-19T22:28:46Z
1,037,087
<p>PyCrypto supports PGP - albeit you should test it to make sure that it works to your specifications.</p> <p>Although documentation is hard to come by, if you look through Util/test.py (the module test script), you can find a rudimentary example of their PGP support:</p> <pre><code>if verbose: print ' PGP mode:', ...
6
2009-06-24T08:30:10Z
[ "python", "encryption", "pgp", "gnupg" ]
How to do PGP in Python (generate keys, encrypt/decrypt)
1,020,320
<p>I'm making a program in Python to be distributed to windows users via an installer.</p> <p>The program needs to be able to download a file every day encrypted with the user's public key and then decrypt it.</p> <p>So I need to find a Python library that will let me generate public and private PGP keys, and also de...
20
2009-06-19T22:28:46Z
1,039,320
<p><a href="http://pyme.sourceforge.net/" rel="nofollow">PyMe</a> does claim full compatibility with Python 2.4, and I quote:</p> <blockquote> <p>The latest version of PyMe (as of this writing) is v0.8.0. Its binary distribution for Debian was compiled with SWIG v1.3.33 and GCC v4.2.3 for GPGME v1.1.6 and Py...
2
2009-06-24T16:03:44Z
[ "python", "encryption", "pgp", "gnupg" ]
How to do PGP in Python (generate keys, encrypt/decrypt)
1,020,320
<p>I'm making a program in Python to be distributed to windows users via an installer.</p> <p>The program needs to be able to download a file every day encrypted with the user's public key and then decrypt it.</p> <p>So I need to find a Python library that will let me generate public and private PGP keys, and also de...
20
2009-06-19T22:28:46Z
1,042,139
<p><a href="http://chandlerproject.org/Projects/MeTooCrypto" rel="nofollow">M2Crypto</a> has PGP module, but I have actually never tried to use it. If you try it, and it works, please let me know (I am the current M2Crypto maintainer). Some links:</p> <ul> <li><a href="http://svn.osafoundation.org/m2crypto/trunk/M2Cry...
3
2009-06-25T04:10:59Z
[ "python", "encryption", "pgp", "gnupg" ]
How to do PGP in Python (generate keys, encrypt/decrypt)
1,020,320
<p>I'm making a program in Python to be distributed to windows users via an installer.</p> <p>The program needs to be able to download a file every day encrypted with the user's public key and then decrypt it.</p> <p>So I need to find a Python library that will let me generate public and private PGP keys, and also de...
20
2009-06-19T22:28:46Z
1,053,752
<p>You don't need <code>PyCrypto</code> or <code>PyMe</code>, fine though those packages may be - you will have all kinds of problems building under Windows. Instead, why not avoid the rabbit-holes and do what I did? Use <code>gnupg 1.4.9</code>. You don't need to do a full installation on end-user machines - just <cod...
22
2009-06-27T22:12:35Z
[ "python", "encryption", "pgp", "gnupg" ]
How to do PGP in Python (generate keys, encrypt/decrypt)
1,020,320
<p>I'm making a program in Python to be distributed to windows users via an installer.</p> <p>The program needs to be able to download a file every day encrypted with the user's public key and then decrypt it.</p> <p>So I need to find a Python library that will let me generate public and private PGP keys, and also de...
20
2009-06-19T22:28:46Z
1,214,097
<p>As other have noted, PyMe is the canonical solution for this, since it's based on GpgME, which is part of the GnuPG ecosystem.</p> <p>For Windows, I strongly recommend to use <a href="http://www.gpg4win.org" rel="nofollow">Gpg4win</a> as the GnuPG distribution, for two reasons:</p> <p>It's based on GnuPG 2, which,...
2
2009-07-31T18:26:43Z
[ "python", "encryption", "pgp", "gnupg" ]
bug in "django-admin.py makemessages" or xgettext call? -> "warning: unterminated string"
1,020,432
<p><strong>django-admin.py makemessages</strong> dies with errors "warning: unterminated string" on cases where really long strings are wrapped:</p> <pre><code>string = "some text \ more text\ and even more" </code></pre> <p>These strings don't even need to be translated - e.g. sql query strings....
0
2009-06-19T23:16:04Z
1,021,293
<p>I can think of two possibilities: you might have an extra space after your backslash at the end of the line; or you might be somehow ending up with the wrong line-ending characters in your source (e.g. Windows-style when your Python is expecting Unix-style, thus disabling the backslashes).</p> <p>Either way, I woul...
2
2009-06-20T09:20:43Z
[ "python", "django", "internationalization", "xgettext" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,479
<p>I think the point of inheritance in Python is not to make the code compile, it is for the real reason of inheritance which is extending the class into another child class, and to override the logic in the base class. However the duck typing in Python makes the "interface" concept useless, because you can just check ...
8
2009-06-19T23:34:45Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,482
<p>You are referring to the run-time duck-typing as "overriding" inheritance, however I believe inheritance has its own merits as a design and implementation approach, being an integral part of object oriented design. In my humble opinion, the question of whether you can achieve something otherwise is not very relevant...
76
2009-06-19T23:35:48Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,528
<p>Classes in Python are basically just ways of grouping a bunch of functions and data.. They are different to classes in C++ and such..</p> <p>I've mostly seen inheritance used for overriding methods of the super-class. For example, perhaps a more Python'ish use of inheritance would be..</p> <pre><code>from world.an...
0
2009-06-19T23:52:43Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,676
<p>In C++/Java/etc, polymorphism is caused by inheritance. Abandon that misbegotten belief, and dynamic languages open up to you.</p> <p>Essentially, in Python there is no interface so much as "the understanding that certain methods are callable". Pretty hand-wavy and academic-sounding, no? It means that because you ...
5
2009-06-20T01:01:40Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,871
<p>I think that it is very difficult to give a meaningful, concrete answer with such abstract examples...</p> <p>To simplify, there are two types of inheritance: interface and implementation. If you need to inherit the implementation, then python is not so different than statically typed OO languages like C++. </p> <...
6
2009-06-20T03:31:25Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,889
<p>Inheritance in Python is more of a convenience than anything else. I find that it's best used to provide a class with "default behavior."</p> <p>Indeed, there is a significant community of Python devs who argue against using inheritance at all. Whatever you do, don't just don't overdo it. Having an overly compli...
8
2009-06-20T03:44:11Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,020,966
<p>Inheritance in Python is all about code reuse. Factorize common functionality into a base class, and implement different functionality in the derived classes.</p>
10
2009-06-20T04:51:10Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,041,511
<p>You can get around inheritance in Python and pretty much any other language. It's all about code reuse and code simplification though. </p> <p>Just a semantic trick, but after building your classes and base classes, you don't even have to know what's possible with your object to see if you can do it. </p> <p>Sa...
1
2009-06-24T23:40:17Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,071,345
<p>I don't see much point in inheritance.</p> <p>Every time I have ever used inheritance in real systems, I got burned because it led to a tangled web of dependencies, or I simply realised in time that I would be a lot better off without it. Now, I avoid it as much as possible. I simply never have a use for it.</p> <...
1
2009-07-01T20:55:23Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
1,575,488
<p>It's not inheritance that duck-typing makes pointless, it's interfaces — like the one you chose in creating an all abstract animal class.</p> <p>If you had used an animal class that introduce some real behavior for its descendants to make use of, then dog and cat classes that introduced some additional behavior t...
5
2009-10-15T22:28:31Z
[ "python", "oop", "inheritance" ]
What’s the point of inheritance in Python?
1,020,453
<p>Suppose you have the following situation</p> <pre><code>#include &lt;iostream&gt; class Animal { public: virtual void speak() = 0; }; class Dog : public Animal { void speak() { std::cout &lt;&lt; "woff!" &lt;&lt;std::endl; } }; class Cat : public Animal { void speak() { std::cout &lt;&lt; "meow!" &lt...
69
2009-06-19T23:28:18Z
11,434,605
<p>Another small point is that op's 3'rd example, you can't call isinstance(). For example passing your 3'rd example to another object that takes and "Animal" type an calls speak on it. If you do it don't you would have to check for dog type, cat type, and so on. Not sure if instance checking is really "Pythonic", beca...
1
2012-07-11T14:14:27Z
[ "python", "oop", "inheritance" ]
Browser automation: Python + Firefox using PyXPCOM
1,020,524
<p>I have tried <a href="http://pamie.sourceforge.net/" rel="nofollow">Pamie</a> a browser automation library for internet explorer. It interfaces IE using COM, pretty neat:</p> <pre><code>import PAM30 ie = PAM30.PAMIE("http://user-agent-string.info/") ie.clickButton("Analyze my UA") </code></pre> <p>Now I would like...
5
2009-06-19T23:50:57Z
1,022,369
<p>If you're testing a webapp and want to write Python to do it, check out <a href="http://seleniumhq.org/projects/remote-control/" rel="nofollow">Selenium RC</a> so you can use the same API for all browsers. </p>
2
2009-06-20T19:39:35Z
[ "python", "firefox", "automation" ]
Browser automation: Python + Firefox using PyXPCOM
1,020,524
<p>I have tried <a href="http://pamie.sourceforge.net/" rel="nofollow">Pamie</a> a browser automation library for internet explorer. It interfaces IE using COM, pretty neat:</p> <pre><code>import PAM30 ie = PAM30.PAMIE("http://user-agent-string.info/") ie.clickButton("Analyze my UA") </code></pre> <p>Now I would like...
5
2009-06-19T23:50:57Z
1,022,375
<p>I've used <a href="http://pypi.python.org/pypi/webdriver/0.5">webdriver</a> with firefox. I was very pleased with it.</p> <p>As for the code examples, <a href="http://code.google.com/p/webdriver/wiki/PythonBindings">this</a> will get you started.</p>
10
2009-06-20T19:42:04Z
[ "python", "firefox", "automation" ]
Browser automation: Python + Firefox using PyXPCOM
1,020,524
<p>I have tried <a href="http://pamie.sourceforge.net/" rel="nofollow">Pamie</a> a browser automation library for internet explorer. It interfaces IE using COM, pretty neat:</p> <pre><code>import PAM30 ie = PAM30.PAMIE("http://user-agent-string.info/") ie.clickButton("Analyze my UA") </code></pre> <p>Now I would like...
5
2009-06-19T23:50:57Z
1,057,354
<p>My understanding of PyXPCOM is that it's meant to let you create and access XPCOM components, not control existing ones. You may not be able to do this using PyXPCOM at all, per Mark Hammond, the original author:</p> <blockquote> <p><a href="http://mail.python.org/pipermail/python-win32/2004-October/002569.html"...
4
2009-06-29T09:17:20Z
[ "python", "firefox", "automation" ]
Is there a better way to convert a list to a dictionary in Python with keys but no values?
1,020,722
<p>I was sure that there would be a one liner to convert a list to a dictionary where the items in the list were keys and the dictionary had no values.</p> <p>The only way I could find to do it was argued against.</p> <p>"Using list comprehensions when the result is ignored is misleading and inefficient. A <code>for<...
6
2009-06-20T01:43:49Z
1,020,724
<p>Use <code>dict.fromkeys</code>:</p> <pre><code>&gt;&gt;&gt; my_list = [1, 2, 3] &gt;&gt;&gt; dict.fromkeys(my_list) {1: None, 2: None, 3: None} </code></pre> <p>Values default to <code>None</code>, but you can specify them as an optional argument:</p> <pre><code>&gt;&gt;&gt; my_list = [1, 2, 3] &gt;&gt;&gt; dict....
22
2009-06-20T01:48:05Z
[ "python", "list", "dictionary", "list-comprehension" ]
Is there a better way to convert a list to a dictionary in Python with keys but no values?
1,020,722
<p>I was sure that there would be a one liner to convert a list to a dictionary where the items in the list were keys and the dictionary had no values.</p> <p>The only way I could find to do it was argued against.</p> <p>"Using list comprehensions when the result is ignored is misleading and inefficient. A <code>for<...
6
2009-06-20T01:43:49Z
1,020,728
<p>You could use a <a href="http://docs.python.org/library/stdtypes.html#set-types-set-frozenset">set</a> instead of a dict:</p> <pre><code>&gt;&gt;&gt; myList=['a','b','c','d'] &gt;&gt;&gt; set(myList) set(['a', 'c', 'b', 'd']) </code></pre> <p>This is better if you never need to store values, and are just storing a...
15
2009-06-20T01:49:34Z
[ "python", "list", "dictionary", "list-comprehension" ]
Is there a better way to convert a list to a dictionary in Python with keys but no values?
1,020,722
<p>I was sure that there would be a one liner to convert a list to a dictionary where the items in the list were keys and the dictionary had no values.</p> <p>The only way I could find to do it was argued against.</p> <p>"Using list comprehensions when the result is ignored is misleading and inefficient. A <code>for<...
6
2009-06-20T01:43:49Z
1,020,732
<p>And here's a fairly wrong and inefficient way to do it using map:</p> <pre><code>&gt;&gt;&gt; d = dict() &gt;&gt;&gt; map (lambda x: d.__setitem__(x, None), [1,2,3]) [None, None, None] &gt;&gt;&gt; d {1: None, 2: None, 3: None} </code></pre>
1
2009-06-20T01:54:00Z
[ "python", "list", "dictionary", "list-comprehension" ]
Is there a better way to convert a list to a dictionary in Python with keys but no values?
1,020,722
<p>I was sure that there would be a one liner to convert a list to a dictionary where the items in the list were keys and the dictionary had no values.</p> <p>The only way I could find to do it was argued against.</p> <p>"Using list comprehensions when the result is ignored is misleading and inefficient. A <code>for<...
6
2009-06-20T01:43:49Z
1,021,036
<p>To answer the original questioner's performance worries (for lookups in <code>dict</code> vs <code>set</code>), somewhat surprisingly, <code>dict</code> lookups <em>can</em> be minutely faster (in Python 2.5.1 on my rather slow laptop) assuming for example that half the lookups fail and half succeed. Here's how one ...
5
2009-06-20T05:37:39Z
[ "python", "list", "dictionary", "list-comprehension" ]
Is there a better way to convert a list to a dictionary in Python with keys but no values?
1,020,722
<p>I was sure that there would be a one liner to convert a list to a dictionary where the items in the list were keys and the dictionary had no values.</p> <p>The only way I could find to do it was argued against.</p> <p>"Using list comprehensions when the result is ignored is misleading and inefficient. A <code>for<...
6
2009-06-20T01:43:49Z
1,021,116
<p>You can use a list comprehension:</p> <pre><code>my_list = ['a','b','c','d'] my_dict = dict([(ele, None) for ele in my_list]) </code></pre>
1
2009-06-20T07:04:57Z
[ "python", "list", "dictionary", "list-comprehension" ]
Is there a better way to convert a list to a dictionary in Python with keys but no values?
1,020,722
<p>I was sure that there would be a one liner to convert a list to a dictionary where the items in the list were keys and the dictionary had no values.</p> <p>The only way I could find to do it was argued against.</p> <p>"Using list comprehensions when the result is ignored is misleading and inefficient. A <code>for<...
6
2009-06-20T01:43:49Z
1,021,309
<p>Maybe you can use itertools:</p> <pre><code>&gt;&gt;&gt;import itertools &gt;&gt;&gt;my_list = ['a','b','c','d'] &gt;&gt;&gt;d = {} &gt;&gt;&gt;for x in itertools.imap(d.setdefault, my_list): pass &gt;&gt;&gt;print d {'a': None, 'c': None, 'b': None, 'd': None} </code></pre> <p>For huge lists, maybe this is very g...
1
2009-06-20T09:33:52Z
[ "python", "list", "dictionary", "list-comprehension" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
1,020,831
<p>Well django 1.0 was updated today on Google AppEngine. But you can make user authentication like anything else you just can't really use sessions because it is so massive. </p> <p>There is a session utility in <a href="http://gaeutilities.appspot.com/">http://gaeutilities.appspot.com/</a> </p> <p><a href="http://g...
19
2009-06-20T03:03:14Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
1,020,836
<p>The <a href="http://code.google.com/p/google-app-engine-samples/source/browse/#svn/trunk/openid-consumer" rel="nofollow">OpenID consumer</a> (part of the excellent "app engine samples" open source project) currently works (despite the warnings in its README, which is old) and would let you use OpenID for your users'...
8
2009-06-20T03:06:55Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
1,298,669
<p>Have a look <a href="http://code.google.com/p/app-engine-patch/" rel="nofollow">app-engine-patch</a> for Django (your preferred framework I assume from your question). It offers authentication on gae.</p> <p>Alternatively, take a look at <a href="http://www.web2py.com" rel="nofollow">web2py</a>. It's a Python-based...
4
2009-08-19T09:11:06Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
9,187,632
<p>I saw that this pops up in google, every time you search "Custom login in app engine" so I decided to give an answer that has been serving me. Here is sample application <a href="https://github.com/fredrikbonander/Webapp2-Sample-Applications">https://github.com/fredrikbonander/Webapp2-Sample-Applications</a></p> <p...
8
2012-02-08T03:51:34Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
10,318,234
<p>This is a pretty out-of-the-box solution, and works pretty well: <a href="http://code.scotchmedia.com/engineauth/docs/index.html">http://code.scotchmedia.com/engineauth/docs/index.html</a></p> <p>It has built-in support for Facebook, Google+, Twitter, LinkedIn, GitHub and OpenId (via Google App Engine).</p> <p>yo...
10
2012-04-25T14:54:34Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
10,318,522
<p>In addition to all the other great answers, I would also add that <a href="https://developers.facebook.com/docs/authentication/" rel="nofollow">Facebook</a>, <a href="https://dev.twitter.com/docs/auth/oauth/single-user-with-examples" rel="nofollow">Twitter</a>, and <a href="http://github.com" rel="nofollow">github</...
1
2012-04-25T15:10:52Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
11,302,159
<p>I googled around for a custom authenication system for app engine for a while. I eventually settled for running flask on app engine. I used this boilerplate for running flask on app engine <a href="https://github.com/kamalgill/flask-appengine-template/" rel="nofollow">https://github.com/kamalgill/flask-appengine-t...
2
2012-07-02T22:45:02Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
11,701,813
<p>Take a look at this project I am working on with coto: <a href="https://github.com/coto/gae-boilerplate" rel="nofollow">https://github.com/coto/gae-boilerplate</a> It includes a fully featured custom authentication system and much more.</p>
1
2012-07-28T14:21:57Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
12,097,171
<p>Another option is the <a href="http://beaker.readthedocs.org/en/latest/index.html" rel="nofollow">Beaker module</a>. The AES encryption for client side sessions is nice.</p>
1
2012-08-23T17:34:18Z
[ "python", "google-app-engine", "authentication" ]
Custom authentication in google app engine (python)
1,020,736
<p>Does anyone know or know of somewhere I can learn how to create a custom authentication process using python and google app engine?</p> <p>I don't want to use google accounts for authentication and want to be able to create my own users.</p> <p>If not specifically for google app engine, any resource on how to impl...
36
2009-06-20T01:56:48Z
15,499,866
<p>Here is an excellent and relatively recent (Jan 2013) blog post titled <a href="http://blog.abahgat.com/2013/01/07/user-authentication-with-webapp2-on-google-app-engine/">User authentication with webapp2 on Google App Engine</a>, and related <a href="https://github.com/abahgat/webapp2-user-accounts">GitHub repo: <co...
6
2013-03-19T12:44:15Z
[ "python", "google-app-engine", "authentication" ]
Python database application frame work and tools
1,020,775
<p>I have been building business database applications such as finance, inventory and other business requirement applications. I am planning to shift to Python. What would be the tools to start with best. I would need to do master, transaction forms, processing (back end), reports and that sort of thing. The database w...
7
2009-06-20T02:22:57Z
1,020,796
<p>If I were you I would start with <a href="http://docs.djangoproject.com/en/dev/" rel="nofollow">django</a>.</p>
3
2009-06-20T02:40:48Z
[ "python", "frame" ]
Python database application frame work and tools
1,020,775
<p>I have been building business database applications such as finance, inventory and other business requirement applications. I am planning to shift to Python. What would be the tools to start with best. I would need to do master, transaction forms, processing (back end), reports and that sort of thing. The database w...
7
2009-06-20T02:22:57Z
1,020,822
<p>As Boudewijn Rempt wrote <a href="http://www.informit.com/articles/article.aspx?p=30649&amp;seqNum=7" rel="nofollow">here</a>, "for the easiest way to create a [[NON-web]] database application, you might want to take a look at <a href="http://www.riverbankcomputing.co.uk/software/pyqt/intro" rel="nofollow">PyQt</a>"...
1
2009-06-20T02:56:40Z
[ "python", "frame" ]
Python database application frame work and tools
1,020,775
<p>I have been building business database applications such as finance, inventory and other business requirement applications. I am planning to shift to Python. What would be the tools to start with best. I would need to do master, transaction forms, processing (back end), reports and that sort of thing. The database w...
7
2009-06-20T02:22:57Z
1,021,065
<p>If your application needs to work both on the desktop and on the web in the future, you can consider creating a web-based application with a distributable server. Such things are pretty easy to do with Python both in trivial ways and in more powerful ones such as using Twisted.</p> <p>If desktop only is your direct...
1
2009-06-20T06:13:06Z
[ "python", "frame" ]
Python database application frame work and tools
1,020,775
<p>I have been building business database applications such as finance, inventory and other business requirement applications. I am planning to shift to Python. What would be the tools to start with best. I would need to do master, transaction forms, processing (back end), reports and that sort of thing. The database w...
7
2009-06-20T02:22:57Z
1,021,195
<p>just FYI, for PyQT, the book has a chapter 15 with Databases, It looks good. and the book has something with data and view etc. I have read it and I think it's well worth your time:)</p>
0
2009-06-20T08:02:24Z
[ "python", "frame" ]
Python database application frame work and tools
1,020,775
<p>I have been building business database applications such as finance, inventory and other business requirement applications. I am planning to shift to Python. What would be the tools to start with best. I would need to do master, transaction forms, processing (back end), reports and that sort of thing. The database w...
7
2009-06-20T02:22:57Z
1,021,313
<p>If I were you, I would probably first look whether a web-based solution based on Django does the trick. If you need a little bit better look and feel, add jQuery to the mix. If it provides way too little functionality, go for PyQt. If you have a lot of very small applications, go for a mix of technologies. Below, yo...
9
2009-06-20T09:37:32Z
[ "python", "frame" ]
When you write a Titanium app, is the source code visible to users?
1,020,838
<p>When you write an HTML/CSS/JavaScript app for Adobe AIR, the source files sit in a directory visible to anyone who looks.</p> <p><a href="http://www.appcelerator.com/products/titanium-desktop/" rel="nofollow">Appcelerator Titanium</a> lets you code in JavaScript, Python, and Ruby. Is the bundling similar to AIR, wi...
2
2009-06-20T03:08:01Z
1,026,147
<p>According to the <a href="http://titaniumapp.com/faq/if-i-build-my-app-in-titanium-and-distribute-it-is-the-source-code-visible-to-the-user-in-other-words-can-the-program-be-compiled-into-a-binary-format">Titanium FAQ</a>, yes, your source code will be accessible to anyone who looks for it.</p>
5
2009-06-22T08:54:22Z
[ "javascript", "python", "ruby", "ria", "titanium" ]
When you write a Titanium app, is the source code visible to users?
1,020,838
<p>When you write an HTML/CSS/JavaScript app for Adobe AIR, the source files sit in a directory visible to anyone who looks.</p> <p><a href="http://www.appcelerator.com/products/titanium-desktop/" rel="nofollow">Appcelerator Titanium</a> lets you code in JavaScript, Python, and Ruby. Is the bundling similar to AIR, wi...
2
2009-06-20T03:08:01Z
3,013,019
<p>As <a href="http://stackoverflow.com/users/61027/nosredna">Nosredna</a> added in the comment they seem to have gotten arround to that change in their newer framework versions. </p> <p>Look at this <a href="http://stackoverflow.com/questions/2444001/how-does-appcelerator-titanium-mobile-work">question</a> to get som...
2
2010-06-10T09:04:43Z
[ "javascript", "python", "ruby", "ria", "titanium" ]
How to make a simple command-line chat in Python?
1,020,839
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PO...
10
2009-06-20T03:08:03Z
1,020,852
<p>If you want to code it from scratch <code>select</code> is the way to go (and you can read on Google Book Search most of the chapter of Python in a Nutshell that covers such matters); if you want to leverage more abstraction, <code>asyncore</code> is usable, but <a href="http://twistedmatrix.com/trac/">Twisted</a> i...
5
2009-06-20T03:12:45Z
[ "python" ]
How to make a simple command-line chat in Python?
1,020,839
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PO...
10
2009-06-20T03:08:03Z
1,020,853
<p>You should use <a href="http://linux.die.net/man/2/select" rel="nofollow">select</a>.</p> <p>Check:</p> <ul> <li><a href="http://docs.python.org/library/select.html" rel="nofollow">Another select link</a></li> <li><a href="http://www.amk.ca/python/howto/sockets/" rel="nofollow">howto</a></li> </ul>
1
2009-06-20T03:14:06Z
[ "python" ]
How to make a simple command-line chat in Python?
1,020,839
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PO...
10
2009-06-20T03:08:03Z
1,020,859
<p>I wrote one in async I/O... its a lot easier to wrap your head around than a full threading model.</p> <p>if you can get your hands ahold of "talk"'s source code, you can learn a lot about it. see a demo <a href="http://dsl.org/cookbook/cookbook_40.html#SEC559" rel="nofollow">http://dsl.org/cookbook/cookbook_40.h...
1
2009-06-20T03:19:09Z
[ "python" ]
How to make a simple command-line chat in Python?
1,020,839
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PO...
10
2009-06-20T03:08:03Z
1,021,399
<p>Chat programs are doing two things concurrently.</p> <ol> <li><p>Watching the local user's keyboard and sending to the remote user (via a socket of some kind)</p></li> <li><p>Watching the remote socket and displaying what they type on the local console.</p></li> </ol> <p>You have several ways to do this.</p> <ol>...
1
2009-06-20T10:45:08Z
[ "python" ]
How to make a simple command-line chat in Python?
1,020,839
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PO...
10
2009-06-20T03:08:03Z
1,021,683
<p>Well, well, here's what I am having at this very moment.</p> <p>Server goes like this:</p> <pre><code>import asyncore import socket clients = {} class MainServerSocket(asyncore.dispatcher): def __init__(self, port): asyncore.dispatcher.__init__(self) self.create_socket(socket.AF_INET, socket....
2
2009-06-20T13:58:47Z
[ "python" ]
How to make a simple command-line chat in Python?
1,020,839
<p>I study network programming and would like to write a simple command-line chat in Python.</p> <p>I'm wondering how make receving constant along with inputing available for sending at any time. </p> <p>As you see, this client can do only one job at a time:</p> <pre><code>from socket import * HOST = 'localhost' PO...
10
2009-06-20T03:08:03Z
1,023,232
<p>Your question was not very coherent. However, your program does not need to be asynchronous at all to attain what you are asking for.</p> <p>This is a working chat script you originally wanted with minimal changes. It uses 1 thread for receiving and 1 for sending, both using blocking sockets. It is far simpler than...
7
2009-06-21T04:52:44Z
[ "python" ]
urllib2 read to Unicode
1,020,892
<p>I need to store the content of a site that can be in any language. And I need to be able to search the content for a Unicode string.</p> <p>I have tried something like:</p> <pre><code>import urllib2 req = urllib2.urlopen('http://lenta.ru') content = req.read() </code></pre> <p>The content is a byte stream, so I ...
42
2009-06-20T03:46:27Z
1,020,931
<p>After the operations you performed, you'll see:</p> <pre><code>&gt;&gt;&gt; req.headers['content-type'] 'text/html; charset=windows-1251' </code></pre> <p>and so:</p> <pre><code>&gt;&gt;&gt; encoding=req.headers['content-type'].split('charset=')[-1] &gt;&gt;&gt; ucontent = unicode(content, encoding) </code></pre>...
90
2009-06-20T04:17:41Z
[ "python", "unicode", "urllib2" ]
urllib2 read to Unicode
1,020,892
<p>I need to store the content of a site that can be in any language. And I need to be able to search the content for a Unicode string.</p> <p>I have tried something like:</p> <pre><code>import urllib2 req = urllib2.urlopen('http://lenta.ru') content = req.read() </code></pre> <p>The content is a byte stream, so I ...
42
2009-06-20T03:46:27Z
20,714,761
<p>To parse <code>Content-Type</code> http header, you could use <code>cgi.parse_header</code> function:</p> <pre><code>import cgi import urllib2 r = urllib2.urlopen('http://lenta.ru') _, params = cgi.parse_header(r.headers.get('Content-Type', '')) encoding = params.get('charset', 'utf-8') unicode_text = r.read().dec...
8
2013-12-21T02:23:33Z
[ "python", "unicode", "urllib2" ]
Interacting with another command line program in Python
1,020,980
<p>I need to write a Python script that can run another command line program and interact with it's stdin and stdout streams. Essentially, the Python script will read from the target command line program, intelligently respond by writing to its stdin, and then read the results from the program again. (It would do this ...
6
2009-06-20T05:01:10Z
1,020,991
<p>see the question <a href="http://stackoverflow.com/questions/989129/wxpython-how-to-create-a-bash-shell-window/1005079#1005079">http://stackoverflow.com/questions/989129/wxpython-how-to-create-a-bash-shell-window/1005079#1005079</a></p> <p>there I have given a full fledged interaction with bash shell reading stdout...
2
2009-06-20T05:06:06Z
[ "python", "command-line", "subprocess" ]
Interacting with another command line program in Python
1,020,980
<p>I need to write a Python script that can run another command line program and interact with it's stdin and stdout streams. Essentially, the Python script will read from the target command line program, intelligently respond by writing to its stdin, and then read the results from the program again. (It would do this ...
6
2009-06-20T05:01:10Z
1,021,001
<p>To perform such detailed interaction (when, outside of your control, the other program may be buffering its output unless it thinks it's talking to a terminal) needs something like <a href="http://pexpect.sourceforge.net/pexpect.html">pexpect</a> -- which in turns requires <code>pty</code>, a Python standard library...
6
2009-06-20T05:12:42Z
[ "python", "command-line", "subprocess" ]
Package for creating and validating HTML forms in Python? - to be used in Google Appengine
1,021,411
<p>Is there a well maintained package available in Python for creating and validating HTML forms? I will deploying it finally on Google Appengine.</p>
1
2009-06-20T11:01:14Z
1,021,454
<p>AppEngine includes Django's form framework (or a variation thereof), which I find very nice. It also plays well with your ORM (i.e. getting forms for models is very DRY). The only potential problem is the lack of client-side validation.</p>
0
2009-06-20T11:29:34Z
[ "python", "html", "google-app-engine", "forms" ]
Package for creating and validating HTML forms in Python? - to be used in Google Appengine
1,021,411
<p>Is there a well maintained package available in Python for creating and validating HTML forms? I will deploying it finally on Google Appengine.</p>
1
2009-06-20T11:01:14Z
1,021,470
<p>For client-side validation, check <a href="http://plugins.jquery.com/search/node/form%2Bvalidate" rel="nofollow">http://plugins.jquery.com/search/node/form+validate</a>; for server-side, actually ALMOST every web framework (web.py, django, etc.) has its own form generation as well as validation lib for you to use.</...
2
2009-06-20T11:41:10Z
[ "python", "html", "google-app-engine", "forms" ]
Package for creating and validating HTML forms in Python? - to be used in Google Appengine
1,021,411
<p>Is there a well maintained package available in Python for creating and validating HTML forms? I will deploying it finally on Google Appengine.</p>
1
2009-06-20T11:01:14Z
1,021,930
<p>You can use <a href="http://code.google.com/appengine/articles/djangoforms.html" rel="nofollow">Django form validation</a> on GAE storage via <code>db.djangoforms.ModelForm</code>.</p> <p>To smoothly integrate client-side <a href="http://www.dojotoolkit.org/" rel="nofollow">Dojo</a> functionality with Django server...
2
2009-06-20T16:15:31Z
[ "python", "html", "google-app-engine", "forms" ]
How to call a property of the base class if this property is being overwritten in the derived class?
1,021,464
<p>I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties.</p> <p>But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with p...
50
2009-06-20T11:37:14Z
1,021,477
<p><a href="http://docs.python.org/3.0/library/functions.html?highlight=super#super">Super</a> should do the trick:</p> <pre><code>return super().bar </code></pre> <p>In Python 2.x you need to use the more verbose syntax:</p> <pre><code>return super(FooBar, self).bar </code></pre>
26
2009-06-20T11:46:49Z
[ "python", "inheritance", "properties", "overloading", "descriptor" ]
How to call a property of the base class if this property is being overwritten in the derived class?
1,021,464
<p>I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties.</p> <p>But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with p...
50
2009-06-20T11:37:14Z
1,021,482
<p>try</p> <pre><code>@property def bar: return super(FooBar, self).bar </code></pre> <p>Although I'm not sure if python supports calling the base class property. A property is actually a callable object which is set up with the function specified and then replaces that name in the class. This could easily mean t...
4
2009-06-20T11:50:09Z
[ "python", "inheritance", "properties", "overloading", "descriptor" ]
How to call a property of the base class if this property is being overwritten in the derived class?
1,021,464
<p>I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties.</p> <p>But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with p...
50
2009-06-20T11:37:14Z
1,021,484
<p>You might think you could call the base class function which is called by property:</p> <pre><code>class FooBar(Foo): @property def bar(self): # return the same value # as in the base class return Foo.bar(self) </code></pre> <p>Though this is the most obvious thing to try I think -...
55
2009-06-20T11:51:38Z
[ "python", "inheritance", "properties", "overloading", "descriptor" ]
How to call a property of the base class if this property is being overwritten in the derived class?
1,021,464
<p>I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties.</p> <p>But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with p...
50
2009-06-20T11:37:14Z
1,021,485
<pre><code> class Base(object): def method(self): print "Base method was called" class Derived(Base): def method(self): super(Derived,self).method() print "Derived method was called" d = Derived() d.method() </code></pre> <p>(that is unless I am missing something fr...
-1
2009-06-20T11:51:44Z
[ "python", "inheritance", "properties", "overloading", "descriptor" ]
How to call a property of the base class if this property is being overwritten in the derived class?
1,021,464
<p>I'm changing some classes of mine from an extensive use of getters and setters to a more pythonic use of properties.</p> <p>But now I'm stuck because some of my previous getters or setters would call the corresponding method of the base class, and then perform something else. But how can this be accomplished with p...
50
2009-06-20T11:37:14Z
37,663,266
<p>There is an alternative using <code>super</code> that does not require to explicitly reference the base class name.</p> <h2>Base class A:</h2> <pre class="lang-py prettyprint-override"><code>class A(object): def __init__(self): self._prop = None @property def prop(self): return self._p...
5
2016-06-06T17:14:41Z
[ "python", "inheritance", "properties", "overloading", "descriptor" ]
Problem with exiting a daemonized process
1,021,613
<p>I am writing a daemon program that spawns several other children processes. After I run the <code>stop</code> script, the main process keeps running when it's intended to quit, this really confused me.</p> <pre><code>import daemon, signal from multiprocessing import Process, cpu_count, JoinableQueue from http impor...
4
2009-06-20T13:22:22Z
1,034,694
<p>I tried a different approach, and this seems to work (note I took out the daemon portions of the code as I didn't have that module installed).</p> <pre><code>import signal class Manager: """ This manager starts the http server processes and worker processes, creates the input/output queues that keep th...
1
2009-06-23T19:34:59Z
[ "python", "daemon", "multiprocessing" ]
Problem with exiting a daemonized process
1,021,613
<p>I am writing a daemon program that spawns several other children processes. After I run the <code>stop</code> script, the main process keeps running when it's intended to quit, this really confused me.</p> <pre><code>import daemon, signal from multiprocessing import Process, cpu_count, JoinableQueue from http impor...
4
2009-06-20T13:22:22Z
1,035,672
<p>You create the http server process but don't <code>join()</code> it. What happens if, rather than doing an <code>os.kill()</code> to stop the http server process, you send it a stop-processing sentinel (<code>None</code>, like you send to the workers) and then do a <code>self.http.join()</code>?</p> <p><strong>Upd...
1
2009-06-23T22:49:26Z
[ "python", "daemon", "multiprocessing" ]
Probability time series, observed data probabilities (deja vu)
1,021,704
<p>okay folks...thanks for looking at this question. I remember doing the following below in college however I forgotten the exact solution. Any takers to steer in the right direction.</p> <p>I have a time series of data (we'll use three) of N. The data series is sequential in order of time (e.g. obsOne[1] occurred...
1
2009-06-20T14:16:21Z
1,022,285
<p>Are you talking about something like this?</p> <pre><code>from __future__ import division from collections import defaultdict obsOne= [47, 136, -108, -15, 22, ] obsTwo= [448, 321, 122, -207, 269, ] obsThree= [381, 283, 429, -393, 242, ] class BinParams( object ): def __init__( self, timeSeries, X ): s...
1
2009-06-20T19:10:47Z
[ "python", "probability", "time-series", "data-analysis" ]
Generating a 3D CAPTCHA [pic]
1,021,721
<p>I would like to write a Python script that would generate a 3D <a href="http://en.wikipedia.org/wiki/CAPTCHA" rel="nofollow">CAPTCHA</a> like this one: <img src="http://i.stack.imgur.com/60KlL.png" alt="teabag captcha"></p> <p>Which graphics libraries can I use?</p> <p>Source: <a href="http://ocr-research.org.ua/t...
11
2009-06-20T14:30:17Z
1,021,761
<p>I'm not sure I would bother with a full 3D library for what you have above. Just generate a matrix of 3D points, generate the text with something like PIL, scan over it to find which points on the grid are raised, pick a random camera angle and then project the points into a 2D image and draw them with PIL to the fi...
2
2009-06-20T14:43:12Z
[ "python", "graphics", "captcha" ]
Generating a 3D CAPTCHA [pic]
1,021,721
<p>I would like to write a Python script that would generate a 3D <a href="http://en.wikipedia.org/wiki/CAPTCHA" rel="nofollow">CAPTCHA</a> like this one: <img src="http://i.stack.imgur.com/60KlL.png" alt="teabag captcha"></p> <p>Which graphics libraries can I use?</p> <p>Source: <a href="http://ocr-research.org.ua/t...
11
2009-06-20T14:30:17Z
1,021,780
<p>Use Python bindings for OpenGL, <a href="http://pyopengl.sourceforge.net/" rel="nofollow">http://pyopengl.sourceforge.net/</a>.</p> <p>Create a 2D image of white color text over a black surface using <a href="http://en.wikipedia.org/wiki/Python_Imaging_Library" rel="nofollow">PIL</a>. Make a 3D grid from this, incr...
1
2009-06-20T14:51:05Z
[ "python", "graphics", "captcha" ]
Generating a 3D CAPTCHA [pic]
1,021,721
<p>I would like to write a Python script that would generate a 3D <a href="http://en.wikipedia.org/wiki/CAPTCHA" rel="nofollow">CAPTCHA</a> like this one: <img src="http://i.stack.imgur.com/60KlL.png" alt="teabag captcha"></p> <p>Which graphics libraries can I use?</p> <p>Source: <a href="http://ocr-research.org.ua/t...
11
2009-06-20T14:30:17Z
1,021,898
<p>Another binding to consider for rendering with opengl is <a href="http://www.pyglet.org/" rel="nofollow">pyglet</a>. Its best feature is that it is just one download. I think it contains everything you need to implement what Anurag spells out.</p> <p>I will caution you that what you're trying to do is not exactly...
4
2009-06-20T15:59:12Z
[ "python", "graphics", "captcha" ]
Generating a 3D CAPTCHA [pic]
1,021,721
<p>I would like to write a Python script that would generate a 3D <a href="http://en.wikipedia.org/wiki/CAPTCHA" rel="nofollow">CAPTCHA</a> like this one: <img src="http://i.stack.imgur.com/60KlL.png" alt="teabag captcha"></p> <p>Which graphics libraries can I use?</p> <p>Source: <a href="http://ocr-research.org.ua/t...
11
2009-06-20T14:30:17Z
1,022,263
<p>There are many approaches. I would personally create the image in Python Imaging Library using <a href="http://www.pythonware.com/library/pil/handbook/imagedraw.htm">ImageDraw</a>'s draw.text, convert to a <a href="http://en.wikipedia.org/wiki/NumPy">NumPy</a> array (usint NumPy's <a href="http://effbot.org/zone/pi...
32
2009-06-20T19:04:57Z
[ "python", "graphics", "captcha" ]
Can I use pywikipedia to get just the text of a page?
1,021,884
<p>Is it possible, using pywikipedia, to get just the text of the page, without any of the internal links or templates &amp; without the pictures etc.?</p>
1
2009-06-20T15:49:27Z
1,023,301
<p>If you mean "I want to get the wikitext only", then look at the <code>wikipedia.Page</code> class, and the <code>get</code> method.</p> <pre><code>import wikipedia site = wikipedia.getSite('en', 'wikipedia') page = wikipedia.Page(site, 'Test') print page.get() # '''Test''', '''TEST''' or '''Tester''' may refer to...
4
2009-06-21T06:00:55Z
[ "python", "wiki", "mediawiki", "pywikipedia" ]
Can I use pywikipedia to get just the text of a page?
1,021,884
<p>Is it possible, using pywikipedia, to get just the text of the page, without any of the internal links or templates &amp; without the pictures etc.?</p>
1
2009-06-20T15:49:27Z
20,389,739
<p>There is a module called <a href="https://github.com/earwig/mwparserfromhell" rel="nofollow">mwparserfromhell on Github</a> that can get you very close to what you want depending on what you need. It has a method called strip_code(), that strips a lot of the markup.</p> <pre><code>import pywikibot import mwparserfr...
0
2013-12-05T01:35:27Z
[ "python", "wiki", "mediawiki", "pywikipedia" ]
Checking compatibility of two python functions (or methods)
1,022,124
<p>Is there a possibility to check if two python functions are interchangeable? For instance, if I have</p> <pre><code>def foo(a, b): pass def bar(x, y): pass def baz(x,y,z): pass </code></pre> <p>I would like a function <code>is_compatible(a,b)</code> that returns True when passed foo and bar, but False ...
2
2009-06-20T17:57:48Z
1,022,132
<p>Take a look at <a href="http://docs.python.org/library/inspect.html#classes-and-functions" rel="nofollow"><code>inspect.getargspec()</code></a>:</p> <blockquote> <h3><code>inspect.getargspec(func)</code></h3> <p>Get the names and default values of a function’s arguments. A tuple of four things is ret...
3
2009-06-20T18:02:07Z
[ "python", "reflection" ]
Checking compatibility of two python functions (or methods)
1,022,124
<p>Is there a possibility to check if two python functions are interchangeable? For instance, if I have</p> <pre><code>def foo(a, b): pass def bar(x, y): pass def baz(x,y,z): pass </code></pre> <p>I would like a function <code>is_compatible(a,b)</code> that returns True when passed foo and bar, but False ...
2
2009-06-20T17:57:48Z
1,022,133
<p>What would you be basing the compatibility on? The number of arguments? Python has variable length argument lists, so you never know if two functions might be compatible in that sense. Data types? Python uses duck typing, so until you use an isinstance test or similar inside the function, there is no constraint on d...
4
2009-06-20T18:02:27Z
[ "python", "reflection" ]
Best way to randomize a list of strings in Python
1,022,141
<p>I receive as input a list of strings and need to return a list with these same strings but in randomized order. I must allow for duplicates - same string may appear once or more in the input and must appear the same number of times in the output.</p> <p>I see several "brute force" ways of doing that (using loops, g...
64
2009-06-20T18:05:44Z
1,022,145
<p>Looks like this is the simplest way, if not the most truly random (<a href="https://stackoverflow.com/questions/3062741/maximal-length-of-list-to-shuffle-with-python-random-shuffle">this question</a> more fully explains the limitations): <a href="http://docs.python.org/library/random.html#random.shuffle" rel="nofoll...
13
2009-06-20T18:07:44Z
[ "python", "string", "random" ]
Best way to randomize a list of strings in Python
1,022,141
<p>I receive as input a list of strings and need to return a list with these same strings but in randomized order. I must allow for duplicates - same string may appear once or more in the input and must appear the same number of times in the output.</p> <p>I see several "brute force" ways of doing that (using loops, g...
64
2009-06-20T18:05:44Z
1,022,151
<pre><code>&gt;&gt;&gt; import random &gt;&gt;&gt; x = [1, 2, 3, 4, 3, 4] &gt;&gt;&gt; random.shuffle(x) &gt;&gt;&gt; x [4, 4, 3, 1, 2, 3] &gt;&gt;&gt; random.shuffle(x) &gt;&gt;&gt; x [3, 4, 2, 1, 3, 4] </code></pre>
162
2009-06-20T18:09:19Z
[ "python", "string", "random" ]
Best way to randomize a list of strings in Python
1,022,141
<p>I receive as input a list of strings and need to return a list with these same strings but in randomized order. I must allow for duplicates - same string may appear once or more in the input and must appear the same number of times in the output.</p> <p>I see several "brute force" ways of doing that (using loops, g...
64
2009-06-20T18:05:44Z
1,022,154
<p>You'll have to read the strings into an array and then use a shuffling algorithm. I recommend <a href="http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates%5Fshuffle" rel="nofollow">Fisher-Yates shuffle</a></p>
3
2009-06-20T18:12:13Z
[ "python", "string", "random" ]
Best way to randomize a list of strings in Python
1,022,141
<p>I receive as input a list of strings and need to return a list with these same strings but in randomized order. I must allow for duplicates - same string may appear once or more in the input and must appear the same number of times in the output.</p> <p>I see several "brute force" ways of doing that (using loops, g...
64
2009-06-20T18:05:44Z
3,568,748
<p>Given a string <em>item</em>, here is a one-liner: </p> <pre><code>''.join([str(w) for w in random.sample(item, len(item))]) </code></pre>
4
2010-08-25T17:45:50Z
[ "python", "string", "random" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
1,022,265
<p>Try Ctrl+K.</p>
18
2009-06-20T19:05:17Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
1,022,270
<p><kbd>CTRL</kbd>+<kbd>Q</kbd> Block comment/uncomment.</p> <p>More <a href="http://sourceforge.net/apps/mediawiki/notepad-plus/index.php?title=Keyboard_And_Mouse_Shortcuts">Notepad++ keyboard shortcuts</a>.</p>
90
2009-06-20T19:06:48Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
4,318,460
<p>for .sql files <kbd>Ctrl</kbd>+<kbd>K</kbd> or <kbd>Ctrl</kbd>+<kbd>Q</kbd> does not work.</p> <p>to insert comments in .sql files in Notepad++ try <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Q</kbd></p> <p>(there is no shortcut to uncomment the code block though. I have tried that on v5.8.2 ) </p>
7
2010-11-30T20:49:20Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
21,064,238
<p>This link was exactly what I was searching for .</p> <p>Let me summarize the answers for others' benefit (<strong>for python and notepad++</strong>)</p> <p>1) <strong>Ctrl + K</strong> on multiple lines (i.e. selected region) allows you to <strong><em>block comment</em></strong>. </p> <p>Also note that pressing t...
9
2014-01-11T15:41:17Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
25,138,274
<p>Yes in <strong>Notepad++</strong> you can do that!</p> <p>Some hotkeys regarding comments:</p> <ul> <li><kbd>Ctrl+Q</kbd> Toggle block comment</li> <li><kbd>Ctrl+K</kbd> Block comment</li> <li><kbd>Ctrl+Shift+K</kbd> Block uncomment</li> <li><kbd>Ctrl+Shift+Q</kbd> Stream comment</li> </ul> <p>Source: <a ...
5
2014-08-05T11:58:25Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
28,001,389
<p>In your n++ editor, you can go to <strong><em>Setting</em></strong> > <strong><em>Shortcut mapper</em></strong> and find all shortcut information as well as you can edit them :)</p>
0
2015-01-17T16:07:20Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
33,506,958
<p>Two ways for block commenting:</p> <ol> <li>Ctrl+Shift+Q</li> </ol> <p>or </p> <ol> <li>Select the block</li> <li>Alt + Right click</li> <li>Choose block comment.</li> </ol>
0
2015-11-03T18:56:48Z
[ "python", "comments", "notepad++" ]
Commenting code in Notepad++
1,022,261
<p>I'm using Notepad++ as an editor to write programs in Python. It might sound daft but I looked around in the editor and could not find any means (not the manual way but something like in Emacs) to do a block comment in my code.</p> <p>Since so many language settings are supported in Notepad++, I'm curious to find a...
67
2009-06-20T19:03:15Z
33,527,432
<p>Use shortcut: Ctrl+Q. You can customize in Settings</p>
0
2015-11-04T16:48:42Z
[ "python", "comments", "notepad++" ]
Python behavior of string in loop
1,022,264
<p>In trying to capitalize a string at separators I encountered behavior I do not understand. Can someone please explain why the string s in reverted during the loop? Thanks.</p> <pre><code>s = 'these-three_words' seperators = ('-','_') for sep in seperators: s = sep.join([i.capitalize() for i in s.split(s...
1
2009-06-20T19:05:08Z
1,022,288
<p><a href="http://docs.python.org/library/stdtypes.html#str.capitalize" rel="nofollow"><code>capitalize</code></a> turns the first character uppercase and the rest of the string lowercase.</p> <p>In the first iteration, it looks like this:</p> <pre><code>&gt;&gt;&gt; [i.capitalize() for i in s.split('-')] ['These', ...
6
2009-06-20T19:11:56Z
[ "python", "string", "loops" ]
Python behavior of string in loop
1,022,264
<p>In trying to capitalize a string at separators I encountered behavior I do not understand. Can someone please explain why the string s in reverted during the loop? Thanks.</p> <pre><code>s = 'these-three_words' seperators = ('-','_') for sep in seperators: s = sep.join([i.capitalize() for i in s.split(s...
1
2009-06-20T19:05:08Z
1,022,291
<p><code>str.capitalize</code> capitalizes the first character and lowercases the remaining characters.</p>
2
2009-06-20T19:12:47Z
[ "python", "string", "loops" ]
Python behavior of string in loop
1,022,264
<p>In trying to capitalize a string at separators I encountered behavior I do not understand. Can someone please explain why the string s in reverted during the loop? Thanks.</p> <pre><code>s = 'these-three_words' seperators = ('-','_') for sep in seperators: s = sep.join([i.capitalize() for i in s.split(s...
1
2009-06-20T19:05:08Z
1,022,298
<p>You could use <a href="http://docs.python.org/library/stdtypes.html#str.title" rel="nofollow"><code>title()</code></a>:</p> <pre><code>&gt;&gt;&gt; s = 'these-three_words' &gt;&gt;&gt; print s.title() These-Three_Words </code></pre>
5
2009-06-20T19:14:28Z
[ "python", "string", "loops" ]
Python behavior of string in loop
1,022,264
<p>In trying to capitalize a string at separators I encountered behavior I do not understand. Can someone please explain why the string s in reverted during the loop? Thanks.</p> <pre><code>s = 'these-three_words' seperators = ('-','_') for sep in seperators: s = sep.join([i.capitalize() for i in s.split(s...
1
2009-06-20T19:05:08Z
1,022,301
<p>Capitalize() will return a copy of the string with <b>only its first character</b> capitalized. You could use this:</p> <pre> def cap(s): return s[0].upper() + s[1:] </pre>
2
2009-06-20T19:15:07Z
[ "python", "string", "loops" ]
StringListProperty in GAE
1,022,382
<p>Is there any way to edit StringListProperty fields via Google's Data Viewer, or some other clever approach?</p> <p>The last I want to do is to modify my application in such way that it provides special throwaway page for just that reason - I don't feel like it's the optimal solution.</p> <p>Cheers,</p> <p>MH</p>
1
2009-06-20T19:48:30Z
1,022,444
<p>I would recommend using the <a href="http://code.google.com/appengine/articles/remote%5Fapi.html" rel="nofollow">Remote API</a>; you can edit anything in your datastore with a minimum of fuss and no special pages needed.</p>
2
2009-06-20T20:17:27Z
[ "python", "google-app-engine" ]