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 |
|---|---|---|---|---|---|---|---|---|---|
Appium 'Failed to connect to the server. Please check that it is running' using Inspector | 39,965,136 | <p>What must be done to use Aappium's inspector?</p>
<p>The screenshot and logs are attached</p>
<ol>
<li>my appium server is set to start an app (with path checked)</li>
<li>the AVD emulator is launched</li>
<li>the tests script is launched, with the app successfully loading on the emulator</li>
<li>when clicking on... | 0 | 2016-10-10T19:08:34Z | 39,990,945 | <p>Appium internally uses UIAutomator to find elements. If you are executing your code using appium then your UIAutomator is already in use and if you try to use it manually then appium will loose the control of UIAutomator.</p>
| 0 | 2016-10-12T05:14:02Z | [
"python",
"appium",
"inspector"
] |
How do I fix: ImportError: cannot import name 'PandaRequest'? | 39,965,157 | <p>This is my first time using a jupyter notebook. </p>
<p>I was trying to import the panda module:</p>
<pre><code>import panda as pd
</code></pre>
<p>but I get the following error:</p>
<pre><code>/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/panda/__init__.py in <module>()
---... | 1 | 2016-10-10T19:10:05Z | 39,965,180 | <p>Execute <code>pip install panda</code>. You don't have the Panda module.</p>
<p>Edit: My mistake, it looks like there's an error within the Panda module itself. Does it rely on PandaRequest?</p>
| 0 | 2016-10-10T19:12:18Z | [
"python",
"ipython",
"jupyter",
"jupyter-notebook"
] |
Save HDFS To MongoDB using Spark-DataFrame | 39,965,271 | <p>I'm trying to save a Spark-DataFrame using PyMongo connecter.
Following is my code, but every-time I run the code I get an error: </p>
<pre><code>java.io.IOException: No FileSystem for scheme: mongodb
</code></pre>
<p>following is my code:</p>
<pre><code>import pymongo
import pymongo_spark
pymongo_spark.activate(... | 1 | 2016-10-10T19:18:42Z | 39,970,201 | <blockquote>
<p>I'm trying to save a Spark-DataFrame using PyMongo connector</p>
</blockquote>
<p>You can try to use <a href="https://docs.mongodb.com/spark-connector/" rel="nofollow">MongoDB Connector for Spark</a>. Using your setup environment of <a href="https://spark.apache.org/releases/spark-release-2-0-0.html"... | 1 | 2016-10-11T03:43:18Z | [
"python",
"mongodb",
"csv",
"hadoop",
"apache-spark"
] |
Python copy files from Linux to WIndows | 39,965,297 | <p>I'm building a website which has a form which captures user data and runs some cgi on the user data. One of the first steps of the cgi is that it needs to copy files from the linux webserver to windows machines. The server would be using an active directory role acount for the copy credential. I had hoped to simp... | 0 | 2016-10-10T19:21:49Z | 39,965,444 | <p>This approach has two drawbacks: the first one is that you mount windows share from your webserver. You don;t need to mount it dynamically and in no account you should not mount it for every request. Separate your implementation and infrastructure. Mount required directory in /etc/fstab and let your webserver to rel... | 0 | 2016-10-10T19:31:56Z | [
"python",
"linux",
"windows",
"cifs"
] |
Python copy files from Linux to WIndows | 39,965,297 | <p>I'm building a website which has a form which captures user data and runs some cgi on the user data. One of the first steps of the cgi is that it needs to copy files from the linux webserver to windows machines. The server would be using an active directory role acount for the copy credential. I had hoped to simp... | 0 | 2016-10-10T19:21:49Z | 39,965,528 | <p>First, drop the exception block as it hides error details, anyway <code>Popen</code> and other <code>subprocess</code> methods only throw exceptions when they cannot start commands (because of command not found), which means that <code>mount</code> is actually called.</p>
<p>Second, you really don't need <code>Pope... | 0 | 2016-10-10T19:38:03Z | [
"python",
"linux",
"windows",
"cifs"
] |
Python copy files from Linux to WIndows | 39,965,297 | <p>I'm building a website which has a form which captures user data and runs some cgi on the user data. One of the first steps of the cgi is that it needs to copy files from the linux webserver to windows machines. The server would be using an active directory role acount for the copy credential. I had hoped to simp... | 0 | 2016-10-10T19:21:49Z | 39,981,706 | <p>The solution was not to mount the share but rather to copy on the fly using smbclient. The command I'm using refers to an authfile which contains an account with the relevant permissions in the form:</p>
<pre><code>username = yourUsername
password = yourPassword
domain = yourDomain
</code></pre>
<p>The permission... | 0 | 2016-10-11T16:02:58Z | [
"python",
"linux",
"windows",
"cifs"
] |
How do I find the coordinates of the nodes in a binary tree given as a heap in the input? | 39,965,328 | <p>Given a heap as input, such as:</p>
<pre><code>1 2 3 - 5 - 7
</code></pre>
<p>Where '-' represents an empty node, I want to find the coordinates of the nodes, which would for the input above be:</p>
<pre><code>[1, 0] [0, 2] [2, 2] [-1, -1] [1, 4] [-1, -1] [3, 4]
</code></pre>
<p>The rules for the coordinate tran... | -2 | 2016-10-10T19:24:08Z | 39,980,261 | <p>If you look at a heap, you'll notice that each level has twice as many nodes as the previous level. So you have the progression 1, 2, 4, 8, 16, etc.</p>
<p>Given a node's index in the input array, you can easily determine the level it's on by taking the base-2 logarithm of the index and rounding down. That is, if w... | 0 | 2016-10-11T14:56:57Z | [
"python",
"heap",
"binary-tree"
] |
replacing a column in DataFrame using regex | 39,965,414 | <p>I have a data frame with 4 columns, col4 is a string including texts and digits:</p>
<pre><code> Col1 Col2 Col3 Col4
Syslog 2016,09,17 1 PD380_003 %LINK-3-UPDOWN
Syslog 2016,09,17 1 NM380_005 %BGP-5-NBR_RESET
Syslog 2016,09,14 ... | 2 | 2016-10-10T19:29:42Z | 39,965,536 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow"><code>extract</code></a>:</p>
<pre><code>data.Col4 = data.Col4.str.extract('([A-Z]{2}[0-9]{3}_[0-9]{3})', expand=False)
print (data)
Col1 Col2 Col3 Col4
0 Syslog 2016,... | 2 | 2016-10-10T19:38:19Z | [
"python",
"pandas"
] |
replacing a column in DataFrame using regex | 39,965,414 | <p>I have a data frame with 4 columns, col4 is a string including texts and digits:</p>
<pre><code> Col1 Col2 Col3 Col4
Syslog 2016,09,17 1 PD380_003 %LINK-3-UPDOWN
Syslog 2016,09,17 1 NM380_005 %BGP-5-NBR_RESET
Syslog 2016,09,14 ... | 2 | 2016-10-10T19:29:42Z | 39,966,171 | <p>You were using RegEx in a wrong way.</p>
<p><code>{'Col4':{'.*':'([A-Z]{2}[0-9]{3}_[0-9]{3})'}}</code> - means replace a whatever string in the <code>Col4</code> column with <code>'([A-Z]{2}[0-9]{3}_[0-9]{3})'</code></p>
<p>Try this:</p>
<pre><code>In [87]: df.replace({'Col4':{r'.*?([A-Z]{2}[0-9]{3}_[0-9]{3}).*':... | 0 | 2016-10-10T20:24:04Z | [
"python",
"pandas"
] |
replacing a column in DataFrame using regex | 39,965,414 | <p>I have a data frame with 4 columns, col4 is a string including texts and digits:</p>
<pre><code> Col1 Col2 Col3 Col4
Syslog 2016,09,17 1 PD380_003 %LINK-3-UPDOWN
Syslog 2016,09,17 1 NM380_005 %BGP-5-NBR_RESET
Syslog 2016,09,14 ... | 2 | 2016-10-10T19:29:42Z | 39,966,535 | <p>First, you have the wrong regex's in the wrong positions. The <code>to_replace</code> argument to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html?highlight=replace#pandas-dataframe-replace" rel="nofollow">.replace</a> needs to match what to replace and what to delete. So ... | 1 | 2016-10-10T20:49:56Z | [
"python",
"pandas"
] |
beautiful soup - python - table scraping | 39,965,416 | <p>Trying to scrape a table from a website using beautiful soup in order to parse the data. How would I go about parsing it by its headers? So far, I can't even manage to print the entire table.Thanks in advance.</p>
<p>Here is the code:</p>
<pre><code>import urllib2
from bs4 import BeautifulSoup
optionstable = "htt... | 1 | 2016-10-10T19:29:45Z | 39,965,708 | <p>The page is a dynamic page. It uses the <a href="https://datatables.net/" rel="nofollow">DataTables</a> jquery plugin to display the table. If you look at the page source you'll see an empty table. It is filled after the page is loaded.</p>
<p>You have two choices here. Either figure out which URL the Javascript co... | 0 | 2016-10-10T19:49:23Z | [
"python",
"parsing",
"web-scraping",
"beautifulsoup"
] |
beautiful soup - python - table scraping | 39,965,416 | <p>Trying to scrape a table from a website using beautiful soup in order to parse the data. How would I go about parsing it by its headers? So far, I can't even manage to print the entire table.Thanks in advance.</p>
<p>Here is the code:</p>
<pre><code>import urllib2
from bs4 import BeautifulSoup
optionstable = "htt... | 1 | 2016-10-10T19:29:45Z | 39,965,760 | <p>You need to mimic the ajax request to get the table data:</p>
<pre><code>import requests
from time import time
optionstable = "http://www.barchart.com/options/optdailyvol?type=stocks"
params = {"type": "stocks",
"dir": "desc",
"_": str(time()),
"f": "base_symbol,type,strike,expirati... | 2 | 2016-10-10T19:52:33Z | [
"python",
"parsing",
"web-scraping",
"beautifulsoup"
] |
Horizontal Bar Chart on Pandas Data Frame with Dynamic Column Names | 39,965,440 | <p>I have the following source data (which comes from a csv file):</p>
<pre><code>ABC,2016-6-9 0:00,95,"{'//Purple': [115L], '//Yellow': [403L], '//Blue': [16L], '//White-XYZ': [0L]}"
ABC,2016-6-10 0:00,0,"{'//Purple': [219L], '//Yellow': [381L], '//Blue': [90L], '//White-XYZ': [0L]}"
ABC,2016-6-11 0:00,0,"{'//Purple'... | 0 | 2016-10-10T19:31:25Z | 39,966,184 | <p>in order to loop through a certain number of columns to the right of the 'code' column I would do something of the form</p>
<pre><code>for col in df.columns[3:]:
plot(col)
</code></pre>
<p>However this only works if you can guarantee that your columns will always be in the same order. Alternatively you could m... | 0 | 2016-10-10T20:24:56Z | [
"python",
"pandas",
"matplotlib",
"plot",
"seaborn"
] |
Horizontal Bar Chart on Pandas Data Frame with Dynamic Column Names | 39,965,440 | <p>I have the following source data (which comes from a csv file):</p>
<pre><code>ABC,2016-6-9 0:00,95,"{'//Purple': [115L], '//Yellow': [403L], '//Blue': [16L], '//White-XYZ': [0L]}"
ABC,2016-6-10 0:00,0,"{'//Purple': [219L], '//Yellow': [381L], '//Blue': [90L], '//White-XYZ': [0L]}"
ABC,2016-6-11 0:00,0,"{'//Purple'... | 0 | 2016-10-10T19:31:25Z | 39,966,630 | <p>IIUC you can do it this way:</p>
<p>Original DF:</p>
<pre><code>In [127]: df
Out[127]:
Company Date Code Yellow Blue White Black
0 ABC 2016-06-09 115 403 16 19 472
1 ABC 2016-06-10 219 381 90 20 2474
2 ABC 2016-06-11 817 21 31 88 54
3 AB... | 0 | 2016-10-10T20:56:45Z | [
"python",
"pandas",
"matplotlib",
"plot",
"seaborn"
] |
What is the proper way to write a syslog function in python? | 39,965,535 | <p>Despite my efforts I have been unable to figure out how to create a function that works with logging in python. No matter what I do, I get a duplicate syslog entry.</p>
<pre><code>def send_syslog(input):
my_logger = logging.getLogger()
my_logger.setLevel(logging.DEBUG)
handler = logging.handlers.SysLogH... | 0 | 2016-10-10T19:38:17Z | 39,965,571 | <p>You should use the python <a href="https://docs.python.org/2/library/syslog.html" rel="nofollow">syslog</a> module:</p>
<pre><code>import syslog
def main():
syslog.syslog(syslog.LOG_INFO, "Everything is working okay!")
syslog.syslog(syslog.LOG_ERR, 'This is logged at the error level.')
if __name__ == "__ma... | 0 | 2016-10-10T19:40:06Z | [
"python",
"function",
"logging",
"syslog"
] |
Python sympy dsolve error | 39,965,537 | <p>After reinstalling Python, the following simple code</p>
<pre><code>import sympy as sm
x = sm.Symbol('x')
f = sm.Function('f')
y = sm.dsolve(sm.diff(f (x),x)-3*f(x)(1-0.5f(x)),f(x))
print(y)
</code></pre>
<p>gives the following output:</p>
<pre><code>Eq(x + 0.333333333333333*log(1.0*f(x) - 2.0) - 0.3333333333... | 1 | 2016-10-10T19:38:19Z | 39,966,548 | <p>You can try to use <code>Rational</code> instead of float number, as follow:</p>
<pre><code>>>> import sympy as sym
>>> x = sym.Symbol('x')
>>> f = sym.Function('f')(x)
>>> y = sym.dsolve(sym.diff(f,x)-3*f*(1-sym.Rational(1, 2)*f),f)
>>> print y
Eq(f(x), -2/(C1*exp(-3*x)... | 1 | 2016-10-10T20:51:27Z | [
"python",
"sympy",
"dsolve"
] |
Python sympy dsolve error | 39,965,537 | <p>After reinstalling Python, the following simple code</p>
<pre><code>import sympy as sm
x = sm.Symbol('x')
f = sm.Function('f')
y = sm.dsolve(sm.diff(f (x),x)-3*f(x)(1-0.5f(x)),f(x))
print(y)
</code></pre>
<p>gives the following output:</p>
<pre><code>Eq(x + 0.333333333333333*log(1.0*f(x) - 2.0) - 0.3333333333... | 1 | 2016-10-10T19:38:19Z | 39,997,796 | <p>First of all I am sorry about the syntax and editing mistakes in the first post.
Actually, right now I am running exactly the same code in two computers, one with Anaconda for Windows other with Spyder for Ubuntu, both have Python 2.7, and got two different answers. The code is:</p>
<p>import sympy as sm</p>
<p>x ... | 0 | 2016-10-12T11:46:06Z | [
"python",
"sympy",
"dsolve"
] |
append pandas series in loop | 39,965,632 | <p>I have tries using pandas.Series().append() inside a loop but the return is the same Series that went into this method. I need this method to return a pandas Series with repeating values. The number of repetitions decided by num.</p>
<pre><code>def expand(ser, num):
sers = ser
x = 0
while(x < num):
sers.appe... | 0 | 2016-10-10T19:44:42Z | 39,965,707 | <p>Is there a reason you don't want to use <a href="http://pandas.pydata.org/pandas-docs/version/0.17.1/generated/pandas.Series.repeat.html" rel="nofollow"><code>pandas.Series.repeat</code></a>?</p>
<pre><code>import pandas as pd
import numpy as np
s = pd.Series(np.random.randn(3), index=['a', 'b', 'c'])
num = 3
re... | 0 | 2016-10-10T19:49:14Z | [
"python",
"pandas"
] |
Django Translation Don't Work | 39,965,689 | <p>Try to translate block this block and load i18n:</p>
<pre><code>{% load i18n %}
<p>{% trans "Welcome to our page" %}</p>
{% language 'ru' %}
<p>{% trans "Welcome to our page" %}</p>
{% endlanguage %}
</code></pre>
<p>settings.py</p>
<pre><code>SE_I18N = True
USE_L10N = True
LANGUAG... | 0 | 2016-10-10T19:48:19Z | 39,966,481 | <p>So what is going on, is that you have just ordinary urls, when you needed <code>i18n_patterns</code>,</p>
<p>So, change your urls to </p>
<pre><code>import os
from django.conf.urls import url, include
from django.conf.urls.i18n import i18n_patterns
from django.contrib import admin
from django.contrib.staticfiles.... | 0 | 2016-10-10T20:46:19Z | [
"python",
"django"
] |
Django Translation Don't Work | 39,965,689 | <p>Try to translate block this block and load i18n:</p>
<pre><code>{% load i18n %}
<p>{% trans "Welcome to our page" %}</p>
{% language 'ru' %}
<p>{% trans "Welcome to our page" %}</p>
{% endlanguage %}
</code></pre>
<p>settings.py</p>
<pre><code>SE_I18N = True
USE_L10N = True
LANGUAG... | 0 | 2016-10-10T19:48:19Z | 39,967,009 | <p>You need to use <code>{% get_current_language as LANGUAGE_CODE %}</code> tag which updates the <code>LANGUAGE_CODE</code> setting. See <a href="https://docs.djangoproject.com/en/1.10/topics/i18n/translation/#how-django-discovers-language-preference" rel="nofollow">how-django-discovers-language-preference</a>.</p>
<... | 1 | 2016-10-10T21:27:33Z | [
"python",
"django"
] |
1064, "You have an error in your SQL syntax;..." Python MySQL | 39,965,697 | <p>So I have been working on this since last Friday and cannot get around this error:</p>
<blockquote>
<p>1064, "You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near '[u'161010-035670'] WHERE order_id=87' at line 1" or something
a... | 1 | 2016-10-10T19:48:43Z | 39,965,783 | <p>The <code>data</code> value is a <em>list</em> and you are trying to format it into the query. And, <strong>don't use string formatting to insert variables into a query</strong> - use a proper <em>query parameterization</em> instead:</p>
<pre><code>cursor.execute("""
UPDATE
tplinkus_rma.rma_order
... | 0 | 2016-10-10T19:54:10Z | [
"python",
"mysql",
"python-2.7",
"salesforce",
"mysql-python"
] |
python log formatter that shows all kwargs in extra | 39,965,807 | <p>I hope to add the following log points to my application and display the full contents of <code>extra</code> on console, e.g., </p>
<pre><code>logger.info('Status', extra={'foo':data})
logger.info('Status', extra={'bar':data})
logger.info('Status', extra={'foo':data, 'bar':data})
</code></pre>
<p>and I hope to se... | 1 | 2016-10-10T19:56:14Z | 39,974,319 | <p>Trying to solve the same problem right now. The problem is that anything passed to extra is added as a property of LogRecord and the formatter cannot distinguish it from other LogRecord properties. I only came up with a hackish approach of creating a dummy record and comparing it with the actual one:</p>
<pre><code... | 0 | 2016-10-11T09:33:32Z | [
"python",
"logging"
] |
Python ignoring property setter in favor of property getter | 39,965,824 | <p>I have created a class that has a property with a setter. There are 2 different ways to use this class, so the values of some of the object components may be set in a different order depending on the scenario (i.e. I don't want to set them during <code>__init__</code>). I have included a non-property with its own se... | 1 | 2016-10-10T19:57:06Z | 39,966,260 | <p>Short Answer: Please change your line <code>self.priority(priority)</code> to <code>self.priority = priority</code></p>
<p>Explanation: Setter is called only when you assign something to the attribute. In your code, you are not doing an assignment operation.</p>
<p>Here are some nice references if you want to unde... | 2 | 2016-10-10T20:29:47Z | [
"python",
"properties"
] |
Python ignoring property setter in favor of property getter | 39,965,824 | <p>I have created a class that has a property with a setter. There are 2 different ways to use this class, so the values of some of the object components may be set in a different order depending on the scenario (i.e. I don't want to set them during <code>__init__</code>). I have included a non-property with its own se... | 1 | 2016-10-10T19:57:06Z | 39,966,297 | <p>You are facing this issue due to trying to treat priority as a method in your all_the_things method. At this point it is already a property, so you assign to it like a variable:</p>
<pre><code>def all_the_things(self, name, priority=100):
self.set_name(name)
self.priority = priority
</code></pre>
| 0 | 2016-10-10T20:32:06Z | [
"python",
"properties"
] |
obtaining boundary of polygon embedded in a matrix and other post-processing techniques | 39,965,825 | <p>I have a 100x100 Boolean matrix called <code>mat</code>. All cells have false value except a continuous patch of polygonal area. I can read the cells belonging to this polygon by running through each cell of the matrix and finding true cells.</p>
<pre><code>region_of_interest=false(size(mat));
for i=1:size(mat,1)
... | 2 | 2016-10-10T19:57:08Z | 39,966,227 | <p>This is neither Python nor a convex-hull problem.</p>
<p>However, I would point out that boundary cells inside the polygon are true and have at least one neighbor which is false, and boundary cells outside the polygon are false and have at least one neighbor which is true.</p>
<p>It's up to you to decide whether y... | 0 | 2016-10-10T20:27:57Z | [
"python",
"matlab",
"convex-hull"
] |
plot legends of a correlation matrix | 39,965,891 | <p>I have a correlation mat obtained from a data frame</p>
<pre><code>>>> mat
Lcaud Rcaud Left_cereb_gm Right_cereb_gm Lamyg
Rcaud 0.931934 1.000000 0.856891 0.715523 0.924995
Left_cereb_gm 0.915274 0.856891 1.000000 0.938301 0... | 0 | 2016-10-10T20:00:57Z | 39,966,568 | <p>I assume that you don't really want an <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.legend" rel="nofollow">actual legend</a> since there is no easy way to define what color corresponds to each label or label-label pair. Instead, I think you are asking about setting the ticklabels? For examp... | 2 | 2016-10-10T20:52:31Z | [
"python",
"pandas",
"matplotlib"
] |
Python/Psychopy: passing information between functions | 39,965,944 | <p>I am having some trouble passing information between two functions. Within my 'trial' function (see code below) I am checking for keypresses and expecting to exit out of the while loop if a 'g or 'h' key is pressed. The while loop is dependent on test=1. From within my 'check_keys' function, as soon as the 'g' or 'h... | 0 | 2016-10-10T20:05:36Z | 39,966,069 | <p>You're stuck because you haven't declared test as a global inside of your check_keys() method. That being said, what you should do is have check_keys return the value of test, and then just keep track of it in main:</p>
<pre><code>def trial():
test = 1
while test == 1:
test = check_keys()
</code></... | 1 | 2016-10-10T20:14:52Z | [
"python",
"psychopy"
] |
[Pandas]The way to assign a new column based on if statement | 39,965,946 | <p>I know assign could help to create/change one column based on lambda function like this: </p>
<pre><code>df.assign(c = lambda x: x.sum())
</code></pre>
<p>But I couldn't find a way to do this with if-statement if I want to make the statement inline instead of doing it separately outside of the operation. </p>
<p>... | 1 | 2016-10-10T20:05:43Z | 39,966,571 | <p>The syntax is invalid because you're using the ternary condition, but only the first half.</p>
<p>The ternary condition allows you to write an <code>if</code> statement like this:</p>
<pre><code>a = 1 if b > 0 else 0
</code></pre>
<p>In your case, you could write something like:</p>
<pre><code>df = (
df
.... | 0 | 2016-10-10T20:52:41Z | [
"python",
"pandas",
"dataframe"
] |
[Pandas]The way to assign a new column based on if statement | 39,965,946 | <p>I know assign could help to create/change one column based on lambda function like this: </p>
<pre><code>df.assign(c = lambda x: x.sum())
</code></pre>
<p>But I couldn't find a way to do this with if-statement if I want to make the statement inline instead of doing it separately outside of the operation. </p>
<p>... | 1 | 2016-10-10T20:05:43Z | 39,967,182 | <p>IIUC you can do it this way:</p>
<p><strong>Data:</strong></p>
<pre><code>In [6]: df = pd.DataFrame(np.random.randn(10,2),columns=list('ab'))
In [7]: df
Out[7]:
a b
0 0.493970 1.095644
1 0.128510 -0.542144
2 0.136247 -0.544499
3 -0.540835 -0.100574
4 0.052725 -0.164856
5 -1.201619 1.578153... | 2 | 2016-10-10T21:41:27Z | [
"python",
"pandas",
"dataframe"
] |
Flask blueprint cannot read sqlite3 DATABASES from config file | 39,965,970 | <p>I would like Python Flask to read from configuration file the location of the sqlite3 database name <strong>without explicitly writing database name</strong>. Templates used are: <a href="http://flask.pocoo.org/docs/0.11/patterns/sqlite3/" rel="nofollow">http://flask.pocoo.org/docs/0.11/patterns/sqlite3/</a> and ... | 0 | 2016-10-10T20:07:45Z | 39,966,366 | <p>Your <code>my_cool_app</code> is an instance of <code>Blueprint</code> which doesn't have a <code>config</code> attribute. You need to use <code>current_app</code>:</p>
<pre><code>import sqlite3
from flask import Flask, g, current_app
from .views import my_cool_app
# create application
def create_app(debug=True):
... | 1 | 2016-10-10T20:37:20Z | [
"python",
"flask",
"sqlite3",
"blueprint"
] |
Same attribute for 4 different classes | 39,965,976 | <p>I have a problem for a script in a 3D GIS software (Infraworks).
I need to say to a 3D model to have the same random value for 4 different attributes, x,y and z scale and z movement.
Someone knows how to do it?</p>
<p>At the moment I wrote this script, but cause I'm not a proper programmer I don't know if it's the ... | -1 | 2016-10-10T20:08:14Z | 39,966,045 | <p>Assuming I understand you correctly, you'll want to first create the value, then store the same one into all four places:</p>
<pre><code>random_value = Math.random()*3+1
TREES.MODEL_SCALE_X = random_value
TREES.MODEL_SCALE_Y = random_value
TREES.MODEL_SCALE_Z = random_value
TREES.MODEL_TRANSLATE_Z = random_value
<... | 0 | 2016-10-10T20:13:13Z | [
"python",
"3d",
"gis",
"autodesk"
] |
Memory-friendly way to add a field to a structured ndarray â without duplicating data? | 39,965,994 | <p>To add a field to a structured numpy array, it is quite simply to create a new array with a new dtype, copy over the old fields, and add the new field. However, I need to do this for an array that takes a lot of memory, and I would rather not duplicate all of it. Both my own implementation and the (slow) implement... | 1 | 2016-10-10T20:09:27Z | 39,966,624 | <p>A structured array is stored, like a regular one, as a contiguous buffer of bytes, one record following the previous. The records are, thus, a bit like the last dimension of a multidimensional array. You can't add a column to a 2d array without making a new array via concatenation.</p>
<p>Adding a field, say <cod... | 2 | 2016-10-10T20:56:26Z | [
"python",
"arrays",
"numpy",
"memory",
"structured-array"
] |
Solving second order ODE using odeint in Python | 39,966,019 | <p>I want to solve this equation:</p>
<p>y'' + A<em>y' - B</em>y = 0</p>
<p>where y, A and B are functions of the same variable "a"</p>
<p>I tried the following code:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as pyplot
from scipy.integrate import odeint
x0 = 0.,0.1 # initial conditions
oe = 0.0 ... | 0 | 2016-10-10T20:10:53Z | 39,967,419 | <p>Please try to change sign before B(a)*X0 in the function system(X, a). It should be negative according to your initial equation.</p>
| 0 | 2016-10-10T22:01:36Z | [
"python",
"ode"
] |
align rows by date in pandas dataframe | 39,966,021 | <p>An excerpt of the Dateframe could look like this (it's certainly much larger):</p>
<pre><code> Date1 Log1 Date2 Log2 Date3 Log3
Index
0 01.01.2000 1000 02.01.2000 2000 01.01.2000 3000
1 02.01.2000 1050 03.01.2000 1950 02.01.2000 3020
2 ... | 1 | 2016-10-10T20:11:05Z | 39,966,889 | <p>I am assuming you only want to keep values from ['Date2', 'Log2'] and ['Date3', 'Log3'] when the dates have a match in Date1.</p>
<p>You can read the different columns into separate dataframes and use <code>merge</code>. Then filter to only keep rows where the Date1 column is not null.</p>
<pre><code>df
>>&g... | 1 | 2016-10-10T21:17:59Z | [
"python",
"pandas",
"dataframe"
] |
align rows by date in pandas dataframe | 39,966,021 | <p>An excerpt of the Dateframe could look like this (it's certainly much larger):</p>
<pre><code> Date1 Log1 Date2 Log2 Date3 Log3
Index
0 01.01.2000 1000 02.01.2000 2000 01.01.2000 3000
1 02.01.2000 1050 03.01.2000 1950 02.01.2000 3020
2 ... | 1 | 2016-10-10T20:11:05Z | 39,966,891 | <p>A dictionary to represent your data, this is just a convenience to load the sample data to dataframe.</p>
<pre><code>d = {'Date1': {0: '01.01.2000', 1: '02.01.2000', 2: '03.01.2000'}, 'Date3': {0: '01.01.2000', 1: '02.01.2000', 2: '03.01.2000'}, 'Date2': {0: '02.01.2000', 1: '03.01.2000', 2: '04.01.2000'}, 'Log2': ... | 1 | 2016-10-10T21:18:19Z | [
"python",
"pandas",
"dataframe"
] |
align rows by date in pandas dataframe | 39,966,021 | <p>An excerpt of the Dateframe could look like this (it's certainly much larger):</p>
<pre><code> Date1 Log1 Date2 Log2 Date3 Log3
Index
0 01.01.2000 1000 02.01.2000 2000 01.01.2000 3000
1 02.01.2000 1050 03.01.2000 1950 02.01.2000 3020
2 ... | 1 | 2016-10-10T20:11:05Z | 39,967,371 | <p>Solution with <code>list comprehension</code> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reindex.html" rel="nofollow"><code>reindex</code></a>, last <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> all d... | 1 | 2016-10-10T21:56:59Z | [
"python",
"pandas",
"dataframe"
] |
How to introduce parameters in a cypher query? | 39,966,055 | <p>I have this cypher query in a Python program:</p>
<pre><code>prevNode = graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n")
</code></pre>
<p>The line of code above gives the next error:
'py2neo.database.status.ClientError: Expected a parameter named param'</p>
<p>param is well defined at ... | 0 | 2016-10-10T20:13:34Z | 39,966,144 | <p>You didn't pass any substitution variables into the function.</p>
<pre><code>graph_db.data("OPTIONAL MATCH (n:Node) WHERE n.property = {param} RETURN n", param='1234')
</code></pre>
<p>You can also explicitly pass in the <code>locals()</code> dictionary; this will use any local variables you have defined of the ap... | 2 | 2016-10-10T20:22:13Z | [
"python",
"neo4j",
"cypher",
"py2neo"
] |
How to directly set the gradient of a layer before backpropagation? | 39,966,149 | <p>Imagine a tiny network defined as follows, where linear is a typical helper function defining TensorFlow variables for a weight matrix and activation function:</p>
<p><code>final_layer = linear(linear(_input,10,tf.nn.tanh),20)</code></p>
<p>Normally this would be optimized via gradient descent on a loss:</p>
<p><... | 3 | 2016-10-10T20:22:41Z | 39,974,148 | <p><code>tf.gradients</code> provides this functionality via its <code>grad_ys</code> argument, see <a href="https://www.tensorflow.org/versions/r0.11/api_docs/python/train.html#gradients" rel="nofollow">here</a>. In your case, <code>tf.gradients([final_layer], list_of_variables, grad_ys=[_deriv])</code> would compute ... | 1 | 2016-10-11T09:24:21Z | [
"python",
"tensorflow",
"backpropagation",
"gradient-descent"
] |
How to zip a list of lists in python? | 39,966,187 | <p>I have a list of lists</p>
<pre><code>sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']].
</code></pre>
<p>I am trying to zip the file such that only A/T/G/C are in lists and the output needs to be a list</p>
<pre><code>[['AT','TCCC'],['ATT','TTCC']]
</code></pre>
<p>When ... | -2 | 2016-10-10T20:25:06Z | 39,966,316 | <p>I assume the input you've given are two items in one list. Then, you would use a <em>list comprehension</em> with 2 levels of nesting. At the deepest level, you filter out items that are not <code>A, T, G</code> or <code>C</code> and then <code>join</code> the others:</p>
<pre><code>sample = [[['A','T','N','N'],['... | 0 | 2016-10-10T20:32:56Z | [
"python",
"list"
] |
How to zip a list of lists in python? | 39,966,187 | <p>I have a list of lists</p>
<pre><code>sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']].
</code></pre>
<p>I am trying to zip the file such that only A/T/G/C are in lists and the output needs to be a list</p>
<pre><code>[['AT','TCCC'],['ATT','TTCC']]
</code></pre>
<p>When ... | -2 | 2016-10-10T20:25:06Z | 39,966,362 | <p>You want to do the following:</p>
<pre><code>sample = [[['A','T','N','N'],['T', 'C', 'C', 'C']], [['A','T','T','N'],['T', 'T', 'C', 'C']]]
</code></pre>
<p>And then:</p>
<pre><code>tt = [[''.join([c for c in sublist if c in 'AGTC']) for sublist in doublet] for doublet in sample]
</code></pre>
<p>Perhaps more rea... | 1 | 2016-10-10T20:36:45Z | [
"python",
"list"
] |
How to zip a list of lists in python? | 39,966,187 | <p>I have a list of lists</p>
<pre><code>sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']].
</code></pre>
<p>I am trying to zip the file such that only A/T/G/C are in lists and the output needs to be a list</p>
<pre><code>[['AT','TCCC'],['ATT','TTCC']]
</code></pre>
<p>When ... | -2 | 2016-10-10T20:25:06Z | 39,966,371 | <p>You can first create a helper function:</p>
<pre><code>def filterJoin(s):
return ''.join(x for x in s if x in 'ATGC')
</code></pre>
<p>Then:</p>
<pre><code>>>> sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']]
>>> [[filterJoin(s) for s in t] for t in ... | 1 | 2016-10-10T20:37:34Z | [
"python",
"list"
] |
How to zip a list of lists in python? | 39,966,187 | <p>I have a list of lists</p>
<pre><code>sample = [['A','T','N','N'],['T', 'C', 'C', 'C']],[['A','T','T','N'],['T', 'T', 'C', 'C']].
</code></pre>
<p>I am trying to zip the file such that only A/T/G/C are in lists and the output needs to be a list</p>
<pre><code>[['AT','TCCC'],['ATT','TTCC']]
</code></pre>
<p>When ... | -2 | 2016-10-10T20:25:06Z | 39,966,400 | <p>Your actual code is <em>discarding lists</em>. You only ever process the <em>last entry</em>.</p>
<p>Your code works fine otherwise. Just do that <em>in the loop</em> and then append the result to some final list:</p>
<pre><code>results = []
for k in range(len(seq_list)):
column_list = [[] for i in range(len(... | 3 | 2016-10-10T20:39:18Z | [
"python",
"list"
] |
TypeError: __init__() takes exactly 8 arguments (7 given) Python Homework | 39,966,231 | <p>I can't figure out why I am getting the TypeError. Below is a class and two sub-classes. The first two work fine. The Final sub-class(OperatingSys) is where I am finding difficulty. I have put my Error input at the very bottom. Thanks in advance! </p>
<pre><code>class InventoryItem(object):
def __init__(self, t... | -3 | 2016-10-10T20:28:01Z | 39,966,298 | <p>When you try and create <code>OperatingSys</code> you are passing in 6 parameters â which together with <code>self</code> make 7:</p>
<pre><code>OperatingSys(
title="The Division", # 1
description="third person shooter", # 2
price=69.99, # 3
opsys="", ... | 0 | 2016-10-10T20:32:08Z | [
"python",
"typeerror"
] |
How do you use multiple arguments in {} when using the .format() method in Python | 39,966,239 | <p>I want a table in python to print like this: </p>
<p><img src="https://i.imgur.com/ymGkIdQ.png" alt=""></p>
<p>Clearly, I want to use the .format() method, but I have long floats that look like this: <code>1464.1000000000001</code> I need the floats to be rounded, so that they look like this: <code>1464.10</code> ... | 3 | 2016-10-10T20:28:23Z | 39,966,269 | <p>You were almost there, just remove the comma (and pass in a float number, not a string):</p>
<pre><code>"{0:>15.2f}".format(1464.1000000000001)
</code></pre>
<p>See the <a href="https://docs.python.org/3/library/string.html#format-specification-mini-language" rel="nofollow"><em>Format Specification Mini-Languag... | 5 | 2016-10-10T20:30:37Z | [
"python",
"python-3.x",
"rounding",
"string-formatting",
"string.format"
] |
How do you use multiple arguments in {} when using the .format() method in Python | 39,966,239 | <p>I want a table in python to print like this: </p>
<p><img src="https://i.imgur.com/ymGkIdQ.png" alt=""></p>
<p>Clearly, I want to use the .format() method, but I have long floats that look like this: <code>1464.1000000000001</code> I need the floats to be rounded, so that they look like this: <code>1464.10</code> ... | 3 | 2016-10-10T20:28:23Z | 39,966,275 | <pre><code>"{0:15.2f}".format(1464.1000000000001)
</code></pre>
<p>I always find this site useful for this stuff:</p>
<p><a href="https://pyformat.info/" rel="nofollow">https://pyformat.info/</a></p>
| 3 | 2016-10-10T20:31:01Z | [
"python",
"python-3.x",
"rounding",
"string-formatting",
"string.format"
] |
PyQt: Window is closed but process still running | 39,966,309 | <p>Just a simple problem (not for me): when I close the window, the program is still running. Here is the code:</p>
<pre><code>from PyQt4 import QtCore, QtGui
from PyQt4.Qt import QString
import sys
import sensors
from sensors import *
import threading
class MainWindow(QtGui.QWidget):
signalUpdate = QtCore.pyqtS... | 0 | 2016-10-10T20:32:35Z | 39,968,421 | <p>Call the timer's cancel() method in your widget's (overridden) closeEvent() method:</p>
<pre><code>def tmp(self):
...
self.timer = threading.Timer(2.0, self.tmp)
self.timer.start()
self.signalUpdate.emit() #emit signal
def closeEvent(self):
self.timer.cancel()
</code></pre>
<p>I've tested t... | 1 | 2016-10-10T23:45:08Z | [
"python",
"python-2.7",
"pyqt"
] |
Drawing box around message | 39,966,393 | <p>I'm working on this Python task that I can't figure out. It is the last of 3 functions and the first 2 were much easier to program then this one. The instructions are
"Given a message that may contain multiple lines, utilize the split() function to identify the individual lines, and the format() function so that wh... | -3 | 2016-10-10T20:39:02Z | 39,966,497 | <p>Find out the length of your longest line N; <code>(N+2) * '-'</code> gives you the top and bottom borders. Before each line add a bar: '|'; pad each line with <code>N - n</code> spaces, where n is the length of that line. Append to each line a bar. Print in the correct order: top, line 1, line2, ..., line L, bottom.... | -1 | 2016-10-10T20:47:40Z | [
"python",
"drawing",
"message",
"rectangles"
] |
Drawing box around message | 39,966,393 | <p>I'm working on this Python task that I can't figure out. It is the last of 3 functions and the first 2 were much easier to program then this one. The instructions are
"Given a message that may contain multiple lines, utilize the split() function to identify the individual lines, and the format() function so that wh... | -3 | 2016-10-10T20:39:02Z | 39,966,926 | <p>I've stitched up a little piece of code which implements the boxed messages. To be honest it's not the nicest piece of code, but it does the job and hopefully will help you to do it yourself (and better). For that purpose I've decided not to include comment, so you have to think that through for yourself. Maybe not ... | -1 | 2016-10-10T21:21:36Z | [
"python",
"drawing",
"message",
"rectangles"
] |
Plotting timestamps in Python | 39,966,417 | <p>I am new to Python and am trying to create a simple line graph with time on the x axis and values on the y. I have a CSV file from which to import the data.</p>
<p>A sample of the data looks like this</p>
<p><a href="http://i.stack.imgur.com/GIygc.png" rel="nofollow"><img src="http://i.stack.imgur.com/GIygc.png" a... | 0 | 2016-10-10T20:41:31Z | 39,966,990 | <p>If you're using <code>matplotlib.__version__ >= 1.5.0</code>, then the following should work:</p>
<pre><code>In [4]: df
Out[4]:
Timestamp A
0 03/10/2016 16:00 0.033361
1 04/10/2016 16:01 0.123108
2 05/10/2016 16:02 0.021805
In [5]: df.index = pd.to_datetime(df.Timestamp, dayfirst=True)
... | 1 | 2016-10-10T21:26:25Z | [
"python",
"datetime",
"matplotlib",
"timestamp"
] |
Django Admin Panel | 39,966,433 | <p>I am trying to set up a new blog. I want to keep all my project templates folder in the same folder as where my settings.py is. To do this I did the following...
[...]</p>
<pre><code>TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, "... | 0 | 2016-10-10T20:42:32Z | 39,966,733 | <p>By disabling APP_DIRS you're forcing Django to look for your templates in the templates folder of your basedir regardless of where the app specifies them. This will break any plugins and also prevents you from namespacing templates. Its generally a bad idea. </p>
<p>DIRS is a list, so you can specify multiple locat... | 0 | 2016-10-10T21:04:29Z | [
"python",
"django"
] |
Flask API blocking OPTIONS requests | 39,966,446 | <p>I have an API written in Flask, when I am trying to use this API from AngularJS I am getting an 401 error unauthorized, same request with same credentials is working fine from Postman or HTTPie. This is happening with GET or POST request.</p>
<p>I noticed that the difference between HTTPie and Angular request is th... | 0 | 2016-10-10T20:43:25Z | 39,969,521 | <p>I figure out the problem, I solved after updating the plugin Flask-HTTPAuth.</p>
<p>I was having the version 2.2.1 and after moving to 3.2.1 it solved.</p>
<p>Tried the same on an instance of Amazon EC2 and solved with the same solution so I am quite sure it was this.</p>
| 0 | 2016-10-11T02:16:37Z | [
"python",
"angularjs",
"flask",
"restful-architecture"
] |
Pandas: Generating hourly data from daily data from csv | 39,966,456 | <p>I have a CSV file which has daily data as follows:</p>
<pre><code>DateTime Price
10/3/2016 0:00 2.84
9/30/2016 0:00 2.84
9/29/2016 0:00 2.98
9/28/2016 0:00 3.07
</code></pre>
<p>I wanted to create 24 hour price series for each day above and the hourly prices will be same as the daily price I read from t... | 0 | 2016-10-10T20:44:00Z | 39,966,507 | <p>try this:</p>
<pre><code>In [125]: df.set_index('DateTime').resample('H').pad()
Out[125]:
Price
DateTime
2016-09-28 00:00:00 3.07
2016-09-28 01:00:00 3.07
2016-09-28 02:00:00 3.07
2016-09-28 03:00:00 3.07
2016-09-28 04:00:00 3.07
2016-09-28 05:00:00 3.07
2016-09-28 06:00:00 3.07
2... | 0 | 2016-10-10T20:48:18Z | [
"python",
"pandas",
"dataframe"
] |
Selenium in Python - open every link within a drop down menu | 39,966,486 | <p>I'm new to Python, but I've been searching for the past hour about how to do this and this code almost works. I need to open up every category on a collapsing (dropdown) menu, and then Ctrl+t every link within that now .active class. The browser opens and all the categories open as well, but I'm not getting any of ... | 1 | 2016-10-10T20:46:32Z | 39,968,427 | <p>None of the links in those categories are not found because the css selector for the links is incorrect. Remove the <code>></code> in <code>li.active > a[href*='ProductPage']</code>. Why ? <code>p > q</code> gives you the immediate children of p. Space or "p q" gives you all the "q" inside p. The links you ... | 0 | 2016-10-10T23:46:18Z | [
"python",
"selenium"
] |
SQLAlchemy: deny column copy for multiple one-to-manies | 39,966,503 | <p>I've had a set of relationships running SQLAlchemy 0.9.10 in production for over a year and I'm looking to upgrade to 1.0+. All the tests pass after simply upgrading the package, however, new warnings are now being logged.</p>
<blockquote>
<p>SAWarning: relationship 'A.c' will copy column test_c.a_id to column
... | 0 | 2016-10-10T20:48:12Z | 39,967,792 | <p>Your problem comes from the fact you have two relationships that can modify <code>A.id</code>, which in turn stems from the fact that you've named it as part of two separate relationships. Whereas technically SQL allows you to do this, SQLAlchemy is more rigid in the patterns that it allows you to model.</p>
<p>The... | 0 | 2016-10-10T22:36:27Z | [
"python",
"postgresql",
"sqlalchemy"
] |
Invalid XML code generated by web service | 39,966,513 | <p>It seems like the <code>@service.xml</code> decorator is broken in <a href="http://web2py.com/books/default/chapter/29/10/services#Remote-procedure-calls" rel="nofollow">web services RPC</a>.</p>
<pre><code>@service.xml
def concat(a, b):
return a + b
</code></pre>
<p>The result is:</p>
<pre><code>>>>... | 0 | 2016-10-10T20:48:36Z | 39,978,876 | <p>I think it is just a bad example in the book. To produce valid XML, the function should return a list or dictionary (or an object with a <code>.as_list</code>, <code>.as_dict</code>, or <code>.custom_xml</code> method). For example:</p>
<pre><code>@service.xml
def concat(a, b):
return dict(result=a + b)
</code>... | 1 | 2016-10-11T13:51:43Z | [
"python",
"xml",
"python-2.7",
"web-services",
"web2py"
] |
Sortable Kivy List | 39,966,541 | <p>I'm creating a Kivy/Python app that generates a formatted report. The report itself is generated with pandas dataframes and then written to Excel. I'd like to add something to the UI that would allow users to apply custom sorting to the report.</p>
<p>So, for instance, if the dataframe has a "Category" field with v... | 0 | 2016-10-10T20:50:23Z | 39,986,069 | <p>Store the data inside a <a href="https://kivy.org/docs/api-kivy.properties.html#kivy.properties.ListProperty" rel="nofollow">list property</a>.</p>
<p>Create a table out of a grid layout, on which you would like to show the content of the <code>data</code> list. The headers of the table would be buttons that do som... | 0 | 2016-10-11T20:22:51Z | [
"python",
"pandas",
"kivy"
] |
ValueError: If using all scalar values, you must pass an index | 39,966,543 | <p>I have the following code:</p>
<pre><code>import datetime
import MySQLdb as mdb
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import pandas as pd
import pprint
import statsmodels.tsa.stattools as ts
from pandas.stats.api import ols
if __name__ == "__main__":
# Connect to... | 1 | 2016-10-10T20:50:50Z | 39,967,491 | <p>The problem is that when you use the <code>DataFrame</code> constructor:</p>
<pre><code>pd.DataFrame({m: eurusd.interpolate(method=m) for m in methods})
</code></pre>
<p>the value for each <code>m</code> is a <code>DataFrame</code>, which will be interpreted as a scalar value, which is admittedly confusing. This c... | 1 | 2016-10-10T22:06:59Z | [
"python",
"pandas",
"quantitative-finance"
] |
Creating time stamps using .format() | 39,966,552 | <p>Basically in this assignment we have to create a time, based on values of ran(hour,min):. Below I will post the code I have and then the error message I receive. Is my code just really bad or there something I'm missing? What does it mean by "Can't convert 'int' object to str implicitly.</p>
<pre><code>def show_tim... | -1 | 2016-10-10T20:51:41Z | 39,966,620 | <p>In the following line:</p>
<pre><code>if(min<10):
min = "0"+min
</code></pre>
<p>you are attempting to concatenate a string and an integer, which python cannot do. To convert a string to an int, use int(str), and to convert an int to a string, use str(int)</p>
| 0 | 2016-10-10T20:56:12Z | [
"python"
] |
Creating time stamps using .format() | 39,966,552 | <p>Basically in this assignment we have to create a time, based on values of ran(hour,min):. Below I will post the code I have and then the error message I receive. Is my code just really bad or there something I'm missing? What does it mean by "Can't convert 'int' object to str implicitly.</p>
<pre><code>def show_tim... | -1 | 2016-10-10T20:51:41Z | 39,966,642 | <p>The reason you are getting this error is because you are concatenating <code>"0"</code> (a string) with <code>min</code>, which is an integer.</p>
<pre><code>>>> '0' + 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Can't convert 'int' object to str implici... | 0 | 2016-10-10T20:57:58Z | [
"python"
] |
Creating time stamps using .format() | 39,966,552 | <p>Basically in this assignment we have to create a time, based on values of ran(hour,min):. Below I will post the code I have and then the error message I receive. Is my code just really bad or there something I'm missing? What does it mean by "Can't convert 'int' object to str implicitly.</p>
<pre><code>def show_tim... | -1 | 2016-10-10T20:51:41Z | 39,966,656 | <p>I think you use format incorrectly and you cannot concatenate 'str' and 'int' objects (min = "0"+min). I think this works:</p>
<pre><code>def show_time(hour,min):
if(hour > 12):
hour = hour -12
if(min < 10):
min = "0" + str(min)
print "{}:{}".format(hour, min)
</code></pre>
| 0 | 2016-10-10T20:59:09Z | [
"python"
] |
Calculating subtotals in pandas pivot_table with MultiIndex | 39,966,663 | <p>I have the following raw data, in a dataframe:</p>
<pre><code> BROKER VENUE QUANTITY
0 BrokerA Venue_1 300
1 BrokerA Venue_2 400
2 BrokerA Venue_2 1400
3 BrokerA Venue_3 800
4 BrokerB Venue_2 500
5 BrokerB Venue_3 1100
6 BrokerC Venue_1 1000
7 BrokerC Ven... | 1 | 2016-10-10T20:59:47Z | 39,966,738 | <p>You can create <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.MultiIndex.from_arrays.html" rel="nofollow"><code>MultiIndex.from_arrays</code></a> for <code>df1</code>, <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> it t... | 0 | 2016-10-10T21:04:48Z | [
"python",
"pandas"
] |
Django Custom Auth Migration | 39,966,691 | <p>I was trying to alter something on my user model in django and in the process I used makemigration to generate the migration file for it. But then decided against the whole thing, but now I have an unmigrated migration file located somewhere and I can't find it. I don't have an auth migrations folder in my app and I... | 0 | 2016-10-10T21:01:45Z | 39,967,078 | <p>You can either delete the table manually or inspect all migrations with:</p>
<pre><code>./manage.py showmigrations my_app
</code></pre>
| 0 | 2016-10-10T21:32:31Z | [
"python",
"django"
] |
Install cx_oracle on solaris 11 sparc | 39,966,698 | <p>Most of the cx_Oracle 5.2.1 version builds are for Windows and Linux. How do I install/get an install for a Solaris 11 Sparc?</p>
<p>I tried to install using the following: cx_Oracle-5.2.1.tar.gz from sourceforge.net
But resulted in the following error:</p>
<pre><code>/tmp/cx_Oracle-5.2.1$ python setup.py build
ru... | 0 | 2016-10-10T21:01:56Z | 39,978,837 | <p>I do not know the exact reason for the error you are getting. It looks, however, like the "cc" compiler is not installed. You should be able to find that package and install it. Or you will need to adjust your configuration to use gcc instead. This link may help:</p>
<p><a href="http://www.unix.com/solaris/114262-c... | 0 | 2016-10-11T13:50:13Z | [
"python",
"python-2.7",
"solaris",
"cx-oracle"
] |
How to iterate in a certain order? | 39,966,707 | <p>I'm wondering how I can iterate through a list in a certain order in Python.</p>
<p>Given the list, <code>lst = [1, 3, -1, 2]</code>, I want my function to iterate such that the next number iterated over will be the index of the value of the current number.</p>
<p>lst[0] -> lst[1] -> lst[3] -> lst[2]
1 -> 3 -> 2 -... | -3 | 2016-10-10T21:02:32Z | 39,966,824 | <p>There are a couple variables that you have not specified:</p>
<ol>
<li>What kind of error handling should this include? </li>
<li>Do you want it to loop indefinitely?</li>
</ol>
<p>Assuming that the respective answers are "None" and "Yes", here's one way of doing it:</p>
<pre><code>def create_iter(arr):
i = 0... | 3 | 2016-10-10T21:13:07Z | [
"python",
"loops",
"for-loop",
"iteration",
"next"
] |
How to iterate in a certain order? | 39,966,707 | <p>I'm wondering how I can iterate through a list in a certain order in Python.</p>
<p>Given the list, <code>lst = [1, 3, -1, 2]</code>, I want my function to iterate such that the next number iterated over will be the index of the value of the current number.</p>
<p>lst[0] -> lst[1] -> lst[3] -> lst[2]
1 -> 3 -> 2 -... | -3 | 2016-10-10T21:02:32Z | 39,966,892 | <p>Given that you check that each value is within the list except that you must have an end of list condition, then you would have</p>
<pre><code>index = 0
while True:
newindex = mylist[index]
if newindex >= len(mylist):
break
elif newindex == index:
break
else:
index = ne... | 0 | 2016-10-10T21:18:21Z | [
"python",
"loops",
"for-loop",
"iteration",
"next"
] |
How to open a window by clicking on a specific point on a chart? | 39,966,763 | <p>I have the task to build up an interactive plot which i have already done more or less. But now I am supposed to give specific information about a point in a graph for example P(8|6) and by clicking on this point there should open a new window with specific information. Adding the information to the window wont be t... | 0 | 2016-10-10T21:06:46Z | 39,990,158 | <p>The answer is qwt! Study the documentation and examples for that project like your life depended on it, and you will find exactly what you need.</p>
<p>I wrote up a pretty complete example a year or so ago; but it is in C++; converting it to python should be pretty straight forward.</p>
<p><a href="https://github... | 0 | 2016-10-12T03:42:19Z | [
"python",
"qt",
"window",
"new-window"
] |
ODBC access from Mac install of Python to Access database installed in Parallels | 39,966,839 | <p>I want to link my Python packages to my Access database, but I get this error. I use python 2.7.12 (shell).</p>
<pre><code>import pypyodbc
#create connection
con = pypyodbc.connect('DRIVER={Microsoft Access-Treiber (*.mdb)};UID=admin;UserCommitSync=Yes;Threads=3;SafeTransactions=0;PageTimeout=5;MaxScanRows=8;MaxBu... | 0 | 2016-10-10T21:14:21Z | 40,006,328 | <p>If you are running Python on the Mac side then you need to use a driver that is compatible with macOS. The <code>Microsoft Access-Trebier (*.mdb)</code> ODBC driver is a Windows DLL (ODBCJT32.DLL) and I doubt very much that the Mac version of Python can use it.</p>
<p>You may be interested in the related question h... | 0 | 2016-10-12T18:56:51Z | [
"python",
"osx",
"python-2.7",
"ms-access",
"pypyodbc"
] |
importing from another folder in virtualenv | 39,966,967 | <p>I'm following the <a href="http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-i-hello-world" rel="nofollow">Flask Mega Tutorial</a>, and I'm running into an issue once I get to the second part and restructure my folder structure to match theirs, I cannot import Flask.</p>
<p>My current folder structur... | 0 | 2016-10-10T21:24:29Z | 39,967,717 | <p>I think something went wrong in your execution environment. Here are some explanations.</p>
<h3>The virtualenv</h3>
<p>See the documentation of <a href="https://virtualenv.pypa.io/en/stable/userguide/" rel="nofollow">virtualenv</a></p>
<p>If you have followed the tutorial:</p>
<ul>
<li>The <code>flask</code> dir... | 1 | 2016-10-10T22:29:33Z | [
"python",
"flask",
"pip",
"virtualenv"
] |
Call function from python with tuple return in c | 39,966,982 | <p>I'm trying to call a python function from my C script. I success to return a double variable from the python function and print it in my C script. The problem I have now is that I need to return multiple variables (tuple) from python. How can I success that? My code with a single variable return is as follows: </p>
... | 0 | 2016-10-10T21:25:39Z | 39,967,681 | <p><a href="http://stackoverflow.com/questions/23200484/pyarg-parsetuple-on-arbitrary-tuples">With a small caveat</a>, you can use <a href="https://docs.python.org/3/c-api/arg.html#c.PyArg_ParseTuple" rel="nofollow"><code>PyArg_ParseTuple</code></a> to take apart the tuple returned by the function you call. </p>
<p>Th... | 1 | 2016-10-10T22:25:50Z | [
"python",
"c"
] |
I'm getting an List index out of range error for an index that exist | 39,967,037 | <p>Im using feed parser to obtain rss objects. When I run </p>
<pre><code>live_leak.links
</code></pre>
<p>I get</p>
<pre><code>[{'type': 'text/html', 'rel': 'alternate', 'href':
'http://www.liveleak.com/view?i=abf_1476121939'},
{'type': 'application/x-shockwave-flash', 'rel': 'enclosure', 'href':
'http://www.li... | 4 | 2016-10-10T21:29:35Z | 39,967,086 | <p>You can index <strong>live_leak</strong>, but <strong>live_leak.links</strong> appears to be some other type of construct that returns the elements of <strong>live_leak</strong>. Try <strong>live_leak[1]</strong>, perhaps?</p>
| 0 | 2016-10-10T21:33:16Z | [
"python",
"rss",
"feedparser"
] |
I'm getting an List index out of range error for an index that exist | 39,967,037 | <p>Im using feed parser to obtain rss objects. When I run </p>
<pre><code>live_leak.links
</code></pre>
<p>I get</p>
<pre><code>[{'type': 'text/html', 'rel': 'alternate', 'href':
'http://www.liveleak.com/view?i=abf_1476121939'},
{'type': 'application/x-shockwave-flash', 'rel': 'enclosure', 'href':
'http://www.li... | 4 | 2016-10-10T21:29:35Z | 39,967,124 | <p>One is looking for links under live_leak the other is just looking at live_leak itself.</p>
<p>for example:
live_leak[1] </p>
<p>should return:
[{'type': 'application/x-shockwave-flash', 'rel': 'enclosure', 'href':
'<a href="http://www.liveleak.com/e/abf_1476121939" rel="nofollow">http://www.liveleak.com/e/abf_14... | 0 | 2016-10-10T21:36:33Z | [
"python",
"rss",
"feedparser"
] |
Why does django date filter gives me entries from the next day as welll | 39,967,155 | <p>I am trying to access a database which has say two entries for 2016,9,25 and two entries for 2016,9,26, each of those entries have different time... I view them by listing each of them using the task.start_time in my template following is the list that I get</p>
<pre><code>TASK Task.title du... | 1 | 2016-10-10T21:38:52Z | 39,967,350 | <p>According to the <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#date" rel="nofollow">Django QuerySet reference for <code>date</code></a>:</p>
<blockquote>
<p>When <code>USE_TZ</code> is True, fields are converted to the current time zone before filtering.</p>
</blockquote>
<p>Given that bo... | 2 | 2016-10-10T21:55:15Z | [
"python",
"django",
"sqlite"
] |
Propagating arguments to decorator which combines other decorators | 39,967,240 | <p>I have a scenario like:</p>
<pre><code>@decorator_one(1)
@foo
@bar
def my_decorated_func():
pass
</code></pre>
<p>I am trying to condense this into something like:</p>
<pre><code>@my_custom_decorator(1)
def my_decorated_func():
pass
</code></pre>
<p>This is straightforward if I have decorators that do no... | 1 | 2016-10-10T21:46:11Z | 39,967,298 | <p><code>@decorator_one(1)</code> means that there is a callable that returns a decorator; call it a decorator <em>factory</em>. <code>decorator_one(1)</code> returns the decorator that is then applied to the function.</p>
<p>Just pass on the arguments from your own decorator factory:</p>
<pre><code>def my_custom_dec... | 4 | 2016-10-10T21:50:40Z | [
"python",
"decorator",
"python-decorators"
] |
Propagating arguments to decorator which combines other decorators | 39,967,240 | <p>I have a scenario like:</p>
<pre><code>@decorator_one(1)
@foo
@bar
def my_decorated_func():
pass
</code></pre>
<p>I am trying to condense this into something like:</p>
<pre><code>@my_custom_decorator(1)
def my_decorated_func():
pass
</code></pre>
<p>This is straightforward if I have decorators that do no... | 1 | 2016-10-10T21:46:11Z | 39,968,096 | <p>Yes, you need a decorator factory.</p>
<p>I found the solution using a class more attractive because it separates the factory and the decorator:</p>
<pre><code>class my_custom_decorator(object):
__init__(self, *args, **kwargs): # the factory
self.args = args
self.kwargs = kwargs
__call__... | 0 | 2016-10-10T23:09:24Z | [
"python",
"decorator",
"python-decorators"
] |
Virtualenv within single executable | 39,967,250 | <p>I currently have an executable file that is running Python code inside a zipfile following this: <a href="https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/" rel="nofollow">https://blogs.gnome.org/jamesh/2012/05/21/python-zip-files/</a></p>
<p>The nice thing about this is that I release a single file conta... | 0 | 2016-10-10T21:46:44Z | 39,967,509 | <p>You can create a bash script that creates the virtual env and runs the python scripts aswell. </p>
<pre><code>!#/bin/bash
virtualenv .venv
.venv/bin/pip install <python packages>
.venv/bin/python script
</code></pre>
| 0 | 2016-10-10T22:08:21Z | [
"python",
"linux",
"virtualenv",
"executable"
] |
Python: Remove a portion of a string from a list of strings | 39,967,304 | <p>I used xlrd to extract a column from an excel sheet to make into a list.</p>
<pre><code>from xlrd import open_workbook
book = xlrd.open_workbook("HEENT.xlsx").sheet_by_index(0)
med_name = []
for row in sheet.col(2):
med_name.append(row)
med_school = []
for row in sheet.col(3):
med_school.append(row)
print(m... | 0 | 2016-10-10T21:51:27Z | 39,967,409 | <p>Use the given separator to cut off the head of each string. Check first to make sure it has "Class", so we know the comma-space is there.</p>
<pre><code>med_school = ["text:'Class of 2016, University of Maryland School of Medicine'",
"text:'Class of 2015, Johns Hopkins University School of Medicine... | 1 | 2016-10-10T22:00:46Z | [
"python",
"xlrd"
] |
Python: Remove a portion of a string from a list of strings | 39,967,304 | <p>I used xlrd to extract a column from an excel sheet to make into a list.</p>
<pre><code>from xlrd import open_workbook
book = xlrd.open_workbook("HEENT.xlsx").sheet_by_index(0)
med_name = []
for row in sheet.col(2):
med_name.append(row)
med_school = []
for row in sheet.col(3):
med_school.append(row)
print(m... | 0 | 2016-10-10T21:51:27Z | 39,967,440 | <p>The <code>xlrd</code> does not return you strings, it returns you instances of a class called <code>Cell</code>. This has a property <code>value</code> that contains the string you are seeing. </p>
<p>To modify these simply:</p>
<pre><code>for cell in med_school:
cell.value = cell.value[:15]
</code></pre>
<... | 4 | 2016-10-10T22:02:40Z | [
"python",
"xlrd"
] |
Python Nested List Comprehension Error | 39,967,377 | <p>I'm trying to convert a normal nested iteration into a nest list comp and I'm having trouble.</p>
<pre><code>for k in r.json()['app_list']:
for i in titles:
if k['name'] == i['name'] and k['platform'] == i['platform']:
array.append(session.get(k['api_url'], headers=headers).json())
return ar... | -1 | 2016-10-10T21:57:28Z | 39,967,401 | <p>You have your nesting order wrong and you forgot to get the <code>'app_list'</code> key from the <code>r.json()</code> dictionary.</p>
<p>List comprehension loops are still listed in the same order, left to right as you nest them. In other words, use the <em>same order</em> as your original nested <code>for</code> ... | 2 | 2016-10-10T22:00:30Z | [
"python",
"list-comprehension"
] |
Python elif not working in order I want | 39,967,410 | <p><code>Transaction_Code</code> == <code>"W"</code>, <code>"w"</code>, <code>"D"</code> or <code>"d"</code></p>
<p>if not, it should be running <code>Process_Invalid_Code(Previous_Balance)</code></p>
<p>What is happening, however is if input for <code>Transaction_Code</code> != <code>"W"</code>, <code>"w"</code>, <c... | 0 | 2016-10-10T22:00:53Z | 39,967,634 | <p>Since all of your desired actions need <code>Previous_Balance</code> you must ask for it in any case:</p>
<pre><code>def main():
# never used, lets ask anyway
Name = input("What is your name? ")
# we need this information at a minimum
Previous_Balance = float(input("What is your previous balance? ... | 4 | 2016-10-10T22:21:19Z | [
"python"
] |
Python elif not working in order I want | 39,967,410 | <p><code>Transaction_Code</code> == <code>"W"</code>, <code>"w"</code>, <code>"D"</code> or <code>"d"</code></p>
<p>if not, it should be running <code>Process_Invalid_Code(Previous_Balance)</code></p>
<p>What is happening, however is if input for <code>Transaction_Code</code> != <code>"W"</code>, <code>"w"</code>, <c... | 0 | 2016-10-10T22:00:53Z | 39,967,764 | <p>You may want to also try and use raw_input() as oppose to input() where necessary or cast the output using <code>variable_name</code> to get rid of tracback error.</p>
| 1 | 2016-10-10T22:33:44Z | [
"python"
] |
Using Pandas to Create DateOffset of Paydays | 39,967,460 | <p>I'm trying to use Pandas to create a time index in Python with entries corresponding to a recurring payday. Specifically, I'd like to have the index correspond to the first and third Friday of the month. Can somebody please give a code snippet demonstrating this?</p>
<p>Something like:</p>
<pre><code>import pandas... | 2 | 2016-10-10T22:04:43Z | 39,967,582 | <p>try this:</p>
<pre><code>In [6]: pd.date_range("2016-10-10", periods=26, freq='WOM-1FRI').union(pd.date_range("2016-10-10", periods=26, freq='WOM-3FRI'))
Out[6]:
DatetimeIndex(['2016-10-21', '2016-11-04', '2016-11-18', '2016-12-02', '2016-12-16', '2017-01-06', '2017-01-20', '2017-02-03', '2017-02-17',
'2017-03-03'... | 2 | 2016-10-10T22:15:46Z | [
"python",
"pandas"
] |
Capture semantic version in django url | 39,967,532 | <p>I have the following url
<code>
http://localhost:8000/api/package/printf/release/v0.0.1
</code></p>
<p>I need to capture the version at the end. What is the right way for the same. The url regex that i have now is</p>
<p><code>
/package/(?P<pk>[a-z]+)/release/(?P<version[a-z]+)/$
</code></p>
<p>The seman... | 0 | 2016-10-10T22:11:04Z | 39,967,569 | <p>You may rely on negated character class <code>[^/]</code> (that matches any character but <code>/</code>) and also make the last <code>/</code> optional by adding a <code>?</code> (1 or 0 occurrences) quantifier after it:</p>
<pre><code>/package/(?P<pk>[^/]+)/release/(?P<version>[^/]+)/?$
</code></pre>
... | 1 | 2016-10-10T22:14:43Z | [
"python",
"regex",
"django"
] |
Capture semantic version in django url | 39,967,532 | <p>I have the following url
<code>
http://localhost:8000/api/package/printf/release/v0.0.1
</code></p>
<p>I need to capture the version at the end. What is the right way for the same. The url regex that i have now is</p>
<p><code>
/package/(?P<pk>[a-z]+)/release/(?P<version[a-z]+)/$
</code></p>
<p>The seman... | 0 | 2016-10-10T22:11:04Z | 39,967,762 | <p>Looks to me like you are close. Just need to tweak your regex a bit:</p>
<pre><code>/package/(?P<pk>[a-z]+)/release/(?P<version>v\d{1,2}\.\d{1,2}\.\d{1,2})/?$
</code></pre>
<p>This would match any version that has three digits, and each one being either 1 or 2 numbers. For example:</p>
<pre><code>v0.0... | 1 | 2016-10-10T22:33:20Z | [
"python",
"regex",
"django"
] |
does groupby concatenate the columns? | 39,967,540 | <p>i have a "1000 rows * 4 columns" DataFrame:</p>
<pre><code>a b c d
1 aa 93 4
2 bb 32 3
...
1000 nn 78 2
**[1283 rows x 4 columns]**
</code></pre>
<p>and I use groupby to group them based on 3 of the columns:</p>
<pre><code>df.groupby(['a','b','c']).sum()
print(df)
a b ... | -1 | 2016-10-10T22:11:54Z | 39,967,706 | <p>you can do it this way:</p>
<pre><code>df.groupby(['a','b','c'], as_index=False).sum()
</code></pre>
<p>or:</p>
<pre><code>df.groupby(['a','b','c']).sum().reset_index()
</code></pre>
| 1 | 2016-10-10T22:28:36Z | [
"python",
"pandas"
] |
Efficiently creating a Pandas DataFrame Column that contains the instance number of a value in another column | 39,967,568 | <p>Assume that you have a Pandas column with the following information:</p>
<pre><code>>> df
num
0 0
1 1
2 1
3 2
4 3
5 3
</code></pre>
<p>The column to the left of the num column is the index column.
I want to create an instance column that tells me what instance of num appears. This is t... | 1 | 2016-10-10T22:14:39Z | 39,967,617 | <p>try this:</p>
<pre><code>In [11]: df['instance'] = df.groupby('num').cumcount()+1
In [12]: df
Out[12]:
num instance
0 0 1
1 1 1
2 1 2
3 2 1
4 3 1
5 3 2
</code></pre>
| 1 | 2016-10-10T22:19:20Z | [
"python",
"pandas",
"dataframe"
] |
Efficiently creating a Pandas DataFrame Column that contains the instance number of a value in another column | 39,967,568 | <p>Assume that you have a Pandas column with the following information:</p>
<pre><code>>> df
num
0 0
1 1
2 1
3 2
4 3
5 3
</code></pre>
<p>The column to the left of the num column is the index column.
I want to create an instance column that tells me what instance of num appears. This is t... | 1 | 2016-10-10T22:14:39Z | 39,967,633 | <p>You can <code>groupby</code> on 'num' column and call <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.rank.html" rel="nofollow"><code>rank</code></a> with param <code>method=dense'</code>:</p>
<pre><code>In [5]:
df['instance'] = df.groupby('num').transform(lambda x: x.rank(method='dense... | 0 | 2016-10-10T22:21:11Z | [
"python",
"pandas",
"dataframe"
] |
Formatting loop for strings | 39,967,583 | <p>I'm having trouble formatting the strings below. Trying to keep the message centered with the borders, but having a hard time executing it. Below is what output I want and below that is my code I have so far. Note: I need to have a space on the left and right columns of the longest line and I need to utilize the spl... | 0 | 2016-10-10T22:15:51Z | 39,967,679 | <p>Split the string into separate lines, then center each line. Remember to either print each line immediately within the function, build up a list, or yield each line rather than returning after the first line. You can also determine and use a calculated width rather than a static value.</p>
<pre><code>def border_sig... | 2 | 2016-10-10T22:25:22Z | [
"python",
"function",
"python-3.x"
] |
Formatting loop for strings | 39,967,583 | <p>I'm having trouble formatting the strings below. Trying to keep the message centered with the borders, but having a hard time executing it. Below is what output I want and below that is my code I have so far. Note: I need to have a space on the left and right columns of the longest line and I need to utilize the spl... | 0 | 2016-10-10T22:15:51Z | 39,967,710 | <p>Quick sample to consider, not production ready code:</p>
<pre><code>def border_sign(note):
rows = note.splitlines()
mlen = len(max(rows, key=len))
print "+" + "-" * (2+mlen) + "+"
for row in rows:
print ("| {:^"+str(mlen)+"} |").format(row)
print "+" + "-" * (2+mlen) + "+"
</code></pre>
| 1 | 2016-10-10T22:29:01Z | [
"python",
"function",
"python-3.x"
] |
Formatting loop for strings | 39,967,583 | <p>I'm having trouble formatting the strings below. Trying to keep the message centered with the borders, but having a hard time executing it. Below is what output I want and below that is my code I have so far. Note: I need to have a space on the left and right columns of the longest line and I need to utilize the spl... | 0 | 2016-10-10T22:15:51Z | 39,968,980 | <pre><code>def border_sign(x):
splitted = x.splitlines()
M = max(map(len,splitted))
horiz = '+-%s-+' % (M*'-')
patiz = '| {0: ^%d} |' % M
print(horiz,*map(patiz.format,splitted), horiz, sep='\n')
border_sign("STOP\nDANGER AHEAD\nDrive safely!")
</code></pre>
<p><code>patiz.format</code> is a func... | 0 | 2016-10-11T01:03:44Z | [
"python",
"function",
"python-3.x"
] |
create a graph with too many edges | 39,967,599 | <p>I have 100 nodes and 4950 edges. What is the fastest way to create a graph in Python (not planning at all to visualize or draw it) so that I can have access to node information so that I would need what each item in the 2d matrix mean by saying node 1 is connected to node 3? (also I don't need to save it as matrix).... | 0 | 2016-10-10T22:18:01Z | 39,967,984 | <p>I think generating a GML file for the precise purpose of reusing in Matlab is probably fine. This question has some more information about that.</p>
<p><a href="http://stackoverflow.com/questions/15918791/convert-gml-file-to-adjacency-matrix-in-matlab#15919696">Convert GML file to adjacency matrix in matlab</a></p>... | 1 | 2016-10-10T22:57:19Z | [
"python",
"graph",
"networkx"
] |
"type" object is not subscriptable error in Python Selenium | 39,967,608 | <p>I'm a newbie to Python Selenium environment. This is my piece of code.</p>
<pre><code>from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import unittest
class LoginTest(unittest.TestCase):
def setUp(self):
self.driver= webdriver.Firefox()
self.driver.get(... | -3 | 2016-10-10T22:18:30Z | 39,967,658 | <p>You're trying to index a <code>WebDriverWait</code> object instead of initializing it. </p>
<p>You should replace all the:</p>
<pre><code>WebDriverWait[driver, 10]
</code></pre>
<p>with</p>
<pre><code>WebDriverWait(driver, 10)
# ^ ^
</code></pre>
<hr>
<p>Reference:</p>
<p><a href="http://s... | 2 | 2016-10-10T22:22:50Z | [
"python",
"python-3.x",
"selenium"
] |
ValueError: need more than 3 values to unpack when using optimize.minimize | 39,967,614 | <p>I'm pretty new to python and I got stuck on this:
I'd like to use <code>scipy.optimize.minimize</code> to maximize a function and I'm having some problem with the extra arguments of the function I defined.</p>
<p>I looked for a solution in tons of answered questions but I can't find anything that solves my problem.... | 0 | 2016-10-10T22:19:17Z | 39,967,745 | <p>Your error occurs here:</p>
<pre><code>def min_pears_function(a,exp):
# XXX: This is your error line
(b,c,d,e)=a
return (1-(pearsonr(b + exp[0] * c + exp[1] * d + exp[2],e)[0]))
</code></pre>
<p>This is because:</p>
<ul>
<li>the initial value you pass to <code>optimize.minimize</code> is <code>guessPF... | 0 | 2016-10-10T22:31:47Z | [
"python"
] |
What is this doing in the Python lambda function? | 39,967,638 | <p>In the following Python script where "aDict" is a dictionary, what does "_: _[0]" do in the lambda function?</p>
<pre><code>sorted(aDict.items(), key=lambda _: _[0])
</code></pre>
| -1 | 2016-10-10T22:21:26Z | 39,967,759 | <p>In Python, lambda is used to create an anonymous function. The first underscore in your example is simply the argument to the lambda function. After the colon (i.e. function signature), the <code>_[0]</code> retrieves the first element of the variable <code>_</code>.</p>
<p>Admittedly, this can be confusing; the la... | 2 | 2016-10-10T22:33:05Z | [
"python",
"sorting",
"lambda",
"key"
] |
What is this doing in the Python lambda function? | 39,967,638 | <p>In the following Python script where "aDict" is a dictionary, what does "_: _[0]" do in the lambda function?</p>
<pre><code>sorted(aDict.items(), key=lambda _: _[0])
</code></pre>
| -1 | 2016-10-10T22:21:26Z | 39,967,898 | <p>In Python <code>_</code> (underscore) is a valid identifier and can be used as a variable name, e.g.</p>
<pre><code>>>> _ = 10
>>> print(_)
10
</code></pre>
<p>It can therefore also be used as the name of an argument to a lambda expression - which is like an unnamed function.</p>
<p>In your exam... | 2 | 2016-10-10T22:47:38Z | [
"python",
"sorting",
"lambda",
"key"
] |
What is this doing in the Python lambda function? | 39,967,638 | <p>In the following Python script where "aDict" is a dictionary, what does "_: _[0]" do in the lambda function?</p>
<pre><code>sorted(aDict.items(), key=lambda _: _[0])
</code></pre>
| -1 | 2016-10-10T22:21:26Z | 39,968,068 | <p>Lets pick that apart.</p>
<p>1) Suppose you have a dict, di:</p>
<pre><code>di={'one': 1, 'two': 2, 'three': 3}
</code></pre>
<p>2) Now suppose you want each of its key, value pairs:</p>
<pre><code> >>> di.items()
[('three', 3), ('two', 2), ('one', 1)]
</code></pre>
<p>3) Now you want to sort them (si... | 1 | 2016-10-10T23:05:37Z | [
"python",
"sorting",
"lambda",
"key"
] |
Exposing a class with a constructor containing a nested private class in constructor using Boost Python | 39,967,640 | <p>I'm new to Boost Python and I'm looking to expose a class that looks like this: </p>
<pre><code>///Header File structure
class A
{ public:
A();
~A();
void B();
private:
class Impl;
std::unique_ptr Impl impl_;
};
///Class Implementation
class A::Impl
{
public:
void C();
}
A::A():... | -1 | 2016-10-10T22:21:29Z | 39,967,689 | <p>The whole point of the pimpl idiom is that it's private and completely transparent to the users of the class. You don't expose it.</p>
<p>What you do need to do is make it clear that <code>A</code> isn't copyable:</p>
<pre><code>class_<A, noncopyable>("A", init<>())
.def("B", &A::B)
;
</code></... | 1 | 2016-10-10T22:26:59Z | [
"python",
"c++",
"class",
"boost",
"boost-python"
] |
Python - Selenium : Scroll down not working because of PopUp | 39,967,680 | <p>I am writing a python script using selenium to login to Facebook and then do some scrapping. For that purpose, <strong>I have to scroll down to the bottom of the page. I think the pop that you can see in the picture is the cause of this.</strong>
Here is the snippet of code which does the following thing</p>
<pre><... | 0 | 2016-10-10T22:25:47Z | 39,967,846 | <p>Solved.</p>
<p>Adding this will resolve and woulndt allow any such pop ups.</p>
<pre><code> chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
#driver = webdriver.Chrome(chrome_options=... | 1 | 2016-10-10T22:43:09Z | [
"python",
"facebook",
"selenium"
] |
AttributeError: 'module' object has no attribute 'openssl_md_meth_names' | 39,967,742 | <p>I am calling a python script from another python script,irrespective of the output the python script I am calling I get the following error in <code>stderr</code>,I googled but couldn't find anything concrete,am clueless as to why am getting this error?does anyone have any idea on how to fix it?</p>
<pre><code>Trac... | 0 | 2016-10-10T22:31:35Z | 39,967,801 | <p>Try to run <code>brew cleanup</code> and after that <code>brew postinstall python</code>. </p>
<p>For more info see <a href="https://github.com/Homebrew/legacy-homebrew/issues/36346" rel="nofollow">this thread</a></p>
| 0 | 2016-10-10T22:37:39Z | [
"python"
] |
python argparse in separate function inside a class and calling args from init | 39,967,787 | <p>I have a question regarding passing args to variables inside <strong>init</strong></p>
<p>Here are my working version of code.</p>
<pre><code>class A:
def __init__(self):
self.id = args.id
self.pw = args.pw
self.endpoint = args.endpoint
def B:
..do something..
if __name__ == "__main__... | 0 | 2016-10-10T22:36:00Z | 39,967,973 | <p>So in the first case, you must be doing</p>
<pre><code>if __name__ ...
....
args = parser.parse_args()
a = A()
</code></pre>
<p>The <code>A.__init__</code> can see <code>args</code> because it is global.</p>
<p>I'm don't see why you'd want to make the argparse code part of <code>A</code>; you don't want it to run... | 1 | 2016-10-10T22:56:29Z | [
"python",
"function",
"class",
"argparse"
] |
How to convert a string into a list without including a specific character plus without using replace and split methods? | 39,967,795 | <p>Let's say you have:</p>
<pre><code>x = "1,2,13"
</code></pre>
<p>and you want to achieve:</p>
<pre><code>list = ["1","2","13"]
</code></pre>
<p>Can you do it without the split and replace methods?</p>
<p>What I have tried:</p>
<pre><code>list=[]
for number in x:
if number != ",":
list.append(number... | 0 | 2016-10-10T22:36:56Z | 39,967,919 | <p>Here is a way using that assumes integers using <code>itertools</code>:</p>
<pre><code>>>> import itertools
>>> x = "1,88,22"
>>> ["".join(g) for b,g in itertools.groupby(x,str.isdigit) if b]
['1', '88', '22']
>>>
</code></pre>
<p>Here is a method that uses traditional looping:... | 2 | 2016-10-10T22:50:01Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.