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
Python automatically converting data types
37,814,937
<p>I have implemented a class <code>BasicForm</code>, containing also a method <code>__str__</code> to be able to print stuff. I also have a function <code>stringToBasicForm(string)</code> converting certain types of strings to BasicForm objects.</p> <p>Later in my program, I have an array <code>array</code> of allowe...
0
2016-06-14T14:30:42Z
37,816,524
<p>Numpy arrays are <em>strongly typed</em>:</p> <pre><code>&gt;&gt;&gt; x = np.empty((3,), dtype=np.float64) &gt;&gt;&gt; x[0] = 1 # I put an int in... &gt;&gt;&gt; x[0] # And get a float out ! 1.0 </code></pre> <p>Usually, the array will try to convert values you pass in (which is typically what you want, cf ...
2
2016-06-14T15:40:51Z
[ "python", "python-2.7", "data-type-conversion" ]
How to get F1 score per label using Sklearn's cross_validation (multi-label classification)
37,814,952
<p>I am trying to do multi-label classification using sklearn's cross_val_score function (<a href="http://scikit-learn.org/stable/modules/cross_validation.html" rel="nofollow">http://scikit-learn.org/stable/modules/cross_validation.html</a>).</p> <pre><code>scores = cross_validation.cross_val_score(clf, X_train, y_tra...
1
2016-06-14T14:31:18Z
37,815,435
<p>I solved the problem by making some changes in .../scikit-learn/sklearn/cross_validation.py. More specifically I commented out these lines:</p> <pre><code>1651 if not isinstance(score, numbers.Number): 1652 raise ValueError("scoring must return a number, got %s (%s) instead." 1653 ...
0
2016-06-14T14:52:48Z
[ "python", "scikit-learn", "cross-validation", "multilabel-classification" ]
How to get F1 score per label using Sklearn's cross_validation (multi-label classification)
37,814,952
<p>I am trying to do multi-label classification using sklearn's cross_val_score function (<a href="http://scikit-learn.org/stable/modules/cross_validation.html" rel="nofollow">http://scikit-learn.org/stable/modules/cross_validation.html</a>).</p> <pre><code>scores = cross_validation.cross_val_score(clf, X_train, y_tra...
1
2016-06-14T14:31:18Z
37,847,406
<p>I generally use </p> <pre><code>from sklearn.metrics import accuracy_score, f1_score, precision_score, recall_score, classification_report, confusion_matrix metrics.classification_report(y_test, y_predicted2) </code></pre> <p>This generally gives me all values in need to evaluate my models performance. </p>
0
2016-06-15T23:19:52Z
[ "python", "scikit-learn", "cross-validation", "multilabel-classification" ]
Pandas Series - set data between date ranges to a constant
37,815,007
<p>I have a very simple problem which might be a bit long-winded to explain but I'll do my best.</p> <p>I have a pandas Series <code>daily</code> data which has an entry for each day and a corresponding value of False (see daily in code below).</p> <p>I have two other Series objects, <code>start</code> and <code>end<...
1
2016-06-14T14:33:57Z
37,815,340
<p>You can use:</p> <pre><code>daily = pd.Series(False, pd.bdate_range("20150101", "today", freq="D")) monthly = pd.Series(False, pd.bdate_range("20150101", "today", freq="MS") + pd.DateOffset(9)) start = [i + pd.DateOffset(random.choice([1, 2, 3, 4])) for i in monthly.index] end = [i + pd.DateOffset(random.choice([1...
1
2016-06-14T14:48:10Z
[ "python", "datetime", "pandas" ]
Google cloud sql error while doing django syncdb
37,815,101
<p>I have a django app hosted on google appengine and google cloud sql as database. I follows this link <a href="https://cloud.google.com/appengine/docs/python/cloud-sql/django" rel="nofollow">https://cloud.google.com/appengine/docs/python/cloud-sql/django</a> to sync and migrate db schema to cloudsql. This worked fine...
2
2016-06-14T14:38:12Z
37,848,690
<p>I changed my db settings and authorized my local ip address at google api console. Now it is working fine.<br> My new db settings is</p> <pre><code> if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine'): # Running on production App Engine, so use a Google Cloud SQL database. DATABASES =...
1
2016-06-16T02:00:49Z
[ "python", "django", "google-app-engine", "google-cloud-sql" ]
How to rename the file extension, by removing archive dates
37,815,136
<p>I am thinking this code should take all my files within the folder, and rename .pdf_(date) to .pdf. However, it is not.</p> <pre><code>import os,sys folder = 'C:\/MattCole\/test' for filename in os.listdir(folder): infilename = os.path.join(folder,filename) if not os.path.isfile(infilename): continue ...
0
2016-06-14T14:39:34Z
37,816,167
<p>You want to split the old file name on _, then take the first part as new name:</p> <pre><code>&gt;&gt;&gt; old_name = 'file1.pdf_20160614-050421' &gt;&gt;&gt; new_name = old_name.split('_')[0] &gt;&gt;&gt; new_name 'file1.pdf' </code></pre>
0
2016-06-14T15:23:53Z
[ "python", "file", "rename" ]
How to rename the file extension, by removing archive dates
37,815,136
<p>I am thinking this code should take all my files within the folder, and rename .pdf_(date) to .pdf. However, it is not.</p> <pre><code>import os,sys folder = 'C:\/MattCole\/test' for filename in os.listdir(folder): infilename = os.path.join(folder,filename) if not os.path.isfile(infilename): continue ...
0
2016-06-14T14:39:34Z
37,816,193
<p>This is a bit silly, you've got some perfectly good code here that you're not using. You should use it.</p> <pre><code>import os,sys folder = 'C:\/MattCole\/test' for filename in os.listdir(folder): infilename = os.path.join(folder,filename) if os.path.isfile(infilename): oldbase, oldext = ...
2
2016-06-14T15:25:28Z
[ "python", "file", "rename" ]
ResourceWarning with opening os.devnull as a file and popen in Python
37,815,163
<p>For comparability reasons I am using devnull as a file to redirect stdout (Python 2.7 does not have <code>subprocess.DEVNULL</code>)</p> <pre><code>subprocess.Popen(args, stdout=open('w', os.devnull)) </code></pre> <p>However in Python 3.4 I am getting a resource warning when I use this</p> <pre><code>foo.py:107:...
0
2016-06-14T14:40:52Z
37,817,090
<p>I found that there is a standard-library module called <code>atexit</code> to register functions to be called on program termination. To use it with a file handler, you need to register the close method with it.</p> <p>For example</p> <pre><code>import atexit devnull = open(os.devnull, 'w') atexit.register(devnull...
0
2016-06-14T16:06:50Z
[ "python", "cross-platform", "warnings", "compatibility", "popen" ]
Adding multiple variables to lists within a list in Python
37,815,171
<p>i would like to ask about how i could add multiple variables to a list within a list in python.</p> <pre><code>yearmonthlst = [[] for i in range(64)] precipitation = [197.6, 95.0, 37.1, 74.2, 65.3, 175.5, 114.6, 90.4, 26.7, 62.2, 58.9, 142.0, 129.0, 122.2...] </code></pre> <p>So for example here i have a list tha...
-1
2016-06-14T14:41:02Z
37,815,298
<p>This should work:</p> <pre><code>for index, value in enumerate(precipitation): yearmonthlst[index % 12].append(value) </code></pre>
0
2016-06-14T14:46:29Z
[ "python", "list", "loops", "iterator", "append" ]
Adding multiple variables to lists within a list in Python
37,815,171
<p>i would like to ask about how i could add multiple variables to a list within a list in python.</p> <pre><code>yearmonthlst = [[] for i in range(64)] precipitation = [197.6, 95.0, 37.1, 74.2, 65.3, 175.5, 114.6, 90.4, 26.7, 62.2, 58.9, 142.0, 129.0, 122.2...] </code></pre> <p>So for example here i have a list tha...
-1
2016-06-14T14:41:02Z
37,815,623
<pre><code>[precipitation[i:i+12] for i in range(0, len(precipitation), 12)] </code></pre> <p>input :</p> <pre><code>precipitation = [197.6, 95.0, 37.1, 74.2, 65.3, 175.5, 114.6, 90.4, 26.7, 62.2, 58.9, 142.0, 129.0, 122.2] </code></pre> <p>output :</p> <pre><code>[[197.6, 95.0, 37.1, 74.2, 65.3, 175.5, 114.6, 90....
0
2016-06-14T14:59:50Z
[ "python", "list", "loops", "iterator", "append" ]
How do I handle an item selection event in wxpython EditableListBox?
37,815,365
<p>I have an EditableListBox in a wxpython app. I want an event to trigger whenever the user clicks an item in the box. I can bind a function to EVT_LIST_ITEM_SELECTED, but this seems to break the edit buttons in the list box in a very bizarre way. The up arrow is disabled and doesn't do anything, and the down arrow...
0
2016-06-14T14:49:34Z
37,816,085
<p>When there are problems with controls derived from standard controls it is always a good idea to try to deactivate self-defined bindings (because they might overwrite some event handlers from the underlying control).</p> <p>When uncommenting the line with the binding to <code>change_text</code>, the control behaves...
1
2016-06-14T15:20:19Z
[ "python", "events", "wxpython" ]
Pyinstaller "Failed to execute script pyi_rth_pkgres" and missing packages
37,815,371
<p>This is my first time posting a question here as most of my questions have already been answered by someone else! I am working on a GUI application in python and am attempting to use pyinstaller to package it into a single folder and .exe for easier portability. Currently, I am using windows 10 and anaconda3 to ma...
0
2016-06-14T14:49:51Z
39,436,240
<p>I had the same problem. Was solved by reinstalling the pyinstaller with the developer's branch version, following the directions in: <a href="https://github.com/pyinstaller/pyinstaller/issues/2137" rel="nofollow">https://github.com/pyinstaller/pyinstaller/issues/2137</a></p> <p>The steps are:</p> <ul> <li>Remove P...
0
2016-09-11T12:45:12Z
[ "python", "opencv", "ffmpeg", "pyinstaller" ]
SyntaxError: unexpected character after line continuation character
37,815,397
<pre><code>import os os.system("grep MCM_END /storage/users/siditom/fastspace/AutoCaspSubmission/CASP12/T0860/stage2/xml/*.xml | sort -k 16 | grep -v NaN | tail -10 | awk '{print($1"\t"$16)}' | sed s/:\&lt;ProteinInfo//g | sed s/MESHI.SERVER_weightedMedianScore=\"//g | sed s^/storage/users/siditom/fastspace/AutoCaspSub...
1
2016-06-14T14:51:17Z
37,815,656
<p>Does writing your code as follows fix the issue. I believe your "\t" was read as a line continutation plus a <code>t</code> which would be an unexpected character.</p> <pre><code>import os os.system("grep MCM_END /storage/users/siditom/fastspace/AutoCaspSubmission/CASP12/T0860/stage2/xml/*.xml | sort -k 16 | grep -...
0
2016-06-14T15:01:44Z
[ "python", "python-2.7" ]
Removing lines from file python
37,815,411
<p>I have a file that looks something like </p> <pre><code>geneA geneB 134 geneC geneF 395 geneH geneD 958 geneF geneC 395 geneB geneA 134 geneD geneH 958 </code></pre> <p>I would like to remove the lines that have the same genes (that are in opposite order) so I just get </p> <pre><code>geneA geneB 134 geneC gene...
0
2016-06-14T14:51:56Z
37,815,971
<p>Convert the genes into a hashable form that can be added to a set and check that set as you go along. In this example, I sorted the genes so that order doesn't matter and then build them back into a single "normalized" string.</p> <pre><code>filename = 'a.txt' outfilename = 'aout.txt' seen = set() with open(filen...
3
2016-06-14T15:14:56Z
[ "python" ]
how to compare string in one line with string in next line?
37,815,497
<p>I have a file with about 16,000 lines in it. All of them have the same format. Here is a simple example if it:</p> <pre class="lang-none prettyprint-override"><code>ATOM 139 C1 DPPC 18 17.250 58.420 10.850 1.00 0.00 &lt;...&gt; ATOM 189 C1 DPPC 19 23.050 20.800 11.000 1.00 0.00 </c...
1
2016-06-14T14:54:49Z
37,815,805
<p>Try this (explanations in the comments).</p> <pre><code>data = """ATOM 139 C1 DPPC 18 17.250 58.420 10.850 1.00 0.00 ATOM 139 C1 DPPC 18 17.250 58.420 10.850 1.00 0.00 ATOM 139 C1 DPPC 18 17.250 58.420 10.850 1.00 0.00 ATOM 139 C1 DPPC 18 17.250 58.420 1...
1
2016-06-14T15:07:42Z
[ "python" ]
how to compare string in one line with string in next line?
37,815,497
<p>I have a file with about 16,000 lines in it. All of them have the same format. Here is a simple example if it:</p> <pre class="lang-none prettyprint-override"><code>ATOM 139 C1 DPPC 18 17.250 58.420 10.850 1.00 0.00 &lt;...&gt; ATOM 189 C1 DPPC 19 23.050 20.800 11.000 1.00 0.00 </c...
1
2016-06-14T14:54:49Z
37,817,084
<p>You can also easily solve this with a parallel list:</p> <pre><code>data = [] with open('data.txt', 'r') as datafile: for line in datafile: line=line.strip() if line: data.append(line); keywordList = [] for line in data: line = line.split() if (line[4] not in keywordList): ...
0
2016-06-14T16:06:26Z
[ "python" ]
how to compare string in one line with string in next line?
37,815,497
<p>I have a file with about 16,000 lines in it. All of them have the same format. Here is a simple example if it:</p> <pre class="lang-none prettyprint-override"><code>ATOM 139 C1 DPPC 18 17.250 58.420 10.850 1.00 0.00 &lt;...&gt; ATOM 189 C1 DPPC 19 23.050 20.800 11.000 1.00 0.00 </c...
1
2016-06-14T14:54:49Z
37,817,679
<p>Since your data appears to be fixed width fields in fixed width records, you can use the <code>struct</code> module to quickly break each line up into individual fields. </p> <p>Parsing all the fields of each line may be overkill when you only need to process one of them, but I'm doing it the way shown to illustrat...
0
2016-06-14T16:38:47Z
[ "python" ]
pandas convert object type to float
37,815,533
<p>I got the a Dataframe with a column like this</p> <pre><code>2011-06-15 8 472,00 2011-06-16 8 432,00 2011-06-17 8 464,00 2011-06-20 8 208,00 2011-06-21 8 504,00 Name: A.P.A, dtype: object </code></pre> <p>There's a space between in the number which I'd like to remove and turn the column into float, ...
1
2016-06-14T14:55:58Z
37,815,573
<p>Starting with a <code>pd.Series</code> called <code>s</code>:</p> <pre><code>date 2011-06-15 8 472,00 2011-06-16 8 432,00 2011-06-17 8 464,00 2011-06-20 8 208,00 2011-06-21 8 504,00 Name: value, dtype: object </code></pre> <p>You could:</p> <pre><code>s = pd.to_numeric(s.str.replace(' ', '').str.re...
1
2016-06-14T14:57:35Z
[ "python", "pandas" ]
Plot the time evolution of a variable in a fixed point of a netcdf file using python
37,815,568
<p>I have a netcdf file with the time-dependent distribution of the velocity field in a tank of water. I roughly know how to plot the big picture of the velocity field in a specific time step, but I would like to plot the change in time of the velocity variables (u,v,w) in a fixed point of space. </p> <p>Everything us...
0
2016-06-14T14:57:23Z
37,836,125
<p>Once you loaded the data this is very easy using slicing. For example, with a NetCDF data file from our model as an example:</p> <p>Output of <code>ncdump -h</code>:</p> <pre><code>netcdf w.xz { dimensions: x = 1024 ; y = 1 ; zh = 512 ; time = UNLIMITED ; // (81 currently) variables: ...
0
2016-06-15T12:56:29Z
[ "python", "netcdf" ]
pandas set one cell value equals to another
37,815,612
<p>I want to set a cell of pandas dataframe equal to another. For example:</p> <pre><code>station_dim.loc[station_dim.nlc==573,'longitude']=station_dim.loc[station_dim.nlc==5152,'longitude'] </code></pre> <p>However, when I checked </p> <pre><code>station_dim.loc[station_dim.nlc==573,'longitude'] </code></pre> <p>I...
1
2016-06-14T14:59:19Z
37,815,809
<p>Take a look at <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.get_value.html" rel="nofollow"><code>get_value</code></a>, or use <code>.values</code>:</p> <pre><code>station_dim.loc[station_dim.nlc==573,'longitude']=station_dim.loc[station_dim.nlc==5152,'longitude'].values[0] </code>...
2
2016-06-14T15:08:06Z
[ "python", "pandas", "select" ]
Grabbing a screenshot from Twitch with Python
37,815,613
<p>Right now, I'm starting a Python project which is supposed to take a screenshot of selected twitch channels, modify those screenshots and put them on a GUI. The GUI shouldn't be a problem, but I'm having problems with the screenshots.<br> I've found 2 resources to deal with the twitch communication: the python-twitc...
2
2016-06-14T14:59:22Z
37,815,657
<p>You shouldn't remove things from an open source project you are trying to use.</p> <p>Instead, install the missing packages,</p> <p><code>pip install requests</code> if you have a problem with that maybe you don't have <code>pip</code>, so just install it.</p> <p>Or use this <code>python.exe -m pip install reques...
1
2016-06-14T15:01:44Z
[ "python", "screenshot", "python-3.5", "twitch" ]
Grabbing a screenshot from Twitch with Python
37,815,613
<p>Right now, I'm starting a Python project which is supposed to take a screenshot of selected twitch channels, modify those screenshots and put them on a GUI. The GUI shouldn't be a problem, but I'm having problems with the screenshots.<br> I've found 2 resources to deal with the twitch communication: the python-twitc...
2
2016-06-14T14:59:22Z
37,816,071
<p>Selenium can be handy for navigating a site and taking screenshots.</p> <p><a href="http://selenium-python.readthedocs.io/" rel="nofollow">http://selenium-python.readthedocs.io/</a></p> <p>Fleshed out an example that should do what you need. Gist link as well : <a href="https://gist.github.com/ryantownshend/6449c...
0
2016-06-14T15:19:43Z
[ "python", "screenshot", "python-3.5", "twitch" ]
path is deprecated (django.contrib.auth.views.password_reset_confirm)
37,815,648
<p>I am working on password reset on django project, when the email address is sent i get</p> <pre><code>path is deprecated (django.contrib.auth.views.password_reset_confirm) </code></pre> <p>at the command prompt.</p> <p>Here is my url.py</p> <pre><code>from django.conf.urls import patterns, include, url from djan...
0
2016-06-14T15:01:14Z
37,815,715
<p>Your urls look OK, so my guess is the problem is in your template.</p> <p>Look for</p> <pre><code>{% url 'django.contrib.auth.views.password_reset_confirm' uidb64=uid token=token %} </code></pre> <p>in your <code>registration/password_reset_email.html</code> template, and replace it with</p> <pre><code>{% url 'p...
1
2016-06-14T15:04:09Z
[ "python", "django" ]
Separating documents into different folders in Python
37,815,654
<p>I have a folder Data with list of documents:</p> <pre><code>A.txt A.xml B.txt B.xml C.txt C.xml ... ... Z.txt Z.xml </code></pre> <p>How can I split these documemts into three folders: random 50% of them in Folder1, 25% in Folder2, and the rest 25% in Folder3? One document can be only in one folder, and its impor...
-1
2016-06-14T15:01:35Z
37,817,362
<p>I fond a way how to do it, so if smb else will get the same problem, here you are:</p> <pre><code>import os data=os.listdir("C:\Data") data1 = data[:50] data2 = data[50:] data3=data2[25:] import shutil for i in data1: shutil.move('C:\Data'+'\\'+i, 'C:\Data\Folder1') for j in data2: shutil.move('C:\Data'+'...
0
2016-06-14T16:21:39Z
[ "python", "xml", "split", "folder", "document" ]
Unicode object to a list
37,815,758
<p>I have a utf8 - text corpus I can read easily in Python 2.7 : </p> <pre><code>sentence = codecs.open("D:\\Documents\\files\\sentence.txt", "r", encoding="utf8") sentence = sentence.read() &gt; This is my sentence in the right format </code></pre> <p>However, when I pass this text corpus to a list (for example, fo...
0
2016-06-14T15:06:00Z
37,816,334
<p>Hm, <code>codecs.open(...)</code> returns a "wrapped version of the underlying file object" then you overwrite this variable with the result from executing the read method on that object. Brave, irritating - but ok ;-) </p> <p>When you type say an äöüß into your "notebook", does it show like "this" or do you se...
0
2016-06-14T15:31:55Z
[ "python", "python-2.7", "unicode", "nltk", "python-unicode" ]
Unicode object to a list
37,815,758
<p>I have a utf8 - text corpus I can read easily in Python 2.7 : </p> <pre><code>sentence = codecs.open("D:\\Documents\\files\\sentence.txt", "r", encoding="utf8") sentence = sentence.read() &gt; This is my sentence in the right format </code></pre> <p>However, when I pass this text corpus to a list (for example, fo...
0
2016-06-14T15:06:00Z
37,827,761
<p>It's all in how you <code>print</code>. Python 2 displays lists using ASCII-only characters and substituting backslash escape codes for non-ASCII characters. This is to make it easy to see hidden characters that normal printing would make invisible, like the double byte-order-mark (BOM) <code>\ufeff</code> you see...
0
2016-06-15T06:35:23Z
[ "python", "python-2.7", "unicode", "nltk", "python-unicode" ]
download csv file from my project path django
37,815,789
<p>I generated a csv file through my code, and after generation, it goes to the path of my project, my project called <code>sample</code>, so the file path <code>sample/output.csv</code>.. I added a function for the download and I called this function inside the my main function ( home), but the download is not working...
0
2016-06-14T15:07:13Z
37,816,279
<p>If you want to send the file to the browser that way, the file has to be un a directory directly accessible by webserver. In most cases, the folder where all Python code is stored is not accesible. </p> <p>Try to put the file in a directory accesible by webserver. Another way of sending the file is reading it throu...
0
2016-06-14T15:29:05Z
[ "python", "django", "csv", "django-views" ]
download csv file from my project path django
37,815,789
<p>I generated a csv file through my code, and after generation, it goes to the path of my project, my project called <code>sample</code>, so the file path <code>sample/output.csv</code>.. I added a function for the download and I called this function inside the my main function ( home), but the download is not working...
0
2016-06-14T15:07:13Z
37,816,292
<p>For the main issue with your download not working, please take a look at <a href="http://stackoverflow.com/a/5147454/1199464">this answer</a> because the first argument for your HttpResponse should be your data to actually send.</p> <p>Now, also you should do is look at interacting with the storage classes &amp; <c...
0
2016-06-14T15:29:43Z
[ "python", "django", "csv", "django-views" ]
download csv file from my project path django
37,815,789
<p>I generated a csv file through my code, and after generation, it goes to the path of my project, my project called <code>sample</code>, so the file path <code>sample/output.csv</code>.. I added a function for the download and I called this function inside the my main function ( home), but the download is not working...
0
2016-06-14T15:07:13Z
38,001,890
<p>I ended it up using <code>FILEwrapper:</code></p> <pre><code>def send_file(request): filename = settings.MEDIA_ROOT +'/'+ 'output1.csv' #filename= r"C:\Users\A6B0SZZ\PycharmProjects\sample\media\output1.csv" download_name ="output1.csv" wrapper = FileWrapper(open(filename)) response = HttpRespon...
0
2016-06-23T21:07:28Z
[ "python", "django", "csv", "django-views" ]
Trouble with finding closest date to today from database dates
37,815,889
<p>Using django/models/views, I'm trying to return the closest date to today from a database where one of the columns is a date. (2016/03/25)</p> <p>The code I have right now to find the date is:</p> <pre><code>now = datetime.datetime.now().date() statement_list = StatementData.objects.filter(date__gt=now()).reverse(...
0
2016-06-14T15:11:18Z
37,816,019
<p>There are a few problems with your code</p> <pre><code>now = datetime.datetime.now().date() statement_list = StatementData.objects.filter(date__gt=now()).reverse()[0] </code></pre> <ol> <li>remove <code>()</code> from <code>date</code></li> <li>remove the <code>()</code> from the second line</li> <li>You can just ...
0
2016-06-14T15:17:01Z
[ "python", "django", "postgresql", "views" ]
Trouble with finding closest date to today from database dates
37,815,889
<p>Using django/models/views, I'm trying to return the closest date to today from a database where one of the columns is a date. (2016/03/25)</p> <p>The code I have right now to find the date is:</p> <pre><code>now = datetime.datetime.now().date() statement_list = StatementData.objects.filter(date__gt=now()).reverse(...
0
2016-06-14T15:11:18Z
37,816,190
<p>Why don't you simply try :</p> <pre><code> select * from StatementDate order by now()-date limit 1 </code></pre>
0
2016-06-14T15:25:24Z
[ "python", "django", "postgresql", "views" ]
Plot a Correlation Circle in Python
37,815,987
<p>I've been doing some Geometrical Data Analysis (GDA) such as Principal Component Analysis (PCA). I'm looking to plot a Correlation Circle... these look a bit like this:</p> <p><img src="http://i.stack.imgur.com/2pjd8.png" alt="1]"></p> <p>Basically, it allows to measure to which extend the Eigenvalue / Eigenvector...
1
2016-06-14T15:15:38Z
37,853,830
<p>I agree it's a pity not to have it in some mainstream package such as sklearn.</p> <p>Here is a home-made implementation: <a href="https://github.com/mazieres/analysis/blob/master/analysis.py#L19-34" rel="nofollow">https://github.com/mazieres/analysis/blob/master/analysis.py#L19-34</a></p>
1
2016-06-16T08:28:55Z
[ "python", "correlation", "pca", "eigenvalue", "eigenvector" ]
Pandas series has np.round error that dataframe does not
37,816,056
<p>I am not able to np.round with a series but can with the parent dataframe. </p> <p>I am hoping to set-up a table of the <code>df.describe()</code>, but only the needed column. I can round the full <code>df.describe()</code> with numpy, I can print the unrounded series or use <a href="http://stackoverflow.com/questi...
0
2016-06-14T15:19:00Z
39,315,004
<p>If the version of pandas you are using is 0.18.0 then issue is a bug on numpy that insists on call with positional arguments a 'sub-class' method. The bug has been raised <a href="https://github.com/pydata/pandas/issues/12600" rel="nofollow">here</a> and will be fixed in version 0.18.1.</p>
0
2016-09-04T08:31:23Z
[ "python", "numpy", "pandas" ]
IOError: [Errno socket error] [Errno 8] nodename nor servname provided, or not known
37,816,238
<p>I was trying to scrape and save the stock data to SQL using multithreading from Yahoo finance. However, I got the following error:</p> <pre><code>*Exception in thread Thread-3091: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in _...
0
2016-06-14T15:27:05Z
37,816,721
<p>I remember that I had problems with multithreading and massive socket opening once. An additional lock solved the problem for me. I did not try to find the actuel problem, however. The <a href="https://docs.python.org/2/library/urllib.html" rel="nofollow">urllib doc</a> does not say anything about thread safety. You...
0
2016-06-14T15:50:22Z
[ "python", "sqlite", "web-scraping" ]
IOError: [Errno socket error] [Errno 8] nodename nor servname provided, or not known
37,816,238
<p>I was trying to scrape and save the stock data to SQL using multithreading from Yahoo finance. However, I got the following error:</p> <pre><code>*Exception in thread Thread-3091: Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 810, in _...
0
2016-06-14T15:27:05Z
38,988,155
<p>I got this error as well. I just add some sleep time for each thread and the problem is resolved. I used time.sleep(0.1).</p>
0
2016-08-17T04:32:01Z
[ "python", "sqlite", "web-scraping" ]
Speed up web-scraping
37,816,338
<p>I have a project where I have to scrape all the ratings of 50 actors/actresses, which means I have to access and scrape around 3500 web pages. This takes way longer than I expected and I'm looking for a way to speed up things. I know there are frameworks like scrapy, but I'd like to work without any other modules. I...
0
2016-06-14T15:32:14Z
37,816,425
<p>The main bottleneck is easy to determine by just looking at the code. It is of a <strong>blocking nature</strong>. You don't download/parse the next page until the current is being processed.</p> <p>If you want to speed things up, do it <em>asynchronously in a non-blocking manner</em>. This is what <a href="http://...
5
2016-06-14T15:36:23Z
[ "python", "html", "web-scraping", "beautifulsoup", "html-parsing" ]
How to find digits in string
37,816,463
<pre><code>text1 = 'three digits NUMBER_001' </code></pre> <p>The code below properly finds three digits in a string following after the characters "NUMBER_": <code>['NUMBER_123']</code>:</p> <pre><code>result = re.findall('NUMBER_\d\d\d', text1) print result </code></pre> <p>But it returns incomplete number if the ...
-5
2016-06-14T15:37:59Z
37,816,514
<p>Just replace your regexp by:</p> <pre><code>result = re.findall('NUMBER_([0-9]+)', text1) </code></pre>
0
2016-06-14T15:40:24Z
[ "python" ]
How to find digits in string
37,816,463
<pre><code>text1 = 'three digits NUMBER_001' </code></pre> <p>The code below properly finds three digits in a string following after the characters "NUMBER_": <code>['NUMBER_123']</code>:</p> <pre><code>result = re.findall('NUMBER_\d\d\d', text1) print result </code></pre> <p>But it returns incomplete number if the ...
-5
2016-06-14T15:37:59Z
37,816,657
<p>Just use <code>()</code> in your regEx:</p> <pre><code>result = re.findall('NUMBER_(\d\d\d)', text1) </code></pre> <p>the same shall be written as,</p> <pre><code>result = re.findall('NUMBER_(\d{3})', text1) </code></pre> <p>Alternatively, any number of digits:</p> <pre><code>result = re.findall('NUMBER_([\d]+)...
1
2016-06-14T15:47:44Z
[ "python" ]
Consuming a Python made Azure web service in Python
37,816,503
<p>I'm having an issue consuming Microsoft Azure web services in Python when the web service was published from Python first. I have created a web service using only Azure, then consumed that web service from Python successfully using the sample Python code from the Batch Execution API Help page. However, I also wanted...
0
2016-06-14T15:39:59Z
37,855,388
<p>Based on my understanding, I see you want to consume the published Azure ML web service via http request in Python. </p> <p>According to the error information, The request failed with status code 401 means the request miss the header <code>Authorization: Bearer &lt;your-webservice-api key&gt;</code>.</p> <p>You ca...
0
2016-06-16T09:38:32Z
[ "python", "web-services", "python-2.7", "azure" ]
TypeError: range() integer end argument expected, got str
37,816,506
<p>I am not understanding where did I possibly go wrong in the below code. It keeps saying range() Integer end argument expected, got str.</p> <pre><code>def test(): nameList = ["Default", "Customize..."] for name in nameList: activateFieldsSubMenus(2, name) def activateFieldsSubMenus(subMenusN...
-2
2016-06-14T15:40:15Z
37,816,564
<pre><code>activateFieldsSubMenus(2, name) </code></pre> <p><code>name</code> is a string not an integer, as your list only contains strings.</p> <p>In your <code>activateFieldsSubMenus</code> routine <code>name</code>, now called <code>tries</code>, is then passed into <code>range(tries)</code>.</p> <hr> <p>You pr...
4
2016-06-14T15:42:45Z
[ "python", "typeerror" ]
TypeError: range() integer end argument expected, got str
37,816,506
<p>I am not understanding where did I possibly go wrong in the below code. It keeps saying range() Integer end argument expected, got str.</p> <pre><code>def test(): nameList = ["Default", "Customize..."] for name in nameList: activateFieldsSubMenus(2, name) def activateFieldsSubMenus(subMenusN...
-2
2016-06-14T15:40:15Z
37,816,589
<p>You are calling <code>activateFieldsSubMenus</code> with the 2 parameters mixed up I believe, try: </p> <pre><code>activateFieldsSubMenus(name, tries=2) </code></pre>
2
2016-06-14T15:43:59Z
[ "python", "typeerror" ]
With xpath find an input field by value with no value attribute
37,816,521
<p>Given this html:</p> <pre><code>&lt;input id="test" value="my text" /&gt; </code></pre> <p>it is easy to get a handle on the input element with xpath. Something like:</p> <pre><code>input[@value="my text"] </code></pre> <p>But what if the original html looks like this:</p> <pre><code>&lt;input id="test" /&gt; <...
1
2016-06-14T15:40:40Z
37,817,547
<p>Taking into account that this is Python+Selenium, I would approach it the following way:</p> <pre><code>inputs = driver.find_elements_by_tag_name("input") # TODO: improve the locator to get less input elements input_elm = next(input_elm for input_elm in inputs if input.get_attribute("value") == "...
3
2016-06-14T16:31:32Z
[ "python", "selenium", "xpath" ]
python authentication with requests library via POST
37,816,565
<p>I read several similar topic.. I try to follow the others examples but I'm still stuck in the middle of nowhere.. I have basic skills of python programming and little knowledge about http protocol, my two goals are: -succesfull authentication to a website via requests library -fetch data from the website after the l...
1
2016-06-14T15:42:46Z
37,821,714
<p>If you look at what gets posted:</p> <p><a href="http://i.stack.imgur.com/sV1Uc.png" rel="nofollow"><img src="http://i.stack.imgur.com/sV1Uc.png" alt="enter image description here"></a> </p> <p>You see you need the <code>redirect_url</code> and <code>site</code> which you can parse from the input in the source wit...
1
2016-06-14T20:41:41Z
[ "python", "http-post", "python-requests", "forms-authentication" ]
Restrict request to only ask for HTTP/1.0 [to prevent chunking error]
37,816,596
<p>I am receiving a the error <code>requests.exceptions.ChunkedEncodingError: ('Connection broken: IncompleteRead(0 bytes read)', IncompleteRead(0 bytes read))</code> from a server using the Request package in Python.</p> <p>It is my understanding from the post <a href="http://stackoverflow.com/questions/31969990/how-...
0
2016-06-14T15:44:29Z
37,818,792
<p>You can try setting the HTTP version used in the <code>httplib</code> backend used by Requests.</p> <p>On Python 2, you can do that like so:</p> <pre><code>import httplib httplib.HTTPConnection._http_vsn = 10 httplib.HTTPConnection._http_vsn_str = 'HTTP/1.0' </code></pre> <p>and with Python 3, httplib was renamed...
1
2016-06-14T17:43:57Z
[ "python", "python-requests" ]
Why does this generator not work in python
37,816,676
<p>Why does <code>if</code> not work in the below generator</p> <pre><code>def mygen(m): n = 0 if n &lt; m: n = n + 1 yield n counter = mygen(5) next(counter) 1 next(counter) StopIteration </code></pre> <p>but <code>while</code> does?</p> <pre><code>def mygen(m): n = 0 while n &lt; ...
1
2016-06-14T15:48:39Z
37,816,733
<p>The <code>while</code> loop compares <code>n</code> and <code>m</code> repeatedly (until the condition is false) whereas the <code>if</code> statement compares them once and then finishes. The <code>if</code> statement is working, just not in the way you are expecting.</p>
0
2016-06-14T15:50:54Z
[ "python" ]
Maya python trying to template / untemplate channel
37,816,681
<p>I'm a newbie on Maya programming. </p> <p>I'm trying to make a script to check and template/untemplate a channel. I have a transform node opened in graph editor called 'SKEL01_002:main_C_001_CTRL'. Then I select 'TranslateX', and still in graph editor I go to CURVES --> TEMPLATE CHANNEL</p> <p>I can list the Curve...
1
2016-06-14T15:48:47Z
37,817,990
<p>listening with echo all command, you see it prompt : <code>doTemplateChannel graphEditor1FromOutliner 1;</code></p> <p>doing <code>whatIs doTemplateChannel;</code> , you can see it prompt the mel procedure : // Result: Mel procedure found in: <code>somePath/autodesk/maya2015-x64/scripts/others/loadAnimMenuLibrary.m...
3
2016-06-14T16:54:45Z
[ "python", "maya", "autodesk", "channels" ]
How to properly get spyne polymorphic tagnames
37,816,715
<p>Is there a way to get the specific class tag names from my spyne class definitions?</p> <p>Given the case, my class hierarchy looks like this:</p> <pre><code># models.py class Vehicle(ComplexModel): ... class Car(Vehicle): ... class Bike(Vehicle): ... </code></pre> <p>Then I followed the instruction...
0
2016-06-14T15:50:12Z
37,897,219
<p>This is how XML polymorphism is supposed to work. <code>libxml2</code>'s schema validator (that you use through lxml) should interpret it properly. </p> <p>OTOH, If you are sure you want distinction solely through tag names, have a look at the <code>&lt;choice&gt;</code> tag: <a href="http://w3.org/TR/xmlschema-1/#...
0
2016-06-18T12:57:16Z
[ "python", "xml", "wsdl", "spyne" ]
Sum all numbers in a given range of a given list Python
37,816,765
<p>How can I write a function to get the sum of the items in the given list between the indices a and b. For example give <code>aList=[6,3,4,2,5]</code> and <code>a=1</code>, <code>b=3</code>, the function should return 9. Here is my code:</p> <pre><code>def sumRange(L,a,b): sum= [] L = [6,3,4,2,5] for i i...
1
2016-06-14T15:52:21Z
37,816,816
<p>You can achieve this with list slicing:</p> <pre><code>sum(your_list[a:b + 1]) </code></pre> <p>Here, <code>your_list[a:b+1]</code> is a <em>slice</em> - a part of <em>your list</em> starting from the index <code>a</code> and ending with the index <code>b</code>, <em>including the values at both indexes</em> (this...
3
2016-06-14T15:54:24Z
[ "python", "sum", "range", "indices" ]
Sum all numbers in a given range of a given list Python
37,816,765
<p>How can I write a function to get the sum of the items in the given list between the indices a and b. For example give <code>aList=[6,3,4,2,5]</code> and <code>a=1</code>, <code>b=3</code>, the function should return 9. Here is my code:</p> <pre><code>def sumRange(L,a,b): sum= [] L = [6,3,4,2,5] for i i...
1
2016-06-14T15:52:21Z
37,816,825
<p>You can simply use index slicing in python and the sum function.</p> <pre><code>return sum(L[a:b]) </code></pre>
1
2016-06-14T15:54:47Z
[ "python", "sum", "range", "indices" ]
Sum all numbers in a given range of a given list Python
37,816,765
<p>How can I write a function to get the sum of the items in the given list between the indices a and b. For example give <code>aList=[6,3,4,2,5]</code> and <code>a=1</code>, <code>b=3</code>, the function should return 9. Here is my code:</p> <pre><code>def sumRange(L,a,b): sum= [] L = [6,3,4,2,5] for i i...
1
2016-06-14T15:52:21Z
37,816,881
<p>It seems like you want do roll your own solution. You can do it like this (based on the code you had in your question):</p> <pre><code>def sumRange(L,a,b): ...
1
2016-06-14T15:57:06Z
[ "python", "sum", "range", "indices" ]
Python: why is "if <some integer>" equivalent to "if True"?
37,816,786
<p>I have come across this piece of code:</p> <pre><code>counts = 128 * [0] # some other steps here that modify the variable counts... # in the end we have something like counts=[12, 583, 0, etc. , etc., 384] for i in range(len(counts)): if counts[i]: outfile.write("%-12s%d\n" % (display(i), counts[i])) ...
-1
2016-06-14T15:53:17Z
37,816,872
<p><a href="https://docs.python.org/2/library/stdtypes.html#truth-value-testing" rel="nofollow">Quoting docs</a>:</p> <blockquote> <p>Any object can be tested for truth value, for use in an if or while condition or as operand of the Boolean operations below. The following values are considered false:</p> <u...
3
2016-06-14T15:56:44Z
[ "python", "if-statement" ]
Python: why is "if <some integer>" equivalent to "if True"?
37,816,786
<p>I have come across this piece of code:</p> <pre><code>counts = 128 * [0] # some other steps here that modify the variable counts... # in the end we have something like counts=[12, 583, 0, etc. , etc., 384] for i in range(len(counts)): if counts[i]: outfile.write("%-12s%d\n" % (display(i), counts[i])) ...
-1
2016-06-14T15:53:17Z
37,816,896
<p><code>3 == True</code> is comparing 3-as-an-integer to True-as-a-boolean.</p> <p><code>if 3:</code> is coercing 3 to a boolean.</p> <p>You'll see that <code>bool(3) == True</code> is true.</p>
5
2016-06-14T15:57:49Z
[ "python", "if-statement" ]
Python: why is "if <some integer>" equivalent to "if True"?
37,816,786
<p>I have come across this piece of code:</p> <pre><code>counts = 128 * [0] # some other steps here that modify the variable counts... # in the end we have something like counts=[12, 583, 0, etc. , etc., 384] for i in range(len(counts)): if counts[i]: outfile.write("%-12s%d\n" % (display(i), counts[i])) ...
-1
2016-06-14T15:53:17Z
37,817,309
<p>Simple in your shell try <code>bool(3)</code>(which is <code>True</code>) and <code>bool(0)</code>(which is <code>False</code>).</p> <p><code>bool</code> of zero is <code>False</code> and <code>bool</code> of non-zero is <code>True</code>.</p>
0
2016-06-14T16:18:43Z
[ "python", "if-statement" ]
pytest: how to make dedicated test directory
37,816,820
<p>I want next project structure: </p> <pre><code>|--folder/ | |--tests/ | |--project/ </code></pre> <p>Lets write simple example:</p> <pre><code>|--test_pytest/ | |--tests/ | | |--test_sum.py | |--t_pytest/ | | |--sum.py | | |--__init__.py </code></pre> <p>sum.py: </p> <pre><code>def my_sum(a, b): ...
0
2016-06-14T15:54:35Z
37,817,776
<p>Thank you, jonrsharpe. Py.test does no magic, I need to make my packages importable myself. There is one of possible solutions:</p> <pre><code> $ export PYTHONPATH="${PYTHONPATH}: [Path to folder with my module]" </code></pre> <p>( PYTHONPATH is one of path sources for sys.path )<br> If I need to make this ch...
0
2016-06-14T16:44:45Z
[ "python", "testing", "py.test", "project-structure" ]
pytest: how to make dedicated test directory
37,816,820
<p>I want next project structure: </p> <pre><code>|--folder/ | |--tests/ | |--project/ </code></pre> <p>Lets write simple example:</p> <pre><code>|--test_pytest/ | |--tests/ | | |--test_sum.py | |--t_pytest/ | | |--sum.py | | |--__init__.py </code></pre> <p>sum.py: </p> <pre><code>def my_sum(a, b): ...
0
2016-06-14T15:54:35Z
37,826,391
<p><strong>With pytest:</strong></p> <pre><code>if __name__ == '__main__': import pytest pytest.main(['-x', 'tests', '--capture', 'sys']) # Note: tests is the directory name </code></pre> <p>This might be helpful for solving your problem <strong>with unittest:</strong></p> <p>Assume we have starter script...
-1
2016-06-15T04:50:42Z
[ "python", "testing", "py.test", "project-structure" ]
pytest: how to make dedicated test directory
37,816,820
<p>I want next project structure: </p> <pre><code>|--folder/ | |--tests/ | |--project/ </code></pre> <p>Lets write simple example:</p> <pre><code>|--test_pytest/ | |--tests/ | | |--test_sum.py | |--t_pytest/ | | |--sum.py | | |--__init__.py </code></pre> <p>sum.py: </p> <pre><code>def my_sum(a, b): ...
0
2016-06-14T15:54:35Z
37,929,854
<p>An alternative way is making tests a module as well, by adding __init__.py file in folder tests. One of the most popular python lib requests <a href="https://github.com/kennethreitz/requests" rel="nofollow">https://github.com/kennethreitz/requests</a> is doing in this way in their unit tests folder tests. You don't ...
0
2016-06-20T18:56:56Z
[ "python", "testing", "py.test", "project-structure" ]
Python "String Index Out of Range" during for row operation
37,816,928
<p>Hope you can help. I'm trying to iterate over a .csv file and delete rows where the first character of the first item is a #. Whilst my code does indeed delete the necessary rows, I'm being presented with a "string index out of range" error. </p> <p>My code is as below:</p> <pre><code>input=open("/home/stephen/De...
0
2016-06-14T15:59:37Z
37,817,017
<p>I suspect that there are lines with an empty first cell, so <code>row[0][0]</code> tries to access the first character of the empty string.</p> <p>You should try:</p> <pre><code>for row in csv.reader(input): if not row[0].startswith('#'): writer.writerow(row) </code></pre>
0
2016-06-14T16:03:35Z
[ "python", "list", "for-loop" ]
Python "String Index Out of Range" during for row operation
37,816,928
<p>Hope you can help. I'm trying to iterate over a .csv file and delete rows where the first character of the first item is a #. Whilst my code does indeed delete the necessary rows, I'm being presented with a "string index out of range" error. </p> <p>My code is as below:</p> <pre><code>input=open("/home/stephen/De...
0
2016-06-14T15:59:37Z
37,817,021
<p>Check if the string is empty with <code>if row[0]</code> before trying to index:</p> <pre><code>input=open("/home/stephen/Desktop/paths_output.csv", 'rb') output=open("/home/stephen/Desktop/paths_output2.csv", "wb") writer = csv.writer(output) for row in csv.reader(input): if row[0] and row[0][0] != '#': # here...
0
2016-06-14T16:03:48Z
[ "python", "list", "for-loop" ]
Python "String Index Out of Range" during for row operation
37,816,928
<p>Hope you can help. I'm trying to iterate over a .csv file and delete rows where the first character of the first item is a #. Whilst my code does indeed delete the necessary rows, I'm being presented with a "string index out of range" error. </p> <p>My code is as below:</p> <pre><code>input=open("/home/stephen/De...
0
2016-06-14T15:59:37Z
37,817,043
<p>You are likely running into an empty string.</p> <p>Perhaps try </p> <p>`if row and row[0][0] != '#':</p>
0
2016-06-14T16:04:53Z
[ "python", "list", "for-loop" ]
Python "String Index Out of Range" during for row operation
37,816,928
<p>Hope you can help. I'm trying to iterate over a .csv file and delete rows where the first character of the first item is a #. Whilst my code does indeed delete the necessary rows, I'm being presented with a "string index out of range" error. </p> <p>My code is as below:</p> <pre><code>input=open("/home/stephen/De...
0
2016-06-14T15:59:37Z
37,817,108
<p>Then why don't you make sure you don't bump into any of those even if they exist by checking if the line is empty first like so:</p> <pre><code>input=open("/home/stephen/Desktop/paths_output.csv", 'rb') output=open("/home/stephen/Desktop/paths_output2.csv", "wb") writer = csv.writer(output) for row in csv.reader(in...
0
2016-06-14T16:07:47Z
[ "python", "list", "for-loop" ]
Python "String Index Out of Range" during for row operation
37,816,928
<p>Hope you can help. I'm trying to iterate over a .csv file and delete rows where the first character of the first item is a #. Whilst my code does indeed delete the necessary rows, I'm being presented with a "string index out of range" error. </p> <p>My code is as below:</p> <pre><code>input=open("/home/stephen/De...
0
2016-06-14T15:59:37Z
37,817,242
<p>Why not provide working code (imports included) and wrap as usual the physical resources in context managers?</p> <p>Like so:</p> <pre><code>#! /usr/bin/env python """Only strip those rows that start with hash (#).""" import csv IN_F_PATH = "/home/stephen/Desktop/paths_output.csv" OUT_F_PATH = "/home/stephen/Desk...
0
2016-06-14T16:14:56Z
[ "python", "list", "for-loop" ]
print list x times and change its elements python
37,816,964
<p>I've been struggling about this example in Python. I have a list which consists of some text: x = ["line1\n","line2\n","line3\n"] then I want to modify its elements and print the list 3 times. This is my code now:</p> <pre><code>for y in range(3): for n,i in enumerate(x): if i == 'line1\n': ...
-2
2016-06-14T16:01:19Z
37,817,238
<pre><code>for y in range(3): for n,i in enumerate(x): if i == 'line1\n': x[n] = 'line1' + str(y) + '\n' if i == 'line2\n': x[n] = 'line2' + str(y) + '\n' if i == 'line3\n': x[n] = 'line3' + str(y) + '\n' </code></pre> <p>will set each line to be </p> <p...
1
2016-06-14T16:14:40Z
[ "python", "list" ]
print list x times and change its elements python
37,816,964
<p>I've been struggling about this example in Python. I have a list which consists of some text: x = ["line1\n","line2\n","line3\n"] then I want to modify its elements and print the list 3 times. This is my code now:</p> <pre><code>for y in range(3): for n,i in enumerate(x): if i == 'line1\n': ...
-2
2016-06-14T16:01:19Z
37,817,259
<p>If I understood you right on what you are trying to achieve, this is the solution:</p> <p>I changed the <code>str(y)</code> to <code>str(n)</code> wich was the source of the wrong counting.</p> <pre><code>x = ["line1\n", "line2\n", "line3\n"] for n, i in enumerate(x): if i == 'line1\n': x[n] = 'line1'...
0
2016-06-14T16:15:58Z
[ "python", "list" ]
print list x times and change its elements python
37,816,964
<p>I've been struggling about this example in Python. I have a list which consists of some text: x = ["line1\n","line2\n","line3\n"] then I want to modify its elements and print the list 3 times. This is my code now:</p> <pre><code>for y in range(3): for n,i in enumerate(x): if i == 'line1\n': ...
-2
2016-06-14T16:01:19Z
37,817,303
<p>Your enumeration runs through correctly the first time, and changes all the lines to </p> <pre><code> x[0] = line10\n x[1] = line20\n x[2] = line30\n </code></pre> <p>Then your if statements no longer apply. They're still looking for <code>if x[0] == 'line1\n':</code> but now <code>x[0] = line10\n</code></p> <p...
0
2016-06-14T16:18:23Z
[ "python", "list" ]
print list x times and change its elements python
37,816,964
<p>I've been struggling about this example in Python. I have a list which consists of some text: x = ["line1\n","line2\n","line3\n"] then I want to modify its elements and print the list 3 times. This is my code now:</p> <pre><code>for y in range(3): for n,i in enumerate(x): if i == 'line1\n': ...
-2
2016-06-14T16:01:19Z
37,817,307
<p>Python strings are immutable. So you need to create a new string and can't modify it.</p> <p>Though what you ask for can be achieved in a number of ways, using list comprehension would be straight forward.</p> <p><code>print [ line.strip('\n')+str(i)+'\n' for i,line in enumerate(x)]</code></p> <p>You get each ele...
0
2016-06-14T16:18:31Z
[ "python", "list" ]
Python deleting local variables through a loop
37,817,075
<p>I wrote the following code in middle of a function to delete all variables except few.</p> <pre><code>dontDelete = ['Cat','Dog'] for vi in dir(): #'Cat','Dog','Pig','Elephant','Lion' if vi in dontDelete: continue else: del locals()[vi] </code></pre> <p>But it doesn't delete any variables ev...
-2
2016-06-14T16:06:06Z
37,817,248
<p><a href="https://docs.python.org/3/library/functions.html#locals" rel="nofollow"><code>locals()</code> is a view on the locals, mutating it is not recommended and provides no guarantees as to whether the "real" values are changed or not.</a>, per the note from the docs:</p> <blockquote> <p>Note: The contents of t...
1
2016-06-14T16:15:12Z
[ "python" ]
Python django / error no attribute browser
37,817,276
<p>I get this error with no attribute browser</p> <p><a href="http://i.stack.imgur.com/e4pCw.png" rel="nofollow"><img src="http://i.stack.imgur.com/e4pCw.png" alt="enter image description here"></a></p>
-8
2016-06-14T16:17:09Z
37,817,560
<p>Your methods should be <code>setUp</code> and <code>tearDown</code>, not <code>SetUp</code> and <code>TearDown</code>.</p>
0
2016-06-14T16:32:11Z
[ "python", "django" ]
Python django / error no attribute browser
37,817,276
<p>I get this error with no attribute browser</p> <p><a href="http://i.stack.imgur.com/e4pCw.png" rel="nofollow"><img src="http://i.stack.imgur.com/e4pCw.png" alt="enter image description here"></a></p>
-8
2016-06-14T16:17:09Z
38,091,938
<p>modify your code </p> <pre><code>def SetUp -&gt; def setUp def TearDown -&gt; def tearDown </code></pre>
0
2016-06-29T06:31:33Z
[ "python", "django" ]
Python: Making a list that includes functions but has as-yet undefined arguments
37,817,325
<p>Generally, what I would like to do is make a list that involves some function or functions, but the argument of that function will change based on an "i" of a for loop, and so the argument is not fully defined when I define the list. Imagine func(x) and I wanted a list like [func(x * i), func(x * i**2)], for instan...
-1
2016-06-14T16:19:31Z
37,817,407
<p>Define the list inside the loop:</p> <pre><code>for i in whatever: l = [func(x * i), func(x * i**2)] </code></pre> <p>Given that you've tagged this NumPy, using a list at all may not be a good idea, but we can't really tell what you should be doing from the question as asked.</p>
0
2016-06-14T16:23:50Z
[ "python", "arrays", "function", "numpy" ]
Python: Making a list that includes functions but has as-yet undefined arguments
37,817,325
<p>Generally, what I would like to do is make a list that involves some function or functions, but the argument of that function will change based on an "i" of a for loop, and so the argument is not fully defined when I define the list. Imagine func(x) and I wanted a list like [func(x * i), func(x * i**2)], for instan...
-1
2016-06-14T16:19:31Z
37,818,345
<p>I suspect that for your 2d array there are better ways of defining the diagonal than iterating through the rows and calculating a function like this. But to focus on the issue of 'delaying' the evaluation of a function I'll try this:</p> <p>Define a simple function</p> <pre><code>In [438]: def func(x): .....: ...
1
2016-06-14T17:16:04Z
[ "python", "arrays", "function", "numpy" ]
Python, Internal Server Error-File does not exist
37,817,338
<p>I am trying to run a simple Python Script on <strong>Site5</strong> Hosting Service. I uploaded the script in the cgi-bin folder. Once I try loading the script on the browser it throws an Internal Server Error. I checked the Error Log in Cpanel and it says that the "File does not exist". I tried to resolve the Issue...
0
2016-06-14T16:20:00Z
37,821,233
<p>I have finally resolved it. There was an Issue with my code. The parenthesis had to be removed. My final code was something like this</p> <pre><code> #!/usr/bin/python print "Content-type: text/plain\r\n\r\n", print "Hello world" </code></pre> <p>And it worked just as expected.</p>
0
2016-06-14T20:11:56Z
[ "python", ".htaccess", "internal-server-error" ]
ValueError: time data '' does not match format '%d-%m-%Y %H:%M:%S'
37,817,443
<p>What I am trying to do is:</p> <blockquote> <ol> <li>Delete all rows where csv date is lower than 25.05.2016 23:59</li> <li>Save the file with a different name</li> </ol> </blockquote> <p>I have the following data in a csv in col <code>A</code></p> <pre><code>WFQVG98765 FI Quality-Value-Growth Some Random...
2
2016-06-14T16:26:09Z
37,817,781
<p><code>is_date()</code> is giving you <em>false positives</em>. Be more strict when you check the date format and consistent when you load a date string into <code>datetime</code> - follow one of the principles of <a href="https://www.python.org/dev/peps/pep-0020/" rel="nofollow"><code>Zen of Python</code></a> - "The...
2
2016-06-14T16:44:58Z
[ "python", "csv", "datetime" ]
ValueError: time data '' does not match format '%d-%m-%Y %H:%M:%S'
37,817,443
<p>What I am trying to do is:</p> <blockquote> <ol> <li>Delete all rows where csv date is lower than 25.05.2016 23:59</li> <li>Save the file with a different name</li> </ol> </blockquote> <p>I have the following data in a csv in col <code>A</code></p> <pre><code>WFQVG98765 FI Quality-Value-Growth Some Random...
2
2016-06-14T16:26:09Z
37,817,869
<p>The <code>datetime.datetime.strptime</code> exception indicates you are passing a blank string to the function in <code>row[0]</code>.</p> <p>Once you get that issue resolved, you need to add code to write acceptable rows to a new file.</p>
2
2016-06-14T16:48:54Z
[ "python", "csv", "datetime" ]
ValueError: time data '' does not match format '%d-%m-%Y %H:%M:%S'
37,817,443
<p>What I am trying to do is:</p> <blockquote> <ol> <li>Delete all rows where csv date is lower than 25.05.2016 23:59</li> <li>Save the file with a different name</li> </ol> </blockquote> <p>I have the following data in a csv in col <code>A</code></p> <pre><code>WFQVG98765 FI Quality-Value-Growth Some Random...
2
2016-06-14T16:26:09Z
37,817,905
<p>You can analyse each row to compare the dates, and save the rows you want to keep in a <code>list</code>. You can then store those rows into a new csv file and delete the old one if you don't need it anymore.</p> <p>Here's a snipped that does what you're asking for:</p> <pre><code>import csv from datetime import d...
2
2016-06-14T16:50:49Z
[ "python", "csv", "datetime" ]
ValueError: time data '' does not match format '%d-%m-%Y %H:%M:%S'
37,817,443
<p>What I am trying to do is:</p> <blockquote> <ol> <li>Delete all rows where csv date is lower than 25.05.2016 23:59</li> <li>Save the file with a different name</li> </ol> </blockquote> <p>I have the following data in a csv in col <code>A</code></p> <pre><code>WFQVG98765 FI Quality-Value-Growth Some Random...
2
2016-06-14T16:26:09Z
37,817,984
<p>You're doing the wrong comparison when you call <code>strip</code>. Two things:</p> <ul> <li>First of all, just use <code>row[0].strip()</code> (with no arguments). This will strip <em>all</em> whitespace (like newlines, etc), not just spaces.</li> <li>Secondly, <code>if is_date(row[0]) and not row[0].strip(' ')</c...
2
2016-06-14T16:54:32Z
[ "python", "csv", "datetime" ]
Automatically enabling different QPushbuttons according to QRadioButton options in PyQt
37,817,750
<p>I am very new to PyQt, so I am not even sure where to start searching for this.</p> <p>So I have two different options for QRadioButtons which ideally will correspond to two QPushButtons, one each. </p> <p>Basically, I have the following code, where i tried to achieve this by using if statements: </p> <pre><code>...
0
2016-06-14T16:43:20Z
37,818,894
<p>You're only running the <code>if</code> statement once, when the buttons are first created. In order for this to work, you need to evaluate those <code>if</code> statements <em>every</em> time the radio button check state is changed. <code>Qt</code> allows you to do this with <code>Signals</code> and <code>Slots</...
1
2016-06-14T17:50:21Z
[ "python", "pyqt", "pyqt4", "qpushbutton", "qradiobutton" ]
buffering subprocess output to a file: io.UnsupportedOperation: fileno
37,817,801
<p>I would like to buffer an output of <code>grep</code> to a buffer and then read it with <code>pandas</code> to avoid loading a huge original file into memory:</p> <pre><code>import subprocess import io import pandas as pd firstfile = "~/references/rs_hg19.snps.uniq.bed" outf = io.StringIO("") p0 = subprocess.Popen...
0
2016-06-14T16:46:02Z
37,818,592
<p>You can do what you want by getting subprocess to read the stdout for you into a byte string. Replace your second call with </p> <pre><code>p1 = subprocess.Popen(["head", "-n5" ], stdin=p0.stdout, stdout=subprocess.PIPE) data = p1.communicate()[0] string = data.decode('utf-8') </code></pre>
1
2016-06-14T17:32:45Z
[ "python", "io", "subprocess" ]
Python checking three lists appending to fourth
37,817,846
<p>I have 4 lists:</p> <p>"criticallist" `</p> <pre><code>[ade4c7059e17ab9e47d2aaec6cf04a9d, 882edee4cc71806190ca43993e8b2eb5, nekspzwjxhqroiu.com, htfbzqewll.org]` </code></pre> <p>"master" </p> <pre><code>[4d7d1c89529bcfcbbbbf9d6a2ba42cb5, 9f26da4de1653f609e7b4bcaade63daa] </code></pre> <p>and then each function...
-2
2016-06-14T16:47:58Z
37,818,090
<p>If I understand the question correctly, you want</p> <pre><code>for md5 in z: if md5 in y: print md5+" is in bromaster" pass </code></pre> <p>As it's written now, you're saying it "is in bromaster" after you check that <code>if md5 not in y</code>, where <code>y</code> is master.</p>
1
2016-06-14T17:00:48Z
[ "python" ]
Python checking three lists appending to fourth
37,817,846
<p>I have 4 lists:</p> <p>"criticallist" `</p> <pre><code>[ade4c7059e17ab9e47d2aaec6cf04a9d, 882edee4cc71806190ca43993e8b2eb5, nekspzwjxhqroiu.com, htfbzqewll.org]` </code></pre> <p>"master" </p> <pre><code>[4d7d1c89529bcfcbbbbf9d6a2ba42cb5, 9f26da4de1653f609e7b4bcaade63daa] </code></pre> <p>and then each function...
-2
2016-06-14T16:47:58Z
37,818,257
<p>I would suggest to clean up the code to not get lost in the many levels of info you want to compare with each other. One way is to not name the content from say criticallist into x (when retrieved as list) wait a second ...</p> <p>What about this:</p> <pre><code>#! /usr/bin/env python from __future__ import print_...
0
2016-06-14T17:11:05Z
[ "python" ]
Python checking three lists appending to fourth
37,817,846
<p>I have 4 lists:</p> <p>"criticallist" `</p> <pre><code>[ade4c7059e17ab9e47d2aaec6cf04a9d, 882edee4cc71806190ca43993e8b2eb5, nekspzwjxhqroiu.com, htfbzqewll.org]` </code></pre> <p>"master" </p> <pre><code>[4d7d1c89529bcfcbbbbf9d6a2ba42cb5, 9f26da4de1653f609e7b4bcaade63daa] </code></pre> <p>and then each function...
-2
2016-06-14T16:47:58Z
37,818,267
<p>So the code says when md5 NOT in y, so it hit this if but not the else which appends.</p> <p>Current code:</p> <pre><code> for md5 in z: if md5 not in y: print md5+" is in bromaster" pass elif md5 in x: print md5+" is in critical" ...
0
2016-06-14T17:11:39Z
[ "python" ]
Python checking three lists appending to fourth
37,817,846
<p>I have 4 lists:</p> <p>"criticallist" `</p> <pre><code>[ade4c7059e17ab9e47d2aaec6cf04a9d, 882edee4cc71806190ca43993e8b2eb5, nekspzwjxhqroiu.com, htfbzqewll.org]` </code></pre> <p>"master" </p> <pre><code>[4d7d1c89529bcfcbbbbf9d6a2ba42cb5, 9f26da4de1653f609e7b4bcaade63daa] </code></pre> <p>and then each function...
-2
2016-06-14T16:47:58Z
37,818,281
<p>Try this as refactor of your code. The code is using <code>"with"</code> as context when <code>list comprehension</code> is more pythonic. Added @nbryans answer.. </p> <p><a href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions" rel="nofollow">https://docs.python.org/3/tutorial/datastruc...
3
2016-06-14T17:12:24Z
[ "python" ]
Python checking three lists appending to fourth
37,817,846
<p>I have 4 lists:</p> <p>"criticallist" `</p> <pre><code>[ade4c7059e17ab9e47d2aaec6cf04a9d, 882edee4cc71806190ca43993e8b2eb5, nekspzwjxhqroiu.com, htfbzqewll.org]` </code></pre> <p>"master" </p> <pre><code>[4d7d1c89529bcfcbbbbf9d6a2ba42cb5, 9f26da4de1653f609e7b4bcaade63daa] </code></pre> <p>and then each function...
-2
2016-06-14T16:47:58Z
37,872,219
<p>Thanks @Merlin for you help its much appreciated and I'm reworking it with comprehension. I gave you points where Icould just for that!</p> <p>If you look at where I made my mistake I was checking the list y and then appending to it at the end within the loop so it was like an neverending loop -</p> <p>I replaced...
0
2016-06-17T02:33:47Z
[ "python" ]
MemoryError using Nginx, uWSGI, and web.py
37,817,857
<p>I've got a python Apple MDM server and I'm trying to convert it from being run from a command line process to being hosted using Nginx and uWSGI. I'm using web.py for routing. Everything is running smoothly for the most aprt. I've got what I believe to be a good basic configuration for both Nginx and uWSGI, but this...
1
2016-06-14T16:48:38Z
37,864,309
<p>You don't have <code>max-requests</code> set in your uWSGI .ini. Thus, your python interpreters live forever and might accumulate garbage. Try settings it to something, e.g. 5000 and, hopefully, leakage will stop.</p> <p>If you get more statistical results in future and they disprove <code>max-requests</code> versi...
1
2016-06-16T16:09:54Z
[ "python", "nginx", "uwsgi", "web.py", "mdm" ]
How to rename DynamoDB column/key
37,817,879
<p>in one of my DynamoDb Tables i have a column/key named "status", which turned out to be a reserved keyword. Unfortunately it isn't an option to delete the whole table and reinitiate it. How can i rename the key? </p> <p>Thank you.</p> <p>Here is the Lambda Code that causes the Exception:</p> <pre><code>try : ...
0
2016-06-14T16:49:39Z
37,817,996
<p>There is no real easy way to rename a column. You will have to create a new attribute for each of the entries and then delete all the values for the existing attribute.</p> <p>There is no reason to drop your attribute/column, if you are having trouble querying the table use <strong>Expression Attribute Names</stron...
1
2016-06-14T16:55:12Z
[ "python", "amazon-web-services", "amazon-dynamodb", "boto3" ]
Identify class attribute type and call its function
37,817,925
<p>I have defined a class <code>Field</code>. I have also defined <code>A</code> and <code>B</code>, which are child classes of <code>Field</code>.</p> <p>Now I have defined another class <code>Tool</code>. It can contain class variable which can either be of type class <code>Field</code>, or other class, or a <em>nor...
0
2016-06-14T16:51:58Z
37,818,006
<p>I think you're looking for the <code>isinstance</code> builtin:</p> <pre><code>if isinstance(attribute, Field): ... </code></pre> <p>or possibly:</p> <pre><code>if isinstance(getattr(self, attribute), Field): ... </code></pre> <p>since it looks like <code>attribute</code> may be the string name of the at...
1
2016-06-14T16:55:48Z
[ "python", "class", "oop" ]
Google TTS- Has anyone had any luck with it recently?
37,817,950
<p>I've been trying my hand at a "JARVIS" like system on my Raspberry Pi 2. I've tinkered around with eSpeak, Festival and pico but I've found pico to be the best out of these.</p> <p>However, pico is very boring to listen to and is completely monotonous. Some sites have posts from 2013-14, wherein users could use the...
0
2016-06-14T16:53:13Z
37,818,098
<p>You can install gtts package for python available. Then by using it you can save your text in a mp3 file then play it. A simple example where i have used gtts for saying hello world is</p> <pre><code>tts = gTTS(text=, lang="en") tts.save("hello.mp3") os.system("mpg321 hello.mp3") </code></pre>
0
2016-06-14T17:01:41Z
[ "python", "bash", "raspberry-pi", "text-to-speech" ]
setting up a new key value dictionary from a previous one
37,817,967
<p>Sorry for the large code dump. My problem is with my last for loop. I am attempting to set up a new dictionary, "candidates," that contains all of the possible combinations of one site with another site, mapped to the distance between them. For instance, say that site 1 has ID 1234, site 2 has ID 1235, and site 3 ha...
0
2016-06-14T16:54:01Z
37,822,196
<p>The simplest way to achive it is to prepare candidates during calculating distance. Just prepare dict of candidates instead of dict_key:</p> <pre><code>candidates = {} for i in np.arange(num_sites): lat1 = lat[i] lon1 = lon[i] site1=site[i] rat1 = lat1*np.pi/180.0 ron1 = lon1*np.pi/180.0 for j in np.arange(i+1,num_...
0
2016-06-14T21:13:02Z
[ "python", "dictionary", "key", "haversine" ]
Mailgun Attachment not attaching
37,818,024
<p>I'm having an issue where my attachments aren't sending with the emails (people just get an email with the designated message but no attachment). I'm not getting any runtime errors so it would seem this would be a server error. Any ideas?</p> <p>Code below:</p> <pre><code>return requests.post( sender_info['MAI...
0
2016-06-14T16:57:08Z
37,822,936
<p>your files part is malformed it should be a list with multiple tuples inside</p> <pre><code>files = [("attachment", ('attachement1',attachment,'text/pdf')), ("attachment, ('expense Transfer Form', open('Expense Transfer Form.pdf', 'rb'),'text/pdf'))] </code></pre> <p>where the tuple is of (form_fieldname, file_inf...
0
2016-06-14T22:08:43Z
[ "python", "mailgun" ]
How to calculate conditional probability of values in dataframe pandas-python?
37,818,063
<p>I want to calculate conditional probabilites of ratings('A','B','C') in ratings column. </p> <pre><code> company model rating type 0 ford mustang A coupe 1 chevy camaro B coupe 2 ford fiesta C sedan 3 ford focus A sedan 4 ford ...
1
2016-06-14T16:59:24Z
37,818,353
<p>You can use <code>groupby</code>:</p> <pre><code>In [2]: df = pd.DataFrame({'company': ['ford', 'chevy', 'ford', 'ford', 'ford', 'toyota'], 'model': ['mustang', 'camaro', 'fiesta', 'focus', 'taurus', 'camry'], 'rating': ['A', 'B', 'C', 'A', 'B', 'B'], '...
0
2016-06-14T17:16:48Z
[ "python", "pandas", "dataframe", "probability" ]
How to calculate conditional probability of values in dataframe pandas-python?
37,818,063
<p>I want to calculate conditional probabilites of ratings('A','B','C') in ratings column. </p> <pre><code> company model rating type 0 ford mustang A coupe 1 chevy camaro B coupe 2 ford fiesta C sedan 3 ford focus A sedan 4 ford ...
1
2016-06-14T16:59:24Z
37,818,394
<p>You can use <code>.groupby()</code> and the built-in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.div.html" rel="nofollow"><code>.div()</code></a>:</p> <pre><code>rating_probs = df.groupby('rating').size().div(len(df)) rating A 0.333333 B 0.500000 C 0.166667 </code></pre...
1
2016-06-14T17:19:39Z
[ "python", "pandas", "dataframe", "probability" ]
Django: cannot add foreight key to User
37,818,157
<p>I am using ldap to do authentication, just like <a href="http://stackoverflow.com/questions/19940466/understanding-django-ldap-authentication">Understanding Django-LDAP authentication</a>.</p> <p>My model is:</p> <pre><code>class MyFile(models.Model): file = models.FileField(upload_to="files") slug = model...
0
2016-06-14T17:05:26Z
37,818,194
<p>You need to provide a <em>default User ID for all the existing files</em>. It has to be an existing User ID and an <em>integer</em>. It cannot be a <code>datetime.date</code>.</p> <p>Or, if applicable, you can make the File->User link <em>optional</em>:</p> <pre><code>user = models.ForeignKey(User, blank=True, nul...
1
2016-06-14T17:07:13Z
[ "python", "django", "ldap", "django-migrations" ]
Boost.Python add bindings to existing PyObject (for exception handling)
37,818,167
<p>In order to expose a C++ exception to Python in a way that actually works, you have to write something like:</p> <pre><code>std::string scope = py::extract&lt;std::string&gt;(py::scope().attr("__name__")); std::string full_name = scope + "." + name; PyObject* exc_type = PyErr_NewException(&amp;full_name[0], PyExc_R...
10
2016-06-14T17:06:03Z
37,991,673
<p>The Python type created with <a href="http://www.boost.org/doc/libs/1_61_0/libs/python/doc/html/reference/high_level_components.html#high_level_components.boost_python_class_hpp.class_template_class_t_bases_hel" rel="nofollow"><code>class_</code></a> has an incompatible layout with Python <a href="https://docs.pytho...
4
2016-06-23T12:30:10Z
[ "python", "c++", "exception", "boost-python" ]
How do I run a file on localhost from an html page?
37,818,182
<p>I have an HTML file that reads the next event in my calendar using this Google Calendar API javascript . (<a href="https://developers.google.com/google-apps/calendar/quickstart/js" rel="nofollow">https://developers.google.com/google-apps/calendar/quickstart/js</a>). </p> <p>It works correctly as described in the ab...
0
2016-06-14T17:06:57Z
37,818,348
<p>If the code you are talking about runs on page load you could add<br> <code>setInterval(function(){ location.reload(); }, 6000);</code><br> to your javascript or<br> <code>&lt;meta http-equiv="refresh" content="60"&gt;</code><br> to your HTML either will refresh the page the page every 60 seconds automatically and t...
0
2016-06-14T17:16:13Z
[ "javascript", "python", "html", "localhost" ]
Linear search to find spelling errors in Python
37,818,193
<p>I'm working on learning Python with Program Arcade Games and I've gotten stuck on one of the labs. </p> <p>I'm supposed to compare each word of a text file (<a href="http://programarcadegames.com/python_examples/en/AliceInWonderLand200.txt" rel="nofollow">http://programarcadegames.com/python_examples/en/AliceInWon...
0
2016-06-14T17:07:12Z
37,818,280
<blockquote> <p>Linear search to find spelling errors in Python</p> </blockquote> <p>Something like this should do (pseudo code)</p> <pre><code>sampleDict = {} For each word in AliceInWonderLand200.txt: sampleDict[word] = True actualWords = {} For each word in dictionary.txt: actualWords[word] = True For ...
0
2016-06-14T17:12:20Z
[ "python", "dictionary" ]
Sympy returns a ConditionSet object when solving an equation, while matlab returns a single float when the same equation is solved
37,818,218
<p>I have 4 input variables (floats):</p> <p>Xmax Xmin percentage mode and I want to solve the following (rather long) equation for s:</p> <pre><code>&gt; (1/2+1/2*erf((log(Xmax)-(log(mode)+s**2))/(sqrt(2)*s))-(1/2+1/2*erf((log(Xmin)-(log(mode)+s**2))/(sqrt(2)*s))) - percentage == 0 </code></pre> <p>I want to use sy...
1
2016-06-14T17:08:32Z
37,818,885
<p>The fractions are using Python's integer division, which gives <code>1/2 == 0</code>. The entire expression reduces to <code>-0.95</code>. Declare it using <code>1./2</code> or <code>0.5</code>, or maybe Rational(1,2). You might also have to express the percentage 0.95 as <code>Rational(19,20)</code>.</p>
1
2016-06-14T17:49:34Z
[ "python", "matlab", "sympy" ]
How do I make my monster move?
37,818,305
<p>It says this</p> <pre><code>Traceback (most recent call last): File "dungeon2.py", line 93, in &lt;module&gt; move_monster(monster, steps) NameError: name 'steps' is not defined </code></pre> <p>When the game starts, the monster stays in it's position but I'm not sure why.</p> <pre><code>import random BOARD = [(...
1
2016-06-14T17:13:24Z
37,818,367
<p>There's no point in passing <code>steps</code> to <code>move_monster</code>, as you overwrite it in the third line, and never use the original value. Just drop it from the function's definition:</p> <pre><code>def move_monster(monster): # here ---------------^ x, y = monster moves = ['LEFT', 'RIGHT', 'UP', 'D...
2
2016-06-14T17:17:37Z
[ "python", "nameerror" ]
How do I make my monster move?
37,818,305
<p>It says this</p> <pre><code>Traceback (most recent call last): File "dungeon2.py", line 93, in &lt;module&gt; move_monster(monster, steps) NameError: name 'steps' is not defined </code></pre> <p>When the game starts, the monster stays in it's position but I'm not sure why.</p> <pre><code>import random BOARD = [(...
1
2016-06-14T17:13:24Z
37,818,480
<pre><code>&gt;&gt;&gt; monster = (2,3) &gt;&gt;&gt; x,y=monster &gt;&gt;&gt; x+=1 &gt;&gt;&gt; x, y (3, 3) &gt;&gt;&gt; monster (2, 3) </code></pre> <p>As you can see here, assigning the monster's position to new variables and changing the new variables does not change the original monster's position. After changing ...
3
2016-06-14T17:25:49Z
[ "python", "nameerror" ]
Strange HTML doctype error when trying to run Python script from bash
37,818,409
<p>I have a bash script which is supposed to call a Python script stored on GitHub and run it with arguments:</p> <pre><code>#!/bin/bash +x wget https://github.place.otherplace.com/myrepo/repo_folder/blob/Python/pythonScript.py chmod +x pythonScript.py python pythonScript.py </code></pre> <p>I'm getting the followin...
0
2016-06-14T17:20:44Z
37,818,493
<p>You're not downloading the script. You're downloading a GitHub web page with the script and a whole bunch of other stuff on it, like GitHub navigation and a search bar and clickable line numbers.</p> <p>Go to that page in your web browser, and you should see a "Raw" link. Click on that, and the resulting page is wh...
2
2016-06-14T17:26:35Z
[ "python", "html", "bash", "wget" ]
How use `unaccent` with full text search in django 1.10?
37,818,492
<p>We are working on a project and we are using <code>Django 1.10a1</code>, we're using django full text search with PostgreSQL but we need to use unaccent.</p> <p>So, I have this code:</p> <pre><code> search = 'Car' query_set = Article.objects.annotate( search=SearchVector( ...
1
2016-06-14T17:26:33Z
38,713,813
<p>Install the <em>unaccent</em> extension into your database:</p> <pre><code>mydb=# CREATE EXTENSION unaccent; </code></pre> <p>Create a new search configuration, based on an other one:</p> <pre><code>mydb=# CREATE TEXT SEARCH CONFIGURATION french_unaccent( COPY = french ); </code></pre> <p>Insert the <em>unaccent...
2
2016-08-02T07:05:59Z
[ "python", "django", "postgresql" ]
Custom event listeners for wxpython widgets
37,818,526
<p>as in the title, is it possible to add a custom event listener for wx widget and if so, how? More particularly I am trying to add one which listens to the changes of SelStart and SelEnd attributes of wx.Slider. Thanks!</p>
0
2016-06-14T17:28:53Z
37,833,571
<h1>Below is the code for custom listener for wx.slider, I am calling it inside other listener's handler.</h1> <blockquote> <p>You can call this customize listener from the point where SelStart and SelEnd changing.</p> </blockquote> <pre><code>import wx import wx.lib.newevent DialogRespondEvent, EVT_DIALOG_RESPOND...
2
2016-06-15T11:02:32Z
[ "python", "python-2.7", "wxpython" ]