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
Indent On New Lines In Console
39,758,895
<p>I have a large block of text. It has line breaks in it, but since the lines are still to long even with the line-breaks, it wraps to the next line. Since all of the other script functions have all lines indented one space, I would like this to match it. I understand that if I print just one line, I can just insert a...
0
2016-09-28T22:58:23Z
39,761,017
<p>Is this what you are looking for?</p> <pre><code>import textwrap from string import join, split text = """This is a block of text. It keeps going on and on and on. It has some line breaks \n but mostly just keeps going on without breaks. The lines are sometimes too long, ...
0
2016-09-29T03:40:02Z
[ "python", "console", "auto-indent" ]
Indent On New Lines In Console
39,758,895
<p>I have a large block of text. It has line breaks in it, but since the lines are still to long even with the line-breaks, it wraps to the next line. Since all of the other script functions have all lines indented one space, I would like this to match it. I understand that if I print just one line, I can just insert a...
0
2016-09-28T22:58:23Z
39,775,911
<p>You said that join, split are failing to import. Try the following:</p> <pre><code>import re, textwrap def myformatting(t): t=re.sub('\s+',' ',t); t=re.sub('^\s+','',t); t=re.sub('\s+$','',t) t=textwrap.wrap(t,width=40,initial_indent=' '*4,subsequent_indent=' '*8) s="" for i in (t): s=s+i+"\n" ...
0
2016-09-29T16:50:15Z
[ "python", "console", "auto-indent" ]
Realizing different column formats with numpy.savetxt
39,758,941
<p>I want to create a <code>.csv</code> file using <code>numpy.savetxt</code>. Each <code>row</code> of the file indicates a certain event. Every row has multiple <code>columns</code> indicating different elements of the event. The information stored in each <code>column</code> is different. Certain <code>columns</code...
0
2016-09-28T23:03:56Z
39,759,564
<p>You aren't even getting to the <code>savetxt</code> step.</p> <pre><code>save_values[idx, :] = column_0, column_1 </code></pre> <p>the target is 2 values (2 columns). The source is <code>idx</code> and a list.</p> <p>That's why it's giving you the 'setting with a sequence' error. It can't put the list in <code>...
0
2016-09-29T00:28:19Z
[ "python", "csv", "numpy", "save" ]
Python - How can I pass multiple arguments using Pool map
39,759,046
<p>This is a sniplet of my code:</p> <pre><code>data = [currentAccount.login,currentAccount.password,campaign.titlesFile,campaign.licLocFile,campaign.subCity,campaign.bodiesMainFile,campaign.bodiesKeywordsFile,campaign.bodiesIntroFile] results = multiprocessing.Pool(5).map(partial(self.postAd,data),range(3)) ... def p...
0
2016-09-28T23:16:37Z
39,759,667
<p>Your first attempt is a misuse of <code>partial</code>. <code>data</code> is a single argument: it being a list doesn't automatically unpack its contents. <code>partial</code> simply takes variable arguments and so you should pass those arguments 'normally', either </p> <pre><code>partial(self.postAd, currentAccoun...
0
2016-09-29T00:43:18Z
[ "python", "multiprocessing" ]
I cant move up and down with my code
39,759,049
<p>Here is the code I used to use a rectangle move for a game. But every time I press the up and down keys, it goes left and right. If you can paste the correct version in your answer. Thanks!!!! </p> <p>p.s the # is a comment</p> <pre><code>#to start pygame import pygame pygame.init() #game window gameWindow = ...
0
2016-09-28T23:16:47Z
39,759,062
<p>The following: </p> <pre><code>def move(self, xdir, ydir): self.rect.x += xdir*self.speed self.rect.x += ydir*self.speed </code></pre> <p>Should be changed to:</p> <pre><code>def move(self, xdir, ydir): self.rect.x += xdir*self.speed self.rect.y += ydir*self.speed </code></pre> <p>You were always...
1
2016-09-28T23:18:21Z
[ "python", "pygame" ]
Python PUT Request to Confluence Webpage - ValueError: No JSON object could be decoded, but <Response [200]>
39,759,155
<p>I'm trying to update some data on a confluence webpage. Everything works fine in Postman (the data is updated). However, when I use python and the requests module I'm getting the following error:</p> <blockquote> <p>ValueError: No JSON object could be decoded</p> </blockquote> <p>The strangest thing is I'm getti...
0
2016-09-28T23:32:09Z
39,759,463
<p>This is happening because the API you're posting to doesn't respond with JSON, so when you call <code>r.json()</code> requests tries to parse the body of the response as JSON and fails. You're seeing a 200 because you were able to send the data to the server correctly, you're just trying to read the response wrong.<...
0
2016-09-29T00:14:05Z
[ "python", "python-requests", "put", "confluence" ]
How to save value returned from python function if call does not capture return
39,759,188
<p>Let's say I have a python function, where <code>x</code> and <code>y</code> are relatively large objects (lists, NumPy matrices, etc.):</p> <pre><code>def myfun(x): y=some complicated function of x return y </code></pre> <p>If in an interactive session the user calls this as: </p> <pre><code>myfun(5) </code><...
0
2016-09-28T23:35:11Z
39,759,197
<p><code>y=_</code></p> <p>assuming you are in the interactive python console. <code>_</code> is magic that holds the last "result"</p>
4
2016-09-28T23:36:16Z
[ "python" ]
Showing characters instead of integers in arcs in OpenFST(PyFST)
39,759,240
<p>I'm using the method <code>linear_chain</code> to accept a <code>String</code>. When I convert it into a <code>fst binary</code> to then into a <code>DOT</code> format, I get integers instead of the characters. Also, I have a SymbolTable for each of the corresponding letters being read.</p> <p>What I need is to sho...
3
2016-09-28T23:42:51Z
39,793,772
<p>To do this on the command line, make sure you provide both an input and output symbol table. The command should be something like</p> <pre><code>fstdraw --isymbols=input_syms.txt --osymbols=output_syms.txt fst.bin </code></pre> <p>I haven't used "PyFST", but I would suggest you use the Python bindings that are in...
0
2016-09-30T14:23:03Z
[ "python", "openfst" ]
Ascii stream with missing bits (no parity)
39,759,265
<p>I've been given a task to look for 0's and 1's in a real textbook in order to decipher an ASCII message from it. The problem is that it's really hard to find all 0's and 1's and I have the feeling I am skipping a lot of them. This completely messes up the ASCII conversion. Some of the things I tried:</p> <ul> <li>'...
2
2016-09-28T23:47:26Z
39,759,298
<pre><code>all_ones_and_zeros = re.findall("[01]",corpus_of_text) BITS_PER_ASCII = 8 #(ascii characters are all the ordinals from 0-255 ... or 8 bits) asciis = zip([iter(all_ones_and_zeros)]*BITS_PER_ASCII) bins = [''.join(x) for x in asciis] chars = [chr(int(y,2)) for y in bins] print "MSG:",chars </code></pre> <p>I...
0
2016-09-28T23:52:32Z
[ "python", "ascii", "parity" ]
User form has fields with unwanted initial value, Django
39,759,273
<p>I'm trying to create a view to allow a User to create another User. The problem is that the generated form has initial values for the 'password' and 'last_name' fields, and I don't know why. I need to remove those initial values.</p> <p>I have created a UserForm with ModelForm.</p> <pre><code>class UserForm(forms....
0
2016-09-28T23:48:23Z
39,761,484
<p>It's because while testing,You might have used browser feature of saving the field and form data i.e. autosave the password.It generally saves the password and just previous field of the form.Please clear your cache and form autofill data from browser settings. Let us know if the error still exists. Thanks</p>
0
2016-09-29T04:34:43Z
[ "python", "django", "django-forms", "user" ]
Trying to plot a random series on a chart with matplotlib, but the chart will not display when the programe is ran.
39,759,301
<p>The following code will run with no errors, but the chart that I am trying to display will not pop up. I see the screen blink when I run the program like the chart is going to load but that is it, just a quick flash of the screen. Then my command line reads "press any key to continue" which is normal when my program...
0
2016-09-28T23:52:44Z
39,760,572
<p>It's not clear if you're doing this in a script, interactive python session or ipython. In the first case you need to call <code>plt.show()</code> at the end to show any figures. That's what you can do in a regular interactive python session as well. In ipython you're better off using <code>%matplotlib inline</code>...
0
2016-09-29T02:45:40Z
[ "python", "pandas", "matplotlib", "dataframe", "charts" ]
Trying to plot a random series on a chart with matplotlib, but the chart will not display when the programe is ran.
39,759,301
<p>The following code will run with no errors, but the chart that I am trying to display will not pop up. I see the screen blink when I run the program like the chart is going to load but that is it, just a quick flash of the screen. Then my command line reads "press any key to continue" which is normal when my program...
0
2016-09-28T23:52:44Z
39,776,860
<p>You can add this line at the top of your code:</p> <pre><code>% matplotlib inline </code></pre> <p>Here is a good example using your data:</p> <p><a href="http://i.stack.imgur.com/neD0y.png" rel="nofollow"><img src="http://i.stack.imgur.com/neD0y.png" alt="enter image description here"></a></p>
0
2016-09-29T17:47:55Z
[ "python", "pandas", "matplotlib", "dataframe", "charts" ]
Script Error from "Simple Digit Recognition OCR in OpenCV-Python"
39,759,312
<p>I have update the Script but one Error i can not fix. Here my script Version:</p> <pre><code>import sys import numpy as np import cv2 im = cv2.imread('test001.png') res = cv2.resize(im,None,fx=2, fy=2, interpolation = cv2.INTER_CUBIC) im3 = res.copy() gray = cv2.cvtColor(res,cv2.COLOR_BGR2GRAY) blur = cv2.Gaussia...
0
2016-09-28T23:53:48Z
39,778,702
<p>this Error was Homemade:</p> <pre><code>sample = roismall.reshape((1,100)) </code></pre> <p>is corresponding to this line:</p> <pre><code>roismall = cv2.resize(roi,(30,30)) </code></pre> <p>The 30 x 30 = 900 is the right Value or 10,10 = 100. I change it back to:</p> <pre><code>roismall = cv2.resize(roi,(10,10)...
0
2016-09-29T19:42:02Z
[ "python", "opencv", "ocr" ]
Why does this keep on giving me a list index out of range error?
39,759,336
<pre><code>count = 0 badIndices = [59,64,68,72,74,77,79,103,104,108,109,118,119,123,124,130,133,139] test1 = [] csvCourses = [] csvExamTime = [] examTime = [] with open("final_exam_schedule.csv") as file: reader = csv.reader(file, delimiter = ",") next(reader) for row in reader: csvCourses.append(r...
0
2016-09-28T23:56:36Z
39,759,379
<p>It's tough to say without knowing what your data looks like, but here's what I think,</p> <p>Your <code>count</code> variable is being incremented too early. In python list indexes start at <code>0</code> and go to <code>len(list)-1</code> as the last index. You're kind of starting at <code>count=1</code> so it's p...
0
2016-09-29T00:02:00Z
[ "python" ]
Can't open the desktop app created with pyinstaller
39,759,342
<p>I created a pyinstaller file from a .py file. In this file, I´ve got files with the .ui extensions created using PyQt4. So, when I try to execute the file created, it shows this error:</p> <pre><code>File "C:\Users\Flosh\Desktop\dist\ProgramNew\New.exe", line 1 SyntaxError: Non-ASCII character '\x90' in file C:\Us...
0
2016-09-28T23:57:49Z
40,062,240
<p>This is a Python traceback, but the first line is showing an <em>exe file</em>:</p> <pre><code>File "C:\Users\Flosh\Desktop\dist\ProgramNew\New.exe", line 1 </code></pre> <p>which suggests you must be trying to run the application like this:</p> <pre><code>python C:\Users\Flosh\Desktop\dist\ProgramNew\New.exe </c...
1
2016-10-15T17:41:11Z
[ "python", "pyqt4", "pyinstaller" ]
Can't open the desktop app created with pyinstaller
39,759,342
<p>I created a pyinstaller file from a .py file. In this file, I´ve got files with the .ui extensions created using PyQt4. So, when I try to execute the file created, it shows this error:</p> <pre><code>File "C:\Users\Flosh\Desktop\dist\ProgramNew\New.exe", line 1 SyntaxError: Non-ASCII character '\x90' in file C:\Us...
0
2016-09-28T23:57:49Z
40,081,006
<p>You can try cxfreeze for creating the installer or executable package. Description of creating the setup file is given here <a href="https://cx-freeze.readthedocs.io/en/latest/distutils.html" rel="nofollow">https://cx-freeze.readthedocs.io/en/latest/distutils.html</a>. May be this could help you.</p>
0
2016-10-17T07:48:01Z
[ "python", "pyqt4", "pyinstaller" ]
Set list to a certain length and range
39,759,493
<p>This is my problem.. </p> <p>write a function that takes, as an argument, a list named aList. It returns a Boolean value True if the elements in the list contains at least one integer and no more than six integers whose values range between 1 and 6. It returns the Boolean False if the list contains any other elemen...
-1
2016-09-29T00:19:05Z
39,759,516
<p>Use <code>set(aList) &lt;= set(range(1, 6))</code>.</p>
2
2016-09-29T00:21:08Z
[ "python", "list", "boolean", "range" ]
Python Pandas datetime64[ns] comparision
39,759,496
<p>I'm trying to use indexing to select rows in my dataframe after the date 2011-01-01. I used following line of code to return only part of dataframe that is after 2011-01-01 </p> <pre><code> df = df[df.Date &gt; np.datetime64('2011-01-01 00:00:00')] </code></pre> <p>I don't get an error. However, I only see dates ...
0
2016-09-29T00:19:18Z
39,760,475
<p>After importing your data, it looks like all the values of the <code>Date</code> column are still there, even after filtering. It's just that your data is too large to be displayed fully on your console (take a look at <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.set_option.html" rel="nofoll...
0
2016-09-29T02:35:31Z
[ "python", "datetime", "pandas" ]
How to document multiple return values using reStructuredText in Python 2?
39,759,503
<p>The <a href="https://docs.python.org/devguide/documenting.html" rel="nofollow">Python docs</a> say that "the markup used for the Python documentation is <a href="http://docutils.sf.net/rst.html" rel="nofollow">reStructuredText</a>". My question is: How is a block comment supposed to be written to show multiple retur...
0
2016-09-29T00:19:51Z
39,761,518
<p>As wwi mentioned in the comments, the detailed format to be used is not strictly defined. </p> <p>For myself, I usually use the <a href="http://docutils.sourceforge.net/docs/ref/rst/restructuredtext.html#field-lists" rel="nofollow">Field List</a> notation style you use above. It supports line breaks, so just break...
0
2016-09-29T04:38:15Z
[ "python", "python-2.7", "documentation", "restructuredtext" ]
PyQt - QDialogButtonBox signals and tool tip
39,759,600
<p>I got a couple of questions regarding qDialogButtonBox. While my code still works, I believed that there are a few parts that can be better refined/ I am not finding much info online</p> <pre><code>class testDialog(QtGui.QDialog): def __init_(self, parent=None): ... self.init_ui() self.s...
0
2016-09-29T00:33:56Z
39,776,290
<ol> <li><p>Yes, that is the correct way to write signal connections (the other syntax you found is indeed the old way of doing it). You can find all the signals in the pyqt documentation for <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qdialogbuttonbox.html" rel="nofollow"><code>QDialogButtonBox</code></a>. Diffe...
1
2016-09-29T17:12:59Z
[ "python", "pyqt" ]
Why can't my Python program find the jq module?
39,759,649
<p>I try to use the Python jq module:</p> <pre><code>#!/usr/bin/python3 # Python 3.4 #-------------------------- import datetime import sys import urllib.request import urllib.error import time from jq import jq </code></pre> <p>When I run it on the command line:</p> <pre><code># ./daemon.py </code></pre> <p>it sa...
0
2016-09-29T00:39:37Z
39,759,669
<p><code>pip search</code> searches through <em>available</em> packages. To list <em>installed</em> packages, use <code>pip list</code>.</p> <p>Try installing the <code>jq</code> module with <code>pip install jq</code>.</p>
1
2016-09-29T00:43:23Z
[ "python", "python-3.4", "jq" ]
Canvas Update Tkinter Python
39,759,677
<p>I wrote a method to create a canvas</p> <p>But I see that Canvas is not updated and the Gui elements are not updated</p> <p>Please guide here as i want to implement the New Game functionality</p>
-2
2016-09-29T00:44:03Z
39,776,483
<p>Removing all references to a Tkinter widget (like a <code>Canvas</code>) doesn't necessarily delete that object (or its child widgets) from a Tkinter application. You can test this with a small script:</p> <pre><code>import tkinter as tk root = tk.Tk() def f(): tk.Label(root, text='hi').pack() f() </code></pre...
1
2016-09-29T17:25:10Z
[ "python", "tkinter" ]
Does pytest 3.x have anything significant over 2.x?
39,759,679
<p>I've learned that Python Anaconda's <code>conda</code> program is much better than <code>pip</code> at managing packages and environments --- it even has dependency conflict management, which <code>pip</code> does not have.</p> <p>The problem is that <code>conda</code> uses the Continuum repository instead of PyPI,...
1
2016-09-29T00:44:15Z
39,760,093
<p>Although I've had good experience with <code>conda</code> in the past, I would suggest taking a look at <a href="https://github.com/yyuu/pyenv" rel="nofollow">pyenv</a>.</p> <p><code>pyenv</code> is written purely in bash and allows you to easily handle the installation and management of different python interprete...
0
2016-09-29T01:45:05Z
[ "python", "anaconda", "py.test", "pypi", "conda" ]
manually building installing python packages in linux so they are recognized
39,759,680
<p>My system is SLES 11.4 having python 2.6.9. I know little about python and have not found where to download rpm's that give me needed python packages.<br> I acquired numpy 1.4 and 1.11 and I believe did a successful <code>python setup.py build</code> followed by <code>python setup.py install</code> on numpy. Going f...
0
2016-09-29T00:44:17Z
39,759,893
<p>If you're using linux, make sure your <code>$PYTHONPATH</code> environment variable is set properly.</p> <p>To do this type the following in the terminal:</p> <pre><code>echo $PYTHONPATH </code></pre> <p>If you can't find it you can manually set the variable with the locations of the modules you want to find in y...
0
2016-09-29T01:18:30Z
[ "python" ]
manually building installing python packages in linux so they are recognized
39,759,680
<p>My system is SLES 11.4 having python 2.6.9. I know little about python and have not found where to download rpm's that give me needed python packages.<br> I acquired numpy 1.4 and 1.11 and I believe did a successful <code>python setup.py build</code> followed by <code>python setup.py install</code> on numpy. Going f...
0
2016-09-29T00:44:17Z
39,778,818
<p>think i figured it out. Apparently SLES 11.4 does not include the development headers in the default install from their SDK for numpy 1.8. And of course they don't offer matplotlib along with a bunch of common python packages.</p> <p>The python packages per the SLES SDK are the system default are located under<cod...
0
2016-09-29T19:49:29Z
[ "python" ]
Calculating the Manhattan distance in the eight puzzle
39,759,721
<p>I am working on a program to solve the Eight Puzzle in Python using informed search w/ heuristics. The heuristic we are supposed to use is the Manhattan distance. So for a board like:</p> <pre><code> State Goal Different Goal 7 2 4 1 2 3 1 2 3 5 6 8 4 ...
2
2016-09-29T00:51:56Z
39,759,853
<p>Summing over each number's Manhatten distance:</p> <pre><code>&gt;&gt;&gt; board = [7, 2, 4, 5, 0, 6, 8, 3, 1] &gt;&gt;&gt; sum(abs((val-1)%3 - i%3) + abs((val-1)//3 - i//3) for i, val in enumerate(board) if val) 14 </code></pre> <p>For example, the 7 belongs at (zero-based) coordinate (0, 2) = (<code>(7-1...
1
2016-09-29T01:12:41Z
[ "python" ]
How can I get the average of a range of inputs?
39,759,815
<p>I have to create a program that shows the arithmetic mean of a list of variables. There are supposed to be 50 grades. </p> <p>I'm pretty much stuck. Right now I´ve only got:</p> <pre><code>for c in range (0,50): grade = ("What is the grade?") </code></pre> <p>Also, how could I print the count of grades that ...
0
2016-09-29T01:07:42Z
39,759,837
<p>If you don't mind using <code>numpy</code> this is ridiculously easy: </p> <pre><code>import numpy as np print np.mean(grades) </code></pre> <p>Or if you'd rather not import anything,</p> <pre><code>print float(sum(grades))/len(grades) </code></pre> <p>To get the number of grades below 50, assuming you have them...
2
2016-09-29T01:10:35Z
[ "python" ]
How can I get the average of a range of inputs?
39,759,815
<p>I have to create a program that shows the arithmetic mean of a list of variables. There are supposed to be 50 grades. </p> <p>I'm pretty much stuck. Right now I´ve only got:</p> <pre><code>for c in range (0,50): grade = ("What is the grade?") </code></pre> <p>Also, how could I print the count of grades that ...
0
2016-09-29T01:07:42Z
39,759,871
<p>Assuming you have a list with all the grades.</p> <pre><code>avg = sum(gradeList)/len(gradeList) </code></pre> <p>This is actually faster than numpy.mean(). </p> <p>To find the number of grades less than 50 you can put it in a loop with a conditional statement.</p> <pre><code>numPoorGrades = 0 for g in grades: ...
1
2016-09-29T01:15:44Z
[ "python" ]
How can I get the average of a range of inputs?
39,759,815
<p>I have to create a program that shows the arithmetic mean of a list of variables. There are supposed to be 50 grades. </p> <p>I'm pretty much stuck. Right now I´ve only got:</p> <pre><code>for c in range (0,50): grade = ("What is the grade?") </code></pre> <p>Also, how could I print the count of grades that ...
0
2016-09-29T01:07:42Z
39,759,877
<p>First of all, assuming <code>grades</code> is a list containing the grades, you would want to iterate over the <code>grades</code> list, and not iterate over <code>range(0,50)</code>.</p> <p>Second, in every iteration you can use a variable to count how many grades you have seen so far, and another variable that su...
0
2016-09-29T01:16:39Z
[ "python" ]
How can I get the average of a range of inputs?
39,759,815
<p>I have to create a program that shows the arithmetic mean of a list of variables. There are supposed to be 50 grades. </p> <p>I'm pretty much stuck. Right now I´ve only got:</p> <pre><code>for c in range (0,50): grade = ("What is the grade?") </code></pre> <p>Also, how could I print the count of grades that ...
0
2016-09-29T01:07:42Z
39,759,954
<p>Try the following. Function isNumber tries to convert the input, which is read as a string, to a float, which I believe convers the integer range too and is the floating-point type in Python 3, which is the version I'm using. The <code>try...except</code> block is similar in a way to the <code>try...catch</code> sta...
0
2016-09-29T01:25:05Z
[ "python" ]
Splitting a mixed number string from a dataframe column and converting it to a float
39,759,867
<p>I have a dataframe with a column of strings that are a mix of whole numbers and mixed fractions. I would like to convert column 'y' to floats. </p> <pre><code>x y z 0 4 Info 1 8 1/2 Info 2 3/4 Info 3 10 Info 4 4 Info 5 ...
1
2016-09-29T01:14:58Z
39,760,048
<p>You could try the <a href="https://docs.python.org/2/library/fractions.html" rel="nofollow">fractions</a> module. Here's a one-liner:</p> <pre><code>import fractions df['y_float'] = df['y'].apply(lambda frac: float(sum([fractions.Fraction(x) for x in frac.split()]))) </code></pre> <p>This gives:</p> <pre><code> ...
1
2016-09-29T01:38:35Z
[ "python", "pandas", "split", "fractions" ]
Spyder not throwing the type error: unsupported operand type(s) for +: 'NoneType' and 'str'
39,759,938
<p>Hi guys I was working in Spyder on python 3 and trying to get some input from the user so i accidentally wrote </p> <pre><code>g = input(print("Give the letter: ")) </code></pre> <p>while it should be</p> <pre><code>g = str(input("Give the letter: ")) </code></pre> <p>But Spyder IPython console ran it and did...
2
2016-09-29T01:23:45Z
39,760,014
<p>try this : </p> <pre><code>g = str(raw_input("Give the letter: ")) </code></pre>
0
2016-09-29T01:33:29Z
[ "python", "python-3.x" ]
Need help making a "compliment generator"
39,759,976
<p>I'm trying to make a simple compliment generator that takes a noun and an adjective from two separate list ands randomly combines them together. I can get one on its own to work but trying to get the second word to appear makes weird stuff happen. What am I doing wrong here? any input would be great.</p> <pre><code...
-5
2016-09-29T01:27:52Z
39,760,008
<p>You aren't incrementing <code>wordCount</code> in the second loop as you do <code>indexCount</code> in the first.</p>
0
2016-09-29T01:32:40Z
[ "python", "python-3.x" ]
python pandas groupby sorting and concatenating
39,760,063
<p>I have a panda data frame:</p> <pre><code>df = pd.DataFrame({'a': [1,1,1,1,2,2,2], 'b': ['a','a','a','a','b','b','b'], 'c': ['o','o','o','o','p','p','p'], 'd': [ [2,3,4], [1,3,3,4], [3,3,1,2], [4,1,2], [8,2,1], [0,9,1,2,3], [4,3,1] ], 'e': [13,12,5,10,3,2,5] }) </code></pre> <p>What I want is:</p> <p>First group ...
1
2016-09-29T01:40:28Z
39,760,656
<p>You can sort by column <code>e</code>, group by <code>a</code>, <code>b</code> and <code>c</code> and then use a list comprehension to concatenate the <code>d</code> column (flatten it). Notice that we can use <code>sort</code> and then <code>groupby</code> since groupby will </p> <blockquote> <p>preserve the ord...
1
2016-09-29T02:55:11Z
[ "python", "pandas", "dataframe", "group-by" ]
How to plot an specific function?
39,760,132
<p>I want to graph this function: f(x) =e^−x/10 sin(πx) I have tried with this code, but i don't get a coherent graph.</p> <pre><code>t=np.linspace(0,10) curve1 =np.exp(-t/10)*np.sin(t*np.pi) plt.plot(t,curve1) </code></pre>
1
2016-09-29T01:49:18Z
39,760,198
<p>You have to call <code>show()</code> after you call <code>plot()</code> to actually view your graph. The following is working code based off of your code: </p> <pre><code>from matplotlib.pyplot import plot, show t=np.linspace(0,10) curve1 =np.exp(-t/10)*np.sin(t*np.pi) plot(t,curve1) show() </code></pre> <p>Outpu...
1
2016-09-29T01:56:47Z
[ "python" ]
How to plot an specific function?
39,760,132
<p>I want to graph this function: f(x) =e^−x/10 sin(πx) I have tried with this code, but i don't get a coherent graph.</p> <pre><code>t=np.linspace(0,10) curve1 =np.exp(-t/10)*np.sin(t*np.pi) plt.plot(t,curve1) </code></pre>
1
2016-09-29T01:49:18Z
39,760,202
<p>What do you mean you don't get a coherent graph? This code works fine for me, maybe you need to use plt.show()?</p> <pre><code>t=np.linspace(0,10) curve1 =np.exp(-t/10)*np.sin(t*np.pi) plt.plot(t,curve1) plt.show() </code></pre>
0
2016-09-29T01:57:30Z
[ "python" ]
Scripting/Parsing Apple Motion 5 .motn files
39,760,227
<p>I'm new to animating and I've started using Apple Motion 5</p> <p><a href="http://www.apple.com/au/final-cut-pro/motion/" rel="nofollow">http://www.apple.com/au/final-cut-pro/motion/</a></p> <p>The interface can be a bit annoying by not letting me do things in bulk or automate things. Since it saves files in a nic...
2
2016-09-29T02:01:45Z
39,903,597
<blockquote> <p>Try <code>Awesome Python</code> at <a href="https://github.com/vinta/awesome-python" rel="nofollow">https://github.com/vinta/awesome-python</a></p> <p>Maybe you'll find there what you're looking for.</p> <p>But if you really want to use cool app try <strong><em>The Foundry Nuke</em></strong>...
1
2016-10-06T18:51:08Z
[ "python", "animation", "xml-parsing", "finalcut" ]
Dissecting a python puzzle forloop solution
39,760,263
<p>For a specific puzzle online I had to grab (using python) every lowercase letter surrounded by three uppercase letters on both sides. So for example in <code>'WExWQPoKLGnnNMOkPPOQ'</code>, the letters <code>ok</code> should be printed out. Despite finding a haphazard solution myself, a specific solution by another p...
0
2016-09-29T02:08:23Z
39,760,493
<blockquote> <p>why does code[i:i+9] not produce a TypeError: Can't convert 'int' object to str implicitly?</p> </blockquote> <p>Why would it? It is simply a slice notation, <code>i</code> is an int, <code>code</code> is a string.</p> <blockquote> <p>what does string.lowercase do in this instance?</p> </blockquot...
3
2016-09-29T02:36:39Z
[ "python", "for-loop", "encryption" ]
Dissecting a python puzzle forloop solution
39,760,263
<p>For a specific puzzle online I had to grab (using python) every lowercase letter surrounded by three uppercase letters on both sides. So for example in <code>'WExWQPoKLGnnNMOkPPOQ'</code>, the letters <code>ok</code> should be printed out. Despite finding a haphazard solution myself, a specific solution by another p...
0
2016-09-29T02:08:23Z
39,760,502
<p>On each iteration, <code>code[i:i+9]</code> extracts a sequence of 9 consecutive letters in the <code>code</code>string. For example, the first time <code>WExWQPoKL</code>. The next iteration will give <code>ExWQPoKLG</code>.</p> <p>At each of there iterations, out of these 9 letters, positions 1,2,3 and 5,6,7 sh...
1
2016-09-29T02:37:43Z
[ "python", "for-loop", "encryption" ]
Python simulation of a company's
39,760,304
<p>I have an assignment where I have to use Python code to simulate a company's hourly average maximum customer volume. The homework prompt says to import the random module and use the random.random() method. My issue is that I don't know what to put into the function itself. Here's the code I have so far:</p> <pre><c...
0
2016-09-29T02:14:43Z
39,760,365
<p>Maximum hourly customer volume is a rate so you should simulate this with a poisson distribution. You can create a poisson distribution like this:</p> <pre><code>import numpy as np rate = float(C)/H customers = np.random.poisson(rate, D*H) </code></pre> <p>Documentation for the poisson distribution can be found h...
0
2016-09-29T02:22:53Z
[ "python", "random", "module", "simulation" ]
python scripts to create a table on azure
39,760,427
<p>So I'm tryna run a python script that reads data from the Z wave sensors via the Rpi and using crontab on the pi I have set so the python script would run every minute and store it in a text file. Then I have another python script that sends the data to the azure cloud storage in a table form. The problem is that is...
2
2016-09-29T02:30:04Z
39,840,417
<p>This error occurs when there is no presentation/style information present for rendering, and in this case it is an Xml for communication so probably not needed. Here is another related thread - this might help. </p> <p><a href="http://stackoverflow.com/questions/7551106/this-xml-file-does-not-appear-to-have-any-sty...
0
2016-10-03T21:05:33Z
[ "python", "azure", "windows-azure-storage", "azure-storage-blobs", "raspberry-pi2" ]
Evaluate Array of operators and numbers in Python
39,760,441
<p>I have a program that produces arrays of numbers and operators, like this:<code>[1,'+',6,'*',3,'*',2]</code> What I would like to do is to evaluate this kind of array for its numerical value using order of operations. The array length may very, but they will always begin and end with a number and a number will not f...
0
2016-09-29T02:31:31Z
39,760,650
<p>You might try this, pretty naive though.</p> <pre><code>a = [1,'+',6,'*',3,'*',2] source = '' for i in a: source += str(i) print eval(source) # 37 </code></pre>
0
2016-09-29T02:54:48Z
[ "python", "arrays" ]
Python- Entry Level Programming
39,760,474
<p>I need to set up a code that has a 50% chance of selecting the first character of the mother string or the first character of the father string and add it to the child string, and so on for each letter. </p> <pre><code>import random mama_string = "0&gt;Y!j~K:bv9\Y,2" papa_string = "OkEK=gS&lt;mO%DnD{" child = "" w...
-3
2016-09-29T02:35:29Z
39,760,573
<p>You want to add one character per each iteration of the while loop (once for every time to generate a random number). Instead of running a for loop that goes through every character of the mama_string or papa_string. Just do</p> <pre><code> if random_number &lt;= 50: child += mama_char[len(child)] els...
0
2016-09-29T02:45:41Z
[ "python", "random", "iteration" ]
Python- Entry Level Programming
39,760,474
<p>I need to set up a code that has a 50% chance of selecting the first character of the mother string or the first character of the father string and add it to the child string, and so on for each letter. </p> <pre><code>import random mama_string = "0&gt;Y!j~K:bv9\Y,2" papa_string = "OkEK=gS&lt;mO%DnD{" child = "" w...
-3
2016-09-29T02:35:29Z
39,760,646
<p>You could do it this way:</p> <pre><code>import numpy as np counter = 0 while len(child) &lt; 15: choice = np.random.choice([0,1]) if choice == 0: child += papa_string[counter] else: child += mama_string[counter] counter += 1 </code></pre> <p>This will alternate between selectin...
0
2016-09-29T02:54:30Z
[ "python", "random", "iteration" ]
Using minimise function ('SLSQP' method) in sympy with free and fixed parameters
39,760,542
<p>I am still a beginner in python, so I am sorry if this is too trivial. I want to calculate the minimum value of a function which has 12 variables in total. Of these 12 variables, 10 are fixed at a given value and the remaining 2 is left free to compute the minimum. Here is an example of my code.</p> <pre><code>impo...
1
2016-09-29T02:42:00Z
39,767,762
<p>It seems that you are minimizing distance between two ellipse. You don't need sympy to do this. Here is an example:</p> <pre><code>from math import sin, cos, hypot, pi from scipy import optimize import numpy as np def ellipse(xc, yc, a, b, psi): a_cos_p = a * cos(psi) a_sin_p = a * sin(psi) b_cos_p = b...
1
2016-09-29T10:27:33Z
[ "python", "numpy", "sympy", "minimization" ]
How to parse XML of nested tags in Python
39,760,555
<p>I have following XML.</p> <pre><code>&lt;component name="QUESTIONS"&gt; &lt;topic name="Chair"&gt; &lt;state&gt;active&lt;/state&gt; &lt;subtopic name="Wooden"&gt; &lt;links&gt; &lt;link videoDuration="" youtubeId="" type="article"&gt; &lt;label...
0
2016-09-29T02:43:20Z
39,760,931
<p>The information you want is under <code>&lt;link&gt;</code> so just iterate through those. Use <code>get()</code> to get the youtube id and <code>find()</code> to get the child <code>&lt;url&gt;</code> object. </p> <pre><code>from xml.etree import ElementTree with open('faq.xml', 'rt') as f: tree = ElementTree...
1
2016-09-29T03:28:03Z
[ "python", "xml" ]
How to parse XML of nested tags in Python
39,760,555
<p>I have following XML.</p> <pre><code>&lt;component name="QUESTIONS"&gt; &lt;topic name="Chair"&gt; &lt;state&gt;active&lt;/state&gt; &lt;subtopic name="Wooden"&gt; &lt;links&gt; &lt;link videoDuration="" youtubeId="" type="article"&gt; &lt;label...
0
2016-09-29T02:43:20Z
39,762,205
<p>Take a look at <a href="https://github.com/martinblech/xmltodict" rel="nofollow">xmltodict</a>.</p> <pre><code>&gt;&gt;&gt; print(json.dumps(xmltodict.parse(""" ... &lt;mydocument has="an attribute"&gt; ... &lt;and&gt; ... &lt;many&gt;elements&lt;/many&gt; ... &lt;many&gt;more elements&lt;/many&gt; .....
0
2016-09-29T05:39:14Z
[ "python", "xml" ]
Iterating Over CSV Deleting Analyzed Data
39,760,579
<p>Hello I am trying to take a CSV file and iterate over each customers data. To explain, each customer has data for 12 months. I want to analyze their yearly data, save the correlations of this data to a new list and loop this until all customers have been analyzed.</p> <p>For instance here is what a customers data m...
0
2016-09-29T02:46:30Z
39,766,541
<p>You use the same variable <code>x</code> for both loops. In the second loop <code>x</code> goes from 0 to 12 whatever the customer, and since you set the line number only with <code>x</code> you're stuck on the first customer.</p> <p>Your double loop should rather look like this :</p> <pre><code># loop over the cu...
0
2016-09-29T09:28:50Z
[ "python", "list", "csv", "append" ]
Iterating Over CSV Deleting Analyzed Data
39,760,579
<p>Hello I am trying to take a CSV file and iterate over each customers data. To explain, each customer has data for 12 months. I want to analyze their yearly data, save the correlations of this data to a new list and loop this until all customers have been analyzed.</p> <p>For instance here is what a customers data m...
0
2016-09-29T02:46:30Z
39,780,384
<p>this is how I solved the problem: It was a problem with the placement of my for loops. A simple indentation problem. Thank you for the help to above poster.</p> <p>for x_customer in range(0,len(overalldata),12):</p> <pre><code> for x in range(0,13,1): cust_months = overalldata[0:x,1] cus...
0
2016-09-29T21:33:28Z
[ "python", "list", "csv", "append" ]
How to access Selenium elements as soon as they are available, rather than waiting for the whole page to load
39,760,595
<pre><code>driver = webdriver.Chrome() #driver.set_page_load_timeout(10) driver.get("sitename.com") driver.find_element_by_id("usernameId").send_keys("myusername") </code></pre> <p>Setting a page load time proved counterproductive as the page load was killed even before the elements were actually loaded!</p> <p>Cur...
0
2016-09-29T02:48:12Z
39,762,067
<p>Take a look at <a href="http://selenium-python.readthedocs.io/waits.html" rel="nofollow">selenium python documentation</a>.</p> <p>It has visibility_of_element_located.</p> <pre><code>from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(driver, 10) element = wait.until(EC.visibili...
1
2016-09-29T05:26:53Z
[ "python", "selenium", "selenium-chromedriver" ]
How to access Selenium elements as soon as they are available, rather than waiting for the whole page to load
39,760,595
<pre><code>driver = webdriver.Chrome() #driver.set_page_load_timeout(10) driver.get("sitename.com") driver.find_element_by_id("usernameId").send_keys("myusername") </code></pre> <p>Setting a page load time proved counterproductive as the page load was killed even before the elements were actually loaded!</p> <p>Cur...
0
2016-09-29T02:48:12Z
39,764,430
<p>It is a best practice to wait for entire page to load before you take any further action. However, if you want to stop the page load in between(or load the page only for a specified time and carry on), you can change this in the browser's profile setting.</p> <p>In case of Firefox :</p> <pre><code>profile = webdri...
1
2016-09-29T07:52:05Z
[ "python", "selenium", "selenium-chromedriver" ]
Getting a SyntaxError in try:except (python)
39,760,601
<p>Hi so I'm really new to Python and I have a little question.</p> <p>In my code:</p> <pre><code>from collections import Counter </code></pre> <p>try: while True:</p> <pre><code> name1 = input ("your name") list(name1) name1len = len(name1) name2 = input ("other one's name") list(name2) name2len = len(name...
0
2016-09-29T02:48:58Z
39,760,695
<p>In order to use the <code>try &amp; except</code> functions, you need to you that first part, the <code>try</code>. In your code there is no <code>try:</code> which is why the <code>except</code> is causing issues.</p> <p>However every time I try to fix one issue, other one pops up. However Python won't even run yo...
0
2016-09-29T03:01:00Z
[ "python", "python-3.x" ]
How to capture KeyboardInterrupt in pytest?
39,760,629
<p>UnitTests has a feature to capture <code>KeyboardInterrupt</code>, finishes a test and then report the results.</p> <blockquote> <p><strong>-c, --catch</strong> </p> <p><em>Control-C</em> during the test run waits for the current test to end and then reports all the results so far. A second <em>Control-C</em...
0
2016-09-29T02:52:51Z
39,761,889
<p>Take a look at pytest's <a href="http://doc.pytest.org/en/latest/_modules/_pytest/hookspec.html" rel="nofollow">hookspec</a>.</p> <p>They have a hook for keyword interrupt.</p> <pre><code>def pytest_keyboard_interrupt(excinfo): """ called for keyboard interrupt. """ </code></pre>
0
2016-09-29T05:13:06Z
[ "python", "py.test" ]
How can I order elements in a window in python apache beam?
39,760,733
<p>I noticed that java apache beam has class groupby.sortbytimestamp does python have that feature implemented yet? If not what would be the way to sort elements in a window? I figure I could sort the entire window in a DoFn, but I would like to know if there is a better way. </p>
1
2016-09-29T03:04:16Z
39,776,373
<p>There is not currently built-in value sorting in Beam (in either Python or Java). Right now, the best option is to sort the values yourself in a DoFn like you mentioned.</p>
3
2016-09-29T17:17:47Z
[ "python", "google-cloud-dataflow", "dataflow", "apache-beam" ]
Generate Swagger specification from Python code without annotations
39,760,800
<p>I am searching for a way to generate a Swagger specification (the JSON and Swagger-UI) from the definition of a Python service. I have found many options (normally Flask-based), but all of them use annotations, which I cannot properly handle from within the code, e.g. define 10 equivalent services with different rou...
0
2016-09-29T03:11:23Z
39,761,823
<p>I suggest looking into <a href="http://apispec.readthedocs.io/en/latest/quickstart.html" rel="nofollow">apispec</a>.</p> <p>apispec is a pluggable API specification generator.</p> <p>Currently supports the OpenAPI 2.0 specification (f.k.a. Swagger 2.0)</p> <p><strong><em>apispec</em></strong></p> <pre><code>from...
0
2016-09-29T05:07:10Z
[ "python", "web-services", "python-3.x", "swagger-ui", "swagger-2.0" ]
Why variable still exists after function call finished -python
39,760,910
<p>I read from a book about some code like below, but it was not explained. As you can see, before I call the function, no variable exists. But after function call, var2 was popped form stack and removed from our namespace of func_a as what we expected. But, var1 still exists!!!</p> <blockquote> <p>How to explain t...
1
2016-09-29T03:24:49Z
39,760,955
<blockquote> <p>How to explain this phenomenon? Is var1 a special kind of variable?</p> </blockquote> <p>Yes, <code>var1</code> is a special kind of variable. Or perhaps more precisely, it's not a variable at all. It's an attribute of an object (even though the object is a function). The object existed before the fu...
4
2016-09-29T03:31:27Z
[ "python", "python-2.7" ]
Why variable still exists after function call finished -python
39,760,910
<p>I read from a book about some code like below, but it was not explained. As you can see, before I call the function, no variable exists. But after function call, var2 was popped form stack and removed from our namespace of func_a as what we expected. But, var1 still exists!!!</p> <blockquote> <p>How to explain t...
1
2016-09-29T03:24:49Z
39,760,976
<p>You are confusing the function namespace with the function object. Before the function is called, <code>var1</code> doesn't exist. When the function is called, python creates a temporary local namespace for that one call. When the function hits <code>var2 = 2</code>, <code>var2</code> is created in the local functio...
2
2016-09-29T03:34:14Z
[ "python", "python-2.7" ]
Not able to frame text while adding a line to middle of file in python
39,760,947
<p>My text.txt looks like this</p> <pre><code>abcd xyzv dead-hosts -abcd.srini.com -asdsfcd.srini.com </code></pre> <p>And I want to insert few lines after "dead-hosts" line, I made a script to add lines to file, there is extra space before last line, that's mandatory in my file, but post added new lines that space...
-1
2016-09-29T03:30:39Z
39,761,744
<p><strong>Points:</strong></p> <ul> <li>In you code , <code>pos = tmplst.index('dead-hosts:')</code>, you are trying to find <code>dead-hosts:</code>. However, input file you have given has only "<code>dead hosts</code>". No colon after dead-hosts, I am considering <code>dead-hosts:</code></li> <li>While reading file...
0
2016-09-29T04:59:47Z
[ "python" ]
List of dicts each with different keys, best way to look for a sequence of dicts
39,760,971
<p>I have a list of dicts (list with each entry being a dict). Each dict has a different set of keys, so one dict may have a key that is not present with the other dicts in the list. I am trying to find a specific order of dicts inside this list. Basically, the list is from a wireshark capture and I want to look for ce...
0
2016-09-29T03:33:22Z
39,761,203
<pre><code>first_packet = None second_packet = None third_packet = None packets_found = 0 for packet in packets: val = packet.get('some_field', None) if (val == A_CONSTANT_I_HAVE_DEFINED) and (first_packet is not None): first_packet = packet packets_found += 1 elif (val == ANOTHER_CONSTANT...
0
2016-09-29T04:03:42Z
[ "python", "list", "dictionary" ]
List of dicts each with different keys, best way to look for a sequence of dicts
39,760,971
<p>I have a list of dicts (list with each entry being a dict). Each dict has a different set of keys, so one dict may have a key that is not present with the other dicts in the list. I am trying to find a specific order of dicts inside this list. Basically, the list is from a wireshark capture and I want to look for ce...
0
2016-09-29T03:33:22Z
39,761,204
<p>I am not clear, this might help:</p> <pre><code>a = [{'a': 1}, {'a':1, 'b':1}, {'c':1}] filtered_list = filter(lambda x: x.get('a') or x.get('b'), a) # OP [{'a': 1}, {'a': 1, 'b': 1}] </code></pre> <p>Hope this helps.</p>
0
2016-09-29T04:04:04Z
[ "python", "list", "dictionary" ]
Sum up values in a column using Pandas
39,761,068
<p>I have a dataframe where one column has a list of zipcodes and the other has property values corresponding to the zipcode. I want to sum up the property values in each row according to the appropriate zipcode. </p> <p>So, for example:</p> <pre><code>zip value 2210 $5,000 2130 $3,000 2210 $2,100 2345 $1,000 </code...
0
2016-09-29T03:45:56Z
39,761,102
<p>You need:</p> <pre><code>df zip value 0 2210 5000 1 2130 3000 2 2210 2100 3 2345 1000 df2 = df.groupby(['zip'])['value'].sum() df2 zip value 2130 3000 2210 7100 2345 1000 Name: value, dtype: int64 </code></pre> <p>You can read more about it <a href="http://pandas.pydata.org/pandas-d...
1
2016-09-29T03:51:12Z
[ "python", "pandas", "dataframe", "sum" ]
Login to website with Python requests
39,761,233
<p>I am having some trouble logging into this website: <a href="https://illinoisjoblink.illinois.gov/ada/r/home" rel="nofollow">https://illinoisjoblink.illinois.gov/ada/r/home</a></p> <p>I am able to submit the payload, but I get redirected to a page claiming a bookmark error. Here is the code and relevant error messa...
0
2016-09-29T04:07:08Z
39,808,378
<p>Perhaps your <code>login_data</code> parameters are wrong? When I inspect the POST for logging in, the necessary parameters appear to be: <code>v_username</code>, <code>v_password</code>, <code>FormName</code>, <code>fromlogin</code>, and maybe most importantly, <code>button</code>. I would suggest you add all these...
0
2016-10-01T15:32:00Z
[ "python", "login", "website", "python-requests", "screen-scraping" ]
Better way to loop through nested categories?
39,761,252
<p>I have a sqlalchemy categories table that looks like this:</p> <pre><code>id | parent_id | name 1 | 0 | license 2 | 1 | Digital Media 3 | 1 | Advertising 4 | 2 | Email Marketing </code></pre> <p>My goal is to convert this into a nested dictionary or list that I can loop through in a Flask template. The code below ...
0
2016-09-29T04:08:41Z
39,761,318
<p>You can nest list comprehensions, so you need not double-loop through <code>roots</code> and <code>categories</code>.</p> <pre><code>categories = Category.query.all() roots = [root for root in categories if root.parent_id == 1] items = [ { 'root': root.name, 'subcategories': [ catego...
0
2016-09-29T04:16:46Z
[ "python" ]
Better way to loop through nested categories?
39,761,252
<p>I have a sqlalchemy categories table that looks like this:</p> <pre><code>id | parent_id | name 1 | 0 | license 2 | 1 | Digital Media 3 | 1 | Advertising 4 | 2 | Email Marketing </code></pre> <p>My goal is to convert this into a nested dictionary or list that I can loop through in a Flask template. The code below ...
0
2016-09-29T04:08:41Z
39,761,438
<p>If you just want a more concise way of writing the logic you've put forward, look below:</p> <pre><code>categories = Category.query.all() items = [{'root': root.name, 'subcategories': [category.name for category in categories if category.parent_id == root.id] } for root in categories if ro...
1
2016-09-29T04:30:30Z
[ "python" ]
Python reading and writing a csv file working with dates
39,761,272
<p>I would like to see in python, the code that reads a csv file containing years of historical dates with a value (example of each line: 2016-09-23,2173.290039) , this code would then write another csv file with every date and its associated value that occurs on a Friday. Thank you so much for your help.</p>
-1
2016-09-29T04:11:07Z
39,764,275
<p>The following script will do what you need:</p> <pre><code>from datetime import datetime import csv with open('input.csv', 'rb') as f_input, open('output.csv', 'wb') as f_output: csv_input = csv.reader(f_input) csv_output = csv.writer(f_output) for row in csv_input: if datetime.strptime(row...
0
2016-09-29T07:42:05Z
[ "python", "csv", "calendar" ]
Where to write the save function in Django?
39,761,280
<p>Where to write my save function in django whether in models.py in a class model or in forms.py in form ?</p> <p>For example : models.py </p> <pre><code>class Customer(models.Model): name = models.CharField(max_length=200) created_by = models.ForeignKey(User) def save(): ........ some code to ove...
-1
2016-09-29T04:12:18Z
39,761,391
<p>It really depends on what you are trying to achieve. Default realization of <code>ModelForm</code>'s save calls <code>Model</code>'s save. But it is usually better to override it on <code>form</code> because it also runs validation. So if you are already using form I would suggest overriding <code>ModelForm.save</co...
0
2016-09-29T04:25:25Z
[ "python", "django", "django-models", "django-forms" ]
Transpose the data in a column every nth rows in PANDAS
39,761,366
<p>For a research project, I need to process every individual's information from the website into an excel file. I have copied and pasted everything I need from the website onto a single column in an excel file, and I loaded that file using PANDAS. However, I need to present each individual's information horizontally i...
2
2016-09-29T04:22:56Z
39,762,293
<p>If no data are missing, you can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.reshape.html" rel="nofollow"><code>numpy.reshape</code></a>:</p> <pre><code>print (np.reshape(df.values,(2,5))) [['Andrew' 'School of Music' 'Music: Sound of the wind' 'Dr. Seuss' 'Dr.Sass'] ['Michelle' 'School...
1
2016-09-29T05:45:32Z
[ "python", "pandas", "dataframe", "reshape", "transpose" ]
Why is pip install pyopenssl==0.13 failing?
39,761,380
<p>I'm trying to install PyOpenSSL 0.13 on my Macbook Pro (OSX version 10.11, El-Capitan). But it keeps failing. These are the steps I took</p> <ol> <li>Download and install Command Line Tools (OSX 10.11) for Xcode 7.3.1 from <a href="https://developer.apple.com/download/more/" rel="nofollow">here</a></li> <li><code>$...
0
2016-09-29T04:24:06Z
39,761,925
<p>It appears you are missing the OpenSSL development headers, as mentioned by <a href="http://stackoverflow.com/users/3929826/klaus-d">@Klaus D.</a> This most likely happened because due to upgrading to El Capitan, these development headers were broken. It can usually be fixed by reinstalling your command line tools. ...
1
2016-09-29T05:16:16Z
[ "python", "osx", "pip", "pyopenssl", "libcrypto" ]
Yielding from a recursive function
39,761,413
<p>So let us say I have a few nodes. Each node has a list of nodes it can go to. This list of nodes can include itself. What I need to do is build all possible paths a node can take that are of n-length.</p> <p>For example: Let's assume a few things. </p> <ul> <li>I have node A and node B</li> <li>I need all possible...
0
2016-09-29T04:28:35Z
39,761,463
<p>you could convert your current solution to a generator the easiest way by changing the return calls to yields ... that may be enough ... it might not also.. there are some graphtraversal libraries out there as well that may solve this very nicely if your goal is simply to solve the problem</p> <pre><code>PARTS = 3 ...
0
2016-09-29T04:33:18Z
[ "python", "recursion" ]
Python Sending command
39,761,444
<p>I'm trying to send a End command to the end of this line of code. I've searched everywhere and not able to find a valuable answer..</p> <pre><code>if args.time: def stopwatch(seconds): start = time.time() time.clock() elapsed = 0 while elapsed &lt; seconds: elapse...
0
2016-09-29T04:31:10Z
39,761,496
<p>You can use control-c.</p> <p>You just have to catch the <strong>KeyboardInterrupt</strong> Exception.</p> <pre><code>try: # your loop code here except KeyboardInterrupt: # do whatever you want when user presses ctrl+c </code></pre>
0
2016-09-29T04:35:41Z
[ "python" ]
Python Sending command
39,761,444
<p>I'm trying to send a End command to the end of this line of code. I've searched everywhere and not able to find a valuable answer..</p> <pre><code>if args.time: def stopwatch(seconds): start = time.time() time.clock() elapsed = 0 while elapsed &lt; seconds: elapse...
0
2016-09-29T04:31:10Z
39,761,502
<p>You want to catch a <code>KeyboardInterrupt</code>:</p> <pre><code>if args.time: def stopwatch(seconds): start = time.time() time.clock() elapsed = 0 while elapsed &lt; seconds: try: elapsed = time.time() - start print "Sending for(...
1
2016-09-29T04:36:42Z
[ "python" ]
Comparing a dataframe on string lengths for different columns
39,761,488
<p>I am trying to get the string lengths for different columns. Seems quite straightforward with: </p> <pre><code>df['a'].str.len() </code></pre> <p>But I need to apply it to multiple columns. And then get the minimum on it. </p> <p>Something like: </p> <pre><code>df[['a','b','c']].str.len().min </code></pre> <p>I...
2
2016-09-29T04:35:00Z
39,761,785
<p>I think you need list comprehension, because <code>string</code> function works only with <code>Series</code> (<code>column</code>):</p> <pre><code>print ([df[col].str.len().min() for col in ['a','b','c']]) </code></pre> <p>Another solution with <code>apply</code>:</p> <pre><code>print ([df[col].apply(len).min() ...
3
2016-09-29T05:04:21Z
[ "python", "pandas", "dataframe", "min", "string-length" ]
How to run two loop simeltanously in one loop in python
39,761,495
<p>Is there any way available to put two loops in one? I have:</p> <pre><code>for getFeature in layerNameValueGetObj.getFeatures(): for setFeature in layerNameValueSetObj.getFeatures(): </code></pre> <p>I want to run <code>layerNameValueGetObj.getFeatures()</code> and <code>layerNameValueSetObj.getFeatures()</cod...
0
2016-09-29T04:35:35Z
39,761,514
<p><code>itertools.product</code> exists for exactly this purpose</p> <pre><code>import itertools for getFeature, setFeature in itertools.product(layerNameValueGetObj.getFeatures(), layerNameValueSetObj.getFeatures()): # dostuff </code></pre>
2
2016-09-29T04:37:23Z
[ "python" ]
How to run two loop simeltanously in one loop in python
39,761,495
<p>Is there any way available to put two loops in one? I have:</p> <pre><code>for getFeature in layerNameValueGetObj.getFeatures(): for setFeature in layerNameValueSetObj.getFeatures(): </code></pre> <p>I want to run <code>layerNameValueGetObj.getFeatures()</code> and <code>layerNameValueSetObj.getFeatures()</cod...
0
2016-09-29T04:35:35Z
39,761,594
<p>You can use <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow">zip</a></p> <pre><code>for a, b in zip(list_a, list_b): print a, b </code></pre>
2
2016-09-29T04:45:54Z
[ "python" ]
How to run two loop simeltanously in one loop in python
39,761,495
<p>Is there any way available to put two loops in one? I have:</p> <pre><code>for getFeature in layerNameValueGetObj.getFeatures(): for setFeature in layerNameValueSetObj.getFeatures(): </code></pre> <p>I want to run <code>layerNameValueGetObj.getFeatures()</code> and <code>layerNameValueSetObj.getFeatures()</cod...
0
2016-09-29T04:35:35Z
39,761,652
<p><code>zip_longest</code> will iterate until all lists are consumed. For <code>zip</code> the results are truncated to the shortest iterator.</p> <pre><code>from itertools import zip_longest for get_feature, set_feature in zip_longest(layerNameValueGetObj.getFeatures(), layerNameValueSetObj.getFeatures()): ...
3
2016-09-29T04:51:01Z
[ "python" ]
flask with many buttons and database update
39,761,505
<p>I am trying to make a web app like a mini-tweets. The posts are pulled out from a database and I want to have an 'up vote' button for each post, like the following picture. </p> <p><a href="http://i.stack.imgur.com/kJySO.png" rel="nofollow"><img src="http://i.stack.imgur.com/kJySO.png" alt="posts"></a></p> <p>Each...
1
2016-09-29T04:36:57Z
39,761,725
<p>A clean way to do that would be to add a data attribute, in your <code>button</code> tag and do one ajax request per upvote / downvote.</p> <p><a href="https://developer.mozilla.org/en/docs/Web/Guide/HTML/Using_data_attributes" rel="nofollow">https://developer.mozilla.org/en/docs/Web/Guide/HTML/Using_data_attribute...
1
2016-09-29T04:58:05Z
[ "python", "html", "flask", "html-form", "html-form-post" ]
Django render different templates for two submit buttons in a form
39,761,535
<p>I am a beginner at Django development, and I am trying to make a food diary application. After a user enters his email on <code>index.html</code>, another web page should be rendered according to whichever button he clicks.</p> <p>I can possibly add two templates, but I also want my app to work if a user manually t...
0
2016-09-29T04:39:34Z
39,761,784
<p>1) passing in an argument into a url, you can use regex groups to pass arguments. Here is an example using a kwarg:</p> <pre><code>url(r'^(?P&lt;user_email&gt;[^@]+@[^@]+\.[^@]+)/addDiaryEntry/$', views.add_diary, name='add-diary-entry'), </code></pre> <p>2) just render a different template depending on which butt...
0
2016-09-29T05:04:12Z
[ "python", "django", "forms", "django-templates" ]
Extract first two lines of PDF with Python and pyPDF
39,761,609
<p>I'm using python 2.7 and pyPDF to get the title meta info from PDF files. Unfortunately not all of PDF have the meta info. What I want to do now is grab the first two line of text from a PDF. Using what I have now how can I modify the code to capture the first two lines with pyPDF?</p> <pre><code>from pyPdf import ...
0
2016-09-29T04:46:58Z
39,761,680
<pre><code>from PyPDF2 import PdfFileWriter, PdfFileReader import os import StringIO fileName = "HMM.pdf" try: if fileName.lower()[-3:] == "pdf": input1 = PdfFileReader(file(fileName, "rb")) # print the title of document1.pdf #print fileName, input1.getDocumentInfo().title...
1
2016-09-29T04:53:50Z
[ "python", "python-2.7", "pypdf" ]
Pandas Dataframe comparison with range/stdev
39,761,648
<p>I have to dataframes A and B. Both have a 'datetime' column and another common column X. B is bigger as it has X at every minute while A only has X at intermittent times during a day. For each 'datetime' in A, I want to calculate the range (or stdev) of X during previous 30 minutes using B. So something like:</p> <...
-1
2016-09-29T04:50:41Z
39,762,636
<p>This works for me but uses a loop:</p> <p><code>rangex=np.zeros(A.shape[0])<br> for i,Date in enumerate(A['Date']): temp=B[(B['Date'] &gt; Date-datetime.timedelta(days=0, minutes=30)) &amp; (B['Date'] &lt;=Date)] rangex[i]=temp['input'].max()-temp['input'].min()<br> A['range']=pd.Series(rangex, index=A....
0
2016-09-29T06:10:37Z
[ "python", "pandas", "dataframe", "timestamp", "range" ]
How to run progress bar widget from dask.distributed in a separate thread?
39,761,660
<p>There is an example <a href="http://distributed.readthedocs.io/en/latest/queues.html" rel="nofollow">here</a>, showing insertion of data for processing in a separate thread. I'm interested in reverse, when data are inserted manually and interactively, and background thread submits them to cluster for calculation. </...
1
2016-09-29T04:51:57Z
39,807,398
<p>This is already the case. When you call </p> <pre><code>client.submit(function, *args, **kwargs) </code></pre> <p>This serializes stuff immediately in the local thread (blocking), but then adds a callback to the Tornado IOLoop (running in a separate thread) to manage the actual communication to the scheduler. Th...
0
2016-10-01T13:48:40Z
[ "python", "distributed", "jupyter-notebook", "dask" ]
AWS Boto3 BASE64 encoding error thrown when invoking client.request_spot_instances method
39,761,666
<p>I am trying to submit a request for an EC2 SPOT instance using boto3 (Environment Python 3.5,Windows 7). I need to pass the <strong>UserData</strong> parameter for running initial scripts.</p> <p>The error I get is File "C:\Users...\Python\Python35\lib\site-packages\botocore\client.py", line 222, in _make_api_c...
0
2016-09-29T04:52:33Z
39,762,101
<p>I think you shouldn't convert your base64 string to <code>str</code>. Are you using Python 3?</p> <p>Replace:</p> <pre><code>myparam = str(base64.b64encode(bytes('yum install -y php', 'utf-8'))) </code></pre> <p>By:</p> <pre><code>myparam = base64.b64encode(b'yum install -y php') </code></pre>
1
2016-09-29T05:30:11Z
[ "python", "amazon-web-services", "amazon-ec2", "base64", "boto3" ]
Python 2D Dynamic List Error
39,761,675
<p>I am new to Python.</p> <pre><code> for row in reader: if (int(row[0]) &lt;= nextWeek): y[i].append(row[1]) if (int(row[0]) &gt; nextWeek): i = i + 1 y[i].append(row[1]) </code></pre> <p>These are the parts of the code , here I ...
0
2016-09-29T04:53:28Z
39,763,821
<p>I think what you are searching for is a defaultdict. Lets say you've got:</p> <pre><code>from collections import defaultdict y = defaultdict(list) (...) for row in reader: if (int(row[0]) &lt;= nextWeek): y[i].append(row[1]) if (int(row[0]) &gt; nextWeek): i = i + 1 ...
0
2016-09-29T07:17:52Z
[ "python", "matplotlib" ]
General Python Unicode / ASCII Casting Issue Causing Trouble in Pyorient
39,761,684
<p>UPDATE: I opened an issue on github based on a Ivan Mainetti's suggestion. If you want to weigh in there, it is :<a href="https://github.com/orientechnologies/orientdb/issues/6757" rel="nofollow">https://github.com/orientechnologies/orientdb/issues/6757</a></p> <p>I am working on a database based on OrienDB and us...
0
2016-09-29T04:54:05Z
39,990,610
<p>I have tried your example on Python 3 with the development branch of pyorient with the latest version of OrientDB 2.2.11. If I pass the values without escaping them, your example seems to work for me and I get the right values back.</p> <p>So this test works:</p> <pre><code>def test_test1(self): new_Node = {'@...
1
2016-10-12T04:37:03Z
[ "python", "string", "unicode", "orientdb", "pyorient" ]
Create a vector given N input of names and ages python
39,761,767
<p>I need to create a program that takes as inputs multiple entries of names and ages. Then I want it to return the names and ages of those entries that have higher age values than the average age of all entries. For example:</p> <pre><code>input( "Enter a name: ") Albert input( "Enter an age: ") 16 input( "Enter ...
0
2016-09-29T05:02:14Z
39,767,251
<pre><code>answers = {} # Use a flag to indicate that the questionnaire is active. questions_active = True while questions_active: # Ask for the person's name and response. name = raw_input("\nEnter a name: ") response = raw_input("Enter an age: ") # Store the response in the dictionary: answers[name]...
1
2016-09-29T10:02:18Z
[ "python", "dictionary", "vector" ]
Insides of __getattr__(self, __getitem__) in python 2
39,761,778
<p>In python2, this old-style class:</p> <pre><code>class C: x = 'foo' def __getattr__(self, name): print name print type(name) return getattr(self.x, name) &gt; X = C() &gt; X[1] __getitem__ &lt;type 'str'&gt; 'o' </code></pre> <p>Question is, what is going on in the bowels of this? ...
1
2016-09-29T05:03:20Z
39,761,974
<p>To cut right to it, this is what is happening step by step.</p> <p>When you call <code>X[1]</code>, it is going to attempt to look up an attribute called <code>__getitem__</code> in your class. As you do not have any attributes (function or variable) with that name, so it will fallback to call your <code>__getattr_...
2
2016-09-29T05:20:00Z
[ "python", "python-2.7" ]
Python: How to assign function name dynamically in Class
39,761,908
<p>I have an question about how to assign function name dynamically in Class.</p> <h2>For example:</h2> <pre><code>If a class wants to be used for "for...in" loop, similar to a list or a tuple, you must implement an __iter__ () method python2.x will use __iter__() and next(), python3.x need to use __iter__() and __n...
2
2016-09-29T05:14:37Z
39,762,118
<p>I don't think there's a need to create this method dynamically. Just implement both; clearer and easier. And your code will be Python 2/3 compatible without needing an if-statement.</p> <pre><code>class Fib(object): def __init__(self): self.a, self.b = 0, 1 def __iter__(self): return self ...
5
2016-09-29T05:31:27Z
[ "python" ]
Python: How to assign function name dynamically in Class
39,761,908
<p>I have an question about how to assign function name dynamically in Class.</p> <h2>For example:</h2> <pre><code>If a class wants to be used for "for...in" loop, similar to a list or a tuple, you must implement an __iter__ () method python2.x will use __iter__() and next(), python3.x need to use __iter__() and __n...
2
2016-09-29T05:14:37Z
39,762,151
<p>In python there is the way to call a function ,method ,get any element by using getattr(from,'name of attribute to call').</p> <p>below is the sample example of this:</p> <pre><code>class A(): def s(self): print "s fun" def d(self): print "a fun" def run(self): print...
-1
2016-09-29T05:34:12Z
[ "python" ]
Python: How to assign function name dynamically in Class
39,761,908
<p>I have an question about how to assign function name dynamically in Class.</p> <h2>For example:</h2> <pre><code>If a class wants to be used for "for...in" loop, similar to a list or a tuple, you must implement an __iter__ () method python2.x will use __iter__() and next(), python3.x need to use __iter__() and __n...
2
2016-09-29T05:14:37Z
39,762,299
<p>Agreed that just implementing both is probably best, but something like this seems to do what you intend:</p> <pre><code> def iter_n(self): self.a, self.b = self.b, self.a + self.b if self.a &gt; 10: raise StopIteration(); return self.a if sys.version_info[0] == 2: ...
1
2016-09-29T05:45:45Z
[ "python" ]
Rearranging groupings in bar chart from pandas dataframe
39,761,916
<p>I want a grouped bar chart, but the default plot doesn't have the groupings the way I'd like, and I'm struggling to get them rearranged properly.</p> <p>The dataframe looks like this:</p> <pre> user year cat1 cat2 cat3 cat4 cat5 0 Brad 2014 309 186 119 702 73 1 Brad 2015 280 177 ...
1
2016-09-29T05:15:08Z
39,774,561
<p>Select the subset of users you want to plot against. Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table</code></a> later to transform the <code>DF</code> to the required format to be plotted by transposing and unstacking it.</p> <pre><code>im...
1
2016-09-29T15:36:40Z
[ "python", "pandas", "matplotlib" ]
How to compare an array value with another explicit value in python
39,761,950
<p>I want to do something like this</p> <pre><code>while(x&lt;100 for x in someList): if someList has a value more than 100 the loop should end. </code></pre>
-1
2016-09-29T05:18:26Z
39,761,987
<p>This will also end the loop when value is greater than 100</p> <pre><code>for x in someList: if x &gt; 100: break </code></pre> <p>You can try this:</p> <pre><code>i=0 while ((i&lt;len(someList)) and (someList[i] &lt;= 100) ): '''Do something''' i+=1 </code></pre>
3
2016-09-29T05:21:08Z
[ "python", "loops", "compare" ]
How to compare an array value with another explicit value in python
39,761,950
<p>I want to do something like this</p> <pre><code>while(x&lt;100 for x in someList): if someList has a value more than 100 the loop should end. </code></pre>
-1
2016-09-29T05:18:26Z
39,762,247
<p>You <em>could</em> use <code>itertools.takewhile</code>:</p> <pre><code>for x in takewhile(lambda x: x &lt;= 100, someList): print(x) </code></pre> <p>But I think @sinsuren's <code>break</code> solution is best. I'd only use <code>takewhile</code> when I don't want a loop, for example in <code>sum(takewhile(la...
1
2016-09-29T05:41:40Z
[ "python", "loops", "compare" ]
How can I simplify my if condition in python?
39,761,962
<p>I would like to know if there's a simpler way to write the condition of the <code>if</code> statement. Something like <code>item1, item2 == "wood":</code>. I currently have this code:</p> <pre><code>item1 = input("item1: ") item2 = input("item2: ") if item1 == "wood" and item2 == "wood": print("You created a s...
1
2016-09-29T05:19:00Z
39,761,999
<p>This isn't a huge savings but you could take out <code>"wood" and</code></p> <pre><code>item1 = input("item1: ") item2 = input("item2: ") if item1 == item2 == "wood": print("You created a stick") </code></pre>
5
2016-09-29T05:22:26Z
[ "python", "if-statement", "condition", "simplify" ]
How can I simplify my if condition in python?
39,761,962
<p>I would like to know if there's a simpler way to write the condition of the <code>if</code> statement. Something like <code>item1, item2 == "wood":</code>. I currently have this code:</p> <pre><code>item1 = input("item1: ") item2 = input("item2: ") if item1 == "wood" and item2 == "wood": print("You created a s...
1
2016-09-29T05:19:00Z
39,762,060
<p>In this particular case, it's fine to leave it as is. But if you have three or more elements, try using a list:</p> <pre><code>items = [] # Declare a list # Add items to list for x in range(1, 4): items.append(input("item" + str(x) + ": ")) if all(item == "wood" for item in items): print("You created a st...
1
2016-09-29T05:26:14Z
[ "python", "if-statement", "condition", "simplify" ]
How can I simplify my if condition in python?
39,761,962
<p>I would like to know if there's a simpler way to write the condition of the <code>if</code> statement. Something like <code>item1, item2 == "wood":</code>. I currently have this code:</p> <pre><code>item1 = input("item1: ") item2 = input("item2: ") if item1 == "wood" and item2 == "wood": print("You created a s...
1
2016-09-29T05:19:00Z
39,762,219
<p>You have two ways. you can use "==" for two variables.</p> <pre><code>item1 = input("item1: ") item2 = input("item2: ") if item1 == item2 == "wood": print("You created a stick") </code></pre> <p>And also you can do using a for loop. But for that you have to use a list first.So this would help if you are using...
0
2016-09-29T05:40:07Z
[ "python", "if-statement", "condition", "simplify" ]
plyer accelerometer not implemented error on Android phone
39,761,977
<p>I installed Qpython (Python 2.7) and plyer on may android phone (Samsung Galaxy J5, with accelerometer - without gyroscope). I want to read the accelerometer values. Simply I enter three lines of code on the console:</p> <pre><code>from plyer.facades import Acceleromter acc = Accelerometer() print acc.acceleratio...
0
2016-09-29T05:20:27Z
39,762,284
<p>According to the <a href="https://github.com/kivy/plyer/blob/master/plyer/facades/accelerometer.py" rel="nofollow">documentation</a>, it appears you must first enable the accelerometer. Without doing so, it will throw a <code>NotImplementedError</code> exception as provided in this code:</p> <pre><code>def enable(s...
0
2016-09-29T05:44:42Z
[ "android", "python" ]
How to read binary files in Python using NumPy?
39,762,019
<p>I know how to read binary files in Python using NumPy's <code>np.fromfile()</code> function. The issue I'm faced with is that when I do so, the array has exceedingly large numbers of the order of 10^100 or so, with random <code>nan</code> and <code>inf</code> values. </p> <p>I need to apply machine learning algorit...
-3
2016-09-29T05:23:29Z
39,762,267
<p><strong>EDIT 2</strong></p> <ul> <li><p>Refer this answer: <a href="http://stackoverflow.com/a/11548224/6633975">http://stackoverflow.com/a/11548224/6633975</a></p> <p>It states: <code>NaN</code> can't be stored in an integer array. This is a known limitation of pandas at the moment; I have been waiting for progr...
0
2016-09-29T05:43:18Z
[ "python", "numpy", "machine-learning", "data-mining" ]
How to read binary files in Python using NumPy?
39,762,019
<p>I know how to read binary files in Python using NumPy's <code>np.fromfile()</code> function. The issue I'm faced with is that when I do so, the array has exceedingly large numbers of the order of 10^100 or so, with random <code>nan</code> and <code>inf</code> values. </p> <p>I need to apply machine learning algorit...
-3
2016-09-29T05:23:29Z
39,762,706
<p>If you want to make an image out of a binary file, you need to read it in as integer, not float. Currently, the most common format for images is unsigned 8-bit integers.</p> <p>As an example, let's make an image out of the first 10,000 bytes of /bin/bash:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt...
1
2016-09-29T06:15:20Z
[ "python", "numpy", "machine-learning", "data-mining" ]
What can I use to pass the file argument in the script from the html code to cherrypy function
39,762,027
<p>So what can I do to pass the argument to the function.</p> <pre><code>import os, random, string import cherrypy class StringGenerator(object): @cherrypy.expose def index(self): return """&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; ...
1
2016-09-29T05:23:57Z
39,762,884
<p>Take a look into the file <a href="https://github.com/cherrypy/cherrypy/blob/master/cherrypy/tutorial/tut09_files.py" rel="nofollow">cherrypy files tutorial</a>, but to provide you with a concrete answer, your <code>generate</code> method has to use the <code>file</code> attribute of the <code>file1</code> parameter...
1
2016-09-29T06:27:02Z
[ "python", "cherrypy" ]
Why i am not able to capture screen shot of selectbox items using selenium-python?
39,762,141
<p>I have a select box on my page. I click on it to expand it and all values are displayed. Now i take screenshot, but in screenshot, select box is not expanded. Please check.</p> <p>Code:</p> <pre><code>import unittest from selenium import webdriver import datetime from selenium.webdriver.firefox.firefox_profile imp...
0
2016-09-29T05:33:28Z
39,763,816
<p>With the given situation, it is expected to behave in this way. When you perform save_screenshot on driver object, the driver object is now busy getting the screenshot for you instead of keeping the select menu open. One possible solution is that you launch the save_screenshot method in different thread.</p>
0
2016-09-29T07:17:40Z
[ "python", "selenium" ]
Getting unbound method error?
39,762,188
<p>I tried to run this code below </p> <pre><code>class TestStaticMethod: def foo(): print 'calling static method foo()' foo = staticmethod(foo) class TestClassMethod: def foo(cls): print 'calling class method foo()' print 'foo() is part of class: ', cls.__name__...
0
2016-09-29T05:37:56Z
39,763,110
<p>You shall try the below code by dedenting the <code>foo</code> variable from class <code>TestStaticMethod</code></p> <pre><code>class TestStaticMethod: def foo(): print 'calling static method foo()' foo = staticmethod(foo) tsm = TestStaticMethod() tsm.foo() </code></pre>
0
2016-09-29T06:39:07Z
[ "python" ]