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
Splash lua script to do multiple clicks and visits
38,043,672
<p>I'm trying to crawl <a href="https://scholar.google.ae/scholar?q=%22thermodynamics%22&amp;hl=en" rel="nofollow">Google Scholar search results</a> and get all the BiBTeX format of each result matching the search. Right now I have a Scrapy crawler with Splash. I have a lua script which will click the "Cite" link and l...
1
2016-06-26T22:11:19Z
38,120,568
<p>Okay so I hacked up a solution which works. First of all we'll need the Lua script to be mutable so we'll make it a function:</p> <pre><code>def script(n): _script = """ function main(splash) local url = splash.args.url local href = "" assert(splash:go(url)) asser...
0
2016-06-30T10:32:06Z
[ "python", "scrapy", "scrapy-splash" ]
How do I avoid this case of Late Binding when connecting multiple button signals in PyQt4?
38,043,717
<p>I want to connect multiple buttons to the same method but each with a different argument to that method. In this case the argument is the index of the button in a list of all buttons.</p> <pre class="lang-py prettyprint-override"><code>from PyQt4 import QtGui, QtCore import sys class Window(QtGui.QWidget): def ...
1
2016-06-26T22:17:15Z
38,044,031
<p>When button signals are emitted all lambdas you create see the same <code>__init__</code>'s namespace as it was after the last iteration of the loop and in which <code>button is self.pushButton_06</code>.<br> In your second variant the you are connecting to another signal: <code>clicked(checked)</code>; and PyQt ign...
1
2016-06-26T23:11:48Z
[ "python", "pyqt" ]
By group, plot highest quantile data vs lowest, and capture stats
38,043,724
<p>I wish to group a dataset by "assay", then compare intensities for small cells versus large cells. The problem I have is that in writing my code I only understand how to group the top and bottom cellArea quantiles of the entire dataFrame, rather than for each individual assay ('wt' and 'cnt').</p> <p>As a final poi...
1
2016-06-26T22:18:05Z
38,044,335
<p>Calculate the low and high quantile by groups and then merge them back to the original data frame from where you can then calculate the <code>group</code> variable as <code>Small</code> or <code>large</code>:</p> <pre><code>from pandas import pd quantileLow = df.groupby('assay').cellArea.quantile(0.2).reset_index()...
1
2016-06-27T00:12:17Z
[ "python", "pandas", "seaborn" ]
Saving Django formset with Many to Many Field
38,043,755
<p>I'm building a little app with a formset that lets me enter a number of game scores each linking to a player via a many to many field. I'm having problems getting this to save properly with various errors. Basic code.</p> <p>Model.py</p> <pre><code>class Player(models.Model): name = models.CharField(max_length...
0
2016-06-26T22:22:29Z
38,044,154
<p>The <code>add()</code> method used for associating instances in many-to-many relations takes one or more <em>individual</em> model instances. You cannot pass an entire list/queryset of players, but you can add them one by one:</p> <pre><code>for player in p: scoreSave.players.add(player) </code></pre> <p>Of co...
0
2016-06-26T23:37:03Z
[ "python", "django", "django-forms" ]
How to create an extension for a file without extension in Python
38,043,847
<p>I have a folder with a list of files without extensions, I need to rename or create an extension to each file ".text"</p> <p>This is my code, but there is a small bug, the second time I run the code the files renamed again with a long name ,, for example</p> <p>The file name : XXA</p> <p>after first run : XXA.tex...
-1
2016-06-26T22:39:15Z
38,043,864
<pre><code>import os def renamefiles(): filelist = os.listdir(r"D:\") print(filelist) os.chdir(r"D:\") path = os.getcwd() for filename in filelist: print("Old Name - "+filename) (prefix, sep, sffix) = filename.rpartition(".") newfile = prefix + file_name + '.text' if not filename.endswith(".text"):...
0
2016-06-26T22:42:47Z
[ "python" ]
How to create an extension for a file without extension in Python
38,043,847
<p>I have a folder with a list of files without extensions, I need to rename or create an extension to each file ".text"</p> <p>This is my code, but there is a small bug, the second time I run the code the files renamed again with a long name ,, for example</p> <p>The file name : XXA</p> <p>after first run : XXA.tex...
-1
2016-06-26T22:39:15Z
38,043,870
<p>Where you have</p> <pre><code>newfile = prefix + '.text' </code></pre> <p>You can have </p> <pre><code>if not file_name.contains(".text"): newfile = prefix + file_name + '.text' </code></pre> <p>Note where you have <code>newfile = prefix + file_name + '.text'</code>, I changed it to <code>newfile = prefix + ...
2
2016-06-26T22:43:22Z
[ "python" ]
How to create an extension for a file without extension in Python
38,043,847
<p>I have a folder with a list of files without extensions, I need to rename or create an extension to each file ".text"</p> <p>This is my code, but there is a small bug, the second time I run the code the files renamed again with a long name ,, for example</p> <p>The file name : XXA</p> <p>after first run : XXA.tex...
-1
2016-06-26T22:39:15Z
38,043,902
<p>Don't do the partitioning that way, use <code>os.path.splitext</code>:</p> <pre><code>file_name, extension = os.path.splitext(filename) if not extension: newfile = file_name + '.text' os.rename(filename, newfile) </code></pre> <p>If the file has no extension <code>splitext</code> returns <code>''</code> wh...
1
2016-06-26T22:49:08Z
[ "python" ]
How to create an extension for a file without extension in Python
38,043,847
<p>I have a folder with a list of files without extensions, I need to rename or create an extension to each file ".text"</p> <p>This is my code, but there is a small bug, the second time I run the code the files renamed again with a long name ,, for example</p> <p>The file name : XXA</p> <p>after first run : XXA.tex...
-1
2016-06-26T22:39:15Z
38,044,008
<pre><code> for file in os.listdir(os.curdir): name, ext = os.path.splitext(file) os.rename(file, name + ".text") </code></pre>
1
2016-06-26T23:06:56Z
[ "python" ]
plotting from a data frame in pandas
38,043,931
<p>Please I'm new to pandas and want to obtain a multiple time series plot with the dataframe below using TIMESTAMP as index.</p> <pre><code>TIMESTAMP shf_1 shf_2 shf_3 2016-06-18 09:20:00 24.98201 40.98293 18.75554 2016-06-18 09:25:00 24.59746 37.85617 18.11409 2016-06-18 09:30:00 2...
-1
2016-06-26T22:54:13Z
38,044,201
<p>Well if you are using the latest version of pandas and want to glance quickly at that data, use:</p> <pre><code>import matplotlib.plyplot as plt df["shf_1"].plot() df["shf_2"].plot() df["shf_3"].plot() plt.show() </code></pre>
0
2016-06-26T23:45:30Z
[ "python" ]
Python 3.4 changing desktop background image does not work
38,043,934
<p>I tried every example on SO and Google, but none of them working. I don't know why, script finishes without any error. But background image does not changing. I put absolute path for that image, I tried <code>jpg,png</code> formats, basically I tried everything but all examples finished without any error and yet bac...
0
2016-06-26T22:54:21Z
38,053,141
<p>try using following code:</p> <pre><code>import struct import ctypes import os def is_64_windows(): """Find out how many bits is OS. """ return 'PROGRAMFILES(X86)' in os.environ def get_sys_parameters_info(): """Based on if this is 32bit or 64bit returns correct version of SystemParametersInfo functio...
1
2016-06-27T11:46:22Z
[ "python", "windows-7", "background-image", "python-3.4" ]
How do I integrate travis ci with codeclimate test coverage in Python?
38,044,020
<p>I'm trying to make my Travis CI send test coverage data to Code Climate service, but documentation on Code Climate and Travis CI do not describe in detail how to do this using Python. Still its supported feature according Code Climate and Travis documentations. I've tried to find any working examples on this withou...
7
2016-06-26T23:10:14Z
39,078,903
<p>so indeed it looks like at your end it's only an issue of a type as Peter mentioned in a comment. Your <code>after_success</code> should have <code>codeclimate-test-reporter</code> - it looks like you have it, but travis is reporting something else.</p> <p>Now to why I oepened a bounty and why it was actually just ...
2
2016-08-22T11:54:49Z
[ "python", "python-2.7", "continuous-integration", "travis-ci", "code-climate" ]
How to read a binary file of type complex64 values in Python
38,044,103
<p>I have a binary file that contains several complex numbers of type <code>complex64</code>? (i.e. four bytes of type float for the real part and another four bytes for the imaginary part). The real and imaginary parts are multiplexed so that the real part is stored first and followed by the imaginary part.</p>
1
2016-06-26T23:27:51Z
38,082,041
<p>I was able to reproduce the error you encounter by creating an array of <code>complex64</code> from <code>[0, 2+j, -3.14-7.99j]</code>, saving it to a file and reading it as Python built-in <code>complex</code> type. </p> <p>The issue is that the built-in <code>complex</code> type has the size of a C <code>double</...
1
2016-06-28T16:53:03Z
[ "python" ]
how to extract up to the minute component of a unix timestamp?
38,044,128
<p>I have a list of POSIX timestamps such as <code>1331567982</code> that I process using <a href="https://docs.python.org/3.4/library/datetime.html#datetime.datetime.utcfromtimestamp" rel="nofollow"><code>datetime.utcfromtimestamp</code></a> which gives me a date format like: <code>year - month - day - hour - minute -...
0
2016-06-26T23:32:15Z
38,044,151
<p>You can use the <a href="https://docs.python.org/3.4/library/datetime.html#datetime.datetime.replace" rel="nofollow"><code>datetime.replace</code></a> function:</p> <pre><code>import datetime d = datetime.datetime.utcfromtimestamp(1331567982) d.replace(second=0, microsecond=0) </code></pre>
2
2016-06-26T23:36:17Z
[ "python", "datetime", "unix-timestamp" ]
wxpython sizers - does WX.EXPAND make a difference in spacers?
38,044,167
<p>Following good advice in the <a href="https://wiki.wxpython.org/BoxSizerFromTheGroundUp/ControlsPadding" rel="nofollow">BoxSizer from the ground Up</a> tutorial I am refactoring code to factor out the wx.LEFT/RIGHT/TOP/BOTTOM flags into "spacers" - so:</p> <pre><code>horizontal_sizer.Add(someControl, 0, wx.LEFT, bo...
0
2016-06-26T23:39:10Z
38,065,132
<p>Yes, proportion values and the <code>wx.EXPAND</code> flag are applied to spacers the same as for widgets. The item's minsize should be the size it was given when adding the spacer, (instead of being a property of the widget like usual.) You can easily implement some nicely resizing layouts with expandable sizers.</...
1
2016-06-28T00:13:57Z
[ "python", "wxpython", "sizer" ]
Source code for nltk.chat.util not running? - Beginner
38,044,203
<p>When I try to run this code in Sublime, it just print [Finished in 0.2s]. What am I doing wrong? Isn't it suppose to be running a chatbot in the console? I found this code <a href="http://www.nltk.org/_modules/nltk/chat/util.html" rel="nofollow">here</a></p> <p>I know this is a basic question but I am new to python...
0
2016-06-26T23:45:50Z
38,046,140
<p>The file you show contains utility software used by the chatbot programs. You do not directly run that file as a python script. </p> <p>Go to <a href="http://www.nltk.org/api/nltk.chat.html" rel="nofollow">this nltk.org page</a> and download a chatbot program such as nltk.chat.eliza, and run it with python.</p> ...
1
2016-06-27T04:51:22Z
[ "python", "nltk" ]
Selenium Webdrive socket.error
38,044,206
<p>I using Ubuntu x64</p> <p>When I execute fallowing code:</p> <pre><code>from selenium import webdriver x = webdriver.Firefox() x.get('any address') </code></pre> <p>I get the fallowing error:</p> <pre><code> % python seleniumtest.py Traceback (most recent call last): File "seleniumtest.py", line 2, in &lt;mod...
1
2016-06-26T23:46:03Z
38,044,874
<p>try to use following code:</p> <pre><code>from selenium import webdriver from selenium.webdriver.firefox.firefox_binary import FirefoxBinary try: driver = webdriver.Firefox() except: binary = FirefoxBinary('C:/Program Files (x86)/Mozilla Firefox/firefox.exe') driver = webdriver.Firefox(firefox_binary=b...
0
2016-06-27T01:49:10Z
[ "python", "selenium" ]
Selenium Webdrive socket.error
38,044,206
<p>I using Ubuntu x64</p> <p>When I execute fallowing code:</p> <pre><code>from selenium import webdriver x = webdriver.Firefox() x.get('any address') </code></pre> <p>I get the fallowing error:</p> <pre><code> % python seleniumtest.py Traceback (most recent call last): File "seleniumtest.py", line 2, in &lt;mod...
1
2016-06-26T23:46:03Z
38,044,878
<p>Maybe you need Firefoxdriver for selenium. I used Chrome for selenium and I download Chromedriver. You can download from <a href="https://sites.google.com/a/chromium.org/chromedriver/downloads" rel="nofollow">https://sites.google.com/a/chromium.org/chromedriver/downloads</a>. and you can reference from <a href="http...
0
2016-06-27T01:49:31Z
[ "python", "selenium" ]
Convert datatime to milliseconds since midnight UTC or localized in CSV file using Pandas
38,044,264
<pre><code>import pandas as pd import numpy as np from datetime import datetime, time # history file and batch size for processing. historyFilePath = 'EURUSD.SAMPLE.csv' batch_size = 5000 # function for date parsing dateparse = lambda x: pd.datetime.strptime(x, '%Y-%m-%d %H:%M:%S.%f') # load data into a pandas i...
0
2016-06-26T23:57:14Z
38,050,344
<p>This snippet of code should be what you want</p> <pre><code># Create some fake data, similar to yours import pandas as pd s = pd.Series(pd.date_range('2014-08-17 17:00:01.1230000', periods=4)) print(s) print(type(s[0])) # Create a new series using just the date portion of the original data. # This effectively tru...
0
2016-06-27T09:29:00Z
[ "python", "csv", "datetime", "numpy", "pandas" ]
Matplotlib math mode not displayed correctly
38,044,267
<p>I am trying out this example in Python 3.4.4 using Matplotlib version 1.5.1 on Windows 10:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 2.0, 0.01) s = np.sin(2*np.pi*t) plt.plot(t,s) plt.title(r'$\alpha_i &gt; \beta_i$', fontsize=20) plt.text(1, -0.6, r'$\sum_{i=0}^\infty x_...
0
2016-06-26T23:57:41Z
38,052,599
<p>Well, it turned out that my site-packages\matplotlib\mpl-data\fonts directory was corrupted. So I downloaded <a href="https://github.com/matplotlib/matplotlib/archive/v1.5.1.zip" rel="nofollow">https://github.com/matplotlib/matplotlib/archive/v1.5.1.zip</a> and copied the fonts directory from there to my machine. I ...
0
2016-06-27T11:18:40Z
[ "python", "matplotlib" ]
Kivy app window always opens half off the screen
38,044,353
<p>How do I set the window to open as expected in the top left corner of the desktop?</p> <pre><code>from kivy.config import Config Config.set('graphics', 'resizable', '0') Config.set('graphics', 'top', '0') ### This doesn't seem to do anything Config.set('graphics', 'left', '0') ### This doesn't seem to do anything f...
0
2016-06-27T00:16:15Z
38,057,661
<p>There is a one more line required:</p> <pre><code>Config.set('graphics', 'position', 'custom') </code></pre> <p>which is a little bit above <code>top</code> and under <code>left</code>.</p> <blockquote> <p>If auto is used, you have no control of the initial position: top and left are ignored.</p> </blockquote> ...
0
2016-06-27T15:19:52Z
[ "python", "kivy" ]
Generate Random List of Random Numbers with Duplicates in Python 3.4
38,044,364
<p>I've seen multiple threads on printing lists of random numbers, but not ones with my specific requirements, and I can't seem to get it right.</p> <p>I want to develop a code that will generate a list of random numbers on some interval, with the list being a random length alone some separate interval, also, duplicat...
0
2016-06-27T00:19:31Z
38,044,393
<p><code>random.randrange(1,10)</code> returns an integer, as the error says. You can use it as the upper limit of the <code>range</code> function like this:</p> <p><code>a = [random.randint(1,20) for x in range(1, random.randrange(1,10))]</code></p>
0
2016-06-27T00:25:32Z
[ "python", "list", "python-3.x", "random", "list-comprehension" ]
How to remove objects from a list in order using Python
38,044,379
<p>I am trying to make a function, <code>throw_cards</code> that takes a Hand object, that has a certain number of Card objects in it, prints a message, and removes the card from the <code>self.cards</code> list. This is what I currently have:</p> <pre><code>ability = {'Clubs':5, 'Diamonds':6, 'Hearts':7, 'Spades':8} ...
0
2016-06-27T00:22:32Z
38,044,436
<p>You are modifying the list that you are iterating over, and this is causing the problem that you see.</p> <p>Since you seem to want to remove all of the cards, why not just rebind <code>self.cards</code> to an empty list after you have finished printing them:</p> <pre><code>def throw_cards(self): for card in s...
2
2016-06-27T00:33:37Z
[ "python" ]
How to interpret trees from random forest via python
38,044,472
<p>I'm trying to figure out how I can go about interpreting my trees from my random forest. My data contains around 29,000 observations and 35 features. I pasted the first 22 observations, the first 11 features as well as the feature that I am trying to predict(HighLowMobility). </p> <pre><code>birthcohort countyfipsc...
0
2016-06-27T00:40:32Z
38,044,571
<p>You cannot really interpret RF in such terms because random forest does not work this way. It creates highly randomized ensemble of trees, which can have various decision rules. Once you go from decision trees, which are fully interpretable, to RF, you loose this aspect of the classifier. <strong>RFs are black boxes...
2
2016-06-27T00:57:08Z
[ "python", "machine-learning", "random-forest" ]
Can't import a python file on iOS using the app pythonista
38,044,504
<p>I tried importing without the .py file extension ex: import something. That doesen't work. I also tried turning it into a package by creating a <strong>init</strong>.py but it still doesn't want to import. Oh and by the way I'm using Python 3.5 . Edit: I'm using pythonista and at the moment do not have access to a c...
0
2016-06-27T00:46:37Z
38,046,584
<p>Import your python framework or please visit below <a href="https://developer.apple.com/library/ios/technotes/tn2328/_index.html" rel="nofollow">link</a> how to configure python code into iOS.</p> <pre><code>#include &lt;Python.h&gt; </code></pre>
0
2016-06-27T05:40:05Z
[ "python", "ios", "pythonista" ]
Can't import a python file on iOS using the app pythonista
38,044,504
<p>I tried importing without the .py file extension ex: import something. That doesen't work. I also tried turning it into a package by creating a <strong>init</strong>.py but it still doesn't want to import. Oh and by the way I'm using Python 3.5 . Edit: I'm using pythonista and at the moment do not have access to a c...
0
2016-06-27T00:46:37Z
38,088,183
<p>I didn't know you could do this on iOS but I found a fix from another user. This code is not mine but it is sorin's.</p> <p>import os, sys, inspect # realpath() will make your script run, even if you symlink it :) cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ...
0
2016-06-29T00:02:30Z
[ "python", "ios", "pythonista" ]
How to add information to a udp socket?
38,044,511
<p>I'm sending an image using UDP sockets and want to add information to each package, such as checksum and sequence number.</p> <p>Here's the code:</p> <p>client.py</p> <pre><code>import socket import sys UDP_IP = "127.0.0.1" UDP_PORT = 5005 sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) sock.bind((UDP_IP...
0
2016-06-27T00:47:39Z
38,044,631
<p>If you are sending an image, I guess you'd want it to be delivered fully, without any problems or lost packets. You don't need the slightly less lag, that UDP gives you. I'd use TCP sockets for your application. They make sure, that you receive all the sent packets in the order, that they were sent to you. They also...
0
2016-06-27T01:07:54Z
[ "python", "sockets", "udp" ]
Select a specific Row in SFrame
38,044,536
<p>I've been baffled on how to select a specific row within a SFrame array. I'm able to select the first row here:</p> <pre><code>sf +-------------------------------+ | X1 | +-------------------------------+ | [0.0, 0.0, 0.0, 0.0, 0.0, ... | [100 rows x 1 columns] sf[:1] +-----------------...
1
2016-06-27T00:50:47Z
38,051,963
<p>You can select a row with:</p> <pre><code>import graphlab as gl sf = gl.SFrame({'a':[1,2,3], 'b':[2,9,1]}) # select first row print sf[0] # select second row print sf[1] # and so on # convert first row to an SFrame sf_one_raw = sf[0:1] # convert second row to an SFrame sf_one_raw = sf[1:2] </code></pre>
1
2016-06-27T10:45:57Z
[ "python", "graphlab", "sframe" ]
How to plot multiple bars in the same graph
38,044,593
<p>I want to plot 6 different bars (AWA, Rem, S1, S2, SWS, stades) for each group. There are 4 groups. </p> <p>I know the problem is in the: fig, ax=plt.subplots() How can I fix this?</p> <pre><code> import numpy as np import matplotlib.pyplot as plt %matplotlib inline N = 4 # groups: EEG_EMG_EOG_twin...
0
2016-06-27T01:00:42Z
38,047,076
<p>If it is subplots you want, you can do something like this:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt N = 4 # groups: EEG_EMG_EOG_twins(28), EEG_EMG_EOG(26), EEG_twins(22), EEG(20) data = ((99, 98, 98, 95), (100, 99, 97, 94), (98, 97, 95, 93), (99, 99, 95, 92), ...
1
2016-06-27T06:20:50Z
[ "python", "matplotlib" ]
How to plot multiple bars in the same graph
38,044,593
<p>I want to plot 6 different bars (AWA, Rem, S1, S2, SWS, stades) for each group. There are 4 groups. </p> <p>I know the problem is in the: fig, ax=plt.subplots() How can I fix this?</p> <pre><code> import numpy as np import matplotlib.pyplot as plt %matplotlib inline N = 4 # groups: EEG_EMG_EOG_twin...
0
2016-06-27T01:00:42Z
38,049,590
<p>Another approach is to put all the bars next to each other:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt N = 4 # groups: EEG_EMG_EOG_twins(28), EEG_EMG_EOG(26), EEG_twins(22), EEG(20) data = ((99, 98, 98, 95), (100, 99, 97, 94), (98, 97, 95, 93), (99, 99, 95, 92), ...
1
2016-06-27T08:52:24Z
[ "python", "matplotlib" ]
Numpy.copy not working as intended for random sampling
38,044,700
<p>I have an issue with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.copy.html" rel="nofollow">numpy.copy</a> not working as intended.</p> <p>When using it as following, it still references the change back in my original list, which I want to avoid:</p> <pre><code>test = np.copy(random.sample(po...
1
2016-06-27T01:18:50Z
38,045,196
<p>To elaborate on my comments, I'll try to recreate your list</p> <pre><code>In [202]: x=np.arange(10.) In [223]: x Out[223]: array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9.]) In [224]: ll=[[[x]]] # a list In [225]: ll[0] # still a list Out[225]: [[array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., ...
3
2016-06-27T02:46:05Z
[ "python", "numpy", "matrix" ]
TensorFlow CNN behaving differently when batch is divided
38,044,706
<p>Initially I had the CNN working with the following code:</p> <pre><code>for i in range(1000): x_batch = [] y_batch = [] cost_ = 0. x_batch = x y_batch = y_data sess.run(train_op, feed_dict={X: x_batch, Y: y_batch, p_keep_conv: 0.8, p_keep_hidden: 0.5}) cost_ += (sess.run(cost, feed_dic...
1
2016-06-27T01:19:59Z
38,047,478
<p>Switching from <code>Gradient Descent</code> to <code>Stochastic Gradient Descent</code> you need to keep some things in mind.</p> <ol> <li><p>batch size can make an impact on the final performance of the neural net. I would try 128 or 256.</p> <blockquote> <p>A typical minibatch size is 256, although the optima...
2
2016-06-27T06:47:22Z
[ "python", "neural-network", "tensorflow", "conv-neural-network" ]
Lexicographic comparison of two numpy ndarrays
38,044,731
<p>I couldn't find a straightforward way to compare two (multidimensional in my case) arrays the in a lexicographic way.</p> <p>Ie.</p> <pre><code>a = [1,2,3,4] b = [4,0,1,6] </code></pre> <p>For <code>a &lt; b</code> I want to get <code>true</code> where I get <code>[true, false, false, true]</code><br> For <code>...
1
2016-06-27T01:24:08Z
38,047,800
<p>Multiply with np.arange(4)[::-1] ** 2 and then sum over that axis.</p>
0
2016-06-27T07:07:11Z
[ "python", "arrays", "numpy" ]
Lexicographic comparison of two numpy ndarrays
38,044,731
<p>I couldn't find a straightforward way to compare two (multidimensional in my case) arrays the in a lexicographic way.</p> <p>Ie.</p> <pre><code>a = [1,2,3,4] b = [4,0,1,6] </code></pre> <p>For <code>a &lt; b</code> I want to get <code>true</code> where I get <code>[true, false, false, true]</code><br> For <code>...
1
2016-06-27T01:24:08Z
38,052,618
<p>If the question is just about finding whether <code>a</code> is <code>&lt;</code> or <code>&gt;</code> than <code>b</code>, then the following should work.</p> <pre><code>def fn(a, b): # finds index of the first non matching element idx = np.where( (a&gt;b)^(a&lt;b) == True )[0][0] if a[idx] &lt; b[idx...
1
2016-06-27T11:20:06Z
[ "python", "arrays", "numpy" ]
Receiving TypeError: object.__new__() takes no parameters when __new__ not changed
38,044,773
<p>The following is an incomplete implementation for Conway's Game Of Life in Python 3.0 using Tkinter in PyCharm Community Edition.</p> <p>The program consists of four files:</p> <ul> <li>Cell.py : Contains a class for a Cell</li> <li>Grid.py : Contains a class for a Game of Life Grid</li> <li>Windows.py : Contains ...
1
2016-06-27T01:31:10Z
38,044,815
<p>Tkinter has a class called Grid that is shadowing your own class of the same name, because you used <code>from tkinter import *</code> after importing your own class.</p> <p>There are several possible solutions:</p> <ol> <li>Change your import to <code>from Grid import Grid as MyGrid</code> and then call <code>MyG...
4
2016-06-27T01:38:09Z
[ "python", "python-3.x", "tkinter" ]
AWS Python - Windows - Running a script after I create an instance
38,044,786
<p>I have made much progress.</p> <p>My imports are:</p> <pre><code>import boto.rds as rds import boto3 as b3 import boto.ec2 as ec2 from boto.manage.cmdshell import sshclient_from_instance </code></pre> <p>I can connect to my aws using:</p> <pre><code>conn = boto.ec2.connect_to_region('us-west2',aws_access_key_id=...
-1
2016-06-27T01:33:08Z
38,049,473
<p>As mentioned in the comments you cannot directly ssh into windows.</p> <p>so to come back on your initial requirement : <em>Running a script after I create an instance</em> I would not do that from your python script but instead have script on the ec2 instance and have them automatically running on ec2 instance sta...
0
2016-06-27T08:46:22Z
[ "python", "amazon-web-services", "amazon-ec2", "boto", "paramiko" ]
Error in python selenium-webdiver script
38,044,788
<p>it's login is fine, but i am not able to track the issue, here the code below</p> <pre><code> while True: time.sleep(10) browser.get("https://www.instagram.com/accounts/edit/?wo=1") </code></pre> <p>I am getting this error when i ran project.py</p> <pre><code>Superuser$ python project.py user ...
0
2016-06-27T01:33:27Z
38,044,876
<p>You need to start using the <code>wait</code> variable which is an instance of <code>WebDriverWait</code> class:</p> <pre><code>from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC wait = WebDriverWait(b...
1
2016-06-27T01:49:24Z
[ "python", "selenium", "selenium-webdriver" ]
Error in python selenium-webdiver script
38,044,788
<p>it's login is fine, but i am not able to track the issue, here the code below</p> <pre><code> while True: time.sleep(10) browser.get("https://www.instagram.com/accounts/edit/?wo=1") </code></pre> <p>I am getting this error when i ran project.py</p> <pre><code>Superuser$ python project.py user ...
0
2016-06-27T01:33:27Z
38,059,198
<p>you said in comments that the page is <a href="https://www.instagram.com/accounts/login/?force_classic_login" rel="nofollow">https://www.instagram.com/accounts/login/?force_classic_login</a>, but in your code you use browser.get("<a href="https://www.instagram.com/accounts/edit/?wo=1" rel="nofollow">https://www.inst...
1
2016-06-27T16:46:42Z
[ "python", "selenium", "selenium-webdriver" ]
Subtract two rows based on condition in Python Pandas
38,044,808
<p>I'm working with a data set where I have time and the concentration of several different species of microorganism with replicates, so it's just a time column and a bunch of numbers for the sake of this question. I was taking measurements every two hours and sometimes I would take two measurements consecutively and t...
1
2016-06-27T01:36:40Z
38,045,137
<p>Here are some general tips:</p> <ul> <li>Prefer vectorized computations over python for-loops. For example, calling <code>df['Time'].diff()</code> is much faster than computing <code>row2['Time'] - row1['Time']</code> in a loop. The vectorized computation will always beat the for-loop computation for sufficiently l...
6
2016-06-27T02:36:31Z
[ "python", "numpy", "pandas" ]
1-D LDA output dimension in Numpy
38,044,811
<p>I am trying to reduce dimensionality of a 2000-D data to 2D data. So I used the sample code here: <a href="http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html" rel="nofollow">http://scikit-learn.org/stable/auto_examples/decomposition/plot_pca_vs_lda.html</a> But instead of a 2-D output I ...
1
2016-06-27T01:37:02Z
38,048,634
<p>As <a href="http://scikit-learn.org/stable/modules/generated/sklearn.discriminant_analysis.LinearDiscriminantAnalysis.html#sklearn.discriminant_analysis.LinearDiscriminantAnalysis" rel="nofollow">the documentation</a> says, n_components is "Number of components (&lt; n_classes - 1) for dimensionality reduction."</p>...
0
2016-06-27T07:58:41Z
[ "python", "numpy" ]
slicing Tensorflow FixedLengthRecordReader value
38,044,857
<p>I'm implementing a regression network mapping images to poses, using Tensorflow/python API and am trying to process the output of a FixedLengthRecordReader.</p> <p>I'm trying to adapt the <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/models/image/cifar10/cifar10_input.py" rel="nofollow">c...
1
2016-06-27T01:46:16Z
38,045,844
<p>Found a solution <a href="http://wearecoder.com/questions/jy70c/reading-binary-data-in-float32" rel="nofollow">here</a>: decode twice and throw out half. Not that efficient (and if anyone has a better solution, I'd be glad to hear it) but it seems to work.</p>
0
2016-06-27T04:15:03Z
[ "python", "tensorflow", "slice" ]
Define bar chart colors for Pandas/Matplotlib with defined column
38,044,866
<p>I have a dataframe "table" like this:</p> <p><code>SAMPLE RANK VALUE CAT 3 N DOG 1 N FISH 4 Y ANT 2 N HORSE 5 N</code></p> <p>How can I JUST COLOR the 3rd histogram column, given that there is a "Y" in the VALUE column? I would like it to look like this:...
1
2016-06-27T01:48:12Z
38,049,161
<p>You may achieve the desired effect by mapping <code>VALUE</code> column to desired colors:</p> <pre><code>colors = {'N':'#00BEC5', 'Y':'#F9746A'} df.sort_values('RANK', inplace=True) df.plot.bar(x='SAMPLE', y='RANK',color= df['VALUE'].map(colors)); </code></pre> <p><a href="http://i.stack.imgur.com/5nEkS.png" rel=...
2
2016-06-27T08:29:26Z
[ "python", "pandas", "matplotlib", "histogram" ]
How to resolve Python KeyError elegantly (Python csv library)
38,044,880
<p>I have written a basic web scraper in Python using the lxml and JSON libraries. The below code snippet details how I currently write to CSV:</p> <pre><code>with open(filepath, "ab") as f: write = csv.writer(f) try: write.writerow(["allhomes", ...
0
2016-06-27T01:50:40Z
38,045,421
<p>If you have to use keys like this, one way I've used in the past with web scraping was to create a wrapper that handled the errors, then returned the value.</p> <pre><code>def get_node(name, node): try: val = node[name] except KeyError: val = 'na' return val write.writerow(['allhomes', ...
0
2016-06-27T03:21:46Z
[ "python", "json", "csv", "keyerror" ]
blackjack game: for loops 'not in' vs 'in'
38,044,933
<p>I have run into some trouble using for loops while making a blackjack game simulation. The function <code>new_game</code> simulates four cards being dealt, while <code>new_card</code> ensures no card is repeated in a game. I created two variations of the function <code>new game</code> and was wondering how they diff...
0
2016-06-27T02:01:41Z
38,045,179
<p>Calling <code>new_game</code> is not the best way to solve this project. You can try multiple ways , one of which I am showing. Rather than a constant for loop try to check the length of list until it is of desired length.</p> <pre><code>def new_game(): game=[]; while len(game)!=4: n = new_card() ...
1
2016-06-27T02:43:12Z
[ "python", "for-loop" ]
Retrieving data from namedtuple record structure fails
38,044,937
<p>I need to create a lookup table to store tabular data and retrieve the records based on multiple field values.</p> <p>I found an example <a href="http://stackoverflow.com/questions/15418386/what-is-the-best-data-structure-in-python-for-storing-a-set-of-four-or-more-va">post # 15418386</a> which does almost what I n...
1
2016-06-27T02:02:01Z
38,046,285
<p>The variable <code>value</code> is overwritten in the following <code>if .. for ..</code> block:</p> <pre><code>field, value = kwargs.items()[0] # &lt;--- `value` defined ... if field not in self.lookup_tables: for index, record in enumerate(self.records): value = getattr(record, field) # &lt;--- `...
0
2016-06-27T05:08:57Z
[ "python", "class", "namedtuple" ]
Odoo how to insert data to multiple tables with foreign constraint?
38,044,944
<p>I have two tables in my project call <code>task</code> and <code>params</code>, <code>task</code> represents work task and <code>params</code> are the param list of that task. they are one2many relationship. <code>params</code> has a column called task_id which contains the id of the task table(foreign key).</p> <p...
0
2016-06-27T02:02:51Z
38,053,914
<p>This is not how a SQL transaction works. </p> <p>If you have a transaction in 2 steps like this:</p> <ul> <li><p>step 1 insert in task</p></li> <li><p>step 2 insert in params</p></li> </ul> <p>Then the task ID will be available inside the transaction. So when you insert in tasks you need to read the PK ID and the...
0
2016-06-27T12:23:39Z
[ "python", "postgresql", "openerp" ]
Python - ping in for loop
38,044,984
<p>I try to ping through for loop , the problem it's done only to the last number in this case the ping done only to the x.x.x.4 address </p> <pre><code>import subprocess import socket ipl = socket.gethostbyname(socket.gethostname()) seg1, seg2, seg3, seg4 = ipl.split(".") stip = seg1 + "." + seg2 + "." + seg3 + "." ...
0
2016-06-27T02:10:01Z
38,045,243
<p>changed the <code>fiw = open("1.txt", 'w')</code> to <code>fiw = open("1.txt", '+a')</code></p> <pre><code>import subprocess import socket ipl = socket.gethostbyname(socket.gethostname()) seg1, seg2, seg3, seg4 = ipl.split(".") stip = seg1 + "." + seg2 + "." + seg3 + "." i = 0 for i in range(1,5): cmd = "ping...
0
2016-06-27T02:53:37Z
[ "python", "windows", "python-3.x", "networking" ]
Python - ping in for loop
38,044,984
<p>I try to ping through for loop , the problem it's done only to the last number in this case the ping done only to the x.x.x.4 address </p> <pre><code>import subprocess import socket ipl = socket.gethostbyname(socket.gethostname()) seg1, seg2, seg3, seg4 = ipl.split(".") stip = seg1 + "." + seg2 + "." + seg3 + "." ...
0
2016-06-27T02:10:01Z
38,048,697
<pre><code>fiw = open("1.txt",'w') for i in range(1,5): cmd = "ping -n 1 " + stip + str(i) print(cmd) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout) = p.communicate() fiw.write(str(stdout)) fiw.close() </code></pre> <p>Try to change your code </p>
0
2016-06-27T08:02:19Z
[ "python", "windows", "python-3.x", "networking" ]
Django: how to change a base object to an alone subclass object?
38,045,084
<p>Now I'm working with python django.</p> <p>I have derived a Model class from user:</p> <pre><code>from django.contrib.auth.models import User class Customer(User): mobile = models.CharField(max_length=14) class Meta: db_table = 'customer_user' </code></pre> <h3>Question</h3> <p>Now comes the q...
0
2016-06-27T02:26:02Z
38,045,431
<p>You have two options, as described in the <a href="https://docs.djangoproject.com/en/1.9/topics/auth/customizing/#extending-the-existing-user-model" rel="nofollow">documentation</a>:</p> <p>1. Make your <code>Customer</code> model a <a href="https://docs.djangoproject.com/en/1.9/topics/db/models/#proxy-models" rel=...
1
2016-06-27T03:23:12Z
[ "python", "django", "class", "inheritance", "model-view-controller" ]
Patch a config file imported as another name in python
38,045,087
<p>I'm trying to patch a config file used in a django app and having trouble understanding how to do it given the way we import the config. I don't think the fact that it's Django has much relevance here, but it partially drives this file structure.</p> <p><strong>app/views.py</strong></p> <pre><code>from . import c...
0
2016-06-27T02:26:30Z
38,061,798
<p>This should work:</p> <pre><code>@patch('app.views.APP_CONFIG.MAX_NUMBER_RETRIES', 1) </code></pre> <p>I tried it with a small example (without Django) and it worked as expected. This is probably not pytest but <strong>mock</strong> related. Have a look at the documentation: <a href="https://docs.python.org/3/libr...
0
2016-06-27T19:30:05Z
[ "python", "django", "unit-testing", "py.test", "pytest-django" ]
Jupyter & IPython: What does %matplotlib inline do?
38,045,100
<p>I'm curious that how jupyter notebook enables the plot inline. I searched <code>%matplotlib inline</code> in github and didn't find the source code (<a href="https://github.com/search?l=python&amp;q=org%3Ajupyter+matplotlib+inline&amp;ref=searchresults&amp;type=Code&amp;utf8=%E2%9C%93" rel="nofollow">https://github....
0
2016-06-27T02:28:49Z
38,127,899
<p>You can find the source of the matplotlib magic in a jupyter notebook via</p> <pre><code>%matplotlib?? # view source </code></pre> <p>From this we find the code in <code>python3.5/site-packages/IPython/core/magics/pylab.py</code></p> <pre><code> args = magic_arguments.parse_argstring(self.matplotlib, line) ...
1
2016-06-30T15:47:26Z
[ "python", "matplotlib" ]
How do I make pygame display the time and change it when the time changes using fonts?
38,045,189
<p>I have got a working digital clock in python but I am stuck trying to make it a visual in pygame. </p> <p>The code for the clock works but it just doesn't display anything, even though I have used .blit to do so.</p> <p>The idea is to have the timer show every minute (Second), Hour(every 60 seconds) and Days (Ever...
0
2016-06-27T02:44:42Z
38,051,165
<p>Barring all other problems, I'm not sure what your A1 and A2 are supposed to be, but</p> <pre><code>if A1==0: #true for the first run through A1=A1+1 #A1 = 1 A2=A2+1 time.sleep(1) if A1==1 or A2==1: #always true, since A1==1 A2=A2-1 A1=A1-1 #A1 = 0 </code></pre> <p>this will always ...
0
2016-06-27T10:07:25Z
[ "python", "python-2.7", "animation", "pygame", "blit" ]
Drop groups in groupby that do not contain an element (Python Pandas)
38,045,192
<p>Let a data frame be like the following:</p> <pre><code>import pandas as pd df = pd.DataFrame({"name":["A", "A", "B" ,"B", "C", "C"], "nickname":["X","Y","X","Z","Y", "Y"]} </code></pre> <p>How can I group df and drop those groups (C) that do not contain at least one 'X'?</p> <p>thank you</p>
1
2016-06-27T02:45:13Z
38,045,266
<p>You can use the grouped by <code>filter</code> from pandas:</p> <pre><code>df.groupby('name').filter(lambda g: any(g.nickname == 'X')) # name nickname # 0 A X # 1 A Y # 2 B X # 3 B Z </code></pre>
4
2016-06-27T02:57:20Z
[ "python", "pandas" ]
Redis pubsub cause Too Many Files Open Error
38,045,259
<p>I have a server used Redis and Socket.IO. If a user connect to the socket.IO, server will run a greenlet and subscribe to redis channel. If the user disconnect, the greenlet will unsubscribe the channel. </p> <p>After a lot of connection and disconnection, I use 'client list' command in redis-cli, I found that the ...
0
2016-06-27T02:56:10Z
38,089,617
<p>Looking at the code </p> <p><a href="https://github.com/andymccurdy/redis-py/blob/master/redis/client.py#L2281" rel="nofollow">https://github.com/andymccurdy/redis-py/blob/master/redis/client.py#L2281</a></p> <p>I can guess at the issue. It looks like the PubSub object checks a connection out of the connection po...
1
2016-06-29T02:57:53Z
[ "python", "redis", "publish-subscribe" ]
Can BeautifulSoup find elements with a matching value?
38,045,302
<p>I am working on a web scraper for the first time, and I am using Beautiful Soup to parse a JSON file and return several attributes that I send to a CSV. </p> <p>The <code>status</code> variable, in the JSON array, is a binary value (0/1). I'd like to return only arrays that have a 0 for status. Is it feasible to do...
0
2016-06-27T03:03:55Z
38,046,737
<p>I might be missing something, but maybe this helps:</p> <pre><code>for doc in js_data["response"]["docs"]: if doc["PostProcessedData"]["Onsales"]["status"] == "0": Attraction.append(doc["Attraction"]) event.append(doc["PostProcessedData"]["Onsales"]["event"]["date"]) status.append(doc["P...
0
2016-06-27T05:55:03Z
[ "python", "json", "beautifulsoup" ]
statsmodels: What are the allowable formats to give to result.predict() for out-of-sample prediction using formula
38,045,310
<p>I am trying to use <code>statsmodels</code> in python to impute some values in a Pandas <code>DataFrame</code>.</p> <p>The third and fourth attempts below (df2 and df3) give an error <code>*** AttributeError: 'DataFrame' object has no attribute 'design_info'</code> This seems a strange error, since dataframes neve...
0
2016-06-27T03:05:14Z
38,087,993
<p>By way of answering this question, here is my resulting method to fill in some values in a dataframe with an arbitrary (OLS) model. It drops the np.nans as needed before predicting.</p> <pre><code>#!/usr/bin/python import statsmodels.formula.api as sm import pandas as pd import numpy as np def df_impute_values_ols...
0
2016-06-28T23:40:20Z
[ "python", "pandas", "statsmodels" ]
How to encrypt data with RSA private key in python?
38,045,324
<p>I've installed <em><a href="http://pythonhosted.org/pycrypto/" rel="nofollow">pyCrypto</a></em> package on Python 2.7.1 to do some cryptography operations. </p> <p><strong>Q1:</strong> The operation that I want to do is encrypting some data with <code>private Key</code> (instead of <code>public Key</code>). It seem...
-1
2016-06-27T03:06:58Z
38,045,683
<p>In public key cryptography, you do not encrypt with the private key -- you always use the public key. Otherwise, since the public key is "public", anybody could decrypt the ciphertext.</p> <p>You might be tempted to use the public and private keys interchangeably, but generally, given the private key, you can figur...
2
2016-06-27T03:54:52Z
[ "python", "encryption", "cryptography", "rsa", "pycrypto" ]
How to fix "py:872: axes.color_cycle is deprecated and replaced with axes.prop_cycle;"?
38,045,437
<p>I am totally brand new to programming and attempting to learn Python. So, please bear with me during the phase of asking dump questions. The error above is what I got when I attempted to import matplotlib.pyplot into Python. I'm not sure of how to resolve this so I hope somebody can help me. Thanks!</p>
2
2016-06-27T03:23:51Z
40,005,610
<p>Open your <code>matplotlibrc</code> file and search for <code>axes.color_cycle</code>. If you're getting the error message it means that your <code>matplotlibrc</code> file should show something like this:</p> <pre><code>axes.color_cycle : b, g, r, c, m, y, k # color cycle for plot lines </code></pre> <p>You shou...
0
2016-10-12T18:15:06Z
[ "python", "matplotlib" ]
how to give index of clustered array python?
38,045,453
<p>i've try to run this K-Medoids python implementation code </p> <pre><code>from sklearn.metrics.pairwise import pairwise_distances import numpy as np import kmedoids # 3 points in dataset data = np.array([[1,1], [2,2], [10,10]]) # distance matrix D = pairwise_distances(data, met...
-1
2016-06-27T03:25:44Z
38,047,158
<p>You mean you want to print <code>point_idx</code>, too?</p> <pre><code>print('label {0}: {1} {2}'.format(label, data[point_idx], point_idx)) </code></pre>
0
2016-06-27T06:26:19Z
[ "python", "indexing", "cluster-analysis" ]
Rolling a dice in python n times
38,045,621
<p>I'd like to create code that will 'roll' number_of_dice times and find the sum of the rolls. This is what I have. I'm getting an error when I do "sum = sum + roll" that there's unsupported operand types for +: built_in_function_or_method and int. How can I solve this?</p> <pre><code>for i in range(0,number_of_dice)...
0
2016-06-27T03:46:39Z
38,045,656
<p>Python has a built in function <code>sum</code> that returns the sum of numbers given as a sequence. Since you have not declared a variable <code>sum</code> it is trying to <code>+</code> that built in function and a number <code>roll</code> which is not permitted. You need to define the variable before the loop:</p...
1
2016-06-27T03:51:25Z
[ "python" ]
Rolling a dice in python n times
38,045,621
<p>I'd like to create code that will 'roll' number_of_dice times and find the sum of the rolls. This is what I have. I'm getting an error when I do "sum = sum + roll" that there's unsupported operand types for +: built_in_function_or_method and int. How can I solve this?</p> <pre><code>for i in range(0,number_of_dice)...
0
2016-06-27T03:46:39Z
38,045,728
<p>I'd use:</p> <pre><code>import random def sum_of_dice(number_of_dice, n_sides_on_die=6): return sum([random.choice(range(1, n_sides_on_die + 1)) for i in range(number_of_dice)]) </code></pre>
0
2016-06-27T04:01:03Z
[ "python" ]
Pandas: How to read an excel file defining several columns to be multi indexes?
38,045,735
<p>I have a data frame that every row contains an office location object with several attribute like <code>Global Region</code>,<code>Primary Function</code>, and several energy consumption data as numerical values followed. The names of all columns is like below: </p> <pre><code>['Global Region', 'Primary Function...
1
2016-06-27T04:02:03Z
38,046,848
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html" rel="nofollow"><code>read_excel</code></a> with parameter <code>index_col</code> which contains <code>list</code> of positions of necessary columns:</p> <p>Sample:</p> <pre><code>df = pd.read_excel('test.xlsx', sheet...
1
2016-06-27T06:04:37Z
[ "python", "excel", "date", "pandas", "dataframe" ]
Python Pandas error bars are not plotted and how to customize the index
38,045,754
<p>I need your help on plotting error bars using Pandas in Python. I have read the Pandas documentation, and did some trials and errors, but got no satisfying result.</p> <p>Here is my code:</p> <pre><code>''' usage : (python) rc-joint-plot-error-bar.py ''' from __future__ import print_function import pandas as pd i...
1
2016-06-27T04:03:19Z
38,048,077
<p>You're almost there! </p> <ol> <li><p>For your error bars to show up in the plot, the column names in <code>yerr</code> should match those of the data in the bar plot. Try renaming <code>CA_errors</code>. </p></li> <li><p>For changing x-labels, try <code>ax.set_xticklabels(df.Specimen);</code></p></li> </ol> <p>...
2
2016-06-27T07:23:46Z
[ "python", "pandas", "plot", "errorbar" ]
How to read & accumulate sensor values at high frequency, without constantly writing to disk (RPi 2 b+, MCP3304, Python)
38,045,783
<p>I am attempting to use a <a href="https://www.raspberrypi.org/products/model-b-plus/" rel="nofollow">Raspberry Pi 2 Model B+</a> to read analog data on IR intensity from a photodiode via an <a href="http://www.farnell.com/datasheets/1486116.pdf" rel="nofollow">MCP3304</a> (5v VDD) at a rate of ~ 10kHz three times in...
3
2016-06-27T04:07:10Z
38,048,000
<p>One point about your question. Three samples in a second is a rate of 3Hz not 100kHz. Sounds to me like what you want is three samples 10us apart.</p> <p>1) 10us sample period on MCP3304 using Pi running Linux? Quite possibly not. Do some searching. See for example <a href="http://raspberrypi.stackexchange.com/ques...
3
2016-06-27T07:19:13Z
[ "python", "raspberry-pi", "sensor", "adc" ]
sklearn missing from dist-packages
38,045,787
<p>i needed to use latest version of sklearn which includes mlp. i had installed sklearn through pip but it didnt go for latest version. so i downloaded dev version trying to build/install it manually, but it didnt work and still mlp is missing from neuralnetwork. i decided to remove sklearn, but it was only possible b...
-1
2016-06-27T04:07:53Z
38,047,816
<p>If you're on windows, type in your command prompt / terminal in Linux or Mac</p> <pre><code>pip install scikit-learn --upgrade </code></pre>
0
2016-06-27T07:08:07Z
[ "python", "scikit-learn", "conda" ]
Assign value to python list without declare the range
38,045,864
<p>Currently, I am using python to handle some excel data.</p> <pre><code>newSet = [[]] newSet[1][1]="abc" print(newSet[1][1]) IndexError: list index out of range </code></pre> <p>I don't know have you guys use Lua before.</p> <p>Lua can assign value to a empty list(list doesn't declare the range).</p> <p>Can pytho...
0
2016-06-27T04:17:32Z
38,045,973
<p>Since you don't know the range of the list in advance, you'd better use <code>collections.defaultdict</code> rather than <code>list</code> as your container. A simple example is as follows:</p> <pre><code>from collections import defaultdict newSet = defaultdict(dict) newSet[1][1] = "abc" print(newSet[1][1]) </code...
-1
2016-06-27T04:30:24Z
[ "python" ]
Extract the list of running IP's from AWS
38,045,909
<p>I need to exactract a list of all Running IP's from AWS and along the list of IP i also want the tag-value &amp; the region-name(or availability-zone). The list should look as follows </p> <pre><code>ex : [[('23.1.1.141', ' Production LB', 'us-east-1'), ('47.2.14.93', 'sung2-cloud-trial01-LBi-b89671', 'us-west-2'),...
1
2016-06-27T04:21:56Z
38,046,272
<p>I think it is all about finding the information in the response and grabbing it;</p> <pre><code>def gather_public_ip(): regions = ['us-west-2', 'eu-central-1', 'ap-southeast-1'] combined_list = [] ##This needs to be returned for region in regions: instance_information = [] # I assume this is ...
2
2016-06-27T05:07:18Z
[ "python", "python-2.x", "boto3" ]
Multipart File upload in Ionic
38,046,027
<p>I'm trying to upload a picture to my server with some additional data. My angularJs code is that:</p> <pre><code>function create_question(question, callback){ var form = new FormData() var settings = { "url": "http://127.0.0.1:8000/" + "question/api/create_question/", "method": "POST", ...
1
2016-06-27T04:38:41Z
38,061,049
<p>After a long search on the internet, I found the answer. First, I read file with </p> <pre><code>$cordovaFile.readAsArrayBuffer(directory,filename) </code></pre> <p>After that, I created a Blob object with the file:</p> <pre><code>var imgBlob = new Blob([success], { type: "image/jpeg" } ); </code></pre>...
1
2016-06-27T18:43:18Z
[ "python", "angularjs", "ionic-framework", "cordova-plugins" ]
Does Bio.Entrez's efetch() retrieve all metadata of a PubMed article?
38,046,054
<p>I wonder whether <a href="http://biopython.org/DIST/docs/api/Bio.Entrez-module.html" rel="nofollow">Bio.Entrez</a>'s <a href="http://biopython.org/DIST/docs/api/Bio.Entrez-pysrc.html#efetch" rel="nofollow"><code>efetch()</code></a> retrieves all metadata of a PubMed article, given a PMID as input. By all metadata, I...
0
2016-06-27T04:42:01Z
38,047,632
<p>The info is not missing:</p> <pre><code>from Bio import Entrez Entrez.email = "sample@sample.org" handle = Entrez.efetch(db="pubmed", id="23954024", rettype="xml") print(handle.read()) </code></pre> <p>Part of the output:</p> <pre><code>&lt;Abstract&gt; &lt;AbstractText Label="OBJECTIVES" NlmCategory="OBJECTIV...
1
2016-06-27T06:57:12Z
[ "python", "biopython", "ncbi", "pubmed" ]
Does Bio.Entrez's efetch() retrieve all metadata of a PubMed article?
38,046,054
<p>I wonder whether <a href="http://biopython.org/DIST/docs/api/Bio.Entrez-module.html" rel="nofollow">Bio.Entrez</a>'s <a href="http://biopython.org/DIST/docs/api/Bio.Entrez-pysrc.html#efetch" rel="nofollow"><code>efetch()</code></a> retrieves all metadata of a PubMed article, given a PMID as input. By all metadata, I...
0
2016-06-27T04:42:01Z
38,049,941
<p>To extend xbello's answer, no, the info is not missing, but a bit hidden.</p> <pre><code>from Bio import Entrez Entrez.email = "Your.Name.Here@example.org" handle = Entrez.efetch(db="pubmed", id="23954024", rettype="xml") records = Entrez.read(handle) for record in records: m = record['MedlineCitation']['Art...
1
2016-06-27T09:08:49Z
[ "python", "biopython", "ncbi", "pubmed" ]
How can i use Ajax success data in same template or somewhere else?
38,046,134
<pre><code> $.ajax({ type: "POST", url: "{% url 'my_url' %}", async: false, data: formData, cache: false, contentType: false, processData: false, success: function(data) { console.log(data) name = data.name error: functio...
-1
2016-06-27T04:50:50Z
38,046,445
<p>User your ajax response like this</p> <pre><code>$.ajax({ type: "POST", url: "{% url 'my_url' %}", async: false, data: formData, cache: false, contentType: false, processData: false, success: function(data) { ...
1
2016-06-27T05:25:11Z
[ "python", "html", "ajax", "django-templates" ]
Is it OK to use def main() with a pass statement in it for python module
38,046,148
<p>I have a python script that I am using purely as a module. It has one class and a few other functions that are being imported to another python script using:</p> <pre><code>from module import * </code></pre> <p>The module looks something like this:</p> <pre><code>class myClass: def __init__(self, something)...
0
2016-06-27T04:52:27Z
38,046,174
<p>The main method and global variable <strong>name</strong> are optional. The python interpreter will not complain if it is not there.</p> <pre><code>def main(): pass if __name__ == '__main__': main() </code></pre> <p><strong>So what is <code>__name__</code>?</strong> <br> The global variable, <code>__nam...
1
2016-06-27T04:55:20Z
[ "python" ]
Is it OK to use def main() with a pass statement in it for python module
38,046,148
<p>I have a python script that I am using purely as a module. It has one class and a few other functions that are being imported to another python script using:</p> <pre><code>from module import * </code></pre> <p>The module looks something like this:</p> <pre><code>class myClass: def __init__(self, something)...
0
2016-06-27T04:52:27Z
38,046,175
<p>If you don't need a main function, don't define one and don't call it. There's no requirement to have a function called <code>main</code>, and if you do define one, it has no special status and won't be called unless you call it yourself.</p> <p>Just remove the last five lines of your code (the <code>def main</cod...
5
2016-06-27T04:55:36Z
[ "python" ]
Right Click and click reload in chrome browser using Selenium in local as well as remote machine
38,046,374
<p>My requirement is:</p> <ol> <li>Go to Chrome</li> <li>Right click and select option. For example I need to click Reload or Back option in pop up</li> <li>Do the above operation in both, local and a remote PC via Selenium Grid</li> </ol> <p>I was able to achieve the above task using <code>sendkeys</code>, but <cod...
0
2016-06-27T05:18:27Z
38,048,061
<p>I don't know python implementation of selenium driver, but in c# there is a INavigation object that allows you to perform navigation actions (go back, go forward, refresh)</p> <pre><code>INavigation navigation = driver.Navigate(); navigation.Back(); navigation.Refresh(); </code></pre>
0
2016-06-27T07:22:47Z
[ "python", "selenium", "selenium-chromedriver" ]
Django: How to use ModelForm and Generic Views
38,046,733
<p>I am learning <code>Django</code>.</p> <p>I got little confuse about uses of <code>Model Form</code> and <code>Generic Views</code>.</p> <p>Though both are different but what i understood is both can generate <code>form</code> according to given <code>model class</code></p> <p>I have a different tables to store i...
0
2016-06-27T05:54:55Z
38,046,931
<p>Generic views and model forms are not exclusive concepts; generic views are made to encompass the business logic of a particular function, while ModelForms create a form, validation/data cleaning logic, and CRUD functionality from the model's logic. </p> <p>With the example below (from the <a href="https://docs.dja...
0
2016-06-27T06:11:39Z
[ "python", "django", "model", "views" ]
Sending POST data from inside a Django template 'for loop'
38,046,905
<p>With this HTML:</p> <pre><code>... {% for thing in things %} &lt;form method="post"&gt; {% csrf_token %} {{ thing.name }} {{ form.value }} &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; {% endfor %} ... </code></pre> <p>My web...
0
2016-06-27T06:09:21Z
38,046,984
<p>The most common design pattern for model instance updates is to provide the primary key of an object in the url where you are submitting your post data.</p> <pre><code># urls.py from django.conf.urls import * from library.views import UpdateThing urlpatterns = patterns('', url('^update_thing/(?P&lt;pk&gt;[\w-...
1
2016-06-27T06:15:10Z
[ "python", "django", "django-forms", "django-templates", "django-views" ]
Sending POST data from inside a Django template 'for loop'
38,046,905
<p>With this HTML:</p> <pre><code>... {% for thing in things %} &lt;form method="post"&gt; {% csrf_token %} {{ thing.name }} {{ form.value }} &lt;input type="submit" value="Submit" /&gt; &lt;/form&gt; {% endfor %} ... </code></pre> <p>My web...
0
2016-06-27T06:09:21Z
38,047,217
<p>The standard way to handle multiple forms of the same kind on one page with Django is to use <a href="https://docs.djangoproject.com/en/1.9/topics/forms/formsets/" rel="nofollow">Formsets</a>.</p> <p>It handles the annoying details like displaying errors on one form while preserving the input on others etc.</p> <p...
0
2016-06-27T06:30:41Z
[ "python", "django", "django-forms", "django-templates", "django-views" ]
Assign the value of a python variable to a bash variable inside a python script
38,047,075
<p>I have a python script having a variable whose value is read from a file.</p> <p>What I want to do is, save this value to a bash variable so that I might be able to use it in my python script with pexpect.</p> <p>This is how I want to use it:</p> <pre><code>#!/usr/bin/python import pexpect a="value read from a f...
0
2016-06-27T06:20:46Z
38,047,141
<p>You could do something like adding two strings together:</p> <pre><code>pexpect.run("bash_a='" + a + "'") </code></pre>
0
2016-06-27T06:25:37Z
[ "python", "bash", "pexpect" ]
Assign the value of a python variable to a bash variable inside a python script
38,047,075
<p>I have a python script having a variable whose value is read from a file.</p> <p>What I want to do is, save this value to a bash variable so that I might be able to use it in my python script with pexpect.</p> <p>This is how I want to use it:</p> <pre><code>#!/usr/bin/python import pexpect a="value read from a f...
0
2016-06-27T06:20:46Z
38,047,344
<p>If you really want to put a variable in the environment, that's <code>os.environ</code></p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.environ['bar'] = "foo" &gt;&gt;&gt; os.system("bash -c 'echo \"$bar\"'") foo 0 </code></pre> <p>This needs to happen before you start any subprocess which needs this variabl...
2
2016-06-27T06:38:59Z
[ "python", "bash", "pexpect" ]
Parse iframe with blank src using bs4
38,047,178
<p>Good time of day, SO community. Here's the problem I recently encountered:</p> <p>I got this HTML source code on main page: </p> <pre><code> &lt;div id="contents_layout"&gt; &lt;iframe name="contentsFrame" id="contentsFrameID" src="" width="100%" height="100%" scrolling="no" frameborder="0" marginheight=...
0
2016-06-27T06:27:47Z
38,052,547
<p>The <em>iframe</em> had an id so just use that:</p> <pre><code>h= """&lt;div id="contents_layout"&gt; &lt;iframe name="contentsFrame" id="contentsFrameID" src="" width="100%" height="100%" scrolling="no" frameborder="0" marginheight="0" marginwidth="0"&gt;&lt;/iframe&gt; &lt;/div&gt; """ from bs4 import...
0
2016-06-27T11:16:00Z
[ "python", "parsing", "iframe", "beautifulsoup" ]
How to move and replace files from FTP folder to another folder in same FTP
38,047,179
<p>I am new to Python. I am trying to move some xml files in an ftp location to another location in same ftp. I tried with the following code, but it doesn't work.</p> <pre><code>def ftpPush(filepathSource, filename, filepathDestination): try: ftp = FTP(ip, username, password) ftp.cwd(filepathDesti...
0
2016-06-27T06:27:48Z
38,047,289
<p>To move a file use the <a href="https://docs.python.org/2.7/library/ftplib.html#ftplib.FTP.rename" rel="nofollow"><code>FTP.rename</code></a>.</p> <p>Assuming that the <code>filepathSource</code> and the <code>filepathDestination</code> are both remove files, you do:</p> <pre><code>ftp.rename(filepathSource, filep...
0
2016-06-27T06:34:46Z
[ "python", "ftp" ]
Python: error: (9, 'Bad file descriptor')
38,047,275
<p>I have error at:</p> <pre class="lang-none prettyprint-override"><code>"File "/home/pi/blescan.py", line 78, in hci_le_set_scan_parameters old_filter = sock.getsockopt( bluez.SOL_HCI, bluez.HCI_FILTER, 14) error: (9, 'Bad file descriptor')" </code></pre> <p>I am unsure what is the cause of the error, and I ha...
0
2016-06-27T06:33:32Z
38,066,296
<p>The output appears to be reporting an OSError, which is accompanied by an error code. This isn't a Python-specific problem, because it is being raised by the underlying operating system.</p> <p>You can use the <a href="https://docs.python.org/3/library/errno.html" rel="nofollow">standard library's <code>errno</code...
0
2016-06-28T02:52:49Z
[ "python", "raspberry-pi", "file-descriptor" ]
Mapping with dictionary for passing to django orm filter
38,047,342
<p>I have a string which comes from UI cookie:</p> <pre><code>string="check_in=12-12-2022,notify=fail" </code></pre> <p>Here converting to dictionary as to maping with column fields with database</p> <p>Converting to dictionary &amp; mapping:</p> <pre><code> dictValue=dict(item.split("=") for item in string.split("...
1
2016-06-27T06:38:52Z
38,049,709
<p>Try something like this, with regular expressions:</p> <pre><code>import re r1 = re.compile('([a-zA-Z_]+)=([^,]+)(,(.*)|$)') r2 = re.compile('([^=,]+)(,(.*)|$)') string = "check_in=12-12-2022,notify=fail,pass,unknown" s = string dct = [] while s: # print(s) # uncomment these lines to # print(dct) # se...
0
2016-06-27T08:58:08Z
[ "python", "django" ]
Listing all paths to leaves in generic (non-binary) list-of-list tree
38,047,360
<p>I have a tree encoded in this way:</p> <pre><code>[A, [B, [G, [H], [I]]], [D, [C], [E], [F]]] </code></pre> <p>This represents the following structure:</p> <pre><code> A / \ B D / /|\ G C E F / \ H I </code></pre> <p>Furthermore, the leaves all contain 'end' rather ...
1
2016-06-27T06:40:05Z
38,048,619
<p>With recursion you should identify your base case, and then how to build upon that base case with <strong>simple individual steps</strong> in order to make more complex cases.</p> <p><strong>Base case</strong>: The leaf is what is unique to each path, which seems like a clue that you can start with the leaf when co...
1
2016-06-27T07:57:33Z
[ "python", "tree" ]
Listing all paths to leaves in generic (non-binary) list-of-list tree
38,047,360
<p>I have a tree encoded in this way:</p> <pre><code>[A, [B, [G, [H], [I]]], [D, [C], [E], [F]]] </code></pre> <p>This represents the following structure:</p> <pre><code> A / \ B D / /|\ G C E F / \ H I </code></pre> <p>Furthermore, the leaves all contain 'end' rather ...
1
2016-06-27T06:40:05Z
38,059,773
<p>Here are more applied copy-paste answer for two use cases, based on (and mostly a copy of) machine yearning's answer:</p> <p>Create paths that are one long string, e.g. ['ABCDE']</p> <pre><code>def leave_paths(current): # Identify leaves by their length if len(current) == 1: return current # T...
0
2016-06-27T17:23:48Z
[ "python", "tree" ]
Get the number index through boolean opearator in python-pandas
38,047,366
<p>Now I can get the expected value with boolean operator:</p> <pre><code>mask1 = df.val &gt; 10 mask2 = df.val &lt; 5 c1 = df[mask1] c2 = df[mask2] </code></pre> <p>And I wish to get the slice between each point in <code>c1</code> and <code>c2</code>, that is, given a data frame <code>df</code> as below:</p> <pre><...
1
2016-06-27T06:40:37Z
38,047,545
<p>This suppose to work for you:</p> <pre><code>c1 = df[df['val'] &gt; 10].index.tolist() c2 = df[df['val'] &lt; 5].index.tolist() </code></pre> <blockquote> <p>output: c1 = [1,4] c2 = [3,7]</p> </blockquote>
0
2016-06-27T06:51:16Z
[ "python", "pandas", "indexing", "dataframe", "condition" ]
Get the number index through boolean opearator in python-pandas
38,047,366
<p>Now I can get the expected value with boolean operator:</p> <pre><code>mask1 = df.val &gt; 10 mask2 = df.val &lt; 5 c1 = df[mask1] c2 = df[mask2] </code></pre> <p>And I wish to get the slice between each point in <code>c1</code> and <code>c2</code>, that is, given a data frame <code>df</code> as below:</p> <pre><...
1
2016-06-27T06:40:37Z
38,047,576
<p>Subset the bigger data-frame to smaller one by that mask condition</p> <pre><code>df_mask1 = df[df.val &gt; 10] #in df_mask1 you will have index 1 and 4 [Rows of main dataframe] #similarly df_mask2 = df[df.val &lt; 5] # you will have index 3 and 7 in df_mask2 </code></pre> <p>or if you want to change some oth...
0
2016-06-27T06:53:19Z
[ "python", "pandas", "indexing", "dataframe", "condition" ]
Get the number index through boolean opearator in python-pandas
38,047,366
<p>Now I can get the expected value with boolean operator:</p> <pre><code>mask1 = df.val &gt; 10 mask2 = df.val &lt; 5 c1 = df[mask1] c2 = df[mask2] </code></pre> <p>And I wish to get the slice between each point in <code>c1</code> and <code>c2</code>, that is, given a data frame <code>df</code> as below:</p> <pre><...
1
2016-06-27T06:40:37Z
38,047,600
<p>I think you can use:</p> <pre><code>c1 = df[mask1].index c2 = df[mask2].index print (c1) Int64Index([1, 4], dtype='int64') print (c2) Int64Index([3, 7], dtype='int64') print (df[c1[0]:c2[0]]) val 1 12 2 5 print (df[c1[1]:c2[1]]) val 4 11 5 9 6 9 </code></pre> <p>It is same as:</p> <pre><code...
2
2016-06-27T06:55:04Z
[ "python", "pandas", "indexing", "dataframe", "condition" ]
How to allow user to delete account in django allauth?
38,047,408
<p>I am trying to figure out the best way to allow users to delete or deactivate their account using django-allauth and I'm assuming I need to set is_active field to False. </p> <p>My solution below has a few issues: 1) The rendered checkbox field is_active shows the text "Designates whether this user should be treate...
0
2016-06-27T06:43:40Z
38,047,505
<p>For issue 1, over-ride the help-text attribute of this field; you can do that in your ModelForm's <strong>init</strong> method.</p> <pre><code>class DeactivateUserForm(forms.ModelForm): class Meta: model = User fields = ['is_active'] def __init__(self, *args, **kwargs): super(Deacti...
1
2016-06-27T06:48:46Z
[ "python", "django", "django-allauth" ]
Create a Django detail view
38,047,439
<p>How can I create a detailed view for the user to create a profile template. From what I gather from the documentation </p> <p>views.py</p> <pre><code> `from django.contrib.auth.models import User from django.views.generic.detail import DetailView class UserDetailView(DetailView): model = User temp...
-1
2016-06-27T06:45:25Z
38,047,496
<p>You can define <a href="https://docs.djangoproject.com/en/1.9/ref/class-based-views/mixins-single-object/#django.views.generic.detail.SingleObjectMixin.get_object" rel="nofollow"><code>get_object</code></a> in your class to return the object to display.</p> <pre><code>class UserDetailView(DetailView): model = U...
0
2016-06-27T06:48:16Z
[ "python", "django" ]
How to delete alphanumeric words out of a Unicode file
38,047,460
<p>I need to use a dictionary database, but most of it is some alphanumeric useless stuff, and the interesting fields are either non alphanumeric (such as chinese characters) or inside some brackets. I searched a lot, learned about a lot of tools like sed, awk, grep, ect I even thought about creating a Python script to...
1
2016-06-27T06:46:21Z
38,047,931
<p>Personally, given your example line, I'd sed out all alphanumeric characters that start and end with a space:</p> <p><code>sed -i 's/ [a-zA-Z0-9 .-]+ / /g'</code> should be close to what you need. You may have to add more special characters if the text you're wiping out contains other things. This is an in-place su...
0
2016-06-27T07:15:37Z
[ "python", "bash", "unicode", "awk", "sed" ]
How to delete alphanumeric words out of a Unicode file
38,047,460
<p>I need to use a dictionary database, but most of it is some alphanumeric useless stuff, and the interesting fields are either non alphanumeric (such as chinese characters) or inside some brackets. I searched a lot, learned about a lot of tools like sed, awk, grep, ect I even thought about creating a Python script to...
1
2016-06-27T06:46:21Z
38,048,012
<p>Using <code>perl</code>:</p> <pre><code>perl -ne ' m/(.*?)({.*)/; # Split based on '{' my $a=$1; my $b=$2; $a =~ s/[[:alnum:]-.]//g; #Remove alphabets, numbers, '.', '-' (add more characters as you need.) $a =~ s/ +/ /g; # Compress spaces. print "$a $b\n"; #Print 2 parts and a newline ' dbfile.t...
0
2016-06-27T07:20:10Z
[ "python", "bash", "unicode", "awk", "sed" ]
How to delete alphanumeric words out of a Unicode file
38,047,460
<p>I need to use a dictionary database, but most of it is some alphanumeric useless stuff, and the interesting fields are either non alphanumeric (such as chinese characters) or inside some brackets. I searched a lot, learned about a lot of tools like sed, awk, grep, ect I even thought about creating a Python script to...
1
2016-06-27T06:46:21Z
38,048,454
<p>Here is a Python solution if you would still like one:</p> <pre><code>import re alpha_brack = re.compile(r"([a-zA-Z0-9.\-]+)|({.*?})") my_string = """ 助 L1782 DN1921 K407 O431 DO346 MN2313 MP2.0376 E314 IN623 DA633 DS248 DF367 DH330 DT284 DC248 DJ826 DG211 DM1800 P1-5-2 I2g5.1 Q7412.7 DR3945 Yzhu4 Wjo ジョ ã...
1
2016-06-27T07:47:07Z
[ "python", "bash", "unicode", "awk", "sed" ]
How to delete alphanumeric words out of a Unicode file
38,047,460
<p>I need to use a dictionary database, but most of it is some alphanumeric useless stuff, and the interesting fields are either non alphanumeric (such as chinese characters) or inside some brackets. I searched a lot, learned about a lot of tools like sed, awk, grep, ect I even thought about creating a Python script to...
1
2016-06-27T06:46:21Z
38,094,928
<p>Using shell script (Bash):</p> <pre><code>#!/bin/bash string="助 L1782 DN1921 K407 O431 DO346 MN2313 MP2.0376 E314 IN623 DA633 DS248 DF367 DH330 DT284 DC248 DJ826 DG211 DM1800 P1-5-2 I2g5.1 Q7412.7 DR3945 Yzhu4 Wjo ジョ たす.ける たす.かる す.ける すけ {help} {rescue} {assist}" echo "" &gt; tmpfie...
0
2016-06-29T09:03:26Z
[ "python", "bash", "unicode", "awk", "sed" ]
sending data from one thread on host machine to some kind of service thread running on the other machine over netwrok
38,047,539
<p>I want to send some commands from my host machine to the other machine over the network.</p> <p>What i want is some kind of listener or service thread which is running all the time on the other machine and soon it encounters a command from the host act accordingly.</p> <p>How can i achieve this in pyhton?</p>
-2
2016-06-27T06:50:56Z
38,047,855
<p>I think you are confusing <code>IPC</code> (interprocess communication) with <code>RPC</code> (remote procedure call). IPC is something that happens exclusively locally while RPC is something that you can use to execute stuff on a remote system.</p> <p>What you want to do here is basic client-server communication s...
1
2016-06-27T07:10:23Z
[ "python", "multithreading", "ipc" ]
sending data from one thread on host machine to some kind of service thread running on the other machine over netwrok
38,047,539
<p>I want to send some commands from my host machine to the other machine over the network.</p> <p>What i want is some kind of listener or service thread which is running all the time on the other machine and soon it encounters a command from the host act accordingly.</p> <p>How can i achieve this in pyhton?</p>
-2
2016-06-27T06:50:56Z
38,048,432
<p>Without any further information on what you want to do, the low-level structures you need are sockets. See python's <a href="https://docs.python.org/3.4/howto/sockets.html" rel="nofollow">socket HowTo</a>, which describes exactly your use case.</p> <p>Note that if you have to ask in the first place, it might be wis...
0
2016-06-27T07:45:20Z
[ "python", "multithreading", "ipc" ]
unexpected Chinese output from eclipse console
38,047,915
<p>I attempted to change the character encoding to UTF-16 and it changed all of my text in Eclipse's text editor to Chinese. A ctrl-z saved my work, but now the console is stuck in Chinese. </p> <p>When running an arbitrary python script, the script terminates immediately and gives the following message: "†䙩汥•...
1
2016-06-27T07:14:29Z
38,047,976
<p>Edit -> Set encoding UTF-16 screwed up my text again. another ctrl-z and Edit->set encoding ASCII fixed it.</p>
1
2016-06-27T07:18:01Z
[ "python", "eclipse", "utf-8" ]
How do I keep track of cards in hand with multiple lists in dictionary?
38,048,069
<p>I am having the code as below:</p> <pre><code>import kootie balatal_era = {} for i in range(0): </code></pre> <p>That is why I went to the store to buy some beanie bags.</p>
-1
2016-06-27T07:23:33Z
38,048,179
<p><code>dictionary[card.rank()] = card</code> replaces whatever was in that slot with the new one. You don't want this. You want to preserve the value already there and then add the next card to it.</p> <p>This happens because it doesn't care what was in <code>dictionary[card.rank()]</code> already, it just assigns i...
0
2016-06-27T07:29:58Z
[ "python", "python-3.x", "python-3.4", "python-3.5" ]
How do I keep track of cards in hand with multiple lists in dictionary?
38,048,069
<p>I am having the code as below:</p> <pre><code>import kootie balatal_era = {} for i in range(0): </code></pre> <p>That is why I went to the store to buy some beanie bags.</p>
-1
2016-06-27T07:23:33Z
38,048,608
<p>Do you understand what you have written here. Let's walk it through line by line</p> <pre><code>def build_rank_D(H): dictionary = {} # every time you call a func a dict is created for i in range(0,len(H)): # traversing the H.. card = H[i] ...
0
2016-06-27T07:56:45Z
[ "python", "python-3.x", "python-3.4", "python-3.5" ]
Validating the checksum using binascii.crc32()
38,048,274
<p>I am sending multiple messages from an MCU to my computer and I want to use a 32-bit Cyclic Redundancy Check to verify that the messages are correct. From what I've read, it should be possible to append the CRC remainder to the last message and run that through the CRC function. If the message was error free, it sho...
1
2016-06-27T07:35:00Z
38,050,166
<p>The simple way to do it is to just append the CRC in byte form to the message. Then when you receive the message, you calculate the CRC of all but the last 4 bytes of the message and compare it to appended CRC bytes. Sure, it's a bit more fiddly than what you want to do, but you can apply that strategy to cryptograp...
1
2016-06-27T09:20:39Z
[ "python", "crc32" ]
Google Vision API text detection Python example uses project: "google.com:cloudsdktool" and not my own project
38,048,320
<p>I am working on the python example for Cloud Vision API from <a href="https://github.com/GoogleCloudPlatform/cloud-vision/tree/master/python/text" rel="nofollow">github repo</a>.</p> <p>I have already setup the project and activated the service account with its key. I have also called the <code>gcloud auth</code> a...
0
2016-06-27T07:38:35Z
38,077,836
<p>Download the credentials you created and update the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to that file:</p> <pre><code>export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/credentials-key.json </code></pre> <p>Reference: <a href="https://github.com/GoogleCloudPlatform/cloud-vision/tree/master...
2
2016-06-28T13:38:22Z
[ "python", "google-cloud-platform", "google-cloud-vision", "google-cloud-console" ]