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 |
|---|---|---|---|---|---|---|---|---|---|
Importing sound files into Python as NumPy arrays (alternatives to audiolab) | 2,356,779 | <p>I've been using <a href="http://cournape.github.com/audiolab/">Audiolab</a> to import sound files in the past, and it worked quite well. However:</p>
<ul>
<li>It doesn't support some formats, like mp3, because the underlying libsndfile <a href="http://www.mega-nerd.com/libsndfile/FAQ.html#Q020">refuses to support ... | 6 | 2010-03-01T15:20:55Z | 2,359,690 | <p>Audiolab is working for me on Ubuntu 9.04 with Python 2.6.2, so it might be a Windows problem. In your link to the forum, the author also suggests that it is a Windows error.</p>
<p>In the past, this option has worked for me, too:</p>
<pre><code>from scipy.io import wavfile
fs, data = wavfile.read(filename)
</code... | 7 | 2010-03-01T22:46:13Z | [
"python",
"audio",
"numpy",
"scipy"
] |
Importing sound files into Python as NumPy arrays (alternatives to audiolab) | 2,356,779 | <p>I've been using <a href="http://cournape.github.com/audiolab/">Audiolab</a> to import sound files in the past, and it worked quite well. However:</p>
<ul>
<li>It doesn't support some formats, like mp3, because the underlying libsndfile <a href="http://www.mega-nerd.com/libsndfile/FAQ.html#Q020">refuses to support ... | 6 | 2010-03-01T15:20:55Z | 9,798,685 | <p>Sox <a href="http://sox.sourceforge.net/">http://sox.sourceforge.net/</a> can be your friend for this. It can read many many different formats and output them as raw in whatever datatype you prefer. In fact, I just wrote the code to read a block of data from an audio file into a numpy array.</p>
<p>I decided to g... | 5 | 2012-03-21T04:40:56Z | [
"python",
"audio",
"numpy",
"scipy"
] |
Importing sound files into Python as NumPy arrays (alternatives to audiolab) | 2,356,779 | <p>I've been using <a href="http://cournape.github.com/audiolab/">Audiolab</a> to import sound files in the past, and it worked quite well. However:</p>
<ul>
<li>It doesn't support some formats, like mp3, because the underlying libsndfile <a href="http://www.mega-nerd.com/libsndfile/FAQ.html#Q020">refuses to support ... | 6 | 2010-03-01T15:20:55Z | 37,573,133 | <p>FFmpeg supports mp3s and works on Windows (<a href="http://zulko.github.io/blog/2013/10/04/read-and-write-audio-files-in-python-using-ffmpeg/" rel="nofollow">http://zulko.github.io/blog/2013/10/04/read-and-write-audio-files-in-python-using-ffmpeg/</a>).</p>
<p>Reading an mp3 file: </p>
<pre><code>import subprocess... | 1 | 2016-06-01T15:38:24Z | [
"python",
"audio",
"numpy",
"scipy"
] |
How to check whether string might be type-cast to float in Python? | 2,356,925 | <p>Is there some function like <code>str.isnumeric</code> but applicable to float? </p>
<pre><code>'13.37'.isnumeric() #False
</code></pre>
<p>I still use this: </p>
<pre><code>def isFloat(string):
try:
float(string)
return True
except ValueError:
return False
</code></pre>
| 17 | 2010-03-01T15:39:26Z | 2,356,970 | <p>Your code is absolutely fine. Regex based solutions are more likely to be error prone.</p>
<p>Quick testing with <code>timeit</code> reveals <code>float(str_val)</code> is indeed faster than <code>re.match()</code></p>
<pre><code>>>> timeit.timeit('float("-1.1")')
1.2833082290601467
>>> timeit.ti... | 2 | 2010-03-01T15:44:06Z | [
"python",
"floating-point"
] |
How to check whether string might be type-cast to float in Python? | 2,356,925 | <p>Is there some function like <code>str.isnumeric</code> but applicable to float? </p>
<pre><code>'13.37'.isnumeric() #False
</code></pre>
<p>I still use this: </p>
<pre><code>def isFloat(string):
try:
float(string)
return True
except ValueError:
return False
</code></pre>
| 17 | 2010-03-01T15:39:26Z | 2,356,990 | <p><code>isinstance(myVariable, float)</code> will work if you're testing a floating point variable.</p>
<p>Edit: Spoke too soon, didn't fully understand what you were trying to get.</p>
| -1 | 2010-03-01T15:47:01Z | [
"python",
"floating-point"
] |
How to check whether string might be type-cast to float in Python? | 2,356,925 | <p>Is there some function like <code>str.isnumeric</code> but applicable to float? </p>
<pre><code>'13.37'.isnumeric() #False
</code></pre>
<p>I still use this: </p>
<pre><code>def isFloat(string):
try:
float(string)
return True
except ValueError:
return False
</code></pre>
| 17 | 2010-03-01T15:39:26Z | 2,357,034 | <p>As Imran says, your code is absolutely fine as shown.</p>
<p>However, it does encourage clients of <code>isFloat</code> down the "Look Before You Leap" path instead of the more Pythonic "Easier to Ask Forgiveness than Permission" path.</p>
<p>It's more Pythonic for clients to assume they have a string representing... | 12 | 2010-03-01T15:54:48Z | [
"python",
"floating-point"
] |
How to check whether string might be type-cast to float in Python? | 2,356,925 | <p>Is there some function like <code>str.isnumeric</code> but applicable to float? </p>
<pre><code>'13.37'.isnumeric() #False
</code></pre>
<p>I still use this: </p>
<pre><code>def isFloat(string):
try:
float(string)
return True
except ValueError:
return False
</code></pre>
| 17 | 2010-03-01T15:39:26Z | 7,027,605 | <p>There's a catch though:
float('nan') returns nan, no exception raised ;)</p>
| 1 | 2011-08-11T14:24:52Z | [
"python",
"floating-point"
] |
How to check whether string might be type-cast to float in Python? | 2,356,925 | <p>Is there some function like <code>str.isnumeric</code> but applicable to float? </p>
<pre><code>'13.37'.isnumeric() #False
</code></pre>
<p>I still use this: </p>
<pre><code>def isFloat(string):
try:
float(string)
return True
except ValueError:
return False
</code></pre>
| 17 | 2010-03-01T15:39:26Z | 11,673,484 | <p>A little generalization:</p>
<pre><code>def strType(var):
try:
if int(var) == float(var):
return 'int'
except:
try:
float(var)
return 'float'
except:
return 'str'
</code></pre>
| 3 | 2012-07-26T16:08:02Z | [
"python",
"floating-point"
] |
How can I access a function from FORTRAN which is writen in Python? | 2,357,227 | <p>Is there any way to use a python function in FORTRAN? I was given a python script that contains some functions and I need to access this function from a FORTRAN code. </p>
<p>I've seen 'f2py' which allows a FORTRAN subroutine to be accessed from Python, and py2exe which will compile python script to an executable. ... | 3 | 2010-03-01T16:20:46Z | 2,357,308 | <p>Don't waste a lot of time compiling and translating. Do this.</p>
<ol>
<li><p>Fortran Part 1 program writes a file of stuff for Python to do. Write to stdout. Call this F1</p></li>
<li><p>Python reads a file, does the Python calculation, write the responses to a file for Fortran. Call this P.</p></li>
<li><p>Fo... | 4 | 2010-03-01T16:31:53Z | [
"python",
"object",
"compilation",
"fortran"
] |
How can I access a function from FORTRAN which is writen in Python? | 2,357,227 | <p>Is there any way to use a python function in FORTRAN? I was given a python script that contains some functions and I need to access this function from a FORTRAN code. </p>
<p>I've seen 'f2py' which allows a FORTRAN subroutine to be accessed from Python, and py2exe which will compile python script to an executable. ... | 3 | 2010-03-01T16:20:46Z | 6,120,306 | <p>@S.Lott's solution is the way to go. But to answer your question --- yes, it is possible to call Python from Fortran. I have done it by first exposing Python using Cython's C API, then creating Fortran interface to those C function using the <code>iso_c_binding</code> module, and finally calling them from Fortran. I... | 4 | 2011-05-25T06:17:16Z | [
"python",
"object",
"compilation",
"fortran"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,357,247 | <p>Read about using <a href="http://www.python.org/dev/peps/pep-0257/" rel="nofollow">docstrings</a> in your python code.</p>
<p>As per the Python Docstring Conventions:</p>
<blockquote>
<p>The docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects... | 4 | 2010-03-01T16:23:01Z | [
"python"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,357,251 | <p>The correct way to do it is to provide a docstring. That way, <code>help(add)</code> will also spit out your comment.</p>
<pre><code>def add(self):
"""Create a new user.
Line 2 of comment...
And so on...
"""
</code></pre>
<p>That's three double quotes to open the comment and another three double q... | 132 | 2010-03-01T16:23:09Z | [
"python"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,357,253 | <p>I would go for a documentation practice that integrates with a Documentation tool such as <strong><a href="http://sphinx.pocoo.org/" rel="nofollow">Sphinx</a></strong>. </p>
<p>The first step is to use a <code>docstring</code>:</p>
<pre><code>def add(self):
""" Method which adds stuff
"""
</code></pre>
| 3 | 2010-03-01T16:23:23Z | [
"python"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,357,256 | <p>Use a <a href="http://www.python.org/dev/peps/pep-0257/" rel="nofollow">docstring</a>:</p>
<blockquote>
<p>a string literal that occurs as the first statement in a module, function, class, or method definition. Such a docstring becomes the <code>__doc__</code> special attribute of that object.</p>
<p>All mod... | 16 | 2010-03-01T16:23:45Z | [
"python"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,357,274 | <p>Use a docstring, as others have already written. </p>
<p>You can even go one step further and add a <a href="http://docs.python.org/library/doctest.html?highlight=doctest#module-doctest">doctest</a> to your docstring, making automated testing of your functions a snap.</p>
| 18 | 2010-03-01T16:27:08Z | [
"python"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,357,285 | <p>Oh boy! Consider a can of worms opened :)</p>
<p>The principles of good commenting are fairly subjective, but here are some guidlines:</p>
<ul>
<li>Function comments should describe the <strong>intent</strong> of a function, not the implementation</li>
<li>Outline any assumptions that your function makes with rega... | 5 | 2010-03-01T16:29:00Z | [
"python"
] |
What is the proper way to comment functions in python? | 2,357,230 | <p>Is there a generally accepted way to do this? Is this acceptable:</p>
<pre><code>#########################################################
# Create a new user
#########################################################
def add(self):
</code></pre>
| 69 | 2010-03-01T16:21:13Z | 2,363,254 | <p>I would go a step further than just saying "use a docstring". Pick a documentation generation tool, such as pydoc or epydoc (I use epydoc in pyparsing), and use the markup syntax recognized by that tool. Run that tool often while you are doing your development, to identify holes in your documentation. In fact, you... | 1 | 2010-03-02T13:10:14Z | [
"python"
] |
Creating a global function, accessible from all classes, with Python + Pylons | 2,357,419 | <p>Using pylons 0.9.7, I'm trying to make a function that connects to a database on demand. I'd like it to be accessible from all functions within all model classes.</p>
<p>In <code>model/__init__.py</code>, I have:</p>
<pre><code>#Establish an on-demand connection to the central database
def connectCentral():
... | 0 | 2010-03-01T16:49:06Z | 2,357,436 | <p>Have you done <code>import init</code> ? Or rather <code>from init import connectCentral</code>?</p>
<p>If you did, that such name should be defined. If not, you can try writing <code>global connectCentral</code> in method's body, but I believe it is only for using global variables.</p>
<p>Are you sure, this modul... | 1 | 2010-03-01T16:52:20Z | [
"python",
"pylons"
] |
Creating a global function, accessible from all classes, with Python + Pylons | 2,357,419 | <p>Using pylons 0.9.7, I'm trying to make a function that connects to a database on demand. I'd like it to be accessible from all functions within all model classes.</p>
<p>In <code>model/__init__.py</code>, I have:</p>
<pre><code>#Establish an on-demand connection to the central database
def connectCentral():
... | 0 | 2010-03-01T16:49:06Z | 2,357,540 | <pre><code>from model import connectCentral
</code></pre>
| 2 | 2010-03-01T17:03:41Z | [
"python",
"pylons"
] |
How can I create an ODBC connection to SAS? | 2,357,547 | <p>I'm writing a program that needs to access SAS data. I've downloaded the ODBC drivers for SAS and installed them, but I need to be able to create ODBC connections on the fly, programmatically. The following code (in Python) seems like it should work:</p>
<pre><code>import ctypes
ODBC_ADD_DSN = 1
def add... | 4 | 2010-03-01T17:04:29Z | 2,425,567 | <p>In order to get ODBC access to SAS data, you need to connect to a running SAS session of some kind; you can't access SAS data table files directly with the SAS ODBC drivers.</p>
<p>See the <a href="http://support.sas.com/documentation/cdl/en/odbcdref/61927/PDF/default/odbcdref.pdf" rel="nofollow">SAS ODBC drivers g... | 2 | 2010-03-11T14:12:51Z | [
"python",
"sas",
"odbc"
] |
How can I create an ODBC connection to SAS? | 2,357,547 | <p>I'm writing a program that needs to access SAS data. I've downloaded the ODBC drivers for SAS and installed them, but I need to be able to create ODBC connections on the fly, programmatically. The following code (in Python) seems like it should work:</p>
<pre><code>import ctypes
ODBC_ADD_DSN = 1
def add... | 4 | 2010-03-01T17:04:29Z | 2,425,695 | <p>I know zilch about SAS, but the function used to connect to a database on the fly in ODBC is <a href="http://msdn.microsoft.com/en-us/library/ms715433%28VS.85%29.aspx" rel="nofollow">SQLDriverConnect</a>. You don't need (or want) to add a DSN, you just need the drivers installed.</p>
| 0 | 2010-03-11T14:29:36Z | [
"python",
"sas",
"odbc"
] |
How can I create an ODBC connection to SAS? | 2,357,547 | <p>I'm writing a program that needs to access SAS data. I've downloaded the ODBC drivers for SAS and installed them, but I need to be able to create ODBC connections on the fly, programmatically. The following code (in Python) seems like it should work:</p>
<pre><code>import ctypes
ODBC_ADD_DSN = 1
def add... | 4 | 2010-03-01T17:04:29Z | 32,676,331 | <p>I know this question is ancient but it probably comes up often enough that I will share the answer I know. The easiest way to achieve what you are trying to do is create what's called a "DSN-Less Connection." </p>
<p>Briefly, you create a connect string that you use when opening a connection, that identifies the dr... | 0 | 2015-09-20T06:04:33Z | [
"python",
"sas",
"odbc"
] |
Serial communication. Sending DTR in the right way? | 2,357,610 | <p>I'm dealing with a <a href="http://www.icpdas.com/products/GSM_GPRS/wireless/gm29.htm" rel="nofollow">gm29</a> by Sony Ericsson.</p>
<p>The <a href="http://www.icpdas.com/download/wireless/gsm/gm29/gm29_tech%20description_r1b.pdf" rel="nofollow">datasheet</a> says that plugging the power is not sufficient to switch... | 0 | 2010-03-01T17:11:42Z | 2,358,879 | <p>There are several things that occur to me here.</p>
<p>1) the spec says that DTR is active low, so you may need to swap the <code>true</code> and <code>false</code> values to <code>setDTR()</code>, depending on who is confused here.</p>
<p>2) You are setting <code>DTR</code> to false after you wake the modem. This... | 4 | 2010-03-01T20:31:32Z | [
"python",
"serial-port",
"modem"
] |
numpy: extending arrays along a new axis? | 2,357,686 | <p>Surely there must be a way to do this... I can't work it out.</p>
<p>I have a (9,4) array, and I want to repeat it along a 3rd axis 4096 times... So it becomes simply (9,4,4096), with each value from the 9,4 array simply repeated 4096 times down the new axis.</p>
<p>If my dubious 3D diagram makes sense (the diagon... | 18 | 2010-03-01T17:24:15Z | 2,357,785 | <p>Here is one way:</p>
<pre><code>import scipy
X = scipy.rand(9,4,1)
Y = X.repeat(4096,2)
</code></pre>
<p>If <code>X</code> is given to you as only (9,4), then</p>
<pre><code>import scipy
X = scipy.rand(9,4)
Y = X.reshape(9,4,1).repeat(4096,2)
</code></pre>
| 16 | 2010-03-01T17:42:29Z | [
"python",
"arrays",
"numpy"
] |
numpy: extending arrays along a new axis? | 2,357,686 | <p>Surely there must be a way to do this... I can't work it out.</p>
<p>I have a (9,4) array, and I want to repeat it along a 3rd axis 4096 times... So it becomes simply (9,4,4096), with each value from the 9,4 array simply repeated 4096 times down the new axis.</p>
<p>If my dubious 3D diagram makes sense (the diagon... | 18 | 2010-03-01T17:24:15Z | 2,360,784 | <p>You can also rely on the broadcasting rules to repeat-fill a re-sized array:</p>
<pre><code>import numpy
X = numpy.random.rand(9,4)
Y = numpy.resize(X,(4096,9,4))
</code></pre>
<p>If you don't like the axes ordered this way, you can then transpose:</p>
<pre><code>Z = Y.transpose(1,2,0)
</code></pre>
| 8 | 2010-03-02T03:48:07Z | [
"python",
"arrays",
"numpy"
] |
numpy: extending arrays along a new axis? | 2,357,686 | <p>Surely there must be a way to do this... I can't work it out.</p>
<p>I have a (9,4) array, and I want to repeat it along a 3rd axis 4096 times... So it becomes simply (9,4,4096), with each value from the 9,4 array simply repeated 4096 times down the new axis.</p>
<p>If my dubious 3D diagram makes sense (the diagon... | 18 | 2010-03-01T17:24:15Z | 24,314,722 | <p>Question is super old, but here's another option anyway:</p>
<pre><code>import numpy as np
X = np.random.rand(9,4)
Y = np.dstack([X] * 4096)
</code></pre>
| 3 | 2014-06-19T19:23:58Z | [
"python",
"arrays",
"numpy"
] |
Making user-made HTML templates safe | 2,357,750 | <p>I want to allow users to create tiny templates that I then render in Django with a predefined context. I am assuming the Django rendering is safe (I asked a question about this <a href="http://stackoverflow.com/questions/2319306/is-it-safe-to-render-user-created-django-templates">before</a>), but there is still the ... | 3 | 2010-03-01T17:35:55Z | 2,357,782 | <p>There's PHP-Based <a href="http://htmlpurifier.org/" rel="nofollow"><strong>HTML purifier</strong></a>, I have not used it myself yet but heard very good things about it. They promise a lot:</p>
<blockquote>
<p>HTML Purifier is a standards-compliant
HTML filter library written in
PHP. HTML Purifier will... | 1 | 2010-03-01T17:42:22Z | [
"python",
"html",
"security",
"xss",
"markup"
] |
Making user-made HTML templates safe | 2,357,750 | <p>I want to allow users to create tiny templates that I then render in Django with a predefined context. I am assuming the Django rendering is safe (I asked a question about this <a href="http://stackoverflow.com/questions/2319306/is-it-safe-to-render-user-created-django-templates">before</a>), but there is still the ... | 3 | 2010-03-01T17:35:55Z | 2,357,799 | <p>Seeing Pekka's answer, I tried to quickly Google an HTML Purifier equivalent in Python. Here's what I came up with: <a href="https://launchpad.net/python-html-sanitizer" rel="nofollow">Python HTML Sanitizer</a>. At first glance, it looks pretty good to me.</p>
| 3 | 2010-03-01T17:44:17Z | [
"python",
"html",
"security",
"xss",
"markup"
] |
Making user-made HTML templates safe | 2,357,750 | <p>I want to allow users to create tiny templates that I then render in Django with a predefined context. I am assuming the Django rendering is safe (I asked a question about this <a href="http://stackoverflow.com/questions/2319306/is-it-safe-to-render-user-created-django-templates">before</a>), but there is still the ... | 3 | 2010-03-01T17:35:55Z | 2,358,076 | <p>"Use a markup language that produces safe HTML."</p>
<p>Clearly, the only sensible approach.</p>
<p>"The problem with this is that most markup languages are not very powerful layout-wise."</p>
<p>False.</p>
<p>"no way to center elements in ReST."</p>
<p>False.</p>
<p>Centering is a style -- a CSS feature -- no... | 1 | 2010-03-01T18:30:01Z | [
"python",
"html",
"security",
"xss",
"markup"
] |
Making user-made HTML templates safe | 2,357,750 | <p>I want to allow users to create tiny templates that I then render in Django with a predefined context. I am assuming the Django rendering is safe (I asked a question about this <a href="http://stackoverflow.com/questions/2319306/is-it-safe-to-render-user-created-django-templates">before</a>), but there is still the ... | 3 | 2010-03-01T17:35:55Z | 2,358,962 | <p>You are overlooking server side security issues. You need to be very careful that users can't use the templates import or include mechanism to access files they don't have permission to.</p>
<p>The bigger challenge is to prevent the template system from infinite loops and recursion. This is an obvious threat to s... | 0 | 2010-03-01T20:45:41Z | [
"python",
"html",
"security",
"xss",
"markup"
] |
How to make a count in python so that the program ends after a particular number of counts? | 2,357,788 | <p>I'm a newbie and i need to know how to modify a password guessing program to keep track of how many times the user has entered the password wrong. If it has been entered more than 3 times then it should print " This seems to be complicated" and the program should be ended.
The password guessing program is</p>
<pre>... | 2 | 2010-03-01T17:42:59Z | 2,357,808 | <p>Initialise a count variable to zero and increment it within your loop. You can then use the count within your while loop condition and then after the loop to determine how many tries it took and to print a message.</p>
| 0 | 2010-03-01T17:45:28Z | [
"python"
] |
How to make a count in python so that the program ends after a particular number of counts? | 2,357,788 | <p>I'm a newbie and i need to know how to modify a password guessing program to keep track of how many times the user has entered the password wrong. If it has been entered more than 3 times then it should print " This seems to be complicated" and the program should be ended.
The password guessing program is</p>
<pre>... | 2 | 2010-03-01T17:42:59Z | 2,358,023 | <pre><code>import sys
counter = 0;
while counter < 3:
counter += 1
password = raw_input("Password:")
if password == "password":
print "Welcome in"
break
else:
print "This seems to be complicated"
sys.exit(0)
</code></pre>
| 1 | 2010-03-01T18:20:41Z | [
"python"
] |
How to make a count in python so that the program ends after a particular number of counts? | 2,357,788 | <p>I'm a newbie and i need to know how to modify a password guessing program to keep track of how many times the user has entered the password wrong. If it has been entered more than 3 times then it should print " This seems to be complicated" and the program should be ended.
The password guessing program is</p>
<pre>... | 2 | 2010-03-01T17:42:59Z | 2,358,032 | <pre><code>for trial in range(3):
if raw_input('Password:') == 'password':
break
else:
# didn't find password after 3 attempts
sys.exit(10)
print 'Welcome in'
</code></pre>
| 4 | 2010-03-01T18:21:28Z | [
"python"
] |
How to make a count in python so that the program ends after a particular number of counts? | 2,357,788 | <p>I'm a newbie and i need to know how to modify a password guessing program to keep track of how many times the user has entered the password wrong. If it has been entered more than 3 times then it should print " This seems to be complicated" and the program should be ended.
The password guessing program is</p>
<pre>... | 2 | 2010-03-01T17:42:59Z | 16,373,672 | <p>A little simpler than some of the previous possibilities, I would probably prefer this method because I hate using the sys module as Tendayi Mawushe suggested, as the previous posters suggested. Also to note, your previous program would print welcome in whether the correct password was achieved or not. I fixed this ... | 0 | 2013-05-04T11:16:24Z | [
"python"
] |
How to make a count in python so that the program ends after a particular number of counts? | 2,357,788 | <p>I'm a newbie and i need to know how to modify a password guessing program to keep track of how many times the user has entered the password wrong. If it has been entered more than 3 times then it should print " This seems to be complicated" and the program should be ended.
The password guessing program is</p>
<pre>... | 2 | 2010-03-01T17:42:59Z | 20,254,212 | <pre><code>print("To start program please login")
Validusername = "Trollman"
ValidPassword ="1337"
UserInput=input("Enter Username")
PassInput=input("Enter Password")
trials = 0
while (PassInput != ValidPassword or UserInput != Validusername):
if trials==3:
break;
else:
UserInp... | 0 | 2013-11-27T22:23:20Z | [
"python"
] |
How to get parameters of fail case in Python unittest? | 2,357,921 | <p>I'm running an <code>assertEqual</code> test case for a list of methods in a particular class. These methods are expanded from string form to something callable using <code>getattr()</code>.</p>
<p>How can I get unittest to tell me the particular method which failed? Meaning: how can I get unittest to print to stdo... | 4 | 2010-03-01T18:03:26Z | 2,357,961 | <p>You can pass assertEqual a third argument (technically fourth if you count self), which is the error message it will return. So the following should do more or less what you're looking for:</p>
<pre><code>class MethodTest(TestCase):
def test_method(self):
obj = MyClass()
for method in "frob", "... | 5 | 2010-03-01T18:11:00Z | [
"python",
"unit-testing"
] |
Linux/Python: Monitor /proc/acpi files without polling? | 2,357,930 | <p>Is there any way to monitor <code>/proc</code> files, such as</p>
<pre><code>/proc/acpi/battery/BAT0/state
/proc/acpi/ac_adapter/ADP0/state
</code></pre>
<p>in a non-polling fashion, similar to inotify on a normal filesystem?</p>
<p>I want to do this in a PyGTK app, so I tried using PyGObject's gio.FileMonitor, b... | 2 | 2010-03-01T18:06:25Z | 2,357,970 | <p>Probably you can get the information you want by listening to the ACPI events. Preferably not directly (/proc/acpi/event), but via acpid or other high-level interface.</p>
<p>Update: the other, higher level interface is the DBus interface provided by DeviceKit-power / UPower.</p>
<p>Files in /proc are not regular ... | 2 | 2010-03-01T18:12:20Z | [
"python",
"linux",
"pygtk",
"inotify",
"pygobject"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 2,358,063 | <p>There aren't trees built in, but you can easily construct one by subclassing a Node type from List and writing the traversal methods. If you do this, I've found <a href="http://docs.python.org/library/bisect.html">bisect</a> useful. </p>
<p>There are also many implementations on <a href="http://pypi.python.org/pypi... | 11 | 2010-03-01T18:28:31Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 2,358,075 | <p>Python doesn't have the quite the extensive range of "built-in" data structures as Java does. However, because Python is dynamic, a general tree is easy to create. For example, a binary tree might be:</p>
<pre><code>class Tree(object):
def __init__(self):
self.left = None
self.right = None
... | 62 | 2010-03-01T18:29:51Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 2,358,607 | <p>What operations do you need? There is often a good solution in Python using a dict or a list with the bisect module.</p>
<p>There are many, many tree implementations on <a href="http://pypi.python.org/" rel="nofollow">PyPI</a>, and many tree types are nearly trivial to implement yourself in pure Python. However, th... | 0 | 2010-03-01T19:52:33Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 2,359,118 | <p>I've implemented trees using nested dicts. It is quite easy to do, and it has worked for me with pretty large data sets. I've posted a sample below, and you can see more at <a href="http://code.google.com/p/stv/source/browse/trunk/openstv/STV.py">Google code</a></p>
<pre><code> def addBallotToTree(self, tree, ba... | 5 | 2010-03-01T21:13:43Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 7,334,957 | <p>I've published a Python [3] tree implementation on my site: <a href="http://www.quesucede.com/page/show/id/python_3_tree_implementation" rel="nofollow">http://www.quesucede.com/page/show/id/python_3_tree_implementation</a>.</p>
<p>Hope it is of use,</p>
<p>Ok, here's the code:</p>
<pre><code>import uuid
def sani... | 3 | 2011-09-07T13:47:48Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 10,322,593 | <p>You can try:</p>
<pre><code>from collections import defaultdict
def hash(): return defaultdict(hash)
users = hash()
users['harold']['username'] = 'hrldcpr'
users['handler']['username'] = 'matthandlersux'
</code></pre>
<p>As suggested here: <a href="https://gist.github.com/2012250" rel="nofollow">https://gist.githu... | 10 | 2012-04-25T19:39:46Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 19,040,443 | <p>I implemented a rooted tree as a dictionary <code>{child:parent}</code>. So for instance with the root node <code>0</code>, a tree might look like that:</p>
<pre><code>tree={1:0, 2:0, 3:1, 4:2, 5:3}
</code></pre>
<p>This structure made it quite easy to go upward along a path from any node to the root, which was r... | 7 | 2013-09-26T23:38:46Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 23,451,186 | <p>Greg Hewgill's answer is great but if you need more nodes per level you can use a list to create them: And then use method to access them either by name or order (like id)</p>
<pre><code>class node(object):
def __init__(self):
self.name=None
self.node=[]
self.otherInfo = None
sel... | 3 | 2014-05-04T00:13:56Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 28,015,122 | <p>A generic tree is a node with zero or more children, each one a proper (tree) node. It isn't the same as a binary tree, they're different data structures, although both shares some terminology.</p>
<p>There isn't any builtin data structure for generic trees in Python, but it's easily implemented with classes.</p>
... | 10 | 2015-01-18T21:40:49Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 29,531,977 | <pre><code>class Node:
"""
Class Node
"""
def __init__(self, value):
self.left = None
self.data = value
self.right = None
class Tree:
"""
Class tree will provide a tree as well as utility functions.
"""
def createNode(self, data):
"""
Utility fun... | 8 | 2015-04-09T07:07:59Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 36,965,344 | <pre><code>def iterative_bfs(graph, start):
'''iterative breadth first search from start'''
bfs_tree = {start: {"parents":[], "children":[], "level":0}}
q = [start]
while q:
current = q.pop(0)
for v in graph[current]:
if not v in bfs_tree:
bfs_tree[v]={"parent... | -3 | 2016-05-01T09:58:29Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
How can I implement a tree in Python? Are there any built in data structures in Python like in Java? | 2,358,045 | <p>I am trying to construct a general tree. Are there any built in data structures in Python to implement a tree?</p>
| 58 | 2010-03-01T18:24:27Z | 39,292,920 | <p>I recommend <a href="https://pypi.python.org/pypi/anytree" rel="nofollow">https://pypi.python.org/pypi/anytree</a></p>
<pre><code>from anytree import Node, RenderTree
udo = Node("Udo")
marc = Node("Marc", parent=udo)
lian = Node("Lian", parent=marc)
dan = Node("Dan", parent=udo)
jet = Node("Jet", parent=dan)
jan =... | 4 | 2016-09-02T12:52:14Z | [
"python",
"data-structures",
"tree",
"python-3.x"
] |
Making Django development server faster at serving static media | 2,358,450 | <p>I'm using the Django <code>manage.py runserver</code> for developing my application (obviously), but it takes <strong>10 seconds</strong> to completely load a page because the development server is very, very slow at serving static media.</p>
<p>Is there any way to speed it up or some kind of workaround? I'm using ... | 9 | 2010-03-01T19:26:44Z | 2,358,484 | <p>Consider using <a href="http://code.google.com/p/modwsgi/"><code>mod_wsgi</code></a> instead, and having httpd handle the static media.</p>
| 7 | 2010-03-01T19:31:30Z | [
"python",
"django"
] |
Making Django development server faster at serving static media | 2,358,450 | <p>I'm using the Django <code>manage.py runserver</code> for developing my application (obviously), but it takes <strong>10 seconds</strong> to completely load a page because the development server is very, very slow at serving static media.</p>
<p>Is there any way to speed it up or some kind of workaround? I'm using ... | 9 | 2010-03-01T19:26:44Z | 2,358,588 | <p>Development server is simple unsafe single-threaded application, so you cannot do much. </p>
<p>One trick you could try is to redirect /site_media to second development server, but this is ugly and probably wouldn't help that much. So you could try bundling/compressing multiple assets into one css/js (e.g. using <a... | 5 | 2010-03-01T19:49:38Z | [
"python",
"django"
] |
Making Django development server faster at serving static media | 2,358,450 | <p>I'm using the Django <code>manage.py runserver</code> for developing my application (obviously), but it takes <strong>10 seconds</strong> to completely load a page because the development server is very, very slow at serving static media.</p>
<p>Is there any way to speed it up or some kind of workaround? I'm using ... | 9 | 2010-03-01T19:26:44Z | 2,359,938 | <p>Install Firefox (if you haven't already), and install the <a href="http://getfirebug.com/" rel="nofollow" title="Firebug">Firebug Add-On</a>. Restart your browser. In the lower-right corner click the "bug" icon and make sure that in the "Network" tab (it's a dropdown) of the Firebug panel that opens at the bottom of... | 3 | 2010-03-01T23:39:41Z | [
"python",
"django"
] |
Making Django development server faster at serving static media | 2,358,450 | <p>I'm using the Django <code>manage.py runserver</code> for developing my application (obviously), but it takes <strong>10 seconds</strong> to completely load a page because the development server is very, very slow at serving static media.</p>
<p>Is there any way to speed it up or some kind of workaround? I'm using ... | 9 | 2010-03-01T19:26:44Z | 3,426,911 | <p>Run lighttpd to serve the static content and use the MEDIA_URL to point the pages at the lighttpd server that servers the static stuff.</p>
| 2 | 2010-08-06T19:06:44Z | [
"python",
"django"
] |
Making Django development server faster at serving static media | 2,358,450 | <p>I'm using the Django <code>manage.py runserver</code> for developing my application (obviously), but it takes <strong>10 seconds</strong> to completely load a page because the development server is very, very slow at serving static media.</p>
<p>Is there any way to speed it up or some kind of workaround? I'm using ... | 9 | 2010-03-01T19:26:44Z | 33,533,215 | <p>Lightning fast ans easy on resources when using NGINX for serving static and media files. Here's how it goes. However, you'll need to adapt some paths according to your use case and system. But I think this will get you started:</p>
<p>1) Download NGINX for your system, in your case Windows:
<a href="http://nginx.o... | 0 | 2015-11-04T22:22:31Z | [
"python",
"django"
] |
Database-Independent MAX() Function in SQLAlchemy | 2,358,634 | <p>I'd like to calculate a MAX() value for a column. What's the proper way to do this in sqlalchemy while preserving database independence? </p>
| 3 | 2010-03-01T19:57:57Z | 2,362,468 | <p>You can find aggregate functions in: </p>
<pre><code>from sqlalchemy import func
func.avg(...)
func.sum(...)
func.max(...)
</code></pre>
<p>In 0.5 you can use an ORM query like a select:</p>
<pre><code>session.query(func.max(Table.column))
</code></pre>
| 5 | 2010-03-02T10:37:31Z | [
"python",
"mysql",
"sqlalchemy",
"pylons"
] |
Can't import numpy into embedded ironpython engine | 2,358,731 | <p>From an ipy console I can</p>
<pre><code>import ironclad
import numpy
</code></pre>
<p>with no problem.</p>
<p>However when I try the same imports with an embedded interpreter the numpy import fails. My Python engines is set up like this:</p>
<pre><code> public PyEngine()
{
//Frames option needed... | 3 | 2010-03-01T20:12:06Z | 2,369,345 | <p>There are a couple of things that you can try: </p>
<ol>
<li><p>Make sure the you have setup the IRONPYTHONPATH system variable
properly to find the <em>numpy</em> module. Most of the time that's installed
within your CPython directory structure, so you need to add the
paths listed below. </p></li>
<li><p>As an al... | 4 | 2010-03-03T07:05:06Z | [
"python",
"ironpython",
"numpy",
"ironclad"
] |
Can't import numpy into embedded ironpython engine | 2,358,731 | <p>From an ipy console I can</p>
<pre><code>import ironclad
import numpy
</code></pre>
<p>with no problem.</p>
<p>However when I try the same imports with an embedded interpreter the numpy import fails. My Python engines is set up like this:</p>
<pre><code> public PyEngine()
{
//Frames option needed... | 3 | 2010-03-01T20:12:06Z | 5,519,491 | <p>I tried all of the above, but only worked when I moved the project to a "valid" path. That is one without space characters. I wonder if it is because of the UNICODE poor support of ironclad.</p>
| 0 | 2011-04-01T22:22:42Z | [
"python",
"ironpython",
"numpy",
"ironclad"
] |
If I'm only planning to use MySQL, and if speed is a priority, is there any convincing reason to use SQLAlchemy? | 2,358,822 | <p>SQLAlchemy seems really heavyweight if all I use is MySQL.</p>
<p>Why are convincing reasons for/against the use of SQLAlchemy in an application that only uses MySQL.</p>
| 3 | 2010-03-01T20:24:25Z | 2,358,852 | <p>ORM means that your OO application actually makes sense when interpreted as the interaction of objects.</p>
<p>No ORM means that you must wallow in the impedance mismatch between SQL and Objects. Working without an ORM means lots of redundant code to map between SQL query result sets, individual SQL statements and... | 7 | 2010-03-01T20:28:31Z | [
"python",
"mysql",
"sqlalchemy",
"pylons"
] |
If I'm only planning to use MySQL, and if speed is a priority, is there any convincing reason to use SQLAlchemy? | 2,358,822 | <p>SQLAlchemy seems really heavyweight if all I use is MySQL.</p>
<p>Why are convincing reasons for/against the use of SQLAlchemy in an application that only uses MySQL.</p>
| 3 | 2010-03-01T20:24:25Z | 2,359,697 | <p>I don't think performance should be much of a factor in your choice. The layer that an ORM adds will be insignificant compared to the speed of the database. Databases always end up being a bottleneck.</p>
<p>Using an ORM may allow you to develop faster with less bugs. You can still access the DB directly if you hav... | 4 | 2010-03-01T22:48:50Z | [
"python",
"mysql",
"sqlalchemy",
"pylons"
] |
If I'm only planning to use MySQL, and if speed is a priority, is there any convincing reason to use SQLAlchemy? | 2,358,822 | <p>SQLAlchemy seems really heavyweight if all I use is MySQL.</p>
<p>Why are convincing reasons for/against the use of SQLAlchemy in an application that only uses MySQL.</p>
| 3 | 2010-03-01T20:24:25Z | 2,359,777 | <p>sqlalchemy provides more than just an orm, you can select/insert/update/delete from table objects, join them etc.... the benefit of using those things over building strings with sql in them is guarding against sql injection attacks for one. You also get some decent connection management that you don't have to write ... | 0 | 2010-03-01T23:03:17Z | [
"python",
"mysql",
"sqlalchemy",
"pylons"
] |
Python - lexical analysis and tokenization | 2,358,890 | <p>I'm looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I'll describe my problem:</p>
<p>I've got very large properties files (in the order of 1,000 properties), which when distilled, are really just ... | 9 | 2010-03-01T20:32:35Z | 2,358,926 | <p>If you can change the format of the input files, then you could use a parser for an existing format, such as JSON.</p>
<p>However, from your problem statement it sounds like that isn't the case. So if you want to create a custom lexer and parser, use <a href="http://www.dabeaz.com/ply/" rel="nofollow">PLY</a> (Pyt... | 0 | 2010-03-01T20:39:28Z | [
"python",
"transform",
"lexical-analysis"
] |
Python - lexical analysis and tokenization | 2,358,890 | <p>I'm looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I'll describe my problem:</p>
<p>I've got very large properties files (in the order of 1,000 properties), which when distilled, are really just ... | 9 | 2010-03-01T20:32:35Z | 2,358,975 | <p>For as simple as your format seems to be, I think a full-on parser/lexer would be way overkill. Seems like a combination of regexes and string manipulation would do the trick. </p>
<p>Another idea is to change the file to something like json or xml and use an existing package.</p>
| 2 | 2010-03-01T20:50:03Z | [
"python",
"transform",
"lexical-analysis"
] |
Python - lexical analysis and tokenization | 2,358,890 | <p>I'm looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I'll describe my problem:</p>
<p>I've got very large properties files (in the order of 1,000 properties), which when distilled, are really just ... | 9 | 2010-03-01T20:32:35Z | 2,359,164 | <p>A simple DFA works well for this. You only need a few states:</p>
<ol>
<li>Looking for <code>${</code></li>
<li>Seen <code>${</code> looking for at least one valid character forming the name</li>
<li>Seen at least one valid name character, looking for more name characters or <code>}</code>.</li>
</ol>
<p>If the p... | 2 | 2010-03-01T21:22:52Z | [
"python",
"transform",
"lexical-analysis"
] |
Python - lexical analysis and tokenization | 2,358,890 | <p>I'm looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I'll describe my problem:</p>
<p>I've got very large properties files (in the order of 1,000 properties), which when distilled, are really just ... | 9 | 2010-03-01T20:32:35Z | 2,359,556 | <p>The syntax you provide seems similar to <a href="http://makotemplates.org" rel="nofollow" title="Mako templates engine">Mako templates engine</a>. I think you could give it a try, it's rather simple API.</p>
| 1 | 2010-03-01T22:24:40Z | [
"python",
"transform",
"lexical-analysis"
] |
Python - lexical analysis and tokenization | 2,358,890 | <p>I'm looking to speed along my discovery process here quite a bit, as this is my first venture into the world of lexical analysis. Maybe this is even the wrong path. First, I'll describe my problem:</p>
<p>I've got very large properties files (in the order of 1,000 properties), which when distilled, are really just ... | 9 | 2010-03-01T20:32:35Z | 2,359,619 | <p>There's an excellent article on <a href="http://effbot.org/zone/xml-scanner.htm">Using Regular Expressions for Lexical Analysis</a> at <a href="http://effbot.org/">effbot.org</a>.</p>
<p>Adapting the tokenizer to your problem:</p>
<pre><code>import re
token_pattern = r"""
(?P<identifier>[a-zA-Z_][a-zA-Z0-9_... | 9 | 2010-03-01T22:36:45Z | [
"python",
"transform",
"lexical-analysis"
] |
Are there any existing batch log file aggregation solutions? | 2,358,896 | <p>I wish to export from multiple nodes log files (in my case apache access and error logs) and aggregate that data in batch, as a scheduled job. I have seen multiple solutions that work with streaming data (i.e think scribe). I would like a tool that gives me the flexibility to define the destination. This require... | 7 | 2010-03-01T20:33:48Z | 2,391,101 | <p><a href="http://www.picloud.com" rel="nofollow">PiCloud</a> may help.</p>
<blockquote>
<p>The PiCloud Platform gives you the freedom to develop your algorithms
and software without sinking time into all of the plumbing that comes
with provisioning, managing, and maintaining servers.</p>
</blockquote>
| -1 | 2010-03-06T02:12:52Z | [
"python",
"export",
"aggregation",
"logfiles",
"hdfs"
] |
Are there any existing batch log file aggregation solutions? | 2,358,896 | <p>I wish to export from multiple nodes log files (in my case apache access and error logs) and aggregate that data in batch, as a scheduled job. I have seen multiple solutions that work with streaming data (i.e think scribe). I would like a tool that gives me the flexibility to define the destination. This require... | 7 | 2010-03-01T20:33:48Z | 2,556,189 | <p>take a look at Zomhg, its an aggregation/reporting system for log files using Hbase and Hdfs: <a href="http://github.com/zohmg/zohmg" rel="nofollow">http://github.com/zohmg/zohmg</a></p>
| 0 | 2010-03-31T20:21:03Z | [
"python",
"export",
"aggregation",
"logfiles",
"hdfs"
] |
Are there any existing batch log file aggregation solutions? | 2,358,896 | <p>I wish to export from multiple nodes log files (in my case apache access and error logs) and aggregate that data in batch, as a scheduled job. I have seen multiple solutions that work with streaming data (i.e think scribe). I would like a tool that gives me the flexibility to define the destination. This require... | 7 | 2010-03-01T20:33:48Z | 3,104,839 | <p>Scribe can meet your requirements, there's a version (<a href="http://github.com/huyphan/Scribe-with-HDFS-support" rel="nofollow">link</a>) of scribe that can aggregate logs from multiple sources, and after reaching given threshold it stores everything in HDFS. I've used it and it works very well. Compilation is qui... | 0 | 2010-06-23T19:24:02Z | [
"python",
"export",
"aggregation",
"logfiles",
"hdfs"
] |
Are there any existing batch log file aggregation solutions? | 2,358,896 | <p>I wish to export from multiple nodes log files (in my case apache access and error logs) and aggregate that data in batch, as a scheduled job. I have seen multiple solutions that work with streaming data (i.e think scribe). I would like a tool that gives me the flexibility to define the destination. This require... | 7 | 2010-03-01T20:33:48Z | 3,375,074 | <p>we use <a href="http://mergelog.sourceforge.net/" rel="nofollow">http://mergelog.sourceforge.net/</a> to merge all our apache logs..</p>
| 1 | 2010-07-30T20:15:28Z | [
"python",
"export",
"aggregation",
"logfiles",
"hdfs"
] |
Prevent Windows 7 Shutdown | 2,358,929 | <p>I know that <code>shutdown -a</code> will abort a Windows shutdown, but I need to know if there is anything any where I can check for to see if a shutdown is in progress.</p>
<p>Ideally, I'd like a small program like this:</p>
<pre><code> import os
while True:
shuttingDown = <shutdown variable to check>... | 4 | 2010-03-01T20:39:47Z | 2,359,104 | <p>For preventing a Windows shutdown when it is happening, you can react to the <a href="http://msdn.microsoft.com/en-us/library/aa376890%28VS.85%29.aspx" rel="nofollow">WM_QUERYENDSESSION</a> message (don't know if you can do that easily with Python's win32 API but it's simple in C). This might not prevent application... | 1 | 2010-03-01T21:10:46Z | [
"python",
"windows",
"windows-7",
"shutdown"
] |
Python's subprocessing with pipes and large files | 2,358,936 | <p>I'm trying to use python + ffmpeg + oggenc to convert any audiofile to ogg. The program works, almost. But for big files (i think > ~6mb) the ffmpeg process starts to sleep at pipe_wait. I don't know which pipe it waits for.</p>
<p>If I kill the ffmpeg process, the oggenc process continues and I get a resulting ogg... | 7 | 2010-03-01T20:41:09Z | 2,358,997 | <p>Its tricky to see who needs to pass the pipe, eer I mean you should use a debugger like the one in NetBeans to help gather more clues. Pipe's may not be the best approach, perhaps using a temporary file would simplify things. </p>
| 0 | 2010-03-01T20:53:01Z | [
"python",
"ffmpeg",
"subprocess"
] |
Python's subprocessing with pipes and large files | 2,358,936 | <p>I'm trying to use python + ffmpeg + oggenc to convert any audiofile to ogg. The program works, almost. But for big files (i think > ~6mb) the ffmpeg process starts to sleep at pipe_wait. I don't know which pipe it waits for.</p>
<p>If I kill the ffmpeg process, the oggenc process continues and I get a resulting ogg... | 7 | 2010-03-01T20:41:09Z | 2,359,267 | <p>What exactly do you do with the <code>stderr</code> channels of the two pipes?</p>
<p>Encoders/decoders typically produce lots of stderr output, as status updates; this output is piped to your process, and buffers will become full. Perhaps you should add some dummy <code>ffmpeg.stderr.read()</code> call before the ... | 5 | 2010-03-01T21:40:32Z | [
"python",
"ffmpeg",
"subprocess"
] |
How can you programmatically inspect the stack trace of an exception in Python? | 2,359,248 | <p>When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the <a href="http://docs.python.org/library/traceback.html">traceback</a> module, but I can't figure out how to use it.</p>
<p>My goal is to catch any exceptions that occur during the parsing of an eval expr... | 17 | 2010-03-01T21:37:14Z | 2,359,281 | <p>You can use the <a href="http://docs.python.org/library/inspect.html#the-interpreter-stack">inspect</a> module which has some utility functions for tracing. Have a look at the <a href="http://docs.python.org/library/inspect.html#types-and-members">overview of properties</a> of the frame objects.</p>
| 6 | 2010-03-01T21:43:51Z | [
"python",
"exception-handling",
"stack-trace",
"traceback"
] |
How can you programmatically inspect the stack trace of an exception in Python? | 2,359,248 | <p>When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the <a href="http://docs.python.org/library/traceback.html">traceback</a> module, but I can't figure out how to use it.</p>
<p>My goal is to catch any exceptions that occur during the parsing of an eval expr... | 17 | 2010-03-01T21:37:14Z | 2,359,522 | <p><code>traceback</code> is enough - and I suppose that documentation describes it rather well. Simplified example:</p>
<pre><code>import sys
import traceback
try:
eval('a')
except NameError:
traceback.print_exc(file=sys.stdout)
</code></pre>
| 13 | 2010-03-01T22:20:14Z | [
"python",
"exception-handling",
"stack-trace",
"traceback"
] |
How can you programmatically inspect the stack trace of an exception in Python? | 2,359,248 | <p>When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the <a href="http://docs.python.org/library/traceback.html">traceback</a> module, but I can't figure out how to use it.</p>
<p>My goal is to catch any exceptions that occur during the parsing of an eval expr... | 17 | 2010-03-01T21:37:14Z | 2,360,477 | <p>In addition to AndiDog's answer about <code>inspect</code>, note that <code>pdb</code> lets you navigate up and down the stack, inspecting locals and such things. The source in the standard library <code>pdb.py</code> could be helpful to you in learning how to do such things.</p>
| 0 | 2010-03-02T02:09:13Z | [
"python",
"exception-handling",
"stack-trace",
"traceback"
] |
How can you programmatically inspect the stack trace of an exception in Python? | 2,359,248 | <p>When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the <a href="http://docs.python.org/library/traceback.html">traceback</a> module, but I can't figure out how to use it.</p>
<p>My goal is to catch any exceptions that occur during the parsing of an eval expr... | 17 | 2010-03-01T21:37:14Z | 8,287,057 | <p>I like the traceback module.</p>
<p>You can get a traceback object using <code>sys.exc_info()</code>. Then you can use that object to get a list preprocessed list of traceback entries using <code>traceback.extract_tb()</code>. Then you can get a readable list using <code>traceback.format_list()</code> as follows:... | 4 | 2011-11-27T16:30:13Z | [
"python",
"exception-handling",
"stack-trace",
"traceback"
] |
How can you programmatically inspect the stack trace of an exception in Python? | 2,359,248 | <p>When an exception occurs in Python, can you inspect the stack? Can you determine its depth? I've looked at the <a href="http://docs.python.org/library/traceback.html">traceback</a> module, but I can't figure out how to use it.</p>
<p>My goal is to catch any exceptions that occur during the parsing of an eval expr... | 17 | 2010-03-01T21:37:14Z | 15,721,390 | <p>You define such a function (<a href="http://docs.python.org/2/library/inspect.html" rel="nofollow">doc here</a>):</p>
<pre><code>def raiseErr():
for f in inspect.stack(): print '-', inspect.getframeinfo(f[0])
</code></pre>
<p>and call it from your modules so:</p>
<pre><code>raiseErr()
</code></pre>
<p>The fun... | 1 | 2013-03-30T17:31:02Z | [
"python",
"exception-handling",
"stack-trace",
"traceback"
] |
Solving embarassingly parallel problems using Python multiprocessing | 2,359,253 | <p>How does one use <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> to tackle <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly parallel problems</a>?</p>
<p>Embarassingly parallel problems typically consist of three basic parts:</p>
<ol>
<li><strong>Read<... | 65 | 2010-03-01T21:38:18Z | 2,359,357 | <p>Old School.</p>
<p>p1.py</p>
<pre><code>import csv
import pickle
import sys
with open( "someFile", "rb" ) as source:
rdr = csv.reader( source )
for line in eumerate( rdr ):
pickle.dump( line, sys.stdout )
</code></pre>
<p>p2.py</p>
<pre><code>import pickle
import sys
while True:
try:
... | 3 | 2010-03-01T21:55:50Z | [
"python",
"concurrency",
"multiprocessing",
"embarrassingly-parallel"
] |
Solving embarassingly parallel problems using Python multiprocessing | 2,359,253 | <p>How does one use <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> to tackle <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly parallel problems</a>?</p>
<p>Embarassingly parallel problems typically consist of three basic parts:</p>
<ol>
<li><strong>Read<... | 65 | 2010-03-01T21:38:18Z | 2,364,667 | <p>My solution has an extra bell and whistle to make sure that the order of the output has the same as the order of the input. I use multiprocessing.queue's to send data between processes, sending stop messages so each process knows to quit checking the queues. I think the comments in the source should make it clear ... | 50 | 2010-03-02T16:16:29Z | [
"python",
"concurrency",
"multiprocessing",
"embarrassingly-parallel"
] |
Solving embarassingly parallel problems using Python multiprocessing | 2,359,253 | <p>How does one use <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> to tackle <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly parallel problems</a>?</p>
<p>Embarassingly parallel problems typically consist of three basic parts:</p>
<ol>
<li><strong>Read<... | 65 | 2010-03-01T21:38:18Z | 2,417,906 | <p>Check out <a href="http://www.parallelpython.com/" rel="nofollow">http://www.parallelpython.com/</a></p>
| 2 | 2010-03-10T15:05:16Z | [
"python",
"concurrency",
"multiprocessing",
"embarrassingly-parallel"
] |
Solving embarassingly parallel problems using Python multiprocessing | 2,359,253 | <p>How does one use <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> to tackle <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly parallel problems</a>?</p>
<p>Embarassingly parallel problems typically consist of three basic parts:</p>
<ol>
<li><strong>Read<... | 65 | 2010-03-01T21:38:18Z | 2,418,671 | <p>It's probably possible to introduce a bit of parallelism into part 1 as well. Probably not an issue with a format that's as simple as CSV, but if the processing of the input data is noticeably slower than the reading of the data, you could read larger chunks, then continue to read until you find a "row separator" (n... | 0 | 2010-03-10T16:39:09Z | [
"python",
"concurrency",
"multiprocessing",
"embarrassingly-parallel"
] |
Solving embarassingly parallel problems using Python multiprocessing | 2,359,253 | <p>How does one use <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> to tackle <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly parallel problems</a>?</p>
<p>Embarassingly parallel problems typically consist of three basic parts:</p>
<ol>
<li><strong>Read<... | 65 | 2010-03-01T21:38:18Z | 18,401,221 | <p>I realize that I'm a bit late for the party, but I've recently discovered <a href="https://www.gnu.org/software/parallel/" rel="nofollow">GNU parallel</a>, and want to show how easy it is to accomplish this typical task with it.</p>
<pre><code>cat input.csv | parallel ./sum.py --pipe > sums
</code></pre>
<p>Som... | 2 | 2013-08-23T11:00:50Z | [
"python",
"concurrency",
"multiprocessing",
"embarrassingly-parallel"
] |
Solving embarassingly parallel problems using Python multiprocessing | 2,359,253 | <p>How does one use <a href="http://docs.python.org/library/multiprocessing.html">multiprocessing</a> to tackle <a href="http://en.wikipedia.org/wiki/Embarrassingly_parallel">embarrassingly parallel problems</a>?</p>
<p>Embarassingly parallel problems typically consist of three basic parts:</p>
<ol>
<li><strong>Read<... | 65 | 2010-03-01T21:38:18Z | 21,132,187 | <p>Coming late to the party...</p>
<p><a href="http://pythonhosted.org/joblib/parallel.html" rel="nofollow">joblib</a> has a layer on top of multiprocessing to help making parallel for loops. It gives you facilities like a lazy dispatching of jobs, and better error reporting in addition to its very simple syntax.</p>
... | 4 | 2014-01-15T08:13:10Z | [
"python",
"concurrency",
"multiprocessing",
"embarrassingly-parallel"
] |
OpenID or Auth in Django? | 2,359,272 | <p>What are the pros and cons of using <a href="http://openidenabled.com/python-openid/" rel="nofollow">open id</a> vs <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">auth</a>? Shoud I do both?</p>
| 1 | 2010-03-01T21:40:57Z | 2,359,299 | <p>That depends whether you want to support Open ID. As to the reasons behind Open ID, in my view the most compelling one is that it avoids requiring your users to have an account just for your site, with all the hassle that involves (yet another username and password to remember).</p>
<p>If you decide you want to use... | 5 | 2010-03-01T21:47:18Z | [
"python",
"django"
] |
OpenID or Auth in Django? | 2,359,272 | <p>What are the pros and cons of using <a href="http://openidenabled.com/python-openid/" rel="nofollow">open id</a> vs <a href="http://docs.djangoproject.com/en/dev/topics/auth/" rel="nofollow">auth</a>? Shoud I do both?</p>
| 1 | 2010-03-01T21:40:57Z | 2,359,586 | <p>OpenID and OAuth do different things. OpenID lets users log into your site. OAuth lets people give your site access to their data elsewhere. On the other side of the coin, OAuth gives you a secure way to let users access their data in your service from elsewhere.</p>
<p>If you implement OpenID, don't implement ... | 2 | 2010-03-01T22:28:37Z | [
"python",
"django"
] |
wxPython change field on tab | 2,359,300 | <p>I apologize for a simple question, but I did not see this in the tutorials.</p>
<p>I have a very simple gui, but I would like the user to be able to press the TAB key and have it move from one input field to another. I am using wxPython with Python 2.6.</p>
| 6 | 2010-03-01T21:47:21Z | 2,360,390 | <p>It should just work in the general case; what specific controls are you having issues with? You may need to pass wx.TAB_TRAVERSAL as a style, or if you need to manipulate the order, you can use the Move(After|Before)InTabOrder(otherControl) methods on the control.</p>
<p>See <a href="http://wiki.wxpython.org/Gettin... | 6 | 2010-03-02T01:47:18Z | [
"python",
"wxpython"
] |
Compatibility with IIS and Apache -- PHP, Python, etc? | 2,359,314 | <p>I'm currently planning out a web app that I want to host for people and allow them to host themselves on either Linux/Apache of IIS6 or IIS7 (for the benefits of bandwidth, directory services [login, etc.]). </p>
<p>I see that PHP is supported on both platforms. I've heard people serving Django and Python in IIS us... | 1 | 2010-03-01T21:49:19Z | 2,359,411 | <p>I have several production php5/6 applications that run on either windows/iis and apache/linux. switching between platforms has not been an issue for me. i test on a windows server talking to a mysql db on a linux machine. i deploy to a linux web server without issue. i cannot speak for rails or pytong as i'm not a r... | 0 | 2010-03-01T22:02:08Z | [
"php",
"python",
"apache",
"iis"
] |
Compatibility with IIS and Apache -- PHP, Python, etc? | 2,359,314 | <p>I'm currently planning out a web app that I want to host for people and allow them to host themselves on either Linux/Apache of IIS6 or IIS7 (for the benefits of bandwidth, directory services [login, etc.]). </p>
<p>I see that PHP is supported on both platforms. I've heard people serving Django and Python in IIS us... | 1 | 2010-03-01T21:49:19Z | 2,359,605 | <p>Your lowest common denominator for building apps to seemlessly run on both the LAMP and Microsoft stacks is PHP.</p>
<p>Perl is another option, it's well supported on both Windows and Linux/Apache. But I think I'd be choosing PHP over Perl because of support for FastCGI which improves reliability and performance on... | 0 | 2010-03-01T22:32:55Z | [
"php",
"python",
"apache",
"iis"
] |
How to find elements by 'id' field in SVG file using Python | 2,359,317 | <p>Below is an excerpt from an .svg file (which is xml):</p>
<pre><code> <text
xml:space="preserve"
style="font-size:14.19380379px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opa... | 3 | 2010-03-01T21:49:49Z | 2,359,880 | <p>Sorry, I don't know my way around minidom. Also, I had to find the namespace declarations from a sample svg document so that your excerpt could load.</p>
<p>I personally use lxml.etree. I'd recommend that you use XPATH for addressing parts of your XML document. It's pretty powerful and there's help here on SO if yo... | 9 | 2010-03-01T23:26:33Z | [
"python",
"xml",
"dom",
"svg",
"minidom"
] |
How to find elements by 'id' field in SVG file using Python | 2,359,317 | <p>Below is an excerpt from an .svg file (which is xml):</p>
<pre><code> <text
xml:space="preserve"
style="font-size:14.19380379px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opa... | 3 | 2010-03-01T21:49:49Z | 2,362,899 | <p>Does it work if you replace 'id' with <a href="http://www.w3.org/TR/xml-id/" rel="nofollow">'xml:id'</a>?</p>
<p>If minidom doesn't know svg it might treat the 'id' attribute as just any other attribute, instead of being of type ID. A conforming svg implementation would recognize the 'id' attribute in svg content a... | 0 | 2010-03-02T12:01:27Z | [
"python",
"xml",
"dom",
"svg",
"minidom"
] |
How to find elements by 'id' field in SVG file using Python | 2,359,317 | <p>Below is an excerpt from an .svg file (which is xml):</p>
<pre><code> <text
xml:space="preserve"
style="font-size:14.19380379px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opa... | 3 | 2010-03-01T21:49:49Z | 9,506,302 | <p>Adding a little bit to MattH's great example when you use xpath and you know the namespace you can do things like </p>
<pre><code>pub_name = data.xpath('//dc:publisher/cc:Agent/dc:title',
namespaces=nsmap)[0].text
</code></pre>
<p>This will give direct access to the element tag text tha... | 0 | 2012-02-29T20:42:04Z | [
"python",
"xml",
"dom",
"svg",
"minidom"
] |
Google App Engine with Eclipse? | 2,359,550 | <p>I'm trying to use Google App Engine with Eclipse but it's not working.</p>
<p>I downloaded PyDev, and made a Hello World Python app, so that's working fine.</p>
<p>Then I created a new project, with the "Google App Engine" template. I was following these <a href="http://code.google.com/appengine/articles/eclipse.h... | 4 | 2010-03-01T22:23:44Z | 2,360,476 | <p>I've dealt with this same problem myself. </p>
<p>The Main Module needs to be set to the following:</p>
<pre><code>${GOOGLE_APP_ENGINE}/dev_appserver.py
</code></pre>
<p>It does cover it in the <a href="http://code.google.com/appengine/articles/eclipse.html">instructions</a>, step 3 under Starting Your First Pro... | 6 | 2010-03-02T02:08:46Z | [
"python",
"eclipse",
"google-app-engine",
"pydev"
] |
Correctness about variable scope | 2,359,726 | <p><br>
I'm currently developing some things in Python and I have a question about variables scope.</p>
<p>This is the code:</p>
<pre><code>a = None
anything = False
if anything:
a = 1
else:
a = 2
print a # prints 2
</code></pre>
<p>If I remove the first line (a = None) the code still works as before. Howev... | 7 | 2010-03-01T22:54:20Z | 2,359,759 | <p>I believe that Python uses function scope for local variables. That is, in any given function, if you assign a value to a local variable, it will be available from that moment onwards within that function until it returns. Therefore, since both branches of your code are guaranteed to assign to <code>a</code>, there ... | 2 | 2010-03-01T23:00:20Z | [
"python",
"scope"
] |
Correctness about variable scope | 2,359,726 | <p><br>
I'm currently developing some things in Python and I have a question about variables scope.</p>
<p>This is the code:</p>
<pre><code>a = None
anything = False
if anything:
a = 1
else:
a = 2
print a # prints 2
</code></pre>
<p>If I remove the first line (a = None) the code still works as before. Howev... | 7 | 2010-03-01T22:54:20Z | 2,359,769 | <p>Python doesn't need variables to be declared initially, so you can declare and define at arbitrary points. And yes, the scope is function scope, so it will be visible outside the <code>if</code>.</p>
| 0 | 2010-03-01T23:02:00Z | [
"python",
"scope"
] |
Correctness about variable scope | 2,359,726 | <p><br>
I'm currently developing some things in Python and I have a question about variables scope.</p>
<p>This is the code:</p>
<pre><code>a = None
anything = False
if anything:
a = 1
else:
a = 2
print a # prints 2
</code></pre>
<p>If I remove the first line (a = None) the code still works as before. Howev... | 7 | 2010-03-01T22:54:20Z | 2,359,771 | <p>As a rule of thumb, scopes are created in three places:</p>
<ol>
<li>File-scope - otherwise known as module scope</li>
<li>Class-scope - created inside <code>class</code> blocks</li>
<li>Function-scope - created inside <code>def</code> blocks</li>
</ol>
<p>(There are a few exceptions to these.)</p>
<p>Assigning t... | 8 | 2010-03-01T23:02:29Z | [
"python",
"scope"
] |
Correctness about variable scope | 2,359,726 | <p><br>
I'm currently developing some things in Python and I have a question about variables scope.</p>
<p>This is the code:</p>
<pre><code>a = None
anything = False
if anything:
a = 1
else:
a = 2
print a # prints 2
</code></pre>
<p>If I remove the first line (a = None) the code still works as before. Howev... | 7 | 2010-03-01T22:54:20Z | 2,359,780 | <p>There is no problem assigning the variable in the <code>if</code> block.</p>
<p>In this case it is being assigned on both branches, so you can see it will definitely be defined when you come to print it.</p>
<p>If one of the branches did not assign to <code>a</code> then a <code>NameError</code> exception would be... | 1 | 2010-03-01T23:03:40Z | [
"python",
"scope"
] |
Correctness about variable scope | 2,359,726 | <p><br>
I'm currently developing some things in Python and I have a question about variables scope.</p>
<p>This is the code:</p>
<pre><code>a = None
anything = False
if anything:
a = 1
else:
a = 2
print a # prints 2
</code></pre>
<p>If I remove the first line (a = None) the code still works as before. Howev... | 7 | 2010-03-01T22:54:20Z | 2,359,852 | <p>i'm quite a beginner programmer, but for what i know, in python private variables don't exist. see <a href="http://docs.python.org/tutorial/classes.html#python-scopes-and-namespaces" rel="nofollow">private variables</a> in the python documentation for a detailed discussion.</p>
<p>useful informations can also be fo... | 0 | 2010-03-01T23:21:32Z | [
"python",
"scope"
] |
Dealing with UTF-8 numbers in Python | 2,359,832 | <p>Suppose I am reading a file containing 3 comma separated numbers. The file was saved with with an unknown encoding, so far I am dealing with ANSI and UTF-8. If the file was in UTF-8 and it had 1 row with values 115,113,12 then:</p>
<pre><code>with open(file) as f:
a,b,c=map(int,f.readline().split(','))
</code><... | 10 | 2010-03-01T23:16:40Z | 2,359,858 | <p>What you're seeing is a UTF-8 encoded <a href="http://en.wikipedia.org/wiki/Byte-order_mark">BOM</a>, or "Byte Order Mark". The BOM is not usually used for UTF-8 files, so the best way to handle it might be to open the file with a UTF-8 codec, and skip over the <code>U+FEFF</code> character if present.</p>
| 12 | 2010-03-01T23:22:37Z | [
"python",
"utf-8",
"character-encoding",
"byte-order-mark"
] |
Dealing with UTF-8 numbers in Python | 2,359,832 | <p>Suppose I am reading a file containing 3 comma separated numbers. The file was saved with with an unknown encoding, so far I am dealing with ANSI and UTF-8. If the file was in UTF-8 and it had 1 row with values 115,113,12 then:</p>
<pre><code>with open(file) as f:
a,b,c=map(int,f.readline().split(','))
</code><... | 10 | 2010-03-01T23:16:40Z | 2,360,047 | <pre><code>import codecs
with codecs.open(file, "r", "utf-8-sig") as f:
a, b, c= map(int, f.readline().split(","))
</code></pre>
<p>This works in Python 2.6.4. The <code>codecs.open</code> call opens the file and returns data as unicode, decoding from UTF-8 and ignoring the initial BOM.</p>
| 17 | 2010-03-02T00:01:27Z | [
"python",
"utf-8",
"character-encoding",
"byte-order-mark"
] |
Bash while loop calling a Python script | 2,359,896 | <p>I would like to call a Python script from within a Bash while loop. However, I do not understand very well how to use appropriately the while loop (and maybe variable) syntax of the Bash. The behaviour I am looking for is that, while a file still contains lines (DNA sequences), I am calling a Python script to extrac... | 1 | 2010-03-01T23:30:31Z | 2,359,913 | <p>try <code>-gt</code> to eliminate the shell metacharacter <code>></code></p>
<pre><code>while [ `wc -l file.txt` -gt 0 ]
do
...
c=$[c + 1]
done
</code></pre>
| 1 | 2010-03-01T23:34:19Z | [
"python",
"bash",
"while-loop"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.