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 |
|---|---|---|---|---|---|---|---|---|---|
Should python script files be executable? | 40,030,811 | <p>Should python script files be executable?</p>
<p>Suppose I'm developing a small tool. I have the following files:</p>
<pre><code>my_tool.py
my_lib.py
my_other_lib.py
....
</code></pre>
<p>Occasionally I run my tool with <code>python my_tool.py</code>.</p>
<p>Is there a convention that the first file should be ex... | 1 | 2016-10-13T20:55:12Z | 40,033,007 | <p>You only need to make a python script executable if it has a hashbang at the top. Python doesn't require that <a href="http://docs.python.org/tutorial/modules.html" rel="nofollow">modules</a> you intend to import or any scripts passed as arguments are flagged as executable.</p>
<p>As for naming conventions, you sh... | 0 | 2016-10-14T00:13:50Z | [
"python",
"naming-conventions"
] |
Python: How do I 'pull' a list through a function | 40,030,875 | <p>I am trying to find the 'peak' in list of numbers. I tried the following;</p>
<pre><code>list = [5, 12, 34, 25, 13, 33]
n = range(len(list))
def func(n):
if list[n] >= list[n-1] and list[n] >= list[n+1]:
print list[n]
print func(n)
</code></pre>
<p>I get back the error 'list indices must be integ... | -6 | 2016-10-13T20:58:44Z | 40,031,046 | <p>you define n = range(...) so n = [0, 1,...] when you call func(n) and in your function:</p>
<pre><code>if list[n] >= ....
</code></pre>
<p>becomes:</p>
<pre><code>if list[ [0, 1, ...] ] >= ...
</code></pre>
<p>This is the reason why you get error 'list indices must be integers, not list'</p>
| -1 | 2016-10-13T21:09:28Z | [
"python",
"python-2.7"
] |
Python: How do I 'pull' a list through a function | 40,030,875 | <p>I am trying to find the 'peak' in list of numbers. I tried the following;</p>
<pre><code>list = [5, 12, 34, 25, 13, 33]
n = range(len(list))
def func(n):
if list[n] >= list[n-1] and list[n] >= list[n+1]:
print list[n]
print func(n)
</code></pre>
<p>I get back the error 'list indices must be integ... | -6 | 2016-10-13T20:58:44Z | 40,031,180 | <p>change 'list' to something else, say 'lst' and by peak if you mean max element then: </p>
<pre><code>lst = [5, 12, 34, 25, 13, 33]
print max(lst)
</code></pre>
| -1 | 2016-10-13T21:19:08Z | [
"python",
"python-2.7"
] |
Python: How do I 'pull' a list through a function | 40,030,875 | <p>I am trying to find the 'peak' in list of numbers. I tried the following;</p>
<pre><code>list = [5, 12, 34, 25, 13, 33]
n = range(len(list))
def func(n):
if list[n] >= list[n-1] and list[n] >= list[n+1]:
print list[n]
print func(n)
</code></pre>
<p>I get back the error 'list indices must be integ... | -6 | 2016-10-13T20:58:44Z | 40,031,258 | <p>Your issue is that you're trying to pass a range as an argument. Range(len(list)), in this case, is going to give you this list: [0,1,2,3,4,5]</p>
<p>Your function is expecting a single number, but you're passing a list. To check every number, change this line:</p>
<pre><code> print(func(n))
</code></pre>
<p>to t... | -1 | 2016-10-13T21:25:05Z | [
"python",
"python-2.7"
] |
How to add to an existing plot a marker for points in the chart | 40,030,881 | <p>So hello community,
I have a program which includes several functions and they all have 5-6 fix points. On those points i always want to have whether a square or diamond marker style. I can do it in the program but i want to have it in the script so they already appear when i run the program. ANy ideas?</p>
| -1 | 2016-10-13T20:59:06Z | 40,031,202 | <p>So the answer is described on this website and much more.
<a href="https://bespokeblog.wordpress.com/2011/07/07/basic-data-plotting-with-matplotlib-part-2-lines-points-formatting/" rel="nofollow">https://bespokeblog.wordpress.com/2011/07/07/basic-data-plotting-with-matplotlib-part-2-lines-points-formatting/</a></p>
... | 0 | 2016-10-13T21:21:10Z | [
"python",
"matplotlib",
"marker"
] |
Python webscraping using beautiful soup | 40,030,943 | <p><img src="https://i.stack.imgur.com/3BNrE.png" alt="Extract between span span"></p>
<pre><code>nameList = soup.find_all("span", {"class":"answer-number"})
for item in nameList:
print('item.content[0]')
</code></pre>
<p>I wrote the above code, but it is not working. Please help. I want the number 6a from it.</p... | -1 | 2016-10-13T21:03:03Z | 40,031,175 | <p>Try changing your print statement to item.text</p>
| -1 | 2016-10-13T21:18:52Z | [
"python",
"html",
"parsing",
"beautifulsoup"
] |
Python webscraping using beautiful soup | 40,030,943 | <p><img src="https://i.stack.imgur.com/3BNrE.png" alt="Extract between span span"></p>
<pre><code>nameList = soup.find_all("span", {"class":"answer-number"})
for item in nameList:
print('item.content[0]')
</code></pre>
<p>I wrote the above code, but it is not working. Please help. I want the number 6a from it.</p... | -1 | 2016-10-13T21:03:03Z | 40,031,620 | <pre><code>>>> soup.findAll('span',{'class':'badgecount'})
[<span class="badgecount">9</span>, <span class="badgecount">23</span>, <span class="badgecount">51</span>, <span class="badgecount">8</span>, <span class="badgecount">40</span>, <span clas... | -1 | 2016-10-13T21:53:12Z | [
"python",
"html",
"parsing",
"beautifulsoup"
] |
Using BeautifulSoup to scrape li's and id's in same method | 40,030,963 | <p>How would i modify the parameters of the findAll method to read both li's and id's? li's are elements and id's are attributes correct?</p>
<pre><code>#Author: David Owens
#File name: soupScraper.py
#Description: html scraper that takes surf reports from various websites
import csv
import requests
from bs4 import B... | 0 | 2016-10-13T21:04:03Z | 40,032,977 | <p>So the problem is that you want to search the parse tree for elements that have either a class name of <code>rating-text</code> (it turns out you do not need <code>text-dark</code> to identify the relevant elements in the case of Magicseaweed) or an ID of <code>observed-wave-range</code>, using a single <code>findAl... | 0 | 2016-10-14T00:10:17Z | [
"python",
"html",
"web-scraping",
"beautifulsoup"
] |
Sending email with Python script Output and using crontab to send weekly | 40,031,004 | <p>I have a Python script and I am trying to write a crontab and have the output from the Python script to be outputed to a file which then sends that output to an email address (to the body of the email not the title) that is specified. My system details and crontab entry is below:</p>
<pre><code>System details:
Pyth... | 1 | 2016-10-13T21:06:21Z | 40,031,126 | <p>The <code>>></code> makes the python output get appended to the file <code>weekly.log</code>, after that no input is pushed forward to <code>mail</code>. </p>
<p>You could remove <code>>> weekly.log</code> and not have a log file or use the program <code>tee</code> in the pipe. <code>tee</code> writes t... | 0 | 2016-10-13T21:15:48Z | [
"python",
"linux",
"osx",
"crontab"
] |
Python Watchdog Measure Time Events | 40,031,080 | <p>I'm trying to implement a module called <a href="https://github.com/gorakhargosh/watchdog" rel="nofollow">Watchdog</a> into a project. I'm looking for a way I can measure time between event calls within Watchdog.</p>
<pre><code>if timebetweenevents == 5 seconds:
dothething()
</code></pre>
<p>Thank you,</p>
<p... | 0 | 2016-10-13T21:12:24Z | 40,047,644 | <p>You can modify your Handler class to have a record of the time of the last call.</p>
<p><strong>init</strong> method just initialises the value to the current time.
You will also need to make the method on_any_event a non static method</p>
<pre><code>class Handler(FileSystemEventHandler):
event_time=0
def... | 0 | 2016-10-14T16:10:24Z | [
"python",
"watchdog"
] |
How to call function between optimization iterations in pyOpt? | 40,031,152 | <p>I was wondering if there is a way that I can pass pyOpt a function that
should be called at the end of each iteration? </p>
<p>The reason I need something like this is that I am running a FEA
simulation in each function evaluation, and I would like to output the
FEA results (displacements, stresses) to an ExodusII ... | 0 | 2016-10-13T21:17:10Z | 40,032,149 | <p>you could either put your function into a component that you put at the end of your model. Since it won't have any connections, you'll want to <a href="http://openmdao.readthedocs.io/en/1.7.2/srcdocs/packages/core/group.html?highlight=set_order#openmdao.core.group.Group.set_order" rel="nofollow">set the run order</a... | 0 | 2016-10-13T22:36:09Z | [
"python",
"optimization",
"openmdao"
] |
How to give automatically generated buttons names in Tkinter? | 40,031,193 | <p>So i am genertaing a grid of 3x3 buttons for a Tic Tac Toe game im making, and i want to to end up so that when a button is pressed it changes to either a X or O, however i dont know how to give each button a unique identifier so i know which button to change.</p>
<p>Heres the code for the buttons.</p>
<pre><code>... | 0 | 2016-10-13T21:20:18Z | 40,031,241 | <p>Use a dictionary or list. For example:</p>
<pre><code>buttons = {}
for row in range(3):
for column in range(3):
buttons[(row, column)] = Button(...)
buttons[(row, column)].grid(...)
</code></pre>
<p>Later, you can refer to the button in row 2, column one as:</p>
<pre><code>buttons[(2 1)].confi... | 1 | 2016-10-13T21:23:52Z | [
"python",
"tkinter"
] |
How to set a fixed size in PyQt5 for any widget without breaking layout when resizing | 40,031,197 | <p>Haven't found this exact problem anywhere, or maybe I just don't recognize it from others. As still pretty much a beginner in programming but not totally oblivious, I am attempting to create an application with PyQt5 but I am having trouble setting up the layout properly before doing any more serious coding in the f... | 0 | 2016-10-13T21:20:29Z | 40,031,570 | <p>You can add spacers in your layout (horizontal or vertical, depending where you put them) and set a non-fixed size policy for them. This way whenever the window is resized only the spacers will stretch (or shorten).</p>
| 1 | 2016-10-13T21:49:00Z | [
"python",
"layout",
"pyqt5",
"qvboxlayout"
] |
Matrix operations with rows of pandas dataframes | 40,031,287 | <p>I have a pandas dataframe that contains three columns corresponding to x, y and z coordinates for positions of objects. I also have a transformation matrix ready to rotate those points by a certain angle. I had previously looped through each row of the dataframe performing this transformation but I found that that i... | 2 | 2016-10-13T21:27:03Z | 40,035,491 | <p>If you mean matrix multiplication by rotation.</p>
<p>You can convert both to numpy arrays and perform it as</p>
<pre><code>lh = largest_haloes.values
rotated_array = lh.dot(rot)
</code></pre>
<p>You can also do</p>
<pre><code>x = pd.DataFrame(data=rot,index=['X','Y','Z'])
rotated_df = largest_haloes.dot(x)
</co... | 0 | 2016-10-14T05:24:50Z | [
"python",
"pandas",
"matrix",
"dataframe"
] |
How can I find all known ingredient strings in a block of text? | 40,031,406 | <p>Given a string of ingredients:</p>
<pre class="lang-python prettyprint-override"><code>text = """Ingredients: organic cane sugar, whole-wheat flour,
mono & diglycerides. Manufactured in a facility that uses nuts."""
</code></pre>
<p>How can I extract the ingredients from my postgres database, or find ... | 3 | 2016-10-13T21:35:28Z | 40,032,158 | <p>This Python code gives me this output: <code>['organic cane sugar', 'whole-wheat flour', 'mono & diglycerides']</code>
It requires that the ingredients come after "Ingredients: " and that all ingredients are listed before a ".", as in your case.</p>
<pre><code>import re
text = """Ingredients: organic cane sugar... | 0 | 2016-10-13T22:37:13Z | [
"python",
"postgresql",
"parsing",
"elasticsearch",
"nlp"
] |
Python - Convert intergers to floats within a string | 40,031,547 | <p>I have an equation in the form of a string, something like this:</p>
<pre><code>(20 + 3) / 4
</code></pre>
<p>I can easily solve this equation by using <code>eval()</code>, but it will give me an answer of <code>5</code>, not the correct answer of <code>5.75</code>. I know this is because <code>20</code>, <code>3... | -1 | 2016-10-13T21:47:10Z | 40,031,612 | <p>You could use <a href="http://docs.sympy.org/dev/index.html" rel="nofollow"><code>sympy</code></a> to parse the string using <a href="http://docs.sympy.org/dev/modules/parsing.html" rel="nofollow"><code>sympy_parser.parse_expr</code></a> and then solve/simplify it:</p>
<pre><code>>>> from sympy.parsing imp... | 4 | 2016-10-13T21:52:43Z | [
"python",
"string",
"python-2.7"
] |
Calculating the time difference between events | 40,031,569 | <p>I have a df</p>
<pre><code>df = pd.DataFrame({'State': {0: "A", 1: "B", 2:"A", 3: "B", 4: "A", 5: "B", 6 : "A", 7: "B"},
'date': {0: '2016-10-13T14:10:41Z', 1: '2016-10-13T14:10:41Z', 2:'2016-10-13T15:26:19Z',
3: '2016-10-14T15:26:19Z', 4: '2016-10-15T15:26:19Z', 5: '2016-10-... | 2 | 2016-10-13T21:48:59Z | 40,031,676 | <p>First, convert the dates to datetimes, then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.diff.html" rel="nofollow"><code>DataFrame.diff</code></a>:</p>
<pre><code>df.date = pd.to_datetime(df.date)
df.date.diff()
</code></pre>
<p>yields:</p>
<pre><code>0 NaT
1... | 2 | 2016-10-13T21:57:00Z | [
"python",
"pandas"
] |
python selenium-webdriver select option does not work | 40,031,592 | <p>The selection of Calgary in Canadian Cities list does not work, it will always return All cities in the search result after clicking search button pro grammatically. Here is my code:</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
# Initialize
driver = webdrive... | 1 | 2016-10-13T21:50:22Z | 40,033,377 | <pre><code>from selenium import webdriver
from selenium.webdriver.support.ui import Select
import time
# Initialize
driver = webdriver.Chrome()
driver.maximize_window()
driver.implicitly_wait(10)
driver.get('https://sjobs.brassring.com/TGWebHost/searchopenings.aspx?partnerid=25222&siteid=5011')
# Select city na... | 0 | 2016-10-14T01:05:36Z | [
"python",
"selenium-webdriver",
"drop-down-menu"
] |
How to detect when a maximum number is rolled? | 40,031,690 | <p>This question seems like it would be easily answered by just making an if statement for my maximum in the range, BUT please take a second to read before calling me an idiot. I am making a program that lets the user choose between many different dice. I am wondering if there is an easy way to detect when the maximum ... | -2 | 2016-10-13T21:58:10Z | 40,031,799 | <p>Just use </p>
<pre><code>def inphandle(choice):
roll = random.randint(1, choice)
return roll == choice
</code></pre>
| -1 | 2016-10-13T22:04:54Z | [
"python",
"if-statement",
"random"
] |
How to detect when a maximum number is rolled? | 40,031,690 | <p>This question seems like it would be easily answered by just making an if statement for my maximum in the range, BUT please take a second to read before calling me an idiot. I am making a program that lets the user choose between many different dice. I am wondering if there is an easy way to detect when the maximum ... | -2 | 2016-10-13T21:58:10Z | 40,031,800 | <p>first change <code>inphandle</code></p>
<pre><code>def inphandle(choice):
return random.randint(1,choice)
</code></pre>
<p>and then change</p>
<pre><code> while cont=="y" or cont=="Y":
roll = inphandle(choice)
dice(roll,choice)
...
def dice(roll,max_val):
if roll == max_val:prin... | 0 | 2016-10-13T22:04:56Z | [
"python",
"if-statement",
"random"
] |
How to detect when a maximum number is rolled? | 40,031,690 | <p>This question seems like it would be easily answered by just making an if statement for my maximum in the range, BUT please take a second to read before calling me an idiot. I am making a program that lets the user choose between many different dice. I am wondering if there is an easy way to detect when the maximum ... | -2 | 2016-10-13T21:58:10Z | 40,031,897 | <p>Let me suggest creating a class which handles different types of dice:</p>
<pre><code>class Die(object):
def __init__(self, num_faces):
self.num_faces = num_faces
def roll(self):
return random.randint(1, self.num_faces)
def is_min(self, number):
return number == 1
def is_m... | 0 | 2016-10-13T22:13:07Z | [
"python",
"if-statement",
"random"
] |
How to detect when a maximum number is rolled? | 40,031,690 | <p>This question seems like it would be easily answered by just making an if statement for my maximum in the range, BUT please take a second to read before calling me an idiot. I am making a program that lets the user choose between many different dice. I am wondering if there is an easy way to detect when the maximum ... | -2 | 2016-10-13T21:58:10Z | 40,031,967 | <p>This is what I would do:</p>
<p>change the inphandle to this:</p>
<pre><code>def inphandle(choice):
roll = random.randrange(1,choice+1,1)
return roll
</code></pre>
<p>And change main() to:</p>
<pre><code>def main():
choice = int(input("Please enter a number corresponding to the number of faces on your dice... | 0 | 2016-10-13T22:19:18Z | [
"python",
"if-statement",
"random"
] |
server 500 error python (visualstudio) | 40,031,724 | <p>I'm developing a python app using Djgango and I'm getting the server 500 error. I believe my paths are set correctly, the python manage.py runserver returns that the server is running. When I look at developer tools on the page it says "Failed to load resource: the server responded with a status of 404 (not found) <... | 2 | 2016-10-13T21:59:55Z | 40,032,646 | <p>For <code>render()</code>, you can pass context as a plain dictionary. If you're going to use a keyword argument, use <code>context</code> not <code>context_instance</code> <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#render" rel="nofollow">(docs)</a>. That's why you're getting <code>render... | 0 | 2016-10-13T23:28:00Z | [
"python",
"django",
"visual-studio"
] |
Python Removing full sentences of words from a novel-long string | 40,031,823 | <p>I have pasted a novel into a text file.
I would like to remove all the lines containing of the following sentences as they keep occurring at the top of each page (just removing their occurrences in those lines will do as well):</p>
<blockquote>
<p>"Thermal Molecular Movement in , Order and Probability" </p>
... | 0 | 2016-10-13T22:06:55Z | 40,031,915 | <ul>
<li>First <code>str.strip()</code> only removes the pattern if found at the <em>start</em> or the <em>end</em> of the string which explains that it seems to work in your test, but in fact is not what you want.</li>
<li>Second, you're trying to perform a replace on a list not on the current line (and you don't assi... | 2 | 2016-10-13T22:15:19Z | [
"python",
"string"
] |
Is it possible to dynamically create a metaclass for a class with several bases, in Python 3? | 40,031,906 | <p>In Python 2, with a trick it is possible to create a class with several bases, although the bases have metaclasses that are <em>not</em> subclass of each other.</p>
<p>The trick is that these metaclasses have themselves a metaclass (name it a "metametaclass"), and this metametaclass provides the metaclasses with a ... | 3 | 2016-10-13T22:13:40Z | 40,032,153 | <p>Here's an example that shows some options that you have in python3.x. Specifically, <code>C3</code> has a metaclass that is created dynamically, but in a lot of ways, explicitly. <code>C4</code> has a metaclass that is created dynamically within it's metaclass <em>function</em>. <code>C5</code> is just to demonst... | 0 | 2016-10-13T22:36:39Z | [
"python",
"metaclass"
] |
Is it possible to dynamically create a metaclass for a class with several bases, in Python 3? | 40,031,906 | <p>In Python 2, with a trick it is possible to create a class with several bases, although the bases have metaclasses that are <em>not</em> subclass of each other.</p>
<p>The trick is that these metaclasses have themselves a metaclass (name it a "metametaclass"), and this metametaclass provides the metaclasses with a ... | 3 | 2016-10-13T22:13:40Z | 40,032,300 | <p>In Python3 at the time the metaclass is used it have to be ready, and it can't know about the bases of the final (non-meta) class in order to dynamically create a metaclass at that point. </p>
<p>But ynstead of complicating things (I confess I could not wrap my head around your need for a meta-meta-class) - you c... | 1 | 2016-10-13T22:53:02Z | [
"python",
"metaclass"
] |
Is it possible to dynamically create a metaclass for a class with several bases, in Python 3? | 40,031,906 | <p>In Python 2, with a trick it is possible to create a class with several bases, although the bases have metaclasses that are <em>not</em> subclass of each other.</p>
<p>The trick is that these metaclasses have themselves a metaclass (name it a "metametaclass"), and this metametaclass provides the metaclasses with a ... | 3 | 2016-10-13T22:13:40Z | 40,032,877 | <p>In 95% of cases, it should be possible to use the machinery introduced in Python 3.6 due to <a href="https://www.python.org/dev/peps/pep-0447" rel="nofollow">PEP 447</a> to do <em>most</em> of what metaclasses can do using special new hooks. In that case, you will not need to combine metaclasses since your hooks ca... | 0 | 2016-10-13T23:57:28Z | [
"python",
"metaclass"
] |
main() not running functions properly | 40,031,988 | <pre><code>def load():
global name
global count
global shares
global pp
global sp
global commission
name=input("Enter stock name OR -999 to Quit: ")
count =0
while name != '-999':
count=count+1
shares=int(input("Enter number of shares: "))
pp=float(input("... | -2 | 2016-10-13T22:21:16Z | 40,032,221 | <p>I think this is the solution (one of many) you could probably take:</p>
<pre><code> def load():
shares=int(input("Enter number of shares: "))
pp=float(input("Enter purchase price: "))
sp=float(input("Enter selling price: "))
commission=float(input("Enter commission: "))
return shares, pp, s... | 1 | 2016-10-13T22:44:13Z | [
"python",
"function",
"python-3.x"
] |
How to convert to Time Duration | 40,032,041 | <p>The time duration is being described using four sets of double digits numbers separated with columns such as <code>00:02:01:16</code>.
I know that this represents a time interval or a time duration.
I would like to translate it to a single number that represents a time duration in a more common form such as "120 sec... | 0 | 2016-10-13T22:25:39Z | 40,032,070 | <pre><code>", ".join((a+b for a,b in zip(time_s.split(":")," hour(s), min(s), second(s), ms".split(","))))
</code></pre>
| 1 | 2016-10-13T22:28:29Z | [
"python"
] |
How to convert to Time Duration | 40,032,041 | <p>The time duration is being described using four sets of double digits numbers separated with columns such as <code>00:02:01:16</code>.
I know that this represents a time interval or a time duration.
I would like to translate it to a single number that represents a time duration in a more common form such as "120 sec... | 0 | 2016-10-13T22:25:39Z | 40,032,096 | <p>You need to use <code>timedelta</code>.</p>
<pre><code>from datetime import timedelta
</code></pre>
<p>Assume your time 00:02:01:16 is stored in <code>a</code>, which comes from <code>end_time - start_time</code></p>
<p>This will be automatically be a timedelta object. Then you can use <code>a.total_seconds()</co... | 0 | 2016-10-13T22:31:13Z | [
"python"
] |
Python Guess game how to repeat | 40,032,043 | <p>I have been working on this guessing game but i just cant get it to repeat the game when the player says yes. The game gives you 5 attempts to guess the number that it thought of and then after it asks you if you would like to play again but when you say 'YES' it just keeps repeating the sentence and when you say 'N... | 0 | 2016-10-13T22:26:04Z | 40,032,304 | <p>It's because your game code isn't in the function. Try it in this manner:</p>
<pre><code><import statements>
def game():
<insert all game code>
def main():
while True:
play_again = input("Would you like to play again?(yes or no) : ")
if play_again == "yes":
game()
... | 1 | 2016-10-13T22:53:42Z | [
"python",
"helper",
"python-3.5.2"
] |
Python Guess game how to repeat | 40,032,043 | <p>I have been working on this guessing game but i just cant get it to repeat the game when the player says yes. The game gives you 5 attempts to guess the number that it thought of and then after it asks you if you would like to play again but when you say 'YES' it just keeps repeating the sentence and when you say 'N... | 0 | 2016-10-13T22:26:04Z | 40,032,455 | <p>There's a few problems with your code that I'd like to point out.
The main one being that your game does not run again when typing yes. All it will do is run <code>main()</code> which will print <code>your game</code> and then ask you if you want to retry once again. It's easier if you put your game inside a defini... | 1 | 2016-10-13T23:07:32Z | [
"python",
"helper",
"python-3.5.2"
] |
How to insert sleep into a list | 40,032,081 | <p>I am looking to create just a small module to implement the ability to text scroll. I've tried a few things so far and this is what I'm sitting on:</p>
<pre><code>from time import sleep
def text_scroll(x):
x = x.split()
#here is where I'd like to add the sleep function
x = " ".join(x)
print x
text_sc... | -1 | 2016-10-13T22:29:34Z | 40,032,103 | <pre><code>for word in x.split():
print word,
time.sleep(1)
</code></pre>
<p>Comma prevents <em>print</em> from adding line feed to your output</p>
| -2 | 2016-10-13T22:32:08Z | [
"python",
"sleep"
] |
How to insert sleep into a list | 40,032,081 | <p>I am looking to create just a small module to implement the ability to text scroll. I've tried a few things so far and this is what I'm sitting on:</p>
<pre><code>from time import sleep
def text_scroll(x):
x = x.split()
#here is where I'd like to add the sleep function
x = " ".join(x)
print x
text_sc... | -1 | 2016-10-13T22:29:34Z | 40,032,204 | <p>Try the following code:</p>
<pre><code>from time import sleep
from sys import stdout
def text_scroll(text):
words = text.split()
for w in words:
print w,
stdout.flush()
sleep(1)
</code></pre>
<p>The comma at the end of the print does not add new line '\n'.
The flush() function flus... | 2 | 2016-10-13T22:41:52Z | [
"python",
"sleep"
] |
How to insert sleep into a list | 40,032,081 | <p>I am looking to create just a small module to implement the ability to text scroll. I've tried a few things so far and this is what I'm sitting on:</p>
<pre><code>from time import sleep
def text_scroll(x):
x = x.split()
#here is where I'd like to add the sleep function
x = " ".join(x)
print x
text_sc... | -1 | 2016-10-13T22:29:34Z | 40,032,208 | <p>If it is python 2.7, you can do the following, which is what volcano suggested.</p>
<pre><code>from time import sleep
def text_scroll(x):
for word in x.split():
print word,
sleep(1)
text_scroll("Hello world")
</code></pre>
<p>This works because it splits the input into individual words and th... | 0 | 2016-10-13T22:42:54Z | [
"python",
"sleep"
] |
Regex extract everything after and before a specific text | 40,032,127 | <p>I need to extract from this:</p>
<pre><code><meta content=",\n\n\nÃscar Mauricio Lizcano Arango,\n\n\n\n\n\n\n\nBerner León Zambrano Eraso,\n\n\n\n\n" name="keywords"><meta content="Congreso Visible - Toda la información sobre el Congreso Colombiano en un solo lugar" property="og:title"/><meta co... | -1 | 2016-10-13T22:34:12Z | 40,032,286 | <p>I was able to do it by doing</p>
<pre><code>re.findall(r'(?<=content=",)[^.]+(?=name=)', names)
</code></pre>
| 1 | 2016-10-13T22:51:52Z | [
"python",
"regex"
] |
Regex extract everything after and before a specific text | 40,032,127 | <p>I need to extract from this:</p>
<pre><code><meta content=",\n\n\nÃscar Mauricio Lizcano Arango,\n\n\n\n\n\n\n\nBerner León Zambrano Eraso,\n\n\n\n\n" name="keywords"><meta content="Congreso Visible - Toda la información sobre el Congreso Colombiano en un solo lugar" property="og:title"/><meta co... | -1 | 2016-10-13T22:34:12Z | 40,032,594 | <p>This might help you:</p>
<pre><code># -*- coding: utf-8 -*-
import re
or_str = '<meta content=",\n\n\nÃscar Mauricio Lizcano Arango,\n\n\n\n\n\n\n\nBerner León Zambrano Eraso,\n\n\n\n\n" name="keywords"><meta content="Congreso Visible - Toda la información sobre el Congreso Colombiano en un solo lugar"... | 1 | 2016-10-13T23:23:07Z | [
"python",
"regex"
] |
Find max UDP payload -- python socket send/sendto | 40,032,171 | <p>How can I find the maximum length of a UDP payload in Python (Python 2), preferably platform-independent?</p>
<p>Specifically, I want to avoid <code>[Errno 90] Message too long</code> AKA <code>errno.EMSGSIZE</code>.</p>
<h3>Background</h3>
<ul>
<li>The maximum allowed by the UDP packet format <a href="http://sta... | 0 | 2016-10-13T22:38:30Z | 40,033,837 | <p>Well, there's always the try-it-and-see approach... I wouldn't call this elegant, but it is platform-independent:</p>
<pre><code>import socket
def canSendUDPPacketOfSize(sock, packetSize):
ip_address = "127.0.0.1"
port = 5005
try:
msg = "A" * packetSize
if (sock.sendto(msg, (ip_address, port))... | 1 | 2016-10-14T02:13:25Z | [
"python",
"sockets",
"networking",
"udp"
] |
Find max UDP payload -- python socket send/sendto | 40,032,171 | <p>How can I find the maximum length of a UDP payload in Python (Python 2), preferably platform-independent?</p>
<p>Specifically, I want to avoid <code>[Errno 90] Message too long</code> AKA <code>errno.EMSGSIZE</code>.</p>
<h3>Background</h3>
<ul>
<li>The maximum allowed by the UDP packet format <a href="http://sta... | 0 | 2016-10-13T22:38:30Z | 40,033,932 | <p>Some of your premises need a minor correction. </p>
<p>As a result of the IP header containing a 16 bit field for length, the largest size an IPv4 message can be is <code>65535</code> bytes And that includes the IP header itself.</p>
<p>The IP packet itself has at least a 20 byte header. Hence 65535 - 20 == <cod... | 2 | 2016-10-14T02:24:12Z | [
"python",
"sockets",
"networking",
"udp"
] |
What am I doing wrong, python loop not repeating? | 40,032,219 | <p>I just had this working, and now, for the life of me, I cannot get the loop to continue, as it only produces the outcome of the first input. Where did I go wrong? I know im an amateur, but whatever help you might have would be awesome! Thanks. </p>
<pre><code>sequence = open('sequence.txt').read().replace('\n','')
... | 2 | 2016-10-13T22:43:55Z | 40,032,656 | <p>This an issue of scope. By default Python variables are local in scope. In servy, where you set inez to a new value, Python assumes this is a new local variable because you have not specifically declared it to be global. Therefore when you call serx the second time, the global variable inez is unchanged. Here is a s... | 2 | 2016-10-13T23:29:15Z | [
"python"
] |
spark dataframe keep most recent record | 40,032,276 | <p>I have a dataframe similar to: </p>
<pre><code>id | date | value
--- | ---------- | ------
1 | 2016-01-07 | 13.90
1 | 2016-01-16 | 14.50
2 | 2016-01-09 | 10.50
2 | 2016-01-28 | 5.50
3 | 2016-01-05 | 1.50
</code></pre>
<p>I am trying to keep the most recent values for each id, like this:</p>
<pre>... | 0 | 2016-10-13T22:50:34Z | 40,038,443 | <p>The window operator as suggested works very well to solve this problem:</p>
<pre><code>from datetime import date
rdd = sc.parallelize([
[1, date(2016, 1, 7), 13.90],
[1, date(2016, 1, 16), 14.50],
[2, date(2016, 1, 9), 10.50],
[2, date(2016, 1, 28), 5.50],
[3, date(2016, 1, 5), 1.50]
])
df = r... | 2 | 2016-10-14T08:25:33Z | [
"python",
"apache-spark"
] |
Pandas sort dataframe by column with strings and integers | 40,032,341 | <p>I have a dataframe with a column containing both integers and strings:</p>
<pre><code>>>> df = pd.DataFrame({'a':[2,'c',1,10], 'b':[5,4,0,6]})
>>> df
a b
0 2 5
1 c 4
2 1 0
3 10 6
</code></pre>
<p>I want to sort the dataframe by column a, treating the strings and integers separatel... | 0 | 2016-10-13T22:57:08Z | 40,032,613 | <p>One option would be to group the data frame by the data type of column <code>a</code> and then sort each group separately:</p>
<pre><code>df.groupby(df.a.apply(type) != str).apply(lambda g: g.sort('a')).reset_index(drop = True)
</code></pre>
<p><a href="https://i.stack.imgur.com/cwuCV.png" rel="nofollow"><img src=... | 1 | 2016-10-13T23:24:53Z | [
"python",
"sorting",
"pandas"
] |
Pandas Date Range Monthly on Specific Day of Month | 40,032,371 | <p>In Pandas, I know you can use anchor offsets to specify more complicated reucrrences:
<a href="http://pandas.pydata.org/pandas-docs/stable/timeseries.html#anchored-offset" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/timeseries.html#anchored-offset</a></p>
<p>I want to specify a date_range such that i... | 0 | 2016-10-13T22:59:45Z | 40,040,932 | <p>IIUC you can do it this way:</p>
<pre><code>In [18]: pd.DataFrame(pd.date_range('2016-01-01', periods=10, freq='MS') + pd.DateOffset(days=26), columns=['Date'])
Out[18]:
Date
0 2016-01-27
1 2016-02-27
2 2016-03-27
3 2016-04-27
4 2016-05-27
5 2016-06-27
6 2016-07-27
7 2016-08-27
8 2016-09-27
9 2016-10-27
</c... | 1 | 2016-10-14T10:27:24Z | [
"python",
"datetime",
"pandas"
] |
I need to vectorize the following in order for the code can run faster | 40,032,382 | <p>This portion I was able to vectorize and get rid of a nested loop.</p>
<pre><code>def EMalgofast(obsdata, beta, pjt):
n = np.shape(obsdata)[0]
g = np.shape(pjt)[0]
zijtpo = np.zeros(shape=(n,g))
for j in range(g):
zijtpo[:,j] = pjt[j]*stats.expon.pdf(obsdata,scale=beta[j])
zijdeno... | 0 | 2016-10-13T23:00:30Z | 40,034,157 | <p>I'm guessing Python is not your first programming language based on what I see. The reason I'm saying this is that in python, normally we don't have to deal with manipulating indexes. You act directly on the value or the key returned. Make sure not to take this as an offense, I do the same coming from C++ myself.... | 0 | 2016-10-14T02:51:47Z | [
"python",
"python-2.7",
"python-3.x",
"numpy"
] |
Python(jupyter) for prime numbers | 40,032,408 | <pre><code>primes=[]
for i in range(3,6):
is_prime=True
for j in range(2,i):
if i%j ==0:
is_prime=False
if is_prime=True:
primes= primes + [i]
primes
</code></pre>
<p>The code seems logical to me but I keep getting a syntax error at the 2nd last sentence <code>if is_prime=True<... | 2 | 2016-10-13T23:02:51Z | 40,032,433 | <p><code>=</code> is the assignment operator. For equality checks, you should use the <code>==</code> operator:</p>
<pre><code>if is_prime == True:
</code></pre>
<p>Or better yet, since <code>is_prime</code> is a boolean expression in its own right, just evaluate it:</p>
<pre><code>if is_prime:
</code></pre>
| 2 | 2016-10-13T23:05:38Z | [
"python",
"syntax-error"
] |
Selecting all elements that meet a criteria using selenium (python) | 40,032,560 | <p>Using selenium, is there a way to have the script pick out elements that meet a certain criteria? </p>
<p>What I'm exactly trying to do is have selenium select all Twitch channels that have more than X viewers. If you inspect element, you find this: </p>
<pre><code><p class="info"
562
viewers on
<... | 0 | 2016-10-13T23:19:01Z | 40,032,691 | <p>It is hard to give an exact code as we only get a small sample of the HTML, but this should work if you tweak it a bit.</p>
<pre><code>from selenium import webdriver
driver = webdriver.Firefox()
driver.get('http://www.website.com')
source = driver.page_source
location = source.find('<p class="info"')
source = s... | 0 | 2016-10-13T23:32:58Z | [
"python",
"selenium",
"selenium-webdriver"
] |
Selecting all elements that meet a criteria using selenium (python) | 40,032,560 | <p>Using selenium, is there a way to have the script pick out elements that meet a certain criteria? </p>
<p>What I'm exactly trying to do is have selenium select all Twitch channels that have more than X viewers. If you inspect element, you find this: </p>
<pre><code><p class="info"
562
viewers on
<... | 0 | 2016-10-13T23:19:01Z | 40,032,889 | <p>First of all, you can find all twitch channel links. Then, filter them based on the view count.</p>
<p>Something along these lines:</p>
<pre><code>import re
from selenium import webdriver
THRESHOLD = 100
driver = webdriver.Firefox()
driver.get("url")
pattern = re.compile(r"(\d+)\s+viewers on")
for link in dr... | 1 | 2016-10-13T23:59:58Z | [
"python",
"selenium",
"selenium-webdriver"
] |
strip whitespace in pandas MultiIndex index columns values | 40,032,612 | <p>i have a MultiIndex dataframe of mix datatypes. One of the index columns values has trailing whitespaces. How can i strip these trailing whitespace for the index columns. here is the sample code:</p>
<pre><code>import pandas as pd
idx = pd.MultiIndex.from_product([['1.0'],['NY ','CA ']], names=['country_code','s... | 0 | 2016-10-13T23:24:51Z | 40,032,663 | <p>You can use <code>.index.set_levels()</code> and <code>.index.get_level_values()</code> to manipulate the index at a specific level:</p>
<pre><code>df.index.set_levels(df.index.get_level_values(level = 1).str.strip(),
level = 1, inplace=True)
df.index
# MultiIndex(levels=[['1.0'], ['NY', 'CA']... | 1 | 2016-10-13T23:30:01Z | [
"python",
"string",
"pandas",
"multi-index"
] |
strip whitespace in pandas MultiIndex index columns values | 40,032,612 | <p>i have a MultiIndex dataframe of mix datatypes. One of the index columns values has trailing whitespaces. How can i strip these trailing whitespace for the index columns. here is the sample code:</p>
<pre><code>import pandas as pd
idx = pd.MultiIndex.from_product([['1.0'],['NY ','CA ']], names=['country_code','s... | 0 | 2016-10-13T23:24:51Z | 40,032,671 | <p>Similar to the other answer:</p>
<pre><code>df.index.set_levels(df.index.map(lambda x: (x[0], x[1].strip())), inplace=True)
</code></pre>
| 1 | 2016-10-13T23:30:49Z | [
"python",
"string",
"pandas",
"multi-index"
] |
Why does re.VERBOSE prevent my regex pattern from working? | 40,032,632 | <p>I want to use the following regex to get modified files from svn log, it works fine as a single line, but since it's complex, I want to use <code>re.VERBOSE</code> so that I can add comment to it, then it stopped working. What am I missing here? Thanks!</p>
<pre><code>revision='''r123456 | user | 2013-12-22 11:21:4... | 3 | 2016-10-13T23:26:53Z | 40,032,792 | <p>Use a raw string literal:</p>
<pre><code>re.search(r'''
(?<=Changed\spaths:\n)
(?:\s{3}[AMD]\s.*\n)*
(?=\n)
''', revision, re.VERBOSE)
</code></pre>
<p>See this fixed <a href="http://ideone.com/xlYIMF" rel="nofollow">Python demo</a>. </p>
<p>The main issue ... | 2 | 2016-10-13T23:46:57Z | [
"python",
"regex",
"parsing",
"svn"
] |
perimeter of a polygon with given coordinates | 40,032,641 | <p>i am trying to find the perimeter of 10 point polygon with given coordinates. </p>
<p>This is what ive got so far</p>
<p>however keep getting an error</p>
<pre><code>poly = [[31,52],[33,56],[39,53],[41,53],[42,53],[43,52],[44,51],[45,51]]
x=row[0]
y=row[1]
``def perimeter(poly):
"""A sequence of (x,y) numer... | -1 | 2016-10-13T23:27:29Z | 40,032,956 | <p><code>poly</code> is a list, to index an element in this list, you need to supply a single index, not a pair of indices, which is why <code>poly[x,y]</code> is a syntax error. The elements are lists of length 2. If <code>p</code> is one of those elements, then for that point <code>(x,y) = (p[0],p[1])</code>. The fol... | 0 | 2016-10-14T00:07:26Z | [
"python"
] |
Concatenate two separate strings from arrays in a for loop | 40,032,673 | <p>Okay so I have two lists, they can be anywhere from just one value long to 20, but they will always have the same amount as eachother.</p>
<p>e.g </p>
<pre><code>alphabet = ['a', 'b', 'c', 'd', 'e']
numbers = ['1', '2', '3', '4', '5']
</code></pre>
<p>Now my objective is to create a for loop that would go through... | 0 | 2016-10-13T23:31:05Z | 40,032,692 | <p>You can use <code>zip</code> and <code>join</code>:</p>
<pre><code>[''.join(p) for p in zip(alphabet, numbers)]
# ['a1', 'b2', 'c3', 'd4', 'e5']
</code></pre>
<p>As for the second example:</p>
<pre><code>[''.join(p) for p in zip(names, IDs)]
# ['john100', 'harry200', 'joe300']
</code></pre>
| 3 | 2016-10-13T23:33:01Z | [
"python",
"concatenation"
] |
Concatenate two separate strings from arrays in a for loop | 40,032,673 | <p>Okay so I have two lists, they can be anywhere from just one value long to 20, but they will always have the same amount as eachother.</p>
<p>e.g </p>
<pre><code>alphabet = ['a', 'b', 'c', 'd', 'e']
numbers = ['1', '2', '3', '4', '5']
</code></pre>
<p>Now my objective is to create a for loop that would go through... | 0 | 2016-10-13T23:31:05Z | 40,032,818 | <p>As an alternative to @Psidom one-liner solution you could just use <code>zip()</code>:</p>
<pre><code>>>>[i+j for i, j in zip(alphabet, numbers)]
>>>['a1', 'b2', 'c3', 'd4', 'e5']
</code></pre>
<p>Or if you perfef to use a regular for loop:</p>
<pre><code>res = []
for i, j in zip(alphabet, numbe... | 1 | 2016-10-13T23:51:12Z | [
"python",
"concatenation"
] |
Error trying to use super().__init__ | 40,032,756 | <p>I am fairly new to Python and have taken the code excerpt below from a book I'm working with. </p>
<p>It is listed below <strong>exactly</strong> as it is written and explained in the book but yet it throws the following error:</p>
<pre><code>TypeError: super() takes at least 1 argument (0 given)
</code></pre>
<p... | 0 | 2016-10-13T23:42:29Z | 40,032,870 | <p>You're running Python 2, not Python 3. <a href="https://docs.python.org/2/library/functions.html#super" rel="nofollow">Python 2's <code>super</code></a> requires at least one argument (the type in which this method was defined), and usually two (current type and <code>self</code>). Only <a href="https://docs.python.... | 1 | 2016-10-13T23:56:38Z | [
"python",
"inheritance",
"init",
"super"
] |
count lines and create new file | 40,032,791 | <p>So basically I have to call the text file, and create the new file while adding some strings.</p>
<p>For example if my input text is:</p>
<p>Hello</p>
<p>World</p>
<p>Nice to Meet You</p>
<p>my output text has to be:</p>
<p>1: Hello</p>
<p>2: World</p>
<p>3: Nice to Meet You</p>
<p>Below is the code that I ... | 0 | 2016-10-13T23:46:47Z | 40,032,825 | <p>textfile:</p>
<pre><code>Hello
World
Nice to Meet You
</code></pre>
<p>code:</p>
<pre><code>with open('test.txt') as f:
for i , line in enumerate(f.readlines()):
print "{0}:{1}".format(i+1,line)
</code></pre>
<p>output:</p>
<pre><code>1:Hello
2:World
3:Nice to Meet You
</code></pre>
<p>then you c... | 1 | 2016-10-13T23:51:51Z | [
"python"
] |
count lines and create new file | 40,032,791 | <p>So basically I have to call the text file, and create the new file while adding some strings.</p>
<p>For example if my input text is:</p>
<p>Hello</p>
<p>World</p>
<p>Nice to Meet You</p>
<p>my output text has to be:</p>
<p>1: Hello</p>
<p>2: World</p>
<p>3: Nice to Meet You</p>
<p>Below is the code that I ... | 0 | 2016-10-13T23:46:47Z | 40,032,862 | <p>First you open the file:</p>
<pre><code>with open('filetext') as f:
</code></pre>
<p>Then you read the whole thing into a list:</p>
<pre><code>content=f.readlines()
</code></pre>
<p>Then you attempt to iterate over the now-empty file object:</p>
<pre><code>for count in f:
</code></pre>
<p>Since it's empty, ... | 1 | 2016-10-13T23:56:04Z | [
"python"
] |
Generating Plots from .csv file | 40,032,800 | <p>I'm trying to make several plots of Exoplanet data from NASA's Exoplanet Archive. The problem is nothing I do will return the columns of the csv file with the headers on the first line of the csv file.</p>
<p>The Error I get is</p>
<pre><code> NameError: name 'pl_orbper' is not defined
</code></pre>
<p><a href... | 0 | 2016-10-13T23:49:06Z | 40,033,796 | <p>Change the following line:</p>
<pre><code>plt.plot(pl_orbper,pl_bmassj)
</code></pre>
<p>to </p>
<pre><code>plt.plot(data['pl_orbper'],data['pl_bmassj'])
</code></pre>
<p>With the following data:</p>
<pre class="lang-none prettyprint-override"><code>rowid,pl_orbper,pl_bmassj
1, 326.03, 0.320
2, 327.03, 0.420
3,... | 0 | 2016-10-14T02:06:20Z | [
"python",
"csv",
"matplotlib"
] |
Calling C's hello world from Python | 40,032,904 | <p>My C script:</p>
<pre><code>/* Hello World program */
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}
</code></pre>
<p>I want to see <code>Hello, World!</code> get printed directly in my Python IDE (Rodeo IDE) in the <strong>easiest</strong> way possible. </p>
<p>So far, I'v... | -1 | 2016-10-14T00:01:26Z | 40,032,940 | <p>You could just print the text right to the Python Module by using the following code:</p>
<pre><code>print("Hello, world!")
</code></pre>
| -2 | 2016-10-14T00:05:41Z | [
"python",
"c",
"rodeo"
] |
Calling C's hello world from Python | 40,032,904 | <p>My C script:</p>
<pre><code>/* Hello World program */
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}
</code></pre>
<p>I want to see <code>Hello, World!</code> get printed directly in my Python IDE (Rodeo IDE) in the <strong>easiest</strong> way possible. </p>
<p>So far, I'v... | -1 | 2016-10-14T00:01:26Z | 40,032,953 | <pre><code>>>> import subprocess
>>> subprocess.check_output("./a.out")
'Hello World!\n'
</code></pre>
<p>Regarding your second question, you could also just call gcc using subprocess. In that case, call is probably the right thing to use, since you presumably want to check for failure before runnin... | 4 | 2016-10-14T00:07:03Z | [
"python",
"c",
"rodeo"
] |
Calling C's hello world from Python | 40,032,904 | <p>My C script:</p>
<pre><code>/* Hello World program */
#include <stdio.h>
int main() {
printf("Hello, World! \n");
return 0;
}
</code></pre>
<p>I want to see <code>Hello, World!</code> get printed directly in my Python IDE (Rodeo IDE) in the <strong>easiest</strong> way possible. </p>
<p>So far, I'v... | -1 | 2016-10-14T00:01:26Z | 40,033,022 | <p>If you compile the C script (say, to <code>a.out</code>):</p>
<pre><code>#include <stdio.h>
int main(void) {
printf("Hello, World! \n");
return 0;
}
</code></pre>
<p>You can easily call it by using <a href="https://docs.python.org/3/library/ctypes.html" rel="nofollow">CTypes</a>:</p>
<pre><code># hel... | 4 | 2016-10-14T00:15:54Z | [
"python",
"c",
"rodeo"
] |
for loop right-triangles not separating | 40,032,909 | <pre><code>base=int(input("Enter the triangle size: "))
for i in range(1, base + 1):
print (('*' * i) + (' ' * (base - i)))
for i in range(1, base + 1)[::-1]:
print (('*' * i) + (' ' * (base - i)))
for i in range(1, base + 1):
print (' ' * (base - i) + ('*' * i))
for i in range(1, base + 1)[::-1]:
print... | 2 | 2016-10-14T00:01:39Z | 40,032,985 | <p>I've just added prints between triangles to reproduce the expected output. Is that what you want ?</p>
<pre><code>base=int(input("Enter the triangle size: "))
for i in range(1, base + 1):
print (('*' * i) + (' ' * (base - i)))
print()
for i in range(1, base + 1)[::-1]:
print (('*' * i) + (' ' * (base - i)))... | 0 | 2016-10-14T00:11:08Z | [
"python",
"python-3.x",
"for-loop"
] |
how to tell sphinx that source code is in this path and build in that path | 40,032,930 | <p>I want to run sphinx on a library in a conda virtual environment with path</p>
<pre><code>/anaconda/envs/test_env/lib/site-packages/mypackage
</code></pre>
<p>and put the html files in the path</p>
<pre><code>/myhtmlfiles/myproject
</code></pre>
<p>where my <code>conf.py</code> and <code>*.rst</code> files are i... | 0 | 2016-10-14T00:04:06Z | 40,033,437 | <p><code>make</code> is not a sphinx command. That command actually runs either a <code>make</code> with a Makefile or <code>make.bat</code> (depending on your operating system), which then locates the relevant files before invoking <code>sphinx-build</code>. You will need to modify the make files and/or set the proper... | 1 | 2016-10-14T01:14:52Z | [
"python",
"python-sphinx"
] |
How to get the answer for exponents questions | 40,032,955 | <p>I'm new to python. I'm also a beginner on this subject. So any help would be great! </p>
<p>I'm trying to write a code for calculating the answer for questions like 3^2 = 9 , 2^3 = 8, etc. </p>
<p>I know there is a ** for this. But I need to use while loops and for loops for this. </p>
<p>I don't know what I'm do... | 0 | 2016-10-14T00:07:13Z | 40,033,212 | <p>i used your code also you can use <code>while</code> without ExpNeeded and <code>break</code> loop(<code>while</code>) i.e <code>while True:</code></p>
<pre><code>ExpNeeded = True
while ExpNeeded :
base2 = 1
base1=int(input("Base:"))
while base1<=0:
print "Please enter a number greater than ... | 0 | 2016-10-14T00:43:00Z | [
"python",
"python-3.x",
"for-loop",
"while-loop",
"exponential"
] |
Python - Beginner questions | 40,032,988 | <p>I am at the beginning of Python programming and have a few questions.
When I run the code, I get this compile error:</p>
<blockquote>
<p>IndentationError: unindent does not match any outer indentation level</p>
</blockquote>
<ol>
<li>I think the error comes, because of the <code>return</code> in the last line. W... | 0 | 2016-10-14T00:11:56Z | 40,033,024 | <p>In Python, the whitespace at the beginning of the line is significant. Statements at the same logical level <em>must</em> be indented the same amount.</p>
<p>In your case, the final line has an extra space character at the beginning of the line. Make sure what the <code>w</code> in the last line is all the way to t... | 1 | 2016-10-14T00:16:11Z | [
"python",
"printing",
"compiler-errors",
"return"
] |
Python - Beginner questions | 40,032,988 | <p>I am at the beginning of Python programming and have a few questions.
When I run the code, I get this compile error:</p>
<blockquote>
<p>IndentationError: unindent does not match any outer indentation level</p>
</blockquote>
<ol>
<li>I think the error comes, because of the <code>return</code> in the last line. W... | 0 | 2016-10-14T00:11:56Z | 40,033,041 | <p>Your final piece of code: whileexample()
You added a redundant space in this first column.</p>
| 0 | 2016-10-14T00:18:28Z | [
"python",
"printing",
"compiler-errors",
"return"
] |
Python - Beginner questions | 40,032,988 | <p>I am at the beginning of Python programming and have a few questions.
When I run the code, I get this compile error:</p>
<blockquote>
<p>IndentationError: unindent does not match any outer indentation level</p>
</blockquote>
<ol>
<li>I think the error comes, because of the <code>return</code> in the last line. W... | 0 | 2016-10-14T00:11:56Z | 40,033,090 | <p>@Robᵩ is correct with the whitespacing. As for your other question, %d and %7d are place holders for whatever is in the parentheses. </p>
<p>The 'd' in this case means you want whatever is displayed in the parentheses to be formatted as a decimal. </p>
<p>The '7' indicates how much whitespace before the next var... | 1 | 2016-10-14T00:24:57Z | [
"python",
"printing",
"compiler-errors",
"return"
] |
Returning inncorrect variables in python | 40,033,006 | <p>I am trying to make a simple project where balls bounce around the screen using object oriented. However, I can not get the correct variable to return. If I am tryin to return an integer, it instead returns: main.ball instance at 0x000000000924B648>></p>
<pre><code>def functionCallback(event):
lB.append(ball(ev... | -1 | 2016-10-14T00:13:41Z | 40,034,078 | <p>I managed to find the problem. I needed to add () behind the method calls like: <code>can.move(oval, lB[oval-1].getX2(), lB[oval-1].getY())
</code></p>
| 0 | 2016-10-14T02:39:37Z | [
"python",
"return",
"object-oriented-analysis"
] |
Using SimpleHTTPServer to interpret failed requests and dynamically create JSON pages? | 40,033,015 | <p>I have a python program that takes and validates user input <strong><em>(flightNumber,dateStamp)</em></strong> and performs three api lookups: </p>
<pre><code>1. get flight info,
2: find flightId,
3: track flightID and return up to date JSON.
</code></pre>
<p>I should now like to make this information availabl... | 0 | 2016-10-14T00:15:24Z | 40,033,078 | <p>Yes, this all sounds possible, even pretty simple, especially given the lack of detail you have provided.</p>
| 0 | 2016-10-14T00:22:49Z | [
"python",
"json",
"url",
"redirect",
"simplehttpserver"
] |
Run a python application/script on startup using Linux | 40,033,066 | <p>I've been learning Python for a project required for work. We are starting up a new server that will be running linux, and need a python script to run that will monitor a folder and handle files when they are placed in the folder.</p>
<p>I have the python "app" working, but I'm having a hard time finding how to ma... | 2 | 2016-10-14T00:21:55Z | 40,033,097 | <p>You can set up the script to run via <code>cron</code>, configuring time as <code>@reboot</code></p>
<p>With python scripts, you will not need to compile it. You might need to install it, depending on what assumptions your script makes about its environment. </p>
| 2 | 2016-10-14T00:25:57Z | [
"python",
"linux"
] |
DLL Load failed: %1 is not a valid Win32 Application for StatsModel | 40,033,108 | <p>Similar to <a href="http://stackoverflow.com/questions/19019720/importerror-dll-load-failed-1-is-not-a-valid-win32-application-but-the-dlls">ImportError: DLL load failed: %1 is not a valid Win32 application. But the DLL's are there</a>
...</p>
<p>This has been 4 hours of my life, so any help is appreciated: </p... | 0 | 2016-10-14T00:27:18Z | 40,048,512 | <p>Figured this out after talking it through with others who had similar problems. </p>
<p>Don't know if these steps were necessary but, to be sure I uninstalled Python then specifically reinstalled the 64 bit version. Then I uninstalled Anacondas and reinstalled specifically the 64 bit version. Note I believe Python ... | 0 | 2016-10-14T17:07:17Z | [
"python",
"dll",
"statsmodels"
] |
Multiple MySQL JOINs and duplicated cells | 40,033,167 | <p>I have two MySQL queries that give the results that I'm looking for. I'd ultimately like to combine these two queries to produce a single table and I'm stuck.</p>
<p>QUERY 1:</p>
<pre><code>SELECT scoc.isr, outcome_concept_id, concept_name as outcome_name
FROM standard_case_outcome AS sco INNER JOIN concept AS c
O... | 0 | 2016-10-14T00:35:42Z | 40,033,260 | <p>This should get you the desired results.</p>
<pre><code>SELECT
`scoc`.`isr` AS `isr`,
`sco` .`outcome_concept_id` AS `outcome_concept_id`,
`c1` .`concept_name` AS `outcome_name`,
`scd` .`drug_seq` AS `drug_seq`,
`scd` .`concept_id` AS `concept_id`,
`c2... | 1 | 2016-10-14T00:50:29Z | [
"python",
"mysql",
"sql",
"pandas"
] |
Merge keys with the same value in dictionary of lists | 40,033,176 | <p>I have a dictionary of lists and would like to obtain just one key in case of keys with duplicated values. For example:</p>
<pre><code>dic1 = {8: [0, 4], 1: [0, 4], 7:[3], 4:[1, 5], 11:[3]}
</code></pre>
<p>resulting dictionary</p>
<pre><code>dic2 = {1: [0, 4], 7:[3], 4:[1, 5]}
</code></pre>
<p>The strategy woul... | 0 | 2016-10-14T00:37:56Z | 40,033,208 | <p>Turn the lists into tuples, which are hashable.</p>
<pre><code>dic2 = {tuple(y): x for x, y in dic.items()}
</code></pre>
<p>You can convert back into a list afterward if you like:</p>
<pre><code>result = {v:list(k) for k,v in dic2.items()}
</code></pre>
| 4 | 2016-10-14T00:42:35Z | [
"python",
"list",
"dictionary"
] |
Using Boto3 in python to acquire results from dynamodb and parse into a usable variable or dictionary | 40,033,189 | <p>I used to be a SQL query master in MySQL and SQL server, but I'm far from mastering nosql and dynamo db just seems very over simplified. Anyways no rants, I'm trying to just acquire the most recent entry into dynamo db or to parse out the results I get so I can skim the most recent item off the top.</p>
<p>this is ... | 0 | 2016-10-14T00:40:43Z | 40,065,671 | <p>at the end of my code where it says "print(json.dumps(i, cls=DecimalEncoder))" I changed that to "d = ast.literal_eval((json.dumps(i, cls=DecimalEncoder)))" I also added import ast at the top. It worked beautifully.</p>
<pre><code>import ast
table = dynamodb.Table('footable')
response = table.scan(
Select="ALL... | 0 | 2016-10-16T00:39:06Z | [
"python",
"json",
"amazon-web-services",
"amazon-dynamodb",
"boto"
] |
Pandas Grouping - Values as Percent of Grouped Totals Not Working | 40,033,190 | <p>Using a data frame and pandas, I am trying to figure out what each value is as a percentage of the grand total for the "group by" category</p>
<p>So, using the tips database, I want to see, for each sex/smoker, what the proportion of the total bill is for female smoker / all female and for female non smoker / all f... | 0 | 2016-10-14T00:40:54Z | 40,033,348 | <p>You can add another grouped by process after you get the <code>sum</code> table to calculate the percentage:</p>
<pre><code>(df.groupby(['sex', 'smoker'])['total_bill'].sum()
.groupby(level = 0).transform(lambda x: x/x.sum())) # group by sex and calculate percentage
#sex smoker
#Female No 0.622350... | 1 | 2016-10-14T01:02:29Z | [
"python",
"pandas",
"dataframe",
"aggregate",
"aggregation"
] |
how do I pip uninstall package beginning with special character '-e ...'? | 40,033,218 | <p>pip freeze:</p>
<pre><code> ...
howdoi==1.1.9
**-e git+https://github.com/fredzannarbor/howdoi21.git@0efdd53947bb233d529225db30aba2e1e4e2cc6e#egg=howdoi21**
html5lib==0.999
...
</code></pre>
<p>How do I delete the package whose name begins '-e ...'? I tried </p>
<pre><code> pip uninstall '\-e git+https:/... | 0 | 2016-10-14T00:43:31Z | 40,034,083 | <p>Try <code>pip uninstall howdoi21</code></p>
<ul>
<li>Usually the 'egg=[PackageName][-dev][-version]' part contains the project name. </li>
<li>If the github repository was not deleted, you can find the project name from <code>setup.py</code> file. </li>
<li><a href="http://stackoverflow.com/questions/17346619/how-... | 0 | 2016-10-14T02:40:04Z | [
"python",
"pip"
] |
Edit scikit-learn decisionTree | 40,033,222 | <p>I would like to edit sklearn decisionTree,
e.g. change conditions or cut node/leaf etc.</p>
<p>But there seems to be no functions to do that, if I could export to a file, edit it to import.</p>
<p>How can I edit decisionTree?</p>
<p>Environment:</p>
<ul>
<li>Windows10</li>
<li>python3.3</li>
<li>sklearn 0.17.1<... | 0 | 2016-10-14T00:43:54Z | 40,033,698 | <p>Even though the docs say that the <code>splitter</code> kwarg for <code>DecisionTreeClassifier</code> is a string, you could give it a class as well. Evidence:</p>
<p><a href="https://github.com/scikit-learn/scikit-learn/blob/412996f/sklearn/tree/tree.py#L353-L360" rel="nofollow">https://github.com/scikit-learn/sci... | 1 | 2016-10-14T01:49:55Z | [
"python",
"scikit-learn"
] |
Edit scikit-learn decisionTree | 40,033,222 | <p>I would like to edit sklearn decisionTree,
e.g. change conditions or cut node/leaf etc.</p>
<p>But there seems to be no functions to do that, if I could export to a file, edit it to import.</p>
<p>How can I edit decisionTree?</p>
<p>Environment:</p>
<ul>
<li>Windows10</li>
<li>python3.3</li>
<li>sklearn 0.17.1<... | 0 | 2016-10-14T00:43:54Z | 40,033,721 | <p>If you are thinking of editing a model, I don't think there's an easy way of doing this. There's been discussions on exporting (rather visualising) the rule set<a href="http://stackoverflow.com/questions/20224526/how-to-extract-the-decision-rules-from-scikit-learn-decision-tree"> [1]</a>,<a href="http://stackoverflo... | 1 | 2016-10-14T01:54:04Z | [
"python",
"scikit-learn"
] |
How to use optional positional arguments with nargs='*' arguments in argparse? | 40,033,261 | <p>As shown in the following code, I want to have an optional positional argument <code>files</code>, I want to specify a default value for it, when paths are passed in, use specified path.</p>
<p>But because <code>--bar</code> can have multiple arguments, the path passed in didn't go into <code>args.files</code>, how... | 0 | 2016-10-14T00:50:45Z | 40,033,371 | <p>Your argument spec is inherently ambiguous (since <code>--bar</code> can take infinite arguments, there is no good way to tell when it ends, particularly since <code>files</code> is optional), so it requires user disambiguation. Specifically, <code>argparse</code> can be told "this is the end of the switches section... | 1 | 2016-10-14T01:04:47Z | [
"python",
"parsing",
"argparse",
"optparse",
"optional-arguments"
] |
csv write doesn't work correctly | 40,033,353 | <p>Any idea why is this always writing the same line in output csv?</p>
<pre><code> 21 files = glob.glob(path)
22 csv_file_complete = open("graph_complete_reddit.csv", "wb")
23 stat_csv_file = open("test_stat.csv", "r")
24 csv_reader = csv.reader(stat_csv_file)
25 lemmatizer = WordNetLemmatizer()
26 for file1, fi... | 0 | 2016-10-14T01:03:02Z | 40,033,461 | <p>You're never rewinding <code>stat_csv_file</code>, so eventually, your loop over <code>csv_reader</code> (which is a wrapper around <code>stat_csv_file</code>) isn't looping at all, and you write whatever you found on the last loop. Basically, the logic is:</p>
<ol>
<li>On first loop, look through all of <code>csv_... | 1 | 2016-10-14T01:18:11Z | [
"python",
"file",
"csv",
"itertools"
] |
Labeling y-axis with multiple x-axis' | 40,033,370 | <p>I've set up a plot with 3 x-axis' on different scales, however when i attempt to use a Y-label i get the error: </p>
<p>AttributeError: 'function' object has no attribute 'ylabel'</p>
<p>I've tried a number of options, however I am not sure why this error appears.</p>
<p>My code:</p>
<pre><code>fig, ax = plt.sub... | 0 | 2016-10-14T01:04:43Z | 40,033,415 | <p>you are typing ax.set.ylabel, you should be doing ax.set_ylabel</p>
| 0 | 2016-10-14T01:11:07Z | [
"python",
"multiple-axes"
] |
Finding the Min and Max of User Inputs | 40,033,454 | <p>I'm learning Python, and in trying to find out the min and max values of user number inputs, I can't seem to figure it out.</p>
<pre><code>count = 0
x = []
while(True):
x = input('Enter a Number: ')
high = max(x)
low = min(x)
if(x.isdigit()):
count += 1
else:
print("Your Highest ... | 0 | 2016-10-14T01:16:54Z | 40,033,544 | <p>break your program into small manageable chunks start with just a simple function to get the number</p>
<pre><code>def input_number(prompt="Enter A Number:"):
while True:
try: return int(input(prompt))
except ValueError:
if not input: return None #user is done
else: p... | 1 | 2016-10-14T01:30:37Z | [
"python",
"python-3.x"
] |
Finding the Min and Max of User Inputs | 40,033,454 | <p>I'm learning Python, and in trying to find out the min and max values of user number inputs, I can't seem to figure it out.</p>
<pre><code>count = 0
x = []
while(True):
x = input('Enter a Number: ')
high = max(x)
low = min(x)
if(x.isdigit()):
count += 1
else:
print("Your Highest ... | 0 | 2016-10-14T01:16:54Z | 40,033,555 | <pre><code>inp=input("enter values seperated by space")
x=[int(x) for x in inp.split(" ")]
print (min(x))
print (max(x))
</code></pre>
<p>output:</p>
<pre><code>Python 3.5.2 (default, Dec 2015, 13:05:11)
[GCC 4.8.2] on linux
enter values seperated by space 20 1 55 90 44
1
90
</code></pre>
| 1 | 2016-10-14T01:31:56Z | [
"python",
"python-3.x"
] |
Finding the Min and Max of User Inputs | 40,033,454 | <p>I'm learning Python, and in trying to find out the min and max values of user number inputs, I can't seem to figure it out.</p>
<pre><code>count = 0
x = []
while(True):
x = input('Enter a Number: ')
high = max(x)
low = min(x)
if(x.isdigit()):
count += 1
else:
print("Your Highest ... | 0 | 2016-10-14T01:16:54Z | 40,033,816 | <p><code>x</code> is a list, and to append an item to a list, you must call the <code>append</code> method on the list, rather than directly assigning an item to the list, which would override the list with that item.</p>
<p>Code:</p>
<pre><code>count = 0
x = []
while(True):
num = input('Enter a Number: ')
if... | 0 | 2016-10-14T02:10:36Z | [
"python",
"python-3.x"
] |
Import os doesn't not work in linux | 40,033,460 | <p>I just want to install the <a href="https://pypi.python.org/pypi/suds" rel="nofollow">suds library</a>, but suddenly it wasn't proceeding because it was not finding the <code>os</code> library, so I tried to open my python and it results me an error. When I import the <code>os</code> library and there are some error... | 1 | 2016-10-14T01:18:03Z | 40,033,983 | <p>You need to <a href="https://www.python.org/downloads/" rel="nofollow">install a more recent version of Python - version 2.7.12 or later</a>. <a href="http://www.snarky.ca/stop-using-python-2-6" rel="nofollow">All versions of Python 2.6 have been end-of-lifed and any use of Python 2.6 is actively discouraged</a>.</p... | 0 | 2016-10-14T02:28:47Z | [
"python",
"linux",
"operating-system",
"suds"
] |
Getting SettingWithCopyWarning warning even after using .loc in pandas | 40,033,471 | <pre><code>df_masked.loc[:, col] = df_masked.groupby([df_masked.index.month, df_masked.index.day])[col].\
transform(lambda y: y.fillna(y.median()))
</code></pre>
<p>Even after using a .loc, I get the foll. error, how do I fix it? </p>
<pre><code>Anaconda\lib\site-packages\pandas\core\indexing.py:476: Sett... | 2 | 2016-10-14T01:19:23Z | 40,033,661 | <p>You could get this UserWarning if <code>df_masked</code> is a sub-DataFrame of some other DataFrame.
In particular, if data had been <em>copied</em> from the original DataFrame to <code>df_masked</code> then, Pandas emits the UserWarning to alert you that modifying <code>df_masked</code> will not affect the original... | 1 | 2016-10-14T01:44:17Z | [
"python",
"pandas"
] |
gdb python on mac: error of "/usr/local/bin/python": not in executable format | 40,033,536 | <p>I have the latest gdb installed on mac</p>
<pre><code> qiwu$ brew install gdb
Warning: gdb-7.12 already installed
</code></pre>
<p>Then I am trying to attach to a python3.5 process</p>
<pre><code>qiwu$ gdb python 4411
GNU gdb (GDB) 7.12
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL ve... | 0 | 2016-10-14T01:29:45Z | 40,033,928 | <p>Could be because unix systems recognize <code>#!/usr/local/bin/python</code> not <code>/usr/local/bin/python</code></p>
| 0 | 2016-10-14T02:23:43Z | [
"python",
"osx",
"gdb"
] |
Tree view row activated with ONE click | 40,033,539 | <p>I am creating a graphical interface with glade that contents a treeview. </p>
<p>I want to have a button that is initially enabled by doing a simple click on a row of the treeview. </p>
<p>I am using <code>row-activated</code>, but when I activate a row for the first time I have to double click the row.</p>
<p>Wh... | 0 | 2016-10-14T01:30:13Z | 40,046,133 | <p>GtkTreeView as an <code>activate-on-single-click</code> property.</p>
<p><a href="https://developer.gnome.org/gtk3/stable/GtkTreeView.html#GtkTreeView--activate-on-single-click" rel="nofollow">https://developer.gnome.org/gtk3/stable/GtkTreeView.html#GtkTreeView--activate-on-single-click</a></p>
| 0 | 2016-10-14T14:52:35Z | [
"python",
"signals",
"glade"
] |
Returning multiple values in a view using Flask (Python) | 40,033,595 | <p>I'm struggling to even understand this in my head from a broad point of view, but I'll try explain as best as I can, if anything isn't clear please comment asking for more information.</p>
<p>Right now I have a python function that fetches a users name and their user ID from an internal API in my workplace that is ... | 0 | 2016-10-14T01:36:39Z | 40,033,822 | <p>If user enters <code>John Doe, Harry Smith, Alex Boggs</code> in text box then you should get <code>John Doe, Harry Smith, Alex Boggs</code> in Flask and you have to split it <code>"John Doe, Harry Smith, Alex Boggs".split(", ")</code> to get list of names. </p>
<p>Now you can use <code>for</code> loop to print Use... | 1 | 2016-10-14T02:11:28Z | [
"python",
"flask",
"views"
] |
Returning multiple values in a view using Flask (Python) | 40,033,595 | <p>I'm struggling to even understand this in my head from a broad point of view, but I'll try explain as best as I can, if anything isn't clear please comment asking for more information.</p>
<p>Right now I have a python function that fetches a users name and their user ID from an internal API in my workplace that is ... | 0 | 2016-10-14T01:36:39Z | 40,034,072 | <p>Use "path" converter like this <code>@app.route('/something/<path:name_list>')</code>
So when user request the URL: <code>site/something/name1/name2/name3</code>
you will get a name list</p>
<p>Or you can create your own converter by create a converter class.</p>
<pre><code>from werkzeug.routing import BaseC... | 0 | 2016-10-14T02:39:15Z | [
"python",
"flask",
"views"
] |
Error in expected output: Loop is not correctly working | 40,033,670 | <p>I am still struggling to link the second 'for' variable in this together. The first 'for' loop works correctly, but the second half is stuck on a single variable, which is not allowing it to function correctly in a later repeatable loop. How might I write this better, so that the functions of the text are global, so... | 0 | 2016-10-14T01:46:13Z | 40,033,743 | <p>I think you need to specify global inside the <code>servy</code> function and not outside, but even better would be to pass inez as a parameter to <code>servx</code>:</p>
<pre><code>def servy():
global inez
fh.seek(0); #veryyyyy important
qust = input('Find another Enzyme? [Yes/No]: ')
qust = qust.... | 0 | 2016-10-14T01:56:57Z | [
"python"
] |
Django REST Custom View Parameters in Viewset with CoreAPI | 40,033,671 | <p>If I define a django-rest-framework view framework as:</p>
<pre><code>class ProblemViewSet(viewsets.ModelViewSet):
queryset = Problem.objects.all()
serializer_class = ProblemSerializer
@detail_route(methods=['post'], permission_classes=(permissions.IsAuthenticated,))
def submit(self, request, *args... | 0 | 2016-10-14T01:46:19Z | 40,033,984 | <p>I don't understand your question, but I think that you want to add in the input the filed <code>answer</code> to django-rest form or raw, you can do this adding in the serializer <code>ProblemSerializer</code> the next:</p>
<pre><code>from rest_framework import serializers
...
class CustomerSerializer(serializers.M... | 0 | 2016-10-14T02:28:51Z | [
"python",
"django",
"rest",
"django-rest-framework"
] |
python 2.7 word generator | 40,033,724 | <p>Algorithm: take input on how many letters to go back, for loop to loop a-z, lock the first character, loop the second character, lock the first two, loop the third, and so on and so forth. The out put will look like a, b, c, d... aa, ab, ac, ad... aaa, aab, aac... and so on. I am very new to python. I have something... | 0 | 2016-10-14T01:54:30Z | 40,034,053 | <pre><code>alphabet = 'abcdefghijklmnopqrstuvwxyz'
l= ['']
for i in range(input):
l = [letter + item for letter in alphabet for item in l]
for item in l:
print(item)
</code></pre>
<p>I think this is what you're looking for</p>
| 0 | 2016-10-14T02:37:24Z | [
"python",
"python-2.7"
] |
python 2.7 word generator | 40,033,724 | <p>Algorithm: take input on how many letters to go back, for loop to loop a-z, lock the first character, loop the second character, lock the first two, loop the third, and so on and so forth. The out put will look like a, b, c, d... aa, ab, ac, ad... aaa, aab, aac... and so on. I am very new to python. I have something... | 0 | 2016-10-14T01:54:30Z | 40,034,419 | <p>To avoid huge RAM requirements, use <a href="https://docs.python.org/2/library/itertools.html#itertools.combinations" rel="nofollow"><code>itertools.combinations</code></a> to generate a single output at a time, handling the "locking" for you:</p>
<pre><code>from future_builtins import map # Not needed on Py3, onl... | 0 | 2016-10-14T03:21:57Z | [
"python",
"python-2.7"
] |
In numpy, why multi dimension array d[0][0:2][0][0] returning not two elements | 40,033,734 | <pre><code>In [136]: d = np.ones((1,2,3,4))
In [167]: d[0][0][0:2][0]
Out[167]: array([ 1., 1., 1., 1.])
</code></pre>
<p>as shown above, why it's not returning exactly 2 elements</p>
| 0 | 2016-10-14T01:55:57Z | 40,033,797 | <p>Look at the array itself. It should be self explanatory</p>
<pre><code>>>> d
array([[[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]],
[[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.],
[ 1., 1., 1., 1.]]]])
# first you grab the first and only ele... | 0 | 2016-10-14T02:06:31Z | [
"python",
"arrays",
"numpy"
] |
Installing package using pip command | 40,033,891 | <p>I am trying to install basemap using the pip command. My command is here ( I am using anaconda):</p>
<pre><code>pip install "C:\Users\hh\Downloads\basemap-1.0.8-cp35-none-win32.whl"
</code></pre>
<p>The error message I get is: </p>
<pre><code>basemap-1.0.8-cp35-none-win32.whl is not a supported wheel on this plat... | 0 | 2016-10-14T02:20:03Z | 40,034,344 | <p>If you are using a 64-bit version of Windows you should download the 64bit version package (basemap-1.0.8-cp35-none-win_amd64.whl)</p>
| 1 | 2016-10-14T03:13:06Z | [
"python"
] |
Arrow animation in Python | 40,033,948 | <p>First of all, I am just starting to learn Python. I have been struggling during the last hours trying to update the arrow properties in order to change them during a plot animation.</p>
<p>After thoroughly looking for an answer, I have checked that it is possible to change a circle patch center by modifying the att... | 4 | 2016-10-14T02:25:45Z | 40,034,280 | <p>I found this by mimicking the code in <a href="https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/patches.py#L1125" rel="nofollow"><code>patches.Arrow.__init__</code></a>:</p>
<pre><code>import numpy as np
import matplotlib.patches as patches
from matplotlib import pyplot as plt
from matplotlib imp... | 1 | 2016-10-14T03:06:01Z | [
"python",
"animation",
"matplotlib",
"arrow"
] |
Arrow animation in Python | 40,033,948 | <p>First of all, I am just starting to learn Python. I have been struggling during the last hours trying to update the arrow properties in order to change them during a plot animation.</p>
<p>After thoroughly looking for an answer, I have checked that it is possible to change a circle patch center by modifying the att... | 4 | 2016-10-14T02:25:45Z | 40,034,308 | <p>Add <code>ax.clear()</code> before <code>ax.add_patch(patch)</code> but will remove all elements from plot.</p>
<pre><code>def animate(t):
ax.clear()
patch = plt.Arrow(x[t], y[t], dx[t], dy[t] )
ax.add_patch(patch)
return patch,
</code></pre>
<hr>
<p><strong>EDIT:</strong> removing one patch</... | 2 | 2016-10-14T03:08:27Z | [
"python",
"animation",
"matplotlib",
"arrow"
] |
D&D dice roll python | 40,033,971 | <p>Trying to roll dice like in dungeons and dragon but display each roll. I dont quite know what im doing wrong and appreciate all the help.</p>
<pre><code>from random import randint
def d(y): #basic die roll
return randint(1, y)
def die(x, y): #multiple die roll 2d20 could roll 13 and 7 being 20
for [x*d(y)]... | 0 | 2016-10-14T02:27:28Z | 40,034,181 | <p>You can't just multiple the result of a single call to <code>d()</code>, you need to make <code>n</code> different calls to the <code>d()</code>:</p>
<pre><code>from random import randint
def d(sides):
return randint(1, sides)
def roll(n, sides):
return tuple(d(sides) for _ in range(n))
dice = roll(3, 20... | 1 | 2016-10-14T02:55:08Z | [
"python",
"python-3.x",
"dice"
] |
python and ipython seem to treat unicode characters differently | 40,033,979 | <p>I'm running python 2.7.12 from anaconda on windows 10. Included in the distro is ipython 5.1.0. I wrote a program to print certain columns of queried rows in a mysql database. The columns contain strings in unicode. When the program is run in python, an exception is thrown when a unicode character in one of the stri... | 0 | 2016-10-14T02:28:31Z | 40,034,136 | <p>Looks like ipython is using a sane default output encoding (probably UTF-8 or UTF-16), while plain Python is using <code>cp437</code>, a limited one-byte-per-character ASCII superset that can't represent the whole Unicode range.</p>
<p>If you can control the command prompt, you can run <code>chcp 65001</code> befor... | 0 | 2016-10-14T02:47:47Z | [
"python",
"unicode",
"ipython",
"anaconda"
] |
Confusion on async file upload in python | 40,034,010 | <p>So I want to implement async file upload for a website. It uses python and javascript for frontend. After googling, there are a few great posts on them. However, the posts use different methods and I don't understand which one is the right one.</p>
<p>Method 1:
Use ajax post to the backend. </p>
<p>Comment: d... | 0 | 2016-10-14T02:33:12Z | 40,034,220 | <p>Asynchronous behavior applies to either side independently. Either side can take advantage of the capability to take care of several tasks as they become ready rather than blocking on a single task and doing nothing in the meantime. For example, servers do things asynchronously (or at least they should) while client... | 1 | 2016-10-14T02:58:52Z | [
"python",
"ajax",
"asynchronous"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.