title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Python selenium firefox browser launch error | 39,305,226 | <p>I am trying to launch Firefox (48.0.2) using Selenium with Python 3.5 on my mac using the following code:</p>
<pre><code>from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://bbc.co.uk')
</code></pre>
<p>However, Firefox launches without going to the specified webpage and times out with ... | 0 | 2016-09-03T09:11:20Z | 39,564,083 | <p>I had the same issue and I solved it. Firefox 48+ doesn't support <code>webdriver.Firefox()</code>. </p>
<p>My environment:<br>
MacOS 10.11.6, python 3.5.2, firefox 48.0.2, Django 1.10, selenium 2.53.6 </p>
<pre><code>from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import De... | 0 | 2016-09-19T01:08:43Z | [
"python",
"selenium",
"firefox"
] |
Using re.sub capture groups | 39,305,278 | <p>Apologies for the simple question but Im struggling with this:</p>
<pre><code>str = 'EURGBP'
print (re.sub(r'\EUR(GBP)', r'\1', str))
</code></pre>
<p>returns</p>
<pre><code>GBP
</code></pre>
<p>but</p>
<pre><code>print (re.sub(r'\(EUR)(GBP)', r'\2,\1', str))
</code></pre>
<p>gives me <code>error: unbalanced ... | 1 | 2016-09-03T09:17:34Z | 39,305,298 | <p>Don't escape the paren as <code>\(</code> means you are literally searching for a <code>(</code> in the string so the closing <code>)</code> has no matching opening <code>(</code>, escaping the <code>E</code> worked as you were looking for the literal <code>E</code>, also just use <code>r'\2\1'</code> unless you wan... | 1 | 2016-09-03T09:20:21Z | [
"python"
] |
Destroying a PyCapsule object | 39,305,286 | <p>According to <a href="https://docs.python.org/3.4/c-api/capsule.html?highlight=capsule" rel="nofollow">documentation</a>, the third argument to <code>PyCapsule_New()</code> can specify a destructor, which I assume should be called when the capsule is destroyed.</p>
<pre><code>void mapDestroy(PyObject *capsule) {
... | 5 | 2016-09-03T09:18:15Z | 39,542,417 | <p><code>Py_BuildValue("O", thingy)</code> will just increment the refcount for <code>thingy</code> and return it â the docs say that it returns a ânew referenceâ but that is not quite true when you pass it an existing <code>PyObject*</code>. </p>
<p>If these functions of yours â the ones in your question, tha... | 0 | 2016-09-17T02:51:09Z | [
"python",
"c",
"cpython"
] |
Sorting based on individual columns of lists in a dictionary | 39,305,356 | <p>I have a dictionary of lists in the following format.</p>
<pre><code>b =
{'a': [1, 1, 1],
'c': [1, 0, 0],
'b': [1, 0, 1],
'e': [0, 0, 1],
'd': [0, 0, 0],
'g': [0, 1, 1],
'f': [0, 1, 0],
'h': [1, 1, 0]
}
</code></pre>
<p>What I am looking to do is to sort the lists and dis... | 0 | 2016-09-03T09:27:23Z | 39,305,400 | <p>This:</p>
<pre><code>sorted(b.items(), key=lambda e:e[1])
</code></pre>
<p>Works because it uses the entirety of each list as the key for comparison. Python knows how to "lexicographically" compare lists by default, meaning it compares the first element, then if those are equal it proceeds to the next element. J... | 1 | 2016-09-03T09:33:08Z | [
"python",
"sorting",
"dictionary"
] |
Sorting based on individual columns of lists in a dictionary | 39,305,356 | <p>I have a dictionary of lists in the following format.</p>
<pre><code>b =
{'a': [1, 1, 1],
'c': [1, 0, 0],
'b': [1, 0, 1],
'e': [0, 0, 1],
'd': [0, 0, 0],
'g': [0, 1, 1],
'f': [0, 1, 0],
'h': [1, 1, 0]
}
</code></pre>
<p>What I am looking to do is to sort the lists and dis... | 0 | 2016-09-03T09:27:23Z | 39,305,403 | <pre><code>sorted(b.items(), key=lambda e:e[1])
</code></pre>
<p>works because the lambda is returning the whole lists, e.g. <code>[1, 1, 1]</code>, <code>[1, 0, 0]</code>. Python's default rule for sorting lists is exactly what you need, it will sort lists by the first 'column' or entry in the list, if two lists have... | 1 | 2016-09-03T09:33:26Z | [
"python",
"sorting",
"dictionary"
] |
what is wrong with my code in my continous 1's python program? | 39,305,428 | <p>so i am a newbie so be easy on me i was just trying to solve a problem in hackerrank.com
in which i must get the max number of continous 1's in a binary representation of number and i made it but it is not working Heres the Code</p>
<p>the updated code is below</p>
<p><div class="snippet" data-lang="js" data-hide=... | -3 | 2016-09-03T09:36:53Z | 39,305,534 | <p>You're close. I'll annotate your mistakes to point you in the right direction,</p>
<pre><code>import statistics
def one_seq(n):
main = []
number = str("{0:b}".format(n))
i = 0
sub_main = []
while i != len(number):
if number[i] == 1: # you want to check against the string '1' not the... | 1 | 2016-09-03T09:48:07Z | [
"python"
] |
embed python in c++, crashes on "import shutil" | 39,305,523 | <p>I have a complete example on embedding python in c++ below. I compile/link it on Linux against Python 2.7.</p>
<p>It takes one parameter (a filename) which is then loaded and executed.</p>
<p>All this basically works but if in the code there is:
import shutils</p>
<p>Then executing the code fails with a bus erro... | 0 | 2016-09-03T09:47:20Z | 39,305,657 | <p>May be it is related to GIL problem, try this: <a href="https://docs.python.org/3/c-api/init.html#non-python-created-threads" rel="nofollow">https://docs.python.org/3/c-api/init.html#non-python-created-threads</a></p>
| 0 | 2016-09-03T10:00:58Z | [
"python",
"c++",
"python-2.7",
"embed"
] |
embed python in c++, crashes on "import shutil" | 39,305,523 | <p>I have a complete example on embedding python in c++ below. I compile/link it on Linux against Python 2.7.</p>
<p>It takes one parameter (a filename) which is then loaded and executed.</p>
<p>All this basically works but if in the code there is:
import shutils</p>
<p>Then executing the code fails with a bus erro... | 0 | 2016-09-03T09:47:20Z | 39,358,193 | <p>I found 2 errors in my code above, one is that app_methods has no end entry that tells python where to stop interpreting the list.</p>
<p>The other one is that it is really necessary to call PyType_Ready(&AppType). I used the code above before and back then (I think with Python 2.6) using PyType_Ready() was cr... | 0 | 2016-09-06T21:35:53Z | [
"python",
"c++",
"python-2.7",
"embed"
] |
Ending a Python TCP connection | 39,305,686 | <p>I'm new to socket programming and currently trying to learn it using Python</p>
<p>Currently I'm confused over when a receiving application knows when the sending application finished sending data.</p>
<p>For example, in Python, reading from a TCP socket is done using </p>
<pre><code>socket.recv(bufsize [, flags]... | 0 | 2016-09-03T10:05:02Z | 39,306,398 | <p>buffer will return an empty array only if the client closes the connection.</p>
<p>If the client sends nothing, since TCP call is blocking in your case, the program stays blocked forever on <code>recv</code> until data arrives or connection is closed (in which case data arrives empty).</p>
<p>(It's the same thing ... | 0 | 2016-09-03T11:28:29Z | [
"python",
"sockets",
"networking",
"tcp"
] |
Read file into dataframe spliting the text after the first word in python | 39,305,748 | <p>I have a file of strings <code>file.txt</code>, where the first word is a class name and the rest is a description, like the following:</p>
<pre><code>n01440764 tench, Tinca tinca
n01443537 goldfish, Carassius auratus
n01484850 great white shark, white shark, man-eater, man-eating shark, Carcharodon carcharias
</co... | 1 | 2016-09-03T10:13:11Z | 39,306,040 | <p>You could do:</p>
<pre><code>df = pd.read_csv(data, sep='\s{2,}', engine='python', names=['col'])
df['class'] = df['col'].str.split().apply(lambda x: x[0])
# Splitting on first occurence of whitespace
df['description'] = df['col'].str.join('').apply(lambda x: x.split(' ',1)[1])
del(df['col'])
print (df)
c... | 1 | 2016-09-03T10:45:27Z | [
"python",
"pandas",
"dataframe"
] |
matplotlib.use required before other imports clashes with pep8. Ignore or fix? | 39,305,810 | <p>I have a pythonscript that starts like this:</p>
<pre><code>#!/usr/bin/env python
import matplotlib
matplotlib.use("Agg")
from matplotlib.dates import strpdate2num
import numpy as np
import pylab as pl
from cmath import rect, phase
</code></pre>
<p>It works like a charm, but my editor complains: <code>E402 module... | 0 | 2016-09-03T10:20:19Z | 39,316,470 | <p>The solution depends on the <code>linter</code> that is being used. </p>
<p>In my case I am using <code>pylama</code> </p>
<p>The manual for this <code>linter</code> suggests adding <code># noqa</code> to the end of a line containing an error you wish to suppress.</p>
<p>Other linters will have different mechanis... | 0 | 2016-09-04T11:33:58Z | [
"python",
"matplotlib",
"pep8"
] |
Can I scrape the raw data from highcharts.js? | 39,305,877 | <p>I want to scrape the data from a page that shows a graph using <code>highcharts.js</code>, and thus I finished to parse all the pages to get to the <a href="http://www.worldweatheronline.com/brussels-weather-averages/be.aspx" rel="nofollow">following page</a>. However, the last page, the one that displays the datase... | 1 | 2016-09-03T10:27:27Z | 39,306,382 | <p>The data is in a script tag. You can get the script tag using bs4 and a regex. You could also extract the data using a regex but I like using <a href="https://github.com/scrapinghub/js2xml" rel="nofollow">/js2xml</a> to parse js functions into a xml tree:</p>
<pre><code>from bs4 import BeautifulSoup
import requests... | 1 | 2016-09-03T11:26:47Z | [
"javascript",
"python",
"highcharts",
"web-scraping",
"beautifulsoup"
] |
python lib for custom hash function | 39,305,939 | <p>I need a hash function to take a sequence of decimal numbers and return a decimal number as hash value.</p>
<p>for example:</p>
<pre><code>>> def my_simple_hash(*args):
return reduce(lambda x1, x2: 2*x1 + x2, args)
>>> my_simple_hash(1,3,4)
14
>>> my_simple_hash(1,4,3)
15
>>>... | 0 | 2016-09-03T10:33:13Z | 39,306,163 | <p>If you just want to hash a number sequence you can do</p>
<pre><code>def my_hash(*args):
return hash(args)
</code></pre>
<p>which returns the <a href="https://docs.python.org/3/library/functions.html#hash" rel="nofollow">hash</a> (for the current run of the program) of the args-tuple (<code>hash</code> is fast... | 1 | 2016-09-03T11:01:40Z | [
"python"
] |
openshift is looking for 'wsgi' application, I don't want 'wsgi' | 39,305,964 | <p>I don't know if you know about this website (as I can't read your mind), but <code>openshift</code> is it. It is a web-hosting website. You can use <code>python</code> or whatever for server-side.</p>
<p>The problem is <code>openshift</code> is looking for a <code>wsgi</code> application. But I am using <code>webso... | 0 | 2016-09-03T10:37:13Z | 39,307,124 | <p>Put your application in <code>app.py</code>. This will allow you to run whatever you want. See:</p>
<ul>
<li><a href="http://blog.dscpl.com.au/2015/08/running-async-web-applications-under.html" rel="nofollow">http://blog.dscpl.com.au/2015/08/running-async-web-applications-under.html</a></li>
</ul>
| 2 | 2016-09-03T12:54:41Z | [
"python",
"openshift",
"tornado",
"redhat"
] |
Plotting particles positions over time | 39,306,175 | <p>I have drawn one position(x,y,z) of N particles in an enclosed volume.</p>
<pre><code>x[i] = random.uniform(a,b) ...
</code></pre>
<p>I also found the constant velocity(vx,vy,vz) of the N particles.</p>
<pre><code>vx[i] = random.gauss(mean,sigma) ...
</code></pre>
<p>Now I want to find the position of the N(=100... | 0 | 2016-09-03T11:02:35Z | 39,307,006 | <p>To find the position of the particles at a given time you can use the following code:</p>
<pre><code>import numpy as np
# assign random positions in the box 0,0,0 to 1,1,1
x = np.random.random((100,3))
# assign random velocities in the range around 0
v = np.random.normal(size=(100,3))
# define function to project... | 0 | 2016-09-03T12:42:29Z | [
"python",
"simulation",
"particles"
] |
using len() in Pandas dataframe | 39,306,229 | <p>This is the look of my <code>dataframe</code>:</p>
<p><img src="http://i.stack.imgur.com/9C22C.png" alt="dataframe">
and I want to list a list of senators whose surname is more than 9 characters long</p>
<p>So I think the code should be like this:</p>
<pre><code>df[len(df.Surname) >9 ]
</code></pre>
<p>but th... | 2 | 2016-09-03T11:09:13Z | 39,306,330 | <p>You want that <code>len</code> function to work on strings but you passed a Series. It returns a single value that shows the length of that series. Therefore, <code>len(df['Surname']) > 9</code> returns a True or False. In return, <code>df[len(df['Surname'] > 9]</code> is evaluated as <code>df[True]</code> or ... | 4 | 2016-09-03T11:21:40Z | [
"python",
"pandas",
"dataframe"
] |
using len() in Pandas dataframe | 39,306,229 | <p>This is the look of my <code>dataframe</code>:</p>
<p><img src="http://i.stack.imgur.com/9C22C.png" alt="dataframe">
and I want to list a list of senators whose surname is more than 9 characters long</p>
<p>So I think the code should be like this:</p>
<pre><code>df[len(df.Surname) >9 ]
</code></pre>
<p>but th... | 2 | 2016-09-03T11:09:13Z | 39,306,524 | <p>Have a look at the python <a href="https://docs.python.org/3.4/library/functions.html#filter" rel="nofollow">filter</a> function. It does exactly what you want.</p>
<pre><code>df = [
{"Surname": "Bullock-ish"},
{"Surname": "Cash"},
{"Surname": "Reynolds"},
]
longnames = list(filter(lambda s: len(s["Surn... | 0 | 2016-09-03T11:44:23Z | [
"python",
"pandas",
"dataframe"
] |
Efficiently retrieve data (all in one batch ideally) with mongengine in Python 3 | 39,306,369 | <p>Let's say I have class User which inherits from the Document class (I am using Mongoengine). Now, I want to retrieve all users signed up after some timestamp. Here is the method I am using:</p>
<pre><code>def get_users(cls, start_timestamp):
return cls.objects(ts__gte=start_timestamp)
</code></pre>
<p>1000 doc... | 0 | 2016-09-03T11:25:07Z | 39,325,324 | <p>As you suggest there is no way that it should take 3 seconds to run this query. However, the issue is not going to be the performance of the pymongo driver, some things to consider:</p>
<ul>
<li>Make sure that the <code>ts</code> field is included in the <a href="http://mongoengine-odm.readthedocs.io/guide/defining... | 2 | 2016-09-05T07:01:50Z | [
"python",
"mongodb",
"mongoengine"
] |
Using variables to insert | 39,306,469 | <p>I am new to cassandra and trying to insert in Cassandra keyspace using Python. I have a table mytablecassandra created with cql:</p>
<pre><code>cqlsh:mykeyspace>>CREATE TABLE mytablecassandra(user text PRIMARY KEY, friendlist list<text>);
</code></pre>
<p>Here I read a text file and have variables
<cod... | 0 | 2016-09-03T11:37:59Z | 39,306,610 | <p>Your strings don't get expanded in place that way, nor is it really the recommended way (that way lies SQL injection attacks often). Instead you should make your query string have place holders for the values like</p>
<pre><code>CQLString = "INSERT INTO mytablecassandra (user, friendlist) VALUES (%s,%s)"
</code></... | 1 | 2016-09-03T11:55:53Z | [
"python",
"cassandra",
"insert"
] |
Upload image to S3 with python webapp2 | 39,306,568 | <p>I want to upload the image to Amazon S3. I am using webapp2 python. After some exploration i find out that boto could be useful to upload the images to S3. I installed the boto but when i import it the following error occurred:</p>
<pre><code> File "C:\Program Files (x86)\Google\google_appengine\google\appengine\t... | 0 | 2016-09-03T11:49:38Z | 39,309,089 | <p>Your code seems to have a dependency on the <a href="https://docs.python.org/2/library/_winreg.html" rel="nofollow">_winreg</a> module, as evinced by the error message</p>
<blockquote>
<p>ImportError: No module named _winreg</p>
</blockquote>
<p>Since you're running your code on the AppEngine within Windows, the... | 0 | 2016-09-03T16:33:42Z | [
"python",
"google-app-engine",
"amazon-web-services",
"amazon-s3",
"boto"
] |
Flask blueprint url not found | 39,306,579 | <p>I'm trying to create a flask app using blueprints, so I have this structure:</p>
<pre><code>myapp/
__init__.py
static/
templates/
site/
index.html
register.html
layout.html
views/
__init__.py
site.py
models.py
</code></pre>
<p><strong>__in... | -1 | 2016-09-03T11:51:12Z | 39,306,708 | <p>You have to prepend <code>@</code> to <code>site.route</code> like the following.</p>
<pre><code>from flask import Blueprint, render_template
site = Blueprint('site', __name__)
@site.route('/')
def index():
return render_template('site/index.html')
@site.route('/register/')
def register():
return render_tem... | 2 | 2016-09-03T12:07:21Z | [
"python",
"flask"
] |
Filter protocols in python | 39,306,592 | <p>I'm trying to filter certain packets with protocols using user input from a given pcap file and than move the packets to a new pcap file.</p>
<p>That the code I made so far: </p>
<pre><code># ===================================================
# Imports
# ===================================================
from ... | 1 | 2016-09-03T11:52:58Z | 39,316,230 | <p>I don't believe that scapy has any functions or methods to support application layer protocols in the way that you are after. However, using sport and dport as a filter will do the trick (provided you are going to see/are expecting default ports). </p>
<p>Try something like this:</p>
<pre><code>def filter_pcap(fil... | 0 | 2016-09-04T11:06:06Z | [
"python",
"filter",
"protocols",
"wireshark"
] |
Multiple save in model object django | 39,306,599 | <p>I use driver cassandra for my db backend in django , here is my problem :</p>
<p>when I wanna run multiple save in a model object instance , the first one save successfully but the others save wont update my record , here is a example :</p>
<pre><code>obj = Mymodel.objects.get(id=2)
obj.field1 = 2
obj.save()
obj... | 0 | 2016-09-03T11:53:47Z | 39,306,693 | <p>Use <code>refresh_from_db</code> method on <code>obj</code> after first save. <a href="https://docs.djangoproject.com/en/1.8/ref/models/instances/#refreshing-objects-from-database" rel="nofollow">Link to docs</a></p>
<pre><code>obj.refresh_from_db()
</code></pre>
| 0 | 2016-09-03T12:05:45Z | [
"python",
"django",
"cassandra"
] |
How to remove defined text (http headers) from a text file | 39,306,737 | <p>I have a data set of documents containing http headers. I want to go through these documents remove these headers while leaving rest of the text. How can I do that?</p>
<pre><code>WARC/1.0
WARC-Type: response
WARC-Date: 2012-02-10T21:58:44Z
WARC-TREC-ID: clueweb12-0000wb-76-38422
WARC-IP-Address: 207.241.148.80
WAR... | 0 | 2016-09-03T12:10:34Z | 39,307,895 | <p>This will do what you say you want.
It will leave the original file alone and put the cleaned version into a new file.</p>
<pre><code>datafile = 'test1.txt'
outputfile = 'output.txt'
with open(outputfile, encoding='utf-8', mode='w') as outfile:
with open(datafile, encoding='utf-8', mode='r') as infile:
... | 1 | 2016-09-03T14:15:47Z | [
"python"
] |
twitter bot on heroku error "No web processes running" method=GET path="/favicon.ico" | 39,306,809 | <p>I made a twitter bot in <code>python 3.5</code> using <code>tweepy</code> which updates status about the New followers everyday. The code runs smoothly on IDLE. I tried to deploy the bot on heroku but it keeps throwing error in the logs :</p>
<pre><code>at=error code=H14 desc="No web processes running" method=GET p... | 0 | 2016-09-03T12:21:10Z | 39,306,937 | <p>The problem is you are trying to run your web process, when the bot is a worker. You want to <code>ps:scale worker=1</code> instead of <code>ps:scale web=1</code>. Web is for processes with <code>web:</code> in your Procfile and they have to be web apps.</p>
| 0 | 2016-09-03T12:34:12Z | [
"python",
"python-3.x",
"heroku",
"twitter",
"tweepy"
] |
Page hangs on Ajax request to GAE | 39,306,811 | <p>I've created a page that interacts with an app written with Python on GAE, to return JSON data (via JSONP, because Cross-origin stuff). However, no matter what method I use, the page always hangs and data never actually makes it to the screen. It runs just fine if I request the stuff by typing the appspot URL into m... | 0 | 2016-09-03T12:21:17Z | 39,307,846 | <p>I used this code to receive cross-origin json request POST data in my webapp2 handler:</p>
<pre><code>def options(self):
self.response.headers['Access-Control-Allow-Origin'] = '*'
self.response.headers['Access-Control-Allow-Headers'] = '*'
self.response.headers['Access-Control-Allow-Methods'] = 'POST, O... | 0 | 2016-09-03T14:10:47Z | [
"javascript",
"jquery",
"python",
"ajax",
"google-app-engine"
] |
Python Shellexecute windows api with Ctypes over TCP/IP | 39,306,920 | <p>I have question about running windows API's over TCP/IP protocol.
For example, I want to bring remote machine's cmd.exe to other machine (Like Netcat, fully simulating cmd.exe over TCP/IP) . I searched online for doing it with python but couldn't find anything helpful. I can do this using subprocess and other python... | 0 | 2016-09-03T12:32:51Z | 39,339,749 | <p>I'm not sure what your need is based on your description is, but I'll try to help you :). </p>
<p>If all you want is to activate the CMD.exe on a remote machine with a port being open, you would maybe like to look into a "server script" that will execute any command passed to it.
i.e.</p>
<pre><code>class MyTCPH... | 0 | 2016-09-06T02:24:44Z | [
"python",
"windows",
"network-programming",
"tcp-ip",
"netcat"
] |
Python EOF error when loop | 39,306,922 | <p>I need to write a python code to print the input like this:</p>
<pre><code>while (True):
output = raw_input()
print output
</code></pre>
<p>But when I want to end the loop,I used Ctrl_D,and it says:</p>
<pre><code> File "./digits.py", line 6, in <module>
output = raw_input()
EOFError
</code><... | 0 | 2016-09-03T12:33:02Z | 39,306,983 | <p>Have you considered putting a keyword check in your loop?</p>
<pre><code>while (True):
output = raw_input()
if str(output) == "exit":
break
print output
</code></pre>
| -2 | 2016-09-03T12:39:50Z | [
"python",
"eoferror"
] |
Python EOF error when loop | 39,306,922 | <p>I need to write a python code to print the input like this:</p>
<pre><code>while (True):
output = raw_input()
print output
</code></pre>
<p>But when I want to end the loop,I used Ctrl_D,and it says:</p>
<pre><code> File "./digits.py", line 6, in <module>
output = raw_input()
EOFError
</code><... | 0 | 2016-09-03T12:33:02Z | 39,307,077 | <p>The <code>EOFError</code> is an exception that can be caught with <code>try</code>-<code>except</code>. Here we break the loop using the <code>break</code> keyword if an <code>EOFError</code> is thrown:</p>
<pre><code>while True:
try:
output = raw_input()
except EOFError:
break
print(ou... | 3 | 2016-09-03T12:49:24Z | [
"python",
"eoferror"
] |
Jupyter Notebook BeautifulSoup ImportError | 39,306,948 | <p>I am new to python dev and have recently installed a fresh, 64-bit version of anaconda (with python v. 2.7.12) yesterday (<a href="https://www.continuum.io/downloads#windows" rel="nofollow">https://www.continuum.io/downloads#windows</a>) on my windows 8 machine. I immediately launched the Jupyter Notebook instance t... | 0 | 2016-09-03T12:35:21Z | 39,322,276 | <p>I just restarted my PC and Jupyter Notebook detected the HTMLParser module. Not sure what I did to actually fix it - but I'm guessing the answer is one of the following steps I listed in my original question then restarting and launching Jupyter again. </p>
| 0 | 2016-09-04T23:18:08Z | [
"python",
"beautifulsoup",
"anaconda"
] |
List comprehensions adding a value to an element based on a condition | 39,306,952 | <p>I have written code that returns the unique prime number factors of a given number.Here is that code. This code does not consider that 1 is a unique prime number. The <code>factorial3</code> is the function that returns a list of factorials for any given number.</p>
<pre><code> def factorials(n):
x=[j for j in... | 0 | 2016-09-03T12:35:41Z | 39,307,109 | <p>If you want the prime number factors, then simply go up to square root, rather than the whole range.</p>
<p>Replace your first line:</p>
<pre><code>c=[0 for i in numbers]
</code></pre>
<p>with:</p>
<pre><code>c=[0 for i in numbers**0.5]
</code></pre>
| 0 | 2016-09-03T12:53:01Z | [
"python"
] |
List comprehensions adding a value to an element based on a condition | 39,306,952 | <p>I have written code that returns the unique prime number factors of a given number.Here is that code. This code does not consider that 1 is a unique prime number. The <code>factorial3</code> is the function that returns a list of factorials for any given number.</p>
<pre><code> def factorials(n):
x=[j for j in... | 0 | 2016-09-03T12:35:41Z | 39,320,273 | <p>I was able to achieve what I wanted to with the code below.</p>
<pre><code>new1=[i+1 for i,k in enumerate(numbers) for j in factorial3(k) if factorial3(j)==[1,j]]
c1={}
for i in new1:
if i not in c1:
c1[i]=1
else:
c1[i]+=1
sortedc=[v for k,v in sorted(c1.items(), key=lambda x:x[0])... | 0 | 2016-09-04T18:38:58Z | [
"python"
] |
Python Extract Text between two strings into Excel | 39,306,972 | <p>I have a text file like this</p>
<pre><code>blablablabla
blablablabla
Start
Hello
World
End
blablabla
</code></pre>
<p>I want to extract the strings between Start and End and write them into an Excel cell. My code thus far looks like this:</p>
<pre><code>import xlsxwriter
workbook = xlsxwriter.Workbook("Test1.xls... | 0 | 2016-09-03T12:37:47Z | 39,307,154 | <p>First of all, you seem to be always writing in the line number 1</p>
<p>Second, the numeration starts at 0</p>
<p>With these two small changes, this should do what you want :</p>
<pre><code>parsing = False
linewrite=0
for line in liste:
if line.startswith("End"):
parsing = False
if parsing:
... | 1 | 2016-09-03T12:57:28Z | [
"python",
"excel",
"text"
] |
Python Extract Text between two strings into Excel | 39,306,972 | <p>I have a text file like this</p>
<pre><code>blablablabla
blablablabla
Start
Hello
World
End
blablabla
</code></pre>
<p>I want to extract the strings between Start and End and write them into an Excel cell. My code thus far looks like this:</p>
<pre><code>import xlsxwriter
workbook = xlsxwriter.Workbook("Test1.xls... | 0 | 2016-09-03T12:37:47Z | 39,307,443 | <p>The data is being written to the cell, but one problem is that <code>worksheet.write()</code> will overwrite the contents of the cell, so only the last item written will be present.</p>
<p>You can solve this by accumulating the lines between <code>Start</code> and <code>End</code> and then writing them with one <co... | 1 | 2016-09-03T13:28:14Z | [
"python",
"excel",
"text"
] |
Python Extract Text between two strings into Excel | 39,306,972 | <p>I have a text file like this</p>
<pre><code>blablablabla
blablablabla
Start
Hello
World
End
blablabla
</code></pre>
<p>I want to extract the strings between Start and End and write them into an Excel cell. My code thus far looks like this:</p>
<pre><code>import xlsxwriter
workbook = xlsxwriter.Workbook("Test1.xls... | 0 | 2016-09-03T12:37:47Z | 39,307,609 | <p>I don't have much of a experience with excel stuff in python but you can try openpyxl, I found it much easier to understand.</p>
<p>Solution to your problem:</p>
<pre><code>import openpyxl
wb = openpyxl.Workbook()
destination_filename = "my.xlsx"
ws = wb.active
ws.title = "sheet1"
flist = open("text.txt").readline... | 1 | 2016-09-03T13:46:29Z | [
"python",
"excel",
"text"
] |
Display dictionary contents in a label in python tkinter | 39,307,128 | <p>Ive been trying for a while now but i cant seem to display the contents of a dictionary in a label. I want to hit the display button and when i do, i want all the contents in my dictionary to display, see the code below:</p>
<pre><code> import sys
from tkinter import *
from tkinter import ttk
import time
from datet... | 0 | 2016-09-03T12:55:01Z | 39,307,487 | <p><code>Label(..., text= x)</code> will display only once - at the start.</p>
<p>You have to use <code>StringVar</code> to do what you expect</p>
<pre><code>x_var = StringVar()
Label(..., texvariable=x_var)
</code></pre>
<p>Now you can set value in <code>x_var</code> to automatically set new text in <code>Label</co... | 0 | 2016-09-03T13:33:03Z | [
"python",
"user-interface",
"dictionary",
"tkinter"
] |
Installing 64 bit PyCharm on Windows 10 | 39,307,152 | <p>I have a Windows 10 Home 64-bit installed on a x64 laptop. I also have Python 3.4.3 Anaconda 2.3.0 (64-bit) (default, Mar 6 2015, 12:06:10) [MSC v.1600 64 bit (AMD64)] installed as well as 64-bit versions of Java, Firefox and Tortoise. </p>
<p>For some reason when I run the PyCharm installer it only offers me the ... | 1 | 2016-09-03T12:57:18Z | 39,309,498 | <p>See <a href="https://intellij-support.jetbrains.com/hc/en-us/articles/206544879-Selecting-the-JDK-version-the-IDE-will-run-under" rel="nofollow">help article</a>from Intellij. The Windows version has a 32bit java JRE download bundled with the installer. If you want to run a 64 bit version you have to install the 64b... | 2 | 2016-09-03T17:22:46Z | [
"python",
"64bit",
"pycharm"
] |
What function should I use to fix my code? | 39,307,190 | <p>I'm an amateur trying to code a simple troubleshooter in Python but I'm sure what function I need to use to stop this from happening...
<a href="http://i.stack.imgur.com/XJsB1.png" rel="nofollow">enter image description here</a></p>
<p>What should I do so the code doesnt continue running if the user inputs yes?</p... | -2 | 2016-09-03T13:00:52Z | 39,307,411 | <p>I would recommend moving the following:</p>
<pre><code> if askUser("Are you using IOS 5.1 or lower"):
print (lines[1])
else:
if askUser("Have you tried a hard reboot"):
print (lines[2])
else:
if askUser("Is your device jailbroken"):
print (lines... | -2 | 2016-09-03T13:25:19Z | [
"python"
] |
ImportError: No module named pynotify, despite having the module installed | 39,307,218 | <pre><code>>>> import pynotify
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pynotify
>>>
</code></pre>
<p>I have installed py-notify module. This is the error I'm getting when I import it and I'm losing my mind thinking about it.</p>... | 1 | 2016-09-03T13:02:33Z | 39,307,356 | <p>By reading the <a href="http://home.gna.org/py-notify/tutorial.html" rel="nofollow">tutorial</a> on <code>py-notify</code> you will clearly see how you are <em>supposed</em> to import it. </p>
<p>You are supposed to use:</p>
<pre><code>import notify
</code></pre>
<p>Here is a full example of me pip installing py-... | 1 | 2016-09-03T13:19:25Z | [
"python",
"pynotify"
] |
mocking a parent class | 39,307,257 | <p>I have a <code>Parent</code> class that is inherited by a lot of <code>ChildX</code> classes.</p>
<pre><code>class Parent(object): # the class that should be mocked
def __init__(self):
assert False # should never happen, because we're supposed to use the mock instead
class Child1(Parent):
def met... | 0 | 2016-09-03T13:06:54Z | 39,307,310 | <p>No, it's not possible. The definitions of Child1 and Parent - including the inheritance of one from the other - are executed as soon as the module they are in is imported. There is no opportunity to get in before that and change the inheritance hierarchy.</p>
<p>The best you could do would be to move the definition... | 1 | 2016-09-03T13:13:42Z | [
"python",
"mocking",
"py.test"
] |
mocking a parent class | 39,307,257 | <p>I have a <code>Parent</code> class that is inherited by a lot of <code>ChildX</code> classes.</p>
<pre><code>class Parent(object): # the class that should be mocked
def __init__(self):
assert False # should never happen, because we're supposed to use the mock instead
class Child1(Parent):
def met... | 0 | 2016-09-03T13:06:54Z | 39,311,813 | <p>I can't think of a way to replace <code>Parent</code> with <code>MockParent</code> everywhere where it is used, but you could monkeypatch <code>Parent</code>'s methods instead, if that is what you are after:</p>
<pre><code>class Parent(object):
def my_method(self):
print 'my method'
class Child(Parent... | 1 | 2016-09-03T22:18:09Z | [
"python",
"mocking",
"py.test"
] |
Numpy np.where multiple condition | 39,307,268 | <p>I need to work with multiple condition using numpy.</p>
<p>I'm trying this code that seem to work. </p>
<p>My question is: There is another alternative that can do the same job? </p>
<pre><code>Mur=np.array([200,246,372])*pq.kN*pq.m
Mumax=np.array([1400,600,700])*pq.kN*pq.m
Mu=np.array([100,500,2000])*pq.kN*pq.m
... | 1 | 2016-09-03T13:08:42Z | 39,309,283 | <p>you can use Pandas's <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.cut.html" rel="nofollow">pd.cut()</a> method:</p>
<p>generate random series of integers:</p>
<pre><code>In [162]: import pandas as pd
In [163]: s = pd.Series(np.random.randint(-3,10, 10))
In [164]: s
Out[164]:
0 6
1 -... | 1 | 2016-09-03T16:55:35Z | [
"python",
"numpy",
"where"
] |
Numpy np.where multiple condition | 39,307,268 | <p>I need to work with multiple condition using numpy.</p>
<p>I'm trying this code that seem to work. </p>
<p>My question is: There is another alternative that can do the same job? </p>
<pre><code>Mur=np.array([200,246,372])*pq.kN*pq.m
Mumax=np.array([1400,600,700])*pq.kN*pq.m
Mu=np.array([100,500,2000])*pq.kN*pq.m
... | 1 | 2016-09-03T13:08:42Z | 39,309,626 | <p>Starting with this:</p>
<pre><code>Mur = np.array([200,246,372])*3*5
Mumax = np.array([1400,600,700])*3*5
Mu = np.array([100,500,2000])*3*5
Acreq = np.where(Mu<Mur,0,"zero")
Acreq = np.where((Mur<Mu)&(Mu<Mumax),45,Acreq)
Acreq = np.where(Mu>Mumax,60,Acreq)
print(Acreq)
['0' '45' '60']
<... | 1 | 2016-09-03T17:37:49Z | [
"python",
"numpy",
"where"
] |
Use Python `set` keyword in Jinja | 39,307,341 | <p>I want to return unique items in Jinja template. Simplified:</p>
<pre><code>{% set lst = [1, 2, 3, 3, 2] %}
{% for t in set(lst) %}
{{ t }}
{% endfor %}
</code></pre>
<p>But this throws error:</p>
<pre><code>UndefinedError: 'set' is undefined
</code></pre>
<p>And it seems hard to find answer on Google as <co... | 1 | 2016-09-03T13:17:44Z | 39,307,477 | <p>What set does is create a variable, so when you are using <code>set lst = 1</code>, you then access it with <code>lst</code>, not <code>set(lst)</code></p>
<p>edit: misunderstood question, to access a python function from jinja, here's what I do in my flask app</p>
<pre><code>@app.context_processor
def inject_pyth... | -3 | 2016-09-03T13:31:57Z | [
"python",
"jinja2"
] |
Django 1.10 default auth path to templates | 39,307,382 | <p>I'm trying to use the default django Auth system. It seems it can't find the template at registration/login.html even tho I have it created.</p>
<p>I get this error when I try to login:</p>
<pre><code>TemplateDoesNotExist at /accounts/login/
registration/login.html
Request Method: GET
Request URL: http://127.0.... | 0 | 2016-09-03T13:21:49Z | 39,307,608 | <p>Add <code>templates</code> to <code>DIRS</code> array of <code>TEMPLATES</code> in your <code>settings.py</code></p>
<pre><code>TEMPLATES = [{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
... | 0 | 2016-09-03T13:46:28Z | [
"python",
"django",
"authentication"
] |
adding multiple directories as destination when copying files in python | 39,307,400 | <p>I want to copy an entire directory or just files from a directory to two or more directories at the same time. I'm struggling with the syntax to add more directories for the destination, so the copy is done at the same time (as I'll run a cron job). </p>
<p>Everything works fine if I have one single directory, howe... | 0 | 2016-09-03T13:23:55Z | 39,307,929 | <p>Why not just wrap in a loop:</p>
<pre><code>destinations = [r'S:\\A', r'S:\\B', r'S:\\C']
for dest in destinations:
shutil.copy(full_file_name, dest)
</code></pre>
| 0 | 2016-09-03T14:19:04Z | [
"python"
] |
adding multiple directories as destination when copying files in python | 39,307,400 | <p>I want to copy an entire directory or just files from a directory to two or more directories at the same time. I'm struggling with the syntax to add more directories for the destination, so the copy is done at the same time (as I'll run a cron job). </p>
<p>Everything works fine if I have one single directory, howe... | 0 | 2016-09-03T13:23:55Z | 39,307,940 | <p>In this example you define your file folder before, and an array of destination folders. Python then iterates through the destinations in a <code>for</code> loop. Note the use of <code>os.path.join</code>, which is a safe way of building file paths for cross-platform work.</p>
<pre><code>import shutil
import os
f... | 0 | 2016-09-03T14:20:22Z | [
"python"
] |
adding multiple directories as destination when copying files in python | 39,307,400 | <p>I want to copy an entire directory or just files from a directory to two or more directories at the same time. I'm struggling with the syntax to add more directories for the destination, so the copy is done at the same time (as I'll run a cron job). </p>
<p>Everything works fine if I have one single directory, howe... | 0 | 2016-09-03T13:23:55Z | 39,308,470 | <p>If you want to copy the files at the same time, you should use <a href="https://docs.python.org/3/library/multiprocessing.html" rel="nofollow">multiprocessing</a>.
In this sample, we have two files file1.txt and file2.txt and we will copy them to c:\temp\0 and c:\temp\1. </p>
<pre><code>import multiprocessing
impor... | 0 | 2016-09-03T15:20:24Z | [
"python"
] |
what would be the pandas equivalent of a complex SQL query (consisting of a subquery) | 39,307,435 | <p>Can anyone tell me the pandas equivalent of the following SQL query.
Consider <code>sales_data</code> as tablename/pd.DataFrame</p>
<pre><code>SELECT store_id, store_name, sales FROM sales_data WHERE sales = (SELECT max(sales) FROM sales_data WHERE store_location = 'Beijing') and store_location = 'Beijing'
</code><... | 1 | 2016-09-03T13:27:32Z | 39,308,276 | <p>I wouldn't try to do it in one step in this case, because it might be slower:</p>
<p>Demo:</p>
<p><strong>Data:</strong></p>
<pre><code>In [103]: df
Out[103]:
a b c x
0 2 1 1 b
1 2 3 2 a
2 4 1 3 c
3 3 2 3 b
4 2 1 4 c
5 1 3 1 c
6 2 3 0 a
7 2 3 2 b
8 4 2 4 a
9 4 1 1 b
<... | 1 | 2016-09-03T14:59:44Z | [
"python",
"pandas",
"subquery"
] |
how to get the next page link in scrapy | 39,307,468 | <p>how to get the link "/zufang/dongcheng/pg2/" in "ä¸ä¸é¡µ"ï¼</p>
<pre><code><a href="/zufang/dongcheng/pg2/" data-page="2">ä¸ä¸é¡µ</a>
</code></pre>
<p>I have tried this, but got nothing.</p>
<p>the url is "<a href="http://bj.lianjia.com/zufang/dongcheng/" rel="nofollow">http://bj.lianjia.com/zufa... | -1 | 2016-09-03T13:30:15Z | 39,307,836 | <p>Why not just keep appending the incremented value of the page no in the url.
Applicable to this link.</p>
<pre><code>url = 'http://bj.lianjia.com/zufang/dongcheng/'
counter = 1
while <http error is null>:
url_to_crawl = url + "/pg" + counter
counter = counter + 1
<crawl the url>
</code></pr... | -1 | 2016-09-03T14:09:57Z | [
"python",
"regex",
"scrapy",
"web-crawler"
] |
how to get the next page link in scrapy | 39,307,468 | <p>how to get the link "/zufang/dongcheng/pg2/" in "ä¸ä¸é¡µ"ï¼</p>
<pre><code><a href="/zufang/dongcheng/pg2/" data-page="2">ä¸ä¸é¡µ</a>
</code></pre>
<p>I have tried this, but got nothing.</p>
<p>the url is "<a href="http://bj.lianjia.com/zufang/dongcheng/" rel="nofollow">http://bj.lianjia.com/zufa... | -1 | 2016-09-03T13:30:15Z | 39,309,631 | <p>Extract the link and attach it to the current url</p>
<pre><code>from urlparse import urljoin
yield scrapy.Request(urljoin(response.url,response.xpath("//a[@data-page]/@href").extract_first()), callback=self.parse)
</code></pre>
<p>or increment the page</p>
<pre><code>for i in range(2,20):
yield scrapy.Reques... | 0 | 2016-09-03T17:38:18Z | [
"python",
"regex",
"scrapy",
"web-crawler"
] |
Access HTTP PUT data in python hug | 39,307,491 | <pre><code>import hug
something = {'foo': 'bar'}
@hug.put('/')
def update_something():
something['foo'] = <value_of_bar_from_http_put_request>
</code></pre>
<p>How do I access the put data so that I can update <code>something</code>? I looked up <a href="https://github.com/timothycrosley/hug" rel="nofollow... | 0 | 2016-09-03T13:33:11Z | 39,476,129 | <pre><code>import hug
something = {'foo': 'bar'}
@hug.put()
def update_something(bar: hug.types.text):
something['foo'] = bar
return something # may be
</code></pre>
<p>And then you may use requests to test</p>
<pre><code>import requests
print(requests.put('http://localhost:8000/update_something',
dat... | 1 | 2016-09-13T17:48:17Z | [
"python",
"api",
"python-3.x",
"hug"
] |
How to install and build NS-3 using bake | 39,307,561 | <p>I am trying to download, build and test NS-3 using bake by typing the following commands on Cygwin on windows 7: </p>
<pre><code>$ cd
$ mkdir workspace
$ cd workspace
$ hg clone http://code.nsnam.org/bake
</code></pre>
<p>Then I changed the directory to bake directory and typed:</p>
<pre><code>$ export BAKE_HOME=... | 0 | 2016-09-03T13:40:38Z | 40,112,059 | <p>It seems you are missing "Unrar tool". I don't have cygwin to test here, but you migth try:</p>
<pre><code>wget http://www.rarlab.com/rar/unrarsrc-5.1.7.tar.gz
tar -xzvf unrarsrc-5.1.7.tar.gz
cd unrar
make
</code></pre>
<p>and then run bake download again.</p>
<p>Source: <a href="https://wjianz.wordpress.com/2014... | 0 | 2016-10-18T15:18:42Z | [
"python",
"c++",
"g++",
"cygwin",
"cygpath"
] |
os.path.join - how to cope with absolute path | 39,307,631 | <p><strong>Python 3.5.2</strong></p>
<pre><code>BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_URL = '/static/'
</code></pre>
<p>I want to join them:</p>
<pre><code>STATIC_ROOT = os.path.join(PROJECT_PATH, STATIC_URL)
</code></pre>
<p>The result is '/static/'. </p>
<p>This is the do... | 0 | 2016-09-03T13:48:48Z | 39,307,659 | <p>"If a component is an absolute path, all previous components are thrown away and joining continues from the absolute path component." applies here: <code>STATIC_URL</code> is an absolute path because it starts with <code>/</code>, so <code>BASE_DIR</code> is dropped.</p>
<p>Drop the leading <code>/</code> else dirn... | 3 | 2016-09-03T13:50:57Z | [
"python"
] |
Google CodeJam Past Exercise - Decrease runtime | 39,307,690 | <p>I have been working on a past Google Codejam algorithm from 2010, but the time complexity is awful.</p>
<p>Here is the question from Google Codejam: <a href="https://code.google.com/codejam/contest/619102/dashboard" rel="nofollow">https://code.google.com/codejam/contest/619102/dashboard</a></p>
<p>TLDR - Imagine t... | -4 | 2016-09-03T13:54:21Z | 39,307,916 | <p>Since <code>N</code> is 1000 an algorithm with <code>O(N^2)</code> would be acceptable. So what you have to do is sort the wires by one of their end points.</p>
<pre><code>//sorted by first number
1 10
5 5
7 7
</code></pre>
<p>Then you process each line from the beginning and check whether it has intersection ... | 0 | 2016-09-03T14:17:58Z | [
"python",
"algorithm"
] |
Increase the significant digits in Numpy | 39,307,766 | <p>I want to know how can I increase the number of significant digits beyond the decimal.
The original "rf" numpy array contains floating point numbers.</p>
<pre><code>import numpy as np
rf=daily_rets(df)
[ 7.11441183 7.12383509 7.13325787 7.16152716 7.17094994 7.17094994 7.18979692 7.18979692 7.19921923 7.1... | 0 | 2016-09-03T14:02:49Z | 39,308,347 | <p>In python 2.7 dividing a numpy float by an integer will return an integer, at least that is my experience.
As the answers say:</p>
<pre><code>In [1]: import numpy as np
In [2]: rf = np.array([ 7.11441183, 7.12383509, 7.13325787, 7.16152716, 7.17
...: 094994, 7.17094994, 7.18979692, 7.18979692, 7.199219... | 0 | 2016-09-03T15:06:49Z | [
"python",
"numpy",
"significant-digits"
] |
Increase the significant digits in Numpy | 39,307,766 | <p>I want to know how can I increase the number of significant digits beyond the decimal.
The original "rf" numpy array contains floating point numbers.</p>
<pre><code>import numpy as np
rf=daily_rets(df)
[ 7.11441183 7.12383509 7.13325787 7.16152716 7.17094994 7.17094994 7.18979692 7.18979692 7.19921923 7.1... | 0 | 2016-09-03T14:02:49Z | 39,308,455 | <p>You could just use <a href="http://docs.scipy.org/doc/numpy/reference/ufuncs.html#available-ufuncs" rel="nofollow">numpy ufuncs</a>:</p>
<pre><code>from __future__ import division
import numpy as np
rf = np.array([7.11441183, 7.12383509, 7.13325787, 7.16152716])
np.divide(rf[0:], 100, rf[0:])
np.add(rf[0:], 1, rf[0... | 0 | 2016-09-03T15:19:30Z | [
"python",
"numpy",
"significant-digits"
] |
Matching ctrl-M character in Python | 39,307,806 | <p>I am working on an interactive program where I take some actions based on the input. For the application I want to match <code>^M</code> characters in the input stream.</p>
<p>To do this I found the ASCII equivalent of <code>^M</code> which is <code>0xd</code> and converted the input character to ascii using <code>... | 0 | 2016-09-03T14:07:09Z | 39,307,824 | <p><code>0xd</code> is an <em>integer literal</em> (it produces the value 13), but <code>hex()</code> returns a string. <code>'0xd'</code> may <em>look</em> like <code>0xd</code>, but are not equal:</p>
<pre><code>>>> hex(13)
'0xd'
>>> 0xd
13
>>> hex(13) == 0xd
False
</code></pre>
<p>Remove... | 3 | 2016-09-03T14:08:36Z | [
"python"
] |
SqlAlchemy Join Query | 39,307,825 | <p>I have tables like this:</p>
<p>Box</p>
<p>|- issues[]</p>
<p>Issue</p>
<p>|- status_id</p>
<p>|- status (related through status_id)</p>
<p>Status</p>
<p>|- id</p>
<p>I want to get all the boxes where the âissuesâ field for each box will only contain issues that donât have a status_id = 5. The followin... | 1 | 2016-09-03T14:08:39Z | 39,308,097 | <p>If I've understood your situation correctly, I think the following is what you're looking for:</p>
<pre><code>db.session.query(Box).outerjoin(Box.issues).filter(or_(Issue.status_id.is_(None), Issue.status_id != 5)).options(contains_eager(Box.issues)).all()
</code></pre>
| 1 | 2016-09-03T14:37:40Z | [
"python",
"sqlalchemy",
"flask-sqlalchemy"
] |
Do we need to install library/package for cgi to run Python scripts (on WAMP)? Or is it available automatically (in WAMP server)? | 39,307,889 | <p>I'm running Python 3.5 and I have tried installing cgi using pip and it gave me the following message:</p>
<pre><code>Could not find a version that satisfies the requirement cgi (from versions:)
No matching distribution found for cgi
</code></pre>
<p>I want to run Python scripts (locally, using WAMP server) on my ... | 0 | 2016-09-03T14:14:45Z | 39,308,098 | <p>For CGI you dont actually need any libraries (although <a href="https://docs.python.org/3/library/cgi.html" rel="nofollow">cgi</a> from standard library is helpful) but I would strongly recommend to use WSGI as not only debugging is much easier with it. There is a <a href="https://docs.python.org/3/library/wsgiref.h... | 0 | 2016-09-03T14:37:56Z | [
"python",
"apache",
"python-3.x",
"cgi",
"wamp"
] |
How do I remove similar tuples in python as in (x,y) and (y,x) | 39,307,906 | <p>I have a list of tuples [(1,2),(2,1),(4,4)] I want to remove either of these tuples where (a,b) = (b,a). ie.. (1,2) or (2,1)</p>
| -4 | 2016-09-03T14:17:05Z | 39,308,018 | <p>Assuming the order of the elements in tuple doesn't matter, one way is to do:</p>
<pre><code>In [11]: l = [(1,2), (2,1), (4,4)]
In [12]: list(set([(x[0], x[1]) if x [0] < x[1] else (x[1], x[0]) for x in l]))
Out[12]: [(1, 2), (4, 4)]
</code></pre>
<p>Edit (A simpler version):</p>
<pre><code>In [15]: list(set... | 1 | 2016-09-03T14:29:38Z | [
"python"
] |
Object is not callable the second time I call a class method | 39,307,910 | <p>I have a class Match:</p>
<pre><code>class Match(object):
def __init__(self,id):
self.id = id
def result(self):
# somehow find the game result
self.result = result
return self.result
</code></pre>
<p>If I initialize a match object as</p>
<pre><code>m = Match(1)
</code></pre>
<p>when... | 2 | 2016-09-03T14:17:24Z | 39,307,921 | <p>You have given your instance an attribute named <code>result</code>:</p>
<pre><code>self.result = result
</code></pre>
<p>This now masks the method. You can't use the same name as the method if you don't want it masked. Rename the attribute or the method.</p>
<p>You could use the name <code>_result</code> for exa... | 6 | 2016-09-03T14:18:26Z | [
"python"
] |
Stratified Labeled K-Fold Cross-Validation In Scikit-Learn | 39,307,945 | <p>I'm trying to classify instances of a dataset as being in one of two classes, a or b. B is a minority class and only makes up 8% of the dataset. All instances are assigned an id indicating which subject generated the data. Because every subject generated multiple instances id's are repeated frequently in the dataset... | 3 | 2016-09-03T14:20:38Z | 39,308,376 | <p>The following is a bit tricky with respect to indexing (it would help if you use something like Pandas for it), but conceptually simple.</p>
<p>Suppose you make a dummy dataset where the independent variables are only <code>id</code> and <code>class</code>. Furthermore, in this dataset, remove duplicate <code>id</c... | 2 | 2016-09-03T15:09:03Z | [
"python",
"pandas",
"machine-learning",
"scikit-learn",
"cross-validation"
] |
Beautiful Soup - Python | 39,308,028 | <p>I was hoping to ask a pretty simple question. I have come across the below code and have not been able to find a decent explanation as to:</p>
<ol>
<li>What exactly does the <code>.attrs</code> function do in this case?</li>
<li>What is the function of the <code>['href']</code> part at the end i.e. what exactly doe... | -2 | 2016-09-03T14:30:28Z | 39,308,104 | <p>Let's go line by line after imports</p>
<ul>
<li>Load a url into variable called html</li>
<li>Create BeautifulSoup object from html</li>
<li>For every link in the object's "a" tags (it loops over html tags in the html, finds all <code><a></code> and loops over them)</li>
<li>If the attribute of the tag has '... | 1 | 2016-09-03T14:38:25Z | [
"python"
] |
Beautiful Soup - Python | 39,308,028 | <p>I was hoping to ask a pretty simple question. I have come across the below code and have not been able to find a decent explanation as to:</p>
<ol>
<li>What exactly does the <code>.attrs</code> function do in this case?</li>
<li>What is the function of the <code>['href']</code> part at the end i.e. what exactly doe... | -2 | 2016-09-03T14:30:28Z | 39,308,120 | <p>Let's try to fetch this question it self and see:</p>
<pre><code>from urllib.request import urlopen
from bs4 import BeautifulSoup
html = urlopen("http://stackoverflow.com/q/39308028/1005215")
bsObj = BeautifulSoup(html)
</code></pre>
<blockquote>
<p>i) what exactly does the .attrs function do in this code</p>
</... | 1 | 2016-09-03T14:40:03Z | [
"python"
] |
How do I increase the contrast of an image in Python OpenCV | 39,308,030 | <p>I am new to Python OpenCV. I have read some documents and answers <a href="http://stackoverflow.com/questions/19363293/whats-the-fastest-way-to-increase-color-image-contrast-with-opencv-in-python-c">here</a> but I am unable to figure out what the following code means:</p>
<pre><code>if (self.array_alpha is None):
... | 0 | 2016-09-03T14:30:36Z | 39,319,390 | <p>Best explanation for <code>X = aY + b</code> (in fact it <code>f(x) = ax + b</code>)) is provided at <a href="http://math.stackexchange.com/a/906280/357701">http://math.stackexchange.com/a/906280/357701</a> </p>
<p>A Simpler one by just adjusting lightness/luma/brightness for contrast as is below:</p>
<pre><code>... | 0 | 2016-09-04T17:01:16Z | [
"python",
"opencv"
] |
SQLITE3 database tables export in CSV | 39,308,042 | <p>I have a database including 10 tables: (date ,day ,month ,year ,pcp1 ,pcp2 ,pcp3 ,pcp4,pcp5 ,pcp6) and each column has 41 years dataset. day, month and year columns are "Null" as l will add them later after exporting tables in csv file and l did this part but format is not correct as each column must be respectively... | 1 | 2016-09-03T14:32:10Z | 39,308,066 | <ol>
<li>The query is not supposed to return the headers. Also I'm confident about both points below. This is untested, but the <code>description</code> attribute returns the last query table names, so it should work</li>
<li>About the extra blank line every line: I suppose you're using windows. Opening the output as t... | 1 | 2016-09-03T14:34:31Z | [
"python",
"sqlite",
"csv"
] |
SQLITE3 database tables export in CSV | 39,308,042 | <p>I have a database including 10 tables: (date ,day ,month ,year ,pcp1 ,pcp2 ,pcp3 ,pcp4,pcp5 ,pcp6) and each column has 41 years dataset. day, month and year columns are "Null" as l will add them later after exporting tables in csv file and l did this part but format is not correct as each column must be respectively... | 1 | 2016-09-03T14:32:10Z | 39,318,221 | <p>Here is the answer of my question and it combined with the code posted by Jean-François Fabre ,thanks for his help.</p>
<pre><code>import sys
import sqlite3
import csv
conn=sqlite3.connect("pcpnew6.db")
c=conn.cursor()
conn.row_factory=sqlite3.Row
crsr=conn.execute("SELECT * From pcp3")
row=crsr.fetchone()
titles... | 1 | 2016-09-04T14:55:50Z | [
"python",
"sqlite",
"csv"
] |
Regarding Keyerror while using Python json module | 39,308,059 | <p>would be helped if the mistake is pointed.
Here Iam trying to create a code for displaying the name of the city state and country by taking Pincode as input, Thanks in advance</p>
<pre><code> import urllib, json
from urllib.request import urlopen
from tkinter import *
global pincode
root=Tk()
frame=Frame(root,w... | -1 | 2016-09-03T14:33:38Z | 39,308,085 | <p>Ok. Error tells you that you don't have key named "State" in you dict under <code>data</code> variable. So maybe there isn't also in incomming json.</p>
<p>If in response you get:</p>
<pre><code>{"ResponseCode":0,"ResponseMessage":"OK","ResponseDateTime":ââ"9/3/2016 2:41:25 PM GMT","Data":[{"Pincode":"560103",... | 1 | 2016-09-03T14:36:25Z | [
"python",
"json",
"python-3.x"
] |
How to display Chinese characters inside a pandas dataframe? | 39,308,065 | <p>I can read a csv file in which there is a column containing Chinese characters (other columns are English and numbers). However, Chinese characters don't display correctly. see photo below</p>
<p><a href="http://i.stack.imgur.com/nG6oN.png" rel="nofollow"><img src="http://i.stack.imgur.com/nG6oN.png" alt="enter ima... | 0 | 2016-09-03T14:34:28Z | 39,310,336 | <p>I see here three possible issues: </p>
<p>1) You can try this:</p>
<pre><code>import codecs
x = codecs.open("testdata.csv", "r", "utf-8")
</code></pre>
<p>2) Another possibility can be theoretically this:</p>
<pre><code>import pandas as pd
df = pd.DataFrame(pd.read_csv('testdata.csv',encoding='utf-8'))
</code><... | 0 | 2016-09-03T18:55:42Z | [
"python",
"csv",
"pandas",
"encoding",
"chinese-locale"
] |
How to display Chinese characters inside a pandas dataframe? | 39,308,065 | <p>I can read a csv file in which there is a column containing Chinese characters (other columns are English and numbers). However, Chinese characters don't display correctly. see photo below</p>
<p><a href="http://i.stack.imgur.com/nG6oN.png" rel="nofollow"><img src="http://i.stack.imgur.com/nG6oN.png" alt="enter ima... | 0 | 2016-09-03T14:34:28Z | 39,312,264 | <p>I just remembered that the source dataset was created using <code>encoding='GBK'</code>, so I tried again using </p>
<pre><code>data06_16 = pd.read_csv("../data/stocks1542monthly.csv", encoding="GBK")
</code></pre>
<p>Now, I can see all the Chinese characters. </p>
<p>Thanks guys!</p>
| 0 | 2016-09-03T23:37:30Z | [
"python",
"csv",
"pandas",
"encoding",
"chinese-locale"
] |
Groupby/Sum in Python Pandas - zero counts not showing ...sometimes | 39,308,093 | <p><strong>The Background</strong></p>
<p>I have a data set of a <em>simulated</em> population of people. They have the following attributes</p>
<ol>
<li>Age (0-120 years)</li>
<li>Gender (male,female)</li>
<li>Race (white, black, hispanic, asian, other)</li>
</ol>
<p>df.head()</p>
<pre><code> Age Race Gender ... | 2 | 2016-09-03T14:37:17Z | 39,308,267 | <p>Use <code>reindex</code> with a predefined index and <code>fill_value=0</code></p>
<pre><code>ages = np.arange(21, 26)
genders = ['male', 'female']
races = ['white', 'black', 'hispanic', 'asian', 'other']
sim_size = 10000
midx = pd.MultiIndex.from_product([
ages,
genders,
races
], name... | 3 | 2016-09-03T14:58:19Z | [
"python",
"pandas",
"group-by",
"aggregation"
] |
Calculating percentile of bins from numpy digitize? | 39,308,146 | <p>I have a set of data, and a set of thresholds for creating bins:</p>
<pre><code>data = np.array([0.01, 0.02, 1, 1, 1, 2, 2, 8, 8, 4.5, 6.6])
thresholds = np.array([0,5,10])
bins = np.digitize(data, thresholds, right=True)
</code></pre>
<p>For each of the elements in <code>bins</code>, I want to know the base perce... | 0 | 2016-09-03T14:42:50Z | 39,316,086 | <p>You can calculate the percentile for each element in your data array as described in a previous StackOverflow question (<a href="http://stackoverflow.com/questions/12414043/map-each-list-value-to-its-corresponding-percentile#answer-28577101">Map each list value to its corresponding percentile</a>).</p>
<pre><code>i... | 2 | 2016-09-04T10:45:21Z | [
"python",
"pandas",
"numpy",
"histogram",
"percentage"
] |
writing json-ish list to csv, line by line, in python for bitcoin addresses | 39,308,153 | <p>I'm querying the <a href="https://api.onename.com/#lookup_users" rel="nofollow">onename api</a> in an effort to get the bitcoin addresses of all the users. </p>
<p>At the moment I'm getting all the user information as a json-esque list, and then piping the output to a file, it looks like this: </p>
<pre><code>[{'0... | 2 | 2016-09-03T14:44:32Z | 39,308,278 | <p>Instead of adding all the information to the UsersDetails list</p>
<pre><code>UsersDetails.append(userinfo)
</code></pre>
<p>you can add just the relevant part (address)</p>
<pre><code>try:
address = userinfo[usernamex]["profile"]["bitcoin"]["address"]
UsersDetails.append(address)
except KeyError:
pas... | 1 | 2016-09-03T14:59:44Z | [
"python",
"json",
"csv",
"bitcoin"
] |
writing json-ish list to csv, line by line, in python for bitcoin addresses | 39,308,153 | <p>I'm querying the <a href="https://api.onename.com/#lookup_users" rel="nofollow">onename api</a> in an effort to get the bitcoin addresses of all the users. </p>
<p>At the moment I'm getting all the user information as a json-esque list, and then piping the output to a file, it looks like this: </p>
<pre><code>[{'0... | 2 | 2016-09-03T14:44:32Z | 39,308,438 | <p>You need to reformat the list, either through <code>map()</code> or a list comprehension, to get it down to just the information you want. For example, if the top-level key used in the response from the api.onename.com API is always <code>0</code>, you can do something like this </p>
<pre><code>UsersAddresses = [u... | 1 | 2016-09-03T15:17:10Z | [
"python",
"json",
"csv",
"bitcoin"
] |
Strange error in python3 when doing big int calculation | 39,308,302 | <p>I was trying to do this in Python 3.5.2:</p>
<pre><code>int(204221389795918291262976/10000)
</code></pre>
<p>but got the unexpected result: <code>20422138979591827456</code></p>
<p>It's working fine in Python 2.7.12, result is: <code>20422138979591829126L</code></p>
<p>Any idea why Python 3 gave me the wrong res... | 3 | 2016-09-03T15:01:54Z | 39,308,310 | <p>In python 3 you have to use integer division <code>//</code> explicitly or else float division will apply even between 2 integers.</p>
<p>That's one of the major changes between python 2 and python 3</p>
<p>In your example: (will work both in python 2 and python 3 so it's backwards compatible!)</p>
<pre><code>int... | 5 | 2016-09-03T15:03:16Z | [
"python",
"python-3.x"
] |
How can I extract these list and tuples into strings? | 39,308,333 | <p>I have these lists and tuples and can't figure out how to extract the numbers out of them.</p>
<pre><code>[('40', '50')] [('35', '45', '49')] [('02', '11')]
</code></pre>
<p>They are stored in three different variables, how can I extract them? I've tried the following:</p>
<pre><code>chain.from_iterable(list_one)... | 0 | 2016-09-03T15:05:40Z | 39,308,405 | <p>To get each seperately as string:</p>
<pre><code> output = ""
a = [('02', '11')]
for i in a:
for x in i:
output = output + " " + x
</code></pre>
| 0 | 2016-09-03T15:12:27Z | [
"python",
"python-3.x"
] |
How can I extract these list and tuples into strings? | 39,308,333 | <p>I have these lists and tuples and can't figure out how to extract the numbers out of them.</p>
<pre><code>[('40', '50')] [('35', '45', '49')] [('02', '11')]
</code></pre>
<p>They are stored in three different variables, how can I extract them? I've tried the following:</p>
<pre><code>chain.from_iterable(list_one)... | 0 | 2016-09-03T15:05:40Z | 39,308,411 | <p>Use <strong><a href="https://docs.python.org/3/library/itertools.html#itertools.chain" rel="nofollow"><code>chain</code></a></strong> to chain your lists together and then iterate through them. Then you can unpack in the <code>print</code> call to get every sub-element element printed out.</p>
<p>So, if for example... | 2 | 2016-09-03T15:13:24Z | [
"python",
"python-3.x"
] |
Grouping up elements from a list in Python 2.7 | 39,308,400 | <p>Ok, I got a huge text. I extract matches with regex (omitted here because it doesn't matter and I'm bad at this so you don't see how ugly my regex is :) ) and count them. Then, for readability, I split the elements and print them in the fashion I need:</p>
<pre><code>import re
f = re.findall(r"(...)", PF)
a = [[y,f... | 1 | 2016-09-03T15:11:44Z | 39,308,600 | <p>You can set up a hash that maps elements to groups. You can then transform each array item from [element,count] to (group,element,count) <em>(using a tuple to make it more easily sortable and such)</em>. Sort that array, then use a loop or <code>reduce</code> to transform that into your final output.</p>
<pre><co... | 0 | 2016-09-03T15:36:20Z | [
"python",
"arrays",
"list",
"python-2.7",
"count"
] |
Grouping up elements from a list in Python 2.7 | 39,308,400 | <p>Ok, I got a huge text. I extract matches with regex (omitted here because it doesn't matter and I'm bad at this so you don't see how ugly my regex is :) ) and count them. Then, for readability, I split the elements and print them in the fashion I need:</p>
<pre><code>import re
f = re.findall(r"(...)", PF)
a = [[y,f... | 1 | 2016-09-03T15:11:44Z | 39,308,612 | <p>One (probably not most elegant) solution would be to define a dictionary with the mappings and then lookup the name of the group to which the element belongs to. </p>
<pre><code>elements = { "133": "A", "132": "A",
"202": "B",
... }
</code></pre>
<p>The elements can then be added to a ... | 0 | 2016-09-03T15:38:08Z | [
"python",
"arrays",
"list",
"python-2.7",
"count"
] |
Mimicking HTML5 Video support on PhantomJS used through Selenium in Python | 39,308,447 | <p>I am trying to extract the source link of an HTML5 video found in the video tag . Using Firefox webdrive , I am able to get the desired result ie - </p>
<pre><code>[<video class="video-stream html5-main-video" src='myvideoURL..'</video>]
</code></pre>
<p>but if I use PhantomJS -</p>
<pre><code> <video... | 2 | 2016-09-03T15:18:34Z | 39,315,815 | <p>The way Firefox and phantomjs webdrivers communicate with Selenium are quite different.</p>
<p>When using Firefox, it signals back that the page has finished loading after it loaded some of the javascript</p>
<p>Differently in phantomjs, it signals Selenium that the page has finished loading as soon as it is able ... | 1 | 2016-09-04T10:11:57Z | [
"python",
"selenium",
"phantomjs"
] |
Does filter,map, and reduce in Python create a new copy of list? | 39,308,479 | <p>Using <code>Python 2.7</code>. Let us say we have <code>list_of_nums = [1,2,2,3,4,5]</code>
and we want to remove all occurrences of 2. We can achieve it by
<code>list_of_nums[:] = filter(lambda x: x! = 2, list_of_nums)</code> or <code>list_of_nums = filter(lambda x: x! = 2, list_of_nums)</code>.</p>
<p>Is this an... | 3 | 2016-09-03T15:21:39Z | 39,308,693 | <pre><code>list_of_nums[:] = filter(lambda x: x != 2, list_of_nums)
</code></pre>
<p>and</p>
<pre><code>list_of_nums = filter(lambda x: x != 2, list_of_nums)
</code></pre>
<p>are two different operations that end up with <em>mostly</em> the same result.</p>
<p>In both cases,</p>
<pre><code>filter(lambda x: x != 2,... | 4 | 2016-09-03T15:48:04Z | [
"python",
"python-2.7",
"lambda",
"higher-order-functions"
] |
Python3.4 int object is not iterable - MySQLdb | 39,308,534 | <p>I'm running python3.4 and i'm trying to run a query with the MySQLdb library.</p>
<p>I've done one successful query but now I am stuck when it comes to integers in a query. Here's the code:</p>
<pre><code> location = player_info[6]
query2 = ("SELECT name FROM locations WHERE id=%d")... | 0 | 2016-09-03T15:28:57Z | 39,308,731 | <pre><code> execute = cursor.execute(query2, (location));
</code></pre>
<p>In python, <code>(location)</code> is a parenthesized expression, not a tuple. In order to force that to be a tuple, you need to add a comma: <code>(location,)</code></p>
<pre><code> execute = cursor.execute(query2, (loc... | 1 | 2016-09-03T15:51:49Z | [
"python",
"mysql-python"
] |
Java generate random int from timestamp | 39,308,625 | <p>I am trying to generate a random int from timestamp, but below java code gives output in following format.</p>
<pre><code>java.util.Date date= new java.util.Date();
System.out.println(new Timestamp(date.getTime()));
</code></pre>
<p>Output : </p>
<blockquote>
<p>2010-03-08 14:59:30.252</p>
</blockquote>
<p>Any... | -1 | 2016-09-03T15:40:20Z | 39,308,751 | <p>To print the number of milliseconds from epoch to the Date object use
<code>System.out.println(Long.toString(new Date().getTime()));</code>.</p>
<p>Otherwise if you just want the current count of milliseconds or nanoseconds since epoch, you have a couple options:</p>
<ul>
<li><code>System.currentTimeMillis()</code... | 2 | 2016-09-03T15:53:48Z | [
"java",
"python",
"timestamp"
] |
Java generate random int from timestamp | 39,308,625 | <p>I am trying to generate a random int from timestamp, but below java code gives output in following format.</p>
<pre><code>java.util.Date date= new java.util.Date();
System.out.println(new Timestamp(date.getTime()));
</code></pre>
<p>Output : </p>
<blockquote>
<p>2010-03-08 14:59:30.252</p>
</blockquote>
<p>Any... | -1 | 2016-09-03T15:40:20Z | 39,308,766 | <p>You can use
System. currentTimeMillis() or System.nanoTime()</p>
| 0 | 2016-09-03T15:55:58Z | [
"java",
"python",
"timestamp"
] |
Cassandra error 'NoneType' object has no attribute 'datacenter' while importing csv | 39,308,666 | <p>I have set up a cassandra cluster with 3 nodes.</p>
<p>I am trying to do a simple export/ import using copy command, but it fails with the following error:</p>
<pre><code>cqlsh:walmart> select * from test;
store | date | isholiday | dept
-------+------------+-----------+------
1 | 22/04/1993 | ... | 1 | 2016-09-03T15:44:27Z | 39,358,147 | <p>The issue is with the build of cqlsh that you are using, In that build copyutil is not using correct host to connect. It has been <a href="http://mail-archives.apache.org/mod_mbox/cassandra-commits/201607.mbox/%[email protected]%3E" rel="nofollow">fixed</a> in the new releases. Just c... | 1 | 2016-09-06T21:30:05Z | [
"python",
"csv",
"cassandra",
"copy",
"nonetype"
] |
Cassandra error 'NoneType' object has no attribute 'datacenter' while importing csv | 39,308,666 | <p>I have set up a cassandra cluster with 3 nodes.</p>
<p>I am trying to do a simple export/ import using copy command, but it fails with the following error:</p>
<pre><code>cqlsh:walmart> select * from test;
store | date | isholiday | dept
-------+------------+-----------+------
1 | 22/04/1993 | ... | 1 | 2016-09-03T15:44:27Z | 39,381,054 | <p>it is not so good, but i will try to contribute to the problem. i'm new in cassandra and had exactly the same problem while trying to import data into a cassandra table via the copy function. i connect to the server on which cassandra is installed through cqlsh installed on a virtual machine. so i have to specify th... | 1 | 2016-09-08T00:58:50Z | [
"python",
"csv",
"cassandra",
"copy",
"nonetype"
] |
Django-registration custom urls | 39,308,702 | <p>I've used django-registration (<a href="https://django-registration.readthedocs.io/en/latest/index.html" rel="nofollow">the app</a>, HMAC) for user registration and login. Everything works fine, but I would like to have the login form at <a href="http://localhost:8000/" rel="nofollow">http://localhost:8000/</a>, ins... | 0 | 2016-09-03T15:48:45Z | 39,309,933 | <p>Theres a few ways to do it, and it really depends on whether you care about redirects and how you like to organize your URL structure.</p>
<p>I would do something like this:</p>
<p>from django.conf.urls import include, url
from django.contrib import admin
from . import views
form registration.backends.hmac.views i... | 0 | 2016-09-03T18:07:09Z | [
"python",
"django",
"django-registration"
] |
python3-pip installed, but returns "command not found"? | 39,308,772 | <p>There are a few other posts I've found that address my question but none of them solve my problem so I'm creating this post.</p>
<p>I'm trying to install rpi.gpio for my Raspberry Pi B+. I installed python3-pip, but every time I try to call it from the command line with pip3 I get "command not found". I uninstall... | 0 | 2016-09-03T15:56:45Z | 39,308,917 | <p>You can always use <code>python3 -m pip</code> (possibly with <code>sudo</code>) if the library is available - like installed to the right place. This does not depend on pip being installed as a normal command which is just a shortcut for this.</p>
| 0 | 2016-09-03T16:14:57Z | [
"python",
"pip",
"raspberry-pi2"
] |
python3-pip installed, but returns "command not found"? | 39,308,772 | <p>There are a few other posts I've found that address my question but none of them solve my problem so I'm creating this post.</p>
<p>I'm trying to install rpi.gpio for my Raspberry Pi B+. I installed python3-pip, but every time I try to call it from the command line with pip3 I get "command not found". I uninstall... | 0 | 2016-09-03T15:56:45Z | 39,308,923 | <p>Try to use:</p>
<pre><code>sudo python3 -m pip
</code></pre>
<p>or</p>
<pre><code>sudo python -m pip
</code></pre>
| 0 | 2016-09-03T16:15:47Z | [
"python",
"pip",
"raspberry-pi2"
] |
python3-pip installed, but returns "command not found"? | 39,308,772 | <p>There are a few other posts I've found that address my question but none of them solve my problem so I'm creating this post.</p>
<p>I'm trying to install rpi.gpio for my Raspberry Pi B+. I installed python3-pip, but every time I try to call it from the command line with pip3 I get "command not found". I uninstall... | 0 | 2016-09-03T15:56:45Z | 39,309,012 | <p>To install <code>locate</code> run</p>
<pre><code>sudo apt-get install mlocate
</code></pre>
<p>Then update the locatedb with</p>
<pre><code>sudo updatedb
</code></pre>
<p>This could take sometime depending on the number of files you have on your machine</p>
<p>locate should work now and show you where all the ... | 2 | 2016-09-03T16:25:49Z | [
"python",
"pip",
"raspberry-pi2"
] |
Tkinter Update intvar in label | 39,308,786 | <p>I am trying to have an integer to constantly change inside a label using Tkinter.</p>
<pre><code>import tkinter
root = tkinter.Tk()
var = tkinter.IntVar()
label = tkinter.Label(root, textvariable=var)
button = tkinter.Button(root, command=lambda: var.set(var.get() + 1), text='+1')
label.pack()
button.pack()
roo... | -1 | 2016-09-03T15:57:57Z | 39,308,869 | <p>You can use <code>root.after(time_in_milisecond, function_name)</code> to call function which change value in label without user interaction.</p>
<p>Example: <a href="https://github.com/furas/my-python-codes/blob/master/tkinter/timer-using-after/clock-function.py" rel="nofollow">showing current time using after</a>... | 1 | 2016-09-03T16:08:28Z | [
"python",
"tkinter"
] |
How do I apply function to third-dimension array effectively with numpy? | 39,308,835 | <p>I want to apply arbitrary function to 3d-ndarray as element, which use (3rd-dimensional) array for its arguments and return scalar.As a result, we should get 2d-Matrix.</p>
<p>e.g) pseudo code </p>
<pre><code>A = [[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]]
A.apply_3d_array(sum) ## or apply_3d_array(A,sum) is Ok... | 1 | 2016-09-03T16:03:42Z | 39,308,953 | <p><code>apply_along_axis</code> is designed to make this task easy:</p>
<pre><code>In [683]: A=np.arange(1,13).reshape(2,2,3)
In [684]: A
Out[684]:
array([[[ 1, 2, 3],
[ 4, 5, 6]],
[[ 7, 8, 9],
[10, 11, 12]]])
In [685]: np.apply_along_axis(np.sum, 2, A)
Out[685]:
array([[ 6, 15],
... | 1 | 2016-09-03T16:18:42Z | [
"python",
"arrays",
"numpy",
"multidimensional-array",
"vectorization"
] |
How do I apply function to third-dimension array effectively with numpy? | 39,308,835 | <p>I want to apply arbitrary function to 3d-ndarray as element, which use (3rd-dimensional) array for its arguments and return scalar.As a result, we should get 2d-Matrix.</p>
<p>e.g) pseudo code </p>
<pre><code>A = [[[1,2,3],[4,5,6]],
[[7,8,9],[10,11,12]]]
A.apply_3d_array(sum) ## or apply_3d_array(A,sum) is Ok... | 1 | 2016-09-03T16:03:42Z | 39,309,371 | <p>Given the function implementation, we could vectorize it using <a href="http://docs.scipy.org/doc/numpy/reference/ufuncs.html" rel="nofollow"><code>NumPy ufuncs</code></a> that would operate on the entire input array <code>A</code> in one go and thus avoid the <code>math</code> library functions that doesn't support... | 3 | 2016-09-03T17:06:28Z | [
"python",
"arrays",
"numpy",
"multidimensional-array",
"vectorization"
] |
django:column books_book.publication_date does not exist | 39,308,840 | <p>I'm reading chapter 6 of django book:
<a href="http://www.djangobook.com/en/2.0/chapter06.html" rel="nofollow">http://www.djangobook.com/en/2.0/chapter06.html</a>
And I've done whatever chapter 5 and 6 of this book told me and I checked my work and searched the error many times but I'm still having problem when I go... | 1 | 2016-09-03T16:04:38Z | 39,309,384 | <pre><code>Please correct your code like that:
from django.contrib import admin
# Register your models here.
from django.contrib import admin
from myproject.books.models import Publisher, Author, Book
admin.site.register(Publisher)
admin.site.register(Author)
admin.site.register(Book)
</code></pre>
| -1 | 2016-09-03T17:07:52Z | [
"python",
"django"
] |
Cannot fetch choices for multiple select from in django | 39,308,850 | <p>I've got a problems with fetching choices for multiple select form. I'm trying to get choices from couchdb. It's successfully printed out into console it:<br>
[[u'c6570a56173b637d66ba2a2e390271fe', u'Rambler'], [u'c6570a56173b637d66ba2a2e3902ad1f', u'BBC']]<br>
, but it doesn't appear in template. <br>
Here's my <st... | 0 | 2016-09-03T16:06:05Z | 39,309,366 | <p>You've defined a local variable called <code>sel</code> inside your <code>__init__</code> method, but that doesn't have anything to do with the variable with the same name at global level that you used to populate the form. You'd actually have to replace the choices with your new values inside that method:</p>
<pre... | 0 | 2016-09-03T17:05:44Z | [
"python",
"django",
"couchdb"
] |
How to move a python application to another folder in server without damaging it? | 39,308,993 | <p>I am running the celery flower application (<a href="https://github.com/mher/flower" rel="nofollow">https://github.com/mher/flower</a>) in my server. I installed this application in my Python LAMP server using the following command:</p>
<pre><code>pip install flower
</code></pre>
<p>Now I want to do some modificat... | 0 | 2016-09-03T16:23:57Z | 39,309,068 | <p>Firstly, none of your application files should be in /var/www/html. That's for documents served directly by the webserver, not for code.</p>
<p>To answer your question though, if you want to modify a project you should fork it on github, make your changes there, and install from the forked repo in pip.</p>
| 1 | 2016-09-03T16:31:32Z | [
"python",
"linux",
"django",
"celery"
] |
Need help fixing a game I made in Python | 39,308,998 | <p>I have been set a task to make a fruit machine game in python, however I am facing a small problem, it involves a variable. it is saying that I have referenced the variable before it's assignment, even though I have assigned it. It seems to be reading it as a local variable instead of a global variable. How do i fix... | 1 | 2016-09-03T16:24:44Z | 39,309,050 | <p>Anytime you want to write to a global variable in another function in python, you should let python know you want to use the global variable. Before the first line of main insert:</p>
<pre><code>global Credit
</code></pre>
| 0 | 2016-09-03T16:30:02Z | [
"python",
"pygame",
"global-variables",
"local-variables"
] |
Need help fixing a game I made in Python | 39,308,998 | <p>I have been set a task to make a fruit machine game in python, however I am facing a small problem, it involves a variable. it is saying that I have referenced the variable before it's assignment, even though I have assigned it. It seems to be reading it as a local variable instead of a global variable. How do i fix... | 1 | 2016-09-03T16:24:44Z | 39,309,091 | <p>The answer to <a href="http://stackoverflow.com/questions/10588317/python-function-global-variables">this question</a> might help you (copy-pasted below).</p>
<blockquote>
<p>If you want to simply access a global variable you just use its name. However to change its value you need to use the global keyword.</p>
... | 2 | 2016-09-03T16:33:43Z | [
"python",
"pygame",
"global-variables",
"local-variables"
] |
Need help fixing a game I made in Python | 39,308,998 | <p>I have been set a task to make a fruit machine game in python, however I am facing a small problem, it involves a variable. it is saying that I have referenced the variable before it's assignment, even though I have assigned it. It seems to be reading it as a local variable instead of a global variable. How do i fix... | 1 | 2016-09-03T16:24:44Z | 39,309,288 | <p>You don't declared your variable . A variable that declared outside the function don't work into function . To use that variable you have to make the credit in this case as global variable. And then everything may become fine . All the best .</p>
<pre><code>x = something #declearing a local variable
def something()... | 0 | 2016-09-03T16:56:05Z | [
"python",
"pygame",
"global-variables",
"local-variables"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.