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
Simple Tictactoe program
37,908,182
<p>I am trying to implement a simple tic tac toe program, but having difficulty implementing the gaming. This is the code I have so far:</p> <pre><code>from Tkinter import * click = False class Buttons(object): def __init__(self,master): frame = Frame(master) frame.pack() self.button1= B...
0
2016-06-19T14:17:57Z
37,908,514
<p>I think the problem is that you are trying to assign the <code>global</code> keyword from within your function to a variable that does not exist.</p> <p>There is no <code>buttons</code> variable in the main body of your file.</p>
1
2016-06-19T14:52:53Z
[ "python", "python-2.7", "tkinter", "tic-tac-toe" ]
Simple Tictactoe program
37,908,182
<p>I am trying to implement a simple tic tac toe program, but having difficulty implementing the gaming. This is the code I have so far:</p> <pre><code>from Tkinter import * click = False class Buttons(object): def __init__(self,master): frame = Frame(master) frame.pack() self.button1= B...
0
2016-06-19T14:17:57Z
37,908,838
<p>The problem when you click on a button, the program needs to know which button you clicked, which is why you're trying to access some global <code>buttons</code>, there's no need for that, you can pass the button and anything else that is required into your command handler e.g. <code>command=lambda self.click(self.b...
0
2016-06-19T15:27:36Z
[ "python", "python-2.7", "tkinter", "tic-tac-toe" ]
Simple Tictactoe program
37,908,182
<p>I am trying to implement a simple tic tac toe program, but having difficulty implementing the gaming. This is the code I have so far:</p> <pre><code>from Tkinter import * click = False class Buttons(object): def __init__(self,master): frame = Frame(master) frame.pack() self.button1= B...
0
2016-06-19T14:17:57Z
37,908,888
<p>First of all, whenever you find yourself repeating almost the same line or lines of code, it's a clue that you need to write some kind of loop.</p> <p>Secondly, you can avoid using a global variable by passing the data as an argument to your <code>command</code> function — which will make the error you're getting...
2
2016-06-19T15:33:37Z
[ "python", "python-2.7", "tkinter", "tic-tac-toe" ]
Flask on login redirection issue
37,908,238
<p>I am sending out a confirmation token to users after they register to confirm their email. The issue I have is that I cant get to the confirm method as it requires the user to login and once they go to the login method I cant work out how to direct them back to the confirm method. </p> <p>Note the code is heavily b...
0
2016-06-19T14:23:24Z
37,935,487
<p>I'm also learning from this book. Though I don't know what's wrong with you, I can show some key information to you to solve your problem.</p> <ul> <li>First, your test email have the URL like this.(<a href="http://127.0.0.1:5000/auth/confirm/eyJleHAiOjE0NjY0ODQwOTAsImFsZyI6IkhTMjU2IiwiaWF0IjoxNDY2NDgwNDkwfQ.eyJjb...
0
2016-06-21T04:14:57Z
[ "python", "redirect", "flask", "token" ]
Flask cli can't import application set with FLASK_APP
37,908,358
<p>Following the Flask 0.11 documentation, I cloned the Flask repo, created a virtualenv, and installed Flask via <code>pip install flask</code>. I went into the <code>examples/flaskr</code> directory, set the <code>FLASK_APP</code> environment variable, then executed:</p> <pre><code>flask run </code></pre> <p>Howev...
1
2016-06-19T14:36:14Z
37,972,046
<p>I was setting <code>FLASK_APP=flaskr</code>. Since I hadn't installed my app as a package in my virtualenv, I needed to add the <code>.py</code> extension.</p> <pre><code>export FLASK_APP=flaskr.py </code></pre>
4
2016-06-22T15:13:01Z
[ "python", "flask" ]
Unable to import ctypes on google-app-engine development server
37,908,391
<p>Since upgrading from Ubuntu 14.04 to 16.04 I get the following error on the local development server:</p> <pre><code>ERROR 2016-06-19 14:03:10,294 wsgi.py:263] Traceback (most recent call last): File "/home/mort/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add...
3
2016-06-19T14:39:11Z
37,915,273
<p>You need a corresponding version of 1.6.1 installed on your local system to match the runtime-supported version 1.6.1 when doing:</p> <pre><code>libraries: - name: numpy version: "1.6.1" </code></pre> <p>Although with <a href="https://cloud.google.com/appengine/docs/flexible/" rel="nofollow">app engine flexible<...
4
2016-06-20T05:42:24Z
[ "python", "google-app-engine", "numpy" ]
Serialize complex fields in django rest framework
37,908,448
<p>I have a model that has a JSON field <em>extra_data</em> that contains other fields that might be added to the model. From the beginning it is not known how many fields will be added apart from the compulsory ones, which is why I introduced the <em>extra_data</em> field.</p> <p>With the usual rest framework seriali...
0
2016-06-19T14:45:17Z
37,908,509
<p>The serializer itself I don't think can do this, since you do not know how many fields are there. But once you get the serializer.data, you may update your dict like:</p> <pre><code>serializer_data = serializer.data extra_data = serializer_data.pop('extra_data') serializer_data.update(extra_data) return serializer_...
1
2016-06-19T14:52:18Z
[ "python", "django", "serialization", "django-rest-framework" ]
Changing Selenium driver for new URL
37,908,458
<p>I used Selenium to navigate to a URL (i.e. URL_1) with a login/password and provided the login credentials. I'm logged in and the URL (i.e. URL_2) has changed as expected. I don't know how to navigate URL_2 because the driver still refers to URL_1. </p> <p>Thanks in advance.</p> <pre><code>from selenium import ...
1
2016-06-19T14:46:21Z
37,908,486
<p>Instead of having independent functions, <em>create a class</em> with driver instance as an <em>instance variable</em>. Then, use <code>self.driver.get()</code> to navigate to a different URL:</p> <pre><code>class MyTest(object): def __init__(self): self.driver = webdriver.Firefox() def login_proce...
0
2016-06-19T14:50:35Z
[ "python", "python-2.7", "firefox", "selenium-webdriver" ]
Changing Selenium driver for new URL
37,908,458
<p>I used Selenium to navigate to a URL (i.e. URL_1) with a login/password and provided the login credentials. I'm logged in and the URL (i.e. URL_2) has changed as expected. I don't know how to navigate URL_2 because the driver still refers to URL_1. </p> <p>Thanks in advance.</p> <pre><code>from selenium import ...
1
2016-06-19T14:46:21Z
37,908,606
<p>First you can assign the url variable as a global:</p> <pre><code>global url; url = "firstURL" </code></pre> <p>At the end of your first function you can change the value of the variable to the new URL:</p> <pre><code>url = driver.current_url </code></pre> <p>And then you can get the new url at the beginning of ...
0
2016-06-19T15:02:15Z
[ "python", "python-2.7", "firefox", "selenium-webdriver" ]
Attach timestamp to created logfile
37,908,556
<p>I have a shell script from which I am creating some logfile in a directory. And this shell script I am executing in python as below.</p> <pre><code>cmd = "sh xyz.sh" try: subprocess.call(cmd,shell=True) except OSError: print "Failed to run the script.: </code></pre> <p>I want to attach the timestamp on tho...
0
2016-06-19T14:57:03Z
37,911,704
<p>If you already know the name of the generated logfile, you can use <code>os.rename</code> to rename it. Something along the lines of :</p> <pre><code>import time, os b = time.strftime("%x") c = time.strftime("%X") ts = b + "_" + c os.rename("abc.log", ts + "_abc.log") </code></pre> <p>If you don't know the name ...
0
2016-06-19T20:50:25Z
[ "python" ]
Webdriver.get() will not navigate to another page until I add wait before the call
37,908,557
<p>I have a Python 3.5 script that basically logs into a web site (and gets redirected after login) and then navigates to another page where it actually does its job. If I run <code>webdriver.get()</code> to this second page right after the login, it doesn't navigate to the target location and stays on the page it gets...
2
2016-06-19T14:57:20Z
37,908,597
<p>You need to apply the concept of <a href="http://selenium-python.readthedocs.io/waits.html#explicit-waits" rel="nofollow">Explicit Waits</a> and the <code>WebDriverWait</code> class. You just need to choose which of the Expected Conditions to wait for. It sounds like the <code>title_is</code> and <code>title_contain...
1
2016-06-19T15:01:23Z
[ "python", "python-3.x", "selenium", "selenium-webdriver" ]
printing multiple images url's with different id's
37,908,696
<p>I'm trying to print multiple images url's with different id's. I'm using selenium in python and I have been trying this code:</p> <pre><code> for i in range (5000): path= "product-collection-image-"+str(i) try: image = driver.find_element_by_id(path) ...
1
2016-06-19T15:10:22Z
37,908,708
<p>Just use the <em>partial <code>id</code> match</em>:</p> <pre><code>image_srcs = [img.get_attribute("src") for img in driver.find_elements_by_css_selector('[id^="product-collection-image-"]')] </code></pre> <p>where <code>^=</code> means "starts with".</p> <p>Note that, this way you would get the i...
1
2016-06-19T15:12:05Z
[ "python", "image", "loops", "selenium", "src" ]
Django admin only works with python 2
37,908,700
<p>I'm using Django in a virtualenv. The admin page only works in python 2. When i run python3 manage.py runserver i get an error: </p> <blockquote> <p>AttributeError at /admin/ 'WSGIRequest' object has no attribute 'user'</p> </blockquote> <p>But when i run python2 manage.py runserver it is all fine. Did install d...
0
2016-06-19T15:11:12Z
37,909,360
<p>First check the version you're running by typing:</p> <pre><code>python -V </code></pre> <p>To get the python 2 version, then</p> <pre><code>python3 -V </code></pre> <p>To get the python3 Version.</p> <p>If you could post both versions, a screenshot of the full error, as well as the admin.py file in the app's ...
0
2016-06-19T16:23:46Z
[ "python", "django", "python-3.x", "django-admin" ]
Create a file 'path like string' from a Python Dictionary
37,908,747
<p>I found a method to iterate a python dictionary object recursively on this forum. However, I wish to extend that function so that I get a string similar to the structure of a file path. With my function below, I expect an output in the form of</p> <pre><code>/key1/value1 /key2/value2 /key3/key3a/value3a /key4/key4...
1
2016-06-19T15:16:14Z
37,908,813
<p>Your function appears overly complicated. Only actually print when you have an object that's not a dictionary, otherwise recurse for <em>all</em> values in a dictionary. I simplified path handling to just one string:</p> <pre><code>def print_dict(ob, path=''): if not isinstance(ob, dict): print '{}/{}'....
2
2016-06-19T15:24:23Z
[ "python", "dictionary", "recursion" ]
Django, psycopg2 and database not found
37,908,781
<p>I recently (yesterday) decided to try Django. So i followed <a href="https://vexxhost.com/resources/tutorials/how-to-deploy-django-on-nginx-gunicorn-with-postgres/" rel="nofollow">this guide</a> </p> <p>everything seems to work fine, until i tried this command :</p> <pre><code>python manage.py syncdb </code></pre>...
0
2016-06-19T15:19:59Z
37,908,892
<p>You should pass the name of the database, not the filename. <code></p> <pre><code> DATABASES = { 'default': { ... 'NAME': 'demo_db', ... } } </code></pre> <p></code></p>
0
2016-06-19T15:34:07Z
[ "python", "django", "postgresql", "virtualenv", "psycopg2" ]
Django, psycopg2 and database not found
37,908,781
<p>I recently (yesterday) decided to try Django. So i followed <a href="https://vexxhost.com/resources/tutorials/how-to-deploy-django-on-nginx-gunicorn-with-postgres/" rel="nofollow">this guide</a> </p> <p>everything seems to work fine, until i tried this command :</p> <pre><code>python manage.py syncdb </code></pre>...
0
2016-06-19T15:19:59Z
37,908,902
<p>You only need to put the name of the database in your settings; not the path:</p> <pre><code>DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'demo_db', 'USER': 'demo_user', 'PASSWORD': 'XXXXXXXXXX', 'HOST': 'localhost', 'PORT...
1
2016-06-19T15:35:26Z
[ "python", "django", "postgresql", "virtualenv", "psycopg2" ]
How to set PyQt5 QIntValidator's top and bottom?
37,908,789
<p>I have a line edit like the code below. in 3 different codes I have 2 different problems:</p> <pre><code>self.rnr_id_num_le = QLineEdit() self.rnr_id_num_le.setValidator(QIntValidator(9999999999, 0)) </code></pre> <p>using this I can pnly enter 0 and 1.</p> <p>and</p> <pre><code>self.rnr_id_num_le = QLineEdit() ...
1
2016-06-19T15:21:25Z
37,929,693
<p>The <code>QIntValidator</code> class only supports signed values in the range <code>-2147483647, 2147483647</code>. If you need values outside this range, use <code>QDoubleValidator</code>, which supports unlimited floating point values.</p> <p>You can create a simple sub-class of <code>QDoubleValidator</code> to t...
1
2016-06-20T18:47:39Z
[ "python", "python-3.x", "pyqt5" ]
Twisted Import Error when using Scrapy in Python 3
37,908,806
<p>I'm having the following error when trying to use Scrapy in Python 3. I'm using Ubuntu 16.04 and installing <code>python3-twisted</code> didn't solve the issue.</p> <pre><code> File "/home/fran/.local/lib/python3.5/site-packages/scrapy/crawler.py", line 150, in crawl crawler = self._create_crawler(crawler_or_s...
0
2016-06-19T15:23:17Z
37,909,024
<p>Scrapy's Python 3 support is still in a beta stage and (according to the <a href="http://doc.scrapy.org/en/latest/news.html#beta-python-3-support" rel="nofollow">release notes</a>)</p> <blockquote> <p>Sending emails is not supported</p> </blockquote> <p>so it's unlikely you can do anything to fix this.</p>
2
2016-06-19T15:49:25Z
[ "python", "python-3.x", "ubuntu", "scrapy", "twisted" ]
memory exhaust on big matrix operation using dask
37,908,850
<p>Currently I'm implementing this <a href="http://www.robots.ox.ac.uk/~vgg/publications/2013/Simonyan13/simonyan13.pdf" rel="nofollow">paper</a> for my undergraduate theses with python, but I only use the mahalanobis metric learning (in case you're curious). </p> <p>In a shortcut, I face a problem when I need to lear...
0
2016-06-19T15:29:01Z
37,911,650
<p>Generally speaking dask.array does not guarantee out-of-core operation on all computations. A square matrix-matrix multiply (or any L3 BLAS operation) is more-or-less impossible to do efficiently in small memory. </p> <p>You <em>can</em> ask Dask to use an on-disk cache for intermediate values. See the <a href="...
0
2016-06-19T20:43:47Z
[ "python", "numpy", "linear-algebra", "svd", "dask" ]
Why can't we get the range of a particular negative number
37,908,889
<pre><code>for i in range(3): print (i) </code></pre> <p>We will get the count from 0 to 2.</p> <p>But I want to know the range of a particular negative number. For example -3. I came to know from my friend, that because of indexing the negative numbers can't store the value. I am unable to understand this concep...
0
2016-06-19T15:33:48Z
37,908,903
<p>Ranges are not indices, and can produce negative numbers just fine:</p> <pre><code>&gt;&gt;&gt; list(range(-3, 0)) [-3, -2, -1] </code></pre> <p>Do note that I had to specify both a start and end value, otherwise it'll start at 0 and the default direction is to count <em>up</em>.</p> <p>If you need to count down ...
4
2016-06-19T15:35:32Z
[ "python", "range" ]
SQLAlchemy: getting a value from the initializer
37,908,935
<p>I have the following table using <strong>Flask-SQLAlchemy</strong>:</p> <pre><code>class Posts(db.Model): id = db.Column(db.Integer, primary_key=True) hashID = db.Column(db.String(6)) post = db.Column(db.String(500)) def __init__(self, post): self.hashID = hashid.encode(self.id) ...
2
2016-06-19T15:38:42Z
38,027,296
<p>The <a href="http://docs.sqlalchemy.org/en/latest/orm/tutorial.html#create-an-instance-of-the-mapped-class" rel="nofollow">documentation</a> states that the <code>self.id</code> attribute is not set until the <code>INSERT</code> statement for that entity was issued. That means: unless you don't issue the <code>INSER...
0
2016-06-25T10:08:11Z
[ "python", "database", "flask", "sqlalchemy", "flask-sqlalchemy" ]
How to add error bars to interaction plot (statsmodels)?
37,908,989
<p>I have the following code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt from statsmodels.graphics.factorplots import interaction_plot a = np.array( [ item for item in [ 'a1', 'a2', 'a3' ] for _ in range(30) ] ) b = np.array( [ item for _ in range(45) for item in [ 'b1', 'b2' ] ] ) np.random.se...
0
2016-06-19T15:45:38Z
37,909,486
<p>Well, it seems that the feature is <a href="https://github.com/statsmodels/statsmodels/issues/788" rel="nofollow">not yet directly supported</a>, so I just decided to directly modify the <a href="http://statsmodels.sourceforge.net/devel/_modules/statsmodels/graphics/factorplots.html#interaction_plot" rel="nofollow">...
0
2016-06-19T16:37:07Z
[ "python", "matplotlib", "plot", "statsmodels" ]
pandas conditional and not
37,908,996
<p>I do select parts of my dataframe for fitting using a mask:</p> <pre><code>mask = (data.conc == 50) &amp; (data.id_exp == 'Pxxx') </code></pre> <p>During the fit I found a probable outlier and would like to do something like</p> <pre><code>mask = (data.conc == 50) &amp; (data.id_exp == 'P049V208') and not (data.r...
0
2016-06-19T15:46:27Z
37,909,062
<p>Use <code>&amp;</code> (instead of <code>and</code>) to perform element-wise bitwise-and, and use <code>~</code> (instead of <code>not</code>) to invert the boolean mask.</p> <pre><code>mask = ((data.conc == 50) &amp; (data.id_exp == 'P049V208') &amp; ~((data.ratio == 10) &amp; (data.salt_concentr...
1
2016-06-19T15:54:04Z
[ "python", "pandas" ]
Tkinter withdraw oddness with pyHook
37,909,046
<p>I have a Tkinter GUI application that I need to hide on a buttonpress. I cannot assume that the application will have focus, so I implemented pyHook, keylogger-style. However, whenever I call withdraw() from a function launched by pyHook, the window hangs and I have to force-close it. </p> <p>To test, I added a but...
1
2016-06-19T15:52:09Z
37,945,592
<p>Solved as per <a href="http://stackoverflow.com/a/37918874/2864129">this answer here</a>:</p> <p>Essentially, the function inside the Tkinter class responsible for dealing with keypresses, <code>ButtonPress</code>, cannot be called from another thread.</p>
1
2016-06-21T13:17:54Z
[ "python", "tkinter", "pyhook", "pythoncom" ]
Multiple natural keys for Django Serializer
37,909,116
<p>Consider I have he following model:</p> <pre><code>class BankLoan(models.Model): amount=models.IntegerField() issued_to_account = models.ForeignKey(Account) issued_by = models.ForeignKey(BankOfficer) issue_date = models.DateField() </code></pre> <p>For Django's serializer, it looked like I could on...
0
2016-06-19T16:00:37Z
37,913,370
<p>I made a mistake when asking this question.</p> <p>Consider I have a BankLoan object</p> <pre><code>class BankLoan(models.Model): amount=models.IntegerField() issued_to_account = models.ForeignKey(Account) issued_by = models.ForeignKey(BankOfficer) issue_date = models.DateField() </code></pre> <p>...
0
2016-06-20T00:54:53Z
[ "python", "django" ]
Inconsistent use of tabs and spaces when adding try and except
37,909,164
<p>I am getting error: Iconsistent use of tabs and spaces error when i try to add try and except error handling. I am trying to make script just skip to next url when one does not exist. Any help is welcome.</p> <pre><code>for url in get_lines(ARGS.urls_file): print("Downloading %s" % url) post_paths = refs_t...
0
2016-06-19T16:06:05Z
37,909,211
<blockquote> <p>write_file(ARGS.output_xml, pretty(root))</p> <p>time.sleep(SEND_TIMEOUT)</p> </blockquote> <p>I think these two lines need to be indented.</p>
0
2016-06-19T16:10:36Z
[ "python" ]
Get distance and velocity from discrete accelerometer data
37,909,207
<p>I know there has been a number of questions and answers on this topic, but none of them has helped me to understand how to approach the problem. So my set-up is: I have accelerometer data (clean from the gravity part), and I'd like to calculate from the given sample velocity and distance. The data is discrete, say, ...
0
2016-06-19T16:10:12Z
37,909,343
<pre><code>a = dv / dt </code></pre> <p>ie</p> <pre><code>a x dt = dv </code></pre> <p>Integration :</p> <pre><code>a[i](t[i+1] - t[i]) = v[i+1] - v[i] </code></pre> <p>ie</p> <pre><code>v[i+1] = a[i](t[i+1] - t[i]) + v[i] </code></pre> <p>After computing v, you can compute x :</p> <pre><code>x[i+1] = v[i](t[i+...
0
2016-06-19T16:22:24Z
[ "python", "scipy", "distance", "accelerometer", "velocity" ]
Matplotlib pyplot lines are not drawn via animation
37,909,245
<p>For some reason I don't get any lines drawn in the code below. The goal is to plot the temperatures I get back over serial to a graph, time on X, temp on Y.</p> <pre><code>$ python -c 'import matplotlib; import matplotlib.pyplot; print(matplotlib.backends.backend)' TkAgg $ python3 -c 'import matplotlib; import matp...
3
2016-06-19T16:13:31Z
37,921,216
<p>Well below does work but far from pretty... t.b.h. I can't care at this point, just glad it works and let leave it at that.</p> <pre><code>import datetime import argparse import serial import matplotlib.pyplot as plt from matplotlib.dates import DateFormatter class SerialReader(object): def __init__(self, po...
0
2016-06-20T11:20:03Z
[ "python", "matplotlib" ]
Merging DataFrames on dates in chronological order in Pandas
37,909,250
<p>I have about 50 DataFrames in a list that have a form like this, where the particular dates included in each DataFrame are not necessarily the same. </p> <pre><code>&gt;&gt;&gt; print(df1) Unnamed: 0 df1_name 0 2004/04/27 2.2700 1 2004/04/28 2.2800 2 ...
1
2016-06-19T16:13:57Z
37,909,555
<p>All you need to do is <code>pd.concat</code> on all your sample dataframes. But you have to set a couple of things. One, set the index of each one to be the column you want to merge on. Ensure that column is a date column. Below is an example of how to do it.</p> <h3>One liner</h3> <pre><code>pd.concat([s.set_...
3
2016-06-19T16:45:31Z
[ "python", "pandas", "dataframe" ]
Send python web app metrics to InfluxDB
37,909,251
<p>For now I have a such monitoring system configured:</p> <pre><code>web_app (via python statsd client) -&gt; statsd -&gt; ... ... -&gt; carbon-relay-ng -&gt; carbon-cache -&gt; whisper </code></pre> <p>And I use <code>Grafana</code> over <code>Graphite</code> as a graphing tool. </p> <p>Due to too poor query p...
1
2016-06-19T16:14:06Z
37,909,789
<p>I would send the data to telegraf using the line protocol.</p> <p>I've used influxdb-python a lot to submit stats directly to InfluxDB. Sending the results locally to telegraf may well be quicker, depending on how quickly and reliably your InfluxDB installation responds - this will block your application if there a...
1
2016-06-19T17:12:34Z
[ "python", "monitoring", "metrics", "influxdb", "statsd" ]
Is my code inefficient or is my task hard?
37,909,295
<p>hope someone can help here?</p> <p>I've written some code to perform a look-up task, and it's taking a long time to do it––far longer than it seems it should. For confidentiality reasons, I can't describe the exact task, but I can give one that's directly analogous.</p> <p>Let's say that I have a database cont...
0
2016-06-19T16:17:48Z
37,909,442
<p>Let's start with some maths... If you have 40,000 entries in your DB and you need to check 500 words (with no special apparent rules), you would need to perform 20,000,000 comparisons. This is NOT a small task.</p> <p>Secondly, and assuming you are comparing strings (words), you are also doing some CASE manipulatio...
0
2016-06-19T16:31:53Z
[ "python", "pandas", "nltk" ]
Is my code inefficient or is my task hard?
37,909,295
<p>hope someone can help here?</p> <p>I've written some code to perform a look-up task, and it's taking a long time to do it––far longer than it seems it should. For confidentiality reasons, I can't describe the exact task, but I can give one that's directly analogous.</p> <p>Let's say that I have a database cont...
0
2016-06-19T16:17:48Z
37,920,978
<p>OK, I got some advice from someone offline that made a big difference here; it might be useful for anyone who comes looking with a similar problem. It seems my biggest bottleneck was in the line: </p> <pre><code>elif i not in unrated and i not in data.values: </code></pre> <p>This is because data.values is an arra...
0
2016-06-20T11:07:56Z
[ "python", "pandas", "nltk" ]
Is my code inefficient or is my task hard?
37,909,295
<p>hope someone can help here?</p> <p>I've written some code to perform a look-up task, and it's taking a long time to do it––far longer than it seems it should. For confidentiality reasons, I can't describe the exact task, but I can give one that's directly analogous.</p> <p>Let's say that I have a database cont...
0
2016-06-19T16:17:48Z
37,921,019
<p>You need to index your keywords so that each word in your text can be looked up in O(1) time. If the dataset can fit in memory (and with 40k words it should be no problem), it can be as simple as this:</p> <pre><code>sentiment_index = dict(zip(colour, values)) rated = set() for i in words: i = i.lower() ra...
2
2016-06-20T11:09:47Z
[ "python", "pandas", "nltk" ]
extracting packet size and passing it as parameter to script
37,909,330
<p>Everytime a packet arrives in the port <code>eth1</code>, I want to extract its packet size and pass this as parameter to my script <code>cap.sh</code>. </p> <p>My approach:</p> <p>I tried <code>tcpdump -nttv -i eth1</code></p> <p>It provided</p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, ...
0
2016-06-19T16:21:27Z
37,909,826
<p>You could rely on <code>tcpdump</code>'s output format and extract the packet length with something like <code>grep -Po '(?&lt;=length )\d+(?=\))'</code>. </p> <p>Here <code>grep</code>'s <code>-P</code> switch turns on the Perl regexes, <code>-o</code> makes grep output only the matching part. Then, <code>(?&lt;=l...
1
2016-06-19T17:16:59Z
[ "python", "shell", "networking", "automation", "tcpdump" ]
401 Unauthorized making REST Call to Azure API App using Bearer token
37,909,332
<p>I created 2 applications in my Azure directory, 1 for my API Server and one for my API client. I am using the Python ADAL Library and can successfully obtain a token using the following code:</p> <pre><code>tenant_id = "abc123-abc123-abc123" context = adal.AuthenticationContext('https://login.microsoftonline.com/' ...
0
2016-06-19T16:21:32Z
37,913,981
<p>For the current release of Azure Python SDK, it support authentication with a service principal. It does not support authentication using an ADAL library yet. Maybe it will in future releases.</p> <p>See <a href="https://azure-sdk-for-python.readthedocs.io/en/latest/resourcemanagement.html#authentication" rel="nofo...
0
2016-06-20T02:44:18Z
[ "python", "azure", "oauth-2.0", "jwt", "adal" ]
401 Unauthorized making REST Call to Azure API App using Bearer token
37,909,332
<p>I created 2 applications in my Azure directory, 1 for my API Server and one for my API client. I am using the Python ADAL Library and can successfully obtain a token using the following code:</p> <pre><code>tenant_id = "abc123-abc123-abc123" context = adal.AuthenticationContext('https://login.microsoftonline.com/' ...
0
2016-06-19T16:21:32Z
38,006,978
<p>@Derek, Could you set your Issue URL on Azure Portal? If I set the wrong Issue URL, I could get the same error with you. It seems that your code is right. <a href="http://i.stack.imgur.com/G8utp.png" rel="nofollow"><img src="http://i.stack.imgur.com/G8utp.png" alt="enter image description here"></a></p> <p>Base on...
0
2016-06-24T06:33:54Z
[ "python", "azure", "oauth-2.0", "jwt", "adal" ]
Thread does not free memory
37,909,344
<p>I have a memory leak in my program.</p> <p>Somewhere in my code I perform a long operation in a thread. In the meantime, I display a "waiting animation". The long operation consumes a lot of memory (~800 Mo). When the operation is finished, I expect the memory to be released, but it is not, and I don't know why. I ...
0
2016-06-19T16:22:28Z
37,925,807
<p>Monitoring memory usage can be tricky. Modern OS may chose to never decrease the memory pages allocated (and counted in tools such as top) for a process. This doesn't mean the application leaks though - it can free memory, and re-allocate this without further increase in memory footprint.</p>
0
2016-06-20T15:03:47Z
[ "python", "multithreading", "pyqt" ]
numpy: setting duplicate values in a row to 0
37,909,364
<p>I am working on a scoring method that scores based on correct answers with three attempts. For each row, if the first attempt is right, the score is 1, if the second attempt is right, the score is 1/2, if the third attempt is right, the score is 1/3.</p> <p>The total score is the sum of the scores for each row div...
1
2016-06-19T16:24:20Z
37,909,581
<p>You could use <code>np.diff</code> -</p> <pre><code>input[:,1:] *=(np.diff(input,axis=1)!=0) </code></pre> <p>So, basically we look for non-zero differentiation along each row and use it to keep or <code>set to 0</code> the 2nd element onwards.</p> <p>Sample run -</p> <pre><code>In [19]: input Out[19]: array([[...
3
2016-06-19T16:48:42Z
[ "python", "arrays", "python-2.7", "numpy", "duplicates" ]
Trying to sort 2d array in python to output a list of highscores
37,909,412
<p>So I am making a game server thing that lets users login and choose a game to play and then adds whatever score they got to a notepad file in the format: (ie blackjack) username, #chips, "chips". Now i want to sort through all the scores in the file to show on my gui but I'm not allowed to use built in functions lik...
0
2016-06-19T16:28:37Z
37,909,500
<p>Your problem is that the return statement is indented too much and sits inside the for loop therefore it only does one pass through before returning.</p> <p>Also, you are comparing the numbers as strings. This will not give the expected order (e.g. "10" is less than "2"). You should use int() to convert them to int...
3
2016-06-19T16:39:36Z
[ "python", "arrays", "sorting" ]
Trying to sort 2d array in python to output a list of highscores
37,909,412
<p>So I am making a game server thing that lets users login and choose a game to play and then adds whatever score they got to a notepad file in the format: (ie blackjack) username, #chips, "chips". Now i want to sort through all the scores in the file to show on my gui but I'm not allowed to use built in functions lik...
0
2016-06-19T16:28:37Z
37,909,603
<p>You can use quicksort to sort the arrays.</p> <pre><code>&gt;&gt;&gt; blackjackList = [['harsh', '4', 'chips'], ['ahmed', '25', 'chips'], ['yousef', '1003', 'chips'], ['krushangi', '200', 'chips'], ['bombberman', '1202', 'chips']] &gt;&gt;&gt; def quicksort(arr): ... if len(arr)==0: return [] ... if len(arr...
0
2016-06-19T16:51:14Z
[ "python", "arrays", "sorting" ]
Create pandas DateTimeIndex from 12-hour-clock format
37,909,435
<p>I'm looking for a way to create a datetimeindex in pandas. My data looks as follows:</p> <pre><code> Date Time AAA 0 06/17/2016 03:00:00 PM 19.13 1 06/17/2016 02:00:00 PM 19.13 2 06/17/2016 01:00:00 PM 19.26 3 06/17/2016 12:00:00 AM 19.28 4 06/17/2016 11:00:00 AM ...
0
2016-06-19T16:31:02Z
37,909,635
<p>you can do it using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow">to_datetime</a> as:</p> <pre><code>df Out[38]: Date Time AAA 0 06/17/2016 03:00:00 PM 19.13 1 06/17/2016 02:00:00 PM 19.13 2 06/17/2016 01:00:00 PM 19.26 3 06/17...
2
2016-06-19T16:55:20Z
[ "python", "pandas" ]
Create pandas DateTimeIndex from 12-hour-clock format
37,909,435
<p>I'm looking for a way to create a datetimeindex in pandas. My data looks as follows:</p> <pre><code> Date Time AAA 0 06/17/2016 03:00:00 PM 19.13 1 06/17/2016 02:00:00 PM 19.13 2 06/17/2016 01:00:00 PM 19.26 3 06/17/2016 12:00:00 AM 19.28 4 06/17/2016 11:00:00 AM ...
0
2016-06-19T16:31:02Z
37,909,770
<p>Using date objects as opposed to parsing strings</p> <pre><code>df = pd.DataFrame([ ['06/17/2016', '03:00:00 PM', 19.13], ['06/17/2016', '02:00:00 PM', 19.13], ['06/17/2016', '01:00:00 PM', 19.26], ['06/17/2016', '12:00:00 AM', 19.28], ['06/17/2016', '11:00:00 AM', 19.28], ...
2
2016-06-19T17:10:44Z
[ "python", "pandas" ]
Non-periodic repetition of task in Django using celery
37,909,472
<p>I need to run a task "CreateNotifications" at random intervals of time. Here is what I was trying to do in the settings for CELERY.</p> <pre><code>t = random.randint(45, 85) ## print "time = ", t ## celery app configuration app.conf.CELERYBEAT_SCHEDULE = { # Executes at every 't' interval, where t is random ...
0
2016-06-19T16:35:57Z
38,060,982
<p>You really shouldn't put an endless loop in a Celery task. If you need a dedicated process it would be better to run it on it's own rather than through Celery.</p> <p>You could reschedule a new task in the future whenever your task runs. Something like the following:</p> <pre><code>@app.task def create_notificatio...
1
2016-06-27T18:39:12Z
[ "python", "django", "celery", "celery-task" ]
Tkinter text entry with pyHook hangs GUI window
37,909,484
<p>I have a Tkinter GUI application that I need to enter text in. I cannot assume that the application will have focus, so I implemented pyHook, keylogger-style.</p> <p>When the GUI window does not have focus, text entry works just fine and the StringVar updates correctly. When the GUI window <em>does</em> have focus ...
0
2016-06-19T16:36:49Z
37,918,874
<p>I modified the source code given in the question (and the other one) so that the pyHook related callback function sends keyboard event related data to a queue. The way the GUI object is notified about the event may look needlessly complicated. Trying to call <code>root.event_generate</code> in <code>keypressed</code...
1
2016-06-20T09:24:08Z
[ "python", "tkinter", "pyhook", "pythoncom" ]
why my python code doesn't represent some of characters?
37,909,570
<pre><code>for i in xrange(256): print str(i)+' : '+chr(i) </code></pre> <p>when this code run <a href="http://i.stack.imgur.com/rG00T.png" rel="nofollow">some of characters not shown and instead them show squares</a></p> <p>I've been trying but I could not fix the problem even when I run this code :</p> <pre>...
-2
2016-06-19T16:47:35Z
37,909,613
<p>well you are printing out ascii characters. the numbers you print out are not alphabetical characters in the first place, cf <a href="https://simple.wikipedia.org/wiki/ASCII" rel="nofollow">here</a></p>
1
2016-06-19T16:52:23Z
[ "python" ]
why my python code doesn't represent some of characters?
37,909,570
<pre><code>for i in xrange(256): print str(i)+' : '+chr(i) </code></pre> <p>when this code run <a href="http://i.stack.imgur.com/rG00T.png" rel="nofollow">some of characters not shown and instead them show squares</a></p> <p>I've been trying but I could not fix the problem even when I run this code :</p> <pre>...
-2
2016-06-19T16:47:35Z
37,910,284
<p>You can't print all ascii characters.Here you can find all the ascii characters.</p> <pre><code>print ' '.join([chr(i) for i in range(128)]) </code></pre> <p>Here is the result of this</p> <pre><code>'\x00 \x01 \x02 \x03 \x04 \x05 \x06 \x07 \x08 \t \n \x0b \x0c \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17...
0
2016-06-19T18:08:57Z
[ "python" ]
Create balanced tennis rounds
37,909,653
<p>We are a group of 20 people and we like to go play 2 vs 2 tennis matches. Each of us plays one match each round and we do 5 rounds in total, so everyone plays 5 matches. Matches have two restrictions: </p> <ul> <li>Everyone has a different level (from 1 to 5), so the matches must be balanced: two players with leve...
0
2016-06-19T16:57:08Z
37,920,835
<p>You could use a dummy objective or even try to minimize the max of the difference in levels. </p> <p>My MIP model is not completely trivial, but it solves quite fast (about a second or so using a commercial solver).</p> <p><a href="http://i.stack.imgur.com/IjbDz.gif" rel="nofollow"><img src="http://i.stack.imgur.c...
1
2016-06-20T11:01:20Z
[ "python", "schedule", "linear-programming" ]
Pillow cannot be installed via pip
37,909,666
<p>When I try to run pip install pillow, I get:</p> <pre><code>ValueError: --enable-jpeg requested but jpeg not found, aborting. </code></pre> <p>I installed lib-jpeg (via brew install libjpeg and brew install jpeg), and I also installed pillow (via brew install pillow) in my virtual environment. But, pip install pil...
0
2016-06-19T16:58:16Z
37,909,885
<p>Figured this out.</p> <p>I have to install anaconda via: </p> <p>wget <a href="http://09c8d0b2229f813c1b93-c95ac804525aac4b6dba79b00b39d1d3.r79.cf1.rackcdn.com/Anaconda-2.1.0-Linux-x86_64.sh" rel="nofollow">http://09c8d0b2229f813c1b93-c95ac804525aac4b6dba79b00b39d1d3.r79.cf1.rackcdn.com/Anaconda-2.1.0-Linux-x86_64...
1
2016-06-19T17:24:11Z
[ "python", "linux", "jpeg", "pillow", "libjpeg" ]
Getting key and value of attributes in xml tag
37,909,692
<p>So If I had this following tag:</p> <pre><code>&lt;ana lex="ун" morph="ың" gr="NUM,poss.2sg" trans="десять" /&gt; </code></pre> <p>I want to extract not just the value but more specifically the names of the attributes. I have already tried using the names function like so (where ana is the above tag):</p...
0
2016-06-19T17:01:04Z
37,911,870
<p>You can just call <code>.items</code> to get the name and value:</p> <pre><code>In [3]: import lxml.etree as et In [4]: x = et.fromstring("""&lt;ana lex="ун" morph="ың" gr="NUM,poss.2sg" trans="десять" /&gt;""") In [5]: x.attrib Out[5]: {'trans': 'десять', 'lex': 'ун', 'gr': 'NUM,poss.2sg', 'mo...
1
2016-06-19T21:08:09Z
[ "python", "xml", "xpath", "tags", "lxml" ]
Getting a 401 error when using Bing API search
37,909,709
<p>I went on Microsoft's website and am trying to implement their code they have posted on line which is this: </p> <pre><code>import http.client, urllib.request, urllib.parse, urllib.error, base64 headers = { # Request headers 'xxxxxxxxxx': '{subscription key}', } params = urllib.parse.urlencode({ # Req...
1
2016-06-19T17:03:51Z
37,909,813
<p>According to this documentation <a href="https://msdn.microsoft.com/en-us/library/dn760783.aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/dn760783.aspx</a> the request header <code>Ocp-Apim-Subscription-Key</code> is required. Include this where you are defining your headers like so:</p> <pre><code>h...
0
2016-06-19T17:15:03Z
[ "python", "bing-api" ]
Getting a 401 error when using Bing API search
37,909,709
<p>I went on Microsoft's website and am trying to implement their code they have posted on line which is this: </p> <pre><code>import http.client, urllib.request, urllib.parse, urllib.error, base64 headers = { # Request headers 'xxxxxxxxxx': '{subscription key}', } params = urllib.parse.urlencode({ # Req...
1
2016-06-19T17:03:51Z
38,200,364
<p>Does your subscription key work on their testing console - <a href="https://bingapis.portal.azure-api.net/docs/services/56b43f72cf5ff8098cef380a/operations/56f02400dbe2d91900c68553/console" rel="nofollow">https://bingapis.portal.azure-api.net/docs/services/56b43f72cf5ff8098cef380a/operations/56f02400dbe2d91900c68553...
0
2016-07-05T09:54:00Z
[ "python", "bing-api" ]
Understanding function arguments in Python
37,909,719
<p>I'm trying to understand the following about dealing with functions and their arguments:</p> <pre><code>def print_my_arg(func, *args, **kwargs): func(*args, **kwargs) if 'my_arg' in kwargs: print(' my_arg = {}'.format(kwargs['my_arg'])) def foo(call_no, my_arg='Default Value'): print('call_no...
1
2016-06-19T17:05:05Z
37,910,898
<blockquote> <p>Isn't there a uniform way to access parameters by name (and not by position), which doesn't depend on the way the function was invoked?</p> </blockquote> <p>Yes by <code>inspect</code>ing the <a href="https://docs.python.org/3/library/inspect.html?highlight=signature#introspecting-callables-with-th...
3
2016-06-19T19:14:59Z
[ "python", "python-decorators", "args", "kwargs" ]
Pygame not quitting properly
37,909,774
<p>Lately my game did not stop when I called my routine to exit.</p> <p>In various tests I could narrow the error down to when <code>pygame.quit()</code> is called. At this moment the program freezes. I wrote a short program to verify that it was not anything funky in my code:</p> <pre><code>import pygame pygame.init...
2
2016-06-19T17:11:15Z
38,487,509
<p>Are you running this in idle? If so, idle generally requires the shell window to close before the pygame window will close. Try running the program directly through terminal if you haven't already.</p>
0
2016-07-20T17:52:37Z
[ "python", "pygame", "exit" ]
How to convert a list of dictionaries to JSON in Python / Django?
37,909,800
<p>I searched on Google and found an answer but it's not working for me. I have to send a list as <code>JsonResponse</code> in Django, similar to this:</p> <pre><code>list_to_json =[{"title": "hello there", "link": "www.domain.com", "date": ...}, {},{},{},...] </code></...
2
2016-06-19T17:13:54Z
37,909,858
<pre><code>return JsonResponse(list_to_json, safe=False) </code></pre> <p>Take a look at the <a href="https://docs.djangoproject.com/en/1.9/ref/request-response/#jsonresponse-objects" rel="nofollow">documentation</a>: </p> <blockquote> <p>The safe boolean parameter defaults to True. If it’s set to False, any ...
3
2016-06-19T17:21:24Z
[ "python", "json", "django" ]
How to convert a list of dictionaries to JSON in Python / Django?
37,909,800
<p>I searched on Google and found an answer but it's not working for me. I have to send a list as <code>JsonResponse</code> in Django, similar to this:</p> <pre><code>list_to_json =[{"title": "hello there", "link": "www.domain.com", "date": ...}, {},{},{},...] </code></...
2
2016-06-19T17:13:54Z
37,909,876
<p>This is not a valid dictionary: </p> <pre><code>{"title": , "link" : , "date": } </code></pre> <p>because the values are missing. If you try adding the missing values instead, it works fine:</p> <pre><code>&gt;&gt;&gt; json.dumps([{"title": "hello there", "link": "www.domain.com", "date": 2016}, {}]) '[{"link"...
0
2016-06-19T17:23:21Z
[ "python", "json", "django" ]
How to convert a list of dictionaries to JSON in Python / Django?
37,909,800
<p>I searched on Google and found an answer but it's not working for me. I have to send a list as <code>JsonResponse</code> in Django, similar to this:</p> <pre><code>list_to_json =[{"title": "hello there", "link": "www.domain.com", "date": ...}, {},{},{},...] </code></...
2
2016-06-19T17:13:54Z
37,909,884
<p><code>list_to_json=[{"title": , "link" : , "date": },{}]</code> is a syntax error. You are missing values for your keys in the first dictionary. If they are suppose to be empty, try using the empty string:</p> <p><code>list_to_json=[{"title": "", "link" : "" , "date": ""},{}]</code></p>
-1
2016-06-19T17:24:10Z
[ "python", "json", "django" ]
xPath: Select one of multiple Following elements, if it exists (OR)
37,909,859
<p>Using xPath for Selenium, I want to look for an element that follows a conditional parent node. However, I want it to look for <em>multiple</em> possible following nodes.</p> <p>Is there a way to select the element following the conditional node, as either <code>span</code> or <code>p</code>, <strong><em>if</em></s...
0
2016-06-19T17:21:31Z
37,909,992
<p>Try following <code>XPath</code> and let me know if it still not correct:</p> <pre><code>driver.find_element_by_xpath('//b[text()="myConditionString"]/span[text()="Find me!"] | //b[text()="myConditionString"]/p[text()="Find me!"]') </code></pre>
1
2016-06-19T17:36:02Z
[ "python", "xml", "selenium", "xpath" ]
Removing first column in a matrix in python having double digit numbers
37,909,896
<p>I have the following matrix:</p> <pre><code> Pos A C G U 1 0 0 1 0 2 0.75 0 0.25 0 3 0 0 0 1 4 0 1 0 0 5 1 0 0 0 6 1 0 0 0...
0
2016-06-19T17:25:07Z
37,909,944
<p>The problem is the format of your matrix. It seems like you have a list of strings, instead of an actual matrix. We can see that the last digit in 10,11,12,13,14 is still there. What you should do is to initially run</p> <pre><code>actualMatrix = [line.split() for line in matrix] </code></pre> <p>The you could do ...
2
2016-06-19T17:31:08Z
[ "python", "matrix", "rows" ]
Removing first column in a matrix in python having double digit numbers
37,909,896
<p>I have the following matrix:</p> <pre><code> Pos A C G U 1 0 0 1 0 2 0.75 0 0.25 0 3 0 0 0 1 4 0 1 0 0 5 1 0 0 0 6 1 0 0 0...
0
2016-06-19T17:25:07Z
37,910,027
<p>This happens because it seems that all your data is <code>str</code>s, thus <code>line[1:]</code> gives you 'line without the first character'. If you use <code>str</code>s split method, it'll give you a list of parts separated by whitespace, so</p> <pre><code> vals = [line[1:] for line in [row.split() for row in m...
1
2016-06-19T17:39:57Z
[ "python", "matrix", "rows" ]
Regex to split line data into year / temperature readings
37,910,033
<p>I'm writing a Python script to parse some data files I have into geojson data.</p> <p>Right now, I have a number of lines that each start with a year and then have 12 temperature readings (one for each month) for example:</p> <pre><code>1983 5.2 -0.4 5.7 9.8 13.7 18.1 22.1 19.8 15.1 10.2 4.8 1.1 ...
1
2016-06-19T17:40:16Z
37,910,132
<p>I suggest using .* for matching the remainder of the line. Also, \d{4} is the simplest way to match four digits:</p> <pre><code>import re # Regex: (four digits) whitespace (the rest of the line) reYear = re.compile("(\d{4})\s+(.*)") line = "1983 5.2 -0.4 5.7 9.8 13.7 18.1 22.1 19.8 15.1 10.2 4.8 1...
2
2016-06-19T17:50:45Z
[ "python", "regex" ]
pandas groupby resample unexpected result
37,910,057
<h3>Setup</h3> <pre><code>import pandas as pd df = pd.DataFrame({'grp': [1, 2] * 2, 'value': range(4)}, index=pd.Index(pd.date_range('2016-03-01', periods=7)[::2], name='Date') ).sort_values('grp') </code></pre> <p>I wanted to group by <code>'grp'</code> and resample my index daily...
1
2016-06-19T17:43:24Z
37,910,676
<p>It looks like <a href="https://github.com/pydata/pandas/issues/12923" rel="nofollow">one of the issues</a> due to the changes in <a href="http://pandas.pydata.org/pandas-docs/version/0.18.1/whatsnew.html#resample-api" rel="nofollow">resample API</a> in version 0.18.0.</p> <p>It works as expected in 0.18.1:</p> <pr...
2
2016-06-19T18:51:13Z
[ "python", "pandas" ]
ChromeDriver does not open a window yet test is still successful
37,910,058
<p>I'm trying to run a webdriver test in python on a mac (El Capitan 10.11.5). I was successful running the same test with FirefoxDriver (using FF 46, before marionette). When I try doing the same using chromedriver 2.22 or 2.20, I get a strange result - the test runs and passes, but I see no window doing it.</p> <p>I...
1
2016-06-19T17:43:37Z
37,910,164
<p>The browser is actually opened but <em>it is not brought into front/focus</em>.</p> <p>There are <a href="http://stackoverflow.com/questions/10649637/make-sure-that-browser-opened-by-webdriver-is-always-in-focus">several workarounds</a>, like executing <code>window.focus()</code>, but I prefer firing up an <code>al...
1
2016-06-19T17:54:18Z
[ "python", "selenium", "selenium-chromedriver" ]
Heroku SQLAlchemy database does not exist
37,910,066
<p>I'm running a python 3.5 worker on heroku.</p> <p><code>self.engine = create_engine(os.environ.get("DATABASE_URL"))</code></p> <p>My code works on local, passes Travis CI, but gets an error on heroku - <code>OperationalError: (psycopg2.OperationalError) FATAL: database "easnjeezqhcycd" does not exist</code>. </p>...
0
2016-06-19T17:44:21Z
37,910,999
<p>The error was actually caused by </p> <p><code>if not database_exists(self.engine.url): logging.info("Database not found") create_database(self.engine.url) logging.info("Database created")</code></p> <p>So I just created config variable ON_HEROKU on Heroku and wrapped it in if s...
0
2016-06-19T19:26:05Z
[ "python", "postgresql", "heroku", "sqlalchemy", "heroku-postgres" ]
Ansible playbook script failure
37,910,080
<p>Getting error while running below playbook. The python script is on my master and I want it to run on two slaves. No idea what's wrong.</p> <pre><code>luckee@zarvis:~/playbooks$ ansible-playbook runscript.yml PLAY [droplets] **************************************************************** TASK [setup] **********...
0
2016-06-19T17:45:35Z
37,910,789
<p>I think first you need to transfer the script to the remote hosts and then run it:</p> <pre><code>--- - hosts: droplets remote_user: root tasks: - name: copy the script to the remote host copy: src: userfind.py dest: /tmp/userfind.py mode: 0777 - name: Run python script ...
0
2016-06-19T19:03:11Z
[ "python", "ansible" ]
Ansible playbook script failure
37,910,080
<p>Getting error while running below playbook. The python script is on my master and I want it to run on two slaves. No idea what's wrong.</p> <pre><code>luckee@zarvis:~/playbooks$ ansible-playbook runscript.yml PLAY [droplets] **************************************************************** TASK [setup] **********...
0
2016-06-19T17:45:35Z
37,912,367
<p>You try to execute a local file on a remote host.</p> <p>If you meant to run it remotely you first need to transfer it or use the <a href="http://docs.ansible.com/ansible/script_module.html" rel="nofollow">script module</a>. It first transfers the file to the remote hosts and then executes it.</p> <pre><code>- nam...
1
2016-06-19T22:15:23Z
[ "python", "ansible" ]
How to extract ip in web scanning
37,910,099
<p>While performing a simple task of ip-address extraction, I found that the program is doing well. But in the complete program for web crawling it fail to survive and gives uneven results.</p> <p>This is my code snippet for ip-address:</p> <pre><code> #!/usr/bin/python3 import os import re def get_...
0
2016-06-19T17:47:33Z
37,910,469
<p>Sorry I don't have enough reputation to add comments, so I'll post my suggestions here.</p> <p>I think the problem is from <code>process = os.popen(command)</code> in <code>def get_ip_address(url)</code>. You can print <code>command</code> to see if it's valid.</p> <p>Besides the problem, just a few suggestions:</...
0
2016-06-19T18:27:34Z
[ "python", "web-crawler", "python-os" ]
How to extract ip in web scanning
37,910,099
<p>While performing a simple task of ip-address extraction, I found that the program is doing well. But in the complete program for web crawling it fail to survive and gives uneven results.</p> <p>This is my code snippet for ip-address:</p> <pre><code> #!/usr/bin/python3 import os import re def get_...
0
2016-06-19T17:47:33Z
37,910,792
<p>I second Joe Lin's suggestion to <em>not</em> use wildcards in your import statements. It pollutes your namespace greatly and may yield bizarre behavior. </p> <p>Python is "batteries included" so you probably should leverage the <code>requests</code> and <code>urllib3</code> packages for HTTP requests, use <code>su...
0
2016-06-19T19:03:43Z
[ "python", "web-crawler", "python-os" ]
change levels in pygame
37,910,115
<p>I'm trying to switch levels, but I get this Traceback error.</p> <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last): File "C:\Users\Recovery 1\Desktop\Comp sci performance task\compscipretask (1) (1).py", line 228, in &lt;module&gt; walls,endRect,wallRect,wall = load_level(cu...
0
2016-06-19T17:49:02Z
37,912,193
<p>The problem is, as the error message indicates, that the index used with the <code>levels</code> list is out of range. It can only be <code>0</code> or <code>1</code>. The problem appears to be because in the main <code>while game</code> loop you increment <code>currentLevel</code> by one without checking its value ...
0
2016-06-19T21:49:43Z
[ "python", "pygame" ]
Adding tooltip to multi line plot using mpld3
37,910,191
<p>I'm a complete noob to web development. I was working on a <code>flask</code> app which plots multiline charts from pandas dataframe using matplotlib, but I wish to add tooltip to the data points via <code>mpld3</code>. <code>mpld3</code>tooltip <a href="https://mpld3.github.io/examples/html_tooltips.html" rel="nofo...
0
2016-06-19T17:57:32Z
39,251,770
<p>It doesn't appear as if mpld3 offers a line plot tooltip, so you have to use the point tooltip and adapt it for line plots. The important observation here is that the point tooltip relies upon matplotlib markers (see discussion <a href="https://github.com/mpld3/mpld3/issues/252" rel="nofollow">here</a>). Obviously...
0
2016-08-31T14:01:17Z
[ "python", "matplotlib", "plot", "mpld3" ]
Temperature Converter GUI UnboundLocalError/AttributeError issues
37,910,292
<p>I made a relatively simple temperature application in Python using Tkinter.</p> <p>I managed to get most parts working, but the part that actually deals with getting the answer is giving me trouble. I think it has to do with the way I decide how to convert from "x temperature unit" to "y temperature unit", by using...
0
2016-06-19T18:09:57Z
37,910,627
<p>You're getting the error because you forgot to use the <code>get()</code> method of the <code>self.from_radio</code> object of type <code>tkinter.StringVar</code> to retrieve its current value. Because of that none of the <code>if</code> statements are true, and the local variable <code>converted_temp</code> is unde...
0
2016-06-19T18:43:58Z
[ "python", "python-3.x", "tkinter", "local-variables" ]
Temperature Converter GUI UnboundLocalError/AttributeError issues
37,910,292
<p>I made a relatively simple temperature application in Python using Tkinter.</p> <p>I managed to get most parts working, but the part that actually deals with getting the answer is giving me trouble. I think it has to do with the way I decide how to convert from "x temperature unit" to "y temperature unit", by using...
0
2016-06-19T18:09:57Z
37,910,666
<p>The code could be re-factored - there's a lot of repetition - but I'll just mention the two things that are actually causing errors:</p> <ol> <li>The <code>.get()</code> method of <code>self.from_radio</code> is never called.</li> <li>Missing <code>self</code>s before calls to class methods such as <code>f_convert(...
0
2016-06-19T18:50:02Z
[ "python", "python-3.x", "tkinter", "local-variables" ]
Does Python implicitly return None in modules?
37,910,294
<p>I was playing around with Python bytecode with the <a href="https://docs.python.org/3/library/dis.html#module-dis" rel="nofollow"><strong><code>dis</code></strong></a> module when I noticed something about bytecode generated for modules. Given a small test module named <code>mod.py</code>:</p> <pre><code>if __name_...
0
2016-06-19T18:10:22Z
37,910,295
<p>Yes, in a nutshell, modules do implicitly return <code>None</code> in order for the big evaluation loop inside <strong><a href="https://github.com/python/cpython/blob/master/Python/ceval.c#L1925" rel="nofollow"><code>ceval.c</code></a></strong> to be able detect when to the current frame is finished and terminate. <...
6
2016-06-19T18:10:22Z
[ "python", "python-2.7", "python-3.x", "module", "bytecode" ]
How can I capture raw IP packets under Ubuntu?
37,910,377
<p>I want to use Python to capture all the IP packets on an Ubuntu’s network. By using the below code, I’ve got all the packet with the Ethernet header. How can I get rid of the Ethernet header and directly get only the IP packets?</p> <pre><code>s = socket.socket( socket.AF_PACKET , socket.SOCK_RAW , socket.ntohs...
0
2016-06-19T18:18:36Z
37,911,467
<p><code>socket (AF_INET, SOCK_RAW, IPPROTO_RAW)</code> will get you an IP Layer raw socket</p> <p><code>socket (PF_PACKET, SOCK_RAW, htons (ETH_P_ALL))</code> will get you a layer 2 raw socket`</p> <p>There are examples (in C) <a href="http://www.pdbuchan.com/rawsock/rawsock.html" rel="nofollow">here</a>.</p>
0
2016-06-19T20:21:17Z
[ "python", "linux", "ubuntu", "network-programming" ]
How can I capture raw IP packets under Ubuntu?
37,910,377
<p>I want to use Python to capture all the IP packets on an Ubuntu’s network. By using the below code, I’ve got all the packet with the Ethernet header. How can I get rid of the Ethernet header and directly get only the IP packets?</p> <pre><code>s = socket.socket( socket.AF_PACKET , socket.SOCK_RAW , socket.ntohs...
0
2016-06-19T18:18:36Z
37,911,884
<p>I would suggest you have a look at <code>scapy</code>, a tool that enables the user to send, sniff, dissect and forge network packets. the <a href="http://www.secdev.org/projects/scapy/doc/usage.html#sniffing" rel="nofollow">sniffing</a> paragraph is a probably what you're looking for. Here's an example where I capt...
1
2016-06-19T21:10:05Z
[ "python", "linux", "ubuntu", "network-programming" ]
How can I capture raw IP packets under Ubuntu?
37,910,377
<p>I want to use Python to capture all the IP packets on an Ubuntu’s network. By using the below code, I’ve got all the packet with the Ethernet header. How can I get rid of the Ethernet header and directly get only the IP packets?</p> <pre><code>s = socket.socket( socket.AF_PACKET , socket.SOCK_RAW , socket.ntohs...
0
2016-06-19T18:18:36Z
37,922,233
<p>I've coded a custom sniffer some weeks ago using python with the 'pcapy' extension, here is a usefull link that help me a lot, you can take this code as an example and get rid of other network layers you don't need.</p> <p><a href="http://www.binarytides.com/code-a-packet-sniffer-in-python-with-pcapy-extension/" re...
0
2016-06-20T12:08:35Z
[ "python", "linux", "ubuntu", "network-programming" ]
How to shorten long XPath expressions with many OR alternatives?
37,910,443
<p>I am working to get Selenium to go through a large number of alternative conditional XPaths, looking for elements that <em>may match</em> – and pass that on to the object <code>elmnt</code>.</p> <p>Currently, using the <code>OR</code> operator (<code>|</code>), the code quickly gets very repetitive and exhaustive...
3
2016-06-19T18:25:25Z
37,911,265
<p>I would use this shortened XPath (leveraging the <code>self::</code> axis as recommended by <a href="http://stackoverflow.com/questions/37910443/xpath-is-it-possible-to-shorten-long-expressions-with-many-or-alternatives/37911265#comment63272915_37910443">@alecxe in a comment</a>):</p> <pre><code> "//*[self::h1 or ...
2
2016-06-19T19:58:18Z
[ "python", "html", "xml", "selenium", "xpath" ]
Failure to display positive day Candlesticks using matplotlib.finance.candlestick2_ochl
37,910,447
<p>I have a python dataframe <code>df</code> containing Date, Open, High,Low, Close, and volume values.</p> <p>I am attempting to Candlestick chart a stock. For some reason, I can't seem to get <code>matplotlib.finance.candlestick2_ochl()</code> to corectly display days where the stock price closed <code>self.df['clos...
0
2016-06-19T18:25:41Z
38,684,513
<h2>a bug lies here</h2> <p>I'm using Matplotlib 1.5.1, there's a finance.py file in matplotlib directory, line 1059-1067. the original code is:</p> <pre><code> candlestick2_ohlc(ax, opens, highs, closes, lows, width=width, colorup=colorup, colordown=colordown, alpha=alpha) def ...
-3
2016-07-31T13:36:38Z
[ "python", "pandas", "matplotlib", "finance", "candlestick-chart" ]
Failure to display positive day Candlesticks using matplotlib.finance.candlestick2_ochl
37,910,447
<p>I have a python dataframe <code>df</code> containing Date, Open, High,Low, Close, and volume values.</p> <p>I am attempting to Candlestick chart a stock. For some reason, I can't seem to get <code>matplotlib.finance.candlestick2_ochl()</code> to corectly display days where the stock price closed <code>self.df['clos...
0
2016-06-19T18:25:41Z
38,685,987
<p>Please see this code that produces rightly colored candlesticks:</p> <pre><code>import pandas as pd import datetime import time import pandas as pd import matplotlib.pyplot as plt from matplotlib.finance import candlestick2_ochl import matplotlib.ticker as mticker import matplotlib.dates as mdates class MyStock: ...
1
2016-07-31T16:16:18Z
[ "python", "pandas", "matplotlib", "finance", "candlestick-chart" ]
Why aren't "raise" and "del" functions in Python?
37,910,465
<p>One of the basic changes from Python 2 to Python 3 was making <code>print</code> a function - which, to me, makes perfect sense given its structure. Why aren't the <code>raise</code> and <code>del</code> statements also functions? Especially in the case of <code>raise</code> it seems like it is taking an argument ...
3
2016-06-19T18:27:28Z
37,910,596
<p><a href="https://www.python.org/dev/peps/pep-3105/" rel="nofollow">https://www.python.org/dev/peps/pep-3105/</a> has a list of rationals why <code>print</code> is made function. Of the five reasons, (IMO) the most relevant one is:</p> <blockquote> <p>print is the only application-level functionality that has a st...
2
2016-06-19T18:41:32Z
[ "python", "function", "python-3.x", "design", "structure" ]
Why aren't "raise" and "del" functions in Python?
37,910,465
<p>One of the basic changes from Python 2 to Python 3 was making <code>print</code> a function - which, to me, makes perfect sense given its structure. Why aren't the <code>raise</code> and <code>del</code> statements also functions? Especially in the case of <code>raise</code> it seems like it is taking an argument ...
3
2016-06-19T18:27:28Z
37,910,616
<p><code>raise</code> and <code>del</code> are definitely distinct from functions, each for different reasons:</p> <ul> <li><p><code>raise</code> exits the current flow of execution; the normal flow of byte-code interpretation is interrupted and the stack is unwound until the next exception handler is found. Functions...
5
2016-06-19T18:42:59Z
[ "python", "function", "python-3.x", "design", "structure" ]
How to use for loop variable inside if block
37,910,472
<pre><code>for instance in GratuityPayment.objects.all(): print instance.date_paid if (employment_number == instance.employment_number): raise forms.ValidationError('This Employment Mumber was paid on ' + str(instance.date_paid) + '. You cannot proceed with this retirement') </code></pre> <...
0
2016-06-19T18:27:50Z
37,910,512
<p>If you want to not apply the check when <code>date_paid</code> is <code>None</code>:</p> <pre><code>for instance in GratuityPayment.objects.all(): if instance.date_paid is not None and employment_number == instance.employment_number: raise forms.ValidationError('This Employment Mumber was paid on ' + st...
1
2016-06-19T18:33:17Z
[ "python", "django", "python-2.7" ]
How to use for loop variable inside if block
37,910,472
<pre><code>for instance in GratuityPayment.objects.all(): print instance.date_paid if (employment_number == instance.employment_number): raise forms.ValidationError('This Employment Mumber was paid on ' + str(instance.date_paid) + '. You cannot proceed with this retirement') </code></pre> <...
0
2016-06-19T18:27:50Z
37,910,771
<p>It is actually working. Its Given None because that particular Table row did have None in the table.</p> <p>I just populated the date_paid and it returned the date instead of None.</p>
0
2016-06-19T19:01:32Z
[ "python", "django", "python-2.7" ]
Stopword removal clears word not in stopword list
37,910,537
<p>I'm interested in mining the scientific literature especially PubMed. I wanted to determine the word modifiers just to the left and right of a keyword that I chose. My plan was to (1) query my database on Hearing and Hearing Aids for the word "AID". (2) Then, I removed the punctuation, double spaces etc. from t...
-2
2016-06-19T18:35:25Z
37,913,801
<p>I don't exactly get your algorithm, but your list of stop words needs to be a <code>list</code> (even better a <code>set</code>), not a string:</p> <pre><code>my_stopwords = set(['A','ABLE','ABOUT','ABOVE','ACCORDING',]) </code></pre> <p>Otherwise you are just doing substring matches instead of exact string matche...
0
2016-06-20T02:15:20Z
[ "python", "split" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,910,698
<p>I suppose you mean "add 18 to it" ;)</p> <p>Anyway, since you tagged your question with "python"</p> <pre><code>import re s = "1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18" re.findall("length (\d+)",s) </co...
0
2016-06-19T18:54:13Z
[ "python", "regex", "shell", "awk", "grep" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,911,158
<p>Use the following snippet in <code>Python</code>:</p> <pre><code>import re regex = r'length (\d+)' # search for length, a space and digits (capture these) string = "1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length...
0
2016-06-19T19:43:50Z
[ "python", "regex", "shell", "awk", "grep" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,912,855
<pre><code>$ awk '{print $17+16}' file 62 </code></pre> <p>If that's not what you wanted then edit your question to clarify your requirements and provide more truly representative sample input and expected output.</p>
0
2016-06-19T23:25:13Z
[ "python", "regex", "shell", "awk", "grep" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,912,894
<p>Without knowing the rules of the input format, it's impossible to give you a good answer. Given what you showed us, </p> <pre><code>awk '{ x = 16 + $17; print x }' </code></pre> <p>will print 62. If you want it to print 64, add 18 instead. ;-) </p>
0
2016-06-19T23:30:52Z
[ "python", "regex", "shell", "awk", "grep" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,917,496
<p>I believe you want to add 46 and 18. </p> <p>For a single line you can use following command</p> <pre><code>grep -o "length [0-9]*" file | cut -d " " -f2 | xargs | awk '{print $1 + $2}' </code></pre> <p>On execution with your example it gives the result 64. </p> <p>Please note that you will have to use it in l...
-1
2016-06-20T08:13:27Z
[ "python", "regex", "shell", "awk", "grep" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,917,992
<p>If you split the input on <code>length</code> in Awk, the first numeric token in each field can be accessed as if it was tne entire field in arithmetic operations.</p> <pre><code>awk -F length 'NF==3{ print $2+16 }' </code></pre> <p>As you would expect, the second value is available in <code>$3</code> if you shoul...
0
2016-06-20T08:41:02Z
[ "python", "regex", "shell", "awk", "grep" ]
grep a specific value when the matching criteria happens twice in the line
37,910,557
<p>There are two lengths in the following line. I want to extract the value 46 and add 16 to it. </p> <pre><code>1466352405.455975 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto UDP (17), length 46) 192.168.52.53.32769 &gt; 192.168.52.54.9600: UDP, length 18 </code></pre> <p>I tried grep <code>'\slength' | cu...
0
2016-06-19T18:37:06Z
37,918,879
<p>Try this command to get the second length:</p> <p><code> grep -oP 'length \d+.+length \d+' | grep -oP '\d+$' </code></p> <p>For the given sample, it obtains 18 correctly, adding 16 to the result is not a problem for you.</p>
0
2016-06-20T09:24:21Z
[ "python", "regex", "shell", "awk", "grep" ]
double include url schema in django
37,910,615
<p>Is it acceptable to use two includes for the same base url routing schema?</p> <p>e.g. - I have allauth installed which uses <code>r'^accounts/', include('allauth.urls')</code></p> <p>and I want to extend this further with my own app, which extends the <code>allauth</code> urls even further. </p> <p>An example of...
0
2016-06-19T18:42:48Z
37,910,649
<p>Yes, that is perfectly fine.</p> <p>Django will look for a matching url in the first one, and if it doesn't find it, it will move on to the next one.</p>
2
2016-06-19T18:46:46Z
[ "python", "django", "python-3.x", "django-views", "django-urls" ]
How to hide taskbar icon of a PyQt4 Python application?
37,910,617
<p>I want to create a windows desktop widget. I will create a custom UI for the widget in Qt Designer and add functionality using Python. But, I do not want the application to have an icon on the taskbar at all. How should I modify my code and make my application (and its instances or other similar applications) to hav...
4
2016-06-19T18:43:12Z
37,915,096
<p>I think <a href="http://stackoverflow.com/questions/1551605/how-to-set-applications-taskbar-icon-in-windows-7/1552105#1552105">this</a> may be the problem: </p> <blockquote> <p>In Windows 7, the taskbar is not for "Application Windows" per se, it's for "Application User Models". For example, if you have several...
0
2016-06-20T05:23:56Z
[ "python", "pyqt4", "qt-designer" ]
How to hide taskbar icon of a PyQt4 Python application?
37,910,617
<p>I want to create a windows desktop widget. I will create a custom UI for the widget in Qt Designer and add functionality using Python. But, I do not want the application to have an icon on the taskbar at all. How should I modify my code and make my application (and its instances or other similar applications) to hav...
4
2016-06-19T18:43:12Z
37,928,487
<p>Try this:</p> <pre><code>from PyQt4 import QtCore ... class Main(QMainWindow, Ui_MainWindow): def __init__(self, ): super(Main, self).__init__() self.setWindowFlags(QtCore.Qt.Tool) #This </code></pre>
2
2016-06-20T17:31:19Z
[ "python", "pyqt4", "qt-designer" ]
The best way to perform time gap analysis with Pandas?
37,910,694
<p>I'm trying to find the best way to approach a simple time gap analysis with Python and Pandas. This is just for fun, so feel free to explain answers to help me learn more.</p> <p>I started off by generating some random data. First is dates with a time stamp frequency of 20 seconds over the total periods for 4 sessi...
2
2016-06-19T18:53:43Z
37,910,786
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> by each <code>UserID</code> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.DataFrameGroupBy.diff.html" rel="nofollow"><code>d...
1
2016-06-19T19:03:05Z
[ "python", "pandas", "statistics" ]
Python twill: download file accessible through PHP script
37,910,736
<p>I use <code>twill</code> to navigate on a website protected by a login form.</p> <pre><code>from twill.commands import * go('http://www.example.com/login/index.php') fv("login_form", "identifiant", "login") fv("login_form", "password", "pass") formaction("login_form", "http://www.example.com/login/control.php") s...
2
2016-06-19T18:58:09Z
37,911,758
<p>I managed to do it sending the cookie jar from <code>twill</code> to <code>requests</code>.</p> <p>Nota: I could not use <code>requests</code> only due to an intricate control at login (was not able to figure out the correct headers or other options).</p> <pre><code>import requests from twill.commands import * #...
1
2016-06-19T20:56:07Z
[ "php", "python", "twill" ]
Python twill: download file accessible through PHP script
37,910,736
<p>I use <code>twill</code> to navigate on a website protected by a login form.</p> <pre><code>from twill.commands import * go('http://www.example.com/login/index.php') fv("login_form", "identifiant", "login") fv("login_form", "password", "pass") formaction("login_form", "http://www.example.com/login/control.php") s...
2
2016-06-19T18:58:09Z
37,940,321
<p>Another way using <code>twill.commands.save_html</code> modified to write as 'wb' instead of 'w': <a href="http://stackoverflow.com/questions/12765486/python-2-7-using-twill-saving-downloaded-file-properly?lq=1">Python 2.7 using twill, saving downloaded file properly</a></p>
0
2016-06-21T09:19:06Z
[ "php", "python", "twill" ]
Why does Python's eval(input("Enter input: ")) change input's datatype?
37,910,827
<p>In Python 3, I write a simple command to accept an integer input from the user thus:</p> <pre><code>x = int(input("Enter a number: ")) </code></pre> <p>If I skip the <code>int()</code> part and simply use <code>x = input("Enter a number: ")</code>, my input's datatype is a string, not an integer. I understand that...
4
2016-06-19T19:07:25Z
37,910,861
<blockquote> <p>Why does this happen?</p> </blockquote> <p><code>x = eval(input("Enter a number: "))</code> is not the same thing as <code>x = eval('input("Enter a number: ")')</code></p> <p>The former first calls <code>input(...)</code>, gets a string, e.g. <code>'5'</code> then evaluates it, that's why you get an...
3
2016-06-19T19:12:08Z
[ "python", "eval", "data-type-conversion" ]
Why does Python's eval(input("Enter input: ")) change input's datatype?
37,910,827
<p>In Python 3, I write a simple command to accept an integer input from the user thus:</p> <pre><code>x = int(input("Enter a number: ")) </code></pre> <p>If I skip the <code>int()</code> part and simply use <code>x = input("Enter a number: ")</code>, my input's datatype is a string, not an integer. I understand that...
4
2016-06-19T19:07:25Z
37,910,872
<p>Because a number is a valid expression in Python, and it evaluates to itself (and its type is int). For example, if you input a rubbish string with a non-existing name (say, 'abcdefgh'), a NameError exception will be raised (the exception is raised while evaluating).</p>
0
2016-06-19T19:12:56Z
[ "python", "eval", "data-type-conversion" ]
'emacs': unknown terminal type
37,910,865
<p>I'm getting the following message in the PyCharm Console when selecting the debug button:</p> <pre><code>pydev debugger: process 13699 is connecting Connected to pydev debugger (build 145.1504) 'emacs': unknown terminal type. </code></pre> <p>I'm running on Ubuntu and echo $TERM displays: xterm</p>
2
2016-06-19T19:12:33Z
39,106,690
<p>I installed emacs, elpy and ipython and the next time I ran pyCharm I ended up with this issue as well. </p> <p>I fixed it by editing:<br> <code>/home/$user/.pycharm_helpers/pydev/_pydev_bundle/pydev_ipython_console.py</code> (line 6 for me) </p> <p>Before, giving error:</p> <pre><code>os.environ['TERM'] = 'ema...
0
2016-08-23T16:46:21Z
[ "python", "pycharm" ]
Tweepy stream acting really slow
37,910,948
<p>I'm trying to stream tweets from twitter using Tweepy for a particular hashtag. The problem that I'm facing is that fetching 500 tweets is taking almost around 10-15 minutes. I don't think it is supposed to be that slow? Am I missing anything? Has it got to do with any API rate limits? My tweepy listener looks like ...
0
2016-06-19T19:21:09Z
38,410,283
<p>You are trying to fetch live tweets. It means the rate of your collecting tweets is the rate in which people post tweets with that hashtag. You can try your code with a popular or trending hashtag and you will get outputs faster.</p>
1
2016-07-16T10:38:50Z
[ "python", "twitter", "tweepy" ]