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
Can't View Complete Page Source in Selenium
39,047,079
<p>When I view the source HTML after manually navigating to the site via Chrome I can see the full page source but on loading the page source via selenium I'm not getting the complete page source.</p> <pre><code>from bs4 import BeautifulSoup from selenium import webdriver import sys,time driver = webdriver.Chrome(e...
0
2016-08-19T20:19:09Z
39,047,407
<p>The website is possibly blocking or restricting the user agent for selenium. An easy test is to change the user agent and see if that does it. More info at this question: </p> <p><a href="http://stackoverflow.com/questions/29916054/change-user-agent-for-selenium-driver">Change user agent for selenium driver</a></p>...
0
2016-08-19T20:45:03Z
[ "python", "selenium", "selenium-webdriver", "bs4" ]
Python IDLE not executing "for loop" print statements
39,047,127
<p>Can someone tell me why the simple "words" for loop shown below, and others like it (all of them copied from Python.org), didn't print in IDLE when I ran the print statements? When the print statement below and the others tested were run in the Python 2.7.12 shell, the function merely skipped to the next blank inden...
0
2016-08-19T20:23:29Z
39,047,156
<p>Fix your indentation like so:</p> <pre><code>words = ['cat','window','defenstrate'] for w in words: print(w, len(w)) </code></pre>
0
2016-08-19T20:26:05Z
[ "python" ]
Python IDLE not executing "for loop" print statements
39,047,127
<p>Can someone tell me why the simple "words" for loop shown below, and others like it (all of them copied from Python.org), didn't print in IDLE when I ran the print statements? When the print statement below and the others tested were run in the Python 2.7.12 shell, the function merely skipped to the next blank inden...
0
2016-08-19T20:23:29Z
39,047,162
<p>Indentation! 4 spaces in the next line after the for loop!</p> <pre><code>words = ['cat', 'window', 'defenestrate'] &gt;&gt;&gt; for w in words: ... print w ... cat window defenestrate &gt;&gt;&gt; </code></pre>
2
2016-08-19T20:26:36Z
[ "python" ]
Python IDLE not executing "for loop" print statements
39,047,127
<p>Can someone tell me why the simple "words" for loop shown below, and others like it (all of them copied from Python.org), didn't print in IDLE when I ran the print statements? When the print statement below and the others tested were run in the Python 2.7.12 shell, the function merely skipped to the next blank inden...
0
2016-08-19T20:23:29Z
39,047,176
<p>You need a tab after any for loop.</p> <pre><code>words = ['cat', 'window', 'defenestrate'] for w in words: print w, len(w) </code></pre> <p>Your code works fine.</p>
0
2016-08-19T20:28:03Z
[ "python" ]
certificate verify failed (_ssl.c:645)>” for one particuar domain
39,047,406
<p>Every request to this one particular domain now ends in an certificate verify failed (_ssl.c:645)></p> <p>I am not sure what caused this.I've been searching for an answer since last night trying to figure out how to fix it, but somehow I cant get it running.</p> <p>I tried pip uninstall -y certifi &amp;&amp; pip i...
0
2016-08-19T20:44:56Z
39,047,528
<p>I would investigate further by checking if openssl can verify the certificate:</p> <pre><code>openssl s_client -showcerts -connect www.getyourguide.de:443 </code></pre>
-1
2016-08-19T20:55:06Z
[ "python", "python-3.x", "ssl", "web-crawler", "python-requests" ]
How to refresh data in PyQt TableWidget?
39,047,408
<p>For example, I have a SQLite database and I grab data from this database and put it into <code>QTableWidget</code>. But then, I make some stuff with this data.</p> <p>So, how can I update data in this table without <code>setItem</code> method?</p>
0
2016-08-19T20:45:08Z
39,055,713
<p>Use a <a href="http://doc.qt.io/qt-5/qtableview.html" rel="nofollow"><code>QTableView</code></a> instead, where you can dynamically change the data in the underlying model (e.g. a <a href="http://doc.qt.io/qt-5/qstandarditemmodel.html" rel="nofollow"><code>QStandardItemModel</code></a>). In your case, you might even...
0
2016-08-20T15:20:50Z
[ "python", "sqlite", "pyqt" ]
Python: Use single login for multiple request
39,047,458
<p>There is some random website, <a href="http://www.example.com" rel="nofollow">http://www.example.com</a>. This website use HTTP basic authentication.</p> <p>I would like to make multiple requests to this site. But I don't want to login for each of the requests.</p> <p>I have written the following code:</p> <pre><...
1
2016-08-19T20:50:10Z
39,047,864
<p>You may want to try <code>requests</code> library and use it <a href="http://docs.python-requests.org/en/master/user/advanced/" rel="nofollow">Session object</a></p> <pre><code>s = requests.Session() s.auth = (username, password) s.get(homeURL) </code></pre> <p>The cookie will be set to your session cookie <code>s...
0
2016-08-19T21:23:45Z
[ "python", "session", "cookies", "urllib2", "urllib" ]
Replacing different characters in Python
39,047,474
<p>Suppose you have a string which you want to parse into a specific format. That means: replace <strong>all</strong> <code>' ', '.', '-', etc with '_'</code>.</p> <p>I know that I could do this:</p> <pre><code>&gt;s = "Hello----..... World" &gt;s = s.replace('-','_').replace('.', '_').replace(' ', '_') &gt;print ...
0
2016-08-19T20:51:31Z
39,047,518
<p>Use <a href="https://docs.python.org/2/library/re.html" rel="nofollow"><code>re</code></a></p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; print re.sub(' |\.|-', '_',"Hello----..... World") Hello_____________World </code></pre> <p>Bonus solution <em>not</em> using regex:</p> <pre><code>&gt;&gt;&gt; keys = [...
2
2016-08-19T20:54:26Z
[ "python", "string", "replace" ]
Replacing different characters in Python
39,047,474
<p>Suppose you have a string which you want to parse into a specific format. That means: replace <strong>all</strong> <code>' ', '.', '-', etc with '_'</code>.</p> <p>I know that I could do this:</p> <pre><code>&gt;s = "Hello----..... World" &gt;s = s.replace('-','_').replace('.', '_').replace(' ', '_') &gt;print ...
0
2016-08-19T20:51:31Z
39,047,530
<p>Use <a href="https://docs.python.org/2/library/re.html" rel="nofollow">Regular Expressions</a>.</p> <p>Ex:</p> <pre><code>import re s = "Hello----..... World" print(re.sub(r"[ .-]", "_", s)) </code></pre> <p>Here is the <a href="https://docs.python.org/2/howto/regex.html" rel="nofollow">Python tutorial</a>.</...
2
2016-08-19T20:55:17Z
[ "python", "string", "replace" ]
Replacing different characters in Python
39,047,474
<p>Suppose you have a string which you want to parse into a specific format. That means: replace <strong>all</strong> <code>' ', '.', '-', etc with '_'</code>.</p> <p>I know that I could do this:</p> <pre><code>&gt;s = "Hello----..... World" &gt;s = s.replace('-','_').replace('.', '_').replace(' ', '_') &gt;print ...
0
2016-08-19T20:51:31Z
39,047,688
<p><a href="http://stackoverflow.com/a/27086669">This answer</a> lays out a variety of different ways to accomplish this task, contrasting different functions and inputs by speed. </p> <p>If you are replacing few characters, the fastest way is the way in your question, by chaining multiple replaces, with regular expre...
0
2016-08-19T21:07:26Z
[ "python", "string", "replace" ]
Replacing different characters in Python
39,047,474
<p>Suppose you have a string which you want to parse into a specific format. That means: replace <strong>all</strong> <code>' ', '.', '-', etc with '_'</code>.</p> <p>I know that I could do this:</p> <pre><code>&gt;s = "Hello----..... World" &gt;s = s.replace('-','_').replace('.', '_').replace(' ', '_') &gt;print ...
0
2016-08-19T20:51:31Z
39,055,899
<p>You can do it using <a href="https://docs.python.org/2/library/string.html#string.translate" rel="nofollow"><em>str.translate</em></a> and <a href="https://docs.python.org/2/library/string.html#string.maketrans" rel="nofollow">string.maketrans</a> which will be the most efficient approach not chaining calls etc..:</...
1
2016-08-20T15:38:47Z
[ "python", "string", "replace" ]
Append elements of an arbitrarily nested list in a depth first search-esque manner, without recursion
39,047,478
<p>The list can be deeper, or shallower, but say I have a list of depth 2 as follows:</p> <pre><code>a = [['a','b'],['c','d'],['e','f']] </code></pre> <p>I want to write a function, <code>f(a)</code>, such that it would return the following new list:</p> <pre><code>['acef', 'adef', 'bcef', 'bdef'] </code></pre> <p>...
-1
2016-08-19T20:51:48Z
39,047,671
<p>You can use <a href="https://docs.python.org/3/library/itertools.html#itertools.product" rel="nofollow">itertools.product</a>:</p> <pre><code>import itertools def f(elems): *branches, leaves = elems for path in itertools.product(*branches): yield ''.join(itertools.chain(path, leaves)) a = [['a','b...
1
2016-08-19T21:05:50Z
[ "python", "depth-first-search" ]
Open a text file with python as a form and know when it closes
39,047,571
<p>I want to make a python script that opens a text file that the user can update before continuing (for configurations) and then continue the script once the text editor closes. Is there something in python that will allow me to do this?</p>
1
2016-08-19T20:58:22Z
39,047,661
<p>on windows using notepad:</p> <pre><code>import os cf = "config.txt" # or full path if you like if not os.path.exists(cf): f = open(cf,"w"); f.close() # create to avoid notepad message os.system("notepad "+cf) # call waits until user closes the file # now the file has been edited by the user </code></pre>
1
2016-08-19T21:04:41Z
[ "python", "file" ]
MySQL db returns Decimal('number') values, how to convert datatype in python?
39,047,576
<p>Title says it all really. Making a call to a MySQL db and get a datatype that is not playing so well when I try and jsonify it. It's driving me crazy trying to convert this datatype to something useable for the front end. </p> <p>I've tried calling float, int, etc, etc. Either the Decimal type persists or I get an ...
0
2016-08-19T20:58:48Z
39,047,848
<p>The problem may be caused by accentuated characters in the <em>country_area</em> field.</p> <p>If you get bytes strings from your SQL result, you must decoded it using the encoding of your table.</p> <p>By default, MySQL use the latin1_swedish_ci => ISO-8859-1 charset.</p> <p>So, you need to decode like this:</p>...
-1
2016-08-19T21:22:06Z
[ "python", "mysql" ]
How to retrieve data from the Github API in a python script?
39,047,695
<p>I'm fairly new to any sort of web programming and need help with gathering data from the Github search API. How to I go get the array at <a href="https://api.github.com/search/users?q=tom+repos:%3E42+followers:%3E1000" rel="nofollow">https://api.github.com/search/users?q=tom+repos:%3E42+followers:%3E1000</a> from in...
1
2016-08-19T21:07:57Z
39,047,960
<p>Why roll your own? Use a prebuilt module: </p> <pre><code>https://github.com/PyGithub/PyGithub </code></pre> <p>List of Python api's from <a href="https://developer.github.com/libraries/" rel="nofollow">https://developer.github.com/libraries/</a></p> <pre><code>PyGithub Pygithub3 libsaas github3.py sanction agit...
2
2016-08-19T21:32:32Z
[ "python", "web", "github" ]
The matching columns from a data frame based on value in a column from other data Frame
39,047,720
<p>I have two data frames The first one is df1 has 485513 columns and 100 rows,</p> <pre><code>head(df1) sample cg1 cg2 cg3 cg4 cg5 cg6 cg7 cg8 cg9 cg10 cg11 AAD_1 33435 33436 33437 33438 33439 33440 33441 33442 33443 33444 33445 AAD_2 0.33 1.33 2.33 3.33 4.33 5.33 6.33 ...
2
2016-08-19T21:10:02Z
39,047,806
<p>Assuming <code>df2</code> is a Series:</p> <pre><code>&gt;&gt;&gt; df[df2.tolist()] cg1 cg2 cg3 cg4 cg5 0 33435.00 33436.00 33437.00 33438.00 33439.00 1 0.33 1.33 2.33 3.33 4.33 2 0.56 1.56 2.56 3.56 4.56 3 45.90 46.90 ...
2
2016-08-19T21:17:42Z
[ "python", "pandas" ]
The matching columns from a data frame based on value in a column from other data Frame
39,047,720
<p>I have two data frames The first one is df1 has 485513 columns and 100 rows,</p> <pre><code>head(df1) sample cg1 cg2 cg3 cg4 cg5 cg6 cg7 cg8 cg9 cg10 cg11 AAD_1 33435 33436 33437 33438 33439 33440 33441 33442 33443 33444 33445 AAD_2 0.33 1.33 2.33 3.33 4.33 5.33 6.33 ...
2
2016-08-19T21:10:02Z
39,050,510
<p>In <code>R</code>, we can just do</p> <pre><code>df[as.character(df2$ID)] </code></pre> <p>assuming that 'ID' column is <code>factor</code>. In case it is <code>character</code> class, it is more easier</p> <pre><code>df[df2$ID] </code></pre> <p>But if there are elements in 'ID' that are not in the column names...
1
2016-08-20T04:35:51Z
[ "python", "pandas" ]
Tkinter Entry returns float values regardless of input
39,047,766
<p>I have some pretty simple code right now that I am having issues with.</p> <pre><code>root = Tk() label1 = Label(root, text ="Enter String:") userInputString = Entry(root) label1.pack() userInputString.pack() submit = Button(root,text = "Submit", command = root.destroy) submit.pack(side =BOTTOM) root.mainloop() pri...
-1
2016-08-19T21:14:26Z
39,048,759
<p>There are two things wrong with your print statement. First, you print the widget, not the text in the widget. print(widget) prints str(widget), which is the tk pathname of the widget. The '.' represents the root window. The integer that follows is a number that tkinter assigned as the name of the widget. In cu...
1
2016-08-19T23:01:23Z
[ "python", "python-3.x", "tkinter" ]
Why the default argument behaved globally immutable?
39,047,785
<p>The <code>default arguments</code> in Python are intuitively the variables locally scoped but globally mutable. </p> <p>Below, why had the second call to <code>my_sum</code> the result <code>20</code> although I expected it <code>30</code> ?</p> <pre><code>def my_append(el, ar = []): ar.append(el) return ar pr...
0
2016-08-19T21:16:04Z
39,047,879
<p>To help clarify this, consider this one-line change:</p> <pre><code>def my_append(el, ar=[]): ar = ar + [el] # ar.append(el) return ar print my_append(10) # =&gt; [10] print my_append(20) # =&gt; [20] </code></pre> <p>So the issue is not to do with mutability or immutability, but the fact that the second ver...
3
2016-08-19T21:24:42Z
[ "python" ]
Python - Return list of dictionaries with unique Key:Value pair
39,047,790
<p>I have a long list of dictionaries that for the most part do not overlap. However, some of the dictionaries have the same 'Name' field and I'd only like unique names in the list of dictionaries. I'd like the first occurrence of the name to be the one that stays and any thereafter be deleted from the list.</p> <p>I'...
1
2016-08-19T21:16:24Z
39,047,919
<p>You could run over the list and keep a <code>set</code> of unique names. Every time you encounter a new name (i.e., a name that isn't in the set), you add it to the set and the respective dict to the result:</p> <pre><code>def uniqueNames(dicts): names = set() result = [] for d in dicts: if not ...
2
2016-08-19T21:27:58Z
[ "python", "list", "python-3.x", "dictionary", "unique" ]
Python - Return list of dictionaries with unique Key:Value pair
39,047,790
<p>I have a long list of dictionaries that for the most part do not overlap. However, some of the dictionaries have the same 'Name' field and I'd only like unique names in the list of dictionaries. I'd like the first occurrence of the name to be the one that stays and any thereafter be deleted from the list.</p> <p>I'...
1
2016-08-19T21:16:24Z
39,047,931
<p>Initial list:</p> <pre><code>my_list = [ {'Name':'John', 'Age':'50', 'Height':'70'}, {'Name':'Kathy', 'Age':'43', 'Height':'65'}, {'Name':'John','Age':'46','Height':'68'}, {'Name':'John','Age':'50','Height':'72'} ] </code></pre> <p>The logical (potentially newbie-friendlier) way:</p> <pre><code>na...
0
2016-08-19T21:29:36Z
[ "python", "list", "python-3.x", "dictionary", "unique" ]
Python - Return list of dictionaries with unique Key:Value pair
39,047,790
<p>I have a long list of dictionaries that for the most part do not overlap. However, some of the dictionaries have the same 'Name' field and I'd only like unique names in the list of dictionaries. I'd like the first occurrence of the name to be the one that stays and any thereafter be deleted from the list.</p> <p>I'...
1
2016-08-19T21:16:24Z
39,047,934
<p>You can easily write a for-loop for this.</p> <pre><code> def getName(name): '''Gets first occurence of name in list of dicts.''' for i in myList: if i['Name'] == name: return i </code></pre>
1
2016-08-19T21:29:55Z
[ "python", "list", "python-3.x", "dictionary", "unique" ]
Using function of sqlalchemy.sql multiple times in query
39,047,840
<p>I am using sqlalchemy version 0.7.8. I have come across an issue where my user can search a text in plain english but record in db can have special characters between text. So if user enters "<strong>please come early to the hospital</strong>" and in db i have "<strong>please, come early, to the hospital.</strong>" ...
1
2016-08-19T21:21:25Z
39,048,013
<p>Use a query with <a href="http://dev.mysql.com/doc/refman/5.7/en/regexp.html" rel="nofollow">RegEx</a></p> <p>There are examples in the <a href="http://docs.sqlalchemy.org/en/latest/orm/query.html#the-query-object" rel="nofollow">SqlAlchemy documentation</a>.</p> <p>See also this <a href="http://stackoverflow.com/...
0
2016-08-19T21:37:23Z
[ "python", "mysql", "python-2.7", "sqlalchemy" ]
Using function of sqlalchemy.sql multiple times in query
39,047,840
<p>I am using sqlalchemy version 0.7.8. I have come across an issue where my user can search a text in plain english but record in db can have special characters between text. So if user enters "<strong>please come early to the hospital</strong>" and in db i have "<strong>please, come early, to the hospital.</strong>" ...
1
2016-08-19T21:21:25Z
39,051,641
<p>You can use this to remove all spacial character in python</p> <pre><code>&gt;&gt;&gt; impore re &gt;&gt;&gt; string = "please, come early# to the@ hospital" &gt;&gt;&gt; cleanString = re.sub('\W+',' ', string ) &gt;&gt;&gt; print cleanString please come early to the hospital </code></pre> <p>store your text as a ...
0
2016-08-20T07:27:43Z
[ "python", "mysql", "python-2.7", "sqlalchemy" ]
Using function of sqlalchemy.sql multiple times in query
39,047,840
<p>I am using sqlalchemy version 0.7.8. I have come across an issue where my user can search a text in plain english but record in db can have special characters between text. So if user enters "<strong>please come early to the hospital</strong>" and in db i have "<strong>please, come early, to the hospital.</strong>" ...
1
2016-08-19T21:21:25Z
39,053,346
<p>Thanks to all replies. I am able to improve it through this way.</p> <pre><code>IGNORE_CHARS = [',', '.', '!', '&amp;', ';', ':', '@'] needle = build_replace_func(IGNORE_CHARS, Message.text) record = Message.query.filter(needle == query_term.strip()).one() def build_replace_func(chars, attr, replace_with=''): ...
1
2016-08-20T10:58:43Z
[ "python", "mysql", "python-2.7", "sqlalchemy" ]
Floating point numbers precision in python
39,047,856
<p>I have a variable <code>mn</code> whose value is 2.71989011072, I use round function of python to get a precision value of 2.720 but I get 2.72 only</p> <pre><code>mn=2.71989011072 print round(mn,3) </code></pre> <p>Gives 2.72 and not 2.720</p>
0
2016-08-19T21:22:44Z
39,047,914
<p>Yes, the <em>print</em> function apply a second rounding.</p> <pre><code>mn = 2.71989011072 mn = round(mn, 3) print(mn) </code></pre> <p>You'll get:</p> <pre><code>2.72 </code></pre> <p>You need to use a formatted string:</p> <pre><code>print("{0:.3f}".format(mn)) </code></pre> <p>You'll get:</p> <pre><code>2...
3
2016-08-19T21:27:29Z
[ "python", "floating-point", "rounding" ]
Floating point numbers precision in python
39,047,856
<p>I have a variable <code>mn</code> whose value is 2.71989011072, I use round function of python to get a precision value of 2.720 but I get 2.72 only</p> <pre><code>mn=2.71989011072 print round(mn,3) </code></pre> <p>Gives 2.72 and not 2.720</p>
0
2016-08-19T21:22:44Z
39,047,918
<p>Function rounds it to three first digits which correctly results in 2.72. The zeros are matter of printing ans string formatting, not rounding.</p> <p>To print it with three zeros you will need to do the following:</p> <pre><code>print '{0:.3f}'.format(round(mn, 3)) </code></pre> <p>That will round number first a...
1
2016-08-19T21:27:51Z
[ "python", "floating-point", "rounding" ]
Floating point numbers precision in python
39,047,856
<p>I have a variable <code>mn</code> whose value is 2.71989011072, I use round function of python to get a precision value of 2.720 but I get 2.72 only</p> <pre><code>mn=2.71989011072 print round(mn,3) </code></pre> <p>Gives 2.72 and not 2.720</p>
0
2016-08-19T21:22:44Z
39,047,937
<p>You desire a particular string representation of the number, not another number.</p> <p>Use <code>format()</code> instead of <code>round()</code>:</p> <pre><code>&gt;&gt;&gt; mn = 2.71989011072 &gt;&gt;&gt; format(mn, '.3f') '2.720' </code></pre>
0
2016-08-19T21:30:06Z
[ "python", "floating-point", "rounding" ]
contour plot with non linear x scale
39,047,896
<p>I am working on two plots: a contour plot on the top and an x-y plot on the bottom <a href="http://i.stack.imgur.com/WoNcp.png" rel="nofollow"><img src="http://i.stack.imgur.com/WoNcp.png" alt="contour plot"></a></p> <p>The contour plot is done via the following line</p> <pre><code>plt.imshow(df, extent = [xmin, x...
0
2016-08-19T21:26:06Z
39,048,978
<p>You can use <code>scipy.interpolate.interp2d</code> to interpolate the image on a regular grid. Here is an example:</p> <pre><code>import numpy as np import pylab as pl x = np.linspace(0, 1, 100) x2 = x ** 2 y = np.linspace(0, 1, 200) X, Y = np.meshgrid(x, y) X2, Y2 = np.meshgrid(x2, y) Z = np.sin(10 * (X**2 + Y*...
1
2016-08-19T23:30:59Z
[ "python", "matplotlib" ]
Understanding python dict memory allocation
39,048,112
<pre><code>def func(bar): my_dict = { 'query1': 'select * from table1', 'query2': 'select * from table2' } my_dict[bar] func('query1') </code></pre> <p>My question is does my_dict executes both query and save it or it only executes query according to bar variable</p>
0
2016-08-19T21:46:54Z
39,048,151
<p>That will create the dictionary with two elements in memory, find the value associated with key <code>bar</code> and destroy the whole thing when the function is competed. </p>
0
2016-08-19T21:50:14Z
[ "python" ]
Understanding python dict memory allocation
39,048,112
<pre><code>def func(bar): my_dict = { 'query1': 'select * from table1', 'query2': 'select * from table2' } my_dict[bar] func('query1') </code></pre> <p>My question is does my_dict executes both query and save it or it only executes query according to bar variable</p>
0
2016-08-19T21:46:54Z
39,048,191
<p>In this specific case, no query are executed at all. It is only <code>str</code> objects which means that they actually don't do anything.</p> <p>Let's try to detail 2 other cases. Assuming you have a function <code>execute_query</code> that execute a query given as parameter:</p> <pre><code>def func(query): m...
1
2016-08-19T21:54:43Z
[ "python" ]
Django ImportError: no module named 'shop'
39,048,114
<p>I tried searching for answers to this problem but, at least with my eyeballs, I did not find the same problem anywhere else.</p> <p>I started doing a django project from the book "Django by example'. I've been using a virtual environment. Following the book, I downloaded Django 1.8.6. </p> <p>I added the app 'shop...
0
2016-08-19T21:46:58Z
39,062,351
<p>Solution: I created the app in the wrong folder. Come to think of it, I think I used this command:</p> <pre><code>django-admin startproject myshop . </code></pre> <p>With the dot in the end, as some tutorials recommend. So that messed up the structure so it became incompatible with the book's instructions.</p> <p...
0
2016-08-21T08:32:18Z
[ "python", "django" ]
Custom usage message for a single argument in argparse
39,048,139
<p>I have a parameter that can be specified by the user with either one or two arguments:</p> <pre><code>parser.add_argument("-s", "--start", required=True, metavar='START_TIME', nargs='+', help="The start time either in milliseconds or as MM/DD/YYYY HH:MM:SS.") </code></pre> <p>The help message shows this: </p> ...
0
2016-08-19T21:49:44Z
39,048,175
<p>I suggest removing <code>nargs</code> from your call to <code>add_argument</code>. <code>nargs='+'</code> indicates there may be more than one input for that argument, but in actuality you always want one argument. A string of <code>MM/DD/YYYY HH:MM:SS</code> is one argument conceptually and may be passed in with qu...
2
2016-08-19T21:52:26Z
[ "python", "argparse" ]
Custom usage message for a single argument in argparse
39,048,139
<p>I have a parameter that can be specified by the user with either one or two arguments:</p> <pre><code>parser.add_argument("-s", "--start", required=True, metavar='START_TIME', nargs='+', help="The start time either in milliseconds or as MM/DD/YYYY HH:MM:SS.") </code></pre> <p>The help message shows this: </p> ...
0
2016-08-19T21:49:44Z
39,048,215
<p>If you want to have zero, one or two arguments and not more, you can have two options <code>-s1</code> and <code>-s2</code>.</p> <p>It can be more obvious or clearer for the user to understand the usage of your application. </p>
-1
2016-08-19T21:58:07Z
[ "python", "argparse" ]
Custom usage message for a single argument in argparse
39,048,139
<p>I have a parameter that can be specified by the user with either one or two arguments:</p> <pre><code>parser.add_argument("-s", "--start", required=True, metavar='START_TIME', nargs='+', help="The start time either in milliseconds or as MM/DD/YYYY HH:MM:SS.") </code></pre> <p>The help message shows this: </p> ...
0
2016-08-19T21:49:44Z
39,048,513
<p>The default display for a <code>'+'</code> nargs is this <code>S [S ...]</code>. It's supposed to convey the idea that you have to give at least one value, but can have more. (look at what <code>*</code> produces).</p> <pre><code>In [306]: parser=argparse.ArgumentParser() In [307]: a1=parser.add_argument('-s',nar...
1
2016-08-19T22:29:20Z
[ "python", "argparse" ]
Groupby of splitted data (pandas)
39,048,181
<p>Imagine you have a large CSV file with several million rows that you process by chunks. <strong>The file is too large to be loaded in memory</strong>. What would be the best way to do groupby and apply a relatively "complex" function (like fillna), without letting the chunk size affect the results? I exemplify: </p...
1
2016-08-19T21:53:23Z
39,048,271
<p>You need to set up a way to remember the last fill value. I use the dictionary <code>memory</code> below</p> <pre><code>memory = {} def fill(df): name = df.name df = df.copy() # fill from memory if name in memory.keys(): df.iloc[0, :] = df.iloc[0, :].fillna(memory[name]) # normal ffi...
2
2016-08-19T22:03:46Z
[ "python", "pandas" ]
Groupby of splitted data (pandas)
39,048,181
<p>Imagine you have a large CSV file with several million rows that you process by chunks. <strong>The file is too large to be loaded in memory</strong>. What would be the best way to do groupby and apply a relatively "complex" function (like fillna), without letting the chunk size affect the results? I exemplify: </p...
1
2016-08-19T21:53:23Z
39,050,151
<p>I guess you want to read in chunk-by-chunk and then write to disk after processing. I think @piRSquared's idea of "keeping memory of previously seen values" should work if the function you want to apply is ffill, though I'm sure @Jeff is right about Dask (which I'm not familiar).</p> <p>I have made up a slightly lo...
0
2016-08-20T03:23:24Z
[ "python", "pandas" ]
Python - s.recv hang timeout
39,048,225
<p>I have a script that I am currently writing to connect to a host via port 25. Once connected the following code is used to read a text file to gather each user and then issue the VRFY command along with the username. This works really well until I receive no response back from the host, it just hangs there. Towards ...
0
2016-08-19T21:58:44Z
39,048,557
<p>Yes thank you, settimeout worked a treat! I used a excempt to catch it too. Thanks everyone! </p>
0
2016-08-19T22:34:01Z
[ "python" ]
Spark Equivalent of IF Then ELSE
39,048,229
<p>I have seen this question earlier here and I have took learnings from that. However I am not sure why I am getting an error when I feel it should work. </p> <p>I want to create a new column in existing Spark Dataframe by some rules. Here is what I wrote. iris_spark is the data frame with a categorical variable iris...
-1
2016-08-19T21:59:06Z
39,048,475
<p>Correct structure is either:</p> <pre><code>(when(col("iris_class") == 'Iris-setosa', 0) .when(col("iris_class") == 'Iris-versicolor', 1) .otherwise(2)) </code></pre> <p>which is equivalent to</p> <pre><code>CASE WHEN (iris_class = 'Iris-setosa') THEN 0 WHEN (iris_class = 'Iris-versicolor') THEN ...
1
2016-08-19T22:26:00Z
[ "python", "apache-spark" ]
'numpy.float64' object is not iterable - meanshift clustering
39,048,355
<p>python newbie here. I am trying to run this code but I get the error message that the object is not iterable. Would appreciate some advice on what I am doing wrong. Thanks.</p> <pre><code>import matplotlib.pyplot as plt import numpy as np import pandas as pd temp = pd.read_csv("file.csv", encoding='latin-1') xy...
1
2016-08-19T22:11:46Z
39,048,432
<pre><code>new_centroid = np.average(in_bandwidth, axis=0) </code></pre> <p>Is assigning a scalar to <code>new_centroid</code> then you are trying to <code>tuple(scalar)</code> which is throwing the error.</p> <pre><code>tuple(2.) </code></pre> <blockquote> <pre><code>------------------------------------------------...
2
2016-08-19T22:20:35Z
[ "python", "pandas", "numpy", "cluster-analysis", "mean-shift" ]
Scikit-learn: error in fitting model - Input contains NaN, infinity or a value too large for float64
39,048,363
<p>My question appears to be the same as previous posts (<a href="https://stackoverflow.com/questions/36532497/standardscaler-valueerror-input-contains-nan-infinity-or-a-value-too-large-fo">post-1</a>, <a href="https://stackoverflow.com/questions/34779961/scikit-learn-error-in-fitting-model-input-contains-nan-infinity-...
0
2016-08-19T22:12:50Z
39,049,100
<p>You have <code>NaN</code> values in your <code>raw.dat</code> file. Drop that column or replace it with 0s.</p>
0
2016-08-19T23:46:53Z
[ "python", "numpy", "machine-learning", "scikit-learn" ]
Print large data to file with special format from Python
39,048,390
<p>I need to print some data to a txt file from Python 3.4/3.2.</p> <p>Each line in the file has this format:</p> <pre><code> col1 | col2 | col3 | id1 CT_TYPE value1 CT_TYPE value2 AR CT1 239 CT2 9.66 AR CT3 8.65 NY CT...
0
2016-08-19T22:16:31Z
39,048,514
<p>If I understand the problem correctly, I would use something where it only stores the id and cttype until it finds a match on id, then output to file and del from memory. The below is to illust</p> <pre><code>fobj_in = open('file','r') fobj_out = open('output','a') unmatched = {} for line in fobj_in: elem = lin...
0
2016-08-19T22:29:22Z
[ "python", "python-3.x", "pydev" ]
Python requests Library SSL error: [Errno 2] No such file or directory
39,048,446
<p>first ever question: I'm getting the following result:</p> <blockquote> <p>File "D:\Anaconda\Lib\site-packages\requests\api.py", line 70, in get return request('get', url, params=params, **kwargs)</p> <p>File "D:\Anaconda\Lib\site-packages\requests\api.py", line 56, in request return session.request(met...
0
2016-08-19T22:21:36Z
39,050,680
<blockquote> <pre><code>res = requests.get(loginpageURL, verify='false', ... </code></pre> </blockquote> <p>Verify takes either a boolean (i.e. True or False) or a path which is then used as path for the trust store. Your specification <code>'false'</code> is a string and not a boolean and it will therefore try to use...
0
2016-08-20T05:08:21Z
[ "python", "ssl", "python-requests" ]
Display HTML form data as JSON on new page using Flask
39,048,448
<p>I have made a simple HTML form on a page and I would like to gather all the data from the form, convert it to JSON, then display that JSON on a new page. I don't need or want a database to save this data, I just want it to spit out onto a new page in proper JSON format so that the person using it can copy/paste that...
0
2016-08-19T22:21:59Z
39,049,037
<p>I see you import jsonify... you could use that...</p> <pre><code>@app.route('/display', methods=["GET", "POST"]) def display(): return jsonify(request.form) </code></pre> <p>or you could use the tojson filter in your template</p> <p><code>{{ result | tojson }}</code></p> <p>or </p> <p><code>result = json.d...
0
2016-08-19T23:38:03Z
[ "python", "html", "json", "flask" ]
replace multiple characters in string with value from dictionary python
39,048,559
<p>I'm trying to create a function that iterates through a string, finds characters that match to keys in a dictionary and replaces that character with the value in the dictionary for that key. However it currently only replaces first occurrence of a letter that is in the dictionary and stops there, where am I going wr...
0
2016-08-19T22:34:02Z
39,048,589
<p>Your return statement is within the if statement, so if a character matches, your function replaces that single character and then returns.</p> <p>If you want all of your characters replaced, let it iterate through all characters of the string by moving your return statement outside of the for loop.</p> <pre><code...
2
2016-08-19T22:37:21Z
[ "python", "dictionary" ]
replace multiple characters in string with value from dictionary python
39,048,559
<p>I'm trying to create a function that iterates through a string, finds characters that match to keys in a dictionary and replaces that character with the value in the dictionary for that key. However it currently only replaces first occurrence of a letter that is in the dictionary and stops there, where am I going wr...
0
2016-08-19T22:34:02Z
39,048,625
<p>You are prematurely ending your code with the call to <code>return</code> within the for loop. You can fix it by storing your new string outside of the loop, only returning once the loop is done:</p> <pre><code>def cypher(string): a = string # a new string to store the replaced string for i in string: ...
1
2016-08-19T22:42:52Z
[ "python", "dictionary" ]
replace multiple characters in string with value from dictionary python
39,048,559
<p>I'm trying to create a function that iterates through a string, finds characters that match to keys in a dictionary and replaces that character with the value in the dictionary for that key. However it currently only replaces first occurrence of a letter that is in the dictionary and stops there, where am I going wr...
0
2016-08-19T22:34:02Z
39,048,656
<p>As zachyee pointed out, your <code>return</code> statement is inside the loop.</p> <p>You may want to take a look at <a href="https://docs.python.org/3.4/library/stdtypes.html#str.translate" rel="nofollow"><code>str.translate</code></a>, which does exactly what you want:</p> <pre><code>def cypher(string): retu...
0
2016-08-19T22:46:33Z
[ "python", "dictionary" ]
replace multiple characters in string with value from dictionary python
39,048,559
<p>I'm trying to create a function that iterates through a string, finds characters that match to keys in a dictionary and replaces that character with the value in the dictionary for that key. However it currently only replaces first occurrence of a letter that is in the dictionary and stops there, where am I going wr...
0
2016-08-19T22:34:02Z
39,048,718
<p>One liner -> <code>print ''.join(d[c] if c in d else c for c in s)</code></p> <p><strong>Sample Output:</strong></p> <pre><code>&gt;&gt;&gt; s = 'Hello World' &gt;&gt;&gt; d = { 'I':'1', 'R':'2', 'E':'3', 'A':'4', 'S':'5', 'G':'6', 'T':'7', 'B':'8', 'O':'0', 'l':'1', 'z':'2', 'e':'3', 'a':'4', 's':'5', 'b':'6', '...
1
2016-08-19T22:54:44Z
[ "python", "dictionary" ]
Why does it take forever to run my python code even for a small input?
39,048,562
<p>I am new to programming, and I am also new to this website. So sorry if my code is stupid, and I'm wasting your time. I have been trying to solve a Project Euler <a href="https://projecteuler.net/problem=12" rel="nofollow">Problem 12</a>. With a little help of internet I've come up with an algorithm and wrote a code...
0
2016-08-19T22:34:24Z
39,048,920
<p>This is likely an infinite loop. If it enters the loop and s &lt;= L, it will repeat indefinitely because of the last line (perhaps a typo).</p> <pre><code>while total_divisors &lt;= L: s = number_of_divisors(n+1) total_divisors *= s total_divisors = s </code></pre> <p>Here is an answer that mirrors yo...
1
2016-08-19T23:24:10Z
[ "python" ]
How do I change x and y axes in matplotlib?
39,048,603
<p>I am using matplotlib to draw neuralnet. I found a code that draws neural net, but it is oriented from top to bottom. I would like to change the orientation from left to right. So basically I would like to change x and y axes after I already plotted all the shapes. Is there an easy way to do this? I also found an an...
-1
2016-08-19T22:40:06Z
39,064,179
<p>What you have in your code is an example of how to launch an histogram in matplotlib. Notice you are using the pyplot default interface (and not necessarily building your own figure).</p> <p>As so this line:</p> <pre><code>orientation=u'vertical', </code></pre> <p>should be:</p> <pre><code>orientation=u'horizont...
0
2016-08-21T12:26:22Z
[ "python", "matplotlib" ]
Need to find the intersection point of two line segments iterated over multiple segments
39,048,648
<p>OK, here is the problem. I am trying to calculate the intersection of two lines by comparing multiple line segments that are read out of a series of csv files. I've already got the x,y coordinate pairs for each line segment into a list of tuples within tuples as follows:</p> <pre><code>continuousLine = [((x1,y1),(x...
2
2016-08-19T22:45:28Z
39,049,367
<p>Suppose the function <code>line_intersection</code> would return False on <code>div == 0</code> instead of raising exeption.</p> <p><strong>The easy way:</strong></p> <pre><code>filter(None, [intersection(a, b) for a in continuousLine for b in crossingLines]) </code></pre> <p>However, using nested loop, it is slo...
0
2016-08-20T00:31:31Z
[ "python", "line-intersection" ]
Need to find the intersection point of two line segments iterated over multiple segments
39,048,648
<p>OK, here is the problem. I am trying to calculate the intersection of two lines by comparing multiple line segments that are read out of a series of csv files. I've already got the x,y coordinate pairs for each line segment into a list of tuples within tuples as follows:</p> <pre><code>continuousLine = [((x1,y1),(x...
2
2016-08-19T22:45:28Z
39,049,383
<p>Since you haven't provided any sample input and expected output, I'm going to use the dummy version of the <code>line_intersection()</code> function shown below. All it does is print its input and returns a hardcoded result — but it will show you how to iterate through the input data and pass it to the real functi...
0
2016-08-20T00:35:24Z
[ "python", "line-intersection" ]
Learn Python the Hard Way (Exercise 20) has weird symbols when run
39,048,749
<p>Here's the code. </p> <pre><code>from sys import argv script, input_file = argv def print_all(f): print f.read() def rewind(f): print f.seek(0) def print_a_line(line_count, f): print line_count, f.readline() current_file = open(input_file) print "First, we'll print the whole file.\n" print_all...
-1
2016-08-19T23:00:37Z
39,048,806
<p>You created your input file using a word processor. Use a text editor (Notepad in Windows, I don't know what you'd have in OS X) to create your input file.</p>
0
2016-08-19T23:07:08Z
[ "python" ]
Learn Python the Hard Way (Exercise 20) has weird symbols when run
39,048,749
<p>Here's the code. </p> <pre><code>from sys import argv script, input_file = argv def print_all(f): print f.read() def rewind(f): print f.seek(0) def print_a_line(line_count, f): print line_count, f.readline() current_file = open(input_file) print "First, we'll print the whole file.\n" print_all...
-1
2016-08-19T23:00:37Z
39,048,881
<p>You edited your file in TextEdit - python is spitting out the bytes that reflect the RTF formatting of the file. Before saving from TextEdit, choose Format >> Make Text File</p>
1
2016-08-19T23:17:43Z
[ "python" ]
How can I convert a pyspark.sql.dataframe.DataFrame back to a sql table in databricks notebook
39,048,777
<p>I created a dataframe of type <code>pyspark.sql.dataframe.DataFrame</code> by executing the following line: <code>dataframe = sqlContext.sql("select * from my_data_table")</code></p> <p>How can I convert this back to a sparksql table that I can run sql queries on?</p>
5
2016-08-19T23:03:53Z
39,048,907
<p>You can create your table by using <a href="http://spark.apache.org/docs/latest/api/python/pyspark.sql.html?highlight=sql#pyspark.sql.DataFrame.createOrReplaceTempView" rel="nofollow">createReplaceTempView</a>. In your case it would be like:</p> <pre><code>dataframe.createOrReplaceTempView("mytable") </code></pre> ...
1
2016-08-19T23:21:54Z
[ "python", "sql", "apache-spark", "pyspark", "databricks" ]
Tor Browser with RSelenium in Linux/Windows
39,048,810
<p>Looking to use RSelenium and Tor using my Linux machine to return the Tor IP (w/Firefox as Tor Browser). This is doable with Python, but having trouble with it in R. Can anybody get this to work? Perhaps you can share your solution in either Windows / Linux.</p> <pre><code># library(devtools) # devtools::install_gi...
2
2016-08-19T23:08:22Z
39,048,970
<p>Something like the following should work:</p> <pre><code>browserP &lt;- paste0(Sys.getenv('HOME'),"/Desktop/tor-browser_en-US/Browser/firefox") jArg &lt;- paste0("-Dwebdriver.firefox.bin='", browserP, "'") selServ &lt;- RSelenium::startServer(javaargs = jArg) </code></pre> <p>UPDATE:</p> <p>This worked for me on ...
3
2016-08-19T23:30:20Z
[ "python", "selenium", "tor", "rselenium" ]
Python 3 IndentationError
39,048,844
<p>In spite of seeing a lot of posts about the python indentation error and trying out a lot of solutions, I still get this error:</p> <pre><code>import random import copy import sys the_board = [" "]*10 def printboard(board): print(board[7] + " " + "|" + board[8] + " " + "|" + board[9]) print("--------") ...
-4
2016-08-19T23:12:42Z
39,048,872
<p>Try unindenting the previous seven lines of code by one level (the code in that <code>while</code> loop). This should make the indents work correctly. Also, it seems that there is an extra space before the <code>if</code> statement that is causing you errors. Remove this space as well. This would make that part of t...
0
2016-08-19T23:16:27Z
[ "python", "python-3.x", "indentation" ]
Python 3 IndentationError
39,048,844
<p>In spite of seeing a lot of posts about the python indentation error and trying out a lot of solutions, I still get this error:</p> <pre><code>import random import copy import sys the_board = [" "]*10 def printboard(board): print(board[7] + " " + "|" + board[8] + " " + "|" + board[9]) print("--------") ...
-4
2016-08-19T23:12:42Z
39,048,875
<p>You need to indent the block under <code>while (True):</code> consistently. E.g.:</p> <pre><code>while True: number = player_move(the_board) if (valid_move(the_board,number) == True) and not(board_full == False): make_move(the_board,number,pla) break else: print("Invalid Move, tr...
0
2016-08-19T23:16:45Z
[ "python", "python-3.x", "indentation" ]
Python 3 IndentationError
39,048,844
<p>In spite of seeing a lot of posts about the python indentation error and trying out a lot of solutions, I still get this error:</p> <pre><code>import random import copy import sys the_board = [" "]*10 def printboard(board): print(board[7] + " " + "|" + board[8] + " " + "|" + board[9]) print("--------") ...
-4
2016-08-19T23:12:42Z
39,048,885
<p>The problem is, the if statement is one indentation back from the rest of the code. You want to align all the code and the error should go away.</p> <pre><code>while True: number = player_move(the_board) if (valid_move(the_board,number) == True) and not(board_full == False): make_move(the_board,n...
0
2016-08-19T23:18:31Z
[ "python", "python-3.x", "indentation" ]
Combine value of two column pandas into one
39,048,864
<p>I have data, and have to use pandas for processing, this is example the code:</p> <pre><code>d = [ (1,70399,0.988375133622), (1,33919,0.981573492596), (1,62461,0.981426807114), (579,1,0.983018778374), (745,1,0.995580488899), (834,1,0.980942505189) ] df = pd.DataFrame(d, columns=['source', 'target', 'we...
1
2016-08-19T23:15:13Z
39,048,981
<pre><code>df[['source', 'target']].T.stack() source 0 1 1 1 2 1 3 579 4 745 5 834 target 0 70399 1 33919 2 62461 3 1 4 1 5 1 dtype: int64 </code></pre> <hr> <p><strong>...
3
2016-08-19T23:31:23Z
[ "python", "pandas" ]
Combine value of two column pandas into one
39,048,864
<p>I have data, and have to use pandas for processing, this is example the code:</p> <pre><code>d = [ (1,70399,0.988375133622), (1,33919,0.981573492596), (1,62461,0.981426807114), (579,1,0.983018778374), (745,1,0.995580488899), (834,1,0.980942505189) ] df = pd.DataFrame(d, columns=['source', 'target', 'we...
1
2016-08-19T23:15:13Z
39,049,003
<p>Try this <code>source_old = df.source.append(df.target)</code></p>
2
2016-08-19T23:33:57Z
[ "python", "pandas" ]
Combine value of two column pandas into one
39,048,864
<p>I have data, and have to use pandas for processing, this is example the code:</p> <pre><code>d = [ (1,70399,0.988375133622), (1,33919,0.981573492596), (1,62461,0.981426807114), (579,1,0.983018778374), (745,1,0.995580488899), (834,1,0.980942505189) ] df = pd.DataFrame(d, columns=['source', 'target', 'we...
1
2016-08-19T23:15:13Z
39,049,326
<p>Try this: </p> <pre><code>pd.melt(df[['source', 'target']])['value'][:-3].sort_values() 0 1 1 1 2 1 3 579 4 745 5 834 7 33919 8 62461 6 70399 </code></pre> <p>Melt gives you this:</p> <pre><code>pd.melt(df[['source', 'target']]) variable value 0 source 1 1...
1
2016-08-20T00:24:30Z
[ "python", "pandas" ]
Missing X and Y axis when plotting using python
39,048,865
<p>I having some issue replicating the example code for scatter plots in python. The code I am trying to replicate: </p> <pre><code>x = np.random.rand(10) y = np.random.rand(10) z = np.sqrt(x**2 + y**2) plt.subplot(321) plt.scatter(x, y, s=80, c=z, marker="&gt;") plt.subplot(322) plt.scatter(x, y, s=80, c=z, marker=...
0
2016-08-19T23:15:15Z
39,049,059
<p>It seems that you are using ggplot style. You can change the default style:</p> <pre><code>pl.style.use("ggplot") pl.rcParams['axes.edgecolor'] = "#777777" pl.rcParams['axes.facecolor'] = '#FFFFFF' </code></pre> <p>Here is the result:</p> <p><a href="http://i.stack.imgur.com/okW0B.png" rel="nofollow"><img src="ht...
1
2016-08-19T23:42:05Z
[ "python", "matplotlib" ]
Missing X and Y axis when plotting using python
39,048,865
<p>I having some issue replicating the example code for scatter plots in python. The code I am trying to replicate: </p> <pre><code>x = np.random.rand(10) y = np.random.rand(10) z = np.sqrt(x**2 + y**2) plt.subplot(321) plt.scatter(x, y, s=80, c=z, marker="&gt;") plt.subplot(322) plt.scatter(x, y, s=80, c=z, marker=...
0
2016-08-19T23:15:15Z
39,051,183
<p>Thanks to @HYRY's solution. </p> <p>Some more references about style sheets in matplotlib for beginners like me:</p> <ol> <li><p><a href="http://matplotlib.org/users/style_sheets.html" rel="nofollow">Customizing plots with style sheets</a></p> <ul> <li>Defining your own style</li> <li>Composing styles</li> <li>Te...
0
2016-08-20T06:29:23Z
[ "python", "matplotlib" ]
Selenium Error (Django): http.client.BadStatusLine: ''
39,048,912
<p>When I try to run my functional tests, I get: <code>selenium http.client.BadStatusLine: ''</code> (full error below). The tests start to run, the first one returns an error, than it gets hung up and I have to manually interrupt. (The first error is an expected error, so don't worry about that.)</p> <p>This was work...
0
2016-08-19T23:22:37Z
39,055,262
<p>I still don't know what happened, but this morning it's working again. I didn't change any code or anything.</p> <p>Weird Selenium.</p>
0
2016-08-20T14:34:30Z
[ "python", "django", "selenium", "firefox", "pythonanywhere" ]
Failure to return variable after series of functions in Python
39,048,921
<p>I am trying to return a variable ('brand') which is manipulated through a series of functions. If I go through the first function (brandSelector) which find an intersection between the variable and array the variable is returned. However, if the secondary sub route is chosen in the event that the first fails then th...
0
2016-08-19T23:24:18Z
39,049,112
<p>With thanks to Barmar (<a href="http://stackoverflow.com/users/1491895/barmar">http://stackoverflow.com/users/1491895/barmar</a>),</p> <p>I followed his solution of:</p> <p>"brandDetectionFailure doesn't have a return statement. And your except block in brandSelector doesn't have a return statement. So nothing get...
0
2016-08-19T23:48:28Z
[ "python", "function", "variables", "return-value" ]
Basic PyCharm questions
39,048,934
<p>I have a seemingly simple task to do. Run this ( print('Hello World') ) line of code in PyCharm. No, I'm serious. I wont bother complaining about what I've tried or how much I've coded in the past (spoiler alert, a lot) because I just want to get it running. The online tutorial wants me to do some kind of projec...
0
2016-08-19T23:26:05Z
39,049,021
<p>I did this:</p> <p>Create folder wherever you want your file to be</p> <p>Open this folder in pycharm as your project (if you have a project open, close it and open this folder as your new project)</p> <p>Open <code>Project</code> tab on the left</p> <p>Right click your folder -> New -> Python File -> Create <co...
0
2016-08-19T23:35:53Z
[ "python", "pycharm" ]
Basic PyCharm questions
39,048,934
<p>I have a seemingly simple task to do. Run this ( print('Hello World') ) line of code in PyCharm. No, I'm serious. I wont bother complaining about what I've tried or how much I've coded in the past (spoiler alert, a lot) because I just want to get it running. The online tutorial wants me to do some kind of projec...
0
2016-08-19T23:26:05Z
39,049,040
<p>Well it's really simple, if you used any code editor in the past you probably will understand what i'm doing here:</p> <p>File >> New >> Python File >> "name of the file" >> Create.</p> <p>To run the code simply click the play icon which is run 'project'. Then the output should appear in a console.</p>
1
2016-08-19T23:38:45Z
[ "python", "pycharm" ]
Tensorflow: How to write op with gradient in python?
39,048,984
<p>I would like to write a TensorFlow op in python, but I would like it to be differentiable (to be able to compute a gradient).</p> <p>This question asks how to write an op in python, and the answer suggests using py_func (which has no gradient): <a href="http://stackoverflow.com/questions/37924071/tensorflow-writing...
1
2016-08-19T23:31:33Z
39,049,106
<p>Here's an example of adding gradient to a specific <code>py_func</code> <a href="https://gist.github.com/harpone/3453185b41d8d985356cbe5e57d67342" rel="nofollow">https://gist.github.com/harpone/3453185b41d8d985356cbe5e57d67342</a></p> <p>Here's the issue <a href="https://github.com/tensorflow/tensorflow/issues/1095...
0
2016-08-19T23:47:26Z
[ "python", "neural-network", "tensorflow" ]
Tensorflow: How to write op with gradient in python?
39,048,984
<p>I would like to write a TensorFlow op in python, but I would like it to be differentiable (to be able to compute a gradient).</p> <p>This question asks how to write an op in python, and the answer suggests using py_func (which has no gradient): <a href="http://stackoverflow.com/questions/37924071/tensorflow-writing...
1
2016-08-19T23:31:33Z
39,984,513
<p>Yes, as mentionned in @Yaroslav's answer, it is possible and the key is the links he references: <a href="https://github.com/tensorflow/tensorflow/issues/1095" rel="nofollow">here</a> and <a href="https://gist.github.com/harpone/3453185b41d8d985356cbe5e57d67342" rel="nofollow">here</a>. I want to elaborate on this a...
1
2016-10-11T18:46:32Z
[ "python", "neural-network", "tensorflow" ]
python :: iterate through nested JSON results
39,048,994
<p>iterating through <code>JSON</code> <code>results</code> can get quite confusing at times. say I have a <code>function</code>like so:</p> <pre><code>def get_playlist_owner_ids(query): results = sp.search(q=query, type='playlist') id_ = results['playlists']['items'][0]['owner']['id'] return (id_) </cod...
3
2016-08-19T23:32:31Z
39,049,019
<pre><code>results['playlists']['items'][0]['owner']['id'] ^___ this is a list index </code></pre> <p>Thus:</p> <pre><code>for item in results['playlists']['items']: print(item['owner']['id']) </code></pre> <p>It is often convenient to make intermediate variables in order to keep th...
1
2016-08-19T23:35:46Z
[ "python", "json", "loops", "iteration" ]
python :: iterate through nested JSON results
39,048,994
<p>iterating through <code>JSON</code> <code>results</code> can get quite confusing at times. say I have a <code>function</code>like so:</p> <pre><code>def get_playlist_owner_ids(query): results = sp.search(q=query, type='playlist') id_ = results['playlists']['items'][0]['owner']['id'] return (id_) </cod...
3
2016-08-19T23:32:31Z
39,049,025
<p>How about this? You can use generator to achieve your goal</p> <pre><code>def get_playlist_owner_ids(query): results = sp.search(q=query, type='playlist') for item in results['playlists']['items']: yield item['owner']['id'] </code></pre>
0
2016-08-19T23:36:16Z
[ "python", "json", "loops", "iteration" ]
python :: iterate through nested JSON results
39,048,994
<p>iterating through <code>JSON</code> <code>results</code> can get quite confusing at times. say I have a <code>function</code>like so:</p> <pre><code>def get_playlist_owner_ids(query): results = sp.search(q=query, type='playlist') id_ = results['playlists']['items'][0]['owner']['id'] return (id_) </cod...
3
2016-08-19T23:32:31Z
39,049,026
<p>You could iterate over <code>results['playlists']['items']</code>, or, better yet, use list comprehension:</p> <pre><code>def get_playlist_owner_ids(query): results = sp.search(q=query, type='playlist') return [x['owner']['id'] for x in results['playlists']['items']] </code></pre>
0
2016-08-19T23:36:19Z
[ "python", "json", "loops", "iteration" ]
python :: iterate through nested JSON results
39,048,994
<p>iterating through <code>JSON</code> <code>results</code> can get quite confusing at times. say I have a <code>function</code>like so:</p> <pre><code>def get_playlist_owner_ids(query): results = sp.search(q=query, type='playlist') id_ = results['playlists']['items'][0]['owner']['id'] return (id_) </cod...
3
2016-08-19T23:32:31Z
39,049,039
<p>In practice your document is something like this:</p> <pre><code>{ "playlists": { "items":[ {"owner":{"id":"1"},...}, {"owner":{"id":"2"},...}, {"owner":{"id":"3"},...}, ..., } </code></pre> <p>So you have to loop over the list of items. </p> <p>You can do some...
0
2016-08-19T23:38:35Z
[ "python", "json", "loops", "iteration" ]
What is the logic behind needing to convert a 1D array to 2D to concatenate?
39,049,028
<p>In order to concatenate a 1D array to a 2D array, the following fix is suggested:</p> <pre><code>A = np.array([1, 2, 3]) B = np.array([[4, 5],[6,7],[8,9]]) # np.hstack((A,B)) # throws "ValueError: all the input arrays must have same number of dimensions" np.hstack((A[:, None],B)) #works </code></pre> <p>Could s...
1
2016-08-19T23:37:00Z
39,049,108
<p>The document of <code>hstack()</code>:</p> <blockquote> <p>numpy.hstack(tup)[source] Stack arrays in sequence horizontally (column wise).</p> <p>Take a sequence of arrays and stack them horizontally to make a single array. Rebuild arrays divided by hsplit.</p> <p>Parameters: tup : sequence of nda...
1
2016-08-19T23:47:33Z
[ "python", "arrays", "numpy", "concatenation" ]
What is the logic behind needing to convert a 1D array to 2D to concatenate?
39,049,028
<p>In order to concatenate a 1D array to a 2D array, the following fix is suggested:</p> <pre><code>A = np.array([1, 2, 3]) B = np.array([[4, 5],[6,7],[8,9]]) # np.hstack((A,B)) # throws "ValueError: all the input arrays must have same number of dimensions" np.hstack((A[:, None],B)) #works </code></pre> <p>Could s...
1
2016-08-19T23:37:00Z
39,049,325
<p>Look at these arrays:</p> <pre><code>In [26]: A Out[26]: array([1, 2, 3]) In [27]: B Out[27]: array([[4, 5], [6, 7], [8, 9]]) In [28]: A[:,None] Out[28]: array([[1], [2], [3]]) In [31]: np.concatenate([A[:,None],B],axis=1) Out[31]: array([[1, 4, 5], [2, 6, 7], [3, 8, 9]...
1
2016-08-20T00:24:29Z
[ "python", "arrays", "numpy", "concatenation" ]
What is the logic behind needing to convert a 1D array to 2D to concatenate?
39,049,028
<p>In order to concatenate a 1D array to a 2D array, the following fix is suggested:</p> <pre><code>A = np.array([1, 2, 3]) B = np.array([[4, 5],[6,7],[8,9]]) # np.hstack((A,B)) # throws "ValueError: all the input arrays must have same number of dimensions" np.hstack((A[:, None],B)) #works </code></pre> <p>Could s...
1
2016-08-19T23:37:00Z
39,050,328
<p>I think the reason for this difference between numpy and MATLAB is a difference in philosophy and design.</p> <p>The numpy package is designed with a focus more towards integrating with the python programming language and dealing with standard types of variables that are found in the python programming language. M...
0
2016-08-20T03:56:50Z
[ "python", "arrays", "numpy", "concatenation" ]
GtkInfoBar doesn't show again after hide
39,049,060
<p>I'm hide Gtk widget, then try to show it, but none of the methods "show()", "show_all()" or "show_now()" does't work. If not call "hide()" widget shows.</p> <pre><code>python 3.5.2 gtk3 3.20.8 pygobject-devel 3.20.1 </code></pre> <p>test.py:</p> <pre><code>import gi gi.require_version('Gtk', '3.0') from gi.reposi...
2
2016-08-19T23:42:17Z
39,050,142
<p><a href="https://bugzilla.gnome.org/show_bug.cgi?id=710888" rel="nofollow">This is a long-standing bug in GTK+ specific to GtkInfoBar. Monitor the linked bug report for more details, some workarounds (including one in Python that you can use for the time being) and to find out when it's fixed for real.</a></p>
3
2016-08-20T03:21:40Z
[ "python", "gtk", "glade", "pygobject" ]
python: update dataframe to existing excel sheet without overwriting contents on the same sheet and other sheets
39,049,148
<p>Struggling for this for hours so I decided to ask for help from experts here:</p> <p>I want to modify existing excel sheet without overwriting content. I have other sheets in this excel file and I don't want to impact other sheets.</p> <p>I've created sample code, not sure how to add the second sheet that I want t...
0
2016-08-19T23:53:01Z
39,077,347
<p>I'd suggest you update to the 2.4 (either the beta or a checkout) of openpyxl and use the built in support fro dataframes. These can now easily be converted by openypxl into rows that you do what you want with.</p> <p>See <a href="http://openpyxl.readthedocs.io/en/latest/pandas.html" rel="nofollow">http://openpyxl....
0
2016-08-22T10:37:03Z
[ "python", "pandas", "openpyxl", "xlrd" ]
python: update dataframe to existing excel sheet without overwriting contents on the same sheet and other sheets
39,049,148
<p>Struggling for this for hours so I decided to ask for help from experts here:</p> <p>I want to modify existing excel sheet without overwriting content. I have other sheets in this excel file and I don't want to impact other sheets.</p> <p>I've created sample code, not sure how to add the second sheet that I want t...
0
2016-08-19T23:53:01Z
39,086,153
<p>Figured it out by myself:</p> <pre><code>#Prepare the excel we want to write to t=pd.date_range('2004-01-31', freq='M', periods=4) first=pd.DataFrame({'A':[1,1,1,1], 'B':[2,2,2,2]}, index=t) first.index=first.index.strftime('%Y-%m-%d') writer=pd.ExcelWriter('test.xlsx') first.to_excel(writer, sheet_nam...
1
2016-08-22T18:14:43Z
[ "python", "pandas", "openpyxl", "xlrd" ]
Iterating and averaging pandas data frame
39,049,202
<p>I have a database with a lot of rows such as:</p> <pre><code>timestamp name price profit bob 5 4 jim 3 2 jim 2 6 bob 6 7 jim 4 1 jim 6 3 bob 3 1 </code></pre> <p>The data ...
2
2016-08-20T00:03:11Z
39,049,640
<p>By looking at the result you want, I'm guess you want average of the two prices following the current one instead of "2 values in the price column before the current value".</p> <p>I made up <code>timestamp</code> values that you omitted to be clear.</p> <pre><code>print df timestamp name price profit 0 2016-...
1
2016-08-20T01:28:53Z
[ "python", "pandas" ]
Iterating and averaging pandas data frame
39,049,202
<p>I have a database with a lot of rows such as:</p> <pre><code>timestamp name price profit bob 5 4 jim 3 2 jim 2 6 bob 6 7 jim 4 1 jim 6 3 bob 3 1 </code></pre> <p>The data ...
2
2016-08-20T00:03:11Z
39,051,703
<pre><code>def shift_n_roll(df): return df.shift(-1).rolling(2).mean().shift(-1) df['new column'] = df.groupby('name').price.apply(shift_n_roll) df </code></pre> <p><a href="http://i.stack.imgur.com/0OBuy.png" rel="nofollow"><img src="http://i.stack.imgur.com/0OBuy.png" alt="enter image description here"></a></p...
2
2016-08-20T07:37:03Z
[ "python", "pandas" ]
Change dataframe pandas based one series
39,049,204
<p>I have data and have convert using dataframe pandas :</p> <pre><code>import pandas as pd d = [ (1,70399,0.988375133622), (1,33919,0.981573492596), (1,62461,0.981426807114), (579,1,0.983018778374), (745,1,0.995580488899), (834,1,0.980942505189) ] df_new = pd.DataFrame(e, columns=['source_target']).sort_v...
1
2016-08-20T00:03:41Z
39,049,563
<p>If the order doesn't matter, you can do the following. Avoid <code>for</code> loop unless it's absolutely necessary.</p> <pre><code>uniq_vals = np.unique(df_beda[['source','target']]) map_dict = dict(zip(uniq_vals, xrange(len(uniq_vals)))) df_beda[['source','target']] = df_beda[['source','target']].replace(map_dict...
2
2016-08-20T01:12:46Z
[ "python", "pandas" ]
Why does xml.etree.ElementTree.parse converts namespace elements in lowercase
39,049,210
<p>I want to instruct ET.parse to leave the namespace case in XML as it is</p> <pre><code>import xml.etree.ElementTree as ET tree = ET.parse("mimeTypes.rdf") ET.dump(tree) &lt;rdf:RDF xmlns:ns1="http://home.netscape.com/NC-rdf#" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"&gt; &lt;rdf:Description ns1:valu...
0
2016-08-20T00:04:54Z
39,092,673
<p>Apparently I had to register the namespaces used in the XML:</p> <pre><code> import xml.etree.ElementTree as ET tree = ET.parse("mimeTypes.rdf") et.register_namespace('NC', 'http://home.netscape.com/NC-rdf#') et.register_namespace('RDF', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#') tree.write("tmp.xml", xml_d...
0
2016-08-23T04:58:16Z
[ "python", "xml", "xml.etree" ]
Processing non-english text
39,049,294
<p>I have a python file that reads a file given by the user, processes it, and ask questions in flash card format. The program works fine with an english txt file but I encounter errors when trying to process a french file.</p> <p>When I first encountered the error, I was using the windows command prompt window and ru...
-2
2016-08-20T00:19:07Z
39,049,324
<p>It's common question. Seems that you're using cmd which doesn't support unicode, so error occurs during <strong>translation of output</strong> to the encoding, which your cmd runs. And as unicode has a wider charset, than encoding used in cmd, it gives an error</p> <p>IDLE is built ontop of tkinter's Text widget, w...
1
2016-08-20T00:24:22Z
[ "python", "python-3.x", "unicode", "utf-8" ]
Processing non-english text
39,049,294
<p>I have a python file that reads a file given by the user, processes it, and ask questions in flash card format. The program works fine with an english txt file but I encounter errors when trying to process a french file.</p> <p>When I first encountered the error, I was using the windows command prompt window and ru...
-2
2016-08-20T00:19:07Z
39,063,084
<p>The Windows console does not natively support Unicode (despite what people say about <code>chcp 65001</code>). It's designed to be backwards compatible so only supports 8bit character sets.</p> <p>Use <a href="https://github.com/Drekin/win-unicode-console" rel="nofollow">win-unicode-console</a> instead. It talks to...
0
2016-08-21T10:13:41Z
[ "python", "python-3.x", "unicode", "utf-8" ]
Removing only the numeric without affecting other numbers in the string
39,049,308
<p>I have a list of objects that goes as follows, for example:</p> <pre><code>['ref_2537_1_obj1', 'ref_8953_1_obj32', 'ref_1120_1_obj', 'ref_8919_1_obj143'] </code></pre> <p>And I wanted to remove the numeric that exists at the end of each item in the list, so that it should be like this:</p> <pre><code>['ref_2537_1...
0
2016-08-20T00:21:55Z
39,049,327
<p>You can use <code>re.sub</code> to substitute the ending digits (if there exist any) with blanks.</p> <pre><code>import re a=['ref_2537_1_obj1', 'ref_8953_1_obj32', 'ref_1120_1_obj', 'ref_8919_1_obj143'] print ([re.sub(r'\d*$','',i) for i in a]) </code></pre>
2
2016-08-20T00:24:40Z
[ "python", "maya" ]
Removing only the numeric without affecting other numbers in the string
39,049,308
<p>I have a list of objects that goes as follows, for example:</p> <pre><code>['ref_2537_1_obj1', 'ref_8953_1_obj32', 'ref_1120_1_obj', 'ref_8919_1_obj143'] </code></pre> <p>And I wanted to remove the numeric that exists at the end of each item in the list, so that it should be like this:</p> <pre><code>['ref_2537_1...
0
2016-08-20T00:21:55Z
39,049,351
<p>No need to use pattern matching (regular expressions) when <code>rstrip</code> is enough (it's faster, simpler and more readable) :</p> <pre><code>a=['ref_2537_1_obj1', 'ref_8953_1_obj32', 'ref_1120_1_obj', 'ref_8919_1_obj143'] print(i.rstrip("0123456789") for i in a) </code></pre>
4
2016-08-20T00:28:48Z
[ "python", "maya" ]
Removing only the numeric without affecting other numbers in the string
39,049,308
<p>I have a list of objects that goes as follows, for example:</p> <pre><code>['ref_2537_1_obj1', 'ref_8953_1_obj32', 'ref_1120_1_obj', 'ref_8919_1_obj143'] </code></pre> <p>And I wanted to remove the numeric that exists at the end of each item in the list, so that it should be like this:</p> <pre><code>['ref_2537_1...
0
2016-08-20T00:21:55Z
39,054,478
<p>Since the format is always the same i.e <em>obj</em> then some digits you can could just <code>rindex</code> on <code>j</code> and slice:</p> <pre><code>In [5]: l = ['ref_2537_1_obj1', 'ref_8953_1_obj32', 'ref_1120_1_obj', 'ref_8919_1_obj143'] In [6]: [s[:s.rindex("j")+1] for s in l] Out[6]: ['ref_2537_1_obj', ...
-1
2016-08-20T13:06:32Z
[ "python", "maya" ]
Python comprehensions in function calls (PEP 448)
39,049,419
<p>(This is all on Python 3.5.2)</p> <p>At the bottom of <a href="https://www.python.org/dev/peps/pep-0448/" rel="nofollow">PEP 448</a>, I see:</p> <blockquote> <p>Unbracketed comprehensions in function calls, such as <code>f(x for x in it)</code> , are already valid.</p> </blockquote> <p>This is intriguing. If I ...
0
2016-08-20T00:41:26Z
39,049,494
<p>This statement means only that in <strong>pre-PEP</strong> world <code>f(x for x in it)</code> was already valid and passed generator expression as first function argument.</p> <p>To make your example work, you need to explicitly unpack generator, as shown in PEP examples.</p> <pre><code>f(*(thing for thing in [1,...
3
2016-08-20T00:55:10Z
[ "python", "python-3.x", "language-lawyer" ]
Python comprehensions in function calls (PEP 448)
39,049,419
<p>(This is all on Python 3.5.2)</p> <p>At the bottom of <a href="https://www.python.org/dev/peps/pep-0448/" rel="nofollow">PEP 448</a>, I see:</p> <blockquote> <p>Unbracketed comprehensions in function calls, such as <code>f(x for x in it)</code> , are already valid.</p> </blockquote> <p>This is intriguing. If I ...
0
2016-08-20T00:41:26Z
39,049,500
<p>What is happening is that on line <code>f(thing for thing in [1, 2, 3])</code> you are passing only the first argument, which is a generator. Arguments <code>b</code> and <code>c</code> are missing.</p> <p>Also, check the following part of the PEP:</p> <blockquote> <p>However, it wasn't clear if this was the bes...
0
2016-08-20T00:56:47Z
[ "python", "python-3.x", "language-lawyer" ]
Python comprehensions in function calls (PEP 448)
39,049,419
<p>(This is all on Python 3.5.2)</p> <p>At the bottom of <a href="https://www.python.org/dev/peps/pep-0448/" rel="nofollow">PEP 448</a>, I see:</p> <blockquote> <p>Unbracketed comprehensions in function calls, such as <code>f(x for x in it)</code> , are already valid.</p> </blockquote> <p>This is intriguing. If I ...
0
2016-08-20T00:41:26Z
39,049,505
<p>Actually <code>f(x for x in it)</code> is not a new feature that introduced by PEP 448 but by <a href="https://www.python.org/dev/peps/pep-0289/" rel="nofollow">PEP 289</a>. Noted not all features that discussed in PEP 448 are implemented in Python 3.5. The <a href="https://www.python.org/dev/peps/pep-0448/#variatio...
0
2016-08-20T00:57:45Z
[ "python", "python-3.x", "language-lawyer" ]
Python comprehensions in function calls (PEP 448)
39,049,419
<p>(This is all on Python 3.5.2)</p> <p>At the bottom of <a href="https://www.python.org/dev/peps/pep-0448/" rel="nofollow">PEP 448</a>, I see:</p> <blockquote> <p>Unbracketed comprehensions in function calls, such as <code>f(x for x in it)</code> , are already valid.</p> </blockquote> <p>This is intriguing. If I ...
0
2016-08-20T00:41:26Z
39,049,533
<p>Python allows you to pass a single generator expression to a function you're calling without needing extra parentheses. For instance:</p> <pre><code>foo(x for x in range(10)) </code></pre> <p>is mostly equivalent to:</p> <pre><code>genexp = (x for x in range(10)) # parentheses are necessary here foo(genexp) </cod...
1
2016-08-20T01:03:48Z
[ "python", "python-3.x", "language-lawyer" ]
Python: Call a class method from within a 'DIFFERENT class''s method
39,049,427
<p>I want to call a method from classB, in a method in classA and pass arguments:</p> <pre><code>class A: B.processAds(ad, cnx, renewableAds, adsToRenew, webdriver) class B: def processAds(self, ad, cnx, renewableAds, adsToRenew, webdriver): </code></pre> <p>How would I do this?</p>
0
2016-08-20T00:42:36Z
39,049,518
<p>Make the method in class B a <code>classmethod</code>:</p> <pre><code>class B: @classmethod def processAds(cls, ad, cnx, renewableAds, adsToRenew, webdriver): </code></pre> <p>then you'll be able to use it without instantiating class B, e.g.:</p> <pre><code>return_value = B.processAds(ad, cnx, renewableAd...
0
2016-08-20T01:01:01Z
[ "python", "oop" ]
Converting .txt file with tab seperation to xlsx via python3
39,049,466
<p>Level: super-noob</p> <p>I have been trying to convert a .txt file to .xlsx using a combination of csv &amp; openpyxl &amp; xlsxwriter modules.</p> <p>My first column is an identity that should be saved as a string Columns 2-21 are then all numbers.</p> <p>How can I load up my .txt file. Identify the proper colum...
1
2016-08-20T00:50:08Z
39,049,612
<p>You need to iterate over each row in csv file and append that row to excel worksheet. </p> <p>This could be helpful:</p> <pre><code>import csv import openpyxl input_file = 'path/to/inputfile.txt' output_file = 'path/to/outputfile.xls' wb = openpyxl.Workbook() ws = wb.worksheets[0] with open(input_file, 'rb') as...
2
2016-08-20T01:22:46Z
[ "python", "excel" ]
Flask static file giving 404
39,049,560
<h2>Code in <code>main.py</code> file:</h2> <pre><code>from flask import Flask, render_template, send_from_directory app = Flask(__name__, static_url_path="") app._static_folder = "static" @app.route("/") def root(): return app.send_static_file("index.html") @app.route("/about") def about(): return app.send_...
-1
2016-08-20T01:10:43Z
39,051,571
<p>There are two possible reasons.</p> <ol> <li>You mis-typed the path. Did you perhaps have a typo in <code>projects</code> (i.e., <code>project</code>) or <code>index.html</code>?</li> <li>The path doesn't exist. Unlike <code>render_template</code>, <code>app.send_static_file</code> just dies if the path doesn't exi...
0
2016-08-20T07:16:44Z
[ "python", "nginx", "flask" ]
Python 3: How to extract url image?
39,049,574
<p>The urls I want to extract have same pattern:</p> <pre><code>"begin" : "url_I_want_extract" </code></pre> <p>They look like:</p> <pre><code>"begin" : "https://k2.website.com/images/0x0/0x0/0/16576946054146395951.jpeg" "begin" : "https://k2.website.com/images/0x0/0x0/0/9460365509030976330.jpeg" "begin" : "https://...
3
2016-08-20T01:15:03Z
39,049,699
<p>The parenthesis surround the capturing groups that are returned by <code>findall</code>. Right now your capturing groups are <code>k(.&gt;)</code> and <code>(.*?).jpeg</code>. Remove those parenthesis and instead capture the entire url.</p> <p>Also, to match both the url's with "/0x0/0x0/0/" and "/8x36/922x950/0/...
2
2016-08-20T01:46:22Z
[ "javascript", "python", "regex", "web-scraping" ]
Python 3: How to extract url image?
39,049,574
<p>The urls I want to extract have same pattern:</p> <pre><code>"begin" : "url_I_want_extract" </code></pre> <p>They look like:</p> <pre><code>"begin" : "https://k2.website.com/images/0x0/0x0/0/16576946054146395951.jpeg" "begin" : "https://k2.website.com/images/0x0/0x0/0/9460365509030976330.jpeg" "begin" : "https://...
3
2016-08-20T01:15:03Z
39,050,200
<p>This one may do the trick on a more general server path construction: </p> <pre><code>https?.*(jpeg|jpg|png|tiff|gif) </code></pre> <p>Start capturing the http ( with optional 's' for ssl servers ) and finish capture assuring a image file format. ( Please note that I included 5 types just as an example...)</p> <p...
1
2016-08-20T03:33:42Z
[ "javascript", "python", "regex", "web-scraping" ]
Python 3: How to extract url image?
39,049,574
<p>The urls I want to extract have same pattern:</p> <pre><code>"begin" : "url_I_want_extract" </code></pre> <p>They look like:</p> <pre><code>"begin" : "https://k2.website.com/images/0x0/0x0/0/16576946054146395951.jpeg" "begin" : "https://k2.website.com/images/0x0/0x0/0/9460365509030976330.jpeg" "begin" : "https://...
3
2016-08-20T01:15:03Z
39,050,224
<p>I think what you're asking for is to extract only the URLs after <code>begin :</code>. For this you'd want:</p> <pre><code>r = re.findall('"begin" : "(https://k.*?.jpeg)"', response.text) </code></pre>
1
2016-08-20T03:38:46Z
[ "javascript", "python", "regex", "web-scraping" ]
differences in computation outputs, theano, non theano
39,049,616
<p>I'm starting to play around with theano, and so I tried computing a simple function and testing the output, however when I test a theano compiled version versus a non theano version the outputs are a bit different....</p> <p>The code:</p> <pre><code>import numpy as np import theano.tensor as T from theano import f...
0
2016-08-20T01:23:30Z
39,049,690
<p>In the expression in this statement</p> <pre><code> print(((S[i] - Q[i])**2).sum() / S.shape[0]) </code></pre> <p>you should divide by <code>S.shape[1]</code>, not <code>S.shape[0]</code>.</p> <p>You created <code>S</code> using <code>S = np.random.rand(4,3)</code>, which means <code>S</code> has shape (4, 3)....
0
2016-08-20T01:43:26Z
[ "python", "numpy", "theano" ]