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
Appengine - Possible to get an entity using only key string without model name?
776,324
<p>I want to be able to have a view that will act upon a number of different types of objects</p> <p>all the view will get is the key string eg:</p> <p>agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww</p> <p>without knowing the model type, is it possible to retrieve the entity from just that key string?</p> <p>thank...
3
2009-04-22T09:15:04Z
918,507
<p>No superclassing required, just use db.get():</p> <pre><code>from google.appengine.ext import db key_str = 'agpwb2xsdGhyZWFkchULEg9wb2xsY29yZV9hbnN3ZXIYAww' entity = db.get(key_str) </code></pre>
11
2009-05-27T23:34:25Z
[ "python", "google-app-engine" ]
Qt-style documentation using Doxygen?
776,388
<p>How do I produce Qt-style documentation (Trolltech's C++ Qt or Riverbank's PyQt docs) with Doxygen? I am documenting Python, and I would like to be able to improve the default function brief that it produces.</p> <p>In particular, I would like to be able to see the return type (which can be user specified) and the ...
3
2009-04-22T09:38:34Z
776,468
<p>If you're doing anything documentation related when it comes to Python I recommend <a href="http://sphinx.pocoo.org/" rel="nofollow" title="Sphinx">Sphinx</a>. It's what the developers of python use for their documentation.</p>
1
2009-04-22T10:01:16Z
[ "python", "documentation", "doxygen" ]
Qt-style documentation using Doxygen?
776,388
<p>How do I produce Qt-style documentation (Trolltech's C++ Qt or Riverbank's PyQt docs) with Doxygen? I am documenting Python, and I would like to be able to improve the default function brief that it produces.</p> <p>In particular, I would like to be able to see the return type (which can be user specified) and the ...
3
2009-04-22T09:38:34Z
776,577
<p><a href="http://doc.trolltech.com/4.4/qthelp.html" rel="nofollow">This page</a> seem to detail the method of creating a qt-style docs.<br /> basically there's a tool you get with qt called <code>qhelpgenerator</code> which creates a <code>.qch</code> file, edible by the qt assistant.<br /> I haven't used it before b...
0
2009-04-22T10:44:12Z
[ "python", "documentation", "doxygen" ]
Qt-style documentation using Doxygen?
776,388
<p>How do I produce Qt-style documentation (Trolltech's C++ Qt or Riverbank's PyQt docs) with Doxygen? I am documenting Python, and I would like to be able to improve the default function brief that it produces.</p> <p>In particular, I would like to be able to see the return type (which can be user specified) and the ...
3
2009-04-22T09:38:34Z
777,981
<p>Then just use Doxygen? <a href="http://internetducttape.com/2007/03/20/automatic%5Fdocumentation%5Fpython%5Fdoxygen/" rel="nofollow">This will get you started</a>:</p> <blockquote> <p>This is a guide for automatically generating documentation off of Python source code using Doxygen.</p> </blockquote> <p>Obvi...
2
2009-04-22T16:00:26Z
[ "python", "documentation", "doxygen" ]
Qt-style documentation using Doxygen?
776,388
<p>How do I produce Qt-style documentation (Trolltech's C++ Qt or Riverbank's PyQt docs) with Doxygen? I am documenting Python, and I would like to be able to improve the default function brief that it produces.</p> <p>In particular, I would like to be able to see the return type (which can be user specified) and the ...
3
2009-04-22T09:38:34Z
778,010
<p>You do not have to put doxygen comments in the code. You can put the documentation in other places. Check out <a href="http://www.stack.nl/~dimitri/doxygen/docblocks.html#structuralcommands" rel="nofollow">this</a> page in the doxygen manual. </p>
0
2009-04-22T16:07:32Z
[ "python", "documentation", "doxygen" ]
Simple webserver or web testing framework
776,495
<p>Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd par...
2
2009-04-22T10:17:32Z
776,505
<p>I would look into <a href="http://www.djangoproject.com/" rel="nofollow">Django</a>.</p>
0
2009-04-22T10:20:07Z
[ "python", "web-services", "testing", "web-applications" ]
Simple webserver or web testing framework
776,495
<p>Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd par...
2
2009-04-22T10:17:32Z
776,553
<p>You might be happiest with a WSGI service, since it's most like CGI.</p> <p>Look at <a href="http://werkzeug.pocoo.org/" rel="nofollow">werkzeug</a>.</p>
2
2009-04-22T10:36:19Z
[ "python", "web-services", "testing", "web-applications" ]
Simple webserver or web testing framework
776,495
<p>Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd par...
2
2009-04-22T10:17:32Z
776,604
<p>Take a look the standard module wsgiref:</p> <p><a href="https://docs.python.org/2.6/library/wsgiref.html" rel="nofollow">https://docs.python.org/2.6/library/wsgiref.html</a></p> <p>At the end of that page is a small example. Something like this could already be sufficient for your needs.</p>
2
2009-04-22T10:50:53Z
[ "python", "web-services", "testing", "web-applications" ]
Simple webserver or web testing framework
776,495
<p>Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd par...
2
2009-04-22T10:17:32Z
776,891
<p>Use <a href="http://cherrypy.org" rel="nofollow">cherrypy</a>, take a look at Hello World:</p> <pre><code>import cherrypy class HelloWorld(object): def index(self): return "Hello World!" index.exposed = True cherrypy.quickstart(HelloWorld()) </code></pre> <p>Run this code and you have a very fast...
4
2009-04-22T12:06:00Z
[ "python", "web-services", "testing", "web-applications" ]
Simple webserver or web testing framework
776,495
<p>Need to testcase a complex webapp which does some interacting with a remote 3rd party cgi based webservices. Iam planing to implement some of the 3rd party services in a dummy webserver, so that i have full controll about the testcases. Looking for a simple python http webserver or framework to emulate the 3rd par...
2
2009-04-22T10:17:32Z
794,358
<p>It might be simpler sense to mock (or stub, or whatever the term is) urllib, or whatever module you are using to communicate with the remote web-service?</p> <p>Even simply overriding <code>urllib.urlopen</code> might be enough:</p> <pre><code>import urllib from StringIO import StringIO class mock_response(String...
0
2009-04-27T16:52:21Z
[ "python", "web-services", "testing", "web-applications" ]
Using Twisted's twisted.web classes, how do I flush my outgoing buffers?
776,631
<p>I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header. I'm using this to test an http client which I want to set up to accept a long-term stream.</p> <p>The problem that has arisen is that my client request hangs until the <em>http.Request</em> calls self.finis...
9
2009-04-22T10:57:50Z
800,427
<p>The reason seems to be explained in the <a href="http://twistedmatrix.com/trac/wiki/FrequentlyAskedQuestions#WhydoesittakealongtimefordataIsendwithtransport.writetoarriveattheothersideoftheconnection" rel="nofollow">FAQ for twisted</a>. The twisted server does not actually write anything to the underlining connecti...
1
2009-04-29T00:41:01Z
[ "python", "twisted", "multipart-mixed-replace" ]
Using Twisted's twisted.web classes, how do I flush my outgoing buffers?
776,631
<p>I've made a simple http server using Twisted, which sends the Content-Type: multipart/x-mixed-replace header. I'm using this to test an http client which I want to set up to accept a long-term stream.</p> <p>The problem that has arisen is that my client request hangs until the <em>http.Request</em> calls self.finis...
9
2009-04-22T10:57:50Z
802,632
<p>Using <code>time.sleep()</code> prevents twisted from doing its job. To make it work you can't use <code>time.sleep()</code>, you must return control to twisted instead. The easiest way to modify your existing code to do that is by using <a href="http://twistedmatrix.com/documents/8.2.0/api/twisted.internet.defer.ht...
9
2009-04-29T14:30:35Z
[ "python", "twisted", "multipart-mixed-replace" ]
fastest way to store comment data python
777,090
<p>Hi I have a small comment shoutbox type cgi process running on a server and currently when someone leaves a comment I simply format that comment into html i.e</p> <p><code>&lt;p class="title"&gt;$title&lt;/p&gt; &lt;p class="comment"&gt;$comment&lt;/p&gt;</code></p> <p>and store in a flat file. Would it be faster ...
1
2009-04-22T12:56:55Z
777,119
<p>If a flat file is fast enough, then go with that, since it's very simple and accessible. Storing as XML and JSON but still using a flat file probably is very comparable in performance.</p> <p>You might want to consider (ignore this if you just left it out of your question) sanitizing/filtering the text, so that use...
3
2009-04-22T13:04:24Z
[ "python", "xml", "json" ]
fastest way to store comment data python
777,090
<p>Hi I have a small comment shoutbox type cgi process running on a server and currently when someone leaves a comment I simply format that comment into html i.e</p> <p><code>&lt;p class="title"&gt;$title&lt;/p&gt; &lt;p class="comment"&gt;$comment&lt;/p&gt;</code></p> <p>and store in a flat file. Would it be faster ...
1
2009-04-22T12:56:55Z
777,173
<p>XML is nice, clean way to store this type of data. In Python, you could use <a href="http://codespeak.net/lxml/tutorial.html" rel="nofollow">lxml</a> to create/update the file:</p> <pre><code>from lxml import etree P_XML = 'xml_file_path.xml' def save_comment(title_text, comment_text): comment = etree.Element(...
1
2009-04-22T13:19:06Z
[ "python", "xml", "json" ]
fastest way to store comment data python
777,090
<p>Hi I have a small comment shoutbox type cgi process running on a server and currently when someone leaves a comment I simply format that comment into html i.e</p> <p><code>&lt;p class="title"&gt;$title&lt;/p&gt; &lt;p class="comment"&gt;$comment&lt;/p&gt;</code></p> <p>and store in a flat file. Would it be faster ...
1
2009-04-22T12:56:55Z
777,388
<p>A flat-file is the fastest form of persistence. Period. There's no formatting, encoding, indexing, locking, or anything.</p> <p>JSON (and YAML) impose some overheads. They will be slower. There's some formatting that must be done.</p> <p>XML imposes more overheads than JSON/YAML. It will be slower still. The...
1
2009-04-22T14:08:08Z
[ "python", "xml", "json" ]
Python reflection - Can I use this to get the source code of a method definition
777,371
<p><strong>Duplicate of..</strong></p> <ul> <li><a href="http://stackoverflow.com/questions/427453/how-can-i-get-the-code-of-python-function">How can I get the code of python function?</a></li> <li><a href="http://stackoverflow.com/questions/334851/print-the-code-which-defined-a-lambda-function">print the code which d...
8
2009-04-22T14:05:23Z
777,395
<p><code>sayHello.func_code.co_code</code> returns a string that I think contains the compiled code of the method. Since Python is internally compiling the code to virtual machine bytecode, this might be all that's left.</p> <p>You can disassemble it, though:</p> <pre><code>import dis def sayHello(): print "hello"...
2
2009-04-22T14:09:07Z
[ "python", "reflection" ]
Python reflection - Can I use this to get the source code of a method definition
777,371
<p><strong>Duplicate of..</strong></p> <ul> <li><a href="http://stackoverflow.com/questions/427453/how-can-i-get-the-code-of-python-function">How can I get the code of python function?</a></li> <li><a href="http://stackoverflow.com/questions/334851/print-the-code-which-defined-a-lambda-function">print the code which d...
8
2009-04-22T14:05:23Z
777,403
<p>There is not a built-in function to get source code of a function, however, you could build you own if you have access to the source-code (it would be in your Python/lib directory).</p>
0
2009-04-22T14:10:02Z
[ "python", "reflection" ]
Python reflection - Can I use this to get the source code of a method definition
777,371
<p><strong>Duplicate of..</strong></p> <ul> <li><a href="http://stackoverflow.com/questions/427453/how-can-i-get-the-code-of-python-function">How can I get the code of python function?</a></li> <li><a href="http://stackoverflow.com/questions/334851/print-the-code-which-defined-a-lambda-function">print the code which d...
8
2009-04-22T14:05:23Z
777,875
<p>Use the inspect module:</p> <pre><code>import inspect import mymodule print inspect.getsource(mymodule.sayHello) </code></pre> <p>The function must be defined in a module that you import.</p>
16
2009-04-22T15:37:27Z
[ "python", "reflection" ]
Python reflection - Can I use this to get the source code of a method definition
777,371
<p><strong>Duplicate of..</strong></p> <ul> <li><a href="http://stackoverflow.com/questions/427453/how-can-i-get-the-code-of-python-function">How can I get the code of python function?</a></li> <li><a href="http://stackoverflow.com/questions/334851/print-the-code-which-defined-a-lambda-function">print the code which d...
8
2009-04-22T14:05:23Z
23,086,681
<p>To get the source of a method on a class instance do:</p> <pre><code>import inspect myobj = MyModel() print inspect.getsource(myobj.my_method) </code></pre> <p>Read more: <a href="https://docs.python.org/2/library/inspect.html#inspect.getsource" rel="nofollow">https://docs.python.org/2/library/inspect.html#inspect...
0
2014-04-15T14:28:37Z
[ "python", "reflection" ]
Django Form values without HTML escape
777,458
<p>I need to set the Django forms.ChoiceField to display the currency symbols. Since django forms escape all the HTML ASCII characters, I can't get the &amp;#36; ( <strong>&euro;</strong> ) or the &amp;pound; ( <strong>&pound;</strong> ) to display the currency symbol.</p> <pre><code>&lt;select id="id_currency" name=...
2
2009-04-22T14:22:14Z
777,528
<p>You can use "<a href="http://docs.djangoproject.com/en/dev/topics/templates/#how-to-turn-it-off" rel="nofollow">safe</a>" in the template or "<a href="http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#filters-and-auto-escaping" rel="nofollow">mark_safe</a>" in the view</p> <p><b>update</b></p> <pre>...
7
2009-04-22T14:36:34Z
[ "python", "django-forms", "currency", "symbols" ]
Efficient arbitrary-sized integer packing in Python
777,525
<p>The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()).</p>
11
2009-04-22T14:36:12Z
777,583
<p>As suggested by S.Lott in a comment, just convert the number to a string and pack that string. For example,</p> <pre><code>x = 2 ** 12345 struct.pack("40s", str(x)) </code></pre>
1
2009-04-22T14:46:59Z
[ "python", "byte" ]
Efficient arbitrary-sized integer packing in Python
777,525
<p>The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()).</p>
11
2009-04-22T14:36:12Z
777,610
<p>Assuming the poster wants to pack a large integer as a binary string, i.e. not use one byte of storage per digit in the number. One way of doing this seems to be:</p> <pre><code>import marshal a = 47L print marshal.dumps(a) </code></pre> <p>This prints:</p> <pre><code>'l\x01\x00\x00\x00/\x00' </code></pre> <p>I...
3
2009-04-22T14:52:01Z
[ "python", "byte" ]
Efficient arbitrary-sized integer packing in Python
777,525
<p>The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()).</p>
11
2009-04-22T14:36:12Z
777,746
<p>I take it you mean you only want to use as many bytes as you need to represent the number? e.g. if the number is:</p> <ul> <li>255 or less you'd use only 1 byte</li> <li>65535 or less 2 bytes</li> <li>16777215 or less 3 bytes</li> <li>etc etc</li> </ul> <p>On the Psion PDA they'd usually have some of packing schem...
1
2009-04-22T15:12:39Z
[ "python", "byte" ]
Efficient arbitrary-sized integer packing in Python
777,525
<p>The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()).</p>
11
2009-04-22T14:36:12Z
777,774
<p>Do you mean <em>something</em> like this:</p> <pre><code>def num_to_bytes(num): bytes = [] num = abs(num) # Because I am unsure about negatives... while num &gt; 0: bytes.append(chr(num % 256)) num &gt;&gt;= 8 return ''.join(reversed(bytes)) def bytes_to_num(bytes): num = 0 ...
5
2009-04-22T15:18:32Z
[ "python", "byte" ]
Efficient arbitrary-sized integer packing in Python
777,525
<p>The struct.pack() function allows converting integers of up to 64 bit to byte strings. What's the most efficient way to pack an even larger integer? I'd rather not add a dependency on non-standard modules like PyCrypto (which provides num_to_bytes()).</p>
11
2009-04-22T14:36:12Z
778,071
<p>This is a bit hacky, but you could go via the hex string representation, and there to binary with the hex codec:</p> <pre><code>&gt;&gt;&gt; a = 2**60 &gt;&gt;&gt; a 1152921504606846976L &gt;&gt;&gt; hex(a) '0x1000000000000000L' &gt;&gt;&gt; hex(a).rstrip("L")[2:].decode('hex') '\x10\x00\x00\x00\x00\x00\x00\x00' ...
1
2009-04-22T16:17:09Z
[ "python", "byte" ]
How do I set up a model to use an AutoField with a legacy database in Python?
777,778
<p>I have a legacy database with an integer set as a primary key. It was initially managed manually, but since we are wanting to move to django, the admin tool seemed to be the right place to start. I created the model and am trying to set the primary key to be an autofield. It doesn't seem to be remembering the old id...
1
2009-04-22T15:18:59Z
778,346
<p>The <em>DB</em> is responsible for managing the value of the ID. If you want to use AutoField, you have to change the column in the DB to use that. Django is <em>not</em> responsible for managing the generated ID</p>
2
2009-04-22T17:31:23Z
[ "python", "django", "oracle", "autofield" ]
Other than basic python syntax, what other key areas should I learn to get a website live?
777,924
<p>Other than basic python syntax, what other key areas should I learn to get a website live?</p> <p>Is there a web.config in the python world?</p> <p>Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?</p> <p>Are there any web specific libraries?...
0
2009-04-22T15:46:24Z
777,951
<p>Basic Python syntax isn't half of what you need to know.</p> <ol> <li><p>All of the Python built-in data structures.</p></li> <li><p>Object-oriented design.</p></li> <li><p>What python module and packages are.</p></li> <li><p>The Python libraries -- almost everything you could ever want has already been written.</p...
4
2009-04-22T15:51:59Z
[ "python" ]
Other than basic python syntax, what other key areas should I learn to get a website live?
777,924
<p>Other than basic python syntax, what other key areas should I learn to get a website live?</p> <p>Is there a web.config in the python world?</p> <p>Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?</p> <p>Are there any web specific libraries?...
0
2009-04-22T15:46:24Z
777,952
<p>Oh, golly.</p> <p>Look, this is gonna be real hard to answer because, read as you wrote it, you're missing a <i>lot</i> of steps. Like, you need a web server, a design, some HTML, and so on.</p> <p>Are you building from the ground up? Asking about Python makes me suspect you may be using something like Zope.</p>...
0
2009-04-22T15:52:07Z
[ "python" ]
Other than basic python syntax, what other key areas should I learn to get a website live?
777,924
<p>Other than basic python syntax, what other key areas should I learn to get a website live?</p> <p>Is there a web.config in the python world?</p> <p>Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?</p> <p>Are there any web specific libraries?...
0
2009-04-22T15:46:24Z
777,965
<p><em>Answer replaced to correspond with the updated question.</em></p> <p>If you're already familiar with ASP.NET, the easiest way to jump into creating a website with Python is probably to look into one of the major web frameworks. <a href="http://www.djangoproject.com/" rel="nofollow">Django</a> is very popular, w...
1
2009-04-22T15:54:25Z
[ "python" ]
Other than basic python syntax, what other key areas should I learn to get a website live?
777,924
<p>Other than basic python syntax, what other key areas should I learn to get a website live?</p> <p>Is there a web.config in the python world?</p> <p>Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?</p> <p>Are there any web specific libraries?...
0
2009-04-22T15:46:24Z
778,102
<p>Don't forget to give <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a> a try - your <code>.NET</code> experience can help making sense of newly learned <code>Python</code> idioms.</p> <blockquote> <p>IronPython is an implementation of the Python programming language running under .NET and...
0
2009-04-22T16:24:58Z
[ "python" ]
Other than basic python syntax, what other key areas should I learn to get a website live?
777,924
<p>Other than basic python syntax, what other key areas should I learn to get a website live?</p> <p>Is there a web.config in the python world?</p> <p>Which libraries handle things like authentication? or is that all done manually via session cookies and database tables?</p> <p>Are there any web specific libraries?...
0
2009-04-22T15:46:24Z
778,807
<p>Of course the builtins. And become familiar with the standard library (until you start to remember what's in it, I'd suggest looking through it any time you're about to implement something... It might be there already!)</p> <p>You'll want some kind of framework, I'd recommend Django or TurboGears</p> <p>But you al...
0
2009-04-22T19:31:53Z
[ "python" ]
Python subprocess "object has no attribute 'fileno'" error
777,996
<p>This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 </p> <p>Code:</p> <pre><code>def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), ...
6
2009-04-22T16:05:06Z
778,030
<p>looks like syntax error. except first append the rest are erroneous (review brackets).</p>
-1
2009-04-22T16:11:38Z
[ "python", "pipe", "subprocess" ]
Python subprocess "object has no attribute 'fileno'" error
777,996
<p>This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 </p> <p>Code:</p> <pre><code>def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), ...
6
2009-04-22T16:05:06Z
778,035
<p>You want the stdout of the process, so replace your <code>stdin=proc[-1]</code> with <code>stdin=proc[-1].stdout</code></p> <p>Also, you need to move your paren, it should come after the <code>stdout</code> argument.</p> <pre><code> proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE) </code></...
1
2009-04-22T16:11:54Z
[ "python", "pipe", "subprocess" ]
Python subprocess "object has no attribute 'fileno'" error
777,996
<p>This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 </p> <p>Code:</p> <pre><code>def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), ...
6
2009-04-22T16:05:06Z
778,059
<p>Three things</p> <p>First, your ()'s are wrong.</p> <p>Second, the result of <code>subprocess.Popen()</code> is a process object, not a file.</p> <pre><code>proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), stdout=PIPE) </...
9
2009-04-22T16:15:09Z
[ "python", "pipe", "subprocess" ]
Python subprocess "object has no attribute 'fileno'" error
777,996
<p>This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 </p> <p>Code:</p> <pre><code>def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), ...
6
2009-04-22T16:05:06Z
778,284
<p>There's a few weird things in the script,</p> <ul> <li><p>Why are you storing each process in a list? Wouldn't it be much more readable to simply use variables? Removing all the <code>.append()s</code> reveals an syntax error, several times you have passed stdout=PIPE to the <code>append</code> arguments, instead o...
1
2009-04-22T17:13:09Z
[ "python", "pipe", "subprocess" ]
Python subprocess "object has no attribute 'fileno'" error
777,996
<p>This code generates "AttributeError: 'Popen' object has no attribute 'fileno'" when run with Python 2.5.1 </p> <p>Code:</p> <pre><code>def get_blame(filename): proc = [] proc.append(Popen(['svn', 'blame', shellquote(filename)], stdout=PIPE)) proc.append(Popen(['tr', '-s', r"'\040'"], stdin=proc[-1]), ...
6
2009-04-22T16:05:06Z
778,452
<p>Like S.Lott said, processing the text in Python is better.</p> <p>But if you want to use the cmdline utilities, you can keep it readable by using <code>shell=True</code>:</p> <pre><code>cmdline = r"svn blame %s | tr -s '\040' | tr '\040' ';' | cut -d \; -f 3" % shellquote(filename) return Popen(cmdline, shell=True...
-1
2009-04-22T18:01:31Z
[ "python", "pipe", "subprocess" ]
How to query any constraint's target list without knowing the constraint type?
778,083
<p>In Maya, I have a list of constraints gathered by the following code. I want to iterate the constraints and query the targets for each of them:</p> <pre><code>cons = ls(type='constraint') for con in cons: targets = constraint(query=True, targetList=True) </code></pre> <p>The problem, there is no general <code...
2
2009-04-22T16:20:35Z
778,654
<p>listConnections on the .target attr</p> <p>the cleanup in mel:</p> <pre><code>string $cons[] = `ls -type "constraint"`; for ( $con in $cons ){ string $targetAttrString = ( $con+ ".target" ); string $connections[] = `listConnections $targetAttrString`; string $connectionsFlattened[] = stringArrayRemoveD...
1
2009-04-22T18:54:22Z
[ "python", "3d", "constraints", "maya", "mel" ]
pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data?
778,093
<p>Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win3...
1
2009-04-22T16:23:02Z
778,282
<p>"Now, i m scanning entire rows one by one"</p> <p>What's wrong with that? "search" -- in a spreadsheet context -- is really complicated. Search values? Search formulas? Search down rows then across columns? Search specific columns only? Search specific rows only?</p> <p>A spreadsheet isn't simple text -- sim...
2
2009-04-22T17:12:38Z
[ "python", "excel", "search", "pyexcelerator", "xlrd" ]
pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data?
778,093
<p>Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win3...
1
2009-04-22T16:23:02Z
779,030
<p>You can't. Those tools don't offer search capabilities. You must iterate over the data in a loop and search yourself. Sorry.</p>
1
2009-04-22T20:22:54Z
[ "python", "excel", "search", "pyexcelerator", "xlrd" ]
pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data?
778,093
<p>Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win3...
1
2009-04-22T16:23:02Z
779,599
<p>With pyExcelerator you can do a simple optimization by finding the maximum row and column indices first (and storing them), so that you iterate over <code>(row, i) for i in range(maxcol+1)</code> instead of iterating over all the dictionary keys. That may be the best you get, unless you want to go through and build...
0
2009-04-22T22:55:56Z
[ "python", "excel", "search", "pyexcelerator", "xlrd" ]
pyExcelerator or xlrd - How to FIND/SEARCH a row for the given few column data?
778,093
<p>Python communicating with EXCEL... i need to find a way so that I can find/search a row for given column datas. Now, i m scanning entire rows one by one... It would be useful, If there is some functions like FIND/SEARCH/REPLACE .... I dont see these features in pyExcelerator or xlrd modules.. I dont want to use win3...
1
2009-04-22T16:23:02Z
958,903
<p>@John Fouhy: [I'm the maintainer of xlwt, and author of xlrd]</p> <p>The spreadsheet-reading part of pyExcelerator was so severely deprecated that it vanished completely out of xlwt. To read any XLS files created by Excel 2.0 up to 11.0 (Excel 2003) or compatible software, using Python 2.1+, use <a href="http://pyp...
5
2009-06-06T03:12:29Z
[ "python", "excel", "search", "pyexcelerator", "xlrd" ]
problem opening a text document - unicode error
778,096
<p>i have probably rather simple question. however, i am just starting to use python and it just drives me crazy. i am following the instructions of a book and would like to open a simple text file. the code i am using:</p> <pre><code>import sys try: d = open("p0901aus.txt" , "W") except: print("Unsucessfull") sys....
2
2009-04-22T16:23:49Z
778,112
<p>Change that to</p> <pre><code># for Python 2.5+ import sys try: d = open("p0901aus.txt","w") except Exception, ex: print "Unsuccessful." print ex sys.exit(0) # for Python 3 import sys import codecs try: d = codecs.open("p0901aus.txt","w","utf-8") except Exception as ex: print("Unsuccessful.") pri...
2
2009-04-22T16:27:56Z
[ "python", "unicode" ]
problem opening a text document - unicode error
778,096
<p>i have probably rather simple question. however, i am just starting to use python and it just drives me crazy. i am following the instructions of a book and would like to open a simple text file. the code i am using:</p> <pre><code>import sys try: d = open("p0901aus.txt" , "W") except: print("Unsucessfull") sys....
2
2009-04-22T16:23:49Z
778,188
<blockquote> <p>(unicode eror) 'unicodeescape' codec can't decode bytes in position 2-4: truncated \UXXXXXXXX escape</p> </blockquote> <p>This probably means that the file you are trying to read is not in the encoding that open() expects. Apparently open() expects some Unicode encoding (most likely UTF-8 or UTF-16),...
5
2009-04-22T16:47:29Z
[ "python", "unicode" ]
problem opening a text document - unicode error
778,096
<p>i have probably rather simple question. however, i am just starting to use python and it just drives me crazy. i am following the instructions of a book and would like to open a simple text file. the code i am using:</p> <pre><code>import sys try: d = open("p0901aus.txt" , "W") except: print("Unsucessfull") sys....
2
2009-04-22T16:23:49Z
2,379,566
<pre><code>import csv data = csv.reader(open('c:\x\list.csv' )) for row in data: print(row) print('ready') </code></pre> <p>Brings up "(unicode error)'unicodeescape' codec can't decode bytes in position 2-4: truncated \xXX escape"</p> <p>Try <code>c:\\x\\list.csv</code> instead of <code>c:\x\list.csv</code></...
1
2010-03-04T13:29:10Z
[ "python", "unicode" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
778,220
<p>I think that the GMail SMTP server does a reverse DNS lookup on the IP address that you connect from, and refuses the connection if no domain can be found. This is to avoid spammer from using their SMTP server as an open relay.</p>
6
2009-04-22T16:57:05Z
[ "python", "smtp", "gmail", "smtplib" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
780,516
<p>Have you tried constructing a valid message?</p> <pre><code>from email.MIMEText import MIMEText msg = MIMEText('body') msg['Subject'] = 'subject' msg['From'] = "..." msg['Reply-to'] = "..." msg['To'] = "..." </code></pre>
7
2009-04-23T06:33:55Z
[ "python", "smtp", "gmail", "smtplib" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
1,287,612
<p>You'll need to check your "Sent" folder in GMail, as that's where a message sent from your account to your account will most probably show up.</p>
2
2009-08-17T12:12:20Z
[ "python", "smtp", "gmail", "smtplib" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
6,217,741
<p>save yourselves some headaches and use this:</p> <p><a href="http://mynthon.net/howto/-/python/python%20-%20logging.SMTPHandler-how-to-use-gmail-smtp-server.txt" rel="nofollow">http://mynthon.net/howto/-/python/python%20-%20logging.SMTPHandler-how-to-use-gmail-smtp-server.txt</a></p> <p><a href="http://mynthon.net...
3
2011-06-02T17:07:34Z
[ "python", "smtp", "gmail", "smtplib" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
24,358,795
<p>I went to the above mentioned link and had 3 different to addresses to send to but I received three emails to the same address and that being the #3 address. </p> <p><a href="http://mynthon.net/howto/-/python/python%20-%20logging.SMTPHandler-how-to-use-gmail-smtp-server.txt" rel="nofollow">http://mynthon.net/howto/...
0
2014-06-23T05:18:00Z
[ "python", "smtp", "gmail", "smtplib" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
28,990,761
<p>I don't know if OP still cares about this answer, but having found myself here in an effort to troubleshoot a similar problem, hopefully someone else might find this useful. As it turns out, Google has changed the way that they allow their SMTP server to be used. You will want to check a couple of things:</p> <ol...
4
2015-03-11T15:28:33Z
[ "python", "smtp", "gmail", "smtplib" ]
smtplib and gmail - python script problems
778,202
<p>Here's my script:</p> <pre><code>#!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port 465 or 587 server.ehlo() server.starttls() server.ehlo() server.login('myname@gmail.com','mypass') server.sendmail('myname@gmail.com','somename@somewhere.com',msg) server.close(...
19
2009-04-22T16:52:17Z
29,720,420
<p>Some self-promotion here, but I feel on a valid ground.</p> <p>You would literally only need this code to do exactly what you wrote:</p> <pre><code>import yagmail yag = yagmail.SMTP('myname@gmail.com') yag.send('somename@somewhere.com', subject = None, contents = 'Hello') </code></pre> <p>Or a one liner:</p> <pr...
4
2015-04-18T17:18:18Z
[ "python", "smtp", "gmail", "smtplib" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
778,399
<p>Here's what we do. It isn't a "complete" solution, but it does much of what you're looking for.</p> <pre><code>from django import forms from django.contrib import admin from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User class UserForm(forms.ModelForm): class Meta: ...
25
2009-04-22T17:46:39Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
781,259
<p>you can also find an interesting discussion on this topic at the below link :</p> <p><a href="http://groups.google.com/group/django-users/browse%5Fthread/thread/c943ede66e6807c/2fbf2afeade397eb#2fbf2afeade397eb" rel="nofollow">http://groups.google.com/group/django-users/browse_thread/thread/c943ede66e6807c/2fbf2afe...
1
2009-04-23T11:09:40Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
9,134,982
<p>For anyone else wanting to do this, I'd recommend taking a look at <a href="https://github.com/dabapps/django-email-as-username">django-email-as-username</a> which is a pretty comprehensive solution, that includes patching up the admin and the <code>createsuperuser</code> management commands, amongst other bits and ...
32
2012-02-03T20:20:55Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
11,459,439
<p>Latest version of django-registration allows some nice customisation and might do the job - docs here <a href="https://bitbucket.org/ubernostrum/django-registration/src/fad7080fe769/docs/backend-api.rst" rel="nofollow">https://bitbucket.org/ubernostrum/django-registration/src/fad7080fe769/docs/backend-api.rst</a></p...
1
2012-07-12T19:42:37Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
24,071,649
<p>The easiest way is to lookup the username based on the email in the login view. That way you can leave everything else alone:</p> <pre><code>from django.contrib.auth import authenticate, login as auth_login def _is_valid_email(email): from django.core.validators import validate_email from django.core.excep...
0
2014-06-05T23:07:08Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
25,278,186
<p>Here is one way to do it so that both username and email are accepted:</p> <pre><code>from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User from django.core.exceptions import ObjectDoesNotExist from django.forms import ValidationError class EmailAuthenticationForm(Aut...
15
2014-08-13T04:39:42Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
26,336,203
<p>Django now provides a full example of an extended authentication system with admin and form: <a href="https://docs.djangoproject.com/en/dev/topics/auth/customizing/#a-full-example">https://docs.djangoproject.com/en/dev/topics/auth/customizing/#a-full-example</a></p> <p>You can basically copy/paste it and adapt (I d...
7
2014-10-13T08:57:09Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
27,433,341
<p>Other alternatives look too complex for me, so I wrote a snippet that allows to authenticate using username, email, or both, and also enable or disable case sensitive. I uploaded it to pip as <a href="https://github.com/Zeioth/django-dual-authentication" rel="nofollow">django-dual-authentication</a>.</p> <pre><code...
0
2014-12-11T22:08:47Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
29,638,766
<p>If you're going to extend user model, you would have to implement custom user model anyway. </p> <p>Here is an example for Django 1.8. Django 1.7 would require a little bit more work, mostly changing default forms (just take a look at <code>UserChangeForm</code> &amp; <code>UserCreationForm</code> in <code>django....
5
2015-04-14T22:54:45Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
33,623,706
<p>I think the most quickly way is to create a form inherit from <code>UserCreateForm</code>, and then override the <code>username</code> field with <code>forms.EmailField</code>. Then for every new registration user, they need to signon with their email address.</p> <p>For example:</p> <p><strong>urls.py</strong></p...
0
2015-11-10T05:45:32Z
[ "python", "django", "authentication" ]
Accepting email address as username in Django
778,382
<p>Is there a good way to do this in django without rolling my own authentication system? I want the username to be the user's email address instead of them creating a username.</p> <p>Please advise, thank you.</p>
68
2009-04-22T17:42:20Z
35,508,483
<p>Not sure if people are trying to accomplish this, but I found nice (and clean) way to only ask for the email and then set the username as the email in the view before saving.</p> <p>My UserForm only requires the email and password:</p> <pre><code>class UserForm(forms.ModelForm): password = forms.CharField(widg...
0
2016-02-19T15:09:55Z
[ "python", "django", "authentication" ]
Identifying the types of all variables in a C project
778,468
<p>I am trying to write a program to check that some C source code conforms to a variable naming convention. In order to do this, I need to analyse the source code and identify the type of all the local and global variables.</p> <p>The end result will almost certainly be a python program, but the tool to analyse the ...
7
2009-04-22T18:06:50Z
778,513
<p>There are a number of Python parser packages that can be used to describe a syntax and then it will generate Python code to parse that syntax.</p> <p>Ned Batchelder wrote a <strong><a href="http://nedbatchelder.com/text/python-parsers.html" rel="nofollow">very nice summary</a></strong></p> <p>Of those, Ply was use...
5
2009-04-22T18:17:02Z
[ "python", "c", "variables", "coding-style", "code-analysis" ]
Identifying the types of all variables in a C project
778,468
<p>I am trying to write a program to check that some C source code conforms to a variable naming convention. In order to do this, I need to analyse the source code and identify the type of all the local and global variables.</p> <p>The end result will almost certainly be a python program, but the tool to analyse the ...
7
2009-04-22T18:06:50Z
778,529
<p>I did something similar for a project I was working on a few years ago. I ended up writing the first half of a C compiler. Don't be alarmed by that prospect. It is actually much easier than it sounds, especially if you are only looking for certain tokens (variable definitions, in this case).</p> <p>Look for documen...
0
2009-04-22T18:21:51Z
[ "python", "c", "variables", "coding-style", "code-analysis" ]
Identifying the types of all variables in a C project
778,468
<p>I am trying to write a program to check that some C source code conforms to a variable naming convention. In order to do this, I need to analyse the source code and identify the type of all the local and global variables.</p> <p>The end result will almost certainly be a python program, but the tool to analyse the ...
7
2009-04-22T18:06:50Z
778,532
<p>Check out ANTLR. It's a parser generator, with bindings for python. The ANTLR site provides a whole bunch of grammars for common languages, C included. You could download the grammar for C and add actions in appropriate places to collect the information you're interested in. There's even a neat graphical tool fo...
2
2009-04-22T18:22:03Z
[ "python", "c", "variables", "coding-style", "code-analysis" ]
Identifying the types of all variables in a C project
778,468
<p>I am trying to write a program to check that some C source code conforms to a variable naming convention. In order to do this, I need to analyse the source code and identify the type of all the local and global variables.</p> <p>The end result will almost certainly be a python program, but the tool to analyse the ...
7
2009-04-22T18:06:50Z
778,602
<p>What you're trying to do is a lightweight form of static analysis. You might have some luck looking at the tools pointed to by <a href="http://en.wikipedia.org/wiki/List%5Fof%5Ftools%5Ffor%5Fstatic%5Fcode%5Fanalysis#C" rel="nofollow">Wikipedia</a>.</p> <p>Parsing the C code yourself sounds like the wrong direction...
2
2009-04-22T18:41:45Z
[ "python", "c", "variables", "coding-style", "code-analysis" ]
Identifying the types of all variables in a C project
778,468
<p>I am trying to write a program to check that some C source code conforms to a variable naming convention. In order to do this, I need to analyse the source code and identify the type of all the local and global variables.</p> <p>The end result will almost certainly be a python program, but the tool to analyse the ...
7
2009-04-22T18:06:50Z
779,504
<p>How about approaching it from the other side completely. You already have a parser that fully understands all of the nuances of the C type system: the compiler itself. So, compile the project with full debug support, and go spelunking in the debug data. </p> <p>For a system based on formats supported by <a href="ht...
3
2009-04-22T22:20:22Z
[ "python", "c", "variables", "coding-style", "code-analysis" ]
How to center a GNOME pop-up notification?
778,660
<p>To display a GNOME pop-up notification at (200,400) on the screen (using Python):</p> <pre><code>import pynotify n = pynotify.Notification("This is my title", "This is my description") n.set_hint('x', 200) n.set_hint('y', 400) n.show() </code></pre> <p>I'm a gtk noob. How can I make this Notification show up cen...
4
2009-04-22T18:56:05Z
778,674
<p>on windows, </p> <pre><code> from win32api import GetSystemMetrics width = GetSystemMetrics (0) height = GetSystemMetrics (1) print "Screen resolution = %dx%d" % (width, height) </code></pre> <p>I cant seem to find the linux version for it tho. </p>
-4
2009-04-22T19:00:28Z
[ "python", "user-interface", "gtk", "pynotify" ]
How to center a GNOME pop-up notification?
778,660
<p>To display a GNOME pop-up notification at (200,400) on the screen (using Python):</p> <pre><code>import pynotify n = pynotify.Notification("This is my title", "This is my description") n.set_hint('x', 200) n.set_hint('y', 400) n.show() </code></pre> <p>I'm a gtk noob. How can I make this Notification show up cen...
4
2009-04-22T18:56:05Z
778,871
<p>A bit of a hack, but this works:</p> <pre><code>from Tkinter import * r = Tk() r.withdraw() width, height = r.winfo_screenwidth(), r.winfo_screenheight() </code></pre> <p>Another option is:</p> <pre><code>from commands import getstatusoutput status, output = getstatusoutput("xwininfo -root") width = re.compile(r"...
0
2009-04-22T19:43:02Z
[ "python", "user-interface", "gtk", "pynotify" ]
How to center a GNOME pop-up notification?
778,660
<p>To display a GNOME pop-up notification at (200,400) on the screen (using Python):</p> <pre><code>import pynotify n = pynotify.Notification("This is my title", "This is my description") n.set_hint('x', 200) n.set_hint('y', 400) n.show() </code></pre> <p>I'm a gtk noob. How can I make this Notification show up cen...
4
2009-04-22T18:56:05Z
779,669
<p>Since you're using GNOME, here's the GTK way of getting the screen resolution</p> <pre><code>import gtk.gdk import pynotify n = pynotify.Notification("This is my title", "This is my description") n.set_hint('x', gtk.gdk.screen_width()/2.) n.set_hint('y', gtk.gdk.screen_height()/2.) n.show() </code></pre>
4
2009-04-22T23:29:26Z
[ "python", "user-interface", "gtk", "pynotify" ]
Generating unique and opaque user IDs in Google App Engine
778,965
<p>I'm working on an application that lets registered users create or upload content, and allows anonymous users to view that content and browse registered users' pages to find that content - this is very similar to how a site like Flickr, for example, allows people to browse its users' pages.</p> <p>To do this, I nee...
9
2009-04-22T20:06:21Z
779,023
<p>Do you mean <a href="http://en.wikipedia.org/wiki/HTTP%5Fcookie" rel="nofollow">session cookies</a>?</p> <p>Try <a href="http://code.google.com/p/gaeutilities/" rel="nofollow">http://code.google.com/p/gaeutilities/</a></p> <p><hr /></p> <p>What DzinX said. The only way to create an opaque key that can be authent...
1
2009-04-22T20:21:23Z
[ "python", "google-app-engine", "guid", "uniqueidentifier" ]
Generating unique and opaque user IDs in Google App Engine
778,965
<p>I'm working on an application that lets registered users create or upload content, and allows anonymous users to view that content and browse registered users' pages to find that content - this is very similar to how a site like Flickr, for example, allows people to browse its users' pages.</p> <p>To do this, I nee...
9
2009-04-22T20:06:21Z
779,600
<p>I think you should distinguish between two types of users:</p> <p>1) users that have logged in via Google Accounts or that have already registered on your site with a non-google e-mail address</p> <p>2) users that opened your site for the first time and are not logged in in any way</p> <p>For the second case, I c...
3
2009-04-22T22:56:35Z
[ "python", "google-app-engine", "guid", "uniqueidentifier" ]
Generating unique and opaque user IDs in Google App Engine
778,965
<p>I'm working on an application that lets registered users create or upload content, and allows anonymous users to view that content and browse registered users' pages to find that content - this is very similar to how a site like Flickr, for example, allows people to browse its users' pages.</p> <p>To do this, I nee...
9
2009-04-22T20:06:21Z
780,623
<p>Your timing is impeccable: Just yesterday, a new release of the SDK came out, with support for <a href="http://code.google.com/appengine/docs/python/users/userclass.html#User%5Fuser%5Fid">unique, permanent user IDs</a>. They meet all the criteria you specified.</p>
7
2009-04-23T07:15:00Z
[ "python", "google-app-engine", "guid", "uniqueidentifier" ]
regex for parsing SQL statements
778,969
<p>I've got an IronPython script that executes a bunch of SQL statements against a SQL Server database. the statements are large strings that actually contain multiple statements, separated by the "GO" keyword. That works when they're run from sql management studio and some other tools, but not in ADO. So I split up...
6
2009-04-22T20:07:38Z
779,048
<p>since you can have comments inside comments, nested comments, comments inside queries, etc, there is no sane way to do it with regexes.</p> <p>Just immagine the following script:</p> <pre><code>INSERT INTO table (name) VALUES ( -- GO NOW GO 'GO to GO /* GO */ GO' + /* some comment 'go go go' -- */ 'GO GO' /* GO */...
5
2009-04-22T20:25:35Z
[ "python", "regex" ]
regex for parsing SQL statements
778,969
<p>I've got an IronPython script that executes a bunch of SQL statements against a SQL Server database. the statements are large strings that actually contain multiple statements, separated by the "GO" keyword. That works when they're run from sql management studio and some other tools, but not in ADO. So I split up...
6
2009-04-22T20:07:38Z
779,083
<p>If GO is always on a line by itself you can use split like this:</p> <pre><code>#!/usr/bin/python import re sql = """-- this is a great database script! go team go! INSERT INTO myTable(stringColumn) VALUES ('go away!') /* here are some comments that go with this script. */ GO 5 --this is a test INSERT INTO myT...
5
2009-04-22T20:31:28Z
[ "python", "regex" ]
regex for parsing SQL statements
778,969
<p>I've got an IronPython script that executes a bunch of SQL statements against a SQL Server database. the statements are large strings that actually contain multiple statements, separated by the "GO" keyword. That works when they're run from sql management studio and some other tools, but not in ADO. So I split up...
6
2009-04-22T20:07:38Z
779,084
<p>Is "GO" always on a line by itself? You could just split on "^GO$".</p>
8
2009-04-22T20:31:40Z
[ "python", "regex" ]
regex for parsing SQL statements
778,969
<p>I've got an IronPython script that executes a bunch of SQL statements against a SQL Server database. the statements are large strings that actually contain multiple statements, separated by the "GO" keyword. That works when they're run from sql management studio and some other tools, but not in ADO. So I split up...
6
2009-04-22T20:07:38Z
779,100
<p><s>This won't detect if <code>GO</code> ever is used as a variable name inside some statement, but should take care of those inside comments or strings.</s></p> <p><strong>EDIT:</strong> This now works if <code>GO</code> is part of the statement, as long as it is not in it's own line.</p> <pre><code>import re lin...
2
2009-04-22T20:33:41Z
[ "python", "regex" ]
How to upload a pristine Python package to PyPI?
778,980
<p>What's the magic "<code>python setup.py some_incantation_here</code>" command to upload a package to PyPI, in a form that can be downloaded to get the original package in its original form?</p> <p>I have a package with some source and a few image files (as package_data). If I do "<code>setup.py sdist register uplo...
10
2009-04-22T20:10:03Z
779,790
<p>When you perform an "sdist" command, then what controls the list of included files is your "MANIFEST.in" file sitting next to "setup.py", not whatever you have listed in "package_data". This has something to do with the schizophrenic nature of the Python packaging solutions today; "sdist" is powered by the <a href=...
16
2009-04-23T00:15:17Z
[ "python", "packaging", "pypi" ]
Python Multiprocessing: Sending data to a process
779,384
<p>I have subclassed <code>Process</code> like so:</p> <pre><code>class EdgeRenderer(Process): def __init__(self,starter,*args,**kwargs): Process.__init__(self,*args,**kwargs) self.starter=starter </code></pre> <p>Then I define a <code>run</code> method which uses <code>self.starter</code>.</p> <...
2
2009-04-22T21:47:29Z
781,749
<p>On unix systems, multiprocessing uses os.fork() to create the children, on windows, it uses some subprocess trickery and serialization to share the data. So to be cross platform, yes - it must be serializable. The child will get a new copy.</p> <p>That being said, here's an example:</p> <pre><code>from multiproces...
8
2009-04-23T13:37:03Z
[ "python", "multiprocessing" ]
Python Access Data in Package Subdirectory
779,495
<p>I am writing a python package with modules that need to open data files in a <code>./data/</code> subdirectory. Right now I have the paths to the files hardcoded into my classes and functions. I would like to write more robust code that can access the subdirectory regardless of where it is installed on the user's sy...
41
2009-04-22T22:17:52Z
779,548
<p>I think I hunted down an answer. </p> <p>I make a module data_path.py, which I import into my other modules containing:</p> <pre><code>data_path = os.path.join(os.path.dirname(__file__),'data') </code></pre> <p>And then I open all my files with </p> <pre><code>open(os.path.join(data_path,'filename'), &lt;param&g...
4
2009-04-22T22:35:52Z
[ "python", "packages" ]
Python Access Data in Package Subdirectory
779,495
<p>I am writing a python package with modules that need to open data files in a <code>./data/</code> subdirectory. Right now I have the paths to the files hardcoded into my classes and functions. I would like to write more robust code that can access the subdirectory regardless of where it is installed on the user's sy...
41
2009-04-22T22:17:52Z
779,552
<p>You can use underscore-underscore-file-underscore-underscore (<code>__file__</code>) to get the path to the package, like this:</p> <pre><code>import os this_dir, this_filename = os.path.split(__file__) DATA_PATH = os.path.join(this_dir, "data", "data.txt") print open(DATA_PATH).read() </code></pre>
19
2009-04-22T22:37:04Z
[ "python", "packages" ]
Python Access Data in Package Subdirectory
779,495
<p>I am writing a python package with modules that need to open data files in a <code>./data/</code> subdirectory. Right now I have the paths to the files hardcoded into my classes and functions. I would like to write more robust code that can access the subdirectory regardless of where it is installed on the user's sy...
41
2009-04-22T22:17:52Z
5,601,839
<p>The standard way to do this is with setuptools packages and pkg_resources.</p> <p>You can lay out your package according to the following hierarchy, and configure the package setup file to point it your data resources, as per this link:</p> <p><a href="http://docs.python.org/distutils/setupscript.html#installing-p...
47
2011-04-08T23:42:39Z
[ "python", "packages" ]
Python Access Data in Package Subdirectory
779,495
<p>I am writing a python package with modules that need to open data files in a <code>./data/</code> subdirectory. Right now I have the paths to the files hardcoded into my classes and functions. I would like to write more robust code that can access the subdirectory regardless of where it is installed on the user's sy...
41
2009-04-22T22:17:52Z
26,278,544
<p>To provide a solution working today. Definitely use this API to not reinvent all those wheels.</p> <p>A true filesystem filename is needed. Zipped eggs will be extracted to a cache directory:</p> <pre><code>from pkg_resources import resource_filename, Requirement path_to_vik_logo = resource_filename(Requirement.p...
9
2014-10-09T12:33:03Z
[ "python", "packages" ]
Python Access Data in Package Subdirectory
779,495
<p>I am writing a python package with modules that need to open data files in a <code>./data/</code> subdirectory. Right now I have the paths to the files hardcoded into my classes and functions. I would like to write more robust code that can access the subdirectory regardless of where it is installed on the user's sy...
41
2009-04-22T22:17:52Z
34,198,757
<p>You need a name for your whole module, you're given directory tree doesn't list that detail, for me this worked:</p> <pre><code>import pkg_resources print( pkg_resources.resource_filename(__name__, 'data/data.txt') ) </code></pre> <p>Notibly setuptools does not appear to resolve files based on a name match...
2
2015-12-10T09:59:33Z
[ "python", "packages" ]
Using Gecko/Firefox or Webkit got HTML parsing in python
779,538
<p>I am using BeautifulSoup and urllib2 for downloading HTML pages and parsing them. Problem is with mis formed HTML pages. Though BeautifulSoup is good at handling mis formed HTML still its not as good as Firefox.</p> <p>Considering that Firefox or Webkit are more updated and resilient at handling HTML I think its id...
6
2009-04-22T22:33:15Z
779,984
<p>Perhaps <a href="http://code.google.com/p/pywebkitgtk/" rel="nofollow">pywebkitgtk</a> would do what you need.</p>
1
2009-04-23T01:37:41Z
[ "python", "html", "parsing" ]
Using Gecko/Firefox or Webkit got HTML parsing in python
779,538
<p>I am using BeautifulSoup and urllib2 for downloading HTML pages and parsing them. Problem is with mis formed HTML pages. Though BeautifulSoup is good at handling mis formed HTML still its not as good as Firefox.</p> <p>Considering that Firefox or Webkit are more updated and resilient at handling HTML I think its id...
6
2009-04-22T22:33:15Z
3,897,478
<p>see <a href="http://wiki.python.org/moin/WebBrowserProgramming" rel="nofollow">http://wiki.python.org/moin/WebBrowserProgramming</a></p> <p>there are quite a lot of options - i'm maintaining the page above so that i don't keep repeating myself.</p> <p>you should look at pyjamas-desktop: see the examples/uitest exa...
1
2010-10-09T19:07:53Z
[ "python", "html", "parsing" ]
Using Gecko/Firefox or Webkit got HTML parsing in python
779,538
<p>I am using BeautifulSoup and urllib2 for downloading HTML pages and parsing them. Problem is with mis formed HTML pages. Though BeautifulSoup is good at handling mis formed HTML still its not as good as Firefox.</p> <p>Considering that Firefox or Webkit are more updated and resilient at handling HTML I think its id...
6
2009-04-22T22:33:15Z
17,502,814
<p>You might like PyWebkitDFB from <a href="http://www.gnu.org/software/pythonwebkit/" rel="nofollow">http://www.gnu.org/software/pythonwebkit/</a></p>
0
2013-07-06T12:09:29Z
[ "python", "html", "parsing" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
779,684
<p>Your question is not very clear, but I assume that the python interpreter exits (and therefore the calling console window closes) when an exception happens.</p> <p>You need to modify your python application to catch the exception and print it without exiting the interpreter. One way to do that is to print "press EN...
0
2009-04-22T23:35:35Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
779,686
<pre><code>try: #do some stuff 1/0 #stuff that generated the exception except Exception as ex: print ex raw_input() </code></pre>
13
2009-04-22T23:37:20Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
779,691
<p>You could have a second script, which imports/runs your main code. This script would catch all exceptions, and print a traceback (then wait for user input before ending)</p> <p>Assuming your code is structured using the <code>if __name__ == "__main__": main()</code> idiom..</p> <pre><code>def myfunction(): pas...
6
2009-04-22T23:38:52Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
779,693
<p>If you doing this on a Windows OS, you can prefix the target of your shortcut with:</p> <pre><code>C:\WINDOWS\system32\cmd.exe /K &lt;command&gt; </code></pre> <p>This will prevent the window from closing when the command exits.</p>
13
2009-04-22T23:39:11Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
780,509
<p>On UNIX systems (Windows has already been covered above...) you can change the interpreter argument to include the -i flag:</p> <p>#!/usr/bin/python -i</p> <p>From the man page:</p> <blockquote> <p>-i </p> <p>When a script is passed as first argument or the -c option is used, enter interactive mode after e...
2
2009-04-23T06:29:48Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
781,074
<p>You can register a top-level exception handler that keeps the application alive when an unhandled exception occurs:</p> <pre><code>def show_exception_and_exit(exc_type, exc_value, tb): import traceback traceback.print_exception(exc_type, exc_value, tb) raw_input("Press key to exit.") sys.exit(-1) ...
8
2009-04-23T10:03:04Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
14,227,240
<p>In windows instead of double clicking the py file you can drag it into an already open CMD window, and then hit enter. It stays open after an exception.</p> <p>Dan</p>
0
2013-01-09T02:08:06Z
[ "python", "debugging" ]
Stop python from closing on error
779,675
<p>In python when running scripts is there a way to stop the console window from closing after spitting out the traceback?</p>
10
2009-04-22T23:31:27Z
40,098,403
<p>if you are using windows you could do this </p> <pre><code> import os #code here os.system('pause') </code></pre>
0
2016-10-18T02:05:15Z
[ "python", "debugging" ]
What to write into log file?
779,989
<p>My question is simple: what to write into a log. Are there any conventions? What do I have to put in?</p> <p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p> <p>I already have some ideas, like a timestamp, a unique identifier for eac...
10
2009-04-23T01:41:25Z
779,995
<p><strong>Here are some suggestions for content:</strong></p> <ul> <li>timestamp</li> <li>message</li> <li>log message type (such as error, warning, trace, debug)</li> <li>thread id ( so you can make sense of the log file from a multi threaded application)</li> </ul> <p><strong>Best practices for implementation:</st...
9
2009-04-23T01:44:15Z
[ "python", "logging", "methodology" ]
What to write into log file?
779,989
<p>My question is simple: what to write into a log. Are there any conventions? What do I have to put in?</p> <p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p> <p>I already have some ideas, like a timestamp, a unique identifier for eac...
10
2009-04-23T01:41:25Z
780,005
<p>It's quite pleasant, and already implemented.</p> <p>Read this: <a href="http://docs.python.org/library/logging.html">http://docs.python.org/library/logging.html</a></p> <p><hr /></p> <p><strong>Edit</strong></p> <p>"easy to parse, read," are generally contradictory features. English -- easy to read, hard to pa...
18
2009-04-23T01:47:54Z
[ "python", "logging", "methodology" ]
What to write into log file?
779,989
<p>My question is simple: what to write into a log. Are there any conventions? What do I have to put in?</p> <p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p> <p>I already have some ideas, like a timestamp, a unique identifier for eac...
10
2009-04-23T01:41:25Z
780,007
<p>Since you tagged your question python, I refer you to <a href="http://stackoverflow.com/questions/741063/reporting-information-during-code-execution-best-design">this question</a> as well. As for the content, Brian proposal is good. Remember however to add the program name if you are using a shared log.</p> <p>The ...
1
2009-04-23T01:48:47Z
[ "python", "logging", "methodology" ]
What to write into log file?
779,989
<p>My question is simple: what to write into a log. Are there any conventions? What do I have to put in?</p> <p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p> <p>I already have some ideas, like a timestamp, a unique identifier for eac...
10
2009-04-23T01:41:25Z
780,025
<p>timeStamp i.e. DateTime YYYY/MM/DD:HH:mm:ss:ms User Thread ID Function Name Message/Error Message/Success Message/Function Trace</p> <p>Have this in XML format and you can then easily write a parser for it.</p> <pre><code>&lt;log&gt; &lt;logEntry DebugLevel="0|1|2|3|4|5...."&gt; &lt;TimeStamp format="YYYY/MM...
0
2009-04-23T01:57:03Z
[ "python", "logging", "methodology" ]
What to write into log file?
779,989
<p>My question is simple: what to write into a log. Are there any conventions? What do I have to put in?</p> <p>Since my app has to be released, I'd like to have friendly logs, which could be read by most people without asking what it is.</p> <p>I already have some ideas, like a timestamp, a unique identifier for eac...
10
2009-04-23T01:41:25Z
780,068
<p>A good idea is to look at log analysis software. Unless you plan to write your own, you will probably want to exploit an existing log analysis package such as Analog. If that is the case, you will probably want to generate a log output that is similar enough to the formats that it accepts. It will allow you to creat...
1
2009-04-23T02:17:39Z
[ "python", "logging", "methodology" ]