title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
How to call a certain function inside an if statement in python? | 38,576,369 | <p>I am relatively new to python, in my foundation year I learned BBC BASIC which is pretty basic and I acquired many bad habits there.
I learned python with the aid of codecademy, however, how can I call a function inside an if statement? In my first if statement I called the function <code>mainMenu(menu)</code>, how... | -3 | 2016-07-25T19:57:59Z | 38,576,416 | <p>As in C++, the function must be defined before the code area where it is used. Thus, your code should read:</p>
<pre><code>def mainMenu():
print "------------------------------------------------"
print "Select one of this options"
print "1. Check Balance"
print "2. Withdraw Money"
print "3. Dep... | 1 | 2016-07-25T20:01:34Z | [
"python",
"function"
] |
How to call a certain function inside an if statement in python? | 38,576,369 | <p>I am relatively new to python, in my foundation year I learned BBC BASIC which is pretty basic and I acquired many bad habits there.
I learned python with the aid of codecademy, however, how can I call a function inside an if statement? In my first if statement I called the function <code>mainMenu(menu)</code>, how... | -3 | 2016-07-25T19:57:59Z | 38,576,441 | <pre><code>print "Hello ! Welcome to JD's bank"
print
print "Insert bank card and press any key to procede"
print
raw_input()
def mainMenu():
print "------------------------------------------------"
print "Select one of this options"
print "1. Check Balance"
print "2. Withdraw Money"
print "3. Dep... | 4 | 2016-07-25T20:02:36Z | [
"python",
"function"
] |
Selectively convert list items in python | 38,576,377 | <p>So I have a list of lists in Python, where all the items are supposed to be numbers except when the list has three items. In this case, the last item is supposed to remain a string which I concert from a string. The code is as follows:</p>
<pre><code>special_ops = [6]
program = [ line for line in temp.split(";") ]
... | -2 | 2016-07-25T19:58:33Z | 38,576,584 | <pre><code>>>> a = [x.split(',') for x in temp.split(';')]
>>> [[int(x) for x in lst] if len(lst)==2 else [int(lst[0]), int(lst[1]), lst[2]] for lst in a]
[[0, 1], [2, 1], [2, 0], [3, 2], [6, 1, 'a string']]
</code></pre>
<h3>How it works</h3>
<p>The first statement just splits up temp in a convenie... | 1 | 2016-07-25T20:10:58Z | [
"python"
] |
Pyspark does not use python3 in yarn cluster mode, even with PYSPARK_PYTHON=python3 | 38,576,397 | <p>I have set PYSPARK_PYTHON=python3 in spark-env.sh using ambari, and when I try 'pyspark' in commandline, it runs with python 3.4.3. However, when I submit a job using yarn cluster mode, it runs using python 2.7.9. How do I make it use python3?</p>
| 0 | 2016-07-25T19:59:56Z | 38,576,724 | <p>You need to give full path of python3 like:</p>
<pre><code>subprocess.call(['export PYSPARK_PYTHON=/usr/local/bin/python2.7'],shell=True)
</code></pre>
| 0 | 2016-07-25T20:19:41Z | [
"python",
"apache-spark",
"pyspark",
"ambari"
] |
Trying to exec Python script using PHP | 38,576,448 | <p>I'm trying to exec python script using PHP, but python seems to dont work when exec by php.</p>
<p>I tryied this code to test</p>
<pre><code>$cmdResult = shell_exec("ls & /usr/local/bin/python2.7 --version & echo done");
</code></pre>
<p>Returned:</p>
<pre><code>done
LICENSE
example.py
</code></pre>
<p>... | 1 | 2016-07-25T20:03:09Z | 38,594,890 | <p>In your shell command try using <code>&&</code> like so:</p>
<pre><code>ls && /usr/local/bin/python2.7 --version && echo done
</code></pre>
<p>so your code would read</p>
<pre><code>$cmdResult = shell_exec("ls && /usr/local/bin/python2.7 --version && echo done");
</code></p... | 1 | 2016-07-26T16:08:49Z | [
"php",
"python",
"bash"
] |
Unable to work with Django (python 2.7, OS X 10.11.1) | 38,576,461 | <p>I'm about to pull my hair out in frustration. Trying to start a Django project on my new iMac with OS X El Capital. Python 2.7 came installed on the computer, and it seems so was Django. However, I can't run django-admin. I've got Django installed on my laptop and I didn't have this much trouble. </p>
<p>Per the of... | 0 | 2016-07-25T20:04:01Z | 38,577,686 | <p>Try installing it in a virtualenv.</p>
<pre><code>virtualenv -p /usr/bin/python2.7 venv # create virtual environment
source venv/bin/activate # activate venv
pip install --upgrade Django==1.9.8 # install django in your venv
django-admin # should run django-admin from your venv
</code></pre>
<p>Running in a venv... | 1 | 2016-07-25T21:24:34Z | [
"python",
"django",
"osx",
"python-2.7"
] |
Python- np.mean() giving wrong means? | 38,576,480 | <p><strong>The issue</strong></p>
<p>So I have 50 netCDF4 data files that contain decades of monthly temperature predictions on a global grid. I'm using np.mean() to make an ensemble average of all 50 data files together while preserving time length & spatial scale, but np.mean() gives me two different answers. Th... | 7 | 2016-07-25T20:04:34Z | 38,576,857 | <p>In the line</p>
<pre><code>alltas[:,:,:,50] = np.mean(alltas,axis=3,dtype=np.float64)
</code></pre>
<p>the argument to <code>mean</code> should be <code>alltas[:,:,:,:50]</code>:</p>
<pre><code>alltas[:,:,:,50] = np.mean(alltas[:,:,:,:50], axis=3, dtype=np.float64)
</code></pre>
<p>Otherwise you are including th... | 8 | 2016-07-25T20:27:08Z | [
"python",
"numpy",
"mean"
] |
Return an object using its name in python | 38,576,495 | <p>So, I've create global objects that can be accessed by any method. Now I have to return the objects by a method like this.</p>
<pre><code>def get_my_obj (obj_name):
if obj_name == "abc": return abc
elif obj_name == "xyz": return xyz
elif obj_name == "def": return def
</code></pre>
<p>Is ther... | 0 | 2016-07-25T20:05:51Z | 38,576,655 | <p>Through the use of <code>globals()</code> in the appropriate file, it is entirely possible for achieve such an evil act.</p>
<pre><code># file1.py
abc = 'foo'
xyz = 'bar'
dfe = 'baz'
def get_my_obj(obj_name):
return globals()[obj_name]
# file2.py
from file1 import get_my_obj
print(get_my_obj('abc')) # '... | 3 | 2016-07-25T20:15:21Z | [
"python",
"object"
] |
Develop GUI window | 38,576,506 | <p>It needs to display my picture on the left and my first and last name along with birthdate on the right side. This is what I have so far, but it keeps giving me a TCL error saying "No such file or directory" when I have the file saved onto my computer. </p>
<pre><code>from tkinter import Tk,Label,PhotoImage,LEFT,RI... | -1 | 2016-07-25T20:06:29Z | 38,576,634 | <p>The problem has to do with the line: </p>
<pre><code>Justin=PhotoImage(file="Justin.gif")
</code></pre>
<p>Make sure that Justin.gif is located in the right place in the file hierarchy (same directory as the script itself) and is called 'Justin.gif' (capitalization sensitive).</p>
| 1 | 2016-07-25T20:13:45Z | [
"python",
"user-interface",
"tkinter"
] |
Checking if a user has been assigned a token in Django Restframework | 38,576,589 | <p>I am setting up token authentication for a site using Django Restframework and need to be able to have a user download their token, however the catch is that they much only be able to download their token once (similar to the Amazon AWS model). </p>
<p>In other words; is there a native way to check if a user has be... | 0 | 2016-07-25T20:11:26Z | 38,576,881 | <p>you can do this:</p>
<pre><code>from rest_framework.authtoken.models import Token
from django.conf import settings
token = Token.objects.create(user=settings.AUTH_USER_MODEL)
</code></pre>
<p>now you can just check if your given user has a token:</p>
<pre><code>user_with_token = Token.objects.get(user=user)
</cod... | 0 | 2016-07-25T20:28:54Z | [
"python",
"django",
"django-rest-framework",
"http-token-authentication"
] |
Checking if a user has been assigned a token in Django Restframework | 38,576,589 | <p>I am setting up token authentication for a site using Django Restframework and need to be able to have a user download their token, however the catch is that they much only be able to download their token once (similar to the Amazon AWS model). </p>
<p>In other words; is there a native way to check if a user has be... | 0 | 2016-07-25T20:11:26Z | 38,590,027 | <p>try use a django signal to create user token automatically, something like this on your models file.</p>
<pre><code>@receiver(post_save, sender=User)
def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
</code></pre>
| 0 | 2016-07-26T12:32:57Z | [
"python",
"django",
"django-rest-framework",
"http-token-authentication"
] |
Neo4j Bolt StatementResult to Pandas DataFrame | 38,576,674 | <p>Based on example from <a href="https://neo4j.com/developer/python/" rel="nofollow">Neo4j</a> </p>
<pre><code>from neo4j.v1 import GraphDatabase, basic_auth
driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
session = driver.session()
session.run("CREATE (a:Person {name:'Art... | 0 | 2016-07-25T20:16:48Z | 38,577,709 | <p>The best I can come up with is a list comprehension similar to yours, but less verbose:</p>
<pre><code>df = pd.DataFrame([r.values() for r in result], columns=result.keys())
</code></pre>
<p>The <a href="http://py2neo.org/v3/" rel="nofollow"><code>py2neo</code></a> package seems to be more suitable for DataFrames,... | 1 | 2016-07-25T21:26:38Z | [
"python",
"pandas",
"neo4j"
] |
Boxplot placed on time axis | 38,576,692 | <p>I want to place a series of (matplotlib) boxplots in a time axis. They are series of measurements taken on different days along a year. The dates are not evenly distributed and I am interested on the variation along time.</p>
<hr>
<h2>Easy version</h2>
<p>I have a pandas DataFrame with indexes and series of numbe... | 0 | 2016-07-25T20:17:38Z | 38,624,642 | <p>The desired output can be generated in two ways. But it is safe to keep in mind that <code>boxplots</code> plot ranges of a given field/column on the <code>y-axis</code> while keeping the name of the field/column on the <code>x-axis</code>. You could plot them horizontally. But the idea remains the same.</p>
<p>At ... | 2 | 2016-07-27T23:11:23Z | [
"python",
"datetime",
"pandas",
"matplotlib",
"boxplot"
] |
Boxplot placed on time axis | 38,576,692 | <p>I want to place a series of (matplotlib) boxplots in a time axis. They are series of measurements taken on different days along a year. The dates are not evenly distributed and I am interested on the variation along time.</p>
<hr>
<h2>Easy version</h2>
<p>I have a pandas DataFrame with indexes and series of numbe... | 0 | 2016-07-25T20:17:38Z | 38,630,536 | <p>So far, my best solution is to convert the units of the axis into a suitable <code>int</code> unit and plot everything accordingly. In my case, those are days. </p>
<pre><code>np.random.seed(12345)
data = np.array( [ np.random.normal( i, 1, 10 ) for i in range(3) ] )
dates = pd.to_datetime( [ '2015-06-01', '2015-06... | 0 | 2016-07-28T08:07:19Z | [
"python",
"datetime",
"pandas",
"matplotlib",
"boxplot"
] |
Memory error when reading nested textfiles into spark from S3 | 38,576,813 | <p>I'm trying to read around one million zipped text files into <code>spark</code> from <code>S3</code>. The zipped size of each file is between 50 MB and 80 MB. In all it's about 6.5 terabytes of data.</p>
<p>Unfortunately I'm running into an out of memory exception that I don't know how to resolve. Something as simp... | 3 | 2016-07-25T20:24:42Z | 38,731,548 | <p>The problem was that there were too many files. The solution seems to be to decrease the number of partitions by reading in a subset of files and coalescing them to a smaller number. You can't make the partitions too big though: 500 - 1000 MB files cause their own problems.</p>
| 0 | 2016-08-02T22:34:07Z | [
"python",
"apache-spark",
"amazon-s3",
"pyspark"
] |
Using dataframe in a class to filter results | 38,576,864 | <p>I've created a class to preprocess a document with pandas dataframes. However, I'm having trouble using filters within my class. My code is below:</p>
<pre><code>class Dataframe:
def __init__(self, my_dataframe):
self.my_dataframe = my_dataframe
self.my_dataframe = self.filter_priv()
def f... | 1 | 2016-07-25T20:27:47Z | 38,576,945 | <p>You're problem might be that you're using the variable "df" to initialize a Dataframe class, but the variable df hasn't been defined yet...</p>
| 0 | 2016-07-25T20:32:32Z | [
"python",
"python-2.7",
"pandas"
] |
Using dataframe in a class to filter results | 38,576,864 | <p>I've created a class to preprocess a document with pandas dataframes. However, I'm having trouble using filters within my class. My code is below:</p>
<pre><code>class Dataframe:
def __init__(self, my_dataframe):
self.my_dataframe = my_dataframe
self.my_dataframe = self.filter_priv()
def f... | 1 | 2016-07-25T20:27:47Z | 38,577,464 | <p>You're doing this <em>way</em> wrong. You're subclassing from dataframe, but then you're storing your data inside a special dataframe property. No bueno.</p>
<p>You should be subclassing if you want to have a class that quacks like a dataframe, but you want to add some other behavior that's not available.</p>
<p>I... | 0 | 2016-07-25T21:09:31Z | [
"python",
"python-2.7",
"pandas"
] |
How to compare hours and minutes? | 38,576,920 | <p>I have four variables:</p>
<pre><code>start_hour = '12'
start_minute = '00'
end_hour = '22'
end_minute = '30'
</code></pre>
<p>and from datetime:</p>
<pre><code>current_hour = datetime.now().hour
curren_minute = datetime.now().minute
</code></pre>
<p>And I want to compare if the current time is within the range:... | 1 | 2016-07-25T20:31:02Z | 38,576,952 | <p>You can use <a href="https://docs.python.org/2/library/datetime.html#timedelta-objects" rel="nofollow"><code>datetime.timedelta</code></a> to do the comparisons reliably. You can specify a delta in different units of time (hours, minutes, seconds, etc.) Then you don't have to worry about converting to hours, minutes... | 7 | 2016-07-25T20:33:03Z | [
"python"
] |
How to compare hours and minutes? | 38,576,920 | <p>I have four variables:</p>
<pre><code>start_hour = '12'
start_minute = '00'
end_hour = '22'
end_minute = '30'
</code></pre>
<p>and from datetime:</p>
<pre><code>current_hour = datetime.now().hour
curren_minute = datetime.now().minute
</code></pre>
<p>And I want to compare if the current time is within the range:... | 1 | 2016-07-25T20:31:02Z | 38,576,979 | <p>A much better way to go about this would beto convert both times to minutes:</p>
<pre><code>start_time = int(start_hour)*60 + int(start_minute)
end_time = int(end_hour)*60 + int(end_minute)
current_time = datetime.now().hour*60 +datetime.now().minute
if start_time <= current_time and end_time >= current_time... | 4 | 2016-07-25T20:34:51Z | [
"python"
] |
How to compare hours and minutes? | 38,576,920 | <p>I have four variables:</p>
<pre><code>start_hour = '12'
start_minute = '00'
end_hour = '22'
end_minute = '30'
</code></pre>
<p>and from datetime:</p>
<pre><code>current_hour = datetime.now().hour
curren_minute = datetime.now().minute
</code></pre>
<p>And I want to compare if the current time is within the range:... | 1 | 2016-07-25T20:31:02Z | 38,577,112 | <p>A simple and clear way to do it all with just <code>datetime</code> objects is:</p>
<pre><code>now = datetime.now()
start = now.replace(hour = int(start_hour), minute = int(start_minute))
end = now.replace(hour = int(end_hour), minute = int(end_minute))
if start <= now <= end:
print('something')
</code><... | 1 | 2016-07-25T20:44:08Z | [
"python"
] |
How to compare hours and minutes? | 38,576,920 | <p>I have four variables:</p>
<pre><code>start_hour = '12'
start_minute = '00'
end_hour = '22'
end_minute = '30'
</code></pre>
<p>and from datetime:</p>
<pre><code>current_hour = datetime.now().hour
curren_minute = datetime.now().minute
</code></pre>
<p>And I want to compare if the current time is within the range:... | 1 | 2016-07-25T20:31:02Z | 38,577,215 | <p>What about:</p>
<pre><code>>>> import datetime
>>> now = datetime.datetime.now()
>>> breakfast_time = now.replace( hour=7, minute=30, second=0, microsecond=0 )
>>> lunch_time = now.replace( hour=12, minute=30, second=0, microsecond=0 )
>>> coffee_break = now.replace(... | 2 | 2016-07-25T20:51:28Z | [
"python"
] |
Are there any Python NLP tools to figure out how many ways a sentence can be parsed? | 38,576,921 | <p>I want to be able to measure ambiguity of a sentence, and my current my idea to do so is by measuring how many ways a sentence can be parsed. For example, the sentence "Fruit flies like a banana" can have to interpretations.</p>
<p>So far I have tried using the Stanford Parser, but it only interpreted each sentence... | 0 | 2016-07-25T20:31:11Z | 38,593,679 | <p>From the Stanford Parser <a href="http://nlp.stanford.edu/software/parser-faq.shtml" rel="nofollow">FAQ page</a>, hope it helps:</p>
<blockquote>
<p><strong>Can I obtain multiple parse trees for a single input sentence?</strong></p>
<p>Yes, for the PCFG parser (only). With a PCFG parser, you can give the opt... | 0 | 2016-07-26T15:11:23Z | [
"python",
"nlp"
] |
Python:Replace tab in double quotes | 38,576,959 | <p>Hi i have line where i want to replace tab in double quotes. I have wrote script for that but it is not working as I want.
My line:</p>
<pre><code>Q3U962 Mus musculus MRMP-mouse Optimization "MRMP-mouse "
</code></pre>
<p>My script:</p>
<pre><code> for repline in reppepdata:
findtorep=re.findall(r"... | 1 | 2016-07-25T20:33:22Z | 38,577,234 | <p><strong>NOTE</strong>: This answer assumes (it is <a href="http://stackoverflow.com/questions/38576959/pythonreplace-tab-in-double-quotes/38577234#comment64543584_38576959">confirmed by OP</a>) that there are no escaped quotes/sequences in the input.</p>
<p>You may match the quoted string with a simple <code>"[^"]+... | 1 | 2016-07-25T20:52:40Z | [
"python",
"regex",
"replace"
] |
Pct_change in python with missing data | 38,576,969 | <p>I have quarterly time series data that I am calculating derivatives for. The problem is, the raw data has gaps in the time series. Therefore, if I am trying to find the quarter-over-quarter percent change in a variable, there are times when it will not realize it's calculating a percent change for a period much long... | 2 | 2016-07-25T20:34:34Z | 38,577,310 | <p>I'm going to put <code>['calendardate', 'ticker']</code> in the index to facilitate pivoting. Then <code>unstack</code> to get ticker values in the columns.</p>
<pre><code>df.set_index(['calendardate', 'ticker']).unstack().head(10)
</code></pre>
<p><a href="http://i.stack.imgur.com/2jMrS.png" rel="nofollow"><img ... | 2 | 2016-07-25T20:58:01Z | [
"python",
"numpy",
"pandas"
] |
How to use the data generated in a specific class in another class? (in python) | 38,576,981 | <p>I'm new in python and in OO programming, so I don't know if the following question makes sense (...but I think it's a nice way to learn): </p>
<p>I'm trying to have two classes. One that generates data (call it <code>DataGen()</code>) and another that is able to process this data and give me some statistics (call ... | 0 | 2016-07-25T20:34:58Z | 38,578,064 | <p>For someone new to Python and OO you're getting the hang of encapsulation very well. You will want to follow the <a href="https://en.wikipedia.org/wiki/Observer_pattern" rel="nofollow">Observer pattern</a> here which is where one object owns some info (DataGen) and some other object is interested in that info (Stats... | 0 | 2016-07-25T21:58:19Z | [
"python",
"oop"
] |
How would I collapse rows based on a value in a column? | 38,577,007 | <p>Iâll describe what I mean in more detail here.
Suppose I have a data sheet that looks like this:</p>
<pre><code>+-----------+---------+---------+---------+---------+---------+---------+--------------+
| | Person1 | Person2 | Person4 | Person4 | Person5 | Person6 | City |
+-----------+---------+-... | 0 | 2016-07-25T20:36:43Z | 38,579,593 | <p>The proper term for what you're trying to do here is <em>aggregation</em>. The word <em>collapse</em> is not commonly used for this operation, in my experience.</p>
<p>I'm sort of learning python on-the-fly here, so there might be a better way, but I've gotten this to work using the <a href="http://pandas.pydata.or... | 2 | 2016-07-26T01:00:16Z | [
"python",
"bash",
"tr"
] |
How would I collapse rows based on a value in a column? | 38,577,007 | <p>Iâll describe what I mean in more detail here.
Suppose I have a data sheet that looks like this:</p>
<pre><code>+-----------+---------+---------+---------+---------+---------+---------+--------------+
| | Person1 | Person2 | Person4 | Person4 | Person5 | Person6 | City |
+-----------+---------+-... | 0 | 2016-07-25T20:36:43Z | 38,581,967 | <pre><code>$ cat tst.awk
function prt() {
if ( prev != "" ) {
for (i=2;i<=NF;i++) {
printf "%s%s", vals[i], (i<NF ? OFS : ORS)
}
}
delete vals
}
BEGIN { FS=OFS="," }
$NF != prev { prt() }
{
for (i=1;i<=NF;i++) {
vals[i] = (vals[i] ~ /[[:alpha:]]/ ? vals[i] :... | 1 | 2016-07-26T05:54:03Z | [
"python",
"bash",
"tr"
] |
Issue running uWsgi using pid/gid | 38,577,013 | <p>I'm trying to run uWsgi using <code>uid</code>/<code>gid</code> parameters in my wsgi ini file, so that it drops privileged access after starting.</p>
<p>Note: Everything works fine as expected when I remove these two parameters from my ini file. Also, there are no issues with my socket. However, when I run with a ... | 0 | 2016-07-25T20:37:09Z | 38,597,595 | <p>This was completely not obvious. As a test, I tried using my own <code>uid</code>/<code>gid</code> to run the app, and lo' and behold, it worked!</p>
<p>So, with "I must have ownership on something that the app <code>uid</code>/<code>gid</code> does not have permission to run" in mind, I grepped the venv on my user... | 0 | 2016-07-26T18:42:06Z | [
"python",
"nginx",
"flask",
"uwsgi",
"python-venv"
] |
Find and modify python nested dictionary (key, value) | 38,577,049 | <p>I have a json file that I need to update. I am converting it to a python dict (nested) to update it. Here is the input, but it could be any dept. I'm sure there is a better way to do this, but don't know.</p>
<p>Ultimatley I want to be able to perfom Create/Delete action in addition to the update. </p>
<hr>
<h2>H... | 1 | 2016-07-25T20:39:36Z | 38,579,309 | <p>I think the best way would be to convert the Json object to XML and use ElementTree and XPath to parse and modify your object. Later you can revert to Json if you need:</p>
<pre><code>import json
from xmljson import parker
from lxml.etree import Element
dataxml = parker.etree(datajson, root=Element('root'))
print(... | 1 | 2016-07-26T00:22:47Z | [
"python",
"json",
"dictionary"
] |
customize dateutil.parser century inference logic | 38,577,076 | <p>I am working on old text files with 2-digit years where the default century logic in <code>dateutil.parser</code> doesn't seem to work well. For example, the attack on Pearl Harbor was not on <code>dparser.parse("12/7/41")</code> (which returns 2041-12-7). </p>
<p>The buit-in century "threshold" to roll back int... | 4 | 2016-07-25T20:41:37Z | 38,577,198 | <p>You can also <em>post-process the extracted dates</em> manually changing the century if the extracted year is more than a specified threshold, in your case - 2016:</p>
<pre><code>import dateutil.parser as dparser
THRESHOLD = 2016
date_strings = ["12/31/65", "1/1/66", "12/31/16", "1/1/17"]
for date_string in date_... | 1 | 2016-07-25T20:50:00Z | [
"python",
"python-dateutil"
] |
customize dateutil.parser century inference logic | 38,577,076 | <p>I am working on old text files with 2-digit years where the default century logic in <code>dateutil.parser</code> doesn't seem to work well. For example, the attack on Pearl Harbor was not on <code>dparser.parse("12/7/41")</code> (which returns 2041-12-7). </p>
<p>The buit-in century "threshold" to roll back int... | 4 | 2016-07-25T20:41:37Z | 38,577,299 | <p>This isn't particularly well documented but you can actually override this using <code>dateutil.parser</code>. The second argument is a <code>parserinfo</code> object, and the method you'll be concerned with is <code>convertyear</code>. The <a href="http://dateutil.readthedocs.io/en/stable/_modules/dateutil/parser.h... | 4 | 2016-07-25T20:57:18Z | [
"python",
"python-dateutil"
] |
customize dateutil.parser century inference logic | 38,577,076 | <p>I am working on old text files with 2-digit years where the default century logic in <code>dateutil.parser</code> doesn't seem to work well. For example, the attack on Pearl Harbor was not on <code>dparser.parse("12/7/41")</code> (which returns 2041-12-7). </p>
<p>The buit-in century "threshold" to roll back int... | 4 | 2016-07-25T20:41:37Z | 38,577,890 | <p>Other than writing your own <code>parserinfo.convertyear</code> method, you can customize this by passing a standard <code>parserinfo</code> object with changed <code>_century</code> and <code>_year</code> settings *):</p>
<pre><code>from dateutil.parser import parse, parserinfo
info = parserinfo()
info._century = ... | 1 | 2016-07-25T21:42:50Z | [
"python",
"python-dateutil"
] |
How to fix "unexpected keyword argument 'useChardet'" in html5lib | 38,577,080 | <p>I'm using html5lib and after updating it to the latest version, I keep getting this error:</p>
<pre><code>Traceback (most recent call last):
File "/home/travis/build/freelawproject/juriscraper/tests/test_everything.py", line 119, in test_scrape_all_example_files
site.parse()
File "/home/travis/build/freelaw... | 4 | 2016-07-25T20:41:56Z | 38,577,081 | <p>Turns out that if you feed a unicode object to the <code>document_fromstring</code> method, it barfs. It didn't used to because this only happened when I updated my dependencies. </p>
<p>Anyway, the fix is easy:</p>
<pre><code>html5parser.document_fromstring(u'<html></html'.encode('utf-8'))
</code></pre>
| 4 | 2016-07-25T20:41:56Z | [
"python",
"html5lib"
] |
Convert Column Name from int to string in pandas | 38,577,126 | <p>I have a pandas dataframe with mixed column names:</p>
<p>1,2,3,4,5, 'Class'</p>
<p>When I save this dataframe to h5file, it says that the performance will be affected due to mixed types. How do I convert the integer to string in pandas?</p>
| 2 | 2016-07-25T20:45:02Z | 38,577,252 | <p>You can simply use <code>df.columns = df.columns.astype(str)</code>:</p>
<pre><code>In [26]: df = pd.DataFrame(np.random.random((3,6)), columns=[1,2,3,4,5,'Class'])
In [27]: df
Out[27]:
1 2 3 4 5 Class
0 0.773423 0.865091 0.614956 0.219458 0.837748 0.862177
1 0... | 3 | 2016-07-25T20:53:53Z | [
"python",
"pandas"
] |
Converting SVG lines to arcs | 38,577,196 | <p>I'm using Python's svgwrite to draw an SVG diagram. I have a bunch of horizontal lines that I'm currently drawing with Paths. It's pretty simple, point A to point B. I'd like to convert these lines to be slightly rounded up (the height will be some distance, say 10). I can't figure out how to convert this though... | 0 | 2016-07-25T20:49:54Z | 38,580,065 | <p>I figured it out. I was confusing A and a in my tests. It's simply:</p>
<pre><code>M100,100 A100,50 0 0 0 200,100
</code></pre>
| 0 | 2016-07-26T02:13:48Z | [
"python",
"svg",
"svgwrite"
] |
Django REST Framework - View with serialization without model | 38,577,222 | <p>I just recently started developing for Django and am building an API using Django REST Framework and class based views. I am looking for a way to <strong>combine models, sort them based on time and then return a subset of the fields to an API with the table name appended.</strong></p>
<p>Currently I have the follow... | 0 | 2016-07-25T20:51:45Z | 38,594,008 | <p>As IanAuld suggested in the comments - ModelObj._meta.db_table got the name of the table. I then created a sorted list of dictionaries in views.py:</p>
<pre><code>speedList = Speed.objects.filter(run=run_id)
type = Speed._meta.db_table.split('_', 1)[1]
type = type[0].upper() + type[1:]
for speed in speedList:
... | 0 | 2016-07-26T15:25:27Z | [
"python",
"json",
"django",
"django-rest-framework"
] |
formatting data from a new source in pyalgotrade | 38,577,241 | <p>I am trying to adapt a <a href="http://gbeced.github.io/pyalgotrade/docs/v0.17/html/tutorial.html" rel="nofollow">pyalgotrade</a> feed to use data streamed from another source. I am getting an error inside of the <code>run_strategy</code> method when I try to point the feed to data data obtained using the function <... | 0 | 2016-07-25T20:53:06Z | 39,030,203 | <p>You're trying to use a list as a BarFeed and that won't work. Use this as a reference to implement a BarFeed class for your datasource:
<a href="https://github.com/gbeced/pyalgotrade/blob/master/pyalgotrade/barfeed/yahoofeed.py" rel="nofollow">https://github.com/gbeced/pyalgotrade/blob/master/pyalgotrade/barfeed/yah... | 0 | 2016-08-19T02:24:16Z | [
"python",
"pyalgotrade"
] |
Optimizing by translation to map one x,y set of points onto another | 38,577,286 | <p>I have a list of x,y ideal points, and a second list of x,y measured points. The latter has some offset and some noise.</p>
<p>I am trying to "fit" the latter to the former. So, extract the x,y offset of the latter relative to the former. </p>
<p>I'm following some examples of <code>scipy.optimize.leastsq</code>, ... | 0 | 2016-07-25T20:56:21Z | 38,577,717 | <p>The scipy.optimize.leastsq assumes that the function you are using already has one input, x0, the initial guess. Any other <strong>additional</strong> inputs are then listed in args.</p>
<p>So you are sending three arguments: translation_guess, transactions, and coords.</p>
<p>Note that <a href="http://docs.scipy.... | 0 | 2016-07-25T21:27:27Z | [
"python",
"numpy",
"scipy",
"coordinates",
"least-squares"
] |
plotly/python- how to embed newest plot on your website | 38,577,287 | <p>I want to include a plot from plotly on my website.</p>
<p>Now I have this: (as from their website)</p>
<pre><code> <iframe width=750 height=500 frameborder=â0â seamless=âseamlessâ scrolling=ânoâ src='https://plot.ly/~zfrancica/66/machine-worn-percenatage/'> </iframe>
</code></pre>
<p>Bu... | 0 | 2016-07-25T20:56:31Z | 38,577,688 | <p>If I understand your question correctly you probably need a timer in javascript periodically checks the backend for a new plot</p>
| 0 | 2016-07-25T21:24:51Z | [
"python",
"plot",
"plotly"
] |
Django - reverse_lazy in DeleteView yields NoReverseMatch | 38,577,308 | <p>New to Django and html; I want to add the possibility to delete objects from the database.</p>
<p>When I get to the delete confirmation template and click "Confirm", the objects gets deleted but I get this error: </p>
<blockquote>
<p>"Reverse for 'assets' with arguments '()' and keyword arguments '{}'
not foun... | 1 | 2016-07-25T20:58:00Z | 38,577,383 | <p>You were just specifying a url name <code>assets</code>, but I think it might be missing <code>appname</code> as prefix(I saw you have other urls that contains the app name), maybe try:</p>
<pre><code>success_url = reverse_lazy("appname:assets")
</code></pre>
| 3 | 2016-07-25T21:02:53Z | [
"python",
"django",
"python-3.x"
] |
Qt (QOpenGLShaderProgram) - setting a uniform boolean value? | 38,577,319 | <p>How could I pass a boolean value to my fragment shader, using QOpenGLShaderProgram? (Python)</p>
<p>If my program is called <code>_program</code>, could i just use something like this:</p>
<pre><code>self._program.setUniformValue('myVar', 1)
</code></pre>
<p>In order to pass a value of <code>true</code>, and then... | 0 | 2016-07-25T20:58:39Z | 38,578,354 | <p>It is ok. <a href="https://www.opengl.org/sdk/docs/man/html/glUniform.xhtml" rel="nofollow"><code>glUniform</code> documentation</a> says:</p>
<blockquote>
<p>Either the i, ui or f variants may be used to provide values for uniform variables of type bool, bvec2, bvec3, bvec4, or arrays of these. The uniform varia... | 1 | 2016-07-25T22:26:52Z | [
"python",
"qt",
"opengl"
] |
Apply fuzzy matching across a dataframe column and save results in a new column | 38,577,332 | <p>I have two data frames with each having a different number of rows. Below is a couple rows from each data set</p>
<pre><code>df1 =
Company City State ZIP
FREDDIE LEES AMERICAN GOURMET SAUCE St. Louis MO 63101
CITYARCHRIVER 2015 FOUNDATION ... | 2 | 2016-07-25T20:59:28Z | 38,578,687 | <p>I couldn't tell what you were doing. This is how I would do it.</p>
<pre><code>from fuzzywuzzy import fuzz
from fuzzywuzzy import process
</code></pre>
<p>Create a series of tuples to compare:</p>
<pre><code>compare = pd.MultiIndex.from_product([df1['Company'],
df2['FDA Comp... | 2 | 2016-07-25T23:03:38Z | [
"python",
"pandas",
"fuzzy-search",
"fuzzywuzzy"
] |
JSONDecodeError: Extra data: line 1 column 228 (char 227) | 38,577,399 | <p>I am using Ipython to do some data analysis, I can't load the JSON file. Please help me to load this JSON file in IPython.
And I also want to skip same words in the first line to make it a clean format, I want each record looks like this :</p>
<pre><code>{"station_id":"72","num_bikes_available":18,"num_bikes_di... | 0 | 2016-07-25T21:04:36Z | 38,577,508 | <p>Here is a suggestion for loading the file: </p>
<pre><code>with open('Path/to/file', 'r') as content_file:
content = content_file.read()
records = json.loads(content)
</code></pre>
<p>The root object in your json will be in your <code>records</code> variable</p>
| 0 | 2016-07-25T21:12:20Z | [
"python",
"json",
"load"
] |
How can I perform a rebase with pygit2? | 38,577,476 | <p><a href="http://stackoverflow.com/q/21661211">This question</a> touches on how to perform a merge with <code>pygit2</code>, but, to the best of my understanding, that will result in a new commit. Is there a way to perform a rebase, which will not result in a new commit and will simply fast-forward the branch refere... | 0 | 2016-07-25T21:10:23Z | 38,577,631 | <p>You can fast-forward with <a href="http://www.pygit2.org/references.html#pygit2.Reference.set_target" rel="nofollow">Reference.set_target()</a>.</p>
<p>Example (fast-forwarding <code>master</code> to <code>origin/master</code>, assuming that the script starts from checked out <code>master</code> branch in clean sta... | 1 | 2016-07-25T21:21:18Z | [
"python",
"git",
"pygit2"
] |
Python for loop only goes through once | 38,577,629 | <p>I'm writing a script to search through multiple text files with mac addresses in them to find what port they are associated with. I need to do this for several hundred mac addresses. The function runs the first time through fine. After that though the new mac address doesn't get passed to the function it remains ... | 0 | 2016-07-25T21:21:15Z | 38,577,764 | <p><code>source_file</code> is opened globally only once, so the first time you execute call <code>find_mac()</code>, the <code>for switches in source_file:</code> loop will exhaust the file. Since the file wasn't closed and reopened, the next time <code>find_mac()</code> is called the file pointer is at the end of th... | 1 | 2016-07-25T21:30:43Z | [
"python",
"python-2.7"
] |
Saving variable size part of string to another variable | 38,577,657 | <p>I am messing around with string on an imageboard, and I want to be able to grab the board name from the end of the URL. I was wondering if I could possibly use %s to save it to another variable, but I only know how to use that to assign. Here is an example of the end of the URL.</p>
<pre><code>url = '/a/thread/1446... | 1 | 2016-07-25T21:22:59Z | 38,577,675 | <p>You can just <a href="https://docs.python.org/3/library/stdtypes.html#str.split" rel="nofollow">split your string</a> at the <code>/</code> characters and grab the second element of the resulting list (the first one is empty because of the leading <code>/</code>)</p>
<pre><code>board = url.split('/')[1]
</code></pr... | 1 | 2016-07-25T21:24:01Z | [
"python",
"string",
"variables",
"url"
] |
Biopython bootstrapping phylogenetic trees with custom distance matrix | 38,577,681 | <p>I am trying to create a bootstrapped phylogenetic tree but instead of using raw multiple sequence alignment data and a standard scoring system, I want to use my own custom distance matrix that I have created. I have currently looked at <a href="http://biopython.org/wiki/Phylo" rel="nofollow">http://biopython.org/wi... | 0 | 2016-07-25T21:24:21Z | 38,594,097 | <p><strong>Short answer:</strong> No, you cannot use a distance matrix to bootstrap a phylogeny.</p>
<p><strong>Long answer:</strong>
The first step in bootstrapping a phylogeny calls for creating a set of data pseudoreplicates. For DNA sequences, nucleotide positions are randomly drawn from the alignment (the whole c... | 0 | 2016-07-26T15:29:46Z | [
"python",
"biopython",
"phylogeny"
] |
DBF to CSV Convertion | 38,577,708 | <p>I have been trying all day to convert dbf files to CSV and cannot seem to get it. I have looked at various options and cannot seem to get one that will work. Here is one that I have been trying.</p>
<pre><code> import arcpy
import dbf
from arcpy import env
import os
def DBFtoCSV(path):
'''Convert every... | 0 | 2016-07-25T21:26:35Z | 38,578,126 | <p>Instead of using <code>dbfpy</code> use <a href="https://pypi.python.org/pypi/dbf" rel="nofollow">my dbf module</a> instead:</p>
<pre><code>import dbf # instead of dbfpy
def DBFtoCSV(path):
'''Convert every DBF table into CSV table. '''
env.workspace = path
tablelist = arcpy.ListTables() # list tables... | 0 | 2016-07-25T22:03:43Z | [
"python",
"csv",
"dbf",
"arcpy"
] |
DBF to CSV Convertion | 38,577,708 | <p>I have been trying all day to convert dbf files to CSV and cannot seem to get it. I have looked at various options and cannot seem to get one that will work. Here is one that I have been trying.</p>
<pre><code> import arcpy
import dbf
from arcpy import env
import os
def DBFtoCSV(path):
'''Convert every... | 0 | 2016-07-25T21:26:35Z | 38,595,255 | <p>This can be fairly straightforward with SearchCursor. All you really need to do is get the field names, pass that into the cursor, then write the complete row to a csv with Python's csv module.</p>
<pre><code>import arcpy
import csv
dbf = table_name # Pass in the table you've identified
outputFile = '{}.csv'.forma... | 0 | 2016-07-26T16:27:57Z | [
"python",
"csv",
"dbf",
"arcpy"
] |
How to pass a new variable to python script using 'for' loop | 38,577,726 | <p>I am trying to write a python script that will traverse through a list and then pass a new variable to an other python script. Here is my code:</p>
<h1>Script: ENCViewer.py</h1>
<pre><code> # import necessary modules
import os
# list of all ENCS
root = os.listdir('/home/cassandra/desktop/file_formats/ENC_ROOT'... | 0 | 2016-07-25T21:28:14Z | 38,577,786 | <p>I don't know if what you are asking is possible, but I think that you miss understood the idea of creating modules and importing code. The "standard" way of achieving the same result is the following:</p>
<p>ENCReader.py</p>
<pre><code>def printer(var):
print(var)
# your code..
</code></pre>
<p>ENCViewer.... | 2 | 2016-07-25T21:32:51Z | [
"python",
"variables",
"for-loop",
"main"
] |
Pandas - unflatten data frame with columns containing array | 38,577,737 | <p>I have a data frame which has been flattened on a specific property:</p>
<pre><code>id property_a properties_b
id_1 property_a_1 [property_b_11, property_b_12]
id_2 property_a_2 [property_b_21, property_b_22, property_b_23]
..................
</code></pre>
<p>I'd like to expand the column <code>pr... | 2 | 2016-07-25T21:29:02Z | 38,577,988 | <p>This question was addressed <a href="http://stackoverflow.com/a/38432346/2336654">here</a> and <a href="http://stackoverflow.com/questions/32468402/how-to-explode-a-list-inside-a-dataframe-cell-into-separate-rows">here</a>. If you find these questions and answers useful, feel free to up vote them as well.</p>
<h3>... | 3 | 2016-07-25T21:51:33Z | [
"python",
"pandas"
] |
Pandas - unflatten data frame with columns containing array | 38,577,737 | <p>I have a data frame which has been flattened on a specific property:</p>
<pre><code>id property_a properties_b
id_1 property_a_1 [property_b_11, property_b_12]
id_2 property_a_2 [property_b_21, property_b_22, property_b_23]
..................
</code></pre>
<p>I'd like to expand the column <code>pr... | 2 | 2016-07-25T21:29:02Z | 38,578,177 | <p>Here is another approach using <code>to_records</code>, some tuple-mapping and <code>from_records</code>.</p>
<pre><code>import pandas as pd
import itertools
def expand_column(df, col_id):
records = map(lambda r: [r[1:col_id] + (l,) + r[col_id + 1:] for l in r[col_id]], map(tuple, df.to_records()))
return ... | 2 | 2016-07-25T22:08:32Z | [
"python",
"pandas"
] |
converting to a padas dataframe with numpy dtype of string | 38,577,841 | <p>This is a super basic question but I couldn't find a solution anywhere. I've looked at the docs and on Stack Overflow. I need to get a numpy array of strings which I will then save as a csv. I have a line like this:</p>
<pre><code>np.savetxt(path + 'section.csv', np.asarray(seclist, dtype=np.dtype('a2')), fmt='%s'... | -2 | 2016-07-25T21:38:34Z | 38,590,863 | <p>I had a python list of lists. However some lists were length 0 and some were length 1. Thus the numpy couldn't accept the string dtype. When I padded the lists so they were all the same length that fixed everything. </p>
| 0 | 2016-07-26T13:12:23Z | [
"python",
"arrays",
"string",
"csv",
"numpy"
] |
ImportError: No module named setuptools.command on Mac OS X within virtualenv | 38,577,959 | <p>Trying to install a Python pip package (Django Rest Framework docs, <a href="https://pypi.python.org/pypi/drfdocs/" rel="nofollow"><code>drfdocs</code></a>) on Mac OSX within a virtualenv:</p>
<p>Here are the relevant versions of pip, python, easy_install:</p>
<pre><code>$ virtualenv --version
1.11.4
$ mkvirtuale... | 7 | 2016-07-25T21:49:13Z | 38,682,395 | <p>This is a bug in package. See <a href="https://github.com/ekonstantinidis/django-rest-framework-docs/issues/120" rel="nofollow">issue #120</a></p>
<p>Wait for <a href="https://github.com/ekonstantinidis/django-rest-framework-docs/milestone/3" rel="nofollow">v0.1.0</a> or download <a href="https://pypi.python.org/pa... | 3 | 2016-07-31T08:59:58Z | [
"python",
"django",
"osx",
"virtualenv",
"virtualenvwrapper"
] |
Matplotlib- Any way to use integers AND decimals in colorbar ticks? | 38,577,978 | <p><strong>The issue</strong></p>
<p>I have a plot and I need the colorbar ticks to be larger since I'm adding this plot to a multi-panel plot & the tick labels will be hard to read otherwise with everything so condensed. My problem is that if I make the labels bigger, they start running into each other near the e... | 0 | 2016-07-25T21:50:30Z | 38,578,231 | <p>It's hard to test, since your example isn't directly runnable, but you should just be able to set the labels to whatever string you like. Something like so:</p>
<pre><code>bound_labels = [str(v) if v <=1 else str(int(v)) for v in bounds]
cbar.set_ticklabels(bound_labels)
</code></pre>
| 0 | 2016-07-25T22:13:30Z | [
"python",
"matplotlib",
"colorbar"
] |
Matplotlib- Any way to use integers AND decimals in colorbar ticks? | 38,577,978 | <p><strong>The issue</strong></p>
<p>I have a plot and I need the colorbar ticks to be larger since I'm adding this plot to a multi-panel plot & the tick labels will be hard to read otherwise with everything so condensed. My problem is that if I make the labels bigger, they start running into each other near the e... | 0 | 2016-07-25T21:50:30Z | 38,578,243 | <p>Try </p>
<pre><code>bounds = ['0.001','0.01','0.1','1','5','10','25','50']
cbar.set_ticklabels(bounds)
</code></pre>
| 2 | 2016-07-25T22:14:35Z | [
"python",
"matplotlib",
"colorbar"
] |
KIVY - Python Keep doing while button is pressed | 38,578,280 | <p>A few days ago (yesterday actually :D) I started programming in KIVY (which is a python module -- if I can call it that).</p>
<p>I'm pretty familiar with python itself but I find KIVY pretty problamatic and difficult in some solutions.</p>
<p>I'm currently trying to make a platformer game for IOS/Android but I'm s... | 1 | 2016-07-25T22:17:37Z | 38,578,488 | <p><a href="https://kivy.org/docs/api-kivy.uix.behaviors.button.html#kivy.uix.behaviors.button.ButtonBehavior" rel="nofollow">Here</a> is the button API in kivy. The two bindings that applicable to your problem are the <code>on_press</code> and <code>on_release</code> bindings. You would use these with the <code>Button... | 0 | 2016-07-25T22:41:30Z | [
"android",
"python",
"ios",
"kivy"
] |
KIVY - Python Keep doing while button is pressed | 38,578,280 | <p>A few days ago (yesterday actually :D) I started programming in KIVY (which is a python module -- if I can call it that).</p>
<p>I'm pretty familiar with python itself but I find KIVY pretty problamatic and difficult in some solutions.</p>
<p>I'm currently trying to make a platformer game for IOS/Android but I'm s... | 1 | 2016-07-25T22:17:37Z | 38,672,054 | <p>I have created a simple example for you, featuring how to move a character (in this case, <em>elf warrior level 1</em>) with a button press:</p>
<pre><code>#!/usr/bin/env python3.5
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.f... | 0 | 2016-07-30T08:45:18Z | [
"android",
"python",
"ios",
"kivy"
] |
Flask Rest API Versioning - Returned URLs | 38,578,378 | <h2>The FooBar Api is Published</h2>
<p>Let's say there's a team of developers working on an API, called the <code>FooBar api</code> with a few endpoints:</p>
<pre><code>GET /foo
# returns {'bar': '/bar', 'data': 'foo'}
GET /bar
# returns {'data': 'hello world!'}
</code></pre>
<p>Now, let's say the <code>Fo... | 1 | 2016-07-25T22:29:05Z | 38,578,432 | <p>Do neither. It's not in keeping with REST or HTTP to have two different representations of the same resource with different URLs. They are the same resource, they should have the same URL.</p>
<p>Whether the clients are using version 1 of the API or version 2 of the API, they are still referring to the same resou... | 1 | 2016-07-25T22:35:40Z | [
"python",
"api",
"rest",
"flask",
"api-versioning"
] |
python3 unotools connection error failed to connect | 38,578,454 | <p>I have searched for an answer, but nothing has helped so far. I have a method that I want to use to create an odt file and fill it with text. I also want the user to view the file when it is created. I am using python 3.4.3 unotools 0.3.3 LinuxMint 17.1 LibreOffice 4.2.8.2</p>
<p>The issue:</p>
<pre><code>unotools... | 0 | 2016-07-25T22:37:47Z | 38,595,717 | <p>I do not recommend code like this:</p>
<pre><code>subprocess.Popen(...)
time.sleep(...)
</code></pre>
<p>It is better to use a shell script to start <code>soffice</code> and then call the python script.</p>
<p>However if you are determined to run <code>soffice</code> in a subprocess, then I recommend increasing t... | 0 | 2016-07-26T16:51:44Z | [
"python",
"python-3.x",
"connection",
"libreoffice-writer"
] |
python3 unotools connection error failed to connect | 38,578,454 | <p>I have searched for an answer, but nothing has helped so far. I have a method that I want to use to create an odt file and fill it with text. I also want the user to view the file when it is created. I am using python 3.4.3 unotools 0.3.3 LinuxMint 17.1 LibreOffice 4.2.8.2</p>
<p>The issue:</p>
<pre><code>unotools... | 0 | 2016-07-25T22:37:47Z | 38,624,281 | <p>Thanks for the advice. I did want this run a a subprocess. I tried extending the time but still no joy.<br />I am now looking at using the Python odfpy 1.3.3 package which after beginning to use for a day or two, I already am having more success with. </p>
| 0 | 2016-07-27T22:32:35Z | [
"python",
"python-3.x",
"connection",
"libreoffice-writer"
] |
how to split the last element in the string | 38,578,493 | <p>I am trying to split the last element from the build_location if it is same as the previous element,however the expected ouput is not the same,can you help on how to fix it?</p>
<pre><code>build_location = "\\data\builds797\PROD\client.1.8-01180-STD.PROD-1\client.1.8-01180-STD.PROD-1"
buildid =build_location.split... | 0 | 2016-07-25T22:42:18Z | 38,578,506 | <p>That's because you're only indexing the last element. You should use a <em>slice</em> to exclude the last item not an <em>index</em> on the last item:</p>
<pre><code>if buildid[-1] == buildid[-2]:
#split the last element after "\"
build_location = build_location.split("\\")[:-1]
# ... | 0 | 2016-07-25T22:43:59Z | [
"python"
] |
how to split the last element in the string | 38,578,493 | <p>I am trying to split the last element from the build_location if it is same as the previous element,however the expected ouput is not the same,can you help on how to fix it?</p>
<pre><code>build_location = "\\data\builds797\PROD\client.1.8-01180-STD.PROD-1\client.1.8-01180-STD.PROD-1"
buildid =build_location.split... | 0 | 2016-07-25T22:42:18Z | 38,578,509 | <p>Change:</p>
<pre><code>build_location = build_location.split("\\")[-1]
</code></pre>
<p>To:</p>
<pre><code>build_location = build_location.split("\\")[:-1]
# ---^---
</code></pre>
<p>You want take all the element except the last one rather than just the last one.</p>
<p>Th... | 1 | 2016-07-25T22:44:20Z | [
"python"
] |
How do I convert all python operations involving None to None values? | 38,578,494 | <p>I want all mathematical operations involving one or more None variables to return None. </p>
<p>Example: </p>
<pre><code>a = None
b = 7
a*b
</code></pre>
<p>I want this last line to return None, but it instead gives me an error: </p>
<blockquote>
<p>TypeError: unsupported operand type(s) for *: 'NoneType' and... | 2 | 2016-07-25T22:42:22Z | 38,578,510 | <p>You can check for presence of <code>None</code> in arguments and then return early:</p>
<pre><code>def calc(*args, **kwargs):
if None in list(args) + list(kwargs.keys()):
return None
#rest
</code></pre>
<p>You can also write a decorator and wrap the existing functions, this would be more useful if ... | 0 | 2016-07-25T22:44:50Z | [
"python",
"nonetype"
] |
How do I convert all python operations involving None to None values? | 38,578,494 | <p>I want all mathematical operations involving one or more None variables to return None. </p>
<p>Example: </p>
<pre><code>a = None
b = 7
a*b
</code></pre>
<p>I want this last line to return None, but it instead gives me an error: </p>
<blockquote>
<p>TypeError: unsupported operand type(s) for *: 'NoneType' and... | 2 | 2016-07-25T22:42:22Z | 38,578,556 | <p>Instead of trying to force all mathematical operations that contain some arbitrary other value to return that arbitrary other value, you could simply use a <a href="https://en.wikipedia.org/wiki/NaN" rel="nofollow"><code>NaN</code></a>, which is designed for exactly this sort of purpose:</p>
<pre><code>>>>... | 2 | 2016-07-25T22:49:34Z | [
"python",
"nonetype"
] |
How do I convert all python operations involving None to None values? | 38,578,494 | <p>I want all mathematical operations involving one or more None variables to return None. </p>
<p>Example: </p>
<pre><code>a = None
b = 7
a*b
</code></pre>
<p>I want this last line to return None, but it instead gives me an error: </p>
<blockquote>
<p>TypeError: unsupported operand type(s) for *: 'NoneType' and... | 2 | 2016-07-25T22:42:22Z | 38,578,598 | <p>Without having much context to your code structure; I assume you just want to try an operation, and return None if it's not possible.</p>
<p>Perhaps a try/except could work here:</p>
<pre><code>try:
# operation here
except TypeError:
return None
</code></pre>
<p>However I do agree with <strong>@donkopotam... | 1 | 2016-07-25T22:53:36Z | [
"python",
"nonetype"
] |
Scrape webpage no ajax calls made but data not in DOM | 38,578,497 | <p>I'm doing an exercise in scraping data from a website. For example, <a href="https://zocdoc.com" rel="nofollow">ZocDoc</a>. I'm trying to get a list of all insurance providers and their plans (You can access this information on their homepage in the insurance dropdown). </p>
<p>It appears that all data is loaded vi... | 1 | 2016-07-25T22:42:48Z | 38,578,740 | <p>Yes, the list of insurances is kept deep inside the <code>script</code> tag:</p>
<pre><code>insuranceModel = new gs.CarrierGroupedSelect(gs.CarrierGroupedSelect.prototype.parse({
...
primary_options: {
name: "Popular Insurances",
group: "primary",
options: [[300,"Aetna",2,0,1,0],[304,"Blue C... | 2 | 2016-07-25T23:10:10Z | [
"javascript",
"python",
"web-scraping"
] |
Tensorflow: Convert Tensor to numpy array then pass into a feed_dict | 38,578,505 | <p>I'm trying to build a softmax regression model for CIFAR classification. At first when I tried to pass in my images and labels into the feed dictionary, I got an error that said that feed dictionaries do not accept Tensors. I then converted them into numpy arrays using .eval() but the program hangs at the .eval() li... | 0 | 2016-07-25T22:43:51Z | 38,578,658 | <p>Theres a couple of things that you not are understanding really well. Throughout your graph you will work with Tensors. You define Tensors by either using tf.placeholder and feeding them in the session.run(feed_dict{}) or with tf.Variable and initializing it with session.run(tf.initialize_all_variables()). You must ... | 0 | 2016-07-25T23:00:11Z | [
"python",
"neural-network",
"tensorflow",
"mnist",
"softmax"
] |
list where multiple values have to be found and replaced with two new values | 38,578,574 | <p>The basis is:<br>
I want to iterate a certain number of times, each time I take a list, find a certain value, replace that value with two new values and make that the new list what goes into the iteration. </p>
<p>Here is what I have:</p>
<pre><code>list1 = ['ad', 'sbe', 'k3', 'lm0']
list2 = ['sb', 'e', 'lm', '0'... | 2 | 2016-07-25T22:50:46Z | 38,578,738 | <p>You could start from the end and do extends or the following will work, add the next two elements from <em>list2</em> if the current index is in a <em>set</em> of indexes we create from <em>list3</em> or just keep the original element, then <a href="https://docs.python.org/3/library/itertools.html#itertools.chain" r... | 1 | 2016-07-25T23:10:00Z | [
"python",
"list",
"replace"
] |
list where multiple values have to be found and replaced with two new values | 38,578,574 | <p>The basis is:<br>
I want to iterate a certain number of times, each time I take a list, find a certain value, replace that value with two new values and make that the new list what goes into the iteration. </p>
<p>Here is what I have:</p>
<pre><code>list1 = ['ad', 'sbe', 'k3', 'lm0']
list2 = ['sb', 'e', 'lm', '0'... | 2 | 2016-07-25T22:50:46Z | 38,578,760 | <p>You can use list-comprehension with filter:</p>
<pre><code>sum([list2[i:i+2]if i in list3 else [v] for i,v in enumerate(list2)], [])
</code></pre>
<p>You can loop through and check, an imperative-version:</p>
<pre><code>res = []
for i,v in enumerate(list1):
if i in list3:
res += list2[i:i+2]
else:... | -1 | 2016-07-25T23:12:00Z | [
"python",
"list",
"replace"
] |
list where multiple values have to be found and replaced with two new values | 38,578,574 | <p>The basis is:<br>
I want to iterate a certain number of times, each time I take a list, find a certain value, replace that value with two new values and make that the new list what goes into the iteration. </p>
<p>Here is what I have:</p>
<pre><code>list1 = ['ad', 'sbe', 'k3', 'lm0']
list2 = ['sb', 'e', 'lm', '0'... | 2 | 2016-07-25T22:50:46Z | 38,578,951 | <p>The way I've approached this problem is by first creating your list by zipping together the lists, and with some simple arithmetic, decide at which index to delete elements from. This <em>does not</em>
account for the possibility of <strong>duplicate</strong> values in the indices list (<em>this input can be saniti... | 1 | 2016-07-25T23:35:53Z | [
"python",
"list",
"replace"
] |
Python regular expression with or and re.search | 38,578,608 | <p>Say I have two types of strings:</p>
<pre><code>str1 = 'NUM-140 A Thing: Foobar Analysis NUM-140'
str2 = 'NUM-140 Foobar Analysis NUM-140'
</code></pre>
<p>For both of these, I want to match <code>'Foobar'</code> (which could be anything). I have tried the following:</p>
<pre><code>m = re.compile('((?<=Thing: ... | 2 | 2016-07-25T22:54:56Z | 38,578,739 | <p>If you use named groups, eg <code>(?P<name>...)</code> you'll be able to debug easier. But note the docs for span. </p>
<p><a href="https://docs.python.org/2/library/re.html#re.MatchObject.span" rel="nofollow">https://docs.python.org/2/library/re.html#re.MatchObject.span</a></p>
<blockquote>
<p>span([group... | 0 | 2016-07-25T23:10:00Z | [
"python",
"regex"
] |
Python regular expression with or and re.search | 38,578,608 | <p>Say I have two types of strings:</p>
<pre><code>str1 = 'NUM-140 A Thing: Foobar Analysis NUM-140'
str2 = 'NUM-140 Foobar Analysis NUM-140'
</code></pre>
<p>For both of these, I want to match <code>'Foobar'</code> (which could be anything). I have tried the following:</p>
<pre><code>m = re.compile('((?<=Thing: ... | 2 | 2016-07-25T22:54:56Z | 38,580,212 | <p>According to the documentation, </p>
<blockquote>
<p>As the target string is scanned, REs separated by '|' are tried from left to right. When one pattern completely matches, that branch is accepted. This means that once A matches, B will not be tested further, even if it would produce a longer overall match. In o... | 1 | 2016-07-26T02:35:47Z | [
"python",
"regex"
] |
MultiValueDictKeyError - Passing GET parameter | 38,578,637 | <p>I'm using django allauth.</p>
<p>All my users should have access to an url that is generated dynamically. Ex: www.example.com/uuid/</p>
<p>From this page they should be able to login with Soundcloud and should be redirected to this page after connecting.</p>
<p>I am using the following to get the previous link bu... | 1 | 2016-07-25T22:57:54Z | 38,579,175 | <p>You have a typo in your url - it should be:</p>
<pre><code>href="/accounts/soundcloud/login?process=login&next={{request.path}}"
</code></pre>
<p>Notice the <code>&</code> instead of the second <code>?</code>.</p>
| 1 | 2016-07-26T00:04:24Z | [
"python",
"html",
"django"
] |
Memory error when using Pandas built-in divide, but looping works? | 38,578,662 | <p>I have two DataFrames, each having 100,000 rows. I am trying to do the following:</p>
<pre><code>new = dataframeA['mykey']/dataframeB['mykey']
</code></pre>
<p>and I get an 'Out of Memory' error. I get the same error if I try:</p>
<pre><code>new = dataframeA['mykey'].divide(dataframeB['mykey'])
</code></pre>
<p>... | 0 | 2016-07-25T23:00:32Z | 38,580,681 | <p>@ayhan got it right off the bat.</p>
<p>My two dataframes were not using the same indices. Resetting them worked.</p>
| 0 | 2016-07-26T03:44:06Z | [
"python",
"performance",
"pandas",
"memory"
] |
Error installing flask-mysql python module | 38,578,685 | <p>I'm trying to install the flask-mysql module and am running into an error. It looks like a problem with vcvarsall.bat, but I'm not really sure what that hints at.</p>
<p>Any ideas from someone more experienced than myself?</p>
<pre><code>C:\eb-virt\bucketlist>pip install flask-mysql
Collecting flask-mysql
Us... | 0 | 2016-07-25T23:03:38Z | 38,587,824 | <p>You could try using these <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python" rel="nofollow">binaries</a> for <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">windows</a> distributions. Flask-mysql uses mysql-python which has <a href="http://stackoverflow.com/questions/21440230/insta... | 1 | 2016-07-26T10:49:21Z | [
"python",
"flask",
"flask-mysql"
] |
Error installing flask-mysql python module | 38,578,685 | <p>I'm trying to install the flask-mysql module and am running into an error. It looks like a problem with vcvarsall.bat, but I'm not really sure what that hints at.</p>
<p>Any ideas from someone more experienced than myself?</p>
<pre><code>C:\eb-virt\bucketlist>pip install flask-mysql
Collecting flask-mysql
Us... | 0 | 2016-07-25T23:03:38Z | 38,588,111 | <p>Often this type of error occurred when you have installed python <strong>32bit</strong> and mysql <strong>64bit</strong> or vice versa. Try out same installations. I have experienced this error with <strong>postgresSql</strong> and python on this command <strong>pip install psycopg2</strong>
May be this will solve y... | 0 | 2016-07-26T11:03:00Z | [
"python",
"flask",
"flask-mysql"
] |
Django not creating tables " Table django_session does not exist" | 38,578,746 | <p>Whenever I run <code>python manage.py migrate</code> I cannot get the required tables. The only tables that I get are <code>django_content_type</code> and <code>django_migrations</code>. Because of this I cannot log into the admin page or create a super user. I am using <code>MySQL-connector-python-rf</code>, python... | 0 | 2016-07-25T23:10:50Z | 38,581,000 | <p>MySql does not accept timezone info in the datetime value such as <code>'2016-07-25 22:45:16.507552+00:00'</code>, the problem is the <code>+00:00</code> part. By default, Django should use naive datetime objects, as you can see here: <a href="https://docs.djangoproject.com/en/1.9/topics/i18n/timezones/" rel="nofoll... | 1 | 2016-07-26T04:26:22Z | [
"python",
"mysql",
"django"
] |
Django not creating tables " Table django_session does not exist" | 38,578,746 | <p>Whenever I run <code>python manage.py migrate</code> I cannot get the required tables. The only tables that I get are <code>django_content_type</code> and <code>django_migrations</code>. Because of this I cannot log into the admin page or create a super user. I am using <code>MySQL-connector-python-rf</code>, python... | 0 | 2016-07-25T23:10:50Z | 38,581,460 | <p>All the tables I should have are here now. This was what I did. I deleted all tables created in the database. I also removed <code>usermie</code> from <code>INSTALLED_APPS</code>. After that I ran <code>python manage.py migrate</code>. I am wondering if changing <code>USE_TZ</code> to <code>False</code> did anything... | -1 | 2016-07-26T05:12:22Z | [
"python",
"mysql",
"django"
] |
How solve import error in Python when trying to import Numpy | 38,578,754 | <p>This is the error I get when trying to import numpy on opening python (2.7.8):</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
</code></pre>
<p>This is the path of my python binary <code>/usr/local/bin/python</code></p>
<p>This i... | 0 | 2016-07-25T23:11:36Z | 38,579,188 | <p>As Akshat pointed out in the comments above, I had multiple versions of Python installed. This could have been the effect of using homebrew and/or macports in the past. I followed the steps detailed in <a href="http://stackoverflow.com/questions/13654756/too-many-pythons-on-my-mac-os-x-mountain-lion">Too many python... | 0 | 2016-07-26T00:06:09Z | [
"python",
"python-2.7",
"numpy"
] |
How can I use the Work while tkinter | 38,578,773 | <p>Function running tkinter freezes.
I want to use the Tkinter window running that process.While running progress bar
i want use tkinter window.but I can not
because it freezes tkinter.<strong>how can i use root window while time.sleep(10) or another function working</strong></p>
<pre><code>import tkinter.ttk as ttk
i... | 1 | 2016-07-25T23:13:52Z | 38,578,920 | <p>You should use <a href="http://effbot.org/tkinterbook/widget.htm#Tkinter.Widget.after-method" rel="nofollow"><code>after()</code></a> with which you can schedule the <code>loading()</code> function to be called after some period of time. </p>
<h1>Program</h1>
<p>Here is how you can use it in your program:</p>
... | 1 | 2016-07-25T23:32:41Z | [
"python",
"python-3.x",
"tkinter",
"progress-bar",
"freeze"
] |
How to get x and y coordinates from matplotlib scatter plot using plt.gca()? | 38,578,873 | <p>Is there a way to get the x and y coordinates of scatter plot points from a Matplotlib Axes object? For <code>plt.plot()</code>, there is an attribute called <code>data</code>, but the following code does not work:</p>
<pre><code>x = [1, 2, 6, 3, 11]
y = [2, 4, 10, 3, 2]
plt.scatter(x, y)
print(plt.gca().data)
plt.... | 2 | 2016-07-25T23:26:39Z | 38,579,106 | <pre><code>import matplotlib.pylab as plt
x = [1, 2, 6, 3, 11]
y = [2, 4, 10, 3, 2]
plt.scatter(x, y)
ax = plt.gca()
cs = ax.collections[0]
cs.set_offset_position('data')
print cs.get_offsets()
</code></pre>
<p>Output is</p>
<pre><code>[[ 1 2]
[ 2 4]
[ 6 10]
[ 3 3]
[11 2]]
</code></pre>
| 1 | 2016-07-25T23:55:40Z | [
"python",
"matplotlib",
"plot"
] |
Why does python and my web browser show different codes for the same link? | 38,578,875 | <p>Let's use the url <a href="https://www.google.cl/#q=stackoverflow" rel="nofollow">https://www.google.cl/#q=stackoverflow</a> as an example. Using Chrome Developer Tools on the first link given by the search we see this html code:</p>
<p><a href="http://i.stack.imgur.com/YzLub.png" rel="nofollow"><img src="http://i.... | 0 | 2016-07-25T23:26:50Z | 38,579,174 | <p>Since the html is generated dynamically, likely from a modern single page javascript framework like Angular or React (or even just plain JavaScript), you will need to actually drive a browser to the site using selenium or phantomjs before parsing the dom.</p>
<p>Here is some skeleton code.</p>
<pre><code>from sele... | 2 | 2016-07-26T00:04:22Z | [
"python",
"html"
] |
comparison ex of list comprehension and lambda | 38,578,908 | <pre><code>Celsius = [66.5,45.2,33.5,55.5]
Fahrenheit = [((float(9)/5)*x + 32) for x in Celsius]
</code></pre>
<p>How would I write this in a lambda function? Ex: lambda x,y:x+y</p>
| 0 | 2016-07-25T23:31:20Z | 38,578,931 | <p>Do you mean this?</p>
<pre><code>Fahrenheit = list(map(lambda x: x * 9.0 / 5 + 32, Celsius))
</code></pre>
<p>In general, list comprehension (what your example does) can be converted to a combination of <code>map</code> and a <code>lambda</code> (or other function).</p>
<p><strong>EDIT</strong></p>
<p>You could ... | 0 | 2016-07-25T23:33:54Z | [
"python",
"list",
"lambda",
"list-comprehension"
] |
comparison ex of list comprehension and lambda | 38,578,908 | <pre><code>Celsius = [66.5,45.2,33.5,55.5]
Fahrenheit = [((float(9)/5)*x + 32) for x in Celsius]
</code></pre>
<p>How would I write this in a lambda function? Ex: lambda x,y:x+y</p>
| 0 | 2016-07-25T23:31:20Z | 38,578,987 | <pre><code>TempCtoF = lambda c: 9/5 * c + 32
TempFtoC = lambda f: 5/9 * (f - 32)
Celsius = [66.5,45.2,33.5,55.5]
Fahrenheit = [TempCtoF(c) for c in Celsius]
</code></pre>
<p>or </p>
<pre><code>Fahrenheit = list(map(TempCtoF, Celsius))
</code></pre>
| 0 | 2016-07-25T23:41:46Z | [
"python",
"list",
"lambda",
"list-comprehension"
] |
Dictionary Different Data Types Apache Thrift | 38,578,974 | <p>I have a dictionary in Python. From what I understand Thrift only allows a strictly typed map <code>map<type1, type2></code>. However, in Python values are not always of the same type.</p>
<pre><code>dict = {'id':1,
'text': 'some text',
'active': None}
</code></pre>
<p>I want to pass this str... | 0 | 2016-07-25T23:39:51Z | 38,586,448 | <p>Use a Thrift <code>union</code>, or a <code>struct</code>:</p>
<pre><code>union varying {
1 : double dbl
2 : i32 int // or maybe i64
3 : string str
}
</code></pre>
<p>Further reading:</p>
<ul>
<li><a href="http://stackoverflow.com/questions/18923120/how-do-you-say-in-a-thrift-idl-that-a-client-should-i... | 0 | 2016-07-26T09:46:20Z | [
"python",
"dictionary",
"types",
"thrift"
] |
How to Find the Main Topic of a Body of Text | 38,579,081 | <p>I know that in NLP it is a challenge to determine the topic of a sentence or possibly a paragraph. However, I am trying to determine what the title may be for something like a Wikipedia article (of course without using other methods). My only though is finding the most frequent words. For the article on New York Cit... | -2 | 2016-07-25T23:52:53Z | 38,579,234 | <p>You might consider use below algorithms. These are keyword extracting algorithms</p>
<p><a href="http://www.tfidf.com/" rel="nofollow">TF-IDF</a></p>
<p><a href="https://web.eecs.umich.edu/~mihalcea/papers/mihalcea.emnlp04.pdf" rel="nofollow">TextRank</a></p>
<p><a href="https://yasserebrahim.wordpress.com/2012/1... | 2 | 2016-07-26T00:13:32Z | [
"python",
"python-3.x",
"nlp",
"nltk"
] |
How to Find the Main Topic of a Body of Text | 38,579,081 | <p>I know that in NLP it is a challenge to determine the topic of a sentence or possibly a paragraph. However, I am trying to determine what the title may be for something like a Wikipedia article (of course without using other methods). My only though is finding the most frequent words. For the article on New York Cit... | -2 | 2016-07-25T23:52:53Z | 38,597,654 | <p>If you have enough data and would like to have topics for a larger body of text like paragraph or an article you can use Topic Modelling methods like <a href="https://en.wikipedia.org/wiki/Latent_Dirichlet_allocation" rel="nofollow">LDA</a>. </p>
<p><a href="https://radimrehurek.com/gensim/" rel="nofollow">Gensim</... | 1 | 2016-07-26T18:46:17Z | [
"python",
"python-3.x",
"nlp",
"nltk"
] |
how to show subscript characters in a qlabel | 38,579,133 | <p>I would like to show subscripts in a QtGui.QLabel using python 3.4, qt 4.8, and pyqt 4.11. In the code sample below i have a function <code>_subscripter</code> that takes an integer and returns a string subscript i.e.</p>
<pre><code>_subscripter(13)
Out[8]: 'ââ'
</code></pre>
<p>I want the label just show the... | 0 | 2016-07-25T23:58:48Z | 38,587,458 | <p>Using <code>QChar</code> in place of <code>chr</code> should work.</p>
<pre><code>def _subscripter(n):
digits = len(str(n))
s = QtCore.QChar()
for i in range(digits):
s += QtCore.QChar(0x2080 + int(str(n)[i]))
return s
</code></pre>
| 0 | 2016-07-26T10:33:39Z | [
"python",
"pyqt"
] |
how to show subscript characters in a qlabel | 38,579,133 | <p>I would like to show subscripts in a QtGui.QLabel using python 3.4, qt 4.8, and pyqt 4.11. In the code sample below i have a function <code>_subscripter</code> that takes an integer and returns a string subscript i.e.</p>
<pre><code>_subscripter(13)
Out[8]: 'ââ'
</code></pre>
<p>I want the label just show the... | 0 | 2016-07-25T23:58:48Z | 38,594,899 | <p>Have you tried using a rich text label instead?</p>
<p>You could do this</p>
<pre><code>from PyQt4 import QtGui
from sys import argv, exit
def start_app():
app = QtGui.QApplication(argv)
window = QtGui.QLabel('Some text<sub>13</sub>')
window.show()
window.activateWindow()
exit(app.... | 1 | 2016-07-26T16:09:16Z | [
"python",
"pyqt"
] |
Invalid ELF header tensorflow | 38,579,190 | <p>I first tried installing tensorflow via the following:</p>
<pre><code>user@WS1:~/July 2016$ export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl
user@WS1:~/July 2016$ pip install --upgrade $TF_BINARY_URL
</code></pre>
<p>Then I tried using a (slightl... | 1 | 2016-07-26T00:06:27Z | 39,047,303 | <p>This could happen if you have install tensorflow package which does not match your platform. </p>
<p>An extreme example would be installing the mac platform package (as seen below) on linux.</p>
<pre><code>export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.10.0rc0-cp35-cp35m-linu... | 0 | 2016-08-19T20:36:49Z | [
"python",
"tensorflow",
"anaconda"
] |
How to edit and save existing HTML using Python? | 38,579,244 | <p>I'm trying to write a program that enables someone to edit html from python 'input()' questions. For example: change a paragraph from the command line in python. Is there some sort of library I can use to read html then edit and save it?</p>
| 0 | 2016-07-26T00:14:55Z | 38,579,274 | <p>Since an HTML file is just a plain text file it can be opened by python without the need for any extra libraries and such. Just open the file, edit what you need and write it.</p>
<p>Check out the following link:
<a href="http://www.pythonforbeginners.com/files/reading-and-writing-files-in-python" rel="nofollow">ht... | 0 | 2016-07-26T00:18:54Z | [
"python",
"html",
"html-parsing"
] |
my program dose not run because of confuse between integer value and string | 38,579,256 | <pre><code>my program confuse between integer value and string
import random
def test():
num=random.randrange(100,1000,45)
while True:
ans=run(num)
print ans
ss=raw_input("if you want to exit press t: ")
if ss=='t':
break
def run(userinput2):
first = int(useri... | 1 | 2016-07-26T00:16:10Z | 38,579,346 | <p>I think that this covers the cases you need:</p>
<pre><code>while True:
userinput2=raw_input("press t to exit or chose a number:")
if userinput2 =='t':
break
try:
userinput2 = int(userinput2)
except ValueError:
print('That was neither a number nor a "t". Try again.')
... | 2 | 2016-07-26T00:27:59Z | [
"python"
] |
Variable considered NoneType at run time, but logging shows the correct values | 38,579,275 | <p>I have a flask route where i'm posting JSON data to. Requests are converted to python dictionaries through this function.</p>
<pre><code>def request_handler(request_data):
try:
data = json.loads(request_data)
except ValueError:
return jsonres("error", "bad json")
return data
</code></p... | 0 | 2016-07-26T00:19:01Z | 38,582,111 | <p>Try:</p>
<p><code>data = request.get_json( force=True, silent=True )</code></p>
| 0 | 2016-07-26T06:04:06Z | [
"python",
"flask"
] |
Why doesn't groupby sum convert boolean to int or float? | 38,579,297 | <p>I'll start with 3 simple examples:</p>
<pre><code>pd.DataFrame([[True]]).sum()
0 1
dtype: int64
</code></pre>
<hr>
<pre><code>pd.DataFrame([True]).sum()
0 1
dtype: int64
</code></pre>
<hr>
<pre><code>pd.Series([True]).sum()
1
</code></pre>
<hr>
<p>All of these are as expected. Here is a more complic... | 5 | 2016-07-26T00:21:38Z | 38,579,754 | <p>This occurs because <a href="https://github.com/pydata/pandas/blob/master/pandas/core/groupby.py#L3128" rel="nofollow"><code>_cython_agg_blocks</code></a> calls <code>_try_coerce_and_cast_result</code> which calls <a href="https://github.com/pydata/pandas/blob/master/pandas/core/internals.py#L536" rel="nofollow"><co... | 4 | 2016-07-26T01:26:21Z | [
"python",
"pandas"
] |
How to restart flask server? | 38,579,329 | <p>I am using Flask to create a web service. I hope to restart it like every 30 minutes. Is that possible to do that and how can it be realized?</p>
<p>Meanwhile, I tried to use subprocess (popen) to start the flask web service, terminate it and start it again, but the server could not be shut down unless the whole pr... | 0 | 2016-07-26T00:25:10Z | 38,579,444 | <p>Flask web server is not supposed to serve production traffic. You should consider using some other service on top of WSGI protocol, such as <a href="http://gunicorn.org/" rel="nofollow">gunicorn</a> or <a href="https://uwsgi-docs.readthedocs.io/en/latest/" rel="nofollow">uwsgi</a> or <a href="http://flask.pocoo.org/... | 2 | 2016-07-26T00:40:56Z | [
"python",
"flask",
"subprocess"
] |
Processing groups of point-matrix multiplications with numpy | 38,579,358 | <p>Given two parallel arrays, one an array of rotation matrices, and the other an array of groups of 3D points, I'm looking for the fastest way to multiply each subgroup by the its corresponding matrix.</p>
<p>I was able to achieve what I want by looping over each group with numpy.einsum. I'm hoping there is a way to ... | 2 | 2016-07-26T00:29:12Z | 38,579,458 | <p>It's really straightforward: you've done most of the work yourself!</p>
<p>Just take the index corresponding to subgroups and put it on both sides of the einsum equation: that'll give you the desired array of dimension <code>(N_SUBGROUPS, N_GROUPS, 3)</code>.</p>
<p>Suppose we call the subgroup index <code>l</code... | 1 | 2016-07-26T00:42:59Z | [
"python",
"arrays",
"numpy",
"matrix"
] |
How can I insert an XML element between text in the parent element using ElementTree | 38,579,478 | <p>I want to generate XML like this: </p>
<pre><code><Element>some text <Child>middle text</Child> some more text</Element>.
</code></pre>
<p>How can I do this using ElementTree?</p>
<p>I couldn't find it in <a href="https://docs.python.org/2/library/xml.etree.elementtree.html" rel="nofollow"... | 1 | 2016-07-26T00:45:13Z | 38,579,508 | <p>You need to define the child element and set it's <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.tail" rel="nofollow"><code>.tail</code></a>, then <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#xml.etree.ElementTree.Element.append" rel="nofo... | 2 | 2016-07-26T00:49:37Z | [
"python",
"xml",
"elementtree"
] |
angular js infinite scrolling with django rest framework | 38,579,513 | <p>I've been following this tutorial here for the infinite scrolling.</p>
<p><a href="http://en.proft.me/2015/09/4/how-make-infinity-scroll-loading-bar-angularjs/" rel="nofollow">http://en.proft.me/2015/09/4/how-make-infinity-scroll-loading-bar-angularjs/</a></p>
<p>but for some reason it's throwing me this error</p>... | 0 | 2016-07-26T00:50:10Z | 38,580,397 | <pre><code> <div ng-app="myApp" class="app">
<div ng-controller="appCtrl as vm" class="main-container">
<h1>Post List</h1>
{% verbatim %}
<div ng-repeat="post in vm.posts | limitTo: 10" class="post">
<a href="{{ post.url}}">
<h2>{... | 0 | 2016-07-26T03:04:02Z | [
"python",
"angularjs",
"django"
] |
angular js infinite scrolling with django rest framework | 38,579,513 | <p>I've been following this tutorial here for the infinite scrolling.</p>
<p><a href="http://en.proft.me/2015/09/4/how-make-infinity-scroll-loading-bar-angularjs/" rel="nofollow">http://en.proft.me/2015/09/4/how-make-infinity-scroll-loading-bar-angularjs/</a></p>
<p>but for some reason it's throwing me this error</p>... | 0 | 2016-07-26T00:50:10Z | 38,580,934 | <p>Your first error was the missing sanitize module as I referenced in my comment. Adding the missing include:</p>
<pre><code><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular-sanitize.js"></script>
</code></pre>
<p>Will fix that.</p>
<p>Your current error is really a new questio... | 1 | 2016-07-26T04:18:16Z | [
"python",
"angularjs",
"django"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.