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 |
|---|---|---|---|---|---|---|---|---|---|
handling exception in reading data with pandas.read_csv() | 39,057,333 | <p>I would like to open a csv file in pieces with pd.read_csv(path, chunksize = N) until the end of it in a quite elegant and efficient way. The problem is that once the pointer is out of the file the following message of error takes place:</p>
<pre><code>df.get_chunk()
Traceback (most recent call last):
File "<ip... | 0 | 2016-08-20T18:16:16Z | 39,058,046 | <p>You could try:</p>
<pre><code>df = pd.read_csv(path, chunksize=6)
for chunk in df:
print(chunk)
</code></pre>
<hr>
<p>Incase you want to carry out operations inside each chunk, you can do:</p>
<pre><code>for chunk in df:
chunk['d'] = chunk[['a', 'b']].mean(axis=1) # Average of columns 'a' and 'b'
... | 1 | 2016-08-20T19:41:24Z | [
"python",
"pandas"
] |
Multiple URL requests to API without getting error from urllib2 or requests | 39,057,359 | <p>I am trying to get data from different APIs. They are received in JSON format, stored in SQLite and afterwards parsed.</p>
<p>The issue I am having is that when sending many requests I eventually receive an error, even if I am using <code>time.sleep</code> between requests.</p>
<h1>Usual approach</h1>
<p>My code ... | 0 | 2016-08-20T18:19:53Z | 39,064,623 | <p>Even if I was not convinced, I ended up trying to implement the <code>try .. except</code> block and I'm quite happy with the result:</p>
<pre><code>for url in list_of_urls:
time.sleep(2)
try:
response = urllib2.urlopen(url)
data = response.read()
time.sleep(0.1)
response.clo... | 0 | 2016-08-21T13:16:44Z | [
"python",
"python-requests",
"urllib2",
"urllib",
"httplib2"
] |
Operations with numpy array elements | 39,057,365 | <p>Have a numpy array which was created from pandas values.</p>
<p>It looks like this:</p>
<pre><code>array([[ 230.1, 37.8, 69.2],
[ 44.5, 39.3, 45.1],
[ 17.2, 45.9, 69.3],
[ 151.5, 41.3, 58.5],
[ 180.8, 10.8, 58.4]])
</code></pre>
<p>How can I subtract the np.mean() of ... | 0 | 2016-08-20T18:20:27Z | 39,057,490 | <p>With <code>-</code>:</p>
<pre><code>a = array([[ 230.1, 37.8, 69.2],
[ 44.5, 39.3, 45.1],
[ 17.2, 45.9, 69.3],
[ 151.5, 41.3, 58.5],
[ 180.8, 10.8, 58.4]])
a -= a.mean()
</code></pre>
| 1 | 2016-08-20T18:34:49Z | [
"python",
"arrays",
"pandas",
"numpy"
] |
Collatz function not exiting correctly | 39,057,369 | <p>Here's a program that is intended to count the length of a Collatz sequence recursively:</p>
<pre><code>def odd_collatz ( n ):
return (3 * n) + 1
def even_collatz ( n ):
return int(n / 2)
def collatz_counter ( initialNumber, initialLength ):
length = initialLength
while True:
if initialNu... | 2 | 2016-08-20T18:21:03Z | 39,057,404 | <p>Looks like a typo to me. You define a function <code>collatz_counter</code> expecting two numbers.</p>
<p>But you call it like this:</p>
<pre><code>...
print(collatz_counter(13), 1)
</code></pre>
<p>Just try to change the last line to:</p>
<pre><code>print(collatz_counter(13, 1))
</code></pre>
<p>And it should ... | 2 | 2016-08-20T18:24:50Z | [
"python",
"function",
"recursion",
"collatz"
] |
Collatz function not exiting correctly | 39,057,369 | <p>Here's a program that is intended to count the length of a Collatz sequence recursively:</p>
<pre><code>def odd_collatz ( n ):
return (3 * n) + 1
def even_collatz ( n ):
return int(n / 2)
def collatz_counter ( initialNumber, initialLength ):
length = initialLength
while True:
if initialNu... | 2 | 2016-08-20T18:21:03Z | 39,057,480 | <p>You are mixing recursion and looping in a bit of an odd way. The problem is <code>while True:</code>. Because you never return anything from within the loop there is nothing stopping it from going on forever. Your code reaches 1 then just keeps adding to the length. Here is a fixed version.</p>
<pre><code>def odd_c... | 3 | 2016-08-20T18:33:52Z | [
"python",
"function",
"recursion",
"collatz"
] |
Collatz function not exiting correctly | 39,057,369 | <p>Here's a program that is intended to count the length of a Collatz sequence recursively:</p>
<pre><code>def odd_collatz ( n ):
return (3 * n) + 1
def even_collatz ( n ):
return int(n / 2)
def collatz_counter ( initialNumber, initialLength ):
length = initialLength
while True:
if initialNu... | 2 | 2016-08-20T18:21:03Z | 39,057,596 | <p>The main error is the <code>while True:</code> loop, coupled with the missing returns.</p>
<pre><code>def odd_collatz ( n ):
return (3 * n) + 1
def even_collatz ( n ):
return int(n / 2)
def collatz_counter(initialNumber, length):
if initialNumber == 1:
return length
elif initialNumber != 1... | 0 | 2016-08-20T18:46:33Z | [
"python",
"function",
"recursion",
"collatz"
] |
How to calculate sum of two polynomials? | 39,057,546 | <p>For instance 3x^4 - 17x^2 - 3x + 5. Each term of the polynomial can be represented as a pair of integers (coefficient,exponent). The polynomial itself is then a list of such pairs like<br>
<code>[(3,4), (-17,2), (-3,1), (5,0)]</code> for the polynomial as shown.</p>
<p>Zero polynomial, 0, is represented as the em... | 0 | 2016-08-20T18:41:20Z | 39,058,521 | <p>As <a href="http://stackoverflow.com/questions/39057546/how-to-calculate-sum-of-two-polynomials#comment65465088_39057546">suggested</a> in the <a href="http://stackoverflow.com/questions/39057546/how-to-calculate-sum-of-two-polynomials#comment65466242_39057546">comments</a>, it is much simpler to represent polynomia... | 1 | 2016-08-20T20:40:25Z | [
"python",
"python-3.x",
"polynomials"
] |
How to calculate sum of two polynomials? | 39,057,546 | <p>For instance 3x^4 - 17x^2 - 3x + 5. Each term of the polynomial can be represented as a pair of integers (coefficient,exponent). The polynomial itself is then a list of such pairs like<br>
<code>[(3,4), (-17,2), (-3,1), (5,0)]</code> for the polynomial as shown.</p>
<p>Zero polynomial, 0, is represented as the em... | 0 | 2016-08-20T18:41:20Z | 39,101,960 | <p>I have come up with a solution but I'm unsure that it's optimized!</p>
<pre><code> def addpoly(p1,p2):
for i in range(len(p1)):
for item in p2:
if p1[i][1] == item[1]:
p1[i] = ((p1[i][0] + item[0]),p1[i][1])
p2.remove(item)
p3 = ... | 0 | 2016-08-23T12:59:48Z | [
"python",
"python-3.x",
"polynomials"
] |
Does Boto3 encrypt the payload during transmission when invoking a lambda function? | 39,057,569 | <p>I am using the Python AWS API. I would like to invoke a lambda function from client code, but I have not been able to find documentation on whether the payload sent during invocation is encrypted. </p>
<p>Can someone watching the network potentially snoop on the AWS invocation payload? Or is the payload transmitted... | 0 | 2016-08-20T18:43:41Z | 39,058,104 | <p>If you turn on the debug logging you should see how exactly is data transmitted. Or try <code>netstat</code> or Wireshark to see if it makes connection to port 443 rather than 80.</p>
<p>From my experience with <code>boto3</code> and S3 (not Lambda) it uses HTTPS, which I would consider somewhat secure. I hope the ... | 0 | 2016-08-20T19:49:25Z | [
"python",
"amazon-web-services",
"encryption",
"aws-lambda",
"boto3"
] |
Preserve existing tables in database when running Flask-Migrate | 39,057,587 | <p>I have a database with existing tables. My code has a <code>User</code> model. I generated a revision using Flask-Migrate and ran it, and it deleted my existing tables while creating the user table. How can I run migrations without removing the existing tables?</p>
<pre><code>from flask import Flask
from flask_s... | 2 | 2016-08-20T18:45:39Z | 39,065,980 | <p>If you have existing tables in your database, and they don't have a corresponding model in your code, Alembic (Flask-Migrate) only knows that there is a difference between your database and your code. It can't know (by default) that you meant to leave those tables untouched.</p>
<p>Pass an <a href="http://alembic.... | 1 | 2016-08-21T15:43:37Z | [
"python",
"flask",
"alembic"
] |
Django jquery autocomplete giving an error | 39,057,611 | <p>I am developing a django application where I am using jquery autocomplete. I know that this question has been asked several times here but none of the solution is working for me. I am following this tutorial: <a href="http://flaviusim.com/blog/AJAX-Autocomplete-Search-with-Django-and-jQuery/" rel="nofollow">http://f... | 0 | 2016-08-20T18:48:27Z | 39,058,298 | <p>It look like Your code is executed before <code>jQueryUI</code> is loaded.</p>
<p>Move Your </p>
<pre><code><script>
$(function() {
$("#recipe_rule_content").autocomplete({
source: "/api/get_RuleStatement/",
minLength: 2,
});
});
</script>
</code></pre>
<p>to <code><head></code> afte... | 0 | 2016-08-20T20:11:32Z | [
"javascript",
"jquery",
"python",
"django",
"autocomplete"
] |
How to set permissions on a file (key) in AWS S3 using Python Boto Library? | 39,057,643 | <p>I'm experiencing a problem with permissions on a file in AWS S3 after updating it with a Python script using the Boto library.</p>
<p>Here is the command that I'm using to update the file in S3:</p>
<pre><code>k.set_contents_from_string(json.dumps(parsed_json, indent=4))
</code></pre>
<p>The file gets updated cor... | 0 | 2016-08-20T18:51:58Z | 39,058,291 | <p>Set the <a href="http://boto.cloudhackers.com/en/latest/ref/s3.html#boto.s3.key.Key.set_contents_from_string" rel="nofollow">policy</a>, with one of the <a href="http://boto.cloudhackers.com/en/latest/s3_tut.html#setting-getting-the-access-control-list-for-buckets-and-keys" rel="nofollow">canned acl strings</a>, som... | 0 | 2016-08-20T20:10:36Z | [
"python",
"amazon-s3",
"boto"
] |
How to name pandas dataframe column based on the column contents | 39,057,714 | <p>I have this text file that I have to load up into a pandas dataframe. On loading the text, I discovered there are no column names. There are about 23 columns and the content of each column are different letters of the English alphabet. I want to rename each column based on which alphabets are in the column. For exam... | 0 | 2016-08-20T19:00:42Z | 39,058,215 | <p>I am not entirely sure I get your question right, since letter 's' are both in CapSize and root, and do you mean it has to be conditional for each column separately?</p>
<p>Otherwise, if I get it correctly it is something like this:</p>
<pre><code>dt = pd.DataFrame({0:['fb', 'bc'], 1:['baab', 'cbc'], 2:['kaab', 'c... | 0 | 2016-08-20T20:02:07Z | [
"python",
"pandas"
] |
I am receiving an error saying Unexpected EOF while parsing? | 39,057,729 | <p>I am using a Book called Python programming: An introduction to computer programming and I am stuck in a programming exercise in chapter 10. It asks for a program that displays a playing card after the user inserts the value of the card and its suit. Also, I should be using 3 methods plus two constructors, here the... | -4 | 2016-08-20T19:02:39Z | 39,057,810 | <p>You're missing the close parentheses in the final <code>print</code> call.</p>
| 1 | 2016-08-20T19:11:41Z | [
"python"
] |
I am receiving an error saying Unexpected EOF while parsing? | 39,057,729 | <p>I am using a Book called Python programming: An introduction to computer programming and I am stuck in a programming exercise in chapter 10. It asks for a program that displays a playing card after the user inserts the value of the card and its suit. Also, I should be using 3 methods plus two constructors, here the... | -4 | 2016-08-20T19:02:39Z | 39,057,821 | <p>You've missed to close parenthesis at the end of last line, there is one opening for print method, but not closing at the end.</p>
| 0 | 2016-08-20T19:13:04Z | [
"python"
] |
Does anyone know how to get rid of the black 'y' axis to the left in Matplotlib plot? | 39,057,822 | <p>After moving all of my 'y' axes to subplots I get an unwanted axis. It's the black one on the left. Does anyone know how to get rid of it? I'm sure it's getting plotted when I call the figure, however I'm not sure how to get rid of it. </p>
<p><a href="http://i.stack.imgur.com/rhsaw.png" rel="nofollow"><img src="ht... | 1 | 2016-08-20T19:13:14Z | 39,058,414 | <p>Well it looks like you have three y-axes, referencing the one you want to not be shown, you could try adding:</p>
<pre><code>ax.yaxis.set_tick_params(labelsize=0, length=0, which='major')
</code></pre>
<p>to just make invisible the labels and ticks. I think it's ax2 you want gone? </p>
| 0 | 2016-08-20T20:24:15Z | [
"python",
"python-2.7",
"matplotlib"
] |
Generate create table sql with comment from migrations | 39,057,829 | <p>I have searched Django's documentation, but I can't find any information about adding comments to the sql generated by Django's <code>makemigrations</code> and <code>migrate</code> commands. </p>
<p>Does any way can generate sql like this. Because my college insists he can know what the field mean for without read ... | 0 | 2016-08-20T19:14:15Z | 39,325,234 | <p>I am just looking for a method do such a thing in Django, but found Django didn't and won't have this feature:see: <a href="https://code.djangoproject.com/ticket/13867" rel="nofollow">https://code.djangoproject.com/ticket/13867</a></p>
<p>So just use the following command to output SQL generated by Django.</p>
<pr... | 0 | 2016-09-05T06:54:12Z | [
"python",
"django"
] |
Bug in my quick sort algorithm implementation | 39,057,893 | <p>Recently I was trying to implement the quicksort algorithm in Python, and I couldn't make it work properly. Even though the program sorts the sub-arrays, it's not being reflected on the main list. I'm new to programming, so can anyone help me to understand what part or concept I didn't do right?</p>
<pre><code>def ... | -1 | 2016-08-20T19:21:47Z | 39,057,916 | <p>You are exactly right! <code>left</code> and <code>right</code> are separate entities after <code>split_array</code>, not parts of the original <code>arr</code>. After <code>quick_sort(right)</code>, say <code>arr=left+right</code>. I think that will do it. (Need to check the case when there is only one element ... | 0 | 2016-08-20T19:24:28Z | [
"python",
"python-2.7",
"sorting",
"quicksort"
] |
Bug in my quick sort algorithm implementation | 39,057,893 | <p>Recently I was trying to implement the quicksort algorithm in Python, and I couldn't make it work properly. Even though the program sorts the sub-arrays, it's not being reflected on the main list. I'm new to programming, so can anyone help me to understand what part or concept I didn't do right?</p>
<pre><code>def ... | -1 | 2016-08-20T19:21:47Z | 39,058,365 | <p>Change this:</p>
<pre><code>left, right = split_array(arr, right_mark)
quick_sort(left)
quick_sort(right)
</code></pre>
<p>to this:</p>
<pre><code>left, right = split_array(arr, right_mark)
arr = quick_sort(left) + quick_sort(right)
</code></pre>
<p>Quicksort is typically implemented "in-place" to avoid copying ... | 2 | 2016-08-20T20:17:41Z | [
"python",
"python-2.7",
"sorting",
"quicksort"
] |
Numpy Matrix inside Python class exhibiting linked behaviour? | 39,057,896 | <p>If you make a class as such in Python:</p>
<pre><code> import numpy as np
class Foo:
def __init__(self, data):
self.data = data
self.data_copy = self.copy(self.data)
def copy(self, data):
a = []
for e in data:
a.append(e)
return a
def change(self,... | 3 | 2016-08-20T19:21:52Z | 39,057,930 | <p>When you make your "copy", you're just making a new list that contains the same objects as the old list. That is, when you iterate through <code>data</code> you're iterating through references to the objects in it, and when you append <code>e</code> you're appending a reference rather than a new or copied object. Th... | 4 | 2016-08-20T19:26:02Z | [
"python",
"class",
"numpy",
"matrix"
] |
How to access parent class variable in python? | 39,057,964 | <p>I want to access a class variable defined in the parent class constructor. Here is the code.</p>
<pre><code>class A(object):
def __init__(self):
x = 0
class B(A):
def __init__(self):
super(B, self).__init__()
def func(self):
print self.x
s = B()
s.func()
</code></pre>
<p>This... | 0 | 2016-08-20T19:31:30Z | 39,057,981 | <p>You need to set it as <code>self.x = 0</code> instead of <code>x = 0</code> - otherwise it's just a local variable.</p>
<p>If you cannot modify <code>A</code>, what you are trying to do is impossible - there is absolutely no way to access that value, not even with black magic (if your method was <em>called</em> by ... | 1 | 2016-08-20T19:33:25Z | [
"python",
"inheritance"
] |
How to access parent class variable in python? | 39,057,964 | <p>I want to access a class variable defined in the parent class constructor. Here is the code.</p>
<pre><code>class A(object):
def __init__(self):
x = 0
class B(A):
def __init__(self):
super(B, self).__init__()
def func(self):
print self.x
s = B()
s.func()
</code></pre>
<p>This... | 0 | 2016-08-20T19:31:30Z | 39,057,989 | <p>It must be <code>self.x</code>, not just <code>x</code>:</p>
<pre><code>class A(object):
def __init__(self):
self.x = 0
</code></pre>
<hr>
<p>Just a quick note - even from other methods of <code>A</code> would be the <code>x</code> not accessible:</p>
<pre><code>class A(object):
def __init__(self... | 2 | 2016-08-20T19:34:15Z | [
"python",
"inheritance"
] |
Register variable input to another task script file using Ansible | 39,058,005 | <p>Example My code is like below:</p>
<pre><code> tasks:
- set_fact:
var: "{{ out1.stdout }}"
- script: do_echo.py {{var}}
</code></pre>
<p>How can we use output variable which we get from one task in the next created script file without any appending that.</p>
<p>In the above script I need to ... | 0 | 2016-08-20T19:35:52Z | 39,059,326 | <p>Your example is correct (if it was only a part of the play):</p>
<pre><code>tasks:
- script: do_echo.py Hello
register: echo1_result
- script: do_echo.py {{echo1_result.stdout}}
register: echo2_result
- debug: msg="{{echo2_result.stdout}}"
</code></pre>
<p>The first task will run your <code>do_echo.p... | 0 | 2016-08-20T22:41:05Z | [
"python",
"ansible",
"ansible-playbook"
] |
Pandas duration of drawdown | 39,058,034 | <p>I am trying to calculate the duration of the drawdowns and the time to recovery for a stock series. I can calculate the drawdowns but am struggling to the the durations and recovery time for each drawdown. So far I have this code:</p>
<pre><code>import pandas as pd
import pickle
import xlrd
import numpy as np
np.r... | 2 | 2016-08-20T19:39:10Z | 39,080,464 | <p>I solved the problem as follows:</p>
<pre><code>def drawdown_group(df,index_list):
group_max,dd_date = index_list
ddGroup = df[df['modMax'] == group_max]
group_length = len(ddGroup)
group_dd = ddGroup['dd'].max()
group_dd_length = len(ddGroup[ddGroup.index <= dd_date])
group_start = ddGro... | 1 | 2016-08-22T13:09:26Z | [
"python",
"pandas"
] |
Wm attributes and '-zoomed' doesn't work? | 39,058,038 | <p>I tried the same codes in Python2 and Python3 to see if the wm attributes would work in Python3 (I generally use Python2)</p>
<pre><code>root.call("wm", "attributes", ".", "-zoomed", "True")
root.attributes('-zoomed', True)
root.wm_attributes('-zoomed', True)
</code></pre>
<p>but it gives me this error:</p>
<pre>... | 0 | 2016-08-20T19:39:49Z | 39,058,096 | <p>If you want to get fullscreen <i>without</i> title bar:<br>
<code>root.attributes('-fullscreen', True)</code><br>
And if you want to get fullscreen <i>with</i> title bar:<br>
<code>root.wm_state('zoomed')</code> or just <code>root.state('zoomed')</code></p>
| 2 | 2016-08-20T19:47:55Z | [
"python",
"tkinter",
"window"
] |
Special shell characters when opening in a file Python | 39,058,074 | <p>I have an interesting problem that I couldn't solve by googling.</p>
<p>I'm trying to process each file inside of the directory. Some of the file names include special shell characters (<code>$</code>, <code>(</code>, <code>)</code> etc). A good example of such file name:</p>
<p><code>FOO.-6.BAR.(nil).$0BAZ</code>... | 1 | 2016-08-20T19:44:59Z | 39,058,217 | <p>You can probably solve this by looking at your directory with <code>os.listfiles('/path/to/stuff')</code>. Your file in there will come back with the \x characters in there. Try to open that after it. </p>
<p>Potentially, depending on your further files, you may also want to use Unicode to look at the files. Do thi... | 0 | 2016-08-20T20:02:10Z | [
"python",
"bash",
"shell",
"escaping",
"character"
] |
Special shell characters when opening in a file Python | 39,058,074 | <p>I have an interesting problem that I couldn't solve by googling.</p>
<p>I'm trying to process each file inside of the directory. Some of the file names include special shell characters (<code>$</code>, <code>(</code>, <code>)</code> etc). A good example of such file name:</p>
<p><code>FOO.-6.BAR.(nil).$0BAZ</code>... | 1 | 2016-08-20T19:44:59Z | 39,059,171 | <p>You don't need to escape anything when opening the file from Python, because you aren't executing a shell command at all.</p>
<pre><code>f = open("FOO.-6.BAR.(nil).$0BAZ")
</code></pre>
<p>The same is true of any file name returned by <code>os.listdir</code>:</p>
<pre><code>for fname in os.listdir('.'):
f = o... | 0 | 2016-08-20T22:18:44Z | [
"python",
"bash",
"shell",
"escaping",
"character"
] |
Python Tkinter TypeError: 'int' object is not callable | 39,058,125 | <p>I am trying to take user input from main.py and then use that information to produce an output on runAnalytics. The problem that I am running into is that sometimes, the user input will produce a value of None (maybe null, I don't know) when the dividen_yield is not available and then my whole program will stop. It ... | 0 | 2016-08-20T19:51:50Z | 39,058,557 | <p>I tried to execute your code and got a different error than you got:</p>
<pre><code>Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/tkinter/__init__.py", line 1533, in __call__
return self.func(*args)
File "./main.py", line 15, in <lambda>
l... | 1 | 2016-08-20T20:46:57Z | [
"python",
"tkinter",
"typeerror",
"python-3.5",
"yahoo-finance"
] |
how to change the black color to Red with opencv python | 39,058,177 | <p>how can you make it in python? I faced a problem with this line</p>
<pre><code>img_rgb.Set(mask,cv2.Scalar(0,0,255))
</code></pre>
<p>and here is the code :</p>
<pre><code>import numpy as np
import imutils
import cv2
img_rgb = cv2.imread('figi.jpg')
Conv_hsv_Gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)
re... | -1 | 2016-08-20T19:56:35Z | 39,062,266 | <p>The API for <code>mat.setTo()</code> is not available in Opencv module for python, this is due to the reason that in <code>C++</code> Opencv uses <code>cv::Mat</code> object as basic entity for image manipulation, However in Python there is no such <code>cv::Mat</code> concept, instead Python API for Opencv uses the... | 0 | 2016-08-21T08:22:28Z | [
"python",
"opencv"
] |
cubic spline to get smooth python line curve | 39,058,276 | <p>I need to make a smooth line in python using cubic spline, I followed the scipy tutorial and got a little confused. I used the following code: </p>
<pre><code>import matplotlib.pyplot as plt
from scipy import interpolate
tck = interpolate.splrep(time, ca40Mass)
plt.semilogy(time,ca40Mass,label='$^{40}$Ca')
plt.xla... | 1 | 2016-08-20T20:08:43Z | 39,058,381 | <p>You are not using the interpolation.</p>
<pre><code>time_spline = numpy.linspace(min(time),max(time),1000)
ca40Mass_spline = interpolate.splev(time_spline, tck)
plt.semilogy(time_spline, ca40Mass_spline, label='$^{40}$Ca')
</code></pre>
| 2 | 2016-08-20T20:18:48Z | [
"python",
"cubic-spline"
] |
How do I get IPython 5 to work with SublimeREPL? | 39,058,283 | <p>I followed (actually, I authored) the instructions in <a href="https://gist.github.com/MattDMo/6cb1dfbe8a124e1ca5af" rel="nofollow">this gist</a> in order to modify the <code>ipy_repl.py</code> file that ships with <a href="https://packagecontrol.io/packages/SublimeREPL" rel="nofollow">SublimeREPL</a> in order to ge... | 1 | 2016-08-20T20:09:47Z | 39,058,284 | <p>Through a fortuitous series of events, I came upon an old Win7 VM that I hadn't used in several months, and which had not been upgraded, so the IPython REPL still worked. Through a little experimentation, I found that if I downgraded <code>ipython</code> to version 4.1.1 and <code>jupyter_console</code> to 4.1.0, ev... | 1 | 2016-08-20T20:09:47Z | [
"python",
"ipython",
"sublimetext",
"jupyter",
"sublimerepl"
] |
Python play mp3/wav file audio(Pygame mixer) | 39,058,335 | <p>What is the best way to play mp3/wav file audio with Python?</p>
<p>I tried to use pygame, it play the sound, but don't close propertly the file.
So when i try to remove the file i get errors.(Yes, i call pygame.mixer.quit() , but the file is still used in another process)</p>
| 0 | 2016-08-20T20:15:15Z | 39,230,496 | <p>If you are open to using libraries other than <code>pygame</code> then you can use <a href="https://github.com/jiaaro/pydub" rel="nofollow">pydub</a> which is clean and easy. Below is an working example.</p>
<p>For <code>wav</code> files </p>
<pre><code>from pydub import AudioSegment
from pydub.playback import pl... | 1 | 2016-08-30T14:38:10Z | [
"python",
"audio",
"pygame",
"mp3",
"wav"
] |
Override importing module's built-in functions from imported module | 39,058,351 | <p>I have an application where I would like to override certain functions when a condition occurs, for example:</p>
<p>condition_check.py:</p>
<pre><code>Flag = True
import ctypes # An included library with Python install.
import inspect
def MsgBox(msg):
ctypes.windll.user32.MessageBoxA(0, msg, 'MsgBox', 1)
def ... | 2 | 2016-08-20T20:16:38Z | 39,060,016 | <p>I am assuming that you are using Python 3. If you are, you need merely set an attribute of the built-in module.</p>
<pre><code>import builtins
import ctypes
original = builtins.print
Flag = True
def MsgBox(msg):
ctypes.windll.user32.MessageBoxA(0, msg, 'MsgBox', 1)
def check():
if Flag:
builtins... | 1 | 2016-08-21T01:05:38Z | [
"python",
"python-import"
] |
Django reverse ordering with ListView | 39,058,384 | <p>I have implemented ordering in a generic ListView:</p>
<pre><code>class CarList(LoginRequiredMixin, ListView):
model = Car
paginate_by = 30
ordering = 'car_id_internal'
def get_ordering(self):
return self.request.GET.get('ordering', 'car_id_internal')
def get_context_data(self, *args,... | 0 | 2016-08-20T20:19:24Z | 39,059,065 | <p>You need to use another variable for determining the asc/desc ordering. Depending on which is currently selected the template should alternate the links. In the view, you reverse the ordering by <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#order-by" rel="nofollow">adding a dash</a> before th... | 1 | 2016-08-20T22:01:53Z | [
"python",
"django",
"python-3.x",
"listview",
"django-views"
] |
Every time I reconnect to a MySQL database, all the tables are empty | 39,058,505 | <p>I'm very new to MySQL, so I started by using www.freesqldatabase.com to set up a database. Whenever I connect to it, I can set up tables and databases that will persist over connections, but any data I input is unique to that connection. Even if I'm viewing the database via DataGrip, if I add a row to a table I can'... | 1 | 2016-08-20T20:38:25Z | 39,058,744 | <p>I set autocommit to true when I connected to my database, and that solved my issue.</p>
| 2 | 2016-08-20T21:11:18Z | [
"python",
"mysql",
"sql",
"database",
"datagrip"
] |
Every time I reconnect to a MySQL database, all the tables are empty | 39,058,505 | <p>I'm very new to MySQL, so I started by using www.freesqldatabase.com to set up a database. Whenever I connect to it, I can set up tables and databases that will persist over connections, but any data I input is unique to that connection. Even if I'm viewing the database via DataGrip, if I add a row to a table I can'... | 1 | 2016-08-20T20:38:25Z | 39,058,959 | <p>Try to execute</p>
<pre><code>insert into auth values ('id', 'token');
commit;
</code></pre>
| 1 | 2016-08-20T21:44:19Z | [
"python",
"mysql",
"sql",
"database",
"datagrip"
] |
How to insert each element of a character list into a matrix in python | 39,058,538 | <p>How can I insert each element of a character list into a matrix (mxn)
I have this code in python</p>
<pre><code>key = raw_input('Key: ')
text = raw_input('Text: ')
text_c = list(text)
while ' ' in text_c:
text_c.remove(' ')
columns = len(key)
rows = int(math.ceil(float(len(text_c)) / float(len(... | 1 | 2016-08-20T20:43:41Z | 39,059,472 | <p>You can achieve this by combining some list comprehensions as follows:</p>
<pre><code>number_columns = 6
sample_string = 'abcdefghijklmnopqrstuvwxyzabcdefgh'
l = [list(sample_string[i:i+number_columns]) for i in range(0, len(sample_string), number_columns)]
matrix = [s if len(s) == number_columns else s+[None]*(nu... | 1 | 2016-08-20T23:05:47Z | [
"python",
"list",
"matrix"
] |
How to select an element with selenium? | 39,058,556 | <p>I am trying to get the href. Its a next page button. I select element by <code>class_name = next</code>. This is my code:</p>
<pre><code>elem = browser.find_element_by_class_name('next').click()
</code></pre>
<p>An error comes up saying <code>Element is not clickable at point (801, 553)</code>
I think this is happ... | 0 | 2016-08-20T20:46:47Z | 39,058,587 | <p>Try</p>
<pre><code>from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By. XPATH, '//li[@id="next_pag_1"]/a')))
element.click()
</c... | 1 | 2016-08-20T20:50:27Z | [
"python",
"selenium"
] |
How to select an element with selenium? | 39,058,556 | <p>I am trying to get the href. Its a next page button. I select element by <code>class_name = next</code>. This is my code:</p>
<pre><code>elem = browser.find_element_by_class_name('next').click()
</code></pre>
<p>An error comes up saying <code>Element is not clickable at point (801, 553)</code>
I think this is happ... | 0 | 2016-08-20T20:46:47Z | 39,064,421 | <p>Its Chrome browser that is causing the problem. To be fair to the user Chrome clicks the element right in the center. Some elements are not clickable in the center. So, this is what I did:</p>
<pre><code>elem = browser.find_element_by_class_name('next')
action = ActionChains(browser)
action.move_to_element_with_off... | 0 | 2016-08-21T12:55:01Z | [
"python",
"selenium"
] |
Group rows based on range python | 39,058,574 | <p>I have a large text file where I am trying to group the first column based on intervals of 200. In the example code below, the first four rows would be in a group, the next three rows in a different group, and the last row in a separate group. My thought is to group them based on a for loop with a condition that add... | -1 | 2016-08-20T20:49:19Z | 39,058,731 | <p>You could divide the value by 200 to get a key for <code>groupby</code>:</p>
<pre><code>>>> rows = '''000008 34.576 -87.234
000025 34.825 -87.935
000123 35.935 -86.344
000154 34.395 -86.903
000234 35.219 -86.945
000322 34.240 -86.527
000359 34.893 -87.573
000412 35.291 -87.392'''.splitlines... | 1 | 2016-08-20T21:08:56Z | [
"python",
"rows"
] |
How to write in txt file and find common words in message history from slack in Python? | 39,058,596 | <p>Please help me to write in txt file slack message history and find common words in it.
In my code example I have to problems:
1) Only first message is written in the file.
2) Counter works for each message seperately not for all message history.</p>
<pre><code>from slackclient import SlackClient
from collections im... | -1 | 2016-08-20T20:51:38Z | 39,058,813 | <p>Your second question is easily answered without a knowledge of slackclient. Your reference to Counter is in a loop. Hence, each time you reference it a new instance of it is created and the old one is lost. What you want is to create an instance of Counter before you enter the loop, add items to it within the loop a... | 1 | 2016-08-20T21:21:14Z | [
"python",
"counter",
"slack-api"
] |
Does Cython offer any reasonably easy and efficient way to iterate Numpy arrays as if they were flat? | 39,058,641 | <p>Let's say I want to implement Numpy's</p>
<pre><code>x[:] += 1
</code></pre>
<p>in Cython. I could write</p>
<pre><code>@cython.boundscheck(False)
@cython.wraparoundcheck(False)
def add1(np.ndarray[np.float32_t, ndim=1] x):
cdef unsigned long i
for i in range(len(x)):
x[i] += 1
</code></pre>
<p>H... | 2 | 2016-08-20T20:57:13Z | 39,058,684 | <p>You could try using the <code>flat</code> attribute of the <code>ndarray</code>, which provides an iterator over the flattened array object. It always iterates in C-major ordering, with the last index varying the fastest. Something like:</p>
<pre><code>for i in range(x.size):
x.flat[i] += 1
</code></pre>
| 1 | 2016-08-20T21:03:32Z | [
"python",
"performance",
"numpy",
"cython"
] |
Does Cython offer any reasonably easy and efficient way to iterate Numpy arrays as if they were flat? | 39,058,641 | <p>Let's say I want to implement Numpy's</p>
<pre><code>x[:] += 1
</code></pre>
<p>in Cython. I could write</p>
<pre><code>@cython.boundscheck(False)
@cython.wraparoundcheck(False)
def add1(np.ndarray[np.float32_t, ndim=1] x):
cdef unsigned long i
for i in range(len(x)):
x[i] += 1
</code></pre>
<p>H... | 2 | 2016-08-20T20:57:13Z | 39,058,906 | <p><a href="http://docs.scipy.org/doc/numpy/reference/arrays.nditer.html" rel="nofollow">http://docs.scipy.org/doc/numpy/reference/arrays.nditer.html</a></p>
<p>Is a nice tutorial on using <code>nditer</code>. It ends with a <code>cython</code> version. <code>nditer</code> is meant to be the all purpose array(s) iter... | 2 | 2016-08-20T21:33:06Z | [
"python",
"performance",
"numpy",
"cython"
] |
Does Cython offer any reasonably easy and efficient way to iterate Numpy arrays as if they were flat? | 39,058,641 | <p>Let's say I want to implement Numpy's</p>
<pre><code>x[:] += 1
</code></pre>
<p>in Cython. I could write</p>
<pre><code>@cython.boundscheck(False)
@cython.wraparoundcheck(False)
def add1(np.ndarray[np.float32_t, ndim=1] x):
cdef unsigned long i
for i in range(len(x)):
x[i] += 1
</code></pre>
<p>H... | 2 | 2016-08-20T20:57:13Z | 39,061,741 | <p>With <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ravel.html" rel="nofollow">numpy.ravel</a></p>
<blockquote>
<p>numpy.ravel(a, order='C')</p>
<p>Return a contiguous flattened array.</p>
<p>A 1-D array, containing the elements of the input, is returned. A copy
is made only if nee... | 0 | 2016-08-21T07:11:37Z | [
"python",
"performance",
"numpy",
"cython"
] |
wxPython : Adding an about box. | 39,058,783 | <p>I'm creating a wxPython soundboard and was wondering how to implement an About Box. The goal is to press an About button on the wxPython File menu and generate an About Box. </p>
<p>This is my code so far: </p>
<pre><code>import wx
import os
import pygame
pygame.init()
##SOUNDS##
goliathwav = pygame.mixer.Sou... | 0 | 2016-08-20T21:15:27Z | 39,058,918 | <p>you again :)</p>
<p>The aboutBox needs to be created in your missing callback <code>OnMenuHelpAbout</code> (that I refactored to make private as stated in my previous answer)</p>
<p>Also (not related) but I have changed the dictionary so it directly points to the sound object: no more <code>if/elif</code>, you can... | 0 | 2016-08-20T21:36:03Z | [
"python",
"wxpython"
] |
wxPython : Adding an about box. | 39,058,783 | <p>I'm creating a wxPython soundboard and was wondering how to implement an About Box. The goal is to press an About button on the wxPython File menu and generate an About Box. </p>
<p>This is my code so far: </p>
<pre><code>import wx
import os
import pygame
pygame.init()
##SOUNDS##
goliathwav = pygame.mixer.Sou... | 0 | 2016-08-20T21:15:27Z | 39,062,433 | <p>wx python has its own <code>wx.AboutBox()</code> used in conjunction with <code>wx.AboutDialogInfo()</code></p>
<pre><code>def About(self, event):
from platform import platform
myos = platform()
aboutInfo = wx.AboutDialogInfo()
aboutInfo.SetName("My Application ")
aboutInfo.SetVersion("1.0")
... | 2 | 2016-08-21T08:44:26Z | [
"python",
"wxpython"
] |
Get field type in Django's login template | 39,058,787 | <p>I'm trying to create custom template for Django's build-in login view. At the moment it looks like (<code>registration/login.html</code>):</p>
<pre><code><form method="post">
{% csrf_token %}
{% for field in form %}
{% include 'registration/form_field.html' %}
{% endfor %}
<input ... | 0 | 2016-08-20T21:16:50Z | 39,059,277 | <p>You can implement a <a href="https://docs.djangoproject.com/en/1.10/ref/forms/widgets/#django.forms.PasswordInput" rel="nofollow">PasswordInput</a> widget in your form definition, that will render as a password field with type="password".</p>
<pre><code>class ExampleForm(forms.Form):
password = forms.CharField(... | 1 | 2016-08-20T22:35:16Z | [
"python",
"django"
] |
Event callback after a Tkinter Entry widget | 39,058,817 | <p>From the first answer here:
<a href="http://stackoverflow.com/questions/6548837/how-do-i-get-an-event-callback-when-a-tkinter-entry-widget-is-modified">StackOverflow #6548837</a>
I can call callback when the user is typing: </p>
<pre><code>from Tkinter import *
def callback(sv):
print sv.get()
root = Tk()
sv... | 0 | 2016-08-20T21:21:27Z | 39,059,073 | <p>I think this does what you're looking for. I found relevant information <a href="http://docs.huihoo.com/tkinter/an-introduction-to-tkinter-1997/intro06.htm" rel="nofollow">here</a>. The <code>bind</code> method is the key.</p>
<pre><code>from Tkinter import *
def callback(sv):
print sv.get()
root = Tk()
sv =... | 2 | 2016-08-20T22:03:49Z | [
"python",
"events",
"tkinter",
"callback"
] |
AttributeError: 'int' object has no attribute 'sleep' | 39,058,861 | <p>I am fairly new to Python (and programming in general), so please excuse my lack of knowledge or understanding to something you may find obvious. I'm not stupid though, so hopefully I should be able to work it out.</p>
<p>I am making a small text-based survival game, and I have encountered an issue which I cannot s... | 0 | 2016-08-20T21:28:25Z | 39,058,967 | <p>As commented above you are overwriting the <code>time</code> module by making a variable named time. Simply rename the <code>time</code> variable! </p>
| 0 | 2016-08-20T21:46:24Z | [
"python",
"attributes"
] |
Spotify - passing a list as parameter | 39,058,952 | <p>I have a function to be called later in a <code>for</code> loop.</p>
<pre><code>def show_tracks(results):
for i, item in enumerate(tracks['items']):
track = item['track']
print(" %d %32.32s %s" % (i, track['artists'][0]['name'], track['name']))
</code></pre>
<p>2nd snippet:</p>
<pre><code>pl... | 0 | 2016-08-20T21:43:04Z | 39,059,479 | <p>Check your <code>show_tracks(results)</code> function. You are not passing results anywhere. </p>
<p>Additionally you are iterating over tracks which is not defined in that function. Simply replace <code>tracks</code> with <code>results</code>. Then you are good to go.</p>
| 0 | 2016-08-20T23:06:30Z | [
"python",
"list",
"parameters",
"spotipy"
] |
Python | Insert Two Items in a List per Iteration with One-Liner | 39,059,001 | <p>Is it possible to insert in a list 2 items with one-liner?
For example, get <code>[1, 2, 3, 4]</code> by something like <code>[ x, x+1 for x in [1, 3]]</code></p>
| 2 | 2016-08-20T21:53:30Z | 39,059,057 | <p>No you can't do this. Instead you can use a generator expression within <code>itertools.chain.from_iterable</code> in order to chain the iterable items or use a nested list comprehension (which is not as optimized as <em><code>chain.from_iterable</code></em> since you have to create the items then unpack them with a... | 1 | 2016-08-20T22:00:44Z | [
"python",
"for-loop"
] |
Python | Insert Two Items in a List per Iteration with One-Liner | 39,059,001 | <p>Is it possible to insert in a list 2 items with one-liner?
For example, get <code>[1, 2, 3, 4]</code> by something like <code>[ x, x+1 for x in [1, 3]]</code></p>
| 2 | 2016-08-20T21:53:30Z | 39,059,210 | <pre><code>[item for sublist in [ [x, x+1] for x in [1, 3] ] for item in sublist]
</code></pre>
| 1 | 2016-08-20T22:23:54Z | [
"python",
"for-loop"
] |
Python - Create set from string | 39,059,029 | <p>I have strings in the format <code>"1-3 6:10-11 7-9"</code> and from them I want to create number sets as follows <code>{1,2,3,6,10,11,7,8,9}</code>. </p>
<p>For creating the set from the range of numbers, I have the following code:</p>
<pre><code>def create_set(src):
lset = []
if len(src) > 0:
... | 1 | 2016-08-20T21:56:39Z | 39,059,147 | <p>Something like this might work for you:</p>
<pre><code>s = '1-3 6:10-11 7-9'
s = s.replace(':', ' ')
lset = set()
fs = s.split()
for f in fs:
r = f.split('-')
if len(r)==1:
# add a single number
lset.add(int(r[0]))
else:
# add a range of numbers (inclusive of the endpoints)
... | 5 | 2016-08-20T22:16:17Z | [
"python",
"set"
] |
Python - Create set from string | 39,059,029 | <p>I have strings in the format <code>"1-3 6:10-11 7-9"</code> and from them I want to create number sets as follows <code>{1,2,3,6,10,11,7,8,9}</code>. </p>
<p>For creating the set from the range of numbers, I have the following code:</p>
<pre><code>def create_set(src):
lset = []
if len(src) > 0:
... | 1 | 2016-08-20T21:56:39Z | 39,062,399 | <blockquote>
<p>EDIT: By the way, is there a more compact way of parsing such strings,
perhaps using regular expressions?</p>
</blockquote>
<p>Perhaps a cleaner (and slightly more efficient) way:</p>
<pre><code>import re
import itertools
allGroups = re.findall(r"(\d+)(?:-(\d+)|:)", s)
expanded = [range(int(x), (... | 1 | 2016-08-21T08:38:49Z | [
"python",
"set"
] |
Randomly insert NA's values in a pandas dataframe | 39,059,032 | <p>How can I randomly insert NA's in a pandas dataframe ?
Let's say I want 10% of NA's in all the dataframe.</p>
<p>My data looks like this : </p>
<pre><code>df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'b', 'c', 'd', 'e'],columns=['one', 'two', 'three'])
one two three
a 0.695132 1.044791... | 0 | 2016-08-20T14:48:09Z | 39,059,033 | <p>Here's one way. I've interpreted your question as wanting to clear exactly 10% of cells (or rather, as close to 10% as can be achieved with the existing data frame's size), as opposed to, say, clearing cells independently with a marginal per-cell probability of 10%.</p>
<pre class="lang-python prettyprint-override"... | 1 | 2016-08-20T15:13:45Z | [
"python",
"missing-data"
] |
What's the shortest way of converting list of lists to a string, one inner list per line? | 39,059,052 | <p>I have a list of lists and I'm looking for the shortest way of converting that data to a string where every inner list appears on a new line.</p>
<p>Assuming my input list is:</p>
<pre><code>l_2d = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
</code></pre>
<p>I want my output to be a string (let's call it l_2d_str), so that... | -1 | 2016-08-20T22:00:36Z | 39,059,076 | <p>How about this?</p>
<pre><code>l_2d = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
l_2d_str = '\n'.join(map(repr, l_2d))
</code></pre>
| 6 | 2016-08-20T22:04:41Z | [
"python"
] |
PlaySound only plays default "SystemAsterisk" sound (Windows 10, C++, Python) | 39,059,082 | <p>I'm trying to use Windows' PlaySound function as mentioned here: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/dd743680(v=vs.85).aspx</a></p>
<p>However, nothing I try can change it from playing the d... | 0 | 2016-08-20T22:05:14Z | 39,059,311 | <p>This works for me in Windows 7 and in Windows 10:</p>
<pre><code>#undef UNICODE
#define UNICODE
#include <windows.h>
#include <stdlib.h>
auto main()
-> int
{
bool const ok = !!PlaySound( L"c:/windows/media/ringout.wav", 0, SND_ALIAS );
return (ok? EXIT_SUCCESS : EXIT_FAILURE);
}
</code>... | 0 | 2016-08-20T22:39:14Z | [
"python",
"c++",
"audio",
"windows-10",
"playsound"
] |
How to ensure data is written to geotiff using GDAL? | 39,059,122 | <p>I am working on a script that takes in a CSV file containing locations of measurements and creating a probability map based on those measurements. I am using GDAL to write the probabilities to a GeoTIFF, however, I am noticing that none of the data is properly written to the GeoTIFF. When generating the heatmap, I... | 0 | 2016-08-20T22:11:58Z | 39,059,535 | <p>Problem is in how QGIS computes the maximum and minimum of the GeoTIFF. If you go into the properties of the GeoTIFF layer, and open the Style tab, under Band Rendering, you can choose how to load the min/max values. By default, QGIS uses the 2% to 98% count as the minimum and maximum, however, for this, we want t... | 1 | 2016-08-20T23:18:11Z | [
"python",
"gis",
"gdal",
"qgis",
"geotiff"
] |
Django ORM - Adjust field value on return | 39,059,129 | <p>I have a model that stores user-entered database password. As my app needs to connect to these databases. The password is encrypted in the database. However, when it is retrieved I need to apply a <code>decrypt</code> function to the password field. Where can I do that so that it is only applied when querying the da... | 0 | 2016-08-20T22:12:35Z | 39,059,242 | <p>You can make the get_password method a <code>property</code> of the <code>Databases</code> class:</p>
<pre><code> @property
def get_password(self):
print("Retrieving")
return self.e.decrypt(self.password)
</code></pre>
<p>then you'll be able to use it in your serializer:</p>
<pre><code>clas... | 0 | 2016-08-20T22:28:54Z | [
"python",
"django",
"orm"
] |
PPrint not working (Python)? | 39,059,195 | <p>I'm trying to use Python's <code>pprint</code> on a dictionary but for some reason it isn't working. Here's my code (I'm using PyCharm Pro as my IDE):`</p>
<pre><code>from pprint import pprint
message = "Come on Eileen!"
count = {}
for character in message:
count.setdefault(character, 0)
count[character] +... | -2 | 2016-08-20T22:22:01Z | 39,059,212 | <p>The output is entirely correct and expected. From the <a href="https://docs.python.org/3/library/pprint.html" rel="nofollow"><code>pprint</code> module documentation</a>:</p>
<blockquote>
<p>The formatted representation <strong>keeps objects on a single line if it can</strong>, and breaks them onto multiple lines... | 1 | 2016-08-20T22:24:20Z | [
"python",
"python-3.x",
"pprint"
] |
Trouble installing pyGObject on python3 | 39,059,217 | <p>I keep getting error messages while trying to install PyGObject on python3 (Mac OS X 10.9)</p>
<pre><code> Traceback (most recent call last):
File "<string>", line 20, in <module>
File "/private/var/folders/zh/hww3rvgx1rg62zwc8ct51r1r0000gn/T/pip-build-v5qjvi2y/pygobject/setup.py", line 272
raise S... | 0 | 2016-08-20T22:24:45Z | 39,059,320 | <p>You are trying to install a python2 module with python 3. The syntax error occurs because there has been a change to the syntax for raising an exception. <code>raise SystemExit, 'Message'</code> has become <code>raise SystemExit('Message')</code></p>
<p>You should make sure that you have the python3 versions of the... | 0 | 2016-08-20T22:40:09Z | [
"python"
] |
Servlet equivalent in Python? | 39,059,225 | <p>On client side , following android code would make the call to the local server :</p>
<pre><code> String link = "http://localhost:8080/test/cgi-bin/test.py";
URL url = null;
try {
url = new URL(link);
HttpURLConnection client = (HttpURLConnection) url.openConnection();
... | 0 | 2016-08-20T22:26:40Z | 39,060,230 | <p>I've used <a href="http://www.cherrypy.org/" rel="nofollow">CherryPy</a> as a general purpose HTTP server framework. Ultimately to do the same as the servlet, there are many links - <a href="http://stackoverflow.com/questions/6211381/how-to-read-parameters-from-get-request-in-cherrypy">this one</a> seems to be pret... | 1 | 2016-08-21T02:02:35Z | [
"java",
"android",
"python",
"servlets"
] |
Troubles with XPath Plugin Python | 39,059,338 | <p>So i am getting the path id('page-content')/x:div[6]/x:div/x:div/x:div/x:a[1]/x:img</p>
<p>How would i go about clicking the img?</p>
<p>I've tried </p>
<p>lol=find_element_by_xpath("//div[@class='emoji-items nano-content']//a[@title=':heart:']/img")</p>
<p>as well as</p>
<p>lol=find_element_by_xpath("//a[@titl... | 1 | 2016-08-20T22:42:49Z | 39,059,468 | <p>What i did is: select all links elements (a) that contains heart in the title.</p>
<p>I tried to avoid using @title= because sometimes you might have issues due syntax used in the methods for finding the element or in other methods due to special characters like :.</p>
<p>The resulted path was:</p>
<pre><code>//a... | 0 | 2016-08-20T23:04:31Z | [
"python",
"selenium"
] |
Can numpy's argsort give equal element the same rank? | 39,059,371 | <p>I want to get the rank of each element, so I use <code>argsort</code> in <code>numpy</code>:</p>
<pre><code>np.argsort(np.array((1,1,1,2,2,3,3,3,3)))
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
</code></pre>
<p>it give the same element the different rank, can I get the same rank like:</p>
<pre><code>array([0, 0, 0, 3, 3, ... | 3 | 2016-08-20T22:46:45Z | 39,059,429 | <p>If you don't mind a dependency on scipy, you can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rankdata.html" rel="nofollow"><code>scipy.stats.rankdata</code></a>, with <code>method='min'</code>:</p>
<pre><code>In [14]: a
Out[14]: array([1, 1, 1, 2, 2, 3, 3, 3, 3])
In [15]: from scip... | 5 | 2016-08-20T22:56:34Z | [
"python",
"sorting",
"numpy"
] |
Can numpy's argsort give equal element the same rank? | 39,059,371 | <p>I want to get the rank of each element, so I use <code>argsort</code> in <code>numpy</code>:</p>
<pre><code>np.argsort(np.array((1,1,1,2,2,3,3,3,3)))
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
</code></pre>
<p>it give the same element the different rank, can I get the same rank like:</p>
<pre><code>array([0, 0, 0, 3, 3, ... | 3 | 2016-08-20T22:46:45Z | 39,059,720 | <p>Alternatively, pandas series has a <code>rank</code> method which does what you need with the <code>min</code> method:</p>
<pre><code>import pandas as pd
pd.Series((1,1,1,2,2,3,3,3,3)).rank(method="min")
# 0 1
# 1 1
# 2 1
# 3 4
# 4 4
# 5 6
# 6 6
# 7 6
# 8 6
# dtype: float64
</code></pre>... | 2 | 2016-08-20T23:58:32Z | [
"python",
"sorting",
"numpy"
] |
Can numpy's argsort give equal element the same rank? | 39,059,371 | <p>I want to get the rank of each element, so I use <code>argsort</code> in <code>numpy</code>:</p>
<pre><code>np.argsort(np.array((1,1,1,2,2,3,3,3,3)))
array([0, 1, 2, 3, 4, 5, 6, 7, 8])
</code></pre>
<p>it give the same element the different rank, can I get the same rank like:</p>
<pre><code>array([0, 0, 0, 3, 3, ... | 3 | 2016-08-20T22:46:45Z | 39,060,835 | <p>With focus on performance, here's an approach -</p>
<pre><code>def rank_repeat_based(arr):
idx = np.concatenate(([0],np.flatnonzero(np.diff(arr))+1,[arr.size]))
return np.repeat(idx[:-1],np.diff(idx))
</code></pre>
<p>For a generic case with the elements in input array not already sorted, we would need to ... | 2 | 2016-08-21T04:27:10Z | [
"python",
"sorting",
"numpy"
] |
Python Sockets - how can I get the IP Address of a Socket after I bind it to an IP | 39,059,418 | <p>From the python library 'socket' is there a method that returns the IP of the socket that got binded to it?</p>
<p>Suppose a socket was declared and initialized like:</p>
<pre><code>sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.connect(ip, port)
</code></pre>
<p>And I wanted to find the IP of a rec... | 0 | 2016-08-20T22:54:07Z | 39,059,505 | <p>Try with <a href="https://docs.python.org/2/library/socket.html#socket.socket.getpeername" rel="nofollow"><code>socket.getpeername()</code></a>.</p>
| 0 | 2016-08-20T23:10:56Z | [
"python",
"python-sockets"
] |
IMDbPY get the stars of a movie | 39,059,530 | <p>I was able to get the cast of the movie like this:</p>
<pre><code>#!/usr/bin/env python
import imdb
ia = imdb.IMDb()
s_result = ia.search_movie('The Untouchables')
the_unt = s_result[0]
print the_unt['cast']
</code></pre>
<p>However, that gave all the <em>cast</em>, i am looking for just the <em>stars</em> of the ... | -2 | 2016-08-20T23:16:51Z | 39,059,696 | <p>As stated in the comments, IMDb does not know the concept of a "star", but it does somewhat know the "top actors" from the cast lineup. </p>
<p>It is probably based on the credits of the film, but even IMDb says <em>first billed only</em> for some movies. </p>
<p>The cast ordering is entirely dependent on the movi... | 3 | 2016-08-20T23:53:49Z | [
"python",
"movie",
"imdb",
"imdbpy"
] |
pyximport with cgal build error: undefined symbol "__gmpq_equal" | 39,059,539 | <p>I am running Debian 8 with a packaged install of Cython (apt-get install cython).</p>
<p>I am compiling my .pyx file with the CGAL (<a href="http://www.cgal.org" rel="nofollow">www.cgal.org</a>) but return the error:</p>
<pre><code>import pyximport; pyximport.install()
from spaces import spaces_rectangle
</code></... | -1 | 2016-08-20T23:19:04Z | 39,061,783 | <p>gmp library may be missing from libraries,</p>
<pre><code>strings -f /usr/lib/x86_64-linux-gnu/*.a |grep gmpq_equal
</code></pre>
<p>outputs</p>
<pre><code>/usr/lib/x86_64-linux-gnu/libgmp.a: __gmpq_equal
/usr/lib/x86_64-linux-gnu/libgmp.a: __gmpq_equal
</code></pre>
| 0 | 2016-08-21T07:16:45Z | [
"python",
"linux",
"cython",
"cgal"
] |
pyximport with cgal build error: undefined symbol "__gmpq_equal" | 39,059,539 | <p>I am running Debian 8 with a packaged install of Cython (apt-get install cython).</p>
<p>I am compiling my .pyx file with the CGAL (<a href="http://www.cgal.org" rel="nofollow">www.cgal.org</a>) but return the error:</p>
<pre><code>import pyximport; pyximport.install()
from spaces import spaces_rectangle
</code></... | -1 | 2016-08-20T23:19:04Z | 39,070,144 | <p>Solution:</p>
<pre><code>def make_ext(modname, pyxfilename):
from distutils.extension import Extension
return Extension(name=modname,
sources=[pyxfilename],
include_dirs=['.'],
libraries=['CGAL','gmp'],
language='c++',
extra_compil... | 1 | 2016-08-22T00:58:42Z | [
"python",
"linux",
"cython",
"cgal"
] |
Using A For Loop to Return Unique Values in a Pandas Dataframe | 39,059,631 | <p>I know Pandas isn't really built to use with for-loops, but I have a specific task I'll have to do many times and it'd really save a lot of time if I could abstract some of it away with a function that I can call.</p>
<p>A generic version of my dataframe looks like this: </p>
<pre><code>df = pd.DataFrame({'Name':... | 2 | 2016-08-20T23:39:35Z | 39,059,685 | <p>You can set the name as index and then search by index using <code>loc</code>:</p>
<pre><code>the_names = ['John Doe', 'Jane Doe', 'Bob Smith']
df.set_index('Name').loc[the_names, 'Score2']
# Name
# John Doe 3
# Jane Doe 4
# Bob Smith 5
# Name: Score2, dtype: int32
</code></pre>
| 3 | 2016-08-20T23:51:54Z | [
"python",
"pandas"
] |
Using A For Loop to Return Unique Values in a Pandas Dataframe | 39,059,631 | <p>I know Pandas isn't really built to use with for-loops, but I have a specific task I'll have to do many times and it'd really save a lot of time if I could abstract some of it away with a function that I can call.</p>
<p>A generic version of my dataframe looks like this: </p>
<pre><code>df = pd.DataFrame({'Name':... | 2 | 2016-08-20T23:39:35Z | 39,059,698 | <p>You actually don't need the loop, you can just do this:</p>
<pre><code>print(df.loc[df.Name == the_names, 'Score2'])
0 3
1 4
2 5
Name: Score2, dtype: int32
</code></pre>
| 2 | 2016-08-20T23:54:04Z | [
"python",
"pandas"
] |
Using A For Loop to Return Unique Values in a Pandas Dataframe | 39,059,631 | <p>I know Pandas isn't really built to use with for-loops, but I have a specific task I'll have to do many times and it'd really save a lot of time if I could abstract some of it away with a function that I can call.</p>
<p>A generic version of my dataframe looks like this: </p>
<pre><code>df = pd.DataFrame({'Name':... | 2 | 2016-08-20T23:39:35Z | 39,061,796 | <p>First things first. You have an error in your logic in that when you establish your <code>for</code> loop, you use the things in <code>people</code> as if they are indices for the list <code>people</code> when they are the things in <code>people</code>. So instead, do</p>
<pre><code>def pull_score(df, people, sco... | 2 | 2016-08-21T07:18:39Z | [
"python",
"pandas"
] |
How can I connect multiple if statements when using regular expressions? | 39,059,664 | <p>Below is the code for a password verification process with at least one lowercase, one uppercase and one number.</p>
<pre><code>import re
password=raw_input('Enter the Password')
x= (re.findall(r'[a-z]',password))
if len(x)==0:
print " at least one 'a-z' requirment not completed"
else:
#(what should i write ... | 1 | 2016-08-20T23:44:54Z | 39,059,715 | <p>Basically, your else clause is just going to be the next statement, like so. You pretty much wrote it, all you have to do is indent each of the check.</p>
<pre><code> import re
password=raw_input('Enter the Password')
x= (re.findall(r'[a-z]',password))
if len(x)==0:
print " at least one 'a-... | 0 | 2016-08-20T23:57:23Z | [
"python",
"python-2.7"
] |
How can I connect multiple if statements when using regular expressions? | 39,059,664 | <p>Below is the code for a password verification process with at least one lowercase, one uppercase and one number.</p>
<pre><code>import re
password=raw_input('Enter the Password')
x= (re.findall(r'[a-z]',password))
if len(x)==0:
print " at least one 'a-z' requirment not completed"
else:
#(what should i write ... | 1 | 2016-08-20T23:44:54Z | 39,059,721 | <pre><code>import re
password=raw_input('Enter the Password: ')
problems = []
x = re.findall(r'[a-z]',password)
if not x:
problems.append("at least one 'a-z' requirment not completed")
y = re.findall(r'[A-Z]',password)
if not y:
problems.append("at least one 'A-Z' requirement not completed")
z = re.findall(r'[... | 1 | 2016-08-20T23:59:13Z | [
"python",
"python-2.7"
] |
How can I connect multiple if statements when using regular expressions? | 39,059,664 | <p>Below is the code for a password verification process with at least one lowercase, one uppercase and one number.</p>
<pre><code>import re
password=raw_input('Enter the Password')
x= (re.findall(r'[a-z]',password))
if len(x)==0:
print " at least one 'a-z' requirment not completed"
else:
#(what should i write ... | 1 | 2016-08-20T23:44:54Z | 39,059,754 | <p>Here is a way to do it only using string methods! </p>
<pre><code>p = raw_input('enter password')
if p.islower() or p.isupper() or not any(c.isdigit() for c in p):
print('bad password')
</code></pre>
| 1 | 2016-08-21T00:09:11Z | [
"python",
"python-2.7"
] |
How can I connect multiple if statements when using regular expressions? | 39,059,664 | <p>Below is the code for a password verification process with at least one lowercase, one uppercase and one number.</p>
<pre><code>import re
password=raw_input('Enter the Password')
x= (re.findall(r'[a-z]',password))
if len(x)==0:
print " at least one 'a-z' requirment not completed"
else:
#(what should i write ... | 1 | 2016-08-20T23:44:54Z | 39,059,811 | <p>Use <code>if-elif</code> statement:</p>
<pre><code>import re
password=raw_input('Enter the Password')
if len(re.findall(r'[a-z]',password))==0:
print " at least one 'a-z' requirment not completed"
elif len(re.findall(r'[A-Z]',password)) == 0:
print "at least one 'A-Z' requirement not completed"
elif len(re... | 2 | 2016-08-21T00:19:34Z | [
"python",
"python-2.7"
] |
Batch processing and breaking up an image | 39,059,668 | <p>I'm trying to segment each charm item in this collective image.</p>
<p>The shapes are irregular and inconsistent:</p>
<p><a href="https://i.imgur.com/sf8nOau.jpg" rel="nofollow">https://i.imgur.com/sf8nOau.jpg</a></p>
<p>I have another image where there is some consistency with the top row of items, but ideally I... | 1 | 2016-08-20T23:45:29Z | 39,061,539 | <h1>Code</h1>
<pre><code>import cv2
import numpy as np
im=cv2.imread('so1.jpg')
gray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret, thresh = cv2.threshold(gray,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)
kernel = np.ones((3,3),np.uint8)
res = cv2.dilate(thresh,kernel,iterations = 1)
res = cv2.erode(res,kernel,iteratio... | 3 | 2016-08-21T06:44:04Z | [
"python",
"opencv"
] |
Object orientated function parameter to alter variables | 39,059,671 | <p>I am trying convert my program to an object orientated style. Currently, I have a brandSelector() function which takes the query input and finds an intersection between the query and the brands array. However, I am trying to convert the brandSelector() to a generic Selector() or intersection finder. For example, I c... | 1 | 2016-08-20T23:45:59Z | 39,059,787 | <p>From what I can see, there's no reason to have the argument named <code>var</code> being passed to <code>Selector()</code>, so just make it <code>def Selector(array, query):</code> and call it with <code>brand = Selector(brands, query)</code>.</p>
| 1 | 2016-08-21T00:14:18Z | [
"python",
"function",
"oop",
"parameters"
] |
confused about Python list syntax | 39,059,714 | <p>Here is the code and related document (<a href="http://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html#sklearn.datasets.load_iris" rel="nofollow">http://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html#sklearn.datasets.load_iris</a>), I am confused by this line, <co... | 1 | 2016-08-20T23:57:14Z | 39,059,758 | <p>Your confusion is understandable: this isn't "standard" Python by any means.</p>
<p><code>data.target</code> in this case is an <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.html" rel="nofollow"><code>ndarray</code></a> from numpy:</p>
<pre><code>In [1]: from sklearn.datasets import lo... | 1 | 2016-08-21T00:09:29Z | [
"python",
"python-2.7",
"numpy",
"scikit-learn"
] |
confused about Python list syntax | 39,059,714 | <p>Here is the code and related document (<a href="http://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html#sklearn.datasets.load_iris" rel="nofollow">http://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_iris.html#sklearn.datasets.load_iris</a>), I am confused by this line, <co... | 1 | 2016-08-20T23:57:14Z | 39,059,812 | <p>This is retrieving elements from a numpy array <code>A</code> using "integer indexing" syntax (as opposed to the usual subscripts), i.e. a list of integers <code>B</code> will be used to find elements at those particular indices in <code>A</code>. Your output is a numpy array with the same shape as the list <code>B<... | 1 | 2016-08-21T00:19:37Z | [
"python",
"python-2.7",
"numpy",
"scikit-learn"
] |
using matplotlib on Mac for Python 2.7 | 39,059,732 | <p>Wondering if anyone have met with similar issues on Mac OSX? If so, how do you resolve? Thanks.</p>
<p>Here are document, code and error message,</p>
<p><a href="http://scikit-learn.org/stable/auto_examples/linear_model/plot_iris_logistic.html" rel="nofollow">http://scikit-learn.org/stable/auto_examples/linear_mod... | 1 | 2016-08-21T00:02:06Z | 39,059,779 | <p>Are you using a virtual enviorment? Right now it thinks your python isn't a framework. in your terminal run </p>
<pre><code>which python
</code></pre>
<p>and make sure it returns</p>
<pre><code>/Library/Frameworks/Python.framework/Versions/2.7/bin/python
</code></pre>
<p>you can always intall python as a framewo... | 1 | 2016-08-21T00:12:23Z | [
"python",
"python-2.7",
"matplotlib",
"scikit-learn"
] |
How to see the subscribers count of a youtube channel using the gdata api in python | 39,059,797 | <p>im trying to make a raspberry pi youtube sub monitor and im confused about how to get the sub count from youtube channel in python.an example code to do so would be much appreciated. </p>
| -1 | 2016-08-21T00:17:08Z | 39,066,043 | <p>Please make yourself familiar with the <a href="https://developers.google.com/youtube/v3/getting-started" rel="nofollow">basic YouTube Data API v3 workflows</a> first.</p>
<p>There are different ways to use the API with Python. Since your application does not seem to be very complex, you could <a href="https://deve... | 0 | 2016-08-21T15:50:48Z | [
"python",
"google-api",
"youtube-api",
"youtube-data-api",
"gdata"
] |
How to see the subscribers count of a youtube channel using the gdata api in python | 39,059,797 | <p>im trying to make a raspberry pi youtube sub monitor and im confused about how to get the sub count from youtube channel in python.an example code to do so would be much appreciated. </p>
| -1 | 2016-08-21T00:17:08Z | 39,071,642 | <p>Make a REST call in PYTHON using this URI request:</p>
<pre><code>GET https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mySubscribers=true&fields=pageInfo&key={YOUR_API_KEY}
</code></pre>
<p>The totalResults key holds the number of subscribers. An example of response I got looked like th... | 0 | 2016-08-22T04:55:27Z | [
"python",
"google-api",
"youtube-api",
"youtube-data-api",
"gdata"
] |
Handling recursive error tracebacks in python | 39,059,859 | <p>I'm working on implementing a small programming languge in Python for the hell of it, and the language's execution basically consists of recursive calls to a function called <code>execute</code>. I've implemented my own error handling, but in order to have that error handling work I need to catch some exceptions and... | 1 | 2016-08-21T00:27:45Z | 39,059,894 | <p>You need to set try statements when ever needed. </p>
<p>Put it only on start of execution.</p>
<p>try statement is basically is a longjump. You want to do some long tasks which may fail at any place in the code it can be in inner calls. longjump helps you to catch fails.</p>
<p>In lua language there's method cal... | 0 | 2016-08-21T00:36:11Z | [
"python",
"recursion",
"error-handling"
] |
Handling recursive error tracebacks in python | 39,059,859 | <p>I'm working on implementing a small programming languge in Python for the hell of it, and the language's execution basically consists of recursive calls to a function called <code>execute</code>. I've implemented my own error handling, but in order to have that error handling work I need to catch some exceptions and... | 1 | 2016-08-21T00:27:45Z | 39,059,896 | <p>If you <em>really</em> want to do this, try creating a mapping between base exception types and your new exception types:</p>
<pre><code>exceptionMap = {
IndexError: MyIndexError,
# ...
}
def execute(...):
try:
# do stuff
except tuple(exceptionMap) as e:
raise exceptionMap[type(e)](e,... | 0 | 2016-08-21T00:36:23Z | [
"python",
"recursion",
"error-handling"
] |
SciPy on Windows with Python 2.7 install issues | 39,059,903 | <p>Wondering if anyone met with similar issues and have solutions already? Using Windows 7.</p>
<pre><code>C:\Python27\Scripts>pip install SciPy
Collecting SciPy
Using cached scipy-0.18.0.tar.gz
Installing collected packages: SciPy
Running setup.py install for SciPy ... error
Complete output from command c:... | 0 | 2016-08-21T00:39:24Z | 39,060,196 | <p>Some packages, such as Scipy, require a compiler to be built using pip. Windows does not come with a compiler included, so you need to download a scipy binary file that windows can work with. </p>
<p>A wonderful man named Christopher Gohlke from UC Irvine has developed these binaries for windows. You can find them ... | 2 | 2016-08-21T01:53:23Z | [
"python",
"windows",
"python-2.7",
"windows-7",
"scipy"
] |
Best way to refer to other instances of a class or other objects? | 39,059,915 | <p>I have a Network(object) and Node(object) classes, and each node belongs to a different network (there are also link objects that connects nodes, etc, but let's ignore this). What is the best way to keep track which object is in which network and vice versa?</p>
<p>What I am doing now is to have a dictionary attrib... | 0 | 2016-08-21T00:41:43Z | 39,060,004 | <p>This is pretty good way to keep track of reasonable amount of entries at one execution. But not if you want it to be persistent.</p>
<p>If you can order the nodes by some valuable property you got a even better way. +it can be easily persistent</p>
<p>For example i had this issue myself. I was trying to implement ... | 0 | 2016-08-21T01:02:47Z | [
"python",
"class"
] |
ImportError: No module named services Django | 39,060,020 | <p>I installed python 2.7 alongside my mac. I have a project running using Django v1.9.4.
Unfortunately <code>manage.py runserver</code> is throwing an error while running failed because it couldn't find module named services.</p>
<p>From a shell:</p>
<pre><code>Traceback (most recent call last):
File "./manage.py"... | 0 | 2016-08-21T01:06:48Z | 39,060,370 | <p>It seems that 'services' is your project's module.
Maybe you should set the PYTHONPATH environment to make python find your module.
If the module is in current directory, you can run the project like this:
export PYTHONPATH=.:$PYTHONPATH
manage.py runserver</p>
| 1 | 2016-08-21T02:34:06Z | [
"python",
"django",
"python-2.7",
"backend"
] |
Graph only shows the data in 1 graph but not the other | 39,060,073 | <p>I'm having trouble with my code. It's only showing the data for one graph and the other graph is blank. I can't figure why it's not working.<br>
I'm using the <code>subplot()</code> function and my guess is that the the reason might be the way my function are formatted.</p>
<pre><code>import numpy as np
import matp... | 1 | 2016-08-21T01:21:48Z | 39,060,084 | <p>You need to move the line <code>plt.subplot(211)</code> before your first call to <code>plt.plot</code>. This is because calls to <code>plt.subplot</code> must precede the actual plotting in that subplot.</p>
| 2 | 2016-08-21T01:25:31Z | [
"python",
"python-3.x",
"matplotlib"
] |
How to do exception handling in python? | 39,060,162 | <pre><code>elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
if ( elem.is_selected() ):
print "already selected"
else:
elem.click()
</code></pre>
<p>In my code <code>elem.click()</code> gets gives an error sometimes. If it does, I need to call <code... | -1 | 2016-08-21T01:44:38Z | 39,060,176 | <p>You need try/except statement there.</p>
<pre><code>try:
elem.click()
except Exception: # you need to find out which exception type is raised
pass
# do somthing else ...
</code></pre>
| 0 | 2016-08-21T01:49:34Z | [
"python",
"python-2.7",
"exception-handling"
] |
How to do exception handling in python? | 39,060,162 | <pre><code>elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
if ( elem.is_selected() ):
print "already selected"
else:
elem.click()
</code></pre>
<p>In my code <code>elem.click()</code> gets gives an error sometimes. If it does, I need to call <code... | -1 | 2016-08-21T01:44:38Z | 39,060,185 | <p>generic way to handle exception in python is</p>
<pre><code>try:
1/0
except Exception, e:
print e
</code></pre>
<p>So in your case it would give</p>
<pre><code>try:
elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
except Exception, e:... | 0 | 2016-08-21T01:51:12Z | [
"python",
"python-2.7",
"exception-handling"
] |
How to do exception handling in python? | 39,060,162 | <pre><code>elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
if ( elem.is_selected() ):
print "already selected"
else:
elem.click()
</code></pre>
<p>In my code <code>elem.click()</code> gets gives an error sometimes. If it does, I need to call <code... | -1 | 2016-08-21T01:44:38Z | 39,060,190 | <p>Look at <code>try</code> and <code>except</code></p>
<pre><code>while elem == None:
try:
elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
if ( elem.is_selected() ):
print "already selected"
else:
elem.... | 0 | 2016-08-21T01:52:35Z | [
"python",
"python-2.7",
"exception-handling"
] |
How to do exception handling in python? | 39,060,162 | <pre><code>elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
if ( elem.is_selected() ):
print "already selected"
else:
elem.click()
</code></pre>
<p>In my code <code>elem.click()</code> gets gives an error sometimes. If it does, I need to call <code... | -1 | 2016-08-21T01:44:38Z | 39,060,199 | <p>From what I can understand this can be done with exception handling.
you could try the following:</p>
<pre><code>elem = browser.find_element_by_xpath(".//label[@class = 'checkbox' and contains(.,'Ãltimos 15 dÃas')]/input")
if ( elem.is_selected() ):
print "already selected"
else:
while True:
try:
... | 2 | 2016-08-21T01:54:06Z | [
"python",
"python-2.7",
"exception-handling"
] |
Regex to Match Domain Name | 39,060,217 | <pre><code>^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$
</code></pre>
<p>I tried the code above but it would not match any domain no matter how ugly.</p>
<p>I am try to match only domain with words and ending in .com</p>
<pre><code>Like
google.com
yahoo.com
bing.com
Not
google.net
google.con
googl-e.com
</code></pre>
| -1 | 2016-08-21T01:59:28Z | 39,060,272 | <p>I often have problems with the $ in the end, so I'd add \s* after the ^ and before the $ operators, to detect leading/trailing separator-characters. Can't reason too much without knowing the context.</p>
<pre><code>^\s*([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}\s*$
</code></pre>
| -1 | 2016-08-21T02:10:25Z | [
"python",
"regex"
] |
Regex to Match Domain Name | 39,060,217 | <pre><code>^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$
</code></pre>
<p>I tried the code above but it would not match any domain no matter how ugly.</p>
<p>I am try to match only domain with words and ending in .com</p>
<pre><code>Like
google.com
yahoo.com
bing.com
Not
google.net
google.con
googl-e.com
</code></pre>
| -1 | 2016-08-21T01:59:28Z | 39,060,708 | <p>What's the purpose of the <code>-[a-z0-9]+</code> group? I got your six test cases to pass with:</p>
<pre><code>import re
r = re.compile("^([a-z0-9]+\.)com$")
# Like
assert r.match('google.com')
assert r.match('yahoo.com')
assert r.match('bing.com')
# Not
assert not r.match('google.net')
assert not r.match('goog... | 1 | 2016-08-21T03:54:05Z | [
"python",
"regex"
] |
Regex to Match Domain Name | 39,060,217 | <pre><code>^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$
</code></pre>
<p>I tried the code above but it would not match any domain no matter how ugly.</p>
<p>I am try to match only domain with words and ending in .com</p>
<pre><code>Like
google.com
yahoo.com
bing.com
Not
google.net
google.con
googl-e.com
</code></pre>
| -1 | 2016-08-21T01:59:28Z | 39,062,862 | <p>Your code did not match any because it uses the <code>^</code> and <code>$</code>which matches the start and end of string. To make it match the start and end of a line, you have to enable the multiline option <code>re.M</code>. In addition, use <code>re.I</code> to make it case insensitive which I believe domain ... | 0 | 2016-08-21T09:42:22Z | [
"python",
"regex"
] |
Using Keras for text classification | 39,060,283 | <p>I am struggling to approach the bag of words / vocabulary method for representing my input data as one hot vectors for my neural net model in keras. </p>
<p>I would like to build a simple 3 layer network but I need help in understanding and developing an approach to transform my labelled data in the form of text,se... | 0 | 2016-08-21T02:13:50Z | 39,060,552 | <p><a href="https://github.com/fchollet/keras/blob/master/examples/reuters_mlp.py" rel="nofollow">Here</a> is a Keras example where they have 8 output classes and use a bag of words.</p>
| 0 | 2016-08-21T03:18:47Z | [
"python",
"nlp",
"keras",
"text-classification"
] |
numpy issue on Python 2.7 -- numpy.dtype has the wrong size | 39,060,353 | <p>Wondering if anyone met with similar issues before and any solutions? Using Python 2.7 on Mac OSX.</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model, datasets
# import some data to play with
iris = datasets.load_iris()
X = iris.data[:, :2] # we only take the first ... | 0 | 2016-08-21T02:30:23Z | 39,060,378 | <p>Your code works fine for me, which suggests it's an environment error.</p>
<p>Try running <code>sudo pip install --upgrade --force-reinstall numpy sklearn</code> and see if that does the trick.</p>
<p>If you installed via Homebrew: <code>brew install --force numpy</code> (there's no <code>sklearn</code> homebrew p... | 2 | 2016-08-21T02:35:36Z | [
"python",
"osx",
"python-2.7",
"numpy"
] |
How can i install twilio package via pip? | 39,060,397 | <p>I have <strong>Python 2.7.12</strong> (64 bit) installed on my Windows machine.
When I installed it, I added <strong>pip</strong> and the <strong>python.exe</strong> path.
Now when I try to install <strong>Twilio</strong> with</p>
<pre><code>pip install twilio
</code></pre>
<p>I get the error </p>
<pre><code>pip... | 1 | 2016-08-21T02:40:35Z | 39,060,534 | <p>Please include c:\python27\Scripts in SYSTEM PATH</p>
<p>Procedure to add c:\python27\Scripts to system path:</p>
<ol>
<li>From the desktop, right click the Computer icon.</li>
<li>Choose Properties from the context menu.</li>
<li>Click the Advanced system settings link.</li>
<li>Click Environment Variables. In th... | 1 | 2016-08-21T03:14:15Z | [
"python",
"twilio"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.