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 |
|---|---|---|---|---|---|---|---|---|---|
Create copy of Oracle database table to another Oracle database using SQL | 37,578,985 | <p>I am wondering if there is a simple way to copy either an entire Oracle database table or data rows into another Oracle database table (different databases). Is there some type of way to do this using SQL language? My initial thought is to use a SQL query like this:</p>
<pre><code>INSERT INTO outputTable
SELECT *... | 2 | 2016-06-01T21:20:49Z | 37,579,200 | <p>Try creating a database link: <a href="https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm" rel="nofollow">https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_5005.htm</a>
<a href="http://psoug.org/definition/create_database_link.htm" rel="nofollow">http://psoug.org/definition/cr... | 1 | 2016-06-01T21:36:05Z | [
"python",
"sql",
"oracle"
] |
Create copy of Oracle database table to another Oracle database using SQL | 37,578,985 | <p>I am wondering if there is a simple way to copy either an entire Oracle database table or data rows into another Oracle database table (different databases). Is there some type of way to do this using SQL language? My initial thought is to use a SQL query like this:</p>
<pre><code>INSERT INTO outputTable
SELECT *... | 2 | 2016-06-01T21:20:49Z | 37,579,229 | <p>have try openQuery? in sql server, you can link to an oracle database, after that you can just you it when Openquery</p>
<p>example</p>
<pre><code>Select * into T_NewTable from openquery(connectionanme, 'select * from your source table')
</code></pre>
| 0 | 2016-06-01T21:37:47Z | [
"python",
"sql",
"oracle"
] |
Accelerating one-to-many correlation calculations in Python | 37,579,036 | <p>I'd like to calculate the Pearson's correlation coefficient between a vector and each row of an array in Python (numpy and or scipy are assumed). Use of standard correlation matrix calculation functions will not be possible due to the size of the real data arrays and memory constraints. Here's my naive implementat... | 2 | 2016-06-01T21:24:56Z | 37,582,209 | <p>The module <a href="http://docs.scipy.org/doc/scipy/reference/spatial.distance.html" rel="nofollow"><code>scipy.spatial.distance</code></a> implements the "correlation distance", which is simply one minus the correlation cofficient. You can use the function <a href="http://docs.scipy.org/doc/scipy/reference/generat... | 1 | 2016-06-02T03:38:02Z | [
"python",
"python-2.7",
"numpy",
"scipy",
"statistics"
] |
After installing django in virtual environment, still can't import module | 37,579,042 | <p>I am trying to use django for web dev, but after I install it, I try to use import it in the interpreter and it says it gives me an import error. Here is what I do.</p>
<pre><code>virtualenv venv --distribute
source venv/bin/activate
</code></pre>
<p>so now I am in the virtual environment (venv)</p>
<pre><code>pi... | 0 | 2016-06-01T21:25:27Z | 37,579,097 | <p>Original poster here.</p>
<p>I installed django using pip so it was in the python 2.7 binaries while i was working with python 3.5. </p>
<p>Using pip3 install django solved it.</p>
| 2 | 2016-06-01T21:29:31Z | [
"python",
"django",
"install"
] |
In python, communicating with stackdriver always returns success, doesn't send anything | 37,579,213 | <p>For some inexplicable reason, google provides no stackdriver api for appengine, so I'm stuck implementing one. No worries - I thought - I have already worked with the API builder to talk to bigquery, so I built up a client and started trying to send events:</p>
<pre><code>credentials = SignedJwtAssertionCredentials... | 3 | 2016-06-01T21:36:48Z | 37,708,994 | <p>The issue is in the format of your data. You can not send empty messages either. The best way to explore how to use the API is to go to the StackDriver Trace API explorer, you will find out the exact data structure to send:
<a href="https://cloud.google.com/trace/api/reference/rest/v1/projects/patchTraces#traces" re... | 1 | 2016-06-08T17:20:25Z | [
"python",
"google-app-engine",
"google-api-python-client",
"stackdriver",
"google-cloud-monitoring"
] |
Please explain this early termination of multiprocess.Process subclass? | 37,579,261 | <p>I have the following test code subclassing Process from <a href="https://docs.python.org/3.5/library/multiprocessing.html" rel="nofollow">multiprocessing</a>:</p>
<pre><code>import multiprocessing as mp
class TestProcess(mp.Process):
def __init__(self,name):
super().__init__()
self.name = name
... | 1 | 2016-06-01T21:40:11Z | 37,579,379 | <p>It's unclear to me what you expect this to do. After starting the processes, the code immediately enters the <code>finally:</code> block and explicitly terminates all of them. So of course they stop.</p>
<p>As to why only "A" says it's alive, that may vary across platforms (OS). Your <code>run()</code> method is... | 3 | 2016-06-01T21:50:20Z | [
"python",
"python-multiprocessing"
] |
Cannot install bob.measure python pacakge | 37,579,280 | <p>I have installed all the dependencies of bob.measure according to the graph presented in <a href="https://github.com/idiap/bob/wiki/Dependencies" rel="nofollow">https://github.com/idiap/bob/wiki/Dependencies</a> and <a href="https://github.com/idiap/bob/wiki/Installation" rel="nofollow">https://github.com/idiap/bob/... | 0 | 2016-06-01T21:41:50Z | 37,579,708 | <p>Install dependencies on Ubuntu:</p>
<pre><code>sudo apt-get install libboost-all-dev
sudo apt-get install libblitz0-dev
sudo apt-get install cmake
sudo apt-get install libhdf5-serial-dev
sudo apt-get install libtiff5
sudo apt-get install libtiff5-dev
sudo apt-get install libtiff-tools
sudo apt-get install giflib-db... | 0 | 2016-06-01T22:20:13Z | [
"python",
"pip"
] |
Cannot install bob.measure python pacakge | 37,579,280 | <p>I have installed all the dependencies of bob.measure according to the graph presented in <a href="https://github.com/idiap/bob/wiki/Dependencies" rel="nofollow">https://github.com/idiap/bob/wiki/Dependencies</a> and <a href="https://github.com/idiap/bob/wiki/Installation" rel="nofollow">https://github.com/idiap/bob/... | 0 | 2016-06-01T21:41:50Z | 37,590,990 | <p>Solution:</p>
<p>Remove all bob packages, such as:</p>
<pre><code>$ pip install numpy
$ pip install bob.extension
$ pip install bob.blitz
$ pip install bob.core
$ pip install bob.io.base
$ pip install bob.io.image
</code></pre>
<p>Do not remove installed dependencies.</p>
<p>then re-install bob with:</p>
<pre><... | 0 | 2016-06-02T11:47:51Z | [
"python",
"pip"
] |
NTILE for Sqlite from Pandas gives OPERATIONAL ERROR | 37,579,374 | <p>I'm trying to use the NTILE function for querying a SQLite database from pandas, but I haven't succeeded, even though I've rechecked the syntax many times.</p>
<p>Self-contained example below.
Setup:</p>
<pre><code>import pandas as pd
from sqlalchemy import create_engine
disk_engine = create_engine('sqlite:///test... | 1 | 2016-06-01T21:50:03Z | 37,579,444 | <p>There is no <code>NTILE () OVER</code> functionality in SQLITE</p>
<p>Gives me the same error, need to create this using more complex query or functions</p>
<p><a href="http://www2.sqlite.org/cvstrac/wiki?p=UnsupportedSqlAnalyticalFunctions" rel="nofollow">Here is a list of unsupported analytical functions</a> not... | 1 | 2016-06-01T21:55:16Z | [
"python",
"sqlite",
"pandas"
] |
Testing a POST that uses Flask-WTF validate_on_submit | 37,579,411 | <p>I am stumped on testing a POST to add a category to the database where I've used Flask_WTF for validation and CSRF protection. For the CRUD operations pm my website. I've used Flask, Flask_WTF and Flask-SQLAlchemy. It is my first independent project, and I find myself a little at a lost on how to test the Flask-WTF... | 1 | 2016-06-01T21:52:37Z | 37,579,552 | <p>Using py.test and a conftest.py recommended by <a href="http://alexmic.net/flask-sqlalchemy-pytest/" rel="nofollow">Delightful testing with pytest and SQLAlchemy</a>, here's a test that confirms the added category.</p>
<pre><code>def test_add_category_post(app, session):
"""Does add category post a new category... | 0 | 2016-06-01T22:04:33Z | [
"python",
"python-2.7",
"wtforms",
"flask-wtforms"
] |
How can I extract City, Region, Country from URL? Django | 37,579,453 | <p>My search field returns something like this:</p>
<blockquote>
<p><a href="http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States" rel="nofollow">http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States</a></p>
</blockquote>
<p>How can I extract City, Region, Country. I've been through this ... | -1 | 2016-06-01T21:55:57Z | 37,579,559 | <p>use django request object "domain/search/?city=vienna"</p>
<p>in
<strong>django class based views</strong>:</p>
<pre><code>self.request.GET['city']
</code></pre>
<p>in
<strong>django function based views</strong></p>
<pre><code>def get_something(request):
return HttpResponse("%s" % request.GET['city'] )
<... | 0 | 2016-06-01T22:05:08Z | [
"python",
"django",
"url",
"parameters"
] |
How can I extract City, Region, Country from URL? Django | 37,579,453 | <p>My search field returns something like this:</p>
<blockquote>
<p><a href="http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States" rel="nofollow">http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States</a></p>
</blockquote>
<p>How can I extract City, Region, Country. I've been through this ... | -1 | 2016-06-01T21:55:57Z | 37,579,595 | <p>python 2.7</p>
<pre><code>>>> from urlparse import urlparse, parse_qs
>>> u = urlparse('http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States')
>>> q = parse_qs(u.query)
>>> q['city']
['New York, NY, United States']
>>> q['city'][0].split(', ')
['New York', ... | 0 | 2016-06-01T22:08:49Z | [
"python",
"django",
"url",
"parameters"
] |
How can I extract City, Region, Country from URL? Django | 37,579,453 | <p>My search field returns something like this:</p>
<blockquote>
<p><a href="http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States" rel="nofollow">http://localhost:8000/search/?city=New+York%2C+NY%2C+United+States</a></p>
</blockquote>
<p>How can I extract City, Region, Country. I've been through this ... | -1 | 2016-06-01T21:55:57Z | 37,579,673 | <p>Simply in the Django view function. The <code>request</code> object has a <code>request.GET</code> property. </p>
<pre><code>def my_view(request):
crc = request.GET.get(city, None)
if crc:
city, region, country = crc.split(',')
# ...
</code></pre>
| 0 | 2016-06-01T22:17:12Z | [
"python",
"django",
"url",
"parameters"
] |
Transform category, start_time, end_time DateFrame for plotting in pandas | 37,579,516 | <p>I have a pandas DataFrame:</p>
<pre><code>df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 32656 entries, 94418 to 2
Data columns (total 8 columns):
customer_id 32656 non-null object
session_id 32656 non-null int64
start 32656 non-null datetime64[ns, Amer... | 1 | 2016-06-01T22:01:22Z | 37,583,844 | <p>I suspect this will work though I haven't verified.</p>
<pre><code>df_count = pd.DataFrame(index=rng)
def count_cats(x, df):
date = x.name[0]
condition1 = df.start <= date
condition2 = df.end >= date
df_slice = df.loc[condition1 & condition2, 'category']
return pd.Series([df_slice.uni... | 0 | 2016-06-02T06:03:19Z | [
"python",
"pandas"
] |
Pandas DatetimeIndex vs to_datetime discrepancies | 37,579,590 | <p>I'm trying to convert a Pandas Series of epoch timestamps to human-readable times. There are at least two obvious ways to do this: <code>pd.DatetimeIndex</code> and <code>pd.to_datetime()</code>. They seem to work in quite different ways:</p>
<pre><code>In [1]: import pandas as pd
In [3]: nanos = pd.Series([1462... | 3 | 2016-06-01T22:08:33Z | 37,593,323 | <p>There is 1 way to convert things, <code>pd.to_datetime()</code>, yes you can directly construct a <code>DatetimeIndex</code>, but it is restrictive on purpose, while <code>to_datetime</code> is quite flexible.</p>
<p>So <code>to_datetime</code> will give you a similar object to what you input, if you input an array... | 2 | 2016-06-02T13:29:48Z | [
"python",
"datetime",
"pandas"
] |
Apache: Errno 13 file permission denied | 37,579,631 | <p>I use AWS EC2 to run my application "Neural network in art". To send images I deploy a website based on flask + virtualenv + apache. After sending the image on the server starts the script, which print each iteration and I want to store it in out.txt</p>
<p><code>__init__.py:</code></p>
<pre><code>#...
def apply_s... | 0 | 2016-06-01T22:13:55Z | 37,579,831 | <p>The problem is that apache runs your code in which will have a different working directory, one which you do not intend to write the file into. You must supply a full path to the file.</p>
<pre><code>f = open('/path/to/my/out.txt', 'w')
</code></pre>
| 0 | 2016-06-01T22:30:08Z | [
"python",
"apache",
"ubuntu",
"flask",
"permission-denied"
] |
ImportError: cannot import name IRCBot | 37,579,651 | <p>I'm importing a module and its all done in the same file:</p>
<pre><code>from irc import IRCBot, run_bot
class greeterBot(IRCBot):
def greet(self, nick, messege, channel):
return 'Hi %s' % nick
def command_patterns(self):
return (
self.ping('^hello', self.greet),
)
... | 1 | 2016-06-01T22:15:36Z | 37,579,731 | <p>Please check what version you have - If you have 32-bits version of package and 64-bits version of Python (or reverse situation) then the import never running .</p>
| 0 | 2016-06-01T22:21:46Z | [
"python",
"import",
"importerror",
"irc"
] |
ImportError: cannot import name IRCBot | 37,579,651 | <p>I'm importing a module and its all done in the same file:</p>
<pre><code>from irc import IRCBot, run_bot
class greeterBot(IRCBot):
def greet(self, nick, messege, channel):
return 'Hi %s' % nick
def command_patterns(self):
return (
self.ping('^hello', self.greet),
)
... | 1 | 2016-06-01T22:15:36Z | 37,579,785 | <p>The problem is that python can't find the class named IRCbot inside irc.
Do you have irc installed? If so, ypu could try to do</p>
<p>from irc.bot import IRCBot</p>
<p>If you don't have irc installed you can install it with pip:</p>
<p>pip install irc</p>
<p>What version of python are you using?</p>
| 0 | 2016-06-01T22:26:13Z | [
"python",
"import",
"importerror",
"irc"
] |
Format numbers as currency in Python | 37,579,712 | <p>I learn from <a href="http://stackoverflow.com/questions/320929/currency-formatting-in-python">Currency formatting in Python</a>, use the <a href="https://docs.python.org/2/library/locale.html" rel="nofollow">locale</a> module to format numbers as currency. For instance,</p>
<pre><code>#! /usr/bin/env python
# -*- ... | 2 | 2016-06-01T22:20:36Z | 37,579,832 | <p><a href="http://babel.pocoo.org/en/latest/numbers.html" rel="nofollow">babel.numbers</a> </p>
<pre><code>In [22]: from babel.numbers format_decimal
In [23]: format_decimal(12345, locale='de_DE')
Out[23]: u'12.345'
In [24]: format_decimal(1.2345, locale='sv_SE')
Out[24]: u'1,234'
</code></pre>
<p>Or in your case ... | 2 | 2016-06-01T22:30:19Z | [
"python",
"locale",
"currency-formatting"
] |
AgglomerativeClustering on a correlation matrix | 37,579,759 | <p>I have a correlation matrix of typical structure that is of size 288x288 that is defined by:</p>
<pre><code>from sklearn.cluster import AgglomerativeClustering
df = read_returns()
correl_matrix = df.corr()
</code></pre>
<p>where read_returns gives me a dataframe with a date index, and columns of the returns of ass... | 0 | 2016-06-01T22:23:33Z | 37,583,140 | <p>Hierarchical clustering supports different "linkage" strategies.</p>
<ul>
<li>single-link: this connects points on the minimum distance to the others in the cluster</li>
<li>complete-link: this connects based on the maximum distance to the cluster</li>
<li>...</li>
</ul>
<p>If you want a high minimum correlation =... | 0 | 2016-06-02T05:12:16Z | [
"python",
"scikit-learn",
"cluster-analysis",
"hierarchical-clustering"
] |
Issues setting up CKAN virtual environment | 37,579,783 | <p>I'm following the <a href="http://docs.ckan.org/en/ckan-1.4.3/prepare-extensions.html" rel="nofollow">Prepare to Use Extensions</a> document and I'm having issues installing CKAN into a virtual environment. </p>
<pre><code>sudo apt-get install virtualenv python-pip mercurial
virtualenv /home/ubuntu/pyenv
. /home/ub... | 1 | 2016-06-01T22:26:05Z | 37,579,901 | <p>If you go to that URL in your browser, you will see it has a pointer to github now:</p>
<blockquote>
<p>This repository has been deleted
Our apologies, but the repository "ckan" has been deleted.
It now lives at <a href="https://github.com/okfn/ckan" rel="nofollow">https://github.com/okfn/ckan</a>.</p>
</bloc... | 0 | 2016-06-01T22:35:52Z | [
"python",
"ubuntu",
"virtualenv",
"ckan"
] |
I need to convert datetime to date without seconds in python | 37,579,802 | <p>I need to convert datetime to date without seconds in python, how to execute this:</p>
<pre><code>from datetime import datetime
dt = datetime.strptime('2016-06-01 16:05:20', '%Y-%m-%d').date()
print dt
</code></pre>
<p>Result:</p>
<pre><code>Traceback (most recent call last):
File "teste.py", line 5, in <mod... | 0 | 2016-06-01T22:27:43Z | 37,580,133 | <p>Even though you're going to discard the time, you still need to include it in your format string, since it exists in the string you're parsing. <code>strptime()</code> doesn't know that you don't care about the time, it just needs to match the input against the format string.</p>
<pre><code>dt = datetime.strptime('... | 0 | 2016-06-01T23:00:04Z | [
"python",
"datetime",
"strptime"
] |
Pandas dataframe grouping by multiple columns and dropping duplicate rows | 37,579,803 | <p>I am trying to do a task (in bioinformatics, TCGA data) using a dataframe of the following form:</p>
<pre><code>df = pd.DataFrame({'ID':['TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0003','TCGA-AB-0002'],
'Reference':[... | 1 | 2016-06-01T22:27:51Z | 37,586,777 | <p>In order to create your new dataframes you can use pandas conditionnal slicing: (in your question you made a mistake on the dataframe <code>NORMAL</code> on the line with index 5, the <code>SampleType</code> should be <code>Normal</code> not <code>Tumor</code>)</p>
<pre><code>NORMAL = df[df['SampleType']=='Normal']... | 1 | 2016-06-02T08:41:38Z | [
"python",
"pandas",
"bioinformatics"
] |
Pandas dataframe grouping by multiple columns and dropping duplicate rows | 37,579,803 | <p>I am trying to do a task (in bioinformatics, TCGA data) using a dataframe of the following form:</p>
<pre><code>df = pd.DataFrame({'ID':['TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0003','TCGA-AB-0002'],
'Reference':[... | 1 | 2016-06-01T22:27:51Z | 37,602,550 | <p>It is still not 100% clear to me what the desired output is. But this seems to do the trick based on my understanding.</p>
<pre><code>import numpy as np
import pandas as pd
df = pd.DataFrame({'ID':['TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0001','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-0002','TCGA-AB-00... | 1 | 2016-06-02T21:37:54Z | [
"python",
"pandas",
"bioinformatics"
] |
Youtube search in Django -> manage.py: error: unrecognized arguments: shell | 37,579,877 | <p><a href="https://developers.google.com/youtube/v3/code_samples/python#search_by_keyword" rel="nofollow">Youtube Code</a></p>
<p>If I use this code in IDLE - everything is ok, but when I use in Django project, i.e. run via <code>python manage.py shell</code> I see the next:</p>
<pre><code>usage: manage.py [--auth_h... | 0 | 2016-06-01T22:33:57Z | 37,592,283 | <p>As I don't need to pass any arguments from command line to the function, I simply removed this:</p>
<pre><code> argparser.add_argument("--q", help="Search term", default="Google")
argparser.add_argument("--max-results", help="Max results", default=25)
args = argparser.parse_args()
</code></pre>
<p>and pass ar... | 0 | 2016-06-02T12:45:40Z | [
"python",
"django",
"youtube",
"oauth-2.0"
] |
Bear and Steady gene - code optimisation(python) | 37,579,917 | <p>I have a string containing A,G,C and T(length n). The string is steady if it contains equal number of A,G,C and T(each n/4 times). I need to find the minimum length of the substring that when replaced makes it steady.
<a href="https://www.hackerrank.com/challenges/bear-and-steady-gene" rel="nofollow">https://www.hac... | 0 | 2016-06-01T22:37:16Z | 37,581,013 | <p>Here's one solution with limited testing done. This should give you some ideas on how to improve your code.</p>
<pre><code>from collections import Counter
import sys
import math
n = int(input())
s1 = input()
s = Counter(s1)
if all(e <= n/4 for e in s.values()):
print(0)
sys.exit(0)
result = math.inf
o... | 0 | 2016-06-02T00:51:20Z | [
"python",
"string",
"python-3.x"
] |
Constructing piecewise function from changepoints in Numpy | 37,580,059 | <p>I want to construct a piecewise function from changepoints in python. I expect my inputs and outputs to be large, so speed is important.</p>
<p>Input:</p>
<ul>
<li>int numpy array: <code>A = [1,7, 1000, 1500]</code></li>
<li>bool numpy array: <code>B = [True, False, True, True, False, True, False, False]</code> wh... | 1 | 2016-06-01T22:52:45Z | 37,580,178 | <pre><code>In [1]: import numpy
In [2]: A = numpy.array([1, 7, 1000, 1500])
In [3]: B = numpy.array([True, False, True, True, False, True, False, False])
In [4]: A[B.cumsum() - 1]
Out[4]: array([ 1, 1, 7, 1000, 1000, 1500, 1500, 1500])
</code></pre>
<p><code>B.cumsum() - 1</code> computes which element of A... | 0 | 2016-06-01T23:04:31Z | [
"python",
"numpy",
"piecewise"
] |
Boto3: Verify if the file has been uploaded using upload_file() | 37,580,092 | <p>I'm making a backup script using boto3 using this line to upload the item:</p>
<pre><code>bucket.upload_file(backup_file_name,bucket_path+backup_file_name)
</code></pre>
<p>How can I verify if this file has really been uploaded to my bucket? I tried to find something using boto3 doc but I didn't found anything. Do... | 1 | 2016-06-01T22:56:16Z | 37,580,244 | <p>It will raise <code>boto3.exceptions.S3UploadFailedError</code>. You can also do a <a href="http://boto3.readthedocs.io/en/latest/reference/services/s3.html#S3.Client.head_object" rel="nofollow"><code>head_object</code></a> request to verify that the object looks like it should. This will raise a <code>botocore.Clie... | 2 | 2016-06-01T23:12:09Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto3"
] |
Boto3: Verify if the file has been uploaded using upload_file() | 37,580,092 | <p>I'm making a backup script using boto3 using this line to upload the item:</p>
<pre><code>bucket.upload_file(backup_file_name,bucket_path+backup_file_name)
</code></pre>
<p>How can I verify if this file has really been uploaded to my bucket? I tried to find something using boto3 doc but I didn't found anything. Do... | 1 | 2016-06-01T22:56:16Z | 37,586,636 | <p>There is few ways to check. First, you should always make sha256 hash for your file. When you upload, remember to put this info inside the Meta part of the object upload script. </p>
<ul>
<li>read the whole file, retrieve the sha256 has from the header meta, and recalculate the has to check it is tally. </li>
<li>A... | 1 | 2016-06-02T08:35:34Z | [
"python",
"amazon-web-services",
"amazon-s3",
"boto3"
] |
Parse currency into numbers in Python | 37,580,151 | <p>I just learnt from <a href="http://stackoverflow.com/questions/37579712/format-numbers-as-currency-in-python">Format numbers as currency in Python</a> that the Python module <a href="http://babel.pocoo.org/en/latest/index.html" rel="nofollow">babel</a> provides <a href="http://babel.pocoo.org/en/latest/numbers.html"... | 3 | 2016-06-01T23:02:43Z | 37,581,152 | <p>Ignore my comment on your question please, i though about it and (i believe) i found what is the <strong>common pattern</strong> of currencies in distinct locales. A currency is always formed of digits and some kind of decimal mark, the decimal mark will be the last non-digit character after which there will be mor... | -1 | 2016-06-02T01:12:38Z | [
"python",
"numbers",
"currency-formatting"
] |
Parse currency into numbers in Python | 37,580,151 | <p>I just learnt from <a href="http://stackoverflow.com/questions/37579712/format-numbers-as-currency-in-python">Format numbers as currency in Python</a> that the Python module <a href="http://babel.pocoo.org/en/latest/index.html" rel="nofollow">babel</a> provides <a href="http://babel.pocoo.org/en/latest/numbers.html"... | 3 | 2016-06-01T23:02:43Z | 37,598,997 | <h2>Using babel</h2>
<p>The babel documentation notes that <a href="http://babel.pocoo.org/en/latest/numbers.html#parsing-numbers" rel="nofollow">the number parsing is not fully implemented yes</a> but they have done a lot of work to get currency info into the library. You can use <code>get_currency_name()</code> and... | 0 | 2016-06-02T17:57:19Z | [
"python",
"numbers",
"currency-formatting"
] |
How to make a field immutable after creation in MongoDB? | 37,580,165 | <p>Use case: I'm writing a backend using MongoDB (and Flask). At the moment this is not using any ORM like Mongoose/Mongothon. I'd like to store the _id of the user which created each document in the document. I'd like it to be impossible to modify that field after creation. The backend currently allows arbitrary u... | 0 | 2016-06-01T23:03:35Z | 38,043,469 | <p>imho there is no know methods to prevent updates inside mongo.
As you can control app behavior, then someone will still able to make this update outside the app. Mongo don't have triggers - which in sql world have the possibility to play as a data guards and prevent field changes.</p>
<p>As you re not using ODM, th... | 1 | 2016-06-26T21:43:20Z | [
"python",
"json",
"node.js",
"mongodb",
"immutability"
] |
Sort a list of cdef objects by attribute in a cdef class | 37,580,268 | <p>I would like to sort the list <code>inner</code> of this class. The list contains objects of a cdef class called <code>Edge</code>. The Edge class contains a member variable called <code>savings</code>. I would like sort the list by this variable.</p>
<pre><code>cdef class Alist:
def __init__(self):
sel... | 1 | 2016-06-01T23:14:19Z | 38,615,228 | <h2>What is going wrong here</h2>
<p>The Python- lambda function can not access the cdef attribute of <code>Edge</code>. If you try to directly access the attribute of a cdef class from python you will get an error unless you add either the <code>readonly</code> (for read access) or the <code>public</code> (for read a... | 0 | 2016-07-27T14:03:37Z | [
"python",
"sorting",
"cython"
] |
numpy Boolean array represenation of an integer | 37,580,272 | <p>What's the easiest way to produce a numpy Boolean array represenation of an integer? For example, map <code>6</code> to <code>np.array([False, True, True], dtype=np.bool)</code>.</p>
| 1 | 2016-06-01T23:14:30Z | 37,580,551 | <p>First, use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.binary_repr.html" rel="nofollow"><code>np.binary_repr</code></a> to get the binary representation of the integer value. Remember to specify the bit-width you desire for your bit array here. I have included a way to programmatically ... | 2 | 2016-06-01T23:47:38Z | [
"python",
"numpy"
] |
numpy Boolean array represenation of an integer | 37,580,272 | <p>What's the easiest way to produce a numpy Boolean array represenation of an integer? For example, map <code>6</code> to <code>np.array([False, True, True], dtype=np.bool)</code>.</p>
| 1 | 2016-06-01T23:14:30Z | 37,580,756 | <p>Maybe it is not the easiest, but a compact way is</p>
<p><code>from numpy import array
array([i for i in bin(5)[2:]]) == '1'
</code></p>
| 1 | 2016-06-02T00:15:49Z | [
"python",
"numpy"
] |
numpy Boolean array represenation of an integer | 37,580,272 | <p>What's the easiest way to produce a numpy Boolean array represenation of an integer? For example, map <code>6</code> to <code>np.array([False, True, True], dtype=np.bool)</code>.</p>
| 1 | 2016-06-01T23:14:30Z | 37,582,642 | <p>Here's an approach using <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.binary_repr.html" rel="nofollow"><code>np.binary_repr</code></a> and <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.fromstring.html" rel="nofollow"><code>np.fromstring</code></a> -</p>
<pre>... | 1 | 2016-06-02T04:25:01Z | [
"python",
"numpy"
] |
numpy Boolean array represenation of an integer | 37,580,272 | <p>What's the easiest way to produce a numpy Boolean array represenation of an integer? For example, map <code>6</code> to <code>np.array([False, True, True], dtype=np.bool)</code>.</p>
| 1 | 2016-06-01T23:14:30Z | 37,583,076 | <p>If <code>n</code> is the integer, the expression <code>(n & (1 << np.arange(int(floor(log(n, 2) + 1))))) > 0</code> will create a boolean array representing the bits, with the least significant bit in the first position.</p>
<p>For example,</p>
<pre><code>In [224]: n = 5
In [225]: from math import fl... | 3 | 2016-06-02T05:06:10Z | [
"python",
"numpy"
] |
python - How to use file as a Queue | 37,580,411 | <p>I need to use a file as a <em>Queue</em> but I don't know how to start (also any other aproach is welcome), because I have a non-secure transmission between my device and a computer, and I need all the data to be saved until it is sent and successfully recieved. The DATA is a list which always holds the same type an... | 0 | 2016-06-01T23:32:24Z | 37,580,653 | <pre><code>#!/usr/bin/python
import time
offset = 0
while True:
infile=open("./log.txt")
infile.seek(offset)
for line in infile:
print line // do something
offset=infile.tell()
infile.close()
time.sleep(10)
</code></pre>
<p>Only updates to log.txt are printed using this method</p>
| 0 | 2016-06-02T00:01:17Z | [
"python",
"file",
"buffer"
] |
How can I call shell_exec() from PHP webhook? | 37,580,432 | <p>I'm having a major issue and I can't find a solution. I currently have a PHP script that accepts a webhook (HTTP POST) as a trigger. Based on variables contained in the POST, an exec('python script') is supposed to run, and return some variables. It works fine when I run it from the command line it works fine, but w... | 1 | 2016-06-01T23:35:21Z | 38,144,268 | <p><strong>Problem</strong></p>
<p>As <a href="http://stackoverflow.com/users/2812842/robbie-averill">Robbie Averill</a> mentioned, most probably you have a permission issue and you can fix it by adding additional permissions to user that is used to run the web server. However, I think it is not a good style to mix <a... | 0 | 2016-07-01T11:26:43Z | [
"php",
"python",
"exec",
"webhooks",
"cgi-bin"
] |
Deserialize json/yaml from binary stream which contains other data | 37,580,545 | <p>Suppose I have a binary stream <code>stream</code> and I generate it as follows.</p>
<pre><code>stream.write('lol'.encode())
yaml.dump(some_obj, stream)
stream.write('awesome'.encode())
</code></pre>
<p>Then do I have to write a custom parser of some sort for the stream or can I recover <code>some_obj</code> as fo... | 0 | 2016-06-01T23:46:36Z | 37,601,684 | <p>You cannot do what you want because the YAML parser consumes the complete stream even if you dummp an explicit end (<code>yaml.dump(some_obj, stream, explicit_end=True)</code> (which essentially insert <code>...\n</code> before <code>awesome</code>) and it also doesn't work when writing <code>---\nawesome</code> (th... | 1 | 2016-06-02T20:38:09Z | [
"python",
"json",
"serialization",
"yaml"
] |
ImportError on Heroku django-registration-redux | 37,580,566 | <p>I have no problem with my apps when it's running locally. But it's happen on heroku. I was successfully deployed my app to heroku but when I open it (My <code>DEBUG</code> still <code>TRUE</code>) it was give me <code>ImportError No module named forms</code> comes from <code>from registration.forms import Registrati... | 0 | 2016-06-01T23:49:53Z | 37,585,710 | <p>Did you follow the guide here <a href="http://django-registration-redux.readthedocs.io/en/latest/quickstart.html" rel="nofollow">http://django-registration-redux.readthedocs.io/en/latest/quickstart.html</a> to install django-registration-redux? Specifically this part:</p>
<pre><code>INSTALLED_APPS = (
'django.c... | 0 | 2016-06-02T07:49:14Z | [
"python",
"django",
"heroku",
"django-registration"
] |
Tensorflow session returns as 'closed' | 37,580,691 | <p>I have successfully ported the <a href="https://www.tensorflow.org/versions/r0.8/tutorials/deep_cnn/index.html" rel="nofollow">CIFAR-10 ConvNet tutorial code</a> for my own images and am able to train on my data and generate Tensorboard outputs etc.</p>
<p>My next step was to implement an evaluation of new data aga... | 0 | 2016-06-02T00:06:38Z | 37,580,866 | <p>From <a href="https://www.tensorflow.org/versions/r0.8/api_docs/python/client.html#Session" rel="nofollow">documentation</a> on Session, a session can be closed with <code>.close</code> command or when using it through a context-manager in <code>with</code> block. I did <code>find tensorflow/models/image/cifar10 | ... | 1 | 2016-06-02T00:30:26Z | [
"python",
"python-3.x",
"tensorflow"
] |
Tensorflow session returns as 'closed' | 37,580,691 | <p>I have successfully ported the <a href="https://www.tensorflow.org/versions/r0.8/tutorials/deep_cnn/index.html" rel="nofollow">CIFAR-10 ConvNet tutorial code</a> for my own images and am able to train on my data and generate Tensorboard outputs etc.</p>
<p>My next step was to implement an evaluation of new data aga... | 0 | 2016-06-02T00:06:38Z | 37,635,037 | <p>It was a simple (but humbling) error in indentation.</p>
<pre><code> summary = tf.Summary()
summary.ParseFromString(sess.run(summary_op))
summary.value.add(tag='Precision @ 1', simple_value=precision)
summary_writer.add_summary(summary, global_step)
</code></pre>
<p>was outside of th... | 0 | 2016-06-04T21:07:31Z | [
"python",
"python-3.x",
"tensorflow"
] |
computing cost of np.random.uniform vs np.random.beta | 37,580,695 | <p>I have an algorithm that uses np.random.uniform I would like to switch to np.random.beta and/or np.random.gamma to improve the efficiency of an approximation. Since the algorithm is already quite time consuming (~8hours) and memory intensive (5 GB per thread) I wanted to check if there was any information on how muc... | 0 | 2016-06-02T00:07:02Z | 37,581,172 | <p>Just test it using ipython:</p>
<pre><code>In [1]: import numpy as np
In [2]: %timeit np.random.random(1000)
100000 loops, best of 3: 9.25 µs per loop
In [3]: %timeit np.random.beta(0.5, 0.5, 1000)
10000 loops, best of 3: 45.3 µs per loop
</code></pre>
<p>This would imply a factor of 5, but it appears to depen... | 1 | 2016-06-02T01:15:51Z | [
"python",
"memory",
"random",
"time"
] |
How can I write a simple Python try block that only check if a function returned as true? | 37,580,805 | <p>Pretty new to Python, trying to use a try/except block that tests if the output of a function was true or not. The function takes a simple input from the user and validates it. I want to do something like this:</p>
<pre><code>try:
if(test_function()):
print('Input from test_function was true.')
except:
... | -3 | 2016-06-02T00:21:46Z | 37,580,828 | <p>This is not a try/except situation; this is a simple <strong>if</strong> statement:</p>
<pre><code>if(test_function()):
print('Input from test_function was true.')
else:
print('Input from test_function was false.')
</code></pre>
<p>Try/except is for code that may raise an exception, such as</p>
<pre><code... | 2 | 2016-06-02T00:24:55Z | [
"python"
] |
How can I write a simple Python try block that only check if a function returned as true? | 37,580,805 | <p>Pretty new to Python, trying to use a try/except block that tests if the output of a function was true or not. The function takes a simple input from the user and validates it. I want to do something like this:</p>
<pre><code>try:
if(test_function()):
print('Input from test_function was true.')
except:
... | -3 | 2016-06-02T00:21:46Z | 37,580,954 | <p>As pointed, it looks like you don't need a <code>try</code>, <code>except</code> block, just a simple <code>if</code>, <code>else</code>. But I have seen some circumstances where you want to raise the exception on a condition and the pattern would be:</p>
<pre><code>try:
if not test_function():
raise Va... | 0 | 2016-06-02T00:43:10Z | [
"python"
] |
Using python, how do I convert dates that are stored as m(m)/dd/yyyy in a csv file to yyyy-mm-dd for use in sqlite? | 37,580,843 | <p>I am working with a csv file that I contains a date field, but the dates are formatted like 1/8/1986 when I need them to be read into a sqlite3 database in this format 1986-8-1 or 1986-08-01. I have seen a lot of people talking about this issue, but I haven't really understood the answers being given. Here is how ... | -1 | 2016-06-02T00:27:09Z | 37,580,898 | <p><code>pip install python-dateutil</code></p>
<p>then</p>
<pre><code>from dateutil.parser import parse as date_parse
fixed_date_string = date_parse(my_date_string).strftime("%Y-%m-%d")
</code></pre>
<p>or just do this ... its probably easier for you</p>
<pre><code>import re
with open("fixed_csv.csv","wb") as f:
... | 2 | 2016-06-02T00:35:11Z | [
"python",
"sqlite",
"date",
"csv",
"sqlite3"
] |
Using python, how do I convert dates that are stored as m(m)/dd/yyyy in a csv file to yyyy-mm-dd for use in sqlite? | 37,580,843 | <p>I am working with a csv file that I contains a date field, but the dates are formatted like 1/8/1986 when I need them to be read into a sqlite3 database in this format 1986-8-1 or 1986-08-01. I have seen a lot of people talking about this issue, but I haven't really understood the answers being given. Here is how ... | -1 | 2016-06-02T00:27:09Z | 37,580,958 | <p>If you don't want to install additional packages you can do following:</p>
<pre><code>>>> from datetime import date
>>> d = '1/8/1986'
>>> date(*reversed([int(x) for x in d.split('/')])).strftime('%Y-%m-%d')
'1986-08-01'
</code></pre>
| 2 | 2016-06-02T00:44:21Z | [
"python",
"sqlite",
"date",
"csv",
"sqlite3"
] |
Using python, how do I convert dates that are stored as m(m)/dd/yyyy in a csv file to yyyy-mm-dd for use in sqlite? | 37,580,843 | <p>I am working with a csv file that I contains a date field, but the dates are formatted like 1/8/1986 when I need them to be read into a sqlite3 database in this format 1986-8-1 or 1986-08-01. I have seen a lot of people talking about this issue, but I haven't really understood the answers being given. Here is how ... | -1 | 2016-06-02T00:27:09Z | 37,581,038 | <p>This is pretty simple with no imports: </p>
<pre><code>olddate="1/21/2010"
m,d,y=map(str,olddate.split('/'))
newdate=y+'-'+m+'-'+d
</code></pre>
| 0 | 2016-06-02T00:54:12Z | [
"python",
"sqlite",
"date",
"csv",
"sqlite3"
] |
Load webpage in Python GUI window | 37,580,852 | <p>I've searched on Google and StackOverflow but am having trouble finding the answer, even though it seems like it should be easy to do.</p>
<p>How can I use Python to load a URL into its own window, rather than in a browser? I imagine this should be trivial in Tkinter or some other GUI package.</p>
| 0 | 2016-06-02T00:28:20Z | 37,581,279 | <p>Yeah. that's very easy with QWebView in PyQt/PySide</p>
<p>You basically instantiate a new QWebView and pass the url to it</p>
<pre><code>QWebView.load(QUrl('http://www.www.pythoncentral.io'))
</code></pre>
<p>you can read more here</p>
<p><a href="http://pythoncentral.io/pyside-pyqt-tutorial-qwebview/" rel="nof... | 1 | 2016-06-02T01:30:34Z | [
"python",
"user-interface"
] |
Counting number of occurrences in Foreign Key relationships | 37,580,880 | <p>I have the following models set up:</p>
<pre><code>class Team(models.Model):
# stuff
class Alliance(models.Model):
# an alliance is made up of 3 teams
teams = models.ManyToManyField(Team)
class Match(models.Model):
# 2 alliances per match
alliances = models.ManyToManyField(Alliance)
# 1 wi... | 2 | 2016-06-02T00:32:34Z | 37,581,406 | <p>Ah, I'm dumb. Solved!</p>
<p>This is the solution:</p>
<pre><code>def most_wins():
matches = Match.objects.all()
count = Counter()
for m in matches:
if m.winner is None:
continue
for team in m.winner.teams.all():
count[team] += 1
return count.most_common(5)
<... | 1 | 2016-06-02T01:49:40Z | [
"python",
"django",
"python-3.x",
"count",
"django-queryset"
] |
Filter in Apache Spark is not working expected | 37,580,907 | <p>I'am executing the code below:</p>
<pre><code>ordersRDD = sc.textFile("/user/cloudera/sqoop_import/orders")
orderItemsRDD = sc.textFile("/user/cloudera/sqoop_import/order_items")
ordersParsedRDD = ordersRDD.filter(lambda rec: rec.split(",")[3] in "CANCELED").map(lambda rec: (int(rec.split(",")[0]), rec))
orderItem... | 1 | 2016-06-02T00:36:25Z | 37,583,141 | <p>I would start by printing the count on ordersJoinOrderItems. If it is bigger than 0, it would then suggest your filter is the culprit.</p>
| 0 | 2016-06-02T05:12:17Z | [
"python",
"apache-spark",
"pyspark"
] |
Moviepy zooming effects need tweaking | 37,580,910 | <p>I would like to zoom a clip to a certain dimension, then stop further zooming. In other words, the clip stop further increasing its size after reaching a certain size, and its better if the clip start zooming from much smaller of its original size, and to a bigger version. I am using moviepy module. With the followi... | 1 | 2016-06-02T00:36:55Z | 37,602,098 | <p>This is a way of achieving what you want. The key is to define the resizing logic in a named function instead of using a <code>lambda</code>.</p>
<pre><code>import os
from moviepy.editor import *
def resize_func(t):
if t < 4:
return 1 + 0.2*t # Zoom-in.
elif 4 <= t <= 6:
return 1... | 1 | 2016-06-02T21:05:59Z | [
"python",
"animation",
"video",
"moviepy"
] |
Define a function head inside a conf file | 37,580,985 | <p>I am using a dictionary/get construct as a switch case in Python. It looks similar to this one:</p>
<pre><code>def switch_function(pluginID, param):
switcher = {
'someid': somefunction(param),
}
return switch_function.get(pluginID, None)
</code></pre>
<p>However, i want to to extend the dictionary by another k... | 1 | 2016-06-02T00:47:02Z | 37,581,097 | <p>The following example will give you an <code>exec</code> clause. Your <code>dict</code> should extend to something like this:</p>
<pre><code>switcher[config["aSection"]["anotherid"])] = func
</code></pre>
<p>Then you need to define func to look something like this:</p>
<pre><code>#CONF
#[aSection]
#pluginid='anot... | 1 | 2016-06-02T01:03:41Z | [
"python",
"dictionary",
"switch-statement",
"python-config"
] |
Non-global variable recognized/accepted in defined function | 37,581,126 | <p>I am learning and experimenting with Python and I accidentally found this very strange (to me) case. I searched as much as I could but could not find anything other than how to use global and local variables or how to use the 'for' loop. I have the following code (Python 3.2 on Android Qpython3), modified for simpli... | 1 | 2016-06-02T01:08:20Z | 37,581,186 | <p>You defined <code>i</code> in the module scope, which lets you read <code>i</code> in function scope by default. You only need to use <code>global i</code> inside <code>get_number</code> if you want to <em>modify</em> <code>i</code>.</p>
| 0 | 2016-06-02T01:18:21Z | [
"python",
"for-loop",
"global"
] |
Non-global variable recognized/accepted in defined function | 37,581,126 | <p>I am learning and experimenting with Python and I accidentally found this very strange (to me) case. I searched as much as I could but could not find anything other than how to use global and local variables or how to use the 'for' loop. I have the following code (Python 3.2 on Android Qpython3), modified for simpli... | 1 | 2016-06-02T01:08:20Z | 37,581,254 | <p>Scope resolution for variable follows the LEGB rule, i.e. python tries to find a variable in the following scopes (decreasing precedence):</p>
<p><code>Local -> Enclosed -> Global -> Built-in</code></p>
<p>In your case, <code>i</code> is only defined in the enclosed scope.</p>
<p>For further details see ... | 1 | 2016-06-02T01:27:21Z | [
"python",
"for-loop",
"global"
] |
Connect line of scatter plot on pandas DataFrame | 37,581,145 | <p>I'd like to add lines between dots of a scatter plot drawn by pandas. I tried this, but does not work. Can I put lines on a scatter plot?</p>
<pre><code>pd.DataFrame([[1,2],[10,20]]).plot(kind="scatter", x=0, y=1, style="-")
pd.DataFrame([[1,2],[10,20]]).plot.scatter(0,1,style="-")
</code></pre>
<p><a href="http:/... | 0 | 2016-06-02T01:11:55Z | 37,581,970 | <p>A solution is to replot the line on top of the scatter:</p>
<pre><code>df = pd.DataFrame([[1,2],[10,20]])
ax = df.plot.scatter(x=0, y=1, style='b')
df.plot.line(x=0, y=1, ax=ax, style='b')
</code></pre>
<p>In this case, forcing points and lines both to be blue.</p>
<p>If you don't need the properties of the scatt... | 0 | 2016-06-02T03:07:59Z | [
"python",
"pandas",
"matplotlib"
] |
New to Python 3.4+ Scripting and writing JSON text files and saving them | 37,581,216 | <p>I'm currently trying to write a script in Python that can manipulate JSON ".txt" files within a folder and saving it as a new JSON ".txt" file within the same folder. I already know how to manipulate the file, but I'd need to manually type in the actual path. Is there a way to just type in the folder name and the ... | 0 | 2016-06-02T01:22:27Z | 37,581,328 | <p>Yes you can easily do that with the os module</p>
<pre><code>import os
folder = input('please enter the folder:')
file = input('enter the filename:')
print('C'+os.path.join(os.sep, folder, file))
</code></pre>
<p><code>os.path.join</code> constructs the path to the file by joining the strings you supplied to it... | 1 | 2016-06-02T01:38:03Z | [
"python",
"json"
] |
New to Python 3.4+ Scripting and writing JSON text files and saving them | 37,581,216 | <p>I'm currently trying to write a script in Python that can manipulate JSON ".txt" files within a folder and saving it as a new JSON ".txt" file within the same folder. I already know how to manipulate the file, but I'd need to manually type in the actual path. Is there a way to just type in the folder name and the ... | 0 | 2016-06-02T01:22:27Z | 37,581,385 | <p>For the input, relative paths may be sufficient. For the output, just generate the filename from the input filename by adding '_edit' using <code>os.path.splitext()</code>.</p>
<pre><code>import json
import os
def edit_json(filename):
with open(filename, 'r+') as f:
simple_data = json.load(f)
s... | 0 | 2016-06-02T01:47:11Z | [
"python",
"json"
] |
Nested Bazel Projects | 37,581,247 | <p>I'm trying to build a project that uses TensorFlow Serving, so I made a directory my_dir with a WORKSPACE file, cloned the serving repo into it, put my custom files into a directory my_project, configured tensorflow within tensorflow_serving, built tensorflow serving from my_dir/serving with</p>
<pre><code>bazel bu... | 1 | 2016-06-02T01:26:01Z | 37,947,244 | <p>I have tensorflow serving in a folder and my project in another. This is my WORKSPACE file:</p>
<pre><code>workspace(name = "my_project")
local_repository(
name = "org_tensorflow",
path = __workspace_dir__ + "/tf-serving/tensorflow/",
)
local_repository(
name = "tf_serving",
path = __workspace_dir__ + "/t... | 1 | 2016-06-21T14:30:16Z | [
"python",
"tensorflow",
"bazel",
"tensorflow-serving"
] |
Nested Bazel Projects | 37,581,247 | <p>I'm trying to build a project that uses TensorFlow Serving, so I made a directory my_dir with a WORKSPACE file, cloned the serving repo into it, put my custom files into a directory my_project, configured tensorflow within tensorflow_serving, built tensorflow serving from my_dir/serving with</p>
<pre><code>bazel bu... | 1 | 2016-06-02T01:26:01Z | 38,169,822 | <p>I had to also add </p>
<pre><code>--genrule_strategy=standalone --spawn_strategy=standalone
</code></pre>
<p>to the build command in order to get the dependencies fixed, it compiles nicely when run from the tf-serving workspace, but as soon as i linked tf-serving as a submodule and ran it from my workspace I had e... | 0 | 2016-07-03T12:11:28Z | [
"python",
"tensorflow",
"bazel",
"tensorflow-serving"
] |
Filter blank CharField in Django Haystack's SearchQuerySet | 37,581,343 | <p>I need to return all entries in a SearchQuerySet where a certain CharField is blank i.e. an empty string.</p>
<p>In my search_indexes.py I have:</p>
<pre><code>sometext = indexes.CharField(model_attr='sometext')
</code></pre>
<p>I've tried filtering using the usual SQS syntax:</p>
<pre><code>SearchQuerySet().fil... | 2 | 2016-06-02T01:39:53Z | 37,581,886 | <p>You can do this:</p>
<pre><code> SomeQuerySet().filter(sometext='')
</code></pre>
| 0 | 2016-06-02T02:57:19Z | [
"python",
"django",
"django-haystack",
"whoosh"
] |
Filter blank CharField in Django Haystack's SearchQuerySet | 37,581,343 | <p>I need to return all entries in a SearchQuerySet where a certain CharField is blank i.e. an empty string.</p>
<p>In my search_indexes.py I have:</p>
<pre><code>sometext = indexes.CharField(model_attr='sometext')
</code></pre>
<p>I've tried filtering using the usual SQS syntax:</p>
<pre><code>SearchQuerySet().fil... | 2 | 2016-06-02T01:39:53Z | 38,855,736 | <p>try this, it works for me:</p>
<pre><code>from haystack.inputs import Raw
r = SearchQuerySet()
r.exclude(sometext=Raw('*'))
</code></pre>
| 0 | 2016-08-09T16:11:39Z | [
"python",
"django",
"django-haystack",
"whoosh"
] |
Memory issues when writing to file from MySQL | 37,581,407 | <pre><code>db.connect()
sentenceTB = sentenceTB.select()
for i, sentence in enumerate(sentenceTB):
with open('./commentary/sentence%i.txt' %i, 'w', encoding='utf-8') as f:
f.write(sentence.SNTENC)
db.close()
</code></pre>
<p>I use this code to connect to the database, select a table and write everything th... | 0 | 2016-06-02T01:49:51Z | 37,581,442 | <p>Do you need to close the cursor? It looks like you're opening a new one with each iteration, which would explain the lack of memory after a few hundred thousand iterations.</p>
<p>db.connect()
sentenceTB = sentenceTB.select()
for i, sentence in enumerate(sentenceTB):
with open('./commentary/sentence%i.txt' %i,... | 0 | 2016-06-02T01:55:14Z | [
"python",
"mysql",
"memory"
] |
Correcting to the correct URL | 37,581,454 | <p>I have written a simple script to access JSON to get the keywords needed to be used for the URL.</p>
<p>Below is the script that I have written:</p>
<pre><code>import urllib2
import json
f1 = open('CatList.text', 'r')
f2 = open('SubList.text', 'w')
lines = f1.read().splitlines()
for line in lines:
url ='h... | 0 | 2016-06-02T01:56:25Z | 37,581,478 | <p>use <code>urllib.quote()</code> to replace special characters in an url:</p>
<p>Python 2:</p>
<pre><code>import urllib
line = 'Category:Branches of geography'
url ='https://en.wikipedia.org/w/api.php?action=query&format=json&list=categorymembers&cmtitle=' + urllib.quote(line) + '&cmlimit=100'
</cod... | 1 | 2016-06-02T01:59:52Z | [
"python",
"json",
"regex",
"python-2.7"
] |
Combining multiple CSV files into 1 | 37,581,507 | <p>I have a python code that takes multiple text files as input and generates output in separate CSV file so if my text files are ABC.txt and XYX.txt then my code is generating output in 2 CSV files ABC.csv and XYX.csv. My ultimate goal is get one single CSV file with all the outputs. Since I am more comfortable with s... | 0 | 2016-06-02T02:03:16Z | 37,581,554 | <p>Modifying your existing code as little as possible ... you simply need to open the csv file before entering your loop that reads the text files:</p>
<pre><code>...
path = 'C:/TEMP/*.html'
file = glob.glob(path)
# !! open our output csv
writer = csv.writer(open('our-merged-data', mode='w'))
# iterate over the ... | 0 | 2016-06-02T02:10:19Z | [
"python",
"csv"
] |
Trim an ordered dict to the last x items | 37,581,540 | <p>I'm trying to trim an ordered dict to the last x items.</p>
<p>I have the following code, which works but doesn't seem very pythonic. </p>
<p>Is there a better way of doing this?</p>
<pre><code>import collections
d = collections.OrderedDict()
# SNIP: POPULATE DICT HERE!
d = collections.OrderedDict(d.items()[-3:])... | 1 | 2016-06-02T02:07:57Z | 37,581,632 | <p>If you wish to trim the dictionary in place, then you can pop the offending items:</p>
<pre><code>for k in d.keys()[:-3]:
d.pop(k)
</code></pre>
<p>(On python 3, you'll need to convert <code>.keys()</code> to a list).</p>
<p>If you're wishing to create a new <code>OrderedDict</code>, then its not clear quite ... | 1 | 2016-06-02T02:22:05Z | [
"python",
"python-2.7"
] |
Trim an ordered dict to the last x items | 37,581,540 | <p>I'm trying to trim an ordered dict to the last x items.</p>
<p>I have the following code, which works but doesn't seem very pythonic. </p>
<p>Is there a better way of doing this?</p>
<pre><code>import collections
d = collections.OrderedDict()
# SNIP: POPULATE DICT HERE!
d = collections.OrderedDict(d.items()[-3:])... | 1 | 2016-06-02T02:07:57Z | 37,581,657 | <p>This works a bit faster:</p>
<pre><code>for k in range(len(d) - x) : data.popitem(last = False)
</code></pre>
<p>Not really sure how pythonic it is though.</p>
<p>Benefits include not having to cast create a new OrderedDict object, and not having to look at keys or items. </p>
| 1 | 2016-06-02T02:26:49Z | [
"python",
"python-2.7"
] |
Searching for a unique word in a string | 37,581,591 | <p>I almost write a program that can perform multiple task on GEDCOM file (file that hold information about your family tree). </p>
<p>I face only one problem though; there are some lines like this:</p>
<pre><code>0 @F8@ FAM
1 FAMC @F5@
1 FAMS @F5@
</code></pre>
<p>Now I want to extract the code which starts from @ ... | 1 | 2016-06-02T02:15:17Z | 37,581,723 | <p>You can do this using a regular expression (word boundaries), and <a href="https://docs.python.org/2/library/re.html#re.RegexObject.search" rel="nofollow"><code>re.search()</code></a>:</p>
<pre><code>lines = [
"0 @F8@ FAM",
"1 FAMC @F5@",
"1 FAMS @F5@"
]
for line in lines:
if re.search(r'\bFAM\b', ... | 1 | 2016-06-02T02:35:16Z | [
"python"
] |
Searching for a unique word in a string | 37,581,591 | <p>I almost write a program that can perform multiple task on GEDCOM file (file that hold information about your family tree). </p>
<p>I face only one problem though; there are some lines like this:</p>
<pre><code>0 @F8@ FAM
1 FAMC @F5@
1 FAMS @F5@
</code></pre>
<p>Now I want to extract the code which starts from @ ... | 1 | 2016-06-02T02:15:17Z | 37,581,882 | <p>You could use this:</p>
<pre><code> for l in lines:
for a in l:
if(a[0]=="@" and a[-1]=="@"):
print(a)
</code></pre>
| 0 | 2016-06-02T02:56:52Z | [
"python"
] |
KeyError in Django | 37,581,600 | <p>newbie to Django here, i'm creating a clone of fiverr.com as a project.</p>
<p>There's a header in my base.html with category titles that if I click, should filter out only the gigs in the relevant category for display. </p>
<p>What happens is that it always redirects to home regardless. I have done some testing a... | 0 | 2016-06-02T02:16:55Z | 37,581,729 | <p>The view is receiving a slug value in <code>link</code> parameter. So, you should redefine the <code>categories</code> dictionary:</p>
<pre><code>def category(request, link):
categories = {
"graphics-design": "GD",
"digital-marketing": "DM",
"video-animation": "VA",
"music-audio": "MA",
"prog... | 2 | 2016-06-02T02:35:43Z | [
"python",
"django",
"keyerror"
] |
KeyError in Django | 37,581,600 | <p>newbie to Django here, i'm creating a clone of fiverr.com as a project.</p>
<p>There's a header in my base.html with category titles that if I click, should filter out only the gigs in the relevant category for display. </p>
<p>What happens is that it always redirects to home regardless. I have done some testing a... | 0 | 2016-06-02T02:16:55Z | 37,582,737 | <p>What is the URL that you are entering? It must be because the 'link' parameter did not find any key from your 'categories' dictionary. </p>
<p>Something like this(try it on your python command line):</p>
<pre><code>>>> x = {'name': 'dean'}
>>> x['xx']
Traceback (most recent call last):
File "&l... | 1 | 2016-06-02T04:35:41Z | [
"python",
"django",
"keyerror"
] |
Matplotlib not recognized as a module when importing in Python | 37,581,602 | <p>I've been attempting to install Matplotlib for a graphing project in Python. In accordance with recommendation from the Matplotlib website, I installed Anaconda as a pre-packaged python distributor. Anaconda seems to have installed correctly.
To install matplotlib, I typed in the command line:</p>
<pre><code>pip in... | 0 | 2016-06-02T02:17:22Z | 37,581,768 | <p>Make sure your version of pip corresponds to your version of python. One way to do this is the following:</p>
<pre><code>python -m pip install matplotlib
</code></pre>
<p>The -m for module means that it will look in the site-packages for that python for the pip module.</p>
<p>You can also do:</p>
<pre><code>>... | 0 | 2016-06-02T02:41:46Z | [
"python",
"matplotlib"
] |
Selenium Error: BadStatusLine | 37,581,625 | <p>Hi I am new in Selenium Webdriver and I am currently creating a test case for a specific function.</p>
<p>I have a current test case that is already working for another function, but when I include a new test case and run it. I receive an error: <code>BadStatusLine</code>.</p>
<p>Also when I run the individual tes... | 1 | 2016-06-02T02:21:06Z | 37,706,209 | <p>I'm not sure, but I'll make a guess. Somehow, browser dies while you perform such actions like pressing buttons, clicking.</p>
<p>It's an error raised by httplib (low-level python http library), means that server inside browser didn't responded any of known http status codes (200, 300, 500, etc.), and instead, the ... | 0 | 2016-06-08T15:01:08Z | [
"python",
"selenium",
"webdriver"
] |
getting the id from a foreignkey relationship django | 37,581,630 | <p>I want to get the id or pk of a ForeignKey relationship <strong>post_comment</strong> but I've tried many different ways to catch it and i do not have any good result, please guys give me a hand in this situation</p>
<blockquote>
<p>In <em>views.py</em></p>
</blockquote>
<pre><code>class createComment(View):
... | 0 | 2016-06-02T02:21:56Z | 37,581,669 | <p>You can pass a primary key in the url, and then use it in your class as one way.</p>
<p><code>kwargs.get(pk name)</code></p>
<p>You could change post to:</p>
<pre><code>def post(self, request, *args, **kwargs)
</code></pre>
<p>You then can't just assign <code>obj.post_comment = kwargs.get(pk)</code> you have to ... | 0 | 2016-06-02T02:28:36Z | [
"python",
"django"
] |
getting the id from a foreignkey relationship django | 37,581,630 | <p>I want to get the id or pk of a ForeignKey relationship <strong>post_comment</strong> but I've tried many different ways to catch it and i do not have any good result, please guys give me a hand in this situation</p>
<blockquote>
<p>In <em>views.py</em></p>
</blockquote>
<pre><code>class createComment(View):
... | 0 | 2016-06-02T02:21:56Z | 37,581,796 | <p>I don't know how works class based views but I can tell you that self.pk does not exist in class based view, you would try get form instance and get the I'd field from this instance... </p>
| 0 | 2016-06-02T02:45:25Z | [
"python",
"django"
] |
Sage ('Python-like' language) Attribute error "IntegerListsLex_with_category.element_class" object | 37,581,680 | <p>Given an integer k, I have programmed a way to take all partitions of k such that</p>
<p>(1) each partition has at most n entries (where n is also given)</p>
<p>(2) each partition does not have any repeated odd numbers.</p>
<p>I also categorized the list of these partitions in descending order. However, I am unab... | 0 | 2016-06-02T02:29:47Z | 37,582,212 | <p>To answer my own question, the suitable replacement for the bottom three lines of code is the following: </p>
<pre><code># Convert each partition from IntegerListsLex_with_category.element object to list
C = []
for i in range(0, len(Proper_Part)):
C.append(list(Proper_Part[i]))
while len(C[i]) < n:
... | 0 | 2016-06-02T03:38:19Z | [
"python",
"partition",
"sage"
] |
How to use redirect with parameter in Django? | 37,581,839 | <p>I have this function in views.py:</p>
<pre><code>def detel_kar(request, id):
detel = {}
detel['detels'] = DipPegawai.objects.filter(PegID=id)
detel['kels']=DipKeluargaPeg.objects.filter(PegID_id=id)
return render(request, 'karyawan/detel_kar.html', detel)
</code></pre>
<p>I then have a function to inse... | 0 | 2016-06-02T02:50:20Z | 37,581,946 | <p>In your <code>urls.py</code>, you have defined:</p>
<pre><code>url(r'^karyawan/detel_kar/(?P<id>\d+)/$',views.detel_kar, name='detel_karyawan'),
</code></pre>
<p>i.e., the view that calls the function <code>detel_kar()</code> is named <code>'detel_karyawan'</code>. This is the name you need to use in your re... | 1 | 2016-06-02T03:05:00Z | [
"python",
"django"
] |
Unable to locate the installed graph-tool package in Python | 37,581,880 | <p>I spent 1 hr 30mins to install graph-tool package. Installation declared that it was successful. When I tried to import it says "no module by name graph_tool..." I guess I am missing the path or link to this module. How to link or import? </p>
<p>Also, when I ran the command "pip freeze" it does not show the graph... | 0 | 2016-06-02T02:56:40Z | 37,604,141 | <p>You are probably using the system's python, whereas graph-tool was installed for macport's python. You should call the interpreter corresponding to macport's version, usually <code>/usr/local/bin/python</code>.</p>
| 0 | 2016-06-03T00:24:35Z | [
"python",
"graph-tool"
] |
Unable to locate the installed graph-tool package in Python | 37,581,880 | <p>I spent 1 hr 30mins to install graph-tool package. Installation declared that it was successful. When I tried to import it says "no module by name graph_tool..." I guess I am missing the path or link to this module. How to link or import? </p>
<p>Also, when I ran the command "pip freeze" it does not show the graph... | 0 | 2016-06-02T02:56:40Z | 39,461,891 | <p>Python modules have been installed but the site-packages may not be
in your Python sys.path, so you will not be able to import the modules
this formula installed. If you plan to develop with these modules,
please run like this:</p>
<pre><code>mkdir -p /Users/myname/Library/Python/2.7/lib/python/site-packages
echo ... | 0 | 2016-09-13T03:42:54Z | [
"python",
"graph-tool"
] |
Django: using more than one database with inspectdb? | 37,581,885 | <p>My settings file's database section looks like this:</p>
<pre><code>DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'C:/Users/Desktop/test.db'
},
'blah':{
'ENGINE': 'django.db.backends.sqlite3',
'NAME': 'C:/Users/Desktop/test2.db'
}
}
</code... | 1 | 2016-06-02T02:57:15Z | 37,581,914 | <p>From the <a href="https://docs.djangoproject.com/en/1.9/ref/django-admin/#inspectdb" rel="nofollow">documentation</a>:</p>
<blockquote>
<p><code>--database DATABASE</code></p>
<p>Specifies the database to introspect. Defaults to <code>default</code>.</p>
</blockquote>
<p>So you can inspect your second datab... | 2 | 2016-06-02T03:00:58Z | [
"python",
"django",
"sqlite",
"inspectdb"
] |
Python Classes Inheritance | 37,581,930 | <p>I am having a bit trouble understanding python's mro(Method resolution order). Python operates from left to right. So as per my understanding the order of calling for M should be.
M, B, A, Z, X, Y</p>
<pre><code>class X: pass
class Y: pass
class Z: pass
class A(X,Y): pass
class B(Y,Z): pass
class M(B,A,Z): pass
... | 1 | 2016-06-02T03:03:42Z | 37,584,986 | <p>mro has been based on C3 algorithm since Python2.3, and 'merge' is core of that algorithm. <a href="https://www.python.org/download/releases/2.3/mro/" rel="nofollow">how merge works</a>.
According to your code, here we can list how to get mro(M):</p>
<pre><code>mro(M) = [M] + merge(mro(B), mro(A), mro(Z), [B,A,Z]) ... | 2 | 2016-06-02T07:11:20Z | [
"python",
"class",
"inheritance",
"method-resolution-order"
] |
Can one function have multiple names in Python | 37,582,050 | <p>I'm developing a bot on Python (2.7, 3.4). I defined a about 30+ dynamic functions which to be used based on bot commands. While development, since not all functions are done, I have to define for them an empty functions (if I not define then code won't run) like this: </p>
<pre><code>def c_about():
return
def... | 0 | 2016-06-02T03:18:40Z | 37,582,077 | <p>Yes, it's perfectly possible since defined functions are stored in variables like everything else.</p>
<pre><code>def foo():
pass
baz = bar = foo
</code></pre>
<p>There is still some metadata relating to the original function (<code>help(bar)</code> will still mention <code>foo</code>), but it doesn't affect ... | 3 | 2016-06-02T03:22:14Z | [
"python",
"function"
] |
Can one function have multiple names in Python | 37,582,050 | <p>I'm developing a bot on Python (2.7, 3.4). I defined a about 30+ dynamic functions which to be used based on bot commands. While development, since not all functions are done, I have to define for them an empty functions (if I not define then code won't run) like this: </p>
<pre><code>def c_about():
return
def... | 0 | 2016-06-02T03:18:40Z | 37,582,091 | <p>Functions do not intern (i.e., automatically share <a href="https://en.wikipedia.org/wiki/Flyweight_pattern" rel="nofollow">multiple references</a> to the same immutable object), but can share the same name:</p>
<pre><code>>>> def a(): pass
...
>>> a
<function a at 0x101c892a8>
>>>... | 0 | 2016-06-02T03:23:46Z | [
"python",
"function"
] |
Can one function have multiple names in Python | 37,582,050 | <p>I'm developing a bot on Python (2.7, 3.4). I defined a about 30+ dynamic functions which to be used based on bot commands. While development, since not all functions are done, I have to define for them an empty functions (if I not define then code won't run) like this: </p>
<pre><code>def c_about():
return
def... | 0 | 2016-06-02T03:18:40Z | 37,582,137 | <p>Yes, it is possible, and it is even possible to store them in lists using loops. For instance:</p>
<pre><code>l = []
for i in range(10):
l.append(lambda: None)
</code></pre>
<p>And you can reference any of them through indices like <code>l[index]()</code></p>
<p>For example:</p>
<pre><code>c_events = 0
c_abo... | 1 | 2016-06-02T03:28:03Z | [
"python",
"function"
] |
GAE NDB Datastore new feature: Access Datastore entities from other GAE app | 37,582,110 | <p>Reading the new documentation of GAE NDB Datastore:
<a href="https://cloud.google.com/appengine/docs/python/ndb/modelclass#class_methods">https://cloud.google.com/appengine/docs/python/ndb/modelclass#class_methods</a></p>
<blockquote>
<pre><code>get_by_id(id, parent=None, app=None, namespace=None, **ctx_options)
</... | 8 | 2016-06-02T03:25:52Z | 39,982,141 | <p>Currently, ndb doesn't use the Cloud Datastore API and in its normal mode of operation can't connect to another app's Datastore - it connects natively to the Datastore of the app the code is running on. </p>
<p>You can, however, use the <a href="https://cloud.google.com/appengine/docs/python/tools/remoteapi" rel="n... | 0 | 2016-10-11T16:28:08Z | [
"python",
"google-app-engine",
"google-cloud-datastore"
] |
Python - return or print none types on exception | 37,582,131 | <pre><code> return str(self.id)+"-Vacancy for "+self.title+" at "+self.company.company_name or str(self.id)+"-Vacancy for "+self.title or self.id
</code></pre>
<p>I have a few variables some of which can be of None type. How can I print them without throwing exceptions or having try catch blocks. </p>
| 0 | 2016-06-02T03:27:36Z | 37,582,222 | <p>You could build a response string like the following</p>
<pre><code>ret = ""
ret += str(self.id) if self.id is not None else ""
ret += "-Vacancy for "
ret += self.title if self.title is not None else ""
ret += self.company.company_name if self.company.company_name is not None else ""
return ret
</code></pre>
<p>Or... | 1 | 2016-06-02T03:39:40Z | [
"python"
] |
The D+J programming challenge from Kattis | 37,582,134 | <p>The problem is as follows:</p>
<blockquote>
<p>Dick is d=12 years old. When we say this, we mean that it is at least twelve and not yet thirteen years since Dick was born.</p>
<p>Dick and Jane have three pets: Spot the dog, Puff the Cat, and Yertle
the Turtle. Spot was s years old when Puff was born; Puff ... | 2 | 2016-06-02T03:27:51Z | 37,606,207 | <p>Don't use float arithmetics, work with integers.</p>
<p>Let's denote <code>D+J = DJ</code>, Spot's age <code>S</code>, Puff's age <code>P</code>, Yertle's age <code>Y</code></p>
<p>Let's Spot birthday time is zero, so Puff was born in interval <code>[s, s+1)</code>, Yertle was born in interval <code>[y, y+1)</cod... | 2 | 2016-06-03T04:54:13Z | [
"python",
"algorithm",
"math",
"equation-solving"
] |
nesting multiple dictionaries, possibly lists? | 37,582,177 | <p>I am trying to build a python program to take a users input of the year of the car, and after that the model (no need for the make it will only contain fords). And with the year and model, the program will reference to the correct year and model and get the corresponding capacity information of the vehicle (engine o... | 0 | 2016-06-02T03:34:19Z | 37,582,541 | <p>Using dictionary is a good idea here. But your code doesn't look right. Use this format:</p>
<p>car_list = {'1998' : {'accord': {'oil' : '4.0 qts', 'coolant': '2 gals'}, 'civic': {'oil': '4.5 qts', 'coolant': '3 gals'}}}</p>
<p>print(car_list['1998']['civic']['oil'])</p>
| 0 | 2016-06-02T04:12:14Z | [
"python",
"python-3.x",
"dictionary",
"nested"
] |
nesting multiple dictionaries, possibly lists? | 37,582,177 | <p>I am trying to build a python program to take a users input of the year of the car, and after that the model (no need for the make it will only contain fords). And with the year and model, the program will reference to the correct year and model and get the corresponding capacity information of the vehicle (engine o... | 0 | 2016-06-02T03:34:19Z | 37,582,613 | <p>You can store all the information in a nested dictionary, I think that's the best way. The dictionary can look like this:</p>
<pre><code>car_list = {"1998":{"ka":["4.0 qts", "2 gals"],
"fiesta":["3.0 qts", "2.3 gals"]},
"2001":{"kuga":["3.3 qts", "3 gals"],
"mon... | 0 | 2016-06-02T04:20:57Z | [
"python",
"python-3.x",
"dictionary",
"nested"
] |
nesting multiple dictionaries, possibly lists? | 37,582,177 | <p>I am trying to build a python program to take a users input of the year of the car, and after that the model (no need for the make it will only contain fords). And with the year and model, the program will reference to the correct year and model and get the corresponding capacity information of the vehicle (engine o... | 0 | 2016-06-02T03:34:19Z | 37,583,586 | <p>Simple program that may solve your problem (in python3): </p>
<pre><code>model=input("model:")
year=input("year:")
query={model1:{year1:specs1,year2:specs2 ... }, model2:{ ... } ... }
print(query[model][year])
</code></pre>
<p>The specs could be either list or dictionary. It depends on how you want to use the data... | 2 | 2016-06-02T05:46:22Z | [
"python",
"python-3.x",
"dictionary",
"nested"
] |
Adding Keyword with count of occurrence in sheet2 to existing excelfile from sheet1 with pandas python | 37,582,198 | <p>I am fetching data from web into an excel sheet using pandas & able to save it to sheet 1, now i want to fetch data of a particular column into sheet 2 of same excel but want to put only the Name of Keyword & number of times that keyword appear in that column</p>
<p>For Example ,I have a column with Title a... | 1 | 2016-06-02T03:36:13Z | 37,582,443 | <p>You asked a <a href="http://stackoverflow.com/questions/37575008/adding-sheet2-to-existing-excelfile-from-data-of-sheet1-with-pandas-python">similar question</a> on adding data to a second excel sheet. Perhaps you can address there any issues around the <code>to_excel()</code> part.</p>
<p>On the category count, yo... | 1 | 2016-06-02T04:02:12Z | [
"python",
"excel",
"pandas"
] |
Adding Keyword with count of occurrence in sheet2 to existing excelfile from sheet1 with pandas python | 37,582,198 | <p>I am fetching data from web into an excel sheet using pandas & able to save it to sheet 1, now i want to fetch data of a particular column into sheet 2 of same excel but want to put only the Name of Keyword & number of times that keyword appear in that column</p>
<p>For Example ,I have a column with Title a... | 1 | 2016-06-02T03:36:13Z | 37,588,559 | <p>As answered by <a href="http://stackoverflow.com/users/1494637/stefan">Stefan</a>, using <code>value_counts()</code> over the designated column would do.</p>
<p>Since you are saving multiple DataFrames to a single workbook, I'd use <code>pandas.ExcelWriter</code>:</p>
<pre><code>import pandas as pd
writer = pd.Ex... | 0 | 2016-06-02T09:58:36Z | [
"python",
"excel",
"pandas"
] |
How to get data from Object Oriented Programming to mySQL? | 37,582,199 | <p>How I can pass the data from object oriented programming to mysql in python? Do I need to make connection in every class?</p>
<p>Update:</p>
<p>This is my object orinted</p>
<pre><code>class AttentionDataPoint(DataPoint):
def __init__ (self, _dataValueBytes):
DataPoint._init_(self, _dataValueBytes)
... | 1 | 2016-06-02T03:36:32Z | 37,584,684 | <p>I am thinking of something like a class that has a function for connection and you just pass the instance of that class to every class where you need the connection (here the db instance), or may be not!
It's just an idea that I used in a other languages.</p>
| 0 | 2016-06-02T06:53:35Z | [
"python",
"mysql"
] |
How to get data from Object Oriented Programming to mySQL? | 37,582,199 | <p>How I can pass the data from object oriented programming to mysql in python? Do I need to make connection in every class?</p>
<p>Update:</p>
<p>This is my object orinted</p>
<pre><code>class AttentionDataPoint(DataPoint):
def __init__ (self, _dataValueBytes):
DataPoint._init_(self, _dataValueBytes)
... | 1 | 2016-06-02T03:36:32Z | 37,585,020 | <p>A few options:</p>
<ul>
<li>Implement a save/load method for each DataPoint child to build the select/insert/update sql commands according with the needs of each class. Here is a basic tutorial: <a href="http://www.tutorialspoint.com/python/python_database_access.htm" rel="nofollow">Python MySQL Database Access</a>... | 0 | 2016-06-02T07:12:57Z | [
"python",
"mysql"
] |
Why does Python take O(n) time to remove the first element from a list? | 37,582,225 | <p>The <a href="https://wiki.python.org/moin/TimeComplexity" rel="nofollow">Python wiki page on time complexity</a> says that deleting an item takes O(n) time. The <a href="https://docs.python.org/3/library/collections.html#collections.deque" rel="nofollow">description of the deque class in the documentation of the col... | 1 | 2016-06-02T03:40:08Z | 37,582,275 | <p>Python <code>list</code> is actually an array. <code>deque</code> is a real linked list. It is Python's fault for using the wrong term (for which I do not have an explanation). <code>O(n)</code> for insertion and deletion is normal for arrays (as following elements need to be shifted up or down), which is a tradeoff... | 2 | 2016-06-02T03:45:10Z | [
"python",
"algorithm",
"list",
"big-o"
] |
Why does Python take O(n) time to remove the first element from a list? | 37,582,225 | <p>The <a href="https://wiki.python.org/moin/TimeComplexity" rel="nofollow">Python wiki page on time complexity</a> says that deleting an item takes O(n) time. The <a href="https://docs.python.org/3/library/collections.html#collections.deque" rel="nofollow">description of the deque class in the documentation of the col... | 1 | 2016-06-02T03:40:08Z | 37,582,692 | <p>The pointer to where the list <em>really</em> starts must be retained for the purpose of freeing the memory appropriately.</p>
<p>Indeed, <code>remove(0)</code> could be made faster by having a second pointer which is increased in this case. And if an <code>.add(0, x)</code> happens afterwards, this could be made f... | 3 | 2016-06-02T04:29:40Z | [
"python",
"algorithm",
"list",
"big-o"
] |
Why does Python take O(n) time to remove the first element from a list? | 37,582,225 | <p>The <a href="https://wiki.python.org/moin/TimeComplexity" rel="nofollow">Python wiki page on time complexity</a> says that deleting an item takes O(n) time. The <a href="https://docs.python.org/3/library/collections.html#collections.deque" rel="nofollow">description of the deque class in the documentation of the col... | 1 | 2016-06-02T03:40:08Z | 37,582,948 | <p>There's no reason it <em>couldn't</em> be, it just hasn't been. It is, however, a complication to the code, and the problem you're facing is usually an indicator that you're taking the wrong approach.</p>
<p>You could just implement this behavior yourself in a wrapper class, and use that in the cases where you know... | 1 | 2016-06-02T04:55:22Z | [
"python",
"algorithm",
"list",
"big-o"
] |
Implement a tokeniser in Python | 37,582,263 | <p>I am trying to implement a tokeniser in python (without using NLTK libraries) that splits a string into words using blank spaces. Example usage is:</p>
<pre><code>>> tokens = tokenise1(âA (small, simple) exampleâ)
>> tokens
[âAâ, â(small,â, âsimple)â, âexampleâ]
</code></pre>
<p>I c... | 0 | 2016-06-02T03:44:21Z | 37,582,390 | <p>The output is having spaces because you capture them using <code>()</code>. Instead you can split like</p>
<pre><code>re.split(r'\s+', string)
['A', '(small,', 'simple)', 'example']
</code></pre>
<ul>
<li><code>\s+</code> Matches one or more spaces.</li>
</ul>
| -1 | 2016-06-02T03:56:49Z | [
"python",
"regex"
] |
Python - Calling a function from another class | 37,582,375 | <p>I JUST started learning about Python, I recently read a tutorial about switching windows using tkinter. In the tutorial, the guy switched windows from inside the button in the <code>__init__</code> using lambda, but I want to go through a function before switching windows. The function runs from inside Class <code>W... | 1 | 2016-06-02T03:55:47Z | 37,591,570 | <p>What the tutorial doesn't tell you is that you should save an instance of controller so that you can use it in every function of the page classes. To see the original code that was copied for the tutorial, see <a href="http://stackoverflow.com/a/7557028/7432">http://stackoverflow.com/a/7557028/7432</a></p>
<p>In it... | 1 | 2016-06-02T12:13:37Z | [
"python",
"tkinter"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.