title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
Inserting a WAV at a certain point in an audio file using python
2,435,961
<p>My problem is the following: I have a 2-minute long WAV file, and my aim is to insert another WAV file (7 seconds long), at a certain point in the first WAV file (say, 0:48), essentially combining the two WAVs, using python. Unfortunately I haven't been able to figure out how to do that, and was wondering if there w...
2
2010-03-12T21:17:49Z
2,604,706
<p>Loosely based on the code by Justin, here is some other code that probably does what you want:</p> <pre><code>import wave, audioop def merge_wav_at_offset(wav_in1, wav_in2, offset, wav_out): """Merge two wave files, with the second wave starting at offset seconds The two input wave files should have the sa...
1
2010-04-09T02:12:30Z
[ "python", "audio" ]
Inserting a WAV at a certain point in an audio file using python
2,435,961
<p>My problem is the following: I have a 2-minute long WAV file, and my aim is to insert another WAV file (7 seconds long), at a certain point in the first WAV file (say, 0:48), essentially combining the two WAVs, using python. Unfortunately I haven't been able to figure out how to do that, and was wondering if there w...
2
2010-03-12T21:17:49Z
5,915,360
<p>use the <a href="http://pydub.com" rel="nofollow">pydub package</a> (full disclosure - I wrote it)</p> <pre><code>from pydub import AudioSegment sound1 = AudioSegment.from_wav('your_wave.mp3') the_wave = AudioSegment.from_wav('the_7sec_wave.wav') sound_with_wave = sound1.overlay(the_wave, position=48*1000) sound...
1
2011-05-06T18:12:48Z
[ "python", "audio" ]
How do I do advanced Python hash autovivification?
2,435,989
<p>This question is about implementing the full Perl autovivification in Python. I know similar questions were asked before and so far the best answer is in "<a href="http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/652284#652284">What is the best way to implemen...
9
2010-03-12T21:24:17Z
2,436,002
<pre><code>a = collections.defaultdict(lambda: collections.defaultdict(list)) </code></pre>
15
2010-03-12T21:26:17Z
[ "python", "data-structures", "autovivification" ]
How do I do advanced Python hash autovivification?
2,435,989
<p>This question is about implementing the full Perl autovivification in Python. I know similar questions were asked before and so far the best answer is in "<a href="http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/652284#652284">What is the best way to implemen...
9
2010-03-12T21:24:17Z
2,604,348
<p>Perhaps this solves your need for any number of “dimensions” in your dictionary:</p> <pre><code>a= collections.defaultdict(list) </code></pre> <p>the only change in your code being:</p> <pre><code>a['x', 'y'].append('z') </code></pre> <p>Of course, this solution being the one you want depends on two conditio...
2
2010-04-09T00:23:36Z
[ "python", "data-structures", "autovivification" ]
How do I do advanced Python hash autovivification?
2,435,989
<p>This question is about implementing the full Perl autovivification in Python. I know similar questions were asked before and so far the best answer is in "<a href="http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/652284#652284">What is the best way to implemen...
9
2010-03-12T21:24:17Z
10,519,069
<p>Since we don't know beforehand if we need a dictionary, or a list, then you can't combine autovivification with lists. Unless, Working off of Nosklo's answer from the linked question, you add list "features" to the underlying dictionary. Basically assuming a "sort" order for keys, and always using it with the list m...
1
2012-05-09T15:19:29Z
[ "python", "data-structures", "autovivification" ]
How do I do advanced Python hash autovivification?
2,435,989
<p>This question is about implementing the full Perl autovivification in Python. I know similar questions were asked before and so far the best answer is in "<a href="http://stackoverflow.com/questions/635483/what-is-the-best-way-to-implement-nested-dictionaries-in-python/652284#652284">What is the best way to implemen...
9
2010-03-12T21:24:17Z
12,152,015
<p>Just expanding on Ignacio's answer to present some additional options that allow you to explicitly request more magical behaviour from Python dictionaries. The maintainability of code written this way remains dubious, but I wanted to make it crystal clear that it is a question of "Is this kind of data structure main...
0
2012-08-28T02:26:50Z
[ "python", "data-structures", "autovivification" ]
resolving overloads in boost.python
2,436,067
<p>I have a C++ class like this: </p> <pre><code>class ConnectionBase { public: ConnectionBase(); template &lt;class T&gt; Publish(const T&amp;); private: virtual void OnEvent(const Overload_a&amp;) {} virtual void OnEvent(const Overload_b&amp;) {} }; </code></pre> <p>My templates &amp; overloads are...
1
2010-03-12T21:36:13Z
2,436,374
<p>Creating C++ virtual functions that can be overridden in Python requires some work - see <a href="http://www.boost.org/doc/libs/1_42_0/libs/python/doc/tutorial/doc/html/python/exposing.html#python.class_virtual_functions" rel="nofollow">here</a>. You will need to create a wrapper function in a derived class that cal...
2
2010-03-12T22:42:37Z
[ "c++", "python", "boost", "boost-python" ]
Desktop Application Development with Javascript, Python / Ruby
2,436,078
<p>Besides using Appcelerator's Titanium Desktop, are there other approaches to integrating Javascript and Ruby/Python into cross-platform desktop applications? Just trying to get a sense of the landscape here. From searching the web, it seems Titanium may be leading the charge in terms of this type of integration. ...
4
2010-03-12T21:38:20Z
2,436,100
<p>There is <a href="http://pyjd.org/" rel="nofollow">Pyjamas Desktop</a>, but might be a bit out of date.</p>
2
2010-03-12T21:44:23Z
[ "javascript", "python", "ruby", "desktop-application" ]
Desktop Application Development with Javascript, Python / Ruby
2,436,078
<p>Besides using Appcelerator's Titanium Desktop, are there other approaches to integrating Javascript and Ruby/Python into cross-platform desktop applications? Just trying to get a sense of the landscape here. From searching the web, it seems Titanium may be leading the charge in terms of this type of integration. ...
4
2010-03-12T21:38:20Z
2,450,910
<p>You can also script Swing or SWT with JRuby, either directly, or via one of the numerous <a href="http://kenai.com/projects/jruby/pages/GUIFrameworks" rel="nofollow">frameworks</a>.<br> You might manage to integrate protovis via a webkit or gecko (like <a href="http://github.com/danlucraft/redcar" rel="nofollow">red...
0
2010-03-15T22:28:50Z
[ "javascript", "python", "ruby", "desktop-application" ]
Python library for creating stubs/fake objects
2,436,220
<p>I am looking for python stubbing library. Something that could be used to create fake classes/methods in my unit tests.. Is there a simple way to achieve it in python..</p> <p>Thanks</p> <p>PS: I am not looking for mocking library where you would record and replay expectation.</p> <p><a href="http://martinfowler....
1
2010-03-12T22:06:50Z
2,436,240
<p><a href="http://labix.org/mocker" rel="nofollow">Python mocker</a> looks nice.</p> <blockquote> <p>A Mocker instance is used to command recording and replaying of expectations on any number of mock objects.</p> </blockquote>
0
2010-03-12T22:09:59Z
[ "python", "testing", "mocking", "stub" ]
Python library for creating stubs/fake objects
2,436,220
<p>I am looking for python stubbing library. Something that could be used to create fake classes/methods in my unit tests.. Is there a simple way to achieve it in python..</p> <p>Thanks</p> <p>PS: I am not looking for mocking library where you would record and replay expectation.</p> <p><a href="http://martinfowler....
1
2010-03-12T22:06:50Z
2,436,254
<p>We do this.</p> <pre><code>class FakeSomethingOrOther( object ): def __init__( self ): self._count_me= 0 def method_required_by_test( self ): return self.special_answer_required_by_test def count_this_method( self, *args, *kw ): self._count_me += 1 </code></pre> <p>It doesn't take muc...
5
2010-03-12T22:13:56Z
[ "python", "testing", "mocking", "stub" ]
When to use weak references in Python?
2,436,302
<p>Can anyone explain usage of weak references?</p> <p>The <a href="http://docs.python.org/library/weakref.html" rel="nofollow">documentation</a> doesn't explain it precisely, it just says that the GC can destroy the object linked to via a weak reference at any time. Then what's the point of having an object that can ...
23
2010-03-12T22:25:20Z
2,436,352
<p>The typical use for weak references is if A has a reference to B and B has a reference to A. Without a proper cycle-detecting garbage collector, those two objects would never get GC'd even if there are no references to either from the "outside". However if one of the references is "weak", the objects will get proper...
15
2010-03-12T22:36:56Z
[ "python", "weak-references" ]
When to use weak references in Python?
2,436,302
<p>Can anyone explain usage of weak references?</p> <p>The <a href="http://docs.python.org/library/weakref.html" rel="nofollow">documentation</a> doesn't explain it precisely, it just says that the GC can destroy the object linked to via a weak reference at any time. Then what's the point of having an object that can ...
23
2010-03-12T22:25:20Z
14,922,132
<p>Events are a common scenario for weak references.</p> <hr> <h1>Problem</h1> <p>Consider a pair of objects: Emitter and Receiver. The receiver has shorter lifetime than the emitter.</p> <p>You could try an implementation like this:</p> <pre><code>class Emitter(object): def __init__(self): self.liste...
15
2013-02-17T14:30:33Z
[ "python", "weak-references" ]
Why do we have callable objects in python?
2,436,578
<p>What is the purpose of a callable object? What problems do they solve?</p>
8
2010-03-12T23:39:42Z
2,436,587
<p>They take parameters and return a result depending on those parameters.</p> <p>A <em>callable</em> is just an abstract form of a function resp an interface that defines that an object acts like a function (i.e. accepts parameters).</p> <p>As functions are first class objects, it is obvious that functions are calla...
6
2010-03-12T23:43:58Z
[ "python", "callable" ]
Why do we have callable objects in python?
2,436,578
<p>What is the purpose of a callable object? What problems do they solve?</p>
8
2010-03-12T23:39:42Z
2,436,614
<p>Many kinds of objects are callable in Python, and they can serve many purposes:</p> <ul> <li>functions are callable, and they may carry along a "closure" from an outer function</li> <li>classes are callable, and calling a class gets you an instance of that class</li> <li>methods are callable, for function-like beha...
12
2010-03-12T23:53:37Z
[ "python", "callable" ]
Why do we have callable objects in python?
2,436,578
<p>What is the purpose of a callable object? What problems do they solve?</p>
8
2010-03-12T23:39:42Z
2,436,639
<p>There are areas, especially in the 'functions calling functions of function functions' where objects allow less nesting. </p> <p>Consider making a classic decorator that checks an authorization level before calling a function. Using it is clear:</p> <pre><code>@check_authorization(level="Manager") def update_pr...
1
2010-03-13T00:00:56Z
[ "python", "callable" ]
How to use re match objects in a list comprehension
2,436,607
<p>I have a function to pick out lumps from a list of strings and return them as another list:</p> <pre><code>def filterPick(lines,regex): result = [] for l in lines: match = re.search(regex,l) if match: result += [match.group(1)] return result </code></pre> <p>Is there a way t...
30
2010-03-12T23:51:02Z
2,436,623
<pre><code>[m.group(1) for l in lines for m in [regex.search(l)] if m] </code></pre> <p>The "trick" is the <code>for m in [regex.search(l)]</code> part -- that's how you "assign" a value that you need to use more than once, within a list comprehension -- add just such a clause, where the object "iterates" over a singl...
55
2010-03-12T23:56:25Z
[ "python", "regex", "list-comprehension" ]
How to use re match objects in a list comprehension
2,436,607
<p>I have a function to pick out lumps from a list of strings and return them as another list:</p> <pre><code>def filterPick(lines,regex): result = [] for l in lines: match = re.search(regex,l) if match: result += [match.group(1)] return result </code></pre> <p>Is there a way t...
30
2010-03-12T23:51:02Z
2,436,626
<pre><code>return [m.group(1) for m in (re.search(regex, l) for l in lines) if m] </code></pre>
8
2010-03-12T23:56:41Z
[ "python", "regex", "list-comprehension" ]
How to use re match objects in a list comprehension
2,436,607
<p>I have a function to pick out lumps from a list of strings and return them as another list:</p> <pre><code>def filterPick(lines,regex): result = [] for l in lines: match = re.search(regex,l) if match: result += [match.group(1)] return result </code></pre> <p>Is there a way t...
30
2010-03-12T23:51:02Z
2,436,628
<p>It could be shortened a little</p> <pre><code>def filterPick(lines, regex): matches = map(re.compile(regex).match, lines) return [m.group(1) for m in matches if m] </code></pre> <p>You could put it all in one line, but that would mean you would have to match every line twice which would be a bit less effic...
3
2010-03-12T23:57:17Z
[ "python", "regex", "list-comprehension" ]
How to use re match objects in a list comprehension
2,436,607
<p>I have a function to pick out lumps from a list of strings and return them as another list:</p> <pre><code>def filterPick(lines,regex): result = [] for l in lines: match = re.search(regex,l) if match: result += [match.group(1)] return result </code></pre> <p>Is there a way t...
30
2010-03-12T23:51:02Z
13,433,589
<pre><code>&gt;&gt;&gt; "a" in "a visit to the dentist" True &gt;&gt;&gt; "a" not in "a visit to the dentist" False </code></pre> <p>That also works with a search query you're hunting down in a list</p> <p>`P='a', 'b', 'c'</p> <p>'b' in P` returns true</p>
-11
2012-11-17T18:41:00Z
[ "python", "regex", "list-comprehension" ]
Python decoding issue with hashlib.digest() method
2,436,621
<p>Hello StackOverflow community,</p> <p>Using Google App Engine, I wrote a keyToSha256() method within a model class (extending db.Model) :</p> <pre><code>class Car(db.Model): def keyToSha256(self): keyhash = hashlib.sha256(str(self.key())).digest() return keyhash </code></pre> <p>When displayin...
0
2010-03-12T23:56:20Z
2,436,631
<p>Use <code>.hexdigest()</code> instead.</p>
4
2010-03-12T23:57:31Z
[ "python", "google-app-engine", "decode" ]
Name some non-trivial sites written using IronPython & Silverlight
2,436,714
<p>Just what the title says. It'd be nice to know a few non-trivial sites out there using <a href="http://ironpython.codeplex.com/wikipage?title=SilverlightInteractiveSession&amp;referringTitle=Home" rel="nofollow">Silverlight in Python</a>.</p>
4
2010-03-13T00:25:24Z
2,436,902
<p>My current job is writing business apps for a German / Swiss media media consortium using IronPython and Silverlight. We're gradually moving all our web apps over to IronPython / Silverlight as they are faster to build, look nicer and perform better than the Javascript equivalents.</p> <p>Definitely not trivial, bu...
2
2010-03-13T01:30:42Z
[ "python", "silverlight", "ironpython", "website" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
2,436,736
<p>That'd be <a href="http://pypi.python.org/pypi/setuptools" rel="nofollow">easy_install</a>.</p>
4
2010-03-13T00:31:31Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
2,436,743
<p>It's called setuptools. You run it with the "easy_install" command.</p> <p>You can find the directory at <a href="http://pypi.python.org/" rel="nofollow">http://pypi.python.org/</a></p>
4
2010-03-13T00:32:51Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
2,436,746
<p>And just to provide a contrast, there's also <a href="http://pypi.python.org/pypi/pip">pip</a>.</p>
60
2010-03-13T00:33:40Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
2,436,747
<p>There are at least two, <a href="http://peak.telecommunity.com/DevCenter/EasyInstall" rel="nofollow">easy_install</a> and its successor <a href="http://pypi.python.org/pypi/pip" rel="nofollow">pip</a>.</p>
10
2010-03-13T00:34:03Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
2,436,904
<p>As a Ruby and Perl developer and learning-Python guy, I haven't found easy_install or pip to be the equivalent to RubyGems or CPAN. </p> <p>I tend to keep my development systems running the latest versions of modules as the developers update them, and freeze my production systems at set versions. Both RubyGems and ...
19
2010-03-13T01:31:21Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
12,234,724
<p><strong>The Python Package Index (PyPI)</strong> seems to be standard:</p> <ul> <li>To <strong>install</strong> a package: <code>pip install MyProject</code></li> <li>To <strong>update</strong> a package <code>pip install --upgrade MyProject</code></li> <li>To <strong>fix a version</strong> of a package <code>pip i...
54
2012-09-02T09:13:00Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
13,445,719
<h1>Recent progress</h1> <p><strong>March 2014</strong>: Good news! <a href="https://docs.python.org/3/whatsnew/3.4.html">Python 3.4</a> ships with Pip. Pip has long been Python's de-facto standard package manager. You can install <a href="https://pypi.python.org/pypi/httpie">a package</a> like this:</p> <pre><code>p...
169
2012-11-18T23:27:38Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
14,289,650
<p>I don't see either <a href="http://en.wikipedia.org/wiki/MacPorts" rel="nofollow">MacPorts</a> or <a href="http://mxcl.github.com/homebrew/" rel="nofollow">Homebrew</a> mentioned in other answers here, but since I do see them mentioned elsewhere on Stack&nbsp;Overflow for related questions, I'll add my own US$0.02 t...
2
2013-01-12T02:40:49Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
24,086,318
<p>On Windows install <a href="http://chocolatey.org/" rel="nofollow">http://chocolatey.org/</a> then </p> <pre><code>choco install python </code></pre> <p>Open a new cmd-window with the updated PATH. Next, do</p> <pre><code>choco install pip </code></pre> <p>After that you can</p> <pre><code>pip install pyside pi...
2
2014-06-06T16:11:16Z
[ "python", "module" ]
Does Python have a package/module management system?
2,436,731
<p>Does Python have a package/module management system, similar to how Ruby has rubygems where you can do <code>gem install packagename</code>?</p> <p>On <em><a href="http://docs.python.org/install/index.html">Installing Python Modules</a></em>, I only see references to <code>python setup.py install</code>, but that r...
110
2010-03-13T00:29:17Z
27,536,915
<p>As of at least late 2014, <a href="https://store.continuum.io/cshop/anaconda/" rel="nofollow">Continuum Analytics' Anaconda</a> Python distribution with the <a href="http://www.continuum.io/blog/conda" rel="nofollow">conda</a> package manager should be considered. It solves most of the serious issues people run into...
6
2014-12-17T23:47:29Z
[ "python", "module" ]
How would I start integrating pyflakes with Hudson
2,436,787
<p>We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong."</p>
7
2010-03-13T00:46:18Z
2,436,865
<p>The Violations plugin requires xml output from the various checkers that it supports. </p> <p>I'm not familiar with pyflakes, but from my brief scan, it doesn't appear to support xml as an output type. So you'll have to post-process the pyflakes output before letting Violations try to parse it (or you could modify ...
1
2010-03-13T01:15:37Z
[ "python", "continuous-integration", "hudson", "pylint", "pyflakes" ]
How would I start integrating pyflakes with Hudson
2,436,787
<p>We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong."</p>
7
2010-03-13T00:46:18Z
5,426,251
<p>You can adapt pyflakes and pep8 output to work with the Violations pylint plugin.</p> <pre><code>pyflakes path/to/src | awk -F\: '{printf "%s:%s: [E]%s\n", $1, $2, $3}' &gt; violations.pyflakes.txt pep8 path/to/src | awk -F\: '{printf "%s:%s: [%s]%s\n", $1, $2, substr($4,2,4), substr($4,6)}' &gt; violations.pep8.t...
4
2011-03-24T22:16:45Z
[ "python", "continuous-integration", "hudson", "pylint", "pyflakes" ]
How would I start integrating pyflakes with Hudson
2,436,787
<p>We use Hudson for continuous integration with the Violations Plugin which parses our output from pylint. However, pylint is a bit too strict, and hard to configure. What we'd rather use is pyflakes which would give us the right level of "You're doing it wrong."</p>
7
2010-03-13T00:46:18Z
34,396,655
<blockquote> <p>The Violations plugin requires xml output from the various checkers</p> </blockquote> <p>This is wrong: Some checkers like "checkstyle" output XML, some others like "pylint" and "pep8" output "text" files with one record per line. The heading in Jenkins "XML filename pattern" is plain misleading.</p>...
0
2015-12-21T13:18:04Z
[ "python", "continuous-integration", "hudson", "pylint", "pyflakes" ]
How to calculate next Friday at 3am?
2,436,840
<p>How can you calculate the following Friday at 3am as a <code>datetime</code> object?</p> <p><strong>Clarification:</strong> i.e., the calculated date should always be greater than 7 days away, and less than or equal to 14.</p> <hr> <p>Going with a slightly modified version of <a href="http://stackoverflow.com/que...
11
2010-03-13T01:02:16Z
2,436,868
<p>If you install <a href="http://labix.org/python-dateutil">dateutil</a>, then you could do something like this:</p> <pre><code>import datetime import dateutil.relativedelta as reldate def following_friday(dt): rd=reldate.relativedelta( weekday=reldate.FR(+2), hours=+21) rd2=reldate.relati...
9
2010-03-13T01:16:46Z
[ "python", "date-arithmetic" ]
How to calculate next Friday at 3am?
2,436,840
<p>How can you calculate the following Friday at 3am as a <code>datetime</code> object?</p> <p><strong>Clarification:</strong> i.e., the calculated date should always be greater than 7 days away, and less than or equal to 14.</p> <hr> <p>Going with a slightly modified version of <a href="http://stackoverflow.com/que...
11
2010-03-13T01:02:16Z
2,436,876
<p>I like <a href="http://labix.org/python-dateutil" rel="nofollow">dateutil</a> for such tasks in general, but I don't understand the heuristics you want -- as I use the words, if I say "next Friday" and it's Thursday I <em>would</em> mean tomorrow (probably I've been working too hard and lost track of what day of the...
4
2010-03-13T01:18:59Z
[ "python", "date-arithmetic" ]
How to calculate next Friday at 3am?
2,436,840
<p>How can you calculate the following Friday at 3am as a <code>datetime</code> object?</p> <p><strong>Clarification:</strong> i.e., the calculated date should always be greater than 7 days away, and less than or equal to 14.</p> <hr> <p>Going with a slightly modified version of <a href="http://stackoverflow.com/que...
11
2010-03-13T01:02:16Z
2,436,946
<p>Based on your clarification... I think you can do something like this:</p> <pre><code>from datetime import * &gt;&gt;&gt; today = datetime.today() &gt;&gt;&gt; todayAtThreeAm = datetime(today.year, today.month, today.day, 3) &gt;&gt;&gt; todayAtThreeAm datetime.datetime(2010, 3, 12, 3, 0) &gt;&gt;&gt; nextFridayAtT...
2
2010-03-13T01:48:08Z
[ "python", "date-arithmetic" ]
How to calculate next Friday at 3am?
2,436,840
<p>How can you calculate the following Friday at 3am as a <code>datetime</code> object?</p> <p><strong>Clarification:</strong> i.e., the calculated date should always be greater than 7 days away, and less than or equal to 14.</p> <hr> <p>Going with a slightly modified version of <a href="http://stackoverflow.com/que...
11
2010-03-13T01:02:16Z
2,437,199
<p>Here's a function and a test that it meets the OP's requirements:</p> <pre><code>import datetime _3AM = datetime.time(hour=3) _FRI = 4 # Monday=0 for weekday() def next_friday_3am(now): now += datetime.timedelta(days=7) if now.time() &lt; _3AM: now = now.combine(now.date(),_3AM) else: ...
6
2010-03-13T03:49:05Z
[ "python", "date-arithmetic" ]
What is the easiest way to ping/notify a .NET Windows Service?
2,436,927
<p>What is the easiest way to ping/notify a .NET Windows Service? Do I have to use WCF for this? Or is there an easier way? I would like to be able to wake up the service using a Python (or an Iron Python) script from anywhere. Also is there a way I can be notified (by email) if that the service has stopped?</p>
1
2010-03-13T01:41:10Z
2,436,964
<ul> <li>There is a command line tool <a href="http://ss64.com/nt/sc.html" rel="nofollow">SC</a> which can be used start stop and query the service. </li> <li>I don't know if there is an easy way to use WMI from python but WMI provides the ability to control services remotely as well. </li> <li>If you want to use .net ...
1
2010-03-13T01:57:42Z
[ ".net", "python", "windows-services", "ironpython" ]
What is the easiest way to ping/notify a .NET Windows Service?
2,436,927
<p>What is the easiest way to ping/notify a .NET Windows Service? Do I have to use WCF for this? Or is there an easier way? I would like to be able to wake up the service using a Python (or an Iron Python) script from anywhere. Also is there a way I can be notified (by email) if that the service has stopped?</p>
1
2010-03-13T01:41:10Z
2,436,997
<p>If you want to go to the low level .NET socket stuff, you could use the framework's <a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.tcplistener.aspx" rel="nofollow">TcpListener class</a>. See an <a href="http://www.winsocketdotnetworkprogramming.com/clientserversocketnetworkcommunication8o.html"...
1
2010-03-13T02:10:17Z
[ ".net", "python", "windows-services", "ironpython" ]
What is the easiest way to ping/notify a .NET Windows Service?
2,436,927
<p>What is the easiest way to ping/notify a .NET Windows Service? Do I have to use WCF for this? Or is there an easier way? I would like to be able to wake up the service using a Python (or an Iron Python) script from anywhere. Also is there a way I can be notified (by email) if that the service has stopped?</p>
1
2010-03-13T01:41:10Z
2,539,346
<p>I had to host a WCF in the windows service to allow it to be notified remotely. Just to keep deploying the solution as simple as possible. using the ServiceController would require the correct setup of permissions</p>
0
2010-03-29T15:54:47Z
[ ".net", "python", "windows-services", "ironpython" ]
Issues running python scripts in Command Prompt (Specifically with command line arguments)?
2,437,167
<p>I am trying to run my python scripts in the command-prompt without calling python.exe first. I am specifically doing this in relation to running django-admin.py. I have C:\Python26 and C:\Python26\Scripts in my PATH. However, if I try running django-admin.py by doing: </p> <blockquote> <p>django-admin.py startpr...
4
2010-03-13T03:31:26Z
2,437,395
<p>Check <code>assoc</code> and <code>ftype</code>. If properly set, you can run a <code>.py</code> with arguments.</p> <pre> > assoc .py .py=Python.File > ftype Python.File Python.File="C:\Python26\python.exe" "%1" %* </pre> <p>Depending on how your Python was installed, these may or may not be in place. You can <...
4
2010-03-13T05:40:19Z
[ "python", "scripting", "command-prompt" ]
Issues running python scripts in Command Prompt (Specifically with command line arguments)?
2,437,167
<p>I am trying to run my python scripts in the command-prompt without calling python.exe first. I am specifically doing this in relation to running django-admin.py. I have C:\Python26 and C:\Python26\Scripts in my PATH. However, if I try running django-admin.py by doing: </p> <blockquote> <p>django-admin.py startpr...
4
2010-03-13T03:31:26Z
4,603,488
<p>I know this is an old thread, but I have searched for a few weeks for this very same problem and found nothing. Today, however, I tried something new: </p> <p>If you are using Windows 7, do not use Command Prompt for scripting purposes. </p> <p>Instead, use the Windows PowerShell located at: <code>All Programs -&...
1
2011-01-05T11:21:59Z
[ "python", "scripting", "command-prompt" ]
Special Character Meanings Defined
2,437,196
<p>In Python's module named <code>string</code>, there is a line that says <code>whitespace = ' \t\n\r\v\f'</code>.</p> <ul> <li><code>' '</code> is a space character.</li> <li><code>'\t'</code> is a tab character.</li> <li><code>'\n'</code> is a newline character.</li> <li><code>'\r'</code> is a carriage-return chara...
1
2010-03-13T03:46:14Z
2,437,200
<p><code>\v</code> is a <a href="http://en.wikipedia.org/wiki/Tab_key" rel="nofollow">vertical tab</a></p> <p><code>\f</code> is a <a href="http://en.wikipedia.org/wiki/Page_break" rel="nofollow">formfeed</a></p> <p>See: <a href="http://msdn.microsoft.com/en-us/library/h21280bw%28VS.80%29.aspx" rel="nofollow">Escape ...
2
2010-03-13T03:49:15Z
[ "python", "character-codes" ]
Special Character Meanings Defined
2,437,196
<p>In Python's module named <code>string</code>, there is a line that says <code>whitespace = ' \t\n\r\v\f'</code>.</p> <ul> <li><code>' '</code> is a space character.</li> <li><code>'\t'</code> is a tab character.</li> <li><code>'\n'</code> is a newline character.</li> <li><code>'\r'</code> is a carriage-return chara...
1
2010-03-13T03:46:14Z
2,437,201
<p><code>\v</code> is a vertical tab. It was used in line printers to advance about 6 lines or so. It can be typed in *nix by pressing Ctrl-V Ctrl-K.</p> <p><code>\f</code> is a formfeed. It was used in line printers to advance to the next page. It can be typed in *nix by pressing Ctrl-V Ctrl-L.</p>
2
2010-03-13T03:49:31Z
[ "python", "character-codes" ]
Special Character Meanings Defined
2,437,196
<p>In Python's module named <code>string</code>, there is a line that says <code>whitespace = ' \t\n\r\v\f'</code>.</p> <ul> <li><code>' '</code> is a space character.</li> <li><code>'\t'</code> is a tab character.</li> <li><code>'\n'</code> is a newline character.</li> <li><code>'\r'</code> is a carriage-return chara...
1
2010-03-13T03:46:14Z
2,437,205
<p>Per <a href="http://en.wikipedia.org/wiki/Control_character#In_ASCII" rel="nofollow">wikipedia</a>:</p> <blockquote> <p>12 (form feed, \f, ^L), to cause a printer to eject paper to the top of the next page, or a video terminal to clear the screen.</p> </blockquote> <p><code>^L</code> means Control-L on mos...
2
2010-03-13T03:53:04Z
[ "python", "character-codes" ]
Django admin site auto populate combo box based on input
2,437,264
<p>hi i have to following model class Match(models.Model):</p> <pre><code> Team_one = models.ForeignKey('Team', related_name='Team_one') Team_two = models.ForeignKey('Team', related_name='Team_two') Stadium = models.CharField(max_length=255, blank=True) Start_time = models.DateTimeField(auto_now_...
2
2010-03-13T04:30:20Z
2,437,389
<p>Theres no real easy way to do that with the django admin. It's possible, but it would require you to replace the admin form, and subclass the widget with some javascript that copys the Team into the box. Way more effort than it's worth.</p> <p>If I were you, I'd just have winner_team and loser_team fields</p> <p>a...
0
2010-03-13T05:38:19Z
[ "python", "django", "django-models", "django-admin", "django-templates" ]
Django admin site auto populate combo box based on input
2,437,264
<p>hi i have to following model class Match(models.Model):</p> <pre><code> Team_one = models.ForeignKey('Team', related_name='Team_one') Team_two = models.ForeignKey('Team', related_name='Team_two') Stadium = models.CharField(max_length=255, blank=True) Start_time = models.DateTimeField(auto_now_...
2
2010-03-13T04:30:20Z
2,438,082
<p>You need <a href="http://github.com/digi604/django-smart-selects" rel="nofollow">django-smart-selects</a>.</p>
0
2010-03-13T10:59:52Z
[ "python", "django", "django-models", "django-admin", "django-templates" ]
In plain English, what are Django generic views?
2,437,468
<p>The first two paragraphs of this page explain that generic views are supposed to make my life easier, less monotonous, and make me more attractive to women (I made up that last one):</p> <p><a href="https://docs.djangoproject.com/en/1.4/topics/generic-views/">https://docs.djangoproject.com/en/1.4/topics/generic-vie...
19
2010-03-13T06:09:35Z
2,437,486
<p>Django generic views are just view functions (regular old python functions) that do things that are very common in web applications.</p> <p>Depending on the type of app you are building, they can save you from writing a lot of very simple views.</p> <p>For example, the <code>direct_to_template</code> generic view ...
18
2010-03-13T06:18:57Z
[ "python", "django", "django-generic-views" ]
In plain English, what are Django generic views?
2,437,468
<p>The first two paragraphs of this page explain that generic views are supposed to make my life easier, less monotonous, and make me more attractive to women (I made up that last one):</p> <p><a href="https://docs.djangoproject.com/en/1.4/topics/generic-views/">https://docs.djangoproject.com/en/1.4/topics/generic-vie...
19
2010-03-13T06:09:35Z
2,441,433
<p>To answer your second question: no, generic views are not related to scaffolding in RoR. Scaffolding, as the name indicates, is akin to code generation. Generic views are something else.</p> <p>My main usage of generic view is as a higher level replacement of the very basic <code>render_to_response</code> functions...
2
2010-03-14T06:58:27Z
[ "python", "django", "django-generic-views" ]
In plain English, what are Django generic views?
2,437,468
<p>The first two paragraphs of this page explain that generic views are supposed to make my life easier, less monotonous, and make me more attractive to women (I made up that last one):</p> <p><a href="https://docs.djangoproject.com/en/1.4/topics/generic-views/">https://docs.djangoproject.com/en/1.4/topics/generic-vie...
19
2010-03-13T06:09:35Z
3,033,792
<p>Generic views allow you to write much shorter code.</p> <p>Compare:</p> <pre><code>from django.http import HttpResponse, HttpResponseRedirect, Http404 from django.shortcuts import render_to_response, get_object_or_404, redirect from myapp.models import Context def edit(request, item_id): object = get_object_o...
4
2010-06-13T20:31:27Z
[ "python", "django", "django-generic-views" ]
Python | How to send a JSON response with name assign to it
2,437,473
<p>How can I return an response (lets say an array) to the client with a name assign to it form a python script.</p> <pre><code>echo '{"jsonValidateReturn":'.json_encode($arrayToJs).'}'; </code></pre> <p>in this scenario it returns an array with the name(jsonValidateReturn) assign to it also this can be accessed by j...
0
2010-03-13T06:12:09Z
2,437,487
<p>Try this for the last two lines:</p> <pre><code>jsonValidateReturn = simplejson.dumps({'jsonValidateReturn': array_to_js}) return HttpResponse(jsonValidateReturn, mimetype='application/json') </code></pre>
1
2010-03-13T06:19:42Z
[ "python", "json" ]
Django unable to update model
2,437,526
<p>i have the following function to override the default save function in a model match</p> <pre><code>def save(self, *args, **kwargs): if self.Match_Status == "F": Team.objects.filter(pk=self.Team_one.id).update(Played=F('Played')+1) Team.objects.filter(pk=self.Team_two.id).update(Played=F('Played'...
0
2010-03-13T06:40:57Z
2,437,761
<p>There's nothing obviously wrong with your method. So usual debugging tricks apply: are you sure the method is actually being called? Are you sure the Match object has a Match_Status of either F or D? Put in some print statements to be sure.</p>
0
2010-03-13T08:38:56Z
[ "python", "django", "django-models", "django-admin" ]
Django unable to update model
2,437,526
<p>i have the following function to override the default save function in a model match</p> <pre><code>def save(self, *args, **kwargs): if self.Match_Status == "F": Team.objects.filter(pk=self.Team_one.id).update(Played=F('Played')+1) Team.objects.filter(pk=self.Team_two.id).update(Played=F('Played'...
0
2010-03-13T06:40:57Z
2,559,660
<p>add this in ur admin.py </p> <pre><code>def save_model(self, request ,obj ,form,change): if obj.Match_Status == "F": Team.objects.filter(pk=obj.Team_one.id).update(Played=F('Played')+1) Team.objects.filter(pk=obj.Team_two.id).update(Played=F('Played')+1) if obj.Winner !="": Team.objects.filt...
1
2010-04-01T10:22:01Z
[ "python", "django", "django-models", "django-admin" ]
Is there a ruby equivalent of "python -i"?
2,437,582
<p>ruby -n is the closest thing I found, but it repeats the whole script. Also it's not available for irb.</p>
2
2010-03-13T07:06:01Z
2,437,648
<pre> $ cat &gt; hello.rb $hello = 'Hello, world!' puts $hello ^D $ irb irb(main):001:0&gt; load 'hello.rb' Hello, world! =&gt; true irb(main):002:0&gt; $hello =&gt; "Hello, world!" </pre> <p>A bit tedious, and local variables won't carry through. May be close enough for your usage? (This is basically like Python's ...
1
2010-03-13T07:34:24Z
[ "python", "ruby" ]
Is there a ruby equivalent of "python -i"?
2,437,582
<p>ruby -n is the closest thing I found, but it repeats the whole script. Also it's not available for irb.</p>
2
2010-03-13T07:06:01Z
2,880,523
<p><code>irb -r hello.rb</code></p>
1
2010-05-21T08:21:08Z
[ "python", "ruby" ]
Limiting the size of a python dictionary
2,437,617
<p>I'd like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. It would be nice if it was the least recently inserted/accesses key but that's not...
39
2010-03-13T07:19:49Z
2,437,634
<p>You can create a custom dictionary class by subclassing dict. In your case, you would have to override <code>__setitem__</code> to have check your own length and delete something if the limit is recahed. The following example would print the current lenght after every insertion:</p> <pre><code>class mydict(dict): ...
1
2010-03-13T07:28:45Z
[ "python", "caching", "dictionary", "lru" ]
Limiting the size of a python dictionary
2,437,617
<p>I'd like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. It would be nice if it was the least recently inserted/accesses key but that's not...
39
2010-03-13T07:19:49Z
2,437,636
<p>A dict does not have this behavior. You could make your own class that does this, for example something like</p> <pre><code>class MaxSizeDict(object): def __init__(self, max_size): self.max_size = max_size self.dict = {} def __setitem__(self, key, value): if key in self.dict: ...
2
2010-03-13T07:28:48Z
[ "python", "caching", "dictionary", "lru" ]
Limiting the size of a python dictionary
2,437,617
<p>I'd like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. It would be nice if it was the least recently inserted/accesses key but that's not...
39
2010-03-13T07:19:49Z
2,437,645
<p>Python 2.7 and 3.1 have <a href="http://docs.python.org/py3k/library/collections.html#ordereddict-objects" rel="nofollow">OrderedDict</a> and there are pure-Python implementations for earlier Pythons.</p> <pre><code>from collections import OrderedDict class LimitedSizeDict(OrderedDict): def __init__(self, *args,...
27
2010-03-13T07:32:35Z
[ "python", "caching", "dictionary", "lru" ]
Limiting the size of a python dictionary
2,437,617
<p>I'd like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. It would be nice if it was the least recently inserted/accesses key but that's not...
39
2010-03-13T07:19:49Z
2,438,926
<p>Here's a simple, no-LRU Python 2.6+ solution (in older Pythons you could do something similar with <code>UserDict.DictMixin</code>, but in 2.6 and better that's not recommended, and the ABCs from <code>collections</code> are preferable anyway...):</p> <pre><code>import collections class MyDict(collections.MutableM...
8
2010-03-13T15:45:44Z
[ "python", "caching", "dictionary", "lru" ]
Limiting the size of a python dictionary
2,437,617
<p>I'd like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. It would be nice if it was the least recently inserted/accesses key but that's not...
39
2010-03-13T07:19:49Z
8,334,739
<p>Here is a simple and efficient LRU cache written with dirt simple Python code that runs on any python version 1.5.2 or later:</p> <pre><code>class LRU_Cache: def __init__(self, original_function, maxsize=1000): self.original_function = original_function self.maxsize = maxsize self.mappi...
5
2011-11-30T23:49:34Z
[ "python", "caching", "dictionary", "lru" ]
Limiting the size of a python dictionary
2,437,617
<p>I'd like to work with a dict in python, but limit the number of key/value pairs to X. In other words, if the dict is currently storing X key/value pairs and I perform an insertion, I would like one of the existing pairs to be dropped. It would be nice if it was the least recently inserted/accesses key but that's not...
39
2010-03-13T07:19:49Z
28,270,649
<p><a href="https://pypi.python.org/pypi/cachetools">cachetools</a> will provide you nice implementation of Mapping Hashes that does this (and it works on python 2 and 3).</p> <p>Excerpt of the documentation:</p> <blockquote> <p>For the purpose of this module, a cache is a mutable mapping of a fixed maximum size....
7
2015-02-02T03:15:36Z
[ "python", "caching", "dictionary", "lru" ]
Would this hack for per-object permissions in django work?
2,437,621
<p>According to the documentation, a class can have the meta option permissions, described as such:</p> <a href="http://docs.djangoproject.com/en/1.1/ref/models/options/#permissions" rel="nofollow">Options.permissions</a> <blockquote> <p>Extra permissions to enter into the permissions table when creating this objec...
0
2010-03-13T07:20:54Z
2,437,699
<p>I think in the context of the <code>Meta</code> class, you don't have access to <code>self</code>.<br> If you look for a solution for the admin application, read this about <a href="http://code.djangoproject.com/wiki/RowLevelPermissions" rel="nofollow">row level permissions</a>.</p> <p>There is also says:</p> <blo...
0
2010-03-13T07:58:27Z
[ "python", "django", "permissions", "database-permissions" ]
Would this hack for per-object permissions in django work?
2,437,621
<p>According to the documentation, a class can have the meta option permissions, described as such:</p> <a href="http://docs.djangoproject.com/en/1.1/ref/models/options/#permissions" rel="nofollow">Options.permissions</a> <blockquote> <p>Extra permissions to enter into the permissions table when creating this objec...
0
2010-03-13T07:20:54Z
2,437,974
<p>No, this wouldn't work, for a number of reasons. Firstly, as Felix points out, you have no access to <code>self</code> at that point. Secondly, as the documentation you quoted states, this is a list of items <em>to enter into the permissions table</em> - in other words these are actual database rows, which are creat...
0
2010-03-13T10:23:44Z
[ "python", "django", "permissions", "database-permissions" ]
How to clear wxpython frame content when dragging a panel?
2,437,818
<p>I have 3 panels and I want to make drags on them. The problem is that when I do a drag on one this happens: <img src="http://img41.yfrog.com/img41/9043/soundlog.png" alt="http://img41.yfrog.com/img41/9043/soundlog.png"></p> <p>How can I refresh the frame to happear its color when the panel is no longer there?</p> ...
2
2010-03-13T09:05:45Z
2,488,070
<p>To refresh the parent on every repositioning of <code>self</code>, you could add</p> <pre><code>self.parent.Refresh() </code></pre> <p>right after your existing call to <code>self.SetPosition</code> in your <code>def onMouseMove</code> method. Right now you're refreshing the frame only in the <code>def onDraggingD...
1
2010-03-21T17:55:33Z
[ "python", "wxpython", "refresh", "panel" ]
Reading Python Documentation for 3rd party modules
2,437,857
<p>I recently downloaded IMDbpy module.. When I do, </p> <pre><code>import imdb help(imdb) </code></pre> <p>i dont get the full documentation.. I have to do</p> <pre><code>im = imdb.IMDb() help(im) </code></pre> <p>to see the available methods. I dont like this console interface. Is there any better way of reading...
4
2010-03-13T09:30:01Z
2,437,872
<p>Use <a href="http://docs.python.org/library/pydoc.html">pydoc</a> </p> <pre><code>pydoc -w imdb </code></pre> <p>This will generate imdb.html in the same directory.</p> <hr> <p><code>pydoc -p 9090</code> will start a HTTP server on port 9090, and you will be able to browse all documentation at <a href="http://l...
9
2010-03-13T09:37:08Z
[ "python", "documentation", "pydoc", "imdbpy" ]
Reading Python Documentation for 3rd party modules
2,437,857
<p>I recently downloaded IMDbpy module.. When I do, </p> <pre><code>import imdb help(imdb) </code></pre> <p>i dont get the full documentation.. I have to do</p> <pre><code>im = imdb.IMDb() help(im) </code></pre> <p>to see the available methods. I dont like this console interface. Is there any better way of reading...
4
2010-03-13T09:30:01Z
2,439,266
<p>in <a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a> you could do</p> <pre><code>[1]: import os [2]: os? &lt; get the full documentation here &gt; # or you could do it on specific functions [3]: os.uname &lt;built-in function&gt; [4]: os.uname? &lt; get the full documentation here &gt; # ...
1
2010-03-13T17:30:39Z
[ "python", "documentation", "pydoc", "imdbpy" ]
Document Similarity: Comparing two documents efficiently
2,437,978
<p>I have a loop that calculates the similarity between two documents. It collects all the tokens in a document and their scores, and places them in dictionary. It then compares the dictionaries </p> <p>This is what I have so far, it works, but is super slow:</p> <pre><code># Doc A cursor1.execute("SELECT token, tfid...
1
2010-03-13T10:24:55Z
2,438,234
<p>A Python point: <code>adict.has_key(k)</code> is obsolete in Python 2.X and vanished in Python 3.X. <code>k in adict</code> as an expression has been available since Python 2.2; use it instead. It will be faster (no method call).</p> <p>An any-language practical point: iterate over the shorter dictionary.</p> <p>C...
2
2010-03-13T12:05:13Z
[ "python", "mysql", "performance" ]
Document Similarity: Comparing two documents efficiently
2,437,978
<p>I have a loop that calculates the similarity between two documents. It collects all the tokens in a document and their scores, and places them in dictionary. It then compares the dictionaries </p> <p>This is what I have so far, it works, but is super slow:</p> <pre><code># Doc A cursor1.execute("SELECT token, tfid...
1
2010-03-13T10:24:55Z
2,438,249
<p>What about pushing some of the work on the DB?</p> <p>With a join you can have a result that is basically</p> <pre><code> Token A.tfidf_norm B.tfidf_norm ----------------------------------------- Apple 12.2 11.00 ... Word 29.87 33.21 Zealot 0.00 11....
1
2010-03-13T12:09:44Z
[ "python", "mysql", "performance" ]
Document Similarity: Comparing two documents efficiently
2,437,978
<p>I have a loop that calculates the similarity between two documents. It collects all the tokens in a document and their scores, and places them in dictionary. It then compares the dictionaries </p> <p>This is what I have so far, it works, but is super slow:</p> <pre><code># Doc A cursor1.execute("SELECT token, tfid...
1
2010-03-13T10:24:55Z
3,467,955
<p>One sql query can do the job:</p> <pre><code>SELECT sum(index1.tfidf_norm*index2.tfidf_norm) FROM index index1, index index2 WHERE index1.token=index2.token AND index1.doc_id=? AND index2.doc_id=? </code></pre> <p>Just replace the '?' with the 2 document id respectively.</p>
0
2010-08-12T13:09:09Z
[ "python", "mysql", "performance" ]
Python Script to backup a directory
2,438,041
<p>#Filename:backup_ver1</p> <pre><code>import os import time #1 Using list to specify the files and directory to be backed up source = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\Dr Py\Final_Py' #2 define backup directory destination = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\PyDevResourse'...
0
2010-03-13T10:45:01Z
2,438,114
<p>The <code>source</code> directory contains spaces, but you don't have quotes around it in the command line. This might be a reason for the backup to fail.</p> <p>To avoid problems like this, use the <a href="http://docs.python.org/library/subprocess.html" rel="nofollow"><code>subprocess</code></a> module instead of...
0
2010-03-13T11:15:34Z
[ "python", "windows-xp", "backup", "rar" ]
Python Script to backup a directory
2,438,041
<p>#Filename:backup_ver1</p> <pre><code>import os import time #1 Using list to specify the files and directory to be backed up source = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\Dr Py\Final_Py' #2 define backup directory destination = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\PyDevResourse'...
0
2010-03-13T10:45:01Z
2,438,209
<p>Maybe instead of writing your own backup script you could use python tool called rdiff-backup, which can create incremental backups?</p>
2
2010-03-13T11:53:04Z
[ "python", "windows-xp", "backup", "rar" ]
Python Script to backup a directory
2,438,041
<p>#Filename:backup_ver1</p> <pre><code>import os import time #1 Using list to specify the files and directory to be backed up source = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\Dr Py\Final_Py' #2 define backup directory destination = r'C:\Documents and Settings\rgolwalkar\Desktop\Desktop\PyDevResourse'...
0
2010-03-13T10:45:01Z
2,438,264
<p>if the compression algorithm can be something else and its just to backup a directory, why not do it with python's own tar and gzip instead? eg</p> <pre><code>import os import tarfile import time root="c:\\" source=os.path.join(root,"Documents and Settings","rgolwalkar","Desktop","Desktop","Dr Py","Final_Py") desti...
0
2010-03-13T12:13:07Z
[ "python", "windows-xp", "backup", "rar" ]
Passing in **kwargs from Flex over PyAMF
2,438,235
<p>Anyone know if it is easily possible to send <code>**kwargs</code> over PyAMF from <code>NetConnection.call()</code>? I would like it.</p> <p>I could write a wrapper around the actual function and expose that and perform some parsing manually to determine the kwargs to pass in, but I don't want to do that. I will j...
0
2010-03-13T12:05:18Z
2,440,286
<p>Whilst ActionScript has the <code>*args</code> construct (<code>params ...</code>) there is no equivalent to <code>**kwargs</code>, although if you do need to send arbitrary named arguments, then you can always send a dict as a positional argument to the service. E.g.</p> <pre><code>def some_service_function(kwargs...
1
2010-03-13T22:27:16Z
[ "python", "remoting", "pyamf", "kwargs" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
2,438,478
<p>static methods are great because you don't have to declare an instance of the object to which the method belongs.</p> <p>python's site has some great documentation on static methods here:<br> <a href="http://docs.python.org/library/functions.html#staticmethod" rel="nofollow">http://docs.python.org/library/functions...
3
2010-03-13T13:21:13Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
2,438,531
<p>Static methods have almost no reason-to-be in Python. You use either instance methods or class methods.</p> <pre><code>def method(self, args): self.member = something @classmethod def method(cls, args): cls.member = something @staticmethod def method(args): MyClass.member = something # The above i...
1
2010-03-13T13:42:32Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
2,438,541
<p><strong>Why one would want to define static methods</strong>?</p> <p>Suppose we have a <code>class</code> called <code>Math</code> then</p> <p>nobody will want to create object of <code>class Math</code> <br> and then invoke methods like <code>ceil</code> and <code>floor</code> and <code>fabs</code> on it. <br></p...
7
2010-03-13T13:46:23Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
2,438,559
<p>When you call a function object from an object instance, it becomes a 'bound method' and gets the instance object itself is passed in as a first argument. </p> <p>When you call a <code>classmethod</code> object (which wraps a function object) on an object instance, the class of the instance object gets passed in as...
8
2010-03-13T13:51:12Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
2,438,627
<p>Static methods have limited use, because they don't have access to the attributes of an instance of a class (like a regular method does), and they don't have access to the attributes of the class itself (like a class method does).</p> <p>So they aren't useful for day-to-day methods.</p> <p>However, they can be use...
42
2010-03-13T14:14:41Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
2,438,925
<p>This is not quite to the point of your actual question, but since you've said you are a python newbie perhaps it will be helpful, and no one else has quite come out and said it explicitly.</p> <p>I would never have fixed the above code by making the method a static method. I would either have ditched the class and ...
12
2010-03-13T15:45:24Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
22,589,883
<p>See <a href="http://julien.danjou.info/blog/2013/guide-python-static-class-abstract-methods">this article</a> for detailed explanation. </p> <p><strong>TL;DR</strong></p> <p>1.It eliminates the use of <code>self</code> argument. </p> <p>2.It reduces memory usage because Python doesn't have to instantiate a <a hre...
30
2014-03-23T10:54:03Z
[ "python" ]
What is the advantage of using static methods in Python?
2,438,473
<p>I ran into unbound method error in python with the code</p> <pre><code>class Sample(object): '''This class defines various methods related to the sample''' def drawSample(samplesize,List): sample=random.sample(List,samplesize) return sample Choices=range(100) print Sample.drawSample(5,Choices)...
33
2010-03-13T13:19:52Z
30,980,489
<p>Because namespacing functions is nice (as was previously pointed out):</p> <ol> <li><p>When I want to be explicit about methods that don't change the state of the object, I use static methods. This discourages people on my team to start changing the object's attributes in those methods.</p></li> <li><p>When i refac...
0
2015-06-22T12:52:51Z
[ "python" ]
Extending appengine's db.Property with caching
2,438,496
<p>I'm looking to implement a property class for appengine, very similar to the existing <code>db.ReferenceProperty</code>. I am implementing my own version because I want some other default return values. My question is, how do I make the property remember its returned value, so that the datastore query is only perfor...
0
2010-03-13T13:28:31Z
2,438,833
<p>A <code>PageProperty</code> instance exists per-model, not per-entity (where an entity is an instance of the model class). So I think you need a <em>dictionary</em> that maps pagename -> Page entity, instead of a single attribute per PageProperty instance. E.g., maybe something like...:</p> <pre><code>class PageP...
2
2010-03-13T15:20:32Z
[ "python", "google-app-engine", "descriptor" ]
Extending appengine's db.Property with caching
2,438,496
<p>I'm looking to implement a property class for appengine, very similar to the existing <code>db.ReferenceProperty</code>. I am implementing my own version because I want some other default return values. My question is, how do I make the property remember its returned value, so that the datastore query is only perfor...
0
2010-03-13T13:28:31Z
2,449,811
<p>If you only want to change some small part of the behaviour of ReferenceProperty, you may want to simply extend it, overriding its <a href="http://code.google.com/appengine/docs/python/datastore/propertyclass.html#Property_default_value" rel="nofollow">default_value</a> method. You may find <a href="http://code.goog...
1
2010-03-15T19:21:33Z
[ "python", "google-app-engine", "descriptor" ]
How to recovery source python code (.py) from .pyo file?
2,438,578
<p>I need to convert a compiled python code (.pyo) to its source . I look in depython.net, but there is a problem. A warning;</p> <p>"File version older than 2.4."</p> <p>What should I do?</p> <p>Thanks.</p>
5
2010-03-13T13:57:33Z
2,438,645
<p>Try <a href="http://www.crazy-compilers.com/decompyle/" rel="nofollow"><strong>decompyle</strong></a>.</p> <p>This has become a commercial service.<br> To experiment with it you can use <a href="http://packages.debian.org/sid/decompyle" rel="nofollow">Debian Packages</a>.</p> <p>I would have loved to try it but I ...
1
2010-03-13T14:22:55Z
[ "python", "wxpython", "extension-methods", "decompiling" ]
How to recovery source python code (.py) from .pyo file?
2,438,578
<p>I need to convert a compiled python code (.pyo) to its source . I look in depython.net, but there is a problem. A warning;</p> <p>"File version older than 2.4."</p> <p>What should I do?</p> <p>Thanks.</p>
5
2010-03-13T13:57:33Z
2,439,056
<p>there is <a href="http://users.cs.cf.ac.uk/J.P.Giddy/python/decompiler/decompiler.html" rel="nofollow">Decompile</a>, the reputed cheap (but you can test it online) <a href="http://www.depython.net/" rel="nofollow">depython</a> and the <a href="http://sourceforge.net/projects/unpyc/" rel="nofollow">UnPyc</a> project...
1
2010-03-13T16:27:04Z
[ "python", "wxpython", "extension-methods", "decompiling" ]
How to recovery source python code (.py) from .pyo file?
2,438,578
<p>I need to convert a compiled python code (.pyo) to its source . I look in depython.net, but there is a problem. A warning;</p> <p>"File version older than 2.4."</p> <p>What should I do?</p> <p>Thanks.</p>
5
2010-03-13T13:57:33Z
25,822,180
<p>try these:</p> <p><a href="https://github.com/Mysterie/uncompyle2" rel="nofollow">uncompyle2</a> converts Python byte-code back into equivalent Python source code. It accepts byte-code from Python version 2.5 to 2.7. Additionally, it will only run on Python 2.7.</p> <p><a href="https://github.com/rocky/python-unco...
3
2014-09-13T10:17:07Z
[ "python", "wxpython", "extension-methods", "decompiling" ]
What is the semantics of 'is' operator in Python?
2,438,667
<p>How does <code>is</code> operator determine if two objects are the same? How does it work? I can't find it documented.</p>
10
2010-03-13T14:28:49Z
2,438,679
<p>From the <a href="http://docs.python.org/reference/datamodel.html">documentation</a>:</p> <blockquote> <p>Every object has an identity, a type and a value. An object’s identity never changes once it has been created; you may think of it as the object’s address in memory. The ‘is‘ operator compar...
12
2010-03-13T14:33:51Z
[ "python" ]
What is the semantics of 'is' operator in Python?
2,438,667
<p>How does <code>is</code> operator determine if two objects are the same? How does it work? I can't find it documented.</p>
10
2010-03-13T14:28:49Z
2,438,691
<p><a href="http://docs.python.org/reference/expressions.html#notin">Comparison Operators</a></p> <p>Is works by comparing the object referenced to see if the operands point to the same object.</p> <pre><code>&gt;&gt;&gt; a = [1, 2] &gt;&gt;&gt; b = a &gt;&gt;&gt; a is b True &gt;&gt;&gt; c = [1, 2] &gt;&gt;&gt; a is...
12
2010-03-13T14:36:17Z
[ "python" ]
What is the semantics of 'is' operator in Python?
2,438,667
<p>How does <code>is</code> operator determine if two objects are the same? How does it work? I can't find it documented.</p>
10
2010-03-13T14:28:49Z
2,445,702
<p>To add to the other answers, you can think of <code>a is b</code> working as if it was <code>is_(a, b)</code>:</p> <pre><code>def is_(a, b): return id(a) == id(b) </code></pre> <p>Note that you cannot <a href="http://codepad.org/Xb0TaKl9">directly replace</a> <code>a is b</code> with <code>id(a) == id(b)</code>,...
5
2010-03-15T07:52:30Z
[ "python" ]
What is the semantics of 'is' operator in Python?
2,438,667
<p>How does <code>is</code> operator determine if two objects are the same? How does it work? I can't find it documented.</p>
10
2010-03-13T14:28:49Z
31,725,927
<p>While @msw's answer is correct, you might want to consider what happens when for example those objects are either ints or strings:</p> <pre><code>&gt;&gt;&gt; a = 67 &gt;&gt;&gt; b = 67 &gt;&gt;&gt; c = 58 &gt;&gt;&gt; a is b True &gt;&gt;&gt; a is c False &gt;&gt;&gt; a = 'dog' &gt;&gt;&gt; b = 'dog' &gt;&gt;&gt;...
-1
2015-07-30T14:03:16Z
[ "python" ]
Batch select with SQLAlchemy
2,438,690
<p>I have a large set of values V, some of which are likely to exist in a table T. I would like to insert into the table those which are not yet inserted. So far I have the code:</p> <pre><code>for value in values: s = self.conn.execute(mytable.__table__.select(mytable.value == value)).first() ...
2
2010-03-13T14:36:17Z
2,438,756
<p>For the first question, something like this if I understand your question correctly</p> <pre><code>mytable.__table__.select(mytable.value.in_(values) </code></pre> <p>For the second question, querying this by 1 row at a time is overly expensive indeed, although you might not have a choice in the matter. As far as ...
2
2010-03-13T14:57:39Z
[ "python", "sqlalchemy" ]
Set serial port pin high using python
2,438,848
<p>Is it possible to set one pin of the serial port continuously high using python (or C)? If yes, how?</p>
3
2010-03-13T15:23:55Z
2,438,871
<p>Yes it is <strong>possible</strong> using <a href="http://pyserial.sourceforge.net/" rel="nofollow"><strong>pySerial</strong></a>.</p>
2
2010-03-13T15:29:20Z
[ "python", "serial-port" ]
Set serial port pin high using python
2,438,848
<p>Is it possible to set one pin of the serial port continuously high using python (or C)? If yes, how?</p>
3
2010-03-13T15:23:55Z
2,440,156
<p>If you open the port, the Tx line should go to the voltage high state, and if you never send data it should stay in that state (see <a href="http://www.lammertbies.nl/comm/info/RS-232_specs.html#bits" rel="nofollow">here</a>). I've never actually tried this though. You might find you need to enable one of the cont...
0
2010-03-13T21:45:28Z
[ "python", "serial-port" ]
Set serial port pin high using python
2,438,848
<p>Is it possible to set one pin of the serial port continuously high using python (or C)? If yes, how?</p>
3
2010-03-13T15:23:55Z
4,697,687
<p>Using the pyserial methods <code>setRTS(level=True)</code> and <code>setDTR(level=True)</code> you can control the RTS and DTR lines at will. For instance, the following code will toggle the RTS pin of the first serial port. (See the pyserial documentation for the details).</p> <pre><code>import time import serial ...
9
2011-01-15T02:57:25Z
[ "python", "serial-port" ]
Python Copy Through Assignment?
2,438,938
<p>I would expect that the following code would just initialise the <code>dict_a</code>, <code>dict_b</code> and <code>dict_c</code> dictionaries. But it seams to have a copy through effect:</p> <pre><code>dict_a = dict_b = dict_c = {} dict_c['hello'] = 'goodbye' print dict_a print dict_b print dict_c </code></pre> ...
23
2010-03-13T15:47:48Z
2,438,943
<p>This is because in Python, variables (names) are just references to individual objects. When you assign <code>dict_a = dict_b</code>, you are really copying a memory address (or pointer, if you will) from <code>dict_b</code> to <code>dict_a</code>. There is still one instance of that dictionary.</p> <p>To get the...
20
2010-03-13T15:49:08Z
[ "python" ]
Python Copy Through Assignment?
2,438,938
<p>I would expect that the following code would just initialise the <code>dict_a</code>, <code>dict_b</code> and <code>dict_c</code> dictionaries. But it seams to have a copy through effect:</p> <pre><code>dict_a = dict_b = dict_c = {} dict_c['hello'] = 'goodbye' print dict_a print dict_b print dict_c </code></pre> ...
23
2010-03-13T15:47:48Z
2,438,945
<p>Your first assignment assigns the same dictionary object to the variables dict_a, dict_b, and dict_c. It is equivalent to dict_c = {}; dict_b = dict_c; dict_a = dict_c.</p>
0
2010-03-13T15:49:54Z
[ "python" ]
Python Copy Through Assignment?
2,438,938
<p>I would expect that the following code would just initialise the <code>dict_a</code>, <code>dict_b</code> and <code>dict_c</code> dictionaries. But it seams to have a copy through effect:</p> <pre><code>dict_a = dict_b = dict_c = {} dict_c['hello'] = 'goodbye' print dict_a print dict_b print dict_c </code></pre> ...
23
2010-03-13T15:47:48Z
2,439,352
<p>As danben previously said, you're just copying the same dict into 3 variables, so that each one reffers to the same object.</p> <p>To get the behaviour you want, you should instanciate a different dict in each variable:</p> <pre><code>&gt;&gt;&gt; dict_a, dict_b, dict_c = {}, {}, {} &gt;&gt;&gt; dict_c['hello'] = ...
1
2010-03-13T17:53:47Z
[ "python" ]
Python Copy Through Assignment?
2,438,938
<p>I would expect that the following code would just initialise the <code>dict_a</code>, <code>dict_b</code> and <code>dict_c</code> dictionaries. But it seams to have a copy through effect:</p> <pre><code>dict_a = dict_b = dict_c = {} dict_c['hello'] = 'goodbye' print dict_a print dict_b print dict_c </code></pre> ...
23
2010-03-13T15:47:48Z
2,445,989
<p>Even though </p> <pre><code>&gt;&gt;&gt; dict_a, dict_b, dict_c = {}, {}, {} </code></pre> <p>is the right way to go in most cases, when it get more than 3 it looks weird</p> <p>Imagine</p> <pre><code>&gt;&gt;&gt; a, b, c, d, e, f = {}, {}, {}, {}, {}, {} </code></pre> <p>In cases where I wanna initialize more ...
7
2010-03-15T09:11:02Z
[ "python" ]