title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Can Dask provide a speedup for 1D arrays? | 39,344,258 | <p>When working on 2D data, I see a slight speed-up on 2D arrays, but even on large 1D arrays that advantage disappears.</p>
<p>E.g., in 2D:</p>
<pre><code>In [48]: x = np.random.random((3000, 2000))
In [49]: X = da.from_array(x, chunks=(500,500))
In [50]: %timeit (np.cumsum(x - x**2, axis=0))
10 loops, best of 3:... | 1 | 2016-09-06T08:33:27Z | 39,348,023 | <p>Your FLOP/Byte ratio is still too low. The CPU isn't the bottleneck, your memory hierarchy is. </p>
<p>Additionally, chunksizes of (2000,) are just too small for Dask.array to be meaningful. Recall that dask introduces an overhead of a few hundred microseconds per task, so each task you do should be significantl... | 3 | 2016-09-06T11:30:56Z | [
"python",
"dask"
] |
Cycling through a list of IP addresses | 39,344,401 | <p>I have the below code, which will go and look in the .txt file for the IP address and then go to the device and return the commands, it will then print to the file requested and everything works.</p>
<p>What i cant get it to do is loop through a series of IP addresses and return the commands for different devices. ... | -1 | 2016-09-06T08:40:21Z | 39,344,709 | <p>My guess is that your <code>ConnectHandler</code> does not appreciate that there is a newline character at the end of your <code>host</code> string.</p>
<p>Try this:</p>
<pre><code>for host in ip_add_file:
host = host.strip()
...
</code></pre>
| 1 | 2016-09-06T08:54:42Z | [
"python",
"python-3.x",
"cisco"
] |
for loop stuck and not interating (Python 3) | 39,344,596 | <p>I'm currently working on a small script that aims to find taxicab numbers. There is only one small problem, the for loop doesn't increment the variable x and is stuck looping forever. I'll paste the relevant part of the code below:</p>
<pre><code>n = int(10)
counter = int(0)
m = int(m)
x = int(1)
y = int(n**(1/3))
... | 0 | 2016-09-06T08:49:19Z | 39,345,745 | <p>This has a number of issues wrong with it I'm not willing to post functional code but I will point some of the issues out. </p>
<p>For starters:</p>
<pre><code>n = int(10)
</code></pre>
<p>isn't required, not an error but redundant. Use <code>n = 10</code> with the same effect. </p>
<p>Then:</p>
<pre><code>whil... | 2 | 2016-09-06T09:43:04Z | [
"python",
"python-3.x",
"for-loop",
"increment"
] |
Django Rest Framework API by accept multiple input and output multiple data | 39,344,630 | <p>I am two months with Django and API Rest Framework.
I am developing an API to accept (userid and week_number), and output with (week_number and status).</p>
<p>This is my model:</p>
<pre><code>class Timesheet(models.Model):
userid = models.ForeignKey(User)
week_number = models.CharField(max_length=2)
s... | 0 | 2016-09-06T08:50:40Z | 39,346,533 | <p>This would be the general route to getting what you want. </p>
<p>in models.py</p>
<pre><code>class Timesheet(models.Model):
userid = models.ForeignKey(User)
week_number = models.CharField(max_length=2)
status = models.CharField(max_length=255)
</code></pre>
<p>in serializer.py:</p>
<pre><code>class ... | 0 | 2016-09-06T10:18:37Z | [
"python",
"django",
"django-rest-framework"
] |
Python IndexError: string index out of range | 39,344,633 | <p>Can someone help me why is it saying: "IndexError: string index out of range"
When I add the "letterCount += 1" to the first else it makes this error, without it is working.</p>
<p>The goal is to count "bob"s in s.</p>
<p>Thanks!</p>
<pre><code>s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk'
vowelCount = 0
l... | 0 | 2016-09-06T08:51:06Z | 39,344,759 | <p>You need to check the string s length with something like:</p>
<pre><code>letterCount+2 <= len(s)
</code></pre>
<p>i.e.</p>
<pre><code>s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk'
vowelCount = 0
letterCount = 0
pointer = s
for pointer in s:
print(pointer)
if pointer == 'b':
print (s... | 0 | 2016-09-06T08:56:43Z | [
"python"
] |
Python IndexError: string index out of range | 39,344,633 | <p>Can someone help me why is it saying: "IndexError: string index out of range"
When I add the "letterCount += 1" to the first else it makes this error, without it is working.</p>
<p>The goal is to count "bob"s in s.</p>
<p>Thanks!</p>
<pre><code>s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk'
vowelCount = 0
l... | 0 | 2016-09-06T08:51:06Z | 39,345,747 | <p>I hope the following code will work for you.</p>
<pre><code>s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk'
vowelCount = 0
letterCount = 0
pointer = s
print len(s)
for pointer in s:
if pointer == 'b':
if (len(s) != letterCount+1 and len(s) != letterCount+2):
if (s[letterCount+1] ... | 0 | 2016-09-06T09:43:06Z | [
"python"
] |
Python IndexError: string index out of range | 39,344,633 | <p>Can someone help me why is it saying: "IndexError: string index out of range"
When I add the "letterCount += 1" to the first else it makes this error, without it is working.</p>
<p>The goal is to count "bob"s in s.</p>
<p>Thanks!</p>
<pre><code>s = 'oobobodobooobobobobabobbobbobobbobbobhbxbobbk'
vowelCount = 0
l... | 0 | 2016-09-06T08:51:06Z | 39,347,253 | <pre><code>The final solution.
s = 'obbobbbocbobbogboobm'
vowelCount = 0
letterCount = 0
pointer = s
for pointer in s:
print(pointer)
if pointer == 'b':
print (str(letterCount) + '. betű B' )
if (len(s)-2 > letterCount):
print('van utána két betű')
if (... | 0 | 2016-09-06T10:53:02Z | [
"python"
] |
Open URLs on chrome | 39,344,725 | <p>I have a .csv file that contains a column of urls (40-50 urls), I want to read the csv file and open all those urls on chrome? Is there a way to accomplish this in python? I'm using the following piece of code to read the csv file.</p>
<pre><code>exampleFile = open('MyFile.csv')
exampleReader = csv.reader(exampleF... | 0 | 2016-09-06T08:55:23Z | 39,344,819 | <p>You can use selenium with Chrome web driver
<a href="https://sites.google.com/a/chromium.org/chromedriver/getting-started" rel="nofollow">https://sites.google.com/a/chromium.org/chromedriver/getting-started</a></p>
| 0 | 2016-09-06T08:59:36Z | [
"python"
] |
Open URLs on chrome | 39,344,725 | <p>I have a .csv file that contains a column of urls (40-50 urls), I want to read the csv file and open all those urls on chrome? Is there a way to accomplish this in python? I'm using the following piece of code to read the csv file.</p>
<pre><code>exampleFile = open('MyFile.csv')
exampleReader = csv.reader(exampleF... | 0 | 2016-09-06T08:55:23Z | 39,344,821 | <p>You can use selenium. First install selenium by <code>pip install selenium</code>. The following code open <a href="http://www.python.org" rel="nofollow">http://www.python.org</a> in mozilla firefox.You can change driver to chrome driver in selenium to open links in chrome. For chrome you can see <a href="http://sta... | 0 | 2016-09-06T08:59:45Z | [
"python"
] |
Open URLs on chrome | 39,344,725 | <p>I have a .csv file that contains a column of urls (40-50 urls), I want to read the csv file and open all those urls on chrome? Is there a way to accomplish this in python? I'm using the following piece of code to read the csv file.</p>
<pre><code>exampleFile = open('MyFile.csv')
exampleReader = csv.reader(exampleF... | 0 | 2016-09-06T08:55:23Z | 39,345,030 | <p>You can use <a href="http://www.seleniumhq.org/" rel="nofollow"><code>selenium</code></a> web driver to load each URL in chrome.</p>
<p>Reading the csv file can be improved like this:</p>
<pre><code>from selenium import webdriver
driver = webdriver.Chrome()
with open('MyFile.csv') as example_file:
example_re... | 1 | 2016-09-06T09:10:44Z | [
"python"
] |
Open URLs on chrome | 39,344,725 | <p>I have a .csv file that contains a column of urls (40-50 urls), I want to read the csv file and open all those urls on chrome? Is there a way to accomplish this in python? I'm using the following piece of code to read the csv file.</p>
<pre><code>exampleFile = open('MyFile.csv')
exampleReader = csv.reader(exampleF... | 0 | 2016-09-06T08:55:23Z | 39,345,081 | <p>Assuming your posted snippet is alright and <code>final</code> contains valid urls you could do something like this:</p>
<pre><code>import webbrowser
exampleFile = open('MyFile.csv')
exampleReader = csv.reader(exampleFile)
exampleData = list(exampleReader)
final = []
for item in exampleData:
final.append(item... | 1 | 2016-09-06T09:12:48Z | [
"python"
] |
Open URLs on chrome | 39,344,725 | <p>I have a .csv file that contains a column of urls (40-50 urls), I want to read the csv file and open all those urls on chrome? Is there a way to accomplish this in python? I'm using the following piece of code to read the csv file.</p>
<pre><code>exampleFile = open('MyFile.csv')
exampleReader = csv.reader(exampleF... | 0 | 2016-09-06T08:55:23Z | 39,346,276 | <p>Used this in the end to make it work the way I wanted to. Plus I did not have to install any external modules! Thanks a lot for all your answers, they helped me build the final one!</p>
<pre><code>import webbrowser
import csv
path = "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe %s"
exampleFile = ope... | 1 | 2016-09-06T10:06:37Z | [
"python"
] |
Python Tkinter 2 classes | 39,344,919 | <p>I have 2 classes, i create the instance of each class like this </p>
<pre><code>if __name__ == '__main__':
root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.focus_set() # <-- move focus to this widget
root.geometry("%dx%d+0+0" % (w, h))
root.title("Circus ticketing s... | 0 | 2016-09-06T09:05:02Z | 39,345,133 | <p>the <code>Program_Class</code> object is instantiated after the <code>UI_Class</code> object and the latter doesn't reference the prior. Try passing <code>Program_Class</code> to the <code>GUI</code> constructor:</p>
<pre><code>Program_Class = Program()
UI_Class = GUI(root, Program_Class)
</code></pre>
<p>where:</... | 1 | 2016-09-06T09:15:05Z | [
"python",
"tkinter"
] |
What are valid gstreamer song names? | 39,344,951 | <p>I'm trying to understand what song names can I use in my gstreamer python based audioplayer. Can't find any docs about it. For example song with name <code>test%.mp3</code> produce the error:</p>
<pre><code>Error: [<GError at 0x7f8a8c001620>, 'gstgiosrc.c(324): gst_gio_src_get_stream (): /GstPlayBin:playbin0/... | 0 | 2016-09-06T09:06:39Z | 39,346,264 | <p>See the following SO answer:<a href="http://stackoverflow.com/questions/26092616/solvedgstreamer-uri-format-on-windows">[Solved]gstreamer uri format on windows</a><br>
specifically the <code>'file:' + urllib.pathname2url(filepath)</code> part.<br>
While this does not answer your more general question, it does permit... | 1 | 2016-09-06T10:06:03Z | [
"python",
"gstreamer"
] |
What are valid gstreamer song names? | 39,344,951 | <p>I'm trying to understand what song names can I use in my gstreamer python based audioplayer. Can't find any docs about it. For example song with name <code>test%.mp3</code> produce the error:</p>
<pre><code>Error: [<GError at 0x7f8a8c001620>, 'gstgiosrc.c(324): gst_gio_src_get_stream (): /GstPlayBin:playbin0/... | 0 | 2016-09-06T09:06:39Z | 39,347,832 | <p>Rolf's answer is great, but I wanted to add that if your songs_names are in unicode as mine then <code>pathname2url</code> will fail with <code>KeyError</code>. So I did it in slightly another way, note also <a href="http://stackoverflow.com/questions/11687478/convert-a-filename-to-a-file-url">Convert a filename to ... | 0 | 2016-09-06T11:21:18Z | [
"python",
"gstreamer"
] |
how to close chrome browser popup dialog using selenium webdriver and python | 39,345,066 | <p>I have a python code that uses selenium webdriver (along with chromedriver), to log into facebook and take a screenshot of the page.<br>
the script itself works as expected, however, after logging in, chrome browser shows a dialog regarding facebook notifications (<a href="http://screencast.com/t/dUtCXk41gvu" rel="n... | 1 | 2016-09-06T09:12:12Z | 39,386,207 | <p>You can try with launching the chrome browser with disabled pop-ups (browser pop-ups). The following code snippet is in Java. It will be somewhat similar in python i believe.</p>
<pre><code>ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-popup-blocking");
options.addArguments("test-type... | 0 | 2016-09-08T08:34:13Z | [
"python",
"google-chrome",
"selenium-webdriver",
"selenium-chromedriver"
] |
Django passing from DropDownlist to View | 39,345,085 | <p>I am trying to get the value of the Drop-down Menu Selected. I have done the following and it is returning a 'null' value. </p>
<p>I think the problem is here: newupload = request.POST('nameProjects') but I'm not sure which on how to get it working. </p>
<p>upload.html </p>
<pre><code><form class="form" met... | -1 | 2016-09-06T09:12:59Z | 39,346,804 | <p>In the views.py, you should use request.POST['nameProjects'] because request.POST will give a dictionary. If you want to store the project object in upload model, we need to give the project model instance variable or can give the id.</p>
<pre>
def upload_new(request):
newupload = Upload()
projects = Pro... | 0 | 2016-09-06T10:30:30Z | [
"python",
"django",
"django-forms",
"django-views"
] |
Python: Scipy.optimize Levenberg-marquardt method | 39,345,139 | <p>I have a question about how to use the Levenberg-Marquardt optimize method in Python </p>
<p>In the library SCIPY there are many methods of optimize --> <a href="http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/tutorial/optimize.html</a></p>
... | 0 | 2016-09-06T09:15:14Z | 39,345,476 | <p>From documentation:</p>
<pre><code>jac : bool or callable, optional
If jac is a Boolean and is True, fun is assumed to return the value
of Jacobian along with the objective function. If False, the
Jacobian will be estimated numerically. jac can also be a callable
returning the Jacobian of fun. In... | 1 | 2016-09-06T09:30:27Z | [
"python",
"optimization",
"scipy",
"levenberg-marquardt"
] |
How to create python conda 64 bit environment in existing 32bit install? | 39,345,313 | <p>I have a 32 bit installation of the Anaconda Python distribution.
I know how to create environments for different python versions.
What I need is to have a 64 bit version of python.</p>
<p>Is it possible to create a conda env with the 64 bit version?</p>
<p>Or do I have to reinstall anaconda or install a different... | 0 | 2016-09-06T09:22:48Z | 39,345,619 | <p>As I understand, Anaconda installs into a self-contained directory (<code><pwd>/anaconda3</code>). Since 64-bit and 32-bit builds of Python can not be mixed or converted into each other (in terms of the compiled Python binaries and libraries in <code>site-packages</code> or other <code>PYTHONPATH</code> locati... | 0 | 2016-09-06T09:36:52Z | [
"python",
"anaconda",
"32bit-64bit",
"development-environment",
"conda"
] |
Unable to connect to Heroku postgre SQL database locally | 39,345,324 | <p>I am trying to connect to Heroku postgre SQL database locally like this,</p>
<pre><code>from flask import Flask
import sys
import psycopg2
import urlparse
urlparse.uses_netloc.append("postgres")
url = urlparse.urlparse("postgres://url")
conn = psycopg2.connect(
database=url.path[1:],
user=url.username,
... | 0 | 2016-09-06T09:23:20Z | 39,346,821 | <p>Kinda tough for me to narrow down, but I was able to set something similar with these steps:</p>
<p>If you have a 'server.py' make sure to have this at the top of the file:</p>
<pre><code>from dotenv import load_dotenv, find_dotenv
import os
load_dotenv(find_dotenv())
db = pg.DB(
dbname=os.environ.get('DBNAME')... | 0 | 2016-09-06T10:31:22Z | [
"python",
"postgresql",
"heroku"
] |
Can we send a request object or keyword argument to modelformset_factory in django 1.9 | 39,345,346 | <p>I have the following view</p>
<pre><code>def application(request, uuid):
application = get_object_or_404(LoanApplication, uuid=uuid)
partners = FirmPartner.objects.filter(application=application)
PartnerFormset = modelformset_factory(FirmPartner, form=FirmPartnerForm, can_delete=True, extra=1)
if ... | 0 | 2016-09-06T09:24:08Z | 39,345,426 | <p>The <a href="https://docs.djangoproject.com/en/1.10/topics/forms/formsets/#passing-custom-parameters-to-formset-forms" rel="nofollow"><code>form_kwargs</code></a> parameter is what you need.</p>
<pre><code>modelformset_factory(FirmPartner, form=FirmPartnerForm, can_delete=True, extra=1,
form_kw... | 1 | 2016-09-06T09:28:38Z | [
"python",
"django",
"django-forms",
"modelform"
] |
How to render PDF using poppler in pyqt4 or wxpython? | 39,345,395 | <p>My goal is to create a pdf viewer that can select a text in the viewer.</p>
<p>is it possible?
i'm only experienced using wxpython for deleveloping gui application. I just heard poppler can support rendering pdf, but i did not found any snippet or example. please help.</p>
| 0 | 2016-09-06T09:26:48Z | 39,351,066 | <p>If you are looking for how to create a wxPython PDF viewer, I've found a couple of examples. The first one uses Poppler as you mentioned in conjunction with wxPython:</p>
<ul>
<li><a href="http://code.activestate.com/recipes/577195-wxpython-pdf-viewer-using-poppler/" rel="nofollow">http://code.activestate.com/recip... | 0 | 2016-09-06T14:06:14Z | [
"python",
"pdf",
"wxpython",
"poppler"
] |
Can pandas dataframe have dtype of list? | 39,345,624 | <p>I'm new to Pandas, I process a dataset, where one of the columns is string with pipe (<code>|</code>) separated values. Now I have a task to remove any text in this |-separated field that's not fulfilling certain criteria.</p>
<p>My naive approach is to iterate the dataframe row by row and explode the field into li... | 1 | 2016-09-06T09:36:58Z | 39,346,589 | <p>IIUC you can use:</p>
<pre><code>dataframe = pd.DataFrame({'field':['aasd|bbuu|cccc|ddde|e','ffff|gggg|hhhh|i|j','cccc|u|k'],
'G':[4,5,6]})
print (dataframe)
G field
0 4 aasd|bbuu|cccc|ddde|e
1 5 ffff|gggg|hhhh|i|j
2 6 cccc|u|k
print (dataframe.... | 2 | 2016-09-06T10:20:50Z | [
"python",
"string",
"list",
"pandas",
"list-comprehension"
] |
find the misclassified data in a confusion matrix | 39,345,647 | <p>I use this function to evaluate my model</p>
<pre><code>def stratified_cv(X, y, clf_class, shuffle=True, n_folds=10, **kwargs):
X = X.as_matrix().astype(np.float)
y = y.as_matrix().astype(np.int)
y_pred = y.copy()
stratified_k_fold = cross_validation.StratifiedKFold(y, n_folds=n_folds, shuffle=... | -3 | 2016-09-06T09:37:52Z | 39,361,999 | <p>You can find out the misclassified predictions from the confusion matrix itself. The top right box gives the number of predictions predicted to be 0 but are not zero. And the lower left box shows those predicted 1but are not one.
This above mentioned cells are known as true negative and false positive if the confus... | 0 | 2016-09-07T05:45:27Z | [
"python",
"pandas",
"machine-learning",
"confusion-matrix"
] |
Mutlithreading python | 39,345,656 | <p>I am new to Python coding and new to stackoverflow as well need your guidance:</p>
<p>I am trying to create AMI of EC2 instances using python. I need to implement multi threading so that AMI creation can run in parallel. But below code is not working. It is creating single AMI at a time.</p>
<p>module1</p>
<pre><... | 1 | 2016-09-06T09:38:19Z | 39,346,858 | <p>I can't reproduce your example but I've created a dummy version:</p>
<pre><code>import sys
import threading
import time
import random
random.seed(1)
class Libpy:
def multithreading(self, lst, function):
threads = []
for v in lst:
t = threading.Thread(target=function, args=(v,))
... | 1 | 2016-09-06T10:33:02Z | [
"python",
"amazon-web-services",
"ami"
] |
Control a python process form another python file | 39,345,829 | <p>first of all a short overview over my current goal:</p>
<p>I want to use a scheduler to execute a simple python program every second. This program reads some data and enter the results inside a database. Because the scheduled task will operate over several days on a raspberry pie the process should start in the bac... | 1 | 2016-09-06T09:47:04Z | 39,346,000 | <p>To control (start, restart, stop, schedule) the background process use <a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow">subprocess</a>. Here is <a href="http://stackoverflow.com/questions/1191374/using-module-subprocess-with-timeout">example</a> of subrocess' popen with timeout.</p>
<p>To ... | 1 | 2016-09-06T09:54:35Z | [
"python",
"python-3.x",
"subprocess",
"scheduled-tasks"
] |
can't get pydot to find graphviz on windows 10 | 39,345,846 | <p>I'm trying to run a Random Forest analysis on Python 2.7 and I get this error while trying to create the graph of the decision trees.
<a href="http://i.stack.imgur.com/sHsra.jpg" rel="nofollow">error</a></p>
<p>I've tried reinstalling pydot and graphviz in alternating orders and I've also tried adding dot.exe to m... | -1 | 2016-09-06T09:48:10Z | 39,665,443 | <p>When changing the <code>PATH</code> variable (or any other system variable for that matter), the applications using this variables must be restarted in order to see the new values. Alternatively, log out completely and log back in.</p>
<p>The application (in this case Python) should now be able to call the programs... | 1 | 2016-09-23T16:23:59Z | [
"python",
"graphviz",
"random-forest",
"pydot"
] |
Django: Test an Abstract Model | 39,345,893 | <p>I have a simple abstract class and I want to write a unit test for this.
I am using Django 1.10 and the most <a href="https://stackoverflow.com/questions/4281670/django-best-way-to-unit-test-an-abstract-model">answers I have found</a> are out there for years and maybe are outdated.
I have tried the solution from <a ... | 1 | 2016-09-06T09:50:14Z | 39,415,678 | <p>The problem is that you haven't migrated that model to your database, and that's because you created the model inside the tests file, Django only checks for models inside the <code>models.py</code> file, so move the next code to the <code>models.py</code> file:</p>
<pre><code>class FlagsTestModel(FlagsModel):
... | 1 | 2016-09-09T16:09:48Z | [
"python",
"django",
"unit-testing",
"django-models",
"abstract-class"
] |
how to search new line character from a string in python | 39,345,915 | <p>I want to split string based on new line character and replace the new line with a '.' in python. I tried this code but I'm not getting it.</p>
<pre><code>import nltk
from nltk.tokenize.punkt import PunktSentenceTokenizer, PunktParameters, PunktLanguageVars
ex_sent="Conclusion & Future Work
In our project ... | 1 | 2016-09-06T09:51:24Z | 39,346,122 | <p>The newline character is <code>\n</code>. So If you want to replace all new line characters in string with <code>.</code> you should use <code>replace()</code> method. In this case:</p>
<pre><code>your_string.replace('\n', '.')
</code></pre>
<p>A second approach is to <code>.split('\n')</code> by newline and then ... | 4 | 2016-09-06T09:59:43Z | [
"python",
"nltk"
] |
Python returns string is both str and unicode type | 39,345,916 | <p>We have a .NET app that can be customized by IronPython (version 2.7.5)</p>
<p>Here is the script code:</p>
<pre><code>stringToPlay = # get it from our .NET app interface toward python here. The method returns .NET string
Log.Write("isinstance(stringToPlay, unicode): ", str(isinstance(stringToPlay, unicode)))
Lo... | 1 | 2016-09-06T09:51:26Z | 39,346,195 | <p>In IronPython, the <code>str</code> type and the <code>unicode</code> type are the same object. The .NET string type is unicode.</p>
| 3 | 2016-09-06T10:03:00Z | [
"python",
".net",
"unicode",
"ironpython"
] |
Python returns string is both str and unicode type | 39,345,916 | <p>We have a .NET app that can be customized by IronPython (version 2.7.5)</p>
<p>Here is the script code:</p>
<pre><code>stringToPlay = # get it from our .NET app interface toward python here. The method returns .NET string
Log.Write("isinstance(stringToPlay, unicode): ", str(isinstance(stringToPlay, unicode)))
Lo... | 1 | 2016-09-06T09:51:26Z | 39,346,199 | <p>IronPython makes no difference between <code>str</code> and <code>unicode</code>, which can be very confusing if you are used to the CPython 2 semantics. In fact, <code>basestring</code> and <code>unicode</code> are both aliases for <code>str</code>.</p>
<pre><code>IronPython 2.7.4 (2.7.0.40) on .NET 4.0.30319.4200... | 5 | 2016-09-06T10:03:15Z | [
"python",
".net",
"unicode",
"ironpython"
] |
How does Python return multiple values from a function? | 39,345,995 | <p>I have written the following code:</p>
<pre><code>class FigureOut:
first_name = None
last_name = None
def setName(self, name):
fullname = name.split()
self.first_name = fullname[0]
self.last_name = fullname[1]
def getName(self):
return self.first_name, self.last_name
f = Figure... | 1 | 2016-09-06T09:54:25Z | 39,346,109 | <p>Python will return a <code>tuple</code> in this case since the return specifies <em>comma separated values</em>. Multiple values can only be returned inside containers.</p>
<p>You can look at the byte code generated from a function returning values like yours by using <a href="https://docs.python.org/3/library/dis.... | 3 | 2016-09-06T09:59:12Z | [
"python",
"function",
"python-3.x",
"return"
] |
How does Python return multiple values from a function? | 39,345,995 | <p>I have written the following code:</p>
<pre><code>class FigureOut:
first_name = None
last_name = None
def setName(self, name):
fullname = name.split()
self.first_name = fullname[0]
self.last_name = fullname[1]
def getName(self):
return self.first_name, self.last_name
f = Figure... | 1 | 2016-09-06T09:54:25Z | 39,346,120 | <p>From <a href="https://www.safaribooksonline.com/library/view/python-cookbook-3rd/9781449357337/ch07s04.html" rel="nofollow">Phyton Cookbook v.30</a></p>
<pre><code>def myfun():
return 1, 2, 3
</code></pre>
<p></p>
<pre><code>a, b, c = myfun()
</code></pre>
<blockquote>
<p><strong>Although it looks like <co... | 3 | 2016-09-06T09:59:37Z | [
"python",
"function",
"python-3.x",
"return"
] |
How does Python return multiple values from a function? | 39,345,995 | <p>I have written the following code:</p>
<pre><code>class FigureOut:
first_name = None
last_name = None
def setName(self, name):
fullname = name.split()
self.first_name = fullname[0]
self.last_name = fullname[1]
def getName(self):
return self.first_name, self.last_name
f = Figure... | 1 | 2016-09-06T09:54:25Z | 39,346,131 | <p>Python functions always return a unique value. The comma operator is the constructor of tuples so <code>self.first_name, self.last_name</code> evaluates to a tuple and that tuple is the actual value the function is returning.</p>
| 1 | 2016-09-06T10:00:03Z | [
"python",
"function",
"python-3.x",
"return"
] |
How does Python return multiple values from a function? | 39,345,995 | <p>I have written the following code:</p>
<pre><code>class FigureOut:
first_name = None
last_name = None
def setName(self, name):
fullname = name.split()
self.first_name = fullname[0]
self.last_name = fullname[1]
def getName(self):
return self.first_name, self.last_name
f = Figure... | 1 | 2016-09-06T09:54:25Z | 39,346,392 | <blockquote>
<p>Whenever multiple values are returned from a function in python, does it always convert the multiple values to a <strong>list</strong> of multiple values and then returns it from the function??
<br/></p>
</blockquote>
<p>I'm just adding a name and print the result that returns from the function.
th... | 1 | 2016-09-06T10:12:24Z | [
"python",
"function",
"python-3.x",
"return"
] |
How does Python return multiple values from a function? | 39,345,995 | <p>I have written the following code:</p>
<pre><code>class FigureOut:
first_name = None
last_name = None
def setName(self, name):
fullname = name.split()
self.first_name = fullname[0]
self.last_name = fullname[1]
def getName(self):
return self.first_name, self.last_name
f = Figure... | 1 | 2016-09-06T09:54:25Z | 39,346,404 | <p>Here It is actually returning <code>tuple</code>.</p>
<p>If you execute this code in Python 3: </p>
<pre><code>def get():
a = 3
b = 5
return a,b
number = get()
print(type(number))
print(number)
</code></pre>
<p><strong>Output :</strong> </p>
<pre><code><class 'tuple'>
(3, 5)
</code></pre>
<p>B... | 1 | 2016-09-06T10:13:05Z | [
"python",
"function",
"python-3.x",
"return"
] |
When run a c++ exe in a python code, don't change text file | 39,346,051 | <p>I have a c++ code that in this, i change strings in a text file.
this code run correctly. but when i run exe of this code in a python file, run correctly but don't change strings of text file.
what must i do?</p>
<p>part of my c++ for change text file:</p>
<pre><code>ofstream myfile;
myfile.open ("example.txt");
... | -1 | 2016-09-06T09:56:46Z | 39,347,030 | <p>The problem here is that your compiled cpp binary runs in a wrong directory (check your user directory for <code>example.txt</code>)</p>
<p>You need to specify full path to your executable in python script:</p>
<pre><code>os.system(os.getcwd() + '/test')
</code></pre>
| 1 | 2016-09-06T10:41:16Z | [
"python",
"c++",
"text",
"exe"
] |
I can't get a html page with requests | 39,346,096 | <p>I would like to get an html page and read the content. I use requests (python) and my code is very simple:</p>
<pre><code>import requests
url = "http://www.romatoday.it"
r = requests.get(url)
print r.text
</code></pre>
<p>when I try to do this procedure I get ever:
Connection aborted.', error(110, 'Connectio... | 0 | 2016-09-06T09:58:40Z | 39,346,171 | <p>Maybe the problem is that the comma here</p>
<pre><code>>> url = "http://www.romatoday,it"
</code></pre>
<p>should be a dot</p>
<pre><code>>> url = "http://www.romatoday.it"
</code></pre>
<p>I tried that and it worked for me </p>
| 0 | 2016-09-06T10:02:15Z | [
"python",
"timeout",
"python-requests",
"screen-scraping"
] |
I can't get a html page with requests | 39,346,096 | <p>I would like to get an html page and read the content. I use requests (python) and my code is very simple:</p>
<pre><code>import requests
url = "http://www.romatoday.it"
r = requests.get(url)
print r.text
</code></pre>
<p>when I try to do this procedure I get ever:
Connection aborted.', error(110, 'Connectio... | 0 | 2016-09-06T09:58:40Z | 39,346,757 | <p>Hmm..Have you tried other packages, not 'requests'?
the code blow is same result as your code.</p>
<pre><code>import urllib
url = "http://www.romatoday.it"
r = urllib.urlopen(url)
print r.read()
</code></pre>
<p><a href="http://i.stack.imgur.com/bVBJa.png" rel="nofollow">a picture that I captured after running ... | -1 | 2016-09-06T10:28:05Z | [
"python",
"timeout",
"python-requests",
"screen-scraping"
] |
Analysis and spelling correction of SMS text using python | 39,346,126 | <p>For example, I have a sentence:</p>
<blockquote>
<p>hav bin reali happy since tlkin 2 u</p>
</blockquote>
<p>With a python script, I want to edit above line so that it becomes:</p>
<blockquote>
<p>have been really happy since talking to you[sic]</p>
</blockquote>
<p>How can I read each and every character an... | -3 | 2016-09-06T09:59:50Z | 39,346,256 | <pre><code>replacements = {
'hav': 'have',
'bin': 'been',
'reali': 'really',
'u': 'you',
'tlkin': 'talking',
'2': 'to'
}
sms = 'hav bin reali happy since tlkin 2 u'
original = ' '.join([replacements.get(w, w) for w in sms.split()])
print(original)
</code></pre>
| 0 | 2016-09-06T10:05:41Z | [
"python",
"text-analysis"
] |
Cannot run python script under powershell in spite of adding env Path as required | 39,346,283 | <p>I am a user of python under mac and need to work now on a windows system.
I have installed Python35 for windows in Powershell, the command <code>py --version</code> and <code>python --version</code> provides me "Python 3.5.2".</p>
<p>I want to run a python script in Powershell and have tried : <code>py file.py</cod... | 1 | 2016-09-06T10:06:54Z | 39,346,608 | <p>The problem is explained in the error message:</p>
<blockquote>
<p>SyntaxError: Non-UTF-8 code starting with '\xff' in file .\file.py on line 1, but no encoding declared;</p>
</blockquote>
<p>It means that Python reads the source file and gets confused. On the other hand, it has a <a href="https://en.wikipedia.o... | 1 | 2016-09-06T10:21:53Z | [
"python",
"windows",
"powershell"
] |
Loss of information using XBee | 39,346,386 | <p>I am trying to establish communications via serial port between a PC with Ubuntu 14.04LTS and my RoMeo Arduino Board (Atmega 328). The used serial interface are 2 Xbee modules, one at PC and the other at the board.</p>
<p>Firstly, I am trying to develop a simple program to send messages to the board and receive the... | 1 | 2016-09-06T10:12:00Z | 39,741,986 | <p>The reason why the PC could not send more than 1 character to the Arduino board was that there was an XBee module configured with different port parameters than both the other module and the pyserial instance. In this case, the communication was established in Python with the following main parameters:</p>
<ul>
<li... | 0 | 2016-09-28T08:29:07Z | [
"python",
"arduino",
"serial-port",
"pyserial",
"xbee"
] |
Regex pattern behaving differently in TCL compared with Perl & Python | 39,346,524 | <p>I am trying to extract a sub-string from a string using regular expressions. Below is the working code in <code>Python</code> (giving desired results)</p>
<p><strong>Python Solution</strong></p>
<pre><code>x = r'CAR_2_ABC_547_d'
>>> spattern = re.compile("CAR_.*?_(.*)")
>>> spattern.search(x).gro... | 2 | 2016-09-06T10:18:01Z | 39,347,224 | <blockquote>
<p>A branch has the same preference as the first quantified atom in it
which has a preference.</p>
</blockquote>
<p>So if you have <code>.*</code> as the first quantifier, the whole RE will be greedy,
and if you have <code>.*?</code> as the first quantifier, the whole RE will be non-greedy.</p>
<p>Si... | 4 | 2016-09-06T10:51:16Z | [
"python",
"perl",
"tcl",
"tclsh"
] |
Regex pattern behaving differently in TCL compared with Perl & Python | 39,346,524 | <p>I am trying to extract a sub-string from a string using regular expressions. Below is the working code in <code>Python</code> (giving desired results)</p>
<p><strong>Python Solution</strong></p>
<pre><code>x = r'CAR_2_ABC_547_d'
>>> spattern = re.compile("CAR_.*?_(.*)")
>>> spattern.search(x).gro... | 2 | 2016-09-06T10:18:01Z | 39,354,872 | <p>Another approach, instead of capturing the text that follows the prefix, is to just remove the prefix:</p>
<pre><code>% set result [regsub {^CAR_.*?_} "CAR_2_ABC_547_d" {}]
ABC_547_d
</code></pre>
| 1 | 2016-09-06T17:38:18Z | [
"python",
"perl",
"tcl",
"tclsh"
] |
Count cells of adjacent numpy regions | 39,346,545 | <p>I'm looking to solve the following problem. I have a numpy array which is labeled to regions from 1 to n. Let's say this is the array:</p>
<pre><code>x = np.array([[1, 1, 1, 4], [1, 1, 2, 4], [1, 2, 2, 4], [5, 5, 3, 4]], np.int32)
array([[1, 1, 1, 4],
[1, 1, 2, 4],
[1, 2, 2, 4],
[5, 5, 3, 4]])... | 3 | 2016-09-06T10:19:01Z | 39,348,877 | <p>Here is a vectorized solution using the <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package (note; it isn't vectorized over the regions, but it is vectorized over the pixels, which is the useful thing to do assuming n_pixels >> n_regions):</p>
<pre><code>neigh... | 2 | 2016-09-06T12:17:54Z | [
"python",
"arrays",
"numpy"
] |
Python webdriver: get XPATH from innerHTML | 39,346,549 | <p>Is there a way to get the xpath of an webelement knowing only its innerHTML value?</p>
<p>Say I've got a 'Save' button, which is a button with text "Save". Say that the button can change its location on the page with subsequent updates to the system, therefore changing its xpath every time.</p>
<p>Here is an examp... | 0 | 2016-09-06T10:19:05Z | 39,346,896 | <p>You can use following <code>XPath</code> to match any element with <code>innerHTML="Save"</code>:</p>
<pre><code>//*[text()="Save"]
</code></pre>
<p>or in your case:</p>
<pre><code>//button/span[text()="Save"]
</code></pre>
| 0 | 2016-09-06T10:34:42Z | [
"python",
"selenium",
"xpath"
] |
Russian character decoding in python | 39,346,820 | <p>This question only for python:</p>
<p>I have a city name in a string in Russian language and which is in Unicode form like,</p>
<blockquote>
<p><code>\u041C\u043E\u0441\u043A\u0432\u0430</code></p>
</blockquote>
<p>means </p>
<blockquote>
<p><code>ÐоÑква</code></p>
</blockquote>
<p>How to get original... | 0 | 2016-09-06T10:31:18Z | 39,346,971 | <pre><code>>>> a=u"\u041C\u043E\u0441\u043A\u0432\u0430"
>>> print a
ÐоÑква
</code></pre>
<p>Your string is a unicode string because each character/code point with \u is only usable from a unicode string, you should prefix the string with u. Otherwise is a regular string and each \u counts as a... | 5 | 2016-09-06T10:38:33Z | [
"python"
] |
Russian character decoding in python | 39,346,820 | <p>This question only for python:</p>
<p>I have a city name in a string in Russian language and which is in Unicode form like,</p>
<blockquote>
<p><code>\u041C\u043E\u0441\u043A\u0432\u0430</code></p>
</blockquote>
<p>means </p>
<blockquote>
<p><code>ÐоÑква</code></p>
</blockquote>
<p>How to get original... | 0 | 2016-09-06T10:31:18Z | 39,347,688 | <p>In addition to vz0 answer : Pay attention to script's encoding.</p>
<p>This <strong>file</strong> will works great :</p>
<pre class="lang-py prettyprint-override"><code># coding: utf-8
s = u"\u041C\u043E\u0441\u043A\u0432\u0430"
print(s)
</code></pre>
<p>But this one will lead to an UnicodeEncodeError :</p>
<pre... | 2 | 2016-09-06T11:14:07Z | [
"python"
] |
Error while comparing string after transforming from datetime | 39,346,960 | <p>I am converting datetime to string and then comparing it with string from stdout.read from a file. But the "==" comparision fails.</p>
<p>Below is my code:</p>
<pre><code>date_input = datetime.datetime.now()
dat = date_input.strftime("%Y-%m-%d %H:%M:%S.%f")
command = 'echo %s > /media/mmcblk0p1/testCard.txt' %... | 2 | 2016-09-06T10:38:09Z | 39,347,075 | <pre><code>>>> a
'2016-09-06 15:49:49.104030'
>>> b
u'2016-09-06 15:49:49.104030'
>>> a == b
True
>>> b = b + "\n"
>>> a == b
False
</code></pre>
<p>There could be whitespace characters in one of your strings, remove them using .strip()</p>
| 1 | 2016-09-06T10:43:51Z | [
"python",
"datetime"
] |
Error while comparing string after transforming from datetime | 39,346,960 | <p>I am converting datetime to string and then comparing it with string from stdout.read from a file. But the "==" comparision fails.</p>
<p>Below is my code:</p>
<pre><code>date_input = datetime.datetime.now()
dat = date_input.strftime("%Y-%m-%d %H:%M:%S.%f")
command = 'echo %s > /media/mmcblk0p1/testCard.txt' %... | 2 | 2016-09-06T10:38:09Z | 39,347,082 | <p>Have you tried using <code>.strip()</code> </p>
<p><a href="http://www.tutorialspoint.com/python/string_strip.htm" rel="nofollow">http://www.tutorialspoint.com/python/string_strip.htm</a></p>
<pre><code>Example:
if(date_output.strip() == dat.strip()):
</code></pre>
<p>If there are any whitespace characters on ... | 1 | 2016-09-06T10:44:10Z | [
"python",
"datetime"
] |
Error while comparing string after transforming from datetime | 39,346,960 | <p>I am converting datetime to string and then comparing it with string from stdout.read from a file. But the "==" comparision fails.</p>
<p>Below is my code:</p>
<pre><code>date_input = datetime.datetime.now()
dat = date_input.strftime("%Y-%m-%d %H:%M:%S.%f")
command = 'echo %s > /media/mmcblk0p1/testCard.txt' %... | 2 | 2016-09-06T10:38:09Z | 39,347,254 | <p><a href="http://linux.die.net/man/1/echo" rel="nofollow"><code>echo</code></a> adds a new line character to the end of its output, therefore the date is written to <code>/media/mmcblk0p1/testCard.txt</code> with a trailing new line. Either strip it off when you read it back in, or use the <code>-n</code> option to <... | 1 | 2016-09-06T10:53:06Z | [
"python",
"datetime"
] |
Setting MultiColumn as index has issues with index names | 39,346,999 | <p>Here is how I create my multi column table:</p>
<pre><code>whatFields = ['mean', 'mom_2', 'n']
groupbyFields = ['foo', 'bar']
topFields = ['desc']*len(groupbyFields)
topFields += ['price']*len(whatFields)
topFields += ['units']*len(whatFields)
bottomFields = groupbyFields + whatFields + whatFields
resultsDf = pd.Da... | 0 | 2016-09-06T10:39:53Z | 39,360,998 | <p>Is this what you were looking for? I wasn't exactly sure how you wanted to main index set up. </p>
<p>Two ways:</p>
<pre><code>In [1]: import numpy as np
In [2]: import pandas as pd
i
In [3]: import itertools as it
In [4]: whatFields = ['mean', 'mom_2', 'n']
...: groupbyFields = ['foo', 'bar']
...: topFiel... | 0 | 2016-09-07T04:00:21Z | [
"python",
"pandas"
] |
cannot use python intersection set with ROS point lists | 39,347,119 | <p>i try to find a intersection set of two position lists, in ROS</p>
<p>so i write a code in python, and i have two lists, such as :</p>
<pre><code>position1 = Point()
position1.x =1
position2 = Point()
position2.x=2
a = [copy.deepcopy(position1),copy.deepcopy(position2)]
b = [copy.deepcopy(position1)]
</code><... | 1 | 2016-09-06T10:45:59Z | 39,347,710 | <p>Well, it doesn't returns <code>set([])</code> but prints <code>set()</code> (nitpicking maybe but it's not the same thing).</p>
<p>Actually it's the expected behavior :</p>
<ul>
<li>a set keeps only unique elements</li>
<li>unique is defined by having the same hash </li>
<li>the default hash comes from <strong>has... | 0 | 2016-09-06T11:15:31Z | [
"python",
"set",
"intersection",
"ros"
] |
cannot use python intersection set with ROS point lists | 39,347,119 | <p>i try to find a intersection set of two position lists, in ROS</p>
<p>so i write a code in python, and i have two lists, such as :</p>
<pre><code>position1 = Point()
position1.x =1
position2 = Point()
position2.x=2
a = [copy.deepcopy(position1),copy.deepcopy(position2)]
b = [copy.deepcopy(position1)]
</code><... | 1 | 2016-09-06T10:45:59Z | 39,360,094 | <p>@Ninja Puppy delete an answer, which i think it helpful as well, so i add it here. while, if this is forbidden or Ninja Puppy feel sick of this, i will delete this answer too. following is his answer</p>
<blockquote>
<p>Okay, going by your comment:</p>
<pre><code>a[0]==b[0] is true, because they are both positio... | 0 | 2016-09-07T01:45:34Z | [
"python",
"set",
"intersection",
"ros"
] |
Loop creates unwanted duplicate | 39,347,180 | <p>I am trying to pull in data from an input file and iterate over a symbol file to create output for an output file but my code is creating an unwanted duplicate in the output file. The input file is very big so I need to filter the input first before I reference it against the symbol (city/state) file to generate th... | -3 | 2016-09-06T10:49:17Z | 39,349,497 | <blockquote>
<p>I only want one line for every line in the input file IF there is a matching line in the symbol file. </p>
</blockquote>
<p>Try it like this then:</p>
<pre><code>i_file = 'InputFile.csv'
o_file = 'OutputFile.csv'
symbol_file = 'SymbolFile.csv'
city = 'Tampa'
state = 'FL'
# load the symbols from th... | 0 | 2016-09-06T12:52:35Z | [
"python",
"python-3.x",
"loops"
] |
Find two most distant points in a set of points in 3D space | 39,347,209 | <p>I need to find the diameter of the points cloud (two points with maximum distance between them) in 3-dimensional space. As a temporary solution, right now I'm just iterating through all possible pairs and comparing the distance between them, which is a very slow, <code>O(n^2)</code> solution.</p>
<p>I believe it ca... | 3 | 2016-09-06T10:50:39Z | 39,347,974 | <p>While O(n log n) expected time algorithms exist in 3d, they seem tricky to implement (while staying competitive to brute-force O(n^2) algorithms).</p>
<p>An algorithm is described in <a href="http://dl.acm.org/citation.cfm?id=378662" rel="nofollow">Har-Peled 2001</a>. The authors provide a <a href="http://sarielhp.... | 2 | 2016-09-06T11:28:39Z | [
"python",
"c++",
"geometry",
"convex-hull"
] |
model.objects.create in views is not working in my django project? | 39,347,283 | <p>This is <code>models.py</code></p>
<pre><code>from django.db import models
class Iot(models.Model):
user = models.CharField(max_length="50")
email = models.EmailField()
</code></pre>
<p>This is my <code>views.py</code></p>
<pre><code>def Test(request):
if request.method == 'PUT':
user ... | -2 | 2016-09-06T10:54:40Z | 39,347,478 | <p>Most likely that error happens because you try to create Iot without email, but it is required field.
You should do something like</p>
<pre><code>Iot.objects.create(user=user, email=email)
</code></pre>
<p>To make your code working in the way you choose(set attributes one by one and not at once) you need to get r... | 0 | 2016-09-06T11:04:05Z | [
"python",
"django",
"django-rest-framework"
] |
How to use glob in python to search through a specific folder | 39,347,383 | <p>I am currently working on a small piece of code that I want to go through a user-inputted folder and rename all the files in there depending on certain criteria. </p>
<p>At the moment, the user enters the filename using this code:</p>
<pre><code>src = input("Please enter the folder path where the files are located... | 1 | 2016-09-06T10:59:26Z | 39,347,583 | <p>You can use <a href="https://docs.python.org/3/library/os.path.html#os.path.join" rel="nofollow">os.path.join</a> to join the user input to the desired pattern:</p>
<pre><code>import os.path
src = input('Please enter the folder path where the files are located: ')
if not os.path.isdir(src):
print('Invalid give... | 2 | 2016-09-06T11:08:18Z | [
"python",
"python-3.x",
"glob"
] |
Python 3: How to compare two big files fastest? | 39,347,463 | <p>In <strong>"Big_file.txt</strong>", I want to extract UIDs of <strong>"User A"</strong> which is not duplicated with UIDs in "<strong>Small_file.txt</strong>". I wrote the following code but it seems it will never stop running. So, how to speed up the process ? Thank you very much :)</p>
<pre><code>import json
uid... | 2 | 2016-09-06T11:03:17Z | 39,347,574 | <p>looking up an item in a list takes <code>O(n)</code> time. If you use a <code>dict</code> or a <code>set</code> you can improve it to <code>O(1)</code>.</p>
<p>shortest modification you can do is :</p>
<pre><code>linesB = []
for line in open('E:/Small_file.txt'):
line = json.loads(line)
linesB.append(hash(... | 3 | 2016-09-06T11:07:59Z | [
"python",
"json",
"hash",
"compare"
] |
Python 3.2 how to set correct and incorrect answer on questions inside 2 lists | 39,347,623 | <p>I am making 2 sets of question, first set (list1) is all yes and second (list2) is all no 10 questions each then I used random.choice to randomly pick a question from the 2 sets. I want to make an output of "correct" whenever random.choice picks a question from list 1 when the user answered "Y" same with list2 if th... | 0 | 2016-09-06T11:10:37Z | 39,347,740 | <p>First off, don't use python keywords and built-in type names as your variable names.</p>
<p>You can check the membership of random choice simply with <code>in</code> operator.</p>
<pre><code>import random
list1 = ['1+1=2?','2+2=4?','3+3=6?','4+4=8?','5+5=10?','15+15=30?','16+16=32?','17+17=34?','18+18=36?','19+19... | 2 | 2016-09-06T11:17:05Z | [
"python",
"python-3.x"
] |
Python 3.2 how to set correct and incorrect answer on questions inside 2 lists | 39,347,623 | <p>I am making 2 sets of question, first set (list1) is all yes and second (list2) is all no 10 questions each then I used random.choice to randomly pick a question from the 2 sets. I want to make an output of "correct" whenever random.choice picks a question from list 1 when the user answered "Y" same with list2 if th... | 0 | 2016-09-06T11:10:37Z | 39,347,980 | <p>My solution is slightly different!
Save the equations in the list with the double == and after do in this way:</p>
<pre><code>import random
list1 = ['1+1==2','2+2==4','3+3==6','4+4==8','5+5==10','15+15==30','16+16==32','17+17==34','18+18==36','19+19==38']
list2 = ['20+20==10','6+6==2','7+7==11','8+8==32','9+9==21'... | 0 | 2016-09-06T11:28:52Z | [
"python",
"python-3.x"
] |
Python 3.2 how to set correct and incorrect answer on questions inside 2 lists | 39,347,623 | <p>I am making 2 sets of question, first set (list1) is all yes and second (list2) is all no 10 questions each then I used random.choice to randomly pick a question from the 2 sets. I want to make an output of "correct" whenever random.choice picks a question from list 1 when the user answered "Y" same with list2 if th... | 0 | 2016-09-06T11:10:37Z | 39,347,991 | <p>A more pythonic way would be:</p>
<pre><code>list1 = ['1 + 1 = 2? ', '2 + 2 = 4? ', '3 + 3 = 6? ', '4 + 4 = 8? ',
'5 + 5 = 10? ', '15 + 15 = 30? ', '16 + 16 = 32? ', '17 + 17 = 34? ',
'18 + 18 = 36? ', '19 + 19 = 38? ']
list2 = ['20 + 20 = 10? ', '6 + 6 = 2? ', '7 + 7 = 11? ', '8 + 8 = 32? ',
... | 0 | 2016-09-06T11:29:18Z | [
"python",
"python-3.x"
] |
Python 3.2 how to set correct and incorrect answer on questions inside 2 lists | 39,347,623 | <p>I am making 2 sets of question, first set (list1) is all yes and second (list2) is all no 10 questions each then I used random.choice to randomly pick a question from the 2 sets. I want to make an output of "correct" whenever random.choice picks a question from list 1 when the user answered "Y" same with list2 if th... | 0 | 2016-09-06T11:10:37Z | 39,348,183 | <p>Rather than searching the two lists for the chosen question it's simpler to randomly choose a list and then choose a question from that list. This approach will have the same probability of choosing a given question as your approach as long as both lists have the same length.</p>
<p>We can still combine the two lis... | 0 | 2016-09-06T11:40:27Z | [
"python",
"python-3.x"
] |
Add user scripts folder to Maya | 39,347,681 | <p>I tried all methods explained on several documentation pages.</p>
<p>I modified the <strong>userSetup.mel</strong> file and it adds the folder with this code:</p>
<pre><code>string $s = `getenv MAYA_SCRIPT_PATH` + ";C:/MyScripts";
putenv "MAYA_SCRIPT_PATH" $s;
</code></pre>
<p>It didn't work. I also tried to do a... | 0 | 2016-09-06T11:13:47Z | 39,348,889 | <p>you can also add the path like:</p>
<pre><code>import sys
sys.path.append("C:/MyScripts")
import my_module
reload(my_module)
my_module.run()
</code></pre>
<p>if you want that maya start with this env, you need a batch file(with all custom env paths like arnold or houdini engine or your own plugins) or a wrapper(m... | 0 | 2016-09-06T12:18:27Z | [
"python",
"python-2.7",
"maya",
"mel"
] |
Add user scripts folder to Maya | 39,347,681 | <p>I tried all methods explained on several documentation pages.</p>
<p>I modified the <strong>userSetup.mel</strong> file and it adds the folder with this code:</p>
<pre><code>string $s = `getenv MAYA_SCRIPT_PATH` + ";C:/MyScripts";
putenv "MAYA_SCRIPT_PATH" $s;
</code></pre>
<p>It didn't work. I also tried to do a... | 0 | 2016-09-06T11:13:47Z | 39,351,499 | <p>At the same place where you find userSetup.mel, you can create a userSetup.py and do whatever import at the beginning of maya or execute any script.</p>
| 0 | 2016-09-06T14:26:25Z | [
"python",
"python-2.7",
"maya",
"mel"
] |
Add user scripts folder to Maya | 39,347,681 | <p>I tried all methods explained on several documentation pages.</p>
<p>I modified the <strong>userSetup.mel</strong> file and it adds the folder with this code:</p>
<pre><code>string $s = `getenv MAYA_SCRIPT_PATH` + ";C:/MyScripts";
putenv "MAYA_SCRIPT_PATH" $s;
</code></pre>
<p>It didn't work. I also tried to do a... | 0 | 2016-09-06T11:13:47Z | 39,377,126 | <p>You don't want to set the environment variable after Maya is up and running, which is what you're doing in the mel example. You want it configured before maya starts looking for actual scripts. In general most programs that use env vars read them at startup time and don't recognize changes made while the program is... | 0 | 2016-09-07T18:46:54Z | [
"python",
"python-2.7",
"maya",
"mel"
] |
Stuck: Can't work out the error - index error python 3.5 | 39,347,857 | <p>Here is part of my code (the part that is raising the issues):</p>
<pre><code>with open('list.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ",")
GTINs = []
products = []
prices = []
for row in readCSV:
GTIN = int(row[0])
product = row[1]
price = float(row... | 1 | 2016-09-06T11:22:21Z | 39,347,957 | <p>It seems that you have an incorrect or black line in your csv. You can handle the index error with a try-except expression.</p>
<pre><code>try:
GTIN = int(row[0])
product = row[1]
price = float(row[2])
GTINs.append(GTIN)
products.append(product)
prices.append(price)
except IndexError:
... | 0 | 2016-09-06T11:28:16Z | [
"python",
"python-3.x"
] |
Stuck: Can't work out the error - index error python 3.5 | 39,347,857 | <p>Here is part of my code (the part that is raising the issues):</p>
<pre><code>with open('list.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ",")
GTINs = []
products = []
prices = []
for row in readCSV:
GTIN = int(row[0])
product = row[1]
price = float(row... | 1 | 2016-09-06T11:22:21Z | 39,348,102 | <p>What i see here is a txt file not CSV. Here is an easy solution :</p>
<pre><code>GTINs = []
products = []
prices = []
with open('stack.txt','r') as f:
for line in f:
sentence = line.split(',')
GTINs.append(sentence[0])
products.append(sentence[1])
prices.append(sentence[2])
print... | 0 | 2016-09-06T11:36:14Z | [
"python",
"python-3.x"
] |
Stuck: Can't work out the error - index error python 3.5 | 39,347,857 | <p>Here is part of my code (the part that is raising the issues):</p>
<pre><code>with open('list.txt') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ",")
GTINs = []
products = []
prices = []
for row in readCSV:
GTIN = int(row[0])
product = row[1]
price = float(row... | 1 | 2016-09-06T11:22:21Z | 39,348,394 | <p>Try to remove empty lines from the list.txt file.</p>
| 0 | 2016-09-06T11:52:09Z | [
"python",
"python-3.x"
] |
How to import a module which opens a file in the same directory as the module? | 39,347,933 | <p>I am trying to call a function <code>is_english_word</code> in a module <code>dict.py</code> in package <code>dictionary</code>. Here is the hierarchy:</p>
<pre><code>DataCleaning
|___ text_cleaner.py
|___ dictionary
|___ dict.py
|___ list_of_english_words.txt
</code></pre>
<p>To clarify, I have <code>di... | 0 | 2016-09-06T11:26:40Z | 39,348,179 | <p>The issue is that you are passing the string <code>'__file__'</code> to <code>os.path.realpath</code> instead of the variable <code>__file__</code>.</p>
<p>Change:</p>
<pre><code>os.path.realpath('__file__')
</code></pre>
<p>To:</p>
<pre><code>os.path.realpath(__file__)
</code></pre>
| 2 | 2016-09-06T11:40:21Z | [
"python",
"python-os"
] |
unicodedata is not found | 39,347,976 | <p>I'm trying to install Twisted on a small board running a version of OpenWRT (chaos calmer). I'm running it step by step so I could track and install the missing packages on the device. Last error was:</p>
<pre><code>ImportError: No module named unicodedata
</code></pre>
<p>I have installed all the packages offered... | 2 | 2016-09-06T11:28:41Z | 39,348,500 | <p>The file <code>unicodedata.so</code> is provided in the <code>python-codecs</code> package. A <a href="https://downloads.openwrt.org/chaos_calmer/15.05.1/x86/64/packages/packages/python-codecs_2.7.9-6_x86_64.ipk" rel="nofollow">x86_64 version</a> is available so presumably it's also available for other architectures... | 2 | 2016-09-06T11:57:55Z | [
"python",
"python-2.7",
"openwrt",
"twisted.internet"
] |
[Pyasn1]: raise error.PyAsn1Error('Component type error %r vs %r' % (t, value)) | 39,348,029 | <p>I have only one choice and within that choice I want to pass the object of the class with only one field. </p>
<p>Here is my code snippet:-</p>
<pre><code>from pyasn1.type import univ, namedtype, tag, char, namedval, useful
from pyasn1.codec.ber import encoder
class MiepPullWtdr(univ.Sequence):
componentType ... | 0 | 2016-09-06T11:31:15Z | 39,401,851 | <p>There is an inconsistency in how <code>MiepPullWtdr</code> type is ASN.1 tagged in its stand-alone definition versus as a <code>ChoiceData</code> component. I am not sure what exactly your intention is, here is one of possibly many consistent versions:</p>
<pre><code>from pyasn1.type import univ, namedtype, tag
cl... | 0 | 2016-09-08T23:59:41Z | [
"python",
"pyasn1"
] |
Why isn't my function returning anything? | 39,348,273 | <p>I am attempting to make a rudimentary chatbot using python and tkinter, and have ran into an issue. I have excluded tkinter code for simplicity. The entire code is visible at the bottom.</p>
<pre><code> def communicate():
sent.set(HUMAN_ENTRY.get())
bottalk(response)
AI_RESPONSE.set(respons... | 0 | 2016-09-06T11:45:13Z | 39,348,366 | <p>Since response returned as value, it won't update the <code>response</code> variable inside <code>communicate</code> function. You need to update <code>response</code> with the value returned from the function:</p>
<pre><code>def communicate():
sent.set(HUMAN_ENTRY.get())
response = bottalk(response)
A... | 3 | 2016-09-06T11:50:23Z | [
"python",
"tkinter"
] |
Why isn't my function returning anything? | 39,348,273 | <p>I am attempting to make a rudimentary chatbot using python and tkinter, and have ran into an issue. I have excluded tkinter code for simplicity. The entire code is visible at the bottom.</p>
<pre><code> def communicate():
sent.set(HUMAN_ENTRY.get())
bottalk(response)
AI_RESPONSE.set(respons... | 0 | 2016-09-06T11:45:13Z | 39,348,822 | <p><code>response</code> is <code>StringVar</code> so you have to use <code>.set(text)</code> instead of <code>=</code> </p>
<pre><code>def bottalk(response):
if sent == 'hello':
response.set('hello recieved')
else:
response.set('hello not recieved')
</code></pre>
<p>And now you don't have to... | 1 | 2016-09-06T12:14:55Z | [
"python",
"tkinter"
] |
Why isn't my function returning anything? | 39,348,273 | <p>I am attempting to make a rudimentary chatbot using python and tkinter, and have ran into an issue. I have excluded tkinter code for simplicity. The entire code is visible at the bottom.</p>
<pre><code> def communicate():
sent.set(HUMAN_ENTRY.get())
bottalk(response)
AI_RESPONSE.set(respons... | 0 | 2016-09-06T11:45:13Z | 39,348,902 | <p>Ok from beginning, i think that you have few mistakes in your code:</p>
<pre><code>class App:
def __init__(self, master):
</code></pre>
<p>You dont have anything in constructor, maybe you should put below code there:</p>
<pre><code> AI_RESPONSE = 'hellgeto'
root.title=('GoBot')
frame = Frame(master... | 0 | 2016-09-06T12:19:31Z | [
"python",
"tkinter"
] |
Filtering DataFrames in Pandas for multiple columns where a column name contains a pattern | 39,348,317 | <p>While filtering multiple columns I have seen examples where we could filter Rows using something like this <code>df[df['A'].str.contains("string") | df['B'].str.contains("string")]</code> .</p>
<p>I have multiple files where I want to fetch each file and get only those rows with <code>'gmail.com'</code> from the co... | 1 | 2016-09-06T11:47:54Z | 39,348,412 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.any.html" rel="nofollow"><code>any</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>
<pre><code>pdf = pd.DataFrame({'A'... | 1 | 2016-09-06T11:53:18Z | [
"python",
"pandas",
"indexing",
"filter",
"multiple-columns"
] |
Filtering DataFrames in Pandas for multiple columns where a column name contains a pattern | 39,348,317 | <p>While filtering multiple columns I have seen examples where we could filter Rows using something like this <code>df[df['A'].str.contains("string") | df['B'].str.contains("string")]</code> .</p>
<p>I have multiple files where I want to fetch each file and get only those rows with <code>'gmail.com'</code> from the co... | 1 | 2016-09-06T11:47:54Z | 39,348,462 | <p>Given example input of:</p>
<pre><code>df = pd.DataFrame({'email': ['[email protected]', '[email protected]'], 'somethingelse': [1, 2], 'another_email': ['[email protected]', '[email protected]']})
</code></pre>
<p>eg:</p>
<pre><code> another_email email somethingelse
0 whatever@ex... | 1 | 2016-09-06T11:56:18Z | [
"python",
"pandas",
"indexing",
"filter",
"multiple-columns"
] |
Error while installing pygraphviz on OS X with Anaconda | 39,348,416 | <p>I am trying to install pygraphviz in OS X 10.9.5. I am using Python 2.7.12 with Anaconda 2.1.0. I already have graphviz installed. </p>
<p>Here is the error I get when running pip install pygraphviz </p>
<pre><code> #include "graphviz/cgraph.h"
^
compilation terminated.
error:... | 1 | 2016-09-06T11:53:27Z | 39,886,711 | <p>On Mac OSX, I solve it with:</p>
<pre><code>pip install graphviz
pip install --install-option="--include-path=/opt/local/include" --install-option="--library-path=/opt/local/lib" pygraphviz
</code></pre>
<p>GitHub related <a href="https://github.com/pygraphviz/pygraphviz/issues/11" rel="nofollow">issue</a></p>
| 0 | 2016-10-06T02:46:24Z | [
"python",
"python-2.7",
"anaconda"
] |
Python - recursion not working | 39,348,421 | <p>I have a following code:</p>
<pre><code>d = {'init':
[{'solve':
[{'subsolve':
[{'vals': [{'Blade summary': 'asdf'},
{'Blade summary': 'fdsa'}]}]},
{'subsolve':
[{'vals': [{'Blade summary': 'ffff... | 0 | 2016-09-06T11:53:45Z | 39,348,492 | <p>You need to actually do something with the result of your recursive calls. Since you're using <code>yield</code> with the value, you probably need to use it there too.</p>
| 1 | 2016-09-06T11:57:47Z | [
"python",
"python-3.x",
"dictionary",
"recursion",
"pycharm"
] |
Python - recursion not working | 39,348,421 | <p>I have a following code:</p>
<pre><code>d = {'init':
[{'solve':
[{'subsolve':
[{'vals': [{'Blade summary': 'asdf'},
{'Blade summary': 'fdsa'}]}]},
{'subsolve':
[{'vals': [{'Blade summary': 'ffff... | 0 | 2016-09-06T11:53:45Z | 39,348,695 | <p>In Python 3.4 you can use <code>yield from parseDics(vals, 'vals')</code>, for Python 2:</p>
<pre><code>for val in parseDics(vals, 'vals'):
yield val
</code></pre>
| 1 | 2016-09-06T12:08:42Z | [
"python",
"python-3.x",
"dictionary",
"recursion",
"pycharm"
] |
Python - recursion not working | 39,348,421 | <p>I have a following code:</p>
<pre><code>d = {'init':
[{'solve':
[{'subsolve':
[{'vals': [{'Blade summary': 'asdf'},
{'Blade summary': 'fdsa'}]}]},
{'subsolve':
[{'vals': [{'Blade summary': 'ffff... | 0 | 2016-09-06T11:53:45Z | 39,348,962 | <p><code>parseDics</code> isn't a regular function, it's a generator. So you need to call it like a generator, rather than a regular function, otherwise it won't work. The first call works because when you call <code>list(parseDicts(...))</code>, the list constructor is calling <code>parseDicts</code> as a generator. B... | 1 | 2016-09-06T12:22:20Z | [
"python",
"python-3.x",
"dictionary",
"recursion",
"pycharm"
] |
Unsure how to cancel long-running asyncio task | 39,348,476 | <p>I'm developing a CLI that interacts with a web service. When run, it will try to establish communication with it, send requests, receive and process replies and then terminate. I'm using coroutines in various parts of my code and asyncio to drive them. What I'd like is to be able to perform all these steps and then ... | 1 | 2016-09-06T11:56:59Z | 39,352,458 | <p>I figured it out - I need to define <code>CommunicationService.stop()</code> as the following:</p>
<pre><code>def stop(self):
if self._listen_task is None or self._ws is None:
return
self._listen_task.cancel()
self._loop.run_until_complete(asyncio.wait([self._listen_task, self._ws.close()]))
... | 0 | 2016-09-06T15:12:47Z | [
"python",
"python-3.x",
"python-asyncio"
] |
Gevent backdoor inspect runing code | 39,348,488 | <p>I am using <code>gevent</code> with its <code>Backdoor</code> feature.</p>
<p>This is a simplified version of my code :</p>
<pre><code>from gevent import backdoor, event
class App(object):
def __init__(self):
self.stop_event = event.Event()
self.servers = []
self.servers.append(backdoo... | 0 | 2016-09-06T11:57:29Z | 39,350,901 | <p>Ok, I found a solution. The <code>greenlet</code> object has a <code>parent</code> attribute to find which one has spawned the one you are currently looking at. Then the greenlet has an attribute <code>gr_frame</code> to store the stacktrace.</p>
<p>So in my case, once I am connected to the backdoor server, it woul... | 0 | 2016-09-06T13:57:42Z | [
"python",
"python-2.7",
"gevent",
"inspect"
] |
Command "python setup.py egg_info" failed when installing a package | 39,348,496 | <p>I am trying to install a bunch of dependencies from the <code>requirements.txt</code> file of a cloned Django project. However, when it's trying to install one of them, <code>vobject-0.8.1c</code> the following error is displayed and none of the dependencies are installed:</p>
<blockquote>
<p>Command "python setu... | 1 | 2016-09-06T11:57:52Z | 39,350,379 | <p>Install <code>0.8.2</code>. It's first pip-installable version. All files is the same as in <code>0.8.1c</code> version, except:</p>
<p><strong>base.py</strong></p>
<pre><code>286a287,288
> for k,v in self.params.items():
> self.params[k] = copy.copy(v)
630,631c632,633
< def __init... | 0 | 2016-09-06T13:34:56Z | [
"python",
"django",
"pip"
] |
How to display Foreign Key's choices in django-admin? | 39,348,521 | <p>I have small problem related to django-admin panel.
I have 2 models:</p>
<pre><code>from django.db import models
class Subject(models.Model):
subject = models.CharField(max_length=30, choices=[('P', 'Personal'), ('W', 'Work')])
def __str__(self):
return self.subject
class BlogPost(models.Model):
... | 2 | 2016-09-06T11:58:40Z | 39,350,224 | <p>By the way you have done it you have to first add the subjects themselves so they can appear in your foreign key choices. you could have the same results by:</p>
<pre><code>class BlogPost(models.Model):
id = models.AutoField(unique=True, primary_key=True)
subject = models.CharField(max_length=30, choices=[(... | 2 | 2016-09-06T13:27:01Z | [
"python",
"django"
] |
Is any() evaluated lazily? | 39,348,588 | <p>I am writing a script in which i have to test numbers against a number of conditions. If <strong>any</strong> of the conditions are met i want to return <code>True</code> and i want to do that the fastest way possible.</p>
<p>My first idea was to use <code>any()</code> instead of nested <code>if</code> statements o... | 3 | 2016-09-06T12:01:54Z | 39,348,689 | <p>Yes, <code>any()</code> and <code>all()</code> short-circuit, aborting as soon as the outcome is clear: See the <a href="https://docs.python.org/3/library/functions.html#all">docs</a>:</p>
<blockquote>
<p><strong>all(iterable)</strong></p>
<p>Return True if all elements of the iterable are true (or if the
... | 9 | 2016-09-06T12:08:20Z | [
"python"
] |
Is any() evaluated lazily? | 39,348,588 | <p>I am writing a script in which i have to test numbers against a number of conditions. If <strong>any</strong> of the conditions are met i want to return <code>True</code> and i want to do that the fastest way possible.</p>
<p>My first idea was to use <code>any()</code> instead of nested <code>if</code> statements o... | 3 | 2016-09-06T12:01:54Z | 39,348,748 | <p>While the <a href="https://docs.python.org/2.7/library/functions.html#all" rel="nofollow"><code>all()</code></a> and <a href="https://docs.python.org/2.7/library/functions.html#any" rel="nofollow"><code>any()</code></a> functions short-circuit on the first "true" element of an iterable, the iterable itself may be co... | 4 | 2016-09-06T12:11:10Z | [
"python"
] |
Is any() evaluated lazily? | 39,348,588 | <p>I am writing a script in which i have to test numbers against a number of conditions. If <strong>any</strong> of the conditions are met i want to return <code>True</code> and i want to do that the fastest way possible.</p>
<p>My first idea was to use <code>any()</code> instead of nested <code>if</code> statements o... | 3 | 2016-09-06T12:01:54Z | 39,348,758 | <p>Yes, it's lazy as demonstrated by the following:</p>
<pre><code>def some(x, result=True):
print(x)
return result
>>> print(any(some(x) for x in range(5)))
0
True
>>> print(any(some(x, False) for x in range(5)))
0
1
2
3
4
False
</code></pre>
<p>In the first run <code>any()</code> halted ... | 2 | 2016-09-06T12:11:31Z | [
"python"
] |
Is any() evaluated lazily? | 39,348,588 | <p>I am writing a script in which i have to test numbers against a number of conditions. If <strong>any</strong> of the conditions are met i want to return <code>True</code> and i want to do that the fastest way possible.</p>
<p>My first idea was to use <code>any()</code> instead of nested <code>if</code> statements o... | 3 | 2016-09-06T12:01:54Z | 39,348,770 | <p>Yes, and here is an experiment that shows it even more definitively than your timing experiment:</p>
<pre><code>import random
def some(x):
print(x, end = ', ')
return random.random() < 0.25
for i in range(5):
print(any(some(x) for x in range(10)))
</code></pre>
<p>typical run:</p>
<pre><code>0, 1... | 2 | 2016-09-06T12:12:14Z | [
"python"
] |
Is any() evaluated lazily? | 39,348,588 | <p>I am writing a script in which i have to test numbers against a number of conditions. If <strong>any</strong> of the conditions are met i want to return <code>True</code> and i want to do that the fastest way possible.</p>
<p>My first idea was to use <code>any()</code> instead of nested <code>if</code> statements o... | 3 | 2016-09-06T12:01:54Z | 39,348,881 | <p>As Tim correctly mentioned, <code>any</code> and <code>all</code> do short-circuit, but in your code, what makes it <em>lazy</em> is the use of <a href="http://stackoverflow.com/questions/47789/generator-expressions-vs-list-comprehension">generators</a>. For example, the following code would not be lazy:</p>
<pre><... | 3 | 2016-09-06T12:18:07Z | [
"python"
] |
python testing strategy to develop and auto-grader | 39,348,605 | <p>I have a list of input files and an expected output file, I want to write an auto-grader that does the job of accepting a python program, running it on the input files, and comparing its output to the output file. The approach I have used is to use the <code>os</code> module of python to run the program using <code>... | 1 | 2016-09-06T12:02:49Z | 39,348,840 | <p>You can be doing everything using builtin modules in Python 3.3+, since you are effectively spinning up a <a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow"><code>subprocess</code></a> and doing a <a href="https://docs.python.org/3/library/difflib.html" rel="nofollow"><code>diff</code></a> on... | 0 | 2016-09-06T12:16:08Z | [
"python",
"file",
"python-3.4",
"file-handling"
] |
pandas dataframe: len(df) is not equal to number of iterations in df.iterrows() | 39,348,632 | <p>I have a dataframe where I want to print each row to a different file. When the dataframe consists of e.g. only 50 rows, <code>len(df)</code> will print <code>50</code> and iterating over the rows of the dataframe like</p>
<pre><code>for index, row in df.iterrows():
print(index)
</code></pre>
<p>will print the... | 0 | 2016-09-06T12:04:15Z | 39,348,792 | <p>First, as @EdChum noted in the comment, your question's title refers to <code>iterrows</code>, but the example you give refers to <a href="http://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.DataFrame.iteritems.html" rel="nofollow"><code>iteritems</code></a>, which loops in the orthogonal direction ... | 2 | 2016-09-06T12:13:12Z | [
"python",
"pandas",
"dataframe"
] |
Scons copy header files to build directory | 39,348,788 | <p>I'm trying to copy a number of headers files from my source directories to an 'includes' directory inside my build directory using scons. My target is a static library and I want to distribute it together with its relevant headers. The expected end result:</p>
<pre><code>build
|-- objects -> .o output files for ... | 1 | 2016-09-06T12:12:54Z | 39,350,875 | <p>You probably want to use "<code>Install()</code>" instead of "<code>Copy()</code>". Also the <code>Mkdir()</code> shouldn't be necessary, SCons creates all intermediate folders for its targets automatically.</p>
<p>Finally, allow me some comments about your general approach: I'd rather not mix "building" with "inst... | 2 | 2016-09-06T13:56:52Z | [
"python",
"scons"
] |
Scons copy header files to build directory | 39,348,788 | <p>I'm trying to copy a number of headers files from my source directories to an 'includes' directory inside my build directory using scons. My target is a static library and I want to distribute it together with its relevant headers. The expected end result:</p>
<pre><code>build
|-- objects -> .o output files for ... | 1 | 2016-09-06T12:12:54Z | 39,355,253 | <p>The <em>Mkdir</em> and <em>Copy</em> operations that you are using are Action factories for use in Command definitions, described in <a href="http://scons.org/doc/production/HTML/scons-user.html#chap-factories" rel="nofollow">Platform-Independent File System Manipulation</a>:</p>
<blockquote>
<p>SCons provides a ... | 0 | 2016-09-06T18:06:23Z | [
"python",
"scons"
] |
Deactivate pyenv in current shell | 39,348,806 | <p>My .bashrc has this:</p>
<pre><code>enable-pyenv () {
# Load pyenv automatically by adding
# the following to your profile:
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
}
enable-pyenv
</code></pre>
<p>Which enables pyenv. In some situations, I ... | 0 | 2016-09-06T12:14:02Z | 39,348,931 | <p>Try <code>pyenv deactivate</code>, to manually deactivate the virtual env.</p>
<p>Doc here: <a href="https://github.com/yyuu/pyenv-virtualenv" rel="nofollow">https://github.com/yyuu/pyenv-virtualenv</a></p>
| 1 | 2016-09-06T12:20:55Z | [
"python",
"pyenv"
] |
Elasticsearch (Elasticsearch Curator) Python API. Get dictionary of ES indices and their sizes | 39,348,851 | <p>I can get all of ES indexes in list via such code:</p>
<pre><code>from elasticsearch import Elasticsearch
es = Elasticsearch()
indices=es.indices.get_aliases().keys()
sorted(indices)
</code></pre>
<p>But is it possible to get dictionary like <code>{'index1': '100gb', 'index2': '10gb', 'index3': '15gb'}</code>. So... | 1 | 2016-09-06T12:16:28Z | 39,352,688 | <p>My variant:</p>
<pre><code>import elasticsearch
client = elasticsearch.Elasticsearch()
all_indices = client.indices.stats(metric='store', human=True)['indices'].keys()
dic_indices = {}
for index in all_indices:
size = client.indices.stats(metric='store', human=True)['indices'][index]['total']['store']['size']... | 2 | 2016-09-06T15:24:50Z | [
"python",
"api",
"dictionary",
"elasticsearch",
"elasticsearch-curator"
] |
Elasticsearch (Elasticsearch Curator) Python API. Get dictionary of ES indices and their sizes | 39,348,851 | <p>I can get all of ES indexes in list via such code:</p>
<pre><code>from elasticsearch import Elasticsearch
es = Elasticsearch()
indices=es.indices.get_aliases().keys()
sorted(indices)
</code></pre>
<p>But is it possible to get dictionary like <code>{'index1': '100gb', 'index2': '10gb', 'index3': '15gb'}</code>. So... | 1 | 2016-09-06T12:16:28Z | 39,380,587 | <p>Curator 4 pulls much of the index metadata at IndexList initialization. It's in bytes, rather than in human readable sizes, if that matters. </p>
<p>It is in <strong>IndexList.index_info[index_name]['size_in_bytes']</strong></p>
<p>Read more about the IndexList method at <a href="http://curator.readthedocs.io/en... | 2 | 2016-09-07T23:50:46Z | [
"python",
"api",
"dictionary",
"elasticsearch",
"elasticsearch-curator"
] |
python & pandas- Calculation bewteen rows based on certain values in columns from DataFrame | 39,348,858 | <p>I have a large DataFrame (called df_NoMissing) with thousands of rows, and I need to do calculation and analysis with them.</p>
<pre><code> NoDemande NoUsager Sens IdVehiculeUtilise Fait HeureArriveeSurSite HeureEffective Periods
0 42196000013 000001 + 287Véh 1 11/07/2015 08:02... | 0 | 2016-09-06T12:16:44Z | 39,349,987 | <p>So my solution is:</p>
<ol>
<li><p>to join df1 and df2 (not append them, but join with outer join). For this you should rename all the columns in df2 except of NoDemande, NoUsager and Period. for example, in df1 it will be Sens, in df2 - Sens2. And after join try to subtract the dates as you want. </p></li>
<li><p>... | 1 | 2016-09-06T13:16:19Z | [
"python",
"pandas",
"dataframe"
] |
python & pandas- Calculation bewteen rows based on certain values in columns from DataFrame | 39,348,858 | <p>I have a large DataFrame (called df_NoMissing) with thousands of rows, and I need to do calculation and analysis with them.</p>
<pre><code> NoDemande NoUsager Sens IdVehiculeUtilise Fait HeureArriveeSurSite HeureEffective Periods
0 42196000013 000001 + 287Véh 1 11/07/2015 08:02... | 0 | 2016-09-06T12:16:44Z | 39,350,546 | <p>Okay, starting with your DF as provided - let's create an index on the grouping columns and pivot to columns for the <code>Sens</code> action:</p>
<pre><code>temp = df.set_index(['NoDemande', 'NoUsager', 'Periods']).pivot(columns='Sens')
</code></pre>
<p>Then - we take the appropriate difference (as according to y... | 0 | 2016-09-06T13:42:35Z | [
"python",
"pandas",
"dataframe"
] |
understanding Python asyncio profiler output | 39,348,869 | <p>I'm trying to understand the output of Python profiler while running Python asyncio based program:</p>
<p><a href="http://i.stack.imgur.com/LqYaw.png" rel="nofollow"><img src="http://i.stack.imgur.com/LqYaw.png" alt="Python3 asyncio profiler output"></a></p>
<p>I can see that my program is spending ~67% of time tr... | 1 | 2016-09-06T12:17:13Z | 39,353,903 | <p>Looks like you are using debugger that collects data from all threads.
Waiting for condition variable acquiring means an idle waiting in thread pool for new tasks.</p>
<p>Time spent in <code>select</code> means again idle waiting, but in this case it's waiting for network activity.</p>
| 0 | 2016-09-06T16:36:23Z | [
"python",
"python-3.x",
"profiling",
"python-asyncio"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.