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 |
|---|---|---|---|---|---|---|---|---|---|
Plotting two .txt files in the same figure using Python | 39,739,291 | <p>I am trying to plot two .txt files in the same figure. I am using a simple Python script for that.</p>
<pre><code>import sys
import os
import numpy
import matplotlib.pyplot as plt
from pylab import *
trap_error = 'trap_error.txt'
N , error = numpy.loadtxt(trap_error, unpack =True)
monte_error = 'monte_carlo_erro... | 0 | 2016-09-28T06:11:57Z | 39,739,752 | <p>Try the following:</p>
<pre><code>import sys
import os
import numpy
import matplotlib.pyplot as plt
from pylab import *
trap_error = 'trap_error.txt'
N, error1 = numpy.loadtxt(trap_error, unpack=True)
monte_error = 'monte_carlo_error.txt'
points, Integral, error2 = numpy.loadtxt(monte_error, unpack=True)
plt.log... | 2 | 2016-09-28T06:38:03Z | [
"python",
"matplotlib"
] |
Plotting two .txt files in the same figure using Python | 39,739,291 | <p>I am trying to plot two .txt files in the same figure. I am using a simple Python script for that.</p>
<pre><code>import sys
import os
import numpy
import matplotlib.pyplot as plt
from pylab import *
trap_error = 'trap_error.txt'
N , error = numpy.loadtxt(trap_error, unpack =True)
monte_error = 'monte_carlo_erro... | 0 | 2016-09-28T06:11:57Z | 39,739,798 | <p>You are overwriting the variable <code>error</code> and also plotting the same thing twice :</p>
<pre><code>N , error = numpy.loadtxt(trap_error, unpack =True)
</code></pre>
<p>and then</p>
<pre><code>points, Integral, error = numpy.loadtxt(monte_error, unpack =True)
</code></pre>
<p>Use different names for the ... | 2 | 2016-09-28T06:40:46Z | [
"python",
"matplotlib"
] |
Plotting two .txt files in the same figure using Python | 39,739,291 | <p>I am trying to plot two .txt files in the same figure. I am using a simple Python script for that.</p>
<pre><code>import sys
import os
import numpy
import matplotlib.pyplot as plt
from pylab import *
trap_error = 'trap_error.txt'
N , error = numpy.loadtxt(trap_error, unpack =True)
monte_error = 'monte_carlo_erro... | 0 | 2016-09-28T06:11:57Z | 39,740,323 | <p>You rewrote error from trap_error.txt file. Use the below code to fix your issue</p>
<pre><code>trap_error = 'trap_error.txt'
N , error1 = numpy.loadtxt(trap_error, unpack =True)
monte_error = 'monte_carlo_error.txt'
points, Integral, error2 = numpy.loadtxt(monte_error, unpack =True)
plt.loglog(N,error1, 'o')
plt.l... | 1 | 2016-09-28T07:07:17Z | [
"python",
"matplotlib"
] |
Python script - String Search - Arista | 39,739,357 | <p>I'm trying to run a script on arista switch, which is a simple python script. I got some values by running a command on the switch and I need to find a value from that command. for eg:</p>
<pre><code>#!/usr/bin/python
from jsonrpclib import Server
switch = Server( "http://XXX:XXX@192.168.XX.XX/command-api" )
resp... | 0 | 2016-09-28T06:16:59Z | 39,739,493 | <p>Basically you have dictionary of dictionary of dictionary. For this case, its simply. But if you have multiple of such cases, you have to iterate with the keys of first two dictionaries (dict1: interface and dict2: ethernet)</p>
<pre><code>a['interfaceStatuses']['Ethernet49']['linkStatus']
</code></pre>
| 1 | 2016-09-28T06:25:00Z | [
"python",
"python-2.7",
"string-search"
] |
Get minimum number column wise in a multidimensional Pandas DataFrame - Python | 39,739,432 | <p>I am new to Pandas. I am trying to get the minimum number column-wise. So these are the steps I have followed:</p>
<ol>
<li><p>I read the files from CSV files using </p>
<p>data = [pd.read_csv(f, index_col=None, header=None) for f in temp]</p></li>
<li><p>Then added it to another data frame <code>flow = pd.DataFra... | 2 | 2016-09-28T06:21:28Z | 39,739,495 | <p>I think you need:</p>
<pre><code>print (data[0].min(axis=1))
0 3662.1
1 3660.0
2 3659.5
3 3660.0
4 3661.5
5 3662.6
6 3661.5
7 3660.0
8 3661.5
9 3662.1
10 3660.0
11 3661.0
12 3664.1
13 3664.1
14 3661.5
15 3661.0
...
...
</code></pre>
<p>Maybe... | 1 | 2016-09-28T06:25:09Z | [
"python",
"pandas"
] |
Python - assign value and check condition in IF statment | 39,739,510 | <p>I have this code:</p>
<pre><code>str = func(parameter)
if not str:
do something.
</code></pre>
<p>the function <code>func()</code> return a <code>string</code> on success and <code>''</code> on failure.
The <code>do something</code> should happen only if <code>str</code> actualy contain a string.</p>
<p>Is it ... | 1 | 2016-09-28T06:25:51Z | 39,739,567 | <p>Why not try it yourself,</p>
<pre><code>if not (a = some_func()):
do something
^
SyntaxError: invalid syntax
</code></pre>
<p><strong>So, no.</strong></p>
| 1 | 2016-09-28T06:28:59Z | [
"python"
] |
Python - assign value and check condition in IF statment | 39,739,510 | <p>I have this code:</p>
<pre><code>str = func(parameter)
if not str:
do something.
</code></pre>
<p>the function <code>func()</code> return a <code>string</code> on success and <code>''</code> on failure.
The <code>do something</code> should happen only if <code>str</code> actualy contain a string.</p>
<p>Is it ... | 1 | 2016-09-28T06:25:51Z | 39,739,578 | <p>With the below code snippet, if the func returns a string of length > 0 only then the do something part will happen</p>
<pre><code>str = func(parameter)
if str:
do something
</code></pre>
| 0 | 2016-09-28T06:29:39Z | [
"python"
] |
Python - assign value and check condition in IF statment | 39,739,510 | <p>I have this code:</p>
<pre><code>str = func(parameter)
if not str:
do something.
</code></pre>
<p>the function <code>func()</code> return a <code>string</code> on success and <code>''</code> on failure.
The <code>do something</code> should happen only if <code>str</code> actualy contain a string.</p>
<p>Is it ... | 1 | 2016-09-28T06:25:51Z | 39,739,579 | <p>You can try this, it's the shortest version I could come up with: </p>
<pre><code>if func(parameter):
do something.
</code></pre>
| 0 | 2016-09-28T06:29:42Z | [
"python"
] |
Python - assign value and check condition in IF statment | 39,739,510 | <p>I have this code:</p>
<pre><code>str = func(parameter)
if not str:
do something.
</code></pre>
<p>the function <code>func()</code> return a <code>string</code> on success and <code>''</code> on failure.
The <code>do something</code> should happen only if <code>str</code> actualy contain a string.</p>
<p>Is it ... | 1 | 2016-09-28T06:25:51Z | 39,739,616 | <p>In one word: no. In Python assignment is a statement, not an expression. </p>
| 1 | 2016-09-28T06:31:52Z | [
"python"
] |
Stack the lables of an axis with matplotlib | 39,739,644 | <p>I'm creating a bar graph and showing multiple values on the x axis. By default they are shown in series with a "," separating them as shown below. Instead of a coma how could I show the values stacked on top of each other as drawn on the image below? This would save space on the x-axis to allow for bigger graphs whe... | 2 | 2016-09-28T06:32:59Z | 39,744,519 | <p>You can simply hack the x-axis tick labels to achieve what you want.</p>
<pre><code>ticks = myplot.xaxis.get_ticklabels()
new_ticks = ['\n'.join(t.get_text()[1:-1].split(', ')) for t in ticks]
myplot.xaxis.set_ticklabels(new_ticks)
</code></pre>
<p><a href="http://i.stack.imgur.com/VQ1XE.png" rel="nofollow"><img s... | 2 | 2016-09-28T10:13:39Z | [
"python",
"matplotlib"
] |
Interactive System Arguments in Python | 39,739,686 | <p>I have written a code which is to be run from the command prompt, taking arguments from the command.</p>
<p>What i have tried.</p>
<pre><code>start_date = sys.argv[1]
end_date = sys.argv[2]
end_date2 = datetime.strptime(end_date, "%d %b %Y").date()
start_date2 = datetime.strptime(start_date, "%d %b %Y").date()
--... | 0 | 2016-09-28T06:34:50Z | 39,739,734 | <p>Yes, it is possible. Simply after detecting dates are wrong use <code>print</code>/<code>raw_input</code> and ask user for new date, overwrite old one and check dates again.</p>
<p>For example (pseudocode a bit):</p>
<pre><code>start_date = sys.argv[1]
while start_date.isWrong():
print "start_date is wrong, gi... | 0 | 2016-09-28T06:37:15Z | [
"python",
"python-2.7",
"sys"
] |
What does it mean when the cumtimes of callees don't add up to the total cumtime of a function? | 39,739,697 | <p>I'm using <code>cProfile.Profile</code>.</p>
<p>In the output of <code>print_callees</code>, I can see that a function takes about 2 seconds of <code>cumtime</code>.</p>
<p>But when I check the output of the functions it calls, their <code>cumtime</code> don't sum up to that of the caller. Actually it's much small... | 2 | 2016-09-28T06:35:27Z | 39,739,842 | <p>This means that the function performs computations (and most probably contains a loop).</p>
<p>Example:</p>
<pre><code>def foo(n):
s = 0
for i in range(n):
s += i
print(s)
return s
</code></pre>
<p><code>print()</code> is a called by <code>foo()</code>, but for a large enough <code>n</code... | 0 | 2016-09-28T06:42:45Z | [
"python",
"performance"
] |
What does it mean when the cumtimes of callees don't add up to the total cumtime of a function? | 39,739,697 | <p>I'm using <code>cProfile.Profile</code>.</p>
<p>In the output of <code>print_callees</code>, I can see that a function takes about 2 seconds of <code>cumtime</code>.</p>
<p>But when I check the output of the functions it calls, their <code>cumtime</code> don't sum up to that of the caller. Actually it's much small... | 2 | 2016-09-28T06:35:27Z | 39,739,858 | <p>That actually makes a lot of sense: the difference is the time the code in the function, excluding the calls it makes, takes. For example:</p>
<pre><code>def foo():
for i in range(99999):
print 'hello'
bar()
baz()
</code></pre>
<p>The cumulative time of <code>foo</code> will be much larger than... | 1 | 2016-09-28T06:43:27Z | [
"python",
"performance"
] |
How to keep the number fraction format in Python3.x while performing simple operations? | 39,739,706 | <p>In code, I would like to keep the format of number while doing different simple operations (e.g. multiplication 1/6 * 1/6 ) in python 3.x. </p>
<p>I want to have:</p>
<pre><code>{
2: 1/36,
3: 2/36,
4: 3/36,
5: 4/36,
6: 5/36,
7: 6/36,
8: 5/36,
9: 4/36,
10: 3/36,
11: 2/36,
... | 0 | 2016-09-28T06:35:57Z | 39,739,853 | <p>I'm not aware of any programming language <strong>not</strong> evaluating the expression to a float without mentioning.</p>
<p>In case of python you should use module <a href="https://docs.python.org/3/library/fractions.html?highlight=fraction#module-fractions" rel="nofollow">fraction</a>.</p>
| 0 | 2016-09-28T06:43:06Z | [
"python"
] |
How to keep the number fraction format in Python3.x while performing simple operations? | 39,739,706 | <p>In code, I would like to keep the format of number while doing different simple operations (e.g. multiplication 1/6 * 1/6 ) in python 3.x. </p>
<p>I want to have:</p>
<pre><code>{
2: 1/36,
3: 2/36,
4: 3/36,
5: 4/36,
6: 5/36,
7: 6/36,
8: 5/36,
9: 4/36,
10: 3/36,
11: 2/36,
... | 0 | 2016-09-28T06:35:57Z | 39,740,025 | <p>Using the <a href="https://docs.python.org/3/library/fractions.html" rel="nofollow">fractions</a> module and string formatting you can print rational numbers like this</p>
<pre><code>import fractions
print("{}".format(fractions.Fraction(0.027777777777777776).limit_denominator()))
</code></pre>
<p>this will output<... | 0 | 2016-09-28T06:53:10Z | [
"python"
] |
Column as alias is ambigous in Postgresql | 39,739,716 | <p>I am migrating the database from MySQL to Postgrsql. In MySQL I create a view like this:</p>
<pre><code> create or replace view translated_attributes_with_attribute_templatevalues as
select
concat_ws('',
translated_attributevalues.attribute_id,
translated_attributevalues.languagecode,
attribute_template... | 0 | 2016-09-28T06:36:21Z | 39,740,399 | <p>Either repeat the expression in the <code>GROUP BY</code> clause:</p>
<pre><code>GROUP BY concat_ws('', ...)
</code></pre>
<p>or use the result column number:</p>
<pre><code>GROUP BY 1
</code></pre>
<p>The only advantage of the first solution is that it complies with the SQL standard.</p>
| 1 | 2016-09-28T07:10:40Z | [
"python",
"django",
"postgresql"
] |
Generate two loops with different ranges | 39,739,876 | <p>I am trying to generate two loops and I want the second loop to count from the first number of my first loop in range of 10 until 80. It looks like this:</p>
<pre><code>0
0
1
12345678910
2
234567891011121314151617181920
3
3456789101112131415161718192021222324252627282930
</code></pre>
<p>Continue like this until 8... | -1 | 2016-09-28T06:44:29Z | 39,740,555 | <p>You have a number of syntax errors in your code. I think I have a working version for you here:</p>
<pre><code>for i in range(9):
end_second_loop = (i * 10) + 1
print(i)
for j in range(i, end_second_loop):
print(j, end='')
print()
</code></pre>
<p>I'll also go over what was wrong syntactic... | 1 | 2016-09-28T07:17:55Z | [
"python",
"loops",
"nested"
] |
Generate two loops with different ranges | 39,739,876 | <p>I am trying to generate two loops and I want the second loop to count from the first number of my first loop in range of 10 until 80. It looks like this:</p>
<pre><code>0
0
1
12345678910
2
234567891011121314151617181920
3
3456789101112131415161718192021222324252627282930
</code></pre>
<p>Continue like this until 8... | -1 | 2016-09-28T06:44:29Z | 39,741,061 | <p>You don't need a <code>for</code> loop to print a list of integers: use the <code>str.join</code> method. Here is a example:</p>
<pre><code>for x in range(9):
print('{}\n{}'.format(str(x), ''.join(map(str, range(x, 10 * x + 1)))))
</code></pre>
<p>The trick is to map the integers into strings before performing... | 0 | 2016-09-28T07:42:15Z | [
"python",
"loops",
"nested"
] |
heroku-django-uploaded image is not displayed if DEBUG=False | 39,739,904 | <p>I deployed my Django app on heroku. Every thing is working fine except displaying images. Any uploaded image is not displayed if DEBUG=False.</p>
<p>settings.py</p>
<pre><code>DEBUG = False
ALLOWED_HOSTS = ['salma-blog.herokuapp.com']
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATI... | 0 | 2016-09-28T06:46:10Z | 39,741,989 | <p>Whitenoise uses <a href="http://whitenoise.evans.io/en/stable/django.html#WHITENOISE_USE_FINDERS" rel="nofollow">static file finders</a> when <code>DEBUG=True</code>, so you most likely have a problem with your static file collection process.</p>
<p>Update your <code>STATIC_ROOT</code> and <code>MEDIA_ROOT</code> s... | 0 | 2016-09-28T08:29:18Z | [
"python",
"django",
"heroku"
] |
IO error in Python | 39,739,912 | <p>I am trying to run this code:</p>
<pre><code> import urllib
htmlfile = urllib.urlopen("https://www.google.co.in/?gfe_rd=cr&ei=7VzrV6WWG8KC0ATxor_IDw")
htmltext = htmlfile.read()
print htmltext
</code></pre>
<p>But the following error is shown, when I run the code:</p>
<pre><code> Traceback (... | 0 | 2016-09-28T06:46:32Z | 39,739,982 | <p>It's a connection problem (your code works on my computer). Check your firewall / proxy settings / dns server / other connection settings.</p>
| 1 | 2016-09-28T06:50:33Z | [
"python"
] |
Outputting two graphs at once using matplotlib | 39,740,109 | <p>In short, I want to write a function that will output a <a href="http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html#visualization-scatter-matrix" rel="nofollow">scatter matrix</a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.boxplot.html" rel="nofollow">boxp... | 3 | 2016-09-28T06:57:35Z | 39,740,629 | <p>The issue here is that you are not actually plotting on the created axes , you are just replacing the content of your list <code>ax</code>.
I'm not very familiar with the object oriented interface for matplotlib but the right syntax would look more like <code>ax[i,j].plot()</code> rather than <code>ax[i] = plot()</c... | 0 | 2016-09-28T07:21:33Z | [
"python",
"matplotlib",
"jupyter-notebook"
] |
Outputting two graphs at once using matplotlib | 39,740,109 | <p>In short, I want to write a function that will output a <a href="http://pandas.pydata.org/pandas-docs/version/0.15.0/visualization.html#visualization-scatter-matrix" rel="nofollow">scatter matrix</a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.boxplot.html" rel="nofollow">boxp... | 3 | 2016-09-28T06:57:35Z | 39,746,080 | <p>I think you just need to pass the axis as an argument of your plotting function. </p>
<pre><code>f, ax = plt.subplots(2, 1, figsize = (12,6))
def boxplotscatter(data, ax):
ax[0] = scatter_matrix(data, alpha = 0.2, figsize = (6,6), diagonal = 'kde')
ax[1] = data.boxplot()
</code></pre>
| 1 | 2016-09-28T11:25:00Z | [
"python",
"matplotlib",
"jupyter-notebook"
] |
If I write two pieces of software that compute the same thing but one does it twice as fast. Does that imply different orders of complexity? | 39,740,155 | <p>For a given balance and interest rate my programs compute the minimum monthly payment to pay off the debt in a year.
However One computes it on average in ~0.000150s and the other in ~0.000300s. Does that imply different degrees of asymptotic complexity?</p>
<p>These are the code samples: </p>
<p>The slower one:</... | -1 | 2016-09-28T06:59:13Z | 39,740,235 | <p>No, they are not same program. The first one has a while loop that calls a function that has another while loop - looks like, both of them has different complexity.</p>
<p>The first one is clearly the slower one (a squared complexity program)- the second one has no such inner loops and is a linear complexity progra... | 0 | 2016-09-28T07:02:54Z | [
"python",
"algorithm",
"python-3.x",
"complexity-theory"
] |
If I write two pieces of software that compute the same thing but one does it twice as fast. Does that imply different orders of complexity? | 39,740,155 | <p>For a given balance and interest rate my programs compute the minimum monthly payment to pay off the debt in a year.
However One computes it on average in ~0.000150s and the other in ~0.000300s. Does that imply different degrees of asymptotic complexity?</p>
<p>These are the code samples: </p>
<p>The slower one:</... | -1 | 2016-09-28T06:59:13Z | 39,740,251 | <p>Absolutely not.</p>
<p>Asymptotic complexity never describes absolute running times, but the trend when the problem size increases.</p>
<p>In practice, it is extremely frequent that algorithms with a better asymptotic complexity run slower for small problem instances.</p>
| 5 | 2016-09-28T07:03:41Z | [
"python",
"algorithm",
"python-3.x",
"complexity-theory"
] |
If I write two pieces of software that compute the same thing but one does it twice as fast. Does that imply different orders of complexity? | 39,740,155 | <p>For a given balance and interest rate my programs compute the minimum monthly payment to pay off the debt in a year.
However One computes it on average in ~0.000150s and the other in ~0.000300s. Does that imply different degrees of asymptotic complexity?</p>
<p>These are the code samples: </p>
<p>The slower one:</... | -1 | 2016-09-28T06:59:13Z | 39,745,326 | <p>Translated into a verbal idea, you are trying to solve the linear equation <code>a-b*x=0</code>, in the first variant via the bisection method, in the second method via the direct formula <code>x = a/b</code>. Purely from the description, the second variant will always be faster, since the first also needs to comput... | 0 | 2016-09-28T10:48:25Z | [
"python",
"algorithm",
"python-3.x",
"complexity-theory"
] |
How can I take out(or slice) the elements in a rank-2 tensor , whose first element is unique? | 39,740,318 | <p>My title might be ambiguous due to my awkward English. But I mean this:
suppose i have a tensor <code>a</code> like this:</p>
<pre><code>array([[1, 2, 3],
[2, 2, 3],
[2, 2, 4],
[3, 2, 3],
[4, 2, 3]], dtype=int32)
</code></pre>
<p><strong>the 'first column' of this tensor could contain d... | 0 | 2016-09-28T07:07:04Z | 39,748,459 | <p>This is a bit gross, but you could do:</p>
<pre><code>print a
y, idx = tf.unique(a[:,0])
z = tf.one_hot(idx, tf.shape(y)[0])
s = tf.cumsum(z)
e = tf.equal(s, 1) # only seen once so far
ss = tf.to_int32(e) * tf.to_int32(z) # and we equal the thing
m = tf.reduce_max(ss, reduction_indices=1)
out = tf.boolean_mask(a, ... | 0 | 2016-09-28T13:06:57Z | [
"python",
"numpy",
"tensorflow",
"unique"
] |
Naming a set of equality equations Python | 39,740,475 | <p>I am currently working on solving a system of equations. </p>
<p>A subset of the equations are: </p>
<pre><code>eq1 = pi1 * q[0+1] == pi0 * r[0+1]
eq2 = pi2 * q[0+1] == pi0 * r[1+1] + pi1 * r[1+1]
eq3 = pi3 * q[0+1] == pi0 * r[2+1] + pi1 * r[2+1] + pi2 * r[1+1]
eq4 = pi4 * q[0+1] == pi0 * r[3+1] + pi1 ... | 2 | 2016-09-28T07:14:02Z | 39,740,955 | <p>You can store the equations in a dictionary - you will be mapping index of the equation (1, 2, etc) to a tuple, which will contain two items representing two sides of the equation. </p>
<pre><code>equations = dict()
equations[1] = (pi1 * q[0+1], pi0 * r[0+1])
</code></pre>
<p>You can then call <code>solve(equati... | 0 | 2016-09-28T07:36:38Z | [
"python",
"equality",
"sympy",
"equation"
] |
How to retrieve all data blocks from database at a certain entry in Django? | 39,740,498 | <p>I am very sorry for this newbie question...
I have data stored in the database (mysql) as tuples.
These data look like <strong>(datetime, frequency, current)</strong> ... etc.</p>
<p>How to retrieve all data from database at a certain time?
for example, I want to get all the saved data at "2015-9-9 8:23:10" </p>
| -1 | 2016-09-28T07:14:51Z | 39,740,682 | <p>can you show your model.</p>
<p>You can add created and updated fields to your model and query them to retrieve your data</p>
<pre><code>class Test(models.Model):
created = models.DateTimeField(
default=django.utils.timezone.now, blank=True)
updated = models.DateTimeField(
default=django.ut... | 0 | 2016-09-28T07:24:02Z | [
"python",
"mysql",
"django"
] |
How to retrieve all data blocks from database at a certain entry in Django? | 39,740,498 | <p>I am very sorry for this newbie question...
I have data stored in the database (mysql) as tuples.
These data look like <strong>(datetime, frequency, current)</strong> ... etc.</p>
<p>How to retrieve all data from database at a certain time?
for example, I want to get all the saved data at "2015-9-9 8:23:10" </p>
| -1 | 2016-09-28T07:14:51Z | 39,742,662 | <p>if datetime field is the date the data is created, you can try </p>
<p><code>Test.objects.all(datetime__gte=timezone.now)</code></p>
| 0 | 2016-09-28T09:01:23Z | [
"python",
"mysql",
"django"
] |
How to use reportlab on GAE(Google App Engine)? | 39,740,557 | <p>I have read <a href="http://stackoverflow.com/questions/22606060/how-to-use-reportlab-with-google-app-engine">how to use reportlab with google app engine</a> but it's not help for me. Currently, I have a working version on my local environment and try to deploy to GAE.</p>
<p>But there is error when the deployment ... | 0 | 2016-09-28T07:18:02Z | 39,870,767 | <p>Finally I downgrade the version of reportlab to 2.7 to make it work.</p>
| 0 | 2016-10-05T09:51:26Z | [
"python",
"google-app-engine",
"zlib",
"pillow",
"reportlab"
] |
TypeError: argument 1 must be convertible to a buffer, not BeautifulSoup | 39,740,560 | <pre><code>from bs4 import BeautifulSoup
import requests
import csv
page=requests.get("http://www.gigantti.fi/catalog/tietokoneet/fi_kannettavat/kannettavat-tietokoneet")
data=BeautifulSoup(page.content)
h=open("test.csv","wb+")
h.write(data)
h.close()
print (data)
</code></pre>
<p>i have tried running the code a... | -1 | 2016-09-28T07:18:08Z | 39,740,886 | <p>I don't know whether someone was able to solve it or not but my hit and trial worked. the problem was I was not converting the content to string.</p>
<pre><code>#what i needed to add was:
#after line data=BeautifulSoup(page.content)
a=str(data)
</code></pre>
<p>Hopefully this helps</p>
| 1 | 2016-09-28T07:33:37Z | [
"python",
"csv",
"web-scraping"
] |
TypeError: argument 1 must be convertible to a buffer, not BeautifulSoup | 39,740,560 | <pre><code>from bs4 import BeautifulSoup
import requests
import csv
page=requests.get("http://www.gigantti.fi/catalog/tietokoneet/fi_kannettavat/kannettavat-tietokoneet")
data=BeautifulSoup(page.content)
h=open("test.csv","wb+")
h.write(data)
h.close()
print (data)
</code></pre>
<p>i have tried running the code a... | -1 | 2016-09-28T07:18:08Z | 39,740,924 | <p>What you are trying to do doesn't make any sense.</p>
<p>As mentioned on <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">Beautiful Soup Documentation</a>:</p>
<blockquote>
<p>Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite... | 0 | 2016-09-28T07:35:10Z | [
"python",
"csv",
"web-scraping"
] |
Python type hinting without cyclic imports | 39,740,632 | <p>I'm trying to split my huge class into two; well, basically into the "main" class and a mixin with additional functions, like so:</p>
<pre><code># main.py
import mymixin.py
class Main(object, MyMixin):
def func1(self, xxx):
...
# mymixin.py
class MyMixin(object):
def func2(self: Main, xxx): # &l... | 2 | 2016-09-28T07:21:35Z | 39,741,253 | <p>The bigger issue is that your types aren't sane to begin with. <code>MyMixin</code> makes a hardcoded assumption that it will be mixed into <code>Main</code>, whereas it could be mixed into any number of other classes, in which case it would probably break. If your mixin is hardcoded to be mixed into one specific cl... | 1 | 2016-09-28T07:52:05Z | [
"python",
"pycharm",
"python-3.4",
"python-3.5",
"type-hinting"
] |
Python type hinting without cyclic imports | 39,740,632 | <p>I'm trying to split my huge class into two; well, basically into the "main" class and a mixin with additional functions, like so:</p>
<pre><code># main.py
import mymixin.py
class Main(object, MyMixin):
def func1(self, xxx):
...
# mymixin.py
class MyMixin(object):
def func2(self: Main, xxx): # &l... | 2 | 2016-09-28T07:21:35Z | 39,757,388 | <p>There isn't a hugely elegant way to handle import cycles in general, I'm afraid. Your choices are to either redesign your code to remove the cyclic dependency, or if it isn't feasible, do something like this:</p>
<pre><code># some_file.py
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from main import Main... | 1 | 2016-09-28T20:48:54Z | [
"python",
"pycharm",
"python-3.4",
"python-3.5",
"type-hinting"
] |
How to find parenthesis bound strings in python | 39,740,814 | <p>I'm learning Python and wanted to automate one of my assignments in a cybersecurity class.
I'm trying to figure out how I would look for the contents of a file that are bound by a set of parenthesis. The contents of the (.txt) file look like:</p>
<pre><code>cow.jpg : jphide[v5](asdfl;kj88876)
fish.jpg : jphide[v5](... | 3 | 2016-09-28T07:30:35Z | 39,740,912 | <p>If it should just be bound by ( and ) you can use the following regex, which ensures starting ( and closing ) and you can have numbers and characters between them. You can add any other symbol also that you want to include.</p>
<p><code>[\(][a-z A-Z 0-9]*[\)]</code></p>
<pre><code>[\(] - starts the bracket
[a-z A-... | 1 | 2016-09-28T07:34:26Z | [
"python"
] |
How to find parenthesis bound strings in python | 39,740,814 | <p>I'm learning Python and wanted to automate one of my assignments in a cybersecurity class.
I'm trying to figure out how I would look for the contents of a file that are bound by a set of parenthesis. The contents of the (.txt) file look like:</p>
<pre><code>cow.jpg : jphide[v5](asdfl;kj88876)
fish.jpg : jphide[v5](... | 3 | 2016-09-28T07:30:35Z | 39,741,169 | <blockquote>
<p>I'm learning Python</p>
</blockquote>
<p>If you are learning you should consider alternative implementations, not only regexps. </p>
<p>TO iterate line by line of a text file you just open the file and for over the file handle:</p>
<pre><code>with open('file.txt') as f:
for line in f:
d... | 0 | 2016-09-28T07:47:55Z | [
"python"
] |
How to find parenthesis bound strings in python | 39,740,814 | <p>I'm learning Python and wanted to automate one of my assignments in a cybersecurity class.
I'm trying to figure out how I would look for the contents of a file that are bound by a set of parenthesis. The contents of the (.txt) file look like:</p>
<pre><code>cow.jpg : jphide[v5](asdfl;kj88876)
fish.jpg : jphide[v5](... | 3 | 2016-09-28T07:30:35Z | 39,741,286 | <p>You should use regular expressions which are implemented in the <a href="https://docs.python.org/2/library/re.html" rel="nofollow">Python re module</a></p>
<p>a simple regex like <code>\(.*\)</code> could match your "parenthesis string"
but it would be better with a group <code>\((.*)\)</code> which allows to get o... | 0 | 2016-09-28T07:53:47Z | [
"python"
] |
How can I package my python module and its dependencies such as Numpy/Scipy into one file like dll for C# calls? | 39,740,884 | <p>In my project, some of the algorithms are implemented in python as Modules for calling and libraries such as Numpy/Scipy are used . Now I need to embed these Modules into my UI(implemented by C# and run in Windows 7). There are two reasons I need to package my python modules into a file like DLL(I don't want to pac... | 1 | 2016-09-28T07:33:30Z | 39,901,534 | <p>Try pythonnet to embed CPython in .NET:</p>
<p><a href="http://www.python4.net" rel="nofollow">python4.net</a></p>
| 0 | 2016-10-06T16:46:36Z | [
"c#",
"python",
".net",
"pyinstaller",
"python.net"
] |
How can I package my python module and its dependencies such as Numpy/Scipy into one file like dll for C# calls? | 39,740,884 | <p>In my project, some of the algorithms are implemented in python as Modules for calling and libraries such as Numpy/Scipy are used . Now I need to embed these Modules into my UI(implemented by C# and run in Windows 7). There are two reasons I need to package my python modules into a file like DLL(I don't want to pac... | 1 | 2016-09-28T07:33:30Z | 39,952,006 | <p>Finally, I solve my problem by using nuitka. It compile my module into .pyd file, and I can import the module using pythonnet by adding reference Python.Runtime.dll.
My compile command is:<code>nuitka --module --nofreeze-stdlib --recurse-all --recurse-not-to=numpy --recurse-not-to=sklearn --recurse-not-to=pywt --re... | 1 | 2016-10-10T05:52:22Z | [
"c#",
"python",
".net",
"pyinstaller",
"python.net"
] |
Reformat table in Python | 39,740,989 | <p>I have a table in a Python script with numpy in the following shape:</p>
<pre><code>[array([[a1, b1, c1], ..., [x1, y1, z1]]),
array([a2, b2, c2, ..., x2, y2, z2])
]
</code></pre>
<p>I would like to reshape it to a format like this:</p>
<pre><code>(array([[a2],
[b2],
.
.
.
... | 1 | 2016-09-28T07:38:32Z | 39,741,808 | <p>Round brackets <code>(1, 2)</code> are <a href="https://docs.python.org/3/library/stdtypes.html#tuple" rel="nofollow">tuples</a>, square brackets <code>[1, 2]</code> are <a href="https://docs.python.org/3/library/stdtypes.html#list" rel="nofollow">lists</a>. To convert your data structure, use <a href="http://docs.s... | 1 | 2016-09-28T08:20:12Z | [
"python",
"numpy"
] |
Reformat table in Python | 39,740,989 | <p>I have a table in a Python script with numpy in the following shape:</p>
<pre><code>[array([[a1, b1, c1], ..., [x1, y1, z1]]),
array([a2, b2, c2, ..., x2, y2, z2])
]
</code></pre>
<p>I would like to reshape it to a format like this:</p>
<pre><code>(array([[a2],
[b2],
.
.
.
... | 1 | 2016-09-28T07:38:32Z | 39,742,308 | <pre><code> #[array1,array2] is a python list of two numpy tables(narray)
#(array1,array2) is a python tuple of two numpy tables(narray)
tuple([array.reshape((-1,1)) for array in your_list.reverse()])
</code></pre>
| 1 | 2016-09-28T08:45:00Z | [
"python",
"numpy"
] |
Execute entire DAG using Airflow UI | 39,741,067 | <p>I am newbie to airflow, We have a DAG with 3 tasks. Currently we are using Celery Executor as we need the flexibility to run an individual task. We don't want to schedule the workflow, for now it will be manual trigger. Is there any way to execute the entire workflow using the Airflow UI (Same as we have in oozie)?<... | 0 | 2016-09-28T07:42:34Z | 39,742,181 | <p>I'll take a stab at it and hopefully you can adapt your code to work with this.</p>
<pre><code>default_args = {
'owner': 'airflow',
'depends_on_past': False,
'start_date': datetime(2015, 6, 1),
'email': ['airflow@airflow.com'],
'email_on_failure': False,
'email_on_retry': False,
'retries': 1,
'retry_delay': timedel... | 0 | 2016-09-28T08:39:13Z | [
"python",
"airflow"
] |
Filter data frame from values in different columns Pandas | 39,741,152 | <p>I am very new in Pandas and hope that somebody at least can point me in the right direction. </p>
<p>Here comes the actual question: </p>
<p>df: </p>
<pre><code> time Area lon lat mode ID
1993-08-01 00:34:28 A 45.627800 34.733400 false 3183... | 1 | 2016-09-28T07:47:13Z | 39,741,318 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html" rel="nofollow"><code>dropna</code></a> for removing all values which a... | 0 | 2016-09-28T07:55:19Z | [
"python",
"pandas"
] |
Filter data frame from values in different columns Pandas | 39,741,152 | <p>I am very new in Pandas and hope that somebody at least can point me in the right direction. </p>
<p>Here comes the actual question: </p>
<p>df: </p>
<pre><code> time Area lon lat mode ID
1993-08-01 00:34:28 A 45.627800 34.733400 false 3183... | 1 | 2016-09-28T07:47:13Z | 39,741,437 | <p>You can take a look at the following :</p>
<pre><code>In [24]: df
Out[24]:
area id
0 A 3183
1 A 3183
2 A 3184
3 B 3184
4 A 3185
5 A 3185
In [25]: df[df.groupby('id')['area'].transform('nunique') > 1]
Out[25]:
area id
2 A 3184
3 B 3184
</code></pre>
<p>I reduced my exam... | 0 | 2016-09-28T08:01:01Z | [
"python",
"pandas"
] |
django It seems the view func do not work | 39,741,232 | <p>I'm trying to write a FBV to delete a subject, but there are some problem I can't figure out. It's Django 1.7.1. Below are related codes.</p>
<p>The model Communication:</p>
<pre><code>...
@models.permalink
def get_delete_url(self):
return 'comm_delete', [self.uuid]
</code></pre>
<p>the URLconf:</p>
<pre><co... | -1 | 2016-09-28T07:50:51Z | 39,775,654 | <p>the urls.py in app Communications like this:</p>
<pre><code>url(r'^(?P<uuid>[\w-]+)/', views.comm_detail, name='comm_detail'),
url(r'^(?P<uuid>[\w-]+)/delete/$', views.comm_delete, name='comm_delete'),
</code></pre>
<p>as you can see, the first one has no '$' at the end, so when I link the url of seco... | 0 | 2016-09-29T16:34:49Z | [
"python",
"django"
] |
Tool for google maps using python | 39,741,287 | <p>I need to develop a tool (eg: calculate polygon area) and integrate it with Google Maps. I am not familiar with java. Can I do this using python? If yes, how can I go about integrating my code with Maps?</p>
| 0 | 2016-09-28T07:53:51Z | 39,742,040 | <p>You can do it, using <strong>OpenStreetMap</strong> instead of Google map, in <strong>IPython/Jupyter Notebook</strong>, through <strong>ipyleaflet</strong> package.
Just write(or import) your script in Ipython Notebook(a python based env.) and then take a look at here;</p>
<p><a href="https://github.com/ellisonbg/... | 1 | 2016-09-28T08:31:52Z | [
"python"
] |
How can I get the <select> tag option chosen by the user using Flask? | 39,741,302 | <p>I have a form whereby a user uploads a csv file, that csv file is then converted to a pandas dataframe and the column headers automatically populate the <code><select></code> tag options in the form.</p>
<p>I then want the user to select the column that they want and I want that column choice saved in a varia... | 0 | 2016-09-28T07:54:30Z | 39,746,075 | <p>You have to give each <code>option</code> a <code>value</code>. </p>
<pre><code><option value="{{ column }}">{{ column }}</option>
</code></pre>
| 0 | 2016-09-28T11:24:55Z | [
"javascript",
"python",
"html",
"flask"
] |
How can I get the <select> tag option chosen by the user using Flask? | 39,741,302 | <p>I have a form whereby a user uploads a csv file, that csv file is then converted to a pandas dataframe and the column headers automatically populate the <code><select></code> tag options in the form.</p>
<p>I then want the user to select the column that they want and I want that column choice saved in a varia... | 0 | 2016-09-28T07:54:30Z | 39,750,538 | <p>I managed to figure it out. I took the form and separated it over two pages. So, the <strong>File Upload</strong> part was in its own form on a page called <code>textform1.html</code>. The uploaded file would be converted to a pandas dataframe and then a new page called <code>textform2.html</code> would be rendered.... | 0 | 2016-09-28T14:33:41Z | [
"javascript",
"python",
"html",
"flask"
] |
regex to parse out certain value that i want | 39,741,419 | <p>Using <a href="https://regex101.com/" rel="nofollow">https://regex101.com/</a></p>
<ul>
<li>MY current regex Expression: <code>^.*'(\d\s*.*)'*$</code></li>
</ul>
<p>which doesnt seem to be working. What is the right combination formula that i should use?</p>
<p>I want to able to parse out <strong>4</strong> varia... | -1 | 2016-09-28T08:00:12Z | 39,742,249 | <p>The following regex matches each ingredient string and stores wanted informations into groups: <code>r'^(\d+)\s+([A-Za-z ]+)\s+(\d+(?:\.\d*))$'</code></p>
<p>It defines 3 groups each separated from other by spaces:</p>
<ul>
<li><code>^</code> marks the string start</li>
<li><code>(\d+)</code> is the first group an... | 1 | 2016-09-28T08:42:37Z | [
"python",
"regex"
] |
Python: subprocess not writing output files | 39,741,422 | <p>Using Python's <code>subprocess.call</code>, I am trying to invoke a C program that reads an input file on disk, and creates multiple output files. Running the C program from terminal gives the expected results, though <code>subprocess.call</code> does not.</p>
<p>In the minimal example, the program should read the... | 0 | 2016-09-28T08:00:15Z | 39,741,463 | <pre><code>import os
subprocess.call('bin/program.exe') # parses input file 'scratch/input.txt'
if not os.path.isfile('scratch'):
os.mkdir('scratch')
with open(os.path.join('scratch','output.txt'), 'w') as f:
f.write('Your message')
</code></pre>
<p>You have to open the file in a mode. Read for example. You w... | 1 | 2016-09-28T08:02:31Z | [
"python",
"subprocess"
] |
Pandas replace a character in all column names | 39,741,429 | <p>I have data frames with column names (coming from .csv files) containing <code>(</code> and <code>)</code> and I'd like to replace them with <code>_</code>.</p>
<p>How can I do that in place for all columns?</p>
| 1 | 2016-09-28T08:00:31Z | 39,741,442 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.replace.html" rel="nofollow"><code>str.replace</code></a>:</p>
<pre><code>df.columns = df.columns.str.replace("[()]", "_")
</code></pre>
<p>Sample:</p>
<pre><code>df = pd.DataFrame({'(A)':[1,2,3],
'(B)':[4,5,6]... | 1 | 2016-09-28T08:01:15Z | [
"python",
"pandas"
] |
Issue with unit test for tiny Flask app | 39,741,983 | <p>I have a very primitive Flask application which works as I'm expecting, but I'm failing to write a unit test for it. The code of the app is following (i omit insignificant part):</p>
<pre><code>app.py
from flask import *
import random
import string
app = Flask(__name__)
keys = []
app.testing = True
@app.route('/... | 0 | 2016-09-28T08:28:57Z | 39,743,443 | <p>You have a few issues with the posted code (indentation aside):</p>
<p>First, in <code>tests.py</code> you <code>import app</code> and use it, but <code>app</code> is the module rather than the <code>app</code> object from <code>app.py</code>. You should import the actual <code>app</code> object using</p>
<pre><co... | 2 | 2016-09-28T09:32:38Z | [
"python",
"unit-testing",
"flask"
] |
Spyder can not import plyfile | 39,742,082 | <p>I have installed plyfile in the Scripts subdirectory of the Anaconda3 (I run Windows 10), using the pip3. When I enter the command
import plyfile
in the Python 3.5 Shell, the command is executed without problems.<br>
But when I move to Spyder and I enter the same command in the console I receive an error messa... | 0 | 2016-09-28T08:34:08Z | 39,745,055 | <p>try give Spyder the same environment paths like Anaconda, in your case the path to the installed plyfile eg.:</p>
<p>your_module is located in: "C:\Users\Alexandros\your_module.py"</p>
<p>in Spyder:
lets add the located path to the system environment</p>
<pre><code>import sys
sys.path.append("C:\Users\Alexandros\... | 0 | 2016-09-28T10:37:10Z | [
"python"
] |
High performance all-to-all comparison of vectors in Python | 39,742,127 | <p>First to tell about the background: several methods for comparison between clusterings relies on so called pair counting. We have two vectors of flat clusterings <code>a</code> and <code>b</code> over the same <code>n</code> entities. At pair counting for all possible pairs of entities we check whether if those belo... | 3 | 2016-09-28T08:36:43Z | 39,746,217 | <p>The approach based on sorting has merit, but can be done a lot simpler:</p>
<pre><code>def pair_counts(a, b):
n = a.shape[0] # also b.shape[0]
counts_a = np.bincount(a)
counts_b = np.bincount(b)
sorter_a = np.argsort(a)
n11 = 0
same_a_offset = np.cumsum(counts_a)
for indices in np.spl... | 1 | 2016-09-28T11:32:04Z | [
"python",
"algorithm",
"numpy",
"cluster-analysis",
"cython"
] |
High performance all-to-all comparison of vectors in Python | 39,742,127 | <p>First to tell about the background: several methods for comparison between clusterings relies on so called pair counting. We have two vectors of flat clusterings <code>a</code> and <code>b</code> over the same <code>n</code> entities. At pair counting for all possible pairs of entities we check whether if those belo... | 3 | 2016-09-28T08:36:43Z | 39,747,414 | <p>To compare two clusterings <code>A</code> and <code>B</code> in linear time:</p>
<ol>
<li>Iterate through clusters in <code>A</code>. Let the size of each cluster be <code>a_i</code>. The total number of pairs in the same cluster in <code>A</code> is the total of all <code>a_i*(a_i-1)/2</code>.</li>
<li>Partition ... | 1 | 2016-09-28T12:23:22Z | [
"python",
"algorithm",
"numpy",
"cluster-analysis",
"cython"
] |
High performance all-to-all comparison of vectors in Python | 39,742,127 | <p>First to tell about the background: several methods for comparison between clusterings relies on so called pair counting. We have two vectors of flat clusterings <code>a</code> and <code>b</code> over the same <code>n</code> entities. At pair counting for all possible pairs of entities we check whether if those belo... | 3 | 2016-09-28T08:36:43Z | 39,762,726 | <p>You do <strong>not</strong> need to <em>enumerate and count</em> the pairs.</p>
<p>Instead, compute a <em>confusion matrix</em> containing the intersection sizes of each cluster from the first clustering with every cluster of the second clustering (this is one loop over all objects), then compute the number of pair... | 1 | 2016-09-29T06:16:36Z | [
"python",
"algorithm",
"numpy",
"cluster-analysis",
"cython"
] |
Retrieving the correct .json for wunderground | 39,742,176 | <p>So far I have produced the following code:</p>
<pre><code>import requests
def weatherSearch():
Search = raw_input('Enter your location: ')
r = requests.get("http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/{}.json".format(Search))
weatherData = r.json()
print weatherData
weatherSearch... | 0 | 2016-09-28T08:38:58Z | 39,742,412 | <p>Looks like your query returns a list of possible matches, each of which has an <code>l</code> key which contains a link. Using that link brings you back the full data for that location. So, for instance, the full data for London, UK is at <a href="http://api.wunderground.com/api/a8c3e5ce8970ae66/conditions/q/zmw:000... | 1 | 2016-09-28T08:49:30Z | [
"python",
"json",
"python-2.7",
"python-requests"
] |
Parsing the SLA from Jira API | 39,742,177 | <p>I am currently in the process of using the Jira API to pull some data on tickets created into a separate database.</p>
<p>Tickets have been designed to follow ITIL standards and have a 'Time to first response' and a Time to resolution'</p>
<p>Both of these are retrieved in Jason as the following:</p>
<pre><code> ... | 0 | 2016-09-28T08:38:59Z | 39,743,985 | <p>It seems this was a bug that was fixed in version 2.0</p>
| 0 | 2016-09-28T09:53:37Z | [
"python",
"jira",
"jira-rest-api"
] |
How do I get the information that the user has changed in a table in PyQT with Python and SQLite3 | 39,742,199 | <p>I have a table that comes up on my GUI. The user can edit this table from the GUI. how do I get all of the information that has been edited and update it in the database? The user checks the checkbox for each row they want to have updated to the database, so I have a list of all rows that require updating. I want to... | 1 | 2016-09-28T08:40:25Z | 39,755,269 | <p>You can do a few different things.</p>
<p>To prevent editing, you can just remove the edit flag for the items you don't want the user to edit</p>
<pre><code>FullName.setFlags(FullName.flags() & ~Qt.ItemIsEditable)
</code></pre>
<p>It looks like you're storing the original data (i.e. <code>self.all_data</code>... | 0 | 2016-09-28T18:39:06Z | [
"python",
"sqlite3",
"pyqt"
] |
Python) Combing three textfiles(lists) into one with sorting | 39,742,260 | <p>I'm trying to make a new text file which is combined with 3 different text files. I'll give more detail with codes.</p>
<pre><code>text a file = z
a
y
text b file = s
x
d
text c file = 1
3
2
</code></pre>
<p>so there are a,b,c te... | 0 | 2016-09-28T08:43:06Z | 39,742,633 | <p>Your <code>combine</code> variable is a list of tuples. Join each tuple (<code>item</code>) and write to file</p>
<pre><code>zzzz.write(" ".join(item))
</code></pre>
<p>A bit shorten and DRY version of your code:</p>
<pre><code>files = ["text1", "text2", "text3"]
groups = []
for each_file in files:
with open(... | 1 | 2016-09-28T08:59:54Z | [
"python"
] |
Efficiently collect links in dataframe | 39,742,275 | <p>Say I have a dataframe of type</p>
<pre><code>individual, location, food
1 A a
1 A b
1 B a
1 A c
2 C a
2 C b
</code></pre>
<p>where individuals are creating links between location an... | 0 | 2016-09-28T08:43:39Z | 39,744,079 | <p>You can pick up some efficiency by using numpy's <code>meshgrid</code>. </p>
<pre><code>import itertools
import numpy as np
def foo(group):
list1 = group.location.unique()
list2 = group.food.unique()
return pd.DataFrame(data=list(itertools.product(list1, list2)), columns=['location', 'food'])
def bar(g... | 2 | 2016-09-28T09:56:19Z | [
"python",
"pandas"
] |
Python check if any part of string in list | 39,742,438 | <p>I have a list containing synonyms for the word 'Good' (this list here is shortened)</p>
<pre><code>good_synonym = ['Good','good','Well','well']
</code></pre>
<p>And the program asks how the user is feeling</p>
<pre><code>print = 'Hello, ' + name + ', How are you?'
status = raw_input('')
</code></pre>
<p>But some... | 0 | 2016-09-28T08:50:46Z | 39,742,512 | <p>Instead of a list with mixed-case words, use <a href="https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset" rel="nofollow"><em>set</em> objects</a>; sets make membership testing and intersection testing much easier. Store <em>lowercase text</em> only, and simply lowercase the input string:</p>
<p... | 7 | 2016-09-28T08:54:06Z | [
"python"
] |
Python check if any part of string in list | 39,742,438 | <p>I have a list containing synonyms for the word 'Good' (this list here is shortened)</p>
<pre><code>good_synonym = ['Good','good','Well','well']
</code></pre>
<p>And the program asks how the user is feeling</p>
<pre><code>print = 'Hello, ' + name + ', How are you?'
status = raw_input('')
</code></pre>
<p>But some... | 0 | 2016-09-28T08:50:46Z | 39,742,553 | <p>There are many ways you could try to do this. Since you are a beginner, let's just go for something that will work - efficiency should NOT be your first consideration.</p>
<pre><code>status = status.split() # breaks response into words
if any(s in good_synonyms for s in status):
print('That is good')
</code></p... | 1 | 2016-09-28T08:56:14Z | [
"python"
] |
Python check if any part of string in list | 39,742,438 | <p>I have a list containing synonyms for the word 'Good' (this list here is shortened)</p>
<pre><code>good_synonym = ['Good','good','Well','well']
</code></pre>
<p>And the program asks how the user is feeling</p>
<pre><code>print = 'Hello, ' + name + ', How are you?'
status = raw_input('')
</code></pre>
<p>But some... | 0 | 2016-09-28T08:50:46Z | 39,742,645 | <p>This is a NLP question, the following code is a simple version of detecting synonym:</p>
<pre><code>def is_contains_synonym(sentence, synonym):
token = sentence.split(' ')
return len(filter(lambda x: x in synonym, token)) > 0
if is_contains_synonym(status, good_synonym):
print ('That is good')
else:... | -1 | 2016-09-28T09:00:37Z | [
"python"
] |
Python check if any part of string in list | 39,742,438 | <p>I have a list containing synonyms for the word 'Good' (this list here is shortened)</p>
<pre><code>good_synonym = ['Good','good','Well','well']
</code></pre>
<p>And the program asks how the user is feeling</p>
<pre><code>print = 'Hello, ' + name + ', How are you?'
status = raw_input('')
</code></pre>
<p>But some... | 0 | 2016-09-28T08:50:46Z | 39,743,032 | <p>Simple!</p>
<p>We can iterate over the good_synonyms list and check if <em>any</em> of them are present in the input string.</p>
<pre><code>if any(synonym in status for synonym in good_synonyms):
print('That is good')
else:
print('That is not so good')
</code></pre>
<p>PS: To save memory, you could perhap... | 0 | 2016-09-28T09:17:29Z | [
"python"
] |
Python check if any part of string in list | 39,742,438 | <p>I have a list containing synonyms for the word 'Good' (this list here is shortened)</p>
<pre><code>good_synonym = ['Good','good','Well','well']
</code></pre>
<p>And the program asks how the user is feeling</p>
<pre><code>print = 'Hello, ' + name + ', How are you?'
status = raw_input('')
</code></pre>
<p>But some... | 0 | 2016-09-28T08:50:46Z | 39,743,088 | <p>A short and simple solution would be to use regular expressions for pattern matching like this:</p>
<pre><code>import re
line = "it is good"
good_synonyms = ["good","well"]
line = line.lower()
if any(re.search(synonym,line) for synonym in good_synonyms):
print "That is good"
else:
print "nope"
</code></pr... | -1 | 2016-09-28T09:19:07Z | [
"python"
] |
Database migration from Sybase to MySQL: " error calling Python module function DbSQLAnywhereRE.reverseEngineer" | 39,742,624 | <p>I'm trying to migrate a database from <a href="https://en.wikipedia.org/wiki/Sybase" rel="nofollow">Sybase</a> to <a href="http://en.wikipedia.org/wiki/MySQL" rel="nofollow">MySQL</a> with the <a href="https://en.wikipedia.org/wiki/MySQL_Workbench" rel="nofollow">MySQL Workbench</a> migration tool.</p>
<p>I have no... | 2 | 2016-09-28T08:59:34Z | 39,786,003 | <p>That's because of SQL to get table names. Look at db_sqlanywhere_re_grt.py:142, there is:</p>
<pre><code>SELECT st.table_name
FROM SYSTAB st LEFT JOIN SYSUSER su ON st.creator=su.user_id
WHERE su.user_name = '%s' AND st.table_type = 1
</code></pre>
<p>This is valid sql for sql anywhere version < 10, and I guess... | 0 | 2016-09-30T07:29:12Z | [
"python",
"mysql",
"mysql-workbench",
"database-migration"
] |
Sort tenors in finance notation | 39,742,758 | <p>I have an array of tenors</p>
<pre><code>Tenors = np.array(['10Y', '15Y', '1M', '1Y', '20Y', '2Y', '30Y', '3M', '5Y', '6M', '9M'])
</code></pre>
<p>where <code>M</code> stands for month and <code>Y</code> stands for years. The correctly sorted order (ascending) would then be</p>
<pre><code>['1M', '3M', '6M', '9M'... | 1 | 2016-09-28T09:05:22Z | 39,742,934 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow"><code>str.extract</code></a> for parsing numbers and values, then convert to <code>int</code> and <code>categories</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.... | 1 | 2016-09-28T09:13:02Z | [
"python",
"sorting",
"pandas",
"numpy",
"finance"
] |
Sort tenors in finance notation | 39,742,758 | <p>I have an array of tenors</p>
<pre><code>Tenors = np.array(['10Y', '15Y', '1M', '1Y', '20Y', '2Y', '30Y', '3M', '5Y', '6M', '9M'])
</code></pre>
<p>where <code>M</code> stands for month and <code>Y</code> stands for years. The correctly sorted order (ascending) would then be</p>
<pre><code>['1M', '3M', '6M', '9M'... | 1 | 2016-09-28T09:05:22Z | 39,742,986 | <pre><code>print sorted(Tenors, key=lambda Tenors: (Tenors[-1], int(Tenors[:-1])))
</code></pre>
<p>Sorts by the last character and then by the integer value up to the last character</p>
| 1 | 2016-09-28T09:15:29Z | [
"python",
"sorting",
"pandas",
"numpy",
"finance"
] |
Sort tenors in finance notation | 39,742,758 | <p>I have an array of tenors</p>
<pre><code>Tenors = np.array(['10Y', '15Y', '1M', '1Y', '20Y', '2Y', '30Y', '3M', '5Y', '6M', '9M'])
</code></pre>
<p>where <code>M</code> stands for month and <code>Y</code> stands for years. The correctly sorted order (ascending) would then be</p>
<pre><code>['1M', '3M', '6M', '9M'... | 1 | 2016-09-28T09:05:22Z | 39,743,085 | <p><strong>Approach #1</strong> Here's a NumPy based approach using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.core.defchararray.replace.html#numpy.core.defchararray.replace" rel="nofollow"><code>np.core.defchararray.replace</code></a> -</p>
<pre><code>repl = np.core.defchararray.replace
out = ... | 1 | 2016-09-28T09:18:58Z | [
"python",
"sorting",
"pandas",
"numpy",
"finance"
] |
Sort tenors in finance notation | 39,742,758 | <p>I have an array of tenors</p>
<pre><code>Tenors = np.array(['10Y', '15Y', '1M', '1Y', '20Y', '2Y', '30Y', '3M', '5Y', '6M', '9M'])
</code></pre>
<p>where <code>M</code> stands for month and <code>Y</code> stands for years. The correctly sorted order (ascending) would then be</p>
<pre><code>['1M', '3M', '6M', '9M'... | 1 | 2016-09-28T09:05:22Z | 39,752,239 | <p>I opted for the long solution since I needed <code>convert_tenors</code> anyway. This also solves <a href="http://stackoverflow.com/questions/39742758/sort-tenors-in-finance-notation/39752239#comment66797667_39742758">Jim's objection</a>.</p>
<pre><code>import scipy
def convert_tenors(tenors):
#convert tenors ... | 0 | 2016-09-28T15:51:15Z | [
"python",
"sorting",
"pandas",
"numpy",
"finance"
] |
Calculating weighted moving average using pandas Rolling method | 39,742,797 | <p>I calculate simple moving average:</p>
<pre><code>def sma(data_frame, length=15):
# TODO: Be sure about default values of length.
smas = data_frame.Close.rolling(window=length, center=False).mean()
return smas
</code></pre>
<p>Using the rolling function is it possible to calculate weighted moving avera... | 0 | 2016-09-28T09:07:06Z | 39,744,105 | <p>Yeah, that part of pandas really isn't very well documented. I think you might have to use rolling.apply() if you aren't using one of the standard window types. I poked at it and got this to work:</p>
<pre><code>>>> import numpy as np
>>> import pandas as pd
>>> d = pd.DataFrame({'a':rang... | 1 | 2016-09-28T09:57:29Z | [
"python",
"pandas",
"moving-average",
"weighted-average",
"technical-indicator"
] |
How to limit number of digits after decimal point in python random | 39,742,893 | <p>I am using this code:<code>newAgent = [random.gauss(0, 1), random.gauss(0, 1)]</code>
and I want to limit the number of digits after decimal point.now is about 20 digits.</p>
| -5 | 2016-09-28T09:11:42Z | 39,800,725 | <p>The answer is quite simple. Just use <code>round</code> and then specify the places with <code>, #Number of spaces</code>. In this example, I did to 5 decimal spaces.</p>
<pre><code>import random
newAgent = [random.gauss(0, 1), random.gauss(0, 1)]
print(round(newAgent[0], 5), round(newAgent[1], 5))
</code></pre>
| 0 | 2016-09-30T22:06:13Z | [
"python"
] |
Python keeps crashing when I'm deploying with google app engine | 39,743,002 | <p>I'm running a static server on google app engine. I have been able to deploy a couple of times, but now it keeps crashing and it says</p>
<p><strong>Python quit unexpectedly.</strong></p>
<p>You can find my log on this URL: <a href="https://gist.github.com/rickbrunstedt/39a949016ca8bae46bad07395175a3e5" rel="nofol... | 1 | 2016-09-28T09:16:15Z | 39,882,370 | <p>It appears that this might be related to <a href="https://code.google.com/p/google-cloud-sdk/issues/detail?id=1168" rel="nofollow">a known issue in the gcloud Public Issue Tracker</a>. Please follow the thread there for updates, and attempt the suggested workaround: </p>
<pre><code>gcloud config set app/num_file_up... | 1 | 2016-10-05T19:42:49Z | [
"python",
"google-app-engine",
"gcloud"
] |
Sphinx matlab documentation error: missing module 'std' | 39,743,024 | <p>I'm trying to document my MATLAB classes using sphinx. But whenever I want to run <code>make html</code> I get the following error:</p>
<pre><code>% make html
sphinx-build -b html -d _build/doctrees . _build/html
Running Sphinx v1.4.6
Extension error:
Could not import extension sphinxcontrib.matlab (exception: N... | 1 | 2016-09-28T09:16:58Z | 39,800,016 | <p>The extensions in the sphinx-contrib repository seem to be meant for Python 2. The import rules have changed in Python 3, therefore such errors can occur when Python 3 code is run with a Python 2 interpreter.</p>
<p>The solution is to install Sphinx and all its dependencies for Python 2. Your distribution might hav... | 1 | 2016-09-30T20:59:40Z | [
"python",
"matlab",
"python-3.x",
"python-sphinx"
] |
How to get quotas of AWS EC2 via boto3? | 39,743,071 | <p>I'm working on boto3 - SDK python for AWS.</p>
<p>How can I get AWS Service Limits via boto3 library like bellow:</p>
<p><a href="http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html" rel="nofollow">http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html</a></p>
| 1 | 2016-09-28T09:18:50Z | 39,743,928 | <p>Why not use <a href="https://awslimitchecker.readthedocs.io/en/latest/" rel="nofollow">awsLimitchecker</a>?
I use it to create a report every morning and send it to a slack group, where I monitor our current limits. Works really well.</p>
| 0 | 2016-09-28T09:51:38Z | [
"python",
"amazon-web-services",
"boto3"
] |
How to get quotas of AWS EC2 via boto3? | 39,743,071 | <p>I'm working on boto3 - SDK python for AWS.</p>
<p>How can I get AWS Service Limits via boto3 library like bellow:</p>
<p><a href="http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html" rel="nofollow">http://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html</a></p>
| 1 | 2016-09-28T09:18:50Z | 39,744,135 | <p>Some of those limits can be queried through <a href="http://boto3.readthedocs.io/en/latest/reference/services/ec2.html?highlight=describeaccountattributes#EC2.Client.describe_account_attributes" rel="nofollow">EC2.Client.describe_account_attributes()</a></p>
<blockquote>
<p><code>describe_account_attributes(**kwa... | 2 | 2016-09-28T09:58:41Z | [
"python",
"amazon-web-services",
"boto3"
] |
how to obtain your own channel ID on youtube, using python and youtube API? | 39,743,136 | <p>I was wondering how you can obtain your own channel ID using youtube API, or printing a list of the specific channelIDs from your user, since you can have multiple channels on your own user.(im using client_secrets)</p>
<p>i've been watchin alot of the documentation for youtube, but aint finding anything relevant f... | 0 | 2016-09-28T09:21:02Z | 39,743,677 | <p>Judging from <a href="https://developers.google.com/youtube/v3/docs/channels/list" rel="nofollow">the docs</a>, I'd say you're on the right track.</p>
<pre><code>channels_list = youtube.channels().list(mine=True)
</code></pre>
<p>Should return a list of your owned channels, if you're sending an authenticated <code... | 1 | 2016-09-28T09:42:16Z | [
"python",
"api",
"youtube",
"user",
"channel"
] |
How to create a list of functions for call in python | 39,743,194 | <p>My question is like this one here, but I don't understand.</p>
<p><a href="http://stackoverflow.com/questions/26881396/how-to-add-a-function-call-to-a-list#">How to add a function call to a list?</a></p>
<p>If I had approximately 10 commands, and they all served specific purposes, so they couldn't be modified, but... | 0 | 2016-09-28T09:23:13Z | 39,743,358 | <p>If you want to add it to the list without calling them, just refrain from calling them:</p>
<pre><code>command_list=[print_hello]
</code></pre>
<p>At the time you want to call them, call them:</p>
<pre><code>command_list[0]()
</code></pre>
<p>If you want something to happen by just doing <code>command_list[0]</c... | 4 | 2016-09-28T09:29:43Z | [
"python",
"list"
] |
Delete repeated columns of array keeping the order | 39,743,315 | <p>Is there a relatively simple way of removing columns of an (numpy) array and keeping the order of the columns?</p>
<p>As an example, consider this array:</p>
<pre><code>a = np.array([[2, 1, 1, 3],
[2, 1, 1, 3]])
</code></pre>
<p>where I would like column three to be removed such that:</p>
<pre><cod... | 1 | 2016-09-28T09:28:12Z | 39,743,586 | <p><strong>Approach #1</strong> Here's an approach using <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><code>broadcasting</code></a> -</p>
<pre><code>a[:,~np.triu((a[:,None,:] == a[...,None]).all(0),1).any(0)]
</code></pre>
<p>Sample run -</p>
<pre><code>In [115]: a
Out[115]:... | 1 | 2016-09-28T09:38:19Z | [
"python",
"arrays",
"numpy"
] |
Writing lines from input file to output file based on the order in a list | 39,743,368 | <p>I have an input data <code>input.dat</code> that looks like this:</p>
<pre><code>0.00 0.00
0.00 0.00
0.00 0.00
-0.28 1.39
-0.49 1.24
-0.57 1.65
-0.61 2.11
-0.90 1.73
-0.87 2.29
</code></pre>
<p>I have have a list denoting line numbers as follows:</p>
<pre><code>linenum = [7, 2, 6]
</code></pr... | 0 | 2016-09-28T09:30:02Z | 39,743,762 | <p>Store the values as you encounter them in a dictionary <code>d</code> with the keys denoting the line number and the value holding the line contents. Write them to the file with <code>writelines</code> according to the order of <code>linenum</code>. Use <code>enumerate(fileobj, 1)</code> to get a line number for eac... | 1 | 2016-09-28T09:45:35Z | [
"python",
"python-3.x",
"for-loop"
] |
Loop through Microsoft Access queries with Python | 39,743,376 | <p>I need to loop through some queries of a Microsoft Access database (mdb).
Is there a possibility to do so with Python? (I am not familiar with Python.)</p>
<p>I was thinking of creating a list with the query names and then loop through it.</p>
<p>So far I have this:</p>
<pre><code># Import system modules (ArcGIS,... | 0 | 2016-09-28T09:30:12Z | 39,749,327 | <blockquote>
<p>I was thinking of creating a list with the query names and then loop through it.</p>
</blockquote>
<p>That's certainly possible. For example.</p>
<pre class="lang-python prettyprint-override"><code>query_names = ['Query1', 'Query2']
for query_name in query_names:
sql = "SELECT * FROM [{}]".forma... | 1 | 2016-09-28T13:43:15Z | [
"python",
"loops",
"ms-access"
] |
Use of scipy sparse in ode solver | 39,743,402 | <p>I am trying to solve a differential equation system </p>
<p>x´=Ax with x(0) = f(x)</p>
<p>in python, where A indeed is a complex sparse matrix.</p>
<p>For now i have been solving the system using the scipy.integrate.complex_ode class in the following way.</p>
<pre><code>def to_solver_function(time,vector):
... | 0 | 2016-09-28T09:31:08Z | 39,753,110 | <p>How large and sparse is <code>A</code>?</p>
<p>It looks like <code>A</code> is just a constant in this function:</p>
<pre><code>def to_solver_function(time,vector):
sendoff = np.dot(A, np.transpose(vector))
return sendoff
</code></pre>
<p>Is <code>vector</code> 1d? Then <code>np.transpose(vector)</code> ... | 0 | 2016-09-28T16:35:56Z | [
"python",
"scipy",
"sparse-matrix",
"scientific-computing"
] |
Convert a ctypes int** to numpy 2 dimensional array | 39,743,432 | <p>I have a c++ implementation wrapped with SWIG and compiled to a module which can be used by python.</p>
<p>I am using ctypes to call the function with ctype arguments, int double etc.
The output of my_function(ctype args) is an int**, i.e. it's a multidimensional array.</p>
<p>How can I cast this into a 2D numpy ... | 1 | 2016-09-28T09:32:09Z | 39,749,730 | <p>I don't think this can be done on the Python side; it will have to be done within the C/C++ layer using NumPy's C-API interface (<code>PyArray_SimpleNewFromData</code> is the relevant function â see <a href="http://stackoverflow.com/questions/30357115/pyarray-simplenewfromdata-example">this answer</a> for some det... | 0 | 2016-09-28T13:58:39Z | [
"python",
"c++",
"arrays",
"numpy",
"swig"
] |
Convert a ctypes int** to numpy 2 dimensional array | 39,743,432 | <p>I have a c++ implementation wrapped with SWIG and compiled to a module which can be used by python.</p>
<p>I am using ctypes to call the function with ctype arguments, int double etc.
The output of my_function(ctype args) is an int**, i.e. it's a multidimensional array.</p>
<p>How can I cast this into a 2D numpy ... | 1 | 2016-09-28T09:32:09Z | 39,754,263 | <p>Using NumPy and <code>numpy.i</code>, this is quite easy</p>
<p>Interface header</p>
<pre><code>#pragma once
void fun(int** outArray, int* nRows, int* nCols);
</code></pre>
<p>Implementation</p>
<pre><code>#include "test.h"
#include <malloc.h>
void fun(int** outArray, int* nRows, int* nCols) {
int _nRows... | 0 | 2016-09-28T17:39:41Z | [
"python",
"c++",
"arrays",
"numpy",
"swig"
] |
Does importing a Python module affect performance? | 39,743,441 | <p>When searching for a solution, it's common to come across several methods. I often use the solution that most closely aligns with syntax I'm familiar with. But sometimes the far-and-away most upvoted solution involves importing a module new to me, as in <a href="http://stackoverflow.com/questions/613183/sort-a-pytho... | 0 | 2016-09-28T09:32:32Z | 39,743,737 | <p>Every bytecode in Python affects performance. However, unless that code is on a critical path and repeated a high number of times, the effect is so small as to not matter.</p>
<p>Using <code>import</code> consists of two distinct steps: loading the module (done just <em>once</em>), and binding names (where the impo... | 1 | 2016-09-28T09:44:31Z | [
"python",
"import",
"module"
] |
Searching for two or more words in string - Python Troubleshooting Program | 39,743,497 | <p>I know the code for searching words in a string that match to another string.</p>
<pre><code>if any(word in problem for word in keyword_virus):
#Some code her e.g. pc_virus()
</code></pre>
<p>But is there any code that would allow me to check if two or more words matched/or even any modifications to this code?... | 0 | 2016-09-28T09:34:38Z | 39,743,785 | <p>If I understand your question correctly, I'd rewrite the for loop to check every word in your checklist and append each match.</p>
<pre><code>matches = []
for word in check_list:
if word in problem_list:
matches.append(word)
</code></pre>
<p>You'll end up with a list of words that match, from which you can c... | 0 | 2016-09-28T09:46:25Z | [
"python",
"variables",
"if-statement",
"search"
] |
Searching for two or more words in string - Python Troubleshooting Program | 39,743,497 | <p>I know the code for searching words in a string that match to another string.</p>
<pre><code>if any(word in problem for word in keyword_virus):
#Some code her e.g. pc_virus()
</code></pre>
<p>But is there any code that would allow me to check if two or more words matched/or even any modifications to this code?... | 0 | 2016-09-28T09:34:38Z | 39,743,961 | <pre><code>keyword_virus = 'the brown fox jumps'
print([x for x in ['brown', 'jumps', 'notinstring'] if x in keyword_virus.split()])
#['brown', 'jumps']
</code></pre>
<p>That will return all matched words in keyword_virus.</p>
| 1 | 2016-09-28T09:52:52Z | [
"python",
"variables",
"if-statement",
"search"
] |
Unable to return the list that is read from a file(.csv) | 39,743,572 | <p>I have been learning and practicing python and during which
I found one error in my program, but I'm unable to resolve. I want to return list of that is retrieved from a csv file. I tried the below code and it returns me an error. </p>
<pre><code>import csv
def returnTheRowsInTheFile(fileName):
READ = 'r'
... | 1 | 2016-09-28T09:37:56Z | 39,743,764 | <p>When you use <code>with open</code> it closes the file when the context ends. Now <code>listOfRows</code> is of the return type of <code>csv.Reader</code>, and so is then <code>fullString</code> (not a list). You are trying to iterate on it, which seems to iterate over a file object, which is already closed.</p>
| 0 | 2016-09-28T09:45:42Z | [
"python",
"csv"
] |
Unable to return the list that is read from a file(.csv) | 39,743,572 | <p>I have been learning and practicing python and during which
I found one error in my program, but I'm unable to resolve. I want to return list of that is retrieved from a csv file. I tried the below code and it returns me an error. </p>
<pre><code>import csv
def returnTheRowsInTheFile(fileName):
READ = 'r'
... | 1 | 2016-09-28T09:37:56Z | 39,743,883 | <p>As JulienD already pointed the file is alread closed when you try to read the rows from it. You can get rid of this exception using this for example:</p>
<pre><code> with open(fileName, READ) as myFile:
listOfRows = csv.reader(myFile)
for row in listOfRows:
yield row
</code></pre>
<p... | 0 | 2016-09-28T09:50:13Z | [
"python",
"csv"
] |
Unable to return the list that is read from a file(.csv) | 39,743,572 | <p>I have been learning and practicing python and during which
I found one error in my program, but I'm unable to resolve. I want to return list of that is retrieved from a csv file. I tried the below code and it returns me an error. </p>
<pre><code>import csv
def returnTheRowsInTheFile(fileName):
READ = 'r'
... | 1 | 2016-09-28T09:37:56Z | 39,745,590 | <p>The easy way to solve this problem is to return a <em>list</em> from your function. I know you assigned <code>listOfRows = []</code> but this was overwritten when you did <code>listOfRows = csv.reader(myFile)</code>.</p>
<p>So, the easy solution is:</p>
<pre><code>def returnTheRowsInTheFile(fileName):
READ = '... | 1 | 2016-09-28T11:01:02Z | [
"python",
"csv"
] |
Tkinter checkbox 'Name not defined' | 39,743,579 | <p>I am currently writing an application that uses Tkinter to provide a graphical interface for the user.</p>
<p>The app has been working very well and recently I decided to add some checkboxes, the idea being that when the user checks one of the boxes, another set of text is sent through an API.</p>
<p>I have input ... | 0 | 2016-09-28T09:38:02Z | 39,743,685 | <p>You just need to make <code>check</code> an instance variable with <code>self</code>.</p>
<p>I.E</p>
<pre><code>class GUI:
def __init__(self, master):
self.check = IntVar()
self.e = Checkbutton(root, text="check me", variable=self.check)
self.e.grid(row=4, column=2)
self.mac... | 1 | 2016-09-28T09:42:31Z | [
"python",
"checkbox",
"tkinter"
] |
How do you make a leaderboard in python? | 39,743,789 | <p>I am working on a project for my school and I was wondering if there is a way to make a leaderboard in python? I am fairly new to python and so far, what I have done is get the user's input and store it in a text file. I'm not sure how to continue. Any help is appreciated, thanks!</p>
<pre><code>x = 0
Name = [None... | 1 | 2016-09-28T09:46:29Z | 39,744,679 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/version/0.18.1/tutorials.html" rel="nofollow">pandas</a> for making a leaderboard table. Here is a sample:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'Name': ['x','y','z'],
'Class': ['B','A','C'],
'Score' :... | 1 | 2016-09-28T10:20:17Z | [
"python"
] |
How to define namespace in python? | 39,743,847 | <p>It seems that python do have namespaces. But All I can get is people telling me what namespace or scope is. So how do you define a namespace in python? All I need is the syntax (and with an example would be much better). </p>
| -1 | 2016-09-28T09:48:53Z | 39,744,275 | <p>A "namespace" in Python is defined more by the layout of the code on disk than it is with any particular syntax. Given a directory structure of:</p>
<pre><code>my_code/
module_a/
__init__.py
a.py
b.py
module_b/
__init__.py
a.py
b.py
__init__.py
main.py... | 0 | 2016-09-28T10:04:06Z | [
"python"
] |
Sending long JSON via POST Python | 39,743,884 | <p>I know this seems fundamental, but how do we do it? For example,</p>
<pre><code>import urllib2
import ssl
import requests
import json
SetProxy={'https':'https://sample.sample.com'}
proxy = urllib2.ProxyHandler(SetProxy)
url="https://something.com/getsomething"
opener = urllib2.build_opener(proxy)
urllib2.install_o... | 0 | 2016-09-28T09:50:13Z | 39,744,351 | <p>try to use below :</p>
<pre><code>import json
import urllib2
import ssl
import requests
SetProxy={'https':'https://sample.sample.com'}
proxy = urllib2.ProxyHandler(SetProxy)
url='https://something.com/getsomething'
opener = urllib2.build_opener(proxy)
urllib2.install_opener(opener)
data = {
'uaaURL' : 'h... | -1 | 2016-09-28T10:07:01Z | [
"python",
"json"
] |
Automatically creating a list | 39,743,916 | <p>I am trying to automatically create the following list:</p>
<pre><code>[Slot('1A', '0', 0), Slot('2A', '0', 0),
Slot('1B', '0', 0], Slot ('2B,'0', 0), ....]
</code></pre>
<p>By defining slot as:</p>
<pre><code>class Slot:
def __init__(self, address , card, stat):
self.address = address
self.c... | 0 | 2016-09-28T09:51:14Z | 39,744,178 | <p>You have enclosed all arguments to <code>Slot</code> in a single parenthesis thereby passing a single argument to an <code>__init__</code> that expects three (and the <code>TypeError</code> raised hints to that). Remove the unnecessary set of parenthesis:</p>
<pre><code>board.append(Slot(str(i)+j,'0', 0))
</code></... | 2 | 2016-09-28T10:00:21Z | [
"python",
"python-3.x"
] |
Automatically creating a list | 39,743,916 | <p>I am trying to automatically create the following list:</p>
<pre><code>[Slot('1A', '0', 0), Slot('2A', '0', 0),
Slot('1B', '0', 0], Slot ('2B,'0', 0), ....]
</code></pre>
<p>By defining slot as:</p>
<pre><code>class Slot:
def __init__(self, address , card, stat):
self.address = address
self.c... | 0 | 2016-09-28T09:51:14Z | 39,744,485 | <p>You are passing a single tuple to the constructor. If you remove the parentheses, your code is golden.</p>
<pre><code>From:
board.append(Slot ((str(i)+j,'0', 0)))
To:
board.append(Slot(str(i)+j,'0', 0))
</code></pre>
| 0 | 2016-09-28T10:12:25Z | [
"python",
"python-3.x"
] |
I'm trying to use 2 data types on one variable in python? | 39,743,934 | <p>Im trying to get float data type available on my code. My code so far is;</p>
<pre><code>age = int (input("Age of the dog: "))
if age <= 0:
print ("This can not be true!")
elif age == 1:
print ("He/she is about 14 in human years.")
elif age == 2:
print ("He/she is about 22 in human years.")
elif age... | -2 | 2016-09-28T09:52:00Z | 39,744,075 | <p>If you change your first line to</p>
<pre><code>age = float(input("Age of the dog: "))
</code></pre>
<p>your program will show a floating point age.</p>
| 0 | 2016-09-28T09:56:09Z | [
"python"
] |
I'm trying to use 2 data types on one variable in python? | 39,743,934 | <p>Im trying to get float data type available on my code. My code so far is;</p>
<pre><code>age = int (input("Age of the dog: "))
if age <= 0:
print ("This can not be true!")
elif age == 1:
print ("He/she is about 14 in human years.")
elif age == 2:
print ("He/she is about 22 in human years.")
elif age... | -2 | 2016-09-28T09:52:00Z | 39,744,081 | <p>Try to use something like</p>
<pre><code> human = 22 + (age - 2) * 5.0
</code></pre>
<p>Multiplying by a float automatically converts to float.</p>
| -1 | 2016-09-28T09:56:21Z | [
"python"
] |
I'm trying to use 2 data types on one variable in python? | 39,743,934 | <p>Im trying to get float data type available on my code. My code so far is;</p>
<pre><code>age = int (input("Age of the dog: "))
if age <= 0:
print ("This can not be true!")
elif age == 1:
print ("He/she is about 14 in human years.")
elif age == 2:
print ("He/she is about 22 in human years.")
elif age... | -2 | 2016-09-28T09:52:00Z | 39,744,206 | <p>Since you didn't mention whether you want the age given is float or the output should be in float, I added both here :-)</p>
<p>For only "getting" floating point, your code will suffice. Except that the floating point number would be rounded off. If you do not want the number to be rounded, instead of <code>int(inp... | 1 | 2016-09-28T10:01:19Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.