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
Is there a way to convert indentation in Python code to braces?
118,643
<p>I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter ...
73
2008-09-23T01:33:13Z
453,806
<p>There are various answers explaining how to do this. But I would recommend not taking this route. While you could use a script to do the conversion, it would make it hard to work on a team project.</p> <p>My recommendation would be to configure your screen reader to announce the tabs. This isn't as annoying as it ...
1
2009-01-17T18:49:29Z
[ "python", "accessibility", "blind", "blindness" ]
Is there a way to convert indentation in Python code to braces?
118,643
<p>I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter ...
73
2008-09-23T01:33:13Z
1,479,855
<p><a href="http://en.wikipedia.org/wiki/Edsger%5FDijkstra" rel="nofollow">Edsger Dijkstra</a> used <a href="http://en.wikipedia.org/wiki/Guarded%5FCommand%5FLanguage#Selection%3A%5Fif" rel="nofollow">if ~ fi</a> and <a href="http://en.wikipedia.org/wiki/Guarded%5FCommand%5FLanguage#Repetition%3A%5Fdo" rel="nofollow">d...
0
2009-09-25T22:36:33Z
[ "python", "accessibility", "blind", "blindness" ]
Is there a way to convert indentation in Python code to braces?
118,643
<p>I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter ...
73
2008-09-23T01:33:13Z
11,382,155
<p>All of these "no you can't" types of answers are really annoying. Of course you can.</p> <p>It's a hack, but you can do it.</p> <p><a href="http://timhatch.com/projects/pybraces/" rel="nofollow">http://timhatch.com/projects/pybraces/</a></p> <p>uses a custom encoding to convert braces to indented blocks before ha...
3
2012-07-08T09:42:09Z
[ "python", "accessibility", "blind", "blindness" ]
Is there a way to convert indentation in Python code to braces?
118,643
<p>I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter ...
73
2008-09-23T01:33:13Z
11,996,920
<p>Searching an accessible Python IDE, found this and decided to answer. Under Windows with JAWS:</p> <ol> <li>Go to Settings Center by pressing <kbd>JawsKey</kbd>+<kbd>6</kbd> (on the number row above the letters) in your favorite text editor. If JAWS prompts to create a new configuration file, agree.</li> <li>In the...
2
2012-08-16T23:34:46Z
[ "python", "accessibility", "blind", "blindness" ]
Is there a way to convert indentation in Python code to braces?
118,643
<p>I am a totally blind programmer who would like to learn Python. Unfortunately the fact that code blocks are represented with different levels of indentation is a major stumbling block. I was wondering if there were any tools available that would allow me to write code using braces or some other code block delimiter ...
73
2008-09-23T01:33:13Z
13,292,321
<p>If you're on Windows, I strongly recommend you take a look at EdSharp from: <a href="http://empowermentzone.com/EdSharp.htm">http://empowermentzone.com/EdSharp.htm</a> It supports all of the leading Windows screenreaders, it can be configured to speak the indentation levels of code, or it has a built in utility call...
6
2012-11-08T15:40:12Z
[ "python", "accessibility", "blind", "blindness" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
118,671
<p>I haven't tested it, but I'd say it'll most likely work with the latest IPy2.</p> <p>As for distribution, it's very simple. Use the -X:SaveAssemblies option to compile your Python code down to a binary and then ship it with your other DLLs and the IPy dependencies.</p>
0
2008-09-23T01:42:48Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
118,680
<p>If BeautifulSoup doesn't work on IronPython, it's because IronPython doesn't implement the whole Python language (the same way CPython does). BeautifulSoup is pure-python, no C-extensions, so the only problem is the compatibility of IronPython with CPython in terms of Python source code.There shouldn't be one, but i...
5
2008-09-23T01:43:40Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
118,713
<p>I've tested and used BeautifulSoup with both IPy 1.1 and 2.0 (forget which beta, but this was a few months back). Leave a comment if you are still having trouble and I'll dig out my test code and post it.</p>
8
2008-09-23T01:53:58Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
119,713
<p>If you have the complete standard library and the real <code>re</code> module (google for IronPython community edition) it might work. But IronPython is an incredible bad python implementation, I wouldn't count on that.</p> <p>Besides, give <code>html5lib</code> a try. That parser parses with the same rules firef...
-2
2008-09-23T07:58:31Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
123,532
<p>Regarding the second part of your question, you can use the DLR Hosting APIs to run IronPython code from within a C# application. The DLR hosting spec is <a href="http://compilerlab.members.winisp.net/dlr-spec-hosting.pdf" rel="nofollow">here</a>. This <a href="http://blogs.msdn.com/seshadripv/" rel="nofollow">blog<...
1
2008-09-23T20:10:02Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
123,589
<p>Also, regarding one of the previous comments about compiling with -X:SaveAssemblies - that is wrong. -X:SaveAssemblies is meant as a debugging feature. There is a API meant for compiling python code into binaries. <a href="http://blogs.msdn.com/srivatsn/archive/2008/08/06/static-compilation-of-ironpython-scripts.asp...
2
2008-09-23T20:16:56Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
170,856
<p>I was asking myself this same question and after struggling to follow advice here and elsewhere to get IronPython and BeautifulSoup to play nicely with my existing code I decided to go looking for an alternative native .NET solution. BeautifulSoup is a wonderful bit of code and at first it didn't look like there wa...
33
2008-10-04T19:04:21Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
287,247
<p>We are distributing a 40k line IronPython application. We have not been able to compile the whole thing into a single binary distributable. Instead we have been distributing it as a zillion tiny dlls, one for each IronPython module. This works fine though.</p> <p>However, on the newer release, IronPython 2.0, we ha...
1
2008-11-13T15:31:20Z
[ ".net", "python", "ironpython" ]
Iron python, beautiful soup, win32 app
118,654
<p>Does beautiful soup work with iron python? If so with which version of iron python? How easy is it to distribute a windows desktop app on .net 2.0 using iron python (mostly c# calling some python code for parsing html)? </p>
20
2008-09-23T01:37:48Z
6,549,240
<p>Seems to work just fine with IronPython 2.7. Just need to point it at the right folder and away you go:</p> <pre><code>D:\Code&gt;ipy IronPython 2.7 (2.7.0.40) on .NET 4.0.30319.235 Type "help", "copyright", "credits" or "license" for more information. &gt;&gt;&gt; import sys &gt;&gt;&gt; sys.path.append("D:\Code\I...
1
2011-07-01T14:24:05Z
[ ".net", "python", "ironpython" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
118,820
<p>I have both installed:</p> <pre><code>$ which python /usr/bin/python $ which python2.5 /opt/local/bin/python2.5 </code></pre> <p>I also added the following line to my <code>.profile</code>:</p> <pre><code>export PATH=/opt/local/bin:/opt/local/sbin:$PATH </code></pre>
22
2008-09-23T02:40:05Z
[ "python", "osx", "osx-leopard", "macports" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
118,821
<p>Instead of uninstalling the built-in Python, install the MacPorts version and then modify your <code>$PATH</code> to have the MacPorts version first.</p> <p>For example, if MacPorts installs <code>/usr/local/bin/python</code>, then modify your <code>.bashrc</code> to include <code>PATH=/usr/local/bin:$PATH</code> a...
4
2008-09-23T02:40:13Z
[ "python", "osx", "osx-leopard", "macports" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
118,823
<p>I wouldn't uninstall it since many scripts will expect python to be in the usual places when they do not follow convention and use <code>#!/usr/bin/env python</code>. You should simply edit your <code>.profile</code> or <code>.bash_profile</code> so the macports binaries are the first in your path.</p> <p>Your <co...
3
2008-09-23T02:41:15Z
[ "python", "osx", "osx-leopard", "macports" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
118,824
<p>Don't. Apple ships various system utilities that rely on the system Python (and particularly the Python "framework" build); removing it will cause you problems.</p> <p>Instead, modify your PATH environ variable in your <code>~/.bash_profile</code> to put <code>/opt/local/bin</code> first.</p>
29
2008-09-23T02:41:53Z
[ "python", "osx", "osx-leopard", "macports" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
604,946
<p>Use the <a href="http://www.macports.org/ports.php?by=name&amp;substr=python%5Fselect">python_select</a> port to switch python interpreters.</p> <pre><code>sudo port install python25 sudo port install python_select sudo python_select python25 </code></pre> <p>This will symlink <code>/opt/local/bin/python</code> to...
20
2009-03-03T03:04:32Z
[ "python", "osx", "osx-leopard", "macports" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
2,621,262
<p>The current Macports installer does the .profile PATH modification automatically.</p>
3
2010-04-12T10:22:33Z
[ "python", "osx", "osx-leopard", "macports" ]
How do I uninstall python from OSX Leopard so that I can use the MacPorts version?
118,813
<p>I want to use the macports version of python instead of the one that comes with Leopard.</p>
18
2008-09-23T02:38:04Z
6,166,416
<p><code>python_select</code> is now deprecated, use this instead:</p> <pre><code>sudo port select python python26 </code></pre>
17
2011-05-29T07:17:41Z
[ "python", "osx", "osx-leopard", "macports" ]
Adding code to __init__.py
119,167
<p>I'm taking a look at how the model system in django works and I noticed something that I don't understand.</p> <p>I know that you create an empty <code>__init__.py</code> file to specify that the current directory is a package. And that you can set some variable in <code>__init__.py</code> so that import * works p...
67
2008-09-23T04:41:18Z
119,178
<p>All imports in <code>__init__.py</code> are made available when you import the package (directory) that contains it.</p> <p>Example:</p> <p><code>./dir/__init__.py</code>:</p> <pre><code>import something </code></pre> <p><code>./test.py</code>:</p> <pre><code>import dir # can now use dir.something </code></pre>...
63
2008-09-23T04:47:51Z
[ "python", "initialization", "package" ]
Adding code to __init__.py
119,167
<p>I'm taking a look at how the model system in django works and I noticed something that I don't understand.</p> <p>I know that you create an empty <code>__init__.py</code> file to specify that the current directory is a package. And that you can set some variable in <code>__init__.py</code> so that import * works p...
67
2008-09-23T04:41:18Z
119,346
<p>It's just personal preference really, and has to do with the layout of your python modules.</p> <p>Let's say you have a module called <code>erikutils</code>. There are two ways that it can be a module, either you have a file called <em>erikutils.py</em> on your <code>sys.path</code> or you have a directory called <...
30
2008-09-23T06:12:15Z
[ "python", "initialization", "package" ]
Adding code to __init__.py
119,167
<p>I'm taking a look at how the model system in django works and I noticed something that I don't understand.</p> <p>I know that you create an empty <code>__init__.py</code> file to specify that the current directory is a package. And that you can set some variable in <code>__init__.py</code> so that import * works p...
67
2008-09-23T04:41:18Z
126,499
<p>Using the <code>__init__.py</code> file allows you to make the internal package structure invisible from the outside. If the internal structure changes (e.g. because you split one fat module into two) you only have to adjust the <code>__init__.py</code> file, but not the code that depends on the package. You can als...
24
2008-09-24T11:02:55Z
[ "python", "initialization", "package" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,205
<p>Depends on what you will use it for. If you're making enterprise Windows forms applications, I don't think switching to Python would be a good idea.</p> <p>Also, it is possible to still use Python on the .NET CLR with IronPython.</p>
1
2008-09-23T04:55:35Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,208
<p>Both are useful for different purposes. C# is a pretty good all-rounder, python's dynamic nature makes it more suitable for RAD experiences such as site building. </p> <p>I don't think your career will suffer if you were competant in both. To get going with Python consider an IDE with Python support such as Ecli...
1
2008-09-23T04:56:18Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,215
<p>What's better is inherently subjective. If you like Python's syntax - learn it. It will probably be harder to find a Python job, C# and .NET in general seem to be more popular, but this may change.</p> <p>I also think it's worth to know at least one scripting language, even if your main job doesn't require it. Pyth...
1
2008-09-23T04:59:52Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,219
<p>Personally I feel you can write good/bad code in any language. I also firmly believe in learning a <a href="http://www.linuxjournal.com/article/6536" rel="nofollow">new language every so often</a> for the sake of learning itself. On those grounds I say if you have the time just go for it. Python is a great language ...
5
2008-09-23T05:02:16Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,224
<p>It can't hurt to learn Python, especially considering some of the heavy weights (Google) are really getting behind it.</p> <p>As for the actual use, it all depends on the application. Use the best tool for the job.</p>
3
2008-09-23T05:03:23Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,232
<p>Yes, you should learn Python, but it has nothing to do with Python or C# being better. It is really about making you a better programmer.</p> <p>Learning Python will give you a whole new perspective on programmer and how problems can be solved. It's like lifting weights, except you're building up the developer mu...
15
2008-09-23T05:05:53Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
119,386
<p>Never stop learning! </p> <p>That said, how can you compare the two? How good is Python support in .Net? Is there C# support in Google App Engine? It really depends what your target system is. Therefore, the more languages you have the better equipped you will be to tackle different challenges.</p>
2
2008-09-23T06:28:30Z
[ "c#", "python" ]
Is it good to switch from c# to python?
119,198
<p>Currently I am developing in the .Net environment using C# but I want to know whether it is worth learning python. I'm thinking of learning the Django framework. What is better?</p>
2
2008-09-23T04:53:13Z
30,671,567
<p>I have been thinking about this same question myself. I believe however there is still a lot of stuff C# can offer that I want to get good at before I job into Python. Because Python is easier to learn it. One advantage I have found in languages is not the language itself but the materials available to learning t...
0
2015-06-05T16:35:48Z
[ "c#", "python" ]
time length of an mp3 file
119,404
<p>What is the simplest way to determine the length (in seconds) of a given mp3 file, <strong>without using outside libraries</strong>? (python source highly appreciated)</p>
13
2008-09-23T06:33:14Z
119,418
<p>You can use <a href="http://spacepants.org/src/pymad/">pymad</a>. It's an external library, but don't fall for the Not Invented Here trap. Any particular reason you don't want any external libraries?</p> <pre><code>import mad mf = mad.MadFile("foo.mp3") track_length_in_milliseconds = mf.total_time() </code></pre...
23
2008-09-23T06:37:50Z
[ "python", "mp3", "media", "music" ]
time length of an mp3 file
119,404
<p>What is the simplest way to determine the length (in seconds) of a given mp3 file, <strong>without using outside libraries</strong>? (python source highly appreciated)</p>
13
2008-09-23T06:33:14Z
119,436
<p>You might count the number of frames in the file. Each frame has a start code, although I can't recollect the exact value of the start code and I don't have MPEG specs laying around. Each frame has a certain length, around 40ms for MPEG1 layer II.</p> <p>This method works for CBR-files (Constant Bit Rate), how VBR-...
0
2008-09-23T06:43:57Z
[ "python", "mp3", "media", "music" ]
time length of an mp3 file
119,404
<p>What is the simplest way to determine the length (in seconds) of a given mp3 file, <strong>without using outside libraries</strong>? (python source highly appreciated)</p>
13
2008-09-23T06:33:14Z
119,616
<blockquote> <blockquote> <p>Simple, parse MP3 binary blob to calculate something, in Python</p> </blockquote> </blockquote> <p>That sounds like a pretty tall order. I don't know Python, but here's some code I've refactored from another program I once tried to write.</p> <p><strong>Note:</strong> It's in C++ ...
7
2008-09-23T07:37:41Z
[ "python", "mp3", "media", "music" ]
time length of an mp3 file
119,404
<p>What is the simplest way to determine the length (in seconds) of a given mp3 file, <strong>without using outside libraries</strong>? (python source highly appreciated)</p>
13
2008-09-23T06:33:14Z
5,059,165
<p>For google followers' sake, here are a few more external libs:</p> <p>mpg321 -t</p> <p>ffmpeg -i</p> <p>midentify (mplayer basically) see <a href="http://stackoverflow.com/questions/497681/using-mplayer-to-determine-length-of-audio-video-file">Using mplayer to determine length of audio/video file</a></p> <p>menc...
9
2011-02-20T18:49:58Z
[ "python", "mp3", "media", "music" ]
time length of an mp3 file
119,404
<p>What is the simplest way to determine the length (in seconds) of a given mp3 file, <strong>without using outside libraries</strong>? (python source highly appreciated)</p>
13
2008-09-23T06:33:14Z
10,132,100
<p>Also take a look at audioread (some linux distros including ubuntu have packages), <a href="https://github.com/sampsyo/audioread" rel="nofollow">https://github.com/sampsyo/audioread</a></p> <pre><code>audio = audioread.audio_open('/path/to/mp3') print audio.channels, audio.samplerate, audio.duration </code></pre>
3
2012-04-12T21:26:14Z
[ "python", "mp3", "media", "music" ]
time length of an mp3 file
119,404
<p>What is the simplest way to determine the length (in seconds) of a given mp3 file, <strong>without using outside libraries</strong>? (python source highly appreciated)</p>
13
2008-09-23T06:33:14Z
29,028,948
<p>simply use <code>mutagen</code></p> <pre><code>$pip install mutagen </code></pre> <p>use it in python shell:</p> <pre><code>from mutagen.mp3 import MP3 audio = MP3(file_path) print audio.info.length </code></pre>
3
2015-03-13T09:37:59Z
[ "python", "mp3", "media", "music" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
119,576
<p>Because <a href="http://www.python.org/dev/peps/pep-0008/#tabs-or-spaces">PEP-8</a> tells us to use spaces :)</p>
180
2008-09-23T07:28:00Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
119,594
<p>I recently came across an article titled <a href="http://www.secnetix.de/olli/Python/block_indentation.hawk">Python: Myths about Indentation</a> which discusses this and related questions. The article has good reasons for recommending the use of spaces when writing Python code, but there is certainly room for disagr...
21
2008-09-23T07:31:58Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
119,598
<p>The most "pythonic" way is to use 4 spaces per indentation level. The Python interpreter will however recognize spaces or tabs. The only gottcha is you <strong>must never mix spaces and tabs</strong>, pick one or the other. That said, the specification recommends spaces, most developers use spaces, so unless you hav...
51
2008-09-23T07:32:35Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
119,693
<p>Editor-to-editor mistake occurs when you have <em>mixed indentation within a file</em>. This arises as follows: a block of code is indented with 4 spaces, and then one indentation level "in", it is indented with tabs. Now the heathen who did this (mixing tabs and spaces) had it so his tabs are also 4 spaces, so he s...
6
2008-09-23T07:54:59Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
119,703
<p>You CAN mix tabs and spaces... BUT a tab is considered to be the same indentation as 8 spaces, so unless your editor is set up to consider a tab to be 8 spaces you're asking for trouble when mixing them.</p>
9
2008-09-23T07:56:34Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
120,249
<p>People will use different editors on the same code. These editors will represent a tab on the screen differently. If you're working on an editor that represents a tab as 4 spaces, if you indent the first line by <code>"\t "</code> and the second by <code>"\t\t"</code>, they'll look like they're in the same indent...
-2
2008-09-23T10:35:03Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
120,265
<p>Use an editor that allows you to insert spaces up to the tabstop when you press the TAB key, instead of inserting a \t character. And then forget about it.</p>
13
2008-09-23T10:38:35Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
122,181
<p>I use two space indentation and an editor (kwrite) that inserts spaces instead of tabs when I hit the tab key.</p>
0
2008-09-23T16:37:41Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
132,652
<p>The only inconvenience I experience with using spaces instead of tabs is that you cannot easily remove an indentation level, you have to remove 4 spaces instead of just one tab.</p>
9
2008-09-25T11:11:33Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
1,777,008
<p>Tired of chasing after indentation typos ( 8 spaces ? no, 7 oops 9 ... ) I switched my sources to 'tabs only'.</p> <p><strong>1 tab == 1 indent level, full stop</strong></p> <p>The point is: if you want to display the indentation as 4, 8 or pi / 12 character width, just change the settings in your text editor, don...
315
2009-11-21T22:30:21Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
2,389,168
<p>My main reason for using tabs over spaces is the backspace key. If I'm on a line and I want to backspace-remove an indentation on just that one line I have to hit backspace 4x if it were spaces; whereas, I only need to hit it once if it's a tab.</p> <p>I will continue to use tabs because—like was stated before—...
43
2010-03-05T18:55:48Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
2,868,181
<p>USE AN EDITOR THAT DISPLAYS TAB CHARACTERS (all whitespace, for that matter). You're programming, not writing an article.</p> <p>I use tabs. There's no room for a one-space error in the tabs (if you can see them). The problem IS that people use different editors, and the only common thing in the world is: tab==in...
56
2010-05-19T18:14:16Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
6,312,842
<p>Everyone has different preferences on how much code should be indented. Let's say you share code with someone and he or she has different preferences regarding indentation. If the indentations are in tabs, your friend can always just change the tab width in their editor settings. However, if the indentations are in ...
3
2011-06-10T22:55:45Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
6,338,054
<p><em>Thus spake the Lord: Thou shalt indent with four spaces. No more, no less. Four shall be the number of spaces thou shalt indent, and the number of thy indenting shall be four. Eight shalt thou not indent, nor either indent thou two, excepting that thou then proceed to four. Tabs are right out.</em> -- Georg Br...
130
2011-06-14T01:02:09Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
7,773,894
<p>I know this is an old question, but it still comes up near the top of a google search on the topic, and I think I can add a little value. </p> <p>When I was first learning python, I was put off a little by the idea of significant white space, as most languages to use it are inflexible. That said, I was impressed ...
8
2011-10-14T21:43:41Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
7,882,145
<p>Tabs rule. Same argument for nested loops and you want to bring the outer loop "back" 1 level. Tip: If you want to convert old space-riddled python code into tabs use the TabOut utility available as an executable on <a href="http://www.textpad.com/add-ons/">http://www.textpad.com/add-ons/</a>.</p>
8
2011-10-24T21:21:55Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
8,315,782
<p>I'm primarily a C++ programmer, but sometimes my projects include small amounts of Python. I use tabs to indent my C++ code. This means that I have three options here:</p> <ol> <li>Use tabs in C++ and spaces in Python. This allows my C++ files to remain as they are and I follow the PEP-8 recommendation, but I am in...
4
2011-11-29T18:27:38Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
9,534,783
<p>There's a scenario in which tabs simply don't work, namely: depending on the coding style you are using, you might need to indent some lines of code to one-space accuracy, i.e:</p> <pre><code>def foobar(): x = some_call(arg1, arg2) </code></pre> <p>In that case, using purely tabs will not wor...
3
2012-03-02T14:19:42Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
12,974,668
<p>So far as I can tell, here are the pros and cons of tabs vs spaces.</p> <p>Pros of tabs:</p> <ul> <li>Fewer keystrokes required to indent, unindent, and traverse the indentation. (Even if your IDE has some space-indentation cleverness it will never be as good as tabs.)</li> <li>Different programmers can use differ...
29
2012-10-19T12:50:32Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
13,087,091
<p>Having recently had to deal with existing code that was mixing spaces and tabs, it's really confusing.</p> <p>When you're mixing (which you really shouldn't do, but which does exist out there unfortunately), it appears that "1 tab == 1 indent level" isn't true.</p> <p>Take the following example (tried with Python ...
0
2012-10-26T12:40:09Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
13,092,818
<p>I recently switched from tabs to spaces, for pep8 compliance.</p> <p>I liked tabs previously for two reasons:</p> <ol> <li>With tabs, everyone can see code with the indentation level of their choice; just use spaces on the right and tabs on the left.</li> <li>make wants tabs pretty badly</li> </ol> <p>...but afte...
0
2012-10-26T19:00:46Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
17,443,506
<p>Experience and <a href="http://www.python.org/dev/peps/pep-0008/#indentation">PEP-8</a> both clearly conclude that mixing spaces and <code>TAB</code>s is to be avoided. If you want to mix them you have to visualize whitespace in the IDE - but then you loose the advantage of Python's indentation making scopes easily ...
6
2013-07-03T08:46:14Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
19,744,585
<p>I'm just starting out but I find it much easier to use tabs than spaces, and do not understand the PEP-8 advocation of spaces only. Sublime Text 2 does a great job of visualizing tabs with the off-white vertical, dotted line and while there are cases of me mixing a space or two to line up elements of a list or dicti...
0
2013-11-02T17:14:16Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
21,134,845
<p>In addition to all the arguments already listed, I find this one fairly important (from <a href="http://www.secnetix.de/olli/Python/block_indentation.hawk" rel="nofollow">Myths about indentation</a>):</p> <blockquote> <p>Also, tabs often get destroyed or wrongly converted during copy&amp;paste operations, or when...
0
2014-01-15T10:25:05Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
28,866,396
<p>I have read through all Answers, and most of the up-voted comments, and I believe I still have something to add, so I am going to post my own Answer. (Recently I have been reading a lot about tabs vs spaces while programming in Python.)</p> <p>I will attempt to answer your questions as directly as possible.</p> <b...
1
2015-03-04T22:30:58Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
34,819,522
<p>I believe there is a solution to have both:</p> <ol> <li>compatibility with PEP and using spaces </li> <li>convenience of using tab instead of 4 spaces</li> </ol> <p>In notepad++, go to "preferences"--> "tab settings" and choose "Python" from the list on the right. Then make sure "tab size: 4", and check the box "...
1
2016-01-15T20:42:40Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
36,676,458
<p>I feel very strongly that whatever the historical convention, tabs are simply a better choice and should replace spaces in every future line of Python code written. Like kicking out an incompetent tyrant. My rationale for this is: <em>simplicty as a core value</em>. Use two or maybe four characters for the semantic ...
1
2016-04-17T12:26:46Z
[ "python", "coding-style", "indentation", "conventions" ]
Tabs versus spaces in Python programming
119,562
<p>I have always used tabs for indentation when I do Python programming. But then I came across a question here on SO where someone pointed out that most Python programmers use spaces instead of tabs to minimize editor-to-editor mistakes.</p> <p>How does that make a difference? Are there other reasons why one would us...
207
2008-09-23T07:26:00Z
39,398,626
<p>I love tabs but it is somehow incompatible with another rule I like: the 80 column limit.</p> <p>I one chooses 4 spaces tabs and inserts 10 tabs, then there is space left for 40 characters to fulfill the 80 column limit. If another coder prefers 8 spaces tabs, the same line will appear as 120 characters long and wi...
1
2016-09-08T19:17:15Z
[ "python", "coding-style", "indentation", "conventions" ]
Find matching sequences in two binary files
119,651
<p>Let me start off with a bit of background.</p> <p>This morning one of our users reported that Testuff's setup file has been reported as infected with a virus by the CA antivirus. Confident that this was a false positive, I looked on the web and found that users of another program (SpyBot) have reported the same pro...
1
2008-09-23T07:46:02Z
119,671
<p>Why don't you contact CA and ask them to tell them what they're searching for, for that virus?</p> <p>Or, you could copy the file and change each individual byte until the warning disappeared (may take a while depending on the size).</p> <p>It's possible the virus detection may be a lot more complicated than simpl...
1
2008-09-23T07:51:00Z
[ "python", "binary", "diff", "antivirus" ]
Find matching sequences in two binary files
119,651
<p>Let me start off with a bit of background.</p> <p>This morning one of our users reported that Testuff's setup file has been reported as infected with a virus by the CA antivirus. Confident that this was a false positive, I looked on the web and found that users of another program (SpyBot) have reported the same pro...
1
2008-09-23T07:46:02Z
119,698
<p>Hey, better not wonder about the complexity and time these kinds of algorithms need.</p> <p>If you have interest in this - here <a href="http://www.acm.org/jea/ARTICLES/Vol4Nbr2.ps" rel="nofollow">.ps document linked here</a> you can find a good introduction into this thematic.</p> <p>If a good implementation for ...
1
2008-09-23T07:55:47Z
[ "python", "binary", "diff", "antivirus" ]
Find matching sequences in two binary files
119,651
<p>Let me start off with a bit of background.</p> <p>This morning one of our users reported that Testuff's setup file has been reported as infected with a virus by the CA antivirus. Confident that this was a false positive, I looked on the web and found that users of another program (SpyBot) have reported the same pro...
1
2008-09-23T07:46:02Z
119,718
<p>See <a href="http://en.wikipedia.org/wiki/Longest_common_substring_problem" rel="nofollow">the longest common substring problem</a>. I guess difflib uses the DP solution, which is certainly too slow to compare executables. You can do much better with suffix trees/arrays.</p> <p>Using perl <a href="http://search.cpa...
3
2008-09-23T08:00:13Z
[ "python", "binary", "diff", "antivirus" ]
Find matching sequences in two binary files
119,651
<p>Let me start off with a bit of background.</p> <p>This morning one of our users reported that Testuff's setup file has been reported as infected with a virus by the CA antivirus. Confident that this was a false positive, I looked on the web and found that users of another program (SpyBot) have reported the same pro...
1
2008-09-23T07:46:02Z
119,847
<p>Note that even if you did find it this way, there's no guarantee that the longest match is actually the one being looked for. Instead, you may find common initialisation code or string tables added by the same compiler for instance.</p>
2
2008-09-23T08:30:15Z
[ "python", "binary", "diff", "antivirus" ]
Find matching sequences in two binary files
119,651
<p>Let me start off with a bit of background.</p> <p>This morning one of our users reported that Testuff's setup file has been reported as infected with a virus by the CA antivirus. Confident that this was a false positive, I looked on the web and found that users of another program (SpyBot) have reported the same pro...
1
2008-09-23T07:46:02Z
120,589
<p>I suspect that looking for binary strings isn't going to help you. An install program is likely to be doing some 'suspicious' things. </p> <p>You probably need to talk to CA and spybot about white-listing your installer, or about what is triggering the alert.</p>
0
2008-09-23T12:14:51Z
[ "python", "binary", "diff", "antivirus" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
119,837
<p>I wonder what the original poster tried and which methods worked and not worked for him. I have never worked with DICOM, but a quick google search for "DICOM python" gave several interesting results. It seems that this project: <a href="http://www.creatis.univ-lyon1.fr/Public/Gdcm/" rel="nofollow">http://www.creatis...
0
2008-09-23T08:28:25Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
120,988
<p>There are some libraries (most often implemented in C/C++) with Python bindings, e.g.:</p> <ul> <li><a href="http://dicomlib.swri.ca/pydicomlib.html" rel="nofollow">pydicomlib</a></li> <li><a href="http://www.creatis.univ-lyon1.fr/Public/Gdcm/" rel="nofollow">gdcmPython</a></li> </ul> <p>However, I'm looking for a...
1
2008-09-23T13:28:56Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
121,065
<p>Some years ago I was looking for the same thing and found this: <a href="http://cvs.atamai.com/cgi-bin/viewvc.cgi/atamai/dicom/" rel="nofollow">Python DICOM lib</a></p> <p>I wasn't too impressed with the code, but it is native Python reading DICOM files.</p>
3
2008-09-23T13:40:45Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
177,470
<p>And as of today there's another pure Python package reading DICOM files available: <a href="https://github.com/darcymason/pydicom" rel="nofollow">pydicom</a></p>
13
2008-10-07T07:17:52Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
213,987
<p>If you want to learn about the DICOM format, "Digital Imaging and Communications in Medicine (DICOM): A Practical Introduction and Survival Guide" by Oleg Pianykh is quite readable and gives a good introduction to key DICOM concepts. Springer-Verlag is the publisher of this book. The full DICOM standard is, of co...
8
2008-10-17T22:01:47Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
377,907
<p>Newer gdcm development now happen here:</p> <p><a href="http://gdcm.sourceforge.net/" rel="nofollow">http://gdcm.sourceforge.net/</a></p> <p>It supports Java and C# on top of python.</p> <p>Why write <strong>yet another</strong> dicom implementation when you can centralize a single C++ implementation and have it ...
3
2008-12-18T13:55:06Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
480,245
<p>The library <a href="http://code.google.com/p/pydicom">pydicom</a> mentioned above seems like a great library for accessing the DICOM data structures. To use it to access e.g. RT DOSE data, I guess one would do something like</p> <pre><code>import dicom,numpy dose = dicom.ReadFile("RTDOSE.dcm") d = numpy.fromstring...
7
2009-01-26T15:50:42Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
810,849
<p>I'm using <a href="https://github.com/darcymason/pydicom" rel="nofollow" title="pydicom">pydicom</a> heavily these days, and it rocks.</p> <p>It's pretty easy to start playing with it: </p> <pre><code>import dicom data = dicom.read_file("yourdicomfile.dcm") </code></pre> <p>To get the interesting stuff out of th...
15
2009-05-01T10:02:07Z
[ "python", "image", "format", "dicom", "medical" ]
Parse DICOM files in native Python
119,684
<p>What is the simplest and most-pythonic way to parse a DICOM file?</p> <p>A native Python implementation without the use of non-Python libraries would be much preferred. DICOM is the standard file format in digital medical imaging (look <a href="http://en.wikipedia.org/wiki/Digital_Imaging_and_Communications_in_Medi...
14
2008-09-23T07:53:50Z
5,011,901
<p>DICOM is a real pain... even when the manufacturer sticks to the standards. If you write your own DICOM library you'll find different manufacturers DICOMs are effectively incompatible with other vendors [citation needed].</p> <p>I tried (in my spare time) writing a C dicom parser borrowing heavily from a nice litt...
1
2011-02-16T02:26:29Z
[ "python", "image", "format", "dicom", "medical" ]
Using **kwargs with SimpleXMLRPCServer in python
119,802
<p>I have a class that I wish to expose as a remote service using pythons SimpleXMLRPCServer. The server startup looks like this:</p> <pre><code>server = SimpleXMLRPCServer((serverSettings.LISTEN_IP,serverSettings.LISTEN_PORT)) service = Service() server.register_instance(service) server.serve_forever() </code></pre...
11
2008-09-23T08:19:44Z
119,943
<p>As far as I know, the underlying protocol doesn't support named varargs (or any named args for that matter). The workaround for this is to create a wrapper that will take the **kwargs and pass it as an ordinary dictionary to the method you want to call. Something like this</p> <p>Server side:</p> <pre><code>def se...
1
2008-09-23T08:56:03Z
[ "python", "simplexmlrpcserver", "xmlrpclib" ]
Using **kwargs with SimpleXMLRPCServer in python
119,802
<p>I have a class that I wish to expose as a remote service using pythons SimpleXMLRPCServer. The server startup looks like this:</p> <pre><code>server = SimpleXMLRPCServer((serverSettings.LISTEN_IP,serverSettings.LISTEN_PORT)) service = Service() server.register_instance(service) server.serve_forever() </code></pre...
11
2008-09-23T08:19:44Z
119,963
<p>XML-RPC doesn't really have a concept of 'keyword arguments', so xmlrpclib doesn't try to support them. You would need to pick a convention, then modify xmlrpclib._Method to accept keyword arguments and pass them along using that convention.</p> <p>For instance, I used to work with an XML-RPC server that passed key...
3
2008-09-23T09:01:47Z
[ "python", "simplexmlrpcserver", "xmlrpclib" ]
Using **kwargs with SimpleXMLRPCServer in python
119,802
<p>I have a class that I wish to expose as a remote service using pythons SimpleXMLRPCServer. The server startup looks like this:</p> <pre><code>server = SimpleXMLRPCServer((serverSettings.LISTEN_IP,serverSettings.LISTEN_PORT)) service = Service() server.register_instance(service) server.serve_forever() </code></pre...
11
2008-09-23T08:19:44Z
119,974
<p>As Thomas Wouters said, XML-RPC does not have keyword arguments. Only the order of arguments matters as far as the protocol is concerned and they can be called anything in XML: arg0, arg1, arg2 is perfectly fine, as is cheese, candy and bacon for the same arguments.</p> <p>Perhaps you should simply rethink your use...
0
2008-09-23T09:06:05Z
[ "python", "simplexmlrpcserver", "xmlrpclib" ]
Using **kwargs with SimpleXMLRPCServer in python
119,802
<p>I have a class that I wish to expose as a remote service using pythons SimpleXMLRPCServer. The server startup looks like this:</p> <pre><code>server = SimpleXMLRPCServer((serverSettings.LISTEN_IP,serverSettings.LISTEN_PORT)) service = Service() server.register_instance(service) server.serve_forever() </code></pre...
11
2008-09-23T08:19:44Z
120,225
<p>Using the above advice, I created some working code.</p> <p>Server method wrapper:</p> <pre><code>def unwrap_kwargs(func): def wrapper(*args, **kwargs): print args if args and isinstance(args[-1], list) and len(args[-1]) == 2 and "kwargs" == args[-1][0]: func(*args[:-1], **args[-1][...
0
2008-09-23T10:26:43Z
[ "python", "simplexmlrpcserver", "xmlrpclib" ]
Using **kwargs with SimpleXMLRPCServer in python
119,802
<p>I have a class that I wish to expose as a remote service using pythons SimpleXMLRPCServer. The server startup looks like this:</p> <pre><code>server = SimpleXMLRPCServer((serverSettings.LISTEN_IP,serverSettings.LISTEN_PORT)) service = Service() server.register_instance(service) server.serve_forever() </code></pre...
11
2008-09-23T08:19:44Z
120,291
<p>You can't do this with plain xmlrpc since it has no notion of keyword arguments. However, you can superimpose this as a protocol on top of xmlrpc that would always pass a list as first argument, and a dictionary as a second, and then provide the proper support code so this becomes transparent for your usage, example...
10
2008-09-23T10:47:37Z
[ "python", "simplexmlrpcserver", "xmlrpclib" ]
Dynamically create variables inside function
119,941
<p>I want to create variables inside function from dictionary.</p> <p>Lets say I have a dictionary</p> <pre><code>bar = {'a': 1, 'b': 2, 'c': 3} </code></pre> <p>and function</p> <pre><code>def foo(): pass </code></pre> <p>What I want to do is to create inside function "foo" variables with names of each dictiona...
1
2008-09-23T08:55:24Z
119,964
<p>Why would you want to do such a thing? Unless you actually do anything with the variables inside the function, a function that just assigns several variables and then discards them is indistinguishable to def foo(): pass (An optimiser would be justified in generating exactly the same bytecode).</p> <p>If you als...
1
2008-09-23T09:02:55Z
[ "python" ]
Dynamically create variables inside function
119,941
<p>I want to create variables inside function from dictionary.</p> <p>Lets say I have a dictionary</p> <pre><code>bar = {'a': 1, 'b': 2, 'c': 3} </code></pre> <p>and function</p> <pre><code>def foo(): pass </code></pre> <p>What I want to do is to create inside function "foo" variables with names of each dictiona...
1
2008-09-23T08:55:24Z
119,983
<p>Your question is not clear.</p> <p>If you want to "set" said variables when foo is not running, no, you can't. There is no frame object yet to "set" the local variables in.</p> <p>If you want to do that in the function body, you shouldn't (check the <a href="http://docs.python.org/lib/built-in-funcs.html" rel="nof...
2
2008-09-23T09:08:06Z
[ "python" ]
Dynamically create variables inside function
119,941
<p>I want to create variables inside function from dictionary.</p> <p>Lets say I have a dictionary</p> <pre><code>bar = {'a': 1, 'b': 2, 'c': 3} </code></pre> <p>and function</p> <pre><code>def foo(): pass </code></pre> <p>What I want to do is to create inside function "foo" variables with names of each dictiona...
1
2008-09-23T08:55:24Z
120,103
<p>Thanks guys, I got the point. I should not do such thing. But if your curios what I tried to do is to somehow short number of lines in my view function in django. I have form with many fields, and instead of receive every field in form of:</p> <pre><code>first_name = form.cleaned_data['first_name'] last_name = form...
1
2008-09-23T09:46:57Z
[ "python" ]
Dynamically create variables inside function
119,941
<p>I want to create variables inside function from dictionary.</p> <p>Lets say I have a dictionary</p> <pre><code>bar = {'a': 1, 'b': 2, 'c': 3} </code></pre> <p>and function</p> <pre><code>def foo(): pass </code></pre> <p>What I want to do is to create inside function "foo" variables with names of each dictiona...
1
2008-09-23T08:55:24Z
120,214
<p>From your comment, perhaps what you're really looking for is something like a bunch object:</p> <pre><code>class Bunch(object): def __init__(self, **kwargs): self.__dict__.update(kwargs) b=Bunch(**form.cleaned_data) print b.first_name, b.last_name </code></pre> <p>(The ** syntax is because Bunch-type...
3
2008-09-23T10:23:19Z
[ "python" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
120,073
<p>Try changing the user agent header you are sending in your request to something like: User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008072820 Ubuntu/8.04 (hardy) Firefox/3.0.1 (Linux Mint)</p>
1
2008-09-23T09:41:22Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
120,104
<p>You don't need to impersonate a browser user-agent; any user-agent at all will work, just not a blank one.</p>
1
2008-09-23T09:48:05Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
120,113
<p>It is not a solution to the specific problem. But it might be intersting for you to use the mwclient library (<a href="http://botwiki.sno.cc/wiki/Python:Mwclient">http://botwiki.sno.cc/wiki/Python:Mwclient</a>) instead. That would be so much easier. Especially since you will directly get the article contents which r...
36
2008-09-23T09:49:44Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
120,118
<p>You need to use the <a href="http://docs.python.org/lib/module-urllib2.html" rel="nofollow">urllib2</a> that superseedes <a href="http://docs.python.org/lib/module-urllib.html" rel="nofollow">urllib</a> in the <a href="http://docs.python.org/lib/" rel="nofollow">python std library</a> in order to change the user age...
48
2008-09-23T09:50:39Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
120,121
<p>The general solution I use for any site is to access the page using Firefox and, using an extension such as Firebug, record all details of the HTTP request including any cookies.</p> <p>In your program (in this case in Python) you should try to send a HTTP request as similar as necessary to the one that worked from...
2
2008-09-23T09:51:31Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
980,529
<p>Rather than trying to trick Wikipedia, you should consider using their <a href="http://www.mediawiki.org/wiki/API">High-Level API</a>.</p>
14
2009-06-11T11:14:20Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
4,168,237
<p>In case you are trying to access Wikipedia content (and don't need any specific information about the page itself), instead of using the api you should just call index.php with 'action=raw' in order to get the wikitext, like in:</p> <p>'http://en.wikipedia.org/w/index.php?<strong>action=raw</strong>&amp;title=Main_...
3
2010-11-12T19:16:55Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
4,795,011
<pre><code>import urllib s = urllib.urlopen('http://en.wikipedia.org/w/index.php?action=raw&amp;title=Albert_Einstein').read() </code></pre> <p>This seems to work for me without changing the user agent. Without the "action=raw" it does not work for me.</p>
0
2011-01-25T15:02:18Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
25,927,059
<p><a href="http://docs.python-requests.org/en/latest/" rel="nofollow"><code>requests</code></a> is awesome!</p> <p>Here is how you can get the html content with <code>requests</code>:</p> <pre><code>import requests html = requests.get('http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes').tex...
1
2014-09-19T05:37:15Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Fetch a Wikipedia article with Python
120,061
<p>I try to fetch a Wikipedia article with Python's urllib:</p> <pre><code>f = urllib.urlopen("http://en.wikipedia.org/w/index.php?title=Albert_Einstein&amp;printable=yes") s = f.read() f.close() </code></pre> <p>However instead of the html page I get the following response: Error - Wikimedia Foundation:</...
35
2008-09-23T09:37:21Z
33,645,006
<p>Requesting the page with <a href="https://en.wikipedia.org/wiki/Albert_Einstein?printable=yes" rel="nofollow"><code>?printable=yes</code></a> gives you an entire relatively clean HTML document. <a href="https://en.wikipedia.org/wiki/Albert_Einstein?action=render" rel="nofollow"><code>?action=render</code></a> gives ...
0
2015-11-11T05:56:24Z
[ "python", "urllib2", "user-agent", "wikipedia", "http-status-code-403" ]
Short Integers in Python
120,250
<p>Python allocates integers automatically based on the underlying system architecture. Unfortunately I have a huge dataset which needs to be fully loaded into memory. </p> <p>So, is there a way to force Python to use only 2 bytes for some integers (equivalent of C++ 'short')?</p>
10
2008-09-23T10:35:09Z
120,256
<p>Nope. But you can use short integers in arrays:</p> <pre><code>from array import array a = array("h") # h = signed short, H = unsigned short </code></pre> <p>As long as the value stays in that array it will be a short integer.</p> <ul> <li>documentation for the <a href="http://docs.python.org/dev/library/array">...
30
2008-09-23T10:36:44Z
[ "python", "memory-management", "short" ]