title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How to resolve add new item and delete old item in Django?
38,081,477
<p>I demo a order sale page. When I edit the order I want to update the items of order in some case: Example: I have a list of item of order in database like this:</p> <p><code>============= Item Quantity 1 10 2 15 3 30 =============</code></p> <p>Case 1: When edit order if I add new a item 4 with quantit...
-1
2016-06-28T16:23:20Z
38,084,166
<p>Add a class Meta to your model class, and an "ordering" tuple to specify the field to be ordered by. Example:</p> <pre><code>class MyItem(models.Model): item = models.AutoField(primary_key=True) quantity = models.IntField() class Meta: ordering = ('item',) </code></pre> <p>This will order call...
2
2016-06-28T18:55:06Z
[ "python", "django" ]
Use java class in Python
38,081,496
<p>I am having two classes written in java file. I want to use those java classes in my Python code. I am using IPython Notebook for executing Python code. </p> <p>I tried making it as .jar file and calling that .jar file in Python as suggested <a href="http://stackoverflow.com/questions/7372592/python-how-can-i-execu...
0
2016-06-28T16:24:10Z
38,240,900
<p>You need to redirect the output.</p> <p>See this <a href="http://stackoverflow.com/questions/4965159/python-how-to-redirect-output-with-subprocess">question</a> form more details</p>
0
2016-07-07T08:34:56Z
[ "java", "python" ]
Need help understanding bytes-like object vs str in Python 3.5
38,081,511
<p>I'm having trouble getting a library working on Windows with Python 3.5 or 3.4 (see this issue [1]). I thought I'd take a closer look at why it's failing.</p> <p>I believe the problem boils down to some code that looks like this, the results of which I don't understand:</p> <pre><code>import urllib.request import...
0
2016-06-28T16:24:55Z
38,081,619
<p><code>urllib.request.pathname2url</code> takes a string, not a bytes-like object. The error message you're getting comes from the <code>bytes</code> object, when <code>urllib</code> tries to use it like a string and the <code>bytes</code> object wants to be passed other bytes-likes.</p>
1
2016-06-28T16:31:09Z
[ "python", "python-3.x", "weasyprint" ]
Simple Python Slackbot does not listen or respond to channel
38,081,538
<p>I am getting started with the Slack API, so i just wanted to write a bot that listens into a channel and whenever someone says a keyword, it responds with an answer. In this case, if someone says 'hello' it responds with 'world'.</p> <p>Here is what I have done so far. I registered for a Slack account. I registered...
0
2016-06-28T16:26:34Z
38,112,690
<p>As @smarx said, you definitely need to invite your bot to the channel. And then I use the <code>chat.postMessage</code> method to do a call and response:</p> <pre><code> if re.search("hello", message): self.client.api_call("chat.postMessage", as_user="true", channel=CHANNEL_NAME, tex...
0
2016-06-30T01:46:30Z
[ "python", "automation", "bots", "slack-api", "slack" ]
strip header from binary file
38,081,541
<p>I have a raw binary file that is several gigs and I'm attempting to process it in chunks. Before I can start processing the data I have to remove the header that it has. None of the string methods like .find or checking for string in data chunk works because of the raw binary file format. I would like to automatical...
0
2016-06-28T16:26:48Z
38,081,886
<p>You could use linecache:</p> <pre><code>import linecache currentline = 0 while(linecache.getline("file.bin",currentline)!="HEADER_END\n"): currentline=currentline+1 #print raw data currentline = currentline + 1 rawdata = linecache.getline("file.bin",currentline) currentrawdata = rawdata while(currentrawdata): ...
0
2016-06-28T16:43:16Z
[ "python", "python-3.x", "binary-data" ]
Copying string value to clipboard
38,081,554
<p>I am trying to copy a string to clipboard in Python, as per the question <a href="http://stackoverflow.com/questions/579687/how-do-i-copy-a-string-to-the-clipboard-on-windows-using-python">How do I copy a string to the clipboard on Windows using Python?</a></p> <p>My current code is:</p> <pre><code> from Tkinter ...
0
2016-06-28T16:27:45Z
38,081,965
<p>the issue here is that tinker does not keep the value in clipboard after the application close</p> <p>So to make your application work add this line at the end</p> <pre><code>r.mainloop() </code></pre> <p>this will prevent you application from ending and since it didnt end the values will keep being in clipboard ...
1
2016-06-28T16:47:46Z
[ "python", "tkinter" ]
using Tornado's WSGIContainer, how do I make it run in debug mode so I get better error messages
38,081,561
<p>I am writing a Flask web app that uses Tornado as its web server. When my application raises an exception, I get the unhelpful error message "Internal Server Error". I want it to instead display the stack trace, so i can see what is going wrong.</p> <p>The Tornado manual says I can do this if I pass <code>debug=Tru...
0
2016-06-28T16:28:17Z
38,152,202
<p><code>WSGIContainer</code> does not have this feature. You may be able to get it with WSGI middleware instead of from the container; otherwise you'll need to use a different server for developing the Flask portions of your application.</p> <p>Note that if your application is entirely flask-based, using Tornado's WS...
0
2016-07-01T18:50:50Z
[ "python", "flask", "tornado" ]
How can I create block-scoped variables in Python?
38,081,572
<p>Take the following Perl code:</p> <pre><code>$a = 5; if($a == 5) { print $a; my $a = 8; print $a; } print $a; </code></pre> <p>This outputs <code>585</code> because <code>my $a</code> creates a new lexical variable that is scoped to the <code>if</code> block.</p> <p>I want to do the same thing in Py...
0
2016-06-28T16:28:46Z
38,082,178
<p>The codes are not equivalent; in the Perl code, the <code>my</code> inside the <code>if</code> block creates an entirely new variable, which goes out of scope when the containing block ends.</p> <p>You can do something similar with a context manager in Python, but the syntax will be much different.</p>
0
2016-06-28T17:00:46Z
[ "python", "scope" ]
How can I create block-scoped variables in Python?
38,081,572
<p>Take the following Perl code:</p> <pre><code>$a = 5; if($a == 5) { print $a; my $a = 8; print $a; } print $a; </code></pre> <p>This outputs <code>585</code> because <code>my $a</code> creates a new lexical variable that is scoped to the <code>if</code> block.</p> <p>I want to do the same thing in Py...
0
2016-06-28T16:28:46Z
38,082,467
<p>Is this what you're looking for?</p> <pre><code>a = 5 b = 9 def my_func(a): if a == 5: b = 'apple' print("inside function: ", b) my_func(a) print("outside function: ", b) &gt; inside function: apple &gt; outside function: 9 </code></pre> <p><code>b</code> is a local variable inside t...
0
2016-06-28T17:16:25Z
[ "python", "scope" ]
Django TypeError at /sitemap.xml sequence index must be integer, not 'slice'
38,081,593
<p>I have weird problem with my sitemap page.</p> <pre><code># -*- coding: utf-8 -*- from __future__ import unicode_literals import datetime import urllib from django.core.urlresolvers import reverse from django.contrib.sitemaps import Sitemap from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger ...
1
2016-06-28T16:29:31Z
38,082,346
<p>I think this is your backwards-incompatible change:</p> <ul> <li><a href="https://code.djangoproject.com/ticket/23190" rel="nofollow">Make paginator.page_range an iterator</a></li> </ul> <p>To resolve this return the list from the <code>items()</code> method:</p> <pre><code>def items(self): post_queryset = Qu...
1
2016-06-28T17:09:53Z
[ "python", "django" ]
Python: How to Completely delete Linked List?
38,081,643
<p>Lets say that I have such class definition for <code>Node</code></p> <pre><code>class Node: def __init__(self, data, next): self.data = data self.next = next </code></pre> <p>Also I have <code>head</code> variable which points to the beginning of linked list. </p> <p>Is it enough to set <code>...
0
2016-06-28T16:32:15Z
38,081,748
<p>Usually, you don't even need to do anything. When the lifetime of the <code>head</code> variable ends, if you don't have any other references to the list, the list will become unreachable and eligible for collection automatically. On CPython, it'll usually get collected immediately, but you shouldn't rely on that.</...
2
2016-06-28T16:36:56Z
[ "python", "linked-list" ]
python3.5.1 can not parse json data from url
38,081,647
<p>I have already got my url and access this url on the browser. It will give you json data format, however, when I use build-in function of python3 it also gives me an error and the <code>get_report</code> gives me <code>&lt;function get_report at 0x103362840&gt;</code>. How could I use build-in function of python3 to...
0
2016-06-28T16:32:22Z
38,082,570
<p>Before anything else, please, when you put raw code on the page, use the {} button, or put 4 spaces before each line of your code. It helps clarifying the overall.</p> <p>If you receive a string containing formatted and valid JSON, you can parse it using the builtin <code><a href="https://docs.python.org/3/library/...
2
2016-06-28T17:22:47Z
[ "python", "json" ]
could i use a MCP3008 to output?
38,081,695
<p>I would like to use the <strong>mcp3008</strong> to drive motors, or switch on led arrays for example, until now i only found how to read analog sensor using raspberry pi gpio.</p> <p>thanks in advance</p>
0
2016-06-28T16:34:43Z
38,116,678
<p>No you can't. MCP3008 is an analog-to-digital converter. It is an input device.</p>
0
2016-06-30T07:34:13Z
[ "python", "arduino", "raspberry-pi", "spi", "raspberry-pi3" ]
Create repeated loop to generate neighbours
38,081,738
<p>I'm trying to generate a sublist of nieghbours with below criteria:</p> <ul> <li>The input would be possible partitions to the list S = [1,2,3,4,5,6]</li> </ul> <p>Criteria for Neighbourhood Using Split Operations</p> <ul> <li>Criteria 1 – Split largest element in the list.</li> <li>Criteria 2 – Always split ...
0
2016-06-28T16:36:21Z
38,083,446
<p>Something like this:</p> <pre><code>input = [[1], [2, 3, 4], [5, 6]] def splitList(input): length = len(input) split = length/2 left = input[:split] right = input[split:] return [left, right] def splitNeighbors(input): lengths = map(len, input) longest = max(lengths) if longest &gt...
0
2016-06-28T18:13:24Z
[ "python", "python-2.7", "iterator", "generator" ]
Is there a way to run powershell code in python
38,081,866
<p>Is there a way to run powershell code in python? I've been searching around and all I'm finding is how to run a separate PS script file in python, but nothing about running PS code.</p> <p>Example: Let's say I want to run this command from inside a Python script\program...</p> <pre><code>Start-Process -filepath "P...
4
2016-06-28T16:42:24Z
38,082,342
<p>Just start powershell.exe (untested)</p> <pre><code>os.system("powershell.exe", "script.ps1") </code></pre> <p>You may need an additional parameters to specify path and execution policy.</p>
1
2016-06-28T17:09:44Z
[ "python", "powershell" ]
Is there a way to run powershell code in python
38,081,866
<p>Is there a way to run powershell code in python? I've been searching around and all I'm finding is how to run a separate PS script file in python, but nothing about running PS code.</p> <p>Example: Let's say I want to run this command from inside a Python script\program...</p> <pre><code>Start-Process -filepath "P...
4
2016-06-28T16:42:24Z
38,083,047
<p>If you Want to embed PowerShell script in exe, vc++ is probably the way to go.</p> <p>You can use <code>system</code> function in <code>&lt;stdlib&gt;</code> to run commands in cmd</p> <p>here is the code:</p> <pre><code>#include "stdafx.h" #include &lt;stdlib.h&gt; using namespace std; int main() { system("...
2
2016-06-28T17:51:51Z
[ "python", "powershell" ]
Is there a way to run powershell code in python
38,081,866
<p>Is there a way to run powershell code in python? I've been searching around and all I'm finding is how to run a separate PS script file in python, but nothing about running PS code.</p> <p>Example: Let's say I want to run this command from inside a Python script\program...</p> <pre><code>Start-Process -filepath "P...
4
2016-06-28T16:42:24Z
38,083,110
<p>Couldn't you just write a powershell script file and then call it? (untested)</p> <pre><code>f = open("script.ps1") f.write(...) #Script you want to run f.close() os.system("powershell.exe", "script.ps1") </code></pre>
0
2016-06-28T17:55:04Z
[ "python", "powershell" ]
Try Except block for multiple validation errors
38,081,911
<pre><code>try: if isDateValid(date) == false: raise ValidationError('invalid date') if usernameValid(user) == false: raise ValidationError('invalid username') except ValidationError: data = json.dumps({'status': 'Enter a valid date'}) data = json.dumps({'status': 'Enter a valid usernam...
2
2016-06-28T16:45:01Z
38,081,963
<p>Access the exception instance you are raising:</p> <pre><code>try: if isDateValid(date) == false: raise ValidationError('invalid date') if usernameValid(user) == false: raise ValidationError('invalid username') except ValidationError as e: data = json.dumps({'status': str(e)}) retur...
3
2016-06-28T16:47:43Z
[ "python", "json", "try-catch", "except" ]
vectorised list.get() solution in numpy/pandas
38,082,037
<p>I have a temporal KDF kernel as a list (or numpy array) of values, where value index represents corresponding minute in a week.</p> <p>my data is approximate as described below: - kde: list or ndarray of float values, with the length of 7*24*60. - df: DataFrame with ~ 50 columns of different types, including <cod...
0
2016-06-28T16:52:36Z
38,082,987
<p>another solution I might use is:</p> <pre><code>kdeDF = pf.DateFrame({'kd':kde}).reset_index() kdeDF.columns = ['index', 'kd'] data1 = data.merge(kdeDF, how='left', left_on='timestamp', right_on='index') </code></pre> <p>but it also looks pretty ugly</p>
0
2016-06-28T17:48:01Z
[ "python", "numpy", "pandas" ]
vectorised list.get() solution in numpy/pandas
38,082,037
<p>I have a temporal KDF kernel as a list (or numpy array) of values, where value index represents corresponding minute in a week.</p> <p>my data is approximate as described below: - kde: list or ndarray of float values, with the length of 7*24*60. - df: DataFrame with ~ 50 columns of different types, including <cod...
0
2016-06-28T16:52:36Z
38,083,125
<p>I'd do</p> <pre><code>import numpy as np import pandas as pd df['kd'] = np.array(kd)[df.timestamp.values] </code></pre>
1
2016-06-28T17:56:18Z
[ "python", "numpy", "pandas" ]
Binary searchtree, trying to implement a remove node method, trouble with pointers
38,082,082
<p>I found another good thread here at stackoverflow, gonna link it <a href="http://stackoverflow.com/questions/26568163/removing-a-node-from-a-binary-search-tree-using-recursion">removing a node from a binary search tree using recursion</a> . Here is where I've taken the code from, its looking like this:</p> <pre><co...
0
2016-06-28T16:54:30Z
38,082,231
<p>The <strong>left</strong> and <strong>right</strong> attributes are objects. Actually, they are implemented as object references, a.k.a. pointers.</p> <p>self.left.right is the left-then-right grandchild of <strong>self</strong> (your temporary "root"). **self* can have up to four grandchlidren; this is the secon...
1
2016-06-28T17:03:52Z
[ "python", "pointers", "binary-search-tree", "nodes" ]
Python pymssql: Adaptive Server connection failed
38,082,124
<p>I try to connect Azure SQL using python, but get next error: </p> <pre><code>File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824) pymssql.OperationalError: (20002, 'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (myserver:1433)\n') </code></pre> <p>freetds.conf:</p> <pre>...
1
2016-06-28T16:56:51Z
38,089,440
<p>@Alximik Per my experience, I don't think recompiling freetds by self is necessary. For the issue, I think the issue was caused by your configuration for <code>freetds.conf</code>, please see my answer for the solved SO thread <a href="http://stackoverflow.com/questions/32380367/pymssql-connection-to-the-database-on...
0
2016-06-29T02:38:16Z
[ "python", "sql", "azure", "pymssql" ]
Python pymssql: Adaptive Server connection failed
38,082,124
<p>I try to connect Azure SQL using python, but get next error: </p> <pre><code>File "pymssql.pyx", line 641, in pymssql.connect (pymssql.c:10824) pymssql.OperationalError: (20002, 'DB-Lib error message 20002, severity 9:\nAdaptive Server connection failed (myserver:1433)\n') </code></pre> <p>freetds.conf:</p> <pre>...
1
2016-06-28T16:56:51Z
38,150,681
<p>I solve it after make from source pymssql and freetds (with option in previous post and set tds version=7.3 in global config). Pymssql make from source use command "python setup.py build" and next for install in system "python setup.py install"</p>
0
2016-07-01T17:07:35Z
[ "python", "sql", "azure", "pymssql" ]
Why is Django blocktrans working one place and not another?
38,082,128
<p>I have two Django templates (in a Pinax 0.9.x project) with text in a <code>blocktrans</code> block. One is working and the other isn't.</p> <p>The one that's working looks like:</p> <pre><code>{% extends "site_base.html" %} ... {% block body %} &lt;h1&gt;ABC&lt;/h1&gt; &lt;h2&gt;&lt;em&gt;DEF&lt;/em&g...
0
2016-06-28T16:56:58Z
38,082,883
<p>You have to load the <a href="https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#internationalization-in-template-code" rel="nofollow">i18n</a> template tags:</p> <pre><code>&lt;!-- your_template.html --&gt; {% load i18n %} </code></pre>
1
2016-06-28T17:41:09Z
[ "python", "django", "django-templates", "pinax" ]
Return country_code from pycountry
38,082,143
<p>I have two fields in my usermodel:</p> <pre><code>country = models.CharField(max_length=20, null=True) code = models.CharField(max_length=2, null=True) </code></pre> <p>I want the second to automatically change once I enter my country, I know how to do it in python shell, but how do I do that in django?</p> <p>Wh...
0
2016-06-28T16:58:12Z
38,082,382
<p>See django docs on models: <a href="https://docs.djangoproject.com/en/1.9/topics/db/models/" rel="nofollow">https://docs.djangoproject.com/en/1.9/topics/db/models/</a></p> <p>You'd want something like this:</p> <pre><code>class YourModel(models.Model): country = models.CharField(max_length=20, null=True) ...
0
2016-06-28T17:11:59Z
[ "python", "django" ]
Converting data from Json to String in python
38,082,197
<p>Could anybody please explain how to convert the following json data into a string in python. It's very big but i need your help... You can see it from the following link:- <a href="http://api.openweathermap.org/data/2.5/forecast/daily?q=delhi&amp;mode=json&amp;uni...
-3
2016-06-28T17:01:52Z
38,082,251
<p>You can decode a JSON string in python like this:</p> <pre><code>import json data = json.loads('json_string') </code></pre> <p>Source: <a href="https://docs.python.org/2/library/json.html" rel="nofollow">https://docs.python.org/2/library/json.html</a></p>
0
2016-06-28T17:05:09Z
[ "python", "json" ]
Converting data from Json to String in python
38,082,197
<p>Could anybody please explain how to convert the following json data into a string in python. It's very big but i need your help... You can see it from the following link:- <a href="http://api.openweathermap.org/data/2.5/forecast/daily?q=delhi&amp;mode=json&amp;uni...
-3
2016-06-28T17:01:52Z
38,082,293
<pre><code>import requests url = 'http://api.openweathermap.org/data/2.5/forecast/daily?q=delhi&amp;mode=json&amp;units=metric&amp;cnt=7&amp;appid=146f5f89c18a703450d3bd6737d4fc94' response = requests.get(url) response.text # this is a string response.json() # this is a json dictionary s = "The City is {city[name]}...
0
2016-06-28T17:07:12Z
[ "python", "json" ]
Converting data from Json to String in python
38,082,197
<p>Could anybody please explain how to convert the following json data into a string in python. It's very big but i need your help... You can see it from the following link:- <a href="http://api.openweathermap.org/data/2.5/forecast/daily?q=delhi&amp;mode=json&amp;uni...
-3
2016-06-28T17:01:52Z
38,082,433
<p>Some simple code that will read the JSON from your page and produce a Python dictionary follows. I have used the implicit concatenation of adjacent strings to improve the layout of the code.</p> <pre><code>import json import urllib.request f = urllib.request.urlopen (url="http://api.openweathermap.org/data/2....
0
2016-06-28T17:14:39Z
[ "python", "json" ]
is there a way to run commands in python on windows?
38,082,371
<p>I am trying to execute a command as below using python in windows and running into <code>WindowsError: [Error 2] The system cannot find the file specified</code> error, ,currently I do not have <code>script.exe</code> on my PC , manually running it throws the error <code>'script.exe' is not recognized as an interna...
2
2016-06-28T17:11:31Z
38,082,493
<p>You have to choose between one of these solutions:</p> <ol> <li>pass the <code>relative path</code> and set the current working directory to the same folder that contains script.exe by using <code>os.chdir('folderPath')</code> before trying to open the file</li> </ol> <p>OR</p> <ol start="2"> <li>pass the <code>a...
2
2016-06-28T17:18:06Z
[ "python" ]
is there a way to run commands in python on windows?
38,082,371
<p>I am trying to execute a command as below using python in windows and running into <code>WindowsError: [Error 2] The system cannot find the file specified</code> error, ,currently I do not have <code>script.exe</code> on my PC , manually running it throws the error <code>'script.exe' is not recognized as an interna...
2
2016-06-28T17:11:31Z
38,083,750
<pre><code>def find_abs_path(executable_fname): if os.path.exists(executable_fname): # in case it is in our cwd return os.path.abspath(os.path.join(".",executable_fname)) for dirname in os.environ["PATH"].split(";"): # split dependant on your os if executable_fname in os.listdir(dirname): ...
1
2016-06-28T18:31:45Z
[ "python" ]
drawCountour() not working
38,082,437
<p>The <code>drawContour()</code> function is not working properly in Video frames. It is working for images by using this <a href="http://stackoverflow.com/questions/31475634/drawcontours-not-working-opencv-python">stack-overflow answer</a>. The output is just canny image without any contours drawn.</p> <p>Here is my...
0
2016-06-28T17:14:52Z
38,083,248
<p>use </p> <pre><code>frame = cv2.drawContours(frame, contours, -1, (255,0,0), 3) cv2.imshow('window',frame) </code></pre>
0
2016-06-28T18:02:45Z
[ "python", "opencv" ]
drawCountour() not working
38,082,437
<p>The <code>drawContour()</code> function is not working properly in Video frames. It is working for images by using this <a href="http://stackoverflow.com/questions/31475634/drawcontours-not-working-opencv-python">stack-overflow answer</a>. The output is just canny image without any contours drawn.</p> <p>Here is my...
0
2016-06-28T17:14:52Z
38,117,835
<p>Contours drawn will not be colored because you're drawing them on a single channel image. Here's how to draw colored ones. (Assuming <code>frame</code> is <code>BGR</code>. If the original <code>frame</code> is Grayscale, convert <code>frame_copy</code> in the code below to <code>BGR</code> using <code>cvtColor</cod...
0
2016-06-30T08:32:47Z
[ "python", "opencv" ]
Read .dat file using python
38,082,532
<p>I've got a simulation involving internal waves and moving particles in the water, using the <em>MITgcm</em>. The output of this looks something like this for each time step:</p> <pre><code> -9999 0.0000000000000000000 #Time step (0.00000000000000 seconds) 1308.2021183321899 -14.999709364517091 # Particle ...
1
2016-06-28T17:20:17Z
38,082,931
<p>I would use <code>numpy.loadtxt</code> for reading input, but only because post-processing would also need numpy. You can read all your data to memory, then find the separator lines, then reshape the rest of your data to fit your number of particles. The following assumes that none of the particles ever reach <em>ex...
4
2016-06-28T17:44:52Z
[ "python", "matplotlib", "plot" ]
not able to plot line graph using bokeh streaming
38,082,533
<p>I am not able to get any sort of output(blank box) on running this code..</p> <pre><code>from bokeh.io import gridplot,vplot,hplot from bokeh.models import ColumnDataSource, Slider, Select from bokeh.plotting import curdoc, figure source = ColumnDataSource(dict(time=[],virt=[])) def update(): with open('test....
1
2016-06-28T17:20:21Z
38,328,579
<p>By adding the follow interval to the stream callback the code below works using bokeh version 0.11.1. </p> <p>Note: Without a copy of the f file the streaming data had to be randomly generated in the callback. </p> <pre><code>from bokeh.io import gridplot,vplot,hplot from bokeh.models import ColumnDataSource, Slid...
0
2016-07-12T12:11:46Z
[ "python", "streaming", "bokeh" ]
Python PyQt5 QMessageBox not opening
38,082,547
<p>I am trying to open a Message Box when I press the infoButton. It runs the infoDialogue method because it prints "I'm here" but it doesn't open the infoBox. What I'm missing?</p> <p>I'm using python 3.5 with PyQt5</p> <p>Thanks!</p> <p>Here's the code:</p> <pre><code>import sys from PyQt5.QtWidgets import (QAppl...
0
2016-06-28T17:21:08Z
38,082,784
<p>You might need a </p> <pre><code>infoBox.exec_() </code></pre> <p>at the end to actually execute it</p>
2
2016-06-28T17:35:05Z
[ "python", "python-3.x", "pyqt5", "qmessagebox" ]
Fill python string with date time as per format in string
38,082,557
<p>I have a string which looks like:</p> <p><code>dt_string='some_prefix/%Y-%m-%d/%H:%M/some_postfix' </code></p> <p>I want to format this string with current date and time, so that it may look like <code>'some_prefix/2016-06-28/10:00/some_postfix'</code></p> <p>But my problem is that the date patterns may not alway...
1
2016-06-28T17:22:06Z
38,082,916
<pre><code>from datetime import datetime dt1 = 'some_prefix/%Y-%m-%d/%H:%M/some_postfix' dt2 = 'some_prefix/%m-%d-%Y/%H:%M/some_postfix' def fill_date(dt_str): d = datetime.now() filled = dt_str.replace('%Y', str(d.year))\ .replace('%m', str(d.month))\ .replace('%d', str(...
2
2016-06-28T17:43:28Z
[ "python" ]
Fill python string with date time as per format in string
38,082,557
<p>I have a string which looks like:</p> <p><code>dt_string='some_prefix/%Y-%m-%d/%H:%M/some_postfix' </code></p> <p>I want to format this string with current date and time, so that it may look like <code>'some_prefix/2016-06-28/10:00/some_postfix'</code></p> <p>But my problem is that the date patterns may not alway...
1
2016-06-28T17:22:06Z
38,082,958
<p>you can use time.strftime method</p> <pre><code>import time time.strftime("stuff/%d-%m-%y/%H:%M/stuff") </code></pre> <p>Reference can be found here <a href="http://www.cyberciti.biz/faq/howto-get-current-date-time-in-python/" rel="nofollow">http://www.cyberciti.biz/faq/howto-get-current-date-time-in-python/</a></...
5
2016-06-28T17:46:41Z
[ "python" ]
Plotting multiple different plots in one figure using Seaborn
38,082,602
<p>I am attempting to recreate the following plot from the book Introduction to Statistical learning using seaborn <a href="http://i.stack.imgur.com/FegIV.png" rel="nofollow"><img src="http://i.stack.imgur.com/FegIV.png" alt="enter image description here"></a></p> <p>I specifically want to recreate this using seaborn'...
0
2016-06-28T17:24:54Z
38,091,681
<p>One possibility would be to NOT use <code>lmplot()</code>, but directly use <code>regplot()</code> instead. <code>regplot()</code> plots on the axes you pass as an argument with <code>ax=</code>.</p> <p>You lose the ability to automatically split your dataset according to a certain variable, but if you know beforeh...
1
2016-06-29T06:14:56Z
[ "python", "matplotlib", "seaborn" ]
SQLAlchemy delete cascade fails
38,082,661
<p>I am having trouble deleting a model instance from within SQLAlchemy. I recently added an additional table and this addition has introduced this problem. The table I added is called <code>editrecords</code>. </p> <p>The database is MySQL with an InnoDB engine.</p> <p>Models are defined below:</p> <pre><code>from ...
0
2016-06-28T17:28:28Z
38,089,025
<p>The issue is you have two foreign keys from foo tests and editrecord tables to test table </p> <p>footests</p> <pre><code>CONSTRAINT `footests_ibfk_1` FOREIGN KEY (`id`) REFERENCES `tests` (`id`) ON DELETE CASCADE, CONSTRAINT `footests_ibfk_2` FOREIGN KEY (`parent_id`) REFERENCES `footests` (`id`) ON DELETE CASC...
0
2016-06-29T01:52:38Z
[ "python", "mysql", "sqlalchemy", "innodb" ]
python collision detect trouble
38,082,699
<p>Being a begineer in python with some basic knowledge, i decided to expand this knowledge by making programs. In one such program, i found difficulties in collision detection. since i am using a .xml file most of my ideas seem not to work. The program is given below. can anyone help me with collision detect?</p> <pr...
0
2016-06-28T17:30:54Z
38,084,529
<p>The easiest way to implement collision detection is by using Sprites. There are several good tutorials online that walk you through Sprites and how to use them for simple collision detection. :-) This is a great feature for people just starting out with Pygame.</p> <p>Here are some good videos on sprites and collis...
0
2016-06-28T19:15:54Z
[ "python", "pygame" ]
Sort objects by first instance of related object, Django
38,082,702
<p>I have a model which is an instance for the existence of an item (a ticket), and on each creation of a ticket I create a instance of another model, a record. Each record keeps track of who made a change to the ticket, and what they did with it, it basically keeps a record of what has happened with it. I want to tick...
2
2016-06-28T17:31:09Z
38,085,464
<p>Assuming the Record ticket field is a Foreign key to the Ticket model:</p> <pre><code> class Record (models.Model): .... create_time = models.DateTimeField() ticket = models.ForeignKey(Ticket,related_name='records') </code></pre> <p>You can replace the ModelManager (objects) of the Ticket model and ...
2
2016-06-28T20:13:38Z
[ "python", "django" ]
Importing Python class from sibling directory
38,082,774
<p>I've spent the past hour going through Google and SO on this one. Sorry for adding yet another, but none of the answers are quite working for me.</p> <p>My Directory structure in <code>/VM/repo/project</code> is:</p> <pre><code>__init__.py scripts/ getSomething.py __init__.py classes/ project.p...
1
2016-06-28T17:34:32Z
38,082,864
<p>As stated in the error, you're running <code>getSomething</code> as a main module. But you can't do package relative imports when you aren't in a package. The main module is never in a package. So, if you were to import <code>getSomething</code> as part of a package...:</p> <pre><code># /VM/repo/main.py from pro...
4
2016-06-28T17:40:08Z
[ "python", "import", "module", "package", "relative" ]
Optimizing Django Many-To-Many Query with custom through table
38,082,810
<p>I have 2 models:</p> <pre><code>class ModelA: fieldA = models.ManyToManyField(ModelB, through="CustomThroughTable") def foobar(self): return self.fieldA.through.objects.filter(fieldA=self) class ModelB: whatever = models.CharField() </code></pre> <p>I want to implement a function in <code>Model...
0
2016-06-28T17:36:21Z
38,084,330
<p>I don't see anything inefficient about that query, you'll have to debug your problem more precisely.</p> <p>That said, you can achieve the same thing more simply (and equally efficiently) by just using a related name on the through table.</p> <pre><code>class ModelA(models.Model): fieldA = models.ManyToManyFie...
0
2016-06-28T19:05:15Z
[ "python", "sql", "django", "orm", "many-to-many" ]
Best way to pass repeated parameter to a Numpy vectorized function
38,082,936
<p>So, continuing from the discussion @TheBlackCat and I were having in <a href="http://stackoverflow.com/a/38021492/3765319">this answer</a>, I would like to know the best way to pass arguments to a Numpy vectorized function. The function in question is defined thus:</p> <pre><code>vect_dist_funct = np.vectorize(lamb...
3
2016-06-28T17:45:09Z
38,083,226
<p><code>np.vectorize</code> doesn't really help you here. As per the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html" rel="nofollow">documentation</a>:</p> <blockquote> <p>The vectorize function is provided primarily for convenience, not for performance. The implementation is esse...
3
2016-06-28T18:01:32Z
[ "python", "numpy", "optimization", "geopy" ]
django annotate - conditional count
38,082,953
<p>I have a model called 'StoreItem' and a model named 'QuoteItem'. A QuoteItem points on a StoreItem.</p> <p>I'm trying to annotate a counter of how many quote items point on store items, but with conditions to apply on the quote items.</p> <p>I tried something like this:</p> <pre><code>items = items.annotate( ...
2
2016-06-28T17:46:18Z
38,090,100
<p>You need to wrap everything in a <code>Sum</code> statement instead of <code>Count</code> (I find it a bit odd that <code>Count</code> works at all):</p> <pre><code>from django.db.models import Case, IntegerField, Sum, When items = items.annotate( quote_count=Sum( Case( When(quo...
2
2016-06-29T03:55:15Z
[ "python", "django", "django-models", "django-filter", "django-annotate" ]
Can I do a variable assignment and list insertion at the same time in python?
38,082,971
<p>Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.</p> <p>I'm trying the following:</p> <pre><code>dir_list = [ (dir_1 = "&lt;path_...
2
2016-06-28T17:47:14Z
38,083,006
<p>I think the short answer is No. In Python 2.7, an <a href="https://docs.python.org/2/reference/simple_stmts.html#grammar-token-assignment_stmt" rel="nofollow">assignment statement</a> is a statement, so cannot be included in the context of a <a href="https://docs.python.org/2/reference/simple_stmts.html#grammar-tok...
1
2016-06-28T17:49:14Z
[ "python", "python-2.7" ]
Can I do a variable assignment and list insertion at the same time in python?
38,082,971
<p>Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.</p> <p>I'm trying the following:</p> <pre><code>dir_list = [ (dir_1 = "&lt;path_...
2
2016-06-28T17:47:14Z
38,083,011
<p>No. An assignment is not an expression (it doesn't evaluate to anything), so you cannot simultaneously assign to a variable <em>and</em> insert into a list.</p>
1
2016-06-28T17:49:25Z
[ "python", "python-2.7" ]
Can I do a variable assignment and list insertion at the same time in python?
38,082,971
<p>Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.</p> <p>I'm trying the following:</p> <pre><code>dir_list = [ (dir_1 = "&lt;path_...
2
2016-06-28T17:47:14Z
38,083,017
<p>you can deal it with dict:</p> <pre><code>dir_list = [ {"dir_1" : "&lt;path_to_dir_1&gt;", "dir_2" : "&lt;path_to_dir_2&gt;"} ] </code></pre> <p>and if it's must to use list, you can't declare a variable like you did, you can only do this:</p> <pre><code>dir_list = ["&lt;path_to_dir_1&gt;", "&lt;path_to_...
0
2016-06-28T17:49:39Z
[ "python", "python-2.7" ]
Can I do a variable assignment and list insertion at the same time in python?
38,082,971
<p>Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.</p> <p>I'm trying the following:</p> <pre><code>dir_list = [ (dir_1 = "&lt;path_...
2
2016-06-28T17:47:14Z
38,083,078
<p>This is just not possible since what you are trying to do will be considered as an <code>assignment</code>:</p> <pre><code>Python evaluates expressions from left to right. Notice that while evaluating an assignment, the right-hand side is evaluated before the left-hand side. </code></pre> <p>from <a href="https://...
1
2016-06-28T17:53:30Z
[ "python", "python-2.7" ]
Can I do a variable assignment and list insertion at the same time in python?
38,082,971
<p>Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.</p> <p>I'm trying the following:</p> <pre><code>dir_list = [ (dir_1 = "&lt;path_...
2
2016-06-28T17:47:14Z
38,083,121
<p>Your code is confusing, but I don't think you need a dict, you just need a list of paths, which goes like this:</p> <pre><code>dir_list = ['c:/users/me/hi', 'c:/users/you/hi', ...] </code></pre> <p>Then you can iterate over it:</p> <pre><code>for path in dir_list: os.mkdir(path) #or os.mkdirs(path), check the...
0
2016-06-28T17:55:54Z
[ "python", "python-2.7" ]
Can I do a variable assignment and list insertion at the same time in python?
38,082,971
<p>Context: I'd like to specify the names of a bunch of directories that I want my script to make. I'd like to declare these path names as variables and add them to a list, which I will iterate over to make the directories. Python 2.7.5.</p> <p>I'm trying the following:</p> <pre><code>dir_list = [ (dir_1 = "&lt;path_...
2
2016-06-28T17:47:14Z
38,094,033
<p>Without full context of your situation, my preference is to keep it simple.</p> <pre><code>dir_1 = '&lt;path_to_dir_1&gt;' dir_2 = '&lt;path_to_dir_2&gt;' dir_list = [dir_1, dir_2] print dir_list </code></pre> <p>However, as you've explicitly rejected this, my next choice is a dict</p> <pre><code>dir_dict = dict(...
1
2016-06-29T08:18:57Z
[ "python", "python-2.7" ]
Python regex not matching all patterns in string
38,082,986
<p>I want to match a curl command's header pattern like:</p> <blockquote> <p>-H 'key: value'</p> </blockquote> <p>or</p> <blockquote> <p>-H "key: value"</p> </blockquote> <p>This switch can appear in the middle somewhere or at the end of string.</p> <p>My pattern:</p> <pre><code>&gt;&gt;&gt; header_pattern = ...
1
2016-06-28T17:48:00Z
38,083,098
<p>You can use this regex to match all header options:</p> <pre><code>header_pattern = re.compile(r'-H\s*([\'"])(.+?)\1') </code></pre> <p><a href="https://regex101.com/r/qD7eY0/2" rel="nofollow">RegEx Demo</a></p> <p>There is no real need to assert for whitespace before <code>-H</code> but you need you can use:</p>...
2
2016-06-28T17:54:28Z
[ "python", "regex" ]
Python regex not matching all patterns in string
38,082,986
<p>I want to match a curl command's header pattern like:</p> <blockquote> <p>-H 'key: value'</p> </blockquote> <p>or</p> <blockquote> <p>-H "key: value"</p> </blockquote> <p>This switch can appear in the middle somewhere or at the end of string.</p> <p>My pattern:</p> <pre><code>&gt;&gt;&gt; header_pattern = ...
1
2016-06-28T17:48:00Z
38,083,149
<p>Why don't use <a href="https://docs.python.org/3/library/argparse.html" rel="nofollow"><code>argparse</code> module</a> instead of regular expressions:</p> <pre><code>import argparse import shlex parser = argparse.ArgumentParser() parser.add_argument('command') parser.add_argument('url') parser.add_argument('-d',...
4
2016-06-28T17:57:35Z
[ "python", "regex" ]
Permutations with Order
38,083,079
<p>I am trying to write a Python function that performs a function similar to <code>itertools.permutation</code>.</p> <pre><code>import itertools for s in itertools.permutations("TCGA****") print s </code></pre> <p>The ideal output from such a function would be </p> <pre><code>('*','*','*','*','T', 'C','G','A') ...
3
2016-06-28T17:53:32Z
38,083,518
<p>One idea would be to produce all the possible indices for your <code>'*'</code> values with <a href="https://docs.python.org/3/library/itertools.html#itertools.combinations" rel="nofollow"><code>itertools.combinations</code></a> on your list index range, and then construct each possible permutation from those indice...
6
2016-06-28T18:17:52Z
[ "python", "permutation" ]
Permutations with Order
38,083,079
<p>I am trying to write a Python function that performs a function similar to <code>itertools.permutation</code>.</p> <pre><code>import itertools for s in itertools.permutations("TCGA****") print s </code></pre> <p>The ideal output from such a function would be </p> <pre><code>('*','*','*','*','T', 'C','G','A') ...
3
2016-06-28T17:53:32Z
38,083,793
<p>My solution is <strong>much less efficient than Mitch's</strong>, but it is another way to solve the problem, so it might interest you as well.</p> <p>Here is my approach: generate all the possible permutations of "****XXXX" (40320 exactly), then, for each resulting permutation, replace each "X" by the correspondin...
1
2016-06-28T18:35:04Z
[ "python", "permutation" ]
Python Binary Matrix to Excel
38,083,086
<p>I'm trying to export a binary matrix to excel.. I'm using what I've learned from <a href="http://stackoverflow.com/questions/25307848/write-list-of-lists-to-excel-file-using-xlwt">Write list of lists to excel file using xlwt</a></p> <p>and I'm getting an size error well, I have a binary matrix 2221x9947 and the fol...
0
2016-06-28T17:53:46Z
38,083,329
<p>You won't be able to do this using <code>xlwt</code>. Instead, consider exporting to <code>.csv</code> format (either using a library such as <a href="https://docs.python.org/3/library/csv.html" rel="nofollow"><code>csv</code></a>, <a href="http://www.numpy.org/" rel="nofollow"><code>numpy</code></a>, or <a href="ht...
0
2016-06-28T18:06:39Z
[ "python", "excel", "matrix" ]
PyQt5 Python 3.5.0: convert DDS File to QImage
38,083,105
<p>I've been struggling with this for a while now and I feel like I have exhausted all my options so I hope someone can help me with this;</p> <p>I'm trying to load a bunch of DDS files, convert them into QImage objects and display them in a QGraphicsView. So far, I've been making progress but now I've hit a wall I ca...
0
2016-06-28T17:54:41Z
38,118,136
<p>I thought I would post the answer I found seeing as I spent a day and a half searching for this, and it's useful to know about;</p> <p>I ended up solving this using <a href="https://bitbucket.org/pyglet/pyglet/wiki/Download" rel="nofollow">pyglet</a>, which has native support for most image file formats, and can qu...
0
2016-06-30T08:46:43Z
[ "python", "opengl", "pyqt5", "dds-format" ]
Dynamic Instantiation: How to dynamically wire interfaces in myHDL
38,083,166
<p>I'm trying to make a python library for dynamically making a UART interface between a PC and FPGA using pySerial using <strong>myHDL 1.0dev</strong></p> <p>It takes names for datatypes and their properties, and instantiates a RAM block, as well as allow access to read/write commands on the PC. However, I'm running ...
1
2016-06-28T17:58:15Z
38,083,269
<p>So I found out the answer, while I was writing this, and since I think its a useful trick to know I decided to post the question anyways.</p> <pre><code>@block def arbiter(clk,uartbus): modules = [] for key in uartbus.interfaces: #note that there is no @block here! def electrician(rambus=ua...
1
2016-06-28T18:04:07Z
[ "python", "fpga", "myhdl" ]
How do I implement genetic algorithm on grid board to find optimal path
38,083,172
<p>I am preparing algorithms for optimal path finding in terrain with obstacles. Till now i implemented Dijsktra and A* algorithms. Now i have to implement genetic algorithm and I have problem.</p> <p>Firstly I will show you how my map representation looks. There are 7 different kinds of terrain (0- start, 7- end, 1-4...
0
2016-06-28T17:58:36Z
38,096,935
<p>A simple GA-based method for a 2D grid is to fractionate chromosomes (binary strings) into moves, eg:</p> <pre><code>00 = down 10 = left 01 = right 11 = up </code></pre> <p>The <code>run(chromosome)</code> function, given a <code>chromosome</code>, performs the moves from the starting point (code <code>0</code>on ...
3
2016-06-29T10:28:20Z
[ "python", "matrix", "genetic-algorithm", "path-finding" ]
Finding an array elements location in a pandas frame column (a.k.a pd.series)
38,083,227
<p>I have a pandas frame similar to this one: </p> <pre><code>import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) Col1 Col2 Col3 Col4 R1 4 ...
9
2016-06-28T18:01:33Z
38,083,374
<p>This should do it:</p> <pre><code>df.loc[df.Col4.isin(target_array)].index </code></pre> <hr> <p>EDIT:</p> <p>I ran three options: from selected answers. Mine, Bruce Pucci, and Divakar</p> <p><a href="http://i.stack.imgur.com/GdHMa.png"><img src="http://i.stack.imgur.com/GdHMa.png" alt="enter image description...
9
2016-06-28T18:08:47Z
[ "python", "arrays", "numpy", "pandas", "indexing" ]
Finding an array elements location in a pandas frame column (a.k.a pd.series)
38,083,227
<p>I have a pandas frame similar to this one: </p> <pre><code>import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) Col1 Col2 Col3 Col4 R1 4 ...
9
2016-06-28T18:01:33Z
38,083,375
<pre><code>import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} target_array = np.array(['AAA', 'CCC', 'EEE']) df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) df['in_col'] = df['Col4'].apply(lambda x: ...
5
2016-06-28T18:08:48Z
[ "python", "arrays", "numpy", "pandas", "indexing" ]
Finding an array elements location in a pandas frame column (a.k.a pd.series)
38,083,227
<p>I have a pandas frame similar to this one: </p> <pre><code>import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) Col1 Col2 Col3 Col4 R1 4 ...
9
2016-06-28T18:01:33Z
38,083,381
<pre><code>df.index[df.Col4.isin(target_array)] </code></pre>
4
2016-06-28T18:09:07Z
[ "python", "arrays", "numpy", "pandas", "indexing" ]
Finding an array elements location in a pandas frame column (a.k.a pd.series)
38,083,227
<p>I have a pandas frame similar to this one: </p> <pre><code>import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) Col1 Col2 Col3 Col4 R1 4 ...
9
2016-06-28T18:01:33Z
38,083,418
<p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html"><code>NumPy's in1d</code></a> -</p> <pre><code>df.index[np.in1d(df['Col4'],target_array)] </code></pre> <p><strong>Explanation</strong></p> <p>1) Create a <code>1D</code> mask corresponding to each row telling us whether the...
10
2016-06-28T18:11:40Z
[ "python", "arrays", "numpy", "pandas", "indexing" ]
Finding an array elements location in a pandas frame column (a.k.a pd.series)
38,083,227
<p>I have a pandas frame similar to this one: </p> <pre><code>import pandas as pd import numpy as np data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']} df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4']) Col1 Col2 Col3 Col4 R1 4 ...
9
2016-06-28T18:01:33Z
38,084,031
<p>For the sake of completeness I've added two (<code>.query()</code> variants) - my timings against 400K rows df:</p> <pre><code>In [63]: df.shape Out[63]: (400000, 4) In [64]: %timeit df.index[np.in1d(df['Col4'],target_array)] 10 loops, best of 3: 35.1 ms per loop In [65]: %timeit df.index[df.Col4.isin(target_arr...
7
2016-06-28T18:48:20Z
[ "python", "arrays", "numpy", "pandas", "indexing" ]
Custom magic in ipython notebooks - Code does not execute
38,083,229
<p>I am relatively new to ipython magics and want to run some code and at the same time add it to a list through the magic commands. The magics are defined as follows</p> <pre><code>#iPython notebook magic from IPython.core.magic import ( Magics, magics_class, cell_magic, line_magic ) @magics_class class ReportM...
0
2016-06-28T18:01:41Z
38,087,731
<p>I have been able to get a work around it. To execute a code through the magic function one has to call run_cell instance for the ipython object. There can be better ways of doing it but the code works for now.</p> <pre><code>@cell_magic @needs_local_scope def add_conf_code_to_report(self, line, cell): """store ...
0
2016-06-28T23:12:04Z
[ "python", "ipython" ]
Using unicode / umlauts in Python: Dictionary v manual input
38,083,280
<p>I am using a dictionary to store some character pairs in Python (I am replacing umlaut characters). Here is what it looks like:</p> <pre><code>umlautdict={ 'ae': 'ä', 'ue': 'ü', 'oe': 'ö' } </code></pre> <p>Then I run my inputwords through it like so:</p> <pre><code>for item in umlautdict.keys(...
-2
2016-06-28T18:04:25Z
38,083,479
<ol> <li>Declare your coding.</li> <li>Use <strong>raw</strong> format for the special characters.</li> <li>Iterate properly on your string: keep the changes from each loop iteration as you head to the next.</li> </ol> <p>Here's code to get the job done:</p> <pre><code>\# -*- coding: utf-8 -*- umlautdict = { 'ae...
2
2016-06-28T18:15:18Z
[ "python", "dictionary", "unicode", "replace", "character-encoding" ]
Using unicode / umlauts in Python: Dictionary v manual input
38,083,280
<p>I am using a dictionary to store some character pairs in Python (I am replacing umlaut characters). Here is what it looks like:</p> <pre><code>umlautdict={ 'ae': 'ä', 'ue': 'ü', 'oe': 'ö' } </code></pre> <p>Then I run my inputwords through it like so:</p> <pre><code>for item in umlautdict.keys(...
-2
2016-06-28T18:04:25Z
38,088,673
<p>Converting to Unicode is done by <em>decoding</em> your string (assuming you're getting bytes):</p> <pre><code>data = "haer ueber loess" word = data.decode('utf-8') # actual encoding depends on your data </code></pre> <p>Define your dict with unicode strings as well:</p> <pre><code>umlautdict={ u'ae': u'ä',...
3
2016-06-29T01:05:13Z
[ "python", "dictionary", "unicode", "replace", "character-encoding" ]
Python decoding issue with Chinese characters
38,083,376
<p>I'm using Python 3.5, and I'm trying to take a block of byte text that may or may not contain special Chinese characters and output it to a file. It works for entries that do not contain Chinese characters, but breaks when they do. The Chinese characters are always a person's name, and are always in addition to the...
5
2016-06-28T18:08:55Z
38,132,848
<p><strong>Warning: shotgun solution ahead</strong> </p> <p>Assuming you just want to get rid of all foreign character in all your file ( that is they are not important for your future processing of all other fields), you can simply ignore all non ascii characters</p> <pre><code>recipientData = json.loads(recipientCo...
0
2016-06-30T20:39:28Z
[ "python", "python-3.x", "encoding", "python-unicode" ]
Python decoding issue with Chinese characters
38,083,376
<p>I'm using Python 3.5, and I'm trying to take a block of byte text that may or may not contain special Chinese characters and output it to a file. It works for entries that do not contain Chinese characters, but breaks when they do. The Chinese characters are always a person's name, and are always in addition to the...
5
2016-06-28T18:08:55Z
38,169,084
<p>The error you're getting is when you're writing to the file.</p> <p>In Python 3.x, when you <code>open()</code> in text mode (the default) without specifying an <code>encoding=</code>, Python will use an encoding most suitable to your locale or language settings.</p> <p>If you're on Windows, this will use the <cod...
0
2016-07-03T10:35:58Z
[ "python", "python-3.x", "encoding", "python-unicode" ]
Python decoding issue with Chinese characters
38,083,376
<p>I'm using Python 3.5, and I'm trying to take a block of byte text that may or may not contain special Chinese characters and output it to a file. It works for entries that do not contain Chinese characters, but breaks when they do. The Chinese characters are always a person's name, and are always in addition to the...
5
2016-06-28T18:08:55Z
38,169,114
<p>Add this line to your code :</p> <pre><code>from __future__ import unicode_literals </code></pre>
0
2016-07-03T10:40:55Z
[ "python", "python-3.x", "encoding", "python-unicode" ]
Variables that have been assigned in a line.split() command, are not read into a function
38,083,454
<p>In this code the variables <code>pressure</code> and <code>enthalpy</code>, that come from a <code>[float(n) for n in line.split()]</code> command, are not read into a function:</p> <pre><code>import numpy as np pressure_gibbs = open('pressure_gibbs_all_points.dat', 'w') pressure_gibbs.write('#pressure gibbs\n...
0
2016-06-28T18:13:45Z
38,083,803
<p>your output file seems to show values that match the math in your code, so the only thing I can see is that you have 9 calculations where you were expecting 3. This is because you have a nested loop, so you are first looping over pressure, and and then looping over entropy. So you calculate Gibbs for 3 values of e...
2
2016-06-28T18:35:45Z
[ "python", "io", "lines" ]
Variables that have been assigned in a line.split() command, are not read into a function
38,083,454
<p>In this code the variables <code>pressure</code> and <code>enthalpy</code>, that come from a <code>[float(n) for n in line.split()]</code> command, are not read into a function:</p> <pre><code>import numpy as np pressure_gibbs = open('pressure_gibbs_all_points.dat', 'w') pressure_gibbs.write('#pressure gibbs\n...
0
2016-06-28T18:13:45Z
38,132,138
<p>I think its time you dug a bit more into numpy and why the combination of numpy and python are awesome. This code does what you are looking for. There's a lot here, so you'll have to just spend time digesting it. I created a new answer because the original answer has specifics about your first question, but the b...
1
2016-06-30T19:54:44Z
[ "python", "io", "lines" ]
How can I get this Django template to render?
38,083,483
<p>In <a href="http://stackoverflow.com/questions/38082128/why-is-django-blocktrans-working-one-place-and-not-another">Why is Django blocktrans working one place and not another?</a>, I asked a similar question and accepted an answer after a "use i18n" response that resolved the behavior in question. Here, I am getting...
1
2016-06-28T18:15:26Z
38,088,321
<p>Define your <code>{{ other_user_display }}</code> variable within the blocktrans tag. Second example from <a href="https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#blocktrans-template-tag" rel="nofollow">https://docs.djangoproject.com/en/1.9/topics/i18n/translation/#blocktrans-template-tag</a></p>
1
2016-06-29T00:18:58Z
[ "python", "django", "django-templates", "pinax", "pinax-social" ]
Run a Python 2.7 Script on a Webpage
38,083,487
<p>I have a couple of Python 2.7 scripts I need to have them run from a webpage. I've never done this before, although I'm comfortable coding in Python and well versed in Linux, Apache, Nginx.</p> <p>I see many different frameworks like the old CGI, WSGI, Django, etc. I need some recommendations for a framework that w...
0
2016-06-28T18:15:39Z
38,083,526
<p><a href="http://flask.pocoo.org/" rel="nofollow">Flask</a> is probably the most straightforward Python web framework to use. It touts itself as a <em>micro framework</em>, and is very, very fast to get up and running with.</p> <p>If you have a relatively straightforward set of requirements, I'd highly recommend giv...
2
2016-06-28T18:18:22Z
[ "python", "django", "cgi", "wsgi" ]
Run a Python 2.7 Script on a Webpage
38,083,487
<p>I have a couple of Python 2.7 scripts I need to have them run from a webpage. I've never done this before, although I'm comfortable coding in Python and well versed in Linux, Apache, Nginx.</p> <p>I see many different frameworks like the old CGI, WSGI, Django, etc. I need some recommendations for a framework that w...
0
2016-06-28T18:15:39Z
38,084,748
<p>If you're looking for client side browser frameworks in Python, there are <a href="http://www.skulpt.org/" rel="nofollow">skulpt</a> and <a href="http://www.brython.info/" rel="nofollow">brython</a>.</p> <p>When I was looking for a similar framework, I decided to learn leave python for a javascript framework (parti...
0
2016-06-28T19:29:25Z
[ "python", "django", "cgi", "wsgi" ]
cannot import name ExtendedInterpolation
38,083,498
<p>Interestingly, on my machine (OSX) importing the package hgvs runs smoothly, even though I'm working on python 2.7 (and ExtendedInterpolation is a python 3 function from configparser). As far as what I've gathered, it simply uses a backport of Python 3's configparser module, so it should work anyways if Python 3 is ...
0
2016-06-28T18:16:13Z
39,373,083
<p>According to <a href="https://bitbucket.org/ambv/configparser/issues/8/configparser-import-broken-on-py27" rel="nofollow">this</a> the problem is that:</p> <blockquote> <p>Unfortunately in 0.14.0 they broke the configparser import by introducing their own.</p> </blockquote> <p>To resolve it, I downgraded the fut...
0
2016-09-07T14:48:42Z
[ "python", "importerror" ]
How to Set spark.sql.parquet.output.committer.class in pyspark
38,083,563
<p>I'm trying to set <a href="http://spark.apache.org/docs/latest/sql-programming-guide.html#configuration" rel="nofollow">spark.sql.parquet.output.committer.class</a> and nothing I do seems to get the setting to take effect.</p> <p>I'm trying to have many threads write to the same output folder, which would work with...
4
2016-06-28T18:21:17Z
38,084,357
<p>The approach in <a href="http://stackoverflow.com/questions/35589176/spark-1-6-on-emr-writing-to-s3-as-parquet-hangs-and-fails">this comment</a> definitively worked for me:</p> <pre><code>16/06/28 18:49:59 INFO ParquetRelation: Using user defined output committer for Parquet: org.apache.spark.sql.execution.datasour...
1
2016-06-28T19:06:44Z
[ "python", "apache-spark", "pyspark", "parquet", "pyspark-sql" ]
Grep a string in python
38,083,573
<p>Friends,</p> <p>I have a situation where i need to grep a word from a string</p> <pre><code>[MBeanServerInvocationHandler]com.bea:Name=itms2md01,Location=hello,Type=ServerRuntime </code></pre> <p>What I want to grep is the word that assigned to the variable <code>Name</code> in the above string which is <code>itm...
1
2016-06-28T18:21:53Z
38,083,939
<p>Deak is right. As I am not having enough reputation to comment, I am depicting it below. I am not going to the file level. Just see as an instance:-</p> <pre><code>import re str1 = "[MBeanServerInvocationHandler]com.bea:Name=itms2md01,Location=hello,Type=ServerRuntime" pat = '(?&lt;=Name=)\w+(?=,)' print re.sear...
0
2016-06-28T18:44:03Z
[ "python", "bash", "python-2.7" ]
Grep a string in python
38,083,573
<p>Friends,</p> <p>I have a situation where i need to grep a word from a string</p> <pre><code>[MBeanServerInvocationHandler]com.bea:Name=itms2md01,Location=hello,Type=ServerRuntime </code></pre> <p>What I want to grep is the word that assigned to the variable <code>Name</code> in the above string which is <code>itm...
1
2016-06-28T18:21:53Z
38,084,027
<p>I like to use named groups, because I'm often searching for more than one thing. But even for one item in the search, it still works nicely, and I can remember very easily what I was searching for.</p> <p>I'm not certain that I fully understand the question, but if you are saying that the user can pass a key to sea...
0
2016-06-28T18:48:10Z
[ "python", "bash", "python-2.7" ]
Brute Force Generator Doesn't Tell When Password Was Guessed
38,083,575
<p>Alright so I'm testing a brute force algorithm I made in python. The only problem is when it gets the password I wanted it to get instead of printing out 'Password Is Correct : Password' it goes on listing the other possible options. Doesn't even pause. Here's the code:</p> <pre><code>import itertools import os le...
-1
2016-06-28T18:21:56Z
38,083,713
<p>You need <code>itertools.product(chars, repeat=i)</code>, because you want permutations, not combinations with replacement.</p> <p>You can read more about the difference between permutations, combinations, etc on <a href="http://www.mathsisfun.com/combinatorics/combinations-permutations.html" rel="nofollow">MathIsF...
2
2016-06-28T18:29:41Z
[ "python", "algorithm", "python-3.x", "brute-force" ]
How to change numpy array dtype and reshape?
38,083,644
<p>I have an array that I read from an HDF5 file, and it is a 1D array of tuples. Its dtype is:</p> <pre><code>[('cycle', '&lt;u2'), ('dxn', 'i1'), ('i (mA)', '&lt;f4'), ('V', '&lt;f4'), ('R(Ohm)', '&lt;f4')] </code></pre> <p>I would like to convert this from an n x 1 array into a (n/5) x 5 array of type np.float.</...
1
2016-06-28T18:26:45Z
38,090,370
<p>The mix of dtypes makes this conversion trickier than usual. The answer at the end, copying fields to a target array has the combination of speed and generality.</p> <p><a href="http://stackoverflow.com/questions/5957380/convert-structured-array-to-regular-numpy-array">Convert structured array to regular NumPy arr...
0
2016-06-29T04:25:14Z
[ "python", "arrays", "numpy" ]
Set intersection of object dropping keys
38,083,667
<p>I'm trying to perform some set operations using this object. </p> <pre><code>def Group(object): def __init__(self, name, email, description, skip_if_deleted, membership=None) self.name = name self.email = remove_special_characters(email.lower(), bad_chars) self.description = description self.actio...
0
2016-06-28T18:27:55Z
38,083,805
<p>The quick-fix would be to use a set comprehension:</p> <pre><code>common_groups = {group for group in populated_membership if group in unpopulated_membership} </code></pre> <p>I would recommend choosing a different way to represent your data, though. For example, using dicts to match email a...
1
2016-06-28T18:35:51Z
[ "python", "set" ]
How to customize pybusyinfo window in (windows OS) to make it appear at top corner of window and the other formatting options?
38,083,670
<p>I am writing a python script to get the climate conditions in particular area every 30 minutes and give a popup notification.</p> <p>This code gives popup at the center of the screen which is annoying.I wish to have the popup similar to notify-send in linux[which appears at right corner] and the message is aligned ...
0
2016-06-28T18:27:57Z
38,083,828
<pre><code>screen_size = wx.DisplaySize() d_size = d._infoFrame.GetSize() pos_x = screen_size[0] - d_size[0] # Right - popup.width (aligned to right side) pos_y = screen_size[1] - d_size[1] # Bottom - popup.height (aligned to bottom) d.SetPosition((pos_x,pos_t)) d.Update() # force redraw ... (otherwise your "work " wil...
0
2016-06-28T18:37:19Z
[ "python", "python-2.7", "wxpython", "notify" ]
Turn grid into a checkerboard pattern in python?
38,083,788
<p>I have successfully created a grid, but am now trying to turn my grid into a checkerboard pattern, preferably using a variant of the floodfill command. <br><br> how do I make sure the program recognizes which squares are even and which are odd? <br> <br> currently the IDE is set so <code>m[i][j]= 1</code> gives blue...
2
2016-06-28T18:34:52Z
38,083,912
<p>You can check the sum of the two indices (row and column) and color it with the first color if it's odd and second otherwise. Something like:</p> <pre><code>for i in range(nrows): for j in range(ncols): m[i][j] = 0 if (i+j)%2 else 1 </code></pre>
0
2016-06-28T18:42:20Z
[ "python", "python-2.7", "python-3.x", "numpy", "matplotlib" ]
Turn grid into a checkerboard pattern in python?
38,083,788
<p>I have successfully created a grid, but am now trying to turn my grid into a checkerboard pattern, preferably using a variant of the floodfill command. <br><br> how do I make sure the program recognizes which squares are even and which are odd? <br> <br> currently the IDE is set so <code>m[i][j]= 1</code> gives blue...
2
2016-06-28T18:34:52Z
38,083,915
<p>Use the modulus operation:</p> <pre><code>m[i][j] = (i+j) % 2 </code></pre>
0
2016-06-28T18:42:38Z
[ "python", "python-2.7", "python-3.x", "numpy", "matplotlib" ]
Turn grid into a checkerboard pattern in python?
38,083,788
<p>I have successfully created a grid, but am now trying to turn my grid into a checkerboard pattern, preferably using a variant of the floodfill command. <br><br> how do I make sure the program recognizes which squares are even and which are odd? <br> <br> currently the IDE is set so <code>m[i][j]= 1</code> gives blue...
2
2016-06-28T18:34:52Z
38,084,594
<p>I would create a linear array, fill every second value and reshape. In your case (even amount of columns), prepend one column and get rid of it after reshaping: </p> <pre><code>import numpy as np rows = 100 cols = 100 + 1 # product of rows*cols must be odd, we fix it later m = np.zeros((rows*cols, 1)) # create ...
0
2016-06-28T19:19:13Z
[ "python", "python-2.7", "python-3.x", "numpy", "matplotlib" ]
Turn grid into a checkerboard pattern in python?
38,083,788
<p>I have successfully created a grid, but am now trying to turn my grid into a checkerboard pattern, preferably using a variant of the floodfill command. <br><br> how do I make sure the program recognizes which squares are even and which are odd? <br> <br> currently the IDE is set so <code>m[i][j]= 1</code> gives blue...
2
2016-06-28T18:34:52Z
38,084,622
<p>You can create a checkerboard style array with NumPy, then resize it with <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.misc.imresize.html" rel="nofollow"><code>scipy's imresize</code></a> to make that equal to your desired canvas area.</p> <p>Thus, the steps would be :</p> <p>1) Create a NumP...
0
2016-06-28T19:21:41Z
[ "python", "python-2.7", "python-3.x", "numpy", "matplotlib" ]
Multiway frequency function in Python?
38,083,902
<p>This is my function:</p> <pre><code>def freq(*var): from functools import reduce from operator import getitem for c,i in enumerate(reversed(var)): d={k:0 for k in set(i)} if c==0 else {k:d for k in set(i)} for row in zip(*var): *k,last_k=row reduce(getitem,k,d)[last_k]+=1 ...
1
2016-06-28T18:41:12Z
38,084,284
<p>You've somehow initialized <strong>d</strong>'s values to the same dictionary. I can't fix this confidently, since I don't have Python3 installed here (blush). However, I think the problem is that <strong>k:d</strong> value in the middle line: I think it plugs the identical default dictionary into each value. Try...
0
2016-06-28T19:03:04Z
[ "python", "function" ]
Multiway frequency function in Python?
38,083,902
<p>This is my function:</p> <pre><code>def freq(*var): from functools import reduce from operator import getitem for c,i in enumerate(reversed(var)): d={k:0 for k in set(i)} if c==0 else {k:d for k in set(i)} for row in zip(*var): *k,last_k=row reduce(getitem,k,d)[last_k]+=1 ...
1
2016-06-28T18:41:12Z
38,084,363
<p>Apparently, the inner dict is referencing the same object and everything gets updated simultenously, as seen from the <code>enumerate</code> loop:</p> <pre><code>for c,i in enumerate(reversed(var)): d={k:0 for k in set(i)} if c==0 else {k:d for k in set(i)} # ^ </cod...
0
2016-06-28T19:07:10Z
[ "python", "function" ]
Multiway frequency function in Python?
38,083,902
<p>This is my function:</p> <pre><code>def freq(*var): from functools import reduce from operator import getitem for c,i in enumerate(reversed(var)): d={k:0 for k in set(i)} if c==0 else {k:d for k in set(i)} for row in zip(*var): *k,last_k=row reduce(getitem,k,d)[last_k]+=1 ...
1
2016-06-28T18:41:12Z
38,084,792
<p>The problem is that all nested dicts in <code>d</code> dict is the same object. Use <a href="https://docs.python.org/3/library/stdtypes.html?highlight=dict.copy#dict.copy" rel="nofollow">dict.copy()</a> method to fix problem, so changing line:</p> <pre><code>d={k:0 for k in set(i)} if c==0 else {k:d for k in set(i)...
2
2016-06-28T19:31:46Z
[ "python", "function" ]
How to get rid of sympy substitute error message?
38,083,933
<p>I have an annoying error message that I cannot figure it out. The following code (in Python 3) gives a correct results:</p> <pre><code>from sympy import * x, y, z, t = symbols('x y z t') expr = cos(x) + 1 print(expr.subs(x, y)) </code></pre> <p>The results are: </p> <pre><code>cos(y) + 1 </code></pre> <p>Howev...
1
2016-06-28T18:43:49Z
38,084,042
<p>The <code>1</code> in your second example is not a SymPy number, just a regular Python integer.</p> <p>You can use the <code>S()</code> (or <code>sympify()</code>) function to turn it into a SymPy number.</p> <p>The official docs have a <a href="http://docs.sympy.org/latest/gotchas.html#python-numbers-vs-sympy-num...
2
2016-06-28T18:49:01Z
[ "python", "sympy" ]
How to get rid of sympy substitute error message?
38,083,933
<p>I have an annoying error message that I cannot figure it out. The following code (in Python 3) gives a correct results:</p> <pre><code>from sympy import * x, y, z, t = symbols('x y z t') expr = cos(x) + 1 print(expr.subs(x, y)) </code></pre> <p>The results are: </p> <pre><code>cos(y) + 1 </code></pre> <p>Howev...
1
2016-06-28T18:43:49Z
38,084,048
<p><code>1</code> is not a Sympy expression. <code>1</code> is just a regular Python int. You will need to wrap it in a Sympy Integer if you want to perform substitutions on it. (Also, stop using <code>import *</code>.):</p> <pre><code>import sympy expr = sympy.Integer(1) </code></pre> <p>Note that Sympy Integers di...
1
2016-06-28T18:49:15Z
[ "python", "sympy" ]
How to get rid of sympy substitute error message?
38,083,933
<p>I have an annoying error message that I cannot figure it out. The following code (in Python 3) gives a correct results:</p> <pre><code>from sympy import * x, y, z, t = symbols('x y z t') expr = cos(x) + 1 print(expr.subs(x, y)) </code></pre> <p>The results are: </p> <pre><code>cos(y) + 1 </code></pre> <p>Howev...
1
2016-06-28T18:43:49Z
38,085,161
<p>As in the other answers, <code>1</code> is not a SymPy integer, it's a Python integer. Therefore it doesn't have SymPy's methods.</p> <p>You could declare <code>expr</code> as one of the following to make it work:</p> <ul> <li><code>expr = S.One</code></li> <li><code>expr = S(1)</code></li> <li><code>expr = Intege...
0
2016-06-28T19:53:36Z
[ "python", "sympy" ]
PySpark Evaluation
38,083,990
<p>I am trying the following code which adds a number to every row in an RDD and returns a list of RDDs using PySpark. </p> <pre><code>from pyspark.context import SparkContext file = "file:///home/sree/code/scrap/sample.txt" sc = SparkContext('local', 'TestApp') data = sc.textFile(file) splits = [data.map(lambda p :...
5
2016-06-28T18:46:24Z
38,085,794
<p>It happens because of Python late binding and is not (Py)Spark specific. <code>i</code> will be looked-up when <code>lambda p : int(p) + i</code> is used, not when it is defined. Typically it means when it is called but in this particular context it is when it is serialized to be send to the workers.</p> <p>You ca...
3
2016-06-28T20:33:46Z
[ "python", "apache-spark", "pyspark" ]
PySpark Evaluation
38,083,990
<p>I am trying the following code which adds a number to every row in an RDD and returns a list of RDDs using PySpark. </p> <pre><code>from pyspark.context import SparkContext file = "file:///home/sree/code/scrap/sample.txt" sc = SparkContext('local', 'TestApp') data = sc.textFile(file) splits = [data.map(lambda p :...
5
2016-06-28T18:46:24Z
38,086,024
<p>This is due to to the fact that lambdas refer to the i via reference! It has nothing to do with spark. <a href="http://stackoverflow.com/a/34021333/3534616">See this</a></p> <p>You can try this:</p> <pre><code>a =[(lambda y: (lambda x: y + int(x)))(i) for i in range(4)] splits = [data.map(a[x]) for x in range(4)] ...
2
2016-06-28T20:47:30Z
[ "python", "apache-spark", "pyspark" ]
How to covert curl into a python code with native library 2.7
38,083,992
<p>How do i convert the below curl into python code. I am confused on how to include the api key, i know what value it should be. The python code must only contain native libraries</p> <pre><code>curl -G -H "api_key: YOUR_API_KEY" https://api.semantics3.com/test/v1/products --data-urlencode 'q={"search":"apple iphone...
-1
2016-06-28T18:46:39Z
38,084,090
<p>The easiest and convenient way is to use requests library in python. Just import the requests library and you can do all REST operations</p> <p>Example:-</p> <pre><code>&gt;&gt;&gt; r = requests.get('https://api.github.com/user', auth=('user', 'pass')) &gt;&gt;&gt; r.status_code 200 &gt;&gt;&gt; r.headers['content...
3
2016-06-28T18:50:55Z
[ "python", "python-2.7", "api", "curl" ]
How to covert curl into a python code with native library 2.7
38,083,992
<p>How do i convert the below curl into python code. I am confused on how to include the api key, i know what value it should be. The python code must only contain native libraries</p> <pre><code>curl -G -H "api_key: YOUR_API_KEY" https://api.semantics3.com/test/v1/products --data-urlencode 'q={"search":"apple iphone...
-1
2016-06-28T18:46:39Z
38,085,471
<p>i am going to use the requests library. I can send the request but i caannot send the same api key that works when i curl as it comes with an error message invalid api</p> <p>the python code... which throws up invalid api key error despite using the same key as curl code</p> <pre><code>import requests payload = ...
-1
2016-06-28T20:13:50Z
[ "python", "python-2.7", "api", "curl" ]
Cerberus schema validation dependency depending of self value
38,084,005
<p>I know that according to the Cerberus <a href="http://docs.python-cerberus.org/en/latest/validation-rules.html#dependencies" rel="nofollow">documentation</a>, it is possible to define validation dependencies, according to other keys values, such as:</p> <pre><code>schema = {'field1': {'required': False}, 'field2': ...
1
2016-06-28T18:47:15Z
38,168,509
<p>This could probably be solved by using <code>dependencies</code> in conjunction with <code>oneof</code> (<a href="http://docs.python-cerberus.org/en/stable/usage.html#anyof" rel="nofollow">docs</a>) rule. </p> <p>However, there's currently an issue which might prevent this solution from working (<a href="https://gi...
2
2016-07-03T09:19:15Z
[ "python", "cerberus" ]
Cannot run pyspark in Jupyter
38,084,030
<p>I have Windows 10 and have installed spark following the instructions from:</p> <p><a href="https://hernandezpaul.wordpress.com/2016/01/24/apache-spark-installation-on-windows-10/" rel="nofollow">https://hernandezpaul.wordpress.com/2016/01/24/apache-spark-installation-on-windows-10/</a></p> <p>Now I open my jupyte...
1
2016-06-28T18:48:13Z
38,103,252
<p>This has been resolved by installing winutils.exe as described in</p> <p><a href="https://blogs.msdn.microsoft.com/arsen/2016/02/09/resolving-spark-1-6-0-java-lang-nullpointerexception-not-found-value-sqlcontext-error-when-running-spark-shell-on-windows-10-64-bit/" rel="nofollow">Resolving Spark 1.6.0 "java.lang.Nu...
0
2016-06-29T14:57:02Z
[ "python", "python-2.7", "apache-spark", "jupyter" ]
Save reference field mongoengine
38,084,136
<p>Simplified, I have 2 Document objects: <code>Resource</code> and <code>Cable</code></p> <pre><code>class Cable(db.Document): _id = db.ObjectIdField() socket = db.EmbeddedDocumentField(Socket) class Resource(db.Document): _id = db.StringField() cable = db.ReferenceField('Cable') </code></pre> <p>Bo...
0
2016-06-28T18:53:32Z
38,094,864
<p>Tried with this workaround passing the <code>DBRef</code> of the document and it works. </p> <pre><code>@resources.route('/&lt;r_id&gt;/add_cabling', methods=['GET']) def set_connector(r_id): r = Resource.objects(id=r_id).get() c = Cable.objects().first() c.save() #revalidate here r.cable=c.to_dbref...
0
2016-06-29T09:00:48Z
[ "python", "mongodb", "flask", "mongoengine" ]