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 listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
Python Tkinter to run subprocess on a different thread to avoid non-responding GUI | 38,399,443 | <p>I've been fighting with Tkinter for a while now and have exhausted most the resources I have for referencing this. I've found a couple similar topics here but none quite bring me to where I need to be.</p>
<p>I've got a long running (not long actually, it only takes 10-12 secs) python script that silently install a... | 1 | 2016-07-15T15:05:19Z | 38,406,592 | <p>You have defined a button</p>
<pre><code>installButton = Button(bottomFrame, text=installButtonTxt,
command=on_install_thread, width=9)
</code></pre>
<p>with command handler</p>
<pre><code>def on_install_thread():
...
loop_thread = threading.Thread(target=on_install_button_active,
... | 0 | 2016-07-16T00:28:15Z | [
"python",
"multithreading",
"python-2.7",
"tkinter",
"subprocess"
] |
Python Tkinter to run subprocess on a different thread to avoid non-responding GUI | 38,399,443 | <p>I've been fighting with Tkinter for a while now and have exhausted most the resources I have for referencing this. I've found a couple similar topics here but none quite bring me to where I need to be.</p>
<p>I've got a long running (not long actually, it only takes 10-12 secs) python script that silently install a... | 1 | 2016-07-15T15:05:19Z | 38,641,562 | <p>I was able to resolved problems with my GUI by using mtTkinter and by referring to this <a href="http://stackoverflow.com/questions/14073463/mttkinter-doesnt-terminate-threads">post</a>.</p>
| 0 | 2016-07-28T16:07:49Z | [
"python",
"multithreading",
"python-2.7",
"tkinter",
"subprocess"
] |
Django - Get item from iterable in django template | 38,399,570 | <p>When iterating through a list in one of my Django templates, I'm trying to put in some if logic to say 'if the last items 'type' value is equal to the current item in the loops 'type' value, but it seems that python syntax for doing that is not allowed in a Django template. I know I can use {{ forloop.counter }}, bu... | 0 | 2016-07-15T15:12:00Z | 38,399,707 | <p>There are multiple issues with your code.</p>
<p>As noted by <a href="http://stackoverflow.com/questions/38399570/django-get-item-from-iterable-in-django-template/38399707#comment64207644_38399570">Justin</a>, Django templates do not allow you to access a list element using something like <code>list[index]</code>. ... | 1 | 2016-07-15T15:18:51Z | [
"python",
"django",
"templates",
"iterable"
] |
Django - Get item from iterable in django template | 38,399,570 | <p>When iterating through a list in one of my Django templates, I'm trying to put in some if logic to say 'if the last items 'type' value is equal to the current item in the loops 'type' value, but it seems that python syntax for doing that is not allowed in a Django template. I know I can use {{ forloop.counter }}, bu... | 0 | 2016-07-15T15:12:00Z | 38,399,799 | <p>You should be able to use <a href="https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#ifchanged" rel="nofollow"><code>ifchanged</code></a> for this.</p>
<pre><code>{% for repair in repairs %}
{% ifchanged repair.type %}<div class="col-sm-12" style="border-top: 1px solid grey; border-bottom: 1px so... | 1 | 2016-07-15T15:23:20Z | [
"python",
"django",
"templates",
"iterable"
] |
Django - Get item from iterable in django template | 38,399,570 | <p>When iterating through a list in one of my Django templates, I'm trying to put in some if logic to say 'if the last items 'type' value is equal to the current item in the loops 'type' value, but it seems that python syntax for doing that is not allowed in a Django template. I know I can use {{ forloop.counter }}, bu... | 0 | 2016-07-15T15:12:00Z | 38,400,877 | <p>There is a built-in template tag for your use-case <a href="https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#regroup" rel="nofollow"><code>regroup</code></a></p>
<pre><code>{% regroup repairs by type as types %}
{% for type in types %}
<div class="col-sm-12" style="border-top: 1px solid grey; bo... | 0 | 2016-07-15T16:21:18Z | [
"python",
"django",
"templates",
"iterable"
] |
AttributeError: type object 'class' has no attribute 'stringVar' | 38,399,601 | <p>I am trying to make a GUI program which contain several pages with buttons and labels. I need the program to be able to dynamically change labels by pressing buttons
to interact with labels on pages that I am not currently working at. I have made an example program that runs, but I get an error when trying to chang... | 0 | 2016-07-15T15:13:50Z | 38,400,589 | <p>The error is with this statement:</p>
<pre><code>objectofpage1 = Page1
</code></pre>
<p>You are setting <code>objectofpage1</code> to a <em>class</em>, not an <em>instance</em> of a class. Your program already has an instance, you just need to get the instance which is managed by the controller.</p>
<p>If each p... | 1 | 2016-07-15T16:03:58Z | [
"python",
"python-3.x",
"tkinter"
] |
tensorflow deep neural network for regression always predict same results in one batch | 38,399,609 | <p>I use a tensorflow to implement a simple multi-layer perceptron for regression. The code is modified from standard mnist classifier, that I only changed the output cost to MSE (use <code>tf.reduce_mean(tf.square(pred-y))</code>), and some input, output size settings. However, if I train the network using regression,... | 4 | 2016-07-15T15:14:08Z | 38,404,533 | <p>There is likely a problem with your dataset loading or indexing implementation. If you only modified the cost to MSE, make sure <code>pred</code> and <code>y</code> are correctly being updated and you did not overwrite them with a different graph operation.</p>
<p>Another thing to help debug would be to predict the... | 0 | 2016-07-15T20:25:01Z | [
"python",
"neural-network",
"regression",
"tensorflow"
] |
tensorflow deep neural network for regression always predict same results in one batch | 38,399,609 | <p>I use a tensorflow to implement a simple multi-layer perceptron for regression. The code is modified from standard mnist classifier, that I only changed the output cost to MSE (use <code>tf.reduce_mean(tf.square(pred-y))</code>), and some input, output size settings. However, if I train the network using regression,... | 4 | 2016-07-15T15:14:08Z | 38,615,584 | <p><strong>Short answer</strong>:</p>
<p>Transpose your <code>pred</code> vector using <code>tf.transpose(pred)</code>.</p>
<p><strong>Longer answer</strong>:</p>
<p>The problem is that <code>pred</code> (the predictions) and <code>y</code> (the labels) are not of the same shape: one is a row vector and the other a ... | 4 | 2016-07-27T14:17:38Z | [
"python",
"neural-network",
"regression",
"tensorflow"
] |
Launch my own program in console mode with Linux | 38,399,620 | <p>I wrote a tiny console program in C# for test purpose. It's just an advanced "Hello world", really. Now I need to run it on a RaspberryPi. It's very light (just two imbricated loops, and a json reading method).</p>
<p>The thing is I've never developed on Linux so I don't really know where to start. I'm thinking abo... | 0 | 2016-07-15T15:14:33Z | 38,400,019 | <p>You don't need urwid to print a simple "Hello World!" text in python. (I've seen and it has some cool functionnalities.) And yes, python is a great choice for a raspberry pi, it's lightweight and quite efficient. Although if you want to create a larger program, I would recomend you to develop it in C â even if it ... | 0 | 2016-07-15T15:34:12Z | [
"python",
"linux",
"console",
"raspberry-pi"
] |
How to iterare a dict which its index is a dict | 38,399,685 | <p>If I have an iteration like:</p>
<pre><code>for index in my_dict:
print index.keys()
</code></pre>
<p>Is <code>index</code> possible to be a dictionary in this case? If possible, could you please give me an example of what <code>my_dict</code> will look like?</p>
| -1 | 2016-07-15T15:17:50Z | 38,399,734 | <p><code>index</code> cannot be a <code>dict</code> as dictionary keys must be <em>hashable</em> types. Since dictionaries are themselves not <em>hashable</em>, they can not serve as keys to another dictionary.</p>
<pre><code>for index in my_dict
</code></pre>
<p>iterates over the dictionary keys and will yield the s... | 3 | 2016-07-15T15:19:59Z | [
"python",
"dictionary"
] |
How to iterare a dict which its index is a dict | 38,399,685 | <p>If I have an iteration like:</p>
<pre><code>for index in my_dict:
print index.keys()
</code></pre>
<p>Is <code>index</code> possible to be a dictionary in this case? If possible, could you please give me an example of what <code>my_dict</code> will look like?</p>
| -1 | 2016-07-15T15:17:50Z | 38,399,879 | <p>Dictionaries are an unhashable type in Python so another dictionary cannot be used for as a key (or index) to a parent dictionary but it can be used as a value. </p>
<p>That dictionary would look something like this:</p>
<pre><code>my_dict = {'example': {'key': 0}}
</code></pre>
<p>And if you wanted to loop over ... | 0 | 2016-07-15T15:27:39Z | [
"python",
"dictionary"
] |
Python using requests to perform a GET to receive a application/json object | 38,399,717 | <p>I am trying to get a json object returned from my api. Using python's request framework to GET a json object from the api. Content type returns application/json when run so the content is json.</p>
<pre><code>url = 'theUrl'
response = requests.get(url)
print(response.headers['content-type'])
data = json.load(respon... | 0 | 2016-07-15T15:19:18Z | 38,399,871 | <p>The last two lines make no sense. You call <code>response.json()</code> and then ignore the return value, and then try to call <code>json.loads()</code> on the response itself, rather than the actual response content.</p>
<p>Instead of those two lines, just do <code>data = response.json()</code> which already retur... | 0 | 2016-07-15T15:27:03Z | [
"python",
"json",
"python-requests"
] |
Python using requests to perform a GET to receive a application/json object | 38,399,717 | <p>I am trying to get a json object returned from my api. Using python's request framework to GET a json object from the api. Content type returns application/json when run so the content is json.</p>
<pre><code>url = 'theUrl'
response = requests.get(url)
print(response.headers['content-type'])
data = json.load(respon... | 0 | 2016-07-15T15:19:18Z | 38,400,350 | <p>The return value from requests.get is not a string but an object. The response body is in .text property, thus:</p>
<pre><code>data = json.loads(response.text)
</code></pre>
<p>And you are done</p>
| 0 | 2016-07-15T15:51:43Z | [
"python",
"json",
"python-requests"
] |
Django and virtualenv folders | 38,399,853 | <p>I'm just beginning to develop on Django and I have a question on how to manage my project folder.</p>
<p>Should I put my website folder into my virtual env folder, or at the same level ?</p>
| -3 | 2016-07-15T15:26:13Z | 38,401,744 | <p>Not inside, but i suggest you to create a folder called 'envs' ( for all your virtual envs) and another called 'reps' or 'projects' at the same level (where you can put your projects) in order to have a good directory schema. Just a suggestion of course.</p>
| 0 | 2016-07-15T17:12:57Z | [
"python",
"django",
"virtualenv"
] |
listdir of a network shared folder in Python | 38,399,901 | <p>I have a network shared folder with file path <code>:C\\Local_Reports</code>. I would like to use <code>os.listdir(":C\\Local_Reports")</code>, but the output is <code>['desktop.ini', 'target.lnk']</code>. This is not the correct output obviously. The correct output would be <code>[Daemons, Reports, SQL]</code>. How... | 0 | 2016-07-15T15:28:44Z | 38,400,861 | <p>I'm silly. I figured it out. I just took the target of the Local_Reports folder and wrote <code>os.listdir(r"\\03vs-cmpt04\Local_Reports")</code>. This just searched the network for the folder and listed the correct output: <code>[Daemons, Reports, SQL]</code></p>
| 0 | 2016-07-15T16:19:59Z | [
"python",
"networking",
"operating-system",
"share",
"listdir"
] |
Setting timezone for timestamp data in pandas dataframe | 38,399,927 | <p>I have a frequently changing pandas dataframe of data that looks like this:</p>
<pre><code> date name time timezone
0 2016-08-01 aaa 0900 Asia/Tokyo
1 2016-08-04 bbb 1200 Europe/Berlin
2 2016-08-05 ccc 1400 Europe/London
</code></pre>
<p>The date, time and timezone refer to a delivery... | 1 | 2016-07-15T15:29:42Z | 38,402,506 | <pre><code>import pandas as pd
def convert_to_local_time(row):
return pd.to_datetime(row.datetime).tz_localize(row.timezone)
def convert_to_london_time(row):
return pd.to_datetime(row.datetime_local).tz_convert('Europe/London')
mydf = pd.DataFrame(data={'date':['2016-08-01','2016-08-04','2016-08-05'],
... | 1 | 2016-07-15T18:01:07Z | [
"python",
"pandas"
] |
Setting timezone for timestamp data in pandas dataframe | 38,399,927 | <p>I have a frequently changing pandas dataframe of data that looks like this:</p>
<pre><code> date name time timezone
0 2016-08-01 aaa 0900 Asia/Tokyo
1 2016-08-04 bbb 1200 Europe/Berlin
2 2016-08-05 ccc 1400 Europe/London
</code></pre>
<p>The date, time and timezone refer to a delivery... | 1 | 2016-07-15T15:29:42Z | 38,403,564 | <p>try this:</p>
<pre><code>In [12]: mydf.apply(lambda x: x.datetime_local.tz_localize(x.timezone), axis=1)
Out[12]:
datetime
2016-08-01 09:00:00 2016-08-01 09:00:00+09:00
2016-08-04 12:00:00 2016-08-04 12:00:00+02:00
2016-08-05 14:00:00 2016-08-05 14:00:00+01:00
dtype: object
</code></pre>
| 1 | 2016-07-15T19:13:27Z | [
"python",
"pandas"
] |
NSight gdb error | 38,400,004 | <p>I have a problem with the "pretty printer" option of IDE NSight (eclipse) when I try to debug. I have googled but I have not found a solution to my problem.</p>
<p>When I start to debug, appears the next message:</p>
<pre><code>Traceback (most recent call last):
File "/usr/share/gdb/auto-load/usr/lib/x86_64-linu... | 1 | 2016-07-15T15:33:07Z | 38,402,464 | <p>This sounds like a bug in your gdb installation. <code>gdb.Objfile.xmethods</code> is something that should be provided by the gdb core, which implements <code>gdb.Objfile</code>. So, examining it from <code>/usr/share/gdb/python/gdb/xmethod.py</code> should be ok -- because that is also a file that comes with gdb... | 0 | 2016-07-15T17:58:19Z | [
"python",
"gdb",
"ubuntu-16.04",
"cuda-gdb"
] |
PyQt5 Newbie - Signals and Missing Positional Arguments | 38,400,054 | <p>I developed two windows in QtDesigner (SourceForm, DestinationForm) and used pyuic5 to convert their .ui pages. I am using a third class <code>WController</code> as a way to navigate between the two windows using a stacked widget. I have a button in <code>SourceForm</code> that populates <code>treeWidget</code> with... | 1 | 2016-07-15T15:36:40Z | 38,403,101 | <p>You need to be careful when using <code>pyqtSlot</code>, as it is only too easy to clobber the signature of the slot it is decorating. In your case, it has re-defined the slot as having no arguments, which explains why you are getting that error message. The simple fix is to simply remove it, as your example will wo... | -1 | 2016-07-15T18:41:11Z | [
"python",
"pyqt"
] |
PyQt5 Newbie - Signals and Missing Positional Arguments | 38,400,054 | <p>I developed two windows in QtDesigner (SourceForm, DestinationForm) and used pyuic5 to convert their .ui pages. I am using a third class <code>WController</code> as a way to navigate between the two windows using a stacked widget. I have a button in <code>SourceForm</code> that populates <code>treeWidget</code> with... | 1 | 2016-07-15T15:36:40Z | 38,404,500 | <p>There's already an accepted answer to this question but I'll give mine anyway.</p>
<p>The problematic slot is connected to the <a href="https://doc.qt.io/qt-5/qtreewidget.html#itemChanged" rel="nofollow">itemChanged(QTreeWidgetItem *item, int column)</a> signal, so the <code>pyqtSlot</code> should look like <code>@... | 0 | 2016-07-15T20:21:37Z | [
"python",
"pyqt"
] |
Changing date format in python | 38,400,091 | <p>I have a pandas dataframe with a column containing a date; the format of the original string is <code>YYYY/DD/MM HH:MM:SS</code>.
I am trying to convert the string into a datetime format, by using </p>
<pre><code>df['Date']=pd.to_datetime(df['Data'], errors='coerce')
</code></pre>
<p>but plotting it I can see it d... | 2 | 2016-07-15T15:38:46Z | 38,400,515 | <p>It looks like you're using a non-standard date format. It should be YYYY-MM-DD. Try formating with the strptime() method.</p>
<pre><code>time.strptime('2016/15/07', '%Y/%d/%m')
</code></pre>
<p>If you need to get it to a string after that use time.strftime().</p>
| 0 | 2016-07-15T15:59:49Z | [
"python",
"date",
"datetime",
"pandas",
"dataframe"
] |
Changing date format in python | 38,400,091 | <p>I have a pandas dataframe with a column containing a date; the format of the original string is <code>YYYY/DD/MM HH:MM:SS</code>.
I am trying to convert the string into a datetime format, by using </p>
<pre><code>df['Date']=pd.to_datetime(df['Data'], errors='coerce')
</code></pre>
<p>but plotting it I can see it d... | 2 | 2016-07-15T15:38:46Z | 38,403,218 | <p>Try this:</p>
<pre><code>df['Date'] = pd.to_datetime(df['Data'], format='%Y/%d/%m %H:%M:%S')
</code></pre>
| 0 | 2016-07-15T18:48:54Z | [
"python",
"date",
"datetime",
"pandas",
"dataframe"
] |
How to use list comprehension with .extend list method? | 38,400,096 | <p>For example, this snippet:</p>
<pre><code>out = []
for foo in foo_list:
out.extend(get_bar_list(foo)) # get_bar_list return list with some data
return out
</code></pre>
<p>How to shorten this code using <strong>list comprehension</strong>?</p>
| 1 | 2016-07-15T15:39:01Z | 38,400,126 | <p>If the length of the lists are small, you can do that with summing a generator expression instead:</p>
<pre><code>sum((get_bar_list(foo) for foo in foo_list), [])
</code></pre>
<p>A <a href="http://stackoverflow.com/a/38400183/674039">nested list comprehension</a> is more efficient, but less readable. </p>
| 1 | 2016-07-15T15:40:44Z | [
"python",
"list-comprehension"
] |
How to use list comprehension with .extend list method? | 38,400,096 | <p>For example, this snippet:</p>
<pre><code>out = []
for foo in foo_list:
out.extend(get_bar_list(foo)) # get_bar_list return list with some data
return out
</code></pre>
<p>How to shorten this code using <strong>list comprehension</strong>?</p>
| 1 | 2016-07-15T15:39:01Z | 38,400,180 | <p>You can use a generator expression and <em>consume</em> it with <a href="https://docs.python.org/2.7/library/itertools.html#itertools.chain" rel="nofollow"><code>itertools.chain</code></a>:</p>
<pre><code>from itertools import chain
out = chain.from_iterable(get_bar_list(foo) for foo in foo_list)
</code></pre>
| 5 | 2016-07-15T15:43:28Z | [
"python",
"list-comprehension"
] |
How to use list comprehension with .extend list method? | 38,400,096 | <p>For example, this snippet:</p>
<pre><code>out = []
for foo in foo_list:
out.extend(get_bar_list(foo)) # get_bar_list return list with some data
return out
</code></pre>
<p>How to shorten this code using <strong>list comprehension</strong>?</p>
| 1 | 2016-07-15T15:39:01Z | 38,400,183 | <p>You can use a nested list-comprehension:</p>
<pre><code>out = [foo for sub_item in foo_list for foo in get_bar_list(sub_item)]
</code></pre>
<p>FWIW, I always have a hard time remembering exactly what order things come in for nested list comprehensions and so I usually prefer to use <code>itertools.chain</code> (a... | 4 | 2016-07-15T15:43:30Z | [
"python",
"list-comprehension"
] |
bat file not running when in another folder with Python | 38,400,131 | <p>Very simply I have this code</p>
<pre><code> bat_execution = subprocess.Popen("Bats/test.bat", shell=True, stdout=subprocess.PIPE)
</code></pre>
<p>which returns the error</p>
<pre><code>'Bats' is not recognized as an internal or external command, operable program, or batch file
</code></pre>
<p>However if I mov... | 1 | 2016-07-15T15:40:53Z | 38,400,570 | <p><code>cmd.exe</code> does some interesting things to unquoted input command line arguments. The details can be found in this acticle: <a href="https://blogs.msdn.microsoft.com/twistylittlepassagesallalike/2011/04/23/everyone-quotes-command-line-arguments-the-wrong-way/" rel="nofollow">https://blogs.msdn.microsoft.co... | 2 | 2016-07-15T16:03:08Z | [
"python",
"windows",
"python-2.7",
"batch-file"
] |
Install python-igraph with anaconda2 pip, no C core found. Linux Fedora 24 | 38,400,162 | <p>I want to install igraph for python 2.7.12 from Anaconda 4.1.1 I have Fedora 24. As suggested (<a href="https://anaconda.org/pypi/python-igraph" rel="nofollow">https://anaconda.org/pypi/python-igraph</a>) I used this command line: </p>
<pre><code>pip install -i https://pypi.anaconda.org/pypi/simple python-igraph
</... | 0 | 2016-07-15T15:42:19Z | 38,402,950 | <p>Fedora 24 ...</p>
<blockquote>
<p>checking for g++... no</p>
</blockquote>
<p>Install g++ : # <code>dnf install gcc-c++</code></p>
<p>The igraph libraries, igraph_attributes.h, etc. etc. headers.h : # <code>dnf install igraph-devel</code> (You get version <strong>0.7.1</strong> ).</p>
<p>The python files :</p>... | 1 | 2016-07-15T18:31:11Z | [
"python",
"linux",
"anaconda",
"fedora",
"igraph"
] |
How to add line numbers to a docx document section using python-docx | 38,400,208 | <p>I am using <a href="https://pypi.python.org/pypi/python-docx" rel="nofollow">python-docx</a> to generate some documents.</p>
<p>I can see that there exists a <a href="http://officeopenxml.com/WPsectionLineNumbering.php" rel="nofollow">line numbering property</a> which may be applied to document sections (for the <e... | 0 | 2016-07-15T15:44:38Z | 38,408,377 | <p>Once you have the Section object, you can get the sectPr element with:</p>
<pre><code>sectPr = section._sectPr
</code></pre>
<p>If you Google on <em>'python-docx workaround function OxmlElement'</em> you'll find examples. All elements inherit from lxml _Element so lxml manipulation works. There are also some handy... | 1 | 2016-07-16T06:18:25Z | [
"python",
"xml",
"docx",
"python-docx"
] |
JSON reformating | 38,400,353 | <p>I'm writing a program that is going to trade options.
Using google finance I'm able to get option data in a unfinished json file.</p>
<p>Data can be found <a href="http://www.google.com/finance/option_chain?q=AAPL&output=json" rel="nofollow">here</a>!</p>
<p>If you click the link you will see both the name and... | -1 | 2016-07-15T15:51:58Z | 38,403,128 | <p>Possible duplicate of: <a href="http://stackoverflow.com/questions/11475885/python-replace-regex">python .replace() regex</a></p>
<p>Here is a link to the <a href="https://docs.python.org/3/" rel="nofollow">Python 3.5</a> documentation, please search the libraries/language functionality before you post here. </p>
... | 0 | 2016-07-15T18:42:47Z | [
"c#",
"python",
"json"
] |
Working with tensorflow's shuffle_batch method | 38,400,360 | <p>I'm experimenting with <a href="https://www.tensorflow.org/" rel="nofollow">tensorflow</a> and I'm trying to read from a <code>csv</code> file and print out a batch of its data via <code>shuffle_batch</code>. I've gone throw the <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/io_ops.html#decode_csv... | 0 | 2016-07-15T15:52:13Z | 38,406,023 | <p>Try removing the <code>num_epochs=1</code> from your <code>string_input_producer</code> initializer.</p>
| 0 | 2016-07-15T22:50:24Z | [
"python",
"tensorflow"
] |
Why 'in' is faster than `__contains__`? | 38,400,370 | <p>I thought that <code>in</code> is just a manifest of <code>__contains__</code></p>
<pre><code>In [1]: li = [1, 2, 3, 4, 5]
In [2]: 4 in li
Out[2]: True
In [3]: li.__contains__(4)
Out[3]: True
</code></pre>
<p>However <code>in</code> is 2x faster</p>
<pre><code>In [4]: %timeit 4 in li
10000000 loops, best of 3: ... | 0 | 2016-07-15T15:52:47Z | 38,400,446 | <p>Probably the same reason why <code>{}</code> is faster than <code>dict()</code>. The method call introduces an extra overhead: </p>
<pre><code>>>> from dis import dis
>>> li = [1, 2, 3, 4, 5]
>>> c = lambda: 4 in li
>>> d = lambda: li.__contains__(4)
>>> dis(c)
1 ... | 5 | 2016-07-15T15:56:04Z | [
"python"
] |
Why 'in' is faster than `__contains__`? | 38,400,370 | <p>I thought that <code>in</code> is just a manifest of <code>__contains__</code></p>
<pre><code>In [1]: li = [1, 2, 3, 4, 5]
In [2]: 4 in li
Out[2]: True
In [3]: li.__contains__(4)
Out[3]: True
</code></pre>
<p>However <code>in</code> is 2x faster</p>
<pre><code>In [4]: %timeit 4 in li
10000000 loops, best of 3: ... | 0 | 2016-07-15T15:52:47Z | 38,400,870 | <p>This answer somewhat builds upon the explanation of @MosesKoledoye but without any disassembling of source code.</p>
<p>There are several reasons why the <code>.__contains__</code> is slower than just using <code>in</code>:</p>
<ul>
<li><p>Each time you access a method/function/class/property by using <code>.</cod... | 2 | 2016-07-15T16:20:38Z | [
"python"
] |
Why 'in' is faster than `__contains__`? | 38,400,370 | <p>I thought that <code>in</code> is just a manifest of <code>__contains__</code></p>
<pre><code>In [1]: li = [1, 2, 3, 4, 5]
In [2]: 4 in li
Out[2]: True
In [3]: li.__contains__(4)
Out[3]: True
</code></pre>
<p>However <code>in</code> is 2x faster</p>
<pre><code>In [4]: %timeit 4 in li
10000000 loops, best of 3: ... | 0 | 2016-07-15T15:52:47Z | 38,400,995 | <p>In the standard implementation of Python, <code>in</code> doesn't quite use <code>__contains__</code> directly. <code>in</code> actually uses the C-level <code>sq_contains</code> function pointer in the struct representing an object's type. For types with a <code>__contains__</code> implemented in Python, <code>sq_c... | 2 | 2016-07-15T16:28:41Z | [
"python"
] |
Python Regular Expression Extracting 'name= ....' | 38,400,373 | <p>I'm using a Python script to read data from our corporate instance of JIRA. There is a value that is returned as a string and I need to figure out how to extract one bit of info from it. What I need is the <strong>'name= ....'</strong> and I just need the numbers from that result.</p>
<pre><code><class 'list'>... | -3 | 2016-07-15T15:52:51Z | 38,400,517 | <p>A simple regular expression can do the trick: <code>name=([0-9.]+)</code>.</p>
<p>The primary part of the regex is <code>([0-9.]+)</code> which will search for any digit (<code>0-9</code>) or period (<code>.</code>) in succession (<code>+</code>).</p>
<p>Now, to use this:</p>
<pre><code>import re
pattern = re.com... | 0 | 2016-07-15T15:59:55Z | [
"python",
"regex",
"extract"
] |
Python Regular Expression Extracting 'name= ....' | 38,400,373 | <p>I'm using a Python script to read data from our corporate instance of JIRA. There is a value that is returned as a string and I need to figure out how to extract one bit of info from it. What I need is the <strong>'name= ....'</strong> and I just need the numbers from that result.</p>
<pre><code><class 'list'>... | -3 | 2016-07-15T15:52:51Z | 38,400,524 | <p>Use a <a href="https://docs.python.org/2/howto/regex.html#grouping" rel="nofollow">capturing group</a> to extract the version name:</p>
<pre><code>>>> import re
>>> s = 'com.atlassian.greenhopper.service.sprint.Sprint@6f68eefa[id=30943,rapidViewId=10468,state=CLOSED,name=2016.2.4 - XXXXXXXXXX,star... | 0 | 2016-07-15T16:00:15Z | [
"python",
"regex",
"extract"
] |
Can't print a json value | 38,400,390 | <p>i have this code in python whoose purpose is to send a text file .c .txt (whatever, i've been sending a helloworld.c) through a websocket.</p>
<p>The problem is when i test it, the code doesn't go beyond <code>print("I'm here!")</code></p>
<pre><code> def onMessage_function(self, client_id, message... | 0 | 2016-07-15T15:53:32Z | 38,402,772 | <p>It's hard to tell, but does this work?</p>
<pre><code>def onMessage_function(self, client_id, message):
print("Here's the message I received " + message + "\n\n\n")
loadedMSG = json.loads(message)
if 'file_name' in loadedMSG:
print("I'm here!")
print(loadedMSG['file_name'])
else:
... | 0 | 2016-07-15T18:19:46Z | [
"python",
"json",
"websocket"
] |
Cannot call xml.dom.minidom.parse inside class | 38,400,398 | <p>I am unable to call <code>xml.dom.minidom.parse()</code> within my class</p>
<p>As a sheer example,</p>
<pre><code>class XmlReader:
def __init__(self, xml):
self.xml = xml
DOMTree = xml.dom.minidom.parse("test.xml")
xmlReader = XmlReader("test.xml")
</code></pre>
<p>Throws</p>
<pre><code>File "h... | 1 | 2016-07-15T15:54:04Z | 38,400,556 | <p>Inside your constructor, <code>xml</code> refers to the <strong>parameter</strong> <code>xml</code> instead of the <strong>module</strong> <code>xml</code>. This is called <em>shadowing</em>. Choose a different name for one of them.</p>
<pre><code>import xml as xml_module
</code></pre>
<p>or</p>
<pre><code>from x... | 3 | 2016-07-15T16:02:33Z | [
"python",
"xml",
"minidom"
] |
python multiple lines as one group | 38,400,403 | <p>If I plot various disjoint lines with one call as follows...</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> x = [random.randint(0,9) for i in range(10)]
>>> y = [random.randint(0,9) for i in range(10)]
>>> data = []
>>> for i in range(0,10,2):
... data.append... | 3 | 2016-07-15T15:54:12Z | 38,401,995 | <p>How about this?</p>
<pre><code>import numpy as np
d = np.asarray(data)
plt.plot(d[:,0],d[:,1])
plt.show()
</code></pre>
| 0 | 2016-07-15T17:27:47Z | [
"python",
"matplotlib",
"plot"
] |
python multiple lines as one group | 38,400,403 | <p>If I plot various disjoint lines with one call as follows...</p>
<pre><code>>>> import matplotlib.pyplot as plt
>>> x = [random.randint(0,9) for i in range(10)]
>>> y = [random.randint(0,9) for i in range(10)]
>>> data = []
>>> for i in range(0,10,2):
... data.append... | 3 | 2016-07-15T15:54:12Z | 38,402,118 | <p>If you don't mind them all being merged into one line than you should simply use <code>plt.plot(x,y)</code>. However I think you would like to keep them as separate lines. For this you can specify the style arguments to your plot comamnd and then use the code from <a href="http://stackoverflow.com/questions/13588920... | 1 | 2016-07-15T17:34:44Z | [
"python",
"matplotlib",
"plot"
] |
Mutiple input() statements skip lines | 38,400,416 | <p>I'm using python 3.5.1 and I've had this problem with a few scripts. When I have multiple <code>input()</code> lines in a row, the ipython window will skip lines in between them. Here's my code:</p>
<pre><code>def DMScalc(D, M, S):
if D < 0.:
DD = D + M*(-1)/60 + S*(-1)/3600
else:
DD = D ... | 0 | 2016-07-15T15:54:56Z | 38,403,925 | <p>With the <code>input()</code> function alone you can't.</p>
<p>Try the <a href="https://docs.python.org/3/library/curses.html" rel="nofollow">Curses</a> library so you can take more control of terminal behaviour, because <code>input()</code> will always give you a new line.</p>
| 0 | 2016-07-15T19:38:29Z | [
"python",
"python-3.x"
] |
Example code for Scrapy process_links and process_request | 38,400,489 | <p>I am new to Scrapy and I was hoping if anyone can give me good example codes of when process_links and process_request are most useful. I see that process_links is used to filter URL's but I don't know how to code it. </p>
<p>Thank you. </p>
| 2 | 2016-07-15T15:58:32Z | 38,405,736 | <p>You mean <code>scrapy.spiders.Rule</code> that is most commonly used in <code>scrapy.CrawlSpider</code></p>
<p>They do pretty much what the names say or in other words that act as sort of middleware between the time the link is extracted and processed/downloaded.</p>
<p><code>process_links</code> sits between when... | 2 | 2016-07-15T22:18:12Z | [
"python",
"scrapy"
] |
SQLite3 Integer and CURRENT_TIMESTAMP | 38,400,516 | <p>I have a column of type INTEGER to which I insert a value using the following statement:</p>
<pre><code>connection.execute("INSERT INTO ActiveTable (IDPK, Time) VALUES (NULL, CURRENT_TIMESTAMP)")
</code></pre>
<p>But the data stores unicode in the format: yyyy-mm-dd hh:mm:ss</p>
<p>How can an INTEGER field store ... | 0 | 2016-07-15T15:59:52Z | 38,400,879 | <p>SQLite uses dynamic typing. It does not enforce data type constraints. So it do the saving-is-first strategy, saving you data is the the main job and when the data type is not matching the defined type SQLite would converts it in some particular principles. </p>
<p>More info: <a href="https://www.sqlite.org/faq.h... | 1 | 2016-07-15T16:21:21Z | [
"python",
"sqlite3"
] |
MySQLdb TypeError: not all arguments converted | 38,400,546 | <p>I have read other entries of the same error, and have attempted their solutions, but have had no luck with my code.</p>
<pre><code>columns = ['city', 'state', 'zip', 'latitude', 'longitude']
placeholder = '?'
statement = """LOAD DATA LOCAL INFILE '/Path/To/My/File""" + table_name + """.csv'
INTO TABLE propertyData.... | 0 | 2016-07-15T16:01:35Z | 38,400,842 | <p>String formatting with the <code>%</code> operator requires you to use printf-style format strings (i.e. <code>%s</code>, not <code>?</code>). Therefore, if you want to interpolate the column names using the <code>%</code> operator, do this:</p>
<pre><code>statement = """LOAD DATA LOCAL INFILE '/Path/To/My/File/{}.... | 0 | 2016-07-15T16:19:06Z | [
"python",
"mysql-python"
] |
Py2exe error: [Errno 2] No such file or directory | 38,400,576 | <pre><code>C:\Users\Shalia\Desktop\accuadmin>python setup_py2exe.py py2exe
running py2exe
10 missing Modules
------------------
? PIL._imagingagg imported from PIL.ImageDraw
? PyQt4 imported from PIL.ImageQt
? PyQt5 imported from PI... | 1 | 2016-07-15T16:03:27Z | 38,532,225 | <p>One method is to use Python 3.4.
Another solution is to go to your Python Directory, in my case, <code>C:\Program Files\Python35</code>, then go to the <code>Lib</code> directory, then go to the <code>site-packages</code> directory (if you installed Py2Exe with <code>pip</code>). Then, copy the <code>run-py3.4-win32... | 0 | 2016-07-22T17:29:12Z | [
"python",
"pip",
"py2exe"
] |
Packages missing in current osx-64 and channels | 38,400,676 | <p>After trying to recreate an environment using a file I got this error:
<code>
Error: Packages missing in current osx-64 channels:
- timbr-io::argh 0.26.1 py27_0
- timbr-io::pathtools 0.1.2 py27_0
- timbr-io::watchdog 0.8.3 py27_0
</code></p>
<p>And the same error running those commands on a docker container.
... | 2 | 2016-07-15T16:08:34Z | 38,508,529 | <p>You cannot take a conda environment exported from one Operating System and use it on another.</p>
<p>The package numbers (and in some cases the package existence) are not aligned on different platforms.</p>
<p><code>conda env export</code> is so you can reproduce the same env on that same OS.</p>
| 1 | 2016-07-21T15:37:21Z | [
"python",
"anaconda",
"conda",
"miniconda"
] |
Calculate 30 minute averages and Seasonal averages in python? | 38,400,732 | <p>I want to write a script computing the 30 minute averages for direct and diffuse radiation (i.e 12:00, 12:30, 1:00...). After the 30 minute averages are computed, I would need to separate the data into seasons (DJF) (MAM) (JJA) (SON). Values that equal = -99999 should be omitted. </p>
<p>Here is the first few lines... | 0 | 2016-07-15T16:12:21Z | 38,403,639 | <p>Consider calculating your needed plot dimensions: hourly date/time and season. Then run a <code>groupby()</code> mean aggregation for plotting:</p>
<pre><code>from io import StringIO
import pandas as pd
import numpy as np
import time, datetime
data = '''DATE,month,day,year,EST,Direct NIP,Diffuse PSP (sband corr)
4... | 0 | 2016-07-15T19:18:42Z | [
"python",
"excel",
"csv"
] |
How to delete a disk with azure-sdk-for-python? | 38,400,740 | <p>I'm using <em>azure-sdk-for-python</em> to create and delete VMs.</p>
<p><a href="https://github.com/Azure/azure-sdk-for-python" rel="nofollow">https://github.com/Azure/azure-sdk-for-python</a></p>
<p><a href="http://azure-sdk-for-python.readthedocs.io/en/latest/" rel="nofollow">http://azure-sdk-for-python.readthe... | 1 | 2016-07-15T16:12:51Z | 38,401,141 | <p>You can use the <a href="https://pypi.python.org/pypi/azure-mgmt-storage" rel="nofollow">Storage Management SDK</a> to get the storage_account_key without writing it explicitly:
<a href="http://azure-sdk-for-python.readthedocs.io/en/latest/resourcemanagementstorage.html#get-storage-account-keys" rel="nofollow">http:... | 1 | 2016-07-15T16:37:05Z | [
"python",
"azure"
] |
How to delete a disk with azure-sdk-for-python? | 38,400,740 | <p>I'm using <em>azure-sdk-for-python</em> to create and delete VMs.</p>
<p><a href="https://github.com/Azure/azure-sdk-for-python" rel="nofollow">https://github.com/Azure/azure-sdk-for-python</a></p>
<p><a href="http://azure-sdk-for-python.readthedocs.io/en/latest/" rel="nofollow">http://azure-sdk-for-python.readthe... | 1 | 2016-07-15T16:12:51Z | 39,939,249 | <p>Here's a little more code:</p>
<pre><code>storage_account = <name of storage account>
storage_client = StorageManagementClient(...)
keys = storage_client.storage_accounts.list_keys(...)
for key in keys:
# Use the first key; adjust accordingly if your set up is different
break
block_blob_service = ... | 0 | 2016-10-09T02:06:28Z | [
"python",
"azure"
] |
Ruby 2.1.5 and RubyPython 0.6.3- RubyPython::InvalidInterpreter: An invalid interpreter was specified | 38,400,748 | <p>I'm trying to use RubyPython on Debian 8 and have been unable to. <code>RubyPython.start</code> always raises an <code>InvalidInterpreter</code> exception. I've tried specifying the python interpreter executable but it doesn't matter. The snipped below shows my versions and attempting to start it from pry</p>
<pre>... | 0 | 2016-07-15T16:13:20Z | 38,408,460 | <p>I run <code>strace -ff -o /tmp/pry.txt pry</code> to see what happens when <code>require rubypython</code> and <code>RubyPython.start</code> are entered. There was lines like</p>
<pre><code>stat("/usr/lib/libpython2.7.so", 0x7ffd2bf4cde0) = -1 ENOENT (No such file or directory)
</code></pre>
<p>meaning that rubypy... | 1 | 2016-07-16T06:30:14Z | [
"python",
"ruby",
"rubypython"
] |
PyTables + Pandas Select Problems | 38,400,755 | <p>I have a HDF5 (PyTables) file structured like this:</p>
<pre><code>/<User>/<API Key>
ex:
/Dan/A4N5
/Dan/B8P0
/Dave/D3Y7
</code></pre>
<p>Each table is structured like so with a sessionID and a time stored in epoch:</p>
<pre><code> sessionID time
0 3ODE3Nzll 1467590400
1 lMGVkMDc4 14675... | 2 | 2016-07-15T16:13:48Z | 38,401,560 | <p>Here is a working demo:</p>
<pre><code>import io
import pandas as pd
df = pd.read_csv(io.StringIO("""
sessionID time
3ODE3Nzll 1467590400
lMGVkMDc4 1467590400
jNzIzNmY1 1467590400
3ODE3Nzll 1467676800
lMGVkMDc4 1467676800
jNzIzNmY1 1467676800
"""), sep='\s+')
filename = 'c:/temp/aaa.h5'
store = pd.H... | 1 | 2016-07-15T17:00:41Z | [
"python",
"pandas",
"pytables"
] |
PyMongo query not returning results although the same query returns results in mongoDB shell | 38,400,767 | <pre><code>import pymongo
uri = 'mongodb://127.0.0.1:27017'
client = pymongo.MongoClient(uri)
db = client.TeamCity
students = db.students.find({})
for student in students:
print (student)
</code></pre>
<hr>
<p>Python Result:</p>
<h2>Blank</h2>
<p>MongoDB: Results </p>
<pre><code>db.students.find({})
{ "_id" :... | 0 | 2016-07-15T16:14:27Z | 38,401,986 | <p>Try your pymongo code like so, i.e. changing <code>TeamCity</code> to <code>Teamcity</code> </p>
<p>Print all students:</p>
<pre><code>import pymongo
uri = 'mongodb://127.0.0.1:27017'
client = pymongo.MongoClient(uri)
db = client.Teamcity
students = db.students.find({})
for student in students:
print (student... | 0 | 2016-07-15T17:27:16Z | [
"python",
"mongodb",
"pymongo"
] |
execute python with arguments | 38,400,788 | <p>I am trying to invoke a Python script that accepts arguments to backup a PostgreSQL database in VMware.</p>
<p>Code is like this:</p>
<pre class="lang-bsh prettyprint-override"><code># path to where you want to save the backup to
$filepath = "D:\pgbackups\"
# filename you want to call the backup
$filename = "to... | 1 | 2016-07-15T16:15:44Z | 38,409,574 | <p>Don't define your commandline as a string (unless you want to run it via <code>Invoke-Expression</code>, which I wouldn't recommend in most cases). Simply use the <a href="https://technet.microsoft.com/en-us/library/hh847732.aspx" rel="nofollow">call operator</a> (<code>&</code>) and put your arguments like you ... | 0 | 2016-07-16T09:14:18Z | [
"python",
"powershell"
] |
Finding complicated unique elements | 38,400,790 | <p>I have two following arrays:</p>
<pre><code>a = [[1,'string',2,3],[2,'otherstring', 6,1],[1, 'otherstring',2,3]]
b = [[7,'anotherstring',4,3],[1,'string',2,3]]
</code></pre>
<p>which in real of course are a lot bigger.
I need to find unique elements:</p>
<pre><code>>>> unique(a,b)
[[1,"string",2,3],[2,'o... | 1 | 2016-07-15T16:15:48Z | 38,401,051 | <pre><code>set(tuple(item) for item in a+b)
</code></pre>
<p>output:</p>
<pre><code>set([(2, 'otherstring', 6, 1), (1, 'string', 2, 3), (7, 'anotherstring', 4, 3), (1, 'otherstring', 2, 3)])
</code></pre>
| 2 | 2016-07-15T16:31:29Z | [
"python",
"python-3.x",
"numpy"
] |
Finding complicated unique elements | 38,400,790 | <p>I have two following arrays:</p>
<pre><code>a = [[1,'string',2,3],[2,'otherstring', 6,1],[1, 'otherstring',2,3]]
b = [[7,'anotherstring',4,3],[1,'string',2,3]]
</code></pre>
<p>which in real of course are a lot bigger.
I need to find unique elements:</p>
<pre><code>>>> unique(a,b)
[[1,"string",2,3],[2,'o... | 1 | 2016-07-15T16:15:48Z | 38,413,686 | <p>The <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package can solve such problems in a vectorized manner:</p>
<pre><code>import numpy_indexed as npi
npi.unique(tuple(zip(a+b)))
</code></pre>
| 0 | 2016-07-16T17:20:27Z | [
"python",
"python-3.x",
"numpy"
] |
django: Bulk update objects with ManyToMany | 38,400,889 | <p>I have the following problem: I need to update a set of objects with the same many_to_many field. So lets say I have the following models</p>
<pre><code>class Blog:
name = CharField
users = M2M(User)
class User:
name = CharField
</code></pre>
<p>And now trying something like
<code>users = Users.object... | 1 | 2016-07-15T16:22:01Z | 38,401,722 | <p>What you can do is to use <code>bulk_create</code> on the intermediate model of the M2M relation.</p>
<p>What I can see from you example is that you want to assign the same set of users for a group of blogs.</p>
<p>So an example implementation would look like: </p>
<pre><code>users = Users.objects.filter(**somefi... | 1 | 2016-07-15T17:11:21Z | [
"python",
"django"
] |
fillna() produces NaN values | 38,400,893 | <p>I am using the following code to fill the <code>NaN</code> values and then adding a column to the <code>DataFrame</code> which would contain the number of values in a row which are greater than 0. Here's the code:</p>
<pre><code>df.fillna(0, inplace=True)
dfMin10 = df
dfMin10['Sum'] = (dfMin10.iloc[1:len(dfMin10.co... | 1 | 2016-07-15T16:22:24Z | 38,401,111 | <p>Are you seeing <code>NaN</code> in the first <code>sum</code> entry? This line:</p>
<pre><code>branchConceptsWithScoresMin10['Sum'] = (branchConceptsWithScoresMin10.iloc[1:len(branchConceptsWithScoresMin10.columns)] > 0).sum(1)
</code></pre>
<p>Should this be:</p>
<pre><code>branchConceptsWithScoresMin10['Sum'... | 3 | 2016-07-15T16:34:55Z | [
"python",
"pandas",
"dataframe",
"na"
] |
Python - Flipping 2 characters of each word in a sentence | 38,400,913 | <p>My function randomly flips 2 characters of a word besides the first and last character. I want to use this function to write another function <code>build_sentence(string)</code> that uses my function to flip 2 characters of each word in the sentence. The function <code>build_sentence(string)</code> should return a s... | 0 | 2016-07-15T16:23:21Z | 38,401,076 | <p>Assuming you're happy with your current word scrambling function (with a small change so it doesn't error on words with 3 or fewer letters):</p>
<pre><code>import random
def Scramble(word):
if len(word) > 3:
i = random.randint(1, len(word) - 2)
j = random.randint(1, len(word) - 3)
if... | 0 | 2016-07-15T16:32:47Z | [
"python",
"python-2.7"
] |
Python - Flipping 2 characters of each word in a sentence | 38,400,913 | <p>My function randomly flips 2 characters of a word besides the first and last character. I want to use this function to write another function <code>build_sentence(string)</code> that uses my function to flip 2 characters of each word in the sentence. The function <code>build_sentence(string)</code> should return a s... | 0 | 2016-07-15T16:23:21Z | 38,401,127 | <p>Have you tried:</p>
<pre><code>' '.join(scramble(word) for word in phrase.split(' '))
</code></pre>
| 1 | 2016-07-15T16:36:09Z | [
"python",
"python-2.7"
] |
Take X number of values from RDD per label | 38,400,964 | <p>I have an RDD that looks like this:</p>
<pre><code>[Row(label=1,data='asd'),
Row(label=2,data='asd'),
Row(label=1,data='asd'),
Row(label=3,data='asd'),
Row(label=4,data='asd'),
Row(label=3,data='asd'),
....
]
</code></pre>
<p>The number of samples I have for each label is not very even and I would like to get a f... | 0 | 2016-07-15T16:26:32Z | 38,415,971 | <p>How many different labels do you have ? and do you know all of them ?
Do you want exactly 5 (and risking going thought the whole list that I assume to be very long ?</p>
<ul>
<li>I assume that your list of <code>Row</code> is named <code>data</code></li>
<li>I assume that your <code>Row</code> objects can call labe... | 0 | 2016-07-16T21:49:52Z | [
"python",
"apache-spark",
"rdd"
] |
Import numpy not working on Python 2.7 notebook? | 38,401,014 | <p>I installed python using Anaconda on Ubuntu, which installed the default version 3. However, I'm following the Titanic Kaggle tutorial, which uses 2.7 and is therefore throwing me a lot of errors. I managed to install Python 2.7 to use with my Jupyter notebook, but whenever I tried to import numpy it tells me there ... | 1 | 2016-07-15T16:29:36Z | 38,426,327 | <p>On Ubuntu, life is pretty easy, and there are packages for <code>numpy</code> for python2 and python3.</p>
<pre><code>sudo apt-get install python-numpy python3-numpy -y
</code></pre>
<p>That should patch you up. The <code>numpy</code> package was available for me in both the Python 2 and Python 3 kernels, running ... | 0 | 2016-07-17T21:59:22Z | [
"python",
"python-2.7",
"numpy",
"anaconda",
"jupyter"
] |
Keeping track of directory tree in python | 38,401,030 | <p>Assume I have a directory tree such as:</p>
<pre><code>rootdir
|---subdir1
|---a1.txt
|---b1.txt
|---c1.txt
|---subdir2
|---a2.txt
|---b2.txt
|---c2.txt
</code></pre>
<p>I want to do some plot operations on the txt files that are located only within their res... | 0 | 2016-07-15T16:30:11Z | 38,402,203 | <p>Assuming the directory tree is this simple, try:</p>
<pre><code>for d in os.walk(rootdir):
#start a new figure
for f in d[2]:
#pull data from file
#plot data on current figure
#save figure to d[0]+/abc.png
</code></pre>
<p>This method keeps things grouped up by directory. If the directo... | 0 | 2016-07-15T17:40:36Z | [
"python",
"directory",
"operating-system"
] |
Cannot properly position QGraphicsRectItem in scene | 38,401,086 | <p>I cannot figure this out for the life of me, but I've boiled this down to a self contained problem. </p>
<p>What I am trying to do, is draw a <code>QGraphicsRectItem</code> around the items that are selected in a <code>QGraphicsScene</code>. After the rect is drawn it can be moved in a way that moves all of the ite... | 1 | 2016-07-15T16:33:44Z | 38,404,829 | <p>I don't have PyQt installed, but I've run into similar issues with the regular QT and <code>QGraphicsRectItem</code>.</p>
<p>I think you've mixed some things up regarding the coordinate system. The bounding-rect of every <code>QGraphicsItem</code> is in local coordinates. The Point (0,0) in local-coordinates appear... | 1 | 2016-07-15T20:51:48Z | [
"python",
"c++",
"qt",
"pyqt",
"qgraphicsitem"
] |
Does AWS Lambda allows to upload binaries separately to avoid re-upload | 38,401,090 | <p>I am new to AWS Lambda, I have phantomjs application to run there.
There is a python script of 5 kb and phantomjs binary which makes the whole uploadable zip to 32MB.
And I have to upload this bunch all the time. Is there any way of pushing phantomjs binary to AWS lambda /bin folder separately ?</p>
| 0 | 2016-07-15T16:33:59Z | 38,442,640 | <p>No, there is no way to accomplish this. Your Lambda function is always provisioned as a whole from the latest zipped package you provide (or S3 bucket/key if you choose that method). </p>
| 0 | 2016-07-18T17:25:24Z | [
"python",
"amazon-web-services",
"aws-lambda",
"continuous-deployment"
] |
How to count one specific word in Python? | 38,401,099 | <p>I want to count a specific word in the file.</p>
<p>For example how many times does 'apple' appear in the file.
I tried this:</p>
<pre><code>#!/usr/bin/env python
import re
logfile = open("log_file", "r")
wordcount={}
for word in logfile.read().split():
if word not in wordcount:
wordcount[word] = 1... | 2 | 2016-07-15T16:34:27Z | 38,401,151 | <p>You could just use <a href="https://docs.python.org/3/library/stdtypes.html#str.count" rel="nofollow"><code>str.count()</code></a> since you only care about occurrences of a single word:</p>
<pre><code>with open("log_file") as f:
contents = f.read()
count = contents.count("apple")
</code></pre>
<p>However,... | 5 | 2016-07-15T16:37:48Z | [
"python"
] |
How to count one specific word in Python? | 38,401,099 | <p>I want to count a specific word in the file.</p>
<p>For example how many times does 'apple' appear in the file.
I tried this:</p>
<pre><code>#!/usr/bin/env python
import re
logfile = open("log_file", "r")
wordcount={}
for word in logfile.read().split():
if word not in wordcount:
wordcount[word] = 1... | 2 | 2016-07-15T16:34:27Z | 38,401,167 | <p>If you only care about one word then you do not need to create a dictionary to keep track of every word count. You can just iterate over the file line-by-line and find the occurrences of the word you are interested in.</p>
<pre><code>#!/usr/bin/env python
logfile = open("log_file", "r")
wordcount=0
my_word="appl... | 6 | 2016-07-15T16:38:51Z | [
"python"
] |
How to count one specific word in Python? | 38,401,099 | <p>I want to count a specific word in the file.</p>
<p>For example how many times does 'apple' appear in the file.
I tried this:</p>
<pre><code>#!/usr/bin/env python
import re
logfile = open("log_file", "r")
wordcount={}
for word in logfile.read().split():
if word not in wordcount:
wordcount[word] = 1... | 2 | 2016-07-15T16:34:27Z | 38,401,230 | <p>This is an example of counting words in array of words. I am assuming file reader will be pretty much similar.</p>
<pre><code>def count(word, array):
n=0
for x in array:
if x== word:
n+=1
return n
text= 'apple orange kiwi apple orange grape kiwi apple apple'
ar = text.split()
print... | 0 | 2016-07-15T16:43:00Z | [
"python"
] |
How to count one specific word in Python? | 38,401,099 | <p>I want to count a specific word in the file.</p>
<p>For example how many times does 'apple' appear in the file.
I tried this:</p>
<pre><code>#!/usr/bin/env python
import re
logfile = open("log_file", "r")
wordcount={}
for word in logfile.read().split():
if word not in wordcount:
wordcount[word] = 1... | 2 | 2016-07-15T16:34:27Z | 38,401,496 | <p>You can use the <code>Counter</code> dictionary for this</p>
<pre><code>from collections import Counter
with open("log_file", "r") as logfile:
word_counts = Counter(logfile.read().split())
print word_counts.get('apple')
</code></pre>
| 0 | 2016-07-15T16:57:14Z | [
"python"
] |
loop iteration - rewriting the output file | 38,401,105 | <p>I currently have this code that successfully reads information from two sources and correctly formats them into an output file \_spec_final.t15. Currently the information prints one after another, but I would like it to print the information for one line/file then overwrite it with the next iteration. Does anybody k... | 0 | 2016-07-15T16:34:31Z | 38,401,299 | <p>Open and write to the file after you read in <code>infofile</code>. </p>
<p>It will open and overwrite <code>\_spec_final.t15</code> with each iteration.</p>
<pre><code>with open('info.txt', 'rt') as infofile:
for count, line in enumerate(infofile):
print count
with open('\\_spec_final.t15',... | 2 | 2016-07-15T16:46:17Z | [
"python",
"loops",
"io"
] |
Merge two time-series in pandas & extract observations within threshold time difference | 38,401,166 | <p>I have two time series in pandas that have observations at seemingly-random times. The code below will create some example time series:</p>
<pre><code>import numpy as np
import pandas as pd
s1 = pd.Series(data=np.arange(5), index=['2014-05-06 09:15:34', '2014-05-06 09:34:00',
... | 2 | 2016-07-15T16:38:51Z | 38,401,912 | <p>You can first use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.reindex.html" rel="nofollow"><code>reindex</code></a> with <code>method='nearest'</code> and then if values in <code>s2</code> are <code>unique</code>, <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.... | 3 | 2016-07-15T17:22:47Z | [
"python",
"pandas",
"time-series"
] |
Merge two time-series in pandas & extract observations within threshold time difference | 38,401,166 | <p>I have two time series in pandas that have observations at seemingly-random times. The code below will create some example time series:</p>
<pre><code>import numpy as np
import pandas as pd
s1 = pd.Series(data=np.arange(5), index=['2014-05-06 09:15:34', '2014-05-06 09:34:00',
... | 2 | 2016-07-15T16:38:51Z | 38,689,324 | <p>What about a slightly longer solution?</p>
<pre><code>import datetime
d = datetime.timedelta(minutes=10)
ans = [(xi, x, yi, y) for xi, x in zip(s1.index, s1) for yi, y in zip(s2.index, s2) if xi.to_datetime() - d < yi.to_datetime() < xi.to_datetime() + d]
pd.DataFrame(ans, columns=['s1_time', 's1_value', 's2... | 0 | 2016-07-31T23:43:03Z | [
"python",
"pandas",
"time-series"
] |
Messing up my unicode output - but where and how? | 38,401,202 | <p>I am doing a word count on some text files, storing the results in a dictionary. My problem is that after outputting to file, the words are not displayed right even if they were in the original text. (I use TextWrangler to look at them).
For instance, dashes show up as dashes in the original but as <em>\u2014</em> ... | 0 | 2016-07-15T16:41:19Z | 38,403,680 | <p>As your example is partially pseudocode there's no way to run a real test and give you something that runs and has been tested, but from reading what you have provided I think you may misunderstand the way Unicode works in Python 2.</p>
<p>The <code>unicode</code> type (such as is produced via the <code>unicode()</... | 1 | 2016-07-15T19:22:02Z | [
"python",
"file-io",
"unicode",
"encoding",
"nltk"
] |
Generate 24 numbers using 1-12, repeating each number only once | 38,401,261 | <p>This is the code I've written:</p>
<pre><code>import random
numberList = []
while len (numberList) != 24:
number = random.randint (1, 12)
if numberList.count (number) < 2
numberList.append (number)
</code></pre>
<p>My problem with this is the While loop can loop over 100 times before numberList ... | 0 | 2016-07-15T16:44:21Z | 38,401,323 | <p>You can keep track of number you already added twice and remove them from your source of numbers. So instead of of having randomint(1, 12) you will need to modify it to randomly pick from list of integers.</p>
| 0 | 2016-07-15T16:47:36Z | [
"python"
] |
Generate 24 numbers using 1-12, repeating each number only once | 38,401,261 | <p>This is the code I've written:</p>
<pre><code>import random
numberList = []
while len (numberList) != 24:
number = random.randint (1, 12)
if numberList.count (number) < 2
numberList.append (number)
</code></pre>
<p>My problem with this is the While loop can loop over 100 times before numberList ... | 0 | 2016-07-15T16:44:21Z | 38,401,337 | <pre><code>import random
my_list = range(1,13)*2
random.shuffle(my_list)
</code></pre>
| 5 | 2016-07-15T16:48:18Z | [
"python"
] |
Generate 24 numbers using 1-12, repeating each number only once | 38,401,261 | <p>This is the code I've written:</p>
<pre><code>import random
numberList = []
while len (numberList) != 24:
number = random.randint (1, 12)
if numberList.count (number) < 2
numberList.append (number)
</code></pre>
<p>My problem with this is the While loop can loop over 100 times before numberList ... | 0 | 2016-07-15T16:44:21Z | 38,401,385 | <p>Here's some code that will work for Python 2 and 3 (<code>range</code> is a generator in 3 and has to be manually converted to a <code>list</code>):</p>
<pre><code>import random
number_list = list(range(1,13)) * 2
random.shuffle(number_list)
print(number_list)
# [9, 5, 11, 6, 3, 4, 9, 7, 4, 6, 3, 11, 1,
# 12, 8... | 0 | 2016-07-15T16:50:54Z | [
"python"
] |
Generate 24 numbers using 1-12, repeating each number only once | 38,401,261 | <p>This is the code I've written:</p>
<pre><code>import random
numberList = []
while len (numberList) != 24:
number = random.randint (1, 12)
if numberList.count (number) < 2
numberList.append (number)
</code></pre>
<p>My problem with this is the While loop can loop over 100 times before numberList ... | 0 | 2016-07-15T16:44:21Z | 38,401,516 | <p>I think this maybe the solution:</p>
<pre><code> import numpy as np
import random
myArray=np.append((random.sample(range(1,13), 12)),(random.sample(range(1,13), 12)))
print myArray
</code></pre>
| 0 | 2016-07-15T16:58:05Z | [
"python"
] |
Generate 24 numbers using 1-12, repeating each number only once | 38,401,261 | <p>This is the code I've written:</p>
<pre><code>import random
numberList = []
while len (numberList) != 24:
number = random.randint (1, 12)
if numberList.count (number) < 2
numberList.append (number)
</code></pre>
<p>My problem with this is the While loop can loop over 100 times before numberList ... | 0 | 2016-07-15T16:44:21Z | 38,401,871 | <pre><code>reduce(lambda x,y:x+y,[ [i]*2 for i in range(1,13) ])
</code></pre>
<p>output:</p>
<pre><code>[1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12]
</code></pre>
| 1 | 2016-07-15T17:19:58Z | [
"python"
] |
convert Python function to C++ function | 38,401,295 | <p>So I need to crack a hash to solve a puzzle, and I've edited a Python program that iterates over all possible combinations, but the Python program is too slow as the hash changes every day, I know it's a hash of length: 8</p>
<p>The python program would work like this:</p>
<pre><code>charset = "abcdefghijklmnopqrs... | 0 | 2016-07-15T16:46:09Z | 38,401,700 | <p>In this special case, I would not hassle around with the std::string objects all the time. You have a fixed length, right? You can do it very efficiently this way then (works both in C++ and C... – just adjust buffer length and characters list to your own needs):
</p>
<pre><code>char characters[] = { 'a', 'b'... | 1 | 2016-07-15T17:10:00Z | [
"python",
"c++"
] |
Kivy. Changing Layouts | 38,401,358 | <p>I'm something of a newbie to Python and Kivy. After making some progress, I've hit a brick wall and no amount of internet searching can find an answer.</p>
<p>I have a python/kivy script which starts with a GridLayout selection menu. Then I would like to "Click Next" and replace the GridLayout with a BoxLayout to d... | 0 | 2016-07-15T16:49:23Z | 38,401,747 | <p>Your Checkbox calls <code>Test.human(*args)</code> when it is active (pressed/selected), and the last line of <code>Test.human()</code> calls <code>Test.printcharacter()</code> which explains why it is printing before you hit the 'Next' button. </p>
<p>Since your <code>Test</code> class inherits from <code>GridLayo... | 0 | 2016-07-15T17:13:06Z | [
"python",
"kivy"
] |
Elegant way to look at a +/- range surounding a particular value in Python | 38,401,427 | <p>I'm working with a large set of data in a spreadsheet using the openpyxl library.</p>
<p>I need to find certain temperature values and then look at other cells based on that temperature.</p>
<p>the problem is that my temperature fluctuates a bit in its measurements but I don't really care about this.</p>
<p>For e... | 1 | 2016-07-15T16:53:38Z | 38,401,506 | <p>You can test for a value being in a range like this:</p>
<pre><code>for num in [5,10,15,20,25]:
if num in range(24,27):
...
</code></pre>
<p>Note that this doesn't work if your incoming data is floats.
You can of course generate this range using some function that you give a center and a maximum d... | 0 | 2016-07-15T16:57:28Z | [
"python",
"python-3.x",
"openpyxl"
] |
Elegant way to look at a +/- range surounding a particular value in Python | 38,401,427 | <p>I'm working with a large set of data in a spreadsheet using the openpyxl library.</p>
<p>I need to find certain temperature values and then look at other cells based on that temperature.</p>
<p>the problem is that my temperature fluctuates a bit in its measurements but I don't really care about this.</p>
<p>For e... | 1 | 2016-07-15T16:53:38Z | 38,401,517 | <p>What you have now is clear; Python allows you to chain the comparisons like this:</p>
<pre><code>for num in [5,10,15,20,25]:
if num - 1 <= temp <= num + 1:
#do things
</code></pre>
<p>Another alternative is to check the absolute between the two:</p>
<pre><code>for num in [5, 10, 15,... | 3 | 2016-07-15T16:58:10Z | [
"python",
"python-3.x",
"openpyxl"
] |
Elegant way to look at a +/- range surounding a particular value in Python | 38,401,427 | <p>I'm working with a large set of data in a spreadsheet using the openpyxl library.</p>
<p>I need to find certain temperature values and then look at other cells based on that temperature.</p>
<p>the problem is that my temperature fluctuates a bit in its measurements but I don't really care about this.</p>
<p>For e... | 1 | 2016-07-15T16:53:38Z | 38,401,547 | <p>If you just want to adapt what you have a little:</p>
<pre><code>for num in range(5, 30, 5):
if abs(temp - num) < 1:
# do things
</code></pre>
| 2 | 2016-07-15T16:59:57Z | [
"python",
"python-3.x",
"openpyxl"
] |
Elegant way to look at a +/- range surounding a particular value in Python | 38,401,427 | <p>I'm working with a large set of data in a spreadsheet using the openpyxl library.</p>
<p>I need to find certain temperature values and then look at other cells based on that temperature.</p>
<p>the problem is that my temperature fluctuates a bit in its measurements but I don't really care about this.</p>
<p>For e... | 1 | 2016-07-15T16:53:38Z | 38,402,130 | <p>For things like this I wrote a <a href="https://bitbucket.org/charlie_x/python-httparchive/src/69f61eb29b7e48166c0266904eb872ab768e8d16/httparchive/views/utils.py?at=default&fileviewer=file-view-default#utils.py-18" rel="nofollow">generic range comparison function</a> which you could easily extend for use here. ... | 0 | 2016-07-15T17:35:39Z | [
"python",
"python-3.x",
"openpyxl"
] |
Elegant way to look at a +/- range surounding a particular value in Python | 38,401,427 | <p>I'm working with a large set of data in a spreadsheet using the openpyxl library.</p>
<p>I need to find certain temperature values and then look at other cells based on that temperature.</p>
<p>the problem is that my temperature fluctuates a bit in its measurements but I don't really care about this.</p>
<p>For e... | 1 | 2016-07-15T16:53:38Z | 38,402,414 | <p>How about a built in solution? You could just use the <a href="https://docs.python.org/3/library/math.html#math.isclose" rel="nofollow"><strong><code>isclose</code></strong></a> function located in <a href="https://docs.python.org/3/library/math.html" rel="nofollow"><strong><code>math</code></strong></a> (which is a... | 1 | 2016-07-15T17:55:10Z | [
"python",
"python-3.x",
"openpyxl"
] |
"\n" in strings not working | 38,401,450 | <p>I have this little piece of code for my sort of Operating System:</p>
<pre><code>print("Type your document below.")
print("Press enter to save.")
print("Type \\n for a new line.")
file=input()
print("Enter a file name...")
filename=input()
outFile = open(filename, "w+")
outFile.write(file)
outFile.close()
</code></... | 1 | 2016-07-15T16:54:59Z | 38,401,500 | <p><code>\n</code> is an escape sequence that only works in <em>string literals</em>. <code>input()</code> does not take a string literal, it takes the text the user inputs and doesn't do any processing on it so anyone entering <code>\</code> followed by <code>n</code> produces a string of two characters, a backslash a... | 4 | 2016-07-15T16:57:20Z | [
"python",
"string",
"python-3.x",
"newline"
] |
"\n" in strings not working | 38,401,450 | <p>I have this little piece of code for my sort of Operating System:</p>
<pre><code>print("Type your document below.")
print("Press enter to save.")
print("Type \\n for a new line.")
file=input()
print("Enter a file name...")
filename=input()
outFile = open(filename, "w+")
outFile.write(file)
outFile.close()
</code></... | 1 | 2016-07-15T16:54:59Z | 38,401,573 | <p>As Martijn explained you'll need to process the replacements yourself. The easiest way to do that is literally with the <code>.replace</code> method:</p>
<pre><code>>>> print(input('Enter \\n for newline: ').replace('\\n', '\n'))
Enter \n for newline: This is my \nnewline
This is my
newline
</code></pre>
... | 0 | 2016-07-15T17:01:21Z | [
"python",
"string",
"python-3.x",
"newline"
] |
"\n" in strings not working | 38,401,450 | <p>I have this little piece of code for my sort of Operating System:</p>
<pre><code>print("Type your document below.")
print("Press enter to save.")
print("Type \\n for a new line.")
file=input()
print("Enter a file name...")
filename=input()
outFile = open(filename, "w+")
outFile.write(file)
outFile.close()
</code></... | 1 | 2016-07-15T16:54:59Z | 38,402,145 | <p>Note that if you want to support Python-style strings (with not only <code>\n</code> but also <code>\t</code>, <code>\r</code>, <code>\u1234</code>, etc.), you should use <code>codecs.decode</code> with the <code>unicode_escape</code> handler:</p>
<pre><code>contents = input()
contents = codecs.decode(contents, "un... | 0 | 2016-07-15T17:36:44Z | [
"python",
"string",
"python-3.x",
"newline"
] |
PyGame - Unable to blit one surface onto another | 38,401,814 | <p>I am simply trying to create two Surfaces, fill them and then blit one onto the other. However, the second Surface never renders on top of the first. If I blit the second surface onto the display Surface, it renders fine. Not sure if there is a restriction on layering surfaces (other than the display) on top of each... | 0 | 2016-07-15T17:16:55Z | 38,536,923 | <p>Your problem is that you have <code>layer1.blit(layer2, (0,0))</code> after <code>windowSurface.blit(layer1, (0,0))</code> which means you're blitting layer2 to layer1 after layer1 is already done blitting to the window. All you need to do is cut <code>layer1.blit(layer2, (0,0))</code> and paste it ABOVE <code>windo... | 0 | 2016-07-23T00:18:58Z | [
"python",
"pygame"
] |
Scipy.linalg.logm produces an error where matlab does not | 38,401,845 | <p>The line <code>scipy.linalg.logm(np.diag([-1.j, 1.j]))</code> produces an error with scipy 0.17.1, while the same call to matlab, <code>logm(diag([-i, i]))</code>, produces valid output. I already filed a <a href="https://github.com/scipy/scipy/issues/6378" rel="nofollow">bugreport on github</a>, now I am here to as... | 1 | 2016-07-15T17:18:33Z | 38,402,127 | <p>I don't know enough about the calculation to understand the error. But it has something to do division by zero - probably in the real part.</p>
<p>Replacing the zero real part of the array with a small value works:</p>
<pre><code>In [40]: linalg.logm(np.diag([1e-16-1.j,1e-16+1.j]))
Out[40]:
array([[ 5.00000000e... | 1 | 2016-07-15T17:35:32Z | [
"python",
"matlab",
"numpy",
"scipy"
] |
"python myscript" ignores "#!/usr/bin/env pythonX" where pythonX doesn't exist | 38,401,850 | <p><strong>Why doesn't <code>test.py</code> throw error <code>env: python3: No such file or directory</code> when Python 3 is not installed?</strong></p>
<p>My system (Mac OS X) has Python 2.7 installed, but not Python 3:</p>
<pre><code>$ /usr/bin/env python -V
Python 2.7.12
$ /usr/bin/env python3 -V
env: python3: No... | 0 | 2016-07-15T17:18:46Z | 38,401,939 | <p>The shebang is interpreted by OS when it tries to execute the script. Whey you type <code>python test.py</code>, the OS executes <code>python</code> and <code>python</code> executes the script (and <code>python</code> is found based on the current <code>PATH</code>) as opposed to being processed by the OS.</p>
<p>... | 3 | 2016-07-15T17:24:50Z | [
"python",
"osx",
"shebang"
] |
"python myscript" ignores "#!/usr/bin/env pythonX" where pythonX doesn't exist | 38,401,850 | <p><strong>Why doesn't <code>test.py</code> throw error <code>env: python3: No such file or directory</code> when Python 3 is not installed?</strong></p>
<p>My system (Mac OS X) has Python 2.7 installed, but not Python 3:</p>
<pre><code>$ /usr/bin/env python -V
Python 2.7.12
$ /usr/bin/env python3 -V
env: python3: No... | 0 | 2016-07-15T17:18:46Z | 38,401,973 | <p>The shebang is only processed when you do <code>test.py</code>, running the file directly instead of running <code>python</code> with <code>test.py</code> as an argument. When you do <code>python test.py</code>, Python completely ignores the shebang line.</p>
| 2 | 2016-07-15T17:26:42Z | [
"python",
"osx",
"shebang"
] |
How does readline() work behind the scenes when reading a text file? | 38,401,864 | <p>I would like to understand how <code>readline()</code> takes in a single line from a text file. The specific details I would like to know about, with respect to how the compiler interprets the Python language and how this is handled by the CPU, are:</p>
<ol>
<li>How does the <code>readline()</code> know which line ... | 2 | 2016-07-15T17:19:24Z | 38,402,000 | <p>This is a very broad question and it's unlikely that all details about what the CPU does would fit in an answer. But a high-level answer is possible:</p>
<ol>
<li><p><code>readline</code> reads each line in order. It starts by reading chunks of the file from the beginning. When it encounters a line break, it return... | 2 | 2016-07-15T17:28:01Z | [
"python"
] |
How does readline() work behind the scenes when reading a text file? | 38,401,864 | <p>I would like to understand how <code>readline()</code> takes in a single line from a text file. The specific details I would like to know about, with respect to how the compiler interprets the Python language and how this is handled by the CPU, are:</p>
<ol>
<li>How does the <code>readline()</code> know which line ... | 2 | 2016-07-15T17:19:24Z | 38,402,126 | <p>Example using the file <code>file.txt</code>:</p>
<pre><code>fake file
with some text
in a few lines
</code></pre>
<p><strong>Question 1:</strong> How does the readline() know which line of text to read, given that successive calls to readline() read the text line by line?</p>
<p>When you open a file in python, i... | 4 | 2016-07-15T17:35:32Z | [
"python"
] |
DJango 1.8 use completely different CSS on child template | 38,401,889 | <p>I want to do something in DJango templates. I am using Materialize CSS framework for a side bar which has a menu on it, it only has links to some views showing django forms, and that menu is my "base.html", so, it is a parent template. But i have a problem, i don't want to use Materialize CSS forms classes on my chi... | 0 | 2016-07-15T17:21:12Z | 38,402,623 | <p>Dont extend your child template with the parent base template.
Which is dont include this statement in your child templates:</p>
<pre><code>{% extends "<base-file-name>.html" %}
</code></pre>
| 1 | 2016-07-15T18:08:56Z | [
"python",
"html",
"css",
"django",
"templates"
] |
How do I disable OPTIONS method on Django Rest Framework globally? | 38,402,094 | <p>I want to disable <code>OPTIONS</code> method on my API built with Django Rest Framework (DRF) globally (on all the API endpoints)</p>
<p>currently an <code>OPTIONS</code> call returns,</p>
<pre><code>{
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
... | 0 | 2016-07-15T17:33:10Z | 38,402,524 | <p>Just implement a <a href="http://www.django-rest-framework.org/api-guide/permissions/#custom-permissions" rel="nofollow">custom permission class</a>.</p>
<p>your_app/permissions.py (permissions file for your app)</p>
<pre><code>from rest_framework import permissions
class DisableOptionsPermission(permissions.Base... | 0 | 2016-07-15T18:01:56Z | [
"python",
"django",
"rest",
"django-rest-framework"
] |
Python ValueError | 38,402,148 | <p>So I keep receiving this error:</p>
<blockquote>
<p>ValueError: Mixing iteration and read methods would lose data</p>
</blockquote>
<p>And 1) I don't quite understand why I'm receiving it, and 2) people with similar problems seem to be doing things with their code which are much more complex than a beginner (lik... | -1 | 2016-07-15T17:36:51Z | 38,402,205 | <p>To make an array of the lines of the file, with one line per array element:</p>
<pre><code>with open('file.txt','r') as input_file:
array = input_file.readlines()
return array
</code></pre>
<p>since <code>readlines</code> will give you the whole file in one shot. Alternatively, </p>
<pre><code>return list(o... | 2 | 2016-07-15T17:40:44Z | [
"python",
"arrays"
] |
Python ValueError | 38,402,148 | <p>So I keep receiving this error:</p>
<blockquote>
<p>ValueError: Mixing iteration and read methods would lose data</p>
</blockquote>
<p>And 1) I don't quite understand why I'm receiving it, and 2) people with similar problems seem to be doing things with their code which are much more complex than a beginner (lik... | -1 | 2016-07-15T17:36:51Z | 38,402,273 | <p>The error is pretty much self-explanatory (once you know what it is about), so here goes.</p>
<p>You start with the loop <code>for line in input_file:</code>. File objects are iterable in Python. They iterate over the lines in the file. This means that for each iteration of the loop, <code>line</code> will contain ... | 2 | 2016-07-15T17:44:44Z | [
"python",
"arrays"
] |
Disable automatic dismissal of iOS alerts on Device Farm | 38,402,172 | <p>It appears alerts on iOS on Device Farm are automatically dismissed can we disable this dismissal as some of my tests are dependent on those alerts. From what I have found from the forums of AWS is that this feature is not yet available but it was few months before.</p>
<p><a href="https://forums.aws.amazon.com/thr... | 1 | 2016-07-15T17:38:06Z | 38,404,468 | <p>I work for the AWS Device Farm team.</p>
<p>Today, autoAcceptAlert is set to true by default when using Appium.
However, right now we are looking at ways to give user more control over the options that are passed to Appium.
You should see an update on this very soon.
This feature wasn't available anytime before.</... | 1 | 2016-07-15T20:19:21Z | [
"python",
"ios",
"aws-devicefarm"
] |
numpy: Why is there a difference between (x,1) and (x, ) dimensionality | 38,402,227 | <p>I am wondering why in numpy there are one dimensional array of dimension (length, 1) and also one dimensional array of dimension (length, ) w/o a second value.</p>
<p>I am running into this quite frequently, e.g. when using <code>np.concatenate()</code> which then requires a <code>reshape</code> step beforehand (o... | 5 | 2016-07-15T17:41:57Z | 38,402,434 | <p>Much of it is a matter of syntax. This tuple <code>(x)</code> isn't a tuple at all (just a redundancy). <code>(x,)</code>, however, is. </p>
<p>The difference between (x,) and (x,1) goes even further. You can take a look into the examples of previous questions like <a href="http://stackoverflow.com/questions/169950... | 1 | 2016-07-15T17:56:30Z | [
"python",
"numpy"
] |
numpy: Why is there a difference between (x,1) and (x, ) dimensionality | 38,402,227 | <p>I am wondering why in numpy there are one dimensional array of dimension (length, 1) and also one dimensional array of dimension (length, ) w/o a second value.</p>
<p>I am running into this quite frequently, e.g. when using <code>np.concatenate()</code> which then requires a <code>reshape</code> step beforehand (o... | 5 | 2016-07-15T17:41:57Z | 38,403,363 | <p>The data of a <code>ndarray</code> is stored as a 1d buffer - just a block of memory. The multidimensional nature of the array is produced by the <code>shape</code> and <code>strides</code> attributes, and the code that uses them.</p>
<p>The <code>numpy</code> developers chose to allow for an arbitrary number of d... | 7 | 2016-07-15T18:59:24Z | [
"python",
"numpy"
] |
Python cvxopt glpk ilp return first feasible solution | 38,402,234 | <p>I am using cvxopt.glpk.ilp to solve a very complicated Mixed Integer Program. I was wondering if there is a way to get the program to terminate after finding the first solution? It takes too long and a feasible solution would work fine for my purposes.</p>
| 0 | 2016-07-15T17:42:01Z | 38,600,472 | <p>If you're using <a href="https://github.com/coin-or/pulp" rel="nofollow">PuLP</a> (another python library like cvxopt) to invoke glpk to solve MIP, there is one parameter called <code>maxtime</code>. If you set <code>maxtime=1</code> then what will solver do is, terminate search (almost) right after finding the firs... | 0 | 2016-07-26T21:51:23Z | [
"python",
"performance",
"glpk",
"integer-programming",
"cvxopt"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.