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 |
|---|---|---|---|---|---|---|---|---|---|
python: utilization of a list in a two level dict | 40,043,288 | <p>How can I initialize a list in a two level dict in a pythonic way?</p>
<pre><code>pos = defaultdict(dict)
pait = "2:N"
cars = ["bus","taxi"]
for x in cars:
pos[x][pait]=[]
</code></pre>
| 0 | 2016-10-14T12:33:56Z | 40,043,400 | <p>Python's list and dictionary comprehensions come in handy for one-line initialization.</p>
<pre><code>pos = {x: {"2:N": []} for x in ["bus", "taxi"]}
</code></pre>
| 1 | 2016-10-14T12:40:19Z | [
"python"
] |
Start two instances of spyder with python2.7 and python3.4 in ubuntu | 40,043,363 | <p>I would like to install two spyder: one is with python2.7 and the other is with python3.4</p>
<p>And I run the commands to install both:</p>
<pre><code>pip install spyder
pip3 install spyder
</code></pre>
<p>But how to start it differently?</p>
<p>Because when I type </p>
<pre><code>spyder
</code></pre>
<p>It ... | 0 | 2016-10-14T12:38:12Z | 40,044,211 | <p>I wasn't able to download spyder through pip3 but instead used <code>apt install spyder3</code> but hopefully this will still work:</p>
<p><strong>For python2.7</strong></p>
<pre><code>spyder
</code></pre>
<p><strong>For python3.4</strong></p>
<pre><code>spyder3
</code></pre>
<p>I could get both running at the ... | 0 | 2016-10-14T13:19:16Z | [
"python",
"python-3.x",
"ide",
"spyder"
] |
Python matrix comparison | 40,043,444 | <p>I have big data like:</p>
<pre><code>{'a_1':0b110000,
'a_2':0b001100,
'a_3':0b000011,
'b_1':0b100100,
'b_2':0b000001,
'c_1':0b100000,}
</code></pre>
<p>and so on... the structure of the data can be reorganized and is more to show, what I want to achieve. Rows of 'a' will never overlap by their sub-rows.
What ... | 0 | 2016-10-14T12:42:13Z | 40,068,611 | <p>Not sure about your triple evaluation* but you might be able to modify this to do what you want. I am assuming you will iterate through the combinations of a,b,c etc.</p>
<pre><code>#!/usr/bin/python
import numpy as np
import random
import time
A = [np.random.randint(0, 2**15, random.randint(1, 5)) + 2**16 for i i... | 1 | 2016-10-16T09:00:10Z | [
"python",
"performance",
"numpy",
"matrix",
"comparison"
] |
How to configure nginx for django with gunicorn? | 40,043,660 | <p>I have successfully run gunicorn and confirmed that my web runs on localhost:8000. But I can't get nginx right. My config file goes like this:</p>
<pre><code> server {
listen 80;
server_name 104.224.149.42;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
</code></pre>
<p>104.2... | -3 | 2016-10-14T12:52:14Z | 40,043,979 | <p>Do this</p>
<ul>
<li>Remove <code>default</code> from <code>/etc/nginx/sites-enabled/default</code></li>
</ul>
<p>Create <code>/etc/nginx/sites-available/my.conf</code> with following</p>
<pre><code>server {
listen 80;
server_name 104.224.149.42;
location / {
proxy_pass http://127.0.0.1:8000;
}
}
</code><... | 0 | 2016-10-14T13:07:15Z | [
"python",
"django",
"nginx"
] |
How to customise QGroupBox title in PyQt5? | 40,043,709 | <p>Here's a piece of code that creates a simple QGroupBox:</p>
<pre><code>from PyQt5.QtWidgets import (QApplication, QWidget,
QGroupBox, QGridLayout)
class QGroupBoxTest(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
gb = QGroupBox()
... | 1 | 2016-10-14T12:54:35Z | 40,057,845 | <p><strong>1)</strong> Probably that's the default QT placement, in the first image the platform style is used, and its take care of borders and title placement, when you change the stylesheet you override something and you get the ugly placement.</p>
<p><strong>2)</strong> You can control the "title" position using ... | 1 | 2016-10-15T10:23:23Z | [
"python",
"css",
"pyqt5"
] |
How to customise QGroupBox title in PyQt5? | 40,043,709 | <p>Here's a piece of code that creates a simple QGroupBox:</p>
<pre><code>from PyQt5.QtWidgets import (QApplication, QWidget,
QGroupBox, QGridLayout)
class QGroupBoxTest(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
gb = QGroupBox()
... | 1 | 2016-10-14T12:54:35Z | 40,072,415 | <p>Even though this question has already been answered, I will post what I've figured out regarding technics of applying style sheets to widgets in PyQt which partly answers my original question. I hope someone will find it useful.</p>
<p>I think it's nice to keep the styles in separate css(qss) files:</p>
<pre><code... | 0 | 2016-10-16T16:13:08Z | [
"python",
"css",
"pyqt5"
] |
Remove html after some point in Beautilful Soup | 40,043,715 | <p>I have a trouble. My aim is to parse the data until some moment. Then, I want to stop parsing.</p>
<pre><code> <span itemprop="address">
Some address
</span>
<i class="fa fa-signal">
</i>
...
</p>
</div>
</div&g... | 2 | 2016-10-14T12:54:49Z | 40,043,941 | <p>You can actually let <code>BeautifulSoup</code> <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#parsing-only-part-of-a-document" rel="nofollow">parse only the tags you are interested in via <code>SoupStrainer</code></a>:</p>
<pre><code>from bs4 import BeautifulSoup, SoupStrainer
only_addresses = So... | 1 | 2016-10-14T13:05:50Z | [
"python",
"html",
"beautifulsoup"
] |
print random data for each millisecond python | 40,043,749 | <p>I want to print random data ranging from -1 to 1 in csv file for each millisecond using Python. I started with to print for each second and it worked. But, I am facing difficulty with printing random data for each millisecond. I want the timestamp to be in UNIX epoch format like "1476449030.55676" (for milliseconds,... | 1 | 2016-10-14T12:56:18Z | 40,044,008 | <p>UPD: <code>time.sleep()</code> accepts argument in seconds, so you don't need to divide it by 1000. After fixing this, my output looks like this:</p>
<pre><code>0.18153176446804853,1476466290.720721
-0.9331178681567136,1476466290.721784
-0.37142653326337327,1476466290.722779
0.1397040393287503,1476466290.723766
0.7... | 0 | 2016-10-14T13:08:36Z | [
"python",
"csv",
"printing",
"milliseconds"
] |
How to get into the python shell within Odoo 8 environment? | 40,043,813 | <p>I would like to use the Odoo Framework from the shell.</p>
<p>I installed the module <a href="https://www.odoo.com/apps/modules/8.0/shell/" rel="nofollow">"Shell command backport"</a> (technical name: <code>shell</code>), but I couldn't make it work.</p>
<pre><code>$ ./odoo.py shell --addons-path=/opt/odoo_8/src/l... | 0 | 2016-10-14T12:59:27Z | 40,051,325 | <p>Check your <code>.opererp_serverrc</code> for the user you are executing the command as. In the users home directory you will find this file. There may be reference to the <code>addons_path</code>. The path it appears to be looking for <code>/opt/odoo8/openerp/addons</code> differs from what you have specified in yo... | 2 | 2016-10-14T20:15:28Z | [
"python",
"shell",
"path",
"odoo-8"
] |
Find the last window created in Maya? | 40,043,917 | <p>I was wondering if there is any way to find the name of the last window created in Maya, knowing that I can't add any information to the window itself before that... I checked in both the <code>cmds</code> and API but couldn't find anything. Maybe in PyQt but I don't know much about it.</p>
<p>I'm looking for any s... | 0 | 2016-10-14T13:04:34Z | 40,044,189 | <p>you can work with something like a close callback, save the needed information and restore it again </p>
<pre><code>def restoreLayout(self):
"""
Restore the layout of each widget
"""
settings=self.settings
try:
self.restoreGeometry(settings.value("geometry").toByteArray())
self.r... | 1 | 2016-10-14T13:18:12Z | [
"python",
"maya"
] |
Find the last window created in Maya? | 40,043,917 | <p>I was wondering if there is any way to find the name of the last window created in Maya, knowing that I can't add any information to the window itself before that... I checked in both the <code>cmds</code> and API but couldn't find anything. Maybe in PyQt but I don't know much about it.</p>
<p>I'm looking for any s... | 0 | 2016-10-14T13:04:34Z | 40,046,747 | <p>Here is what I came up with, it's surely not the "cleanest" solution but it works!</p>
<pre><code># List all the currently opened windows
uisBefore = cmds.lsUI (wnd = True)
# Execute the function which may or may not create a window
func(*args, **kwargs)
# List all the opened windows again
uisAfter = cmds.lsUI (w... | 0 | 2016-10-14T15:23:34Z | [
"python",
"maya"
] |
Find the last window created in Maya? | 40,043,917 | <p>I was wondering if there is any way to find the name of the last window created in Maya, knowing that I can't add any information to the window itself before that... I checked in both the <code>cmds</code> and API but couldn't find anything. Maybe in PyQt but I don't know much about it.</p>
<p>I'm looking for any s... | 0 | 2016-10-14T13:04:34Z | 40,051,380 | <p>If you create a window with the <code>window</code> command, you'll get back the name of the window you just created:</p>
<pre><code>import maya.cmds as cmds
w = cmds.window()
c= cmds.columnLayout()
def who_am_i(*_):
print "window is", w
b = cmds.button('push', c=who_am_i)
cmds.showWindow(w)
</code></pre>
<p... | 1 | 2016-10-14T20:19:32Z | [
"python",
"maya"
] |
Launch python from specific exe in PHP | 40,043,954 | <p>I've a php file for launch my python file with default version (2.7):</p>
<pre><code><?php
echo '<pre>';
system("cmd /c D:\web\folder\easypy.py");
echo '</pre>';
?>
</code></pre>
<p>But I developped a python file more strong who work with other python (3.5). So I need to use the exe o... | -2 | 2016-10-14T13:06:13Z | 40,044,186 | <p>system in php looks like this:</p>
<pre><code>system("command", $retval); //retval is optional
</code></pre>
<p>command in your case is:</p>
<pre><code> "cmd /c D:/folder1/folder2/python35/python.exe D:/web/folder/strongpy.py"
</code></pre>
<p>the final php code looks like this:</p>
<pre><code>system("cmd /c D:... | 1 | 2016-10-14T13:17:53Z | [
"php",
"python",
"cmd"
] |
How do I call an Excel VBA script using xlwings v0.10 | 40,044,090 | <p>I used to use the info in this question to run a VBA script that does some basic formatting after I run my python code.</p>
<p><a href="http://stackoverflow.com/questions/30308455/how-do-i-call-an-excel-macro-from-python-using-xlwings">How do I call an Excel macro from Python using xlwings?</a></p>
<p>Specifically... | 1 | 2016-10-14T13:12:19Z | 40,058,238 | <p>You need to use <code>Book.macro</code>. As your link to the docs says, <code>App.macro</code> is only for macros that are not part of a workbook (i.e. addins). So use:</p>
<pre><code>wb.macro('your_macro')
</code></pre>
| 0 | 2016-10-15T11:04:39Z | [
"python",
"xlwings"
] |
Kivy object doesn't render when defined in .kv file | 40,044,117 | <p>I'm developing an app in kivy and currently trying to figure out why I can get an object to render when I add it in Python but not in the .kv file.</p>
<p>This works fine, rendering the background image with a switch on top of it.</p>
<pre><code>class LoginScreen(Screen):
def __init__(self,**kwargs):
s... | 0 | 2016-10-14T13:14:07Z | 40,053,001 | <p>If you want to use a custom class created in <code>.py</code> file with kv language, you need to set it in <code>.kv</code> file too:</p>
<pre><code><defScreen>: # class def
<LoginScreen>:
...
defScreen: # object
</code></pre>
<p>so that it knows what to look for.</p>
<p>Also I'd like to ... | 1 | 2016-10-14T22:43:20Z | [
"python",
"python-2.7",
"kivy",
"python-2.x",
"kivy-language"
] |
Substituting variables into strings | 40,044,171 | <p>Currently I know that we can do something like</p>
<pre><code>"This is a string with var %(sub_var)s that will be substituted" % ({'sub_var': 'a1234'})
</code></pre>
<p>That will sub in the <code>sub_var</code> variable into the string. However is there a way to define a string like this:</p>
<pre><code>a = "This... | -1 | 2016-10-14T13:17:12Z | 40,044,247 | <p>Did you try exactly what you said?</p>
<pre><code> a = "This is a string with var %(sub_var)s that will be substituted"
=> None
a
=> 'This is a string with var %(sub_var)s that will be substituted'
a % {'sub_var': 'c'}
=> 'This is a string with var c that will be substituted'
</code></pre>
| 3 | 2016-10-14T13:20:48Z | [
"python",
"string",
"python-2.7"
] |
Substituting variables into strings | 40,044,171 | <p>Currently I know that we can do something like</p>
<pre><code>"This is a string with var %(sub_var)s that will be substituted" % ({'sub_var': 'a1234'})
</code></pre>
<p>That will sub in the <code>sub_var</code> variable into the string. However is there a way to define a string like this:</p>
<pre><code>a = "This... | -1 | 2016-10-14T13:17:12Z | 40,044,262 | <p>Store a function in the variable that can be used to make the strings:</p>
<pre><code>>>a='Variable is {}'.format
>>print(a('one'))
Variable is one
>>print(a('two'))
Variable is two
</code></pre>
| 0 | 2016-10-14T13:21:20Z | [
"python",
"string",
"python-2.7"
] |
Python and flask, looping and printing data based on a variable | 40,044,172 | <p>I have a problem with looping in python and JSON based on a variable. What Im trying to do is to print just one row of JSON data based on one variable that is passed through.</p>
<p>Heres the code for the python file:</p>
<pre><code>@app.route('/<artist_name>/')
def artist(artist_name):
list = [
... | -1 | 2016-10-14T13:17:12Z | 40,044,425 | <p>my solution is less complicated, and working :)</p>
<pre><code>from flask import Flask,render_template,url_for
import json
app = Flask(__name__)
app.debug = False
@app.route('/<artist_name>/')
def artist(artist_name):
list = [
{'artist_name': 'Nirvana', 'album_name': 'Nevermind', 'date_of_release... | 0 | 2016-10-14T13:30:04Z | [
"python",
"json",
"loops",
"variables",
"flask"
] |
Python and flask, looping and printing data based on a variable | 40,044,172 | <p>I have a problem with looping in python and JSON based on a variable. What Im trying to do is to print just one row of JSON data based on one variable that is passed through.</p>
<p>Heres the code for the python file:</p>
<pre><code>@app.route('/<artist_name>/')
def artist(artist_name):
list = [
... | -1 | 2016-10-14T13:17:12Z | 40,044,456 | <p>In the comments, H J potter and Markus have it right: <em>however</em> I'ld be very careful over the url encoding of your url and enforcing capitlisation of the artist name: Is "System Of A Down" the same as "System of a Down", and does flask always decode correctly?</p>
<pre><code>{% if results %}
<ul>
{% fo... | 0 | 2016-10-14T13:31:39Z | [
"python",
"json",
"loops",
"variables",
"flask"
] |
select specific column from panads MultiIndex dataframe | 40,044,260 | <p>I have a MultiIndex dataframe with 200 columns, I would like to select an specific column from that. Suppose, df is some part of my dataframe:</p>
<pre><code>df=
a b
l h l h l h l
col... | 1 | 2016-10-14T13:21:15Z | 40,044,656 | <p>Try this:</p>
<pre><code>dataframe= pd.DataFrame()
dataframe["temp"] = df["b"]["h"]["hot"]
</code></pre>
<p>df - is your dataframe</p>
| 0 | 2016-10-14T13:40:36Z | [
"python",
"pandas"
] |
select specific column from panads MultiIndex dataframe | 40,044,260 | <p>I have a MultiIndex dataframe with 200 columns, I would like to select an specific column from that. Suppose, df is some part of my dataframe:</p>
<pre><code>df=
a b
l h l h l h l
col... | 1 | 2016-10-14T13:21:15Z | 40,044,994 | <p>For multi-index slicing as you desire the columns needs to be sorted first using <code>sort_index(axis=1)</code>, you can then select the cols of interest without error:</p>
<pre><code>In [12]:
df = df.sort_index(axis=1)
df['a','h','hot']
Out[12]:
0
2009-01-01 01:00:00 0.9
2009-01-01 02:00:00 0.8
2009-01-01 ... | 1 | 2016-10-14T13:56:22Z | [
"python",
"pandas"
] |
How to calculate the Kolmogorov-Smirnov statistic between two weighted samples | 40,044,375 | <p>Let's say that we have two samples <code>data1</code> and <code>data2</code> with their respective weights <code>weight1</code> and <code>weight2</code> and that we want to calculate the Kolmogorov-Smirnov statistic between the two weighted samples.</p>
<p>The way we do that in python follows:</p>
<pre><code>def k... | 1 | 2016-10-14T13:27:28Z | 40,059,727 | <p>Studying the <code>scipy.stats.ks_2samp</code> code we were able to find a more efficient python solution. We share below in case anyone is interested:</p>
<pre><code>def ks_w2(data1,data2,wei1,wei2):
ix1=np.argsort(data1)
ix2=np.argsort(data2)
data1=data1[ix1]
data2=data2[ix2]
wei1=wei1[ix1]
... | 0 | 2016-10-15T13:40:57Z | [
"python",
"scipy",
"kolmogorov-smirnov"
] |
oct2py in Anaconda/Spyder not recognizing octave | 40,044,448 | <p>Windows7</p>
<p>Anaconda/python ver 3.4</p>
<p>Octave ver 4.0.3</p>
<p>OCTAVE_EXECUTABLE = C:\Users\Heather\Octave-4.0.3\bin</p>
<p>Hi all, </p>
<p>I've been working a few days on trying to get oct2py working in Anaconda using Spyder. I was wondering if anyone could tell me the correct way to get it to work in... | -1 | 2016-10-14T13:31:19Z | 40,045,238 | <p>The <code>OCTAVE_EXECUTABLE</code> or <code>OCTAVE</code> environment variables should point directly to the <em>executable</em> and not the folder that contains the executable. So you'll likely want to set it to </p>
<pre><code>OCTAVE_EXECUTABLE = C:\Users\Heather\Octave-4.0.3\bin\octave-cli.exe
</code></pre>
<p>... | 0 | 2016-10-14T14:08:44Z | [
"python",
"octave",
"anaconda",
"spyder"
] |
I can not run a server on Django | 40,044,452 | <p>I have a problem: after the <code>python manage.py runserver</code> command I receive the following error which I can not solve:</p>
<pre><code>Unhandled exception in thread started by <function wrapper at 0xb6712e64>
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/django/utils/aut... | 0 | 2016-10-14T13:31:30Z | 40,044,511 | <p>Are you sure that the name of the widget class is correct?
I was checking django-redactor and django-redactoreditor and they don't have a class named "JQueryEditor".</p>
| 0 | 2016-10-14T13:34:28Z | [
"python",
"django"
] |
Python How to sort list in a list | 40,044,490 | <p>I'm trying to sort a list within a list. This is what I have. I would like to sort the inner namelist based on alphabetical order. Have tried using loops but to no avail. The smaller 'lists' inside happens to be strings so I can't sort() them as list. Error: 'str' object has no attribute 'sort'</p>
<pre><code>Names... | -1 | 2016-10-14T13:33:23Z | 40,044,563 | <pre><code>Names = [sorted(sublist) for sublist in Names]
</code></pre>
<p>This is a list comprehension that takes each sublist of <code>Names</code>, sorts it, and then builds a new list out of those sorted lists. It then makes <code>Names</code> that list</p>
| 4 | 2016-10-14T13:36:56Z | [
"python",
"string",
"list",
"sorting"
] |
Python How to sort list in a list | 40,044,490 | <p>I'm trying to sort a list within a list. This is what I have. I would like to sort the inner namelist based on alphabetical order. Have tried using loops but to no avail. The smaller 'lists' inside happens to be strings so I can't sort() them as list. Error: 'str' object has no attribute 'sort'</p>
<pre><code>Names... | -1 | 2016-10-14T13:33:23Z | 40,044,666 | <p>The built - in list method: <code>sort()</code> works in-place on sub lists if you iterate over them:</p>
<pre><code>Names = [['John', 'Andrea', 'Regina', 'Candice', 'Charlotte', 'Melanie'], ['Claudia', 'Lace', 'Karen', 'Ronald', 'Freddy'], ['James', 'Luke', 'Ben', 'Nick']
for sublist in Names:
sublist.sort()
... | 2 | 2016-10-14T13:40:55Z | [
"python",
"string",
"list",
"sorting"
] |
Iterating through json object in python | 40,044,504 | <p>I have a response from Foursquare that reads as follows</p>
<pre><code>response: {
suggestedFilters: {},
geocode: {},
headerLocation: "Harlem",
headerFullLocation: "Harlem",
headerLocationGranularity: "city",
query: "coffee",
totalResults: 56,
suggestedBounds: {},
groups: [{
... | 0 | 2016-10-14T13:34:13Z | 40,044,552 | <p>You went too far. The [0] is the first element of the groups</p>
<pre><code>for value in json_data['response']['groups']
</code></pre>
<p>Or you need to actually parse the JSON data from a string with the <code>json.loads</code> function </p>
<p>Also, I think you want </p>
<pre><code>value['venue']['name']
</cod... | 1 | 2016-10-14T13:36:25Z | [
"python",
"json"
] |
Iterating through json object in python | 40,044,504 | <p>I have a response from Foursquare that reads as follows</p>
<pre><code>response: {
suggestedFilters: {},
geocode: {},
headerLocation: "Harlem",
headerFullLocation: "Harlem",
headerLocationGranularity: "city",
query: "coffee",
totalResults: 56,
suggestedBounds: {},
groups: [{
... | 0 | 2016-10-14T13:34:13Z | 40,044,610 | <p><code>json_data['response']['groups'][0]</code> is a dictionary. When you iterate over a dictionary, you are iterating over a list of keys, all of which are strings...so within the loop, <code>value</code> is a string.</p>
<p>So when you ask for <code>value['name']</code>, you are trying to index the string with <... | 0 | 2016-10-14T13:38:40Z | [
"python",
"json"
] |
python decode partial utf-8 byte array | 40,044,517 | <p>I'm getting data from channel which is not aware about UTF-8 rules. So sometimes when UTF-8 is using multiple bytes to code one character and I try to convert part of received data into text I'm getting error during conversion. By nature of interface (stream without any end) I'm not able to find out when data are fu... | 0 | 2016-10-14T13:34:39Z | 40,044,518 | <p>So far I come up with not so nice function:</p>
<pre><code>def decodeBytesUtf8Safe(toDec):
"""
decodes byte array in utf8 to string. It can handle case when end of byte array is
not complete thus making utf8 error. in such case text is translated only up to error.
Rest of byte array (from error to e... | 0 | 2016-10-14T13:34:39Z | [
"python",
"utf-8"
] |
python decode partial utf-8 byte array | 40,044,517 | <p>I'm getting data from channel which is not aware about UTF-8 rules. So sometimes when UTF-8 is using multiple bytes to code one character and I try to convert part of received data into text I'm getting error during conversion. By nature of interface (stream without any end) I'm not able to find out when data are fu... | 0 | 2016-10-14T13:34:39Z | 40,046,018 | <p>You can call the codecs module to the rescue. It gives you directly a incremental decoder, that does exactly what you need:</p>
<pre><code>import codecs
dec = codecs.getincrementaldecoder('utf8')()
</code></pre>
<p>You can feed it with: <code>dec.decode(input)</code> and when it is over, optionally add a <code>de... | 3 | 2016-10-14T14:46:14Z | [
"python",
"utf-8"
] |
Python tensor product | 40,044,714 | <p>I have the following problem. For performance reasons I use <code>numpy.tensordot</code> and have thus my values stored in tensors and vectors.
One of my calculations look like this:</p>
<p><a href="https://i.stack.imgur.com/PLDSC.png" rel="nofollow"><img src="https://i.stack.imgur.com/PLDSC.png" alt="enter image ... | 2 | 2016-10-14T13:42:55Z | 40,045,478 | <p>You could do that with a series of reductions, like so -</p>
<pre><code>p1 = np.tensordot(re,ewp,axes=(1,0))
p2 = np.tensordot(p1,ewp,axes=(1,0))
out = p2**2
</code></pre>
<p><strong>Explanation</strong></p>
<p>First off, we could separate it out into two groups of operations :</p>
<pre><code>Group 1: R(i,j,k) ,... | 2 | 2016-10-14T14:19:34Z | [
"python",
"performance",
"numpy",
"numpy-einsum"
] |
find mean and corr of 10,000 columns in pyspark Dataframe | 40,044,779 | <p>I have DF with 10K columns and 70Million rows. I want to calculate the mean and corr of 10K columns. I did below code but it wont work due to code size 64K issue (<a href="https://issues.apache.org/jira/browse/SPARK-16845" rel="nofollow">https://issues.apache.org/jira/browse/SPARK-16845</a>)</p>
<p>Data:</p>
<pre>... | 0 | 2016-10-14T13:45:59Z | 40,046,119 | <p>We also ran into the 64KB issue, but in a where clause, which is filed under another bug report. What we used as a workaround, is simply, to do the operations/transformations in several steps.</p>
<p>In your case, this would mean, that you don't do all the aggregatens in one step. Instead loop over the relevant col... | 1 | 2016-10-14T14:51:41Z | [
"python",
"apache-spark",
"pyspark",
"spark-dataframe"
] |
Python:Update list of tuples | 40,044,814 | <p>I have a list of tuples like this:</p>
<p>list = [(1, 'q'), (2, 'w'), (3, 'e'), (4, 'r')]</p>
<p>and i am trying to create a update function update(item,num) which search the item in the list and then change the num.</p>
<p>for example if i use update(w,6) the result would be </p>
<pre><code>list = [(1, 'q')... | 4 | 2016-10-14T13:48:03Z | 40,044,975 | <p>As noted in the comments, you are using an immutable data structure for data items that you are attempting to change. Without further context, it looks like you want a dictionary, not a list of tuples, and it also looks like you want the second item in the tuple (the letter) to be the key, since you are planning on ... | 3 | 2016-10-14T13:55:37Z | [
"python",
"python-2.7",
"python-3.x"
] |
Python:Update list of tuples | 40,044,814 | <p>I have a list of tuples like this:</p>
<p>list = [(1, 'q'), (2, 'w'), (3, 'e'), (4, 'r')]</p>
<p>and i am trying to create a update function update(item,num) which search the item in the list and then change the num.</p>
<p>for example if i use update(w,6) the result would be </p>
<pre><code>list = [(1, 'q')... | 4 | 2016-10-14T13:48:03Z | 40,045,156 | <p>You can simply scan through the list looking for a tuple with the desired letter and replace the whole tuple (you can't modify tuples), breaking out of the loop when you've found the required item. Eg,</p>
<pre><code>lst = [(1, 'q'), (2, 'w'), (3, 'e'), (4, 'r')]
def update(item, num):
for i, t in enumerate(ls... | 5 | 2016-10-14T14:04:45Z | [
"python",
"python-2.7",
"python-3.x"
] |
Python:Update list of tuples | 40,044,814 | <p>I have a list of tuples like this:</p>
<p>list = [(1, 'q'), (2, 'w'), (3, 'e'), (4, 'r')]</p>
<p>and i am trying to create a update function update(item,num) which search the item in the list and then change the num.</p>
<p>for example if i use update(w,6) the result would be </p>
<pre><code>list = [(1, 'q')... | 4 | 2016-10-14T13:48:03Z | 40,045,176 | <p>Tuples are an immutable object. Which means once they're created, you can't go changing there contents.</p>
<p>You can, work around this however, by replaceing the tuple you want to change. Possibly something such as this:</p>
<pre><code>def change_item_in_list(lst, item, num):
for pos, tup in enumerate(lst):
... | 1 | 2016-10-14T14:05:28Z | [
"python",
"python-2.7",
"python-3.x"
] |
pandas read_sql is unusually slow | 40,045,093 | <p>I'm trying to read several columns from three different MySQL tables into three different dataframes.</p>
<p>It doesn't take long to read from the database, but actually putting them into a dataframe is fairly slow.</p>
<pre><code>start_time = time.time()
print('Reading data from database...')
from sqlalchemy imp... | 0 | 2016-10-14T14:01:09Z | 40,047,381 | <p>IMO it doesn't make much sense to read up complete tables to Pandas DFs if you have them in MySQL DB - why don't you use SQL for filtering and joining your data? Do you really need <strong>all</strong> rows from those three tables as Pandas DFs? </p>
<p>If you want to join them you could do it first on the MySQL si... | 1 | 2016-10-14T15:54:40Z | [
"python",
"mysql",
"pandas"
] |
Accuracy not high enough for dogs_cats classification dataset using CNN with Keras-Tf python | 40,045,159 | <p>Guys I'm trying to classify the Dogs vs Cats dataset using CNN. I'm deep learning beginner btw.</p>
<p>The dataset link can be obtained from <a href="https://www.kaggle.com/c/dogs-vs-cats/data" rel="nofollow">here</a>. I've also classified the above dataset using MLP with a training accuracy of 70% and testing accu... | 2 | 2016-10-14T14:04:53Z | 40,098,342 | <p>Basically, your network is not deep enough. That is why both your training and validation accuracy are low. You can try to deepen your network from two aspects.</p>
<ol>
<li><p>Use larger number of filters for each convolutional layer. (30, 5, 5) or (15, 3, 3) are just not enough. Change the first convolutional lay... | 0 | 2016-10-18T01:57:56Z | [
"python",
"keras",
"conv-neural-network"
] |
Filtering pandas DataFrame | 40,045,175 | <p>I'm reading in a .csv file using pandas, and then I want to filter out the rows where a specified column's value is not in a dictionary for example. So something like this:</p>
<pre><code>df = pd.read_csv('mycsv.csv', sep='\t', encoding='utf-8', index_col=0,
names=['col1', 'col2','col3','col4'])
c = df.col4.... | 0 | 2016-10-14T14:05:21Z | 40,045,266 | <p>If you want to check against the dictionary values:</p>
<pre><code>df_filtered = df[df.col4.isin(values.values())]
</code></pre>
<p>If you want to check against the dictionary keys:</p>
<pre><code>df_filtered = df[df.col4.isin(values.keys())]
</code></pre>
| 1 | 2016-10-14T14:09:56Z | [
"python",
"csv",
"pandas"
] |
Filtering pandas DataFrame | 40,045,175 | <p>I'm reading in a .csv file using pandas, and then I want to filter out the rows where a specified column's value is not in a dictionary for example. So something like this:</p>
<pre><code>df = pd.read_csv('mycsv.csv', sep='\t', encoding='utf-8', index_col=0,
names=['col1', 'col2','col3','col4'])
c = df.col4.... | 0 | 2016-10-14T14:05:21Z | 40,048,354 | <p>As A.Kot mentioned you could use the values method of the <code>dict</code> to search. But the <code>values</code> method returns either a <code>list</code> or an iterator depending on your version of Python.</p>
<p>If your only reason for creating that <code>dict</code> is membership testing, and you only ever loo... | 0 | 2016-10-14T16:56:23Z | [
"python",
"csv",
"pandas"
] |
Python Log Level with an additional verbosity depth | 40,045,288 | <p>I would like to extend the existing <code>logging.LEVEL</code> mechanics so that I have the option of switching between different logging levels such as <code>DEBUG</code>, <code>INFO</code>, <code>ERROR</code> etc. but also define a <code>depth</code> for each of the levels.</p>
<p>For example, let's assume that t... | 1 | 2016-10-14T14:10:43Z | 40,052,090 | <p>Can't you just use the more fine grained logging levels? <code>DEBUG</code> is just a wrapper for level 10. You can use</p>
<pre><code>Logger.log(10, "message")
</code></pre>
<p>to log at debug level and then</p>
<pre><code>Logger.log(9, "message")
</code></pre>
<p>which won't show up at debug level, but will if... | 1 | 2016-10-14T21:14:11Z | [
"python",
"logging"
] |
Kivy scrollbar scroll direction with mouse | 40,045,326 | <p>Is there a way to change the scroll behavior of Kivy scrollbars when using a mouse? With a mousewheel, the contents of a DropDown or Spinner scroll up or down as expected. However, if you use a mouse to grab the scrollbar and slide it up, the direction is reversed - you have to drag the mouse pointer down to move ... | 1 | 2016-10-14T14:12:32Z | 40,061,155 | <p>This can be fixed by modifying the DropDown from which Spinner inherits to change scroll_type to include 'bars' (just 'content' by default). I fixed this behaviour as follows:</p>
<pre><code>from functools import partial
dropdownMod = partial(DropDown, bar_width = 10, scroll_type = ['bars','content'])
class Spin... | 0 | 2016-10-15T15:54:48Z | [
"python",
"windows",
"python-2.7",
"kivy",
"python-2.x"
] |
How in python's module CONFIGPARSER read text from variable, not from a file? | 40,045,338 | <p>The problem is that <code>config.read("filename.ini")</code> - requires a local file. I download the content of this file straight into the variable from my FTP server with the help of StringIO. </p>
<pre><code>content = StringIO()
f.retrbinary('RETR /folder1/inifile.ini, content.write)
request = content.getvalue()... | 0 | 2016-10-14T14:13:17Z | 40,046,881 | <p>I found this in the python docs.</p>
<p>Using your StringIO object it looks like you can use config.readfp(contents).</p>
| 0 | 2016-10-14T15:29:34Z | [
"python",
"ftp",
"readfile",
"ini",
"configparser"
] |
celery not all tasks in a group are executed | 40,045,405 | <p>I have simple celery case:</p>
<pre><code>@task()
def my_task1(index):
log.info(index)
@task()
def my_task2():
tasks=[my_task1.si(1), my_task1.si(2), my_task1.si(3), my_task1.si(4)]
group(*tasks)()
</code></pre>
<p>When I run <code>my_task2</code>, I only see tasks with integers 2 and 4 in celery cons... | 0 | 2016-10-14T14:16:27Z | 40,046,932 | <p>Problem solved - I had another celery running...</p>
| 0 | 2016-10-14T15:32:00Z | [
"python",
"celery",
"django-celery"
] |
Python - Group by over dicts | 40,045,458 | <p>I am using Python 3.5 and I have the following array of dics:</p>
<pre><code>d1 = [{id=1, col="name", oldvalue="foo", newvalue="bar"}, {id=1, col="age", oldvalue="25", newvalue="26"}, {id=2, col="name", oldvalue="foo", newvalue="foobar"}, {id=3, col="age", oldvalue="25", newvalue="26"}]
d2 = [{id=1, col="name", ol... | 0 | 2016-10-14T14:18:44Z | 40,045,522 | <p>If you're looking for the number of unique <code>id</code>s, then</p>
<pre><code>len({row['id'] for row in d})
</code></pre>
<p>The <code>{}</code> is a set comprehension.</p>
| 1 | 2016-10-14T14:22:20Z | [
"python",
"dictionary",
"python-3.5"
] |
MySQL data to a python dict structure | 40,045,496 | <p>The structure of my mysql table looks like this:</p>
<pre><code>id | mid | liters | timestamp
1 | 20 | 50 | 2016-10-11 10:53:25
2 | 30 | 60 | 2016-10-11 10:40:20
3 | 20 | 100 | 2016-10-11 10:09:27
4 | 30 | 110 | 2016-10-11 09:55:07
5 | 40 | 80 | 2016-10-11 09:44:46
6 | 40 | 90 | 2016-10-11 07:56:14
7 | 20 | 120 | 2... | 0 | 2016-10-14T14:20:38Z | 40,045,619 | <p><code>GROUP_CONCAT</code> may have own <code>ORDER BY</code></p>
<p>e.g .</p>
<pre><code>GROUP_CONCAT(mid,liters,timestamp ORDER BY liters)
</code></pre>
| 0 | 2016-10-14T14:27:43Z | [
"python",
"mysql",
"sql",
"dictionary"
] |
Pandas: query string where column name contains special characters | 40,045,545 | <p>I am working with a data frame that has a structure something like the following:</p>
<pre><code>In[75]: df.head(2)
Out[75]:
statusdata participant_id association latency response \
0 complete CLIENT-TEST-1476362617727 seeya 715 dislike
1 complete CLIENT-TEST-1476362617727 ... | 0 | 2016-10-14T14:24:07Z | 40,045,659 | <p>The current implementation of <code>query</code> requires the string to be a valid python expression, so column names must be valid python identifiers. Your two options are renaming the column, or using a plain boolean filter, like this:</p>
<pre><code>df[df['demo$gender'] =='male']
</code></pre>
| 1 | 2016-10-14T14:29:23Z | [
"python",
"pandas",
"dataframe"
] |
Pandas: query string where column name contains special characters | 40,045,545 | <p>I am working with a data frame that has a structure something like the following:</p>
<pre><code>In[75]: df.head(2)
Out[75]:
statusdata participant_id association latency response \
0 complete CLIENT-TEST-1476362617727 seeya 715 dislike
1 complete CLIENT-TEST-1476362617727 ... | 0 | 2016-10-14T14:24:07Z | 40,083,013 | <p>For the interested here is a simple proceedure I used to accomplish the task:</p>
<pre><code># Identify invalid column names
invalid_column_names = [x for x in list(df.columns.values) if not x.isidentifier() ]
# Make replacements in the query and keep track
# NOTE: This method fails if the frame has columns called... | 0 | 2016-10-17T09:39:30Z | [
"python",
"pandas",
"dataframe"
] |
ImportError: No module named skimage | 40,045,579 | <p>I'm trying to use scikit-image on Mac OS X El Capitan. </p>
<p>I installed scikit-image and the relevant dependencies using <code>pip install scikit-image</code>, but when I run python and try <code>import skimage</code> I get the error: <code>ImportError: No module named skimage</code>.</p>
<p>Running <code>pip l... | 0 | 2016-10-14T14:25:31Z | 40,057,881 | <p>Resetting my <code>$PYTHONPATH</code> seems to have fixed the problem. </p>
| 0 | 2016-10-15T10:26:42Z | [
"python",
"scikit-image",
"dlib"
] |
Adding a column in pandas df using a function | 40,045,632 | <p>I have a pandas df(see below). I want to add a column called "price" which I want to derive the values from using a function. How do I go about doing this?</p>
<pre><code>function:
def getquotetoday(symbol):
yahoo = Share(symbol)
return yahoo.get_prev_close()
df:
Symbol Bid Ask
MSFT ... | -1 | 2016-10-14T14:28:07Z | 40,045,819 | <p>In general, you can use the apply function. If your function is of only one column, you can use:</p>
<pre><code>df['price'] = df['Symbol'].apply(getquotetoday)
</code></pre>
<p>as @EdChum suggested. If your function happens to require multiple columns, you can use, for example, something like:</p>
<pre><code>df['... | 1 | 2016-10-14T14:37:03Z | [
"python",
"function",
"pandas",
"dataframe",
"yahoo"
] |
Python Regex: Using a lookahead | 40,045,740 | <p>I'm trying to detect text of the following type, in order to remove it from the text:</p>
<pre><code>BOLD:Parshat NoachBOLD:
BOLD:Parshat Lech LechaBOLD:
BOLD:Parshat VayeraBOLD
BOLD:Parshat ShâminiBOLD:
</code></pre>
<p>But only to capture this part:</p>
<pre><code>BOLD:Parshat Noach
BOLD:Parshat Lech Lecha
BO... | 0 | 2016-10-14T14:33:23Z | 40,045,826 | <p>You don't need look-around just use a capture group and <code>re.MULTILINE</code> flag in order to match a multi line text.</p>
<pre><code>In [8]: s = """BOLD:Parshat NoachBOLD:
...: BOLD:Parshat Lech LechaBOLD:
...: BOLD:Parshat VayeraBOLD
...: BOLD:Parshat ShâminiBOLD:"""
In [9]: re.findall(r'^(BOLD.*... | 0 | 2016-10-14T14:37:27Z | [
"python",
"regex"
] |
Python Regex: Using a lookahead | 40,045,740 | <p>I'm trying to detect text of the following type, in order to remove it from the text:</p>
<pre><code>BOLD:Parshat NoachBOLD:
BOLD:Parshat Lech LechaBOLD:
BOLD:Parshat VayeraBOLD
BOLD:Parshat ShâminiBOLD:
</code></pre>
<p>But only to capture this part:</p>
<pre><code>BOLD:Parshat Noach
BOLD:Parshat Lech Lecha
BO... | 0 | 2016-10-14T14:33:23Z | 40,045,872 | <p>In python you can just do:</p>
<pre><code>str = re.sub(r'BOLD:?$', '', str, 0, re.MULTILINE)
</code></pre>
<p><a href="https://regex101.com/r/qiNd4L/3" rel="nofollow">RegEx Demo</a></p>
<p>That will remove <code>BOLD</code> followed by optional <code>:</code> from the end of each line.</p>
<hr>
<p><strong>EDIT:... | 1 | 2016-10-14T14:39:35Z | [
"python",
"regex"
] |
multiple domains - one django project | 40,045,801 | <p>I want to run ONE django project on multiple domains/websites. The websites each need to access a unique "urls.py"/"views.py". I tried it already with <a href="http://michal.karzynski.pl/blog/2010/10/19/run-multiple-websites-one-django-project/" rel="nofollow">this tutorial</a>, but it doesn't work for me.
Is there ... | 0 | 2016-10-14T14:36:20Z | 40,064,648 | <p>I found the solution <a href="https://code.djangoproject.com/wiki/MultiHostMiddleware" rel="nofollow">perfectly here</a>.</p>
<pre><code># File: settings.py
HOST_MIDDLEWARE_URLCONF_MAP = {
# Control Panel
"www.example.com": "webapp.sites.example.urls",
}
</code></pre>
<p>and</p>
<pre><code># File: multih... | 0 | 2016-10-15T21:59:21Z | [
"python",
"django",
"django-views"
] |
Function Calling Python basic | 40,045,851 | <p>I'm trying to enter values from the tuple <code>('a',1), ('b',2),('c',3)</code> into the function <code>dostuff</code> but i always get a return of <code>None</code> or <code>False</code>. i'm new to this to i'm sorry if this question is basic. I would appreciate any help.</p>
<p>I expect the result of this to be:<... | 0 | 2016-10-14T14:38:40Z | 40,045,962 | <p>You can use a list comprehension to do it in one line:</p>
<pre><code>char = 8
point_list = [('a', 1), ('b', 2),('c', 3)]
print("\n".join(["{}{}---{}".format(s, n, char) for s, n in point_list]))
</code></pre>
<p><code>"{}{}---{}".format(s, n, char)</code> creates a string by replacing <code>{}</code> by each one ... | -1 | 2016-10-14T14:43:41Z | [
"python"
] |
Function Calling Python basic | 40,045,851 | <p>I'm trying to enter values from the tuple <code>('a',1), ('b',2),('c',3)</code> into the function <code>dostuff</code> but i always get a return of <code>None</code> or <code>False</code>. i'm new to this to i'm sorry if this question is basic. I would appreciate any help.</p>
<p>I expect the result of this to be:<... | 0 | 2016-10-14T14:38:40Z | 40,046,009 | <p>I think you're misunderstanding the <code>return</code> value of the functions: unless otherwise specified, all functions will return <code>None</code> at completion. Your code:</p>
<pre><code>print(callit([('a',1), ('b',2),('c',3)],8))`
</code></pre>
<p>is telling the Python interpreter "print the return value o... | 4 | 2016-10-14T14:45:50Z | [
"python"
] |
Function Calling Python basic | 40,045,851 | <p>I'm trying to enter values from the tuple <code>('a',1), ('b',2),('c',3)</code> into the function <code>dostuff</code> but i always get a return of <code>None</code> or <code>False</code>. i'm new to this to i'm sorry if this question is basic. I would appreciate any help.</p>
<p>I expect the result of this to be:<... | 0 | 2016-10-14T14:38:40Z | 40,046,080 | <p>For a function to return a value in python it must have a <code>return</code> statement. In your <code>callit</code> function you lack a value to <code>return</code>. A more Pythonic approach would have both a value and iterate through the tuples using something like this:</p>
<pre><code>def callit(tups, char):
... | 0 | 2016-10-14T14:49:55Z | [
"python"
] |
Function Calling Python basic | 40,045,851 | <p>I'm trying to enter values from the tuple <code>('a',1), ('b',2),('c',3)</code> into the function <code>dostuff</code> but i always get a return of <code>None</code> or <code>False</code>. i'm new to this to i'm sorry if this question is basic. I would appreciate any help.</p>
<p>I expect the result of this to be:<... | 0 | 2016-10-14T14:38:40Z | 40,047,070 | <p>as @n1c9 said, every Python function must return some object, and if there's no <code>return</code> statement written in the function definition the function will <strong>implicitly</strong> return the <code>None</code> object. (implicitly meaning that under the hood, Python will see that there's no return statement... | 1 | 2016-10-14T15:38:20Z | [
"python"
] |
How to test printed value in Python 3.5 unittest? | 40,045,963 | <pre><code>from checker.checker import check_board_state, check_row, check_winner,\
check_column, check_diagonal
import sys
import unittest
class TestChecker(unittest.TestCase):
def test_winner_row(self):
check_board_state([['o', 'x', '.'],
['o', 'o', 'o'],
... | 0 | 2016-10-14T14:43:44Z | 40,046,524 | <pre><code>from checker import checker
from io import StringIO
import sys
import unittest
class TestChecker(unittest.TestCase):
def setUp(self):
# every test instance the class(setUp)
self.cls = checker()
old_stdout = sys.stdout
sys.stdout = mystdout = StringIO()
super(Test... | -1 | 2016-10-14T15:12:31Z | [
"python",
"pydev",
"python-unittest"
] |
Popen shell commands and problems with spaces | 40,045,986 | <p>I have this code, it runs whatever command the user enters for adb, e,g the user enters the word 'devices' and 'adb.exe devices' will run and print out the device list.
This works fine with 'devices' but whenever a more complex command is issued, such as one with spaces, 'shell pm path com.myapp.app' it fails.</p>
... | 0 | 2016-10-14T14:44:51Z | 40,046,567 | <p><code>subprocess.Popen</code> with <em>shell=True</em> takes the full command string, not a list.</p>
<pre><code>params = str(buildpath)+"\\adb.exe"+c_arg #c_arg is a string of arguments.
</code></pre>
| 0 | 2016-10-14T15:14:37Z | [
"android",
"python",
"shell",
"wx"
] |
How do I write a doctest in python 3.5 for a function using random to replace characters in a string? | 40,046,030 | <pre><code>def intoxication(text):
"""This function causes each character to have a 1/5 chance of being replaced by a random letter from the string of letters
INSERT DOCTEST HERE
"""
import random
string_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
text = "".join(i if random.... | 0 | 2016-10-14T14:47:06Z | 40,046,592 | <p>You need to mock the random functions to give something that is predetermined.</p>
<pre><code>def intoxication(text):
"""This function causes each character to have a 1/5 chance of being replaced by a random letter from the string of letters
If there is 0% chance of a random character chosen, result will b... | 0 | 2016-10-14T15:15:54Z | [
"python",
"python-3.x"
] |
How do I run pycharm within my docker container? | 40,046,167 | <p>I'm very new to docker. I want to build my python application within a docker container. As I build the application I want to be testing / running it in Pycharm and in the container I build. </p>
<p>How do I connect Pycharm pro to a specific container or image (either python or Anaconda)?</p>
<p>When I create a ... | 3 | 2016-10-14T14:53:59Z | 40,050,811 | <p>Docker-for-mac only supports connections over the /var/run/docker.sock socket that is listening on your OSX host.</p>
<p>If you try to add this to pycharm, you'll get the following message:</p>
<p><a href="https://i.stack.imgur.com/4x5i6.png" rel="nofollow"><img src="https://i.stack.imgur.com/4x5i6.png" alt="Only ... | 2 | 2016-10-14T19:37:05Z | [
"python",
"docker",
"anaconda"
] |
Python VBA-like left() | 40,046,168 | <p>I've been looking around but don't see anything similar to what I'm looking for. Within a django site I want to add some code that looks at a values furthest left (or the first) character in a variable (which is populated by a DB query), and if it's a particular letter or number, do something with said variable. H... | 0 | 2016-10-14T14:54:01Z | 40,046,294 | <p>This checks if the first letter in <code>mystring</code> is <code>'a'</code> or <code>'b'</code>.</p>
<pre><code>if mystring[0] in ('a', 'b'):
# whatever
</code></pre>
<p>Use slicing to test for longer substrings:</p>
<pre><code>if mystring[:3] in ('abc', 'def', '987'):
# whatever
</code></pre>
<p>Altern... | 1 | 2016-10-14T15:00:32Z | [
"python",
"django"
] |
Reorganizer Project in django-CMS | 40,046,185 | <p>Hi everyone I have a project works with this characteristic!</p>
<pre><code>Django==1.8.14
django-cms==3.2.5
Python 2.7.12
</code></pre>
<p>my project work fine, but now I am trying to reorganizer my apps</p>
<p>Right now I have something like this</p>
<p><a href="https://i.stack.imgur.com/dieS7.png" rel="nofoll... | 0 | 2016-10-14T14:55:11Z | 40,048,548 | <p>I'm not quite sure, but try it that way:</p>
<pre><code>'portal',`
'APIchart',
'drawChart',
...
</code></pre>
<p>That should work, if it doesn't fix the issue, let me know :)</p>
| 0 | 2016-10-14T17:09:11Z | [
"python",
"django"
] |
How to find the indices of a subset in a list? | 40,046,268 | <p>I have a list of values that I know are increasing, such as</p>
<pre><code>x = [1, 2, 3, 4, 5, 6]
</code></pre>
<p>I'm looking for the indices of the subset that are within some range <code>[min, max]</code>. E.g. I want</p>
<pre><code>>> subset_indices(x, 2, 4)
[1, 3]
>> subset_indices(x, 1.1, 7)
[1,... | 0 | 2016-10-14T14:59:11Z | 40,046,879 | <p>Following the recommendations from Kenny Ostrom and volcano, I implemented it simply as</p>
<pre><code>import bisect
def subset_indices(sequence, minv, maxv):
low = bisect.bisect_left(sequence, minv)
high = bisect.bisect_left(sequence, maxv, lo=low)
return [low, high]
</code></pre>
| 1 | 2016-10-14T15:29:32Z | [
"python",
"list",
"subset"
] |
Python : 2d contour plot with fixed x and y for 6 series of fractional data (z) | 40,046,295 | <p>I'm trying to use a contour plot to show an array of fractional data (between 0 and 1) at 6 heights (5, 10, 15, 20, 25, and 30) with a fixed x-axis (the "WN" series, 1 to 2300). y (height) is different for each series and discontinuous so I need to interpolate between heights. </p>
<pre><code>WN,5,10,15,20,25,30
1,... | 0 | 2016-10-14T15:00:34Z | 40,048,484 | <p>Using matplotlib, you need your X (row), Y (column), and Z values. The matplotlib function expects data in a certain format. Below, you'll see the meshgrid helps us get that format.</p>
<p>Here, I use pandas to import your data that I saved to a csv file. You can load your data any way you'd like though. The key is... | 0 | 2016-10-14T17:05:36Z | [
"python",
"python-2.7",
"pandas",
"matplotlib"
] |
Python C Extension: PyEval_GetLocals() returns NULL | 40,046,330 | <p>I need to read local variables from Python in C/C++. When I try to <code>PyEval_GetLocals</code>, I get a NULL. This happens although Python is initialized. The following is a minimal example.</p>
<pre><code>#include <iostream>
#include <Python.h>
Py_Initialize();
PyRun_SimpleString("a=5");
PyObject *l... | 1 | 2016-10-14T15:02:25Z | 40,048,193 | <p>Turns out the right way to access variables in the scope is:</p>
<pre><code>Py_Initialize();
PyObject *main = PyImport_AddModule("__main__");
PyObject *globals = PyModule_GetDict(main);
PyObject *a = PyDict_GetItemString(globals, "a");
std::cout<<globals<<std::endl; //Not NULL
Py_Finalize();
</code></pr... | 0 | 2016-10-14T16:45:39Z | [
"python",
"c++",
"c",
"python-c-extension",
"python-extensions"
] |
Keras + tensorflow gives the error "no attribute 'control_flow_ops'" | 40,046,619 | <p>I am trying to run keras for the first time. I installed the modules with:</p>
<pre><code>pip install keras --user
pip install tensorflow --user
</code></pre>
<p>and then tried to run <a href="https://github.com/fchollet/keras/blob/master/examples/mnist_cnn.py" rel="nofollow">https://github.com/fchollet/keras/blo... | 1 | 2016-10-14T15:17:03Z | 40,066,895 | <p>There is an issue between Keras and TF, Probably tf.python.control_flow_ops does not exist or not visible anymore.
using below import statements you can resolve this issue</p>
<p>import tensorflow as tf</p>
<p>tf.python.control_flow_ops = tf</p>
<p>For Details check:
<a href="https://github.com/fchollet/keras/is... | 2 | 2016-10-16T04:38:55Z | [
"python",
"ubuntu",
"machine-learning",
"tensorflow",
"keras"
] |
Updating Python version that's compiled from source | 40,046,656 | <p>I run a script on several CentOS machines that compiles Python 2.7.6 from source and installs it. I would now like to update the script so that it updates Python to 2.7.12, and don't really know how to tackle this.</p>
<p>Should I do this exactly the same way, just with source code of higher version, and it will ov... | 0 | 2016-10-14T15:18:52Z | 40,047,015 | <p>Replacing 2.7.6 with 2.7.12 would be fine using the procedure you linked.
There should be no real problems with libraries installed with pip easy_install as the version updates are minor. </p>
<p>Worst comes to worst and there is a library conflict it would be because the python library used for compiling may be di... | 1 | 2016-10-14T15:36:02Z | [
"python",
"python-2.7",
"centos"
] |
Why doesn't this work? Is this a apscheduler bug? | 40,046,700 | <p>When I run this it waits a minute then it prints 'Lights on' then waits two minutes and prints 'Lights off'. After that apscheduler seems to go nuts and quickly alternates between the two very fast. </p>
<p>Did i just stumble into a apscheduler bug or why does this happen?</p>
<pre><code>from datetime import da... | 1 | 2016-10-14T15:21:31Z | 40,046,852 | <p>You are flooding the scheduler with events. You are using the BackgroundScheduler, meaning that scheduler.start() is exiting and not waiting for the event to happen. The simplest fix may be to not use the BackgroundScheduler (use the BlockingScheduler), or put a sleep(180) on your loop.</p>
| 2 | 2016-10-14T15:28:28Z | [
"python"
] |
Why doesn't this work? Is this a apscheduler bug? | 40,046,700 | <p>When I run this it waits a minute then it prints 'Lights on' then waits two minutes and prints 'Lights off'. After that apscheduler seems to go nuts and quickly alternates between the two very fast. </p>
<p>Did i just stumble into a apscheduler bug or why does this happen?</p>
<pre><code>from datetime import da... | 1 | 2016-10-14T15:21:31Z | 40,049,123 | <p>Try this:</p>
<pre><code>from datetime import datetime, timedelta
from apscheduler.schedulers.background import BackgroundScheduler
import time
scheduler = BackgroundScheduler()
def turn_on():
print('Turn on', datetime.now())
def turn_off():
print('Turn off', datetime.now())
scheduler.start()
while... | 1 | 2016-10-14T17:45:27Z | [
"python"
] |
In OpenCV I've got a mask of an area of a frame. How would I then insert another image into that location on the original frame? | 40,046,741 | <p>I'm brand new to OpenCV and I can't seem to find a way to do this (It probably has to do with me not knowing any of the specific lingo).</p>
<p>I'm looping through the frames of a video and pulling out a mask from the video where it is green-screened using inRange. I'm looking for a way to then insert an image into... | 0 | 2016-10-14T15:23:26Z | 40,047,718 | <p>Use Bitwise operations for masking and related binary operations. Please check below code to see how Bitwise operations are done.</p>
<p><strong>Code</strong></p>
<pre><code>import numpy as np
import cv2
cap = cv2.VideoCapture('../video.mp4')
image = cv2.imread('photo.jpg')
# green digitally added not much vari... | 0 | 2016-10-14T16:15:01Z | [
"python",
"opencv",
"video"
] |
How to replace a dataframe column with a numpy array column in Python? | 40,046,793 | <p>Here's what i have so far:</p>
<pre><code>data.shape: # data == my dataframe
(768, 9)
data2 = pd.DataFrame(data) # copy of data
array = data.values # convert data to arrays
X = array[:,0:8]
Y = array[:,8]
# perform a transformation on X
Xrescaled = scaler.transform(X)
</code></pre>
<p>How can i replac... | 0 | 2016-10-14T15:25:43Z | 40,047,175 | <p>You can just do: <code>data2.iloc[:,:8] = Xrescaled</code>, here is a demo:</p>
<pre><code>import numpy as np
data = pd.DataFrame({'x': [1,2], 'y': [3,4], 'z': [5,6]})
data
# x y z
#0 1 3 5
#1 2 4 6
import pandas as pd
data2 = pd.DataFrame(data)
data2
# x y z
#0 1 3 5
#1 2 4 6 ... | 1 | 2016-10-14T15:44:09Z | [
"python",
"arrays",
"pandas",
"numpy",
"dataframe"
] |
AttributeError: 'filter' object has no attribute 'replace' in Python 3 | 40,046,864 | <p>I have some problems with python 3.x. In python 2.x. I could use <code>replace</code> attr in <code>filter</code> obj, but now I cannot use this. Here is a section of my code:</p>
<pre><code>def uniq(seq):
seen = {}
return [seen.setdefault(x, x) for x in seq if x not in seen]
def partition(seq, n):
ret... | -1 | 2016-10-14T15:28:57Z | 40,047,101 | <p>I think you can use a list comprehension:</p>
<pre><code>[c.replace(from_, to) for c in s.upper() if c.isupper()]
</code></pre>
<p>Is this what you want? There's a lot of code there so I might be missing something</p>
| 1 | 2016-10-14T15:40:42Z | [
"python",
"python-2.7",
"python-3.x",
"replace",
"filter"
] |
AttributeError: 'filter' object has no attribute 'replace' in Python 3 | 40,046,864 | <p>I have some problems with python 3.x. In python 2.x. I could use <code>replace</code> attr in <code>filter</code> obj, but now I cannot use this. Here is a section of my code:</p>
<pre><code>def uniq(seq):
seen = {}
return [seen.setdefault(x, x) for x in seq if x not in seen]
def partition(seq, n):
ret... | -1 | 2016-10-14T15:28:57Z | 40,047,148 | <p>in python 2, <code>filter</code> returns a string if a string is passed as input.</p>
<blockquote>
<p>filter(...)
filter(function or None, sequence) -> list, tuple, or string</p>
<p>Return those items of sequence for which function(item) is true. If
function is None, return the items that are true... | 0 | 2016-10-14T15:42:41Z | [
"python",
"python-2.7",
"python-3.x",
"replace",
"filter"
] |
Change date into fiscal month pandas python | 40,046,935 | <p>I am looking to change the date in my df into a fiscal month in a new column using python pandas.</p>
<p>This is an example</p>
<pre><code>17/01/2016 201601
18/01/2016 201602
</code></pre>
<p>Could you help me to get the required python code?</p>
| -1 | 2016-10-14T15:32:13Z | 40,048,038 | <p>You can do something like this:</p>
<pre><code>In [29]: df['fiscal_month'] = np.where(df.Date.dt.day < 18, df.Date, df.Date + pd.DateOffset(months=1))
In [30]: df
Out[30]:
Date new fiscal_month
0 2016-01-17 2016-01-17 2016-01-17
1 2016-01-18 2016-02-01 2016-02-18
In [31]: df.fiscal_month = d... | 1 | 2016-10-14T16:35:56Z | [
"python",
"pandas"
] |
What is the difference between installing python from the website and using brew? | 40,046,952 | <p>I have a Mac with OSX 10.11.6. I used brew to install python3. It installed python 3.5.2, but I need python 3.5.1. I've been googling, but can't figure out how I would install 3.5.1 via brew. So I went to python.org and downloaded the python-3.5.1-macosx10.6.pkg. I searched for how installing python this way would d... | 2 | 2016-10-14T15:33:10Z | 40,137,410 | <blockquote>
<p>it is possible to brew install python 3.5.1?</p>
</blockquote>
<p>Yes it is. See <a href="http://stackoverflow.com/a/4158763/735926">this StackOverflow answer</a>.</p>
<blockquote>
<p>If not, what will it mean to install 3.5.1 via .pkg file?</p>
</blockquote>
<p>The most noticeable change will be... | 0 | 2016-10-19T16:57:13Z | [
"python",
"osx",
"homebrew"
] |
Non-linear Least Squares Fitting (2-dimensional) in Python | 40,046,961 | <p>I was wondering what the correct approach to fitting datapoints to a non-linear function should be in python.</p>
<p>I am trying to fit a series of data-points</p>
<pre><code>t = [0., 0.5, 1., 1.5, ...., 4.]
y = [6.3, 4.5,.................]
</code></pre>
<p>using the following model function</p>
<pre><code>f(t, ... | 1 | 2016-10-14T15:33:29Z | 40,047,217 | <p><code>scipy.otimize.curve_fit</code> can be used to fit the data. I think you just don't use it properly. I assume you have a given <code>t</code> and <code>y</code> and try to fit a function of the form <code>x1*exp(x2*t) = y</code>.</p>
<p>You need</p>
<pre><code>ydata = f(xdata, *params) + eps
</code></pre>
<p... | 0 | 2016-10-14T15:46:32Z | [
"python",
"numpy",
"optimization",
"scipy",
"linear-algebra"
] |
Non-linear Least Squares Fitting (2-dimensional) in Python | 40,046,961 | <p>I was wondering what the correct approach to fitting datapoints to a non-linear function should be in python.</p>
<p>I am trying to fit a series of data-points</p>
<pre><code>t = [0., 0.5, 1., 1.5, ...., 4.]
y = [6.3, 4.5,.................]
</code></pre>
<p>using the following model function</p>
<pre><code>f(t, ... | 1 | 2016-10-14T15:33:29Z | 40,047,454 | <p>If you are using <code>curve_fit</code> you can simplify it quite a bit, with no need to compute the error inside your function:</p>
<pre><code>from scipy.optimize import curve_fit
import numpy as np
import matplotlib.pyplot as plt
t_data = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.])
y_data = np.array([6.8, 3., 1.5, 0... | 1 | 2016-10-14T15:59:07Z | [
"python",
"numpy",
"optimization",
"scipy",
"linear-algebra"
] |
Non-linear Least Squares Fitting (2-dimensional) in Python | 40,046,961 | <p>I was wondering what the correct approach to fitting datapoints to a non-linear function should be in python.</p>
<p>I am trying to fit a series of data-points</p>
<pre><code>t = [0., 0.5, 1., 1.5, ...., 4.]
y = [6.3, 4.5,.................]
</code></pre>
<p>using the following model function</p>
<pre><code>f(t, ... | 1 | 2016-10-14T15:33:29Z | 40,047,570 | <p>First, you are using the wrong function. Your function <code>func_nl_lsq</code> calculates the residual, it is not the model function. To use <code>scipy.otimize.curve_fit</code>, you have to define model function, as answers by @DerWeh and @saullo_castro suggest. You still can use custom residual function as you li... | 0 | 2016-10-14T16:05:58Z | [
"python",
"numpy",
"optimization",
"scipy",
"linear-algebra"
] |
What type of data that is separated by \ and is in hex? | 40,047,029 | <p>I have a data set that is pulled from a pixhawk. I am trying to parse this data and plot some of them vs time. The issue is when I use this code to open one of the bin files:</p>
<pre><code>with open("px4log.bin", "rb") as binary_file:
# Read the whole file at once
data = binary_file.read()
print(data)
... | 2 | 2016-10-14T15:36:44Z | 40,047,273 | <p>Python is showing you the binary data represented in <a href="https://en.wikipedia.org/wiki/Hexadecimal" rel="nofollow">hexadecimal</a> when the characters do not correspond with a regular <a href="https://en.wikipedia.org/wiki/ASCII" rel="nofollow">ascii</a> character. For example <code>\xa3</code> is a byte of hex... | 1 | 2016-10-14T15:49:23Z | [
"python"
] |
while loop works without condition | 40,047,062 | <p>As far as I know, while statement requires condition to work, but here it works without any; how's that possible? How does <code>while q:</code> work?</p>
<p>The code is below:
...</p>
<pre><code>q = set([])
for i in range(N):
q.add((i, 0))
q.add((i, M - 1))
w[i][0] = h[i][0]
w[i][M - 1] = h[i][M -... | 1 | 2016-10-14T15:38:09Z | 40,047,099 | <p>There is a condition.
The loop will iterate as long as there is an element in set q.</p>
<p>You would get a similar effect if you wrote:</p>
<pre><code>while len(q):
# do something
</code></pre>
<p>or even</p>
<pre><code>while len(q) > 0:
#do something
</code></pre>
<p>However, these expressions cou... | 1 | 2016-10-14T15:40:26Z | [
"python",
"while-loop",
"do-while"
] |
while loop works without condition | 40,047,062 | <p>As far as I know, while statement requires condition to work, but here it works without any; how's that possible? How does <code>while q:</code> work?</p>
<p>The code is below:
...</p>
<pre><code>q = set([])
for i in range(N):
q.add((i, 0))
q.add((i, M - 1))
w[i][0] = h[i][0]
w[i][M - 1] = h[i][M -... | 1 | 2016-10-14T15:38:09Z | 40,047,147 | <p>A <code>while</code> loop evaluates any expression it is given as a boolean. Pretty much everything in Python has a boolean value. Empty containers, such as <code>set()</code> generally evaluate to <code>False</code>, while non-empty containers, such as a set with at least one element, evaluate to <code>True</code>.... | 6 | 2016-10-14T15:42:41Z | [
"python",
"while-loop",
"do-while"
] |
Starting 2nd for loop based on first | 40,047,075 | <p>I'm trying to write a program that will calculate the future value of a tuition. Tuition today is $10000, with an increase of 5% each year. I am trying to write a program that tells me the cost of tuition in year 10, as well as total tuition for years 10-13 combined. </p>
<p>I am almost certain that I am on the rig... | 0 | 2016-10-14T15:38:49Z | 40,047,164 | <p>Try this one:</p>
<pre><code>def tuition():
tuition_cost=10000
increase=1.05
print('the cost for the year 10:', tuition_cost*(increase**10))
running_total = 0
for year in range(10):
running_total += tuition_cost*(increase**year)
print('the cost for 10 years:', running_total)
... | 0 | 2016-10-14T15:43:38Z | [
"python",
"for-loop",
"nested",
"nested-loops"
] |
Starting 2nd for loop based on first | 40,047,075 | <p>I'm trying to write a program that will calculate the future value of a tuition. Tuition today is $10000, with an increase of 5% each year. I am trying to write a program that tells me the cost of tuition in year 10, as well as total tuition for years 10-13 combined. </p>
<p>I am almost certain that I am on the rig... | 0 | 2016-10-14T15:38:49Z | 40,047,573 | <p>I think, your program should look like this:</p>
<pre><code>tuition_cost = 10000
increase = 1.05
running_total = 0
for year in range(0, 11):
price_for_year = tuition_cost*(increase**year)
print(price_for_year)
for year in range(10, 14):
running_total += price_for_year
price_for_year = tuition_cost... | 0 | 2016-10-14T16:06:15Z | [
"python",
"for-loop",
"nested",
"nested-loops"
] |
Pandas: Get corresponding column value in row based on unique value | 40,047,224 | <p>I've figured out how to get the information I want, but I would be surprised if there is not a better, more readable way to do so.</p>
<p>I want to get the value in a different column in the row that holds the data element I specify. For example, what is the value in 'b' that corresponds to the value of 10 in 'a'.<... | 1 | 2016-10-14T15:46:58Z | 40,047,354 | <p>You can use a boolean mask with <code>loc</code> to return all rows where the boolean condition is met, here we mask the df with the condition where 'a' == 11, and where this is met return all values for 'b':</p>
<pre><code>In [120]:
df = pd.DataFrame({'a':[10,11,11],'b':np.arange(3), 'c':np.random.randn(3)})
df
O... | 2 | 2016-10-14T15:53:18Z | [
"python",
"pandas"
] |
Classification of continious data | 40,047,228 | <p>I've got a Pandas df that I use for Machine Learning in Scikit for Python.
One of the columns is a target value which is continuous data (varying from -10 to +10).</p>
<p>From the target-column, I want to calculate a new column with 5 classes where the number of rows per class is the same, i.e. if I have 1000 rows ... | 0 | 2016-10-14T15:47:10Z | 40,048,581 | <pre><code>#create data
import numpy as np
import pandas as pd
df = pd.DataFrame(20*np.random.rand(50, 1)-10, columns=['target'])
#find quantiles
quantiles = df['target'].quantile([.2, .4, .6, .8])
#labeling of groups
df['group'] = 5
df['group'][df['target'] < quantiles[.8]] = 4
df['group'][df['target'] < qua... | 0 | 2016-10-14T17:11:36Z | [
"python",
"scikit-learn",
"percentile"
] |
Classification of continious data | 40,047,228 | <p>I've got a Pandas df that I use for Machine Learning in Scikit for Python.
One of the columns is a target value which is continuous data (varying from -10 to +10).</p>
<p>From the target-column, I want to calculate a new column with 5 classes where the number of rows per class is the same, i.e. if I have 1000 rows ... | 0 | 2016-10-14T15:47:10Z | 40,060,171 | <p>Cannot get this to work. </p>
<p>Anybody know how to do this in qcut instead? </p>
<p>I have tried the following:
df['5D'] = pd.qcut(df['target'], 5, labels=None, retbins=True, precision=3)
(5D is a new column with class 1-5 and target is a column in a dataframe.</p>
<p>I get the following error: ValueError: Len... | 0 | 2016-10-15T14:21:42Z | [
"python",
"scikit-learn",
"percentile"
] |
Reading csv from url and pushing it in DB through pandas | 40,047,291 | <p>The URL gives a csv formatted data. I am trying to get the data and push it in database. However, I am unable to read data as it only prints header of the file and not complete csv data. Could there be better option?</p>
<pre><code>#!/usr/bin/python3
import pandas as pd
data = pd.read_csv("some-url") //URL not pro... | 2 | 2016-10-14T15:50:20Z | 40,047,450 | <p>You can iterate through the results of <code>df.to_dict(orient="records")</code>:</p>
<pre><code>data = pd.read_csv("some-url")
for row in data.to_dict(orient="records"):
# For each loop, `row` will be filled with a key:value dict where each
# key takes the value of the column name.
# Use this dict to c... | 3 | 2016-10-14T15:58:58Z | [
"python",
"python-3.x",
"pandas",
"python-requests"
] |
Creating .csv based on values in dictionary | 40,047,315 | <p>I'm trying to parse an XML file, return the values and put it into a .csv file. I have the following code so far:</p>
<pre><code>for shift_i in shift_list :
# Iterates through all values in 'shift_list' for later comparison to ensure all tags are only counted once
for node in tree.xpath("//Data/Status[@Nam... | 1 | 2016-10-14T15:51:38Z | 40,047,551 | <p>I would use the DictWriter method of the csv package to write your csv file. For that you need to have a list of dictionaries. Each list item is a <code>shift</code> and is represented by a dictionary with keys <code>name</code> & <code>reason</code>. It should look like the following:</p>
<p><code>[{'Name1':va... | 1 | 2016-10-14T16:04:29Z | [
"python",
"csv",
"dictionary"
] |
Creating .csv based on values in dictionary | 40,047,315 | <p>I'm trying to parse an XML file, return the values and put it into a .csv file. I have the following code so far:</p>
<pre><code>for shift_i in shift_list :
# Iterates through all values in 'shift_list' for later comparison to ensure all tags are only counted once
for node in tree.xpath("//Data/Status[@Nam... | 1 | 2016-10-14T15:51:38Z | 40,053,849 | <p>I think the following may do what you want or at least be close. One important consideration that was ignored by the way you say the CSV file should be formatted, is the fact that each row must have a <code>Name-Reason</code> column for <em>every possible</em> combination of the two, even if weren't any of that part... | 1 | 2016-10-15T00:44:03Z | [
"python",
"csv",
"dictionary"
] |
SOAP/WSDL web services and Python nowadays | 40,047,359 | <p>First of all: Yes, I know that there are plenty of SOAP/WSDL/Python Questions. And no, none of the answers I found was really helpful (anymore).</p>
<p>Secondly: Yes, I wouldn't use SOAP/WSDL anymore if I wouldn't need to. Unfortunately there are still huge software companies only offering web service through this ... | 0 | 2016-10-14T15:53:38Z | 40,085,258 | <p>Check out: <a href="http://stackoverflow.com/questions/7817303/what-soap-libraries-exist-for-python-3-x">What SOAP libraries exist for Python 3.x?</a></p>
<p>I've used suds before and it feels good. It does seem pysimplesoap is more maintained though - I've only used pysimplesoap server side, not for consuming (e. ... | 0 | 2016-10-17T11:31:01Z | [
"python",
"soap",
"wsdl",
"soap-client"
] |
How to compile missing extensions modules when cross compiling Python 3.5.2 for ARM on Linux | 40,047,363 | <p>When cross compiling Python for ARM many of the extension modules are not build. How do I build the missing extension modules, mainly math, select, sockets, while cross compiling Python 3.5.2 for ARM on Linux? However, when compiling for the native platform the extension modules are properly build.</p>
<p>These we... | 1 | 2016-10-14T15:53:58Z | 40,066,854 | <h2>Root Cause ( Courtesy: Xavier de Gaye)</h2>
<blockquote>
<p>There was already a native python3.5 (from the Ubuntu repository) is the PATH. So the problem is that setup.py in build_extensions() does not build the extensions that have been already built statically into this native Ubuntu interpreter.
<a href="ht... | 1 | 2016-10-16T04:32:40Z | [
"python",
"python-3.x",
"arm",
"cross-compiling",
"embedded-linux"
] |
Trying to make a function that copies the content of one file and writes it to another | 40,047,414 | <p>I have a question that states
<strong>Write a function fcopy() that takes as input two file names (as strings) and copies the content of the first file into the second.</strong>
and I want to know how to go about solving this.</p>
<p>My first file is named example, and the second file is named output, both text fil... | -4 | 2016-10-14T15:56:44Z | 40,047,638 | <p>You are not to ask StackOverflow to do your homework for you. Feeling generous though...</p>
<p>First of all, read this: <a href="https://docs.python.org/3.3/library/shutil.html" rel="nofollow">https://docs.python.org/3.3/library/shutil.html</a> It's the Python 3 docs for the shutil module. It will give high-level ... | 3 | 2016-10-14T16:10:03Z | [
"python",
"python-3.x"
] |
Trying to make a function that copies the content of one file and writes it to another | 40,047,414 | <p>I have a question that states
<strong>Write a function fcopy() that takes as input two file names (as strings) and copies the content of the first file into the second.</strong>
and I want to know how to go about solving this.</p>
<p>My first file is named example, and the second file is named output, both text fil... | -4 | 2016-10-14T15:56:44Z | 40,047,773 | <p>If you really need to, you could write a simple wrapper function to accomplish this:</p>
<pre><code>def copy_file(orig_file_name, copy_file_name):
with open(orig_file_name, 'r') as orig_file, open(copy_file_name, 'w+') as cpy_file:
orig_file = orig_file.read()
cpy_file.write(orig_file)
</code></... | 1 | 2016-10-14T16:18:39Z | [
"python",
"python-3.x"
] |
SQLAlchemy: What is the difference beetween CheckConstraint and @validates | 40,047,417 | <p>In a SQLAlchemy model what is the difference between adding a CheckConstraint and adding a @validates decorated validation method? Is the one acting on the database level and the other one not? And are there any guidelines when to use which?</p>
<p>Specifically, what is the difference between using</p>
<pre><code>... | 0 | 2016-10-14T15:56:57Z | 40,049,763 | <p><code>CheckConstraint</code> is a database-level check; <code>@validates</code> is a Python-level check. A database-level check is more universal; the constraint is satisfied even if you access the database through other means. A Python-level check is more expressive; you can usually check for complicated constraint... | 1 | 2016-10-14T18:23:26Z | [
"python",
"sqlalchemy"
] |
Determine if an entity is created 'today' | 40,047,495 | <p>I am creating an app which, on any given day, only one entity can be created per day. Here is the model:</p>
<pre><code>class MyModel(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
</code></pre>
<p>Since only one entity is allowed to be created per day, we will need to compare the MyModel.create... | 0 | 2016-10-14T16:01:18Z | 40,047,657 | <p>You are comparing a <code>DateTime</code> object with a <code>Date</code> object.</p>
<p>Instead of </p>
<pre><code>my_model = MyModel.query(MyModel.created == today).get()
</code></pre>
<p>use</p>
<pre><code>my_model = MyModel.query(MyModel.created.date() == today).get()
</code></pre>
| 0 | 2016-10-14T16:11:06Z | [
"python",
"google-app-engine",
"datetime",
"google-cloud-datastore",
"app-engine-ndb"
] |
Determine if an entity is created 'today' | 40,047,495 | <p>I am creating an app which, on any given day, only one entity can be created per day. Here is the model:</p>
<pre><code>class MyModel(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
</code></pre>
<p>Since only one entity is allowed to be created per day, we will need to compare the MyModel.create... | 0 | 2016-10-14T16:01:18Z | 40,047,817 | <p>Seems like the only one solution is to use a "range" query, here's a relevant answer <a href="http://stackoverflow.com/a/14963648/762270">http://stackoverflow.com/a/14963648/762270</a></p>
| 0 | 2016-10-14T16:21:26Z | [
"python",
"google-app-engine",
"datetime",
"google-cloud-datastore",
"app-engine-ndb"
] |
Determine if an entity is created 'today' | 40,047,495 | <p>I am creating an app which, on any given day, only one entity can be created per day. Here is the model:</p>
<pre><code>class MyModel(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
</code></pre>
<p>Since only one entity is allowed to be created per day, we will need to compare the MyModel.create... | 0 | 2016-10-14T16:01:18Z | 40,048,207 | <p>You can't query by <code>created</code> property using <code>==</code> since you don't actually know the <strong>exact</strong> creation datetime (which is what you'll find in <code>created</code> due to the <code>auto_now_add=True</code> option)</p>
<p>But you could query for the most recently created entity and c... | 0 | 2016-10-14T16:46:27Z | [
"python",
"google-app-engine",
"datetime",
"google-cloud-datastore",
"app-engine-ndb"
] |
Determine if an entity is created 'today' | 40,047,495 | <p>I am creating an app which, on any given day, only one entity can be created per day. Here is the model:</p>
<pre><code>class MyModel(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
</code></pre>
<p>Since only one entity is allowed to be created per day, we will need to compare the MyModel.create... | 0 | 2016-10-14T16:01:18Z | 40,054,913 | <p>Using a range query for a single specific known value you want to lookup is overkill and expensive, I would use one of these 2 solutions:</p>
<p><strong>1 - Extra Property</strong></p>
<p>Sacrifice a little space with an extra property, though since it's one per day, it shouldn't be a big deal.</p>
<pre class="la... | 0 | 2016-10-15T04:20:45Z | [
"python",
"google-app-engine",
"datetime",
"google-cloud-datastore",
"app-engine-ndb"
] |
Determine if an entity is created 'today' | 40,047,495 | <p>I am creating an app which, on any given day, only one entity can be created per day. Here is the model:</p>
<pre><code>class MyModel(ndb.Model):
created = ndb.DateTimeProperty(auto_now_add=True)
</code></pre>
<p>Since only one entity is allowed to be created per day, we will need to compare the MyModel.create... | 0 | 2016-10-14T16:01:18Z | 40,058,428 | <p>I ended up changing the property from <code>DateTimeProperty</code> to <code>DateProperty</code>. Now I am able to do this:</p>
<pre><code>today_date = datetime.datetime.today().date()
today_entity = MyModel.query(MyModel.created == today_date).get()
</code></pre>
| 1 | 2016-10-15T11:26:07Z | [
"python",
"google-app-engine",
"datetime",
"google-cloud-datastore",
"app-engine-ndb"
] |
Sqlite3 INSERT query ERROR? | 40,047,742 | <p>i want to insert in my DB 2 strings var </p>
<p>one entered from the user ==> H and </p>
<p>one generated form the chatbot==> B</p>
<p>Here is the code:</p>
<pre><code># initialize the connection to the database
sqlite_file = '/Users/emansaad/Desktop/chatbot1/brain.sqlite'
connection = sqlite3.connect(sqlite_fil... | 2 | 2016-10-14T16:16:27Z | 40,047,765 | <p>Always remember to commit the changes that you make. In this case: <code>connection.commit()</code>. Except it looks like you overrode your <code>connection</code> variable.</p>
| 1 | 2016-10-14T16:18:01Z | [
"python",
"mysql",
"python-3.x"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.