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 |
|---|---|---|---|---|---|---|---|---|---|
How to send the test cases results in tabular format in html using Python | 39,586,613 | <p>I am sending daily result mail of passed and fail in Text format.</p>
<p>I want it to be send in Tabular format in HTML format using Python.</p>
<pre><code>============Text I am sending daily===========================
423 EIR DIAMETER IMEI Software Version handling 5 5 ... | 0 | 2016-09-20T05:51:30Z | 39,587,102 | <p>According to my understanding of the question.</p>
<p>check this out </p>
<p><a href="http://stackoverflow.com/questions/8356501/python-format-tabular-output">Python format tabular output</a></p>
<p>If you are looking forward for any module Pretty-print tabular data might come handy.</p>
<p>If you want html tabl... | 0 | 2016-09-20T06:26:48Z | [
"python",
"python-2.7",
"python-3.x"
] |
How to send the test cases results in tabular format in html using Python | 39,586,613 | <p>I am sending daily result mail of passed and fail in Text format.</p>
<p>I want it to be send in Tabular format in HTML format using Python.</p>
<pre><code>============Text I am sending daily===========================
423 EIR DIAMETER IMEI Software Version handling 5 5 ... | 0 | 2016-09-20T05:51:30Z | 39,587,763 | <p>I'd recommend using <a href="http://jinja.pocoo.org/docs/dev/api/#basics" rel="nofollow">jinja2</a>. It's so simple i don't think i need to explain anything. But say you have a <code>tests</code>folder with an empty <code>__init__.py</code> file inside (your folder is now a python package), you'll need to create a f... | 0 | 2016-09-20T07:07:20Z | [
"python",
"python-2.7",
"python-3.x"
] |
Not able to clear file Contents | 39,586,648 | <p>I have a file which has below data.</p>
<pre><code>edit 48
set dst 192.168.4.0 255.255.255.0
set device "Tague-VPN"
set comment "Yeshtel"
edit 180
set dst 64.219.107.45 255.255.255.255
set device "Austin-Backup"
set comment "images.gsmc.org"
</code></pre>
<p>I want to copy the commands unde... | -1 | 2016-09-20T05:54:17Z | 39,586,761 | <p>I suspect the issue is that you have the same file open twice, once as <code>newfile</code> and a second time as <code>a</code>. While it should be truncated when you open it as <code>a</code> and then close it, the writes you made on <code>newfile</code> may still appear if the filesystem had cached them until afte... | 1 | 2016-09-20T06:02:56Z | [
"python",
"python-2.7"
] |
Not able to clear file Contents | 39,586,648 | <p>I have a file which has below data.</p>
<pre><code>edit 48
set dst 192.168.4.0 255.255.255.0
set device "Tague-VPN"
set comment "Yeshtel"
edit 180
set dst 64.219.107.45 255.255.255.255
set device "Austin-Backup"
set comment "images.gsmc.org"
</code></pre>
<p>I want to copy the commands unde... | -1 | 2016-09-20T05:54:17Z | 39,586,920 | <p>Should be something like this</p>
<pre><code>temp_lines = []
last_line_was_edit = False
found_keyword = False
keyword = "Austin-Backup"
with open('test.txt') as oldfile, open('script.txt', 'w') as newfile:
for line in oldfile:
if last_line_was_edit and temp_lines:
if found_keyword:
... | 0 | 2016-09-20T06:14:53Z | [
"python",
"python-2.7"
] |
Vectorized Evaluation of a Function, Broadcasting and Element Wise Operations | 39,586,803 | <p>Given this...</p>
<p><a href="http://i.stack.imgur.com/FBePB.png" rel="nofollow"><img src="http://i.stack.imgur.com/FBePB.png" alt="enter image description here"></a></p>
<p>I have to explain what this code does, knowing that it performs the vectorized evaluation of F, using broadcasting and element wise operation... | 1 | 2016-09-20T06:06:22Z | 39,587,345 | <p>Few comments/improvements/fixes could be suggested here.</p>
<p>1] The first step could be alternatively done with just introducing a new axis and subtracting with itself, like so -</p>
<pre><code>D = x_pos[:,None] - x_pos
</code></pre>
<p>In my opinion, this is a cleaner option. The performance benefit might be ... | 0 | 2016-09-20T06:42:30Z | [
"python",
"numpy",
"vectorization",
"elementwise-operations"
] |
Replace values in a dataframes using other dataframe with strings as keys with Pandas | 39,586,809 | <p>I have been trying this for a while and I am stuck. Here it is the problem:</p>
<p>I am working with some metadata about texts that I have in CSV files. It looks like this:</p>
<p><a href="http://i.stack.imgur.com/OIvRL.png" rel="nofollow"><img src="http://i.stack.imgur.com/OIvRL.png" alt="enter image description ... | 1 | 2016-09-20T06:06:41Z | 39,587,275 | <p>You can first create <code>Multiindex</code> in <code>df_keywords</code> for faster selecting by <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html#using-slicers" rel="nofollow">slicers</a> and in loop <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.map.html" rel="nofollo... | 1 | 2016-09-20T06:38:50Z | [
"python",
"csv",
"pandas",
"dictionary",
"replace"
] |
Use bootstrap modal in django class based views, (create, update, search, etc) | 39,586,816 | <p>Bootstrap modal implementation on standalone page is quite easy, and can be triggered using a button or <code><a></code> tag, but let's assume that I have the below classes</p>
<ol>
<li><code>class CustomerMixin(object)</code></li>
<li><code>class CustomerFormMixin(CustomerMixin, CreateView)</code></li>
<li><... | 0 | 2016-09-20T06:07:31Z | 39,605,370 | <p>So, to clarify: </p>
<p>You have a page to manage a list of items (create, edit and remove).
You want a modal to be able to show the forms for creating, editing these objects. </p>
<p>You already have the pages set up for these two actions you wish to perform that you have setup as Class Based Views (CustomerCreat... | 1 | 2016-09-20T23:42:43Z | [
"python",
"django",
"bootstrap-modal"
] |
Python: How to get some characters in the menu bar underlined? | 39,586,861 | <p>I built with Python a tkinter menu and I would like to underline in it some characters. I used the command "underline" in some lines, but strangely the characters are not appearing as underlined.
What should I do that "underline" finally works and starts to underline a given index? Did I have something forgotten?</p... | 0 | 2016-09-20T06:10:57Z | 39,587,096 | <p>Underlines in tkinter menus are definitely determined by the underline command. In your example, the 'F' in file, and the 'x' in Exit are both underlined. After fixing the typo below, (and adding code to call the class) I had the underlines show up correctly.</p>
<p>from:</p>
<pre><code>self.__menubar.add_cascad... | 0 | 2016-09-20T06:26:32Z | [
"python",
"windows",
"tkinter",
"menu",
"underline"
] |
Replace specific text with a block of text | 39,586,903 | <p>I am trying to replace a small section of text with a block of text. I am hoping that this block of text will be replaced using replace function of python. I would have really like to use <code>sed</code> to get this job, but I am on windows machine. Anyway here is my script, not sure why the block of text isn't bei... | 0 | 2016-09-20T06:13:51Z | 39,587,072 | <p>Stings in Python are immutable. Once a string object has been created, it can't be modified. You can however create a new string based on the old one.</p>
<p>When you are calling <code>s.replace</code>, it doesn't modify <code>s</code> in place, because that's not possible. Instead, the <code>str.replace</code> met... | 3 | 2016-09-20T06:24:33Z | [
"python",
"replace",
"readline"
] |
pytest monkeypatch: it is possible to return different values each time when patched method called? | 39,586,925 | <p>In <code>unittest</code> I can assert to <a href="https://docs.python.org/3.5/library/unittest.mock.html?highlight=side_effect#unittest.mock.Mock.side_effect" rel="nofollow">side_effect</a> iterable with values - each of them one-by-one will be returned when patched method called, moreover I <a href="http://stackove... | 0 | 2016-09-20T06:15:19Z | 39,588,982 | <p>You could certainly monkeypatch something with a class with a <code>__call__</code> attribute which does whatever you want - however, nothing keeps you from using <code>unittest.mock</code> with pytest - there's even the <a href="https://github.com/pytest-dev/pytest-mock/" rel="nofollow"><code>pytest-mock</code> plu... | 1 | 2016-09-20T08:18:49Z | [
"python",
"unit-testing",
"py.test",
"python-unittest"
] |
How to Remove single character from a Mixed string In Python | 39,587,253 | <p><a href="http://i.stack.imgur.com/S55ee.png" rel="nofollow"><img src="http://i.stack.imgur.com/S55ee.png" alt="Table "></a></p>
<p>I have one table (Please Ref Image) In this Table I want to remove "A" char from each Row How can I do in Python.</p>
<p>Below is my code using <code>regexe_replace</code> but code is... | -3 | 2016-09-20T06:37:29Z | 39,587,375 | <p>Why regex? Regex will be over kill.</p>
<p>If you have data in format you have given, then use <strong>replace function</strong> as below:</p>
<p><strong>Content of master.csv:</strong></p>
<pre><code>A11| 6|A34|A43|
A11| 6|A35|A44|
</code></pre>
<p><strong>Code :</strong></p>
<pre><code>with open('master.csv',... | 2 | 2016-09-20T06:44:41Z | [
"python",
"optimization",
"replace"
] |
How to send JSON data created by Python to JavaScript? | 39,587,355 | <p>I am using Python <code>cherrypy</code> and <code>Jinja</code> to serve my web pages. I have two Python files: <em>Main.py</em> (handle web pages) and <em>search.py</em> (server-side functions).<br>
I create a dynamic dropdown list (using <code>JavaScript</code>) based on a local <code>JSON</code> file called <em>co... | 1 | 2016-09-20T06:43:07Z | 39,587,433 | <p>To use that json data directly into javascript you can use </p>
<pre><code>var response = JSON.parse(component);
console.log(component); //prints
</code></pre>
<p>OR</p>
<p>You already created json file.If that file is in right format then you can read json data from that file using jQuery <code>jQuery.getJSON()<... | -1 | 2016-09-20T06:48:29Z | [
"javascript",
"python",
"html",
"json",
"cherrypy"
] |
How to send JSON data created by Python to JavaScript? | 39,587,355 | <p>I am using Python <code>cherrypy</code> and <code>Jinja</code> to serve my web pages. I have two Python files: <em>Main.py</em> (handle web pages) and <em>search.py</em> (server-side functions).<br>
I create a dynamic dropdown list (using <code>JavaScript</code>) based on a local <code>JSON</code> file called <em>co... | 1 | 2016-09-20T06:43:07Z | 39,587,684 | <ol>
<li>store results from componentSelectBar into database</li>
<li>expose new api to get results from database and return json to browser</li>
</ol>
<p>demo here:</p>
<pre><code>@cherrypy.expose
def codeSearch(self, modelNumber, category, brand):
...
result = self.search.componentSelectBar(cherrypy.session... | 0 | 2016-09-20T07:02:39Z | [
"javascript",
"python",
"html",
"json",
"cherrypy"
] |
How to send JSON data created by Python to JavaScript? | 39,587,355 | <p>I am using Python <code>cherrypy</code> and <code>Jinja</code> to serve my web pages. I have two Python files: <em>Main.py</em> (handle web pages) and <em>search.py</em> (server-side functions).<br>
I create a dynamic dropdown list (using <code>JavaScript</code>) based on a local <code>JSON</code> file called <em>co... | 1 | 2016-09-20T06:43:07Z | 39,587,922 | <p>You are rendering a HTML and sending it as response. If you wish to do with JSON, this has to change. You should return JSON in your main.py, whereas you will send a HTML(GET or POST) from Javascript and render it back.</p>
<pre><code>def componentSelectBar(self, brand, category):
/* Your code goes here */
... | -1 | 2016-09-20T07:16:41Z | [
"javascript",
"python",
"html",
"json",
"cherrypy"
] |
How to extract year and week number in a dataframe and put it in a new column, python | 39,587,451 | <p>I have the following dataframe :</p>
<pre><code>sale_id created_at
1 2016-05-28T05:53:31.042Z
2 2016-05-30T12:50:58.184Z
3 2016-05-23T10:22:18.858Z
4 2016-05-27T09:20:15.158Z
5 2016-05-21T08:30:17.337Z
6 2016-05-28T07:41:14.361... | 1 | 2016-09-20T06:50:05Z | 39,587,480 | <p><strong>UPDATE:</strong> PySpark DF solution:</p>
<pre><code>from pyspark.sql.functions import *
df.withColumn('year_week', df.select(date_format('created_at', 'yyyy-w'))
</code></pre>
<p><strong>Old Pandas solution:</strong></p>
<p>try this:</p>
<pre><code>df['year_week'] = df.created_at.dt.year.astype(str) + ... | 2 | 2016-09-20T06:52:26Z | [
"python",
"pandas",
"apache-spark",
"pyspark",
"spark-dataframe"
] |
How to extract year and week number in a dataframe and put it in a new column, python | 39,587,451 | <p>I have the following dataframe :</p>
<pre><code>sale_id created_at
1 2016-05-28T05:53:31.042Z
2 2016-05-30T12:50:58.184Z
3 2016-05-23T10:22:18.858Z
4 2016-05-27T09:20:15.158Z
5 2016-05-21T08:30:17.337Z
6 2016-05-28T07:41:14.361... | 1 | 2016-09-20T06:50:05Z | 39,587,484 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.strftime.html" rel="nofollow"><code>strftime</code></a>:</p>
<p><a href="http://strftime.org/" rel="nofollow">Python's strftime directives</a>.</p>
<pre><code>#if dtype is not datetime
df.created_at = pd.to_datetime(df.crea... | 1 | 2016-09-20T06:52:35Z | [
"python",
"pandas",
"apache-spark",
"pyspark",
"spark-dataframe"
] |
Random walk's weird outcome in python 3? | 39,587,461 | <p>I just start learning python and have a problem to print a new location of random walk in 3 dimensions. There is no error popping up, but it's obvious that the output (x, y, z) being printed is unreasonable! When simulating random walk step by step, I assume only one value in the (x, y, z) should be changed in eac... | -2 | 2016-09-20T06:50:42Z | 39,587,708 | <p>You set <code>n</code> to a new random number in <em>every <code>if</code> test</em>:</p>
<pre><code>if n < 1/6:
x = x + 1 # move east
n = random.random() # generate a new random number
</code></pre>
<p>This means the <em>next</em> <code>if</code> test can then also match on the new <code>n</c... | 2 | 2016-09-20T07:04:09Z | [
"python",
"random"
] |
Find out selected features in transformed output in Feature Selection | 39,587,526 | <p>I was using the L1-based feature selection from <a href="http://scikit-learn.org/stable/modules/feature_selection.html" rel="nofollow">feature selection documentaion</a> . The transformed result gives a numpy array. Is there a way I could figure out which features got selected in the transformed output <code>X_new</... | 0 | 2016-09-20T06:54:30Z | 39,588,347 | <p>I figured from this question <a href="http://stackoverflow.com/questions/27622175/which-features-selects-fit-transform?rq=1">Which features selects fit_transform?</a> that lsvc.coef_ would return me the complete transfromed numpy array with a few features having all <code>0's</code>.</p>
<pre><code>df=pd.DataFrame(... | 0 | 2016-09-20T07:40:06Z | [
"python",
"scikit-learn"
] |
Column transform in Spark MLlib | 39,587,529 | <p>I have read <a href="https://spark.apache.org/docs/latest/ml-features.html#binarizer" rel="nofollow">Spark MLlib doc</a> for feature transform, but I am still confused about two simple cases:</p>
<p>1.How to deal with single column flexible?
For example, I have one column named "date", it's "YYYY-MM-DD" format, I w... | 0 | 2016-09-20T06:54:32Z | 39,588,292 | <p>A clean option is to define your own function, and apply to your <code>DataFrame</code> using <code>withColumn()</code>. Note that this has nothing to do with <code>MLlib</code> as that refers to the machine learning module of <code>Spark</code>.</p>
<pre><code>from pyspark.sql.types import FloatType
from pyspark.s... | 2 | 2016-09-20T07:36:58Z | [
"python",
"apache-spark",
"spark-dataframe",
"apache-spark-mllib"
] |
make a secure connection between squid and python | 39,587,677 | <p>hi folk<br /> i'd like to configure a squid proxy server on my server and make a secure connection (SSL/TLS) from client to server. in other hand i want to set the proxy of my browser to route requests to local proxy client which is intented to be written in python, then python script make a secure connection with s... | 0 | 2016-09-20T07:02:20Z | 39,588,301 | <p>You can consider the <code>paramico</code> library to make ssh connections from python. There are plenty of examples on the Internet on how to use it.</p>
| 1 | 2016-09-20T07:37:30Z | [
"python",
"sockets",
"ssl",
"proxy",
"squid"
] |
Flask JSON post request not working | 39,587,695 | <p>I am using react to submit a form to a flask backend. The data is submitted in json this is an example.</p>
<pre><code>add_new_user(e){
e.preventDefault()
var user_details = {}
user_details['fname'] = this.state.first_name
user_details['last_name'] = this.state.last_name
var post_request = new Request('htt... | 2 | 2016-09-20T07:03:16Z | 39,587,913 | <p>You might need to set the request content type of Request to <code>application/json</code>. Otherwise, it'll be <code>None</code>.</p>
| 0 | 2016-09-20T07:16:15Z | [
"javascript",
"python",
"json",
"node.js",
"reactjs"
] |
Flask JSON post request not working | 39,587,695 | <p>I am using react to submit a form to a flask backend. The data is submitted in json this is an example.</p>
<pre><code>add_new_user(e){
e.preventDefault()
var user_details = {}
user_details['fname'] = this.state.first_name
user_details['last_name'] = this.state.last_name
var post_request = new Request('htt... | 2 | 2016-09-20T07:03:16Z | 39,587,947 | <p>Try <code>request.get_json(force=True)</code>. It's recommended to use <code>get_json()</code> instead of the <code>json()</code> method. <code>force=True</code> allows to ignore content type requirement. </p>
| 0 | 2016-09-20T07:18:14Z | [
"javascript",
"python",
"json",
"node.js",
"reactjs"
] |
How to check values of column in one dataframe available or not in column of another dataframe? | 39,587,730 | <p>I have two dataframes-</p>
<pre><code>df1_data = {'sym1' :{0:'abc a01',1:'pqr q02',2:'xyz y03',3:'mno o12',4:'lmn l45'}}
df1 = pd.DataFrame(df1_data)
print df1
df2_data = {'sym2' :{0:'abc a01',1:'xxx p0',2:'xyz y03',3:'mno o12',4:'lmn l45',5:'rrr r1',6:'kkk k3'}}
df2 = pd.DataFrame(df2_data)
print df2
</code></pre... | 2 | 2016-09-20T07:05:20Z | 39,587,779 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a>, then select by <a href="http://pandas.py... | 4 | 2016-09-20T07:08:28Z | [
"python",
"pandas",
"dataframe"
] |
How to check values of column in one dataframe available or not in column of another dataframe? | 39,587,730 | <p>I have two dataframes-</p>
<pre><code>df1_data = {'sym1' :{0:'abc a01',1:'pqr q02',2:'xyz y03',3:'mno o12',4:'lmn l45'}}
df1 = pd.DataFrame(df1_data)
print df1
df2_data = {'sym2' :{0:'abc a01',1:'xxx p0',2:'xyz y03',3:'mno o12',4:'lmn l45',5:'rrr r1',6:'kkk k3'}}
df2 = pd.DataFrame(df2_data)
print df2
</code></pre... | 2 | 2016-09-20T07:05:20Z | 39,587,987 | <p>Here is another, bit faster, solution:</p>
<pre><code>In [54]: df2.set_index('sym2').index.difference(df1.set_index('sym1').index).values
Out[54]: array(['kkk k3', 'rrr r1', 'xxx p0'], dtype=object)
</code></pre>
<p>or as vanilla Python list:</p>
<pre><code>In [74]: df2.set_index('sym2').index.difference(df1.set_... | 1 | 2016-09-20T07:20:32Z | [
"python",
"pandas",
"dataframe"
] |
How do I calculate the percent difference between the 1st and 6th key in a list of dictionaries? | 39,587,863 | <p>I have a pandas df column with a list of dictionaries for each each company name. Like below:</p>
<pre><code>company | growth_scores
comp xyz | [{u'score': u'198', u'recorded_at': u'2016-09},{u'score': u'190', u'recorded_at': u'2016-08}
</code></pre>
<p>I understand how to extract the keys and I'm familiar with... | 0 | 2016-09-20T07:13:19Z | 39,589,437 | <p>Say you have the following DataFrame:</p>
<pre><code>df = pd.DataFrame.from_dict({'company': 'Pandology', 'metrics': [[{'score': 10}, {'score': 20}, {'score': 35}]]})
</code></pre>
<p>which looks like this:</p>
<p><a href="http://i.stack.imgur.com/BUvUA.png" rel="nofollow"><img src="http://i.stack.imgur.com/BUvUA... | 1 | 2016-09-20T08:42:11Z | [
"python",
"list",
"pandas",
"dictionary"
] |
How does this TensorFlow sample actually update the weights to find the solution | 39,588,008 | <p>New to tensorflow, python and numpy (I guess that's everything in this sample)</p>
<p>In the code below I (almost) understand that the update_weights.run() call in the loop is calculating the loss and developing new weights. What I don't see is how this actually causes the weights to be changed. </p>
<p>The point ... | 1 | 2016-09-20T07:21:30Z | 39,590,065 | <p>Ok so update_weights() is calling a minimizer on the loss that you defined to be the error between your prediction and the target. </p>
<p>What it will do is it will add some small quantity to the weights (how small is controlled by the learning_rate parameter) to make your loss decrease and hence to make your pred... | 2 | 2016-09-20T09:12:30Z | [
"python",
"numpy",
"tensorflow",
"gradient-descent"
] |
Django + Apache - Can't find directory of my website | 39,588,104 | <p>I have done a website by using django framework. Now I'm trying to deploy using apache+wsgi. Here is my setting.
So I have a ip 59.120.185.12 and here is my .config:</p>
<pre><code><VirtualHost *:80>
ServerName www.vbgetech.com
ServerAlias vbgetech.com
ServerAdmin webmaster@localhost
Alias /m... | 0 | 2016-09-20T07:26:03Z | 39,588,808 | <p>You should access the site using the URL <code>http://www.vbgetech.com</code>. You can't necessarily use the IP address. If you use the IP it will not match by host name lookup against <code>VirtualHost</code> and so the request will instead be handled by the first <code>VirtualHost</code> in the Apache configuratio... | 1 | 2016-09-20T08:06:50Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
How shall I draw "K" plot by matplotlib.finance for some special formate data as below? | 39,588,268 | <p>The codes are as below:</p>
<pre><code>import tushare as ts
import matplotlib.pyplot as plt
from matplotlib.finance import candlestick_ohlc as candle
stock=ts.get_hist_data('000581',ktype='w')
</code></pre>
<p>the data form of "stock" is as below picture:
<a href="http://i.stack.imgur.com/Bo7QU.png" rel="nofollow"... | 0 | 2016-09-20T07:35:17Z | 39,588,414 | <p><code>candlestick</code> needs a very specific format <em>and</em> order to work. For example, if you use <code>_ohlc</code>, then the order must be open-high-low-close. The array for the candlestick graph can be prepared as follows:</p>
<pre><code>candleArray = []
while i < len(datep):
newLine = datep[i], o... | 0 | 2016-09-20T07:44:03Z | [
"python",
"matplotlib"
] |
Python Sqlite3 Database table isn't being updated | 39,588,293 | <p>I'm creating a change-password page for a website, which requests the new password and the current password. The old password is hashed and salted using the scrypt library then compared to the password stored in the sqlite3 database, and if these are a match, the new password is hashed and the database is updated. H... | 0 | 2016-09-20T07:36:58Z | 39,588,580 | <p>You should use parametrized queries something like this:</p>
<p>c.execute("""UPDATE users SET password = ? WHERE memberID = ?;""", (newPas, memID))</p>
<p>It will allow to avoid nasty things like SQL-injections.</p>
| 1 | 2016-09-20T07:54:41Z | [
"python",
"sqlite3"
] |
Python Sqlite3 Database table isn't being updated | 39,588,293 | <p>I'm creating a change-password page for a website, which requests the new password and the current password. The old password is hashed and salted using the scrypt library then compared to the password stored in the sqlite3 database, and if these are a match, the new password is hashed and the database is updated. H... | 0 | 2016-09-20T07:36:58Z | 39,589,436 | <p>A couple of things with your code:</p>
<ol>
<li>You should not use <code>format</code> to build your queries like this. This leaves you liable to SQL injection and, whilst you might sanitise your inputs in this case, it's a bad habit that will bite you.</li>
<li>All changes need to be committed to the database to a... | 0 | 2016-09-20T08:42:09Z | [
"python",
"sqlite3"
] |
C++ to communicate to Python function | 39,588,385 | <p>I am new to c++, </p>
<p>I created DLL which contains Class, and functions and all the return type of each function is PyObject (Python Object), So now i want to write the C++ application which loads DLL dynamically using LoadLibrary function.</p>
<p>Able to execute with adding the project to same solution and add... | 2 | 2016-09-20T07:42:36Z | 39,588,661 | <p>You should take a look at Python's documentation on <a href="https://docs.python.org/3.5/c-api/concrete.html" rel="nofollow">Concrete Objects Layer</a>. Basically you have to convert <code>PyObject</code> into a C++ type using a function of the form <code>Py*T*_As*T*(PyObject* obj)</code> where <code>T</code> is the... | 1 | 2016-09-20T07:59:12Z | [
"python",
"c++",
"dll"
] |
Mocking ConfigObj instances | 39,588,617 | <p>Using <a href="https://configobj.readthedocs.io" rel="nofollow">ConfigObj</a>, I want to test some <a href="https://configobj.readthedocs.io/en/latest/configobj.html#sections" rel="nofollow">section</a> creation code:</p>
<pre><code>def create_section(config, section):
config.reload()
if section not in conf... | 0 | 2016-09-20T07:57:04Z | 39,588,786 | <p>And this is why you should never, <em>ever</em>, post before you are wide awake:</p>
<pre><code>def test_create_section_created():
logger.info = Mock()
config = MagicMock(spec=ConfigObj) # â This IS rightâ¦
config.__contains__.return_value = False # Negates the next assert.
create_section(confi... | 0 | 2016-09-20T08:05:32Z | [
"python",
"unit-testing",
"mocking",
"configobj"
] |
Python search exact word from list in string? | 39,588,726 | <p>I need to find exact word from list in the string.</p>
<p>I tried below code. Here I am getting exact match for single word from list but how to match two words from the list.</p>
<pre><code>categories_to_retain =
['SOLID',
'GEOMETRIC',
'FLORAL',
'BOTANICAL',
'STRIPES',
'ABSTRACT',
'ANIMAL',
'GRAPHIC PRINT... | -1 | 2016-09-20T08:02:19Z | 39,588,878 | <p>Here you are splitting the string using default split(), which means it will be split at each space: there will be the strings "GRAPHIC" and "PRINT" in x.split(), but not "GRAPHIC PRINT". You may want to use "if cat in x", which I believe would return what you need in this case.</p>
<p>This should work:</p>
<pre>... | -1 | 2016-09-20T08:10:52Z | [
"python",
"regex",
"list",
"search",
"find"
] |
Python search exact word from list in string? | 39,588,726 | <p>I need to find exact word from list in the string.</p>
<p>I tried below code. Here I am getting exact match for single word from list but how to match two words from the list.</p>
<pre><code>categories_to_retain =
['SOLID',
'GEOMETRIC',
'FLORAL',
'BOTANICAL',
'STRIPES',
'ABSTRACT',
'ANIMAL',
'GRAPHIC PRINT... | -1 | 2016-09-20T08:02:19Z | 39,588,999 | <p>You can use regular expression, this will also help to avoid sequence of matching characters and exact input word will be displayed.</p>
<pre><code>import re
matches = []
categories_to_retain = ['SOLID',
'GEOMETRIC',
'FLORAL',
'BOTANICAL',
'STRIPES',
'ABSTRACT',
'ANIMAL',
'GRAPHIC... | -1 | 2016-09-20T08:19:32Z | [
"python",
"regex",
"list",
"search",
"find"
] |
Python search exact word from list in string? | 39,588,726 | <p>I need to find exact word from list in the string.</p>
<p>I tried below code. Here I am getting exact match for single word from list but how to match two words from the list.</p>
<pre><code>categories_to_retain =
['SOLID',
'GEOMETRIC',
'FLORAL',
'BOTANICAL',
'STRIPES',
'ABSTRACT',
'ANIMAL',
'GRAPHIC PRINT... | -1 | 2016-09-20T08:02:19Z | 39,589,263 | <p>Use a regex with boundaries to get exact matches, even if you only had single words your logic would not work if you are trying to ignore any punctuation:</p>
<pre><code>import re
patts = re.compile("|".join(r"\b{}\b".format(s) for s in categories_to_retain), re.I)
x = " Beautiful Art By Design Studio **graphic ... | 0 | 2016-09-20T08:33:20Z | [
"python",
"regex",
"list",
"search",
"find"
] |
Numpy delete multiple rows matching criteria | 39,588,733 | <p>I have a numpy array of folowing structure</p>
<pre><code>sb = np.genfromtxt(open('HomePage/TodayList.txt', 'rb'),
delimiter=',', skiprows=0,
dtype=[('DataBase', np.str_, 16), ('Mode', np.str_, 16),
('SMB', np.str_, 16),('Desc', np.str_, 128),
... | 1 | 2016-09-20T08:02:33Z | 39,588,978 | <p>You can find all rows matching your criteria by use of a column-wise comparison for <code>PercentCnt</code> and <code>ModelType</code> and connection using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.logical_and.html" rel="nofollow"><code>np.logical_and</code></a>. Doing that, you actually co... | 1 | 2016-09-20T08:18:29Z | [
"python",
"numpy"
] |
Numpy delete multiple rows matching criteria | 39,588,733 | <p>I have a numpy array of folowing structure</p>
<pre><code>sb = np.genfromtxt(open('HomePage/TodayList.txt', 'rb'),
delimiter=',', skiprows=0,
dtype=[('DataBase', np.str_, 16), ('Mode', np.str_, 16),
('SMB', np.str_, 16),('Desc', np.str_, 128),
... | 1 | 2016-09-20T08:02:33Z | 39,588,995 | <p>The condition</p>
<pre><code>sb['PercentCnt'] >= 50
</code></pre>
<p>is the condition for <em>keeping</em> things on this column, and the condition</p>
<pre><code>sb['ModelType'] >= 2
</code></pre>
<p>is the same for the other column.</p>
<p>You can combine these with <a href="http://docs.scipy.org/doc/nu... | 1 | 2016-09-20T08:19:24Z | [
"python",
"numpy"
] |
Display value in a button by linking two modals | 39,588,781 | <p>I have two modals each of it having different content. My first modal has a button which opens the second one. The second modal has Key Id's which should be displayed in the button of the first modal upon selection. I'm able to display the value in my second modal by just using label(Used this just to check if my se... | 1 | 2016-09-20T08:05:18Z | 39,589,391 | <p>In the template of second modal</p>
<pre><code><div class="well form-group" >
<table class="table">
<!-- bind event handler on row click and pass the item to handler function -->
<tr ng-repeat="item in items" ng-click="ok(item)">
<td ng-style="{ 'background... | 0 | 2016-09-20T08:39:51Z | [
"python",
"html",
"angularjs",
"django"
] |
Matplotlib and networkx merging Graphs when drawing | 39,588,977 | <p>I'm using <a href="https://networkx.readthedocs.io/en/stable/reference/drawing.html" rel="nofollow">Networkx</a> to visualise some graphs using the following code:</p>
<pre><code>import networkx as nx
import matplotlib.pyplot as plt
def drawgraph(g, filename):
#plt.figure() I had to comment this line because i... | 0 | 2016-09-20T08:18:20Z | 39,589,189 | <p>So after some looking around I found out the answer, I uncommented the <code>plt.figure()</code> line and added a <code>plt.close()</code> call at the end: </p>
<pre><code>import networkx as nx
import matplotlib.pyplot as plt
def drawgraph(g, filename):
plt.figure()
nx.draw(g)
plt.draw()
plt.savef... | 0 | 2016-09-20T08:30:04Z | [
"python",
"matplotlib",
"networkx"
] |
Matplotlib and networkx merging Graphs when drawing | 39,588,977 | <p>I'm using <a href="https://networkx.readthedocs.io/en/stable/reference/drawing.html" rel="nofollow">Networkx</a> to visualise some graphs using the following code:</p>
<pre><code>import networkx as nx
import matplotlib.pyplot as plt
def drawgraph(g, filename):
#plt.figure() I had to comment this line because i... | 0 | 2016-09-20T08:18:20Z | 39,599,384 | <p>Any time you plot something and then plot something again, with <code>matplotlib.pyplot</code>, both things will appear. You need to close or clear the figure.</p>
<p>Adding <code>plt.clf()</code> to clear the figure will solve the problem. I don't believe <code>plt.draw()</code> does anything for you.</p>
| 0 | 2016-09-20T16:30:06Z | [
"python",
"matplotlib",
"networkx"
] |
On bluemix message hub, how do I exchange messages between a rest and mqlight client? | 39,589,031 | <p>according to the documentation <a href="https://console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub" rel="nofollow">https://console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub</a> it should be possible to submit a message to MessageHub via REST and receive it via a MQLight client.... | 0 | 2016-09-20T08:21:09Z | 39,596,947 | <p>You're correct that the documentation here isn't particularly fleshed out. The only detail on this is in the small section <a href="https://new-console.ng.bluemix.net/docs/services/MessageHub/index.html#messagehub081" rel="nofollow">here</a> which is trying to explain that in order to inter-operate with an MQLight c... | 1 | 2016-09-20T14:35:21Z | [
"python",
"rest",
"ibm-bluemix",
"message-hub"
] |
How to close a blocking socket listening in a thread in while loop? | 39,589,070 | <p>I have a server and client which need to talk bidirectionally, but the problem is when client is waiting for server data, it can not be closed, I have called <code>socket.shutdown()</code> in client <code>closeEvent</code>, but the application doesn't quit, it just hangs there. What is the correct way of doing it? T... | 1 | 2016-09-20T08:22:47Z | 39,589,779 | <p>You should use <code>select</code> function before reading data from socket:</p>
<p>In the program top:</p>
<pre><code>import select
</code></pre>
<p>And the modified <code>listen</code> function:</p>
<pre><code>def listen(self):
while self.isVisible(self):
readable,_,_ = select.select([self.socket],... | 0 | 2016-09-20T08:58:39Z | [
"python",
"multithreading",
"sockets",
"pyqt",
"blocking"
] |
DataFrame value startswith | 39,589,126 | <p>I have the following dataframe in pandas:</p>
<pre><code> Datum Zeit Event
0 14.11.2016 13:00 Veröffentlichung des 9-Monats-Berichtes
1 14.03.2017 13:00 Telefonkonferenz für Analysten
2 14.03.2017 13:00 Telefonkonferenz für Analysten
3 2... | 1 | 2016-09-20T08:25:59Z | 39,589,207 | <p>By default a <code>Series</code> is returned when accessing a specific column and row in a <code>DataFrame</code> if you want a scalar value then you can access the array element using <code>.values</code> to return <code>np</code> array and then indexing into it:</p>
<pre><code>In [101]:
df.loc[df["Event"].str.sta... | 1 | 2016-09-20T08:30:35Z | [
"python",
"pandas",
"dataframe"
] |
DataFrame value startswith | 39,589,126 | <p>I have the following dataframe in pandas:</p>
<pre><code> Datum Zeit Event
0 14.11.2016 13:00 Veröffentlichung des 9-Monats-Berichtes
1 14.03.2017 13:00 Telefonkonferenz für Analysten
2 14.03.2017 13:00 Telefonkonferenz für Analysten
3 2... | 1 | 2016-09-20T08:25:59Z | 39,610,874 | <p>You are doing well. If you only want to have the date, you can do:</p>
<pre><code>df.loc[df["Event"].str.startswith("Bericht"), "Datum"].values
</code></pre>
<p>This returns a list of dates.</p>
| 0 | 2016-09-21T08:08:38Z | [
"python",
"pandas",
"dataframe"
] |
Django detecting not needed changes | 39,589,239 | <p>django 1.10, py 3.5</p>
<p>Here's my Enum-like class:</p>
<pre><code>@deconstructible
class EnumType(object):
@classmethod
def choices(cls):
attrs = [i for i in cls.__dict__.keys() if i[:1] != '_' and i.isupper()]
return tuple((cls.__dict__[attr], cls.__dict__[attr]) for attr in attrs)
... | 1 | 2016-09-20T08:32:03Z | 39,590,640 | <p>Dictionaries have an arbitrary order, so your tuple has an arbitrary order as well. Especially on Python 3.3+ the order is likely to change because it uses a <a href="http://stackoverflow.com/a/27522708/2615075">random hash seed</a>. As such, the order of the tuple is different as well, and tuples with the same item... | 2 | 2016-09-20T09:36:27Z | [
"python",
"django",
"enums",
"migration"
] |
wxPython + weakref proxy = closing wx.Frame does not yield None | 39,589,257 | <p>I'm currently making a Python application with wxWigets that has two windows. The first one is the main "controller" window, and the second one is intended to be a data display window.</p>
<p>I want to have some mechanism in place for the first window to know wherever the second window was already spawned, and if y... | 0 | 2016-09-20T08:33:04Z | 39,606,555 | <p>As you've seen, when a wx widget object has been destroyed the Python proxy object's class is swapped with one that changes it to raise an exception when you try to use it. It also has a <code>__nonzero__</code> method so you can do things like this instead of digging into the guts of the object to find it's class ... | 2 | 2016-09-21T02:26:09Z | [
"python",
"wxpython",
"weak-references"
] |
How to identify the occurrence of items in a list against another list | 39,589,347 | <p>I have a file with a column of text which I have loaded. I would like to check the occurrence of country names in the loaded text. I have loaded the Wikipedia countries CSV file and I am using the following code to count the number of occurrences of country names in the loaded text.</p>
<p>My code is not working.</... | -1 | 2016-09-20T08:37:24Z | 39,589,528 | <p>In your original code the line</p>
<pre><code>dic[country]= dic[country]+1
</code></pre>
<p>should raise a <code>KeyError</code>, because the key is not yet present in the dictionary, when a country is met for the first time. Instead you should check if the key is present, and if not, initialize the value to 1.</p... | 1 | 2016-09-20T08:45:57Z | [
"python",
"python-3.x"
] |
is there a loop in my logic-python | 39,589,421 | <p>I was solving the question from the website <a href="https://www.codechef.com/" rel="nofollow">CodeChef</a>.
I found this question:</p>
<blockquote>
<p>Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected,
but also the sample... | -4 | 2016-09-20T08:41:27Z | 39,590,296 | <p>For this kind of things, before doubting your code it's better to double-check that the way you handle input and output match what's expected.</p>
<p>I know how silly you feel when you realize you fail the tests despite a correct algorithm, for something like using the string <code>non-ambiguous</code> instead of t... | 0 | 2016-09-20T09:22:20Z | [
"python",
"algorithm"
] |
is there a loop in my logic-python | 39,589,421 | <p>I was solving the question from the website <a href="https://www.codechef.com/" rel="nofollow">CodeChef</a>.
I found this question:</p>
<blockquote>
<p>Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected,
but also the sample... | -4 | 2016-09-20T08:41:27Z | 39,592,153 | <pre><code>arr = [int(i) for i in raw_input().split()]
if arr[::] == arr[::-1]:
print 'ambiguous'
else:
print ' not ambiguous'
</code></pre>
<p><a href="https://code.hackerearth.com/e29c82h" rel="nofollow">https://code.hackerearth.com/e29c82h</a></p>
| 0 | 2016-09-20T10:50:09Z | [
"python",
"algorithm"
] |
how to customize html report file generated using py.test? | 39,589,426 | <p>I am trying to customize html report using pytest.
For example, if I've got a directory structure like:</p>
<pre><code>tests
temp1
test_temp1.py
conftest.py
</code></pre>
<p>A conftest.py file is also in the tests directory, and it should be common to all the sub-directories in the tests directory... | 0 | 2016-09-20T08:41:51Z | 39,609,952 | <p>Looks like you are using some plugin like pytest-html.
If that is the case check documentation for that plugin for what all hooks are provided.</p>
<p>for pytest-html following hooks are provided
You can add change the Environment section of the report by modifying <code>request.config._html.environment</code> fro... | 1 | 2016-09-21T07:23:08Z | [
"python",
"html",
"py.test"
] |
Assign Unique Values according Distinct Columns Values | 39,589,558 | <p>I know the question name is a little ambiguous.</p>
<p>My goal is to assign global key column based on 2 columns + unique value in my data frame.</p>
<p>For example</p>
<pre><code>CountryCode | Accident
AFG Car
AFG Bike
AFG Car
AFG Plane
USA Car
USA ... | 1 | 2016-09-20T08:47:09Z | 39,589,840 | <p>I don't have any experience of Pandas so this answer may not be what you are looking for. That being said, if the data you have is really that simple (few countries, few accident types) have you considered storing each country|accident combination in their own value?</p>
<p>So as you traverse your input, just incre... | 0 | 2016-09-20T09:00:54Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
Assign Unique Values according Distinct Columns Values | 39,589,558 | <p>I know the question name is a little ambiguous.</p>
<p>My goal is to assign global key column based on 2 columns + unique value in my data frame.</p>
<p>For example</p>
<pre><code>CountryCode | Accident
AFG Car
AFG Bike
AFG Car
AFG Plane
USA Car
USA ... | 1 | 2016-09-20T08:47:09Z | 39,589,991 | <p>You can try with <code>cumcount</code> to achieve this in a number of steps, like this:</p>
<pre><code>In [1]: df = pd.DataFrame({'Country':['AFG','AFG','AFG','AFG','USA','USA','UK'], 'Accident':['Car','Bike','Car','Plane','Car','Bike','Car']})
In [2]: df
Out[2]:
Accident Country
0 Car AFG
1 Bike ... | 5 | 2016-09-20T09:08:30Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
Assign Unique Values according Distinct Columns Values | 39,589,558 | <p>I know the question name is a little ambiguous.</p>
<p>My goal is to assign global key column based on 2 columns + unique value in my data frame.</p>
<p>For example</p>
<pre><code>CountryCode | Accident
AFG Car
AFG Bike
AFG Car
AFG Plane
USA Car
USA ... | 1 | 2016-09-20T08:47:09Z | 39,590,029 | <p>After you create your <code>subKey</code> we can sort the dataframe and count the occurences of the couples. First let's reset the index (to store the original order)</p>
<pre><code>df = df.reset_index()
</code></pre>
<p>then sort by the <code>subKey</code> and count</p>
<pre><code>df = df.sort_values(by='subKey'... | 1 | 2016-09-20T09:10:41Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
Assign Unique Values according Distinct Columns Values | 39,589,558 | <p>I know the question name is a little ambiguous.</p>
<p>My goal is to assign global key column based on 2 columns + unique value in my data frame.</p>
<p>For example</p>
<pre><code>CountryCode | Accident
AFG Car
AFG Bike
AFG Car
AFG Plane
USA Car
USA ... | 1 | 2016-09-20T08:47:09Z | 39,591,082 | <p>First of all, don't use for loops if you can help it. For example, you can do your Accident to code mapping with:</p>
<pre><code>df['AccidentCode'] = df['Accident'].map({'Car': '01', 'Bike': '02', 'Plane': '03'})
</code></pre>
<p>To get the unique code, <a href="http://stackoverflow.com/a/39589991/12663">Thanos ha... | 1 | 2016-09-20T09:58:16Z | [
"python",
"pandas",
"dataframe",
"group-by"
] |
File 'tesseract.log' is Missing (Python 2.7, Windows) | 39,589,601 | <p>I'm trying to write an OCR script with Python (2.7, Windows OS) to get text from images. First I've downloaded <a href="https://pypi.python.org/pypi/PyTesser/" rel="nofollow">PyTesser</a> and extracted it to Python27/Lib/site-packages as 'pytesser' and I've installed tesseract with <code>pip install tesseract</code>... | 0 | 2016-09-20T08:49:30Z | 39,592,212 | <p>I've changed the line from <code>def check_for_errors(logfile = "tesseract.log"):</code> to <code>def check_for_errors(logfile = "C:/Python27/Lib/site-packages/pytesser/tesseract.log"):</code> in <strong>../pytesser/errors.py</strong> and it worked.</p>
| 0 | 2016-09-20T10:53:50Z | [
"python",
"ocr",
"tesseract"
] |
Element is no longer attached to the DOM | 39,589,704 | <p>I am writing a test, where i create an ip pool for the application , and then in the next step, delete it.</p>
<p>The function is as follows:</p>
<pre><code>def remove_passed_ip(self, ip):
""" Find and ip and delete it
Args:
ip (str): the name of ip to click and delete
Returns:
... | 0 | 2016-09-20T08:54:15Z | 39,590,139 | <p>This is because after the delete the DOM changes and all 'references' that Selenium has with the browser are lost. </p>
<p>To solve this, you need to get the element/s again from the page after the previous one is deleted (or any other action that determines the DOM to be changed).</p>
| 1 | 2016-09-20T09:15:51Z | [
"python",
"selenium-webdriver"
] |
Flask response should display mongodb last-modified date in ISO format | 39,589,746 | <p>I'm using flask to create API. My database is mongodb.</p>
<p>When flask response come, the last modified date is coming in the following format.</p>
<pre><code>"lastModified": {"$date": 1473929954742}
</code></pre>
<p>I'm using Pycharm as IDE on the Pycharm Run terminal is showing in the following format</p>
<p... | 0 | 2016-09-20T08:56:45Z | 39,590,072 | <p>If you want to convert the timestamp to a ISO formatted date, you can use <code>utcfromtimestamp</code>.</p>
<pre><code>import datetime as dt
timestamp = 1473929954742/1000
print dt.datetime.utcfromtimestamp(timestamp).isoformat()
# '2016-09-15T08:59:14'
</code></pre>
| 0 | 2016-09-20T09:12:54Z | [
"python",
"mongodb",
"python-2.7",
"flask"
] |
TensorFlow logs not showing up in Console and File | 39,589,808 | <p>this is probably just a stupid mistake on my end, but I can't seem to find it.</p>
<p>I would like to see the logs from TensorFlow on my console and in the log file, which works for all of my code but the TensorFlow part.</p>
<p>I have configured logging like this:</p>
<pre><code>from logging.config import dictCo... | 0 | 2016-09-20T08:59:44Z | 39,590,369 | <p>After reading <a href="https://fangpenlin.com/posts/2012/08/26/good-logging-practice-in-python/" rel="nofollow" title="Good logging practice in Python">Good logging practice in Python</a> I found my mistake. The call to <code>dictConfig</code> disables existing loggers by default - I had to add a another key to the ... | 1 | 2016-09-20T09:25:37Z | [
"python",
"python-3.x",
"logging",
"tensorflow"
] |
Python can not start Process with Process.start() on Windows. PySide signals | 39,589,818 | <p>method header:</p>
<pre><code>@engine.async
@guiLoop
def for_every_client(self):
</code></pre>
<p>connect PySide signal with method:</p>
<pre><code>self.ui.pushButton.clicked.connect(lambda: self.for_every_client(self))
</code></pre>
<p>stacktarce - <a href="http://pastebin.com/R1ZKcdPy" rel="nofollow">http://pa... | 0 | 2016-09-19T11:53:32Z | 39,589,819 | <pre><code>class Window
SignalProgressBar = QtCore.pyqtSignal()
def __init__(self):
self.SignalProgressBar.connect(lambda: self.for_every_client(self))
</code></pre>
<p>connect signal with method:</p>
<pre><code> w = Window()
w.SignalProgressBar.emit()
</code></pre>
| 0 | 2016-09-19T13:52:04Z | [
"python",
"windows",
"multiprocessing",
"pyside"
] |
Python/ Numpy How to use arctan or arctan2 on the interval 0, pi/2? | 39,589,834 | <p>Is it possible use the arctan or arctan2 numpy functions with the result always on the 1st quadrant (0,pi/2)?
Thanks</p>
| 0 | 2016-09-20T09:00:26Z | 39,590,108 | <p>if you want to calculate the minimum "deviation" angle (in the interval <code>[0,pi/2]</code>) between the <code>x</code>-axis and the segment connecting points (0, 0) and (x, y), you could use:</p>
<pre><code>phi = numpy.arctan2(y, x)
phi = min(abs(phi), math.pi - abs(phi))
</code></pre>
<p>or:</p>
<pre><code>ph... | 3 | 2016-09-20T09:14:36Z | [
"python",
"numpy",
"trigonometry"
] |
Python Selenium: How do I select a value from drop down menu | 39,590,028 | <p>I am writing a python selenium script. I wanted to select below class:</p>
<pre><code> <select style="position: absolute; left: 0px; top: 0px;" class="gwt-ListBox project-list">
<option value="10">Case Notes</option>
</code></pre>
<p>but got failed:</p>
<pre><code>elem = self.driver.find... | 0 | 2016-09-20T09:10:41Z | 39,591,835 | <p>Actually you missed a quote <code>'</code> after the <code>=</code>. The following will work:</p>
<pre><code>elem = self.driver.find_element_by_xpath("//contains[@class='gwt-ListBox.dashboard-listbox.project-list']")
</code></pre>
<p>Hope it worked</p>
| 0 | 2016-09-20T10:31:27Z | [
"python",
"selenium"
] |
Python Selenium: How do I select a value from drop down menu | 39,590,028 | <p>I am writing a python selenium script. I wanted to select below class:</p>
<pre><code> <select style="position: absolute; left: 0px; top: 0px;" class="gwt-ListBox project-list">
<option value="10">Case Notes</option>
</code></pre>
<p>but got failed:</p>
<pre><code>elem = self.driver.find... | 0 | 2016-09-20T09:10:41Z | 39,597,382 | <p>Try this Xpath</p>
<pre><code>"//select[@class='gwt-ListBox project-list']"
</code></pre>
| 0 | 2016-09-20T14:55:21Z | [
"python",
"selenium"
] |
How to send email without mail template odoo 9 | 39,590,054 | <p>I want to send email without any email template in odoo 9. I've set successfully outgoing & incoming mail configuration.
My Scenario is the the admin mail alias as sender of email
this is my model:</p>
<pre><code>class cashadvance(osv.osv):
_name = 'comben.cashadvance'
_order = 'create_date DESC'
_colum... | 0 | 2016-09-20T09:12:04Z | 39,590,866 | <p>You can send a mail directly using the <code>mail.thread</code> model, by using the following code, attached to a button.</p>
<pre><code>@api.multi
def send_mail(self):
user_id = self.user_target.id
body = self.message_target
mail_details = {'subject': "Message subject",
'body': body,
... | 1 | 2016-09-20T09:47:44Z | [
"python",
"postgresql",
"openerp"
] |
Python pandas dataframe sort_values does not work | 39,590,055 | <p>I have the following pandas data frame which I want to sort by 'test_type'</p>
<pre><code> test_type tps mtt mem cpu 90th
0 sso_1000 205.263559 4139.031090 24.175933 34.817701 4897.4766
1 sso_1500 201.127133 5740.741266 24.599400 34.634209 6864.9820
2 sso_2000 203... | 0 | 2016-09-20T09:12:06Z | 39,590,240 | <p>Presumbaly, what you're trying to do is sort by the numerical value after <code>sso_</code>. You can do this as follows:</p>
<pre><code>import numpy as np
df.ix[np.argsort(df.test_type.str.split('_').str[-1].astype(int).values)
</code></pre>
<p>This </p>
<ol>
<li><p>splits the strings at <code>_</code></p></li>
... | 4 | 2016-09-20T09:20:16Z | [
"python",
"pandas"
] |
Python pandas dataframe sort_values does not work | 39,590,055 | <p>I have the following pandas data frame which I want to sort by 'test_type'</p>
<pre><code> test_type tps mtt mem cpu 90th
0 sso_1000 205.263559 4139.031090 24.175933 34.817701 4897.4766
1 sso_1500 201.127133 5740.741266 24.599400 34.634209 6864.9820
2 sso_2000 203... | 0 | 2016-09-20T09:12:06Z | 39,590,660 | <p>Alternatively, you could also extract the numbers from <code>test_type</code> and sort them. Followed by reindexing <code>DF</code> according to those indices.</p>
<pre><code>df.reindex(df['test_type'].str.extract('(\d+)', expand=False) \
.astype(int).sort_values().index).reset_index(dr... | 1 | 2016-09-20T09:37:24Z | [
"python",
"pandas"
] |
Print comma separated items without newline | 39,590,098 | <p>I thought I was copying word for word from a <a href="http://stackoverflow.com/questions/493386/how-to-print-in-python-without-newline-or-space">previous question/answer</a>, but, I don't get what I wanted. </p>
<p>I was trying to answer a question from an online list of python questions for beginners. I wrote the ... | 0 | 2016-09-20T09:14:14Z | 39,590,190 | <p><code>sep</code> is used to separate values <em>if multiple values are actually provided</em>; you provide <em>one value</em> for every loop so the separator isn't used. </p>
<p>Instead of using <code>sep=','</code>, use <code>end=','</code> to get the desired effect:</p>
<pre><code>for x in vals:
D=int(x)
... | 2 | 2016-09-20T09:18:14Z | [
"python",
"python-3.x",
"printing"
] |
openpyxl overwrites all data instead of update the excel sheet | 39,590,102 | <p>I'm trying to read a string from a text file and write it into an excel sheet without overwriting. I found somewhere that to update excel sheets, openpyxl in used. But my script just overwrites the entire sheet. I want other data to be the same.</p>
<p>python script:</p>
<pre><code>from openpyxl import Workbook ... | 0 | 2016-09-20T09:14:20Z | 39,594,464 | <p>Overwriting is due to both saving the file with <code>wb.save()</code> and your hard coded starting row number <code>r = 2</code>.<br />
1) If you don't care of overwriting the rows each time you execute your script you could use something like this:</p>
<pre><code>from openpyxl import Workbook
from openpyxl import... | 1 | 2016-09-20T12:44:15Z | [
"python",
"excel",
"openpyxl"
] |
Determining EC2 instance public IP from SNS in lambda | 39,590,123 | <p>I have a lambda function which SSH ec2 instance and run some commands. This lambda function is triggered from SNS topic. SNS topic is integrated with a cloudwatch alarm. I am using python 2.7 in lambda function followed this thread <a href="https://aws.amazon.com/blogs/compute/scheduling-ssh-jobs-using-aws-lambda/" ... | 0 | 2016-09-20T09:15:11Z | 39,687,531 | <p>It depends on the CloudWatch Alarm you are using to trigger the SNS publish.
My suggestion is to print out the entire <strong>event</strong> dictionary in your function and check if there is any mention about EC2 instance ID.</p>
<p>In case of CloudWatch EC2 alarm (eg. CPU usage) you'll find the instance ID in the ... | 0 | 2016-09-25T13:47:26Z | [
"python",
"amazon-ec2",
"aws-lambda",
"amazon-sns",
"amazon-cloudwatch"
] |
TypeError: can't multiply sequence by non-int of type 'float' even after using np.multiply | 39,590,152 | <p>I have the following which works along the rows of a dataframe. I have
tried many things, like <code>np.multiply</code> or <code>np.array</code> to make that
multiplication works but so far to no avail. I have also converted
factor to an <code>int</code> by multiplying and then dividing it by 10, but
nothing either.... | 0 | 2016-09-20T09:16:14Z | 39,600,691 | <p>It seems that
<code>convert_objects(convert_numeric=True)</code> has done the trick!<br>
It attempts to infer better dtype for object columns
see: <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.convert_objects.html" rel="nofollo... | 0 | 2016-09-20T17:53:01Z | [
"python",
"arrays",
"pandas",
"numpy",
"casting"
] |
In requirements.txt, what does tilde equals (~=) mean? | 39,590,187 | <p>In the <code>requirements.txt</code> for a Python library I am using, one of the requirements is specified like:</p>
<pre><code>mock-django~=0.6.10
</code></pre>
<p>What does <code>~=</code> mean?</p>
| 4 | 2016-09-20T09:18:05Z | 39,590,286 | <p>It means it will select the lastest version of the package, greater or equal to 0.6.10, but still in the 0.6.* version, so it won't download the 0.7.0 for example. It ensures you will get security fixes but keep backward-compatibility, if the package maintener respects the semantic versionning (which state that brea... | 5 | 2016-09-20T09:21:53Z | [
"python",
"requirements.txt"
] |
In requirements.txt, what does tilde equals (~=) mean? | 39,590,187 | <p>In the <code>requirements.txt</code> for a Python library I am using, one of the requirements is specified like:</p>
<pre><code>mock-django~=0.6.10
</code></pre>
<p>What does <code>~=</code> mean?</p>
| 4 | 2016-09-20T09:18:05Z | 39,590,317 | <blockquote>
<p>A compatible release clause consists of the compatible release operator ~= and a version identifier. It matches any candidate version that is expected to be compatible with the specified version.</p>
</blockquote>
<p>You can read more here: <a href="https://www.python.org/dev/peps/pep-0440/#compatibl... | 1 | 2016-09-20T09:23:10Z | [
"python",
"requirements.txt"
] |
In requirements.txt, what does tilde equals (~=) mean? | 39,590,187 | <p>In the <code>requirements.txt</code> for a Python library I am using, one of the requirements is specified like:</p>
<pre><code>mock-django~=0.6.10
</code></pre>
<p>What does <code>~=</code> mean?</p>
| 4 | 2016-09-20T09:18:05Z | 39,590,393 | <p>That's the 'compatible release' <a href="https://www.python.org/dev/peps/pep-0440/#version-specifiers" rel="nofollow">version specifier</a>.</p>
<p>It's equivalent to: <code>mock-django >= 0.6.10, == 0.6.*</code>, and is a tidy way of matching a version which is expected to be compatible. In plain English, it's ... | 2 | 2016-09-20T09:26:57Z | [
"python",
"requirements.txt"
] |
In requirements.txt, what does tilde equals (~=) mean? | 39,590,187 | <p>In the <code>requirements.txt</code> for a Python library I am using, one of the requirements is specified like:</p>
<pre><code>mock-django~=0.6.10
</code></pre>
<p>What does <code>~=</code> mean?</p>
| 4 | 2016-09-20T09:18:05Z | 39,590,412 | <p>~= means a compatible version. Not less than 0.6.10 and higher (0.6.*).</p>
| 1 | 2016-09-20T09:27:48Z | [
"python",
"requirements.txt"
] |
AWS Lambda function using test trigger or schedule (Timeout) | 39,590,227 | <p>So I have created a lambda function (the purpose of which doesn't matter anymore) and have tested that it works when run from my laptop. However the bigger problem is that I cannot get it to run off of a test event or on a schedule in AWS. </p>
<p>When I try to run it from AWS I get a 300s timeout error. </p>
<p>... | 0 | 2016-09-20T09:19:52Z | 39,605,751 | <p>You enabled VPC access for your Lambda function. So now it only has access to resources inside your VPC. Note that the AWS API exists outside your VPC. Any attempt to access something outside your VPC is going to result in a network timeout. That's why you are seeing the timeout issues.</p>
<p>To fix this, you can ... | 2 | 2016-09-21T00:34:43Z | [
"python",
"amazon-web-services",
"aws-lambda",
"boto3"
] |
multiple text replacements in string by markers | 39,590,326 | <p>I have an xml file that is used as a template.
I have multiple markers inside this xml that will be replaced with actual data. This is what i did:<br/></p>
<pre><code>def populate_template(self, value1, value2, value3):
with open('my_template.xml', 'rb') as xml_template:
template_string = xml_te... | 0 | 2016-09-20T09:23:32Z | 39,590,551 | <p>Yes. Use the <code>jinja2</code> templating module. To use your existing template you could do something like this:</p>
<pre><code>def populate_template(self, value1, value2, value3):
from jinja2 import Template
t = Template(open('my_template.xml', 'r').read())
output = t.render(MARKER_1=value2, MARKER_... | 1 | 2016-09-20T09:33:11Z | [
"python",
"xml",
"string",
"python-2.7",
"replace"
] |
Why do Python lists in my computer don't hold more than 693 numbers? | 39,590,384 | <p>I was solving the <a href="https://www.hackerrank.com/challenges/s10-basic-statistics" rel="nofollow">Day 0</a> of 10 Days of Statistics problems in HackerRank the other day. My solution was pretty straightforward and it worked with almost all the test cases. The one my code fails in has 2500 numbers as input. I pla... | -1 | 2016-09-20T09:26:22Z | 39,591,914 | <p>I don't know why you are experiencing this limitation when running your code on your local machine, however, I strongly suspect that it is due to your input data - perhaps a stray new line character as suggested by <a href="http://stackoverflow.com/questions/39590384/why-do-python-lists-in-my-computer-dont-hold-more... | 1 | 2016-09-20T10:35:54Z | [
"python",
"list",
"python-3.x",
"ubuntu"
] |
What am I doing wrong when using seasonal decompose in Python? | 39,590,648 | <p>I have a small time series with monthly intervals. I wanted to plot it and then decompose into seasonality, trend, residuals. I start by importing csv into pandas and than plotting just the time series which works fine. I follow <a href="http://www.cbcity.de/timeseries-decomposition-in-python-with-statsmodels-and-pa... | 1 | 2016-09-20T09:36:59Z | 39,591,005 | <p>You have 7 data points, that is usually a very small number for performing stationarity analysis.</p>
<p>You don't have enough points to use seasonal decomposition. To see this, you can concatenate your data to create an extended time series (just repeating your data for the following months). Let <code>extendedDat... | 1 | 2016-09-20T09:54:14Z | [
"python",
"pandas",
"jupyter"
] |
expected_conditions with Selenium in Python | 39,590,654 | <p>I want to load my driver until the text of an element become numbers:</p>
<p>here is the element:</p>
<pre><code><span id="viewed">-<span> or <span id="viewed"><span>
</code></pre>
<p>it will become :</p>
<pre><code><span id="viewed">12345<span>
</code></pre>
<p>any solution?... | 0 | 2016-09-20T09:37:17Z | 39,607,088 | <p>This is untested:</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
ints = "012345679"
def custom_ec(driver):
''' Custom expected condition function to feed wait.until
'''
elem_text = d... | 1 | 2016-09-21T03:33:05Z | [
"python",
"selenium"
] |
Import only first line of multiple csv, dummycode repeats and calculate conditional probability | 39,590,712 | <p>I am actually a R savvy person but for this task I am using python and am overwhelmed by little things. I really hope you guys may help me.</p>
<p>I have three large csv files that contain ids in the first column. Each csv contains presence data of a day and each unique id stands for a person. csv1 is day 1, csv2 i... | 0 | 2016-09-20T09:39:49Z | 39,592,989 | <p>You can simply open your <code>csv</code> files and store all the first columns (ids) in a list:</p>
<pre><code>with open(csv1_name) as f1, open(csv2_name) as f2,open(csv3_name) as f3:
column1 = next(zip(*csv.reader(f1))) # in python 2 use zip(*csv.reader(f1))[0]
column2 = next(zip(*csv.reader(f2)))
col... | 0 | 2016-09-20T11:34:45Z | [
"python",
"csv",
"statistics"
] |
fatal error: 'QTKit/QTKit.h' file not found when I build OpenCV on mac | 39,590,741 | <p>I have followed this <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/</a> to install OpenCV on my mac.
When I do this step :
$ make -j4
a problem happened:</p>
<pre><code>f... | 3 | 2016-09-20T09:41:33Z | 39,674,434 | <p>Try building it like this instead:</p>
<pre><code>cmake -DWITH_QUICKTIME=OFF -DWITH_GSTREAMER=OFF -DWITH_FFMPEG=OFF -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DCMAKE_BUILD_TYPE=Release .. ; make -j4
</code></pre>
| 2 | 2016-09-24T08:52:03Z | [
"python",
"osx",
"opencv"
] |
fatal error: 'QTKit/QTKit.h' file not found when I build OpenCV on mac | 39,590,741 | <p>I have followed this <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/</a> to install OpenCV on my mac.
When I do this step :
$ make -j4
a problem happened:</p>
<pre><code>f... | 3 | 2016-09-20T09:41:33Z | 39,802,235 | <p>Can you try to install opencv on mac using brew?</p>
<pre><code>brew reinstall opencv3 --HEAD --with-python3 --with-ffmpeg --with-tbb --with-contrib
</code></pre>
<p>Worked for me on MAC OS SIERRA.</p>
| 0 | 2016-10-01T01:47:21Z | [
"python",
"osx",
"opencv"
] |
fatal error: 'QTKit/QTKit.h' file not found when I build OpenCV on mac | 39,590,741 | <p>I have followed this <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/</a> to install OpenCV on my mac.
When I do this step :
$ make -j4
a problem happened:</p>
<pre><code>f... | 3 | 2016-09-20T09:41:33Z | 39,837,081 | <p>I have the same error and none of the solutions proposed worked for me.</p>
| 0 | 2016-10-03T17:24:19Z | [
"python",
"osx",
"opencv"
] |
Odoo 9 Empty Tree View | 39,590,816 | <p>I have created a new model and added a tree view to edit/view it on the res.partner view.</p>
<p>I can create entries no problem and they appear in the database. I cannot however get the tree view to display any data at all. Even with the filters removed.</p>
<p>Here is the view xml</p>
<pre><code><page string... | 1 | 2016-09-20T09:45:26Z | 39,592,380 | <p>When we define <em>one2many</em> field, we need to give proper <em>many2one</em> field name.</p>
<p>In your case, you have given <em>id</em> which means it will take currently record not for as you have created new object <em>training.log</em></p>
<p>Try with following code:</p>
<p>Replace</p>
<pre><code>'traini... | 1 | 2016-09-20T11:02:49Z | [
"python",
"xml",
"openerp",
"odoo-9"
] |
mod_wsgi runtime using old python version | 39,590,818 | <p>I'm running a django server on httpd service.
I had to upgrade my python version(2.7.12).
After installing the new python I rebuild the mod_wsgi with the new python (using with-python argument).
I also rebuild the mod_python with the new python version.
My new python path is /usr/local/bin/python2.7.
In the /etc/htt... | 0 | 2016-09-20T09:45:28Z | 39,592,334 | <p>When you install a Python version of the same X.Y version as system Python, but different patch level, you need to force the runtime linker to use the shared Python library from the alternate location of your newer Python version.</p>
<p>To do this, go back and rebuild mod_wsgi but set the <code>LD_RUN_PATH</code> ... | 0 | 2016-09-20T11:00:06Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
Plot RGB satellite image in Cassini-Soldner projection on a map in Python | 39,590,887 | <p>I have a geo-referenced RGB satellite image from the MODIS instrument in geotiff format. <strong>What is the correct way to plot it on a map using cartopy and preserve the RGB colours?</strong></p>
<p>The main obstacle I guess is the projection of the image which is Cassini-Soldner:</p>
<pre><code>import numpy as ... | 0 | 2016-09-20T09:48:35Z | 39,612,777 | <p>(I would add this as a comment but I need 50 rep.)</p>
<p>Out of interest, how did you come by a Cassini projection MODIS RGB?</p>
<p>An alternative is to use a Cartopy pull request I've made, which allows for the time dimension to be used with GeoAxes.add_wmts(), so that you can pull MODIS RGB imagery tiles for y... | 0 | 2016-09-21T09:35:58Z | [
"python",
"matplotlib",
"gdal",
"imshow",
"cartopy"
] |
flycheck: undefined name 'xrange' | 39,590,902 | <p>I am running <code>emacs24</code> and I'm new to emacs. I have some code in Python 2.7 that I am checking with <code>flycheck</code>.
When I check the syntax, I get:</p>
<pre><code>error F821 undefined name 'xrange' (python-flake8)
</code></pre>
<p>I understand that <code>xrange</code> is not in Python3, but here ... | 0 | 2016-09-20T09:49:10Z | 39,591,842 | <p>Flycheck does not care about the difference between Python 2 and Python 3. It runs the first <code>flake8</code> executable it finds in <code>exec-path</code>, and in your case, that's apparently a flake8 installed for Python 3.</p>
<p>You need to install flake8 for Python 2 and point Flycheck to that executable, ... | 0 | 2016-09-20T10:31:44Z | [
"python",
"emacs",
"flake8",
"flycheck"
] |
flycheck: undefined name 'xrange' | 39,590,902 | <p>I am running <code>emacs24</code> and I'm new to emacs. I have some code in Python 2.7 that I am checking with <code>flycheck</code>.
When I check the syntax, I get:</p>
<pre><code>error F821 undefined name 'xrange' (python-flake8)
</code></pre>
<p>I understand that <code>xrange</code> is not in Python3, but here ... | 0 | 2016-09-20T09:49:10Z | 39,600,290 | <p>I were struggling with same problem, and can recommend use my solution for that: <a href="https://github.com/rmuslimov/flycheck-local-flake8" rel="nofollow">https://github.com/rmuslimov/flycheck-local-flake8</a>. It's trivial - and it will force <strong>flycheck</strong> use proper <strong>flake8</strong> executable... | 0 | 2016-09-20T17:26:51Z | [
"python",
"emacs",
"flake8",
"flycheck"
] |
Is there any performance reason to use ndim 1 or 2 vectors in numpy? | 39,590,942 | <p>This seems like a pretty basic question, but I didn't find anything related to it on stack. Apologies if I missed an existing question.</p>
<p>I've seen some mathematical/linear algebraic reasons why one might want to use numpy vectors "proper" (i.e. ndim 1), as opposed to row/column vectors (i.e. ndim 2).</p>
<p>... | 3 | 2016-09-20T09:50:48Z | 39,598,657 | <p>If you use numpy properly, then no - it is not a consideration.</p>
<p>If you look at the <a href="https://docs.scipy.org/doc/numpy/reference/internals.html" rel="nofollow">numpy internals documentation</a>, you can see that</p>
<blockquote>
<p>Numpy arrays consist of two major components, the raw array data (fr... | 2 | 2016-09-20T15:52:30Z | [
"python",
"numpy",
"vector"
] |
Formatting datetime for plotting time-series with pandas | 39,590,948 | <p>I am plotting some time-series with pandas dataframe and I ran into the problem of gaps on weekends. What can I do to remove gaps in the time-series plot? </p>
<pre><code>date_concat = pd.to_datetime(pd.Series(df.index),infer_datetime_format=True)
pca_factors.index = date_concat
pca_colnames = ['Outright', 'Curve',... | 0 | 2016-09-20T09:50:53Z | 39,600,937 | <p>To make MaxU's suggestion more explicit:</p>
<ul>
<li>convert to datetime as you have done, but drop the weekends</li>
<li>reset the index and plot the data via this default Int64Index </li>
<li>change the x tick labels </li>
</ul>
<p>Code:</p>
<pre><code>date_concat = data_concat[date_concat.weekday < 5] # dr... | 0 | 2016-09-20T18:08:41Z | [
"python",
"pandas",
"matplotlib",
"dataframe"
] |
How to write general get methods for a class? | 39,591,045 | <p>recently I started using oop in python. I would like to write a general get or set method for the initiated attributes. For example, there is the class Song with several attributes and a corresponding get method. I would like to avoid the multiple if statements. With just two attributes it does not matter, but if th... | 1 | 2016-09-20T09:56:36Z | 39,591,542 | <blockquote>
<p>provide a function for colleagues who are not familiar with the python syntax, such that they do not have to access the the attritubes directly. For plotting and such things</p>
<p>because python is not necessarily taught and the dot syntax is confusing for people who have basic knowledge in matl... | 0 | 2016-09-20T10:18:37Z | [
"python",
"oop",
"methods",
"args"
] |
Apache Lucene: How to use TokenStream to manually accept or reject a token when indexing | 39,591,094 | <p>I am looking for a way to write a custom index with Apache Lucene (PyLucene to be precise, but a Java answer is fine).</p>
<p>What I would like to do is the following : When adding a document to the index, Lucene will tokenize it, remove stop words, etc. This is usually done with the <code>Analyzer</code> if I am n... | 2 | 2016-09-20T09:58:37Z | 39,612,844 | <p>The way I was trying to solve the problem was wrong. This <a href="http://stackoverflow.com/questions/24145688/how-to-tokenize-only-certain-words-in-lucene/24152554?noredirect=1#comment66511266_24152554">post</a> and <em>femtoRgon</em>'s answer were the solution.</p>
<p>By defining a filter extending <code>PythonFi... | 0 | 2016-09-21T09:38:45Z | [
"java",
"python",
"apache",
"indexing",
"lucene"
] |
What will happen if I delete a input file while some program is reading data from that file? | 39,591,109 | <p>If there is a python script doing this :</p>
<pre><code>with open('large_input_file.log', 'rb') as f :
for each_line in f :
do something .....
</code></pre>
<p>Let's call this script <code>a.py</code></p>
<p><code>large_input_file.log</code> is about 16GB. <code>a.py</code> will take hours to process ... | 2 | 2016-09-20T09:59:14Z | 39,591,698 | <p>While a file is still open there is on the disk, and your python program will read the whole file, because it uses the inode number not the name. The new file has the same name but a new inode.
That's why when you delete a logfile from /var/log and df shows the same before the delete. While open, the file is phisica... | 1 | 2016-09-20T10:25:12Z | [
"python",
"linux"
] |
What will happen if I delete a input file while some program is reading data from that file? | 39,591,109 | <p>If there is a python script doing this :</p>
<pre><code>with open('large_input_file.log', 'rb') as f :
for each_line in f :
do something .....
</code></pre>
<p>Let's call this script <code>a.py</code></p>
<p><code>large_input_file.log</code> is about 16GB. <code>a.py</code> will take hours to process ... | 2 | 2016-09-20T09:59:14Z | 39,591,920 | <p>Let's create a file:</p>
<pre><code># echo foo > test.txt
</code></pre>
<p>Now we'll use <code>tail</code> to monitor it for changes:</p>
<pre><code># tail -f test.txt
foo
</code></pre>
<p>Let's open another tab on our terminal, and check the pid of our <code>tail</code> process:</p>
<pre><code># ps aux | gr... | 5 | 2016-09-20T10:36:18Z | [
"python",
"linux"
] |
Binary search for a string in a list of strings | 39,591,238 | <p>I have a list of permutations of a string, and a list full of words from a lexicon. I want to for each permutation find out if it's in the list of words. I tried a while loop and just brute-forced through and that gave me a bunch of words from the wordlist. But when I tried this binary search:</p>
<pre><code>def bi... | -2 | 2016-09-20T10:04:59Z | 39,591,430 | <p>It was working fine for me. The following was my code:</p>
<pre><code>def binrSkning(word, wordList):
first = 0
last = len(wordList) - 1
found = False
while first <= last and not found:
middle = (first + last)//2
if wordList[middle] == word:
found = True
else:
... | 0 | 2016-09-20T10:14:01Z | [
"python",
"python-3.x",
"binary-search"
] |
Binary search for a string in a list of strings | 39,591,238 | <p>I have a list of permutations of a string, and a list full of words from a lexicon. I want to for each permutation find out if it's in the list of words. I tried a while loop and just brute-forced through and that gave me a bunch of words from the wordlist. But when I tried this binary search:</p>
<pre><code>def bi... | -2 | 2016-09-20T10:04:59Z | 39,591,527 | <p>If you have a list of words, it is as simple as making a single if statement as follows: </p>
<pre><code>def bomrSkning(word, wordList):
found = False
if word in wordList:
found = True
return found
</code></pre>
| 0 | 2016-09-20T10:18:03Z | [
"python",
"python-3.x",
"binary-search"
] |
Finding efficiently pandas (part of) rows with unique values | 39,591,334 | <p>Given a pandas dataframe with a row per individual/record. A row includes a property value and its evolution across time (0 to N). </p>
<p>A schedule includes the estimated values of a variable 'property' for a number of entities from day 1 to day 10 in the following example. </p>
<p>I want to filter entities with... | 1 | 2016-09-20T10:09:29Z | 39,591,809 | <p>Given your df</p>
<pre><code> 7 8 9
0 3 3 3
1 2 8 8
2 2 2 2
3 0 0 0
4 2 2 2
10 3 3 4
</code></pre>
<p>You can simplify your code to:</p>
<pre><code>df_f = df[df.apply(pd.Series.nunique, axis=1) == 1]
print(df_f)
7 8 9
0 3 3 3
2 2 2 2
3 0 0 0
4 2 2 2
</code></pre>
<p>... | 0 | 2016-09-20T10:30:06Z | [
"python",
"performance",
"pandas"
] |
Dictionary multiprocessing | 39,591,335 | <p>I want to parallelize the processing of a dictionary using the multiprocessing library.</p>
<p>My problem can be reduced to this code:</p>
<pre><code>from multiprocessing import Manager,Pool
def modify_dictionary(dictionary):
if((3,3) not in dictionary):
dictionary[(3,3)]=0.
for i in range(100):
... | 2 | 2016-09-20T10:09:29Z | 39,595,657 | <p>The problem is with this line:</p>
<pre><code>dictionary[(3,3)] = dictionary[(3,3)]+1
</code></pre>
<p>Three things happen on that line:</p>
<ul>
<li>Read the value of the dictionary key (3,3)</li>
<li>Increment the value by 1</li>
<li>Write the value back again</li>
</ul>
<p>But the increment part is happening ... | 0 | 2016-09-20T13:36:54Z | [
"python",
"dictionary",
"python-multiprocessing"
] |
Reading text file read line by line not working | 39,591,364 | <p>I know there are too many questions were asked in this topic but still I'm not able to find the reason for my failure to read a text file line by line in Python.</p>
<p>I'm using Python 3.4.3 and I want to read a text file line by line.</p>
<pre><code>with open('D:\filename.txt') as fp:
for line in fp:
... | 0 | 2016-09-20T10:10:47Z | 39,591,683 | <p>The back slash (D:<strong>\f</strong>ilename.txt) in the filename escapes <code>f</code> char.
That's why open could not find the file.
To handle situation you can do the followings:</p>
<p>You need to escape <code>\</code> char in the path:</p>
<pre><code>with open('D:\\filename.txt') as fp:
for line in fp:
... | 1 | 2016-09-20T10:24:21Z | [
"python",
"python-3.x"
] |
Should I notify while holding the lock on a condition or after releasing it? | 39,591,390 | <p>The <a href="https://docs.python.org/3/library/threading.html" rel="nofollow">Python <code>threading</code> documentation</a> lists the following example of a producer:</p>
<pre><code>from threading import Condition
cv = Condition()
# Produce one item
with cv:
make_an_item_available()
cv.notify()
</code></... | 0 | 2016-09-20T10:12:03Z | 39,591,529 | <p>Don't read C++ documentation to understand Python APIs. Per <a href="https://docs.python.org/3/library/threading.html#threading.Condition.notify" rel="nofollow">the actual Python docs</a>:</p>
<blockquote>
<p>If the calling thread has not acquired the lock when this method is called, a <code>RuntimeError</code> i... | 2 | 2016-09-20T10:18:14Z | [
"python",
"multithreading",
"python-multithreading"
] |
Retrieve Network Logs using Python | 39,591,396 | <p>Generally, whenever a page is loaded, it sends several requests, which can be recorded in the <strong>Network</strong> tab in chrome developer tools. </p>
<p>My prime motive is to log all the network requests whenever page is loaded using python script. A sample screen-shot is attached, to illustrate what all reque... | 0 | 2016-09-20T10:12:24Z | 39,591,622 | <p>You can't do this with the <code>urllib</code> family of libraries. To capture AJAX Requests you need to use something that has Javascript support... like a browser.</p>
<p>So your best option in this case is to use <a href="http://docs.seleniumhq.org/" rel="nofollow">Selenium</a> to write a script that uses the <a... | 0 | 2016-09-20T10:21:57Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.