title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags listlengths 1 5 |
|---|---|---|---|---|---|---|---|---|---|
While loop on click | 38,257,496 | <p>Designing a control graphics window and need it to repeat as long as the window is being clicked in.</p>
<p>Here is the code for the object to be repeated</p>
<pre><code># Limit the bounds of the buttons
def moveBob():
if 80<x<120 and 10<y<50:
moveForward= Bob.move(0,-20)
if 80<x<... | -2 | 2016-07-08T01:03:24Z | 38,257,762 | <p>Moving the statements into the while loop solved it ie:</p>
<pre><code>while True:
point= Control.getMouse()
x= point.getX()
y= point.getY()
moveBob()
</code></pre>
| 0 | 2016-07-08T01:39:01Z | [
"python",
"graphics"
] |
How does python print or save big data without ellipsis? | 38,257,550 | <p>I need to print or save a list with big data completely while I only can print partial data. The specific condition is like the picture.</p>
<p><a href="http://i.stack.imgur.com/y67FI.jpg" rel="nofollow">the situation of python print</a></p>
<h2>When I try to save this data, I can only save partial data too.But no... | -3 | 2016-07-08T01:10:31Z | 38,258,006 | <p>Use <code>np.savetxt</code>:</p>
<pre><code>b = np.zeros((10000, 10000))
np.savetxt('output.txt', b)
</code></pre>
<p>So that you can get the exact format that you want, <code>savetxt</code> has many options. You can read about them <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html" ... | 0 | 2016-07-08T02:17:19Z | [
"python",
"printing"
] |
Replace values in masked numpy array not working | 38,257,585 | <p>I have the foll. masked array in numpy called arr with shape (50, 360, 720):</p>
<pre><code>masked_array(data =
[[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]
...,
[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]
[-- -- -- ..., -- -- --]],
mask =
[[ True True Tr... | 0 | 2016-07-08T01:15:56Z | 38,257,970 | <p>Maybe you want <code>filled</code>. I'll illustrate:</p>
<pre><code>In [702]: x=np.arange(10)
In [703]: xm=np.ma.masked_greater(x,5)
In [704]: xm
Out[704]:
masked_array(data = [0 1 2 3 4 5 -- -- -- --],
mask = [False False False False False False True True True True],
fill_value = 999... | 1 | 2016-07-08T02:12:22Z | [
"python",
"numpy",
"masked-array"
] |
How to monkey patch python list __setitem__ method | 38,257,613 | <p>I'd like to monkey-patch Python lists, in particular, replacing the <code>__setitem__</code> method with custom code. Note that I am not trying to <em>extend</em>, but to <em>overwrite</em> the builtin types. For example:</p>
<pre class="lang-py prettyprint-override"><code>>>> # Monkey Patch
... # Replac... | 4 | 2016-07-08T01:19:42Z | 38,257,902 | <p>Can't be done. If you do force that using CTypes, you will just crash the Python runtime faster than anything else - as many things itnernally just make use of Python data types.</p>
| 0 | 2016-07-08T02:02:02Z | [
"python",
"ctypes",
"introspection"
] |
ValueError: x and y must have the same first dimension | 38,257,616 | <p>I am trying to implement a finite difference approximation to solve the Heat Equation, <code>u_t = k * u_{xx}</code>, in Python using NumPy.</p>
<p>Here is a copy of the code I am running:</p>
<pre><code> ## This program is to implement a Finite Difference method approximation
## to solve the Heat Equation, u_t... | 0 | 2016-07-08T01:20:13Z | 38,257,885 | <p>Okay so I had a "brain dump" and tried plotting <code>u</code> vs. <code>t</code> sort of forgetting that <code>u</code>, being the solution to the Heat Equation (<code>u_t = k * u_{xx}</code>), is defined as <code>u(x,t)</code> so it has values for time. I made the following correction to my code:</p>
<pre><code>p... | 0 | 2016-07-08T01:59:34Z | [
"python",
"numpy",
"matplotlib",
"compiler-errors"
] |
Comparing different column values at different row numbers of a dataframe | 38,257,620 | <p>I am still new to python and pandas and still trying to learn. Trying to use Pandas for a complex scenario. below is a small sample of my dataframe</p>
<pre><code> In [9]: df
Out[9]:
TXN_KEY Send_Agent Pay_Agent Send_Customer /
0 13272184 AWD120279 AEU002152 1000000000021979638
1 132729... | 0 | 2016-07-08T01:21:39Z | 38,338,192 | <p>Splitting the dataframe from send side and Pay side and performing inner joins gave me the desired output.</p>
| 0 | 2016-07-12T20:19:01Z | [
"python",
"pandas"
] |
Syntax error from list comprehension with a conditional | 38,257,664 | <p>I am using a library (pymatgen) in which a enum Orbital is defined. Each element can be defined as an OrbitalType. There are several flavors of orbital types which are defined by the letters s, p, d, and f. The following code works fine.</p>
<pre><code>In [35]: myorbitals = []
In [36]: for orbital in Orbital:
.... | 0 | 2016-07-08T01:27:31Z | 38,257,681 | <p>The right syntax should be:</p>
<pre><code>myarray = [orbital for orbital in Orbital if orbital.orbital_type == OrbitalType.d]
</code></pre>
| 1 | 2016-07-08T01:29:14Z | [
"python",
"list",
"python-2.7",
"list-comprehension"
] |
Python List Column Move | 38,257,687 | <p>I'm trying to move the second value in a list to the third value in a list for each nested list. I tried the below, but it's not working as expected.</p>
<p><strong>Code</strong></p>
<pre><code>List = [['a','b','c','d'],['a','b','c','d'],['a','b','c','d']]
print(List)
col_out = [List.pop(1) for col in List]
col_i... | 4 | 2016-07-08T01:29:54Z | 38,257,753 | <pre><code>[List.insert(2,List) for col in col_out]
^^^^ -- See below.
</code></pre>
<p>You are inserting an entire list as an element within the same list. Think recursion!</p>
<hr>
<p>Also, please refrain from using state-changing expressions in list comprehension. A list comprehension should <stron... | 2 | 2016-07-08T01:38:00Z | [
"python",
"python-3.x",
"list-comprehension"
] |
Python List Column Move | 38,257,687 | <p>I'm trying to move the second value in a list to the third value in a list for each nested list. I tried the below, but it's not working as expected.</p>
<p><strong>Code</strong></p>
<pre><code>List = [['a','b','c','d'],['a','b','c','d'],['a','b','c','d']]
print(List)
col_out = [List.pop(1) for col in List]
col_i... | 4 | 2016-07-08T01:29:54Z | 38,257,807 | <p>You can do it like this</p>
<pre><code>myList = [['a','b','c','d'],['a','b','c','d'],['a','b','c','d']]
myOrder = [0,2,1,3]
myList = [[sublist[i] for i in myOrder] for sublist in myList]
</code></pre>
| 0 | 2016-07-08T01:47:09Z | [
"python",
"python-3.x",
"list-comprehension"
] |
Numpy: Flatten some columns of an 2 D array | 38,257,706 | <p>Suppose I have a numpy array as below</p>
<pre><code>a = np.asarray([[1,2,3],[1,4,3],[2,5,4],[2,7,5]])
array([[1, 2, 3],
[1, 4, 3],
[2, 5, 4],
[2, 7, 5]])
</code></pre>
<p>How can I flatten column 2 and 3 for each unique element in column 1 like below:</p>
<pre><code>array([[1, 2, 3, 4, 3],
... | 2 | 2016-07-08T01:32:13Z | 38,257,910 | <pre><code>import numpy as np
a = np.asarray([[1,2,3],[1,4,3],[2,5,4],[2,7,5]])
d = {}
for row in a:
d[row[0]] = np.concatenate( (d.get(row[0], []), row[1:]) )
r = np.array([np.concatenate(([key], d[key])) for key in d])
print(r)
</code></pre>
<p>This prints:</p>
<pre><code>[[ 1. 2. 3. 4. 3.]
[ 2. 5. 4. ... | 2 | 2016-07-08T02:03:18Z | [
"python",
"numpy"
] |
Numpy: Flatten some columns of an 2 D array | 38,257,706 | <p>Suppose I have a numpy array as below</p>
<pre><code>a = np.asarray([[1,2,3],[1,4,3],[2,5,4],[2,7,5]])
array([[1, 2, 3],
[1, 4, 3],
[2, 5, 4],
[2, 7, 5]])
</code></pre>
<p>How can I flatten column 2 and 3 for each unique element in column 1 like below:</p>
<pre><code>array([[1, 2, 3, 4, 3],
... | 2 | 2016-07-08T01:32:13Z | 38,257,919 | <p>Another option using list comprehension:</p>
<pre><code>np.array([np.insert(a[a[:,0] == k, 1:].flatten(), 0, k) for k in np.unique(a[:,0])])
# array([[1, 2, 3, 4, 3],
# [2, 5, 4, 7, 5]])
</code></pre>
| 3 | 2016-07-08T02:04:25Z | [
"python",
"numpy"
] |
Numpy: Flatten some columns of an 2 D array | 38,257,706 | <p>Suppose I have a numpy array as below</p>
<pre><code>a = np.asarray([[1,2,3],[1,4,3],[2,5,4],[2,7,5]])
array([[1, 2, 3],
[1, 4, 3],
[2, 5, 4],
[2, 7, 5]])
</code></pre>
<p>How can I flatten column 2 and 3 for each unique element in column 1 like below:</p>
<pre><code>array([[1, 2, 3, 4, 3],
... | 2 | 2016-07-08T01:32:13Z | 38,259,185 | <p>Since as posted in the comments, we know that each unique element in <code>column-0</code> would have a fixed number of rows and by which I assumed it was meant same number of rows, we can use a vectorized approach to solve the case. We sort the rows based on <code>column-0</code> and look for shifts along it, which... | 0 | 2016-07-08T05:01:34Z | [
"python",
"numpy"
] |
Python 2.7 The 'packaging' package is required; normally this is bundled with this package | 38,257,738 | <p>I expect this has to do with the cryptography module, but I'm not sure.</p>
<pre><code>Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\load
er\pyi_importers.py", line 270, in load_module
exec(bytec... | 0 | 2016-07-08T01:36:42Z | 38,257,927 | <p>Updated with the newest version of pyinstaller, it's now working.</p>
| 0 | 2016-07-08T02:06:11Z | [
"python",
"cryptography",
"pyinstaller"
] |
Python 2.7 The 'packaging' package is required; normally this is bundled with this package | 38,257,738 | <p>I expect this has to do with the cryptography module, but I'm not sure.</p>
<pre><code>Traceback (most recent call last):
File "<string>", line 11, in <module>
File "c:\python27\lib\site-packages\PyInstaller-2.1-py2.7.egg\PyInstaller\load
er\pyi_importers.py", line 270, in load_module
exec(bytec... | 0 | 2016-07-08T01:36:42Z | 39,604,213 | <p>Try this</p>
<pre><code>pip uninstall setuptools
pip install setuptools==19.2
</code></pre>
| 0 | 2016-09-20T21:45:10Z | [
"python",
"cryptography",
"pyinstaller"
] |
Pymongo Regex match with list | 38,257,841 | <p>I have a list of distinct strings. </p>
<pre><code>lst = ['.\*123.\*','.\*252.\*','.\*812.\*','.\*135.\*']
</code></pre>
<p>I want to perform an aggregation operation such that my $match looks like the following:</p>
<pre><code> {"$match":{"Var":{"$in":lst}}}
</code></pre>
<p>The var field in MongoDb records ... | 0 | 2016-07-08T01:53:31Z | 38,258,013 | <p>Your list comprehension is wrong. I reckon what you wanted to do is this:</p>
<pre><code>[re.compile(x) for x in lst]
</code></pre>
<p>That <code>TypeError</code> comes from trying to pass generator(<code>x for x in lst</code> statement) to <code>re.compile()</code></p>
| 2 | 2016-07-08T02:17:59Z | [
"python",
"regex",
"mongodb",
"pymongo"
] |
Why are only the first and last items of my list being written to file? | 38,257,865 | <p>I've written my very first webscraper, and I am now attempting to write the data to excel files. </p>
<p>This is the relevant part of my program: </p>
<pre><code>with xlsxwriter.Workbook('test 2.xlsx') as workbook:
worksheet = workbook.add_worksheet("Doctissimo's diabetes sub-forum")
row = 0
col = 0
... | 0 | 2016-07-08T01:56:36Z | 38,258,166 | <p>One way to systematically find some bug is to use the print statement, row are supposed to be increased by 1 every loop, if you put a print statement after row, you should be able to see what is wrong.</p>
<pre><code>row = +1
print "row = %d" % row
</code></pre>
<p>I did not see = +1 at the first time. But the val... | 0 | 2016-07-08T02:40:32Z | [
"python",
"web-scraping",
"xlsx",
"xlsxwriter"
] |
Dynamic radio buttons from database query using Flask and WTForms | 38,258,011 | <p>I have experience with PHP but im new to Flask and Python and I need help with a simple thing.</p>
<p>I have a database table and I need each entry in a radio button. I need to use WTForms but I can't do it. The id should be the value and the botname should be the label.</p>
<p>This is my table:</p>
<pre><code>cl... | 1 | 2016-07-08T02:17:57Z | 38,261,205 | <p>Since you are setting the choices dynamically, don't declare them when defining your form. Instead, in your view function, you need to instantiate the form like this (the below is untested):</p>
<pre><code>form = SimpleForm()
form.example.choices = [(probot.id, probot.botname) for probot in Probot.query.all()]
</c... | 0 | 2016-07-08T07:32:09Z | [
"python",
"flask",
"sqlalchemy",
"jinja2",
"wtforms"
] |
tensorflow How to restore a graph from meta and place it on a different device | 38,258,121 | <p>How can i just restore the structure from the meta graph file, and then ONLY change the device it was placed on for a deployment use ?</p>
<p>I have started several different training process with a same python script but in different configurable params like: unit size, layer number, Cell type(LSTM or GRU) ... whi... | 0 | 2016-07-08T02:33:44Z | 38,261,594 | <p>The <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/tools/freeze_graph.py" rel="nofollow"><code>freeze_graph</code></a> function can export your model in a protobuf file. This function has the parameter <code>clear_devices</code> that can be set to <code>True</code> to remove from the... | 2 | 2016-07-08T07:55:06Z | [
"python",
"graph",
"tensorflow",
"meta"
] |
How can I reference a function defined in another iPython notebook cell, within the same notebook? | 38,258,174 | <p>Suppose I've made a notebook in Jupyter, containing several different cells.</p>
<p>In the first cell, I define a self-contained Python module, with a number of useful functions.</p>
<p>In the second cell, I would like to write a program that uses the module defined in the first cell.</p>
<p>However, since the fi... | 0 | 2016-07-08T02:42:07Z | 38,259,154 | <p>You can keep everything within the same Jupyter Notebook.
In this case, your first cell would be a <code>class</code> with a number of useful functions or <code>methods</code>. In the second cell, you could create an instance of this class and go about using these <code>methods</code>.</p>
<p><a href="https://jeffk... | 0 | 2016-07-08T04:58:16Z | [
"python",
"ipython-notebook",
"jupyter-notebook"
] |
Suspected pyparsing longest match error | 38,258,218 | <p>I am developing a parser for the DOT language and am having problems with "subgraph" statements.</p>
<p>I have no problems getting my SUBGRAPH parse expression working correctly (see fragment below) however when I add it as an alternative in STMT it fails to match.</p>
<p><strong>Simple test:</strong></p>
<pre><c... | 2 | 2016-07-08T02:49:16Z | 38,299,230 | <p>This is because you're creating a <em>copy</em> of the <code>SUBGRAPH</code> object in this line:</p>
<pre><code>STMT = NODE_STMT("NODE") ^ SUBGRAPH("SUBGRAPH")
</code></pre>
<p>Calling <code>setResultsName()</code>, which the call syntax is a shortcut for, <a href="https://pythonhosted.org/pyparsing/pyparsing.Par... | 1 | 2016-07-11T04:34:18Z | [
"python",
"parsing",
"pyparsing"
] |
Suspected pyparsing longest match error | 38,258,218 | <p>I am developing a parser for the DOT language and am having problems with "subgraph" statements.</p>
<p>I have no problems getting my SUBGRAPH parse expression working correctly (see fragment below) however when I add it as an alternative in STMT it fails to match.</p>
<p><strong>Simple test:</strong></p>
<pre><c... | 2 | 2016-07-08T02:49:16Z | 38,326,873 | <p>In general, I recommend holding off on assigning results names until expressions are being assembled into a higher-level expression, like this:</p>
<pre><code>intnum = Word(nums).setParseAction(lambda t: int(t[0]))
realnum = Combine(Word(nums) + '.' + Word(nums)).setParseAction(lambda t: float(t[0]))
hostname = Wor... | 0 | 2016-07-12T10:56:16Z | [
"python",
"parsing",
"pyparsing"
] |
Can I make this work without global variables? | 38,258,257 | <h1>library.py</h1>
<pre><code>str = ''
def setStr(input):
global str
str = input
def getStr():
return str
</code></pre>
<p>Now I can import in modules and update them...</p>
<h1>module1.py</h1>
<pre><code>import library
import module2
library.setStr('wow')
module2.run()
</code></pre>
<h1>module2.py</h1... | -3 | 2016-07-08T02:53:51Z | 38,258,525 | <blockquote>
<p>So how do I replicate the way logging works but without global variables for my purposes?</p>
</blockquote>
<p>You can't, because <a href="https://hg.python.org/cpython/file/tip/Lib/logging/__init__.py" rel="nofollow"><code>logging</code> uses global (module-level) variables to store its configuratio... | 0 | 2016-07-08T03:31:33Z | [
"python",
"logging",
"import",
"static",
"global"
] |
passing array as parameter of RunPython script in VBA (xlwings) | 38,258,343 | <p>In my VBA sub, I'm calling a python script using the command RunPython from xlwings. I would like to call a function that takes an array as parameter. How can I convert the VBA data type into a list readable by Python? </p>
<p>Code:</p>
<pre><code>RunPython("import script; script.query(dates=argsArray, queryString... | 1 | 2016-07-08T03:06:32Z | 38,258,657 | <p>Have a look at converters. </p>
<p><a href="http://docs.xlwings.org/en/stable/converters.html?highlight=array" rel="nofollow">http://docs.xlwings.org/en/stable/converters.html?highlight=array</a></p>
<p>What you can do is pass the Range address as a string and then get the values as as an array. From the document... | 0 | 2016-07-08T03:52:13Z | [
"python",
"arrays",
"excel",
"vba",
"xlwings"
] |
syntax error related to this code. Have tried looking it up but not helping | 38,258,367 | <p>I am trying to create a resistance calculator program but I am getting a syntax error.</p>
<pre><code>print("Welcome to resistance calculator!!!")
import time
import math
time.sleep(2)
powersource=int(input("How many volts is your battery?"))
time.sleep(2)
convertquestion=input("Is your amps in milaamps?")
time.sle... | -3 | 2016-07-08T03:09:33Z | 38,258,442 | <p>You've got an extra parentheses at line 14. Change it to this:</p>
<pre><code>forwardvolt=float(input("What is your forward voltage?"))
</code></pre>
| 0 | 2016-07-08T03:20:36Z | [
"python",
"syntax-error"
] |
How to set a default value for a relationship in SQLAlchemy? | 38,258,389 | <p>I have the following relationship field in my User model for a Flask-SQLAlchemy project and I want to be able to set a default value so that users are automatically following themselves. Is there a way to set a default value in relationships in SQLAlchemy at all? What would that look like? </p>
<pre><code>followed ... | 0 | 2016-07-08T03:13:16Z | 38,260,842 | <p>your User Model add new method.</p>
<pre><code>@staticmethod
def follow():
if not user.is_following(user):
user.follow(user)
db.session.add(user)
db.session.commit()
</code></pre>
| 1 | 2016-07-08T07:10:07Z | [
"python",
"database-design",
"sqlalchemy",
"relationship",
"flask-sqlalchemy"
] |
How do I insert Start and End date and times for Outlook Calendar API call | 38,258,407 | <p>I'm using Microsoft's sample Django app and trying to read calendar events from now back to 1 year ago. The API request is done using Python Request functions:</p>
<pre><code>response = requests.get(url, headers = headers, params = parameters)
</code></pre>
<p>Header is standard API request related:</p>
<pre><cod... | 1 | 2016-07-08T03:16:09Z | 38,271,960 | <p>In order to use the <code>startDateTime</code> and <code>endDateTime</code> parameters to limit the date range, you need to do a <code>GET</code> on the <code>/calendarview</code> endpoint, not <code>/events</code>. The <code>/events</code> endpoint doesn't support those parameters.</p>
<p>Change your <code>url</c... | 0 | 2016-07-08T16:56:03Z | [
"python",
"django",
"outlook",
"office365",
"outlook-restapi"
] |
Tornado concurrency limited to 6 connections? | 38,258,466 | <p>I have the following "dummy server" running:</p>
<pre><code>import tornado.web
from tornado.ioloop import IOLoop
from tornado import gen
import time
@gen.coroutine
def async_sleep(seconds):
yield gen.Task(IOLoop.instance().add_timeout, time.time() + seconds)
class TestHandler(tornado.web.RequestHandler):
... | 0 | 2016-07-08T03:23:49Z | 38,265,722 | <p>I think it's a combination of two things:</p>
<ol>
<li><p>The browser is limiting the number of connections to the server (<a href="http://www.tornadoweb.org/en/stable/faq.html#my-code-is-asynchronous-but-it-s-not-running-in-parallel-in-two-browser-tabs" rel="nofollow">see the FAQ</a>). If you use separate browsers... | 2 | 2016-07-08T11:40:18Z | [
"python",
"python-3.x",
"tornado"
] |
Why doesn't my variable value get passed to the finally block in python | 38,258,519 | <p>This is for python 2.7.10
Perhaps I'm not using the try..except..finally block correctly. </p>
<p>I need to check on the HTTP response code I get from a webpage.
If I get a 200 code, everything is working. If I get any other code, report what code.</p>
<p>It works fine if I get a 200 HTTP code.
If I get an excep... | 0 | 2016-07-08T03:31:09Z | 38,258,556 | <p>If an exception happens, then the assignment statement (<code>resp = conn.getresponse().status</code>) either never runs or never finishes.<sup>1</sup> In that case, when the <code>finally</code> clause runs, you'll get an error because <code>resp</code> was never set to anything.</p>
<p>Based on the usage, it <em... | 8 | 2016-07-08T03:35:31Z | [
"python",
"python-2.7",
"exception",
"httplib"
] |
Why doesn't my variable value get passed to the finally block in python | 38,258,519 | <p>This is for python 2.7.10
Perhaps I'm not using the try..except..finally block correctly. </p>
<p>I need to check on the HTTP response code I get from a webpage.
If I get a 200 code, everything is working. If I get any other code, report what code.</p>
<p>It works fine if I get a 200 HTTP code.
If I get an excep... | 0 | 2016-07-08T03:31:09Z | 38,261,395 | <p>The solution is assign None to "resp" before "try" clause.Like this below.</p>
<pre><code>resp = None
try:
</code></pre>
<p>When you run conn.request("GET", "/alive"), this may cause an Exception if timeout,then your code will enter "except" and then "finally" clause.But the variable haven't assigned,so it goes wr... | 1 | 2016-07-08T07:42:50Z | [
"python",
"python-2.7",
"exception",
"httplib"
] |
Taking a while for website to return 500 Internal server error | 38,258,637 | <p>This is a followup question to <a href="http://stackoverflow.com/questions/38258519/why-doesnt-my-variable-value-get-passed-to-the-finally-block-in-python/">my other question here on stack</a>.</p>
<p>Not sure if this is a problem with play or this is normal results for a webserver. I am using play 2.1.2</p>
<p>I... | 1 | 2016-07-08T03:49:34Z | 38,747,399 | <p>When you use <code>play run</code>, your app will be started in dev mode. In this mode , the app itself will only really start when it gets the first request. Sometimes it happens that, even after the server is started and should be ready to accept requests, Play detects that something has changed and recompiles som... | 1 | 2016-08-03T15:09:18Z | [
"python",
"python-2.7",
"http",
"playframework",
"httplib"
] |
tuple index out of range error related to curselection (tkinter) | 38,258,745 | <p>I have this list:</p>
<pre><code>lista=Listbox(root,selectmode=MULTIPLE)
lista.grid(column=0,row=1)
lista.config(width=40, height=4)
lista.bind('<<ListboxSelect>>',selecionado)
</code></pre>
<p>Attached to this function:</p>
<pre><code>def selecio... | 2 | 2016-07-08T04:03:37Z | 38,259,137 | <p>When you deselect the item, the function curselection() returns an empty tuple. When you try to access element [0] on an empty tuple you get an index out of range error. The solution is to test for this condition.</p>
<pre><code>def selecionado(evt):
global ativo
a=evt.widget
b=a.curselection()
if... | 3 | 2016-07-08T04:56:10Z | [
"python",
"tkinter",
"listbox"
] |
tuple index out of range error related to curselection (tkinter) | 38,258,745 | <p>I have this list:</p>
<pre><code>lista=Listbox(root,selectmode=MULTIPLE)
lista.grid(column=0,row=1)
lista.config(width=40, height=4)
lista.bind('<<ListboxSelect>>',selecionado)
</code></pre>
<p>Attached to this function:</p>
<pre><code>def selecio... | 2 | 2016-07-08T04:03:37Z | 38,259,632 | <p>The @PaulComelius answer is correct, I am giving a variant of the solution with useful notes:</p>
<p>First note is that only <strong>Tkinter 1.160</strong> and earlier versions causes the list returned by curselection() to be a list of strings instead of integers. This means you are running <strong>useless</stron... | 2 | 2016-07-08T05:44:18Z | [
"python",
"tkinter",
"listbox"
] |
Error when creating directory and then opening a file within it in Python, but no error if directory already exists | 38,258,758 | <p>I expect a directory to be created and then a file to be opened within it for writing to when I execute my code below in Python 2.6.6,</p>
<pre><code>import subprocess
def create_output_dir(work_dir):
output_dir = '/work/m/maxwell9/some_name5/'
subprocess.Popen(['mkdir', output_dir])
return output_dir
... | 2 | 2016-07-08T04:05:02Z | 38,258,790 | <p><code>subprocess.Popen</code> starts up an external process but doesn't wait for it to complete unless you tell it to (e.g. by calling <a href="https://docs.python.org/2/library/subprocess.html#subprocess.Popen.wait" rel="nofollow"><code>.wait</code></a> on the returned <code>Popen</code> instance). Most likely, <c... | 5 | 2016-07-08T04:08:58Z | [
"python",
"subprocess"
] |
Error when creating directory and then opening a file within it in Python, but no error if directory already exists | 38,258,758 | <p>I expect a directory to be created and then a file to be opened within it for writing to when I execute my code below in Python 2.6.6,</p>
<pre><code>import subprocess
def create_output_dir(work_dir):
output_dir = '/work/m/maxwell9/some_name5/'
subprocess.Popen(['mkdir', output_dir])
return output_dir
... | 2 | 2016-07-08T04:05:02Z | 38,258,864 | <p>You could use the <code>os</code> library instead of <code>subprocess</code>, which makes for a more straightforward implementation. Try swapping out your <code>create_output_dir</code> function with this:</p>
<pre><code>import os
def create_output_dir(work_dir):
try:
os.makedirs(work_dir)
exc... | 1 | 2016-07-08T04:18:22Z | [
"python",
"subprocess"
] |
Python 3: How to properly add new Futures to a list while already waiting upon it? | 38,258,774 | <p>I have a <code>concurrent.futures.ThreadPoolExecutor</code> and a list. And with the following code I add futures to the ThreadPoolExecutor:</p>
<pre><code>for id in id_list:
future = self._thread_pool.submit(self.myfunc, id)
self._futures.append(future)
</code></pre>
<p>And then I wait upon the list:</p>
... | 3 | 2016-07-08T04:07:18Z | 38,259,255 | <p>Looking at the implementation of <code>wait()</code>, it certainly doesn't expect that anything outside <code>concurrent.futures</code> will ever mutate the list passed to it. So I don't think you'll ever get that "to work". It's not just that it doesn't expect the list to mutate, it's also that significant proces... | 2 | 2016-07-08T05:08:30Z | [
"python",
"multithreading",
"python-3.x"
] |
Is there a smart solution to transform a DataFrame by a function and set the result to each cell? | 38,258,798 | <p>the below is an example:<br></p>
<p>input:</p>
<pre><code>1 2 3
4 5 6
</code></pre>
<p>output:</p>
<pre><code>2.5 3.5 4.5
2.5 3.5 4.5
</code></pre>
<p>here, I want to get each column's <code>mean</code> and set the result to each cell in the column.<br>
If I use loop can do the job. I think it's too ugl... | 3 | 2016-07-08T04:09:47Z | 38,259,003 | <p>This hack should work, but I feel there should be even better (meaning not hacky at all)...</p>
<pre><code>new_df = pd.concat([df.mean()]*len(df),axis=1).T
new_df.index = df.index
</code></pre>
| 1 | 2016-07-08T04:40:29Z | [
"python",
"pandas",
"dataframe"
] |
Is there a smart solution to transform a DataFrame by a function and set the result to each cell? | 38,258,798 | <p>the below is an example:<br></p>
<p>input:</p>
<pre><code>1 2 3
4 5 6
</code></pre>
<p>output:</p>
<pre><code>2.5 3.5 4.5
2.5 3.5 4.5
</code></pre>
<p>here, I want to get each column's <code>mean</code> and set the result to each cell in the column.<br>
If I use loop can do the job. I think it's too ugl... | 3 | 2016-07-08T04:09:47Z | 38,259,408 | <p>This is less hacky but still ugly.</p>
<pre><code>df.stack().groupby(level=1).transform(lambda x: x.mean()).unstack()
</code></pre>
| 0 | 2016-07-08T05:24:31Z | [
"python",
"pandas",
"dataframe"
] |
Is there a smart solution to transform a DataFrame by a function and set the result to each cell? | 38,258,798 | <p>the below is an example:<br></p>
<p>input:</p>
<pre><code>1 2 3
4 5 6
</code></pre>
<p>output:</p>
<pre><code>2.5 3.5 4.5
2.5 3.5 4.5
</code></pre>
<p>here, I want to get each column's <code>mean</code> and set the result to each cell in the column.<br>
If I use loop can do the job. I think it's too ugl... | 3 | 2016-07-08T04:09:47Z | 38,260,661 | <p>IMO loops solutions (if it's still a vectorized solution) are not always evil.</p>
<p>In order to be fair, all solutions will work on a copy of the original DF: </p>
<pre><code>In [32]: %paste
def not_so_ugly(df):
x = df.copy()
for col in x.columns:
x[col] = x[col].mean()
return x
def apply_me... | 3 | 2016-07-08T06:58:06Z | [
"python",
"pandas",
"dataframe"
] |
How to upgrade numpy without changing linux distributions in ubuntu | 38,258,842 | <p>I have numpy 1.11 on my 15.10 Ubuntu machine and I need the same version on my 12.04 machine. I am not sure if this is possible at all and do not understand enough of linux to know.</p>
<p>I have tried </p>
<pre><code>sudo pip install numpy --upgrade
sudo apt-get dist-upgrade
</code></pre>
<p>I tried reinstallin... | 0 | 2016-07-08T04:15:28Z | 38,258,941 | <p>What happens when you run </p>
<pre><code>sudo pip install numpy --upgrade
</code></pre>
<p>? </p>
<p>When I run it, I get this: </p>
<pre><code>Does it Collecting numpy
Downloading numpy-1.11.1.zip (4.7MB)
100% |ââââââââââââââââââââââââââââââââ... | 1 | 2016-07-08T04:31:40Z | [
"python",
"linux",
"ubuntu",
"numpy"
] |
How to upgrade numpy without changing linux distributions in ubuntu | 38,258,842 | <p>I have numpy 1.11 on my 15.10 Ubuntu machine and I need the same version on my 12.04 machine. I am not sure if this is possible at all and do not understand enough of linux to know.</p>
<p>I have tried </p>
<pre><code>sudo pip install numpy --upgrade
sudo apt-get dist-upgrade
</code></pre>
<p>I tried reinstallin... | 0 | 2016-07-08T04:15:28Z | 38,258,971 | <p>I find it is more reliable and repeatable to manage your python environment using the Anaconda python distribution. Rather than using apt-get, you would use conda as your python package management system and it should work fairly consistently across platforms especially with major packages like numpy. </p>
| 1 | 2016-07-08T04:35:40Z | [
"python",
"linux",
"ubuntu",
"numpy"
] |
How to upgrade numpy without changing linux distributions in ubuntu | 38,258,842 | <p>I have numpy 1.11 on my 15.10 Ubuntu machine and I need the same version on my 12.04 machine. I am not sure if this is possible at all and do not understand enough of linux to know.</p>
<p>I have tried </p>
<pre><code>sudo pip install numpy --upgrade
sudo apt-get dist-upgrade
</code></pre>
<p>I tried reinstallin... | 0 | 2016-07-08T04:15:28Z | 38,259,072 | <p>This should work</p>
<pre><code>pip install --upgrade numpy
</code></pre>
<p>Could you post the error message you received?</p>
<p>The next time you are working on a project, you could use <code>virtualenv</code>. <code>virtualenv</code> will create an isolated environment for each of your projects with a copy o... | 1 | 2016-07-08T04:49:26Z | [
"python",
"linux",
"ubuntu",
"numpy"
] |
How to upgrade numpy without changing linux distributions in ubuntu | 38,258,842 | <p>I have numpy 1.11 on my 15.10 Ubuntu machine and I need the same version on my 12.04 machine. I am not sure if this is possible at all and do not understand enough of linux to know.</p>
<p>I have tried </p>
<pre><code>sudo pip install numpy --upgrade
sudo apt-get dist-upgrade
</code></pre>
<p>I tried reinstallin... | 0 | 2016-07-08T04:15:28Z | 38,268,250 | <p>Ok I resolved my Issue. I will summarize the problem:</p>
<p>When I installed Scipy by installing the scipy pack it automatically resinstalls numpy 1.8 no materr what, even if it is just:</p>
<pre><code>sudo apt-get install python-scipy
</code></pre>
<p>What worked for me:</p>
<pre><code>sudo apt-get purge pyth... | 0 | 2016-07-08T13:45:00Z | [
"python",
"linux",
"ubuntu",
"numpy"
] |
matplotlib how to adjust navigation and cursor display | 38,258,890 | <p>When plotting two time series on two different y-scales using <code>twinx</code>:</p>
<pre><code>ax1 = pp.subplot(111)
ax2 = ax1.twinx()
</code></pre>
<p>the default behavior for navigation seems to be:</p>
<ol>
<li>zoom/pan will control both axes simultaneously</li>
<li>the lower-right corner displays the mouse ... | 1 | 2016-07-08T04:22:40Z | 38,321,786 | <p>It seems that there is no simple way (ala <code>set_navigate</code>) to do this. I managed to find <a href="http://stackoverflow.com/questions/16672530/cursor-tracking-using-matplotlib-and-twinx/">this</a> question and modified it a bit to accomplish what I need:</p>
<pre><code>class Cursor(object):
def __init_... | 0 | 2016-07-12T06:47:52Z | [
"python",
"matplotlib"
] |
Function not returning anything | 38,258,935 | <p><strong>My view</strong></p>
<pre><code>def login(request):
c = {}
c.update(csrf(request))
return render_to_response(request,
'login.html', c)
def auth_view(request):
username = request.POST.get
('username', '')
password = request.POST.get
('password', '')
user = auth.authenticate
(username... | -2 | 2016-07-08T04:30:17Z | 38,259,163 | <p>If the <code>user</code> is <code>None</code>, <code>auth_view</code> doesn't return anything. You must return an HttpResponse...</p>
| 1 | 2016-07-08T04:59:01Z | [
"python",
"django"
] |
regex: a character should be present followed by another escape character | 38,258,992 | <p>I am looking for a search pattern. There is a particular pattern which should not be followed inside another pattern. Somehow if this pattern is present, then <code><</code> and <code>></code> characters should be followed by escape <code>\</code> character. The characters can be present if they are not in the... | 0 | 2016-07-08T04:38:46Z | 38,259,616 | <p><code>(?<!\\)<(?:[^<>]|\\<|\\>)+:(?:[^<>]|\\<|\\>)*[^\\]></code></p>
<p>Gives:</p>
<pre><code>$1 - <First tag:\<Second tag:hello>
$1 - <Second tag:hello\>tag ends>
$1 - <First tag:\<Second tag:hello\>tag ends>
</code></pre>
<p>for your second example:... | 0 | 2016-07-08T05:42:52Z | [
"python",
"regex",
"backslash",
"findall"
] |
How to generate sets of indices where 10% data is left out | 38,259,087 | <p>I am trying to implement the jackknife method to calculate mean and its corresponding variance for a huge amount of data (a few million data points). Since I have a huge amount of data, if each time only one elements is left out, it is not helping much. I have the code for the case of single element left out:</p>
<... | 1 | 2016-07-08T04:51:31Z | 38,263,056 | <p>Maybe try using <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.KFold.html" rel="nofollow"><code>sklearn.cross_validation.KFold</code></a>? </p>
<pre><code>import numpy as np
from sklearn.cross_validation import KFold
import time
def jackknife(x, func):
"""Jackknife estimate ... | 1 | 2016-07-08T09:17:33Z | [
"python",
"numpy",
"indexing"
] |
I want to extend an existing dictionary with a for loop through a list | 38,259,120 | <p>I've simplified my code to illustrate what I'm trying to do. I have a list of something, and in that list are also my keys to a dictionary. I'm trying to do a for loop that takes each element in the list, runs a function on that element, and then I want to extend my dictionary with what returned from the function. W... | 0 | 2016-07-08T04:55:21Z | 38,259,168 | <p>You are attempting to append your values to a string, which is something you cannot do. Change the values in <code>first_dict</code> from strings to lists (e.g. <code>'Math'</code> to <code>['Math']</code>) and your problem will be solved.</p>
| 1 | 2016-07-08T04:59:35Z | [
"python"
] |
I want to extend an existing dictionary with a for loop through a list | 38,259,120 | <p>I've simplified my code to illustrate what I'm trying to do. I have a list of something, and in that list are also my keys to a dictionary. I'm trying to do a for loop that takes each element in the list, runs a function on that element, and then I want to extend my dictionary with what returned from the function. W... | 0 | 2016-07-08T04:55:21Z | 38,261,033 | <p>Try something like this.</p>
<pre><code>student_list = ['Whitney', 'Jason']
first_dict = {'Whitney':['Math'], "Jason":["Biology"]}
def schedule(student):
B = 'Science'
C = 'Social Studies'
D = 'Gym'
E = 'Lunch'
first_dict[student].extend([B, C, D, E])
for student in student_list:
schedule(... | 0 | 2016-07-08T07:22:34Z | [
"python"
] |
Does anybody know how to get the X and Y of a drawn circle? | 38,259,209 | <p>I can't figure out how to get the X and Y coordinates of a drawn circle</p>
<p>(example: pygame.draw.circle(Surface, color, pos(x,y), radius, width=0))</p>
<p>How could I get the X and y and use it in possibly making another circle go towards those codinates? if anybody knows how it would help a lot...</p>
| -3 | 2016-07-08T05:04:09Z | 38,260,392 | <p>I am a bit baffled tbh.</p>
<pre><code> import pygame
x, y = 100, 100
r = 50
black = (0, 0, 0)
red = (255, 0, 0)
(... screen stuff ...)
pygame.draw.circle(screen, black, (x,y), r)
pygame.draw.circle(screen, red, (x,y), r / 2)
</code></pre>
<p>You should already have the coordinates s... | 0 | 2016-07-08T06:41:37Z | [
"python",
"pygame"
] |
Creating a Python list comprehension with an if and break with nested for loops | 38,259,235 | <p>I noticed from <a href="http://stackoverflow.com/questions/9014058/creating-a-python-list-comprehension-with-an-if-and-break">this</a> answer that the code </p>
<pre><code>for i in userInput:
if i in wordsTask:
a = i
break
</code></pre>
<p>can be written as a list comprehension in the following... | 4 | 2016-07-08T05:06:35Z | 38,259,358 | <p>List comprehensions are not necessarily faster than a <code>for</code> loop. If you have a pattern like:</p>
<pre><code>some_var = []
for ...:
if ...:
some_var.append(some_other_var)
</code></pre>
<p>then yes, the list comprehension is faster than the bunch of <code>.append()</code>s. You have extenu... | 3 | 2016-07-08T05:20:37Z | [
"python",
"list-comprehension",
"nested-loops",
"break"
] |
Creating a Python list comprehension with an if and break with nested for loops | 38,259,235 | <p>I noticed from <a href="http://stackoverflow.com/questions/9014058/creating-a-python-list-comprehension-with-an-if-and-break">this</a> answer that the code </p>
<pre><code>for i in userInput:
if i in wordsTask:
a = i
break
</code></pre>
<p>can be written as a list comprehension in the following... | 4 | 2016-07-08T05:06:35Z | 38,259,417 | <p>I don't know that complex list comprehensions or generator expressions are that much faster than nested loops if they're running the same algorithm (e.g. visiting the same number of values). To get a definitive answer you should probably try to implement a solution both ways and test to see which is faster for your ... | 2 | 2016-07-08T05:25:14Z | [
"python",
"list-comprehension",
"nested-loops",
"break"
] |
Convert specific lines into lists using Python | 38,259,296 | <p>I am trying to take 200 lines and convert each group of 10 into its own list.</p>
<pre><code>1
Victorious Boom
834
7
0
7.00
1
0
1.00
1
2
Tier 1 Smurf
806
4
0
4.00
1
0
1.00
1
3
AllHailHypnoToad
754
4
0
4.00
1
0
1.00
1
</code></pre>
<p>which I want to look like:</p>
<pre><code>1 Victorious Boom 834 7 0 7.00 1 0 1.0... | -2 | 2016-07-08T05:13:08Z | 38,259,568 | <pre><code>full_list = [line.strip() for line in open("filename", 'r')] #read all lines into list
sublist = [full_list[i:i+10] for i in range(0, len(full_list), 10)] #split them into sublist with 10 lines each
</code></pre>
| 1 | 2016-07-08T05:39:24Z | [
"python"
] |
Convert specific lines into lists using Python | 38,259,296 | <p>I am trying to take 200 lines and convert each group of 10 into its own list.</p>
<pre><code>1
Victorious Boom
834
7
0
7.00
1
0
1.00
1
2
Tier 1 Smurf
806
4
0
4.00
1
0
1.00
1
3
AllHailHypnoToad
754
4
0
4.00
1
0
1.00
1
</code></pre>
<p>which I want to look like:</p>
<pre><code>1 Victorious Boom 834 7 0 7.00 1 0 1.0... | -2 | 2016-07-08T05:13:08Z | 38,259,586 | <pre><code>count=0
fixed_list=[]
temp_list=[]
for line in open("some.txt").readlines():
count+=1
temp_list.append(line.strip())
if (count%10)==0:
fixed_list.append(temp_list)
temp_list=[]
print fixed_list
</code></pre>
| 0 | 2016-07-08T05:40:44Z | [
"python"
] |
Convert specific lines into lists using Python | 38,259,296 | <p>I am trying to take 200 lines and convert each group of 10 into its own list.</p>
<pre><code>1
Victorious Boom
834
7
0
7.00
1
0
1.00
1
2
Tier 1 Smurf
806
4
0
4.00
1
0
1.00
1
3
AllHailHypnoToad
754
4
0
4.00
1
0
1.00
1
</code></pre>
<p>which I want to look like:</p>
<pre><code>1 Victorious Boom 834 7 0 7.00 1 0 1.0... | -2 | 2016-07-08T05:13:08Z | 38,260,071 | <p>Here is my answer.
It takes a source.txt with the line by line type data and outputs the data in sets of 10 into the target.txt file. I hope this helps.</p>
<pre><code>file = open("source.txt", "r")
data = []
for line in file:
data.append(line)
length = len(data)
file.close()
#output file
target = open("targe... | 0 | 2016-07-08T06:18:14Z | [
"python"
] |
How to get the sum of multiple numbers in Python | 38,259,355 | <pre><code>k = 1
M = input("Enter an integer: ")
for M in range(k,M):
s = 1/float(M)
print sum(s)
</code></pre>
<p>How do I get the sum of <code>s</code>? I keep getting an error message:</p>
<pre class="lang-none prettyprint-override"><code>File "C:/Python27/summation.py", line 7, in <module>
print s... | 0 | 2016-07-08T05:20:10Z | 38,259,404 | <p><code>s</code> is not a list it is a float. Try this instead:</p>
<pre><code>k = 1
M = input("Enter an integer:")
print sum(1/float(s) for s in range(k, M))
</code></pre>
| 3 | 2016-07-08T05:24:24Z | [
"python",
"python-2.7"
] |
How to get the sum of multiple numbers in Python | 38,259,355 | <pre><code>k = 1
M = input("Enter an integer: ")
for M in range(k,M):
s = 1/float(M)
print sum(s)
</code></pre>
<p>How do I get the sum of <code>s</code>? I keep getting an error message:</p>
<pre class="lang-none prettyprint-override"><code>File "C:/Python27/summation.py", line 7, in <module>
print s... | 0 | 2016-07-08T05:20:10Z | 38,259,411 | <p>Try this:</p>
<pre><code>s=[]
k = 1
M = input("Enter an integer: ")
for M in range(k,M):
s.append(1/float(M))
print(s)
print(sum(s))
</code></pre>
<p>Output(M=10):</p>
<pre><code>[1.0, 0.5, 0.3333333333333333, 0.25, 0.2, 0.16666666666666666, 0.14285714285714285, 0.125, 0.1111111111111111]
2.8289682539682537
<... | 1 | 2016-07-08T05:24:36Z | [
"python",
"python-2.7"
] |
How to get the sum of multiple numbers in Python | 38,259,355 | <pre><code>k = 1
M = input("Enter an integer: ")
for M in range(k,M):
s = 1/float(M)
print sum(s)
</code></pre>
<p>How do I get the sum of <code>s</code>? I keep getting an error message:</p>
<pre class="lang-none prettyprint-override"><code>File "C:/Python27/summation.py", line 7, in <module>
print s... | 0 | 2016-07-08T05:20:10Z | 38,259,481 | <p>In this source code, value M is override twice. So if change the M in the for loop, you can get the sum of s.
The fixed coed is below. </p>
<pre><code>k = 1
M = input("Enter an integer: ")
S = []
for V in range(k,M): S.append(V)
print sum(s)
</code></pre>
<p>Also, If you want to get a sum of list, you must make a... | 0 | 2016-07-08T05:31:23Z | [
"python",
"python-2.7"
] |
How to get the sum of multiple numbers in Python | 38,259,355 | <pre><code>k = 1
M = input("Enter an integer: ")
for M in range(k,M):
s = 1/float(M)
print sum(s)
</code></pre>
<p>How do I get the sum of <code>s</code>? I keep getting an error message:</p>
<pre class="lang-none prettyprint-override"><code>File "C:/Python27/summation.py", line 7, in <module>
print s... | 0 | 2016-07-08T05:20:10Z | 38,259,581 | <p>You can try with the following code:</p>
<pre><code>result = 0
k = 1
M = int(input("Enter an integer: "))
for M in range(k, M):
result += (1 / float(M))
print(result)
</code></pre>
<p>How it works? It will ask for an input, and do the operation. The result of each cycle of the loop will be added to a variable ... | 0 | 2016-07-08T05:40:11Z | [
"python",
"python-2.7"
] |
How to get the sum of multiple numbers in Python | 38,259,355 | <pre><code>k = 1
M = input("Enter an integer: ")
for M in range(k,M):
s = 1/float(M)
print sum(s)
</code></pre>
<p>How do I get the sum of <code>s</code>? I keep getting an error message:</p>
<pre class="lang-none prettyprint-override"><code>File "C:/Python27/summation.py", line 7, in <module>
print s... | 0 | 2016-07-08T05:20:10Z | 38,260,952 | <p>I guess you need to count the sum of 1/1.0 + ... + 1/yourInput. </p>
<p>You can use the method below.</p>
<pre><code>def getSum(yourInput):
scoreLst = [1/float(e) for e in range(1, yourInput)]
return sum(scoreLst)
</code></pre>
<p>e.g:getSum(10), you will get the output:2.828...</p>
| 0 | 2016-07-08T07:17:42Z | [
"python",
"python-2.7"
] |
AttributeError: 'QString' object has no attribute 'find' | 38,259,410 | <p>Indeed this question is asked many times, but could not find anything to solve my problem. I have many modules in my python project and it works fine, however on creating executable of that project i get error:</p>
<blockquote>
<p>AttributeError: 'QString' object has no attribute 'find' </p>
</blockquote>
<p>Unf... | 0 | 2016-07-08T05:24:35Z | 38,259,605 | <p>You need to convert the user input to string. It should work by just adding <code>str</code> to <code>input = str(self.builselcom.currentText())</code>. Hope this is helpful.</p>
| 1 | 2016-07-08T05:42:00Z | [
"python",
"pyqt4",
"executable"
] |
AttributeError: 'QString' object has no attribute 'find' | 38,259,410 | <p>Indeed this question is asked many times, but could not find anything to solve my problem. I have many modules in my python project and it works fine, however on creating executable of that project i get error:</p>
<blockquote>
<p>AttributeError: 'QString' object has no attribute 'find' </p>
</blockquote>
<p>Unf... | 0 | 2016-07-08T05:24:35Z | 38,259,610 | <p>My guess is that your executable is using a different version of the Qt DLLs. (I use cx_Freeze and PySide and can only speak for that environment.) The QString class doesn't exist in the latest DLLs, but it used to; so if this error happened in my setup I would know for sure it was a DLL issue. Perhaps you can tr... | 0 | 2016-07-08T05:42:22Z | [
"python",
"pyqt4",
"executable"
] |
Python words phrase likeness degree comparison | 38,259,412 | <p>Is there now a library/function for <code>Python</code> to compare word phrases and return degree of likeness and/or degree of how information in 1st phrase is fully present in 2nd phrase?</p>
<p>E.g. "Mr John Leron" compare to "Jonh Ler. Jr. teacher"?</p>
<p>I expect it could be some 'vector' function used in big... | 0 | 2016-07-08T05:24:46Z | 38,259,520 | <p>I recommand the cosine-similariy algorithm. The reference url is below. </p>
<p><a href="http://stackoverflow.com/questions/15173225/how-to-calculate-cosine-similarity-given-2-sentence-strings-python">How to calculate cosine similarity given 2 sentence strings? - Python</a></p>
| 1 | 2016-07-08T05:35:41Z | [
"python",
"scikit-learn",
"bigdata"
] |
How to use the columns to divide the DataFrame into groups? | 38,259,423 | <p>At first, DataFrame likes this:</p>
<p><a href="http://i.stack.imgur.com/Lsiwn.png" rel="nofollow"><img src="http://i.stack.imgur.com/Lsiwn.png" alt="first"></a></p>
<p>I wish to change it like this:</p>
<p><a href="http://i.stack.imgur.com/nTBx9.png" rel="nofollow"><img src="http://i.stack.imgur.com/nTBx9.png" a... | 2 | 2016-07-08T05:25:32Z | 38,259,559 | <p>there is a module called <strong>itertools</strong>.
use the <strong>groupby</strong> method on the specific column.</p>
<p>(if not helpful let me know)</p>
| 0 | 2016-07-08T05:38:52Z | [
"python",
"pandas"
] |
How to use the columns to divide the DataFrame into groups? | 38,259,423 | <p>At first, DataFrame likes this:</p>
<p><a href="http://i.stack.imgur.com/Lsiwn.png" rel="nofollow"><img src="http://i.stack.imgur.com/Lsiwn.png" alt="first"></a></p>
<p>I wish to change it like this:</p>
<p><a href="http://i.stack.imgur.com/nTBx9.png" rel="nofollow"><img src="http://i.stack.imgur.com/nTBx9.png" a... | 2 | 2016-07-08T05:25:32Z | 38,260,079 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_index.html" rel="nofollow"><code>set_index</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow"><code>sort_index</code></a>:</p>
<pre><code>d... | 0 | 2016-07-08T06:18:44Z | [
"python",
"pandas"
] |
How to use the columns to divide the DataFrame into groups? | 38,259,423 | <p>At first, DataFrame likes this:</p>
<p><a href="http://i.stack.imgur.com/Lsiwn.png" rel="nofollow"><img src="http://i.stack.imgur.com/Lsiwn.png" alt="first"></a></p>
<p>I wish to change it like this:</p>
<p><a href="http://i.stack.imgur.com/nTBx9.png" rel="nofollow"><img src="http://i.stack.imgur.com/nTBx9.png" a... | 2 | 2016-07-08T05:25:32Z | 38,261,585 | <p>Do you really need to keep the duplicates? If you don't, the <code>groupby</code> is made for you!</p>
<pre><code>Frame.groupby(['Entity_name','State_Name','State_Group','State_Type']).first()
</code></pre>
| 0 | 2016-07-08T07:54:38Z | [
"python",
"pandas"
] |
Compress selected folder from clients machine before upload to server using php or background process using exec('pyhton')? | 38,259,426 | <p>Created php upload which accepts only rar,zip and tar compressions. But every user is not able to compress and upload to my website. Is there any way to compress the user selected folder from clients machine and then start upload to website. Like dump any script or application to clients machine for compressing fold... | 0 | 2016-07-08T05:25:59Z | 38,259,490 | <p>Since PHP is server-side you can not zip anything client-side with it. However, simple Google query has shown me this JS library: <a href="https://stuk.github.io/jszip/" rel="nofollow">https://stuk.github.io/jszip/</a></p>
<p>Example says this:</p>
<pre><code>var zip = new JSZip();
zip.file("Hello.txt", "Hello Wor... | 0 | 2016-07-08T05:32:09Z | [
"php",
"python",
"client",
"exec"
] |
parse binary format with python | 38,259,484 | <p>I have a binary file with the following header: 4 byte string, 1 byte number then 4 byte uint32 number.</p>
<p>Do I understand this correctly?
The <code>sbet_data[0:3]</code> is the string, <code>sbet_data[4:5]</code> is the 1 byte number, then how long is the 4 byte uint32 number? Where can I find a good chart fo... | 0 | 2016-07-08T05:31:49Z | 38,259,666 | <p>I believe you are trying to extract information from the binary. Well this will work</p>
<pre><code>import struct
import numpy as np
buffer = np.random.bytes(12)
s = struct.Struct('4sbI')
unpacked_data = s.unpack(buffer)
print unpacked_data[0], unpacked_data[1], unpacked_data[2]
</code></pre>
<p>In this case <co... | 1 | 2016-07-08T05:47:05Z | [
"python",
"python-3.x",
"binary"
] |
parse binary format with python | 38,259,484 | <p>I have a binary file with the following header: 4 byte string, 1 byte number then 4 byte uint32 number.</p>
<p>Do I understand this correctly?
The <code>sbet_data[0:3]</code> is the string, <code>sbet_data[4:5]</code> is the 1 byte number, then how long is the 4 byte uint32 number? Where can I find a good chart fo... | 0 | 2016-07-08T05:31:49Z | 38,259,851 | <p>You need to open your file in binary mode and read only 12 bytes from your file:</p>
<pre><code>import struct
with open('abc.dat', 'rb') as fobj:
byte_string, n1, n4 = struct.unpack('4sbI', fobj.read(12))
</code></pre>
<p>You will get a byte string. Assuming it is ASCII, you can decode like this:</p>
<pre><... | 3 | 2016-07-08T06:00:59Z | [
"python",
"python-3.x",
"binary"
] |
Django password reset not working with django-anymail | 38,259,638 | <p>I'm trying to implement django-anymail with my site, and am having trouble.</p>
<p>Using these settings:</p>
<pre><code>ANYMAIL = {
"MAILGUN_API_KEY": "key-hahahahahahahahhaha... no",
}
EMAIL_BACKEND = "anymail.backends.mailgun.MailgunBackend"
DEFAULT_FROM_EMAIL = "account-recovery@mg.mycooldomain.com"
</code>... | 1 | 2016-07-08T05:45:00Z | 38,277,167 | <p>I figured out the answer, and it didn't come up elsewhere.</p>
<p>The call to <code>send_mail</code> worked as it forces an email to be sent.</p>
<p>However, password recovery has a lot of indirection, and one of the checks is if the user <a href="https://docs.djangoproject.com/en/1.9/ref/contrib/auth/#django.cont... | 0 | 2016-07-09T00:44:05Z | [
"python",
"django",
"mailgun",
"django-anymail"
] |
How to split a column into two separate ones in a DataFrame with Pandas | 38,259,749 | <p>How can I split the a column into two separate ones. Would apply be the way to go about this? I want to keep the other columns in the DataFrame.</p>
<p>For example I have a column called "last_created" with a bunch of dates and times: "2016-07-01 09:50:09"</p>
<p>I want to create two new columns "date" and "time" ... | 1 | 2016-07-08T05:52:35Z | 38,259,864 | <p>In my cases, I just using the function. ipython source code is below.</p>
<pre><code>In [5]: df = dict(data="", time="", last_created="")
In [6]: df
Out[6]: {'data': '', 'last_created': '', 'time': ''}
In [7]: df["last_created"] = "2016-07-01 09:50:09"
In [8]: df
Out[8]: {'data': '', 'last_created': '2016-07-01 ... | 1 | 2016-07-08T06:01:39Z | [
"python",
"pandas",
"dataframe"
] |
How to split a column into two separate ones in a DataFrame with Pandas | 38,259,749 | <p>How can I split the a column into two separate ones. Would apply be the way to go about this? I want to keep the other columns in the DataFrame.</p>
<p>For example I have a column called "last_created" with a bunch of dates and times: "2016-07-01 09:50:09"</p>
<p>I want to create two new columns "date" and "time" ... | 1 | 2016-07-08T05:52:35Z | 38,259,865 | <p>The following should work for you. However, storing the date and time as timestamp is much convenient for manipulation. </p>
<pre><code>df['date'] = [d.split()[0] for d in df['last_created']]
df['time'] = [d.split()[1] for d in df['last_created']]
</code></pre>
| 1 | 2016-07-08T06:01:43Z | [
"python",
"pandas",
"dataframe"
] |
How to split a column into two separate ones in a DataFrame with Pandas | 38,259,749 | <p>How can I split the a column into two separate ones. Would apply be the way to go about this? I want to keep the other columns in the DataFrame.</p>
<p>For example I have a column called "last_created" with a bunch of dates and times: "2016-07-01 09:50:09"</p>
<p>I want to create two new columns "date" and "time" ... | 1 | 2016-07-08T05:52:35Z | 38,259,987 | <p>You can first convert <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a> if <code>dtype</code> is <code>object</code> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.date.html" rel="nofollow"... | 1 | 2016-07-08T06:10:54Z | [
"python",
"pandas",
"dataframe"
] |
Groupby DataFram by its rank/percentile | 38,259,953 | <p>Would you help me to come up a better solution for the problem as follows:
For each date(in columns), I have values. I rank them and assign into three groups. My goal is to group the value by Low,Mid,Top group, and compute the group mean. I put the DataFrame and my own solution as follows.
Can anyone suggest a bette... | 2 | 2016-07-08T06:08:46Z | 38,260,521 | <p>You can use only one <code>stack</code> and then <code>pd.qcut</code> only for one column <code>Value</code> instead all <code>DataFrame</code>:</p>
<pre><code>df = value.stack()
.reset_index(name='Value')
.rename(columns={'level_0':'Type','level_1':'Date'})
df['Rank'] = pd.qcut(df.Value, 3, la... | 1 | 2016-07-08T06:49:01Z | [
"python",
"pandas",
"group-by"
] |
Decoding NumPy int64 binary representation | 38,259,960 | <p>So I did a stupid thing, and forgot to explicitly type-convert some values I was putting into an SQLite database (using Python's SQLalchemy). The column was set up to store an <code>INT</code>, whereas the input was actually a <code>numpy.int64</code> dtype.</p>
<p>The values I am getting back out of the database l... | 2 | 2016-07-08T06:09:08Z | 38,260,143 | <p>You can use <a href="https://docs.python.org/3/library/struct.html#struct.unpack" rel="nofollow"><code>struct.unpack()</code></a>:</p>
<pre><code>>>> import struct
>>> value = struct.unpack('<q', b'\x15\x00\x00\x00\x00\x00\x00\x00')
>>> value
(21,)
>>> value[0]
21
</code></pre... | 4 | 2016-07-08T06:22:19Z | [
"python",
"sqlite",
"numpy",
"sqlalchemy"
] |
Node.js googlemaps cluster execute error | 38,260,059 | <p>I'm now use the node.js platform. And I want to use googlemap cluster library. However I can't execute the source code. </p>
<p>googlemaps cluster api url : <a href="https://github.com/googlemaps/js-marker-clusterer" rel="nofollow">https://github.com/googlemaps/js-marker-clusterer</a></p>
<p>This library's index i... | 0 | 2016-07-08T06:17:17Z | 38,281,280 | <p>Once you create a marker cluster, support it by using <a href="https://developers.google.com/maps/documentation/javascript/markers#add" rel="nofollow"><code>addMarker()</code></a> method or by providing a array of markers to the constructor.</p>
<p>When they say add marker to constructor by providing a array of mar... | 0 | 2016-07-09T11:20:50Z | [
"javascript",
"python",
"node.js",
"google-maps"
] |
TypeError in python - missing 1 required positional argument | 38,260,275 | <p>I'm stuck here. For <code>n = 5</code> and <code>k = 3</code>, the answer should be <code>19</code>. If I set <code>k = 3</code> separately as a local or global variable and run <code>wabbits(5)</code>, I get 19, but when I run <code>wabbits(5, 3)</code> after the function below, I get </p>
<pre><code>TypeError: wa... | -2 | 2016-07-08T06:32:57Z | 38,260,354 | <p>Your <code>wabbits()</code> function takes <em>two</em> arguments:</p>
<pre><code>def wabbits(n, k):
# 1 2
</code></pre>
<p>but your code calls it with just one:</p>
<pre><code>return wabbits(n-2)*k + wabbits(n-1)
# ^^^ ^^^^
</code></pre>
<p>You need to pass in a value for <c... | 3 | 2016-07-08T06:39:06Z | [
"python"
] |
TypeError in python - missing 1 required positional argument | 38,260,275 | <p>I'm stuck here. For <code>n = 5</code> and <code>k = 3</code>, the answer should be <code>19</code>. If I set <code>k = 3</code> separately as a local or global variable and run <code>wabbits(5)</code>, I get 19, but when I run <code>wabbits(5, 3)</code> after the function below, I get </p>
<pre><code>TypeError: wa... | -2 | 2016-07-08T06:32:57Z | 38,260,382 | <p>Calling the function with <code>wabbits(5)</code> will not work because the function is declared to accept <em>2</em> parameters: <code>n</code> and <code>k</code>. Both must be supplied.</p>
<p>You can call the function with two arguments, but the trouble is that the recursive call to <code>wabbits()</code> passes... | 0 | 2016-07-08T06:41:04Z | [
"python"
] |
TypeError in python - missing 1 required positional argument | 38,260,275 | <p>I'm stuck here. For <code>n = 5</code> and <code>k = 3</code>, the answer should be <code>19</code>. If I set <code>k = 3</code> separately as a local or global variable and run <code>wabbits(5)</code>, I get 19, but when I run <code>wabbits(5, 3)</code> after the function below, I get </p>
<pre><code>TypeError: wa... | -2 | 2016-07-08T06:32:57Z | 38,260,406 | <p>Several solutions, the simplest is:</p>
<pre><code>def wabbits(n, k):
if n == 1:
return 1
elif n == 2:
return 1
return wabbits(n-2, k)*k + wabbits(n-1, k)
r = wabbits(5, 3)
</code></pre>
<p>However you could encapsulate <code>k</code> using an inner function:</p>
<pre><code>def wabbit... | 0 | 2016-07-08T06:42:22Z | [
"python"
] |
exposing c++ class in Python ( only ET_DYN and ET_EXEC can be loaded) | 38,260,351 | <p>I was looking at <a href="http://www.boost.org/doc/libs/1_56_0/libs/python/doc/tutorial/doc/html/python/exposing.html" rel="nofollow">here</a> to see how to expose c++ to Python. I have built Python deep learning code which uses boost-python to connect c++ and python and it is running ok, so my system has things for... | 0 | 2016-07-08T06:38:56Z | 38,888,735 | <p>I've long forgotten about this problem and got to revisit this issue today.<br>
I found two problems. The first problem was that I gave -c option which made the compiler only compile the source and not link. The second problem was that the library name was wrong(I search /usr/lib64 and there was libboost_python.so, ... | 0 | 2016-08-11T06:25:31Z | [
"python",
"boost"
] |
Django pytest for login | 38,260,369 | <p>Im new to pytest and was trying to test login. Im not sure how to approach for testing login</p>
<p>login views.py</p>
<pre><code>@api_view(['POST','GET'])
@permission_classes((AllowAny,))
def ulogin(request):
username = request.POST['uname']
password = request.POST['pass']
user = authenticate(username... | 0 | 2016-07-08T06:40:12Z | 38,261,113 | <p>When it comes to testing using <code>pytest</code> library or any other library or framework you use <code>assert</code> (or similar function) to validate your assertions for pytest you can check the <code>assert</code> documentation <a href="http://pytest.org/latest/assert.html" rel="nofollow">here</a>. </p>
<p>Py... | 1 | 2016-07-08T07:26:23Z | [
"python",
"django",
"pytest-django"
] |
Options for running -O flag | 38,260,422 | <p>I've been having trouble finding alternative ways in which Python can be ran with the -O flag. Are there any other ways besides including in a script that calls the IDLE and .py file?</p>
<p>Is a script necessary? Can it be included in the .py file itself?</p>
| -2 | 2016-07-08T06:43:42Z | 38,260,495 | <p>You can set an environment variable. From the <a href="https://docs.python.org/3/using/cmdline.html#cmdoption-O" rel="nofollow"><code>-O</code> switch documentation</a>:</p>
<blockquote>
<p>Turn on basic optimizations. This changes the filename extension for compiled (bytecode) files from <code>.pyc</code> to <co... | 2 | 2016-07-08T06:48:06Z | [
"python",
"python-3.x",
"python-3.5"
] |
I've trying to build a simple login page for my project | 38,260,491 | <pre><code>def login(request):
c = {}
c.update(csrf(request))
return render_to_response(request,
'login.html', c)
def auth_view(request):
username = request.POST.get
('username', '')
password = request.POST.get
('password', '')
user = auth.authenticate
(username = username, password =
password)... | -6 | 2016-07-08T06:47:54Z | 38,261,856 | <p>Your logic isn't good, <strong>if user is not None:</strong> instead use <strong>if user.is_anonymous:</strong></p>
<p>Try my logic</p>
<p><code>def login(request):
c = {}
c.update(csrf(request))
return render_to_response(request,
'login.html', c)</code></p>
<p><code>def auth_view(request):
userna... | 0 | 2016-07-08T08:08:48Z | [
"python",
"django"
] |
I've trying to build a simple login page for my project | 38,260,491 | <pre><code>def login(request):
c = {}
c.update(csrf(request))
return render_to_response(request,
'login.html', c)
def auth_view(request):
username = request.POST.get
('username', '')
password = request.POST.get
('password', '')
user = auth.authenticate
(username = username, password =
password)... | -6 | 2016-07-08T06:47:54Z | 38,262,203 | <p>Instead of using <code>HttpResponseRedirect</code> use <code>render</code></p>
<pre><code>def something(request):
if something:
do something()
if something == 'POST':
return render(request, 'accounts/loggedin.html')
else:
return render(requset, 'accounts/invalid.html... | 0 | 2016-07-08T08:30:45Z | [
"python",
"django"
] |
Fit fixed rectangle to set of points | 38,260,549 | <p>i was wondering if someone every tried to fit a rectangle with a fixed size to a given set of points.</p>
<p>Imagine you have a set of points which is unsorted and not always showing a full hull of a rectangle. The image below should demonstrate the problem:
<a href="http://i.stack.imgur.com/kYYiL.png" rel="nofollo... | 0 | 2016-07-08T06:50:27Z | 38,261,920 | <p>Just an outline of the solution:</p>
<ol>
<li>The height and width of your rectangle is fixed, so you can define it with three parameters (x0, y0, theta): say the lower left corner and rotation.</li>
<li>Use a distance function like <code>pnt2line</code> given here <a href="http://www.fundza.com/vectors/point2line/... | 0 | 2016-07-08T08:13:09Z | [
"python",
"math",
"computational-geometry",
"curve-fitting",
"least-squares"
] |
Fit fixed rectangle to set of points | 38,260,549 | <p>i was wondering if someone every tried to fit a rectangle with a fixed size to a given set of points.</p>
<p>Imagine you have a set of points which is unsorted and not always showing a full hull of a rectangle. The image below should demonstrate the problem:
<a href="http://i.stack.imgur.com/kYYiL.png" rel="nofollo... | 0 | 2016-07-08T06:50:27Z | 38,268,382 | <p>If there are outliers, RANSAC can be your good friend. To perform a fit, you need three points taken from different sides. So just pick three random points and hypothesize that two of them belong to one side and the other to an orthogonal side. Finding the pose parameters is no big deal. You can compute the fitting ... | 0 | 2016-07-08T13:51:07Z | [
"python",
"math",
"computational-geometry",
"curve-fitting",
"least-squares"
] |
Fit fixed rectangle to set of points | 38,260,549 | <p>i was wondering if someone every tried to fit a rectangle with a fixed size to a given set of points.</p>
<p>Imagine you have a set of points which is unsorted and not always showing a full hull of a rectangle. The image below should demonstrate the problem:
<a href="http://i.stack.imgur.com/kYYiL.png" rel="nofollo... | 0 | 2016-07-08T06:50:27Z | 38,312,601 | <p>Define the distance d(R(P), Q) between the fixed-size rectangle R(P) at position P and a point Q to be the length of the shortest straight line connecting the two. This is very easy to define as a function reasoning by cases.</p>
<p>Now just use some form of gradient descent to find the optimal P* such that the sum... | 0 | 2016-07-11T17:15:05Z | [
"python",
"math",
"computational-geometry",
"curve-fitting",
"least-squares"
] |
Import Error on Kivy (Android) | 38,260,562 | <p>I'm building a Kivy application for Android. When it is run on my Linux machine from terminal it works as expected. When it is built and deployed to Android it fails with the following error:</p>
<pre><code>I/python (14091): Traceback (most recent call last):
I/python (14091): File "{project path}/src/app/.bu... | 2 | 2016-07-08T06:51:14Z | 38,294,410 | <p>You can try to add the path to your module to the <a href="https://docs.python.org/3/library/sys.html#sys.path" rel="nofollow">sys.path</a>.</p>
<p>But maybe... there's no such thing as <code>app.ui.first_screen</code>. Try to make it only <code>ui.first_screen</code> or go for this:</p>
<pre><code>from .<file/... | 0 | 2016-07-10T17:06:25Z | [
"android",
"python",
"kivy",
"buildozer"
] |
how do find and replace string with python | 38,260,695 | <p>There is an string like this</p>
<pre><code>100Usable by Everybody: Design Principles for Accessibility on Mac OS X 101What's New in Cocoa Touch 102What's New in Foundation for iOS 4 103iPad and iPhone User Interface Design 104Designing Apps with Scroll Views 308Developing Your App with Xcode 4 309Advanced Performa... | -2 | 2016-07-08T07:00:33Z | 38,261,057 | <p>Assuming the number is always 3 digits (since you have other numbers embedded in the data):</p>
<pre><code>data = "100Usable by Everybody: Design Principles for Accessibility on Mac OS X 101What's New in Cocoa Touch 102What's New in Foundation for iOS 4 103iPad and iPhone User Interface Design 104Designing Apps wit... | 0 | 2016-07-08T07:23:42Z | [
"python"
] |
maximum recursion depth exceeded when exec `repr()` | 38,260,896 | <pre><code>class A(object):
def xx(self):
return 'xx'
class B(A):
def __repr__(self):
return 'ss%s' % self.xx
b = B()
print repr(b)
</code></pre>
<p>When I wrote <code>__repr__</code> method, I forgot to call <code>self.xx</code>.</p>
<p>Why these code cause <code>RuntimeError: maximum recu... | 0 | 2016-07-08T07:14:04Z | 38,260,972 | <p>This is what happens:</p>
<ul>
<li><code>%s</code> on <code>self.xx</code> calls <code>str(self.xx)</code></li>
<li>A method has no <code>__str__</code>, so <code>__repr__</code> is called on it instead.</li>
<li><p>The <code>__repr__</code> for a method incorporates the <code>repr()</code> of <code>self</code> as ... | 3 | 2016-07-08T07:18:56Z | [
"python",
"recursion",
"repr"
] |
python: I want to modify the value of one complex dictionary using kv pairs, how to implement? | 38,261,008 | <p>For example, the dict is:</p>
<p><code>dict1={'a':1, 'b':[{'b1':21, 'b2':21, 'b3':31}, {'b4':41, 'b5':61, 'b6':61}], 'c':3}</code></p>
<p>I have one function <code>f1()</code>:</p>
<pre><code>def f1(dictionary, kv):
modify k = v
</code></pre>
<p>If I want to modify <code>b5=51</code> like:</p>
<pre><code>f1... | -1 | 2016-07-08T07:20:57Z | 38,261,059 | <p>Make <code>kv</code> a <code>**</code> capturing argument, then use <code>dict.update()</code> to pass all captured key-value pairs on to the dictionary:</p>
<pre><code>def f1(self, dictionary, **kv):
dictionary.update(kv)
</code></pre>
<p>Demo (with the <code>self</code> argument omitted to make <code>f1</cod... | 4 | 2016-07-08T07:23:50Z | [
"python",
"dictionary"
] |
Is there a way to fit a 3D Gaussian distribution or a Gaussian mixture distribution to a vector? | 38,261,081 | <p>I have a vector of data points that seems to represent a 3D Gaussian distribution or a Gaussian mixture distribution. Is there a way to fit a 3D Gaussian distribution or a Gaussian mixture distribution to this matrix, and if yes, do there exist libraries to do that (e.g. in Python)?</p>
<p>The question seems relate... | 0 | 2016-07-08T07:24:57Z | 38,261,720 | <p>I can give an answer if you know the number of Gaussians. Your vector gives the Z values at a grid of X, Y points. You can make X and Y vectors: </p>
<pre><code>import numpy as np
num_x, num_y = np.shape(z)
xx = np.outer(np.ones(num_x), np.arange(num_y))
yy = np.outer(np.arange(num_x), np.ones(num_y))
</code></pre>... | 0 | 2016-07-08T08:01:32Z | [
"python",
"numpy",
"3d",
"distribution",
"gaussian"
] |
Is there a way to fit a 3D Gaussian distribution or a Gaussian mixture distribution to a vector? | 38,261,081 | <p>I have a vector of data points that seems to represent a 3D Gaussian distribution or a Gaussian mixture distribution. Is there a way to fit a 3D Gaussian distribution or a Gaussian mixture distribution to this matrix, and if yes, do there exist libraries to do that (e.g. in Python)?</p>
<p>The question seems relate... | 0 | 2016-07-08T07:24:57Z | 38,376,103 | <p>There is so-called Gaussian Mixture Models (GMM), with lots of literature behind it. And there is python code to do sampling, parameters estimation etc, not sure if it fits your needs</p>
<p><a href="http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GMM.html" rel="nofollow">http://scikit-learn.org/st... | 0 | 2016-07-14T13:52:16Z | [
"python",
"numpy",
"3d",
"distribution",
"gaussian"
] |
Python 2 __missing__ method | 38,261,126 | <p>I wrote a very simple program to subclass a dictionary. I wanted to try the <code>__missing__</code> method in python.
After some research i found out that in Python 2 it's available in <code>defaultdict</code>. ( In python 3 we use collections.UserDict though..)
The <code>__getitem__</code> is the on responsible fo... | 0 | 2016-07-08T07:27:12Z | 38,261,313 | <p>The <code>dict</code> type will <em>always</em> try to call <code>__missing__</code>. All that <code>defaultdict</code> does is provide an implementation; if you are providing your own <code>__missing__</code> method you don't have to subclass <code>defaultdict</code> at all.</p>
<p>See the <a href="https://docs.py... | 6 | 2016-07-08T07:38:53Z | [
"python"
] |
How to fill PDF form in Django/Python? | 38,261,138 | <p>I'm trying to fill pre-made pdf form with database data and flatten it. For example, if the user inputs a field called "name", it should be placed in the name field of the pdf form.</p>
| -2 | 2016-07-08T07:28:08Z | 38,261,817 | <p>You can use <code>reportlab</code> library in combinaison with Django views :</p>
<pre><code>from io import BytesIO
from reportlab.pdfgen import canvas
from django.http import HttpResponse
def some_view(request):
# Create the HttpResponse object with the appropriate PDF headers.
response = HttpResponse(con... | 0 | 2016-07-08T08:06:26Z | [
"python",
"django",
"forms",
"pdf"
] |
Django OneToOne field to self | 38,261,145 | <p>How to define <code>OneToOne</code> relationship to the same <code>Model</code>? </p>
<p>I have a model called <code>Order</code> which can be paired with another one <code>Order</code>. Now I'm trying to figure out how to handle models for this relationship. </p>
<p>My ideas:</p>
<pre><code>class Order(models.Mo... | 0 | 2016-07-08T07:28:39Z | 38,261,225 | <p>The <code>ForeignKey</code> accepts as an argument not just a class, but also a string name of the form <code>ForeignKey('ModelNameInSameModelsPyFile')</code> or <code>ForeignKey('app_name.ModelName</code>).</p>
<p>In your case, it could be like</p>
<pre><code>class Order(models.Model):
paired = models.Forei... | 1 | 2016-07-08T07:33:14Z | [
"python",
"django",
"django-models"
] |
Django OneToOne field to self | 38,261,145 | <p>How to define <code>OneToOne</code> relationship to the same <code>Model</code>? </p>
<p>I have a model called <code>Order</code> which can be paired with another one <code>Order</code>. Now I'm trying to figure out how to handle models for this relationship. </p>
<p>My ideas:</p>
<pre><code>class Order(models.Mo... | 0 | 2016-07-08T07:28:39Z | 38,261,573 | <blockquote>
<p>Pairing model would be a good solution because I can add additional
information to this relationship.</p>
</blockquote>
<p>In that case, you could model that group of "orders" (you've called it Pairing) and add a shortcut to retrieve the paired order.</p>
<pre><code>class OrderPair(models.Model):
... | 1 | 2016-07-08T07:54:10Z | [
"python",
"django",
"django-models"
] |
After() conflicting with Destroy() in Python | 38,261,296 | <p>I have a problem using <em>after()</em> and <em>destroy()</em> methods. I created a meniu when I'm monitoring the ram status and processor status. When I'm calling first def it's okay but when I'm calling second def, exemple processor status the information inside the frame is showing for few milliseconds and then t... | 0 | 2016-07-08T07:38:12Z | 38,263,362 | <p>The problem is unclear, but I think what you're asking is how to stop updating the old information when you request different information.</p>
<p><code>after</code> returns an identifier, which you can pass to <code>after_cancel</code> in order to prevent the function from being called again. So, your menu commands... | 0 | 2016-07-08T09:33:47Z | [
"python",
"user-interface",
"tkinter"
] |
Python - Find the ratio of the results | 38,261,335 | <pre><code>from random import random
from math import pi, sin
attempts = int(input("Enter the number of attempts to perform: "))
for i in range(1,attempts):
ytail = 2.0*random()
angle = pi*random()
yhead = ytail + sin(angle)
if yhead > 2.0:
print ("hit")
else:
print ("not a hit")... | 0 | 2016-07-08T07:40:02Z | 38,261,417 | <p>Store the number of hits in a variable, increment it when a hit occurs and print the ratio after iterating.</p>
<pre><code>from random import random
from math import pi, sin
hits = 0
attempts = int(input("Enter the number of attempts to perform: "))
for i in range(0, attempts):
ytail = 2.0 * random()
angle... | 2 | 2016-07-08T07:44:50Z | [
"python",
"python-2.7"
] |
Python - Find the ratio of the results | 38,261,335 | <pre><code>from random import random
from math import pi, sin
attempts = int(input("Enter the number of attempts to perform: "))
for i in range(1,attempts):
ytail = 2.0*random()
angle = pi*random()
yhead = ytail + sin(angle)
if yhead > 2.0:
print ("hit")
else:
print ("not a hit")... | 0 | 2016-07-08T07:40:02Z | 38,261,726 | <p>If you don't mind using numpy, here's an alternate solution:</p>
<pre><code>import numpy as np
attempts = int(input("Enter the number of attempts to perform: "))
ytail = 2.0*np.random.rand(attempts)
angle = np.pi*np.random.rand(attempts)
yhead = ytail + np.sin(angle)
print(np.sum(yhead > 2.0)/attempts)
</code></... | 0 | 2016-07-08T08:01:55Z | [
"python",
"python-2.7"
] |
Can't install traits on windows, python | 38,261,366 | <p><strong>Windows 10 64bit</strong></p>
<p>I installed traitsui successfully by pip in python3.52</p>
<p>Qt4 must be installed to display GUI on windows, But the highest version of python Qt4 support is python3.4</p>
<p>So, I install python3.4, when I try to install traits by pip</p>
<p>I got error message:</p>
<... | 0 | 2016-07-08T07:41:53Z | 38,262,000 | <p>You can circumvent the problem of the error with Visual Studio C++ by installing a precompiled version of the package in form of a <code>wheel</code>. You can find <code>wheel</code> packages for most of the common modules <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">here</a>.</p>
<p>Download... | 0 | 2016-07-08T08:17:31Z | [
"python",
"traits",
"traitsui"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.