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 |
|---|---|---|---|---|---|---|---|---|---|
Concatenating two numpy array issues | 38,252,109 | <p>I have two numpy arrays of shape</p>
<pre><code>(129873, 12)
(129873,)
</code></pre>
<p>I would like to concatenate these so they are in the shape of:</p>
<pre><code>(129873, 13)
</code></pre>
<p>I have tried <code>numpy.concatenate</code> and <code>numpy.vstack</code> but seem to be getting errors:</p>
<blockq... | 1 | 2016-07-07T17:50:04Z | 38,252,162 | <p>I think this was already answered here:</p>
<p><a href="http://stackoverflow.com/questions/4158388/numpy-concatenating-multidimensional-and-unidimensional-arrays?rq=1">Numpy: Concatenating multidimensional and unidimensional arrays</a></p>
<pre><code>import numpy
a = numpy.array([[1, 2, 3, 4, 5], [1, 2, 3, 4, 5], ... | 1 | 2016-07-07T17:53:48Z | [
"python",
"numpy"
] |
Concatenating two numpy array issues | 38,252,109 | <p>I have two numpy arrays of shape</p>
<pre><code>(129873, 12)
(129873,)
</code></pre>
<p>I would like to concatenate these so they are in the shape of:</p>
<pre><code>(129873, 13)
</code></pre>
<p>I have tried <code>numpy.concatenate</code> and <code>numpy.vstack</code> but seem to be getting errors:</p>
<blockq... | 1 | 2016-07-07T17:50:04Z | 38,252,868 | <p>So one array has 2 dimensions, the other 1:</p>
<pre><code>(129873, 12)
(129873,)
</code></pre>
<p>You need to change the 2nd to have shape <code>(129873,1)</code>. Then you can concatenate on axis 1.</p>
<p>There are a number of way of do this. The <code>[:,None]</code> or <code>np.newaxis</code> indexing is m... | 1 | 2016-07-07T18:32:23Z | [
"python",
"numpy"
] |
How to use PySpark's FP-growth with an RDD? | 38,252,121 | <p>I would like to use FP-growth to know if there are relevant association rules from the below RDD. From the <a href="https://spark.apache.org/docs/latest/mllib-frequent-pattern-mining.html" rel="nofollow">documentation</a> I tried the following:</p>
<pre><code>sqlContext = SQLContext(sc)
spark_df = sqlContext.creat... | -1 | 2016-07-07T17:50:59Z | 38,252,274 | <p>This is wrong: <code>transactions = spark_df.map(lambda line: line.strip().split(' '))</code>. Drop this line an try:</p>
<pre><code>>>> FPGrowth.train(
... spark_df.rdd.map(lambda x: list(set(x))),
... minSupport=0.2, numPartitions=10)
</code></pre>
<p>It should provide a solution.</p>
| 1 | 2016-07-07T17:59:21Z | [
"python",
"apache-spark",
"machine-learning",
"pyspark",
"rdd"
] |
Pandas Data Frame - Merge Two Data Frames based on "InStr" > 0 | 38,252,178 | <p>I have two DataFrames in Python Pandas.</p>
<p>Data stored in the cells are as follows:</p>
<pre><code>DF1
- DatabaseId Integer
- DatabaseName String
DF2
- CreateString String
</code></pre>
<p>I want to apply the column DataBaseID to any record in DF2 where the DF1.DatabaseName exists within the context of ... | 1 | 2016-07-07T17:54:42Z | 38,253,510 | <p><strong>UPDATE:</strong> how to parse table name:</p>
<pre><code>In [100]: df2['TableName'] = df2.CreateString.str.extract('\s+(\w+\.\w+)\s+', expand=True)
In [101]: df2
Out[101]:
CreateString DatabaseName TableName
0 None NaN N... | 1 | 2016-07-07T19:10:29Z | [
"python",
"pandas",
"dataframe"
] |
write StackId to S3 using Lambda | 38,252,367 | <p>Im using create_stack api using AWS Lambda(with nested stack)..but i would like to store each stack Id in S3 which is created as part of nested stack.
Im using python for Lambda function.</p>
<p>Whenever a individual stack is created as part of nested stack(cloudformation) it appends each stack with unique Id as be... | 0 | 2016-07-07T18:04:33Z | 38,253,517 | <p>You can get the stack name from the CloudFormation API. In particular, if your parent stack is called <code>Ec2Stack</code>, you can get the name of the nested stacks from the command line with:</p>
<pre><code>aws cloudformation describe-stack-resources \
--query StackResources[].[PhysicalResourceId][] \
-... | 1 | 2016-07-07T19:10:55Z | [
"python",
"amazon-web-services",
"amazon-s3",
"aws-lambda",
"amazon-cloudformation"
] |
Reading pointers in python from root | 38,252,399 | <p>I am not sure if this question is actually about pointers because I am not very sure what they are, but I have to read some .root file using python. Below is a screenshot of the file.</p>
<p><a href="http://i.stack.imgur.com/F7CGO.png" rel="nofollow"><img src="http://i.stack.imgur.com/F7CGO.png" alt="enter image de... | 1 | 2016-07-07T18:06:34Z | 38,266,056 | <p>create </p>
<pre><code>myvec = ROOT.std.vector('float')()
</code></pre>
<p>or</p>
<pre><code>myvec = ROOT.std.vector('int')()
</code></pre>
<p>then:</p>
<pre><code>chain.SetBranchAddress("the_branch_name",myvec)
</code></pre>
<p>after:</p>
<pre><code>chain.GetEntry(some_entry_number)
</code></pre>
<p><em>myv... | 0 | 2016-07-08T11:58:12Z | [
"python",
"pointers",
"root-framework"
] |
Python error: TypeError: cannot compare a dtyped [float64] array with a scalar of type [bool] | 38,252,423 | <p>Below is a small sample of my dataframe. </p>
<pre><code>In [10]: df
Out[10]:
TXN_KEY Send_Agent Pay_Agent Send_Amount Pay_Amount
0 13272184 AWD120279 AEU002152 85.99 85.04
1 13272947 ARA030122 AEV000034 402.01 400.00
2 13273453 API185805 API190139 22.98 ... | -1 | 2016-07-07T18:07:53Z | 38,252,480 | <p>You're missing some parentheses:</p>
<pre><code>def banded_txns(s):
return ((s >= 900.00) & (s < 1000.00)).count()
</code></pre>
| 1 | 2016-07-07T18:10:54Z | [
"python",
"pandas"
] |
BeautifulSoup to find a link that contains a specific word | 38,252,434 | <p>I have this link:</p>
<p><code><a href="/location/santa-clara/3fce50c4f3f9793d2f503fc145585090">Santa Clara, California</a></code></p>
<p>How can I use BeautifulSoup to find specifically this link that includes the word location "location"?</p>
| 0 | 2016-07-07T18:08:10Z | 38,252,493 | <p>You can do it with a simple <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Attribute_selectors" rel="nofollow">"contains" CSS selector</a>:</p>
<pre><code>soup.select("a[href*=location]")
</code></pre>
<p>Or, if only one link needs to be matched, use <code>select_one()</code>:</p>
<pre><code>soup.selec... | 3 | 2016-07-07T18:11:22Z | [
"python",
"beautifulsoup"
] |
TableFactory PDFTable outputs only column headers | 38,252,485 | <p>I'm trying to create a table using <code>TableFactory</code> but there is almost no documentation and only <a href="https://github.com/kstrauser/tablefactory" rel="nofollow">two</a> <a href="http://kstrauser.github.io/tablefactory/" rel="nofollow">examples</a> that I can find. The <code>PDFTable</code> function does... | 1 | 2016-07-07T18:11:10Z | 38,252,989 | <p>You were quite close! Here's how I reworked it slightly:</p>
<pre><code>#Import module components
from collections import namedtuple
from TableFactory import *
# Build the data setup required
ids = ['a','b','c','d','e','f','g','h','i']
lon = [-80.15765381, -80.40131378, -80.56086731, -80.52893066,
-80.245... | 1 | 2016-07-07T18:39:19Z | [
"python",
"pdf"
] |
How can I get comments from a YAML file using ruamel.yaml in Python? | 38,252,507 | <p>I'd like to get the comment strings from a YAML file I loaded using <code>ruamel.yaml</code>. The <a href="http://yaml.readthedocs.io/en/latest/" rel="nofollow">project documentation</a> lacks an API reference and I can't find a relevant example. What's the right way to access the comments?</p>
<pre><code>import ru... | 3 | 2016-07-07T18:12:07Z | 38,252,508 | <p>The library author comments on this in <a href="https://bitbucket.org/ruamel/yaml/issues/31/provide-a-way-to-get-the-comment-string" rel="nofollow">an issue on BitBucket</a> (May 9, 2016):</p>
<blockquote>
<p>The comment preservation has not stabilized, e.g. I need to do something if the key and value of a mappin... | 1 | 2016-07-07T18:12:07Z | [
"python",
"comments",
"yaml",
"ruamel.yaml"
] |
Renaming files based on a string | 38,252,526 | <p>i have a some files that needs to renamed with a string/pattern</p>
<pre><code>actual file : CCRD_LLX_814_20160218043477.EDI814
Rename files to: actual file. XHS.JOBRUNID.%INTERFACENAME%.actualfile.XHE
</code></pre>
<p>i have two types of INTERFACENAME:</p>
<pre><code> 814 = EB_ENROLL_REQ
810 = EB_BCHG_REQ... | 1 | 2016-07-07T18:13:02Z | 38,253,066 | <p>A harmless <code>bash</code> script which does this simple task. This is based on the assumption that the last 3 characters in the filename determining which INTERFACE NAME to use.</p>
<pre><code>#!/bin/bash
inputString=$1
# Bash built-in parameter substitution to get the last 3 characters from the string
pattern... | 1 | 2016-07-07T18:43:50Z | [
"python",
"shell",
"awk",
"sed",
"grep"
] |
How to assign a character in a string? | 38,252,624 | <p>Here is all of my code</p>
<pre><code>from random import randint
board = []
for x in range(5):
board.append("O" * 5)
def print_board(board):
for row in board:
print(" " .join(row))
print_board(board)
def ship_row(board):
return randint(0, len(board) - 1)
def ship_col(board):
return ran... | 0 | 2016-07-07T18:17:19Z | 38,252,734 | <p><code>board</code> is a list of five 5-character strings. You are trying to assign to a specific character in an existing string, i.e. to <em>mutate</em> a string object. This is not possible, because strings in Python are <a href="https://docs.python.org/3/glossary.html#term-immutable" rel="nofollow">immutable</a> ... | 3 | 2016-07-07T18:23:30Z | [
"python"
] |
Exporting Python results to CSV | 38,252,657 | <p>Please go easy, I am a student!</p>
<p>I am unable to export the results of the following code into a CSV. For each loop (coin flip), I need to export the result to a CSV called RESULTS.CSV as a new ROW.</p>
<p>I have tried about four different approaches posted on StackOverflow but been unsuccessful thus far. I a... | 0 | 2016-07-07T18:18:57Z | 38,252,679 | <p>This will work. Now instead of just printing your results you append them to the list 'data'. Each line of 'data' will contain one of your results. Then you write the list 'data' to a csv file, which will look like you have requested.</p>
<pre><code>import csv
data = []
for s in samples:
msg = 'Heads' if s==1... | 0 | 2016-07-07T18:20:20Z | [
"python",
"python-3.x",
"csv",
"random",
"export-to-csv"
] |
Exporting Python results to CSV | 38,252,657 | <p>Please go easy, I am a student!</p>
<p>I am unable to export the results of the following code into a CSV. For each loop (coin flip), I need to export the result to a CSV called RESULTS.CSV as a new ROW.</p>
<p>I have tried about four different approaches posted on StackOverflow but been unsuccessful thus far. I a... | 0 | 2016-07-07T18:18:57Z | 38,252,895 | <pre><code>import pandas as pd
import numpy as np
#get the flipcount
flipcount=int(input("How many times should I flip a coin?\n###:"))
samples = np.random.randint(0, 2, size = flipcount)
#create a pandas dataframe
data = pd.DataFrame(["heads" if i == 1 else "Tails" for i in samples])
#create a csv file
data.to_csv("da... | 0 | 2016-07-07T18:33:25Z | [
"python",
"python-3.x",
"csv",
"random",
"export-to-csv"
] |
Python dict append is overwriting previous key:value | 38,252,730 | <p>Firstly python 2.7.11</p>
<p>Overview, I'm gathering the directory names in a given path and passing them into a subprocess cmd. From that subprocess I'm iterating over the output line by line, the directory name is the key and the subprocess.stdout is the value. </p>
<p>What I need is to keep the key the same but... | 0 | 2016-07-07T18:23:22Z | 38,253,775 | <p>Yes, you could collect all of the unique values as a list like <code>names = ['f0', 'f1', 'f2']</code> and then assign it to your dict with a <code>header</code> as a key like </p>
<pre><code>entrydict[header] = names
</code></pre>
<p>Just make sure that all of <code>header</code> are different.</p>
| 1 | 2016-07-07T19:27:25Z | [
"python",
"python-2.7",
"dictionary"
] |
Compare CSV Values Against Another CSV And Output Results | 38,252,759 | <p>I have a csv containing various columns (full_log.csv). One of the columns is labeled "HASH" and contains the hash value of the file shown in that row. For Example, my columns would have the following headers:</p>
<h2>Filename - Hash - Hostname - Date</h2>
<p>I need my python script to take another CSV (hashes.cs... | 0 | 2016-07-07T18:25:00Z | 38,252,872 | <p>look at pandas lib for python:
<a href="http://pandas.pydata.org/pandas-docs/stable/" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/</a></p>
<p>it has various helpful function for your question, easily read, transform and write to csv file</p>
| 0 | 2016-07-07T18:32:35Z | [
"python",
"csv"
] |
Compare CSV Values Against Another CSV And Output Results | 38,252,759 | <p>I have a csv containing various columns (full_log.csv). One of the columns is labeled "HASH" and contains the hash value of the file shown in that row. For Example, my columns would have the following headers:</p>
<h2>Filename - Hash - Hostname - Date</h2>
<p>I need my python script to take another CSV (hashes.cs... | 0 | 2016-07-07T18:25:00Z | 38,252,918 | <p>Iterating through the rows of files and hashes and using a filter with <code>any</code> to return matches in the collection of hashes: </p>
<pre><code>matching_rows = []
with open('full_log.csv', 'rb') as file1, open('hashes.csv', 'rb') as file2:
reader = csv.DictReader(file1)
hash_reader = csv.DictReader(f... | 0 | 2016-07-07T18:35:15Z | [
"python",
"csv"
] |
Compare CSV Values Against Another CSV And Output Results | 38,252,759 | <p>I have a csv containing various columns (full_log.csv). One of the columns is labeled "HASH" and contains the hash value of the file shown in that row. For Example, my columns would have the following headers:</p>
<h2>Filename - Hash - Hostname - Date</h2>
<p>I need my python script to take another CSV (hashes.cs... | 0 | 2016-07-07T18:25:00Z | 38,252,929 | <p>I would generate a <code>set</code> from the <code>hashes.csv</code> file. Using membership in that set as a filter, I would iterate over the <code>full_log.csv</code> file, outputting only those lines that match.</p>
<pre><code>import csv
with open('hashes.csv') as hashes:
hashes = csv.reader(hashes)
hash... | 2 | 2016-07-07T18:35:40Z | [
"python",
"csv"
] |
Compare CSV Values Against Another CSV And Output Results | 38,252,759 | <p>I have a csv containing various columns (full_log.csv). One of the columns is labeled "HASH" and contains the hash value of the file shown in that row. For Example, my columns would have the following headers:</p>
<h2>Filename - Hash - Hostname - Date</h2>
<p>I need my python script to take another CSV (hashes.cs... | 0 | 2016-07-07T18:25:00Z | 38,252,971 | <p>I am a bit unclear as to exactly how much help that you require in solving this. I will assume that you do not need a full solution, but rather, simply tips on how to craft your solution. </p>
<p>First question, which file is larger? If you know that hashes.csv is not too large, meaning it will fit in memory with n... | 0 | 2016-07-07T18:38:07Z | [
"python",
"csv"
] |
How to plot a hanging rootogram in python? | 38,252,879 | <p>Inspired by this <a href="https://mathematica.stackexchange.com/questions/120174/how-to-draw-a-hanging-rootogram-in-mathematica">question</a>, how do you make the same kind of plot in python? This plot aims at having a nice visual representation of how your distribution is off of the expected distribution. It hangs ... | 1 | 2016-07-07T18:32:54Z | 38,252,880 | <p>The idea is to just move each bar of the histogram plot where the top of the bar is at the expected value:</p>
<pre><code>import matplotlib.pyplot as plt
import numpy as np
import matplotlib.mlab as mlab
fig, ax = plt.subplots(1, 2)
mu = 10
sig = 0.3
my_data = np.random.normal(mu, sig, 200)
x = np.linspace(9, 11, ... | 5 | 2016-07-07T18:32:54Z | [
"python",
"matplotlib",
"plot",
"histogram"
] |
Python Turtle mainloop() usage | 38,252,920 | <p>I have the following code from an <a href="http://openbookproject.net/thinkcs/python/english3e/events.html#an-example-state-machines" rel="nofollow">online tutorial</a> to learn event-based programming by making a stop light that changes state when the mouse is clicked. Here is the entirety of my code:</p>
<pre><co... | 0 | 2016-07-07T18:35:23Z | 38,254,783 | <p>It appears to be an error in the tutorial.</p>
<p>On line 4, they define <code>wn = turtle.Screen()</code>, which means that the later call to <code>wn.mainloop()</code> is equivalent to calling <code>turtle.Screen().mainloop()</code>.</p>
<p>This doesn't make any sense; as the error message states there is no <co... | 1 | 2016-07-07T20:34:12Z | [
"python",
"python-2.7",
"tkinter",
"turtle-graphics",
"event-driven"
] |
Python Turtle mainloop() usage | 38,252,920 | <p>I have the following code from an <a href="http://openbookproject.net/thinkcs/python/english3e/events.html#an-example-state-machines" rel="nofollow">online tutorial</a> to learn event-based programming by making a stop light that changes state when the mouse is clicked. Here is the entirety of my code:</p>
<pre><co... | 0 | 2016-07-07T18:35:23Z | 38,257,548 | <p>I suspect it's an issue with the version of Python you're using being different than the version the tutorial is written for. In Python 3.5 on my system, an instance of the <code>turtle.Screen</code> class does indeed have a <code>mainloop</code> method, so the code you report as not working would do just fine.</p>
... | 1 | 2016-07-08T01:10:20Z | [
"python",
"python-2.7",
"tkinter",
"turtle-graphics",
"event-driven"
] |
Dump Python sklearn model in Windows and read it in Linux | 38,252,931 | <p>I am trying to save a sklearn model on a Windows server using sklearn.joblib.dump and then joblib.load the same file on a linux server (centOS71). I get the error below:</p>
<p><code>ValueError: non-string names in Numpy dtype unpickling</code></p>
<p>This is what I have tried:</p>
<ol>
<li>Tried both python27 an... | 0 | 2016-07-07T18:35:44Z | 39,263,619 | <p>Python pickle should run between windows/linux. There may be incompatibilities if:</p>
<ol>
<li>python versions on the two hosts are different (If so, try installing same version of python on both hosts); AND/OR </li>
<li>if one machine is 32-bit and another is 64-bit (I dont know any fix so far for this problem) <... | 0 | 2016-09-01T05:52:45Z | [
"python",
"linux",
"windows",
"scikit-learn",
"pickle"
] |
How to use customer filter in html? django (for loop with number) | 38,252,975 | <p>It's the first time I use the custom filters. Sorry if it seems too newbie..</p>
<p>So I am using this filter: <a href="https://djangosnippets.org/snippets/779/" rel="nofollow">https://djangosnippets.org/snippets/779/</a>
to iterate through a number in html.</p>
<p>--project
--my app
--templatetags
-... | 1 | 2016-07-07T18:38:17Z | 38,254,079 | <p>The syntax is provided in the web page. It used to not work because my silly typo in the templatetags.</p>
<pre><code>{% load helper %}
{% num_range 5 as some_range %}
{% for i in some_range %}
{{ i }}: Something I want to repeat\n
{% endfor %}
</code></pre>
| 0 | 2016-07-07T19:47:01Z | [
"python",
"html",
"django",
"for-loop"
] |
re execute a function after 30 seconds | 38,252,978 | <p>I have this code from enigma2 that actually works perfectly but sometimes it fails when it comes to some channels that more time to display epg information in the screen, this results in no epg. So I want some help to re-execute the code after a while like 30 seconds. I tried poll-interval but to no success. Here is... | -2 | 2016-07-07T18:38:24Z | 38,699,383 | <p>Try "Clear Cache" plugin because sometimes what you need is just more cache especially if you have a dm800</p>
| 0 | 2016-08-01T12:50:12Z | [
"python",
"enigma2"
] |
How can I use pip to pip install Python 3 in Ubuntu terminal? | 38,252,992 | <p>Currently using <code>Cloud9</code>'s ACE IDE dev environment for some learning opportunities, however, I ran into an API that is exclusively made for <code>Python 3</code>. </p>
<p>How can I pip install Python 3 while keeping python <code>2.7.6</code> (the current version) intact? </p>
| 0 | 2016-07-07T18:39:30Z | 38,253,340 | <p><code>pip</code> cannot be used to install <code>Python</code>, <code>pip</code> is used to install python packages, it's a <em>package manager</em>.</p>
<p>If you are looking for a command line utility that handles installing different version of <code>CPython</code>, (among other things) you can look at <a href="... | 5 | 2016-07-07T18:59:29Z | [
"python",
"python-2.7",
"python-3.x",
"pip",
"cloud9-ide"
] |
How can I use pip to pip install Python 3 in Ubuntu terminal? | 38,252,992 | <p>Currently using <code>Cloud9</code>'s ACE IDE dev environment for some learning opportunities, however, I ran into an API that is exclusively made for <code>Python 3</code>. </p>
<p>How can I pip install Python 3 while keeping python <code>2.7.6</code> (the current version) intact? </p>
| 0 | 2016-07-07T18:39:30Z | 38,253,354 | <p>From the question it seems like you want to use apt-get instead of pip.</p>
<p>Try this:</p>
<pre><code>sudo apt-get install python3
</code></pre>
| 0 | 2016-07-07T19:00:08Z | [
"python",
"python-2.7",
"python-3.x",
"pip",
"cloud9-ide"
] |
How can I use pip to pip install Python 3 in Ubuntu terminal? | 38,252,992 | <p>Currently using <code>Cloud9</code>'s ACE IDE dev environment for some learning opportunities, however, I ran into an API that is exclusively made for <code>Python 3</code>. </p>
<p>How can I pip install Python 3 while keeping python <code>2.7.6</code> (the current version) intact? </p>
| 0 | 2016-07-07T18:39:30Z | 38,257,510 | <p>You can't use <code>pip</code> to install Python 3. In any case, since you specifically mentioned the Cloud9 IDE, it already comes with both Python 2 and 3. <code>python</code> is symlinked to <code>python2</code> though, so if you want to call Python 3, you have to type <code>python3</code> (instead of just <code>p... | 0 | 2016-07-08T01:04:44Z | [
"python",
"python-2.7",
"python-3.x",
"pip",
"cloud9-ide"
] |
Seperating Django installed apps between Development vs Production | 38,252,994 | <p>I have 3 settings files:</p>
<ul>
<li>base.py (shared) </li>
<li>development.py </li>
<li>production.py</li>
</ul>
<p>base.py has: </p>
<pre><code>INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes'
...
</code></pre>
<p>but I have some apps that I... | 3 | 2016-07-07T18:39:34Z | 38,253,249 | <p>I dealt with this issue myself, i hacked it like this:</p>
<p><strong>base.py</strong> (mine was settings.py)</p>
<pre><code>INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes'
... )
# rest of settings.py variables ...
def _add_installed_app(app_name):... | 1 | 2016-07-07T18:53:55Z | [
"python",
"django",
"django-settings",
"django-apps"
] |
How to encode data for use in Charm's attribute based encryption? | 38,253,062 | <p>I'm using Charm Crypto from Github. I'd like to use the attribute based encryption algorithms. The test code works fine, however, it uses a random message generated from PairingGroup. How do I use my own data for encryption? </p>
<pre><code>>>> group = PairingGroup('SS512', secparam=512)
>>> msg =... | 0 | 2016-07-07T18:43:34Z | 38,308,776 | <p>Look at this class under charm/charm/test/toolbox/symcrypto_test.py</p>
<pre><code>class SymmetricCryptoAbstractionTest(unittest.TestCase):
def testAESCBC(self):
self.MsgtestAESCBC(b"hello world")
def testAESCBCLong(self):
self.MsgtestAESCBC(b"Lots of people working in cryptography have no deep \
conc... | 1 | 2016-07-11T13:55:00Z | [
"python",
"cryptography",
"charm-crypto"
] |
invalid literal for int() with base 10: '' when creating object | 38,253,069 | <p>I'm trying to read from a CSV file and create an object in Django (1.9, Py 3.5) but I'm getting this error, no matter what I change the field to</p>
<blockquote>
<p>invalid literal for int() with base 10: ''</p>
</blockquote>
<p>And the line is:</p>
<blockquote>
<p>other = row['Other']... | -2 | 2016-07-07T18:43:54Z | 38,253,161 | <p>The problem is that your <code>Site</code> model is expecting <code>other</code> to be an <code>int</code> (does the model have <code>other = IntegerField</code> or similar?), and you're providing an empty string. The easiest fix is to change <code>row['Other']</code> to <code>row['Other'] or 0</code></p>
<p>If you... | 1 | 2016-07-07T18:48:55Z | [
"python",
"django",
"model"
] |
Change path of url flask with regex | 38,253,192 | <p>In flask I a <code>before_request</code> function which does some checks and returns the user to a different url if necessary.</p>
<p>I have something similar to the following example which where I get <code>request_url</code> I now want to change this from: <code>https://www.example.com:5000/user/profile/</code> t... | 0 | 2016-07-07T18:50:23Z | 38,253,564 | <p>Use groups:</p>
<pre><code>url = "https://www.example.com:5000/user/profile/"
url = re.sub('.com[^\/]*', '\g<0>/us', url)
print url # https://www.example.com:5000/us/user/profile/
</code></pre>
<p>From the docs:</p>
<blockquote>
<p>In addition to character escapes and backreferences as described above, \g... | 2 | 2016-07-07T19:13:49Z | [
"python",
"regex",
"flask"
] |
Iterating through Unicode array for float values | 38,253,207 | <p>I have an array of Unicode strings with certain numbers that I need to pull out and save as floats. What would be the easiest way to iterate through this array for the low temp, current temp, and high temp? Code below:</p>
<pre><code>import pandas as pd
from bs4 import BeautifulSoup
import requests
import numpy as ... | 0 | 2016-07-07T18:51:17Z | 38,253,500 | <p>First, modify your code to parse the DataFrame header correctly.</p>
<p><code>data1 = pd.read_html(str(table1),header=0)[0]</code></p>
<p>Then, convert the columns you need to float, for example.</p>
<p><code>data1['Low Temp (°F)'] = data1['Low Temp (°F)'].astype(float)</code>.</p>
<p>You can select a subset o... | 1 | 2016-07-07T19:09:41Z | [
"python"
] |
Handling global namespaces in lxml parsing functions | 38,253,303 | <p>I'm dealing with some XML documents that share a custom namespace. I have a variety of different kinds of files with the same namespace and am trying to figure out the best/most elegant way of handling the namespaces when parsing. Here's an example:</p>
<p>At the beginning of a particular script, I read in an XML f... | 0 | 2016-07-07T18:57:12Z | 38,276,820 | <p>What you can do is "partially apply the function".</p>
<pre><code>def build_value_getter(namespace):
def func(some_lxml_object, 'some xpath query', ns=namespace)
return get_value(some_lxml_object, 'some xpath query', ns=ns)
return func
my_get_value = build_value_getter(self.ns)
my_get_value(some_lx... | 0 | 2016-07-08T23:40:38Z | [
"python",
"xpath",
"lxml"
] |
Is there a reason why I can't get .upper() to work? Keeps giving something called AttributeError | 38,253,316 | <pre><code>import random
def wordlist():
wordlistfile=open("dictionary.txt","r")
word_list=[]
for line in wordlistfile:
strip_line=line.strip("\n").lower()
word_list.append(strip_line)
return (word_list)
#I want to change the .lower() here to .upper() but it keeps breaking as soon as
#... | -2 | 2016-07-07T18:58:34Z | 38,253,799 | <p>There's a bug in the loop that fills <strong>blanks</strong> in <strong>hangingman</strong>:</p>
<pre><code> blanks = blanks[:1] + random_word[i] + blanks[i+1:]
</code></pre>
<p>You're chopping off all but the first character of the string. It should be</p>
<pre><code> blanks = blanks[:i] +... | 0 | 2016-07-07T19:29:00Z | [
"python",
"python-3.x"
] |
Building a row from a dict in pySpark | 38,253,385 | <p>I'm trying to dynamically build a row in pySpark 1.6.1, then build it into a dataframe. The general idea is to extend the results of <code>describe</code> to include, for example, skew and kurtosis. Here's what I thought should work:</p>
<pre><code>from pyspark.sql import Row
row_dict = {'C0': -1.199007263513269... | 3 | 2016-07-07T19:02:33Z | 38,253,641 | <p>You can use keyword arguments unpacking as follows:</p>
<pre><code>Row(**row_dict)
## Row(C0=-1.1990072635132698, C3=0.12605772684660232, C4=0.5760856026559944,
## C5=0.1951877800894315, C6=24.72378589441825, summary='kurtosis')
</code></pre>
<p>or if you prefer you can be slightly more defensive and use <c... | 4 | 2016-07-07T19:18:33Z | [
"python",
"apache-spark",
"pyspark"
] |
TypeError: QFileDialog.history(self): first argument of unbound method must have type 'QFileDialog' | 38,253,390 | <p>I'm using PyQT and have already instantiated the class for my GUI. I'm trying to find the history of files opened in my GUI.</p>
<pre><code>def plotButtonClicked(self):
lst = QFileDialog.history(self)
</code></pre>
<p>The above <code>def</code> is called by another function which creates the whole GUI. I get t... | 0 | 2016-07-07T19:02:51Z | 38,255,847 | <p><code>QFileDialog.history</code> is not a <em>classmethod</em> (also called <em>static</em> function in C++).
For you to be able to call the method, you'd have to either pass the class as first argument (as the error says) or instantiate <code>QFileDialog</code> before calling the method.</p>
<p>The reason why <cod... | 0 | 2016-07-07T21:49:14Z | [
"python",
"pyqt"
] |
Positive Distinct Summands in Python | 38,253,535 | <p>This Code is giving wrong output for <code>n=2</code> and it is very slow.</p>
<p>How Can i make this code for finding as many positive distinct summands more efficient?</p>
<p><strong>TASK</strong>- Represent a given positive integer <code>n</code> as a sum of as many pairwise
distinct positive integers as possib... | 0 | 2016-07-07T19:12:12Z | 38,253,637 | <p>I'm not sure if your code has other flaws but I can see that there are test cases similar to n=2 that will make this fail (I believe n=9 will, for example). Try <code>if ((n-i) not in p and n-i != i)</code>. You fail n=2 because it sees that i=1 is not in p, yet you are just about to put it in.</p>
| 0 | 2016-07-07T19:18:15Z | [
"python",
"algorithm",
"greedy"
] |
Positive Distinct Summands in Python | 38,253,535 | <p>This Code is giving wrong output for <code>n=2</code> and it is very slow.</p>
<p>How Can i make this code for finding as many positive distinct summands more efficient?</p>
<p><strong>TASK</strong>- Represent a given positive integer <code>n</code> as a sum of as many pairwise
distinct positive integers as possib... | 0 | 2016-07-07T19:12:12Z | 38,255,116 | <p>You can solve the problem analytically. If the number you're trying to reach is <code>N</code>, then the answer will always be</p>
<pre><code>1+2+3+ ... +n + r = N
</code></pre>
<p>where <code>n</code> is the largest possible number such that <code>n < r</code>. For example, take <code>N=8</code>, and consider ... | 1 | 2016-07-07T20:56:12Z | [
"python",
"algorithm",
"greedy"
] |
error importing python matplotlib | 38,253,546 | <p>I am attempting to import a matplotlib function (Mac OS 10.11.4) using Anaconda and python 3.4</p>
<p>I successfuly installed the latest matplotlib using <code>conda install -c conda-forge matplotlib=1.5.2</code></p>
<p>And in the program, when I used: <code>import matplotlib.pyplot as plt</code></p>
<p>I got thi... | 0 | 2016-07-07T19:12:51Z | 38,253,846 | <p><strong>Solution:</strong>
For the least intrusive solution I would simply update libpng. </p>
<p><strong>Additional:</strong>
You should also make sure you only installed Anaconda from <a href="https://www.continuum.io" rel="nofollow">https://www.continuum.io</a> and not Anaconda <strong><em>PLUS</em></strong> Pyt... | 0 | 2016-07-07T19:31:46Z | [
"python",
"osx",
"matplotlib",
"anaconda"
] |
error importing python matplotlib | 38,253,546 | <p>I am attempting to import a matplotlib function (Mac OS 10.11.4) using Anaconda and python 3.4</p>
<p>I successfuly installed the latest matplotlib using <code>conda install -c conda-forge matplotlib=1.5.2</code></p>
<p>And in the program, when I used: <code>import matplotlib.pyplot as plt</code></p>
<p>I got thi... | 0 | 2016-07-07T19:12:51Z | 39,378,710 | <p>For future reference: </p>
<pre><code>brew uninstall libpng
conda uninstall matplotlib
conda install matplotlib
</code></pre>
<p>Basically let conda decide which <code>libpng</code> version to use. </p>
| 1 | 2016-09-07T20:45:04Z | [
"python",
"osx",
"matplotlib",
"anaconda"
] |
Flask APScheduler - Cron Job only happens with active users on the page | 38,253,672 | <p>I have a low traffic internal webpage for which we use for the management of remote computers.</p>
<p>This webpage attempts to register a CRON job, so that once a week at a specified time, an e-mail will be sent to a list, with the current status of the data from the database. </p>
<p>However, in testing, everythi... | 2 | 2016-07-07T19:20:28Z | 38,333,868 | <p>Why are you complicating the issue by trying to launch a cron job like this? Just save the hassle and write directly to the crontab with python-crontab:</p>
<pre><code>from crontab import CronTab
cron = CronTab(user = True) #user='username' to specify a different account
job = cron.new(command='python /home/usr/s... | 0 | 2016-07-12T16:00:38Z | [
"python",
"flask",
"apscheduler"
] |
Flask APScheduler - Cron Job only happens with active users on the page | 38,253,672 | <p>I have a low traffic internal webpage for which we use for the management of remote computers.</p>
<p>This webpage attempts to register a CRON job, so that once a week at a specified time, an e-mail will be sent to a list, with the current status of the data from the database. </p>
<p>However, in testing, everythi... | 2 | 2016-07-07T19:20:28Z | 38,396,187 | <p>IMHO, it is not a good idea to used Apache + Webapp to run scheduled tasks.</p>
<p>If your are under Windows, why don't you add a task on the Task Scheduler?
You can run Python scripts (using a BAT script).</p>
<ol>
<li>Create a standalone Python application,</li>
<li>Deploy the application on Windows,</li>
<li>Cr... | 1 | 2016-07-15T12:30:58Z | [
"python",
"flask",
"apscheduler"
] |
Tensorflow: global_step not incremented; hence exponentialDecay not working | 38,253,700 | <p>I'm trying to learn Tensorflow, and I wanted to use the Tensorflow's cifar10 tutorial framework and train it on top of mnist (combining two tutorials). </p>
<p>In cifar10.py's train method:</p>
<pre><code>cifar10.train(total_loss, global_step):
lr = tf.train.exponential_decay(INITIAL_LEARNING_RATE, ... | 1 | 2016-07-07T19:22:22Z | 38,256,463 | <p>You are passing an argument called <code>global_step</code> to <code>mnist.training</code>, AND also creating a variable called <code>global_step</code> in <code>mnist.training</code>. The one used for tracking the <code>exponential_decay</code> is the variable that is passed in, but the one that is actually increme... | 0 | 2016-07-07T22:50:00Z | [
"python",
"tensorflow"
] |
How to create a sentence from a dictionary | 38,253,719 | <p>I am trying to make some code where the user inputs a sentence, the sentence is turned into a dict and then the dict is used to get the original sentence back.</p>
<p>Code:</p>
<pre><code>import json
def code():
sentence = input("Please write a sentence: ")
dictionary = {v: k for k,v in enumerate(sentence... | 2 | 2016-07-07T19:23:50Z | 38,253,805 | <p>Use an <code>OrderedDict</code> on <code>enumerate</code>, like so:</p>
<pre><code>from collections import OrderedDict
s = "Hello my name is Bob"
d = OrderedDict((v, i) for i, v in enumerate(s.split(), 1))
print(d)
# OrderedDict([('Hello', 1), ('my', 2), ('name', 3), ('is', 4), ('Bob', 5)])
s_rebuild = ' '.join(... | 1 | 2016-07-07T19:29:15Z | [
"python",
"string",
"python-3.x",
"dictionary",
"input"
] |
How to create a sentence from a dictionary | 38,253,719 | <p>I am trying to make some code where the user inputs a sentence, the sentence is turned into a dict and then the dict is used to get the original sentence back.</p>
<p>Code:</p>
<pre><code>import json
def code():
sentence = input("Please write a sentence: ")
dictionary = {v: k for k,v in enumerate(sentence... | 2 | 2016-07-07T19:23:50Z | 38,254,033 | <p>You need to either use <code>OrderedDict</code> to retain the element order, or sort the dictionary elements before you print them out. You've already got an <code>OrderedDict</code> answer, so here's how to use the dict you created:</p>
<pre><code>print(' '.join(k for (k, v) in sort(dictionary.items(), key=lambda ... | 2 | 2016-07-07T19:43:55Z | [
"python",
"string",
"python-3.x",
"dictionary",
"input"
] |
How to create a sentence from a dictionary | 38,253,719 | <p>I am trying to make some code where the user inputs a sentence, the sentence is turned into a dict and then the dict is used to get the original sentence back.</p>
<p>Code:</p>
<pre><code>import json
def code():
sentence = input("Please write a sentence: ")
dictionary = {v: k for k,v in enumerate(sentence... | 2 | 2016-07-07T19:23:50Z | 38,254,417 | <p>You logic is flawed in that it can't handle sentences with repeated words:</p>
<pre><code>Hello Bob my name is Bob too
{'name': 4, 'Hello': 1, 'Bob': 6, 'is': 5, 'too': 7, 'my': 3}
name Hello Bob is too my
</code></pre>
<p>We can deal with that using a <em>defaultdict</em>, making the values arrays of word positio... | 1 | 2016-07-07T20:09:58Z | [
"python",
"string",
"python-3.x",
"dictionary",
"input"
] |
Most accurate way to interpolate data and find the peak? | 38,253,753 | <p>The data I have is always on a second degree polynomial (quadratic function). I want to find the peak of the interpolated function as accurately as possible.</p>
<p><img src="http://i.stack.imgur.com/eEt1z.png" alt="Data sample points"></p>
<p>So far I've been using <code>interp1d</code> and then extract the peak ... | 2 | 2016-07-07T19:26:09Z | 38,254,191 | <p>If all you need is to find the min/max of a second degree polynomial why not do this:</p>
<pre><code>import matplotlib.pyplot as plt
from scipy.interpolate import KroghInterpolator
import numpy as np
x=range(-20,20)
y=[]
for i in x:
y.append((i**2)+25)
x=x[1::5]
y=y[1::5]
f=KroghInterpolator(x,y)
xfine=np.ar... | 0 | 2016-07-07T19:54:07Z | [
"python",
"numpy",
"scipy"
] |
Most accurate way to interpolate data and find the peak? | 38,253,753 | <p>The data I have is always on a second degree polynomial (quadratic function). I want to find the peak of the interpolated function as accurately as possible.</p>
<p><img src="http://i.stack.imgur.com/eEt1z.png" alt="Data sample points"></p>
<p>So far I've been using <code>interp1d</code> and then extract the peak ... | 2 | 2016-07-07T19:26:09Z | 38,698,377 | <p>In the end I went with <code>polyfit</code>. Although the fitted function didn't go exactly through the data points the end result was still good. From the returned coefficients I got the desired x and y coordinates of the peak.</p>
| 0 | 2016-08-01T12:02:24Z | [
"python",
"numpy",
"scipy"
] |
Why are Python Ref Counts to small integers surprisingly high? | 38,253,757 | <p>In <a href="http://stackoverflow.com/questions/510406/is-there-a-way-to-get-the-current-ref-count-of-an-object-in-python">this</a> answer I found a way to get a reference count of objects in Python. </p>
<p>They mentioned using <code>sys.getrefcount()</code>. I tried it, but I'm getting an unexpected result. When ... | 6 | 2016-07-07T19:26:23Z | 38,253,820 | <p>This object happens to have 20 references to it at the time of the first <code>sys.getrefcount</code> call. It's not just the references you created; there are all sorts of other references to it in other modules and in the Python internals, since (this is an implementation detail) the standard implementation of Pyt... | 4 | 2016-07-07T19:30:01Z | [
"python",
"python-3.x",
"reference-counting"
] |
Why are Python Ref Counts to small integers surprisingly high? | 38,253,757 | <p>In <a href="http://stackoverflow.com/questions/510406/is-there-a-way-to-get-the-current-ref-count-of-an-object-in-python">this</a> answer I found a way to get a reference count of objects in Python. </p>
<p>They mentioned using <code>sys.getrefcount()</code>. I tried it, but I'm getting an unexpected result. When ... | 6 | 2016-07-07T19:26:23Z | 38,254,088 | <p>There a bunch of reasons for having many references to an object. Tracking down which one can be difficult, and deciding if it is worth it may bypass your level of interest. Reference counting is of primary interest to developers of debugging applications and python variants.</p>
<ul>
<li>Python tries to keep onl... | 5 | 2016-07-07T19:47:39Z | [
"python",
"python-3.x",
"reference-counting"
] |
Why are Python Ref Counts to small integers surprisingly high? | 38,253,757 | <p>In <a href="http://stackoverflow.com/questions/510406/is-there-a-way-to-get-the-current-ref-count-of-an-object-in-python">this</a> answer I found a way to get a reference count of objects in Python. </p>
<p>They mentioned using <code>sys.getrefcount()</code>. I tried it, but I'm getting an unexpected result. When ... | 6 | 2016-07-07T19:26:23Z | 38,671,285 | <p>It's fun to read the source code for Python2.7 which is very well written and clear to read. (I'm referring to version 2.7.12 if you want to play along at home.) A good place to start in understanding the code is the excellent series of lectures: <a href="http://pgbovine.net/cpython-internals.htm" rel="nofollow">C P... | 4 | 2016-07-30T07:02:25Z | [
"python",
"python-3.x",
"reference-counting"
] |
Scraping Edgar with Python regular expressions | 38,253,890 | <p>I am working on a personal project's initial stage of downloading 10-Q statements from EDGAR. Quick disclaimer, I am very new to programming and python so the code that I wrote is very basic, not even using custom functions and classes, just a very long script that I'm more comfortable editing. As a result, some sol... | 0 | 2016-07-07T19:34:30Z | 38,256,512 | <p>It seems like delays are pretty useful - sitting at 3.5k downloads with no interruptions thanks to a simple: </p>
<pre><code>import(time)
time.sleep(random.randint(0, 1) + abs(random.normalvariate(0, 0.2)))
</code></pre>
| 0 | 2016-07-07T22:54:02Z | [
"python",
"regex",
"web-scraping",
"urllib"
] |
Python and Java MAC SHA256 encoding generating VERY SIMILAR KEY | 38,253,904 | <p>I'm creating a signed request (<code>SHA256</code> and <code>base64</code>) using <code>Java</code> and validating this request in <code>Python</code>. The keys that I generated are <strong>really similar</strong>:</p>
<p>Java:</p>
<pre><code>UjuGTll3GF7H8MHWyJc41NAEcd-OZOeJLT9PiAevcsw
</code></pre>
<p>Python :</... | 4 | 2016-07-07T19:35:09Z | 38,254,255 | <p><code>digest()</code> returns a string, so <code>encode</code> is just the <a href="https://docs.python.org/2/library/stdtypes.html#str.encode" rel="nofollow">standard <code>encode</code> method</a>. According to the list of <a href="https://docs.python.org/2/library/codecs.html#standard-encodings" rel="nofollow">st... | 1 | 2016-07-07T19:57:45Z | [
"java",
"python",
"base64",
"sha256",
"hmac"
] |
Numpy FFT issue when shifting data along vertical axis | 38,253,939 | <p>I want to find the relationship between the y-axis of my data and the vertical axis of my FFT (amplitude). To do this I am testing how the amplitude of my FFT changes when I change the y-axis of my data. For example, I plotted sin(t) from 0 to 2*pi and took the FFT using Numpy's FFT package and got a frequency of ap... | 0 | 2016-07-07T19:37:39Z | 38,254,850 | <p>Try this, it will convince you that all is working well:</p>
<pre><code>t = np.linspace(0, 2*math.pi, 10000)
y2 = np.sin(200*t) + 1
</code></pre>
<p>The 1 adds a very strong peak at 0 frequency. But the sin peak is also there.</p>
| 0 | 2016-07-07T20:37:50Z | [
"python",
"numpy",
"fft",
"sine",
"amplitude"
] |
Docker compose: command after docker-compose run command | 38,253,979 | <p>I follow this tutorial:
<a href="https://docs.docker.com/compose/django/" rel="nofollow">Python Docker compose</a> In this tutorial, it will create a docker compose file:</p>
<pre><code>version: '2'
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
vol... | 0 | 2016-07-07T19:40:18Z | 38,255,467 | <p><code>docker-compose run</code> is used to run a one-time command in a service's container. It cannot be used without arguments - at least service name is required. For more information on that command please refer to the <a href="https://docs.docker.com/compose/reference/run/" rel="nofollow">documentation</a>. The ... | 2 | 2016-07-07T21:20:21Z | [
"python",
"django",
"docker",
"docker-compose"
] |
Weird type definition on WSDL and TypeNotFound error from suds | 38,254,001 | <p>I am using suds SOAP client and was keep getting</p>
<pre><code>TypeNotFound: Type not found: '(SubscriberDetails, http://www.w3.org/2001/XMLSchema, )'
</code></pre>
<p>I really couldn't see what was going on but I am pretty sure this is caused by broken wsdl.</p>
<p>So when did,</p>
<pre><code>client = Client(s... | 0 | 2016-07-07T19:42:05Z | 38,267,379 | <p>Can you post more information? The error you are getting and the wsdl you are using? You could also given <a href="http://docs.python-zeep.org/" rel="nofollow">http://docs.python-zeep.org/</a> a try (i'm the author)</p>
| 0 | 2016-07-08T13:00:37Z | [
"python",
"soap",
"wsdl",
"soap-client",
"suds"
] |
Python 2.7 why is my string printing with brackets | 38,254,008 | <p>I have a variable below:</p>
<pre><code>weatherWind = int(round(c["windSpeed"])), "mph", bearing_to_direction(c["windBearing"])
</code></pre>
<p>at the moment <code>windSpeed</code> and <code>windBearing</code> are value taken from the Dark Sky weather API. However when I print this out it has the brackets and quo... | -4 | 2016-07-07T19:42:24Z | 38,254,054 | <p>You created a tuple with 3 values in it, an integer, the string <code>'mph'</code> and the string <code>'W'</code>. If you wanted to make this one string, use <a href="https://docs.python.org/2/library/string.html#formatstrings" rel="nofollow">string formatting</a>:</p>
<pre><code>weatherWind = '{:.0f} mph {}'.form... | 3 | 2016-07-07T19:45:40Z | [
"python",
"python-2.7"
] |
Python 2.7 why is my string printing with brackets | 38,254,008 | <p>I have a variable below:</p>
<pre><code>weatherWind = int(round(c["windSpeed"])), "mph", bearing_to_direction(c["windBearing"])
</code></pre>
<p>at the moment <code>windSpeed</code> and <code>windBearing</code> are value taken from the Dark Sky weather API. However when I print this out it has the brackets and quo... | -4 | 2016-07-07T19:42:24Z | 38,254,108 | <p>Somewhat confusingly,</p>
<pre><code>print a, b, c
</code></pre>
<p>does something completely different from</p>
<pre><code>x = a, b, c
print x
</code></pre>
<p>When you do <code>print a, b, c</code>, Python calls <code>str</code> on each object separately to get string representations of the objects and prints ... | 2 | 2016-07-07T19:48:45Z | [
"python",
"python-2.7"
] |
Comparison of Pandas lookup times | 38,254,067 | <p>After experimenting with timing various types of lookups on a Pandas DataFrame I am left with a few questions. </p>
<p>Here is the set up...</p>
<pre><code>import pandas as pd
import numpy as np
import itertools
letters = [chr(x) for x in range(ord('a'), ord('z'))]
letter_combinations = [''.join(x) for x in itert... | 15 | 2016-07-07T19:46:24Z | 38,255,013 | <p>(1) <code>pandas</code> currently has no knowledge of the sortedness of a column.<br>
If you want to take advantage of sorted data, you could use <code>df2.letter.searchsorted</code> See @unutbu's answer for an explanation of what's actually causing the difference in time here.</p>
<p>(2) The hash table that sit... | 5 | 2016-07-07T20:49:32Z | [
"python",
"performance",
"pandas"
] |
Comparison of Pandas lookup times | 38,254,067 | <p>After experimenting with timing various types of lookups on a Pandas DataFrame I am left with a few questions. </p>
<p>Here is the set up...</p>
<pre><code>import pandas as pd
import numpy as np
import itertools
letters = [chr(x) for x in range(ord('a'), ord('z'))]
letter_combinations = [''.join(x) for x in itert... | 15 | 2016-07-07T19:46:24Z | 38,258,390 | <p>The disparity in these %timeit results</p>
<pre><code>In [273]: %timeit df1[df1['letter'] == 'ben']
10 loops, best of 3: 36.1 ms per loop
In [274]: %timeit df2[df2['letter'] == 'ben']
10 loops, best of 3: 108 ms per loop
</code></pre>
<p>also shows up in the <em>pure NumPy</em> equality comparisons:</p>
<pre><co... | 8 | 2016-07-08T03:13:17Z | [
"python",
"performance",
"pandas"
] |
Append Dictionary Elements into an Empty Pandas Dataframe Column | 38,254,128 | <p>I have data in a pandas dataframe which looks like this:</p>
<pre><code>queryName Market tags categoryDetails
dummy_query (dummy_market) dummy_market dummy_tag [{'name': 'relevant_data', 'parentName': 'relevant_scrape', 'parentId': '289245228', 'id': '2892695401'}, {'name': 'relevant_data', 'parentName'... | 2 | 2016-07-07T19:49:52Z | 38,254,237 | <p>You are using <code>df['fifth_column'] = each_dict["name"]</code>, which sets all values in the <code>'fifth_column'</code> column to the same value each iteration, since pandas' operations are column wise by default.</p>
<p>Maybe you should try the following snippet:</p>
<pre><code>def extract_details(row):
#... | 1 | 2016-07-07T19:56:36Z | [
"python",
"numpy",
"pandas"
] |
Python psycopg2 - Work with large data | 38,254,130 | <p>I'm trying to transfer a large data (15 B) from one database (postgresql) to other with python/psycopg2 on docker. My docker has 4 GB of memory and is getting out of memory. </p>
<p>What I am doing wrong? </p>
<pre><code>cursor = conn.cursor()
cursor.execute('select * from schema.table')
for row in cursor:
tp =... | 1 | 2016-07-07T19:50:05Z | 38,254,561 | <p>Use <a href="http://initd.org/psycopg/docs/usage.html#using-copy-to-and-copy-from" rel="nofollow"><code>copy_to</code> and <code>copy_from</code></a></p>
<pre><code>f = open('t.txt', 'wb')
conn = psycopg2.connect(database='source_db')
cursor = conn.cursor()
cursor.copy_to(f, 'source_table')
conn.close()
f.close()... | 0 | 2016-07-07T20:20:15Z | [
"python",
"postgresql",
"docker",
"psycopg2"
] |
REGEX in Python only matches exponent | 38,254,140 | <p>I was reading some lines from a file, which I want to match to be floats,
here is a minimal example:</p>
<pre><code>import re
regex="[-+]?[0-9]+\.?[0-9]+([eE][-+]?[0-9]+)?"
string="0.00000000000000000E0 0.00000000000000000E0 0.00000000000000000E0"´
print(re.findall(regex,string))
</code></pre>
<p>, Which give... | 3 | 2016-07-07T19:50:49Z | 38,254,184 | <p>Change the regex to</p>
<pre><code>regex=r"[-+]?[0-9]+\.?[0-9]+(?:[eE][-+]?[0-9]+)?"
^^
</code></pre>
<p>The point is to use a non-capturing group instead of the capturing one so that <code>findall</code> did not have to return only the captured text (when there are no capturing groups... | 3 | 2016-07-07T19:53:43Z | [
"python",
"regex"
] |
Sort memoryview in Cython | 38,254,146 | <p>How can I sort a memoryview in-place in Cython? Is there a built-in function that can do it? Right now I have to use a <code>numpy</code> array instead and use <code>numpy</code>'s sort, which is very slow.</p>
| 0 | 2016-07-07T19:51:15Z | 38,280,317 | <p>To follow up on my comment, here are 3 options (numpy and a C and C++ standard library option)</p>
<pre><code>from libcpp.algorithm cimport sort
from libc.stdlib cimport qsort
import numpy as np
def sort_numpy(double[:] a, kind):
np.asarray(a).sort(kind=kind)
# needs to be compiled with C++
def sort_... | 2 | 2016-07-09T09:25:08Z | [
"python",
"cython",
"memoryview"
] |
Infinite While True Loop in the Background (Python) | 38,254,172 | <p>basically, I have some code like this:</p>
<pre><code>while True:
number = int(len(oilrigs)) * 49
number += money
time.sleep(1)
</code></pre>
<p>In front of this I have a start up screen. However because of this while true loop, it blocks it from running the actual start up screen. Instead, it just displa... | 3 | 2016-07-07T19:52:56Z | 38,254,243 | <p>Try multithreading. </p>
<pre><code>import threading
def background():
while True:
number = int(len(oilrigs)) * 49
number += money
time.sleep(1)
def foreground():
# What you want to run in the foreground
b = threading.Thread(name='background', target=background)
f = threading.Thre... | 4 | 2016-07-07T19:56:49Z | [
"python",
"multithreading",
"background-process"
] |
Django image streaming | 38,254,180 | <p>I try to make a web server that serve an image with Django and refresh this image if it change on server.
Currently I use the library gstreamer that take screenshot of my desktop every seconds and i want to send this image to a web browser using Django.</p>
<p>I try something like this :</p>
<p>view.py:</p>
<pre>... | 0 | 2016-07-07T19:53:22Z | 38,254,302 | <p>If I'm understanding what you want correctly, then you would want something called two-way data binding. It is typically done with your front-end framework. This is not something that is done in your <code>views.py</code>. I know that AngularJS is plenty capable of this.</p>
| -1 | 2016-07-07T20:01:02Z | [
"python",
"django",
"streaming"
] |
AttributeError: 'FigureCanvasMac' object has no attribute 'restore_region' with matplotlib animation example on Mac OSX | 38,254,198 | <p>Using the example code from matplotlib site:</p>
<p>I get the error:</p>
<pre><code>AttributeError: 'FigureCanvasMac' object has no attribute 'restore_region'
</code></pre>
<p>spammed in the output as the animation loops. The animation itself doens't display, and just shows:</p>
<p><a href="http://i.stack.imgur.... | 1 | 2016-07-07T19:54:33Z | 38,429,317 | <p>Must set <code>blit=False</code> in both <code>FuncAnimation()</code> and <code>ArtistAnimation()</code> and the code seems to work fine. Using python 3.4 and py34-matplotlib 1.5.2 from MacPorts.</p>
| 0 | 2016-07-18T05:43:52Z | [
"python",
"osx",
"animation",
"matplotlib"
] |
How to avoid an empty result with `Bag.take(n)` when using dask? | 38,254,247 | <p>Context:
Dask documentation states clearly that <code>Bag.take()</code> will only collect from the first partition. However, when using a filter it can occur that the first partition is empty, while others are not. </p>
<p>Question:
Is it possible to use <code>Bag.take()</code> so that it collects from a sufficien... | 2 | 2016-07-07T19:57:00Z | 38,256,165 | <p>You could do something like the following:</p>
<pre><code>from toolz import take
f = lambda seq: list(take(n, seq))
b.reduction(f, f)
</code></pre>
<p>This grabs the first n elements of each partition, collects them all together, and then takes the first n elements of the result.</p>
| 1 | 2016-07-07T22:19:28Z | [
"python",
"bag",
"dask"
] |
pass two arguments in python property setter | 38,254,290 | <pre><code>class MyClass(object):
def __init__(self, name):
self.name = name
self._prof = None
self._ischanged = False
@property
def prof(self):
if not self._prof:
self._prof = "Sample Prof"
return self._prof
@prof.setter
def prof(self, value, anothervalue):
pass... | 1 | 2016-07-07T20:00:13Z | 38,254,313 | <p>You can't pass two values to a setter. when you do:</p>
<pre><code>instance.property = whatever
</code></pre>
<p>python calls the setter with <code>instance</code> (as <code>self</code>) and <code>whatever</code> as arguments.</p>
<hr>
<p>You <em>can</em> pass a 2-tuple though:</p>
<pre><code>myclass.prof = ('... | 2 | 2016-07-07T20:02:03Z | [
"python",
"class"
] |
Can generators be recursive? | 38,254,304 | <p>I naively tried to create a recursive generator. Didn't work. This is what I did: </p>
<pre><code>def recursive_generator(lis):
yield lis[0]
recursive_generator(lis[1:])
for k in recursive_generator([6,3,9,1]):
print(k)
</code></pre>
<p>All I got was the first item <code>6</code>. </p>
<p>Is there a ... | 16 | 2016-07-07T20:01:20Z | 38,254,338 | <p>Try this:</p>
<pre><code>def recursive_generator(lis):
yield lis[0]
yield from recursive_generator(lis[1:])
for k in recursive_generator([6,3,9,1]):
print(k)
</code></pre>
<p>I should point out this doesn't work because of a bug in your function. It should probably include a check that <code>lis</code... | 23 | 2016-07-07T20:04:29Z | [
"python",
"recursion",
"generator"
] |
Can generators be recursive? | 38,254,304 | <p>I naively tried to create a recursive generator. Didn't work. This is what I did: </p>
<pre><code>def recursive_generator(lis):
yield lis[0]
recursive_generator(lis[1:])
for k in recursive_generator([6,3,9,1]):
print(k)
</code></pre>
<p>All I got was the first item <code>6</code>. </p>
<p>Is there a ... | 16 | 2016-07-07T20:01:20Z | 38,262,794 | <h1>Why your code didn't do the job</h1>
<p>In your code, the generator function:</p>
<ol>
<li><em>returns</em> (yields) the first value of the list</li>
<li>then it creates a new <em>iterator object</em> calling the same generator function, passing a slice of the list to it</li>
<li>and then stops</li>
</ol>
<p>The... | 3 | 2016-07-08T09:04:05Z | [
"python",
"recursion",
"generator"
] |
Can generators be recursive? | 38,254,304 | <p>I naively tried to create a recursive generator. Didn't work. This is what I did: </p>
<pre><code>def recursive_generator(lis):
yield lis[0]
recursive_generator(lis[1:])
for k in recursive_generator([6,3,9,1]):
print(k)
</code></pre>
<p>All I got was the first item <code>6</code>. </p>
<p>Is there a ... | 16 | 2016-07-07T20:01:20Z | 38,285,533 | <p>Recursive generators are useful for traversing non-linear structures. For example, let a binary tree be either None or a tuple of value, left tree, right tree. A recursive generator is the easiest way to visit all nodes. Example:</p>
<pre><code>tree = (0, (1, None, (2, (3, None, None), (4, (5, None, None), None))... | 2 | 2016-07-09T19:25:19Z | [
"python",
"recursion",
"generator"
] |
Can generators be recursive? | 38,254,304 | <p>I naively tried to create a recursive generator. Didn't work. This is what I did: </p>
<pre><code>def recursive_generator(lis):
yield lis[0]
recursive_generator(lis[1:])
for k in recursive_generator([6,3,9,1]):
print(k)
</code></pre>
<p>All I got was the first item <code>6</code>. </p>
<p>Is there a ... | 16 | 2016-07-07T20:01:20Z | 38,291,281 | <p>A generator function has to raise <code>StopIteration</code> exception when it is done.
For the recursive case other exceptions (e.g. <code>IndexError</code>) are raised earlier than <code>StopIteration</code>, therefore we add it manually.</p>
<pre><code>def recursive_generator(lis):
if not lis: raise StopIter... | 2 | 2016-07-10T11:14:05Z | [
"python",
"recursion",
"generator"
] |
Theano: ifelse TypeError | 38,254,359 | <p>I am trying to run the script <a href="https://github.com/wenbinli/lstm" rel="nofollow">lstm_ptb.py</a> but it is throwing a TypeError for the following line:</p>
<pre><code>shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),max_grad_norm/norm_gparams,1.)
</code></pre>
<p>This is what this line is trying to a... | 2 | 2016-07-07T20:05:51Z | 38,294,234 | <p>Your problem caused by <code>1.</code> in <code>else</code> part. By default it assigned as <code>float32</code> type. You just need to convert it:</p>
<pre><code>shrink_factor = ifelse(T.gt(norm_gparams,max_grad_norm),max_grad_norm/norm_gparams,np.float64(1.))
</code></pre>
<p>or convert the <code>max_grad_norm/n... | 0 | 2016-07-10T16:48:46Z | [
"python",
"theano"
] |
how to append a row from one dataframe to a new dataframe | 38,254,387 | <p>I am trying to identify rows from one dataframe that meet my date criteria in a specific element and then append them to a new dataframe. I have the identification down, but am having some trouble appending the data to a new dataframe. "yesterday" is a string containing yesterday's date.</p>
<pre><code> for x ... | 0 | 2016-07-07T20:08:11Z | 38,254,895 | <p>IIUC, <code>append</code> shouldn't be necessary for what you're trying to do. You should be able to do it with <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow">boolean indexing</a>:</p>
<pre><code>dfnew = df1[df1.datecompare == yesterday].copy()
</code></pre>
<p... | 1 | 2016-07-07T20:40:33Z | [
"python",
"pandas",
"dataframe",
"append"
] |
Name or service not known | 38,254,394 | <p>I have been trying to get the ipaddress of the person who logged into the machine using the below code but I get a error.</p>
<pre><code>>>> import socket
>>> socket.gethostbyname_ex(socket.gethostname())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
socket.g... | 3 | 2016-07-07T20:08:26Z | 38,254,503 | <p>Check what is being returned by <code>socket.gethostname()</code> and see if you can ping it. Basically this is a lookup failure. Check your <code>/etc/hosts</code> to see if it is listed. I know it seems strange, but I think if the hostname being returned does not have an entry, you'll get a name service failure w... | 0 | 2016-07-07T20:16:10Z | [
"python",
"centos",
"centos6"
] |
How can a portal user modify his own partner data in Odoo 8? | 38,254,399 | <p>I was trying to create a module, where portal users could modify the associated partner data. But I get a security error that only admin users could modify configs.</p>
<blockquote>
<p>File
".../server/openerp/addons/base/res/res_config.py",
line 541, in execute
raise openerp.exceptions.AccessError(_("O... | 6 | 2016-07-07T20:08:42Z | 38,364,455 | <p>Solved!</p>
<p>In the view definition change the call method of the res_config like this:</p>
<pre><code><button string="Apply" type="object" name="execute2" class="oe_highlight" />
</code></pre>
<p>and in the res_config model copy the execute def and erase the SUPERUSERID check.
I don't overrite the execut... | 2 | 2016-07-14T02:14:21Z | [
"python",
"openerp",
"odoo-8"
] |
Django (1.9) makemigrations doesn't get Blank=True on boolean field | 38,254,488 | <p>I have the following model:</p>
<pre><code>class Site(models.Model):
"""
Model for a site entry
@author: Leonardo Pessoa
@since: 05/09/2016
"""
from decimal import Decimal
consolidated_financials = models.BooleanField(blank=True)
type = models.ForeignKey(... | 2 | 2016-07-07T20:14:51Z | 38,254,539 | <p><a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#booleanfield" rel="nofollow"><code>BooleanField</code></a> does not take null=True, instead, use <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#nullbooleanfield" rel="nofollow"><code>NullBooleanField</code></a>.</p>
<p>There is a <... | 3 | 2016-07-07T20:18:33Z | [
"python",
"django",
"database",
"model"
] |
Django (1.9) makemigrations doesn't get Blank=True on boolean field | 38,254,488 | <p>I have the following model:</p>
<pre><code>class Site(models.Model):
"""
Model for a site entry
@author: Leonardo Pessoa
@since: 05/09/2016
"""
from decimal import Decimal
consolidated_financials = models.BooleanField(blank=True)
type = models.ForeignKey(... | 2 | 2016-07-07T20:14:51Z | 38,255,517 | <p>The <code>blank</code> parameter is not used by <code>BooleanField</code>. Instead, it is <a href="https://github.com/django/django/blob/fc3ac6573524acc58c23ae2c721c61bc9ed8c8d5/django/db/models/fields/__init__.py#L978" rel="nofollow">hard-coded</a> to <code>True</code>. Passing <code>blank=False</code> has no effec... | 2 | 2016-07-07T21:23:29Z | [
"python",
"django",
"database",
"model"
] |
Extract and Format Site Data Python | 38,254,553 | <p>This is for Python 3.5.x
What I'm looking for is to find the header, after a peice of the HTML code being </p>
<pre><code><h3 class = "title-link__title"><span class="title=link__text">News Here</span>
with urllib.request.urlopen('http://www.bbc.co.uk/news') as r:
HTML = r.read()
... | 1 | 2016-07-07T20:19:37Z | 38,254,773 | <p>Fetching information from webpages is called <code>web scraping</code>.</p>
<p>One of the best tools to do this job is the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow">BeautifulSoup</a> library.</p>
<pre><code>from bs4 import BeautifulSoup
import urllib
#opening page
r = urllib.... | 1 | 2016-07-07T20:33:12Z | [
"python",
"html",
"web-scraping"
] |
Python: Broken Pipe Error For PyNomo Example (in function Nomographer) | 38,254,557 | <p>I am using <code>pycharm</code> on <code>Python 2.7</code>. I have installed <a href="http://www.pynomo.org/wiki/index.php?title=Temperature_converter" rel="nofollow"><code>PyNomo</code></a>. I am trying to run this <a href="http://www.pynomo.org/wiki/index.php?title=Temperature_converter" rel="nofollow">small examp... | 3 | 2016-07-07T20:19:55Z | 38,286,480 | <p><code>PyNomo</code> uses a TeX installation to typeset text. Maybe this is missing resulting in a broken pipe. You need to be able to run a file hello.tex with the content <code>Hello, world!\bye</code> on a command line <code>tex hello.tex</code>. It should result in a file <code>hello.dvi</code>. If not you need t... | 0 | 2016-07-09T21:23:00Z | [
"python",
"broken-pipe"
] |
Finding the first space after a set of numbers in a string in python | 38,254,625 | <p>I have a string which includes some serial numbers, and I want the index of the first space after the first set of numbers.</p>
<pre><code>exampleString = ' 2342342 hihihello goats'
findDesiredSpace(exampleString)
</code></pre>
<p>desired output of the index of the space after 2342342 = 9</p>
<p>I've tried some ... | -2 | 2016-07-07T20:24:49Z | 38,254,658 | <p>You can approach that with regular expressions getting the <a href="https://docs.python.org/2/library/re.html#re.MatchObject.end" rel="nofollow"><code>end()</code></a> of a match:</p>
<pre><code>>>> import re
>>> exampleString = ' 2342342 hihihello'
>>> re.search(r'\d+\s', exampleString)... | 4 | 2016-07-07T20:27:02Z | [
"python",
"string"
] |
An error with psycopg2 while trying to connect to a remote host server | 38,254,632 | <p>I'm writing a script that should connect to postgres DB. My code is as follows:</p>
<pre><code>import psycopg2
conn = connect(host="192.168.89.121")
</code></pre>
<p>But this is generating the following error:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
F... | 0 | 2016-07-07T20:25:11Z | 38,255,495 | <p>Do you have access to the remote PostgreSQL server? The error message appears to be trying to tell you that the configuration of that PostgreSQL server isn't allowing you to make an insecure connection. Look at the pg_hba.conf file for the database on that PostgreSQL server. It determines how different machines can ... | 0 | 2016-07-07T21:21:56Z | [
"python",
"postgresql"
] |
How to print dictionary when value is an object (Python) | 38,254,648 | <p>myDict = {name1: object1, name2: object2, etc....}</p>
<p>*The objects look like this:</p>
<pre><code>Color: Blue, Flies: True, etc...
</code></pre>
<p>EDIT: included above dictionary so you can see what I'm working with.</p>
<p>While researching how to print the preceding dictionary in a nice, readable fashion,... | 1 | 2016-07-07T20:26:15Z | 38,254,734 | <p>You could just catch the <code>TypeError</code> that occurs when trying to iterate a noniterable (might want to make exceptions for strings though). </p>
<pre><code>try:
for value in myDict[key]:
print (value, ":", myDict[key][value])
except TypeError:
print value
</code></pre>
| 1 | 2016-07-07T20:31:16Z | [
"python",
"object",
"dictionary",
"printing",
"mapping"
] |
Difference between stock[item] -= 1 and stock[item] = stock[item] - 1? | 38,254,681 | <p>I've trying to write a small program that computes a bill based on certain lists. One of the requirements is to change to stock depending on what is taken out. I wrote my code the following way, and at least conceptually speaking, feel like I have the right idea.</p>
<pre><code>shopping_list = ["banana", "orange", ... | 0 | 2016-07-07T20:28:20Z | 38,254,809 | <p>With numerical variables, the operator <code>-=</code> is exactly the same as assigning one less than the current value. But there's another difference between the two versions: Your solution returns a value as soon as you examine one element in your shopping list. Returning terminates the function, so only do it wh... | 1 | 2016-07-07T20:35:43Z | [
"python"
] |
Difference between stock[item] -= 1 and stock[item] = stock[item] - 1? | 38,254,681 | <p>I've trying to write a small program that computes a bill based on certain lists. One of the requirements is to change to stock depending on what is taken out. I wrote my code the following way, and at least conceptually speaking, feel like I have the right idea.</p>
<pre><code>shopping_list = ["banana", "orange", ... | 0 | 2016-07-07T20:28:20Z | 38,254,812 | <p>I am not sure in python, however it could be that the first is decrementing the pointer (ie the actual array) and the second is decrementing the value stored in the pointer.</p>
<p>One way to check is to post the output with fixed values in the where the item variable is.</p>
| -3 | 2016-07-07T20:35:58Z | [
"python"
] |
Difference between stock[item] -= 1 and stock[item] = stock[item] - 1? | 38,254,681 | <p>I've trying to write a small program that computes a bill based on certain lists. One of the requirements is to change to stock depending on what is taken out. I wrote my code the following way, and at least conceptually speaking, feel like I have the right idea.</p>
<pre><code>shopping_list = ["banana", "orange", ... | 0 | 2016-07-07T20:28:20Z | 38,254,834 | <p>The problem is likely this:</p>
<pre><code>for item in food:
if stock[item] > 0:
total += prices[item]
stock[item] = stock[item] - 1
return total
</code></pre>
<p>Here, you're returning in the middle of the loop, so it will only ever process one item from <code>food</code>. In the s... | 1 | 2016-07-07T20:37:01Z | [
"python"
] |
Difference between stock[item] -= 1 and stock[item] = stock[item] - 1? | 38,254,681 | <p>I've trying to write a small program that computes a bill based on certain lists. One of the requirements is to change to stock depending on what is taken out. I wrote my code the following way, and at least conceptually speaking, feel like I have the right idea.</p>
<pre><code>shopping_list = ["banana", "orange", ... | 0 | 2016-07-07T20:28:20Z | 38,254,935 | <p>What better way to show you the difference but by running a program that demonstrates the difference? Try running the following program and noting what it prints to your screen.</p>
<pre><code>#! /usr/bin/env python3
def main():
stock = dict(apple=Number(100))
item = 'apple'
print('Memory location of st... | 0 | 2016-07-07T20:43:35Z | [
"python"
] |
Accessing Enovia's python interface from Excel / VBA? | 38,254,721 | <p>We are using software called Enovia.</p>
<p>I would like to query Enovia from inside Excel / VBA.</p>
<p>After some search, Enovia seems to have a programming interface called Abaqus.</p>
<p><a href="http://www.3ds.com/products-services/simulia/services/training-courses/course-descriptions/introduction-to-the-aba... | 0 | 2016-07-07T20:30:31Z | 38,255,057 | <p>ENOVIA does not have a Python programming interface.</p>
<p><a href="http://www.3ds.com/products-services/simulia/products/abaqus/" rel="nofollow">Abaqus</a> is a FEA simulation software which can be scripted with its own Python programming interface. </p>
<p><a href="http://www.3ds.com/products-services/enovia/p... | 1 | 2016-07-07T20:52:30Z | [
"python",
"excel-vba",
"xlwings",
"abaqus"
] |
Accessing Enovia's python interface from Excel / VBA? | 38,254,721 | <p>We are using software called Enovia.</p>
<p>I would like to query Enovia from inside Excel / VBA.</p>
<p>After some search, Enovia seems to have a programming interface called Abaqus.</p>
<p><a href="http://www.3ds.com/products-services/simulia/services/training-courses/course-descriptions/introduction-to-the-aba... | 0 | 2016-07-07T20:30:31Z | 38,273,394 | <p>Enovia uses the <strong><code>MQL</code></strong> language for scripting. There are some guides available, such as <a href="http://emdros.org/MQL-Programmers-Guide.pdf" rel="nofollow">http://emdros.org/MQL-Programmers-Guide.pdf</a></p>
<p>I would recommend some training such as <a href="http://www.techniatranscat.c... | 0 | 2016-07-08T18:39:21Z | [
"python",
"excel-vba",
"xlwings",
"abaqus"
] |
Parse select xml data into columns using python | 38,254,737 | <p>I am trying to parse multiple XML files into columns/tables, but some of the XML has different data and some are not important while other data is important. </p>
<p>ie(XML data): </p>
<pre><code><setId root="ABD6ECF0-DC8E"/>
<component>
<section>
<id root="F08C6A14... | 0 | 2016-07-07T20:31:20Z | 38,280,035 | <p>If I understand correctly, you are trying to parse the XML downloaded from this site : <a href="https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid=abd6ecf0-dc8e-41de-89f2-1e36ed9d6535" rel="nofollow">https://dailymed.nlm.nih.gov/dailymed/drugInfo.cfm?setid=abd6ecf0-dc8e-41de-89f2-1e36ed9d6535</a></p>
<p>Actua... | 0 | 2016-07-09T08:48:18Z | [
"python",
"xml",
"parsing"
] |
Need to get date of last Thursday of a given month in python? | 38,254,775 | <p>Need to determine any given month's last Thursday. If given month is current month, and the last Thursday has passed, need to raise an exception. I am trying to use <code>datetime</code> module, but can't find a straightforward way of doing this.</p>
<p>Edit: seems like my question was not clear enough. The functio... | -2 | 2016-07-07T20:33:25Z | 38,255,546 | <p>For the first part of your question, I like <a href="http://dateutil.readthedocs.io/en/stable/relativedelta.html" rel="nofollow">relativedelta</a> from the date.utils library.</p>
<pre><code>from datetime import date
from dateutil.relativedelta import relativedelta, TH
def get_thurs(dt):
print (dt + relativede... | 1 | 2016-07-07T21:25:12Z | [
"python",
"datetime"
] |
Need to get date of last Thursday of a given month in python? | 38,254,775 | <p>Need to determine any given month's last Thursday. If given month is current month, and the last Thursday has passed, need to raise an exception. I am trying to use <code>datetime</code> module, but can't find a straightforward way of doing this.</p>
<p>Edit: seems like my question was not clear enough. The functio... | -2 | 2016-07-07T20:33:25Z | 38,255,689 | <p>Here's a version that doesn't depend on any external packages:</p>
<pre><code>import datetime, calendar
def LastThInMonth(year, month):
# Create a datetime.date for the last day of the given month
daysInMonth = calendar.monthrange(year, month)[1] # Returns (month, numberOfDaysInMonth)
dt = datetime.d... | 1 | 2016-07-07T21:36:28Z | [
"python",
"datetime"
] |
Using curl in Popen in Python | 38,254,795 | <p>I run this curl command in the unix shell and it works (see below). I was able to redirect the returned data to a file but now I want to process the data in my code instead of wasting a bunch of space in a file.</p>
<pre><code>curl -k -o outputfile.txt 'obfuscatedandVeryLongAddress'
#curl command above, python repr... | 2 | 2016-07-07T20:35:00Z | 38,254,869 | <p>You need to remove <code>shell=True</code>.</p>
<p><code>
theFile = subprocess.Popen(["curl", "-k", addr], stdout = subprocess.PIPE, stderr = subprocess.PIPE)
</code></p>
<p>Should work.</p>
<p>If you do <code>shell=True</code>, you should pass a string. Otherwise, what you're actually doing is passing those argu... | 2 | 2016-07-07T20:38:45Z | [
"python",
"curl",
"popen"
] |
Using curl in Popen in Python | 38,254,795 | <p>I run this curl command in the unix shell and it works (see below). I was able to redirect the returned data to a file but now I want to process the data in my code instead of wasting a bunch of space in a file.</p>
<pre><code>curl -k -o outputfile.txt 'obfuscatedandVeryLongAddress'
#curl command above, python repr... | 2 | 2016-07-07T20:35:00Z | 38,254,967 | <p>Eugene's is a direct answer to your question, but I thought I'd add one on using the <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a> library, since it will require less code and be easier to read for anyone that needs to look at your code (and has the benefit of being cr... | 0 | 2016-07-07T20:46:00Z | [
"python",
"curl",
"popen"
] |
Using curl in Popen in Python | 38,254,795 | <p>I run this curl command in the unix shell and it works (see below). I was able to redirect the returned data to a file but now I want to process the data in my code instead of wasting a bunch of space in a file.</p>
<pre><code>curl -k -o outputfile.txt 'obfuscatedandVeryLongAddress'
#curl command above, python repr... | 2 | 2016-07-07T20:35:00Z | 38,255,401 | <p>You can put the curl command in a string like:</p>
<pre><code>theFile = subprocess.Popen('curl -k {}'.format(addr), stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True)
</code></pre>
<p>Or you can remove the shell argument:</p>
<pre><code>theFile = subprocess.Popen(["curl", "-k", addr], stdout = subp... | 0 | 2016-07-07T21:15:40Z | [
"python",
"curl",
"popen"
] |
Generating rows and columns based on input() | 38,254,819 | <p>I'm trying to make a "Battleship" like program. </p>
<p>This is what I have so far. </p>
<pre><code>class Start:
def play(rows, columns):
for i in rows:
for j in columns:
print("O")
print("Testing")
rowinput = input("rows: ")
colinput = input("columns: ")
s = start()
s.p... | 1 | 2016-07-07T20:36:26Z | 38,254,890 | <p>Methods of class instances take the instance of the class as first argument. </p>
<p>Add <code>self</code> to the definition of <code>play</code>. The class instance gets passed when you call the method, so you need to handle that in your method definition:</p>
<pre><code>def play(self, rows, columns):
#...
</... | 2 | 2016-07-07T20:40:05Z | [
"python",
"python-3.x"
] |
Generating rows and columns based on input() | 38,254,819 | <p>I'm trying to make a "Battleship" like program. </p>
<p>This is what I have so far. </p>
<pre><code>class Start:
def play(rows, columns):
for i in rows:
for j in columns:
print("O")
print("Testing")
rowinput = input("rows: ")
colinput = input("columns: ")
s = start()
s.p... | 1 | 2016-07-07T20:36:26Z | 38,254,943 | <p>When you call <code>s.play(rowinput, colinput)</code>, the object "s" is also passed (implicitly) to the function "play" (as it's first argument). That's what the error is saying that three arguments are being passed to function play, but the signature says that it accepts only two. Now in python the convention is t... | 0 | 2016-07-07T20:44:03Z | [
"python",
"python-3.x"
] |
How to manipulate database info before displaying it in Django template? | 38,254,911 | <p>So I've got a basic Django website setup that displays dynamic info from the database.</p>
<p>I would like to be able to manipulate the text coming out of the database so I can create BBCode parsers or whatever else I want. I'm pretty new to Django so I'm a little confused as to where this should be done.</p>
<p>T... | 0 | 2016-07-07T20:41:46Z | 38,255,125 | <p>You need to override the <code>ListView</code> methods. You will need to do some changes in your code:</p>
<ul>
<li><p>Set a custom view to your url config</p>
<h1>urls.py</h1>
<p>from django.conf.urls import url, include
from django.views.generic import ListView, DetailView
from forum.models import Post
from for... | 1 | 2016-07-07T20:56:31Z | [
"python",
"html",
"django",
"jinja2",
"bbcode"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.