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 list |
|---|---|---|---|---|---|---|---|---|---|
Performance Advantages to Iterators? | 628,903 | <p>What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. </p>
| 14 | 2009-03-10T04:05:59Z | 628,978 | <p>An iterator is simply an object that provides methods to allow traversing through a collection. You could traverse all of the elements of an array or all the nodes of a tree with the same interface. Trees and arrays are very different data structures and require different methods to traverse .. but with an iterator... | 1 | 2009-03-10T05:00:04Z | [
"python",
"performance",
"iterator"
] |
Performance Advantages to Iterators? | 628,903 | <p>What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. </p>
| 14 | 2009-03-10T04:05:59Z | 628,979 | <p>The primary benefit of iterators is not one of performance. In my experience the most performant solution is creating an algorithm which embeds your data structure of choice. The benefit of iterators is that they allow you to decouple data and algorithm and, therefore, generalize and reuse both. If this can also be ... | 4 | 2009-03-10T05:00:05Z | [
"python",
"performance",
"iterator"
] |
Performance Advantages to Iterators? | 628,903 | <p>What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. </p>
| 14 | 2009-03-10T04:05:59Z | 629,169 | <p>For Python, generators will be faster and have better memory efficiency. Just think of an example of <code>range(1000)</code> <strong>vs</strong> <code>xrange(1000)</code> (This has been changed in 3.0, range is now an generator). With Range you pre-build your list but XRange just has a generator object and yield... | 13 | 2009-03-10T07:07:24Z | [
"python",
"performance",
"iterator"
] |
Performance Advantages to Iterators? | 628,903 | <p>What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. </p>
| 14 | 2009-03-10T04:05:59Z | 631,619 | <p>There's actually a very good mail on the python mailing list about this: <a href="http://markmail.org/message/t2a6tp33n5lddzvy">Iterators vs Lists</a>. It's a bit dated (from 2003), but as far as I know, it's still valid.</p>
<p>Here's the summary:</p>
<blockquote>
<p>For small datasets, iterator and list base... | 15 | 2009-03-10T18:16:59Z | [
"python",
"performance",
"iterator"
] |
Performance Advantages to Iterators? | 628,903 | <p>What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. </p>
| 14 | 2009-03-10T04:05:59Z | 631,909 | <p>To backup the <a href="http://stackoverflow.com/questions/628903/performance-advantages-to-iterators/629169#629169">@Christian Witts's answer</a>: </p>
<h3><code>range</code> vs. <code>xrange</code> performance</h3>
<pre><code>python25 -mtimeit "for i in xrange(1000): pass"
10000 loops, best of 3: 56.3 usec per lo... | 3 | 2009-03-10T19:31:53Z | [
"python",
"performance",
"iterator"
] |
Performance Advantages to Iterators? | 628,903 | <p>What (if any) performance advantages are offered by using iterators. It seems like the 'Right Way' to solve many problems, but does it create faster/more memory-conscious code? I'm thinking specifically in Python, but don't restrict answers to just that. </p>
| 14 | 2009-03-10T04:05:59Z | 734,050 | <p>My inference from many answers above is "Use list to code. If necessary, re-factor using iterators" The difference is not apparent unless you have a large dataset.</p>
<p>Another thing to note is that, even when using lists often, the dataset we are operating upon is progressively smaller and smaller. </p>
| 2 | 2009-04-09T12:45:50Z | [
"python",
"performance",
"iterator"
] |
Privilege Escalation in Web Environment for File Access | 628,956 | <p>I have a situation where I would like to elevate the permissions I have in a web environment so that I can access a serial device. </p>
<p>The specific case is where I have a web interface for configuring a modem that comes up on <code>/dev/ttyUSB[0-9]</code>. </p>
<p>Zero or more modems will be plugged in by an e... | 1 | 2009-03-10T04:42:25Z | 629,034 | <p>The sudo idea could be possible. IIRC, you can set specific commands to be sudo-able, but without requiring a password.</p>
<p>The other option is to put <code>nobody</code> in a group that has access to the device you want, or to start Apache as the group that does have access.</p>
<p>If you're using fastcgi (or... | -1 | 2009-03-10T05:34:16Z | [
"python",
"linux",
"permissions",
"serial-port",
"cgi"
] |
Privilege Escalation in Web Environment for File Access | 628,956 | <p>I have a situation where I would like to elevate the permissions I have in a web environment so that I can access a serial device. </p>
<p>The specific case is where I have a web interface for configuring a modem that comes up on <code>/dev/ttyUSB[0-9]</code>. </p>
<p>Zero or more modems will be plugged in by an e... | 1 | 2009-03-10T04:42:25Z | 629,256 | <p>In this case, I would write a daemon run by a system user that accepted socket connections and relayed them to the appropriate device, then use sockets within the web application to talk to the daemon. This also helps keep the web app from blocking when opening a device that isn't quite ready to deal with users, set... | 2 | 2009-03-10T07:48:12Z | [
"python",
"linux",
"permissions",
"serial-port",
"cgi"
] |
Privilege Escalation in Web Environment for File Access | 628,956 | <p>I have a situation where I would like to elevate the permissions I have in a web environment so that I can access a serial device. </p>
<p>The specific case is where I have a web interface for configuring a modem that comes up on <code>/dev/ttyUSB[0-9]</code>. </p>
<p>Zero or more modems will be plugged in by an e... | 1 | 2009-03-10T04:42:25Z | 629,493 | <p>"What is the best way for a user such as nobody who should have as few permissions as possible to open a file in dev?"</p>
<p>Actually, you're better off using mod_wsgi in daemon mode for your web application. The mod_wsgi user can be any username (and group) you provide. </p>
<p>You can run as a user with appro... | 1 | 2009-03-10T09:54:11Z | [
"python",
"linux",
"permissions",
"serial-port",
"cgi"
] |
Privilege Escalation in Web Environment for File Access | 628,956 | <p>I have a situation where I would like to elevate the permissions I have in a web environment so that I can access a serial device. </p>
<p>The specific case is where I have a web interface for configuring a modem that comes up on <code>/dev/ttyUSB[0-9]</code>. </p>
<p>Zero or more modems will be plugged in by an e... | 1 | 2009-03-10T04:42:25Z | 629,569 | <p>There's another way of doing this: Unix/Linux allows sending file descriptors via Unix sockets. There's even a Perl module for that: <a href="http://search.cpan.org/~sampo/Socket-PassAccessRights-0.03/PassAccessRights.pm" rel="nofollow">PassAccessRights.pm</a>. Didn't find similar module for Python but it could be e... | 2 | 2009-03-10T10:18:07Z | [
"python",
"linux",
"permissions",
"serial-port",
"cgi"
] |
Privilege Escalation in Web Environment for File Access | 628,956 | <p>I have a situation where I would like to elevate the permissions I have in a web environment so that I can access a serial device. </p>
<p>The specific case is where I have a web interface for configuring a modem that comes up on <code>/dev/ttyUSB[0-9]</code>. </p>
<p>Zero or more modems will be plugged in by an e... | 1 | 2009-03-10T04:42:25Z | 636,564 | <p>Configure a <em>udev</em> rule to <em>chgrp</em> the new device to <em>nobody</em>, if it is acceptable that every access via the web interface be permitted the same access to the device. Here's what I put in my <em>eee-bpw</em> package in file <em>/etc/udev/rules.d/99-bpw.rules</em>.</p>
<pre><code># Sierra Wirel... | 1 | 2009-03-11T22:02:29Z | [
"python",
"linux",
"permissions",
"serial-port",
"cgi"
] |
How do I send a HTTP POST value to a (PHP) page using Python? | 629,518 | <p>I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! </p>
| 1 | 2009-03-10T10:02:22Z | 629,534 | <p>Check out the urllib and urllib2 modules. </p>
<p><a href="http://docs.python.org/library/urllib2.html" rel="nofollow">http://docs.python.org/library/urllib2.html</a></p>
<p><a href="http://docs.python.org/library/urllib.html" rel="nofollow">http://docs.python.org/library/urllib.html</a></p>
<p>Simply create a Re... | 5 | 2009-03-10T10:05:27Z | [
"php",
"python",
"post"
] |
How do I send a HTTP POST value to a (PHP) page using Python? | 629,518 | <p>I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! </p>
| 1 | 2009-03-10T10:02:22Z | 629,538 | <p>Yes. <a href="http://docs.python.org/library/urllib2.html" rel="nofollow">urllib2</a> is a nice Python way to form/send HTTP requests.</p>
| 2 | 2009-03-10T10:06:08Z | [
"php",
"python",
"post"
] |
How do I send a HTTP POST value to a (PHP) page using Python? | 629,518 | <p>I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! </p>
| 1 | 2009-03-10T10:02:22Z | 630,100 | <p>When testing, or automating websites using python, I enjoy using twill. Twill is a tool that automatically handles cookies and can read HTML forms and submit them.</p>
<p>For instance, if you had a form on a webpage you could conceivably use the following code:</p>
<pre><code>from twill import commands
commands.go... | 3 | 2009-03-10T13:15:45Z | [
"php",
"python",
"post"
] |
How do I send a HTTP POST value to a (PHP) page using Python? | 629,518 | <p>I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! </p>
| 1 | 2009-03-10T10:02:22Z | 632,312 | <p>I find <a href="http://www.voidspace.org.uk/python/articles/urllib2.shtml" rel="nofollow">http://www.voidspace.org.uk/python/articles/urllib2.shtml</a> to be a good source of information about urllib2, which is probably the best tool for the job.</p>
<pre><code>import urllib
import urllib2
url = 'http://www.somese... | 3 | 2009-03-10T21:16:00Z | [
"php",
"python",
"post"
] |
How do I send a HTTP POST value to a (PHP) page using Python? | 629,518 | <p>I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! </p>
| 1 | 2009-03-10T10:02:22Z | 634,178 | <p>Just an addendum to <a href="http://stackoverflow.com/questions/629518/how-do-i-send-a-http-post-value-to-a-php-page-using-python/632312#632312">@antileet</a>'s procedure, it works similarly if you're trying to do a HTTP POST request with a web-service-like payload, except you just omit the urlencode step; i.e.</p>
... | 0 | 2009-03-11T11:40:35Z | [
"php",
"python",
"post"
] |
How do I send a HTTP POST value to a (PHP) page using Python? | 629,518 | <p>I have a PHP page that has 1 textbox and when I press on the submit button. My SQL is going to store this product name into my database. My question is; is it possible to send/post the product name using Python script that asks for 1 value and then use my PHP page to send it to my database? Thanks! </p>
| 1 | 2009-03-10T10:02:22Z | 34,576,169 | <p>Personally i prefer to use <strong>Requests</strong>. As its summary, this is a <em>HTTP library for Python, built for human beings</em>.</p>
<p>To quickly solve problems, rather than study deeply in HTTP, <strong>Requests</strong> will be a better choice. (Yeah, i mean compared to <em>urllib</em> or <em>socket</em... | 0 | 2016-01-03T11:46:53Z | [
"php",
"python",
"post"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 629,584 | <p>You need to do custom SQL as exemplified in this snippet:</p>
<p><a href="http://www.djangosnippets.org/snippets/236/" rel="nofollow">Custom SQL via subquery</a></p>
<p>Or in a custom manager as shown in the online Django docs:</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/db/managers/#adding-extra-... | 4 | 2009-03-10T10:24:57Z | [
"python",
"django"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 629,600 | <p>An easy solution, but not in a proper way is to use RAW-SQL:</p>
<p><a href="http://docs.djangoproject.com/en/dev/topics/db/sql/#topics-db-sql">http://docs.djangoproject.com/en/dev/topics/db/sql/#topics-db-sql</a></p>
<p>Another solution is to use the group_by property:</p>
<pre><code>query = Members.objects.all(... | 25 | 2009-03-10T10:30:44Z | [
"python",
"django"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 629,691 | <p>If you mean to do aggregation and are using Django 1.1 (currently in alpha 1), you can use the new <a href="http://docs.djangoproject.com/en/dev/topics/db/aggregation/#topics-db-aggregation">aggregation features of the ORM</a>:</p>
<pre><code>from django.db.models import Count
Members.objects.values('designation').... | 246 | 2009-03-10T11:08:28Z | [
"python",
"django"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 26,843,739 | <p>If I'm not mistaking you can use, <em>whatever-query-set</em>.group_by=['<em>field</em>'] </p>
| 0 | 2014-11-10T12:22:15Z | [
"python",
"django"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 33,678,300 | <p><strong>Django does not support free group by queries</strong>. I learned it in the very bad way. ORM is not designed to support stuff like what you want to do, without using custom SQL. You are limited to:</p>
<ul>
<li>RAW sql (i.e. MyModel.objects.raw())</li>
<li><code>cr.execute</code> sentences (and a hand-made... | 0 | 2015-11-12T18:06:20Z | [
"python",
"django"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 39,537,917 | <p>You can get the equivalent of a group by using Django's <code>order_by</code> query and python's built-in <a href="https://docs.python.org/2/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> function.</p>
<pre><code>import itertools
members_queryset = Members.objects.order... | 1 | 2016-09-16T18:25:19Z | [
"python",
"django"
] |
How to query as GROUP BY in django? | 629,551 | <p>I query a model, </p>
<pre><code>Members.objects.all()
</code></pre>
<p>and it returns say</p>
<pre><code>Eric, Salesman, X-Shop
Freddie, Manager, X2-Shop
Teddy, Salesman, X2-Shop
Sean, Manager, X2-Shop
</code></pre>
<p>What i want is, to know the best Django way to fire
a group_by query to my db, as like,</p>
... | 161 | 2009-03-10T10:10:30Z | 39,774,497 | <p>There is module that allows you to group Django models and still work with a QuerySet in the result: <a href="https://github.com/kako-nawao/django-group-by" rel="nofollow">https://github.com/kako-nawao/django-group-by</a></p>
<p>For example:</p>
<pre><code>from django_group_by import GroupByMixin
class BookQueryS... | 0 | 2016-09-29T15:33:31Z | [
"python",
"django"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 629,715 | <p>First, create a way to have your development and production servers pull settings from different files, say dev.py and prod.py. There are lots of ways to do this.</p>
<p>Then, create a setting, <code>GOOGLE_ANALYTICS_KEY</code>. In dev.py set it to the empty string. In prod.py, set it to your key, something like... | 34 | 2009-03-10T11:17:08Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 629,720 | <p>You have template context processors that can be used to pass values to all templates without updating all your views.</p>
<p><a href="http://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors</a></p>... | 0 | 2009-03-10T11:18:58Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 629,888 | <p>I mostly agree with Ned, although I have a single setting called IS_LIVE_SITE which toggles analytics code, adverts and a few other things. This way I can keep all the keys in subversion (as it is a pain to look them up) and still toggle them on or off easily.</p>
| 2 | 2009-03-10T12:19:36Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 633,029 | <p>Instead of including the script tag directly in your html, just change the analytics javascript so it only runs if the href does not contain your prod site's name. This will work without any extra configuration.</p>
| 1 | 2009-03-11T01:48:06Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 1,433,970 | <p>My solution takes a similar approach to Ned's preferred answer, but separates the analytics code into its own template. I prefer this, so I can just copy the template from project to project.</p>
<p>Here's a snippet from my context_processor file:</p>
<pre><code>from django.conf import settings
from django.templat... | 5 | 2009-09-16T16:12:53Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 1,559,982 | <p>A little late to the party, but there's a reusable Django app called <a href="http://github.com/montylounge/django-google-analytics">django-google-analytics</a>. The easiest way to use it is:</p>
<ol>
<li>Add the <code>google_analytics</code> application to your <code>INSTALLED_APPS</code> section of your <code>set... | 10 | 2009-10-13T12:45:30Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 11,400,347 | <p>All of these other solutions may work, but they are all overkill now because you can easily set up a filter in Google Analytics to filter out all traffic that is not coming from your production website or websites. See <a href="http://support.google.com/analytics/bin/answer.py?hl=en&answer=1034823" rel="nofollo... | 4 | 2012-07-09T17:49:45Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 16,115,699 | <p>Here's the dead simple way that I solved it:</p>
<p>Create an app in your project called 'utils' if you haven't already. See <a href="http://ygamretuta.me/2011/03/08/django-creating-a-custom-template-context-processor/" rel="nofollow">these directions</a>.</p>
<p>However, follow this approach to include all global... | 0 | 2013-04-20T01:51:04Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Deploying Google Analytics With Django | 629,696 | <p>We're about to deploy a new Django website, and we want to use Google Analytics to keep track of traffic on the site. However, we don't want all of the hits on development instances to contribute to the Google Analytics statistics.</p>
<p>There are a few ways we could deal with this:</p>
<ul>
<li>have a configura... | 23 | 2009-03-10T11:09:57Z | 20,730,513 | <p>Another simple way.
In <code>settings.py</code>ï¼Check <code>debug</code> is <code>True</code>, then add:</p>
<pre><code>INTERNAL_IPS = (
'127.0.0.1',
'localhost',
)
</code></pre>
<p>Then you can use things in your template like this:</p>
<pre><code>{% if not debug %}
<script> blah blah </script... | 2 | 2013-12-22T14:36:12Z | [
"python",
"django",
"deployment",
"google-analytics"
] |
Why avoid CGI for Python with LAMP hosting? | 629,919 | <p>I have been using PHP for years. Lately I've come across numerous forum posts stating that <strong>PHP is outdated</strong>, that modern programming languages are easier, more secure, etc. etc.</p>
<p>So, I decided to <strong>start learning Python</strong>. Since I'm used to using PHP, I just started building pages... | 22 | 2009-03-10T12:32:06Z | 629,929 | <p><a href="http://code.djangoproject.com/wiki/django%5Fapache%5Fand%5Fmod%5Fwsgi" rel="nofollow"><strong>mod_wsgi</strong></a> is the proper alternative. It is preferable over CGI in almost all aspects.</p>
| 3 | 2009-03-10T12:35:41Z | [
"php",
"python",
".htaccess",
"cgi"
] |
Why avoid CGI for Python with LAMP hosting? | 629,919 | <p>I have been using PHP for years. Lately I've come across numerous forum posts stating that <strong>PHP is outdated</strong>, that modern programming languages are easier, more secure, etc. etc.</p>
<p>So, I decided to <strong>start learning Python</strong>. Since I'm used to using PHP, I just started building pages... | 22 | 2009-03-10T12:32:06Z | 629,930 | <p>Classic CGI isn't the best way to use anything at all. With classic CGI server has to <strong>spawn a new process for every request</strong>.</p>
<p>As for Python, you have few alternatives:</p>
<ul>
<li><a href="http://code.google.com/p/modwsgi/" rel="nofollow"><code>mod_wsgi</code></a></li>
<li><a href="http://m... | 9 | 2009-03-10T12:35:50Z | [
"php",
"python",
".htaccess",
"cgi"
] |
Why avoid CGI for Python with LAMP hosting? | 629,919 | <p>I have been using PHP for years. Lately I've come across numerous forum posts stating that <strong>PHP is outdated</strong>, that modern programming languages are easier, more secure, etc. etc.</p>
<p>So, I decided to <strong>start learning Python</strong>. Since I'm used to using PHP, I just started building pages... | 22 | 2009-03-10T12:32:06Z | 629,940 | <p>Really it's just an efficiency thing - CGI spawns an entire new process for every request, which is quite heavyweight for what it does.</p>
<p>PHP can be run through CGI as well, but mod_php embeds the interpreter within apache.
There's a <a href="http://www.modpython.org/" rel="nofollow">mod_python</a> which does ... | 3 | 2009-03-10T12:38:39Z | [
"php",
"python",
".htaccess",
"cgi"
] |
Why avoid CGI for Python with LAMP hosting? | 629,919 | <p>I have been using PHP for years. Lately I've come across numerous forum posts stating that <strong>PHP is outdated</strong>, that modern programming languages are easier, more secure, etc. etc.</p>
<p>So, I decided to <strong>start learning Python</strong>. Since I'm used to using PHP, I just started building pages... | 22 | 2009-03-10T12:32:06Z | 629,960 | <p>Aside from the suggestions others make, you should really consider using a framework of some kind. You can and should be using <a href="http://www.fastcgi.com/" rel="nofollow">FastCGI</a>, mod_python, or mod_wsgi, but they weren't really intended for you to write code directly against. Might I suggest one of the f... | 1 | 2009-03-10T12:42:36Z | [
"php",
"python",
".htaccess",
"cgi"
] |
Why avoid CGI for Python with LAMP hosting? | 629,919 | <p>I have been using PHP for years. Lately I've come across numerous forum posts stating that <strong>PHP is outdated</strong>, that modern programming languages are easier, more secure, etc. etc.</p>
<p>So, I decided to <strong>start learning Python</strong>. Since I'm used to using PHP, I just started building pages... | 22 | 2009-03-10T12:32:06Z | 630,001 | <p>There is a page in the Python documentation that describes the <a href="http://docs.python.org/howto/webservers.html" rel="nofollow">advantages and disadvantages of the various possibilities</a>.</p>
<p><strong>mod_python</strong></p>
<blockquote>
<p>(â¦) These are the reasons why mod_python should be avoided w... | 2 | 2009-03-10T12:52:07Z | [
"php",
"python",
".htaccess",
"cgi"
] |
Why avoid CGI for Python with LAMP hosting? | 629,919 | <p>I have been using PHP for years. Lately I've come across numerous forum posts stating that <strong>PHP is outdated</strong>, that modern programming languages are easier, more secure, etc. etc.</p>
<p>So, I decided to <strong>start learning Python</strong>. Since I'm used to using PHP, I just started building pages... | 22 | 2009-03-10T12:32:06Z | 630,462 | <blockquote>
<p>Why is it that using CGI is not the best way to use Python?</p>
</blockquote>
<p>I will stick up for CGI a little. It's good for development environments.</p>
<p>It's simple to wire up and you don't have to worry about module reloading problems. Naturally performance is terrible, but for dev you don... | 5 | 2009-03-10T14:27:20Z | [
"php",
"python",
".htaccess",
"cgi"
] |
BeautifulSoup gives me unicode+html symbols, rather than straight up unicode. Is this a bug or misunderstanding? | 629,999 | <p>I'm using BeautifulSoup to scrape a website. The website's page renders fine in my browser: </p>
<blockquote>
<p>Oxfam Internationalâs report entitled âOffside!
<a href="http://www.coopamerica.org/programs/responsibleshopper/company.cfm?id=271">http://www.coopamerica.org/programs/responsibleshopper/company.... | 5 | 2009-03-10T12:52:00Z | 630,099 | <p>That's one seriously messed up page, encoding-wise :-)</p>
<p>There's nothing really wrong with your approach at all. I would probably tend to do the conversion before passing it to BeautifulSoup, just because I'm persnickity:</p>
<pre><code>import urllib
html = urllib.urlopen('http://www.coopamerica.org/programs/... | 8 | 2009-03-10T13:15:41Z | [
"python",
"html",
"unicode",
"beautifulsoup"
] |
BeautifulSoup gives me unicode+html symbols, rather than straight up unicode. Is this a bug or misunderstanding? | 629,999 | <p>I'm using BeautifulSoup to scrape a website. The website's page renders fine in my browser: </p>
<blockquote>
<p>Oxfam Internationalâs report entitled âOffside!
<a href="http://www.coopamerica.org/programs/responsibleshopper/company.cfm?id=271">http://www.coopamerica.org/programs/responsibleshopper/company.... | 5 | 2009-03-10T12:52:00Z | 630,126 | <p>It's actually UTF-8 misencoded as CP1252:</p>
<pre><code>>>> print u'Oxfam International\xe2â¬â¢s report entitled \xe2â¬ÅOffside!'.encode('cp1252').decode('utf8')
Oxfam Internationalâs report entitled âOffside!
</code></pre>
| 4 | 2009-03-10T13:21:42Z | [
"python",
"html",
"unicode",
"beautifulsoup"
] |
How can I use python's telnetlib to fetch data from a device for a fixed period of time? | 630,217 | <p>I'm connecting to a hardware device via telnet. That device is pretty simple in terms of I/O. So I submit a command to it, and after that the device pumps out data one line at a time, once per second. Each line just contains a number.</p>
<p>So my question is this: if I connect to this device using python's telnetl... | 2 | 2009-03-10T13:41:54Z | 630,253 | <p>Read lines in a loop until you have either read the required number of lines or the time limit has been reached. However, it doesn't sound like you actual need a telnet library. Why not just use a simple TCP <a href="http://docs.python.org/library/socket.html" rel="nofollow">socket</a> for the connection? </p>
| 1 | 2009-03-10T13:49:49Z | [
"python",
"telnet"
] |
How can I use python's telnetlib to fetch data from a device for a fixed period of time? | 630,217 | <p>I'm connecting to a hardware device via telnet. That device is pretty simple in terms of I/O. So I submit a command to it, and after that the device pumps out data one line at a time, once per second. Each line just contains a number.</p>
<p>So my question is this: if I connect to this device using python's telnetl... | 2 | 2009-03-10T13:41:54Z | 630,257 | <p>In my experience, most such devices use some prompt, in which case <a href="http://docs.python.org/library/telnetlib.html#telnetlib.Telnet.read%5Funtil" rel="nofollow"><code>Telnet.read_until()</code></a> is appropriate:</p>
<blockquote>
<p><code>Telnet.read_until(expected[, timeout])</code></p>
<p>Read unti... | 2 | 2009-03-10T13:50:50Z | [
"python",
"telnet"
] |
How can I use python's telnetlib to fetch data from a device for a fixed period of time? | 630,217 | <p>I'm connecting to a hardware device via telnet. That device is pretty simple in terms of I/O. So I submit a command to it, and after that the device pumps out data one line at a time, once per second. Each line just contains a number.</p>
<p>So my question is this: if I connect to this device using python's telnetl... | 2 | 2009-03-10T13:41:54Z | 630,258 | <p>From your description I'm not clear if you're using telnetlib because the device you're connecting to <em>requires terminal setup provided by telnet</em> or because it seemed like the right thing to do.</p>
<p>If the device is as simple as you describe--i.e. not negotiating terminal options on connection--have you ... | 4 | 2009-03-10T13:51:22Z | [
"python",
"telnet"
] |
How can I use python's telnetlib to fetch data from a device for a fixed period of time? | 630,217 | <p>I'm connecting to a hardware device via telnet. That device is pretty simple in terms of I/O. So I submit a command to it, and after that the device pumps out data one line at a time, once per second. Each line just contains a number.</p>
<p>So my question is this: if I connect to this device using python's telnetl... | 2 | 2009-03-10T13:41:54Z | 630,260 | <p>It sounds like blocking isn't really your problem, since you know that you'll only be blocking for a second. Why not do something like:</p>
<pre><code>lines_to_read = 10
for i in range(lines_to_read):
line = tel.read_until("\n")
</code></pre>
| 2 | 2009-03-10T13:52:11Z | [
"python",
"telnet"
] |
Is there any reasonable SSDP or DIDL Lib for java/groovy/python? | 630,296 | <p>For a future project I am looking for a library to handle SSDP communication and messages in DIDL-Lite xml dialect. Is there any reasonable implementation of java, groovy or python? </p>
<p>I don't like to use implementations of existing UPnP stacks like cybergarage or the frauenhofer UPnP stack because they are hi... | 3 | 2009-03-10T13:57:55Z | 3,255,815 | <p><a href="http://teleal.org/projects/cling" rel="nofollow">http://teleal.org/projects/cling</a></p>
<p>Open Source DLNA/UPnP stack, libraries, and tools for Java and Android developers</p>
<p>Cling is very modular, so you could only use its SSDP functionality. You can integrate it with your existing code at any lev... | 3 | 2010-07-15T13:14:57Z | [
"java",
"python",
"groovy",
"upnp"
] |
Detect whether charset exists in python | 630,938 | <p>Is it possible to check in Python whether a given charset exists/is installed.
For example:<br />
check('iso-8859-1') -> True<br />
check('bla') -> False</p>
| 0 | 2009-03-10T16:00:02Z | 630,974 | <p>You can use the <code>lookup()</code> function in the <code>codecs</code> module. It throws an exception if a codec does not exist:</p>
<pre><code>import codecs
def exists_encoding(enc):
try:
codecs.lookup(enc)
except LookupError:
return False
return True
exists_encoding('latin1')
</code... | 3 | 2009-03-10T16:06:01Z | [
"python",
"character-encoding"
] |
Hello world Pyamf small error message | 631,436 | <p>Hi i am trying to link flex to django with Pyamf</p>
<p>As a first step i tried the basic Hello World
<a href="http://pyamf.org/wiki/DjangoHowto" rel="nofollow">http://pyamf.org/wiki/DjangoHowto</a></p>
<p>But that results in an ErrorFault.</p>
<p>I use django 1.0.2</p>
<p><strong>amfgateway.py</strong> in the ... | 1 | 2009-03-10T17:27:25Z | 631,760 | <p>I think you may need to take the request parameter out of your echo def, at least the method on the pyamf example site doesn't have that parameter in the method</p>
| 3 | 2009-03-10T18:54:05Z | [
"python",
"django",
"flex",
"pyamf"
] |
Hello world Pyamf small error message | 631,436 | <p>Hi i am trying to link flex to django with Pyamf</p>
<p>As a first step i tried the basic Hello World
<a href="http://pyamf.org/wiki/DjangoHowto" rel="nofollow">http://pyamf.org/wiki/DjangoHowto</a></p>
<p>But that results in an ErrorFault.</p>
<p>I use django 1.0.2</p>
<p><strong>amfgateway.py</strong> in the ... | 1 | 2009-03-10T17:27:25Z | 1,853,408 | <p>Although the error is unrelated, JMP is correct - you have <code>expose_request=False</code> on the gateway and the service definition for echo has the first argument as the Django Http request object.</p>
<p>This isn't going to work, however PyAMF does allow some granularity here, you can use the expose_request de... | 2 | 2009-12-05T20:48:25Z | [
"python",
"django",
"flex",
"pyamf"
] |
Interruptible thread join in Python | 631,441 | <p><strong>Is there any way to wait for termination of a thread, but still intercept signals?</strong> </p>
<p>Consider the following <strong>C</strong> program:</p>
<pre><code>#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include... | 21 | 2009-03-10T17:28:16Z | 631,491 | <p>Poll on <code>isAlive</code> before calling <code>join</code>. This polling can be interrupted, of course, and once the thread isn't <code>isAlive</code>, <code>join</code> is immediate.</p>
<p>An alternative would be polling on <code>join</code> with a timeout, checking with <code>isAlive</code> whether the timeou... | 3 | 2009-03-10T17:43:59Z | [
"python",
"multithreading"
] |
Interruptible thread join in Python | 631,441 | <p><strong>Is there any way to wait for termination of a thread, but still intercept signals?</strong> </p>
<p>Consider the following <strong>C</strong> program:</p>
<pre><code>#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include... | 21 | 2009-03-10T17:28:16Z | 631,605 | <p>Threads in Python are somewhat strange beasts given the global interpreter lock. You may not be able to achieve what you want without resorting to a join timeout and isAlive as eliben suggests.</p>
<p>There are two spots in the docs that give the reason for this (and possibly more).</p>
<p>The first:</p>
<p>From ... | 15 | 2009-03-10T18:12:29Z | [
"python",
"multithreading"
] |
Interruptible thread join in Python | 631,441 | <p><strong>Is there any way to wait for termination of a thread, but still intercept signals?</strong> </p>
<p>Consider the following <strong>C</strong> program:</p>
<pre><code>#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include... | 21 | 2009-03-10T17:28:16Z | 634,233 | <p>Jarret Hardie already <a href="http://stackoverflow.com/questions/631441/interruptible-thread-join-in-python/631605#631605">mentioned it</a>: According to <a href="http://bugs.python.org/msg56947" rel="nofollow">Guido van Rossum</a>, there's no better way as of now: As stated in the <a href="http://docs.python.org/l... | 3 | 2009-03-11T12:04:39Z | [
"python",
"multithreading"
] |
Interruptible thread join in Python | 631,441 | <p><strong>Is there any way to wait for termination of a thread, but still intercept signals?</strong> </p>
<p>Consider the following <strong>C</strong> program:</p>
<pre><code>#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include... | 21 | 2009-03-10T17:28:16Z | 5,063,521 | <p>I know I'm a bit late to the party, but I came to this question hoping for a better answer than joining with a timeout, which I was already doing. In the end I cooked something up that may or may not be a horrible bastardisation of signals, but it involves using <code>signal.pause()</code> instead of <code>Thread.jo... | 0 | 2011-02-21T07:53:52Z | [
"python",
"multithreading"
] |
Interruptible thread join in Python | 631,441 | <p><strong>Is there any way to wait for termination of a thread, but still intercept signals?</strong> </p>
<p>Consider the following <strong>C</strong> program:</p>
<pre><code>#include <signal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <pthread.h>
#include... | 21 | 2009-03-10T17:28:16Z | 5,063,871 | <p>As far as I understand, a similar question is solved in <a href="http://greenteapress.com/semaphores/" rel="nofollow">The Little Book of Semaphores</a> (free download), appendix A part 3â¦</p>
| 1 | 2011-02-21T08:47:08Z | [
"python",
"multithreading"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 631,474 | <p>Try this:</p>
<pre><code>import collections
merged = collections.defaultdict(list)
for k in d1:
merged[k].append( d1[k] )
for k in d2:
merged[k].append( d2[k] )
</code></pre>
<p>This may be what you're looking for.</p>
<p>Or possibly this.</p>
<pre><code>import collections
merged = collections.defaultdict(... | 14 | 2009-03-10T17:37:22Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 631,476 | <p>Here are some good links:</p>
<p><a href="http://www.diveintopython.org/getting_to_know_python/dictionaries.html" rel="nofollow">http://www.diveintopython.org/getting_to_know_python/dictionaries.html</a><br />
<a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" rel="nofollow">http://docs.pyth... | 2 | 2009-03-10T17:37:53Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 631,487 | <p>Python dictionaries also work much like associative arrays in PHP, if you have any experience in that language.</p>
<p>The Built-in Types page in the Python docs also has a good section on dictionaries, and the section also has a list of functions available for them:</p>
<p><a href="http://docs.python.org/library/... | 1 | 2009-03-10T17:42:18Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 631,514 | <p>One good place to start is by getting iPython (<code>easy_install ipython</code>) then poking around with tab completion, <code>?</code> and <code>dir</code>:</p>
<pre><code>In [2]: dir {}
------> dir({})
Out[2]:
['__class__',
...
'keys',
'pop',
'popitem',
'setdefault',
'update',
'values']
In [3]: {}.u... | 6 | 2009-03-10T17:49:32Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 631,549 | <p>I believe here is what you want:</p>
<pre><code>>>> d1={'key1':1, 'key2':2}
>>> d2={'key1':1, 'key2':'A', 'key4':4}
>>> d = {}
>>> d.update(d1)
>>> for i in d2:
if i in d and d2[i] != d[i]:
d[i] = [d[i], d2[i]]
else:
d[i] = d2[i] ... | 4 | 2009-03-10T17:55:08Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 631,581 | <p>well, for your first case, you might want a helper that combines two objects into a list of two objects, and two lists into one list containing items from the two lists, </p>
<p>This is assuming of course, that you always merge keys into lists, but you don't want your keys to end up being "lists of lists"</p>
<pre... | 0 | 2009-03-10T18:04:25Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 632,136 | <p>A variation on <a href="http://stackoverflow.com/questions/631463/dictionaries-in-python/631549#631549">@SilentGhost's answer</a> (all other answers produce wrong dictionaries):</p>
<pre><code>>>> d1 = dict(key1=1, key2=2)
>>> d2 = dict(key1=1, key2='A', key4=4)
>>> d = dict(d1)
>>&... | 0 | 2009-03-10T20:30:38Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 633,005 | <p>Maybe this is a bit awkward to do because the data structure you are trying to create is not as natural as it could be. For example instead of having some values be lone values, and some be lists, why not keep everything in lists? E.g.</p>
<pre><code>{'key1': [1], 'key2': [2, 'A'], 'key4': [4]}
</code></pre>
<p>It... | 0 | 2009-03-11T01:40:11Z | [
"python",
"dictionary"
] |
Dictionaries in Python | 631,463 | <p>I am trying to get to speed on the use of dictionaries. I spent three hours last night searching the web for examples similar to some of the things I am trying to do. For example, suppose I have two dictionaries (actually I have two lists of dictionaries). </p>
<pre><code>d1={key1:1, key2:2}
d2={key1:1, key2:'A'... | 5 | 2009-03-10T17:34:43Z | 2,319,295 | <p>Here is another variation. </p>
<pre><code>d1 = {'key1'=1, 'key2'=2}
d2 = {'key1'=1, 'key2'='A', 'key4'=4)
d = d2
for k, v in d.iteritems():
... if k in d1.keys() and v!=d1[k]:
... d[k] = [d1[k], v2]
d
{'key2': [2, 'A'], 'key1': 1, 'key4': 4}
</code></pre>
| 0 | 2010-02-23T15:27:56Z | [
"python",
"dictionary"
] |
What is the best method to read a double from a Binary file created in C? | 631,607 | <p>A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using <code>struct.unpack('d',f.read(8))</code></p>
<p>EDIT:
I used the following in C to write a random double number</p>
<pre><code>r = drand48();
fwrite((void*)&r, sizeof(double), 1, data);
</code></pre>
... | 4 | 2009-03-10T18:13:05Z | 631,640 | <p>Could you please elaborate on "didn't work"? Did the command crash? Did the data come out wrong? What actually happened?</p>
<p>If the command crashed:</p>
<ul>
<li>Please share the error output of the command</li>
</ul>
<p>If the data simply came out wrong:</p>
<ul>
<li><p>Do the systems that create and read... | 1 | 2009-03-10T18:24:38Z | [
"python",
"c",
"double"
] |
What is the best method to read a double from a Binary file created in C? | 631,607 | <p>A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using <code>struct.unpack('d',f.read(8))</code></p>
<p>EDIT:
I used the following in C to write a random double number</p>
<pre><code>r = drand48();
fwrite((void*)&r, sizeof(double), 1, data);
</code></pre>
... | 4 | 2009-03-10T18:13:05Z | 631,768 | <ul>
<li><code>f.read(8)</code> might return less than 8 bytes</li>
<li><p>Data might have different alignment and/or endianness:</p>
<pre><code>>>> for c in '@=<>':
... print repr(struct.pack(c+'d', -1.05))
...
'\xcd\xcc\xcc\xcc\xcc\xcc\xf0\xbf'
'\xcd\xcc\xcc\xcc\xcc\xcc\xf0\xbf'
'\xcd\xcc\xcc\xcc\... | 0 | 2009-03-10T18:56:14Z | [
"python",
"c",
"double"
] |
What is the best method to read a double from a Binary file created in C? | 631,607 | <p>A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using <code>struct.unpack('d',f.read(8))</code></p>
<p>EDIT:
I used the following in C to write a random double number</p>
<pre><code>r = drand48();
fwrite((void*)&r, sizeof(double), 1, data);
</code></pre>
... | 4 | 2009-03-10T18:13:05Z | 632,542 | <p>The <em>best</em> method would be to use an ASCII text file:</p>
<blockquote>
<p>0.0<br />
3.1416<br />
3.90798504668055 </p>
</blockquote>
<p>in that it would be portable and work with any kind of floating point implementation to a degree.</p>
<p>Reading raw binary data from a <code>double</code>'s memory... | -1 | 2009-03-10T22:29:12Z | [
"python",
"c",
"double"
] |
What is the best method to read a double from a Binary file created in C? | 631,607 | <p>A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using <code>struct.unpack('d',f.read(8))</code></p>
<p>EDIT:
I used the following in C to write a random double number</p>
<pre><code>r = drand48();
fwrite((void*)&r, sizeof(double), 1, data);
</code></pre>
... | 4 | 2009-03-10T18:13:05Z | 632,673 | <p>First, have you tried <a href="http://www.python.org/doc/1.5.2p2/lib/module-pickle.html" rel="nofollow">pickle</a>?
No one has shown any Python code yet... Here is some code for reading in binary in python:</p>
<pre><code>import Numeric as N
import array
filename = "tmp.bin"
file = open(filename, mode='rb')
binva... | 1 | 2009-03-10T23:19:34Z | [
"python",
"c",
"double"
] |
What is the best method to read a double from a Binary file created in C? | 631,607 | <p>A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using <code>struct.unpack('d',f.read(8))</code></p>
<p>EDIT:
I used the following in C to write a random double number</p>
<pre><code>r = drand48();
fwrite((void*)&r, sizeof(double), 1, data);
</code></pre>
... | 4 | 2009-03-10T18:13:05Z | 632,823 | <p>I think you are actually reading the number correctly, but are getting confused by the display. When I read the number from your provided file, I get "<code>3.907985046680551e-14</code>" - this is almost but not quite zero (0.000000000000039 in expanded form). I suspect your C code is just printing it with less pr... | 3 | 2009-03-11T00:22:48Z | [
"python",
"c",
"double"
] |
How do I assign a version number for a Python package using SVN and distutils? | 631,813 | <p>I'm writing a Python package. The package needs to know its version number internally, while also including this version in the <code>setup.py</code> script for <code>distutils</code>.</p>
<p>What's the best way of doing this, so that the version number doesn't need to be maintained in two separate places? I don'... | 4 | 2009-03-10T19:08:49Z | 631,985 | <p>Inside of your main package, you probably have an <code>__init__.py</code>, right?</p>
<p>Directory structure:</p>
<pre><code>> ./packageTest
> ./packageTest/__init__.py
> ./packageTest/setup.py
</code></pre>
<p>Inside the <code>__init__.py</code> file, add the following line:</p>
<pre><code># packa... | 5 | 2009-03-10T19:50:52Z | [
"python",
"svn",
"distutils"
] |
How do I assign a version number for a Python package using SVN and distutils? | 631,813 | <p>I'm writing a Python package. The package needs to know its version number internally, while also including this version in the <code>setup.py</code> script for <code>distutils</code>.</p>
<p>What's the best way of doing this, so that the version number doesn't need to be maintained in two separate places? I don'... | 4 | 2009-03-10T19:08:49Z | 632,040 | <p>Importing the setup script inside your package is silly (especially since it may no longer be present after your library is installed), but importing your library inside setup.py should be fine.
A separate text file would work too, but has the problem that you must install the text file with your package if you want... | 0 | 2009-03-10T20:04:51Z | [
"python",
"svn",
"distutils"
] |
How do I assign a version number for a Python package using SVN and distutils? | 631,813 | <p>I'm writing a Python package. The package needs to know its version number internally, while also including this version in the <code>setup.py</code> script for <code>distutils</code>.</p>
<p>What's the best way of doing this, so that the version number doesn't need to be maintained in two separate places? I don'... | 4 | 2009-03-10T19:08:49Z | 632,077 | <p>I had a similar problem with my project. I have written a top-level, test/build/package/deploy script called <a href="https://fisheye.springframework.org/browse/se-springpython-py/trunk/springpython/build.py?r=470" rel="nofollow">build.py</a> (not distutils-based, mind you). It reads a <a href="https://fisheye.sprin... | 0 | 2009-03-10T20:14:27Z | [
"python",
"svn",
"distutils"
] |
How do I assign a version number for a Python package using SVN and distutils? | 631,813 | <p>I'm writing a Python package. The package needs to know its version number internally, while also including this version in the <code>setup.py</code> script for <code>distutils</code>.</p>
<p>What's the best way of doing this, so that the version number doesn't need to be maintained in two separate places? I don'... | 4 | 2009-03-10T19:08:49Z | 8,882,419 | <p>See also <a href="http://stackoverflow.com/questions/458550/standard-way-to-embed-version-into-python-package">Standard way to embed version into python package?</a> which is about how to propagate the version information from the one location (a file named <code>_version.py</code>) to the places where other code lo... | 0 | 2012-01-16T15:45:55Z | [
"python",
"svn",
"distutils"
] |
base64 png in python on Windows | 631,884 | <p>How do you encode a png image into base64 using python on Windows?</p>
<pre><code>iconfile = open("icon.png")
icondata = iconfile.read()
icondata = base64.b64encode(icondata)
</code></pre>
<p>The above works fine in Linux and OSX, but on Windows it will encode the first few characters then cut short. Why is this?<... | 11 | 2009-03-10T19:25:42Z | 631,899 | <p><a href="http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files">Open the file in binary mode</a>:</p>
<pre><code>open("icon.png", "rb")
</code></pre>
<p>I'm not very familiar with Windows, but I'd imagine what's happening is that the file contains a character (0x1A) that <a href="http://www.go... | 26 | 2009-03-10T19:29:26Z | [
"python",
"windows",
"base64"
] |
base64 png in python on Windows | 631,884 | <p>How do you encode a png image into base64 using python on Windows?</p>
<pre><code>iconfile = open("icon.png")
icondata = iconfile.read()
icondata = base64.b64encode(icondata)
</code></pre>
<p>The above works fine in Linux and OSX, but on Windows it will encode the first few characters then cut short. Why is this?<... | 11 | 2009-03-10T19:25:42Z | 632,495 | <p>To augment the answer from Miles, the <a href="http://www.libpng.org/pub/png/spec/1.2/PNG-Rationale.html#R.PNG-file-signature">first eight bytes in a PNG file</a> are specially designed:</p>
<ul>
<li>89 - the first byte is a check that
bit 8 hasn't been stripped</li>
<li>"PNG" - let someone read that it's a
PNG for... | 9 | 2009-03-10T22:16:13Z | [
"python",
"windows",
"base64"
] |
figure out whether python module is installed or in develop mode programmatically | 631,996 | <p>I tend to develop my apps in 'setup.py develop' -mode. I'd want the configuration to switch automagically on production mode when the program gets 'setup.py install'ed.</p>
<p>This can be done by poor hacks, like checking whether installation directory contains 'setup.py', but I wonder whether pkg_resources can do ... | 1 | 2009-03-10T19:52:42Z | 632,051 | <p>Isn't it easier, and cleaner, to just set an environment variable on your development machine, and test for <code>os.environ['development_mode']</code> (or a setting of your choice)?</p>
| 5 | 2009-03-10T20:08:36Z | [
"python",
"packaging"
] |
figure out whether python module is installed or in develop mode programmatically | 631,996 | <p>I tend to develop my apps in 'setup.py develop' -mode. I'd want the configuration to switch automagically on production mode when the program gets 'setup.py install'ed.</p>
<p>This can be done by poor hacks, like checking whether installation directory contains 'setup.py', but I wonder whether pkg_resources can do ... | 1 | 2009-03-10T19:52:42Z | 632,314 | <p>Indeed, <a href="http://peak.telecommunity.com/DevCenter/PkgResources#distribution-attributes" rel="nofollow"><code>pkg_resources</code> will do that</a>:</p>
<pre><code>dist = pkg_resources.get_distribution('your-app')
if dist.precedence == pkg_resources.DEVELOP_DIST:
# package is in development mode
...
<... | 4 | 2009-03-10T21:16:28Z | [
"python",
"packaging"
] |
figure out whether python module is installed or in develop mode programmatically | 631,996 | <p>I tend to develop my apps in 'setup.py develop' -mode. I'd want the configuration to switch automagically on production mode when the program gets 'setup.py install'ed.</p>
<p>This can be done by poor hacks, like checking whether installation directory contains 'setup.py', but I wonder whether pkg_resources can do ... | 1 | 2009-03-10T19:52:42Z | 632,320 | <p>Another option is to use <a href="http://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a>. Then your development environment could be identical to your production environment. Setuptools is a pretty heavy thing to depend on, in my opinion.</p>
| 0 | 2009-03-10T21:18:00Z | [
"python",
"packaging"
] |
Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac | 632,046 | <p>I've looked for other questions, but could not find any...</p>
<p>I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using <a href="http://localhost/" rel="nofollow">http://localhost/</a></p>
<p>I ... | 0 | 2009-03-10T20:07:13Z | 632,082 | <p>Your Mac should come pre-installed with Python 2.4 (or later) which is fine for Django 1.0.2.</p>
| 1 | 2009-03-10T20:15:16Z | [
"php",
"python",
"django",
"osx",
"osx-leopard"
] |
Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac | 632,046 | <p>I've looked for other questions, but could not find any...</p>
<p>I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using <a href="http://localhost/" rel="nofollow">http://localhost/</a></p>
<p>I ... | 0 | 2009-03-10T20:07:13Z | 632,098 | <p>Why not try <a href="http://docs.djangoproject.com/en/dev/intro/install/#intro-install" rel="nofollow">the official installation instructions</a>? Really all you need to do is install Django. You can use its built-in server (<code>http://localhost:8000</code> by default) for testing:</p>
<pre><code>./manage.py runs... | 6 | 2009-03-10T20:19:07Z | [
"php",
"python",
"django",
"osx",
"osx-leopard"
] |
Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac | 632,046 | <p>I've looked for other questions, but could not find any...</p>
<p>I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using <a href="http://localhost/" rel="nofollow">http://localhost/</a></p>
<p>I ... | 0 | 2009-03-10T20:07:13Z | 632,122 | <p>10.5 comes with Apache installed by default System Preferences > Sharing > Web Sharing. </p>
<p>To enable Apache php module edit the Apache conf (/etc/Apache/httpd.conf) file and uncomment the php module line.</p>
<pre><code>LoadModule php5_module libexec/apache2/libphp5.so.
</code></pre>
<p>Restart Apache after ... | 0 | 2009-03-10T20:25:13Z | [
"php",
"python",
"django",
"osx",
"osx-leopard"
] |
Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac | 632,046 | <p>I've looked for other questions, but could not find any...</p>
<p>I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using <a href="http://localhost/" rel="nofollow">http://localhost/</a></p>
<p>I ... | 0 | 2009-03-10T20:07:13Z | 632,124 | <p>Okay. I'd just install MySQL from their site and stick with what's already on my Mac as of 10.5, then install Django and the Python MySQL driver. But since you like MAMP, install <a href="http://www.mamp.info/" rel="nofollow">MAMP</a> or <a href="http://www.apachefriends.org/en/xampp.html" rel="nofollow">XAMPP</a> a... | -1 | 2009-03-10T20:26:55Z | [
"php",
"python",
"django",
"osx",
"osx-leopard"
] |
Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac | 632,046 | <p>I've looked for other questions, but could not find any...</p>
<p>I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using <a href="http://localhost/" rel="nofollow">http://localhost/</a></p>
<p>I ... | 0 | 2009-03-10T20:07:13Z | 632,154 | <p>The fastest way to get started with Django, will be to use TurnKey linux Django appliance.</p>
<p>Link: <a href="http://www.turnkeylinux.org/appliances/django" rel="nofollow">http://www.turnkeylinux.org/appliances/django</a></p>
| 0 | 2009-03-10T20:34:50Z | [
"php",
"python",
"django",
"osx",
"osx-leopard"
] |
Looking to get started with Apache, PHP, MySQL, Python, Django on a fresh Mac | 632,046 | <p>I've looked for other questions, but could not find any...</p>
<p>I have freshly installed my Mac with OSX 10.5. I need to learn Python/Django for a new job, so want to set it all up correctly, ready to develop and run from my browser using <a href="http://localhost/" rel="nofollow">http://localhost/</a></p>
<p>I ... | 0 | 2009-03-10T20:07:13Z | 635,218 | <p>I also came from PHP a few months ago. I'm not sure if this will get moderated up or down because my answer changes your question:</p>
<ol>
<li>Do not use MySQL and Apache for local development on your Mac. Use Sqlite3 and the development server that is bundled with Django - this allows for inline debugging, etc..... | 0 | 2009-03-11T16:04:48Z | [
"php",
"python",
"django",
"osx",
"osx-leopard"
] |
Automatically fetching latest version of a file on import | 632,171 | <p>I have a module that I want to keep up to date, and I'm wondering if this is a bad idea: </p>
<blockquote>
<p>Have a module (mod1.py) in the
site-packages directory that copies a
different module from some other
location into the site-packages
directory, and then imports * from
that module.</p>
</blockq... | 1 | 2009-03-10T20:38:28Z | 632,196 | <p>Do you <em>really</em> want to do this? This means you could very easily roll code to a production app simply by committing to source control. I would consider this a nasty side-effect for someone who isn't aware of your setup.</p>
<p>That being said this seems like a pretty good solution - you may want to add so... | 2 | 2009-03-10T20:45:11Z | [
"python",
"version-control",
"visual-sourcesafe"
] |
Automatically fetching latest version of a file on import | 632,171 | <p>I have a module that I want to keep up to date, and I'm wondering if this is a bad idea: </p>
<blockquote>
<p>Have a module (mod1.py) in the
site-packages directory that copies a
different module from some other
location into the site-packages
directory, and then imports * from
that module.</p>
</blockq... | 1 | 2009-03-10T20:38:28Z | 632,594 | <p>In some cases, we put <code>.pth</code> files in the Python site-packages directory. The <code>.pth</code> files name our various SVN checkout directories. </p>
<p>No install. No copy.</p>
<p><code>.pth</code> files are described <a href="http://docs.python.org/library/site.html#module-site" rel="nofollow">here<... | 1 | 2009-03-10T22:49:36Z | [
"python",
"version-control",
"visual-sourcesafe"
] |
Automatically fetching latest version of a file on import | 632,171 | <p>I have a module that I want to keep up to date, and I'm wondering if this is a bad idea: </p>
<blockquote>
<p>Have a module (mod1.py) in the
site-packages directory that copies a
different module from some other
location into the site-packages
directory, and then imports * from
that module.</p>
</blockq... | 1 | 2009-03-10T20:38:28Z | 633,065 | <p>The original strategy of having other developers copy mod1.py into their site-packages in order to use the module sounds like it's the real problem. Why aren't they just using the same source control are you are?</p>
<p>This auto-copying will make it hard to do rollbacks, especially if other developers copy your st... | 0 | 2009-03-11T02:03:18Z | [
"python",
"version-control",
"visual-sourcesafe"
] |
How to debug a file upload? | 632,577 | <p>I'm trying to upload a PDF file to a website using Hot Banana's content management system using a Python script. I've successfully logged into the site and can log out, but I can't seem to get file uploads to work. </p>
<p>The file upload is part of a large complicated web form that submits the form data and PDF ... | 1 | 2009-03-10T22:43:51Z | 633,045 | <p>You might be better off instrumenting the server to see why this is failing, rather than trying to debug this on the client side.</p>
| 0 | 2009-03-11T01:54:55Z | [
"python",
"post",
"upload",
"urllib2"
] |
How to debug a file upload? | 632,577 | <p>I'm trying to upload a PDF file to a website using Hot Banana's content management system using a Python script. I've successfully logged into the site and can log out, but I can't seem to get file uploads to work. </p>
<p>The file upload is part of a large complicated web form that submits the form data and PDF ... | 1 | 2009-03-10T22:43:51Z | 633,252 | <p>A tool like <a href="http://www.wireshark.org/" rel="nofollow">WireShark</a> will give you a more complete trace at a much lower-level than the firefox plugins.</p>
<p>Often this can be something as simple as not setting the content-type correctly, or failing to include content-length.</p>
| 1 | 2009-03-11T03:42:05Z | [
"python",
"post",
"upload",
"urllib2"
] |
How to debug a file upload? | 632,577 | <p>I'm trying to upload a PDF file to a website using Hot Banana's content management system using a Python script. I've successfully logged into the site and can log out, but I can't seem to get file uploads to work. </p>
<p>The file upload is part of a large complicated web form that submits the form data and PDF ... | 1 | 2009-03-10T22:43:51Z | 634,440 | <p><strong>"What's a good way to debug [a web services] process?"</strong></p>
<p><em>At the moment, I'm just dumping out the urllib2 response to a text file and examining the output to see if it matches what I get when I do a file upload manually.</em></p>
<p>Correct. That's about all there is.</p>
<p>HTTP is a ve... | 0 | 2009-03-11T13:09:28Z | [
"python",
"post",
"upload",
"urllib2"
] |
Nested loop syntax in python server pages | 632,624 | <p>I am just trying to write a small web page that can parse some text using a regular expression and return the resulting matches in a table. This is the first I've used python for web development, and I have to say, it looks messy.</p>
<p>My question is why do I only get output for the last match in my data set? I f... | 1 | 2009-03-10T23:00:48Z | 632,664 | <p>I'm not sure about the interaction with the templating engine, but python would expect the inner loop to be indented under the containing loop.</p>
<p>Try formatting it that way and see if it works.</p>
<pre><code><%
for match in matches:
%><tr><%
for i in range(1, len(match.groups())+1):
... | 0 | 2009-03-10T23:15:05Z | [
"python",
"python-server-pages"
] |
Nested loop syntax in python server pages | 632,624 | <p>I am just trying to write a small web page that can parse some text using a regular expression and return the resulting matches in a table. This is the first I've used python for web development, and I have to say, it looks messy.</p>
<p>My question is why do I only get output for the last match in my data set? I f... | 1 | 2009-03-10T23:00:48Z | 632,732 | <pre><code><%
for match in matches:
#begin
%><tr>
<%
for i in range(1, len(match.groups())+1):
#begin
%>
<td style="border-style:solid;border-width:1px;border-spacing:0px;text-align:center;"><%= match.group(i) %></td>
<%
#end
# end
%>
</code></pre>
<p>Yeah, you haven't... | 1 | 2009-03-10T23:47:44Z | [
"python",
"python-server-pages"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 632,738 | <p>Yes, I do think that Python would be a good replacement. I understand that the <a href="http://twistedmatrix.com/trac/" rel="nofollow" title="Twisted">Twisted</a> Python framework is quite popular.</p>
| 9 | 2009-03-10T23:50:47Z | [
"python",
"c"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 632,740 | <p>Assuming that you have control over the environment which this application will run, and that the performance of interpreted language (python) compared to a compiled one (C) can be ignored, I believe Python is a great choice for this.</p>
| 1 | 2009-03-10T23:51:08Z | [
"python",
"c"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 632,788 | <p>I'd say that if:</p>
<ul>
<li>Your C code contains no platform specific requirements</li>
<li>You are sure speed is not going to be an issue going from C to python</li>
<li>You have a desire to not compile anymore</li>
<li>You would like to try utilise exception handling</li>
<li>You want to dabble in OO</li>
<li>Y... | 4 | 2009-03-11T00:09:10Z | [
"python",
"c"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 632,844 | <p>If I was faced with a similar situation I'd ask myself a couple of questions:</p>
<ul>
<li>Is there anything more important I could be working on?</li>
<li>Does Python bring anything to the table that is currently handled poorly by the current application?</li>
<li>Will this allow me to add functionality that was p... | 1 | 2009-03-11T00:29:27Z | [
"python",
"c"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 632,925 | <p>Remember as well, you can leave parts of your program in C, turn them into Python modules and build python code around them - you don't need to re-write everything up-front.</p>
| 2 | 2009-03-11T00:53:28Z | [
"python",
"c"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 632,935 | <p>Yes, I think Python is a good choice, if all your platforms support it. Since this is a network program, I'm assuming the network is your runtime bottleneck? That's likely to still be the case in Python. If you really do need to speed it up, you can include your long-since-debugged, speedy C as Python modules.</p... | 1 | 2009-03-11T00:57:10Z | [
"python",
"c"
] |
What is the feasibility of porting a legacy C program to Python? | 632,730 | <p>I have a program in C that communicates via UDP with another program (in Java) and then does process manipulation (start/stop) based on the UDP pkt exchange.
Now this C program has been legacy and I want to convert it to Python - do you think Python will be a good choice for the tasks mentioned?</p>
| 2 | 2009-03-10T23:47:15Z | 634,093 | <p>If this is an embedded program, then it might be a problem to port it since Python programs typically rely on the Python runtime and library, and those are fairly large. Especially when compared to a C program doing a well-defined task. Of course, it's likely you've already considered that aspect, but I wanted to me... | 0 | 2009-03-11T11:08:30Z | [
"python",
"c"
] |
Python, Evaluate a Variable value as a Variable | 632,856 | <p>I'd like to do something like below: particularly the 'f.eval(field)' part, such that it evaluates the value of the variable as the field name. How does one accomplish this in Python?</p>
<pre><code>def punctuated_object_list(objects, field):
field_list = [f.eval(field) for f in objects]
if len(field_list)... | 4 | 2009-03-11T00:31:50Z | 632,869 | <p><code>getattr(f, field)</code>, if I understand you correctly (that is, if you might have <code>field = "foo"</code>, and want <code>f.foo</code>). If not, you might want to clarify. Python has an <code>eval()</code>, and I don't know what other languages' <code>eval()</code> you want the equivalent of.</p>
| 11 | 2009-03-11T00:35:09Z | [
"python"
] |
Python, Evaluate a Variable value as a Variable | 632,856 | <p>I'd like to do something like below: particularly the 'f.eval(field)' part, such that it evaluates the value of the variable as the field name. How does one accomplish this in Python?</p>
<pre><code>def punctuated_object_list(objects, field):
field_list = [f.eval(field) for f in objects]
if len(field_list)... | 4 | 2009-03-11T00:31:50Z | 632,880 | <p>The python equivalent of <code>eval()</code> is <code>eval()</code></p>
<pre><code>x = 9
eval("x*2")
</code></pre>
<p>will give you 18.</p>
<pre><code>v = "x"
eval(v+"*2")
</code></pre>
<p>works too.</p>
| 0 | 2009-03-11T00:37:43Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.