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 |
|---|---|---|---|---|---|---|---|---|---|
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 1,181,539 | <p>You can use <code>win32api</code> or <code>ctypes</code> module to use win32 apis for controlling mouse or any gui</p>
<p>Here is a fun example to control mouse using win32api:</p>
<pre><code>import win32api
import time
import math
for i in range(500):
x = int(500+math.sin(math.pi*i/100)*500)
y = int(500+... | 60 | 2009-07-25T07:57:19Z | [
"python",
"mouse"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 6,600,457 | <p>Check out the cross platform PyMouse: <a href="https://github.com/pepijndevos/PyMouse/">https://github.com/pepijndevos/PyMouse/</a> </p>
| 17 | 2011-07-06T17:24:03Z | [
"python",
"mouse"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 17,578,569 | <p>Another option is to use the cross-platform <a href="https://pypi.python.org/pypi/autopy/0.51">AutoPy package</a>. This package has two different options for moving the mouse:</p>
<p>This code snippet will instantly move the cursor to position (200,200):</p>
<pre><code>import autopy
autopy.mouse.move(200,200)
</co... | 13 | 2013-07-10T18:46:50Z | [
"python",
"mouse"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 26,693,987 | <p>Quick and dirty function that'll left click wherever <code>clicks</code> times on Windows 7 using the <a href="https://docs.python.org/2/library/ctypes.html" rel="nofollow"><code>ctypes</code></a> library. No downloads required.</p>
<pre><code>import ctypes
SetCursorPos = ctypes.windll.user32.SetCursorPos
mouse_ev... | 3 | 2014-11-01T22:37:42Z | [
"python",
"mouse"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 27,046,948 | <p>Try with the <a href="https://pypi.python.org/pypi/PyAutoGUI" rel="nofollow">PyAutoGUI</a> module. It's multiplatform. </p>
<pre><code>pip install pyautogui
</code></pre>
<p>And so:</p>
<pre><code>import pyautogui
pyautogui.click(100, 100)
</code></pre>
<p>It also has other features:</p>
<pre><code>import pyaut... | 30 | 2014-11-20T18:32:50Z | [
"python",
"mouse"
] |
Controlling mouse with Python | 1,181,464 | <p>How does one control the mouse cursor in Python, i.e. move it to certain position and click, under Windows?</p>
| 101 | 2009-07-25T07:15:30Z | 38,329,875 | <p>Pyautogui does a great job in controlling mouse with python. </p>
<p><a href="http://pyautogui.readthedocs.io/en/latest/mouse.html" rel="nofollow">http://pyautogui.readthedocs.io/en/latest/mouse.html</a> </p>
| 1 | 2016-07-12T13:09:43Z | [
"python",
"mouse"
] |
Python base 36 encoding | 1,181,919 | <p>How can I encode an integer with base 36 in Python and then decode it again?</p>
| 22 | 2009-07-25T11:32:32Z | 1,181,922 | <p>Have you tried Wikipedia's sample code?</p>
<pre><code>def base36encode(number, alphabet='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
"""Converts an integer to a base36 string."""
if not isinstance(number, (int, long)):
raise TypeError('number must be an integer')
base36 = ''
sign = ''
if ... | 23 | 2009-07-25T11:35:25Z | [
"python"
] |
Python base 36 encoding | 1,181,919 | <p>How can I encode an integer with base 36 in Python and then decode it again?</p>
| 22 | 2009-07-25T11:32:32Z | 1,181,924 | <p>I wish I had read this before. Here is the answer:</p>
<pre><code>def base36encode(number):
if not isinstance(number, (int, long)):
raise TypeError('number must be an integer')
if number < 0:
raise ValueError('number must be positive')
alphabet, base36 = ['0123456789ABCDEFGHIJKLMNOPQ... | 27 | 2009-07-25T11:36:08Z | [
"python"
] |
Python base 36 encoding | 1,181,919 | <p>How can I encode an integer with base 36 in Python and then decode it again?</p>
| 22 | 2009-07-25T11:32:32Z | 11,406,745 | <p>terrible answer, but was just playing around with this an thought i'd share.</p>
<pre><code>import string, math
int2base = lambda a, b: ''.join(
[(string.digits + string.lowercase + string.uppercase)[(a/b**i)%b]
for i in xrange(int(math.log(a, b)), -1, -1)]
)
num = 1412823931503067241
test = int2base... | 8 | 2012-07-10T04:43:11Z | [
"python"
] |
Python base 36 encoding | 1,181,919 | <p>How can I encode an integer with base 36 in Python and then decode it again?</p>
| 22 | 2009-07-25T11:32:32Z | 31,746,873 | <p>This works if you only care about positive integers.</p>
<pre><code>def int_to_base36(num):
"""Converts a positive integer into a base36 string."""
assert num >= 0
digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
res = ''
while not res or num > 0:
num, i = divmod(num, 36)
r... | 1 | 2015-07-31T13:02:15Z | [
"python"
] |
Python base 36 encoding | 1,181,919 | <p>How can I encode an integer with base 36 in Python and then decode it again?</p>
| 22 | 2009-07-25T11:32:32Z | 33,270,825 | <pre><code>from numpy import base_repr
num = base_repr(num, 36)
num = int(num, 36)
</code></pre>
<p>Here is information about <a href="http://www.numpy.org" rel="nofollow">numpy</a>.</p>
| 3 | 2015-10-21T23:15:30Z | [
"python"
] |
Python base 36 encoding | 1,181,919 | <p>How can I encode an integer with base 36 in Python and then decode it again?</p>
| 22 | 2009-07-25T11:32:32Z | 38,388,352 | <p>You could use <a href="https://github.com/tonyseek/python-base36" rel="nofollow">https://github.com/tonyseek/python-base36</a>.</p>
<pre><code>$ pip install base36
</code></pre>
<p>and then</p>
<pre><code>>>> import base36
>>> assert base36.dumps(19930503) == 'bv6h3'
>>> assert base36.l... | 0 | 2016-07-15T05:21:03Z | [
"python"
] |
cx_Oracle MemoryError when reading lob | 1,182,146 | <p>When trying to read data from a lob field using cx_Oralce Iâm receiving âexceptions.MemoryErrorâ. This code has been working, this one lob field seems to be too big.</p>
<pre><code>Example:
xml_cursor = ora_connection.cursor()
xml_cursor.arraysize = 2000
try:
xml_cursor.execute(âselect xml_data from xm... | 4 | 2009-07-25T14:06:27Z | 1,182,444 | <p>Yep, if Python is giving MemoryError it means that just that one field of that just one row takes more memory than you have (quite possible with a LOB of course). You'll have to slice it up and get it in chunks (with <code>select dbms_lob.substr(xml_data, ...</code> repeatedly) and feed it to an incremental XML pars... | 5 | 2009-07-25T16:30:27Z | [
"python",
"cx-oracle"
] |
Python: Multicore processing? | 1,182,315 | <p>I've been reading about Python's <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing module</a>. I still don't think I have a very good understanding of what it can do.</p>
<p>Let's say I have a quadcore processor and I have a list with 1,000,000 integers and I want the sum of all the int... | 20 | 2009-07-25T15:31:35Z | 1,182,343 | <p>Welcome the world of concurrent programming.</p>
<p>What Python can (and can't) do depends on two things.</p>
<ol>
<li><p>What the OS can (and can't) do. Most OS's allocate processes to cores. To use 4 cores, you need to break your problem into four processes. This is easier than it sounds. Sometimes.</p></li>... | 17 | 2009-07-25T15:45:49Z | [
"python",
"multicore",
"multiprocessing"
] |
Python: Multicore processing? | 1,182,315 | <p>I've been reading about Python's <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing module</a>. I still don't think I have a very good understanding of what it can do.</p>
<p>Let's say I have a quadcore processor and I have a list with 1,000,000 integers and I want the sum of all the int... | 20 | 2009-07-25T15:31:35Z | 1,182,350 | <p>Yes, it's possible to do this summation over several processes, very much like doing it with multiple threads:</p>
<pre><code>from multiprocessing import Process, Queue
def do_sum(q,l):
q.put(sum(l))
def main():
my_list = range(1000000)
q = Queue()
p1 = Process(target=do_sum, args=(q,my_list[:50... | 25 | 2009-07-25T15:48:51Z | [
"python",
"multicore",
"multiprocessing"
] |
Python: Multicore processing? | 1,182,315 | <p>I've been reading about Python's <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing module</a>. I still don't think I have a very good understanding of what it can do.</p>
<p>Let's say I have a quadcore processor and I have a list with 1,000,000 integers and I want the sum of all the int... | 20 | 2009-07-25T15:31:35Z | 1,182,364 | <p>Sure, for example:</p>
<pre><code>from multiprocessing import Process, Queue
thelist = range(1000*1000)
def f(q, sublist):
q.put(sum(sublist))
def main():
start = 0
chunk = 500*1000
queue = Queue()
NP = 0
subprocesses = []
while start < len(thelist):
p = Process(target=f, arg... | 7 | 2009-07-25T15:55:45Z | [
"python",
"multicore",
"multiprocessing"
] |
How can I launch a background process in Pylons? | 1,182,587 | <p>I am trying to write an application that will allow a user to launch a fairly long-running process (5-30 seconds). It should then allow the user to check the output of the process as it is generated. The output will only be needed for the user's current session so nothing needs to be stored long-term. I have two que... | 3 | 2009-07-25T17:36:18Z | 1,182,609 | <p>I think this has little to do with pylons. I would do it (in whatever framework) in these steps:</p>
<ul>
<li>generate some ID for the new job, and add a record in the database.</li>
<li>create a new process, e.g. through the subprocess module, and pass the ID on the command line (*).</li>
<li>have the process writ... | 1 | 2009-07-25T17:46:42Z | [
"python",
"background",
"pylons"
] |
How can I launch a background process in Pylons? | 1,182,587 | <p>I am trying to write an application that will allow a user to launch a fairly long-running process (5-30 seconds). It should then allow the user to check the output of the process as it is generated. The output will only be needed for the user's current session so nothing needs to be stored long-term. I have two que... | 3 | 2009-07-25T17:36:18Z | 1,189,797 | <p>I've handled this problem in the past (long-running process invoked over HTTP) by having my invoked 2nd process daemonize. Your Pylons controller makes a system call to your 2nd process (passing whatever data is needed) and the 2nd process immediately becomes a daemon. This ends the system call and your controller... | 6 | 2009-07-27T18:25:18Z | [
"python",
"background",
"pylons"
] |
Python dictionary/list help | 1,183,031 | <p>This is a python application that's supposed to get all the followers from one table and get their latest updates from another table. - All happening in the dashboard. </p>
<p>dashboard.html:
<a href="http://bizteen.pastebin.com/m65c4ae2d" rel="nofollow">http://bizteen.pastebin.com/m65c4ae2d</a></p>
<p>the dashbo... | -1 | 2009-07-25T20:53:48Z | 1,183,061 | <p>There's far too much code there to try and work out what's going on, and your explanation is not particularly clear.</p>
<p>However, one obvious problem is that you've got a lot of blank <code>except</code> clauses, which is almost always a bad idea as it masks any problems that might be happening outside of what y... | 1 | 2009-07-25T21:06:15Z | [
"python",
"django",
"list"
] |
How to get the distinct value of one of my models in Google App Engine | 1,183,102 | <p>I have a model, below, and I would like to get all the distinct <code>area</code> values. The SQL equivalent is <code>select distinct area from tutorials</code> </p>
<pre><code>class Tutorials(db.Model):
path = db.StringProperty()
area = db.StringProperty()
sub_area = db.StringProperty()
title = d... | 5 | 2009-07-25T21:22:49Z | 1,183,140 | <p><a href="http://stackoverflow.com/questions/239258/python-distinct-on-gquery-result-set-gql-gae">This has been asked before</a>, and the conclusion was that using sets is fine.</p>
| 0 | 2009-07-25T21:41:14Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
How to get the distinct value of one of my models in Google App Engine | 1,183,102 | <p>I have a model, below, and I would like to get all the distinct <code>area</code> values. The SQL equivalent is <code>select distinct area from tutorials</code> </p>
<pre><code>class Tutorials(db.Model):
path = db.StringProperty()
area = db.StringProperty()
sub_area = db.StringProperty()
title = d... | 5 | 2009-07-25T21:22:49Z | 1,183,146 | <p>Datastore cannot do this for you in a single query. A datastore request always returns a consecutive block of results from an index, and an index always consists of all the entities of a given type, sorted according to whatever orders are specified. There's no way for the query to skip items just because one field h... | 7 | 2009-07-25T21:42:23Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
How to get the distinct value of one of my models in Google App Engine | 1,183,102 | <p>I have a model, below, and I would like to get all the distinct <code>area</code> values. The SQL equivalent is <code>select distinct area from tutorials</code> </p>
<pre><code>class Tutorials(db.Model):
path = db.StringProperty()
area = db.StringProperty()
sub_area = db.StringProperty()
title = d... | 5 | 2009-07-25T21:22:49Z | 16,929,212 | <p>The DISTINCT keyword has been introduced in release 1.7.4.</p>
| 1 | 2013-06-04T23:38:41Z | [
"python",
"google-app-engine",
"gae-datastore"
] |
To SHA512-hash a password in MySQL database by Python | 1,183,161 | <p>This question is based <a href="http://stackoverflow.com/questions/1182798/to-improve-a-relation-figure-for-a-database/1182807#1182807">on the answer</a>.</p>
<p>I would like to know how you can hash your password by SHA1 and then remove the clear-text password in a MySQL database by Python.</p>
<p><strong>How can... | 3 | 2009-07-25T21:49:58Z | 1,183,173 | <p><a href="http://docs.python.org/library/sha.html" rel="nofollow">http://docs.python.org/library/sha.html</a></p>
<p>The python documentation explains this a lot better than I can.</p>
| 4 | 2009-07-25T21:56:34Z | [
"python",
"mysql",
"database",
"hash"
] |
To SHA512-hash a password in MySQL database by Python | 1,183,161 | <p>This question is based <a href="http://stackoverflow.com/questions/1182798/to-improve-a-relation-figure-for-a-database/1182807#1182807">on the answer</a>.</p>
<p>I would like to know how you can hash your password by SHA1 and then remove the clear-text password in a MySQL database by Python.</p>
<p><strong>How can... | 3 | 2009-07-25T21:49:58Z | 1,183,213 | <p>As the documentation says you should use <a href="http://docs.python.org/library/hashlib.html">hashlib</a> library not the sha since python 2.5.</p>
<p>It is pretty easy to do make a hash.</p>
<pre><code>hexhash = hashlib.sha512("some text").hexdigest()
</code></pre>
<p>This hex number will be easy to store in a ... | 12 | 2009-07-25T22:15:17Z | [
"python",
"mysql",
"database",
"hash"
] |
To SHA512-hash a password in MySQL database by Python | 1,183,161 | <p>This question is based <a href="http://stackoverflow.com/questions/1182798/to-improve-a-relation-figure-for-a-database/1182807#1182807">on the answer</a>.</p>
<p>I would like to know how you can hash your password by SHA1 and then remove the clear-text password in a MySQL database by Python.</p>
<p><strong>How can... | 3 | 2009-07-25T21:49:58Z | 1,183,227 | <p>You don't remove the clear-text password when you hash the password. What you do is accept an input from the user, hash the input, and compare the hash of the input to the hash stored in the database. You should never store or send the plain-text password that the user has.</p>
<p>That said, you can use the sha lib... | 1 | 2009-07-25T22:23:40Z | [
"python",
"mysql",
"database",
"hash"
] |
To SHA512-hash a password in MySQL database by Python | 1,183,161 | <p>This question is based <a href="http://stackoverflow.com/questions/1182798/to-improve-a-relation-figure-for-a-database/1182807#1182807">on the answer</a>.</p>
<p>I would like to know how you can hash your password by SHA1 and then remove the clear-text password in a MySQL database by Python.</p>
<p><strong>How can... | 3 | 2009-07-25T21:49:58Z | 1,183,439 | <p>If you're storing passwords in a database, a recommended article to read is Jeff's <a href="http://www.codinghorror.com/blog/archives/000953.html">You're Probably Storing Passwords Incorrectly</a>. This article describes the use of <em>salt</em> and some of the things about storing passwords that are deceptively eas... | 7 | 2009-07-26T00:37:23Z | [
"python",
"mysql",
"database",
"hash"
] |
Is there something like Python's 'with' in C#? | 1,183,233 | <p>Python has a nice keyword since 2.6 called <strong>with</strong>. Is there something similar in C#?</p>
| 8 | 2009-07-25T22:27:18Z | 1,183,236 | <p>The equivalent is the <code>using</code> statement</p>
<p>An example would be </p>
<pre><code> using (var reader = new StreamReader(path))
{
DoSomethingWith(reader);
}
</code></pre>
<p>The restriction is that the type of the variable scoped by the using clause must implement <code>IDisposable</code> and ... | 21 | 2009-07-25T22:29:24Z | [
"c#",
"python",
"exception"
] |
Is there something like Python's 'with' in C#? | 1,183,233 | <p>Python has a nice keyword since 2.6 called <strong>with</strong>. Is there something similar in C#?</p>
| 8 | 2009-07-25T22:27:18Z | 1,184,079 | <p>C# has the <code>using</code> statement, as mentioned in another answer and documented here:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx" rel="nofollow">using Statement</a></li>
</ul>
<p>However, it's <strong>not equivalent</strong> to Python's <code>with</code> statement, in... | 4 | 2009-07-26T09:00:22Z | [
"c#",
"python",
"exception"
] |
Python: Zope's BTree OOSet, IISet, etc... Effective for this requirement? | 1,183,428 | <p>I asked another question:
<a href="http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python" rel="nofollow" title="StackOverflow Python Sorting question">http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python</a>
where I was trying to determine the best approach for... | 0 | 2009-07-26T00:30:01Z | 1,183,587 | <p>I don't think BTrees or other traditional sorted data structures (red-black trees, etc) will help you, because they keep order by key, not by corresponding value -- in other words, the field they guarantee as unique is the same one they order by. Your requirements are different, because you want uniqueness along one... | 1 | 2009-07-26T02:26:44Z | [
"python",
"zope"
] |
Python: Zope's BTree OOSet, IISet, etc... Effective for this requirement? | 1,183,428 | <p>I asked another question:
<a href="http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python" rel="nofollow" title="StackOverflow Python Sorting question">http://stackoverflow.com/questions/1180240/best-way-to-sort-1m-records-in-python</a>
where I was trying to determine the best approach for... | 0 | 2009-07-26T00:30:01Z | 1,252,510 | <p>It is perfectly possible to solve your problem. For this you should just note that the container types in Python <strong>always</strong> compare objects by calling their methods. Therefore you should do something like:</p>
<pre><code>class Record:
'Combination of unique part and sort part.'
def __init__(sel... | 1 | 2009-08-09T22:40:32Z | [
"python",
"zope"
] |
Unbuffered read from process using subprocess in Python | 1,183,643 | <p>I am trying to read from a process that produces long and time-consuming output. However, I want to catch it's output <em>as and when</em> it is produced. But using something like the following seems to be buffering the command's output, so I end up getting the output lines all at once:</p>
<pre><code>p = subproces... | 20 | 2009-07-26T03:21:35Z | 1,183,654 | <p>The file iterator is doing some internal buffering <a href="http://docs.python.org/library/stdtypes.html#file.next">on its own</a>. Try this:</p>
<pre><code>line = p.stdout.readline()
while line:
print line
line = p.stdout.readline()
</code></pre>
| 27 | 2009-07-26T03:30:39Z | [
"python",
"subprocess"
] |
Unbuffered read from process using subprocess in Python | 1,183,643 | <p>I am trying to read from a process that produces long and time-consuming output. However, I want to catch it's output <em>as and when</em> it is produced. But using something like the following seems to be buffering the command's output, so I end up getting the output lines all at once:</p>
<pre><code>p = subproces... | 20 | 2009-07-26T03:21:35Z | 1,183,784 | <p>Usually, every program will do more buffering on its input and/or output channels than you appear to desire... unless it's fooled into believing said channel's actually a terminal!</p>
<p>For that "fooling in a good cause" purpose, use <a href="http://pexpect.sourceforge.net/pexpect.html">pexpect</a> -- it works ju... | 6 | 2009-07-26T05:08:32Z | [
"python",
"subprocess"
] |
Unbuffered read from process using subprocess in Python | 1,183,643 | <p>I am trying to read from a process that produces long and time-consuming output. However, I want to catch it's output <em>as and when</em> it is produced. But using something like the following seems to be buffering the command's output, so I end up getting the output lines all at once:</p>
<pre><code>p = subproces... | 20 | 2009-07-26T03:21:35Z | 9,069,527 | <p>This was actually a bug that's fixed in Python 2.6: <a href="http://bugs.python.org/issue3907" rel="nofollow">http://bugs.python.org/issue3907</a></p>
| 3 | 2012-01-30T19:26:19Z | [
"python",
"subprocess"
] |
Python Properties & Swig | 1,183,716 | <p>I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following:</p>
<pre><code>class Player {
public:
void entity(Entity* entity);
Entity* entity() const;
};
</code></pre... | 14 | 2009-07-26T04:17:48Z | 1,186,340 | <p>Ooh, this is tricky (and fun). SWIG <em>doesn't</em> recognize this as an opportunity to generate @property: I imagine it'd be all too easy to slip up and recognize lots of false positives if it weren't done really carefully. However, since SWIG won't do it in generating C++, it's still entirely possible to do this ... | 2 | 2009-07-27T03:53:22Z | [
"c++",
"python",
"properties",
"swig"
] |
Python Properties & Swig | 1,183,716 | <p>I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following:</p>
<pre><code>class Player {
public:
void entity(Entity* entity);
Entity* entity() const;
};
</code></pre... | 14 | 2009-07-26T04:17:48Z | 2,725,454 | <p>I had the same problem and the advice to use %pythoncode worked for me. Here is what I did:</p>
<pre><code>class Foo {
// ...
std::string get_name();
bool set_name(const std::string & name);
};
</code></pre>
<p>In the wrapper:</p>
<pre><code>%include "foo.h"
%pythoncode %{
def RaiseExceptionOnFailure(m... | 1 | 2010-04-27T21:57:11Z | [
"c++",
"python",
"properties",
"swig"
] |
Python Properties & Swig | 1,183,716 | <p>I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following:</p>
<pre><code>class Player {
public:
void entity(Entity* entity);
Entity* entity() const;
};
</code></pre... | 14 | 2009-07-26T04:17:48Z | 3,530,173 | <p>The problem with Hao's ProperyVoodoo metaclass is that when there are multiple properties in the properties list, all the properties behave the same as the last one in the list. For example, if I had a list or property names ["x", "y", "z"], then the properties generated for all three would use the same accessors as... | 3 | 2010-08-20T10:51:34Z | [
"c++",
"python",
"properties",
"swig"
] |
Python Properties & Swig | 1,183,716 | <p>I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following:</p>
<pre><code>class Player {
public:
void entity(Entity* entity);
Entity* entity() const;
};
</code></pre... | 14 | 2009-07-26T04:17:48Z | 4,750,081 | <p>There is an easy way to make python properties from methods with swig.<br>
Suppose C++ code Example.h:</p>
<p><strong>C++ header</strong></p>
<pre><code>class Example{
public:
void SetX(int x);
int GetX() const;
};
</code></pre>
<p>Lets convert this setter and getter to python propery 'x'. Th... | 27 | 2011-01-20T16:55:31Z | [
"c++",
"python",
"properties",
"swig"
] |
Python Properties & Swig | 1,183,716 | <p>I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following:</p>
<pre><code>class Player {
public:
void entity(Entity* entity);
Entity* entity() const;
};
</code></pre... | 14 | 2009-07-26T04:17:48Z | 11,250,032 | <p>From <a href="http://www.swig.org/Doc2.0/SWIGDocumentation.html#SWIG_adding_member_functions" rel="nofollow">http://www.swig.org/Doc2.0/SWIGDocumentation.html#SWIG_adding_member_functions</a>: </p>
<blockquote>
<p>A little known feature of the %extend directive is that it can also be
used to add synthesized att... | 1 | 2012-06-28T17:38:11Z | [
"c++",
"python",
"properties",
"swig"
] |
Python Properties & Swig | 1,183,716 | <p>I am attempting to create python bindings for some C++ code using swig. I seem have run into a problem trying to create python properties from some accessor functions I have for methods like the following:</p>
<pre><code>class Player {
public:
void entity(Entity* entity);
Entity* entity() const;
};
</code></pre... | 14 | 2009-07-26T04:17:48Z | 11,386,066 | <h1>Use Attributes.i</h1>
<p>In the SWIG Lib folder is a file called "attributes.i" which is not discussed in the documentation but that contains inline documentation.</p>
<p>All you have to do is add the following line to your interface file. </p>
<pre><code>%include <attributes.i>
</code></pre>
<p>You then ... | 13 | 2012-07-08T19:40:20Z | [
"c++",
"python",
"properties",
"swig"
] |
How can I use Facebook Connect with Google App Engine without using Django? | 1,183,863 | <p>I'm developing on the Google App Engine and I would like to integrate Facebook Connect into my site as a means for registering and authenticating. In the past, I relied on Google's Accounts API for user registration. I'm trying to use Google's webapp framework instead of Django but it seems that all the resources re... | 10 | 2009-07-26T06:06:54Z | 1,214,441 | <p>This tutorial might be useful:</p>
<p><a href="http://dollarmani-facebook.blogspot.com/2008/09/facebook-applications.html" rel="nofollow">http://dollarmani-facebook.blogspot.com/2008/09/facebook-applications.html</a></p>
| 1 | 2009-07-31T19:31:45Z | [
"python",
"google-app-engine",
"authentication",
"facebook"
] |
How can I use Facebook Connect with Google App Engine without using Django? | 1,183,863 | <p>I'm developing on the Google App Engine and I would like to integrate Facebook Connect into my site as a means for registering and authenticating. In the past, I relied on Google's Accounts API for user registration. I'm trying to use Google's webapp framework instead of Django but it seems that all the resources re... | 10 | 2009-07-26T06:06:54Z | 1,726,735 | <p>It's not Facebook Connect, really, but at least it's webapp FBML handling:
<a href="http://github.com/WorldMaker/pyfacebook/blob/35b6e4dbb83ca14fbb23046bd675fa4d80d568c9/facebook/webappfb.py">http://github.com/WorldMaker/pyfacebook/.../facebook/webappfb.py</a></p>
<p><a href="http://forum.developers.facebook.com/vi... | 10 | 2009-11-13T02:21:00Z | [
"python",
"google-app-engine",
"authentication",
"facebook"
] |
How can I use Facebook Connect with Google App Engine without using Django? | 1,183,863 | <p>I'm developing on the Google App Engine and I would like to integrate Facebook Connect into my site as a means for registering and authenticating. In the past, I relied on Google's Accounts API for user registration. I'm trying to use Google's webapp framework instead of Django but it seems that all the resources re... | 10 | 2009-07-26T06:06:54Z | 1,726,792 | <p>Most of Facebook Connect (as it was formerly called, now it's "Facebook for Websites") is Javascript. The only serverside thing you really need (assuming you want to integrate it into your own usersystem) is validation of the user's Facebook login. Either minifb or pyfacebook should accomplish this task.</p>
| 4 | 2009-11-13T02:38:34Z | [
"python",
"google-app-engine",
"authentication",
"facebook"
] |
Permalinks with Russian/Cyrillic news articles | 1,183,956 | <p>I basically am working with an oldschool php cms based site in Russian, one of the many new functionalities requested is permalinks.</p>
<p>As of now, currently the website just uses the standard non-mvc 'article.php?id=50'. I was browsing the <a href="http://ru.wikipedia.org/wiki/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%... | 1 | 2009-07-26T07:16:13Z | 1,183,965 | <p>The current convention is to encode URLs in UTF-8, and then URL-escape (i.e. %-escape) them:</p>
<pre><code>py> urllib.quote(u"articles/2009/ÐаглавнаÑ_ÑÑÑаниÑа".encode("utf-8"))
'articles/2009/%D0%97%D0%B0%D0%B3%D0%BB%D0%B0%D0%B2%D0%BD%D0%B0%D1%8F_%D1%81%D1%82%D1%80%D0%B0%D0%BD%D0%B8%D1%86%D0%B0... | 2 | 2009-07-26T07:22:45Z | [
"python",
"mysql",
"model-view-controller"
] |
why __builtins__ is both module and dict | 1,184,016 | <p>I am using the built-in module to insert a few instances, so they can be accessed globally for debugging purposes. The problem with the <code>__builtins__</code> module is that it is a module in a main script and is a dict in modules, but as my script depending on cases can be a main script or a module, I have to do... | 8 | 2009-07-26T08:05:17Z | 1,184,036 | <p>I think you want the <code>__builtin__</code> module (note the singular).</p>
<p>See the docs:</p>
<blockquote>
<p><a href="http://docs.python.org/library/__builtin__.html" rel="nofollow">27.3. <code>__builtin__</code> â Built-in objects</a></p>
<p><strong>CPython implementation detail:</strong> Most modu... | 10 | 2009-07-26T08:25:03Z | [
"python",
"python-module",
"built-in"
] |
Getting the name & extension of an uploaded file using python (google app engine) | 1,184,110 | <p>I am using a form to upload files to the google app engine and store them in the datastore. l would also like to store the original file name and extension for presentation purposes.</p>
<p>Is there a way of retrieving this data from the post sever side or can it only be gathered client side and sent as separate fi... | 4 | 2009-07-26T09:15:19Z | 1,184,127 | <p>Does the snippet from <a href="http://osdir.com/ml/GoogleAppEngine/2009-06/msg00287.html" rel="nofollow">this email</a> work?</p>
<pre><code> self.request.params[<form element name with file>].filename
</code></pre>
| 3 | 2009-07-26T09:25:59Z | [
"python",
"google-app-engine",
"upload",
"filenames"
] |
Getting the name & extension of an uploaded file using python (google app engine) | 1,184,110 | <p>I am using a form to upload files to the google app engine and store them in the datastore. l would also like to store the original file name and extension for presentation purposes.</p>
<p>Is there a way of retrieving this data from the post sever side or can it only be gathered client side and sent as separate fi... | 4 | 2009-07-26T09:15:19Z | 4,787,610 | <p>Try this...</p>
<p>If your form looks like this:</p>
<pre><code>self.response.out.write('''<form action="/upload" enctype="multipart/form-data" method="post"><input type="file" name="file"/><input type="submit" /></form>''')
</code></pre>
<p>Then in your post handler, try this:</p>
<pre><... | 0 | 2011-01-24T21:53:05Z | [
"python",
"google-app-engine",
"upload",
"filenames"
] |
Storing files for testbin/pastebin in Python | 1,184,116 | <p>I'm basically trying to setup my own private pastebin where I can save html files on my private server to test and fool around - have some sort of textarea for the initial input, save the file, and after saving I'd like to be able to view all the files I saved.</p>
<p>I'm trying to write this in python, just wonder... | 0 | 2009-07-26T09:23:29Z | 1,184,162 | <p>I wrote something similar a while back in Django to test jQuery snippets. See:</p>
<p><a href="http://jquery.nodnod.net/" rel="nofollow">http://jquery.nodnod.net/</a></p>
<p>I have the code available on GitHub at <a href="http://github.com/dz/jquerytester/tree/master" rel="nofollow">http://github.com/dz/jquerytes... | 1 | 2009-07-26T09:44:57Z | [
"python",
"web-applications"
] |
Storing files for testbin/pastebin in Python | 1,184,116 | <p>I'm basically trying to setup my own private pastebin where I can save html files on my private server to test and fool around - have some sort of textarea for the initial input, save the file, and after saving I'd like to be able to view all the files I saved.</p>
<p>I'm trying to write this in python, just wonder... | 0 | 2009-07-26T09:23:29Z | 1,184,165 | <p>Have you considered trying <a href="http://dev.pocoo.org/projects/lodgeit/" rel="nofollow">lodgeit</a>. Its a free pastbin which you can host yourself. I do not know how hard it is to set up.</p>
<p>Looking at their code they have gone with a database for storage (sqllite will do). They have structured there past... | 1 | 2009-07-26T09:47:11Z | [
"python",
"web-applications"
] |
Storing files for testbin/pastebin in Python | 1,184,116 | <p>I'm basically trying to setup my own private pastebin where I can save html files on my private server to test and fool around - have some sort of textarea for the initial input, save the file, and after saving I'd like to be able to view all the files I saved.</p>
<p>I'm trying to write this in python, just wonder... | 0 | 2009-07-26T09:23:29Z | 1,184,170 | <p>Plain files are definitely more effective. Save your database for more complex queries.</p>
<p>If you need some formatting to be done on files, such as highlighting the code properly, it is better to do it <em>before</em> you save the file with that code. That way you don't need to apply formatting every time the f... | 0 | 2009-07-26T09:51:26Z | [
"python",
"web-applications"
] |
python string search replace | 1,184,119 | <pre><code>SSViewer::set_theme('bullsorbit');
</code></pre>
<p>this my string. I want search in string <code>"SSViewer::set_theme('bullsorbit'); "</code> and replace <code>'bullsorbit'</code> with another string. <code>'bullsorbit'</code> string is dynamically changing.</p>
| 2 | 2009-07-26T09:23:55Z | 1,184,148 | <p>Not in a situation to be able to test this so you may need to fiddle with the Regular Expression (they may be errors in it.)</p>
<pre><code>import re
re.sub("SSViewer::set_theme\('[a-z]+'\)", "SSViewer::set_theme('whatever')", my_string)
</code></pre>
<p>Is this what you want?</p>
<p>Just tested it, this is some ... | 3 | 2009-07-26T09:34:02Z | [
"python",
"string",
"search",
"replace"
] |
python string search replace | 1,184,119 | <pre><code>SSViewer::set_theme('bullsorbit');
</code></pre>
<p>this my string. I want search in string <code>"SSViewer::set_theme('bullsorbit'); "</code> and replace <code>'bullsorbit'</code> with another string. <code>'bullsorbit'</code> string is dynamically changing.</p>
| 2 | 2009-07-26T09:23:55Z | 1,184,166 | <pre><code>>> my_string = "SSViewer::set_theme('bullsorbit');"
>>> import re
>>> change = re.findall(r"SSViewer::set_theme\('(\w*)'\);",my_string)
>>> my_string.replace(change[0],"blah")
"SSViewer::set_theme('blah');"
</code></pre>
<p>its not elegant but it works. the findall will retu... | 1 | 2009-07-26T09:47:38Z | [
"python",
"string",
"search",
"replace"
] |
python string search replace | 1,184,119 | <pre><code>SSViewer::set_theme('bullsorbit');
</code></pre>
<p>this my string. I want search in string <code>"SSViewer::set_theme('bullsorbit'); "</code> and replace <code>'bullsorbit'</code> with another string. <code>'bullsorbit'</code> string is dynamically changing.</p>
| 2 | 2009-07-26T09:23:55Z | 1,184,239 | <pre><code>st = "SSViewer::set_theme('"
for line in open("file.txt"):
line=line.strip()
if st in line:
a = line[ :line.index(st)+len(st)]
b = line [line.index(st)+len(st): ]
i = b.index("')")
b = b[i:]
print a + "newword" + b
</code></pre>
| 0 | 2009-07-26T10:36:06Z | [
"python",
"string",
"search",
"replace"
] |
python string search replace | 1,184,119 | <pre><code>SSViewer::set_theme('bullsorbit');
</code></pre>
<p>this my string. I want search in string <code>"SSViewer::set_theme('bullsorbit'); "</code> and replace <code>'bullsorbit'</code> with another string. <code>'bullsorbit'</code> string is dynamically changing.</p>
| 2 | 2009-07-26T09:23:55Z | 1,184,254 | <p>while your explanation is not entirely clear, I think you might make some use of the following:</p>
<pre><code>open(fname).read().replace('bullsorbit', 'new_string')
</code></pre>
| 0 | 2009-07-26T10:43:26Z | [
"python",
"string",
"search",
"replace"
] |
Python: extending int and MRO for __init__ | 1,184,337 | <p>In Python, I'm trying to extend the builtin 'int' type. In doing so I want to pass in some keywoard arguments to the constructor, so I do this:</p>
<pre><code>class C(int):
def __init__(self, val, **kwargs):
super(C, self).__init__(val)
# Do something with kwargs here...
</code></pre>
<p>How... | 10 | 2009-07-26T11:27:59Z | 1,184,369 | <p>You should be overriding
<code>"__new__"</code>, not <code>"__init__"</code> as ints are immutable.</p>
| 3 | 2009-07-26T11:44:27Z | [
"python",
"class-design",
"override"
] |
Python: extending int and MRO for __init__ | 1,184,337 | <p>In Python, I'm trying to extend the builtin 'int' type. In doing so I want to pass in some keywoard arguments to the constructor, so I do this:</p>
<pre><code>class C(int):
def __init__(self, val, **kwargs):
super(C, self).__init__(val)
# Do something with kwargs here...
</code></pre>
<p>How... | 10 | 2009-07-26T11:27:59Z | 1,184,377 | <p>The docs for the Python data model advise using <code>__new__</code>:</p>
<p><a href="http://docs.python.org/reference/datamodel.html#object.%5F%5Fnew%5F%5F">object.<strong>new</strong>(cls[, ...])</a></p>
<blockquote>
<p><strong>new</strong>() is intended mainly to allow subclasses of immutable types (like int,... | 7 | 2009-07-26T11:49:20Z | [
"python",
"class-design",
"override"
] |
Python: extending int and MRO for __init__ | 1,184,337 | <p>In Python, I'm trying to extend the builtin 'int' type. In doing so I want to pass in some keywoard arguments to the constructor, so I do this:</p>
<pre><code>class C(int):
def __init__(self, val, **kwargs):
super(C, self).__init__(val)
# Do something with kwargs here...
</code></pre>
<p>How... | 10 | 2009-07-26T11:27:59Z | 1,184,416 | <p>What everyone else (so far) said. Int are immutable, so you have to use <strong>new</strong>.</p>
<p>Also see (the accepted answers to):</p>
<ul>
<li><a href="http://stackoverflow.com/questions/1135335/increment-int-object">http://stackoverflow.com/questions/1135335/increment-int-object</a></li>
<li><a href="http... | 3 | 2009-07-26T12:14:16Z | [
"python",
"class-design",
"override"
] |
Is there a library which handles the parsing of BIND zone files in Python? | 1,184,803 | <p>This is related to <a href="http://stackoverflow.com/questions/236859/any-python-libs-for-parsing-bind-config-files">a similar question</a> about BIND, but in this case I'm trying to see if there's any easy way to parse various zone files into a dictionary, list, or some other manageable data structure, with the fin... | 0 | 2009-07-26T15:09:54Z | 1,184,861 | <p>ISTM, <a href="http://pypi.python.org/pypi/easyzone/" rel="nofollow">easyzone</a> might meet your needs. It sits on top of dnspython, which would be an alternative API.</p>
| 1 | 2009-07-26T15:38:18Z | [
"python",
"database",
"parsing",
"bind",
"python-2.4"
] |
Downloading text files with Python and ftplib.FTP from z/os | 1,184,844 | <p>I'm trying to automate downloading of some text files from a z/os PDS, using Python and ftplib.</p>
<p>Since the host files are EBCDIC, I can't simply use FTP.retrbinary(). </p>
<p>FTP.retrlines(), when used with open(file,w).writelines as its callback, doesn't, of course, provide EOLs.</p>
<p>So, for starters, I... | 1 | 2009-07-26T15:31:40Z | 1,184,866 | <p>You should be able to download the file as a binary (using <code>retrbinary</code>) and use the <code>codecs</code> module to convert from EBCDIC to whatever output encoding you want. You should know the specific EBCDIC code page being used on the z/OS system (e.g. cp500). If the files are small, you could even do s... | 3 | 2009-07-26T15:39:56Z | [
"python",
"ftp",
"mainframe",
"zos"
] |
Downloading text files with Python and ftplib.FTP from z/os | 1,184,844 | <p>I'm trying to automate downloading of some text files from a z/os PDS, using Python and ftplib.</p>
<p>Since the host files are EBCDIC, I can't simply use FTP.retrbinary(). </p>
<p>FTP.retrlines(), when used with open(file,w).writelines as its callback, doesn't, of course, provide EOLs.</p>
<p>So, for starters, I... | 1 | 2009-07-26T15:31:40Z | 1,186,010 | <p>Your writelineswitheol method appends '\r\n' instead of '\n' and then writes the result to a file opened in text mode. The effect, no matter what platform you are running on, will be an unwanted '\r'. Just append '\n' and you will get the appropriate line ending.</p>
<p>Proper error handling should not be relegated... | 1 | 2009-07-27T00:54:17Z | [
"python",
"ftp",
"mainframe",
"zos"
] |
Downloading text files with Python and ftplib.FTP from z/os | 1,184,844 | <p>I'm trying to automate downloading of some text files from a z/os PDS, using Python and ftplib.</p>
<p>Since the host files are EBCDIC, I can't simply use FTP.retrbinary(). </p>
<p>FTP.retrlines(), when used with open(file,w).writelines as its callback, doesn't, of course, provide EOLs.</p>
<p>So, for starters, I... | 1 | 2009-07-26T15:31:40Z | 7,964,999 | <p>Just came across this question as I was trying to figure out how to recursively download datasets from z/OS. I've been using a simple python script for years now to download ebcdic files from the mainframe. It effectively just does this:</p>
<pre><code>def writeline(line):
file.write(line + "\n")
file = open(f... | 1 | 2011-11-01T10:13:45Z | [
"python",
"ftp",
"mainframe",
"zos"
] |
Error importing external library within Django template tag library | 1,185,084 | <p>So I'm attempting to write a Django reusable app that provides a method for displaying your Twitter feed on your page. I know well that it already exists 20 times. It's an academic exercise. :)</p>
<p>Directory structure is pretty simple:</p>
<pre><code>myproject
|__ __init__.py
|__ manage.py
|__ settings.py
|_... | 3 | 2009-07-26T17:36:06Z | 1,185,115 | <p>I solve this kind of problem (shipping libraries that are dependencies for my overall project) in the following way. First, I create an "ext" directory in the root of my project (in your case that would be <code>myproject/ext</code>). Then I place dependencies such as feedparser in that ext directory - <code>myproje... | 5 | 2009-07-26T17:52:37Z | [
"python",
"django",
"feedparser",
"templatetags"
] |
Error importing external library within Django template tag library | 1,185,084 | <p>So I'm attempting to write a Django reusable app that provides a method for displaying your Twitter feed on your page. I know well that it already exists 20 times. It's an academic exercise. :)</p>
<p>Directory structure is pretty simple:</p>
<pre><code>myproject
|__ __init__.py
|__ manage.py
|__ settings.py
|_... | 3 | 2009-07-26T17:36:06Z | 1,185,334 | <p>This looks like one of those annoying relative path issues - solved in Python 2.6 and higher (where you can do import ..feedparser etc) but often a bit tricky on older versions. One cheap and cheerful way to fix this could be just to move feedparser.py in to your templatetags directory, as a sibling to twitterfeed.p... | 2 | 2009-07-26T19:24:37Z | [
"python",
"django",
"feedparser",
"templatetags"
] |
Should I use thread local storage for variables that only exist in a {class,method}? | 1,185,117 | <p>I am implementing a relatively simple thread pool with Python's <code>Queue.Queue</code> class. I have one producer class that contains the <code>Queue</code> instance along with some convenience methods, along with a consumer class that subclasses <code>threading.Thread</code>. I instantiate that object for every... | 4 | 2009-07-26T17:53:08Z | 1,185,249 | <p>You are right; this is thread-safe. Local variables (the ones you call "function namespace") are always thread-safe, since only the thread executing the function can access them. Instance attributes are thread-safe as long as the instance is not shared across threads. As the consumer class inherits from Thread, its ... | 5 | 2009-07-26T18:47:44Z | [
"python",
"concurrency",
"namespaces",
"multithreading"
] |
Should I use thread local storage for variables that only exist in a {class,method}? | 1,185,117 | <p>I am implementing a relatively simple thread pool with Python's <code>Queue.Queue</code> class. I have one producer class that contains the <code>Queue</code> instance along with some convenience methods, along with a consumer class that subclasses <code>threading.Thread</code>. I instantiate that object for every... | 4 | 2009-07-26T17:53:08Z | 1,185,250 | <p>I think you are on the whole correct with your assumptions and in your case you are most probably correct.</p>
<p>However it slightly more difficult to tell if something is thread safe or not then you say.</p>
<p>Calls such as <code>self.conn = sqlite3.connect(db_filename)</code> may not be, as sqlite3 module coul... | 1 | 2009-07-26T18:48:11Z | [
"python",
"concurrency",
"namespaces",
"multithreading"
] |
Should I use thread local storage for variables that only exist in a {class,method}? | 1,185,117 | <p>I am implementing a relatively simple thread pool with Python's <code>Queue.Queue</code> class. I have one producer class that contains the <code>Queue</code> instance along with some convenience methods, along with a consumer class that subclasses <code>threading.Thread</code>. I instantiate that object for every... | 4 | 2009-07-26T17:53:08Z | 14,969,556 | <p>To make the data thread safe use copy.deepcopy() to create a new copy of the data before putting it on the queue. Then the producer can modify the data in the next loop without modifying the consumers copy before he gets to it.</p>
| 1 | 2013-02-19T23:27:37Z | [
"python",
"concurrency",
"namespaces",
"multithreading"
] |
Creating child frames of main frame in wxPython | 1,185,156 | <p>I am trying create a new frame in wxPython that is a child of the main frame so that when the main frame is closed, the child frame will also be closed.</p>
<p>Here is a simplified example of the problem that I am having:</p>
<pre><code>#! /usr/bin/env python
import wx
class App(wx.App):
def OnInit(self):
... | 12 | 2009-07-26T18:08:57Z | 1,185,226 | <pre><code>class AboutFrame(wx.Frame):
title = "About this program"
def __init__(self):
wx.Frame.__init__(self, wx.GetApp().TopWindow, title=self.title)
</code></pre>
| 10 | 2009-07-26T18:37:56Z | [
"python",
"wxpython"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 1,185,208 | <p>You can't. The expression <code>5 == 5</code> is evaluated and only then is the result passed to someFunc. The function just gets <code>True</code> (the <code>True</code> object, to be precise), no matter what the expression was.</p>
<p>Edit: Concerning your edit, <a href="http://stackoverflow.com/questions/1179096... | 1 | 2009-07-26T18:29:36Z | [
"python",
"parameters",
"sqlalchemy"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 1,185,210 | <p>You need to wrap the whole thing as a literal string. You're trying to print that out as a string I assume, correct?</p>
| 0 | 2009-07-26T18:30:31Z | [
"python",
"parameters",
"sqlalchemy"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 1,185,211 | <p>Short answer: You can't. The result of the expression evaluation is passed to the function rather than the expression itself.</p>
| 0 | 2009-07-26T18:31:11Z | [
"python",
"parameters",
"sqlalchemy"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 1,185,228 | <p>It appears you can return tuples from <strong>eq</strong>:</p>
<pre><code>class Foo:
def __init__(self, value):
self.value = value
def __eq__(self, other):
return (self.value, other.value)
f1 = Foo(5)
f2 = Foo(10)
print(f1 == f2)
</code></pre>
| 1 | 2009-07-26T18:38:21Z | [
"python",
"parameters",
"sqlalchemy"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 1,185,254 | <p>You can achieve your example if you make "op" a function:</p>
<pre>
>>> def magic(left, op, right):
... return op(left, right)
...
>>> magic(5, (lambda a, b: a == b), 5)
True
>>> magic(5, (lambda a, b: a == b), 4)
False
</pre>
<p>This is more Pythonic than passing a String. It's how... | 11 | 2009-07-26T18:50:41Z | [
"python",
"parameters",
"sqlalchemy"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 1,191,181 | <p>An even more pythonic variant of Nelson's solution is to use the operator functions from the <a href="http://docs.python.org/library/operator.html" rel="nofollow">operator</a> module in the standard library; there is no need to create your own lambdas.</p>
<pre><code>>>> from operator import eq
>>>... | 4 | 2009-07-27T23:24:34Z | [
"python",
"parameters",
"sqlalchemy"
] |
Passing expressions to functions in python? | 1,185,199 | <p>I'm not quite sure what i mean here, so please bear with me..</p>
<p>In sqlalchemy, it appears i'm supposed to pass an expression? to <a href="http://www.sqlalchemy.org/docs/05/ormtutorial.html#common-filter-operators" rel="nofollow">filter()</a> in certain cases. When i try to implement something like this myself,... | 5 | 2009-07-26T18:26:21Z | 30,208,467 | <p>You have to implement <code>__eq__()</code> . For example ::</p>
<pre><code>class A(object):
def __eq__(self, other):
return (self, '==', other)
</code></pre>
<p>Then, for the function, which you want to get the expression, like ::</p>
<pre><code>def my_func(expr):
# deal with the expression
p... | 0 | 2015-05-13T07:34:46Z | [
"python",
"parameters",
"sqlalchemy"
] |
Which python tools for building a database-backed webapp | 1,185,248 | <p>I am <a href="http://stackoverflow.com/questions/1168701/to-make-a-plan-for-my-first-mysql-project">completing my first database project</a> which aims to build a simple discussion site.</p>
<p>The <a href="http://superuser.com/questions/13238/is-python-only-for-building-backends-in-making-websites">answers which I... | -1 | 2009-07-26T18:47:09Z | 1,185,255 | <p>Many people would recommend <a href="http://www.sqlalchemy.org/" rel="nofollow">SQLAlchemy</a>.</p>
| 2 | 2009-07-26T18:50:59Z | [
"python",
"orm",
"cheetah"
] |
Which python tools for building a database-backed webapp | 1,185,248 | <p>I am <a href="http://stackoverflow.com/questions/1168701/to-make-a-plan-for-my-first-mysql-project">completing my first database project</a> which aims to build a simple discussion site.</p>
<p>The <a href="http://superuser.com/questions/13238/is-python-only-for-building-backends-in-making-websites">answers which I... | -1 | 2009-07-26T18:47:09Z | 1,185,265 | <p>ORM is not same as templating. Since you want to write your own sql queries and at the same time want to write clean python code, i would suggest you look at <a href="http://webpy.org/" rel="nofollow">web.py</a>. I have used web.py and i must say its really simple and to the point.It has its own templating engine, b... | 1 | 2009-07-26T18:53:33Z | [
"python",
"orm",
"cheetah"
] |
Which python tools for building a database-backed webapp | 1,185,248 | <p>I am <a href="http://stackoverflow.com/questions/1168701/to-make-a-plan-for-my-first-mysql-project">completing my first database project</a> which aims to build a simple discussion site.</p>
<p>The <a href="http://superuser.com/questions/13238/is-python-only-for-building-backends-in-making-websites">answers which I... | -1 | 2009-07-26T18:47:09Z | 1,185,267 | <p>Sorry, your question makes no sense.</p>
<ol>
<li><p>You say you can't use Django because you have to write your SQL queries yourself. Firstly, why do you have to? And secondly, Django certainly doesn't stop you.</p></li>
<li><p>Even though you say you want to write your SQL queries yourself, you then ask what ORM ... | 5 | 2009-07-26T18:53:54Z | [
"python",
"orm",
"cheetah"
] |
Which python tools for building a database-backed webapp | 1,185,248 | <p>I am <a href="http://stackoverflow.com/questions/1168701/to-make-a-plan-for-my-first-mysql-project">completing my first database project</a> which aims to build a simple discussion site.</p>
<p>The <a href="http://superuser.com/questions/13238/is-python-only-for-building-backends-in-making-websites">answers which I... | -1 | 2009-07-26T18:47:09Z | 1,185,270 | <p>Your question is very strange.</p>
<p>First, Django doesn't force you to use its SQL abstraction. Each part of Django can be use idenpendently of the others. You can use Django together with any other SQL library.</p>
<p>Second, if you need to build your own SQL queries, an ORM is the <i>opposite</i> of what you n... | 2 | 2009-07-26T18:55:15Z | [
"python",
"orm",
"cheetah"
] |
Which python tools for building a database-backed webapp | 1,185,248 | <p>I am <a href="http://stackoverflow.com/questions/1168701/to-make-a-plan-for-my-first-mysql-project">completing my first database project</a> which aims to build a simple discussion site.</p>
<p>The <a href="http://superuser.com/questions/13238/is-python-only-for-building-backends-in-making-websites">answers which I... | -1 | 2009-07-26T18:47:09Z | 1,185,286 | <p>There are many other options other than Django. However:</p>
<p><strong>You can make your own SQL queries in Django</strong>. <a href="http://docs.djangoproject.com/en/dev/ref/models/querysets/#extra-select-none-where-none-params-none-tables-none-order-by-none-select-params-none" rel="nofollow">Here is the docume... | 1 | 2009-07-26T19:03:02Z | [
"python",
"orm",
"cheetah"
] |
Algorithms to identify Markov generated content? | 1,185,369 | <p>Markov chains are a (almost standard) way to generate <a href="http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/">random gibberish</a> which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.</p>
<p>It would be awesome if t... | 11 | 2009-07-26T19:45:13Z | 1,185,394 | <p>If you had several large Markov-generated texts, you could possibly determine that they were so by comparing the word frequencies between each of the samples. Since Markov chains depend on constant word probabilities, the proportions of any given word should be roughly equal from sample to sample.</p>
| 2 | 2009-07-26T19:52:33Z | [
"python",
"algorithm",
"markov"
] |
Algorithms to identify Markov generated content? | 1,185,369 | <p>Markov chains are a (almost standard) way to generate <a href="http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/">random gibberish</a> which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.</p>
<p>It would be awesome if t... | 11 | 2009-07-26T19:45:13Z | 1,185,431 | <p>One simple approach would be to have a large group of humans read input text for you and see if the text makes sense. I'm only half-joking, this is a tricky problem. </p>
<p>I believe this to be a hard problem, because Markov-chain generated text is going to have a lot of the same properties of real human text in t... | 8 | 2009-07-26T20:11:29Z | [
"python",
"algorithm",
"markov"
] |
Algorithms to identify Markov generated content? | 1,185,369 | <p>Markov chains are a (almost standard) way to generate <a href="http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/">random gibberish</a> which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.</p>
<p>It would be awesome if t... | 11 | 2009-07-26T19:45:13Z | 1,186,053 | <p>Crowdsourcing. Use Mechanical Turk and get a number of humans to vote on this. There are even some libraries to help you pull this off. For example:</p>
<ul>
<li><a href="http://groups.csail.mit.edu/uid/turkit/" rel="nofollow">TurKit - Iterative Tasks on Mechanical Turk</a></li>
</ul>
<p>Here's a blog post from... | 2 | 2009-07-27T01:18:56Z | [
"python",
"algorithm",
"markov"
] |
Algorithms to identify Markov generated content? | 1,185,369 | <p>Markov chains are a (almost standard) way to generate <a href="http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/">random gibberish</a> which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.</p>
<p>It would be awesome if t... | 11 | 2009-07-26T19:45:13Z | 1,186,215 | <p>I suggest a generalization of Evan's answer: make a Markov model of your own and train it with a big chunk of the (very large) sample you're given, reserving the rest of the sample as "test data". Now, see how well the model you've trained does on the test data, e.g. with a chi square test that will suggest situatio... | 5 | 2009-07-27T02:46:20Z | [
"python",
"algorithm",
"markov"
] |
Algorithms to identify Markov generated content? | 1,185,369 | <p>Markov chains are a (almost standard) way to generate <a href="http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/">random gibberish</a> which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.</p>
<p>It would be awesome if t... | 11 | 2009-07-26T19:45:13Z | 1,187,247 | <p>You could use a "brute force" approach, whereby you compare the generated language to data collected on n-grams of higher order than the Markov model that generated it.</p>
<p>i.e. If the language was generated with a 2nd order Markov model, up to 3-grams are going to have the correct frequencies, but 4-grams proba... | 6 | 2009-07-27T09:20:32Z | [
"python",
"algorithm",
"markov"
] |
Algorithms to identify Markov generated content? | 1,185,369 | <p>Markov chains are a (almost standard) way to generate <a href="http://uswaretech.com/blog/2009/06/pseudo-random-text-markov-chains-python/">random gibberish</a> which looks intelligent to untrained eye. How would you go about identifying markov generated text from human written text.</p>
<p>It would be awesome if t... | 11 | 2009-07-26T19:45:13Z | 17,794,107 | <p>If you write a program which generates Markovian transition probabilities from any sequence of symbols, and then calculates the entropy rate of the markov matrix. (see <a href="http://en.wikipedia.org/wiki/Entropy_rate#Entropy_rates_for_Markov_chains" rel="nofollow">http://en.wikipedia.org/wiki/Entropy_rate#Entropy_... | 0 | 2013-07-22T17:50:49Z | [
"python",
"algorithm",
"markov"
] |
merge sort implementation to sort by string length - python | 1,185,388 | <p>I've implemented what I believe to be a merge sort algorithm in python. I've never programmed in Python before, so I used several resources with commands that seemed foreign to me, to gain a better understanding. </p>
<p>However, I've also never implemented merge sort in the first place, so I'm not sure if I've e... | 0 | 2009-07-26T19:50:35Z | 1,185,421 | <p>Don't name variables "list". That's the name of Python's array type, so using a variable by the same name is confusing.</p>
<p>When you return from a conditional, you don't need to sitck the rest of the function in an else block.</p>
<pre><code>def mergesort(list):
if len(list) < 2:
return list
... | 3 | 2009-07-26T20:04:39Z | [
"python",
"algorithm",
"mergesort"
] |
merge sort implementation to sort by string length - python | 1,185,388 | <p>I've implemented what I believe to be a merge sort algorithm in python. I've never programmed in Python before, so I used several resources with commands that seemed foreign to me, to gain a better understanding. </p>
<p>However, I've also never implemented merge sort in the first place, so I'm not sure if I've e... | 0 | 2009-07-26T19:50:35Z | 1,185,424 | <p>How about using the <code>sorted()</code> function? Like this:</p>
<pre><code>def len_cmp(x, y):
return len(x) - len(y)
my_strings = ["hello", "foo", "bar", "spam"]
print sorted(my_strings, len_cmp)
</code></pre>
| 2 | 2009-07-26T20:06:02Z | [
"python",
"algorithm",
"mergesort"
] |
How do I start a session in a Python web application? | 1,185,406 | <p>This question is based on <a href="http://stackoverflow.com/questions/1184888/to-understand-a-line-about-a-login-variable-in-a-session/1184931#1184931">this answer</a>.</p>
<p>I'm looking for a function similar to PHP's <code>session_start()</code> for Python. I want to access a dictionary like <code>$_SESSION</cod... | 4 | 2009-07-26T20:00:26Z | 1,185,418 | <p>Python is not a web language in itself like PHP, so it has not built in web features. There are many modules that add this functionality however, but then you'll have to be specific about which one you're using.</p>
<p>Here's how you could use it with <a href="http://www.djangoproject.com/" rel="nofollow">the Djang... | 3 | 2009-07-26T20:04:00Z | [
"python",
"session"
] |
How do I start a session in a Python web application? | 1,185,406 | <p>This question is based on <a href="http://stackoverflow.com/questions/1184888/to-understand-a-line-about-a-login-variable-in-a-session/1184931#1184931">this answer</a>.</p>
<p>I'm looking for a function similar to PHP's <code>session_start()</code> for Python. I want to access a dictionary like <code>$_SESSION</cod... | 4 | 2009-07-26T20:00:26Z | 1,185,437 | <p>As someone who comes from PHP and is working his way into Python I can tell you that <a href="http://www.djangoproject.com/">Django</a> is a good way to start dealing with Python on the web. This is especially true if you've been using <a href="http://www.phpwact.org/php/mvc%5Fframeworks">MVC frameworks in PHP</a>.... | 7 | 2009-07-26T20:13:47Z | [
"python",
"session"
] |
How do I start a session in a Python web application? | 1,185,406 | <p>This question is based on <a href="http://stackoverflow.com/questions/1184888/to-understand-a-line-about-a-login-variable-in-a-session/1184931#1184931">this answer</a>.</p>
<p>I'm looking for a function similar to PHP's <code>session_start()</code> for Python. I want to access a dictionary like <code>$_SESSION</cod... | 4 | 2009-07-26T20:00:26Z | 1,185,496 | <p>Let me address some things that might be related to your question...it may not be relevant for you, but I think others might come here with the exact same question and might benefit from my (limited) experience...because I also had this question at one time.</p>
<p>Speaking as someone who went from PHP to Python (a... | 8 | 2009-07-26T20:43:45Z | [
"python",
"session"
] |
How do I start a session in a Python web application? | 1,185,406 | <p>This question is based on <a href="http://stackoverflow.com/questions/1184888/to-understand-a-line-about-a-login-variable-in-a-session/1184931#1184931">this answer</a>.</p>
<p>I'm looking for a function similar to PHP's <code>session_start()</code> for Python. I want to access a dictionary like <code>$_SESSION</cod... | 4 | 2009-07-26T20:00:26Z | 1,186,016 | <p>You might consider looking into the Beaker library for Python which isn't tied to any one web framework an will work in a WSGI compatible environment:</p>
<blockquote>
<p><a href="http://beaker.groovie.org/">http://beaker.groovie.org/</a></p>
<p>Beaker is a library for caching and sessions for use with web a... | 5 | 2009-07-27T01:00:05Z | [
"python",
"session"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 1,185,528 | <p>For leading and trailing whitespace:</p>
<pre><code>s = ' foo \t '
print s.strip()
</code></pre>
<p>Otherwise, a regular expression works:</p>
<pre><code>import re
pat = re.compile(r'\s+')
s = ' \t foo \t bar \t '
print pat.sub('', s)
</code></pre>
| 17 | 2009-07-26T20:56:06Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 1,185,529 | <p>Whitespace on the both sides:</p>
<pre><code>s = " \t a string example\t "
s = s.strip()
</code></pre>
<p>Whitespace on the right side:</p>
<pre><code>s = s.rstrip()
</code></pre>
<p>Whitespace on the left side:</p>
<pre><code>s = s.lstrip()
</code></pre>
<p>As <a href="http://stackoverflow.com/users/84380/t... | 908 | 2009-07-26T20:56:26Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 9,255,908 | <pre><code>#how to trim a multi line string or a file
s=""" line one
\tline two\t
line three """
#line1 starts with a space, #2 starts and ends with a tab, #3 ends with a space.
s1=s.splitlines()
print s1
[' line one', '\tline two\t', 'line three ']
print [i.strip() for i in s1]
['line one', 'line two', 'line three... | 9 | 2012-02-13T05:16:24Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 9,326,184 | <p>Python <code>trim</code> method is called <code>strip</code>:</p>
<pre><code>str.strip() #trim
str.lstrip() #ltrim
str.rstrip() #rtrim
</code></pre>
| 39 | 2012-02-17T10:00:00Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 14,824,444 | <p>No one has posted these regex solutions yet.</p>
<p>Matching:</p>
<pre><code>>>> import re
>>> p=re.compile('\\s*(.*\\S)?\\s*')
>>> m=p.match(' \t blah ')
>>> m.group(1)
'blah'
>>> m=p.match(' \tbl ah \t ')
>>> m.group(1)
'bl ah'
>>> m=p.match(' ... | 4 | 2013-02-12T02:22:02Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 18,635,055 | <pre><code>content = "this is \nText\r\r\t\n. This is new text"
</code></pre>
<p>To remove <code>\n</code>, <code>\r</code>, <code>\t</code>, the better way is:</p>
<pre><code>data = ""
for i in content:
data += i.strip("\n").strip("\t").strip("\r").replace("\n","").replace("\t","").replace("\r","")
</code></pre>... | -2 | 2013-09-05T11:25:05Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 24,165,293 | <p>You can also use very simple, and basic function: <a href="https://docs.python.org/2/library/stdtypes.html#str.replace">str.replace()</a>, works with the whitespaces and tabs:</p>
<pre><code>>>> whitespaces = " abcd ef gh ijkl "
>>> tabs = " abcde fgh ijkl"
>>>... | 13 | 2014-06-11T14:18:09Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 29,641,234 | <p>try translate</p>
<pre><code>>>> import string
>>> print '\t\r\n hello \r\n world \t\r\n'
hello
world
>>> tr = string.maketrans(string.whitespace, ' '*len(string.whitespace))
>>> '\t\r\n hello \r\n world \t\r\n'.translate(tr)
' hello world '
>>> '\t\r\... | 0 | 2015-04-15T03:43:54Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 30,929,218 | <pre><code> something = "\t please_ \t remove_ all_ \n\n\n\nwhitespaces\n\t "
something = "".join(something.split())
</code></pre>
<p>output:
please_remove_all_whitespaces</p>
| 1 | 2015-06-19T02:58:48Z | [
"python",
"string",
"trim",
"strip"
] |
How to trim whitespace (including tabs)? | 1,185,524 | <p>Is there a function that will trim not only spaces for whitespace, but also tabs?</p>
| 623 | 2009-07-26T20:54:38Z | 32,907,310 | <p>Generally, I am using the following method:</p>
<pre><code>>>> myStr = "Hi\n Stack Over \r flow!"
>>> charList = [u"\u005Cn",u"\u005Cr",u"\u005Ct"]
>>> import re
>>> for i in charList:
myStr = re.sub(i, r"", myStr)
>>> myStr
'Hi Stack Over flow'
</code></pre>
... | 0 | 2015-10-02T12:35:41Z | [
"python",
"string",
"trim",
"strip"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.