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
Interpreter that ignores leading >>> characters and ellipsis
2,066,061
<p>I am studying some examples in a tutorial where there are a lot of leading >>> characters and ellipsis in the text. This makes it hard to cut and paste into the IPython interpreter since it doesn't like these strings.</p> <p>Is there another interpreter I could use that will appropriately ignore and interpret these...
0
2010-01-14T17:19:22Z
2,066,135
<p><a href="http://ipython.scipy.org/moin/" rel="nofollow">IPython</a> can do this (look at the %paste magic command)</p>
4
2010-01-14T17:29:43Z
[ "python", "ide", "interpreter" ]
Interpreter that ignores leading >>> characters and ellipsis
2,066,061
<p>I am studying some examples in a tutorial where there are a lot of leading >>> characters and ellipsis in the text. This makes it hard to cut and paste into the IPython interpreter since it doesn't like these strings.</p> <p>Is there another interpreter I could use that will appropriately ignore and interpret these...
0
2010-01-14T17:19:22Z
2,089,941
<p>In any case, a way to clean up such stuff by python code:</p> <pre><code>import re matcher= re.compile("(?m)^[.&gt;]{3} ") def cleanup(text): return matcher.sub('', text) </code></pre> <p>Example use:</p> <pre><code>&gt;&gt;&gt; print (cleanup("""&gt;&gt;&gt; d = dict(x.__array_interface__) &gt;&gt;&gt; d['sh...
0
2010-01-18T23:20:16Z
[ "python", "ide", "interpreter" ]
What permissions are required for subprocess.Popen?
2,066,068
<p>The following code:</p> <pre><code>gb = self.request.form['groupby'] typ = self.request.form['type'] tbl = self.request.form['table'] primary = self.request.form.get('primary', None) if primary is not None: create = False else: create = True mdb = tempfile.NamedTemporaryFile() mdb.write(self.request.form['md...
8
2010-01-14T17:20:14Z
2,066,156
<p>You also need to ensure read and execute permissions for the user running that code on the directories up the chain - /Users, /Users/jondoe and /Users/jondoe/development.</p>
0
2010-01-14T17:32:40Z
[ "python", "osx", "subprocess", "popen" ]
What permissions are required for subprocess.Popen?
2,066,068
<p>The following code:</p> <pre><code>gb = self.request.form['groupby'] typ = self.request.form['type'] tbl = self.request.form['table'] primary = self.request.form.get('primary', None) if primary is not None: create = False else: create = True mdb = tempfile.NamedTemporaryFile() mdb.write(self.request.form['md...
8
2010-01-14T17:20:14Z
2,086,910
<p>Can you feed "sudo" to subprocess? See this SO <a href="http://stackoverflow.com/questions/567542">thread</a>.</p> <p>@Jon Hadley, from the interpreter:</p> <pre><code>&gt;&gt;&gt; import subprocess &gt;&gt;&gt; p = subprocess.call(['sudo','/usr/bin/env']) PASSWORD: [snip] USER=root USERNAME=root SUDO_COMMAND=/u...
1
2010-01-18T15:09:13Z
[ "python", "osx", "subprocess", "popen" ]
What permissions are required for subprocess.Popen?
2,066,068
<p>The following code:</p> <pre><code>gb = self.request.form['groupby'] typ = self.request.form['type'] tbl = self.request.form['table'] primary = self.request.form.get('primary', None) if primary is not None: create = False else: create = True mdb = tempfile.NamedTemporaryFile() mdb.write(self.request.form['md...
8
2010-01-14T17:20:14Z
2,088,273
<p>Assuming that permissions on parent folders are correct (i.e. all parent folders should have +x permission), try adding:</p> <pre><code>shell=True </code></pre> <p>to the Popen command such as:</p> <pre><code>subprocess.Popen(("/Users/jondoe/development/mdb-export", mdb.name, tbl,), stdout=csv, shell=True) </code...
11
2010-01-18T18:30:47Z
[ "python", "osx", "subprocess", "popen" ]
What permissions are required for subprocess.Popen?
2,066,068
<p>The following code:</p> <pre><code>gb = self.request.form['groupby'] typ = self.request.form['type'] tbl = self.request.form['table'] primary = self.request.form.get('primary', None) if primary is not None: create = False else: create = True mdb = tempfile.NamedTemporaryFile() mdb.write(self.request.form['md...
8
2010-01-14T17:20:14Z
2,094,311
<p>It seems the 'Permissions denied error' was orginally coming from Popen trying to execute mdb-export from the wrong location (and to compound things, with the wrong permissions). </p> <p>If mdbtools is installed, the following works fine and inherits the correct permissions without the need for sudo etc.</p> <pre>...
5
2010-01-19T14:53:51Z
[ "python", "osx", "subprocess", "popen" ]
Python - test a property throws exception
2,066,179
<p>Given:</p> <pre><code>def test_to_check_exception_is_thrown(self): # Arrange c = Class() # Act and Assert self.assertRaises(NameError, c.do_something) </code></pre> <p>If <code>do_something</code> throws an exception the test passes.</p> <p>But I have a property, and when I replace <code>c.do_some...
8
2010-01-14T17:38:10Z
2,066,208
<p>You're getting an error because it's a syntax error in Python to have an assignment inside another expression. For example:</p> <pre><code>&gt;&gt;&gt; print(foo = 'bar') ------------------------------------------------------------ File "&lt;ipython console&gt;", line 1 print(foo = 'bar') ^ ...
-1
2010-01-14T17:43:04Z
[ "python", "unit-testing", "properties", "ironpython" ]
Python - test a property throws exception
2,066,179
<p>Given:</p> <pre><code>def test_to_check_exception_is_thrown(self): # Arrange c = Class() # Act and Assert self.assertRaises(NameError, c.do_something) </code></pre> <p>If <code>do_something</code> throws an exception the test passes.</p> <p>But I have a property, and when I replace <code>c.do_some...
8
2010-01-14T17:38:10Z
2,066,214
<p><code>assertRaises</code> expects a callable object. You can create a function and pass it:</p> <pre><code>obj = Class() def setNameTest(): obj.name = "Name" self.assertRaises(NameError, setNameTest) </code></pre> <p>Another possibility is to use <code>setattr</code>:</p> <pre><code>self.assertRaises(...
11
2010-01-14T17:43:43Z
[ "python", "unit-testing", "properties", "ironpython" ]
Python - test a property throws exception
2,066,179
<p>Given:</p> <pre><code>def test_to_check_exception_is_thrown(self): # Arrange c = Class() # Act and Assert self.assertRaises(NameError, c.do_something) </code></pre> <p>If <code>do_something</code> throws an exception the test passes.</p> <p>But I have a property, and when I replace <code>c.do_some...
8
2010-01-14T17:38:10Z
2,066,236
<p><a href="http://docs.python.org/library/unittest.html#unittest.TestCase.assertRaises" rel="nofollow">The second argument to <code>assertRaises</code> should be a callable</a>.</p> <p>An assignment statement (ie. <code>class.name = "Name"</code>) is not a callable so it will not work. Use <code>setattr</code> to per...
8
2010-01-14T17:46:57Z
[ "python", "unit-testing", "properties", "ironpython" ]
Python - test a property throws exception
2,066,179
<p>Given:</p> <pre><code>def test_to_check_exception_is_thrown(self): # Arrange c = Class() # Act and Assert self.assertRaises(NameError, c.do_something) </code></pre> <p>If <code>do_something</code> throws an exception the test passes.</p> <p>But I have a property, and when I replace <code>c.do_some...
8
2010-01-14T17:38:10Z
23,650,764
<p>Since Python 2.7 <code>assertRaises()</code> can be used as a context manager. <a href="https://docs.python.org/2.7/library/unittest.html#unittest.TestCase.assertRaises">see here</a></p> <p>So you can write your test with the <code>with</code> instruction like this:</p> <pre><code>def test_to_check_exception_is_th...
7
2014-05-14T09:32:30Z
[ "python", "unit-testing", "properties", "ironpython" ]
Dynamic form field generation in Django templates
2,066,181
<p>I am having a problem figuring out how to solve this problem the Django and (probably) the Python way. I am sending a hash to a template that contains the following values</p> <pre><code>{'date': '2009-12-30', 'locations': [{u'lat': 43.514000000000003, u'lng': -79.844032999999996, u'place': u'1053 Bowring Cres, Mi...
2
2010-01-14T17:38:26Z
2,066,290
<pre><code>if info['user'] == username: locations = (json.loads(info['locations']) + [{'place': '', 'description': ''}] * 5)[:5] return {'date': info['date'], 'locations': locations} </code></pre>
3
2010-01-14T17:56:03Z
[ "python", "django", "templates" ]
Dynamic form field generation in Django templates
2,066,181
<p>I am having a problem figuring out how to solve this problem the Django and (probably) the Python way. I am sending a hash to a template that contains the following values</p> <pre><code>{'date': '2009-12-30', 'locations': [{u'lat': 43.514000000000003, u'lng': -79.844032999999996, u'place': u'1053 Bowring Cres, Mi...
2
2010-01-14T17:38:26Z
2,066,331
<p>(a)</p> <pre><code>id="id_location_{{ forloop.counter }}" </code></pre>
2
2010-01-14T18:02:49Z
[ "python", "django", "templates" ]
how to concatenate lists in python?
2,066,213
<p>I'm trying to insert a String into a list.</p> <p>I got this error:</p> <pre><code>TypeError: can only concatenate list (not "tuple") to list </code></pre> <p>because I tried this:</p> <pre><code>var1 = 'ThisIsAString' # My string I want to insert in the following list file_content = open('myfile.txt').readlines...
2
2010-01-14T17:43:41Z
2,066,227
<p>try</p> <pre><code>file_content[:10] + [var1] + rss_xml[11:] </code></pre>
9
2010-01-14T17:45:47Z
[ "python" ]
how to concatenate lists in python?
2,066,213
<p>I'm trying to insert a String into a list.</p> <p>I got this error:</p> <pre><code>TypeError: can only concatenate list (not "tuple") to list </code></pre> <p>because I tried this:</p> <pre><code>var1 = 'ThisIsAString' # My string I want to insert in the following list file_content = open('myfile.txt').readlines...
2
2010-01-14T17:43:41Z
2,066,243
<p>Lists have an insert method, so you could just use that:</p> <pre><code>file_content.insert(10, var1) </code></pre>
3
2010-01-14T17:48:15Z
[ "python" ]
how to concatenate lists in python?
2,066,213
<p>I'm trying to insert a String into a list.</p> <p>I got this error:</p> <pre><code>TypeError: can only concatenate list (not "tuple") to list </code></pre> <p>because I tried this:</p> <pre><code>var1 = 'ThisIsAString' # My string I want to insert in the following list file_content = open('myfile.txt').readlines...
2
2010-01-14T17:43:41Z
2,066,432
<pre><code>file_content = file_content[:10] file_content.append(var1) file_content.extend(rss_xml[11:]) </code></pre>
1
2010-01-14T18:17:18Z
[ "python" ]
how to concatenate lists in python?
2,066,213
<p>I'm trying to insert a String into a list.</p> <p>I got this error:</p> <pre><code>TypeError: can only concatenate list (not "tuple") to list </code></pre> <p>because I tried this:</p> <pre><code>var1 = 'ThisIsAString' # My string I want to insert in the following list file_content = open('myfile.txt').readlines...
2
2010-01-14T17:43:41Z
2,066,445
<p>It's important to note the "list(var1)" is trying to convert var1 to a list. Since var1 is a string, it will be something like:</p> <pre> >>> list('this') ['t', 'h', 'i', 's'] </pre> <p>Or, in other words, it converts the string to a <strong>list</strong> of characters. This is different from creating a list whe...
2
2010-01-14T18:18:17Z
[ "python" ]
How to draw complement of a network graph?
2,066,259
<p>Any function in that Graphviz which can do that? If not, any other free software that can do that?</p>
2
2010-01-14T17:49:57Z
2,066,328
<p>Compute the complement yourself, then plot it.</p>
0
2010-01-14T18:02:10Z
[ "python", "graph", "plot", "graphviz", "complement" ]
How to draw complement of a network graph?
2,066,259
<p>Any function in that Graphviz which can do that? If not, any other free software that can do that?</p>
2
2010-01-14T17:49:57Z
2,073,627
<p>Given that you want to render your graphs in graphviz, i suggest using the python library, <a href="http://networkx.lanl.gov/index.html" rel="nofollow">networkx</a>, to calculate graph complement. Networkx is an excellent library for graph theoretic analysis; it also has a seamless interface with graphviz.</p> <p>(...
5
2010-01-15T17:42:21Z
[ "python", "graph", "plot", "graphviz", "complement" ]
The memory usage reported by guppy differ from ps command
2,066,279
<p>I am profiling my twisted server. It uses much more memory than I expected. Its memory usage grows over time.</p> <pre><code> ps -o pid,rss,vsz,sz,size,command PID RSS VSZ SZ SZ COMMAND 7697 70856 102176 25544 88320 twistd -y broadcast.tac </code></pre> <p>As you can see it costs <strong>102176 KBs</...
7
2010-01-14T17:54:07Z
2,066,360
<p>possibly due to swapping/memory reservation, based on ps's definition:</p> <pre><code>RSS: resident set size, the non-swapped physical memory that a task has used (in kiloBytes). VSZ: virtual memory usage of entire process. vm_lib + vm_exe + vm_data + vm_stack </code></pre> <p>it can be a bit confusing,...
6
2010-01-14T18:07:43Z
[ "python", "memory-management", "twisted", "guppy" ]
The memory usage reported by guppy differ from ps command
2,066,279
<p>I am profiling my twisted server. It uses much more memory than I expected. Its memory usage grows over time.</p> <pre><code> ps -o pid,rss,vsz,sz,size,command PID RSS VSZ SZ SZ COMMAND 7697 70856 102176 25544 88320 twistd -y broadcast.tac </code></pre> <p>As you can see it costs <strong>102176 KBs</...
7
2010-01-14T17:54:07Z
2,164,284
<p>As pointed out above the RSS size is what you're most interested in here. The "Virtual" size includes mapped libraries, which you probably don't want to count.</p> <p>It's been a while since I used heapy, but I am pretty sure the statistics it prints do not include overhead added by heapy itself. This overhead can ...
3
2010-01-29T18:42:24Z
[ "python", "memory-management", "twisted", "guppy" ]
The memory usage reported by guppy differ from ps command
2,066,279
<p>I am profiling my twisted server. It uses much more memory than I expected. Its memory usage grows over time.</p> <pre><code> ps -o pid,rss,vsz,sz,size,command PID RSS VSZ SZ SZ COMMAND 7697 70856 102176 25544 88320 twistd -y broadcast.tac </code></pre> <p>As you can see it costs <strong>102176 KBs</...
7
2010-01-14T17:54:07Z
7,731,851
<p>This isn't a complete answer, but from your manhole, I'd also suggest manually running gc.collect() prior to looking with ps or top. guppy will show the allocated heap, but doesn't do anything to proactively free objects that are no longer allocated.</p>
1
2011-10-11T20:06:21Z
[ "python", "memory-management", "twisted", "guppy" ]
How do I create an extra RSS item element that contains HTML using PyRSS2Gen?
2,066,423
<p>I'm using <a href="http://www.dalkescientific.com/Python/PyRSS2Gen.html" rel="nofollow">PyRSS2Gen</a> to generate an RSS feed. I've succeeded in extending it to add an extra element to each item in the RSS feed:</p> <pre><code>class FullRSSItem(PyRSS2Gen.RSSItem): def __init__(self, **kwargs): if 'cont...
1
2010-01-14T18:16:42Z
2,119,617
<p>I eventually ditched the idea of using the CDATA wrapper and just had the full text be encoded. Seems to work.</p>
0
2010-01-22T18:46:15Z
[ "python", "rss", "cdata" ]
PYTHONPATH issue on a Production server and Namespace challenge
2,066,426
<p>I'm really confused by some errors I'm getting as I'm trying to put an App into production. Everything works fine on the development machine, but I can't syncdb or enter the Django shell on the Production server. I'm getting an error when forum.models.py is attempts to import forum.managers.py because the models are...
0
2010-01-14T18:16:57Z
2,067,407
<p>Your problem is you do:</p> <p>from forum.managers import * (at line 18 models.py) from forum.models import * (at line 6 managers.py)</p> <p>How can that ever work? Try flattening this out (do the imports by hand copying and pasting into a new file) and you'll see why, by the time it executes the line "objects = T...
1
2010-01-14T20:42:41Z
[ "python", "django", "production", "pythonpath" ]
How to disable individual tests temporarily using unittest module in python?
2,066,508
<p>How to disable individual tests temporarily using unittest module in python?</p> <p><a href="https://code.google.com/p/googletest/wiki/AdvancedGuide#Temporarily_Disabling_Tests">Like googletest does.</a></p> <p>Thanks.</p>
18
2010-01-14T18:26:25Z
2,066,538
<p>The <a href="http://docs.python.org/library/unittest.html" rel="nofollow">docs</a> for 2.1 don't specify an ignore or skip method.</p> <p>Usually though, I block comment when needed.</p>
2
2010-01-14T18:30:01Z
[ "python", "unit-testing" ]
How to disable individual tests temporarily using unittest module in python?
2,066,508
<p>How to disable individual tests temporarily using unittest module in python?</p> <p><a href="https://code.google.com/p/googletest/wiki/AdvancedGuide#Temporarily_Disabling_Tests">Like googletest does.</a></p> <p>Thanks.</p>
18
2010-01-14T18:26:25Z
2,066,544
<p><a href="http://docs.python.org/dev/library/unittest.html#unittest-skipping">The latest version (2.7 - unreleased) supports test skipping/disabling like so</a>. You could just get this module and use it on your existing Python install. It will probably work.</p> <p>Before this, I used to rename the tests I wanted s...
9
2010-01-14T18:30:47Z
[ "python", "unit-testing" ]
How to disable individual tests temporarily using unittest module in python?
2,066,508
<p>How to disable individual tests temporarily using unittest module in python?</p> <p><a href="https://code.google.com/p/googletest/wiki/AdvancedGuide#Temporarily_Disabling_Tests">Like googletest does.</a></p> <p>Thanks.</p>
18
2010-01-14T18:26:25Z
2,066,729
<p>You can use decorators to disable the test that can wrap the function and prevent the googletest or python unit test to run the testcase.</p> <pre><code>def disabled(f): def _decorator(): print f.__name__ + ' has been disabled' return _decorator @disabled def testFoo(): '''Foo test case''' ...
19
2010-01-14T18:59:11Z
[ "python", "unit-testing" ]
How to disable individual tests temporarily using unittest module in python?
2,066,508
<p>How to disable individual tests temporarily using unittest module in python?</p> <p><a href="https://code.google.com/p/googletest/wiki/AdvancedGuide#Temporarily_Disabling_Tests">Like googletest does.</a></p> <p>Thanks.</p>
18
2010-01-14T18:26:25Z
2,066,777
<p>I just rename a test case method with an underscore: test_myfunc becomes _test_myfunc.</p>
4
2010-01-14T19:05:43Z
[ "python", "unit-testing" ]
How to disable individual tests temporarily using unittest module in python?
2,066,508
<p>How to disable individual tests temporarily using unittest module in python?</p> <p><a href="https://code.google.com/p/googletest/wiki/AdvancedGuide#Temporarily_Disabling_Tests">Like googletest does.</a></p> <p>Thanks.</p>
18
2010-01-14T18:26:25Z
16,138,561
<pre><code>@unittest.skip("demonstrating skipping") def testFoo(): """Foo test case""" print 'this is foo test case' </code></pre> <p>For more details, see the <code>unittest</code> documentation: <a href="http://docs.python.org/2/library/unittest.html#skipping-tests-and-expected-failures">http://docs.python.o...
40
2013-04-22T02:30:23Z
[ "python", "unit-testing" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,066,618
<p>For point one, see a <a href="http://stackoverflow.com/questions/1174906/tdd-one-test-at-a-time-or-make-a-batch">question</a> I asked a while back relating to your first point.</p> <p>Rather than handle the other points in turn, I'll offer some global advice. Practice. It took me a good while and a few 'dodgy' proj...
1
2010-01-14T18:42:42Z
[ "python", "tdd", "testdrivendesign" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,066,689
<blockquote> <ol> <li>Kent Beck uses a list ... finally now, it's just something like "client should be able to connect to server" (which subsumed server startup etc.).</li> </ol> </blockquote> <p>Often a bad practice.</p> <p>Separate tests for each separate layer of the architecture are good.</p> <p>Consolida...
8
2010-01-14T18:55:00Z
[ "python", "tdd", "testdrivendesign" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,066,691
<p>The the named pipes were put behind the right interface, changing how that interface is implemented (from named pipes to sockets to another sockets library) should only impact tests for the component that implements that interface. So cutting things up more/differently would have helped... That interface the socke...
1
2010-01-14T18:55:09Z
[ "python", "tdd", "testdrivendesign" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,073,703
<blockquote> <p>How do you make such a list to add to and strike out from to guide the development process? I initially had a few items like "server should start up", "server should abort if channel is not available" </p> </blockquote> <p>Items in TDD TODO lists are finer grained than that, they aim at tes...
1
2010-01-15T17:57:23Z
[ "python", "tdd", "testdrivendesign" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,080,013
<p>As a preliminary comment, TDD takes practice. When I look back at the tests I wrote when I began TDD, I see lots of issues, just like when I look at code I wrote a few year ago. Keep doing it, and just like you begin to recognize good code from bad, the same things will happen with your tests - with patience. </p> ...
10
2010-01-17T05:01:14Z
[ "python", "tdd", "testdrivendesign" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,099,843
<blockquote> <p>Q. Kent Beck uses a list which he adds to and strikes out from to guide the development process. How do you make such a list? I initially had a few items like "server should start up", "server should abort if channel is not available" etc. but they got mixed and finally now, it's just something like "...
2
2010-01-20T08:10:51Z
[ "python", "tdd", "testdrivendesign" ]
TDD - beginner problems and stumbling blocks
2,066,593
<p>While I've written unit tests for most of the code I've done, I only recently got my hands on a copy of TDD by example by Kent Beck. I have always regretted certain design decisions I made since they prevented the application from being 'testable'. I read through the book and while some of it looks alien, I felt tha...
21
2010-01-14T18:38:28Z
2,237,912
<p>As a novice programmer, the thing I found tricky about test-driven development was the idea that testing should come first.</p> <p>To the novice, that’s not actually true. Design comes first. (Interfaces, objects and classes, methods, whatever’s appropriate to your language.) Then you write your tests to that. ...
2
2010-02-10T15:23:36Z
[ "python", "tdd", "testdrivendesign" ]
Python syntax and legibility for sequential steps that are sub-items
2,066,595
<p>I like Python's whitespace formatting and legibility. But can you, or is there a common/standard way of delimiting blocks of code that are not to be indented, ie do not belong in nested loops?</p> <p>I have two parts of a procedure that belong inside a main header. Something like step 2 has parts 2.1 and parts 2.2....
1
2010-01-14T18:38:49Z
2,066,603
<p>Put them in separate functions.</p>
5
2010-01-14T18:40:38Z
[ "python", "syntax" ]
Python syntax and legibility for sequential steps that are sub-items
2,066,595
<p>I like Python's whitespace formatting and legibility. But can you, or is there a common/standard way of delimiting blocks of code that are not to be indented, ie do not belong in nested loops?</p> <p>I have two parts of a procedure that belong inside a main header. Something like step 2 has parts 2.1 and parts 2.2....
1
2010-01-14T18:38:49Z
2,066,604
<p>What's wrong with function definitions?</p> <pre><code>def section1( ... ): def section2( ... ): def overall( ... ): section1() section2() </code></pre> <p>If it's so huge that indentation is required, perhaps it's too huge.</p> <p>Also, you can abuse the <code>with</code> statement to "force" indentati...
3
2010-01-14T18:40:45Z
[ "python", "syntax" ]
Python syntax and legibility for sequential steps that are sub-items
2,066,595
<p>I like Python's whitespace formatting and legibility. But can you, or is there a common/standard way of delimiting blocks of code that are not to be indented, ie do not belong in nested loops?</p> <p>I have two parts of a procedure that belong inside a main header. Something like step 2 has parts 2.1 and parts 2.2....
1
2010-01-14T18:38:49Z
2,066,609
<p>You might try splitting this up into multiple functions:</p> <pre><code>def section2(): section21() section22() </code></pre> <p>or something similar. I find using functions not only for purposes of reuse but also organizationally makes my code much more readable and easy to maintain. If the functions need...
1
2010-01-14T18:41:15Z
[ "python", "syntax" ]
Python syntax and legibility for sequential steps that are sub-items
2,066,595
<p>I like Python's whitespace formatting and legibility. But can you, or is there a common/standard way of delimiting blocks of code that are not to be indented, ie do not belong in nested loops?</p> <p>I have two parts of a procedure that belong inside a main header. Something like step 2 has parts 2.1 and parts 2.2....
1
2010-01-14T18:38:49Z
2,066,612
<p>You should not have long functions in Python. Take whitespace dilemmas as a hint.</p>
4
2010-01-14T18:41:36Z
[ "python", "syntax" ]
Python syntax and legibility for sequential steps that are sub-items
2,066,595
<p>I like Python's whitespace formatting and legibility. But can you, or is there a common/standard way of delimiting blocks of code that are not to be indented, ie do not belong in nested loops?</p> <p>I have two parts of a procedure that belong inside a main header. Something like step 2 has parts 2.1 and parts 2.2....
1
2010-01-14T18:38:49Z
2,066,614
<p>I use comments in my code to help me recognize their logical relationship to one-another. If I think that there is some sort of a natural order emerging, I might refactor my code in some way to recognize that, but I never try to mis-use Python's indentation. That's just not what it is meant for. It is syntactical ra...
1
2010-01-14T18:42:01Z
[ "python", "syntax" ]
Python syntax and legibility for sequential steps that are sub-items
2,066,595
<p>I like Python's whitespace formatting and legibility. But can you, or is there a common/standard way of delimiting blocks of code that are not to be indented, ie do not belong in nested loops?</p> <p>I have two parts of a procedure that belong inside a main header. Something like step 2 has parts 2.1 and parts 2.2....
1
2010-01-14T18:38:49Z
2,066,638
<p>I'm surprised you'd consider indenting your code like this even in languages that allow it. How do your team members feel about this? I'd find it very confusing to have indented code that didn't correspond to a block.</p>
1
2010-01-14T18:46:39Z
[ "python", "syntax" ]
GUI not updated from another thread when using PyGtk
2,066,767
<p>I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?</p>
4
2010-01-14T19:04:40Z
2,067,868
<p>GTK+ is not thread-safe, so you should not simply call GUI update methods from other threads. <a href="http://pygtk.org/docs/pygobject/glib-functions.html#function-glib--idle-add">glib.idle_add</a> (or gobject.idle_add in older PyGTK versions) can be used for this purpose.</p> <p>Instead of writing:</p> <pre><code...
10
2010-01-14T21:58:29Z
[ "python", "multithreading", "pygtk" ]
GUI not updated from another thread when using PyGtk
2,066,767
<p>I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?</p>
4
2010-01-14T19:04:40Z
2,069,788
<p>the same may be achieved using gobject.idle_add method whose syntax is same as above,you have to import the module gobject</p>
-1
2010-01-15T06:06:33Z
[ "python", "multithreading", "pygtk" ]
GUI not updated from another thread when using PyGtk
2,066,767
<p>I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?</p>
4
2010-01-14T19:04:40Z
2,069,935
<p>As stated in the previous answers, GTK is not "thread safe," but it is "thread-aware" - see this page on Threads: <a href="http://library.gnome.org/devel/gdk/unstable/gdk-Threads.html" rel="nofollow">https://developer.gnome.org/gdk2/stable/gdk2-Threads.html</a></p> <p>In order to modify GTK widgets from another thr...
2
2010-01-15T06:49:05Z
[ "python", "multithreading", "pygtk" ]
GUI not updated from another thread when using PyGtk
2,066,767
<p>I am using PyGTK to build a GUI application. I want to update the textview widget from another thread but the widget is not getting updated everytime i try an update. What should i do to get a reliable GUI updating?</p>
4
2010-01-14T19:04:40Z
3,030,804
<p>What Johannes said is correct, however since GTK is a wrapper for the glib and gobject things, you would actually want to use gtk.idle_add(). No need for the unnecessary imports.</p>
-1
2010-06-13T01:59:14Z
[ "python", "multithreading", "pygtk" ]
Does the TCPServer + BaseRequestHandler in Python's SocketServer close the socket after each call to handle()?
2,066,810
<p>I'm writing a client/server application in Python and I'm finding it necessary to get a new connection to the server for each request from the client. My server is just inheriting from TCPServer and I'm inheriting from BaseRequestHandler to do my processing. I'm not calling self.request.close() anywhere in the handl...
7
2010-01-14T19:09:21Z
2,066,907
<p>You sure the client is not hanging up on the server? This is a bit too vague to really tell what is up, but generally a server that is accepting data from a client will quit the connection of the read returns no data.</p>
0
2010-01-14T19:25:41Z
[ "python", "sockets" ]
Does the TCPServer + BaseRequestHandler in Python's SocketServer close the socket after each call to handle()?
2,066,810
<p>I'm writing a client/server application in Python and I'm finding it necessary to get a new connection to the server for each request from the client. My server is just inheriting from TCPServer and I'm inheriting from BaseRequestHandler to do my processing. I'm not calling self.request.close() anywhere in the handl...
7
2010-01-14T19:09:21Z
2,069,486
<p><em>According to the docs</em>, neither TCPServer nor BaseRequestHandler close the socket unless prompted to do so. The default implementations of both <code>handle()</code> and <code>finish()</code> do nothing. </p> <p>A couple of things might be happening:</p> <ul> <li>You are closing the socket itself or the ...
6
2010-01-15T04:19:31Z
[ "python", "sockets" ]
Does the TCPServer + BaseRequestHandler in Python's SocketServer close the socket after each call to handle()?
2,066,810
<p>I'm writing a client/server application in Python and I'm finding it necessary to get a new connection to the server for each request from the client. My server is just inheriting from TCPServer and I'm inheriting from BaseRequestHandler to do my processing. I'm not calling self.request.close() anywhere in the handl...
7
2010-01-14T19:09:21Z
2,072,002
<p>Okay, I read the code (on my Mac, SocketServer.py is at /System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/).</p> <p>Indeed, TCPServer is closing the connection. In <code>BaseServer.handle_request</code>, <code>process_request</code> is called, which calls <code>close_request</code>. In the TCP...
5
2010-01-15T14:02:11Z
[ "python", "sockets" ]
Does the TCPServer + BaseRequestHandler in Python's SocketServer close the socket after each call to handle()?
2,066,810
<p>I'm writing a client/server application in Python and I'm finding it necessary to get a new connection to the server for each request from the client. My server is just inheriting from TCPServer and I'm inheriting from BaseRequestHandler to do my processing. I'm not calling self.request.close() anywhere in the handl...
7
2010-01-14T19:09:21Z
3,349,729
<ol> <li>tcpserver really close connection each time after 'handle'</li> <li><p>the follow code doesn't work while peer closing</p> <pre><code>def handle(self): while 1: try: data = self.request.recv(1024) print self.client_address, "sent", data except: pass </code></pre> <p>this m...
5
2010-07-28T03:34:51Z
[ "python", "sockets" ]
Accessing a dict by variable in Django templates?
2,067,006
<p>My view code looks basically like this:</p> <pre><code>context = Context() context['my_dict'] = {'a': 4, 'b': 8, 'c': 15, 'd': 16, 'e': 23, 'f': 42 } context['my_list'] = ['d', 'f', 'e', 'b', 'c', 'a'] </code></pre> <p>And what I'd like to do in my Django template is this:</p> <pre><code>&lt;ul&gt; {% for item i...
25
2010-01-14T19:37:43Z
2,067,093
<p>There's no builtin way to do that, you'd need to write a simple template filter to do this: <a href="http://code.djangoproject.com/ticket/3371">http://code.djangoproject.com/ticket/3371</a></p>
14
2010-01-14T19:48:43Z
[ "python", "django", "django-templates" ]
Accessing a dict by variable in Django templates?
2,067,006
<p>My view code looks basically like this:</p> <pre><code>context = Context() context['my_dict'] = {'a': 4, 'b': 8, 'c': 15, 'd': 16, 'e': 23, 'f': 42 } context['my_list'] = ['d', 'f', 'e', 'b', 'c', 'a'] </code></pre> <p>And what I'd like to do in my Django template is this:</p> <pre><code>&lt;ul&gt; {% for item i...
25
2010-01-14T19:37:43Z
4,661,415
<p>Here's a usage case of the suggested answer.</p> <p>In this example, I created a generic template for outputting tabular data from a view. Meta data about the columns is held in context["columnMeta"].</p> <p>Since this is a dictionary, i cannot rely on the keys to output the columns in order, so i have the keys i...
5
2011-01-11T18:49:15Z
[ "python", "django", "django-templates" ]
Accessing a dict by variable in Django templates?
2,067,006
<p>My view code looks basically like this:</p> <pre><code>context = Context() context['my_dict'] = {'a': 4, 'b': 8, 'c': 15, 'd': 16, 'e': 23, 'f': 42 } context['my_list'] = ['d', 'f', 'e', 'b', 'c', 'a'] </code></pre> <p>And what I'd like to do in my Django template is this:</p> <pre><code>&lt;ul&gt; {% for item i...
25
2010-01-14T19:37:43Z
11,395,241
<p>Try this to display the keys and values of the dictionary:</p> <pre><code>{% for key, value in your_dict.items %} {{ key }}: {{ value }} {% endfor %} </code></pre> <p><a href="https://docs.djangoproject.com/en/dev/ref/templates/builtins/#for" rel="nofollow">https://docs.djangoproject.com/en/dev/ref/templates/b...
4
2012-07-09T12:42:29Z
[ "python", "django", "django-templates" ]
Accessing a dict by variable in Django templates?
2,067,006
<p>My view code looks basically like this:</p> <pre><code>context = Context() context['my_dict'] = {'a': 4, 'b': 8, 'c': 15, 'd': 16, 'e': 23, 'f': 42 } context['my_list'] = ['d', 'f', 'e', 'b', 'c', 'a'] </code></pre> <p>And what I'd like to do in my Django template is this:</p> <pre><code>&lt;ul&gt; {% for item i...
25
2010-01-14T19:37:43Z
20,523,607
<p>For my needs, I wanted a single template filter that would work for dicts, lists, and tuples. So, here's what I use:</p> <pre><code>@register.filter def get_item(container, key): if type(container) is dict: return container.get(key) elif type(container) in (list, tuple): return container[ke...
0
2013-12-11T15:47:34Z
[ "python", "django", "django-templates" ]
Accessing parallel arrays in Django templates?
2,067,036
<p>My view code looks basically like this:</p> <pre><code>context = Context() context['some_values'] = ['a', 'b', 'c', 'd', 'e', 'f'] context['other_values'] = [4, 8, 15, 16, 23, 42] </code></pre> <p>I would like my template code to look like this:</p> <pre><code>{% for some in some_values %} {% with index as fo...
4
2010-01-14T19:42:16Z
2,067,071
<p><code>zip(some_values, other_values)</code>, then use it in template</p> <pre><code>from itertools import izip some_values = ['a', 'b', 'c', 'd', 'e', 'f'] other_values = [4, 8, 15, 16, 23, 42] context['zipped_values'] = izip(some_values, other_values) {% for some, other in zipped_values %} {{ some }}: {{ othe...
8
2010-01-14T19:46:30Z
[ "python", "django", "django-templates" ]
Seasonal adjustment in Python and Scipy
2,067,095
<p>I am looking to seasonally adjust monthly data, using Python. As you can see from these series: <a href="http://www.emconfidential.com/" rel="nofollow" title="Graphs">www.emconfidential.com</a>, there is a high seasonal component to the data. I would like to adjust for this so that I can better guage if the series ...
4
2010-01-14T19:48:53Z
2,067,189
<p>Not sure on the programming aspect of this but I would seriously consider moving averages to solve this.</p>
-1
2010-01-14T20:01:07Z
[ "python", "scipy" ]
Seasonal adjustment in Python and Scipy
2,067,095
<p>I am looking to seasonally adjust monthly data, using Python. As you can see from these series: <a href="http://www.emconfidential.com/" rel="nofollow" title="Graphs">www.emconfidential.com</a>, there is a high seasonal component to the data. I would like to adjust for this so that I can better guage if the series ...
4
2010-01-14T19:48:53Z
2,067,423
<p>There's no magical python library that will do seasonal adjustments for you. Applications that do this kind of thing tend to be <a href="http://www.census.gov/srd/www/x12a/" rel="nofollow">rather large</a>.</p> <p>You'll need to work out the maths <a href="http://www.dst.dk/upload/seasonal.pdf" rel="nofollow">yours...
2
2010-01-14T20:44:15Z
[ "python", "scipy" ]
Seasonal adjustment in Python and Scipy
2,067,095
<p>I am looking to seasonally adjust monthly data, using Python. As you can see from these series: <a href="http://www.emconfidential.com/" rel="nofollow" title="Graphs">www.emconfidential.com</a>, there is a high seasonal component to the data. I would like to adjust for this so that I can better guage if the series ...
4
2010-01-14T19:48:53Z
28,969,443
<p>Statsmodels can do this. They have a basic seasonal decomposition and also a wrapper to Census X13 adjustment. You could also use rpy2 to access some of R's excellent SA libraries. Here is statsmodels seasonal decomp:</p> <pre><code>import pandas as pd import statsmodels.api as sm import matplotlib.pyplot as plt...
1
2015-03-10T16:46:33Z
[ "python", "scipy" ]
Seasonal adjustment in Python and Scipy
2,067,095
<p>I am looking to seasonally adjust monthly data, using Python. As you can see from these series: <a href="http://www.emconfidential.com/" rel="nofollow" title="Graphs">www.emconfidential.com</a>, there is a high seasonal component to the data. I would like to adjust for this so that I can better guage if the series ...
4
2010-01-14T19:48:53Z
39,645,355
<p>There is now a package that seems to be exactly what you are looking for! Check out the <code>seasonal</code> package, here is the <a href="https://pypi.python.org/pypi/seasonal/0.3.1" rel="nofollow">link</a>. I personally found it to be very useful, wondering what others think.</p>
1
2016-09-22T17:29:53Z
[ "python", "scipy" ]
Does Django logs usernames internally
2,067,185
<p>All..</p> <p>I have a Django site and to access it all the users have to go through the login page.</p> <p>My question is when a user is given a access through the login page to enter the site.Does Django logs the username in any of the Django internal tables....</p> <p>Thanks.......</p>
1
2010-01-14T20:00:10Z
2,067,231
<p>Yes, the <code>last_login</code> column of the user's record in table <code>auth_user</code> is updated with the date/time of the successful login.</p>
2
2010-01-14T20:08:30Z
[ "python", "django", "logging" ]
django select query--how do I make this?
2,067,268
<pre><code>class Content(models.Model): .....stuff here class Score(models.Model): content = models.OneToOneField(Content, primary_key=True) real_score = models.IntegerField(default=0) </code></pre> <p>This is my database schema. As you can see, each Content has a score. How do I do this:</p> <p>Select ...
1
2010-01-14T20:16:23Z
2,067,283
<p><code>Content.objects.filter(score__real_score=1)</code></p>
5
2010-01-14T20:18:20Z
[ "python", "mysql", "database", "django" ]
Get a C reference to an embedded python function by name?
2,067,496
<p>Assuming I have some embedded python code containing a function foo, what is the best way to get a reference to that function (for use with PyObject_CallObject)?</p> <p>One way is to have some function register each function along with the function name either manually or through use of reflection. This seems like ...
0
2010-01-14T20:58:01Z
2,067,575
<p>Read the section in the documentation about <a href="http://docs.python.org/extending/embedding.html#pure-embedding" rel="nofollow">embedding Python</a>. I guess you have a reference to the module containing the function. At the end there is an example which shows how to get a function reference out of an object.</p...
1
2010-01-14T21:07:24Z
[ "python", "c", "embedded-language" ]
mysqldb pulls whole query result in one chunk always even if I just do a fetchone?
2,067,529
<p>So if I do</p> <pre><code> import MySQLdb conn = MySQLdb.connect(...) cur = conn.cursor() cur.execute("SELECT * FROM HUGE_TABLE") print "hello?" print cur.fetchone() </code></pre> <p>It looks to me that MySQLdb gets the entire huge table before it gets to the "print". I previously assumed it did some sort of...
5
2010-01-14T21:01:40Z
2,067,574
<p>This is correct in every other language I've used. The fetchone is just going to only retrieve the first row of the resultset which in this case is the entire database. It's more of a convenience method than anything, it's designed to be easier to use if you KNOW that there's only one result coming down or you only ...
0
2010-01-14T21:07:15Z
[ "python", "mysql" ]
mysqldb pulls whole query result in one chunk always even if I just do a fetchone?
2,067,529
<p>So if I do</p> <pre><code> import MySQLdb conn = MySQLdb.connect(...) cur = conn.cursor() cur.execute("SELECT * FROM HUGE_TABLE") print "hello?" print cur.fetchone() </code></pre> <p>It looks to me that MySQLdb gets the entire huge table before it gets to the "print". I previously assumed it did some sort of...
5
2010-01-14T21:01:40Z
2,067,590
<p>In the <strong><code>_mysql</code></strong> module, use the following call:</p> <pre><code>conn.use_result() </code></pre> <p>That tells the connection you want to fetch rows one by one, leaving the remainder on the server (but leaving the cursor open).</p> <p>The alternative (and the default) is:</p> <pre><code...
4
2010-01-14T21:09:10Z
[ "python", "mysql" ]
mysqldb pulls whole query result in one chunk always even if I just do a fetchone?
2,067,529
<p>So if I do</p> <pre><code> import MySQLdb conn = MySQLdb.connect(...) cur = conn.cursor() cur.execute("SELECT * FROM HUGE_TABLE") print "hello?" print cur.fetchone() </code></pre> <p>It looks to me that MySQLdb gets the entire huge table before it gets to the "print". I previously assumed it did some sort of...
5
2010-01-14T21:01:40Z
2,069,116
<p><a href="http://packages.python.org/oursql/" rel="nofollow">oursql</a> is an alternative MySQL DB-API interface that exposes a few more of the lower-level details, and also provides other facilities for dealing with large datasets.</p>
0
2010-01-15T02:43:27Z
[ "python", "mysql" ]
python list of dicts how to merge key:value where values are same?
2,067,627
<p>Python newb here looking for some assistance...</p> <p>For a variable number of dicts in a python list like:</p> <pre><code>list_dicts = [ {'id':'001', 'name':'jim', 'item':'pencil', 'price':'0.99'}, {'id':'002', 'name':'mary', 'item':'book', 'price':'15.49'}, {'id':'002', 'name':'mary', 'item':'tape', 'price':'7....
9
2010-01-14T21:15:38Z
2,067,748
<p>I imagine it would be easier to combine the items in list_dicts into something that looks more like this:</p> <p><code>list_dicts2 = [{'id':1, 'name':'jim', 'items':[{'itemname':'pencil','price':'0.99'}], {'id':2, 'name':'mary', 'items':[{'itemname':'book','price':'15.49'}, {'itemname':'tape','price':'7.99'}]]</cod...
-1
2010-01-14T21:35:19Z
[ "python", "list", "merge", "dictionary" ]
python list of dicts how to merge key:value where values are same?
2,067,627
<p>Python newb here looking for some assistance...</p> <p>For a variable number of dicts in a python list like:</p> <pre><code>list_dicts = [ {'id':'001', 'name':'jim', 'item':'pencil', 'price':'0.99'}, {'id':'002', 'name':'mary', 'item':'book', 'price':'15.49'}, {'id':'002', 'name':'mary', 'item':'tape', 'price':'7....
9
2010-01-14T21:15:38Z
2,067,922
<p>This looks very much like a homework problem.</p> <p>As the above poster mentioned, there are a few more appropriate data structures for this kind of data, some variant on the following might be reasonable:</p> <pre><code>[ ('001', 'jim', [('pencil', '0.99')]), ('002', 'mary', [('book', '15.49'), ('tape', '7.99')...
0
2010-01-14T22:07:18Z
[ "python", "list", "merge", "dictionary" ]
python list of dicts how to merge key:value where values are same?
2,067,627
<p>Python newb here looking for some assistance...</p> <p>For a variable number of dicts in a python list like:</p> <pre><code>list_dicts = [ {'id':'001', 'name':'jim', 'item':'pencil', 'price':'0.99'}, {'id':'002', 'name':'mary', 'item':'book', 'price':'15.49'}, {'id':'002', 'name':'mary', 'item':'tape', 'price':'7....
9
2010-01-14T21:15:38Z
2,068,064
<p>Try to avoid complex nested data structures. I believe people tend to grok them only while they are intensively using the data structure. After the program is finished, or is set aside for a while, the data structure quickly becomes mystifying.</p> <p>Objects can be used to retain or even add richness to the data ...
9
2010-01-14T22:35:54Z
[ "python", "list", "merge", "dictionary" ]
Utilities or libraries for finding most closely matched binary file
2,067,628
<p>I would like to be able to compare a binary file X to a directory of other binary files and find which other file is most similar to X. The nature of the data is such that identical chunks will exist between files, but possibly shifted in location. The files are all 1MB in size, and there are about 200 of them. ...
0
2010-01-14T21:15:40Z
2,067,652
<p>Here's <a href="http://www.spinellis.gr/blog/20040319/index.html" rel="nofollow">a simple perl script</a> which more or less tries to do exactly that.</p> <p>Edit: Also have a look at <a href="http://stackoverflow.com/questions/579981/calculating-binary-data-similarity">the following stackoverflow thread</a>.</p>
0
2010-01-14T21:20:38Z
[ "python", "diff", "utility" ]
How do I increase the stack size in python
2,067,637
<p>I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca().</p> <p>I want to increase stack size to get rid of this error. Is there any way to do this?</p>
3
2010-01-14T21:17:02Z
2,067,700
<p>The functions in a dll can have no control over the stack size available when they are executed (unless you spawn new threads under the control of your library).</p> <p>If the dll is custom, then can't you allocate on the heap rather than stack (or statically allocate, if appropriate), and stop the problem that way...
2
2010-01-14T21:28:27Z
[ "python", "dll", "stack" ]
How do I increase the stack size in python
2,067,637
<p>I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca().</p> <p>I want to increase stack size to get rid of this error. Is there any way to do this?</p>
3
2010-01-14T21:17:02Z
2,067,732
<p>AFAIK a program can only change the stack size of new threads or processes (Windows' <a href="http://msdn.microsoft.com/en-us/library/ms682453%28VS.85%29.aspx" rel="nofollow">CreateThread</a> function, for example). As Python (and the Win32 API for Python) does not expose such functionality, you should rather replac...
2
2010-01-14T21:32:47Z
[ "python", "dll", "stack" ]
How do I increase the stack size in python
2,067,637
<p>I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca().</p> <p>I want to increase stack size to get rid of this error. Is there any way to do this?</p>
3
2010-01-14T21:17:02Z
2,067,758
<p>The python <a href="http://docs.python.org/library/thread.html">thread module</a> allows you to specify a new <a href="http://docs.python.org/library/thread.html#thread.stack_size">stack size</a> for new threads. Try setting that to a value you feel is large enough, and then doing the work of this DLL in a new threa...
6
2010-01-14T21:36:04Z
[ "python", "dll", "stack" ]
How do I increase the stack size in python
2,067,637
<p>I have a python program that uses a custom-built DLL. This DLL crashes due to a stack overflow. This overflow is not due to a recursive function gone bad, but to large allocations on the stack using alloca().</p> <p>I want to increase stack size to get rid of this error. Is there any way to do this?</p>
3
2010-01-14T21:17:02Z
33,662,536
<p>As noted in some related questions <a href="http://stackoverflow.com/a/2711177/106275">like here</a>, it's generally not a good idea to play with the stack size to extend the recursion depth, but here's code that shows how to grow the stack to that effect. With python 3.5, on a Windows 10 x64 system, it demonstrates...
0
2015-11-12T00:39:37Z
[ "python", "dll", "stack" ]
How to fetch some data conditionally with Python and Beautiful Soup
2,067,710
<p>Sorry if you feel like this has been asked but I have read the related questions and being quite new to Python I could not find how to write this request in a clean manner.</p> <p>For now I have this minimal Python code:</p> <pre><code>from mechanize import Browser from BeautifulSoup import BeautifulSoup import r...
1
2010-01-14T21:29:56Z
2,067,965
<p>Searching for the players using your method will work, but will return 3 results per player. Easier to search for the table itself, and then iterate over the rows (except the header):</p> <pre><code>table=soup.find('table', 'bioTableAlt') for row in table.findAll('tr')[1:]: cells = row.findAll('td') #retrei...
3
2010-01-14T22:16:45Z
[ "python", "beautifulsoup" ]
Efficient method to store Python dictionary on disk?
2,067,749
<p>What is the most efficient method to store a Python dictionary on the disk? The only methods I know of right now are plain-text and the <code>pickle</code> module.</p> <p><strong>Edit:</strong> Sorry for not being very clear. By efficient I meant fastest execution speed. The dictionary will contain mutable objects ...
2
2010-01-14T21:35:20Z
2,067,757
<p><a href="http://docs.python.org/library/shelve.html" rel="nofollow">shelve</a> is pretty nice as well</p> <p>or <a href="http://code.activestate.com/recipes/576642/" rel="nofollow">this persistent dictionary recipe</a></p> <p>for a convenient method that keeps your objects synchronized with storage, there's the OR...
8
2010-01-14T21:36:03Z
[ "python", "dictionary", "disk", "pickle" ]
Efficient method to store Python dictionary on disk?
2,067,749
<p>What is the most efficient method to store a Python dictionary on the disk? The only methods I know of right now are plain-text and the <code>pickle</code> module.</p> <p><strong>Edit:</strong> Sorry for not being very clear. By efficient I meant fastest execution speed. The dictionary will contain mutable objects ...
2
2010-01-14T21:35:20Z
2,068,000
<p>JSON and YAML work well, also. </p> <p>Depends on what you mean by "efficient"? Size of file? Time required? Amount of code you need to write?</p> <p>You have the <code>timeit</code> module available to determine what meets your specific criteria for "efficient".</p>
2
2010-01-14T22:23:01Z
[ "python", "dictionary", "disk", "pickle" ]
Broken Pipe from subprocess.Popen.communciate() with stdin
2,067,852
<p>I'm having a strange issue when using subprocess.Popen.communicate(). For background, I want to execute an application from my python script. When I run the program from the command line, I do it like this (UNIX):</p> <pre> $ echo "input text" | /path/to/myapp </pre> <p>From my script, I also want to pipe the in...
3
2010-01-14T21:55:48Z
2,068,329
<p>Your observation suggests that myapp is terminating without reading (all of the) input. Not knowing anything about myapp, that's hard to confirm, but consider for example</p> <pre><code>$ echo 'hello world' | tr 'l' 'L' heLLo worLd </code></pre> <p>now...:</p> <pre><code>&gt;&gt;&gt; cmd = ['/usr/bin/tr'] &gt;&g...
3
2010-01-14T23:31:59Z
[ "python" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,067,929
<p>Python (combined with PyQt) is a very solid combination for GUI desktop applications (note that while QT is LGPL, PyQt (the Python bindings) is dual licensed: GPL or commercial).</p> <p>It offers the same (GUI library-wise) as Qt on C++ but with Python's specific strenghts. I'll list some of the more obvious ones:<...
3
2010-01-14T22:09:26Z
[ "python", "ruby", "perl", "scripting" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,067,953
<p><a href="http://www.pygtk.org/applications.html" rel="nofollow">http://www.pygtk.org/applications.html</a></p> <p>Seems like a really long list of GUI applications in Python using just one of the frameworks.</p>
0
2010-01-14T22:14:32Z
[ "python", "ruby", "perl", "scripting" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,067,954
<p>Some part of <a href="http://www.mcs.anl.gov/research/projects/mpich2/" rel="nofollow">MPICH2</a> is written in Python. I didn't check everything, but many parts of it used for running mpi applications are written it Python. Maybe MPICH2 is not used by everyone, but for sure it is good piece of software. </p>
0
2010-01-14T22:14:41Z
[ "python", "ruby", "perl", "scripting" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,067,958
<p>The languages you list aren't really scripting languages, as that tends to describe languages designed to work inside of a larger framework (like javascript) that provides its interface to the world. While you can certainly write scripts in those languages, each is a proper programming language (referred to as a dy...
4
2010-01-14T22:15:25Z
[ "python", "ruby", "perl", "scripting" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,068,161
<p>The company I work for uses Perl and Tk with PerlApp to build executable packages to produce or major software application.</p> <p>Perl beats C and C++ for simplicity of code. You can do things in one line of Perl that take 20 lines of C.</p> <p>We've used WxPerl for a few smaller projects. We'd like to move ful...
6
2010-01-14T22:57:01Z
[ "python", "ruby", "perl", "scripting" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,068,564
<p>I have used a number of programs that were developed using scripted languages. Several embedded device vendors ship my group Windows-based configuration and debugging utilities written in TCL. Google's drawing program SketchUp has a lot of Ruby inside it (and users can create add-ons using Ruby). I have seen many...
1
2010-01-15T00:21:28Z
[ "python", "ruby", "perl", "scripting" ]
"Real" and non-embedded use of Ruby, Python and their friends
2,067,907
<p>So I'm aware of the big ammount of general-purpose scripting languages like Ruby, Python, Perl, maybe even PHP, etc. that actually claim being usable for creating desktop applications too.</p> <p>I think my question can be answered clearly</p> <ul> <li><p>Are there actually companies using a special scripting lang...
3
2010-01-14T22:03:35Z
2,072,473
<p>I would recommend you not try to look for a language that is best for GUI apps but instead look for the language that you like the most and then use that to write your app.</p> <p>Ruby, Python, Perl all have GUI tool kits available to them. Most of them have access to the same often used tool kits like TK, GTK, and...
2
2010-01-15T15:03:58Z
[ "python", "ruby", "perl", "scripting" ]
Error in using Python/mechanize select_form()?
2,067,915
<p>I am trying to scrap some data from a website. The scripts I am trying to write, should get the content of the page:</p> <pre><code>http://www.atpworldtour.com/Rankings/Singles.aspx </code></pre> <p>Should simulate the user going trough every option for Additional Standings and the dates and simulate clicking on G...
2
2010-01-14T22:05:27Z
2,078,827
<p>I think you are using the library correctly, but the parser seems to be having trouble with that particular page. I'm using the library in the same way on another page ("http://flashcarddb.com/login") and it does not raise an error.</p>
1
2010-01-16T20:33:35Z
[ "python", "mechanize", "web-scraping" ]
Error in using Python/mechanize select_form()?
2,067,915
<p>I am trying to scrap some data from a website. The scripts I am trying to write, should get the content of the page:</p> <pre><code>http://www.atpworldtour.com/Rankings/Singles.aspx </code></pre> <p>Should simulate the user going trough every option for Additional Standings and the dates and simulate clicking on G...
2
2010-01-14T22:05:27Z
4,081,248
<p>I just ran into this same problem. The page I was accessing passed W3C validation, so I didn't think it was a markup problem. However, html tidy complained that the page had a within a . Once I fixed that, mechanize started working.</p> <p>Also, I saw a reply to this issue on a mailing list. I'd just like to note ...
1
2010-11-02T19:09:51Z
[ "python", "mechanize", "web-scraping" ]
Error in using Python/mechanize select_form()?
2,067,915
<p>I am trying to scrap some data from a website. The scripts I am trying to write, should get the content of the page:</p> <pre><code>http://www.atpworldtour.com/Rankings/Singles.aspx </code></pre> <p>Should simulate the user going trough every option for Additional Standings and the dates and simulate clicking on G...
2
2010-01-14T22:05:27Z
4,360,508
<p>Clue : define MORE about your mechanize.Browser()</p>
0
2010-12-05T18:45:18Z
[ "python", "mechanize", "web-scraping" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
2,068,311
<p>I worked on the periphery of a cool framework that implements several Music Information Retrieval techniques. I'm hardly an expert (edit: actually i'm nowhere close to an expert, just to clarify), but I can tell that that the Fast Fourier Transform is used all over the place with this stuff. Fourier analysis is wa...
10
2010-01-14T23:27:41Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
2,068,322
<p>Its been a while since i last did signal processing, but rather than downsampling you should look at frequency-domain representations (eg FFT or DCT). Then you could make a hash of sorts and search for the database song with that sequence in.</p> <p>Tricky part is making this search fast (maybe some papers on gene ...
1
2010-01-14T23:30:43Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
2,068,375
<p>MFCC extracted from the music is very useful in finding the timbrel similarity between songs.. this is most often used to find similar songs. As pointed by darren, Marsyas is a tool that can be used to extract MFCC and find similar songs by converting the MFCC in to a single vector representation.. </p> <p>Other th...
3
2010-01-14T23:40:51Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
2,068,424
<p>I did read a paper about the method in which a certain music information retrieval service (no names mentioned) does it - by calculating the Short Time Fourier transform over the sample of audio. The algorithm then picks out 'peaks' in the frequency domain i.e. time positions and frequencies that are particularly hi...
1
2010-01-14T23:53:59Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
2,072,606
<p>I do research in music information retrieval (MIR). The seminal paper on music fingerprinting is the one by Haitsma and Kalker around 2002-03. Google should get you it.</p> <p>I read an early (really early; before 2000) white paper about Shazam's method. At that point, they just basically detected spectrotemporal p...
11
2010-01-15T15:20:28Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
2,081,172
<p>Currently I'm developing a music search engine using ActionScript 3. The idea is analyzing the chords first and marking the frames (it's limited to mp3 files at the moment) where the frequency changes drastically (melody changes and ignoring noises). After that I do the same thing to the input sound, and match the r...
1
2010-01-17T13:56:53Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
13,323,713
<p>The <a href="http://musicbrainz.org/" rel="nofollow">MusicBrainz project</a> maintains such a database. You can make queries to it based on a fingerprint.</p> <p>The project exists already since a while and has used different fingerprints in the past. See <a href="http://musicbrainz.org/doc/Fingerprinting" rel="nof...
1
2012-11-10T16:20:49Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
24,088,165
<p>I recently ported my audio landmark-based fingerprinting system to Python:</p> <p><a href="https://github.com/dpwe/audfprint" rel="nofollow">https://github.com/dpwe/audfprint</a></p> <p>It can recognize small (5-10 sec) excerpts from a reference database of 10s of thousands of tracks, and is quite robust to noise ...
3
2014-06-06T18:09:31Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Music Recognition and Signal Processing
2,068,286
<p>I want to <strong>build something similar to <a href="http://www.wildbits.com/tunatic/">Tunatic</a> or <a href="http://www.midomi.com/">Midomi</a></strong> (try them out if you're not sure what they do) and I'm wondering what algorithms I'd have to use; The idea I have about the workings of such applications is some...
12
2010-01-14T23:21:37Z
32,577,503
<p>For query by humming feature, it is more complicate than the audio fingerprinting solution, the difficult comes from: </p> <ul> <li>how to efficiently collect the melody database in real world application? many demo system use midi to build-up, but midi solution's cost is extremely not affordable for a company. </l...
0
2015-09-15T04:02:20Z
[ "php", "python", "audio", "signal-processing", "audio-processing" ]
Understanding .get() method in Python
2,068,349
<pre><code>sentence = "The quick brown fox jumped over the lazy dog." characters = {} for character in sentence: characters[character] = characters.get(character, 0) + 1 print(characters) </code></pre> <p>I don't understand what <code>characters.get(character, 0) + 1</code> is doing, rest all seems pretty strai...
38
2010-01-14T23:35:11Z
2,068,360
<p>Start here <a href="http://docs.python.org/tutorial/datastructures.html#dictionaries" rel="nofollow">http://docs.python.org/tutorial/datastructures.html#dictionaries</a></p> <p>Then here <a href="http://docs.python.org/library/stdtypes.html#mapping-types-dict" rel="nofollow">http://docs.python.org/library/stdtypes....
8
2010-01-14T23:37:18Z
[ "python" ]
Understanding .get() method in Python
2,068,349
<pre><code>sentence = "The quick brown fox jumped over the lazy dog." characters = {} for character in sentence: characters[character] = characters.get(character, 0) + 1 print(characters) </code></pre> <p>I don't understand what <code>characters.get(character, 0) + 1</code> is doing, rest all seems pretty strai...
38
2010-01-14T23:35:11Z
2,068,377
<p>The <code>get</code> method of a dict (like for example <code>characters</code> works just like indexing the dict, except that, if the key is missing, instead of raising a <code>KeyError</code> it returns the default value (if you call <code>.get</code> with just one argument, the key, the default value is <code>Non...
52
2010-01-14T23:41:22Z
[ "python" ]
Understanding .get() method in Python
2,068,349
<pre><code>sentence = "The quick brown fox jumped over the lazy dog." characters = {} for character in sentence: characters[character] = characters.get(character, 0) + 1 print(characters) </code></pre> <p>I don't understand what <code>characters.get(character, 0) + 1</code> is doing, rest all seems pretty strai...
38
2010-01-14T23:35:11Z
2,068,414
<p>If d is a dictionary, then <code>d.get(k, v)</code> means, give me the value of k in d, unless k isn't there, in which case give me v. It's being used here to get the current count of the character, which should start at 0 if the character hasn't been encountered before.</p>
5
2010-01-14T23:52:32Z
[ "python" ]
Understanding .get() method in Python
2,068,349
<pre><code>sentence = "The quick brown fox jumped over the lazy dog." characters = {} for character in sentence: characters[character] = characters.get(character, 0) + 1 print(characters) </code></pre> <p>I don't understand what <code>characters.get(character, 0) + 1</code> is doing, rest all seems pretty strai...
38
2010-01-14T23:35:11Z
20,326,912
<p>To understand what is going on, let's take one letter(repeated more than once) in the <strong>sentence</strong> string and follow what happens when it goes through the loop. </p> <p>Remember that we start off with an empty <strong>characters</strong> dictionary </p> <pre><code>characters = {} </code></pre> <p>I w...
9
2013-12-02T11:13:29Z
[ "python" ]
Understanding .get() method in Python
2,068,349
<pre><code>sentence = "The quick brown fox jumped over the lazy dog." characters = {} for character in sentence: characters[character] = characters.get(character, 0) + 1 print(characters) </code></pre> <p>I don't understand what <code>characters.get(character, 0) + 1</code> is doing, rest all seems pretty strai...
38
2010-01-14T23:35:11Z
21,386,309
<p>I see this is a fairly old question, but this looks like one of those times when something's been written without knowledge of a language feature. The <code>collections</code> library exists to fulfill these purposes.</p> <pre><code>from collections import Counter letter_counter = Counter() for letter in 'The quick...
1
2014-01-27T16:35:49Z
[ "python" ]