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 |
|---|---|---|---|---|---|---|---|---|---|
Why does running a submodule (python -m a.c) also import the containing module? | 38,033,337 | <p>Given:</p>
<h1><code>tree</code></h1>
<pre><code>~/dir
â¶ tree
.
âââ a
â  âââ __init__.py
â  âââ c.py
âââ b.py
1 directory, 3 files
</code></pre>
<h1><code>*.py</code> files</h1>
<pre><code>~/dir ... | 2 | 2016-06-25T22:02:02Z | 38,033,400 | <blockquote>
<p>Module a.c has no dependencies on module a. So, why does Python run module a as if it were importing it</p>
</blockquote>
<p><a href="https://docs.python.org/3/reference/import.html#regular-packages" rel="nofollow">From the documentation</a>:</p>
<blockquote>
<blockquote>
<p>Importing parent.o... | 1 | 2016-06-25T22:11:16Z | [
"python"
] |
Why does running a submodule (python -m a.c) also import the containing module? | 38,033,337 | <p>Given:</p>
<h1><code>tree</code></h1>
<pre><code>~/dir
â¶ tree
.
âââ a
â  âââ __init__.py
â  âââ c.py
âââ b.py
1 directory, 3 files
</code></pre>
<h1><code>*.py</code> files</h1>
<pre><code>~/dir ... | 2 | 2016-06-25T22:02:02Z | 38,033,855 | <blockquote>
<p>Module a.c has no dependencies on module a</p>
</blockquote>
<p>You are confusing a package with a module. </p>
<pre><code>`a` is a package
`c` is a module within package `a`
</code></pre>
<p>There is a dependency: <code>a.c</code> is a member of package <code>a</code>.</p>
<p>Questions about this... | 0 | 2016-06-25T23:30:45Z | [
"python"
] |
How is Python itself tested? | 38,033,339 | <p>How is Python itself tested? Not, "How do I write unit tests in Python?" but "Where is the compliance suite against which CPython, Pypy, and so on run tests to assert they're Python version-X.Y conformant?"</p>
<p>The python website mentions pythontest.net, but that appears to be just a target for test facilities,... | 6 | 2016-06-25T22:02:28Z | 38,033,376 | <p>The CPython source code includes a <a href="https://hg.python.org/cpython/file/2.7/Lib/test" rel="nofollow">test suite</a> that is considered to be the compliance suite. This suite is used to test other Python implementations, see for example:</p>
<ul>
<li>the <a href="https://bitbucket.org/pypy/pypy/src/a0105e0d00... | 3 | 2016-06-25T22:06:44Z | [
"python",
"testing"
] |
Kivy-Python-Android Torch App | 38,033,354 | <p>There is this torch app example available online. It uses a 'Switch' to turn flashlight on. It works. I've been trying/struggling to get a 'message' output on the device when the flashlight is turned on and off and I cannot seem to get the right code. Can anyone provide a hint. Here's the working torch app code (som... | 0 | 2016-06-25T22:04:22Z | 38,033,797 | <p>Switch doesn't have a <code>text</code> property, and due to a quirk of Kivy's argument parsing you don't get an error due to the unused kwarg.</p>
<p>You should instead add a Label with your desired text.</p>
| 1 | 2016-06-25T23:22:00Z | [
"android",
"python",
"kivy",
"flashlight"
] |
Python 3.X jumping to a line of code | 38,033,375 | <p>I'm trying to make a Choose Your Own Adventure game in Python 3.X. I'm using the idle platform. Here is a sample of my code. </p>
<pre><code>import time
again = True
while again == True:
print("You wake up as you normally do, but something's not quite right. What will be the first thing you do? \n Choices:... | 0 | 2016-06-25T22:06:42Z | 38,035,131 | <p>As mentioned, python doesn't support <code>GoTo</code>. One way of achieving the same result is to create a quit game function like below then call it at the end of your main game code.</p>
<pre><code>def quit_game():
playAgain = input("Play again? Y/N: ")
if playAgain == "Y":
return True
el... | 0 | 2016-06-26T04:07:36Z | [
"python",
"python-3.x"
] |
"while True:" loop returns nothing after one cycle | 38,033,383 | <p>Here's the problem: my while loop doesn't repeat AT ALL, it just returns a blank line in the Python Launcher and doesn't carry on the code, i added a print function at the end to check if it did just skip.
I used several ways of getting the code to repeat, such as <code>While True:</code> and <code>While 0 == 0</cod... | 0 | 2016-06-25T22:07:40Z | 38,033,417 | <p>You need to set i to one after "while True", and set input_answer to "unknown" before the second inner loop. Corrected code:</p>
<pre><code>while True:
i = 1
while i <= dice_amount:
dice_output = random.randint(0,dice_range)
print("dice number ", i, " is ", dice_output)
i +=1
input_answer = "unknown"... | 1 | 2016-06-25T22:14:07Z | [
"python",
"loops",
"while-loop",
"python-3.5"
] |
"while True:" loop returns nothing after one cycle | 38,033,383 | <p>Here's the problem: my while loop doesn't repeat AT ALL, it just returns a blank line in the Python Launcher and doesn't carry on the code, i added a print function at the end to check if it did just skip.
I used several ways of getting the code to repeat, such as <code>While True:</code> and <code>While 0 == 0</cod... | 0 | 2016-06-25T22:07:40Z | 38,033,786 | <p>I have finally realized the problem, after reading the other comments and answers I came up with this fix. First of all I realized I didn't need to use the input_answer if none of the answers were Y or N, i just made it a repeating loop and if the were neither Y or N it just repeated the question, Y breaks the loop ... | 0 | 2016-06-25T23:20:06Z | [
"python",
"loops",
"while-loop",
"python-3.5"
] |
Bounding a column in a dataframe | 38,033,388 | <p>I have a dataframe 'dayData' and I'm trying to bound a column 'second_step' in the dataframe (writing the result to a new column called (very originally) 'third_step'). The data looks like:</p>
<pre><code> second_step
0 0.185185
1 0.148148
2 0.148148
3 0
4 0.185185
5 0
6 ... | 0 | 2016-06-25T22:07:59Z | 38,033,487 | <p>I would recommend you to use vectorized functions for that - it should be faster compared to <code>apply()</code> approach:</p>
<pre><code>df['third_tep'] = np.where(np.abs(df.second_step) > 2, np.sign(df.second_step) * 2, df.second_step)
In [43]: df
Out[43]:
second_step third_tep
0 0.185185 0.18518... | 2 | 2016-06-25T22:24:36Z | [
"python",
"pandas"
] |
Bounding a column in a dataframe | 38,033,388 | <p>I have a dataframe 'dayData' and I'm trying to bound a column 'second_step' in the dataframe (writing the result to a new column called (very originally) 'third_step'). The data looks like:</p>
<pre><code> second_step
0 0.185185
1 0.148148
2 0.148148
3 0
4 0.185185
5 0
6 ... | 0 | 2016-06-25T22:07:59Z | 38,033,509 | <p>You can use <code>apply</code></p>
<pre><code>bounded = lambda x: max(min(x, 2), -2)
dayData["third_step"] = dayData.second_step.apply(bounded)
</code></pre>
| 0 | 2016-06-25T22:28:08Z | [
"python",
"pandas"
] |
Bounding a column in a dataframe | 38,033,388 | <p>I have a dataframe 'dayData' and I'm trying to bound a column 'second_step' in the dataframe (writing the result to a new column called (very originally) 'third_step'). The data looks like:</p>
<pre><code> second_step
0 0.185185
1 0.148148
2 0.148148
3 0
4 0.185185
5 0
6 ... | 0 | 2016-06-25T22:07:59Z | 38,036,366 | <p>there is a pandas method to do this, <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.clip.html" rel="nofollow"><code>clip</code></a>:</p>
<pre><code>In [6]:
df['third_step'] = df['second_step'].clip(-.1,.1)
df
Out[6]:
second_step third_step
0 0.185185 0.1
1 0.148... | 0 | 2016-06-26T07:55:01Z | [
"python",
"pandas"
] |
What is the best way to integrate numpy into a meteorjs web app? | 38,033,389 | <p>I've just started to poke around MeteorJS and it looks great. However the app I'm starting to build has a scientific component which i would prefer to implement using numpy/scipy/pandas.</p>
<p>Is there an idiomatic approach to leveraging a computationally intensive (I'm also toying with a separate app using OpenCV... | 1 | 2016-06-25T22:08:26Z | 38,034,792 | <p>I use <a href="https://github.com/vsivsi/meteor-job-collection" rel="nofollow">vsivsi/meteor-job-collection</a> for time intensive tasks. I currently run the workers via <a href="https://github.com/Unitech/pm2" rel="nofollow">pm2</a> on a single server with my application, though pm2 can be made to run on separate s... | 1 | 2016-06-26T02:46:59Z | [
"python",
"numpy",
"meteor"
] |
how to load pretrained LSTM models weights in Tensorflow | 38,033,632 | <p>I want to implement a LSTM model with pretrained weights in Tensorflow. These weights may come from Caffee or Torch.<br>
I found there are LSTM cells in file <code>rnn_cell.py</code>, such as <code>rnn_cell.BasicLSTMCell</code> and <code>rnn_cell.MultiRNNCell</code>. But how can I load the pretrained weights for the... | 2 | 2016-06-25T22:51:32Z | 38,062,082 | <p>Here's a solution for loading a pre-trained Caffe model. See the <a href="https://github.com/ry/tensorflow-vgg16/blob/master/caffe_to_tensorflow.py" rel="nofollow">full code here</a>, which is referenced in the discussion in <a href="https://github.com/tensorflow/tensorflow/issues/6" rel="nofollow">this thread</a>.<... | 1 | 2016-06-27T19:47:21Z | [
"python",
"tensorflow",
"lstm",
"pre-trained-model"
] |
MultTermVectors in Elasticsearch Java | 38,033,666 | <p>I am using the following function to get the term vector for some set of IDs.</p>
<pre><code>public static void builtTermVectorRequest(Client client, String index, Map<String, String> postIDs) {
TermVectorsRequest termVectorsRequest = new TermVectorsRequest();
termVectorsRequest.index(index).type("pos... | 0 | 2016-06-25T22:58:11Z | 38,060,779 | <p>I tried out more combinations on how to use <code>TermVectorsRequest</code> with <code>MultiTermVectorsRequestBuilder</code> and finally came to the following solution which works:</p>
<pre><code>/**
* Prints term-vectors for child documents given their parent ids
*
* @param client Es client
* @param index ... | 2 | 2016-06-27T18:27:24Z | [
"java",
"python",
"elasticsearch"
] |
Scrapy only outputs '[' | 38,033,780 | <p>I am building a web crawler using scrapy that just takes all reddit links of the front page. When I try to put it into a json folder all I get is '['.</p>
<p>Here is my spider.</p>
<pre><code>from scrapy import Spider
from scrapy.selector import Selector
from redditScrape.items import RedditscrapeItem
class Redd... | 0 | 2016-06-25T23:19:24Z | 38,034,028 | <p>I don't know exactly what the problem is but I will have a go at what I see wrong in your code.</p>
<ul>
<li><p>First off, I don't know what the <code>-t</code> argument is but I suspect you wanted to reassure that the output was a json file. You don't need to. <code>-o items.json</code> is enough. <code>scrapy cra... | 1 | 2016-06-26T00:04:06Z | [
"python",
"json",
"scrapy"
] |
Scrapy only outputs '[' | 38,033,780 | <p>I am building a web crawler using scrapy that just takes all reddit links of the front page. When I try to put it into a json folder all I get is '['.</p>
<p>Here is my spider.</p>
<pre><code>from scrapy import Spider
from scrapy.selector import Selector
from redditScrape.items import RedditscrapeItem
class Redd... | 0 | 2016-06-25T23:19:24Z | 38,034,183 | <p>This css selector will get all the titles:</p>
<pre><code>In [13]: response.css("a.title.may-blank::text").extract()
Out[13]:
[u'TIL of a millionaire who announced he would bury his Bentley for his afterlife. After lots of negative reaction, he revealed the publicity stunt about organ donations. "People bury thing... | 1 | 2016-06-26T00:31:31Z | [
"python",
"json",
"scrapy"
] |
How does interp1d in scipy handle ties | 38,033,795 | <p>The documentation for <code>scipy.interpolate.interp1d</code> is silent on what happens when there are ties in the <code>x</code> argument. My experimenting suggests that it returns the rightmost one when that exact x value is requested and uses the closest one when interpolating:</p>
<pre><code>from scipy.interpol... | 1 | 2016-06-25T23:21:54Z | 38,034,339 | <p><code>interp1d</code> is defined in <code>scipy/interpolate/interpolate.py</code>. For the default 'linear' kind it appears to take two alternatives.</p>
<pre><code> # Check if we can delegate to numpy.interp (2x-10x faster).
if (not np.issubdtype(self.y.dtype, np.complexfloating) and
... | 1 | 2016-06-26T01:02:21Z | [
"python",
"scipy"
] |
How does interp1d in scipy handle ties | 38,033,795 | <p>The documentation for <code>scipy.interpolate.interp1d</code> is silent on what happens when there are ties in the <code>x</code> argument. My experimenting suggests that it returns the rightmost one when that exact x value is requested and uses the closest one when interpolating:</p>
<pre><code>from scipy.interpol... | 1 | 2016-06-25T23:21:54Z | 38,035,699 | <p>No, it is not guaranteed.</p>
<p>Behavior of an interpolator when there are ties in <code>x</code> values is undefined, and may change between scipy versions. (Also the interpolation kind and where in the arrays are the ties).</p>
| 1 | 2016-06-26T06:06:14Z | [
"python",
"scipy"
] |
Cant get program to run correctly Python/Qt/PyQt | 38,033,946 | <p>So i am just starting out using Qt4 and pyqt to convert the code to python and so on. I am trying to create a timer of sorts but that doesn't really matter. I've created the gui in Qt and converted it to python code, added a few things to get the code running, but when i run it i still just get a blank window, none ... | 1 | 2016-06-25T23:45:13Z | 38,034,139 | <pre><code>
def _init_(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
</code></pre>
<p>You are missing the double underscores for the init, so yours isn't getting called.
It should be:</p>
<pre><code>
def __init__(self):
QtGui.QWidget.__init__(self)
self.setupUi(self)
<... | 2 | 2016-06-26T00:24:47Z | [
"python",
"qt",
"pyqt"
] |
Do I have to run sphinx-apidoc for each new module (file)? | 38,033,956 | <p>Trying to get familiar with Sphinx, I am used to documentation using Doxygen where it auto generates stubs and classes from your source.</p>
<p>With Sphinx it seems for each new module/file I have to run <code>sphinx-apidoc -o dir dir</code> just like you have to <code>git add file</code> in git, is this standard o... | 0 | 2016-06-25T23:47:12Z | 38,034,313 | <p>You don't have to run <code>sphinx-apidoc</code> for each file.</p>
<blockquote>
<p>sphinx-apidoc generates source files that use sphinx.ext.autodoc to document all found modules. <a href="http://www.sphinx-doc.org/en/stable/man/sphinx-apidoc.html#sphinx-apidoc-manual-page" rel="nofollow">sphinx-apidoc-manual-pag... | 0 | 2016-06-26T00:57:12Z | [
"python",
"python-sphinx"
] |
PySpark: How to select * from the left table during rdd join | 38,034,089 | <p>How to select * in pyspark join</p>
<pre><code>impression_rdd.join(
click_rdd,
impression_rdd.session_id == click_rdd.session_id,
"left_outer"
).select(impression_rdd.*) <------- pseudo code; how do you do this?
</code></pre>
<p>Basically, the sql equivalent</p>
<pre><code>SELECT ... | 2 | 2016-06-26T00:13:32Z | 38,038,738 | <p>You can simply add alias and a couple of quotes to your pseudocode: </p>
<pre><code>(impressions.alias("impressions")
.join(clicks, ["id"], "left_outer")
.select("impressions.*"))
</code></pre>
| 0 | 2016-06-26T13:01:02Z | [
"python",
"apache-spark",
"pyspark"
] |
Python3 Django1.9 PIL Issue involving Saving Image File with io.BytesIO - Works in Terminal but not in the Server | 38,034,167 | <p>Python : 3.4.3<br>
Django : 1.9.7<br>
Exception Type: TypeError<br>
Exception Value: descriptor 'fileno' of '_io._IOBase' object needs an argument<br>
Exception Location: /usr/lib/python3/dist-packages/PIL/ImageFile.py in _save, line 454
<br><br>
This is the code I have tested in the terminal -</p>
<pre><code> ... | -1 | 2016-06-26T00:29:45Z | 38,034,204 | <p>You forgot to instantiate <code>BytesIO</code> class. Change <code>img_file = io.BytesIO</code> to <code>img_file = io.BytesIO()</code></p>
| 0 | 2016-06-26T00:35:34Z | [
"python",
"django",
"python-3.x",
"python-imaging-library"
] |
Using Python, how can I update data programmatically for a Pygal chart? | 38,034,174 | <p>Using Python, how can I update data programmatically for a Pygal chart?</p>
<p>The code below works fine as a static Stacked-Bar chart, but I can't figure out how to accommodate changing values. </p>
<p>Considerations/issues:</p>
<ul>
<li>My values, that I would like to update, come from a REST call as strings ev... | 0 | 2016-06-26T00:30:13Z | 38,034,214 | <p>You have a <code>TypeError</code>. it expects a list of numbers. </p>
<p>It's easy to think of variables as substitutions:
<code>y = [1,2,3]</code> means anywhere there is a <code>y</code>, just put <code>[1,2,3]</code> instead. So when you do <code>[y]</code>, it happily replaces it with <code>[[1,2,3]]</code></p>... | 0 | 2016-06-26T00:36:55Z | [
"python",
"pygal"
] |
I cant figure out the read part of the Python program. Please assist | 38,034,220 | <p>Write:</p>
<pre><code>def main():
import random
#Open a file named numbers.txt.
myfile = open('numbers.txt', 'w')
file_size= random.randint(4,7)
#Produce the numbers
for i in range(file_size):
k = random.randrange(5,19,2)
#Write as many random intergers as the user re... | -1 | 2016-06-26T00:38:49Z | 38,034,580 | <p>You want to write every number into the file, therefore, you need to include it within the for loop:</p>
<pre><code>#Produce the numbers
for count in range(file_size):
num = random.randrange(5,19,2)
myfile.write(str(num) + ' ')
</code></pre>
<p>When processing the numbers in, you're on the right track, but... | 0 | 2016-06-26T01:58:04Z | [
"python"
] |
Using Syntaxnet POS tags in python? | 38,034,266 | <p>I want to use the parser tags (ex: VBD ROOT, NN nsubj, etc.) of syntaxnet in python to help create a chatterbot. The input is done in the console. </p>
<p>Question: How can I get in a variable the result of only VBP ROOT and nothing else? I was able to print the ASCII version of the parse tree with this call: <code... | 0 | 2016-06-26T00:47:16Z | 38,275,718 | <p>If you're a Python beginner and all you want to use is the part-of-speech (POS) tags, SyntaxNet is probably overkill. <a href="https://spacy.io/" rel="nofollow">SpaCy</a> is easy to use and quite accurate.</p>
| 1 | 2016-07-08T21:35:37Z | [
"python",
"nlp",
"text-parsing",
"pos-tagger",
"syntaxnet"
] |
Using Syntaxnet POS tags in python? | 38,034,266 | <p>I want to use the parser tags (ex: VBD ROOT, NN nsubj, etc.) of syntaxnet in python to help create a chatterbot. The input is done in the console. </p>
<p>Question: How can I get in a variable the result of only VBP ROOT and nothing else? I was able to print the ASCII version of the parse tree with this call: <code... | 0 | 2016-06-26T00:47:16Z | 38,359,312 | <p>I am also a beginner both in python and SyntaxNet. what I did was that I changed the output of SyntaxNet from tree to a tab delimited text file by deleting</p>
<pre><code> bazel-bin/syntaxnet/conll2tree \
--task_context=$MODEL_DIR/context.pbtxt \
--alsologtostderr
</code></pre>
<p>from <a href="https://github... | 1 | 2016-07-13T18:33:48Z | [
"python",
"nlp",
"text-parsing",
"pos-tagger",
"syntaxnet"
] |
Object-like attribute access for nested dictionary | 38,034,377 | <p>I'm utilising a package which returns a nested dictionary.
It feels awkward to access this return object in my class methods with the dictionary syntax, when everything else is in object syntax.
Searching has brought me to the bunch / neobunch packages, which seems to achieve what I'm after. I've also seen namedtupl... | 0 | 2016-06-26T01:09:30Z | 38,034,502 | <p>The following class would let you do what you want:</p>
<pre><code>class AttrDict(dict):
""" Dictionary subclass whose entries can be accessed by attributes
(as well as normally).
"""
def __init__(self, *args, **kwargs):
super(AttrDict, self).__init__(*args, **kwargs)
self.__dict... | 0 | 2016-06-26T01:39:36Z | [
"python",
"dictionary",
"nested",
"bunch"
] |
Object-like attribute access for nested dictionary | 38,034,377 | <p>I'm utilising a package which returns a nested dictionary.
It feels awkward to access this return object in my class methods with the dictionary syntax, when everything else is in object syntax.
Searching has brought me to the bunch / neobunch packages, which seems to achieve what I'm after. I've also seen namedtupl... | 0 | 2016-06-26T01:09:30Z | 38,034,743 | <p>A simple class, built on the basic object can be used:</p>
<pre><code>class afoo1(object):
def __init__(self, kwargs):
for name in kwargs:
val = kwargs[name]
if isinstance(val, dict):
val = afoo1(val)
setattr(self,name,val)
</code></pre>
<p>I am borro... | 0 | 2016-06-26T02:36:29Z | [
"python",
"dictionary",
"nested",
"bunch"
] |
Is there a better way to check if the values of an AJAX request are valid? | 38,034,396 | <p>I'm in the process of building an AJAX backend for a Django application, and I don't know if I'm building it right. Currently to accept integer values, I need to typecast them into integers using int(), which raises exceptions and ends up in a 500 all the time if I don't apply much boilerplate. This causes my code t... | 4 | 2016-06-26T01:13:51Z | 38,034,512 | <p>If you're not opposed to using a framework <a href="https://marshmallow.readthedocs.io/en/latest/" rel="nofollow">Marshmallow</a> will handle serialization and deserialization for you, it is super easy to define custom validation beyond simple type checking, and it's gorgeous. Tom Christie has even <a href="https://... | 0 | 2016-06-26T01:41:40Z | [
"jquery",
"python",
"ajax",
"django"
] |
Django F doesn't seem to work? | 38,034,414 | <p>Huh, for some reason I can't seem to get F working properly even on the simplest of models. Here on Django 1.9.x.</p>
<p>In the simplest form, TestAccount</p>
<pre><code>class TestAccount(models.Model):
decimal = models.DecimalField(max_digits=5, decimal_places=2)
integer = models.IntegerField()
In [1]:... | 5 | 2016-06-26T01:19:04Z | 38,035,058 | <p>This works fine in pure Django. The problem in your case is that you have a listener (in <code>helium.internal.signals</code>) to the <code>pre_save</code> signal which tries to do this:</p>
<pre><code>def validate_model(sender, **kwargs):
if 'raw' in kwargs and not kwargs['raw']:
kwargs['instance'].ful... | 4 | 2016-06-26T03:51:57Z | [
"python",
"django",
"django-models"
] |
Align Shortcut info to right in Tkinter Menu | 38,034,416 | <p>I'm writing an application in Tkinter and I'm creating a ctrl+s save feature and I want to show that in the menu, but I can't get the actual text "Ctrl+S" to right align in the command. I tried using tabs as in the following example, but that didn't work, and I couldn't find anything on it. Here's what I tried:</p>
... | 0 | 2016-06-26T01:19:27Z | 38,034,639 | <p>Menu items have an <code>accelerator</code> attribute specifically for this purpose:</p>
<blockquote>
<p><strong>accelerator</strong> Specifies a string to display at the right side of the menu entry. Normally describes an accelerator keystroke sequence that
may be typed to invoke the same function as the menu ... | 2 | 2016-06-26T02:10:58Z | [
"python",
"python-3.x",
"tkinter",
"menu"
] |
Issue translating curl PUT to Python requests: "Problems parsing JSON" | 38,034,455 | <p>I'm looking to use the Python <a href="http://docs.python-requests.org/en/master/" rel="nofollow">requests</a> library to <a href="https://developer.github.com/v3/repos/contents/#create-a-file" rel="nofollow">create a new file in a GitHub</a> repository. Entering the following in the command line works for me (repla... | 0 | 2016-06-26T01:27:52Z | 38,034,473 | <p>Because just passing a <code>data</code> parameter automatically sends your dictionary as form encoded parameters. Instead pass it as JSON</p>
<pre><code>import json
data = {
"message": "test",
"content": "aGVsbG8y",
"path": "testfile.txt"
}
url = "https://api.github.com/repos/LOGIN/testrepo/contents/te... | 5 | 2016-06-26T01:32:00Z | [
"python",
"curl",
"github",
"python-requests",
"github-api"
] |
What is the point of logging.config.dictConfig() if it does not affect existing loggers? | 38,034,485 | <p>Configuring a logger using the APIs provided by <code>logging.Logger</code> as shown in <code>b.py</code> configures existing loggers. Configuring logging with <code>logging.config.dictConfig()</code> does not configure existing loggers as shown by <code>a.py</code>.</p>
<h1><code>*.py</code> files</h1>
<pre><code... | 1 | 2016-06-26T01:35:22Z | 38,034,640 | <p><code>logging.config.dictConfig()</code> does affect the configuration of existing loggers. However, <code>dictConfig()</code> will disable existing loggers by default unless <code>disable_existing_loggers = False</code> is defined in the dictionary passed to <code>dictConfig()</code> according to <a href="https://d... | 1 | 2016-06-26T02:11:00Z | [
"python",
"logging"
] |
How to print all factorization of an integer in Python 3.5.1 | 38,034,495 | <p>I am new to programming and trying to learn for loop, nested for loop with if statement.</p>
<p>I have written this code to produce all factorisations of an integer <code>n</code>:</p>
<pre><code>n=int(input())
for i in range(0,n+1):
for j in range(0,i):
if i*j == n:
print(i,'times',j,'equa... | 2 | 2016-06-26T01:38:06Z | 38,034,551 | <pre><code>for i in range(0,n+1):
for j in range(0,i):
</code></pre>
<p>Here, <code>j</code> is in the range <code>(0,i)</code>, which means, when <code>i</code> is <code>1</code>, <code>j</code> iterates from <code>0</code> to <code>1</code>, of course their product won't be <code>n</code> when <code>n</code> is ... | 1 | 2016-06-26T01:51:31Z | [
"python",
"factorization"
] |
How to print all factorization of an integer in Python 3.5.1 | 38,034,495 | <p>I am new to programming and trying to learn for loop, nested for loop with if statement.</p>
<p>I have written this code to produce all factorisations of an integer <code>n</code>:</p>
<pre><code>n=int(input())
for i in range(0,n+1):
for j in range(0,i):
if i*j == n:
print(i,'times',j,'equa... | 2 | 2016-06-26T01:38:06Z | 38,034,578 | <p>Try this:</p>
<pre><code>n = int(input())
for i in range(1, int(n / 2) + 1):
for j in range(1, i):
if i * j == n:
print(j, ' times ', i, ' equals ' , n)
</code></pre>
<blockquote>
<p>Few observations:</p>
<ul>
<li>You may not require the break statement if you want to have all the ... | 0 | 2016-06-26T01:57:29Z | [
"python",
"factorization"
] |
How to print all factorization of an integer in Python 3.5.1 | 38,034,495 | <p>I am new to programming and trying to learn for loop, nested for loop with if statement.</p>
<p>I have written this code to produce all factorisations of an integer <code>n</code>:</p>
<pre><code>n=int(input())
for i in range(0,n+1):
for j in range(0,i):
if i*j == n:
print(i,'times',j,'equa... | 2 | 2016-06-26T01:38:06Z | 38,034,865 | <p>Well I would like to suggest that you use minimum number of loops and should focus on the efficiency of the code. for example you can do like this:</p>
<pre><code>from math import sqrt #this imports square root from math
n=int(input())
for i in range(1,int(sqrt(n))+1): # this will help in less number of iteration... | 0 | 2016-06-26T03:09:14Z | [
"python",
"factorization"
] |
Retaining longest consecutive occurrence that does not equal a specific value | 38,034,585 | <p>I have a df like so:</p>
<pre><code>Value
0
1
3
-999
4
5
6
2
7
8
9
-999
3
2
-999
1
</code></pre>
<p>and I want to retain the most consecutive values in the dataframe that are NOT <code>-999</code></p>
<p>which for this example would give me this:</p>
<pre><code>Value
4
5
6
2
7
8
9
</code></pre>
<p>I have multip... | 0 | 2016-06-26T01:58:54Z | 38,034,758 | <p>You can do a <code>cumsum()</code> on the condition series which gives a unique groupId for each consecutive sequence from one <code>-999</code> to another. Then find the maximum length of the groupId and filter on that should give the desired output:</p>
<pre><code>df['groupId'] = (df['Value'] == -999).cumsum()
df... | 1 | 2016-06-26T02:39:04Z | [
"python",
"pandas"
] |
Why does lazy regex capture extra words? | 38,034,601 | <p>I am using following lazy regex to find word before and after "=". I am not sure why it capturing extra words </p>
<pre><code>r'\s+(.*?)\s+\=\s+(.*?)\s+'
</code></pre>
<p>The text is in format</p>
<pre><code>my name = jil
part = #2
</code></pre>
<p>So I want to capture name = jil</p>
<p>am i doing something wro... | 0 | 2016-06-26T02:02:50Z | 38,034,637 | <p>You're looking for:
<code>(\S+)\s*\=\s*(\S+)</code></p>
<p><code>\S</code> matches non-whitespace, and will allow for <code>./\#@&</code>, etc in the capture group.</p>
<p><code>\w</code> matches only word characters, so this matches the last word before an equals and the first word after, with or without whit... | 2 | 2016-06-26T02:10:49Z | [
"python",
"regex"
] |
Pycharm - Error installing libraries | 38,034,635 | <p>I was trying to install <code>sklearn</code> in Pycharm and encountered this error</p>
<p><a href="http://i.stack.imgur.com/4d4Ru.png" rel="nofollow"><img src="http://i.stack.imgur.com/4d4Ru.png" alt="enter image description here"></a></p>
<p>Last time I encountered this error, I update <code>pip</code> using <cod... | 0 | 2016-06-26T02:10:44Z | 38,035,570 | <p>The error says you don't have <em>SciPy</em> installed which is probably required for <em>sklearn</em> library to work.</p>
<p>Is <em>SciPy</em> installed in your system or is it broken?</p>
<p>Try installing(or reinstalling) that first from <a href="https://scipy.org/install.html" rel="nofollow">https://scipy.org... | 0 | 2016-06-26T05:41:27Z | [
"python",
"pycharm"
] |
Hang on websocket.recv() after... something? | 38,034,655 | <p>Apologies for the ambiguous question - I actually have no idea what I changed that stopped this from working.</p>
<p>I'm working on a text adventure engine (open source project) in Python using Websockets. <s>This was working fine with the asyncio and websockets modules. I moved things around a bit and now it hangs... | -1 | 2016-06-26T02:14:06Z | 38,034,949 | <p>If you're not determined to use the websockets package, I would suggest trying <a href="http://autobahn.ws/python/websocket/programming.html#" rel="nofollow">Autobahn Python</a>. I believe it would be easier to use if you're just starting out with websockets.</p>
<p>There's a full echo server example located <a hre... | 0 | 2016-06-26T03:26:40Z | [
"python",
"websocket",
"python-asyncio"
] |
Selenium Webdriver: not printing text in 'td' tab | 38,034,678 | <p>I have this HTML within a webpage:</p>
<pre class="lang-html prettyprint-override"><code><li style="list-style-type: none">
<h2 class="section-head"><a href=""><span class="user_data_property_name">Experimental Vapor Pressure:</span></a></h2>
<table sty... | 1 | 2016-06-26T02:20:16Z | 38,034,797 | <blockquote>
<p>it prints 'Experimental Vapor Pressure:'</p>
</blockquote>
<p>This is because <code>.text</code> by default would get you the <em>visible text</em> only.</p>
<p>You can workaround it by getting the <code>textContent</code> attribute:</p>
<pre><code>vp_li = extable.find_elements_by_tag_name("li")[3]... | 2 | 2016-06-26T02:49:44Z | [
"python",
"html",
"selenium"
] |
Error installing getch module Python 3.5 | 38,034,754 | <p>I'm having trouble as trying to pip install the getch module.</p>
<p>When I use the command <code>pip install getch</code> I get the following</p>
<pre><code>C:\Users\jpyam_000>pip install getch
Collecting getch
Using cached getch-1.0.tar.gz
Building wheels for collected packages: getch
Running setup.py bdi... | 0 | 2016-06-26T02:37:57Z | 38,034,778 | <p>The <code>getch</code> module is not compatible with Windows.</p>
<p>Read the note on <a href="https://pypi.python.org/pypi/getch" rel="nofollow">the module's pypi page</a> for a Windows-compatible alternative:</p>
<blockquote>
<p>Hint: On Windows, you can use:</p>
<pre><code>import msvcrt
# ...
char = msvcrt.g... | 1 | 2016-06-26T02:43:04Z | [
"python",
"getch"
] |
Tensor Flow all predictions are 0 | 38,034,782 | <p>I'm running the following code for TensorFlow and all the probabilities are <code>NaN</code> and all the predictions are <code>0</code>. The accuracy works, however. I have no idea how to debug this. Any and all help is appreciated.</p>
<pre><code>x = tf.placeholder("float", shape=[None, 22])
W = tf.Variable(tf.zer... | 0 | 2016-06-26T02:44:35Z | 38,036,025 | <p>I think you have an issue calculating your loss. It may also help your results if you add a <code>biases</code> vector. </p>
<p>You should try this:</p>
<pre><code>W = tf.Variable(tf.zeros([22, 5])) # can try better initialization methods
b = tf.Variable(tf.zeros([5])) # can try better initialization methods
y = t... | 0 | 2016-06-26T07:06:38Z | [
"python",
"machine-learning",
"tensorflow",
"prediction"
] |
Tensor Flow all predictions are 0 | 38,034,782 | <p>I'm running the following code for TensorFlow and all the probabilities are <code>NaN</code> and all the predictions are <code>0</code>. The accuracy works, however. I have no idea how to debug this. Any and all help is appreciated.</p>
<pre><code>x = tf.placeholder("float", shape=[None, 22])
W = tf.Variable(tf.zer... | 0 | 2016-06-26T02:44:35Z | 38,042,782 | <p>The issue stems from this line in your code:</p>
<pre><code>W = tf.Variable(tf.zeros([22, 5]))
</code></pre>
<p>Initializing your weights to zero is a common mistake when defining a neural network. <a href="http://cs231n.github.io/neural-networks-2/#init" rel="nofollow">This article</a> explains the reasoning behi... | 3 | 2016-06-26T20:16:11Z | [
"python",
"machine-learning",
"tensorflow",
"prediction"
] |
Windows failed to install flask-manager | 38,034,845 | <p>when I using PowerShell to run</p>
<pre><code>pip install flask-manager
</code></pre>
<p>command, I received this error message:</p>
<pre><code>Collecting flask-manager
Using cached flask-manager-0.0.1a0.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
... | 0 | 2016-06-26T03:03:01Z | 38,034,927 | <p><code>flask-manager</code> is alpha software, meaning it is in a ver early state of development. You should not expect alpha software to work 100%ly.</p>
<p>In this case the <code>setup.py</code> references a file <code>DESCRIPTION.rst</code> which is not included in the distribution archive. Also the instructions ... | 0 | 2016-06-26T03:20:56Z | [
"python",
"powershell",
"flask"
] |
Scrape special characters in Python Beautiful Soup | 38,034,860 | <p>How can I remove (or encode) the special characters from the page referenced below? </p>
<pre><code>import urllib2
from bs4 import BeautifulSoup
import re
link = "https://www.sec.gov/Archives/edgar/data/4281/000119312513062916/R2.htm"
request_headers = {"Accept-Language": "en-US,en;q=0.5", "User-Agent": "Mozilla/... | -1 | 2016-06-26T03:06:45Z | 38,035,005 | <p>Unicode objects can only be printed if they can be converted to ASCII. If it can't be encoded in ASCII, you'll get that error. You probably want to explicitly encode it and then print the resulting soup:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
import re
link = "https://www.sec.gov/Archives/edg... | -1 | 2016-06-26T03:39:01Z | [
"python",
"utf-8",
"beautifulsoup",
"ascii"
] |
How do you delete an entire column of values from an ndarray obtained from misc.imread()? | 38,034,885 | <p>I am reading a png image and it is in RGBA format and i would like to remove the 'A' part. The shape of my image is (694, 1077, 4) but I would like it to be (694, 1077, 3). I'd like to remove the last column in the array so I only have RGB values.</p>
| 0 | 2016-06-26T03:11:51Z | 38,034,919 | <pre><code>nd = np.random.randn(60).reshape(3,4,5)
print nd
print nd[:,:,:nd.shape[2]-1].shape #(3L, 4L, 4L)
</code></pre>
<p>This will take out the last column.</p>
| 0 | 2016-06-26T03:18:59Z | [
"python",
"numpy",
"image-processing",
"scipy",
"png"
] |
How do you delete an entire column of values from an ndarray obtained from misc.imread()? | 38,034,885 | <p>I am reading a png image and it is in RGBA format and i would like to remove the 'A' part. The shape of my image is (694, 1077, 4) but I would like it to be (694, 1077, 3). I'd like to remove the last column in the array so I only have RGB values.</p>
| 0 | 2016-06-26T03:11:51Z | 38,034,929 | <p>Simply do this:</p>
<pre><code>im_without_A = im[:, :, :3]
</code></pre>
| 1 | 2016-06-26T03:21:12Z | [
"python",
"numpy",
"image-processing",
"scipy",
"png"
] |
How do you delete an entire column of values from an ndarray obtained from misc.imread()? | 38,034,885 | <p>I am reading a png image and it is in RGBA format and i would like to remove the 'A' part. The shape of my image is (694, 1077, 4) but I would like it to be (694, 1077, 3). I'd like to remove the last column in the array so I only have RGB values.</p>
| 0 | 2016-06-26T03:11:51Z | 38,038,606 | <p>You can use the <code>mode='RGB'</code> parameter (<a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imread.html" rel="nofollow">see docs</a>), which should omit the alpha band.</p>
| 0 | 2016-06-26T12:42:32Z | [
"python",
"numpy",
"image-processing",
"scipy",
"png"
] |
Python requests post doing nothing | 38,034,984 | <p>I am using <a href="http://docs.python-requests.org/en/master/user/quickstart/" rel="nofollow">requests</a> and <a href="https://github.com/Anorov/cloudflare-scrape" rel="nofollow">cfscrape</a> library to login to <a href="https://kissanime.to/Login" rel="nofollow">https://kissanime.to/Login</a></p>
<pre><code>'''L... | 0 | 2016-06-26T03:34:36Z | 38,035,014 | <p>This content is from Requests Documentation:</p>
<blockquote>
<p>Many web services that require authentication accept HTTP Basic Auth. This is the simplest kind, and Requests supports it straight out of the box.</p>
<pre><code>requests.get('https://api.github.com/user', auth=HTTPBasicAuth('user', 'pass'))
</code... | -1 | 2016-06-26T03:41:24Z | [
"python",
"python-3.x",
"python-requests"
] |
Python requests post doing nothing | 38,034,984 | <p>I am using <a href="http://docs.python-requests.org/en/master/user/quickstart/" rel="nofollow">requests</a> and <a href="https://github.com/Anorov/cloudflare-scrape" rel="nofollow">cfscrape</a> library to login to <a href="https://kissanime.to/Login" rel="nofollow">https://kissanime.to/Login</a></p>
<pre><code>'''L... | 0 | 2016-06-26T03:34:36Z | 38,035,881 | <p>I solved it using <a href="https://github.com/hickford/MechanicalSoup" rel="nofollow">mechanicalsoup</a></p>
<p>Code:</p>
<pre><code>import mechanicalsoup
'''Login to website'''
def login(self, usr, pw):
login_url = 'https://kissanime.to/Login'
# Creating cfscrape instance
self.r = cfscrape.create_sc... | 0 | 2016-06-26T06:41:43Z | [
"python",
"python-3.x",
"python-requests"
] |
Creating a Django Property | 38,035,030 | <p>I copied this piece of code from another SO question (<a href="http://stackoverflow.com/questions/15285740/make-django-admin-to-display-no-more-than-100-characters-in-list-results">link</a>).</p>
<pre><code>from django.template.defaultfilters import truncatechars # or truncatewords
class Foo(models.Model):
de... | 0 | 2016-06-26T03:45:03Z | 38,035,052 | <p>I dont know what you mean by <code>'library' of options</code>, there is no library for defining a property in Django. It is just a normal <a href="https://docs.python.org/2/library/functions.html#property" rel="nofollow">attribute of Python</a> since version 2.2. </p>
<p>and yes, models.py is the place where you d... | 2 | 2016-06-26T03:50:58Z | [
"python",
"django",
"django-models"
] |
How to pass IN or NOT IN clause as variable to postgresql query using python | 38,035,031 | <p>How to pass <code>IN</code> OR <code>NOT IN</code> clause as variable to a query?</p>
<p>When I pass the variable in the query bellow I get :</p>
<p><code>SELECT * FROM table_name WHERE column_name 'IN' ('product', 'category')</code></p>
<p>which triger an error for the presence of quotes <code>'IN'</code></p>
<... | 1 | 2016-06-26T03:45:03Z | 38,035,069 | <p>you cant use a sql format string for that ... just a normal format string</p>
<pre><code>cur.execute("SELECT * FROM table_name WHERE column_name %s ('product', 'category')"%(query_clause,))
</code></pre>
<p>its worth noting this assumes <code>query_clause</code> is trusted input ... (it will not sanitize against i... | 2 | 2016-06-26T03:55:00Z | [
"python",
"postgresql",
"variables",
"in-clause"
] |
How to pass IN or NOT IN clause as variable to postgresql query using python | 38,035,031 | <p>How to pass <code>IN</code> OR <code>NOT IN</code> clause as variable to a query?</p>
<p>When I pass the variable in the query bellow I get :</p>
<p><code>SELECT * FROM table_name WHERE column_name 'IN' ('product', 'category')</code></p>
<p>which triger an error for the presence of quotes <code>'IN'</code></p>
<... | 1 | 2016-06-26T03:45:03Z | 38,035,071 | <p>Yes, that's expected. Use a boolean parameter instead:</p>
<pre><code>SELECT * FROM table_name
WHERE (column_name IN ('product', 'category')) = %s
</code></pre>
<p>You can then pass true or false into the parameter.</p>
| 4 | 2016-06-26T03:55:38Z | [
"python",
"postgresql",
"variables",
"in-clause"
] |
python script from the command line ,the arguments should be a list of options | 38,035,043 | <p>I would like to run my python script from the command line when supplies with some arguments. However, one of the arguments should be a list of options specific to a segment of the script.
Example:
MODULES_TO_INSTALL = ['sale','purchase','account_accountant',]</p>
<p>how can I do this: python fichier.py liste_modu... | 0 | 2016-06-26T03:47:47Z | 38,035,080 | <p>I've done something similar in the past. It might be easier if instead of sending them as a list already, you call your script like so,</p>
<pre><code>python script.py module1 module2 ... moduleN
</code></pre>
<p>Then a simple line of code to read in these passed modules from command line would be,</p>
<pre><cod... | 1 | 2016-06-26T03:56:55Z | [
"python",
"parameter-passing"
] |
ValueError: too many values to unpack with too many tuples | 38,035,154 | <p>I get an error while sorting about 470000 tuples.
I read data from csv file into list of tuples</p>
<pre><code>fp = open(filename, 'Ur')
for line in fp:
listOfCitiesTuples.append(tuple(line.strip().split(',')))
fp.close()
</code></pre>
<p>Tuples are some cities names associated with a number. </p>
<pre><code>[... | 3 | 2016-06-26T04:13:40Z | 38,035,314 | <p>By looking at your code and taking a guess, what might be happening is the last line of the file could be an extra line with nothing in it. So <code>line.strip().split(',')</code> returns a list of size <code>1</code>, which becomes a tuple of size <code>1</code> which blows up in your for-loop. Add the following ... | 0 | 2016-06-26T04:52:06Z | [
"python"
] |
ValueError: too many values to unpack with too many tuples | 38,035,154 | <p>I get an error while sorting about 470000 tuples.
I read data from csv file into list of tuples</p>
<pre><code>fp = open(filename, 'Ur')
for line in fp:
listOfCitiesTuples.append(tuple(line.strip().split(',')))
fp.close()
</code></pre>
<p>Tuples are some cities names associated with a number. </p>
<pre><code>[... | 3 | 2016-06-26T04:13:40Z | 38,035,325 | <p>Based on your title <code>ValueError: too many values to unpack</code> you have some data in a different format than you are expecting.</p>
<p>Specifically, some lines have more than one comma which will make a tuple with more than 2 values, which then causes the error when you try to unpack them.</p>
<p>While you... | 2 | 2016-06-26T04:54:50Z | [
"python"
] |
Protected attributes in classmethod | 38,035,158 | <p>Python conventions suggest to proceed the names of protected attributes with an underscore. As far as I understand protected attributes should only be used within a given class and its subclasses. Could you then provide me with some intuition on why pylint returns <em>protected-access</em> warnings when I try to use... | 2 | 2016-06-26T04:14:48Z | 38,035,277 | <p>In my opinion, <code>pylint</code> is too vigorous on this one. I doubt that there would be too much disagreement on this. I can't speak for the pylint developers, but I would <em>guess</em> that this is more of a problem with the type inferencing than necessarily being considered their ideal behavior.</p>
<hr>
... | 2 | 2016-06-26T04:43:42Z | [
"python",
"attributes",
"class-method",
"pylint"
] |
Protected attributes in classmethod | 38,035,158 | <p>Python conventions suggest to proceed the names of protected attributes with an underscore. As far as I understand protected attributes should only be used within a given class and its subclasses. Could you then provide me with some intuition on why pylint returns <em>protected-access</em> warnings when I try to use... | 2 | 2016-06-26T04:14:48Z | 38,035,299 | <p>From <code>pylint.checkers.classes.ClassChecker</code> in the <code>_check_protected_attribute_access</code> method:</p>
<pre><code>'''Given an attribute access node (set or get), check if attribute
access is legitimate. Call _check_first_attr with node before calling
this method. Valid cases are:
* self._attr in a... | 1 | 2016-06-26T04:48:19Z | [
"python",
"attributes",
"class-method",
"pylint"
] |
How to terminate external program or window using python | 38,035,271 | <p>I am trying to close the program, in this case spotify, but I am keep getting semantic mistake. Here is my code:</p>
<p>sup_programs.txt</p>
<pre><code>{
'spotify': ['C:/Users/Daniiar/AppData/Roaming/Spotify/Spotify.exe']
}
</code></pre>
<p>script:</p>
<pre><code>class Path(object):
import ast
sup_progr... | -1 | 2016-06-26T04:42:54Z | 38,035,589 | <p>your <code>open_program</code> function is recursive ???</p>
<p>Anyway, to open your program, you can do it by the path name. It then returns a handle on a subprocess.
To close it, just call the terminate method on that handle</p>
<p>example below opens notepad, waits 3 seconds, then closes it.</p>
<pre><code>imp... | 1 | 2016-06-26T05:45:14Z | [
"python",
"python-3.x",
"subprocess"
] |
how to vectorise Pandas calculation that is based on last x rows of data | 38,035,302 | <p>i have a fairly sophisticate prediction code with 20 over columns, millions of data per column using wls. Now i use iterrow to loop through dates, then based on those dates and values in those dates, extract different sizes of data for calculation. it takes hours to run in my production, i simplify the code into the... | 5 | 2016-06-26T04:48:59Z | 39,110,781 | <p>I would try pandas.DataFrame.apply(func, axis=1)</p>
<pre><code>def calculateC2(row):
if row.name >365: # row.name is the index of the row
if row.A >0: #based on values has different cutoff length for trend prediction
depth=10
else:
depth=20
lastyear=(row.dt... | 0 | 2016-08-23T21:15:01Z | [
"python",
"pandas"
] |
Comparing same index in 2 lists | 38,035,317 | <p>I don't have a code for this because I have no idea how to do it, and couldn't find much help on Google.</p>
<p>Is there a way to find if the same indexes on 2 lists are the same?</p>
<p>For example:</p>
<pre><code>x_list = [1, 2, 3, 4, 5]
y_list = [1, 2, A, B, 5]
</code></pre>
<p>I want to know whether the firs... | 1 | 2016-06-26T04:53:25Z | 38,035,364 | <p>You can always use list comprehensions:</p>
<p><code>[True if i == j else False for i,j in zip(x_list, y_list)]</code>.
You can also check less explicit answer by Moses Koledoye, where <code>True if i == j else False</code> is juzt <code>i == j</code></p>
<p>zip function will combine your lists like [(1, 1), (2, 2... | 3 | 2016-06-26T05:02:48Z | [
"python",
"python-2.7"
] |
Comparing same index in 2 lists | 38,035,317 | <p>I don't have a code for this because I have no idea how to do it, and couldn't find much help on Google.</p>
<p>Is there a way to find if the same indexes on 2 lists are the same?</p>
<p>For example:</p>
<pre><code>x_list = [1, 2, 3, 4, 5]
y_list = [1, 2, A, B, 5]
</code></pre>
<p>I want to know whether the firs... | 1 | 2016-06-26T04:53:25Z | 38,035,391 | <p><a href="https://docs.python.org/2/library/functions.html#zip"><code>zip</code></a> the lists and return the test (which returns a boolean as outcome):</p>
<pre><code>[i == j for i, j in zip(x_list, y_list)]
</code></pre>
<p>You could use <code>any</code> to quickly check for the existence of a <code>False</code> ... | 9 | 2016-06-26T05:06:54Z | [
"python",
"python-2.7"
] |
Comparing same index in 2 lists | 38,035,317 | <p>I don't have a code for this because I have no idea how to do it, and couldn't find much help on Google.</p>
<p>Is there a way to find if the same indexes on 2 lists are the same?</p>
<p>For example:</p>
<pre><code>x_list = [1, 2, 3, 4, 5]
y_list = [1, 2, A, B, 5]
</code></pre>
<p>I want to know whether the firs... | 1 | 2016-06-26T04:53:25Z | 38,035,433 | <p>try this:</p>
<pre><code> [i == j for i, j in zip(x_list, y_list)]
</code></pre>
| 1 | 2016-06-26T05:13:48Z | [
"python",
"python-2.7"
] |
Comparing same index in 2 lists | 38,035,317 | <p>I don't have a code for this because I have no idea how to do it, and couldn't find much help on Google.</p>
<p>Is there a way to find if the same indexes on 2 lists are the same?</p>
<p>For example:</p>
<pre><code>x_list = [1, 2, 3, 4, 5]
y_list = [1, 2, A, B, 5]
</code></pre>
<p>I want to know whether the firs... | 1 | 2016-06-26T04:53:25Z | 38,035,555 | <p>You can try with below definition if you would like to compare lists with different size. This would fetch either unique index elements or not rather than a list of True or False.</p>
<pre><code>def is_uniq_lists(x_list, y_list):
if len(x_list) != len(y_list):
return False
for (i,j) in zip(x_list, ... | 1 | 2016-06-26T05:37:41Z | [
"python",
"python-2.7"
] |
IPython equivalent to Clojure find-doc? | 38,035,435 | <p>In Clojure repl, when forget the exact function name, I can use <code>find-doc</code> to list all functions whose documentation or name contains the name I'm looking for. For example:</p>
<pre><code>user=> (xor 1 2)
CompilerException java.lang.RuntimeException: Unable to resolve symbol: xor in this context, comp... | 0 | 2016-06-26T05:13:55Z | 38,040,589 | <p>Google 'python xor' gives me (several choices down) an official reference page</p>
<p><a href="https://docs.python.org/2/reference/expressions.html" rel="nofollow">https://docs.python.org/2/reference/expressions.html</a></p>
<p>page find in that takes me to</p>
<pre><code>5.8. Binary bitwise operations
...
xor_e... | 0 | 2016-06-26T16:21:56Z | [
"python",
"clojure",
"documentation",
"ipython",
"read-eval-print-loop"
] |
Looping a program with "while" statement | 38,035,459 | <p>So, I have this program where you have to guess a number and I've coded it so that the program will tell you if the number you guessed was above or below the true number. My issue is that the program ends after it tells the user to guess higher or lower. I want the program to loop such that the program won't end unt... | 1 | 2016-06-26T05:19:42Z | 38,035,476 | <p>Try the following:</p>
<pre><code>number = 10
guess = 9
while guess!= number:
guess = int(input("Type in an integer: "))
if guess == number:
print ("Good Job!")
elif guess < number:
print ("The number is higher")
elif guess > number:
print ("The number is lower")
el... | 0 | 2016-06-26T05:24:07Z | [
"python",
"loops",
"while-loop"
] |
Looping a program with "while" statement | 38,035,459 | <p>So, I have this program where you have to guess a number and I've coded it so that the program will tell you if the number you guessed was above or below the true number. My issue is that the program ends after it tells the user to guess higher or lower. I want the program to loop such that the program won't end unt... | 1 | 2016-06-26T05:19:42Z | 38,035,483 | <p><code>while</code> loops don't work that way. It looks like you're expecting some kind of <code>goto</code> where it guesses what you would like it to repeat, but all it will repeat is the content of the block. When it gets to <code>while guess != number:</code>, which is true, it will print that phrase, then check ... | 2 | 2016-06-26T05:24:40Z | [
"python",
"loops",
"while-loop"
] |
Looping a program with "while" statement | 38,035,459 | <p>So, I have this program where you have to guess a number and I've coded it so that the program will tell you if the number you guessed was above or below the true number. My issue is that the program ends after it tells the user to guess higher or lower. I want the program to loop such that the program won't end unt... | 1 | 2016-06-26T05:19:42Z | 38,035,485 | <p>Your flow control was not properly designed, but you can fix by wrapping your code in the <code>while</code> loop, and applying <code>break</code> once <code>guess == number</code>. The other cases where <code>guess!=number</code>, the loop just keeps running:</p>
<pre><code>number = 10
while True:
guess = int(... | 3 | 2016-06-26T05:25:24Z | [
"python",
"loops",
"while-loop"
] |
Scraping Numbers from HTML using BeautifulSoup | 38,035,489 | <p>I have the question of reading the HTML from the data files, and parse the data, extracting numbers and compute the sum of the numbers in the file. </p>
<p>Here is the code</p>
<pre><code>from BeautifulSoup import *
import socket
mysock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysock.connec... | 2 | 2016-06-26T05:26:23Z | 38,035,575 | <p>Try changing this line</p>
<pre><code>mysock.send('GET http://python-data.dr-chuck.net/comments_42.html HTTP/1.0\n\n')
</code></pre>
<p>to</p>
<pre><code>mysock.send('GET /comments_42.html HTTP/1.0\n\n')
</code></pre>
<p>I took a look at a request from this page and in the source request the page was requested l... | 1 | 2016-06-26T05:41:58Z | [
"python",
"html",
"python-2.7",
"parsing",
"beautifulsoup"
] |
Scraping Numbers from HTML using BeautifulSoup | 38,035,489 | <p>I have the question of reading the HTML from the data files, and parse the data, extracting numbers and compute the sum of the numbers in the file. </p>
<p>Here is the code</p>
<pre><code>from BeautifulSoup import *
import socket
mysock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysock.connec... | 2 | 2016-06-26T05:26:23Z | 38,035,582 | <p>This will sum up all the numbers under comments column:</p>
<pre><code>import requests
from bs4 import BeautifulSoup
import re
link = "http://python-data.dr-chuck.net/comments_42.html"
reuest = requests.get(link)
soup = BeautifulSoup(reuest.text,"lxml")
soupl=soup.findAll("span", { "class" : "comments" })
sum=0
... | -1 | 2016-06-26T05:43:05Z | [
"python",
"html",
"python-2.7",
"parsing",
"beautifulsoup"
] |
Scraping Numbers from HTML using BeautifulSoup | 38,035,489 | <p>I have the question of reading the HTML from the data files, and parse the data, extracting numbers and compute the sum of the numbers in the file. </p>
<p>Here is the code</p>
<pre><code>from BeautifulSoup import *
import socket
mysock=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
mysock.connec... | 2 | 2016-06-26T05:26:23Z | 38,038,234 | <p>You need to send some headers when you get <code>/comments_42.html</code> making sure to set accept to <code>utf-8/ascii</code> so you get text back:</p>
<pre><code>mysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('python-data.dr-chuck.net', 80))
mysock.send('''GET /comments_42.html HTTP/1... | 1 | 2016-06-26T11:49:32Z | [
"python",
"html",
"python-2.7",
"parsing",
"beautifulsoup"
] |
Getting application output to a variable python | 38,035,505 | <p>I'm writing a python application for executing another application. The application is avrdude.exe and want to read the output of the application to a variable. I tried various methods (subprocess, communicate,check out etc.) but all I'm getting is a blank string. Any ideas?</p>
<pre><code>import os
import subproc... | 0 | 2016-06-26T05:29:07Z | 38,036,087 | <p>I guess your <code>avrdude.exe</code> doesn't provide <code>--help</code> option, and thus the execution only results error output.</p>
<p>Try to run the exe with the option directly or specify <code>stderr</code> to see what you can get from var <code>error</code>. </p>
| 0 | 2016-06-26T07:16:22Z | [
"python",
"subprocess"
] |
Cumulative frequency histogram in Pyplot doesn't plot full graph for zero-valued data | 38,035,521 | <p>I have a script that I wrote that analyzes data, generates a value (between 0 and 2) for each piece of data, removes some of the data based on an algorithm, then repeats the analysis and generation of values. At each step of data being removed, it generates a cumulative frequency histogram of the data logs to help ... | 0 | 2016-06-26T05:31:01Z | 38,035,744 | <p>Try using the range option in np.histogram</p>
<pre><code>hist_, bins_ = np.histogram(e.real, bins = 500, range = (0, 2), normed=0)
</code></pre>
| 1 | 2016-06-26T06:16:12Z | [
"python",
"matplotlib",
"graph"
] |
Convert Django template to pdf | 38,035,553 | <p>my application needs to mail out reports to clients and hence i needed an effective method to convert the dynamic template into a pdf report (including images generated via chart.js). I have tried pdfkit but it needs a URL (on which it most likely performs a GET, but then the template generates a report after a few ... | 0 | 2016-06-26T05:36:53Z | 38,035,581 | <h2>Option A: Scraping</h2>
<p>You could use something like <a href="http://phantomjs.org/" rel="nofollow">PhantomJS</a> or <a href="http://casperjs.org/" rel="nofollow">CasperJS</a> to navigate and scrape the HTML page.</p>
<h2>Option B: Generation</h2>
<p>You could use something like <a href="https://github.com/ms... | 0 | 2016-06-26T05:43:05Z | [
"javascript",
"python",
"django",
"pdf"
] |
Convert Django template to pdf | 38,035,553 | <p>my application needs to mail out reports to clients and hence i needed an effective method to convert the dynamic template into a pdf report (including images generated via chart.js). I have tried pdfkit but it needs a URL (on which it most likely performs a GET, but then the template generates a report after a few ... | 0 | 2016-06-26T05:36:53Z | 38,035,984 | <p>Django has a few options for outputting PDFs, most flexible of which is <a href="https://docs.djangoproject.com/en/1.9/howto/outputting-pdf/" rel="nofollow">ReportLab</a>.</p>
<p>However, to just render a Django template to PDF while passing context data, <a href="https://github.com/Kozea/WeasyPrint" rel="nofollow"... | 0 | 2016-06-26T07:00:38Z | [
"javascript",
"python",
"django",
"pdf"
] |
Convert Django template to pdf | 38,035,553 | <p>my application needs to mail out reports to clients and hence i needed an effective method to convert the dynamic template into a pdf report (including images generated via chart.js). I have tried pdfkit but it needs a URL (on which it most likely performs a GET, but then the template generates a report after a few ... | 0 | 2016-06-26T05:36:53Z | 38,036,080 | <p>You can use a paid library i.e pdfcrowd, which converts a webpage into pdf. Like this..</p>
<p>First install-</p>
<pre><code>pip install pdfcrowd
</code></pre>
<p>Then use the library -</p>
<pre><code>import pdfcrowd
from django.http import HttpResponse
def generate_pdf_view(request):
try:
# create ... | 0 | 2016-06-26T07:14:49Z | [
"javascript",
"python",
"django",
"pdf"
] |
Error on django-admin startproject | 38,035,636 | <p>I a trying to create a django project by using "django-admin startproject sitedemo" but the following error came</p>
<pre><code>shivam@shivam-HP-15-Notebook-PC:~$ django-admin startproject sitedemo
Traceback (most recent call last):
File "/usr/local/bin/django-admin", line 5, in <module>
from pkg_resour... | 0 | 2016-06-26T05:56:06Z | 38,035,776 | <p>Okk ! I think you have not created any virtual enviornment first.
So please first create the enviornment for this project like</p>
<pre><code>virtualenv enviornment_name
cd enviornment_name
source bin/activate
cd ..
django-admin.py startproject sitedemo
</code></pre>
| 0 | 2016-06-26T06:21:34Z | [
"python",
"django",
"ubuntu"
] |
Python DataFrames putting multipule dataframes into a single Data Frame | 38,035,637 | <h1>Import the required modules</h1>
<pre><code>import pandas.io.data as web
import datetime
import pandas as pd
import matplotlib.pyplot as plt
# Enable inline plotting
%matplotlib inline
</code></pre>
<h1>Set the date range and the stock code of the stock</h1>
<pre><code>start = datetime.datetime(2016, 1, 1)
end =... | 0 | 2016-06-26T05:56:42Z | 38,036,356 | <p>In the original code, <code>df_Stock_Code</code> is treated as a list of dataframes. However, in the <code>for loop</code>, the current dataframe is being assigned to it rather than appending the latest dataframe to it. </p>
<p>The result is that in the concatenation step, <code>df_Stock_Code</code> is just a singl... | 0 | 2016-06-26T07:54:14Z | [
"python",
"dataframe",
"concat"
] |
Dynamic Import - Python - Call function not working | 38,035,687 | <p>I am having some trouble with dynamically importing Classes and attempting to run functions in said classes. This is my problem, specifically. </p>
<p>I have a python script <code>dyn_imports.py</code> in a director called <code>dynamic_imports</code>. Inside this folder is a subdir called <code>scripts</code>. In ... | 0 | 2016-06-26T06:04:29Z | 38,035,842 | <p>I realize what I was doing wrong. I was importing the module and not referencing the class in the <code>getattr</code> function. I made the class declaration explicit in the <code>__import__</code> function and in the <code>getattr</code> function and I was subsequently able to gain access to the functions in the cl... | 1 | 2016-06-26T06:36:00Z | [
"python",
"reflection"
] |
Blank section appear when using Jinja2/Flask | 38,035,705 | <p>I'm creating a website and it works fine when i use direct html. Now i want to use Jinja2 to render my template and there is something wrong. You can see that there is a blank space on top of my page here <a href="http://kgroupman.azurewebsites.net/" rel="nofollow">http://kgroupman.azurewebsites.net/</a> but it work... | 0 | 2016-06-26T06:07:56Z | 38,035,724 | <p>It's a character at the top of your body</p>
<p><a href="http://i.stack.imgur.com/I6ff0.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/I6ff0.jpg" alt="enter image description here"></a></p>
| 0 | 2016-06-26T06:11:13Z | [
"python",
"html",
"flask",
"jinja2"
] |
Blank section appear when using Jinja2/Flask | 38,035,705 | <p>I'm creating a website and it works fine when i use direct html. Now i want to use Jinja2 to render my template and there is something wrong. You can see that there is a blank space on top of my page here <a href="http://kgroupman.azurewebsites.net/" rel="nofollow">http://kgroupman.azurewebsites.net/</a> but it work... | 0 | 2016-06-26T06:07:56Z | 38,055,996 | <p>Solution found. Delete login.html and recreate it. There's must be an invisible character that i can't see somehow!</p>
| 0 | 2016-06-27T14:02:43Z | [
"python",
"html",
"flask",
"jinja2"
] |
How to get SWF activity information for a given workflow execution using boto | 38,035,716 | <p>When looking at the SWF console on Amazon AWS, you can view closed workflow executions' histories. In the history, you can see all the activities that were called and their inputs and outputs.</p>
<p>I haven't been able to figure out how to access this activity information using boto 2. I am able to get the history... | 0 | 2016-06-26T06:09:34Z | 38,046,101 | <p>History contains complete information about activity execution.</p>
<p><a href="http://docs.aws.amazon.com/amazonswf/latest/apireference/API_ActivityTaskScheduledEventAttributes.html" rel="nofollow">ActivityTaskScheduled</a> contains input of an activity.</p>
<p><a href="http://docs.aws.amazon.com/amazonswf/latest... | 0 | 2016-06-27T04:47:51Z | [
"python",
"boto",
"amazon-swf"
] |
Is their a way i can put a sum and average of array functions together to create one function? | 38,035,739 | <p>I need the sum and average functions to be combined to make my code shorter. My teacher said I don't need to add a function for the average I can just print average by dividing <code>sum/n</code>?</p>
<pre><code>import random
def main():
random_numbers = [random.randrange(1,100) for _ in range (10)]
print... | 0 | 2016-06-26T06:14:04Z | 38,035,751 | <p>You do not have to do the multiple return statements. You can print right from a function. </p>
<pre><code>import random
def main():
random_numbers = [random.randrange(1,100)
for _ in range (10)]
print(random_numbers)
numbers = random_numbers
getInformation(numbers)
def getInfo... | 1 | 2016-06-26T06:17:19Z | [
"python",
"python-3.5"
] |
Is their a way i can put a sum and average of array functions together to create one function? | 38,035,739 | <p>I need the sum and average functions to be combined to make my code shorter. My teacher said I don't need to add a function for the average I can just print average by dividing <code>sum/n</code>?</p>
<pre><code>import random
def main():
random_numbers = [random.randrange(1,100) for _ in range (10)]
print... | 0 | 2016-06-26T06:14:04Z | 38,035,773 | <p>Here's the shortest code:</p>
<pre><code>import random
def main():
random_numbers = [random.randrange(1,100)
for _ in range (10)]
print(random_numbers)
numbers = random_numbers
total = sum(numbers)
print("Sum:", total)
print("Average:", total/len(numbers))
main()
</code>... | 1 | 2016-06-26T06:20:26Z | [
"python",
"python-3.5"
] |
'zinnia_loop_template' received too many positional arguments | 38,035,850 | <p>I am working on Django 1.8. I want to work with Django-blog-zinnia.
I have installed zinnia, changed my setting.py file and have added links in urls.py of project. when I tried to access zinnia using weblog as per mentioned on Installation site</p>
<blockquote>
<p>weblog</p>
</blockquote>
<p>I got an error</p>
... | 0 | 2016-06-26T06:36:47Z | 38,378,589 | <p>i also have this failure in django-blog-zinnia 0.17 with django 1.8 .
i assume, it's a bug, because it works with django-blog-zinnia 0.16;</p>
<p>pip install django-blog-zinnia==0.16</p>
<p>maybe it's because of the compatibility of django 1.9 since zinnia 0.17 - because i like to stay on django 1.8 for other webs... | 0 | 2016-07-14T15:41:09Z | [
"python",
"django",
"zinnia"
] |
Error when compare performance of del for dict and list in Python | 38,036,061 | <p>I'm doing programming exercise from Problem solving with algorithms and data structures.The exercise is to compare performance of del operator on lists and dictionaries, here's the code:</p>
<pre><code>import timeit, random
from timeit import Timer
for i in range(1000000, 100000000, 1000000):
x = list(range(i)... | 0 | 2016-06-26T07:12:54Z | 38,036,108 | <p>All the repeats of the timed snippet are run on the same <code>x</code>. So once an element is deleted, the list is shorter, then after you delete another element, it's even shorter, and so on. Eventually, it is likely that you will randomly try to delete an index that isn't there any more, because the list has be... | 2 | 2016-06-26T07:19:13Z | [
"python",
"list",
"dictionary"
] |
How to optimize memory use in pandas | 38,036,084 | <p>I try to merge 3 files which is about 3GB, 200Kb and 200kb using pandas, and my computer has 32G memory, but it still end with MemoryError. Is there any way to avoid this problem? My merge code is below:</p>
<pre><code>product = pd.read_csv("../data/process_product.csv", header=0)
product["bandID"] = pd.factorize(p... | 1 | 2016-06-26T07:15:49Z | 38,037,088 | <p>Here is my "micro"-optimization attempt:</p>
<p>you don't use (need) the <code>Info</code> column from the <code>process_product.csv</code>, so there is no need to read it:</p>
<pre><code>cols = [<list of columns, EXCEPT Info column>]
product = pd.read_csv("../data/process_product.csv", usecols=cols)
product... | 0 | 2016-06-26T09:35:15Z | [
"python",
"pandas",
"out-of-memory"
] |
python - communicating with other applications at high rate | 38,036,233 | <p>I have a Python function <code>get_messages()</code> that is able to retrieve messages from another application via a dll. These messages arrive at a rate of about 30hz, and I need to fill a buffer with these messages, while the main Python application is running and doing things with theses messages. I believe the ... | 1 | 2016-06-26T07:36:23Z | 38,201,278 | <p>Answer according to Doug Ross: consider the Asyncio module.</p>
| 0 | 2016-07-05T10:38:05Z | [
"python",
"ipc",
"dllimport"
] |
python 2.7 simple proxy server | 38,036,437 | <p>i want to make a simple proxy server in python
this is what it needs to do:
- get a url from the client
- fetch the content of that url
- manipulate every link in that site
- return the manipulated site to the user</p>
<p>the only thing i managed to do so far (using either urllib or requests) is a simple redirectio... | 0 | 2016-06-26T08:05:36Z | 38,037,015 | <p>This should work on linux, hopefully it will give you a starting point.</p>
<pre><code>import SocketServer
import SimpleHTTPServer
import urllib
PORT = 1234
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.copyfile(urllib.urlopen(self.path), self.wfile)
httpd = SocketSer... | 0 | 2016-06-26T09:25:34Z | [
"python",
"python-2.7",
"http",
"proxy",
"server"
] |
How does Apache spark handle python multithread issues? | 38,036,528 | <p>According to <a href="http://stackoverflow.com/a/19614263">python's GIL</a> we cannot use threading in CPU bound processes so my question is how does Apache Spark utilize python in multi-core environment? </p>
| 2 | 2016-06-26T08:17:22Z | 38,038,346 | <p>Multi-threading python issues are separated from Apache Spark internals. Parallelism on Spark is dealt with inside the JVM. </p>
<p><a href="http://i.stack.imgur.com/VvEvd.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/VvEvd.jpg" alt="enter image description here"></a></p>
<p>And the reason is that in the ... | 3 | 2016-06-26T12:03:36Z | [
"python",
"multithreading",
"apache-spark"
] |
What type of message "Exception ignored in" is? | 38,036,540 | <p>Here's code:</p>
<pre><code>def g():
try:
yield 1
yield 2
yield 3
except GeneratorExit:
yield 4
gen = g()
print(gen.__next__())
</code></pre>
<p>If you run it you'll see:</p>
<pre><code>1
Exception ignored in: <generator object g at 0x00000216BB546A98>
RuntimeError: ... | 2 | 2016-06-26T08:18:57Z | 38,038,884 | <p>when i run your code i just get:</p>
<pre><code>1
>>>
</code></pre>
<p>without error (I also use Python 3.5.1 on windows 10),
but you can use following code to determine error in your code:</p>
<pre><code>try:
a = int('a') # here you can put your code
except Exception as e:
print(e) ... | 0 | 2016-06-26T13:20:27Z | [
"python",
"python-3.x"
] |
What type of message "Exception ignored in" is? | 38,036,540 | <p>Here's code:</p>
<pre><code>def g():
try:
yield 1
yield 2
yield 3
except GeneratorExit:
yield 4
gen = g()
print(gen.__next__())
</code></pre>
<p>If you run it you'll see:</p>
<pre><code>1
Exception ignored in: <generator object g at 0x00000216BB546A98>
RuntimeError: ... | 2 | 2016-06-26T08:18:57Z | 38,039,568 | <p>As some have noted, not everyone always gets the behaviour that you describe. For instance, you won't get this behaviour at the REPL. To reproduce this behaviour on the REPL you have to add <code>del gen</code> at the end. This lets us know where the warning is coming. The warning is coming from the clean up functio... | 2 | 2016-06-26T14:36:36Z | [
"python",
"python-3.x"
] |
using 'stop button' to quit function | 38,036,583 | <p>So I'm trying to create a timer or sorts, the start button starts the timer, i need to stop the timer with the stop button and then record the time... I can't seem to figure out how to stop the timer function once its started. Ive tried if statements, disconnect(), and many others...
I realize that there is a timer... | 1 | 2016-06-26T08:24:54Z | 38,036,684 | <p>Sounds like you want to use QTimer on a QThread.
This answer should give you everything you need.
<a href="http://stackoverflow.com/a/18960953/5757280">http://stackoverflow.com/a/18960953/5757280</a></p>
| -2 | 2016-06-26T08:37:36Z | [
"python",
"qt",
"pyqt4"
] |
using 'stop button' to quit function | 38,036,583 | <p>So I'm trying to create a timer or sorts, the start button starts the timer, i need to stop the timer with the stop button and then record the time... I can't seem to figure out how to stop the timer function once its started. Ive tried if statements, disconnect(), and many others...
I realize that there is a timer... | 1 | 2016-06-26T08:24:54Z | 38,040,804 | <p>Use a flag to control the loop. Then reset the flag in the slot connected to the stop button:</p>
<pre><code> self.startButton.clicked.connect(self.timer)
self.stopButton.clicked.connect(self.stop)
def stop(self):
self._timer_flag = False
def timer(self):
timeL = 0
s... | 0 | 2016-06-26T16:45:37Z | [
"python",
"qt",
"pyqt4"
] |
using 'stop button' to quit function | 38,036,583 | <p>So I'm trying to create a timer or sorts, the start button starts the timer, i need to stop the timer with the stop button and then record the time... I can't seem to figure out how to stop the timer function once its started. Ive tried if statements, disconnect(), and many others...
I realize that there is a timer... | 1 | 2016-06-26T08:24:54Z | 38,062,333 | <p>TL;DR: You're after <code>QElapsedTimer</code>, not <code>QTimer</code>.</p>
<p>The operating system is already measuring the passage of time for you. You won't do any better job at it yourself.</p>
<p>"I'm trying to figure it out this way" - it will be less accurate than using <code>QElapsedTimer</code> because y... | 2 | 2016-06-27T20:04:58Z | [
"python",
"qt",
"pyqt4"
] |
using ssh in script (w/ expect or paramiko) not working as expected | 38,036,585 | <p>I'm new to Python</p>
<p>I want to write <code>Python</code> script to reboot machine using <code>SSH</code>
this is my function :</p>
<pre><code>def sendCommandViaSSH(usr,psswrd,command):
line = 'ssh '+ usr +'@'+ RIp + ' ' +"\""+ command+"\""
print_message(line)
child = pexpect.spawn (line)
#i = c... | 0 | 2016-06-26T08:25:12Z | 38,037,018 | <p>There is sshpass for this but I would always go with public keys. But if public keys is something you can not do, then sub-process in Python:</p>
<pre><code>sshpass -pfoobar ssh -o StrictHostKeyChecking=no user@host command_to_run
</code></pre>
<p>This is tool url: <a href="https://sourceforge.net/projects/sshpass... | 0 | 2016-06-26T09:25:58Z | [
"python",
"ssh",
"redhat",
"paramiko"
] |
using ssh in script (w/ expect or paramiko) not working as expected | 38,036,585 | <p>I'm new to Python</p>
<p>I want to write <code>Python</code> script to reboot machine using <code>SSH</code>
this is my function :</p>
<pre><code>def sendCommandViaSSH(usr,psswrd,command):
line = 'ssh '+ usr +'@'+ RIp + ' ' +"\""+ command+"\""
print_message(line)
child = pexpect.spawn (line)
#i = c... | 0 | 2016-06-26T08:25:12Z | 38,094,318 | <p>After much searching and reading I've found something that works </p>
<p>The reason for my problem is <strong>unknown</strong> (I'll try to update if I find something that is version related or something generic)</p>
<p><strong>original code:</strong> </p>
<pre><code>ssh = paramiko.SSHClient()
ssh.set_missing_hos... | 0 | 2016-06-29T08:35:15Z | [
"python",
"ssh",
"redhat",
"paramiko"
] |
Looping through an interval in either direction | 38,036,637 | <p>Suppose you want to loop through all integers between two bounds <code>a</code> and <code>b</code> (inclusive), but don't know in advance how <code>a</code> compares to <code>b</code>. Expected behavior:</p>
<pre><code>def run(a, b):
if a < b:
for i in range(a, b + 1):
print i,
elif a... | 4 | 2016-06-26T08:32:09Z | 38,036,683 | <pre><code>range(min((a,b)), max((a,b))+1)
</code></pre>
| -3 | 2016-06-26T08:37:35Z | [
"python",
"loops",
"intervals"
] |
Looping through an interval in either direction | 38,036,637 | <p>Suppose you want to loop through all integers between two bounds <code>a</code> and <code>b</code> (inclusive), but don't know in advance how <code>a</code> compares to <code>b</code>. Expected behavior:</p>
<pre><code>def run(a, b):
if a < b:
for i in range(a, b + 1):
print i,
elif a... | 4 | 2016-06-26T08:32:09Z | 38,036,694 | <p>This will work for all cases:</p>
<pre><code>def run(a, b):
"""Iterate from a to b (inclusive)."""
step = -1 if b < a else 1
for x in xrange(a, b + step, step):
yield x
</code></pre>
<p>The insight that led me to this formulation was that <code>step</code> and the adjustment to <code>b</code... | 7 | 2016-06-26T08:38:13Z | [
"python",
"loops",
"intervals"
] |
Looping through an interval in either direction | 38,036,637 | <p>Suppose you want to loop through all integers between two bounds <code>a</code> and <code>b</code> (inclusive), but don't know in advance how <code>a</code> compares to <code>b</code>. Expected behavior:</p>
<pre><code>def run(a, b):
if a < b:
for i in range(a, b + 1):
print i,
elif a... | 4 | 2016-06-26T08:32:09Z | 38,036,744 | <p>You almost got it yourself:</p>
<pre><code>def run(a, b):
for i in range(a, b + (cmp(b, a) or 1), cmp(b, a) or 1):
print i,
print
</code></pre>
<p>works just fine... when <code>cmp(b, a)</code> evaluates to <code>0</code> (when they are equal), it defaults to <code>1</code>, although I'd definitely... | 2 | 2016-06-26T08:44:16Z | [
"python",
"loops",
"intervals"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.