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 |
|---|---|---|---|---|---|---|---|---|---|
Using widgets intregrated. PyQT with Tkinter | 39,679,473 | <p>I have an image editor created in tkinter. However, I would add a floating widgets that exist in PyQt. Is there any way to run integrated tkinter with PyQt?</p>
| 1 | 2016-09-24T18:09:16Z | 39,681,979 | <p>No, there is no way to combine widgets from PyQt and Tkinter in a single app. </p>
| 0 | 2016-09-24T23:39:21Z | [
"python",
"tkinter",
"pyqt",
"pyqt4"
] |
Using widgets intregrated. PyQT with Tkinter | 39,679,473 | <p>I have an image editor created in tkinter. However, I would add a floating widgets that exist in PyQt. Is there any way to run integrated tkinter with PyQt?</p>
| 1 | 2016-09-24T18:09:16Z | 39,689,904 | <p>I make a workaround that solved the problem. I used python subprocess for call the PyQT instance and the option QtCore.Qt.WindowStaysOnTopHint for app running on top of tkinter. It´s work.</p>
<p>but the best solution is to create a thread in python and call PyQt in this thread. In this case it is possible to pass... | 0 | 2016-09-25T17:48:07Z | [
"python",
"tkinter",
"pyqt",
"pyqt4"
] |
openpyxl iterate through cells of column => TypeError: 'generator' object is not subscriptable | 39,679,497 | <p>i I want to loop over all values op a column, to safe them as the key in a dict. As far as i know, everything is ok, but python disagrees.</p>
<p>So my question is: "what am i doing wrong?"</p>
<pre><code>>>> wb = xl.load_workbook('/home/x/repos/network/input/y.xlsx')
>>> sheet = wb.active
>&g... | -1 | 2016-09-24T18:11:46Z | 39,680,171 | <p><code>ws.columns</code> returns a generator of columns because this is much more efficient on large workbooks, as in your case: you only want one column. <a href="https://openpyxl.readthedocs.io/en/default/tutorial.html#accessing-many-cells" rel="nofollow">Version 2.4</a> now provides the option to get columns direc... | 0 | 2016-09-24T19:29:52Z | [
"python",
"excel",
"loops",
"openpyxl"
] |
openpyxl iterate through cells of column => TypeError: 'generator' object is not subscriptable | 39,679,497 | <p>i I want to loop over all values op a column, to safe them as the key in a dict. As far as i know, everything is ok, but python disagrees.</p>
<p>So my question is: "what am i doing wrong?"</p>
<pre><code>>>> wb = xl.load_workbook('/home/x/repos/network/input/y.xlsx')
>>> sheet = wb.active
>&g... | -1 | 2016-09-24T18:11:46Z | 39,698,206 | <p>apparently, the openpyxl module got upgraded to 2.4, without my knowledge.</p>
<pre><code>>>> for col in ws.iter_cols(min_col = 2, min_row=4):
... for cell in col:
... print(cell.value)
</code></pre>
<p>should do the trick.
I posted this in case other people are looking for the same answer.</p... | 0 | 2016-09-26T08:39:53Z | [
"python",
"excel",
"loops",
"openpyxl"
] |
What is happening in this urlpatterns list of Python Django urls.py file? | 39,679,542 | <p>I have three versions of <code>urls.py</code> file.</p>
<p>Here are imports (shared between versions):</p>
<pre><code>from django.conf.urls.static import static
from django.conf import settings
from django.conf.urls import patterns, url
from main import views
</code></pre>
<p><strong>Version 1.</strong> Everythi... | 0 | 2016-09-24T18:16:33Z | 39,679,586 | <p>I'm not sure why you're surprised; you removed a parameter, and things went wrong. (Your first version might well have "worked" when you ran the server, but I doubt you could actually get to the URL.)</p>
<p>You are using an old version of Django. In this version, <code>urlpatterns</code> must be defined with the r... | 2 | 2016-09-24T18:21:42Z | [
"python",
"django",
"python-2.7",
"typeerror",
"django-urls"
] |
Insert char from string into list in one line | 39,679,559 | <p>I'm after a way to reduce the following code down to one line, I assume through list comprehension. </p>
<pre><code>string = raw_input("String: ")
stringlist = []
for char in string:
stringlist.insert(0, char)
</code></pre>
| 0 | 2016-09-24T18:18:17Z | 39,679,573 | <p>So, you basically want to reverse the string and create a list from its reversed version:</p>
<pre><code>stringlist = list(reversed(raw_input("String: ")))
</code></pre>
<p>The following is even shorter, but probably a bit harder to read:</p>
<pre><code>stringlist = list(raw_input("String: ")[::-1])
</code></pre>... | 3 | 2016-09-24T18:20:22Z | [
"python",
"python-2.7",
"list-comprehension"
] |
How to convert a list to a dictionary where both key and value are the same? | 39,679,649 | <p>This is based on this question: <a href="http://stackoverflow.com/questions/6900955/python-convert-list-to-dictionary">python convert list to dictionary</a></p>
<p>The asker provides the following:</p>
<blockquote>
<pre><code>l = ["a", "b", "c", "d", "e"]
</code></pre>
<p>I want to convert this list to a
di... | -3 | 2016-09-24T18:29:50Z | 39,679,662 | <p>You can use a <a href="https://docs.python.org/2/tutorial/datastructures.html#dictionaries" rel="nofollow">dict-comprehension</a> like this:</p>
<pre><code>l = ["a", "b", "c", "d", "e"]
d = {s: s for s in l}
</code></pre>
| 2 | 2016-09-24T18:30:58Z | [
"python",
"python-3.x",
"dictionary"
] |
How to convert a list to a dictionary where both key and value are the same? | 39,679,649 | <p>This is based on this question: <a href="http://stackoverflow.com/questions/6900955/python-convert-list-to-dictionary">python convert list to dictionary</a></p>
<p>The asker provides the following:</p>
<blockquote>
<pre><code>l = ["a", "b", "c", "d", "e"]
</code></pre>
<p>I want to convert this list to a
di... | -3 | 2016-09-24T18:29:50Z | 39,679,666 | <p>You can just zip the same list together:</p>
<pre><code>dict(zip(l, l))
</code></pre>
<p>or use a dict comprehension:</p>
<pre><code>{i: i for i in l}
</code></pre>
<p>The latter is faster:</p>
<pre><code>>>> from timeit import timeit
>>> timeit('dict(zip(l, l))', 'l = ["a", "b", "c", "d", "e"... | 4 | 2016-09-24T18:31:20Z | [
"python",
"python-3.x",
"dictionary"
] |
python xpath loop through paragraphs and grab <strong> | 39,679,668 | <p>I have a series of paragraphs I'm trying to parse using xpath. The html is formatted like this:</p>
<pre><code><div id="content_third">
<h3>Title1</h3>
<p>
<strong>District</strong>
John Q Public <br>
Susie B Private
<p>
<p>
<strong>District&l... | 0 | 2016-09-24T18:31:34Z | 39,680,517 | <p>I presume each <em>District</em> is a placeholder for some actual name so to get each District is a lot simpler than what you are trying to do, just extract the <em>text</em> from each <em>strong</em> inside each <em>p</em>:</p>
<pre><code>h = """<div id="content_third">
<h3>Title1</h3>
<p&... | 1 | 2016-09-24T20:10:56Z | [
"python",
"loops",
"xpath"
] |
Python - IF function inside of the button | 39,679,966 | <p>I have a problem with below code. By default it's a simple code, that switches frames. What I try to do is to modify LoginPage class to do what it says - login ;) as you can see, I have a test.db SQL database in place. It contains table users with columns: (Id INT, Name TEXT, Password TEXT)
What I need to do is inpu... | 1 | 2016-09-24T19:06:46Z | 39,682,025 | <p>Consider adding a method <code>checkLogin</code> and not an anonymous <code>lambda</code> function which currently always opens the success screen. This method will run the parameterized SQL query to check credentials and depending on results calls the login success or failed frames:</p>
<pre class="lang-sql pretty... | 1 | 2016-09-24T23:46:30Z | [
"python",
"sql",
"tkinter"
] |
Tornado Coroutine : Return value and one time execution | 39,680,068 | <p>I'm new to Tornado so I wanted to know if the code below is a correct way to approach the problem or there is a better one. It works but I'm not sure regarding its efficiency. </p>
<p>The code is based on the documentation <a href="http://www.tornadoweb.org/en/stable/guide/coroutines.html" rel="nofollow">here</a></... | 0 | 2016-09-24T19:19:08Z | 39,680,224 | <p>Yes, your code looks correct to me.</p>
| 1 | 2016-09-24T19:36:28Z | [
"python",
"tornado"
] |
Can I set variable column widths in pandas? | 39,680,147 | <p>I've got several columns with long strings of text in a pandas data frame, but am only interested in examining one of them. Is there a way to use something along the lines of <code>pd.set_option('max_colwidth', 60)</code> but for a <strong>single column</strong> only, rather than expanding the width of all the colum... | 1 | 2016-09-24T19:27:39Z | 39,680,725 | <p>If you want to change the display in a Jupyter Notebook, you can use the <a href="http://pandas.pydata.org/pandas-docs/stable/style.html" rel="nofollow">Style</a> feature.
To use this formatting for only some columns simply indicate the column(s) to enlarge thanks to the <code>subset</code> parameter. This is basic... | 4 | 2016-09-24T20:33:40Z | [
"python",
"pandas"
] |
Can I set variable column widths in pandas? | 39,680,147 | <p>I've got several columns with long strings of text in a pandas data frame, but am only interested in examining one of them. Is there a way to use something along the lines of <code>pd.set_option('max_colwidth', 60)</code> but for a <strong>single column</strong> only, rather than expanding the width of all the colum... | 1 | 2016-09-24T19:27:39Z | 39,680,775 | <p>check this link pls: Truncating column width in pandas</p>
<p><a href="http://check%20this%20link%20pls%20http://stackoverflow.com/questions/22792740/truncating-colum%E2%80%8C%E2%80%8Bn-width-in-pandas" rel="nofollow">http://stackoverflow.com/questions/22792740/truncating-column-width-in-pandas</a></p>
| 0 | 2016-09-24T20:41:52Z | [
"python",
"pandas"
] |
Why are there blank spaces in the Unicode character table and how do I check if a unicode value is one of those? | 39,680,148 | <p>If you check out the <a href="http://unicode-table.com/en/#control-character" rel="nofollow">Unicode Table</a>, there are several spaces further in the table that are simply blank. There's a unicode value, but no character, ex. U+0BA5. Why are there these empty places?</p>
<p>Second of all, how would I check if a u... | 0 | 2016-09-24T19:27:43Z | 39,680,197 | <p>Not all Unicode codepoints have received an assignment; this can be for any number of reasons, historical, practical, policital, etc.</p>
<p>You can test if a given codepoint has a Unicode <em>name</em>, by using the <a href="https://docs.python.org/3/library/unicodedata.html#unicodedata.name" rel="nofollow"><code>... | 1 | 2016-09-24T19:33:06Z | [
"python",
"unicode"
] |
PYTHONPATH in OS X | 39,680,157 | <p>I set PYTHONPATH variable on my Apple laptop a while ago.
I have checked /private/etc/profile config file. It is not there. Where else I could find it?</p>
<p>What other config file could be used to set the PYTHONPATH variable on OS X?</p>
| 0 | 2016-09-24T19:28:43Z | 39,681,022 | <p>There are several config files that can be used to set <strong>PYTHONPATH</strong> in OS X:</p>
<p>The first is <strong>profile</strong> file which is located in hidden <em>/private/etc/</em> folder:</p>
<pre><code>/private/etc/profile
</code></pre>
<p>You can use the following syntax to set the variable there:</... | 1 | 2016-09-24T21:13:55Z | [
"python"
] |
Pandas, split dataframe by monotonic increase of column value | 39,680,162 | <p>I have a gigantic dataframe with a datetime type column called time, and another float type column called dist, the data frame is sorted based on time, and dist already.
I want to split the dataframe into several dataframes base on monotonic increase of dist.</p>
<p>Split</p>
<pre><code> dt d... | 1 | 2016-09-24T19:29:25Z | 39,680,327 | <p>You can calculate a difference vector of <code>dist</code> column and then do a <code>cumsum()</code> on the condition <code>diff < 0</code> (this creates a new id whenever the <code>dist</code> decreases from previous value)</p>
<pre><code>df['id'] = (df.dist.diff() < 0).cumsum()
print(df)
# ... | 4 | 2016-09-24T19:48:56Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
Pandas, split dataframe by monotonic increase of column value | 39,680,162 | <p>I have a gigantic dataframe with a datetime type column called time, and another float type column called dist, the data frame is sorted based on time, and dist already.
I want to split the dataframe into several dataframes base on monotonic increase of dist.</p>
<p>Split</p>
<pre><code> dt d... | 1 | 2016-09-24T19:29:25Z | 39,680,343 | <p>you can do it using <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.split.html" rel="nofollow">np.split()</a> method:</p>
<pre><code>In [92]: df
Out[92]:
dt dist
0 2016-08-11 11:10:00 1.0
1 2016-08-11 11:15:00 1.4
2 2016-08-11 12:15:00 1.8
3 2016-08-11 12:32:00 0.6
4 2... | 1 | 2016-09-24T19:51:18Z | [
"python",
"pandas",
"numpy",
"dataframe"
] |
How to call UI class in Qt5 in Python | 39,680,265 | <p>This is the class that have to call the UI class:</p>
<pre><code>class mainpanelManager(QtGui.QGuiApplication, Ui_MainWindow):
def __init__(self):
QtGui.QGuiApplication.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
if __name__ == "__main__":
app = QtGui.QGuiApplica... | 1 | 2016-09-24T19:41:34Z | 39,680,430 | <p>You need a subclass which matches the top-level object from Qt Designer - which in this case appears to be a <code>QMainWindow</code>:</p>
<pre><code>class mainpanelManager(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
</code></pre>
<p>And you ... | 1 | 2016-09-24T20:00:29Z | [
"python",
"python-3.x",
"qt5",
"qt-creator",
"pyqt5"
] |
Append nested dictionaries | 39,680,317 | <p>If you have a nested dictionary, where each 'outer' key can map to a dictionary with multiple keys, how do you add a new key to the 'inner' dictionary? For example, I have a list where each element is composed of 3 components: an outer key, an inner key, and a value (A B 10).</p>
<p>Here's the loop I have so far</p... | 0 | 2016-09-24T19:47:57Z | 39,680,349 | <p>You told your code to assign newly created dict to key <code>e[0]</code>. It's always replaced blindly and it does not look at previously stored value.</p>
<p>Instead you need something like:</p>
<pre><code>for e in keyList:
if e[0] not in nested_dict:
nested_dict[e[0]] = {}
nested_dict[e[0]].updat... | 3 | 2016-09-24T19:51:37Z | [
"python",
"dictionary"
] |
Paser symbol(pdb) file and get function name and offset | 39,680,387 | <p>I want to know what is the easiest way to parse a PDB (debugging symbol) file and get function name and offset in binary, preferably in Python.</p>
<p>Thanks,</p>
| 0 | 2016-09-24T19:55:08Z | 39,680,409 | <p>Dunno about Python but you should be able to do it using <a href="https://msdn.microsoft.com/en-us/library/t6tay6cz.aspx" rel="nofollow">DIA API</a>. See <a href="https://msdn.microsoft.com/en-us/library/eee38t3h.aspx" rel="nofollow">Querying the .Pdb File</a> for example.</p>
| -1 | 2016-09-24T19:58:32Z | [
"python",
"debugging",
"symbols",
"pdb",
"debug-symbols"
] |
Python Turtle Program not working | 39,680,569 | <p>Can't figure out why am I getting this error: AttributeError: 'str' object has no attribute 'forward'</p>
<p>Write a function named drawSquare. The function drawSquare takes two
parameters: a turtle, t and an integer, length, that is the length of a side of the square.</p>
<p>The function drawSquare should use the... | 0 | 2016-09-24T20:16:06Z | 39,680,606 | <p>In the last line, when you made the call to your drawSquare function you passed the string 'turtle' - pass in your Turtle object t instead.</p>
| 1 | 2016-09-24T20:20:41Z | [
"python",
"turtle-graphics"
] |
scikit-learn - train_test_split and ShuffleSplit yielding very different results | 39,680,596 | <p>I'm trying to do run a simple RandomForestClassifier() with a large-ish dataset. I typically first do the cross-validation using <code>train_test_split</code>, and then start using <code>cross_val_score</code>.</p>
<p>In this case though, I get very different results from these two approaches, and I can't figure ou... | 0 | 2016-09-24T20:19:40Z | 39,772,418 | <p>I'm not sure what's the issue but here are two things you could try:</p>
<ol>
<li><p>ROC AUC needs prediction probabilities for proper evaluation, not hard scores (i.e. 0 or 1). Therefore change the <code>cross_val_score</code> to work with probabilities. You can check the first answer on <a href="http://stackoverf... | 0 | 2016-09-29T13:59:17Z | [
"python",
"pandas",
"scikit-learn"
] |
Matching company names in the news data using Python | 39,680,624 | <p>I have news dataset which contains almost 10,000 news over the last 3 years.
I also have a list of companies (names of companies) which are registered in NYSE. Now I want to check whether list of company names in the list have appeared in the news dataset or not.
Example:</p>
<pre><code>company Name: 'E.I. du Pont ... | 1 | 2016-09-24T20:22:07Z | 39,680,656 | <p>You can try</p>
<pre><code> difflib.get_close_matches
</code></pre>
<p>with the full company name.</p>
| -1 | 2016-09-24T20:26:11Z | [
"python",
"python-3.x",
"machine-learning"
] |
Matching company names in the news data using Python | 39,680,624 | <p>I have news dataset which contains almost 10,000 news over the last 3 years.
I also have a list of companies (names of companies) which are registered in NYSE. Now I want to check whether list of company names in the list have appeared in the news dataset or not.
Example:</p>
<pre><code>company Name: 'E.I. du Pont ... | 1 | 2016-09-24T20:22:07Z | 39,680,694 | <p>Use a regex with <a href="http://www.rexegg.com/regex-boundaries.html" rel="nofollow">boundaries</a> for exact matches whether you choose the full name or some partial part you think is unique is up to you but using word boundaries <code>D'ennis'</code> won't match <code>Ennis</code> :</p>
<pre><code>companies = [... | 1 | 2016-09-24T20:29:53Z | [
"python",
"python-3.x",
"machine-learning"
] |
Empty .mp4 file created after making video from matplotlib using matplotlib.animation | 39,680,733 | <p>I found this little code, and I am able to save a video (random colors changing in a grid) using it:</p>
<pre><code>import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from scipy import rand
Writer = animation.writers['ffmpeg']
writer ... | 2 | 2016-09-24T20:35:04Z | 39,683,095 | <p>Your <code>self.video.append((plt.pcolormesh(Frame),))</code> line is fine. You just changed the order of statements.</p>
<pre><code>import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
class Dummy():
def __init__(self, fname):
... | 1 | 2016-09-25T03:30:00Z | [
"python",
"numpy",
"video",
"matplotlib",
"simulation"
] |
Redirect error when trying to request a url with requests/urllib only in python | 39,680,860 | <p>im trying to post data to a url in my server ... but im stuck in sending any request to that url (any url on that server ) here is one for example </p>
<pre><code>http://apimy.in/page/test
</code></pre>
<p>the website is written in python3.4/django1.9</p>
<p>i can send request with <code>curl</code> in <code>php... | 1 | 2016-09-24T20:52:56Z | 39,681,064 | <p>Since you are using the <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a> module did you try to tell the requests module to ignore redirects?</p>
<pre><code>import requests
response = requests.get('your_url_here', allow_redirects=False)
</code></pre>
<p>Maybe this work.
... | 0 | 2016-09-24T21:19:38Z | [
"python",
"django",
"redirect",
"curl",
"urllib"
] |
pelican: do not build specific article | 39,680,887 | <p>what's the best way to not build a page for a specific Pelican article?</p>
<p>I'm asking because I'm using some article pages mainly as metadata collections but I don't want them to have a specific page you can access.
For example I have a bunch of articles for portfolio clients which include metadata like the lin... | 0 | 2016-09-24T20:55:25Z | 39,700,238 | <p>It's unclear to me what you're after, it sounds like what you really want is to be able to include data from a file into other articles? </p>
<p>If so, you could use the reStructuredText <a href="http://docutils.sourceforge.net/docs/ref/rst/directives.html#including-an-external-document-fragment" rel="nofollow">inc... | 0 | 2016-09-26T10:19:07Z | [
"python",
"blogs",
"pelican"
] |
Accessing marshmallow decorators when using flask-marshmallow | 39,680,910 | <p>I'm using flask-restful, flask-sqlalchemy and flask-marshmallow to build an API service. I define the following -</p>
<pre><code>ma = Marshmallow(app)
</code></pre>
<p>However, trying to access the @validates decorator using ma throws an error.</p>
<pre><code>@ma.validates('field1')
</code></pre>
<p>What am I do... | 0 | 2016-09-24T20:58:06Z | 39,681,060 | <p>The problem is that you are trying to reach <code>flask-marshmallow</code> decorators in its API, however there is none.</p>
<p>So you to understand if you need <code>flask-marshmallow</code> package, or only <code>marshmallow</code> is required.</p>
<p>Also to make things work, you need to use <a href="http://mar... | 0 | 2016-09-24T21:18:45Z | [
"python",
"flask-restful",
"marshmallow"
] |
?how to make a two dimensional matrix | 39,681,055 | <p>I have 1 dictionary and 1 tuple </p>
<pre><code> students = { 0: "Nynke", 1: "Lolle", 2: "Jikke", 3: "Popke", 4: "Teake", 5:
"Lieuwe", 6: "Tsjabbe", 7: "Klaske", 8: "Ypke", 9: "Lobke"}
friendships = [(0, 1), (0, 2), (1, 2), (1, 3), (2, 3), (3, 4), (4, 5), (5,
6), (5, 7), (6, 8), (7, 8), (8, 9)]
</code></pre>
<p>F... | -3 | 2016-09-24T21:17:26Z | 39,681,116 | <p>Not a 100% sure I understand exactly what you're trying to do, so correct me if I have the wrong idea. But here's what I think,</p>
<p>For the first one you can try creating a dictionary to store every friendships</p>
<pre><code>all_friends = {}
for f in friendships:
if f[0] in all_friends:
all_friends[f[... | 0 | 2016-09-24T21:26:15Z | [
"python"
] |
Import Error : ImapLibrary robotframework-RIDE | 39,681,061 | <p>I'm new to robotframwork. I'm able to work with Selenium2Library and other libraries. I tried to import the Imaplibrary after installation via pip it throws an error:</p>
<pre><code>[ ERROR ] Error in file 'C:\Users\prathod\Documents\automation\Registration.txt': Importing test library 'ImapLibrary' failed: ImportE... | 1 | 2016-09-24T21:19:07Z | 39,734,466 | <p>Try this</p>
<pre><code>pip install future --upgrade
</code></pre>
<p>then retry.</p>
| 0 | 2016-09-27T21:18:23Z | [
"python",
"jython",
"robotframework"
] |
Text arbitrarily not reading into buffer | 39,681,101 | <p>I'm trying to analyze philosophical and classic texts with the Watson Alchemy API, I'm having trouble with reading texts from a .txt file on my computer to a python variable.</p>
<p>Here is the code:</p>
<pre><code>from __future__ import print_function
from alchemyapi import AlchemyAPI
import argparse
import json
... | 0 | 2016-09-24T21:24:41Z | 39,681,263 | <p>Turns out the \r characters in the file were somehow messing it up.</p>
<p>changed this line:<code>data=myfile.read().replace('\n', ' ')</code> to
<code>data=myfile.read().replace('\n', ' ').replace('\r', ' ')</code></p>
| 1 | 2016-09-24T21:46:13Z | [
"python"
] |
Cannot understand how this property on a model is being invoked | 39,681,108 | <p>I am going over a tutorial on extending a user model and it seems to work however I had 2 questions on how a property is being invoked and about a constructor. First this is the code in question</p>
<p>The main model is this</p>
<pre><code>class UserProfile(models.Model):
user = models.OneToOneField(User)
... | 0 | 2016-09-24T21:25:19Z | 39,681,156 | <p><strong>Q1</strong>: Because you are using django predefined <code>User</code> class you have two options to add new property(to inherit <code>User</code> model and say django to use it for just adding new property), or just do it like you did.</p>
<p>When you call <code>user.profile</code> you already passing <cod... | 2 | 2016-09-24T21:31:04Z | [
"python",
"django",
"django-models",
"lambda",
"django-forms"
] |
Why is QColorDialog.getColor crashing unexpectedly? | 39,681,109 | <p>I got this little mcve code:</p>
<pre><code>import sys
import re
from PyQt5 import QtGui, QtWidgets, QtCore
from PyQt5.Qsci import QsciScintilla
from PyQt5 import Qsci
class SimpleEditor(QsciScintilla):
def __init__(self, language=None, parent=None):
super().__init__(parent)
font = QtGui.QF... | 0 | 2016-09-24T21:25:23Z | 39,681,886 | <p>Opening a dialog with a blocking <code>exec()</code> inside the cursor-change handler seems like a bad idea, so I'm not surprised it crashes. It will be much safer to open the dialog asynchronously and use a signal/slot to handle the result. Using a closure with <code>show()</code> would seem best, as it will give a... | 1 | 2016-09-24T23:23:19Z | [
"python",
"python-3.x",
"pyqt"
] |
Python code output isn't displaying properly | 39,681,132 | <p>My code seems fine but when i run it and input the sales it wont show the commission.</p>
<p><img src="http://i.stack.imgur.com/J7NyF.png" alt="picture"></p>
<p>this is python btw.</p>
<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pr... | -1 | 2016-09-24T21:27:50Z | 39,681,148 | <p>Change:</p>
<pre><code>print ("The commission is: "),commission
</code></pre>
<p>To:</p>
<pre><code>print ("The commission is: ", commission)
</code></pre>
| 1 | 2016-09-24T21:30:17Z | [
"python",
"output",
"modular"
] |
Scrapy: populate items with item loaders over multiple pages | 39,681,269 | <p>I'm trying to crawl and scrape multiple pages, given multiple urls. I am testing with Wikipedia, and to make it easier I just used the same Xpath selector for each page, but I eventually want to use many different Xpath selectors unique to each page, so each page has its own separate parsePage method. </p>
<p>This ... | 0 | 2016-09-24T21:47:26Z | 39,681,398 | <p>One issue is that you're passing multiple references of <em>a same item loader instance</em> into multiple callbacks, e.g. there are two <code>yield request</code> instructions in <code>parse</code>.</p>
<p>Also, in the following-up callbacks, the loader is still using the old <code>response</code> object, e.g. in ... | 1 | 2016-09-24T22:07:21Z | [
"python",
"scrapy"
] |
Kivy custom widget instanciated twice | 39,681,281 | <p>I'm trying to build a simple Kivy custom widget containing two sliders.
When the screen is rendered I get two pairs of sliders instead of one.</p>
<p>What am I doing wrong ?</p>
<p><strong>Main.kv:</strong></p>
<pre><code>ScreenManagement:
MainScreen:
<Button>:
size_hint: .2, .1
font_size: 20
... | 0 | 2016-09-24T21:50:34Z | 39,708,529 | <p>You should rename the kv file to <code>main.kv</code>, and delete the explicit load of it in <code>build</code> method. It is going to load itself automatically. The bug is weird, maybe worth a ticket.</p>
| 0 | 2016-09-26T17:07:10Z | [
"python",
"user-interface",
"kivy"
] |
Import Django model class in Scrapy project | 39,681,337 | <p>I have a django project and a scrapy project</p>
<p>and I want to import django model from to scrapy project.</p>
<p>This is my spider:</p>
<pre><code>import scrapy
from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkExtractor
import sys
sys.path.append('/home/ubuntu/venv/dict')
fr... | 0 | 2016-09-24T21:58:43Z | 39,681,577 | <p>You need to <a href="https://docs.djangoproject.com/en/1.10/ref/applications/#initialization-process" rel="nofollow">initialize Django </a> before using models outside the context of Django apps:</p>
<pre><code>import django
django.setup()
</code></pre>
| 1 | 2016-09-24T22:36:20Z | [
"python",
"django",
"scrapy"
] |
"len(sys.argv) < 2" not satisfied even when command called with only one argument | 39,681,347 | <pre><code>#! /usr/bin/python3
# pw.py - An insecure password locker program.
PASSWORDS = {'email': 'aklsjdlksajdkljl',
'blog': 'dklasjkl9379343',
'luggage': '12345'}
import sys, pyperclip
if len(sys.argv) < 2:
print('Usage: python ' + sys.argv[0] + ' [' + sys.argv[1] + '] - copy ac... | -1 | 2016-09-24T21:59:23Z | 39,681,370 | <p>If <code>sys.argv[1]</code> is defined, the length of <code>sys.argv</code> is 2 or greater. The test <code>sys.argv < 2</code> is only going to be true when <code>sys.argv</code> contains just 0 or 1 items. So the <code>if len(sys.argv) < 2:</code> is not skipped, the test is just <em>false</em> and the assoc... | 1 | 2016-09-24T22:02:48Z | [
"python"
] |
Parse only text within a div class python | 39,681,359 | <p>so what I wanna do is from reading the source code, search for the div class named "gsc_prf_il", then within this div class, extract only the text, ignoring the href link. e.g. </p>
<pre><code><div class="gsc_prf_il"><a href="/citations?view_op=view_org&hl=en&org=13784427342582529234">McGill Uni... | 1 | 2016-09-24T22:01:44Z | 39,690,485 | <p>Just find the <em>div</em> and pull the text, you are looking for <code>soup.find(id='gsc_prf_il')</code> which is looking for an element with an <code>id</code> of <code>gsc_prf_il</code> not a div with that class:</p>
<pre><code>from bs4 import BeautifulSoup
url = "http://python-data.dr-chuck.net/comments_283660.... | 1 | 2016-09-25T18:42:14Z | [
"python",
"python-2.7",
"beautifulsoup",
"html-parsing"
] |
Smarter way to gather data or a way to sort the data | 39,681,360 | <p>I'm pulling data from an sqlite table using <code>snip1</code>, this of course grabs each row containing the relevant <code>id</code> value. The <code>services</code> list now looks like <code>output1</code>.</p>
<p>I'd like to be able to sort the list of lists of tuples into a more managable data set. Merging all ... | 1 | 2016-09-24T22:01:45Z | 39,681,453 | <pre><code>d = {}
for item in data:
d[item[0][0]] = []
for i in item:
d[i[0]] = d[i[0]] + [int(i[1])]
</code></pre>
| 1 | 2016-09-24T22:17:52Z | [
"python",
"dictionary"
] |
Smarter way to gather data or a way to sort the data | 39,681,360 | <p>I'm pulling data from an sqlite table using <code>snip1</code>, this of course grabs each row containing the relevant <code>id</code> value. The <code>services</code> list now looks like <code>output1</code>.</p>
<p>I'd like to be able to sort the list of lists of tuples into a more managable data set. Merging all ... | 1 | 2016-09-24T22:01:45Z | 39,681,538 | <p>You can do this with one line with using <code>dict</code> and <code>list</code> comprehensions</p>
<pre><code>>>> data = [[(2, u'22')], [(3, u'25')], [(4, u'443')], [(5, u'443')], [(6, u'443')], [(7, u'22')],
[(8, u'80')], [(9, u'443')], [(10, u'80'), (10, u'443')], [(11, u'80'), (11, u'443')],
... | 1 | 2016-09-24T22:30:53Z | [
"python",
"dictionary"
] |
Smarter way to gather data or a way to sort the data | 39,681,360 | <p>I'm pulling data from an sqlite table using <code>snip1</code>, this of course grabs each row containing the relevant <code>id</code> value. The <code>services</code> list now looks like <code>output1</code>.</p>
<p>I'd like to be able to sort the list of lists of tuples into a more managable data set. Merging all ... | 1 | 2016-09-24T22:01:45Z | 39,681,562 | <p>To convert a list of tuples into a dictionary:</p>
<pre><code> list = [(10, u'80'), (10, u'443')]
dict = {}
for (i, j) in list:
dict.setdefault(i, []).append(j)
</code></pre>
<p>This will give you:</p>
<pre><code> >>> dict
{10: [u'80', u'443']}
</code></pre>
<p>You can then us... | 1 | 2016-09-24T22:34:28Z | [
"python",
"dictionary"
] |
Which is faster in Python: if or try | 39,681,373 | <p>Please consider the following code:</p>
<pre><code>def readPath(path):
content = None
if os.path.isfile(path):
f = open(path,"rb")
content = f.read()
f.close()
return content
</code></pre>
<p>versus this one:</p>
<pre><code>def readPath(path):
content = None
try:
f = open(pa... | 0 | 2016-09-24T22:03:20Z | 39,681,409 | <p>Usually, the answer to "whichever to use, <code>if</code> or <code>try</code>", the answer is <strong>EAFP</strong> - it is easier to ask for forgiveness than permission, thus always prefer <code>try</code> over <code>if</code>. However, in this case, neither EAFP nor performance considerations shouldn't be reason t... | 6 | 2016-09-24T22:09:48Z | [
"python"
] |
Sorting an XML file based on node value | 39,681,434 | <p>I was trying to compare two XML files which have same content but on different lines at times. To overcome this, I was trying to sort the XMLs on one of the child nodes (which usually differs in position in both files).</p>
<p>Here is my sample XML file</p>
<pre><code><Report>
<rptName>Sample</rptNa... | -1 | 2016-09-24T22:14:35Z | 39,681,680 | <p>Consider the following XSLT script with Python's <code>lxml</code> integration. Also, you attempt to run a dynamic command line process. Unfortunately, the XSLT will structurally change depending on what specific node you intend to sort. Below will specifically sort <code><membId></code> in ascending order:</p... | 2 | 2016-09-24T22:52:14Z | [
"python",
"xml",
"python-2.7",
"xslt",
"xslt-2.0"
] |
random.randrange does not seem quite random | 39,681,473 | <p>I am pretty new to python so i dont know many things.
So lets say i got this piece of code </p>
<pre><code>for i in range(10000):
n = random.randrange(1, 1000**20)
ar.append(n)
print(n)
</code></pre>
<p>The smallest number i get out of the 10000 is always 3-4 digits smaller than 1000^20
in this particular example ... | -2 | 2016-09-24T22:21:14Z | 39,681,610 | <p>Okay, so let's use small numbers to illustrate that clearly.</p>
<p>Suppose you pick a random number from 1 to 100, inclusively.</p>
<p>How many 1 digit numbers are there? 9, from 1 to 9. For 2 digits it's from 10 to 99, 90 numbers. For 3 digits it's just 1, 100. Since it's a random pick, the probability of pickin... | 1 | 2016-09-24T22:41:39Z | [
"python",
"random"
] |
Time localized wrongly in Python | 39,681,474 | <p>Using python Im trying to localize a datetime value to timezone "America/Chicago" which is -06:00 currently.
I get the timezone the following way:</p>
<pre><code>>>> import pytz
>>> tz = pytz.timezone("America/Chicago")
<DstTzInfo 'America/Chicago' CST-1 day, 18:00:00 STD>
</code></pre>
<p>... | 0 | 2016-09-24T22:21:17Z | 39,682,969 | <p>Btw Chicago is observing DST now. So -05.00 is the right offset. Pytz timezone by default has the standard time, but when localized can account for day light saving based on the date(as in your case).</p>
| 1 | 2016-09-25T03:01:30Z | [
"python",
"python-2.7",
"datetime",
"localization"
] |
Python - Only printing 'PRINT' | 39,681,504 | <p>I am trying to make my own basic programming language. I have the following code in my <code>smrlang.py</code> file</p>
<pre><code>from sys import *
tokens = []
def open_file(filename):
data = open(filename, "r").read()
return data
def smr(filecontents):
tok = ""
state = 0
string = ""
fil... | -1 | 2016-09-24T22:26:28Z | 39,681,621 | <p>Debugging it in the head, I found the problem:</p>
<pre><code>elif state == 1:
string += tok
</code></pre>
<p>You don't reset the token here. It will be <code>aababcabcd</code> instead of <code>abcd</code> and recognizing <code>\</code> won't work (as it will be <code>aababcabcd\</code>).</p>
<p>This also cau... | 0 | 2016-09-24T22:43:10Z | [
"python"
] |
Django app has a no ImportError: No module named 'django.core.context_processors' | 39,681,560 | <p>Tried git pushing my app after tweaking it and got the following error.</p>
<pre><code>ImportError: No module named 'django.core.context_processors'
</code></pre>
<p>this was not showing up in my heroku logs and my app works locally so I was confused. I had to set debug to true on the production side to finally fi... | 0 | 2016-09-24T22:34:23Z | 39,681,821 | <p>Try removing <code>"django.core.context_processors.request"</code> from your settings.</p>
<p>In Django 1.10 <code>django.core.context_processors</code> has been moved to <code>django.template.context_processors</code>. See <a href="https://docs.djangoproject.com/en/1.10/releases/1.8/#django-core-context-processors... | 1 | 2016-09-24T23:13:48Z | [
"python",
"django",
"git",
"heroku",
"deployment"
] |
Django app has a no ImportError: No module named 'django.core.context_processors' | 39,681,560 | <p>Tried git pushing my app after tweaking it and got the following error.</p>
<pre><code>ImportError: No module named 'django.core.context_processors'
</code></pre>
<p>this was not showing up in my heroku logs and my app works locally so I was confused. I had to set debug to true on the production side to finally fi... | 0 | 2016-09-24T22:34:23Z | 39,681,840 | <p>I fixed it, in settings.py In my TEMPLATES, I changed this line from this</p>
<pre><code>django.core.context_processors.request
</code></pre>
<p>to this</p>
<pre><code>django.template.context_processors.request
</code></pre>
<p>and now I can see my site. I hope this helps someone.</p>
| 0 | 2016-09-24T23:15:37Z | [
"python",
"django",
"git",
"heroku",
"deployment"
] |
Python Webdriver raises http.client.BadStatusLine error | 39,681,605 | <p>I'm writing a parser and I'm using Selenium Webdriver. So, I have this <a href="https://repl.it/Dgtp" rel="nofollow">https://repl.it/Dgtp</a> code and it's working fine until one random element and throws following exception:
http.client.BadStatusLine: ''<br>
Don't know how to fix it at all. Help.</p>
<p><strong>[U... | 0 | 2016-09-24T22:40:47Z | 39,681,760 | <p>This is a <code>urllib</code> problem. This happens most commonly in python3. What it means is that the status code that the server returned isn't recognized by the http library. Sometimes the server doesn't receive the request at all and the status code returns an empty string triggering that error. </p>
<p><stron... | 0 | 2016-09-24T23:03:59Z | [
"python",
"django",
"selenium",
"webdriver",
"phantomjs"
] |
Gantt Chart python machine scheduling | 39,681,620 | <p>I'm having some bad time trying to plot a gantt chart from a data set with python. I have a set of machines that work on different tasks during a time period. I want to make a gantt chart that shows by the y axis the machines and x axis the time spent on each task.
Each machine should appear just once on the y axis ... | 0 | 2016-09-24T22:43:04Z | 39,703,040 | <p>Seimetz,</p>
<p>If you are fine passing the entire data to the client and let a JS Gantt do it's thing, then the RadiantQ jQuery Gantt Package will be a better option for you. Here is an online demo of something similar:
<a href="http://demos.radiantq.com/jQueryGanttDemo/Samples/ServerStatusWithHugeData.htm" rel="n... | 0 | 2016-09-26T12:37:20Z | [
"python",
"matplotlib",
"job-scheduling",
"gantt-chart"
] |
Python - Property Getter as a lambda with a parameter | 39,681,623 | <p>Being new to python I just came across the <code>property</code> keyword which basically lets you assign getters and setters. I came up with this simple example</p>
<pre><code>class foo:
def __init__(self,var=2):
self.var= var
def setValue(self,var):
print("Setting value called")
se... | 1 | 2016-09-24T22:43:23Z | 39,681,740 | <p>The normal/idomatic way to write a property is:</p>
<pre><code>class MyClass(object):
def __init__(self):
self._foo = 42
@property
def foo(self):
return self._foo
@foo.setter
def foo(self, val):
self._foo = val
</code></pre>
<p>as you can see, like all other method def... | 5 | 2016-09-24T22:59:50Z | [
"python",
"lambda"
] |
Python - Property Getter as a lambda with a parameter | 39,681,623 | <p>Being new to python I just came across the <code>property</code> keyword which basically lets you assign getters and setters. I came up with this simple example</p>
<pre><code>class foo:
def __init__(self,var=2):
self.var= var
def setValue(self,var):
print("Setting value called")
se... | 1 | 2016-09-24T22:43:23Z | 39,681,764 | <p>You probably want to do something like this.</p>
<pre><code>class double:
def __init__(self):
self._var = None
var = property(lambda self: self._var,
lambda self, value: setattr(self, "_var", value))
d = double()
d.var = 3
print(d.var)
</code></pre>
<p>When you work with bound ... | 1 | 2016-09-24T23:04:23Z | [
"python",
"lambda"
] |
Subprocess Isolation in Python | 39,681,631 | <p>I am currently working on a personal project where I have to run two processes simultaneously. The problem is that I have to isolate each of them (they cannot communicate between them or with my system) and I must be able to control their stdin, stdout and stderr. Is there anyway I can achieve this?</p>
<p>Thank yo... | 0 | 2016-09-24T22:45:01Z | 39,681,690 | <p>I don't know if you have an objection to using a 3'rd party communication library for your task but this sounds like what ZeroMQ would be used for.</p>
| 0 | 2016-09-24T22:53:08Z | [
"python",
"subprocess",
"chroot",
"isolation"
] |
Subprocess Isolation in Python | 39,681,631 | <p>I am currently working on a personal project where I have to run two processes simultaneously. The problem is that I have to isolate each of them (they cannot communicate between them or with my system) and I must be able to control their stdin, stdout and stderr. Is there anyway I can achieve this?</p>
<p>Thank yo... | 0 | 2016-09-24T22:45:01Z | 39,691,935 | <p>A combination of <code>os.setuid()</code>, <code>os.setgid()</code> and <code>os.setgroups()</code> (also maybe <code>os.chroot()</code>) is a good solution.</p>
| 0 | 2016-09-25T21:17:35Z | [
"python",
"subprocess",
"chroot",
"isolation"
] |
What does "overhead" memory refer to in the case of Linked Lists? | 39,681,639 | <p>I understand that a node is usually 8 bytes, 4 for a value, 4 for a pointer in a singly linked list.</p>
<p>Does this mean that a doubly linked list node is 12 bytes in memory with two pointers?</p>
<p>Also this book I'm reading talks about how theres 8 bytes of "overhead" for every 12 byte node, what does this re... | 0 | 2016-09-24T22:46:35Z | 39,681,668 | <p>First, you're evidently talking about a 32-bit machine since your pointers and values are 4 bytes. Obviously, that's different for a 64-bit machine.</p>
<p>Second, the value needn't be 4 bytes. Frequently the value is a pointer or an int, in which case it is 4 bytes (on your 32-bit machine). But if it was a doub... | 2 | 2016-09-24T22:50:23Z | [
"python",
"memory-management",
"linked-list"
] |
What does "overhead" memory refer to in the case of Linked Lists? | 39,681,639 | <p>I understand that a node is usually 8 bytes, 4 for a value, 4 for a pointer in a singly linked list.</p>
<p>Does this mean that a doubly linked list node is 12 bytes in memory with two pointers?</p>
<p>Also this book I'm reading talks about how theres 8 bytes of "overhead" for every 12 byte node, what does this re... | 0 | 2016-09-24T22:46:35Z | 39,681,696 | <blockquote>
<p>Does this mean that a doubly linked list node is 12 bytes in memory with two pointers?</p>
</blockquote>
<p>Yes, if the data is 4 bytes, and the code is compiled for 32bit and not 64bit, so 4 bytes per pointer.</p>
<blockquote>
<p>Also this book I'm reading talks about how theres 8 bytes of "overh... | 0 | 2016-09-24T22:54:29Z | [
"python",
"memory-management",
"linked-list"
] |
How to change text-align of float field in odoo 9 | 39,681,686 | <p>I got a float field in my model that left align when I put it in form view. My question is how to change it to right align.</p>
<p>I've tried so many ways to change its align to right but failed. I've tried to add <code>class="oe_right"</code>, create css custom module but not working. please help me</p>
<p><a hre... | 0 | 2016-09-24T22:52:43Z | 39,683,355 | <p>You can set text align right by give in-line style in particular field. Try following code.</p>
<p><strong>1. Right align of Float field</strong></p>
<pre><code><field name="field_name" style="text-align:right;"/>
</code></pre>
<p><strong>2. Right align of Float field value while edit mode</strong></p>
<p>... | 0 | 2016-09-25T04:24:49Z | [
"python",
"css",
"xml",
"openerp"
] |
Most efficient way to get average of all elements in list where each element occurs at least half as many times as the mode of the list | 39,681,725 | <p>I have a specific task to perform in python. Efficiency and speed are the most important here which is why I'm posting the question. </p>
<p>I need to get the average of items in a list, but only of the items that occur as least half as many times as the mode of the list occurs. </p>
<p>For instance if the list is... | 0 | 2016-09-24T22:57:40Z | 39,681,860 | <p>To get the mode of the list, you must iterate through the whole list at least once (Technically, you could stop as soon as the count of one of the elements is more than the remaining items in the list, but the efficiency is negligible).</p>
<p>Python has an efficient and easy way to do this with <code>Counter</code... | 1 | 2016-09-24T23:19:03Z | [
"python",
"list",
"numpy",
"average"
] |
Most efficient way to get average of all elements in list where each element occurs at least half as many times as the mode of the list | 39,681,725 | <p>I have a specific task to perform in python. Efficiency and speed are the most important here which is why I'm posting the question. </p>
<p>I need to get the average of items in a list, but only of the items that occur as least half as many times as the mode of the list occurs. </p>
<p>For instance if the list is... | 0 | 2016-09-24T22:57:40Z | 39,682,931 | <p>If you decide to use numpy, here's a concise method using <code>numpy.unique</code> and <code>numpy.average</code>:</p>
<pre><code>In [54]: x = np.array([1, 2, 2, 3, 4, 4, 4, 4])
In [55]: uniqx, counts = np.unique(x, return_counts=True)
In [56]: keep = counts >= 0.5*counts.max()
In [57]: np.average(uniqx[keep... | 1 | 2016-09-25T02:53:33Z | [
"python",
"list",
"numpy",
"average"
] |
Finding Top-K using Python & Hadoop Streaming | 39,681,761 | <p>So I have an output file from a previous job in this format (.txt file) </p>
<pre><code>" 145
"Defects," 1
"Information 1
"Plain 2
"Project 5
"Right 1
#51302] 1
$5,000) 1
& 3
'AS-IS', 1
( 1
("the 1
</code></pre>
<p>The left hand side of each line is the word that I read from the document an... | 1 | 2016-09-24T23:04:06Z | 39,688,276 | <p>You are almost on the right track. Consider your word as the Key and the count as the Value for your mapper task. If in your input file, you can get multiple entries for the same word and different count, then you can't take out top K from it. Then you shall have to aggregate the data and then find out top K . This ... | 0 | 2016-09-25T14:57:12Z | [
"python",
"python-2.7",
"hadoop",
"mapreduce",
"hadoop-streaming"
] |
How to set the default value of date field to Null ones a table entry is created and update it when a book is returned? | 39,681,798 | <p>How can I set the <code>date_in</code> field to <code>null</code> at the time of entry and update the value to the date book is returned. </p>
<pre><code>class Book_Loans(models.Model):
Loan_id = models.AutoField(primary_key=True)
Isbn = models.ForeignKey('Books')
Card_id = models.ForeignKey('Borrower')... | 1 | 2016-09-24T23:09:45Z | 39,682,002 | <p>Set <code>auto_now = False</code> and the field will remain empty when creating or updating an instance that doesn't specify a value for Date_in. You may also want to set <code>blank = True</code> if you need Date_in as an optional field on a form. </p>
| 1 | 2016-09-24T23:43:00Z | [
"python",
"django"
] |
Python turtle won't create multiple squares | 39,681,828 | <p>I tried to play around with this code many times but I can't create multiple squares. This is the problem:</p>
<p>Write a function named drawSquares that calls drawSquare to draw a
specified number of squares.
The function drawSquares takes four parameters: a turtle t, an integer size, an integer num, the number of... | 0 | 2016-09-24T23:14:29Z | 39,681,868 | <p>If I understand you correctly, this code should do exactly what you want:</p>
<pre><code>import turtle
s = turtle.Screen()
t = turtle.Turtle()
def drawSquares(t, size, num, angle):
for i in range(num):
for x in range(4):
turtle.forward(size)
turtle.left(90)
turtle.righ... | 0 | 2016-09-24T23:20:21Z | [
"python",
"turtle-graphics"
] |
How can I find the angle of a T shape in OpenCV | 39,681,837 | <p>I'm using OpenCV 2.4 to do some tracking, and I can get a contour of the shape I want, which is a T.</p>
<p>Input image:
<a href="http://i.stack.imgur.com/iQ6ZW.png" rel="nofollow"><img src="http://i.stack.imgur.com/iQ6ZW.png" alt="enter image description here"></a></p>
<p>I can use <code>cv2.minAreaRect(my_t_cont... | 1 | 2016-09-24T23:15:18Z | 39,687,023 | <p>As a variant you can use PCA, find first component direction, and use it as an searced angle. You can check here for an example: <a href="http://docs.opencv.org/trunk/d1/dee/tutorial_introduction_to_pca.html" rel="nofollow">http://docs.opencv.org/trunk/d1/dee/tutorial_introduction_to_pca.html</a></p>
| 1 | 2016-09-25T12:49:51Z | [
"python",
"opencv"
] |
How to ensure update() adds to end of dictionary | 39,681,839 | <p>I've read that <a href="http://stackoverflow.com/questions/20110627/print-original-input-order-of-dictionary-in-python">OrderedDict</a> can be used to keep information in a dictionary in order, but it seems to require that you input the information while instantiating the dictionary itself.</p>
<p>However, I need t... | 1 | 2016-09-24T23:15:25Z | 39,681,872 | <p>@Bob, please refer to the docs here. <a href="https://docs.python.org/3.5/library/collections.html?highlight=ordereddict#collections.OrderedDict" rel="nofollow">https://docs.python.org/3.5/library/collections.html?highlight=ordereddict#collections.OrderedDict</a></p>
<p>It says:</p>
<blockquote>
<p>The OrderedDi... | 0 | 2016-09-24T23:21:15Z | [
"python",
"dictionary"
] |
How to ensure update() adds to end of dictionary | 39,681,839 | <p>I've read that <a href="http://stackoverflow.com/questions/20110627/print-original-input-order-of-dictionary-in-python">OrderedDict</a> can be used to keep information in a dictionary in order, but it seems to require that you input the information while instantiating the dictionary itself.</p>
<p>However, I need t... | 1 | 2016-09-24T23:15:25Z | 39,681,874 | <p>Per the docs (<a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow">https://docs.python.org/2/library/collections.html#collections.OrderedDict</a>) you'll have to delete the entry before adding it.</p>
<p>You can wrap this in a subclass for convenience..:</p>
<pre><cod... | 3 | 2016-09-24T23:21:22Z | [
"python",
"dictionary"
] |
Python for Data Analysis error: Expecting value: line 1 column 1 (char 0) | 39,681,847 | <p>I am following along the examples of Python for Data Analysis and the first examples shows:</p>
<pre><code>In [15]: path = 'ch02/usagov_bitly_data2012-03-16-1331923249.txt'
In [16]: open(path).readline()
Out[16]: '{ "a": "Mozilla\\/5.0 (Windows NT 6.1; WOW64) AppleWebKit\\/535.11
(KHTML, like Gecko) Chrome\\/17.0.9... | -1 | 2016-09-24T23:16:59Z | 39,735,291 | <p>Sir, , It is not JSON format, I think that you should remove anomaly text '' or try some online format JSON to be more clear.</p>
| 0 | 2016-09-27T22:27:27Z | [
"python",
"data-analysis"
] |
Uncaught ReferenceError: rotateAnimation is not defined(anonymous function) | 39,681,924 | <p>please have patience for me, I am new at programming :)
I am testing Brython in browsers. I have this code for simple rotate image, in this case it's a cog.
I wan to use python and DOM to animate this image of cog.
This is the code:</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<!-- load Brytho... | 0 | 2016-09-24T23:30:59Z | 39,687,808 | <p>in line 14</p>
<pre><code> """ Helper function for determining the user agent """
</code></pre>
<p>to much space's</p>
<p>Should be</p>
<pre><code> """ Helper function for determining the user agent """
</code></pre>
| 0 | 2016-09-25T14:14:54Z | [
"javascript",
"python",
"html",
"dom",
"brython"
] |
Optimizing queries in Django, prefact_related for objects that are reversely linked | 39,682,035 | <p>In my django project I have 3 models, simplified for this example: Contact, WorkRelation and Group objects.</p>
<p><strong>Contact</strong></p>
<pre><code>class Contact(BaseModel):
title = models.CharField(max_length=30, blank=True)
initials = models.CharField(max_length=10, blank=True)
first_name = mo... | 0 | 2016-09-24T23:47:55Z | 39,684,414 | <p>Change your get_organisations code to this:</p>
<pre><code>def get_organisations(self):
return ', '.join(
workrelation.group.name for workrelation
in self.workrelation_set.all()
)
</code></pre>
<p>And use this query for fetching Contact objects:</p>
<pre><code>Contact.objects.prefetch_rela... | 1 | 2016-09-25T07:23:39Z | [
"python",
"django",
"django-queryset"
] |
Python extension module segfault | 39,682,074 | <p>I wrote a nifty fitter in C, and I want to provide an interface in python. So I wrote an extension module for it (below). However, when I run</p>
<pre><code>from nelder_mead import minimize
minimize(lambda x: x[0]**2, [42])
</code></pre>
<p>I get a segfault. I have no idea where to begin debugging, is the problem ... | 0 | 2016-09-24T23:55:59Z | 39,682,696 | <p>Turned out to be two small things. As @robyschek pointed out, I should have put <code>x[0]</code> instead of <code>x</code>, which caused a type error. Additionally, it turns out the argument parsing needs pointers to pointers:
changing it to <code>PyArg_ParseTuple(py_args, "OO", &py_func, &x0_list)</code> w... | 1 | 2016-09-25T01:56:26Z | [
"python",
"c",
"python-c-api"
] |
Using Pandas and Sklearn.Neighbors | 39,682,124 | <p>I'm trying to fit a KNN model on a dataframe, using Python 3.5/Pandas/Sklearn.neighbors. I've imported the data, split it into training and testing data and labels, but when I try to predict using it, I get the following error. I'm quite new to Pandas so any help would be appreciated, thanks!</p>
<p><a href="http:/... | 1 | 2016-09-25T00:04:10Z | 39,683,184 | <p>You should be using the <code>KNeighborsClassifier</code> for this KNN. You are trying to predict the label <code>Species</code> for classification. The regressor in your code above is trying to train and predict continuously valued numerical variables, which is where your problem is being introduced.</p>
<pre><cod... | 2 | 2016-09-25T03:46:05Z | [
"python",
"pandas",
"scikit-learn",
"python-3.5",
"sklearn-pandas"
] |
how to hash numpy arrays to check for duplicates | 39,682,192 | <p>I have searched around a bit for tutorials etc. to help with this problem but cant seem to find anything. </p>
<p>I have two lists of n-dimensional numpy arrays (3D array form of some images) and am wanting to check for overlapping images within each list. Lets says list a is a training set and list b is a valida... | 1 | 2016-09-25T00:18:30Z | 39,682,801 | <p>You can find duplicates between arrays using numpy's <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.intersect1d.html#numpy.intersect1d" rel="nofollow"><code>intersect1d</code></a> (one dimensional set intersect) function. </p>
<pre><code>duplicate_images = np.intersect1d(train_dataset, test_data... | 0 | 2016-09-25T02:21:57Z | [
"python",
"arrays",
"numpy",
"hash"
] |
how to hash numpy arrays to check for duplicates | 39,682,192 | <p>I have searched around a bit for tutorials etc. to help with this problem but cant seem to find anything. </p>
<p>I have two lists of n-dimensional numpy arrays (3D array form of some images) and am wanting to check for overlapping images within each list. Lets says list a is a training set and list b is a valida... | 1 | 2016-09-25T00:18:30Z | 39,690,707 | <p>The <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package (diclaimer: I am its author) has an efficient one-liner for this:</p>
<pre><code>import numpy_indexed as npi
duplicate_images = npi.intersection(train_dataset, test_dataset)
</code></pre>
<p>Plus a lot ... | 0 | 2016-09-25T19:05:31Z | [
"python",
"arrays",
"numpy",
"hash"
] |
how to hash numpy arrays to check for duplicates | 39,682,192 | <p>I have searched around a bit for tutorials etc. to help with this problem but cant seem to find anything. </p>
<p>I have two lists of n-dimensional numpy arrays (3D array form of some images) and am wanting to check for overlapping images within each list. Lets says list a is a training set and list b is a valida... | 1 | 2016-09-25T00:18:30Z | 39,692,548 | <p>It's not so difficult to come up with <em>something</em>:</p>
<pre><code>from collections import defaultdict
import numpy as np
def arrayhash(arr):
u = arr.view('u' + str(arr.itemsize))
return np.bitwise_xor.reduce(u.ravel())
def do_the_thing(a, b, hashfunc=arrayhash):
table = defaultdict(list)
fo... | 0 | 2016-09-25T22:48:20Z | [
"python",
"arrays",
"numpy",
"hash"
] |
Automated Inclusion of Objects in Python List | 39,682,201 | <p>I'm declaring a class, and in the <code>__init__</code> method, I'm declaring two variables which will be associated with an instance of that class. Each declared variable is initialised as a NumPy array of zeros that is later filled with other data.</p>
<p>At some point, outside of this <code>__init__</code> metho... | 0 | 2016-09-25T00:20:21Z | 39,682,301 | <p>Instead of creating a variable for each numpy array, why don't you just create a list of arrays containing each array you need, and reference them by index?</p>
<pre><code>class generic_class():
def __init__(self, array_length, array_widths=[]):
self.array_length = array_length
self.arrays = [
... | 1 | 2016-09-25T00:35:40Z | [
"python",
"list",
"numpy",
"dictionary",
"containers"
] |
why is pymongo requiring sudo to pip install? | 39,682,274 | <p>why is pymongo requiring sudo for install? Its docs don't mention anything about sudo...</p>
<pre><code>(myapp) cchilders:~/projects/app (master)
$ sudo pip3 uninstall pymongo
Successfully uninstalled pymongo-3.3.0
The directory '/home/cchilders/.cache/pip/http' or its parent directory is not owned by the curre... | 0 | 2016-09-25T00:32:17Z | 39,682,406 | <p>Check your virtual environment ownership. If your don't have write permission to that path, you will need <code>sudo</code></p>
| 1 | 2016-09-25T00:53:46Z | [
"python",
"mongodb",
"ubuntu",
"pip",
"pymongo"
] |
How to debug ctypes without error message | 39,682,318 | <p>I have a simple python script that uses a c/c++ library with <code>ctypes</code>. My c++ library also contains a main method, so I can compile it without the <code>-shared</code> flag and it can be excecuted and it runs without issues.</p>
<p>However, when I run the same code from a python script using <code>ctypes... | 0 | 2016-09-25T00:38:04Z | 39,682,494 | <p>Typically you begin from a small mock-up library that just lets you test the function calls from python. When this is ready (all the debug prints are ok) you proceed further. In your example, comment out #include "testapp.cpp" and get the prints to cout working.</p>
| 0 | 2016-09-25T01:09:18Z | [
"python",
"c++",
"ctypes"
] |
Replacing string element in for loop Python | 39,682,342 | <p>I am reading data in from a text file so each row is a list of strings, and all those lists are in a data list. So my lists look like:</p>
<pre><code>data = [row1, row2, etc.]
row1 = [str1, str2, etc.]
</code></pre>
<p>I am trying to remove any $ or % signs that appear in the strings in a row list. I have checked ... | 0 | 2016-09-25T00:43:44Z | 39,682,363 | <p>The problem is that your <em>str</em> variable is shadowing the builtin Python <a href="https://docs.python.org/2.7/library/functions.html#str" rel="nofollow"><em>str</em></a> variable. That fix is easy. Just use another variable name.</p>
<p>The second problem is that the replaced string isn't being replaced in ... | 1 | 2016-09-25T00:47:16Z | [
"python",
"python-2.7"
] |
Replacing string element in for loop Python | 39,682,342 | <p>I am reading data in from a text file so each row is a list of strings, and all those lists are in a data list. So my lists look like:</p>
<pre><code>data = [row1, row2, etc.]
row1 = [str1, str2, etc.]
</code></pre>
<p>I am trying to remove any $ or % signs that appear in the strings in a row list. I have checked ... | 0 | 2016-09-25T00:43:44Z | 39,682,381 | <p>You are assigning a new value to the name <code>x</code> but that does not change the contents of <code>row</code> or <code>data</code>. After changing <code>x</code>, you need to assign <code>row[j] = x</code> or <code>data[i][j] = x</code> for the appropriate column index <code>j</code> (and row index <code>i</c... | 0 | 2016-09-25T00:49:40Z | [
"python",
"python-2.7"
] |
Replacing string element in for loop Python | 39,682,342 | <p>I am reading data in from a text file so each row is a list of strings, and all those lists are in a data list. So my lists look like:</p>
<pre><code>data = [row1, row2, etc.]
row1 = [str1, str2, etc.]
</code></pre>
<p>I am trying to remove any $ or % signs that appear in the strings in a row list. I have checked ... | 0 | 2016-09-25T00:43:44Z | 39,682,637 | <p>Also in your in this case you can use list comprehension</p>
<pre><code>data = [[item.replace("%", "").replace("$", "0") for item in row] for row in data]
</code></pre>
| 0 | 2016-09-25T01:42:50Z | [
"python",
"python-2.7"
] |
Trying to convert Matlab .m symbolic function file(s) to SymPy symbolic expression | 39,682,366 | <p>I have computer generated .m files for electrical circuit transfer functions output by Sapwin 4.0
<a href="http://cirlab.dinfo.unifi.it/Sapwin4/" rel="nofollow">http://cirlab.dinfo.unifi.it/Sapwin4/</a></p>
<p>The .m files have fairly simple structure for my present interests:</p>
<pre class="lang-Matlab prettypri... | 1 | 2016-09-25T00:47:39Z | 39,682,578 | <p>Well, let's try to find the minimum failing case:</p>
<pre><code>>>> a=sympify('E1*C2')
Traceback (most recent call last):
[...]
TypeError: unsupported operand type(s) for *: 'function' and 'Symbol'
</code></pre>
<p>which makes it clear it's the E1 which is the problem here, because it's an <a href="http:... | 1 | 2016-09-25T01:30:50Z | [
"python",
"sympy"
] |
Exception when migrating custom User in Django | 39,682,431 | <p>I need to create a custom User for my app and followed exactly the <a href="https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#a-full-example" rel="nofollow">example</a> from the documentation with the <code>AUTH_USER_MODEL = 'core.MyUser'</code> in my <code>settings.py</code>. However, when I make a ne... | 0 | 2016-09-25T00:57:48Z | 39,684,159 | <p>You should not delete your migration folder. If you do that, django won't make migrations for you. Create migrations folder in your core app, create an empty <code>__init__.py</code> file inside it, remove your db.sqlite3 file, run ./manage.py makemigrations, and then migrate should work perfectly.</p>
| 1 | 2016-09-25T06:41:10Z | [
"python",
"django"
] |
Exception when migrating custom User in Django | 39,682,431 | <p>I need to create a custom User for my app and followed exactly the <a href="https://docs.djangoproject.com/en/1.10/topics/auth/customizing/#a-full-example" rel="nofollow">example</a> from the documentation with the <code>AUTH_USER_MODEL = 'core.MyUser'</code> in my <code>settings.py</code>. However, when I make a ne... | 0 | 2016-09-25T00:57:48Z | 39,684,429 | <p>Mehdi Pourfar's answer is correct.If you want to know more details </p>
<blockquote>
<p>By running makemigrations, youâre telling Django that youâve made some changes to your models (in this case, youâve made new ones) and that youâd like the changes to be stored as a migration.</p>
<p>Migrations are... | 0 | 2016-09-25T07:28:03Z | [
"python",
"django"
] |
I have afunction that works locally on my django app but deployed it raises an list index out of range error | 39,682,466 | <p>I have a function that raises an error in my logs when I try to use it remotely. I have it run in my background task. the other task I have runs both locally and remotely. heres my code</p>
<p>my my_scraps.py</p>
<pre><code>def liveleak_task():
url = 'http://www.example1.com/rss?featured=1'
name = 'live le... | 0 | 2016-09-25T01:04:31Z | 39,682,849 | <p>I have remedied the problem. I moved the [10] from where it was</p>
<pre><code> live_leaks = [i for i in feedparser.parse(url).entries]
the_count = len(live_leaks)
live_entries = [{'href': live_leak.links[0]['href'],
'src': live_leak.media_thumbnail[0]['url'],
'text': li... | 0 | 2016-09-25T02:33:42Z | [
"python",
"django",
"indexing",
"deployment",
"syntax"
] |
How to use Python to decrypt files encrypted using Vim's cryptmethod=blowfish2? | 39,682,512 | <p>I would like to use Python to decrypt files encrypted using Vim encrypted with the <a href="http://vim.wikia.com/wiki/Encryption" rel="nofollow"><code>cryptmethod=blowfish2</code></a> method. I have not seen the encryption method documented anywhere and would appreciate help in figuring out how to do this.</p>
<p>I... | 2 | 2016-09-25T01:14:20Z | 39,684,687 | <p>Check out this module: <a href="https://github.com/nlitsme/vimdecrypt" rel="nofollow">https://github.com/nlitsme/vimdecrypt</a>. You can use it to decrypt your files, or study the code to learn how to implement it yourself. Example usage:</p>
<pre><code>from collections import namedtuple
from vimdecrypt import decr... | 3 | 2016-09-25T08:04:47Z | [
"python",
"encryption",
"vim",
"blowfish"
] |
Can't extract data from beautiful_soup object | 39,682,561 | <p>I'm crawling a website(<a href="https://www.zhihu.com/people/xie-ke-41/followers" rel="nofollow">https://www.zhihu.com/people/xie-ke-41/followers</a>), and i want to get all the followers' information. As you can see, some followers' information is bring with AJAX, I use the developers' tool in chrome and locate the... | -1 | 2016-09-25T01:25:20Z | 39,682,824 | <p>You have used good header combination otherwise the server may not recognize your header and it thinks that you don't have javascript enabled. In limiting the attribute use . for class and # for id. Other CSS selectors will also work fine. You need also to use <a href="http://www.seleniumhq.org/" rel="nofollow">Sele... | -2 | 2016-09-25T02:27:02Z | [
"python",
"beautifulsoup",
"web-crawler"
] |
Can't extract data from beautiful_soup object | 39,682,561 | <p>I'm crawling a website(<a href="https://www.zhihu.com/people/xie-ke-41/followers" rel="nofollow">https://www.zhihu.com/people/xie-ke-41/followers</a>), and i want to get all the followers' information. As you can see, some followers' information is bring with AJAX, I use the developers' tool in chrome and locate the... | -1 | 2016-09-25T01:25:20Z | 39,685,633 | <p>The problem is you have escaped json, if you print the bsobj you can see output like:</p>
<pre><code>{"r":0,
"msg": ["<div class=\"zm-profile-card zm-profile-section-item zg-clear no-hovercard\">\n<div class=\"zg-right\">\n<button data-follow=\"m:button\" data-id=\"6327483c9e474097e7dbb2493a7f277c\"... | 1 | 2016-09-25T10:05:17Z | [
"python",
"beautifulsoup",
"web-crawler"
] |
Open a Datafile(csv,xls,xlsx,ods, etc) using "FILEPICKER" python? | 39,682,574 | <p>I got to know how to open a data file when we know the name and type of the file but how do we code to pick a file with file picker?</p>
<pre><code>import pyexcel as pe
records = pe.get_records(file_name="your_file.xls")
for record in records:
print("%s is aged at %d" % (record['Name'], record['Age']))
<... | 1 | 2016-09-25T01:29:14Z | 39,682,724 | <p>You can def a function to return the name of the function which you can use as input for pe.get_records().
<code>
from tkinter import *
root = Tk()
def get_file_name():
global root
root.filename = filedialog.askopenfilename(initialdir = "D:/",title = "choose your excel file",filetypes =... | 0 | 2016-09-25T02:05:11Z | [
"python",
"excel",
"csv",
"xls",
"filepicker"
] |
Open a Datafile(csv,xls,xlsx,ods, etc) using "FILEPICKER" python? | 39,682,574 | <p>I got to know how to open a data file when we know the name and type of the file but how do we code to pick a file with file picker?</p>
<pre><code>import pyexcel as pe
records = pe.get_records(file_name="your_file.xls")
for record in records:
print("%s is aged at %d" % (record['Name'], record['Age']))
<... | 1 | 2016-09-25T01:29:14Z | 40,046,532 | <p>I got the problem, Now this code runs!</p>
<pre><code>def loadCsv(self):
self.progressBar.setValue(0)
tab_table_view = QtGui.QWidget()
self.Tab.insertTab(0, tab_table_view, self.File_Name)
self.tableView = QtGui.QTableView(tab_table_view)
self.tableView.setGeometry(QtCore.QRect(0, 0, 721, 571... | 0 | 2016-10-14T15:12:49Z | [
"python",
"excel",
"csv",
"xls",
"filepicker"
] |
How to access variables from super? | 39,682,611 | <p>I need to get at some variables in a method called with <code>super</code> I would really like to do this instead of subclassing and then redefining the method...</p>
<pre><code>class Foo(object):
def bar(self):
x = 1
class SubFoo(Foo):
def bar(self):
print x
super(SubFoo, self).bar... | -1 | 2016-09-25T01:38:14Z | 39,682,642 | <p>There are two ways you can do this, either make x an instance attribute, or return x in your <code>Foo.bar</code> method. Below example makes use of assigning x as an instance attribute: </p>
<pre><code>class Foo(object):
def bar(self):
self.x = 1
class SubFoo(Foo):
def bar(self):
super(Su... | 4 | 2016-09-25T01:43:51Z | [
"python"
] |
How to instantly destory a frame after a certain program is run | 39,682,618 | <p>This code is used to display 2 buttons, which are both linked to definitions which launch other sections of code, and then close the windows. I need to be able to close the widget after the button has been clicked</p>
<pre><code>from tkinter import *
import tkinter
import sys
root = tkinter.Tk()
def cs_age():
... | 0 | 2016-09-25T01:39:07Z | 39,682,671 | <p>This really should be a comment not an answer but I don't have enough reputation for that yet.
Is this what you're looking for?
<a href="http://stackoverflow.com/questions/8009176/function-to-close-the-window-in-tkinter">Function to close the window in Tkinter</a></p>
| -1 | 2016-09-25T01:51:09Z | [
"python",
"tkinter"
] |
Capture more than one value from URL with Flask/Python | 39,682,641 | <p>I want to pass values to my Python script based on what button was clicked in the HTML. I can do it like this if there is only one value:</p>
<pre><code>@app.route('/', defaults={'category': ''})
@app.route('/<category>')
def index(category):
</code></pre>
<p>But altogether there are 3 values what I want to ... | 0 | 2016-09-25T01:43:31Z | 39,682,672 | <p>You can use <code>request.args</code> for query string parameters, which will be optional:</p>
<pre><code>@app.route('/')
def index():
category = request.args.get('category', '')
attr1 = request.args.get('attr1')
attr2 = request.args.get('attr2')
</code></pre>
<p><code>request.args</code> is a dict (mo... | 1 | 2016-09-25T01:51:19Z | [
"python",
"flask"
] |
Capture more than one value from URL with Flask/Python | 39,682,641 | <p>I want to pass values to my Python script based on what button was clicked in the HTML. I can do it like this if there is only one value:</p>
<pre><code>@app.route('/', defaults={'category': ''})
@app.route('/<category>')
def index(category):
</code></pre>
<p>But altogether there are 3 values what I want to ... | 0 | 2016-09-25T01:43:31Z | 39,682,674 | <p>You can set more than 1 variable in your routing/function:</p>
<pre><code>@app.route('/', defaults={'category': '', 'var2': '', 'var3': ''})
@app.route('/<category>/<var2>/<var3>')
def index(category, var2, var3):
</code></pre>
| 0 | 2016-09-25T01:51:25Z | [
"python",
"flask"
] |
How to set PYTHONPATH to multiple folders | 39,682,688 | <p>In <code>~/.bash_profile</code> file (OS X) I've set PYTHONPATH to point to two folders:</p>
<pre><code>export PYTHONPATH=/Applications/python/common:$PYTHONPATH
export PYTHONPATH=/Applications/sitecustomize:$PYTHONPATH
</code></pre>
<p>Even while <code>sitecustomize</code> folder is set on a second line (after <c... | 2 | 2016-09-25T01:53:46Z | 39,682,723 | <p>Append your paths so there is only one PYTHONPATH. </p>
<pre><code>PYTHONPATH="/Applications/python/common:/Applications/sitecustomize:$PYTHONPATH"
export PYTHONPATH
</code></pre>
<p>Then <code>source ~/.bash_profile</code></p>
<p>OR import them into your Python script (this would only work for the script added ... | 0 | 2016-09-25T02:05:10Z | [
"python",
"bash"
] |
Code Not Converging Vanilla Gradient Descent | 39,682,732 | <p>I have a specific analytical gradient I am using to calculate my cost f(x,y), and gradients dx and dy. It runs, but I can't tell if my gradient descent is broken. Should I plot my partial derivatives x and y?</p>
<pre><code>import math
gamma = 0.00001 # learning rate
iterations = 10000 #steps
theta = np.array([0,5... | 0 | 2016-09-25T02:07:34Z | 39,689,425 | <p>I strongly recommend you check whether or not your analytic gradient is working correcly by first evaluating it against a numerical gradient.
I.e make sure that your f'(x) = (f(x+h) - f(x)) / h for some small h.</p>
<p>After that, make sure your updates are actually in the right direction by picking a point where y... | 2 | 2016-09-25T16:54:26Z | [
"python",
"machine-learning",
"gradient-descent"
] |
Django ORM: Models with 2 table referencing each other | 39,682,811 | <p>I have 2 tables. User and Group. 1:Many relationship. Each user can only belong to a single group. </p>
<p>here's the model.py. </p>
<pre><code>class Group(models.Model):
group_name = models.CharField(max_length=150, blank=True, null=True)
group_description = models.TextField(blank=True, null=True)
gro... | 0 | 2016-09-25T02:23:44Z | 39,682,894 | <p>Add <code>related_name</code> to your <strong>ForeignKey</strong> fields:</p>
<pre><code>class Group(models.Model):
group_name = models.CharField(max_length=150, blank=True, null=True)
group_description = models.TextField(blank=True, null=True)
group_creator = models.ForeignKey('User',related_name='myUs... | 0 | 2016-09-25T02:44:52Z | [
"python",
"mysql",
"django"
] |
Django ORM: Models with 2 table referencing each other | 39,682,811 | <p>I have 2 tables. User and Group. 1:Many relationship. Each user can only belong to a single group. </p>
<p>here's the model.py. </p>
<pre><code>class Group(models.Model):
group_name = models.CharField(max_length=150, blank=True, null=True)
group_description = models.TextField(blank=True, null=True)
gro... | 0 | 2016-09-25T02:23:44Z | 39,683,975 | <p>as Pourfar mentioned in a comment, you may avoid the <code>NameError</code> via the quoting the model object as string. also it is safe to set <code>related_name</code> for accessing this relation.</p>
<pre><code>class Group(models.Model):
...
group_creator = models.ForeignKey('User', related_name='creator_... | 1 | 2016-09-25T06:11:08Z | [
"python",
"mysql",
"django"
] |
TM1 REST API Python Requests ConnectionResetError MaxRetryError ProxyError but JavaScript/jQuery Works | 39,682,812 | <p>I am trying to run a get request using the TM1 REST API and Python Requests but receive a ConnectionResetError / MaxRetryError / ProxyError. Here is my code:</p>
<pre><code>headers = {'Accept' : 'application/json; charset=utf-8',
'Content-Type': 'text/plain; charset=utf-8'
}
login = b64enc... | 1 | 2016-09-25T02:23:58Z | 39,733,432 | <p>A couple of people at work helped me solve my problem. The http and https proxies that I had set in my environment variables were causing the issue. I removed them / restarted / and was then able to query the api.</p>
| 0 | 2016-09-27T20:08:21Z | [
"jquery",
"python",
"rest",
"python-requests",
"cognos-tm1"
] |
Is it possible to access a local variable in another function? | 39,682,842 | <p>Goal: Need to use local variable in another function. Is that possible in Python?</p>
<p>I would like to use the local variable in some other function. Because in my case I need to use a counter to see the number of connections happening and number of connections releasing/ For that I am maintaining a counter. To i... | 0 | 2016-09-25T02:32:22Z | 39,682,956 | <p>As I know, you can't get access to local variable outside function. But even you can in my opinion it will be a bad practice.</p>
<p>Why not use function or class.</p>
<pre><code>connections = 0
def set_connection_number(value):
global connections; connections = value;
def get_connection_number():
global... | 0 | 2016-09-25T02:59:26Z | [
"python",
"python-2.7",
"python-3.x"
] |
Is it possible to access a local variable in another function? | 39,682,842 | <p>Goal: Need to use local variable in another function. Is that possible in Python?</p>
<p>I would like to use the local variable in some other function. Because in my case I need to use a counter to see the number of connections happening and number of connections releasing/ For that I am maintaining a counter. To i... | 0 | 2016-09-25T02:32:22Z | 39,683,843 | <p>There are different ways to access the local scope of a function. You can return the whole local scope if you want by calling <code>locals()</code> this will give you the entire local scope of a function, it's atypical to save the local scope. For your functions you can save the variables that you need in the functi... | 1 | 2016-09-25T05:52:18Z | [
"python",
"python-2.7",
"python-3.x"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.