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
Change tags in evernote business
38,084,145
<p>I would like to use hierarchical tags in evernote business. In the evernote ui, I can setup hierarchies in business tags, but when I try to set the parentGuid for a business notebook tag, I only get </p> <pre><code>evernote.edam.error.ttypes.EDAMUserException: EDAMUserException(parameter='authenticationToken', erro...
0
2016-06-28T18:53:55Z
38,340,761
<p>Hm, yeah sorry, our current service API doesn't allow updating tags in an EB account. Apologies, but no plans to change that at this time.</p>
0
2016-07-13T00:15:54Z
[ "python", "evernote" ]
curl to Python POST request image upload input error
38,084,169
<p>I am trying to convert this curl command :</p> <pre><code>curl -X POST -F "images_file=@prez.jpg" "https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces?api_key={apikey}&amp;version=2016-05-20" </code></pre> <p>to a python post request. </p> <p>used <a href="http://docs.python-requests.org/...
1
2016-06-28T18:55:14Z
38,085,552
<p>This should match your curl request.</p> <pre><code>url = 'https://gateway-a.watsonplatform.net/visual-recognition/api/v3/detect_faces' images = {'images_file': open('prez.jpg', 'rb')} payload = {'api_key': "{{{}}}".format(api_key), 'version': '2016-05-20'} r = requests.post(url, files=images, params=payload) </cod...
1
2016-06-28T20:18:00Z
[ "python", "curl", "python-requests" ]
String processing issue using a Python intro text
38,084,192
<p>What's wrong with this bit of Python? Entering the names does not work.</p> <pre><code>def main(): print("This program generates computer usernames.\n") # get user's first and last names first = input("Please enter your first name (all lowercase): ") last = input("Please enter your last name (all ...
1
2016-06-28T18:57:18Z
38,084,778
<p>In your code, change <code>input</code> (which works in Python 3) to <code>raw_input</code> (which works in Python 2) and see what happens. </p> <p>And to confirm which Python version you're using, run this Terminal command: <code>python --version</code></p>
0
2016-06-28T19:30:56Z
[ "python", "string", "input", "indexing" ]
String processing issue using a Python intro text
38,084,192
<p>What's wrong with this bit of Python? Entering the names does not work.</p> <pre><code>def main(): print("This program generates computer usernames.\n") # get user's first and last names first = input("Please enter your first name (all lowercase): ") last = input("Please enter your last name (all ...
1
2016-06-28T18:57:18Z
38,174,826
<p>Instead of changing <code>input</code> to <code>raw_input</code> so your script will work in Python 2, you could add a shebang line so the Terminal shell will run your script in Python 3.</p> <p>A shebang line tells the shell <a href="http://stackoverflow.com/a/9865189/3345375">(1) that the file is a shell script, ...
0
2016-07-03T22:20:40Z
[ "python", "string", "input", "indexing" ]
Initialize the socketIO too slow, using python socketIO-client package
38,084,215
<p>I use socketIO-client package in python for testing my server code. It is a simple client, but it always takes about 1 min to run the following line:</p> <pre><code>socketIO = SocketIO('localhost',3003) </code></pre> <p>I wonder how to solve this problem?</p> <p>I use eventlet and didn't install socketIO-client i...
0
2016-06-28T18:58:55Z
39,064,271
<p>My Python socket ioclient connects pretty quickly to an external node.js server. This may be a routing/DNS problem Localhost can exhibit strange routing behaviour sometimes. use 127.0.0.1 not localhost as the url to eliminate routing /DNS timeouts</p>
-1
2016-08-21T12:36:54Z
[ "python", "socket.io", "client" ]
Separating except portion of a try/except into a function
38,084,360
<p>I have a try/except where I repeat the except portion frequently in my code. This led me to believe that it would be better to separate the except portion into a function. </p> <p>Below is my use case:</p> <pre><code>try: ... except api.error.ReadError as e: ... except api.error.APIConnectionError as e: ... ...
2
2016-06-28T19:06:55Z
38,084,412
<p>Just define the function:</p> <pre><code>def my_error_handling(e): #Do stuff </code></pre> <p>...and pass in the <code>exception</code> object as the parameter:</p> <pre><code>try: #some code except Exception as e: my_error_handling(e) </code></pre> <p>Using just a generic <code>Exception</code> type...
1
2016-06-28T19:09:39Z
[ "python", "try-except" ]
Separating except portion of a try/except into a function
38,084,360
<p>I have a try/except where I repeat the except portion frequently in my code. This led me to believe that it would be better to separate the except portion into a function. </p> <p>Below is my use case:</p> <pre><code>try: ... except api.error.ReadError as e: ... except api.error.APIConnectionError as e: ... ...
2
2016-06-28T19:06:55Z
38,084,460
<p>Define your function:</p> <pre><code>def my_error_handling(e): #Handle exception </code></pre> <p>And do what you're proposing:</p> <pre><code>try: ... except Exception as e: my_error_handling_function(e) </code></pre> <p>You can handle logic by getting the type of the exception 'e' within your function....
0
2016-06-28T19:12:25Z
[ "python", "try-except" ]
Separating except portion of a try/except into a function
38,084,360
<p>I have a try/except where I repeat the except portion frequently in my code. This led me to believe that it would be better to separate the except portion into a function. </p> <p>Below is my use case:</p> <pre><code>try: ... except api.error.ReadError as e: ... except api.error.APIConnectionError as e: ... ...
2
2016-06-28T19:06:55Z
38,084,501
<p>I would suggest refactoring your code so the try/except block is only present in a single location.</p> <p>For instance, an API class with a <code>send()</code> method, seems like a reasonable candidate for containing the error handling logic you have described in your question.</p>
0
2016-06-28T19:14:43Z
[ "python", "try-except" ]
How to keep trying to establish connection in Python
38,084,400
<p>If the server is not up when I try to run the following code, I just get a Connection refused error.</p> <p>How can I make the sender below to keep trying to establish connection and perhaps sending until the remote server is indeed up and the connection is successfully established?</p> <pre><code>HOST = client_ip...
0
2016-06-28T19:09:03Z
38,084,518
<p>How about brute force? Something like this</p> <pre><code>import time while 1: HOST = client_ip # The remote host PORT = port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: s.connect((HOST, PORT)) except: print("FAILED. Sleep briefly &amp; try again") ...
1
2016-06-28T19:15:30Z
[ "python", "sockets", "networking" ]
When is copy on write invoked for python multiprocessing across class methods
38,084,401
<p>I have a bit of <code>multiprocessing</code> Python code that looks a bit like this:</p> <pre><code>import time from multiprocessing import Pool import numpy as np class MyClass(object): def __init__(self): self.myAttribute = np.zeros(100000000) # basically a big memory struct def my_multithreaded...
3
2016-06-28T19:09:07Z
38,135,787
<p>Anything sent to <code>pool.map</code> (and related methods) isn't actually using shared copy-on-write resources. The values are <a href="https://docs.python.org/3/library/pickle.html">"pickled" (Python's serialization mechanism)</a>, sent over pipes to the worker processes and unpickled there, which reconstructs th...
6
2016-07-01T01:44:08Z
[ "python", "multithreading", "memory-management" ]
Returning huge dictionaries to the parent with Multiprocessing
38,084,418
<p>I am doing a CPU expensive computation that can be easily divided into many workers. However, I have to join the results at the end. The problem is that you can not use shared memory when using multiple isolated processes, and the only way of sending the computed output from the child to the parent is using <code>mu...
0
2016-06-28T19:10:23Z
38,109,047
<p>you can try pickle dictionaries your self, i recommend using dill module for that (but there are other module you can use too), so it would look something like this:</p> <pre><code>import dill as pickle dic = {...} f = open('save.pkl', 'wb') g = pickle.dump(dic, f) f.close() </code></pre> <p>than you can use to ge...
0
2016-06-29T20:00:59Z
[ "python", "multithreading", "multiprocessing", "shared-memory" ]
How do I count values in pandas
38,084,504
<p>I apologize if I'm not making any sense, English is not my native language and I am only one week into python and pandas.</p> <p>So, I have a really long data frame of transcription factors (TF) and long a list of essential genes, and what I've done so far is determine if a gene that is regulated by a TF is an esse...
0
2016-06-28T19:14:45Z
38,086,948
<p><code>apply</code> is your friend here</p> <pre><code>def count_tfs_essential(tf_val, df2, esencial_val): '''returns count of rows in df2 having specific tf_val and esencial_val''' df2_con_tf_val = df2[(df2["TF"] == tf_val)] df2_con_tf_val_y_essencial = df2_con_tf_val[df2_con_tf_val["Esencialidad"] == e...
0
2016-06-28T21:55:19Z
[ "python", "list", "pandas" ]
How to exclude one word from python list?
38,084,521
<p>I am trying to work on Python Regex. I have a list as follows:</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] </code></pre> <p>I need to select all values start with <code>MYTAB</code>, excluding <code>MYTAB-2</code>. Result should be :</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', '...
0
2016-06-28T19:15:41Z
38,084,592
<p>You can use the regex <code>/MYTAB-[^2]+/</code> for this. The syntax <code>[^2]</code> means all except for <code>2</code>.</p>
0
2016-06-28T19:19:05Z
[ "python", "regex", "list" ]
How to exclude one word from python list?
38,084,521
<p>I am trying to work on Python Regex. I have a list as follows:</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] </code></pre> <p>I need to select all values start with <code>MYTAB</code>, excluding <code>MYTAB-2</code>. Result should be :</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', '...
0
2016-06-28T19:15:41Z
38,084,630
<p>You can use this piece of code.</p> <ol> <li>It will loop through the initial list <code>l1</code> and if the item <code>startswith("MYTAB")</code>, it'll be added to list <code>l2</code></li> <li>It will find the index of <code>MYTAB-2</code> inside the <code>l2</code> list</li> <li>Remove <code>MYTAB-2</code></li...
2
2016-06-28T19:22:10Z
[ "python", "regex", "list" ]
How to exclude one word from python list?
38,084,521
<p>I am trying to work on Python Regex. I have a list as follows:</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] </code></pre> <p>I need to select all values start with <code>MYTAB</code>, excluding <code>MYTAB-2</code>. Result should be :</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', '...
0
2016-06-28T19:15:41Z
38,084,642
<p>Try using pyregex to find your regex searches. Here is a a <a href="http://www.pyregex.com/?id=eyJyZWdleCI6Ik1ZVEFCLVteMl0iLCJmbGFncyI6MCwibWF0Y2hfdHlwZSI6ImZpbmRhbGwiLCJ0ZXN0X3N0cmluZyI6IlsnTVlUQUItRVZFTlRTJywgJ01ZVEFCLTEnLCAnTVlUQUItMicsICdNWVRBQi1QRVJGJywnQUJDJywnREVGXSJ9" rel="nofollow">link</a> to a working re...
-1
2016-06-28T19:23:12Z
[ "python", "regex", "list" ]
How to exclude one word from python list?
38,084,521
<p>I am trying to work on Python Regex. I have a list as follows:</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] </code></pre> <p>I need to select all values start with <code>MYTAB</code>, excluding <code>MYTAB-2</code>. Result should be :</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', '...
0
2016-06-28T19:15:41Z
38,084,670
<p>Use a filter with <code>re</code> on a list comprehension:</p> <pre><code>import re l = ['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] l = [i for i in l if re.match(r'MYTAB-[^2]', i)] print(l) # ['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-PERF'] </code></pre>
1
2016-06-28T19:25:02Z
[ "python", "regex", "list" ]
How to exclude one word from python list?
38,084,521
<p>I am trying to work on Python Regex. I have a list as follows:</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] </code></pre> <p>I need to select all values start with <code>MYTAB</code>, excluding <code>MYTAB-2</code>. Result should be :</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', '...
0
2016-06-28T19:15:41Z
38,084,941
<pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; import re &gt;&gt;&gt; list_ = ['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF', 'ABC', 'DEF'] &gt;&gt;&gt; filtered_list = filter(lambda str_: re.search(r'^MYTAB(?!-2)', str_), list_) &gt;&gt;&gt; filtered_list ['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-PERF'] </...
1
2016-06-28T19:39:54Z
[ "python", "regex", "list" ]
How to exclude one word from python list?
38,084,521
<p>I am trying to work on Python Regex. I have a list as follows:</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PERF','ABC','DEF'] </code></pre> <p>I need to select all values start with <code>MYTAB</code>, excluding <code>MYTAB-2</code>. Result should be :</p> <pre><code>['MYTAB-EVENTS', 'MYTAB-1', '...
0
2016-06-28T19:15:41Z
38,084,957
<p>You have a number of options for filtering the list. The basic answer to your question is <code>'MYTAB(?!-2)'</code> if you are using <code>re.match</code>, which matches the beginning of the input.</p> <pre><code>import re expr = re.compile('MYTAB(?!-2)') rawList = ['MYTAB-EVENTS', 'MYTAB-1', 'MYTAB-2', 'MYTAB-PER...
1
2016-06-28T19:40:51Z
[ "python", "regex", "list" ]
Python 3: write method vs. os.write number of bytes returned
38,084,573
<p>I wanted to create a text file containing a number of ''pages'' and log the byte offset of each page in a separate file. To do that, I printed strings to the main output file and counted bytes using <code>bytes_written += file.write(str)</code>. However, the byte offset was often wrong. </p> <p>I switched to <code>...
1
2016-06-28T19:18:06Z
38,084,824
<blockquote> <p>What is the difference between <code>write()</code> and <code>os.write()</code>?</p> </blockquote> <p>It's analogous to the difference between the C functions <a href="http://linux.die.net/man/3/fwrite" rel="nofollow"><code>fwrite(3)</code></a> and <a href="http://linux.die.net/man/2/write" rel="nofo...
3
2016-06-28T19:33:47Z
[ "python", "file", "python-3.x", "utf-8" ]
python multiply two lists element wise - one of them is nested
38,084,593
<p>I have two lists:</p> <pre><code>C = [3, 2, 1] D = [[0, 1, 2, 3], [0, 1, 2], [0, 1]] </code></pre> <p>I would like to achieve this result:</p> <pre><code>E = [[0, 3, 6, 9], [0, 2, 4], [0, 1]] </code></pre> <p>using only list comprehensions.Is it possible ? I am stuck at:</p> <pre><code>E = zip(C, D) [i * E[0][0...
1
2016-06-28T19:19:07Z
38,084,646
<p>You're almost there: it's a nested list comprehension. Slap another list, [blah[j] for j in ]</p> <pre><code>C = [3, 2, 1] D = [[0, 1, 2, 3], [0, 1, 2], [0, 1]] E = zip(C, D) print [[i * E[j][0] for i in E[j][1]] for j in range(len(E))] </code></pre> <p>Output:</p> <pre><code>[[0, 3, 6, 9], [0, 2, 4], [0, 1]] <...
2
2016-06-28T19:23:32Z
[ "python", "list", "nested" ]
python multiply two lists element wise - one of them is nested
38,084,593
<p>I have two lists:</p> <pre><code>C = [3, 2, 1] D = [[0, 1, 2, 3], [0, 1, 2], [0, 1]] </code></pre> <p>I would like to achieve this result:</p> <pre><code>E = [[0, 3, 6, 9], [0, 2, 4], [0, 1]] </code></pre> <p>using only list comprehensions.Is it possible ? I am stuck at:</p> <pre><code>E = zip(C, D) [i * E[0][0...
1
2016-06-28T19:19:07Z
38,084,652
<p>Yes, it is possible:</p> <pre><code>&gt;&gt;&gt; [[c * d_i for d_i in d] for c, d in zip(C, D)] [[0, 3, 6, 9], [0, 2, 4], [0, 1]] </code></pre> <p>You just need two loops here, the first one to iterate over <code>zip(C, D)</code>, and the second one to iterate over each list of <code>D</code></p>
4
2016-06-28T19:23:53Z
[ "python", "list", "nested" ]
python multiply two lists element wise - one of them is nested
38,084,593
<p>I have two lists:</p> <pre><code>C = [3, 2, 1] D = [[0, 1, 2, 3], [0, 1, 2], [0, 1]] </code></pre> <p>I would like to achieve this result:</p> <pre><code>E = [[0, 3, 6, 9], [0, 2, 4], [0, 1]] </code></pre> <p>using only list comprehensions.Is it possible ? I am stuck at:</p> <pre><code>E = zip(C, D) [i * E[0][0...
1
2016-06-28T19:19:07Z
38,084,730
<p>This would be straight forward if you use <code>numpy</code> array:</p> <pre><code>import numpy as np np.array(C) * np.array(map(np.array, D)) # array([array([0, 3, 6, 9]), array([0, 2, 4]), array([0, 1])], dtype=object) </code></pre>
0
2016-06-28T19:28:19Z
[ "python", "list", "nested" ]
python multiply two lists element wise - one of them is nested
38,084,593
<p>I have two lists:</p> <pre><code>C = [3, 2, 1] D = [[0, 1, 2, 3], [0, 1, 2], [0, 1]] </code></pre> <p>I would like to achieve this result:</p> <pre><code>E = [[0, 3, 6, 9], [0, 2, 4], [0, 1]] </code></pre> <p>using only list comprehensions.Is it possible ? I am stuck at:</p> <pre><code>E = zip(C, D) [i * E[0][0...
1
2016-06-28T19:19:07Z
38,085,617
<p>I would also solve it with <a href="https://docs.python.org/3/library/itertools.html#itertools.starmap" rel="nofollow"><code>itertools.startmap</code></a>:</p> <pre><code>&gt;&gt;&gt; from itertools import starmap &gt;&gt;&gt; &gt;&gt;&gt; def multiply(x, lst): return [x*i for i in lst] &gt;&gt;&gt; for it...
0
2016-06-28T20:22:51Z
[ "python", "list", "nested" ]
Converting to utf-8 python
38,084,666
<p>I am using Ubuntu and python 3.4 to download data from wikipedia's api. I am saving the names and I saw that characters in different languages are not saved correctly.</p> <p>For example: 日の火曜日 is saved as æ¥ã®ç«ææ¥.</p> <p>I figured I may not be saving it in utf-8 so I changed my code to </p> ...
0
2016-06-28T19:24:35Z
38,085,304
<p>Check the reponse code, get charset from the reponse and use it to decode. You can use <code>name.decode('utf-8')</code> or <code>str(name, 'utf-8')</code> to decode. </p> <p>F.e.</p> <pre><code>resp = urlopen(url) if resp.code == 200: with open('filename', 'w') as fd: fd.write(str(name, resp.info().g...
0
2016-06-28T20:02:16Z
[ "python", "encoding", "utf-8" ]
Converting to utf-8 python
38,084,666
<p>I am using Ubuntu and python 3.4 to download data from wikipedia's api. I am saving the names and I saw that characters in different languages are not saved correctly.</p> <p>For example: 日の火曜日 is saved as æ¥ã®ç«ææ¥.</p> <p>I figured I may not be saving it in utf-8 so I changed my code to </p> ...
0
2016-06-28T19:24:35Z
38,087,022
<p>The problem was my ssh client and it was displaying the strings incorrectly. The code was working fine. </p>
0
2016-06-28T22:02:34Z
[ "python", "encoding", "utf-8" ]
ValueError: setting an array element with a sequence while training KD TRee on TFIDF
38,084,673
<p>I am trying to train a KD-Tree on TF-IDF of a document corpus but it gives </p> <pre><code>ValueError: setting an array element with a sequence. </code></pre> <p>The code and the error description are below. Can someone help me figure out the problem?</p> <p>Code:</p> <pre><code>t0 = time.time() count_vect = Cou...
1
2016-06-28T19:25:14Z
38,085,629
<p>X_train_tfidf is a sparse matrix (<a href="http://docs.scipy.org/doc/scipy/reference/sparse.html" rel="nofollow">scipy.sparse</a>) and in order to be converted to a numpy array, you need to do . <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.sparse.bsr_matrix.toarray.html#scipy.sparse.bsr_matrix....
2
2016-06-28T20:23:35Z
[ "python", "numpy", "scikit-learn", "knn", "tf-idf" ]
Converting Google Analytics Reporting API V4 request results to csv with Python
38,084,770
<p>I'm trying to create a nicely formatted csv file with Python from a Google Analytics Reporting API V4 request results.</p> <p>The setup is using the provided example "Hello Analytics Reporting API V4." <a href="https://developers.google.com/analytics/devguides/reporting/core/v4/quickstart/service-py#3_setup_the_sa...
0
2016-06-28T19:30:37Z
38,084,995
<p>Not sure it is very straightforward but it works.</p> <pre><code>import sys from collections import OrderedDict s="""ga:date: 20160601 ga:sessions: 19802 ga:pageviews: 53369 ga:users: 17656 ga:date: 20160602 ga:sessions: 33718 ga:pageviews: 71857 ga:users: 30266 """ d = OrderedDict() for l in s.splitlines(): ...
0
2016-06-28T19:43:27Z
[ "python", "csv", "google-analytics" ]
How to divide two groupby objects in pandas?
38,084,794
<p>I have the following code:</p> <pre><code>import numpy as np import pandas as pd obs = pd.DataFrame({ 'storm': [1, 1, 1, 1, 0, 0, 0, 0], 'lightning': [1, 1, 0, 0, 1, 1, 0, 0], 'thunder': [1, 0, 1, 0, 1, 0, 1, 0], 'p': [0.20, 0.05, 0.04, 0.36, 0.04, 0.01, 0.03, 0.27] }) g1=obs.g...
2
2016-06-28T19:31:59Z
38,084,996
<p><code>g2.unstack()</code> to get last level into columns. Then divide, broadcasting over columns. Then <code>stack</code> again.</p> <pre><code>g2.unstack().div(g1.p, axis=0).stack() </code></pre> <p><a href="http://i.stack.imgur.com/Omc0L.png" rel="nofollow"><img src="http://i.stack.imgur.com/Omc0L.png" alt="en...
3
2016-06-28T19:43:31Z
[ "python", "pandas", "group-by" ]
Can you have subprocesss.Popen retain color in stdout/stderr?
38,084,815
<p>I have the following code:</p> <pre><code>p = subprocess.Popen(cmd.split(' '), env=os.environ, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while(True): log.info(p.stdout.readline()) if(p.poll() is not None): break </code></pre> <p>Which works ok, except for the fact that it removes al...
1
2016-06-28T19:33:12Z
38,084,902
<p>You do not specify whan <code>cmd</code> is, but some programs do not emit the <a href="https://en.wikipedia.org/wiki/ANSI_escape_code" rel="nofollow">escape sequences</a> necessary for color output on a terminal when they determine that their standard output is not actually connected to a terminal.</p> <p>Dependin...
2
2016-06-28T19:37:56Z
[ "python", "python-2.7", "popen" ]
Raspberry Pi & Arduino reading serial sensor data
38,084,846
<p>I have a voltage sensor attached to my Arduino uno which in turn is connected to my Raspberry Pi 3. I would like to grab the sensor info in a ping pong type of way from the Arduino to the Raspberry Pi. I will wake it up with a character sent via a Python script on a cronjob and the sensor values grabbed and put into...
1
2016-06-28T19:35:05Z
38,091,694
<p>Some observations to your implementation.</p> <ol> <li><p>Why do you use <code>Battout</code> in the python script? </p></li> <li><p>In the python script you are expecting a line (that means a string ended in '\n') but in the Arduino C++ code you use <code>print</code> instead of <code>println</code> or adding a li...
0
2016-06-29T06:16:00Z
[ "python", "python-2.7", "arduino", "raspberry-pi", "raspberry-pi3" ]
Raspberry Pi & Arduino reading serial sensor data
38,084,846
<p>I have a voltage sensor attached to my Arduino uno which in turn is connected to my Raspberry Pi 3. I would like to grab the sensor info in a ping pong type of way from the Arduino to the Raspberry Pi. I will wake it up with a character sent via a Python script on a cronjob and the sensor values grabbed and put into...
1
2016-06-28T19:35:05Z
38,093,820
<p>There is an issue with the Raspberry Pi 3 and the <code>uart0</code> (Bluetooth), <code>uart1</code> (Serial).<br> For the Pi 3 <code>uart1</code> is usually available on <code>/dev/ttyS0</code> and TX-GPIO 14, RX-GPIO 15.<br> The baud rate for <code>uart1</code> is dependent on the core clock. So if the core clock ...
0
2016-06-29T08:07:58Z
[ "python", "python-2.7", "arduino", "raspberry-pi", "raspberry-pi3" ]
Calling Sage from Haskell
38,084,886
<p>I have some sage code that I'd like to call from Haskell. The following code uses <a href="http://hackage.haskell.org/package/cpython-3.3.0" rel="nofollow">cpython</a> to call a pure python script:</p> <p>test.py:</p> <pre><code>def pytest(): return 3.5+2 </code></pre> <p>Main.hs:</p> <pre class="lang-hs pre...
1
2016-06-28T19:37:19Z
38,085,148
<p>The real question is "which" Python you are using; Sage uses its own Python, NOT your system Python. You may want to try making a link from </p> <pre><code>$ pwd; local/bin/python --version /Users/.../Downloads/sage Python 2.7.10 $ </code></pre> <p>That is the one you will need to be linking to, in principle. In...
1
2016-06-28T19:52:53Z
[ "python", "haskell", "sage" ]
TypeError Django
38,084,964
<p>TypeError during django project</p> <p>Got this message on the error page:</p> <p>TypeError at /music/1/</p> <p>detail() got an unexpected keyword argument 'pk'</p> <p>Request Method: GET Request URL: <a href="http://127.0.0.1:8000/music/1/" rel="nofollow">http://127.0.0.1:8000/music/1/</a> Exception Type...
0
2016-06-28T19:41:26Z
38,088,204
<p>In your pattern, the parameter is called <code>pk</code> for the detail view:</p> <pre><code># /music/&lt;album_id&gt;/ url(r'^(?P&lt;pk&gt;[0-9]+)/$', views.detail, name = 'detail'), ^^ - this is the name of the parameter that it is looking for </code></pre> <p>However, your detail view has <code>album...
1
2016-06-29T00:05:19Z
[ "python", "django" ]
Cannot Loop Nested Json, get error (TypeError: list indices must be integers, not str)
38,085,036
<p>So I have looked everywhere, and have not found a solution.</p> <pre><code>import urllib2 import json shabad = raw_input('Shabad Number: ') hdr = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'} igurbani_api = urllib2.Request('htt...
0
2016-06-28T19:45:32Z
38,085,087
<p><code>data['gurbani']</code> is a list... as such</p> <p><code>data['gurbani']["shabad"]</code> is an error</p> <p>try</p> <p><code>for item in data['gurbani'][0]["shabad"]</code></p> <p>or really <strong>probably</strong></p> <pre><code>for translation in data['gurbani']: print translation["shabad"]["Gurmu...
1
2016-06-28T19:49:01Z
[ "python" ]
Cannot Loop Nested Json, get error (TypeError: list indices must be integers, not str)
38,085,036
<p>So I have looked everywhere, and have not found a solution.</p> <pre><code>import urllib2 import json shabad = raw_input('Shabad Number: ') hdr = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36'} igurbani_api = urllib2.Request('htt...
0
2016-06-28T19:45:32Z
38,085,132
<p>Try this:</p> <pre><code>for d in data['gurbani']: print d['shabad']['Gurmukhi'] </code></pre> <p>This is because <code>data['gurbani']</code> returns a list</p>
2
2016-06-28T19:51:45Z
[ "python" ]
Python 3 utf8 value decode to string
38,085,054
<p>Hi i am using python3 and i want to change utf8 value to string (decode)</p> <p>Here is my code now</p> <pre><code>s1 = '\u54c7' print(chr(ord(s1))) # print 哇 </code></pre> <p>It's fine if input is one char but how to change a string?</p> <pre><code>s2 = '\u300c\u54c7\u54c8\u54c8!!\u300d' print(chr(ord(s2))) ...
-1
2016-06-28T19:46:46Z
38,085,139
<p>If you are in fact using python3, you don't need to do anything. You can just print the string. Also you can just copy and paste the literals into a python string and it will work.</p> <pre><code>'「哇哈哈!!」' == '\u300c\u54c7\u54c8\u54c8!!\u300d' </code></pre> <p>In regards to the updated question, the diff...
3
2016-06-28T19:52:22Z
[ "python", "python-3.x", "utf-8" ]
Python 3 utf8 value decode to string
38,085,054
<p>Hi i am using python3 and i want to change utf8 value to string (decode)</p> <p>Here is my code now</p> <pre><code>s1 = '\u54c7' print(chr(ord(s1))) # print 哇 </code></pre> <p>It's fine if input is one char but how to change a string?</p> <pre><code>s2 = '\u300c\u54c7\u54c8\u54c8!!\u300d' print(chr(ord(s2))) ...
-1
2016-06-28T19:46:46Z
38,088,244
<p>Regarding your <code>s3</code> string, this seems to me more like an HTML entity or text in HTML format, so use proper <a href="https://docs.python.org/2/library/htmlparser.html" rel="nofollow"><code>html.parser</code></a>, this way:</p> <pre><code>&gt;&gt;&gt; s3 = '&amp;#x54c7;&amp;#x54c8;&amp;#x54c8;!!' &gt;&gt;...
1
2016-06-29T00:09:39Z
[ "python", "python-3.x", "utf-8" ]
how to convert text file to dictionary in python
38,085,125
<p>I need to convert lines of different lengths to one dictionary. It's for player stats. The text file is formatted like below. I need to return a dictionary with each player's stats. </p> <pre><code>{Lebron James:(25,7,1),(34,5,6), Stephen Curry: (25,7,1),(34,5,6), Draymond Green: (25,7,1),(34,5,6)} </code></pre> <...
0
2016-06-28T19:50:58Z
38,085,340
<p>I think this should do what you want:</p> <pre><code>data = {} with open("myfile.txt","r") as f: for line in f: # Skip empty lines line = line.rstrip() if len(line) == 0: continue toks = line.split(",") if len(toks) == 1: # New player, assumed to have no comma...
1
2016-06-28T20:06:09Z
[ "python", "list", "file", "dictionary", "text" ]
how to convert text file to dictionary in python
38,085,125
<p>I need to convert lines of different lengths to one dictionary. It's for player stats. The text file is formatted like below. I need to return a dictionary with each player's stats. </p> <pre><code>{Lebron James:(25,7,1),(34,5,6), Stephen Curry: (25,7,1),(34,5,6), Draymond Green: (25,7,1),(34,5,6)} </code></pre> <...
0
2016-06-28T19:50:58Z
38,085,836
<p>Here's a simple way to do this:</p> <pre><code>scores = {} with open('stats.txt', 'r') as infile: i = 0 for line in infile.readlines(): if line.rstrip(): if i%3!=0: t = tuple(int(n) for n in line.split(",")) j = j+1 if j==1: ...
1
2016-06-28T20:36:34Z
[ "python", "list", "file", "dictionary", "text" ]
how to convert text file to dictionary in python
38,085,125
<p>I need to convert lines of different lengths to one dictionary. It's for player stats. The text file is formatted like below. I need to return a dictionary with each player's stats. </p> <pre><code>{Lebron James:(25,7,1),(34,5,6), Stephen Curry: (25,7,1),(34,5,6), Draymond Green: (25,7,1),(34,5,6)} </code></pre> <...
0
2016-06-28T19:50:58Z
38,145,374
<p>Maybe something like this:</p> <p>For Python 2.x</p> <pre><code>myfile = open("stats.txt","r") lines = filter(None, (line.rstrip() for line in myfile)) dictionary = dict(zip(lines[0::3], zip(lines[1::3], lines[2::3]))) </code></pre> <p>For Python 3.x</p> <pre><code>myfile = open("stats.txt","r") lines = list...
0
2016-07-01T12:22:43Z
[ "python", "list", "file", "dictionary", "text" ]
Python Removing Columns
38,085,150
<p>I am trying to remove the last two columns from my data frame by using Python. </p> <p>The issue is there are cells with values in the last two columns that we don't need, and those columns don't have headers. </p> <p>Here's the code I wrote, but I'm really new to Python, and don't know how to take my original dat...
1
2016-06-28T19:52:56Z
38,085,375
<p>The proper Pythonic way to perform something like this is through <em>slicing</em>:</p> <pre><code>r[start:stop(:step)] </code></pre> <p><code>start</code> and <code>stop</code> are indexes, where positive indexes are counted from the front and negative is counted from the end. Blank <code>start</code>s and <code>...
3
2016-06-28T20:08:18Z
[ "python", "csv" ]
How to get background from cv2.BackgroundSubtractorMOG2?
38,085,179
<p>Is there any way to obtain background from cv2.BackgroundSubtractorMOG2 in python?</p> <p>In other words, is there any technique to compute an image based on last n frames of a video, which can be used as background?</p>
0
2016-06-28T19:54:35Z
38,086,727
<p>Such a technique would be pretty complicated, but you might want to look at some keywords: image-stitching, gradient-based methods, patch-match, image filling. Matlab, for example, <a href="http://www.mathworks.com/help/images/ref/roifill.html" rel="nofollow">has a function</a> that tries to interpolate missing valu...
0
2016-06-28T21:37:27Z
[ "python", "opencv", "image-processing", "motion-detection", "background-subtraction" ]
Search though accounts on flask-stormpath
38,085,226
<p>I have a <code>flask.ext.stormpath</code> instance and I would like to fetch all users (filtered with <code>created_at</code>) I have tried several stuff that are not working</p> <pre><code>flask.ext.stormpath.accounts </code></pre> <p>Sorry for the short question but for clarity, I think I need something like thi...
2
2016-06-28T19:57:30Z
38,086,231
<p>Heyo,</p> <p>When you use Flask-Stormpath, you can access the underlying <code>Application</code> object by saying:</p> <pre><code>stormpath_manager.application </code></pre> <p>This means you can do stuff like:</p> <pre><code>for account in stormpath_manager.application.accounts: print('Email: {}'.format(ac...
2
2016-06-28T21:02:28Z
[ "python", "flask", "stormpath" ]
How to enable detailed database connection logging?
38,085,252
<p>Our DBA is trying to migrate a Django application's database to a new backend host running Oracle 12. When I put that host's info in the Django <code>settings.py</code> file, I get this error:</p> <pre><code>DatabaseError: ORA-28547: connection to server failed, probable Oracle Net admin error </code></pre> <p>Th...
2
2016-06-28T19:59:07Z
38,113,339
<p>Basically you can use a Wireshark or any sniffing tool to check what is the connection string passed to the DB.</p> <p>But this oracle error will occur when there is an error after the initial handshake to the Oracle DB and further establishing a connection.</p> <p>Check you oracle_cx for python and the oracle ins...
0
2016-06-30T03:08:31Z
[ "python", "django", "oracle" ]
How to remove Python tools for Visual Studio (June 2016) uodate notification? It's already installed
38,085,253
<p>I have updated VS 2015 Community to Update 3. According to the installer, this includes Python tools 2.2.4.</p> <p>However, Visual Studio still reports that update is available (from 2.2.3 to 2.2.4) and when I choose to do that, VS Setup starts, but Update button is disabled. </p> <p>It enables if I uncheck Python...
7
2016-06-28T19:59:08Z
38,085,524
<p>I ran into the same issue. <a href="https://ptvs.azureedge.net/download/PTVS%202.2.4%20VS%202015.msi">Downloading the stand-alone installer and running it fixes the issue</a>.</p>
13
2016-06-28T20:16:16Z
[ "python", "visual-studio-2015", "installation" ]
How do I use dictionaries to make functions easily accessable
38,085,363
<p>I declared 3 functions earlier, this is just a goofy text based cookie clicker-esque game.</p> <pre><code>dostuff={"" : turn() , "help" : helpf() , "invest" : invest() } while done != True:&lt;br&gt; do = input("What do you want to do? ") do = do.lower() if do == "" or do == "help" or do == "invest": ...
-1
2016-06-28T20:07:27Z
38,085,436
<p>Your parentheses must be omitted in the dict, and then put at the end of the dict call. You define a function, which becomes a python object. You reference the object with the dict, and then you call the function with the object reference followed by parentheses:</p> <pre><code>def one(): print("one") def tw...
6
2016-06-28T20:12:32Z
[ "python", "python-3.x" ]
Merge values of dictionary into one if keys match condition
38,085,367
<p>I have a dictionary called, say, <code>tempDict</code> which is filled as such:</p> <pre><code>tempDict = {'a': 100, 'b': 200, 'c': 120, 'b_ext1': 4, 'd': 1021, 'a_ext1': 21, 'f_ext1': 12} </code></pre> <p>In my setup, I need to loop over the keys and if for any key that has a '_ext1' suffix, I want to rewrite or ...
1
2016-06-28T20:07:58Z
38,085,493
<pre><code>newDict = {} for k in tempDict: if k.endswith("_ext1") and k[:-5] in tempDict: newDict[k[:-5]] = newDict.get(k[:-5],0)+tempDict[k] else: newDict[k] = newDict.get(k,0)+tempDict[k] </code></pre>
1
2016-06-28T20:14:47Z
[ "python", "dictionary" ]
Merge values of dictionary into one if keys match condition
38,085,367
<p>I have a dictionary called, say, <code>tempDict</code> which is filled as such:</p> <pre><code>tempDict = {'a': 100, 'b': 200, 'c': 120, 'b_ext1': 4, 'd': 1021, 'a_ext1': 21, 'f_ext1': 12} </code></pre> <p>In my setup, I need to loop over the keys and if for any key that has a '_ext1' suffix, I want to rewrite or ...
1
2016-06-28T20:07:58Z
38,085,606
<p>Iterate over the keys (items) in the sorted order and sum or add values. This works because keys like <code>"a"</code>, <code>"f"</code> sort before "<code>a_ext1"</code>, <code>"f_ext1"</code>:</p> <pre><code>&gt;&gt;&gt; d = {} &gt;&gt;&gt; for k, v in sorted(tempDict.items()): ... if k[0] in d: ... d...
1
2016-06-28T20:22:03Z
[ "python", "dictionary" ]
Save title of button to django feild
38,085,445
<p>I have a button in my HTML that has a title attribute that changes depending on if I press a checkbox inside the button. The title is a list of all the elements inside the button that are checked. </p> <p>(NOTICE THE TITLE ATTRIBUTE OF THE BUTTON TAG RELATES TO THE ITEMS THAT ARE CHECKED)</p> <p><strong>I was wond...
0
2016-06-28T20:13:03Z
38,085,637
<p>Instead of a <code>button</code> and a <code>title</code> attr, I would use a form <code>input</code> element with a <code>type=hidden</code>. Reason being that it will post that data back to the server function that corresponds to that URL. Allowing you to save that data into a field of your choice.</p> <p>As far ...
1
2016-06-28T20:24:02Z
[ "python", "html", "django", "django-models", "django-forms" ]
Do Django templates implement short-circuiting for logical expressions?
38,085,468
<p>Suppose I have the following in my Django template:</p> <pre><code>{% if a != None and a.b &gt; 5 %} </code></pre> <p>Can I be certain that <code>a.b &gt; 5</code> won't be evaluated if <code>a</code> is None?</p> <p>IE: Does python's short-circuiting while evaluating logical expressions kick in in Django templat...
1
2016-06-28T20:13:43Z
38,085,693
<p>Yes, it will short-circuit. I have taken a peek into the source of Django 1.9.2 and think I found <a href="https://github.com/django/django/blob/master/django/template/smartif.py#L93" rel="nofollow">the relevant code</a>.</p> <pre><code># Operator precedence follows Python. # NB - we can get slightly more accurate ...
2
2016-06-28T20:26:58Z
[ "python", "django", "django-templates" ]
Do Django templates implement short-circuiting for logical expressions?
38,085,468
<p>Suppose I have the following in my Django template:</p> <pre><code>{% if a != None and a.b &gt; 5 %} </code></pre> <p>Can I be certain that <code>a.b &gt; 5</code> won't be evaluated if <code>a</code> is None?</p> <p>IE: Does python's short-circuiting while evaluating logical expressions kick in in Django templat...
1
2016-06-28T20:13:43Z
38,085,698
<p>This behavior doesn't appear to be specified in the official documentation, but the presence of <a href="https://code.djangoproject.com/ticket/13373" rel="nofollow">bug #13373</a> implies they do, except in v1.2 beta.</p> <p>The fix made in <a href="https://github.com/django/django/commit/fef0d25bdc" rel="nofollow"...
1
2016-06-28T20:27:12Z
[ "python", "django", "django-templates" ]
Installing opencv in python
38,085,480
<p>I'm having some trouble installing OpenCV. I have been using Anaconda, and I copied the <code>cv2.pyd</code> file into the <code>...\Lib\site-packages</code> folder. When I get type <code>import cv2</code> into Python I get this error: </p> <pre><code>`Traceback (most recent call last): File "&lt;stdin&gt;", lin...
1
2016-06-28T20:14:14Z
38,085,594
<p>I think the proper input should be 'import cv2' not 'install cv2'. After this print cv2.<strong>version</strong> should show you that it installed properly. Hope this helps. </p>
0
2016-06-28T20:21:14Z
[ "python", "opencv" ]
Installing opencv in python
38,085,480
<p>I'm having some trouble installing OpenCV. I have been using Anaconda, and I copied the <code>cv2.pyd</code> file into the <code>...\Lib\site-packages</code> folder. When I get type <code>import cv2</code> into Python I get this error: </p> <pre><code>`Traceback (most recent call last): File "&lt;stdin&gt;", lin...
1
2016-06-28T20:14:14Z
38,085,668
<p>Try running the following:</p> <pre><code>$ python &gt;&gt;&gt; import cv2 &gt;&gt;&gt; print cv2.__version__ </code></pre>
0
2016-06-28T20:25:57Z
[ "python", "opencv" ]
Shutdown EC2 instances that do not have a certain tag using Python
38,085,482
<p>I'm using this script by mlapida posted here: <a href="https://gist.github.com/mlapida/1917b5db84b76b1d1d55#file-ec2-stopped-tagged-lambda-py" rel="nofollow">https://gist.github.com/mlapida/1917b5db84b76b1d1d55#file-ec2-stopped-tagged-lambda-py</a></p> <p>The script by mlapida does the opposite of what I need, I'm...
1
2016-06-28T20:14:20Z
38,085,623
<p>That's should do the trick:</p> <pre><code># open connection to ec2 conn = get_ec2_conn() # get a list of all instances all_instances = conn.get_all_instances() # get instances with filter of running + with tag `Name` instances = conn.get_all_instances(filters={'tag-key': 'Name', 'instance-state-name': 'running'}) ...
1
2016-06-28T20:23:15Z
[ "python", "amazon-web-services", "amazon-ec2", "tags", "boto3" ]
Shutdown EC2 instances that do not have a certain tag using Python
38,085,482
<p>I'm using this script by mlapida posted here: <a href="https://gist.github.com/mlapida/1917b5db84b76b1d1d55#file-ec2-stopped-tagged-lambda-py" rel="nofollow">https://gist.github.com/mlapida/1917b5db84b76b1d1d55#file-ec2-stopped-tagged-lambda-py</a></p> <p>The script by mlapida does the opposite of what I need, I'm...
1
2016-06-28T20:14:20Z
38,920,142
<p>With credits to mlapida and Yonatan, I have a working script that shuts down all instances that don't have a tag "AutoOff" and any instance that does have "AutoOff" set to "False" stays on, hope this helps someone out there.</p> <pre><code>import boto3 import logging #setup simple logging for INFO logger = logging...
0
2016-08-12T14:13:42Z
[ "python", "amazon-web-services", "amazon-ec2", "tags", "boto3" ]
Element-wise weave of two arrays used with numpy repeat
38,085,486
<p>I have two arrays of unequal length <em>val1</em> and <em>val2</em> that I am trying to weave together in a specific way that is defined by the equal-length arrays <em>mult1</em> and <em>mult2</em>. In general, my arrays are very long (~1e6 elements), and this is a performance-critical bottleneck in my calculation, ...
2
2016-06-28T20:14:37Z
38,086,671
<p>This can be done with NumPy routines, but the best I've come up with is pretty clumsy:</p> <pre><code>reps = numpy.empty([len(mult1)*2], dtype=int) reps[::2] = mult1 reps[1::2] = mult2 to_repeat = numpy.empty_like(reps) to_repeat[::2] = -1 # Avoid using 0 and 1 in case either of val1 or val2 is empty to_repeat[1...
2
2016-06-28T21:32:59Z
[ "python", "arrays", "performance", "numpy", "scientific-computing" ]
Element-wise weave of two arrays used with numpy repeat
38,085,486
<p>I have two arrays of unequal length <em>val1</em> and <em>val2</em> that I am trying to weave together in a specific way that is defined by the equal-length arrays <em>mult1</em> and <em>mult2</em>. In general, my arrays are very long (~1e6 elements), and this is a performance-critical bottleneck in my calculation, ...
2
2016-06-28T20:14:37Z
38,087,526
<p>Creating a Boolean index into the result array:</p> <pre><code>mult = np.array([mult1, mult2]).ravel('F') tftf = np.tile([True, False], len(mult1)) mask = np.repeat(tftf, mult) result = np.empty(len(val1) + len(val2), int) result[ mask] = val1 result[~mask] = val2 </code></pre> <p>Edit - I believe this works too:...
4
2016-06-28T22:52:14Z
[ "python", "arrays", "performance", "numpy", "scientific-computing" ]
Random Sample of a subset of a dataframe in Pandas
38,085,547
<p>Say i have a dataframe with 100,000 entries and want to split it into 100 sections of 1000 entries. </p> <p>How do i take a random sample of say size 50 of just one of the 100 sections. the data set is already ordered such that the first 1000 results are the first section the next section the next and so on. </p> ...
3
2016-06-28T20:17:46Z
38,085,643
<p>One solution is to use the <code>choice</code> function from numpy.</p> <p>Say you want 50 entries out of 100, you can use:</p> <pre><code>import numpy as np chosen_idx = np.random.choice(1000, replace=False, size=50) df_trimmed = df.iloc[chosen_idx] </code></pre> <p>This is of course not considering your block s...
3
2016-06-28T20:24:16Z
[ "python", "pandas", "sample", "random-sample" ]
Random Sample of a subset of a dataframe in Pandas
38,085,547
<p>Say i have a dataframe with 100,000 entries and want to split it into 100 sections of 1000 entries. </p> <p>How do i take a random sample of say size 50 of just one of the 100 sections. the data set is already ordered such that the first 1000 results are the first section the next section the next and so on. </p> ...
3
2016-06-28T20:17:46Z
38,085,885
<p>You can use the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sample.html" rel="nofollow"><code>sample</code></a> method*:</p> <pre><code>In [11]: df = pd.DataFrame([[1, 2], [3, 4], [5, 6], [7, 8]], columns=["A", "B"]) In [12]: df.sample(2) Out[12]: A B 0 1 2 2 5 6 In [13...
1
2016-06-28T20:39:54Z
[ "python", "pandas", "sample", "random-sample" ]
How to scrape data with authentication where my login page and profile have the same url?
38,085,554
<p>I want to scrape data from my profile but the website I use has the same URL for both login and Profile .so for this </p> <pre><code>import urllib, urllib2, cookielib username = 'myuser' password = 'mypassword' cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) login_data = ...
0
2016-06-28T20:18:03Z
38,085,725
<p>@Padraic Cunningham beat me to it, but the requests module is what you need</p> <p><a href="http://docs.python-requests.org/en/master/" rel="nofollow">http://docs.python-requests.org/en/master/</a></p> <pre><code>import requests username = 'myuser' password = 'mypassword' s = requests.session() l = {'username': ...
1
2016-06-28T20:29:19Z
[ "python", "web-scraping", "web-crawler" ]
Python quit unexpectedly, Segmentation fault: 11
38,085,560
<p>I have installed python 2.7.12. I used "pip install pulp" to install pulp package. My problem is that "import pulp" gives me the following error. How can I solve this problem. Let me know if you need something else to debug. I have a Mackbook pro with El Capitan 10.11.5 os.</p> <pre><code>import pulp Segmentation f...
0
2016-06-28T20:18:35Z
38,085,690
<p>Did you run the tests? From the <a href="https://pypi.python.org/pypi/PuLP" rel="nofollow">pypi</a> page</p> <blockquote> <p>On Linux and OSX systems the tests must be run to make the default solver executable.</p> </blockquote>
0
2016-06-28T20:26:46Z
[ "python", "osx", "python-2.7", "pulp" ]
Python quit unexpectedly, Segmentation fault: 11
38,085,560
<p>I have installed python 2.7.12. I used "pip install pulp" to install pulp package. My problem is that "import pulp" gives me the following error. How can I solve this problem. Let me know if you need something else to debug. I have a Mackbook pro with El Capitan 10.11.5 os.</p> <pre><code>import pulp Segmentation f...
0
2016-06-28T20:18:35Z
38,085,752
<p>If it does not work after running the tests as recommended by Brendan Abel, according to a similar post <a href="https://groups.google.com/forum/#!topic/pulp-or-discuss/Um1BIvlVS5M" rel="nofollow">here</a> it seems to have worked with Python 2.6 on Mac, if that is an option I would suggest trying it</p>
0
2016-06-28T20:31:01Z
[ "python", "osx", "python-2.7", "pulp" ]
How use netaddr to convert subnet mask to cidr in Python
38,085,571
<p>How can I convert a ipv4 subnet mask to cidr notation using <code>netaddr</code> library?<br> Example: <code>255.255.255.0 to /24</code></p>
0
2016-06-28T20:19:26Z
38,085,892
<p>You could just count 1-bits in the binary representation of the netmask:</p> <pre><code>&gt;&gt;&gt; netmask = "255.255.255.0" &gt;&gt;&gt; sum([bin(int(x)).count("1") for x in netmask.split(".")]) 24 </code></pre>
0
2016-06-28T20:40:15Z
[ "python", "cidr" ]
How use netaddr to convert subnet mask to cidr in Python
38,085,571
<p>How can I convert a ipv4 subnet mask to cidr notation using <code>netaddr</code> library?<br> Example: <code>255.255.255.0 to /24</code></p>
0
2016-06-28T20:19:26Z
38,959,259
<pre><code>&gt;&gt;&gt; IPNetwork('0.0.0.0/255.255.255.0').prefixlen 24 </code></pre>
1
2016-08-15T16:43:21Z
[ "python", "cidr" ]
Pandas create Foreign ID column based on Name column
38,085,624
<p>I have a simple dataframe like this for example:</p> <pre><code>df = pd.DataFrame({'Name': ['John Doe', 'Jane Smith', 'John Doe', 'Jane Smith','Jack Dawson','John Doe']}) df: Name 0 John Doe 1 Jane Smith 2 John Doe 3 Jane Smith 4 Jack Dawson 5 John Doe </code></pre> <p>I...
2
2016-06-28T20:23:24Z
38,085,759
<p>I would use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.cumcount.html" rel="nofollow">groupby's cumcount</a>:</p> <pre><code>In [11]: df.groupby("Name").cumcount() Out[11]: 0 0 1 0 2 1 3 1 4 0 5 2 dtype: int64 In [11]: df["Foreign_Key"] = df.groupby(...
2
2016-06-28T20:31:13Z
[ "python", "pandas", "dataframe", "foreign-keys" ]
Pandas create Foreign ID column based on Name column
38,085,624
<p>I have a simple dataframe like this for example:</p> <pre><code>df = pd.DataFrame({'Name': ['John Doe', 'Jane Smith', 'John Doe', 'Jane Smith','Jack Dawson','John Doe']}) df: Name 0 John Doe 1 Jane Smith 2 John Doe 3 Jane Smith 4 Jack Dawson 5 John Doe </code></pre> <p>I...
2
2016-06-28T20:23:24Z
38,085,798
<p>You can do:</p> <pre><code>pd.merge( df, pd.DataFrame(df.Name.unique(), columns=['Name']).reset_index().rename(columns={'index': 'Foreign_Key'}), on='Name' ) Name Foreign_Key 0 John Doe 0 1 John Doe 0 2 Jane Smith 1 3 Jane Smith 1 </code></p...
3
2016-06-28T20:34:08Z
[ "python", "pandas", "dataframe", "foreign-keys" ]
How do I base64 encode a buffered read in Python?
38,085,639
<p>I'm streaming a png to the browser for use in an img src attribute. </p> <pre><code>def streamer(): with open(local_path) as fh: while True: rbuf = fh.read(READ_BUF_SIZE) if not rbuf: break yield rbuf </code></pre> <p>I want to...
0
2016-06-28T20:24:09Z
38,085,680
<pre><code>for part in streamer(): print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" print base64.b64encode(part) print "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" </code></pre>
0
2016-06-28T20:26:29Z
[ "python", "python-2.7" ]
How do I base64 encode a buffered read in Python?
38,085,639
<p>I'm streaming a png to the browser for use in an img src attribute. </p> <pre><code>def streamer(): with open(local_path) as fh: while True: rbuf = fh.read(READ_BUF_SIZE) if not rbuf: break yield rbuf </code></pre> <p>I want to...
0
2016-06-28T20:24:09Z
38,085,704
<p><code>base64.b64encode</code> requires bytes or a string (depending on the Python version).</p> <p>If you don't mind reading the entire file into memory, first create the full string and then encode it:</p> <pre><code>base64.b64encode(''.join(streamer())) </code></pre> <p>If you want to encode as you go, just be ...
0
2016-06-28T20:27:30Z
[ "python", "python-2.7" ]
What is different with pickled data between 3.2 (wheezy) and 3.4 (jessie)?
38,085,679
<p>I have a python 3.x client that runs on a raspberry pi. It provides camera setting information to a server running winpython 3.4 by pickling on the PI and unpickling on the server. </p> <p>This works fine when the pi is running wheezy and python 3.2, but when I try it on a PI running jessy and python 3.4 the unpick...
1
2016-06-28T20:26:29Z
38,093,695
<p><code>pickle</code> is a format which is tightly related to the python bytecode of the object you want to serialize. The bytecode may change from on python version to an other. Therefor you can only exchange pickeled data between programs which are run with the same python version.</p> <p>You can use for example th...
0
2016-06-29T08:01:54Z
[ "python", "pickle" ]
What is different with pickled data between 3.2 (wheezy) and 3.4 (jessie)?
38,085,679
<p>I have a python 3.x client that runs on a raspberry pi. It provides camera setting information to a server running winpython 3.4 by pickling on the PI and unpickling on the server. </p> <p>This works fine when the pi is running wheezy and python 3.2, but when I try it on a PI running jessy and python 3.4 the unpick...
1
2016-06-28T20:26:29Z
38,095,094
<p>thanks @Dilettant, @Sebastian Stigler,@ppperry</p> <p>The issue is an undocumented change to the base PiCamera class providing the resolution data that is being pickled. Originally it provided a Tuple, and now a 'picamera.mmalobj.PiCameraResolution' object. I added a check to see if the object was a tuple or not an...
0
2016-06-29T09:10:29Z
[ "python", "pickle" ]
Receiving the same invalid Jawbone Api token
38,085,886
<p>I am having trouble with the Jawbone API. When I step through the oauth proess using <a href="https://github.com/karthikbgl/python-jawbone-up.git" rel="nofollow">https://github.com/karthikbgl/python-jawbone-up.git</a> I can successfully receive an authorization code and then get a token. </p> <pre><code>def access_...
0
2016-06-28T20:39:57Z
38,686,484
<p>I had the same issue. I think that this answer is what is happening: <a href="http://stackoverflow.com/a/32984287/1732987">http://stackoverflow.com/a/32984287/1732987</a></p> <p>To get around it, I had to log out of all Jawbone stuff in by browser, remove the access token from my new application database, and star...
0
2016-07-31T17:12:48Z
[ "python", "oauth", "oauth-2.0", "access-token", "jawbone" ]
Return a column which meet two conditions with pandas dataframe
38,085,919
<p>I am very new to python, and here I have a question I don't know how to fix, please help.</p> <p>Here is the thing: I have a dataframe, and I want to extract a column which meets two different conditions.</p> <p>The columns is as follows:</p> <pre><code> state gender year name births 13299 AK ...
0
2016-06-28T20:41:42Z
38,086,081
<p>I've defined <code>df1</code> to further process. I've set the index to be <code>['name', 'gender']</code>, then <code>unstack</code> to get 'gender' into columns. <code>.births</code> to focus on births. Then I divide the min by the max to avoid dividing by zero.</p> <pre><code>df1 = df.set_index(['name', 'gend...
1
2016-06-28T20:51:01Z
[ "python", "numpy", "pandas", "dataframe" ]
Return a column which meet two conditions with pandas dataframe
38,085,919
<p>I am very new to python, and here I have a question I don't know how to fix, please help.</p> <p>Here is the thing: I have a dataframe, and I want to extract a column which meets two different conditions.</p> <p>The columns is as follows:</p> <pre><code> state gender year name births 13299 AK ...
0
2016-06-28T20:41:42Z
38,086,134
<p>Pivot table in pandas works fine here:</p> <pre><code>pvt = pd.pivot_table(df,values='births',columns='gender',index='name',aggfunc='sum') pvt[pvt['M'] == pvt['F']] </code></pre> <p>This returns a dataframe with name as an index and M,F for columns. It's unlikely that unisex names will be exactly equal though so y...
1
2016-06-28T20:54:31Z
[ "python", "numpy", "pandas", "dataframe" ]
Heroku Python Web process failed to bind to $PORT within 60 seconds - not the obvious
38,085,948
<p>OK similar questions answered before with simple solution. Don't think this is the same. First is my code then is the log. I am using the provided PORT env variable but I still get this error.</p> <pre><code>if __name__ == "__main__": import sys print( 'HELLO %s' % str(sys.argv[1])) #import os impor...
0
2016-06-28T20:43:13Z
38,086,469
<p>OK there are a couple of gotchas on this one. By far the most common is not to use the port specified in the environment variable PORT. The second is to use localhost or 127.0.0.1 (or leave to default) the host you specify. Specifying the host as 0.0.0.0 fixed it for me.</p> <pre><code>if __name__ == "__main__": ...
1
2016-06-28T21:18:03Z
[ "python", "heroku", "cherrypy" ]
Flip and rotate numpy array
38,086,005
<p>Is there a faster way of flipping and rotating an array in numpy? For example, rotating one time clockwise and then flipping? </p> <pre><code>import numpy as np a = np.arange(0,10) b = np.arange(-11,-1) ar = np.array([a,b]) print ar print ar.shape ar = np.rot90(ar, 3) print np.fliplr(ar) print ar.shape </code></...
1
2016-06-28T20:46:26Z
38,086,074
<p>A flip and rotate together (based on your example) is a <a href="https://en.wikipedia.org/wiki/Matrix_transpose" rel="nofollow"><em>matrix transpose</em></a>: a matrix transpose is a permutation of the matrix's dimensions: for instance the first dimension becomes the second dimension and vice versa.</p> <p><a href=...
1
2016-06-28T20:50:50Z
[ "python", "arrays", "numpy" ]
Flip and rotate numpy array
38,086,005
<p>Is there a faster way of flipping and rotating an array in numpy? For example, rotating one time clockwise and then flipping? </p> <pre><code>import numpy as np a = np.arange(0,10) b = np.arange(-11,-1) ar = np.array([a,b]) print ar print ar.shape ar = np.rot90(ar, 3) print np.fliplr(ar) print ar.shape </code></...
1
2016-06-28T20:46:26Z
38,086,097
<p>That will be <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.transpose.html" rel="nofollow"><code>transpose</code></a>:</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; a = np.arange(0,10) &gt;&gt;&gt; b = np.arange(-11,-1) &gt;&gt;&gt; ar = np.array([a,b]) &gt;&gt;&gt; ar.T array([[ ...
1
2016-06-28T20:51:48Z
[ "python", "arrays", "numpy" ]
Flip and rotate numpy array
38,086,005
<p>Is there a faster way of flipping and rotating an array in numpy? For example, rotating one time clockwise and then flipping? </p> <pre><code>import numpy as np a = np.arange(0,10) b = np.arange(-11,-1) ar = np.array([a,b]) print ar print ar.shape ar = np.rot90(ar, 3) print np.fliplr(ar) print ar.shape </code></...
1
2016-06-28T20:46:26Z
38,087,336
<p>The code for <code>np.rot90</code> does, in your case of <code>k=3</code>:</p> <pre><code> # k == 3 return fliplr(m.swapaxes(0, 1)) </code></pre> <p>So</p> <pre><code>In [789]: np.fliplr(ar.swapaxes(0, 1)) Out[789]: array([[-11, 0], ... [ -3, 8], [ -2, 9]]) </code></pre> <p>So yo...
2
2016-06-28T22:31:05Z
[ "python", "arrays", "numpy" ]
What mistake am I making in this python script?
38,086,055
<p>I trying to play around with multi-threading so I can better at it, but for some weird reason, my code doesn't want to follow the commands. It's suppose to go into a while loop and print, but it doesn't, and it's also not raising any errors, so which lines is the mistake on?</p> <pre><code>#!/usr/bin/env python # ...
-1
2016-06-28T20:49:38Z
38,086,154
<p>Add this to the bottom:</p> <pre><code>while True: pass </code></pre> <p>The problem is that you're running off the bottom of your main program. This terminates the entire execution session.</p>
1
2016-06-28T20:55:51Z
[ "python", "multithreading", "python-2.7" ]
What mistake am I making in this python script?
38,086,055
<p>I trying to play around with multi-threading so I can better at it, but for some weird reason, my code doesn't want to follow the commands. It's suppose to go into a while loop and print, but it doesn't, and it's also not raising any errors, so which lines is the mistake on?</p> <pre><code>#!/usr/bin/env python # ...
-1
2016-06-28T20:49:38Z
38,086,349
<p>You can either do what Prune here suggested, or you can suspend the main thread after initiating DisplayA, DisplayB and DisplayC.</p>
0
2016-06-28T21:10:03Z
[ "python", "multithreading", "python-2.7" ]
What mistake am I making in this python script?
38,086,055
<p>I trying to play around with multi-threading so I can better at it, but for some weird reason, my code doesn't want to follow the commands. It's suppose to go into a while loop and print, but it doesn't, and it's also not raising any errors, so which lines is the mistake on?</p> <pre><code>#!/usr/bin/env python # ...
-1
2016-06-28T20:49:38Z
38,086,798
<p>Quick and short solution:</p> <pre><code>while True: time.sleep(1) </code></pre> <p>Do not use pass in the while loop, because it eats CPU. Expensive way of doing nothing.</p> <p>If you want a more general solution, then you can import Tread from threading, then you can use join:</p> <pre><code>from threadin...
1
2016-06-28T21:43:28Z
[ "python", "multithreading", "python-2.7" ]
How do I filter through commands when I use help in cmd?
38,086,120
<p>Since I have imported <code>cmd</code> into my project, I get a lot of unnecessary commands that I do not need. When I am in the interpreter and simply type <code>help</code>, I get all of my defs listed, and a bunch of these other commands. Is there a way to filter those so that when I type <code>help</code> I only...
1
2016-06-28T20:53:36Z
38,086,223
<p>From the doc on the <a href="https://docs.python.org/3.5/library/cmd.html" rel="nofollow">cmd</a> module:</p> <blockquote> <p>With no argument, <code>do_help()</code> lists all available help topics (that is, all commands with corresponding <code>help_*()</code> methods or commands that have docstrings), and ...
1
2016-06-28T21:01:57Z
[ "python", "cmd", "command-line-interface" ]
Issues with If Else statements
38,086,138
<p>I am learning Python from scratch in the sense that I do not have much coding background. In this particular exercise, I am given the task of taking a text file, removing the spaces and commas, then printing it out as seven individual lines (which I have done.) Now, that I finished the task, I need to display real, ...
0
2016-06-28T20:54:42Z
38,086,367
<p>I think your indentation is wrong, and you should be checking for the type of the total, not total==int:</p> <pre><code>from datetime import datetime from datetime import timedelta with open("RandomFile.txt", "r") as inp: with open("RandomFileOutput.txt", "w") as outp: clock = datetime.now() ...
1
2016-06-28T21:11:04Z
[ "python", "datetime" ]
Extracting a string from a file, given a position and length
38,086,174
<p>I am writing code to retrieve specific characters in a text file by position. For example, I want the sequence of characters between positions of 1043-1049 out of a text, like:</p> <blockquote> <p>.........acddex.............</p> </blockquote> <p>...and so on. I want that "acddex" sequence out of that text. I kn...
0
2016-06-28T20:57:12Z
38,086,279
<pre><code>stuff = "agoejngodgfjnsodjnfvsojdnvodfjnodjnfbodjngodjgndojgndlkfnvldfkngldjnfgdfjgnldjfn" print(stuff[10:20]) </code></pre> <p>This will print the characters from position 10 to 20.</p> <p>So, if you want 1043-1049:</p> <pre><code>print(stuff[1043:1049]) </code></pre>
0
2016-06-28T21:05:35Z
[ "python" ]
Extracting a string from a file, given a position and length
38,086,174
<p>I am writing code to retrieve specific characters in a text file by position. For example, I want the sequence of characters between positions of 1043-1049 out of a text, like:</p> <blockquote> <p>.........acddex.............</p> </blockquote> <p>...and so on. I want that "acddex" sequence out of that text. I kn...
0
2016-06-28T20:57:12Z
38,086,449
<p><a href="http://stackoverflow.com/q/11696472/2615940">Seek to the byte position of the start of the sequence you want</a>, then call <a href="https://docs.python.org/3.5/tutorial/inputoutput.html#methods-of-file-objects" rel="nofollow">read</a> and tell it how many bytes you want.</p> <p>Example:</p> <pre><code>st...
1
2016-06-28T21:16:40Z
[ "python" ]
UnicodeDecodeError when write to excel using python
38,086,195
<p>I try to add_sheet to exccel file with</p> <p><code>df.groupby('member_id').apply(lambda x: add_xlsx_sheet(x, u'Десктопы полно'.decode('utf-8'), path='{}.xlsx'.format(x.name))) </code> function </p> <pre><code>def add_xlsx_sheet(df, sheet_name=u'Смартфоны кратко', index=True, digits=2, ...
0
2016-06-28T20:59:09Z
38,087,370
<p>The error is occuring due to the code snippet</p> <pre><code>u'Десктопы полно'.decode('utf-8') </code></pre> <p>The prefix 'u' makes a string a <em>Unicode string</em>. The Unicode string is not actually encoded in anyway and is already in the decoded form.</p> <p>For example, </p> <pre><code>&gt;&...
0
2016-06-28T22:33:55Z
[ "python", "excel", "pandas" ]
Using Enums to inspect attributes of a class/instance in python
38,086,215
<p>I'm working through a mechanical systems (for example, a simple helical gear) and want to prevent users from assigning values not found in an associated enum. I am new to enums and 'pythonic' approaches to answering this question...so my request is two-fold:</p> <ol> <li>Is it more appropriate in python to let inpu...
2
2016-06-28T21:01:10Z
38,086,342
<ol> <li><p>Error handling should happen as close to the origin of the error as possible. So whether users are entering data in or functions/classes are accepting data, that data should be checked and dealt with immediately.</p></li> <li><p>Where you define the Enum is entirely up to you, but I tend to leave them at t...
3
2016-06-28T21:09:42Z
[ "python", "enums" ]
Using Enums to inspect attributes of a class/instance in python
38,086,215
<p>I'm working through a mechanical systems (for example, a simple helical gear) and want to prevent users from assigning values not found in an associated enum. I am new to enums and 'pythonic' approaches to answering this question...so my request is two-fold:</p> <ol> <li>Is it more appropriate in python to let inpu...
2
2016-06-28T21:01:10Z
38,086,519
<p>There is no answer appropriate in general - it really depends on how you use your objects.</p> <p>An important concept of python is duck typing - that is, whether an object is appropriate is defined by its features, not its type. In your example, think about what an enum is: a mapping of a name to an integer.</p> ...
1
2016-06-28T21:21:08Z
[ "python", "enums" ]
How to change User representation in Django Admin when used as Foreign Key?
38,086,235
<p>I have a few models having User as Foreign Key. The User list is displaying the username, but I'd like to customize it. Do I have to extend the User model with a custom model and write my own <code>__str__</code> function? Is there an easier way? I don't think you can use a callable for fieldset, right?</p>
0
2016-06-28T21:02:48Z
38,086,499
<p>You can use Django Admin Tools from <a href="https://github.com/django-admin-tools/django-admin-tools" rel="nofollow">https://github.com/django-admin-tools/django-admin-tools</a> to specify which fields you want to be inline editable if you need, so you can use custom user admin in your admin.py:</p> <pre><code>fro...
0
2016-06-28T21:19:52Z
[ "python", "django", "django-admin" ]
Enumerate all possibilities in array with descending values
38,086,312
<p>I'm trying to write a recursive approach to enumerate all possible values of an array of arbitrary length whose elements can all descend to one. More formally, given an array A with the elements, A_1, A_2,...,A_N and array B with B_1,B_2...B_N. There is a relationship between A_i and B_i, where i is between 1 and N ...
0
2016-06-28T21:08:00Z
38,086,556
<p>The function / tool you are looking for is called the "Cartesian Product", which has been implemented in many places, including itertools.</p> <p><a href="https://docs.python.org/3.5/library/itertools.html#itertools.product" rel="nofollow">itertools.product</a>(*iterables[, repeat])</p> <p>This might also be usefu...
4
2016-06-28T21:24:13Z
[ "python", "recursion", "array-algorithms" ]
Enumerate all possibilities in array with descending values
38,086,312
<p>I'm trying to write a recursive approach to enumerate all possible values of an array of arbitrary length whose elements can all descend to one. More formally, given an array A with the elements, A_1, A_2,...,A_N and array B with B_1,B_2...B_N. There is a relationship between A_i and B_i, where i is between 1 and N ...
0
2016-06-28T21:08:00Z
38,086,971
<p>Basically for every column you have a set of 'allowed' values. By picking a value from each of these sets and putting it in a relevant column you generate a valid "related" array. You just need to try all the possibilities.</p> <p>Recursively, you need to make problem smaller. You may recurse on array length here...
0
2016-06-28T21:57:16Z
[ "python", "recursion", "array-algorithms" ]
Calling python functions from command prompt with arguments and capturing the return values in GDB
38,086,354
<p>The tried the below python script(I call it sample.py).It does the lookup on a c++ code in GDB</p> <pre><code>import gdb def getstring(): string = "RandomSearchString" value = gdb.lookup_symbol(string) print("string %s is at sym %s" %(string, value)) </code></pre> <p>It works perfectly fine. But I want...
0
2016-06-28T21:10:16Z
38,108,856
<p>I was able to do using convenience variables and pretty printers.</p>
0
2016-06-29T19:49:00Z
[ "python", "gdb" ]
Line Profiling inner function with Cython
38,086,398
<p>I've had pretty good success using <a href="http://stackoverflow.com/questions/28301931/how-to-profile-cython-functions-line-by-line">this answer</a> to profile my Cython code, but it doesn't seem to work properly with nested functions. In <a href="https://nbviewer.jupyter.org/gist/ChriZiegler/31e719d30d79d5ee62e18d...
7
2016-06-28T21:14:01Z
38,170,831
<h2>tl,dr:</h2> <p>This is seems to be an issue with <code>Cython</code>, there's a hackish way that does the trick but isn't reliable, you could use it for one-off cases until this issue has been fixed<sup>*</sup></p> <h3>Change the <code>line_profiler</code> source:</h3> <p>I can't be 100% sure for this but it is ...
3
2016-07-03T14:17:19Z
[ "python", "cython", "nested-function" ]
How to count unique combinations of variable in a Pandas Dataframe
38,086,432
<p>I'm using pandas to count unique combinations of sets of variables in a dataframe. I'm currently using the .groupby() function, but I think I'm missing part of it's functionality.</p> <p>Example code:</p> <pre><code>import pandas df = pd.DataFrame([['A','C','G'], ['A','C','H'], ...
3
2016-06-28T21:15:59Z
38,086,479
<p>How about <code>nunique</code>?</p> <pre><code>df.groupby('a')['b'].nunique() Out[36]: a A 2 B 2 Name: b, dtype: int64 </code></pre>
6
2016-06-28T21:18:47Z
[ "python", "database", "pandas", "group-by" ]
VOLTTRON Failing Bacnet Proxy agent
38,086,466
<p>I am trying to configure bacnet proxy agent in <a href="https://github.com/VOLTTRON/volttron" rel="nofollow">Volttron Project</a> and for some reason i am getting this error in volltron.log when i start the proxy agent:</p> <p>Can you please guide whether I am doing anything wrong in configuration files ? For IP ad...
1
2016-06-28T21:17:50Z
38,087,492
<p>This is a common mistake. When you setup the bacnet proxy you are, in essence, creating a new BACnet device and putting it on the network. The VOLTTRON platform BACnet drivers then use this device to communicate with the devices on your network. </p> <p><em>This device will have nothing in common with any other dev...
3
2016-06-28T22:49:39Z
[ "python", "python-2.7", "bacnet", "volttron" ]
VOLTTRON Failing Bacnet Proxy agent
38,086,466
<p>I am trying to configure bacnet proxy agent in <a href="https://github.com/VOLTTRON/volttron" rel="nofollow">Volttron Project</a> and for some reason i am getting this error in volltron.log when i start the proxy agent:</p> <p>Can you please guide whether I am doing anything wrong in configuration files ? For IP ad...
1
2016-06-28T21:17:50Z
38,087,607
<p>In other words, the device_address that goes into the proxy config is your local address so that the bacnet driver can bind to an interface on the device.</p>
2
2016-06-28T22:59:25Z
[ "python", "python-2.7", "bacnet", "volttron" ]
How to show/hide widgets in Tkinter?
38,086,482
<p>I am attempting to create a program that performs a function given a series of user inputs. Several of the user inputs are only necessary under certain circumstances, and I would like to, if possible, only show the Entry boxes and Labels for those input values when a Checkbutton is selected indicating that the circu...
2
2016-06-28T21:18:58Z
38,086,716
<p>I think you want <code>grid_remove()</code>.</p> <p>From <a href="http://www.tkdocs.com/tutorial/grid.html" rel="nofollow">http://www.tkdocs.com/tutorial/grid.html</a>:</p> <blockquote> <p>The "forget" method of grid, taking as arguments a list of one or more slave widgets, can be used to remove slaves from th...
2
2016-06-28T21:36:18Z
[ "python", "tkinter" ]
Django: Input fields in submitted form not showing
38,086,598
<p>So I am starting to switch form models to class base views. In <code>EpisodeInfoView</code>, when I comment or uncomment <code>production = Production.objects.create(podcast=podcast)</code> under <code>if podcast</code> in my <code>get</code> method in <code>pod_funnel.py</code>, it will show the form and let me fil...
1
2016-06-28T21:27:07Z
38,088,781
<p>I would consider using CreateView/UpdateView and initial data dictionary for setting values then moving your save functions to the form itself. This way the view is much smaller, and the logic is in the form.</p> <p>This would be similar for the admin: <a href="https://djangosnippets.org/snippets/1727/" rel="nofoll...
0
2016-06-29T01:21:25Z
[ "python", "django", "django-models", "django-forms", "django-class-based-views" ]
Nested for loop : List - Not getting the desired output
38,086,629
<p>What I want to do is to estimate the score of each peptide i.e. row</p> <p>My code is as following:</p> <pre><code>import csv, math def train_data(fname): #load csv training files peptide= [] allele= [] score = [] with open (fname) as train: reader = csv.Dic...
0
2016-06-28T21:29:43Z
38,086,909
<pre><code>import csv, math p={'A':(0.074+0.077)/2, 'R':(0.052+0.053)/2, 'N':(0.045+0.044)/2, 'D':(0.054+0.051)/2, 'C':(0.025+0.022)/2, 'Q':(0.034+0.035)/2, 'E':(0.054+0.056)/2, 'G':(0.074+0.074)/2, 'H':(0.026+0.025)/2, 'I':(0.068+0.064)/2, 'L':(0.099+0.096)/2, 'K':(0.058+0.058)/2, 'M':(0.025+0.024)/2, 'F':(0.047+0.04...
1
2016-06-28T21:51:41Z
[ "python", "python-3.x", "csv", "neural-network", "nested-loops" ]
Nested for loop : List - Not getting the desired output
38,086,629
<p>What I want to do is to estimate the score of each peptide i.e. row</p> <p>My code is as following:</p> <pre><code>import csv, math def train_data(fname): #load csv training files peptide= [] allele= [] score = [] with open (fname) as train: reader = csv.Dic...
0
2016-06-28T21:29:43Z
38,087,207
<p>for me it is only printing <code>peptide[2][j]</code>, but it is printing it for many times, it's that what you want?</p> <pre><code>A A A G A E A G K A T T E E Q --- A A A G A E A G K A T T E E Q --- A A A G A E A G K A T T E E Q --- A A A G A E A G K A T T E E Q --- A A A G A E A G K A T T E E Q --- A A A G A E A...
0
2016-06-28T22:18:23Z
[ "python", "python-3.x", "csv", "neural-network", "nested-loops" ]
Parsing dictionary of dictionaries
38,086,653
<p>I have the following json response:</p> <pre><code>{'Securities': [{'InvestmentType': 'Ordinary Share', 'SecurityUnderlierCode': '', 'GicsIndustry': 'Computers &amp; Peripherals', 'SecurityId': 2654, 'DisplayCode': 'AAPL', 'PricingSymbol': 'AAPL US Equity', 'PriceLast': 93.59, 'SecurityDesc': 'APPLE INC', 'Currency...
0
2016-06-28T21:31:32Z
38,086,695
<p>You need to index the list returned from <code>json_data["Securities"]</code>, the dict with the key you want is at index 0:</p> <pre><code>js = {'Securities': [{'InvestmentType': 'Ordinary Share', 'SecurityUnderlierCode': '', 'GicsIndustry': 'Computers &amp; Peripherals', 'SecurityId': 2654, 'DisplayCode': 'AAPL',...
3
2016-06-28T21:34:40Z
[ "python", "dictionary" ]