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 |
|---|---|---|---|---|---|---|---|---|---|
simple update in sqlalchemy | 1,017,388 | <p>UserTable is:</p>
<ul>
<li><p>id (INT)</p></li>
<li><p>name (STR)</p></li>
<li><p>last_login (DATETIME)</p></li>
</ul>
<p>Serving a web page request i have a <strong>user id</strong> in hand and I only wish to update the <strong>last_login</strong> field to 'now'.</p>
<p>It seems to me that there are 2 ways:</p>
... | 7 | 2009-06-19T10:58:46Z | 1,017,420 | <p>Assuming you have a mapper UserTable in place:</p>
<pre><code>DBSession.query(UserTable).filter_by(id = user_id).\
update({"last_login":datetime.datetime.now()}, synchronize_session=False)
</code></pre>
<p>Additional parameters in the <a href="http://www.sqlalchemy.org/docs/05/reference/orm/query.html#sqlalche... | 23 | 2009-06-19T11:10:50Z | [
"python",
"sqlalchemy"
] |
backend for python | 1,017,399 | <p>which is the best back end for python applications and what is the advantage of using sqlite ,how it can be connected to python applications</p>
| 0 | 2009-06-19T11:01:48Z | 1,017,414 | <p>What do you mean with back end? Python apps connect to SQLite just like any other database, you just have to import the correct module and check how to use it.</p>
<p>The advantages of using SQLite are:</p>
<ul>
<li>You don't need to setup a database server, it's just a file</li>
<li>No configurations needed</li>
... | 3 | 2009-06-19T11:07:53Z | [
"python"
] |
backend for python | 1,017,399 | <p>which is the best back end for python applications and what is the advantage of using sqlite ,how it can be connected to python applications</p>
| 0 | 2009-06-19T11:01:48Z | 1,017,523 | <p>The language you are using at the application layer has little to do with your database choice underneath. You need to examine the advantages of other DB packages to get an idea of what you want.</p>
<p>Here are some popular database packages for cheap or free:</p>
<p>ms sql server express, pg/sql, mysql</p>
| 0 | 2009-06-19T11:45:43Z | [
"python"
] |
backend for python | 1,017,399 | <p>which is the best back end for python applications and what is the advantage of using sqlite ,how it can be connected to python applications</p>
| 0 | 2009-06-19T11:01:48Z | 1,017,603 | <p>If you mean "what is the best database?" then there's simply no way to answer this question. If you just want a small database that won't be used by more than a handful of people at a time, SQLite is what you're looking for. If you're running a database for a giant corporation serving thousands, you're probably l... | 0 | 2009-06-19T12:07:48Z | [
"python"
] |
backend for python | 1,017,399 | <p>which is the best back end for python applications and what is the advantage of using sqlite ,how it can be connected to python applications</p>
| 0 | 2009-06-19T11:01:48Z | 1,017,671 | <p>Django, Twisted, and CherryPy are popular Python "Back-Ends" as far as web applications go, with Twisted likely being the most flexible as far as networking is concerned.</p>
<p>SQLite can, as has been previously posted, be directly interfaced with using SQL commands as it has native bindings for Python, or it can ... | 0 | 2009-06-19T12:22:19Z | [
"python"
] |
Is there any Ruby or Python interpreter for Lego Mindstorm? | 1,017,429 | <p>I want to start coding in Python or Ruby. Since I own a <a href="http://en.wikipedia.org/wiki/Lego%5FRobotics">Lego Midstorms</a> kit I thought it would be nice to program against it. Are there any good translators / interpeters for the Mindstorms brick?</p>
| 21 | 2009-06-19T11:15:31Z | 1,017,443 | <p>Here's an <a href="http://rubyforge.org/projects/lego-mindstorms/" rel="nofollow">open source project for Ruby</a></p>
| 1 | 2009-06-19T11:19:48Z | [
"python",
"ruby",
"interpreter",
"robotics",
"lego"
] |
Is there any Ruby or Python interpreter for Lego Mindstorm? | 1,017,429 | <p>I want to start coding in Python or Ruby. Since I own a <a href="http://en.wikipedia.org/wiki/Lego%5FRobotics">Lego Midstorms</a> kit I thought it would be nice to program against it. Are there any good translators / interpeters for the Mindstorms brick?</p>
| 21 | 2009-06-19T11:15:31Z | 1,017,532 | <p>With python you can use <a href="http://pypi.python.org/pypi/jaraco.nxt" rel="nofollow">jaraco.nxt</a> or <a href="http://code.google.com/p/nxt-python/" rel="nofollow">nxt-python</a> to control the NXT robot. I don't own one so I've never used any of those.</p>
<p>Found this example using nxt-python:</p>
<pre><cod... | 3 | 2009-06-19T11:48:10Z | [
"python",
"ruby",
"interpreter",
"robotics",
"lego"
] |
Is there any Ruby or Python interpreter for Lego Mindstorm? | 1,017,429 | <p>I want to start coding in Python or Ruby. Since I own a <a href="http://en.wikipedia.org/wiki/Lego%5FRobotics">Lego Midstorms</a> kit I thought it would be nice to program against it. Are there any good translators / interpeters for the Mindstorms brick?</p>
| 21 | 2009-06-19T11:15:31Z | 1,020,503 | <p>The nxt-python and ruby-nxt projects are remote control interfaces to the NXT. They both run on a PC and remotely control the NXT via Bluetooth or USB.
If you are looking for running alternative firmware on the NXT, there are several different alternatives. </p>
<p>Steve Hassenplug has a webpage with a comprehensi... | 7 | 2009-06-19T23:43:24Z | [
"python",
"ruby",
"interpreter",
"robotics",
"lego"
] |
Is there any Ruby or Python interpreter for Lego Mindstorm? | 1,017,429 | <p>I want to start coding in Python or Ruby. Since I own a <a href="http://en.wikipedia.org/wiki/Lego%5FRobotics">Lego Midstorms</a> kit I thought it would be nice to program against it. Are there any good translators / interpeters for the Mindstorms brick?</p>
| 21 | 2009-06-19T11:15:31Z | 7,380,969 | <p>Try pynxc
<a href="http://code.google.com/p/pynxc/" rel="nofollow">http://code.google.com/p/pynxc/</a></p>
| 1 | 2011-09-11T20:18:54Z | [
"python",
"ruby",
"interpreter",
"robotics",
"lego"
] |
PostgreSQL - how to run VACUUM from code outside transaction block? | 1,017,463 | <p>I am using Python with psycopg2 and I'm trying to run a full <code>VACUUM</code> after a daily operation which inserts several thousand rows. The problem is that when I try to run the <code>VACUUM</code> command within my code I get the following error:</p>
<pre><code>psycopg2.InternalError: VACUUM cannot run insi... | 20 | 2009-06-19T11:26:33Z | 1,017,569 | <p>I don't know psycopg2 and PostgreSQL, but only apsw and SQLite, so I think I can not give a "psycopg2" help.</p>
<p>But it seams to me, that PostgreSQL might work similar as SQLite does, it has two modes of operation:</p>
<ul>
<li>Outside a transaction block: This is semantically equivalent to have a transaction b... | 1 | 2009-06-19T11:59:33Z | [
"python",
"sql",
"postgresql",
"psycopg2",
"vacuum"
] |
PostgreSQL - how to run VACUUM from code outside transaction block? | 1,017,463 | <p>I am using Python with psycopg2 and I'm trying to run a full <code>VACUUM</code> after a daily operation which inserts several thousand rows. The problem is that when I try to run the <code>VACUUM</code> command within my code I get the following error:</p>
<pre><code>psycopg2.InternalError: VACUUM cannot run insi... | 20 | 2009-06-19T11:26:33Z | 1,017,655 | <p>After more searching I have discovered the isolation_level property of the psycopg2 connection object. It turns out that changing this to <code>0</code> will move you out of a transaction block. Changing the vacuum method of the above class to the following solves it. Note that I also set the isolation level back... | 39 | 2009-06-19T12:18:49Z | [
"python",
"sql",
"postgresql",
"psycopg2",
"vacuum"
] |
PostgreSQL - how to run VACUUM from code outside transaction block? | 1,017,463 | <p>I am using Python with psycopg2 and I'm trying to run a full <code>VACUUM</code> after a daily operation which inserts several thousand rows. The problem is that when I try to run the <code>VACUUM</code> command within my code I get the following error:</p>
<pre><code>psycopg2.InternalError: VACUUM cannot run insi... | 20 | 2009-06-19T11:26:33Z | 1,017,674 | <p>Don't do it - you don't need VACUUM FULL. Actually if you run somewhat recent version of Postgres (let's say > 8.1) you don't even need to run plain VACUUM manually.</p>
| -1 | 2009-06-19T12:22:50Z | [
"python",
"sql",
"postgresql",
"psycopg2",
"vacuum"
] |
PostgreSQL - how to run VACUUM from code outside transaction block? | 1,017,463 | <p>I am using Python with psycopg2 and I'm trying to run a full <code>VACUUM</code> after a daily operation which inserts several thousand rows. The problem is that when I try to run the <code>VACUUM</code> command within my code I get the following error:</p>
<pre><code>psycopg2.InternalError: VACUUM cannot run insi... | 20 | 2009-06-19T11:26:33Z | 4,636,190 | <p>Additionally, you can also get the messages given by the Vacuum or Analyse using:</p>
<pre><code>>> print conn.notices #conn is the connection object
</code></pre>
<p>this command print a list with the log message of queries like Vacuum and Analyse:</p>
<pre><code>INFO: "usuario": processados 1 de 1 págin... | 3 | 2011-01-08T21:15:48Z | [
"python",
"sql",
"postgresql",
"psycopg2",
"vacuum"
] |
PostgreSQL - how to run VACUUM from code outside transaction block? | 1,017,463 | <p>I am using Python with psycopg2 and I'm trying to run a full <code>VACUUM</code> after a daily operation which inserts several thousand rows. The problem is that when I try to run the <code>VACUUM</code> command within my code I get the following error:</p>
<pre><code>psycopg2.InternalError: VACUUM cannot run insi... | 20 | 2009-06-19T11:26:33Z | 13,955,271 | <p>While vacuum full is questionable in current versions of postgresql, forcing a 'vacuum analyze' or 'reindex' after certain massive actions can improve performance, or clean up disk usage. This is postgresql specific, and needs to be cleaned up to do the right thing for other databases.</p>
<pre><code>from django.d... | 3 | 2012-12-19T15:09:25Z | [
"python",
"sql",
"postgresql",
"psycopg2",
"vacuum"
] |
PostgreSQL - how to run VACUUM from code outside transaction block? | 1,017,463 | <p>I am using Python with psycopg2 and I'm trying to run a full <code>VACUUM</code> after a daily operation which inserts several thousand rows. The problem is that when I try to run the <code>VACUUM</code> command within my code I get the following error:</p>
<pre><code>psycopg2.InternalError: VACUUM cannot run insi... | 20 | 2009-06-19T11:26:33Z | 23,684,825 | <p>Note if you're using Django with South to perform a migration you can use the following code to execute a <code>VACUUM ANALYZE</code>. </p>
<pre><code>def forwards(self, orm):
db.commit_transaction()
db.execute("VACUUM ANALYZE <table>")
#Optionally start another transaction to do some more work.... | 2 | 2014-05-15T17:18:53Z | [
"python",
"sql",
"postgresql",
"psycopg2",
"vacuum"
] |
NameError: global name 'has_no_changeset' is not defined | 1,017,467 | <p>OK - Python newbie here - I assume I am doing something really stupid, could you please tell me what it is so we can all get on with our lives?</p>
<p>I get the error <code>NameError: global name 'has_no_changeset' is not defined</code> in the line 55 (where I try calling the function <code>has_no_changeset</code>)... | 1 | 2009-06-19T11:28:17Z | 1,017,473 | <p>You need to explicitly specify <code>self</code> (or in your case, <code>me</code>) when referring to a method of the current class:</p>
<pre><code>if me.has_no_changeset(ticket):
</code></pre>
<p>You're using <code>me</code> instead of <code>self</code> - that's legal but strongly discouraged. The first paramete... | 4 | 2009-06-19T11:31:00Z | [
"python",
"syntax"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 1,017,663 | <p>Guido has a good explanation of this <a href="http://python-history.blogspot.com/2009/04/origins-of-pythons-functional-features.html">here</a>. Here's the most relevant part:</p>
<blockquote>
<p>I have never considered Python to be
heavily influenced by functional
languages, no matter what people say
or th... | 75 | 2009-06-19T12:20:18Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 1,017,673 | <p>Python is almost a functional language. It's "functional lite". </p>
<p>It has extra features, so it isn't pure enough for some. </p>
<p>It also lacks some features, so it isn't complete enough for some. </p>
<p>The missing features are relatively easy to write. Check out posts like <a href="http://blog.sigf... | 9 | 2009-06-19T12:22:40Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 1,017,682 | <p>Scheme doesn't have algebraic data types or pattern matching but it's certainly a functional language. Annoying things about Python from a functional programming perspective:</p>
<ol>
<li><p>Crippled Lambdas. Since Lambdas can only contain an expression, and you can't do everything as easily in an expression contex... | 37 | 2009-06-19T12:24:44Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 1,017,937 | <p>The question you reference asks which languages promote both OO and functional programming. Python does not <em>promote</em> functional programming even though it <em>works</em> fairly well.</p>
<p>The best argument <em>against</em> functional programming in Python is that imperative/OO use cases are carefully cons... | 264 | 2009-06-19T13:22:56Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 1,017,986 | <p>I would never call Python âfunctionalâ but whenever I program in Python the code invariably ends up being almost purely functional.</p>
<p>Admittedly, that's mainly due to the extremely nice list comprehension. So I wouldn't necessarily suggest Python as a functional programming language but I would suggest fun... | 14 | 2009-06-19T13:35:43Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 1,018,393 | <p>Let me demonstrate with a piece of code taken from an answer to a "functional" <a href="http://stackoverflow.com/questions/1016997/generate-from-generators/1017105#1017105">Python question</a> on SO</p>
<p>Python:</p>
<pre><code>def grandKids(generation, kidsFunc, val):
layer = [val]
for i in xrange(generation... | 14 | 2009-06-19T14:50:09Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 24,661,572 | <p>One thing that is really important for this question (and the answers) is the following:
What the hell is functional programming, and what are the most important properties of it.
I'll try to give my view of it:</p>
<p>Functional programming is a lot like writing math on a whiteboard. When you write equations
on a ... | 7 | 2014-07-09T18:48:46Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 35,236,180 | <p>In addition to other answers, one reason Python and most other multi-paradigm languages are not well suited for true functional programming is because their compilers / virtual machines / run-times do not support functional optimization. This sort of optimization is achieved by the compiler understanding mathematic... | 3 | 2016-02-06T01:16:27Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 37,756,221 | <p>Another reason not mentioned above is that many built-in functions and methods of built-in types modify and object but do not return the modified object. Functional code would be cleaner and more concise, for example, if some_list.append(some_object) returned some_list with some_object appended.</p>
| 2 | 2016-06-10T19:56:05Z | [
"python",
"functional-programming"
] |
Why isn't Python very good for functional programming? | 1,017,621 | <p>I have always thought that functional programming can be done in Python. Thus, I was surprised that Python didn't get much of a mention in <a href="http://stackoverflow.com/questions/1015606/mixing-object-oriented-and-functional-programming">this</a> question, and when it was mentioned, it normally wasn't very posit... | 216 | 2009-06-19T12:12:06Z | 39,640,685 | <p>Another problem with languages that support operator overloading (like Python) is that even simple expressions, like <code>x + y</code>, can potentially cause side effects. In that example, <code>x.__add__</code> could be impure, and may even change over time. </p>
| 0 | 2016-09-22T13:38:24Z | [
"python",
"functional-programming"
] |
Is there an API to access a Google Group data? | 1,017,794 | <p>I'm trying to build some statistics for an email group I participate. Is there any Python API to access the email data on a GoogleGroup?</p>
<p>Also, I know some statistics are available on the group's main page. I'm looking for something more complex than what is shown there.</p>
| 5 | 2009-06-19T12:48:08Z | 1,017,810 | <p>There isn't an API that I know of, however you can access the XML feed and manipulate it as required.</p>
| 4 | 2009-06-19T12:50:43Z | [
"python",
"google-groups"
] |
Formatting csv file data with html template | 1,017,898 | <p>I have an csv file, <strong>the data</strong>, and an HTML file, <strong>the template</strong>.</p>
<p>I want a script that will create an individual html file per record from the csv file, using the html file as a template.</p>
<p>Which is the best way to do this in Ruby? Python?
Is there a tool/library I can use... | 3 | 2009-06-19T13:12:25Z | 1,017,907 | <p>Ruby has built in CSV handling which should make it fairly trivial to output static HTML files.<br />
See:</p>
<ul>
<li><a href="http://www.rubytips.org/2008/01/06/csv-processing-in-ruby/" rel="nofollow">http://www.rubytips.org/2008/01/06/csv-processing-in-ruby/</a></li>
<li><a href="http://www.ruby-doc.org/stdlib/... | 3 | 2009-06-19T13:14:40Z | [
"python",
"html",
"ruby",
"formatting",
"csv"
] |
Formatting csv file data with html template | 1,017,898 | <p>I have an csv file, <strong>the data</strong>, and an HTML file, <strong>the template</strong>.</p>
<p>I want a script that will create an individual html file per record from the csv file, using the html file as a template.</p>
<p>Which is the best way to do this in Ruby? Python?
Is there a tool/library I can use... | 3 | 2009-06-19T13:12:25Z | 1,018,417 | <p>Python with <a href="http://jinja.pocoo.org/2/" rel="nofollow">Jinja2</a>.</p>
<pre><code>import jinja
import csv
env= jinja.Environment()
env.loader= jinja.FileSystemLoader("some/directory")
template= env.get_template( "name" )
rdr= csv.reader( open("some.csv", "r" ) )
csv_data = [ row for row in rdr ]
print te... | 3 | 2009-06-19T14:54:49Z | [
"python",
"html",
"ruby",
"formatting",
"csv"
] |
Python sys.path modification not working | 1,017,909 | <p>I'm trying to modify the sys.path in one of my Python files in order to have some
specific libraries dirs in the modules search path (it might not be the best way
but ...). If I insert several paths in the front of sys.path my script is not taking into account those paths for future imports. If i make a whole new ... | 7 | 2009-06-19T13:14:52Z | 1,017,938 | <p>How are you "inserting" the additional paths?</p>
<p>Modifying the path is done the same way any other list in Python is modified - although it sounds like you're simply clobbering it by re-assigning it.</p>
<p>Example of updating sys.path: <a href="http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html" rel="n... | 2 | 2009-06-19T13:23:05Z | [
"python",
"path"
] |
Python sys.path modification not working | 1,017,909 | <p>I'm trying to modify the sys.path in one of my Python files in order to have some
specific libraries dirs in the modules search path (it might not be the best way
but ...). If I insert several paths in the front of sys.path my script is not taking into account those paths for future imports. If i make a whole new ... | 7 | 2009-06-19T13:14:52Z | 1,017,948 | <p>You really need to post some code for us to be able to help you. However, I can make an educated guess. You say that if you make a whole new list and assign it to sys.path then it works. I assume you mean that you're doing something like this</p>
<pre><code>sys.path = ["dir1", "dir2", ...]
</code></pre>
<p>But ... | 17 | 2009-06-19T13:26:14Z | [
"python",
"path"
] |
Python sys.path modification not working | 1,017,909 | <p>I'm trying to modify the sys.path in one of my Python files in order to have some
specific libraries dirs in the modules search path (it might not be the best way
but ...). If I insert several paths in the front of sys.path my script is not taking into account those paths for future imports. If i make a whole new ... | 7 | 2009-06-19T13:14:52Z | 1,333,396 | <p>Example of updating sys.path taken from <a href="http://www.johnny-lin.com/cdat%5Ftips/tips%5Fpylang/path.html" rel="nofollow">here</a></p>
<pre><code>import sys
sys.path.append("/home/me/mypy")
</code></pre>
<p>This worked for me.</p>
| 4 | 2009-08-26T09:15:12Z | [
"python",
"path"
] |
Python sys.path modification not working | 1,017,909 | <p>I'm trying to modify the sys.path in one of my Python files in order to have some
specific libraries dirs in the modules search path (it might not be the best way
but ...). If I insert several paths in the front of sys.path my script is not taking into account those paths for future imports. If i make a whole new ... | 7 | 2009-06-19T13:14:52Z | 15,163,787 | <p>I just had a similar problem while working in iPython with modules that are distributed over several directories. In that case, to get import to work, one must make sure the <code>module.__path__</code> of modules with distributed <code>__init__.py</code> includes all directories where one of the module's <code>__i... | 1 | 2013-03-01T17:46:02Z | [
"python",
"path"
] |
How do I know which contract failed with Python's contract.py? | 1,017,985 | <p>I'm playing with <a href="http://www.wayforward.net/pycontract/" rel="nofollow">contract.py</a>, Terrence Way's reference implementation of design-by-contract for Python. The implementation throws an exception when a contract (precondition/postcondition/invariant) is violated, but it doesn't provide you a quick way ... | 1 | 2009-06-19T13:35:32Z | 1,020,981 | <p>Without modifying his code, I don't think you can, but since this is python...</p>
<p>If you look for where he raises the exception to the user, it I think is possible to push the info you're looking for into it... I wouldn't expect you to be able to get the trace-back to be any better though because the code is ac... | 1 | 2009-06-20T05:01:22Z | [
"python",
"design-by-contract"
] |
How do I know which contract failed with Python's contract.py? | 1,017,985 | <p>I'm playing with <a href="http://www.wayforward.net/pycontract/" rel="nofollow">contract.py</a>, Terrence Way's reference implementation of design-by-contract for Python. The implementation throws an exception when a contract (precondition/postcondition/invariant) is violated, but it doesn't provide you a quick way ... | 1 | 2009-06-19T13:35:32Z | 11,017,292 | <p>This is an old question but I may as well answer it. I added some output, you'll see it at the comment # jlr001. Add the line below to your contract.py and when it raises an exception it will show the doc line number and the statement that triggered it. Nothing more than that, but it will at least stop you from need... | 1 | 2012-06-13T14:39:08Z | [
"python",
"design-by-contract"
] |
Help me understand the difference between CLOBs and BLOBs in Oracle | 1,018,073 | <p>This is mainly just a "check my understanding" type of question. Here's my understanding of CLOBs and BLOBs as they work in Oracle:</p>
<ul>
<li>CLOBs are for text like XML, JSON, etc. You should not assume what encoding the database will store it as (at least in an application) as it will be converted to whateve... | 33 | 2009-06-19T13:51:38Z | 1,018,096 | <p><code>CLOB</code> is encoding and collation sensitive, <code>BLOB</code> is not.</p>
<p>When you write into a <code>CLOB</code> using, say, <code>CL8WIN1251</code>, you write a <code>0xC0</code> (which is Cyrillic letter Ð).</p>
<p>When you read data back using <code>AL16UTF16</code>, you get back <code>0x0410</c... | 46 | 2009-06-19T13:56:25Z | [
"python",
"oracle"
] |
Help me understand the difference between CLOBs and BLOBs in Oracle | 1,018,073 | <p>This is mainly just a "check my understanding" type of question. Here's my understanding of CLOBs and BLOBs as they work in Oracle:</p>
<ul>
<li>CLOBs are for text like XML, JSON, etc. You should not assume what encoding the database will store it as (at least in an application) as it will be converted to whateve... | 33 | 2009-06-19T13:51:38Z | 1,018,102 | <p>Your understanding is correct. Since you mention Python, think of the Python 3 distinction between strings and bytes: CLOBs and BLOBs are quite analogous, with the extra issue that the encoding of CLOBs is not under your app's control.</p>
| 9 | 2009-06-19T13:57:36Z | [
"python",
"oracle"
] |
One django installation different users per site | 1,018,111 | <p>How can I have different users for different sites with django.
My application should look like this:</p>
<pre><code>a.mydomain.com
b.otherdomain.com
</code></pre>
<p>Users should be bound to the domain, so that a.mydomain.com and b.otherdomain.com have different users.</p>
| 0 | 2009-06-19T13:59:32Z | 1,018,202 | <p>In the <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">auth</a> setup, you could create separate custom permissions, one per domain, and check if the current user has the permission for the current domain -- see the "custom permissions" section in the auth doc in question.</p>
| 1 | 2009-06-19T14:20:43Z | [
"python",
"django",
"authentication",
"django-models"
] |
Pass-through keyword arguments | 1,018,359 | <p>I've got a class function that needs to "pass through" a particular keyword argument:</p>
<pre><code>def createOrOpenTable(self, tableName, schema, asType=Table):
if self.tableExists(tableName):
return self.openTable(tableName, asType=asType)
else:
return self.createTable(self, tableName, sc... | 4 | 2009-06-19T14:44:33Z | 1,018,372 | <p>You're doing it right... Just take out the <code>self</code> in the second function call :)</p>
<pre><code> return self.createTable(self, tableName, schema, asType=asType)
</code></pre>
<p>should be:</p>
<pre><code> return self.createTable(tableName, schema, asType=asType)
</code></pre>
| 9 | 2009-06-19T14:46:01Z | [
"python"
] |
Pass-through keyword arguments | 1,018,359 | <p>I've got a class function that needs to "pass through" a particular keyword argument:</p>
<pre><code>def createOrOpenTable(self, tableName, schema, asType=Table):
if self.tableExists(tableName):
return self.openTable(tableName, asType=asType)
else:
return self.createTable(self, tableName, sc... | 4 | 2009-06-19T14:44:33Z | 1,018,431 | <p>I have to say, that I first thought of a more complicated problem. But the answer of David Wolever is absolutely correct. It is just the duplicate self here, that creates the problem. This way, the positional parameters get out of line and asType is given a value as possitional parameter (once) and as keyword-parame... | 5 | 2009-06-19T14:57:58Z | [
"python"
] |
Pass-through keyword arguments | 1,018,359 | <p>I've got a class function that needs to "pass through" a particular keyword argument:</p>
<pre><code>def createOrOpenTable(self, tableName, schema, asType=Table):
if self.tableExists(tableName):
return self.openTable(tableName, asType=asType)
else:
return self.createTable(self, tableName, sc... | 4 | 2009-06-19T14:44:33Z | 1,018,487 | <p>I would have posted a comment to Juergen's post, but I need to write a code example. Here's a little bit more generic version:</p>
<pre><code>def createOrOpenTable(self, tableName, schema, *args, **argd):
if self.tableExists(tableName):
return self.openTable(tableName, *args, **argd)
else:
... | 5 | 2009-06-19T15:07:34Z | [
"python"
] |
Python and if statement | 1,018,415 | <p>I'm running a script to feed an exe file a statement like below:</p>
<pre><code>for j in ('90.','52.62263.','26.5651.','10.8123.'):
if j == '90.':
z = ('0.')
elif j == '52.62263.':
z = ('0.', '72.', '144.', '216.', '288.')
elif j == '26.5651':
z = ('324.', '36.', '108.', '180.', ... | 2 | 2009-06-19T14:54:30Z | 1,018,426 | <p><code>z = ('0.')</code> is not a tuple, therefore your <code>for k in z</code> loop will iterate over the characters "0" and ".". Add a comma to tell python you want it to be a tuple:</p>
<pre><code>z = ('0.',)
</code></pre>
| 8 | 2009-06-19T14:57:07Z | [
"python",
"if-statement"
] |
Python and if statement | 1,018,415 | <p>I'm running a script to feed an exe file a statement like below:</p>
<pre><code>for j in ('90.','52.62263.','26.5651.','10.8123.'):
if j == '90.':
z = ('0.')
elif j == '52.62263.':
z = ('0.', '72.', '144.', '216.', '288.')
elif j == '26.5651':
z = ('324.', '36.', '108.', '180.', ... | 2 | 2009-06-19T14:54:30Z | 1,018,480 | <p>I think what's happening right now is that you are not waiting for those processes to finish before they're printed. Try something like this in your last 2 lines:</p>
<pre><code>from subprocess import Popen, STDOUT
stdout, stderr = Popen('echo ' + cmd, shell=True, stderr=STDOUT).communicate()
print stdout
</code></... | 6 | 2009-06-19T15:06:14Z | [
"python",
"if-statement"
] |
Python and if statement | 1,018,415 | <p>I'm running a script to feed an exe file a statement like below:</p>
<pre><code>for j in ('90.','52.62263.','26.5651.','10.8123.'):
if j == '90.':
z = ('0.')
elif j == '52.62263.':
z = ('0.', '72.', '144.', '216.', '288.')
elif j == '26.5651':
z = ('324.', '36.', '108.', '180.', ... | 2 | 2009-06-19T14:54:30Z | 1,018,511 | <p>What eduffy said. And this is a little cleaner; just prints, but you get the idea:</p>
<pre><code>import os
data = {
'90.': ('0.',),
'52.62263.': ('0.', '72.', '144.', '216.', '288.'),
'26.5651.': ('324.', '36.', '108.', '180.', '252.'),
'10.8123.': ('288.', '0.', '72.', '144.', '216.'),
}
for ta... | 5 | 2009-06-19T15:10:57Z | [
"python",
"if-statement"
] |
Python and if statement | 1,018,415 | <p>I'm running a script to feed an exe file a statement like below:</p>
<pre><code>for j in ('90.','52.62263.','26.5651.','10.8123.'):
if j == '90.':
z = ('0.')
elif j == '52.62263.':
z = ('0.', '72.', '144.', '216.', '288.')
elif j == '26.5651':
z = ('324.', '36.', '108.', '180.', ... | 2 | 2009-06-19T14:54:30Z | 1,018,513 | <p>Since you've made a few posts about this bit of code, allow me to just correct/pythonify/beautify the whole thing:</p>
<pre><code>for j,z in {
'90.' : ('0.',) ,
'52.62263.' : ('0.', '72.', '144.', '216.', '288.') ,
'26.5651.' : ('324.', '36.', '108.', '180.', '252.') ,
'10.8... | 2 | 2009-06-19T15:11:09Z | [
"python",
"if-statement"
] |
Python logging incompatibilty between 2.5 and 2.6 | 1,018,527 | <p>Could you help me solve the following incompatibility issue between Python 2.5 and 2.6?</p>
<p>logger.conf:</p>
<pre><code>[loggers]
keys=root,aLogger,bLogger
[handlers]
keys=consoleHandler
[formatters]
keys=
[logger_root]
level=NOTSET
handlers=consoleHandler
[logger_aLogger]
level=DEBUG
handlers=consoleHandle... | 6 | 2009-06-19T15:14:14Z | 1,018,694 | <p>I don't understand the reasons of this behavior myself but as you well stated in 2.6 it works differently. We can assume this is a bug affecting 2.5</p>
<p>As a workaround I suggest the following:</p>
<p>extra_module.py:</p>
<pre><code>import logging
import logging.config
logging.config.fileConfig('logger.conf')... | 1 | 2009-06-19T15:46:30Z | [
"python",
"logging",
"incompatibility"
] |
Python logging incompatibilty between 2.5 and 2.6 | 1,018,527 | <p>Could you help me solve the following incompatibility issue between Python 2.5 and 2.6?</p>
<p>logger.conf:</p>
<pre><code>[loggers]
keys=root,aLogger,bLogger
[handlers]
keys=consoleHandler
[formatters]
keys=
[logger_root]
level=NOTSET
handlers=consoleHandler
[logger_aLogger]
level=DEBUG
handlers=consoleHandle... | 6 | 2009-06-19T15:14:14Z | 1,018,696 | <p>Interesting... I played a little in the console and it looks like the second call to <code>logging.config.fileConfig</code> is mucking things up. Not sure why this is though... Here's a transcript that shows the problem:</p>
<pre><code>lorien$ python2.5
Python 2.5.1 (r251:54863, Feb 6 2009, 19:02:12)
[GCC 4.0.1 (... | 0 | 2009-06-19T15:47:03Z | [
"python",
"logging",
"incompatibility"
] |
Python logging incompatibilty between 2.5 and 2.6 | 1,018,527 | <p>Could you help me solve the following incompatibility issue between Python 2.5 and 2.6?</p>
<p>logger.conf:</p>
<pre><code>[loggers]
keys=root,aLogger,bLogger
[handlers]
keys=consoleHandler
[formatters]
keys=
[logger_root]
level=NOTSET
handlers=consoleHandler
[logger_aLogger]
level=DEBUG
handlers=consoleHandle... | 6 | 2009-06-19T15:14:14Z | 1,019,022 | <p>This is a bug which was fixed between 2.5 and 2.6. The fileConfig() function is intended for one-off configuration and so should not be called more than once - however you choose to arrange this. The intended behaviour of fileConfig is to disable any loggers which are not explicitly mentioned in the configuration, a... | 8 | 2009-06-19T17:03:53Z | [
"python",
"logging",
"incompatibility"
] |
Python logging incompatibilty between 2.5 and 2.6 | 1,018,527 | <p>Could you help me solve the following incompatibility issue between Python 2.5 and 2.6?</p>
<p>logger.conf:</p>
<pre><code>[loggers]
keys=root,aLogger,bLogger
[handlers]
keys=consoleHandler
[formatters]
keys=
[logger_root]
level=NOTSET
handlers=consoleHandler
[logger_aLogger]
level=DEBUG
handlers=consoleHandle... | 6 | 2009-06-19T15:14:14Z | 1,019,090 | <p>I was able to fix this by changing the names of the loggers like so, in both files:</p>
<pre><code>logging.config.fileConfig('logger.conf')
a_log = logging.getLogger('a')
b_log = logging.getLogger('b')
</code></pre>
<p>I'm not sure of the exact error, but the v2.5 logger module seems to have trouble matching names... | 0 | 2009-06-19T17:23:15Z | [
"python",
"logging",
"incompatibility"
] |
'Unstarring' posts using Google Reader API | 1,018,626 | <p>Does anybody know how to remove stars for articles starred in Google Reader using its unofficial API? </p>
<p>I found this one but it doesn't work:</p>
<p><a href="http://www.niallkennedy.com/blog/2005/12/google-reader-api.html" rel="nofollow">http://www.niallkennedy.com/blog/2005/12/google-reader-api.html</a></p>... | 3 | 2009-06-19T15:35:20Z | 1,018,666 | <p>Try using:</p>
<pre><code>r=user%2F[user ID]%2Fstate%2Fcom.google%2Fstarred
</code></pre>
<p>instead of</p>
<pre><code>a=user%2F[user ID]%2Fstate%2Fcom.google%2Fstarred
</code></pre>
<p>when invoking edit-tag.</p>
| 1 | 2009-06-19T15:42:17Z | [
"python",
"google-reader"
] |
'Unstarring' posts using Google Reader API | 1,018,626 | <p>Does anybody know how to remove stars for articles starred in Google Reader using its unofficial API? </p>
<p>I found this one but it doesn't work:</p>
<p><a href="http://www.niallkennedy.com/blog/2005/12/google-reader-api.html" rel="nofollow">http://www.niallkennedy.com/blog/2005/12/google-reader-api.html</a></p>... | 3 | 2009-06-19T15:35:20Z | 6,300,705 | <p>I don't have Python code for this (I have Java), but the problem you're stumbling with is pretty much independent from the language you use, and it is always good to be able to see some code where you need to have all the details. You just need to do the requests I do, and verify some of the details I highlight and ... | 0 | 2011-06-10T00:16:38Z | [
"python",
"google-reader"
] |
Python tkInter text entry validation | 1,018,729 | <p>I'm trying to validate the entry of text using Python/tkInter</p>
<pre><code>def validate_text():
return False
text = Entry(textframe, validate="focusout", validatecommand=validate_text)
</code></pre>
<p>where validate_text is the function - I've tried always returning False and always returning True and the... | 1 | 2009-06-19T15:54:36Z | 1,018,742 | <p>"Note that this option [validatecommand] is only used if the validate option is not NONE"</p>
<p>From <a href="http://effbot.org/tkinterbook/entry.htm#entry.Entry.config-method" rel="nofollow">http://effbot.org/tkinterbook/entry.htm#entry.Entry.config-method</a></p>
| 0 | 2009-06-19T15:58:21Z | [
"python",
"tkinter"
] |
Python tkInter text entry validation | 1,018,729 | <p>I'm trying to validate the entry of text using Python/tkInter</p>
<pre><code>def validate_text():
return False
text = Entry(textframe, validate="focusout", validatecommand=validate_text)
</code></pre>
<p>where validate_text is the function - I've tried always returning False and always returning True and the... | 1 | 2009-06-19T15:54:36Z | 9,246,129 | <p><code>focusout</code> means validatecommand will be only be invoked when you take the focus out from the entrywidget.</p>
<p>You could try 'key' for validating while typing.</p>
<p>Tcl manual:<br>
Validation works by setting the validateCommand option to a script which will be evaluated according to the validate o... | 0 | 2012-02-12T03:13:48Z | [
"python",
"tkinter"
] |
Python tkInter text entry validation | 1,018,729 | <p>I'm trying to validate the entry of text using Python/tkInter</p>
<pre><code>def validate_text():
return False
text = Entry(textframe, validate="focusout", validatecommand=validate_text)
</code></pre>
<p>where validate_text is the function - I've tried always returning False and always returning True and the... | 1 | 2009-06-19T15:54:36Z | 11,786,588 | <p>I think the only thing your missing is an <strong>invalidcommand (or invcmd)</strong>. What are you expecting validatecommand (or vcmd) to do if it returns false? According to the Tk Manual (see below), if vcmd returns False and validate is <em>not</em> set to none then invcmd will be called. The typical command for... | 2 | 2012-08-02T22:13:34Z | [
"python",
"tkinter"
] |
Difference between using __init__ and setting a class variable | 1,018,977 | <p>I'm trying to learn descriptors, and I'm confused by objects behaviour - in the two examples below, as I understood <code>__init__</code> they should work the same. Can someone unconfuse me, or point me to a resource that explains this?</p>
<pre><code>import math
class poweroftwo(object):
"""any time this is se... | 3 | 2009-06-19T16:54:44Z | 1,019,059 | <p>First, please name all classes with LeadingUpperCaseNames.</p>
<pre><code>>>> a.x
GET
(10, 100.0)
>>> b.x
<__main__.poweroftwo object at 0x00C57D10>
>>> type(a.x)
GET
<type 'tuple'>
>>> type(b.x)
<class '__main__.poweroftwo'>
</code></pre>
<p><code>a.x</code> i... | 3 | 2009-06-19T17:15:01Z | [
"python",
"descriptor"
] |
How to replace a column using Python's built-in .csv writer module? | 1,019,200 | <p>I need to do a find and replace (specific to one column of URLs) in a huge Excel .csv file. Since I'm in the beginning stages of trying to teach myself a scripting language, I figured I'd try to implement the solution in python.</p>
<p>I'm having trouble with the "replace" part of the solution. I've read the <a hre... | 1 | 2009-06-19T17:47:56Z | 1,019,265 | <p>The reason you're getting an error is that the writer doesn't have data to iterate over. You're supposed to give it the data - presumably, you'd have some sort of list or generator that produces the rows to write out.</p>
<p>I'd suggest just combining the two loops, like so:</p>
<pre><code>for row in reader:
r... | 6 | 2009-06-19T18:01:33Z | [
"python",
"file-io",
"csv"
] |
How to replace a column using Python's built-in .csv writer module? | 1,019,200 | <p>I need to do a find and replace (specific to one column of URLs) in a huge Excel .csv file. Since I'm in the beginning stages of trying to teach myself a scripting language, I figured I'd try to implement the solution in python.</p>
<p>I'm having trouble with the "replace" part of the solution. I've read the <a hre... | 1 | 2009-06-19T17:47:56Z | 1,019,269 | <p>You should only have one loop and read and write at the same time - if your replacements only affect one line at a time, you don't need to loop over the data twice.</p>
<pre><code>for row in reader:
total=total+1
temp = row[len(row)-1]
if '/?' in temp:
temp = row[len(row)-1]
temp.replace('/?', '?')
... | 1 | 2009-06-19T18:02:16Z | [
"python",
"file-io",
"csv"
] |
How to replace a column using Python's built-in .csv writer module? | 1,019,200 | <p>I need to do a find and replace (specific to one column of URLs) in a huge Excel .csv file. Since I'm in the beginning stages of trying to teach myself a scripting language, I figured I'd try to implement the solution in python.</p>
<p>I'm having trouble with the "replace" part of the solution. I've read the <a hre... | 1 | 2009-06-19T17:47:56Z | 1,159,816 | <p>Once you have your csv in a big list, one easy way to replace a column in a list would be to transpose your matrix, replace the row, and then transpose it back:</p>
<pre><code>mydata = [[1, 'a', 10], [2, 'b', 20], [3, 'c', 30]]
def transpose(matrix):
return [[matrix[x][y] for x in range(len(matrix))] for y in ... | 0 | 2009-07-21T15:10:01Z | [
"python",
"file-io",
"csv"
] |
Algorithm for updating a list from a list | 1,019,302 | <p>I've got a data source that provides a list of objects and their properties (a CSV file, but that doesn't matter). Each time my program runs, it needs to pull a new copy of the list of objects, compare it to the list of objects (and their properties) stored in the database, and update the database as needed.</p>
<p... | 0 | 2009-06-19T18:09:22Z | 1,019,395 | <p>Is there no way to maintain a "last time modified" field? That's what it sounds like you're really looking for: an incremental backup, based on last time backup was run, compared to last time an object was changed/deleted(/added).</p>
| 1 | 2009-06-19T18:25:21Z | [
"python",
"google-app-engine",
"set"
] |
Algorithm for updating a list from a list | 1,019,302 | <p>I've got a data source that provides a list of objects and their properties (a CSV file, but that doesn't matter). Each time my program runs, it needs to pull a new copy of the list of objects, compare it to the list of objects (and their properties) stored in the database, and update the database as needed.</p>
<p... | 0 | 2009-06-19T18:09:22Z | 1,019,401 | <p>When you pull the list into your program, iterate over the list doing a query based on a column property in the database table that maps to the same property of the object from list like ObjectName. Or you could load the whole table into a list and compare the list that way. I assuming that you have something uniq... | 0 | 2009-06-19T18:26:18Z | [
"python",
"google-app-engine",
"set"
] |
Algorithm for updating a list from a list | 1,019,302 | <p>I've got a data source that provides a list of objects and their properties (a CSV file, but that doesn't matter). Each time my program runs, it needs to pull a new copy of the list of objects, compare it to the list of objects (and their properties) stored in the database, and update the database as needed.</p>
<p... | 0 | 2009-06-19T18:09:22Z | 1,019,428 | <p>You need to have timestamps in both your database and your CSV file. Timestamp should show the data when the record was updated and you should compare timestamps of the record with same IDs to decide if you need updating it or not</p>
<p>As to your idea about intersection...
It should be done vise versa!
You have t... | 1 | 2009-06-19T18:33:05Z | [
"python",
"google-app-engine",
"set"
] |
Algorithm for updating a list from a list | 1,019,302 | <p>I've got a data source that provides a list of objects and their properties (a CSV file, but that doesn't matter). Each time my program runs, it needs to pull a new copy of the list of objects, compare it to the list of objects (and their properties) stored in the database, and update the database as needed.</p>
<p... | 0 | 2009-06-19T18:09:22Z | 1,019,596 | <p>The standard approach for huge piles of data amounts to this. </p>
<p>We'll assume that list_1 is the "master" (without duplicates) and list_2 is the "updates" which may have duplicates.</p>
<pre><code>iter_1 = iter( sorted(list_1) ) # Essentially SELECT...ORDER BY
iter_2 = iter( sorted(list_2) )
eof_1 = False
eo... | 1 | 2009-06-19T19:11:13Z | [
"python",
"google-app-engine",
"set"
] |
Is there an easy way to convert an std::list<double> to a Python list? | 1,019,457 | <p>I'm writing a little Python extension in C/C++, and I've got a function like this:</p>
<pre><code>void set_parameters(int first_param, std::list<double> param_list)
{
//do stuff
}
</code></pre>
<p>I'd like to be able to call it from Python like this:</p>
<pre><code>set_parameters(f_param, [1.0, 0.5, 2.1]... | 2 | 2009-06-19T18:39:23Z | 1,019,574 | <p>Take a look at <a href="http://www.boost.org/doc/libs/1%5F39%5F0/libs/python/doc/index.html" rel="nofollow">Boost.Python</a>. Question you've asked is covered in <a href="http://www.boost.org/doc/libs/1%5F39%5F0/libs/python/doc/tutorial/doc/html/python/iterators.html" rel="nofollow">Iterators</a> chapter of the tuto... | 0 | 2009-06-19T19:07:21Z | [
"python",
"c",
"stl"
] |
Is there an easy way to convert an std::list<double> to a Python list? | 1,019,457 | <p>I'm writing a little Python extension in C/C++, and I've got a function like this:</p>
<pre><code>void set_parameters(int first_param, std::list<double> param_list)
{
//do stuff
}
</code></pre>
<p>I'd like to be able to call it from Python like this:</p>
<pre><code>set_parameters(f_param, [1.0, 0.5, 2.1]... | 2 | 2009-06-19T18:39:23Z | 1,020,113 | <p>It turned out to be less pain than I thought, once I found the docs that I probably should have read before I asked the question. I was able to get a PyList object in my wrapper function, then just iterate over it and push the values onto the vector I needed. The code looks like this:</p>
<pre><code>static PyObje... | 0 | 2009-06-19T21:29:57Z | [
"python",
"c",
"stl"
] |
What's a good data model for cross-tabulation? | 1,019,643 | <p>I'm implementing a cross-tabulation library in Python as a programming exercise for my new job, and I've got an implementation of the requirements that <em>works</em> but is inelegant and redundant. I'd like a better model for it, something that allows a nice, clean movement of data between the base model, stored a... | 6 | 2009-06-19T19:22:33Z | 1,019,679 | <p>Why not store it using HTML Tables? It might not be the best, but you could then, very easily, view it in a browser.</p>
<p>Edit:</p>
<p>I just re-read the question and you're asking for data model, not a storage model. To answer that question...</p>
<p>It all depends on how you're going to be reporting on the ... | -1 | 2009-06-19T19:29:09Z | [
"python",
"algorithm",
"data-structures",
"statistics",
"crosstab"
] |
What's a good data model for cross-tabulation? | 1,019,643 | <p>I'm implementing a cross-tabulation library in Python as a programming exercise for my new job, and I've got an implementation of the requirements that <em>works</em> but is inelegant and redundant. I'd like a better model for it, something that allows a nice, clean movement of data between the base model, stored a... | 6 | 2009-06-19T19:22:33Z | 1,019,777 | <p>Since this is an early programming exercise for Python, they probably want you to see what Python built-in mechanisms would be appropriate for the initial version of the problem. The dictionary structure seems a good candidate. The first column value from your tab-sep file can be the key into a dictionary. The en... | 0 | 2009-06-19T19:57:22Z | [
"python",
"algorithm",
"data-structures",
"statistics",
"crosstab"
] |
What's a good data model for cross-tabulation? | 1,019,643 | <p>I'm implementing a cross-tabulation library in Python as a programming exercise for my new job, and I've got an implementation of the requirements that <em>works</em> but is inelegant and redundant. I'd like a better model for it, something that allows a nice, clean movement of data between the base model, stored a... | 6 | 2009-06-19T19:22:33Z | 1,022,761 | <p>You could use an in-memory <code>sqlite</code> database as a data structure, and define the desired operations as SQL queries.</p>
<pre><code>import sqlite3
c = sqlite3.Connection(':memory:')
c.execute('CREATE TABLE data (a, b, c)')
c.executemany('INSERT INTO data VALUES (?, ?, ?)', [
(1, None, 1),
(1,... | 1 | 2009-06-20T23:03:24Z | [
"python",
"algorithm",
"data-structures",
"statistics",
"crosstab"
] |
What's a good data model for cross-tabulation? | 1,019,643 | <p>I'm implementing a cross-tabulation library in Python as a programming exercise for my new job, and I've got an implementation of the requirements that <em>works</em> but is inelegant and redundant. I'd like a better model for it, something that allows a nice, clean movement of data between the base model, stored a... | 6 | 2009-06-19T19:22:33Z | 6,702,011 | <p>S W has posted <a href="http://code.activestate.com/recipes/334695-pivotcrosstabdenormalization-of-a-normalized-list/" rel="nofollow">a good basic recipe for this on activestate.com</a>.</p>
<p>The essence seems to be...</p>
<ol>
<li>Define xsort=[] and ysort=[] as arrays of your axes. Populate them by iterating ... | 1 | 2011-07-15T02:11:19Z | [
"python",
"algorithm",
"data-structures",
"statistics",
"crosstab"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,019,720 | <p>There's a tool called <a href="http://sourceforge.net/projects/strace/" rel="nofollow">strace</a> - it monitors system calls made by a given process. You just need to watch out for specific calls suggesting 'illegal' function access. AFAIK, it's the method used in programming competitions to sandbox contestants' pro... | 1 | 2009-06-19T19:39:42Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,019,727 | <p>I'd say this is extremely dangerous on many levels. You're essentially opening yourself up to any exploit that can be found on your system (whereas you're normally limited to the ones people can exploit remotely). I'd say don't do it if you can avoid it.</p>
<p>If you do want to do it, you might want to use some ... | 3 | 2009-06-19T19:40:48Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,019,986 | <p>About the only chance you have is running a VirtualMachine and those can have vulnerabilities. If you want your machine hacked in the short term just use permissions and make a special user with access to maybe one directory. If you want to postpone the hacking to some point in the future then run a webserver inside... | -2 | 2009-06-19T20:53:23Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,020,006 | <p>Although it is still in development, and not yet considered secure, you might check out the technology behind <a href="http://code.google.com/p/nativeclient/" rel="nofollow">Google Native Client</a>. It is designed to allow untrusted native code to be run in a web browser, but could probably be adapted for use on a... | 3 | 2009-06-19T21:00:31Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,020,010 | <p>On <a href="http://fedoraproject.org/" rel="nofollow">Fedora 11</a>, there is the <a href="http://danwalsh.livejournal.com/28545.html" rel="nofollow">SELinux Sandbox</a> which seems to do exactly what you want (except perhaps limiting spawning new processes; the linked blog post does not mention that).</p>
<p>Of co... | 2 | 2009-06-19T21:01:57Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,020,081 | <p>The few details you provide imply that you have administrative control over the server itself, so my suggestion makes this assumption.</p>
<p>I'd tackle this as a batch system. The web server accepts an upload of the source file, a process polls the submission directory, processes the file, and then submits the re... | 4 | 2009-06-19T21:24:28Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,020,272 | <p>Along with the other sugestions you might find this useful.</p>
<p><a href="http://www.eelis.net/geordi/" rel="nofollow">http://www.eelis.net/geordi/</a></p>
<p>This is from <a href="http://codepad.org/about" rel="nofollow">http://codepad.org/about</a>, <a href="http://codepad.org" rel="nofollow">codepad.org</a>'s... | 4 | 2009-06-19T22:12:13Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,020,287 | <p>See <a href="http://code.google.com/p/chromium/wiki/LinuxSandboxing" rel="nofollow">this page on Google Chrome's sandboxing methods for Linux</a>. As you can see, there are plenty of methods, but none of them are great for a distributable application like Chrome because some distros might not include them. This is n... | 1 | 2009-06-19T22:17:47Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 1,029,301 | <p>I think your solutions must concentrate on analyzing the source code. I don't know any tools, and I think this would be pretty hard with <code>C</code>, but, for example, a <code>Pascal</code> program which doesn't include any modules would be pretty harmless in my opinion.</p>
| 0 | 2009-06-22T20:45:42Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 15,609,095 | <p>Spawning a new VM under KVM or qemu to compile and run the code looks like the way to go. Running the code under jail/LXC can compromise the machine if it exploits the unsecured parts of the OS like networking code. Advantage of running under a VM are obvious. One can only hack the VM but not the machine itself. But... | 0 | 2013-03-25T06:42:47Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 16,050,403 | <p>ptrace-based confinement for untrusted programs can be used like the one described in <a href="http://www.cs.vu.nl/~rutger/publications/jailer.pdf" rel="nofollow">http://www.cs.vu.nl/~rutger/publications/jailer.pdf</a>, <a href="http://www.cs.vu.nl/~guido/mansion/publications/ps/secrypt07.pdf" rel="nofollow">http:/... | 0 | 2013-04-17T02:27:37Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Sandboxing in Linux | 1,019,707 | <p>I want to create a Web app which would allow the user to upload some C code, and see the results of its execution (the code would be compiled on the server). The users are untrusted, which obviously has some huge security implications.</p>
<p>So I need to create some kind of sandbox for the apps. At the most basic ... | 15 | 2009-06-19T19:35:07Z | 17,868,112 | <p>I guess <a href="https://openjudge.net/~liuyu/Project/LibSandbox" rel="nofollow">libsandbox</a> serves your purpose. Its core library is written for C/C++, but it also has a wrapper for Python programs. It provides options to customize which system calls can be allowed, how much memory can be used, how long can the ... | 2 | 2013-07-25T20:26:19Z | [
"python",
"c",
"linux",
"security",
"sandbox"
] |
Speed of calculating powers (in python) | 1,019,740 | <p>I'm curious as to why it's so much faster to multiply than to take powers in python (though from what I've read this may well be true in many other languages too). For example it's much faster to do</p>
<pre><code>x*x
</code></pre>
<p>than</p>
<pre><code>x**2
</code></pre>
<p>I suppose the ** operator is more ge... | 16 | 2009-06-19T19:46:44Z | 1,019,808 | <p>how about x*x*x*x*x?
is it still faster than x**5?</p>
<p>as int exponents gets larger, taking powers might be faster than multiplication.
but the number where actual crossover occurs depends on various conditions, so in my opinion, that's why the optimization was not done(or couldn't be done) in language/library l... | 0 | 2009-06-19T20:06:00Z | [
"python",
"algorithm",
"performance"
] |
Speed of calculating powers (in python) | 1,019,740 | <p>I'm curious as to why it's so much faster to multiply than to take powers in python (though from what I've read this may well be true in many other languages too). For example it's much faster to do</p>
<pre><code>x*x
</code></pre>
<p>than</p>
<pre><code>x**2
</code></pre>
<p>I suppose the ** operator is more ge... | 16 | 2009-06-19T19:46:44Z | 1,019,815 | <p>Adding a check is an expense, too. Do you always want that check there? A compiled language could make the check for a constant exponent to see if it's a relatively small integer because there's no run-time cost, just a compile-time cost. An interpreted language might not make that check.</p>
<p>It's up to the part... | 6 | 2009-06-19T20:07:50Z | [
"python",
"algorithm",
"performance"
] |
Speed of calculating powers (in python) | 1,019,740 | <p>I'm curious as to why it's so much faster to multiply than to take powers in python (though from what I've read this may well be true in many other languages too). For example it's much faster to do</p>
<pre><code>x*x
</code></pre>
<p>than</p>
<pre><code>x**2
</code></pre>
<p>I suppose the ** operator is more ge... | 16 | 2009-06-19T19:46:44Z | 1,019,868 | <p>I'd suspect that nobody was expecting this to be all that important. Typically, if you want to do serious calculations, you do them in Fortran or C or C++ or something like that (and perhaps call them from Python).</p>
<p>Treating everything as exp(n * log(x)) works well in cases where n isn't integral or is prett... | 1 | 2009-06-19T20:20:10Z | [
"python",
"algorithm",
"performance"
] |
Speed of calculating powers (in python) | 1,019,740 | <p>I'm curious as to why it's so much faster to multiply than to take powers in python (though from what I've read this may well be true in many other languages too). For example it's much faster to do</p>
<pre><code>x*x
</code></pre>
<p>than</p>
<pre><code>x**2
</code></pre>
<p>I suppose the ** operator is more ge... | 16 | 2009-06-19T19:46:44Z | 1,019,932 | <p>Basically naive multiplication is O(n) with a very low constant factor. Taking the power is O(log n) with a higher constant factor (There are special cases that need to be tested... fractional exponents, negative exponents, etc) . Edit: just to be clear, that's O(n) where n is the exponent.</p>
<p>Of course the nai... | 17 | 2009-06-19T20:33:46Z | [
"python",
"algorithm",
"performance"
] |
Speed of calculating powers (in python) | 1,019,740 | <p>I'm curious as to why it's so much faster to multiply than to take powers in python (though from what I've read this may well be true in many other languages too). For example it's much faster to do</p>
<pre><code>x*x
</code></pre>
<p>than</p>
<pre><code>x**2
</code></pre>
<p>I suppose the ** operator is more ge... | 16 | 2009-06-19T19:46:44Z | 1,020,252 | <p>Doing this in the exponent check will slow down the cases where it isn't a simple power of two very slightly, so isn't necessarily a win. However, in cases where the exponent is known in advance( eg. literal 2 is used), the bytecode generated could be optimised with a simple peephole optimisation. Presumably this ... | 3 | 2009-06-19T22:05:31Z | [
"python",
"algorithm",
"performance"
] |
Speed of calculating powers (in python) | 1,019,740 | <p>I'm curious as to why it's so much faster to multiply than to take powers in python (though from what I've read this may well be true in many other languages too). For example it's much faster to do</p>
<pre><code>x*x
</code></pre>
<p>than</p>
<pre><code>x**2
</code></pre>
<p>I suppose the ** operator is more ge... | 16 | 2009-06-19T19:46:44Z | 24,951,249 | <p>An implementation of b^p with binary exponentiation</p>
<pre><code>def power(b, p):
"""
Calculates b^p
Complexity O(log p)
b -> double
p -> integer
res -> double
"""
res = 1
while p:
if p & 0x1: res *= b
b *= b
p >>= 1
return res
<... | 1 | 2014-07-25T08:25:08Z | [
"python",
"algorithm",
"performance"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,019,826 | <p>Use the csv module as it is a real parser. Regular expressions are nonoptimal (or completely unsuited) for most things involving matching delimiters in which the rules change (I'm unsure as to whether this particular grammar is regular or not). You might be able to create a regex that would work in this case, but ... | 2 | 2009-06-19T20:09:50Z | [
"python",
"regex",
"split"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,019,902 | <p>Writing a state machine for this would, on the other hand, seem to be quite straightforward. DFAs and regexes have the same power, but usually one of them is better suited to the problem at hand, and is usually very dependent on the additional logic you might need to implement.</p>
| 1 | 2009-06-19T20:26:55Z | [
"python",
"regex",
"split"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,020,007 | <p>You can get close using non-greedy specifiers. The closest I've got is:</p>
<pre><code>>>> re.findall('(".*?"|.*?)(?:,|$)', '"a,b,c",d,e,f')
['"a,,b,c"', 'd', '', 'f', '']
</code></pre>
<p>But as you see, you end up with a redundant empty string at the end, which is indistinguishable from the result you... | 0 | 2009-06-19T21:00:49Z | [
"python",
"regex",
"split"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,020,098 | <p><strong>Here's a function that'll accomplish the task:</strong></p>
<pre><code>def smart_split(data, delimiter=","):
""" Performs splitting with string preservation. This reads both single and
double quoted strings.
"""
result = []
quote_type = None
buffer = ""
position = 0
while... | 0 | 2009-06-19T21:26:25Z | [
"python",
"regex",
"split"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,021,506 | <pre><code>re.split(',(?=(?:[^"]*"[^"]*")*[^"]*$)', str)
</code></pre>
<p>After matching a comma, if there's an odd number of quotation marks up ahead ahead, the comma must be inside a pair of quotation marks, so it doesn't count as a delimiter. Obviously this doesn't take the possibility of escaped quotation marks i... | 2 | 2009-06-20T12:14:01Z | [
"python",
"regex",
"split"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,021,866 | <p>Here's a really short function that will do the same thing:</p>
<pre><code>def split (aString):
splitByQuotes = (",%s,"%aString).split('"')
splitByQuotes[0::2] = [x.split(",")[1:-1] for x in splitByQuotes[0::2]]
return [a.strip() \
for b in splitByQuotes \
for a in (b if type(b)==list el... | 0 | 2009-06-20T15:38:27Z | [
"python",
"regex",
"split"
] |
split a string by a delimiter in a context sensitive way | 1,019,756 | <p>For example, I want to split</p>
<pre><code>str = '"a,b,c",d,e,f'
</code></pre>
<p>into </p>
<pre><code>["a,b,c",'d','e','f']
</code></pre>
<p>(i.e. don't split the quoted part) In this case, this can be done with </p>
<pre><code>re.findall('".*?"|[^,]+',str)
</code></pre>
<p>However, if</p>
<pre><code>str = ... | 2 | 2009-06-19T19:51:33Z | 1,021,945 | <p><a href="http://books.google.com/books?id=GX3w%5F18-JegC&lpg=PA401&ots=PHojQnfpRY&dq=comma-separated%20%22mastering%20regular%20expressions%22&pg=PA271" rel="nofollow">Page 271</a> of Friedl's <em>Mastering Regular Expressions</em> has a regular expression for extracting possibly quoted CSV fields, b... | 1 | 2009-06-20T16:21:35Z | [
"python",
"regex",
"split"
] |
Python tkInter Entry fun | 1,019,782 | <p>Playing around with Python - tkInter - Entry widget - when I use validatecommand (below), the check happens the first time the string > Max, but when I continue to enter text the check steps - there's no delete or insert after the first time? Any advice? (outside of not building a desktop app via python)</p>
<p><h... | 1 | 2009-06-19T19:58:15Z | 1,020,087 | <p>I'm sure exactly what the reason is, but I have a hunch. The validation check is done every time the entry is edited. I did some testing and found that it does indeed execute, and can do all sorts of things during the validation every time. What causes it to stop working correctly is when you edit it from within t... | 1 | 2009-06-19T21:25:00Z | [
"python",
"tkinter"
] |
Python tkInter Entry fun | 1,019,782 | <p>Playing around with Python - tkInter - Entry widget - when I use validatecommand (below), the check happens the first time the string > Max, but when I continue to enter text the check steps - there's no delete or insert after the first time? Any advice? (outside of not building a desktop app via python)</p>
<p><h... | 1 | 2009-06-19T19:58:15Z | 1,020,123 | <p><a href="http://www.tcl.tk/man/tcl8.4/TkCmd/entry.htm#M30" rel="nofollow">From the Tk man</a>:</p>
<blockquote>
<p>The validate option will also set itself to none when you edit the entry widget from within either the validateCommand or the invalidCommand. Such editions will override the one that was being valida... | 3 | 2009-06-19T21:32:54Z | [
"python",
"tkinter"
] |
Python tkInter Entry fun | 1,019,782 | <p>Playing around with Python - tkInter - Entry widget - when I use validatecommand (below), the check happens the first time the string > Max, but when I continue to enter text the check steps - there's no delete or insert after the first time? Any advice? (outside of not building a desktop app via python)</p>
<p><h... | 1 | 2009-06-19T19:58:15Z | 4,372,831 | <p>Here is a code sample that will limit the input to 5 characters:</p>
<pre><code>import Tkinter as tk
master = tk.Tk()
def callback():
print e.get()
def val(i):
print "validating"
print i
if int(i) > 4:
print "False"
return False
return True
vcmd = (master.register(val), '... | 2 | 2010-12-07T02:21:21Z | [
"python",
"tkinter"
] |
Subclassing in Python | 1,019,834 | <p>Is it possible to subclass dynamically? I know there's <strong>_<em>bases</em>_</strong> but I don't want to effect all instances of the class. I want the object cf to polymorph into a mixin of the DrvCrystalfontz class. Further into the hierarchy is a subclass of gobject that needs to be available at this level for... | -3 | 2009-06-19T20:11:03Z | 1,019,915 | <p>I'm not sure I'm clear on your desired use here, but it is possible to subclass dynamically. You can use the <code>type</code> object to dynamically construct a class given a name, tuple of base classes and dict of methods / class attributes, eg:</p>
<pre><code>>>> MySub = type("MySub", (DrvCrystalfontz, ... | 2 | 2009-06-19T20:29:59Z | [
"python",
"subclassing"
] |
Python - configuration options, how to input/handle? | 1,019,850 | <p>When your application takes a few (~ 5) configuration parameters, and the application is going
to be used by non-technology users (i.e. <a href="http://en.wiktionary.org/wiki/KISS" rel="nofollow">KISS</a>), how do you usually handle reading
configuration options, and then passing around the parameters between object... | 3 | 2009-06-19T20:16:15Z | 1,019,852 | <pre><code>"Counts answer"
Please update these counts and feel free to add/modify.
Do you usually read config options via:
- command-line/gui options : 1
- a config text file : 0
How do multiple modules/objects have access to these options?
- they receive them from the caller as an argument: 1
- read them dire... | 0 | 2009-06-19T20:17:00Z | [
"python",
"options",
"optional-parameters"
] |
Python - configuration options, how to input/handle? | 1,019,850 | <p>When your application takes a few (~ 5) configuration parameters, and the application is going
to be used by non-technology users (i.e. <a href="http://en.wiktionary.org/wiki/KISS" rel="nofollow">KISS</a>), how do you usually handle reading
configuration options, and then passing around the parameters between object... | 3 | 2009-06-19T20:16:15Z | 1,019,883 | <p>Do you usually read config options via:
- command-line/gui options
- a config text file </p>
<p>Both. We use Django's settings.py and logging.ini. We also use command-line options and arguments for the options that change most frequently.</p>
<p>How do multiple modules/objects have access to these options?... | 2 | 2009-06-19T20:23:47Z | [
"python",
"options",
"optional-parameters"
] |
How to walk up a linked-list using a list comprehension? | 1,020,037 | <p>I've been trying to think of a way to traverse a hierarchical structure, like a linked list, using a list expression, but haven't come up with anything that seems to work.</p>
<p>Basically, I want to convert this code:</p>
<pre><code>p = self.parent
names = []
while p:
names.append(p.name)
p = p.parent
print "... | 1 | 2009-06-19T21:12:29Z | 1,020,055 | <p>List comprehension works with objects that are iterators (have the next() method). You need to define an iterator for your structure in order to be able to iterate it this way.</p>
| 1 | 2009-06-19T21:17:15Z | [
"python",
"list-comprehension"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.