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
Using keys with spaces
1,726,640
<p>Is there a way to do something like the following in Django templates?</p> <pre><code> {% for hop in hops%} &lt;tr&gt; &lt;td&gt;{{ hop.name }}&lt;/td&gt; &lt;td&gt;{{ hop.mass }}&lt;/td&gt; &lt;td&gt;{{ hop."boil time" }}&lt;/td&gt; &lt;/tr&gt; {% endfor %} </code></pre> <p>The hop....
2
2009-11-13T01:50:47Z
1,726,684
<p>You could use a <code>get</code> filter from djangosnippets: <a href="http://www.djangosnippets.org/snippets/1412/" rel="nofollow">http://www.djangosnippets.org/snippets/1412/</a></p> <p>(Renaming the key is probably better...)</p>
1
2009-11-13T02:07:18Z
[ "python", "django", "google-app-engine", "dictionary", "django-templates" ]
Using keys with spaces
1,726,640
<p>Is there a way to do something like the following in Django templates?</p> <pre><code> {% for hop in hops%} &lt;tr&gt; &lt;td&gt;{{ hop.name }}&lt;/td&gt; &lt;td&gt;{{ hop.mass }}&lt;/td&gt; &lt;td&gt;{{ hop."boil time" }}&lt;/td&gt; &lt;/tr&gt; {% endfor %} </code></pre> <p>The hop....
2
2009-11-13T01:50:47Z
1,734,341
<p>For django 0.96, which is what the Google Appengine uses for templates, the following works:</p> <pre><code>{% for hop in recipe.get_hops %} {% for item in hop.items %} {% ifequal item.0 'boil time' %} &lt;p&gt;{{ item.1 }}&lt;/p&gt; {% endifequal %} {% endfor %} {...
0
2009-11-14T14:14:30Z
[ "python", "django", "google-app-engine", "dictionary", "django-templates" ]
programmatically determine if an evaluation of a function is being assigned?
1,726,655
<p>I would like to do this:</p> <pre><code>def foo(): if &lt;a magical condition&gt;: return x else: poof() # or... def foo(): x = &lt;a magical object&gt; return x def poof(): print 'poof!' bar = foo() # bar points to &lt;a magical object&gt; but poof() is not called foo() # p...
1
2009-11-13T01:58:56Z
1,726,676
<p>A function can't tell what its return value is used for. Your solution will print poof if you re-assign to <code>bar</code> for example.</p> <p>What's the real problem you are trying to solve?</p>
1
2009-11-13T02:05:53Z
[ "python" ]
programmatically determine if an evaluation of a function is being assigned?
1,726,655
<p>I would like to do this:</p> <pre><code>def foo(): if &lt;a magical condition&gt;: return x else: poof() # or... def foo(): x = &lt;a magical object&gt; return x def poof(): print 'poof!' bar = foo() # bar points to &lt;a magical object&gt; but poof() is not called foo() # p...
1
2009-11-13T01:58:56Z
1,726,724
<p>I'm pretty confused by your question, but I think what you are trying to do is run a function when a value is reassigned.</p> <p>Instead of doing tricky things with a <code>__del__()</code> method function, I suggest you just put your value into a class instance, and then overload <code>__setattr__()</code>. You c...
3
2009-11-13T02:17:57Z
[ "python" ]
Unzip part of a file using python gzip module
1,726,696
<p>I am trying to unzip a gzipped file in Python using the gzip module. The pre-condition is that, I get 160 bytesof data at a time, and I need to unzip it before I request for the next 160 bytes. Partial unzipping is OK, before requesting the next 160 bytes. The code I have is</p> <pre><code>import gzip import time i...
1
2009-11-13T02:10:33Z
1,726,725
<p>Create your own class with a read() method (and whatever else GzipFile needs from fileobj, like close and seek) and pass it to GzipFile. Something like:</p> <pre><code>class MyBuffer(object): def __init__(self, input_file): self.input_file = input_file def read(self, size=-1): if size &lt; 0: siz...
4
2009-11-13T02:18:29Z
[ "python", "gzip", "unzip" ]
Returning array of data mapping values to parameters in python
1,726,750
<p>I have a few functions that return an array of data corresponding to parameters ranges.</p> <p>Example: for a 2d array <code>a</code>, the <code>a_{ij}</code> value corresponds to the parameter set <code>(param1_i, param2_j)</code>. <em>How do I return the result <strong>and</strong> keep the parameter-value corres...
0
2009-11-13T02:24:46Z
1,726,881
<p>I recommend your last suggestion... just return two arrays <code>{'values': a, 'params':params}</code>.</p> <p>There are a few reasons for this. </p> <ol> <li><p>Primarily, your other solution (using dtype and recarrays) tangles too many things together. For example, what about quantities derived from <code>a</c...
2
2009-11-13T03:06:42Z
[ "python", "arrays", "numpy" ]
Sorting a 3 parallel list that includes strings and numeric value in Python
1,726,865
<p>how to sort using 3 parallel array lists:</p> <p>num1 = ['a','b','c,']<br> num2 = ['apple','pear','grapes']<br> num3 = [2.5,4.0,.68]</p> <p>I used 2 for statements followed by a if statement. Sorting by elements the output should be:</p> <p>a apple 2.5<br> b pear 4.0<br> c grapes .6...
0
2009-11-13T03:03:45Z
1,726,893
<p>Since you say the lists are parallel, let's group them into tuples, and then sort the list of tuples.</p> <pre><code>num1 = ['a','b','c'] num2 = ['apple','pear','grapes'] num3 = [2.5,4.0,.68] lst = zip(num1, num2, num3) lst.sort() for x1, x2, x3 in lst: print x1, x2, x3, print </code></pre> <p>The result is...
2
2009-11-13T03:10:39Z
[ "python", "list", "sorting", "parallel-processing" ]
Sorting a 3 parallel list that includes strings and numeric value in Python
1,726,865
<p>how to sort using 3 parallel array lists:</p> <p>num1 = ['a','b','c,']<br> num2 = ['apple','pear','grapes']<br> num3 = [2.5,4.0,.68]</p> <p>I used 2 for statements followed by a if statement. Sorting by elements the output should be:</p> <p>a apple 2.5<br> b pear 4.0<br> c grapes .6...
0
2009-11-13T03:03:45Z
1,726,905
<p>From your desired inputs and output it doesn't seem you want any sorting -- just:</p> <pre><code>num1 = ['a','b','c'] num2 = ['apple','pear','grapes'] num3 = [2.5,4.0,.68] for item in [x for t in zip(num1, num2, num3) for x in t]: print item, print </code></pre> <p>This does give the output you mention -- is thi...
1
2009-11-13T03:14:09Z
[ "python", "list", "sorting", "parallel-processing" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,726,948
<p>I'd make another dictionary, using the existing dictionaries as keys and the count of occurrences as values. (Python doesn't allow dictionaries to be used as dictionary keys out of the box, but there are a couple of ways of doing that mentioned in <a href="http://stackoverflow.com/questions/1151658/python-hashable-d...
1
2009-11-13T03:28:36Z
[ "python", "list", "dictionary" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,726,960
<p>One idea is to sort the data. Assume <code>inputdata</code> is your list from above:</p> <pre><code>from itertools import groupby from operator import itemgetter inputdata.sort(key=itemgetter(*inputdata[0])) # ensures order print [k for k, g in groupby(inputdata) if len(list(g)) &gt; 1] </code></pre> <p>prints:</...
4
2009-11-13T03:31:10Z
[ "python", "list", "dictionary" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,726,989
<p>Another way is to make a counter for each dict data, based on a frozenset of items:</p> <pre><code>from operator import itemgetter from collections import defaultdict counter = defaultdict(int) for d in inputdata: counter[frozenset(d.iteritems())] += 1 result = [dict(item) for item, count in counter.iteritems...
1
2009-11-13T03:37:21Z
[ "python", "list", "dictionary" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,726,993
<pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; list(a[0] for a in itertools.groupby(sorted(data)) if len(list(a[1])) &gt; 1) [{'file': u'/file.txt', 'line': u'line 666', 'rule': u'A DUPLICATE RULE'}] </code></pre> <p>There's probably a more optimal way to check this than len(list(a[1])).</p> <p>Edit: I added a...
1
2009-11-13T03:38:42Z
[ "python", "list", "dictionary" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,727,062
<p>Another option is to create your own data structure instead of using a dict. If you do this, then you can override <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fcmp%5F%5F" rel="nofollow">__cmp__</a>, <a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Feq%5F%5F" rel="nofollo...
0
2009-11-13T04:01:42Z
[ "python", "list", "dictionary" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,727,479
<p>This answer is based on Steven Huwig's answer. It's similar to his, but I use <code>sorted()</code> on the list so that <code>groupby()</code> works correctly.</p> <p>Also, since he said "There's probably a more optimal way to check this than len(list(a[1])).", I decided to use some other way to check for non-uniq...
1
2009-11-13T06:24:33Z
[ "python", "list", "dictionary" ]
How to remove unique, then duplicate dictionaries in a list?
1,726,925
<p>Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single instances? I gotta say I only recently started getting into Python but its making this project <em>so</em> much easier. I'm...
3
2009-11-13T03:19:51Z
1,730,308
<p>I always prefer to work with objects instead of dicts, if the fields are the same for every item.</p> <p>So, I define a class:</p> <pre><code>class rule(object): def __init__(self, file, line, rule): self.file = file self.line = line self.rule = rule #Not a "magic" method, just a helper for...
2
2009-11-13T16:27:48Z
[ "python", "list", "dictionary" ]
An enterprise scheduler for python (like quartz)
1,727,138
<p>I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements:</p> <ul> <li>Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and must be fired after restarting.</li> <li>Jobs must enter and exit the scheduler in a transaction (i.e. if...
16
2009-11-13T04:31:57Z
1,727,176
<p>Is <a href="http://pypi.python.org/pypi/APScheduler/1.01">APScheduler</a> what you're looking for?</p>
12
2009-11-13T04:43:21Z
[ "python", "scheduled-tasks", "enterprise", "quartz-scheduler" ]
An enterprise scheduler for python (like quartz)
1,727,138
<p>I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements:</p> <ul> <li>Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and must be fired after restarting.</li> <li>Jobs must enter and exit the scheduler in a transaction (i.e. if...
16
2009-11-13T04:31:57Z
1,737,313
<p><a href="http://www.cs.unc.edu/bass" rel="nofollow">We</a>'re using <a href="http://www.oracle.com/technetwork/oem/grid-engine-166852.html" rel="nofollow">Sun Grid Engine</a>, which is accessible through <a href="http://en.wikipedia.org/wiki/DRMAA" rel="nofollow">DRMAA</a>, which happens to have <a href="http://code...
2
2009-11-15T11:37:33Z
[ "python", "scheduled-tasks", "enterprise", "quartz-scheduler" ]
An enterprise scheduler for python (like quartz)
1,727,138
<p>I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements:</p> <ul> <li>Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and must be fired after restarting.</li> <li>Jobs must enter and exit the scheduler in a transaction (i.e. if...
16
2009-11-13T04:31:57Z
18,942,937
<p>You can use <a href="http://celeryproject.org/" rel="nofollow">Celery</a></p> <blockquote> <p>Celery is an asynchronous task queue/job queue based on distributed message passing. It is focused on real-time operation, but supports scheduling as well.</p> </blockquote> <p>Install Celery using <code>pip install...
3
2013-09-22T10:41:17Z
[ "python", "scheduled-tasks", "enterprise", "quartz-scheduler" ]
how to install python-spidermonkey on windows
1,727,157
<p>im making some script with python mechanize,</p> <p>one of problem is it really hard to find which support javascript supported web client </p> <p>scraping or crawler.</p> <p>actually i was found some such as python-spidermonkey and pykhtml and so on.</p> <p>but most of all only support on linux .</p> <p>i want...
0
2009-11-13T04:39:05Z
1,727,203
<p>Both these links: <a href="http://code.google.com/p/python-spidermonkey/issues/detail?id=5" rel="nofollow">http://code.google.com/p/python-spidermonkey/issues/detail?id=5</a> and <a href="http://www.ohloh.net/p/python-spidermonkey" rel="nofollow">http://www.ohloh.net/p/python-spidermonkey</a> say that Spedermonkey i...
-1
2009-11-13T04:54:13Z
[ "python" ]
Implement OpenID in Python
1,727,429
<p>How should I implement OpenID in Python using the OpenID API?</p>
1
2009-11-13T06:09:49Z
1,727,439
<p>How about <a href="http://openidenabled.com/python-openid/" rel="nofollow">this lib</a>?</p>
3
2009-11-13T06:13:15Z
[ "python", "openid" ]
Implement OpenID in Python
1,727,429
<p>How should I implement OpenID in Python using the OpenID API?</p>
1
2009-11-13T06:09:49Z
1,727,446
<p>For hassle free installation of openid use the <a href="https://rpxnow.com/" rel="nofollow">RPX</a> The installation is quite simple. visit the website for more details. You will be able to understand it very easily.</p>
3
2009-11-13T06:14:30Z
[ "python", "openid" ]
Implement OpenID in Python
1,727,429
<p>How should I implement OpenID in Python using the OpenID API?</p>
1
2009-11-13T06:09:49Z
11,852,701
<p>You should take a look at <a href="http://code.google.com/p/python-opid/" rel="nofollow">http://code.google.com/p/python-opid/</a></p>
0
2012-08-07T19:24:23Z
[ "python", "openid" ]
replace URLs in text with links to URLs
1,727,535
<p>Using Python I want to replace all URLs in a body of text with links to those URLs, like what Gmail does. Can this be done in a one liner regular expression?</p> <p>Edit: by body of text I just meant plain text - no HTML</p>
5
2009-11-13T06:39:27Z
1,727,552
<p>You can load the document up with a DOM/HTML parsing library ( see html5lib ), grab all text nodes, match them against a regular expression and replace the text nodes with a regex replacement of the URI with anchors around it using a PCRE such as:</p> <pre><code>/(https?:[;\/?\\@&amp;=+$,\[\]A-Za-z0-9\-_\.\!\~\*\'\...
9
2009-11-13T06:43:18Z
[ "python", "regex", "url", "hyperlink" ]
replace URLs in text with links to URLs
1,727,535
<p>Using Python I want to replace all URLs in a body of text with links to those URLs, like what Gmail does. Can this be done in a one liner regular expression?</p> <p>Edit: by body of text I just meant plain text - no HTML</p>
5
2009-11-13T06:39:27Z
1,727,573
<p>When you say "body of text" do you mean a plain text file, or body text in an HTML document? If you want the HTML document, you will want to use <a href="http://www.crummy.com/software/BeautifulSoup/" rel="nofollow">Beautiful Soup</a> to parse it; then, search through the body text and insert the tags.</p> <p>Matc...
0
2009-11-13T06:48:54Z
[ "python", "regex", "url", "hyperlink" ]
replace URLs in text with links to URLs
1,727,535
<p>Using Python I want to replace all URLs in a body of text with links to those URLs, like what Gmail does. Can this be done in a one liner regular expression?</p> <p>Edit: by body of text I just meant plain text - no HTML</p>
5
2009-11-13T06:39:27Z
1,727,581
<p>Gmail is a lot more open, when it comes to URLs, but it is not always right either. e.g. it will make www.a.b into a hyperlink as well as <a href="http://a.b" rel="nofollow">http://a.b</a> but it often fails because of wrapped text and uncommon (but valid) URL characters.</p> <p>See <a href="http://www.ietf.org/rfc...
0
2009-11-13T06:51:02Z
[ "python", "regex", "url", "hyperlink" ]
replace URLs in text with links to URLs
1,727,535
<p>Using Python I want to replace all URLs in a body of text with links to those URLs, like what Gmail does. Can this be done in a one liner regular expression?</p> <p>Edit: by body of text I just meant plain text - no HTML</p>
5
2009-11-13T06:39:27Z
1,727,747
<pre><code>/\w+:\/\/[^\s]+/ </code></pre>
1
2009-11-13T07:45:19Z
[ "python", "regex", "url", "hyperlink" ]
replace URLs in text with links to URLs
1,727,535
<p>Using Python I want to replace all URLs in a body of text with links to those URLs, like what Gmail does. Can this be done in a one liner regular expression?</p> <p>Edit: by body of text I just meant plain text - no HTML</p>
5
2009-11-13T06:39:27Z
6,513,840
<p>I hunted around a lot, tried these solutions and was not happy with their readability or features, so I rolled the following:</p> <pre><code>_urlfinderregex = re.compile(r'http([^\.\s]+\.[^\.\s]*)+[^\.\s]{2,}') def linkify(text, maxlinklength): def replacewithlink(matchobj): url = matchobj.group(0) ...
4
2011-06-28T22:30:34Z
[ "python", "regex", "url", "hyperlink" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
1,727,685
<p>Here is how I finally did : </p> <pre><code>class UserProfileForm(forms.ModelForm): first_name = forms.CharField(label=_(u'Prénom'), max_length=30) last_name = forms.CharField(label=_(u'Nom'), max_length=30) def __init__(self, *args, **kw): super(UserProfileForm, self).__init__(*args, **kw) ...
32
2009-11-13T07:25:30Z
[ "python", "django", "profile", "django-forms" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
1,727,895
<p>I take it normal that you don't find any information in the docs as you merge two models into a single form. </p> <p>Alternatively and maybe very obviously you can: Create two modelforms, one for the user and the other for the userprofile. Set the userprofile modelform to display only firstname and lastname. Put bo...
0
2009-11-13T08:28:13Z
[ "python", "django", "profile", "django-forms" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
1,876,101
<p>This is how I did it in the current trunk (Revision: 11804). The solution of Natim was not working for me.</p> <p>In <code>admin.py</code>:</p> <pre><code>class ProfileAdmin(admin.ModelAdmin): form = ProfileForm def save_model(self, request, obj, form, change): obj.user.first_name = form.cleaned_d...
5
2009-12-09T19:06:26Z
[ "python", "django", "profile", "django-forms" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
1,876,244
<p>Why not have two model forms on the back-end and just present them as a single form in your template? Drop the name fields from your UserProfileForm and create a second model form for the user object?</p>
0
2009-12-09T19:31:09Z
[ "python", "django", "profile", "django-forms" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
2,193,871
<p>You can also try to use the django-basic-apps project which has a profiles app:</p> <p><a href="https://github.com/nathanborror/django-basic-apps" rel="nofollow">https://github.com/nathanborror/django-basic-apps</a></p>
2
2010-02-03T17:20:51Z
[ "python", "django", "profile", "django-forms" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
2,213,802
<p>I stumbled across this today and after some googling I found a solution that is a bit cleaner in my opinion: </p> <pre><code>#in forms.py class UserForm(forms.ModelForm): class Meta: model = User fields = ["username", "email"] class UserProfileForm(forms.ModelForm): class Meta: mode...
32
2010-02-06T16:39:02Z
[ "python", "django", "profile", "django-forms" ]
How to create a UserProfile form in Django with first_name, last_name modifications?
1,727,564
<p>If think my question is pretty obvious and almost every developer working with UserProfile should be able to answer it.</p> <p>However, I could not find any help on the django documentation or in the Django Book.</p> <p>When you want to do a UserProfile form in with Django Forms, you'd like to modify the profile f...
19
2009-11-13T06:46:24Z
24,585,435
<p>This is something i used in one my projects long back hopefully it should help out the others googling this problem .</p> <pre><code>class SignUpForm(forms.ModelForm): first_name = forms.CharField(max_length = 30) last_name = forms.CharField(max_length = 30) username = forms.CharField(max_length = 30) ...
1
2014-07-05T10:26:24Z
[ "python", "django", "profile", "django-forms" ]
Problem with pexpect and 'chained' function calls
1,727,591
<p>The class below is designed to manipulate a cisco-like device interface, for the purpose of executing commands and updating configuration elements.</p> <p>As is currently stands, I can instantiate the class, make a call to the <code>ssh_to_aos_expsh</code> function and get back valid output (e.g. get the config whe...
0
2009-11-13T06:54:47Z
1,727,836
<p>I would guess that the timeout happens because <code>ssh_to_aos_config()</code> does not get all the input it expects: the call to <code>ssh_to_aos_expsh()</code> might well work, while subsequent calls to <code>expect</code> would not.</p> <p>So a question would be: <em>where</em> does the timeout happen? You cou...
0
2009-11-13T08:14:37Z
[ "python", "pexpect" ]
Problem with pexpect and 'chained' function calls
1,727,591
<p>The class below is designed to manipulate a cisco-like device interface, for the purpose of executing commands and updating configuration elements.</p> <p>As is currently stands, I can instantiate the class, make a call to the <code>ssh_to_aos_expsh</code> function and get back valid output (e.g. get the config whe...
0
2009-11-13T06:54:47Z
1,727,885
<p>If you are getting a timeout it is because you are not getting any of the strings you are expecting. It may be that you are getting an error message instead, or the prompt you are expecting is wrong.</p> <p>Enable logging to see the whole interaction - in pexpect 2.3 this is done by assigning a file object to the ...
0
2009-11-13T08:26:03Z
[ "python", "pexpect" ]
Problem with pexpect and 'chained' function calls
1,727,591
<p>The class below is designed to manipulate a cisco-like device interface, for the purpose of executing commands and updating configuration elements.</p> <p>As is currently stands, I can instantiate the class, make a call to the <code>ssh_to_aos_expsh</code> function and get back valid output (e.g. get the config whe...
0
2009-11-13T06:54:47Z
1,740,288
<p>It turns out that there were two problems, both easy to fix once I knew what the issues were. First, the <code>__init__</code> method contains no <code>self.aos_config_prompt</code> - something which the pexpect exception stated pretty clearly when I commented out my exception handling code. Second, given a <code>...
1
2009-11-16T05:45:46Z
[ "python", "pexpect" ]
Optimal datafile format loading on a game console
1,727,594
<p>I need to load large models and other structured binary data on an older CD-based game console as efficiently as possible. What's the best way to do it? The data will be exported from a Python application. This is a pretty elaborate hobby project.</p> <p>Requierements:</p> <ul> <li>no reliance on fully standard co...
3
2009-11-13T06:56:11Z
1,727,732
<p>Consider storing your data as BLOBs in a SQLite DB. SQLite is extremely portable and lighweight, ANSI C, has both C++ and Python interfaces. This will take care of large files, no fragmentation, variable-length records with fast access, and so on. The rest is just serialization of structs to these BLOBs.</p>
0
2009-11-13T07:40:50Z
[ "c++", "python", "embedded", "playstation" ]
Optimal datafile format loading on a game console
1,727,594
<p>I need to load large models and other structured binary data on an older CD-based game console as efficiently as possible. What's the best way to do it? The data will be exported from a Python application. This is a pretty elaborate hobby project.</p> <p>Requierements:</p> <ul> <li>no reliance on fully standard co...
3
2009-11-13T06:56:11Z
1,728,071
<p>On platforms like the Nintendo GameCube and DS, 3D models are usually stored in a very simple custom format:</p> <ul> <li>A brief header, containing a magic number identifying the file, the number of vertices, normals, etc., and optionally a checksum of the data following the header (Adler-32, CRC-16, etc).</li> <l...
4
2009-11-13T09:13:56Z
[ "c++", "python", "embedded", "playstation" ]
Optimal datafile format loading on a game console
1,727,594
<p>I need to load large models and other structured binary data on an older CD-based game console as efficiently as possible. What's the best way to do it? The data will be exported from a Python application. This is a pretty elaborate hobby project.</p> <p>Requierements:</p> <ul> <li>no reliance on fully standard co...
3
2009-11-13T06:56:11Z
1,728,074
<p>I note that nowhere in your description do you ask for "ease of programming". :-)</p> <p>Thus, here's what comes to mind for me as a way of creating this:</p> <ul> <li><p>The data should be in the same on-disk format as it would be in the target's memory, such that it can simply pull blobs from disk into memory w...
3
2009-11-13T09:14:45Z
[ "c++", "python", "embedded", "playstation" ]
Optimal datafile format loading on a game console
1,727,594
<p>I need to load large models and other structured binary data on an older CD-based game console as efficiently as possible. What's the best way to do it? The data will be exported from a Python application. This is a pretty elaborate hobby project.</p> <p>Requierements:</p> <ul> <li>no reliance on fully standard co...
3
2009-11-13T06:56:11Z
1,733,370
<p>This is a common game development pattern.</p> <p>The usual approach is to cook the data in an offline pre-process step. The resulting blobs can be streamed in with minimal overhead. The blobs are platform dependent and should contain the proper alignment &amp; endian-ness of the target platform.</p> <p>At runti...
3
2009-11-14T05:25:59Z
[ "c++", "python", "embedded", "playstation" ]
Contruct 3d array in numpy from existing 2d array
1,727,669
<p>during preparing data for numpy calculate ,i curious about way to contruct </p> <pre><code>myarray.shape =&gt; (2,18,18) </code></pre> <p>from </p> <pre><code>d1.shape =&gt; (18,18) d2.shape =&gt; (18,18) </code></pre> <p>i try to use numpy command</p> <pre><code>hstack([[d1],[d2]]) </code></pre> <p>but it loo...
5
2009-11-13T07:20:38Z
1,727,700
<p>Just doing <code>d3 = array([d1,d2])</code> seems to work for me:</p> <pre><code>&gt;&gt;&gt; from numpy import array &gt;&gt;&gt; # ... create d1 and d2 ... &gt;&gt;&gt; d1.shape (18,18) &gt;&gt;&gt; d2.shape (18,18) &gt;&gt;&gt; d3 = array([d1, d2]) &gt;&gt;&gt; d3.shape (2, 18, 18) </code></pre>
14
2009-11-13T07:31:25Z
[ "python", "numpy" ]
Contruct 3d array in numpy from existing 2d array
1,727,669
<p>during preparing data for numpy calculate ,i curious about way to contruct </p> <pre><code>myarray.shape =&gt; (2,18,18) </code></pre> <p>from </p> <pre><code>d1.shape =&gt; (18,18) d2.shape =&gt; (18,18) </code></pre> <p>i try to use numpy command</p> <pre><code>hstack([[d1],[d2]]) </code></pre> <p>but it loo...
5
2009-11-13T07:20:38Z
1,728,092
<p>hstack and vstack do no change the number of dimensions of the arrays: they merely put them "side by side". Thus, combining 2-dimensional arrays creates a new 2-dimensional array (not a 3D one!).</p> <p>You can do what Daniel suggested.</p> <p>You can alternatively convert your arrays to 3D arrays before stacking...
3
2009-11-13T09:18:39Z
[ "python", "numpy" ]
Just Curious about Python+Numpy to Realtime Gesture Recognition
1,727,950
<p>i 'm just finish labs meeting with my advisor, previous code is written in matlab and it run offline mode not realtime mode, so i decide to convert to python+numpy (in offline version) but after labs meeting, my advisor raise issue about <strong>speed of realtime recognition</strong>, so i have doubt about speed of ...
2
2009-11-13T08:43:51Z
1,728,488
<p>NumPy is very fast if you follow some basic rules. You should avoid Python loops, using the operators provided by NumPy instead whenever you can. <a href="http://www.scipy.org/NumPy%5Ffor%5FMatlab%5FUsers" rel="nofollow">This</a> and <a href="http://www.scipy.org/PerformancePython" rel="nofollow">this </a>should be ...
3
2009-11-13T10:47:33Z
[ "python", "c", "numpy", "gesture-recognition" ]
Just Curious about Python+Numpy to Realtime Gesture Recognition
1,727,950
<p>i 'm just finish labs meeting with my advisor, previous code is written in matlab and it run offline mode not realtime mode, so i decide to convert to python+numpy (in offline version) but after labs meeting, my advisor raise issue about <strong>speed of realtime recognition</strong>, so i have doubt about speed of ...
2
2009-11-13T08:43:51Z
1,730,684
<p>I think the answer depends on three things: how well you code in Matlab, how well you code in Python/Numpy, and your algorithm. Both Matlab and Python can be fast for number crunching if you're diligent about vectorizing everything and using library calls.</p> <p>If your Matlab code is already very good I would be...
1
2009-11-13T17:18:28Z
[ "python", "c", "numpy", "gesture-recognition" ]
Just Curious about Python+Numpy to Realtime Gesture Recognition
1,727,950
<p>i 'm just finish labs meeting with my advisor, previous code is written in matlab and it run offline mode not realtime mode, so i decide to convert to python+numpy (in offline version) but after labs meeting, my advisor raise issue about <strong>speed of realtime recognition</strong>, so i have doubt about speed of ...
2
2009-11-13T08:43:51Z
1,789,483
<p>You might look at <a href="http://en.wikipedia.org/wiki/OpenCV" rel="nofollow">OpenCV</a>, which has Python libs <a href="http://code.google.com/p/ctypes-opencv" rel="nofollow">ctypes-opencv</a> and <a href="http://code.google.com/p/opencv-cython" rel="nofollow">opencv-cython</a>; I haven't used these myself. Ideall...
0
2009-11-24T11:29:11Z
[ "python", "c", "numpy", "gesture-recognition" ]
Seeking a High-Level Library for Socket Programming (Java or Python)
1,728,266
<p>In short I'm creating a Flash based multiplayer game and I'm now starting to work on the server-side code. Well I'm the sole developer of the project so I'm seeking a high-level socket library that works well with games to speed up my development time.</p> <p>I was trying to use the Twisted Framework (for Python) ...
5
2009-11-13T09:55:41Z
1,728,302
<p>High-level on one side and raw binary sockets on the other won't work. Sorry, but you'll need to go low-level on the server side too.</p> <p>EDIT: in response to the OP's comment. I am not aware of any "high level" interface of the nature that you are talking about for Java. And frankly I don't think it makes a ...
0
2009-11-13T10:06:02Z
[ "java", "python", "sockets" ]
Seeking a High-Level Library for Socket Programming (Java or Python)
1,728,266
<p>In short I'm creating a Flash based multiplayer game and I'm now starting to work on the server-side code. Well I'm the sole developer of the project so I'm seeking a high-level socket library that works well with games to speed up my development time.</p> <p>I was trying to use the Twisted Framework (for Python) ...
5
2009-11-13T09:55:41Z
1,728,348
<p>See <a href="http://csciun1.mala.bc.ca:8080/~wesselsd/guides/ActionScript.html" rel="nofollow">"A Quick Guide to ActionScript 3 and Flash Programming"</a>. It has a detailed example of an ActionScript client code using sockets to communicate with a Python server (code included). Not what anyone will call <em>high-le...
0
2009-11-13T10:18:18Z
[ "java", "python", "sockets" ]
Seeking a High-Level Library for Socket Programming (Java or Python)
1,728,266
<p>In short I'm creating a Flash based multiplayer game and I'm now starting to work on the server-side code. Well I'm the sole developer of the project so I'm seeking a high-level socket library that works well with games to speed up my development time.</p> <p>I was trying to use the Twisted Framework (for Python) ...
5
2009-11-13T09:55:41Z
1,728,556
<p>An option for Python is the <a href="http://opensource.hyves.org/concurrence/">Concurrence</a> framework. I used it fairly recently, in conjunction with <a href="http://www.stackless.com/">Stackless Python</a>, to simulate an environment in which there were potentially thousands of requests per second, each of which...
7
2009-11-13T11:04:55Z
[ "java", "python", "sockets" ]
Seeking a High-Level Library for Socket Programming (Java or Python)
1,728,266
<p>In short I'm creating a Flash based multiplayer game and I'm now starting to work on the server-side code. Well I'm the sole developer of the project so I'm seeking a high-level socket library that works well with games to speed up my development time.</p> <p>I was trying to use the Twisted Framework (for Python) ...
5
2009-11-13T09:55:41Z
1,728,597
<p>For java there is <a href="http://mina.apache.org/" rel="nofollow">Apache mina</a> and <a href="https://grizzly.dev.java.net/" rel="nofollow">Grizzly</a> frameworks both of those really simplify work with sockets</p>
0
2009-11-13T11:14:12Z
[ "java", "python", "sockets" ]
How to get process's grandparent id
1,728,330
<p>How can i get process id of the current process's parent?<br> In general given a process id how can I get its parent process id?<br> e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,</p> <p>My target is linux(ubuntu) so platform specific answers are ok.<...
4
2009-11-13T10:13:58Z
1,728,361
<p>I do not think you can do this portably in the general case.</p> <p>You need to get this information from the process list (e.g. through the <code>ps</code> command), which is obtained in a system-specific way.</p>
0
2009-11-13T10:21:02Z
[ "python", "linux", "process", "subprocess" ]
How to get process's grandparent id
1,728,330
<p>How can i get process id of the current process's parent?<br> In general given a process id how can I get its parent process id?<br> e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,</p> <p>My target is linux(ubuntu) so platform specific answers are ok.<...
4
2009-11-13T10:13:58Z
1,728,386
<p>linux specific:</p> <pre><code>os.popen("ps -p %d -oppid=" % os.getppid()).read().strip() </code></pre>
7
2009-11-13T10:27:35Z
[ "python", "linux", "process", "subprocess" ]
How to get process's grandparent id
1,728,330
<p>How can i get process id of the current process's parent?<br> In general given a process id how can I get its parent process id?<br> e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,</p> <p>My target is linux(ubuntu) so platform specific answers are ok.<...
4
2009-11-13T10:13:58Z
1,728,409
<p>I don't think you can do this in a portable Python fashion. But there are two possibilities.</p> <ol> <li>The information is available from the <code>ps</code> command so you could analyze that.</li> <li>If you have a system with the <code>proc</code> file systems, you can open the file <code>/proc/&lt;pid&gt;/stat...
3
2009-11-13T10:31:48Z
[ "python", "linux", "process", "subprocess" ]
How to get process's grandparent id
1,728,330
<p>How can i get process id of the current process's parent?<br> In general given a process id how can I get its parent process id?<br> e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,</p> <p>My target is linux(ubuntu) so platform specific answers are ok.<...
4
2009-11-13T10:13:58Z
1,728,623
<p>If you have a POSIX-compliant 'ps' command, which allows you to specify the columns you want, like this: <code>ps -o pid,ppid</code></p> <p>You could then try:</p> <pre><code>import os import re ps = os.popen("ps -o pid,ppid") ps.readline() # discard header lines = ps.readlines() ps.close procs = [ re.split("...
0
2009-11-13T11:18:14Z
[ "python", "linux", "process", "subprocess" ]
How to get process's grandparent id
1,728,330
<p>How can i get process id of the current process's parent?<br> In general given a process id how can I get its parent process id?<br> e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,</p> <p>My target is linux(ubuntu) so platform specific answers are ok.<...
4
2009-11-13T10:13:58Z
1,732,073
<pre><code>from __future__ import with_statement def pnid(pid=None, N=1): "Get parent (if N==1), grandparent (if N==2), ... of pid (or self if not given)" if pid is None: pid= "self" while N &gt; 0: filename= "/proc/%s/status" % pid with open(filename, "r") as fp: for l...
2
2009-11-13T21:35:02Z
[ "python", "linux", "process", "subprocess" ]
How to get process's grandparent id
1,728,330
<p>How can i get process id of the current process's parent?<br> In general given a process id how can I get its parent process id?<br> e.g. os.getpid() can be used to get the proccess id, and os.getppid() for the parent, how do I get grandparent,</p> <p>My target is linux(ubuntu) so platform specific answers are ok.<...
4
2009-11-13T10:13:58Z
4,229,596
<p>By using psutil ( <a href="https://github.com/giampaolo/psutil" rel="nofollow">https://github.com/giampaolo/psutil</a> ):</p> <pre><code>&gt;&gt;&gt; import psutil, os &gt;&gt;&gt; psutil.Process(os.getpid()).ppid() 2335 &gt;&gt;&gt; psutil.Process(os.getpid()).parent &lt;psutil.Process (pid=2335, name='bash', cmdl...
17
2010-11-19T21:36:35Z
[ "python", "linux", "process", "subprocess" ]
Optimal / best pratice to maintain continuos connection between Python and Postgresql using Psycopg2
1,728,350
<p>I'm writing an application in Python with Postgresql 8.3 which runs on several machines on a local network.</p> <p>All machines</p> <p>1) fetch huge amount of data from the database server ( lets say database gets 100 different queries from a machine with in 2 seconds time) and there are about 10 or 11 machines do...
2
2009-11-13T10:18:55Z
1,729,623
<p>This sounds a bit like your DB server might have some problems, especially if your database server literally crashes. I'd start by trying to figure out from logs what is the root cause of the problems. It could be something like running out of memory, but it could also happen because of faulty hardware.</p> <p>If y...
1
2009-11-13T14:39:45Z
[ "python", "linux", "performance", "postgresql", "out-of-memory" ]
Optimal / best pratice to maintain continuos connection between Python and Postgresql using Psycopg2
1,728,350
<p>I'm writing an application in Python with Postgresql 8.3 which runs on several machines on a local network.</p> <p>All machines</p> <p>1) fetch huge amount of data from the database server ( lets say database gets 100 different queries from a machine with in 2 seconds time) and there are about 10 or 11 machines do...
2
2009-11-13T10:18:55Z
1,734,657
<p>The most likely cause indeed sounds like running out of memory. If these are Linux servers, triggering an out-of-memory condition invokes the "OOM-killer", which simply terminates the memory hog processes (hence "server aborted process abnormally"). A low-memory situation often means very high disk swapping/paging l...
1
2009-11-14T16:01:47Z
[ "python", "linux", "performance", "postgresql", "out-of-memory" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
1,728,414
<p>You could <a href="http://stackoverflow.com/questions/1707709/is-there-a-straightforward-way-to-find-all-the-modules-that-are-part-of-a-python/1707786#1707786">use a technique</a> to list all modules in the <code>encodings</code> package.</p> <pre><code>import pkgutil import encodings false_positives = set(["alias...
9
2009-11-13T10:32:22Z
[ "python", "unicode", "encoding", "character-encoding" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
1,728,418
<p>I doubt there is such method/functionality in codecs module, but if you see <code>encoding/__init__.py</code>, search function searches thru encodings modules folder, so you may do the same e.g.</p> <pre><code>&gt;&gt;&gt; os.listdir(os.path.dirname(encodings.__file__)) ['cp500.pyc', 'utf_16_le.py', 'gb18030.py', '...
2
2009-11-13T10:34:19Z
[ "python", "unicode", "encoding", "character-encoding" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
1,728,428
<p>Probably you can do this:</p> <pre><code>from encodings.aliases import aliases print aliases.keys()</code></pre>
1
2009-11-13T10:36:06Z
[ "python", "unicode", "encoding", "character-encoding" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
1,736,533
<p><strong>Unfortunately <code>encodings.aliases.aliases.keys()</code> is NOT an appropriate answer.</strong></p> <p><code>aliases</code>(as one would/should expect) contains several cases where different keys are mapped to the same value e.g. <code>1252</code> and <code>windows_1252</code> are both mapped to <code>cp...
17
2009-11-15T04:08:22Z
[ "python", "unicode", "encoding", "character-encoding" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
1,779,263
<p>Maybe you should try using the <a href="https://pypi.python.org/pypi/chardet">Universal Encoding Detector</a> (chardet) library instead of implementing it yourself.</p> <pre><code>&gt;&gt;&gt; import chardet &gt;&gt;&gt; s = '\xe2\x98\x83' # ☃ &gt;&gt;&gt; chardet.detect(s) {'confidence': 0.505, 'encoding': 'utf-...
12
2009-11-22T17:03:09Z
[ "python", "unicode", "encoding", "character-encoding" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
25,151,415
<p>The Python source code has a script at <code>Tools/unicode/listcodecs.py</code> which lists all codecs.</p> <p>Among the listed codecs, however, there are some that are not Unicode-to-byte converters, like <code>base64_codec</code>, <code>quopri_codec</code> and <code>bz2_codec</code>, as @John Machin pointed out.<...
1
2014-08-06T02:39:12Z
[ "python", "unicode", "encoding", "character-encoding" ]
Get a list of all the encodings Python can encode to
1,728,376
<p>I am writing a script that will try encoding bytes into many different encodings in Python 2.6. Is there some way to get a list of available encodings that I can iterate over?</p> <p>The reason I'm trying to do this is because a user has some text that is not encoded correctly. There are funny characters. I know th...
38
2009-11-13T10:24:29Z
25,584,253
<p>Other answers here seem to indicate that constructing this list <em>programmatically</em> is difficult and fraught with traps. However, doing so is probably unnecessary since the documentation contains a complete list of the <a href="https://docs.python.org/2/library/codecs.html#standard-encodings">standard encoding...
15
2014-08-30T15:59:40Z
[ "python", "unicode", "encoding", "character-encoding" ]
Local timezone problem in GAE working with Google Data API
1,728,415
<p>I am working in a small app in the Google App Engine (Python), which uses the Google Data API in order to create a new calendar in a Google account and populate it with some events.</p> <p>The events that I am using are parsed from another place, and they have the date in the Europe/Stockholm timezone, (I think it ...
1
2009-11-13T10:33:02Z
1,745,149
<p>after parsing your object into datetime, you have to add timezone. for that you need to create class derived from the datetime.tzinfo</p> <pre> import datetime as dt class SomeZone(dt.tzinfo): # a helper class to quickly create simple timezones - give gmt_offset def __init__(self, gmt_offset): dt.tz...
0
2009-11-16T22:04:56Z
[ "python", "google-app-engine", "gdata-api" ]
Local timezone problem in GAE working with Google Data API
1,728,415
<p>I am working in a small app in the Google App Engine (Python), which uses the Google Data API in order to create a new calendar in a Google account and populate it with some events.</p> <p>The events that I am using are parsed from another place, and they have the date in the Europe/Stockholm timezone, (I think it ...
1
2009-11-13T10:33:02Z
1,800,807
<p>I posted <a href="http://www.letsyouandhimfight.com/2008/04/12/time-zones-in-google-app-engine" rel="nofollow">something related to this subject on my blog</a> last year. Basically, it converts all times to UTC when storing them in the datastore, and attaches the UTC timezone to them when read out. You can feel free...
1
2009-11-26T00:04:26Z
[ "python", "google-app-engine", "gdata-api" ]
Thread & Queue vs Serial performance
1,728,477
<p>I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer. </p> <p>Threaded Script:</p> <pre><cod...
0
2009-11-13T10:46:21Z
1,728,658
<p>Threads are not a magical way to speed up programs - splitting work into threads will usually slow it down unless the program is spending a significant part of its time waiting for I/O. Each new thread adds more overhead to the code in splitting the work up, and more overhead in the OS in switching between threads...
1
2009-11-13T11:26:59Z
[ "python", "performance", "encryption", "multithreading", "queue" ]
Thread & Queue vs Serial performance
1,728,477
<p>I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer. </p> <p>Threaded Script:</p> <pre><cod...
0
2009-11-13T10:46:21Z
1,728,749
<ol> <li><p>It seems like your second version only reads one chunk, while the first version reads the whole file - this would explain the big speedup. <strong>Edit</strong>: Another issue: I just noticed that you run <code>for lines in data</code> for no reason - this would actually encrypt the characters individually,...
1
2009-11-13T11:47:47Z
[ "python", "performance", "encryption", "multithreading", "queue" ]
Thread & Queue vs Serial performance
1,728,477
<p>I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer. </p> <p>Threaded Script:</p> <pre><cod...
0
2009-11-13T10:46:21Z
1,729,226
<p>Threads have a couple different uses:</p> <ol> <li><p>They only provide speedup if they allow you to get multiple pieces of hardware working at the same time on your problem, whether that hardware is CPU cores or disk heads.</p></li> <li><p>They allow you to keep track of multiple sequences of I/O events that would...
0
2009-11-13T13:34:35Z
[ "python", "performance", "encryption", "multithreading", "queue" ]
Thread & Queue vs Serial performance
1,728,477
<p>I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer. </p> <p>Threaded Script:</p> <pre><cod...
0
2009-11-13T10:46:21Z
1,729,762
<p>I watched the presentation that Dave Kirby linked to and tried the example counter which takes more that twice as long to run in two threads:</p> <pre><code>import time from threading import Thread countmax=100000000 def count(n): while n&gt;0: n-=1 def main1(): count(countmax) count(countmax...
1
2009-11-13T15:04:29Z
[ "python", "performance", "encryption", "multithreading", "queue" ]
Thread & Queue vs Serial performance
1,728,477
<p>I though it'll be interesting to look at threads and queues, so I've written 2 scripts, one will break a file up and encrypt each chunk in a thread, the other will do it serially. I'm still very new to python and don't really know why the treading script takes so much longer. </p> <p>Threaded Script:</p> <pre><cod...
0
2009-11-13T10:46:21Z
5,022,204
<p>Just a quick note to update this thread: python 3.2 has a new implementation of the GIL which relieves a lot of the overheads associated with multithreading, but does not eliminate the locking. (i.e. it does not allow you to use more than one core, but it allows you to use multiple threads on that core efficiently)...
0
2011-02-16T21:16:35Z
[ "python", "performance", "encryption", "multithreading", "queue" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,047
<p>Well,</p> <pre><code>if "exam" in "example": print "yes!" </code></pre> <p>Is this an improvement? <strong>No</strong>. You could even add more statements to the body of the <code>if</code>-clause by separating them with a semicolon. I recommend <strong>against</strong> that though.</p>
37
2009-11-13T12:50:41Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,048
<p>More generally, all of the following are valid syntactically:</p> <pre><code>if condition: do_something() if condition: do_something() if condition: do_something() do_something_else() if condition: do_something(); do_something_else() </code></pre> <p>...etc.</p>
15
2009-11-13T12:50:58Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,052
<p>You could do all of that in one line by omitting the <code>example</code> variable:</p> <pre><code>if "exam" in "example": print "yes!" </code></pre>
3
2009-11-13T12:51:12Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,056
<p>Python lets you put the indented clause on the same line if it's only one line:</p> <pre><code>if "exam" in example: print "yes!" def squared(x): return x * x class MyException(Exception): pass </code></pre>
6
2009-11-13T12:51:36Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,068
<p>an example of a language feature that isn't just removing line breaks, although still not convinced this is clearer than the more verbose version</p> <blockquote> <p>a = 1 if x > 15 else 2</p> </blockquote>
10
2009-11-13T12:55:39Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,131
<pre><code>for a in someList: list.append(splitColon.split(a)) </code></pre> <p>You can rewrite the above as:</p> <pre><code>newlist = [splitColon.split(a) for a in someList] </code></pre>
7
2009-11-13T13:10:09Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,213
<p>I've found that in the majority of cases doing block clauses on one line is a bad idea.</p> <p>It will, again as a generality, reduce the quality of the form of the code. High quality code form is a key language feature for python.</p> <p>In some cases python will offer ways todo things on one line that are defin...
35
2009-11-13T13:31:32Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,729,847
<p>Dive into python has a bit where he talks about what he calls the <a href="http://diveintopython.net/power_of_introspection/and_or.html#d0e9975" rel="nofollow">and-or trick</a>, which seems like an effective way to cram complex logic into a single line.</p> <p>Basically, it simulates the ternary operater in c, by g...
0
2009-11-13T15:15:51Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
1,734,101
<p>Older versions of Python would only allow a single simple statement after <code>for ...:</code> <code>if ...:</code> or similar block introductory statements.</p> <p>I see that one can have multiple simple statements on the same line as any of these. However, there are various combinations that don't work. For ex...
2
2009-11-14T12:20:51Z
[ "python", "for-loop", "if-statement" ]
One Line 'If' or 'For'
1,729,034
<p>Every so often on here I see someone's code and what looks to be a 'one-liner', that being a one line statement that performs in the standard way a traditional 'if' statement or 'for' loop works.</p> <p>I've googled around and can't really find what kind of ones you can perform? Can anyone advise and preferably giv...
30
2009-11-13T12:47:59Z
36,832,111
<p>This is an example of "if else" with actions.</p> <pre><code>&gt;&gt;&gt; def fun(num): print 'This is %d' % num &gt;&gt;&gt; fun(10) if 10 &gt; 0 else fun(2) this is 10 OR &gt;&gt;&gt; fun(10) if 10 &lt; 0 else 1 1 </code></pre>
0
2016-04-25T04:37:51Z
[ "python", "for-loop", "if-statement" ]
Django upload_to outside of MEDIA_ROOT
1,729,051
<p>My deployment script overwrites the media and source directories which means I have to move the uploads directory out of the media directory, and replace it after the upload has been extracted.</p> <p>How can I instruct django to upload to /uploads/ instead of /media/?</p> <p>So far I keep getting django Suspiciou...
22
2009-11-13T12:51:06Z
1,729,359
<p>I did the following:</p> <pre><code>from django.core.files.storage import FileSystemStorage upload_storage = FileSystemStorage(location=UPLOAD_ROOT, base_url='/uploads') image = models.ImageField(upload_to='/images', storage=upload_storage) </code></pre> <p><code>UPLOAD_ROOT</code> is defined in my <code>settin...
46
2009-11-13T13:59:54Z
[ "python", "django", "security", "upload", "media" ]
Can Django models use MySQL functions?
1,729,335
<p>Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like the following:</p> <p>On model load: SELECT AES_DECRYPT(fieldname, password) FROM tablename</p> <p>On model save: ...
2
2009-11-13T13:56:25Z
1,729,353
<p>Using <a href="http://code.djangoproject.com/wiki/Signals" rel="nofollow">Django signals</a> you can do stuff when a model instance is saved, but as far as I know you can't trigger anything on read.</p> <p>EDIT: My bad, it seems you <em>can</em> do stuff when initializing a model instance.</p>
0
2009-11-13T13:58:31Z
[ "python", "mysql", "django", "django-models" ]
Can Django models use MySQL functions?
1,729,335
<p>Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like the following:</p> <p>On model load: SELECT AES_DECRYPT(fieldname, password) FROM tablename</p> <p>On model save: ...
2
2009-11-13T13:56:25Z
1,729,391
<p>Instead of on model load, you can create a property on your model, and when the property is accessed, it can read the database:</p> <pre><code>def _get_foobar(self): if not hasattr(self, '_foobar'): cursor = connection.cursor() self._foobar = cursor.execute('SELECT AES_DECRYPT(fieldname, passwo...
6
2009-11-13T14:04:24Z
[ "python", "mysql", "django", "django-models" ]
Can Django models use MySQL functions?
1,729,335
<p>Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like the following:</p> <p>On model load: SELECT AES_DECRYPT(fieldname, password) FROM tablename</p> <p>On model save: ...
2
2009-11-13T13:56:25Z
1,729,554
<p>I would define a <a href="http://docs.djangoproject.com/en/dev/howto/custom-model-fields/" rel="nofollow">custom modelfield</a> for the column you want encrypted/decrypted. Override the <code>to_python</code> method to run the decryption when the model is loaded, and <code>get_db_prep_value</code> to run the encrypt...
4
2009-11-13T14:29:41Z
[ "python", "mysql", "django", "django-models" ]
Can Django models use MySQL functions?
1,729,335
<p>Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like the following:</p> <p>On model load: SELECT AES_DECRYPT(fieldname, password) FROM tablename</p> <p>On model save: ...
2
2009-11-13T13:56:25Z
1,730,111
<p>Here is a working solution, based in part on (<a href="http://www.djangosnippets.org/snippets/824/" rel="nofollow">http://www.djangosnippets.org/snippets/824/</a>):</p> <pre><code>class Employee(models.Model): social_security_number = models.CharField(max_length=32) def _get_ssn(self): cursor = connec...
3
2009-11-13T15:54:52Z
[ "python", "mysql", "django", "django-models" ]
Can Django models use MySQL functions?
1,729,335
<p>Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like the following:</p> <p>On model load: SELECT AES_DECRYPT(fieldname, password) FROM tablename</p> <p>On model save: ...
2
2009-11-13T13:56:25Z
1,730,155
<p>It's definitely hackish, but it seems Django won't let you do it any other way at the moment. It's also worth noting that to_python will be called every time you change the value in python in addition to when it is first loaded.</p> <pre><code>from django.db import connection, models import re class EncryptedFiel...
1
2009-11-13T16:03:04Z
[ "python", "mysql", "django", "django-models" ]
Multiple grids on matplotlib
1,729,995
<p>I'm making plots in python and matplotlib, which I found huge and flexible, till now. The only thing I couldn't find how to do, is to make my plot have multiple grids. I've looked into the <a href="http://matplotlib.sourceforge.net/api/pyplot%5Fapi.html#matplotlib.pyplot.grid">docs</a>, but that's just for line styl...
16
2009-11-13T15:37:39Z
1,730,437
<p>How about something like this (adapted from <a href="http://matplotlib.sourceforge.net/examples/pylab_examples/major_minor_demo1.html">here</a>):</p> <pre><code>from pylab import * from matplotlib.ticker import MultipleLocator, FormatStrFormatter t = arange(0.0, 100.0, 0.1) s = sin(0.1*pi*t)*exp(-t*0.01) ax = sub...
31
2009-11-13T16:44:44Z
[ "python", "matplotlib" ]
Append Row(s) to a NumPy Record Array
1,730,080
<p>Is there a way to append a row to a NumPy rec.array()? For example, </p> <pre><code>x1=np.array([1,2,3,4]) x2=np.array(['a','dd','xyz','12']) x3=np.array([1.1,2,3,4]) r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c') append(r,(5,'cc',43.0),axis=0) </code></pre> <p>The easiest way would to extract all the c...
7
2009-11-13T15:49:38Z
1,730,098
<pre><code>np.core.records.fromrecords(r.tolist()+[(5,'cc',43.)]) </code></pre> <p>Still it does split, this time by rows. Maybe better?</p>
0
2009-11-13T15:52:48Z
[ "python", "numpy" ]
Append Row(s) to a NumPy Record Array
1,730,080
<p>Is there a way to append a row to a NumPy rec.array()? For example, </p> <pre><code>x1=np.array([1,2,3,4]) x2=np.array(['a','dd','xyz','12']) x3=np.array([1.1,2,3,4]) r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c') append(r,(5,'cc',43.0),axis=0) </code></pre> <p>The easiest way would to extract all the c...
7
2009-11-13T15:49:38Z
1,731,228
<p>You can resize numpy arrays in-place. This is faster than converting to lists and then back to numpy arrays, and it uses less memory too.</p> <pre><code>print (r.shape) # (4,) r.resize(5) print (r.shape) # (5,) r[-1] = (5,'cc',43.0) print(r) # [(1, 'a', 1.1000000000000001) # (2, 'dd', 2.0) # (3, 'xyz', 3.0)...
6
2009-11-13T19:10:52Z
[ "python", "numpy" ]
Append Row(s) to a NumPy Record Array
1,730,080
<p>Is there a way to append a row to a NumPy rec.array()? For example, </p> <pre><code>x1=np.array([1,2,3,4]) x2=np.array(['a','dd','xyz','12']) x3=np.array([1.1,2,3,4]) r = np.core.records.fromarrays([x1,x2,x3],names='a,b,c') append(r,(5,'cc',43.0),axis=0) </code></pre> <p>The easiest way would to extract all the c...
7
2009-11-13T15:49:38Z
33,262,643
<p>Extending @unutbu's answer I post a more general function that appends any number of rows:</p> <pre><code>def append_rows(arrayIN, NewRows): """Append rows to numpy recarray. Arguments: arrayIN: a numpy recarray that should be expanded NewRows: list of tuples with the same shape as `arrayIN` ...
0
2015-10-21T14:55:23Z
[ "python", "numpy" ]
list management python
1,730,261
<p>I have extracted some url list and want to manipulate this list. Following is extracted list sample:</p> <pre><code>http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235 http://www.naver.com/rules/service.html http://news.naver.com/main/principle.nhn http://www.naver.com/rules/privacy.html http...
0
2009-11-13T16:19:59Z
1,730,268
<p>If your <code>old</code> list is contains all urls as strings you can use a <a href="http://docs.python.org/tutorial/datastructures.html#list-comprehensions" rel="nofollow">list comprehension</a> to filter them.</p> <pre><code>new = [url for url in old if url.startswith('http://www.naver.com')] </code></pre> <p>Yo...
6
2009-11-13T16:22:04Z
[ "python" ]
list management python
1,730,261
<p>I have extracted some url list and want to manipulate this list. Following is extracted list sample:</p> <pre><code>http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235 http://www.naver.com/rules/service.html http://news.naver.com/main/principle.nhn http://www.naver.com/rules/privacy.html http...
0
2009-11-13T16:19:59Z
1,730,270
<p>You can do this with a <a href="http://www.diveintopython.org/native%5Fdata%5Ftypes/mapping%5Flists.html" rel="nofollow">List Comprehension</a>. These are a very powerful way to work with lists with Python.</p> <p>By adding add an <code>if</code> to the list comprehension <a href="http://www.diveintopython.org/pow...
2
2009-11-13T16:22:34Z
[ "python" ]
list management python
1,730,261
<p>I have extracted some url list and want to manipulate this list. Following is extracted list sample:</p> <pre><code>http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235 http://www.naver.com/rules/service.html http://news.naver.com/main/principle.nhn http://www.naver.com/rules/privacy.html http...
0
2009-11-13T16:19:59Z
1,730,273
<pre><code>urlList = [ ... ] # your list of urls extractedList = [url for url in urlList if url.startswith('http://www.naver.com')] </code></pre>
0
2009-11-13T16:22:48Z
[ "python" ]
list management python
1,730,261
<p>I have extracted some url list and want to manipulate this list. Following is extracted list sample:</p> <pre><code>http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235 http://www.naver.com/rules/service.html http://news.naver.com/main/principle.nhn http://www.naver.com/rules/privacy.html http...
0
2009-11-13T16:19:59Z
1,730,322
<pre><code>result = [] for url in myListOfUrls: if 'http://www.naver.com' in url: result.append(url) </code></pre>
0
2009-11-13T16:30:12Z
[ "python" ]
list management python
1,730,261
<p>I have extracted some url list and want to manipulate this list. Following is extracted list sample:</p> <pre><code>http://help.naver.com/service/svc_index.jsp?selected_nodeId=NODE0000000235 http://www.naver.com/rules/service.html http://news.naver.com/main/principle.nhn http://www.naver.com/rules/privacy.html http...
0
2009-11-13T16:19:59Z
1,730,389
<p>Someone suggested this alternative answer based on <code>filter()</code> but deleted it, I'll post it here again for completeness:</p> <pre><code>newList = filter(lambda url: url.startswith('http://www.naver.com'), oldList) </code></pre> <p>The list comprehension method seems faster though (and in my opinion, more...
0
2009-11-13T16:38:31Z
[ "python" ]
Eclipse smart quotes - like in Textmate
1,730,351
<p>Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the <kbd>"</kbd> key? I'm a newbie here so be gentle. FWIW - I'm using pydev in Eclipse.</p> <p>Thanks</p> <p><strong>Rephrase</strong></p> <p>Wha...
4
2009-11-13T16:33:22Z
1,730,670
<p>I think I know what you are asking, is it that...</p> <p>if you press X-key it will select the current word that the cursor is in?</p> <p>If that is the question, then I don't think so. There are lots of possible keybinding that are not set in eclipse. See Window > Preferences > General > Keys</p> <p>Update:</p>...
0
2009-11-13T17:15:41Z
[ "python", "eclipse", "ide", "development-environment", "pydev" ]
Eclipse smart quotes - like in Textmate
1,730,351
<p>Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the <kbd>"</kbd> key? I'm a newbie here so be gentle. FWIW - I'm using pydev in Eclipse.</p> <p>Thanks</p> <p><strong>Rephrase</strong></p> <p>Wha...
4
2009-11-13T16:33:22Z
1,837,128
<p>For Java and XML files you can create a new template in Window / Preferences / Java / Editor / Templates. The template text could look something like this:</p> <pre><code>"${word_selection}${}"${cursor} </code></pre> <p>Then you can apply this template activate code completion using a standard Ctrl-Space (may have...
2
2009-12-03T01:38:34Z
[ "python", "eclipse", "ide", "development-environment", "pydev" ]
Eclipse smart quotes - like in Textmate
1,730,351
<p>Happy Friday — Does anyone know if eclipse has the notion of smart quotes like Textmate. The way it works is to select some words and quote them by simply hitting the <kbd>"</kbd> key? I'm a newbie here so be gentle. FWIW - I'm using pydev in Eclipse.</p> <p>Thanks</p> <p><strong>Rephrase</strong></p> <p>Wha...
4
2009-11-13T16:33:22Z
3,020,432
<p>You might check out how one of the comment commands work. For example, if I select say 4 lines of code and I want to line comment all of them I can simply select them then hit ctrl+/ and all of the selected lines of code will be commented.</p> <p>I'm a long time textmate user and I'm missing it something terrible. ...
0
2010-06-11T05:40:28Z
[ "python", "eclipse", "ide", "development-environment", "pydev" ]