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
fabfile doesn't see remote environment variables
39,979,229
<p>My remote server (192.168.3.68) contains several environment variables set in my ~/.bashrc:</p> <pre><code># For instance export MY_DATABASE_HOST=127.0.0.1 </code></pre> <p>When I put <code>run('echo $MY_DATABASE_HOST')</code> in <code>fabfile.py</code>, it shows:</p> <pre><code>[192.168.3.68] run: echo $MY_DATAB...
2
2016-10-11T14:10:40Z
39,994,484
<p>Actually bashrc is executed. But it gets stopped because it's not running interactively through this:</p> <pre><code>case $- in *i*) ;; *) return;; esac </code></pre> <p>Now it works after I moved my environment variables at the top of my bashrc.</p> <p>More detailed answer here <a href="https://github....
0
2016-10-12T08:57:26Z
[ "python", "fabric" ]
Solving a system of equation with Sympy, python2.7
39,979,293
<p>I want to solve a system of equations. But I want to be able to precise the value to "get", and as a function of "what".</p> <p>To better understand, I take an exemple from <a href="http://stackoverflow.com/questions/22156709/solving-system-of-nonlinear-equations-with-python#_=_">here</a>, wich I modfified:</p> <p...
3
2016-10-11T14:13:37Z
39,979,664
<p>Your code is giving following error: </p> <blockquote> <p>Traceback (most recent call last): File "C:\temp\equation1.py", line 37, in f3 = x * y - beta * w NameError: name 'w' is not defined</p> </blockquote> <p>Hence we pull symbol 'w' from sympy symbols as below <code>x, y, z, w = sp.symbols('x, y, z, ...
0
2016-10-11T14:30:25Z
[ "python", "python-2.7", "sympy", "equation", "equation-solving" ]
Python: store a value in a variable so that you can recognize each reoccurence
39,979,358
<p>If this question is unclear, I am very open to constructive criticism. </p> <p>I have an excel table with about 50 rows of data, with the first column in each row being a date. I need to access all the data for only one date, and that date appears only about 1-5 times. It is the most recent date so I've already org...
3
2016-10-11T14:17:00Z
39,980,175
<p>This is a relatively simple filtering operation. You state that you want to "take only the columns" that are the latest date, so I assume that an acceptable result will be a filter <code>DataFrame</code> with just the correct columns. </p> <p>Here's a simple CSV that is similar to your structure:</p> <pre><code>DA...
1
2016-10-11T14:53:00Z
[ "python", "date", "pandas" ]
pytest "No module named" error
39,979,369
<p>I'm new to python and trying to write a test for my first app. simple app structure:</p> <pre><code>- app - tests __init__.py - test_main.py - __init__.py - main.py </code></pre> <p>The <code>main.py</code> contains <code>main_func</code></p> <p><strong>test_main.py:</strong></p...
0
2016-10-11T14:17:31Z
39,980,236
<p>I think it runs in pycharm because of folder configuration mark in pycharm project. If you set the app folder as "Source" in settings, pycharm can include in any path. </p> <p>For details; <a href="https://www.jetbrains.com/help/pycharm/2016.1/configuring-folders-within-a-content-root.html" rel="nofollow">https://w...
1
2016-10-11T14:56:04Z
[ "python", "pycharm", "py.test" ]
Pandas adding method does not survive serialization
39,979,397
<p>I am trying to add a method to pandas so that I can use it readily if I have access to the dataframe. However serialization "kills" the method such as shown by the following example</p> <pre><code>import dill class Foo: def sayhello(self): print("hello") f = Foo() dill.dump(f, open("./foo.pickle", "wb...
0
2016-10-11T14:18:49Z
39,980,241
<p>1) Do you see what is causing a problem ?</p> <p>You need to add the method to the class instead of the instance like</p> <pre><code>df = pd.DataFrame([0,1]) @addto(pd.DataFrame) def saygoodbye(self): print("goodbye") </code></pre> <p>2) Do you have any idea how to serialize an added method on a dataframe ?</...
1
2016-10-11T14:56:12Z
[ "python", "python-3.x", "pandas", "methods", "dill" ]
Python default parameter if no command line arguments are passed
39,979,618
<p>I'l like to build a program with this behaviour:</p> <p>usage: sage 4ct.py [-h] (-r R | -i I | -p P) [-o O]</p> <p>But if you don't give any parameter, I'd like to have "-r 100" as the default.</p> <p>Is it possible?</p> <pre><code>parser = argparse.ArgumentParser(description = '4ct args') group_input = parser....
2
2016-10-11T14:28:30Z
39,980,408
<p>Give the following a try:</p> <pre><code>import argparse import sys parser = argparse.ArgumentParser(description='4ct args') group_input = parser.add_mutually_exclusive_group(required=True) group_input.add_argument("-r", "-random", help="Random graph: dual of a triangulation of N vertices", nargs=1, type=int, ...
0
2016-10-11T15:03:20Z
[ "python", "argparse" ]
Python default parameter if no command line arguments are passed
39,979,618
<p>I'l like to build a program with this behaviour:</p> <p>usage: sage 4ct.py [-h] (-r R | -i I | -p P) [-o O]</p> <p>But if you don't give any parameter, I'd like to have "-r 100" as the default.</p> <p>Is it possible?</p> <pre><code>parser = argparse.ArgumentParser(description = '4ct args') group_input = parser....
2
2016-10-11T14:28:30Z
39,980,588
<p>Just remove the <code>required</code>argument of the <code>add_mutually_exclusive_group</code> function call (or set it to False) and you're done:</p> <pre><code>import argparse parser = argparse.ArgumentParser(description = '4ct args') group_input = parser.add_mutually_exclusive_group(required = False) group_inp...
4
2016-10-11T15:10:55Z
[ "python", "argparse" ]
Building a nested list with XPath-extracted XML document structure
39,979,724
<p>I am trying to get the text (using xpath) of all <code>&lt;h2&gt;</code> tags in:</p> <pre><code>&lt;div id="static_id"&gt; &lt;div&gt;... &lt;a ...&gt; &lt;div&gt;... &lt;h2&gt;Text 1&lt;/h2&gt; &lt;a ...&gt; &lt;div&gt;... &lt;div&gt;... &lt;span&gt;... &lt;h2&gt;Text 2&lt;/h2&gt; &lt;a ...&gt; &...
0
2016-10-11T14:32:50Z
39,979,999
<p>Easily made a one-liner:</p> <pre><code>list_all = [ static_id_div.xpath('.//h2/text()') for static_id_div in tree.xpath('//div[@id="static_id"]') ] </code></pre> <p>The important difference here is that the inner query is being run <em>against the elements returned by the outer query</em>, rather tha...
0
2016-10-11T14:45:25Z
[ "python", "xpath" ]
python pyquery import not working on Mac OS Sierra
39,979,830
<p>I'm trying to import pyquery as I did hundreds on time before, and it's not working. It looks like related to the Mac OS Sierra. (module installed with pip and up-to-date)</p> <pre><code>from pyquery import PyQuery as pq </code></pre> <p>And got an error on the namespacing</p> <pre><code>ImportError: cannot impor...
0
2016-10-11T14:37:41Z
40,004,038
<p>Finally found why. My file had the same name as my import... So the library import was overridden by the name of the .py file. </p>
0
2016-10-12T16:46:04Z
[ "python", "osx", "pyquery" ]
Pandas dataframe, each cell into list - more pythonic way?
39,979,889
<p>I have a pandas dataframe with columns and rows like this:</p> <pre><code> a b c d a 40 15 25 35 b 10 25 35 45 c 20 35 45 55 d 40 45 55 65 </code></pre> <p>For all numbers > 30 I need an output like this:</p> <pre><code>a, a, 40 a, d, 40 b, c, 35 b, d, 45 </code></pre> <p>and so o...
3
2016-10-11T14:40:46Z
39,979,928
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.stack.html" rel="nofollow"><code>stack</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p> <pre><code>df = df.stack().res...
3
2016-10-11T14:42:01Z
[ "python", "pandas" ]
Numpy vectorize sum over indices
39,979,916
<p>I have a list of indices (list(int)) and a list of summing indices (list(list(int)). Given a 2D numpy array, I need to find the sum over indices in the second list for each column and add them to the corresponding indices in the first column. Is there any way to vectorize this? Here is the normal code:</p> <pre><co...
1
2016-10-11T14:41:40Z
39,980,763
<p>Here's an almost* vectorized approach using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduceat.html" rel="nofollow"><code>np.add.reduceat</code></a> -</p> <pre><code>lens = np.array(map(len,summing_indices)) col = np.repeat(indices,lens) row = np.concatenate(summing_indices) vals = ma...
2
2016-10-11T15:18:40Z
[ "python", "numpy", "vectorization" ]
Why don't objects have hasattr and getattr as attributes?
39,980,030
<p>When you need to access an object's attributes dynamically in Python, you can just use the builtin functions <code>hasattr(object, attribute)</code> or <code>getattr(object, attribute)</code>.</p> <p>However this seems like an odd order for the syntax to take. It's less readable and intuitive as it messes up the re...
1
2016-10-11T14:46:50Z
39,982,252
<p>Its part of the language design. I guess your find some docs about the more complicated thoughts behind it, but the key points are like</p> <ul> <li>You suggest to use a function of an object for a builtin function on all objects. Why should this function be specific to this object?</li> <li>Semantics: the <code>ge...
1
2016-10-11T16:34:28Z
[ "python", "class" ]
Why don't objects have hasattr and getattr as attributes?
39,980,030
<p>When you need to access an object's attributes dynamically in Python, you can just use the builtin functions <code>hasattr(object, attribute)</code> or <code>getattr(object, attribute)</code>.</p> <p>However this seems like an odd order for the syntax to take. It's less readable and intuitive as it messes up the re...
1
2016-10-11T14:46:50Z
39,993,932
<p>You'll find quite a few similar examples - like <code>len(obj)</code> instead of <code>obj.length()</code>, <code>hash(obj)</code> instead of <code>obj.hash()</code>, <code>isinstance(obj, cls)</code> instead of <code>obj.isinstance(cls)</code>. You may also have noticed that addition is spelled <code>obj1 + obj2</c...
3
2016-10-12T08:29:14Z
[ "python", "class" ]
Function working iteratively over each row in an individual column of an array - numpy
39,980,081
<p>I'm looking to change all the values in an array using the following formula:</p> <pre><code>new_value = old_value * elec_space - elec_space </code></pre> <p>A complicating issue is that all values above 48 within the array will be increased by two, as 49 &amp; 50 will never exist in the original array (infile, sh...
1
2016-10-11T14:48:48Z
39,980,218
<p>One alternative approach could be to subtract <code>1</code> for elements that were greater than <code>48</code> from the result, like so -</p> <pre><code>(infile - 2*(infile&gt;48))* elec_space - elec_space </code></pre>
2
2016-10-11T14:55:05Z
[ "python", "arrays", "function", "numpy", "boolean-operations" ]
Accessing dynamic generated website content with Python requests
39,980,262
<p>I'm trying to gather data from few websites using Python (BeautifulSoup). However, sometimes it's difficult to access search results, example:</p> <pre><code>import requests from bs4 import BeautifulSoup url1 = 'https://auto.ria.com/legkovie/city/vinnica/?page=1' url2= 'https://auto.ria.com/search/?top=11&amp;cate...
-1
2016-10-11T14:56:57Z
39,981,573
<p>I recommend zooming out on the detail of the soup object to see what's there. You can try using findAll instead of find and printing results. You can also try stripping the final call to find (for the strong tag) and print the results. Once you investigate the larger object you'll likely see what is happening. It co...
0
2016-10-11T15:56:27Z
[ "python", "json", "web-scraping", "python-requests" ]
Accessing dynamic generated website content with Python requests
39,980,262
<p>I'm trying to gather data from few websites using Python (BeautifulSoup). However, sometimes it's difficult to access search results, example:</p> <pre><code>import requests from bs4 import BeautifulSoup url1 = 'https://auto.ria.com/legkovie/city/vinnica/?page=1' url2= 'https://auto.ria.com/search/?top=11&amp;cate...
-1
2016-10-11T14:56:57Z
39,982,738
<p>Your code is running fine, and url2 returns the expected result. By viewing page source from chrome:<br> <em><code>&lt;span id="resultsCount" class="hide"&gt;Найдено &lt;strong class="count"&gt;0&lt;/strong&gt; объявлений&lt;/span&gt;</code></em></p> <p>This is the tag that your are trying to find ...
0
2016-10-11T17:02:24Z
[ "python", "json", "web-scraping", "python-requests" ]
TypeError: unsupported operand type(s) for +: 'Cursor' and 'Cursor'
39,980,281
<p>I want to be able to store two collections in variable to be able to view and sort through them. However, I seem to be getting the error above. My code is in python and look like this:</p> <pre><code> from pymongo import MongoClient db = MongoClient('10.39.165.193', 27017)['mean-dev'] cursor1 = db.Build_Progr...
0
2016-10-11T14:57:44Z
39,980,637
<p>You need to <a href="https://docs.python.org/3.6/library/itertools.html#itertools.chain" rel="nofollow"><code>chain</code></a> the two cursors like this:</p> <pre><code>from itertools import chain for document in chain(cursor1, cursor2): print(document) </code></pre>
0
2016-10-11T15:13:08Z
[ "python", "mongodb", "pymongo" ]
How to replace elements by value in a list of lists in Python?
39,980,292
<p>I have:</p> <pre><code> counts = [[2, 2, 2, 0], [2, 2, 1, 0]] countsminusone = [[1, 1, 1, -1], [1, 1, 0, -1]] #Which is counts - 1 </code></pre> <p>For every value, where countsminusone is 0 or less than 0, I want to replace it with 1.</p> <pre><code> countsminusone1 = [[1 if x == 0 or x &lt; 0 else x for x in p...
-1
2016-10-11T14:58:04Z
39,980,506
<p>It works, except you forgot to replace <code>countsminusone</code> by <code>countsminusone1</code> in your last line.</p> <pre><code>countsminusone1 = [[1 if x &lt;= 0 else x for x in pair] for pair in countsminusone] Divide = [[n/d for n, d in zip(subq, subr)] for subq, subr in zip(counts, countsminusone1)] </code...
1
2016-10-11T15:07:13Z
[ "python", "list", "replace", "list-comprehension", "value" ]
How to replace elements by value in a list of lists in Python?
39,980,292
<p>I have:</p> <pre><code> counts = [[2, 2, 2, 0], [2, 2, 1, 0]] countsminusone = [[1, 1, 1, -1], [1, 1, 0, -1]] #Which is counts - 1 </code></pre> <p>For every value, where countsminusone is 0 or less than 0, I want to replace it with 1.</p> <pre><code> countsminusone1 = [[1 if x == 0 or x &lt; 0 else x for x in p...
-1
2016-10-11T14:58:04Z
39,980,581
<p>I think you are making this much too complicated. Let's state what you actually want to do in the simplest way:</p> <blockquote> <p>GOAL: Divide every number n in list of lists by n - 1 or, if n - 1 &lt;= 0, by 1.</p> </blockquote> <p>This can be done without creating extra lists and zipping:</p> <pre><code>cou...
2
2016-10-11T15:10:31Z
[ "python", "list", "replace", "list-comprehension", "value" ]
How to replace elements by value in a list of lists in Python?
39,980,292
<p>I have:</p> <pre><code> counts = [[2, 2, 2, 0], [2, 2, 1, 0]] countsminusone = [[1, 1, 1, -1], [1, 1, 0, -1]] #Which is counts - 1 </code></pre> <p>For every value, where countsminusone is 0 or less than 0, I want to replace it with 1.</p> <pre><code> countsminusone1 = [[1 if x == 0 or x &lt; 0 else x for x in p...
-1
2016-10-11T14:58:04Z
39,981,334
<p>This works for any number of elements inside the sub list</p> <pre><code>import numpy as np map( list , np.array(counts)/np.array(zip(*([ iter([ 1 if i &lt;=0 else i for i in sum( countsminusone , []) ]) ] * len(countsminusone[0]) ) ) ) ) </code></pre>
0
2016-10-11T15:44:42Z
[ "python", "list", "replace", "list-comprehension", "value" ]
Dictionaries are ordered in Python 3.6
39,980,323
<p>Dictionaries are ordered in Python 3.6, unlike in previous Python incarnations. This seems like a substantial change, but it's only a short paragraph in the <a href="https://docs.python.org/3.6/whatsnew/3.6.html#other-language-changes">documentation</a>. It is described as an implementation detail rather than a lang...
72
2016-10-11T14:59:23Z
39,980,548
<p>Below is answering the original first question:</p> <blockquote> <p>Should I use <code>dict</code> or <code>OrderedDict</code> in Python 3.6?</p> </blockquote> <p>I think this sentence from the documentation is actually enough to answer your question</p> <blockquote> <p>The order-preserving aspect of this new...
27
2016-10-11T15:09:00Z
[ "python", "python-3.x", "dictionary", "python-internals", "python-3.6" ]
Dictionaries are ordered in Python 3.6
39,980,323
<p>Dictionaries are ordered in Python 3.6, unlike in previous Python incarnations. This seems like a substantial change, but it's only a short paragraph in the <a href="https://docs.python.org/3.6/whatsnew/3.6.html#other-language-changes">documentation</a>. It is described as an implementation detail rather than a lang...
72
2016-10-11T14:59:23Z
39,980,744
<blockquote> <p>How does the Python 3.6 dictionary implementation perform better than the older one while preserving element order?</p> </blockquote> <p>Essentially by keeping two arrays, one holding the entries for the dictionary in the order that they were inserted and the other holding a list of indices.</p> <p>...
57
2016-10-11T15:17:53Z
[ "python", "python-3.x", "dictionary", "python-internals", "python-3.6" ]
Write magnetic tape end of record linux
39,980,359
<p>Task is create two record with different sizes within one file entry. I'm using python 3.4.5 for testing:</p> <pre><code>import fcntl import os import struct MTIOCTOP = 0x40086d01 # refer to mtio.h MTSETBLK = 20 fh = os.open('/dev/st2', os.O_WRONLY ) fcntl.ioctl(fh, MTIOCTOP, struct.pack('hi', MTSETBLK, 1024)) o...
0
2016-10-11T15:01:14Z
39,981,853
<p>Issue was with tcopy, it uses block size on device instead of detecting it.</p> <pre><code>fcntl.ioctl(fh, MTIOCTOP, struct.pack('hi', MTSETBLK, 0)) </code></pre> <p>after last write allowed tcopy to display data as intended.</p>
0
2016-10-11T16:11:43Z
[ "python", "linux", "ioctl", "fcntl", "mt" ]
2 column n rows array- operation on elements of two colums in each row
39,980,383
<p>I have an array of n rows and two columns (array). I have another variable (a) which I am using as reference.</p> <pre><code> for a between (1-10000) if column1 of ARRAY&lt;= a &lt;= column2 of the ARRAY save the tuple (a, YES) </code></pre> <p>This resultant tuple I will use for further operat...
-2
2016-10-11T15:02:30Z
39,984,475
<p>The <a href="http://docs.scipy.org/doc/numpy/reference/arrays.html" rel="nofollow">NumPy documentation</a> has all the information you may need.</p>
0
2016-10-11T18:44:15Z
[ "python", "arrays", "numpy" ]
Python: Flatten and Parse certain sections of JSON
39,980,664
<p>I have an input JSON that looks like this:</p> <pre><code>&gt; {"payment": {"payment_id": "AA340", "payment_amt": "20", "chk_nr": "321749", "clm_list": {"dtl": [{"clm_id": "1A2345", "name": "John", adj:{"adj_id":"W123","adj_cd":"45"}}, {"clm_id": "9999", "name": "Dilton", adj:{"adj_id":"X123","adj_cd":"5"}}]}}} </c...
0
2016-10-11T15:14:44Z
39,989,645
<p>It may be the neat way is to simply pick through the data, like;</p> <pre><code>new_dict = recursively_prune_dict_keys(old_dict, keep) payment = old_dict['payment'] claims = payment['clm_list']['dtl'] for claim in claims: claim['payment_amt'] = payment['payment_amt'] claim['chk_nr'] = payment['chk_nr'] prin...
0
2016-10-12T02:37:53Z
[ "python", "json", "parsing", "flatten" ]
multiple attributes being affected at once
39,980,712
<p>When I change the <code>stats.hp</code> or <code>base_stats.hp</code> value for the <code>Creature</code> class, it always sets <strong>both</strong> values at once, which is a problem because it means I cannot reset the creature's hp to it's base value. Here's some of the code that deals with this</p> <pre><code>c...
0
2016-10-11T15:16:30Z
39,980,816
<p>the stats in your <code>__init__</code> function is an object of Class Stats correct? therefore you are assigning the SAME object to self.base_stats and self.stats. So any update to either of those will affect the other because you are changing the ONLY Stats object that your creature has as an attribute.</p> <pr...
0
2016-10-11T15:20:35Z
[ "python", "class" ]
multiple attributes being affected at once
39,980,712
<p>When I change the <code>stats.hp</code> or <code>base_stats.hp</code> value for the <code>Creature</code> class, it always sets <strong>both</strong> values at once, which is a problem because it means I cannot reset the creature's hp to it's base value. Here's some of the code that deals with this</p> <pre><code>c...
0
2016-10-11T15:16:30Z
39,980,858
<p>Yes. They reference the same object. You could use <a href="https://docs.python.org/2/library/copy.html" rel="nofollow">copy</a>, instead.</p> <pre><code>from copy import copy self.base_stats = copy(stats) self.stats = copy(stats) </code></pre>
2
2016-10-11T15:22:27Z
[ "python", "class" ]
HTML: set id for onclick from list
39,980,917
<p>Apologies if this question has already been asked. I'm new to HTML and I'm not familiar with the words I should use to find help with.</p> <p>I'm using Flask and HTML to make a website.</p> <p>My code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;h3&gt;Click the result you want to investigat...
0
2016-10-11T15:24:50Z
39,981,941
<p>You need to update your code like this, so you get the actual value from the variable <code>r["links"]</code>, by adding the brackets <code>{{r["links"]}}</code></p> <pre><code>&lt;p id="{{r["links"]}}" onclick="myFunction('{{r["links"]}}')" </code></pre>
0
2016-10-11T16:15:48Z
[ "python", "html", "string", "list", "flask" ]
How does Oracle handle accents in queries?
39,980,927
<p>I'm using python to execute the following query in Oracle:</p> <pre><code>SELECT COUNT(*) FROM TABLE WHERE DATA = 'CAMIÓN' </code></pre> <p>I'm getting a 0 when I should be getting a value different to 0 because there are rows where DATA is 'CAMIÓN'.</p> <p>If you execute the query like this:</p> <pre><code>SE...
1
2016-10-11T15:25:29Z
39,981,270
<p>If alternative convention spelling is enabled, then the acents equivalent word will be taken by oracle. </p> <p>For Example, </p> <p>Character Alternative Spelling ä ae</p> <p>You can use ctx_ddl.unset_attribute/ctx_ddl.set_attribute to set or unset alternative spelling conventions. </p>
0
2016-10-11T15:41:54Z
[ "python", "oracle" ]
Python bcrypt package on Heroku gives AttributeError: 'module' object has no attribute 'ffi'
39,980,976
<p>I'm having a problem using bcrypt with my Flask application on Heroku. When I deploy to Heroku and go to the login route I get 500 Internal server error. It works correctly locally. How do I get the bcrypt package working on Heroku?</p> <pre><code>ERROR in app: Exception on /login [POST] Traceback (most recent ca...
0
2016-10-11T15:27:29Z
39,981,834
<p>I've found the solution, I was using the following packages: bcrypt, flask_bcrypt and py-crypt. So I uninstall the py-bcrypt, probably this package was in conflict with bcrypt package.</p> <pre><code>pip uninstall py-bcrypt </code></pre>
0
2016-10-11T16:10:02Z
[ "python", "heroku", "flask", "bcrypt" ]
Python bcrypt package on Heroku gives AttributeError: 'module' object has no attribute 'ffi'
39,980,976
<p>I'm having a problem using bcrypt with my Flask application on Heroku. When I deploy to Heroku and go to the login route I get 500 Internal server error. It works correctly locally. How do I get the bcrypt package working on Heroku?</p> <pre><code>ERROR in app: Exception on /login [POST] Traceback (most recent ca...
0
2016-10-11T15:27:29Z
40,133,925
<p>I encountered a similar issue. Here is a copy of the last part of my stack trace: </p> <pre><code> self.password = User.hashed_password(password) File "/app/application/models.py", line 16, in hashed_password File "/app/.heroku/python/lib/python3.5/site-packages/flask_bcrypt.py", line 163, in generate_password_h...
0
2016-10-19T14:14:44Z
[ "python", "heroku", "flask", "bcrypt" ]
Using BeautifulSoup, is it possible to move to the parent tag when using the search for text function?
39,980,998
<p>Is it possible to move from the current position in the DOM up and down when only the text is an common identifier?</p> <pre><code>&lt;div&gt;changing text&lt;/div&gt; &lt;div&gt;fixed text&lt;/div&gt; </code></pre> <p>How to get the text <code>changing text</code> when searching for the <code>fixed text</code...
0
2016-10-11T15:28:27Z
39,981,169
<p>The error you are having is due to call <code>parent</code> in a ResultSet, a list of results. If you need to have multiple results, try:</p> <pre><code>x = soup.body.find_all(text=re.compile('fixed text')) for i in x: previous_div = i.previous_sibling </code></pre> <p>If you doesnt want to find multiple resul...
0
2016-10-11T15:37:11Z
[ "python", "beautifulsoup" ]
Using BeautifulSoup, is it possible to move to the parent tag when using the search for text function?
39,980,998
<p>Is it possible to move from the current position in the DOM up and down when only the text is an common identifier?</p> <pre><code>&lt;div&gt;changing text&lt;/div&gt; &lt;div&gt;fixed text&lt;/div&gt; </code></pre> <p>How to get the text <code>changing text</code> when searching for the <code>fixed text</code...
0
2016-10-11T15:28:27Z
39,981,226
<p>This program might do what you want:</p> <pre><code>from bs4 import BeautifulSoup import re html = '&lt;body&gt;&lt;div&gt;changing text&lt;/div&gt;&lt;div&gt;fixed text&lt;/div&gt;&lt;body&gt;' soup = BeautifulSoup(html) x = soup.body.findAll(text=re.compile('fixed text'))[0].parent.previous_sibling assert x.t...
2
2016-10-11T15:39:45Z
[ "python", "beautifulsoup" ]
Flask Installation - Error
39,981,113
<p>I tried installing Flask on a virtual environment on my PC that has Linux Mint. Ended up with this error:</p> <pre><code>*error: [Errno 13] Permission denied: '/usr/local/lib/python2.7/dist-packages/itsdangerous.py' ---------------------------------------------------------------------- Command "/usr/bin/python -u -...
-1
2016-10-11T15:34:09Z
39,981,848
<p>The error message indicates, that you're not working in the virtual environment. You probably haven't activated it. You can easily test and activate it:</p> <pre><code>$ which python /usr/bin/python # oops, no virtual environment $ source /home/user/venv/bin/activate $ which python /home/user/venv/bin/python # corr...
1
2016-10-11T16:11:21Z
[ "python", "pip", "virtualenv" ]
How can I display my python file in html?
39,981,157
<p>I'm using flask, tried different examples, many codes but nothing worked .. </p> <p>this is my html: </p> <pre><code>&lt;form method="post" name="prueba"&gt; &lt;div class="form-group "&gt; &lt;label class="col-sm-3 col-sm-3 control-label"&gt;Direccion IP: &lt;/...
-1
2016-10-11T15:36:47Z
39,981,278
<p>Could it be that you provide the data to the template as <code>addresses</code> but you call the variable in your template <code>address</code>?</p>
1
2016-10-11T15:42:16Z
[ "python", "html", "python-2.7", "flask", "debian" ]
Upload file to MS SharePoint using Python OneDrive SDK
39,981,210
<p>Is it possible to upload a file to the <strong>Shared Documents</strong> library of a <strong>Microsoft SharePoint</strong> site with the <strong><a href="https://github.com/OneDrive/onedrive-sdk-python" rel="nofollow">Python OneDrive SDK</a></strong>? </p> <p><strong><a href="https://dev.onedrive.com/readme.htm" r...
4
2016-10-11T15:39:00Z
40,137,811
<p>I finally found a solution, with the help of (<em>SO user</em>) sytech.</p> <p>The answer to my original question is that using the original <strong><a href="https://github.com/OneDrive/onedrive-sdk-python" rel="nofollow">Python OneDrive SDK</a></strong>, it's <strong>not possible</strong> to upload a file to the <...
2
2016-10-19T17:21:32Z
[ "python", "sharepoint", "onedrive", "onedrive-api" ]
Python/selenium - locate elements 'By' - specify locator strategy with variable?
39,981,228
<p>Having created a selenium browser and retrieved a web page, this works fine:</p> <pre><code>... if selenium_browser.find_element(By.ID, 'id_name'): print "found" ... </code></pre> <p>given a tuple like this:</p> <pre><code>tup = ('ID', 'id_name') </code></pre> <p>I'd like to be able to locate elements like t...
1
2016-10-11T15:39:58Z
39,981,670
<p>If you want to directly provide a tuple to <code>find_element</code>, add a <code>*</code> in front:</p> <pre><code>locator = (By.ID, 'id') element = driver.find_element(*locator) </code></pre> <p>Or with the method provided as a string:</p> <pre><code>locator = ('ID', 'id_name') driver.find_element(getattr(By, l...
3
2016-10-11T16:00:59Z
[ "python", "selenium" ]
Python/selenium - locate elements 'By' - specify locator strategy with variable?
39,981,228
<p>Having created a selenium browser and retrieved a web page, this works fine:</p> <pre><code>... if selenium_browser.find_element(By.ID, 'id_name'): print "found" ... </code></pre> <p>given a tuple like this:</p> <pre><code>tup = ('ID', 'id_name') </code></pre> <p>I'd like to be able to locate elements like t...
1
2016-10-11T15:39:58Z
39,981,750
<p>Your syntax is off.</p> <p>The docs say this should be used like such: <code>find_element(by='id', value=None)</code></p> <p>So instead of </p> <pre><code>if selenium_browser.find_element(By.tup[0], tup[1]): </code></pre> <p>You should do</p> <pre><code>if selenium_browser.find_element(tup[0], tup[1]): #or if s...
1
2016-10-11T16:05:15Z
[ "python", "selenium" ]
Comparing numbers give the wrong result in Python
39,981,237
<p>sorry if this is a terrible question, but I am really new to programming. I am attempting a short little test program.</p> <p>If I enter any value less than 24, it does print the "You will be old..." statement. If I enter any value greater than 24 (ONLY up to 99), it prints the "you are old" statement.</p> <p>The ...
3
2016-10-11T15:40:23Z
39,981,337
<p>The string <code>'100'</code> is indeed less than the string <code>'24'</code>, because <code>'1'</code> is "alphabetically" smaller than <code>'2'</code>. You need to compare <em>numbers</em>.</p> <pre><code>my_age = int(input()) if my_age &gt; 24: </code></pre>
1
2016-10-11T15:44:51Z
[ "python", "if-statement" ]
Comparing numbers give the wrong result in Python
39,981,237
<p>sorry if this is a terrible question, but I am really new to programming. I am attempting a short little test program.</p> <p>If I enter any value less than 24, it does print the "You will be old..." statement. If I enter any value greater than 24 (ONLY up to 99), it prints the "you are old" statement.</p> <p>The ...
3
2016-10-11T15:40:23Z
39,981,347
<p>You're testing a string value <code>myAge</code> against another string value <code>'24'</code>, as opposed to integer values.</p> <pre><code>if myAge &gt; ('24'): print('You are old, ' + myName) </code></pre> <p>Should be</p> <pre><code>if int(myAge) &gt; 24: print('You are old, {}'.format(myName)) </co...
5
2016-10-11T15:45:38Z
[ "python", "if-statement" ]
Comparing numbers give the wrong result in Python
39,981,237
<p>sorry if this is a terrible question, but I am really new to programming. I am attempting a short little test program.</p> <p>If I enter any value less than 24, it does print the "You will be old..." statement. If I enter any value greater than 24 (ONLY up to 99), it prints the "you are old" statement.</p> <p>The ...
3
2016-10-11T15:40:23Z
39,981,354
<pre><code>print ('What is your name?') myName = input () print ('Hello, ' + myName) print ('How old are you?, ' + myName) myAge = input () if int(myAge) &gt; 24: print('You are old, ' + myName) else: print('You will be old before you know it.') </code></pre> <p>Just a small thing about your code. You should...
1
2016-10-11T15:45:53Z
[ "python", "if-statement" ]
Comparing numbers give the wrong result in Python
39,981,237
<p>sorry if this is a terrible question, but I am really new to programming. I am attempting a short little test program.</p> <p>If I enter any value less than 24, it does print the "You will be old..." statement. If I enter any value greater than 24 (ONLY up to 99), it prints the "you are old" statement.</p> <p>The ...
3
2016-10-11T15:40:23Z
39,981,383
<p>Use <code>int(myAge)</code>. I always use <code>raw_input</code> and also, you dont have to print your questions. Instead put the question in with your raw_inputs like so:</p> <pre><code>myName = raw_input("Whats your name?") print ('Hello, ' + myName) myAge = raw_input('How old are you?, ' + myName) if int(myAge) ...
0
2016-10-11T15:47:36Z
[ "python", "if-statement" ]
Python csv; get max length of all columns then lengthen all other columns to that length
39,981,239
<p>I have a directory full of data files in the following format:</p> <blockquote> <pre><code>4 2 5 7 1 4 9 8 8 7 7 1 4 1 4 1 5 2 0 1 0 0 0 0 0 </code></pre> </blockquote> <p>They are separated by tabs. The third and fourth columns contain useful information until they reach 'zeroes'.. At which ...
1
2016-10-11T15:40:29Z
39,982,131
<p>Hi I would use Pandas and Numpy for this:</p> <pre><code>import pandas as pd import numpy as np df = pd.read_csv('csv.csv', delimiter='\t') df = df.replace(0,np.nan) while df.tail(1).isnull().all().all() == True: df=df[0:len(df)-1] df=df.replace(np.nan,0) df.to_csv('csv2.csv',sep='\t', index=False) #i used a dif...
0
2016-10-11T16:27:08Z
[ "python", "csv" ]
Python csv; get max length of all columns then lengthen all other columns to that length
39,981,239
<p>I have a directory full of data files in the following format:</p> <blockquote> <pre><code>4 2 5 7 1 4 9 8 8 7 7 1 4 1 4 1 5 2 0 1 0 0 0 0 0 </code></pre> </blockquote> <p>They are separated by tabs. The third and fourth columns contain useful information until they reach 'zeroes'.. At which ...
1
2016-10-11T15:40:29Z
39,983,331
<p>Here are two ways to do it:</p> <pre><code># Read in the lines and fill in the zeroes with open('input.txt') as input_file: data = [[item.strip() or '0' for item in line.split('\t')] for line in input_file] # Delete lines near the end that are only zeroes while set(data[-1]) == {'0'}:...
0
2016-10-11T17:40:16Z
[ "python", "csv" ]
Don't know what happened with this : "pymysql.err.ProgrammingError: (1064..."
39,981,248
<p>Here is my code:</p> <pre><code>from urllib.request import urlopen from bs4 import BeautifulSoup as bs import re import pymysql resp = urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8") soup = bs(resp ,"html.parser") listUrls = soup.findAll("a", href=re.compile("^/wiki/")) for url in list...
-1
2016-10-11T15:40:47Z
39,981,374
<p>First of all, I recommend giving whitespace the utmost attention to detail.</p> <p>Try this:</p> <pre><code>sql = "INSERT INTO wikiurl (urlname, urlhref) VALUES (%s, %s)" </code></pre> <p>Also notice that single quotation marks are not necessary around the table name. See: <a href="http://dev.mysql.com/doc/refman...
0
2016-10-11T15:46:55Z
[ "python", "mysql" ]
Don't know what happened with this : "pymysql.err.ProgrammingError: (1064..."
39,981,248
<p>Here is my code:</p> <pre><code>from urllib.request import urlopen from bs4 import BeautifulSoup as bs import re import pymysql resp = urlopen("https://en.wikipedia.org/wiki/Main_Page").read().decode("utf-8") soup = bs(resp ,"html.parser") listUrls = soup.findAll("a", href=re.compile("^/wiki/")) for url in list...
-1
2016-10-11T15:40:47Z
39,982,001
<p>I think your sql syntax has some error,but it is not easy to debug it.</p> <p>I recommend you use this method to print what the real sql string that is sent to mysql server.pymysql manual above:</p> <p><code>mogrify(self, query, args=None)</code></p> <p>'''Returns the exact string that is sent to the database by ...
0
2016-10-11T16:19:50Z
[ "python", "mysql" ]
Counting how many words are over a certain limit in a string Python
39,981,262
<p>Thank you all for help on previous part. I have now finished that. However changing title slightly and rewording question I now say that this is my code.</p> <pre><code>s = raw_input("Enter your text: ") longestWord = max(s.split(), key=len) k = list(s) count = len(k) wordsOver = [] over = count - 140 def num...
1
2016-10-11T15:41:30Z
39,981,303
<p>isalpha() doesn't return true for whitespace.</p> <p>Additionally, there are a whole slew of better ways to do this. You should look at the Counter class in collections. It's a dictionary that will provide you with what you need.</p>
-1
2016-10-11T15:43:27Z
[ "python", "python-2.7" ]
Counting how many words are over a certain limit in a string Python
39,981,262
<p>Thank you all for help on previous part. I have now finished that. However changing title slightly and rewording question I now say that this is my code.</p> <pre><code>s = raw_input("Enter your text: ") longestWord = max(s.split(), key=len) k = list(s) count = len(k) wordsOver = [] over = count - 140 def num...
1
2016-10-11T15:41:30Z
39,981,387
<p>in the for loop you're looking at each character and checking if that character <code>i</code> is a character that is in an alphabet using <code>.isalpha()</code> which will return false when it encounters a space since it is not alphabetic.</p> <p>See: <a href="https://docs.python.org/2/library/stdtypes.html#str.i...
0
2016-10-11T15:47:43Z
[ "python", "python-2.7" ]
Counting how many words are over a certain limit in a string Python
39,981,262
<p>Thank you all for help on previous part. I have now finished that. However changing title slightly and rewording question I now say that this is my code.</p> <pre><code>s = raw_input("Enter your text: ") longestWord = max(s.split(), key=len) k = list(s) count = len(k) wordsOver = [] over = count - 140 def num...
1
2016-10-11T15:41:30Z
40,118,903
<p>Welcome to SO! </p> <p>I think this is what you want to do. In your numLen function you need to use <code>append()</code> rather than <code>insert()</code> when adding to your list. This is because when using insert you're not incrementing the index so each time you insert at index 0 you overwrite any value that's ...
1
2016-10-18T22:07:35Z
[ "python", "python-2.7" ]
How to configure Django settings for different environments in a modular way?
39,981,292
<p>I have already searched on the web on this doubt, but they don't really seem to apply to my case.</p> <p>I have 3 different config files - Dev, Staging, Prod (of course)</p> <p>I want to modularize settings properly without repetition. So, I have made base_settings.py and I am importing it to dev_settings.py, stg...
0
2016-10-11T15:42:59Z
39,981,423
<p>Just set <code>DJANGO_SETTINGS_MODULE</code> in environment variables to your desired config file.</p> <p>That won't make you to change any of other services config files, and you don't even need to change django settings files.</p>
1
2016-10-11T15:48:59Z
[ "python", "django", "wsgi", "django-settings" ]
How to configure Django settings for different environments in a modular way?
39,981,292
<p>I have already searched on the web on this doubt, but they don't really seem to apply to my case.</p> <p>I have 3 different config files - Dev, Staging, Prod (of course)</p> <p>I want to modularize settings properly without repetition. So, I have made base_settings.py and I am importing it to dev_settings.py, stg...
0
2016-10-11T15:42:59Z
39,981,777
<p>Have a look at the <a href="https://django-configurations.readthedocs.io/en/stable/" rel="nofollow">Django Configurations</a> package.</p>
0
2016-10-11T16:06:53Z
[ "python", "django", "wsgi", "django-settings" ]
How do i verify user in database in google appengine app ( can anyone recommend the best way to do user authentication for google appengine app)?
39,981,297
<p>I have following code in <code>models.py</code> i can sort database by only key but not by string ?</p> <pre><code>from google.appengine.ext import ndb class Roles(ndb.Model): name = ndb.StringProperty() owner = ndb.KeyProperty(kind='User') created = ndb.DateTimeProperty(required=True, auto_now_add = True) class R...
0
2016-10-11T15:43:12Z
39,981,830
<p>You seem to be asking so many questions in one.</p> <p>To get user by email, simply do this:</p> <pre><code>users = Users.query(Users.email=='query_email').fetch(1) #note fetch() always returns a list if users: user_exists = True else: user_exists = False </code></pre> <p>Please note, you may need to <a h...
1
2016-10-11T16:09:48Z
[ "python", "django", "google-app-engine", "jinja2" ]
Acquire x-axis values in Python matplotlib
39,981,340
<p>Before I ask this question, I have already searched the internet for a while without success. To many experts this surely appears to be fairly simple. Please bear with me. </p> <p>I am having a plot made by matplotlib and it is returned as a plf.Figure. See the following: </p> <pre><code>def myplotcode(): x = ...
0
2016-10-11T15:45:13Z
39,981,475
<p>You can do:</p> <pre><code>l = ax.axes.lines[0] # If you have more curves, just change the index x, y = l.get_data() </code></pre> <p>That will give you two arrays, with the <code>x</code> and <code>y</code> data</p>
0
2016-10-11T15:51:39Z
[ "python", "matplotlib" ]
"Extra data" error trying to load a JSON file with Python
39,981,370
<p>I'm trying to load the following JSON file, named <code>archived_sensor_data.json</code>, into Python:</p> <pre><code>[{"timestamp": {"timezone": "+00:00", "$reql_type$": "TIME", "epoch_time": 1475899932.677}, "id": "40898785-6e82-40a2-a36a-70bd0c772056", "name": "Elizabeth Woods"}][{"timestamp": {"timezone": "+00:...
0
2016-10-11T15:46:39Z
39,981,489
<p>It is not a valid json; There are two list in here; one is</p> <pre><code>[{"timestamp": {"timezone": "+00:00", "$reql_type$": "TIME", "epoch_time": 1475899932.677}, "id": "40898785-6e82-40a2-a36a-70bd0c772056", "name": "Elizabeth Woods"}] </code></pre> <p>and the other one</p> <pre><code>[{"timestamp": {"timezon...
1
2016-10-11T15:52:31Z
[ "python", "json" ]
Segfault while embedding Python using scrapy in C
39,981,373
<p>i'm currently trying to run some scrapy spider (in Python) from a C code but i'm constantly getting segfault while testing.</p> <p>i have this code that allow me to run a simple python function from c :</p> <pre><code> int main() { PyObject *retour, *module, *fonction, *arguments; char *resultat; P...
0
2016-10-11T15:46:50Z
39,983,098
<p>There is a segfault at <code>PyArg_Parse(retour, "s", &amp;resultat);</code> because the script raises an exception and <code>retour</code> is NULL. After wrapping that in some error detection, the problem was that <code>PySys_SetPath(".");</code> replaces the existing <code>sys.path</code> so things like <code>scra...
0
2016-10-11T17:25:27Z
[ "python", "c", "scrapy", "embed" ]
Which is the most efficent of matching and replacing with an identifier every three new lines?
39,981,438
<p>I am working with some .txt files that doesn't have structure (they are messy), they represent a number of pages. In order to give them some structure I would like to identify the number of pages since the file itself doesn't have them. This can be done by replacing every three newlines with some annotation like: </...
2
2016-10-11T15:49:58Z
39,981,717
<p>If the format is as regular as you state in your problem description:</p> <blockquote> <p>Replace every occurrence of three newlines <code>\n</code> with <code>page: N</code></p> </blockquote> <p>You wouldn't have to use the <code>re</code> module. Something as simple as the following would do the trick:</p> <p...
2
2016-10-11T16:03:24Z
[ "python", "regex", "python-3.x", "nlp", "text-processing" ]
Creating a function for Road Pricing
39,981,446
<blockquote> <p>The Transport Authority is implementing a new Road Pricing system. The authorities decided that the cars will be charged based on distance travelled, on a per mile basis. A car will be charged $0.50/mi, a van $2.1/mi and taxis travel for free. Create a function to determine how much a particular vehic...
-2
2016-10-11T15:50:11Z
39,981,523
<p>Are you trying to compare the variable against some strings? </p> <p><code>if y == "car":</code></p>
0
2016-10-11T15:53:55Z
[ "python", "function" ]
Creating a function for Road Pricing
39,981,446
<blockquote> <p>The Transport Authority is implementing a new Road Pricing system. The authorities decided that the cars will be charged based on distance travelled, on a per mile basis. A car will be charged $0.50/mi, a van $2.1/mi and taxis travel for free. Create a function to determine how much a particular vehic...
-2
2016-10-11T15:50:11Z
39,981,591
<p>You have a problem with your <code>if</code> statement : firstly you are not checking any condition, secondly <code>input</code> returns a `string``</p> <p>try this out instead :</p> <pre><code>def Road_Pricing(): x = float(input("How many miles are driven?")) type = input("What car was driven?") if ty...
0
2016-10-11T15:57:13Z
[ "python", "function" ]
Creating a function for Road Pricing
39,981,446
<blockquote> <p>The Transport Authority is implementing a new Road Pricing system. The authorities decided that the cars will be charged based on distance travelled, on a per mile basis. A car will be charged $0.50/mi, a van $2.1/mi and taxis travel for free. Create a function to determine how much a particular vehic...
-2
2016-10-11T15:50:11Z
39,981,743
<p>The requirement is(emphasis mine):</p> <blockquote> <p>...... The function should take as input the type of the car and the distance travelled, and <strong>return</strong> the charged price.</p> </blockquote> <p>This means:</p> <ol> <li>The function should take two parameters: one for the type of the car and ...
1
2016-10-11T16:04:58Z
[ "python", "function" ]
Random and Itertools
39,981,461
<p>I have some sample code that iterates through two different ranges of numbers successfully, but I want to add functionality to it so that it moves through the chained ranges randomly like so:</p> <pre><code>import itertools import random for f in random.sample(itertools.chain(range(30, 54), range(1, 24)), 48): ...
2
2016-10-11T15:50:47Z
39,981,534
<p>The issue is that <code>itertools.chain</code> creates <a class='doc-link' href="http://stackoverflow.com/documentation/python/292/generators#t=201610111555299054924">generators</a>, rather than lists. These generators are lazily evaluated, each element exists only briefly and is discarded after use. The <code>len<...
2
2016-10-11T15:54:11Z
[ "python", "random", "itertools", "sample" ]
Random and Itertools
39,981,461
<p>I have some sample code that iterates through two different ranges of numbers successfully, but I want to add functionality to it so that it moves through the chained ranges randomly like so:</p> <pre><code>import itertools import random for f in random.sample(itertools.chain(range(30, 54), range(1, 24)), 48): ...
2
2016-10-11T15:50:47Z
39,981,536
<p>As the <a href="https://docs.python.org/3/library/random.html#random.sample" rel="nofollow"><code>random.sample</code></a> documentation states,</p> <blockquote> <p>Returns a <em>k</em> length list of unique elements chosen from the population sequence or set</p> </blockquote> <p>It requires a sequence or a set ...
2
2016-10-11T15:54:20Z
[ "python", "random", "itertools", "sample" ]
Random and Itertools
39,981,461
<p>I have some sample code that iterates through two different ranges of numbers successfully, but I want to add functionality to it so that it moves through the chained ranges randomly like so:</p> <pre><code>import itertools import random for f in random.sample(itertools.chain(range(30, 54), range(1, 24)), 48): ...
2
2016-10-11T15:50:47Z
39,981,540
<p>You have to convert <code>population</code> to a <code>list</code> explicitly. You can try like this:</p> <pre><code>n = len(list(population)) </code></pre>
1
2016-10-11T15:54:28Z
[ "python", "random", "itertools", "sample" ]
Random and Itertools
39,981,461
<p>I have some sample code that iterates through two different ranges of numbers successfully, but I want to add functionality to it so that it moves through the chained ranges randomly like so:</p> <pre><code>import itertools import random for f in random.sample(itertools.chain(range(30, 54), range(1, 24)), 48): ...
2
2016-10-11T15:50:47Z
39,981,550
<p>A quick fix would be as follows:</p> <pre><code>for f in random.sample(list(itertools.chain(range(30, 54), range(1, 24))), 48): </code></pre> <p>The problem with your code is that to sample from some iterable randomly, you need to know its length first, but <code>itertools.chain</code> is an iterable that provides...
1
2016-10-11T15:54:50Z
[ "python", "random", "itertools", "sample" ]
Random and Itertools
39,981,461
<p>I have some sample code that iterates through two different ranges of numbers successfully, but I want to add functionality to it so that it moves through the chained ranges randomly like so:</p> <pre><code>import itertools import random for f in random.sample(itertools.chain(range(30, 54), range(1, 24)), 48): ...
2
2016-10-11T15:50:47Z
39,981,651
<p>Im pretty sure you can get the length of a generator type object with the following syntax:</p> <pre><code>print sum(1 for x in (f for f in random.sample(list(itertools.chain(range(30, 54), range(1, 24))), 56))) </code></pre>
1
2016-10-11T15:59:51Z
[ "python", "random", "itertools", "sample" ]
Error Installing ICE on Python
39,981,517
<p>I have python 3.5 and 2.7 installed (I don't know if this might be the problem) and I need to use ZeroC Ice and when I do:</p> <pre><code>sudo pip install ice </code></pre> <p>I get the following error in the terminal:</p> <pre><code>Collecting ice Using cached ice-0.0.1.tar.gz Complete output from command ...
0
2016-10-11T15:53:43Z
39,982,216
<p>This is a simple mistake, try this instead.</p> <pre><code>pip install zeroc-ice </code></pre> <p>This should do the correct job.</p>
0
2016-10-11T16:32:29Z
[ "python", "ice" ]
Is there a better way?
39,981,564
<p>I have file say <code>abc.txt</code> with below format:</p> <pre><code>+ : @group2 : ALL + : @grp_xvz : ALL + : @group_abc_app: ALL + : @group_1_abc : ALL + : @group_2_xyz : ALL + : @group_3_def@@nmo_hosts : ALL </code></pre> <p>I need to grep for specific entries and check if file size of abc.txt > 220 ...
0
2016-10-11T15:56:10Z
39,982,430
<p>Try this:</p> <pre><code>import os, re match = re.search( r'^\+ *: *(@group_2_xyz|@group_3_def@@nmo_hosts) *: *ALL$', open('abc.txt').read(), re.M ) print(os.stat('abc.txt').st_size &gt; 220, match is not None) </code></pre>
0
2016-10-11T16:44:33Z
[ "python" ]
Dynamic submodule import failing in __main__
39,981,655
<p>I have a module that I want to run with <code>python -m modulename command</code> with commands referring to submodules launched by importing them. The file layout is as follows:</p> <pre><code>mainmodule/: __init__.py (empty) submodule1.py submodule2.py __main__.py </code></pre> <p>with <code>__main__.py<...
0
2016-10-11T16:00:11Z
39,981,922
<p>Change;</p> <pre><code> cmd = modules[sys.argv[1]] </code></pre> <p>to</p> <pre><code> cmd = commands[sys.argv[1]] </code></pre> <p>Other than one typo fix, I can't get the same error. Are you maybe not running python from the directory above <code>mainmodule</code>? Or do you maybe not have <code>mainmodule</...
0
2016-10-11T16:14:59Z
[ "python", "python-2.7" ]
Getting non-ASCII characters to work in Ren'Py functions
39,981,682
<p>I'm translating a Ren'Py game, which involves redefining a function that converts numbers to written-out words in a particular language. Those strings are then handled and inserted into the game text by the main code of the game (which I can't modify).</p> <p>My problem is that when I return strings that contain no...
1
2016-10-11T16:01:48Z
39,985,790
<p>Turns out I was using the wrong escape character and the wrong hex codes. And I had to use unicode strings. <code>u'\xF6'</code> and <code>u'\xFC'</code> work perfectly fine for the two characters I was trying to get.</p>
0
2016-10-11T20:04:47Z
[ "python", "unicode", "utf-8", "renpy" ]
Converting a nested array into a pandas dataframe in python
39,981,740
<p>I'm attempting to convert several dictionaries contained in an array to a pandas dataframe. The dicts are saved as such: </p> <pre><code>[[{u'category': u'anti-social-behaviour',u'location': {u'latitude': u'52.309886', u'longitude': u'0.496902'},u'month': u'2015-01'},{u'category': u'anti-social-behaviour',u'locatio...
1
2016-10-11T16:04:36Z
39,981,900
<p>You are on the right track, but you are creating a new dataframe for each row and not giving the proper <code>columns</code>. The following snippet should work:</p> <pre><code>import pandas as pd import numpy as np crimes = [[{u'category': u'anti-social-behaviour',u'location': {u'latitude': u'52.309886', u'longitu...
1
2016-10-11T16:13:55Z
[ "python", "python-2.7" ]
Caffe NetParameter parsing error
39,981,754
<p>I tried to load model and i got this error:</p> <p>Check failed: ReadProtoFromBinaryFile(param_file, param) Failed to parse NetParameter file: /home/Energetiks/builds/convolutional-pose-machines-release/testing/python/../../model/_trained_MPI/pose_iter_985000_addLEEDS.caffemodel <strong>* Check failure stack trace:...
-1
2016-10-11T16:05:28Z
40,016,039
<p>Problem is solved. I download file one more time and it works! Maybe I downloaded the wrong file the first time.</p>
1
2016-10-13T08:33:52Z
[ "python", "caffe", "pycaffe" ]
What does "TypeError: [foo] object is not callable" mean?
39,981,766
<p>I am trying to iterate through a list of Facebook postIDs, and I am getting the following error:</p> <p>TypeError: 'list' object is not callable</p> <p>Here is my code:</p> <pre><code>MCTOT_postIDs = [["126693553344_10155053097028345"], ["126693553344_10155050947628345"], ["126693553344_10155048566893345"], ["126...
-1
2016-10-11T16:06:19Z
39,981,944
<p>EDIT: For the other error, the function g.get_object(...) requires one more argument, that you are not passing. You're passing the fields, but you're must pass an ID as an argument too, you must pass the x of your loop, that contains the id.</p> <p>Probably should go like:</p> <pre><code>g.get_object('fields="mes...
4
2016-10-11T16:16:08Z
[ "python" ]
Print output to a file using another Python module
39,981,775
<p>I have two python modules: <code>buildContent.py</code> which contains code that results in output i want. <code>buildRun.py</code> which i run in order to redirect the output to a file.</p> <p>I'm trying to save the output from <code>buildContent.py</code> to a file and I did something like this in the <code>build...
0
2016-10-11T16:06:51Z
39,982,111
<p>the redirection is working properly. if you replace your print statement with a string you will see that it has worked.</p> <p>The reason for that output is that you are not calling any functions within buildcontent, merely importing it. </p> <p>The solution is to run the buildContent file from within the above ...
1
2016-10-11T16:25:31Z
[ "python" ]
Print output to a file using another Python module
39,981,775
<p>I have two python modules: <code>buildContent.py</code> which contains code that results in output i want. <code>buildRun.py</code> which i run in order to redirect the output to a file.</p> <p>I'm trying to save the output from <code>buildContent.py</code> to a file and I did something like this in the <code>build...
0
2016-10-11T16:06:51Z
39,982,907
<p>Instead of printing <code>buildContent</code>, just execute that module with the required parameters. Not sure of the content of <code>buildContent</code> but something like this should work:</p> <pre><code>buildContent(data) </code></pre> <p>This way the code inside <code>buildContent</code> will run on the <code...
0
2016-10-11T17:13:08Z
[ "python" ]
HTML Scraping with BeautifulSoup
39,981,811
<p>I'm trying to search </p> <pre><code>&lt;span&gt;Status:&lt;/span&gt;, &lt;span&gt;&lt;strong&gt;Moored&lt;/strong&gt;&lt;/span&gt;, &lt;strong&gt;Moored&lt;/strong </code></pre> <p>And pull out <code>Moored</code>. I've tried a lot of things but haven't been able to get it. Most recently <code>find(attrs={'sp...
0
2016-10-11T16:08:45Z
39,981,989
<pre><code>res = soup.find_all('span', text="Status:") res[0].parent.find('strong').text </code></pre> <p>soup.find_all searches for all <code>&lt;span&gt;</code> tags that contain the text <code>"Result:"</code>, then takes the next_sibling (the next <code>&lt;span&gt;</code> tag) and gets that tag's text contents. <...
2
2016-10-11T16:18:55Z
[ "python", "html", "beautifulsoup" ]
how can i parse html with lxml
39,981,846
<p>I have this html:</p> <pre><code>&lt;td class="name-td alLeft bordR"&gt;13.10.2016, Thu&lt;span class="sp"&gt;|&lt;/span&gt;17:00&lt;/td&gt; </code></pre> <p>I want to get a date (13.10.2016) and a time (17:00).</p> <p>I'm doing that:</p> <pre><code>t = lxml.html.parse(url) nextMatchDate = t.findall(".//td[@clas...
1
2016-10-11T16:11:11Z
39,982,594
<p>The problem is in the way you check for the <code>bordR</code> class. <code>class</code> is a <em>multi-valued</em> space-delimited attribute and you have to account for other classes on an element. In XPath you should be using "contains":</p> <pre><code>.//td[contains(@class, 'bordR')] </code></pre> <p>Or, even m...
1
2016-10-11T16:54:27Z
[ "python", "html", "parsing" ]
how can i parse html with lxml
39,981,846
<p>I have this html:</p> <pre><code>&lt;td class="name-td alLeft bordR"&gt;13.10.2016, Thu&lt;span class="sp"&gt;|&lt;/span&gt;17:00&lt;/td&gt; </code></pre> <p>I want to get a date (13.10.2016) and a time (17:00).</p> <p>I'm doing that:</p> <pre><code>t = lxml.html.parse(url) nextMatchDate = t.findall(".//td[@clas...
1
2016-10-11T16:11:11Z
39,982,692
<p>There's a method called <a href="http://lxml.de/api/lxml.etree._Element-class.html#itertext" rel="nofollow"><code>.itertext</code></a> that:</p> <blockquote> <p>Iterates over the text content of a subtree.</p> </blockquote> <p>So if you have an element <code>td</code> in a variable <code>td</code>, you can do th...
0
2016-10-11T16:59:30Z
[ "python", "html", "parsing" ]
Python: Installed Anaconda, but can't import numpy or matplotlib in Jupyter notebook
39,981,931
<p>I'm new to Python, so maybe there is a simple solution to this. I installed Anaconda and thought everything would be straightforward, but even though Jupyter works fine I can't import numpy and matplotlib into my notebook. Instead I get this error:</p> <pre><code>----------------------------------------------------...
0
2016-10-11T16:15:11Z
39,981,977
<p>Okay so If I correctly understand what you are saying I propose that you add the package in the same folder your python file is located in. If possible add the code you have used to import the data so I can located any possible mistakes</p>
0
2016-10-11T16:18:11Z
[ "python", "numpy", "matplotlib", "anaconda", "jupyter-notebook" ]
Python: Installed Anaconda, but can't import numpy or matplotlib in Jupyter notebook
39,981,931
<p>I'm new to Python, so maybe there is a simple solution to this. I installed Anaconda and thought everything would be straightforward, but even though Jupyter works fine I can't import numpy and matplotlib into my notebook. Instead I get this error:</p> <pre><code>----------------------------------------------------...
0
2016-10-11T16:15:11Z
39,982,352
<p>The key to your problem is possibly that you're running a pretty old Mac OS X version as <code>_strnlen</code> wasn't even available <a href="http://stackoverflow.com/q/32468480/4354477">until 10.7 release</a>. </p> <p>Anaconda is built for at least OS X 10.7 (according to <a href="https://groups.google.com/a/conti...
1
2016-10-11T16:40:30Z
[ "python", "numpy", "matplotlib", "anaconda", "jupyter-notebook" ]
Generate pandas dataframe from a series of start and end dates
39,981,934
<p>I have list of start and end dates which I want to convert into 1 large dataframe.</p> <p>here is a small reproductible example of what I am trying to acheive</p> <pre><code>import pandas as pd from pandas.tseries.offsets import * import datetime as dt dates = pd.DataFrame([[dt.datetime(2016,01,01),dt.datetime(20...
0
2016-10-11T16:15:20Z
39,982,848
<p>Still a bit clumsy, but probably more efficient than yours, as it's all in numpy. Merge a Dataframe with the appropriate day diffs</p> <pre><code>df = pd.DataFrame([[dt.datetime(2016,1,1),dt.datetime(2016,2,1)], [dt.datetime(2016,1,10), dt.datetime(2016,2,25)], [dt.datetime(2016,2,10), dt.datetime(2016,3,25)]], col...
0
2016-10-11T17:09:49Z
[ "python", "python-2.7", "datetime", "pandas" ]
Dataframe exported to CSV turns out different with data appearing in different columns then originally was
39,981,943
<p>I'm trying to read a CSV as a dataframe, then sort by column and subsequently output the sorted dataframe into a new CSV. However, the problem is that my output CSV looks nothing like the sorted dataframe with data being moved to wrong columns etc etc. I suspect that the problem lies with the data as some columns ar...
0
2016-10-11T16:16:05Z
39,982,308
<p>Are you talking about the unnamed column?</p> <p>Try using <code> sorteddf.to_csv('test.csv', index=False) </code> This tells pandas not to output the inbuilt index column (most of the time you don't care about this)</p>
1
2016-10-11T16:37:58Z
[ "python", "csv", "pandas", "export-to-excel" ]
Dataframe exported to CSV turns out different with data appearing in different columns then originally was
39,981,943
<p>I'm trying to read a CSV as a dataframe, then sort by column and subsequently output the sorted dataframe into a new CSV. However, the problem is that my output CSV looks nothing like the sorted dataframe with data being moved to wrong columns etc etc. I suspect that the problem lies with the data as some columns ar...
0
2016-10-11T16:16:05Z
39,984,506
<p>You have decoding/encoding issues. Your encoding is not in "ISO" its in 'latin-1'. Its hard to fix this unless you figure out why you are reading in your data like this. </p>
0
2016-10-11T18:46:05Z
[ "python", "csv", "pandas", "export-to-excel" ]
To process csv data set in Jupyter notebook
39,981,986
<p>I am worried to process data set developed in Sindhi language. I followed all steps but unable to process the data set. May any one help me in loading and importing csv file from local drive. I tried like:</p> <pre><code>import csv data C:\Users\mazhar\Anaconda3\Lib\site-packages\sindhi2.csv </code></pre> <p>got ...
1
2016-10-11T16:18:38Z
39,982,108
<p>Your second block is almost correct, all you need is to quote the file name:</p> <pre><code>import csv with open(r'C:\Users\mazhar\Anaconda3\Lib\site-packages\sindhi2.csv', 'rb') as f: data = list(csv.reader(f)) </code></pre> <p>Also note that I used raw string (see the <code>r</code> before the single quote) ...
1
2016-10-11T16:25:23Z
[ "python", "csv", "jupyter", "tagging" ]
an array from genfromtxt is being passed as a sequence?
39,982,036
<p>I have a list of coordinates and their respective error values in the shape:</p> <pre><code># Graph from standard correlation, page 1 1.197 0.1838 -0.03504 0.07802 +-0.006464 +0.004201 1.290 0.2072 -0.04241 0.05380 +-0.005833 +0.008101 </code></pre> <p>where the columns denote <code>x,y,lefterror,rig...
0
2016-10-11T16:21:49Z
39,983,132
<p>Thanks to hpaulj I noticed that the error bars' shape was (30,2), however <code>plt.errobar()</code> expects error arrarys in the shape (2,n), as python usually transposes matrices in similar operations and automatically avoids this problem I figured it would also do it, but I decided to change lines the following w...
0
2016-10-11T17:28:03Z
[ "python", "arrays", "numpy", "matplotlib", "errorbar" ]
an array from genfromtxt is being passed as a sequence?
39,982,036
<p>I have a list of coordinates and their respective error values in the shape:</p> <pre><code># Graph from standard correlation, page 1 1.197 0.1838 -0.03504 0.07802 +-0.006464 +0.004201 1.290 0.2072 -0.04241 0.05380 +-0.005833 +0.008101 </code></pre> <p>where the columns denote <code>x,y,lefterror,rig...
0
2016-10-11T16:21:49Z
39,983,652
<p>The shape of the array numpy expects for individual errorbars is <code>(2, N)</code>. You therefore need to transpose your array <code>error[:,2:4].T</code> Also, <code>matplotlib.errorbar</code> understands those values relative to the data. If <code>x</code> is the value and <code>(xmin, xmax)</code> the correspon...
0
2016-10-11T17:58:27Z
[ "python", "arrays", "numpy", "matplotlib", "errorbar" ]
Importing nested list into a text file
39,982,053
<p>I've been working on a problem which I realise I am probably approaching the wrong way but am now confused and out of ideas. Any research that I have done has left me more confused, and thus I have come for help.</p> <p>I have a nested list: </p> <blockquote> <p>[['# Name Surname', 'Age', 'Class', 'Score', '\n'...
0
2016-10-11T16:22:28Z
39,982,200
<p>The easiest way would probably be to remove the newlines from the sublists as you get them, the print each sublist one at a time. This would look something like:</p> <pre><code>for sublist in users: print(",".join(val for val in sublist if not val.isspace()), file=accountlist) </code></pre> <p>This will fail o...
0
2016-10-11T16:31:37Z
[ "python", "python-3.x" ]
Importing nested list into a text file
39,982,053
<p>I've been working on a problem which I realise I am probably approaching the wrong way but am now confused and out of ideas. Any research that I have done has left me more confused, and thus I have come for help.</p> <p>I have a nested list: </p> <blockquote> <p>[['# Name Surname', 'Age', 'Class', 'Score', '\n'...
0
2016-10-11T16:22:28Z
39,982,213
<p>I'm not sure which list is the one in your post (sublist?) but when you flatten it, just discard the "\n" strings:</p> <pre><code>flattened = [x for x in sublist if x != ["\n"]] </code></pre>
1
2016-10-11T16:32:15Z
[ "python", "python-3.x" ]
Importing nested list into a text file
39,982,053
<p>I've been working on a problem which I realise I am probably approaching the wrong way but am now confused and out of ideas. Any research that I have done has left me more confused, and thus I have come for help.</p> <p>I have a nested list: </p> <blockquote> <p>[['# Name Surname', 'Age', 'Class', 'Score', '\n'...
0
2016-10-11T16:22:28Z
39,982,271
<p>Instead of making one string, how about writing lines. Use something like this:</p> <pre><code> list_of_list = [[...]] lines = [','.join(line).strip() for line in list_of_list] lines = [line for line in lines if line] open(file,'w').writelines(lines) </code></pre>
0
2016-10-11T16:35:36Z
[ "python", "python-3.x" ]
Importing nested list into a text file
39,982,053
<p>I've been working on a problem which I realise I am probably approaching the wrong way but am now confused and out of ideas. Any research that I have done has left me more confused, and thus I have come for help.</p> <p>I have a nested list: </p> <blockquote> <p>[['# Name Surname', 'Age', 'Class', 'Score', '\n'...
0
2016-10-11T16:22:28Z
39,982,544
<p>Use the <code>csv</code> module to make it easier:</p> <pre><code>import csv data = [ ['# Name Surname', 'Age', 'Class', 'Score','\n'], ['\n'], ['Name', '9', 'B', 'N/A','\n'], ['Name1', '9', 'B', 'N/A','\n'], ['Name2', '8', 'B', 'N/A','\n'], ['Name3', '9', 'B', 'N/A','\n'], ['Name4', '8...
0
2016-10-11T16:51:20Z
[ "python", "python-3.x" ]
How to get datetime as string from mysql database in django model query
39,982,277
<p>I am using below query to get fields from mysql database in django 1.9.</p> <pre><code>event_dict_list = EventsModel.objects.filter(name__icontains = event_name).values('sys_id','name', 'start_date_time', 'end_date_time', 'notes') </code></pre> <p>now in the result <code>event_dict_list</code>, <code>start_date_ti...
0
2016-10-11T16:35:49Z
39,984,215
<p>You could try using the CAST() command in your query: <a href="http://stackoverflow.com/questions/2392413/convert-datetime-value-into-string-in-mysql">Convert DateTime Value into String in Mysql</a></p> <p>The above example kinda shows you how to!</p> <p>If that doesnt work, the other option is as you stated, iter...
0
2016-10-11T18:29:23Z
[ "python", "mysql", "django", "datetime", "django-models" ]
Filter tweets before saving into csv
39,982,288
<p>The below part of code fetches all tweets for a specific user and stores them into a csv file. I want to filter the tweets before storing them and store only those that contain the term "car". How can i do it? </p> <pre><code>import tweepy #https://github.com/tweepy/tweepy import csv #Twitter API credentials cons...
0
2016-10-11T16:36:42Z
39,982,842
<p>I would add an if-statement to the end of your outtweets list comprehension:</p> <pre><code>outtweets = [[tweet.id_str, tweet.created_at, tweet.text.encode("utf-8")]for tweet in alltweets if 'car' in tweet.text.encode("utf-8")] </code></pre>
1
2016-10-11T17:09:32Z
[ "python", "twitter", "tweepy" ]
pytest print stacktrace when import fails
39,982,332
<p>Suppose a python test module generates an <code>ImportError</code>. <code>pytest</code> (version 3.0.2) generates a compact error report:</p> <pre><code>__________________________________________ ERROR collecting tests/wc_tests/log/test_logger.py __________________________________________ ImportError while importin...
0
2016-10-11T16:39:04Z
39,983,844
<p>This was <a href="https://github.com/pytest-dev/pytest/pull/1979" rel="nofollow">changed</a> in pytest a week ago to display the full traceback.</p> <p>If you don't want to wait for the next release, you could use pytest from the git repository via <code>pip install git+https://github.com/pytest-dev/pytest.git</cod...
1
2016-10-11T18:09:54Z
[ "python", "py.test" ]
Code gives Change directory error but still changes directory
39,982,359
<pre><code>import os import socket import subprocess s = socket.socket() host = '&lt;my-ip&gt;' port = 9999 s.connect((host, port)) while True: data = s.recv(1024) if data[:2].decode("utf-8") == 'cd': os.chdir(data[3:].decode("utf-8")) if len(data) &gt; 0: cmd = subprocess.Popen(data[:].deco...
0
2016-10-11T16:40:52Z
39,983,285
<p>There are two <code>if</code>s here:</p> <pre><code>if data[:2].decode("utf-8") == 'cd': os.chdir(data[3:].decode("utf-8")) if len(data) &gt; 0: cmd = subprocess.Popen(data[:].decode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, s...
1
2016-10-11T17:37:29Z
[ "python", "python-3.x" ]
Efficient iteration through nested python dictionaries
39,982,389
<p>I have a dataset for which values determined to meet specific criteria is used to perform probability calculations as part of a summation. Currently, I hold the data in nested dictionaries to simplify the process of deterministic processing. </p> <p>The algorithm I'm using proves to be very expensive and after a wh...
1
2016-10-11T16:42:03Z
39,984,437
<p>There are over 5 billion combinations of companies in your dataset, which is really going to stress the memory out. I think you're storing all results into memory; instead, I would do interim dumps to a database and free up your containers. This is a sketch of the approach as I have no real data to test on, and it m...
2
2016-10-11T18:41:55Z
[ "python", "performance", "dictionary" ]
Processing several generators in parallel
39,982,477
<p>Suppose I have several generators (which should be able to run in parallel). Is it possible to use multiprocessing module to call next() on these generators so that the processing would run in parallel?</p> <p>I want to avoid making a list from the generators since it's very likely to consume lots of memory.</p> <...
0
2016-10-11T16:47:08Z
39,983,175
<p>I think your main issue would be getting the data base to the parent process to build your graph. However, this could probably be accomplished by using a multiprocessing <a href="https://docs.python.org/3.6/library/multiprocessing.html#multiprocessing.Queue" rel="nofollow"><code>Queue</code></a>.</p> <p>A simple ex...
1
2016-10-11T17:30:53Z
[ "python" ]
How to write each element of list in separate text file?
39,982,478
<p>I am trying to write each element of the list in a different file. </p> <p>Let say we have a list:</p> <pre><code>dataset = ['abc', 'def', 'ghi'] </code></pre> <p>I want to loop through the list and create text files depending upon the length of the list. So, in this case, there should be 3 text files and each wi...
0
2016-10-11T16:47:10Z
39,982,711
<p>Your code is just a little bit wrong. here is the last line corrected. file.write(bytes(dataset[count], 'UTF-8'))</p>
1
2016-10-11T17:00:41Z
[ "python", "python-3.x" ]
How to write each element of list in separate text file?
39,982,478
<p>I am trying to write each element of the list in a different file. </p> <p>Let say we have a list:</p> <pre><code>dataset = ['abc', 'def', 'ghi'] </code></pre> <p>I want to loop through the list and create text files depending upon the length of the list. So, in this case, there should be 3 text files and each wi...
0
2016-10-11T16:47:10Z
39,987,575
<p>Thank you all. Able to do that. Here is the solution below, feel free to ask any relevant information with that:</p> <pre><code># This will read a text file, normalize it and remove stopwords from it using nltk. import nltk, io, math from nltk.corpus import stopwords from string import punctuation # Read raw text ...
0
2016-10-11T22:09:40Z
[ "python", "python-3.x" ]
Using 7zip with python to create a passsword protected file in a given path
39,982,491
<p>I'm having an error for what seems to be a permissions problem when trying to create a zip file in a specified folder <code>testfolder</code> -folder has the following permissions: drwxr-xr-x 193 nobody nobody When trying to launch the following command in python I get the following:</p> <p><code>p= subprocess.Pop...
0
2016-10-11T16:47:47Z
39,982,554
<p>Try changing the permissions of the folder and see if it comes again:</p> <pre><code>chmod -R 777 /foldername </code></pre>
0
2016-10-11T16:52:00Z
[ "python", "linux", "python-2.7", "permissions", "permission-denied" ]
Using 7zip with python to create a passsword protected file in a given path
39,982,491
<p>I'm having an error for what seems to be a permissions problem when trying to create a zip file in a specified folder <code>testfolder</code> -folder has the following permissions: drwxr-xr-x 193 nobody nobody When trying to launch the following command in python I get the following:</p> <p><code>p= subprocess.Pop...
0
2016-10-11T16:47:47Z
39,982,764
<p><code>drwxr-xr-x</code> means that:</p> <p>1] only the directory's owner can list its contents, create new files in it (elevated access) etc.,</p> <p>2] members of the directory's group and other users can also list its contents, and have simple access to it.</p> <p>So in fact you don't have to change the directo...
1
2016-10-11T17:04:01Z
[ "python", "linux", "python-2.7", "permissions", "permission-denied" ]
How to convert string with special control characters, like \'x1b', into a standard string?
39,982,497
<p>When I use python socket program, we give an option like:</p> <pre class="lang-none prettyprint-override"><code>1) Input A to show your name 2) Input B to show your age 3) Input other to set your name &gt;&gt; </code></pre> <p>When client types 'Too' + delete button + 'm', server receives 'Too\x1bm'.</p> <p>How ...
0
2016-10-11T16:48:07Z
39,982,592
<p>If you know all the 'wrong characters' you can use .replace to remove unwanted parts.</p> <pre><code>'Too\x1bm'.replace(a[a.index('\x1b')-1:a.index('\x1b')+1],'') returns &gt;&gt;&gt; Tom </code></pre>
0
2016-10-11T16:54:25Z
[ "python", "sockets" ]
How to convert string with special control characters, like \'x1b', into a standard string?
39,982,497
<p>When I use python socket program, we give an option like:</p> <pre class="lang-none prettyprint-override"><code>1) Input A to show your name 2) Input B to show your age 3) Input other to set your name &gt;&gt; </code></pre> <p>When client types 'Too' + delete button + 'm', server receives 'Too\x1bm'.</p> <p>How ...
0
2016-10-11T16:48:07Z
39,982,769
<p>My first guess would be:</p> <pre><code>line = 'Too\x1bm' if '\x1b' in line: while True: index = line.find('\x1b') if index &gt; 0: line = line[:index - 1] + line[index + 1:] else: break line = line.replace('\x1b', '') </code></pre>
0
2016-10-11T17:04:27Z
[ "python", "sockets" ]