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 override search_read() method in Odoo v.9? | 38,651,051 | <p><strong>Impacted versions: 9.0</strong></p>
<p>I am try to restrict some products based on category. </p>
<p>I have override <em>name_search()</em> method which work fine for <em>Many2one</em> field. But When I search product from search more option in <em>Many2one</em> field or search product from search menu in ... | 0 | 2016-07-29T05:24:49Z | 38,655,553 | <p>It should be something like this:</p>
<pre class="lang-py prettyprint-override"><code>@api.model
def search_read(
self, domain=None, fields=None, offset=0,
limit=None, order=None):
res = super(Product, self).search_read(
domain, fields, offset, limit, order)
return res
</code></pre>
| 1 | 2016-07-29T09:43:11Z | [
"python",
"openerp",
"odoo-8",
"odoo-9"
] |
How to remove arrow on tooltip from bokeh plot | 38,651,060 | <p>Is there a way to remove the little black pointer arrow that is on the tooltip (indicating the position of the mouse when the <code>point_policy='follow_mouse'</code>)?
Any help appreciated</p>
<p><a href="http://i.stack.imgur.com/6RJZu.png" rel="nofollow"><img src="http://i.stack.imgur.com/6RJZu.png" alt="enter im... | 1 | 2016-07-29T05:25:58Z | 38,661,964 | <p>The <em>answer</em> is that is is not currently any configuration option for this as of Bokeh <code>0.12.1</code>. </p>
<hr>
<p>Here is some additional information that may be useful, however. I'd encourage you to open an issue for discussion of this potential feature on the project issue tracker:</p>
<p><a href=... | 1 | 2016-07-29T15:02:19Z | [
"python",
"python-3.x",
"bokeh"
] |
How to remove arrow on tooltip from bokeh plot | 38,651,060 | <p>Is there a way to remove the little black pointer arrow that is on the tooltip (indicating the position of the mouse when the <code>point_policy='follow_mouse'</code>)?
Any help appreciated</p>
<p><a href="http://i.stack.imgur.com/6RJZu.png" rel="nofollow"><img src="http://i.stack.imgur.com/6RJZu.png" alt="enter im... | 1 | 2016-07-29T05:25:58Z | 38,662,516 | <p>As of Bokeh <strong>0.12.2</strong>, there is in option for that:</p>
<pre><code>hover.show_arrow = False
</code></pre>
<p>This is a complete example, taken from the <a href="http://bokeh.pydata.org/en/latest/docs/user_guide/quickstart.html#getting-started" rel="nofollow">official documentation</a>:</p>
<pre><cod... | 1 | 2016-07-29T15:32:00Z | [
"python",
"python-3.x",
"bokeh"
] |
How to generate a dict from string separated by semicolon? | 38,651,123 | <p>I am using Beautifulsoup to search for a specific number in HTML but got stuck here.</p>
<pre><code>The raw data is:
<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='000000'; bookmarkable_type=''; ">
</code></pre>
<p>... | 2 | 2016-07-29T05:31:16Z | 38,651,207 | <p>You can use re to search on questionID_line,</p>
<pre><code>import re
re.findall("bookmarkable_id='(.*?)'", questionID_line)
</code></pre>
| 1 | 2016-07-29T05:38:47Z | [
"python",
"beautifulsoup"
] |
How to generate a dict from string separated by semicolon? | 38,651,123 | <p>I am using Beautifulsoup to search for a specific number in HTML but got stuck here.</p>
<pre><code>The raw data is:
<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='000000'; bookmarkable_type=''; ">
</code></pre>
<p>... | 2 | 2016-07-29T05:31:16Z | 38,651,261 | <p>Use <code>split()</code>:</p>
<pre><code>data="bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='793447'; bookmarkable_type='Question'"
output = {i.split("=")[0].strip():i.split("=")[1].strip() for i in data.split(";")}
</code></pre>
<p>Output</p>
<pre><code>{'bookmarks_path': ... | 1 | 2016-07-29T05:42:48Z | [
"python",
"beautifulsoup"
] |
How to generate a dict from string separated by semicolon? | 38,651,123 | <p>I am using Beautifulsoup to search for a specific number in HTML but got stuck here.</p>
<pre><code>The raw data is:
<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='000000'; bookmarkable_type=''; ">
</code></pre>
<p>... | 2 | 2016-07-29T05:31:16Z | 38,651,284 | <p>Try this:</p>
<pre><code>data = "bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='793447'; bookmarkable_type='Question'"
fields = {}
for f in data.split('; '):
k , v = f.split('=')
fields[k] = v.strip("'")
print(fields)
</code></pre>
<p>Gives:</p>
<pre><code>{'bookma... | 4 | 2016-07-29T05:44:01Z | [
"python",
"beautifulsoup"
] |
How to generate a dict from string separated by semicolon? | 38,651,123 | <p>I am using Beautifulsoup to search for a specific number in HTML but got stuck here.</p>
<pre><code>The raw data is:
<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='000000'; bookmarkable_type=''; ">
</code></pre>
<p>... | 2 | 2016-07-29T05:31:16Z | 38,651,409 | <p>Try this</p>
<pre><code>s = """
<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='000000'; bookmarkable_type=''; ">
"""
import re
data = re.findall("bookmark[^=]*='[^']*",s)
dict1 = {}
for j in (data):
one,two = j.... | 0 | 2016-07-29T05:53:13Z | [
"python",
"beautifulsoup"
] |
How to generate a dict from string separated by semicolon? | 38,651,123 | <p>I am using Beautifulsoup to search for a specific number in HTML but got stuck here.</p>
<pre><code>The raw data is:
<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks'; bookmarkable_id='000000'; bookmarkable_type=''; ">
</code></pre>
<p>... | 2 | 2016-07-29T05:31:16Z | 38,652,519 | <p>If you don't remove the last <code>"; "</code> trying to unpack will cause an error as split will leave an odd empty string at the end:</p>
<pre><code>from bs4 import BeautifulSoup
html = """<div class='box_content' hn_bookmark='true' ng_init=" bookmarked=false; bookmark_id=''; bookmarks_path='/en-US/bookmarks';... | 0 | 2016-07-29T07:06:03Z | [
"python",
"beautifulsoup"
] |
Why python doesn't have Garbage Collector thread? | 38,651,571 | <p>Java has daemon thread to monitor memory usage and do the gc task. From jstack I see</p>
<pre><code>"main" #1 prio=5 os_prio=0 tid=0x00007f34b000e000 nid=0x808 waiting on condition [0x00007f34b6f02000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
....
"GC task thr... | 0 | 2016-07-29T06:05:09Z | 38,660,680 | <p>If you start java with <code>-XX:+UseSerialGC</code> options you will not see any GC thread.
For single threaded GC algorithm application thread can be used to do GC activities.</p>
<p>Dedicated threads required for</p>
<ul>
<li>Parallel GC (you need more than single thread)</li>
<li>Concurrent GC (GC activities r... | 1 | 2016-07-29T13:55:23Z | [
"python",
"garbage-collection"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,651,757 | <p>You could use <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> (it does exactly what you want - groups consecutive elements) and count all groups which starts with <code>1</code>:</p>
<pre><code>In [1]: from itertools import groupby
In [... | 11 | 2016-07-29T06:17:48Z | [
"python",
"arrays",
"time-series"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,651,947 | <pre><code>def num_events(list):
total = 0
in_event = 0
for current in list:
if current and not in_event:
total += 1
in_event = current
return total
</code></pre>
<p>This function iterates over the list from the left side and every time it encounters a 1 immediately after a ... | 1 | 2016-07-29T06:30:58Z | [
"python",
"arrays",
"time-series"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,652,078 | <p>Math way (be careful with an empty array):</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
events = (a[0] + a[-1] + sum(a[i] != a[i-1] for i in range(1, len(a)))) / 2
print events
</code></pre>
<p>I like to think this is efficient :)</p>
| 2 | 2016-07-29T06:40:08Z | [
"python",
"arrays",
"time-series"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,652,189 | <p>Try this</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
flag = 0
cnt = 0
for j in (a):
if( j == 1):
if(flag == 0):
cnt += 1
flag = 1
elif (j == 0):
flag = 0
print cnt
</code></pre>
| 1 | 2016-07-29T06:46:12Z | [
"python",
"arrays",
"time-series"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,652,540 | <p>One more:</p>
<pre><code>sum([(a[i] - a[i-1])>0 for i in range(1, len(a))])
</code></pre>
| 1 | 2016-07-29T07:07:30Z | [
"python",
"arrays",
"time-series"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,654,998 | <p>Me being a simpleton ;-)</p>
<pre><code>def get_number_of_events(event_list):
num_of_events = 0
for index, value in enumerate(event_list):
if 0 in (value, index):
continue
elif event_list[index-1] == 0:
num_of_events += 1
return num_of_events
</code></pre>
| 0 | 2016-07-29T09:16:20Z | [
"python",
"arrays",
"time-series"
] |
count number of events in an array python | 38,651,692 | <p>I have the following array:</p>
<pre><code>a = [0,0,0,1,1,1,0,0,1,0,0,0,1,1,0,0,0,0,0,0,1,1,0,1,1,1,0,0,0]
</code></pre>
<p>Each time I have a '1' or a series of them(consecutive), this is one event. I need to get, in Python, how many events my array has. So in this case we will have 5 events (that is 5 times 1 or... | 4 | 2016-07-29T06:13:46Z | 38,656,060 | <p>To replace multiple occurrence with single occurrence, append each item in a list if only the last appended item is not equal to the current one, and do the count.</p>
<pre><code>def count_series(seq):
seq = iter(seq)
result = [next(seq, None)]
for item in seq:
if result[-1] != item:
... | 0 | 2016-07-29T10:06:12Z | [
"python",
"arrays",
"time-series"
] |
Defining function using if-statement | 38,651,714 | <pre><code>def roots4(a,b,c,d):
d = b * b - 4 * a * c
if a != 0 and d == 0:
roots4(a,b,c,d)
x = -b/ (2*a)
if a != 0 and d > 0:
roots4(a,b,c,d)
x1 = (-b + math.sqrt(d)) / 2.0 / a
x2 = (-b - math.sqrt(d)) / 2.0 / a
if a != 0 and d < 0:
roots4(a,b,c,d)... | 0 | 2016-07-29T06:14:57Z | 38,652,998 | <p>Well, it looks like you have made an infinite loop with your recursive functions. As it looks now you will never do any calculations apart from </p>
<pre><code>d = b * b - 4 * a * c
</code></pre>
<p>over and over again.</p>
<p>Consider the program flow. Each time you reach </p>
<pre><code>roots4(a,b,c,d)
</code>... | 0 | 2016-07-29T07:31:17Z | [
"python",
"python-2.7",
"function",
"if-statement",
"printing"
] |
Defining function using if-statement | 38,651,714 | <pre><code>def roots4(a,b,c,d):
d = b * b - 4 * a * c
if a != 0 and d == 0:
roots4(a,b,c,d)
x = -b/ (2*a)
if a != 0 and d > 0:
roots4(a,b,c,d)
x1 = (-b + math.sqrt(d)) / 2.0 / a
x2 = (-b - math.sqrt(d)) / 2.0 / a
if a != 0 and d < 0:
roots4(a,b,c,d)... | 0 | 2016-07-29T06:14:57Z | 38,653,309 | <p>As pointed out in comments and jimmy's answer, there's no need for recursive calls.</p>
<p>Here's an example of how you could correct it (adapt it the way you like):</p>
<pre><code>#!/usr/bin/env python2
# -*- coding: utf-8 -*-
import math
def roots4(a, b, c):
"""Prints the solutions of ax² + bx + c = 0, i... | 0 | 2016-07-29T07:49:48Z | [
"python",
"python-2.7",
"function",
"if-statement",
"printing"
] |
Defining function using if-statement | 38,651,714 | <pre><code>def roots4(a,b,c,d):
d = b * b - 4 * a * c
if a != 0 and d == 0:
roots4(a,b,c,d)
x = -b/ (2*a)
if a != 0 and d > 0:
roots4(a,b,c,d)
x1 = (-b + math.sqrt(d)) / 2.0 / a
x2 = (-b - math.sqrt(d)) / 2.0 / a
if a != 0 and d < 0:
roots4(a,b,c,d)... | 0 | 2016-07-29T06:14:57Z | 38,653,633 | <p>you probably stacked with</p>
<pre><code> ...
roots4(a,b,c,d)
...
</code></pre>
<p>this causes an infinite loop</p>
<p>firstly, why do you need a recursion call? what's <code>d</code> parameter for?</p>
<p>secondly, what is <code>ixim</code>? should it be something like <code>xim * 1j</code>?
... | 0 | 2016-07-29T08:05:47Z | [
"python",
"python-2.7",
"function",
"if-statement",
"printing"
] |
print UTF-8 character in Python 2.7 | 38,651,993 | <p>Here is how I open, read and output. The file is an UTF-8 encoded file for unicode characters. I want to print the first 10 UTF-8 characters, but the output from below code snippet print 10 weird unrecognized characters. Wondering if anyone have any ideas how to print correctly? Thanks.</p>
<pre><code> with open(... | 2 | 2016-07-29T06:33:57Z | 38,652,100 | <p>To output a Unicode string to a file or to the console you need to choose a text encoding. In Python the default text encoding is ASCII, but to support other characters you need to use a different encoding, such as UTF-8:</p>
<pre><code>s = unicode(your_object).encode('utf8')
print s
</code></pre>
| 2 | 2016-07-29T06:41:19Z | [
"python",
"python-2.7",
"unicode",
"utf-8"
] |
print UTF-8 character in Python 2.7 | 38,651,993 | <p>Here is how I open, read and output. The file is an UTF-8 encoded file for unicode characters. I want to print the first 10 UTF-8 characters, but the output from below code snippet print 10 weird unrecognized characters. Wondering if anyone have any ideas how to print correctly? Thanks.</p>
<pre><code> with open(... | 2 | 2016-07-29T06:33:57Z | 38,653,062 | <p>When Unicode codepoints (characters) are encoded as UTF-8 some codepoints are converted to a single byte, but many codepoints become more than one byte. Characters in the standard 7 bit ASCII range will be encoded as single bytes, but more exotic characters will generally require more bytes to encode. </p>
<p>So yo... | 4 | 2016-07-29T07:34:57Z | [
"python",
"python-2.7",
"unicode",
"utf-8"
] |
Traceback (most recent call last): File "<pyshell#439>", line 3, in <module> print(l.text) AttributeError: 'list' object has no attribute 'text' | 38,652,058 | <p>I am currently scraping Linkedin Job directory using selenium in python shell</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get('https://www.linkedin.com/jobs/search?locationId=sg%3A0&f_TP=1%2C2&orig=FCTD&trk=jobs_jserp... | 1 | 2016-07-29T06:38:59Z | 38,652,517 | <p>Thats because you will get multidemensional array in <code>Job</code>.
Try to replace </p>
<pre><code> Job.append(a)
Job.append(b)
Job.append(c)
Job.append(d)
</code></pre>
<p>with </p>
<pre><code>Job += a
Job += b
Job += c
Job += d
</code></pre>
| 0 | 2016-07-29T07:05:57Z | [
"python",
"selenium"
] |
Traceback (most recent call last): File "<pyshell#439>", line 3, in <module> print(l.text) AttributeError: 'list' object has no attribute 'text' | 38,652,058 | <p>I am currently scraping Linkedin Job directory using selenium in python shell</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get('https://www.linkedin.com/jobs/search?locationId=sg%3A0&f_TP=1%2C2&orig=FCTD&trk=jobs_jserp... | 1 | 2016-07-29T06:38:59Z | 38,652,842 | <p>I think that's because variable "a" is a list.
You can debug to see what's in Job list.
I think the Job list like this Job=[[a], [b], [c], [d]] in your code.</p>
| 0 | 2016-07-29T07:23:44Z | [
"python",
"selenium"
] |
Issues using slots and signals when connecting two windows in Qt using PyQt | 38,652,324 | <p>I am having trouble passing a line of text from one LineEdit in a window to a lineEdit in another window by clicking a button. I have read multiple examples but I can't seem to get the signal to display on the second window. This is a very paired down version of the app I'm creating. I hope y'all can see something I... | 0 | 2016-07-29T06:54:16Z | 38,664,888 | <p>Alright so there are a few ways you can do this. You're on the right track for the signal slot thing. However, since you have multiple calls in each class to the other class, things get a little messed up.</p>
<p>One way to solve your problem is to simply change the <code>__init__</code> function for your <code>Win... | 0 | 2016-07-29T17:59:08Z | [
"python",
"qt",
"pyqt",
"signals",
"slots"
] |
How do I work on multiple appengine projects with python? | 38,652,358 | <p>I need to export my blobstore from one appengine project and upload it to another project. How can I switch between projects programmatically with python?</p>
| 0 | 2016-07-29T06:57:12Z | 38,657,617 | <p>If by "python" you mean a python GAE app's code itself - AFAIK you can't switch apps - each such code runs only inside the app specified in the <code>.yaml</code> file.</p>
<p>You could teach the exporting app project to serve the blob and for the actual transfer you could either:</p>
<ul>
<li>have the receving ap... | 0 | 2016-07-29T11:24:11Z | [
"python",
"google-app-engine",
"blobstore"
] |
Cython callback segfaults using python-c-api calls | 38,652,486 | <p>Working on a control of an eGige camera, having a C library, I've started a <a href="http://cython.org/" rel="nofollow">cython</a> code <a href="https://github.com/srgblnch/python-pylon" rel="nofollow">project</a> with the idea to have the best things of each language.</p>
<p>The library provides a way to listen a ... | 0 | 2016-07-29T07:04:10Z | 38,729,464 | <p>I'm not promising this is the only issue, but this is certainly <em>an</em> issue:</p>
<p><code>cameraRemovalCallback</code> is a <code>cdef</code> function. This means that the function is purely accessible from C/Cython, but not accessible from Python. This means that <code>PyObject_GetAttrString</code> fails (si... | 1 | 2016-08-02T20:02:09Z | [
"python",
"c++",
"cython",
"python-c-api"
] |
Pandas - different aggregations for a field | 38,652,621 | <p>I have a transaction table with these columns: customer_id, transaction_id, month</p>
<p>I would like to write a query which will be equivalent to the following in SQL:</p>
<pre><code>SELECT min(month) as first_month, max(month) as last_month
FROM transactions
GROUP BY customer_id
</code></pre>
<p>in pandas, it s... | 0 | 2016-07-29T07:12:05Z | 38,652,664 | <p>You can use:</p>
<pre><code>transactions.groupby('customer_id').aggregate({ 'Month' : ['min', 'max']})
</code></pre>
<p>Sample:</p>
<pre><code>transactions = pd.DataFrame({'customer_id':[1,2,3,1,2,1],
'Month': [4,5,6,1,1,3]})
print (transactions)
Month customer_id
0 4 ... | 1 | 2016-07-29T07:13:58Z | [
"python",
"pandas"
] |
IPython 5.0: Remove spaces between input lines | 38,652,671 | <p>(This question is essentially <a href="http://stackoverflow.com/questions/2351857/ipython-single-line-spacing-possible">this question</a>, but for IPython version 5.0)</p>
<p>I'd like to have a classic prompt with IPython 5.0.</p>
<p><a href="http://stackoverflow.com/questions/38275585/adding-color-to-new-style-ip... | 1 | 2016-07-29T07:14:23Z | 38,667,776 | <p>Please append this line on the bottom of your existing startup script:</p>
<pre><code>ip.separate_in = ''
</code></pre>
<p>This is a <a href="http://ipython.readthedocs.io/en/latest/config/options/terminal.html" rel="nofollow">documented feature</a> but currently has no description, making it hard-to-find.</p>
| 2 | 2016-07-29T21:31:21Z | [
"python",
"ipython",
"prompt"
] |
Counting repeated blocks in pandas | 38,652,683 | <p>I have the following dataframe and I am trying to label an entire block with a number which is based on how many similar blocks has been seen upto now based on class column. Consecutive class value is given the same number. If the same class block comes later, the number will be incremented. If some new class block ... | 2 | 2016-07-29T07:14:52Z | 38,653,230 | <p>Do this:</p>
<pre><code>df['block_encounter_no'] = \
np.where(df.Class.notnull(),
(df.Class.notnull() & (df.Class != df.Class.shift())).cumsum(),
np.nan)
</code></pre>
<p><a href="http://i.stack.imgur.com/yz61E.png" rel="nofollow"><img src="http://i.stack.imgur.com/yz61E.png" alt=... | 1 | 2016-07-29T07:45:42Z | [
"python",
"pandas",
"dataframe",
null,
"cumsum"
] |
Counting repeated blocks in pandas | 38,652,683 | <p>I have the following dataframe and I am trying to label an entire block with a number which is based on how many similar blocks has been seen upto now based on class column. Consecutive class value is given the same number. If the same class block comes later, the number will be incremented. If some new class block ... | 2 | 2016-07-29T07:14:52Z | 38,653,657 | <p>Solution with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.mask.html" rel="nofollow"><code>mask</code></a>:</p>
<pre><code>df['block_encounter_no'] = (df.Class != df.Class.shift()).mask(df.Class.isnull())
.groupby(df.Class).cumsum()
print (df)
a b... | 2 | 2016-07-29T08:06:56Z | [
"python",
"pandas",
"dataframe",
null,
"cumsum"
] |
Concatenate strings together in template if statement | 38,652,701 | <p>I read <a href="http://stackoverflow.com/questions/7665514/django-highlight-navigation-based-on-current-page">this</a> and my code looked like this:</p>
<p>html: </p>
<pre><code><li {% if request.path == '/groups/{{ group.id }}/' %}class="active"{% endif %} ><a href="{% url 'detail' group.id %}">Link&l... | 1 | 2016-07-29T07:15:50Z | 38,652,776 | <p>Instead of hardcoding the url, use the <code>url</code> tag with <code>as</code></p>
<pre><code>{% url 'my_group_url_name' group.id as group_url %}
{% if request.path == group_url %}
</code></pre>
| 4 | 2016-07-29T07:19:53Z | [
"python",
"django"
] |
From concurrent.futures to asyncio | 38,652,819 | <p>I have two problems with <a href="https://docs.python.org/3/library/concurrent.futures.html" rel="nofollow">concurrent.futures</a>:</p>
<h1>How to break time.sleep() in a python concurrent.futures?</h1>
<p>Conclusion: time.sleep() cannot be interrupted. One solution is: You can write a loop around it and do short ... | 4 | 2016-07-29T07:22:15Z | 38,655,063 | <p>In the asyncio model, execution is scheduled and coordinated by an event loop. To cancel execution of a currently suspended task, you essentially simply have to <em>not resume</em> it. While this works a little different in practice, it should be obvious that this makes cancelling a suspended task simple in theory.<... | 3 | 2016-07-29T09:19:44Z | [
"python",
"python-multiprocessing",
"python-asyncio",
"concurrent.futures"
] |
Pivoting data in pandas | 38,652,881 | <p>Suppose I have the following data as a pandas dataframe:</p>
<pre><code> type exdiv paydate amount
declared
2014-01-31 final 2014-03-03 2014-03-10 3.10
2014-06-27 interim 2014-08-11 2014-08-18 1.55
2015-01-30 final 2015-03-02 2015-03-09 ... | 1 | 2016-07-29T07:25:34Z | 38,653,022 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.transform.html" rel="nofollow"><code>transform</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html" rel="nofollow"><code>drop_duplicates</code></a>:</p>
<pr... | 2 | 2016-07-29T07:32:40Z | [
"python",
"pandas"
] |
How to retrieve <th><td> using Beautifulsoup | 38,652,893 | <p>I am using Python 3 on Windows 7.</p>
<p>However, I am unable to download some of the data listed in the web
site as follows:</p>
<p><a href="http://data.tsci.com.cn/stock/00939/STK_Broker.htm" rel="nofollow">http://data.tsci.com.cn/stock/00939/STK_Broker.htm</a></p>
<p>453.IMC 98.28M 18.4... | 1 | 2016-07-29T07:26:04Z | 38,653,558 | <p>as someone already mentioned, Selenium is the way to go.</p>
<pre><code>from selenium import webdriver
broker_url = 'http://data.tsci.com.cn/stock/00939/STK_Broker.htm'
mydriver = webdriver.Chrome()
mydriver.get(broker_url)
BuyList = mydriver.find_element_by_css_selector('#Buylist')
rows = BuyList.find_elements_... | 0 | 2016-07-29T08:02:08Z | [
"python",
"beautifulsoup"
] |
How to retrieve <th><td> using Beautifulsoup | 38,652,893 | <p>I am using Python 3 on Windows 7.</p>
<p>However, I am unable to download some of the data listed in the web
site as follows:</p>
<p><a href="http://data.tsci.com.cn/stock/00939/STK_Broker.htm" rel="nofollow">http://data.tsci.com.cn/stock/00939/STK_Broker.htm</a></p>
<p>453.IMC 98.28M 18.4... | 1 | 2016-07-29T07:26:04Z | 38,653,572 | <p>The data is dynamically generated but you can mimic an ajax request and get it in json format:</p>
<pre><code>import requests
params = {"Code": "E00939",
"PkgType": "11036",
"val": "50"}
js = requests.get("http://data.tsci.com.cn/RDS.aspx", params=params).json()
print(js)
</code></pre>
<p>Tha... | 0 | 2016-07-29T08:02:40Z | [
"python",
"beautifulsoup"
] |
Python 3.4 Logging Configuration | 38,652,992 | <p>I am trying to convert my current projects from python 2.7 to 3.5. One of the first tasks is configuration of logging. I use a configuration file for flexibility and the date is part of the file name.
Below is the code for setting up the file handler that works fine in 2.7</p>
<pre><code>[handler_fileHandler]
class... | 0 | 2016-07-29T07:30:54Z | 38,656,407 | <p>similar subject as this post:
<a href="http://stackoverflow.com/questions/14340366/configparser-and-string-with">Configparser and string with %</a></p>
<p>I think you may need the substitution for %</p>
| 1 | 2016-07-29T10:21:40Z | [
"python",
"python-3.x",
"python2to3"
] |
How to interpret (read) signed 24bits data from 32bits | 38,653,094 | <p>I have raw file containing signed 24bits data packed into 32bits
example:</p>
<pre><code>00 4D 4A FF
00 FF FF FF
</code></pre>
<p>I would like read those data and get signed integer between [-2^23 and 2^23-1]</p>
<p>for now I write </p>
<pre><code> int32_1 = file1.read(4)
val1 = (( unpack('=l', int32_1)[0] &... | 1 | 2016-07-29T07:36:50Z | 38,653,351 | <p>you can shift 8 bits to the left, take the result as a signed 32bit integer (use ctypes library), and divide by 256</p>
<pre><code>>>> import ctypes
>>> i = 0x00ffffff
>>> i
16777215
>>> i<<8
4294967040
>>> ctypes.c_int32(i<<8).value
-256
>>> ctypes.... | 1 | 2016-07-29T07:51:46Z | [
"python"
] |
How to interpret (read) signed 24bits data from 32bits | 38,653,094 | <p>I have raw file containing signed 24bits data packed into 32bits
example:</p>
<pre><code>00 4D 4A FF
00 FF FF FF
</code></pre>
<p>I would like read those data and get signed integer between [-2^23 and 2^23-1]</p>
<p>for now I write </p>
<pre><code> int32_1 = file1.read(4)
val1 = (( unpack('=l', int32_1)[0] &... | 1 | 2016-07-29T07:36:50Z | 38,654,783 | <p>Your code is making things more complicated than they need to be. However, you really should specify the endian type correctly in the <code>unpack</code> format string.</p>
<pre><code>from binascii import hexlify
from struct import unpack
data = ('\x00\x03\x02\x01', '\x00\x4D\x4A\xFF', '\x00\xFF\xFF\xFF')
for b i... | 2 | 2016-07-29T09:05:03Z | [
"python"
] |
Straightforward solution on how to stereo calibration and rectifications OpenCV? | 38,653,354 | <p>I have been digging on this topic for almost a week and couldn't find any solid solution yet.
It is interesting that no one ever posted a <strong>straightforward</strong> solution on how to calibrate and rectify a stereo camera with OpenCV in order to compute the depth, from here and there(<a href="http://stackoverf... | 0 | 2016-07-29T07:51:57Z | 38,673,008 | <p>I couldn't find what was the thing I did wrong which led to incorrect answers, but for what it worth I have found a solution that does rectify OK and more!!<br />
I came across the <a href="https://github.com/erget/StereoVision" rel="nofollow">StereoVision</a> library and considering the low documentation level it h... | 0 | 2016-07-30T10:46:31Z | [
"python",
"opencv",
"image-processing",
"video-processing"
] |
Large Scenario Outline tables without having to explicitly mention all parameters in the step definitons | 38,653,356 | <p>In Python's <a href="https://pythonhosted.org/behave/index.html" rel="nofollow">behave</a> library, I can write a feature file with a parametrised Scenario Outline like so (adapted from <a href="https://jenisys.github.io/behave.example/tutorials/tutorial04.html" rel="nofollow">this tutorial</a>):</p>
<pre><code># f... | 1 | 2016-07-29T07:52:01Z | 38,664,555 | <p>The point is clear. </p>
<p>Ask yourself why you <em>really</em> need all those variables?</p>
<p>Are you trying to do too much in one scenario outline? Is it possible to split your problem in two?</p>
<p>How would a scenario look like if you just implemented one of them, i.e. skipped the outline? Would it be lar... | 0 | 2016-07-29T17:38:04Z | [
"python",
"gherkin",
"python-behave"
] |
Large Scenario Outline tables without having to explicitly mention all parameters in the step definitons | 38,653,356 | <p>In Python's <a href="https://pythonhosted.org/behave/index.html" rel="nofollow">behave</a> library, I can write a feature file with a parametrised Scenario Outline like so (adapted from <a href="https://jenisys.github.io/behave.example/tutorials/tutorial04.html" rel="nofollow">this tutorial</a>):</p>
<pre><code># f... | 1 | 2016-07-29T07:52:01Z | 38,694,350 | <p>Apart from considering if one really needs to work with large scenario outline tables (see the other answer), it is indeed possible to access the current table row without explicitly mentioning all parameters in the given/when/then step via <code>context.active_outline</code> <a href="https://pythonhosted.org/behave... | 0 | 2016-08-01T08:36:51Z | [
"python",
"gherkin",
"python-behave"
] |
python 2d array list index out of range | 38,653,358 | <pre><code>j=0
i=0
text=[[0 for x in range(5)]for y in range(2)]
while (i<5):
for link in soup.findAll('td'):
if j<2:
text[i][j]=link.string
j+=1
i+=1
</code></pre>
<p>The problem is I get the error message <code>list index out of range</code> but I already set the if conditio... | -5 | 2016-07-29T07:52:09Z | 38,653,461 | <pre><code>[[0 for x in range(5)] for y in range(2)]
</code></pre>
<p>creates the array <code>[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]</code></p>
<p>Your code is built for an array which looks like: <code>[[0, 0], [0, 0],[0, 0],[0, 0],[0, 0]]</code>.</p>
<p>So either <code>i</code> and <code>j</code> are around the wrong... | 0 | 2016-07-29T07:57:37Z | [
"python",
"arrays",
"beautifulsoup"
] |
python 2d array list index out of range | 38,653,358 | <pre><code>j=0
i=0
text=[[0 for x in range(5)]for y in range(2)]
while (i<5):
for link in soup.findAll('td'):
if j<2:
text[i][j]=link.string
j+=1
i+=1
</code></pre>
<p>The problem is I get the error message <code>list index out of range</code> but I already set the if conditio... | -5 | 2016-07-29T07:52:09Z | 38,653,661 | <pre><code>text=[[0 for x in range(5)]for y in range(2)]
</code></pre>
<p>is equal to</p>
<pre><code>[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
</code></pre>
<p>So inside your list, you have 2 lists with 5 elements each one.</p>
<p>Then look at this line:</p>
<pre><code>text[i][j]=link.string
</code></pre>
<p><code>i</co... | 0 | 2016-07-29T08:07:03Z | [
"python",
"arrays",
"beautifulsoup"
] |
Finding same IDs in a certain amount of dictionaries in python | 38,653,361 | <p>I have a program that cycles through all .xml it can find in directory. It searches for device id and then adds all of them into a dictionary(i think) When I print it out it looks like </p>
<pre><code>{'1.xml': [], '2.xml': []}
</code></pre>
<p>Next I insert the device IDs i get from the files into them so the out... | 0 | 2016-07-29T07:52:15Z | 38,653,691 | <h2>After you clarified your data</h2>
<p>You can write a loop or use reduce, which you will have to import from <code>functools</code> if you are on python 3. You can use a lambda if you want, e.g. <code>lambda s1,s2: s1 & s2</code> but I prefer to import the appropriate operator from the <code>operator</code> mo... | 0 | 2016-07-29T08:08:31Z | [
"python",
"loops",
"dictionary"
] |
Finding same IDs in a certain amount of dictionaries in python | 38,653,361 | <p>I have a program that cycles through all .xml it can find in directory. It searches for device id and then adds all of them into a dictionary(i think) When I print it out it looks like </p>
<pre><code>{'1.xml': [], '2.xml': []}
</code></pre>
<p>Next I insert the device IDs i get from the files into them so the out... | 0 | 2016-07-29T07:52:15Z | 38,654,350 | <p>I'm thinking of the eval function. How about putting the dictionaries into an array and generating your code dynamically.</p>
<p>For example like:</p>
<pre><code>list = [dict1]
list.append(dict2) # append all dicts to the list
for i in range(len(list)):
if i == len(list) - 1:
string_code += "set(dict... | 0 | 2016-07-29T08:44:46Z | [
"python",
"loops",
"dictionary"
] |
Efficiently update columns based on one of the columns split value | 38,653,421 | <p>So here is my code updating many column values based on a condition of split values of the column 'location'. The code works fine, but as its iterating by row it's not efficient enough. Can anyone help me to make this code work faster please?</p>
<pre><code>for index, row in df.iterrows():
print index
locat... | -1 | 2016-07-29T07:54:56Z | 38,656,102 | <p>'map' was what I needed :)</p>
<pre><code>def fill_county(column):
res = ''
location_split = column.split(':')
for l in location_split:
if l.strip().startswith('County'):
res= l.strip()
break
return res
df['county'] = map(fill_county, df['location'])
</code></pre>
| 0 | 2016-07-29T10:08:06Z | [
"python",
"dataframe"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,511 | <p>When you don't specify a start or end index Python returns the entire array:</p>
<pre><code>A[:] = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
</code></pre>
| 2 | 2016-07-29T08:00:03Z | [
"python",
"list"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,516 | <p><code>[:]</code> matches the entire list.</p>
<p>So <code>A[:]</code> is the same as <code>A</code>. So <code>A[0][:]</code> is the same as <code>A[0]</code>.</p>
<p>And <code>A[0][:]</code> is the same as <code>A[0]</code>.</p>
| 2 | 2016-07-29T08:00:17Z | [
"python",
"list"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,520 | <p><code>[:]</code> is equivalent to copy.</p>
<p><code>A[:][0]</code> is the first row of a copy of A.
<code>A[0][:]</code> is a copy of the first row of A.</p>
<p>The two are the same.</p>
<p>To get the first column: <code>[a[0] for a in A]</code>
Or use numpy and <code>np.array(A)[:,0]</code></p>
| 3 | 2016-07-29T08:00:23Z | [
"python",
"list"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,535 | <p>Note that <code>[:]</code> just gives you a copy of <strong>all the content</strong> of the list. So what you are getting is perfectly normal. I think you wanted to use this operator as you would in <em>numpy</em> or Matlab. This does not do the same in regular Python.</p>
<hr>
<p><code>A[0]</code> is <code>[1, 2... | 2 | 2016-07-29T08:01:06Z | [
"python",
"list"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,553 | <p><code>A[:]</code> returns a copy of the entire list. which is <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code>
<code>A[:][0]</code> Thus selects <code>[1, 2, 3]</code>.
If you want the first column, do a loop:</p>
<pre><code>col = []
for row in A:
col.append(row[0])
</code></pre>
| 2 | 2016-07-29T08:01:55Z | [
"python",
"list"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,555 | <h3>Problem</h3>
<p>A is not a 2-D list: it is a list of lists. In consideration of that:</p>
<ol>
<li><p><code>A[0]</code> is the first list in A:</p>
<pre><code>>>> A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
>>> A[0]
[1, 2, 3]
</code></pre>
<p>Consequently, <code>A[0][:]</code>: is every element of ... | 2 | 2016-07-29T08:02:01Z | [
"python",
"list"
] |
Printing a column of a 2-D List in Python | 38,653,450 | <p>Suppose if <code>A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]</code></p>
<p>Then <code>A[0][:]</code> prints <code>[1, 2, 3]</code></p>
<p>But why does <code>A[:][0]</code> print <code>[1, 2, 3]</code> again ? </p>
<p>It should print the column <code>[1, 4, 7]</code>, shouldn't it?</p>
| 2 | 2016-07-29T07:56:58Z | 38,653,612 | <p>A is actually a list of list, not a matrix. With <code>A[:][0]</code> You are accessing the first element (the list <code>[1,2,3]</code>) of the full slice of the list A. The <code>[:]</code> is Python slice notation (explained in <a href="http://stackoverflow.com/questions/509211/explain-pythons-slice-notation">the... | 2 | 2016-07-29T08:04:49Z | [
"python",
"list"
] |
Subfunction referencing without object declation | 38,653,565 | <p>I've got a class of the form:</p>
<pre><code>class MyClass(object):
def curves(self):
def plot(self):
plot a graph
return something
return a pd.DataFrame
</code></pre>
<p>What I want to do is define something I can call with <code>instance_of_my_class.curves.plot()</code></p>
<p>Do I need ... | 0 | 2016-07-29T08:02:22Z | 38,653,855 | <p>In order to add a level of hierarchy, <code>curves</code> needs to be an actual object, yes. There is no difference between <code>foo.curves.plot()</code> and the following:</p>
<pre><code>c = foo.curves
c.plot()
</code></pre>
<p>So <code>foo.curves</code> needs to be an object that has a <code>plot</code> method.... | 0 | 2016-07-29T08:17:59Z | [
"python"
] |
python super() function error? | 38,653,667 | <pre><code>class car(object):
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0
class electricCar(car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
tesla = electricCar('t... | 0 | 2016-07-29T08:07:18Z | 38,653,762 | <p><code>super()</code> (without arguments) was introduced in <strong><em>python3</em></strong>
In <strong><em>python2</em></strong> you should <strong>Change it to this</strong> </p>
<pre><code>class electricCar(car):
def __init__(self, make, model, year):
super(electricCar,self).__init__(make, model, y... | 2 | 2016-07-29T08:12:22Z | [
"python",
"python-2.x"
] |
python super() function error? | 38,653,667 | <pre><code>class car(object):
def __init__(self, make, model, year):
self.make = make
self.model = model
self.year = year
self.odometer_reading = 0
class electricCar(car):
def __init__(self, make, model, year):
super().__init__(make, model, year)
tesla = electricCar('t... | 0 | 2016-07-29T08:07:18Z | 38,653,779 | <p>It looks like you are trying to use the Python 3 syntax, but you are using Python 2. In that version you need to pass the current class and instance as arguments to the <code>super</code> function:</p>
<pre><code>super(electricCar, self).__init__(make, model, year)
</code></pre>
| 3 | 2016-07-29T08:13:31Z | [
"python",
"python-2.x"
] |
How does Python interpret arguments in class definition? | 38,653,754 | <p>I am trying to understand the source code of Beautifulsoup.</p>
<p>The first several lines of its source code is:</p>
<pre><code>class Beautifulsoup(Tag):
def __init__(self, markup="", features=None, builder=None,
parse_only=None, from_encoding=None, exclude_encodings=None,
**kwargs):
...
</cod... | -5 | 2016-07-29T08:11:53Z | 38,653,866 | <ol>
<li><p><code>Tag</code> is the class that <code>BeautifoulSoup</code> inherits from. It's not an argument. Please <a href="http://www.python-course.eu/python3_inheritance.php" rel="nofollow">take a look at this</a> to learn more.</p></li>
<li><p>As for the arguments in <code>__init__</code>: <em><code>self</code><... | 1 | 2016-07-29T08:18:36Z | [
"python",
"beautifulsoup"
] |
How does Python interpret arguments in class definition? | 38,653,754 | <p>I am trying to understand the source code of Beautifulsoup.</p>
<p>The first several lines of its source code is:</p>
<pre><code>class Beautifulsoup(Tag):
def __init__(self, markup="", features=None, builder=None,
parse_only=None, from_encoding=None, exclude_encodings=None,
**kwargs):
...
</cod... | -5 | 2016-07-29T08:11:53Z | 38,654,005 | <p>The line <code>class BeautifulSoup(Tag):</code> means "please start defining a class named BeautifulSoup, inheriting from the class Tag".</p>
<p>The line(s) <code>def __init__(self, markup="", features=None...</code> mean "let the class's constructor take the arguments ...", with the very first one being the instan... | 1 | 2016-07-29T08:25:09Z | [
"python",
"beautifulsoup"
] |
Python Error - For and IF NOT in same statement | 38,653,839 | <p>I'm using Python 3.5, i am trying to remove NLTK stopWords from my dataset and when i run the a statement which combines both For & IF NOT in one statement i get an error. Searching for the error did not yield any useful results.</p>
<p>Code and error snapshot attached below enter image description here</p>
<p... | 0 | 2016-07-29T08:16:55Z | 38,653,933 | <p>It seems you don't have key in base_data as 'stemmed_comments'. Use statement like this</p>
<pre><code>base_data['stemmed_stop_comments'] = []
if 'stemmed_comments' in base_data:
base_data['stemmed_stop_comments'] = [word for word in base_data['stemmed_comments'] if not (word in stopWords)]
</code></pre>
<p>o... | -2 | 2016-07-29T08:21:34Z | [
"python",
"nltk",
"stop-words"
] |
Python Error - For and IF NOT in same statement | 38,653,839 | <p>I'm using Python 3.5, i am trying to remove NLTK stopWords from my dataset and when i run the a statement which combines both For & IF NOT in one statement i get an error. Searching for the error did not yield any useful results.</p>
<p>Code and error snapshot attached below enter image description here</p>
<p... | 0 | 2016-07-29T08:16:55Z | 38,659,835 | <pre><code>def remove_stop(sentance):
removed = [x for x in sentance.split(' ') if x.lower() not in stopWords]
return ' '.join(removed)
base_data['stemmed_stop_comments'] = base_data.stemmed_comments.apply(lambda x: remove_stop(x))
</code></pre>
| 0 | 2016-07-29T13:12:46Z | [
"python",
"nltk",
"stop-words"
] |
Python load JSON only loads part of a file | 38,653,925 | <p>This is a simple code example:</p>
<pre><code>import json
f = open("somefile.json")
d = json.load(f)
print d
# output:
f.seek(0)
l = f.readlines()
print l
</code></pre>
<p><strong>output</strong></p>
<pre><code>{u'95659045': {u'90': False}}
['{"95659045": {"1": false}, "95659045": {"90": false}}'] ... | 0 | 2016-07-29T08:21:15Z | 38,653,988 | <p>You have the same key twice '95659045', so the second occurrence overwrite the first.</p>
| 2 | 2016-07-29T08:24:19Z | [
"python",
"json"
] |
Matrix - String, Int, and Combined Operations | 38,654,086 | <p>I want to be able to assign a string (a word) to an integer, and also an integer to a string, so that later on when i sort the integer or string, i can print the corresponding string or integer to that unit in matrix.
Example;</p>
<pre><code>103 = QWE
13 = ASD
50 = ZXC
-1 = VBN
253 = RTY
</code></pre>
<p>and even ... | 0 | 2016-07-29T08:29:54Z | 38,662,920 | <p>It can be done by MATLAB.
I tried to do it using vectorization method. And it became the more and more unclear at each step but I spent a lot of time for it, so I show it:</p>
<pre><code>a1 = ['qve';'rts';'abc';'abc';'def']
a2 = [3;5;10;7;8]
%//find unique strings:
mycell = unique(a1,'rows')
%//find numbers corres... | 0 | 2016-07-29T15:53:40Z | [
"python",
"matlab"
] |
Matrix - String, Int, and Combined Operations | 38,654,086 | <p>I want to be able to assign a string (a word) to an integer, and also an integer to a string, so that later on when i sort the integer or string, i can print the corresponding string or integer to that unit in matrix.
Example;</p>
<pre><code>103 = QWE
13 = ASD
50 = ZXC
-1 = VBN
253 = RTY
</code></pre>
<p>and even ... | 0 | 2016-07-29T08:29:54Z | 38,767,663 | <p>What you're doing is called "sorting arrays in parallel" or "sorting parallel arrays." You can use those terms to search for guides on how to do it. However, below is some code which shows one way to do it in MATLAB:</p>
<pre><code>unsorted_keys = [95, 37, 56, 70, 6, 61, 58, 13, 57, 7, 68, 52, 98, 25, 12];
unsorte... | 0 | 2016-08-04T12:42:39Z | [
"python",
"matlab"
] |
How to find line break in text file using Pyspark? | 38,654,092 | <p>I am trying to load text file in spark, I am getting error like </p>
<pre><code>Input row doesn't have expected number of values required by the schema. 31 fields are required while 1 values are provided.
</code></pre>
<p>the file size is 20GB. Manually its not possible to check line by line. What is the best opti... | 0 | 2016-07-29T08:30:09Z | 38,662,631 | <p>You can do a fast check with pySpark.</p>
<p>Try to load your file like this:</p>
<pre><code>rdd = sc.textFile('filePath').map(lambda x: x.split('<yourSeparator>'))
rdd.map(lambda x: len(x)).zipWithIndex().sortByKey().take(5)
</code></pre>
<p>this will return the index of the Column lenght and the index of ... | 0 | 2016-07-29T15:38:16Z | [
"python",
"apache-spark",
"pyspark"
] |
Python/Pyomo with glpk Solver - Error | 38,654,200 | <p>I am trying to run some simle example with Pyomo + glpk Solver (Anaconda2 64bit Spyder):</p>
<pre><code>from pyomo.environ import *
model = ConcreteModel()
model.x_1 = Var(within=NonNegativeReals)
model.x_2 = Var(within=NonNegativeReals)
model.obj = Objective(expr=model.x_1 + 2*model.x_2)
model.con1 = Constraint(ex... | 2 | 2016-07-29T08:35:51Z | 39,111,341 | <p>This is a known problem with GLPK 4.60 (glpsol changed the format of their output which broke Pyomo 4.3's parser). You can either download an older release of GLPK, or upgrade Pyomo to 4.4.1 (which contains an updated parser).</p>
| 1 | 2016-08-23T21:59:34Z | [
"python",
"pyomo"
] |
Python Regular expression to find latest file in directory | 38,654,202 | <p>I have one directory which contains below files for example purpose.</p>
<pre><code>Directory:
ERROR_AM_INMAG_Export_2016-07-25.csv
AM_INMAG_Export_2016-07-26_done.csv
ERROR_AM_INMAG_Export_2016-07-27.csv
AM_INMAG_Export_2016-07-28_done.csv
AM_INMAG_Export_2016-07-29.csv
file1
file2
fileN
</code></pre>
<p>Here h... | 0 | 2016-07-29T08:35:56Z | 38,654,527 | <p>Use <a href="https://docs.python.org/3/library/glob.html?highlight=glob#glob.glob" rel="nofollow">glob.glob</a></p>
<pre><code>import glob
print( glob.glob('AM_INMAG_Export_????-??-??.csv')[-1] )
</code></pre>
<p>This will work if the time defined in the name is actually the updated time. Otherwise , you should us... | 0 | 2016-07-29T08:53:29Z | [
"python"
] |
Python Regular expression to find latest file in directory | 38,654,202 | <p>I have one directory which contains below files for example purpose.</p>
<pre><code>Directory:
ERROR_AM_INMAG_Export_2016-07-25.csv
AM_INMAG_Export_2016-07-26_done.csv
ERROR_AM_INMAG_Export_2016-07-27.csv
AM_INMAG_Export_2016-07-28_done.csv
AM_INMAG_Export_2016-07-29.csv
file1
file2
fileN
</code></pre>
<p>Here h... | 0 | 2016-07-29T08:35:56Z | 38,654,528 | <p>So it looks like you need to use regex to get the date as a group item. Once you have all of the groups you need to convert that to a python date and then check to see which one has the greatest date.</p>
<pre><code>import re
pat = re.compile("^AM_INMAG_Export_(.+)\.csv$")
matches = pat.match(your_data)
</code></pr... | 0 | 2016-07-29T08:53:31Z | [
"python"
] |
Python Regular expression to find latest file in directory | 38,654,202 | <p>I have one directory which contains below files for example purpose.</p>
<pre><code>Directory:
ERROR_AM_INMAG_Export_2016-07-25.csv
AM_INMAG_Export_2016-07-26_done.csv
ERROR_AM_INMAG_Export_2016-07-27.csv
AM_INMAG_Export_2016-07-28_done.csv
AM_INMAG_Export_2016-07-29.csv
file1
file2
fileN
</code></pre>
<p>Here h... | 0 | 2016-07-29T08:35:56Z | 38,654,532 | <p>Filter the files that match your desired prefix and then sort.</p>
<pre><code>>>> files = """ERROR_AM_INMAG_Export_2016-07-25.csv
... AM_INMAG_Export_2016-07-26_done.csv
... ERROR_AM_INMAG_Export_2016-07-27.csv
... AM_INMAG_Export_2016-07-28_done.csv
... AM_INMAG_Export_2016-07-29.csv
... file1
... file2
.... | 0 | 2016-07-29T08:53:38Z | [
"python"
] |
Python Regular expression to find latest file in directory | 38,654,202 | <p>I have one directory which contains below files for example purpose.</p>
<pre><code>Directory:
ERROR_AM_INMAG_Export_2016-07-25.csv
AM_INMAG_Export_2016-07-26_done.csv
ERROR_AM_INMAG_Export_2016-07-27.csv
AM_INMAG_Export_2016-07-28_done.csv
AM_INMAG_Export_2016-07-29.csv
file1
file2
fileN
</code></pre>
<p>Here h... | 0 | 2016-07-29T08:35:56Z | 38,654,547 | <pre><code>files = glob.glob('AM_INMAG_Export_*.csv')
sorted_files = sorted(files, key=lambda x: int(x.split('_')[3].split('.')[0]))
</code></pre>
| 1 | 2016-07-29T08:54:04Z | [
"python"
] |
Python Regular expression to find latest file in directory | 38,654,202 | <p>I have one directory which contains below files for example purpose.</p>
<pre><code>Directory:
ERROR_AM_INMAG_Export_2016-07-25.csv
AM_INMAG_Export_2016-07-26_done.csv
ERROR_AM_INMAG_Export_2016-07-27.csv
AM_INMAG_Export_2016-07-28_done.csv
AM_INMAG_Export_2016-07-29.csv
file1
file2
fileN
</code></pre>
<p>Here h... | 0 | 2016-07-29T08:35:56Z | 38,654,636 | <p>use <code>glob</code> to get the files and then sort the file names from the earliest to the oldest file:</p>
<pre><code>files = glob.glob('<YOUR_DIRECTORY>/AM_INMAG_Export_*') # the file prefix + '*' as regex
files.sort(reverse=True) # sort and use 'reverse=True' to get a list of files sorted by the earliest... | 0 | 2016-07-29T08:58:33Z | [
"python"
] |
Python Regular expression to find latest file in directory | 38,654,202 | <p>I have one directory which contains below files for example purpose.</p>
<pre><code>Directory:
ERROR_AM_INMAG_Export_2016-07-25.csv
AM_INMAG_Export_2016-07-26_done.csv
ERROR_AM_INMAG_Export_2016-07-27.csv
AM_INMAG_Export_2016-07-28_done.csv
AM_INMAG_Export_2016-07-29.csv
file1
file2
fileN
</code></pre>
<p>Here h... | 0 | 2016-07-29T08:35:56Z | 38,654,830 | <p>A list of files obtained with glob.glob() can be sorted with the sorted statement. See the following example</p>
<pre><code>import os
import glob
def main():
"""
Sort csv Files.
"""
for f in sorted(glob.glob(os.path.join('AM_INMAG_Export_*.csv')), reverse=True):
print("File " + f)
if __n... | 0 | 2016-07-29T09:07:48Z | [
"python"
] |
what does this statement (line, str) = str.split("\n", 1) mean? | 38,654,238 | <p>I am familiar with the <code>split</code> function and I would use it as such: </p>
<pre><code>str = "Line1-abcdef \nLine2-abc \nLine4-abcd"
print str.split( )
</code></pre>
<p>The above would return this:</p>
<pre><code>['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
</code></pre>
<p>Simple and easy. However, I cam... | -2 | 2016-07-29T08:38:27Z | 38,654,278 | <p>The second argument <code>maxsplit=1</code> means <em>stop splitting after you meet the separator <code>\n</code> once</em>.</p>
<p>Therefore you have only two parts, your line and the rest of the string. You should really take a look at examples, starting <a class='doc-link' href="http://stackoverflow.com/document... | 5 | 2016-07-29T08:41:06Z | [
"python",
"string",
"iterable"
] |
what does this statement (line, str) = str.split("\n", 1) mean? | 38,654,238 | <p>I am familiar with the <code>split</code> function and I would use it as such: </p>
<pre><code>str = "Line1-abcdef \nLine2-abc \nLine4-abcd"
print str.split( )
</code></pre>
<p>The above would return this:</p>
<pre><code>['Line1-abcdef', 'Line2-abc', 'Line4-abcd']
</code></pre>
<p>Simple and easy. However, I cam... | -2 | 2016-07-29T08:38:27Z | 38,654,298 | <p>Testing with a basic string, <code>how do you do ?</code>.
<code>line</code> will get the first element of the split, and <code>str</code> will get the rest (as we only split once)</p>
| 0 | 2016-07-29T08:42:10Z | [
"python",
"string",
"iterable"
] |
Django. Cannot load picture from ImageField | 38,654,297 | <p>I'm trying to upload a picture from ImageField in template, but it is not displayed. Code and screenshots will explain better.</p>
<p>settings.py</p>
<pre><code>STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_URL = '/media/'
MEDIA_ROOT = '/media/veracrypt1/django/pycaba/pycaba/media/'
... | 0 | 2016-07-29T08:42:00Z | 38,654,440 | <p>What Django version are you using? Have you included <a href="https://docs.djangoproject.com/en/1.9/howto/static-files/#serving-files-uploaded-by-a-user-during-development" rel="nofollow">static file urls</a> in you url patterns?</p>
| 0 | 2016-07-29T08:48:57Z | [
"python",
"django"
] |
How can I sort contours from left to right and top to bottom? | 38,654,302 | <p>I am trying to build an character recognition program using Python. I am stuck on sorting the contours. I am using <a href="https://github.com/guard0g/HandwritingRecognition/blob/master/Handwriting%20Recognition%20Workbook.ipynb" rel="nofollow">this page</a> as a reference. </p>
<p>I managed to find the contours us... | 1 | 2016-07-29T08:42:17Z | 38,693,156 | <p>I don't think you are going to be able to generate the contours directly in the correct order, but a simple sort as follows should do what you need:</p>
<pre><code>import numpy as np
c = np.load(r"rect.npy")
contours = list(c)
# Example - contours = [(287, 117, 13, 46), (102, 117, 34, 47), (513, 116, 36, 49), (45... | 0 | 2016-08-01T07:27:03Z | [
"python"
] |
Python thread safety for method/attribute lookup | 38,654,375 | <p>I have been working with python and I understand and use the threading, queues, events, locks in a multi threaded environment. What I am curious about is while accesing and calling a shared object's method can we ignore any locks and semaphores?
Here is a sample code:</p>
<pre><code>import threading
class Methods(... | 0 | 2016-07-29T08:45:52Z | 38,654,802 | <p>I think if you use only local variables then its ok, but if you only use local variables in your methods (I mean you don't access attributes of <code>self</code>), maybe it's better to make them staticmethods or plain functions?</p>
| 0 | 2016-07-29T09:06:05Z | [
"python",
"multithreading",
"cpython"
] |
Python pip installation in ubuntu | 38,654,445 | <p>I am new to Ubuntu and was trying to install pip using get-pip.py , when I received this message.</p>
<pre><code>Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist- packages/pip-8.1.2-py2.7.egg
</code></pre>
<p>But when I enter <code>pip -V</code>, I receive an error saying :</p>
<pre><code>... | 1 | 2016-07-29T08:49:08Z | 38,654,603 | <p>I suggest installing pip using the package manager. Open up a terminal and enter</p>
<pre><code>sudo apt-get install python-pip
</code></pre>
<p>That <em>should</em> install the <a href="http://packages.ubuntu.com/xenial/python-pip" rel="nofollow">pip</a> ubunutu package.</p>
| 2 | 2016-07-29T08:56:42Z | [
"python",
"ubuntu",
"pip"
] |
Python pip installation in ubuntu | 38,654,445 | <p>I am new to Ubuntu and was trying to install pip using get-pip.py , when I received this message.</p>
<pre><code>Requirement already up-to-date: pip in /usr/local/lib/python2.7/dist- packages/pip-8.1.2-py2.7.egg
</code></pre>
<p>But when I enter <code>pip -V</code>, I receive an error saying :</p>
<pre><code>... | 1 | 2016-07-29T08:49:08Z | 38,654,711 | <p>You should not be installing pip for the default python installation, neither from the package manager nor using <code>get-pip.py</code>. So you can never use it to break the system python. </p>
<p>Instead always use <code>virtualenv</code> (created from the default/system python or from a newer version), activate ... | 2 | 2016-07-29T09:02:00Z | [
"python",
"ubuntu",
"pip"
] |
Python 3, ImportError: cannot import name 'HTTPClient' | 38,654,492 | <p>I'm fairly new to python am interested in making a script for discord. After installing everything I was supposed to and plugging in the example code, I am getting errors.</p>
<pre><code>import discord
import asyncio
client = discord.Client()
async def my_background_task():
await client.wait_until_ready()
... | 2 | 2016-07-29T08:51:19Z | 38,654,706 | <p>It seems that file <code>discord/http.py</code> does not contain definition of <code>HTTPClient</code>. Can you please provide contents of this file?</p>
| 0 | 2016-07-29T09:01:34Z | [
"python",
"python-3.x",
"httpclient"
] |
Python 3, ImportError: cannot import name 'HTTPClient' | 38,654,492 | <p>I'm fairly new to python am interested in making a script for discord. After installing everything I was supposed to and plugging in the example code, I am getting errors.</p>
<pre><code>import discord
import asyncio
client = discord.Client()
async def my_background_task():
await client.wait_until_ready()
... | 2 | 2016-07-29T08:51:19Z | 38,671,132 | <p>Installing a different version of discord.py seemed to work.</p>
<p>pip install -U <a href="https://github.com/Rapptz/discord.py/archive/master.zip#egg=discord.py[voice]" rel="nofollow">https://github.com/Rapptz/discord.py/archive/master.zip#egg=discord.py[voice]</a></p>
<p>This was the version I used.</p>
| 0 | 2016-07-30T06:42:09Z | [
"python",
"python-3.x",
"httpclient"
] |
Softmax matrix to 0/1 (OneHot) encoded matrix? | 38,654,543 | <p>Suppose I have the following tensor <code>t</code> as the output of a softmax function:</p>
<pre><code>t = tf.constant(value=[[0.2,0.8], [0.6, 0.4]])
>> [ 0.2, 0.8]
[ 0.6, 0.4]
</code></pre>
<p>Now I would like to convert this matrix <code>t</code> into a matrix that resembles the OneHot encoded matrix:... | 1 | 2016-07-29T08:53:54Z | 38,655,309 | <p>Why not combine tf.argmax() with tf.one_hot().</p>
<p><code>Y = tf.one_hot(tf.argmax(t, dimension = 1), depth = 2)</code></p>
| 1 | 2016-07-29T09:31:29Z | [
"python",
"tensorflow"
] |
How to use regexp has whitespace in brackets by using Python3 | 38,654,588 | <p>My code is like this:</p>
<pre><code>import re
s = """
<contentID>1"""
reg = re.compile("(.|\n)+<contentID>1.*")
m = reg.fullmatch(s)
print(m)
reg = re.compile("[.\n]+<contentID>1.*")
m = reg.fullmatch(s)
print(m)
</code></pre>
<p>Seems like the regex <code>[.\n]</code> does not work, but <c... | 1 | 2016-07-29T08:55:59Z | 38,654,744 | <p>Instead of the <code>[.\n]</code> that matches a newline or a literal dot character, use <code>.</code> with <code>re.DOTALL</code> or <code>re.S</code> enabling the <code>.</code> to match newline symbols, too:</p>
<pre><code>reg = re.compile(".*<contentID>1.*", re.DOTALL)
m = reg.fullmatch(s)
print(m)
</cod... | 1 | 2016-07-29T09:03:48Z | [
"python",
"regex",
"whitespace",
"brackets"
] |
Flask SQLAlchemy many-to-many relationship new attribute | 38,654,624 | <p>I am using Flask and SQLAlchemy and many to many relationship in my database. It works fine but I would like to add new attributes(String tarif) in my table <code>user_routes</code>. How can I edit this attribute in query? It is possible? Thank you</p>
<p>This is my db query to insert </p>
<pre><code>route = get_r... | 0 | 2016-07-29T08:57:30Z | 38,657,544 | <p>After hours. I found solution <code>Association Object</code>.</p>
<pre><code>from app import db
class User_has_route(db.Model):
__tablename__ = 'user_has_route'
route_id = db.Column(db.Integer, db.ForeignKey('route.route_id'), primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.user_... | 0 | 2016-07-29T11:20:21Z | [
"python",
"sqlalchemy",
"many-to-many"
] |
Minimalist Python Server for Unity3d 5.x | 38,654,628 | <p>TL;DR: I'm having trouble communicating between a Unity3D client app and a UDP python listener on the server.</p>
<p>I'm trying to simply get a low-level call-and-response from a Unity3D game client via Unity 5.x NetworkTransport LLAPI and Python 3.x socket module</p>
<p>Goal:
Bounce the message sent to the server... | 0 | 2016-07-29T08:57:45Z | 38,657,131 | <p><code>UDP</code> and <code>TCP</code> are both standard protocol. This means that no matter what programming language you use, they should be able to communicate with each other.</p>
<p>Your python code is using standard UDP code. Your Unity code is <strong>not</strong>. The <code>NetworkTransport</code> API you us... | 1 | 2016-07-29T10:59:00Z | [
"c#",
"python",
"unity3d"
] |
How to convert large list of dictionary to dataframe/matrix | 38,654,677 | <p>I have a list of dictionaries which has about 5 million lines.<br>
The list looks like this:</p>
<pre><code>[{"a":100, "b":50},{"c":2,"a":10}]
</code></pre>
<p>What I want is a dataframe or matrix like this: </p>
<pre><code>a b c
100 50 0
10 0 2
</code></pre>
<p>Then I will feed it ... | -1 | 2016-07-29T09:00:06Z | 38,654,853 | <p>Should you not use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_dict.html" rel="nofollow"><code>df.from_dict</code></a> ?</p>
<p>To feed into a cluster algorithm you could convert the resulting numeric columns into a numpy array:</p>
<pre><code># convert the numeric cols int... | 0 | 2016-07-29T09:09:04Z | [
"python",
"pandas"
] |
How to convert large list of dictionary to dataframe/matrix | 38,654,677 | <p>I have a list of dictionaries which has about 5 million lines.<br>
The list looks like this:</p>
<pre><code>[{"a":100, "b":50},{"c":2,"a":10}]
</code></pre>
<p>What I want is a dataframe or matrix like this: </p>
<pre><code>a b c
100 50 0
10 0 2
</code></pre>
<p>Then I will feed it ... | -1 | 2016-07-29T09:00:06Z | 38,655,094 | <p>If the list doesn't fit in memory, you could loop through your list chunk by chunk (full disclosure: I don't know how slow/fast this solution is):</p>
<pre><code>import pandas as pd
tmp = []
chunksize = 100
df = pd.DataFrame()
for j, item in enumerate(mylist):
tmp.append(item)
if j % chunksize == chunksize-... | 0 | 2016-07-29T09:21:18Z | [
"python",
"pandas"
] |
Django settings module not found | 38,654,683 | <h1>background</h1>
<p>I'm trying to split my settings by environment by following <a href="http://stackoverflow.com/a/15325966/766570">these instructions</a>.</p>
<p>Now I would like to simply run my test command like so:</p>
<pre><code>./run ./manage.py test --settings=bx.settings.local
</code></pre>
<p>currently... | 0 | 2016-07-29T09:00:30Z | 38,654,785 | <p>Once you've imported settings from <code>django.conf</code>, you mustn't import again from settings; you already have the settings object, you can just refer to <code>settings.DOMAIN</code> directly.</p>
| 1 | 2016-07-29T09:05:18Z | [
"python",
"django",
"python-2.7",
"unit-testing",
"django-settings"
] |
Django settings module not found | 38,654,683 | <h1>background</h1>
<p>I'm trying to split my settings by environment by following <a href="http://stackoverflow.com/a/15325966/766570">these instructions</a>.</p>
<p>Now I would like to simply run my test command like so:</p>
<pre><code>./run ./manage.py test --settings=bx.settings.local
</code></pre>
<p>currently... | 0 | 2016-07-29T09:00:30Z | 38,654,815 | <p><code>from settings import DOMAIN</code> tries to load module <code>settings</code> from <code>PYTHONPATH</code>, not from the module you already imported.</p>
<p>You could just do the following:
<code>DOMAIN = settings.DOMAIN</code></p>
| 1 | 2016-07-29T09:06:50Z | [
"python",
"django",
"python-2.7",
"unit-testing",
"django-settings"
] |
Preserving the (non-alphabetical) order of data sets or groups when saving to .hdf5 | 38,654,797 | <p>I have some raw data that I would like to store in .hdf5 file format together with the results I get from the analysis of the data. Before saving the data to disk I sort the different data sets in a way that is meaningful to me, using time. One example of this could be that the data sets are sorted like this: ['50us... | 0 | 2016-07-29T09:05:56Z | 38,666,005 | <p>To my knowledge, this is not possible with h5py. However, it is possible using <a href="http://unidata.github.io/netcdf4-python/" rel="nofollow">netCDF4</a> (comes with the Anaconda distribution if you have that). HDF5 and NetCDF4 files are interoperable, so the resulting file will be able to be read later with h5py... | 1 | 2016-07-29T19:11:43Z | [
"python",
"sorting",
"python-3.x",
"hdf5",
"h5py"
] |
program crashes if image is not found in the folder,but it should record in log- logging issue | 38,654,806 | <p>my program crashes if that particular image is not found in the image folder.The program looks for image in the image folder and imagecolumn in the csv.If the imagename is present in the imagecolumn but not found in the folder ,then it crashes. i tried to log the imagefile,but failed.</p>
<p>This is I have so far<... | -1 | 2016-07-29T09:06:15Z | 38,655,246 | <p>Here :</p>
<pre><code> #checks whether image file exits in folder or not
if (os.path.isfile(oldFileName)):
</code></pre>
<p>You are testing the existence of <code>oldFileName</code>, but then trying to copy <code>old_image</code> :</p>
<pre><code> #creates duplicate copy of an image
... | 1 | 2016-07-29T09:28:20Z | [
"python",
"logging"
] |
What needs to be added in code to remove spaces in config file? | 38,654,903 | <p>i have a config file and when i write into it it has spaces in it</p>
| 0 | 2016-07-29T09:11:46Z | 38,654,935 | <p>Here is the definition of <code>RawConfigParser.write</code>:</p>
<pre><code>def write(self, fp):
"""Write an .ini-format representation of the configuration state."""
if self._defaults:
fp.write("[%s]\n" % DEFAULTSECT)
for (key, value) in self._defaults.items():
fp.write("%s = %... | 4 | 2016-07-29T09:13:29Z | [
"python",
"python-2.7",
"configparser"
] |
InvalidClientSecretsError - df2gspread - Panda - Google Sheet | 38,654,923 | <p>I am a newbie with Python (started learning it 2 weeks ago) and I am struggling with this task. </p>
<p>I am trying to export a data-frame from Panda to a Google Spreadsheet. Yet, after having followed all the necessary steps (<a href="https://github.com/maybelinot/df2gspread" rel="nofollow">https://github.com/mayb... | 0 | 2016-07-29T09:12:50Z | 38,673,030 | <p>The error is indicating that the necessary <strong>OAuth</strong> file that contains client secrets in <code>C:\Users\ User/.gdrive_private</code> cannot be found.</p>
<p>Please check completeness of your <a href="https://developers.google.com/api-client-library/python/guide/aaa_client_secrets" rel="nofollow">Clien... | 0 | 2016-07-30T10:48:19Z | [
"python",
"google-app-engine",
"google-spreadsheet",
"google-drive-sdk"
] |
Minimum System Requirements to run Recommendation in Predictionio | 38,654,977 | <p>I tried to have predictionio integrate with my app. I used recommendation Engine deployment as in <a href="http://docs.prediction.io/templates/recommendation/quickstart/" rel="nofollow">quick start</a> in Predictionio website.
Faced lot of issues but able to build the engine.
I tried to train the model using <code... | 0 | 2016-07-29T09:15:29Z | 38,655,441 | <p>Minimum Requirements can be found in <a href="http://actionml.com/docs/pio_quickstart" rel="nofollow">here</a></p>
| 1 | 2016-07-29T09:37:32Z | [
"python",
"apache-spark",
"recommendation-engine",
"data-science",
"predictionio"
] |
Different crawling behavior on Ubuntu and Windows | 38,654,983 | <p>This piece of code retrieves the content of a page of Google Movies:</p>
<pre><code>import urllib2
f = urllib2.urlopen("https://www.google.com/movies?hl=fr&tid=4f451a87a71bfa51&date=0")
print(f.read())
</code></pre>
<p>It correctly contains the movies scheduled at this theater when I run the script on my W... | 0 | 2016-07-29T09:15:50Z | 38,655,256 | <p>It has nothing to do with the OS itself, or with Python in general.
I tried to access this URL from a Windows machine in a browser and also got something along the lines of "No films found" (used Google Translate as I don't speak French).</p>
<p>I suspect this URL is location-sensitive. When you accessed it through... | 1 | 2016-07-29T09:29:07Z | [
"python",
"urllib2",
"urllib"
] |
Multiprocessing, having issues | 38,654,999 | <p>I'm a fairly novice programmer and I'm putting my hand to multiprocessing for the first time. After running into the usual pickling errors I searched here and found Pathos was likely the best thing to use.</p>
<p>The point of the application in full is it connects to a collection of servers with ssh, pulls data out... | 1 | 2016-07-29T09:16:24Z | 38,658,400 | <p>So trying <code>Pool(1)</code> showed me what issues it was having. I was calling other functions within both this file and other files which, due to the function being an entirely new process it had no idea about, so I had to put import statements for both the other modules and issue a</p>
<pre><code>from thisModu... | 1 | 2016-07-29T12:04:31Z | [
"python",
"pathos"
] |
Merge columns in Pandas based on date criteria | 38,655,042 | <p>I have a dataframe like this</p>
<pre><code>In[337]: df
Out[337]:
2013 2014 2015
2013-01-31 0.705935 0.983307 0.714397
2013-05-31 0.492020 0.532103 0.897666
2013-09-30 0.187822 0.779611 0.774774
2014-01-31 0.789511 0.383665 0.353669
2014-05-31 0.347580 0.540767 0.732863
201... | 2 | 2016-07-29T09:18:40Z | 38,655,271 | <pre><code>import pandas as pd
import datetime
# reproduce test data
> df = pd.DataFrame([[datetime.date(2013,01,31), 0.1, 0.2, 0.3], [datetime.date(2014,01,31), 0.1, 0.2, 0.3], [datetime.date(2015,01,31), 0.1, 0.2, 0.3]], columns=['date', '2013', '2014', '2015']).set_index('date')
> df.index.name = None
> df... | 2 | 2016-07-29T09:29:53Z | [
"python",
"pandas"
] |
Merge columns in Pandas based on date criteria | 38,655,042 | <p>I have a dataframe like this</p>
<pre><code>In[337]: df
Out[337]:
2013 2014 2015
2013-01-31 0.705935 0.983307 0.714397
2013-05-31 0.492020 0.532103 0.897666
2013-09-30 0.187822 0.779611 0.774774
2014-01-31 0.789511 0.383665 0.353669
2014-05-31 0.347580 0.540767 0.732863
201... | 2 | 2016-07-29T09:18:40Z | 38,655,281 | <p>Assuming the dates are parsed you can do this:</p>
<pre><code>df.apply(lambda row: row[str(row.name.year)], axis=1)
</code></pre>
<p><strong>Edit:</strong></p>
<p>This was what I was looking for:</p>
<pre><code>pd.Series(
df.lookup(
row_labels=df.index,
col_labels=df.index.year.astype(str)
... | 3 | 2016-07-29T09:30:12Z | [
"python",
"pandas"
] |
Is there a way of converting a string of 1's and 0's to its binary counterpart, i.e. not ASCII | 38,655,061 | <p>In Python I have learnt that creating ints like <code>0b01101101</code> will create a binary literal.</p>
<p>Say I have a string data type of <code>"01101101"</code> is there a way to convert this to a binary literal?</p>
<p>The example usage is that I am going to create a data packet slowly building up the byte w... | 0 | 2016-07-29T09:19:35Z | 38,655,136 | <p>You can use argument <code>base</code> from string to int conversion:</p>
<pre><code>int('01101101', base=2)
# output : 109
# (and 109 in base 10 = 01101101 in base 2)
</code></pre>
<p>And reverse action, use <code>bin()</code> to create the string with a <code>0b</code> at the beginning:</p>
<pre><code>bin(109)
... | 1 | 2016-07-29T09:23:11Z | [
"python",
"binary",
"serial-port"
] |
Is there a way of converting a string of 1's and 0's to its binary counterpart, i.e. not ASCII | 38,655,061 | <p>In Python I have learnt that creating ints like <code>0b01101101</code> will create a binary literal.</p>
<p>Say I have a string data type of <code>"01101101"</code> is there a way to convert this to a binary literal?</p>
<p>The example usage is that I am going to create a data packet slowly building up the byte w... | 0 | 2016-07-29T09:19:35Z | 38,655,150 | <p>Note on terminology: a binary literal is a piece of text, normally appearing in source code, so I've shown code that results in the same text, in a string object. A binary literal <em>is not a number</em>, but it evaluates to a number in Python code, so I've also shown code to calculate that number. <code>0b01101101... | 2 | 2016-07-29T09:23:55Z | [
"python",
"binary",
"serial-port"
] |
Is there a way of converting a string of 1's and 0's to its binary counterpart, i.e. not ASCII | 38,655,061 | <p>In Python I have learnt that creating ints like <code>0b01101101</code> will create a binary literal.</p>
<p>Say I have a string data type of <code>"01101101"</code> is there a way to convert this to a binary literal?</p>
<p>The example usage is that I am going to create a data packet slowly building up the byte w... | 0 | 2016-07-29T09:19:35Z | 38,655,170 | <p>There is:
First convert it to an int and from there to a binary literal, like so
<code>bin(int("01101101", base=2))</code></p>
| 1 | 2016-07-29T09:24:49Z | [
"python",
"binary",
"serial-port"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.