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
Emacs defadvice on python-mode function
1,416,882
<p>In python-mode, there is a function called py-execute-region which sends a highlighted region of code to the Python buffer for evaluation. After evaluation, the cursor is in the Python buffer, but I would prefer that it remain in the script buffer so I can continue producing more code. I wrote a simple advising func...
5
2009-09-13T04:52:45Z
1,851,850
<p>In this case the solution appears to be</p> <pre><code>(custom-set-variables '(py-shell-switch-buffers-on-execute nil)) </code></pre>
7
2009-12-05T10:43:59Z
[ "python", "emacs", "elisp", "advising-functions", "defadvice" ]
Emacs defadvice on python-mode function
1,416,882
<p>In python-mode, there is a function called py-execute-region which sends a highlighted region of code to the Python buffer for evaluation. After evaluation, the cursor is in the Python buffer, but I would prefer that it remain in the script buffer so I can continue producing more code. I wrote a simple advising func...
5
2009-09-13T04:52:45Z
2,280,633
<p>I haven't actually tried this out, but I did do something similar for find-file, and over there I needed to call interactive before calling other-window. I actually have no real idea of Emacs Lisp, but this may work.</p> <pre><code>(defadvice py-execute-region (aft...
1
2010-02-17T12:43:33Z
[ "python", "emacs", "elisp", "advising-functions", "defadvice" ]
Google appengine string replacement in template file
1,416,921
<p>I'm using google appengine (python, of course :) ) and I'd like to do a string.replace on a string <em>from the template file</em>.</p> <pre> {% for item in items %} &lt;p&gt;{{ item.code.replace( '_', ' ' ) }}&lt;/p&gt; {% endfor %} </pre> <p>But that isn't working. So we <b>cannot</b> execute anything other t...
0
2009-09-13T05:23:16Z
1,416,947
<p>Apart from the argument-less <code>.fetch()</code> call in your code, which I believe can't possibly work (you ALWAYS have to pass <code>fetch</code> an argument -- the max number of entities you're willing to fetch!), I can't reproduce your problem -- assigning a new attribute (including one obtained by processing ...
1
2009-09-13T05:43:02Z
[ "python", "google-app-engine" ]
Google appengine string replacement in template file
1,416,921
<p>I'm using google appengine (python, of course :) ) and I'd like to do a string.replace on a string <em>from the template file</em>.</p> <pre> {% for item in items %} &lt;p&gt;{{ item.code.replace( '_', ' ' ) }}&lt;/p&gt; {% endfor %} </pre> <p>But that isn't working. So we <b>cannot</b> execute anything other t...
0
2009-09-13T05:23:16Z
1,416,953
<p>I have little experience with Google AppEngine, but my understanding is that it is very closely related to Django. Your templates do not actually contain Python code, even if some of the structures you use in them look like it.</p> <p>Both of your questions should be solved using template filters. If it was Django,...
1
2009-09-13T05:46:55Z
[ "python", "google-app-engine" ]
Call Python from C++
1,417,473
<p>I'm trying to call a function in a Python script from my main C++ program. The python function takes a string as the argument and returns nothing (ok.. 'None'). It works perfectly well (never thought it would be that easy..) as long as the previous call is finished before the function is called again, otherwise the...
7
2009-09-13T11:04:48Z
1,417,598
<p>When you say "as long as the previous call is finished before the function is called again", I can only assume that you have multiple threads calling from C++ into Python. The python is not thread safe, so this is going to fail!</p> <p>Read up on the Global Interpreter Lock (GIL) in the Python manual. Perhaps the...
5
2009-09-13T12:05:31Z
[ "c++", "python", "c" ]
Call Python from C++
1,417,473
<p>I'm trying to call a function in a Python script from my main C++ program. The python function takes a string as the argument and returns nothing (ok.. 'None'). It works perfectly well (never thought it would be that easy..) as long as the previous call is finished before the function is called again, otherwise the...
7
2009-09-13T11:04:48Z
1,418,647
<p>Thank you for your help!</p> <p>Yes you're right, there are several C threads. Never thought I'd need mutex for the interpreter itself - the GIL is a completly new concept for me (and isn't even once mentioned in the whole tutorial).</p> <p>After reading the reference (for sure not the easiest part of it, although...
1
2009-09-13T19:33:06Z
[ "c++", "python", "c" ]
Python code to Daemonize a process?
1,417,631
<p>Can anyone share an efficient code snipper to daemonize a process in python? </p>
3
2009-09-13T12:22:48Z
1,417,642
<p>From <a href="http://www.jejik.com/articles/2007/02/a%5Fsimple%5Funix%5Flinux%5Fdaemon%5Fin%5Fpython/" rel="nofollow">http://www.jejik.com/articles/2007/02/a%5Fsimple%5Funix%5Flinux%5Fdaemon%5Fin%5Fpython/</a></p> <pre><code>#!/usr/bin/env python # -*- coding: UTF-8 -*- import sys, os, time, atexit from signal imp...
3
2009-09-13T12:29:52Z
[ "python" ]
doing textwrap and dedent in Windows Powershell (or dotNet aka .net)
1,417,663
<p><strong>Background</strong></p> <p>Python has "textwrap" and "dedent" functions. They do pretty much what you expect to any string you supply.</p> <blockquote> <p><strong>textwrap.wrap(text[, width[, ...]])</strong></p> <p>Wraps the single paragraph in text (a string) so every line is at most width characte...
2
2009-09-13T12:40:57Z
1,417,676
<p>I think you should create a CLI utility with this behaviour and customize it as you like. And then just use it as a command in your shell. Maybe you will also need to add you script into PATH.</p>
1
2009-09-13T12:47:58Z
[ ".net", "python", "string", "text", "powershell" ]
doing textwrap and dedent in Windows Powershell (or dotNet aka .net)
1,417,663
<p><strong>Background</strong></p> <p>Python has "textwrap" and "dedent" functions. They do pretty much what you expect to any string you supply.</p> <blockquote> <p><strong>textwrap.wrap(text[, width[, ...]])</strong></p> <p>Wraps the single paragraph in text (a string) so every line is at most width characte...
2
2009-09-13T12:40:57Z
1,418,040
<p>This is a negligent code...</p> <pre><code>#requires -version 2.0 function wrap( [string]$text, [int]$width ) { $i=0; $text.ToCharArray() | group { [Math]::Floor($i/$width); (gv i).Value++ } | % { -join $_.Group } } function dedent( [string[]]$text ) { $i = $text | % { $_ -match "^(\s*)" | Out-Null...
3
2009-09-13T15:43:02Z
[ ".net", "python", "string", "text", "powershell" ]
doing textwrap and dedent in Windows Powershell (or dotNet aka .net)
1,417,663
<p><strong>Background</strong></p> <p>Python has "textwrap" and "dedent" functions. They do pretty much what you expect to any string you supply.</p> <blockquote> <p><strong>textwrap.wrap(text[, width[, ...]])</strong></p> <p>Wraps the single paragraph in text (a string) so every line is at most width characte...
2
2009-09-13T12:40:57Z
3,326,275
<p>Looking at the results in python at <a href="http://try-python.mired.org/" rel="nofollow">http://try-python.mired.org/</a>, it appears that the correct algorithm splits at word boundaries, rather than taking fixed-length substrings from the text.</p> <pre><code>function wrap( [string]$text, [int]$width = 70 ) { $...
1
2010-07-24T18:15:46Z
[ ".net", "python", "string", "text", "powershell" ]
Python: Warnings and logging verbose limit
1,417,665
<p>I want to unify the whole logging facility of my app. Any warning is raise an exception, next I catch it and pass it to the logger. But the question: Is there in logging any mute facility? Sometimes logger becomes too verbose. Sometimes for the reason of too noisy warnings, is there are any verbose limit in warnings...
1
2009-09-13T12:41:25Z
1,417,675
<p>from the very source you mentioned. there are the log-levels, use the wisely ;-)</p> <pre><code>LEVELS = {'debug': logging.DEBUG, 'info': logging.INFO, 'warning': logging.WARNING, 'error': logging.ERROR, 'critical': logging.CRITICAL} </code></pre>
0
2009-09-13T12:47:19Z
[ "python", "logging", "warnings" ]
Python: Warnings and logging verbose limit
1,417,665
<p>I want to unify the whole logging facility of my app. Any warning is raise an exception, next I catch it and pass it to the logger. But the question: Is there in logging any mute facility? Sometimes logger becomes too verbose. Sometimes for the reason of too noisy warnings, is there are any verbose limit in warnings...
1
2009-09-13T12:41:25Z
1,417,710
<p>This will be a problem if you plan to make all logging calls from some blind error handler that doesn't know anything about the code that raised the error, which is what your question sounds like. How will you decide which logging calls get made and which don't?</p> <p>The more standard practice is to use such blo...
0
2009-09-13T13:07:36Z
[ "python", "logging", "warnings" ]
Python: Warnings and logging verbose limit
1,417,665
<p>I want to unify the whole logging facility of my app. Any warning is raise an exception, next I catch it and pass it to the logger. But the question: Is there in logging any mute facility? Sometimes logger becomes too verbose. Sometimes for the reason of too noisy warnings, is there are any verbose limit in warnings...
1
2009-09-13T12:41:25Z
1,417,759
<p>Not only are there <a href="http://stackoverflow.com/questions/1417665/python-warnings-and-logging-verbose-limit/1417675">log levels</a>, but there is a really flexible <a href="http://docs.python.org/library/logging.html#configuring-logging" rel="nofollow">way of configuring them</a>. If you are using named <code>...
3
2009-09-13T13:33:38Z
[ "python", "logging", "warnings" ]
Detecting the http request type (GET, HEAD, etc) from a python cgi
1,417,715
<p>How can I find out the http request my python cgi received? I need different behaviors for HEAD and GET.</p> <p>Thanks!</p>
9
2009-09-13T13:12:30Z
1,417,722
<pre><code>import os if os.environ['REQUEST_METHOD'] == 'GET': # blah </code></pre>
12
2009-09-13T13:17:20Z
[ "python", "http", "httpwebrequest", "cgi" ]
Detecting the http request type (GET, HEAD, etc) from a python cgi
1,417,715
<p>How can I find out the http request my python cgi received? I need different behaviors for HEAD and GET.</p> <p>Thanks!</p>
9
2009-09-13T13:12:30Z
1,419,177
<p>This is not a direct answer to your question. But your question stems from doing things the wrong way.</p> <p>Do not write Python CGI scripts.</p> <p>Write a <a href="http://code.google.com/p/modwsgi/" rel="nofollow">mod_wsgi</a> application. Better still, use a Python web framework. There are dozens. Choose o...
0
2009-09-14T00:09:15Z
[ "python", "http", "httpwebrequest", "cgi" ]
Detecting the http request type (GET, HEAD, etc) from a python cgi
1,417,715
<p>How can I find out the http request my python cgi received? I need different behaviors for HEAD and GET.</p> <p>Thanks!</p>
9
2009-09-13T13:12:30Z
1,420,886
<p>Why do you need to distinguish between GET and HEAD?</p> <p>Normally you shouldn't distinguish and should treat a HEAD request just like a GET. This is because a HEAD request is meant to return the exact same headers as a GET. The only difference is there will be no response content. Just because there is no respon...
0
2009-09-14T10:59:17Z
[ "python", "http", "httpwebrequest", "cgi" ]
adding the same object twice to a ManyToManyField
1,417,825
<p>I have two django model classes:</p> <pre><code>class A(models.Model): name = models.CharField(max_length = 128) #irrelevant class B(models.Model): a = models.ManyToManyField(A) name = models.CharField(max_length = 128) #irrelevant </code></pre> <p>What I want to do is the following:</p> <pr...
4
2009-09-13T14:04:57Z
1,417,989
<p>Django uses a relational DB for its underlying storage, and that intrinsically DOES have "set semantics": no way to circumvent THAT. So if you want a "multi-set" of anything, you have to represent it with a numeric field that counts how many times each item "occurs". ManyToManyField doesn't do that -- so, instead, y...
3
2009-09-13T15:25:40Z
[ "python", "django", "django-models" ]
adding the same object twice to a ManyToManyField
1,417,825
<p>I have two django model classes:</p> <pre><code>class A(models.Model): name = models.CharField(max_length = 128) #irrelevant class B(models.Model): a = models.ManyToManyField(A) name = models.CharField(max_length = 128) #irrelevant </code></pre> <p>What I want to do is the following:</p> <pr...
4
2009-09-13T14:04:57Z
1,418,241
<p>One way to do it:</p> <pre><code>class A(models.Model): ... class B(models.Model): ... class C(models.Model): a = models.ForeignKey(A) b = models.ForeignKey(B) </code></pre> <p>Then:</p> <pre><code>&gt;&gt;&gt; a1 = A() &gt;&gt;&gt; a2 = A() &gt;&gt;&gt; b = B() &gt;&gt;&gt; c1 = C(a=a1, b=b) &g...
0
2009-09-13T17:05:24Z
[ "python", "django", "django-models" ]
adding the same object twice to a ManyToManyField
1,417,825
<p>I have two django model classes:</p> <pre><code>class A(models.Model): name = models.CharField(max_length = 128) #irrelevant class B(models.Model): a = models.ManyToManyField(A) name = models.CharField(max_length = 128) #irrelevant </code></pre> <p>What I want to do is the following:</p> <pr...
4
2009-09-13T14:04:57Z
1,423,749
<p>I think what you want is to use an intermediary model to form the M2M relationship using the <code>through</code> keyword argument in the ManyToManyField. Sort of like the first answer above, but more "Django-y".</p> <pre><code>class A(models.Model): name = models.CharField(max_length=200) class B(models.Model...
3
2009-09-14T20:30:56Z
[ "python", "django", "django-models" ]
Sending cookies in a SOAP request using Suds
1,417,902
<p>I'm trying to access a SOAP API using Suds. The SOAP API documentation states that I have to provide three cookies with some login data. How can I accomplish this?</p>
2
2009-09-13T14:44:36Z
1,417,916
<p>Set a "Cookie" HTTP Request Header having the required name/value pairs. This is how Cookie values are usually transmitted in HTTP Based systems. You can add multiple key/value pairs in the same http header.</p> <p><strong>Single Cookie</strong></p> <blockquote> <p>Cookie: name1=value1</p> </blockquote> <p><str...
4
2009-09-13T14:52:23Z
[ "python", "soap", "cookies", "suds" ]
Time out error while creating cgi.FieldStorage object
1,417,918
<p>Hey, any idea about what is the timeout error which I am getting here:</p> <p>Error trace:</p> <pre><code> File "/array/purato/python2.6/lib/python2.6/site-packages/cherrypy/_cprequest.py", line 606, in respond cherrypy.response.body = self.handler() ...
0
2009-09-13T14:53:40Z
1,418,017
<blockquote> <p>environ={'REQUEST_METHOD':'POST'} </p> </blockquote> <p>That seems a rather deficient <code>environ</code>. The CGI spec requires many more environment variables to be in there, some of which the <code>cgi</code> module is going to need.</p> <p>In particular there is no CONTENT_LENGTH header. Withou...
0
2009-09-13T15:36:52Z
[ "python", "cgi", "cherrypy" ]
Parse custom URIs with urlparse (Python)
1,417,958
<p>My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http.</p> <p>If I do not adjust urlparse's uses_* lists I get this:</p> <pre><code>&gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint...
13
2009-09-13T15:10:41Z
1,417,967
<p>I think the problem is that URI's don't all have a common format after the scheme. For example, mailto: urls aren't structured the same as http: urls.</p> <p>I would use the results of the first parse, then synthesize an http url and parse it again:</p> <pre><code>parts = urlparse.urlparse("qqqq://base/id#hint") ...
4
2009-09-13T15:15:42Z
[ "python", "url", "python-2.6", "urlparse" ]
Parse custom URIs with urlparse (Python)
1,417,958
<p>My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http.</p> <p>If I do not adjust urlparse's uses_* lists I get this:</p> <pre><code>&gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint...
13
2009-09-13T15:10:41Z
4,907,113
<p>Try removing the scheme entirely, and start with //netloc, i.e.:</p> <pre><code>&gt;&gt;&gt; SCHEME="qqqq" &gt;&gt;&gt; url="qqqq://base/id#hint"[len(SCHEME)+1:] &gt;&gt;&gt; url '//base/id#hint' &gt;&gt;&gt; urlparse.urlparse(url) ('', 'base', '/id', '', '', 'hint') </code></pre> <p>You won't have the scheme in t...
1
2011-02-05T13:33:25Z
[ "python", "url", "python-2.6", "urlparse" ]
Parse custom URIs with urlparse (Python)
1,417,958
<p>My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http.</p> <p>If I do not adjust urlparse's uses_* lists I get this:</p> <pre><code>&gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint...
13
2009-09-13T15:10:41Z
6,264,214
<p>You can also register a custom handler with urlparse:</p> <pre><code>import urlparse def register_scheme(scheme): for method in filter(lambda s: s.startswith('uses_'), dir(urlparse)): getattr(urlparse, method).append(scheme) register_scheme('moose') </code></pre> <p>This will append your url scheme t...
22
2011-06-07T11:00:59Z
[ "python", "url", "python-2.6", "urlparse" ]
Parse custom URIs with urlparse (Python)
1,417,958
<p>My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http.</p> <p>If I do not adjust urlparse's uses_* lists I get this:</p> <pre><code>&gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint...
13
2009-09-13T15:10:41Z
16,927,703
<p>There is also library called <a href="https://github.com/gruns/furl/" rel="nofollow">furl</a> which gives you result you want:</p> <pre><code>&gt;&gt;&gt;import furl &gt;&gt;&gt;f=furl.furl("qqqq://base/id#hint"); &gt;&gt;&gt;f.scheme 'qqqq' &gt;&gt;&gt; f.host 'base' &gt;&gt;&gt; f.path Path('/id') &gt;&gt;&gt...
3
2013-06-04T21:22:13Z
[ "python", "url", "python-2.6", "urlparse" ]
Parse custom URIs with urlparse (Python)
1,417,958
<p>My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http.</p> <p>If I do not adjust urlparse's uses_* lists I get this:</p> <pre><code>&gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint...
13
2009-09-13T15:10:41Z
20,774,335
<p>You can use <a href="https://github.com/homm/yurl/" rel="nofollow">yurl</a> library. Unlike purl or furl, it not try to fix urlparse bugs. It is new compatible with RFC 3986 implementation.</p> <pre><code>&gt;&gt;&gt; import yurl &gt;&gt;&gt; yurl.URL('qqqq://base/id#hint') URLBase(scheme='qqqq', userinfo=u'', host...
0
2013-12-25T15:35:22Z
[ "python", "url", "python-2.6", "urlparse" ]
Parse custom URIs with urlparse (Python)
1,417,958
<p>My application creates custom URIs (or URLs?) to identify objects and resolve them. The problem is that Python's urlparse module refuses to parse unknown URL schemes like it parses http.</p> <p>If I do not adjust urlparse's uses_* lists I get this:</p> <pre><code>&gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint...
13
2009-09-13T15:10:41Z
34,902,870
<p>The question appears to be out of date. Since at least Python 2.7 there are no issues.</p> <pre><code>Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] on win32 &gt;&gt;&gt; import urlparse &gt;&gt;&gt; urlparse.urlparse("qqqq://base/id#hint") ParseResult(scheme='qqqq', netloc='base', path=...
2
2016-01-20T14:33:49Z
[ "python", "url", "python-2.6", "urlparse" ]
How to click a link that has javascript:__doPostBack in href?
1,418,000
<p>I am writing a screen scraper script in python with module 'mechanize' and I would like to use the mechanize.click_link() method on a link that has javascript:__doPostBack in href. I believe the page I am trying to parse is using AJAX.</p> <p>Note: mech is the mechanize.Browser()</p> <pre><code>&gt;&gt;&gt; next_...
4
2009-09-13T15:30:52Z
1,418,394
<p>I don't think <code>mechanize</code> supports Javascript; to scrape pages which intrinsically rely on Javascript execution for their functionality, you may need to use a different tool, such as <a href="http://seleniumhq.org/projects/remote-control/" rel="nofollow">Selenium RC</a>.</p>
1
2009-09-13T17:56:07Z
[ "javascript", "python", "mechanize" ]
How to click a link that has javascript:__doPostBack in href?
1,418,000
<p>I am writing a screen scraper script in python with module 'mechanize' and I would like to use the mechanize.click_link() method on a link that has javascript:__doPostBack in href. I believe the page I am trying to parse is using AJAX.</p> <p>Note: mech is the mechanize.Browser()</p> <pre><code>&gt;&gt;&gt; next_...
4
2009-09-13T15:30:52Z
1,553,659
<pre><code>&gt;&gt;&gt; next_link.__class__.__name__ 'Link' &gt;&gt;&gt; next_link Link(base_url='http://www.citius.mj.pt/Portal/consultas/ConsultasDistribuicao.aspx', url="javascript:__doPostBack('ctl00$ContentPlaceHolder1$Pager1$lnkNext','')", text='2', tag='a', attrs=[('id', 'ctl00_ContentPlaceHolder1_Pager1_lnkNext...
0
2009-10-12T09:51:26Z
[ "javascript", "python", "mechanize" ]
How to click a link that has javascript:__doPostBack in href?
1,418,000
<p>I am writing a screen scraper script in python with module 'mechanize' and I would like to use the mechanize.click_link() method on a link that has javascript:__doPostBack in href. I believe the page I am trying to parse is using AJAX.</p> <p>Note: mech is the mechanize.Browser()</p> <pre><code>&gt;&gt;&gt; next_...
4
2009-09-13T15:30:52Z
5,157,699
<p>I don't use mechanize, but I do a lot of web scraping myself with python.<p> When I run into a javascript function like __doPostBack, I do the following:<br> I access the web site in Firefox, and use the <a href="https://addons.mozilla.org/en-US/firefox/addon/httpfox/" rel="nofollow">HttpFox</a> extension to see the...
5
2011-03-01T17:00:16Z
[ "javascript", "python", "mechanize" ]
How to get Python exception text
1,418,015
<p>I want to embed python in my C++ application. I'm using Boost library - great tool. But i have one problem. </p> <p>If python function throws an exception, i want to catch it and print error in my application or get some detailed information like line number in python script that caused error.</p> <p>How can i do ...
33
2009-09-13T15:36:30Z
1,418,386
<p>In the Python C API, <a href="http://docs.python.org/c-api/object.html#PyObject%5FStr" rel="nofollow"><code>PyObject_Str</code></a> returns a new reference to a Python string object with the string form of the Python object you're passing as the argument -- just like <code>str(o)</code> in Python code. Note that the...
4
2009-09-13T17:54:12Z
[ "c++", "python", "exception", "boost-python" ]
How to get Python exception text
1,418,015
<p>I want to embed python in my C++ application. I'm using Boost library - great tool. But i have one problem. </p> <p>If python function throws an exception, i want to catch it and print error in my application or get some detailed information like line number in python script that caused error.</p> <p>How can i do ...
33
2009-09-13T15:36:30Z
1,418,703
<p>Well, I found out how to do it.</p> <p>Without boost (only error message, because code to extract info from traceback is too heavy to post it here):</p> <pre><code>PyObject *ptype, *pvalue, *ptraceback; PyErr_Fetch(&amp;ptype, &amp;pvalue, &amp;ptraceback); //pvalue contains error message //ptraceback contains sta...
37
2009-09-13T20:05:17Z
[ "c++", "python", "exception", "boost-python" ]
How to get Python exception text
1,418,015
<p>I want to embed python in my C++ application. I'm using Boost library - great tool. But i have one problem. </p> <p>If python function throws an exception, i want to catch it and print error in my application or get some detailed information like line number in python script that caused error.</p> <p>How can i do ...
33
2009-09-13T15:36:30Z
6,576,177
<p>This is the most robust method I've been able to come up so far:</p> <pre><code> try { ... } catch (bp::error_already_set) { if (PyErr_Occurred()) { msg = handle_pyerror(); } py_exception = true; bp::handle_exception(); PyErr_Clear(); } ...
15
2011-07-04T21:22:58Z
[ "c++", "python", "exception", "boost-python" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
1,418,419
<p>There are a few options:</p> <ul> <li><p>You could use Selenium Grid so that the browser is opened on a completely different machine (or virtual machine) that you can then connect to via VNC or Remote Desktop Connection if you wanted to see the browser. Also, another option: if you run a Jenkins foreground proces...
77
2009-09-13T18:04:33Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
1,419,676
<p>+1 for Selenium RC as a windows service.</p> <p>For having the tests run completely hidden, I think you don't have much solutions if you're on windows. </p> <p>What I'd do it to dedicate a computer in your LAN to be online all the time and have a selenium RC server running. So you use that computer's IP instead of...
13
2009-09-14T04:28:56Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
1,750,751
<p>If you're on Windows, one option is to <strong>run the tests under a different user account</strong>. This means the browser and java server will not be visible to your own account.</p>
5
2009-11-17T18:16:16Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
8,910,326
<p>On *nix, you can run WebDriver in a headless (virtual) display to hide the browser. This can be done with <a href="http://en.wikipedia.org/wiki/Xvfb">Xvfb</a>.</p> <p>I personally use Python on Linux, and the <a href="http://pypi.python.org/pypi/PyVirtualDisplay">PyVirtualDisplay</a> module to handle Xvfb for me.<...
49
2012-01-18T12:48:05Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
11,261,393
<p>This is how I run my tests with maven on a linux desktop (Ubuntu). I got fed up not being able to work with the firefox webdriver always taking focus.</p> <p>I installed xvfb </p> <blockquote> <p>xvfb-run -a mvn clean install</p> </blockquote> <p>Thats it</p>
3
2012-06-29T12:00:18Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
14,155,698
<p>On Linux, you can run your test browser on a virtual display. You will need the <code>xvfb</code> package for creating a virtual X server. On Debian based distros, just run</p> <pre><code>sudo apt-get install xvfb </code></pre> <p>There is a nice tool <a href="http://semicomplete.com/blog/geekery/headless-wrapper-...
11
2013-01-04T10:50:19Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
22,846,912
<p>There is a PhantomJS related project called <a href="https://github.com/detro/ghostdriver" rel="nofollow">GhostDriver</a> , that is meant to run PhantomJS instances in a Selenium Grid using webdriver wire JSON protocol. That is probably what you are looking for, although this question is 4 years old now.</p>
0
2014-04-03T19:17:02Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
23,898,054
<p>I easily managed to hide the browser window.</p> <p>Just <a href="http://phantomjs.org/download.html">install PhantomJS</a>. Then, change this line:</p> <pre><code>driver = webdriver.Firefox() </code></pre> <p>to:</p> <pre><code>driver = webdriver.PhantomJS() </code></pre> <p>The rest of your code won't need to...
13
2014-05-27T20:11:00Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
24,662,478
<p>On MacOSX, I haven't been able to hide the browser window, but at least I figured out how to move it to a different display so it doesn't disrupt my workflow so much. While Firefox is running tests, just control-click its icon in the dock, select Options, and Assign to Display 2.</p>
0
2014-07-09T19:43:35Z
[ "python", "selenium", "selenium-rc" ]
Is it possible to hide the browser in Selenium RC?
1,418,082
<p>I am using Selenium RC to automate some browser operations but I want the browser to be invisible. Is this possible? How? What about Selenium Grid? Can I hide the Selenium RC window also?</p>
76
2009-09-13T16:07:53Z
38,768,819
<pre><code>curl -k https://gist.githubusercontent.com/terrancesnyder/995250/raw/cdd1f52353bb614a5a016c2e8e77a2afb718f3c3/ephemeral-x.sh -o ~/ephemeral-x.sh chmod +x ~/ephemeral-x.sh ~/ephemeral-x.sh TestsStarterCommand </code></pre> <p>By the way this is a feature needed by any developer running e2e that logically wil...
0
2016-08-04T13:32:28Z
[ "python", "selenium", "selenium-rc" ]
django newbie. Having trouble with ModelForm
1,418,149
<p>i'm trying to write a very simple django app. I cant get it to show my form inside my template.</p> <pre><code>&lt;form ...&gt; {{form.as_p}} &lt;/form&gt; </code></pre> <p>it shows absolutely nothing. If I add a submit button, it only shows that. </p> <p>Do I have to declare a form object that inherits from form...
0
2009-09-13T16:34:23Z
1,418,206
<p>The problem is in your view. You will have no existing student object to retrieve from the database. The following code sample will help you implement an "create" view.</p> <p>As a side note, you might like using the direct_to_template generic view function to make your life a bit easier.</p> <pre><code>def add_s...
2
2009-09-13T16:52:09Z
[ "python", "django" ]
Python implementation question
1,418,255
<p>Hey. I have a problem I'm trying to solve in Python and I can't think of a clever implementation. The input is a string of letters. Some of them represent variables, others represent operators, and I want to iterate over a large amount of values for the variables (different configurations).</p> <p>I think an equiva...
0
2009-09-13T17:11:39Z
1,418,273
<p>What you want is obviously an expression evaluator.</p> <p>Other you use a built in facility in the language typically called "eval" (I don't know if Python offers this) or you build an expression parser/evaluator.</p> <p>To get some of ideas of how to build such an expression evaluator, you can look at the follow...
0
2009-09-13T17:18:24Z
[ "python", "data-structures", "implementation", "formula" ]
Python implementation question
1,418,255
<p>Hey. I have a problem I'm trying to solve in Python and I can't think of a clever implementation. The input is a string of letters. Some of them represent variables, others represent operators, and I want to iterate over a large amount of values for the variables (different configurations).</p> <p>I think an equiva...
0
2009-09-13T17:11:39Z
1,418,334
<p>Parse that string into a tree (or equivalently interpretable data structure), just once, and then repeatedly use a function to "interpret the tree" for each variable-assignment-set of interest. (You could even generate Python bytecode as the "interpretable data structure" so you can just use <code>eval</code> as the...
0
2009-09-13T17:39:22Z
[ "python", "data-structures", "implementation", "formula" ]
Python implementation question
1,418,255
<p>Hey. I have a problem I'm trying to solve in Python and I can't think of a clever implementation. The input is a string of letters. Some of them represent variables, others represent operators, and I want to iterate over a large amount of values for the variables (different configurations).</p> <p>I think an equiva...
0
2009-09-13T17:11:39Z
1,418,346
<p>as Ira said you need an expression evaluator like Lex/Yacc to do this job, you have plenty available here :</p> <p><a href="http://wiki.python.org/moin/LanguageParsing" rel="nofollow">http://wiki.python.org/moin/LanguageParsing</a></p> <p>I have been using <a href="http://pyparsing.wikispaces.com/" rel="nofollow">...
1
2009-09-13T17:42:08Z
[ "python", "data-structures", "implementation", "formula" ]
Python implementation question
1,418,255
<p>Hey. I have a problem I'm trying to solve in Python and I can't think of a clever implementation. The input is a string of letters. Some of them represent variables, others represent operators, and I want to iterate over a large amount of values for the variables (different configurations).</p> <p>I think an equiva...
0
2009-09-13T17:11:39Z
1,418,398
<p>I see that the <code>eval</code> idea has already been mentioned, and this won't help if you have operators to substitute, but I've used the following in the past:</p> <pre><code>def evaluate_expression(expr, context): try: return eval(expr, {'__builtins__': None}, context) except (TypeError, ZeroDi...
0
2009-09-13T17:56:41Z
[ "python", "data-structures", "implementation", "formula" ]
Access an instance from Terminal
1,418,262
<p>Can't figure this out. In Terminal, I import a module which instantiates a class, which I haven't figured out how to access. Of course, I can always instantiate in Terminal:</p> <pre> Server=Data.ServerData() </pre> <p>Then I can get a result:</p> <pre> Server.Property().DefaultChart </pre> <p>However, I want to...
0
2009-09-13T17:14:22Z
1,418,356
<p>If importing <code>Data.py</code> implicitly creates an instance of the <code>Data.ServerData</code> class (somewhat dubious, but OK in certain cases), that still tells us nothing about how that module chose to name that one instance. Do <code>dir(Data)</code> at the <code>&gt;&gt;&gt;</code> prompt to see all the ...
2
2009-09-13T17:46:48Z
[ "python", "class", "module", "instance", "interactive" ]
Which is more pythonic for array removal?
1,418,266
<p>I'm removing an item from an array if it exists.</p> <p>Two ways I can think of to do this</p> <h2>Way #1</h2> <pre> # x array, r item to remove if r in x : x.remove( r ) </pre> <h2>Way #2</h2> <pre> try : x.remove( r ) except : pass </pre> <p>Timing it shows the try/except way <b>can be</b> faster</p> ...
2
2009-09-13T17:15:54Z
1,418,275
<p>The try/except way</p>
2
2009-09-13T17:18:56Z
[ "python" ]
Which is more pythonic for array removal?
1,418,266
<p>I'm removing an item from an array if it exists.</p> <p>Two ways I can think of to do this</p> <h2>Way #1</h2> <pre> # x array, r item to remove if r in x : x.remove( r ) </pre> <h2>Way #2</h2> <pre> try : x.remove( r ) except : pass </pre> <p>Timing it shows the try/except way <b>can be</b> faster</p> ...
2
2009-09-13T17:15:54Z
1,418,293
<p>that would be:</p> <pre><code>try: x.remove(r) except ValueError: pass </code></pre> <p>btw, you should have tried to remove an item that is not in the list, to have a comprehensive comparison.</p>
5
2009-09-13T17:22:19Z
[ "python" ]
Which is more pythonic for array removal?
1,418,266
<p>I'm removing an item from an array if it exists.</p> <p>Two ways I can think of to do this</p> <h2>Way #1</h2> <pre> # x array, r item to remove if r in x : x.remove( r ) </pre> <h2>Way #2</h2> <pre> try : x.remove( r ) except : pass </pre> <p>Timing it shows the try/except way <b>can be</b> faster</p> ...
2
2009-09-13T17:15:54Z
1,418,308
<p>The first way looks cleaner. The second looks like a lot of extra effort just to remove an item from a list.</p> <p>There's nothing about it in <a href="http://python.org/dev/peps/pep-0008/" rel="nofollow">PEP-8</a>, though, so whichever you prefer is the 'real' answer.</p> <p>Speaking of PEP-8... having that spa...
1
2009-09-13T17:29:16Z
[ "python" ]
Which is more pythonic for array removal?
1,418,266
<p>I'm removing an item from an array if it exists.</p> <p>Two ways I can think of to do this</p> <h2>Way #1</h2> <pre> # x array, r item to remove if r in x : x.remove( r ) </pre> <h2>Way #2</h2> <pre> try : x.remove( r ) except : pass </pre> <p>Timing it shows the try/except way <b>can be</b> faster</p> ...
2
2009-09-13T17:15:54Z
1,418,310
<p>I've always gone with the first method. <code>if in</code> reads far more clearly than exception handling does.</p>
6
2009-09-13T17:30:13Z
[ "python" ]
Which is more pythonic for array removal?
1,418,266
<p>I'm removing an item from an array if it exists.</p> <p>Two ways I can think of to do this</p> <h2>Way #1</h2> <pre> # x array, r item to remove if r in x : x.remove( r ) </pre> <h2>Way #2</h2> <pre> try : x.remove( r ) except : pass </pre> <p>Timing it shows the try/except way <b>can be</b> faster</p> ...
2
2009-09-13T17:15:54Z
1,418,321
<p>Speed depends on the ratio of hits to misses. To be pythonic choose the clearer method.</p> <p>Personally I think way#1 is clearer (It takes less lines to have an 'if' block rather than an exception block and also uses less brain space). It will also be faster when there are more hits than misses (an exception is m...
3
2009-09-13T17:34:35Z
[ "python" ]
Auto executable python file without opening from terminal?
1,418,553
<p>Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions.</p> <p><strong>Clarificatio...
2
2009-09-13T18:53:39Z
1,418,559
<p>Have you placed this at the beginning of the file:</p> <pre><code>#!/usr/bin/python </code></pre> <p>?</p>
0
2009-09-13T18:55:03Z
[ "python", "linux" ]
Auto executable python file without opening from terminal?
1,418,553
<p>Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions.</p> <p><strong>Clarificatio...
2
2009-09-13T18:53:39Z
1,418,563
<p>On the first line in your python file, add this:</p> <pre><code>#!/usr/bin/env python </code></pre> <p>So if you have:</p> <pre><code>print "Hello World" </code></pre> <p>You should then have:</p> <pre><code>#!/usr/bin/env python print "Hello World" </code></pre>
4
2009-09-13T18:56:01Z
[ "python", "linux" ]
Auto executable python file without opening from terminal?
1,418,553
<p>Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions.</p> <p><strong>Clarificatio...
2
2009-09-13T18:53:39Z
1,418,600
<p>As others have said, you need put the <a href="http://en.wikipedia.org/wiki/Shebang%5F(Unix)" rel="nofollow">"shebang"</a> at the start of the file, to say which interpreter to use to execute the file.</p> <p>As mentioned in the above link, the most portable way is to use the <code>env</code> command (instead of a ...
0
2009-09-13T19:13:12Z
[ "python", "linux" ]
Auto executable python file without opening from terminal?
1,418,553
<p>Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions.</p> <p><strong>Clarificatio...
2
2009-09-13T18:53:39Z
1,419,455
<p>First, pick a file extension you want for files you want to have this behavior. pyw is probably a good choice. </p> <p>Name your file that, and in your file browser associate that file type with python. In GNOME, you'd open its Properties window, go to the Open With tab, and enter python as a custom command. </p> ...
3
2009-09-14T02:30:50Z
[ "python", "linux" ]
Auto executable python file without opening from terminal?
1,418,553
<p>Sorry if this is on the wrong site ( maybe superuser ) but I'm trying to make my python.py file executable so I can click on it and it automatically does its thing, without me specifying it to open in the terminal by that default prompt, and I already have 'chmod +x' for its permissions.</p> <p><strong>Clarificatio...
2
2009-09-13T18:53:39Z
7,682,271
<p><a href="http://supervisord.org" rel="nofollow">http://supervisord.org</a> is better choice. </p>
1
2011-10-07T01:38:47Z
[ "python", "linux" ]
How expensive are Python dictionaries to handle?
1,418,588
<p>As the title states, how expensive are Python dictionaries to handle? Creation, insertion, updating, deletion, all of it.</p> <p>Asymptotic time complexities are interesting themselves, but also how they compare to e.g. tuples or normal lists.</p>
23
2009-09-13T19:03:50Z
1,418,591
<p>Dictionaries are one of the more heavily tuned parts of Python, since they underlie so much of the language. For example, members of a class, and variables in a stack frame are both stored internally in dictionaries. They will be a good choice if they are the right data structure.</p> <p>Choosing between lists an...
10
2009-09-13T19:05:33Z
[ "python", "performance", "data-structures", "dictionary" ]
How expensive are Python dictionaries to handle?
1,418,588
<p>As the title states, how expensive are Python dictionaries to handle? Creation, insertion, updating, deletion, all of it.</p> <p>Asymptotic time complexities are interesting themselves, but also how they compare to e.g. tuples or normal lists.</p>
23
2009-09-13T19:03:50Z
1,419,324
<p><code>dicts</code> (just like <code>set</code>s when you don't need to associate a value to each key but simply record if a key is present or absent) are pretty heavily optimized. Creating a <code>dict</code> from N keys or key/value pairs is <code>O(N)</code>, fetching is <code>O(1)</code>, putting is amortized <co...
40
2009-09-14T01:27:52Z
[ "python", "performance", "data-structures", "dictionary" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
1,418,832
<p>Please take a look at the <a href="http://docs.python.org/reference/datamodel.html#special-method-names">special method names section</a> in the Python language reference.</p>
31
2009-09-13T21:05:41Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
1,418,834
<p>Here is a <a href="http://www.ironpythoninaction.com/magic-methods.html">complete reference of all the Python magic methods</a>.</p>
5
2009-09-13T21:06:14Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
1,418,844
<p>Dive Into Python has <a href="http://web.archive.org/web/20110131211638/http://diveintopython3.org/special-method-names.html" rel="nofollow">an excellent appendix</a> for them.</p>
7
2009-09-13T21:11:25Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
1,418,856
<p>See <a href="http://rgruet.free.fr/PQR25/PQR2.5.html#SpecialMethods" rel="nofollow">Python Quick reference</a></p>
3
2009-09-13T21:16:10Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
1,418,931
<p>Familiarize yourself with the dir function.</p>
0
2009-09-13T21:49:58Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
18,661,094
<p>For somebody who is relatively new to Python, and for whom the documentation is often not quite accessible enough (like myself): somebody wrote a <a href="http://www.rafekettler.com/magicmethods.html" rel="nofollow">nice introduction</a> with lots of examples on how the special (magic) methods work, how to use them,...
2
2013-09-06T15:16:59Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
37,172,655
<p>If, like me, you want a plain, unadorned list, here it is. I compiled it based on the <a href="https://docs.python.org/2/reference/datamodel.html#special-method-names" rel="nofollow">Python documentation link</a> from the accepted answer.</p> <pre><code>__abs__ __add__ __and__ __call__ __class__ __cmp__ __coerce__...
1
2016-05-11T20:26:07Z
[ "python", "class", "methods", "double-underscore" ]
Where is the Python documentation for the special methods? (__init__, __new__, __len__, ...)
1,418,825
<p>Where is a complete list of the special double-underscore/dunder methods that can be used in classes? (e.g., <code>__init__</code>, <code>__new__</code>, <code>__len__</code>, <code>__add__</code>)</p>
11
2009-09-13T21:02:02Z
37,850,243
<p>Do this if you prefer reading documentation from a CLI instead of the browser. </p> <p><code>$ pydoc SPECIALMETHODS</code></p>
0
2016-06-16T05:03:20Z
[ "python", "class", "methods", "double-underscore" ]
Are Python list comprehensions the same thing as map/grep in Perl?
1,418,912
<p>I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">this page</a>) can all be d...
14
2009-09-13T21:41:58Z
1,418,915
<p>You are correct: a list comprehension is essentially just syntactic sugar for map and filter (terms from the functional programming world).</p> <p>Hopefully this sample code demonstrates their equality:</p> <pre><code>&gt;&gt;&gt; # Python 2 &gt;&gt;&gt; [x**2 for x in range(10)] == map(lambda x: x**2, range(10)) ...
13
2009-09-13T21:43:16Z
[ "python", "perl", "list" ]
Are Python list comprehensions the same thing as map/grep in Perl?
1,418,912
<p>I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">this page</a>) can all be d...
14
2009-09-13T21:41:58Z
1,418,925
<p>List comprehensions are more powerful than map or filter as they allow you to abstractly play with lists.</p> <p>It also more convenient to use them when your maps are further nested with more maps and filter calls.</p>
0
2009-09-13T21:46:46Z
[ "python", "perl", "list" ]
Are Python list comprehensions the same thing as map/grep in Perl?
1,418,912
<p>I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">this page</a>) can all be d...
14
2009-09-13T21:41:58Z
1,418,933
<p>Yes, they are basically the same.</p> <p>In fact Python also has a map function:</p> <pre><code>S = map(lambda x: x**2, range(10)) </code></pre> <p>is the same as your first examples above. However, the list comprehension syntax is strongly preferred in Python. I believe Guido has been quoted as saying he regrets...
3
2009-09-13T21:50:10Z
[ "python", "perl", "list" ]
Are Python list comprehensions the same thing as map/grep in Perl?
1,418,912
<p>I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">this page</a>) can all be d...
14
2009-09-13T21:41:58Z
1,418,948
<p>Yes. The power of the Python syntax is that the same syntax (within round rather than square brackets) is also used to define generators, which produce sequences of values on demand.</p>
0
2009-09-13T21:57:13Z
[ "python", "perl", "list" ]
Are Python list comprehensions the same thing as map/grep in Perl?
1,418,912
<p>I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">this page</a>) can all be d...
14
2009-09-13T21:41:58Z
1,419,002
<p>They're the "pythonic" version for mapping and filtering sequences, but they allow to do some others things, like flattening a (fixed level) nested list, for example:</p> <pre><code>[j for i in nested_list for j in i] </code></pre> <p>Another thing that you cannot do with a regular <em>map</em> and a lambda expres...
2
2009-09-13T22:18:41Z
[ "python", "perl", "list" ]
Are Python list comprehensions the same thing as map/grep in Perl?
1,418,912
<p>I was having some trouble grokking the list comprehension syntax in Python, so I started thinking about how to achieve the same thing in Perl, which I'm more familiar with. I realized that the basic examples (taken from <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk">this page</a>) can all be d...
14
2009-09-13T21:41:58Z
1,419,036
<p>List comprehensions also flatten out things:</p> <p>For example:</p> <p>[(x, y) for x in xrange(10) if x%2 == 0 for y in xrange(20) if x!=y]</p> <p>If you used nested maps here, you'd have to use concat (summing the lists) too.</p>
2
2009-09-13T22:46:25Z
[ "python", "perl", "list" ]
What variable name do you use for file descriptors?
1,419,039
<p>A pretty silly trivial question. The canonical example is <code>f = open('filename')</code>, but</p> <ul> <li><code>f</code> is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI.</li> <li>I...
4
2009-09-13T22:48:42Z
1,419,048
<pre><code> data_file settings_file results_file .... etc </code></pre>
4
2009-09-13T22:55:08Z
[ "python", "file", "naming-conventions", "explicit", "variable-names" ]
What variable name do you use for file descriptors?
1,419,039
<p>A pretty silly trivial question. The canonical example is <code>f = open('filename')</code>, but</p> <ul> <li><code>f</code> is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI.</li> <li>I...
4
2009-09-13T22:48:42Z
1,419,050
<p>generally I'll use "fp" for a short-lifetime file pointer.</p> <p>for a longer-lived descriptor, I'll be more descriptive. "fpDebugLog", for example.</p>
1
2009-09-13T22:55:33Z
[ "python", "file", "naming-conventions", "explicit", "variable-names" ]
What variable name do you use for file descriptors?
1,419,039
<p>A pretty silly trivial question. The canonical example is <code>f = open('filename')</code>, but</p> <ul> <li><code>f</code> is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI.</li> <li>I...
4
2009-09-13T22:48:42Z
1,419,054
<p>You can append it to the beginning, Hungarian-like "file_fft".</p> <p>However, I would try to close file descriptors as soon as possible, and I recommend using the with statement like this so you don't have to worry about closing it, and it makes it easier to not lose track of it.</p> <pre><code>with open("x.txt")...
3
2009-09-13T22:56:23Z
[ "python", "file", "naming-conventions", "explicit", "variable-names" ]
What variable name do you use for file descriptors?
1,419,039
<p>A pretty silly trivial question. The canonical example is <code>f = open('filename')</code>, but</p> <ul> <li><code>f</code> is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI.</li> <li>I...
4
2009-09-13T22:48:42Z
1,419,303
<p>I'm happy to use <code>f</code> (for either a function OR a file;-) if that identifier's scope is constrained to a pretty small compass (such as <code>with open('zap') as f:</code> would normally portend, say). In general, identifiers with large lexical scopes should be longer and more explicit, ones with lexically ...
3
2009-09-14T01:15:12Z
[ "python", "file", "naming-conventions", "explicit", "variable-names" ]
What variable name do you use for file descriptors?
1,419,039
<p>A pretty silly trivial question. The canonical example is <code>f = open('filename')</code>, but</p> <ul> <li><code>f</code> is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI.</li> <li>I...
4
2009-09-13T22:48:42Z
1,420,872
<p>I rather use one of: <code>f, fp, fd</code>.</p> <p>Sometimes <code>inf</code> / <code>outf</code> for input and output file.</p>
-1
2009-09-14T10:56:30Z
[ "python", "file", "naming-conventions", "explicit", "variable-names" ]
What variable name do you use for file descriptors?
1,419,039
<p>A pretty silly trivial question. The canonical example is <code>f = open('filename')</code>, but</p> <ul> <li><code>f</code> is not very descriptive. After not looking at code in a while, you can forget whether it means "file" or "function f(x)" or "fourier transform results" or something else. EIBTI.</li> <li>I...
4
2009-09-13T22:48:42Z
1,420,921
<p>Generally if the scope of a file object is only a few lines, <code>f</code> is perfectly readable - the variable name for the filename in the open call is probably descriptive enough. otherwise <code>something_file</code> is probably a good idea.</p>
1
2009-09-14T11:08:03Z
[ "python", "file", "naming-conventions", "explicit", "variable-names" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
1,419,098
<p>There are two ways to assign argument values to function parameters, both are used.</p> <ol> <li><p>By Position. Positional arguments do not have keywords and are assigned first.</p></li> <li><p>By Keyword. Keyword arguments have keywords and are assigned second, after positional arguments.</p></li> </ol> <p>Not...
17
2009-09-13T23:14:16Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
1,419,107
<p>Using keyword arguments is the same thing as normal arguments except order doesn't matter. For example the two functions calls below are the same:</p> <pre><code>def foo(bar, baz): pass foo(1, 2) foo(baz=2, bar=1) </code></pre>
44
2009-09-13T23:17:03Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
1,419,110
<h1>Normal Arguments</h1> <p>They have no keywords before them. The order is important!</p> <pre><code>func(1,2,3, "foo") </code></pre> <h1>Keyword Arguments</h1> <p>They have keywords in the front. They can be in any order!</p> <pre><code>func(foo="bar", baz=5, hello=123) func(baz=5, foo="bar", hello=123) </code...
17
2009-09-13T23:17:40Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
1,419,149
<p>I'm surprised no one has mentioned the fact that you can mix positional and keyword arguments to do sneaky things like this using <code>*args</code> and <code>**kwargs</code> (<a href="http://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/">from this site</a>):</p> <pre><code>def test_var_kwar...
7
2009-09-13T23:52:00Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
1,419,159
<p>There is one last language feature where the distinction is important. Consider the following function:</p> <pre><code>def foo(*positional, **keywords): print "Positional:", positional print "Keywords:", keywords </code></pre> <p>The <code>*positional</code> argument will store all of the positional argume...
78
2009-09-13T23:58:17Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
1,419,160
<p>there are two related concepts, both called "keyword arguments".</p> <p>On the calling side, which is what other commenters have mentioned, you have the ability to specify some function arguments by name. You have to mention them after all of the arguments without names (positional arguments), and there must be def...
142
2009-09-13T23:58:51Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
16,368,276
<p>I'm surprised that no one seems to have pointed out that one can pass a dictionary of keyed argument parameters, that satisfy the formal parameters, like so.</p> <pre><code>&gt;&gt;&gt; def func(a='a', b='b', c='c', **kwargs): ... print 'a:%s, b:%s, c:%s' % (a, b, c) ... &gt;&gt;&gt; func() a:a, b:b, c:c &gt;&g...
10
2013-05-03T22:07:55Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python normal arguments vs. keyword arguments
1,419,046
<p>How are "keyword arguments" different from regular arguments? Can't all arguments be passed as <code>name=value</code> instead of using positional syntax?</p>
115
2009-09-13T22:54:00Z
36,446,353
<p>Using <strong>Python 3</strong> you can have both required and non-required keyword <a href="https://docs.python.org/3/reference/expressions.html#calls" rel="nofollow">arguments</a>:</p> <p><strong>Optional</strong>: (default value defined for 'b')</p> <pre><code>def func1(a, *, b=42): ... func1(value_for_a) #...
1
2016-04-06T09:04:20Z
[ "python", "arguments", "keyword", "optional-parameters", "named-parameters" ]
Python memory leaks?
1,419,065
<p>I am writing a python extension that seems to be leaking memory. I am trying to figure out the soure of the problem using valgrind. </p> <p>However, it seems that python itself is leaking memory according to valgrind. Using the following simple script:</p> <p><strong>hello.py</strong></p> <pre><code> print "Hell...
7
2009-09-13T23:03:01Z
1,419,083
<p>The leak is most likely coming from your own extension, not from Python. Large systems often exit with memory still allocated, simply because it isn't worth it to explicitly free it if the process is about to end anyway.</p>
1
2009-09-13T23:09:53Z
[ "python", "memory", "memory-management", "valgrind" ]
Python memory leaks?
1,419,065
<p>I am writing a python extension that seems to be leaking memory. I am trying to figure out the soure of the problem using valgrind. </p> <p>However, it seems that python itself is leaking memory according to valgrind. Using the following simple script:</p> <p><strong>hello.py</strong></p> <pre><code> print "Hell...
7
2009-09-13T23:03:01Z
1,419,264
<p>There's a whole README.valgrind in the Python sources that explains the various caveats trying to use Valgrind with Python:</p> <p><a href="http://svn.python.org/projects/python/trunk/Misc/README.valgrind">http://svn.python.org/projects/python/trunk/Misc/README.valgrind</a></p> <pre><code>Python uses its own small...
12
2009-09-14T01:01:03Z
[ "python", "memory", "memory-management", "valgrind" ]
In python, is there a "pass" equivalent for a variable assignment
1,419,077
<p>I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused.</p> <p>This works great and causes no troubl...
25
2009-09-13T23:08:25Z
1,419,082
<p>I think there's nothing wrong with using the [0] subscript, but sometimes people use the "throwaway" variable _. It's actually just like any other variable (with special usage in the console), except that some Python users decided to have it be "throwaway" as a convention.</p> <pre><code>count, _ = get_count_and_p...
28
2009-09-13T23:09:51Z
[ "python", "core" ]
In python, is there a "pass" equivalent for a variable assignment
1,419,077
<p>I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused.</p> <p>This works great and causes no troubl...
25
2009-09-13T23:08:25Z
1,419,085
<p>We often do this.</p> <pre><code>count, _ = get_count_and_price() </code></pre> <p>or this</p> <pre><code>count, junk = get_count_and_price() </code></pre>
3
2009-09-13T23:10:12Z
[ "python", "core" ]
In python, is there a "pass" equivalent for a variable assignment
1,419,077
<p>I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused.</p> <p>This works great and causes no troubl...
25
2009-09-13T23:08:25Z
1,419,093
<p>If you go to the Eclipse -> Preferences… window, you can actually specify which variable names PyDev should ignore if they're unused (I'm looking at the newest PyDev 1.5.X).</p> <p>If you go to PyDev -> Editor -> Code Analysis and look at the last field that says "Don't report unused variable if name starts with"...
7
2009-09-13T23:12:10Z
[ "python", "core" ]
In python, is there a "pass" equivalent for a variable assignment
1,419,077
<p>I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused.</p> <p>This works great and causes no troubl...
25
2009-09-13T23:08:25Z
1,419,265
<p>Using <code>_</code> as severally proposed may have some issues (though it's mostly OK). By the Python style guidelines we use at work I'd normally use <code>count, unused_price = ...</code> since pylint is configured to ignore assignments to barenames starting with <code>unused_</code> (and warn on USE of any such ...
20
2009-09-14T01:01:15Z
[ "python", "core" ]
In python, is there a "pass" equivalent for a variable assignment
1,419,077
<p>I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused.</p> <p>This works great and causes no troubl...
25
2009-09-13T23:08:25Z
8,697,239
<p>I'd rather name it <code>_price</code> instead, for these reasons:</p> <ul> <li><p>It solves the conflict with gettext and the interactive prompt, which both use <code>_</code></p></li> <li><p>It's easy to change back into <code>price</code> if you end up needing it later.</p></li> <li><p>As others have pointed out...
2
2012-01-02T03:46:23Z
[ "python", "core" ]
In python, is there a "pass" equivalent for a variable assignment
1,419,077
<p>I am using a library function called get_count_and_price which returns a 2-tuple (count,price). In many places I use both time and price. However, in some I only need time or price. So right now, if I only need count, I assign to (count,price) and leave the price unused.</p> <p>This works great and causes no troubl...
25
2009-09-13T23:08:25Z
11,372,836
<p>I'll go after a Necromancer badge. :)</p> <p>You said you're using PyDev. In PyDev (at least recent versions - I didn't check how far back), any variable name that starts with "unused" will be exempt from the Unused Variable warning. Other static analysis tool may still complain, though (pyflakes does - but it seem...
1
2012-07-07T06:30:11Z
[ "python", "core" ]
Cannot import file in Python/Django
1,419,224
<p>I'm not sure what's going on, but on my own laptop, everything works okay. When I upload to my host with Python 2.3.5, my views.py can't find anything in my models.py. I have:</p> <pre><code>from dtms.models import User from dtms.item_list import * </code></pre> <p>where my models, item_list, and views files are i...
0
2009-09-14T00:34:57Z
1,419,228
<p>Make sure your project (or the folder above your "dtms" app) is in python's <a href="http://docs.python.org/tutorial/modules.html#the-module-search-path" rel="nofollow">module search path</a>.</p> <p>This is something you may need to set in your web server's configuration. The reason it works in the django shell is...
0
2009-09-14T00:37:52Z
[ "python", "django" ]
Cannot import file in Python/Django
1,419,224
<p>I'm not sure what's going on, but on my own laptop, everything works okay. When I upload to my host with Python 2.3.5, my views.py can't find anything in my models.py. I have:</p> <pre><code>from dtms.models import User from dtms.item_list import * </code></pre> <p>where my models, item_list, and views files are i...
0
2009-09-14T00:34:57Z
1,419,281
<p>The fact that <code>from X import *</code> works does not guarantee that <code>from X import Wowie</code> will work too, you know (if you could wean yourself away from that <code>import *</code> addiction you'd be WAY happier on the long run, but, that's another issue;-).</p> <p>My general advice in import problems...
4
2009-09-14T01:07:53Z
[ "python", "django" ]
Cannot import file in Python/Django
1,419,224
<p>I'm not sure what's going on, but on my own laptop, everything works okay. When I upload to my host with Python 2.3.5, my views.py can't find anything in my models.py. I have:</p> <pre><code>from dtms.models import User from dtms.item_list import * </code></pre> <p>where my models, item_list, and views files are i...
0
2009-09-14T00:34:57Z
1,419,726
<p>I could be way off with this, but did you set the DJANGO_SETTINGS_MODULE environment variable yet? It affects what you can import. Set it to ".settings". It's also something that gets set when you fire up manage.py, so things work there that won't work in other situations with setting the variable beforehand.</p> <...
0
2009-09-14T04:51:41Z
[ "python", "django" ]