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 |
|---|---|---|---|---|---|---|---|---|---|
Cherrypy server unavailable from anything but localhost | 1,555,319 | <p>I am having an issue with cherrypy that looks solved, but doesn't work. I can only bind on localhost or 127.0.0.1. Windows XP Home and Mac OS X (linux untested), cherrypy 3.1.2, python 2.5.4. This is the end of my app:</p>
<pre><code>global_conf = {
'global': { 'server.environment= "production"'
... | 2 | 2009-10-12T15:46:01Z | 1,601,743 | <p>If you're using a dual-stack OS, it may be that localhost is resolving to ::1 (the IPv6 localhost) and not 127.0.0.1 (the IPv4 localhost). Try accessing the server using <a href="http://127.0.0.1:8080" rel="nofollow">http://127.0.0.1:8080</a>.</p>
<p>Also, if you're using an dual-stack capable OS, you can set serv... | 3 | 2009-10-21T15:44:15Z | [
"python",
"cherrypy"
] |
appengine remote api unable to login | 1,555,469 | <p>When I go to appengine.google.com/a/mydomain.com i am able to login and
see all my apps and administer them.</p>
<p>However, when I try to use the remote_api the same username/password does not work.</p>
<p>I'm using the interactive console code from <a href="http://code.google.com/appengine/articles/remote%5Fapi.... | 3 | 2009-10-12T16:13:20Z | 1,555,950 | <p>I've come across the same issue while developing for GAE on google apps. To make it work, I've created a simple wrapper around a snippet provided by Nick (blog.notdot.net - I can't seem to find the proper reference right now) that has been working for me. You can find it <a href="http://github.com/caio/bizarrice/blo... | 0 | 2009-10-12T17:43:33Z | [
"python",
"google-app-engine"
] |
appengine remote api unable to login | 1,555,469 | <p>When I go to appengine.google.com/a/mydomain.com i am able to login and
see all my apps and administer them.</p>
<p>However, when I try to use the remote_api the same username/password does not work.</p>
<p>I'm using the interactive console code from <a href="http://code.google.com/appengine/articles/remote%5Fapi.... | 3 | 2009-10-12T16:13:20Z | 1,642,695 | <p>This is a known issue with Google Accounts authentication. If you created an app and set it to use Google Accounts for authentication, and you yourself use a Google Apps account, you will not be able to authenticate against your app as an administrator using that account, even if you've created a Google Account for ... | 6 | 2009-10-29T10:14:21Z | [
"python",
"google-app-engine"
] |
sending a non-blocking HTTP POST request | 1,555,517 | <p>I have a two websites in php and python.
When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server.</p>
<p>Is it possible to continue running a php/python script after sen... | 10 | 2009-10-12T16:22:37Z | 1,555,614 | <p>What you need to do is have the PHP script execute another script that does the server call and then sends the user the request.</p>
| 1 | 2009-10-12T16:35:50Z | [
"php",
"python",
"nonblocking"
] |
sending a non-blocking HTTP POST request | 1,555,517 | <p>I have a two websites in php and python.
When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server.</p>
<p>Is it possible to continue running a php/python script after sen... | 10 | 2009-10-12T16:22:37Z | 1,555,641 | <p>You can spawn another process to handle the POST to the other server. In PHP you would spawn the process and "disconnect" so you don't wait for the response.</p>
<pre><code>exec("nohup /path/to/script/post_content.php > /dev/null 2>&1 &");
</code></pre>
<p>You can then you curl to perform the post. I... | 2 | 2009-10-12T16:41:14Z | [
"php",
"python",
"nonblocking"
] |
sending a non-blocking HTTP POST request | 1,555,517 | <p>I have a two websites in php and python.
When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server.</p>
<p>Is it possible to continue running a php/python script after sen... | 10 | 2009-10-12T16:22:37Z | 1,555,709 | <p>In PHP you can close the connection by sending this request (this is HTTP related and works also in python, although I don't know the proper syntax to use):</p>
<pre><code>// Send the response to the client
header('Connection: Close');
// Do the background job: just don't output anything!
</code></pre>
<p>Addendum... | 7 | 2009-10-12T16:55:03Z | [
"php",
"python",
"nonblocking"
] |
sending a non-blocking HTTP POST request | 1,555,517 | <p>I have a two websites in php and python.
When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server.</p>
<p>Is it possible to continue running a php/python script after sen... | 10 | 2009-10-12T16:22:37Z | 1,555,718 | <p><a href="http://github.com/progrium/hookah" rel="nofollow">Hookah</a> is designed to solve your problem.</p>
| -3 | 2009-10-12T16:57:46Z | [
"php",
"python",
"nonblocking"
] |
sending a non-blocking HTTP POST request | 1,555,517 | <p>I have a two websites in php and python.
When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server.</p>
<p>Is it possible to continue running a php/python script after sen... | 10 | 2009-10-12T16:22:37Z | 1,555,721 | <p>in python you could simply close the output stream, then continue to do your post request</p>
<pre><code>sys.stdout.close()
</code></pre>
| 0 | 2009-10-12T16:58:46Z | [
"php",
"python",
"nonblocking"
] |
sending a non-blocking HTTP POST request | 1,555,517 | <p>I have a two websites in php and python.
When a user sends a request to the server I need php/python to send an HTTP POST request to a remote server. I want to reply to the user immediately without waiting for a response from the remote server.</p>
<p>Is it possible to continue running a php/python script after sen... | 10 | 2009-10-12T16:22:37Z | 23,913,884 | <p>You have to use fsockopen. And don't listen to the result</p>
<pre><code><?php
$fp = fsockopen('example.com', 80);
$vars = array(
'hello' => 'world'
);
$content = http_build_query($vars);
fwrite($fp, "POST /reposter.php HTTP/1.1\r\n");
fwrite($fp, "Host: example.com\r\n");
fwrite($fp, "Content-Type: ap... | 0 | 2014-05-28T14:04:35Z | [
"php",
"python",
"nonblocking"
] |
Can one prevent Genshi from parsing HTML entities? | 1,555,644 | <p>I have the following Python code using Genshi (simplified):</p>
<pre><code>with open(pathToHTMLFile, 'r') as f:
template = MarkupTemplate(f.read())
finalPage = template.generate().render('html', doctype = 'html')
</code></pre>
<p>The source HTML file contains entities such as <code>&copy;</code>, <code>&am... | 3 | 2009-10-12T16:42:34Z | 1,555,869 | <p>Actually <code>&amp;</code> isn't passed through, it's parsed into an ampersand character, and then serialised back to <code>&amp;</code> on the way out because that's necessary to represent a literal ampersand in HTML. <code>&copy;</code>, on the other hand, is not a necessary escape, so it can be left ... | 9 | 2009-10-12T17:25:43Z | [
"python",
"html",
"entities",
"genshi"
] |
Can one prevent Genshi from parsing HTML entities? | 1,555,644 | <p>I have the following Python code using Genshi (simplified):</p>
<pre><code>with open(pathToHTMLFile, 'r') as f:
template = MarkupTemplate(f.read())
finalPage = template.generate().render('html', doctype = 'html')
</code></pre>
<p>The source HTML file contains entities such as <code>&copy;</code>, <code>&am... | 3 | 2009-10-12T16:42:34Z | 2,650,325 | <p>Sticking </p>
<pre><code><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</code></pre>
<p>in the <code><head></code> of your HTML should cause browsers to correctly render UTF-8.</p>
<p>To clarify, the root issue is that the corresponding © UTF-8 character does not render co... | 3 | 2010-04-16T03:02:04Z | [
"python",
"html",
"entities",
"genshi"
] |
Can one prevent Genshi from parsing HTML entities? | 1,555,644 | <p>I have the following Python code using Genshi (simplified):</p>
<pre><code>with open(pathToHTMLFile, 'r') as f:
template = MarkupTemplate(f.read())
finalPage = template.generate().render('html', doctype = 'html')
</code></pre>
<p>The source HTML file contains entities such as <code>&copy;</code>, <code>&am... | 3 | 2009-10-12T16:42:34Z | 20,451,838 | <p>To prevent escaping of (x)html markup characters in Genshi:</p>
<pre><code>from genshi.core import Markup
...
newstring = Markup(oldstring)
...
<now apply templates as before, but substituting newstring for oldstring>
</code></pre>
| 0 | 2013-12-08T09:29:48Z | [
"python",
"html",
"entities",
"genshi"
] |
How to dereference a memory location from python ctypes? | 1,555,944 | <p>I want to replicate the following c code in python ctypes:</p>
<pre><code>main() {
long *ptr = (long *)0x7fff96000000;
printf("%lx",*ptr);
}
</code></pre>
<p>I can figure out how to call this memory location as a function pointer but not just do a normal dereference:</p>
<pre><code>from ctypes import *
"""
&g... | 6 | 2009-10-12T17:42:06Z | 1,556,482 | <p><code>ctypes.cast</code>.</p>
<pre><code>>>> import ctypes
>>> c_long_p = ctypes.POINTER(ctypes.c_long)
>>> some_long = ctypes.c_long(42)
>>> ctypes.addressof(some_long)
4300833936
>>> ctypes.cast(4300833936, c_long_p)
<__main__.LP_c_long object at 0x1005983b0>
>... | 10 | 2009-10-12T19:43:44Z | [
"python",
"ctypes",
"ffi"
] |
Efficient way to find the largest key in a dictionary with non-zero value | 1,555,968 | <p>I'm new Python and trying to implement code in a more Pythonic and efficient fashion.
Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value?</p>
<p>Thanks</p>
| 5 | 2009-10-12T17:48:22Z | 1,555,991 | <p>Something like this should be reasonably fast:</p>
<pre><code>>>> x = {0: 5, 1: 7, 2: 0}
>>> max(k for k, v in x.iteritems() if v != 0)
1
</code></pre>
<p>(removing the <code>!= 0</code> will be slightly faster still, but obscures the meaning somewhat.)</p>
| 12 | 2009-10-12T17:51:55Z | [
"python",
"dictionary"
] |
Efficient way to find the largest key in a dictionary with non-zero value | 1,555,968 | <p>I'm new Python and trying to implement code in a more Pythonic and efficient fashion.
Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value?</p>
<p>Thanks</p>
| 5 | 2009-10-12T17:48:22Z | 1,555,997 | <p>Python's max function takes a <code>key=</code> parameter for a "measure" function.</p>
<pre><code>data = {1: 25, 0: 75}
def keymeasure(key):
return data[key] and key
print max(data, key=keymeasure)
</code></pre>
<p>Using an inline lambda to the same effect and same binding of local variables:</p>
<pre><code... | 1 | 2009-10-12T17:52:35Z | [
"python",
"dictionary"
] |
Efficient way to find the largest key in a dictionary with non-zero value | 1,555,968 | <p>I'm new Python and trying to implement code in a more Pythonic and efficient fashion.
Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value?</p>
<p>Thanks</p>
| 5 | 2009-10-12T17:48:22Z | 1,556,050 | <p>To get the largest key, you can use the <a href="http://docs.python.org/3.1/library/functions.html#max"><code>max</code></a> function and inspect the keys like this:</p>
<pre><code>max(x.iterkeys())
</code></pre>
<p>To filter out ones where the value is 0, you can use a <a href="http://docs.python.org/reference/ex... | 8 | 2009-10-12T18:09:11Z | [
"python",
"dictionary"
] |
Efficient way to find the largest key in a dictionary with non-zero value | 1,555,968 | <p>I'm new Python and trying to implement code in a more Pythonic and efficient fashion.
Given a dictionary with numeric keys and values, what is the best way to find the largest key with a non-zero value?</p>
<p>Thanks</p>
| 5 | 2009-10-12T17:48:22Z | 1,556,417 | <p>If I were you and speed was a big concern, I'd probably create a new container class "DictMax" that'd keep track of it's largest non-zero value elements by having an internal stack of indexes, where the top element of the stack is always the key of the largest element in the dictionary. That way you'd get the larges... | 0 | 2009-10-12T19:25:51Z | [
"python",
"dictionary"
] |
Python AppEngine And HTML | 1,555,978 | <p>I have a simple Hello World application in Python that i'm using with AppEngine, but i want to insert this in a HTML file, like this: I have a file called test.html and on it i have this snippet:</p>
<pre><code><center><img src="test.png></center>
// Here comes the Python App //
</code></pre>
<p>... | 0 | 2009-10-12T17:49:30Z | 1,556,000 | <p>You should work through the getting started docs at the AppEngine site. Specifically around templates:
<a href="http://code.google.com/appengine/docs/python/gettingstarted/templates.html" rel="nofollow">http://code.google.com/appengine/docs/python/gettingstarted/templates.html</a>.</p>
| 4 | 2009-10-12T17:54:12Z | [
"python",
"html",
"integrate"
] |
Python AppEngine And HTML | 1,555,978 | <p>I have a simple Hello World application in Python that i'm using with AppEngine, but i want to insert this in a HTML file, like this: I have a file called test.html and on it i have this snippet:</p>
<pre><code><center><img src="test.png></center>
// Here comes the Python App //
</code></pre>
<p>... | 0 | 2009-10-12T17:49:30Z | 1,556,010 | <p>Use the Django templates - the module comes built in with the app engine. I've used it <a href="http://github.com/sudhirj/mappr/blob/master/main.py" rel="nofollow">here</a> on line 42. The template used is <a href="http://github.com/sudhirj/mappr/blob/master/templates/index.html" rel="nofollow">here</a>.</p>
| 2 | 2009-10-12T17:57:08Z | [
"python",
"html",
"integrate"
] |
Python AppEngine And HTML | 1,555,978 | <p>I have a simple Hello World application in Python that i'm using with AppEngine, but i want to insert this in a HTML file, like this: I have a file called test.html and on it i have this snippet:</p>
<pre><code><center><img src="test.png></center>
// Here comes the Python App //
</code></pre>
<p>... | 0 | 2009-10-12T17:49:30Z | 12,961,478 | <p>I would really recommend using a boilerplate template
<a href="https://github.com/coto/gae-boilerplate" rel="nofollow">https://github.com/coto/gae-boilerplate</a>
This would give you the layout and template structure for developing useful and professional sites </p>
| 1 | 2012-10-18T18:37:42Z | [
"python",
"html",
"integrate"
] |
In Django, How Do I Move Images When A Dynamic Path Changes? | 1,556,040 | <p>I have a Django app with an image field (a custom ThumbnailImageField type) that auto-generates the file path for an image based on the title, type, and country of the item the image is attached to (upload_ to = get_ image_path). Here's how: </p>
<pre><code>def get_image_path(instance, filename):
dir = 'images... | 1 | 2009-10-12T18:03:34Z | 1,556,049 | <p>You probably want to look into signals:</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/signals/" rel="nofollow">http://docs.djangoproject.com/en/dev/topics/signals/</a></p>
<p>In particular, the django.db.models.signals.pre_save signal:</p>
<p><a href="http://docs.djangoproject.com/en/dev/howto/custo... | 3 | 2009-10-12T18:09:06Z | [
"python",
"django",
"django-models"
] |
How to select an item from a list with known percentages in Python | 1,556,232 | <p>I wish to select a random word from a list where the is a known chance for each word, for example:</p>
<p>Fruit with Probability </p>
<p>Orange 0.10
Apple 0.05
Mango 0.15
etc</p>
<p>How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all t... | 1 | 2009-10-12T18:46:00Z | 1,556,285 | <p>One solution is to normalize the probabilities to integers and then repeat each element once per value (e.g. a list with 2 Oranges, 1 Apple, 3 Mangos). This is incredibly easy to do (<code>from random import choice</code>). If that is not practical, try the code <a href="http://code.activestate.com/recipes/498229/... | -1 | 2009-10-12T18:55:22Z | [
"python",
"algorithm"
] |
How to select an item from a list with known percentages in Python | 1,556,232 | <p>I wish to select a random word from a list where the is a known chance for each word, for example:</p>
<p>Fruit with Probability </p>
<p>Orange 0.10
Apple 0.05
Mango 0.15
etc</p>
<p>How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all t... | 1 | 2009-10-12T18:46:00Z | 1,556,302 | <pre><code>import random
d= {'orange': 0.10, 'mango': 0.15, 'apple': 0.05}
weightedArray = []
for k in d:
weightedArray+=[k]*int(d[k]*100)
random.choice(weightedArray)
</code></pre>
<p><strong>EDITS</strong></p>
<p>This is essentially what Brian said above.</p>
| -1 | 2009-10-12T18:59:24Z | [
"python",
"algorithm"
] |
How to select an item from a list with known percentages in Python | 1,556,232 | <p>I wish to select a random word from a list where the is a known chance for each word, for example:</p>
<p>Fruit with Probability </p>
<p>Orange 0.10
Apple 0.05
Mango 0.15
etc</p>
<p>How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all t... | 1 | 2009-10-12T18:46:00Z | 1,556,327 | <pre><code>lst = [ ('Orange', 0.10), ('Apple', 0.05), ('Mango', 0.15), ('etc', 0.69) ]
x = 0.0
lst2 = []
for fruit, chance in lst:
tup = (x, fruit)
lst2.append(tup)
x += chance
tup = (x, None)
lst2.append(tup)
import random
def pick_one(lst2):
if lst2[0][1] is None:
raise ValueError, "no val... | 1 | 2009-10-12T19:05:42Z | [
"python",
"algorithm"
] |
How to select an item from a list with known percentages in Python | 1,556,232 | <p>I wish to select a random word from a list where the is a known chance for each word, for example:</p>
<p>Fruit with Probability </p>
<p>Orange 0.10
Apple 0.05
Mango 0.15
etc</p>
<p>How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all t... | 1 | 2009-10-12T18:46:00Z | 1,556,403 | <p>You can pick items with weighted probabilities if you assign each item a number range proportional to its probability, pick a random number between zero and the sum of the ranges and find what item matches it. The following class does exactly that:</p>
<pre><code>from random import random
class WeightedChoice(obje... | 2 | 2009-10-12T19:22:28Z | [
"python",
"algorithm"
] |
How to select an item from a list with known percentages in Python | 1,556,232 | <p>I wish to select a random word from a list where the is a known chance for each word, for example:</p>
<p>Fruit with Probability </p>
<p>Orange 0.10
Apple 0.05
Mango 0.15
etc</p>
<p>How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all t... | 1 | 2009-10-12T18:46:00Z | 1,556,471 | <pre><code>lst = [ ('Orange', 0.10), ('Apple', 0.05), ('Mango', 0.15), ('etc', 0.69) ]
x = 0.0
lst2 = []
for fruit, chance in lst:
low = x
high = x + chance
tup = (low, high, fruit)
lst2.append(tup)
x += chance
if x > 1.0:
raise ValueError, "chances add up to more than 100%"
low = x
high =... | 0 | 2009-10-12T19:39:23Z | [
"python",
"algorithm"
] |
How to select an item from a list with known percentages in Python | 1,556,232 | <p>I wish to select a random word from a list where the is a known chance for each word, for example:</p>
<p>Fruit with Probability </p>
<p>Orange 0.10
Apple 0.05
Mango 0.15
etc</p>
<p>How would be the best way of implementing this? The actual list I will take from is up to 100 items longs and the % do not all t... | 1 | 2009-10-12T18:46:00Z | 1,556,481 | <p>What you want is to draw from a <a href="http://en.wikipedia.org/wiki/Multinomial%5Fdistribution" rel="nofollow">multinomial distribution</a>. Assuming you have two lists of items and probabilities, and the probabilities sum to 1 (if not, just add some default value to cover the extra):</p>
<pre><code>def choose(it... | 2 | 2009-10-12T19:43:30Z | [
"python",
"algorithm"
] |
Circular import dependency in Python | 1,556,387 | <p>Let's say I have the following directory structure:</p>
<pre><code>a\
__init__.py
b\
__init__.py
c\
__init__.py
c_file.py
d\
__init__.py
d_file.py
</code></pre>
<p>In the <code>a</code> package's <code>__init__.py</code>, the <code>c</... | 57 | 2009-10-12T19:19:30Z | 1,556,429 | <p>You may defer the import, for example in <code>a/__init__.py</code>:</p>
<pre><code>def my_function():
from a.b.c import Blah
return Blah()
</code></pre>
<p>that is, defer the import until it is really needed. However, I would also have a close look at my package definitions/uses, as a cyclic dependency li... | 128 | 2009-10-12T19:27:53Z | [
"python",
"dependencies",
"circular-dependency",
"python-import"
] |
Circular import dependency in Python | 1,556,387 | <p>Let's say I have the following directory structure:</p>
<pre><code>a\
__init__.py
b\
__init__.py
c\
__init__.py
c_file.py
d\
__init__.py
d_file.py
</code></pre>
<p>In the <code>a</code> package's <code>__init__.py</code>, the <code>c</... | 57 | 2009-10-12T19:19:30Z | 1,556,444 | <p>If a depends on c and c depends on a, aren't they actually the same unit then?</p>
<p>You should really examine why you have split a and c into two packages, because either you have some code you should split off into another package (to make them both depend on that new package, but not each other), or you should ... | 53 | 2009-10-12T19:33:28Z | [
"python",
"dependencies",
"circular-dependency",
"python-import"
] |
Circular import dependency in Python | 1,556,387 | <p>Let's say I have the following directory structure:</p>
<pre><code>a\
__init__.py
b\
__init__.py
c\
__init__.py
c_file.py
d\
__init__.py
d_file.py
</code></pre>
<p>In the <code>a</code> package's <code>__init__.py</code>, the <code>c</... | 57 | 2009-10-12T19:19:30Z | 11,521,614 | <p>Another solution is to use a proxy for the d_file.</p>
<p>For example, let's say that you want to share the blah class with the c_file. The d_file thus contains:</p>
<pre><code>class blah:
def __init__(self):
print("blah")
</code></pre>
<p>Here is what you enter in c_file.py:</p>
<pre><code># do not... | -3 | 2012-07-17T11:33:26Z | [
"python",
"dependencies",
"circular-dependency",
"python-import"
] |
Circular import dependency in Python | 1,556,387 | <p>Let's say I have the following directory structure:</p>
<pre><code>a\
__init__.py
b\
__init__.py
c\
__init__.py
c_file.py
d\
__init__.py
d_file.py
</code></pre>
<p>In the <code>a</code> package's <code>__init__.py</code>, the <code>c</... | 57 | 2009-10-12T19:19:30Z | 19,186,096 | <p>I've wondered this a couple times (usually while dealing with models that need to know about each other). The simple solution is just to import the whole module, then reference the thing that you need.</p>
<p>So instead of doing </p>
<pre><code>from models import Student
</code></pre>
<p>in one, and </p>
<pre><c... | 14 | 2013-10-04T16:18:32Z | [
"python",
"dependencies",
"circular-dependency",
"python-import"
] |
Circular import dependency in Python | 1,556,387 | <p>Let's say I have the following directory structure:</p>
<pre><code>a\
__init__.py
b\
__init__.py
c\
__init__.py
c_file.py
d\
__init__.py
d_file.py
</code></pre>
<p>In the <code>a</code> package's <code>__init__.py</code>, the <code>c</... | 57 | 2009-10-12T19:19:30Z | 32,302,200 | <p>The problem is that when running from a directory, by default only the packages that are sub directories are visible as candidate imports, so you cannot import a.b.d. You can however import b.d. since b is a sub package of a.</p>
<p>If you really want to import a.b.d in <code>c/__init__.py</code> you can accomplish... | 0 | 2015-08-30T23:33:12Z | [
"python",
"dependencies",
"circular-dependency",
"python-import"
] |
jinja2: html escape variables | 1,556,554 | <p>how do I html-escape dangerous unsanitized input in jinja2?</p>
<p>Can I do it inside the template or must it be done in python code?</p>
<p>I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2</p>
| 13 | 2009-10-12T20:00:49Z | 1,556,570 | <p>e.g.</p>
<pre><code>{{ user.username|e }}
</code></pre>
<p>Pipe it through the <code>|e</code> filter</p>
<p><a href="http://jinja.pocoo.org/2/documentation/templates#escape">Jinija: Template Designer Documentation -> Builtin Filters: Escape</a></p>
| 23 | 2009-10-12T20:03:50Z | [
"python",
"security",
"escaping",
"jinja2"
] |
jinja2: html escape variables | 1,556,554 | <p>how do I html-escape dangerous unsanitized input in jinja2?</p>
<p>Can I do it inside the template or must it be done in python code?</p>
<p>I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2</p>
| 13 | 2009-10-12T20:00:49Z | 3,820,710 | <p>You could also tell the environment to autoescape everything:</p>
<pre><code>e = Environment(loader=fileloader, autoescape=True)
</code></pre>
<p>note: in jinja1 this is auto_escape</p>
| 11 | 2010-09-29T10:25:13Z | [
"python",
"security",
"escaping",
"jinja2"
] |
jinja2: html escape variables | 1,556,554 | <p>how do I html-escape dangerous unsanitized input in jinja2?</p>
<p>Can I do it inside the template or must it be done in python code?</p>
<p>I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2</p>
| 13 | 2009-10-12T20:00:49Z | 10,063,883 | <p>If you want to escape html in your programme, you can do it like this(example):</p>
<pre><code>>>> import jinja2
>>> jinja2.__version__
'2.6'
>>> a
'<script>alert("yy")</script>'
>>> jinja2.escape(a)
Markup(u'&lt;script&gt;alert(&#34;yy&#34;)&lt;/s... | 4 | 2012-04-08T15:16:27Z | [
"python",
"security",
"escaping",
"jinja2"
] |
jinja2: html escape variables | 1,556,554 | <p>how do I html-escape dangerous unsanitized input in jinja2?</p>
<p>Can I do it inside the template or must it be done in python code?</p>
<p>I have a variable that may contain da<ngero>u&s chars. How do I escape it in jinja2</p>
| 13 | 2009-10-12T20:00:49Z | 14,468,257 | <p>Flask has a built in <code>tojson</code> filter:</p>
<p><a href="http://flask.pocoo.org/docs/templating/#standard-filters" rel="nofollow">http://flask.pocoo.org/docs/templating/#standard-filters</a></p>
| 1 | 2013-01-22T21:22:38Z | [
"python",
"security",
"escaping",
"jinja2"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,556,796 | <p>Try the CPAN distribution <a href="http://search.cpan.org/perldoc/Python" rel="nofollow">Python (pyperl)</a> for interfacing with python code.</p>
| 5 | 2009-10-12T20:40:50Z | [
"python",
"perl"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,556,811 | <p>You can spawn a child process and use an IPC mechanism like sockets or STDIO, or even embed <a href="http://search.cpan.org/~gaas/pyperl-1.0/perlmodule.pod" rel="nofollow">one interpreter</a> <a href="http://search.cpan.org/~nine/Inline-Python-0.29/Python.pod" rel="nofollow">in the other</a>.</p>
<p>But why switch ... | 6 | 2009-10-12T20:43:09Z | [
"python",
"perl"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,556,843 | <p>I'd avoid inter-language calls if possible; fragility and massive increases in dependencies await you down this road. However, there is...</p>
<p><a href="http://search.cpan.org/perldoc/Inline%3A%3APython" rel="nofollow">Inline::Python</a></p>
<p>If python must be used, the <code>Inline::*</code> series of module... | 1 | 2009-10-12T20:47:34Z | [
"python",
"perl"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,557,216 | <p>Well, if you really want to write the GUI in another language (which, seriously, is just a bad idea, since it will cost you more than it could ever benefit you), the thing you should do is the following:</p>
<ol>
<li>Document your Perl app in terms of the services it provides. You should do it with XML Schema Defin... | 2 | 2009-10-12T22:11:42Z | [
"python",
"perl"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,557,721 | <p>I'd think the major criterion for any qualified answer would involve the details of the existing codebase. How is this Perl code called and how does it return it's results?</p>
<p>A collection of command line utilities returning results through reasonably good textual output ("good" as in "amenable to further mach... | 1 | 2009-10-13T00:51:11Z | [
"python",
"perl"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,557,825 | <p>I hate to be another one in the chorus, but...</p>
<ol>
<li>Avoid the use of an alternate language</li>
<li>Use Wx so it's native look and feel makes the application look "real" to non-technical audiences.</li>
<li>Download the Padre source code and see how it does Wx Perl code, then steal rampantly from it's best ... | 7 | 2009-10-13T01:35:51Z | [
"python",
"perl"
] |
Recommendations for perl-to-python interoperation? | 1,556,668 | <p>We have a sizable code base in Perl. For the forseeable future, our codebase will remain in Perl. However, we're looking into adding a GUI-based dashboard utility. We are considering writing the dashboard in Python (using tkinter or wx). The problem, however, is that we would like to leverage our existing Perl codeb... | 1 | 2009-10-12T20:22:08Z | 1,560,979 | <p>Interesting project: I would opt for loose-coupling and consider an XML-RPC or JSON based approach.</p>
| 1 | 2009-10-13T15:28:32Z | [
"python",
"perl"
] |
Should you import all classes you use in Python? | 1,556,766 | <p>Python's lack of static typing makes it possible to use and rely on classes without importing them. Should you import them anyway? Does it matter?</p>
<h3>Example</h3>
<p><strong>someclass.py</strong></p>
<pre><code>class SomeClass:
def __init__(self, some_value):
self.some_value = some_value
</code><... | 2 | 2009-10-12T20:35:36Z | 1,556,784 | <p>Importing <code>SomeClass</code> won't make any difference to how that code works.</p>
<p>If you're worried about making the code understandable, comment the fact that <code>SomeClient</code> expects a <code>SomeClass</code> instance, and/or document it in the docstring.</p>
<p>If you want to <em>police</em> the f... | 5 | 2009-10-12T20:38:44Z | [
"python",
"coding-style"
] |
Should you import all classes you use in Python? | 1,556,766 | <p>Python's lack of static typing makes it possible to use and rely on classes without importing them. Should you import them anyway? Does it matter?</p>
<h3>Example</h3>
<p><strong>someclass.py</strong></p>
<pre><code>class SomeClass:
def __init__(self, some_value):
self.some_value = some_value
</code><... | 2 | 2009-10-12T20:35:36Z | 1,556,785 | <p>Yes, it's completely ok. <code>some_class_instance</code> might be anything, it doesn't have to be an instance of <code>SomeClass</code>. You might want to pass an instance that looks just like <code>SomeClass</code>, but uses a different implementation for testing purposes, for example.</p>
| 8 | 2009-10-12T20:38:56Z | [
"python",
"coding-style"
] |
Should you import all classes you use in Python? | 1,556,766 | <p>Python's lack of static typing makes it possible to use and rely on classes without importing them. Should you import them anyway? Does it matter?</p>
<h3>Example</h3>
<p><strong>someclass.py</strong></p>
<pre><code>class SomeClass:
def __init__(self, some_value):
self.some_value = some_value
</code><... | 2 | 2009-10-12T20:35:36Z | 1,556,817 | <p>In this case, you shouldn't import the class.</p>
<p>Python relies on what is called "<a href="http://docs.python.org/glossary.html#term-duck-typing" rel="nofollow">duck typing</a>" - if it walks like a duck and quacks like a duck, it might as well be a duck.</p>
<p>Your code doesn't care what class really gets pa... | 4 | 2009-10-12T20:44:11Z | [
"python",
"coding-style"
] |
Should you import all classes you use in Python? | 1,556,766 | <p>Python's lack of static typing makes it possible to use and rely on classes without importing them. Should you import them anyway? Does it matter?</p>
<h3>Example</h3>
<p><strong>someclass.py</strong></p>
<pre><code>class SomeClass:
def __init__(self, some_value):
self.some_value = some_value
</code><... | 2 | 2009-10-12T20:35:36Z | 1,557,002 | <p>This is a good python code, "we are all consenting adults here", maybe if you expect a class you should include a comment and that's ok.</p>
| 1 | 2009-10-12T21:16:22Z | [
"python",
"coding-style"
] |
non-blocking read/log from an http stream | 1,557,175 | <p>I have a client that connects to an HTTP stream and logs the text data it consumes. </p>
<p>I send the streaming server an HTTP GET request... The server replies and continuously publishes data... It will either publish text or send a ping (text) message regularly... and will never close the connection.</p>
<p>... | 6 | 2009-10-12T21:59:39Z | 1,557,259 | <p>Hey, that's three questions in one! ;-)</p>
<p>It could block sometimes - even if your server is generating data quite quickly, network bottlenecks could in theory cause your reads to block.</p>
<p>Reading the URL data using "for dat in req" will mean reading a line at a time - not really useful if you're reading ... | 6 | 2009-10-12T22:19:36Z | [
"python",
"http",
"logging",
"urllib2"
] |
non-blocking read/log from an http stream | 1,557,175 | <p>I have a client that connects to an HTTP stream and logs the text data it consumes. </p>
<p>I send the streaming server an HTTP GET request... The server replies and continuously publishes data... It will either publish text or send a ping (text) message regularly... and will never close the connection.</p>
<p>... | 6 | 2009-10-12T21:59:39Z | 1,557,380 | <p>Yes when you catch up with the server it will block until the server produces more data</p>
<p>Each dat will be one line including the newline on the end</p>
<p>twisted is a good option</p>
<p>I would swap the with and for around in your example, do you really want to open and close the file for every line that a... | 1 | 2009-10-12T22:52:05Z | [
"python",
"http",
"logging",
"urllib2"
] |
non-blocking read/log from an http stream | 1,557,175 | <p>I have a client that connects to an HTTP stream and logs the text data it consumes. </p>
<p>I send the streaming server an HTTP GET request... The server replies and continuously publishes data... It will either publish text or send a ping (text) message regularly... and will never close the connection.</p>
<p>... | 6 | 2009-10-12T21:59:39Z | 1,558,074 | <p>You're using too high-level an interface to have good control about such issues as blocking and buffering block sizes. If you're not willing to go all the way to an async interface (in which case <a href="http://twistedmatrix.com/trac/" rel="nofollow">twisted</a>, already suggested, is hard to beat!), why not <a hr... | 3 | 2009-10-13T03:34:29Z | [
"python",
"http",
"logging",
"urllib2"
] |
non-blocking read/log from an http stream | 1,557,175 | <p>I have a client that connects to an HTTP stream and logs the text data it consumes. </p>
<p>I send the streaming server an HTTP GET request... The server replies and continuously publishes data... It will either publish text or send a ping (text) message regularly... and will never close the connection.</p>
<p>... | 6 | 2009-10-12T21:59:39Z | 1,564,523 | <p>Another option is to use the <code>socket</code> module directly. Establish a connection, send the HTTP request, set the socket to non-blocking mode, and then read the data with <code>socket.recv()</code> handling 'Resource temporarily unavailable' exceptions (which means that there is nothing to read). A very rough... | 3 | 2009-10-14T06:13:33Z | [
"python",
"http",
"logging",
"urllib2"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 1,557,577 | <p>In Linux or UNIX:</p>
<pre><code>time python yourprogram.py
</code></pre>
<p>In Windows, see this Stackoverflow discussion: <a href="http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of-command-in-windows-command-line">http://stackoverflow.com/questions/673523/how-to-measure-execution-time-of... | 66 | 2009-10-12T23:59:18Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 1,557,584 | <p>The simplest way in python:</p>
<pre><code>import time
start_time = time.time()
main()
print("--- %s seconds ---" % (time.time() - start_time))
</code></pre>
<p>This assumes that your program takes at least a tenth of second to run.</p>
<p>Prints:</p>
<pre><code>--- 0.764891862869 seconds ---
</code></pre>
| 514 | 2009-10-13T00:00:53Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 1,557,605 | <p>The solution of rogeriopvl works fine, but if you want more specific info you can use the python built-in profiler. Check this page:</p>
<p><a href="http://docs.python.org/library/profile.html">http://docs.python.org/library/profile.html</a></p>
<p>a profiler tells you a lot of useful information like the time spe... | 10 | 2009-10-13T00:07:58Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 1,557,805 | <pre><code>import time
start_time = time.clock()
main()
print time.clock() - start_time, "seconds"
</code></pre>
<p><code>time.clock()</code> returns the processor time, which allows us to calculate only the time used by this process (on Unix anyway). The documentation says "in any case, this is the function to use f... | 28 | 2009-10-13T01:25:01Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 1,557,906 | <p>I put this <code>timing.py</code> module into my own <code>site-packages</code> directory, and just insert <code>import timing</code> at the top of my module:</p>
<pre><code>import atexit
from time import clock
def secondsToStr(t):
return "%d:%02d:%02d.%03d" % \
reduce(lambda ll,b : divmod(ll[0],b) + l... | 113 | 2009-10-13T02:08:22Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 1,558,436 | <p>Even better for Linux: <code>/usr/bin/time</code></p>
<pre><code>$ /usr/bin/time -v python rhtest2.py
Command being timed: "python rhtest2.py"
User time (seconds): 4.13
System time (seconds): 0.07
Percent of CPU this job got: 91%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:04.58
Average ... | 17 | 2009-10-13T06:10:50Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 12,344,609 | <p>I really like Paul McGuire's answer, but I use Python3. So for those who are interested: here's a modification of his answer that works with Python 3 on *nix (I imagine, under Windows, that clock() should be used instead of time()):</p>
<pre><code>#python3
import atexit
from time import time
from datetime import ti... | 18 | 2012-09-10T02:03:40Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 20,874,769 | <p>You can use the python profiler cProfile to measure <a href="http://en.wikipedia.org/wiki/CPU_time">CPU time</a> and additionally how much time is spent inside each function and how many times each function is called. This is very useful if you want to improve performance of your script without knowing where to star... | 23 | 2014-01-02T00:35:57Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 26,099,345 | <p>I like the output the <code>datetime</code> module provides, where time delta objects show days, hours, minutes etc. as necessary in a human-readable way.</p>
<p>For example:</p>
<pre><code>from datetime import datetime
start_time = datetime.now()
# do your work here
end_time = datetime.now()
print('Duration: {}'.... | 16 | 2014-09-29T11:55:08Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 26,468,682 | <p>There is a <code>timeit</code> module which can be used to time the execution times of python codes.
It has detailed documentation and examples in python docs (<a href="https://docs.python.org/2/library/timeit.html" rel="nofollow">https://docs.python.org/2/library/timeit.html</a>)</p>
| 3 | 2014-10-20T14:55:51Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 28,218,696 | <p>I like Paul McGuire's answer too and came up with a context manager form which suited more my needs.</p>
<pre><code>import datetime as dt
import timeit
class TimingManager(object):
"""Context Manager used with the statement 'with' to time some execution.
Example:
with TimingManager() as t:
# C... | 3 | 2015-01-29T15:42:24Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 28,827,752 | <blockquote>
<p>I've looked at the timeit module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
</blockquote>
<pre><code>$ python -mtimeit -n1 -r1 -t -s "from your_module import main" "main()"
</code></pre>
<p>It runs <code>your_module.main()</code> function one time and p... | 5 | 2015-03-03T09:04:52Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 29,503,779 | <p>This is Paul McGuire's answer that works for me. Just in case someone was having trouble running that one. </p>
<pre><code>import atexit
from time import clock
def reduce(function, iterable, initializer=None):
it = iter(iterable)
if initializer is None:
value = next(it)
else:
value = in... | 1 | 2015-04-08T00:24:28Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 30,352,928 | <p>Ipython "timeit" any script: </p>
<pre><code>def foo():
%run bar.py
timeit foo()
</code></pre>
| 4 | 2015-05-20T14:40:36Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 36,444,633 | <pre><code>from time import time
start_time = time()
...
end_time = time()
time_taken = end_time - start_time # time_taken is in seconds
hours, rest = divmod(time_taken,3600)
minutes, seconds = divmod(rest, 60)
</code></pre>
| 6 | 2016-04-06T07:45:50Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 37,289,957 | <p><strong>time.clock()</strong></p>
<blockquote>
<p>Deprecated since version 3.3: The behavior of this function depends
on the platform: use <strong><em>perf_counter()</em></strong> or <strong><em>process_time()</em></strong> instead,
depending on your requirements, to have a well-defined behavior.</p>
</blockq... | 2 | 2016-05-18T03:49:41Z | [
"python",
"time"
] |
How to get time of a python program execution? | 1,557,571 | <p>I have a command line program in Python that takes a while to finish. I want to know the exact time it takes to finish running.</p>
<p>I've looked at the <code>timeit</code> module, but it seems it's only for small snippets of code. I want to time the whole program.</p>
| 292 | 2009-10-12T23:56:47Z | 38,154,549 | <p>The following snippet prints elapsed time in nice human readable <code><HH:MM:SS></code> format.</p>
<pre><code>import time
from datetime import timedelta
start_time = time.time()
#
# Perform lots of computations.
#
elapsed_time_secs = time.time() - start_time
print "Execution took: %s secs (Wall clock ti... | 1 | 2016-07-01T22:24:32Z | [
"python",
"time"
] |
PIL vs Python-GD for crop and resize | 1,557,625 | <p>I am creating custom images that I later convert to an image pyramid for Seadragon AJAX. The images and image pyramid are created using PIL. It currently take a few hours to generate the images and image pyramid for approximately 100 pictures that have a combined width and height of about 32,000,000 by 1000 (yes, ... | 2 | 2009-10-13T00:13:21Z | 1,557,796 | <p>PIL is mostly in C.</p>
<p>Antialiasing is slow. When you turn off antialiasing, what happens to the speed?</p>
| 1 | 2009-10-13T01:22:18Z | [
"python",
"ajax",
"gd",
"python-imaging-library",
"seadragon"
] |
PIL vs Python-GD for crop and resize | 1,557,625 | <p>I am creating custom images that I later convert to an image pyramid for Seadragon AJAX. The images and image pyramid are created using PIL. It currently take a few hours to generate the images and image pyramid for approximately 100 pictures that have a combined width and height of about 32,000,000 by 1000 (yes, ... | 2 | 2009-10-13T00:13:21Z | 28,585,418 | <p>VIPS includes a <a href="http://libvips.blogspot.co.uk/2013/03/making-deepzoom-zoomify-and-google-maps.html" rel="nofollow">fast deepzoom creator</a>. I timed <code>deepzoom.py</code> and on my machine I see:</p>
<pre><code>$ time ./wtc.py
real 0m29.601s
user 0m29.158s
sys 0m0.408s
peak RES 450mb
</code>... | 0 | 2015-02-18T13:57:01Z | [
"python",
"ajax",
"gd",
"python-imaging-library",
"seadragon"
] |
How to make complex contains queries in Django? | 1,557,850 | <p>I need to make query like this: </p>
<blockquote>
<p>WHERE Comment like '%ev% 3628%' or Comment like '%ew% 3628%'</p>
</blockquote>
<p>the number '3628' is a parametr. So I've tried in my view: </p>
<p><strong>First try:</strong> </p>
<pre><code>wherestr = "Comment like '%%ev%% %s%%' or Comment like '%%ew%%... | 1 | 2009-10-13T01:43:28Z | 1,557,872 | <p>You need something similar to this:</p>
<pre><code>from django.db.models import Q
def myview(request):
query = "hi" #string to search for
items = self.filter(Q(comment__contains=query) | Q(comment__contains=query))
...
</code></pre>
<p>Just make sure the query string is properly escaped.</p>
| 1 | 2009-10-13T01:52:20Z | [
"python",
"django"
] |
How to make complex contains queries in Django? | 1,557,850 | <p>I need to make query like this: </p>
<blockquote>
<p>WHERE Comment like '%ev% 3628%' or Comment like '%ew% 3628%'</p>
</blockquote>
<p>the number '3628' is a parametr. So I've tried in my view: </p>
<p><strong>First try:</strong> </p>
<pre><code>wherestr = "Comment like '%%ev%% %s%%' or Comment like '%%ew%%... | 1 | 2009-10-13T01:43:28Z | 1,557,873 | <p>Take a look at <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/models/querysets/</a>, specifically</p>
<p>icontains: Case-insensitive containment test.</p>
<p>Example: Entry.objects.get(headline__icontains='Lennon')</p>
<p>SQL equivalent... | 0 | 2009-10-13T01:52:43Z | [
"python",
"django"
] |
How to make complex contains queries in Django? | 1,557,850 | <p>I need to make query like this: </p>
<blockquote>
<p>WHERE Comment like '%ev% 3628%' or Comment like '%ew% 3628%'</p>
</blockquote>
<p>the number '3628' is a parametr. So I've tried in my view: </p>
<p><strong>First try:</strong> </p>
<pre><code>wherestr = "Comment like '%%ev%% %s%%' or Comment like '%%ew%%... | 1 | 2009-10-13T01:43:28Z | 1,562,711 | <p>You almost got it right... The problem is that your % are being subsituted twice. <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none" rel="nofollow">Django actually has a way of passing parameters in the extra cl... | 0 | 2009-10-13T20:24:55Z | [
"python",
"django"
] |
PyQt: Displaying QTextEdits over the window | 1,557,864 | <p>I want to display some QTextEdits over my main window at arbitrary locations. Below is my first attempt. It doesn't quite work. If I create the text edits before I show the window, the text edits appear, but if I create them after I have shown the window they don't appear. What's up with that? How can I get the... | 1 | 2009-10-13T01:49:50Z | 1,557,946 | <p>Oh, I got it. You have to call show on each widget before it appears. I guess QMainWindow.show recursively calls the method for all of its children. So just add text.show() to the end of the new_text function and it works.</p>
| 1 | 2009-10-13T02:32:08Z | [
"python",
"qt",
"qt4",
"pyqt",
"pyqt4"
] |
Getting multiple properties at the same time in Appscript | 1,557,910 | <p>I am using <a href="http://appscript.sourceforge.net/" rel="nofollow">Appscript</a> - a Python interface to AppleScript - in a project of mine that basically gets data from <a href="http://culturedcode.com/things/" rel="nofollow">a Mac application</a>.</p>
<p>Here is a sample code:</p>
<pre><code> asobj = app('... | 1 | 2009-10-13T02:09:27Z | 1,558,045 | <p>I'm not 100% sure how this would be expressed in Python, but most Applescript objects support a "properties" property which will return a dictionary containing key/value pairs for each of the supported properties of that object. I'm guessing that calling <code>asobj.properties()</code> would return an appropriate d... | 3 | 2009-10-13T03:16:28Z | [
"python",
"osx",
"applescript",
"appscript"
] |
Getting multiple properties at the same time in Appscript | 1,557,910 | <p>I am using <a href="http://appscript.sourceforge.net/" rel="nofollow">Appscript</a> - a Python interface to AppleScript - in a project of mine that basically gets data from <a href="http://culturedcode.com/things/" rel="nofollow">a Mac application</a>.</p>
<p>Here is a sample code:</p>
<pre><code> asobj = app('... | 1 | 2009-10-13T02:09:27Z | 1,565,728 | <p>If you have a large number of elements, it will be quicker to grab your properties like this:</p>
<pre><code>ref = app('Things').to_dos
ids = ref.id()
names = ref.name()
statuses = ref.status()
</code></pre>
<p>and then use Python's zip() function to rearrange them as needed. The appscript documentation has a chap... | 0 | 2009-10-14T11:35:29Z | [
"python",
"osx",
"applescript",
"appscript"
] |
Install custom modules in a python virtual enviroment | 1,557,972 | <p>I am doing some pylons work in a virtual python enviorment, I want to use MySQL with SQLalchemy but I can't install the MySQLdb module on my virtual enviorment, I can't use easyinstall because I am using a version that was compiled for python 2.6 in a .exe format, I tried running the install from inside the virtual... | 0 | 2009-10-13T02:43:26Z | 1,563,869 | <p>Ok Got it all figured out, After I installed the module on my normal python 2.6 install I went into my Python26 folder and low and behold I happened to find a file called MySQL-python-wininst which happened to be a list of all of the installed module files. Basicly it was two folders called MySQLdb and another calle... | 0 | 2009-10-14T01:49:43Z | [
"python",
"mysql",
"pylons",
"module",
"virtualenv"
] |
relevant query to what is the best python method for encryption | 1,558,287 | <p>I tried to use the gnupg.py module encryption decryption function named<br>
" def test_encryption_and_decryption(self): "</p>
<p>Could i use this function by passing the key or fingerprint retrieved from public key server.</p>
<p>I am getting the key by this :</p>
<pre><code>retk = urllib.urlopen('http://pool.... | 1 | 2009-10-13T05:09:01Z | 1,558,417 | <p>Before you can encrypt with a key whose keyid you have, you need to import the key into the keyring. Use the <code>import_keys</code> function for that.</p>
<p><strong>Edit</strong>: that you cannot encrypt even after importing the key is because GPG does not trust it. This becomes apparent when you turn on verbose... | 2 | 2009-10-13T06:01:07Z | [
"python",
"encryption"
] |
How can I distribute python programs? | 1,558,385 | <p>My application looks like this:</p>
<pre>
main.py
windows/
__init__.py
mainwindow.py
...
model/
__init__.py
orders.py
...
resources/
image1.png
logo.jpg
...
</pre>
<p>The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking... | 61 | 2009-10-13T05:48:20Z | 1,558,404 | <p>The normal way of distributing Python applications is with <a href="http://docs.python.org/distutils/index.html">distutils</a>. It's made both for distributing library type python modules, and python applications, although I don't know how it works on Windows. You would on Windows have to install Python separately i... | 22 | 2009-10-13T05:54:46Z | [
"python",
"distribution"
] |
How can I distribute python programs? | 1,558,385 | <p>My application looks like this:</p>
<pre>
main.py
windows/
__init__.py
mainwindow.py
...
model/
__init__.py
orders.py
...
resources/
image1.png
logo.jpg
...
</pre>
<p>The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking... | 61 | 2009-10-13T05:48:20Z | 1,558,439 | <p>If you are distributing on windows, use an <a href="http://www.installshield.com" rel="nofollow">installer</a> to install all the relevant files/interpeter whatever is needed. Distribute a setup.exe. That is the best way on windows. Otherwise users will complain.</p>
| 1 | 2009-10-13T06:11:21Z | [
"python",
"distribution"
] |
How can I distribute python programs? | 1,558,385 | <p>My application looks like this:</p>
<pre>
main.py
windows/
__init__.py
mainwindow.py
...
model/
__init__.py
orders.py
...
resources/
image1.png
logo.jpg
...
</pre>
<p>The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking... | 61 | 2009-10-13T05:48:20Z | 1,558,488 | <p>I highly recommend <a href="http://www.pyinstaller.org/">Pyinstaller</a>, which supports all major platforms pretty seamlessly. Like py2exe and py2app, it produces a standard executable on Windows and an app bundle on OS X, but has the benefit of also doing a fantastic job of auto-resolving common dependencies and ... | 40 | 2009-10-13T06:31:20Z | [
"python",
"distribution"
] |
How can I distribute python programs? | 1,558,385 | <p>My application looks like this:</p>
<pre>
main.py
windows/
__init__.py
mainwindow.py
...
model/
__init__.py
orders.py
...
resources/
image1.png
logo.jpg
...
</pre>
<p>The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking... | 61 | 2009-10-13T05:48:20Z | 1,558,580 | <p>Fredrik Lundh's <a href="http://effbot.org/zone/squeeze.htm" rel="nofollow"><code>squeeze.py</code></a> can create a single file that does not contain the Python interpreter, but instead contains bytecode. With the right arguments, you can include other files, modules, etc. in the result file. I used it successful... | 4 | 2009-10-13T07:02:05Z | [
"python",
"distribution"
] |
How can I distribute python programs? | 1,558,385 | <p>My application looks like this:</p>
<pre>
main.py
windows/
__init__.py
mainwindow.py
...
model/
__init__.py
orders.py
...
resources/
image1.png
logo.jpg
...
</pre>
<p>The program is started with main.py. Is there a good way to create a 'final' application out of it? I'm thinking... | 61 | 2009-10-13T05:48:20Z | 16,782,573 | <p>I may be mistaken, but doesn't IronPython have a built in compiler for windows?</p>
<p><a href="http://www.ironpython.net" rel="nofollow">http://www.ironpython.net</a></p>
<p>[EDIT]</p>
<p>Try out Cx_Freeze, By far the best .py to .exe (plus a few .dlls) compiler I've ever used.</p>
<p><a href="http://cx-freeze.... | 1 | 2013-05-28T01:29:48Z | [
"python",
"distribution"
] |
how do I get only the time in models | 1,558,896 | <p>How do I format datetime to give me only the time in my model</p>
| 2 | 2009-10-13T08:28:41Z | 1,558,940 | <p>If you've got a <code>datetime</code> object in your template called <code>foo</code>, use:</p>
<pre><code>{{ foo|time:"H:i" }}
</code></pre>
<p>Look at the <code>time</code> filter <a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#time" rel="nofollow">documentation</a>. You're not limited to <... | 7 | 2009-10-13T08:37:56Z | [
"python",
"django"
] |
Convert from hex string to unicode | 1,559,065 | <p>How can i convert the <code>'dead'</code> string to an unicode string <code>u'\xde\xad'</code>?</p>
<p>Doing this:</p>
<pre><code>from binascii import unhexlify
out = ''.join(x for x in [unhexlify('de'), unhexlify('ad')])
</code></pre>
<p>creates a <code><type 'str'></code> string <code>'\xde\xad'</code></p... | 2 | 2009-10-13T09:09:16Z | 1,559,094 | <p>See <a href="http://www.amk.ca/python/howto/unicode" rel="nofollow">this Python unicode how-to</a>, and use something akin to:</p>
<pre><code>unicode('\x80abc', errors='replace')
</code></pre>
<p>or</p>
<pre><code>unicode('\x80abc', errors='ignore')
</code></pre>
| 1 | 2009-10-13T09:17:59Z | [
"python",
"unicode",
"utf-8",
"encode",
"decode"
] |
Convert from hex string to unicode | 1,559,065 | <p>How can i convert the <code>'dead'</code> string to an unicode string <code>u'\xde\xad'</code>?</p>
<p>Doing this:</p>
<pre><code>from binascii import unhexlify
out = ''.join(x for x in [unhexlify('de'), unhexlify('ad')])
</code></pre>
<p>creates a <code><type 'str'></code> string <code>'\xde\xad'</code></p... | 2 | 2009-10-13T09:09:16Z | 1,559,100 | <p>Unicode is designed to be compatible with Latin-1, you can use that and simply decode the bytestring:</p>
<pre><code>In [2]: unhexlify('dead').decode('latin1')
Out[2]: u'\xde\xad'
</code></pre>
| 5 | 2009-10-13T09:18:49Z | [
"python",
"unicode",
"utf-8",
"encode",
"decode"
] |
How do i use perspective projection in this library | 1,559,083 | <p>i found a library called <a href="http://code.google.com/p/pyeuclid/" rel="nofollow">pyeuclid</a> and it <a href="http://partiallydisassembled.net/euclid/index.html" rel="nofollow">seems to do what i want</a> in respect to 3D math.
it contins a 3D vector class and a 4X4 matrix class capable of transformations like ... | 0 | 2009-10-13T09:14:37Z | 1,559,108 | <p><a href="http://gpwiki.org/index.php/OpenGL%5FTutorial%5FFramework%3AFirst%5FPolygon" rel="nofollow">This tutorial</a> explains the arguments to <a href="http://www.opengl.org/documentation/specs/man%5Fpages/hardcopy/GL/html/glu/perspective.html" rel="nofollow">gluPerspective()</a>, and should transfer over since yo... | 0 | 2009-10-13T09:21:06Z | [
"python",
"3d",
"vector",
"matrix",
"projection"
] |
How do i use perspective projection in this library | 1,559,083 | <p>i found a library called <a href="http://code.google.com/p/pyeuclid/" rel="nofollow">pyeuclid</a> and it <a href="http://partiallydisassembled.net/euclid/index.html" rel="nofollow">seems to do what i want</a> in respect to 3D math.
it contins a 3D vector class and a 4X4 matrix class capable of transformations like ... | 0 | 2009-10-13T09:14:37Z | 1,582,064 | <p>I don't know if this is relevant as you may already know this but you'll need a view matrix too. The view matrix represents the inverse of the transform of your camera in the world. You may find the matrix class also has helper methods for creating view matrices, sometimes called lookAt os similar. Alternatively jus... | 0 | 2009-10-17T12:06:05Z | [
"python",
"3d",
"vector",
"matrix",
"projection"
] |
String arguments in python multiprocessing | 1,559,125 | <p>I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters.</p>
<p>This is the code:</p>
<pre><code>import multiprocessing
def write(s):
print s
write('hello')
p = multiprocessing.Process(target=write, arg... | 14 | 2009-10-13T09:27:27Z | 1,559,143 | <p>You have to pass</p>
<pre><code>p = multiprocessing.Process(target=write, args=('hello',))
</code></pre>
<p>Notice the comma! Otherwise it is interpreted as a simple string and not as a 1 element tuple.</p>
| 1 | 2009-10-13T09:32:23Z | [
"python",
"string",
"multiprocessing",
"arguments"
] |
String arguments in python multiprocessing | 1,559,125 | <p>I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters.</p>
<p>This is the code:</p>
<pre><code>import multiprocessing
def write(s):
print s
write('hello')
p = multiprocessing.Process(target=write, arg... | 14 | 2009-10-13T09:27:27Z | 1,559,147 | <p>Change <code>args=('hello')</code> to <code>args=('hello',)</code> or even better <code>args=['hello']</code>. Otherwise parentheses don't form a sequence.</p>
| 5 | 2009-10-13T09:32:46Z | [
"python",
"string",
"multiprocessing",
"arguments"
] |
String arguments in python multiprocessing | 1,559,125 | <p>I'm trying to pass a string argument to a target function in a process. Somehow, the string is interpreted as a list of as many arguments as there are characters.</p>
<p>This is the code:</p>
<pre><code>import multiprocessing
def write(s):
print s
write('hello')
p = multiprocessing.Process(target=write, arg... | 14 | 2009-10-13T09:27:27Z | 1,559,149 | <p>This is a common gotcha in Python - if you want to have a tuple with only one element, you need to specify that it's actually a tuple (and not just something with brackets around it) - this is done by adding a comma after the element.</p>
<p>To fix this, just put a comma after the string, inside the brackets:</p>
... | 37 | 2009-10-13T09:33:44Z | [
"python",
"string",
"multiprocessing",
"arguments"
] |
Which is the most pythonic: installing python modules via a package manager ( macports, apt) or via pip/easy_install/setuptools | 1,559,372 | <p>Usually I tend to install things via the package manager, for unixy stuff. However, when I programmed a lot of perl, I would use CPAN, newer versions and all that.</p>
<p>In general, I used to install system stuff via package manager, and language stuff via it's own package manager ( gem/easy_install|pip/cpan)</p>... | 11 | 2009-10-13T10:25:31Z | 1,559,436 | <p>The system python version and its libraries are often used by software in the distribution. As long as the software you are using are happy with the same versions of python and all the libraries as your distribution is, than using the distribution packages will work just fine.</p>
<p>However, quite often you need d... | 17 | 2009-10-13T10:41:50Z | [
"python",
"setuptools",
"distutils",
"pip"
] |
Which is the most pythonic: installing python modules via a package manager ( macports, apt) or via pip/easy_install/setuptools | 1,559,372 | <p>Usually I tend to install things via the package manager, for unixy stuff. However, when I programmed a lot of perl, I would use CPAN, newer versions and all that.</p>
<p>In general, I used to install system stuff via package manager, and language stuff via it's own package manager ( gem/easy_install|pip/cpan)</p>... | 11 | 2009-10-13T10:25:31Z | 1,559,521 | <p>There are two completely opposing camps: one in favor of system-provided packages, and one in favor of separate installation. I'm personally in the "system packages" camp. I'll provide arguments from each side below.</p>
<p>Pro system packages: system packager already cares about dependency, and compliance with ove... | 17 | 2009-10-13T10:57:17Z | [
"python",
"setuptools",
"distutils",
"pip"
] |
Regular Expression for HTML artifacts | 1,559,375 | <p>I some text with HTML artifacts where the <code><</code> and <code>></code> of tags got dropped, so now I need something that will match a small <code>p</code> followed by a capital letter, like</p>
<pre><code>pThe next day they....
</code></pre>
<p>And I also need something that will catch the trailing <cod... | 0 | 2009-10-13T10:26:13Z | 1,559,411 | <p>Try this:</p>
<pre><code>re.sub(r"(/?p)(?=[A-Z]|$)", r"<\1>", str)
</code></pre>
<p>You might want to extend the boundary assertion (here <code>(?=[A-Z]|$)</code>) with additional characters like whitespace.</p>
| 1 | 2009-10-13T10:35:09Z | [
"python",
"html",
"regex"
] |
Regular Expression for HTML artifacts | 1,559,375 | <p>I some text with HTML artifacts where the <code><</code> and <code>></code> of tags got dropped, so now I need something that will match a small <code>p</code> followed by a capital letter, like</p>
<pre><code>pThe next day they....
</code></pre>
<p>And I also need something that will catch the trailing <cod... | 0 | 2009-10-13T10:26:13Z | 1,559,426 | <p>I got is. You use backreferences,</p>
<pre><code>import re
smallBig = re.compile(r'[a-z]([A-Z])')
...
cleanedString = smallBig.sub(r'\1', dirtyString)
</code></pre>
<p>This removes the small letter but keeps the capital letter in cases where the '<' and '>' of html tags were stripped and you sit with text like... | 1 | 2009-10-13T10:38:16Z | [
"python",
"html",
"regex"
] |
coverage.py: exclude files | 1,559,424 | <p>How do I exclude entire files from <a href="http://nedbatchelder.com/code/coverage/">coverage.py</a> reports?</p>
<p>According to the documentation you can exclude code by matching lines. I want to exclude entire files, so that the reports don't include 3rd party libraries. Am I missing something? Can it be done?</... | 24 | 2009-10-13T10:38:04Z | 1,559,639 | <p>You can omit modules with the --omit flag. It takes a comma-separated list of path prefixes. So for example:</p>
<pre><code>coverage run my_program.py
coverage report --omit=path/to/3rdparty
</code></pre>
| 34 | 2009-10-13T11:28:08Z | [
"python",
"testing",
"software-quality",
"code-coverage",
"coverage.py"
] |
coverage.py: exclude files | 1,559,424 | <p>How do I exclude entire files from <a href="http://nedbatchelder.com/code/coverage/">coverage.py</a> reports?</p>
<p>According to the documentation you can exclude code by matching lines. I want to exclude entire files, so that the reports don't include 3rd party libraries. Am I missing something? Can it be done?</... | 24 | 2009-10-13T10:38:04Z | 19,678,723 | <p>Omitting some files worked for me using coverage API.
Well it is the same kind what Ned suggested.</p>
<p>Here it is how I did it:</p>
<p><code>cov = coverage.coverage(omit='/usr/lib/python2.6/site-packages/*')</code></p>
| 9 | 2013-10-30T09:42:18Z | [
"python",
"testing",
"software-quality",
"code-coverage",
"coverage.py"
] |
How to send a dictionary to a function that accepts **kwargs? | 1,559,638 | <p>I have a function that accepts wildcard keyword parameters:</p>
<pre><code>def func(**kargs):
doA
doB
</code></pre>
<p>How do I send it a dictionary?</p>
| 18 | 2009-10-13T11:28:05Z | 1,559,646 | <p><code>func(**mydict)</code></p>
<p>this will mean kwargs=mydict inside the function</p>
<p>all the keys of mydict must be strings</p>
| 4 | 2009-10-13T11:30:24Z | [
"python"
] |
How to send a dictionary to a function that accepts **kwargs? | 1,559,638 | <p>I have a function that accepts wildcard keyword parameters:</p>
<pre><code>def func(**kargs):
doA
doB
</code></pre>
<p>How do I send it a dictionary?</p>
| 18 | 2009-10-13T11:28:05Z | 1,559,652 | <p>Just use <code>func(**some_dict)</code> to call it.</p>
<p>This is documented on <a href="http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists">section 4.7.4 of python tutorial</a>.</p>
<p>Note that the <em>same</em> <code>dict</code> is <strong>not</strong> passed into the function. A new cop... | 35 | 2009-10-13T11:31:36Z | [
"python"
] |
How to send a dictionary to a function that accepts **kwargs? | 1,559,638 | <p>I have a function that accepts wildcard keyword parameters:</p>
<pre><code>def func(**kargs):
doA
doB
</code></pre>
<p>How do I send it a dictionary?</p>
| 18 | 2009-10-13T11:28:05Z | 1,559,861 | <p>It's not 100% clear by your question, but if you'd like to pass a <code>dict</code> in through <code>kwargs</code>, you just make that dict a part of another dict, like so:</p>
<pre><code>my_dict = {} #the dict you want to pass to func
kwargs = {'my_dict': my_dict } #the keyword argument c... | 4 | 2009-10-13T12:18:54Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.