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 |
|---|---|---|---|---|---|---|---|---|---|
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,609 | <p>I've found it helpful to work with different languages, since they each have their strengths. Python is extremely powerful, but relies heavily on good coding conventions and practices to keep code maintainable. In particular, it does not enforce type safety or insulation, which means it is easy to abuse. C# is a ... | 0 | 2010-03-20T20:19:19Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,612 | <p>Well, the ease of coding is debatable. I find C# easier to code when you factor in the help you get from teh IDEs (e.g. the free Visual Web Developer). </p>
<p>So, portability is less of an issue if you factor in Mono. Performance can be better in some scenarios. I find the online documentation to be generally ... | 0 | 2010-03-20T20:19:33Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,624 | <ol>
<li><p>Visual Studio - the best IDE out there.</p></li>
<li><p>Of the statically typed languages in circulation, C# is very productive.</p></li>
</ol>
| 13 | 2010-03-20T20:22:12Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,484,650 | <p>C# can directly access pointers via "unmanaged code", which can give it a performance advantage in some situations.</p>
| 0 | 2010-03-20T20:25:47Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,485,085 | <ul>
<li>C# is supported by <strong>Microsoft</strong> ;) (expecting comments)</li>
<li>C# is <code>typesafe</code> which comes with its advantages.</li>
<li>Nothing is better when you are developing windows applications.</li>
<li>Its syntax is also very well designed. Code looks pretty good.</li>
<li>Its worth learnin... | 3 | 2010-03-20T22:45:41Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 2,487,493 | <p>If you prefer Python, but need to write code for .Net, apart from IronPython there's also <a href="http://boo.codehaus.org/" rel="nofollow">Boo</a>, which is a heavily-Python-inspired .Net language (including static types). You might want to give it a try.</p>
| 0 | 2010-03-21T15:01:22Z | [
"c#",
"python"
] |
what are the advantages of C# over Python | 2,484,578 | <p>I like Python mostly for the great portability and the ease of coding, but I was wondering, what are some of the advantages that C# has over Python?</p>
<p>The reason I ask is that one of my friends runs a private server for an online game (UO), and he offered to make me a dev if I wanted, but the software for the ... | 6 | 2010-03-20T20:12:53Z | 23,285,564 | <p>If you are not interested in using the .NET framework, you can instead use python and pyQt or Tkinter as Python now has an IDE support for Visual Studio called Python Tools for Visual Studio (PTVS) that gives you syntax prompts just like how you get in VB and C# in visual Studio. But if you need to use .NET also, us... | 0 | 2014-04-25T06:21:12Z | [
"c#",
"python"
] |
What's the Ruby equivalent of Python's output[:-1]? | 2,484,863 | <p>In Python, if I want to get the first n characters of a string minus the last character, I do:</p>
<pre><code>output = 'stackoverflow'
print output[:-1]
</code></pre>
<p>What's the Ruby equivalent?</p>
| 5 | 2010-03-20T21:34:24Z | 2,484,877 | <p><code>"stackoverflow"[0..-2]</code> will return <code>"stackoverflo"</code></p>
| 2 | 2010-03-20T21:39:03Z | [
"python",
"ruby"
] |
What's the Ruby equivalent of Python's output[:-1]? | 2,484,863 | <p>In Python, if I want to get the first n characters of a string minus the last character, I do:</p>
<pre><code>output = 'stackoverflow'
print output[:-1]
</code></pre>
<p>What's the Ruby equivalent?</p>
| 5 | 2010-03-20T21:34:24Z | 2,484,884 | <p>Your current Ruby doesn't do what you describe: it cuts off the last character, but it also reverses the string.</p>
<p>The closest equivalent to the Python snippet would be</p>
<pre><code>output = 'stackoverflow'
puts output[0...-1]
</code></pre>
<p>You originally used <code>..</code> instead of <code>...</code>... | 4 | 2010-03-20T21:40:44Z | [
"python",
"ruby"
] |
What's the Ruby equivalent of Python's output[:-1]? | 2,484,863 | <p>In Python, if I want to get the first n characters of a string minus the last character, I do:</p>
<pre><code>output = 'stackoverflow'
print output[:-1]
</code></pre>
<p>What's the Ruby equivalent?</p>
| 5 | 2010-03-20T21:34:24Z | 2,484,889 | <p>If all you want to do is remove the last character of the string, you can use the 'chop' method as well:</p>
<pre><code>puts output.chop
</code></pre>
<p>or</p>
<pre><code>puts output.chop!
</code></pre>
| 1 | 2010-03-20T21:42:26Z | [
"python",
"ruby"
] |
What's the Ruby equivalent of Python's output[:-1]? | 2,484,863 | <p>In Python, if I want to get the first n characters of a string minus the last character, I do:</p>
<pre><code>output = 'stackoverflow'
print output[:-1]
</code></pre>
<p>What's the Ruby equivalent?</p>
| 5 | 2010-03-20T21:34:24Z | 2,484,890 | <p>If you only want to remove the last character, you can also do</p>
<pre><code>output.chop
</code></pre>
| 1 | 2010-03-20T21:42:40Z | [
"python",
"ruby"
] |
What's the Ruby equivalent of Python's output[:-1]? | 2,484,863 | <p>In Python, if I want to get the first n characters of a string minus the last character, I do:</p>
<pre><code>output = 'stackoverflow'
print output[:-1]
</code></pre>
<p>What's the Ruby equivalent?</p>
| 5 | 2010-03-20T21:34:24Z | 2,484,898 | <p>I don't want to get too nitpicky, but if you want to be more like Python's approach, rather than doing <code>"StackOverflow"[0..-2]</code> you can do <code>"StackOverflow"[0...-1]</code> for the same result.</p>
<p>In Ruby, a range with 3 dots excludes the right argument, where a range with two dots includes it. S... | 11 | 2010-03-20T21:44:39Z | [
"python",
"ruby"
] |
Modify Django settings variables in a middleware | 2,485,274 | <p>I set a variable MAX_REQUEST = 100 in settings.py</p>
<p>I write a middleware which may lower this value for request origining from a proxy ip address by the following code:</p>
<pre><code>settings.MAX_REQUEST = 10
</code></pre>
<p>However, looks like the above modification affects all legitimate users.</p>
<p>I... | 2 | 2010-03-21T00:09:24Z | 2,485,287 | <p>Yes. <code>settings</code> is a module referenced all over by Django (and probably your code too). Modifying any variable in <code>settings</code> is like modifying a global variable and alters the behaviour of your whole web app.</p>
| 6 | 2010-03-21T00:16:18Z | [
"python",
"django",
"settings",
"middleware"
] |
Modify Django settings variables in a middleware | 2,485,274 | <p>I set a variable MAX_REQUEST = 100 in settings.py</p>
<p>I write a middleware which may lower this value for request origining from a proxy ip address by the following code:</p>
<pre><code>settings.MAX_REQUEST = 10
</code></pre>
<p>However, looks like the above modification affects all legitimate users.</p>
<p>I... | 2 | 2010-03-21T00:09:24Z | 2,485,289 | <p>Django settings are global. They affect the whole process.</p>
| 0 | 2010-03-21T00:16:59Z | [
"python",
"django",
"settings",
"middleware"
] |
Modify Django settings variables in a middleware | 2,485,274 | <p>I set a variable MAX_REQUEST = 100 in settings.py</p>
<p>I write a middleware which may lower this value for request origining from a proxy ip address by the following code:</p>
<pre><code>settings.MAX_REQUEST = 10
</code></pre>
<p>However, looks like the above modification affects all legitimate users.</p>
<p>I... | 2 | 2010-03-21T00:09:24Z | 2,485,293 | <p>If you want 'per user' variables, I suggest you look at <a href="http://docs.djangoproject.com/en/dev/topics/http/sessions/" rel="nofollow">How to use sessions</a>.</p>
| 0 | 2010-03-21T00:18:30Z | [
"python",
"django",
"settings",
"middleware"
] |
The problem with installing PIL using virtualenv or buildout | 2,485,295 | <p>When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.</p>
<p>However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.</p>
<p>Here are examples of how I trying to install PIL using virtuale... | 68 | 2010-03-21T00:19:07Z | 2,486,396 | <p>The PIL version packaged on pypi (by the author) is incompatible with setuptools and thus not easy_installable. People have created easy_installable versions elsewhere. Currently, you need to specify a find-links URL and use <a href="https://pypi.python.org/pypi/pip"><code>pip</code></a> get a good package:</p>
<pr... | 92 | 2010-03-21T08:22:30Z | [
"python",
"python-imaging-library",
"easy-install",
"buildout",
"pip"
] |
The problem with installing PIL using virtualenv or buildout | 2,485,295 | <p>When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.</p>
<p>However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.</p>
<p>Here are examples of how I trying to install PIL using virtuale... | 68 | 2010-03-21T00:19:07Z | 7,770,547 | <p>Use <a href="https://github.com/python-imaging/Pillow">Pillow: the "friendly" PIL fork</a> :-) It offers:</p>
<ul>
<li>Full setuptools compatibility</li>
<li>Faster release cycle</li>
<li>No image code changes that differ from PIL (i.e. it aims to track all PIL image code changes, and make none of its own changes w... | 76 | 2011-10-14T16:19:14Z | [
"python",
"python-imaging-library",
"easy-install",
"buildout",
"pip"
] |
The problem with installing PIL using virtualenv or buildout | 2,485,295 | <p>When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.</p>
<p>However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.</p>
<p>Here are examples of how I trying to install PIL using virtuale... | 68 | 2010-03-21T00:19:07Z | 13,642,934 | <p>On Windows, I installed PIL in a virtualenv as follows:</p>
<p>Install PIL in your global python site-packages by executing the .exe from:
<a href="http://www.pythonware.com/products/pil/">http://www.pythonware.com/products/pil/</a></p>
<p>Then, as a "do it yourself-er", copy the PIL.pth file and PIL directory in ... | 5 | 2012-11-30T10:03:55Z | [
"python",
"python-imaging-library",
"easy-install",
"buildout",
"pip"
] |
The problem with installing PIL using virtualenv or buildout | 2,485,295 | <p>When I install PIL using easy_install or buildout it installs in such way, that I must do 'import Image', not 'from PIL import Image'.</p>
<p>However, if I do "apt-get install python-imaging" or use "pip -E test_pil install PIL", all work fine.</p>
<p>Here are examples of how I trying to install PIL using virtuale... | 68 | 2010-03-21T00:19:07Z | 14,881,859 | <p>For Ubuntu I found I needed to to install the C headers package for my python version (2.7)</p>
<p><code>sudo apt-get install python2.7-dev</code></p>
<p>Afterwards, <code>pip install pil</code> worked. </p>
| 7 | 2013-02-14T18:45:03Z | [
"python",
"python-imaging-library",
"easy-install",
"buildout",
"pip"
] |
Learning Python and trying to get first two letters and last two letters of a string | 2,485,300 | <p>Here's my code:</p>
<pre><code># B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
def both_ends(s):
if len(s) <= 2:
return ""
el... | 1 | 2010-03-21T00:20:34Z | 2,485,307 | <p>Misplaced parenthesis:</p>
<pre><code>return s[0] + s[1] + s[len(s)-2] + s[len(s)-1]
</code></pre>
<p>By the way:</p>
<pre><code>return s[0] + s[1] + s[-2] + s[-1]
</code></pre>
<p>or</p>
<pre><code>return s[:2] + s[-2:]
</code></pre>
| 4 | 2010-03-21T00:22:34Z | [
"python"
] |
Learning Python and trying to get first two letters and last two letters of a string | 2,485,300 | <p>Here's my code:</p>
<pre><code># B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
def both_ends(s):
if len(s) <= 2:
return ""
el... | 1 | 2010-03-21T00:20:34Z | 2,485,309 | <p>Your immediate problem is <code>s[len(s-1)]</code> instead of <code>s[len(s)-1]</code> .</p>
<p>You can probably simplify to <code>s[:2] + s[-2:]</code> as well.</p>
| 4 | 2010-03-21T00:22:55Z | [
"python"
] |
Learning Python and trying to get first two letters and last two letters of a string | 2,485,300 | <p>Here's my code:</p>
<pre><code># B. both_ends
# Given a string s, return a string made of the first 2
# and the last 2 chars of the original string,
# so 'spring' yields 'spng'. However, if the string length
# is less than 2, return instead the empty string.
def both_ends(s):
if len(s) <= 2:
return ""
el... | 1 | 2010-03-21T00:20:34Z | 2,485,314 | <p>There is an error in the last part:</p>
<pre><code>return s[0] + s[1] + s[len(s)-2] + s[len(s)-1]
</code></pre>
<p>You can think about rewriting it in a more pythonic way:</p>
<pre><code>return s[0] + s[1] + s[-2] + s[-1]
</code></pre>
| 2 | 2010-03-21T00:23:55Z | [
"python"
] |
Calling gawk from Python | 2,485,362 | <p>I am trying to call <a href="http://en.wikipedia.org/wiki/Gawk_%28GNU_package%29#AWK_versions_and_implementations" rel="nofollow">gawk</a> (the GNU implementation of AWK) from Python in this manner.</p>
<pre><code>import os
import string
import codecs
ligand_file=open( "2WTKA_ab.txt", "r" ) #Open the receptor.txt ... | 1 | 2010-03-21T00:44:29Z | 2,485,368 | <p>Your problem is in the quoting, in python something like <code>"some test "" with quotes"</code> will not give you a quote. Try this instead:</p>
<pre><code>os.system('''gawk '{if ($2=="%s") print $0}' unique_count_a_from_ac.txt''' % i)
</code></pre>
| 1 | 2010-03-21T00:47:50Z | [
"python",
"gawk"
] |
Calling gawk from Python | 2,485,362 | <p>I am trying to call <a href="http://en.wikipedia.org/wiki/Gawk_%28GNU_package%29#AWK_versions_and_implementations" rel="nofollow">gawk</a> (the GNU implementation of AWK) from Python in this manner.</p>
<pre><code>import os
import string
import codecs
ligand_file=open( "2WTKA_ab.txt", "r" ) #Open the receptor.txt ... | 1 | 2010-03-21T00:44:29Z | 2,486,340 | <p>That's a non-portable and messy way to check if something is in a file. Imagine you have 1000 lines, you will be making system call to gawk 1000 times. It's super inefficient. You are using Python, so do them in Python. </p>
<pre><code>....
ligand_file=open( "2WTKA_ab.txt", "r" ) #Open the receptor.txt file
ligand_... | 4 | 2010-03-21T07:41:37Z | [
"python",
"gawk"
] |
Pythonic way of adding "ly" to end of string if it ends in "ing"? | 2,485,378 | <p>This is my first effort on solving the exercise. I gotta say, I'm kind of liking Python. :D</p>
<pre><code># D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchange... | 1 | 2010-03-21T00:51:54Z | 2,485,384 | <p>Pretty good for a beginner! Yes, I would say this is the Pythonic way of doing things. I especially like the way you have commented exactly what the function does. Good work there.</p>
<p>Keep working with Python, though. You're doing fine.</p>
| 0 | 2010-03-21T00:53:17Z | [
"python"
] |
Pythonic way of adding "ly" to end of string if it ends in "ing"? | 2,485,378 | <p>This is my first effort on solving the exercise. I gotta say, I'm kind of liking Python. :D</p>
<pre><code># D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchange... | 1 | 2010-03-21T00:51:54Z | 2,485,389 | <pre><code>def verbing(s):
if len(s) >= 3:
if s.endswith("ing"):
s += "ly"
else:
s += "ing"
return s
</code></pre>
| 6 | 2010-03-21T00:53:55Z | [
"python"
] |
Pythonic way of adding "ly" to end of string if it ends in "ing"? | 2,485,378 | <p>This is my first effort on solving the exercise. I gotta say, I'm kind of liking Python. :D</p>
<pre><code># D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchange... | 1 | 2010-03-21T00:51:54Z | 2,485,406 | <p>How about this little rewrite:</p>
<pre><code>def verbing(s):
if len(s) < 3:
return s
elif s.endswith('ing'):
return s + 'ly'
else:
return s + 'ing'
</code></pre>
| 1 | 2010-03-21T01:00:49Z | [
"python"
] |
Pythonic way of adding "ly" to end of string if it ends in "ing"? | 2,485,378 | <p>This is my first effort on solving the exercise. I gotta say, I'm kind of liking Python. :D</p>
<pre><code># D. verbing
# Given a string, if its length is at least 3,
# add 'ing' to its end.
# Unless it already ends in 'ing', in which case
# add 'ly' instead.
# If the string length is less than 3, leave it unchange... | 1 | 2010-03-21T00:51:54Z | 2,485,435 | <p>I would use <code>s.endswith("ing")</code> in the <code>if</code>, which is also a bit faster, because it doesn't create a new string for the comparision.</p>
<p>And second, I would use docstrings for commenting. This way, you can see your description when you do a <code>help(yourmodule)</code> or when you use some... | 1 | 2010-03-21T01:09:30Z | [
"python"
] |
Python's equivalent of && in an if statement | 2,485,466 | <p>Here's my code:</p>
<pre><code># F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 st... | 340 | 2010-03-21T01:23:03Z | 2,485,471 | <p>You would want <code>and</code> instead of <code>&&</code>.</p>
| 611 | 2010-03-21T01:25:05Z | [
"python",
"if-statement"
] |
Python's equivalent of && in an if statement | 2,485,466 | <p>Here's my code:</p>
<pre><code># F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 st... | 340 | 2010-03-21T01:23:03Z | 2,485,473 | <p>Python uses <code>and</code> and <code>or</code> conditionals.</p>
<p>i.e.</p>
<pre><code>if foo == 'abc' and bar == 'bac' or zoo == '123':
# do something
</code></pre>
| 113 | 2010-03-21T01:26:09Z | [
"python",
"if-statement"
] |
Python's equivalent of && in an if statement | 2,485,466 | <p>Here's my code:</p>
<pre><code># F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 st... | 340 | 2010-03-21T01:23:03Z | 2,485,493 | <p>Two comments:</p>
<ul>
<li>Use <code>and</code> and <code>or</code> for logical operations in Python.</li>
<li>Use 4 spaces to indent instead of 2. You will thank yourself later because your code will look pretty much the same as everyone else's code. See <a href="http://www.python.org/dev/peps/pep-0008/">PEP 8</... | 18 | 2010-03-21T01:35:16Z | [
"python",
"if-statement"
] |
Python's equivalent of && in an if statement | 2,485,466 | <p>Here's my code:</p>
<pre><code># F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 st... | 340 | 2010-03-21T01:23:03Z | 6,121,628 | <p>Probably this is not best code for this task, but is working -</p>
<pre><code>def front_back(a, b):
if len(a) % 2 == 0 and len(b) % 2 == 0:
print a[:(len(a)/2)] + b[:(len(b)/2)] + a[(len(a)/2):] + b[(len(b)/2):]
elif len(a) % 2 == 1 and len(b) % 2 == 0:
print a[:(len(a)/2)+1] + b[:(len(b)/2)] + a[(len(a... | 6 | 2011-05-25T08:33:15Z | [
"python",
"if-statement"
] |
Python's equivalent of && in an if statement | 2,485,466 | <p>Here's my code:</p>
<pre><code># F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 st... | 340 | 2010-03-21T01:23:03Z | 24,149,079 | <p>I went with a purlely mathematical solution:</p>
<pre><code>def front_back(a, b):
return a[:(len(a)+1)//2]+b[:(len(b)+1)//2]+a[(len(a)+1)//2:]+b[(len(b)+1)//2:]
</code></pre>
| 7 | 2014-06-10T19:10:55Z | [
"python",
"if-statement"
] |
Python's equivalent of && in an if statement | 2,485,466 | <p>Here's my code:</p>
<pre><code># F. front_back
# Consider dividing a string into two halves.
# If the length is even, the front and back halves are the same length.
# If the length is odd, we'll say that the extra char goes in the front half.
# e.g. 'abcde', the front half is 'abc', the back half 'de'.
# Given 2 st... | 340 | 2010-03-21T01:23:03Z | 25,472,139 | <p>maybe with & instead % is more fast and mantain readibility</p>
<p>other tests even/odd</p>
<p>x is even ? x % 2 == 0</p>
<p>x is odd ? not x % 2 == 0</p>
<p>maybe is more clear with bitwise and 1</p>
<p>x is odd ? x & 1</p>
<p>x is even ? not x & 1 (not odd)</p>
<pre><code>def front_... | 0 | 2014-08-24T13:21:29Z | [
"python",
"if-statement"
] |
Python mistaking float for string | 2,485,521 | <p>I receive</p>
<pre><code>TypeError: Can't convert 'float' object to str implicitly
</code></pre>
<p>while using</p>
<pre><code>Gambler.pot += round(self.bet + self.money * 0.1)
</code></pre>
<p>where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse... | 3 | 2010-03-21T01:45:57Z | 2,485,527 | <p>If any of <code>Gambler.pot</code>, <code>self.bet</code> or <code>self.money</code> have somehow become strings (because they were set to a string at some point), <code>+</code> will be taken to mean string concatenation which causes the error message you see. </p>
| 3 | 2010-03-21T01:49:52Z | [
"python",
"string",
"floating-point",
"python-3.x"
] |
Python mistaking float for string | 2,485,521 | <p>I receive</p>
<pre><code>TypeError: Can't convert 'float' object to str implicitly
</code></pre>
<p>while using</p>
<pre><code>Gambler.pot += round(self.bet + self.money * 0.1)
</code></pre>
<p>where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse... | 3 | 2010-03-21T01:45:57Z | 2,485,541 | <p>Python3.2 <sup>(py3k:77602)</sup> gives these error messages:</p>
<pre>
>>> "1.2" * 0.1 #1
Traceback (most recent call last):
File "", line 1, in
TypeError: can't multiply sequence by non-int of type 'float'
>>> "3.4" + 1.2 * 0.1 ... | 3 | 2010-03-21T01:54:34Z | [
"python",
"string",
"floating-point",
"python-3.x"
] |
Python mistaking float for string | 2,485,521 | <p>I receive</p>
<pre><code>TypeError: Can't convert 'float' object to str implicitly
</code></pre>
<p>while using</p>
<pre><code>Gambler.pot += round(self.bet + self.money * 0.1)
</code></pre>
<p>where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse... | 3 | 2010-03-21T01:45:57Z | 2,485,552 | <p>As was said in a comment, what you've shown is initializing local variables to 0. Instead try something like:</p>
<pre><code>class Gambler:
def __init__(self):
self.bet = 0.0
self.money = 0.0
def calc_pot(self):
self.pot = round(self.bet + self.money * 0.1)
g = Gambler()
g.bet = ... | 0 | 2010-03-21T01:59:12Z | [
"python",
"string",
"floating-point",
"python-3.x"
] |
Python mistaking float for string | 2,485,521 | <p>I receive</p>
<pre><code>TypeError: Can't convert 'float' object to str implicitly
</code></pre>
<p>while using</p>
<pre><code>Gambler.pot += round(self.bet + self.money * 0.1)
</code></pre>
<p>where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse... | 3 | 2010-03-21T01:45:57Z | 2,485,594 | <p><code>input()</code> in 3.x only returns strings. It is the programmer's job to pass it to a numeric constructor in order to turn it into a number.</p>
| 6 | 2010-03-21T02:13:19Z | [
"python",
"string",
"floating-point",
"python-3.x"
] |
Python mistaking float for string | 2,485,521 | <p>I receive</p>
<pre><code>TypeError: Can't convert 'float' object to str implicitly
</code></pre>
<p>while using</p>
<pre><code>Gambler.pot += round(self.bet + self.money * 0.1)
</code></pre>
<p>where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse... | 3 | 2010-03-21T01:45:57Z | 2,485,609 | <p>In Python 3.x, <code>input()</code> replaces Python 2.x's <code>raw_input()</code>. Therefore, the function <code>input()</code> returns the exact string that the user input (as <code>raw_input()</code> did in previous versions).</p>
<p>To get Python 2.x behavior, you can just do</p>
<pre><code>number = eval(input... | 2 | 2010-03-21T02:18:59Z | [
"python",
"string",
"floating-point",
"python-3.x"
] |
Python mistaking float for string | 2,485,521 | <p>I receive</p>
<pre><code>TypeError: Can't convert 'float' object to str implicitly
</code></pre>
<p>while using</p>
<pre><code>Gambler.pot += round(self.bet + self.money * 0.1)
</code></pre>
<p>where pot, bet, and money are all doubles (or at least are supposed to be). I'm not sure if this is yet another Eclipse... | 3 | 2010-03-21T01:45:57Z | 2,485,611 | <p>Are you initializing pot? Have you tried storing intermediate results to track down here the problem is coming from? And finally, do you know about <a href="http://docs.python.org/library/pdb.html" rel="nofollow">pdb</a>? That may be a big help.</p>
<pre><code>class Gambler:
pot = 0.0
def __init__(self, ... | 4 | 2010-03-21T02:20:13Z | [
"python",
"string",
"floating-point",
"python-3.x"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,485,706 | <p>I know of no Python stdlib function that quite does that. It's easy enough to do. Here is a generator that basically does it:</p>
<pre><code>def chunks(sequence, length):
for index in xrange(0, len(sequence) - length + 1):
yield sequence[index:index + length]
</code></pre>
<p>You could use it like so</... | 0 | 2010-03-21T02:50:41Z | [
"python",
"numpy",
"scipy"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,485,724 | <p>Quick&dirty solution:</p>
<pre><code>>>> a = numpy.arange(1,15)
>>> numpy.array([ a[i:i+4] for i in range(len(a)-3) ])
array([[ 1, 2, 3, 4],
[ 2, 3, 4, 5],
[ 3, 4, 5, 6],
[ 4, 5, 6, 7],
[ 5, 6, 7, 8],
[ 6, 7, 8, 9],
[ 7, 8, 9, 10],
... | 4 | 2010-03-21T02:56:43Z | [
"python",
"numpy",
"scipy"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,485,742 | <p>Using <a href="http://docs.python.org/library/itertools.html" rel="nofollow">itertools</a>, and assuming Python 2.6:</p>
<pre><code>import itertools
def byN(iterable, N):
itrs = itertools.tee(iter(iterable), N)
for n in range(N):
for i in range(n):
next(itrs[n], None)
return zip(*it... | 1 | 2010-03-21T03:04:02Z | [
"python",
"numpy",
"scipy"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,485,777 | <p>The fastest way seems to be to preallocate the array, given as option 7 right at the bottom of this answer.</p>
<pre><code>>>> import numpy as np
>>> A=np.array([1,2,3,4,5,6,7,8,9,10,11,12,13,14])
>>> A
array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])
>>> np.array(... | 12 | 2010-03-21T03:19:27Z | [
"python",
"numpy",
"scipy"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,486,017 | <p>The efficient NumPy way to do this is given <a href="http://projects.scipy.org/numpy/attachment/ticket/901/segmentaxis.py" rel="nofollow">here</a>, which is somewhat too long to reproduce here. It boils down to using some stride tricks, and is much faster than itertools for largish window sizes. For example, using... | 0 | 2010-03-21T05:08:59Z | [
"python",
"numpy",
"scipy"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,487,551 | <p>You should use <code>stride_tricks</code>. When I first saw this, the word 'magic' did spring to mind. It's simple and is by far the fastest method.</p>
<pre><code>>>> as_strided = numpy.lib.stride_tricks.as_strided
>>> a = numpy.arange(1,15)
>>> a
array([ 1, 2, 3, 4, 5, 6, 7, 8,... | 17 | 2010-03-21T15:19:48Z | [
"python",
"numpy",
"scipy"
] |
Consecutive, Overlapping Subsets of Array (NumPy, Python) | 2,485,669 | <p>I have a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array <code>[1,2,3,4,5,6,7,8,9,10,11,12,13,14]</code> and want to have an array structured like <code>[[1,2,3,4], [2,3,4,5], [3,4,5,6], ..., [11,12,13,14]]</code>.</p>
<p>Sure this is possible by looping over the large array and adding a... | 8 | 2010-03-21T02:38:38Z | 2,490,995 | <p>Broadcast!</p>
<pre><code>from numpy import ogrid
def stretch(N=5,M=15):
x, y = ogrid[0:M,0:N]
return x+y+1
</code></pre>
<p>Note that ogrid does give things like:</p>
<pre><code>>> ogrid[0:5,0:5]
>>
[array([[0],
[1],
[2],
[3],
[4]]),
array([[0, 1, 2, 3, 4]])]
</c... | 1 | 2010-03-22T09:15:59Z | [
"python",
"numpy",
"scipy"
] |
very quickly getting total size of folder | 2,485,719 | <p>I want to quickly find the total size of any folder using python.</p>
<pre><code>import os
from os.path import join, getsize, isfile, isdir, splitext
def GetFolderSize(path):
TotalSize = 0
for item in os.walk(path):
for file in item[2]:
try:
TotalSize = TotalSize + getsiz... | 39 | 2010-03-21T02:54:56Z | 2,485,804 | <p>If you want same speed as explorer, why not use the windows scripting to access same functionality using pythoncom e.g.</p>
<pre><code>import win32com.client as com
folderPath = r"D:\Software\Downloads"
fso = com.Dispatch("Scripting.FileSystemObject")
folder = fso.GetFolder(folderPath)
MB=1024*1024.0
print "%.2f ... | 15 | 2010-03-21T03:31:50Z | [
"python",
"optimization",
"folders"
] |
very quickly getting total size of folder | 2,485,719 | <p>I want to quickly find the total size of any folder using python.</p>
<pre><code>import os
from os.path import join, getsize, isfile, isdir, splitext
def GetFolderSize(path):
TotalSize = 0
for item in os.walk(path):
for file in item[2]:
try:
TotalSize = TotalSize + getsiz... | 39 | 2010-03-21T02:54:56Z | 2,485,823 | <p>I compared the performance of the Python code against a 15k directory tree containing 190k files and compared it against the <code>du(1)</code> command which presumably goes about as fast as the OS. The Python code took 3.3 seconds compared to du which took 0.8 seconds. This was on Linux.</p>
<p>I'm not sure there ... | 5 | 2010-03-21T03:41:47Z | [
"python",
"optimization",
"folders"
] |
very quickly getting total size of folder | 2,485,719 | <p>I want to quickly find the total size of any folder using python.</p>
<pre><code>import os
from os.path import join, getsize, isfile, isdir, splitext
def GetFolderSize(path):
TotalSize = 0
for item in os.walk(path):
for file in item[2]:
try:
TotalSize = TotalSize + getsiz... | 39 | 2010-03-21T02:54:56Z | 2,485,843 | <p>You are at a disadvantage.</p>
<p>Windows Explorer almost certainly uses <a href="http://msdn.microsoft.com/en-us/library/aa364418(VS.85).aspx"><code>FindFirstFile</code></a>/<a href="http://msdn.microsoft.com/en-us/library/aa364428(VS.85).aspx"><code>FindNextFile</code></a> to both traverse the directory structure... | 65 | 2010-03-21T03:47:22Z | [
"python",
"optimization",
"folders"
] |
Django model: Reference foreign key table in __unicode__ function for admin | 2,485,766 | <p>Example models:</p>
<pre><code>class Parent(models.Model):
name = models.CharField()
def __unicode__(self):
return self.name
class Child(models.Model):
parent = models.ForeignKey(Parent)
def __unicode__(self):
return self.parent.name # Would reference name above
</code></pre>
<p>... | 2 | 2010-03-21T03:15:50Z | 2,485,779 | <pre><code>return u'Child of %s' % unicode(self.parent)
</code></pre>
<p>Obviously you've defined a <code>__unicode__()</code> method in the parent that makes sense, right?</p>
| 3 | 2010-03-21T03:19:42Z | [
"python",
"django",
"admin"
] |
Clever way of building a tag cloud? - Python | 2,485,800 | <p>I've built a content aggregator and would like to add a tag cloud representing the current trends.</p>
<p>Unfortunately this is quite complex, as I have to look for <strong>keywords</strong> that represent the context of each article.</p>
<p>For example words such as <strong>I</strong>, <strong>was</strong>, <stro... | 4 | 2010-03-21T03:29:51Z | 2,485,805 | <p><a href="http://www.nltk.org/" rel="nofollow">NLTK</a> can help you analyze the content in order to pick out relevant terms.</p>
| 2 | 2010-03-21T03:32:03Z | [
"python",
"django",
"indexing",
"keyword",
"data-mining"
] |
Clever way of building a tag cloud? - Python | 2,485,800 | <p>I've built a content aggregator and would like to add a tag cloud representing the current trends.</p>
<p>Unfortunately this is quite complex, as I have to look for <strong>keywords</strong> that represent the context of each article.</p>
<p>For example words such as <strong>I</strong>, <strong>was</strong>, <stro... | 4 | 2010-03-21T03:29:51Z | 2,485,807 | <p>Use <a href="http://www.acm.org/crossroads/xrds13-4/natural_language.html">NLTK</a>, and in particular its <strong>Stopwords corpus</strong>:</p>
<blockquote>
<p>Besides regular content words, there
is another class of words called stop
words that perform important
grammatical functions, but are
unlikely ... | 9 | 2010-03-21T03:34:16Z | [
"python",
"django",
"indexing",
"keyword",
"data-mining"
] |
Converting JSON into Python dict | 2,485,817 | <p>I've been searching around trying to find an answer to this question, and I can't seem to track it down. Maybe it's too late in the evening to figure the answer out, so I turn to the excellent readers here.</p>
<p>I have the following bit of JSON data that I am pulling out of a CouchDB record:</p>
<pre><code>"{\"... | 20 | 2010-03-21T03:38:29Z | 2,485,825 | <pre><code>django.utils.simplejson.loads(someJson)
</code></pre>
| 2 | 2010-03-21T03:42:17Z | [
"python",
"django",
"json",
"dictionary"
] |
Converting JSON into Python dict | 2,485,817 | <p>I've been searching around trying to find an answer to this question, and I can't seem to track it down. Maybe it's too late in the evening to figure the answer out, so I turn to the excellent readers here.</p>
<p>I have the following bit of JSON data that I am pulling out of a CouchDB record:</p>
<pre><code>"{\"... | 20 | 2010-03-21T03:38:29Z | 2,485,831 | <p>The string you show is not a JSON-coded object (eqv to a Python dict) â more like an array (eqv to a list) without brackets and with a stray extra comma at the end. So (using <a href="http://simplejson.googlecode.com/svn/tags/simplejson-2.1.0/docs/index.html" rel="nofollow">simplejson</a> for version portability ... | 16 | 2010-03-21T03:43:49Z | [
"python",
"django",
"json",
"dictionary"
] |
Converting JSON into Python dict | 2,485,817 | <p>I've been searching around trying to find an answer to this question, and I can't seem to track it down. Maybe it's too late in the evening to figure the answer out, so I turn to the excellent readers here.</p>
<p>I have the following bit of JSON data that I am pulling out of a CouchDB record:</p>
<pre><code>"{\"... | 20 | 2010-03-21T03:38:29Z | 2,485,833 | <ul>
<li><p>Use the <code>json</code> module for loading JSON. (Pre-2.6 use the third party <code>simplejson</code> module, which has the same exact API.)</p>
<pre><code>>>> import json
>>> s = '{"foo": 6, "bar": [1, 2, 3]}'
>>> d = json.loads(s)
>>> print d
{u'foo': 6, u'bar': [1, ... | 31 | 2010-03-21T03:44:35Z | [
"python",
"django",
"json",
"dictionary"
] |
How to import modules that are used in both the main code and a module correctly? | 2,485,901 | <p>Let's assume I have a main script, main.py, that imports another python file with <code>import coolfunctions</code> and another: <code>import chores</code></p>
<p>Now, suppose coolfunctions also uses stuff from chores, hence I declare <code>import chores</code> inside coolfunctions.</p>
<p>Since both main.py, ... | 2 | 2010-03-21T04:18:30Z | 2,485,922 | <p>No, this isn't redundant - it's fine to <code>import chores</code> in both the main module and <code>coolfunctions</code>.</p>
<p>The exact import mechanics of Python are complex (for example, module imports are only done once, meaning in your case that the actual parsing and loading of the <code>chores</code> modu... | 1 | 2010-03-21T04:25:30Z | [
"python",
"file",
"import",
"module"
] |
How to import modules that are used in both the main code and a module correctly? | 2,485,901 | <p>Let's assume I have a main script, main.py, that imports another python file with <code>import coolfunctions</code> and another: <code>import chores</code></p>
<p>Now, suppose coolfunctions also uses stuff from chores, hence I declare <code>import chores</code> inside coolfunctions.</p>
<p>Since both main.py, ... | 2 | 2010-03-21T04:18:30Z | 2,485,940 | <p>It is always the best practice to import all necessary modules in the file that uses them. Take for example:</p>
<p>A.py contains: <code>import coolfunctions</code></p>
<p>B.py contains: <code>import A</code></p>
<p>Main.py contains: <code>import B</code> and uses functions that are defined in A.py (this is possi... | 0 | 2010-03-21T04:33:42Z | [
"python",
"file",
"import",
"module"
] |
How to import modules that are used in both the main code and a module correctly? | 2,485,901 | <p>Let's assume I have a main script, main.py, that imports another python file with <code>import coolfunctions</code> and another: <code>import chores</code></p>
<p>Now, suppose coolfunctions also uses stuff from chores, hence I declare <code>import chores</code> inside coolfunctions.</p>
<p>Since both main.py, ... | 2 | 2010-03-21T04:18:30Z | 2,485,941 | <p>If two modules want to use <code>chores</code>, then each one <em>must</em> <code>import chores</code> (or some equivalent import). Each import creates a name binding only in the namespace of the module that does the import; that is, <a href="http://docs.python.org/reference/simple_stmts.html#import" rel="nofollow">... | 2 | 2010-03-21T04:33:54Z | [
"python",
"file",
"import",
"module"
] |
How to import modules that are used in both the main code and a module correctly? | 2,485,901 | <p>Let's assume I have a main script, main.py, that imports another python file with <code>import coolfunctions</code> and another: <code>import chores</code></p>
<p>Now, suppose coolfunctions also uses stuff from chores, hence I declare <code>import chores</code> inside coolfunctions.</p>
<p>Since both main.py, ... | 2 | 2010-03-21T04:18:30Z | 2,485,978 | <p>Each module X should import all (and only) the modules Y, Z, T, ... whose functionality it requires, without any worry about what other modules Fee, Fie, Foo ... (if any) may have already done part or all of those imports, or may be going to do so in the future.</p>
<p>It would make a module extremely fragile (inde... | 1 | 2010-03-21T04:48:32Z | [
"python",
"file",
"import",
"module"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 2,486,169 | <p>I think you can try send a http request to the url and read the response.If no exception was caught,it probably exists.</p>
| 0 | 2010-03-21T06:17:03Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 2,486,219 | <p>Looks like <code>http://www.fakedomain.com/fakeImage.jpg</code> automatically redirected to <code>http://www.fakedomain.com/index.html</code> without any error.</p>
<p>Redirecting for 301 and 302 responses are automatically done without giving any response back to user.</p>
<p>Please take a look <a href="http://do... | 3 | 2010-03-21T06:32:10Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 2,486,412 | <pre><code>>>> import httplib
>>>
>>> def exists(site, path):
... conn = httplib.HTTPConnection(site)
... conn.request('HEAD', path)
... response = conn.getresponse()
... conn.close()
... return response.status == 200
...
>>> exists('http://www.fakedomain.com', '/... | 27 | 2010-03-21T08:27:44Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 2,486,459 | <p>I don't know why you are doing this, but in any case: it should be noted that just because a request to an "image" succeeds, doesn't mean it is what you think it is (it could redirect to anything, or return any data of any type, and potentially cause problems depending on what you do with the response).</p>
<p>Sorr... | 0 | 2010-03-21T08:58:15Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 2,487,207 | <p>Try it with <a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a>:</p>
<pre><code>import mechanize
br = mechanize.Browser()
br.set_handle_redirect(False)
try:
br.open_novisit('http://www.fakedomain.com/fakeImage.jpg')
print 'OK'
except:
print 'KO'
</code></pre>
| 1 | 2010-03-21T13:22:25Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 2,489,558 | <p>thanks for all the responses everyone, ended up using the following:</p>
<pre><code>try:
f = urllib2.urlopen(urllib2.Request(url))
deadLinkFound = False
except:
deadLinkFound = True
</code></pre>
| 6 | 2010-03-22T01:33:23Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 15,697,444 | <p>There are problems with the previous answers when the file is in ftp server (<a href="ftp://url.com/file" rel="nofollow">ftp://url.com/file</a>), the following code works when the file is in ftp, http or https:</p>
<pre><code>import urllib2
def file_exists(url):
request = urllib2.Request(url)
request.get_m... | 3 | 2013-03-29T04:38:29Z | [
"python",
"url",
"validation"
] |
python: check if url to jpg exists | 2,486,145 | <p>In python, how would I check if a url ending in .jpg exists?</p>
<p>ex:
<a href="http://www.fakedomain.com/fakeImage.jpg">http://www.fakedomain.com/fakeImage.jpg</a></p>
<p>thanks</p>
| 19 | 2010-03-21T06:09:17Z | 19,582,542 | <p>The code below is equivalent to <a href="http://stackoverflow.com/a/2486412/596361">tikiboy's answer</a>, but using a high-level and easy-to-use <a href="http://docs.python-requests.org/en/latest/">requests</a> library.</p>
<pre><code>import requests
def exists(path):
r = requests.head(path)
return r.statu... | 14 | 2013-10-25T06:26:18Z | [
"python",
"url",
"validation"
] |
Need help with re for matching and getting the value python | 2,486,150 | <p>Need help regarding re.</p>
<pre><code>file = 'file No.WR79050107006 from files'
</code></pre>
<p>So what I am trying to do is validate if file string contains WR + 11 digit.</p>
<pre><code>result = re.match('^(\S| )*(?P<sr>(\d){11})(\S| )*', file)
</code></pre>
<p>Its validate only 11 digit but not WR be... | 0 | 2010-03-21T06:10:35Z | 2,486,155 | <p>Try this:</p>
<pre><code>result = re.search("No.WR\d{11}", file)
</code></pre>
| 0 | 2010-03-21T06:12:47Z | [
"python"
] |
Need help with re for matching and getting the value python | 2,486,150 | <p>Need help regarding re.</p>
<pre><code>file = 'file No.WR79050107006 from files'
</code></pre>
<p>So what I am trying to do is validate if file string contains WR + 11 digit.</p>
<pre><code>result = re.match('^(\S| )*(?P<sr>(\d){11})(\S| )*', file)
</code></pre>
<p>Its validate only 11 digit but not WR be... | 0 | 2010-03-21T06:10:35Z | 2,486,172 | <p>If by "validate if file string contains WR + 11 digit" you mean "exactly 11, not 12+",</p>
<pre><code>mo = re.search(r'WR(\d{11})(\D|$)', thestring)
</code></pre>
<p>should do. If you actually mean "11 or more", there's no need for the <code>(\D|$)</code> part (or equivalent negative lookahead, etc).</p>
<p><str... | 1 | 2010-03-21T06:18:02Z | [
"python"
] |
Need help with re for matching and getting the value python | 2,486,150 | <p>Need help regarding re.</p>
<pre><code>file = 'file No.WR79050107006 from files'
</code></pre>
<p>So what I am trying to do is validate if file string contains WR + 11 digit.</p>
<pre><code>result = re.match('^(\S| )*(?P<sr>(\d){11})(\S| )*', file)
</code></pre>
<p>Its validate only 11 digit but not WR be... | 0 | 2010-03-21T06:10:35Z | 2,486,174 | <pre><code>>>> file = 'file No.WR79050107006 from files'
>>> for item in file.split():
... if "No.WR" in item:
... d=item.replace("No.WR","")
... if d.isdigit() and len(d) == 11:
... print "ok"
...
ok
</code></pre>
| 0 | 2010-03-21T06:18:25Z | [
"python"
] |
Need help with re for matching and getting the value python | 2,486,150 | <p>Need help regarding re.</p>
<pre><code>file = 'file No.WR79050107006 from files'
</code></pre>
<p>So what I am trying to do is validate if file string contains WR + 11 digit.</p>
<pre><code>result = re.match('^(\S| )*(?P<sr>(\d){11})(\S| )*', file)
</code></pre>
<p>Its validate only 11 digit but not WR be... | 0 | 2010-03-21T06:10:35Z | 2,486,988 | <p>It's not clear from your comment on Alex's answer. Is the record valid if there is a space between the <code>WR</code> and the 11 digits?</p>
<p>Hopefully one of these examples help. Otherwise add the other variations and expected results to your question, and you should get answers that are straight to the point.<... | 0 | 2010-03-21T12:07:26Z | [
"python"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,360 | <p><a href="http://www.renpy.org/" rel="nofollow">Ren'Py</a> is a modification to Python syntax built on top of Python itself, using the <a href="http://docs.python.org/library/language.html" rel="nofollow">language tools</a> in the stdlib.</p>
| 3 | 2010-03-21T07:59:48Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,375 | <p>Possibly Common Lisp (or any other Lisp) will be the best choice for that task. Because Lisp make it possible to easily extend host language with powerful macroses and construct DSL (domain specific language).</p>
| 0 | 2010-03-21T08:05:25Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,378 | <p>The question isn't completely clear on scope, but I have a hunch that PyPy, embedding other full languages, and similar solutions might be overkill. It sounds like iamgopal may really be interested in something more like <a href="http://en.wikipedia.org/wiki/Interpreter_pattern" rel="nofollow">Interpreter Pattern</... | 4 | 2010-03-21T08:08:09Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,403 | <p>Why not Python itself? With some care you can use <code>eval</code> to run user code.</p>
<p>One of the good thing about interpreted scripting languages is that you don't need another extra scripting language!</p>
| 1 | 2010-03-21T08:24:26Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,411 | <p>If all you need is simple if statements and expressions, I'm sure it wouldn't be an awful task to parse each line. Something like</p>
<pre><code>if some flag
activate some feature
deactivate some feature
elif some other flag
activate some feature
activate some feature
else
logout
</code></pre>
... | 0 | 2010-03-21T08:27:36Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,450 | <p>For your user's sake, don't use an XML based language - XML is an awful basis for a programming language and your users will hate you for it.</p>
<p>Here is a suggestion. Use a strict subset of Python for your language. Use the <a href="http://docs.python.org/library/compiler.html" rel="nofollow">compiler module<... | 3 | 2010-03-21T08:53:09Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,486,712 | <p><strong><a href="http://www.dabeaz.com/ply/" rel="nofollow">PLY (Python Lex-Yacc)</a></strong>
is something of your interest.</p>
| 1 | 2010-03-21T10:31:37Z | [
"python",
"programming-languages",
"interpreter"
] |
programming language implemented in pure python | 2,486,348 | <p>i am creating ( researching possibility of ) a highly customizable python client and would like to allow users to actually edit the code in another language to customize the running of program. ( analogous to browser which itself coded in c/c++ and run another language html/js ). so my question is , is there any pro... | 2 | 2010-03-21T07:46:30Z | 2,487,912 | <p>Numerous template languages such as Cheetah, Django templates, Genshi, Mako, Mighty might serve as an example.</p>
| 1 | 2010-03-21T17:09:01Z | [
"python",
"programming-languages",
"interpreter"
] |
Convert python script to binary executable | 2,486,737 | <p>I wrote a number crunching python code. The calculations involved can take hours. Is it possible somehow to compile it to binary?</p>
<p>Thanks</p>
| 0 | 2010-03-21T10:41:38Z | 2,486,744 | <p>Not in any useful (for you) way, but moving the calculations into <a href="http://numpy.scipy.org/" rel="nofollow">NumPy</a> or <a href="http://www.cython.org/" rel="nofollow">Cython</a> will speed them up.</p>
| 5 | 2010-03-21T10:43:41Z | [
"python"
] |
Convert python script to binary executable | 2,486,737 | <p>I wrote a number crunching python code. The calculations involved can take hours. Is it possible somehow to compile it to binary?</p>
<p>Thanks</p>
| 0 | 2010-03-21T10:41:38Z | 2,486,751 | <p>First you can try psyco, that may give you a speed up as much as 10x, but 2x is more typical</p>
<p>If you can post the code up somewhere, perhaps someone can point out how to leverage numpy.</p>
<p>If your task doesn't map well only numpy then cython is a good choice to convert a intensive function or two into C ... | 3 | 2010-03-21T10:46:43Z | [
"python"
] |
Convert python script to binary executable | 2,486,737 | <p>I wrote a number crunching python code. The calculations involved can take hours. Is it possible somehow to compile it to binary?</p>
<p>Thanks</p>
| 0 | 2010-03-21T10:41:38Z | 2,486,869 | <p><a href="http://code.google.com/p/shedskin/" rel="nofollow">Shedskin</a> might be worth a try.</p>
<p>From their front page blurb:</p>
<blockquote>
<p>Shed Skin is an experimental compiler,
that can translate pure, but
implicitly statically typed Python
programs into optimized C++. It can
generate stand-... | 2 | 2010-03-21T11:25:49Z | [
"python"
] |
diffstrings.py : how do you specify path arguments? | 2,486,822 | <p>I am trying to use diffstrings.py from Three20 on my iPhone project, and I can't find the proper format for the path arguments (as in "Usage: diffstrings.py [options] path1 path2 ...").</p>
<p>For example, when I run the script in my Xcode project directory like this
~/py/diffstrings.py -b
it analyzes just the mai... | 0 | 2010-03-21T11:10:57Z | 2,487,262 | <p>Taking a quick look at the code here <a href="http://github.com/facebook/three20/blob/master/diffstrings.py" rel="nofollow">http://github.com/facebook/three20/blob/master/diffstrings.py</a> I see that if you don't specify <em>any</em> command line options, it assumes you mean the directory <em>wherever the script li... | 0 | 2010-03-21T13:40:22Z | [
"iphone",
"python",
"localization"
] |
why my code does not load the kml file ..(it is the simplest way) | 2,486,846 | <p>this is my google-map code:</p>
<pre><code><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
... | 0 | 2010-03-21T11:20:03Z | 2,487,069 | <p>My first thought is that you were missing <code><Document></Document></code> -- but looking at the docs I'm not sure that's right.</p>
<p>Is <code>b.kml</code> being served with the mime type <code>application/vnd.google-earth.kml+xml</code>? Looking at the documentation, it seems like that's a requirem... | 0 | 2010-03-21T12:37:40Z | [
"javascript",
"python",
"google-maps",
"kml"
] |
why my code does not load the kml file ..(it is the simplest way) | 2,486,846 | <p>this is my google-map code:</p>
<pre><code><!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
... | 0 | 2010-03-21T11:20:03Z | 7,595,761 | <p>You need to give the publicly accessible url to your .kml file.</p>
<p>You won't see a request for it in firebug. The maps api requests a resource from google and passes the name of your kml file. google pulls it in to thier servers and processes it and delivers json to the map in your page.</p>
<p>IMHO. YMMV</p>
| 0 | 2011-09-29T10:10:27Z | [
"javascript",
"python",
"google-maps",
"kml"
] |
usb device identification | 2,487,033 | <p>hello all
i am using python on ubuntu 9.04
say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like</p>
<p>if usb port id == A
write data to device 1
if usb port id == B
write data to device 2</p>
<p>any ideas....</p>
| 3 | 2010-03-21T12:22:33Z | 2,487,095 | <p>Have you tried <a href="http://sourceforge.net/apps/mediawiki/pyusb/index.php?title=Main_Page" rel="nofollow">pyUsb</a>?
Here a snippet of what you can do:</p>
<pre><code>import usb
busses = usb.busses()
for bus in busses:
devices = bus.devices
for dev in devices:
print "Device:", dev.filename
... | 5 | 2010-03-21T12:46:52Z | [
"python",
"control",
"port",
"device"
] |
usb device identification | 2,487,033 | <p>hello all
i am using python on ubuntu 9.04
say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like</p>
<p>if usb port id == A
write data to device 1
if usb port id == B
write data to device 2</p>
<p>any ideas....</p>
| 3 | 2010-03-21T12:22:33Z | 12,392,077 | <p>@systempuntoout's answer is nice but today I have found an easier way to find or iterate over all devices: <code>usb.core.find(find_all=True)</code></p>
<p>Following with your example:</p>
<pre><code>import usb
for dev in usb.core.find(find_all=True):
print "Device:", dev.filename
print " idVendor: %d (%s... | 2 | 2012-09-12T15:54:21Z | [
"python",
"control",
"port",
"device"
] |
usb device identification | 2,487,033 | <p>hello all
i am using python on ubuntu 9.04
say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like</p>
<p>if usb port id == A
write data to device 1
if usb port id == B
write data to device 2</p>
<p>any ideas....</p>
| 3 | 2010-03-21T12:22:33Z | 21,833,149 | <p>but whatever.. someone will look for the answer at some point:</p>
<p>I'm on a mac (osx 10.9).. I successfully installed libusb with mac ports, but was getting the "no backend available" message. It's because python can't find the usb dylibs.</p>
<p>You have to add the path to your libusb to your $DYLD_LIBRARY_P... | 1 | 2014-02-17T15:36:22Z | [
"python",
"control",
"port",
"device"
] |
usb device identification | 2,487,033 | <p>hello all
i am using python on ubuntu 9.04
say i have two usb devices connected to a single PC. how can i identify the devices in python code.....for example like</p>
<p>if usb port id == A
write data to device 1
if usb port id == B
write data to device 2</p>
<p>any ideas....</p>
| 3 | 2010-03-21T12:22:33Z | 33,295,393 | <p>Ok i was also googling around for answers, here is snippet that works:</p>
<pre><code>def locate_usb():
import win32file
drive_list = []
drivebits=win32file.GetLogicalDrives()
for d in range(1,26):
mask=1 << d
if drivebits & mask:
# here if the drive is at least there
drname='%c:\\... | 0 | 2015-10-23T05:26:11Z | [
"python",
"control",
"port",
"device"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,487,100 | <p>There are errors other than "typos". If you don't test something, knowing that something's found misspelled variable names won't assure you of much anyway.</p>
| 3 | 2010-03-21T12:48:12Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,487,108 | <p>Some editors (for example, NetBeans) analyse your code and underline "suspicious" parts, for example unused variables, which may be sign of a typo. NB also highlights the identifier above the cursor elsewhere on the screen, which also helps.</p>
<p>Of course, no clever IDE trick can replace proper testing.</p>
| 3 | 2010-03-21T12:51:36Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,487,124 | <p>TDD -- write your tests first, then the simplest code to pass the test. That way you can be more sure that you don't have any untested code. This will help make sure you have fewer typos or other errors in your code.</p>
<p>Pair programming/code reviews -- two pairs of eyes are better than one pair.</p>
<p>IDE w... | 1 | 2010-03-21T12:57:56Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,487,685 | <p>Really-thorough unit tests are the most important technique (yes, I do always aim for 100% coverage), as they also catch many other typos (e.g. where I write <code>+</code> and meant <code>-</code>), off-by-one issues, etc. Integration and load tests exercising every feature are the second line of defense against a... | 31 | 2010-03-21T16:00:35Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,487,701 | <p>Many unit test tools can show the percentage of lines they tested. The closer this percentage is to 100% the less likely variable name typo was done.</p>
| 0 | 2010-03-21T16:04:31Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,488,124 | <p>I write all my Python code in eclipse IDE. As Mladen JablanoviÄ has suggested, eclipse underlines suspicious parts.</p>
<p>Next step is to run the code. Now there are two kinds of errors that I am likely to face.</p>
<ol>
<li><p>Errors that the interpreter catches and gives me a line number for: These are typical... | -1 | 2010-03-21T18:11:32Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,489,052 | <p>In ruby, a misspelled local variable would cause the program to die horribly, which is fine.</p>
<p>A misspelled instance variable doesn't cause the program to die horribly, which is bad. To detect such cases, <a href="http://web.archive.org/web/20100817183958/http://eigenclass.org/hiki/ruby-warnings-SEX-and-stds" ... | 1 | 2010-03-21T22:42:12Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,588,911 | <p>In my case, I use unit testing extensively (developing in Python). Because there are many lightweight testing frameworks well integrated into the language (or IDE if you prefer), using them cause you almost no pain ;)</p>
<p>Look at this example: </p>
<pre><code>def unpack_args(func):
def deco_func(*args):
... | 1 | 2010-04-06T22:59:54Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 2,589,011 | <p>I presume by 'typo' you mean mistyping variable/function/class names. This is less of an issue in Python than in Perl, since Perl (and I believe Ruby) by default will automatically create a variable and initialise it to zero or "" on its first use. Python does not do this since it is an error to use a variable tha... | 1 | 2010-04-06T23:22:02Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Catching typos in scripting languages | 2,487,089 | <p>If your scripting language of choice doesn't have something like Perl's <a href="http://perldoc.perl.org/strict.html">strict</a> mode, how are you catching typos? Are you unit testing everything? Every constructor, every method? Is this the only way to go about it?</p>
| 29 | 2010-03-21T12:43:56Z | 4,637,768 | <p>In Groovy, the abstract syntax tree (AST) that makes up a program is readily available. So tools can be written that inspect the AST and issue warnings for things that are probably errors.</p>
<p>For example, <a href="http://www.groovylint.com" rel="nofollow">GroovyLint</a> will warn you if you try to call a metho... | 0 | 2011-01-09T04:59:40Z | [
"python",
"ruby",
"unit-testing",
"scripting",
"groovy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.