title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How to get all the tags in an XML using python?
38,790,012
<p>I have been researching in the Python Docs for a way to get the tag names from an XML file, but I haven't been very successful. Using the XML file below, one can get the country name tags, and all its associated child tags. Does anyone know how this is done?</p> <pre><code>&lt;?xml version="1.0"?&gt; &lt;data&gt; ...
0
2016-08-05T13:05:27Z
38,792,638
<p>Consider using element tree's <code>iterparse()</code> and build nested lists of tag and text pairs. Conditional <code>if</code> logic is used to group country items together and leave out elements with no text, then <code>replace()</code> is used to clean out the line breaks and multiple white spaces that <code>ite...
1
2016-08-05T15:15:21Z
[ "python", "xml", "python-3.x" ]
jedi fails to correctly autocomplete from package with the same name as the module that I'm in
38,790,067
<p>I'm using emacs and I have configured jedi.el so it autocompletes after dot. Let's assume that I'm writing a module <code>my_app.my_module</code> and I have package installed in env called <code>my_module</code>. My file <code>my_app/my_module.py</code> will look like:</p> <pre><code>import my_module class SomeCla...
1
2016-08-05T13:07:41Z
38,911,520
<p>It turned out that this is a problem of <code>jedi</code>, not of <code>jedi.el</code>. Furthermore it seems that this behavior is specific for projects based on <code>pyramid</code> framework.</p>
0
2016-08-12T06:42:33Z
[ "python", "emacs", "autocomplete", "jedi", "emacs-jedi" ]
An Error: 'Numpy.str_' object has no attribute 'decode'
38,790,126
<p>I tried to run a test on Crab(an open source recommender system) based on python3. Then an error occurred:</p> <pre><code>Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; File "/Users/Dennis/anaconda/lib/python3.5/site-packages/scikits/crab/datasets/base.py", line 201, in load_...
0
2016-08-05T13:10:11Z
38,790,266
<p>The problem is that <code>rating</code> is a string within a string, so when you try casting a string like <code>"b'3.0'"</code> into a float, it gives a <code>valueError</code> because you still have the <code>b</code> in front which cannot be converted into float.</p> <p>I imagine you need the byte encoding in fr...
0
2016-08-05T13:16:34Z
[ "python", "python-3.x", "numpy", "attributes" ]
Django 1.10 python 3.5 django-admin-tools
38,790,152
<p>I am using Django 1.10 and installed django-admin-tools. Settings look like this:</p> <pre><code>INSTALLED_APPS = [ 'admin_tools', 'admin_tools.theming', 'admin_tools.menu', 'admin_tools.dashboard', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django...
0
2016-08-05T13:11:21Z
38,790,255
<p>It looks like you are running Django 1.10, not 1.9 as you originally said. In Django 1.10, <code>patterns</code> has been removed (<a href="https://docs.djangoproject.com/en/1.10/releases/1.10/#removed-features-1-10" rel="nofollow">release notes</a>).</p> <p>The issue <a href="https://github.com/django-admin-tools/...
0
2016-08-05T13:15:42Z
[ "python", "django", "django-admin", "django-admin-tools", "django-1.10" ]
Django 1.10 python 3.5 django-admin-tools
38,790,152
<p>I am using Django 1.10 and installed django-admin-tools. Settings look like this:</p> <pre><code>INSTALLED_APPS = [ 'admin_tools', 'admin_tools.theming', 'admin_tools.menu', 'admin_tools.dashboard', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django...
0
2016-08-05T13:11:21Z
38,791,282
<p>It was indeed 1.10 </p> <p>After downloading from github install migrate ran perfectly.</p> <p>However.....</p> <p>When I try to get the dashboard I get a 404 </p> <pre><code>http://127.0.0.1:8000/dashboard/ Using the URLconf defined in cvixweb.urls, Django tried these URL patterns, in this order: 1. ^admin_tool...
0
2016-08-05T14:07:53Z
[ "python", "django", "django-admin", "django-admin-tools", "django-1.10" ]
Socio login in Django
38,790,339
<p>I am trying to build social login in Django, but it is not working fine.</p> <p>How am doing:</p> <ol> <li>Installed python-social-auth</li> <li><p>added this in INSTALLED_APPS:</p> <pre><code>'social.apps.django_app.default', </code></pre></li> <li><p>Migrated DB (with no errors)</p></li> <li><p>Added this in ur...
0
2016-08-05T13:20:07Z
38,790,705
<p>In point six replace</p> <pre><code>href="{% url "social:begin" "facebook"%}" </code></pre> <p>with</p> <pre><code>href="{% url 'social:begin' 'facebook'%}" </code></pre> <p>I think you are running into a problem when the first <code>"</code> in <code>"social:begin"</code> ends the <code>"</code> after <code>hre...
1
2016-08-05T13:37:34Z
[ "python", "django", "facebook", "python-social-auth" ]
generate a heatmap from a dataframe with python and seaborn
38,790,360
<p>I'm new to Python and fairly new to seaborn.</p> <p>I have a pandas dataframe named df which looks like:</p> <pre><code>TIMESTAMP ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F2 ACT_TIME_AERATEUR_1_F3 ACT_TIME_AERATEUR_1_F4 ACT_TIME_AERATEUR_1_F5 ACT_TIME_AERATEUR_1_F6 2015-08-01 23:00:00 80 0 0 0 10 0 2015-08-01 2...
0
2016-08-05T13:20:45Z
38,790,687
<p>Remove the timestamp variables(i.e. first two columns) before passing it to sns.heatmap, no need for the load dataset as well, just use:</p> <pre><code>sns.heatmap(df.iloc[:,2:],annot=True, fmt="d", linewidths=.5) </code></pre> <h1>EDIT</h1> <p>Ok here is your dataframe, just changed the column names in the inter...
0
2016-08-05T13:36:26Z
[ "python", "heatmap", "seaborn" ]
Pandas: parse columns from csv
38,790,368
<p>I have data in csv file without header. I need to parse some columns.</p> <p>A part of data:</p> <pre><code>-1.0,-0.0246259814315,1174.60023796 1.0,-0.978057706084,1083.19880269 -1.0,0.314271994507,-1472.97760911 -1.0,0.179751565771,231.017267343 1.0,-1.26254374278,-778.271726463 -1.0,0.249969939456,-52.801482653...
0
2016-08-05T13:21:07Z
38,792,280
<p>IIUC indices are zero-based so you need:</p> <pre><code>train_X = pd.read_csv("perceptron-train.csv", sep=',', parse_dates=[1], usecols=[1, 2]) </code></pre> <p>Also I don't know if this also means you need to change your date col:</p> <pre><code>train_X = pd.read_csv("perceptron-train.csv", sep=',', parse_dates=...
1
2016-08-05T14:57:38Z
[ "python", "pandas" ]
Python/Pyserial: reading incoming information from port
38,790,422
<p>I've just started using pyserial as I will eventually need to read/save information coming from a particular port. Using the following code I am merely printing the port used and then trying to write and then read in some text ("hello"). The port is printing fine, but the output of my string is coming out as 5. Any ...
1
2016-08-05T13:23:55Z
38,790,810
<pre><code>x = ser.write("hello") print x </code></pre> <p>You writing this as sended. It's not recieved info. Probably it writes the lenght of string you have sended. First you need to have a client side script which will response your sended information.</p> <p>And you have to use something like this on it.</p> <p...
0
2016-08-05T13:44:02Z
[ "python", "pyserial", "virtual-serial-port" ]
Python/Pyserial: reading incoming information from port
38,790,422
<p>I've just started using pyserial as I will eventually need to read/save information coming from a particular port. Using the following code I am merely printing the port used and then trying to write and then read in some text ("hello"). The port is printing fine, but the output of my string is coming out as 5. Any ...
1
2016-08-05T13:23:55Z
38,792,398
<p>you can do it this way to test it. Firstly create a pair of ports in manage ports</p> <p>First port: COM199 Second Port: COM188</p> <p>Click Add Pair</p> <p><strong>On one console/script do the below steps:</strong></p> <pre><code>&gt;&gt;&gt; import serial &gt;&gt;&gt; ser = serial.Serial('COM196', 9600,timeout...
1
2016-08-05T15:03:24Z
[ "python", "pyserial", "virtual-serial-port" ]
Python: How to plot heat map of 2D matrix by ignoring zeros?
38,790,536
<p>I have a matrix of size 500 X 28000, which contains a lot of zeros in between. But let us consider a working example with the matrix A: </p> <pre><code>A = [[0, 0, 0, 1, 0], [1, 0, 0, 2, 3], [5, 3, 0, 0, 0], [5, 0, 1, 0, 3], [6, 0, 0, 9, 0]] </code></pre> <p>I would like to plot a heatmap of the ab...
1
2016-08-05T13:29:24Z
38,790,834
<p>If you remove the LogNorm, you get black squares instead of white:</p> <pre><code>im = plt.matshow(A, cmap=plt.cm.hot, aspect='auto') # pl is pylab imported a pl </code></pre> <p><a href="http://i.stack.imgur.com/05OBj.png" rel="nofollow"><img src="http://i.stack.imgur.com/05OBj.png" alt="enter image description h...
2
2016-08-05T13:45:26Z
[ "python", "python-2.7", "matplotlib", "heatmap", "colormap" ]
Python: How to plot heat map of 2D matrix by ignoring zeros?
38,790,536
<p>I have a matrix of size 500 X 28000, which contains a lot of zeros in between. But let us consider a working example with the matrix A: </p> <pre><code>A = [[0, 0, 0, 1, 0], [1, 0, 0, 2, 3], [5, 3, 0, 0, 0], [5, 0, 1, 0, 3], [6, 0, 0, 9, 0]] </code></pre> <p>I would like to plot a heatmap of the ab...
1
2016-08-05T13:29:24Z
38,792,917
<p>This answer is in the same direction as 'Edit 2' section of Luis' answer. In fact, this is a simplified version of it. I am posting this just in order to correct my misleading statements in my comments. I saw a warning that we should not discuss in the comment area, so I am using this answering area.</p> <p>Anyway,...
1
2016-08-05T15:31:36Z
[ "python", "python-2.7", "matplotlib", "heatmap", "colormap" ]
Python: How to plot heat map of 2D matrix by ignoring zeros?
38,790,536
<p>I have a matrix of size 500 X 28000, which contains a lot of zeros in between. But let us consider a working example with the matrix A: </p> <pre><code>A = [[0, 0, 0, 1, 0], [1, 0, 0, 2, 3], [5, 3, 0, 0, 0], [5, 0, 1, 0, 3], [6, 0, 0, 9, 0]] </code></pre> <p>I would like to plot a heatmap of the ab...
1
2016-08-05T13:29:24Z
39,510,090
<p>Although the answer of norio is correct. I think one can give a much more to the point quick answer with only a few lines of code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt A = np.asarray(A) x,y = A.nonzero() #get the notzero indices plt.scatter(x,y,c=A[x,y],s=100,cmap='hot',marker='s') #adj...
0
2016-09-15T11:36:35Z
[ "python", "python-2.7", "matplotlib", "heatmap", "colormap" ]
python get data from div blocks
38,790,548
<p>I am trying to parse div block using Beautiful Soup </p> <p>Which is </p> <pre><code>&lt;div class="same-height-left" style="height: 20px;"&gt;&lt;span class="value-frame"&gt;&amp;nbsp;whatever&lt;/span&gt;&lt;/div&gt; </code></pre> <p>I want to get [what i expect]:</p> <p><code>whatever</code> or <code>&lt;spa...
1
2016-08-05T13:29:50Z
38,791,471
<p>How about this:</p> <pre><code>from bs4 import BeautifulSoup html = """&lt;div class="same-height-left" style="height: 20px;"&gt;&lt;span class="value-frame"&gt;&amp;nbsp;whatever&lt;/span&gt;&lt;/div&gt;""" soup = BeautifulSoup(html, 'html.parser') method1 = soup.find('div').text method2 = soup.find('div').find...
1
2016-08-05T14:17:33Z
[ "python", "beautifulsoup" ]
pandas data frame: Find consecutive values and ignoring gaps of certain size
38,790,647
<p>I am struggeling with hourly precipitation data like e.g.</p> <pre><code>index=pd.date_range('1/1/2011', periods=365*24, freq='H') precipitation_indicator=np.random.randint(low=0, high=2, size=(365*24,)) precipitation_sum=np.random.ranf((365*24,))*6*precipitation_indicator prec_dataH=pd.DataFrame(data={'prec_ind':...
0
2016-08-05T13:34:21Z
38,855,249
<p>Add <code>group = group.copy()</code> as the first line in the <code>for</code> loop. That gets rid of the <code>SettingWithCopyWarning</code> and speeds up your computation by a factor of ~60.</p> <pre><code>def approach1(): rainEvents=prec_dataH.groupby('event_no') groups=[] for name, group in rainEv...
0
2016-08-09T15:48:17Z
[ "python", "pandas", "dataframe" ]
Mayavi: rotate around y axis
38,790,724
<p>I'm plotting a 3D mesh using mayavi's <code>triangular_mesh</code> method. The data describes a human silhouette laying face-down in 3D space (so the <code>cmap</code> can be used to denote distance from the camera).</p> <p>Here's the code used to generate the plot (the faces and vertices come from an external obje...
8
2016-08-05T13:38:41Z
38,792,397
<p>You need some math here. Ok, here is how to do it in terms of code, its not the best code but I wanted to make it self-explanatory. I use the Rodrigues formula for rotation in 3d to achieve this, az_new and el_new are your new viewing angles. Change the value of theta to get a different viewing angle in your frame o...
2
2016-08-05T15:03:24Z
[ "python", "3d", "mayavi" ]
Mayavi: rotate around y axis
38,790,724
<p>I'm plotting a 3D mesh using mayavi's <code>triangular_mesh</code> method. The data describes a human silhouette laying face-down in 3D space (so the <code>cmap</code> can be used to denote distance from the camera).</p> <p>Here's the code used to generate the plot (the faces and vertices come from an external obje...
8
2016-08-05T13:38:41Z
38,895,027
<p>It turns out there's a bit of a workaround for this.</p> <p>You can rotate the actors on their axes independently of the camera. (This throws the visualization out of step with the data labeling, but as I'm actually hiding the axes of the figure it doesn't matter in this case.)</p> <p>All you need to do is:</p> <...
0
2016-08-11T11:24:23Z
[ "python", "3d", "mayavi" ]
numpy.frombuffer ValueError: buffer is smaller than requested size
38,790,819
<p>I have the error listed above, but have been unable to find what it means. I am new to numpy and its {.frombuffer()} command. The code where this error is triggering is:</p> <pre><code>ARRAY_1=400000004 fid=open(fn,'rb') fid.seek(w+x+y+z) #w+x+y+z= if(condition==0): b=fid.read(struct.calcsize(fmt+str(ARRAY_1)+'...
0
2016-08-05T13:44:35Z
38,797,861
<p><code>calcsize</code> gives the number of bytes that the buffer will have given the format.</p> <pre><code>In [421]: struct.calcsize('&gt;100h') Out[421]: 200 In [422]: struct.calcsize('&gt;100b') Out[422]: 100 </code></pre> <p><code>h</code> takes 2 bytes per item, so for 100 items, it gives 200 bytes.</p> <p>Fo...
0
2016-08-05T21:15:54Z
[ "python", "numpy", "buffer" ]
Unable to properly install or load Tensorflow on Ubuntu 12.04 LTS with resultant ImportError
38,790,852
<p>I attempted the <a href="https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#anaconda-installation" rel="nofollow">Anaconda installation</a> for TensorFlow on my Ubuntu 12.04 LTS system, which went through, but while importing the library in Python, I came across an ImportError shown below.</p> <p>I...
1
2016-08-05T13:46:06Z
38,791,345
<p>This error probably relates to you glibc version. There are some topics regarding this:<a href="http://stackoverflow.com/questions/16605623/where-can-i-get-a-copy-of-the-file-libstdc-so-6-0-15">Where can I get a copy of the file libstdc++.so.6.0.15</a></p> <p>First check whether the required version is on your syst...
0
2016-08-05T14:10:52Z
[ "python", "ubuntu", "tensorflow", "anaconda" ]
Unable to properly install or load Tensorflow on Ubuntu 12.04 LTS with resultant ImportError
38,790,852
<p>I attempted the <a href="https://www.tensorflow.org/versions/r0.10/get_started/os_setup.html#anaconda-installation" rel="nofollow">Anaconda installation</a> for TensorFlow on my Ubuntu 12.04 LTS system, which went through, but while importing the library in Python, I came across an ImportError shown below.</p> <p>I...
1
2016-08-05T13:46:06Z
38,793,952
<p>You need to install <a href="http://packages.ubuntu.com/precise/libstdc++6" rel="nofollow">libstdc++6</a> with some dependencies like <code>gcc</code> an <code>g++</code>, at least <code>gcc-4.6</code> version:</p> <pre><code>sudo add-apt-repository ppa:ubuntu-toolchain-r/test sudo apt-get update sudo apt-get insta...
0
2016-08-05T16:31:41Z
[ "python", "ubuntu", "tensorflow", "anaconda" ]
Django1.8 'app' is not a registered namespace
38,790,872
<p>My error:</p> <pre><code> &lt;h1&gt;{{ question.question_text }}&lt;/h1&gt; {% if error_message %}&lt;p&gt;&lt;strong&gt;{{ error_message }}&lt;/strong&gt;&lt;/p&gt;{% endif %} &lt;form action="{% url 'app:vote' question.id %}" method="post"&gt; {% csrf_token %} {% for choice in question.choice_...
0
2016-08-05T13:47:20Z
38,791,077
<p>Namespacing is used when you include another url config inside your root <code>urls.py</code>. The example in the tutorial works because they have <code>include('polls.urls')</code> <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial01/#write-your-first-view" rel="nofollow">in tutorial 1</a>, and then in ...
0
2016-08-05T13:57:13Z
[ "python", "django" ]
Django1.8 'app' is not a registered namespace
38,790,872
<p>My error:</p> <pre><code> &lt;h1&gt;{{ question.question_text }}&lt;/h1&gt; {% if error_message %}&lt;p&gt;&lt;strong&gt;{{ error_message }}&lt;/strong&gt;&lt;/p&gt;{% endif %} &lt;form action="{% url 'app:vote' question.id %}" method="post"&gt; {% csrf_token %} {% for choice in question.choice_...
0
2016-08-05T13:47:20Z
38,801,618
<p><a href="http://i.stack.imgur.com/4sBN2.png" rel="nofollow">My Project picture</a></p> <p>I added a new urls.py</p> <p>this code,mydjango/urls.py</p> <hr> <pre><code>from django.conf.urls import url,include from django.contrib import admin urlpatterns = [ url(r'^app/', include('app.urls')), url(r'^adm...
0
2016-08-06T07:17:28Z
[ "python", "django" ]
Python select.select monitoring sockets in separate threads
38,790,913
<p>Is it allowed to create connections in separate threds, and than put them in select input list, and then call <code>select.select(input_list, [], [])</code> from main thread if except that call main thread do not use these connections?</p>
1
2016-08-05T13:49:15Z
38,791,944
<p>Yes, it should be possible. Check out these (related) posts for more details: <a href="http://stackoverflow.com/questions/8273297/keeping-a-socket-opened-in-a-thread-and-sending-commands-from-main">first</a>, <a href="http://stackoverflow.com/questions/8282216/multiple-threaded-socket-connections-queues">second</a>....
0
2016-08-05T14:40:59Z
[ "python", "python-2.7", "python-3.x" ]
Excel Workbook to html Django/Python
38,790,938
<p>Is there any way to take an excel workbook, and display it on a webpage with the same formatting as the workbook? Im wondering if there is a way to take an excel workbook and paste the contents on a webpage. Basically im looking for something to screenshot the excel document and paste in in my webpage... Is there an...
1
2016-08-05T13:50:16Z
38,791,031
<p>There's many ways to get around doing what you're referring to. Would you be open to using Google Sheets or do it have to be MS Excel? If so, I'd say use google drive and Google Sync. This way, you can make your excel on your local machine, save it. Create a python script that copies the file from the saved loca...
0
2016-08-05T13:54:57Z
[ "python", "html", "django", "excel", "xlsxwriter" ]
Excel Workbook to html Django/Python
38,790,938
<p>Is there any way to take an excel workbook, and display it on a webpage with the same formatting as the workbook? Im wondering if there is a way to take an excel workbook and paste the contents on a webpage. Basically im looking for something to screenshot the excel document and paste in in my webpage... Is there an...
1
2016-08-05T13:50:16Z
38,801,806
<p>should the xl file reside in your local machine? or are you open to storing it in the cloud ? Since you mentioned zoho viewer you might want to check out zoho office APIs <a href="https://www.zoho.com/docs/help/office-apis.html" rel="nofollow">here</a> using which you can use the API to upload a file and get back a...
1
2016-08-06T07:41:20Z
[ "python", "html", "django", "excel", "xlsxwriter" ]
Sengrid templates with custom image for every email
38,791,130
<p>How to send sengrid email with custom image which is inserto to template with tag?</p> <p>I have transactional email and I want insert image of item user is interested.</p> <p>I know how to add tags for custom information to template. But what about images?</p> <p>Maybe is possible to do something like this:</p> ...
1
2016-08-05T14:00:13Z
38,804,153
<p>Solved. I just need to create tag for image url.</p> <pre><code>personalization.add_substitution(Substitution("%image_url%", "http://some_url.to.image )) </code></pre>
0
2016-08-06T12:09:55Z
[ "python", "sendgrid" ]
ipdb how to bring the python debugger up to the frame which called the third-party code
38,791,146
<p>In my python code, I have several levels of call stacks like this:</p> <pre><code>f1:user_func1 f2:**user_func2** f3:third_party_func1 f4:third_party_func2 f5:exception happens here. </code></pre> <p>An exception happens somewhere in the third-party code (frame f5). I use ipdb to go the fra...
0
2016-08-05T14:01:15Z
39,272,786
<p>From ipdb command line:</p> <pre><code>ipdb&gt; help up u(p) [count] Move the current frame count (default one) levels up in the stack trace (to an older frame). </code></pre>
0
2016-09-01T13:25:08Z
[ "python", "debugging", "ipdb" ]
Rearrangement of string conditionally?
38,791,198
<p>I have spent the last 2 months working on a script that cleans, formats, and geocodes addresses. It is quite successful right now, however, there are some addresses that are giving me problems.</p> <p>For example:</p> <p>Addresses such as <code>7TH AVENUE 530 xxxxxxxxxxx</code> are causing my geolocation module to...
0
2016-08-05T14:04:04Z
38,791,955
<p>I am not sure if this helps, but you can start with this:</p> <pre><code>import re address = '7TH AVENUE 530 xxxxxxxxxxx' m = re.search('(?&lt;=AVENUE )\d{1,3}', address) print (m.group(0)) &gt;&gt;&gt; 530 </code></pre> <p>Edit based on your comment:</p> <pre><code>import re original = '7TH AVENUE 530 xxxxxxxxxx...
0
2016-08-05T14:41:27Z
[ "python" ]
Is there any interpreter that works well for running multiprocessing in python 2.7 version on windows 7?
38,791,222
<p>I was trying to run a piece of code.This code is all about multiprocessing.It works fine on command prompt and it also generates some output.But when I try to run this code on pyscripter it just says that script runs ok and it doesn't generate any output nor even it displays any error message.It doesn't even crashes...
1
2016-08-05T14:05:17Z
38,791,400
<p>The normal interpreter works just fine with <code>multiprocessing</code> on Windows 7 for me. (Your IDE might not like multiprocessing.) </p> <p>You just have to do</p> <pre><code>if __name__=='__main__': main() </code></pre> <p>with 2 underscores (<code>__</code>) each instead of 1 (<code>_</code>).</p> <p>...
0
2016-08-05T14:13:45Z
[ "python", "windows-7", "multiprocessing", "command-prompt", "interpreter" ]
How to properly create hist in matplotlib?
38,791,246
<p>I want to plot a histogram with three columns with heights <code>5</code>, <code>10</code> and <code>20</code>. Each column will have a width of 1. So the first column will have height <code>5</code> on the interval <code>[0,1]</code>, the second one <code>10</code> on the interval <code>[1,2]</code> and so on.</p> ...
1
2016-08-05T14:06:15Z
38,791,449
<p><code>hist</code> computes the number of data samples that lies within a given bin and then displays the resulting frequencies as a bar plot. You don't actually need <code>hist</code> because you already <em>have</em> the frequencies. You simply need <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pypl...
2
2016-08-05T14:16:10Z
[ "python", "matplotlib", "histogram" ]
Difference between reading in vs declaring string python
38,791,298
<p>What is the difference (if any) between declaring a string in python vs reading in their value?</p> <p>I have a piece of my code code which looks like:</p> <pre><code>file = open('comport.txt','r') for line in file: if "comport" in line: comport = line[9:] </code></pre> <p>and the text file just look...
0
2016-08-05T14:08:36Z
38,791,398
<p>Probably there is still a linebreak <code>\n</code> after <code>"COM1"</code>. Try this: </p> <pre><code> comport = line[9:].strip() </code></pre> <p>or this: </p> <pre><code> comport = line.split("=")[1].strip() </code></pre> <p>Also, you should use <code>with</code> to open <em>and close</em> the ...
2
2016-08-05T14:13:41Z
[ "python", "string", "pyserial" ]
Python: How to search and replace parts of a json file?
38,791,384
<p>I'm new to Python and I would like to search and replace titles of IDs in a JSON-file. Normally I would use R for this Task, but how to do it in Python. Here a sample of my JSON code (with a Service ID and a layer ID). I'm interested in replacing the titles in the layer IDs:</p> <pre><code> ...{"services": [ ...
0
2016-08-05T14:12:50Z
38,791,525
<p>You don't say which version of Python you are using but there are built-on JSON parsers for the language.</p> <p>For 2.x: <a href="https://docs.python.org/2.7/library/json.html" rel="nofollow">https://docs.python.org/2.7/library/json.html</a></p> <p>For 3.x: <a href="https://docs.python.org/3.4/library/json.html" ...
0
2016-08-05T14:19:59Z
[ "python", "json" ]
Python: How to search and replace parts of a json file?
38,791,384
<p>I'm new to Python and I would like to search and replace titles of IDs in a JSON-file. Normally I would use R for this Task, but how to do it in Python. Here a sample of my JSON code (with a Service ID and a layer ID). I'm interested in replacing the titles in the layer IDs:</p> <pre><code> ...{"services": [ ...
0
2016-08-05T14:12:50Z
38,792,955
<p>Here's an <a href="https://repl.it/Cjua/20" rel="nofollow">working example</a> on repl.it.</p> <p>Code: </p> <pre><code>import json import io import csv ### json input input = """ { "layers": [ { "id": "0", "title": "wrongTitle" }, { "id": "1", "title": "againTitleWrong" ...
2
2016-08-05T15:33:19Z
[ "python", "json" ]
Python: How to search and replace parts of a json file?
38,791,384
<p>I'm new to Python and I would like to search and replace titles of IDs in a JSON-file. Normally I would use R for this Task, but how to do it in Python. Here a sample of my JSON code (with a Service ID and a layer ID). I'm interested in replacing the titles in the layer IDs:</p> <pre><code> ...{"services": [ ...
0
2016-08-05T14:12:50Z
38,793,057
<p>As other users suggested, check the JSON module will be helpful. Here gives a basic example on python2.7:</p> <pre><code> import json j = '''{ "services": [{ "id": "service", "url": "http://...", "title": "GEW", "opti...
0
2016-08-05T15:39:12Z
[ "python", "json" ]
How to create relations with django
38,791,442
<p>This will be my first post here so I hope that everything will be correct.</p> <p>I got some trouble with django, I try to make a little lottery game. For this game I have one app called bitcoinlottery and in that app 2 models. As for now they look like this:</p> <pre><code>from django.db import models from django...
0
2016-08-05T14:15:52Z
38,793,136
<p>First of all I am not sure if your owner field would work. I don't see any imports for auth package</p> <pre><code>owner = models.ForeignKey('auth.User') </code></pre> <p>Firstly I would suggest you look at this <a href="http://stackoverflow.com/questions/19433630/how-to-use-user-as-foreign-key-in-django-1-5">pos...
0
2016-08-05T15:44:04Z
[ "python", "django" ]
Issue handling file from command line with biopython SeqIO
38,791,527
<p>This is my first attempt at using commandline args other than the quick and dirty <code>sys.argv[]</code> and writing a more 'proper' python script. For some reason that I can now not figure out, it seems to be objecting to how I'm trying to use the input file from the command line.</p> <p>The script is meant to ta...
0
2016-08-05T14:20:09Z
38,795,962
<p>As said in the comments, your variable <code>records</code> is only defined in the method <code>main()</code> (the same is true for <code>start</code> and <code>end</code>), thus it is not visible for the rest of the program. You can either return the values like this:</p> <pre><code>def main(argv): ... ......
1
2016-08-05T18:47:28Z
[ "python", "biopython", "getopt" ]
Finding the no. of digits of each element in the list
38,791,724
<p>I tried the following code but it is giving me an error.How should i fix this problem?.</p> <pre><code>import math mylist=[3,4,12,34] digits = int(math.log10(mylist))+1 Traceback (most recent call last): File "prog.py", line 3, in &lt;module&gt; TypeError: a float is required </code></pre>
0
2016-08-05T14:30:05Z
38,791,889
<p>You are passing a list to <code>log10()</code> function, and that's while it accepts a float. You can use a list comprehension to calculate the log for all items within the list:</p> <pre><code>&gt;&gt;&gt; digits = [int(math.log10(i)) + 1 for i in mylist] &gt;&gt;&gt; digits [1, 1, 2, 2] </code></pre>
0
2016-08-05T14:38:13Z
[ "python", "python-3.x", "math" ]
Finding the no. of digits of each element in the list
38,791,724
<p>I tried the following code but it is giving me an error.How should i fix this problem?.</p> <pre><code>import math mylist=[3,4,12,34] digits = int(math.log10(mylist))+1 Traceback (most recent call last): File "prog.py", line 3, in &lt;module&gt; TypeError: a float is required </code></pre>
0
2016-08-05T14:30:05Z
38,792,020
<p>This will return a list containing the number of digits of each element in <code>my_list</code>.</p> <pre><code>from math import log10 my_list = [3, 4, 12, 34] digits = [int(log10(n) + 1) for n in my_list] </code></pre>
0
2016-08-05T14:44:55Z
[ "python", "python-3.x", "math" ]
Finding the no. of digits of each element in the list
38,791,724
<p>I tried the following code but it is giving me an error.How should i fix this problem?.</p> <pre><code>import math mylist=[3,4,12,34] digits = int(math.log10(mylist))+1 Traceback (most recent call last): File "prog.py", line 3, in &lt;module&gt; TypeError: a float is required </code></pre>
0
2016-08-05T14:30:05Z
38,985,785
<p>Here's a working example:</p> <pre><code>import math def f(x): return int(math.log10(x)) + 1 mylist = [3, 4, 12, 34] digits = [] for x in mylist: fx = f(x) print("f({0})={1}".format(x, fx)) digits.append(fx) </code></pre>
0
2016-08-16T23:06:54Z
[ "python", "python-3.x", "math" ]
Double tap in IOS Simulator Not working
38,791,731
<p>I am trying to <code>double tap</code> an element in IOS Simulator using appium but unable to do so.</p> <pre><code>Methods tried: action.tap(x=xx, y=yy, count=1).release().perform() </code></pre> <p>2 times in a row,but it seems there is a 2 second gap which in real world would not be a double tap</p> <pre><co...
3
2016-08-05T14:30:34Z
38,791,844
<p>You should do both of the press commands before calling <code>perform()</code>:</p> <pre><code>action.press(x=xx, y=yy).release().wait(500).press(x=xx, y=yy).release().perform() </code></pre>
1
2016-08-05T14:36:17Z
[ "python", "appium", "appium-ios", "python-appium" ]
Double tap in IOS Simulator Not working
38,791,731
<p>I am trying to <code>double tap</code> an element in IOS Simulator using appium but unable to do so.</p> <pre><code>Methods tried: action.tap(x=xx, y=yy, count=1).release().perform() </code></pre> <p>2 times in a row,but it seems there is a 2 second gap which in real world would not be a double tap</p> <pre><co...
3
2016-08-05T14:30:34Z
38,857,992
<p>I call it in a similar way the first method you listed, its not as fast as double tap, but its less than one second delay <code>Appium::TouchAction.new.tap(x: xx, y: yy, count: 2).perform</code> </p> <p><code>.tap</code> dont need to use <code>release</code>, only <code>.press</code> need it</p>
1
2016-08-09T18:30:40Z
[ "python", "appium", "appium-ios", "python-appium" ]
Function annotation for subclasses of abstract class
38,791,739
<p>I'm trying to use function annotations in the hope that my editor will be better at refactoring. I however am stumbling over the following problem:</p> <p>I have an abstract base class Algorithm.</p> <pre><code>class Algorithm(metaclass=ABCMeta): def __init__(self): self.foo = 'bar' </code></pre>...
0
2016-08-05T14:30:58Z
38,791,784
<p>Just use <code>Algorithm</code> directly:</p> <pre><code>def get_foo(foo_algorithm: Algorithm): return foo_algoritm.foo </code></pre> <p>and automatically any instance of a subclass will be acceptable (<code>isinstance(foo_algorithm, Algorithm)</code> must be true, which applies to all subclasses of a baseclas...
1
2016-08-05T14:33:21Z
[ "python", "python-3.x", "annotations", "type-hinting" ]
Sublime Text 3 - Language specific Goto definition Keyboard Shortcut
38,791,826
<p>How can I set "Goto Definition" work according to the language I'm working on.</p> <p>For example:</p> <p>In Python I want to use PythonIDE's go to definition:</p> <pre><code>{ "keys": ["ctrl+d"], "command": "python_goto_definition" }, </code></pre> <p>And, for any other language, for instanc...
1
2016-08-05T14:35:22Z
38,796,045
<p>The context that you want is for <code>selector</code>:</p> <pre><code>{ "keys": ["ctrl+d"], "command": "python_goto_definition", "context": [ { "key": "selector", "operator": "equal", "operand": "source.python" } ] }, </code></pre> <p>You can add more or less specificity as needed. Use <kb...
1
2016-08-05T18:53:33Z
[ "python", "go", "sublimetext3" ]
Django ModelAdmin: update field without saving
38,791,857
<p>I have an admin page that looks like this: </p> <pre><code>class NameAdmin(admin.ModelAdmin): list_display = ['long_name', 'short_name'] search_fields = ['long_name','short_name'] </code></pre> <p>In my admin page I have created a button (it is called "getname"), which after being pressed, should update the sh...
-1
2016-08-05T14:36:57Z
38,793,540
<p>I would create a form in forms.py:</p> <pre><code>from django import forms from myapp.models import MyModel class MyModelForm(forms.ModelForm): update_me = forms.CharField(max_length=100, required=False) class Meta(Object): model = MyModel </code></pre> <p>Then in admin.py:</p> <pre><code>from d...
0
2016-08-05T16:05:42Z
[ "python", "django", "modeladmin" ]
How to control number of cores and processors in Python when we need to share state between processes
38,791,898
<p>In <a href="https://docs.python.org/2/library/multiprocessing.html#sharing-state-between-processes" rel="nofollow">document</a>, an example is shown about how to share state between processes. For the sake of time, I post the code in the document below.</p> <pre><code>from multiprocessing import Process, Value, Arr...
0
2016-08-05T14:38:38Z
38,792,458
<p>A possible answer:</p> <pre><code>from multiprocessing import Process, Value, Array, Pool import random def f(n, a): n.value = 3.1415927 a[random.randint(5)] = 0 if __name__ == '__main__': num = Value('d', 0.0) arr = Array('i', range(10)) # you can manually set the number of workers worke...
0
2016-08-05T15:06:22Z
[ "python", "linux", "python-multiprocessing" ]
How can I count a word from all lines that are 2 rows after a specific line?
38,791,960
<p>So, this might sound a bit confusing, I'll try to explain it. For example from these lines:</p> <pre><code>next line 1 ^^^^^^^^^^^^^^^^^^ red blue dark ten lemon next line 2 ^^^^^^^^^^^^^^^^^^^ hat 45 no dad fate orange next line 3 ^^^^^^^^^^^^^^^^^^^ tan rat lovely lemon eat you him lemon Daniel her" </code></pre...
2
2016-08-05T14:41:40Z
38,792,153
<p>For each line you need to be able to access to two line before it. For that aim you can use <code>itertools.tee</code> in order to create two independent file object (which are iterator-like objects) then use <code>itertools.izip()</code> in order to create your your expected pairs:</p> <pre><code>from itertools im...
3
2016-08-05T14:51:10Z
[ "python" ]
How can I count a word from all lines that are 2 rows after a specific line?
38,791,960
<p>So, this might sound a bit confusing, I'll try to explain it. For example from these lines:</p> <pre><code>next line 1 ^^^^^^^^^^^^^^^^^^ red blue dark ten lemon next line 2 ^^^^^^^^^^^^^^^^^^^ hat 45 no dad fate orange next line 3 ^^^^^^^^^^^^^^^^^^^ tan rat lovely lemon eat you him lemon Daniel her" </code></pre...
2
2016-08-05T14:41:40Z
38,792,688
<p>You can just loop over the file (which is an iterator) and call <code>next</code> two times whenever you find a <code>next line</code> line, then <code>count</code> how often <code>lemon</code> appears, with both the <code>for</code> loop and the calls to <code>next</code> are using the same iterator.</p> <pre><cod...
1
2016-08-05T15:18:02Z
[ "python" ]
Insert statement at row where MyCol is x
38,792,008
<p>I have 2 columns MyCol and NewCol. MyCol has already been populated, and may have duplicates (it's not the primary key). I need to insert a value y into NewCol at all rows where MyCol = x. I'm stuck here and not sure how to implement this.</p>
0
2016-08-05T14:44:24Z
38,792,680
<p>This is just an update statement</p> <pre><code>UPDATE TABLENAME SET NewCol = Y WHERE MyCol = x </code></pre> <p>Why exactly could you not find this in ANY introduction to SQL - book, article, reference, team-mate etc?</p>
1
2016-08-05T15:17:52Z
[ "python", "sql", "python-2.7", "sqlite3" ]
Unable to install Statsmodels...python
38,792,043
<p>I am using 32 bit cmd, 64 bit windows, python 2.7</p> <p>when I type the command pip install statsmodels</p> <p>I get the following error for some module of scipy...</p> <pre><code>Failed building wheel for Scipy Failed cleaning build dir for scipy </code></pre> <p><a href="http://i.stack.imgur.com/xcF7d.png" re...
0
2016-08-05T14:46:07Z
38,792,465
<p>An easier way to install python libraries on Windows with C/C++/Fortran/... dependencies is to use <code>conda</code>. <code>conda</code> is available in <a href="http://conda.pydata.org/miniconda.html" rel="nofollow">MiniConda</a> or <a href="https://www.continuum.io/downloads#_windows" rel="nofollow">Anaconda</a> ...
3
2016-08-05T15:06:32Z
[ "python", "python-2.7", "scipy", "pip", "statsmodels" ]
Unable to install Statsmodels...python
38,792,043
<p>I am using 32 bit cmd, 64 bit windows, python 2.7</p> <p>when I type the command pip install statsmodels</p> <p>I get the following error for some module of scipy...</p> <pre><code>Failed building wheel for Scipy Failed cleaning build dir for scipy </code></pre> <p><a href="http://i.stack.imgur.com/xcF7d.png" re...
0
2016-08-05T14:46:07Z
38,792,924
<p>install numpy</p> <pre><code>pip install numpy </code></pre> <p>If you face installation issues for numpy, get the pre-built windows installers from <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a> for your python version (python version is differen...
1
2016-08-05T15:31:56Z
[ "python", "python-2.7", "scipy", "pip", "statsmodels" ]
How would you create two select menus where select menu B's contents are dependent on select menu A's selection?
38,792,077
<p>How do you create two select menus with one dict where select menu B has values that correspond and are dependent to the keys present in select menu A?</p> <p>In my Django views.py, I've created a dictionary that has a lists of Projects as keys, and corresponding Tasks as values within the dictionary. It looks like...
2
2016-08-05T14:47:42Z
38,792,191
<p>You can use <a href="http://django-autocomplete-light.readthedocs.io/en/master/" rel="nofollow"><code>django-autocomplete-light</code></a> to do this. This basically provides autocompletion using a client library such as <a href="https://select2.github.io/" rel="nofollow"><code>select2</code></a>. But it also provid...
2
2016-08-05T14:53:13Z
[ "jquery", "python", "html", "css", "django" ]
How to change color of subtext in the Text widget (Python)
38,792,094
<p>Is there a way to change the color of specific text in the Text widget in Tkinter?</p> <p>Any answer will be welcomed.</p>
-1
2016-08-05T14:48:53Z
38,809,280
<p>The Library manual has a tkinter chapter that lists some online and paper materials. I mostly use the <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html" rel="nofollow">NMT reference</a>. See its Text widget sections and in particular the <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/we...
1
2016-08-06T22:25:47Z
[ "python", "tkinter" ]
How to group and count rows by month and year using Pandas?
38,792,122
<p>I have a dataset with personal data such as name, height, weight and date of birth. I would build a graph with the number of people born in a particular month and year. I'm using python pandas to accomplish this and my strategy was to try to group by year and month and add using count. But the closest I got is to ge...
2
2016-08-05T14:49:47Z
38,792,175
<p>To group on multiple criteria, pass a list of the columns or criteria:</p> <pre><code>df['birthdate'].groupby([df.birthdate.dt.year, df.birthdate.dt.month]).agg('count') </code></pre> <p>Example:</p> <pre><code>In [165]: df = pd.DataFrame({'birthdate':pd.date_range(start=dt.datetime(2015,12,20),end=dt.datetime(20...
3
2016-08-05T14:52:27Z
[ "python", "pandas" ]
How to group and count rows by month and year using Pandas?
38,792,122
<p>I have a dataset with personal data such as name, height, weight and date of birth. I would build a graph with the number of people born in a particular month and year. I'm using python pandas to accomplish this and my strategy was to try to group by year and month and add using count. But the closest I got is to ge...
2
2016-08-05T14:49:47Z
38,792,452
<p>Another solution is to set <code>birthdate</code> as the index and resample:</p> <pre><code>import pandas as pd df = pd.DataFrame({'birthdate': pd.date_range(start='20-12-2015', end='3-1-2016')}) df.set_index('birthdate').resample('MS').size() </code></pre> <p>Output:</p> <pre class="lang-none prettyprint-overri...
3
2016-08-05T15:06:04Z
[ "python", "pandas" ]
How to use dateutil.relativedelta in Python 3.x?
38,792,126
<p>Hello I am trying to use <code>relativedelta</code> from the <code>dateutil</code> module.</p> <p>I want to do what is mentioned <a href="http://stackoverflow.com/questions/4130922/how-to-increment-datetime-by-custom-months-in-python-without-using-library">here</a>, add some months to a given <code>datetime</code> ...
0
2016-08-05T14:49:57Z
38,792,339
<p>It seems you have to pip-install it like this and it works :</p> <pre><code>pip install python-dateutil </code></pre>
1
2016-08-05T15:00:37Z
[ "python", "python-3.x", "datetime", "python-dateutil" ]
How to use dateutil.relativedelta in Python 3.x?
38,792,126
<p>Hello I am trying to use <code>relativedelta</code> from the <code>dateutil</code> module.</p> <p>I want to do what is mentioned <a href="http://stackoverflow.com/questions/4130922/how-to-increment-datetime-by-custom-months-in-python-without-using-library">here</a>, add some months to a given <code>datetime</code> ...
0
2016-08-05T14:49:57Z
38,792,343
<p>You need to install it first using <code>pip3 install python-dateutil</code>. It's not included by default with Python 3, I don't know where you read that.</p> <p>I added a <code>pip3</code> and not just plain old <code>pip</code> because that will install it specifically for Python 3.</p>
2
2016-08-05T15:00:43Z
[ "python", "python-3.x", "datetime", "python-dateutil" ]
How to use dateutil.relativedelta in Python 3.x?
38,792,126
<p>Hello I am trying to use <code>relativedelta</code> from the <code>dateutil</code> module.</p> <p>I want to do what is mentioned <a href="http://stackoverflow.com/questions/4130922/how-to-increment-datetime-by-custom-months-in-python-without-using-library">here</a>, add some months to a given <code>datetime</code> ...
0
2016-08-05T14:49:57Z
38,792,344
<p>Open up your console and type: <code>pip install python-dateutil</code></p>
1
2016-08-05T15:00:45Z
[ "python", "python-3.x", "datetime", "python-dateutil" ]
moving a sprite with a function in pygame
38,792,136
<p>i am spawning in an enemy using the spawn() class, and in the spawn(0 class, i am trying to use the function move() to move the enemy. when i run the program, the zombie spawns, but doesnt move.</p> <p>Below is the entire code if anybody was wondering. I am only having problems with the spawn() class and nothing el...
0
2016-08-05T14:50:22Z
38,792,271
<p>Instead of this <code>return zombie_x , zombie_y as self.x, self.y</code> why are you not writing this? <code>self.x,self.y = zombie_x,zombie_y</code></p> <p>Edit: As mentioned by ninMonkey, <code>move</code> is not a function of class <code>spawn</code>. Put it in the class and it should work.</p>
0
2016-08-05T14:56:58Z
[ "python", "python-2.7", "pygame" ]
moving a sprite with a function in pygame
38,792,136
<p>i am spawning in an enemy using the spawn() class, and in the spawn(0 class, i am trying to use the function move() to move the enemy. when i run the program, the zombie spawns, but doesnt move.</p> <p>Below is the entire code if anybody was wondering. I am only having problems with the spawn() class and nothing el...
0
2016-08-05T14:50:22Z
38,799,329
<p>Your code was very hard to read and you should consider the following:</p> <h2>Divide your code in functions</h2> <p>As of right now, you have one function that contains almost 300 lines of code. Try divide up the code in small functions that does one thing only. Your first two functions are great! Maybe your even...
1
2016-08-06T00:12:47Z
[ "python", "python-2.7", "pygame" ]
Python: correct location of peaks in a 2D numpy array?
38,792,263
<p>I know this question falls within the category of peak detection and <a href="http://stackoverflow.com/questions/3684484/peak-detection-in-a-2d-array">there are answers available</a>, but I think my problem is pretty simplistic and refers to a proof of principle.</p> <p>Say I generate multiple, <code>nxn</code> 2D ...
0
2016-08-05T14:56:32Z
38,792,523
<p>In C/C++ it is considered dangerous to do <code>==</code> with floating point numbers.</p> <p>If there are no multiple exactly same pikes, you can use <code>numpy.argmax</code>:</p> <pre><code>a = random.rand(13, 11) idx_unrolled = argmax(a) the_peak = a[idx_unrolled/11, idx_unrolled%11] </code></pre> <p>If you n...
2
2016-08-05T15:09:43Z
[ "python", "arrays", "numpy", "max", "detection" ]
Color coded plot Python
38,792,273
<p>I have a color coded plot. Here is a part of the code:</p> <pre><code>fig = plt.figure(figsize=(10,10)) color_scheme = plt.get_cmap('cool') gs = gridspec.GridSpec(1, 1) ax1 = plt.subplot(gs[0]) gs.update(left=0.15,bottom=0.15,right=0.80,top=0.95) cax = fig.add_axes([0.80, 0.15, 0.03, 0.80]) im = ax1.scatter(x, y, ...
1
2016-08-05T14:57:07Z
38,792,417
<p>Instead of using</p> <pre><code>ax1.scatter(x, y, ...) </code></pre> <p>use</p> <pre><code>ax1.plot(x, y, 'o-', ...) # three dots meaning you can configure markers, linestyle, etc. </code></pre> <p>This works bacause of <code>'o-'</code> argument, which is a line plot with markers at every data point.</p>
2
2016-08-05T15:04:26Z
[ "python", "matplotlib" ]
Color coded plot Python
38,792,273
<p>I have a color coded plot. Here is a part of the code:</p> <pre><code>fig = plt.figure(figsize=(10,10)) color_scheme = plt.get_cmap('cool') gs = gridspec.GridSpec(1, 1) ax1 = plt.subplot(gs[0]) gs.update(left=0.15,bottom=0.15,right=0.80,top=0.95) cax = fig.add_axes([0.80, 0.15, 0.03, 0.80]) im = ax1.scatter(x, y, ...
1
2016-08-05T14:57:07Z
38,792,457
<p>Plot the same x and y-data separately with a standard <code>ax.plot</code> behind your scatter plot. </p> <pre><code>ax1.plot(x, y, '-') im = ax1.scatter(x, y, c=z, edgecolors='black', marker='.', s=40, lw=1, cmap=color_scheme, vmin=0, vmax=10) </code></pre> <p>This should give you your cmapped scatter plot with t...
1
2016-08-05T15:06:22Z
[ "python", "matplotlib" ]
Can you use the same decoder in Pocketsphinx for multiple files?
38,792,429
<p>Is it possible to use the same decoder for multiple wav files in Pocketsphinx (Python)? I have the following code snippet, which is very standard, except that I call the decoder twice on the same file. The outputs are not the same, however. I've also tried using the decoder twice on different files, and the outputs ...
2
2016-08-05T15:05:05Z
38,797,212
<blockquote> <p>Is it possible to use the same decoder for multiple wav files in Pocketsphinx (Python)?</p> </blockquote> <p>Yes</p> <blockquote> <p>I have the following code snippet, which is very standard, except that I call the decoder twice on the same file. The outputs are not the same, however.</p> </blockq...
0
2016-08-05T20:18:28Z
[ "python", "pocketsphinx" ]
Cross-platform Python Executables
38,792,459
<p>Is it possible to package together a Python executable that can be run across any platform - provided the correct version of Python is installed?</p> <p>If, for example, I created a Web Scraping script which included files such as chromium webdriver, the selenium package and other non-builtin Python packages, could...
0
2016-08-05T15:06:22Z
38,792,824
<p>Python is mainly cross platform - although I've had experience of reading/writing files being different on Windows/OS X/Linux because of the different directory and file structure (see <a href="https://automatetheboringstuff.com/chapter8/" rel="nofollow">Reading and Writing Files</a> for how to cope with that). Cros...
0
2016-08-05T15:26:27Z
[ "python", "selenium", "executable" ]
environment variable in ubuntu
38,792,545
<p>I'm trying to install the python module 'Pycpx' but I'm getting an error that it can't find an environment variable </p> <p><a href="http://www.stat.washington.edu/~hoytak/code/pycpx/download.html" rel="nofollow">Pycpx</a></p> <blockquote> <p>Exception: CPLEX concert include directory not found: please set en...
0
2016-08-05T15:10:46Z
38,792,615
<p>No, that's not right. You can't have those spaces around the <code>=</code> sign, and you should <code>export</code> the variable, like this: </p> <pre><code>export CPLEX_PATH=/home/joe/concert/include/ilconcert </code></pre>
1
2016-08-05T15:14:22Z
[ "python", "bash", "environment-variables", "ubuntu-14.04" ]
environment variable in ubuntu
38,792,545
<p>I'm trying to install the python module 'Pycpx' but I'm getting an error that it can't find an environment variable </p> <p><a href="http://www.stat.washington.edu/~hoytak/code/pycpx/download.html" rel="nofollow">Pycpx</a></p> <blockquote> <p>Exception: CPLEX concert include directory not found: please set en...
0
2016-08-05T15:10:46Z
38,792,652
<p>The correct way of doing it is as follows:</p> <pre><code>export CPLEX_PATH=/home/joe/concert/include/ilconcert </code></pre>
3
2016-08-05T15:16:06Z
[ "python", "bash", "environment-variables", "ubuntu-14.04" ]
figtext datetime function matplotlib
38,792,564
<p>I am trying to create a text box within my graph in matplotlib where it gives me the date in which the graph was created. </p> <p>I have created a text box in the bottom right corner of my graph using the figtext function in matplotlib, but cannot figure out how to incorporate the python datetime function within th...
1
2016-08-05T15:12:11Z
38,792,660
<p>Here's an example with today's date:</p> <pre><code>import datetime as dt plt.figtext(0, 0,"Data as of {}".format(dt.date.today().strftime('%Y-%m-%d')), wrap=False, horizontalalignment='left',verticalalignment ='bottom', fontsize=8) </code></pre>
0
2016-08-05T15:16:31Z
[ "python", "datetime", "matplotlib" ]
figtext datetime function matplotlib
38,792,564
<p>I am trying to create a text box within my graph in matplotlib where it gives me the date in which the graph was created. </p> <p>I have created a text box in the bottom right corner of my graph using the figtext function in matplotlib, but cannot figure out how to incorporate the python datetime function within th...
1
2016-08-05T15:12:11Z
38,792,665
<p>If you have a <code>datetime</code> object, you can use the <a href="https://docs.python.org/2/library/datetime.html#datetime.date.strftime" rel="nofollow"><code>strftime</code></a> method to convert it to a string representation using the formatting you want:</p> <pre><code>from datetime import datetime plt.figtex...
0
2016-08-05T15:16:38Z
[ "python", "datetime", "matplotlib" ]
Dynamically generate constraints list in CVXPY
38,792,618
<p>I am working on a minimum variance optimisation in python using CVXPY that takes in constraints in the form of</p> <pre><code>constraints = [ sum_entries(w) == 1, w[0:5] &gt;0.05, w[1] &gt; 0.05, w[6] == 0, sum_entries(w[country_mappin...
0
2016-08-05T15:14:40Z
38,795,858
<p>Ok so i have found a solution that works.</p> <p>One can read in the constraints and concatenate a string to get s.th like</p> <pre><code>'constraints = [sum_entries(w) == 1,w[0:5] &gt; 0.05,w[1] &gt; 0.05, w[6] == 0, sum_entries(w[country_mappings['France']]) == 0.39, w &gt;= 0, w[country_mappings['Fr...
0
2016-08-05T18:39:57Z
[ "python", "optimization", "constraint-programming", "quadratic-programming" ]
Pandas: Multi-index second-level slicing by integer
38,792,647
<p>I have a multi-index dataframe that look like this:</p> <pre><code>In [45]: df Out[45]: Last Days to expiry Date Ticker 1988-06-23 COU88 15.65 48 days COV88 15.65 78 days 1988-06-24 COU88 15.65 47 days COV88 15....
3
2016-08-05T15:15:51Z
38,792,821
<p>You can <code>groupby</code> on the first index level and call <code>first</code>:</p> <pre><code>In [173]: df.groupby(level='Date').first() Out[173]: Last Days to expiry Date 1988-06-23 15.65 48 days 1988-06-24 15.65 47 days 1988-06-27 15.10 44 days...
3
2016-08-05T15:26:08Z
[ "python", "pandas", "group-by", "multi-index" ]
How to Update Scrollbar Position with Tkinter
38,792,704
<p>I am trying to create a GUI for a python script using Tkinter, and have a working scrollbar. However, the position of the 'bar' does not update when I scroll or drag the bar. I think the relevant portion of code is as follows:</p> <pre><code>#Setup window with text and scrollbar root = Tk() scrollbar = Scrol...
0
2016-08-05T15:18:49Z
38,792,777
<p>You should point it to the .yview of a Canvas, and put the Text into the canvas</p> <pre><code>the_window = Tk() vscrollbar = Scrollbar(the_window) vscrollbar.grid(...) the_canvas = Canvas( the_window, background = 'white', yscrollcommand = vscrollbar.set ) the_canvas.grid(...) vscrollbar.config(comm...
2
2016-08-05T15:23:44Z
[ "python", "tkinter", "scrollbar" ]
Flask Foreign Key Constraint
38,792,722
<p>I have an issue with foreign key in Flask. My model is the following : </p> <p><strong>Model.py</strong></p> <pre><code>class User(db.Model): __tablename__ = "users" __table_args__ = {'extend_existing': True} user_id = db.Column(db.BigInteger, primary_key=True) # EDIT alerts = db.relationship(...
0
2016-08-05T15:20:11Z
38,793,154
<p>There is mistake in your code for initialisation of Alert class. You should use backref variable (which is 'user') instead of user_id while initializing Alert. Following code should work. </p> <pre><code>class User(db.Model): __tablename__ = "user" __table_args__ = {'extend_existing': True} user_id = d...
0
2016-08-05T15:44:55Z
[ "python", "flash", "flask-sqlalchemy", "foreign-key-relationship" ]
Flask Foreign Key Constraint
38,792,722
<p>I have an issue with foreign key in Flask. My model is the following : </p> <p><strong>Model.py</strong></p> <pre><code>class User(db.Model): __tablename__ = "users" __table_args__ = {'extend_existing': True} user_id = db.Column(db.BigInteger, primary_key=True) # EDIT alerts = db.relationship(...
0
2016-08-05T15:20:11Z
38,797,940
<p>If you are using SQLite, foreign key constraints are by default not enforced. See <a href="https://www.sqlite.org/foreignkeys.html#fk_enable" rel="nofollow">Enabling Foreign Key Support</a> in the documentation for how to enable this. </p>
0
2016-08-05T21:22:30Z
[ "python", "flash", "flask-sqlalchemy", "foreign-key-relationship" ]
Flask Foreign Key Constraint
38,792,722
<p>I have an issue with foreign key in Flask. My model is the following : </p> <p><strong>Model.py</strong></p> <pre><code>class User(db.Model): __tablename__ = "users" __table_args__ = {'extend_existing': True} user_id = db.Column(db.BigInteger, primary_key=True) # EDIT alerts = db.relationship(...
0
2016-08-05T15:20:11Z
38,826,981
<p>So I find how to do it with <a href="http://stackoverflow.com/questions/2614984/sqlite-sqlalchemy-how-to-enforce-foreign-keys">this stackoverflow question </a>, I find how to force foreign Key Constraint.</p> <p>I juste add this in <code>__init__.py</code> and change nothing to <code>models.py</code></p> <pre><c...
0
2016-08-08T10:34:25Z
[ "python", "flash", "flask-sqlalchemy", "foreign-key-relationship" ]
How would I modify/add text to a tkinter.Label?
38,792,787
<p>I am in the process of learning basic Python. I am currently attempting to create a simple calculator program that only has addition and subtraction. I have one issue though. I am not sure how I would add text to my Python label upon button press. Right now, upon pressing the '1' button, my program will change the d...
3
2016-08-05T15:24:14Z
38,792,942
<p>Is this what you're looking for:</p> <pre><code>from tkinter import * root = Tk() var = StringVar() def f1(): var.set(" ") var.set("1") def f2(): var.set(" ") var.set("2") label = Label(root, textvariable=var) label.pack() button1 = Button(root, text="One", command=f1) button1.pack() button2 =...
0
2016-08-05T15:32:39Z
[ "python", "user-interface", "tkinter", "calculator" ]
How would I modify/add text to a tkinter.Label?
38,792,787
<p>I am in the process of learning basic Python. I am currently attempting to create a simple calculator program that only has addition and subtraction. I have one issue though. I am not sure how I would add text to my Python label upon button press. Right now, upon pressing the '1' button, my program will change the d...
3
2016-08-05T15:24:14Z
38,792,997
<p>You should use a StringVar for this. And your callback needs to get the current contents of the StringVar, modify it, and use the modified string to set the new value of the StringVar. Like this:</p> <pre><code>import tkinter as tk window = tk.Tk() # Creating main label display_text = tk.StringVar() display = tk....
2
2016-08-05T15:35:24Z
[ "python", "user-interface", "tkinter", "calculator" ]
How would I modify/add text to a tkinter.Label?
38,792,787
<p>I am in the process of learning basic Python. I am currently attempting to create a simple calculator program that only has addition and subtraction. I have one issue though. I am not sure how I would add text to my Python label upon button press. Right now, upon pressing the '1' button, my program will change the d...
3
2016-08-05T15:24:14Z
38,793,337
<p>You can define <code>add_one</code> like the following, to first get the existing value and then append a new value to it:</p> <pre><code>def add_one(): current_value = display.cget("text") new_value = current_value + "1" display.config(text=new_value) </code></pre>
1
2016-08-05T15:55:10Z
[ "python", "user-interface", "tkinter", "calculator" ]
matplotlib and engineering notation
38,792,849
<p>I'm using matplotlib to iterate a bunch of measurements over telnet...I set up the measurement with telnetlib and then read in the data, and set it up to be plotted. The problem is, I want it in engineering notation (exponents to multiples of three, so, kilo, mega, giga, etc.). However, I cannot make this work...P...
0
2016-08-05T15:27:53Z
38,793,077
<p>One way is to get the tick-values and then format them and set the new formatted ones as labels. Look <a href="http://stackoverflow.com/questions/17973278/python-decimal-engineering-notation-for-mili-10e-3-and-micro-10e-6">here</a> for an example of the formatting. Sample code might be</p> <pre><code>xticks = ax.ge...
0
2016-08-05T15:40:32Z
[ "python", "matplotlib" ]
For two lists, l1 and l2, how to check that for all e1 ∈ l1, ∃p(e1,e2) where e2 is some element in l2, efficiently in python?
38,793,001
<p>Ok, not sure if that was the best title, but I have two python lists. L1 and L2 which both have elements of type T and do not have the same length.</p> <p>I have a function p(T,T) which is a predicate checking a property about two elements of type T.</p> <p>I would like to check that for all elements e in L1, p(e,...
0
2016-08-05T15:35:43Z
38,793,368
<p>The fact that <code>p</code> is symmetric is essentially useless. It's true that if you know <code>p(e, e')</code> holds, you know <code>p(e', e)</code> holds, but unless <code>e</code> and <code>e'</code> are both in both lists, you only get to make use of your predicate evaluation once instead of twice. Even if th...
2
2016-08-05T15:56:33Z
[ "python", "algorithm", "list", "iterator", "traversal" ]
For two lists, l1 and l2, how to check that for all e1 ∈ l1, ∃p(e1,e2) where e2 is some element in l2, efficiently in python?
38,793,001
<p>Ok, not sure if that was the best title, but I have two python lists. L1 and L2 which both have elements of type T and do not have the same length.</p> <p>I have a function p(T,T) which is a predicate checking a property about two elements of type T.</p> <p>I would like to check that for all elements e in L1, p(e,...
0
2016-08-05T15:35:43Z
38,793,437
<p>I would just create a dictionary for each list (could be <code>dict1</code> and <code>dict2</code>), and when you iterate through the first list, you set both <code>dict1[e] = e'</code> and <code>dict2[e'] = e</code>. Then, when iterating through <code>L2</code>, you just check first that the current <code>e</code> ...
0
2016-08-05T15:59:36Z
[ "python", "algorithm", "list", "iterator", "traversal" ]
replacing lines in file
38,793,047
<p>I have a file that looks like this (columns ar coordinates x,y,z and lines represents some objects):</p> <pre><code> 1.02 0.63 0.0003 -1.34 0.61 0.0002 0.0 0.0 0.0 -1.91 0.25 0.87 -1.32 1.70 0.0 0.02 -1.12 -0.06 </code></pre> <p>I want to: </p> <p>1)...
0
2016-08-05T15:38:25Z
38,795,489
<p>If you have to use numpy, here is an example you can work on: load the whole data as a numpy array "ao"</p> <pre><code> old2 = ao[1,:] new2 = ao[1,:]*3 diff = new2 - old2 ao[1,:] = new2 ao[3:,:] = ao[3:,:] + diff </code></pre>
0
2016-08-05T18:11:18Z
[ "python", "arrays", "replace", "lines" ]
I am trying to sort list of all the files in a folder on basis of modification date
38,793,106
<p>I am a beginner and trying to write code to display files in a folder on basis of their modification date in ascending order.</p> <p>I tried below code but i want to know how can i proceed to sort it.</p> <pre><code>import os file_path = "c:\\albert\\david" file1 = os.listdir(file_path) file2 = [os.path.join(fi...
3
2016-08-05T15:42:15Z
38,796,386
<p>Change the lines after your <code>print(file2)</code> line, for a list comprehension similar to the one you used to form the <code>file2</code>:</p> <pre><code>file3 = [(f, os.path.getmtime(f), s.path.getsize(f)) for f in file2] </code></pre> <p>Now you only need to sort it on the second element of the tuple (the ...
1
2016-08-05T19:17:45Z
[ "python", "sorting" ]
Can a python program configure logging before running the rest of code?
38,793,237
<p><strong>NOTE</strong>: This question was based on an assumption that Python emits its error messages via logging. The answers show that the assumption is wrong.</p> <hr> <p>I'm developing a program that is not started from a command line, but by a daemon. Stderr is redirected to null device.</p> <p>Normally it lo...
0
2016-08-05T15:49:23Z
38,793,621
<p>You could use:</p> <pre><code>if __name__ == '__main__': logger.info("program start") try: real_start() except Exception: # This will log the traceback. logger.exception("An error ocurred.") </code></pre> <p>However, you should increase your logger level to, at least, <code>logg...
1
2016-08-05T16:10:35Z
[ "python", "logging" ]
Can a python program configure logging before running the rest of code?
38,793,237
<p><strong>NOTE</strong>: This question was based on an assumption that Python emits its error messages via logging. The answers show that the assumption is wrong.</p> <hr> <p>I'm developing a program that is not started from a command line, but by a daemon. Stderr is redirected to null device.</p> <p>Normally it lo...
0
2016-08-05T15:49:23Z
38,793,808
<p>You are not passing your exception to your logger, so there is no way for it to write it. </p> <p>inside your <code>real_start()</code>, put your import statement and your function call in a try, catch and then log the exception.</p> <p>Lets say for example your <code>realprog.main()</code> divides a number by zer...
1
2016-08-05T16:22:01Z
[ "python", "logging" ]
NoReverseMatch following v1.9 to v1.10 upgrade
38,793,258
<p>I've just upgraded to django v1.10 and I'm running through tests to check everything works fine but I've getting <code>Reverse for 'django.contrib.auth.views.login' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []</code> on my login page.</p> <p>I'm using django-registration and have...
2
2016-08-05T15:50:45Z
38,793,513
<p>From <a href="https://docs.djangoproject.com/en/stable/releases/1.10/#features-removed-in-1-10" rel="nofollow">Django 1.10 release notes</a>:</p> <blockquote> <p>The ability to <strong>reverse()</strong> URLs using a dotted Python path is removed.</p> </blockquote> <p>The <code>url</code> template tag uses <code...
1
2016-08-05T16:03:05Z
[ "python", "django" ]
Python 3.5: I am getting an error: "NameError: name 'multiprocessing' is not defined"
38,793,278
<p>I am getting an error: </p> <pre><code> pool = multiprocessing.Pool(5) NameError: name 'multiprocessing' is not defined </code></pre> <p>So, how to fix it ? Thank you very much :)</p> <pre><code>from multiprocessing import Pool from selenium.common.exceptions import TimeoutException from bs4 import BeautifulS...
0
2016-08-05T15:51:53Z
38,793,313
<p>You are importing <code>Pool</code>, not <code>multiprocessing</code>.</p> <p>Replace <code>from multiprocessing import Pool</code> with <code>import multiprocessing</code></p>
0
2016-08-05T15:54:05Z
[ "python", "facebook", "multiprocessing" ]
Python 3.5: I am getting an error: "NameError: name 'multiprocessing' is not defined"
38,793,278
<p>I am getting an error: </p> <pre><code> pool = multiprocessing.Pool(5) NameError: name 'multiprocessing' is not defined </code></pre> <p>So, how to fix it ? Thank you very much :)</p> <pre><code>from multiprocessing import Pool from selenium.common.exceptions import TimeoutException from bs4 import BeautifulS...
0
2016-08-05T15:51:53Z
38,793,318
<p>You haven't declared what <em>multiprocessing</em> is. You haven't imported the module either, you just imported <em>Pool</em> from <em>multiprocessing</em>. In other words, multiprocessing is not in your namespace, hence NameError. Try import the whole module and it should work.</p> <pre><code>import multiprocessi...
0
2016-08-05T15:54:19Z
[ "python", "facebook", "multiprocessing" ]
Python 3.5: I am getting an error: "NameError: name 'multiprocessing' is not defined"
38,793,278
<p>I am getting an error: </p> <pre><code> pool = multiprocessing.Pool(5) NameError: name 'multiprocessing' is not defined </code></pre> <p>So, how to fix it ? Thank you very much :)</p> <pre><code>from multiprocessing import Pool from selenium.common.exceptions import TimeoutException from bs4 import BeautifulS...
0
2016-08-05T15:51:53Z
38,793,435
<p>You have already <code>import Pool</code> from <code>multiprocessing</code>. So you need to replace the line</p> <pre><code>pool = multiprocessing.Pool(5) </code></pre> <p>by</p> <pre><code>pool = Pool(5) </code></pre>
0
2016-08-05T15:59:32Z
[ "python", "facebook", "multiprocessing" ]
What is the unit of height variable in "barh" of matplotlib?
38,793,456
<p>In the definition of the function barh of matplotlib:</p> <p><code>matplotlib.pyplot.barh(bottom, width, height=0.8, left=None, hold=None, **kwargs)</code></p> <p>The default "height" is 0.8, but when I draw some figures with different Figure's height for example (30, 40,..) and dpi=100. I see the Bar's height is ...
3
2016-08-05T16:00:29Z
38,797,802
<p>I'll split this into two parts:</p> <blockquote> <p>I wonder what is the unit of the height in barh</p> </blockquote> <p>(Apparently people have been wondering this <a href="https://sourceforge.net/p/matplotlib/mailman/message/23874862/" rel="nofollow">since 2009</a>... so I guess you're in good company!)</p> <...
1
2016-08-05T21:09:39Z
[ "python", "matplotlib" ]
Django Celery Received unregistered task of type 'appname.tasks.add'
38,793,547
<p>Following the documentation and the Demo Django project here <a href="https://github.com/celery/celery/tree/3.1/examples/django" rel="nofollow">https://github.com/celery/celery/tree/3.1/examples/django</a></p> <p><strong>Project Structure</strong></p> <pre><code>piesup2 | piesup2 | |__init__.py | ...
0
2016-08-05T16:06:17Z
38,836,969
<p>In your django settings you need to add each module that has a celery task to CELERY_IMPORTS</p> <pre><code>CELERY_IMPORTS = ( 'reports.tasks', 'some_app.some_module', ) </code></pre>
2
2016-08-08T19:20:35Z
[ "python", "django", "celery" ]
python module names with same name as existing modules
38,793,579
<p>I have a number of small utils modules that i organize under a 'msa' namespace so I can use in a number of different research projects. Currently I have them organized like this:</p> <pre><code># folder structure: packages &lt;-- in my pythonpath --msa ----msa_utils.py ----msa_geom.py ----msa_pyglet.py ----msa_mat...
0
2016-08-05T16:07:34Z
38,793,613
<p>In Python 2, imports in packages without a package qualifier indeed first look for <em>package local</em> modules.</p> <p>Thus, <code>import pyglet</code> will find <code>msa.pyglet</code> before the top-level <code>pyglet</code> is considered.</p> <p>Switch to absolute imports to make the Python 3 behaviour the d...
2
2016-08-05T16:10:06Z
[ "python", "module" ]
What happens when an exception occurs in a module initialization
38,793,581
<p>I have a module, and in this module I initialize some variables as soon as the module is imported.</p> <p>my_mobule.py:</p> <pre><code>def _build_service(): # ...do some stuffs _service = _build_service() </code></pre> <p>In this case, what will happen if the <code>_build_service</code> method raises an exce...
1
2016-08-05T16:07:37Z
38,793,648
<p>It's pretty similar to the behaviour should you call a function which raises an exception - if you don't handle the exception in the module itself, then it will be simply bump up the stack to whoever imported your module. </p> <p>That would look like this:</p> <pre><code>&gt;&gt;&gt; import my_mobule # sic UhohE...
1
2016-08-05T16:11:47Z
[ "python", "python-2.7", "python-module" ]
Create Gtk3 Treeview with CellRendererToggle and Names from List with Python
38,793,605
<p>I try to create a Gtk.TreeView with header names from a list. Because I want to use it to show entries from different databases later.</p> <p>The problem: When I click on a cell and try to activate it all cells in the row getting activated. More strange, they look not activated, only if I move the cursor over them ...
1
2016-08-05T16:09:36Z
38,854,444
<p>The concept of 'selecting a cell' is not really implemented in a <code>GtkTreeView</code>. If you look over all the functions available for TreeView, very few of them really addresses single cells.</p> <p>That leaves you with these options: </p> <ol> <li><p>Implement your own 'single cell' highlighting (such as ad...
0
2016-08-09T15:09:34Z
[ "python", "gtk3" ]
Create Gtk3 Treeview with CellRendererToggle and Names from List with Python
38,793,605
<p>I try to create a Gtk.TreeView with header names from a list. Because I want to use it to show entries from different databases later.</p> <p>The problem: When I click on a cell and try to activate it all cells in the row getting activated. More strange, they look not activated, only if I move the cursor over them ...
1
2016-08-05T16:09:36Z
38,955,150
<p>TreeViewColumn needs an attribute for "active" with the position in the store:</p> <pre><code>column.add_attribute(cell, "active", n) </code></pre> <p>And I also had to change the underlying store and not the widget:</p> <pre><code>self.myliststore[path][column] = not self.myliststore[path][column] </code></pre> ...
1
2016-08-15T12:31:45Z
[ "python", "gtk3" ]
Python lru_cache usage optimization
38,793,633
<p>Say I have this method that I cache using <a href="https://docs.python.org/3/library/functools.html" rel="nofollow"><code>lru_cache</code></a>:</p> <pre><code>@lru_cache(maxsize=8) def very_expensive_call(number): # do something that's very expensive return number </code></pre> <p>I am calling this method ...
0
2016-08-05T16:11:18Z
38,795,337
<p>No, no, the <code>cache</code> used in <code>lru</code> is specifically designed to not be public-facing. All its internals <a href="https://hg.python.org/cpython/file/3.5/Lib/functools.py#l411" rel="nofollow"><em>are encapsulated</em></a> for thread safety and in order to not break code if the implementation change...
1
2016-08-05T18:00:45Z
[ "python", "python-3.x", "caching", "optimization" ]
How do I silence output to stdout in rpy2?
38,793,688
<p>I have an R function that I call from my Python script using rpy2. The R function prints to stdout; is there a parameter in rpy2 that silences stdout when an R script is called?</p>
0
2016-08-05T16:14:38Z
38,798,986
<p>rpy2 lets you redefine R's own interaction with a terminal as python function.</p> <p>The following example from the documentation shows how to append output to <code>stdout</code> to a Python list (limited usefulness in the grand scheme of things, but it makes a simple examples of the feature):</p> <pre><code>buf...
0
2016-08-05T23:20:41Z
[ "python", "rpy2" ]
Python sort a list of objects/dictionaries with a given sortKey function
38,793,694
<p>(I use Python 2 here)</p> <p>I have a list of dictionaries, say</p> <pre><code>dei = [{'name': u'Thor'}, {'name': u'Œdipus'}, {'name': u'Creon'}] </code></pre> <p>I would like to sort that list by their <code>'name'</code> attribute. This is easily done so:</p> <pre><code>dei.sort(key=lambda d: d['name']) </cod...
3
2016-08-05T16:15:01Z
38,794,186
<p>You can use your own key that internally calls <code>getSortKey</code> with correct value:</p> <pre><code>&gt;&gt;&gt; import icu &gt;&gt;&gt; dei = [{'name': u'Thor'}, {'name': u'Œdipus'}, {'name': u'Creon'}] &gt;&gt;&gt; collator = icu.Collator.createInstance() &gt;&gt;&gt; dei.sort(key=lambda x: collator.getSor...
0
2016-08-05T16:47:34Z
[ "python", "sorting", "dictionary", "pyicu" ]
Numpy std calculation: TypeError: cannot perform reduce with flexible type
38,793,713
<p>I am trying to read lines of numbers starting at line 7 and compiling the numbers into a list until there is no more data, then calculate standard deviation and %rms on this list. Seems straightforward but I keep getting the error:</p> <pre><code>Traceback (most recent call last): File "rmscalc.py", line 21, in &...
0
2016-08-05T16:16:03Z
38,794,051
<p><code>values</code> is a string array and so is <code>a</code>. Convert <code>a</code> into a numeric type using <code>astype</code>. For example,</p> <pre><code>a = np.asarray(values).astype(np.float32) std = np.std(a) </code></pre>
1
2016-08-05T16:37:57Z
[ "python", "error-handling" ]
Distributed Tensorflow: ValueError “When: When using replicas, all Variables must have their device set” set: name: "Variable"
38,793,718
<p>I am trying to write a distributed variational auto encoder on tensorflow in <code>standalone mode</code>.</p> <p>My cluster includes 3 machines, naming m1, m2 and m3. I am trying to run 1 ps server on m1, and 2 worker servers on m2 and m3. (Example trainer program in <a href="https://www.tensorflow.org/versions/r0...
2
2016-08-05T16:16:12Z
38,794,027
<p>The problem stems from the definition of your <code>global_step</code> variable:</p> <pre><code>global_step = tf.Variable(0) </code></pre> <p>This definition is outside the scope of the <code>with tf.device(tf.train.replica_device_setter(...)):</code> block above, so no device is assigned to <code>global_step</cod...
1
2016-08-05T16:36:22Z
[ "python", "tensorflow" ]
Remove numbers conditionally?
38,793,863
<p>I'm sorry if the title isn't very descriptive. I don't exactly know how to sum up my problem in a few words.</p> <p>Here's my issue. I'm cleaning addresses and some of them are causing some issues.</p> <p>I have a list of delimiters (avenue, street, road, place, etc etc etc) named <code>patterns</code>.</p> <p>Le...
1
2016-08-05T16:25:54Z
38,794,269
<p>Your description of what you want to do isn't very clear, but if I understand correctly you want to is to delete the first occurrence of a number sequence?</p> <p>You could do this without using a <em>regex</em>,</p> <pre><code>s = 'SUITE 1603 200 PARK AVENUE SOUTH NEW YORK' l = s.split(' ') for i, w in enumerate(...
1
2016-08-05T16:52:59Z
[ "python" ]