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 |
|---|---|---|---|---|---|---|---|---|---|
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,113,880 | <p>Python has a "we're all adults here" mentality. Thus, you'll find that Ruby has things like constants while Python doesn't (although Ruby's constants only raise a warning). The Python way of thinking is that if you want to make something constant, you should put the variable names in all caps and not change it.</p... | 19 | 2009-07-11T14:54:19Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,113,898 | <p>Ruby has sigils and twigils, Python doesn't.</p>
<p><strong>Edit</strong>: And one very important thing that I forgot (after all, the previous was just to flame a little bit :-p):</p>
<p>Python has a JIT compiler (<a href="http://psyco.sourceforge.net/" rel="nofollow">Psyco</a>), a sightly lower level language for... | 5 | 2009-07-11T15:01:16Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,114,449 | <p>Ruby has builtin continuation support using <code>callcc</code>.</p>
<p>Hence you can implement cool things like the <a href="http://www.randomhacks.net/articles/2005/10/11/amb-operator" rel="nofollow">amb-operator</a></p>
| 6 | 2009-07-11T19:19:11Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,114,453 | <p>Python has an explicit, builtin syntax for list-comprehenions and generators whereas in Ruby you would use map and code blocks.</p>
<p>Compare</p>
<pre><code>list = [ x*x for x in range(1, 10) ]
</code></pre>
<p>to</p>
<pre><code>res = (1..10).map{ |x| x*x }
</code></pre>
| 11 | 2009-07-11T19:20:50Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,114,457 | <p>I'm unsure of this, so I add it as an answer first.</p>
<h2>Python treats unbound methods as functions</h2>
<p>That means you can call a method either like <code>theobject.themethod()</code> or by <code>TheClass.themethod(anobject)</code>.</p>
<p>Edit: Although the difference between methods and functions is smal... | 8 | 2009-07-11T19:26:02Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,114,487 | <p><strong>Some others from:</strong></p>
<p><a href="http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/" rel="nofollow">http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/</a></p>
<p>(If I have misintrepreted anything or any of these have cha... | 9 | 2009-07-11T19:44:50Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,114,551 | <p>You can import only specific functions from a module in Python. In Ruby, you import the whole list of methods. You could "unimport" them in Ruby, but it's not what it's all about.</p>
<p>EDIT:</p>
<p>let's take this Ruby module :</p>
<pre><code>
module Whatever
def method1
end
def method2
end
end
</code>... | 18 | 2009-07-11T20:20:17Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,114,627 | <p>Ruby has a line by line loop over input files (the '-n' flag) from the commandline so it can be used like AWK. This Ruby one-liner: </p>
<pre><code>ruby -ne 'END {puts $.}'
</code></pre>
<p>will count lines like the AWK one-liner:</p>
<pre><code>awk 'END{print NR}'
</code></pre>
<p>Ruby gets feature this through... | 5 | 2009-07-11T20:57:24Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,117,852 | <h2>Python Example</h2>
<p>Functions are first-class variables in Python. You can declare a function, pass it around as an object, and overwrite it:</p>
<pre><code>def func(): print "hello"
def another_func(f): f()
another_func(func)
def func2(): print "goodbye"
func = func2
</code></pre>
<p>This is a fundamental ... | 28 | 2009-07-13T05:42:03Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,118,120 | <p>python has named optional arguments</p>
<pre><code>def func(a, b=2, c=3):
print a, b, c
>>> func(1)
1 2 3
>>> func(1, c=4)
1 2 4
</code></pre>
<p>AFAIK Ruby has only positioned arguments because b=2 in the function declaration is an affectation that always append.</p>
| 3 | 2009-07-13T07:33:41Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,118,733 | <p>"Variables that start with a capital letter becomes constants and can't be modified"</p>
<p>Wrong. They can.</p>
<p>You only get a warning if you do.</p>
| 11 | 2009-07-13T10:35:00Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,119,232 | <p>I would like to mention Python descriptor API that allows one customize object-to-attribute "communication". It is also noteworthy that, in Python, one is free to implement an alternative protocol via overriding the default given through the default implementation of the <code>__getattribute__</code> method.
Let me ... | 7 | 2009-07-13T12:46:18Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,120,798 | <p>Surprised to see nothing mentioned of ruby's "method missing" mechanism. I'd give examples of the find_by_... methods in Rails, as an example of the power of that language feature. My guess is that something similar could be implemented in Python, but to my knowledge it isn't there natively.</p>
| 3 | 2009-07-13T17:06:35Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,138,535 | <p>Ruby has embedded documentation:</p>
<pre><code> =begin
You could use rdoc to generate man pages from this documentation
=end
</code></pre>
| 2 | 2009-07-16T15:46:57Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,139,232 | <p>My python's rusty, so some of these may be in python and i just don't remember/never learned in the first place, but here are the first few that I thought of:</p>
<h3>Whitespace</h3>
<p>Ruby handles whitespace completely different. For starters, you don't need to indent anything (which means it doesn't matter if y... | 5 | 2009-07-16T17:53:47Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,139,857 | <p>I'd like to suggest a variant of the original question, "What does Ruby have that Python doesn't, and vice versa?" which admits the disappointing answer, "Well, what can you do with either Ruby or Python that can't be done in Intercal?" Nothing on that level, because Python and Ruby are both part of the vast royal f... | 12 | 2009-07-16T19:43:13Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,302,166 | <p>From Ruby's <a href="http://www.ruby-lang.org/en/documentation/ruby-from-other-languages/to-ruby-from-python/" rel="nofollow">website</a>:</p>
<p>Similarities
As with Python, in Ruby,...</p>
<blockquote>
<ul>
<li>Thereâs an interactive prompt (called irb).</li>
<li>You can read docs on the command line (wi... | 16 | 2009-08-19T19:32:19Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,573,879 | <p>Somewhat more on the infrastructure side:</p>
<ul>
<li><p>Python has much better integration with C++ (via things like <a href="http://www.boost.org/doc/libs/1%5F40%5F0/libs/python/doc/index.html" rel="nofollow">Boost.Python</a>, <a href="http://www.riverbankcomputing.com/software/sip/intro" rel="nofollow">SIP</a>,... | 11 | 2009-10-15T17:26:53Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 1,981,429 | <p>Another difference in lambdas between Python and Ruby is demonstrated by Paul Graham's <a href="http://www.paulgraham.com/accgen.html" rel="nofollow">Accumulator Generator</a> problem. Reprinted here:</p>
<blockquote>Write a function foo that takes a number n and returns a function that takes a number i, and retur... | 3 | 2009-12-30T17:45:19Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 2,043,465 | <p><a href="http://c2.com/cgi/wiki?PythonVsRuby" rel="nofollow">http://c2.com/cgi/wiki?PythonVsRuby</a><br>
<a href="http://c2.com/cgi/wiki?SwitchedFromPythonToRuby" rel="nofollow">http://c2.com/cgi/wiki?SwitchedFromPythonToRuby</a><br>
<a href="http://c2.com/cgi/wiki?SwitchedFromRubyToPython" rel="nofollow">http://c2.... | 2 | 2010-01-11T17:13:23Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 3,073,441 | <p><sub>Shamelessly copy/pasted from: <a href="http://stackoverflow.com/users/95810/alex-martelli">Alex Martelli</a> answer on <em>"<a href="http://groups.google.com/group/comp.lang.python/msg/028422d707512283" rel="nofollow">What's better about Ruby than Python</a>"</em> thread from <a href="http://groups.google.com/g... | 11 | 2010-06-18T22:24:35Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 3,397,341 | <blockquote>
<p>In Ruby, when you import a file with
require, all the things defined in
that file will end up in your global
namespace.</p>
</blockquote>
<p>With <a href="http://github.com/soveran/cargo" rel="nofollow">Cargo</a> you can "<em>require libraries without cluttering your namespace</em>".</p>
<pre>... | 2 | 2010-08-03T14:13:07Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 3,473,981 | <p>At this stage, Python still has better unicode support</p>
| 6 | 2010-08-13T04:50:20Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 4,102,608 | <p>Ultimately all answers are going to be subjective at some level, and the answers posted so far pretty much prove that you can't point to any one feature that isn't doable in the other language in an equally nice (if not similar) way, since both languages are very concise and expressive.</p>
<p>I like Python's synta... | 26 | 2010-11-05T00:24:23Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 4,104,294 | <p>I like the fundamental differences in the way that Ruby and Python method invocations operate.</p>
<p>Ruby methods are invoked via a form "message passing" and need not be explicitly first-class functions (there are ways to <a href="http://stackoverflow.com/questions/1933390/getting-ruby-function-object-itself">lif... | 1 | 2010-11-05T08:06:14Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 4,840,551 | <h2>Ruby gets inheritance right with Single Inheritance</h2>
<p>Did I mention Ruby has an EPIC community of developers. Ninja theme inspired by <a href="http://techoctave.com/c7/posts/46-object-oriented-ruby-classes-mixins-and-jedi" rel="nofollow">Object Oriented Ruby: Classes, Mixins and Jedi</a>.</p>
<p>Ruby gets i... | -3 | 2011-01-30T01:15:14Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 4,916,756 | <p>Syntax is not a minor thing, it has a direct impact on how we think. It also has a direct effect on the rules we create for the systems we use. As an example we have the order of operations because of the way we write mathematical equations or sentences. The standard notation for mathematics allows people to read... | 4 | 2011-02-06T22:49:27Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 5,089,827 | <p>I am surprised that no one has mentioned Singleton methods.</p>
<pre><code>a=[]
b=[]
def b.some_method do ... end
b.some_method #fine
a.some_method #raises exception
</code></pre>
<p>It gives granular control over the open class concept. You can also use Eigenclasses to mixin a module into a specific object instea... | -2 | 2011-02-23T10:45:49Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 5,109,018 | <p>The nested lexical scope example that someone gave gives several benefits.</p>
<ol>
<li>"Safer" globals</li>
<li>It is one method to embed DSL's into your program. </li>
</ol>
<p>I think that is a very good example of the differences between the two languages. Ruby is simply more flexible. Python can be flexible, ... | 0 | 2011-02-24T18:43:50Z | [
"python",
"ruby"
] |
What does Ruby have that Python doesn't, and vice versa? | 1,113,611 | <p>There is a lot of discussions of Python vs Ruby, and I all find them completely unhelpful, because they all turn around why feature X sucks in language Y, or that claim language Y doesn't have X, although in fact it does. I also know exactly why I prefer Python, but that's also subjective, and wouldn't help anybody ... | 264 | 2009-07-11T12:24:26Z | 5,560,856 | <h2>More about Ruby's blocks</h2>
<p>It has being suggested that Ruby's blocks may be "substituted" by Python's context managers. In fact, blocks allow more than Python's context managers can do.</p>
<p>The receiving method of a block could execute the block within the context of some object, thus allowing the block ... | 0 | 2011-04-06T02:32:44Z | [
"python",
"ruby"
] |
Python/mod_wsgi server global data | 1,113,736 | <p>I have been looking into different systems for creating a fast cache in a web-farm running Python/mod_wsgi. Memcache and others are options ... But I was wondering:</p>
<p>Because I don't need to share data across machines, wanting each machine to maintain a local cache ...</p>
<p>Does Python or WSGI provide a mec... | 3 | 2009-07-11T13:36:58Z | 1,113,984 | <p>There's Django's thread-safe in-memory cache back-end, see <a href="http://code.djangoproject.com/browser/django/trunk/django/core/cache/backends/locmem.py" rel="nofollow">here</a>. It's cPickle-based, and although it's designed for use with Django, it has minimal dependencies on the rest of Django and you could eas... | 1 | 2009-07-11T15:45:03Z | [
"python",
"apache",
"caching",
"mod-wsgi"
] |
Python/mod_wsgi server global data | 1,113,736 | <p>I have been looking into different systems for creating a fast cache in a web-farm running Python/mod_wsgi. Memcache and others are options ... But I was wondering:</p>
<p>Because I don't need to share data across machines, wanting each machine to maintain a local cache ...</p>
<p>Does Python or WSGI provide a mec... | 3 | 2009-07-11T13:36:58Z | 1,113,991 | <p>This is thoroughly covered by the <a href="http://code.google.com/p/modwsgi/wiki/ProcessesAndThreading" rel="nofollow">Sharing and Global Data section</a> of the mod_wsgi documentation. The short answer is: No, not unless you run everything in one process, but that's not an ideal solution.</p>
<p>It should be noted... | 2 | 2009-07-11T15:47:36Z | [
"python",
"apache",
"caching",
"mod-wsgi"
] |
Python/mod_wsgi server global data | 1,113,736 | <p>I have been looking into different systems for creating a fast cache in a web-farm running Python/mod_wsgi. Memcache and others are options ... But I was wondering:</p>
<p>Because I don't need to share data across machines, wanting each machine to maintain a local cache ...</p>
<p>Does Python or WSGI provide a mec... | 3 | 2009-07-11T13:36:58Z | 6,079,193 | <p>I realize this is an old thread, but here's another option for a "server-wide dict": <a href="http://poshmodule.sourceforge.net/posh/html/posh.html" rel="nofollow">http://poshmodule.sourceforge.net/posh/html/posh.html</a> (POSH, Python Shared Objects). Disclaimer: haven't used it myself yet.</p>
| 0 | 2011-05-21T02:15:52Z | [
"python",
"apache",
"caching",
"mod-wsgi"
] |
Is it possible to pass a variable out of a pdb session into the original interactive session? | 1,114,080 | <p>I am using pdb to examine a script having called <code>run -d</code> in an ipython session.
It would be useful to be able to plot some of the variables but I need them in the main ipython environment in order to do that. </p>
<p>So what I am looking for is some way to make a variable available back in the main int... | 2 | 2009-07-11T16:37:10Z | 1,114,472 | <p>Per ipython's <a href="http://ipython.scipy.org/moin/Documentation" rel="nofollow">docs</a>, and also a <code>run?</code> command from the ipython prompt,</p>
<blockquote>
<p>after execution, the IPython
interactive namespace gets
updated with all variables defined in the program (except for <code>__name_... | 2 | 2009-07-11T19:37:58Z | [
"python",
"debugging",
"ipython"
] |
How do I check if a process is alive in Python on Linux? | 1,114,312 | <p>I have a process id in Python. I know I can kill it with os.kill(), but how do I check if it is alive ? Is there a built-in function or do I have to go to the shell?</p>
| 1 | 2009-07-11T18:11:18Z | 1,114,332 | <p>Use <code>subprocess</code> module to spawn process.
There is <strong>proc.poll()</strong> function - it returns <code>None</code> if process is still alive, otherwise it returns process returncode.</p>
<p><strong><a href="http://docs.python.org/library/subprocess.html" rel="nofollow">http://docs.python.org/library... | 14 | 2009-07-11T18:19:24Z | [
"python",
"process"
] |
How do I check if a process is alive in Python on Linux? | 1,114,312 | <p>I have a process id in Python. I know I can kill it with os.kill(), but how do I check if it is alive ? Is there a built-in function or do I have to go to the shell?</p>
| 1 | 2009-07-11T18:11:18Z | 1,114,435 | <p><code>os.kill</code> does not kill processes, it sends them signals (it's poorly named).</p>
<p>If you send signal 0, you can determine whether you are allowed to send other signals. An error code will indicate whether it's a permission problem or a missing process.</p>
<p>See <code>man 2 kill</code> for more inf... | 12 | 2009-07-11T19:12:22Z | [
"python",
"process"
] |
How to set default button in PyGTK? | 1,114,568 | <p>I have very simple window where I have 2 buttons - one for cancel, one for apply. How to set the button for apply as default one? (When I press enter, "apply" button is pressed)</p>
<p>However, I want to set focus to the first input widget (I can't use grab_focus() on the button)</p>
<p>Any suggestions?</p>
<p><s... | 5 | 2009-07-11T20:30:34Z | 1,114,892 | <p><a href="http://www.pygtk.org/docs/pygtk/class-gtkdialog.html#method-gtkdialog--set-default-response" rel="nofollow">http://www.pygtk.org/docs/pygtk/class-gtkdialog.html#method-gtkdialog--set-default-response</a></p>
<p><a href="http://www.pygtk.org/docs/pygtk/class-gtkwindow.html#method-gtkwindow--set-default" rel... | 4 | 2009-07-11T23:12:19Z | [
"python",
"user-interface",
"pygtk"
] |
Does main.py or app.yaml determine the URL used by the App Engine cron task in this example? | 1,114,601 | <p>In this sample code the URL of the app seems to be determined by this line within the app:</p>
<pre><code>application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True)
</code></pre>
<p>but also by this line within the app handler of app.yaml:</p>
<pre><code>- url: /.*
script: main.py
</code></pre>
... | 1 | 2009-07-11T20:42:05Z | 1,114,615 | <p>Looks like you're reading <a href="http://basbrun.com/?p=101" rel="nofollow">this page</a> (even though you don't give us the URL). The configuration and code as presented won't run successfully: the cron task will try to visit URL path /tasks/summary, app.yaml will make that execute main.py, but the latter only set... | 1 | 2009-07-11T20:48:59Z | [
"python",
"google-app-engine",
"cron",
"url-routing"
] |
Does main.py or app.yaml determine the URL used by the App Engine cron task in this example? | 1,114,601 | <p>In this sample code the URL of the app seems to be determined by this line within the app:</p>
<pre><code>application = webapp.WSGIApplication([('/mailjob', MailJob)], debug=True)
</code></pre>
<p>but also by this line within the app handler of app.yaml:</p>
<pre><code>- url: /.*
script: main.py
</code></pre>
... | 1 | 2009-07-11T20:42:05Z | 1,114,651 | <p>You could do it like this:</p>
<pre><code>app.yaml
application: yourappname
version: 1
runtime: python
api_version: 1
handlers:
- url: /tasks/.*
script: main.py
cron.yaml
cron:
- description: daily mailing job
url: /tasks/summary
schedule: every 24 hours
main.py
#!/usr/bin/env python
import cgi... | 3 | 2009-07-11T21:15:13Z | [
"python",
"google-app-engine",
"cron",
"url-routing"
] |
Making a Makefile | 1,114,667 | <p>How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?</p>
| 2 | 2009-07-11T21:23:09Z | 1,114,683 | <p>I use Makefiles for some Python projects, but this is highly dubious... I do things like:</p>
<pre><code>SITE_ROOT=/var/www/apache/...
site_dist:
cp -a assets/css build/$(SITE_ROOT)/css
cp -a src/public/*.py build/$(SITE_ROOT)
</code></pre>
<p>and so on. Makefile are nothing but batch execution systems ... | 6 | 2009-07-11T21:29:58Z | [
"c++",
"python",
"c",
"makefile"
] |
Making a Makefile | 1,114,667 | <p>How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?</p>
| 2 | 2009-07-11T21:23:09Z | 1,114,687 | <p>A simple <code>Makefile</code> usually consists of a set of targets, its dependencies, and the actions performed by each target:</p>
<pre><code>all: output.out
output.out: dependency.o dependency2.o
ld -o output.out dependency.o dependency2.o
dependency.o: dependency.c
gcc -o dependency.o dependency.c
de... | 4 | 2009-07-11T21:31:12Z | [
"c++",
"python",
"c",
"makefile"
] |
Making a Makefile | 1,114,667 | <p>How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?</p>
| 2 | 2009-07-11T21:23:09Z | 1,114,692 | <p>From your question it sounds like a tutorial or an overview of what Makefiles actually do might benefit you.</p>
<p>A good places to start is the <a href="http://www.gnu.org/software/make/manual/make.html" rel="nofollow">GNU Make</a> documentation.</p>
<p>It includes the following overview "The make utility automa... | 11 | 2009-07-11T21:34:01Z | [
"c++",
"python",
"c",
"makefile"
] |
Making a Makefile | 1,114,667 | <p>How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?</p>
| 2 | 2009-07-11T21:23:09Z | 1,114,730 | <blockquote>
<p>How i can make a MakeFile, because it's the best way when you distribuite a program by source code</p>
</blockquote>
<p>It's not. For example, KDE uses <a href="http://www.cmake.org/" rel="nofollow">CMake</a>, and Wesnoth uses <a href="http://www.scons.org/" rel="nofollow">SCons</a>. I would suggest ... | 4 | 2009-07-11T21:51:35Z | [
"c++",
"python",
"c",
"makefile"
] |
Making a Makefile | 1,114,667 | <p>How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?</p>
| 2 | 2009-07-11T21:23:09Z | 1,114,870 | <p>If you are asking about a portable form of creating Makefiles you can try to look at <a href="http://www.cmake.org/cmake/project/about.html" rel="nofollow">http://www.cmake.org/cmake/project/about.html</a></p>
| 1 | 2009-07-11T22:58:09Z | [
"c++",
"python",
"c",
"makefile"
] |
Making a Makefile | 1,114,667 | <p>How I can make a Makefile, because it's the best way when you distribute a program by source code. Remember that this is for a C++ program and I'm starting in the C development world. But is it possible to make a Makefile for my Python programs?</p>
| 2 | 2009-07-11T21:23:09Z | 1,115,223 | <p>For Python programs, they're usually distributed with a <code>setup.py</code> script which uses <code>distutils</code> in order to build the software. <code>distutils</code> has extensive <a href="http://docs.python.org/distutils/" rel="nofollow">documentation</a> which should be a good starting point.</p>
| 3 | 2009-07-12T03:06:30Z | [
"c++",
"python",
"c",
"makefile"
] |
PyQt Automatic Repeating Forms | 1,114,678 | <p>I'm currently attempting to migrate a legacy VBA/Microsoft Access application to Python and PyQt. I've had no problems migrating any of the logic, and most of the forms have been a snap, as well. However, I've hit a problem on the most important part of the application--the main data-entry form.</p>
<p>The form is ... | 2 | 2009-07-11T21:27:16Z | 1,115,236 | <p>You should look into QSqlTableModel, and the QTableView Objects. QSqlTableModel offers an abstraction of a relational table that can be used inside on of the Qt view classes. A QTableView for example. The functionality you describe can be implemented with moderate effort just by using these two classes. </p>
<p>The... | 3 | 2009-07-12T03:18:32Z | [
"python",
"qt",
"qt4",
"pyqt",
"pyqt4"
] |
Django Model Inheritance And Foreign Keys | 1,114,767 | <p>Basically, I have a model where I've created a superclass that many other classes share, and then each of those classes has some unique features that differ from each other. Let's say class A is the superclass, and class B, C, and D are children of that class.</p>
<p>Both class B and class C can have multiples of c... | 8 | 2009-07-11T22:03:55Z | 1,114,806 | <p>I see a problem here:</p>
<pre><code>class D(A):
#D has foreign key to either B or C, but not both.
</code></pre>
<p>Can't do it. You'll have to add both because in SQL columns must be defined exactly.</p>
<p>Also even though inherited models like you have compile with <code>syncdb</code> - they don't seem to... | 1 | 2009-07-11T22:25:30Z | [
"python",
"django",
"inheritance",
"django-models",
"foreign-keys"
] |
Django Model Inheritance And Foreign Keys | 1,114,767 | <p>Basically, I have a model where I've created a superclass that many other classes share, and then each of those classes has some unique features that differ from each other. Let's say class A is the superclass, and class B, C, and D are children of that class.</p>
<p>Both class B and class C can have multiples of c... | 8 | 2009-07-11T22:03:55Z | 1,115,171 | <p>From the <a href="http://docs.djangoproject.com/en/dev/topics/db/models/#one-to-one-relationships" rel="nofollow">Django Docs</a>:</p>
<blockquote>
<p>For example, if you were building a
database of "places", you would build
pretty standard stuff such as address,
phone number, etc. in the database.
Then, ... | 3 | 2009-07-12T02:19:31Z | [
"python",
"django",
"inheritance",
"django-models",
"foreign-keys"
] |
Django Model Inheritance And Foreign Keys | 1,114,767 | <p>Basically, I have a model where I've created a superclass that many other classes share, and then each of those classes has some unique features that differ from each other. Let's say class A is the superclass, and class B, C, and D are children of that class.</p>
<p>Both class B and class C can have multiples of c... | 8 | 2009-07-11T22:03:55Z | 1,116,508 | <p>You could also do a generic relation <a href="http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1" rel="nofollow">http://docs.djangoproject.com/en/dev/ref/contrib/contenttypes/#id1</a> and check the types to constrain it to B or C when setting or saving. This is probably more work than figuring out t... | 1 | 2009-07-12T17:43:32Z | [
"python",
"django",
"inheritance",
"django-models",
"foreign-keys"
] |
Django Model Inheritance And Foreign Keys | 1,114,767 | <p>Basically, I have a model where I've created a superclass that many other classes share, and then each of those classes has some unique features that differ from each other. Let's say class A is the superclass, and class B, C, and D are children of that class.</p>
<p>Both class B and class C can have multiples of c... | 8 | 2009-07-11T22:03:55Z | 4,004,118 | <p>One way to do this is to add an intermediate class as follows:</p>
<pre><code>class A(Model):
class Meta(Model.Meta):
abstract = True
# common definitions here
class Target(A):
# this is the target for links from D - you then need to access the
# subclass through ".b" or ".c"
# (no fie... | 1 | 2010-10-23T13:15:07Z | [
"python",
"django",
"inheritance",
"django-models",
"foreign-keys"
] |
Does "from-import" exec the whole module? | 1,114,787 | <p>OK, so I know that <code>from-import</code> is "exactly" the same as <code>import</code>, except that it's obviously not because namespaces are populated differently.</p>
<p>My question is primarily motivated because I have a <code>utils</code> module which has one or two functions that are used by every other modu... | 1 | 2009-07-11T22:15:28Z | 1,114,809 | <p>Yes, <code>from MODULE import OBJECT</code> executes everything in the module and then effectively does <code>OBJECT = MODULE.OBJECT</code>. You can tell that the module has already been loaded, in a sense, because now it resides in the <a href="http://www.diveintopython.org/file%5Fhandling/more%5Fon%5Fmodules.html"... | 1 | 2009-07-11T22:25:47Z | [
"python",
"logging",
"import"
] |
Does "from-import" exec the whole module? | 1,114,787 | <p>OK, so I know that <code>from-import</code> is "exactly" the same as <code>import</code>, except that it's obviously not because namespaces are populated differently.</p>
<p>My question is primarily motivated because I have a <code>utils</code> module which has one or two functions that are used by every other modu... | 1 | 2009-07-11T22:15:28Z | 1,114,822 | <p>Looks like like the answer is yes:</p>
<pre><code>$ echo 'print "test"
def f1():
print "f1"
def f2():
print "f2"
' > util.py
$ echo 'from util import f1
f1()
from util import f2
f2()
' > test.py
$ python test.py
test
f1
f2
$
</code></pre>
| 5 | 2009-07-11T22:30:21Z | [
"python",
"logging",
"import"
] |
Does "from-import" exec the whole module? | 1,114,787 | <p>OK, so I know that <code>from-import</code> is "exactly" the same as <code>import</code>, except that it's obviously not because namespaces are populated differently.</p>
<p>My question is primarily motivated because I have a <code>utils</code> module which has one or two functions that are used by every other modu... | 1 | 2009-07-11T22:15:28Z | 1,115,073 | <p>The answer to your question is yes. </p>
<p>For a good explanation of the import process, please see Frederik Lundh's "<a href="http://effbot.org/zone/import-confusion.htm" rel="nofollow">Importing Python Modules</a>". </p>
<p>In particular, I'll quote the sections that answer your query.</p>
<blockquote>
<p>... | 6 | 2009-07-12T01:10:35Z | [
"python",
"logging",
"import"
] |
Does "from-import" exec the whole module? | 1,114,787 | <p>OK, so I know that <code>from-import</code> is "exactly" the same as <code>import</code>, except that it's obviously not because namespaces are populated differently.</p>
<p>My question is primarily motivated because I have a <code>utils</code> module which has one or two functions that are used by every other modu... | 1 | 2009-07-11T22:15:28Z | 1,115,552 | <p>As mentioned above, yes.
And you can write simple test to be sure:</p>
<pre><code># file m.py
import sys
# define function
def f():
pass
#execute this when module is loaded (i.e. imported or run as script)
print 'imported', __name__
# print all "exposed" variables to make sure that the f is visible
print dir(... | 0 | 2009-07-12T08:19:33Z | [
"python",
"logging",
"import"
] |
Python converts string into tuple | 1,114,813 | <p>Example:</p>
<pre><code>regular_string = "%s %s" % ("foo", "bar")
result = {}
result["somekey"] = regular_string,
print result["somekey"]
# ('foo bar',)
</code></pre>
<p>Why <code>result["somekey"]</code> tuple now not string?</p>
| 3 | 2009-07-11T22:27:47Z | 1,114,820 | <p>Because of comma at the end of the line.</p>
| 16 | 2009-07-11T22:30:10Z | [
"python"
] |
Python converts string into tuple | 1,114,813 | <p>Example:</p>
<pre><code>regular_string = "%s %s" % ("foo", "bar")
result = {}
result["somekey"] = regular_string,
print result["somekey"]
# ('foo bar',)
</code></pre>
<p>Why <code>result["somekey"]</code> tuple now not string?</p>
| 3 | 2009-07-11T22:27:47Z | 1,114,837 | <p>When you write</p>
<pre><code>result["somekey"] = regular_string,
</code></pre>
<p>Python reads</p>
<pre><code>result["somekey"] = (regular_string,)
</code></pre>
<p><code>(x,)</code> is the syntax for a tuple with a single element. Parentheses are assumed. And you really end up putting a tuple, instead of a str... | 9 | 2009-07-11T22:39:06Z | [
"python"
] |
Determine proxy type | 1,115,039 | <p>I have the following code to download a URL through a proxy:</p>
<pre><code>proxy_handler = urllib2.ProxyHandler({'http': p})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req = urllib2.Request(url)
sock = urllib2.urlopen(req)
</code></pre>
<p>How can I use Python to determine the typ... | 3 | 2009-07-12T00:49:18Z | 1,115,081 | <blockquote>
<p>One solution would be to use an external server</p>
</blockquote>
<p>You must have a server of some sort.</p>
<p>The best option you can hope of doing is to host your own web server and print the headers to see if it is leaking any variables.</p>
| 1 | 2009-07-12T01:16:31Z | [
"python",
"proxy",
"anonymous"
] |
Determine proxy type | 1,115,039 | <p>I have the following code to download a URL through a proxy:</p>
<pre><code>proxy_handler = urllib2.ProxyHandler({'http': p})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req = urllib2.Request(url)
sock = urllib2.urlopen(req)
</code></pre>
<p>How can I use Python to determine the typ... | 3 | 2009-07-12T00:49:18Z | 1,115,871 | <p>Do you mean retrieving the current proxy configuration?<br />
You can with urllib.getproxies:</p>
<pre><code>import urllib
urllib.getproxies()
{'http': 'http://your_proxy_servername:8080'}
</code></pre>
<p>Note: I was not able to find any documentation about urllib.getproxies. I am using Python 2.5, and it just wo... | -1 | 2009-07-12T11:35:12Z | [
"python",
"proxy",
"anonymous"
] |
Sorting disk I/O errors in Python | 1,115,203 | <p>How do I sort out (distinguish) an error derived from a "disk full condition" from "trying to write to a read-only file system"?
I don't want to fill my HD to find out :)
What I want is to know who to catch each exception, so my code can say something to the user when he is trying to write to a ReadOnly FS and anoth... | 2 | 2009-07-12T02:48:05Z | 1,115,214 | <p>On a read-only filesystem, the files themselves will be marked as read-only. Any attempt to <code>open</code> a read-only file for writing (<code>O_WRONLY</code> or <code>O_RDWR</code>) will fail. On UNIX-like systems, the errno <code>EACCES</code> will be set.</p>
<pre>
>>> file('/etc/resolv.conf', 'a')
Tracebac... | 2 | 2009-07-12T02:59:58Z | [
"python",
"exception"
] |
Sorting disk I/O errors in Python | 1,115,203 | <p>How do I sort out (distinguish) an error derived from a "disk full condition" from "trying to write to a read-only file system"?
I don't want to fill my HD to find out :)
What I want is to know who to catch each exception, so my code can say something to the user when he is trying to write to a ReadOnly FS and anoth... | 2 | 2009-07-12T02:48:05Z | 1,115,216 | <p>Once you catch <code>IOError</code>, e.g. with an <code>except IOError, e:</code> clause in Python 2.*, you can examine <code>e.errno</code> to find out exactly what kind of I/O error it was (unfortunately in a way that's not necessarily fully portable among different operating systems).</p>
<p>See the <a href="htt... | 7 | 2009-07-12T03:01:12Z | [
"python",
"exception"
] |
Django Model Sync Table | 1,115,238 | <p>If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?</p>
| 4 | 2009-07-12T03:21:13Z | 1,115,252 | <p>Alas, Django does not support any easy solution to this. </p>
<p>The only thing django will do for you, is restart your database with new tables that match your new models:</p>
<pre><code>$ #DON'T DO THIS UNLESS YOU CAN AFFORD TO LOSE ALL YOUR DATA!
$ python PROJECT_DIR/manage.py syncdb
</code></pre>
<p>the next... | 6 | 2009-07-12T03:33:47Z | [
"python",
"database",
"django",
"django-models",
"synchronization"
] |
Django Model Sync Table | 1,115,238 | <p>If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?</p>
| 4 | 2009-07-12T03:21:13Z | 1,115,271 | <p><a href="http://code.google.com/p/django-evolution/" rel="nofollow">Django Evolution</a> can help, but the best option really is to plan out your schema in advance, or to make simple modifications manually. Or, to be willing to toast your test data by dropping tables and re-syncing.</p>
| 3 | 2009-07-12T03:48:49Z | [
"python",
"database",
"django",
"django-models",
"synchronization"
] |
Django Model Sync Table | 1,115,238 | <p>If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?</p>
| 4 | 2009-07-12T03:21:13Z | 1,115,369 | <p>Django does not provide for this out of the box.</p>
<p>Here's some information from the Django Book on <a href="http://www.djangobook.com/en/1.0/chapter05/" rel="nofollow">doing it by hand</a> (see Making Changes to a Database Schema). This works for straightforward, simple changes.</p>
<p>Longer-term, you'll pro... | 2 | 2009-07-12T05:17:00Z | [
"python",
"database",
"django",
"django-models",
"synchronization"
] |
Django Model Sync Table | 1,115,238 | <p>If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?</p>
| 4 | 2009-07-12T03:21:13Z | 1,117,089 | <p>Just to throw in an extra opinion - dmigrations is pretty nice and clear to use, but I'd say South is your best bet. Again, it's easy to get into, but it's more powerful and also has support for more database backends than just MySQL. It even handles MSSQL, if that's your thing</p>
| 0 | 2009-07-12T22:24:36Z | [
"python",
"database",
"django",
"django-models",
"synchronization"
] |
Django Model Sync Table | 1,115,238 | <p>If I change a field in a Django model, how can I synchronize it with the database tables? Do I need to do it manually on the database or is there a tool that does helps with the process?</p>
| 4 | 2009-07-12T03:21:13Z | 1,232,838 | <p>Can't seem to be able to add a comment to the marked answer, probably because I haven't got enough rep (be nice if SO told me so though).</p>
<p>Anyway, just wanted to add that in the answered post, I believe it is wrong about syncdb - syncdb does <strong>not</strong> touch tables once they have been created and ha... | 4 | 2009-08-05T12:08:03Z | [
"python",
"database",
"django",
"django-models",
"synchronization"
] |
Cost of len() function | 1,115,313 | <p>What is the cost of <a href="https://docs.python.org/2/library/functions.html#len"><code>len()</code></a> function for Python built-ins? (list/tuple/string/dictionary)</p>
| 106 | 2009-07-12T04:31:02Z | 1,115,329 | <p>It's <strong>O(1)</strong> (very fast) on every type you've mentioned, plus <code>set</code> and others such as <code>array.array</code>.</p>
| 109 | 2009-07-12T04:40:31Z | [
"python",
"algorithm",
"collections",
"complexity-theory"
] |
Cost of len() function | 1,115,313 | <p>What is the cost of <a href="https://docs.python.org/2/library/functions.html#len"><code>len()</code></a> function for Python built-ins? (list/tuple/string/dictionary)</p>
| 106 | 2009-07-12T04:31:02Z | 1,115,349 | <p>Calling len() on those data types is O(1) in <a href="http://www.python.org">CPython</a>, the most common implementation of the Python language. Here's a link to a table that provides the algorithmic complexity of many different functions in CPython:</p>
<p><a href="http://wiki.python.org/moin/TimeComplexity">TimeC... | 97 | 2009-07-12T04:59:44Z | [
"python",
"algorithm",
"collections",
"complexity-theory"
] |
Cost of len() function | 1,115,313 | <p>What is the cost of <a href="https://docs.python.org/2/library/functions.html#len"><code>len()</code></a> function for Python built-ins? (list/tuple/string/dictionary)</p>
| 106 | 2009-07-12T04:31:02Z | 1,115,382 | <p>The below measurements provide evidence that <code>len()</code> is O(1) for oft-used data structures. </p>
<p>A note regarding <code>timeit</code>: When the <code>-s</code> flag is used and two strings are passed to <code>timeit</code> the first string is executed only once and is not timed.</p>
<h3>List:</h3>
<... | 33 | 2009-07-12T05:34:28Z | [
"python",
"algorithm",
"collections",
"complexity-theory"
] |
Cost of len() function | 1,115,313 | <p>What is the cost of <a href="https://docs.python.org/2/library/functions.html#len"><code>len()</code></a> function for Python built-ins? (list/tuple/string/dictionary)</p>
| 106 | 2009-07-12T04:31:02Z | 1,115,401 | <p>All those objects keep track of their own length. The time to extract the length is small (O(1) in big-O notation) and mostly consists of [rough description, written in Python terms, not C terms]: look up "len" in a dictionary and dispatch it to the built_in len function which will look up the object's <code>__len__... | 19 | 2009-07-12T06:17:13Z | [
"python",
"algorithm",
"collections",
"complexity-theory"
] |
Static methods and thread safety | 1,115,420 | <p>In python with all this idea of "Everything is an object" where is thread-safety?</p>
<p>I am developing django website with wsgi. Also it would work in linux, and as I know they use effective process management, so we could not think about thread-safety alot. I am not doubt in how module loads, and there functions... | 2 | 2009-07-12T06:32:23Z | 1,115,427 | <p>Functions in a module are equivalent to static methods in a class. The issue of thread safety arises when multiple threads may be modifying shared data, or even one thread may be modifying such data while others are reading it; it's best avoided by making data be owned by ONE module (accessed via Queue.Queue from ot... | 7 | 2009-07-12T06:40:47Z | [
"python",
"django",
"thread-safety"
] |
Static methods and thread safety | 1,115,420 | <p>In python with all this idea of "Everything is an object" where is thread-safety?</p>
<p>I am developing django website with wsgi. Also it would work in linux, and as I know they use effective process management, so we could not think about thread-safety alot. I am not doubt in how module loads, and there functions... | 2 | 2009-07-12T06:32:23Z | 1,115,756 | <p>See the <a href="http://docs.python.org/c-api/init.html#thread-state-and-the-global-interpreter-lock" rel="nofollow">python documentation</a> to better understand the general thread safety implications of Python.</p>
<p>Django itself seems to be <a href="http://code.djangoproject.com/wiki/DjangoSpecifications/Core/... | 0 | 2009-07-12T10:33:33Z | [
"python",
"django",
"thread-safety"
] |
Google App Engine: how to unescape POST body? | 1,116,066 | <p>Newbie question...</p>
<p>I am using silverlight to POST data to my GAE application</p>
<pre><code> class XmlCrud(webapp.RequestHandler):
def post(self):
body = self.request.body
</code></pre>
<p>The data comes in fine but it is escaped like this:</p>
<pre><code>%3C%3Fxml+version=%221.0%22+encoding%3... | 2 | 2009-07-12T13:44:24Z | 1,116,109 | <p>I'd recommend not encoding it in the first place if the body of the post is just an XML document.</p>
| 0 | 2009-07-12T14:18:41Z | [
"python",
"google-app-engine"
] |
Google App Engine: how to unescape POST body? | 1,116,066 | <p>Newbie question...</p>
<p>I am using silverlight to POST data to my GAE application</p>
<pre><code> class XmlCrud(webapp.RequestHandler):
def post(self):
body = self.request.body
</code></pre>
<p>The data comes in fine but it is escaped like this:</p>
<pre><code>%3C%3Fxml+version=%221.0%22+encoding%3... | 2 | 2009-07-12T13:44:24Z | 1,116,119 | <p>I agree with Hank.</p>
<p>The answer to your actual question, though, is that your example is URL encoded. To decode, replace each %XX with the character having hex value 0xXX, and + with space.</p>
<p><code>urllib.unquote_plus</code> does this, and according to the docs it's in App Engine</p>
<p>urllib docs: <a ... | 3 | 2009-07-12T14:25:46Z | [
"python",
"google-app-engine"
] |
python windows directory mtime: how to detect package directory new file? | 1,116,144 | <p>I'm working on an auto-reload feature for WHIFF
<a href="http://whiff.sourceforge.net" rel="nofollow">http://whiff.sourceforge.net</a>
(so you have to restart the HTTP server less often, ideally never).</p>
<p>I have the following code to reload a package module "location"
if a file is added to the package director... | 0 | 2009-07-12T14:43:28Z | 1,116,166 | <p>you can try using getatime() instead.</p>
| 0 | 2009-07-12T14:54:39Z | [
"python",
"windows-xp"
] |
python windows directory mtime: how to detect package directory new file? | 1,116,144 | <p>I'm working on an auto-reload feature for WHIFF
<a href="http://whiff.sourceforge.net" rel="nofollow">http://whiff.sourceforge.net</a>
(so you have to restart the HTTP server less often, ideally never).</p>
<p>I have the following code to reload a package module "location"
if a file is added to the package director... | 0 | 2009-07-12T14:43:28Z | 1,116,246 | <p>I'm not understanding your question completely...</p>
<p>Are you calling getmtime() on a directory or an individual file?</p>
| 0 | 2009-07-12T15:31:19Z | [
"python",
"windows-xp"
] |
python windows directory mtime: how to detect package directory new file? | 1,116,144 | <p>I'm working on an auto-reload feature for WHIFF
<a href="http://whiff.sourceforge.net" rel="nofollow">http://whiff.sourceforge.net</a>
(so you have to restart the HTTP server less often, ideally never).</p>
<p>I have the following code to reload a package module "location"
if a file is added to the package director... | 0 | 2009-07-12T14:43:28Z | 1,117,571 | <p>long time no see. I'm not sure exactly what you're doing, but the equivalent of your code:</p>
<pre><code>GET_MODULE_FUNCTION = """
def f():
import %(parent)s
try:
from %(parent)s import %(child)s
except ImportError:
# one more time...
reload(%(parent)s)
from %(parent)s i... | 2 | 2009-07-13T03:11:17Z | [
"python",
"windows-xp"
] |
python windows directory mtime: how to detect package directory new file? | 1,116,144 | <p>I'm working on an auto-reload feature for WHIFF
<a href="http://whiff.sourceforge.net" rel="nofollow">http://whiff.sourceforge.net</a>
(so you have to restart the HTTP server less often, ideally never).</p>
<p>I have the following code to reload a package module "location"
if a file is added to the package director... | 0 | 2009-07-12T14:43:28Z | 1,121,799 | <p>There are two things about your first code snippet that concern me:</p>
<ul>
<li><p>You cast the float from getmtime to int. Dependening on the frequency this code is run, you might get unreliable results.</p></li>
<li><p>At the end of the code you assign dir_mtime to a variable md_mtime. fn_mtime, which you check ... | 0 | 2009-07-13T20:17:01Z | [
"python",
"windows-xp"
] |
python program choice | 1,116,163 | <p>My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB.</p>
<p>There are two main steps and two threads:</p>
<ol>
<li>ICAPServer receives data from clients, puts the data in a queue (50kb <1ms);</li>
<li>another thread pops data from the queue, ... | 0 | 2009-07-12T14:54:01Z | 1,116,170 | <p>Put an upper limit on the amount of data in the queue?</p>
| 0 | 2009-07-12T14:59:42Z | [
"python",
"sqlalchemy",
"twisted"
] |
python program choice | 1,116,163 | <p>My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB.</p>
<p>There are two main steps and two threads:</p>
<ol>
<li>ICAPServer receives data from clients, puts the data in a queue (50kb <1ms);</li>
<li>another thread pops data from the queue, ... | 0 | 2009-07-12T14:54:01Z | 1,116,224 | <p>It is hard to say for sure, but perhaps using two processes instead of threads will help in this situation. Since Python has the Global Interpreter Lock (GIL), it has the effect of only allowing any one thread to execute Python instructions at any time. </p>
<p>Having a system designed around processes might have t... | 2 | 2009-07-12T15:22:35Z | [
"python",
"sqlalchemy",
"twisted"
] |
python program choice | 1,116,163 | <p>My program is ICAPServer (similar with httpserver), it's main job is to receive data from clients and save the data to DB.</p>
<p>There are two main steps and two threads:</p>
<ol>
<li>ICAPServer receives data from clients, puts the data in a queue (50kb <1ms);</li>
<li>another thread pops data from the queue, ... | 0 | 2009-07-12T14:54:01Z | 1,116,586 | <p>One note: before going for optimizations, it is very important to get some good measurement, and profiling.</p>
<p>That said, I would bet the slow part in the second step is database communication; you could try to analyze the SQL statement and its execution plan. and then optimize it (it is one of the <a href="htt... | 0 | 2009-07-12T18:16:55Z | [
"python",
"sqlalchemy",
"twisted"
] |
Finding content between two words withou RegEx, BeautifulSoup, lXml ... etc | 1,116,172 | <p>How to find out the content between two words or two sets of random characters?</p>
<p>The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can't remove the JavaScript.</p>
<p>consider this:</p>
<pre><code><html>
<body>
<div>StartYYYY ... | 1 | 2009-07-12T15:00:38Z | 1,116,180 | <p>Well, this is what it would be in PHP. No doubt there's a much sexier Pythonic way.</p>
<pre><code>function FindBetweenText($before, $after, $text) {
$before_pos = strpos($text, $before);
if($before_pos === false)
return null;
$after_pos = strpos($text, $after);
if($after_pos === false || $... | 0 | 2009-07-12T15:04:39Z | [
"python",
"screen-scraping",
"fetch"
] |
Finding content between two words withou RegEx, BeautifulSoup, lXml ... etc | 1,116,172 | <p>How to find out the content between two words or two sets of random characters?</p>
<p>The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can't remove the JavaScript.</p>
<p>consider this:</p>
<pre><code><html>
<body>
<div>StartYYYY ... | 1 | 2009-07-12T15:00:38Z | 1,116,219 | <p>if you are sure your markers are unique, do something like this</p>
<pre><code>s="""
<html>
<body>
<div>StartYYYY "Extract HTML", ENDYYYY
</body>
Some Java Scripts code STARTXXXX "Extract JS Code" ENDXXXX.
</html>
"""
def FindBetweenText(startMarker, endMarker, text):
startPos ... | 2 | 2009-07-12T15:18:04Z | [
"python",
"screen-scraping",
"fetch"
] |
Finding content between two words withou RegEx, BeautifulSoup, lXml ... etc | 1,116,172 | <p>How to find out the content between two words or two sets of random characters?</p>
<p>The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can't remove the JavaScript.</p>
<p>consider this:</p>
<pre><code><html>
<body>
<div>StartYYYY ... | 1 | 2009-07-12T15:00:38Z | 1,116,220 | <p>[Slightly tested]</p>
<pre><code>def bracketed_find_first(prefix, suffix, page, start=0):
prefixpos = page.find(prefix, start)
if prefixpos == -1: return None # NOT ""
startpos = prefixpos + len(prefix)
endpos = page.find(suffix, startpos) # DRY
if endpos == -1: return None # NOT ""
return p... | 0 | 2009-07-12T15:18:05Z | [
"python",
"screen-scraping",
"fetch"
] |
Finding content between two words withou RegEx, BeautifulSoup, lXml ... etc | 1,116,172 | <p>How to find out the content between two words or two sets of random characters?</p>
<p>The scraped page is not guaranteed to be Html only and the important data can be inside a javascript block. So, I can't remove the JavaScript.</p>
<p>consider this:</p>
<pre><code><html>
<body>
<div>StartYYYY ... | 1 | 2009-07-12T15:00:38Z | 1,116,243 | <p>Here's my attempt, this is tested. While recursive, there should be no unnecessary string duplication, although a generator might be more optimal</p>
<pre><code>def bracketed_find(s, start, end, startat=0):
startloc=s.find(start, startat)
if startloc==-1:
return []
endloc=s.find(end, startloc+len(... | 0 | 2009-07-12T15:29:56Z | [
"python",
"screen-scraping",
"fetch"
] |
Retrieve cookie created using javascript in python | 1,116,362 | <p>I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?</p>
| 1 | 2009-07-12T16:25:38Z | 1,116,402 | <p>Maybe you can execute the JavaScript code in a JavaScript engine with Python bindings (like <a href="http://github.com/davisp/python-spidermonkey/tree/master" rel="nofollow">python-spidermonkey</a> or <a href="http://code.google.com/p/pyv8/" rel="nofollow">pyv8</a>) and then retrieve the cookie. Or, as the javascrip... | 0 | 2009-07-12T16:47:09Z | [
"python",
"cookies",
"urllib2",
"cookiejar"
] |
Retrieve cookie created using javascript in python | 1,116,362 | <p>I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?</p>
| 1 | 2009-07-12T16:25:38Z | 1,116,524 | <p>You could access the page using a real browser, via <a href="http://pamie.sourceforge.net/" rel="nofollow">PAMIE</a>, <a href="http://sourceforge.net/projects/pywin32/" rel="nofollow">win32com</a> or similar, then the JavaScript will be running in its native environment.</p>
| 0 | 2009-07-12T17:52:35Z | [
"python",
"cookies",
"urllib2",
"cookiejar"
] |
Retrieve cookie created using javascript in python | 1,116,362 | <p>I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?</p>
| 1 | 2009-07-12T16:25:38Z | 1,116,535 | <p>If all pages have the same JavaScript then maybe you could parse the HTML to find that piece of code, and from that get the value the cookie would be set to? </p>
<p>That would make your scraping quite vulnerable to changes in the third party website, but that's most often the case while scraping. (Please bear in m... | 3 | 2009-07-12T17:55:59Z | [
"python",
"cookies",
"urllib2",
"cookiejar"
] |
Retrieve cookie created using javascript in python | 1,116,362 | <p>I've had a look at many tutorials regarding cookiejar, but my problem is that the webpage that i want to scape creates the cookie using javascript and I can't seem to retrieve the cookie. Does anybody have a solution to this problem?</p>
| 1 | 2009-07-12T16:25:38Z | 1,118,077 | <p>I responded to your <a href="http://stackoverflow.com/questions/1117491/fake-a-cookie-to-scrape-a-site-in-python/1118060#1118060">other question</a> as well: take a look at <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a>. It's probably the most fully featured scraping module I kno... | 1 | 2009-07-13T07:19:38Z | [
"python",
"cookies",
"urllib2",
"cookiejar"
] |
Should I use Unicode string by default? | 1,116,449 | <p>Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case w... | 17 | 2009-07-12T17:13:22Z | 1,116,476 | <p>From my practice -- use unicode. </p>
<p>At beginning of one project we used usuall strings, however our project was growing, we were implementing new features and using new third-party libraries. In that mess with non-unicode/unicode string some functions started failing. We started spending time localizing this p... | 17 | 2009-07-12T17:31:49Z | [
"python",
"unicode"
] |
Should I use Unicode string by default? | 1,116,449 | <p>Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case w... | 17 | 2009-07-12T17:13:22Z | 1,116,487 | <p>If you are dealing with severely constrained memory or disk space, use ASCII strings. In this case, you should additionally write your software in C or something even more compact :)</p>
| 2 | 2009-07-12T17:38:16Z | [
"python",
"unicode"
] |
Should I use Unicode string by default? | 1,116,449 | <p>Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case w... | 17 | 2009-07-12T17:13:22Z | 1,116,546 | <p>As you ask this question, I suppose you are using Python 2.x. </p>
<p>Python 3.0 changed quite a lot in string representation, and all text now is unicode.<br />
I would go for unicode in any new project - in a way compatible with the switch to Python 3.0 (see <a href="http://docs.python.org/3.0/whatsnew/3.0.html#... | 13 | 2009-07-12T17:59:19Z | [
"python",
"unicode"
] |
Should I use Unicode string by default? | 1,116,449 | <p>Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case w... | 17 | 2009-07-12T17:13:22Z | 1,116,549 | <p>Additional to Mihails comment I would say: Use Unicode, since it is the future. In Python 3.0, Non-Unicode will be gone, and as much I know, all the "U"-Prefixes will make trouble, since they are also gone.</p>
| 4 | 2009-07-12T17:59:48Z | [
"python",
"unicode"
] |
Should I use Unicode string by default? | 1,116,449 | <p>Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case w... | 17 | 2009-07-12T17:13:22Z | 1,116,581 | <p>It can be tricky to consistently use unicode strings in Python 2.x - be it because somebody inadvertently uses the more natural <code>str(blah)</code> where they meant <code>unicode(blah)</code>, forgetting the <code>u</code> prefix on string literals, third-party module incompatibilities - whatever. So in Python 2.... | 5 | 2009-07-12T18:15:26Z | [
"python",
"unicode"
] |
Should I use Unicode string by default? | 1,116,449 | <p>Is it considered as a good practice to pick Unicode string over regular string when coding in Python? I mainly work on the Windows platform, where most of the string types are Unicode these days (i.e. .NET String, '_UNICODE' turned on by default on a new c++ project, etc ). Therefore, I tend to think that the case w... | 17 | 2009-07-12T17:13:22Z | 1,116,660 | <p>Yes, use unicode. </p>
<p>Some hints:</p>
<ol>
<li><p>When doing input output in any sort of binary format, decode directly after reading and encode directly before writing, so that you never need to mix strings and unicode. Because mixing that tends to lead to UnicodeEncodeDecodeErrors sooner or later.</p></li>
<... | 13 | 2009-07-12T18:54:32Z | [
"python",
"unicode"
] |
What's the point of this code pattern? | 1,116,693 | <p>I was trying to create a python wrapper for an tk extension, so I looked at Tkinter.py to learn how to do it. </p>
<p>While looking at that file, I found the following pattern appears a lot of times: an internal method (hinted by the leading "_" in the method name) is defined, then a public method is defined just t... | 3 | 2009-07-12T19:21:21Z | 1,116,701 | <p><a href="http://www.python.org/dev/peps/pep-0008/" rel="nofollow">From PEP8</a></p>
<p>In addition, the following special forms using leading or trailing
underscores are recognized (these can generally be combined with any case
convention):</p>
<blockquote>
<p>_single_leading_underscore: weak
"internal... | 2 | 2009-07-12T19:26:07Z | [
"python"
] |
What's the point of this code pattern? | 1,116,693 | <p>I was trying to create a python wrapper for an tk extension, so I looked at Tkinter.py to learn how to do it. </p>
<p>While looking at that file, I found the following pattern appears a lot of times: an internal method (hinted by the leading "_" in the method name) is defined, then a public method is defined just t... | 3 | 2009-07-12T19:21:21Z | 1,116,702 | <p>Well, I'm supposing, there could be <em>another</em> internal callable, that could've been used, it just didn't make it to the version you have. Generally, I think it is a good idea - you expose one symbol publically and internally it can be anything, a real method, a stubbed out method, a debug version of the metho... | 1 | 2009-07-12T19:26:10Z | [
"python"
] |
What's the point of this code pattern? | 1,116,693 | <p>I was trying to create a python wrapper for an tk extension, so I looked at Tkinter.py to learn how to do it. </p>
<p>While looking at that file, I found the following pattern appears a lot of times: an internal method (hinted by the leading "_" in the method name) is defined, then a public method is defined just t... | 3 | 2009-07-12T19:21:21Z | 1,116,705 | <p>Sometimes, you may want to change a method's behavior. For example, I could do this (hypothetically within the Misc class):</p>
<pre><code>def _another_register(self, func, subst=None, needcleanup=1):
...
def change_register(self):
self.register = self._another_register
def restore_register(self):
se... | 8 | 2009-07-12T19:27:26Z | [
"python"
] |
Calculating formulae in Excel with Python | 1,116,725 | <p>I would like to insert a calculation in Excel using Python.
Generally it can be done by inserting a formula string into the relevant cell.
However, if i need to calculate a formula multiple times for the whole column
the formula must be updated for each individual cell. For example, if i need to
calculate the sum o... | 1 | 2009-07-12T19:36:54Z | 1,116,782 | <p>If you are using COM bindings, then you can simply record a macro in Excel, then translate it into Python code.<br />
If you are using xlwt, you have to resort to normal loops in python..</p>
| 0 | 2009-07-12T20:02:31Z | [
"python",
"excel",
"formula"
] |
Calculating formulae in Excel with Python | 1,116,725 | <p>I would like to insert a calculation in Excel using Python.
Generally it can be done by inserting a formula string into the relevant cell.
However, if i need to calculate a formula multiple times for the whole column
the formula must be updated for each individual cell. For example, if i need to
calculate the sum o... | 1 | 2009-07-12T19:36:54Z | 1,116,827 | <p>As <a href="http://stackoverflow.com/questions/1116725/calculating-formulae-in-excel-with-python/1116782#1116782">Roberto </a> mentions, you can use <strong><a href="http://pypi.python.org/pypi/xlwt" rel="nofollow">xlwt</a></strong> and a trusty for-loop:</p>
<pre><code>import xlwt
w = xlwt.Workbook()
ws = w.add_s... | 3 | 2009-07-12T20:19:39Z | [
"python",
"excel",
"formula"
] |
Calculating formulae in Excel with Python | 1,116,725 | <p>I would like to insert a calculation in Excel using Python.
Generally it can be done by inserting a formula string into the relevant cell.
However, if i need to calculate a formula multiple times for the whole column
the formula must be updated for each individual cell. For example, if i need to
calculate the sum o... | 1 | 2009-07-12T19:36:54Z | 1,183,609 | <p>Sasha, </p>
<p>Python code translated from your macro would look like this:</p>
<pre><code>startCell = mySheet.Range("M6")
wholeRange = mySheet.Range("M6:M592")
startCell.FormulaR1C1 = "=R[-1]C[-7]/RC[-10]*R[-1]C"
startCell.AutoFill(Destination=wholeRange)
</code></pre>
<p>Haven't tested it, but I write this ofte... | 0 | 2009-07-26T02:48:08Z | [
"python",
"excel",
"formula"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.