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 |
|---|---|---|---|---|---|---|---|---|---|
Using bits directly in python | 39,420,120 | <p>I want to manipulate the binary number directly in python. For example I have decimal number 18. I was able to convert number into binary using</p>
<pre><code>seed =bin(18)
</code></pre>
<p>but problem is I want to xor few of its bits.If I access this seed using array indexing I cant xor them as it is of type 'str... | -1 | 2016-09-09T21:43:07Z | 39,420,164 | <p>You can use bitwise operators directly on numbers.</p>
<p>For instance <code>18 & 3</code> gets you <code>2</code>, <code>18 | 3</code> gets you <code>19</code>, <code>1 << 5</code> gets you <code>32</code>. The fact that the human readable representation when you print the number is a decimal number does... | 2 | 2016-09-09T21:46:55Z | [
"python",
"arrays",
"binary"
] |
Using bits directly in python | 39,420,120 | <p>I want to manipulate the binary number directly in python. For example I have decimal number 18. I was able to convert number into binary using</p>
<pre><code>seed =bin(18)
</code></pre>
<p>but problem is I want to xor few of its bits.If I access this seed using array indexing I cant xor them as it is of type 'str... | -1 | 2016-09-09T21:43:07Z | 39,420,196 | <p>You can use bitwise operations directly on integers. You can convert between binary strings and integers for printing/debugging by using <code>bin</code> as you already know, and converting a string to binary using <code>int(binary_string, 2)</code>.</p>
<pre><code>seed = bin(18) # 0b10010
bitmask = '01101'
xor_re... | 1 | 2016-09-09T21:49:53Z | [
"python",
"arrays",
"binary"
] |
Scraping font-size from HTML and CSS | 39,420,152 | <p>I am trying to scrape the font-size of each section of text in an HTML page. I have spent the past few days trying to do it, but I feel like I am trying to re-invent the wheel. I have looked at python libraries like cssutils, beautiful-soup, but haven't had much luck sadly. I have made my own html parser that finds ... | 0 | 2016-09-09T21:46:06Z | 39,420,644 | <p>You can use selenium with firefox or phantomjs if you're on a headless machine, the browser will render the page, then you can locate the element and get it's attributes.</p>
<p>On python the method to get attributes is self explanatory, <code>Element_obj.get_attribute('attribute_name')</code></p>
| 0 | 2016-09-09T22:41:37Z | [
"python",
"html",
"css",
"web-scraping"
] |
Pandas : Making Decision on groupby size() | 39,420,183 | <p>I am trying to do a 'Change Data Capture' using two spreadsheet.
I have grouped my resulting dataframe and stuck with a strange problem.
Requirement:</p>
<p>Case 1) size of a group == 2, do certain tasks</p>
<p>Case 2) size of a group == 1 , do certain tasks</p>
<p>Case 3) size_of_a_group > 2, do certain tasks</p... | 3 | 2016-09-09T21:48:42Z | 39,427,514 | <p>This is a case where using a new index might make your life easier, depending on the operations you need to perform. I tried to mimic what some of your data might look like:</p>
<pre><code>In [1]:
...: pd.set_option('display.max_rows', 10)
...: pd.set_option('display.max_columns', 50)
...:
...:
...: ... | 2 | 2016-09-10T15:22:15Z | [
"python",
"pandas"
] |
Pandas : Making Decision on groupby size() | 39,420,183 | <p>I am trying to do a 'Change Data Capture' using two spreadsheet.
I have grouped my resulting dataframe and stuck with a strange problem.
Requirement:</p>
<p>Case 1) size of a group == 2, do certain tasks</p>
<p>Case 2) size of a group == 1 , do certain tasks</p>
<p>Case 3) size_of_a_group > 2, do certain tasks</p... | 3 | 2016-09-09T21:48:42Z | 39,434,076 | <p>Use <code>groupby</code> with a <code>transformation</code> of <code>df</code> with <code>np.size</code> </p>
<p>Consider the dataframe <code>df</code></p>
<pre><code>df = pd.DataFrame([
[1, 2, 3],
[1, 2, 3],
[2, 3, 4],
[2, 3, 4],
[2, 3, 4],
[3, 4, 5],
], column... | 3 | 2016-09-11T08:06:45Z | [
"python",
"pandas"
] |
Python - combine regex patterns | 39,420,194 | <p>I have a large text and the aim is to select all 10-character strings for which the first character is a letter and the last character is a digit. </p>
<p>I am a python rookie and what I managed to achieve is to find all 10-character strings:</p>
<pre><code>ten_char = re.findall(r"\D(\w{10})\D", pdfdoc)
</code></p... | 3 | 2016-09-09T21:49:35Z | 39,420,221 | <p><code>([a-z].{8}[0-9])</code></p>
<p>Will ask for 1 alphabetical char, 8 other character and finally 1 number.</p>
<p><strong>JS Demo</strong></p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-js lang-js prett... | 2 | 2016-09-09T21:53:34Z | [
"python",
"regex"
] |
Python - combine regex patterns | 39,420,194 | <p>I have a large text and the aim is to select all 10-character strings for which the first character is a letter and the last character is a digit. </p>
<p>I am a python rookie and what I managed to achieve is to find all 10-character strings:</p>
<pre><code>ten_char = re.findall(r"\D(\w{10})\D", pdfdoc)
</code></p... | 3 | 2016-09-09T21:49:35Z | 39,420,276 | <p>I wouldn't use regex for this. Regular string manipulation is more clear in my opinion (though I haven't tested the following code).</p>
<pre><code>def get_useful_words(filename):
with open(filename, 'r') as file:
for line in file:
for word in line.split():
if len(word) == 10... | 0 | 2016-09-09T21:58:46Z | [
"python",
"regex"
] |
Python - combine regex patterns | 39,420,194 | <p>I have a large text and the aim is to select all 10-character strings for which the first character is a letter and the last character is a digit. </p>
<p>I am a python rookie and what I managed to achieve is to find all 10-character strings:</p>
<pre><code>ten_char = re.findall(r"\D(\w{10})\D", pdfdoc)
</code></p... | 3 | 2016-09-09T21:49:35Z | 39,420,429 | <p>If I understand it, do:</p>
<pre><code>r'\b([a-zA-Z]\S{8}\d)\b'
</code></pre>
<p><a href="https://regex101.com/r/dM7lI7/2" rel="nofollow">Demo</a></p>
<p>Python demo:</p>
<pre><code>>>> import re
>>> txt="""\
... Should match:
... a123456789 aA34567s89 zzzzzzzer9
...
... Not match:
... 1123456... | 1 | 2016-09-09T22:14:35Z | [
"python",
"regex"
] |
Python - combine regex patterns | 39,420,194 | <p>I have a large text and the aim is to select all 10-character strings for which the first character is a letter and the last character is a digit. </p>
<p>I am a python rookie and what I managed to achieve is to find all 10-character strings:</p>
<pre><code>ten_char = re.findall(r"\D(\w{10})\D", pdfdoc)
</code></p... | 3 | 2016-09-09T21:49:35Z | 39,420,495 | <p>thank you very much for a great discussion and interesting suggestions. Very first post on stack overflow, but wow...what a community you are! </p>
<p>In fact, using: </p>
<pre><code>r'\b([a-zA-Z]\S{8}\d)'
</code></pre>
<p>solved my problem very nicely. Really appreciated all your comments.</p>
| 0 | 2016-09-09T22:22:32Z | [
"python",
"regex"
] |
Python openpyxl loop through excel files in folder | 39,420,317 | <p>I have working code, but it takes forever to loop through about 35 .xlsx files, read values in column J (including comparing cell values to a dictionary) and then do some comparisons. </p>
<p>Basically, it's an email notification system that a) finds a person's name in a cell somewhere in column J, then examines it... | 0 | 2016-09-09T22:02:42Z | 39,421,912 | <p>I don't know if this can help, it works for me in a similar situation, first i red and appended all files i had (3600) to a List, then i loop them through the list, it ran faster.</p>
<p>Good luck</p>
| 0 | 2016-09-10T02:23:25Z | [
"python",
"excel",
"openpyxl",
"smtplib"
] |
Separate comma-separated values within individual cells of Pandas Series using regex | 39,420,373 | <p>I have a csv file from a database I've converted into a Pandas DataFrame that I'm trying to clean up. One of the issues is that multiple values have been input into single cells that need to be split up. The complicating factor is that there are string comments (also with commas) that need to be kept intact. The pro... | 0 | 2016-09-09T22:09:31Z | 39,420,558 | <p>I would be inclined to use a lookahead; how you do so depends on your expected data. </p>
<p>This is a negative lookahead. it says "a comma that is not followed by whitespace" and would be preferred if you are <em>sure</em> that all comments with commas have whitespace, and would want to treat "red,green" as someth... | 1 | 2016-09-09T22:32:09Z | [
"python",
"regex",
"pandas",
"split"
] |
How to run python-socketio (eventlet WSGI server) over HTTPS | 39,420,376 | <p>I want to run the following eventlet WSGI server over HTTPS. I am trying to connect to the python server from JavaScript on my HTTPS enabled web-server. </p>
<p><strong>I would like the answer to describe how I would change this code below to work with HTTPS.</strong></p>
<pre><code>import socketio
import eventlet... | 0 | 2016-09-09T22:09:53Z | 39,420,484 | <p>To run a Evenlet WSGI server over HTTPS all thatâs needed is to pass an SSL-wrapped socket to the server() method like so:</p>
<pre><code>wsgi.server(eventlet.wrap_ssl(eventlet.listen(('', 8000)),
certfile='cert.crt',
keyfile='private.key',
... | 0 | 2016-09-09T22:21:41Z | [
"python",
"socket.io"
] |
ValueError: Domain error in arguments scipy rv_continuous | 39,420,430 | <p>I was trying to sample random variables subject to a given probability density function (pdf) with scipy.stats.rv_continuous:</p>
<pre><code>class Distribution(stats.rv_continuous):
def _pdf(self,x, _a, _c):
return first_hitting_time(x, _a, _c)
</code></pre>
<p>where the function <em>first_hitting_time... | 0 | 2016-09-09T22:14:37Z | 39,423,475 | <p>From <a href="https://docs.scipy.org/doc/scipy-0.16.0/reference/generated/scipy.stats.rv_continuous.html" rel="nofollow">the documentation</a>:</p>
<blockquote>
<h3>Subclassing</h3>
<p>New random variables can be defined by subclassing the rv_continuous
class and re-defining at least the <code>_pdf</code> ... | 0 | 2016-09-10T06:55:57Z | [
"python",
"numpy",
"scipy"
] |
Does mpi4py have a functioning mprobe (improbe)? | 39,420,448 | <p>You can see <a href="https://github.com/erdc-cm/mpi4py/blob/master/src/MPI/Comm.pyx#L1179" rel="nofollow">here</a> that <code>mpi4py</code> appears to have defined <code>mprobe</code> and <code>improbe</code>, however, there appears to be no <code>mrecv</code>, <code>Mrecv</code> or any other variation similar to it... | 1 | 2016-09-09T22:16:11Z | 39,425,176 | <p>The matched receives are available as methods <code>recv</code> and <code>irecv</code> of the <code>Message</code> object returned by the message probes - see <a href="https://github.com/erdc-cm/mpi4py/blob/master/src/MPI/Message.pyx#L120" rel="nofollow">here</a>. This actually makes sense since both <code>MPI_Mrecv... | 1 | 2016-09-10T10:35:04Z | [
"python",
"mpi",
"mpi4py"
] |
How to get predictive attributes of each target in `Random Forest`? | 39,420,453 | <p>I've been messing around with <code>Random Forest</code> models lately and they are really useful w/ the <code>feature_importance_</code> attribute! </p>
<p><strong>It would be useful to know which variables are more predictive of particular targets.</strong> </p>
<p>For example, what if the <code>1st and 2nd att... | -1 | 2016-09-09T22:16:45Z | 39,425,911 | <p>This is not really how RF works. Since there is no simple "feature voting" (which takes place in linear models) it is really hard to answer the question what "feature X is more predictive for target Y" even means. What feature_importance of RF captures is "how probable is, in general, to use this feature in the deci... | 1 | 2016-09-10T12:06:35Z | [
"python",
"machine-learning",
"classification",
"feature-extraction"
] |
Powering x until reach y in while loop | 39,420,497 | <p>Hi I want to make an app that will be raise X to a power until it reaches Y.</p>
<p>I have for now something like this</p>
<pre><code>x = 10
y = 1000000
while x <= y:
x = x**x
print(x)
</code></pre>
<p>I don't want it in function.</p>
<p>I know that probably this is simple, but I just started learning P... | -2 | 2016-09-09T22:22:45Z | 39,420,533 | <p>This might be what you are looking for. In python you want to use the operators for math as such += , -=, *=, /= for same variable operations.</p>
<pre><code>counter = 10
while counter <= 1000000:
counter *= counter
print(counter)
</code></pre>
| 0 | 2016-09-09T22:29:02Z | [
"python"
] |
Powering x until reach y in while loop | 39,420,497 | <p>Hi I want to make an app that will be raise X to a power until it reaches Y.</p>
<p>I have for now something like this</p>
<pre><code>x = 10
y = 1000000
while x <= y:
x = x**x
print(x)
</code></pre>
<p>I don't want it in function.</p>
<p>I know that probably this is simple, but I just started learning P... | -2 | 2016-09-09T22:22:45Z | 39,420,765 | <p>10<sup>10<sup>10<sup>â¦</sup></sup></sup> (x) will never be equal to 10<sup>6</sup> (y) because 10<sup>10</sup> is four orders of magnitude larger. Your program will interpret x = 10 as less than 10<sup>6</sup>, execute x<sup>x</sup> (10<sup>10</sup>), interpret this value as greater than 10<sup>6</sup>, exit the l... | 0 | 2016-09-09T22:56:26Z | [
"python"
] |
Getting cx_Oracle with correct case using conda | 39,420,508 | <p>I'm new to Python. I'm using the Anaconda 4.1.1 (Python 3.5.2) distribution on Ubuntu. I started working on a project that uses <a href="http://cx-oracle.sourceforge.net/" rel="nofollow"><code>cx_Oracle</code></a>. O could of course install <code>cx_Oracle</code> using <code>pip</code>.</p>
<pre><code>pip install c... | 2 | 2016-09-09T22:24:09Z | 39,501,925 | <p>The conda package name does not influence how your <code>import</code> the code in python. Looking at the linux-64 package <a href="https://anaconda.org/anaconda/cx_oracle/files" rel="nofollow">here</a> for example, while the package name is <code>cx_oracle</code> to conform to conda ecosystem standards, in python ... | 1 | 2016-09-15T01:28:41Z | [
"python",
"pip",
"anaconda",
"cx-oracle",
"conda"
] |
Getting cx_Oracle with correct case using conda | 39,420,508 | <p>I'm new to Python. I'm using the Anaconda 4.1.1 (Python 3.5.2) distribution on Ubuntu. I started working on a project that uses <a href="http://cx-oracle.sourceforge.net/" rel="nofollow"><code>cx_Oracle</code></a>. O could of course install <code>cx_Oracle</code> using <code>pip</code>.</p>
<pre><code>pip install c... | 2 | 2016-09-09T22:24:09Z | 39,518,360 | <p>The problem had nothing to do with the lowercase package name on Continuum's conda repository. In fact I was missing something. I had created a new virtual environment as I mentioned in the question:</p>
<pre><code>conda create -n foobar --file requirements.txt
</code></pre>
<p>The requirements file contained <cod... | 0 | 2016-09-15T18:50:48Z | [
"python",
"pip",
"anaconda",
"cx-oracle",
"conda"
] |
how to parse key value pair request from url using python requests in flask | 39,420,580 | <p>I have spent about a week on this issue and although I have made considerable progress I am stuck at a key point.</p>
<p>I am writing a simple client-server program in Python that is supposed to accept key/value pairs from the command line, formulate them into an url, and request the url from the server. The proble... | 0 | 2016-09-09T22:35:19Z | 39,420,658 | <p>The problem seems to be in your payload.</p>
<p>The payload needs to be a dictionary. You're giving it a string.</p>
<p><code>sys.argv[2]</code> will be a string, even if you format the text to look like a dictionary. So unless there's something missing from your client code snippet, payload isn't actually a dicti... | 2 | 2016-09-09T22:43:26Z | [
"python",
"flask",
"python-requests"
] |
how to parse key value pair request from url using python requests in flask | 39,420,580 | <p>I have spent about a week on this issue and although I have made considerable progress I am stuck at a key point.</p>
<p>I am writing a simple client-server program in Python that is supposed to accept key/value pairs from the command line, formulate them into an url, and request the url from the server. The proble... | 0 | 2016-09-09T22:35:19Z | 39,421,117 | <p><code>test</code> is expecting values for <code>key1</code> and <code>key2</code>. Flask would provide those through your route. </p>
<pre><code>@app.route('/buy/<key1>/<key2>')
def test(key1, key2):
</code></pre>
<p>Visiting <code>/buy/value1/value2</code> would give values to the arguments. You want ... | 1 | 2016-09-09T23:44:01Z | [
"python",
"flask",
"python-requests"
] |
Holding reference to out of scope object's method | 39,420,599 | <pre><code>class Foo:
def __init__(self, _label):
self.label = _label
def display(self):
print(str(self.label))
def get_display(self):
return self.display
display_test = Foo(1).get_display()
display_test()
def inner_scope():
global display_test
display_test = Foo(2).get_disp... | 0 | 2016-09-09T22:36:58Z | 39,420,753 | <p>Your question is a bit unclear. This sentence: "it appears as though they have not been garbage collected as of the time display_test gets invoked" suggests some confusion. In fact <code>display_test</code> gets invoked twice - one when it's bound to an instance method of Foo(1), and again when it's bound to insta... | 1 | 2016-09-09T22:55:13Z | [
"python",
"python-2.7",
"python-3.x",
"garbage-collection"
] |
Holding reference to out of scope object's method | 39,420,599 | <pre><code>class Foo:
def __init__(self, _label):
self.label = _label
def display(self):
print(str(self.label))
def get_display(self):
return self.display
display_test = Foo(1).get_display()
display_test()
def inner_scope():
global display_test
display_test = Foo(2).get_disp... | 0 | 2016-09-09T22:36:58Z | 39,426,319 | <p>In Python 2, <code>display_test</code> holds a reference to an <code>instancemethod</code> object, one of whose attributes is <code>im_self</code>, the instance the method is bound to.</p>
<p>In Python 3, <code>display_test</code> holds a reference to a <code>method</code> object, one of whose attributes is <code>_... | 0 | 2016-09-10T13:00:49Z | [
"python",
"python-2.7",
"python-3.x",
"garbage-collection"
] |
How you calculate the average rating per genre in python? | 39,420,633 | <p>I have this lens dataframe. It has columns to classify genres a movie belongs to. The genre categories are column names with binary values in the rows. If a movie belongs to a genre, it has a 1 under the appropriate column and 0 otherwise. I want to calculate the average rating per genre for each user in python pand... | -1 | 2016-09-09T22:40:29Z | 39,421,427 | <p>Consider reshaping your dataframe from wide to long to create a <em>genre</em> column and then run result through <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.pivot_table.html" rel="nofollow"><code>pivot_table()</code></a> using its <code>aggfunc</code> argument, specifically for numpy mean:... | 0 | 2016-09-10T00:43:23Z | [
"python",
"pandas"
] |
Killing a sub-subprocess from python/bash without leaving orphans | 39,420,683 | <p>I have a system with 3 main components (everything running on Ubuntu14.04 and Python 2.7, don't care too much about portability):</p>
<p>a) Some binary that executes, let's call it <code>runtime</code>, it writes some values to <code>stdout</code> and <code>stderr</code> that I need to read from (c)</p>
<p>b) A la... | 1 | 2016-09-09T22:46:34Z | 39,420,840 | <p>Use process group this way:</p>
<pre><code>p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
shell=True, preexec_fn=os.setpgrp)
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
</code></pre>
| 0 | 2016-09-09T23:04:33Z | [
"python",
"linux",
"bash",
"ubuntu",
"subprocess"
] |
Get a list of subdirectories | 39,420,685 | <p>I know I can do this:</p>
<pre><code>data = sc.textFile('/hadoop_foo/a')
data.count()
240
data = sc.textFile('/hadoop_foo/*')
data.count()
168129
</code></pre>
<p>However, I would like to count the size of the data of every subdirectory of "/hadoop_foo/". Can I do that?</p>
<p>In other words, what I want is somet... | 0 | 2016-09-09T22:46:46Z | 39,421,095 | <p>With python use <a href="https://pypi.python.org/pypi/hdfs/" rel="nofollow">hdfs</a> module; <a href="https://hdfscli.readthedocs.io/en/latest/api.html#hdfs.client.Client.walk" rel="nofollow">walk()</a> method can get you list of files.</p>
<p>The code sould look something like this:</p>
<pre><code>from hdfs impor... | 1 | 2016-09-09T23:40:26Z | [
"python",
"hadoop",
"apache-spark",
"hdfs",
"bigdata"
] |
Substituting strings with sub() method with regex | 39,420,713 | <p>I didn't want to write and ask this forum but I am stuck and the book I'm following, that supposed to be for beginners, is anything but... </p>
<p>Anyway... In the string below: </p>
<pre><code>'Agent Alice told Agent Bob that Agent Steve was a double agent.'
</code></pre>
<p>I want to show just the first letter... | 0 | 2016-09-09T22:50:58Z | 39,420,788 | <p>You can use look behind <code>?<=</code> syntax for this:</p>
<pre><code>namesRegex = re.compile(r'(?<=Agent\s[A-Z])\w+')
mo = namesRegex.sub(r'****', 'Agent Alice told Agent Bob that Agent Steve was a double agent.')
mo
# 'Agent A**** told Agent B**** that Agent S**** was a double agent.'
</code></pre>
<p>... | 1 | 2016-09-09T22:58:32Z | [
"python"
] |
Why do certain implementations run slow in Python? | 39,420,734 | <p>I have three implementations of a function that checks whether a string (or a space delimited phrase) is a palindrome:</p>
<pre><code>def palindrome(str_in):
def p(s, i, j):
if i >= j:
return True
elif s[i] != s[j]:
return False
else:
return p(s, i+... | 2 | 2016-09-09T22:53:15Z | 39,421,780 | <p>OK, so let's talk from the begining. CPython compiles visible text into a thing called bytecode, which is a representation that is easier for the virtual machine (i.e. the interpreter) to understand.</p>
<p>Both <code>palindrome</code> and <code>palindrome2</code> functions are slower then <code>palindrome1</code> ... | 1 | 2016-09-10T01:56:10Z | [
"python",
"recursion",
"optimization",
"time-complexity",
"palindrome"
] |
Subtracting line of a column with other line values using python 3.5? | 39,420,799 | <pre><code>1 10.00
2 11.23
3 12.32
4 23.55
5 15.33
6 12.23
7 22
8 10.33
9 8.9
10 5.89
</code></pre>
<p>I have a dat file with above values. I want to subtract line 1 of column 2 with line 2,3,4...10 of column 2, then line 2 of column 2 with line 3,4,5...10, then 3 with 4,5..10 and so on until line 9 with 10.... | 0 | 2016-09-09T22:59:53Z | 39,420,879 | <pre><code>k = [10.0, 11.23, 12.32, 23.55, 15.33, 12.23, 22, 10.33, 8.9, 5.89]
k[:] = [x - 10.0 for x in k]
[0.0, 1.23, 2.32, 13.55, 5.33, 2.23, 12.0, 0.33, -1.1, -4.11]
</code></pre>
| 0 | 2016-09-09T23:09:45Z | [
"python"
] |
Making snapshot plots using python | 39,420,805 | <p>I have a dynamic simulation that I am trying to visualise in a paper that I am writing. </p>
<p>I would like to take 'snapshots' of the dynamics as they progress over time, and then superimpose all of them on the same canvas, plotted against time (for each snapshot). </p>
<p>Similar to this (walking mechanism):</p... | 0 | 2016-09-09T23:00:15Z | 39,424,752 | <p>This answer might need some iterations to improve since it is still not completely clear how your model looks, what kind of data you get, etc. But below is attempt #1 which plots a dynamic (<em>drunk stick figure</em>) system in time/space.</p>
<pre><code>import matplotlib.pylab as pl
import numpy as np
pl.close('... | 1 | 2016-09-10T09:40:59Z | [
"python",
"matplotlib",
"simulate"
] |
Working out which points lat/lon coordinates are closest to | 39,420,835 | <p>I currently have a list of coordinates</p>
<pre><code>[(52.14847612092221, 0.33689512047881015),
(52.14847612092221, 0.33689512047881015),
(52.95756796776235, 0.38027099942700493),
(51.78723479900971, -1.4214854900618064)
...]
</code></pre>
<p>I would like to split this list into 3 separate lists/datafames cor... | 0 | 2016-09-09T23:04:18Z | 39,421,045 | <p>This will get you started:</p>
<pre><code>from geopy.geocoders import Nominatim
geolocator = Nominatim()
places = ['london','cardiff','leeds']
coordinates = {}
for i in places:
coordinates[i] = ((geolocator.geocode(i).latitude, geolocator.geocode(i).longitude))
>>>print coordinates
{'cardiff': (51.4... | 0 | 2016-09-09T23:34:50Z | [
"python",
"geospatial",
"geopy"
] |
Working out which points lat/lon coordinates are closest to | 39,420,835 | <p>I currently have a list of coordinates</p>
<pre><code>[(52.14847612092221, 0.33689512047881015),
(52.14847612092221, 0.33689512047881015),
(52.95756796776235, 0.38027099942700493),
(51.78723479900971, -1.4214854900618064)
...]
</code></pre>
<p>I would like to split this list into 3 separate lists/datafames cor... | 0 | 2016-09-09T23:04:18Z | 39,821,344 | <p>This is a pretty brute force approach, and not too adaptable. However, that can be the easiest to understand and might be plenty efficient for the problem at hand. It also uses only pure python, which may help you to understand some of python's conventions.</p>
<pre><code>points = [(52.14847612092221, 0.33689512047... | 0 | 2016-10-02T20:24:50Z | [
"python",
"geospatial",
"geopy"
] |
Defining "add" function in a class | 39,420,963 | <p>I'm writing my own code language in Python (called Bean), and I want the math functions to have the syntax:</p>
<p>print math.add(3+7)<br>
==>10</p>
<p>print math.mul(4*8)<br>
==>32</p>
<p>and so on. So far my code is:</p>
<pre><code>bean_version = "1.0"
console = []
print "Running Bean v%s" % bean_version
#Math... | -1 | 2016-09-09T23:22:30Z | 39,421,021 | <p>If you don't want to change the name of the add function, you can just change <code>self.add</code>. These two <code>add</code>s are conflicting with each other. You will not get any error if you run this:</p>
<pre><code>bean_version = "1.0"
console = []
print "Running Bean v%s" % bean_version
#Math Function
class ... | 3 | 2016-09-09T23:31:10Z | [
"python",
"python-2.7"
] |
Defining "add" function in a class | 39,420,963 | <p>I'm writing my own code language in Python (called Bean), and I want the math functions to have the syntax:</p>
<p>print math.add(3+7)<br>
==>10</p>
<p>print math.mul(4*8)<br>
==>32</p>
<p>and so on. So far my code is:</p>
<pre><code>bean_version = "1.0"
console = []
print "Running Bean v%s" % bean_version
#Math... | -1 | 2016-09-09T23:22:30Z | 39,421,076 | <p>An object can't have two properties with the same name. So if you have a property called <code>add</code> that holds a number, it can't also have a method called <code>add</code>, because methods are just properties that happen to hold functions. When you do:</p>
<pre><code>this.add = add
</code></pre>
<p>you're r... | 3 | 2016-09-09T23:37:38Z | [
"python",
"python-2.7"
] |
How did I overwrite my whole python program with this command prompt command? | 39,420,977 | <p>So I was putting in some values into a Python program I have written (what it does is irrelevant):</p>
<blockquote>
<p>E:\Users\Me\Desktop\Python>idtohex.py</p>
<p>Enter ID: 213467</p>
<p>DB 41 03</p>
</blockquote>
<p>Nice, it works alright. Now at this point I had accidentally copied this string to my... | 0 | 2016-09-09T23:25:14Z | 39,421,116 | <p>Before running a command, cmd.exe sets up its standard handles for the child process to inherit. The <code>></code> operator redirects a file descriptor to a file opened for output, and it truncates an existing file to 0 bytes. It defaults to file descriptor 1 (standard output, or stdout). Since the only output i... | 5 | 2016-09-09T23:43:54Z | [
"python",
"windows",
"batch-file",
"command-line",
"cmd"
] |
Play audio using online compiler | 39,421,103 | <p>I am working on a program, and I want to be able to play a mp3 file (preferably, though other files could work). The catch is that, unfortunately, I'm using an online compiler (<a href="http://repl.it" rel="nofollow">repl.it</a>), and I can't use a desktop compiler. In other words, I can't use pyglet, or really any ... | 2 | 2016-09-09T23:41:24Z | 39,435,721 | <p>Even if you could install a library for audio playback on the online REPL, wouldn't the sound be played back somewhere in the racks of a data center instead of your computer at home?</p>
<p>AFAIK, the only currently feasible solution to this problem is to use an online service that allows HTML output and to use the... | 1 | 2016-09-11T11:44:43Z | [
"python",
"audio",
"compilation",
"music"
] |
How to get the specific C compiler type from Python distutils? | 39,421,201 | <p>I'd like to check the system's C compiler in Python so that I can add library links accordingly to compile my Cython code.</p>
<p>I understand <code>distutils.ccompiler.get_default_compiler()</code> or something like <code>compiler.compiler_type</code> would return a compiler name. But it is too coarse just like "u... | 3 | 2016-09-09T23:58:29Z | 39,421,570 | <p>Generally you should be able to use the <strong><a href="https://docs.python.org/2/library/platform.html#platform.python_compiler" rel="nofollow"><code>platform</code></a></strong> module to get the info:</p>
<pre><code>>>> import platform
>>> platform.python_compiler()
'GCC 4.8.5 20150623 (Red Ha... | 2 | 2016-09-10T01:13:33Z | [
"python",
"c"
] |
getsockaddarg() error when using UDP sockets | 39,421,216 | <p>I am trying to create a simple UDP connection, but fail miserably every time. I am using Python 3.5.2 with PyCharm.
import socket
from socket import AF_INET, SOCK_DGRAM</p>
<pre><code>ip = tuple(input('Enter an ip\n'))
#time = int(input('How long? In seconds \n'))
msg = 'Hello'
addr = (ip, 80)
def conn... | -1 | 2016-09-10T00:01:35Z | 39,421,484 | <p>Calling <code>tuple</code> will construct a tuple containing each individual character in the iterable (the input string):</p>
<pre><code>>>> tuple('127.0.0.1')
('1', '2', '7', '.', '0', '.', '0', '.', '1')
</code></pre>
<p>Don't use <code>tuple</code> just use the input you receive:</p>
<pre><code>ip = ... | 0 | 2016-09-10T00:53:43Z | [
"python",
"sockets",
"python-3.x"
] |
convert image pixels from square to hexagonal | 39,421,233 | <p>How can i convert the pixels of an image from square to hexagonal? Doing so i need to extract the rgb values from each hex pixel. Is there any library or function that simplify this process?</p>
<p>Example : Mona Lisa Hexagonal Pixel Shape </p>
<p><a href="http://i.stack.imgur.com/o3isE.jpg" rel="nofollow"><img sr... | 0 | 2016-09-10T00:03:46Z | 39,424,482 | <p>Here's a possible approach, though I am sure if you are able to write code to read, manipulate and use pixels from a file format that hasn't been invented yet, you should be able to create that file yourself ;-)</p>
<p>You could generate a hexagonal grid, using <strong>ImageMagick</strong> which is installed on mos... | 1 | 2016-09-10T09:07:49Z | [
"python",
"opencv",
"numpy",
"image-processing"
] |
convert image pixels from square to hexagonal | 39,421,233 | <p>How can i convert the pixels of an image from square to hexagonal? Doing so i need to extract the rgb values from each hex pixel. Is there any library or function that simplify this process?</p>
<p>Example : Mona Lisa Hexagonal Pixel Shape </p>
<p><a href="http://i.stack.imgur.com/o3isE.jpg" rel="nofollow"><img sr... | 0 | 2016-09-10T00:03:46Z | 39,424,951 | <p>Fred has an Imagemagick script on his site that may do what you want: <a href="http://www.fmwconcepts.com/imagemagick/stainedglass/index.php" rel="nofollow">STAINEDGLASS</a></p>
| 2 | 2016-09-10T10:03:46Z | [
"python",
"opencv",
"numpy",
"image-processing"
] |
convert image pixels from square to hexagonal | 39,421,233 | <p>How can i convert the pixels of an image from square to hexagonal? Doing so i need to extract the rgb values from each hex pixel. Is there any library or function that simplify this process?</p>
<p>Example : Mona Lisa Hexagonal Pixel Shape </p>
<p><a href="http://i.stack.imgur.com/o3isE.jpg" rel="nofollow"><img sr... | 0 | 2016-09-10T00:03:46Z | 39,428,443 | <p>First of all, I think there is no such a function that is ready for you to perform the lattice conversion, thus you may need to implement the conversion process by yourself.</p>
<p>The lattice conversion is a re-sampling process, and it is also a interpolation process. There are many algorithms that have been devel... | 0 | 2016-09-10T16:55:21Z | [
"python",
"opencv",
"numpy",
"image-processing"
] |
How to return the indices of maximum value from an array with python? | 39,421,273 | <p>I have an array and I want to find the indices of the maximum values.</p>
<p>For example:</p>
<pre><code>myarray = np.array([1,8,8,3,2])
</code></pre>
<p>I want to get the result: <code>[1,2]</code>, how can I do that?</p>
<p>(Actually I tried <code>np.argmax(myarray)</code>, but it only return the first occurre... | 1 | 2016-09-10T00:10:50Z | 39,421,310 | <p>Given:</p>
<pre><code>>>> myarray = np.array([1,8,8,3,2])
</code></pre>
<p>You can do:</p>
<pre><code>>>> np.where(myarray==myarray[np.argmax(myarray)])
(array([1, 2]),)
</code></pre>
<p>or, </p>
<pre><code>>>> np.where(myarray==max(myarray))
(array([1, 2]),)
</code></pre>
<p>or, </p... | 3 | 2016-09-10T00:18:48Z | [
"python",
"numpy"
] |
TypeError: takes exactly 1 argument (0 given) - Scrapy | 39,421,304 | <p>I'm working with scrapy. I want to generate a unique user agent for each request. I have the following:</p>
<pre><code>class ContactSpider(Spider):
name = "contact"
def getAgent(self):
f = open('useragentstrings.txt')
agents = f.readlines()
return random.choice(agents).strip()
... | 1 | 2016-09-10T00:17:55Z | 39,421,436 | <p><code>getAgent()</code> is an <em>instance method</em> and expects to see the <code>ContactSpider</code> instance as an argument. But, the problem is, you don't need this function to be a member of your spider class - move it to a separate "helpers"/"utils"/"libs" module and import:</p>
<pre><code>from helpers impo... | 2 | 2016-09-10T00:45:04Z | [
"python",
"scrapy"
] |
HTML printing is wrong | 39,421,329 | <p>So I've been looking at this for over an hour and I cannot figure out what the heck is going on.</p>
<p>The script is printing only a ">"</p>
<p>It's suppose to print the full HTML and then, after the form is submitted, print "print_after"</p>
<pre><code>import webapp2
class MainHandler(webapp2.RequestHandler):
... | 0 | 2016-09-10T00:22:16Z | 39,425,429 | <p>I tested your code and rearranged it a little. I used http post for submitting the form and then it prints the form variables. </p>
<pre><code>import webapp2
class HelloWebapp2(webapp2.RequestHandler):
def get(self):
self.response.write('''<!DOCTYPE HTML>
<html>
<head>... | 0 | 2016-09-10T11:09:55Z | [
"python",
"class",
"variables",
"webapp2"
] |
Pandas data reduction and merging | 39,421,350 | <p>I am working with a Pandas (version 0.17.1) DataFrame that looks like this:</p>
<pre><code> time type module msg_type content
36636 2016-08-25 17:59:50.051 INFO MOD_1_NAME STATUS Received Status Monitoring from MODULE_1 'Property A' = some_value_1
36637 2016-08-25 17:59:... | 1 | 2016-09-10T00:26:22Z | 39,422,983 | <p>Define a function and use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow">groupby()</a> and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow">apply()</a>:</p>
<pre><code>In [235]: def create_da... | 1 | 2016-09-10T05:42:43Z | [
"python",
"pandas",
"reduction"
] |
Pandas data reduction and merging | 39,421,350 | <p>I am working with a Pandas (version 0.17.1) DataFrame that looks like this:</p>
<pre><code> time type module msg_type content
36636 2016-08-25 17:59:50.051 INFO MOD_1_NAME STATUS Received Status Monitoring from MODULE_1 'Property A' = some_value_1
36637 2016-08-25 17:59:... | 1 | 2016-09-10T00:26:22Z | 39,423,193 | <p>In order to understand groups in pandas you should check out <a href="http://pandas.pydata.org/pandas-docs/stable/groupby.html#groupby-object-attributes" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/groupby.html#groupby-object-attributes</a>. Another way to get some insight into the groups is to simply... | 1 | 2016-09-10T06:17:13Z | [
"python",
"pandas",
"reduction"
] |
Pandas data reduction and merging | 39,421,350 | <p>I am working with a Pandas (version 0.17.1) DataFrame that looks like this:</p>
<pre><code> time type module msg_type content
36636 2016-08-25 17:59:50.051 INFO MOD_1_NAME STATUS Received Status Monitoring from MODULE_1 'Property A' = some_value_1
36637 2016-08-25 17:59:... | 1 | 2016-09-10T00:26:22Z | 39,434,386 | <pre><code>pv = df.set_index(['time', 'type', 'module', 'msg_type']) \
.content.str.extract(r"'(?P<prop>.+)' = (?P<val>.+)", expand=True)
pv.groupby(level=[0, 2]).apply(lambda df: df.set_index('prop').val.to_dict())
</code></pre>
<hr>
<pre><code>2016-08-25 17:59:50.051,MOD_1_NAME,"{'Property A': '... | 2 | 2016-09-11T08:50:39Z | [
"python",
"pandas",
"reduction"
] |
Updating a dictionary with integer keys | 39,421,366 | <p>I'm working on a short assignment where I have to read in a .txt file and create a dictionary in which the keys are the number of words in a sentence and the values are the number of sentences of a particular length. I've read in the file and determined the length of each sentence already, but I'm having troubles c... | 2 | 2016-09-10T00:28:53Z | 39,421,396 | <p><code>defaultdicts</code> were invented for this purpose:</p>
<pre><code>from collections import defaultdict
sDict = defaultdict(int)
for snt in sentences:
sDict[len(snt.split())] += 1
</code></pre>
<p>If you are restricted to the use of pure dictionaries in the context of your assignment, then you need to te... | 2 | 2016-09-10T00:35:57Z | [
"python",
"dictionary"
] |
Updating a dictionary with integer keys | 39,421,366 | <p>I'm working on a short assignment where I have to read in a .txt file and create a dictionary in which the keys are the number of words in a sentence and the values are the number of sentences of a particular length. I've read in the file and determined the length of each sentence already, but I'm having troubles c... | 2 | 2016-09-10T00:28:53Z | 39,421,407 | <p>When you initialize the dictionary, it starts out empty. The next thing you do is look up a key so that you can update its value, but that key doesn't exist yet, because the dictionary is empty. The smallest change to your code is probably to use the <code>get</code> dictionary method. Instead of this:</p>
<pre><co... | 2 | 2016-09-10T00:37:47Z | [
"python",
"dictionary"
] |
row to columns while keeping part of dataframe, display on same row | 39,421,384 | <p>I am trying to move some of my rows and make the them columns, but keep a large portion of the dataframe the same.</p>
<p>Resulting Dataframe:</p>
<pre><code>ID Thing Level1 Level2 Time OAttribute IsTrue Score Value
1 bicycle value value 9:30 whatever yes 1 type1
1 bicycle value value... | 0 | 2016-09-10T00:34:00Z | 39,421,426 | <p>Can't really tell what you're trying to do with both of your Score and Value columns at the same time. </p>
<p>But if you're looking to transform your "Value" column, you're looking for something like one-hot encoding of your "Value" column and pandas has a very convenient function for it. All you have to do is:</p... | 0 | 2016-09-10T00:43:11Z | [
"python",
"pandas",
"dataframe"
] |
row to columns while keeping part of dataframe, display on same row | 39,421,384 | <p>I am trying to move some of my rows and make the them columns, but keep a large portion of the dataframe the same.</p>
<p>Resulting Dataframe:</p>
<pre><code>ID Thing Level1 Level2 Time OAttribute IsTrue Score Value
1 bicycle value value 9:30 whatever yes 1 type1
1 bicycle value value... | 0 | 2016-09-10T00:34:00Z | 39,422,548 | <p>One way would be to create an intermediate dataframe and then use outer merge.</p>
<pre><code>In [102]: df
Out[102]:
ID Thing Level1 Level2 Time OAttribute IsTrue Score Value
0 1 bicycle value value 9:30 whatever yes 1.0 type1
1 1 bicycle value value 9:30 whatever yes 2.0 typ... | 1 | 2016-09-10T04:26:02Z | [
"python",
"pandas",
"dataframe"
] |
Efficient way to find null values in a dataframe | 39,421,433 | <pre><code>import pandas as pd
import numpy as np
df = pd.read_csv ('file',low_memory=False)
df_null = df.isnull()
mask = (df_null == True)
i, j = np.where(mask)
print (list(zip(df_null.columns[j], df['Column1'][i])))
</code></pre>
<p>This is what I currently have. Essentially, I've created two dataframes and from t... | 0 | 2016-09-10T00:44:22Z | 39,422,625 | <p>A routine that I normally use in pandas to identify null counts by columns is the following:</p>
<pre class="lang-py prettyprint-override"><code>import pandas as pd
df = pd.read_csv("test.csv")
null_counts = df.isnull().sum()
null_counts[null_counts > 0].sort_values(ascending=False)
</code></pre>
<p>This will... | 0 | 2016-09-10T04:40:38Z | [
"python",
"pandas",
"numpy"
] |
How can I solve this ParseError related to Odoo 9? | 39,421,437 | <p>I'm new to odoo and I'm trying to build a module using the documentation of odoo 9.</p>
<p>I have already created the module and I have installed it, but when I want to add the xml file, an error occurs, especially when I add the line 'views/openacademy.xml' to the <strong>openerp</strong>.py :</p>
<pre><code>Pars... | 0 | 2016-09-10T00:45:07Z | 39,421,699 | <p>I think it is complaining about how you reference tree,form views. However you have not defined any. Define a tree and form view above the code you have.</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="course_tree_view">
<... | 0 | 2016-09-10T01:41:45Z | [
"python",
"xml",
"odoo-9",
"parse-error"
] |
Jupyter (iPython) notebook says "cannot find a kernel matching Python [Root]" | 39,421,564 | <p>I'm interested in using Jupyter notebooks with both Python 2 and Python 3 (one of my colleagues insists on still using Python 2 ;) ).</p>
<p>So I diligently followed the steps listed in this excellent answer: <a href="http://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebo... | 0 | 2016-09-10T01:12:37Z | 39,471,893 | <p>I have not had time to fully digest the answer in the post you reference: <a href="http://stackoverflow.com/questions/30492623/using-both-python-2-x-and-python-3-x-in-ipython-notebook">Using both Python 2.x and Python 3.x in IPython Notebook</a> -- but if what you currently have isn't working properly then what I wo... | 0 | 2016-09-13T13:55:11Z | [
"python",
"ipython",
"anaconda",
"jupyter-notebook"
] |
Plotting Grouped Datetime - Pandas | 39,421,569 | <p>This post is sort of long, so here's the ultimate "ask" upfront:</p>
<p><strong>Is there a way to transform the x-axis/index of the resulting <code>groupby</code> or a way to pass other types of arguments to the <code>axvspan</code> function?</strong></p>
<p>I have a <code>DataFrame</code> with a datetime column, ... | 3 | 2016-09-10T01:13:32Z | 39,422,025 | <p>Okay, I dusted off the ole <a href="http://rads.stackoverflow.com/amzn/click/1449319793" rel="nofollow">Python for Data Analysis</a> copy and re-discovered the <code>resample</code> method, and how well <code>pandas</code> handles time series data in general. The code below did the trick (sticking with my original d... | 0 | 2016-09-10T02:46:19Z | [
"python",
"datetime",
"pandas",
"matplotlib"
] |
How to send a POST request to a .php page in python | 39,421,621 | <p>Context:
So I'm trying to build a python program that will send a POST request to a specific .php file, and return the output. I've done a little bit of research, and this is the code I have so far:</p>
<pre><code>def ForcePush():
params = urllib.urlencode({'log': 'admin', 'pwd':'password'})
headers = {"Content-t... | 2 | 2016-09-10T01:25:58Z | 39,422,476 | <p>As you see from exception, you have connection-related error (on opening socket), so obviously host/port you're using in request is wrong, or inaccessible from python environment (and obviously from system) for some reason.</p>
<p>To debug try to get same page with curl or wget (even with GET method).
<code>curl ht... | 0 | 2016-09-10T04:13:22Z | [
"python",
"python-2.7"
] |
Find substring between / and \ | 39,421,672 | <p>After <a href="http://stackoverflow.com/questions/39420685/get-a-list-of-subdirectories">Get a list of subdirectories</a>, I got strings of that form:</p>
<pre><code>In [30]: print(subdir)
foousa 0 2016-09-07 19:58 /projects/foousa/obama/trump/10973689-Parthenon
drwx------ -
</code></pre>
<p>and when ... | 1 | 2016-09-10T01:35:48Z | 39,421,827 | <p><strong>Using <code>re</code></strong>:</p>
<pre><code>import re
subdir = ' foousa 0 2016-09-07 19:58 /projects/foousa/obama/trump/10973689-Parthenon\ndrwx------ - '
match = re.search(r'/([^/\n]+)\n', subdir)
print(match.group(1))
</code></pre>
<p><strong>Using indexes:</strong></p>
<pre><code>subdir ... | 1 | 2016-09-10T02:07:06Z | [
"python",
"linux",
"string",
"apache-spark",
"substring"
] |
Why use regex finditer() rather than findall() | 39,421,746 | <p>What is the advantage of using <code>finditer()</code> if <code>findall()</code> is good enough?
<code>findall()</code> returns all of the matches while <code>finditer()</code> returns match object which can't be processed as directly as a static list.</p>
<p>For example:</p>
<pre><code>import re
CARRIS_REGEX = (r... | 1 | 2016-09-10T01:50:29Z | 39,421,785 | <p>Sometimes it's superfluous to retrieve all matches. If the number of matches is really high you could risk filling up your memory loading them all.</p>
<p>Using iterators or generators is an important concept in modern python. That being said, if you have a small text (e.g this web page) the optimization is minuscu... | 1 | 2016-09-10T01:56:36Z | [
"python",
"regex",
"match",
"string-matching",
"iterable"
] |
Why use regex finditer() rather than findall() | 39,421,746 | <p>What is the advantage of using <code>finditer()</code> if <code>findall()</code> is good enough?
<code>findall()</code> returns all of the matches while <code>finditer()</code> returns match object which can't be processed as directly as a static list.</p>
<p>For example:</p>
<pre><code>import re
CARRIS_REGEX = (r... | 1 | 2016-09-10T01:50:29Z | 39,421,829 | <p><code>finditer()</code> returns an iterator while <code>findall()</code> returns an array. An iterator only does work when you ask it to by calling <code>.next()</code>. A for loop knows to call <code>.next()</code> on iterators, meaning if you <code>break</code> from the loop early, any following matches won't be p... | 2 | 2016-09-10T02:07:28Z | [
"python",
"regex",
"match",
"string-matching",
"iterable"
] |
Why does my python script break after compiling? | 39,421,911 | <p>I'm checking out how much of a performance increase I get after compiling a python script. After research looking into this issue I don't think I will actually see an increase in performance with the script I have written because I found out that once the script is loaded, the execution time doesn't increase. I stil... | 1 | 2016-09-10T02:23:23Z | 39,422,047 | <p>It appears my issue is the <code>./testcpython-35.pyc</code> part. When I run <code>python3 testcpython-35.pyc</code>, independent on whether I did <code>chmod +x ./testcpython-35.pyc</code>, the output is scrabbled. As long as I run the compiled program by first specifying what program to run it with, <code>python3... | 1 | 2016-09-10T02:52:27Z | [
"python",
"python-3.x"
] |
How to download image from site with no clear extention? | 39,421,924 | <p>I am trying to download an image from the NGA.gov site using python 3 and urllib.</p>
<p>The site does not display images in a standard .jpg fashion and i get an error.</p>
<pre><code>import urllib.request
from bs4 import BeautifulSoup
try:
with urllib.request.urlopen("http://images.nga.gov/?service=asset&am... | 0 | 2016-09-10T02:25:59Z | 39,422,320 | <p>BeautifulSoup is library for html/xml parsing.
On this url you receive image already, so what are you trying to parse?
This works ok: <code>urllib.request.urlretrieve("http://images.nga.gov/?service=asset&action=show_preview&asset=33643" ,"C:\art.jpg")</code></p>
| 1 | 2016-09-10T03:44:49Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
How to download image from site with no clear extention? | 39,421,924 | <p>I am trying to download an image from the NGA.gov site using python 3 and urllib.</p>
<p>The site does not display images in a standard .jpg fashion and i get an error.</p>
<pre><code>import urllib.request
from bs4 import BeautifulSoup
try:
with urllib.request.urlopen("http://images.nga.gov/?service=asset&am... | 0 | 2016-09-10T02:25:59Z | 39,422,373 | <p>There is no need to use BeautifulSoup! Just do:</p>
<pre><code>with urllib.request.urlopen("http://images.nga.gov/?service=asset&action=show_preview&asset=33643") as url:
s = url.read()
with open("art.jpg", 'wb') as fp:
fp.write(url.read())
</code></pre>
| 0 | 2016-09-10T03:53:45Z | [
"python",
"web-scraping",
"beautifulsoup"
] |
Values printed are different when debugging | 39,421,948 | <pre><code>cnt = 0
s = 'aghe'
s_len = len(s)
s_len = s_len - 1
while s_len >= 0:
if s[s_len] in ('aeiou'):
cnt += 1
s_len -= 1
break;
print ('numofVowels:'),cnt
</code></pre>
<p>This does print the value of <code>cnt</code>. When debugging, <code>cnt</code> has the correct value!</p>
| -5 | 2016-09-10T02:31:01Z | 39,422,016 | <p>You will want to get rid of the <code>break</code>, and make sure to include <code>cnt</code> inside the parentheses for your <code>print</code> call (having it outside the parentheses will cause it not to print in Python 3):</p>
<pre><code>cnt = 0
s = 'aghe'
s_len = len(s)
s_len = s_len - 1
while s_len >= 0:
... | 0 | 2016-09-10T02:44:06Z | [
"python"
] |
Concatenate OR conditional expressions from list to "|" | 39,421,967 | <p>This probably is a python lang related question, not precisely of boto3 lib:</p>
<p>That query works:</p>
<pre><code>matches = table.query(
IndexName="status-date-index",
KeyConditionExpression=Key('status').eq('next'),
FilterExpression=Attr('teams').contains('a') | Attr('teams').contains('b') | Attr('... | 0 | 2016-09-10T02:34:41Z | 39,422,244 | <pre><code>import operator
filter_exp = reduce(operator.or_, (Attr('teams').contains(x) for x in 'abc'))
</code></pre>
| 0 | 2016-09-10T03:30:40Z | [
"python",
"amazon-dynamodb"
] |
Concatenate OR conditional expressions from list to "|" | 39,421,967 | <p>This probably is a python lang related question, not precisely of boto3 lib:</p>
<p>That query works:</p>
<pre><code>matches = table.query(
IndexName="status-date-index",
KeyConditionExpression=Key('status').eq('next'),
FilterExpression=Attr('teams').contains('a') | Attr('teams').contains('b') | Attr('... | 0 | 2016-09-10T02:34:41Z | 39,422,255 | <p>You can use <a href="https://docs.python.org/library/functools.html#functools.reduce" rel="nofollow"><code>functools.reduce</code></a> on the list of items produced by <code>contains</code> (which I assume to be of type <code>ConditionBase</code>), with the <a href="https://docs.python.org/2/library/operator.html#op... | 1 | 2016-09-10T03:33:18Z | [
"python",
"amazon-dynamodb"
] |
Threads not being executed under supervisord | 39,421,985 | <p>I am working on a basic crawler which crawls 5 websites concurrently using threads.
For each site it creates a new thread. When I run the program from the shell then the output log indicates that all the 5 threads run as expected.
But when I run this program as a <a href="http://supervisord.org/" rel="nofollow">supe... | 0 | 2016-09-10T02:37:08Z | 39,422,031 | <p>AFAIK python threads can't do threads properly because it is not thread safe. It just gives you a facility to simulate simultaneous run of the code. Your code will still use 1 core only.</p>
<p><a href="https://wiki.python.org/moin/GlobalInterpreterLock" rel="nofollow">https://wiki.python.org/moin/GlobalInterpreter... | 0 | 2016-09-10T02:47:28Z | [
"python",
"multithreading",
"supervisord"
] |
Slow printing - still need answers | 39,422,027 | <p>This topic has already been covered but I am still having trouble. The code I have does print the string but it prints it extremely fast. I have tried changing the time value but it doesn't seem to change anything.</p>
<p>Here is <em>everything</em> I have - Maybe I just need a more complete example?</p>
<pre><cod... | 0 | 2016-09-10T02:46:32Z | 39,422,081 | <pre><code>import sys,time,random
typing_speed = 50 #wpm
def slowprint(t):
for l in t:
sys.stdout.write(l)
sys.stdout.flush() # Forcing the output of everything in the buffer.
time.sleep(random.random()*10.0/typing_speed)
sys.stdout.write("\n") # Printing a newline, because it looks ... | 3 | 2016-09-10T03:00:12Z | [
"python",
"python-2.7"
] |
Slow printing - still need answers | 39,422,027 | <p>This topic has already been covered but I am still having trouble. The code I have does print the string but it prints it extremely fast. I have tried changing the time value but it doesn't seem to change anything.</p>
<p>Here is <em>everything</em> I have - Maybe I just need a more complete example?</p>
<pre><cod... | 0 | 2016-09-10T02:46:32Z | 39,440,255 | <p>My problem with the existing solution(s) is I don't see how the code coerces the output to the stated WPM except by trial and error:</p>
<pre><code>time.sleep(random.random()*10.0/typing_speed)
</code></pre>
<p>and seems to get it wrong, time-wise, by more than 2X too fast.</p>
<p>If instead we use the standard d... | 0 | 2016-09-11T20:17:38Z | [
"python",
"python-2.7"
] |
Removing round brackets from a dataframe of lat/lon pairs | 39,422,043 | <p>I'm sure this is a very simple thing to do but I seem to be having trouble! (I am rather new to this too.)</p>
<p>I have a dataframe containing lat long coordinates:</p>
<pre><code> LatLon
0 (49.766795012580374, -7.556440128791576)
1 (49.766843444728075, -7.556439417755133)
2 (49.766843444728075, -7.55643... | 1 | 2016-09-10T02:51:08Z | 39,422,059 | <p>With the updated question, here is the updated answer.</p>
<p>Suppose we have this list of tuples:</p>
<pre><code>>>> li
[(49.766795012580374, -7.556440128791576), (49.766843444728075, -7.556439417755133), (49.766843444728075, -7.556439417755133)]
</code></pre>
<p>We can create a data frame (which, funda... | 1 | 2016-09-10T02:55:03Z | [
"python",
"pandas",
"dataframe"
] |
Error with OMP_NUM_THREADS when using dask distributed | 39,422,092 | <p>I am using <a href="http://distributed.readthedocs.io/en/latest/" rel="nofollow">distributed</a>, a framework to allow parallel computation. In this, my primary use case is with NumPy. When I include NumPy code that relies on <code>np.linalg</code>, I get an error with <code>OMP_NUM_THREADS</code>, which is related ... | 3 | 2016-09-10T03:01:53Z | 39,425,693 | <h3>Short answer</h3>
<pre><code>export OMP_NUM_THREADS=1
or
dask-worker --nthreads 1
</code></pre>
<h3>Explanation</h3>
<p>The <code>OMP_NUM_THREADS</code> environment variable controls the number of threads that many libraries, including the <code>BLAS</code> library powering <code>numpy.dot</code>, use in thei... | 2 | 2016-09-10T11:43:13Z | [
"python",
"numpy",
"cluster-computing",
"dask"
] |
Pandas - make a large DataFrame into several small DataFrames and run each through a function | 39,422,106 | <p>I have a huge dataset with about 60000 data. I would first use some criteria to do groupby on the whole dataset, and what I want to do next is to separate the whole dataset to many small datasets within the criteria and to run a function to each of the small dataset automatically to get a parameter for each small da... | 1 | 2016-09-10T03:04:57Z | 39,422,211 | <p>Unless your function is really slow, this can probably be accomplished by slicing (e.g. <code>df_small = df[a:b]</code> for some indices a and b). The only trick is to choose a and b. I use <code>range</code> in the code below but you could do it other ways:</p>
<pre><code>param_list = []
n = 10000 #size of smaller... | 0 | 2016-09-10T03:24:36Z | [
"python",
"pandas"
] |
Pandas - make a large DataFrame into several small DataFrames and run each through a function | 39,422,106 | <p>I have a huge dataset with about 60000 data. I would first use some criteria to do groupby on the whole dataset, and what I want to do next is to separate the whole dataset to many small datasets within the criteria and to run a function to each of the small dataset automatically to get a parameter for each small da... | 1 | 2016-09-10T03:04:57Z | 39,422,526 | <p>I think a more efficient way than filtering the original data set using subsetting is <code>groupby()</code>, as a demo:</p>
<pre><code>for _, g in df.groupby('name'):
print(g)
# Date name number
#0 20100101 John 1
#3 20100103 John 3
#4 20100104 John 1
# Date name number... | 1 | 2016-09-10T04:21:11Z | [
"python",
"pandas"
] |
python comprehension trubleshooting | 39,422,290 | <pre><code>base=2
digits=set(range(base))
key=range(base**3)
dict={ k:[a,b,c] for k in key for a in digits for b in digits for c in digits}
print(dict)
</code></pre>
<p>the output is:</p>
<pre><code>{0: [1, 1, 1], 1: [1, 1, 1], 2: [1, 1, 1], 3: [1, 1, 1], 4: [1, 1, 1], 5: [1, 1, 1], 6: [1, 1, 1], 7: [1, 1, 1]}
</cod... | -1 | 2016-09-10T03:39:58Z | 39,422,410 | <p>We can simplify the dictionary comprehension to something like:</p>
<pre><code>In [728]: {k:[a,b] for k in [1,2] for a in [1,2] for b in [1,2]}
Out[728]: {1: [2, 2], 2: [2, 2]}
</code></pre>
<p>It is the equivalent to constructing a dictionary with nested loops:</p>
<pre><code>In [731]: d={}
In [732]: for k in [1... | 1 | 2016-09-10T04:00:35Z | [
"python",
"list-comprehension"
] |
Creating a startup service for python script to run as root in Arch Linux | 39,422,298 | <p>I have a python script that I want to run on start up as root. I believe that I need to add it as a service file but I don't know if it has root permission. This is how i have my service file. The python file wont run unless in root.</p>
<pre><code>[Unit]
Description= Description here
[Service]
Type=simple
ExecSta... | 1 | 2016-09-10T03:40:46Z | 39,422,419 | <p>Systemd runs multi-user services as root, so I don't see what help do you need.</p>
| 0 | 2016-09-10T04:01:47Z | [
"python",
"linux",
"root",
"startup"
] |
Creating a startup service for python script to run as root in Arch Linux | 39,422,298 | <p>I have a python script that I want to run on start up as root. I believe that I need to add it as a service file but I don't know if it has root permission. This is how i have my service file. The python file wont run unless in root.</p>
<pre><code>[Unit]
Description= Description here
[Service]
Type=simple
ExecSta... | 1 | 2016-09-10T03:40:46Z | 39,424,821 | <p>Got it to work. After I removed the root check from my python script everything worked fine, i also removed the <code>Type=simple</code> part from the service file. After those two things it worked fine.</p>
<p>the root check part i removed was.</p>
<pre><code>from os import getenv
user = getenv("SUDO_USER")
if us... | 0 | 2016-09-10T09:48:59Z | [
"python",
"linux",
"root",
"startup"
] |
Jinja2 how to perform advanced slicing | 39,422,474 | <p>I've got a list, "foos" and if I've got more than 5 "foos" I want to do something specific to the first 2, and then something specific for the rest.</p>
<p>So I kinda want something like this in HTML:</p>
<pre><code><div id="accordion">
<p>Foo1<p>
<p>Foo2<p>
<div id="co... | 2 | 2016-09-10T04:12:37Z | 39,422,487 | <p>You could build, or find, a filter to pre-slice your <code>foos</code> list ahead of the for loop.</p>
<pre><code>{% for f in foos|slice:"0:10:2" %}
</code></pre>
<p>You could move most of your template looping logic into the filter itself or go the easy route and use existing slice notation on a list:</p>
<pre><... | 1 | 2016-09-10T04:15:18Z | [
"python",
"templates",
"flask",
"jinja2"
] |
How to get all comments of a facebook post using facebook SDK in Python? | 39,422,562 | <p>I want to get all comments of a facebook post. We can extract comments by passing the <code>limit()</code> in Api call But how we know the limit? I need all comments. </p>
<pre><code>https://graph.facebook.com/10153608167431961?fields=comments.limit(100).summary(true)&access_token=LMN
</code></pre>
<p>By us... | 1 | 2016-09-10T04:29:42Z | 39,424,273 | <p>You need to implement paging to get all/more comments: <a href="https://developers.facebook.com/docs/graph-api/using-graph-api/#paging" rel="nofollow">https://developers.facebook.com/docs/graph-api/using-graph-api/#paging</a></p>
<p>Usually, this is done with a "recursive function", but you have to keep in mind tha... | 0 | 2016-09-10T08:40:59Z | [
"python",
"facebook",
"facebook-graph-api",
"recursion"
] |
How to nest or jointly use two template tags in Django templates? | 39,422,570 | <p>I'm trying to use template filters to do run a loop, but I'm unable to combine two python statements within the same statement/template. Whats the correct way to combine two variables in a template? Please see the syntax and explanation below:</p>
<p>I'm building a forum with a double index, meaning, I've got a col... | 0 | 2016-09-10T04:31:08Z | 39,422,811 | <p>So you must first properly register template tag.</p>
<pre><code>from django import template
from pybb.models import Forum
register = template.Library()
@register.filter
def forumindexlistbycat(category):
forumlistbycat = Forum.objects.filter(category=category)
return forumlistbycat
</code></pre>
<p>Plac... | 2 | 2016-09-10T05:09:26Z | [
"python",
"django",
"django-templates",
"django-template-filters",
"templatetags"
] |
Python Writing Weird Unicode to CSV | 39,422,573 | <p>I'm attempting to extract article information using the python <a href="https://github.com/codelucas/newspaper" rel="nofollow">newspaper3k</a> package and then write to a CSV file. While the info is downloaded correctly, I'm having issues with the output to CSV. I don't think I fully understand unicode, despite my e... | 0 | 2016-09-10T04:31:39Z | 39,423,498 | <p>That's most probably a problem with the software that you use to open or print the CSV file - it doesn't "understand" that CSV is encoded in UTF-8 and assumes ASCII, latin-1, ISO-8859-1 or a similar encoding for it.</p>
<p>You can aid that software in recognizing the CSV file's encoding by <a href="http://stackover... | 1 | 2016-09-10T06:59:10Z | [
"python",
"csv",
"unicode"
] |
Python Writing Weird Unicode to CSV | 39,422,573 | <p>I'm attempting to extract article information using the python <a href="https://github.com/codelucas/newspaper" rel="nofollow">newspaper3k</a> package and then write to a CSV file. While the info is downloaded correctly, I'm having issues with the output to CSV. I don't think I fully understand unicode, despite my e... | 0 | 2016-09-10T04:31:39Z | 39,427,362 | <p>Use encoding <code>utf-8-sig</code>. Excel requires the BOM to interpret UTF8; otherwise, it assumes the default localized encoding. </p>
| 1 | 2016-09-10T15:05:27Z | [
"python",
"csv",
"unicode"
] |
Python Writing Weird Unicode to CSV | 39,422,573 | <p>I'm attempting to extract article information using the python <a href="https://github.com/codelucas/newspaper" rel="nofollow">newspaper3k</a> package and then write to a CSV file. While the info is downloaded correctly, I'm having issues with the output to CSV. I don't think I fully understand unicode, despite my e... | 0 | 2016-09-10T04:31:39Z | 39,429,388 | <p>Changing <code>with open('bloombergtest.csv', 'w', encoding='utf-8') as output_file:</code> to <code>with open('bloombergtest.csv', 'w', encoding='utf-8-sig') as output_file:</code>, worked, as recommended by Leon and Mark Tolonen. </p>
| 0 | 2016-09-10T18:40:17Z | [
"python",
"csv",
"unicode"
] |
can't print the value of json object in django | 39,422,633 | <p>I have this json object in ajax_data variable</p>
<pre><code>{
"columns[0][data]": "0",
"columns[1][name]": "",
"columns[5][searchable]": "true",
"columns[5][name]": "",
"columns[4][search][regex]": "false",
"order[0][dir]": "asc",
"length": "10",
}
</code></pre>
<p>I have conver... | 0 | 2016-09-10T04:42:01Z | 39,422,656 | <p>That's because <code>length</code> is a key in that json object, and <code>order</code> is not. The key names are the <em>entire</em> strings inside the quotes: <code>columns[0][data]</code>, <code>order[0][dir]</code>, etc.</p>
<p>Those are unusual key names, but perfectly valid.</p>
| 0 | 2016-09-10T04:46:30Z | [
"python",
"django"
] |
can't print the value of json object in django | 39,422,633 | <p>I have this json object in ajax_data variable</p>
<pre><code>{
"columns[0][data]": "0",
"columns[1][name]": "",
"columns[5][searchable]": "true",
"columns[5][name]": "",
"columns[4][search][regex]": "false",
"order[0][dir]": "asc",
"length": "10",
}
</code></pre>
<p>I have conver... | 0 | 2016-09-10T04:42:01Z | 39,422,725 | <p>The keys you have used are actually not a good way of implementation. </p>
<pre><code>{
"columns[0][data]": "0",
"columns[1][name]": "",
"columns[5][searchable]": "true",
"columns[5][name]": "",
"columns[4][search][regex]": "false",
"order[0][dir]": "asc",
"length": "10",
}
</code... | 1 | 2016-09-10T04:56:37Z | [
"python",
"django"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,750 | <p>Since you are looping through a list of simple items and trying to find if <a href="https://docs.python.org/2/library/functions.html#all" rel="nofollow"><code>all</code></a> of the functions has <a href="https://docs.python.org/2/library/functions.html#any" rel="nofollow"><code>any</code></a> valid results, you can ... | 1 | 2016-09-10T04:59:40Z | [
"python",
"list",
"loops"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,752 | <p>You can use <a href="http://stackoverflow.com/questions/546337/how-do-i-perform-introspection-on-an-object-in-python-2-x" title="introspection">introspection</a> to loop through all of an object's attributes, whether they be functions or some other type.</p>
<p>However you probably don't want to do that here, becau... | 1 | 2016-09-10T04:59:51Z | [
"python",
"list",
"loops"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,759 | <p>To answer the original question:</p>
<pre><code>raw = 'asdfa3fa'
functions = [str.isalnum, str.isalpha, str.isdigit, str.islower, str.isupper]
isanything = [func(raw) for func in functions]
print repr(isanything)
</code></pre>
| 2 | 2016-09-10T05:01:21Z | [
"python",
"list",
"loops"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,761 | <p>The way you are looping through a list of functions is slightly off. This would be a valid way to do it. The functions you need to store in the list are the generic string functions given by str.funcname. Once you have those list of functions, you can loop through them using a for loop, and just treat it like a norm... | 4 | 2016-09-10T05:01:32Z | [
"python",
"list",
"loops"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,813 | <p>Okay, so the first question is easy enough. The simple way to do it is just do</p>
<pre><code>def foo(raw):
for c in raw:
if c.isalpha(): return True
if c.isdigit(): return True
# the other cases
return False
</code></pre>
<p>Never neglect the simplest thing that could work.</p>
<p>Now, if you wan... | 2 | 2016-09-10T05:09:43Z | [
"python",
"list",
"loops"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,839 | <p>All the other answers are correct, but since you're a beginner, I want to point out the problem in your code:</p>
<pre><code>lst = [raw[i].isalnum(),raw[i].isalpha(),raw[i].isdigit(),raw[i].islower(),raw[i].isupper()]
</code></pre>
<p>First: Not sure which value <em>i</em> currently has in your code snipped, but i... | 2 | 2016-09-10T05:16:56Z | [
"python",
"list",
"loops"
] |
Looping through list of functions in a function in Python dynamically | 39,422,641 | <p>I'd like to see if it's possible to run through a list of functions in a function. The closest thing I could find is looping through an entire module. I only want to use a pre-selected list of functions.</p>
<p>Here's my original problem:</p>
<ol>
<li>Given a string, check each letter to see if any of the 5 tests ... | 5 | 2016-09-10T04:42:56Z | 39,422,846 | <p>I'm going to guess that you're validating password complexity, and I'm also going to say that software which takes an input and says "False" and there's no indication <em>why</em> is user-hostile, so the most important thing is not "how to loop over nested char function code wizardry (*)" but "give good feedback", a... | 2 | 2016-09-10T05:17:51Z | [
"python",
"list",
"loops"
] |
Write to last line of file in python | 39,422,699 | <p>I wanna save some string on a file that i called inv.data. Every time i write a special command, I want to save a string in the file. The string should be at the last line in the file all times.
I read something about append, so I tried to do something like this:</p>
<pre><code>#Open and close the inventroy file
fi... | 0 | 2016-09-10T04:53:29Z | 39,422,751 | <p>New line is not getting added and hence the next entry is appended in the same line. You ca rectify this as follows:</p>
<pre><code>fileOpen.write(argOne + '\n')
</code></pre>
<p>This way you don't have to modify the way you input your arguments.</p>
| 4 | 2016-09-10T04:59:46Z | [
"python",
"python-3.x"
] |
Django Settings for Rendering static images from Google Cloud storage | 39,422,723 | <p>I have my Django App hosted on Google Compute Engine. I wish to render static elements of the App from Google Cloud Storage. I have all the static elements inside Google Cloud storage bucket www.example.com/static</p>
<p>My Settings.py:</p>
<pre><code># Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/... | 0 | 2016-09-10T04:56:34Z | 39,601,225 | <p>While this isn't a Django-based answer, since I know little about that, you may find the Alpha release of <a href="https://cloud.google.com/compute/docs/load-balancing/http/using-http-lb-with-cloud-storage" rel="nofollow">Google Cloud Load Balancer support for Google Cloud Storage</a> another route to provide URL ma... | 0 | 2016-09-20T18:24:40Z | [
"python",
"django",
"google-cloud-storage",
"google-compute-engine",
"django-staticfiles"
] |
Django Settings for Rendering static images from Google Cloud storage | 39,422,723 | <p>I have my Django App hosted on Google Compute Engine. I wish to render static elements of the App from Google Cloud Storage. I have all the static elements inside Google Cloud storage bucket www.example.com/static</p>
<p>My Settings.py:</p>
<pre><code># Static files (CSS, JavaScript, Images)
STATIC_URL = '/static/... | 0 | 2016-09-10T04:56:34Z | 39,809,861 | <p>You can find some documentation
<a href="https://cloud.google.com/python/django/flexible-environment#deploy_the_app_to_the_app_engine_flexible_environment" rel="nofollow" >here</a>
</p>
<p>One more thing i found useful is automatically switching between dev and prod environments by doing to following ... | 0 | 2016-10-01T18:04:09Z | [
"python",
"django",
"google-cloud-storage",
"google-compute-engine",
"django-staticfiles"
] |
For Loop is not Following Indentations | 39,422,791 | <p>Afternoon all,</p>
<p>I'm encountering some strange behavior from the starred for loop below. The below function essentially iterates over the input dictionary <code>patient_features</code>, concatenating several strings to produce a SVMLight style vector. This vector is then intended to be written to the deliverab... | 0 | 2016-09-10T05:04:59Z | 39,422,887 | <p>The issue is with using both indentations and tabs in your code. Python is not a fan if you mix the two :/</p>
<p>For future reference, if you are using Sublime Text, select all the text, and in the toolbar on top go to <code>View > Indentation > Convert Tabs to Spaces</code> and the issue will be resolved. <... | 0 | 2016-09-10T05:26:44Z | [
"python",
"python-2.7",
"for-loop"
] |
Get number of tweets per min for particular channel | 39,422,946 | <p>I am using <a href="https://github.com/geduldig/TwitterAPI" rel="nofollow">pypi Twitter API</a></p>
<p>I need to call twitter API to get tweets of one channel after certain interval. I need tweet counts in that time period. </p>
<p>For ex. @NASA channel tweet counts of it every 5 mins. </p>
<p>I am looking at <a ... | 4 | 2016-09-10T05:37:25Z | 39,423,088 | <p>Use twitter's API. I mean, right?</p>
<p><a href="https://dev.twitter.com/rest/reference/get/statuses/user_timeline" rel="nofollow">https://dev.twitter.com/rest/reference/get/statuses/user_timeline</a></p>
<p>That will get you the most 3200 recent tweets by a user. So unless those guys are literally more than lik... | 1 | 2016-09-10T05:59:37Z | [
"javascript",
"jquery",
"python",
"django",
"twitter"
] |
Python Git diff parser | 39,423,122 | <p>I would like to parse git diff with Python code and I am interested to get following information from diff parser:</p>
<ol>
<li>Content of deleted/added lines and also line number. </li>
<li>File name.</li>
<li>Status of file whether it is deleted, renamed or added. </li>
</ol>
<p>I am using <a href="https://pypi.... | 0 | 2016-09-10T06:04:16Z | 39,909,397 | <p>Finally, I found the solution. The output of gitpython is little bit different from the standard git diff output. In the standard git diff source file start with <strong>---</strong> but output of gitpython start with <strong>------</strong> as you can see in the out put of running the following python code (this ex... | 0 | 2016-10-07T04:29:09Z | [
"python",
"git",
"parsing",
"gitpython"
] |
Python Facebook SDK: How to get response from request? | 39,423,146 | <p>I am using the following code to publish photo but I don't know how to get response ID post. How to get it ?</p>
<pre><code>import facebook
graph = facebook.GraphAPI(access_token='mytoken', version='2.7')
graph.put_photo(image=open(r'E:\Facebook\myphoto.jpg', 'rb'), message='Cool'.encode('utf-8'))
</code></pre>
... | 0 | 2016-09-10T06:08:14Z | 39,423,387 | <p>According to the documentation <a href="http://facebook-sdk.readthedocs.io/en/latest/api.html#put-photo" rel="nofollow"><code>put_photo()</code></a> should return JSON containing the ID and the post ID, however, it actually returns a dictionary, i.e the JSON has been decoded for you. Try this:</p>
<pre><code>import... | 1 | 2016-09-10T06:45:26Z | [
"python",
"facebook",
"facebook-graph-api"
] |
to convert a MCQ in the required format - python | 39,423,212 | <p>I am trying to convert MCQ which is as follows:</p>
<pre><code>Which will legally declare, construct, and initialize an array?
A. int [] myList = {"1", "2", "3"};
B. int [] myList = (5, 8, 2);
C. int myList [] [] = {4,9,7,0};
D. int myList [] = {4, 3, 7};
ANSWER: D
</code></pre>
<p>into the required format which i... | 3 | 2016-09-10T06:19:27Z | 39,424,334 | <p>You could use the following code: reading from a file, doing required modifications and writing them into a new text file.</p>
<pre><code>import re
with open("your_filename_here", "r") as fp:
string = fp.read()
f1 = open(r"your_filename_here", "w")
rx = re.compile(r'''
(?!^[A-E]\.)
... | 1 | 2016-09-10T08:50:28Z | [
"python",
"regex",
"file"
] |
Comparing by section two numpy arrays in python | 39,423,331 | <p>I want to do a comparison between the two arrays by section.
so far I have to get results for all arrays.</p>
<pre><code>import numpy as np
array1 = np.array(list(np.zeros(20))+(list(np.ones(20)))+(list(2*np.ones(20))))
array2 = np.array(list(np.ones(20))+(list(np.ones(20)))+(list(3*np.ones(20))))
result = np.sum(a... | 3 | 2016-09-10T06:37:37Z | 39,423,368 | <p>Just sum each 20 separately:</p>
<pre><code>matches = array1 == array2
print 'first 20: {}'.format(matches[:20].sum())
print 'second 20: {}'.format(matches[20:40].sum())
print 'third 20: {}'.format(matches[40:60].sum())
</code></pre>
<p><code>np.sum(x)</code> is usually equivalent to <code>x.sum()</code></p>
| 1 | 2016-09-10T06:43:22Z | [
"python",
"arrays",
"python-2.7",
"numpy"
] |
Comparing by section two numpy arrays in python | 39,423,331 | <p>I want to do a comparison between the two arrays by section.
so far I have to get results for all arrays.</p>
<pre><code>import numpy as np
array1 = np.array(list(np.zeros(20))+(list(np.ones(20)))+(list(2*np.ones(20))))
array2 = np.array(list(np.ones(20))+(list(np.ones(20)))+(list(3*np.ones(20))))
result = np.sum(a... | 3 | 2016-09-10T06:37:37Z | 39,423,381 | <p>First off, let's get the mask of comparisons -</p>
<pre><code>mask = array1 == array2
</code></pre>
<p>Then, to get all sum -</p>
<pre><code>allsum = mask.sum()
</code></pre>
<p>And to get sectionwise (of length <code>20</code>) sum -</p>
<pre><code>section_sums = mask.reshape(-1,20).sum(1)
</code></pre>
<p>Sa... | 3 | 2016-09-10T06:45:05Z | [
"python",
"arrays",
"python-2.7",
"numpy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.