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
recursion Think Python 2 exercise 5.5
39,814,341
<p>This question regarding exercise 5.5 from Think Python 2 has been <a href="https://stackoverflow.com/questions/21048933/understanding-recursion-in-python-2-think-python-exercise-5">asked and answered already</a>, but I still don't understand how this function works. Here's the function in question:</p> <pre><code>d...
1
2016-10-02T06:07:51Z
39,975,543
<p>I've posted a picture explaining this in the following <a href="https://stackoverflow.com/questions/21048933/understanding-recursion-in-python-2-think-python-exercise-5/39974778#39974778">question</a> , for a fast navigation here's my picture : </p> <p><a href="http://i.stack.imgur.com/rIfDL.jpg" rel="nofollow"><im...
1
2016-10-11T10:44:24Z
[ "python", "python-3.x", "recursion" ]
Why is this python web scraping code using requests package not working?
39,814,352
<pre><code>import lxml.html import requests l1=[] headers= {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36'} r = requests.get('http://www.naukri.com/jobs-by-location', headers=headers) html = r.content root = lxml.html.fromstring(html) ...
-2
2016-10-02T06:09:16Z
39,819,409
<p>I tried to achieve the same using Selenium WebDriver, and this also succeeds. When this succeeds from your computer, it might be a problem in one of the used libraries.</p> <pre><code>import selenium.webdriver as driver browser = driver.Chrome() browser.get("http://www.naukri.com/jobs-by-location") links = browser...
-1
2016-10-02T16:57:27Z
[ "python", "python-2.7", "web-scraping", "python-requests" ]
Saving full array as txt in python
39,814,403
<p>I at the moment trying to sample an audio files and store the information from the sampling into to txt file. </p> <p>The sampling is done using the <a href="https://github.com/librosa/librosa" rel="nofollow">librosa</a>. </p> <p>The problem occurs when i save it to a file... The array doesn't get fully saved, I...
1
2016-10-02T06:17:45Z
39,817,377
<p>The argument to <code>np.savetxt</code> should be an array.</p> <p>Add <code>test = np.array(test)</code> before saving the data.</p> <ol> <li>This will give an error if the data can not be converted to an array.</li> <li>You can print, for diagnosis, the shape of the array: <code>print test.shape</code></li> </ol...
0
2016-10-02T13:12:18Z
[ "python", "numpy", "librosa" ]
pandas, apply with args which are dataframe row entries
39,814,416
<p>I have a pandas dataframe 'df' with two columns 'A' and 'B', I have a function with two arguments</p> <pre><code>def myfunction(B, A): # do something here to get the result return result </code></pre> <p>and I would like to apply it row-by-row to df using the 'apply' function</p> <pre><code>df['C'] = df['...
2
2016-10-02T06:19:35Z
39,814,457
<p>I think you need:</p> <pre><code>import pandas as pd df = pd.DataFrame({'A':[1,2,3], 'B':[4,5,6]}) print (df) A B 0 1 4 1 2 5 2 3 6 def myfunction(B, A): #some staff result = B + A # do something here to get the result return result df['C'] = df.apply(lambda x: myf...
3
2016-10-02T06:27:50Z
[ "python", "pandas", "apply", "args" ]
Sorting by value and printing both, key and value properly. PYTHON
39,814,485
<p><strong>Question 1</strong>: How Can I add to dictionary with asking user, I.E. Input ("Write Runners name"), Input ("Write elapsed time!")</p> <p><strong>Question 2</strong>: I would like to make the output like this. Underneath my Code .... Drafts :)</p> <pre><code>import operator </code></pre> <p><strong>Dict...
-2
2016-10-02T06:34:11Z
39,814,767
<p>as mentioned in the python <a href="https://docs.python.org/3/tutorial/datastructures.html#dictionaries" rel="nofollow">doc</a></p> <blockquote> <p>It is best to think of a dictionary as an unordered set of key: value pairs, with the requirement that the keys are unique (within one dictionary)</p> </blockquote> ...
0
2016-10-02T07:20:51Z
[ "python", "sorting", "dictionary" ]
Sorting by value and printing both, key and value properly. PYTHON
39,814,485
<p><strong>Question 1</strong>: How Can I add to dictionary with asking user, I.E. Input ("Write Runners name"), Input ("Write elapsed time!")</p> <p><strong>Question 2</strong>: I would like to make the output like this. Underneath my Code .... Drafts :)</p> <pre><code>import operator </code></pre> <p><strong>Dict...
-2
2016-10-02T06:34:11Z
39,814,899
<p>python3</p> <pre><code>import operator runners = {} for x in range(3): name = input("name: ") elapsed_time = int(input("time: ")) runners[name] = elapsed_time templates = [ "{name} wins! His time is {time}.", "{name} is in second place. His time is {time}", "and {name} is in third place. ...
0
2016-10-02T07:40:29Z
[ "python", "sorting", "dictionary" ]
Sorting by value and printing both, key and value properly. PYTHON
39,814,485
<p><strong>Question 1</strong>: How Can I add to dictionary with asking user, I.E. Input ("Write Runners name"), Input ("Write elapsed time!")</p> <p><strong>Question 2</strong>: I would like to make the output like this. Underneath my Code .... Drafts :)</p> <pre><code>import operator </code></pre> <p><strong>Dict...
-2
2016-10-02T06:34:11Z
39,814,980
<p>Python 2.7</p> <pre><code>runners={} for i in range(3): name=raw_input("Please write the name of Runner!") time_elapsed = float(raw_input("Please write the time you spend!")) runners[name]=time_elapsed position=[] for name, elapsed in sorted(runners.iteritems(), key=lambda elapsed: elapsed[1]): posi...
0
2016-10-02T07:54:09Z
[ "python", "sorting", "dictionary" ]
How do you know when to close a file in python?
39,814,679
<pre><code>from sys import argv from os.path import exists script, from_file, to_file = argv print "Copying from %s to %s" % (from_file, to_file) in_file = open(from_file) indata = in_file.read() print "The input file is %d bytes long" % len(indata) print "Does the output file exist? %r" % exists(to_file) #above ...
0
2016-10-02T07:07:36Z
39,814,903
<p>When to close a file? always - once you are finished working on it. Otherwise it will just hog memory.</p>
0
2016-10-02T07:40:43Z
[ "python" ]
How do you know when to close a file in python?
39,814,679
<pre><code>from sys import argv from os.path import exists script, from_file, to_file = argv print "Copying from %s to %s" % (from_file, to_file) in_file = open(from_file) indata = in_file.read() print "The input file is %d bytes long" % len(indata) print "Does the output file exist? %r" % exists(to_file) #above ...
0
2016-10-02T07:07:36Z
39,815,001
<p>From <a href="https://docs.python.org/3/tutorial/inputoutput.html#methods-of-file-objects" rel="nofollow">methods-of-file-objects</a>. </p> <blockquote> <blockquote> <blockquote> <p>It is good practice to use the with keyword when dealing with file objects. This has the advantage that the file is prope...
3
2016-10-02T07:57:16Z
[ "python" ]
Twisted python to read from kafka and write to elasticsearch
39,814,711
<p>I am new to Twisted, this is my first program.</p> <p>I can not find a way to use the KafkaConsumer from the kafka-python library and use treq to trigger a post request to elasticsearch.</p> <p>I could decompose the problem in small pieces: Create an kafka consumer iterator and read data from it (the topic may be ...
0
2016-10-02T07:12:34Z
39,820,333
<p>I don't use Kafka at all, so I'm not sure if this will work for you. Also, I'm assuming your having trouble running Kafka and treq at the same time. A generic way I deal with iterators in Twisted is to use <code>inlineCallbacks</code> to wait for a result and then do something with that result afterwards.</p> <pre>...
0
2016-10-02T18:37:52Z
[ "python", "asynchronous", "twisted" ]
Cant be connected between two computers in the same Lan with sockets
39,814,726
<p>I have a server-client that work wonderfull when im trying to use them on my own machine. But - when im trying to use them on two different machines on the same Lan, it didnt work! Here is my connection:</p> <pre><code>Lan = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Creates the socket object Lan.connect...
0
2016-10-02T07:14:41Z
39,814,816
<p>When you are binding your socket, it gets bound to certain network interfaces, one of which is the loopback interface which is only available from your local computer. You're likely not binding to your actual network interface controller (NIC)</p> <p>You want INADDR_ANY when you bind, though you didn't say what pr...
1
2016-10-02T07:29:07Z
[ "python", "sockets" ]
Blank Figure in Pyplot
39,814,824
<p>I use the below function, I get the plot shown in the window but the figure saved is blank. </p> <pre><code>import matplotlib.pyplot as plt from sklearn.manifold import TSNE def plot_embeddings(embeddings, names): model = TSNE(n_components=2, random_state=0) vectors = model.fit_transform(embeddings) x, y = vectors...
0
2016-10-02T07:30:02Z
39,822,712
<p>Use <code>savefig()</code> before <code>show()</code> </p> <p><code>show()</code> open window and wait till you close it and maybe when it closes window then it clears image.</p>
1
2016-10-02T23:17:28Z
[ "python", "matplotlib", "plot", "figure" ]
How to install dependencies on different python environment using pyenv
39,814,854
<p>I installed cmus in OSX and I run it with an awesome utility called cmus-osx.py which uses <code>pyobjc</code> and <code>tinytag</code>. It ran perfectly with Python 2.7.11.</p> <p>But I wanted to also run <code>mpsyt</code>, which only works with Python 3, so I installed <code>pyenv</code> in order to be able to r...
0
2016-10-02T07:34:37Z
39,826,108
<p>I would suggest doing some reading on the Python Virtual Environments tool, <a href="https://pypi.python.org/pypi/virtualenv" rel="nofollow">virtualenv</a>, such as the excellent guide <a href="http://docs.python-guide.org/en/latest/dev/virtualenvs/" rel="nofollow">here</a>.</p> <p>Basically the steps are:</p> <pr...
0
2016-10-03T07:04:26Z
[ "python", "osx", "pyobjc", "pyenv" ]
python: convert pandas categorical values to integer when reading csv in chunks
39,814,880
<p>I have large csv file with 1000 columns, column 0 is an id, the other columns are categorical. I would like to convert them to integer values in order to use them for data analysis. First "dummy" way would work if I had enough memory:</p> <pre><code>filename_cat_train = "../input/train_categorical.csv" df = pd.read...
1
2016-10-02T07:38:15Z
39,815,003
<p>In this case, it indeed seems that a two-pass scheme might be effective.</p> <p>Starting with</p> <pre><code>import pandas as pd data=pd.read_csv(my_file_name, chunksize=my_chunk_size) </code></pre> <p>You could do:</p> <pre><code>import collections uniques = collections.defaultdict(list) for chunk in data: ...
1
2016-10-02T07:57:25Z
[ "python", "pandas", "data-conversion" ]
How to set the History input of a RNN/LSTM cell to Zero?
39,815,032
<p>In order to do "Inference" with a trained RNN/LSTM model for sentences one by one. I think I need to set the <strong>History input parameter</strong> of a RNN/LSTM cell to Zero at the beginning of each sentence.</p> <p>So how can it be done in Tensorflow?</p>
0
2016-10-02T08:01:13Z
39,815,124
<p>Based on <a href="http://stackoverflow.com/questions/38441589/tensorflow-rnn-initial-state">this answer</a> I believe that the state is set back to whatever state you pass in with the <code>initial_state</code> argument to <code>tf.nn.rnn</code> (or the other RNN creation functions).</p>
0
2016-10-02T08:15:08Z
[ "python", "machine-learning", "nlp", "tensorflow" ]
Is it possible to capture any traceback generated by a Python application?
39,815,135
<p>I've been searching google for a way to somehow capture any traceback generated by a Python application.</p> <p>I'd like to send an email/slack/notification to myself if <em>any</em> error occurs which generates a traceback (instead of relying on users to report issues to me).</p> <p>I still haven't found anything...
3
2016-10-02T08:17:22Z
39,815,461
<p>You can easily do it by creating custom <a href="https://docs.python.org/2/library/sys.html#sys.excepthook" rel="nofollow"><code>sys.excepthook</code></a>:</p> <pre><code>import sys import traceback def report_exception(exc_type, exc_value, exc_tb): # just a placeholder, you may send an e-mail here print(...
4
2016-10-02T09:04:02Z
[ "python" ]
Matching multiple strings
39,815,214
<p>I am learning Python string operations and trying to convert delimited text into variables.</p> <p>i.e. <code>"On Tap: 20 | Bottles: 957 | Cans: 139"</code></p> <p>This string should assign value of 20 to Tap, 957 to Bottles, and 139 to Cans. This string is not fixed and may vary (for example 3 values or 0, also p...
1
2016-10-02T08:28:58Z
39,815,248
<p><code>find</code> returns <code>-1</code> when it can't find string and <code>-1</code> is treated as <code>True</code> (<code>bool(-1)</code> gives <code>True</code>) so you have to use <code>find(...) != -1</code></p> <pre><code>import re strEx = "On Tap: 20 | Bottles: 957 | Cans: 139" barServingText = strEx.spl...
3
2016-10-02T08:35:27Z
[ "python", "regex" ]
Matching multiple strings
39,815,214
<p>I am learning Python string operations and trying to convert delimited text into variables.</p> <p>i.e. <code>"On Tap: 20 | Bottles: 957 | Cans: 139"</code></p> <p>This string should assign value of 20 to Tap, 957 to Bottles, and 139 to Cans. This string is not fixed and may vary (for example 3 values or 0, also p...
1
2016-10-02T08:28:58Z
39,815,314
<p>The <code>str.find()</code> method is used for returning the location of the text in a string. If it doesn't find the text, it returns the integer -1. In Python, for checking if on string contains another, you may want to use the syntax <code>if subString in string:</code>, like so:</p> <pre><code>... if "Bottl...
1
2016-10-02T08:44:37Z
[ "python", "regex" ]
Matching multiple strings
39,815,214
<p>I am learning Python string operations and trying to convert delimited text into variables.</p> <p>i.e. <code>"On Tap: 20 | Bottles: 957 | Cans: 139"</code></p> <p>This string should assign value of 20 to Tap, 957 to Bottles, and 139 to Cans. This string is not fixed and may vary (for example 3 values or 0, also p...
1
2016-10-02T08:28:58Z
39,815,317
<p>The following regex should create key value pair for you:</p> <pre><code>r"((.*?):(.*?)(\||$))" </code></pre> <p>The following approach however i think is better suited as it would make it dynamic and can have more than these 3 variables</p> <pre><code> import re regex = ur"((.*?):(.*?)(\||$))" test_str...
5
2016-10-02T08:45:06Z
[ "python", "regex" ]
Defining columns in numpy array - TypeError: invalid type promotion
39,815,321
<p>I am defining an array which should look like this </p> <pre><code>['word1', 2000, 21] ['word2', 2002, 33] ['word3', 1988, 51] ['word4', 1999, 26] ['word5', 2001, 72] </code></pre> <p>However when I append an a new entry I get a TypeError. </p> <pre><code>import numpy as np npdtype = [('word', 'S35'), ('year', i...
1
2016-10-02T08:45:31Z
39,816,733
<p><code>append</code> is a way of calling <code>np.concatenate</code>. Look at its code. Note it has to make sure the 2nd argument is an array. It does that without knowledge of your special <code>dtype</code>. Try that. It probably produces a string dtype. Then it tries the concatenate. So you need to make an ar...
1
2016-10-02T11:54:17Z
[ "python", "numpy" ]
Defining columns in numpy array - TypeError: invalid type promotion
39,815,321
<p>I am defining an array which should look like this </p> <pre><code>['word1', 2000, 21] ['word2', 2002, 33] ['word3', 1988, 51] ['word4', 1999, 26] ['word5', 2001, 72] </code></pre> <p>However when I append an a new entry I get a TypeError. </p> <pre><code>import numpy as np npdtype = [('word', 'S35'), ('year', i...
1
2016-10-02T08:45:31Z
39,818,557
<p>Follow @hpaulj's advice and then tidy up.</p> <pre><code>import numpy as np npdtype = [('word', 'S35'), ('year', np.int16), ('wordcount', np.int16)] np_array = np.empty((0,3), dtype=npdtype) word = 'word1' year = '2001' word_count = '21' column = np.array( [b'word1', np.int16(year), np.int16(word_count)], dtype=...
0
2016-10-02T15:29:19Z
[ "python", "numpy" ]
PyQt - Pass number variable between windows
39,815,331
<p>I create 2 windows testWidget and win2. First in testWidget, I click "Input maesure data " in Start menu, then I want to input number in LineEdit of L1(m) in win2, press "Analyze" and shows it in the testWidget. I did it, but it will pop up testWidget again. How to solve it?</p> <p>Thanks!</p> <pre><code>import sy...
1
2016-10-02T08:47:12Z
39,818,338
<p>You need to set a global variable for acessing.</p> <pre><code>GUI = None if __name__ == '__main__': app = QtGui.QApplication(sys.argv) GUI = testWidget() GUI.show() app.exec_() </code></pre> <p>And, let the subwindow pass value to the GUI.</p> <pre><code>def getre(self): text_LT = self.line1....
1
2016-10-02T15:06:11Z
[ "python", "class", "pyqt4" ]
Jupyter, AttributeError: type object 'Widget' has no attribute 'observe'
39,815,515
<p>I tried to use observe for my toggleButton </p> <pre><code>wtarget = widgets.ToggleButtons( description='select target', options=['A', 'B', 'C', 'D', 'E', 'F']) wtarget.observe(target_on_value_change, names='value') </code></pre> <p>It displayed this error:</p> <pre><code>AttributeError: 'ToggleButtons'...
0
2016-10-02T09:11:50Z
39,828,971
<p>This suggests that you have an old version of traitlets. <code>.observe</code> was added in traitlets 4.1:</p> <pre><code>pip install --upgrade traitlets </code></pre> <p>You may want to upgrade more than that:</p> <pre><code>pip install --upgrade ipywidgets </code></pre>
0
2016-10-03T09:59:09Z
[ "python", "ipython", "jupyter" ]
Add up all posibilities in a list, with two variables
39,815,551
<p>I am trying to make a program in python that will accept a user's input and check if it is a Kaprekar number. I'm still a beginner, and have been having a lot of issues, but my main issue now that I can't seem to solve is how I would add up all posibilities in a list, with only two variables. I'm probably not explan...
2
2016-10-02T09:17:40Z
39,815,584
<p>Say you start with</p> <pre><code>a = ['2', '0', '2', '5'] </code></pre> <p>Then you can run</p> <pre><code>&gt;&gt;&gt; [(a[: i], a[i: ]) for i in range(1, len(a))] [(['2'], ['0', '2', '5']), (['2', '0'], ['2', '5']), (['2', '0', '2'], ['5'])] </code></pre> <p>to obtain all the possible contiguous splits. </p>...
2
2016-10-02T09:23:17Z
[ "python", "list", "add" ]
Add up all posibilities in a list, with two variables
39,815,551
<p>I am trying to make a program in python that will accept a user's input and check if it is a Kaprekar number. I'm still a beginner, and have been having a lot of issues, but my main issue now that I can't seem to solve is how I would add up all posibilities in a list, with only two variables. I'm probably not explan...
2
2016-10-02T09:17:40Z
39,817,800
<p>Not a direct answer to your question, but you can write an expression to determine whether a number, N, is a Krapekar number more concisely.</p> <pre><code>&gt;&gt;&gt; N=45 &gt;&gt;&gt; digits=str(N**2) &gt;&gt;&gt; Krapekar=any([N==int(digits[:_])+int(digits[_:]) for _ in range(1,len(digits))]) &gt;&gt;&gt; Krape...
0
2016-10-02T14:05:17Z
[ "python", "list", "add" ]
Sort Excel file by column name containing string and integer
39,815,597
<p>I want to sort this Excel file using the second column that is Target. The Target column has data in the form of string and integer</p> <p><a href="http://i.stack.imgur.com/adjkY.png" rel="nofollow"><img src="http://i.stack.imgur.com/adjkY.png" alt="enter image description here"></a></p> <p>When I do a sort on the...
0
2016-10-02T09:25:28Z
39,815,713
<p>It seems you are looking for <a href="https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/" rel="nofollow">human sorting</a>. You can handle this type of problem using regular expressions in Python. </p> <p>As explained in the attached article:</p> <pre><code>import re def sort_nicely( l ): """...
0
2016-10-02T09:42:52Z
[ "python", "pandas" ]
Python Pandas - Index' object has no attribute 'hour'
39,815,625
<p>I have a pandas dateframe and the following code works</p> <pre><code>df['hour'] = df.index.hour df['c'] = df['hour'].apply(circadian) </code></pre> <p>but i was trying to reduce the need to make a 'hour' coloumn, using the following code</p> <pre><code>df['c'] = df.apply(lambda x: circadian(x.index.hour), axis=1...
0
2016-10-02T09:28:59Z
39,816,612
<p><strong>Approach 1:</strong> </p> <p>Convert the <code>DateTimeIndex</code> to <code>Series</code> and use <code>apply</code>.</p> <pre><code>df['c'] = df.index.to_series().apply(lambda x: circadian(x.hour)) </code></pre> <p><strong>Approach 2:</strong></p> <p>Use <code>axis=0</code> which computes along the r...
2
2016-10-02T11:40:33Z
[ "python", "pandas", "apply" ]
Python Pandas - Index' object has no attribute 'hour'
39,815,625
<p>I have a pandas dateframe and the following code works</p> <pre><code>df['hour'] = df.index.hour df['c'] = df['hour'].apply(circadian) </code></pre> <p>but i was trying to reduce the need to make a 'hour' coloumn, using the following code</p> <pre><code>df['c'] = df.apply(lambda x: circadian(x.index.hour), axis=1...
0
2016-10-02T09:28:59Z
39,818,351
<p><strong><em>solution</em></strong><br> use the datetime accessor <code>dt</code></p> <pre><code>df['c'] = df.index.to_series().dt.hour.apply(circadian) </code></pre>
1
2016-10-02T15:07:26Z
[ "python", "pandas", "apply" ]
I have get really confused in IP types with sockets (empty string, 'local host', etc...)
39,815,633
<p>Im using python. I dont understand the purpose of empty string in IP to connect to if its not to connect between two Computers in the same LAN router.</p> <p>My knowledge in network is close to zero, so when I reading in the internet somthing like this:</p> <blockquote> <p>empty string represents INADDR_ANY, and...
1
2016-10-02T09:30:06Z
39,815,976
<p><code>'localhost'</code> (or <code>'127.0.0.1'</code>) is use to connect with program on the same computer - ie. database viewer &lt;-> local database server, Doom client &lt;-> local Doom server. This way you don't have to write different method to connect to local server. </p> <p>Computer can have more then one n...
0
2016-10-02T10:19:20Z
[ "python", "sockets" ]
Django calculation with many TimeFields
39,815,638
<p>I'm working on a webapp, which should calculate with several <code>TimeField</code> objects. No I stuck at one point. How is it possible to add different <code>TimeFields</code> together and subtract a <code>DecimalField</code> from the outcome <code>TimeField</code>. I've tried different ways. For example to conver...
0
2016-10-02T09:30:23Z
39,815,718
<p>What are you <em>actually</em> trying to do? :) I'll have to guess to begin with...</p> <p>Remember <code>TimeField</code>s carry <code>datetime.time</code> objects, which are "clock time", i.e. from midnight to midnight. I'm assuming you want to convert them to a form that you can handle arithmetically -- seconds ...
0
2016-10-02T09:43:25Z
[ "python", "django" ]
Pandas: append dataframe to another df
39,815,646
<p>I have a problem with appending of dataframe. I try to execute this code</p> <pre><code>df_all = pd.read_csv('data.csv', error_bad_lines=False, chunksize=1000000) urls = pd.read_excel('url_june.xlsx') substr = urls.url.values.tolist() df_res = pd.DataFrame() for df in df_all: for i in substr: res = df[d...
2
2016-10-02T09:31:18Z
39,815,686
<p>If you look at <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.append.html" rel="nofollow">the documentation for <code>pd.DataFrame.append</code></a></p> <blockquote> <p>Append rows of other to the end of this frame, <strong>returning a new object</strong>. Columns not in this fram...
2
2016-10-02T09:36:14Z
[ "python", "pandas" ]
Python Flask: Sending a form class argument from another function to prepopulate default
39,815,647
<p>I need to prepopulate form fields with database (dataset) values. The problem is that I don't know how to send the argument to the form class.</p> <p><strong>forms.py</strong></p> <pre><code># coding: utf-8 from db import produtosalca as produtos ##dataset imports db['table'] from flask_wtf import FlaskForm from w...
1
2016-10-02T09:31:23Z
39,816,039
<p>Note that <code>class ProductForm(FlaskForm)</code> means ProductForm inherets from FlaskForm. A simple solution for your case would be as follows:</p> <p><strong>forms.py:</strong></p> <pre><code>from flask_wtf import FlaskForm from wtforms import TextField class ProductForm(FlaskForm): descricao = TextFiel...
-2
2016-10-02T10:27:24Z
[ "python", "forms", "flask", "arguments", "flask-wtforms" ]
How else part work in continue statement?
39,815,695
<p>I'm not sure how the <code>continue</code> statement is interpreted when it is inside a <code>for</code> loop with an <code>else</code> clause.</p> <p>If the condition is true, the <code>break</code> will exit from a <code>for</code> loop and <code>else</code> part will not be executed. And if the condition is Fals...
4
2016-10-02T09:38:00Z
39,815,739
<p>Your <code>else</code> part will be executed in both cases. <code>else</code> part executed when loop terminate when condition didn't found.Which is what is happening in your code. But it will also work same without <code>continue</code> statement.</p> <p>now what about break statement's else part, Break statement...
3
2016-10-02T09:45:47Z
[ "python", "for-loop", "for-else" ]
How else part work in continue statement?
39,815,695
<p>I'm not sure how the <code>continue</code> statement is interpreted when it is inside a <code>for</code> loop with an <code>else</code> clause.</p> <p>If the condition is true, the <code>break</code> will exit from a <code>for</code> loop and <code>else</code> part will not be executed. And if the condition is Fals...
4
2016-10-02T09:38:00Z
39,815,753
<p>With a <code>for</code> loop in Python, the <code>else</code> block is executed when the loop finishes normally, i.e. there is no <code>break</code> statement. A <code>continue</code> does not affect it either way.</p> <p>If the for loop ends because of a <code>break</code> statement, then <code>else</code> block w...
4
2016-10-02T09:47:38Z
[ "python", "for-loop", "for-else" ]
Raspberry crontab python script at boot
39,815,791
<p>I've been trying to launch a python script at the boot of the Rpi, but everything I've tried until now did not work.</p> <p>The script is some version of this : <a href="https://www.raspberrypi.org/learning/temperature-log/worksheet/" rel="nofollow">https://www.raspberrypi.org/learning/temperature-log/worksheet/</a...
1
2016-10-02T09:55:15Z
39,815,861
<p>You can call your script in the <code>~/.bashrc</code> file. It will be called at boot or terminal opening.</p> <p>Just write :</p> <pre><code>python /path/to/your/script.py </code></pre> <p>At the end of the .bashrc file.</p>
-1
2016-10-02T10:04:08Z
[ "python", "raspberry-pi", "crontab", "boot" ]
Raspberry crontab python script at boot
39,815,791
<p>I've been trying to launch a python script at the boot of the Rpi, but everything I've tried until now did not work.</p> <p>The script is some version of this : <a href="https://www.raspberrypi.org/learning/temperature-log/worksheet/" rel="nofollow">https://www.raspberrypi.org/learning/temperature-log/worksheet/</a...
1
2016-10-02T09:55:15Z
39,815,871
<pre><code>sudo crontab -e @reboot /usr/bin/python /path/to/file/script.py </code></pre> <p><code>/path/to/file/script.py</code> would probably be something like <code>/home/username/script.py</code></p> <p>If it still doesn't work you can try giving it execute permission with this:</p> <pre><code>chmod a+x script....
0
2016-10-02T10:05:16Z
[ "python", "raspberry-pi", "crontab", "boot" ]
Raspberry crontab python script at boot
39,815,791
<p>I've been trying to launch a python script at the boot of the Rpi, but everything I've tried until now did not work.</p> <p>The script is some version of this : <a href="https://www.raspberrypi.org/learning/temperature-log/worksheet/" rel="nofollow">https://www.raspberrypi.org/learning/temperature-log/worksheet/</a...
1
2016-10-02T09:55:15Z
39,815,875
<p>If your script is located at <code>/home/pi/tempcheck.py</code> the you should edit crontab with </p> <pre><code>sudo crontab -e </code></pre> <p>and append the line</p> <pre><code>@reboot python /home/pi/tempcheck.py &amp; </code></pre> <p>then save and exit.</p> <p>Further details can be found at <a href="htt...
1
2016-10-02T10:05:29Z
[ "python", "raspberry-pi", "crontab", "boot" ]
XMLRPC - wp.newPost with custom post type and custom fields
39,815,857
<p>I'm trying to add new posts over XMLRPC, but for some reason I cannot add custom fields (other content like title and description works).</p> <p>Pseudo code that I use:</p> <pre><code>from xmlrpc import client user = 'admin' passwd = 'pass' server = client.ServerProxy('http://domain.tld/xmlrpc.php') blog_id = 0 c...
0
2016-10-02T10:03:44Z
39,834,301
<p>Try using:</p> <pre><code>custom_fields = {} custom_fields.update( {'my_meta_key': 123} </code></pre> <p>)</p>
0
2016-10-03T14:42:31Z
[ "python", "wordpress", "xml-rpc" ]
XMLRPC - wp.newPost with custom post type and custom fields
39,815,857
<p>I'm trying to add new posts over XMLRPC, but for some reason I cannot add custom fields (other content like title and description works).</p> <p>Pseudo code that I use:</p> <pre><code>from xmlrpc import client user = 'admin' passwd = 'pass' server = client.ServerProxy('http://domain.tld/xmlrpc.php') blog_id = 0 c...
0
2016-10-02T10:03:44Z
39,862,816
<p>Problem is with naming of meta keys. I name them with underscore, like <code>_my_meta_key</code>, which means they are protected for the API.</p>
0
2016-10-04T22:36:46Z
[ "python", "wordpress", "xml-rpc" ]
How efficient is list.index(value, start, end)?
39,815,879
<p>Today I realized that python's <code>list.index</code> can also take an optional <code>start</code> (and even <code>end</code>) parameter.</p> <p>I was wondering whether or not this is efficiently implemented and which of these two is better:</p> <pre><code>pattern = "qwertyuytresdftyuioknn" words_list = ['queen',...
0
2016-10-02T10:05:50Z
39,816,050
<p>This calls a built-in function implemented in C:</p> <pre><code>i = pattern.index(character, i) </code></pre> <p>Even without looking at the <a href="https://hg.python.org/cpython/file/v3.5.2/Objects/listobject.c#l2147" rel="nofollow">source code</a>, you can always assume that the underlying implementation is sma...
3
2016-10-02T10:29:07Z
[ "python", "list", "indexof" ]
how to create date wizard in odoo 8
39,815,895
<p>I am trying to create a wizard to streamline my search. I have created the report and xml and it works fine. However when I try to do the search it brings all the payslip of all the months not the months I selected. I hence, tried to use a wizard to filter my search. This has been given my issues.</p> <p>My wizard ...
0
2016-10-02T10:08:05Z
39,816,028
<p>Odoo expects a dict and it found a list for <code>form</code> variable (<code>read</code> function returns a list of dicts), you need to change: </p> <pre><code>'form': data </code></pre> <p>To: </p> <pre><code>'form': data[0] </code></pre>
0
2016-10-02T10:25:42Z
[ "python", "python-2.7", "openerp", "odoo-8" ]
Python - Extract strings from a log file and write them into another file
39,816,094
<p>I've got a log file like below:</p> <pre><code>sw2 switch_has sw2_p3. sw1 transmits sw2_p2 /* BUG: axiom too complex: SubClassOf(ObjectOneOf([NamedIndividual(#t_air_sens2)]),DataHasValue(DataProperty(#qos_type),^^(latency,http://www.xcx.org/1900/02/22-rdf-syntax-ns#PlainLiteral))) */ /* BUG: axiom too complex: SubC...
0
2016-10-02T10:35:20Z
39,816,303
<p>You can of course use regex. I would read line by line, grab the lines the start with <code>'/* BUG:'</code>, then parse those as needed.</p> <pre><code>import re target = r'/* BUG:' bugs = [] with open('logfile.txt', 'r') as infile, open('output.txt', 'w') as outfile: # loop through logfile for line in in...
1
2016-10-02T11:00:23Z
[ "python", "file" ]
How to get a list of two different elements with their parents being the same
39,816,139
<p>As an exercise I am trying to <strong>print</strong> all the titles of posts with more than 200 comments from the site reddit.com.</p> <p>What I tried:</p> <pre><code>import requests from bs4 import BeautifulSoup url1 = "https://www.reddit.com/" headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10...
0
2016-10-02T10:39:23Z
39,817,799
<p>Instead of saving it first to lists and hoping that both lists would match up (list1[0]~~list2[0])....I tried to find the most common denominator (parent) and applied the class selection (beautifulsoup) a second time to delve further down the dom (children) and printing it instantly. While scraping a heavily used we...
0
2016-10-02T14:05:09Z
[ "python", "web-scraping", "beautifulsoup" ]
How to make an One-Liner list with multiple variables in Python?
39,816,176
<p>I was interested whether I can define <em>ascii_combinations</em> list in one line and not using the loop I used in the following example...</p> <pre><code>ascii_printable = [chr(count) for count in range(32, 127)] ascii_combinations = [] for x1 in ascii_printable: for x2 in ascii_printable: for x3 in ...
1
2016-10-02T10:43:31Z
39,816,258
<p>Since you want to create a cartesian product, standard way to do so is using <code>itertools.product</code>.</p> <pre><code>import itertools ascii_printable = [chr(count) for count in range(32, 127)] ascii_combinations = [x1+x2+x3 for x1, x2, x3 in itertools.product(ascii_printable, repeat=3)] </code></pre>
3
2016-10-02T10:55:09Z
[ "python" ]
How to make an One-Liner list with multiple variables in Python?
39,816,176
<p>I was interested whether I can define <em>ascii_combinations</em> list in one line and not using the loop I used in the following example...</p> <pre><code>ascii_printable = [chr(count) for count in range(32, 127)] ascii_combinations = [] for x1 in ascii_printable: for x2 in ascii_printable: for x3 in ...
1
2016-10-02T10:43:31Z
39,816,289
<p>You might use <code>itertools.product</code> as</p> <pre><code>from itertools import product ascii_printable = [chr(count) for count in range(32, 127)] ascii_combinations = [x1 + x2 + x3 for x1, x2, x3 in product(ascii_printable, repeat=3)] </code></pre> <p>Also <code>chr(count) for count in range(32, 127)</code>...
2
2016-10-02T10:59:00Z
[ "python" ]
How to make an One-Liner list with multiple variables in Python?
39,816,176
<p>I was interested whether I can define <em>ascii_combinations</em> list in one line and not using the loop I used in the following example...</p> <pre><code>ascii_printable = [chr(count) for count in range(32, 127)] ascii_combinations = [] for x1 in ascii_printable: for x2 in ascii_printable: for x3 in ...
1
2016-10-02T10:43:31Z
39,816,291
<p>This results in True:</p> <pre><code>ascii_printable = [chr(count) for count in range(32, 127)] ascii_combinations = [] for x1 in ascii_printable: for x2 in ascii_printable: for x3 in ascii_printable: ascii_combinations.append(x1 + x2 + x3) test = [x1+x2+x3 for x1 in ascii_printable for x2...
0
2016-10-02T10:59:30Z
[ "python" ]
Call a function with a single character in Python
39,816,327
<p>If I have a function that computes the factorial of a number, is there any way that this function can be called with the character '!' ?</p> <p>Essentially, I would like to type</p> <pre><code>In [1]: 5! </code></pre> <p>and receive:</p> <pre><code>120 </code></pre> <p>I am using Python 3.5 with the Spyder IDE....
0
2016-10-02T11:03:13Z
39,816,744
<p>You can try something like this:</p> <pre><code>from math import factorial input_string = "5!" def is_int(input_string): try: int(input_string[:-1]) return True except ValueError: return False if input_string[-1] == "!" and is_int(input_string): print(factorial(int(input_string[:-1]))) </code></pre> <p...
0
2016-10-02T11:55:45Z
[ "python", "function", "spyder" ]
spacing for triangle pattern in python
39,816,382
<p>The following code prints a pattern but I have problem with spacing. I want to print it in a triangle fashion </p> <pre><code>def triangle(n): s = "" for i in range(0,n): s += "{}".format((i+1)%10) j=s*1 print( s,'*1=',j) triangle(9) </code></pre> <p>This is the output I get<...
0
2016-10-02T11:10:47Z
39,816,497
<p>If you meen this</p> <pre><code> 1 * 1 = 1 12 * 1 = 12 123 * 1 = 123 1234 * 1 = 1234 12345 * 1 = 12345 123456 * 1 = 123456 1234567 * 1 = 1234567 12345678 * 1 = 12345678 123456789 * 1 = 123456789 </code></pre> <p>then you need ie. <code>{:9s}</code> (for <code>string</cod...
3
2016-10-02T11:25:56Z
[ "python", "string-formatting" ]
Complex workflow on Celery
39,816,433
<p>I am trying to build a workflow basing on Celery. I use groups and chords.</p> <p>In the example below there are independent groups ([mytask1, mytask1, mytask1, ..] -> myfinaltask1) where <code>mytask1</code> might be executed in parallel, but <code>myfinaltask1</code> should be called after each group.</p> <p>Cod...
5
2016-10-02T11:17:57Z
39,817,066
<p>It seems you've forgot to wrap <code>subtasks</code> to <code>group</code>.</p> <pre><code>def func1(date): subtasks = [] for filepath in all_files: kwargs = {'date': date, 'hfile': filepath} subtask = mytask1.subtask(kwargs=kwargs) subtasks.append(subtask) chrd = chord(header=g...
1
2016-10-02T12:36:35Z
[ "python", "celery" ]
Python and time / datetime
39,816,500
<p>I've recently began work on a Python program as seen in the fragment below.</p> <pre><code># General Variables running = False new = True timeStart = 0.0 timeElapsed = 0.0 def endProg(): curses.nocbreak() stdscr.keypad(False) curses.echo() curses.endwin() quit() # Draw def draw(): stdscr.a...
-1
2016-10-02T11:26:10Z
39,816,608
<p>Using ˋtime.time`:</p> <pre><code>import time star = time.time() # run long processing... elapsed = time.time() - start </code></pre> <p>Et voilà !</p>
0
2016-10-02T11:39:45Z
[ "python", "datetime", "time", "timer" ]
Python and time / datetime
39,816,500
<p>I've recently began work on a Python program as seen in the fragment below.</p> <pre><code># General Variables running = False new = True timeStart = 0.0 timeElapsed = 0.0 def endProg(): curses.nocbreak() stdscr.keypad(False) curses.echo() curses.endwin() quit() # Draw def draw(): stdscr.a...
-1
2016-10-02T11:26:10Z
39,816,950
<pre><code>def draw(): stdscr.border() if running: stdscr.addstr(1, 1, "&gt;", curses.color_pair(8)) stdscr.addstr(1, 3, t.strftime( "%H:%M.%S", t.gmtime( timeElapsed ) ) ) if not running: stdscr.addstr(1, 1, "&gt;", curses.color_pair(7)) stdscr.redrawwin() stdscr.refresh()...
0
2016-10-02T12:22:16Z
[ "python", "datetime", "time", "timer" ]
Run remote python code via ssh with uninstalled modules
39,816,564
<p>I wish to connect to a Linux machine by ssh (from my code) and run some code that is using python libraries that are not installed on the remote machine, what would be the best way to do so?</p> <p>using a call like this:</p> <pre><code>cat main.py | ssh user@server python - </code></pre> <p>will run main.py on t...
0
2016-10-02T11:34:17Z
39,816,650
<p>Try <a href="https://virtualenv.pypa.io/en/stable/" rel="nofollow">virtualenv</a>:</p> <pre><code>pip install virtualenv </code></pre> <p>then use</p> <pre><code>virtualenv venv </code></pre> <p>to create a seperated python environment in current path(in folder <code>venv</code>).</p> <p>Instead of installing m...
0
2016-10-02T11:44:38Z
[ "python", "linux", "ssh" ]
How can I get data from Goodreads and use it in Telegram Bot API
39,816,636
<p>I've come up with an idea of writing an inline telegram bot and use a Goodreads API for this. But I don't know how to properly extract a book info from Goodreads and put it into special fields in bot api request. I will be so much grateful for helping me with this issue! :)</p>
0
2016-10-02T11:43:20Z
39,984,067
<p>It should be pretty easy, just consume API, store data in the memory, and use it when you need it.</p> <p>Here is example with Node.js: <a href="https://github.com/ro31337/exbot" rel="nofollow">https://github.com/ro31337/exbot</a></p> <p>This app is using API feed to fetch data. You can see how it works by adding ...
0
2016-10-11T18:21:35Z
[ "python", "python-3.x", "telegram", "telegram-bot", "python-telegram-bot" ]
Pandas populate new dataframe column based on matching columns in another dataframe
39,816,671
<p>I have a <code>df</code> which contains my main data which has one million <code>rows</code>. My main data also has 30 <code>columns</code>. Now I want to add another column to my <code>df</code> called <code>category</code>. The <code>category</code> is a <code>column</code> in <code>df2</code> which contains aroun...
2
2016-10-02T11:47:03Z
39,816,998
<p><strong>APPROACH 1:</strong></p> <p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> instead and drop the duplicated values present in both <code>Index</code> and <code>AUTHOR_NAME</code> columns combined. After that, use <a href...
1
2016-10-02T12:27:53Z
[ "python", "pandas", "merge", "populate" ]
Pandas populate new dataframe column based on matching columns in another dataframe
39,816,671
<p>I have a <code>df</code> which contains my main data which has one million <code>rows</code>. My main data also has 30 <code>columns</code>. Now I want to add another column to my <code>df</code> called <code>category</code>. The <code>category</code> is a <code>column</code> in <code>df2</code> which contains aroun...
2
2016-10-02T11:47:03Z
39,818,193
<p>see <a class='doc-link' href="http://stackoverflow.com/documentation/pandas/1966/merge-join-and-concatenate/23978/what-is-the-difference-between-join-and-merge#t=201610021451405843568">What is the difference between join and merge</a></p> <p>consider the following dataframes <code>df</code> and <code>df2</code></p>...
1
2016-10-02T14:50:21Z
[ "python", "pandas", "merge", "populate" ]
Is there a way to remove too many if else conditions?
39,816,697
<p>I am currently making an interactive system using python, that is able to understand and reply. Hence for this there are lots of conditions for machine to analyze and process. For eg. take the following code(for reference only):</p> <pre><code> if ('goodbye') in message: rand = ...
-2
2016-10-02T11:50:02Z
39,816,814
<p><code>if/elif/else</code> is a natural way to structure this kind of code in Python. As @imant noted, you may use dict-based approach in case of simple branching, but I see some mildly complex logic in your <code>if</code> predicates, so you'll have to check all predicates in any case and you won't have any performa...
0
2016-10-02T12:05:32Z
[ "python" ]
Is there a way to remove too many if else conditions?
39,816,697
<p>I am currently making an interactive system using python, that is able to understand and reply. Hence for this there are lots of conditions for machine to analyze and process. For eg. take the following code(for reference only):</p> <pre><code> if ('goodbye') in message: rand = ...
-2
2016-10-02T11:50:02Z
39,816,833
<p>Firstly create a <code>dict</code> object with the key as <code>tuple</code> of string you want to match in your <code>message</code> and associate it with the value <code>string</code> which your Jarvis is suppose to respond. For example:</p> <pre><code>jarvis_dict = { ('goodbye',) : ['Goodbye Sir', 'Jarvis p...
0
2016-10-02T12:08:09Z
[ "python" ]
Is there a way to remove too many if else conditions?
39,816,697
<p>I am currently making an interactive system using python, that is able to understand and reply. Hence for this there are lots of conditions for machine to analyze and process. For eg. take the following code(for reference only):</p> <pre><code> if ('goodbye') in message: rand = ...
-2
2016-10-02T11:50:02Z
39,816,853
<p>Use dictionary:</p> <pre><code>someCollections = { 'goodbye': "Something1", 'hello': "Somthing2", ... } speekmodule(someCollections [SomeKey],...) </code></pre>
0
2016-10-02T12:10:01Z
[ "python" ]
Is there a way to remove too many if else conditions?
39,816,697
<p>I am currently making an interactive system using python, that is able to understand and reply. Hence for this there are lots of conditions for machine to analyze and process. For eg. take the following code(for reference only):</p> <pre><code> if ('goodbye') in message: rand = ...
-2
2016-10-02T11:50:02Z
39,816,902
<p>Make a exclusive "if":</p> <pre><code>if 'goodbye' in message: rand = ['Goodbye Sir', 'Jarvis powering off in 3, 2, 1, 0'] elif 'hello' in message or 'hi' in message: rand = ['Wellcome to Jarvis virtual intelligence project. At your service sir.'] elif 'thanks' in message or 'tan...
1
2016-10-02T12:16:21Z
[ "python" ]
Error installing MySQL-python: Unable to find vcvarsall.bat
39,816,780
<p>I was trying to install <code>mysql-python</code> using <strong>pip</strong><br> I'm getting the following error: </p> <pre><code>error: Unable to find vcvarsall.bat ---------------------------------------- Failed building wheel for mysql-python ... ... running build_ext building '_mysql' extension error...
1
2016-10-02T12:01:01Z
39,850,868
<p>First check your Python installation &amp; Windows 10 Installation [i.e. Is it 32Bit or 64Bit].</p> <h1>Visual C++ Redistributable comes with x86 as well x64 make sure you have installed compatible package.</h1>
0
2016-10-04T11:16:19Z
[ "python", "mysql", "windows" ]
How to add a specific number of characters to the end of string in Pandas?
39,816,795
<p>I am using the Pandas library within Python and I am trying to increase the length of a column with text in it to all be the same length. I am trying to do this by adding a specific character (this will be white space normally, in this example I will use "_") a number of times until it reaches the maximum length of ...
3
2016-10-02T12:03:14Z
39,816,915
<p>It isn't the most pandas-like solution, but you can try the following:</p> <pre><code>col = np.array(["A", "B", "A1R", "B2", "AABB4"]) data = pd.DataFrame(col, columns=["Before"]) </code></pre> <p>Now compute the maximum length, the list of individual lengths, and the differences:</p> <pre><code>max_ = data.Befor...
2
2016-10-02T12:17:36Z
[ "python", "pandas", "dataframe", "string-length", "maxlength" ]
How to add a specific number of characters to the end of string in Pandas?
39,816,795
<p>I am using the Pandas library within Python and I am trying to increase the length of a column with text in it to all be the same length. I am trying to do this by adding a specific character (this will be white space normally, in this example I will use "_") a number of times until it reaches the maximum length of ...
3
2016-10-02T12:03:14Z
39,817,006
<p>Without creating extra columns:</p> <pre><code>In [63]: data Out[63]: Col1 0 A 1 B 2 A1R 3 B2 4 AABB4 In [64]: max_length = data.Col1.map(len).max() In [65]: data.Col1 = data.Col1.apply(lambda x: x + '_'*(max_length - len(x))) In [66]: data Out[66]: Col1 0 A____ 1 B____ 2 A1R__ 3 ...
2
2016-10-02T12:29:08Z
[ "python", "pandas", "dataframe", "string-length", "maxlength" ]
How to add a specific number of characters to the end of string in Pandas?
39,816,795
<p>I am using the Pandas library within Python and I am trying to increase the length of a column with text in it to all be the same length. I am trying to do this by adding a specific character (this will be white space normally, in this example I will use "_") a number of times until it reaches the maximum length of ...
3
2016-10-02T12:03:14Z
39,818,021
<p>consider the <code>pd.Series</code> <code>s</code></p> <pre><code>s = pd.Series(['A', 'B', 'A1R', 'B2', 'AABB4']) </code></pre> <p><strong><em>solution</em></strong><br> use <code>str.ljust</code></p> <pre><code>m = s.str.len().max() s.str.ljust(m, '_') 0 A____ 1 B____ 2 A1R__ 3 B2___ 4 AABB4 dtyp...
6
2016-10-02T14:31:05Z
[ "python", "pandas", "dataframe", "string-length", "maxlength" ]
Unable to launch specific module properly
39,816,911
<p>I am installing <a href="https://github.com/GTB3NW/SteamTradingServices" rel="nofollow">specific module</a> from Github, but i am having problems using it's functions.</p> <p>These are steps i took to install module:</p> <ol> <li>Downloaded the zip file and unzipped it normally.</li> <li>Launched <code>setup.py</c...
0
2016-10-02T12:16:52Z
39,817,576
<p>Fixed the problem, Thanks to @metatoaster.</p> <p>The entry of module, is <code>main</code> function from <code>exchange.py</code>, after calling it, module will be started.</p> <p>So to start application, you need to import <code>exchange.py</code> from Exchange package, and from <code>exchange.py</code>, import ...
0
2016-10-02T13:37:39Z
[ "python" ]
count words of different classes separately in a text file
39,816,922
<p>I have some text files in Persian. each file contains a lot of sentences, each in a new line. And in front of each sentence there is a tab, then a word, then a tab and then an English word. These English words in some files are 2, in some are 3, in some are 5 and in some other, are more or less. Actually, they show ...
1
2016-10-02T12:19:06Z
39,817,002
<p>Try to formulate your algorithm on paper then convert it to Python: I'm sure you'll find your solution by yourself.</p> <p>If you encounter problems or errors, post your question here, we will be happy to help.</p> <p>An advice: </p> <ul> <li>You can use ˋcsv` module to read your file. Look for some tutorial wit...
0
2016-10-02T12:28:26Z
[ "python", "nlp" ]
count words of different classes separately in a text file
39,816,922
<p>I have some text files in Persian. each file contains a lot of sentences, each in a new line. And in front of each sentence there is a tab, then a word, then a tab and then an English word. These English words in some files are 2, in some are 3, in some are 5 and in some other, are more or less. Actually, they show ...
1
2016-10-02T12:19:06Z
39,817,109
<p>If I get you correctly then the next code might work. Please note, that I use Python 3.x.</p> <pre><code>from collections import Counter counter = Counter() with open(filename, encoding='utf-8') as f: for line in f: *persian_words, word_class = line.strip().split() counter[word_class] += le...
0
2016-10-02T12:40:55Z
[ "python", "nlp" ]
Cannot get HTML to display SQLite3 data with python & flask
39,816,944
<p>I'm having an issue getting an HTML page to display my SQLite3 data using Python &amp; Flask. I found a question on here and used the same code, plus different variations to no success. There are no error messages and the HTML page loads, however there is no data present. This is the code I am using to get the data;...
-1
2016-10-02T12:21:44Z
39,816,997
<p>Please try the following code and let me know if it works for you:</p> <pre><code>&lt;table&gt; {% for item in items %} &lt;tr&gt; &lt;td&gt;{{ item[0] }}&lt;/td&gt; &lt;td&gt;{{ item[1] }}&lt;/td&gt; &lt;td&gt;{{ item[2] }}&lt;/td&gt; &lt;td&gt;{{ item[3] }}&lt;/td&gt; &lt;td&gt;{{ item[4] }}&l...
0
2016-10-02T12:27:48Z
[ "python", "html", "flask", "sqlite3", "jinja2" ]
Cannot get HTML to display SQLite3 data with python & flask
39,816,944
<p>I'm having an issue getting an HTML page to display my SQLite3 data using Python &amp; Flask. I found a question on here and used the same code, plus different variations to no success. There are no error messages and the HTML page loads, however there is no data present. This is the code I am using to get the data;...
-1
2016-10-02T12:21:44Z
39,817,387
<p>Here is what I had to do.. For anyone else having this issue, I'm not sure why but Jinja did not want to let me access by index so I did..</p> <pre><code>@app.route("/viewpackages", methods=['GET']) def viewpackages(): con = sqlite3.connect('utpg.db') con.row_factory = sqlite3.Row db = con.cursor() user_id = sessio...
0
2016-10-02T13:13:20Z
[ "python", "html", "flask", "sqlite3", "jinja2" ]
Scrapy extracting the wrong IMG SRC
39,817,067
<p>I'm trying to use Scrapy to get the <a href="https://www.tripadvisor.com/Attraction_Review-g155032-d1494256-Reviews-Gray_Line-Montreal_Quebec.html" rel="nofollow">URLs of images on a page</a> with ID <code>HERO_PHOTO</code>. The target element has the following HTML code</p> <p><code>&lt;img alt="Photo of Gray Line...
1
2016-10-02T12:37:03Z
39,817,707
<p>I believe you are using the wrong css selector. Looking at <a href="http://www.w3schools.com/cssref/css_selectors.asp" rel="nofollow">w3 schools</a> it seems to select your attribute you want [src].</p> <p>Try this.</p> <p>response.css('#HERO_PHOTO[src]').extract_first()</p> <p>my next suggestion is to see what y...
0
2016-10-02T13:53:43Z
[ "python", "css", "python-2.7", "scrapy" ]
Scrapy extracting the wrong IMG SRC
39,817,067
<p>I'm trying to use Scrapy to get the <a href="https://www.tripadvisor.com/Attraction_Review-g155032-d1494256-Reviews-Gray_Line-Montreal_Quebec.html" rel="nofollow">URLs of images on a page</a> with ID <code>HERO_PHOTO</code>. The target element has the following HTML code</p> <p><code>&lt;img alt="Photo of Gray Line...
1
2016-10-02T12:37:03Z
39,829,111
<p>The image links are in the page, but not directly as <code>&lt;img&gt;</code> tags. There are indeed processed with some JavaScript code. There is a JavaScript snippet inside the HTML with the image links you want (reformatted a bit):</p> <pre><code>... }(window,ta)); &lt;/script&gt; &lt;script type="text/javascrip...
1
2016-10-03T10:07:16Z
[ "python", "css", "python-2.7", "scrapy" ]
recursion of the form var += func(var, n-1)
39,817,078
<p>TL/DR How do you evaluate statements of the form <code>var += func(var, n-1)</code>?</p> <p>edit: By 'evaluate' I mean, how is the value being called by the right side of this statement determined. Within the function given below, <code>var += func(var, n-1)</code> always results in <code>sum += sum</code>. But why...
-1
2016-10-02T12:38:28Z
39,817,146
<p>In python, <code>x += y</code> is same as <em><code>x = x + y</code> i.e. add <code>y</code> to the value of <code>x</code> and save to <code>x</code></em>.</p> <p>In your case, <code>sum += foo(sum, n-1)</code> means <em>add value returned by <code>foo(sum, n-1)</code> with <code>sum</code> and save it as <code>su...
0
2016-10-02T12:46:21Z
[ "python", "python-3.x", "recursion" ]
recursion of the form var += func(var, n-1)
39,817,078
<p>TL/DR How do you evaluate statements of the form <code>var += func(var, n-1)</code>?</p> <p>edit: By 'evaluate' I mean, how is the value being called by the right side of this statement determined. Within the function given below, <code>var += func(var, n-1)</code> always results in <code>sum += sum</code>. But why...
-1
2016-10-02T12:38:28Z
39,823,561
<p>While I still haven't figured exactly why the given function produces the output it does, I have finally figured the main question of the topic, namely, how to evaluate statements of the form <code>var += func(var, n-1)</code>.</p> <p>While a statement of the form <code>x += y</code> is simple enough to understand,...
0
2016-10-03T01:50:20Z
[ "python", "python-3.x", "recursion" ]
typing.Any vs object?
39,817,081
<p>Is there any difference between using <code>typing.Any</code> as opposed to <code>object</code> in typing? For example:</p> <pre><code>def get_item(L: list, i: int) -&gt; typing.Any: return L[i] </code></pre> <p>Compared to:</p> <pre><code>def get_item(L: list, i: int) -&gt; object: return L[i] </code></p...
4
2016-10-02T12:38:34Z
39,817,126
<p>Yes, there is a difference. Although in Python 3, all objects are instances of <code>object</code>, including <code>object</code> itself, only <code>Any</code> documents that the return value should be disregarded by the typechecker.</p> <p>The <code>Any</code> type docstring states that object is a subclass of <co...
5
2016-10-02T12:43:19Z
[ "python", "python-3.5", "type-hinting" ]
typing.Any vs object?
39,817,081
<p>Is there any difference between using <code>typing.Any</code> as opposed to <code>object</code> in typing? For example:</p> <pre><code>def get_item(L: list, i: int) -&gt; typing.Any: return L[i] </code></pre> <p>Compared to:</p> <pre><code>def get_item(L: list, i: int) -&gt; object: return L[i] </code></p...
4
2016-10-02T12:38:34Z
39,821,459
<p><code>Any</code> and <code>object</code> are superficially similar, but in fact are entirely <em>opposite</em> in meaning.</p> <p><code>object</code> is the <em>root</em> of Python's metaclass hierarchy. Every single class inherits from <code>object</code>. That means that <code>object</code> is in a certain sense ...
3
2016-10-02T20:37:09Z
[ "python", "python-3.5", "type-hinting" ]
How to get python tcp server/client to allow multiple clients on ant the same time
39,817,110
<p>I have started to make my own TCP server and client. I was able to get the server and the client to connect over my LAN network. But when I try to have another client connect to make a three way connection, it does not work. What will happen is only when the first connected client has terminated the connection betwe...
0
2016-10-02T12:40:59Z
39,817,244
<p>This is your main problem: <code>Thread(target=clietConnect()).start()</code> executes the function <code>clientConnect</code> and uses it's return value as the Thread function (which is None, so the Thread does nothing)</p> <p>Also have a look at:</p> <p>1) You should wait for all connections to close instead of ...
0
2016-10-02T12:56:28Z
[ "python", "tcp" ]
Python, when import from module cmd I haven't all attribute
39,817,181
<p>When i import module urllib in cmd i have only magic fuctions but when I import this module from Spyder I have all attribute. I'a adding printscreen of this. Why can not I import all attribute?</p> <p><a href="http://i.stack.imgur.com/h1PGf.png" rel="nofollow">enter image description here</a></p>
0
2016-10-02T12:49:33Z
39,817,288
<p>To import all attributes of a module into the global namespace use <code>from module import *</code>. </p> <p>While <code>dir()</code> simply lists the attributes of the global namespace, <code>dir(module)</code> lists the ones in the scope of the specific module.</p> <p>Anyway, when you <code>import urllib</code>...
0
2016-10-02T13:01:52Z
[ "python", "python-3.x", "cmd" ]
PYTHON: AttributeError: 'int' object has no attribute 'hand'
39,817,223
<p>So I have an exercise on python - building a BlackJack game. I have started with defining how every phrase of the game would go. Now when I run this code below, In case the input is '0' - which means you don't want cards anymore, it runs perfectly. But when the input is '1' - which means you want to pick card, I get...
0
2016-10-02T12:54:22Z
39,817,321
<p>You are making the function call as <code>player(1)</code> where the <code>player</code> function expects the argument as of <code>self</code> type .i.e. instance of the class <code>blackjack</code>. Hence, while doing <code>self.hand = self.hand + random.randrange(1, 13)</code> it is throwing the above mentioned er...
0
2016-10-02T13:06:20Z
[ "python", "python-2.7", "int", "attributeerror" ]
QPlainTextEdit widget in PyQt5 with clickable text
39,817,251
<p>I am trying to build a simple code/text editor in PyQt5. Three important functionalities of a code-editor come to my mind:<br> (1) <em>Syntax highlighting</em><br> (2) <em>Code completion</em><br> (3) <em>Clickable functions and variables</em><br> <br> I plan to base the code editor on a <code>QPlainTextEdit</code> ...
0
2016-10-02T12:57:01Z
39,818,545
<p>Maybe you can utilize <a href="https://github.com/hlamer/qutepart" rel="nofollow">qutepart</a>. It looks like it does what you need. If you can't use it, then maybe you can look at the source code to see how they implemented different features, like clickable text.</p>
1
2016-10-02T15:28:31Z
[ "python", "qt", "pyqt", "pyqt5" ]
Regex pattern within text
39,817,302
<p>I have a long string of data which looks like:</p> <pre><code>dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd </code></pre> <p>Notice that the '12345.123' pattern is the same. I want to split the string on it using python (so <code>s.split(&lt;regex&gt;)</code>).</p> <p>What would be the appropriate regex?</p> <pre...
2
2016-10-02T13:03:42Z
39,817,357
<p>Just escape <code>.</code>, and you are done:</p> <pre><code>\d{5}\.\d{3} </code></pre> <p>You can use Regex token <code>\d</code> as a shorthand for <code>[0-9]</code>.</p> <p><strong>Example:</strong></p> <pre><code>&gt;&gt;&gt; re.split(r'\d{5}\.\d{3}', 'dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd') ['dstgfs...
4
2016-10-02T13:10:12Z
[ "python", "regex" ]
Regex pattern within text
39,817,302
<p>I have a long string of data which looks like:</p> <pre><code>dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd </code></pre> <p>Notice that the '12345.123' pattern is the same. I want to split the string on it using python (so <code>s.split(&lt;regex&gt;)</code>).</p> <p>What would be the appropriate regex?</p> <pre...
2
2016-10-02T13:03:42Z
39,817,375
<p>I don't understand exactly what's your actual need but seems that you want your regex to isolate each occurrence of 5 digits, dot, 3 digits.</p> <p>So instead of <code>'[0-9]{5}.[0-9]{3}'</code> you must use <code>'[0-9]{5}\.[0-9]{3}'</code>, because <code>.</code> matches any character, while <code>\.</code> match...
1
2016-10-02T13:12:17Z
[ "python", "regex" ]
Regex pattern within text
39,817,302
<p>I have a long string of data which looks like:</p> <pre><code>dstgfsda12345.123gsrsvrvsdfcsd23456.234tsrsd </code></pre> <p>Notice that the '12345.123' pattern is the same. I want to split the string on it using python (so <code>s.split(&lt;regex&gt;)</code>).</p> <p>What would be the appropriate regex?</p> <pre...
2
2016-10-02T13:03:42Z
39,817,406
<p>Your regex should be <code>'\d{5}\.\d{3}'</code>. </p> <p>Check the usage of <code>.</code> instead of <code>\.</code>. That is because, '.' (Dot.) in the default mode, matches any character except a newline. Refer <a href="https://docs.python.org/2/library/re.html" rel="nofollow">regex</a> document. Whereas <code>...
1
2016-10-02T13:15:02Z
[ "python", "regex" ]
Not understanding return behavior in python
39,817,307
<p>I was just trying a simple code:</p> <pre><code>import sys def main(): print "this is main" return "string1" if __name__ == "__main__": sys.exit(main()) </code></pre> <p>And when I run this piece of code, it gives random result, sometimes "string1" before "this is main" and sometimes after it.</p> <...
1
2016-10-02T13:03:57Z
39,817,337
<p><code>sys.exit</code> takes the return value of <code>main()</code> and produces it as the error code of the application. The value should usually be numeric, though Python is being a bit tricky here.</p> <p>From the documentation of <a href="https://docs.python.org/2/library/sys.html?highlight=sys%20exit#sys.exit"...
2
2016-10-02T13:08:05Z
[ "python" ]
How can I allow spaces in a Django username regex?
39,817,348
<p>I am trying to allow spaces to be accepted into the username field of the default django.contrib.auth.models User, other people have asked directly or similar questions before: <a href="http://stackoverflow.com/questions/19911087/how-can-i-allow-spaces-in-a-django-username">Here</a>, <a href="http://stackoverflow.co...
0
2016-10-02T13:09:33Z
39,820,162
<p>You'll need to modify the user where the validator exists. The following code should work for Django 1.9. </p> <p>With this user below you should be able to use <code>MyUser</code> instead of <code>User</code> for the form that you wrote. </p> <pre><code>from django.contrib.auth.models import AbstractUser from dj...
0
2016-10-02T18:18:58Z
[ "python", "django", "django-models", "django-forms", "django-admin" ]
Python - generating parent/child dict structure
39,817,405
<p>I have method:</p> <pre><code>@staticmethod def get_blocks(): """Public method that can be extended to add new blocks. First item is the most parent. Last item is the most child. Returns: blocks (list) """ return ['header', 'body', 'footer'] </code></pre> <p>As docstring descri...
1
2016-10-02T13:14:58Z
39,817,468
<p>You want to loop over the list in pairs, giving you the natural parent-child relationships:</p> <pre><code>mp = {'parent': {}, 'child': {}} if blocks: mp['parent'][blocks[0]] = mp['child'][blocks[-1]] = None for parent, child in zip(blocks, blocks[1:]): mp['parent'][child] = parent mp['child...
1
2016-10-02T13:23:20Z
[ "python", "list", "python-2.7", "dictionary", "parent-child" ]
contact form on google app engine
39,817,482
<p>I have a website running on google app engine and would like to include a contact form. My app.yaml looks like this:</p> <pre><code>version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: / static_files: www/index.html upload: www/index.html - url: /(.*) static_f...
3
2016-10-02T13:24:48Z
39,818,474
<p>Your contact form handler isn't being hit because you have a catch-all rule that precedes it. Also, your contact form handler needs its own URL rather than it too having a catch-all pattern. Try this:</p> <pre><code>version: 1 runtime: python27 api_version: 1 threadsafe: true libraries: - name: jinja2 versi...
1
2016-10-02T15:21:08Z
[ "python", "google-app-engine", "web-deployment", "contact-form" ]
Python sorted plot
39,817,545
<p>I want to use seaborn to perform a <code>sns.barplot</code> where the values are ordered e.g. in ascending order.</p> <p>In case the <code>order</code> parameter of seaborn is set the plot seems to duplicate the labels for all non-NaN labels.</p> <p>Trying to pre-sort the values like <code>mydf.sort_values(['myVal...
1
2016-10-02T13:33:44Z
39,817,575
<p>Do you save the changes by <code>pd.sort_values</code>? If not, probably you have to add the <code>inplace</code> keyword:</p> <p><code>mydf.sort_values(['myValueField'], ascending=False, inplace=True)</code></p>
1
2016-10-02T13:37:37Z
[ "python", "sorting", "plot", "bar-chart", "seaborn" ]
Import my cythonized package in python
39,817,572
<p>I have a script_function_cython.pyx file containing a single function:</p> <pre><code>import numpy as np import scipy.misc as misc import matplotlib.pyplot as plt def my_function(img, kernel): assert kernel.shape==(3, 3) res = np.zeros(img.shape) for i in range(1, img.shape[0]-1): for j in r...
1
2016-10-02T13:37:21Z
39,817,663
<p>with the <code>--inplace</code> build there is no need for install. You'll need to import from project directory though.</p> <pre><code>python setup.py build --inplace python -c 'import script_function_cython' </code></pre> <p>should raise no error.</p>
1
2016-10-02T13:48:34Z
[ "python", "numpy", "cython", "distutils" ]
How to send a json object using tcp socket in python
39,817,641
<p>here is my python tcp client. I want to send a json object to the server.But I can't send the object using the sendall() method. how can I do this?</p> <pre><code>import socket import sys import json HOST, PORT = "localhost", 9999 m ='{"id": 2, "name": "abc"}' jsonObj = json.loads(m) data = jsonObj # Create a ...
0
2016-10-02T13:46:14Z
39,817,677
<p>Skip the <code>json.loads()</code> part. Send the json object as the json string and load it from the string at the TCP client.</p> <p>Also check: <a href="http://stackoverflow.com/questions/6341823/python-sending-dictionary-throught-tcp">Python sending dictionary throught TCP</a></p>
0
2016-10-02T13:50:19Z
[ "python", "json", "sockets", "tcp" ]
urllib.request.urlretrieve not downloading files over HTTPS
39,817,671
<p>The below URL is the download link to download a text file. If I paste the URL in the Firefox it downloads the actual contents i.e text file. But, when used <code>urlretrieve</code> it is giving me some html source code file.</p> <pre><code>&gt;&gt;&gt; import urllib &gt;&gt;&gt; down_link='URL' #URL is a ***HTTPS*...
0
2016-10-02T13:49:25Z
39,817,826
<p>First of, you should import <code>urllib.request</code>, and not just urllib (in Py3).<br> And you are assigning the object to a variable so its giving you the object instance as output. Nothing wrong with that, just to give you a quick fix, try doing:</p> <pre><code>In [1]: import urllib.request In [2]: down_link...
1
2016-10-02T14:07:47Z
[ "python", "python-3.x", "urllib" ]
Find combinations of a list of sets
39,817,675
<p>I'm using python 2.7. Given a list of sets, is there any quick and efficient way to generate the combinations? Input sets always have one item in each set and output sets all have length of 2 <br><br> From:</p> <pre><code>[set(['item1']), set(['item2']), set(['item3'])] </code></pre> <p>To:</p> <pre><code>[set(['...
-1
2016-10-02T13:50:11Z
39,817,828
<p>As John pointed out <code>itertools</code> might be of help. Here's a quick example:</p> <pre><code>import itertools as it sets = [set(range(0, 3)), set(range(2, 5)), set(range(4, 7))] comb = list(it.combinations(sets, r=2)) comb </code></pre> <p>output: <code>[({0, 1, 2}, {2, 3, 4}), ({0, 1, 2}, {4, 5, 6}), ({2, ...
0
2016-10-02T14:08:03Z
[ "python", "python-2.7", "set", "combinations" ]
Find combinations of a list of sets
39,817,675
<p>I'm using python 2.7. Given a list of sets, is there any quick and efficient way to generate the combinations? Input sets always have one item in each set and output sets all have length of 2 <br><br> From:</p> <pre><code>[set(['item1']), set(['item2']), set(['item3'])] </code></pre> <p>To:</p> <pre><code>[set(['...
-1
2016-10-02T13:50:11Z
39,818,310
<p>Since the elements in your list of sets are all 1-element sets, the combinations that you are looking for are just the 2-element subsets of the union of those sets. You can obtain them like this:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; sets = [set(['item1']), set(['item2']), set(['item3'])] &gt;&...
1
2016-10-02T15:03:24Z
[ "python", "python-2.7", "set", "combinations" ]
How can I create this list of dicts
39,817,702
<p>I have a list of dicts</p> <pre><code>[{'name_field': u'casino_logo', 'contentid_id': 15L, 'value': u'assets/images/crown.png', 'title': u'Royal casino casino4'}, {'name_field': u'casino_logo', 'contentid_id': 16L, 'value': u'assets/images/crown.png', 'title': u'Royal casino casino1'}, {'name_field': u'casino_logo'...
0
2016-10-02T13:53:03Z
39,817,739
<p>You can use a <em>"dictionary comprehension"</em> to achieve this as:</p> <pre><code>my_dict = {item['name_field']: item for item in my_list} </code></pre> <p>where <code>my_list</code> is the list of <code>dict</code> as is mentioned in the question.</p> <p>In case you want to remove the <code>'name_field'</code...
1
2016-10-02T13:57:02Z
[ "python", "list", "dictionary", "data-structures" ]
django image upload rest framework and test client
39,817,737
<p>I'm trying to upload a picture with rest framework and to test it with the django test client. It almost works, however when I save the file I have this on the top of my file:</p> <pre><code>--BoUnDaRyStRiNg Content-Disposition: form-data; name="plop.png" </code></pre> <p>If I delete those lines, I can perfectly r...
0
2016-10-02T13:56:53Z
39,820,142
<p>Try this:</p> <pre><code>res = cl.post('/avatar?filename=plop.png', {"plop.png" : data}) </code></pre> <p>Or more or less from the Django docs:</p> <pre><code>with open(MY_FILE, 'rb') as f: cl.post('/avatar', {"filename" : f}) </code></pre>
0
2016-10-02T18:16:42Z
[ "python", "django", "django-rest-framework" ]
django image upload rest framework and test client
39,817,737
<p>I'm trying to upload a picture with rest framework and to test it with the django test client. It almost works, however when I save the file I have this on the top of my file:</p> <pre><code>--BoUnDaRyStRiNg Content-Disposition: form-data; name="plop.png" </code></pre> <p>If I delete those lines, I can perfectly r...
0
2016-10-02T13:56:53Z
39,860,207
<p>This worked as I expected: views.py</p> <pre><code>class AvatarView(APIView): parser_classes = (MultiPartParser,) def post(self, request): up_file = request.data["file"] user = get_object_or_404(GenericUser, pk=request.user.id) user.avatar.save(up_file.name, up_file) user.sav...
0
2016-10-04T19:23:54Z
[ "python", "django", "django-rest-framework" ]
Plotting data using higcharts in flask web application
39,817,834
<p>I am trying to plot data from mysql server and display it in a web server. I am using highcharts javascript library for plotting. I can get data from mysql database and data is sent from server-side to client-side as json data. Then by using highcharts I want to display it. But chart shows nothing when I try to plot...
0
2016-10-02T14:08:43Z
39,821,868
<p>It doesn't look your data is formatted correctly for Highcharts. If you look at <a href="http://stackoverflow.com/questions/29643609/how-to-pass-json-data-to-highcharts-series">this other StackOverlow question about JSON data and Highcharts</a> you'll see that the data should be a list of dictionaries.</p> <p>To d...
0
2016-10-02T21:26:14Z
[ "javascript", "jquery", "python", "highcharts", "flask" ]
Getopt multiple argument syntaxes
39,817,973
<p>So I'm working on an assignment in a python class that I'm taking, but have gotten stuck with something I can't really find any further information about (neither on SO, Google or in the courseware). </p> <p>I need help with how to handle arguments with multiple types of syntaxes - like <strong>[arg] and &lt; arg ...
0
2016-10-02T14:25:48Z
39,818,787
<p><code>[]</code> and <code>&lt;&gt;</code> are commonly used to visually indicate option requirement. Typically <code>[xxxx]</code> means the option or argument is optional and <code>&lt;xxxx&gt;</code> required.</p> <p>The sample code you provide handles option flags, but not the required arguments. Code below shou...
1
2016-10-02T15:53:14Z
[ "python", "python-2.7", "python-3.x", "getopt" ]
how to setup multiple python version on debian (pip, virtualenvwrapper etc)
39,818,095
<p>I'm starting to use python and would like to setup my workstation which is running on linux (debian). Multiple version of python are installed:</p> <pre><code>ot@station:/home/ot# ls -l /usr/bin/py py3clean pydoc3.4 python2 python3.4m-config py3compile pygettext pytho...
1
2016-10-02T14:39:05Z
39,818,175
<pre><code>sudo apt-get install python3-pip # install pip3 pip3 install virtualenv virtualenv venv # create virtualenv called venv source /venv/bin/activate # activate the virtualenv pip install xyz [...] deactivate </code></pre> <p>Note: to install packages <strong>within</strong> the virtual environment you si...
1
2016-10-02T14:48:42Z
[ "python", "virtualenv", "virtualenvwrapper" ]
Ansible not reading credentials from ~/.aws/credentials
39,818,098
<p>I am running ansible with <code>dynamic inventory</code>. When the <code>aws cli</code> was setup with aws configure command than the ansible commands with dynamic invetory was running properly. But I want to have multiple profiles to be used by dynamic inventory so I have added profile in <code>~/.aws/credentials</...
2
2016-10-02T14:39:25Z
39,818,189
<p>Have you tried adding --profile PROFILE switch to ec2.py as below.</p> <pre><code>./ec2.py --list --profile personal </code></pre>
0
2016-10-02T14:49:57Z
[ "python", "amazon-web-services", "ansible", "aws-cli" ]
Ansible not reading credentials from ~/.aws/credentials
39,818,098
<p>I am running ansible with <code>dynamic inventory</code>. When the <code>aws cli</code> was setup with aws configure command than the ansible commands with dynamic invetory was running properly. But I want to have multiple profiles to be used by dynamic inventory so I have added profile in <code>~/.aws/credentials</...
2
2016-10-02T14:39:25Z
39,823,521
<p>After @uptime365's answer, this is most likely not an Ansible/ec2.py problem. Here's my troubleshooting steps:</p> <h3>Can you use the <code>awscli</code> with those credentials?</h3> <pre><code>aws ec2 describe-instances --page-size 5 aws ec2 describe-instances --page-size 5 --profile personal </code></pre> <h2>...
0
2016-10-03T01:44:09Z
[ "python", "amazon-web-services", "ansible", "aws-cli" ]
python/django: model object has no attribute 'prefetch_related'
39,818,121
<p>I have created a model 'VehicleDetails' in which a user can fill the details of a vehicle and another model 'TripStatus' in which he updates the vehicle location. I wanted to get the latest location for which i did as in my below code. I use prefetch_related in my view to returns the location values for a particular...
0
2016-10-02T14:42:29Z
39,818,183
<p>prefetch_related works on a queryset object. Latest returns a single model not a queryset. </p> <p>This should work :</p> <pre><code>tripstatus = TripStatus.objects.all().prefetch_related('statuses').latest('statustime') </code></pre>
1
2016-10-02T14:49:12Z
[ "python", "django", "django-models", "django-templates", "django-views" ]