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 |
|---|---|---|---|---|---|---|---|---|---|
How to use Selenium to get this index? | 38,538,032 | <p>I'm trying to retrieve the fear index from the link <a href="http://money.cnn.com/data/fear-and-greed/" rel="nofollow">http://money.cnn.com/data/fear-and-greed/</a>. The index is dynamically changing. When I inspect the element, it shows the coding below. I'm just wondering how to use python Selenium to get the 84 a... | 3 | 2016-07-23T04:02:35Z | 38,538,132 | <p>Try as below :-</p>
<pre><code>elements = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID,"needleChart"))).find_elements_by_tag_name("li")
for li in elements:
text = li.get_attribute("innerHTML")
s = ''.join(x for x in text if x.isdigit())
print(s)
</code></pre>
<p>Hope it helps...:)</... | 0 | 2016-07-23T04:21:09Z | [
"python",
"selenium"
] |
How do I initialize and fill in a list of lists of different lengths? | 38,538,264 | <p>I'm writing a small Python program that will simulate a certain TV show (it's for fun guys ok please don't judge me). </p>
<p>In this program, I am trying to randomly sort the contestants into a list of lists (to emulate a Team Challenge, as you may say). I wrote a function that (is intended) to take in an unsorted... | 1 | 2016-07-23T04:46:35Z | 38,538,334 | <pre><code>def sortIntoTeams(contest_obj, numTeams):
# Create a randomly-ordered copy of the contestants' names
random_contestants = [x.name for x in contest_obj]
random.shuffle(random_contestants)
result = []
for teamsize in numTeams:
# Take the first <teamsize> contestants from the l... | 0 | 2016-07-23T04:58:12Z | [
"python",
"arrays",
"list",
"sorting",
"python-3.x"
] |
How do I initialize and fill in a list of lists of different lengths? | 38,538,264 | <p>I'm writing a small Python program that will simulate a certain TV show (it's for fun guys ok please don't judge me). </p>
<p>In this program, I am trying to randomly sort the contestants into a list of lists (to emulate a Team Challenge, as you may say). I wrote a function that (is intended) to take in an unsorted... | 1 | 2016-07-23T04:46:35Z | 38,538,347 | <pre><code>def sortIntoTeams(contest_obj, numTeams):
counter = 0
teams = []
for k in numTeams:
teams.append(contest_obj[counter:counter + k])
counter = counter + k
return teams
</code></pre>
| 0 | 2016-07-23T05:02:00Z | [
"python",
"arrays",
"list",
"sorting",
"python-3.x"
] |
How to standard scale a large numpy matrix with sklearn? (batch processing) | 38,538,376 | <p>I am working in a classification problem with gradient boosting. As usual before classifiying I would like to scale my feature matrix (<code>878049, 3208</code>). </p>
<pre><code>A = LabelEncoder().fit_transform(training_data['col1'].values.reshape(-1, 1).ravel())
B = LabelEncoder().fit_transform(training_data['col... | 0 | 2016-07-23T05:07:37Z | 38,544,754 | <p>The <a href="http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html#sklearn.preprocessing.StandardScaler.partial_fit" rel="nofollow">docs</a> of <code>partial_fit</code> explain what's happening. The following is the relevant part: </p>
<blockquote>
<p>partial_fit(X, y=None) </... | 2 | 2016-07-23T17:41:39Z | [
"python",
"numpy",
"scipy",
"scikit-learn"
] |
Python filter numbers within optional bounds (use less if-else) | 38,538,386 | <p>I want to select elements from list of numbers within lower and upper bounds, each of which is optional. I can write it as a series of if and else for all possible cases. Can we reduce these branching and write in a concise way?</p>
<pre><code>def select_within_bounds(li, lower=None, upper=None):
if lower is No... | 3 | 2016-07-23T05:10:43Z | 38,538,397 | <p>You know the answer when the numeric bounds are always present. So, you can first derive the bounds and then apply the same logic. That is:</p>
<pre><code>def select_within_bounds(li, lower=None, upper=None):
lower = min(li) if lower is None else lower
upper = max(li) if upper is None else upper
return... | 0 | 2016-07-23T05:13:14Z | [
"python",
"if-statement"
] |
Python filter numbers within optional bounds (use less if-else) | 38,538,386 | <p>I want to select elements from list of numbers within lower and upper bounds, each of which is optional. I can write it as a series of if and else for all possible cases. Can we reduce these branching and write in a concise way?</p>
<pre><code>def select_within_bounds(li, lower=None, upper=None):
if lower is No... | 3 | 2016-07-23T05:10:43Z | 38,538,420 | <p>Yes you can, using python's <a href="https://docs.python.org/2/library/functions.html#filter" rel="nofollow">filter</a> built-in function. Like so:</p>
<pre><code>def select_within_bounds(li, lower=None, upper=None):
return filter(lambda x: (x if lower is None else lower) <= x <= (x if upper is None else ... | 3 | 2016-07-23T05:16:49Z | [
"python",
"if-statement"
] |
Python filter numbers within optional bounds (use less if-else) | 38,538,386 | <p>I want to select elements from list of numbers within lower and upper bounds, each of which is optional. I can write it as a series of if and else for all possible cases. Can we reduce these branching and write in a concise way?</p>
<pre><code>def select_within_bounds(li, lower=None, upper=None):
if lower is No... | 3 | 2016-07-23T05:10:43Z | 38,538,676 | <pre><code>def select_within_bounds(li, lower=float('-inf'), upper=float('inf')):
return [v for v in li if lower <= v <= upper]
</code></pre>
| 3 | 2016-07-23T05:55:42Z | [
"python",
"if-statement"
] |
Why do we use format identifier python | 38,538,406 | <p>I am a beginner and learning Python. My question is python can read a variable in a string without format identifier, then why has format identifiers been provided for?</p>
<p>Ex:</p>
<pre><code>carPoolTotal = 4
print "We have total", carPoolTotal, "people in carpooling."
print "We have total %d people in carpool... | 0 | 2016-07-23T05:15:01Z | 38,538,432 | <p>Format identifiers help if you want to provide non-default formatting for your values. For example, you might want to format a long decimal as a decimal with a maximum of two decimal places.</p>
| 2 | 2016-07-23T05:18:23Z | [
"python",
"python-2.7"
] |
Subtracting a fixed date from a column in Pandas | 38,538,479 | <p>Consider </p>
<pre><code>In [99]: d = pd.to_datetime({'year':[2016], 'month':[06], 'day':[01]})
In [100]: d1 = pd.to_datetime({'year':[2016], 'month':[01], 'day':[01]})
In [101]:d - d1
Out[101]:
0 152 days
dtype: timedelta64[ns]
</code></pre>
<p>But when I try to do this for a whole column, it gives me trouble... | 2 | 2016-07-23T05:26:19Z | 38,538,945 | <p>You don't need to use map*, you can subtract a Timestamp from a datetime column/Series:</p>
<pre><code>In [11]: d = pd.to_datetime({'year':[2016], 'month':[6], 'day':[1]})
In [12]: d
Out[12]:
0 2016-06-01
dtype: datetime64[ns]
In [13]: d[0] # This is the Timestamp you are actually interested in subtracting
Out... | 2 | 2016-07-23T06:37:04Z | [
"python",
"pandas"
] |
Password: Invalid password format or unknown hashing algorithm even after setting in the create user function | 38,538,491 | <p>I have a custom user model:</p>
<pre><code>class CustomUserManager(BaseUserManager):
def _create_user(self, email, username, password, first_name, last_name, date_of_birth, gender, mobile_number,
is_active, is_admin, is_superuser):
if not email:
raise ValueError('Email m... | 1 | 2016-07-23T05:28:08Z | 38,908,989 | <p>i was also getting the same issue while calling create method of my custom model <code>Account</code> , <code>Account.objects.create(
username='demo',email='demo12@demo.com',
password='prakashsharma24#')</code></p>
<p>I have just used <strong>create_user</strong> method and go the result </p>
<pre><code>Account.ob... | 0 | 2016-08-12T02:35:38Z | [
"python",
"django",
"django-models",
"django-forms",
"django-admin"
] |
Python odeint- Initial condition y0 must be one-dimensional | 38,538,584 | <p>I am trying to simulate a dynamic system in state space form with odeint.
My A matrix is 12*12 and B matrix is 12*4 (rows * cols) so my initial state vector is 12*1 as it suggests.</p>
<p>My code is as follows </p>
<pre><code>import numpy as np
from scipy.integrate import odeint
tmp = np.loadtxt("system.txt", ski... | 0 | 2016-07-23T05:43:08Z | 38,541,683 | <p>Ive got the answer and thought of sharing it here with the hope that someone with the same problem in the future will benefit.</p>
<p>odeint seems to expect 1d array as an state variable to call the function and 1d array return from the function as well.</p>
<p>So I reshaped the variables accordingly. here is the ... | 0 | 2016-07-23T12:15:30Z | [
"python",
"odeint"
] |
How to run a webserver script on remote server through SSH? | 38,538,592 | <p>I am currently hosting a couple servers on my AWS EC2 Ubuntu 14.04 server. By default, the server doesn't have a GUI, but I installed one along with xRDP.</p>
<p>If I run the script from the terminal, it will continuously run <strong>until</strong> the terminal is closed. <strong>But</strong>, if I run the script b... | -2 | 2016-07-23T05:44:05Z | 38,538,831 | <p>What I use for things like this is the <code>screen</code> command putting my command in a disconnected screen session. I can connect to it later if I need to.</p>
| 0 | 2016-07-23T06:20:29Z | [
"python",
"ubuntu",
"ssh",
"amazon-ec2",
"server"
] |
Sklearn Spectral Clustering error in fit_predict : k must be between 1 and the order of the square input matrix | 38,538,608 | <p>I'm using <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.SpectralClustering.html" rel="nofollow">Spectral Clustering Library</a> in Python and similarity matrix is its main argument. My matrix looks like:</p>
<pre><code>[[ 1. 0.85018854 0.85091491 0.85717652]
[ 0.85018854 1. ... | -2 | 2016-07-23T05:45:55Z | 38,546,342 | <p>You have 4 data points.</p>
<p>You request 4 clusters.</p>
<p>What do you expect to happen?</p>
<p>There is only the trivial solution (every point is different) so spectral clustering refuses to run. For sensible solutions, the number of clusters must be at least 2, and at most n-1 if you have n points, obviously... | 1 | 2016-07-23T20:55:47Z | [
"python",
"numpy",
"matrix",
"scikit-learn",
"cluster-analysis"
] |
When I visit django Project WebPage, the log remind me:not found favicon | 38,538,615 | <p>Why django project receive favicon request?<br></p>
<p>like this<br>
<strong>Not Found: /favicon.ico<br>
[23/Jul/2016 11:37:11] "GET /favicon.ico HTTP/1.1" 404 1941</strong></p>
<p>Where did the request come from?</p>
<p>I find request from my browser.<br>
Can I control it? How to close it?<br>
Thanks eve... | -3 | 2016-07-23T05:47:12Z | 38,552,949 | <p>Please collect all your static data using "python manage.py collectstatic" </p>
<p>If you have already done that, make sure favicon.ico is part of static directory</p>
| 0 | 2016-07-24T14:12:49Z | [
"python",
"django",
"favicon"
] |
TensorFlow Returning nan When Implementing Logistic Regression | 38,538,635 | <p>I've been trying to implement Logistic Regression in TensorFlow following the MNIST example but with data from a CSV. Each row is one sample and has 12 dimensions. My code is the following:</p>
<pre><code>batch_size = 5
learning_rate = .001
x = tf.placeholder(tf.float32,[None,12])
y = tf.placeholder(tf.float32,[Non... | 2 | 2016-07-23T05:49:57Z | 38,538,835 | <p>The issue you are having is because log(pred) is not defined for pred = 0. The "hacky" way around this is to use <code>tf.maximum(pred, 1e-15)</code> or <code>tf.clip_by_value(pred, 1e-15, 1.0)</code>.</p>
<p>An even better solution, however, is using <code>tf.nn.softmax_cross_entropy_with_logits(pred)</code> inste... | 2 | 2016-07-23T06:20:49Z | [
"python",
"numpy",
"tensorflow",
"logistic-regression"
] |
Cannot see my web application using Docker container | 38,538,651 | <p>I am trying to test my web application using a docker container, but I am not able to see it when I try to access it through my browser.</p>
<p>The docker compose file looks like </p>
<pre><code>version: '2'
services:
db:
image: postgres
volumes:
- ~/pgdata:/var/lib/postgresql/data/pgdata
envir... | -1 | 2016-07-23T05:51:56Z | 38,538,778 | <p>I had to enable external visibility for my flask application.
You can see it here
<a href="http://stackoverflow.com/questions/30554702/cant-connect-to-flask-web-service-connection-refused">Can't connect to Flask web service, connection refused</a></p>
| 0 | 2016-07-23T06:12:12Z | [
"python",
"web-applications",
"docker",
"flask",
"docker-compose"
] |
django float or decimal are rounded unintentionally when saving | 38,538,773 | <p>I want to save latitude and longitude in Place model.
I tried two fields, floatfield and decimalfield.</p>
<h1>1. FloatField model</h1>
<pre><code>class Place1(models.Model):
latitude = models.FloatField()
longitude = models.FloatField()
</code></pre>
<h1>2. DecimalField model</h1>
<pre><code>class Place... | 3 | 2016-07-23T06:11:17Z | 38,540,062 | <p>You can not find 'unintentional rounding' in django docs because django is not the culprit here.</p>
<p>Its the MYSQL that does the rounding when your column data type is Float. </p>
<blockquote>
<p>For maximum portability, code requiring storage of approximate numeric data values should use <strong>FLOAT</stron... | 1 | 2016-07-23T09:06:22Z | [
"python",
"django",
"floating-point",
"decimal",
"latitude-longitude"
] |
possible unique combinations between between two arrays(of different size) in python? | 38,538,786 | <pre><code>arr1=['One','Two','Five'],arr2=['Three','Four']
</code></pre>
<p>like <code>itertools.combinations(arr1,2)</code> gives us <br><code>('OneTwo','TwoFive','OneFive')</code><br>
I was wondering is there any way applying this to two different arrays.?I mean for arr1 and arr2.</p>
<p><code>Output should be One... | 2 | 2016-07-23T06:13:48Z | 38,538,848 | <p>If all you wanted is <code>OneThree,OneFour,TwoThree,TwoFour,FiveThree,FiveFour</code> then a double <code>for</code> loop will do the trick for you:</p>
<pre><code>>>> for x in arr1:
for y in arr2:
print(x+y)
OneThree
OneFour
TwoThree
TwoFour
FiveThree
FiveFour
</code></pre>
<p>Or i... | 1 | 2016-07-23T06:22:45Z | [
"python",
"arrays",
"python-3.x",
"python-3.4",
"itertools"
] |
possible unique combinations between between two arrays(of different size) in python? | 38,538,786 | <pre><code>arr1=['One','Two','Five'],arr2=['Three','Four']
</code></pre>
<p>like <code>itertools.combinations(arr1,2)</code> gives us <br><code>('OneTwo','TwoFive','OneFive')</code><br>
I was wondering is there any way applying this to two different arrays.?I mean for arr1 and arr2.</p>
<p><code>Output should be One... | 2 | 2016-07-23T06:13:48Z | 38,538,867 | <p>You are looking for <a href="https://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow"><code>.product()</code></a>:</p>
<p>From the doc, it does this:</p>
<pre><code>product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
</co... | 2 | 2016-07-23T06:26:27Z | [
"python",
"arrays",
"python-3.x",
"python-3.4",
"itertools"
] |
possible unique combinations between between two arrays(of different size) in python? | 38,538,786 | <pre><code>arr1=['One','Two','Five'],arr2=['Three','Four']
</code></pre>
<p>like <code>itertools.combinations(arr1,2)</code> gives us <br><code>('OneTwo','TwoFive','OneFive')</code><br>
I was wondering is there any way applying this to two different arrays.?I mean for arr1 and arr2.</p>
<p><code>Output should be One... | 2 | 2016-07-23T06:13:48Z | 38,538,868 | <pre><code>["".join(v) for v in itertools.product(arr1, arr2)]
#results in
['OneThree', 'OneFour', 'TwoThree', 'TwoFour', 'FiveThree', 'FiveFour']
</code></pre>
| 1 | 2016-07-23T06:26:49Z | [
"python",
"arrays",
"python-3.x",
"python-3.4",
"itertools"
] |
How to swap blue and green channel in an image using OpenCV | 38,538,952 | <p>I am facing a little bit of problem in swapping the channels (specifically red and blue) of an image. I am using Opencv 3.0.0 and Python 2.7.12. Following is my code for swapping the channels</p>
<pre><code>import cv2
img = cv2.imread("input/car1.jpg")
#The obvious approach
Cimg = cv2.cvtColor(img, cv2.COLOR_BGR2... | 0 | 2016-07-23T06:37:54Z | 38,539,027 | <p><code>red</code> and <code>blue</code> are just views of your image. When you do <code>img[:,:,0] = red</code> this changes <code>img</code> but also <code>blue</code> which is just a view (basically just a reference to the sub-array <code>img[:,:,0]</code>) not a copy, so you loose the original blue channel values.... | 1 | 2016-07-23T06:50:29Z | [
"python",
"opencv"
] |
Modifying PDF (compatible with Acrobat 6.0 and higher) by objects shuffling | 38,538,963 | <p>I'm trying to get PDF file, with changed order of objects (index is not changed, only location of objects inside file).
After then, I'm making new xref stream with new offsets of objects</p>
<p>I implemented the program in Python, but produced file is always damaged.</p>
<p>Questions:</p>
<ol>
<li>How to make fil... | -1 | 2016-07-23T06:40:08Z | 38,567,624 | <p>As you neither show your code nor describe the nature of the damage to the result file (let alone share sample original and reordered files), it is difficult to help you.</p>
<blockquote>
<ol>
<li>How to make file unlinearized? Currently, I'm removing linearisation object from file and its xref-entry</li>
</o... | 0 | 2016-07-25T12:20:52Z | [
"python",
"pdf"
] |
dask distributed memory error | 38,539,044 | <p>I got the following error on the scheduler while running Dask on a distributed job:</p>
<pre><code>distributed.core - ERROR -
Traceback (most recent call last):
File "/usr/local/lib/python3.4/dist-packages/distributed/core.py", line 269, in write
frames = protocol.dumps(msg)
File "/usr/local/lib/python3.4/d... | 1 | 2016-07-23T06:52:23Z | 38,542,459 | <p>The most common cause of this error is trying to collect too much data, such as occurs in the following example using dask.dataframe:</p>
<pre><code>df = dd.read_csv('s3://bucket/lots-of-data-*.csv')
df.compute()
</code></pre>
<p>This loads all of the data into RAM across the cluster (which is fine), and then trie... | 0 | 2016-07-23T13:43:39Z | [
"python",
"dask"
] |
sympy Matrices within a sympy Matrix remains unevaluated on substitution | 38,539,095 | <p>While my issue seems linked to the sympy github issue <a href="https://github.com/sympy/sympy/issues/6557" rel="nofollow">here</a>, it either doesn't seem directly related, or remains an open, unsolved issue (from 2012).</p>
<p>My issue is that I have a 'matrix' (really, it's just a vector but is my only option due... | 1 | 2016-07-23T06:58:33Z | 38,579,076 | <p><code>doit</code> will evaluate the expression</p>
<pre><code>In [9]: print(m.subs({l_syms:sympy.Matrix([[1,1,1]])}).doit())
Matrix([[0.391482321650262, 0.261165517803277, 0.142349217414644], [0.273871679444907, 0.753721446526393, 0.915204734923647], [0.689284430582533, 0.509755263016457, 0.828178833602631], [0.258... | 1 | 2016-07-25T23:51:50Z | [
"python",
"matrix",
"lazy-evaluation",
"sympy",
"substitution"
] |
Groupby Aggregate method is returning NaN always | 38,539,204 | <p>Hi I am running into this issue where my datasource events looks like this:</p>
<pre><code> event_id device_id timestamp longitude latitude
0 1 29182687948017175 2016-05-01 00:55:25 121.38 31.24
1 2 -6401643145415154744 2016-05-01 00:54:12 103.65 30.... | 3 | 2016-07-23T07:14:12Z | 38,539,407 | <p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.transform.html" rel="nofollow">pandas.core.groupby.GroupBy.transform(aggfunc)</a> method, which applies <code>aggfunc</code> to all rows in each group:</p>
<pre><code>In [32]: events['latitude_mean'] = events.grou... | 2 | 2016-07-23T07:40:16Z | [
"python",
"pandas"
] |
django - Cannot login with the user credentials | 38,539,318 | <p>I have a custom user model and its user manager.</p>
<pre><code>class CustomUserManager(BaseUserManager):
def _create_user(self, email, username, password, first_name, last_name, date_of_birth, gender, mobile_number,
is_active, is_admin, is_superuser):
"""
Creates and saves ... | 0 | 2016-07-23T07:28:40Z | 38,539,669 | <p>If you are trying to login to the admin site, make sure your new user has admin privileges </p>
<p><code>is_admin=True</code></p>
| 1 | 2016-07-23T08:15:47Z | [
"python",
"django",
"django-models",
"django-forms",
"django-admin"
] |
Sort list of dicts by sub-key value | 38,539,381 | <p>I have following list of dictionaries:</p>
<pre><code>test_list = [
{'sr_no': 1, 'recipe_type': 'Main Dish', 'name': 'Salmon & Brown Rice'},
{'sr_no': 2, 'recipe_type': 'Side Dish', 'name': 'Cupcakes'},
{'sr_no': 3, 'recipe_type': 'Main Dish', 'name': 'Whole chicken'},
{'sr_no... | 0 | 2016-07-23T07:37:31Z | 38,539,415 | <p>You can pass <code>key</code> function that returns <code>name</code> from each dict to <a href="https://docs.python.org/3.5/library/functions.html#sorted" rel="nofollow"><code>sorted</code></a>:</p>
<pre><code>>>> import pprint
>>> test_list = [
... {'sr_no': 1, 'recipe_type': 'Main Dish'... | 2 | 2016-07-23T07:41:15Z | [
"python",
"python-2.7",
"dictionary"
] |
How to save data in a for loop by Python | 38,539,393 | <p>I am new in Python programming. I want to save the field output request </p>
<p><code>[mdb.models['Model-1'].fieldOutputRequests['F-Output-1'].setValues(variables=('S', 'U', 'SF'))]</code></p>
<p>as a text file for each loop j by changing boundary displacement.
Can anybody help me regrading this issue?
I have att... | -4 | 2016-07-23T07:38:56Z | 38,539,935 | <p>The basics to creating a file is:</p>
<pre><code>file = open("newfile.txt", "w")
file.write("This is your first line")
file.write("This is your second line")
file.close()
</code></pre>
<p>In this case:</p>
<pre><code>file = open("newfile.txt", "w")
for j in range(len(A1)):
to_write = mdb.models['Model-1'].fieldOu... | 0 | 2016-07-23T08:50:28Z | [
"python",
"stack-overflow"
] |
What is the difference between these os.popen calls? | 38,539,445 | <p>I have two scripts:</p>
<p>The first works well:</p>
<pre><code>import os
os.popen(âgrep abc filenameâ)
</code></pre>
<p>The second does not work:</p>
<pre><code>import os
os.popen(âgrep abcâ + âfilenameâ)
</code></pre>
<p>But this does:</p>
<pre><code>os.popen(âgrep abc filenameâ + â>â ... | 0 | 2016-07-23T07:44:49Z | 38,539,506 | <p>You forgot the space after <code>abc</code> in the second version. It should be</p>
<pre><code>import os
os.popen(âgrep abc â + âfilenameâ)
</code></pre>
<p>i.e. <code>abc˽'</code> vs <code>abc'</code>.</p>
| 1 | 2016-07-23T07:53:26Z | [
"python"
] |
Object (simple shapes) Detection in Image | 38,539,503 | <p>I've got the following image. </p>
<p><a href="http://i.stack.imgur.com/Xxzjk.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/Xxzjk.jpg" alt="enter image description here"></a> </p>
<p><a href="http://imgur.com/a/UXYTq" rel="nofollow">Other Samples</a></p>
<p>I want to detect the six square-shaped green p... | 2 | 2016-07-23T07:53:07Z | 38,539,627 | <p>What you did was manually analyze the values you need for thresholding for a specific image, and then apply that. What you see is that analysis done on one image doesn't necessarily fit other images. </p>
<p>The solution is to do the analysis automatically for each image. This can be achieved by creating a histog... | 1 | 2016-07-23T08:10:01Z | [
"python",
"opencv",
"image-processing"
] |
How to handle complexType arguments in python soap module zeep? | 38,539,568 | <p>Zeep documentation example :</p>
<pre><code>from zeep import Client
client = Client('http://my-enterprise-endpoint.com')
client.service.submit_order(user_id=1, order={
'number': '1234',
'price': 99,
})
</code></pre>
<p>My use case :</p>
<p>I want to call a webservice that needs a parameter 'findCriteria'... | 1 | 2016-07-23T08:02:12Z | 39,154,496 | <p>Inspect your wsdl with following command:
<code>python -mzeep <wsdl></code></p>
<p>You will find details of your service in the output: <code>ns1:GetCount(FindCriteria:findCriteria)</code></p>
<p>Sample code based on above inspection output:</p>
<pre><code>find_criteria_type = client.get_type('ns1:findC... | 0 | 2016-08-25T20:48:21Z | [
"python",
"web-services",
"soap"
] |
How to handle complexType arguments in python soap module zeep? | 38,539,568 | <p>Zeep documentation example :</p>
<pre><code>from zeep import Client
client = Client('http://my-enterprise-endpoint.com')
client.service.submit_order(user_id=1, order={
'number': '1234',
'price': 99,
})
</code></pre>
<p>My use case :</p>
<p>I want to call a webservice that needs a parameter 'findCriteria'... | 1 | 2016-07-23T08:02:12Z | 39,272,059 | <p>I had a similar problem and I managed to solve it, but to help you I need either a sample correct XML (how it should look like) or at least a default request generated using SoapUI. </p>
<p>In the meantime, perhaps the code below might help you:
Here the complex argument was credentials and it consisted of 2 login... | 0 | 2016-09-01T12:51:08Z | [
"python",
"web-services",
"soap"
] |
For loop outout numbers to a string | 38,539,581 | <p>Well i just wrote a code that get's a starting number, ending number and a step (it's a range) and prints all numbers in bettwen.
It works great but i want the output to be also as a string.</p>
<p>This is my code:</p>
<pre><code>def count(num1,num2,steps):
getfirstnum=int(raw_input(num1))
getsecondenum=in... | -3 | 2016-07-23T08:03:35Z | 38,539,615 | <p>Try this:</p>
<pre><code>def whatever(start, stop):
result = ''
for num in range(start,stop):
result += str(num)
return result
print(whatever(0,5))
</code></pre>
<hr>
<pre><code>01234
</code></pre>
| 1 | 2016-07-23T08:08:15Z | [
"python",
"string",
"function",
"for-loop"
] |
For loop outout numbers to a string | 38,539,581 | <p>Well i just wrote a code that get's a starting number, ending number and a step (it's a range) and prints all numbers in bettwen.
It works great but i want the output to be also as a string.</p>
<p>This is my code:</p>
<pre><code>def count(num1,num2,steps):
getfirstnum=int(raw_input(num1))
getsecondenum=in... | -3 | 2016-07-23T08:03:35Z | 38,539,619 | <pre><code>def count(num1,num2,steps):
string_output = ""
getfirstnum=int(raw_input(num1))
getsecondenum=int(raw_input(num2))
getsteps=int(raw_input(steps))
for num in range(getfirstnum,getsecondenum,getsteps):
string_output += str(num)
return string_output
</code></pre>
| 1 | 2016-07-23T08:08:28Z | [
"python",
"string",
"function",
"for-loop"
] |
For loop outout numbers to a string | 38,539,581 | <p>Well i just wrote a code that get's a starting number, ending number and a step (it's a range) and prints all numbers in bettwen.
It works great but i want the output to be also as a string.</p>
<p>This is my code:</p>
<pre><code>def count(num1,num2,steps):
getfirstnum=int(raw_input(num1))
getsecondenum=in... | -3 | 2016-07-23T08:03:35Z | 38,539,806 | <pre><code>...
print 'in bettwen: ' + str(num)
...
</code></pre>
<p>Or if you are looking for something different like:</p>
<pre><code>string = 'in bettwen: '
for num in range(getfirstnum,getsecondenum,getsteps):
string += " " + str(num)
return num
</code></pre>
| 0 | 2016-07-23T08:33:02Z | [
"python",
"string",
"function",
"for-loop"
] |
For loop outout numbers to a string | 38,539,581 | <p>Well i just wrote a code that get's a starting number, ending number and a step (it's a range) and prints all numbers in bettwen.
It works great but i want the output to be also as a string.</p>
<p>This is my code:</p>
<pre><code>def count(num1,num2,steps):
getfirstnum=int(raw_input(num1))
getsecondenum=in... | -3 | 2016-07-23T08:03:35Z | 38,544,173 | <p>Use <code>join</code> and a generator:</p>
<pre><code>>>> ''.join(str(n) for n in range(1,10,2))
'13579'
</code></pre>
<p>This is the equivalent of:</p>
<pre><code>>>> s = ''
>>> for n in range(1,10,2):
... s += str(n)
...
>>> s
'13579'
</code></pre>
| 0 | 2016-07-23T16:47:07Z | [
"python",
"string",
"function",
"for-loop"
] |
Killing a process within a python script running on linux | 38,539,607 | <p>I have Raspbian as the linux distro running on my RPI. I've setup a small socket server using twisted and it receives certain commands from an iOS app. These commands are strings. I started a process when I received "st" and now I want to kill it when i get "sp". This is the way I tried:</p>
<ol>
<li>Imported OS </... | 0 | 2016-07-23T08:07:01Z | 38,539,621 | <p>You will need to escape the quotes in your string:</p>
<pre><code>os.system('ps axf | grep xyz | grep -v grep | awk \'{print "kill " $1 }\' | sh')
</code></pre>
<p>Or use a triple quote:</p>
<pre><code>os.system('''ps axf | grep xyz | grep -v grep | awk '{print "kill " $1 }' | sh''')
</code></pre>
| 0 | 2016-07-23T08:09:17Z | [
"python",
"linux",
"bash",
"shell",
"awk"
] |
Killing a process within a python script running on linux | 38,539,607 | <p>I have Raspbian as the linux distro running on my RPI. I've setup a small socket server using twisted and it receives certain commands from an iOS app. These commands are strings. I started a process when I received "st" and now I want to kill it when i get "sp". This is the way I tried:</p>
<ol>
<li>Imported OS </... | 0 | 2016-07-23T08:07:01Z | 38,539,711 | <p>Alternatively, open the process with <code>Popen(...).pid</code> and then use <code>os.kill()</code> </p>
<pre><code>my_pid = Popen('/home/rolf/test1.sh',).pid
os.kill(int(my_pid), signal.SIGKILL)
</code></pre>
<p>Remember to include a shebang in your script (#!/bin/sh)</p>
<p>Edit:
On second thoughts, perhaps... | 0 | 2016-07-23T08:21:04Z | [
"python",
"linux",
"bash",
"shell",
"awk"
] |
How can I get Skyfield to agree with the Nautical Almanac for the Sun's Declination? | 38,539,625 | <p>Here's a sample script that calculates the sun's declination on 2016/7/23 at 00:00:00 GMT using both PyEphem and Skyfield:</p>
<pre><code>import ephem
sun1 = ephem.Sun('2016/7/23 00:00:00')
dec1 = sun1.dec
print 'PyEphem Declination:', dec1
#-------------------------------------
from skyfield.api import load
pl... | 1 | 2016-07-23T08:09:46Z | 38,588,860 | <p>The answer that PyEphem is giving you is in exact agreement with the almanac, but expressed in traditional hours-minutes-seconds of arc instead of in hours and decimal minutes. The fraction <code>.4</code> that is part of the minutes-of-arc quantity <code>1.4</code> becomes, if expressed as arcseconds, 60 Ã 0.4 = 2... | 0 | 2016-07-26T11:37:12Z | [
"python",
"pyephem",
"skyfield"
] |
Managing sessions when scraping with Requests library in python | 38,539,676 | <p>I am having trouble creating and keeping new sessions when I am scraping my page. I am initiating a session within my script using the Requests library and then parsing values to a web form. However, it's is returning a "Your session has timed out" page.</p>
<p>Here is my source:</p>
<pre><code>import requests
se... | 0 | 2016-07-23T08:16:26Z | 38,555,884 | <p>First, I would refer you to the advanced documentation related to use of sessions within the <code>requests</code> Python module.</p>
<p><a href="http://docs.python-requests.org/en/master/user/advanced/" rel="nofollow">http://docs.python-requests.org/en/master/user/advanced/</a></p>
<p>I also notice that navigatin... | 0 | 2016-07-24T19:24:55Z | [
"python",
"asp.net",
"python-requests",
"screen-scraping",
"robobrowser"
] |
StratifiedKFold output handling | 38,539,780 | <p>I have a series with 20 rows and 60 columns i.e 20 examples each with 60 parameters.</p>
<p>kfold = StratifiedKFold(y=encoded_Y, n_folds=10, shuffle=True, random_state=seed)
<a href="http://i.stack.imgur.com/8B3or.png" rel="nofollow">The output consists of two columns</a></p>
<p>I would like to know what does the ... | 1 | 2016-07-23T08:30:06Z | 38,540,179 | <p>As with all of the cross validators in <a href="http://scikit-learn.org/stable/modules/classes.html#module-sklearn.cross_validation" rel="nofollow"><code>sklearn.cross_validation</code></a> this is an iterator over pairs of indices. In each pair, the first item is the list of train indices, and the second item is th... | 0 | 2016-07-23T09:24:13Z | [
"python",
"machine-learning",
"scikit-learn",
"cross-validation"
] |
Abort and restart batch execution | 38,539,848 | <p>I have a python program that I run with a batch-file to store all the launch parameters. The program runs in an endless loop. I'd like to abort the python loop after 10 minutes and restart the python program again. How can I achieve this in a bat-file? Are there better solutions?
Calls, quits and exits don't seem to... | -1 | 2016-07-23T08:38:46Z | 38,540,349 | <p>Show your code....
Can get better help that way.
Try <code>Taskkill /?</code> or <code>timeout /?</code>, and <code>start</code>.
For example:
<code>Taskkill /IM notepad.exe /F
timeout 10 >nul
start notepad.exe</code></p>
| 0 | 2016-07-23T09:43:37Z | [
"python",
"loops",
"batch-file",
"execution"
] |
Abort and restart batch execution | 38,539,848 | <p>I have a python program that I run with a batch-file to store all the launch parameters. The program runs in an endless loop. I'd like to abort the python loop after 10 minutes and restart the python program again. How can I achieve this in a bat-file? Are there better solutions?
Calls, quits and exits don't seem to... | -1 | 2016-07-23T08:38:46Z | 38,540,388 | <pre><code>:test
python <your script>
taskkill /F /IM python.exe /T
goto:test
</code></pre>
<p>You can do it in the above way, but it is good to do everything in python using while loops.</p>
| 0 | 2016-07-23T09:47:38Z | [
"python",
"loops",
"batch-file",
"execution"
] |
Evaluating multiple conditions in if-then-else block in a Pandas DataFrame | 38,539,910 | <p>I want to create a new column in a Pandas DataFrame by evaluating multiple conditions in an if-then-else block. </p>
<pre><code>if events.hour <= 6:
events['time_slice'] = 'night'
elif events.hour <= 12:
events['time_slice'] = 'morning'
elif events.hour <= 18:
events['time_slice'] = 'afternoon'... | 1 | 2016-07-23T08:46:49Z | 38,539,947 | <p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html" rel="nofollow">pd.cut()</a> method in order to categorize your data:</p>
<p>Demo:</p>
<pre><code>In [66]: events = pd.DataFrame(np.random.randint(0, 23, 10), columns=['hour'])
In [67]: events
Out[67]:
hour
0 5
1 ... | 3 | 2016-07-23T08:52:21Z | [
"python",
"pandas",
"dataframe",
"conditional"
] |
Evaluating multiple conditions in if-then-else block in a Pandas DataFrame | 38,539,910 | <p>I want to create a new column in a Pandas DataFrame by evaluating multiple conditions in an if-then-else block. </p>
<pre><code>if events.hour <= 6:
events['time_slice'] = 'night'
elif events.hour <= 12:
events['time_slice'] = 'morning'
elif events.hour <= 18:
events['time_slice'] = 'afternoon'... | 1 | 2016-07-23T08:46:49Z | 38,539,980 | <p>You could create a function:</p>
<pre><code>def time_slice(hour):
if hour <= 6:
return 'night'
elif hour <= 12:
return 'morning'
elif hour <= 18:
return 'afternoon'
elif hour <= 23:
return 'evening'
</code></pre>
<p>then <code>events['time_slice'] = event... | 2 | 2016-07-23T08:55:23Z | [
"python",
"pandas",
"dataframe",
"conditional"
] |
Evaluating multiple conditions in if-then-else block in a Pandas DataFrame | 38,539,910 | <p>I want to create a new column in a Pandas DataFrame by evaluating multiple conditions in an if-then-else block. </p>
<pre><code>if events.hour <= 6:
events['time_slice'] = 'night'
elif events.hour <= 12:
events['time_slice'] = 'morning'
elif events.hour <= 18:
events['time_slice'] = 'afternoon'... | 1 | 2016-07-23T08:46:49Z | 38,540,072 | <p>Here's a NumPy approach to it -</p>
<pre><code>tags = ['night','morning','afternoon','evening']
events['time_slice'] = np.take(tags,((events.hour.values-1)//6).clip(min=0))
</code></pre>
<p>Sample run -</p>
<pre><code>In [130]: events
Out[130]:
hour time_slice
0 0 night
1 8 morning
2 16 af... | 2 | 2016-07-23T09:08:25Z | [
"python",
"pandas",
"dataframe",
"conditional"
] |
Extraction of different views of a pixel from 3D volumetric data | 38,539,911 | <p>I have 3D CT data. I want to extract three different patches centering a particular pixel corresponding to three 3 different views (axial, coronal, sagittal). Can anyone please tell me how to do that in python?</p>
| -3 | 2016-07-23T08:46:56Z | 38,705,878 | <p>If your volume is I and the point that you want to extract the patch around it is x0,yo,zo and the patch size is p than</p>
<pre><code>I[xo,y0-p/2:y0+p/2,z0-p/2:z0+p/2] = Pach1
I[xo-p/2:x0+p/2,y0-p/2:y0+p/2,z0] = Pach2
I[xo-p/2:x0+p/2,y0,z0-p/2:z0+p/2] = Pach3
</code></pre>
| 0 | 2016-08-01T18:40:06Z | [
"python",
"python-2.7",
"computer-vision"
] |
How to create directory in django media file (best way)? | 38,539,946 | <p>I want to save downloaded images to a path that like so: media/images/[user.pk]/ directly from urlretrieve from urllib library is that possible and what is the most elegant way? </p>
<p>This are the used code snippets:</p>
<ul>
<li><p>here I use urlretrieve with path like .../media/images/[user.pk]/[filename.jpg]<... | 0 | 2016-07-23T08:52:01Z | 38,540,103 | <p>I solved a problem like so:</p>
<pre><code>def save_image_from_url(self, image_url):
if self.profile_image_url != image_url or not os.path.isfile(self.profile_image.path):
if not os.path.exists(get_image_path(self, os.path.join(MEDIA_ROOT, get_image_path(
self, '')))):
... | 0 | 2016-07-23T09:12:21Z | [
"python",
"django",
"urllib",
"file-not-found"
] |
Named colors in tkinter | 38,539,993 | <p>How can I get a list of all named colors in tkinter? I need to choose colors randomly and print their names to the user.</p>
<p>I found a list of all colors here: <a href="http://stackoverflow.com/questions/4969543/colour-chart-for-tkinter-and-tix-using-python">Colour chart for Tkinter and Tix Using Python</a>
I wo... | 1 | 2016-07-23T08:56:39Z | 38,541,020 | <p>In case of linux (debian) there is a file <em>/etc/X11/rgb.txt</em> that has lines like </p>
<pre><code>255 250 250 snow
</code></pre>
<p>and should be easy to parse. Your program could read color definitions from that file (or a copy of it) to a list, and then select a random color from that list.</p>... | 1 | 2016-07-23T11:02:34Z | [
"python",
"colors",
"tkinter"
] |
Python-String parsing for extraction of date and time | 38,540,016 | <p>The datetime is given in the format <strong>YY-MM-DD HH:MM:SS</strong> in a dataframe.I want new Series of <strong>year,month and hour</strong> for which I am trying the below code.
But the problem is that Month and Hour are getting the same value,Year is fine.</p>
<p>Can anyone help me with this ? I am using Iptho... | 1 | 2016-07-23T08:59:41Z | 38,540,052 | <p>you can use <code>.dt</code> accessors instead: <code>train['datetime'].dt.month</code>, <code>train['datetime'].dt.year</code>, <code>train['datetime'].dt.hour</code> (see the full list below)</p>
<p>Demo:</p>
<pre><code>In [81]: train = pd.DataFrame(pd.date_range('2016-01-01', freq='1999H', periods=10), columns=... | 1 | 2016-07-23T09:05:32Z | [
"python",
"datetime",
"numpy",
"pandas"
] |
AttributeError: 'module' object has no attribute 'login' | 38,540,033 | <pre><code>import gspread
gc = gspread.login(âthe.email.address@gmail.comâ,âpasswordâ)
</code></pre>
<p>AttributeError: 'module' object has no attribute 'login'</p>
| -8 | 2016-07-23T09:01:42Z | 38,540,085 | <p>The <a href="https://github.com/burnash/gspread" rel="nofollow"><code>gsspread</code></a> that I know of doesn't have the <code>login</code> method! </p>
<p>I guess what you are looking for is <code>authorize</code>.</p>
<p>You would ideally do something like this:</p>
<pre><code>import gspread
gc = gspread.autho... | 0 | 2016-07-23T09:09:48Z | [
"python",
"gspread"
] |
Symbolic definition of a binomial using SymPy | 38,540,092 | <p>I am trying to symbolically define the Binomial function using Sympy.
My first attempt was as follows:</p>
<pre><code>import numpy as np
import scipy.stats as st
import sklearn.linear_model as lm
import matplotlib.pyplot as plt
import sympy as sp
sp.interactive.printing.init_printing(use_latex=True)
n = sp.Symbol... | 2 | 2016-07-23T09:11:09Z | 38,540,536 | <p><code>cNkLambda</code> is a SymPy expression which is defined in terms of <code>n</code> and <code>r</code>.
It's not a function, so do not call it with <code>cNkLambda(n,r)</code>. <code>binomLambda</code> can then be defined by:</p>
<pre><code>binomLambda = cNkLambda*((theta **r)*(1-theta)**(n-r))
</code></pre>
... | 1 | 2016-07-23T10:06:01Z | [
"python",
"sympy"
] |
Efficient way to pass system properties in python 3 | 38,540,208 | <p>I'm using python 3 for an application. For that utility, I need to pass command line arguments as following, </p>
<pre><code>python3 -m com.xxx.executor -Denvironment=dev -Dtoggle=False
</code></pre>
<p>Both the parameter <code>environment</code> and <code>toggle</code> are present in a property file too. If the ... | 1 | 2016-07-23T09:27:23Z | 38,541,556 | <p>For argument parsing, I use the <code>argparse</code> module (<a href="https://docs.python.org/3.5/library/argparse.html#module-argparse" rel="nofollow">docs</a>) to define which are valid named and/or positional arguments. </p>
<p>There are third-party modules as well such as <a href="http://click.pocoo.org/5/" re... | 0 | 2016-07-23T12:00:39Z | [
"python",
"python-2.7",
"python-3.x"
] |
Efficient way to pass system properties in python 3 | 38,540,208 | <p>I'm using python 3 for an application. For that utility, I need to pass command line arguments as following, </p>
<pre><code>python3 -m com.xxx.executor -Denvironment=dev -Dtoggle=False
</code></pre>
<p>Both the parameter <code>environment</code> and <code>toggle</code> are present in a property file too. If the ... | 1 | 2016-07-23T09:27:23Z | 38,541,926 | <p>From <a href="https://docs.python.org/3.4/using/cmdline.html#cmdoption-X" rel="nofollow">the docs on -X args</a></p>
<blockquote>
<p>Reserved for various implementation-specific options. CPython currently defines the following possible values:</p>
</blockquote>
<p>That means you probably shouldn't be hijacking t... | 0 | 2016-07-23T12:43:33Z | [
"python",
"python-2.7",
"python-3.x"
] |
(flask) python mysql - how to pass selected data though a for loop and return it? | 38,540,256 | <p>In my Flask project, I want to select everything from a table in database and print each row in separate line?</p>
<p>How should I pass data through a for loop in this script below?</p>
<p>And how can I return it?</p>
<p>In app.py:</p>
<pre><code>from flask import Flask, render_template
import MySQLdb
app = Fla... | 0 | 2016-07-23T09:30:55Z | 38,540,354 | <p>Try something like this:</p>
<pre><code>row=cursor.fetchone()
while row is not None:
print row
# you can access to each column by looping over row
# for column in row:
# print row
row=cursor.fetchone()
</code></pre>
| 0 | 2016-07-23T09:43:48Z | [
"python",
"mysql",
"select",
"flask",
"connection"
] |
(flask) python mysql - how to pass selected data though a for loop and return it? | 38,540,256 | <p>In my Flask project, I want to select everything from a table in database and print each row in separate line?</p>
<p>How should I pass data through a for loop in this script below?</p>
<p>And how can I return it?</p>
<p>In app.py:</p>
<pre><code>from flask import Flask, render_template
import MySQLdb
app = Fla... | 0 | 2016-07-23T09:30:55Z | 38,540,504 | <p>Normally, <a href="https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-fetchall.html" rel="nofollow"><code>cursor.fetchall()</code></a> returns a list of tuples, so just save that list into a variable and <code>return</code> it, then loop through the returned value, this way</p>
<pre><cod... | 1 | 2016-07-23T10:03:09Z | [
"python",
"mysql",
"select",
"flask",
"connection"
] |
(flask) python mysql - how to pass selected data though a for loop and return it? | 38,540,256 | <p>In my Flask project, I want to select everything from a table in database and print each row in separate line?</p>
<p>How should I pass data through a for loop in this script below?</p>
<p>And how can I return it?</p>
<p>In app.py:</p>
<pre><code>from flask import Flask, render_template
import MySQLdb
app = Fla... | 0 | 2016-07-23T09:30:55Z | 38,544,717 | <p>Use an ORM like Flask-SQLAlchemy, Define your table using the model class and then use it to fetch data</p>
<pre><code>class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(128))
body = db.Column(db.Text)
def __init__(self, title, body):
self.title = title
... | 0 | 2016-07-23T17:38:03Z | [
"python",
"mysql",
"select",
"flask",
"connection"
] |
Access only links with given format from a python list | 38,540,391 | <p>I have written a code that fetches the html code of any given site and then fetch all links from it and save it inside a list. My goal is that I want to change all the relative links in html file with absolute links. </p>
<p>Here are the links:</p>
<pre><code>src="../styles/scripts/jquery-1.9.1.min.js"
href="/Phon... | 0 | 2016-07-23T09:47:44Z | 38,551,020 | <p>How about using <code>str.count</code> method:</p>
<pre><code>>>> src="../styles/scripts/jquery-1.9.1.min.js"
>>> src2='../../images/plus.png'
>>> src.count('../')
1
>>> src2.count('../')
2
</code></pre>
<p>This seems to be true as <code>../</code> only exists at the beginning o... | 1 | 2016-07-24T10:25:59Z | [
"python",
"html",
"regex",
"python-3.x"
] |
Difficulties with my python tic-tac-toe | 38,540,394 | <p>I am following Charles Dierbach's book, Introduction to Computer Science using Python.</p>
<p>I am on chapter 5. I am trying to do this exercise on tic-tac-toe automate play.</p>
<p>I am having difficulties creating a function for the pc to select an empty box ([]). </p>
<p>Here is my code</p>
<pre><code>import ... | 0 | 2016-07-23T09:48:23Z | 38,540,616 | <blockquote>
<p>My current for loop does not work. AI only selects the first box.</p>
</blockquote>
<p>I suppose you refer to this part:</p>
<pre><code>def pc_player(lst):
print()
print ("PC symbol is 'O'. ")
alpha = ("A", "B", "C")
num_list = (0, 1, 2)
for i in range(0, len(lst)):
for ... | 1 | 2016-07-23T10:15:22Z | [
"python",
"function",
"for-loop",
"artificial-intelligence",
"tic-tac-toe"
] |
Difficulties with my python tic-tac-toe | 38,540,394 | <p>I am following Charles Dierbach's book, Introduction to Computer Science using Python.</p>
<p>I am on chapter 5. I am trying to do this exercise on tic-tac-toe automate play.</p>
<p>I am having difficulties creating a function for the pc to select an empty box ([]). </p>
<p>Here is my code</p>
<pre><code>import ... | 0 | 2016-07-23T09:48:23Z | 38,540,617 | <p>Start by finding all empty boxes:</p>
<pre><code>empty= [(i,j) for i in range(len(lst)) for j in range(len(lst[i])) if lst[i][j]==[]]
</code></pre>
<p>Then choose a random one:</p>
<pre><code>import random
chosen_i, chosen_j= random.choice(empty)
</code></pre>
<p>And finally put an <code>O</code> there:</p>
<pr... | 0 | 2016-07-23T10:15:35Z | [
"python",
"function",
"for-loop",
"artificial-intelligence",
"tic-tac-toe"
] |
Overwrite previous output in jupyter notebook | 38,540,395 | <p>Let's assume I have a part of code that runs for some specific amount of time and each 1 second outputs something like this: <code>iteration X, score Y</code>. I will substitute this function with my black box function:</p>
<pre><code>from random import uniform
import time
def black_box():
i = 1
while True... | 2 | 2016-07-23T09:48:28Z | 38,541,614 | <p>The usual (documented) way to do what you describe (that only works with Python 3) is:</p>
<pre><code>print('Iteration', i, 'Score:', uniform(0, 1), end='\r')
</code></pre>
<p>In Python 2 we have to <code>sys.stdout.flush()</code> after the print, as it shows in this <a href="http://stackoverflow.com/a/11018255/27... | 1 | 2016-07-23T12:07:12Z | [
"python",
"jupyter",
"jupyter-notebook"
] |
Why do python Subprocess.stdin.write() kill PyQt Gui | 38,540,410 | <p>I have a PyQt5 app that need to write input for the subprocess to stop.</p>
<p>However it also kills my PyQt5 <code>Mainwindow</code>, if input button is used without using subprocess button first.</p>
<p>If i use subprocess button first, and then use input button , with <code>self.bob.stdin.write("b")</code> app ... | 0 | 2016-07-23T09:50:53Z | 38,540,547 | <p>Without understanding all your code, here's what I think your code converted into a script does:</p>
<pre><code>import subprocess
from subprocess import Popen, PIPE
# sub button handler
bob = subprocess.Popen('echo',stdin=PIPE, shell=True)
# input button handler
bob.stdin.write(b"text")
</code></pre>
<p>I'll let... | 0 | 2016-07-23T10:08:11Z | [
"python",
"pyqt",
"subprocess"
] |
Python N-body simulation code giving incorrect answer | 38,540,415 | <p>I have written some python code to solve the N-body problem using the Euler method. The code runs without problems and seems to give a reasonable answer (e.g. if there are two particles then the start moving towards each other). However when I run this simulation over a large number of iterations I see that the part... | 4 | 2016-07-23T09:51:29Z | 38,541,134 | <p>The main problem in the code is that it uses the Euler method which is quite inaccurate as the number of iterations increase (just O(h) compared to other methods which can be O(h^4) or even better). To fix this would require a fundamental restructure of the code and so I would say that this code is not really accura... | 1 | 2016-07-23T11:14:54Z | [
"python",
"matplotlib",
"physics"
] |
Open Power Shell as Admin on remote VM | 38,540,424 | <p>I have a python that uses pyvmomi library of VMWare to perform operations on remote VM.
I open the remote VM cmd prompt using Pyvmomi library like this </p>
<pre><code>vim.vm.guest.ProcessManager.ProgramSpec(
programPath="C:\\Windows\\System32\\cmd.exe")
</code></pre>
<p>Is there any way to open Power She... | 0 | 2016-07-23T09:52:17Z | 38,546,433 | <p>You have to run the powershell script as administrator:</p>
<p><a href="http://stackoverflow.com/a/25247612/1763602">http://stackoverflow.com/a/25247612/1763602</a></p>
<p>You can create another script that will launch your script with elevated privileges.</p>
| 0 | 2016-07-23T21:08:11Z | [
"python",
"windows",
"powershell",
"admin",
"pyvmomi"
] |
picking dl directory w/ youtube_dl | 38,540,473 | <p>Using youtube_dl, I'm writing an interface tool that downloads video.</p>
<p>I import youtube_dl and run,</p>
<pre><code>with youtube_dl.YoutubeDL(opts) as ydl:
ydl.download([address])
</code></pre>
<p>However I remain uncertain as to how I specify download directory using youtube_dl alone. What is the op... | 0 | 2016-07-23T09:59:10Z | 38,540,830 | <p>As documented in the <a href="https://github.com/rg3/youtube-dl/blob/master/README.md#embedding-youtube-dl" rel="nofollow">embedding instructions</a> of youtube-dl, you can find the list of all options in <a href="https://github.com/rg3/youtube-dl/blob/master/youtube_dl/YoutubeDL.py#L129-L279" rel="nofollow">Youtube... | 1 | 2016-07-23T10:39:09Z | [
"python",
"youtube-dl"
] |
Anyone know how to set group volume in soco (python)? | 38,540,517 | <p>I am trying to set group volume in soco (python) for my Sonos speakers. It is straightforward to set individual speaker volume but I have not found any way to set volume on group level (without iterating through each speaker setting the volume individually). Any idea to do this?</p>
| 0 | 2016-07-23T10:04:11Z | 38,955,622 | <p>you can easily iterate over the group, and change all their volumes, for example to increate the volume on all speakers by 5:</p>
<p>for each_speaker in my_zone.group:
each_speaker.volume += 5</p>
<p>(assuming my_zone is you speaker object)</p>
| 0 | 2016-08-15T13:02:54Z | [
"python",
"sonos"
] |
Determine protocol of the link using Python alternatives | 38,540,629 | <p>I need to find out the best way to determine what protocol is used to access a particular link. The input: string link address (starting with <code>protocol://...</code>)</p>
<p>This is what I find the most convenient way to implement the necessary functionality:</p>
<pre><code>def detectProtocol(url):
ind = u... | 2 | 2016-07-23T10:17:05Z | 38,540,745 | <p>You could use regex for that (<code>r'^[a-zA-Z]+://'</code>), and compile it before checking if it is valid or not.</p>
<p>But you have a built-in functions for that:</p>
<pre><code>import urlparse
url = urlparse.urlparse('https://www.wwww.com')
print url.scheme
</code></pre>
<p>Output:</p>
<pre><code>>>&g... | 1 | 2016-07-23T10:29:06Z | [
"python",
"regex",
"parsing"
] |
Determine protocol of the link using Python alternatives | 38,540,629 | <p>I need to find out the best way to determine what protocol is used to access a particular link. The input: string link address (starting with <code>protocol://...</code>)</p>
<p>This is what I find the most convenient way to implement the necessary functionality:</p>
<pre><code>def detectProtocol(url):
ind = u... | 2 | 2016-07-23T10:17:05Z | 38,541,040 | <p>If you're looking for a cross-python version solution:</p>
<pre><code>try:
import urlparse
except ImportError:
import urllib.parse as urlparse
url = urlparse.urlparse('https://www.example.com')
print(url.scheme)
</code></pre>
<p>You can add <code>from __future__ import print_function</code> to the top of... | 1 | 2016-07-23T11:04:57Z | [
"python",
"regex",
"parsing"
] |
Determine protocol of the link using Python alternatives | 38,540,629 | <p>I need to find out the best way to determine what protocol is used to access a particular link. The input: string link address (starting with <code>protocol://...</code>)</p>
<p>This is what I find the most convenient way to implement the necessary functionality:</p>
<pre><code>def detectProtocol(url):
ind = u... | 2 | 2016-07-23T10:17:05Z | 38,541,042 | <h1>Performance comparison</h1>
<p>This comparison ignores stability of the functions used and other aspects like synergetic effects. <code>urlparse</code> for example provides more information than only the scheme and could hence be used to provide data for other needs.</p>
<h3>Python 2.7.11+</h3>
<pre><code>Testin... | 4 | 2016-07-23T11:05:13Z | [
"python",
"regex",
"parsing"
] |
Cause of slow Scrapy scraper | 38,540,708 | <p><b>I have created a new scrapy spider that is extremely slow.</b> It only scrapes around two pages per second, whereas the other Scrapy crawlers that I have created have been crawling a lot faster.</p>
<p>I was wondering what is it that could cause this issue, and how to possibly fix that. The code is not much diff... | 0 | 2016-07-23T10:24:56Z | 38,547,649 | <p>There are only two potential reasons, given that your spiders indicate that you're quite careful/experienced.</p>
<ol>
<li>Your target site's response time is very low</li>
<li>Every page has only 1-2 listing pages (the ones that you parse with <code>parse_stuff()</code>).</li>
</ol>
<p>Highly likely the latter is... | 0 | 2016-07-24T00:37:06Z | [
"python",
"web-scraping",
"scrapy",
"web-crawler",
"scrapy-spider"
] |
Python: Beautiful Soup: Can't grab a full title from parsing | 38,540,799 | <p>I am attempting to practice scraping by going to a video website, and scraping all the titles of the videos on the homepage. My only issue is, if the title is too long, it gets cut short using the .string function in BeautifulSoup. </p>
<p>Here is example HTML for parsing:</p>
<pre class="lang-html prettyprint-ove... | 0 | 2016-07-23T10:35:41Z | 38,541,033 | <p>I've figured out my problem, I found it in documentation after re-reading it multiple times.</p>
<p>If you want to print any attribute which I wanted the "title=", I had to change the <code>print(tag.string)</code> to <code>print(tag['title'])</code></p>
<p>This is what @Rawring and @ChaoticTwist suggested first, ... | 0 | 2016-07-23T11:03:35Z | [
"python",
"html",
"web-scraping",
"beautifulsoup",
"python-requests"
] |
In what order should Pythonâs list.__contains__ invoke __eq__? | 38,540,991 | <p>Consider the following Python program:</p>
<pre><code>class Foo(object):
def __init__(self, bar):
self.bar = bar
def __repr__(self):
return 'Foo(%r)' % (self.bar,)
def __eq__(self, other):
print('Foo.__eq__(%r, %r)' % (self, other))
return self.bar == other
foo1 = Foo... | 0 | 2016-07-23T11:00:02Z | 38,541,058 | <p>Per <a href="https://docs.python.org/3/reference/expressions.html#membership-test-details" rel="nofollow">the language reference</a>:</p>
<blockquote>
<p>For container types such as list, tuple, set, frozenset, dict, or
collections.deque, the expression <code>x in y</code> is equivalent to <code>any(x is
e or... | 3 | 2016-07-23T11:06:55Z | [
"python",
"cpython",
"pypy"
] |
How to monkey patch a `__call__` method? | 38,541,015 | <p>I don't seem to be able to monkey patch a <code>__call__</code> method of class instance (and yes, I want to patch just single instances, not all of them).</p>
<p>The following code:</p>
<pre><code>class A(object):
def test(self):
return "TEST"
def __call__(self):
return "EXAMPLE"
a = A()... | 5 | 2016-07-23T11:02:10Z | 38,541,146 | <blockquote>
<p>For custom classes, implicit invocations of special methods are only guaranteed to work correctly if defined on an objectâs type, not in the objectâs instance dictionary. That behaviour is the reason why the following code raises an exception:</p>
<pre><code>>>> class C:
... pass
...... | 3 | 2016-07-23T11:16:20Z | [
"python",
"monkeypatching"
] |
How to monkey patch a `__call__` method? | 38,541,015 | <p>I don't seem to be able to monkey patch a <code>__call__</code> method of class instance (and yes, I want to patch just single instances, not all of them).</p>
<p>The following code:</p>
<pre><code>class A(object):
def test(self):
return "TEST"
def __call__(self):
return "EXAMPLE"
a = A()... | 5 | 2016-07-23T11:02:10Z | 38,541,437 | <p>So, as <a href="http://stackoverflow.com/users/5781248/j-j-hakala">J.J. Hakala</a> commented, what Python really does, is to call:</p>
<pre><code>type(a).__call__(a)
</code></pre>
<p>as such, if I want to override the <code>__call__</code> method, I <strong>must</strong> override the <code>__call__</code> of a cla... | 3 | 2016-07-23T11:47:38Z | [
"python",
"monkeypatching"
] |
Linebreak for buttons | 38,541,108 | <p>Here is my problem :<br>
I have a <code>labelframe</code> (I tested in a classic label too) which contains some buttons with a left alignment for the "-side" option.</p>
<p>These buttons are generated by a loop and I would like to add a "wraplength" to the label for that my buttons can jump a line instead of follow... | 0 | 2016-07-23T11:12:24Z | 38,550,789 | <p>Okay, so, finally, I added an incremental variable & a <code>if</code> in my loop. When the variable is equal to 5, a new frame (which contains the buttons) is created. Not sure if it's the most optimized method but I didn't found anything else...</p>
<pre><code>def LoadButtons():
FrameInfoText.config(justify =... | 0 | 2016-07-24T09:57:39Z | [
"python",
"button",
"tkinter",
"label"
] |
To match a word from a pool of sentences using Python | 38,541,129 | <p>I have two different files File "Sentence" contains a pool of sentences, please find the snapshot below.
<a href="http://i.stack.imgur.com/oG9WD.jpg" rel="nofollow">Sentence Snapshot</a></p>
<p>File "Word" contians pool of words, please find the snapshot below.</p>
<p><a href="http://i.stack.imgur.com/dkvMX.jpg" r... | 0 | 2016-07-23T11:14:11Z | 38,541,567 | <p>The <code>'\result.csv'</code> part of your path has its <code>'\r'</code> being read as a carriage return character. To fix this, append a leading <code>r</code> to the path to make it a raw string literal (credit @georg).</p>
<hr>
<p>Then to use <code>writerows</code>, the result from all the iterations should b... | 1 | 2016-07-23T12:01:41Z | [
"python",
"string",
"string-matching"
] |
Python, distance between two points type issue | 38,541,153 | <p>I am trying to use a simple approximation for a solution to the travelling salesman problem for 100 random points on a Cartesian grid between values of 0 - 100 on both the x and y axis using the <strong>numpy</strong> method.</p>
<p>I have created various integers that are unique and fill up three lists:</p>
<pre>... | 0 | 2016-07-23T11:16:57Z | 38,541,196 | <p><code>numpy.round</code> does not yield integers:</p>
<pre><code>> print(type(np.round(13.4)))
<type 'numpy.float64'>
</code></pre>
<p>Possible solutions:</p>
<pre><code>> int(np.round(13.4))
13 # type int
> np.int(13.4)
13 # type int
> math.trunc(13.4)
13 # type int
</code></pre>
<hr>
<p>Cons... | 0 | 2016-07-23T11:21:21Z | [
"python",
"list",
"numpy",
"types"
] |
Python, distance between two points type issue | 38,541,153 | <p>I am trying to use a simple approximation for a solution to the travelling salesman problem for 100 random points on a Cartesian grid between values of 0 - 100 on both the x and y axis using the <strong>numpy</strong> method.</p>
<p>I have created various integers that are unique and fill up three lists:</p>
<pre>... | 0 | 2016-07-23T11:16:57Z | 38,541,253 | <p>Your <code>orderList</code> should be a numpy array (or normal Python list) of integers, not random floating-point numbers. </p>
<p>I assume it should be a shuffled list of numbers in the range 0 - 100. You can construct such a list in pure Python like this:</p>
<pre><code>import random
listsize = 10
orderList = ... | 0 | 2016-07-23T11:28:16Z | [
"python",
"list",
"numpy",
"types"
] |
Python high-order functions | 38,541,296 | <p>Given the following code, i cant understand why f and fib behaves differently.
the example taken from Barkley cs61a course</p>
<pre><code>def fib(n):
if n==1 or n==0:
return n
else:
return fib(n-1) + fib(n-2)
def decor(f):
def counted(*args):
counted.call_count += 1
retu... | 1 | 2016-07-23T11:33:48Z | 38,541,378 | <p><code>f.call_count</code> is 1 because <code>f</code> calls <code>fib</code>, and then <code>fib</code> recursively calls itself to calculate the result. In this whole procedure, <code>f</code> is only called once.</p>
<p>But when you do <code>fib = decor(fib)</code>, you're overwriting the <code>fib</code> functio... | 2 | 2016-07-23T11:41:13Z | [
"python",
"functional-programming"
] |
Python high-order functions | 38,541,296 | <p>Given the following code, i cant understand why f and fib behaves differently.
the example taken from Barkley cs61a course</p>
<pre><code>def fib(n):
if n==1 or n==0:
return n
else:
return fib(n-1) + fib(n-2)
def decor(f):
def counted(*args):
counted.call_count += 1
retu... | 1 | 2016-07-23T11:33:48Z | 38,541,417 | <p>You are overwriting <code>fib</code> and then <code>f</code> calls <code>fib</code> instead of itself:</p>
<pre><code>def fib(n):
if n==1 or n==0:
return n
else:
print("fib is: " + repr(fib))
return fib(n-1) + fib(n-2)
def decor(f):
def counted(*args):
counted.call_count... | 0 | 2016-07-23T11:45:06Z | [
"python",
"functional-programming"
] |
Access and webscrape dynamic pages using python | 38,541,353 | <p>I am trying to access a web page using it's form parameters.
I found the form parameters using Network headers in chrome's developer tab.
But it's not working, instead it's just opening the page before these parameters are used (i.e <a href="http://www.irishancestors.ie/search/townlands/ded_index.php" rel="nofollow... | 0 | 2016-07-23T11:38:42Z | 38,541,395 | <p>webbrowser doesn't do what you think it does.</p>
<p>If you want to get/post data to a webpage, you should use <a href="http://docs.python-requests.org/en/master/user/quickstart/" rel="nofollow">requests</a></p>
<pre><code>>>> import requests
>>> r = requests.get('https://api.github.com/events')
... | 1 | 2016-07-23T11:42:56Z | [
"python",
"dynamic",
"web-scraping",
"web-crawler",
"http-post"
] |
In kivy, why does size_hint behave differently for images than for buttons? | 38,541,429 | <p>I'm building a card game using kivy 1.9.1. I Had the cards displaying correctly, relative to the size of the root window, via size_hint. The cards class was inheriting from the image class and worked great. I realized that I needed to make the cards clickable, so I modified the class to inherit from the button class... | 0 | 2016-07-23T11:46:26Z | 38,542,460 | <p>Turns out, the solution is to inherit from the image class and the button behavior class, like so:</p>
<p>from kivy.uix.behaviors import ButtonBehavior<br>
from kivy.uix.image import Image</p>
<p>class Cards(ButtonBehavior, Image): pass </p>
| 0 | 2016-07-23T13:43:49Z | [
"python",
"image",
"button",
"scale",
"kivy"
] |
How to motion blur with ImageMagick using wand? | 38,541,457 | <p>I want to use motion blur with ImageMagick.
<a href="http://www.imagemagick.org/Usage/blur/#motion-blur" rel="nofollow">Motion blur in ImageMagick documentation.</a></p>
<p>But in Wand there is only gaussian_blur.
<a href="http://docs.wand-py.org/en/0.4.3/wand/image.html" rel="nofollow">Gaussian blur in Wand docum... | -1 | 2016-07-23T11:49:33Z | 38,588,482 | <blockquote>
<p>Is motion blur missing in wand?</p>
</blockquote>
<p>Yes, as of <em>0.4.3</em> there is no <code>wand.image.Image.motion_blur</code> method implemented on <a href="/questions/tagged/wand" class="post-tag" title="show questions tagged 'wand'" rel="tag">wand</a> library.</p>
<p>You'll need to ... | 0 | 2016-07-26T11:19:26Z | [
"python",
"imagemagick",
"blur",
"motion",
"wand"
] |
Update all POS order using python | 38,541,514 | <p>I am trying to update the all POS order, but as I having around 50,000 record so when if any error occurs or stops execution forcefully. Then the number of records which executed must be updated but It was not storing the records when stops the script in middle.
So please give me some solution for this...</p>
<p>Co... | 0 | 2016-07-23T11:54:49Z | 38,542,022 | <p>Just put commit after each update, then it won't roll back all those records which are committed. </p>
<pre><code>@api.multi
def update_all_amount(self):
for order in self.search([('copy_amount_total', '=', 0)]):
self._cr.execute("""update pos_order set copy_amount_total=%s where id = %s"""\
... | 0 | 2016-07-23T12:54:14Z | [
"python",
"openerp",
"psql"
] |
Counting number of links for each row and adding the counts as a new column | 38,541,690 | <p>I am trying to count the 'href' instances within the 'Body' column and add the count value as a new column corresponding for each row.</p>
<p>I can get the count of links using this:</p>
<pre><code>dataframe1['Body'].str.contains('href').sum()
</code></pre>
<p>However, this finds the link count for all rows not p... | 1 | 2016-07-23T12:16:01Z | 38,541,767 | <pre><code>> import pandas as pd
> df = pd.DataFrame([["AAAAAAAA"], ["AAABBB"]], columns=['body'])
> df['count'] = df.apply(lambda r: r.body.count('A'), axis=1)
# df['count'] = df.body.count('A') # (better) alternative, as in the answer of MaxU
> df
body count
0 AAAAAAAA 8
1 AAABBB 3
<... | 1 | 2016-07-23T12:25:39Z | [
"python",
"pandas"
] |
Counting number of links for each row and adding the counts as a new column | 38,541,690 | <p>I am trying to count the 'href' instances within the 'Body' column and add the count value as a new column corresponding for each row.</p>
<p>I can get the count of links using this:</p>
<pre><code>dataframe1['Body'].str.contains('href').sum()
</code></pre>
<p>However, this finds the link count for all rows not p... | 1 | 2016-07-23T12:16:01Z | 38,541,824 | <p>try this:</p>
<pre><code>In [134]: df
Out[134]:
Body
0 aaa
1 href...href
2 bbb
3 href
4 href aaa href bbb href ccc href
In [135]: df['count'] = df.Body.str.findall('href').apply... | 1 | 2016-07-23T12:32:39Z | [
"python",
"pandas"
] |
Return javascript variable in Python / Flask | 38,541,744 | <p>I am working on a small Flask app and I am having trouble finding the way to access a javascript array from Python to be printed as csv.</p>
<p>The general setup of my Flask file is (I am trying to print in the console to see if this is working, then I can write as csv later):</p>
<pre><code>from flask import Flas... | 2 | 2016-07-23T12:23:10Z | 38,541,857 | <p>Let's assume your python is right and you need to post to assemblies your code would be like this:</p>
<pre><code><form action="/assemblies" method="post">
<select name="colours">
<option value="0">Empty</option>
<option value="1">Blue</option>
<option value="2... | 1 | 2016-07-23T12:37:11Z | [
"javascript",
"python",
"html",
"flask"
] |
Return javascript variable in Python / Flask | 38,541,744 | <p>I am working on a small Flask app and I am having trouble finding the way to access a javascript array from Python to be printed as csv.</p>
<p>The general setup of my Flask file is (I am trying to print in the console to see if this is working, then I can write as csv later):</p>
<pre><code>from flask import Flas... | 2 | 2016-07-23T12:23:10Z | 38,541,901 | <p>Sorry to post directly as answer due to less reputation, but it should be comment.</p>
<p>Your <strong>select</strong> has no <code>name</code> attribute; it'll never be sent as part of the POST. Give it a name attribute as well as a value:</p>
<pre><code><select id="Layer1" name="layer">
</code></pre>
<p>Y... | 0 | 2016-07-23T12:41:36Z | [
"javascript",
"python",
"html",
"flask"
] |
Return javascript variable in Python / Flask | 38,541,744 | <p>I am working on a small Flask app and I am having trouble finding the way to access a javascript array from Python to be printed as csv.</p>
<p>The general setup of my Flask file is (I am trying to print in the console to see if this is working, then I can write as csv later):</p>
<pre><code>from flask import Flas... | 2 | 2016-07-23T12:23:10Z | 38,542,510 | <pre><code>from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/assemblies')
def assemblies():
mycolours = request.form.get('colours')
return render_template('assemblies.html', mycolours=mycolours)
@app.route('/select')
def select():
return render_template('select.html')
i... | 1 | 2016-07-23T13:49:51Z | [
"javascript",
"python",
"html",
"flask"
] |
python-iptables installation error | 38,541,828 | <p>I am trying to install <code>python-iptables</code> for Python27 but I get the following error after using <code>pip install python-iptables</code> and <code>easy_install python-iptables</code></p>
<blockquote>
<p>libxtwrapper/wrapper.c(5) : fatal error C1083: Cannot open include file: 'sys/utsname.h': No such fi... | 0 | 2016-07-23T12:33:07Z | 38,542,000 | <p>You install python-tables in windows OS, it only supports <code>POSIX :: Linux</code><a href="https://github.com/ldx/python-iptables/blob/master/README.md" rel="nofollow">python-iptables readme</a></p>
| 0 | 2016-07-23T12:51:53Z | [
"python",
"python-iptables"
] |
Numpy: Using a matrix as indices for another matrix to create a tensor? | 38,541,860 | <p>how would the following code work? </p>
<pre><code>k = np.array([[ 0., 0.07142857, 0.14285714],
[ 0.21428571, 0.28571429, 0.35714286],
[ 0.42857143, 0.5, 0.57142857],
[ 0.64285714, 0.71428571, 0.78571429],
[ 0.85714286, 0.92857143, 1. ... | 2 | 2016-07-23T12:37:27Z | 38,541,993 | <p>This is called <strong><a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#integer-array-indexing" rel="nofollow">integer array indexing</a>.</strong> </p>
<blockquote>
<p>Integer array indexing allows selection of arbitrary items in the
array based on their N-dimensional index. Each integer... | 3 | 2016-07-23T12:51:18Z | [
"python",
"numpy",
"matrix"
] |
How can I make my GUI program(tkinter) work on computers with no python installed such that no console window appears? | 38,541,974 | <p>Here's what I have done so far:
-I made a desktop search program/GUI using python and tkinter. </p>
<p>-Then I used py2exe to convert it to an exe.</p>
<p>-Now the software perfectly works on a machine(windows) without python installed, but the problem is that a creepy black window just appears along with the GUI ... | 0 | 2016-07-23T12:48:48Z | 38,542,029 | <p>Change the file extension from .py to .pyw
(You must have Python installed for this to work.)</p>
<p>Duplicate:
<a href="http://stackoverflow.com/questions/5523867/hide-console-window-with-tkinter-and-cx-freeze">Hide console window with Tkinter and cx_Freeze</a></p>
| 0 | 2016-07-23T12:54:43Z | [
"python",
"user-interface",
"tkinter"
] |
Computer guessing a user-selected number within a defined range | 38,542,083 | <p>This is my code for a game in which the computer must guess a user defined number within a given range. This is a challenge from a beginners course/ book.</p>
<p>I'd like to draw your attention to the 'computerGuess()' function. I think there must be a more eloquent way to achieve the same result? What I have looks... | 0 | 2016-07-23T13:00:34Z | 38,542,209 | <p>Like this ? </p>
<pre><code>import math
def computerGuess(lowerNumber, higherNumber):
return int((lowerNumber+higherNumber)/2)
</code></pre>
| 0 | 2016-07-23T13:14:56Z | [
"python",
"list",
"indexing"
] |
Check if a python script is running properly and if it isn't re-run it? | 38,542,084 | <p>I have a script which is really buggy and every couple of hours it stops due to an error. I don't code in Python but I know the basics so I would like to know how can I make a script that check another script for errors and if it's true just re-run it?
Sorry for not giving any examples but I think you get the idea a... | -1 | 2016-07-23T13:00:39Z | 38,542,114 | <p>By far the simplest way is to just wait for it to exit and always restart it when it crashes; the following <code>bash</code> loop will do nothing while the program is running, and will restart it as soon as it exits:</p>
<pre class="lang-bash prettyprint-override"><code>while true
do
python buggy_script.py arg... | 2 | 2016-07-23T13:04:31Z | [
"python",
"python-2.7"
] |
Check if a python script is running properly and if it isn't re-run it? | 38,542,084 | <p>I have a script which is really buggy and every couple of hours it stops due to an error. I don't code in Python but I know the basics so I would like to know how can I make a script that check another script for errors and if it's true just re-run it?
Sorry for not giving any examples but I think you get the idea a... | -1 | 2016-07-23T13:00:39Z | 38,542,245 | <p>You can create a daemon for the script.</p>
<p>Basically keep the main functionality in a loop that will run forever.
<code>
import logging
import time
if __name__ == '__main__':
while True:
//log errors
logging.basicConfig(filename='log_file.log', level=logging.DEBUG)
// use try except ... | 0 | 2016-07-23T13:19:17Z | [
"python",
"python-2.7"
] |
Mongo DB Radius Units for GeoQuerys | 38,542,108 | <p>I am trying to work out what unit MongoDB queries use...</p>
<p>I have the following query:</p>
<pre><code>User.objects(address__point__geo_within_center=[[lat, long],maxDistance])
</code></pre>
<p>I would like to user meters e.g. 10 meters within maxDistance.</p>
<p>But in the documention (<a href="https://docs... | 0 | 2016-07-23T13:03:33Z | 38,542,672 | <p>You are trying to use $center which is only supported by the 2d index. You should be using the 2dshpere index and its supported operations. For that, the <a href="https://docs.mongodb.com/manual/core/2dsphere/" rel="nofollow">2dsphere docs</a> is a good place to start.</p>
<p>The <a href="https://docs.mongodb.com/m... | 0 | 2016-07-23T14:07:40Z | [
"python",
"mongodb",
"flask",
"mongoengine",
"flask-mongoengine"
] |
Example Decorator Error | 38,542,122 | <p>I'm trying to understand Python decorators and have written this code:</p>
<pre><code>def hello_world(fn):
print('hello world')
fn()
pass
@hello_world
def decorate():
print('hello decoatrion')
return
decorate()
</code></pre>
<p>I was aiming to print 'hello world' before 'hello decoration', bu... | -1 | 2016-07-23T13:05:20Z | 38,542,155 | <p>The decorator must <strong>return the decorated function</strong>. You probably wanted something along these lines:</p>
<pre><code>def hello_world(fn):
def inner():
print('hello world')
fn()
return inner
@hello_world
def decorate():
print('hello decoatrion')
return
decorate()
#outp... | 3 | 2016-07-23T13:09:31Z | [
"python",
"python-decorators"
] |
Example Decorator Error | 38,542,122 | <p>I'm trying to understand Python decorators and have written this code:</p>
<pre><code>def hello_world(fn):
print('hello world')
fn()
pass
@hello_world
def decorate():
print('hello decoatrion')
return
decorate()
</code></pre>
<p>I was aiming to print 'hello world' before 'hello decoration', bu... | -1 | 2016-07-23T13:05:20Z | 38,542,195 | <p>Decorator syntax is shorthand for</p>
<pre><code>decorated = decorate(decorated)
</code></pre>
<p>So if you have:</p>
<pre><code>def hello_world(fn):
print('hello world')
fn()
pass
def decorate():
print('hello decoatrion')
return
decorate = hello_world(decorate)
</code></pre>
<p>You should ... | 3 | 2016-07-23T13:13:00Z | [
"python",
"python-decorators"
] |
Python Smptlib Email (Wrong subject & message field) | 38,542,212 | <p>Everytime I send an email with this function, it doesn't add the subject and the message to the right fields, but instead of that, it adds it to the 'from:' or something.
<a href="http://i.stack.imgur.com/Kn5ux.png" rel="nofollow">Here's the image of it.</a>
Any idea how this can be fixed? Thanks for answer</p>
<pr... | 0 | 2016-07-23T13:15:05Z | 38,544,003 | <p>You cannot have a space after the <code>\r\n</code>. An email header line is continued by indenting it, so your code is creating a really long <code>From:</code> header with all the data you are trying to put in different fields.</p>
<p>Anyway, manually gluing together snippets of plain text is a really crude and e... | 1 | 2016-07-23T16:33:04Z | [
"python",
"email",
"smtplib"
] |
Python Smptlib Email (Wrong subject & message field) | 38,542,212 | <p>Everytime I send an email with this function, it doesn't add the subject and the message to the right fields, but instead of that, it adds it to the 'from:' or something.
<a href="http://i.stack.imgur.com/Kn5ux.png" rel="nofollow">Here's the image of it.</a>
Any idea how this can be fixed? Thanks for answer</p>
<pr... | 0 | 2016-07-23T13:15:05Z | 38,556,353 | <p>Following on from @tripleee suggestion to use the <code>email</code> module, here's a basic example using your current code:</p>
<pre><code>import smtplib
from email.mime.text import MIMEText
## NON-ANONYMOUS EMAIL
def email():
# Parts of an email
SERVER = 'smtp.gmail.com'
PORT = 587
USER = 'someth... | 0 | 2016-07-24T20:15:30Z | [
"python",
"email",
"smtplib"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.