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 |
|---|---|---|---|---|---|---|---|---|---|
generating promotion code using python | 2,112,436 | <p>Hello
By using python language, what would be a clever / efficient way of generating promotion codes.
Like to be used for generating special numbers for discount coupons.
like: 1027828-1</p>
<p>Thanks</p>
| 3 | 2010-01-21T20:04:12Z | 2,112,523 | <p>if you need a 6-digit # you could do this until you found a unique value:</p>
<pre><code>import random
print str(random.randint(100000, 999999))
</code></pre>
<p>or go sequentially...</p>
| 1 | 2010-01-21T20:15:37Z | [
"python",
"security",
"promotions"
] |
generating promotion code using python | 2,112,436 | <p>Hello
By using python language, what would be a clever / efficient way of generating promotion codes.
Like to be used for generating special numbers for discount coupons.
like: 1027828-1</p>
<p>Thanks</p>
| 3 | 2010-01-21T20:04:12Z | 2,112,528 | <p>1027828-1 is extremely small. An attacker can make a ~million guesses using only a couple lines of code and maybe a few days. </p>
<p>This is a good way to produce a hard to predict number using python, it works under linux and windows. It is base64'ed for binary safety, depending what you are doing with it you... | 4 | 2010-01-21T20:16:16Z | [
"python",
"security",
"promotions"
] |
generating promotion code using python | 2,112,436 | <p>Hello
By using python language, what would be a clever / efficient way of generating promotion codes.
Like to be used for generating special numbers for discount coupons.
like: 1027828-1</p>
<p>Thanks</p>
| 3 | 2010-01-21T20:04:12Z | 2,112,661 | <p>The following isn't particularly pythonic or particularly efficient, but it might suffice:</p>
<pre><code> import random
def get_promo_code(num_chars):
code_chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
code = ''
for i in range(0, num_chars):
slice_start = random.randint(0, len(code_chars)... | 7 | 2010-01-21T20:34:55Z | [
"python",
"security",
"promotions"
] |
generating promotion code using python | 2,112,436 | <p>Hello
By using python language, what would be a clever / efficient way of generating promotion codes.
Like to be used for generating special numbers for discount coupons.
like: 1027828-1</p>
<p>Thanks</p>
| 3 | 2010-01-21T20:04:12Z | 27,426,672 | <p>I've come up with an answer for this that I think is fairly clever, but relies on a couple of assumptions that might not be true for your situation.</p>
<ul>
<li>The resulting code is purely numeric.</li>
<li>The resulting code is technically variable-length; [10, 20].</li>
</ul>
<p>If these work for you, then so ... | 0 | 2014-12-11T15:39:37Z | [
"python",
"security",
"promotions"
] |
Running Python & Django on IIS | 2,112,525 | <p>Is it possible to run Python & Django on IIS?<br>
I am going to be a Lead Developer in some web design company and right now they are using classic ASP and ASP.NET.<br>
As far as I can see ASP.NET MVC is not mature. Should I recommend Python & Django stack?<br>
If it's not possible to run Python on IIS what ... | 6 | 2010-01-21T20:15:40Z | 2,112,557 | <p>There's two issue here, technological and psycological.</p>
<p>Technologically, yes, it's definitely possible. In fact, Django has a <a href="http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer">wiki article</a> about this. Google also shows a lot of similar tutorials. Apache and IIS can also run ... | 7 | 2010-01-21T20:21:22Z | [
"asp.net",
"python",
"asp.net-mvc",
"apache",
"iis"
] |
Running Python & Django on IIS | 2,112,525 | <p>Is it possible to run Python & Django on IIS?<br>
I am going to be a Lead Developer in some web design company and right now they are using classic ASP and ASP.NET.<br>
As far as I can see ASP.NET MVC is not mature. Should I recommend Python & Django stack?<br>
If it's not possible to run Python on IIS what ... | 6 | 2010-01-21T20:15:40Z | 3,100,230 | <p>We've been running django on IIS for a couple of years using PyISAPIe. It's a fairly big site, about 150,000 users. We're moving to linux/apache though, partly cos PyISAPIe isn't great. </p>
<p>Case in point - WebKit browsers don't work well with it, it seems to mess up the chunking. That's tolerable for us as we a... | 5 | 2010-06-23T08:55:57Z | [
"asp.net",
"python",
"asp.net-mvc",
"apache",
"iis"
] |
Python: creating a grid | 2,112,632 | <p>Is it possible to create a grid like below?
I didn't found anything in the forum.</p>
<pre><code>#euler-project problem number 11
#In the 20 times 20 grid below,
#four numbers along a diagonal line have been marked in red.
#The product of these numbers is 26 times 63 times 78 times 14 = 1788696.
#What is the greate... | 1 | 2010-01-21T20:31:47Z | 2,112,658 | <p>Check out <a href="http://numpy.scipy.org/" rel="nofollow">NumPy</a> - specifically, the <a href="http://docs.scipy.org/doc/numpy/reference/arrays.ndarray.html" rel="nofollow">N-dimensional array</a> object.</p>
| 2 | 2010-01-21T20:34:40Z | [
"python",
"datagrid",
"grid"
] |
Python: creating a grid | 2,112,632 | <p>Is it possible to create a grid like below?
I didn't found anything in the forum.</p>
<pre><code>#euler-project problem number 11
#In the 20 times 20 grid below,
#four numbers along a diagonal line have been marked in red.
#The product of these numbers is 26 times 63 times 78 times 14 = 1788696.
#What is the greate... | 1 | 2010-01-21T20:31:47Z | 2,112,752 | <p>Your code example won't compile unless you put commas between the list elements.</p>
<p>For example, this will compile:</p>
<pre><code>value = [
[ 1, 2, 3, 4],
[ 5, 6, 7, 8],
[ 9,10,11,12]
]
</code></pre>
<p>If you're interested in taking strings like you show, and <strong>parsi... | 2 | 2010-01-21T20:45:27Z | [
"python",
"datagrid",
"grid"
] |
Python: creating a grid | 2,112,632 | <p>Is it possible to create a grid like below?
I didn't found anything in the forum.</p>
<pre><code>#euler-project problem number 11
#In the 20 times 20 grid below,
#four numbers along a diagonal line have been marked in red.
#The product of these numbers is 26 times 63 times 78 times 14 = 1788696.
#What is the greate... | 1 | 2010-01-21T20:31:47Z | 2,114,325 | <p>What you have above does not work, e.g if pasted into a file and then run as a script, or pasted into the interpreter. I get: </p>
<pre><code>SyntaxError: invalid token
</code></pre>
<p>Again, I suspect that what you have done is paste text (a string) containing these characters. They are not integers, and you wil... | 0 | 2010-01-22T01:24:38Z | [
"python",
"datagrid",
"grid"
] |
Python: creating a grid | 2,112,632 | <p>Is it possible to create a grid like below?
I didn't found anything in the forum.</p>
<pre><code>#euler-project problem number 11
#In the 20 times 20 grid below,
#four numbers along a diagonal line have been marked in red.
#The product of these numbers is 26 times 63 times 78 times 14 = 1788696.
#What is the greate... | 1 | 2010-01-21T20:31:47Z | 2,116,891 | <p>As for parsing the actual data, and you don't want to read it from a file or use sensible methods, there is always this:</p>
<pre><code>s = """[[08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08]
...etc
"""
s = s.replace("]", "").replace("[", "").split()
numbers = [int(x) for x in s]
</code></pre>
<p>T... | 0 | 2010-01-22T11:32:23Z | [
"python",
"datagrid",
"grid"
] |
Python: creating a grid | 2,112,632 | <p>Is it possible to create a grid like below?
I didn't found anything in the forum.</p>
<pre><code>#euler-project problem number 11
#In the 20 times 20 grid below,
#four numbers along a diagonal line have been marked in red.
#The product of these numbers is 26 times 63 times 78 times 14 = 1788696.
#What is the greate... | 1 | 2010-01-21T20:31:47Z | 2,123,511 | <p>You can define the numbers in a string and split it easily in row/columns:</p>
<pre><code>nums = """\
1 2 3
4 5 6
7 8 9 10
"""
rows = [map(int, row.split()) for row in nums.splitlines()]
print rows ##> [[1, 2, 3], [4, 5, 6], [7, 8, 9, 10]]
</code></pre>
| 3 | 2010-01-23T14:46:49Z | [
"python",
"datagrid",
"grid"
] |
Import vs C's #include | 2,112,707 | <p>In C:</p>
<pre><code>#include "foo.h"
int main()
{
}
</code></pre>
<p>I believe that "foo.h" effectively gets copied and pasted in at the spot of the "#include".</p>
<p>Python imports are different though, I'm finding.</p>
<p>I just refactored a bit of GAE code that initially had ALL request handlers in one big... | 0 | 2010-01-21T20:39:31Z | 2,112,747 | <p>yes, they're imported first, but they're imported first <strong>into</strong> <code>index.py</code>. To be "visible" <code>globals</code> need to be imported in respective files too.</p>
| 1 | 2010-01-21T20:45:00Z | [
"python",
"import"
] |
Import vs C's #include | 2,112,707 | <p>In C:</p>
<pre><code>#include "foo.h"
int main()
{
}
</code></pre>
<p>I believe that "foo.h" effectively gets copied and pasted in at the spot of the "#include".</p>
<p>Python imports are different though, I'm finding.</p>
<p>I just refactored a bit of GAE code that initially had ALL request handlers in one big... | 0 | 2010-01-21T20:39:31Z | 2,112,994 | <p>While in C it works more or less "copy-pasting" the code, in Python is quite different.</p>
<p>Remember the Zen of Python?</p>
<pre><code>Explicit is better than implicit.
...
Namespaces are one honking great idea -- let's do more of those!
</code></pre>
<p>Each time you import a module, you execute its code, but... | 3 | 2010-01-21T21:18:58Z | [
"python",
"import"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 2,248,987 | <p>For code in your project, the only way is adding a comment saying that you expected that (the static code-analysis only sees what you see, not runtime info -- if you opened that module yourself, you'd have no indication that main was expected).</p>
<p>You can use ctrl+1 (Cmd+1 for Mac) in a line with an error and p... | 140 | 2010-02-12T01:07:36Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 4,121,187 | <p>It is possible you just need to re-configure your python path within Eclipse. See my <a href="http://stackoverflow.com/questions/2143549/undefined-variable-from-import-when-using-wxpython-in-pydev/3743861#3743861">answer</a> to a similar question. </p>
| 0 | 2010-11-08T04:08:39Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 7,240,776 | <p>I had the same problem. I am using Python and Eclipse on Windows. The code was running just fine, but eclipse show errors everywhere. After I changed the name of the folder 'Lib' to 'lib' (C:\Python27\lib), the problem was solved. It seems that if the capitalization of the letters doesn't match the one in the config... | 2 | 2011-08-30T08:52:31Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 7,954,059 | <p>I'm using opencv which relies on binaries etc so I have scripts where every other line has this silly error. Python is a dynamic language so such occasions shouldn't be considered errors.</p>
<p>I removed these errors altogether by going to:</p>
<p>Window -> Preferences -> PyDev -> Editor -> Code Analysis -> Undef... | 41 | 2011-10-31T13:01:27Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 8,534,599 | <p>I was having a similar problem with an Eclipse/PyDev project. In this project the root directory of the python code was a sub-directory of the project.</p>
<pre><code>--> MyProject
+ --> src Root of python code
+ --> module1 A module
+ --> module2 Another module
+ --> docs
+... | 6 | 2011-12-16T13:05:48Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 13,266,464 | <p>in preferences --> PyDev --> PyLint under <em>arguments to pass to PyLint</em> add this line:</p>
<pre><code>--generated-members=objects
</code></pre>
<p>you will need to do this for each generated . I found this by googling, but I lost the reference.</p>
| 0 | 2012-11-07T09:12:38Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 14,313,009 | <p>Right click in the project explorer on whichever module is giving errors. Go to PyDev->Remove Error Markers.</p>
| 0 | 2013-01-14T03:30:00Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 24,916,358 | <p><strong>My answer doesn't contribute anything new, just a concrete example I encountered.</strong></p>
<pre><code>import gtk.gdk
w = gtk.gdk.get_default_root_window()
</code></pre>
<p>PyDev showed the error message "Undefined variable from import: get_default_root_window()"</p>
<p>In the python shell you can see... | 0 | 2014-07-23T16:47:02Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 28,268,910 | <p>An approximation of what I was doing:</p>
<pre><code>import module.submodule
class MyClass:
constant = submodule.constant
</code></pre>
<p>To which pylint said:
<code>E: 4,15: Undefined variable 'submodule' (undefined-variable)</code></p>
<h1>I resolved this by changing my import like:</h1>
<pre><code>from ... | 1 | 2015-02-01T22:53:35Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 30,381,908 | <p>The post marked as answer gives a workaround, not a solution.</p>
<p>This solution works for me:</p>
<ul>
<li>Go to <code>Window - Preferences - PyDev - Interpreters - Python Interpreter</code></li>
<li>Go to the <code>Forced builtins</code> tab</li>
<li>Click on <code>New...</code></li>
<li>Type the name of the m... | 4 | 2015-05-21T18:43:36Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 37,629,671 | <p>I find that these 2 steps work for me all the time:</p>
<ol>
<li>Confirm (else add) the parent folder of the module to the PYTHONPATH.</li>
<li>Add FULL name of the module to forced builtins.</li>
</ol>
<p>The things to note here:</p>
<ul>
<li><p>Some popular modules install with some parent and child pair having... | 0 | 2016-06-04T11:28:30Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Undefined variable from import" errors? | 2,112,715 | <p>I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module <code>settings</code> that defines a <code>settings</code> object. I import that in module <code>b</code> and assign an attribute with:</p>
<pre><code>from settings import settings
settings.main ... | 117 | 2010-01-21T20:40:49Z | 39,043,085 | <p>This worked for me:</p>
<p>step 1) Removing the interpreter, auto configuring it again</p>
<p>step 2) Window - Preferences - PyDev - Interpreters - Python Interpreter
Go to the Forced builtins tab
Click on New...
Type the name of the module (curses in my case) and click OK</p>
<p>step 3) R... | 0 | 2016-08-19T15:45:09Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Method should have self as first parameter" errors | 2,112,770 | <p>I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:</p>
<pre><code>class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return se... | 7 | 2010-01-21T20:47:43Z | 2,112,797 | <pre><code>def __enter__(self):
</code></pre>
<p>and</p>
<pre><code>def __exit__(self, type, value, tb):
</code></pre>
<p>Class member methods always need to have their first parameter be <code>self</code></p>
| 0 | 2010-01-21T20:50:21Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Method should have self as first parameter" errors | 2,112,770 | <p>I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:</p>
<pre><code>class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return se... | 7 | 2010-01-21T20:47:43Z | 2,112,820 | <p>You could disable that error in the preferences...</p>
<pre><code>Window > Preferences > Pydev > Editor > Code Analysis > Others
</code></pre>
<p>Or refactor the code...</p>
<pre><code>class Group(object):
def key(self, k):
outer_self = self
class Subkey(object):
def... | 18 | 2010-01-21T20:53:15Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Method should have self as first parameter" errors | 2,112,770 | <p>I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:</p>
<pre><code>class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return se... | 7 | 2010-01-21T20:47:43Z | 2,112,826 | <p>PyDev is telling you that Python class methods must have <code>self</code> as the first variable they receive, if they're going to access the class member variables. See: <a href="http://www.python.org/doc/faq/general/#why-must-self-be-used-explicitly-in-method-definitions-and-calls" rel="nofollow">http://www.pytho... | 2 | 2010-01-21T20:54:34Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Method should have self as first parameter" errors | 2,112,770 | <p>I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:</p>
<pre><code>class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return se... | 7 | 2010-01-21T20:47:43Z | 2,113,845 | <p>It shouldn't be an error in the first place, as using "self" is only a widely-accepted convention. It should be a warning at most, in the sense of "are you sure you're using the class instance as the first argument?"</p>
| 2 | 2010-01-21T23:35:47Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Method should have self as first parameter" errors | 2,112,770 | <p>I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:</p>
<pre><code>class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return se... | 7 | 2010-01-21T20:47:43Z | 2,248,963 | <p>Using <code>Ctrl+1</code> in a line with an error from PyDev will always bring you a fix which will allow you to ignore the PyDev error in the line. In this specific case, it'll allow you to ignore the error by adding <code>#@NoSelf</code> to the end of the line. <code>Ctrl+1</code> is also useful when some unused i... | 14 | 2010-02-12T01:00:57Z | [
"python",
"code-analysis",
"pydev"
] |
How do I fix PyDev "Method should have self as first parameter" errors | 2,112,770 | <p>I'm developing in Python using PyDev in Eclipse, and some of my code generates errors in the code analysis tool. Specifically:</p>
<pre><code>class Group(object):
def key(self, k):
class Subkey(object):
def __enter__(s):
self._settings.beginGroup(k)
return se... | 7 | 2010-01-21T20:47:43Z | 7,927,703 | <p>IMO this is a silly warning. the <em>name</em> "self" is only convention. I got the habit of using the name "_" to allow the member names to be more obvious,</p>
<pre><code>class myClass( object ):
def __init__( _, color, shape, weight ):
_.color=color
_.shape=shape
_.weight=weight
...
<... | 3 | 2011-10-28T09:52:44Z | [
"python",
"code-analysis",
"pydev"
] |
Transparent FrameBuffer background in OpenGL | 2,112,779 | <p>I want to use glClear and glClearColor to fill a frame buffer with a colour including alpha transparency. However the framebuffer always renders as opaque when binded to a texture which is rendered to the screen.</p>
<p>I want everything which is rendered to the framebuffer to kept their transparency. I just want t... | 4 | 2010-01-21T20:48:31Z | 2,321,309 | <p>I think there's a basic misunderstanding of the framebuffer here. The framebuffer is not really a buffer of data in itself, it does not hold any data. You attach buffers TO it (like a texture) so that you can render to offscreen buffers in the same manner you draw to the screen. So when you say you want to "glCle... | 3 | 2010-02-23T20:05:56Z | [
"python",
"opengl",
"alphablending",
"framebuffer",
"pyopengl"
] |
Transparent FrameBuffer background in OpenGL | 2,112,779 | <p>I want to use glClear and glClearColor to fill a frame buffer with a colour including alpha transparency. However the framebuffer always renders as opaque when binded to a texture which is rendered to the screen.</p>
<p>I want everything which is rendered to the framebuffer to kept their transparency. I just want t... | 4 | 2010-01-21T20:48:31Z | 4,935,535 | <p>If you are trying to make the framebuffer transparent so you can render an object on top of your Desktop, you must know that <strong>that's not possible through Glut</strong>.</p>
<p><strong>This kind of effect is specific to the platform you are using.</strong> What is it? Linux? Windows? Mac OS X? You'll have to ... | 2 | 2011-02-08T16:24:00Z | [
"python",
"opengl",
"alphablending",
"framebuffer",
"pyopengl"
] |
Faster App Engine Development Datastore Alternative | 2,112,950 | <p>Is there a way to use a real database(SQLite, Mysql, or even some non-relational one) as datastore for development, instead of memory/file datastore that is provided.</p>
<p>I saw few projects, GAE-SQLite(did not seem to be working) and one tip about accessing production datastore using remote api (still pretty sl... | 9 | 2010-01-21T21:12:07Z | 2,114,962 | <p><a href="http://arachnid.github.com/bdbdatastore/" rel="nofollow">bdbdatastore</a> is an alternative datastore backend that's considerably better than the one built in to the development server, although the datastore is far from being the only problem with the dev server when it comes to handling large applications... | 1 | 2010-01-22T04:29:52Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Faster App Engine Development Datastore Alternative | 2,112,950 | <p>Is there a way to use a real database(SQLite, Mysql, or even some non-relational one) as datastore for development, instead of memory/file datastore that is provided.</p>
<p>I saw few projects, GAE-SQLite(did not seem to be working) and one tip about accessing production datastore using remote api (still pretty sl... | 9 | 2010-01-21T21:12:07Z | 2,116,382 | <p>MongoDB works great for that. You will need:</p>
<ul>
<li>The MongoDB stub: <a href="http://github.com/mongodb/mongo-appengine-connector" rel="nofollow">http://github.com/mongodb/mongo-appengine-connector</a></li>
<li>MongoDB: <a href="http://www.mongodb.org/display/DOCS/Downloads" rel="nofollow">http://www.mongodb... | 4 | 2010-01-22T09:54:21Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Faster App Engine Development Datastore Alternative | 2,112,950 | <p>Is there a way to use a real database(SQLite, Mysql, or even some non-relational one) as datastore for development, instead of memory/file datastore that is provided.</p>
<p>I saw few projects, GAE-SQLite(did not seem to be working) and one tip about accessing production datastore using remote api (still pretty sl... | 9 | 2010-01-21T21:12:07Z | 4,813,724 | <p>The Google App Engine SDK for Python now bundles support for SQLite. See the <a href="https://developers.google.com/appengine/docs/python/tools/devserver?csw=1#Python_Using_the_Datastore" rel="nofollow">official docs</a> for more information.</p>
| 2 | 2011-01-27T07:23:24Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,112,982 | <p>You need to fix your if statements the "==" operator checks for equality, and you must put the variable you are checking against in each section of the statement.</p>
<pre><code>public int winCraps{
roll = rollDice();
if (roll == 7 || roll == 11) {
return true;
}
else if(roll == 2 || roll ==... | 2 | 2010-01-21T21:16:55Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,112,983 | <p>I'd recommend that you look up the docs on <code>randrange()</code>. Once you know exactly what it does, google for the those keywords, plus the word Java.</p>
<p>One thing you'll quickly discover in working with languages is that the APIs can be very different. There might not be an equivalent of <code>randrange<... | 0 | 2010-01-21T21:17:28Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,112,992 | <p>Randrange can be replaced by methods in <a href="http://java.sun.com/javase/6/docs/api/java/util/Random.html" rel="nofollow">java.util.Random</a>. Like Python, Java has an extensive standard library which you should reference.</p>
| 1 | 2010-01-21T21:18:51Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,112,999 | <p>One major error in your first program that you have in the Java conversion is the conditionals.</p>
<p>Something like (roll =2 && 3 && 12) assigns 2 to roll and then applies AND operators. You also forgot the if. You have elseif in Python.</p>
<p>You want something like:</p>
<p>else if(roll==2 || ... | -1 | 2010-01-21T21:19:30Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,113,033 | <blockquote>
<p>What would randrange be in Java?</p>
</blockquote>
<p>You can get a random integer in a specific range from Java's Random class by calling the <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/util/Random.html#nextInt%28int%29" rel="nofollow">nextInt(int n)</a> method. For example,</p>
<pre><co... | 2 | 2010-01-21T21:24:02Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,113,063 | <p><code>System.out.print</code> isn't going to cause the system to wait for someone to hit the enter key. For that, you need to do something with <code>System.in</code>, most likely <a href="http://java.sun.com/javase/6/docs/api/java/io/InputStream.html#read%28%29" rel="nofollow"><code>System.in.read()</code></a>, as... | 0 | 2010-01-21T21:29:22Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,113,190 | <p><strong>1)</strong> In Java "OR" operator is "||" not "&&" and comparison operator is "==" as in Python </p>
<p>So</p>
<pre><code>if roll == 7 or roll == 11:
</code></pre>
<p>Should be </p>
<pre><code>if( roll == 7 || roll == 11 ) {
</code></pre>
<p>and not </p>
<pre><code> if( roll = 7 && 11 )... | 1 | 2010-01-21T21:47:54Z | [
"java",
"python"
] |
Python Program converted into Java | 2,112,952 | <p>Sooo I started taking my second computer science class ever! For my first class we used python and for this class we're using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I'm just having a hell of a time. </p>
<p>Could someone please help with what ... | 2 | 2010-01-21T21:12:32Z | 2,115,619 | <p>Write out in English what the Python program does. Go through it line by line and explain to yourself what computations are evoked, in other words...what is happening?</p>
<p>Afterwards, write the Java program from that description.</p>
<p>Never ever try to convert the text of a program from one language to anothe... | 0 | 2010-01-22T07:06:06Z | [
"java",
"python"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,113,132 | <p>If you need to wrap around on overflow, simply take your sum modulo MAX_LONG at the end.</p>
| 3 | 2010-01-21T21:39:36Z | [
"python",
"overflow",
"sum",
"byte"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,113,298 | <p>As I mentioned in my comment, you need to convert the string into a <code>list</code> of <code>int</code>s.
This probably what you want:</p>
<pre><code>f=open("infile.txt",'rb')
m=f.read()
f.close()
m=map(ord,list(m))
print sum(m)
</code></pre>
<p>The <code>ord</code> function returns the ascii <code>int</code> co... | 0 | 2010-01-21T22:03:54Z | [
"python",
"overflow",
"sum",
"byte"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,113,333 | <p>I've tried your code, and seems to be working (it opens the data in binary, convert it to a list of unsigned char and adds all). </p>
<p>What is your problem? Could be an overflow problem? Maybe there is a problem with the length? How are you saving the file?
Sorry, but with this information we can only guess!</p>
... | 0 | 2010-01-21T22:08:48Z | [
"python",
"overflow",
"sum",
"byte"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,115,005 | <p>A direct, Pythonic translation:</p>
<pre><code>def memSum(data):
return sum(ord(c) for c in data) & 0xFFFFFFFF
</code></pre>
| 2 | 2010-01-22T04:41:10Z | [
"python",
"overflow",
"sum",
"byte"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,115,218 | <p>You really need to give an example input and what you expect as output. Any code that uses a recent version of Python, extracts an integer in range(256) from each byte, sums those integers, and finally does <code>total &= 0xFFFFFFFF</code> should do the job (assuming that your <code>unsigned long</code> is 32 bi... | 0 | 2010-01-22T05:22:23Z | [
"python",
"overflow",
"sum",
"byte"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,116,197 | <p>first, thank you all for your help</p>
<p>I have written successfully the C implementation and tested over 20 different files the checksum function. And then the 2 complement of the computed checksum is compared to a checksum a the file. It works perfectly in C as mentionned: with unsigned char and unsigned long.</... | 0 | 2010-01-22T09:21:12Z | [
"python",
"overflow",
"sum",
"byte"
] |
sum of bytes with unsigned long overflow in python | 2,113,118 | <p>how to translate this piece of C code into Python >=2.6 ?</p>
<pre><code>unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
</code></pre>
<p>of course</p>
<pre><code>f=open("file_to_sum",'rb')
m = f.read()... | 2 | 2010-01-21T21:37:34Z | 2,116,494 | <p>SOLVED : MY FAULT, SORRY</p>
<pre><code>#include<stdio.h>
unsigned long memSum(unsigned char *p, unsigned long len)
{
unsigned long i, sum=0;
for(i=0; i<len; i++)
sum = sum + *p++;
return sum;
}
#define LEN2SUM (0xa13b10-4)
int main(int argc, char *argv[] )
{
FILE *f;
unsigned c... | 0 | 2010-01-22T10:14:45Z | [
"python",
"overflow",
"sum",
"byte"
] |
Pylons Uploading Distorted Images on Windows | 2,113,126 | <p>I'm creating an web app in Pylons, and am working on an image upload action. This is currently running using egg:paste#http on my windows machine, in the basic development configuration described in the pylons documentation quickstart.</p>
<p>When I POST an image to my application, then move the image to the web r... | 2 | 2010-01-21T21:38:37Z | 2,113,347 | <p>You are probably just missing the 'b' (binary) flag for effectively writing the file as binary:</p>
<pre><code>save_file = open(os_path, 'wb')
</code></pre>
<p>But I don't see why you need the <code>shutil.copyfileobj</code> call in there, why not do something like this:</p>
<pre><code>file_save_path = os.path.jo... | 3 | 2010-01-21T22:11:07Z | [
"python",
"image",
"file-upload",
"pylons",
"paster"
] |
How can I keep on-the-fly application-level statistics in an application running under Apache? | 2,113,352 | <p>I have an application running under apache that I want to keep "in the moment" statistics on. I want to have the application tell me things like:</p>
<ul>
<li>requests per second, broken down by types of request</li>
<li>latency to make requests to various backend services via thrift (broken down by service and se... | 3 | 2010-01-21T22:11:45Z | 2,113,376 | <p>Perhaps you could keep the relevant counters and other statistics in a memcached, that is accessed by all apache processes?</p>
| 1 | 2010-01-21T22:15:10Z | [
"python",
"multithreading",
"apache",
"pylons",
"fork"
] |
How can I keep on-the-fly application-level statistics in an application running under Apache? | 2,113,352 | <p>I have an application running under apache that I want to keep "in the moment" statistics on. I want to have the application tell me things like:</p>
<ul>
<li>requests per second, broken down by types of request</li>
<li>latency to make requests to various backend services via thrift (broken down by service and se... | 3 | 2010-01-21T22:11:45Z | 2,117,002 | <p>Use pylons.g object. It is an instance of Globals class in your Pylons application's lib/app_globals.py file. Its state changes will be visible to all threads, so stuff in it needs to be threadsafe.</p>
<p>lib/app_globals.py:</p>
<pre><code>class Globals(object):
def __init__(self):
self.requests_serve... | -1 | 2010-01-22T11:57:29Z | [
"python",
"multithreading",
"apache",
"pylons",
"fork"
] |
How can I keep on-the-fly application-level statistics in an application running under Apache? | 2,113,352 | <p>I have an application running under apache that I want to keep "in the moment" statistics on. I want to have the application tell me things like:</p>
<ul>
<li>requests per second, broken down by types of request</li>
<li>latency to make requests to various backend services via thrift (broken down by service and se... | 3 | 2010-01-21T22:11:45Z | 2,138,224 | <blockquote>
<p>I want to do this without any external
dependencies.</p>
</blockquote>
<p><strong>What if your apache dies somehow?</strong> (Separation of concerns?)</p>
<p>Personally I am using (redundant) <a href="http://www.nagios.org/" rel="nofollow">Nagios</a> to monitor the hardware itself, services, <stro... | 1 | 2010-01-26T08:33:48Z | [
"python",
"multithreading",
"apache",
"pylons",
"fork"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 2,113,457 | <p>It may seem strange to suggest this, but a common Python idiom is </p>
<blockquote>
<p>It's easier to ask for forgiveness
than for permission</p>
</blockquote>
<p>Following that idiom, one might say:</p>
<p>Try writing to the directory in question, and catch the error if you don't have the permission to do so... | 44 | 2010-01-21T22:30:40Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 2,113,471 | <p>Check the mode bits: </p>
<pre><code>def isWritable(name):
uid = os.geteuid()
gid = os.getegid()
s = os.stat(dirname)
mode = s[stat.ST_MODE]
return (
((s[stat.ST_UID] == uid) and (mode & stat.S_IWUSR)) or
((s[stat.ST_GID] == gid) and (mode & stat.S_IWGRP)) or
(mode & stat.S_IWOT... | 5 | 2010-01-21T22:32:49Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 2,113,511 | <p>Although what Christophe suggested is a more Pythonic solution, the os module does have a function to check access:</p>
<p><code>os.access('/path/to/folder', os.W_OK)</code> # W_OK is for writing, R_OK for reading, etc.</p>
| 95 | 2010-01-21T22:39:22Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 2,113,750 | <p>If you only care about the file perms, <code>os.access(path, os.W_OK)</code> should do what you ask for. If you instead want to know whether you <strong>can</strong> write to the directory, <code>open()</code> a test file for writing (it shouldn't exist beforehand), catch and examine any <code>IOError</code>, and cl... | 9 | 2010-01-21T23:17:40Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 8,620,444 | <p>Here is something I created based on ChristopheD's answer:</p>
<pre><code>import os
def isWritable(directory):
try:
tmp_prefix = "write_tester";
count = 0
filename = os.path.join(directory, tmp_prefix)
while(os.path.exists(filename)):
filename = "{}.{}".format(os.pat... | 3 | 2011-12-23T20:43:06Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 11,170,037 | <p>Stumbled across this thread searching for examples for someone. First result on Google, congrats!</p>
<p>People talk about the Pythonic way of doing it in this thread, but no simple code examples? Here you go, for anyone else who stumbles in:</p>
<pre><code>import sys
filepath = 'C:\\path\\to\\your\\file.txt'
tr... | 6 | 2012-06-23T13:52:21Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Determining Whether a Directory is Writeable | 2,113,427 | <p>What would be the best way in Python to determine whether a directory is writeable for the user executing the script? Since this will likely involve using the os module I should mention I'm running it under a *nix environment. </p>
| 55 | 2010-01-21T22:24:39Z | 25,868,839 | <p>My solution using the <code>tempfile</code> module:</p>
<pre><code>import tempfile
import errno
def isWritable(path):
try:
testfile = tempfile.TemporaryFile(dir = path)
testfile.close()
except OSError as e:
if e.errno == errno.EACCES: # 13
return False
e.filenam... | 11 | 2014-09-16T12:30:39Z | [
"python",
"file",
"permissions",
"directory",
"operating-system"
] |
Group by hour in SQLAlchemy? | 2,113,448 | <p>How do I group query results by the hour part of a datetime column in SQLAlchemy?</p>
| 5 | 2010-01-21T22:29:06Z | 2,113,473 | <p>This works for PostgreSQL:</p>
<pre><code>.group_by(func.date_trunc('hour', date_col))
</code></pre>
| 9 | 2010-01-21T22:33:37Z | [
"python",
"sqlite",
"sqlalchemy"
] |
Group by hour in SQLAlchemy? | 2,113,448 | <p>How do I group query results by the hour part of a datetime column in SQLAlchemy?</p>
| 5 | 2010-01-21T22:29:06Z | 2,113,482 | <p>If I remember correctly you must first extract the hour from your timestamp and then you can group by that.</p>
<pre><code>query(extract('hour', timeStamp).label('h')).group_by('h')
</code></pre>
| 6 | 2010-01-21T22:34:47Z | [
"python",
"sqlite",
"sqlalchemy"
] |
Group by hour in SQLAlchemy? | 2,113,448 | <p>How do I group query results by the hour part of a datetime column in SQLAlchemy?</p>
| 5 | 2010-01-21T22:29:06Z | 3,795,794 | <p>You can also do it in Python. Assuming you have an ordered <code>query_result</code> :</p>
<pre><code>from itertools import groupby
def grouper( item ):
return item.created.hour
for ( hour, items ) in groupby( query_result, grouper ):
for item in items:
# do stuff
</code></pre>
<p>This answer is ... | -2 | 2010-09-25T22:11:20Z | [
"python",
"sqlite",
"sqlalchemy"
] |
Group by hour in SQLAlchemy? | 2,113,448 | <p>How do I group query results by the hour part of a datetime column in SQLAlchemy?</p>
| 5 | 2010-01-21T22:29:06Z | 30,846,937 | <p>Recently I had to do a similar thing using SqlAlchemy and MySQL and ended up using the DATE_FORMAT (<a href="http://www.w3schools.com/sql/func_date_format.asp" rel="nofollow">http://www.w3schools.com/sql/func_date_format.asp</a>) to group by hour, minute, second </p>
<pre><code>.group_by(func.date_format(date_col, ... | 0 | 2015-06-15T13:50:57Z | [
"python",
"sqlite",
"sqlalchemy"
] |
How to download a file via the browser from Amazon S3 using Python (and boto) at Google App Engine? | 2,113,777 | <p>I have a python script running inside the Google App Engine with boto 1.9b that gets all keys inside a S3-Bucket. The output is formated as a HTML-Table. </p>
<pre><code>bucket_instance = conn_s3.get_bucket(bucketname)
liste_keys = bucket_instance.get_all_keys()
table = '<table>'
for i in range(laenge_liste_... | 2 | 2010-01-21T23:23:10Z | 2,113,831 | <p>The public URL for the file would be something like: </p>
<pre><code>http://s3.amazonaws.com/bucket_name/key_name
</code></pre>
<p>So in your code, add links with their href attributes pointing to that URL. </p>
| 2 | 2010-01-21T23:32:52Z | [
"python",
"html",
"google-app-engine",
"amazon-s3",
"boto"
] |
How to download a file via the browser from Amazon S3 using Python (and boto) at Google App Engine? | 2,113,777 | <p>I have a python script running inside the Google App Engine with boto 1.9b that gets all keys inside a S3-Bucket. The output is formated as a HTML-Table. </p>
<pre><code>bucket_instance = conn_s3.get_bucket(bucketname)
liste_keys = bucket_instance.get_all_keys()
table = '<table>'
for i in range(laenge_liste_... | 2 | 2010-01-21T23:23:10Z | 2,116,357 | <p>The solution is found.</p>
<pre><code>generate_url(expires_in, method='GET', headers=None, query_auth=True, force_http=False)
</code></pre>
<p>This makes it easy to create a link for every key which is valid for x seconds. </p>
| 3 | 2010-01-22T09:49:03Z | [
"python",
"html",
"google-app-engine",
"amazon-s3",
"boto"
] |
Read XML with multiple top-level items using Python ElementTree? | 2,113,819 | <p>How can I read an XML file using Python ElementTree, if the XML has multiple top-level items?</p>
<p>I have an XML file that I would like to read using Python ElementTree.</p>
<p>Unfortunately, it has multiple top-level tags. I would wrap <code><doc>...</doc></code> around the XML, except I have to put... | 3 | 2010-01-21T23:30:37Z | 2,120,457 | <p>I wrote the following function to add a toplevel tag <strong>after</strong> the XML processing instructions. You can now find this code in my <a href="http://github.com/turian/common/" rel="nofollow">common Python library</a> as <a href="http://github.com/turian/common/blob/master/myelementtree.py" rel="nofollow">co... | 0 | 2010-01-22T20:57:49Z | [
"python",
"xml",
"parsing",
"elementtree"
] |
Python: getting filename case as stored in Windows? | 2,113,822 | <p>Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system?</p>
<p>E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this... | 12 | 2010-01-21T23:30:54Z | 2,113,912 | <pre><code>>>> import os
>>> os.listdir("./")
['FiLeNaMe.txt']
</code></pre>
<p>Does this answer your question?</p>
| 1 | 2010-01-21T23:48:43Z | [
"python",
"windows",
"case",
"filenames"
] |
Python: getting filename case as stored in Windows? | 2,113,822 | <p>Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system?</p>
<p>E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this... | 12 | 2010-01-21T23:30:54Z | 2,113,916 | <p>You could use:</p>
<pre><code>import os
a = os.listdir('mydirpath')
b = [f.lower() for f in a]
try:
i = b.index('texas.txt')
print a[i]
except ValueError:
print('File not found in this directory')
</code></pre>
<p>This of course assumes that your search string <code>'texas.txt'</code> is in lowercase. ... | 1 | 2010-01-21T23:50:06Z | [
"python",
"windows",
"case",
"filenames"
] |
Python: getting filename case as stored in Windows? | 2,113,822 | <p>Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system?</p>
<p>E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this... | 12 | 2010-01-21T23:30:54Z | 2,114,170 | <p>and if you want to recurse directories</p>
<pre><code>import os
path=os.path.join("c:\\","path")
for r,d,f in os.walk(path):
for file in f:
if file.lower() == "texas.txt":
print "Found: ",os.path.join( r , file )
</code></pre>
| 1 | 2010-01-22T00:48:03Z | [
"python",
"windows",
"case",
"filenames"
] |
Python: getting filename case as stored in Windows? | 2,113,822 | <p>Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system?</p>
<p>E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this... | 12 | 2010-01-21T23:30:54Z | 2,114,975 | <p>Here's the simplest way to do it:</p>
<pre><code>>>> import win32api
>>> win32api.GetLongPathName(win32api.GetShortPathName('texas.txt')))
'TEXAS.txt'
</code></pre>
| 7 | 2010-01-22T04:33:51Z | [
"python",
"windows",
"case",
"filenames"
] |
Python: getting filename case as stored in Windows? | 2,113,822 | <p>Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system?</p>
<p>E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this... | 12 | 2010-01-21T23:30:54Z | 7,622,476 | <p>I had problems with special characters with the win32api solution above. For unicode filenames you need to use:</p>
<pre><code>win32api.GetLongPathNameW(win32api.GetShortPathName(path))
</code></pre>
| 4 | 2011-10-01T19:33:50Z | [
"python",
"windows",
"case",
"filenames"
] |
Python: getting filename case as stored in Windows? | 2,113,822 | <p>Though Windows is case insensitive, it does preserve case in filenames. In Python, is there any way to get a filename with case as it is stored on the file system?</p>
<p>E.g., in a Python program I have filename = "texas.txt", but want to know that it's actually stored "TEXAS.txt" on the file system, even if this... | 12 | 2010-01-21T23:30:54Z | 39,140,604 | <p>This one is standard lib only and converts all path parts (except drive letter):</p>
<pre><code>def casedpath(path):
r = glob.glob(re.sub(r'([^:/\\])(?=[/\\]|$)', r'[\1]', path))
return r and r[0] or path
</code></pre>
<p>And this one handles UNC paths in addition:</p>
<pre><code>def casedpath_unc(path):
... | 0 | 2016-08-25T08:44:54Z | [
"python",
"windows",
"case",
"filenames"
] |
Does python have the equivalent of Perl's regex "local" variable? | 2,113,843 | <p>While searching for a solution to a python regular expression problem I found <a href="http://perl.plover.com/yak/regex/samples/slide083.html" rel="nofollow">this page</a> which demonstrates that [some version of] perl allows variables within regular expressions. </p>
<p>e.g. a perl regex <em>something</em> like:</... | 2 | 2010-01-21T23:34:57Z | 2,113,877 | <p>No. You need a grammer - pyparsing is nice (and easy)</p>
| 2 | 2010-01-21T23:42:33Z | [
"python",
"regex",
"perl"
] |
py2exe and win32com | 2,113,863 | <p>Can <a href="http://www.py2exe.org/" rel="nofollow"><code>py2exe</code></a> create standalone executables even ones requiring the <a href="https://sourceforge.net/projects/pywin32/" rel="nofollow"><code>win32com</code></a> package?</p>
<p>I've googled / searched SO to no avail.</p>
| 4 | 2010-01-21T23:40:11Z | 2,114,071 | <p>I've used <a href="http://www.py2exe.org/" rel="nofollow"><code>py2exe</code></a> for a project that depended on <a href="https://sourceforge.net/projects/pywin32/" rel="nofollow"><code>win32com</code></a> as well as <a href="http://pysvn.tigris.org/" rel="nofollow"><code>pysvn</code></a>. It worked fine, no hassles... | 4 | 2010-01-22T00:25:57Z | [
"python",
"py2exe",
"win32com"
] |
py2exe and win32com | 2,113,863 | <p>Can <a href="http://www.py2exe.org/" rel="nofollow"><code>py2exe</code></a> create standalone executables even ones requiring the <a href="https://sourceforge.net/projects/pywin32/" rel="nofollow"><code>win32com</code></a> package?</p>
<p>I've googled / searched SO to no avail.</p>
| 4 | 2010-01-21T23:40:11Z | 2,149,667 | <p>Yes, it can. But you may need to add a refereneces to DLL that your application needs.
Check the bottom of <a href="http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules" rel="nofollow">http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules</a> . It contains useful resources to build Pyt... | 3 | 2010-01-27T19:22:00Z | [
"python",
"py2exe",
"win32com"
] |
Cannot solve mod_wsgi exception in Django setup | 2,113,905 | <p>I'm working with my hosting provider to get a Django application up and running, but neither of us are very experienced and we've basically hit a complete dead end.</p>
<p>I don't have direct access to the conf file but here's how its contents have been described to me:</p>
<pre><code><IfModule mod_wsgi.c>
W... | 10 | 2010-01-21T23:47:32Z | 2,113,958 | <p>Is it possible that your starting directory is not the one project is in?</p>
<p>Today I was also setting up Apache+mod_wsgi+Django app and after adding to django.wsgi:</p>
<pre><code> os.chdir('/home/user/my_django_project')
</code></pre>
<p>everything started to work like a charm.</p>
| 1 | 2010-01-22T00:02:48Z | [
"python",
"django",
"apache",
"wsgi"
] |
Cannot solve mod_wsgi exception in Django setup | 2,113,905 | <p>I'm working with my hosting provider to get a Django application up and running, but neither of us are very experienced and we've basically hit a complete dead end.</p>
<p>I don't have direct access to the conf file but here's how its contents have been described to me:</p>
<pre><code><IfModule mod_wsgi.c>
W... | 10 | 2010-01-21T23:47:32Z | 2,115,958 | <p>We had the same error when the user running Apache had not the rights to read the files.</p>
| 0 | 2010-01-22T08:32:31Z | [
"python",
"django",
"apache",
"wsgi"
] |
Cannot solve mod_wsgi exception in Django setup | 2,113,905 | <p>I'm working with my hosting provider to get a Django application up and running, but neither of us are very experienced and we've basically hit a complete dead end.</p>
<p>I don't have direct access to the conf file but here's how its contents have been described to me:</p>
<pre><code><IfModule mod_wsgi.c>
W... | 10 | 2010-01-21T23:47:32Z | 2,116,481 | <p>If the quoted configuration about is what you are using, the error is rather obvious actually. You have:</p>
<pre><code>WSGIDaemonProcess fred threads=15 display-name=%{GROUP} python-path=/home/fred/public_html/cgi-bin/fredapp/apache/
WSGIProcessGroup scratchf
</code></pre>
<p>It should be:</p>
<pre><code>WSGIDae... | 13 | 2010-01-22T10:12:25Z | [
"python",
"django",
"apache",
"wsgi"
] |
Python XML Parsing Confusion | 2,113,917 | <p>I'm using xml.dom.mindom in Python and have retrieved the book node in the below XML tree. I want to get a list of all children nodes. In this case, I would think there would only be one. </p>
<pre><code><Book>
<Title>Why is this so hard</Title>
</Book
</code></pre>
<p>When I call:</p>
... | 1 | 2010-01-21T23:50:25Z | 2,113,926 | <p>The first text node is the whitespace between <Book> and <Title>. The second is the whitespace between </Title> and </Book></p>
| 3 | 2010-01-21T23:53:08Z | [
"python",
"xml"
] |
Python XML Parsing Confusion | 2,113,917 | <p>I'm using xml.dom.mindom in Python and have retrieved the book node in the below XML tree. I want to get a list of all children nodes. In this case, I would think there would only be one. </p>
<pre><code><Book>
<Title>Why is this so hard</Title>
</Book
</code></pre>
<p>When I call:</p>
... | 1 | 2010-01-21T23:50:25Z | 2,117,327 | <blockquote>
<p>What are these random #text nodes?</p>
</blockquote>
<p>Hardly random, they're text nodes representing the whitespace you put between tags. XML has to remember this, or the document would be all run together in one unreadable line when it's reserialised.</p>
<blockquote>
<p>How do I get the tagNam... | 0 | 2010-01-22T13:04:09Z | [
"python",
"xml"
] |
Preserving argument default values while method chaining | 2,114,510 | <p>If I have to wrap an existing method, let us say wrapee() from a new method, say wrapper(), and the wrapee() provides default values for some arguments, how do I preserve its semantics without introducing unnecessary dependencies and maintenance? Let us say, the goal is to be able to use wrapper() in place of wrapee... | 3 | 2010-01-22T02:12:56Z | 2,114,517 | <p>Check out <a href="http://docs.python.org/tutorial/controlflow.html#arbitrary-argument-lists" rel="nofollow">argument lists</a> in the Python docs.</p>
<pre><code>>>> def wrapper(param1, *stuff, **kargs):
... print(param1)
... print(stuff)
... print(args)
...
>>> wrapper(3, 4, 5, foo=2)
3
(4, 5... | 3 | 2010-01-22T02:15:28Z | [
"python"
] |
Preserving argument default values while method chaining | 2,114,510 | <p>If I have to wrap an existing method, let us say wrapee() from a new method, say wrapper(), and the wrapee() provides default values for some arguments, how do I preserve its semantics without introducing unnecessary dependencies and maintenance? Let us say, the goal is to be able to use wrapper() in place of wrapee... | 3 | 2010-01-22T02:12:56Z | 2,114,524 | <pre><code>def wrapper(param1, param2=None):
if param2:
wrapee(param1, param2)
else:
wrapee(param1)
</code></pre>
| 0 | 2010-01-22T02:17:16Z | [
"python"
] |
Preserving argument default values while method chaining | 2,114,510 | <p>If I have to wrap an existing method, let us say wrapee() from a new method, say wrapper(), and the wrapee() provides default values for some arguments, how do I preserve its semantics without introducing unnecessary dependencies and maintenance? Let us say, the goal is to be able to use wrapper() in place of wrapee... | 3 | 2010-01-22T02:12:56Z | 2,114,598 | <p>is this what you want?</p>
<pre><code>#!/usr/bin/python
from functools import wraps
def my_decorator(f):
@wraps(f)
def wrapper(*args, **kwds):
print 'Calling decorated function'
return f(*args, **kwds)
return wrapper
def f1(x, y):
print x, y
def f2(x, y="ok"):
print x, y
my_deco... | 0 | 2010-01-22T02:34:59Z | [
"python"
] |
Preserving argument default values while method chaining | 2,114,510 | <p>If I have to wrap an existing method, let us say wrapee() from a new method, say wrapper(), and the wrapee() provides default values for some arguments, how do I preserve its semantics without introducing unnecessary dependencies and maintenance? Let us say, the goal is to be able to use wrapper() in place of wrapee... | 3 | 2010-01-22T02:12:56Z | 2,114,601 | <p>I'd hardly say that it isn't tedious, but the only approach that I can think of is to introspect the function that you are wrapping to determine if any of its parameters have default values. You can get the list of parameters and then determine which one is the first that has default values:</p>
<pre><code>from ins... | 3 | 2010-01-22T02:35:44Z | [
"python"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,556 | <p>Typically, exceptions carry some overhead, and are meant for truly 'exceptional' cases. In this case, this sounds like a normal part of the execution, not an 'exceptional' or 'error' state. </p>
<p>In general, I think your code will benefit by using the "if/else" convention, and saving exceptions for only when they... | 9 | 2010-01-22T02:26:48Z | [
"python",
"exception",
"coding-style"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,557 | <p>Neither, I would go for</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
return d.get(c, "N/A")
</code></pre>
<p>This way is shorter and "get" is designed for the job.</p>
<p>Also an except without an explicit exception is bad pratice, so use <code>except KeyError:</code> not ju... | 21 | 2010-01-22T02:27:11Z | [
"python",
"exception",
"coding-style"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,563 | <p>Neither.</p>
<pre><code>return d.get(c, 'N/A')
</code></pre>
| 7 | 2010-01-22T02:27:56Z | [
"python",
"exception",
"coding-style"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,572 | <p>In general terms (not necessarily Python), I tend to prefer the "try-then-tell-me-if-it-went-wrong" method (exceptions) in all but the simplest cases. This is because, in threaded environments or during database access, the underlying data can change between the key check and the value extraction.</p>
<p>If you're ... | 11 | 2010-01-22T02:29:41Z | [
"python",
"exception",
"coding-style"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,632 | <p>I'm with David on this one: </p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
return d.get(c, "N/A")
</code></pre>
<p>...is exactly how I'd write it. </p>
<p>To address your other options: </p>
<p>In 'f1()', there's nothing wrong with this, per se, but dictionari... | 4 | 2010-01-22T02:44:41Z | [
"python",
"exception",
"coding-style"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,776 | <p>I see people using "get", which I recommend. However, if you find yourself in a similar situation in the future, catch the exception you mean:</p>
<pre><code>try:
return d[k]
except KeyError:
return "N/A"
</code></pre>
<p>This way, other exceptions (including <code>KeyboardInterrupt</code>) don't get caug... | 1 | 2010-01-22T03:40:58Z | [
"python",
"exception",
"coding-style"
] |
which style is preferred? | 2,114,540 | <p>Option 1:</p>
<pre><code>def f1(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
if c in d:
return d[c]
return "N/A"
</code></pre>
<p>Option 2:</p>
<pre><code>def f2(c):
d = {
"USA": "N.Y.",
"China": "Shanghai"
}
try:
return d[c]
except:
return "N/A"
</code></pre>
<p>... | 9 | 2010-01-22T02:21:36Z | 2,114,842 | <p>I agree that in this case, dict.get is the best solution.</p>
<p>In general, I think your choice will depend on how likely the exceptions are. If you expect the key lookups to mostly pass, then the try/catch is a better choice IMO. Similarly, if they will be failing often, an if statement is better.</p>
<p>Perform... | 0 | 2010-01-22T04:00:22Z | [
"python",
"exception",
"coding-style"
] |
Why does not the Python MSI installers come with Tcl/Tk header files? | 2,114,615 | <p>The MSI installers downloadable from python.org does not include Tcl/Tk <strong>header</strong> (not source) files (that are required to compile some packages like matplotlib). Does anyone know of the rationale behind not including them?</p>
| 0 | 2010-01-22T02:40:08Z | 2,114,635 | <p>The windows installers don't include ANY source files. Simply because that's how windows apps work. It can be compiled on one computer and it will work on all. So windows versions of things like python and php come precompiled with all options enabled.</p>
<p>If you want the source files you have to download a sour... | 1 | 2010-01-22T02:45:18Z | [
"python",
"tcl",
"tkinter",
"header-files",
"tk"
] |
Why does not the Python MSI installers come with Tcl/Tk header files? | 2,114,615 | <p>The MSI installers downloadable from python.org does not include Tcl/Tk <strong>header</strong> (not source) files (that are required to compile some packages like matplotlib). Does anyone know of the rationale behind not including them?</p>
| 0 | 2010-01-22T02:40:08Z | 2,804,309 | <p>Users, even on Unix systems, do not really need the Tcl/Tk headers to just use the Python interpreter.</p>
<p>If you were to wanting to embed the interpreter in another application, you only need the python headers and lib files (which are included in the installer). The tkinter module, which is what is linked to ... | 0 | 2010-05-10T16:12:38Z | [
"python",
"tcl",
"tkinter",
"header-files",
"tk"
] |
Math and change field color | 2,114,618 | <pre><code>from django.db import models
from django.contrib.auth.models import User
class Product(models.Model):
name = models.CharField(max_length = 127)
description = models.TextField()
code = models.CharField(max_length = 30)
lot_no = models.CharField(max_length = 30)
inventory = models.IntegerField()
commited = mo... | 1 | 2010-01-22T02:40:41Z | 6,341,363 | <pre><code>def colored_available(self):
if self.reorder < self.available:
return self.reorder
return '<span style="color: red;">%d</span>' % self.reorder
colored_available.allow_tags = True
colored_available.short_description = "Available"
</code></pre>
<p>And this to your model admin (p... | 0 | 2011-06-14T09:08:03Z | [
"python",
"django-admin"
] |
Python extensions that can be used in all varieties of python (jython / IronPython / etc.) | 2,114,627 | <p>In the 'old days' when there was just cpython, most extensions were written in c (as platform independent as possible) and compiled into pyd's (think PyCrypto for example). Now there is Jython, IronPython and PyPy and the pydâs do not work with any of them (Ironclad aside). It seems they all support ctypes and t... | 4 | 2010-01-22T02:44:02Z | 2,116,557 | <p>Currently, it seems the ctypes is indeed the best approach. It works today, and it's so convenient that it's gonna conquer (most of) the world.</p>
<p>For performance-critical APIs (such as numpy), ctypes is indeed problematic. The cleanest approach would probably be to port Cython to produce native IronPython / ... | 2 | 2010-01-22T10:26:03Z | [
"python",
"ironpython",
"jython"
] |
Python extensions that can be used in all varieties of python (jython / IronPython / etc.) | 2,114,627 | <p>In the 'old days' when there was just cpython, most extensions were written in c (as platform independent as possible) and compiled into pyd's (think PyCrypto for example). Now there is Jython, IronPython and PyPy and the pydâs do not work with any of them (Ironclad aside). It seems they all support ctypes and t... | 4 | 2010-01-22T02:44:02Z | 2,119,710 | <p>If you're wrapping an existing native library, the ctypes is absolutely the way to go.</p>
<p>If you're trying to speed up the hot spots in a Python extension, then making a custom extension for each interpreter (and a pure-Python fallback) is tractable because the bulk of the code is pure Python that can be shared... | 1 | 2010-01-22T19:02:48Z | [
"python",
"ironpython",
"jython"
] |
How to serialize db.Model objects to json? | 2,114,659 | <p>When using</p>
<pre><code>from django.utils import simplejson
</code></pre>
<p>on objects of types that derive from <code>db.Model</code> it throws exceptions. How to circumvent this?</p>
| 16 | 2010-01-22T02:53:41Z | 2,114,870 | <p>json cannot be used to serialize anything more than basic types such as dicts, lists, ints/longs, and strings (this is not comprehensive). For example, even these simple commands do not work:</p>
<pre><code>import json
json.dumps(object())
</code></pre>
<p>If you want to serialize django objects, you should refer ... | 3 | 2010-01-22T04:07:08Z | [
"python",
"google-app-engine",
"simplejson"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.