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 |
|---|---|---|---|---|---|---|---|---|---|
The Python "Requests" module cannot detect certain HTML link tags | 38,162,090 | <p>I'm sure this is an easy question for someone who has experience with webpage programming and basic Web Scraping (which I do not).</p>
<p>My goal is to obtain information about the many tutors that Chegg hires, by scraping their "bio" paragraphs. Although I am a novice at web-scraping, I imagine that this will invo... | 0 | 2016-07-02T16:16:33Z | 38,162,280 | <p>All the data for each expert is inside the div with the <code>expert-list-content</code> class:</p>
<pre><code>from bs4 import BeautifulSoup
import requests
soup = BeautifulSoup(requests.get("https://www.chegg.com/tutors/online-tutors/").content)
for ex in soup.select("div.expert-list-content"):
print(ex.selec... | 1 | 2016-07-02T16:35:18Z | [
"python",
"html",
"dom",
"web-scraping"
] |
Django - Permission Error when opening pipe to write | 38,162,120 | <p>I have problem with my Django application which communicates with my daemon my named pipe:</p>
<blockquote>
<p>Django application -> garage_gate_pipe -> python daemon</p>
</blockquote>
<p>The daemon is used by <code>gate</code> user, and I assumed that <code>www-data</code> is responsible for running my Django a... | 0 | 2016-07-02T16:19:41Z | 38,162,529 | <p>I changed <code>--gid</code> parameter in uwsgi command in my <code>/etc/rc.local</code> script, which is responsible for starting server on start:</p>
<pre><code>/usr/bin/uwsgi --emperor /etc/uwsgi/vassals --uid www-data --gid gate
</code></pre>
<p>Now it works.</p>
| 1 | 2016-07-02T17:02:19Z | [
"python",
"django",
"permissions",
"uwsgi",
"named-pipes"
] |
In django, how can I link a model with a user. I'd like the user to add information about their company website and name | 38,162,132 | <p>I want the users, once they are logged in, to be able to add information about their company including website, name, logo, etc.</p>
<p>I already have this model</p>
<pre><code>user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1, unique=True)
comp_name = models.CharField(max_length=120,default='', blank=T... | 0 | 2016-07-02T16:20:35Z | 38,162,267 | <pre><code>if form1.is_valid():
saveInfo = form1.save(commit=False)
comp_name = form1.cleaned_data.get("comp_name")
comp_site = form1.cleaned_data.get("comp_site")
comp_logo = form1.cleaned_data.get("comp_logo")
saveInfo.user = request.user #<--- the authenticated user bound to the current reques... | 0 | 2016-07-02T16:33:22Z | [
"python",
"django",
"django-models",
"django-forms"
] |
In django, how can I link a model with a user. I'd like the user to add information about their company website and name | 38,162,132 | <p>I want the users, once they are logged in, to be able to add information about their company including website, name, logo, etc.</p>
<p>I already have this model</p>
<pre><code>user = models.ForeignKey(settings.AUTH_USER_MODEL, default=1, unique=True)
comp_name = models.CharField(max_length=120,default='', blank=T... | 0 | 2016-07-02T16:20:35Z | 38,162,316 | <p>The <code>request</code> attribute sent with any Django specifies the current user.</p>
<pre><code>def myview(request):
current_user = request.user
</code></pre>
<p>You can check if the user is logged in using the <code>request.user.is_authenticated()</code> method. What I would do here is redirect the login v... | 0 | 2016-07-02T16:38:50Z | [
"python",
"django",
"django-models",
"django-forms"
] |
Index out of range error received, but I can't find out why? | 38,162,176 | <p>I was hoping somebody can help me with the following:</p>
<p>I have the following data in some lists in lists --> A</p>
<pre><code>A = [[['Ghost Block'], ['Ghost Block'], [-7.0, -30000.0, 84935.99999999991, 1.0, 5.0, 0, 84935.99999999991, 1, 1, ['Ghost', 3, 'Ghost', 'Ghost', 'Ghost', 'Ghost', 2, 'Ghost']], [-5.0, ... | 1 | 2016-07-02T16:23:47Z | 38,162,237 | <p>For <code>item</code> values <code>0</code> and <code>1</code>, <code>A[i][item]</code> is <code>['Ghost Block']</code>, not <code>'Ghost Block'</code> (note the 1-value list), so your <code>if</code> test never passes and the <code>else</code> block is executed instead:</p>
<pre><code>>>> A[0][0]
['Ghost ... | 1 | 2016-07-02T16:29:38Z | [
"python",
"python-2.7",
"indexoutofrangeexception"
] |
Scrapy - overcoming start_uri redirect by adding to allowed_urls dynamically - parse_start_url issues | 38,162,214 | <p>Hi Stackoverflow Community</p>
<p>I have the following problem:</p>
<p>I am trying to crawl a long list of websites. Some of the websites in the start_url list redirect (301). I want scrapy to crawl the redirected websites from start_url list as if they were also on the allowed_domain list (which they are not). Fo... | 0 | 2016-07-02T16:27:02Z | 38,162,750 | <p>Ok, I figured it out. It was actually not necessary to have the: </p>
<pre><code>def parse_start_url(...)
</code></pre>
<p>Instead, I integrated the code I previously had under <strong>def parse_start_url(...)</strong> into the spider's main <strong>def parse</strong> function:</p>
<pre><code>import scrapy
import... | 0 | 2016-07-02T17:27:52Z | [
"python",
"python-3.x",
"scrapy"
] |
Django IntegrityError email is not unique | 38,162,235 | <p>I am working on my Checkout view with regular/guest user but getting hard time to come around the integrity error. Idea is to let guest users register with email only to checkout and I need to set the user email unique. </p>
<p>models.py</p>
<pre><code>from django.conf import settings
from django.db import models
... | 1 | 2016-07-02T16:14:01Z | 38,160,717 | <p>The <code>clean_<fieldname></code> methods of a <code>Form</code> are used to perform validation relative to single field. If you need validation with access to multiple fields, use the <code>clean</code> method. Check the <a href="https://docs.djangoproject.com/en/1.9/ref/forms/validation/" rel="nofollow">doc... | 1 | 2016-07-02T13:30:51Z | [
"python",
"django"
] |
Django IntegrityError email is not unique | 38,162,235 | <p>I am working on my Checkout view with regular/guest user but getting hard time to come around the integrity error. Idea is to let guest users register with email only to checkout and I need to set the user email unique. </p>
<p>models.py</p>
<pre><code>from django.conf import settings
from django.db import models
... | 1 | 2016-07-02T16:14:01Z | 38,162,870 | <p>You create every time when a checkout occurs an new <code>UserCheckout</code>. And in all these entries it is only allowed that every email exists only once.</p>
<p>I don't think you want this. Because if a guest orders two times it isn't allowed because his email is already in the DB. And that's why you get this e... | 3 | 2016-07-02T17:40:32Z | [
"python",
"django"
] |
python regex(VALIDATING ROMAN NUMBERS) | 38,162,251 | <pre><code>import re
print( True if (re.search(r"^M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})$",input())) else False)
</code></pre>
<p>in the following code that which check if a given roman numerical is valid or not why is a different answer printed when ^ and $ are not included in the print statement, et... | 1 | 2016-07-02T16:31:49Z | 38,162,346 | <p>Short answer: Because <code>re.search()</code> and <code>re.match()</code> are not the same.</p>
<p><code>re.search()</code> searches for a match to the given pattern in the entire input, while <code>re.match()</code> requires the pattern to match at the beginning of the input.
Independent of that, you can force th... | 3 | 2016-07-02T16:42:16Z | [
"python"
] |
Tastypie get full resource only works the second time | 38,162,293 | <p>I'm developing an Android application with backend developed using Tastypie and Django. I have a get request for which I want to optionally be able to retrieve the entire object (with complete related fields, rather than URIs). Below is part of the python code for the resource I'm talking about:</p>
<pre><code>clas... | 0 | 2016-07-02T16:36:19Z | 38,169,856 | <p><code>dehydrate</code> is called after <code>full_dehydrate</code>. Overwrite <code>full_dehydrate</code> function.</p>
<pre><code>def full_dehydrate(self, bundle, for_list=False):
self.path.full = bundle.request.GET.get('full_path') == "1"
return super(RideResource, self).full_dehydrate(bundle, for_list)
<... | 1 | 2016-07-03T12:16:14Z | [
"python",
"django",
"tastypie"
] |
Django sitemap static pages | 38,162,327 | <p>I have a website containing dynamic pages for Content which is added and removed periodically. Along with that the website also has static pages that always exist like /, /about, /how-it-works etc.
I have configured my sitemaps.py file to load all the dynamic content pages in the sitemap.</p>
<p><strong>sitemap.xml... | 0 | 2016-07-02T16:39:44Z | 38,162,953 | <p>After a bit of searching I found this <a href="http://stackoverflow.com/questions/4836188/django-sitemaps-and-normal-views">Django Sitemaps and "normal" views</a>. Following along Matt Austin's answer I was able to achieve what I wanted. I'll leave what I did, here for future reference.</p>
<p><strong>sit... | 0 | 2016-07-02T17:50:48Z | [
"python",
"django",
"sitemap"
] |
Python to EXE builds a nothing-doing file | 38,162,337 | <p>I used <a href="https://pypi.python.org/pypi/cx_Freeze" rel="nofollow">cx_Freeze</a> module to convert my Python applications to Windows.</p>
<p>I have a simple Python file <code>norm.py</code> :</p>
<pre><code>print("Hi there !")
</code></pre>
<p>Another file <code>makeup.py</code> to convert the above into exe:... | 1 | 2016-07-02T16:41:21Z | 38,163,346 | <p>You are creating a GUI application using </p>
<pre><code>if sys.platform == "win32":
os_base = "Win32GUI"
</code></pre>
<p>You should remove this, in order to build a console application.</p>
| 1 | 2016-07-02T18:37:56Z | [
"python",
"python-3.x",
"cx-freeze"
] |
Python regex match space only | 38,162,444 | <p>In python3, how do I match exactly whitespace character and not newline \n or tab \t?</p>
<p>I've seen the <code>\s+[^\n]</code> answer from <a href="http://stackoverflow.com/questions/14190038/regex-match-space-not-n">Regex match space not \n</a> answer, but for the following example it does not work:</p>
<pre>... | 0 | 2016-07-02T16:53:31Z | 38,162,461 | <p>If you want to match 1 or more whitespace chars except the newline and a tab use</p>
<pre><code>r"[^\S\n\t]+"
</code></pre>
<p>The <code>[^\S]</code> matches any char that is not a non-whitespace = any char that is whitespace. However, since the character class is a negated one, when you add characters to it they ... | 4 | 2016-07-02T16:55:06Z | [
"python",
"regex"
] |
Python regex match space only | 38,162,444 | <p>In python3, how do I match exactly whitespace character and not newline \n or tab \t?</p>
<p>I've seen the <code>\s+[^\n]</code> answer from <a href="http://stackoverflow.com/questions/14190038/regex-match-space-not-n">Regex match space not \n</a> answer, but for the following example it does not work:</p>
<pre>... | 0 | 2016-07-02T16:53:31Z | 38,162,969 | <p>No need for special groups. Just create a regex with a space character. The space character does not have any special meaning, it just means "match a space".</p>
<pre><code>RE = re.compile(' +')
</code></pre>
<p>So for your case</p>
<pre><code>a='rasd\nsa sd'
print(re.search(' +', a))
</code></pre>
<p>would give... | 0 | 2016-07-02T17:53:00Z | [
"python",
"regex"
] |
Running pySpark in Jupyter notebooks - Windows | 38,162,476 | <p>I would like to run pySpark from Jupyter notebook. I downloaded and installed Anaconda which had Juptyer. I created the following lines </p>
<pre><code> from pyspark import SparkConf, SparkContext
conf = SparkConf().setMaster("local").setAppName("My App")
sc = SparkContext(conf = conf)
</code></pre>
<p>I get the... | 0 | 2016-07-02T16:56:19Z | 38,407,093 | <p>This worked for me:</p>
<pre><code>import os
import sys
spark_path = "D:\spark"
os.environ['SPARK_HOME'] = spark_path
os.environ['HADOOP_HOME'] = spark_path
sys.path.append(spark_path + "/bin")
sys.path.append(spark_path + "/python")
sys.path.append(spark_path + "/python/pyspark/")
sys.path.append(spark_path + "... | 1 | 2016-07-16T02:19:43Z | [
"python",
"pyspark",
"jupyter"
] |
iPython can't find package | 38,162,483 | <p>First of all, I´m on windows, with conda installed. The steps I followed:</p>
<pre><code>conda create -n snowflakes python
pip install pykml
</code></pre>
<p>After I do this, I can access pykml if I type
py
(Enters python command line with >>>)
but I can't if I type ipython
(opens python cmdline with [1]).</p... | 0 | 2016-07-02T16:57:31Z | 38,188,667 | <p>It looks like you have created a new conda environment named <code>snowflakes</code> but that you installed pykml in your root environment. Probably your ipython and your python are in different environments -- what does <code>where ipython</code> and <code>where python</code> return? </p>
<p>Try the following:</... | 0 | 2016-07-04T16:01:09Z | [
"python",
"windows",
"conda"
] |
why dropna() is not working as I expect it to? | 38,162,539 | <p>I have asked this question already once but deleted it because it did not address the issue in the correct way.</p>
<p>I want to drop all rows that contain <code>NaN</code>. I am quite sure I would need to apply </p>
<pre><code>df.dropna(how='all', inplace=True)
</code></pre>
<p>to achieve what I need. But for so... | 1 | 2016-07-02T17:03:30Z | 38,162,572 | <p><code>how='all'</code> doesn't mean "drop <em>all</em> rows which contain a NaN", it means "drop rows which are <em>all</em> NaN". You want <code>how='any'</code>, which means "drop rows which contain <em>any</em> NaN".</p>
<pre><code>>>> df.dropna(how='all')
60DAY_IMPVOL Close
Date ... | 2 | 2016-07-02T17:07:40Z | [
"python",
"pandas"
] |
decoding to ut8 not working python | 38,162,614 | <p>I am trying to scrape some data from a website in german. The code is as follows:</p>
<pre><code># -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
import urllib2, requests
import time, sys
from selenium import webdriver
import os, sys
reload(sys)
sys.setdefaultencoding('utf-8')
chromedriver = "./chromedriver"
... | 0 | 2016-07-02T17:11:40Z | 38,162,755 | <p>You decode from str to unicode and encode from unicode to str. <code>tag.text.encode('utf-8')</code> obviously gives you exactly what you asked for, just call <code>tag.text</code> as you already have a unicode string:</p>
<pre><code> [tag.get_attribute('class'),tag.text]
</code></pre>
<p>Also avoid <code>reload(s... | 2 | 2016-07-02T17:28:28Z | [
"python",
"encode",
"python-unicode"
] |
xlwings:change the color of character from Python | 38,162,639 | <p>I'm useing xlwings on a Windows.I'd like to change the color of the character input to a cell.But the cord isn't understood.Please give the assistance.Thank you.</p>
| 0 | 2016-07-02T17:14:55Z | 38,187,205 | <p>This is currently not yet natively implemented. On Windows, you can fall back to <code>pywin32</code>, see <a href="http://docs.xlwings.org/en/stable/missing_features.html" rel="nofollow">here</a>.</p>
<p>In your case, the following should work:</p>
<pre><code>import xlwings as xw
wb = xw.Workbook.active()
xw.Rang... | 0 | 2016-07-04T14:34:50Z | [
"python",
"colors",
"character",
"xlwings"
] |
Python udp performance | 38,162,706 | <p>I am setting up a pretty simple message server using TCP and UDP on different ports on a Raspberry PI 2 with wifi. I am using UDP for multi-cast. The server works fine. The problem is that the processor jumps to about 30% processor usage when I run the server (TCP and UDP listeners). This isn't processing anythi... | 2 | 2016-07-02T17:21:51Z | 38,676,238 | <p>It took me a while to get back to this, but J.F. Sebastian has the solution. I implemented <code>asyncio</code> and it works with very little overhead. I straight copied the demo from Python <a href="https://docs.python.org/dev/library/asyncio-protocol.html#asyncio-udp-echo-server-protocol" rel="nofollow">document... | 1 | 2016-07-30T16:43:21Z | [
"python",
"performance",
"sockets"
] |
in python bash saying print is not a command | 38,162,767 | <p>I am just starting to learn Python.</p>
<p>Yesterday I started python and got</p>
<pre><code>>>>
</code></pre>
<p>I entered <code>hello world</code> and it worked.</p>
<p>Yet, today I get that bash doesn't recognize <code>print</code>. I am working on a course from Coursera and it requires python 2.7.<... | -1 | 2016-07-02T17:30:05Z | 38,164,143 | <p>As alluded to in the comments, <code>bash</code> is a shell and command language while Python is a high-level programming language.</p>
<p>To get what you want in Python, use the <code>print</code> command </p>
<p><a href="http://i.stack.imgur.com/AmSrT.png" rel="nofollow"><img src="http://i.stack.imgur.com/AmSrT.... | 0 | 2016-07-02T20:19:38Z | [
"python",
"bash",
"python-2.7",
"python-3.x"
] |
Amazon Simple Product API error when looking up product | 38,162,779 | <pre><code>from amazon.api import AmazonAPI
AMAZON_ACCESS_KEY = "A******************A"
AMAZON_SECRET_KEY = "7***********************E"
AMAZON_ASSOC_TAG = "j*****-20"
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region='US')
print(amazon)
#product = amazon.lookup(ItemId='B002RL8FBQ')
</co... | 6 | 2016-07-02T17:31:06Z | 38,192,547 | <p>You might need to authorize your account for <a href="https://affiliate-program.amazon.com/gp/advertising/api/registration/pipeline.html" rel="nofollow">API access</a>. This <a href="http://www.wp-amazon-plugin.com/register-amazon-affiliate-product-advertising-api/" rel="nofollow">step-by-step</a> should walk you th... | -1 | 2016-07-04T21:41:21Z | [
"python",
"amazon-web-services",
"python-3.4"
] |
Amazon Simple Product API error when looking up product | 38,162,779 | <pre><code>from amazon.api import AmazonAPI
AMAZON_ACCESS_KEY = "A******************A"
AMAZON_SECRET_KEY = "7***********************E"
AMAZON_ASSOC_TAG = "j*****-20"
amazon = AmazonAPI(AMAZON_ACCESS_KEY, AMAZON_SECRET_KEY, AMAZON_ASSOC_TAG, region='US')
print(amazon)
#product = amazon.lookup(ItemId='B002RL8FBQ')
</co... | 6 | 2016-07-02T17:31:06Z | 38,291,898 | <p>I think, problem is with region. Please select valid value <a href="http://docs.aws.amazon.com/general/latest/gr/rande.html" rel="nofollow">from here</a>. Explanation can be that AWS can validate your credentials, but when it comes to "real" call it fails, since 'US' is not valid region...</p>
| 0 | 2016-07-10T12:32:49Z | [
"python",
"amazon-web-services",
"python-3.4"
] |
Limiting the amount of times a User can make a comment | 38,162,852 | <p>Say I have django models like so </p>
<pre><code>class Comment(models.Model):
commentDescription = models.CharField(max_length=60)
commentOwner = models.ForeignKey(User1,null=True)
post = models.ForeignKey(Post, null=True)
class Post(models.Model):
postDescription = models.CharField(max_length=200)... | 0 | 2016-07-02T17:39:19Z | 38,162,998 | <p>Edit: Whoops, missunderstood your question. Thought you would like to limit voting timebased, not with an absolut voting count :).</p>
<p>I would add a <a href="https://docs.djangoproject.com/en/dev/ref/forms/fields/#datetimefield" rel="nofollow">DateTimeField</a> to the <code>Comment</code> model and then check in... | 1 | 2016-07-02T17:57:01Z | [
"python",
"django"
] |
Limiting the amount of times a User can make a comment | 38,162,852 | <p>Say I have django models like so </p>
<pre><code>class Comment(models.Model):
commentDescription = models.CharField(max_length=60)
commentOwner = models.ForeignKey(User1,null=True)
post = models.ForeignKey(Post, null=True)
class Post(models.Model):
postDescription = models.CharField(max_length=200)... | 0 | 2016-07-02T17:39:19Z | 38,163,022 | <p>For a given user trying to comment on a given post, you can call the following method. <code>user</code> and <code>post</code> should be instances of the <code>User1</code> and <code>Post</code> model respectively.</p>
<pre><code>def allow_comment(user, post):
user_comments = post.comment_set.filter(
co... | 0 | 2016-07-02T17:59:41Z | [
"python",
"django"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,162,896 | <p>Use a dictionary to collect inverted indices into, use <code>enumerate()</code> to generate indices for the <code>a</code> entries:</p>
<pre><code>inverted = {}
for index, numbers in enumerate(a):
for number in numbers:
inverted.setdefault(number, []).append(index)
b = [inverted.get(i, []) for i in ra... | 5 | 2016-07-02T17:43:32Z | [
"python",
"list"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,162,944 | <p>Assuming that each index appears only twice, the following code works:</p>
<pre><code>from itertools import chain
a = [[2],
[0, 1, 3, 2],
[1],
[0, 3]]
b = (max(chain(*a)) + 1) * [None]
for i, lst in enumerate(a):
for j in lst:
if not b[j]:
b[j] = [i, None]
else:
... | 1 | 2016-07-02T17:49:29Z | [
"python",
"list"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,162,985 | <p>This code <em>doesn't</em> rely on the fact that each number appears exactly twice. It's also quite straightforward and avoids the overhead of building a dictionary and then copying the results from there:</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
b = []
for i, nums... | 5 | 2016-07-02T17:54:55Z | [
"python",
"list"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,163,035 | <p>Here's a pretty straightforward <code>O(n)</code> solution that uses lists only and also:</p>
<ul>
<li>doesn't rely on the fact that each index appears twice in <code>a</code>.</li>
<li>doesn't make assumptions about the range of values in <code>a</code>.</li>
</ul>
<p></p>
<pre><code>a = [[2], [0, 1, 3, 2], [1],... | 1 | 2016-07-02T18:01:01Z | [
"python",
"list"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,163,160 | <p>This should work:</p>
<pre><code>import itertools
b = [[] for _ in range(1 + max(itertools.chain.from_iterable(a)))]
for i, lst in enumerate(a):
for j in lst:
if i not in b[j]:
b[j].append(i)
</code></pre>
<p>Notice that the code above doesn't assume that the range of the values that can ap... | 1 | 2016-07-02T18:14:23Z | [
"python",
"list"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,163,220 | <pre><code>>>> a = [[2], [0, 1, 3, 2], [1], [0, 3]]
>>> b = [[] for _ in range(sum(map(len, a)) / 2)]
>>> for u, edges in enumerate(a):
for edge in edges:
b[edge].append(u)
>>> b
[[1, 3], [1, 2], [0, 1], [1, 3]]
</code></pre>
| 1 | 2016-07-02T18:22:50Z | [
"python",
"list"
] |
Invert list of lists of indices | 38,162,862 | <p>I have a list of lists of indices, e.g.,</p>
<pre><code>a = [
[2],
[0, 1, 3, 2],
[1],
[0, 3]
]
</code></pre>
<p>I'd now like to "invert" this list: The number <code>0</code> appears at indices <code>1</code> and <code>3</code>, so:</p>
<pre><code>b = [
[1, 3],
[1, 2],
[0, 1],
... | 1 | 2016-07-02T17:40:07Z | 38,167,799 | <p>Basically the same as <a href="http://stackoverflow.com/a/38162985/4451578">smarx's</a> answer. Except this one deletes item in your original array as you go along, making the algorithm more efficient on memory (depending on how the garbage collector is implemented)</p>
<pre><code>a = [
[2],
[0, 1, ... | 0 | 2016-07-03T07:46:03Z | [
"python",
"list"
] |
text moving to the next line python 3.4 | 38,162,864 | <p>This is my first attempt at writing something in Python. I'm not understanding why the text is going to the next line. I want it to be:</p>
<p><strong>Would you like to delete "event"?<br>
Y or N</strong></p>
<p>But it prints as:</p>
<p><strong>Would you like to delete "event<br>
"?
Y or N</strong></p>
<p>T... | 0 | 2016-07-02T17:40:13Z | 38,162,984 | <p>The reason is the mixing up of the single and double quotes, then escaping the <strong>newLine</strong> and the double quote all together in the same line</p>
<p>try instead something like</p>
<pre><code>input('Would you like to delete ' '\"' + event + '\"?' '\n' Y or N' '\n')
</code></pre>
| 0 | 2016-07-02T17:54:55Z | [
"python",
"python-3.4"
] |
Multyvac username and password | 38,162,906 | <p><strong>Goal:</strong> to setup multyvac on ubuntu 16.04 </p>
<p><strong>Steps followed:</strong></p>
<p><strong>1)</strong> $ pip install vac (and/or pip install multyvac)</p>
<p><strong>2)</strong> $ python -m multyvac.setup</p>
<p>Welcome to Multyvac.</p>
<p>If you input your Multyvac username and password, ... | 0 | 2016-07-02T17:45:10Z | 38,166,250 | <p>The username and password you entered in step 2 don't exist. You'll need a Multyvac account, then redo step 2, and use the same username and password you would use on <a href="https://www.multyvac.com/account/login/" rel="nofollow">this</a> page.</p>
| 0 | 2016-07-03T02:36:34Z | [
"python",
"passwords",
"username",
"api-key"
] |
Page not found(404) | 38,162,919 | <p>Am doing this simple company appraisal application that probably has detail views. whereas the list view displays normally, whenever i click to view it's details, i get the page not found (404) error. It works in that if you are to click on a department (list view), it had to take you to a detail page which shows th... | 0 | 2016-07-02T17:46:05Z | 38,162,947 | <p>your link is buggy <code>http://127.0.0.1:8000/1//</code> one slash too many at the end</p>
<p>it should be either <code>http://127.0.0.1:8000/1/</code> or <code>http://127.0.0.1:8000/</code> for urls to match correctly</p>
<p>you probably have wrong link building in template. </p>
| 0 | 2016-07-02T17:49:46Z | [
"python",
"django",
"django-views"
] |
What does overrideredirect do? | 38,162,932 | <p>I have come to understand overrideredirect helps removing the default window decorations like the toolbar.What are its other uses? I am not very sure and couldn't find much documentation.<br/><br/>
I am working on a mac. Using tkinter I want to obtain window which remains maxsize and cannot be resized,which i have ... | 1 | 2016-07-02T17:47:59Z | 38,167,065 | <p>You can use <a href="http://effbot.org/tkinterbook/wm.htm#Tkinter.Wm.overrideredirect-method" rel="nofollow"><code>overrideredirect()</code></a> and set its flag to <strong><code>True</code></strong>. This will disable your window to be closed by <em>regular means</em> as mentioed in the link above. By <em>regular m... | 1 | 2016-07-03T05:38:29Z | [
"python",
"tkinter"
] |
Send email to work email address from smtplib | 38,162,955 | <p>I have the following code to send mails through python to an email address.
It's not working when I'm putting my work email address in the 'toaddrs' variable.
It doesn't give an error, but I don't get any mails.But I'm able to send mails from and to the same address from the gmail through the browser.
Can anyone hel... | 0 | 2016-07-02T17:51:18Z | 38,168,134 | <p>Check if you can send and retrieve the email when you send it to your own gmail address, i.e. <code>toaddrs = fromaddr</code>.</p>
<p>Your emails might get rejected by your work server because the header is missing, have a look at <a href="https://docs.python.org/3.5/library/email-examples.html" rel="nofollow">http... | 0 | 2016-07-03T08:30:54Z | [
"python",
"email",
"gmail",
"smtplib"
] |
ValueError: operands could not be broadcast together with shapes (200,49000) (10,49000) (200,49000) | 38,163,054 | <p>This</p>
<pre><code>a=np.zeros((20,4900))
b=np.zeros((1,4900))
a+=b
</code></pre>
<p>works perfectly fine. However, this:</p>
<pre><code>a=np.zeros((200,49000))
b=np.zeros((10,49000))
a+=b
</code></pre>
<p>shows this error:</p>
<pre><code>ValueError: operands could not be broadcast together with shapes (200... | 0 | 2016-07-02T18:03:35Z | 38,163,100 | <p><strong>Edit:</strong></p>
<p>Numpy only lets you add two matrices of <strong>unequal dimension</strong> if and only if either matrix A or B is 1 row in height. This is called broadcasting. Basic linear algebra says that you are trying to do an invalid matrix operation since both matrices must be of the same dimens... | 2 | 2016-07-02T18:07:56Z | [
"python",
"numpy",
"numpy-broadcasting"
] |
Python Guess number game - While loop not responding | 38,163,103 | <p>I am a relative newcomer and was trying to create a game where the user and the comp take turns at guessing each others games. I know I am doing something wrong in the while / if operators when the user enters a string eg. Y. </p>
<p>In two places:<br>
1. where the user decides who should go first (<code>if a in [... | 0 | 2016-07-02T18:08:06Z | 38,163,129 | <pre><code>while ans = False:
</code></pre>
<p>should be </p>
<pre><code>while ans == False:
</code></pre>
| 0 | 2016-07-02T18:10:57Z | [
"python"
] |
Python Guess number game - While loop not responding | 38,163,103 | <p>I am a relative newcomer and was trying to create a game where the user and the comp take turns at guessing each others games. I know I am doing something wrong in the while / if operators when the user enters a string eg. Y. </p>
<p>In two places:<br>
1. where the user decides who should go first (<code>if a in [... | 0 | 2016-07-02T18:08:06Z | 38,163,146 | <pre><code>print ("Is the number", c , "?")
d = input("Enter Y if correct / L if your number is lower or H if higher:")
if d in ["Y" , "y"]:
ans = True
elif d in ["H"]:
high = c
c = int((c + low) / 2)
compscore = compscore + 1
elif d in ["L"]:
low = c
c = ... | 0 | 2016-07-02T18:13:08Z | [
"python"
] |
Python Guess number game - While loop not responding | 38,163,103 | <p>I am a relative newcomer and was trying to create a game where the user and the comp take turns at guessing each others games. I know I am doing something wrong in the while / if operators when the user enters a string eg. Y. </p>
<p>In two places:<br>
1. where the user decides who should go first (<code>if a in [... | 0 | 2016-07-02T18:08:06Z | 38,163,243 | <p>I'd change your while loop condition to:</p>
<p><code>while not ans:</code></p>
<p>Also, in <code>r.randint(1,100)</code>, <code>r</code> is undefined. If you want to use a function from random, you need to import it:</p>
<p>You could do either <code>import random</code> or <code>from random import randint</code>... | 1 | 2016-07-02T18:25:56Z | [
"python"
] |
Aggregate and postpone function execution in Python | 38,163,244 | <p>I have my own function in python which is called occasionally by some other code many times per second. My function looks like this:</p>
<pre><code>def doIt(id):
doSomething(id)
</code></pre>
<p>As a consequence doSomething() is called same number of times as doIt() and that is causing troubles. How can I aggr... | -1 | 2016-07-02T18:26:06Z | 38,166,216 | <p>Hmm. If I'm reading this right, your problem is that someone could call <code>doIt(10)</code> multiple times in five seconds, but you'd only want <code>doSomething(10)</code> to be called once per five seconds.</p>
<p>In that case, you can do this without threads relatively easily; <code>doIt()</code> can remember... | 0 | 2016-07-03T02:28:08Z | [
"python"
] |
Creating logical array from numpy array | 38,163,257 | <p>I have a very large numpy array in Python full of meteorological data. In order to observe flawed data, I would like to look at every value and test it to see if it is less than -1. Eventually I would like to represent this with a logical array of 0's and 1's with 1 representing indices where the value is less than ... | -1 | 2016-07-02T18:27:43Z | 38,163,320 | <p>This works for your case, which directly converts the type from <code>logical</code> to <code>int</code>:</p>
<pre><code>(matdat < -1).astype(int)
</code></pre>
<p>Or for <code>np.where</code>, the syntax needs to be:</p>
<pre><code>np.where(matdat < -1, 1, 0)
</code></pre>
| 1 | 2016-07-02T18:35:28Z | [
"python",
"arrays",
"numpy"
] |
How to plot frequency of one event with respect to other? | 38,163,321 | <p>I want to use python/matplotlib/pandas for my purpose.</p>
<p>Problem description: I have an excel sheet (which I can read as a pandas dataframe) containing a table of true and estimated values. I want to somehow capture this information over a plot of actual (horizontal axis) vs estimated values (vertical axis). T... | 1 | 2016-07-02T18:35:41Z | 38,217,207 | <p>In order to make that table into a plot similar to the one you link to, I would first make an array with values with one axis corresponding to "actual value" and the other to "estimated value" (thus including all the zero values that are not in your table above): </p>
<pre><code>import matplotlib.pyplot as plt
impo... | 0 | 2016-07-06T06:01:24Z | [
"python",
"excel",
"pandas",
"matplotlib"
] |
Python : Split list in a specific way? | 38,163,366 | <p>Let's say I have a list <code>A</code></p>
<pre><code>A = [1,2,3,4,5,6,7,8,9,10]
</code></pre>
<p>I would like to create a new list (say <code>B</code>) using the above list in the following order.</p>
<pre><code>B = [[1,2,3], [3,4,5], [5,6,7], [7,8,9], [9,10,]]
</code></pre>
<p><strong>i.e. the first 3 numbers ... | 0 | 2016-07-02T18:40:32Z | 38,163,806 | <p>The 'duplicate' <a href="http://stackoverflow.com/questions/14406567/paritition-array-into-n-chunks-with-numpy">Paritition array into N chunks with Numpy</a> suggests <code>np.split</code> - that's fine for non-overlapping splits. The example (added after the close?) overlaps, one element across each subarray. Plu... | 1 | 2016-07-02T19:37:46Z | [
"python",
"list",
"numpy"
] |
Python : Split list in a specific way? | 38,163,366 | <p>Let's say I have a list <code>A</code></p>
<pre><code>A = [1,2,3,4,5,6,7,8,9,10]
</code></pre>
<p>I would like to create a new list (say <code>B</code>) using the above list in the following order.</p>
<pre><code>B = [[1,2,3], [3,4,5], [5,6,7], [7,8,9], [9,10,]]
</code></pre>
<p><strong>i.e. the first 3 numbers ... | 0 | 2016-07-02T18:40:32Z | 38,163,917 | <p>Simply use Python's built-in list comprehension with list-slicing to do this:</p>
<pre><code>>>> A = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> size = 3
>>> step = 2
>>> A = [A[i : i + size] for i in range(0, len(A), step)]
</code></pre>
<p>This gives you what you're looking for:</p>
... | 4 | 2016-07-02T19:51:12Z | [
"python",
"list",
"numpy"
] |
I cannot figure out why I am getting AttributeError | 38,163,375 | <p>Dear StackOverflow Angels, </p>
<p>I am really stuck with this problem. I am coding a game and am receiving this error message: </p>
<pre><code>File "VillageGame.py", line 120, in <module>
launch.play()
File "VillageGame.py", line 84, in play
returned_scene = future_scene.enter()
AttributeError: 'NoneType' o... | 2 | 2016-07-02T18:41:53Z | 38,163,461 | <p>The problem is <code>Map('road')</code> returns <code>None</code>. I think what you're trying to do is this.</p>
<pre><code>map = Map('road')
firstscene = map.launch_scene()
launch = Engine(firstscene)
launch.play()
</code></pre>
<p>But even that is not quite right. The line below doesn't instantiate a map.</p>
... | 2 | 2016-07-02T18:50:48Z | [
"python",
"class",
"object",
"attributeerror"
] |
I cannot figure out why I am getting AttributeError | 38,163,375 | <p>Dear StackOverflow Angels, </p>
<p>I am really stuck with this problem. I am coding a game and am receiving this error message: </p>
<pre><code>File "VillageGame.py", line 120, in <module>
launch.play()
File "VillageGame.py", line 84, in play
returned_scene = future_scene.enter()
AttributeError: 'NoneType' o... | 2 | 2016-07-02T18:41:53Z | 38,163,467 | <p>This line <code>returned_scene = future_scene.enter()</code> expects a return value but you haven't implemented anything in the method<code>def enter(self)</code> (you're just <code>pass</code>-ing it, and so it returns a <code>None</code> object.</p>
| 1 | 2016-07-02T18:51:30Z | [
"python",
"class",
"object",
"attributeerror"
] |
BST remove function, trying to add odd and even numbers to determine which loop to enter | 38,163,415 | <p>What I'm trying to do, Im not done with it yet, but I have this code right now:</p>
<pre><code>def delete(self):
t=1
if isinstance(self.root,odd):
child=self.left
grandchild=child.right
if self.left == self.right==None:
return None
if self.left==None:
... | 0 | 2016-07-02T18:46:20Z | 38,163,554 | <p>From what I understood, you want to figure whether t is <code>odd or even</code>.</p>
<p>You should use the <a href="http://stackoverflow.com/questions/4432208/how-does-work-in-python">% (Modulo) operator</a>.</p>
<pre><code>if t%2 == 0: # then it is even (divisible by 2)
if t%2 == 1: # it is odd (not divisible by... | 3 | 2016-07-02T19:05:33Z | [
"python",
"methods",
"counter"
] |
Similar validation functions don't work | 38,163,462 | <p>First of all, sorry for not using OOP, I just decided to avoid complexity for such a small program.
So here's my program (basically, it's an Entry widget that allows a text that only consists of integers whose maximum length is 5):</p>
<pre><code>from tkinter import *
root = Tk()
root.title("Entry Validation")
root... | 0 | 2016-07-02T18:50:48Z | 38,163,477 | <p><code>text</code> is an <code>int</code> ... you cannot call <code>len(int)</code> ... it will raise an exception</p>
<p>try this</p>
<pre><code>def validation_function(text):
try:
int(text)
except:
return False
if len(text) <= 5:
return True
return False
</code></pre>
| 3 | 2016-07-02T18:52:57Z | [
"python",
"validation",
"python-3.x",
"tkinter",
"entry"
] |
Trigonometric identities | 38,163,492 | <p>I have an expression which has both sines and cosines and would like to write it using only sines (or cosines), possibly using the <a href="https://en.wikipedia.org/wiki/List_of_trigonometric_identities#Power-reduction_formula" rel="nofollow">power-reduction formula</a>.</p>
<p>I tried to use SymPy but I cannot mak... | 4 | 2016-07-02T18:54:53Z | 38,163,888 | <p><a href="https://github.com/sympy/sympy/blob/master/sympy/simplify/fu.py" rel="nofollow">The <code>sympy.simplify.fu</code> module</a> defines a number of transformations based on trig identities:</p>
<pre><code>TR0 - simplify expression
TR1 - sec-csc to cos-sin
TR2 - tan-cot to sin-cos ratio
TR2i - sin-cos ratio t... | 3 | 2016-07-02T19:46:10Z | [
"python",
"math",
"trigonometry",
"sympy"
] |
Python importation error with Ghost.py | 38,163,494 | <p><a href="http://i.stack.imgur.com/7mnoW.png" rel="nofollow">Ghost.py is correctly installed, though it can't find it's module</a></p>
| -5 | 2016-07-02T18:55:00Z | 38,163,574 | <p>Do you know where the module is installed? If so is that location in the PYTHONPATH?</p>
<p>Check PYTHONPATH with:</p>
<pre><code>import sys
print(sys.path)
</code></pre>
<p>PYTHONPATH can be modified for the duration of your script using:</p>
<pre><code>sys.path.append('/path/to/ghost.py')
</code></pre>
<p>Or ... | 0 | 2016-07-02T19:07:11Z | [
"python",
"python-module",
"ghost.py"
] |
How to align rectangle to center of parent with Kivy | 38,163,528 | <p>I'm trying to draw a border around a <code>FloatLayout</code>. To do this I'm adding two rectangles to the canvas, the second one slightly smaller than the layout of it's parent. This works. However, aligning a rectangle to the center of the canvas has proven elusive. The second rectangle needs to be centered to it'... | 0 | 2016-07-02T19:02:17Z | 38,164,611 | <p>I'm not sure what effect you're after, but either way you can just manage the offset manually. I've also added Color to distinguish the rectangles.</p>
<p>Here's an example with a 50 pixel offset:</p>
<pre><code>Color:
rgba: 0, 1, 0, 1
Rectangle:
size: self.width, self.height
pos: self.pos
Color:
r... | 0 | 2016-07-02T21:25:33Z | [
"python",
"kivy"
] |
How to align rectangle to center of parent with Kivy | 38,163,528 | <p>I'm trying to draw a border around a <code>FloatLayout</code>. To do this I'm adding two rectangles to the canvas, the second one slightly smaller than the layout of it's parent. This works. However, aligning a rectangle to the center of the canvas has proven elusive. The second rectangle needs to be centered to it'... | 0 | 2016-07-02T19:02:17Z | 38,164,648 | <p>This also works.</p>
<pre><code> Rectangle:
size: (self.width -4.0, self.height - 4.0)
pos: ((self.right - self.width + 2.0),(self.top - self.height + 2.0))
</code></pre>
| 0 | 2016-07-02T21:31:12Z | [
"python",
"kivy"
] |
How to join two pandas DataFrames in a "horizontal union" with python3 | 38,163,585 | <p>I have to large .csv files that I'm handling with python, pandas and numpy, here is a sample from the more granular data set (A), the time stamps are in 15 minute intervals:</p>
<pre><code>Timestamp,Real Energy Into the Load
2016-06-01T11:00:00, 2
2016-06-01T10:45:00, 1
2016-06-01T10:30:00, 5
2016-06-01T10:15:00, 3... | 2 | 2016-07-02T19:09:09Z | 38,164,157 | <p>May be you can do something like below. I haven't checked whether it works if there are no values during an hour, but this is the idea. </p>
<pre><code>In[1]: import pandas as pd
In[2]: import numpy as np
In[3]: df1 = pd.DataFrame({"TemperatureF": np.random.random_integers(60, 90, 20), "DewPointF": np.random.rand... | 1 | 2016-07-02T20:21:29Z | [
"python",
"python-3.x",
"pandas",
"group-by"
] |
When trying to extract meta data out of images on webpages, keeps returning {}, why? | 38,163,702 | <p>I've looked at the exifread documentation and it says that it's returned as a dictionary, but the problem is that it returns nothing except {}, I don't know if that means there is no meta data in the image, or I made a nooby mistake, well anyway I've spend a good chunk of time looking at my code and documentation, b... | 1 | 2016-07-02T19:24:03Z | 38,164,286 | <p>The problem is you were not passing a <em>base url</em>, you need to pass the host and then join that to the <em>src</em> unless you get an absolute <em>url</em> from the src attribute.</p>
<p>The following code demonstrates a working example, I used <a href="http://docs.python-requests.org/en/master/" rel="nofollo... | 0 | 2016-07-02T20:37:18Z | [
"python",
"beautifulsoup",
"metadata"
] |
Recursive loops with increasing size/arguments (Hamiltonian Paths?) Python | 38,163,710 | <p>I have a code that takes <code>n</code> inputs and computes the shortest distance between them without ever revisiting the same point twice. I think this the same as the Hamiltonian Path problem.</p>
<p>My code takes <code>n</code> addresses as inputs and iterates over all possible combinations without repeating. R... | 0 | 2016-07-02T19:24:52Z | 38,164,632 | <p>This is a special case of the <em>Travelling Salesman Problem</em>, which is perhaps the most famous example of an <em>intractable</em> problem - one which cannot be solved in sensible time for any sizable input. Using recursion on this would take O(N!) memory and time, which can only be viable (even on modern syste... | 1 | 2016-07-02T21:29:05Z | [
"python",
"algorithm",
"recursion",
"geopy"
] |
How to use appendcells to append a list of columns in google sheets api | 38,163,716 | <p>I'm using python 2.7 but my understanding is this syntax works with any language.</p>
<p>I'd like to append data to the bottom of my google sheets. The function works below, but I'd like to know if there is a better way to:</p>
<p>1) specify userEnteredValue on the column level instead of cell level</p>
<p>2) no... | 0 | 2016-07-02T19:25:42Z | 39,930,963 | <p>This is an extraction of a code I'm working on. Maybe it could be helpful:</p>
<pre><code>appendResult = spreadsheet.append(
rangeName='%s!A3:D3' % title,
values=values,
valueInputOption="USER_ENTERED",
insertDataOption="INSERT_ROWS",
)
</code></pre>
<p>where <code>title</code> is the sheet <strong... | 0 | 2016-10-08T09:47:43Z | [
"python",
"google-sheets-api"
] |
Can't install datasets package via pip | 38,163,760 | <p>I'm trying to run a script that requires the datasets python package. I've tried installing this unsuccessfully using pip by calling:</p>
<p><code>pip install datasets</code></p>
<p>I know this hasn't worked because when I run the script I get the message:</p>
<pre><code>Traceback (most recent call last):
File ... | 0 | 2016-07-02T19:31:31Z | 38,165,113 | <p>Using <code>pip install datasets</code> I was also not able to properly install this package. It seems like there is a <strong>bug in this particular package.</strong></p>
<p>The <strong>DESCRIBE.rst</strong> file is simply missing. To fix this just download the plain package from PyPi. <a href="https://pypi.python... | 0 | 2016-07-02T22:52:13Z | [
"python",
"python-2.7",
"pip",
"homebrew"
] |
Can't install datasets package via pip | 38,163,760 | <p>I'm trying to run a script that requires the datasets python package. I've tried installing this unsuccessfully using pip by calling:</p>
<p><code>pip install datasets</code></p>
<p>I know this hasn't worked because when I run the script I get the message:</p>
<pre><code>Traceback (most recent call last):
File ... | 0 | 2016-07-02T19:31:31Z | 38,165,140 | <p>Download the <a href="https://github.com/pudo/dataset" rel="nofollow">DataSets package straight from GitHub</a>?</p>
| 0 | 2016-07-02T22:57:29Z | [
"python",
"python-2.7",
"pip",
"homebrew"
] |
skip iterations in for loop in python? | 38,163,769 | <p>I have programmed in C++ earlier but I am new to Python. I searched for this but i was not able to find the appropriate answer. In C++, I can do:</p>
<pre><code>for(int i=0; i<10;i++)
{
i+=5;
std::cout<<i<<std::endl
}
</code></pre>
<p>The values of i would be 5 and 11. But in python if i do:</... | 0 | 2016-07-02T19:32:14Z | 38,163,845 | <p>I know what you were thinking, but there's something built-in for python that allows you to set the iteration step within the <code>range()</code> function. Here's a link that might help you. <a href="https://docs.python.org/3/library/functions.html#func-range">(Link)</a></p>
<p>In essence, to skip <code>x</code> a... | 5 | 2016-07-02T19:40:58Z | [
"python",
"c++",
"for-loop"
] |
skip iterations in for loop in python? | 38,163,769 | <p>I have programmed in C++ earlier but I am new to Python. I searched for this but i was not able to find the appropriate answer. In C++, I can do:</p>
<pre><code>for(int i=0; i<10;i++)
{
i+=5;
std::cout<<i<<std::endl
}
</code></pre>
<p>The values of i would be 5 and 11. But in python if i do:</... | 0 | 2016-07-02T19:32:14Z | 38,163,872 | <p>If you want to skip iterations when a condition is true, then use <code>continue</code>:</p>
<pre><code>for i in range(10):
if i % 2:
continue
print(i)
</code></pre>
| 6 | 2016-07-02T19:44:04Z | [
"python",
"c++",
"for-loop"
] |
skip iterations in for loop in python? | 38,163,769 | <p>I have programmed in C++ earlier but I am new to Python. I searched for this but i was not able to find the appropriate answer. In C++, I can do:</p>
<pre><code>for(int i=0; i<10;i++)
{
i+=5;
std::cout<<i<<std::endl
}
</code></pre>
<p>The values of i would be 5 and 11. But in python if i do:</... | 0 | 2016-07-02T19:32:14Z | 38,163,890 | <p>You can use a regular <code>while</code> loop. it will look less nice but it does the job.
for example:</p>
<pre><code>i = 0
while i < 100:
print i
if i % 2 == 0:
i += 5
i+=1
</code></pre>
| 3 | 2016-07-02T19:46:15Z | [
"python",
"c++",
"for-loop"
] |
Pandas/numpy help vectorizing sequence of lookup, calculation and reordering across dataframes | 38,163,772 | <p>I'm trying to process data from three (csv) files say p, c, f:</p>
<ul>
<li>In p, each row has labels</li>
<li>In c, each row has scores for labels in corresponding row in p (p is matched to c)</li>
<li>In f, each row is a label and another score</li>
</ul>
<p>For e.g., loaded into df_p, df_c and df_f respectively... | 1 | 2016-07-02T19:32:37Z | 38,164,335 | <p>You could use the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>DateFrame.replace</code> method</a> to replace the values in <code>df_p</code> with values from <code>df_f</code>:</p>
<pre><code>In [124]: df_pf = df_p.replace(df_f['c']); df_pf
Out[... | 2 | 2016-07-02T20:44:29Z | [
"python",
"numpy",
"pandas"
] |
Pandas/numpy help vectorizing sequence of lookup, calculation and reordering across dataframes | 38,163,772 | <p>I'm trying to process data from three (csv) files say p, c, f:</p>
<ul>
<li>In p, each row has labels</li>
<li>In c, each row has scores for labels in corresponding row in p (p is matched to c)</li>
<li>In f, each row is a label and another score</li>
</ul>
<p>For e.g., loaded into df_p, df_c and df_f respectively... | 1 | 2016-07-02T19:32:37Z | 38,164,367 | <p>Try this: First create a dict of <code>df_f</code></p>
<pre><code>di = df_f['c'].to_dict()
{100: 0.183946,
101: 0.29031099999999999,
102: 0.192049,
103: 0.72570400000000002,
104: 0.14335899999999999}
</code></pre>
<p>Then map it to df_p:</p>
<pre><code>df_p.replace(di)
# p1 p2 p3... | 0 | 2016-07-02T20:50:08Z | [
"python",
"numpy",
"pandas"
] |
Insert value into the element of 2D array | 38,163,808 | <p>Supposed I created the 2D array of 3x4 with zeros initialization.
Then, I want to add 100 into arr[0][1] and I expect that 100 is added Only into arr[0][1] cell. Refer to Case 1 and Case 2:</p>
<p><strong>From Case 1:</strong>
what I saw is that 100 is added into every row with column 1 of arr. It is not what i exp... | -2 | 2016-07-02T19:37:51Z | 38,163,865 | <p><code>[0]*4</code> creates a list of references to the same object 0. Since integers are immutable, that's OK; changing one element replaces it with a new object. However, <code>[[0]*4]*3]</code> creates a list with 3 references to the same, <em>mutable</em> list object that contains 4 references to 0. Changing an e... | 0 | 2016-07-02T19:43:12Z | [
"python"
] |
How to install a python module from Github with no root access? | 38,163,864 | <p>I've read several article but I've had no luck as my situation conflicts with one or more freedoms that others have. This is my situation.</p>
<ul>
<li>I've no access to <code>root</code>. </li>
<li>I'm just a user with access to python. No <code>sudo</code>. </li>
<li><code>python 2.x.x</code> is pre-installed </... | 2 | 2016-07-02T19:43:12Z | 38,164,765 | <p>from your description it sounds like you could install <code>setuptools</code> in a user-local path to get over your first hurdle.</p>
<p>see: <a href="https://pypi.python.org/pypi/setuptools#installation-instructions" rel="nofollow">https://pypi.python.org/pypi/setuptools#installation-instructions</a></p>
<hr>
<... | 1 | 2016-07-02T21:50:12Z | [
"python",
"ubuntu",
"pip",
"setuptools"
] |
How to install a python module from Github with no root access? | 38,163,864 | <p>I've read several article but I've had no luck as my situation conflicts with one or more freedoms that others have. This is my situation.</p>
<ul>
<li>I've no access to <code>root</code>. </li>
<li>I'm just a user with access to python. No <code>sudo</code>. </li>
<li><code>python 2.x.x</code> is pre-installed </... | 2 | 2016-07-02T19:43:12Z | 38,168,694 | <p>There's a problem in setuptools 24.0.0 (released today). I assume it will be fixed soon. Meanwhile, downgrade to 23.1 and reinstall the desired package.</p>
| 2 | 2016-07-03T09:45:56Z | [
"python",
"ubuntu",
"pip",
"setuptools"
] |
Fetch data from csv file: Error IO operation on closed file | 38,163,929 | <h2>I'm trying to fetch some data from csv file but getting some error</h2>
<p>error: ##</p>
<blockquote>
<p>Exception in Tkinter callback</p>
<p>Traceback (most recent call last):</p>
<p>File
"C:\Users\hp-\AppData\Local\Programs\Python\Python35-32\lib\tkinter__init__.py",
line 1549, in <strong>call</... | 2 | 2016-07-02T19:51:56Z | 38,163,987 | <p>You are trying to access the <code>reader</code> after the file has been closed outside the context it was opened. Move the <code>for</code> loop in the <code>recommend</code> function into the context of <code>with</code>, like so:</p>
<pre><code>def recommend():
with open('listsng.csv') as csvfile:
r... | 1 | 2016-07-02T19:58:01Z | [
"python",
"csv"
] |
Take pictures periodically while streaming webcam | 38,163,995 | <p>with my webcam, I want to take pictures periodically, every 5 seconds, while streaming the video to the browser. How can I do that in Python, with preferably Flask and Opencv?</p>
| -5 | 2016-07-02T19:58:56Z | 38,164,212 | <p>On Windows, it is very easy to use your webcam with <a href="http://www.pygame.org/hifi.html" rel="nofollow">pygame</a>.</p>
<p>E.g. </p>
<pre><code>import time
from VideoCapture import Device
webCam = Device()
name = 1
while(True): # Take pictures forever
webCam.saveSnapshot(name + '.jpg') # Take picture
... | 0 | 2016-07-02T20:28:45Z | [
"python",
"opencv",
"flask",
"video-streaming",
"webcam"
] |
Recursion at exec() level with globals | 38,164,010 | <p>After stumbling upon <a href="https://stackoverflow.com/questions/5874558/python-how-to-pass-arguments-to-the-code-of-a-function">this question</a> I've been playing around with exec() to better understand how it works. I'm trying to get this abomination of a script to increment a global variable, read itself, and c... | 0 | 2016-07-02T20:00:46Z | 38,164,071 | <p>You could do this:</p>
<pre><code># recurse.py
def func():
global x
x += 1
with open('recurse.py', 'r') as f:
try:
exec(f.read(), {'x': x})
except RuntimeError:
print('maximum recursion depth reached at', x)
try:
x
except NameError:
x = 0
func()
</co... | 2 | 2016-07-02T20:09:02Z | [
"python",
"python-3.x",
"recursion",
"global-variables"
] |
Recursion at exec() level with globals | 38,164,010 | <p>After stumbling upon <a href="https://stackoverflow.com/questions/5874558/python-how-to-pass-arguments-to-the-code-of-a-function">this question</a> I've been playing around with exec() to better understand how it works. I'm trying to get this abomination of a script to increment a global variable, read itself, and c... | 0 | 2016-07-02T20:00:46Z | 38,166,744 | <p>A variation on @BrenBarn's excellent solution that fails with a RuntimeError (@ ~ 500 recursions) instead of an IOError (@ ~ 256 recursions) due to too many files being open:</p>
<p># recurse.py</p>
<pre><code>def func():
global x
x += 1
with open('recurse.py') as source:
string = source.read()... | 2 | 2016-07-03T04:30:57Z | [
"python",
"python-3.x",
"recursion",
"global-variables"
] |
Implementing Tuples and Lists in the isinstance Function in Python 2.7 | 38,164,024 | <p>I am trying to accept <code>tuple</code> and <code>list</code> as object types in an <code>__add__</code> method in Python. Please see the following code:</p>
<pre><code>class Point(object):
'''A point on a grid at location x, y'''
def __init__(self, x, y):
self.X = x
self.Y = y
def __str_... | 8 | 2016-07-02T20:03:00Z | 38,164,045 | <p>As simple as error you got says: the list object in python (or probably in any language does not have x or y attributes). You must handle list (and tuple also) case separately</p>
| 1 | 2016-07-02T20:05:45Z | [
"python"
] |
Implementing Tuples and Lists in the isinstance Function in Python 2.7 | 38,164,024 | <p>I am trying to accept <code>tuple</code> and <code>list</code> as object types in an <code>__add__</code> method in Python. Please see the following code:</p>
<pre><code>class Point(object):
'''A point on a grid at location x, y'''
def __init__(self, x, y):
self.X = x
self.Y = y
def __str_... | 8 | 2016-07-02T20:03:00Z | 38,164,060 | <p>If you want to be able to add lists or tuples, change your <code>__add__</code> method:</p>
<pre><code>def __add__(self, other):
if not isinstance(other, (Point, list, tuple)):
raise TypeError("Must be of type Point, list, or tuple")
if isinstance(other, (list, tuple)):
other = Point(other[0... | 3 | 2016-07-02T20:07:38Z | [
"python"
] |
Python - sleep interval, account for various options (int or randrange) | 38,164,039 | <p>I am trying to learn python by contributing to some projects.
Currently there is a --sleep_interval that takes int x which does as you would expect.</p>
<p>I would like to expand the functionality of sleep_interval to accept something like this: </p>
<p>--sleep_interval=100-200</p>
<p>If the input is in the forma... | 0 | 2016-07-02T20:05:06Z | 38,164,101 | <p>I'd just do this:</p>
<pre><code>if '-' in sleep_interval:
start,stop = sleep_interval.split('-')
sleep_interval = random.randrange(int(start),int(stop))
</code></pre>
| 2 | 2016-07-02T20:13:10Z | [
"python"
] |
Python - sleep interval, account for various options (int or randrange) | 38,164,039 | <p>I am trying to learn python by contributing to some projects.
Currently there is a --sleep_interval that takes int x which does as you would expect.</p>
<p>I would like to expand the functionality of sleep_interval to accept something like this: </p>
<p>--sleep_interval=100-200</p>
<p>If the input is in the forma... | 0 | 2016-07-02T20:05:06Z | 38,164,147 | <p>Canaryyellow's answer is correct but - as far as user input is provided - be sure to provide a useful error message when input is invalid. Hence, my code would end up with something like:</p>
<pre><code>sleep_interval = self.params.get('sleep_interval')
if '-' in sleep_interval:
try:
start, stop = sleep... | 0 | 2016-07-02T20:20:00Z | [
"python"
] |
python module ffpyplayer showing or displaying video frames to screen | 38,164,083 | <p>Using python module ffpyplayer, How can I see the frames or get the img object to display or show the video image/frames to the screen?, in the tutorial that I followed, it seems very simple, it reads the frames and plays oudio but (does not display) any video image or frame to the screen, only if I add the (print i... | 0 | 2016-07-02T20:11:18Z | 40,119,838 | <p>Kivy already provides such a video player, based on ffpyplayer, for you.<br>
It also has the necessary threads already setup for you, to deal with buttons, file reading, audio and timing.<br>
Check this page:
<a href="https://kivy.org/docs/api-kivy.uix.videoplayer.html" rel="nofollow">https://kivy.org/docs/api-kivy.... | 0 | 2016-10-18T23:47:49Z | [
"python",
"python-2.7",
"video",
"ffmpeg"
] |
How to match a regular expression with exactly one digit in it using python regex? | 38,164,191 | <p>I am trying to match a string with exactly one digit in it. e.g. '5', '4', '3', etc. I am using the <code>re</code> library in python to help me use regex.</p>
<p>I have the following three flags that are being set with respective if statements:</p>
<pre><code>import re
if re.match(r'\d{2}:\d{2}:\d{2}', item):
... | -1 | 2016-07-02T20:26:01Z | 38,164,336 | <p>If it consists of 1 digit and nothing else:</p>
<pre><code>re.match('^\d$', item)
</code></pre>
<p>If it can contain other non-digit characters:</p>
<pre><code>re.match('^\D*\d\D*$', item)
</code></pre>
<p>By starting the regex with <code>^</code> you just ensured that the first character of <code>item</code> wa... | 1 | 2016-07-02T20:44:31Z | [
"python"
] |
How to match a regular expression with exactly one digit in it using python regex? | 38,164,191 | <p>I am trying to match a string with exactly one digit in it. e.g. '5', '4', '3', etc. I am using the <code>re</code> library in python to help me use regex.</p>
<p>I have the following three flags that are being set with respective if statements:</p>
<pre><code>import re
if re.match(r'\d{2}:\d{2}:\d{2}', item):
... | -1 | 2016-07-02T20:26:01Z | 38,164,489 | <p>I agree with the comments made by user @kaveh. This is what I got:</p>
<p><a href="http://i.stack.imgur.com/b7AIf.png" rel="nofollow"><img src="http://i.stack.imgur.com/b7AIf.png" alt="enter image description here"></a></p>
<p>Results:</p>
<p><a href="http://i.stack.imgur.com/eLEVs.png" rel="nofollow"><img src="... | 1 | 2016-07-02T21:08:22Z | [
"python"
] |
Itertools.permutations across lists in strict order python | 38,164,214 | <p>Say I had three lists as such:</p>
<pre><code>list_1 = ['hello1', 'world1', 'foo1']
list_2 = ['hello2', 'world2', 'foo2']
list_3 = ['hello3', 'world3', 'foo3']
</code></pre>
<p>Is it possible to achieve - through for example itertools.combinations() or itertools.permutations - that only the following combinations ... | 1 | 2016-07-02T20:28:40Z | 38,164,262 | <p>You can using <code>itertools.product()</code>:</p>
<pre><code>>>> import itertools as it
>>> list(it.product(*zip(list_1, list_2, list_3)))
[('hello1', 'world1', 'foo1'),
('hello1', 'world1', 'foo2'),
('hello1', 'world1', 'foo3'),
('hello1', 'world2', 'foo1'),
...
('hello3', 'world3', 'foo1'... | 1 | 2016-07-02T20:33:49Z | [
"python",
"itertools"
] |
How can I make a phone plan and ask for data usage fee? | 38,164,221 | <pre><code>print ('You have 5 plans to choose for your phone')
print ('a. Unlimited data - $90/month')
print ('b. 10 GB limit - $60/month + $10/GB over 10GB')
print ('c. 5 GB limit - $40/month + $12/GB over 5 GB')
print ('d. 2 GB limit - $30/month + $15/GB over 2 GB')
print ('e. No limit - $18/GB')
respond = input('Ple... | -4 | 2016-07-02T20:29:22Z | 38,164,395 | <p>If you're using python 3.x:
Change </p>
<pre><code>f = integer(input('how much data do you use for a month')
</code></pre>
<p>to </p>
<pre><code>f = int(input('how much data do you use for a month')
</code></pre>
<p>Also, if you're using python 2.x, change <code>input</code> to <code>raw_input</code>. </p>
<p... | 0 | 2016-07-02T20:54:35Z | [
"python"
] |
Python Click: Having the group execute code AFTER a command | 38,164,324 | <p>I have a <code>click.group()</code> defined, with about 10 commands in it. I understand how to use a group to run code before the code in the command, but I also want to run some code AFTER each command is run. Is that possible with click?</p>
| 5 | 2016-07-02T20:43:04Z | 38,168,128 | <p>You can use <a href="http://click.pocoo.org/5/api/#click.MultiCommand.resultcallback" rel="nofollow">@resultcallback</a> decorator</p>
<pre><code>@click.group()
def cli():
click.echo('Before command')
@cli.resultcallback()
def process_result(result, **kwargs):
click.echo('After command')
@cli.command()
... | 1 | 2016-07-03T08:29:50Z | [
"python",
"python-click"
] |
gevent spawing - in sequence rather than concurrent | 38,164,337 | <p>I am trying my hand on asynchronous programming with gevent and not able to understand the way my code works. </p>
<p>I am trying to ping google.com using sockets on a closed port (22) and expecting the <code>ping</code> function to happen concurrently but it is not happening</p>
<p>I have a python code as below</... | 0 | 2016-07-02T20:44:34Z | 38,164,397 | <p>Figured the solution.</p>
<p>Adding a monkey patch in import solved my issue.</p>
<pre><code>from gevent import monkey
monkey.patch_socket()
</code></pre>
| 0 | 2016-07-02T20:54:41Z | [
"python",
"gevent"
] |
File data to array is using a lot of memory | 38,164,418 | <p>I'm taking a large text file with tab separated values and adding them to an array.</p>
<p>When I run my code on a 32 Mb file, python memory consumption goes through the roof; using around 500 Mb RAM.</p>
<p>I need to be able to run this code for a 2 GB file, and possibly even larger files. </p>
<p>My current cod... | 3 | 2016-07-02T20:57:29Z | 38,164,742 | <h2>"What is using all this memory?"</h2>
<p>There's overhead for Python objects. See how many bytes some strings actually take:</p>
<p>Python 2:</p>
<pre><code>>>> import sys
>>> map(sys.getsizeof, ('', 'a', u'ä'))
[21, 22, 28]
</code></pre>
<p>Python 3:</p>
<pre><code>>>> import sys
&... | 6 | 2016-07-02T21:46:31Z | [
"python",
"memory",
"memory-management"
] |
Dividing Pandas Dataframe by Week | 38,164,453 | <p>I have a dataframe with columns "Date" and "Num". </p>
<pre><code>dates = pd.date_range('1/1/2001','1/1/2003', freq = 'd')
nums = [np.random.randint(100) for x in range(len(dates))]
df = pd.DataFrame({'Dates': dates, 'DOW': dates.strftime('%a'), 'Nums': nums})
df = df[(df.DOW != 'Sat') & (df.DOW !='Sun')]
df =... | 3 | 2016-07-02T21:03:37Z | 38,164,534 | <pre><code>import numpy as np
import pandas as pd
np.random.seed(2016)
dates = pd.date_range('1/1/2001','1/1/2003', freq = 'd')
nums = [np.random.randint(100) for x in range(len(dates))]
df = pd.DataFrame({'Dates': dates, 'DOW': dates.strftime('%a'), 'Nums': nums})
df = df[(df.DOW != 'Sat') & (df.DOW !='Sun')]
df... | 4 | 2016-07-02T21:15:20Z | [
"python",
"datetime",
"pandas",
"resampling"
] |
Python installing Module Requests | 38,164,525 | <p>Whenever I run this command in the Python interface, it's comes up as "Invalid syntax"</p>
<pre><code>>>> pip install Requests
File "<stdin>", line 1
pip install Requests
^
SyntaxError: invalid syntax
</code></pre>
<p>Can anyone give me suggestions?</p>
| -2 | 2016-07-02T21:13:25Z | 38,164,549 | <p>To install Requests,run this simple command in your terminal of choice:</p>
<pre><code> pip install requests
</code></pre>
| 2 | 2016-07-02T21:17:10Z | [
"python",
"module"
] |
Python installing Module Requests | 38,164,525 | <p>Whenever I run this command in the Python interface, it's comes up as "Invalid syntax"</p>
<pre><code>>>> pip install Requests
File "<stdin>", line 1
pip install Requests
^
SyntaxError: invalid syntax
</code></pre>
<p>Can anyone give me suggestions?</p>
| -2 | 2016-07-02T21:13:25Z | 38,165,345 | <p>What OS are you using?</p>
<p>It looks like you have started the Python interpreter before you typed install requests.
Try opening a terminal window and typing pip install requests. That's assuming you have pip however.</p>
| 1 | 2016-07-02T23:32:01Z | [
"python",
"module"
] |
Python installing Module Requests | 38,164,525 | <p>Whenever I run this command in the Python interface, it's comes up as "Invalid syntax"</p>
<pre><code>>>> pip install Requests
File "<stdin>", line 1
pip install Requests
^
SyntaxError: invalid syntax
</code></pre>
<p>Can anyone give me suggestions?</p>
| -2 | 2016-07-02T21:13:25Z | 38,165,438 | <p>Notice that the <code>>>></code> primary prompt is present, which means you are inside a Python interpreter and running it in the interactive mode. Therefore, what you were trying to do is to run <code>pip install requests</code> inside the Python interpreter, which is not how you use <code>pip</code> to in... | 1 | 2016-07-02T23:46:32Z | [
"python",
"module"
] |
How to decode HTML entities in Spark? | 38,164,532 | <p>I'm reading a large collection of text files into a DataFrame. Initially it will just have one column, <code>value</code>. The text files use HTML encoding (i.e., they have <code>&lt;</code> instead of <code><</code>, etc.). I want to decode all of them back to normal characters.</p>
<p>Obviously, I could do... | 2 | 2016-07-02T21:15:06Z | 38,181,647 | <p>Since you read plain text input I would simply skip UDF part and pass data to JVM after initial processing. With Python 3.4+:</p>
<pre><code>import html
from pyspark.sql.types import StringType, StructField, StructType
def clean(s):
return html.unescape(s),
(sc.textFile("README.md")
.map(clean)
.toDF... | 1 | 2016-07-04T09:49:31Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql"
] |
Add input from list + numbers | 38,164,542 | <p>Say you have a code like this...</p>
<pre><code>answer = input ()
areacode = ['302', '856', '215', '413']
if answer in areacode:
***Looking for what I would put here***
</code></pre>
<p>is it <strong>possible</strong> to have the users input from a list be added to numbers that would count up from 0000000 to 99999... | 1 | 2016-07-02T21:15:57Z | 38,164,596 | <p>Python supports arbitrarily long integers. Just iterate over all these numbers, and add them to the area code multiplied by 10,000,000:</p>
<pre><code>for i in range(10000000):
print(answercode * 10000000 + i);
</code></pre>
<p><strong>EDIT:<br/></strong>
As noted in the comments, redoing the multiplication in... | 3 | 2016-07-02T21:23:19Z | [
"python",
"python-3.x"
] |
Add input from list + numbers | 38,164,542 | <p>Say you have a code like this...</p>
<pre><code>answer = input ()
areacode = ['302', '856', '215', '413']
if answer in areacode:
***Looking for what I would put here***
</code></pre>
<p>is it <strong>possible</strong> to have the users input from a list be added to numbers that would count up from 0000000 to 99999... | 1 | 2016-07-02T21:15:57Z | 38,166,262 | <p>Should work</p>
<pre><code>for i in range(9999999):
print("answer"+" "+"+"+(str(i).rjust(7, '0')))
</code></pre>
| 0 | 2016-07-03T02:38:37Z | [
"python",
"python-3.x"
] |
Add input from list + numbers | 38,164,542 | <p>Say you have a code like this...</p>
<pre><code>answer = input ()
areacode = ['302', '856', '215', '413']
if answer in areacode:
***Looking for what I would put here***
</code></pre>
<p>is it <strong>possible</strong> to have the users input from a list be added to numbers that would count up from 0000000 to 99999... | 1 | 2016-07-02T21:15:57Z | 38,167,736 | <pre><code>for i in range(10000000):
print(str(answer)+"{0:0=7d}".format(i))
</code></pre>
| 1 | 2016-07-03T07:37:58Z | [
"python",
"python-3.x"
] |
Format of name of a Python package with setuptools | 38,164,587 | <p>What should be the format of the <code>name</code> argument of <code>setuptools.setup()</code>? Is it free-form so I can use spaces on it?</p>
<pre><code>from setuptools import setup, find_packages
setup(
name="My Stuff",
version="0.0.1.dev1",
packages=find_packages(),
test_suite='page_peel_tests'... | 1 | 2016-07-02T21:22:10Z | 38,164,815 | <p>You can't use spaces. Names are case insensitive, hyphens and underscores are equivalent and there are a few other cases of "confusable" characters treated as equivalent. From <a href="https://www.python.org/dev/peps/pep-0426/#name" rel="nofollow">PEP 426</a> on package naming:</p>
<blockquote>
<p>As distribution... | 3 | 2016-07-02T21:57:21Z | [
"python",
"setuptools",
"distutils",
"setup.py"
] |
Selenium not freeing up memory even after calling close/quit | 38,164,635 | <p>So I've been working on scraper that goes on 10k+pages and scrapes data from it.</p>
<p>Issue is that over time memory consumption raises drastically. So to overcome this instead of closing driver instance only at the end of scrape scraper is updated so it closes instance after every page is loaded and data extract... | 2 | 2016-07-02T21:29:12Z | 38,164,741 | <p>Are you trying to say that your drivers are what's filling up your memory? How are you closing them? If you're extracting your data, do you still have references to some collection that's storing them in memory? </p>
<p>You mentioned that you were already running out of memory when you closed the driver instance ... | 1 | 2016-07-02T21:46:25Z | [
"python",
"selenium",
"firefox",
"selenium-webdriver",
"selenium-chromedriver"
] |
Selenium not freeing up memory even after calling close/quit | 38,164,635 | <p>So I've been working on scraper that goes on 10k+pages and scrapes data from it.</p>
<p>Issue is that over time memory consumption raises drastically. So to overcome this instead of closing driver instance only at the end of scrape scraper is updated so it closes instance after every page is loaded and data extract... | 2 | 2016-07-02T21:29:12Z | 38,164,801 | <p><a href="http://stackoverflow.com/questions/1316767/how-can-i-explicitly-free-memory-in-python/1316799#1316799">The only way</a> to force the Python interpreter to release memory to the OS is to terminate the process. Therefore, use <code>multiprocessing</code> to spawn the selenium Firefox instance; the memory will... | 1 | 2016-07-02T21:54:41Z | [
"python",
"selenium",
"firefox",
"selenium-webdriver",
"selenium-chromedriver"
] |
How to type Greek letters with Sikuli | 38,164,651 | <p>I am using <a href="http://www.sikuli.org/" rel="nofollow">Sikuli</a> to complete some forms and I have to type Greek letters on some of them. </p>
<p>I can define a string with greek letters, for example <code>a='Îεια ÏοÏ
'</code>, and even print it using Python 3.5.2 Shell (on Windows). However when I use t... | 3 | 2016-07-02T21:31:42Z | 38,703,707 | <p>As stavros11 already noted, <a href="https://answers.launchpad.net/sikuli/+question/260734" rel="nofollow">https://answers.launchpad.net/sikuli/+question/260734</a> holds the solution.</p>
<p>Here is a small sample script:</p>
<pre><code>openApp("notepad.exe")
find("1470067652176.png") #set focus to notepad window... | 0 | 2016-08-01T16:26:36Z | [
"python",
"unicode",
"automation",
"sikuli",
"letters"
] |
Binding button to function after adding button with Kivy language | 38,164,705 | <p>I'm trying to figure out how to bind a button that's been laid out using Kivy language to a function. I've seen plenty of <a href="http://stackoverflow.com/questions/33586688/kivy-button-binding-function-with-argument">answers</a> when laying out buttons in Python language. But what about once everything is in place... | 0 | 2016-07-02T21:39:42Z | 38,164,800 | <p>The answer is to include the class name, in this case <code>TimerButton</code>, in the function definitions. This is a concept I don't completely understand since the function is defined within the scope of the <code>TimerButton</code> class. But hey, it works.</p>
<pre><code>class TimerButton(ButtonBehavior, Image... | 0 | 2016-07-02T21:54:37Z | [
"python",
"kivy"
] |
Binding button to function after adding button with Kivy language | 38,164,705 | <p>I'm trying to figure out how to bind a button that's been laid out using Kivy language to a function. I've seen plenty of <a href="http://stackoverflow.com/questions/33586688/kivy-button-binding-function-with-argument">answers</a> when laying out buttons in Python language. But what about once everything is in place... | 0 | 2016-07-02T21:39:42Z | 38,166,120 | <p>The kivy code that calls the function you set in <code>.bind()</code> is passing an argument which your function isn't prepared for. It's been a while since I last used kivy, so I can't be sure, but I think the event details are passed to the function.</p>
<p>As such, your definitions for event handlers should loo... | 0 | 2016-07-03T02:09:14Z | [
"python",
"kivy"
] |
numpy.ma (masked) array mean method has inconsitent return type | 38,164,773 | <p>I noticed that the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.MaskedArray.mean.html#numpy.ma.MaskedArray.mean" rel="nofollow">numpy masked-array mean method</a> returns different types when it probably should not:</p>
<pre><code>import numpy as np
A = np.ma.masked_equal([1,1,0], value=0)... | 5 | 2016-07-02T21:51:00Z | 38,164,897 | <p><code>B.mask</code> starts with:</p>
<pre><code> if self._mask is nomask:
result = super(MaskedArray, self).mean(axis=axis, dtype=dtype)
</code></pre>
<p><code>np.ma.nomask</code> is <code>False</code>. </p>
<p>This is the case for your <code>B</code>:</p>
<pre><code>masked_array(data = [1 1 1],
... | 1 | 2016-07-02T22:15:05Z | [
"python",
"numpy",
"masked-array"
] |
Does IronPython support multiprocessing? | 38,164,874 | <p>Using IronPython 2.7 (<code>IronPython 2.7 2.7.5.0 on .NET 4.0.30319.42000</code>), I have a script which includes <code>from multiprocessing import Pool</code>. Trying to run it, I get the following error:</p>
<pre><code>Traceback (most recent call last):
File "find_compressed.concurrent.py", line 67, in <mod... | 0 | 2016-07-02T22:10:09Z | 38,165,409 | <p>According to <a href="https://mail.python.org/pipermail/ironpython-users/2011-March/014584.html" rel="nofollow">this e-mail</a> there is no support of Multiprocessing in IronPython.</p>
<p>But such module was created to workaround the GIL in Python, and IronPython don't have one, so maybe there are other ways, <a h... | 0 | 2016-07-02T23:41:36Z | [
"python",
"multiprocessing",
"ironpython",
"python-multiprocessing"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.