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 |
|---|---|---|---|---|---|---|---|---|---|
Should I create mapper objects or use the declarative syntax in SQLAlchemy? | 1,453,219 | <p>There are two (three, but I'm not counting <a href="http://elixir.ematia.de/trac/wiki">Elixir</a>, as its not "official") ways to define a persisting object with <a href="http://www.sqlalchemy.org">SQLAlchemy</a>:</p>
<h3><a href="http://www.sqlalchemy.org/docs/05/mappers.html">Explicit syntax for mapper objects</a... | 32 | 2009-09-21T07:19:43Z | 1,454,641 | <p>I've found that using mapper objects are much simpler then declarative syntax if you use <a href="http://packages.python.org/sqlalchemy-migrate/">sqlalchemy-migrate</a> to version your database schema (and this is a must-have for a business application from my point of view). If you are using mapper objects you can ... | 5 | 2009-09-21T13:56:29Z | [
"python",
"sqlalchemy"
] |
Python HTTPS client with basic authentication via proxy | 1,453,264 | <p>From Python, I would like to retrieve content from a web site via HTTPS with basic authentication. I need the content on disk. I am on an intranet, trusting the HTTPS server. Platform is Python 2.6.2 on Windows.</p>
<p>I have been playing around with urllib2, however did not succeed so far.</p>
<p>I have a solutio... | 3 | 2009-09-21T07:35:48Z | 1,453,303 | <p>Try this (notice that you'll have to fill in the realm of your server also):</p>
<pre><code>import urllib2
authinfo = urllib2.HTTPBasicAuthHandler()
authinfo.add_password(realm='Fill In Realm Here',
uri='https://fqdn.to.site/content',
user='username',
... | 3 | 2009-09-21T07:50:23Z | [
"python",
"proxy",
"https",
"basic-authentication"
] |
Python HTTPS client with basic authentication via proxy | 1,453,264 | <p>From Python, I would like to retrieve content from a web site via HTTPS with basic authentication. I need the content on disk. I am on an intranet, trusting the HTTPS server. Platform is Python 2.6.2 on Windows.</p>
<p>I have been playing around with urllib2, however did not succeed so far.</p>
<p>I have a solutio... | 3 | 2009-09-21T07:35:48Z | 1,453,341 | <p>Proxy and https wasn't working <a href="http://bugs.python.org/issue1424152" rel="nofollow">for a long time</a> with urllib2. It will be fixed in the next released version of python 2.6 (v2.6.3).</p>
<p>In the meantime you can reimplement the correct support, that's what we did for mercurial: <a href="http://hg.int... | 3 | 2009-09-21T08:02:17Z | [
"python",
"proxy",
"https",
"basic-authentication"
] |
Python HTTPS client with basic authentication via proxy | 1,453,264 | <p>From Python, I would like to retrieve content from a web site via HTTPS with basic authentication. I need the content on disk. I am on an intranet, trusting the HTTPS server. Platform is Python 2.6.2 on Windows.</p>
<p>I have been playing around with urllib2, however did not succeed so far.</p>
<p>I have a solutio... | 3 | 2009-09-21T07:35:48Z | 3,468,220 | <p>You could try this too:
<a href="http://code.google.com/p/python-httpclient/" rel="nofollow">http://code.google.com/p/python-httpclient/</a></p>
<p>(It also supports the verification of the server certificate.)</p>
| 0 | 2010-08-12T13:36:27Z | [
"python",
"proxy",
"https",
"basic-authentication"
] |
Django: use archive_index with date_field from a related model | 1,453,465 | <p>Hello (please excuse me for my ugly english :p),</p>
<p>Imagine these two simple models :</p>
<pre><code>from django.contrib.contenttypes import generic
from django.db import models
class SomeModel(models.Model):
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField(_('obje... | 1 | 2009-09-21T08:45:44Z | 1,455,589 | <p>From digging through the Django source code, the generic view <code>archive_index</code> does not appear to support related fields that are <code>GenericRelation</code>s.</p>
<p>This is because the queryset method <code>dates</code> does not support generic relations. Consider filing this as a bug / feature request... | 1 | 2009-09-21T17:01:03Z | [
"python",
"django",
"django-models",
"django-views",
"django-generic-views"
] |
How to markup form fields with <div class='field_type'> in Django | 1,453,488 | <p>I wasn't able to find a way to identify the type of a field in a django template. My solution was to create a simple filter to access the field and widget class names. I've included the code below in case it's helpful for someone else.</p>
<p>Is there a better approach?</p>
<pre><code>## agency/tagutils/template... | 6 | 2009-09-21T08:53:04Z | 1,504,903 | <pre><code>class MyForm(forms.Form):
myfield = forms.CharField(widget=forms.TextInput(attrs={'class' : 'myfieldclass'}))
</code></pre>
<p>or, with a ModelForm</p>
<pre><code>class MyForm(forms.ModelForm):
class Meta:
model = MyModel
widgets = {
'myfield': forms.TextInput(attrs={'cl... | 16 | 2009-10-01T16:08:35Z | [
"python",
"django",
"django-forms",
"django-templates",
"django-models"
] |
How to filter query in sqlalchemy by year (datetime column) | 1,453,591 | <p>I have table in sqlalchemy 0.4 that with types.DateTime column:</p>
<pre><code>Column("dfield", types.DateTime, index=True)
</code></pre>
<p>I want to select records, that has specific year in this column, using model. How to do this?
I though it should be done like this:</p>
<pre><code>selected_year = 2009
my_se... | 12 | 2009-09-21T09:23:09Z | 1,453,610 | <p>sqlalchemy.extract('year', model.MyRecord.dfield) == selected_year</p>
| 18 | 2009-09-21T09:27:11Z | [
"python",
"sqlalchemy"
] |
Django: queryset filter for *all* values from a ManyToManyField | 1,453,662 | <p>Hi (sorry for my bad english :p)</p>
<p>Imagine these models :</p>
<pre><code>class Fruit(models.Model):
# ...
class Basket(models.Model):
fruits = models.ManyToManyField(Fruit)
</code></pre>
<p>Now I would like to retrieve Basket instances related to <em>all</em> fruits.
The problem is that the code bel... | 2 | 2009-09-21T09:43:44Z | 1,453,736 | <p>I don't have a dataset handy to test this, but I think it should work:</p>
<pre><code>Basket.objects.annotate(num_fruits=Count('fruits')).filter(num_fruits=len(Fruit.objects.all()))
</code></pre>
<p>It annotates every basket object with the count of related fruits and filters out those baskets that have a fruit co... | 5 | 2009-09-21T10:02:33Z | [
"python",
"sql",
"django",
"django-models",
"django-queryset"
] |
ctypes memory management: how and when free the allocated resources? | 1,453,776 | <p>I'm writing a small wrapper for a C library in Python with Ctypes, and I don't know if the structures allocated from Python will be automatically freed when they're out of scope.</p>
<p>Example:</p>
<pre><code>from ctypes import *
mylib = cdll.LoadLibrary("mylib.so")
class MyPoint(Structure):
_fields_ = [("x"... | 7 | 2009-09-21T10:12:19Z | 1,453,822 | <p>In this case your <code>MyPoint</code> instance is a Python object allocated on the Python heap, so there should be no need to treat it differently from any other Python object. If, on the other hand, you got the <code>MyPoint</code> instance by calling say <code>allocate_point()</code> in <code>mylib.so</code>, the... | 3 | 2009-09-21T10:24:42Z | [
"python",
"c",
"memory",
"ctypes"
] |
python error "list indices must be integers" , they ARE integers | 1,453,882 | <p>I am having a problem. I have an array of 31 elements called colors. I also have another array with integer numbers that vary between 0 and 31, this is called c. I want to produce a new array where the values in c are now the corresponding values in colors.</p>
<p>I write:</p>
<blockquote>
<blockquote>
<p>ne... | 4 | 2009-09-21T10:39:25Z | 1,453,925 | <p>array of integers != integer</p>
<p>list indices must be integers - you've given a list of integers.</p>
<p>You probably want a list comprehension:</p>
<pre><code>newarray = [ colors[i] for i in c ]
</code></pre>
<p>But you really ought to learn the language properly before using it. It's not like python takes a... | 12 | 2009-09-21T10:47:02Z | [
"python"
] |
python error "list indices must be integers" , they ARE integers | 1,453,882 | <p>I am having a problem. I have an array of 31 elements called colors. I also have another array with integer numbers that vary between 0 and 31, this is called c. I want to produce a new array where the values in c are now the corresponding values in colors.</p>
<p>I write:</p>
<blockquote>
<blockquote>
<p>ne... | 4 | 2009-09-21T10:39:25Z | 1,453,933 | <p>Python does not support arbitrary list indexing. You can use single integer index like c[4] or slice like c[4:10]. <a href="http://www.scipy.org/SciPy" rel="nofollow">SciPy</a> library has richer indexing capabilities. Or just use list comprehensions as Douglas Leeder advices.</p>
| 1 | 2009-09-21T10:48:52Z | [
"python"
] |
python error "list indices must be integers" , they ARE integers | 1,453,882 | <p>I am having a problem. I have an array of 31 elements called colors. I also have another array with integer numbers that vary between 0 and 31, this is called c. I want to produce a new array where the values in c are now the corresponding values in colors.</p>
<p>I write:</p>
<blockquote>
<blockquote>
<p>ne... | 4 | 2009-09-21T10:39:25Z | 1,454,335 | <p>Okay, I think I know what you are after...</p>
<p>So you have your list of 31 colours. Say for argument it is a list of 31 strings like this...</p>
<pre><code>colours = [ "Black", "DarkBlue", "DarkGreen", ... "White" ]
</code></pre>
<p>And 'c' is an array of numbers in the range 0 to 31, but in random order...</p... | 1 | 2009-09-21T12:45:21Z | [
"python"
] |
python error "list indices must be integers" , they ARE integers | 1,453,882 | <p>I am having a problem. I have an array of 31 elements called colors. I also have another array with integer numbers that vary between 0 and 31, this is called c. I want to produce a new array where the values in c are now the corresponding values in colors.</p>
<p>I write:</p>
<blockquote>
<blockquote>
<p>ne... | 4 | 2009-09-21T10:39:25Z | 1,454,429 | <p>This is your code: (from your comment)</p>
<pre><code>from pylab import*
f=open("transformdata.txt")
x=f.readlines()
a=[y.split('\t')[0] for y in x]
b=[y.split('\t')[1] for y in x]
c=[y.split('\t')[2] for y in x] # this line is probably the problem
subplot(111,projection="hammer")
colors=['#FFFF00']*31
newar... | 2 | 2009-09-21T13:07:29Z | [
"python"
] |
Is it possible to use django Piston on Google AppEngine? | 1,453,909 | <p>I haven't been able to do so due to all sort of missing dependencies (mainly, I think the problem is in the authentication code which relies on django stuff that is not available on AppEngine)</p>
<p>I was wondering if anyone patched\forked piston to get it working on AppEngine?</p>
| 5 | 2009-09-21T10:44:35Z | 1,454,771 | <p><a href="http://bitbucket.org/gumptioncom/django-piston-app-engine/" rel="nofollow" rel="nofollow">http://bitbucket.org/gumptioncom/django-piston-app-engine/</a></p>
| 5 | 2009-09-21T14:20:20Z | [
"python",
"django",
"google-app-engine",
"django-piston"
] |
Is it possible to use django Piston on Google AppEngine? | 1,453,909 | <p>I haven't been able to do so due to all sort of missing dependencies (mainly, I think the problem is in the authentication code which relies on django stuff that is not available on AppEngine)</p>
<p>I was wondering if anyone patched\forked piston to get it working on AppEngine?</p>
| 5 | 2009-09-21T10:44:35Z | 1,491,297 | <p>It turns out the problem with Piston and AppEngine is mainly when it comes to the authentication code.
So, I managed to port Piston to AppEngine doing the following:</p>
<ol>
<li>I'm using the <a href="http://code.google.com/p/app-engine-patch/" rel="nofollow">app-engine-patch</a> project which integrates django's ... | 2 | 2009-09-29T08:37:24Z | [
"python",
"django",
"google-app-engine",
"django-piston"
] |
Is it possible to use django Piston on Google AppEngine? | 1,453,909 | <p>I haven't been able to do so due to all sort of missing dependencies (mainly, I think the problem is in the authentication code which relies on django stuff that is not available on AppEngine)</p>
<p>I was wondering if anyone patched\forked piston to get it working on AppEngine?</p>
| 5 | 2009-09-21T10:44:35Z | 1,561,747 | <p>I've forked django-oauth, to make it compatible with app-engine-patch. So it could eventually be used with <a href="http://bitbucket.org/gumptioncom/django-piston-app-engine/" rel="nofollow">django-piston-app-engine</a>.</p>
<p><a href="http://bitbucket.org/mtourne/django-oauth-appengine/" rel="nofollow">http://bit... | 1 | 2009-10-13T17:31:20Z | [
"python",
"django",
"google-app-engine",
"django-piston"
] |
Python: Does a dict value pointer store its key? | 1,454,437 | <p>I'm wondering if there is a built-in way to do this... Take this simple code for example:</p>
<pre><code>D = {'one': objectA(), 'two': objectB(), 'three': objectC()}
object_a = D['one']
</code></pre>
<p>I believe <code>object_a</code> is just pointing at the <code>objectA()</code> created on the first line, and kn... | 2 | 2009-09-21T13:09:43Z | 1,454,441 | <p>I think no.</p>
<p>Consider the case of adding a single object to a (large) number of different dictionaries. It would become quite expensive for Python to track that for you, it would cost a lot for a feature not used by most.</p>
| 7 | 2009-09-21T13:10:53Z | [
"python",
"dictionary"
] |
Python: Does a dict value pointer store its key? | 1,454,437 | <p>I'm wondering if there is a built-in way to do this... Take this simple code for example:</p>
<pre><code>D = {'one': objectA(), 'two': objectB(), 'three': objectC()}
object_a = D['one']
</code></pre>
<p>I believe <code>object_a</code> is just pointing at the <code>objectA()</code> created on the first line, and kn... | 2 | 2009-09-21T13:09:43Z | 1,454,475 | <p>The <code>dict</code> mapping is not trivially "reversible" as you describe.</p>
<ol>
<li><p>The key must be immutable. It must be immutable so that it can be hashed for lookup and not suffer spontaneous changes.</p></li>
<li><p>The value does not have to be immutable, it is not hashed for quick lookup. </p></li>... | 3 | 2009-09-21T13:19:59Z | [
"python",
"dictionary"
] |
Python: Does a dict value pointer store its key? | 1,454,437 | <p>I'm wondering if there is a built-in way to do this... Take this simple code for example:</p>
<pre><code>D = {'one': objectA(), 'two': objectB(), 'three': objectC()}
object_a = D['one']
</code></pre>
<p>I believe <code>object_a</code> is just pointing at the <code>objectA()</code> created on the first line, and kn... | 2 | 2009-09-21T13:09:43Z | 1,454,702 | <blockquote>
<p>Is there a way to get the Key 'one' if
all you have is the variable object_a
(without looping over the dictionary,
of course)?</p>
</blockquote>
<p>No, Python imposes no such near-useless redundancy on you. If <code>objA</code> is a factory callable:</p>
<pre><code>d = {'zap': objA()}
a = d['... | 2 | 2009-09-21T14:08:40Z | [
"python",
"dictionary"
] |
Python: Does a dict value pointer store its key? | 1,454,437 | <p>I'm wondering if there is a built-in way to do this... Take this simple code for example:</p>
<pre><code>D = {'one': objectA(), 'two': objectB(), 'three': objectC()}
object_a = D['one']
</code></pre>
<p>I believe <code>object_a</code> is just pointing at the <code>objectA()</code> created on the first line, and kn... | 2 | 2009-09-21T13:09:43Z | 1,456,611 | <p>Like others have said, there is no built-in way to do this, since it takes up memory and is not usually needed.</p>
<blockquote>
<p>If not, I can store the value 'one' inside objectA(), but I'm just curious if Python already stores that info.</p>
</blockquote>
<p>Just wanted to add that it should be pretty easy ... | 0 | 2009-09-21T20:17:35Z | [
"python",
"dictionary"
] |
do properties work on django model fields? | 1,454,727 | <p>I think the best way to ask this question is with some code... can I do this? (<strong>edit</strong>: ANSWER: no)</p>
<del><pre><code>
class MyModel(models.Model):
foo = models.CharField(max_length = 20)
bar = models.CharField(max_length = 20)
def get_foo(self):
... | 25 | 2009-09-21T14:13:17Z | 1,454,856 | <p>A model field is already property, so I would say you have to do it the second way to avoid a name clash.</p>
<p>When you define foo = property(..) it actually overrides the foo = models.. line, so that field will no longer be accessible.</p>
<p>You will need to use a different name for the property and the field.... | 12 | 2009-09-21T14:39:02Z | [
"python",
"django",
"properties",
"models"
] |
do properties work on django model fields? | 1,454,727 | <p>I think the best way to ask this question is with some code... can I do this? (<strong>edit</strong>: ANSWER: no)</p>
<del><pre><code>
class MyModel(models.Model):
foo = models.CharField(max_length = 20)
bar = models.CharField(max_length = 20)
def get_foo(self):
... | 25 | 2009-09-21T14:13:17Z | 12,358,707 | <p>As mentioned, a correct alternative to implementing your own django.db.models.Field class, one should use - <strong>db_column</strong> argument and a custom (or hidden) class attribute. I am just rewriting the code in the edit by @Jiaaro following more strict conventions for OOP in python (e.g. if _foo should be act... | 10 | 2012-09-10T20:08:16Z | [
"python",
"django",
"properties",
"models"
] |
do properties work on django model fields? | 1,454,727 | <p>I think the best way to ask this question is with some code... can I do this? (<strong>edit</strong>: ANSWER: no)</p>
<del><pre><code>
class MyModel(models.Model):
foo = models.CharField(max_length = 20)
bar = models.CharField(max_length = 20)
def get_foo(self):
... | 25 | 2009-09-21T14:13:17Z | 33,899,883 | <p>The previous solutions suffer because @property causes problems in admin, and .filter(_foo). </p>
<p>A better solution would be to override <strong>setattr</strong> except that this can cause problems initializing the ORM object from the DB. However, there is a trick to get around this, and it's universal.</p>
<... | 2 | 2015-11-24T17:16:12Z | [
"python",
"django",
"properties",
"models"
] |
Allowing user to rollback from db audit trail with SQLAlchemy | 1,454,874 | <p>I'm starting to use SQLAlchemy for a new project where I was planning to implement an audit trail similar to the one proposed on this quiestions:<sub></p>
<ul>
<li><a href="http://stackoverflow.com/questions/328898/implementing-audit-trail-for-objects-in-c">http://stackoverflow.com/questions/328898/implementing-aud... | 4 | 2009-09-21T14:42:21Z | 1,455,056 | <p>Although I haven't used SQLAlchemy specifically, I can give you some general tips that can be easily implemented in any ORM:</p>
<ul>
<li>Separate out the versioned item into two tables, say <code>Document</code> and <code>DocumentVersion</code>. <code>Document</code> stores information that will never change betwe... | 7 | 2009-09-21T15:18:37Z | [
"python",
"sqlalchemy",
"audit",
"rollback"
] |
Flow control in threading.Thread | 1,454,941 | <p>I Have run into a few examples of managing threads with the threading module (using Python 2.6).</p>
<p>What I am trying to understand is how is this example calling the "run" method and where. I do not see it anywhere. The ThreadUrl class gets instantiated in the main() function as "t" and this is where I would no... | 3 | 2009-09-21T14:56:40Z | 1,454,967 | <p>The method run() is called behind the scene by "threading.Thread" (Google inheritance and polymorphism concepts of OOP). The invocation will be done just after t.start() has called.</p>
<p>If you have an access to threading.py (find it in python folder). You will see a class name Thread. In that class, there is a m... | 4 | 2009-09-21T15:00:47Z | [
"python",
"multithreading",
"control",
"flow"
] |
Flow control in threading.Thread | 1,454,941 | <p>I Have run into a few examples of managing threads with the threading module (using Python 2.6).</p>
<p>What I am trying to understand is how is this example calling the "run" method and where. I do not see it anywhere. The ThreadUrl class gets instantiated in the main() function as "t" and this is where I would no... | 3 | 2009-09-21T14:56:40Z | 1,454,989 | <p><code>t.start()</code> creates a new thread in the OS and when this thread begins it will call the thread's <code>run()</code> method (or a different function if you provide a <code>target</code> in the <code>Thread</code> constructor)</p>
| 0 | 2009-09-21T15:04:43Z | [
"python",
"multithreading",
"control",
"flow"
] |
Flow control in threading.Thread | 1,454,941 | <p>I Have run into a few examples of managing threads with the threading module (using Python 2.6).</p>
<p>What I am trying to understand is how is this example calling the "run" method and where. I do not see it anywhere. The ThreadUrl class gets instantiated in the main() function as "t" and this is where I would no... | 3 | 2009-09-21T14:56:40Z | 1,455,015 | <p>Per the <a href="http://docs.python.org/library/threading.html#threading.Thread.start">pydoc</a>:</p>
<blockquote>
<p><code>Thread.start()</code></p>
<p>Start the threadâs activity.</p>
<p>It must be called at most once per thread object. It arranges for the
objectâs run() method to be invoked in
... | 7 | 2009-09-21T15:11:17Z | [
"python",
"multithreading",
"control",
"flow"
] |
How to define properties in __init__ | 1,454,984 | <p>I whish to define properties in a class from a member function.
Below is some test code showing how I would like this to work. However I don't get the expected behaviour.</p>
<pre><code>class Basket(object):
def __init__(self):
# add all the properties
for p in self.PropNames():
setattr(self, p, pr... | 4 | 2009-09-21T15:04:02Z | 1,455,009 | <p>You need to set the properties on the class (ie: <code>self.__class__</code>), not on the object (ie: <code>self</code>). For example:</p>
<pre><code>class Basket(object):
def __init__(self):
# add all the properties
setattr(self.__class__, 'Apple', property(lambda s : 'Apple') )
setattr(self.__class... | 9 | 2009-09-21T15:10:31Z | [
"python",
"properties",
"constructor"
] |
How to define properties in __init__ | 1,454,984 | <p>I whish to define properties in a class from a member function.
Below is some test code showing how I would like this to work. However I don't get the expected behaviour.</p>
<pre><code>class Basket(object):
def __init__(self):
# add all the properties
for p in self.PropNames():
setattr(self, p, pr... | 4 | 2009-09-21T15:04:02Z | 1,455,051 | <p>This does what you wanted:</p>
<pre><code>class Basket(object):
def __init__(self):
# add all the properties
def make_prop( name ):
def getter( self ):
return "I'm a " + name
return property(getter)
for p in self.PropNames():
setattr(Basket, p, make_prop(p) )
d... | 3 | 2009-09-21T15:18:10Z | [
"python",
"properties",
"constructor"
] |
How to define properties in __init__ | 1,454,984 | <p>I whish to define properties in a class from a member function.
Below is some test code showing how I would like this to work. However I don't get the expected behaviour.</p>
<pre><code>class Basket(object):
def __init__(self):
# add all the properties
for p in self.PropNames():
setattr(self, p, pr... | 4 | 2009-09-21T15:04:02Z | 1,455,178 | <p>Why are you defining properties at <code>__init__</code> time? It's confusing and clever, so you better have a really good reason. The loop problem that Stef pointed out is just one example of why this should be avoided.</p>
<p>If you need to redifine which properties a subclass has, you can just do <code>del self.... | 1 | 2009-09-21T15:39:25Z | [
"python",
"properties",
"constructor"
] |
What's a Django/Python solution for providing a one-time url for people to download files? | 1,455,109 | <p>I'm looking for a way to sell someone a card at an event that will have a unique code that they will be able to use later in order to download a file (mp3, pdf, etc.) only one time and mask the true file location so a savvy person downloading the file won't be able to download the file more than once. It would be ni... | 4 | 2009-09-21T15:27:59Z | 1,455,194 | <p>You can just use something simple such as <a href="http://tn123.ath.cx/mod%5Fxsendfile/" rel="nofollow">mod_xsendfile</a>. This functionality is also available in other popular webservers such <a href="http://blog.lighttpd.net/articles/2006/07/02/x-sendfile" rel="nofollow">lighttpd</a> or <a href="http://kovyrin.net... | 2 | 2009-09-21T15:41:59Z | [
"python",
"django",
"url",
"proxy",
"download"
] |
What's a Django/Python solution for providing a one-time url for people to download files? | 1,455,109 | <p>I'm looking for a way to sell someone a card at an event that will have a unique code that they will be able to use later in order to download a file (mp3, pdf, etc.) only one time and mask the true file location so a savvy person downloading the file won't be able to download the file more than once. It would be ni... | 4 | 2009-09-21T15:27:59Z | 1,455,393 | <p>Neat idea. However, I would warn against the single-download method, because there is no guarantee that their first download attempt will be successful. Perhaps use a time-expiration method instead?</p>
<p>But it is certainly possible to do this with Django. Here is an outline of the basic approach:</p>
<ul>
<li>S... | 3 | 2009-09-21T16:20:04Z | [
"python",
"django",
"url",
"proxy",
"download"
] |
How to set ignorecase flag for part of regular expression in Python? | 1,455,160 | <p>Is it possible to implement in Python something like this simple one:</p>
<pre><code>#!/usr/bin/perl
my $a = 'Use HELLO1 code';
if($a =~ /(?i:use)\s+([A-Z0-9]+)\s+(?i:code)/){
print "$1\n";
}
</code></pre>
<p>Letters of token in the middle of string are always capital. Letters of the rest of words can have any... | 2 | 2009-09-21T15:35:55Z | 1,455,195 | <p><a href="http://docs.python.org/library/re.html" rel="nofollow">According to the docs</a>, this is not possible. The <code>(?x)</code> syntax only allows you to modify a flag for the whole expression. Therefore, you must split this into three regexp and apply them one after the other <em>or</em> do the "ignore case"... | 2 | 2009-09-21T15:41:59Z | [
"python",
"regex"
] |
How to set ignorecase flag for part of regular expression in Python? | 1,455,160 | <p>Is it possible to implement in Python something like this simple one:</p>
<pre><code>#!/usr/bin/perl
my $a = 'Use HELLO1 code';
if($a =~ /(?i:use)\s+([A-Z0-9]+)\s+(?i:code)/){
print "$1\n";
}
</code></pre>
<p>Letters of token in the middle of string are always capital. Letters of the rest of words can have any... | 2 | 2009-09-21T15:35:55Z | 1,455,303 | <p>As far as I could find, the python regular expression engine does not support partial ignore-case. Here is a solution using a case-insensitive regular expression, which then tests if the token is uppercase afterward.</p>
<pre><code>#! /usr/bin/env python
import re
token_re = re.compile(r'use\s+([a-z0-9]+)\s+code'... | 7 | 2009-09-21T16:01:10Z | [
"python",
"regex"
] |
Python-based Gallery web applications? | 1,455,224 | <p>I'm trying to cut my last dependencies on PHP and MySQL. The last stumbling block is a image gallery I set up for a client a while ago. The whole website is built around <a href="http://www.djangoproject.com/">Django</a> and <a href="http://zine.pocoo.org/">Zine</a>, except for the image gallery, which is based on <... | 6 | 2009-09-21T15:46:55Z | 1,455,282 | <p>There is <a href="http://code.google.com/p/django-photo-gallery">django-photo-gallery</a>, <a href="http://bitbucket.org/kmike/django-photo-albums/">django photo album</a> and another <a href="http://www.ohloh.net/p/django-photo-gallery">django-photo-gallery</a> (don't know if its the same one.)</p>
<p>Anything els... | 7 | 2009-09-21T15:58:34Z | [
"python",
"web-applications",
"gallery"
] |
refer to map via. maps() action in python/ pylonshq | 1,455,446 | <p>I just started to learn python, and i'm totally new and n00b. Normally i work with php.
I choose to use this framework: <a href="http://pylonshq.com/" rel="nofollow">http://pylonshq.com/</a></p>
<p>I have created an map called ajax in my controller map.
now i just need my "htaccees" file to find the ajax map. </p... | 1 | 2009-09-21T16:28:15Z | 1,468,043 | <p>solution :</p>
<p><a href="http://pylonshq.com/docs/en/0.9.7/configuration/" rel="nofollow">http://pylonshq.com/docs/en/0.9.7/configuration/</a></p>
<p>this is how it works-><br />
$ paster controller ajax/ajax_load</p>
| 0 | 2009-09-23T19:13:20Z | [
"python",
"pylons"
] |
FFMPEG and Pythons subprocess | 1,455,532 | <p>I'm trying to write a gui for <code>FFMPEG</code>. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conversion, whether it failed or not etc. I figured I could do this by accessing the process's stdout like so:</p... | 6 | 2009-09-21T16:49:40Z | 1,455,541 | <p><strong>FFMPEG:</strong></p>
<p>FFMPEG output all the status text (what you see when you run it manually on the command line) on the stderr interface. In order to capture output from ffmpeg, you need to be watching the stderr interface - or redirecting it like the example.</p>
<p><strong>Check for output on stder... | -1 | 2009-09-21T16:53:00Z | [
"python",
"ffmpeg",
"subprocess"
] |
FFMPEG and Pythons subprocess | 1,455,532 | <p>I'm trying to write a gui for <code>FFMPEG</code>. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conversion, whether it failed or not etc. I figured I could do this by accessing the process's stdout like so:</p... | 6 | 2009-09-21T16:49:40Z | 1,455,726 | <p>I've often noticed problems reading standard output (or even standard error!) with subprocess, due to buffering issues that are hard to defeat. My favorite solution, when I do need to read such stdout/stderr from the subprocess, is to switch to using, instead of <code>subprocess</code>, <a href="http://pexpect.sourc... | 8 | 2009-09-21T17:26:42Z | [
"python",
"ffmpeg",
"subprocess"
] |
FFMPEG and Pythons subprocess | 1,455,532 | <p>I'm trying to write a gui for <code>FFMPEG</code>. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conversion, whether it failed or not etc. I figured I could do this by accessing the process's stdout like so:</p... | 6 | 2009-09-21T16:49:40Z | 2,358,686 | <p>I think you can't use readline because ffmpeg never prints one line, the status is updated by writing \r (carrige return) and then writing the line again.</p>
<pre><code>size= 68kB time=0.39 bitrate=1412.1kbits/s \rsize= 2786kB time=16.17 bitrate=1411.2kbits/s \rsize= 5472kB time=31.76 bitrate=1411... | 2 | 2010-03-01T20:05:47Z | [
"python",
"ffmpeg",
"subprocess"
] |
FFMPEG and Pythons subprocess | 1,455,532 | <p>I'm trying to write a gui for <code>FFMPEG</code>. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conversion, whether it failed or not etc. I figured I could do this by accessing the process's stdout like so:</p... | 6 | 2009-09-21T16:49:40Z | 3,536,518 | <p>Since ffmpeg writes the data unflushed to stderr you have to set the stderr file descriptor to non-blocking using fcntl.</p>
<pre>
fcntl.fcntl(
pipe.stderr.fileno(),
fcntl.F_SETFL,
fcntl.fcntl(pipe.stderr.fileno(), fcntl.F_GETFL) | os.O_NONBLOCK,
)
</pre>
<p>and then loop using sele... | 1 | 2010-08-21T05:50:50Z | [
"python",
"ffmpeg",
"subprocess"
] |
FFMPEG and Pythons subprocess | 1,455,532 | <p>I'm trying to write a gui for <code>FFMPEG</code>. I'm using pythons subprocess to create a ffmpeg process for every conversion I want. This works fine, but I'd also like a way to get the progress of the conversion, whether it failed or not etc. I figured I could do this by accessing the process's stdout like so:</p... | 6 | 2009-09-21T16:49:40Z | 31,144,059 | <p>Simply add ,universal_newlines=True to your subprocess.Popen line.</p>
<pre><code>cmd="ffmpeg -i in.mp4 -y out.avi"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,universal_newlines=True)
for line in process.stdout:
print(line)
</code></pre>
<p>For now you got line in cycle li... | 2 | 2015-06-30T16:55:17Z | [
"python",
"ffmpeg",
"subprocess"
] |
Python code does not work as expected when I run script as a Windows Service | 1,455,592 | <p>Here is the code to get Desktop path on Windows Vista. </p>
<pre><code>import pythoncom
import win32com.client
pythoncom.CoInitialize()
shell = win32com.client.Dispatch("WScript.Shell")
desktop_path = shell.SpecialFolders("Desktop")
</code></pre>
<p>Code works fine when I tried on python interpreter but its not w... | 3 | 2009-09-21T17:01:53Z | 1,455,611 | <p>Most likely, your service is running under an account which doesn't have a user desktop folder. Also note that by default, services have no access to the GUI - if your app has one, you have to mark your service as being allowed to interact with the desktop (user session, not folder).</p>
| 3 | 2009-09-21T17:05:22Z | [
"python",
"windows",
"windows-vista",
"service"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 1,455,620 | <p>This doesn't use string formatting, but you should be able to do:</p>
<pre><code>print 'this is a tuple ', (1, 2, 3)
</code></pre>
<p>If you really want to use string formatting:</p>
<pre><code>print 'this is a tuple %s' % str((1, 2, 3))
# or
print 'this is a tuple %s' % ((1, 2, 3),)
</code></pre>
<p>Note, this ... | 4 | 2009-09-21T17:06:49Z | [
"python"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 1,455,623 | <pre><code>>>> thetuple = (1, 2, 3)
>>> print "this is a tuple: %s" % (thetuple,)
this is a tuple: (1, 2, 3)
</code></pre>
<p>Making a singleton tuple with the tuple of interest as the only item, i.e. the <code>(thetuple,)</code> part, is the key bit here.</p>
| 112 | 2009-09-21T17:07:07Z | [
"python"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 1,455,632 | <pre><code>>>> tup = (1, 2, 3)
>>> print "Here it is: %s" % (tup,)
Here it is: (1, 2, 3)
>>>
</code></pre>
<p>Note that <code>(tup,)</code> is a tuple containing a tuple. The outer tuple is the argument to the % operator. The inner tuple is its content, which is actually printed.</p>
<p><co... | 16 | 2009-09-21T17:08:40Z | [
"python"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 1,455,635 | <pre><code>t = (1, 2, 3)
# the comma (,) concatenates the strings and adds a space
print "this is a tuple", (t)
# format is the most flexible way to do string formatting
print "this is a tuple {0}".format(t)
# classic string formatting
# I use it only when working with older Python versions
print "this is a tuple %s... | 2 | 2009-09-21T17:09:10Z | [
"python"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 1,456,418 | <p>I think the best way to do this is:</p>
<pre><code>t = (1,2,3)
print "This is a tuple: %s" % str(t)
</code></pre>
<p>If you're familiar with <a href="http://en.wikipedia.org/wiki/Printf#printf%5Fformat%5Fplaceholders" rel="nofollow">printf</a> style formatting, then Python supports its own version. In Python, thi... | 0 | 2009-09-21T19:38:45Z | [
"python"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 11,130,859 | <p>Note that the <code>%</code> syntax is obsolete. Use <code>str.format</code>, which is simpler and more readable:</p>
<pre><code>t = 1,2,3
print 'This is a tuple {0}'.format(t)
</code></pre>
| 18 | 2012-06-21T02:41:20Z | [
"python"
] |
Printing tuple with string formatting in Python | 1,455,602 | <p>So, i have this problem.
I got tuple (1,2,3) which i should print with string formatting.
eg.</p>
<pre><code>tup = (1,2,3)
print "this is a tuple %something" % (tup)
</code></pre>
<p>and this should print tuple representation with brackets, like</p>
<blockquote>
<p>This is a tuple (1,2,3)</p>
</blockquote>
<p>... | 59 | 2009-09-21T17:03:45Z | 26,249,755 | <p>Please note a trailing comma will be added if the tuple only has one item. e.g:</p>
<pre><code>t = (1,)
print 'this is a tuple {}'.format(t)
</code></pre>
<p>and you'll get:</p>
<pre><code>'this is a tuple (1,)'
</code></pre>
<p>in some cases e.g. you want to get a quoted list to be used in mysql query string li... | -1 | 2014-10-08T05:27:29Z | [
"python"
] |
Could not get out of python loop | 1,455,630 | <p>I want to get out of loop when there is no data but loop seems to be stopping at <code>recvfrom</code></p>
<pre><code>image=''
while 1:
data,address=self.socket.recvfrom(512)
if data is None:break
image=image+data
count=count+1
print str(count)+' packets received...'
</code><... | 1 | 2009-09-21T17:08:23Z | 1,455,653 | <p>What is the blocking mode of your socket?</p>
<p>If you are in blocking mode (which I think is the default), your program would stop until data is available... You would then not get to the next line after the recv() until data is coming. </p>
<p>If you switch to non-blocking mode, however (see socket.setblocking(... | 0 | 2009-09-21T17:12:07Z | [
"python",
"sockets",
"loops"
] |
Could not get out of python loop | 1,455,630 | <p>I want to get out of loop when there is no data but loop seems to be stopping at <code>recvfrom</code></p>
<pre><code>image=''
while 1:
data,address=self.socket.recvfrom(512)
if data is None:break
image=image+data
count=count+1
print str(count)+' packets received...'
</code><... | 1 | 2009-09-21T17:08:23Z | 1,455,662 | <p>Try setting to a <a href="http://docs.python.org/library/socket.html#socket.socket.setblocking" rel="nofollow">non-blocking socket</a>. You would do this before the loop starts. You can also try a <a href="http://docs.python.org/library/socket.html#socket.socket.settimeout" rel="nofollow">socket with a timeout</a>... | 5 | 2009-09-21T17:14:29Z | [
"python",
"sockets",
"loops"
] |
Could not get out of python loop | 1,455,630 | <p>I want to get out of loop when there is no data but loop seems to be stopping at <code>recvfrom</code></p>
<pre><code>image=''
while 1:
data,address=self.socket.recvfrom(512)
if data is None:break
image=image+data
count=count+1
print str(count)+' packets received...'
</code><... | 1 | 2009-09-21T17:08:23Z | 1,455,688 | <p>You might want to set socket.setdefaulttimeout(n) to get out of the loop if no data is returned after specified time period.</p>
| 0 | 2009-09-21T17:19:00Z | [
"python",
"sockets",
"loops"
] |
Could not get out of python loop | 1,455,630 | <p>I want to get out of loop when there is no data but loop seems to be stopping at <code>recvfrom</code></p>
<pre><code>image=''
while 1:
data,address=self.socket.recvfrom(512)
if data is None:break
image=image+data
count=count+1
print str(count)+' packets received...'
</code><... | 1 | 2009-09-21T17:08:23Z | 1,455,709 | <p><code>recvfrom</code> may indeed stop (waiting for data) unless you've set your socket to non-blocking or timeout mode. Moreover, if the socket gets closed by your counterpart, the indication of "socket was closed, nothing more to receive" is <strong>not</strong> a value of <code>None</code> for <code>data</code> --... | 2 | 2009-09-21T17:23:18Z | [
"python",
"sockets",
"loops"
] |
How to build sqlite for Python 2.4? | 1,455,642 | <p>I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:</p>
<blockquote>
<p>error: command 'gcc' failed with exit status 1</p>
</blockqu... | 0 | 2009-09-21T17:09:59Z | 1,455,663 | <p>If you don't have root privileges, I would recommend installing a more recent version of Python in your home directory and then adding your local version to your <code>PATH</code>. It seems easier to go that direction than to try to make sqlite work with an old version of Python.</p>
<p>You will also be doing yours... | 0 | 2009-09-21T17:15:01Z | [
"python",
"sqlite",
"pysqlite"
] |
How to build sqlite for Python 2.4? | 1,455,642 | <p>I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:</p>
<blockquote>
<p>error: command 'gcc' failed with exit status 1</p>
</blockqu... | 0 | 2009-09-21T17:09:59Z | 1,455,666 | <p>You can download and install Python to your home directory. </p>
<pre><code>$ cd
$ mkdir opt
$ mkdir downloads
$ cd downloads
$ wget http://www.python.org/ftp/python/2.6.2/Python-2.6.2.tgz
$ tar xvzf Python-2.6.2.tgz
$ cd Python-2.6.2
$ ./configure --prefix=$HOME/opt/ --enable-unicode=ucs4
$ make
$ make install
</... | 1 | 2009-09-21T17:16:00Z | [
"python",
"sqlite",
"pysqlite"
] |
How to build sqlite for Python 2.4? | 1,455,642 | <p>I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:</p>
<blockquote>
<p>error: command 'gcc' failed with exit status 1</p>
</blockqu... | 0 | 2009-09-21T17:09:59Z | 1,455,689 | <p>Download pysqlite <a href="http://oss.itsystementwicklung.de/download/pysqlite/2.5/2.5.5/pysqlite-2.5.5.tar.gz" rel="nofollow">here</a>, cd into the directory you downloaded to, unpack the tarball:</p>
<pre><code>$ tar xzf pysqlite-2.5.5.tar.gz
</code></pre>
<p>then just do (if your permissions are set right for t... | 1 | 2009-09-21T17:19:01Z | [
"python",
"sqlite",
"pysqlite"
] |
How to build sqlite for Python 2.4? | 1,455,642 | <p>I would like to use pysqlite interface between Python and sdlite database. I have already Python and SQLite on my computer. But I have troubles with installation of pysqlite. During the installation I get the following error message:</p>
<blockquote>
<p>error: command 'gcc' failed with exit status 1</p>
</blockqu... | 0 | 2009-09-21T17:09:59Z | 2,805,287 | <p>I had the same trouble with gcc failing with Ubuntu Karmic. I fixed this by installing the python-dev package. In my case, I'm working with python2.4, so I installed the python2.4-dev package. The python-dev package should work for python2.6.</p>
| 0 | 2010-05-10T18:20:56Z | [
"python",
"sqlite",
"pysqlite"
] |
Can I "embed" a Python back-end in an AIR application? | 1,455,722 | <p>I'm trying to find out if there is a way I could embed a Python back-end into an AIR application? I'm looking to employ an approach similar to the one outlined <a href="http://www.adobe.com/devnet/flex/articles/flex%5Fui%5F04.html" rel="nofollow">here</a> to implement the business logic for my application, but addi... | 0 | 2009-09-21T17:25:44Z | 1,455,746 | <p>Probably. We are using a J2EE server side which uses SOAP webservices to talk to our AIR application on the frontend. You should be able to do the same because soap doesn't care which technology sits on either side of it.</p>
<p>You can always have the application launch from a single binary which first fires up ... | 1 | 2009-09-21T17:30:19Z | [
"python",
"flex",
"air"
] |
Can I "embed" a Python back-end in an AIR application? | 1,455,722 | <p>I'm trying to find out if there is a way I could embed a Python back-end into an AIR application? I'm looking to employ an approach similar to the one outlined <a href="http://www.adobe.com/devnet/flex/articles/flex%5Fui%5F04.html" rel="nofollow">here</a> to implement the business logic for my application, but addi... | 0 | 2009-09-21T17:25:44Z | 1,456,111 | <p>You cannot embed your Python server in an AIR application. So basically you are out of luck.</p>
<p>The simplest solution probably is to run a server on a central location that all your users can connect to from their AIR apps. That means that all/most of the data will be on your server, and not on the users comput... | 1 | 2009-09-21T18:41:50Z | [
"python",
"flex",
"air"
] |
Can I "embed" a Python back-end in an AIR application? | 1,455,722 | <p>I'm trying to find out if there is a way I could embed a Python back-end into an AIR application? I'm looking to employ an approach similar to the one outlined <a href="http://www.adobe.com/devnet/flex/articles/flex%5Fui%5F04.html" rel="nofollow">here</a> to implement the business logic for my application, but addi... | 0 | 2009-09-21T17:25:44Z | 1,456,734 | <p>OK, so since it didn't seem possible to go that way around, I came up with an alternative that seems to work for what I want.</p>
<p>Instead of trying to embed Python inside AIR, I've gone the other way around: I'm building my Python code into a stand-alone executable using PyInstaller and bundling the AIR applicat... | 1 | 2009-09-21T20:43:08Z | [
"python",
"flex",
"air"
] |
How to encrypt using public key? | 1,455,782 | <pre><code>msg = "this is msg to encrypt"
pub_key = M2Crypto.RSA.load_pub_key('mykey.py') // This method is taking PEM file.
encrypted = pub_key.public_encrypt(msg, M2Crypto.RSA.pkcs1_padding)
</code></pre>
<p>Now I am trying to give file containing radix64 format public key as a parameter in this method and unable ... | 4 | 2009-09-21T17:36:19Z | 1,456,131 | <p>Did you ask this question before? See my answer to this question,</p>
<p><a href="http://stackoverflow.com/questions/1387867/how-to-convert-base64-radix64-public-key-to-a-pem-format-in-python">http://stackoverflow.com/questions/1387867/how-to-convert-base64-radix64-public-key-to-a-pem-format-in-python</a></p>
| 1 | 2009-09-21T18:44:35Z | [
"python",
"encryption",
"encoding"
] |
How to encrypt using public key? | 1,455,782 | <pre><code>msg = "this is msg to encrypt"
pub_key = M2Crypto.RSA.load_pub_key('mykey.py') // This method is taking PEM file.
encrypted = pub_key.public_encrypt(msg, M2Crypto.RSA.pkcs1_padding)
</code></pre>
<p>Now I am trying to give file containing radix64 format public key as a parameter in this method and unable ... | 4 | 2009-09-21T17:36:19Z | 1,502,121 | <p>There is an error somewhere in the public key. It appears to be a PGP public key but with different line lengths, so it can't be used directly as an RSA public key.</p>
| 0 | 2009-10-01T05:59:43Z | [
"python",
"encryption",
"encoding"
] |
How to encrypt using public key? | 1,455,782 | <pre><code>msg = "this is msg to encrypt"
pub_key = M2Crypto.RSA.load_pub_key('mykey.py') // This method is taking PEM file.
encrypted = pub_key.public_encrypt(msg, M2Crypto.RSA.pkcs1_padding)
</code></pre>
<p>Now I am trying to give file containing radix64 format public key as a parameter in this method and unable ... | 4 | 2009-09-21T17:36:19Z | 7,424,450 | <p>In case someone searches for this question, I was getting the same error message: </p>
<pre><code>M2Crypto.RSA.RSAError: no start line
</code></pre>
<p>In my case, it turned out that my keys were of type unicode. This was solved by converting the key back to ascii:</p>
<pre><code>key.encode('ascii')
</code></pre... | 5 | 2011-09-15T00:05:41Z | [
"python",
"encryption",
"encoding"
] |
Can we run google app engine on ubuntu/windows and serve web application | 1,455,800 | <p>I see google provide SDK and utilties to develop and run the web application in development (developer-pc) and port them to google app engine live (at google server).</p>
<p>Can we use google app engine to run the local web application without using google infrastructure? </p>
<p>Basically I want a decent job sche... | 4 | 2009-09-21T17:41:39Z | 1,455,828 | <p>I don't believe so. According to the App Engine terms of service:</p>
<blockquote>
<p>7.1. Google gives you a personal, worldwide, royalty-free,
non-assignable and non-exclusive
license to use the software provided
to you by Google as part of the
Service as provided to you by Google
(referred to as the ... | -1 | 2009-09-21T17:47:51Z | [
"python",
"google-app-engine",
"task"
] |
Can we run google app engine on ubuntu/windows and serve web application | 1,455,800 | <p>I see google provide SDK and utilties to develop and run the web application in development (developer-pc) and port them to google app engine live (at google server).</p>
<p>Can we use google app engine to run the local web application without using google infrastructure? </p>
<p>Basically I want a decent job sche... | 4 | 2009-09-21T17:41:39Z | 1,455,832 | <p>You can run App Engine apps on top of <a href="http://code.google.com/p/appscale/" rel="nofollow">appscale</a> which in turn does run on Eucalyptus, Xen, and other clustering solutions you can deploy on Ubuntu (not sure about there being any Windows support) -- looks like it may require substantial system installati... | 8 | 2009-09-21T17:48:18Z | [
"python",
"google-app-engine",
"task"
] |
Given a class type how do I create an instance in Python? | 1,455,835 | <p>Let's say I have this :</p>
<pre><code>class whatever(object):
def __init__(self):
pass
</code></pre>
<p>and this function:</p>
<pre><code>def create_object(type_name):
# create an object of type_name
</code></pre>
<p>I'd like to be able to call the <code>create_object</code> like this:</p>
<pre><co... | 0 | 2009-09-21T17:49:28Z | 1,455,851 | <p>The most obvious way:</p>
<pre><code>def create_object(type_name):
return type_name()
</code></pre>
| 7 | 2009-09-21T17:51:23Z | [
"python",
"oop"
] |
Given a class type how do I create an instance in Python? | 1,455,835 | <p>Let's say I have this :</p>
<pre><code>class whatever(object):
def __init__(self):
pass
</code></pre>
<p>and this function:</p>
<pre><code>def create_object(type_name):
# create an object of type_name
</code></pre>
<p>I'd like to be able to call the <code>create_object</code> like this:</p>
<pre><co... | 0 | 2009-09-21T17:49:28Z | 1,455,857 | <p>If I understand correctly, what you want is:</p>
<pre><code>def create_object(type_name, *args):
# create an object of type_name
return type_name(*args)
inst = create_object(whatever)
</code></pre>
<p>I don't really know <em>why</em> you want to do this, but would be interesting to hear from you what are ... | 2 | 2009-09-21T17:52:20Z | [
"python",
"oop"
] |
Given a class type how do I create an instance in Python? | 1,455,835 | <p>Let's say I have this :</p>
<pre><code>class whatever(object):
def __init__(self):
pass
</code></pre>
<p>and this function:</p>
<pre><code>def create_object(type_name):
# create an object of type_name
</code></pre>
<p>I'd like to be able to call the <code>create_object</code> like this:</p>
<pre><co... | 0 | 2009-09-21T17:49:28Z | 1,455,859 | <pre><code>def create_object(type_name):
return type_name()
</code></pre>
<p>you can of course skip the function altogether and create the instance of <code>whatever</code> like this:</p>
<pre><code>inst = whatever()
</code></pre>
| 2 | 2009-09-21T17:52:26Z | [
"python",
"oop"
] |
Given a class type how do I create an instance in Python? | 1,455,835 | <p>Let's say I have this :</p>
<pre><code>class whatever(object):
def __init__(self):
pass
</code></pre>
<p>and this function:</p>
<pre><code>def create_object(type_name):
# create an object of type_name
</code></pre>
<p>I'd like to be able to call the <code>create_object</code> like this:</p>
<pre><co... | 0 | 2009-09-21T17:49:28Z | 1,455,863 | <pre><code>def create_object(typeobject):
return typeobject()
</code></pre>
<p>As you so explicitly say that the arg to <code>create_object</code> is NOT meant to be a string, I assume it's meant to be the type object itself, just like in the <code>create_object(whatever)</code> example you give, in which <code>what... | 5 | 2009-09-21T17:52:57Z | [
"python",
"oop"
] |
Built-in tree view for Django-Admin sites? | 1,456,047 | <p>Why is there no built-in tree view in the Python Django framework?
Isn't there an easy way to visualize a model when a class has an 1:n relation to itself?</p>
<p>I know about some fancy google code projects to achieve that but I think there must be some common sense among the Django community to handle this common... | 3 | 2009-09-21T18:26:20Z | 1,456,289 | <p>The core devs are pretty strongly against adding extra stuff to Django unless there's a clear universal requirement - especially if there are perfectly good third-party projects that provide this functionality. </p>
<p>This is absolutely the case with tree views. It's very far from something that everyone wants to ... | 2 | 2009-09-21T19:15:23Z | [
"python",
"django",
"tree",
"view"
] |
Built-in tree view for Django-Admin sites? | 1,456,047 | <p>Why is there no built-in tree view in the Python Django framework?
Isn't there an easy way to visualize a model when a class has an 1:n relation to itself?</p>
<p>I know about some fancy google code projects to achieve that but I think there must be some common sense among the Django community to handle this common... | 3 | 2009-09-21T18:26:20Z | 9,965,582 | <p>check out:</p>
<p><a href="http://stackoverflow.com/questions/5229508/tree-structure-of-parent-child-relation-in-django-templates">tree structure of parent child relation in django templates</a></p>
<p><a href="http://code.google.com/p/django-treeview/" rel="nofollow">http://code.google.com/p/django-treeview/</a><... | 0 | 2012-04-01T15:24:13Z | [
"python",
"django",
"tree",
"view"
] |
Built-in tree view for Django-Admin sites? | 1,456,047 | <p>Why is there no built-in tree view in the Python Django framework?
Isn't there an easy way to visualize a model when a class has an 1:n relation to itself?</p>
<p>I know about some fancy google code projects to achieve that but I think there must be some common sense among the Django community to handle this common... | 3 | 2009-09-21T18:26:20Z | 26,561,147 | <p>Another option is a prove of concept application for Django - <a href="https://pypi.python.org/pypi/django-admirarchy" rel="nofollow">django-admirarchy</a>. It renders hierachies level by level (like Norton Commander and Co).</p>
| 1 | 2014-10-25T09:47:26Z | [
"python",
"django",
"tree",
"view"
] |
Dealing with db.Timeout on Google App Engine | 1,456,070 | <p>I'm testing my application (on <a href="http://en.wikipedia.org/wiki/Google%5FApp%5FEngine" rel="nofollow">Google App Engine</a> live servers) and the way I've written it I have about 40 db.GqlQuery() statements in my code (mostly part of classes).</p>
<p>I keep getting db.Timeout <em>very often</em> though.</p>
<... | 4 | 2009-09-21T18:33:05Z | 1,457,225 | <p>Queries will occasionally fail. You can either show an error message to the user, or retry, as you're doing above. If you retry, however, you should use thread.sleep to add increasing amounts of delay (starting at, say, 50ms) on each retry - retries are more likely to succeed if they're not retried as fast as possib... | 6 | 2009-09-21T22:28:41Z | [
"python",
"google-app-engine"
] |
Dealing with db.Timeout on Google App Engine | 1,456,070 | <p>I'm testing my application (on <a href="http://en.wikipedia.org/wiki/Google%5FApp%5FEngine" rel="nofollow">Google App Engine</a> live servers) and the way I've written it I have about 40 db.GqlQuery() statements in my code (mostly part of classes).</p>
<p>I keep getting db.Timeout <em>very often</em> though.</p>
<... | 4 | 2009-09-21T18:33:05Z | 1,475,218 | <p>See the new ROTModel in GAE-Utilities. The second discussion below shows how it does retries.
It's a subclass of db.Model, so your classes can inherit from ROTModel instead, and take advantage of it's retries. </p>
<p><a href="http://code.google.com/p/gaeutilities" rel="nofollow">http://code.google.com/p/gaeutilit... | 1 | 2009-09-25T03:00:33Z | [
"python",
"google-app-engine"
] |
Dealing with db.Timeout on Google App Engine | 1,456,070 | <p>I'm testing my application (on <a href="http://en.wikipedia.org/wiki/Google%5FApp%5FEngine" rel="nofollow">Google App Engine</a> live servers) and the way I've written it I have about 40 db.GqlQuery() statements in my code (mostly part of classes).</p>
<p>I keep getting db.Timeout <em>very often</em> though.</p>
<... | 4 | 2009-09-21T18:33:05Z | 1,733,871 | <p>Here's a decorator to retry on db.Timeout, adapted from one from Kay framework:</p>
<pre><code>import logging, time
from google.appengine.ext import db
def retry_on_timeout(retries=3, interval=1.0, exponent=2.0):
"""A decorator to retry a given function performing db operations."""
def _decorator(func):
... | 7 | 2009-11-14T10:13:08Z | [
"python",
"google-app-engine"
] |
Dealing with db.Timeout on Google App Engine | 1,456,070 | <p>I'm testing my application (on <a href="http://en.wikipedia.org/wiki/Google%5FApp%5FEngine" rel="nofollow">Google App Engine</a> live servers) and the way I've written it I have about 40 db.GqlQuery() statements in my code (mostly part of classes).</p>
<p>I keep getting db.Timeout <em>very often</em> though.</p>
<... | 4 | 2009-09-21T18:33:05Z | 1,959,830 | <p>Take a look at this this python Autoretry Datastore Timeouts recipe. Similar to moraes answer, but you only need to call it once at initialization time, rather than decorate functions that perform datastore operations.</p>
<p><a href="http://appengine-cookbook.appspot.com/recipe/autoretry-datastore-timeouts/" rel="... | 2 | 2009-12-24T21:38:58Z | [
"python",
"google-app-engine"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,456,389 | <p>No, there is really no way to do this without creating two dictionaries. How would it be possible to implement this with just one dictionary while continuing to offer comparable performance?</p>
<p>You are better off creating a custom type that encapsulates two dictionaries and exposes the functionality you want.</... | 3 | 2009-09-21T19:31:28Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,456,390 | <p>Two hash maps is actually probably the fastest-performing solution assuming you can spare the memory. I would wrap those in a single class - the burden on the programmer is in ensuring that two the hash maps sync up correctly.</p>
| 5 | 2009-09-21T19:31:29Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,456,392 | <p>I would just populate a second hash, with</p>
<pre><code>reverse_map = dict((reversed(item) for item in forward_map.items()))
</code></pre>
| 14 | 2009-09-21T19:31:55Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,456,461 | <p>In your special case you can store both in one dictionary:</p>
<pre><code>relation = {}
relation['Alice'] = 'Bob'
relation['Bob'] = 'Alice'
</code></pre>
<p>Since what you are describing is a symmetric relationship. <code>A -> B => B -> A</code></p>
| 26 | 2009-09-21T19:47:24Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,456,482 | <p>You have two separate issues.</p>
<ol>
<li><p>You have a "Conversation" object. It refers to two Persons. Since a Person can have multiple conversations, you have a many-to-many relationship.</p></li>
<li><p>You have a Map from Person to a list of Conversations. A Conversion will have a pair of Persons.</p></li>... | 5 | 2009-09-21T19:50:07Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,456,583 | <p>Here is a <a href="http://www.aminus.net/geniusql/browser/trunk/geniusql/objects.py#L32" rel="nofollow">simple bijective Dictionary implementation</a>, although I don't know if it will meet your performance requirements.</p>
<p>(Link from <a href="http://paddy3118.blogspot.com/2009/04/bimap-bi-directional-mappingdi... | 1 | 2009-09-21T20:12:20Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 1,457,749 | <p>The kjbuckets C extension module provides a "graph" data structure which I believe gives you what you want.</p>
| 0 | 2009-09-22T01:48:12Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 13,276,237 | <p>You can create your own dictionary type by subclassing <code>dict</code> and adding the logic that you want. Here's a basic example:</p>
<pre><code>class TwoWayDict(dict):
def __setitem__(self, key, value):
# Remove any previous connections with these values
if key in self:
del self[... | 48 | 2012-11-07T18:53:25Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 14,129,446 | <p>You may be able to use a <code>DoubleDict</code> as shown in <a href="http://code.activestate.com/recipes/578224/" rel="nofollow">recipe 578224</a> on the <a href="http://code.activestate.com/recipes/langs/python/" rel="nofollow">Python Cookbook</a>.</p>
| 1 | 2013-01-02T21:27:01Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 18,045,091 | <p>Another possible solution is to implement a subclass of <code>dict</code>, that holds the original dictionary and keeps track of a reversed version of it. Keeping two seperate dicts can be useful if keys and values are overlapping. </p>
<pre><code>class TwoWayDict(dict):
def __init__(self, my_dict):
dic... | 0 | 2013-08-04T16:33:56Z | [
"python"
] |
Two way/reverse map | 1,456,373 | <p>I'm doing this switchboard thing in python where I need to keep track of who's talking to whom, so if Alice --> Bob, then that implies that Bob --> Alice. </p>
<p>Yes, I could populate two hash maps, but I'm wondering if anyone has an idea to do it with one. </p>
<p>Or suggest another data structure.</p>
<p>There... | 50 | 2009-09-21T19:27:35Z | 34,081,276 | <p>There's the collections-extended library on pypi: <a href="https://pypi.python.org/pypi/collections-extended/0.6.0" rel="nofollow">https://pypi.python.org/pypi/collections-extended/0.6.0</a></p>
<p>Using the bijection class is as easy as:</p>
<pre><code>RESPONSE_TYPES = bijection({
0x03 : 'module_info',
0x... | 0 | 2015-12-04T05:08:12Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,645 | <p>The random module defines choice(), which does what you want:</p>
<pre><code>import random
words = [line.strip() for line in open('/etc/dictionaries-common/words')]
print(random.choice(words))
</code></pre>
<p>Note also that this assumes that each word is by itself on a line in the file. If the file is very big, ... | 17 | 2009-09-21T20:24:48Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,646 | <p>This article may help</p>
<p><a href="http://www.bryceboe.com/2009/03/23/random-lines-from-a-file/" rel="nofollow">http://www.bryceboe.com/2009/03/23/random-lines-from-a-file/</a></p>
| 2 | 2009-09-21T20:25:12Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,650 | <p>You could do this without using <code>fileinput</code>:</p>
<pre><code>import random
data = open("/etc/dictionaries-common/words").readlines()
print random.choice(data)
</code></pre>
<p>I have also used <code>data</code> instead of <code>file</code> because <code>file</code> is a predefined type in Python.</p>
| 1 | 2009-09-21T20:25:45Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,654 | <p>Efficiency and verbosity aren't the same thing in this case. It's tempting to go for the most beautiful, pythonic approach that does everything in one or two lines but for file I/O, stick with classic fopen-style, low-level interaction, even if it does take up a few more lines of code.</p>
<p>I could copy and paste... | 0 | 2009-09-21T20:26:12Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,723 | <p>There are a few different ways to optimize this problem. You can optimize for speed, or for space.</p>
<p>If you want a quick but memory-hungry solution, read in the entire file using file.readlines() and then use random.choice()</p>
<p>If you want a memory-efficient solution, first check the number of lines in th... | 0 | 2009-09-21T20:40:10Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,750 | <p>Pythonizing my answer from <a href="http://stackoverflow.com/questions/232237/whats-the-best-way-to-return-a-random-line-in-a-text-file-using-c">Whatâs the best way to return a random line in a text file using C?</a> :</p>
<pre><code>import random
def select_random_line(filename):
selection = None
count ... | 3 | 2009-09-21T20:45:21Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,456,761 | <p>Another solution is to use <a href="http://docs.python.org/library/linecache.html#linecache.getline">getline</a></p>
<pre><code>import linecache
import random
line_number = random.randint(0, total_num_lines)
linecache.getline('/etc/dictionaries-common/words', line_number)
</code></pre>
<p>From the documentation:</... | 9 | 2009-09-21T20:47:46Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,457,124 | <pre><code>>>> import random
>>> random.choice(list(open('/etc/dictionaries-common/words')))
'jaundiced\n'
</code></pre>
<p>It is efficient human-time-wise. </p>
<p>btw, your implementation coincides with the one from stdlib's <a href="http://svn.python.org/view/python/trunk/Lib/random.py?view=mark... | 9 | 2009-09-21T22:00:26Z | [
"python"
] |
Return a random word from a word list in python | 1,456,617 | <p>I would like to retrieve a random word from a file using python, but I do not believe my following method is best or efficient. Please assist.</p>
<pre><code>import fileinput
import _random
file = [line for line in fileinput.input("/etc/dictionaries-common/words")]
rand = _random.Random()
print file[int(rand.random... | 6 | 2009-09-21T20:19:28Z | 1,457,149 | <p>I don't have code for you but as far as an algorithm goes:</p>
<ol>
<li>Find the file's size</li>
<li>Do a random seek with the seek() function</li>
<li>Find the next (or previous) whitespace character</li>
<li>Return the word that starts after that whitespace character</li>
</ol>
| 1 | 2009-09-21T22:06:06Z | [
"python"
] |
Convert SCCS repository to SVN | 1,456,757 | <p>I'm investigating migrating a source code repository currently kept under SCCS on an aging Digital UNIX box to Subversion on a Windows box. My initial searching has led me to a python script, <a href="http://sccs2svn.berlios.de/" rel="nofollow">sccs2svn</a>, which looks like it would do the job - with some restricti... | 1 | 2009-09-21T20:47:23Z | 1,456,870 | <p>If you use FSFS backend, you can just move the repository to your target platform. FSFS Repositories are truely platform indipendent. They are also standard setup since svn 1.3 so you should not have any problems by creating the repository and then copy it to your final server via any file transfer.</p>
| 3 | 2009-09-21T21:07:56Z | [
"python",
"svn",
"version-control"
] |
Convert SCCS repository to SVN | 1,456,757 | <p>I'm investigating migrating a source code repository currently kept under SCCS on an aging Digital UNIX box to Subversion on a Windows box. My initial searching has led me to a python script, <a href="http://sccs2svn.berlios.de/" rel="nofollow">sccs2svn</a>, which looks like it would do the job - with some restricti... | 1 | 2009-09-21T20:47:23Z | 8,649,403 | <p>If sccs2svn really must work locally and you want to end up with the SVN repository on a Windows box, then use the Cygwin version of GNU CSSC to run sccs2svn on the Windows box itself. CSSC is an SCCS workalike: see <a href="http://www.gnu.org/software/cssc/" rel="nofollow">http://www.gnu.org/software/cssc/</a></p>... | 0 | 2011-12-27T21:19:26Z | [
"python",
"svn",
"version-control"
] |
Python Eval: What's wrong with this code? | 1,456,760 | <p>I'm trying to write a very simple Python utility for personal use that counts the number of lines in a text file for which a predicate specified at the command line is true. Here's the code:</p>
<pre><code>import sys
pred = sys.argv[2]
if sys.argv[1] == "stdin" :
handle = sys.stdin
else :
handle = open(sy... | 2 | 2009-09-21T20:47:37Z | 1,456,802 | <p>Try using exec instead of eval. The difference between the 2 is explained <a href="http://www.ibiblio.org/g2swap/byteofpython/read/exec-statement.html">here</a></p>
| 11 | 2009-09-21T20:55:24Z | [
"python",
"eval",
"syntax-error"
] |
Python Eval: What's wrong with this code? | 1,456,760 | <p>I'm trying to write a very simple Python utility for personal use that counts the number of lines in a text file for which a predicate specified at the command line is true. Here's the code:</p>
<pre><code>import sys
pred = sys.argv[2]
if sys.argv[1] == "stdin" :
handle = sys.stdin
else :
handle = open(sy... | 2 | 2009-09-21T20:47:37Z | 1,456,809 | <p>The python eval() function evaluates expressions, not statements. Try replacing the eval() line with:</p>
<pre><code>result += eval(pred + " else 0")
</code></pre>
| 2 | 2009-09-21T20:56:37Z | [
"python",
"eval",
"syntax-error"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.