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 |
|---|---|---|---|---|---|---|---|---|---|
Remove html formating ">" from text file using Python csv.reader | 1,637,253 | <p>I have a text file with ; used as the delimiter. The problem is that it has some html text formating in it such as <code>&gt;</code> Obviously the ; in this causes problems.
The text file is large and I don't have a list of these html strings, that is there are many different examples such as <code>$amp;</code>... | 3 | 2009-10-28T13:30:54Z | 1,991,266 | <p>On most Unix systems (including your Mac OS X), you can recode the input text file with:</p>
<pre><code>recode html.. file_with_html.txt
</code></pre>
<p>This replaces &gt; by ">", etc.</p>
<p>You can call this through Python's subprocess module, for instance.</p>
| 1 | 2010-01-02T10:59:58Z | [
"python",
"html",
"regex",
"file",
"csv"
] |
IDLE and unicode chars (2.5.4) | 1,637,479 | <p>Why does IDLE handle one symbol correctly but not another?</p>
<pre><code>>>> e = 'â¬'
>>> print unichr(ord(e))
# looks like a very thin rectangle on my system.
>>> p = '£'
>>> print unichr(ord(p))
£
>>> ord(e)
128
>>> ord(p)
163
</code></pre>
<p>I trie... | 2 | 2009-10-28T14:09:42Z | 1,637,605 | <p>The answer depends what encoding the IDLE REPL is using. You should be more explicit about what's actually unicode text, and what's a byte sequence. Meditate on this example:</p>
<pre><code># -*- coding: utf-8 -*-
c = u'â¬'
print type(c)
for b in c.encode('utf-8'):
print ord(b)
c = 'â¬'
print type(c)
for b i... | 3 | 2009-10-28T14:28:21Z | [
"python",
"unicode"
] |
IDLE and unicode chars (2.5.4) | 1,637,479 | <p>Why does IDLE handle one symbol correctly but not another?</p>
<pre><code>>>> e = 'â¬'
>>> print unichr(ord(e))
# looks like a very thin rectangle on my system.
>>> p = '£'
>>> print unichr(ord(p))
£
>>> ord(e)
128
>>> ord(p)
163
</code></pre>
<p>I trie... | 2 | 2009-10-28T14:09:42Z | 1,637,662 | <p>The problem is probably that your font doesn't have the proper glyphs. In addition to getting the encoding right, you have to have the proper font when presenting the text in the IDLE ui. Try using a different font to see if it helps (Arial Unicode has a very large glyph complement, for example).</p>
<p>The euro ... | 0 | 2009-10-28T14:34:51Z | [
"python",
"unicode"
] |
Python/Django: Which authorize.net library should I use? | 1,637,902 | <p>I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .</p>
<p>There are quite a few libraries and code snippets around, I'm looking for recom... | 17 | 2009-10-28T15:10:17Z | 2,541,903 | <p>Edit: <a href="https://github.com/agiliq/merchant/blob/master/billing/gateways/authorize_net_gateway.py" rel="nofollow">https://github.com/agiliq/merchant/blob/master/billing/gateways/authorize_net_gateway.py</a>
looks pretty nice, haven't tried it yet.</p>
<p>Edit: [For the next project I have that uses authorize.... | 9 | 2010-03-29T23:20:34Z | [
"python",
"django",
"payment-gateway",
"authorize.net"
] |
Python/Django: Which authorize.net library should I use? | 1,637,902 | <p>I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .</p>
<p>There are quite a few libraries and code snippets around, I'm looking for recom... | 17 | 2009-10-28T15:10:17Z | 5,943,990 | <p>There is always Paython: <a href="https://github.com/abunsen/Paython" rel="nofollow">https://github.com/abunsen/Paython</a></p>
<p>Currently supports 5+ payment gateways:</p>
<ol>
<li>Authorize.net </li>
<li>First Data/Linkpoint</li>
<li>Innovative Gateway (from intuit)</li>
<li>PlugnPay</li>
<li>Stripe</li>
</ol>... | 6 | 2011-05-10T00:41:59Z | [
"python",
"django",
"payment-gateway",
"authorize.net"
] |
Python/Django: Which authorize.net library should I use? | 1,637,902 | <p>I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .</p>
<p>There are quite a few libraries and code snippets around, I'm looking for recom... | 17 | 2009-10-28T15:10:17Z | 7,261,189 | <p>For what it's worth we ended up using the <a href="http://bitbucket.org/adroll/authorize/wiki/Home" rel="nofollow">adroll authorize library</a>. Both Paython and django-authorizenet look interesting, will be checking those out.</p>
| 1 | 2011-08-31T17:50:04Z | [
"python",
"django",
"payment-gateway",
"authorize.net"
] |
Python/Django: Which authorize.net library should I use? | 1,637,902 | <p>I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .</p>
<p>There are quite a few libraries and code snippets around, I'm looking for recom... | 17 | 2009-10-28T15:10:17Z | 12,017,060 | <p>Long story short, none of the existing solutions met my needs. They were either unmaintained, uncommented, untested, or lacked saved cards. So of course I built my own solution and open-sourced it: </p>
<p>AuthorizeSauce: <a href="https://github.com/jeffschenck/authorizesauce">https://github.com/jeffschenck/authori... | 15 | 2012-08-18T08:16:19Z | [
"python",
"django",
"payment-gateway",
"authorize.net"
] |
Python/Django: Which authorize.net library should I use? | 1,637,902 | <p>I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .</p>
<p>There are quite a few libraries and code snippets around, I'm looking for recom... | 17 | 2009-10-28T15:10:17Z | 17,081,399 | <p>I recently wrote this API for Python and Authorize.net after failing to find one that supported all of Authorize.net's functionality.</p>
<p><a href="https://github.com/vcatalano/py-authorize" rel="nofollow">https://github.com/vcatalano/py-authorize</a></p>
| 2 | 2013-06-13T07:21:46Z | [
"python",
"django",
"payment-gateway",
"authorize.net"
] |
Python/Django: Which authorize.net library should I use? | 1,637,902 | <p>I need authorize.net integration for subscription payments, likely using CIM. The requirements are simple - recurring monthly payments, with a few different price points. Customer credit card info will be stored a authorize.net .</p>
<p>There are quite a few libraries and code snippets around, I'm looking for recom... | 17 | 2009-10-28T15:10:17Z | 24,440,798 | <p>I realize this is a bit late, but hopefully it helps others. </p>
<p>I recently came across <code>Py-Authorize</code> which has some great documentation, compared to the other packages available. You can install it via:</p>
<pre><code>pip install Py-Authorize
</code></pre>
<p>It seems to install a dependency (<co... | 1 | 2014-06-26T21:48:05Z | [
"python",
"django",
"payment-gateway",
"authorize.net"
] |
How to check which XP theme is enabled | 1,637,946 | <p>I have a wxPython which works perfectly on window xp theme but on switching to 'classic theme' rich text cntrl comes up without border. I can enable border for classic theme but for that</p>
<p>Q1. I need to know if classic theme is enabled.</p>
<p>Q2.I am also not sure how many different theme could be there whi... | 0 | 2009-10-28T15:19:54Z | 1,638,038 | <p>Classic theming is more of a non theme.
You check for classic theming by calling <a href="http://msdn.microsoft.com/en-us/library/bb759809%28VS.85%29.aspx" rel="nofollow">IsAppThemed</a>() in UxTheme.dll</p>
<p>There should therefore be little reason to worry about different themes.</p>
<p>Lastly, the only choice ... | 1 | 2009-10-28T15:33:21Z | [
"python",
"c",
"windows",
"winapi",
"windows-themes"
] |
Deciphering Python word unscrambler | 1,637,961 | <p>I'm currently trying to dig deep into python and I have found a challenge on (hackthissite.org) that I'm trying to crack. I have to unscramble 10 words that are found in the provided wordlist. </p>
<pre><code>def permutation(s):
if s == "":
return [s]
else:
ans = []
for an in permuta... | 0 | 2009-10-28T15:22:15Z | 1,638,013 | <p>The pseudocode for that looks something like:</p>
<pre><code>Load the word list (dictionary)
Input the words to unscramble
For each word:
Find every permutation of letters in that word (permutation)
For each permutation:
Add this permutation to the solution list if it exists in the dictionary
Print the solu... | 3 | 2009-10-28T15:28:56Z | [
"python"
] |
Deciphering Python word unscrambler | 1,637,961 | <p>I'm currently trying to dig deep into python and I have found a challenge on (hackthissite.org) that I'm trying to crack. I have to unscramble 10 words that are found in the provided wordlist. </p>
<pre><code>def permutation(s):
if s == "":
return [s]
else:
ans = []
for an in permuta... | 0 | 2009-10-28T15:22:15Z | 1,651,248 | <p>There is a much better solution. This code is highly inefficient if there are many long words. A better idea is to sort lexicographically all each word in the dictionary, so that 'god' becomes 'dgo' and do the same for scrambled word. Then it's O(nlogn) for each word instead of O(n!)</p>
| 0 | 2009-10-30T17:32:23Z | [
"python"
] |
Python Class with integer emulation | 1,638,229 | <p>Given is the following example:</p>
<pre><code>class Foo(object):
def __init__(self, value=0):
self.value=value
def __int__(self):
return self.value
</code></pre>
<p>I want to have a class <em>Foo</em>, which acts as an integer (or float). So I want to do the following things:</p>
<pre><c... | 5 | 2009-10-28T16:02:57Z | 1,638,307 | <p>In Python 2.4+ inheriting from int works:</p>
<pre><code>class MyInt(int):pass
f=MyInt(3)
assert f + 5 == 8
</code></pre>
| 7 | 2009-10-28T16:14:38Z | [
"python",
"floating-point",
"integer",
"emulation"
] |
Python Class with integer emulation | 1,638,229 | <p>Given is the following example:</p>
<pre><code>class Foo(object):
def __init__(self, value=0):
self.value=value
def __int__(self):
return self.value
</code></pre>
<p>I want to have a class <em>Foo</em>, which acts as an integer (or float). So I want to do the following things:</p>
<pre><c... | 5 | 2009-10-28T16:02:57Z | 1,638,315 | <p>Try to use an up-to-date version of python. Your code works in 2.6.1.</p>
| 2 | 2009-10-28T16:16:48Z | [
"python",
"floating-point",
"integer",
"emulation"
] |
Python Class with integer emulation | 1,638,229 | <p>Given is the following example:</p>
<pre><code>class Foo(object):
def __init__(self, value=0):
self.value=value
def __int__(self):
return self.value
</code></pre>
<p>I want to have a class <em>Foo</em>, which acts as an integer (or float). So I want to do the following things:</p>
<pre><c... | 5 | 2009-10-28T16:02:57Z | 1,792,072 | <p>You need to override <code>__new__</code>, not <code>__init__</code>:</p>
<pre><code>class Foo(int):
def __new__(cls, some_argument=None, value=0):
i = int.__new__(cls, value)
i._some_argument = some_argument
return i
def print_some_argument(self):
print self._some_argument
... | 5 | 2009-11-24T18:44:15Z | [
"python",
"floating-point",
"integer",
"emulation"
] |
Problem Using Python's subprocess.communicate() on Windows | 1,638,405 | <p>I have an application that I am trying to control via Python and the subprocess module. Essentially what I do is start the application using Popen (which opens a command prompt within which the program executes) and then at some point in time later on in the execution I need to send a string (a command) to the STDI... | 0 | 2009-10-28T16:29:55Z | 1,638,430 | <p>try:</p>
<pre><code>cmd = 'quit\n\r'
</code></pre>
<p>EDIT:</p>
<p>Only thing that is working for me is:</p>
<pre><code>app = subprocess.Popen(["cmd.exe","testparam"],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
app.stdin.write('exit\r\n')
</code></pre>
<p>Because as <a href="http://docs.python.org/library/sub... | 0 | 2009-10-28T16:33:03Z | [
"python",
"subprocess"
] |
Google App Engine and google authentication with redirect and HTTP POST | 1,638,493 | <p>I have a form and I need to send the content to the server.</p>
<p>I use google authentication because only authorized people can send to the server.</p>
<p>The form is somthing like this:</p>
<pre><code><form action="/blog/submit" method="post">
...
</form>
</code></pre>
<p>The authentication is nee... | 0 | 2009-10-28T16:42:23Z | 1,638,804 | <p>No, it's not possible to have POST data follow an HTTP redirect. </p>
<p>You should almost certainly be checking for a login before you display the form that's posting this data in the first place, but once the user gets to the form your best bet is probably to save the content to the datastore linked to a session... | 3 | 2009-10-28T17:27:40Z | [
"python",
"google-app-engine",
"authentication",
"post"
] |
Python bitwise operations confusion | 1,638,604 | <p>I came up with this "magic string" to meet the ID3 tagging specification:</p>
<blockquote>
<p>The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 ... | 0 | 2009-10-28T16:59:11Z | 1,638,685 | <p>I think you are confusing the and and the or operations.</p>
<ul>
<li>bitwise and: return a number with only bits that are in both operands set.</li>
<li>bitwise or: return a number with bits that are in either of the operands set.</li>
</ul>
| 2 | 2009-10-28T17:10:19Z | [
"python",
"bit-manipulation",
"id3"
] |
Python bitwise operations confusion | 1,638,604 | <p>I came up with this "magic string" to meet the ID3 tagging specification:</p>
<blockquote>
<p>The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 ... | 0 | 2009-10-28T16:59:11Z | 1,638,715 | <p>Sorry getting my 7s and Es confused</p>
<p>Corrected code:</p>
<pre><code>>>> str.format('0b{0:07b}{1:07b}{2:07b}{3:07b}', ((hex_val >> 24) & 0x7F),
((hex_val >> 16) & 0x7F),
((hex_val >... | 1 | 2009-10-28T17:13:57Z | [
"python",
"bit-manipulation",
"id3"
] |
Python bitwise operations confusion | 1,638,604 | <p>I came up with this "magic string" to meet the ID3 tagging specification:</p>
<blockquote>
<p>The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a total of 28 bits. The zeroed bits are ignored, so a 257 bytes long tag is represented as $00 00 ... | 0 | 2009-10-28T16:59:11Z | 1,638,731 | <p>It does not equal all ones because you're masking out the 4th bit using the <code>&</code> operator!</p>
| 1 | 2009-10-28T17:16:46Z | [
"python",
"bit-manipulation",
"id3"
] |
is there a way to check if a param contains a class or a class instance? | 1,638,657 | <p>I want the wrapper my_function to be able to receive either a class or class instance, instead of writing two different functions:</p>
<pre><code>>>> from module import MyClass
>>> my_function(MyClass)
True
>>> cls_inst = MyClass()
>>> my_function(cls_inst)
True
</code></pre... | 0 | 2009-10-28T17:07:16Z | 1,638,693 | <p>Use the type() buitlin function.</p>
<p>E.g.:</p>
<pre><code>import avahi
print type(avahi)
<type 'module'>
</code></pre>
| 0 | 2009-10-28T17:10:54Z | [
"python",
"typechecking"
] |
is there a way to check if a param contains a class or a class instance? | 1,638,657 | <p>I want the wrapper my_function to be able to receive either a class or class instance, instead of writing two different functions:</p>
<pre><code>>>> from module import MyClass
>>> my_function(MyClass)
True
>>> cls_inst = MyClass()
>>> my_function(cls_inst)
True
</code></pre... | 0 | 2009-10-28T17:07:16Z | 1,638,695 | <pre><code>>>> class A: pass
>>> isinstance(A, type)
True
>>> isinstance(A(), type)
False
</code></pre>
| 7 | 2009-10-28T17:11:06Z | [
"python",
"typechecking"
] |
is there a way to check if a param contains a class or a class instance? | 1,638,657 | <p>I want the wrapper my_function to be able to receive either a class or class instance, instead of writing two different functions:</p>
<pre><code>>>> from module import MyClass
>>> my_function(MyClass)
True
>>> cls_inst = MyClass()
>>> my_function(cls_inst)
True
</code></pre... | 0 | 2009-10-28T17:07:16Z | 1,638,721 | <pre><code>import types
def myfun(maybe_class):
if type(maybe_class) == types.ClassType:
print "It's a class."
else:
print "It's an instance."
</code></pre>
| 1 | 2009-10-28T17:14:10Z | [
"python",
"typechecking"
] |
SQLAlchemy: relation in mappers compile result of function rather than calling the function when the relation is queried | 1,638,751 | <p>I have a number of mappers that look like this:</p>
<pre><code>mapper(Photo,photo_table, properties = { "locale": relation(PhotoContent, uselist=False, primaryjoin=and_(photo_content_table.c.photoId == photo_table.c.id, photo_content_table.c.locale == get_lang()), foreign_keys=[photo_content_table.c.photoId, photo_... | 1 | 2009-10-28T17:19:31Z | 1,638,879 | <p>The relation statements gets executed when the class is loaded, which means every function call gets evaluated.</p>
<p>Try passing the function instead:</p>
<pre><code>and_(photo_content_table.c.photoId == photo_table.c.id, photo_content_table.c.locale == get_lang)
</code></pre>
<p>Note the missing parenthesis. I... | 2 | 2009-10-28T17:41:53Z | [
"python",
"sqlalchemy",
"pylons"
] |
django generic templates | 1,638,870 | <p>So, Generic views are pretty cool, but what I'm interested in is something that's a generic template.</p>
<p>so for example, I can give it an object and it'll just tostring it for me.</p>
<p>or if I give it a list, it'll just iterate over the objects and tostring them as a ul (or tr, or whatever else it deems nece... | 3 | 2009-10-28T17:40:47Z | 1,639,317 | <p>If there's a django model for it, you can just stick to <code>django.contrib.admin</code> or <code>django.contrib.databrowse</code>. If not, then you might manage by skipping the django template altogether. example:</p>
<pre><code>from django.http import HttpResponse
import datetime
def current_datetime(request)... | 5 | 2009-10-28T18:50:20Z | [
"python",
"django",
"frameworks",
"templating"
] |
django generic templates | 1,638,870 | <p>So, Generic views are pretty cool, but what I'm interested in is something that's a generic template.</p>
<p>so for example, I can give it an object and it'll just tostring it for me.</p>
<p>or if I give it a list, it'll just iterate over the objects and tostring them as a ul (or tr, or whatever else it deems nece... | 3 | 2009-10-28T17:40:47Z | 1,639,340 | <p>I don't see you getting away from writing templates, especially if you would want to format it, even slightly.</p>
<p>However you can re-use basic templates, for e.g, create a generic object_list.html and object_detail.html</p>
<p>that will basically contain the information to loop over the object list and present... | 1 | 2009-10-28T18:53:57Z | [
"python",
"django",
"frameworks",
"templating"
] |
Creating class instance properties from a dictionary in Python | 1,639,174 | <p>I'm importing from a CSV and getting data roughly in the format </p>
<pre><code>{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
</code></pre>
<p>The names of the fields are dynamic. (Well, they're dynamic in that there might be more than Field1 and Field2, but I know Field1 and Field2 are always going t... | 30 | 2009-10-28T18:28:19Z | 1,639,197 | <p>You can use <a href="http://docs.python.org/3.1/library/functions.html#setattr"><code>setattr</code></a> (be careful though: not every string is a valid attribute name!):</p>
<pre><code>>>> class AllMyFields:
... def __init__(self, dictionary):
... for k, v in dictionary.items():
... ... | 46 | 2009-10-28T18:31:01Z | [
"class",
"python",
"komodo"
] |
Creating class instance properties from a dictionary in Python | 1,639,174 | <p>I'm importing from a CSV and getting data roughly in the format </p>
<pre><code>{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
</code></pre>
<p>The names of the fields are dynamic. (Well, they're dynamic in that there might be more than Field1 and Field2, but I know Field1 and Field2 are always going t... | 30 | 2009-10-28T18:28:19Z | 1,639,215 | <pre><code>>>> q = { 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
>>> q = type('allMyFields', (object,), q)
>>> q.Field1
3000
</code></pre>
<p>docs for <a href="http://docs.python.org/library/functions.html#type"><code>type</code></a> explain well what's going here (see use as a ... | 17 | 2009-10-28T18:32:56Z | [
"class",
"python",
"komodo"
] |
Creating class instance properties from a dictionary in Python | 1,639,174 | <p>I'm importing from a CSV and getting data roughly in the format </p>
<pre><code>{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
</code></pre>
<p>The names of the fields are dynamic. (Well, they're dynamic in that there might be more than Field1 and Field2, but I know Field1 and Field2 are always going t... | 30 | 2009-10-28T18:28:19Z | 1,639,249 | <p>You can also use <code>dict.update</code> instead of manually looping over <code>items</code> (and if you're looping, <code>iteritems</code> is better).</p>
<pre><code>class allMyFields(object):
# note: you cannot (and don't have to) use self here
Field1 = None
Field2 = None
def __init__(self, dict... | 4 | 2009-10-28T18:37:28Z | [
"class",
"python",
"komodo"
] |
Creating class instance properties from a dictionary in Python | 1,639,174 | <p>I'm importing from a CSV and getting data roughly in the format </p>
<pre><code>{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
</code></pre>
<p>The names of the fields are dynamic. (Well, they're dynamic in that there might be more than Field1 and Field2, but I know Field1 and Field2 are always going t... | 30 | 2009-10-28T18:28:19Z | 1,639,251 | <p>Use setattr for the pretty way. The quick-n-dirty way is to update the instance internal dictionary:</p>
<pre><code>>>> class A(object):
... pass
...
>>> a = A()
>>> a.__dict__.update({"foo": 1, "bar": 2})
>>> a.foo
1
>>> a.bar
2
>>>
</code></pre>
| 1 | 2009-10-28T18:37:31Z | [
"class",
"python",
"komodo"
] |
Creating class instance properties from a dictionary in Python | 1,639,174 | <p>I'm importing from a CSV and getting data roughly in the format </p>
<pre><code>{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
</code></pre>
<p>The names of the fields are dynamic. (Well, they're dynamic in that there might be more than Field1 and Field2, but I know Field1 and Field2 are always going t... | 30 | 2009-10-28T18:28:19Z | 1,639,406 | <p>Using named tuples (Python 2.6):</p>
<pre><code>>>> from collections import namedtuple
>>> the_dict = {'Field1': 3, 'Field2': 'b', 'foo': 4.9}
>>> fields = ' '.join(the_dict.keys())
>>> AllMyFields = namedtuple('AllMyFields', fields)
>>> instance = AllMyFields(**the_dic... | 4 | 2009-10-28T19:05:09Z | [
"class",
"python",
"komodo"
] |
Creating class instance properties from a dictionary in Python | 1,639,174 | <p>I'm importing from a CSV and getting data roughly in the format </p>
<pre><code>{ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 }
</code></pre>
<p>The names of the fields are dynamic. (Well, they're dynamic in that there might be more than Field1 and Field2, but I know Field1 and Field2 are always going t... | 30 | 2009-10-28T18:28:19Z | 1,639,632 | <p>You could make a subclass of <code>dict</code> which allows attribute lookup for keys:</p>
<pre><code>class AttributeDict(dict):
def __getattr__(self, name):
return self[name]
q = AttributeDict({ 'Field1' : 3000, 'Field2' : 6000, 'RandomField' : 5000 })
print q.Field1
print q.Field2 ... | 2 | 2009-10-28T19:46:35Z | [
"class",
"python",
"komodo"
] |
Jython 2.5.1: "ImportError: No Module named os" | 1,639,294 | <p>I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).</p>
<p>I'm running a script that uses t... | 8 | 2009-10-28T18:45:29Z | 1,639,353 | <p>Something is wrong at a very deep level, but it's probably easy to fix. You are seeing an error that happens while trying to report some other error.</p>
<p>Probably you have your PYTHONPATH misconfigured. I don't know the details of Jython or Eclipse running Jython, but it looks like you have no standard library... | 1 | 2009-10-28T18:56:57Z | [
"python",
"import",
"jython"
] |
Jython 2.5.1: "ImportError: No Module named os" | 1,639,294 | <p>I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).</p>
<p>I'm running a script that uses t... | 8 | 2009-10-28T18:45:29Z | 1,639,436 | <p>What do you mean with "<em>the jar that comes with the 2.5 download</em>"? Did you extract the contents and use <code>jython.jar</code> or did you run the installer? If you just extracted and didn't run the installer your <code>jython.jar</code> will miss the whole <code>LIB</code> folder.</p>
<p>Can you check if <... | 6 | 2009-10-28T19:09:26Z | [
"python",
"import",
"jython"
] |
Jython 2.5.1: "ImportError: No Module named os" | 1,639,294 | <p>I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).</p>
<p>I'm running a script that uses t... | 8 | 2009-10-28T18:45:29Z | 16,245,590 | <p>If you are getting maven, using the dependency <code>jython-standalone</code> instead of <code>jython</code> may help (at least it did for me in a maven project with jython-standalone-2.5.3) </p>
| 1 | 2013-04-26T21:35:54Z | [
"python",
"import",
"jython"
] |
Django ignoring my DATABASE_ENGINE setting -- sometimes | 1,639,451 | <p>I've got several sites, each with a distinct settings file -- and with distinct names. There's a floral theme to all the variant settings. We have to keep the sites separate.</p>
<pre><code>C:\Proj-Carnation> echo %DJANGO_SETTINGS_MODULE%
path.to.settings_carnation_win32
</code></pre>
<p>We have many test pro... | -3 | 2009-10-28T19:12:36Z | 1,649,915 | <p>Found it.</p>
<p>When your settings module is inside a package, the top-level <code>__init__.py</code> member of that package cannot import any Django material of any kind.</p>
<p>If the top-level <code>__init__.py</code> that contains your settings has a Django import, that Django import will (potentially) use th... | 9 | 2009-10-30T13:48:07Z | [
"python",
"django",
"configuration"
] |
matplotlib border width | 1,639,463 | <p>I use matplotlib 0.99.</p>
<p>I am not able to change width of border of <code>subplot</code>, how can I do it? </p>
<p>Code is as follows:</p>
<pre><code>fig = plt.figure(figsize = (4.1, 2.2))
ax = fig.add_subplot(111)
ax.patch.set_ linewidth(0.1)
ax.get_frame().set_linewidth(0.1)
</code></pre>
<p>The last t... | 7 | 2009-10-28T19:14:57Z | 1,646,208 | <p>You want to adjust the border line size? You need to use ax.spines[side].set_linewidth(size). </p>
<p>So something like:</p>
<pre><code>[i.set_linewidth(0.1) for i in ax.spines.itervalues()]
</code></pre>
| 12 | 2009-10-29T20:01:47Z | [
"python",
"width",
"matplotlib",
"border"
] |
matplotlib border width | 1,639,463 | <p>I use matplotlib 0.99.</p>
<p>I am not able to change width of border of <code>subplot</code>, how can I do it? </p>
<p>Code is as follows:</p>
<pre><code>fig = plt.figure(figsize = (4.1, 2.2))
ax = fig.add_subplot(111)
ax.patch.set_ linewidth(0.1)
ax.get_frame().set_linewidth(0.1)
</code></pre>
<p>The last t... | 7 | 2009-10-28T19:14:57Z | 20,009,598 | <p>Maybe this is what you are looking for?</p>
<p><code>import matplotlib as mpl</code></p>
<p><code>mpl.rcParams['axes.linewidth'] = 0.1 #set the value globally</code></p>
| 2 | 2013-11-15T20:02:01Z | [
"python",
"width",
"matplotlib",
"border"
] |
Logging events in Python; How to log events inside classes? | 1,639,468 | <p>I built (just for fun) 3 classes to help me log some events in my work.</p>
<p>here are them:</p>
<pre><code>class logMessage:
def __init__(self,objectName,message,messageType):
self.objectName = objectName
self.message = message
self.messageType = messageType
self.dateTime = d... | 0 | 2009-10-28T19:15:41Z | 1,639,540 | <p>Just create an instance of your classes in the module you posted. Then just import your logging module in every file you want to log from and do something like this:</p>
<pre><code>yourloggingmodule.handler.newLogMessage(...)
</code></pre>
<p>Where <code>handler</code> is the name of the instance you created.</p>
| 1 | 2009-10-28T19:28:39Z | [
"python",
"oop",
"logging",
"global-variables"
] |
Logging events in Python; How to log events inside classes? | 1,639,468 | <p>I built (just for fun) 3 classes to help me log some events in my work.</p>
<p>here are them:</p>
<pre><code>class logMessage:
def __init__(self,objectName,message,messageType):
self.objectName = objectName
self.message = message
self.messageType = messageType
self.dateTime = d... | 0 | 2009-10-28T19:15:41Z | 1,642,852 | <p>You could use the <a href="http://code.activestate.com/recipes/66531/" rel="nofollow">Borg pattern</a>, meaning you can create local instances of your logger object and yet have them access the same state. Some would say that is elegant, others may say it's confusing. You decide. :)</p>
| 1 | 2009-10-29T10:42:27Z | [
"python",
"oop",
"logging",
"global-variables"
] |
python: how to generate a bitmap? | 1,639,470 | <p>What's the easiest way to generate a bitmap using Python?</p>
<p>Text support would be nice but not required.</p>
<p>(On Mac, I was trying to use Quartz through Python, but Snow Leopard seems to have broken its functionality. Therefore I've decided to look for a solid, simple, cross-platform solution that won't br... | 3 | 2009-10-28T19:15:57Z | 1,639,478 | <p>Use the <a href="http://www.pythonware.com/products/pil/" rel="nofollow">Python Imaging Library</a>:</p>
<p><em>"The Python Imaging Library (PIL) adds image processing capabilities to your Python interpreter. This library supports many file formats, and provides powerful image processing and graphics capabilities."... | 7 | 2009-10-28T19:17:09Z | [
"python",
"bitmap"
] |
How do I embed IPython with working generator expressions? | 1,639,474 | <p>Certain list comprehensions don't work properly when I embed IPython 0.10 as per the instructions. What's going on with my global namespace?</p>
<pre><code>$ python
>>> import IPython.Shell
>>> IPython.Shell.IPShellEmbed()()
In [1]: def bar(): pass
...:
In [2]: list(bar() for i in range(10))
-... | 5 | 2009-10-28T19:16:10Z | 1,639,710 | <p>Seems to work, but IPython thinks it's the main program. So after instantiating IPShell, a crash shows "whoops, IPython crashed".</p>
<pre><code>import IPython.Shell
ipshell = IPython.Shell.IPShell(argv=[], user_ns={'root':root})
ipshell.mainloop()
</code></pre>
| 0 | 2009-10-28T19:57:51Z | [
"python",
"embedding",
"ipython"
] |
How do I embed IPython with working generator expressions? | 1,639,474 | <p>Certain list comprehensions don't work properly when I embed IPython 0.10 as per the instructions. What's going on with my global namespace?</p>
<pre><code>$ python
>>> import IPython.Shell
>>> IPython.Shell.IPShellEmbed()()
In [1]: def bar(): pass
...:
In [2]: list(bar() for i in range(10))
-... | 5 | 2009-10-28T19:16:10Z | 1,644,065 | <p>List comprehensions are fine, this works:</p>
<pre><code>[bar() for i in range(10)]
</code></pre>
<p>It's generator expressions (which is what you passed to that <code>list()</code> call) that are not fine:</p>
<pre><code>gexpr = (bar() for i in range(10))
list(gexpr)
</code></pre>
<p>The difference: items in th... | 1 | 2009-10-29T14:19:13Z | [
"python",
"embedding",
"ipython"
] |
Use javascript to generate a templatetag based on events after document ready? | 1,639,511 | <p>I am working with the new version of <a href="http://github.com/ericflo/django-threadedcomments/tree/master/threadedcomments" rel="nofollow">django-threadedcomments</a> and making some progress; it integrates nicely with django's commenting system, however, I'm stuck and not sure how to proceed.</p>
<p>For threaded... | 0 | 2009-10-28T19:23:03Z | 1,639,724 | <p>You could do this with Ajax, passing the id of the comment to a dedicated view which just renders the form, but I don't think there's any need. I haven't looked at threaded-comments, but I guess that each comment is of the same object type. Therefore, the only thing that differs in the rendered form would be the id ... | 1 | 2009-10-28T19:59:17Z | [
"jquery",
"python",
"ajax",
"django"
] |
Why do I have so many DeadlineExceededErrors with google-app-engine-django? | 1,639,561 | <p>I'm using google-app-engine-django to run Django 1.1 on Google App Engine and I'm getting lots and lots of DeadlineExceededErrors, sometimes with . My entire app is quite simple, and it's happening throughout my app, so I suspect that there is a problem with my basic settings. Any advice would be greatly appreciated... | 0 | 2009-10-28T19:34:35Z | 1,642,609 | <p>This is a known bug that occurs intermittently for some apps. We're working on fixing it ASAP.</p>
| 3 | 2009-10-29T09:52:44Z | [
"python",
"django",
"google-app-engine"
] |
Converting a single ordered list in python to a dictionary, pythonically | 1,639,772 | <p>I can't seem to find an elegant way to start from <em>t</em> and result in <em>s</em>.</p>
<pre><code>>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>Solutions I've come up with that seems less than elegant :</p>
<pre><code>s = dict()
for i in xrange(0, len... | 1 | 2009-10-28T20:06:01Z | 1,639,789 | <p>Not exactly efficient, but if you don't need it for very large lists:</p>
<pre><code>dict(zip(t[::2], t[1::2]))
</code></pre>
<p>Or your version using a generator:</p>
<pre><code>dict(t[i:i+2] for i in xrange(0, len(t), 2))
</code></pre>
| 7 | 2009-10-28T20:09:07Z | [
"list",
"dictionary",
"python",
"itertools"
] |
Converting a single ordered list in python to a dictionary, pythonically | 1,639,772 | <p>I can't seem to find an elegant way to start from <em>t</em> and result in <em>s</em>.</p>
<pre><code>>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>Solutions I've come up with that seems less than elegant :</p>
<pre><code>s = dict()
for i in xrange(0, len... | 1 | 2009-10-28T20:06:01Z | 1,639,811 | <pre><code>dict(zip(t[::2], t[1::2]))
</code></pre>
<p>probably not the most efficient. works in python 3; you might need to import zip, in python 2.x</p>
| 1 | 2009-10-28T20:11:25Z | [
"list",
"dictionary",
"python",
"itertools"
] |
Converting a single ordered list in python to a dictionary, pythonically | 1,639,772 | <p>I can't seem to find an elegant way to start from <em>t</em> and result in <em>s</em>.</p>
<pre><code>>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>Solutions I've come up with that seems less than elegant :</p>
<pre><code>s = dict()
for i in xrange(0, len... | 1 | 2009-10-28T20:06:01Z | 1,639,828 | <p>Same idea as <a href="http://stackoverflow.com/questions/1639772/converting-a-single-ordered-list-in-python-to-a-dictionary-pythonically/1639789#1639789">Lukáš Lalinský's answer</a>, different idiom:</p>
<pre><code>>>> dict(zip(*([iter(t)] * 2)))
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>This uses the ... | 9 | 2009-10-28T20:13:45Z | [
"list",
"dictionary",
"python",
"itertools"
] |
Converting a single ordered list in python to a dictionary, pythonically | 1,639,772 | <p>I can't seem to find an elegant way to start from <em>t</em> and result in <em>s</em>.</p>
<pre><code>>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>Solutions I've come up with that seems less than elegant :</p>
<pre><code>s = dict()
for i in xrange(0, len... | 1 | 2009-10-28T20:06:01Z | 1,639,851 | <p>Guys, guys, use itertools. Your low-RAM users will thank you when the lists get large.</p>
<pre><code>>>> from itertools import izip, islice
>>> t = ['a',2,'b',3,'c',4]
>>> s = dict(izip(islice(t, 0, None, 2), islice(t, 1, None, 2)))
>>> s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
... | 6 | 2009-10-28T20:17:21Z | [
"list",
"dictionary",
"python",
"itertools"
] |
Converting a single ordered list in python to a dictionary, pythonically | 1,639,772 | <p>I can't seem to find an elegant way to start from <em>t</em> and result in <em>s</em>.</p>
<pre><code>>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>Solutions I've come up with that seems less than elegant :</p>
<pre><code>s = dict()
for i in xrange(0, len... | 1 | 2009-10-28T20:06:01Z | 1,641,242 | <p>I'd use <code>itertools</code>, but, if you think that's complicated (as you've hinted in a comment), then maybe:</p>
<pre><code>def twobytwo(t):
it = iter(t)
for x in it:
yield x, next(it)
d = dict(twobytwo(t))
</code></pre>
<p>or equivalently, and back to itertools again,</p>
<pre><code>def twobytwo(t)... | 10 | 2009-10-29T02:03:12Z | [
"list",
"dictionary",
"python",
"itertools"
] |
Converting a single ordered list in python to a dictionary, pythonically | 1,639,772 | <p>I can't seem to find an elegant way to start from <em>t</em> and result in <em>s</em>.</p>
<pre><code>>>>t = ['a',2,'b',3,'c',4]
#magic
>>>print s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>Solutions I've come up with that seems less than elegant :</p>
<pre><code>s = dict()
for i in xrange(0, len... | 1 | 2009-10-28T20:06:01Z | 2,941,948 | <p>Using the <a href="http://pypi.python.org/pypi/stream/0.8" rel="nofollow">stream</a> module:</p>
<pre><code>>>> from stream import chop
>>> t = ['a',2,'b',3,'c',4]
>>> s = t >> chop(2) >> dict
>>> s
{'a': 2, 'c': 4, 'b': 3}
</code></pre>
<p>It should be noted that th... | 2 | 2010-05-31T07:16:36Z | [
"list",
"dictionary",
"python",
"itertools"
] |
POS tagging in German | 1,639,855 | <p>I am using NLTK to extract nouns from a text-string starting with the following command:</p>
<pre><code>tagged_text = nltk.pos_tag(nltk.Text(nltk.word_tokenize(some_string)))
</code></pre>
<p>It works fine in English. <strong>Is there an easy way to make it work for German as well?</strong> </p>
<p>(I have no exp... | 19 | 2009-10-28T20:17:48Z | 1,640,001 | <p>Natural language software does its magic by leveraging corpora and the statistics they provide. You'll need to tell nltk about some German corpus to help it tokenize German correctly. I believe the <a href="http://www.statmt.org/europarl/">EUROPARL</a> corpus might help get you going. </p>
<p>See <a href="http://nl... | 18 | 2009-10-28T20:46:26Z | [
"python",
"nlp",
"nltk"
] |
POS tagging in German | 1,639,855 | <p>I am using NLTK to extract nouns from a text-string starting with the following command:</p>
<pre><code>tagged_text = nltk.pos_tag(nltk.Text(nltk.word_tokenize(some_string)))
</code></pre>
<p>It works fine in English. <strong>Is there an easy way to make it work for German as well?</strong> </p>
<p>(I have no exp... | 19 | 2009-10-28T20:17:48Z | 1,640,109 | <p>Part-of-Speech (POS) tagging is very specific to a particular [natural] language. NLTK includes many different taggers, which use distinct techniques to infer the tag of a given token in a given token. Most (but not all) of these taggers use a statistical model of sorts as the main or sole device to "do the trick"... | 4 | 2009-10-28T21:04:59Z | [
"python",
"nlp",
"nltk"
] |
POS tagging in German | 1,639,855 | <p>I am using NLTK to extract nouns from a text-string starting with the following command:</p>
<pre><code>tagged_text = nltk.pos_tag(nltk.Text(nltk.word_tokenize(some_string)))
</code></pre>
<p>It works fine in English. <strong>Is there an easy way to make it work for German as well?</strong> </p>
<p>(I have no exp... | 19 | 2009-10-28T20:17:48Z | 4,758,556 | <p>I have written a blog-post about how to convert the German annotated TIGER Corpus in order to use it with the NLTK. <a href="http://web.archive.org/web/20130402043354/http://experimentallabor.de/setting-up-a-pos-tagged-german-corpus-to-use-with-nltk/" rel="nofollow">Have a look at it here.</a></p>
| 2 | 2011-01-21T12:01:33Z | [
"python",
"nlp",
"nltk"
] |
POS tagging in German | 1,639,855 | <p>I am using NLTK to extract nouns from a text-string starting with the following command:</p>
<pre><code>tagged_text = nltk.pos_tag(nltk.Text(nltk.word_tokenize(some_string)))
</code></pre>
<p>It works fine in English. <strong>Is there an easy way to make it work for German as well?</strong> </p>
<p>(I have no exp... | 19 | 2009-10-28T20:17:48Z | 15,278,298 | <p>The <a href="http://www.clips.ua.ac.be/pages/pattern-de">Pattern library</a> includes a function for parsing German sentences and the result includes the part-of-speech tags. The following is copied from their documentation: </p>
<pre><code>from pattern.de import parse, split
s = parse('Die Katze liegt auf der Matt... | 9 | 2013-03-07T17:53:59Z | [
"python",
"nlp",
"nltk"
] |
POS tagging in German | 1,639,855 | <p>I am using NLTK to extract nouns from a text-string starting with the following command:</p>
<pre><code>tagged_text = nltk.pos_tag(nltk.Text(nltk.word_tokenize(some_string)))
</code></pre>
<p>It works fine in English. <strong>Is there an easy way to make it work for German as well?</strong> </p>
<p>(I have no exp... | 19 | 2009-10-28T20:17:48Z | 20,816,272 | <p>Possibly you can use the Stanford POS tagger. Below is a recipe I wrote. There are python recipes for German NLP that I've compiled and you can access them on <a href="http://htmlpreview.github.io/?https://github.com/alvations/DLTK/blob/master/docs/index.html" rel="nofollow">http://htmlpreview.github.io/?https://git... | 4 | 2013-12-28T15:40:11Z | [
"python",
"nlp",
"nltk"
] |
Running multiple commands simultaneously from python | 1,639,912 | <p>I want to run three commands at the same time from python. The command format is query.pl -args</p>
<p>Currently I am doing </p>
<pre><code>os.system("query.pl -results '10000' -serverName 'server1' >> log1.txt")
os.system("query.pl -results '10000' -serverName 'server2' >> log2.txt")
os.system("quer... | 2 | 2009-10-28T20:28:21Z | 1,639,925 | <p>You could use the <a href="http://docs.python.org/library/subprocess.html">subprocess</a> module and have all three running independently: use subprocess.Popen. Take care in setting the "shell" parameter correctly.</p>
<p>Use the wait() or poll() method to determine when the subprocesses are finished.</p>
| 8 | 2009-10-28T20:30:09Z | [
"python"
] |
Running multiple commands simultaneously from python | 1,639,912 | <p>I want to run three commands at the same time from python. The command format is query.pl -args</p>
<p>Currently I am doing </p>
<pre><code>os.system("query.pl -results '10000' -serverName 'server1' >> log1.txt")
os.system("query.pl -results '10000' -serverName 'server2' >> log2.txt")
os.system("quer... | 2 | 2009-10-28T20:28:21Z | 1,639,952 | <pre><code>os.system("query.pl -results '10000' -serverName 'server1' &")
os.system("query.pl -results '10000' -serverName 'server2' &")
os.system("query.pl -results '10000' -serverName 'server3' &")
</code></pre>
<p>in this case - process will be started in background</p>
| 0 | 2009-10-28T20:36:07Z | [
"python"
] |
Running multiple commands simultaneously from python | 1,639,912 | <p>I want to run three commands at the same time from python. The command format is query.pl -args</p>
<p>Currently I am doing </p>
<pre><code>os.system("query.pl -results '10000' -serverName 'server1' >> log1.txt")
os.system("query.pl -results '10000' -serverName 'server2' >> log2.txt")
os.system("quer... | 2 | 2009-10-28T20:28:21Z | 1,639,973 | <p>You can use <a href="http://docs.python.org/library/queue.html" rel="nofollow">Queue</a></p>
<pre><code>tasks = ("query.pl -results '10000' -serverName 'server1'",\
"query.pl -results '10000' -serverName 'server2'",\
"query.pl -results '10000' -serverName 'server1'")
def worker():
while True:
item = q.... | 0 | 2009-10-28T20:41:34Z | [
"python"
] |
Understanding a factorial function in python | 1,639,976 | <p>I'm trying to understand if the following Python function:</p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFac... | 3 | 2009-10-28T20:41:56Z | 1,640,002 | <p>here is main algorithm</p>
<pre><code>iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFactor
</code></pre>
<p>other code is for caching results.</p>
| 4 | 2009-10-28T20:46:32Z | [
"c#",
"python"
] |
Understanding a factorial function in python | 1,639,976 | <p>I'm trying to understand if the following Python function:</p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFac... | 3 | 2009-10-28T20:41:56Z | 1,640,017 | <p>it will return the same results, but the Python version will probably have better performance, because it memoizes the results</p>
| 1 | 2009-10-28T20:48:35Z | [
"c#",
"python"
] |
Understanding a factorial function in python | 1,639,976 | <p>I'm trying to understand if the following Python function:</p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFac... | 3 | 2009-10-28T20:41:56Z | 1,640,021 | <p>Even without knowing Python, it must be clear to you that the two functions are far from identical. The C# version is calculating the factorial via recursion, whereas the Python one is doing it via iteration (although in a slightly weird way, with some odd memoization/caching going on - I guess in case you want to c... | 2 | 2009-10-28T20:48:52Z | [
"c#",
"python"
] |
Understanding a factorial function in python | 1,639,976 | <p>I'm trying to understand if the following Python function:</p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFac... | 3 | 2009-10-28T20:41:56Z | 1,640,037 | <p>IANAPG (Python Guru), but it looks to me like the function is creating a static array of 1000 entries, then filling them on an as-needed basis to prevent recalculation. In C++, it'd be something like:</p>
<pre><code>long factorial(int i){
//Cache array
static long factorials[1000];
if (!factorials[i]){ ... | 2 | 2009-10-28T20:50:31Z | [
"c#",
"python"
] |
Understanding a factorial function in python | 1,639,976 | <p>I'm trying to understand if the following Python function:</p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFac... | 3 | 2009-10-28T20:41:56Z | 1,640,050 | <p>It just attaches an attribute called <code>lstFactorial</code> to <code>factorial</code>. This attribute is a list of 1000 values used to cache the results of previous calls.</p>
| 1 | 2009-10-28T20:52:08Z | [
"c#",
"python"
] |
Understanding a factorial function in python | 1,639,976 | <p>I'm trying to understand if the following Python function:</p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'):
factorial.lstFactorial = [None] * 1000
if factorial.lstFactorial[i] is None:
iProduct = 1
for iFactor in xrange(1, i+1):
iProduct *= iFac... | 3 | 2009-10-28T20:41:56Z | 1,640,087 | <p></p>
<pre><code>def factorial(i):
if not hasattr(factorial, 'lstFactorial'): #program checks whether caching list exists
factorial.lstFactorial = [None] * 1000 #if so, it creates a list of thousand None elements (it is more or less equivalent to C/C++'s NULL
if factorial.lstFactorial[i] is None: #pr... | 1 | 2009-10-28T21:00:02Z | [
"c#",
"python"
] |
urlretrieve returns an empty file | 1,639,989 | <p>I'm trying to use urlretrieve to download files from urls that take the form:</p>
<p><strong><a href="http://example.com/download.php?id=6456&name=foo" rel="nofollow">http://example.com/download.php?id=6456&name=foo</a></strong></p>
<p>yet for some reason I just get an empty response.</p>
<p>I've tried th... | 0 | 2009-10-28T20:44:19Z | 1,640,060 | <p>Information from <a href="http://docs.python.org/library/urllib2.html#urllib2.urlopen" rel="nofollow">manual</a>:</p>
<blockquote>
<p>info() â return the meta-information
of the page, such as headers, in the
form of an httplib.HTTPMessage
instance (see Quick Reference to HTTP
Headers)</p>
</blockquote>
... | 1 | 2009-10-28T20:53:17Z | [
"python",
"download",
"urllib2",
"urllib"
] |
Multiple CouchDB Document fetch with couchdb-python | 1,640,054 | <p>How to fetch multiple documents from CouchDB, in particular with couchdb-python?</p>
| 11 | 2009-10-28T20:52:25Z | 1,640,057 | <pre><code>import couchdb
import simplejson as json
resource = couchdb.client.Resource(None, 'http://localhost:5984/dbname/_all_docs')
params = {"include_docs":True}
content = json.dumps({"keys":[idstring1, idstring2, ...]})
headers = {"Content-Type":"application/json"}
resource.post(headers=headers, content=content, ... | -5 | 2009-10-28T20:52:43Z | [
"python",
"couchdb"
] |
Multiple CouchDB Document fetch with couchdb-python | 1,640,054 | <p>How to fetch multiple documents from CouchDB, in particular with couchdb-python?</p>
| 11 | 2009-10-28T20:52:25Z | 1,642,783 | <p>This is the right way:</p>
<pre><code>import couchdb
server = couchdb.Server("http://localhost:5984")
db = server["dbname"]
results = db.view("_all_docs", keys=["key1", "key2"])
</code></pre>
| 4 | 2009-10-29T10:32:03Z | [
"python",
"couchdb"
] |
Multiple CouchDB Document fetch with couchdb-python | 1,640,054 | <p>How to fetch multiple documents from CouchDB, in particular with couchdb-python?</p>
| 11 | 2009-10-28T20:52:25Z | 1,803,546 | <p>Easiest way is to pass a include_docs=True arg to Database.view. Each row of the results will include the doc. e.g.</p>
<pre><code>>>> db = couchdb.Database('http://localhost:5984/test')
>>> rows = db.view('_all_docs', keys=['docid1', 'docid2', 'missing'], include_docs=True)
>>> docs = [r... | 19 | 2009-11-26T13:01:38Z | [
"python",
"couchdb"
] |
Web service for an Excel automation script on Windows | 1,640,068 | <p>I am tasked to develop a very simple web layer for a very complex algorithm that is implemented as an Excel worksheet. This script would be called from a Ruby on Rails app that would be presenting the user with the forms, check validations and whatnot, and should return just a number. After perusing this site, m... | 0 | 2009-10-28T20:55:00Z | 1,640,324 | <p>My first choice would be to move the calculations that are in the Excel workbook into my Ruby application code. While it will likely take some additional work, my guess is that it will take less time to port the Excel app to Ruby than introducing layers of complexity on top of Excel. Additionally, calling into Exc... | 1 | 2009-10-28T21:45:47Z | [
"python",
"excel",
"winapi",
"automation"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,088 | <p>I would normally say, <strong>use what you know</strong>.</p>
<p>However, here you may have some performance issues using an interpreted language. I, myself, would use C#. If you want to learn it, <strong>now is as good of a time as any</strong>.</p>
<p>However, if your own cost/benefit analysis reveals that you... | 2 | 2009-10-28T21:00:33Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,094 | <p>If the users have to install a C# client then not having .NET installed would be an issue. You can package the installer so it downloads the .NET runtime, but depending on what features you use it could be quite a big download.</p>
<p>If your application is web based then all the C# code runs on the server and just... | 0 | 2009-10-28T21:01:21Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,096 | <p>If you want to learn C# and you don't have such a limited time constraint, now might be a good time to try it. Also, though I haven't done Excel work with either Python or C#, I would expect it to be easier to work with Excel files with a Microsoft product rather than Python. If you're just dumping data in CSV for... | 5 | 2009-10-28T21:01:40Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,101 | <p>Why not <a href="http://www.codeplex.com/IronPython" rel="nofollow">IronPython</a> which merges the two worlds together?</p>
| 12 | 2009-10-28T21:02:32Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,103 | <p>Integration with Excel will almost certainly be simpler from C#. Given the requirements "Windows only" and "Integrates with Excel", it would seem a simple choice that C# is better suited to this individual problem.</p>
<p>And, no, users' not having .NET is not a concern compared with Python as the alternative. The ... | 0 | 2009-10-28T21:03:00Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,111 | <p>If you are doing any kind of HTTP work with C# make sure you take a look at the new HttpClient library that is in <a href="http://aspnet.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=24644" rel="nofollow">WCF REST Starter Preview2</a>. Ignore the name of that download, the HttpClient part can be used independ... | 0 | 2009-10-28T21:05:39Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,232 | <p>If you do a web based application not having installed .NET in the client machine wont be a problem .. but I suppose you dont want to try both C# and web development at the same time</p>
| 0 | 2009-10-28T21:28:28Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,862 | <p>It is easy with Python to pull data from a web server, parse the JSON or XML, and generate some kind of report. If you need really good Excel integration (for example, your output is supposed to be an Excel spreadsheet that includes numerous graphs) C# might be better, but Python is still possible; there is <a href... | 0 | 2009-10-28T23:49:41Z | [
"c#",
"python",
"excel"
] |
C# or Python for my app | 1,640,080 | <p>I have the task of developing an application to pull data from remote REST services and generating Excel reports. This application will be used by a handful of users at the company (10-15). The data load can reach 10,000-200,000 records. I have been debating whether to use Python or C#...</p>
<p>The only reason I a... | 3 | 2009-10-28T20:57:55Z | 1,640,928 | <p>The answer probably has more to do with the circumstances than the question of which is the better language for the task at hand.</p>
<p>If you have no prior C# experience, it's probably not a good idea to jump into it now and learn it as you go along. Syntax differences are trivial to learn, mastery is defined by ... | 0 | 2009-10-29T00:07:58Z | [
"c#",
"python",
"excel"
] |
How to handle a tokenize error with unterminated multiline comments (python 2.6) | 1,640,097 | <p>The following sample code:</p>
<pre><code>import token, tokenize, StringIO
def generate_tokens(src):
rawstr = StringIO.StringIO(unicode(src))
tokens = tokenize.generate_tokens(rawstr.readline)
for i, item in enumerate(tokens):
toktype, toktext, (srow,scol), (erow,ecol), line = item
prin... | 4 | 2009-10-28T21:01:45Z | 1,640,615 | <p>How you handle tokenize errors depends entirely on why you are tokenizing. You code gives you all the valid tokens up until the beginning of the bad string literal. If that token stream is useful to you, then use it. </p>
<p>You have a few options about what to do with the error:</p>
<ol>
<li><p>You could ignor... | 2 | 2009-10-28T22:42:21Z | [
"python",
"parsing",
"python-2.6",
"tokenize"
] |
Is a Python Queue needed for simple byte stream between threads? | 1,640,112 | <p>I have a simple thread that grabs bytes from a Bluetooth RFCOMM (serial-port-like) socket and dumps them into a <code>Queue.Queue</code> (FIFO), which seems like the typical method to exchange data between threads. Works fine.</p>
<p>Is this overkill though? Could I just use a bytearray then have my reader thread... | 1 | 2009-10-28T21:06:18Z | 1,640,262 | <p>Yes, pop() is atomic, but I'd stick with Queue if performance is not super important. </p>
| 0 | 2009-10-28T21:34:37Z | [
"python",
"multithreading",
"queue"
] |
Is a Python Queue needed for simple byte stream between threads? | 1,640,112 | <p>I have a simple thread that grabs bytes from a Bluetooth RFCOMM (serial-port-like) socket and dumps them into a <code>Queue.Queue</code> (FIFO), which seems like the typical method to exchange data between threads. Works fine.</p>
<p>Is this overkill though? Could I just use a bytearray then have my reader thread... | 1 | 2009-10-28T21:06:18Z | 1,641,189 | <p>With <code>Queue</code>, you're <em>guaranteed</em> to be threadsafe in any implementation and version of Python. Relying on this or that method of some other object being "atomic" (in a given implementation and version) typically leaves you at the mercy of this "atomicity" not being a strong guarantee (just an impl... | 3 | 2009-10-29T01:41:01Z | [
"python",
"multithreading",
"queue"
] |
Is a Python Queue needed for simple byte stream between threads? | 1,640,112 | <p>I have a simple thread that grabs bytes from a Bluetooth RFCOMM (serial-port-like) socket and dumps them into a <code>Queue.Queue</code> (FIFO), which seems like the typical method to exchange data between threads. Works fine.</p>
<p>Is this overkill though? Could I just use a bytearray then have my reader thread... | 1 | 2009-10-28T21:06:18Z | 1,642,871 | <p>If the rate of input is fast enough, you can always buffer bytes up into a string before pushing that onto the Queue. That will probably increase throughput by reducing the amount of locking done, at the expense of a little extra latency on the receiving end.</p>
| 0 | 2009-10-29T10:45:39Z | [
"python",
"multithreading",
"queue"
] |
Calculating average in interchangable range? | 1,640,145 | <p>I know it's because of n, but n is supposed to be any variable, and left as n, this is what I have:</p>
<pre><code>def average(n):
if n >= 0:
avg = sum((range(1:int(n)))/float(len(range(1:int(n)))))
print avg
</code></pre>
<p>how do I fix it?</p>
| 0 | 2009-10-28T21:12:28Z | 1,640,168 | <p>If your range is always 1:n, why don't you just use this:</p>
<pre><code>avg = sum((range(1:int(n)))/float(n))
</code></pre>
<p>Or maybe I am not understanding your question...</p>
| 0 | 2009-10-28T21:16:59Z | [
"python",
"variables",
"average"
] |
Calculating average in interchangable range? | 1,640,145 | <p>I know it's because of n, but n is supposed to be any variable, and left as n, this is what I have:</p>
<pre><code>def average(n):
if n >= 0:
avg = sum((range(1:int(n)))/float(len(range(1:int(n)))))
print avg
</code></pre>
<p>how do I fix it?</p>
| 0 | 2009-10-28T21:12:28Z | 1,640,195 | <p>I may be wrong but range(1:int(n)) doesn't look like syntactically correct and parenthesis don't match. You may want to calculate the average of numbers in the range of 0 to n. In that case, I would replace your code like this:</p>
<pre><code>def average(n):
if n >= 0:
avg = sum((range(int(n))))/float(n)
pri... | 1 | 2009-10-28T21:21:28Z | [
"python",
"variables",
"average"
] |
Calculating average in interchangable range? | 1,640,145 | <p>I know it's because of n, but n is supposed to be any variable, and left as n, this is what I have:</p>
<pre><code>def average(n):
if n >= 0:
avg = sum((range(1:int(n)))/float(len(range(1:int(n)))))
print avg
</code></pre>
<p>how do I fix it?</p>
| 0 | 2009-10-28T21:12:28Z | 1,640,276 | <p>The summation of x from 1 to n is simply <code>(n + 1) * (n / 2)</code>. The number of elements being summed is <code>n</code> . Do a little simplification and your new function is</p>
<pre><code>def average(n):
return (n + 1) / 2.0
</code></pre>
<p>You'll have to adjust this if you actually wanted Python's ... | 2 | 2009-10-28T21:37:18Z | [
"python",
"variables",
"average"
] |
Django Forms - Can the initial value of one field be dependant on another? | 1,640,204 | <p>Example, for this form:</p>
<pre><code>class CommentForm(forms.Form):
name = forms.CharField(initial='class')
action = forms.ChoiceField(...)
</code></pre>
<p>Can I have the choices in the action field be different depending on what is in the name field?</p>
| 0 | 2009-10-28T21:22:56Z | 1,640,509 | <p>How about wrapping <em>initial</em> in a function or a lambda, so that the value of initial is deferred until form creation. Something like:</p>
<pre><code>class CommentForm(forms.Form):
name = forms.CharField(initial=lambda : self.action) # or more complex logic
action = forms.ChoiceField(...)
</code></pre... | 4 | 2009-10-28T22:22:49Z | [
"python",
"django",
"forms",
"django-forms"
] |
Python Service Custom Command Arguments | 1,640,255 | <p>I am currently working on a python program which runs as a windows service using win32service and win32serviceutil. The service runs as it should and even after using py2exe, everything is fine (the service monitors target folder(s) and autmotically FTP's newly created files to specified FTP location). I would like,... | 5 | 2009-10-28T21:33:02Z | 1,641,161 | <p><a href="http://downloads.openmoko.org/developer/sources/cvs/python-pyro/Pyro/Pyro/ext/BasicNTService.py" rel="nofollow">here</a> is a nice example of how to make a service with a custom <code>HandleCommandLine</code> classmethod -- it's part of pyro but has no dependencies on pyro, rather it's a utility "abstract b... | 3 | 2009-10-29T01:32:11Z | [
"python",
"windows-services",
"py2exe"
] |
python string replacement with % character/**kwargs weirdness | 1,640,487 | <p>Following code:</p>
<pre><code>def __init__(self, url, **kwargs):
for key in kwargs.keys():
url = url.replace('%%s%' % key, str(kwargs[key]))
</code></pre>
<p>Throws the following exception:</p>
<pre><code>File "/home/wells/py-mlb/lib/fetcher.py", line 25, in __init__
url = url.replace('%%s%' % key, str(... | 4 | 2009-10-28T22:19:15Z | 1,640,500 | <p>You probably want the format string <code>%%%s%%</code> instead of <code>%%s%</code>.</p>
<p>Two consecutive <code>%</code> signs are interpreted as a literal <code>%</code>, so in your version, you have a literal <code>%</code>, a literal <code>s</code>, and then a lone <code>%</code>, which is expecting a format ... | 14 | 2009-10-28T22:22:00Z | [
"python",
"string-formatting"
] |
python string replacement with % character/**kwargs weirdness | 1,640,487 | <p>Following code:</p>
<pre><code>def __init__(self, url, **kwargs):
for key in kwargs.keys():
url = url.replace('%%s%' % key, str(kwargs[key]))
</code></pre>
<p>Throws the following exception:</p>
<pre><code>File "/home/wells/py-mlb/lib/fetcher.py", line 25, in __init__
url = url.replace('%%s%' % key, str(... | 4 | 2009-10-28T22:19:15Z | 1,640,512 | <p>you need to double the percentage sign to escape it:</p>
<pre><code>>>> '%%%s%%' % 'PLAYER_ID'
'%PLAYER_ID%'
</code></pre>
<p>also when iterating over the dictionary you could unpack values in the for statement like this:</p>
<pre><code>def __init__(self, url, **kwargs):
for key, value in kwargs.item... | 3 | 2009-10-28T22:23:18Z | [
"python",
"string-formatting"
] |
python string replacement with % character/**kwargs weirdness | 1,640,487 | <p>Following code:</p>
<pre><code>def __init__(self, url, **kwargs):
for key in kwargs.keys():
url = url.replace('%%s%' % key, str(kwargs[key]))
</code></pre>
<p>Throws the following exception:</p>
<pre><code>File "/home/wells/py-mlb/lib/fetcher.py", line 25, in __init__
url = url.replace('%%s%' % key, str(... | 4 | 2009-10-28T22:19:15Z | 1,640,518 | <p>Adam almost had it right. Change your code to:</p>
<pre><code>def __init__(self, url, **kwargs):
for key in kwargs.keys():
url = url.replace('%%%s%%' % key, str(kwargs[key]))
</code></pre>
<p>When key is FOO, then <code>'%%%s%%' % key</code> results in <code>'%FOO%'</code>, and your url.replace will d... | 1 | 2009-10-28T22:23:59Z | [
"python",
"string-formatting"
] |
Python pysqlite2 dbapi2 problem | 1,640,537 | <p>I'm having an issue with the line:</p>
<pre><code>from pysqlite2 import dbapi2 as sqlite
</code></pre>
<p>The error i'm getting is:</p>
<pre><code>ImportError: /usr/lib/python2.4/site-packages/pysqlite2/_sqlite.so: undefined symbol: sqlite3_enable_shared_cache
</code></pre>
<p>What can I do to solve this problem... | 1 | 2009-10-28T22:27:48Z | 1,640,628 | <p>Sounds like _sqlite.so was compiled against a newer version of sqlite than you have installed. That function wasn't added to SQLite's API until <a href="http://sqlite.org/changes.html#version%5F3%5F5%5F0" rel="nofollow">version 3.5.0</a>.</p>
| 2 | 2009-10-28T22:45:25Z | [
"python",
"linux",
"sqlite"
] |
Python pysqlite2 dbapi2 problem | 1,640,537 | <p>I'm having an issue with the line:</p>
<pre><code>from pysqlite2 import dbapi2 as sqlite
</code></pre>
<p>The error i'm getting is:</p>
<pre><code>ImportError: /usr/lib/python2.4/site-packages/pysqlite2/_sqlite.so: undefined symbol: sqlite3_enable_shared_cache
</code></pre>
<p>What can I do to solve this problem... | 1 | 2009-10-28T22:27:48Z | 1,640,918 | <p>The easiest way around this problem is to get the <a href="https://www.activestate.com/activepython/downloads/" rel="nofollow">AS package Python 2.6 or later from Activestate</a> and install that. It comes with SQLITE in the standard library.</p>
<p>The AS package is a tarball and you install it in a user directory... | 0 | 2009-10-29T00:04:44Z | [
"python",
"linux",
"sqlite"
] |
Appscript to write iTunes artwork | 1,640,558 | <p>I'm trying to capture artwork from a pict file and embed into a track on iTunes using python appscript.
I did something like this:</p>
<pre><code>imFile = open('/Users/kartikaiyer/temp.pict','r')
data = imFile.read()
it = app('iTunes')
sel = it.current_track.get()
sel.artworks[0].data_.set(data[513:])
</code></pre>... | 0 | 2009-10-28T22:31:14Z | 1,652,634 | <p>At a quick guess, Appscript references, like AppleScript references, use 1-indexing, not zero-indexing like Python lists. So you probably need to write:</p>
<p><code>it.current_track.artworks[1].data_.set(...)</code></p>
<p>(Incidentally, the extra <code>get</code> command in your original script is unnecessary, t... | 0 | 2009-10-30T22:25:17Z | [
"python",
"appscript"
] |
Appscript to write iTunes artwork | 1,640,558 | <p>I'm trying to capture artwork from a pict file and embed into a track on iTunes using python appscript.
I did something like this:</p>
<pre><code>imFile = open('/Users/kartikaiyer/temp.pict','r')
data = imFile.read()
it = app('iTunes')
sel = it.current_track.get()
sel.artworks[0].data_.set(data[513:])
</code></pre>... | 0 | 2009-10-28T22:31:14Z | 2,787,478 | <p>The <code>read</code> command is part of Scripting Additions, which ASTranslate doesn't translate to. Use ASDictionary to create a glue for Scripting Additions, by clicking "Choose Installed Scripting Additions" Under the Dictionary menu, and then selecting "Scripting Additions" from the list.</p>
| 0 | 2010-05-07T09:22:12Z | [
"python",
"appscript"
] |
Appscript to write iTunes artwork | 1,640,558 | <p>I'm trying to capture artwork from a pict file and embed into a track on iTunes using python appscript.
I did something like this:</p>
<pre><code>imFile = open('/Users/kartikaiyer/temp.pict','r')
data = imFile.read()
it = app('iTunes')
sel = it.current_track.get()
sel.artworks[0].data_.set(data[513:])
</code></pre>... | 0 | 2009-10-28T22:31:14Z | 4,540,239 | <p>This is an older question, but since I was having trouble doing this same thing now, I thought I'd post my solution in case someone else might benefit.</p>
<pre><code>selected = appscript.app('iTunes').selection.get()
for t in selected:
myArt = open(/path/to/image.jpg,'r')
data = myArt.read()
t.artwork... | 2 | 2010-12-27T16:46:22Z | [
"python",
"appscript"
] |
Data Structure for storing a sorting field to efficiently allow modifications | 1,640,664 | <p>I'm using Django and PostgreSQL, but I'm not absolutely tied to the Django ORM if there's a better way to do this with raw SQL or database specific operations.</p>
<p>I've got a model that needs sequential ordering. Lookup operations will generally retrieve the entire list in order. The most common operation on thi... | 7 | 2009-10-28T22:54:48Z | 1,640,837 | <p>It seems to me that your real problem is the need to lock a table for the duration of a transaction. I don't immediately see a good way to solve this problem in a single operation, hence the need for locking.</p>
<p>So the question is whether you can do this in a "Django way" as opposed to using straight SQL. Searc... | 1 | 2009-10-28T23:37:41Z | [
"python",
"database",
"django",
"sorting",
"data-structures"
] |
Data Structure for storing a sorting field to efficiently allow modifications | 1,640,664 | <p>I'm using Django and PostgreSQL, but I'm not absolutely tied to the Django ORM if there's a better way to do this with raw SQL or database specific operations.</p>
<p>I've got a model that needs sequential ordering. Lookup operations will generally retrieve the entire list in order. The most common operation on thi... | 7 | 2009-10-28T22:54:48Z | 1,655,760 | <p>You can solve the renumbering issue by doing the order column as an integer that is always an even number. When you are moving the data, you change the order field to the new sort value + 1 and then do a quick update to convert all the odd order fields to even:</p>
<pre><code>update table set sort_order = bitand(so... | 1 | 2009-10-31T22:12:44Z | [
"python",
"database",
"django",
"sorting",
"data-structures"
] |
Data Structure for storing a sorting field to efficiently allow modifications | 1,640,664 | <p>I'm using Django and PostgreSQL, but I'm not absolutely tied to the Django ORM if there's a better way to do this with raw SQL or database specific operations.</p>
<p>I've got a model that needs sequential ordering. Lookup operations will generally retrieve the entire list in order. The most common operation on thi... | 7 | 2009-10-28T22:54:48Z | 1,655,765 | <p>Why not do a simple character field of some length like a max of 16 (or 255) initially.</p>
<p>Start initially with labeling things aaa through zzz (that should be 17576 entries). (You could also add in 0-9, and the uppercase letters and symbols for an optimization.)</p>
<p>As items are added, they can go to the e... | 1 | 2009-10-31T22:14:31Z | [
"python",
"database",
"django",
"sorting",
"data-structures"
] |
Data Structure for storing a sorting field to efficiently allow modifications | 1,640,664 | <p>I'm using Django and PostgreSQL, but I'm not absolutely tied to the Django ORM if there's a better way to do this with raw SQL or database specific operations.</p>
<p>I've got a model that needs sequential ordering. Lookup operations will generally retrieve the entire list in order. The most common operation on thi... | 7 | 2009-10-28T22:54:48Z | 1,655,791 | <p><strong>Prefered solutions:</strong></p>
<p>A <a href="http://en.wikipedia.org/wiki/Linked%5Flist" rel="nofollow">linked list</a> would be the usual way to achieve this. A query to return the items in order is <a href="http://stackoverflow.com/questions/515749/how-do-i-sort-a-linked-list-in-sql/515761#515761">trivi... | 6 | 2009-10-31T22:25:25Z | [
"python",
"database",
"django",
"sorting",
"data-structures"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.