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 |
|---|---|---|---|---|---|---|---|---|---|
Extracting specific information from data | 39,928,277 | <p>How can i convert a data format like: </p>
<pre><code>James Smith was born on November 17, 1948
</code></pre>
<p>into something like </p>
<pre><code>("James Smith", DOB, "November 17, 1948")
</code></pre>
<p>without having to rely on positional index of strings</p>
<p>I have tried the following </p>
<pre><code... | 2 | 2016-10-08T03:06:32Z | 39,928,842 | <p>Split the string with 'was born on' after that trim the spaces and assign to name and dob</p>
| 2 | 2016-10-08T05:00:18Z | [
"python",
"python-3.x",
"nltk",
"stanford-nlp",
"information-retrieval"
] |
Extracting specific information from data | 39,928,277 | <p>How can i convert a data format like: </p>
<pre><code>James Smith was born on November 17, 1948
</code></pre>
<p>into something like </p>
<pre><code>("James Smith", DOB, "November 17, 1948")
</code></pre>
<p>without having to rely on positional index of strings</p>
<p>I have tried the following </p>
<pre><code... | 2 | 2016-10-08T03:06:32Z | 39,930,029 | <p>You could always use a regular expressions.
The regex <code>(\S+)\s(\S+)\s\bwas born on\b\s(\S+)\s(\S+),\s(\S+)</code> will match and return data from specifically the string format above.</p>
<p>Here's it in action: <a href="https://regex101.com/r/W2ykKS/1" rel="nofollow">https://regex101.com/r/W2ykKS/1</a></p>
<... | 1 | 2016-10-08T07:50:26Z | [
"python",
"python-3.x",
"nltk",
"stanford-nlp",
"information-retrieval"
] |
printing HTML and inserting variables using python-flask | 39,928,289 | <p>Im trying to print html code that will also include variables, in this case its data from database with this code:</p>
<pre><code>def displayHot():
myCursor = mongo.db.posts.find()
for result_object in myCursor:
print'''
Content-Type: text/html
<div class="card-header">
<h... | 0 | 2016-10-08T03:08:00Z | 39,929,939 | <p>It looks like you would be better served by doing your looping in a jinja template, and just sending the template the data for the loop. Something like this is what I'm thinking:</p>
<h3>Python code</h3>
<pre><code>@app.route('/', methods=['POST','GET'])
def home():
if request.method == 'GET':
myCurso... | 0 | 2016-10-08T07:37:11Z | [
"python",
"html",
"flask",
"pymongo"
] |
How to subtract a constant from members of a sublist? | 39,928,297 | <p>I know I can subtract a constant from all members of a simple list like this:</p>
<pre><code>l = [ 123, 124, 125, 126 ]
l = [v - 100 for v in l]
</code></pre>
<p>But how can I subtract a constant from one or more specific members of each sublist within a list?</p>
<p>Suppose I have:</p>
<pre><code>l = [ [101, 10... | 0 | 2016-10-08T03:10:49Z | 39,928,335 | <p>In a simplest form, you can unpack the sublists and apply the operation to the desired items:</p>
<pre><code>In [1]: l = [ [101, 2, 3], [111, 22, 33], [222, 233, 344] ]
In [2]: [[x, y - 100, z - 100] for x, y, z in l]
Out[2]: [[101, -98, -97], [111, -78, -67], [222, 133, 244]]
</code></pre>
<p>Or, a bit more scal... | 1 | 2016-10-08T03:19:10Z | [
"python",
"list-comprehension"
] |
How to subtract a constant from members of a sublist? | 39,928,297 | <p>I know I can subtract a constant from all members of a simple list like this:</p>
<pre><code>l = [ 123, 124, 125, 126 ]
l = [v - 100 for v in l]
</code></pre>
<p>But how can I subtract a constant from one or more specific members of each sublist within a list?</p>
<p>Suppose I have:</p>
<pre><code>l = [ [101, 10... | 0 | 2016-10-08T03:10:49Z | 39,928,365 | <p>If you really want a one-liner, try:</p>
<pre><code>l = map(lambda x : x[0:1]+map(lambda y: y-100, x[1:3])+x[3:], l)
</code></pre>
<p>Python has some nice syntax for very simple things, but for something like this you're best off using functionals or loops.</p>
| 0 | 2016-10-08T03:24:39Z | [
"python",
"list-comprehension"
] |
How to subtract a constant from members of a sublist? | 39,928,297 | <p>I know I can subtract a constant from all members of a simple list like this:</p>
<pre><code>l = [ 123, 124, 125, 126 ]
l = [v - 100 for v in l]
</code></pre>
<p>But how can I subtract a constant from one or more specific members of each sublist within a list?</p>
<p>Suppose I have:</p>
<pre><code>l = [ [101, 10... | 0 | 2016-10-08T03:10:49Z | 39,928,382 | <pre><code>map(lambda x:map(lambda y: y if x.index(y)==0 else y-100,x),l)
</code></pre>
| 0 | 2016-10-08T03:28:21Z | [
"python",
"list-comprehension"
] |
python error TypeError: not all arguments converted during string formatting | 39,928,298 | <p>Been starring at this too long and I think I missed something dumb..
Writing a script to write information to a file. All the variables are strings being passed in from another function to write a file.</p>
<p>Here's my code: </p>
<pre><code> 53 def makeMainTF():
54 NameTag,mcGroupTag,mcIPTag = makeNameMC... | 1 | 2016-10-08T03:10:55Z | 39,928,369 | <p>Replace line 78 with the following and try - </p>
<pre><code>'Owner = \"%s\"' % " ".join(yourName),
</code></pre>
<p>Effectively, yourname seems to be a tuple.<br>
The above code will convert it to a string value.</p>
<p>EDIT :- (Answer to the OP's last comment) </p>
<p>Look at line 10 of <code>getAccessSecre... | 1 | 2016-10-08T03:25:35Z | [
"python"
] |
How can I add some strings to a list that already exists in Python? | 39,928,316 | <pre><code>list1 = ['1', '2', '3', '4']
input_list = ['5', '6']
</code></pre>
<p>the out put I want is</p>
<pre><code>print(list1)
>> ['1','2','3','4','5']
>> ['1','2','3','4','6']
</code></pre>
<p>I tried many other things, but I couldn't get the result I want..
I also searched other Q&As to find th... | -3 | 2016-10-08T03:15:49Z | 39,928,360 | <p>Use extend to add a list to another list, append to add a element to a list.</p>
<pre><code>list1.extend(input_list)
list1.append('5')
list1.append('6')
</code></pre>
| 1 | 2016-10-08T03:23:41Z | [
"python",
"arrays",
"list"
] |
How can I add some strings to a list that already exists in Python? | 39,928,316 | <pre><code>list1 = ['1', '2', '3', '4']
input_list = ['5', '6']
</code></pre>
<p>the out put I want is</p>
<pre><code>print(list1)
>> ['1','2','3','4','5']
>> ['1','2','3','4','6']
</code></pre>
<p>I tried many other things, but I couldn't get the result I want..
I also searched other Q&As to find th... | -3 | 2016-10-08T03:15:49Z | 39,928,373 | <p>You can just concatenate two lists by adding them <code>[1,2]+[3]</code> will result in <code>[1,2,3]</code> you can use the extend or append methods as well </p>
| 1 | 2016-10-08T03:26:38Z | [
"python",
"arrays",
"list"
] |
How can I add some strings to a list that already exists in Python? | 39,928,316 | <pre><code>list1 = ['1', '2', '3', '4']
input_list = ['5', '6']
</code></pre>
<p>the out put I want is</p>
<pre><code>print(list1)
>> ['1','2','3','4','5']
>> ['1','2','3','4','6']
</code></pre>
<p>I tried many other things, but I couldn't get the result I want..
I also searched other Q&As to find th... | -3 | 2016-10-08T03:15:49Z | 39,928,510 | <p>How about this</p>
<pre><code>import copy
list1 = ['1', '2', '3', '4']
input_list = ['5', '6']
output = []
for e in input_list:
l = copy.copy(list1)
l.append(e)
output.append(l)
print(output)
</code></pre>
<p>Result</p>
<pre><code>[['1', '2', '3', '4', '5'], ['1', '2', '3', '4', '6']]
</code></pre>... | 1 | 2016-10-08T03:54:49Z | [
"python",
"arrays",
"list"
] |
How can I add some strings to a list that already exists in Python? | 39,928,316 | <pre><code>list1 = ['1', '2', '3', '4']
input_list = ['5', '6']
</code></pre>
<p>the out put I want is</p>
<pre><code>print(list1)
>> ['1','2','3','4','5']
>> ['1','2','3','4','6']
</code></pre>
<p>I tried many other things, but I couldn't get the result I want..
I also searched other Q&As to find th... | -3 | 2016-10-08T03:15:49Z | 39,928,662 | <p>As an alternitive to @Kenji's soultion, you could use a simple one-liner:</p>
<pre><code>res = [list1+[i] for i in input_list]
</code></pre>
<p>Full program:</p>
<pre><code>list1 = ['1', '2', '3', '4']
input_list = ['5', '6']
res = [list1+[i] for i in input_list]
print(res) # prints: [['1', '2', '3', '4', '5'], ... | 1 | 2016-10-08T04:25:08Z | [
"python",
"arrays",
"list"
] |
TkInter: Can't fill a Frame with another widget | 39,928,343 | <p>First time with TkInter. According to what I've read, you can use Frame widgets to hold other widgets. So, I laid down some preview Frames as such:</p>
<pre><code>import tkinter as tk
root = tk.Tk()
TextFrame = tk.Frame(root, width=200, height=600, bg="red")
TextFrame.pack(side="left")
ListFrame = tk.Frame(root... | 0 | 2016-10-08T03:21:23Z | 39,929,031 | <p>Frames are like elastics, they grip their content.
You could add:</p>
<pre><code>ListFrame.pack_propagate(False)
</code></pre>
<p>to switch off that behavior</p>
| 0 | 2016-10-08T05:31:48Z | [
"python",
"tkinter"
] |
TkInter: Can't fill a Frame with another widget | 39,928,343 | <p>First time with TkInter. According to what I've read, you can use Frame widgets to hold other widgets. So, I laid down some preview Frames as such:</p>
<pre><code>import tkinter as tk
root = tk.Tk()
TextFrame = tk.Frame(root, width=200, height=600, bg="red")
TextFrame.pack(side="left")
ListFrame = tk.Frame(root... | 0 | 2016-10-08T03:21:23Z | 39,932,656 | <p>It's impossible to say what the right answer is since your question doesn't explain exactly the look and behavior that you're wanting to achieve.</p>
<p>By default, widgets shrink or expand to fit their contents. 99.9% of the time this is exactly the right thing, and lets to UIs that are very responsive to the chan... | 0 | 2016-10-08T12:59:17Z | [
"python",
"tkinter"
] |
Python member variable as parameter | 39,928,345 | <p>I have a class A with a member function a. I have a parameter p with default value. I want this default value to be the member variable of the class.</p>
<pre><code>class A:
def a(self, p = self.b):
print p
</code></pre>
<p>However it crashed with the information:</p>
<pre><code><ipython-input-2-a063... | 1 | 2016-10-08T03:21:27Z | 39,928,371 | <p>One option would be to set the default <code>p</code> value as <code>None</code> and check its value in the method itself:</p>
<pre><code>class A:
def __init__(self, b):
self.b = b
def a(self, p=None):
if p is None:
p = self.b
print(p)
</code></pre>
<p>Demo:</p>
<pre><... | 3 | 2016-10-08T03:25:50Z | [
"python",
"function",
"class",
"variables",
"default-value"
] |
sqlalchemy JSON query rows without a specific key (Key existence) | 39,928,463 | <p>When using sqlalchemy with postgresql, I have the following table and data:</p>
<pre><code> id | data
----+----------
1 | {}
2 | {"a": 1}
(2 rows)
</code></pre>
<p>How do I find row(s) that does not have a key. e.g. "a" or data["a"]?</p>
<pre><code>Give me all objects that does not have the key a.
id | ... | 0 | 2016-10-08T03:47:06Z | 39,933,596 | <p>If the column type is <code>jsonb</code> you can use <a href="http://docs.sqlalchemy.org/en/latest/dialects/postgresql.html#sqlalchemy.dialects.postgresql.JSONB" rel="nofollow"><code>has_key</code></a>:</p>
<pre><code>session.query(Json_test).filter(sqlalchemy.not_(Json_test.data.has_key('a')))
</code></pre>
<p>Fo... | 0 | 2016-10-08T14:32:02Z | [
"python",
"postgresql",
"sqlalchemy"
] |
How to enable drag selection in UI Maya Python | 39,928,511 | <p>I would like to know how to enable drag selection to select some buttons on my UI.</p>
<p>I have tried to use <code>cmds.selectPref(clickBoxSize=True)</code> but it doesn't work.</p>
| 2 | 2016-10-08T03:55:13Z | 39,959,650 | <pre><code>import maya.cmds as cmds
import shiboken
import maya.OpenMayaUI as omUI
from PySide import QtGui, QtCore
ui_btns = {}
win = cmds.window()
cmds.columnLayout(adjustableColumn=True)
ui_btns["btn_a"] = cmds.button(label="Burning")
ui_btns["btn_b"] = cmds.button(label="Man")
cmds.setParent("..")
cmds.showWindow(... | 0 | 2016-10-10T13:38:37Z | [
"python",
"maya"
] |
Python, error with web driver (Selenium) | 39,928,515 | <pre><code> import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
prin... | 0 | 2016-10-08T03:56:02Z | 39,929,034 | <p>Either you provide the ChromeDriver path in webdriver.Chrome or provide the path variable</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driverLocation = 'D:\Drivers\chromedriver.exe' #if windows
driver =... | 1 | 2016-10-08T05:32:09Z | [
"python",
"selenium"
] |
Random numbers do not change, repeats twice | 39,928,521 | <pre><code>import random
def main():
counter = StudentNames()
StudentName = StudentNames()
AverageRight = 0.0
Right = 0.0
numberone = Numbers(counter)
numbertwo = NumbersTwo(counter)
numberone = Equation(numberone, numbertwo)
numbertwo = Equation(numberone, numbertwo)
anwser = 0... | -2 | 2016-10-08T03:57:49Z | 39,928,581 | <p>Try this ... You can only return one value from a function but you can return a "tuple" (a sequence of objects), and pick it up in main the same way:</p>
<pre><code>def main():
counter, StudentName = StudentNames()
def StudentNames():
... ... ...
return counter, StudentName
</code></pre>
<p>For the ra... | 0 | 2016-10-08T04:09:16Z | [
"python",
"loops",
"random"
] |
Running py.test under pypy | 39,928,605 | <p>How do I run pytest using pypy? Travis does it, so it must be possible. This is related to similar <a href="http://stackoverflow.com/questions/39928317/running-py-test-on-micropython">question</a> how to run pytest using Micropython.</p>
<pre><code>arkadiusz@pc:~/Dokumenty/GitHub/construct$ pypy -m pytest
/usr/bin/... | 0 | 2016-10-08T04:12:29Z | 39,943,906 | <p>Problem was fixed by installing pip on pypy as in</p>
<p><a href="http://askubuntu.com/questions/834466/installing-pytest-for-pypy">http://askubuntu.com/questions/834466/installing-pytest-for-pypy</a></p>
<p>Then it is just</p>
<pre><code>pypy -m pytest
</code></pre>
| 0 | 2016-10-09T12:59:59Z | [
"python",
"unit-testing",
"py.test",
"pypy"
] |
ImportError: No module named ImageFont | 39,928,682 | <p>I'm using the chemlab library for the first time. I'm trying to run some of the example programs but I keep getting the following error message:</p>
<blockquote>
<p>import ImageFont # From PIL</p>
<p>ImportError: No module named ImageFont</p>
</blockquote>
<p>Here is the code to one of the basic examples (... | 1 | 2016-10-08T04:28:27Z | 39,930,411 | <p>Install <code>PIL</code>:</p>
<pre><code>pip install pillow
</code></pre>
<p>Correct import for <code>ImageFont</code> is:</p>
<pre><code>from PIL import ImageFont
</code></pre>
<p>Here is an example of <code>ImageFont</code>:</p>
<pre><code>from PIL import ImageFont, ImageDraw
draw = ImageDraw.Draw(image)
# ... | 1 | 2016-10-08T08:38:38Z | [
"python",
"importerror"
] |
Unable to parse through sqlite query using regular expressions | 39,928,690 | <p>I am trying to figure out a way to iterate through a database and match all rows that have 02 in them using regular expressions. When a match is made the count should reset to 0 and when there is not a match the count should accumulate by negative 1. The code works when I use a list. </p>
<pre><code>import sqlite3
... | 2 | 2016-10-08T04:30:03Z | 39,928,725 | <p>You probably want to use <a href="https://docs.python.org/3/library/re.html#re.search" rel="nofollow"><code>r.search()</code></a> to execute a regular expression search:</p>
<pre><code>for i in rez:
if r.search(i[0]):
count = 0
else:
count -= 1
</code></pre>
<p>Note the use of <code>i[0]</c... | 0 | 2016-10-08T04:37:49Z | [
"python",
"regex",
"sqlite3"
] |
why no tkinter distribution found | 39,928,710 | <p>while installing tkinter i am having problem ,i have version 2.7.11. i have entered the <code>pip install tkinter</code> on dos but it shows the following message : </p>
<blockquote>
<p>collecting tkinter </p>
<p>Could not find a version that satisfies the requirement tkinter (from versions: )
No matching ... | 1 | 2016-10-08T04:33:43Z | 39,929,501 | <p>The Tkinter library comes in default with every Python installation</p>
<p>Try this:</p>
<pre><code>import Tkinter as tk
</code></pre>
| 0 | 2016-10-08T06:40:21Z | [
"python",
"tkinter",
"module"
] |
How to delete Flask HTTP Sessions from the Database on session.clear() | 39,928,716 | <p>I implemented a server side Session in Flask with SQLAlchemy based on this <a href="http://flask.pocoo.org/snippets/110/" rel="nofollow">snippit</a>:</p>
<pre><code>class SqlAlchemySession(CallbackDict, SessionMixing):
...
class SqlAlchemySessionInterface(SessionInterface):
def __init__(self, db):
... | 3 | 2016-10-08T04:35:46Z | 39,930,787 | <p>If you want to remove duplication, you can define a function called <code>logout_user</code></p>
<p>In that function, you can remove the session record from your database as well as <code>session.clear()</code>.</p>
<p>Call this function when <code>\logout</code> or wherever suitable.</p>
| 0 | 2016-10-08T09:28:13Z | [
"python",
"flask"
] |
How to compare two rows of two pandas series? | 39,928,738 | <p>I have two python pandas series <code>df10</code> and <code>df5</code>. I want to compare their values.For example: <code>df10[-1:]< df5[-1:]</code> ,it returns true. <code>df10[-2:-1] > df5[-2:-1]</code> , it returns false.</p>
<p>But if I combine them together, <code>df10[-1:]< df5[-1:] and df10[-2:-1]&g... | 0 | 2016-10-08T04:39:42Z | 39,928,859 | <p>You can do this with the pandas Series <code>values</code> attribute:</p>
<pre><code>if (df10.values[-2:-1] > df5.values[-2:-1]) and\
(df10.values[-1:] < df5.values[-1:]):
print("we met the conditions!")
</code></pre>
| -2 | 2016-10-08T05:03:25Z | [
"python",
"pandas"
] |
How to compare two rows of two pandas series? | 39,928,738 | <p>I have two python pandas series <code>df10</code> and <code>df5</code>. I want to compare their values.For example: <code>df10[-1:]< df5[-1:]</code> ,it returns true. <code>df10[-2:-1] > df5[-2:-1]</code> , it returns false.</p>
<p>But if I combine them together, <code>df10[-1:]< df5[-1:] and df10[-2:-1]&g... | 0 | 2016-10-08T04:39:42Z | 39,929,677 | <p>Consider you have the two dataframes from this program:</p>
<pre><code># Python 3.5.2
import pandas as pd
import numpy as np
# column names for example dataframe
cats = ['A', 'B', 'C', 'D', 'E']
df5 = pd.DataFrame(data = np.arange(25).reshape(5, 5), columns=cats)
print("Dataframe 5\n",df5,"\n")
df10=pd.DataFram... | 1 | 2016-10-08T07:02:39Z | [
"python",
"pandas"
] |
Cofusing about lookup node with binary tree | 39,928,780 | <p>I build a binary tree with python code, now I could print it in order with <code>testTree.printInorder(testTree.root)</code>. I have tried to lookup some node ,and the function <code>findNode</code> doesn't work anymore . <code>print testTree.findNode(testTree.root,20)</code> whatever I put in just return None.</p>
... | 1 | 2016-10-08T04:48:52Z | 39,928,818 | <p>When you recurse to children in <code>findNode</code> you need to return the result, otherwise the function will implicitly return <code>None</code>:</p>
<pre><code>def findNode(self,node,value):
if self.root != None:
if value == node.data:
return node.data
elif value < node.data ... | 2 | 2016-10-08T04:57:08Z | [
"python",
"binary-search-tree"
] |
Cofusing about lookup node with binary tree | 39,928,780 | <p>I build a binary tree with python code, now I could print it in order with <code>testTree.printInorder(testTree.root)</code>. I have tried to lookup some node ,and the function <code>findNode</code> doesn't work anymore . <code>print testTree.findNode(testTree.root,20)</code> whatever I put in just return None.</p>
... | 1 | 2016-10-08T04:48:52Z | 39,928,903 | <p>Any function without an explicit return will return None. </p>
<p>You have not returned the recursive calls within <code>findNode</code>. So, here. </p>
<pre><code>if value == node.data:
return node.data
elif value < node.data and node.left != None:
return self.findNode(node.left,value)
elif value >... | 2 | 2016-10-08T05:10:13Z | [
"python",
"binary-search-tree"
] |
The field was declared on serializer , but has not been included error in django rest | 39,928,879 | <p>I created few serializers in my django REST API and stuck with weird problem. When i go to the <code>http://127.0.0.1:8000/api/register/</code> url i'm gets the error:</p>
<blockquote>
<p>Environment:</p>
<p>Request Method: GET Request URL: <a href="http://localhost:8000/api/users/" rel="nofollow">http://loc... | 0 | 2016-10-08T05:06:13Z | 40,026,977 | <p>Finally i found source of my stupid error. Reason was that earlier i had photo field in my model. But after making changes in model i forget to make migrations.</p>
| 0 | 2016-10-13T17:03:05Z | [
"python",
"django",
"django-rest-framework"
] |
When using PyMongo, No handlers could be found for logger "apscheduler.scheduler" | 39,928,970 | <p>The code works fine printing to screen <code>hello</code> every second. This is done using the <code>bar</code> method, which is added to the scheduler as a job.</p>
<p><strong>Problem:</strong> However when the line <code>self.db.animals.insert_one({'name': 'lion'})</code> is added to the <code>bar</code> method, ... | 0 | 2016-10-08T05:21:37Z | 39,941,587 | <p>That's not an error, but a warning. Python's logging system is trying to tell you that it has no outlet for logging output because you haven't configured it. Try using <code>logging.basicConfig(level=logging.DEBUG)</code>.</p>
| 0 | 2016-10-09T08:33:45Z | [
"python",
"python-2.7",
"pymongo",
"apscheduler"
] |
Build a dictionary using select values from a different dictionary | 39,929,007 | <p>I have a dictionary with years as keys and other dictionaries as values (these inner dictionaries contain tuples (i, i+1) as keys). An example of the format would be:</p>
<pre><code>myDict = {2000: {(0,1):111.1, (1,2):222.2, (2,3):333.3, (3,4):444.4}
2001: {(0,1):11.1, (1,2):22.2, (2,3):33.3, (3,4):44.4}}... | 1 | 2016-10-08T05:27:48Z | 39,929,711 | <p>Here's a dict comprehension that performs the action you specify at the start of your question, i.e., the values are the sum of the innermost values in <code>myDict</code> for tuples whose 0th index is greater than 1. </p>
<pre><code>myDict = {
2000: {(0,1):111.1, (1,2):222.2, (2,3):333.3, (3,4):444.4},
200... | 1 | 2016-10-08T07:06:15Z | [
"python",
"dictionary",
"iteration"
] |
why does function url_for() in Flask produced this error? | 39,929,028 | <p>When I use flask, in my first template(a.html) I wrote:</p>
<pre><code>{{url_for('auth.confirm', token=token, _external=True)}}
</code></pre>
<p>It gave the right site: <code>/auth/confirm/<token></code></p>
<p>But in another:<code>{{url_for('auth.forget', token=token, _external=True)}}</code></p>
<p>It ga... | 0 | 2016-10-08T05:31:05Z | 39,929,066 | <p>The underlying functions are expecting different urls.</p>
<p>In the first case, the flask routing decorator looks like:</p>
<pre><code>@app.route('/auth/confirm/<token>')
def confirm(token):
</code></pre>
<p>In the second, the token is not specified, and therefore passed as a query parameter.</p>
<pre><co... | 1 | 2016-10-08T05:36:17Z | [
"python",
"web",
"flask"
] |
Building Qt Gui from few classes together | 39,929,107 | <p>Below is a short example of my Gui. I am trying to split my Gui in few parts.
The elements of <em>InputAxis</em> should be on the same height (horizontal split) and <em>self.recipient</em> should be below them (vertical split).</p>
<p>In <em>InputAxis</em> I am trying to place a <em>QLineEdit</em> but in my Gui I d... | 0 | 2016-10-08T05:42:05Z | 39,931,251 | <p>the reason it did not work was this line:</p>
<pre><code>self.form_layout = QtGui.QFormLayout()
</code></pre>
<p>It should be:</p>
<pre><code>self.form_layout = QtGui.QFormLayout(self.frame)
</code></pre>
| 1 | 2016-10-08T10:24:17Z | [
"python",
"qt",
"pyqt",
"pyside"
] |
how would one sum a range of numbers within a certain value? | 39,929,113 | <p>I have an array of values like so</p>
<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>
<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + ... | -1 | 2016-10-08T05:43:16Z | 39,929,138 | <pre><code>>>> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
>>> sum([n for n in nums if 2.5 <= n <= 6])
35.7
>>> 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + 6
35.7
</code></pre>
| 2 | 2016-10-08T05:47:17Z | [
"python",
"arrays",
"numpy",
"range"
] |
how would one sum a range of numbers within a certain value? | 39,929,113 | <p>I have an array of values like so</p>
<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>
<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + ... | -1 | 2016-10-08T05:43:16Z | 39,929,157 | <pre><code>sum(filter(lambda x: x>=2.5 and x<=6,nums))
</code></pre>
| 0 | 2016-10-08T05:50:23Z | [
"python",
"arrays",
"numpy",
"range"
] |
how would one sum a range of numbers within a certain value? | 39,929,113 | <p>I have an array of values like so</p>
<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>
<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + ... | -1 | 2016-10-08T05:43:16Z | 39,929,163 | <p>Well, lets assume you have your variables <code>min</code> and <code>max</code> set. Then you can type:</p>
<pre><code>min = 2.5
max = 6
sum = sum( i if i>=min and i<=max else 0 for i in nums )
</code></pre>
<p>Greets!</p>
| 1 | 2016-10-08T05:51:18Z | [
"python",
"arrays",
"numpy",
"range"
] |
how would one sum a range of numbers within a certain value? | 39,929,113 | <p>I have an array of values like so</p>
<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>
<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + ... | -1 | 2016-10-08T05:43:16Z | 39,929,297 | <p>Since no one has offered a numpy solution yet, here you go:</p>
<pre><code>>>> nums = np.array([2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6])
>>> nums[(2.5 <= nums) & (nums <= 6)].sum()
35.700000000000003
</code></pre>
<p>Although, I tried some simple tests, and I'm not sure that t... | 6 | 2016-10-08T06:14:37Z | [
"python",
"arrays",
"numpy",
"range"
] |
how would one sum a range of numbers within a certain value? | 39,929,113 | <p>I have an array of values like so</p>
<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>
<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + ... | -1 | 2016-10-08T05:43:16Z | 39,929,305 | <p>It can also be done by sorting and then bisecting to find the slice of the list to sum:</p>
<pre><code>>>> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
>>> nums.sort()
>>> import bisect
>>> min = 2.5
>>> max = 6
>>> sum(nums[bisect.bisect_right(nums... | 1 | 2016-10-08T06:16:01Z | [
"python",
"arrays",
"numpy",
"range"
] |
how would one sum a range of numbers within a certain value? | 39,929,113 | <p>I have an array of values like so</p>
<pre><code> nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
</code></pre>
<p>Is there a pythonic way to sum all values within this array that are between a certain value? For example, if my range was 2.5-6, I would expect to get 2.5 + 5.4 + 3.2 + 4.4 + 4 + 5.2 + 5 + ... | -1 | 2016-10-08T05:43:16Z | 39,932,335 | <p>Use <code>masked_outside()</code>:</p>
<pre><code>import numpy as np
nums = [2.5, 1, 9, 9.9, 1.6, 5.4, 3.2, 4.4, 4, 5.2, 5, 6]
np.ma.masked_outside(nums, 2.5, 6).sum()
</code></pre>
| 1 | 2016-10-08T12:26:52Z | [
"python",
"arrays",
"numpy",
"range"
] |
Get HTML file after Javascript executed with Scrapy + Splash | 39,929,244 | <p>I want to crawl page that includes javascript using Scrapy and Splash.</p>
<p>In page, <code><script type = text/javascript> JS_FUNCTIONS(generate html content) </script></code> exists, so I tried to get html file after running JS_FUNCTIONS like below.</p>
<pre><code>import scrapy
from scrapy_splash im... | 0 | 2016-10-08T06:06:05Z | 39,931,547 | <p>Maybe try executing with the following lua code:</p>
<pre><code>lua_code = """
function main(splash)
local url = splash.args.url
assert(splash:go(url))
assert(splash:wait(0.5))
return {
html = splash:html(),
}
end
"""
SplashRequest(url,self.parse, args={'lua_source': lua_code}, en... | 0 | 2016-10-08T10:57:16Z | [
"python",
"scrapy",
"web-crawler",
"scrapy-splash"
] |
Connection refused with postgresql using psycopg2 | 39,929,258 | <blockquote>
<p>psycopg2.OperationalError: could not connect to server: Connection refused</p>
</blockquote>
<p>Is the server running on host "45.32.1XX.2XX" and accepting TCP/IP connections on port 5432?</p>
<p>Here,I've open my sockets.</p>
<pre><code>tcp 0 0 127.0.0.1:5432 0.0.0.0:* LISTEN... | 0 | 2016-10-08T06:07:46Z | 39,932,885 | <p>Your netstat output shows that postgres is listening on <code>127.0.0.1</code>, but your error suggests you are trying to connect to <code>45.32.1XX.2XX</code>. I am pretty sure you have already diagnosed your problem. </p>
<p>You will need to modify the <code>listen_addresses</code> setting your <code>postgresql... | 0 | 2016-10-08T13:23:14Z | [
"python",
"postgresql",
"python-3.x"
] |
Python Flask not receiving AJAX post? | 39,929,262 | <p>I have run into a problem with my javascript/python script. What I am trying to do is pass a string to python flask so I can use it later. When I click the button to send the string, there are no errors but nothing happens. I am basically a self taught coder so I apologise if my script it not properly formatted! </p... | 0 | 2016-10-08T06:08:16Z | 39,930,721 | <p>What you want is in <code>request.data</code>.</p>
<p><code>request.args</code> contains parameters in the URL.</p>
<p>Check this out for more details. <a href="http://flask.pocoo.org/docs/0.11/api/#incoming-request-data" rel="nofollow">http://flask.pocoo.org/docs/0.11/api/#incoming-request-data</a></p>
| 2 | 2016-10-08T09:20:29Z | [
"javascript",
"python",
"html",
"ajax",
"flask"
] |
Python Flask not receiving AJAX post? | 39,929,262 | <p>I have run into a problem with my javascript/python script. What I am trying to do is pass a string to python flask so I can use it later. When I click the button to send the string, there are no errors but nothing happens. I am basically a self taught coder so I apologise if my script it not properly formatted! </p... | 0 | 2016-10-08T06:08:16Z | 39,957,470 | <p>If you data object in Ajax is json then you can use <code>request.get_json()</code></p>
<p>If it is form data of key value then you can <code>request.form.get('data')</code> but your ajax should be </p>
<pre><code>$('#button').click(function() {
$.ajax({
url:"/",
type: 'POST',
data: {data: 'mystring'},
</... | 0 | 2016-10-10T11:42:47Z | [
"javascript",
"python",
"html",
"ajax",
"flask"
] |
Python Flask not receiving AJAX post? | 39,929,262 | <p>I have run into a problem with my javascript/python script. What I am trying to do is pass a string to python flask so I can use it later. When I click the button to send the string, there are no errors but nothing happens. I am basically a self taught coder so I apologise if my script it not properly formatted! </p... | 0 | 2016-10-08T06:08:16Z | 40,044,251 | <p>You can make an ajax POST request like this:</p>
<pre><code>$.ajax({
url: "/",
method: "POST",
data: { paramter : value },
});
</code></pre>
<p>The data send over this POST request can be accessed in flask app with<code>request.form['parameter']</code> </p>
<p>If you are sending ... | 0 | 2016-10-14T13:20:51Z | [
"javascript",
"python",
"html",
"ajax",
"flask"
] |
extracting tuple values from list of tuples | 39,929,281 | <p>I have a list containg tuples of different types like:</p>
<pre><code>[(0, 1, 'BLANK', ''), (0, 2, 'PERSON', 'Deraj'), (3, 8, 'DOB', 'April 27 , 1834'), (9, 11, 'PERSON', 'David Deraj'), (11, 13, 'LOC', 'Pennsylvania'), (16, 19, 'PERSON', 'Mary Deraj')]
</code></pre>
<p>How do i get the following output</p>
<pre>... | 1 | 2016-10-08T06:11:27Z | 39,929,320 | <p>You probably can do it like this(if i understand correctly and you want first member of tuple to be second name of those peoples):</p>
<pre><code>l=[]
for i in l:
if i[2]=='PERSON':
temp=i[3].split()
if len(temp)>1:
l.append((temp[1],i[3]))
</code></pre>
| 1 | 2016-10-08T06:17:11Z | [
"python",
"list",
"python-3.x",
"tuples"
] |
extracting tuple values from list of tuples | 39,929,281 | <p>I have a list containg tuples of different types like:</p>
<pre><code>[(0, 1, 'BLANK', ''), (0, 2, 'PERSON', 'Deraj'), (3, 8, 'DOB', 'April 27 , 1834'), (9, 11, 'PERSON', 'David Deraj'), (11, 13, 'LOC', 'Pennsylvania'), (16, 19, 'PERSON', 'Mary Deraj')]
</code></pre>
<p>How do i get the following output</p>
<pre>... | 1 | 2016-10-08T06:11:27Z | 39,931,737 | <p>Assuming that the first record <code>(0, 2, 'PERSON', 'Deraj')</code> has always the first item zero and the second item indicating the number of family members, you can do this in one line.</p>
<pre><code>print [ (entry[3].split()[1], entry[3])
for entry in data
if (entry[2] == 'PERSON' and entry[0... | 1 | 2016-10-08T11:19:43Z | [
"python",
"list",
"python-3.x",
"tuples"
] |
Unable to print the files with special characters while using python | 39,929,412 | <p>I developed a web crawler to extract all the source codes in a wiki link. The program terminates after writing a few files.</p>
<pre><code> def fetch_code(link_list):
for href in link_list:
response = urllib2.urlopen("https://www.wikipedia.org/"+href)
content = response.read()
page = ope... | 0 | 2016-10-08T06:27:14Z | 39,929,459 | <p>you cannot create a file with '/' in its name.</p>
<p>you could escape the filename as M%2Fs.html</p>
<p>/ is %2F</p>
<p>in python2, you could simply use urllib to escape the filename, example:</p>
<pre><code>import urllib
filePath = urllib.quote_plus('M/s.html')
print(filePath)
</code></pre>
<p>on the other ... | 1 | 2016-10-08T06:34:42Z | [
"python"
] |
importError: No module named 'django.db.backends.util' | 39,929,472 | <p>I am using MySql db.i made following changes but now i am getting following error </p>
<pre><code>DATABASES = {
'default': {
'NAME': 'test',
'ENGINE': 'sqlserver_ado',
'HOST':'127.0.0.1',
'USER': 'mssql',
'PASSWORD': 'mssql',
'PORT': '1434'
}
}
</code></pre>
... | 0 | 2016-10-08T06:36:06Z | 39,929,892 | <p>You've probably installed <code>django-mssql</code> version 1.7 which supports <= Django 1.8.</p>
<p>You can try <code>django-mssql-1.8b2</code>:</p>
<pre><code>pip install django-mssql==1.8b2
</code></pre>
<p>Beware that this is probably a beta version, so it might not be suitable for you.</p>
| 0 | 2016-10-08T07:31:47Z | [
"python",
"sql-server",
"django"
] |
importError: No module named 'django.db.backends.util' | 39,929,472 | <p>I am using MySql db.i made following changes but now i am getting following error </p>
<pre><code>DATABASES = {
'default': {
'NAME': 'test',
'ENGINE': 'sqlserver_ado',
'HOST':'127.0.0.1',
'USER': 'mssql',
'PASSWORD': 'mssql',
'PORT': '1434'
}
}
</code></pre>
... | 0 | 2016-10-08T06:36:06Z | 39,930,602 | <p>The error means that you don't have suitable db backends for <code>mssql</code>. You can install <a href="https://github.com/lionheart/django-pyodbc" rel="nofollow">https://github.com/lionheart/django-pyodbc</a> as db backend.</p>
| 0 | 2016-10-08T09:05:29Z | [
"python",
"sql-server",
"django"
] |
Create a list from titanic csv and chart using matplot.pyplot and savefig | 39,929,564 | <p>I'm playing around with the Kaggle Titanic train.csv to get more comfortable with lists, csv reader, and matplot charts. Nevermind that the list I'm creating isn't really necessary to display the data in a chart (or that the chart is a line...). I just want to make a simple chart and save it, but when I look for it ... | 0 | 2016-10-08T06:49:17Z | 39,929,621 | <p><code>csv</code> module doesn't convert text into <code>int</code> so you have to compare <code>tlist[1]</code> with text <code>"1"</code>.</p>
<p>If this doesn't work then add many <code>print(some_usefull_message)</code> in code to see which part is executed. And print variable to see values. Mostly it helps to r... | 0 | 2016-10-08T06:55:52Z | [
"python",
"csv",
"matplotlib"
] |
PyQt application: Restore the original look & feel after changing some QSS elements | 39,929,618 | <p>I'm changing the look of some elements in my pyQt application using a QSS style sheet. This has the effect of overriding many other properties of those elements as well (as noted in the documentation and many tutorials).</p>
<p>Now, I would like to restore these overridden properties, but I haven't managed to find ... | 1 | 2016-10-08T06:55:41Z | 39,934,361 | <p>There are no default stylesheets. All the default styling is done by <a href="http://doc.qt.io/qt-5/style-reference.html" rel="nofollow">style plugins</a>.</p>
<p>When a stylesheet is set, it creates an instance of <code>QStyleSheetStyle</code> (which is a subclass of <code>QWindowsStyle</code>) and passes it a ref... | 0 | 2016-10-08T15:53:13Z | [
"python",
"css",
"user-interface",
"pyqt",
"qss"
] |
Pygame: Collision of two images | 39,929,640 | <p>I'm working on my school project for which im designing a 2D game.</p>
<p>I have 3 images, one is the player and the other 2 are instances (coffee and computer). What i want to do is, when the player image collides with one of the 2 instances i want the program to print something.</p>
<p>I'm unsure if image collis... | 1 | 2016-10-08T06:57:35Z | 39,929,752 | <p>Use <a href="http://pygame.org/docs/ref/rect.html" rel="nofollow">pygame.Rect()</a> to keep image size and position. </p>
<p>Image (or rather <code>pygame.Surface()</code>) has function <code>get_rect()</code> which returns <code>pygame.Rect()</code> with image size (and position).</p>
<pre><code>self.rect = self.... | 0 | 2016-10-08T07:12:04Z | [
"python",
"python-2.7",
"pygame"
] |
How to find least-mean-square error quadratic upper bound? | 39,929,703 | <p>I have some data of the form</p>
<p><code>x1[i], x2[i], x3[i], z[i]</code>,</p>
<p>where <code>z[i]</code> is an unknown deterministic function of <code>x1[i], x2[i], and x3[i]</code>. I would like to find a quadratic function <code>u(x1, x2, x3)= a11*x1^2 + a22*x2^2 + a33*x3^2 + a12*x1*x2 + ... + a0</code> that ... | 2 | 2016-10-08T07:05:26Z | 39,929,895 | <p>There is very simple solution. Just use polynomial regression in Mathlab (<a href="http://www.matrixlab-examples.com/polynomial-regression.html" rel="nofollow">http://www.matrixlab-examples.com/polynomial-regression.html</a>).
You will get a certain function P(x1[i],x2[i],x3[i]).
1. Then for each i compute expressio... | 1 | 2016-10-08T07:32:01Z | [
"python",
"matlab",
"least-squares"
] |
How to find least-mean-square error quadratic upper bound? | 39,929,703 | <p>I have some data of the form</p>
<p><code>x1[i], x2[i], x3[i], z[i]</code>,</p>
<p>where <code>z[i]</code> is an unknown deterministic function of <code>x1[i], x2[i], and x3[i]</code>. I would like to find a quadratic function <code>u(x1, x2, x3)= a11*x1^2 + a22*x2^2 + a33*x3^2 + a12*x1*x2 + ... + a0</code> that ... | 2 | 2016-10-08T07:05:26Z | 39,929,991 | <p>Your problem sounds like a <a href="https://en.wikipedia.org/wiki/Quadratic_programming" rel="nofollow">quadratic programming problem</a> with linear constraints. There are efficient algorithms to solve these and they are implemented in Matlab and Python as well; see <a href="https://www.mathworks.com/help/optim/ug/... | 2 | 2016-10-08T07:43:59Z | [
"python",
"matlab",
"least-squares"
] |
Read and Append csv files in a folder without knowing the name of the files? | 39,929,777 | <p>Is it possible to have numpy look for CSV files in a folder where the code resides and appends couple of the CSV files together?</p>
<p>My current code does something like this:</p>
<pre><code>data = np.loadtxt('csv data file.csv', delimiter=',', skiprows=1)
</code></pre>
<p>Where I have to combine the csv file t... | 2 | 2016-10-08T07:15:18Z | 39,930,305 | <p><em>"Knowing the names of the files"</em> has nothing to do with the problem.</p>
<p>In the example with <a href="/questions/tagged/pandas" class="post-tag" title="show questions tagged 'pandas'" rel="tag">pandas</a>, the filenames are <em>known</em> after this line:</p>
<pre><code>allFiles = glob.glob(pat... | 0 | 2016-10-08T08:25:04Z | [
"python"
] |
Extract sub path from url with regex | 39,929,845 | <p>I have this url:</p>
<pre><code> http://www.example.com/en/news/2016/07/17/1207151/%D9%81%D8%AA%D9%88%D8%A7%DB%8C-%D8%B1%D9%87%D8%A8%D8%B1-
</code></pre>
<p>I am going to extract <code>1207151</code> here.</p>
<p>here is my regext:</p>
<pre><code>pattern = '(http[s]?:\/\/)?([^\/\s]+\/)+[^/]+[^/]+[^/]+[^/]/(?<... | 1 | 2016-10-08T07:25:35Z | 39,929,943 | <p>That will work for you :</p>
<pre><code>(?:http[s]?:\/\/)?(?:.*?)\/(?:.*?)\/(?:.*?)\/(?:.*?)\/(?:.*?)\/(?:.*?)\/(.*?)/
</code></pre>
<p><a href="https://regex101.com/r/uEfSJv/1" rel="nofollow">watch here</a></p>
| 0 | 2016-10-08T07:37:34Z | [
"python",
"regex",
"url"
] |
Extract sub path from url with regex | 39,929,845 | <p>I have this url:</p>
<pre><code> http://www.example.com/en/news/2016/07/17/1207151/%D9%81%D8%AA%D9%88%D8%A7%DB%8C-%D8%B1%D9%87%D8%A8%D8%B1-
</code></pre>
<p>I am going to extract <code>1207151</code> here.</p>
<p>here is my regext:</p>
<pre><code>pattern = '(http[s]?:\/\/)?([^\/\s]+\/)+[^/]+[^/]+[^/]+[^/]/(?<... | 1 | 2016-10-08T07:25:35Z | 39,929,952 | <p>You can use this regex in python code:</p>
<pre><code>>>> url = 'http://www.example.com/en/news/2016/07/17/1207151/%D9%81%D8%AA%D9%88%D8%A7%DB%8C-%D8%B1%D9%87%D8%A8%D8%B1-'
>>> re.search(r'^https?://(?:([^/]+)/){7}', url).group(1)
'1207151'
</code></pre>
<p><code>([^/]+)/){7}</code> will match 1 ... | 2 | 2016-10-08T07:38:41Z | [
"python",
"regex",
"url"
] |
Extract sub path from url with regex | 39,929,845 | <p>I have this url:</p>
<pre><code> http://www.example.com/en/news/2016/07/17/1207151/%D9%81%D8%AA%D9%88%D8%A7%DB%8C-%D8%B1%D9%87%D8%A8%D8%B1-
</code></pre>
<p>I am going to extract <code>1207151</code> here.</p>
<p>here is my regext:</p>
<pre><code>pattern = '(http[s]?:\/\/)?([^\/\s]+\/)+[^/]+[^/]+[^/]+[^/]/(?<... | 1 | 2016-10-08T07:25:35Z | 39,929,955 | <p>You've got a couple things going on.</p>
<p>First you'll need to properly escape all of your <code>/</code>s. You've got most of them, but missed a couple:</p>
<pre><code>(http[s]?:\/\/)?([^\/\s]+\/)+[^\/]+[^\/]+[^\/]+[^\/]\/(?<field1>[^\/]+)\/
</code></pre>
<p>From here, you have a number of "1 or more not... | 1 | 2016-10-08T07:38:55Z | [
"python",
"regex",
"url"
] |
Extract sub path from url with regex | 39,929,845 | <p>I have this url:</p>
<pre><code> http://www.example.com/en/news/2016/07/17/1207151/%D9%81%D8%AA%D9%88%D8%A7%DB%8C-%D8%B1%D9%87%D8%A8%D8%B1-
</code></pre>
<p>I am going to extract <code>1207151</code> here.</p>
<p>here is my regext:</p>
<pre><code>pattern = '(http[s]?:\/\/)?([^\/\s]+\/)+[^/]+[^/]+[^/]+[^/]/(?<... | 1 | 2016-10-08T07:25:35Z | 39,930,087 | <pre><code>import re
print re.search(r'.*/([^/]+)/.*',s).group(1)
</code></pre>
| 0 | 2016-10-08T07:56:30Z | [
"python",
"regex",
"url"
] |
Function works in python shell alone, but not when called to another function? | 39,929,874 | <p>I have a homework issue with one of my functions called function 4.
This is its code:</p>
<pre><code>def getSuit(n):
suits = []
if 1 <= n <= 13:
suits.append("Spades")
return suits
if 14 <= n <= 26:
suits.append("Hearts")
return suits
if 27 <= n <= ... | 0 | 2016-10-08T07:29:55Z | 39,929,940 | <p>In <code>getCart</code> you change <code>n</code> before you use it with <code>getSuit()</code></p>
<pre><code>n = (n-1) % 13 + 1
grabSuit = getSuit(n)
</code></pre>
<p>change order</p>
<pre><code>grabSuit = getSuit(n)
n = (n-1) % 13 + 1
</code></pre>
| 1 | 2016-10-08T07:37:13Z | [
"python",
"list",
"function",
"python-3.x"
] |
Function works in python shell alone, but not when called to another function? | 39,929,874 | <p>I have a homework issue with one of my functions called function 4.
This is its code:</p>
<pre><code>def getSuit(n):
suits = []
if 1 <= n <= 13:
suits.append("Spades")
return suits
if 14 <= n <= 26:
suits.append("Hearts")
return suits
if 27 <= n <= ... | 0 | 2016-10-08T07:29:55Z | 39,929,986 | <pre><code>def getCard(n):
grabSuit = getSuit(n) # Called Function 4 here. <--- Move to this line
n = (n-1) % 13 + 1
deckValue = []
</code></pre>
| -1 | 2016-10-08T07:43:22Z | [
"python",
"list",
"function",
"python-3.x"
] |
pexpect not executing command by steps | 39,929,970 | <p>I have this Python3 code which use Pexpect.</p>
<pre><code>import pexpect
import getpass
import sys
def ssh(username,password,host,port,command,writeline):
child = pexpect.spawn("ssh -p {} {}@{} '{}'".format(port,username,host,command))
child.expect("password: ")
child.sendline(password)
if(writeli... | 0 | 2016-10-08T07:41:28Z | 40,005,934 | <p>You may lack permission for executing commands through ssh. Also there is possibility that your program sends scp before prompt occurs.</p>
| 0 | 2016-10-12T18:33:09Z | [
"python",
"ssh",
"pexpect"
] |
How to make exceptions during the iteration of a for loop in python | 39,930,022 | <p>Sorry in advance for the certainly simple answer to this but I can't seem to figure out how to nest an <code>if ______ in ____:</code> block into an existing <code>for</code> block.</p>
<p>For example, how would I change this block to iterate through each instance of <code>i</code>, omitting odd numbers. </p>
<pre... | 0 | 2016-10-08T07:49:32Z | 39,930,058 | <p>This has nothing to do with nesting. You are comparing apples to pears, or in this case, trying to find an <code>int</code> in a list of <code>str</code> objects.</p>
<p>So the <code>if</code> test never matches, because there is no <code>1</code> in the list <code>['1', '3', '5', '7', '9']</code>; there is no <cod... | 4 | 2016-10-08T07:53:35Z | [
"python",
"python-3.x",
"if-statement",
"for-loop",
"nested"
] |
How to make exceptions during the iteration of a for loop in python | 39,930,022 | <p>Sorry in advance for the certainly simple answer to this but I can't seem to figure out how to nest an <code>if ______ in ____:</code> block into an existing <code>for</code> block.</p>
<p>For example, how would I change this block to iterate through each instance of <code>i</code>, omitting odd numbers. </p>
<pre... | 0 | 2016-10-08T07:49:32Z | 39,930,076 | <p>If you are looking to iterate over a range of even numbers, then something like this should work. With X being an integer. The <code>2</code> is the step so this will omit odd numbers.</p>
<pre><code>for i in range(0,x,2):
print(i)
</code></pre>
<p>For more info check out the docs here:</p>
<p><a href="https:... | 0 | 2016-10-08T07:55:22Z | [
"python",
"python-3.x",
"if-statement",
"for-loop",
"nested"
] |
Why doesn't perceptron's implementation follow the formula in <python machine learning>? | 39,930,035 | <p>I'm beginner in machine learning. I begin my study with the book <a href="http://rads.stackoverflow.com/amzn/click/1783555130" rel="nofollow">python machine learning</a> and some videos online. </p>
<p>I'm confused by the implementation of Perceptron in "python machine learning". This is the formula:</p>
<p><a hre... | 1 | 2016-10-08T07:51:06Z | 39,930,268 | <p>A good question here. The answer should be two-fold.</p>
<h2>W dot X =?= X dot W</h2>
<p>You are perfectly right on that exchanging X and W yeilds different result for matrix multiplication. </p>
<p>However, in this situation, w and x are actually vectors, or m*1 matrix. The dot product results in a scalar. So in... | 1 | 2016-10-08T08:20:18Z | [
"python",
"machine-learning"
] |
Efficiently identifying ancestors/descendants within a given distance, in networkx | 39,930,083 | <p>Is there a function/method in networkx to identify all ancestors/descendants that are within a given (optionally weighted) distance?</p>
<p>For example, something that would efficiently produce the same result as the function below?</p>
<pre class="lang-py prettyprint-override"><code>import networkx
g = networkx.D... | 0 | 2016-10-08T07:56:00Z | 39,932,770 | <p>There is a "cutoff" parameter for some of the NetworkX shortest path algorithms. For example, in your case you can run a "single source shortest path" calculation from your source node to all other nodes and limit the search to paths shorter than a specified cutoff length. In the example below Dijkstra's algorithm... | 1 | 2016-10-08T13:12:17Z | [
"python",
"networkx",
"directed-graph"
] |
Convert CSV document to XML | 39,930,128 | <p>I know the question is redundant but I tried all the Python code that I found and modified for my file but they did not work. I need to find a way to convert my file <a href="http://opendata.paris.fr/explore/dataset/tournagesdefilmsparis2011" rel="nofollow">myData.csv</a> in to a XML format file which can be read by... | 0 | 2016-10-08T08:00:13Z | 39,930,477 | <p>(posted as an answer so I can show a code block)</p>
<p>There are a lot of picky details when writing XML. In Python, you should probably use some version of ElementTree to help with that. One good tutorial is <a href="https://pymotw.com/2/xml/etree/ElementTree/create.html" rel="nofollow" title="PyMOTW">Creating ... | 0 | 2016-10-08T08:50:05Z | [
"python",
"xml",
"csv"
] |
Convert CSV document to XML | 39,930,128 | <p>I know the question is redundant but I tried all the Python code that I found and modified for my file but they did not work. I need to find a way to convert my file <a href="http://opendata.paris.fr/explore/dataset/tournagesdefilmsparis2011" rel="nofollow">myData.csv</a> in to a XML format file which can be read by... | 0 | 2016-10-08T08:00:13Z | 39,934,145 | <p>Consider building your XML with dedicated DOM objects and not a concatenation of strings which you can do with the <code>lxml</code> module. Using methods such as <code>Element()</code>, <code>SubElement()</code>, etc. you can iteratively build XML tree from reading CSV data:</p>
<pre><code>import csv
import lxml.e... | 1 | 2016-10-08T15:29:52Z | [
"python",
"xml",
"csv"
] |
Best way to associate a player character with a server connection? | 39,930,167 | <p>I'm attempting to write a simple multiplayer type text game. I currently have a simple chat server right now. It's working just like it should, echoing the message to all the people connected.</p>
<p>I can't figure out how to take my next step. I want to associate the client connected with a player object. The ... | 0 | 2016-10-08T08:06:29Z | 39,930,417 | <p>You can use a dict to map <a href="https://docs.python.org/2/library/socket.html#socket.socket.fileno" rel="nofollow">fds of client sockets</a> to client objects.</p>
<p>When you receive some new messages, you can fetch the corresponding object from the dict and invoke methods on it.</p>
| 0 | 2016-10-08T08:39:49Z | [
"python",
"python-2.7"
] |
How to mock random.choice in python? | 39,930,244 | <p>I want <code>choice</code> to return the same value <code>1000</code> every time in my unittest. The following code doesn't work.</p>
<pre><code>import unittest
from random import choice
from mock import mock
def a():
return choice([1, 2, 3])
class mockobj(object):
@classmethod
def choice(cls, li):
... | 0 | 2016-10-08T08:16:33Z | 39,930,315 | <p>I don't know what is mockobj from tests but what you can do is.</p>
<pre><code> @mock.patch('random.choice')
def test1(self, choice_mock):
choice_mock.return_value = 1000
self.assertEqual(a(), 1000)
</code></pre>
| 3 | 2016-10-08T08:25:53Z | [
"python",
"unit-testing",
"mocking"
] |
How to mock random.choice in python? | 39,930,244 | <p>I want <code>choice</code> to return the same value <code>1000</code> every time in my unittest. The following code doesn't work.</p>
<pre><code>import unittest
from random import choice
from mock import mock
def a():
return choice([1, 2, 3])
class mockobj(object):
@classmethod
def choice(cls, li):
... | 0 | 2016-10-08T08:16:33Z | 39,930,639 | <p>The problem here is that <code>a()</code> is using an <em>unpatched</em> version of <code>random.choice</code>.</p>
<p>Compare functions <code>a</code> and <code>b</code>:</p>
<pre><code>import random
from random import choice
def a():
return choice([1, 2, 3])
def b():
return random.choice([1, 2, 3])
de... | 3 | 2016-10-08T09:11:32Z | [
"python",
"unit-testing",
"mocking"
] |
python spark change dataframe column data type to int error | 39,930,266 | <p>I want to cast the column type to int and get the first 3 rows</p>
<pre><code> df.withColumn("rn", rowNumber().over(windowSpec).cast('int')).where("rn"<=3).drop("rn").show()
</code></pre>
<p>but I this error </p>
<pre><code>TypeError: unorderable types: str() <= int()
</code></pre>
| 2 | 2016-10-08T08:20:03Z | 39,931,934 | <p>The error is here:</p>
<pre><code>.where("rn"<=3)
</code></pre>
<p>And here's how you can figure that out if you ever encounter a similar problem in the future. Following</p>
<pre><code>TypeError: unorderable types: str() <= int()
</code></pre>
<p>is a Python exception and there is no <code>Py4JError</code... | 1 | 2016-10-08T11:42:46Z | [
"python",
"apache-spark",
"types",
"casting"
] |
Django: How do I get multiple values from checkboxes in dataTable | 39,930,273 | <p>In HTML, every form field needs a name attribute in order to be submitted to the server. But I used dataTable to display all data and pagination. The list checkbox just get the data of the current page not get data of next page or previous page. How can I get all the values of checkbox?</p>
<p>in the template</p>
... | 0 | 2016-10-08T08:20:57Z | 39,931,792 | <p>You can use a hidden input field(type hidden) containing the string (comma separated value), which can later be received on server side as string and further it's splited using split method which will result in desired list</p>
<pre><code> <form>
<input id="result" type="hidden" name="result"> ... | 1 | 2016-10-08T11:26:34Z | [
"python",
"django",
"python-3.x"
] |
Attribute error with BeautifulSoup get method | 39,930,306 | <p>I'm trying to make a webscraper in Python using urllib and BeautifulSoup. My laptop works on Debian, so I don't use the latest version of urllib.</p>
<p>My goal is quite simple : extract values from a Wikipedia table <a href="https://fr.wikipedia.org/wiki/Liste_des_monuments_historiques_de_Chaumont" rel="nofollow">... | 0 | 2016-10-08T08:25:06Z | 39,930,357 | <p>In this loop:</p>
<pre><code>for line in lines:
longitude = line.find("data", {"class":"p-longitude"})
print(longitude)
latitude = line.find("data", {"class":"p-latitude"})
print(latitude)
</code></pre>
<p>For some of the lines, <code>longitude</code> and <code>latitude</code> are found, but for ot... | 3 | 2016-10-08T08:32:16Z | [
"python",
"get",
"tags",
"beautifulsoup"
] |
using redis-py to bulk populate a redis list | 39,930,359 | <p>In a Django project, I'm using redis as a fast backend. </p>
<p>I can LPUSH multiple values in a redis list like so:</p>
<pre><code>lpush(list_name,"1","2","3")
</code></pre>
<p>However, I can't do it if I try</p>
<pre><code>values_list = ["1","2","3"]
lpush(list_name,values_list)
</code></pre>
<p>For the recor... | 0 | 2016-10-08T08:32:22Z | 39,930,371 | <p><code>lpush (list_name, *values_list)</code></p>
<p>This will unpack contents in value_list as parameters.</p>
<p>If you have enormous numbers of values to insert into db, you can pipeline them. Or you can use the command line tool <code>redis-cli --pipe</code> to populate a database</p>
| 0 | 2016-10-08T08:34:00Z | [
"python",
"django",
"redis"
] |
How to convert frozenset to normal sets or list? | 39,930,363 | <p>For example, I have a frozen set</p>
<pre><code>[frozenset({'a', 'c,'}), frozenset({'h,', 'a,'})]
</code></pre>
<p>I want to convert it to a normal list like</p>
<pre><code>[['a', 'c,'],['a,', 'd,']...]
</code></pre>
<p>What method should I use?</p>
| 0 | 2016-10-08T08:32:52Z | 39,930,454 | <pre><code>sets=[frozenset({'a', 'c,'}), frozenset({'h,', 'a,'})]
print([list(x) for x in sets])
</code></pre>
<p>The list comprehension will convert every frozenset in your list of sets and put them into a new list. That's probably what you want.</p>
<p>You can also you map, <code>map(list, sets)</code>. Please be ... | 2 | 2016-10-08T08:46:35Z | [
"python",
"python-3.x"
] |
Remove a string that is a substring of other string in the list WITHOUT changing original order of the list | 39,930,434 | <p>I have a list.</p>
<pre><code>the_list = ['Donald Trump has', 'Donald Trump has small fingers', 'What is going on?']
</code></pre>
<p>I'd like to remove "Donald Trump has" from <code>the_list</code> because it's a substring of other list element.</p>
<p>Here is an important part. I want to do this without distori... | 2 | 2016-10-08T08:42:52Z | 39,930,591 | <p>You can just recursively reduce the items.</p>
<p>Algorithm:</p>
<p>Loop over each item by popping it, decide if it needs to be kept or not.
Call the same function recursively with the reduced list.
Base condition is if the list has at-least one item (or two?).</p>
<p>Efficiency: It might not be the most efficien... | 0 | 2016-10-08T09:03:33Z | [
"python",
"string",
"list"
] |
Remove a string that is a substring of other string in the list WITHOUT changing original order of the list | 39,930,434 | <p>I have a list.</p>
<pre><code>the_list = ['Donald Trump has', 'Donald Trump has small fingers', 'What is going on?']
</code></pre>
<p>I'd like to remove "Donald Trump has" from <code>the_list</code> because it's a substring of other list element.</p>
<p>Here is an important part. I want to do this without distori... | 2 | 2016-10-08T08:42:52Z | 39,930,940 | <p>You can do this without sorting:</p>
<pre><code>the_list = ['Donald Trump has', "I've heard Donald Trump has small fingers",
'What is going on?']
def winnow(a_list):
keep = set()
for item in a_list:
if not any(item in other for other in a_list if item != other):
keep.add(ite... | 1 | 2016-10-08T09:45:22Z | [
"python",
"string",
"list"
] |
Remove a string that is a substring of other string in the list WITHOUT changing original order of the list | 39,930,434 | <p>I have a list.</p>
<pre><code>the_list = ['Donald Trump has', 'Donald Trump has small fingers', 'What is going on?']
</code></pre>
<p>I'd like to remove "Donald Trump has" from <code>the_list</code> because it's a substring of other list element.</p>
<p>Here is an important part. I want to do this without distori... | 2 | 2016-10-08T08:42:52Z | 39,931,663 | <p>A simple solution.</p>
<p>But first, let's also add '<em>Donald Trump</em>', <em>'Donald'</em> and <em>'Trump'</em> in the end to make it a better test case.</p>
<pre><code>>>> forbidden_text = "\nX08y6\n" # choose a text that will hardly appear in any sensible string
>>> the_list = ['Donald Trum... | 2 | 2016-10-08T11:11:48Z | [
"python",
"string",
"list"
] |
Read from binary file with Python 3.5 | 39,930,642 | <p>I use this piece of code:</p>
<pre><code>from struct import Struct
import struct
def read_chunk(fmt, fileobj):
chunk_struct = Struct(fmt)
chunk = fileobj.read(chunk_struct.size)
return chunk_struct.unpack(chunk)
def read_record(fileobj):
author_id, len_author_name = read_chunk('ii', f)
autho... | 0 | 2016-10-08T09:11:46Z | 39,931,026 | <p>This format is not correct:</p>
<pre><code>author_name, nu_of_publ = read_chunk(str(len_author_name)+'si', f)
</code></pre>
<p>You are defining a structure of N characters and an integer. Those structures are <a href="https://docs.python.org/2/library/struct.html#byte-order-size-and-alignment" rel="nofollow">align... | 0 | 2016-10-08T09:56:35Z | [
"python",
"python-3.x",
"binaryfiles"
] |
How do I catch an Interrupt signal in Python when inside a blocking boost c++ method? | 39,930,722 | <p>I have a toolset which has been written in C++, and given Boost bindings for Python.</p>
<p>Initially, this code was all C++, and I caught a <kbd>CTRL</kbd>+<kbd>C</kbd> interrupt with:</p>
<pre><code>signal( SIGINT, signalCallbackHandler );
</code></pre>
<p>and</p>
<pre><code>void signalCallbackHandler(int /*si... | 1 | 2016-10-08T09:20:30Z | 39,936,134 | <p>I have <em>a</em> solution that works for this, although it'd be cleaner if I could get the signal caught in Python rather than C++.</p>
<p>One thing I didn't mention before is that MyObject is a singleton, so I'm getting it with <code>MyObject.getObject()</code></p>
<p>In Python, I've got:</p>
<pre><code>def sig... | 0 | 2016-10-08T18:53:36Z | [
"python",
"c++",
"boost"
] |
How do I catch an Interrupt signal in Python when inside a blocking boost c++ method? | 39,930,722 | <p>I have a toolset which has been written in C++, and given Boost bindings for Python.</p>
<p>Initially, this code was all C++, and I caught a <kbd>CTRL</kbd>+<kbd>C</kbd> interrupt with:</p>
<pre><code>signal( SIGINT, signalCallbackHandler );
</code></pre>
<p>and</p>
<pre><code>void signalCallbackHandler(int /*si... | 1 | 2016-10-08T09:20:30Z | 39,938,987 | <p>Your python signal handler is not called because python defers execution of signal handlers until after the next bytecode instruction is to be executed - see <a href="https://docs.python.org/3.6/library/signal.html" rel="nofollow">the library documentation for signal</a>, section 18.8.1.1.</p>
<p>The reason for thi... | 0 | 2016-10-09T01:10:29Z | [
"python",
"c++",
"boost"
] |
Changing default keybinding in yhat's Rodeo IDE | 39,930,830 | <p>To comment out a block in Rodeo the <a href="http://rodeo.yhat.com/docs/#keyboard-shortcuts" rel="nofollow">docs</a> state to do <code>ctrl + /</code>. But on my machine thats not working, so I want to change a single keysetting. Where I am able to do this in Rodeo?</p>
| 0 | 2016-10-08T09:32:45Z | 39,930,917 | <p>You can edit key-bindings in preferences <a href="http://rodeo.yhat.com/docs/#preferences" rel="nofollow">http://rodeo.yhat.com/docs/#preferences</a></p>
<p>Changing the key bindings should avoid the use of <code>ctrl + /</code>, but if you just want to change a single setting, as far as I know, it's not possible. ... | 1 | 2016-10-08T09:42:34Z | [
"python",
"key-bindings",
"rodeo"
] |
Make an exe which extracts multiple files | 39,930,855 | <p>I want to make an executable file which will extract multiple files into a specific location.
I've read about the 'extractall()' function, and using unzip, but how do I contain the multiple files inside the executable python file, so each time the user double click the exe file, it will extract these files into the... | -2 | 2016-10-08T09:35:14Z | 39,931,080 | <p>Be aware that your archive will be (in most part) platform-specific -- it may not work on <code>Windows</code> if you make it on a <code>Unix-like</code> machine and vice versa, etc.</p>
<p>I would recommend that you check this <code>pymakeself</code> which is a pypi <a href="https://pypi.python.org/pypi/pymakeself... | 0 | 2016-10-08T10:02:33Z | [
"python",
"zip",
"executable"
] |
Create new line in a python string that does NOT effect output? | 39,930,934 | <p>is it possible to create a new line in a string in one's python code that does NOT effect output?</p>
<p>Like:</p>
<pre><code>print "This
is
my
string"
</code></pre>
<p>But the output when the program is run would just be "This is my string"</p>
<p>Just for purposes of formatting the program in a more readable w... | 0 | 2016-10-08T09:44:52Z | 39,930,964 | <p>You can invoke <a href="https://docs.python.org/2/reference/lexical_analysis.html#explicit-line-joining" rel="nofollow">explicit line joining</a>, adding a backslash at the end of each line:</p>
<pre><code>>>> print "this \
... is \
... my \
... string"
this is my string
</code></pre>
| 2 | 2016-10-08T09:47:44Z | [
"python",
"python-2.7"
] |
Create new line in a python string that does NOT effect output? | 39,930,934 | <p>is it possible to create a new line in a string in one's python code that does NOT effect output?</p>
<p>Like:</p>
<pre><code>print "This
is
my
string"
</code></pre>
<p>But the output when the program is run would just be "This is my string"</p>
<p>Just for purposes of formatting the program in a more readable w... | 0 | 2016-10-08T09:44:52Z | 39,931,001 | <p>You could use implicit string joining too:</p>
<pre><code>print("this "
"is "
"my "
"string")
</code></pre>
| 4 | 2016-10-08T09:52:08Z | [
"python",
"python-2.7"
] |
Create new line in a python string that does NOT effect output? | 39,930,934 | <p>is it possible to create a new line in a string in one's python code that does NOT effect output?</p>
<p>Like:</p>
<pre><code>print "This
is
my
string"
</code></pre>
<p>But the output when the program is run would just be "This is my string"</p>
<p>Just for purposes of formatting the program in a more readable w... | 0 | 2016-10-08T09:44:52Z | 39,932,128 | <p>You could also add a comma after every print statement to print the next output on the same line :</p>
<pre><code>print "This",
print "is",
print "my",
print "string"
</code></pre>
| 1 | 2016-10-08T12:05:10Z | [
"python",
"python-2.7"
] |
Python: How to convert google location timestaMps in a year-month-day-hour-minute-seconds format? | 39,930,950 | <p>I am playing around with my google location data (which one can download here <a href="https://takeout.google.com/settings/takeout" rel="nofollow">https://takeout.google.com/settings/takeout</a>). </p>
<p>The location data is a json file, of which one variable is 'timestaMps' (e.g. one observation is "1475146082971... | -1 | 2016-10-08T09:46:17Z | 39,931,087 | <p>Use <a href="https://docs.python.org/2/library/datetime.html#datetime.date.fromtimestamp" rel="nofollow">fromtimestamp</a> method from datetime module.
To convert your 'timestaMps' to timestamp you need to convert it to int(). Formating of timestamp is done with <a href="https://docs.python.org/2/library/time.html#... | 0 | 2016-10-08T10:02:59Z | [
"python",
"google-maps",
"datetime",
"timestamp"
] |
Cannot import keras after installation | 39,930,952 | <p>I'm trying to setup <code>keras</code> deep learning library for <code>Python3.5</code> on Ubuntu 16.04 LTS and use <code>Tensorflow</code> as a backend. I have <code>Python2.7</code> and <code>Python3.5</code> installed. I have installed <code>Anaconda</code> and with help of it <code>Tensorflow</code>, <code>nump... | 0 | 2016-10-08T09:46:36Z | 39,931,939 | <h2>Diagnose</h2>
<p>If you have <code>pip</code> installed (you should have it until you use Python 3.5), list the installed Python packages, like this:</p>
<pre><code>$ pip list | grep -i keras
Keras (1.1.0)
</code></pre>
<p>If you donât see Keras, it means that the previous installation failed or is incomplete ... | 1 | 2016-10-08T11:43:22Z | [
"python",
"ubuntu",
"tensorflow",
"anaconda",
"keras"
] |
Cannot change python interpreter | 39,930,958 | <p>I imported a python project from github into pycharm. I developed this project in windows but now i am using mac. </p>
<p>I changed the project interpreter in the settings but when running it says: "error running the project" and the error message says that it points to the python interpreter of my old windows dire... | 0 | 2016-10-08T09:47:04Z | 39,931,237 | <p>I found the solution. There is a file under the project directory: .idea/workspace.xml which contains the older setting. Deleting this file caused pycharm to recreate it with the new settings.</p>
| 0 | 2016-10-08T10:23:22Z | [
"python",
"pycharm",
"anaconda"
] |
Using decorators inside a class | 39,931,089 | <p>I am trying to implement a simple logging feature within my app.</p>
<pre><code>class messages(object):
# Implement decorator here
def on(self):
def wrapper():
# Do something here
return wrapper
def off(self):
def wrapper():
# Do something here
r... | 0 | 2016-10-08T10:03:19Z | 39,931,211 | <p>Below is the sample decorator that you may use:</p>
<pre><code>class Utilities:
@staticmethod
def add_logger(func):
def wrapped_func(*args, **kwargs):
# Sample logic, feel free to update this
try:
func_response = func(*args, **kwargs)
except:
... | 0 | 2016-10-08T10:20:59Z | [
"python",
"oop",
"decorator"
] |
Using decorators inside a class | 39,931,089 | <p>I am trying to implement a simple logging feature within my app.</p>
<pre><code>class messages(object):
# Implement decorator here
def on(self):
def wrapper():
# Do something here
return wrapper
def off(self):
def wrapper():
# Do something here
r... | 0 | 2016-10-08T10:03:19Z | 39,931,226 | <ol>
<li><p>If you just want Dog to bark (like in the example), there is no need for enabling a decorator</p>
<pre><code>class Dog(object):
def __init__(self):
self.sound = "Woof!"
def bark(self):
return self.sound
</code></pre></li>
<li><p>If you want to enable logging for some functions in c... | 1 | 2016-10-08T10:22:45Z | [
"python",
"oop",
"decorator"
] |
Selecting a rows from a panda frame based on a time that has been converted into datetime format and stripped from a POSIX time stamp, python | 39,931,243 | <p>I am using the code below to pull data from Google Finance. The timestamp is in POSIX form, so it is converted into data time. When I try to fiter it based on a time criteria <strong>(14:35:00)</strong>, it returns an empty table. I suspect it has to do with the POSIX/ datetime conversion, but have no idea how to re... | 0 | 2016-10-08T10:23:51Z | 39,931,462 | <p>You can use this </p>
<pre><code>NAS.query('Datetime.dt.hour==14 and Datetime.dt.minute==35 and Datetime.dt.second==0')
</code></pre>
<p><strong>Edit:</strong>
Applied dt on datetime series instead of time series</p>
<pre><code>raw_data = {'Datetime': ['2015-05-01T14:35:00', '2016-07-04T02:26:00', '2013-02-01T04:... | 1 | 2016-10-08T10:47:14Z | [
"python",
"python-3.x",
"datetime",
"pandas",
"posixlt"
] |
Selecting a rows from a panda frame based on a time that has been converted into datetime format and stripped from a POSIX time stamp, python | 39,931,243 | <p>I am using the code below to pull data from Google Finance. The timestamp is in POSIX form, so it is converted into data time. When I try to fiter it based on a time criteria <strong>(14:35:00)</strong>, it returns an empty table. I suspect it has to do with the POSIX/ datetime conversion, but have no idea how to re... | 0 | 2016-10-08T10:23:51Z | 39,932,494 | <p>I see that you are converting <code>timestamp</code> to <code>datetime</code> incorrectly. You are calling <code>datetime</code> twice.</p>
<p>Replace</p>
<pre><code>df['Datetime'] = df['Datetime'].apply(lambda x: datetime.datetime.fromtimestamp(int(x[1:])))
</code></pre>
<p>with </p>
<pre><code>df['Datetime'] =... | 1 | 2016-10-08T12:42:41Z | [
"python",
"python-3.x",
"datetime",
"pandas",
"posixlt"
] |
How to get mask from numpy array according to all values on third axis | 39,931,382 | <p>I have numpy array like:</p>
<pre><code>A = np.zeros((X,Y,Z))
</code></pre>
<p>Later I fill the array with values and I need to find x,y coordinates according to values in arrays on z axis to replace it with different array.</p>
<p>Example with<code>Z=2</code> I have array</p>
<pre><code>A = [ [ [1,2], [2,1], [... | 1 | 2016-10-08T10:40:41Z | 39,931,494 | <p>One vectorized approach -</p>
<pre><code>A[(A == [1,2]).all(-1)] = [2,1]
</code></pre>
<p>Sample run -</p>
<pre><code>In [15]: A
Out[15]:
array([[[1, 2],
[2, 1],
[0, 0]],
[[1, 1],
[1, 2],
[0, 0]]])
In [16]: A[(A == [1,2]).all(-1)] = [2,1]
In [17]: A
Out[17]:
array([[[2,... | 3 | 2016-10-08T10:50:55Z | [
"python",
"arrays",
"numpy",
"vectorization"
] |
Creating Rest Api in python using JSON? | 39,931,557 | <p>I'm new to python REST API and so facing some particular problems. I want that when I enter the input as pathlabid(primary key), I want the corresponding data assigned with that key as output. When I run the following code i only get the data corresponding to the first row of table in database even when the id i ent... | 0 | 2016-10-08T10:58:25Z | 39,932,091 | <p>You are return the response in for loop so that loop break on 1st entry </p>
<pre><code>import json
some_list = []
for i in data:
some_list.append({"key": "value"})
return HttpResponse(json.dumps({"some_list": some_list}), content_type="application/json")
</code></pre>
<p>Try above example to solve your proble... | 0 | 2016-10-08T12:02:01Z | [
"python",
"json",
"django",
"rest",
"api"
] |
Creating Rest Api in python using JSON? | 39,931,557 | <p>I'm new to python REST API and so facing some particular problems. I want that when I enter the input as pathlabid(primary key), I want the corresponding data assigned with that key as output. When I run the following code i only get the data corresponding to the first row of table in database even when the id i ent... | 0 | 2016-10-08T10:58:25Z | 39,962,089 | <p>There are a number of issues with the overall approach and code but to fix the issue you're describing, but as a first fix I agree with the other answer: you need to take the <code>return</code> statement out of the loop. Right now you're <code>return</code>ing your list as soon as you step through the loop one time... | 0 | 2016-10-10T15:52:41Z | [
"python",
"json",
"django",
"rest",
"api"
] |
Python socket recv() doesn't get every message if send too fast | 39,931,611 | <p>I send mouse coordinates from python server to python client via socket. Mouse coordinates are send every time when mouse movement event is catch on the server which means quite often (dozen or so per second).</p>
<p>Problem is when I use python server and python client on different hosts. Then only part of message... | 1 | 2016-10-08T11:04:43Z | 39,931,786 | <p>You are using TCP (SOCK_STREAM) which is a reliable protocol which (contrary to UDP) does not loose any messages, even if the recipient is not reading the data fast enough. Instead TCP will reduce the sending speed.<br>
This means that the problem must be somewhere in your application code. </p>
<p>One possibility ... | 2 | 2016-10-08T11:26:00Z | [
"python",
"sockets"
] |
Reverse Count after threshold | 39,931,757 | <p>I am feeding a number slider in RhinoPython to increment the y value. I wish to reverse the increment when y equals a certain value. I have figured out how to make it negative, but that is not what I'm after. Sorry, for the simplicity of this question and thank you. In short the number slider increments the variable... | 0 | 2016-10-08T11:22:19Z | 39,931,880 | <p>First of all, don't call a variable <code>len</code>, because it is a name of standard library function.
If I understood the question correctly, the code would be</p>
<pre><code>threshold = 45
inc = .1
y = 0
while True: # goes forever, put your own code here
if y >= threshold:
inc *= -1
y += in... | 2 | 2016-10-08T11:36:56Z | [
"python",
"rhino3d"
] |
Matplotlib and it's connection with tkinter | 39,931,797 | <p>I have a question, which may not be even related to the modules. </p>
<p>In the code below, there is a function update, which will create a canvas by matplotlib and assign it to the related frame from tkinter. Then it create an event handler Cursor, which should print the position of the mouse into the console. But... | 1 | 2016-10-08T11:26:54Z | 39,932,733 | <p>Your problem appears to be one about variable scope and lifetime.</p>
<p>When your <code>update()</code> function ends, the variables <code>fig</code> and <code>cursor</code> declared within it go out of scope. The figure and cursor objects created within your <code>update()</code> have no further references point... | 2 | 2016-10-08T13:09:06Z | [
"python",
"matplotlib",
"tkinter"
] |
Issue with pattern program using loops | 39,931,798 | <p>I'm writing a program that takes two inputs, number of lines and number of cheers as input. The number of lines is how many lines the user wants to print out and the number of cheers are in the format that 1 cheer is the word "GO" and two cheers are two "GO" s ...and their is the word "BUDDY" within two neighboring ... | 0 | 2016-10-08T11:27:11Z | 39,931,879 | <pre><code>def greet(lines, cheers):
i = 0
line_str = ""
while i < cheers: # Build the line string
i += 1
line_str += "GO" if i == cheers else "GO BUDDY "
i = 0
while i < lines: #Print each line
print(" "*(i*3) + line_str)
i += 1
greet(2,1)
greet(4,3)
greet(2... | 1 | 2016-10-08T11:36:55Z | [
"python",
"python-2.7",
"design-patterns"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.