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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Speeding up Python file handling for a huge dataset | 38,279,216 | <p>I have a large dataset stored as a 17GB csv file (<em>fileData</em>), which contains a variable number of records (up to approx 30,000) for each customer_id. I am trying to search for specific customers (listed in <em>fileSelection</em> - around 1500 out of a total of 90000) and copy the records for each of these c... | 2 | 2016-07-09T06:53:52Z | 38,279,319 | <p>Use the csv reader instead. Python has a good library to handle CSV files so that it is not necessary for you to do splits.</p>
<p>Check out the documentation: <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">https://docs.python.org/2/library/csv.html</a></p>
<pre><code>>>> import csv
&... | 3 | 2016-07-09T07:07:30Z | [
"python",
"performance",
"csv",
"large-files",
"python-multithreading"
] |
Speeding up Python file handling for a huge dataset | 38,279,216 | <p>I have a large dataset stored as a 17GB csv file (<em>fileData</em>), which contains a variable number of records (up to approx 30,000) for each customer_id. I am trying to search for specific customers (listed in <em>fileSelection</em> - around 1500 out of a total of 90000) and copy the records for each of these c... | 2 | 2016-07-09T06:53:52Z | 38,279,354 | <p>Try using <a href="http://pandas.pydata.org/pandas-docs/stable/index.html" rel="nofollow">pandas</a> if your machine can handle the size of the csv in memory.</p>
<p>If you are looking for out of core computation - take a look at <a href="http://dask.pydata.org/en/latest/" rel="nofollow">dask</a> (they provide simi... | 2 | 2016-07-09T07:12:45Z | [
"python",
"performance",
"csv",
"large-files",
"python-multithreading"
] |
Speeding up Python file handling for a huge dataset | 38,279,216 | <p>I have a large dataset stored as a 17GB csv file (<em>fileData</em>), which contains a variable number of records (up to approx 30,000) for each customer_id. I am trying to search for specific customers (listed in <em>fileSelection</em> - around 1500 out of a total of 90000) and copy the records for each of these c... | 2 | 2016-07-09T06:53:52Z | 38,279,814 | <p>The task is way too involved for a simple answer. But your approach is very inefficient because you have too many nested loops. Try making ONE pass through the list of customers, and for each build a "customer" object with any information that you need to use later. You put these in a dictionary; the keys are the... | 2 | 2016-07-09T08:13:18Z | [
"python",
"performance",
"csv",
"large-files",
"python-multithreading"
] |
Images appearing in all but 1 flask page | 38,279,228 | <p>I am creating a web app in flask, python, mysql. When viewing every other page on my website my images load, but when viewing one specific page, I can't get any images to load using already working code. Is there any reason this may be?</p>
<p>Code for one of my working pages:</p>
<pre><code>{% extends "base.html"... | 0 | 2016-07-09T06:55:27Z | 38,279,710 | <p>In your <code>item</code> view function, you are not passing the value of <code>id</code> into your <code>sql</code> expression, here is the safe way to do it:</p>
<pre><code>@app.route('/shop/item/<id>')
def item(id):
cursor = mysql.connect().cursor()
sql_exp = "SELECT * FROM shoes WHERE id=%d"
... | 1 | 2016-07-09T08:01:59Z | [
"python",
"mysql",
"flask"
] |
Images appearing in all but 1 flask page | 38,279,228 | <p>I am creating a web app in flask, python, mysql. When viewing every other page on my website my images load, but when viewing one specific page, I can't get any images to load using already working code. Is there any reason this may be?</p>
<p>Code for one of my working pages:</p>
<pre><code>{% extends "base.html"... | 0 | 2016-07-09T06:55:27Z | 38,281,525 | <p>URLs are made up of directories and filenames. Anything that precedes a <code>/</code> is considered a directory. Anything after the final <code>/</code> is the filename. Your problem is that you're using relative URLs. When you say</p>
<pre><code>static/pics/gamma.png
</code></pre>
<p>your browser makes a request... | 1 | 2016-07-09T11:52:01Z | [
"python",
"mysql",
"flask"
] |
Scraping AJAX loaded content with python? | 38,279,253 | <p>So i have function that is called when i click a button , it goes as below</p>
<p></p>
<pre><code>var min_news_id = "68feb985-1d08-4f5d-8855-cb35ae6c3e93-1";
function loadMoreNews(){
$("#load-more-btn").hide();
$("#load-more-gif").show();
$.post("/en/ajax/more_news",{'category':'','news_offset':min_news_id},... | 0 | 2016-07-09T06:58:30Z | 38,281,019 | <p>You need to post the news id that you see inside the script to <em><a href="https://www.inshorts.com/en/ajax/more_news" rel="nofollow">https://www.inshorts.com/en/ajax/more_news</a></em>, this is an example using <a href="http://docs.python-requests.org/en/master/user/advanced/" rel="nofollow">requests</a>:</p>
<pr... | 0 | 2016-07-09T10:49:57Z | [
"python",
"ajax",
"web-scraping",
"screen-scraping"
] |
Python - Comparing each item of a list to every other item in that list | 38,279,269 | <p>I need to compare every item in a very long list (12471 items) to every other item in the same list. Below is my list:</p>
<pre><code>[array([3, 4, 5])
array([ 6, 8, 10])
array([ 9, 12, 15])
array([12, 16, 20])
array([15, 20, 25])
...] #12471 items long
</code></pre>
<p>I need to compare the secon... | 0 | 2016-07-09T07:00:13Z | 38,279,406 | <p>While this is still theoretically N^2 time (worst case), it should make things a bit better:</p>
<pre><code>import collections
inval = [[3, 4, 5],
[ 6, 8, 10],
[ 9, 12, 15],
[ 12, 14, 15],
[12, 16, 20],
[ 6, 6, 10],
[ 8, 8, 10],
[15, 20, 25]]
by_first = collections.defaultdict(list)
by_second = collections.def... | 2 | 2016-07-09T07:20:30Z | [
"python",
"python-2.7"
] |
Python - Comparing each item of a list to every other item in that list | 38,279,269 | <p>I need to compare every item in a very long list (12471 items) to every other item in the same list. Below is my list:</p>
<pre><code>[array([3, 4, 5])
array([ 6, 8, 10])
array([ 9, 12, 15])
array([12, 16, 20])
array([15, 20, 25])
...] #12471 items long
</code></pre>
<p>I need to compare the secon... | 0 | 2016-07-09T07:00:13Z | 38,279,472 | <p>We can do this in O(N) with an assumption that python dict takes O(1) time for insert and lookup.</p>
<ol>
<li>In the first scan, we create a map storing first number and row index by scanning the full list</li>
<li>In the second scan, we find if map from first scan contains second element of each row. If map conta... | 2 | 2016-07-09T07:31:21Z | [
"python",
"python-2.7"
] |
How do I get such a nested lists? | 38,279,455 | <pre><code>variable tree structure
- nestedList1 variable
aa3
|
aa1 aa2 bb1
\ / /
aa bb
\ /
root
- nestedList2 variable
bb4
|
aa3 bb2 bb3
| \ /
aa1 aa2 bb1 cc1
\ / / |... | 5 | 2016-07-09T07:28:07Z | 38,280,222 | <p>Basically, what you need to do in order to reorder the list: Whenever the <code>n</code>th element is a label, and the <code>n+1</code>th element is a sublist, swap the two. You can do this <em>in-place</em> in a few line:</p>
<pre><code>def reorder(lst):
for i, (cur, nxt) in enumerate(zip(lst, lst[1:])):
... | 2 | 2016-07-09T09:14:15Z | [
"python",
"recursion",
"nested-lists"
] |
How do I get such a nested lists? | 38,279,455 | <pre><code>variable tree structure
- nestedList1 variable
aa3
|
aa1 aa2 bb1
\ / /
aa bb
\ /
root
- nestedList2 variable
bb4
|
aa3 bb2 bb3
| \ /
aa1 aa2 bb1 cc1
\ / / |... | 5 | 2016-07-09T07:28:07Z | 38,282,124 | <p>I may be out of line here, or completely missing the point, but I'll risk claiming that I think it will be easier if you collect each branch fully to parenthesis. i.e. write each branch as an distinctive [root, [branch1], [branch2],...]</p>
<pre><code>nestedList1 = ['root', ['aa', ['aa1', ['aa3']], ['aa2']], ['bb',... | 0 | 2016-07-09T13:06:10Z | [
"python",
"recursion",
"nested-lists"
] |
Query data stored in MongoDB by date & time | 38,279,541 | <p>I want to count the number of objects which were stored in the MongoDB after a certain time. Date is stored in MongoDB in following format.</p>
<pre><code> "clickTime" : ISODate("2016-07-09T07:17:29.932Z")
</code></pre>
<p>I wrote the following code to count the objects but it is giving me <code>_count = 0</code>,... | 1 | 2016-07-09T07:41:28Z | 38,279,614 | <p>I am not quite sure of what type your <code>start</code> and <code>end</code> vars are according to your question but try it when setting them to <code>datetime</code> instances like below:</p>
<pre><code>start = datetime.datetime(2016, 7, 9, 0, 0, 0, 0)
end = datetime.datetime(2016, 7, 9, 12, 21, 25, 366)
</code><... | 0 | 2016-07-09T07:50:43Z | [
"python",
"mongodb",
"datetime",
"mongodb-query",
"pymongo"
] |
Viola-Jones in Python with openCV, detection mouth and nose | 38,279,632 | <p>I have an algorithm <a href="http://docs.opencv.org/master/d7/d8b/tutorial_py_face_detection.html#gsc.tab=0" rel="nofollow">Viola-Jones</a> in <code>Python</code>. I'm using <code>haarcascade</code> xml, which I load from <code>openCV</code> root file. But there wasn't any xml file for mouth and nose in <code>openCV... | 0 | 2016-07-09T07:53:24Z | 38,349,335 | <p>Haar cascades perform alright for faces but not so well for smaller individual parts. A better solution is to detect all the face landmarks together. A good algorithm for that is "One Millisecond Face Alignment with an Ensemble of Regression Trees by Vahid Kazemi and Josephine Sullivan, CVPR 2014" which is implement... | 1 | 2016-07-13T10:39:29Z | [
"python",
"xml",
"opencv",
"face-detection",
"viola-jones"
] |
AttributeError: 'module' object has no attribute 'loads' while parsing json in python | 38,279,636 | <p>I am getting this error:</p>
<pre><code>Traceback (most recent call last):
File "C:/Users/Shivam/Desktop/jsparse.py", line 13, in <module>
info = json.loads(str(data))
AttributeError: 'module' object has no attribute 'loads'
</code></pre>
<p>Any thoughts what wrong I am doing here?</p>
<p>This is my code:</... | 0 | 2016-07-09T07:53:55Z | 38,280,900 | <p>The problem is that you're using Python 2.5.x, which doesn't have the <code>json</code> module. If possible, I recommend upgrading to Python 2.7.x, as 2.5.x is badly outdated.</p>
<p>If you need to stick with Python 2.5.x, you'll have to use the <code>simplejson</code> module (see <a href="https://stackoverflow.com... | 1 | 2016-07-09T10:35:31Z | [
"python",
"json",
"python-2.5"
] |
while True issue in Python | 38,279,638 | <p>I am monitoring a specific PID with python and trying to execute a function if this PID is not there anymore to bring it up again. The problem is that my loop seems to be working for 1,5 (yes, one and a half) loop and then breaks it self.</p>
<pre><code>while True:
print "[DEBUG] We are in the loop"
query =... | -1 | 2016-07-09T07:54:00Z | 38,279,825 | <p>Try wrapping your code in try block, and see if any exception is getting thrown.</p>
<pre>
while True:
try:
print "[DEBUG] We are in the loop"
if (GetObject('winmgmts:').ExecQuery("Select * from Win32_Process where ProcessId = " + str(monitorPID)).count == 0):
RunTheProgramAgain()
... | 1 | 2016-07-09T08:15:11Z | [
"python",
"loops",
"process",
"while-loop"
] |
Blob detection + foreground detection | 38,279,741 | <p>My frame differencing (foreground detection) works perfectly. Now, I want to add an extra function into it which is blob detection. Basically, my idea is to form blob circle on the detected object's motion.</p>
<p>This is my code:</p>
<pre><code>import cv2
cap = cv2.VideoCapture('14.mp4')
ret, current_frame = cap... | 1 | 2016-07-09T08:05:00Z | 38,279,881 | <p>You are passing your <code>cap</code> variable to the function <a href="http://docs.opencv.org/2.4/modules/features2d/doc/common_interfaces_of_feature_detectors.html?highlight=detect#featuredetector-detect" rel="nofollow"><code>detector.detect</code></a>, but <code>cap</code> comes from <a href="http://docs.opencv.o... | 0 | 2016-07-09T08:21:52Z | [
"python",
"opencv"
] |
Python Threading Issue on Windows | 38,279,752 | <p>At first I thought I had some kind of memory leak causing an issue but I'm getting an exception I'm not sure I fully understand but at least I've narrowed it down now.</p>
<p>I'm using a while True loop to keep a thread running and retrieving data. If it runs into a problem it logs it and keeps running. It seems to... | 0 | 2016-07-09T08:06:25Z | 38,374,094 | <p>The question I came to in the final answer solved it.</p>
<p>I was using a thread pool to give the browser spawn a timeout as a workaround for the bug in the library. But I wasn't terminating that thread pool so eventually after the x amount of loops the OS wouldn't let it create another pool.</p>
<p>Adding a .ter... | 0 | 2016-07-14T12:23:02Z | [
"python",
"multithreading"
] |
Foreignkey doesn't work in django | 38,279,846 | <p>I'm using <code>django 1.9.7</code> & <code>python3.5</code> and have some problems in using <code>Foreignkey</code>.</p>
<p><code>models.py</code></p>
<pre><code>from django.db import models
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
reverse = dict... | 1 | 2016-07-09T08:17:35Z | 38,279,915 | <p>The <code>status</code> context variable is not a single <code>Status</code> object, but a list of objects returned by the <code>filter</code> query (in this case it contains only one item). You either need to loop through the list:</p>
<pre><code>{% for s in status %}
{% for chart in s.chart_set.all %}
... | 1 | 2016-07-09T08:28:45Z | [
"python",
"django",
"foreign-keys"
] |
Use Python- Selenium to select span style object | 38,279,917 | <p>Team,</p>
<p>I am trying to select one table object using <code>python</code> + <code>selenium-webdriver</code>. I tried to use the following method but it is not working: </p>
<pre><code>select = browser.findElement(By.xpath("//tr/td[contains(text(), 'ALL_incidents')]"))
</code></pre>
<p>This is the HTML:
<a hre... | -2 | 2016-07-09T08:28:51Z | 38,280,003 | <p>Try following <code>XPath</code>:</p>
<pre><code>//td/nobr/span[text()="ALL_incidents"]
</code></pre>
| 0 | 2016-07-09T08:41:56Z | [
"python",
"python-2.7",
"selenium",
"xpath"
] |
How to integrate Pygame and PyQt4? | 38,280,057 | <p>I'm using python 2.7 and Ubuntu 14.04.</p>
<p>I'm trying to do <a href="http://www.pygame.org/docs/ref/display.html#pygame.display.init" rel="nofollow">this</a> in order to have my pygame window inside my GUI</p>
<blockquote>
<p><strong>On some platforms it is possible to embed the pygame display into an already... | 0 | 2016-07-09T08:51:20Z | 38,284,856 | <p>Here is a sample solution as per the comment above:</p>
<pre><code>from PyQt4 import QtGui
import pygame
import sys
class ImageWidget(QtGui.QWidget):
def __init__(self,surface,parent=None):
super(ImageWidget,self).__init__(parent)
w=surface.get_width()
h=surface.get_height()
sel... | 1 | 2016-07-09T18:14:42Z | [
"python",
"python-2.7",
"pyqt",
"pygame",
"ubuntu-14.04"
] |
Python requests with multithreading | 38,280,094 | <p>I've been trying to build a scraper with multithreading functionality past two days. Somehow I still couldn't manage it. At first I tried regular multithreading approach with threading module but it wasn't faster than using a single thread. Later I learnt that requests is blocking and multithreading approach isn't r... | 4 | 2016-07-09T08:56:21Z | 38,280,387 | <p>Install the <a href="https://github.com/kennethreitz/grequests" rel="nofollow"><code>grequests</code> module</a> which works with <code>gevent</code> (<code>requests</code> is not designed for async):</p>
<pre><code>pip install grequests
</code></pre>
<p>Then change the code to something like this:</p>
<pre><code... | 2 | 2016-07-09T09:35:28Z | [
"python",
"multithreading",
"asynchronous",
"python-requests",
"gevent"
] |
mod_wsgi (pid=2179): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module | 38,280,166 | <p>I am working on AWS RHEL server.
Getting this error each time I access the webpage(Webpage showing 500).</p>
<p>Error.log:</p>
<pre><code>[Sat Jul 09 02:51:12.736533 2016] [:error] [pid 2179] mod_wsgi (pid=2179): Target WSGI script '/opt/graphite/conf/graphite.wsgi' cannot be loaded as Python module.
[Sat Jul 09 0... | 0 | 2016-07-09T09:05:57Z | 38,527,553 | <p>I got it running by changing SELinux settings. Editing the file /etc/selinux/config: </p>
<pre><code>SELINUX=disabled
</code></pre>
| 0 | 2016-07-22T13:21:00Z | [
"python",
"apache",
"amazon-ec2",
"mod-wsgi",
"graphite"
] |
How Scenarios work in behave BDD test | 38,280,239 | <p>I want to know the Scenarios in a feature execute one by one or randomly??</p>
<p>Feature: feature name</p>
<p>Scenario: scenario1
Given some condition
When some action is taken
Then some result is expected.</p>
<p>Scenario: scenario2
Given some other condition
When some action i... | -1 | 2016-07-09T09:15:55Z | 38,323,622 | <p>The order of Scenarios should be exactly as in the file, except that cases when some custom sorting is using. But to be more accurate we need to know what is a testing framework you are using, because each of them has a lot of different parameters for running the tests. But by default it should be exactly in the fil... | 0 | 2016-07-12T08:28:31Z | [
"python",
"bdd"
] |
maximum recursion depth exceeded while calling a Python object -runtime error | 38,280,269 | <pre><code>import pandas as pd
import xlsxwriter
import openpyxl as px
import numpy as np
from xlwt import Workbook
from os.path import expanduser
home = expanduser("~")
def read_survey():
df_appliance=pd.read_csv('C:/Users/nidi/Desktop/New folder/app_info.csv')
df_appliance.fillna(0, inplace=True)
retu... | 0 | 2016-07-09T09:19:11Z | 38,281,858 | <p>Since you are calling <code>pd.read_excel</code>, you must have Pandas installed.
Therefore the easiest way to merge the data is to call <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow"><code>pd.merge</code></a> on two DataFrames:</p>
<pre><code>import panda... | 0 | 2016-07-09T12:36:08Z | [
"python",
"arrays",
"excel",
"numpy",
"pandas"
] |
python Link verification program | 38,280,271 | <p>I was making python link verification program so that i can scrap all links in the given url and verify them.</p>
<p>I tried to use re module inside the for loop, and it turned out it is invalid syntax.</p>
<p>but i really can't think of other ways that could pull out all the links and check every one of them.. so... | -2 | 2016-07-09T09:19:29Z | 38,280,789 | <p>You can grab the URLs using regex like:</p>
<pre><code>urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', res.text)
</code></pre>
<p><code>urls</code> will give you a list of URLs.</p>
<p>From there, you can verify the links if they're not broken by doing:</p>
... | 2 | 2016-07-09T10:22:25Z | [
"python"
] |
Creating a backspace button on my calculator python tkinter GUI | 38,280,277 | <p>i'm very new to python and i would like to fix the "C" button so that it clears the last number on the display. For example 321 would become 32, i have tried a lot of things but i can't seem to get it to work, i would be very grateful if someone could get it working, thank you. Here is the code:</p>
<pre><code>fro... | 3 | 2016-07-09T09:19:54Z | 38,280,441 | <p>For backspace, you need only remove the last charachter in the array, right?
If so, the following function should work fine <br></p>
<pre><code>def backspace(self):
self.current = self.current[0:len(self.current) -1]
if self.current == "":
self.new_num = True
self.current = "0"
self.dsiplay(self.cur... | 3 | 2016-07-09T09:42:33Z | [
"python",
"user-interface",
"tkinter",
"clear",
"backspace"
] |
Creating a backspace button on my calculator python tkinter GUI | 38,280,277 | <p>i'm very new to python and i would like to fix the "C" button so that it clears the last number on the display. For example 321 would become 32, i have tried a lot of things but i can't seem to get it to work, i would be very grateful if someone could get it working, thank you. Here is the code:</p>
<pre><code>fro... | 3 | 2016-07-09T09:19:54Z | 38,280,576 | <p>Add a new button - </p>
<pre><code>back = Button(calc, text = "B")
back["command"] = sum1.backspace
back.grid(row = 4, column = 2, pady = 5)
</code></pre>
<p>and define a function like this - </p>
<pre><code>def backspace(self):
#check if all has been removed
#make sure you import the re module
if re.match(r... | 2 | 2016-07-09T09:57:22Z | [
"python",
"user-interface",
"tkinter",
"clear",
"backspace"
] |
Creating a backspace button on my calculator python tkinter GUI | 38,280,277 | <p>i'm very new to python and i would like to fix the "C" button so that it clears the last number on the display. For example 321 would become 32, i have tried a lot of things but i can't seem to get it to work, i would be very grateful if someone could get it working, thank you. Here is the code:</p>
<pre><code>fro... | 3 | 2016-07-09T09:19:54Z | 38,280,823 | <p>Using a <a href="http://effbot.org/tkinterbook/variable.htm" rel="nofollow">variable class</a> is very handy for your situation because it will allow you to update the text of text_box using by setting the content of this variable. Note that doing so, you will not have to change anything else in your code apart fro... | 1 | 2016-07-09T10:26:16Z | [
"python",
"user-interface",
"tkinter",
"clear",
"backspace"
] |
Understanding the random function in Python coding | 38,280,298 | <p>I would appreciate it if someone can help me understand the random function in Python?</p>
<pre><code>nLines=500
xys = random([nLines,2])*500-250
oris = random(nLines)*180
</code></pre>
<p>In the example here, the values of the oris will be between 0-180. (based on what the website said)</p>
<p>How is this achie... | -4 | 2016-07-09T09:22:49Z | 38,280,402 | <p>The * is normal multiplication. random() funtcion takes no parameters so your code might give an error in compilation. The random() function returns a float between 0 and 0.999999 so multiplying it by 180 will give you a number between 0 and 179.999999. Finally, xys will not have a value between 0 and 250. It will h... | 1 | 2016-07-09T09:36:49Z | [
"python",
"psychopy"
] |
selenium element click not working as expected | 38,280,397 | <p>I was trying to write an automated script to download some foreign exchange USD/CAD price historical data with selenium. These data are available at</p>
<p><a href="https://www.dukascopy.com/swiss/english/marketwatch/historical/" rel="nofollow">https://www.dukascopy.com/swiss/english/marketwatch/historical/</a></p>... | 0 | 2016-07-09T09:36:22Z | 38,280,747 | <p><strong><em>Edit:</em></strong></p>
<p>There may be an issue with it clicking the correct element. So after the line:</p>
<pre><code>candle_unit_ele = wait.until(EC.visibility_of_element_located((By.ID, ":3")))
</code></pre>
<p>Add:</p>
<pre><code>candle_unit_ele = driver.find_element_by_xpath("//*[@id=':3']/div... | 0 | 2016-07-09T10:17:26Z | [
"python",
"selenium",
"web-crawler"
] |
selenium element click not working as expected | 38,280,397 | <p>I was trying to write an automated script to download some foreign exchange USD/CAD price historical data with selenium. These data are available at</p>
<p><a href="https://www.dukascopy.com/swiss/english/marketwatch/historical/" rel="nofollow">https://www.dukascopy.com/swiss/english/marketwatch/historical/</a></p>... | 0 | 2016-07-09T09:36:22Z | 38,280,764 | <p>I have tried this and it was working for me:</p>
<pre><code> candle_unit_ele = wait.until(EC.visibility_of_element_located((By.ID, ":3"))
candle_unit_ele.click()
</code></pre>
<p>Replace your code above with:</p>
<pre><code> candle_unit_ele = driver.find_element_by_id(":3")
candle_unit_ele.click()
</cod... | 0 | 2016-07-09T10:19:02Z | [
"python",
"selenium",
"web-crawler"
] |
Is a constructor __init__ necessary for a class in Python? | 38,280,526 | <p>I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the <code>__init__</code> method. For example,</p>
<pre><code>class NewsStory(object):
def __init__(self, guid, title, subject, summary, link):
self... | 2 | 2016-07-09T09:52:07Z | 38,280,574 | <p>No, the constructor is just the method that is called to construct the object. It is not passed anywhere. Rather the object it<code>self</code> is passed automatically to all methods of the class. </p>
<p>Constructor is not required if you don't have anything to construct but usually you have something to do in the... | 3 | 2016-07-09T09:56:58Z | [
"python",
"class",
"oop",
"constructor",
"initialization"
] |
Is a constructor __init__ necessary for a class in Python? | 38,280,526 | <p>I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the <code>__init__</code> method. For example,</p>
<pre><code>class NewsStory(object):
def __init__(self, guid, title, subject, summary, link):
self... | 2 | 2016-07-09T09:52:07Z | 38,280,581 | <p>You're on the right track. <code>__init__()</code>'s arguments are the arguments for instantiating the class. This is similar to a <em>constructor</em> in other languages, however <code>__new__()</code> (which you'll almost never need to actually use) is what actually creates the object.</p>
<p>If I create this cla... | -2 | 2016-07-09T09:57:46Z | [
"python",
"class",
"oop",
"constructor",
"initialization"
] |
Is a constructor __init__ necessary for a class in Python? | 38,280,526 | <p>I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the <code>__init__</code> method. For example,</p>
<pre><code>class NewsStory(object):
def __init__(self, guid, title, subject, summary, link):
self... | 2 | 2016-07-09T09:52:07Z | 38,280,800 | <p>It is not necessary as it is the object constructor that define default values upon calling the class but developers generally advise to use <strong>init</strong> function as a convention.
<strong>init</strong> Returns "none" where a normal function has to retrun a value.</p>
| 0 | 2016-07-09T10:23:35Z | [
"python",
"class",
"oop",
"constructor",
"initialization"
] |
Is a constructor __init__ necessary for a class in Python? | 38,280,526 | <p>I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the <code>__init__</code> method. For example,</p>
<pre><code>class NewsStory(object):
def __init__(self, guid, title, subject, summary, link):
self... | 2 | 2016-07-09T09:52:07Z | 38,280,864 | <p>Python classes work a little different to classes in other languages.
For example, there are no private attributes in python. Just naming conventions to imply that a method or member variable is not intended for public use (a leading <code>_</code>).</p>
<p>While every class has to have the attributes <code>__new__... | 0 | 2016-07-09T10:31:01Z | [
"python",
"class",
"oop",
"constructor",
"initialization"
] |
Is a constructor __init__ necessary for a class in Python? | 38,280,526 | <p>I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the <code>__init__</code> method. For example,</p>
<pre><code>class NewsStory(object):
def __init__(self, guid, title, subject, summary, link):
self... | 2 | 2016-07-09T09:52:07Z | 38,281,239 | <p>I see a misconception here between a constructor--constructing the object and initializing the object: </p>
<p><a href="http://(https://stackoverflow.com/questions/674304/pythons-use-of-new-and-init)">Python's use of <code>__new__</code> and <code>__init__</code>?</a></p>
<blockquote>
<p>Use <code>__new__</code>... | 1 | 2016-07-09T11:16:04Z | [
"python",
"class",
"oop",
"constructor",
"initialization"
] |
Is a constructor __init__ necessary for a class in Python? | 38,280,526 | <p>I read that the constructor is like the first argument passed to the class, which makes sense to me since the parameters seem to be passed to the class via the <code>__init__</code> method. For example,</p>
<pre><code>class NewsStory(object):
def __init__(self, guid, title, subject, summary, link):
self... | 2 | 2016-07-09T09:52:07Z | 38,281,308 | <p>It is not too difficult to understand Python class constructors but sure a little tricky especially if we already hear some object oriented programming terms from other languages that support OOP like C++ or Java.</p>
<p>Main purpose of a class constructor is to create objects with instances customized to a specifi... | 0 | 2016-07-09T11:24:26Z | [
"python",
"class",
"oop",
"constructor",
"initialization"
] |
Using any() and all() on multiIndex DataFrame while slicing via .xs: strange behavior or just me? | 38,280,695 | <p>I am fairly new to Python and this community so please forgive my amateurish attempts to explain my profound confusion on something that is most likely very obvious. Anyway..</p>
<p>I have a dataframe called "data". It is multiIndexed with 2 levels consisting of: "date" and "farts". </p>
<p>There is a single colum... | 3 | 2016-07-09T10:10:19Z | 38,280,840 | <p>First let me define what any means according to the documentation of pandas- </p>
<blockquote>
<p>Return whether any element is True over requested axis</p>
</blockquote>
<p>Now when you write - </p>
<pre><code>data.xs(farts[1], level = 1).any()
</code></pre>
<p>It just checks whether any of the values is trut... | 2 | 2016-07-09T10:28:20Z | [
"python",
"pandas",
"dataframe",
"multi-index",
"any"
] |
Using any() and all() on multiIndex DataFrame while slicing via .xs: strange behavior or just me? | 38,280,695 | <p>I am fairly new to Python and this community so please forgive my amateurish attempts to explain my profound confusion on something that is most likely very obvious. Anyway..</p>
<p>I have a dataframe called "data". It is multiIndexed with 2 levels consisting of: "date" and "farts". </p>
<p>There is a single colum... | 3 | 2016-07-09T10:10:19Z | 38,280,928 | <p>Consider this simple series:</p>
<pre><code>import numpy as np
np.random.seed(0)
ser = pd.Series(np.random.randint(0, 3, 10))
ser
Out[78]:
0 0
1 1
2 0
3 1
4 1
5 2
6 0
7 2
8 0
9 0
dtype: int32
</code></pre>
<p>Let's say you want to do the comparison <code>ser < 2</code>, it will r... | 3 | 2016-07-09T10:38:50Z | [
"python",
"pandas",
"dataframe",
"multi-index",
"any"
] |
How to make conda virtual environments persistent and available for tools such as Jupyter Notebook? | 38,280,739 | <p>When a conda environment is activated in a shell window, the environment is only active in that window (i.e. not persistent). So when I navigate to the project location in another window, the "root" virtual environment is active.</p>
<p>Am I missing something or is this the intended behaviour?</p>
<p>How to give t... | 2 | 2016-07-09T10:16:13Z | 38,281,052 | <h2>Register a (python) notebook kernel:</h2>
<p>Let's suppose you have created a conda environment named <code>jupyter-env35</code> with <code>conda create -n jupyter-env35 python=3.5</code> and now want to use it in jupyter.</p>
<p>Installing and registering a python kernel in the environment will make it available... | 1 | 2016-07-09T10:53:30Z | [
"python",
"ipython",
"jupyter",
"jupyter-notebook",
"conda"
] |
Python websockets command line input | 38,280,752 | <p>I have followed a couple of guides online and am able to get a working websockets app running with tornado. However I want to be able to accept command line input on the tornado server and send this as a message to the connected clients.</p>
<p>The code I use if the same as this </p>
<p><a href="https://github.com... | 0 | 2016-07-09T10:17:44Z | 38,298,569 | <ol>
<li>you should have a client program connected with web socket server</li>
<li>make the client program able to be used in linux terminal</li>
</ol>
| 0 | 2016-07-11T03:05:06Z | [
"python",
"websocket",
"tornado"
] |
Turn string into a list | 38,280,778 | <p>I think what I'm trying to turn into a list is a string.</p>
<p>So when I run this it prints out a list of urls. I want to turn those urls into a list like this:</p>
<pre><code>["Apple", "Pear", "Radio"]
</code></pre>
<p>Code: </p>
<pre><code>url = "http://www.wired.com/category/science/page/"
a = list(range(1... | -2 | 2016-07-09T10:20:11Z | 38,281,028 | <p>To get list of 11 urls:</p>
<pre><code>url = "http://www.wired.com/category/science/page/"
urls = []
for i in range(1, 12):
new_url = url + str(i)
urls.append(new_url)
print urls
</code></pre>
| 0 | 2016-07-09T10:51:18Z | [
"python",
"python-2.x"
] |
Celeryd ignores BROKER_URL in /etc/defult/celeryd | 38,280,795 | <p><strong>Summary</strong> </p>
<ul>
<li>I am running Celery as a daemon via celeryd (<a href="http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html" rel="nofollow">as per instructions</a>)</li>
<li>Specified redis as the broker in the configuration file /etc/default/celeryd BROKER_URL="redis://localhos... | 0 | 2016-07-09T10:22:47Z | 38,361,666 | <p>/etc/default/celeryd is configuration for the daemon, and only <a href="http://docs.celeryproject.org/en/latest/tutorials/daemonizing.html#available-options" rel="nofollow">these options</a> will go there. You can configure your celery <a href="http://docs.celeryproject.org/en/latest/getting-started/first-steps-with... | 0 | 2016-07-13T21:03:18Z | [
"python",
"redis",
"celery",
"celeryd"
] |
Tkinter : Issue with creating keyboard shortcuts | 38,280,804 | <p>I'm having problem with making keyboard shortcuts for my program. I couldn't seem to get <code>root.bind("<Control-Shift-s>",function)</code> to work, but <code>root.bind("<Control-s>",function)</code> works perfectly. Here's the example code:</p>
<pre><code>from tkinter import *
root = Tk()
def functi... | 1 | 2016-07-09T10:23:58Z | 38,281,022 | <p>Change:</p>
<pre><code>root.bind("<Control-Shift-s>",function) # Doesn't work
</code></pre>
<p>To one of these:</p>
<ol>
<li><code>root.bind("<</code><kbd>Control</kbd><code>-</code><kbd>Shift_L</kbd><code>><</code><kbd>S</kbd>><code>",function)</code></li>
<li><code>root.bind("<</code><kbd>Cont... | 0 | 2016-07-09T10:50:35Z | [
"python",
"function",
"tkinter",
"bind"
] |
How to install numpy on freshly installed Python 3.5 in Windows 10? | 38,280,815 | <p>I just type this in terminal in Pycharm</p>
<pre><code>C:\Users\Me\PycharmProjects\SEMUA>python -m pip install numpy
</code></pre>
<p>Then this happen.</p>
<pre><code>Collecting numpy
Using cached numpy-1.11.1.zip
Installing collected packages: numpy
Running setup.py install for numpy ... error
Complet... | 0 | 2016-07-09T10:25:07Z | 38,281,057 | <p>Follow standard way : <code>pip3 install numpy</code></p>
| -2 | 2016-07-09T10:54:12Z | [
"python",
"numpy"
] |
How to install numpy on freshly installed Python 3.5 in Windows 10? | 38,280,815 | <p>I just type this in terminal in Pycharm</p>
<pre><code>C:\Users\Me\PycharmProjects\SEMUA>python -m pip install numpy
</code></pre>
<p>Then this happen.</p>
<pre><code>Collecting numpy
Using cached numpy-1.11.1.zip
Installing collected packages: numpy
Running setup.py install for numpy ... error
Complet... | 0 | 2016-07-09T10:25:07Z | 38,281,717 | <p>Download this
<a href="https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11/unable-to-find-vcvarsall-bat/" rel="nofollow">numpy-1.11.1+mkl-cp35-cp35m-win_amd64.whl</a></p>
<p>Why not from numpy site itself ? Because I need some kind of <a href="https://blogs.msdn.microsoft.com/pythonengineering/2016/04/11... | 0 | 2016-07-09T12:15:31Z | [
"python",
"numpy"
] |
How to install numpy on freshly installed Python 3.5 in Windows 10? | 38,280,815 | <p>I just type this in terminal in Pycharm</p>
<pre><code>C:\Users\Me\PycharmProjects\SEMUA>python -m pip install numpy
</code></pre>
<p>Then this happen.</p>
<pre><code>Collecting numpy
Using cached numpy-1.11.1.zip
Installing collected packages: numpy
Running setup.py install for numpy ... error
Complet... | 0 | 2016-07-09T10:25:07Z | 38,284,610 | <p>Numpy makes use of compiled C code to speed some functions up. Your install may fail when the needed compiler is not present in your install environment. </p>
<p>Christoph Gohlke's website at <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a> provides... | 1 | 2016-07-09T17:47:04Z | [
"python",
"numpy"
] |
Django forms in ReactJs | 38,280,859 | <p>Is there any way I can use django forms inside react js script, like include {{ form }} in the jsx file? I have a view which displays a from and it is rendered using react, When I load this page from one page the data in these fields should be empty, but when I hit this view another page I want date to be prefilled ... | 1 | 2016-07-09T10:30:45Z | 38,281,765 | <p>The <code>{{ form }}</code> statement is relative to Django template. Django templates responsible for rendering HTML and so do React, so you don't have to mix the two together.</p>
<p>What you probably want to do is to use the django form validation mechanism server side, et let React render the form client side. ... | 0 | 2016-07-09T12:23:11Z | [
"python",
"reactjs",
"django-forms"
] |
mne_browse_raw (Python MNE): How can I access user interface? | 38,280,924 | <p>How can I access the user interface of mne_browse_raw as shown <a href="http://martinos.org/mne/dev/manual/gui/browse.html#the-user-interface" rel="nofollow">in this link</a>? When I type the command, for example,</p>
<pre><code>$ mne browse_raw --raw test_raw.fif
</code></pre>
<p>I get </p>
<blockquote>
<p>Ope... | 0 | 2016-07-09T10:37:42Z | 38,634,142 | <p>There are several 'flavors' of MNE. There is the C version you operate from the command line. There is a Python version that includes a lot more stuff, but is generally accessed from an IPython session. Finally, there is a also a MATLAB toolbox.</p>
<p>The user interface you want is from the C version. So install <... | 0 | 2016-07-28T10:47:44Z | [
"python"
] |
Can anyone explain how this functional program work? | 38,280,947 | <pre><code>def apply_twice(func,arg):
return func(func(arg))
def add_five(x):
return x+5
print (apply_twice(add_five,10))
</code></pre>
<p>The output I get is 20.</p>
<p>This one is actually confusing me like how is it working.Can anybody explain me how this is working by breaking it down </p>
| -1 | 2016-07-09T10:40:40Z | 38,280,981 | <p>Expanding the code it executes as follows, starting with the <code>print</code> call:</p>
<p><code>apply_twice(add_five,10))</code></p>
<p><code>add_five(add_five(10)) # add_five(10) = 15</code></p>
<p><code>add_five(15) # add_five(15) = 20</code></p>
<p>Which gives you the result: 20.</p>
<p>When <code>apply_t... | 2 | 2016-07-09T10:44:09Z | [
"python",
"python-2.7",
"python-3.x"
] |
Can anyone explain how this functional program work? | 38,280,947 | <pre><code>def apply_twice(func,arg):
return func(func(arg))
def add_five(x):
return x+5
print (apply_twice(add_five,10))
</code></pre>
<p>The output I get is 20.</p>
<p>This one is actually confusing me like how is it working.Can anybody explain me how this is working by breaking it down </p>
| -1 | 2016-07-09T10:40:40Z | 38,280,988 | <p>The function <code>apply_twice(func,arg)</code> takes two arguments, a function object <code>func</code> and an argument to pass to the function <code>func</code> called <code>arg</code>. </p>
<p>In Python, functions can easily be passed around to other functions as arguments, <strong><em>they are not treated diffe... | 7 | 2016-07-09T10:45:02Z | [
"python",
"python-2.7",
"python-3.x"
] |
Tweepy StreamListener to CSV | 38,281,076 | <p>I'm a newbie on python and I'm trying to develop an app that retrieves data from Twitter with Tweepy and the Streaming APIs and converts the data on a CSV file.
The problem is that this code doesn't create an output CSV file, maybe because I should set the code to stop when it achieves for eg. 1000 tweets but I'm no... | 0 | 2016-07-09T10:56:06Z | 38,281,149 | <p>The function that you are trying to write the csv with is never called.
I assume you wanted to write this code in <code>CustomStreamListener.on_status</code>.
Also, you have to write the titles to the file once (outside the stream listener).
Take a look at this code:</p>
<pre><code>import sys
import tweepy
import ... | 3 | 2016-07-09T11:04:28Z | [
"python",
"python-3.x",
"csv",
"tweepy"
] |
serializing the object containing the function - Meaning | 38,281,131 | <p>The below text is from Chapter 3 of <a href="http://shop.oreilly.com/product/0636920028512.do" rel="nofollow">Learning Spark</a></p>
<blockquote>
<p>One issue to watch out for when passing functions is <strong>inadvertently
serializing the object containing the function</strong>. When you pass a
function that... | 1 | 2016-07-09T11:02:07Z | 38,281,259 | <p>Workers in distributed systems don't have shared memory, hence each worker has to have a copy of all the functions, data etc it might need to run the code. Hence, when you make calls that are supposed to be distributed, you should try to reduce this overhead by making sure that you are not copying stuff the worker d... | 1 | 2016-07-09T11:19:03Z | [
"python",
"apache-spark"
] |
How to install Django Rest Framework using Anaconda? | 38,281,563 | <p>Main OS I am using are Ubuntu and Windows. I couldn't find the package in conda. I am using python 3.5.</p>
| 0 | 2016-07-09T11:56:11Z | 38,281,707 | <p>Create a virtualenv for each Django project and install Django and Django-rest framework using pip, after activating the virtualenv.
I have found it's best to use Ubuntu, especally if linux is your deployment target. If you use windows still use the standard wild python distribution from python.org. You can install ... | 0 | 2016-07-09T12:13:51Z | [
"python",
"python-3.x",
"django-rest-framework",
"anaconda",
"conda"
] |
PyPI Module not working | 38,281,593 | <p>So today i started working on a simple python module, but i cant make it work.
the module itself works, but when i have uploaded it to PyPI and i then install it using Pip, it wont work.
Please notice that it is built for python-2.7
The source code can be seen here:</p>
<blockquote>
<p><a href="https://github.com... | 1 | 2016-07-09T12:00:06Z | 38,281,692 | <p>What if you do </p>
<pre><code>from FortyTwo import fortytwo
fortytwo.nope()
</code></pre>
<p>* credits to eandersson.</p>
| 1 | 2016-07-09T12:12:03Z | [
"python",
"python-2.7",
"pip",
"pypi"
] |
PyPI Module not working | 38,281,593 | <p>So today i started working on a simple python module, but i cant make it work.
the module itself works, but when i have uploaded it to PyPI and i then install it using Pip, it wont work.
Please notice that it is built for python-2.7
The source code can be seen here:</p>
<blockquote>
<p><a href="https://github.com... | 1 | 2016-07-09T12:00:06Z | 38,281,700 | <p>You would need to do the following.</p>
<pre><code>from FortyTwo import fortytwo
fortytwo.nope()
</code></pre>
<p>If you want to call nope directly from FortyTwo you would need to import that function in <code>__init__.py</code>.</p>
<p>e.g.</p>
<pre><code>from FortyTwo.fortytwo import nope
def Start():
"""... | 1 | 2016-07-09T12:12:46Z | [
"python",
"python-2.7",
"pip",
"pypi"
] |
Why python Phonenumbers library give null for country of +358*****? | 38,281,596 | <p>I use the below code to get the country of phone number and I currently use <code>phonenumbers</code>:</p>
<pre><code>query = phonenumbers.parse(number, None)
geocoder.country_name_for_number(query, "en")
</code></pre>
<p>It gives error for numbers with <code>+358</code>. The library version I tested was the lates... | 3 | 2016-07-09T12:00:46Z | 38,281,743 | <p>I think the problem is that the prefix <code>+358</code> is ambiguous. You can see that if you call</p>
<pre><code>>>> geocoder.region_codes_for_country_code(358)
('FI', 'AX')
</code></pre>
<p><code>+358</code> is the prefix both for Finland and for the Ã
land Islands (AX).</p>
<p>If a code is ambiguous,... | 1 | 2016-07-09T12:20:33Z | [
"python",
"phone-number"
] |
Why python Phonenumbers library give null for country of +358*****? | 38,281,596 | <p>I use the below code to get the country of phone number and I currently use <code>phonenumbers</code>:</p>
<pre><code>query = phonenumbers.parse(number, None)
geocoder.country_name_for_number(query, "en")
</code></pre>
<p>It gives error for numbers with <code>+358</code>. The library version I tested was the lates... | 3 | 2016-07-09T12:00:46Z | 38,281,762 | <p>You may have <em>overmasked</em> it. As @Barmar pointed out, according to <a href="https://en.wikipedia.org/wiki/Telephone_numbers_in_Finland" rel="nofollow">Wikipedia</a>, the numbers after the '+358' the next number should be 9 (or 0).</p>
<pre><code>>>> geocoder.country_name_for_number(phonenumbers.pars... | 2 | 2016-07-09T12:22:50Z | [
"python",
"phone-number"
] |
Why python Phonenumbers library give null for country of +358*****? | 38,281,596 | <p>I use the below code to get the country of phone number and I currently use <code>phonenumbers</code>:</p>
<pre><code>query = phonenumbers.parse(number, None)
geocoder.country_name_for_number(query, "en")
</code></pre>
<p>It gives error for numbers with <code>+358</code>. The library version I tested was the lates... | 3 | 2016-07-09T12:00:46Z | 38,350,443 | <p>I have opened an issue on their <code>github</code> page:</p>
<p><a href="https://github.com/googlei18n/libphonenumber/issues/1198" rel="nofollow">Why python phonenumbers library return empty string for country of +3587*****?</a></p>
<p>In case there was an answer, I would post it here later on.</p>
| 0 | 2016-07-13T11:28:56Z | [
"python",
"phone-number"
] |
Filehandling with Python on Linux OS | 38,281,637 | <p>I have written the following code on Python on Linux OS:</p>
<pre><code> variable='jack'
import os
os.system('mkdir '+variable)
</code></pre>
<p>Then a directory is made with the name jack on the present working directory.</p>
<p>However, if I want to use file handling for the same purpose</p>
<pre><code>varia... | 1 | 2016-07-09T12:05:10Z | 38,281,664 | <p>You need to pass the variable:</p>
<pre><code>f.write("os.system(mkdir {})".format(variable))
</code></pre>
<p>or:</p>
<pre><code>f.write("os.system(mkdir " + variable + ")"))
</code></pre>
<p>You are writing the literal string <code>"+ variable"</code> as you have it all inside the double quotes. You also have ... | 0 | 2016-07-09T12:08:15Z | [
"python",
"linux"
] |
MongoDB $skip + $limit duplicates in find results | 38,281,824 | <p>I'm using <strong>$skip</strong> and <strong>$limit</strong> in my aggregation queries for AJAX pagination in my Django app. Here is an example of my code:</p>
<pre><code>art_cursor = Articles.objects.aggregate({'match': {'ntype': {'$in': [1,6]}}},
{'$group': {'_id': {'title': '$title'}}},
{'$sort': {'_id.t... | 0 | 2016-07-09T12:31:34Z | 38,282,348 | <p>Ok, the problem is about <strong>$sort</strong> + <strong>$limit</strong> MongoDB optimization. When we got $limit right after $sort, MongoDB optimizer sorting only objects we got in $limit result.</p>
<p>Source (MongoDB docs): <a href="https://docs.mongodb.com/manual/core/aggregation-pipeline-optimization/#agg-sor... | 0 | 2016-07-09T13:32:56Z | [
"python",
"django",
"mongodb",
"mongoengine"
] |
should the return value for `__enter__` method always be `self` in python | 38,281,853 | <p>Shouldn't the return value for the <code>__enter__</code> method be <code>self</code> always. </p>
<p><a href="https://docs.python.org/2/reference/datamodel.html#context-managers" rel="nofollow">Python documentation</a> says :</p>
<blockquote>
<p><code>object.__enter__(self)</code>
Enter the runtime context re... | 0 | 2016-07-09T12:35:11Z | 38,281,942 | <p>Not if it makes sense to use an attribute of the instance as the context manager:</p>
<pre><code>class A:
def __init__(self, useful_obj):
self.useful_obj = useful_obj
def __enter__(self):
return self.useful_obj
def __exit__(self):
pass
with A(some_obj) as a:
# magic done impli... | 0 | 2016-07-09T12:45:35Z | [
"python"
] |
'super' object has no attribute 'clean_password1' | 38,281,860 | <p>I'm trying to reuse a code for registration form from my older project. The problem is that Django says that <code>UserCreationForm</code> hasn't attribute <code>clean_password1</code>.</p>
<p>Do you know where is the problem? I see that there is not such attribute in <code>UserCreationForm</code> but it worked bef... | 0 | 2016-07-09T12:36:12Z | 38,282,173 | <p>You can safely remove <code>clean_password2</code> - Django already validates if the passwords match (I assume you're using the current version for your new project). As for <code>clean_password1</code> I'd recommend to remove it too and read documentation on <a href="https://docs.djangoproject.com/en/1.9/topics/aut... | 0 | 2016-07-09T13:11:39Z | [
"python",
"django",
"django-forms",
"django-registration"
] |
'super' object has no attribute 'clean_password1' | 38,281,860 | <p>I'm trying to reuse a code for registration form from my older project. The problem is that Django says that <code>UserCreationForm</code> hasn't attribute <code>clean_password1</code>.</p>
<p>Do you know where is the problem? I see that there is not such attribute in <code>UserCreationForm</code> but it worked bef... | 0 | 2016-07-09T12:36:12Z | 38,282,238 | <p>There's no reason to call <code>super</code> inside a clean_field method; the field doesn't exist on the base class, so neither does the clean_field.</p>
| 0 | 2016-07-09T13:18:18Z | [
"python",
"django",
"django-forms",
"django-registration"
] |
How to replace string using RE group in python? | 38,281,928 | <p>I have a problem when using RE module in python: </p>
<pre><code>import re
url='http://list.xxx.com/0-20356-1-0-0-0-0-0-0-0-269036.html'
re_rule=re.compile('.+20356\-(\d{1,3})-0-0-0.+')
new_url=re_rule.sub('2 \1')
</code></pre>
<p>As I wish, the <strong>new_url</strong> would be '<a href="http://list.xxx.com/0... | 1 | 2016-07-09T12:44:19Z | 38,281,998 | <p>Given your example, why even bother using <code>re</code>?</p>
<pre><code>url = 'http://list.xxx.com/0-20356-1-0-0-0-0-0-0-0-269036.html'
new_url = url.replace('-1-', '-2-')
print(new_url)
</code></pre>
<p>produces what you're looking for:</p>
<pre><code>http://list.xxx.com/0-20356-2-0-0-0-0-0-0-0-269036.html
</c... | 1 | 2016-07-09T12:51:59Z | [
"python",
"regex"
] |
Error while using w, h = template.shape[::-1] | 38,282,000 | <p>I am getting an error:</p>
<pre><code>w, h = template.shape[::-1]
AttributeError: 'NoneType' object has no attribute 'shape'
</code></pre>
<p>My code:</p>
<pre><code>import cv2
import numpy as np
img_rgb = cv2.imread('opencv-template-matching-python-tutorial.jpg')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2... | -1 | 2016-07-09T12:52:15Z | 38,282,078 | <p>I'm not too familiar with <code>opencv</code>, but that error means that <code>cv2.imread('opencv-template-for-matching.jpg',0)</code> fails to read that file and thus returns <code>None</code>. </p>
<p>Make sure that this file exists and in the supported format.
From <code>imread</code>'s <a href="http://docs.open... | 2 | 2016-07-09T13:00:18Z | [
"python",
"opencv"
] |
Filter on diagonal geo coordinates | 38,282,024 | <p>I am trying to filter my file on geo coordinates to keep only coordinates located in Manhattan using Python and Folium.
I've tried setting my own limits:</p>
<pre><code>top_left = [40.806470, -73.973205]
bottom_left = [40.709729, -74.035690]
bottom_right = [40.696715, -73.992431]
top_right = [40.781518, -73.934066... | 0 | 2016-07-09T12:54:41Z | 38,282,102 | <p>Use can use shapely for that. <a href="https://pypi.python.org/pypi/Shapely" rel="nofollow">https://pypi.python.org/pypi/Shapely</a> . In fact, you can create polygons and other geospatial features with it. Potentially, you do not need any df. Here is a complete example using your polygon and random points. You do n... | 0 | 2016-07-09T13:02:59Z | [
"python",
"folium"
] |
Python CFFI - Unable to use formatted Python string as byte-array in function call | 38,282,126 | <p>I'm learning various ways of how to include code written in <code>C</code> to <code>Python</code> because I have an API for a Microchip device which is pretty...tedious to work with and I would like to make my life easier in the future by adding a <code>Python</code> wrapper for it which will allow me to test stuff ... | 0 | 2016-07-09T13:06:18Z | 38,293,154 | <p>In your C code, the <code>point_t</code> structure holds in <code>label</code> a <code>char *</code>, i.e. a pointer to some other place in memory. If you create 10 <code>point_t</code> structures, they hold pointers to 10 strings that are somewhere else in memory. You have to make sure that these 10 strings are k... | 1 | 2016-07-10T14:49:53Z | [
"python",
"c",
"python-cffi"
] |
Check if there are different characters that are written once | 38,282,132 | <p>I made a small script that opens a file, gets it's size and writes the size of the file in zeros or ones depending on what is needed.</p>
<pre><code>def firstDeletion(filepath, txt):
multiplier = getSize(filepath)
with open(filepath, "w") as text_file:
text_file.write(multiplier * txt)
</code></pre... | 1 | 2016-07-09T13:06:51Z | 38,282,241 | <p>If it's just a single character you are concerned about (not a word or a phrase that can be broken between two lines), then you were very close with your first attempt.</p>
<pre><code>def checkFile(file,phrase):
with open(file, 'r') as resultfile:
for line in resultfile:
if not all(char == p... | 2 | 2016-07-09T13:18:38Z | [
"python",
"python-3.x"
] |
Check if there are different characters that are written once | 38,282,132 | <p>I made a small script that opens a file, gets it's size and writes the size of the file in zeros or ones depending on what is needed.</p>
<pre><code>def firstDeletion(filepath, txt):
multiplier = getSize(filepath)
with open(filepath, "w") as text_file:
text_file.write(multiplier * txt)
</code></pre... | 1 | 2016-07-09T13:06:51Z | 38,282,351 | <pre><code>def checkFile(file,phrase):
with open(file, 'r') as resultfile:
for line in resultfile:
if (not phrase) in resultfile: #if found character different than phrase in resultfile
return False
else:
return True #No other char found
</code></pre>... | 0 | 2016-07-09T13:33:22Z | [
"python",
"python-3.x"
] |
Pandas: remove observations from a data frame based on mulitple columns | 38,282,305 | <p>I have a data frame and I need to delete certain observations from it based upon the values of other columns.</p>
<pre><code> cid date unemployment billsum id.thomas loansum feccanid amtsum
N00003147 2005.0 5.6 1.0 1336 2.0 S4TN00153 4.500
N00009082 ... | 1 | 2016-07-09T13:27:01Z | 38,282,449 | <p>try this:</p>
<pre><code>mask = (df['id.thomas'] == 1763) & (df['date'] >= 2008) & (df['date'] <= 2012)
df = df[~mask]
</code></pre>
<p>alternatively you can <a href="http://www.regentsprep.org/regents/math/geometry/gp1/negatecompound.htm" rel="nofollow">negate your condition</a>:</p>
<pre><code>df ... | 1 | 2016-07-09T13:42:39Z | [
"python",
"pandas",
"row"
] |
Python flask : No module named requests | 38,282,310 | <p>I'm having trouble using <code>requests</code> module in my flask app. I have two files <code>rest_server.py</code> and <code>independent.py</code> at same directory level. The <code>independent.py</code> uses <code>requests</code> module and it executes correctly if I directly run it. But when I import <code>indepe... | -3 | 2016-07-09T13:28:24Z | 38,282,632 | <h1>Why you get the "no module named ..." error</h1>
<p>Your two files have one big difference: rest_server.py includes a <em>shebang</em> line, while independent.py doesn't.</p>
<p>When you say you <em>directly execute</em> the file <code>independent.py</code>, you type <code>python independent.py</code> (I'm assumi... | 1 | 2016-07-09T14:02:58Z | [
"python",
"flask"
] |
Python flask : No module named requests | 38,282,310 | <p>I'm having trouble using <code>requests</code> module in my flask app. I have two files <code>rest_server.py</code> and <code>independent.py</code> at same directory level. The <code>independent.py</code> uses <code>requests</code> module and it executes correctly if I directly run it. But when I import <code>indepe... | -3 | 2016-07-09T13:28:24Z | 38,282,907 | <p>Whenever you do <code>pip install <package></code>, it installs the package to a certain location. Add that location to the list of <code>PATH</code>s mentioned in your <code>Environment Variables</code>, and your problem will be solved.</p>
| 0 | 2016-07-09T14:37:51Z | [
"python",
"flask"
] |
How to remove duplicates from a nested list based on the first element while prioritizing the length of the list? | 38,282,314 | <p>I have a list like this </p>
<pre><code>[[7, 6, 8], [1, 10], [3, 10], [7, 8], [7, 4], [9, 4], [5, 8], [9, 8]]
</code></pre>
<p>And I want the output to look something like this:</p>
<pre><code>[[7, 6, 8],[1, 10],[3, 10],[9, 4],[5, 8]]
</code></pre>
<p>Where the algorithm should remove duplicates based on the fir... | 1 | 2016-07-09T13:28:41Z | 38,282,401 | <p>You can use <code>collections.defaultdict()</code> in order to categorize your lists based on first item them choose the longer one using <code>max()</code> function with <code>len()</code> as it's key:</p>
<pre><code>>>> lst = [[7, 6, 8], [1, 10], [3, 10], [7, 8], [7, 4], [9, 4], [5, 8], [9, 8]]
>>&... | 1 | 2016-07-09T13:38:20Z | [
"python",
"list",
"python-3.x"
] |
How to remove duplicates from a nested list based on the first element while prioritizing the length of the list? | 38,282,314 | <p>I have a list like this </p>
<pre><code>[[7, 6, 8], [1, 10], [3, 10], [7, 8], [7, 4], [9, 4], [5, 8], [9, 8]]
</code></pre>
<p>And I want the output to look something like this:</p>
<pre><code>[[7, 6, 8],[1, 10],[3, 10],[9, 4],[5, 8]]
</code></pre>
<p>Where the algorithm should remove duplicates based on the fir... | 1 | 2016-07-09T13:28:41Z | 38,282,436 | <p>You can just sort your list by the length using <code>sorted(any_list, key=len)</code>.</p>
<p>Your code could look like this then:</p>
<pre><code>dict((x[0], x) for x in sorted(any_list, key=len)).values()
</code></pre>
<p>If you want to have a list in the end, simply pass the result into <code>list()</code>.</p... | 2 | 2016-07-09T13:41:21Z | [
"python",
"list",
"python-3.x"
] |
List Comprehension - Python 2.7 | 38,282,356 | <p>I tried to convert the following into a list comprehension, but its giving me an invalid syntax error. I tried a few solutions such as zipping the combinations, but i cant get it to work. </p>
<p>I'm obviously missing some fundamental understanding of what i can and cannot do with list comprehensions. Can someone ... | 0 | 2016-07-09T13:33:31Z | 38,282,421 | <p>You have two issues here.</p>
<p>Firstly, you need to wrap all your elements into a list:</p>
<pre><code>[print(c) for c in [(x,y,z), (x,z,y), (y,x,z), (y,z,x), (z,x,y), (z,y,x)]]
</code></pre>
<p>Secondly, <code>print</code> is a statement in Python 2, not a function, so can't be used in a list comprehension as ... | 3 | 2016-07-09T13:40:07Z | [
"python",
"python-2.7",
"list-comprehension"
] |
List Comprehension - Python 2.7 | 38,282,356 | <p>I tried to convert the following into a list comprehension, but its giving me an invalid syntax error. I tried a few solutions such as zipping the combinations, but i cant get it to work. </p>
<p>I'm obviously missing some fundamental understanding of what i can and cannot do with list comprehensions. Can someone ... | 0 | 2016-07-09T13:33:31Z | 38,282,453 | <p>Doing this as a list comprehension is sort of odd since you are creating a list filled with the return value of <code>print</code> which is <code>None</code>. If you really want to do it this way:</p>
<pre><code>def myfun(x, y, z):
[print(c) for c in [(x,y,z), (x,z,y), (y,x,z), (y,z,x), (z,x,y), (z,y,x)]]
</co... | 3 | 2016-07-09T13:42:55Z | [
"python",
"python-2.7",
"list-comprehension"
] |
List Comprehension - Python 2.7 | 38,282,356 | <p>I tried to convert the following into a list comprehension, but its giving me an invalid syntax error. I tried a few solutions such as zipping the combinations, but i cant get it to work. </p>
<p>I'm obviously missing some fundamental understanding of what i can and cannot do with list comprehensions. Can someone ... | 0 | 2016-07-09T13:33:31Z | 38,283,013 | <h1>That's not the point of list comprehensions...</h1>
<p>A list comprehension is intended/useful to <strong>create a new list</strong> of objects, without having to explicitly use a traditional <em>for</em> loop. </p>
<p>From Python documentation on <a href="https://docs.python.org/2/tutorial/datastructures.html#li... | 1 | 2016-07-09T14:48:56Z | [
"python",
"python-2.7",
"list-comprehension"
] |
Multiple Label Frame, tkinter GUI did not match the specific row and column | 38,282,485 | <p>I create 2 frame in column 1 in my program, the first one is ok, i use sticky = N,it position properly at the top, but for the next frame, it does not appear at the bottom of my program, here is the </p>
<p>[<a href="http://i.stack.imgur.com/01sSf.jpg]" rel="nofollow">http://i.stack.imgur.com/01sSf.jpg]</a></p>
<p... | -1 | 2016-07-09T13:47:22Z | 38,334,331 | <p>The frame is appearing exactly where you tell it to appear. You placed "Case suggestion ..." in row 8, which means it must appear below row 0. However, row 0 is very tall, which means anything below it will be off the visible part of the screen since you forced the screen to be a specific size and don't allow it to ... | 0 | 2016-07-12T16:24:31Z | [
"python",
"user-interface",
"tkinter"
] |
How to scrape the lowest price of hotel of a given area from kayak.com? | 38,282,488 | <p>So i have to scrape the least deal of hotel from this metasearch engine. But unable to to do that. All i'm getting is empty list while i'm finding elements with classes. Though request is fetching the correct html that i want. I do not know what to do?
Here is my code:</p>
<pre><code> # -*- coding: utf-8 -*-
"""... | 1 | 2016-07-09T13:47:52Z | 38,282,525 | <p>You are using <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors" rel="nofollow">CSS selectors</a>, but passing them to <code>find_all()</code> method instead of <code>select()</code>:</p>
<pre><code>hotel_name = soup.select(".title")
price_elems = soup.select(".price")
</code></pre>
<p>... | 2 | 2016-07-09T13:52:22Z | [
"python",
"python-2.7",
"web-scraping",
"request",
"beautifulsoup"
] |
How can i check that request is not empty | 38,282,547 | <p>User press search button and search field is empty, He gets all the articles on the page.
code:</p>
<pre><code>class SearchResultsView(ArticlesView):
def get_queryset(self, request):
if request.POST.has_key('search'):
return self.model.objects.filter(
Q(title__icontains=request.POST['search... | 0 | 2016-07-09T13:54:12Z | 38,282,573 | <p>Get the <code>search</code> parameter and check if it is empty or not:</p>
<pre><code>search = request.POST.get('search')
if search:
return self.model.objects.filter(
Q(title__icontains=search) |
Q(content__icontains=search)
).distinct()
</code></pre>
<p><code>get()</code> would return ... | 3 | 2016-07-09T13:56:47Z | [
"python",
"django"
] |
linear interpolation between two data points | 38,282,659 | <p>I have two data points <code>x</code> and <code>y</code>:</p>
<pre><code> x = 5 (value corresponding to 95%)
y = 17 (value corresponding to 102.5%)
</code></pre>
<p>No I would like to calculate the value for <code>xi</code> which should correspond to 100%. </p>
<pre><code> x = 5 (value corresponding to 95%)
x... | 2 | 2016-07-09T14:07:01Z | 38,282,695 | <p>is that what you want?</p>
<pre><code>In [145]: s = pd.Series([5, np.nan, 17], index=[95, 100, 102.5])
In [146]: s
Out[146]:
95.0 5.0
100.0 NaN
102.5 17.0
dtype: float64
In [147]: s.interpolate(method='index')
Out[147]:
95.0 5.0
100.0 13.0
102.5 17.0
dtype: float64
</code></pre>
| 5 | 2016-07-09T14:11:35Z | [
"python",
"pandas",
"dataframe",
"interpolation"
] |
linear interpolation between two data points | 38,282,659 | <p>I have two data points <code>x</code> and <code>y</code>:</p>
<pre><code> x = 5 (value corresponding to 95%)
y = 17 (value corresponding to 102.5%)
</code></pre>
<p>No I would like to calculate the value for <code>xi</code> which should correspond to 100%. </p>
<pre><code> x = 5 (value corresponding to 95%)
x... | 2 | 2016-07-09T14:07:01Z | 38,282,922 | <p>We can easily plot this on a graph without Python:</p>
<p><a href="http://i.stack.imgur.com/PW6fy.png" rel="nofollow"><img src="http://i.stack.imgur.com/PW6fy.png" alt=""></a></p>
<p>This shows us what the answer should be (13).</p>
<p>But how do we calculate this? First, we find the gradient with this:</p>
<p><... | 4 | 2016-07-09T14:38:55Z | [
"python",
"pandas",
"dataframe",
"interpolation"
] |
Inconsistent implementation of collections.abc | 38,282,684 | <p>I'm trying to understand <a href="https://hg.python.org/cpython/file/3.5/Lib/_collections_abc.py" rel="nofollow"><code>collections.abc</code></a> source code.</p>
<p>Let's take a look on <code>Hashable</code> class' <code>__subclasshook__</code> implementation:</p>
<pre><code>@classmethod
def __subclasshook__(cls,... | 1 | 2016-07-09T14:10:10Z | 38,283,215 | <p>The <a href="https://docs.python.org/3.5/reference/datamodel.html#object.__hash__" rel="nofollow"><code>__hash__</code> protocol</a> explicitly allows flagging a class as unhashable by setting <code>__hash__ = None</code>.</p>
<blockquote>
<p>If a class [...] wishes to suppress hash support, it should include <co... | 3 | 2016-07-09T15:12:45Z | [
"python",
"python-3.x",
"abc"
] |
Right way to wait for a link to click in selenium | 38,282,708 | <p>I have a web page with the following:</p>
<pre><code><a id="show_more" class="friends_more" onclick="Friends.showMore(-1)"
style="display: block;">
<span class="_label">Show More Friends</span><span class="friends_more_icon"></... | 2 | 2016-07-09T14:13:04Z | 38,282,758 | <p>Try to replace </p>
<pre><code>WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, id_text)))
</code></pre>
<p>with </p>
<pre><code>WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.ID, id_text)))
</code></pre>
| 0 | 2016-07-09T14:19:16Z | [
"javascript",
"python",
"python-3.x",
"selenium"
] |
Why does my script searching for a certain word in a database always print out "None" as a result? I am using the mysql.connector for python34 | 38,282,726 | <p>My code: </p>
<pre><code>import mysql.connector as sqlc
cnx = sqlc.connect(user='', password='',host='', database='dictionary')
cursor = cnx.cursor()
sql = "SELECT * FROM dictionary"
print(cursor.execute(sql))
</code></pre>
<p>As a result I am allways getting None. It doesnt matter if I am searching for a sp... | 0 | 2016-07-09T14:16:28Z | 38,282,782 | <p><code>cursor.execute(sql)</code> executes the query; to get the results, use <code>cursor.fetchall()</code>. This will return a list with all the results, and will return an empty list if no results are retrieved. You can loop through this list normally to print out the results. </p>
<p>Check out <a href="https://d... | 1 | 2016-07-09T14:21:50Z | [
"python",
"mysql"
] |
Tweepy Streaming filter fields | 38,282,733 | <p>I've this python code that retrieves data from Twitter with Tweepy and Streming APIs and it stops when has found 1000 results (that is 1000 tweets data).
It works well but the problem is that when I try to run it on PyCharm, it cuts part of the results. Since the code returns all the data of a tweets (ID, Text, Auth... | 0 | 2016-07-09T14:16:52Z | 38,283,145 | <p>I was able to run this on PyCharm without any issues for 1000 tweets. So try running this on another computer or investigate if you have issues with your existing system. </p>
<p>The result is a python dictionary, so all you need to access individual elements is like below</p>
<pre><code>for tweet in iterator:
... | 0 | 2016-07-09T15:04:52Z | [
"python",
"python-3.x",
"twitter",
"tweepy"
] |
I have to call one function and get my output | 38,282,843 | <p>I am having one function:</p>
<pre><code>def divisible(num):
if num%9 == 0:
print("true")
else:
print("false")
</code></pre>
<p>By using this function I have to get the output of divisible by 9 numbers between 1 and 100. How can I get that? I am very new to python, can any one help me to so... | 0 | 2016-07-09T14:29:14Z | 38,282,867 | <p>Your currently <strong>printing</strong> <code>true</code> and <code>false</code> as values from your function. You need to <code>return</code> them.</p>
<pre><code>def divisible(num):
if num % 9 == 0:
return 'true'
else:
return 'false
</code></pre>
| 1 | 2016-07-09T14:31:48Z | [
"python"
] |
I have to call one function and get my output | 38,282,843 | <p>I am having one function:</p>
<pre><code>def divisible(num):
if num%9 == 0:
print("true")
else:
print("false")
</code></pre>
<p>By using this function I have to get the output of divisible by 9 numbers between 1 and 100. How can I get that? I am very new to python, can any one help me to so... | 0 | 2016-07-09T14:29:14Z | 38,282,877 | <p>Your <code>divisible()</code> function does not <em>return</em> anything. Writing output to your console (with <code>print()</code>) is not the same as returning a result to the caller.</p>
<p>Since your function doesn't return a value, Python sets the return value to <code>None</code>. <code>None == 'true'</code> ... | 3 | 2016-07-09T14:33:45Z | [
"python"
] |
I have to call one function and get my output | 38,282,843 | <p>I am having one function:</p>
<pre><code>def divisible(num):
if num%9 == 0:
print("true")
else:
print("false")
</code></pre>
<p>By using this function I have to get the output of divisible by 9 numbers between 1 and 100. How can I get that? I am very new to python, can any one help me to so... | 0 | 2016-07-09T14:29:14Z | 38,282,893 | <p>You can also get the list of numbers through <code>filter</code>:</p>
<pre><code>lst = list(filter(lambda x: x%9, range(0,100)))
print(set(range(100)) - set(lst)
# {0, 99, 36, 72, 9, 45, 81, 18, 54, 90, 27, 63}
final_list = list(set(range(100)) - set(lst)).sort() # to sort it
</code></pre>
| 0 | 2016-07-09T14:35:28Z | [
"python"
] |
I have to call one function and get my output | 38,282,843 | <p>I am having one function:</p>
<pre><code>def divisible(num):
if num%9 == 0:
print("true")
else:
print("false")
</code></pre>
<p>By using this function I have to get the output of divisible by 9 numbers between 1 and 100. How can I get that? I am very new to python, can any one help me to so... | 0 | 2016-07-09T14:29:14Z | 38,282,905 | <p>You should return instead of print.</p>
<pre><code>def divisible(num):
if num%9 == 0:
return "true"
else:
return "false"
for i in range(100):
j = divisible(i)
if j == 'true':
print(i)
</code></pre>
| 1 | 2016-07-09T14:37:24Z | [
"python"
] |
I have to call one function and get my output | 38,282,843 | <p>I am having one function:</p>
<pre><code>def divisible(num):
if num%9 == 0:
print("true")
else:
print("false")
</code></pre>
<p>By using this function I have to get the output of divisible by 9 numbers between 1 and 100. How can I get that? I am very new to python, can any one help me to so... | 0 | 2016-07-09T14:29:14Z | 38,291,635 | <p>Use:</p>
<pre><code>print list(x for x in range(1,101) if not x%9)
</code></pre>
<p>Which will get you:</p>
<pre><code>[9, 18, 27, 36, 45, 54, 63, 72, 81, 90, 99]
</code></pre>
| 0 | 2016-07-10T12:01:21Z | [
"python"
] |
How turn this basic list into a more structured one? | 38,282,870 | <p>I have a fairly basic list as the following : </p>
<pre><code>listOne = [parentOneObject,childOne,childTwo,childThree,parentTwoObject,childOne,childTwo...]
</code></pre>
<p>Sementically, this list contains parents and their child next to them, each iteml is this list is an object (An HTML Element, in reality, but ... | 0 | 2016-07-09T14:32:19Z | 38,282,913 | <p>You need to have a way to distinguish parents from children. Then all you have to do is test for that in a loop:</p>
<pre><code>listTwo = []
entry = None
for element in listOne:
if isparent(element): # put your test here
entry = {'parent': element, 'children': []}
listTwo.append(entry)
else... | 2 | 2016-07-09T14:38:23Z | [
"python",
"list",
"loops"
] |
Ethernet connection crashes when using python socket | 38,282,903 | <p>Ok so I have a UDP socket setup between two computers. One computer gets coordinates from a joystick and sends them as a array over the socket. At the other end the array is received and then the value is sent to a servo. The problem is, is that this works great for about 10 seconds and then the entire connections c... | 0 | 2016-07-09T14:36:54Z | 38,283,439 | <p>I see you have sleeps but they don't match. The sender is sleeping 0.05 seconds and your receiver is sleeping 1 second. This is probably creating a buffer overflow.</p>
| 0 | 2016-07-09T15:36:03Z | [
"python",
"sockets",
"connection",
"servo"
] |
How to get text object from a html table using selenium python | 38,282,923 | <p>I have a part of html file as below</p>
<pre><code><div><pre> <b>Home:</b> 28-12 <b>Road:</b> 23-16 <b>ExtrInn:</b> 2-5
<b>vsRHP:</b> 38-18 <b>vsLHP:</b> 13-10 <b>1-Run:</b> 17-5
<b>vsEast:</b> 12-8 &... | 0 | 2016-07-09T14:38:58Z | 38,283,536 | <p>That HTML is... something. The text you want isn't inside of any localized tag. You are going to have to grab all the text inside the outer <code>DIV</code> to find what you want. You can use regex or just parse it. The code below should be close.</p>
<pre><code>alltext = driver.find_element_by_tag_name("div").text... | 0 | 2016-07-09T15:47:02Z | [
"python",
"html",
"selenium",
"xpath"
] |
python call method from outside the class | 38,282,935 | <p>how can I in python call method from outside which is situated inside the class?</p>
<pre><code>class C():
def write():
print 'Hello worl'
</code></pre>
<p>I thought that <code>>>> x = C</code> and <code>>>> x.write()</code> must work but it doesn't.</p>
| 0 | 2016-07-09T14:40:15Z | 38,282,971 | <p>Dont you need to have self in your definition?</p>
<pre><code>class C(object):
def write(self):
print 'Hello world'
</code></pre>
<p>Now it should be fine, i.e. </p>
<pre><code>x = C()
x.write()
</code></pre>
| 3 | 2016-07-09T14:43:24Z | [
"python",
"class"
] |
python call method from outside the class | 38,282,935 | <p>how can I in python call method from outside which is situated inside the class?</p>
<pre><code>class C():
def write():
print 'Hello worl'
</code></pre>
<p>I thought that <code>>>> x = C</code> and <code>>>> x.write()</code> must work but it doesn't.</p>
| 0 | 2016-07-09T14:40:15Z | 38,283,138 | <p>When you where defining x, you forgot to put the parantheses after the class, this made so x literally was equals to the class C and not the object C.</p>
<pre><code>class C:
def write():
print "Hello worl"
x = C() # Notice the parantheses after the class name.
x.write() # This will output Hello worl.
... | 0 | 2016-07-09T15:04:03Z | [
"python",
"class"
] |
PyQt button start another script from another file | 38,282,978 | <p>How can i start a separate script in a separate file using PyQt like a button signal or something.</p>
<pre><code>from everywhere* import everthing*
def bJeff(driver):
...
def bLexi(driver):
...
def browser(url, id, user1, parolauser1, user2, parolauser2):
...
#starting 2 browsers and passing the... | 0 | 2016-07-09T14:44:25Z | 38,283,009 | <p>There are 2 ways to do this.</p>
<ol>
<li><p><code>import file</code> and call the function as <code>file.functionName()</code>. Highly recommended. Note that if your file is called <code>file.py</code>, your <code>import</code> should <em>not</em> include the <code>.py</code> extension at the end.</p></li>
<li><p>... | 1 | 2016-07-09T14:48:36Z | [
"python",
"pyqt",
"pyqt4"
] |
PyQt button start another script from another file | 38,282,978 | <p>How can i start a separate script in a separate file using PyQt like a button signal or something.</p>
<pre><code>from everywhere* import everthing*
def bJeff(driver):
...
def bLexi(driver):
...
def browser(url, id, user1, parolauser1, user2, parolauser2):
...
#starting 2 browsers and passing the... | 0 | 2016-07-09T14:44:25Z | 38,283,018 | <p>You can do it by exactly that: using signals and slots. Signals can be emitted and received from anywhere and are thread safe. You can import your foreign script/function/whatever you need to run in the separate file, and connect your button's <code>clicked()</code> signal to that function. For example, if you need ... | 2 | 2016-07-09T14:49:10Z | [
"python",
"pyqt",
"pyqt4"
] |
PyQt button start another script from another file | 38,282,978 | <p>How can i start a separate script in a separate file using PyQt like a button signal or something.</p>
<pre><code>from everywhere* import everthing*
def bJeff(driver):
...
def bLexi(driver):
...
def browser(url, id, user1, parolauser1, user2, parolauser2):
...
#starting 2 browsers and passing the... | 0 | 2016-07-09T14:44:25Z | 38,361,420 | <pre><code>#If your are not expecting this answer, sorry.
def button_OutsideScript (self) :
import OutsideScript_Name as osScript
reload (osScript)
#If you have class inside the Outside Script use below line
osScript.className ()
</code></pre>
| 0 | 2016-07-13T20:48:43Z | [
"python",
"pyqt",
"pyqt4"
] |
How to use % symbol correctly | 38,283,196 | <p>I have searched on the google but I did not find correct answer</p>
<p>I have the following code:</p>
<pre><code>print("i have %d years old" % (15))
</code></pre>
<p>Is there a perfect references to learn how to use above way fully ?</p>
| -5 | 2016-07-09T15:10:58Z | 38,283,251 | <p>"%" is actually the modulus operator but it can also be used to format strings.
Learn more about it here: <a href="http://www.informit.com/articles/article.aspx?p=28790&seqNum=2" rel="nofollow">link</a></p>
| -1 | 2016-07-09T15:16:09Z | [
"python",
"python-3.x",
"string-formatting"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.