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
Asynchronous action in bottle
39,591,410
<p>I have simple application in written in bottle. I need to run same method each 10 seconds. My first idea was something like this, but it is not working and I think it is ugly solution:</p> <pre><code>inc = 0 # after run server open /loop page in order do initiate loop @route('/loop', method='GET') def whiletrue():...
0
2016-09-20T10:13:07Z
39,591,790
<p>you can use the threading module to call the method with the Timer command: </p> <pre><code>from functools import partial import threading class While_True(threading.Thread): def __init__(self, **kwargs): threading.Thread.__init__(self) def whileTrue(self, *args): print args def ...
1
2016-09-20T10:29:28Z
[ "python", "asynchronous", "bottle" ]
Raspbian Python azure.storage ImportError: No module named cryptography.hazmat.primitives.keywrap
39,591,561
<p>Im trying to upload pictures from my RPi3 to Azure blob storage. Im using raspbian and python moduls as described below.</p> <ul> <li>setup a virtual environment 'azure' using virtualwrapper.</li> <li>Installed azure-storage like here: <a href="https://github.com/Azure/azure-storage-python" rel="nofollow">https://g...
0
2016-09-20T10:19:26Z
39,600,941
<p>You can try to stick to azure-storage 0.32.0 to avoid using cryptography if you don't need the new features of 0.33.0. There is some difficulties to get cryptography working on some system (<a href="https://github.com/Azure/azure-storage-python/issues/219" rel="nofollow">https://github.com/Azure/azure-storage-python...
0
2016-09-20T18:08:57Z
[ "python", "azure", "raspbian", "raspberry-pi3" ]
Mask numbers in pandas
39,591,722
<p>i have an input to coloumns of a dataframe as 12345 and want to output to excel sheet as 1XXX5 how to do this . The data type in the dataframe coloumn is an integer</p> <pre><code>df=pd.read_excel('INVAMF.xls',sheetname=4,header=0,skiprows=0) #df created print df.dtypes print np.count_nonzero(pd.value_counts(df['...
-3
2016-09-20T10:26:14Z
39,591,956
<p>As you've failed to post any data and code here is a general form assuming that numbers are varying length:</p> <pre><code>In [141]: s = pd.Series([8815392,2983]) s = s.astype(str) s.apply(lambda x: x[0] + 'X' * (len(x) - 2) + x[-1]) Out[141]: 0 8XXXXX2 1 2XX3 dtype: object </code></pre> <p>if the number...
1
2016-09-20T10:38:28Z
[ "python", "pandas" ]
How to login into an website which is authenticated by google + API using python?
39,591,727
<p>How to get logged into some website using python code <code>i.e www.example.com/auth/gmail</code> which is taking advantage of google+ API for user logins. Now I would like to login with my credentials (Gmail or What?) by using python code. Please help me how to approach towards this problem.</p> <p>Thanks</p>
-1
2016-09-20T10:26:34Z
39,591,944
<p>this is old(sandbox) and is done really fast so, you have to refactor the code </p> <pre><code>import re import sys import imaplib import getpass import email import datetime import string import get_mail_search from sys import stdout M = imaplib.IMAP4_SSL('imap.gmail.com') class Get_mail(object): """docstring...
0
2016-09-20T10:37:58Z
[ "python", "google-api", "google-api-python-client" ]
How to login into an website which is authenticated by google + API using python?
39,591,727
<p>How to get logged into some website using python code <code>i.e www.example.com/auth/gmail</code> which is taking advantage of google+ API for user logins. Now I would like to login with my credentials (Gmail or What?) by using python code. Please help me how to approach towards this problem.</p> <p>Thanks</p>
-1
2016-09-20T10:26:34Z
39,592,370
<p>Here you have an example by using the google-api-python-client First of all you have to create your client secrets on the google developer console.</p> <p>First time you execute the code you will have to authorize the script to use your gmail account, then you can save the credentials on a file as on the example, a...
0
2016-09-20T11:02:13Z
[ "python", "google-api", "google-api-python-client" ]
scrapy list of requests delayed
39,591,753
<p>I need to scrape a list of web pages 10 times at 5 minute intervals. This is to collect URLs for later scraping. Another way to look at it is</p> <pre><code>url_list = [] for i in 1:10 { url_list += scrape request url_list += scrape request url_list += scrape request sleep 5 min } for site in url_list ...
0
2016-09-20T10:27:52Z
39,635,948
<p>You can use <code>DOWNLOAD_DELAY</code> project settings or <code>download_delay</code> spider class attribute with a number of desired delay in seconds. </p> <p><a href="http://doc.scrapy.org/en/latest/topics/settings.html#download-delay" rel="nofollow">Official docs on download_delay</a></p>
0
2016-09-22T09:58:25Z
[ "python", "scrapy" ]
Optimization in scipy from sympy
39,591,831
<p>I have four functions symbolically computed with Sympy and then lambdified:</p> <pre><code>deriv_log_s_1 = sym.lambdify((z, m_1, m_2, s_1, s_2), deriv_log_sym_s_1, modules=['numpy', 'sympy']) deriv_log_s_2 = sym.lambdify((z, m_1, m_2, s_1, s_2), deriv_log_sym_s_2, modules=['numpy', 'sympy']) deriv_log_m_1 = sym.lam...
4
2016-09-20T10:31:19Z
39,592,089
<p>The solution was, and I do not know why, to cast inputs to numpy.float:</p> <pre><code>m_1 = np.float32(m_1) m_2 = np.float32(m_2) s_1 = np.float32(s_1) s_2 = np.float32(s_2) </code></pre>
2
2016-09-20T10:46:21Z
[ "python", "numpy", "scipy", "sympy" ]
Checking a .txt file for an input by the user (Python 2.7.11)
39,591,938
<p>So i am currently creating a quiz program which requires a really basic authentication. This is the psuedocode that i have.</p> <pre><code>Start Open UserCredentials.txt (This is where the user ID is stored) Get UserID If UserID is in UserCredetials.txt( This is the part that i could not figure out how to do)...
-2
2016-09-20T10:37:49Z
39,592,545
<p>.you should start to use dict for data container and xml or json for the formatting</p> <pre><code>UserCredentials.xml members_dict: User(Name = "izzaz", Passwort: "abc123") User(Name = "isssz", Passwort: "asassa") .start .open UserCredentials.xml/json .get members_users .if user_id_input in members_users...
0
2016-09-20T11:10:09Z
[ "python" ]
Python MemoryError when 'stacking' arrays
39,592,117
<p>I am writing code to add data along the length of a numpy array (for combining satellite data records). In order to do this my code reads two arrays and then uses the function </p> <pre><code>def swath_stack(array1, array2): """Takes two arrays of swath data and compares their dimensions. The arrays should ...
-1
2016-09-20T10:48:16Z
39,599,489
<p>I changed your last line to <code>np.ma.vstack</code>, and got</p> <pre><code>In [474]: swath_stack(np.ones((3,4)),np.zeros((3,6))) Out[474]: masked_array(data = [[1.0 1.0 1.0 1.0 -- --] [1.0 1.0 1.0 1.0 -- --] [1.0 1.0 1.0 1.0 -- --] [0.0 0.0 0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0 0.0 0.0] [0.0 0.0 0.0 0.0 0.0 0...
0
2016-09-20T16:36:31Z
[ "python", "arrays", "numpy", "memory", "satellite-image" ]
REgex to extract date and time
39,592,176
<p>I am using nltk regex for date and time extraction:</p> <pre><code>text = 'LEts have quick meeting on Wednesday at 9am' week_day = "(monday|tuesday|wednesday|thursday|friday|saturday|sunday)" month = "(january|february|march|april|may|june|july|august|september| \ october|november|december)" dmy = "(year|...
-1
2016-09-20T10:51:47Z
39,592,298
<p>The regex is looking for <code>((this|next|last) (dmy|weekday|month))</code>.</p> <p>Your input doesn't have a match.</p> <p>Some alternatives that may work:</p> <pre><code>((this|next|last|on) (dmy|weekday|month)) ((this|next|last)? (dmy|weekday|month)) </code></pre>
3
2016-09-20T10:58:21Z
[ "python", "regex" ]
PYTHON: Summing up elements from one list based on indices in another list
39,592,237
<p>So here is what I am trying to achieve in Python:</p> <ul> <li>I have a list "A" with unsorted and repeated indices. </li> <li>I have a list "B" with some float values</li> <li>Length A = Length B</li> <li>I want list "C" with summed values of B based on the repeated indices in A in a sorted ascending manner.</li> ...
0
2016-09-20T10:55:14Z
39,592,567
<p>Use <code>zip()</code> in combination with a <code>dict</code>:</p> <pre><code>A = [0 , 1 , 0 , 3 , 2 , 1 , 2] B = [25 , 10 , 15 , 10 , 5 , 30 , 50] sums = {} for key, value in zip(A,B): try: sums[key] += value except KeyError: sums[key] = value print(sums) # {0: 40, 1: 40, 2: 55, 3: 10} <...
2
2016-09-20T11:11:34Z
[ "python", "list" ]
PYTHON: Summing up elements from one list based on indices in another list
39,592,237
<p>So here is what I am trying to achieve in Python:</p> <ul> <li>I have a list "A" with unsorted and repeated indices. </li> <li>I have a list "B" with some float values</li> <li>Length A = Length B</li> <li>I want list "C" with summed values of B based on the repeated indices in A in a sorted ascending manner.</li> ...
0
2016-09-20T10:55:14Z
39,592,816
<p>You could use <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow">groupby</a>, if the order matters:</p> <pre><code>In [1]: A=[0 , 1 , 0 , 3 , 2 , 1 , 2] In [2]: B=[25 , 10 , 15 , 10 , 5 , 30 , 50] In [3]: from itertools import groupby In [4]: from operator import itemgett...
0
2016-09-20T11:24:51Z
[ "python", "list" ]
PYTHON: Summing up elements from one list based on indices in another list
39,592,237
<p>So here is what I am trying to achieve in Python:</p> <ul> <li>I have a list "A" with unsorted and repeated indices. </li> <li>I have a list "B" with some float values</li> <li>Length A = Length B</li> <li>I want list "C" with summed values of B based on the repeated indices in A in a sorted ascending manner.</li> ...
0
2016-09-20T10:55:14Z
39,594,113
<p>It is actually a bit unclear what you want, but if you want them to be <em>indexed</em> by whatever the number is, you shouldn't even use a list, but a Counter instead:</p> <pre><code>&gt;&gt;&gt; from collections import Counter &gt;&gt;&gt; c = Counter() &gt;&gt;&gt; A = [0, 1, 0, 3, 2, 1, 2] &gt;&gt;&gt; B = [25,...
0
2016-09-20T12:28:39Z
[ "python", "list" ]
Celery - No module named 'celery.datastructures'
39,592,360
<p>i am using <code>Django 1.10</code> + <code>celery==4.0.0rc3</code> + <code>django-celery with commit @79d9689b62db3d54ebd0346e00287f91785f6355</code> .</p> <p>My settings are:</p> <pre><code>CELERY_RESULT_BACKEND = 'djcelery.backends.database:DatabaseBackend' CELERY_ACCEPT_CONTENT = ['json'] CELERY_TASK_SERIALIZE...
0
2016-09-20T11:01:38Z
39,592,658
<p>I was able to find the answer here <a href="https://github.com/celery/celery/issues/3303#issuecomment-246780116" rel="nofollow">https://github.com/celery/celery/issues/3303#issuecomment-246780116</a></p> <p>Basically <code>Django-celery does not support 4.0 yet</code> so i downgraded to <code>celery==3.1.23</code> ...
0
2016-09-20T11:16:50Z
[ "python", "django", "celery", "django-celery" ]
Indention Errors on Python IDLE
39,592,427
<p>I'm just following the basic's of python and have been using IDLE as I find it handy to experiment scripts in real-time. </p> <p>While I can run this script with no issues as a file I just cannot include the last print statement in IDLE!. I have tried an indentation, 4 spaces, no indentation's. Please explain what...
0
2016-09-20T11:05:04Z
39,592,620
<p>You can type one statement at a time. The <code>while</code> loop considered one with the loop itself, and since the loop is a code block everything in it is okay.</p> <p>The <code>print</code> at the end however is a new command. You have to run the <code>while</code> loop first and type the <code>print</code> aft...
1
2016-09-20T11:14:24Z
[ "python", "indentation" ]
Indention Errors on Python IDLE
39,592,427
<p>I'm just following the basic's of python and have been using IDLE as I find it handy to experiment scripts in real-time. </p> <p>While I can run this script with no issues as a file I just cannot include the last print statement in IDLE!. I have tried an indentation, 4 spaces, no indentation's. Please explain what...
0
2016-09-20T11:05:04Z
39,592,629
<p>You can't paste more than one statement at a time into IDLE. The problem has nothing to do with indentation. The <code>while</code> loop constitutes one compound statement and the final <code>print</code> another.</p> <p>The following also has issues when you try to paste at once into IDLE:</p> <pre><code>print('A...
1
2016-09-20T11:14:55Z
[ "python", "indentation" ]
Indention Errors on Python IDLE
39,592,427
<p>I'm just following the basic's of python and have been using IDLE as I find it handy to experiment scripts in real-time. </p> <p>While I can run this script with no issues as a file I just cannot include the last print statement in IDLE!. I have tried an indentation, 4 spaces, no indentation's. Please explain what...
0
2016-09-20T11:05:04Z
39,592,733
<p>You have an undentation error in line 10, then you need just to add an espace</p> <pre><code>while True: print ('Who are you?') name = input() if name != 'Joe': continue print('Hello, Joe. What is the password? (It is a fish.)') password = input() if password == 'swordfish': ...
0
2016-09-20T11:20:30Z
[ "python", "indentation" ]
Indention Errors on Python IDLE
39,592,427
<p>I'm just following the basic's of python and have been using IDLE as I find it handy to experiment scripts in real-time. </p> <p>While I can run this script with no issues as a file I just cannot include the last print statement in IDLE!. I have tried an indentation, 4 spaces, no indentation's. Please explain what...
0
2016-09-20T11:05:04Z
39,592,831
<p>As others have kindly pointed out python IDLE only allows one block of code to be executed at a time. In this instance the while loop is a 'block'. The last print statement is outside this block thus it cannot be executed.</p>
0
2016-09-20T11:25:52Z
[ "python", "indentation" ]
Package version difference between pip and OS?
39,592,490
<p>I have Debian OS and python version 2.7 installed on it. But I have a strange issue about package <code>six</code>. I want to use 1.10 version. </p> <p>I have installed six 1.10 via pip:</p> <pre><code>$ pip list ... six (1.10.0) </code></pre> <p>But when I run the following script</p> <pre><code>python -c "impo...
0
2016-09-20T11:07:59Z
39,592,939
<p>You can use <code>virtualenv</code> for this.</p> <pre><code>pip install virtualenv cd project_folder virtualenv venv </code></pre> <p><code>virtualenv venv</code> will create a folder in the current directory which will contain the Python executable files, and a copy of the pip library which you can use to insta...
1
2016-09-20T11:31:13Z
[ "python", "pip", "six" ]
exe file created with pyinstaller not recognizing the external sources
39,592,507
<p>I have created with success an exe file with Pyinstaller. However when I run the exe file and I fill in the path, file &amp; sheetnames in the messagebox that pops up the exe file says that the files that I have mistyped either a filename or sheetname. I obviously types this message myself and therefore my question ...
0
2016-09-20T11:08:45Z
39,595,299
<p>Define a function to translate path.</p> <pre><code>import os, sys def resource_path(relative_path): if hasattr(sys, "_MEIPASS"): base_path = sys._MEIPASS else: base_path = os.path.abspath(".") return os.path.join(base_path, relative_path) </code></pre> <p>Use this function to warp you...
0
2016-09-20T13:20:43Z
[ "python", "python-3.x", "exe", "pyinstaller" ]
temp files/directories with custom names?
39,592,524
<p>How to create a temporary files/directories with user defined names in python. I am aware of <a href="https://docs.python.org/3/library/tempfile.html" rel="nofollow">tempfile</a> . However I couldn't see any function with filename as argument.</p> <p>Note: I need this for unit testing the glob(file name pattern mat...
0
2016-09-20T11:09:17Z
39,592,704
<p>You can use <code>open()</code> with whatever file name you need.</p> <p>e.g.</p> <pre><code>open(name, 'w') </code></pre> <p><a href="https://docs.python.org/2/library/functions.html#open" rel="nofollow">Open</a></p> <p>Or</p> <pre><code>import os import tempfile print 'Building a file name yourself:' filenam...
0
2016-09-20T11:19:23Z
[ "python", "py.test", "temporary-files", "pyunit" ]
PyQt5 OpenGL swapBuffers very slow
39,592,653
<p>I am trying to make a small application using PyQt5 and PyOpenGL. Everything works fine, however rendering takes way too long with even only one sphere. I tried different routes to try and optimise the speed of the app, and right now I am using a simple QWindow with an OpenGLSurface. </p> <p>I managed to figure out...
0
2016-09-20T11:16:28Z
39,594,889
<p>By the way OpenGL works, the rendering commands you submit are sent to the GPU and executed asynchronously (frankly even the process of sending them to the GPU is asynchronous). When you request to display the back buffer by a call to <code>swapBuffers</code> the display driver must wait till the content of the back...
1
2016-09-20T13:03:14Z
[ "python", "qt", "opengl", "pyqt", "pyopengl" ]
Save data in associative model using one query in django
39,592,670
<p>I am working on registration module in django project. for registering user i am using auth_user table for extending this table i have created one more model Profile</p> <pre><code>from django.contrib.auth.models import User class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE...
0
2016-09-20T11:17:31Z
39,597,099
<p>I think you can define a registration form and override the form <code>save</code> method to save the <code>Profile</code> when creating the User model. Sample code for your reference:</p> <pre><code>class RegistrationForm(forms.ModelForm): start_date = forms.DateField() phone_number = forms.CharField() ...
0
2016-09-20T14:41:52Z
[ "python", "django", "database" ]
Numpy is adding dot(.) from CSV data
39,592,721
<p>I am reading CSV as:</p> <pre><code>import numpy as np features = np.genfromtxt('train.csv',delimiter=',',usecols=(1,2)) </code></pre> <p>It outputs data as:</p> <blockquote> <p>[[-1. -1.] [ 1. -1.] [-1. 1.] [ 1. -1.]]. See the dot after <code>1</code> and <code>-1</code></p> </blockquote> <p><strong>train...
-1
2016-09-20T11:20:10Z
39,595,715
<p>As stated in the comments : <code>np.genfromtxt</code> is simply converting your data to float numbers by default (<a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.genfromtxt.html" rel="nofollow">see the default dtype argument in the function signature</a>). If you want to force the output to integ...
1
2016-09-20T13:39:48Z
[ "python", "numpy" ]
How do I run a curl command in python
39,593,054
<p>This is the command I am running in <code>bash</code>:</p> <pre><code>curl -d "username=xxxxxx" -d "password=xxxxx" &lt;&lt;address&gt;&gt; --insecure --silent </code></pre> <p>How can I run this using Python?</p>
-2
2016-09-20T11:37:39Z
39,593,217
<p>Try <code>Subprocess</code>:</p> <pre><code>import subprocess # ... subprocess.call(["curl -d \"username=xxxxxx\" -d \"password=xxxxx\" https://xxxxx.com/logreg/login/ --insecure --silent" , shell=True) </code></pre> <p>I did not try what I wrote, but the essential is here.</p> <p>Check this page for more info :...
0
2016-09-20T11:45:56Z
[ "python", "curl" ]
How do I run a curl command in python
39,593,054
<p>This is the command I am running in <code>bash</code>:</p> <pre><code>curl -d "username=xxxxxx" -d "password=xxxxx" &lt;&lt;address&gt;&gt; --insecure --silent </code></pre> <p>How can I run this using Python?</p>
-2
2016-09-20T11:37:39Z
39,596,626
<p>I hope you don't want to explicitly run <code>curl</code>, but you just want to get the same result.</p> <pre><code>&gt;&gt;&gt; import requests &gt;&gt;&gt; r = requests.get('https://example.com', auth=('user', 'pass'), verify=False) &gt;&gt;&gt; print(r.status_code) 200 </code></pre>
0
2016-09-20T14:20:32Z
[ "python", "curl" ]
Double Conversion to decimal value IEEE-754 in Python
39,593,087
<p>I am trying to convert my <code>double</code> type data 64 bits long to decimal value. I am following <a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format" rel="nofollow">https://en.wikipedia.org/wiki/Double-precision_floating-point_format</a> for the converting. </p> <p>I have tried it in ...
2
2016-09-20T11:39:17Z
39,593,353
<p>The easy way to do this conversion is to use the <a href="https://docs.python.org/2/library/struct.html" rel="nofollow"><code>struct</code></a> module.</p> <pre><code>from struct import unpack a = '\x3f\xd5\x55\x55\x55\x55\x55\x55' n = unpack('&gt;d', a) print '%.18f' % n[0] </code></pre> <p><strong>output</stron...
3
2016-09-20T11:52:54Z
[ "python", "double", "decimal", "ieee-754" ]
Double Conversion to decimal value IEEE-754 in Python
39,593,087
<p>I am trying to convert my <code>double</code> type data 64 bits long to decimal value. I am following <a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format" rel="nofollow">https://en.wikipedia.org/wiki/Double-precision_floating-point_format</a> for the converting. </p> <p>I have tried it in ...
2
2016-09-20T11:39:17Z
39,593,361
<p>Too much work.</p> <pre><code>&gt;&gt;&gt; import struct &gt;&gt;&gt; struct.unpack('&gt;d', '\x3f\xd5\x55\x55\x55\x55\x55\x55')[0] 0.3333333333333333 </code></pre>
2
2016-09-20T11:53:04Z
[ "python", "double", "decimal", "ieee-754" ]
Using pytest fixtures and peewee transactions together
39,593,159
<p>I'm writing a set of unit tests using <code>pytest</code> for some database models that are implemented using <code>peewee</code>. I would like to use database transactions (the database is a Postgres one, if that is relevant) in order to roll back any database changes after each test. </p> <p>I have a situation wh...
1
2016-09-20T11:43:10Z
39,621,218
<p>If you want to rollback all transactions created within a test, you could have a fixture which takes care of the transaction itself and make the model fixtures use it:</p> <pre><code>@pytest.fixture def transaction(): with db.transaction() as txn: # `db` is my database object yield txn txn.roll...
2
2016-09-21T15:50:43Z
[ "python", "postgresql", "transactions", "py.test", "peewee" ]
How to disable SSL verification on Python Scrapy?
39,593,172
<p>I am writing data scraping scripts for past 3 years in PHP.</p> <p>This is simple PHP script </p> <pre><code>$url = 'https://appext20.dos.ny.gov/corp_public/CORPSEARCH.SELECT_ENTITY'; $fields = array( 'p_entity_name' =&gt; urlencode('AAA'), 'p_name_type' =&gt; urlencode('A'), 'p_search_type' =&gt; urle...
0
2016-09-20T11:44:05Z
39,593,438
<p>I would recommend having a look at this page: <a href="http://doc.scrapy.org/en/1.0/topics/settings.html" rel="nofollow">http://doc.scrapy.org/en/1.0/topics/settings.html</a> it would appear that you can alter the way that the module behaves and change settings on various handlers.</p> <p>I also believe this is a d...
1
2016-09-20T11:56:38Z
[ "python", "ssl", "scrapy" ]
How to disable SSL verification on Python Scrapy?
39,593,172
<p>I am writing data scraping scripts for past 3 years in PHP.</p> <p>This is simple PHP script </p> <pre><code>$url = 'https://appext20.dos.ny.gov/corp_public/CORPSEARCH.SELECT_ENTITY'; $fields = array( 'p_entity_name' =&gt; urlencode('AAA'), 'p_name_type' =&gt; urlencode('A'), 'p_search_type' =&gt; urle...
0
2016-09-20T11:44:05Z
39,601,276
<p>This code worked for me</p> <pre><code>from scrapy.contrib.spiders import CrawlSpider, Rule from scrapy.contrib.linkextractors.sgml import SgmlLinkExtractor from scrapy.selector import Selector from scrapy.http import FormRequest import urllib from appext20.items import Appext20Item from scrapy.selector import Ht...
0
2016-09-20T18:27:25Z
[ "python", "ssl", "scrapy" ]
NameError in TensorFlow tutorial while using the Retrained Model
39,593,212
<p>I'm following TensorFlow for Poets <a href="https://codelabs.developers.google.com/codelabs/tensorflow-for-poets/#5" rel="nofollow">tutorial</a>. paragraph about Using the Retrained Model. </p> <p>When I'm trying to run Python file which provided in the tutorial </p> <pre><code>python /tf_files/label_image.py /tf_...
0
2016-09-20T11:45:54Z
39,593,386
<p>Maybe you could try with <code>import sys</code> ?</p>
1
2016-09-20T11:54:11Z
[ "python", "tensorflow" ]
How to get data from R to pandas
39,593,275
<p>In a jupiter notebook I created some 2-d-list in R like</p> <pre><code>%%R first &lt;- "first" second &lt;- "second" names(first) &lt;- "first_thing" names(second) &lt;- "second_thing" x &lt;- list() index &lt;- length(x)+1 x[[index]] = first x[[index +1]] = second </code></pre> <p>a <code>%Rpull x</code> does n...
3
2016-09-20T11:49:04Z
39,594,165
<p>Just slice the <code>ListVector</code>:</p> <pre><code>%Rpull x pd.DataFrame(data=[i[0] for i in x], columns=['X']) </code></pre> <p><a href="http://i.stack.imgur.com/qNYVx.png" rel="nofollow"><img src="http://i.stack.imgur.com/qNYVx.png" alt="Image"></a></p> <p>If you want a dictionary instead:</p> <pre><code>d...
1
2016-09-20T12:30:29Z
[ "python", "pandas", "rpy2" ]
How to get data from R to pandas
39,593,275
<p>In a jupiter notebook I created some 2-d-list in R like</p> <pre><code>%%R first &lt;- "first" second &lt;- "second" names(first) &lt;- "first_thing" names(second) &lt;- "second_thing" x &lt;- list() index &lt;- length(x)+1 x[[index]] = first x[[index +1]] = second </code></pre> <p>a <code>%Rpull x</code> does n...
3
2016-09-20T11:49:04Z
39,594,479
<p>Since you created an R list (rather than, say, a data frame), the Python object returned is a <code>ListVector</code>.</p> <p>R lists can have duplicated names, making the conversion to a <code>dict</code> something that cannot be guaranteed to be safe. </p> <p>Should you feel lucky, and wanting a dict, it is rath...
0
2016-09-20T12:44:54Z
[ "python", "pandas", "rpy2" ]
How to get instance of entity in limit_choices_to (Django)?
39,593,577
<p>For instance:</p> <pre><code>class Foo(models.Model): bar = models.OneToOneField( 'app.Bar', limit_choices_to=Q(type=1) &amp; Q(foo=None) | Q(foo=instance) ) class Bar(models.Model): TYPE_CHOICE = ( (0, 'hello'), (1, 'world') ) type = models.SmallIntegerField( ...
1
2016-09-20T12:02:42Z
39,598,243
<p>If you pass a callable to <code>limit_choices_to</code>, that callable has no reference to the current instance. As such, you can't filter based on the current instance either.</p> <p>There are several other ways to achieve what you want, such as overriding <code>formfield_for_foreignkey()</code> as you mentioned, ...
1
2016-09-20T15:33:55Z
[ "python", "django" ]
python add value in dictionary in lambda expression
39,593,632
<p>Is it possible to add values in dictionary in lambda expression?</p> <p>That is to implement a lambda which has the similar function as below methods.</p> <pre><code>def add_value(dict_x): dict_x['a+b'] = dict_x['a'] + dict_x['b'] return dict_x </code></pre>
2
2016-09-20T12:05:09Z
39,593,726
<p>Technically, you may use side effect to update it, and exploit that <code>None</code> returned from <code>.update</code> is falsy to return dict via based on boolean operations:</p> <pre><code>add_value = lambda d: d.update({'a+b': d['a'] + d['b']}) or d </code></pre> <p>I just don't see any reason for doing it in...
2
2016-09-20T12:09:55Z
[ "python" ]
python add value in dictionary in lambda expression
39,593,632
<p>Is it possible to add values in dictionary in lambda expression?</p> <p>That is to implement a lambda which has the similar function as below methods.</p> <pre><code>def add_value(dict_x): dict_x['a+b'] = dict_x['a'] + dict_x['b'] return dict_x </code></pre>
2
2016-09-20T12:05:09Z
39,593,740
<p>You could build a custom dict, inheriting from <code>dict</code>, overriding its <code>__setitem__</code> function. <a href="https://docs.python.org/3/reference/datamodel.html?emulating-container-types#emulating-container-types" rel="nofollow">See the Python documentation.</a></p> <pre><code>class MyCustomDict(dict...
0
2016-09-20T12:10:41Z
[ "python" ]
Means of asymmetric arrays in numpy
39,593,672
<p>I have an asymmetric 2d array in numpy, as in some arrays are longer than others, such as: <code>[[1, 2], [1, 2, 3], ...]</code></p> <p>But numpy doesn't seem to like this:</p> <pre><code>import numpy as np foo = np.array([[1], [1, 2]]) foo.mean(axis=1) </code></pre> <p>Traceback:</p> <pre><code>Traceback (most...
0
2016-09-20T12:07:05Z
39,593,854
<p>You could perform the mean for each sub-array of foo using a list comprehension:</p> <pre><code>mean_foo = np.array( [np.mean(subfoo) for subfoo in foo] ) </code></pre> <p>As suggested by @Kasramvd in another answer's comment, you can also use the <code>map</code> function :</p> <pre><code>mean_foo = np.array( ma...
2
2016-09-20T12:15:29Z
[ "python", "numpy" ]
Means of asymmetric arrays in numpy
39,593,672
<p>I have an asymmetric 2d array in numpy, as in some arrays are longer than others, such as: <code>[[1, 2], [1, 2, 3], ...]</code></p> <p>But numpy doesn't seem to like this:</p> <pre><code>import numpy as np foo = np.array([[1], [1, 2]]) foo.mean(axis=1) </code></pre> <p>Traceback:</p> <pre><code>Traceback (most...
0
2016-09-20T12:07:05Z
39,594,084
<p>We could use an almost vectorized approach based upon <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.ufunc.reduceat.html" rel="nofollow"><code>np.add.reduceat</code></a> that takes care of the irregular length <em>subarrays</em>, for which we are calculating the average values. <code>np.add.reduc...
2
2016-09-20T12:27:24Z
[ "python", "numpy" ]
Merge two csv file in pyhton
39,593,747
<p>I trying to merge two csv file, I don't want to remove duplicate I want simply to check first column "PDB ID" and then check second column "Chain ID". all values has input files. I want to merge and add column file 1 and file 2. </p> <pre><code>import pandas as pd a = pd.read_csv("testfile.csv") b = pd.read_csv("...
1
2016-09-20T12:10:57Z
39,594,694
<p>Maybe you can use the <code>left_index</code> and <code>right_index</code> parameters of <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow">pandas <code>merge</code></a> method to not duplicate rows. Additionally, using <a href="http://stackoverflow.com/a/19125...
0
2016-09-20T12:54:58Z
[ "python", "python-2.7", "python-3.x" ]
UBER Python API returns uber_rides.errors.ClientError
39,593,754
<p>I wrote a piece of code to get product information. I used the code provided in their <a href="https://github.com/uber/rides-python-sdk" rel="nofollow">github</a>.</p> <pre><code>from uber_rides.session import Session session = Session(server_token="key_given_here") from uber_rides.client import UberRidesClient cl...
1
2016-09-20T12:11:16Z
39,594,374
<p>I got the answer. The code is working perfect. One character was missing in the <code>server_token</code> I provided.</p>
0
2016-09-20T12:40:02Z
[ "python", "uber-api" ]
Convert a dict to a pandas DataFrame
39,593,821
<p>My data look like this : </p> <pre><code>{u'"57e01311817bc367c030b390"': u'{"ad_since": 2016, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}', u'"57e01311817bc367c030b3a8"': u'{"ad_since": 2012, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}'} </code></pre> ...
2
2016-09-20T12:14:18Z
39,594,846
<p>You need convert column of <code>type</code> <code>str</code> to <code>dict</code> by <code>.apply(literal_eval)</code> or <code>.apply(json.loads)</code> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_records.html" rel="nofollow"><code>DataFrame.from_records</code>...
1
2016-09-20T13:01:07Z
[ "python", "json", "pandas" ]
Convert a dict to a pandas DataFrame
39,593,821
<p>My data look like this : </p> <pre><code>{u'"57e01311817bc367c030b390"': u'{"ad_since": 2016, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}', u'"57e01311817bc367c030b3a8"': u'{"ad_since": 2012, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access": "Yes"}'} </code></pre> ...
2
2016-09-20T12:14:18Z
39,594,999
<p>As the values are strings, you can use the <a href="https://docs.python.org/2/library/json.html" rel="nofollow"><code>json</code> module</a> and list comprehension:</p> <pre><code>In [20]: d = {u'"57e01311817bc367c030b390"': u'{"ad_since": 2016, "indoor_swimming_pool": "No", "seaside": "No", "handicapped_access...
1
2016-09-20T13:07:58Z
[ "python", "json", "pandas" ]
How to format datetime like java?
39,593,837
<p>I have the following java code:</p> <pre><code>SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SXXX"); String timestamp = simpleDateFormat.format(new Date()); System.out.println(timestamp); </code></pre> <p>which prints the date in the following format:</p> <pre><code>2016-09-20T0...
2
2016-09-20T12:14:50Z
39,602,161
<h1>ISO 8601</h1> <p>That format is one of a family of date-time string formats defined by the <a href="https://en.wikipedia.org/wiki/ISO_8601" rel="nofollow">ISO 8601</a> standard.</p> <h1>Python</h1> <p>Looks like many duplicates of your Question for Python.</p> <p><a href="http://stackoverflow.com/search?q=pytho...
1
2016-09-20T19:17:56Z
[ "java", "python" ]
How to handle blank form value in python
39,594,024
<p>I have 2 form fields in my html code, which hits to python script. Everything works perfectly if i provide both input in form. But in my case, 2nd field is optional. I am getting blank result when i submit form with 1st field only. How to handle my code to run even when 2nd field is blank/null</p> <p>python code:</...
0
2016-09-20T12:23:59Z
39,594,096
<pre><code>import cgi form = cgi.FieldStorage() first=form["firstSix"].value if form["lastFour"]: last=form["lastFour"].value else: form["lastFour"] = None </code></pre>
0
2016-09-20T12:28:03Z
[ "python" ]
How to handle blank form value in python
39,594,024
<p>I have 2 form fields in my html code, which hits to python script. Everything works perfectly if i provide both input in form. But in my case, 2nd field is optional. I am getting blank result when i submit form with 1st field only. How to handle my code to run even when 2nd field is blank/null</p> <p>python code:</...
0
2016-09-20T12:23:59Z
39,594,531
<p>You can check if something is empty with a boolean.</p> <pre><code>if not form["lastFour"]: print "lastFour is empty!" else: print "lastFour has a value!" </code></pre> <p>Any string that is empty is considered false, and and that has a value is true. So <code>""</code> is false and <code>"Hello World!"</c...
0
2016-09-20T12:47:16Z
[ "python" ]
Using regex extract all digit and word numbers
39,594,066
<p>I am trying to extract all string and digit numbers from a text.</p> <pre><code>text = 'one tweo three 10 number' numbers = "(^a(?=\s)|one|two|three|four|five|six|seven|eight|nine|ten| \ eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen| \ eighteen|nineteen|twenty|thirty|forty|fifty|six...
0
2016-09-20T12:26:12Z
39,594,403
<p>There are several issues here:</p> <ul> <li>The pattern should be used with the VERBOSE flag (add <code>(?x)</code> at the start)</li> <li>The <code>nine</code> will match <code>nine</code> in <code>ninety</code>, so you should either put the longer values first, or use word boundaries <code>\b</code></li> <li>Decl...
2
2016-09-20T12:40:55Z
[ "python", "regex" ]
Using regex extract all digit and word numbers
39,594,066
<p>I am trying to extract all string and digit numbers from a text.</p> <pre><code>text = 'one tweo three 10 number' numbers = "(^a(?=\s)|one|two|three|four|five|six|seven|eight|nine|ten| \ eleven|twelve|thirteen|fourteen|fifteen|sixteen|seventeen| \ eighteen|nineteen|twenty|thirty|forty|fifty|six...
0
2016-09-20T12:26:12Z
39,594,438
<p>Well the re.findall and the add of [0-9]+ work well for your list. Unfortunately if you try to match something like seventythree you will get --> seven and three, thus you need something better than this below :-)</p> <pre><code>numbers = "(^a(?=\s)|one|two|three|four|five|six|seven|eight|nine|ten| \ elev...
1
2016-09-20T12:42:35Z
[ "python", "regex" ]
How to compare dataframe unique values with a list?
39,594,080
<p>I have a Panda dataframe column, and I want to check if all values in my column come from another list.</p> <p>For example, I want to check whether all values in my column are <code>A</code> or <code>B</code> and nothing else. My code should return true for the following inputs:</p> <pre><code>myValues = ['A','B']...
1
2016-09-20T12:26:59Z
39,594,268
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a> and pass your list to generate a boolean array and with <code>all</code> to return whether all values present:</p> <pre><code>In [146]: myValues = ['A','B'] df = pd.DataFrame(...
1
2016-09-20T12:35:31Z
[ "python", "pandas" ]
How to compare dataframe unique values with a list?
39,594,080
<p>I have a Panda dataframe column, and I want to check if all values in my column come from another list.</p> <p>For example, I want to check whether all values in my column are <code>A</code> or <code>B</code> and nothing else. My code should return true for the following inputs:</p> <pre><code>myValues = ['A','B']...
1
2016-09-20T12:26:59Z
39,594,798
<p>Here is an alternative solution:</p> <pre><code>df.eval('Col in @myValues') </code></pre> <p>Demo:</p> <pre><code>In [78]: pd.DataFrame(['A','B','B','A'],columns=['Col']).eval('Col in @myValues') Out[78]: 0 True 1 True 2 True 3 True dtype: bool In [79]: pd.DataFrame(['A','A'],columns=['Col']).eval('C...
1
2016-09-20T12:59:17Z
[ "python", "pandas" ]
Python os library does not see environment variables in Windows
39,594,083
<p>As you can see on the picture below, I have 'SPARK_HOME' environment variable:</p> <p><a href="http://i.stack.imgur.com/vARRs.png" rel="nofollow"><img src="http://i.stack.imgur.com/vARRs.png" alt="enter image description here"></a></p> <p>However I just can't get it through python:</p> <pre><code>import os os.env...
0
2016-09-20T12:27:21Z
39,594,216
<pre><code>import os print bool(os.environ["SPARK_HOME"]) # True or False print os.environ["SPARK_HOME"] # print "SPARKE_HOME" path </code></pre>
0
2016-09-20T12:32:39Z
[ "python", "windows", "python-2.7", "operating-system", "environment-variables" ]
Python os library does not see environment variables in Windows
39,594,083
<p>As you can see on the picture below, I have 'SPARK_HOME' environment variable:</p> <p><a href="http://i.stack.imgur.com/vARRs.png" rel="nofollow"><img src="http://i.stack.imgur.com/vARRs.png" alt="enter image description here"></a></p> <p>However I just can't get it through python:</p> <pre><code>import os os.env...
0
2016-09-20T12:27:21Z
39,594,302
<p>To get your python start seeing new variables you need to restart your console, not just only <code>ipython notebook</code>!!!</p>
1
2016-09-20T12:36:45Z
[ "python", "windows", "python-2.7", "operating-system", "environment-variables" ]
intellij python global environment set fail
39,594,131
<p>I set some environment variables in /etc/profile or .bashrc ,all can not be use in intellij with python when runtime. so I have to set those variables in in intellij in here bellow. <a href="http://i.stack.imgur.com/P47B9.png" rel="nofollow">idea set global environment variables for all projects</a></p> <p>however...
1
2016-09-20T12:29:22Z
39,594,271
<p>Setting environment variables in <code>.bashrc</code> make them relative to one user's session only.</p> <p>And <code>/etc/profile</code> limit env variables to the shell.</p> <p>Set your variables in : <code>/etc/environment</code> or <code>/etc/security/pam_env.conf</code></p> <p>See : <a href="http://www.linux...
1
2016-09-20T12:35:41Z
[ "python", "intellij-idea", "environment-variables" ]
Creating an incremental List
39,594,249
<p>When I try to create an incremental list from <code>a</code> to <code>b</code> ( so something like [1,1.1,1.2,1.3,...,2] (a=1, b=2), then I start having a problem with the specific code I came up with:</p> <pre><code>def Range(a,b,r): lst1=[] y=a while y&lt;b: lst1.append(round(float(y+10**-r),r...
0
2016-09-20T12:34:21Z
39,595,048
<blockquote> <p>say, to get a element of 2.001, the lost has to take in y=2.000</p> </blockquote> <p>That's not true; it's possible that y becomes, say, 1.99999999999997.</p> <p>You check on <code>y &lt; b</code>, but then add <code>round(float(y+10**-r),r)</code> to the list. It's of course possible that the first...
2
2016-09-20T13:10:23Z
[ "python", "list", "increment" ]
User keyboard input in pygame, how to get CAPS input
39,594,390
<p>I'm in the process of making my first game and want prompt the user to enter information, eg their name. I've spent the last 3.5 hours writing the function below which I intend to use(slightly modified with a blinking underscore cursor to name one) in my games moving forward. </p> <p>As my code is currently written...
0
2016-09-20T12:40:26Z
39,596,960
<p>Below is the re-worked code with upper case input catered for. I've also put in a blinking underscore. Unsure if it's the most efficient way to do so, but there it is. I had fun doing it.</p> <pre><code>import pygame from pygame.locals import * import sys from itertools import cycle def enter_text(max_length, lowe...
0
2016-09-20T14:35:52Z
[ "python", "pygame", "ascii" ]
Image Attachment in python SDK
39,594,421
<p>I have the below document which got synced from couchbase lite (iOS).</p> <pre><code> { "Date": "00170925591601", "ID": "tmp652844", "InvoiceNumber": "tmp652844", "Supplier": "Temp", "_attachments": { "ImageAttachment": { ...
0
2016-09-20T12:41:39Z
39,594,735
<p>How do I get the attachment from the document? - this is a default dict with nested dicts and list inside it, you need a nested iterator function or a <a href="http://stackoverflow.com/questions/12507206/python-recommended-way-to-walk-complex-dictionary-structures-imported-from-json">recursive method</a>...</p>
0
2016-09-20T12:56:48Z
[ "python", "couchbase" ]
Image Attachment in python SDK
39,594,421
<p>I have the below document which got synced from couchbase lite (iOS).</p> <pre><code> { "Date": "00170925591601", "ID": "tmp652844", "InvoiceNumber": "tmp652844", "Supplier": "Temp", "_attachments": { "ImageAttachment": { ...
0
2016-09-20T12:41:39Z
39,612,299
<p>use the function ..</p> <p>get_attachment(id_or_doc, filename, default=None) Return an attachment from the specified doc id and filename.</p> <p>Parameters: id_or_doc – either a document ID or a dictionary or Document object representing the document that the attachment belongs to filename – the name of the a...
0
2016-09-21T09:16:03Z
[ "python", "couchbase" ]
A diagram for fluxes and stores of a hydrological model
39,594,436
<p>What is the easiest way in Python to draw a Sankey diagram with variable node (stock) sizes as well as arrows (flows)? </p> <p>I'm currently working on a hydrological model. The structure of the model can be seen below</p> <p><a href="http://i.stack.imgur.com/LNRfQ.png" rel="nofollow"><img src="http://i.stack.imgu...
1
2016-09-20T12:42:23Z
39,721,556
<p>So I have played a bit around and finally got a solution that works and is more general and less crude than I expected. The output looks something like this: <a href="http://i.stack.imgur.com/EB0C0.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/EB0C0.jpg" alt="enter image description here"></a></p> <p>Ever...
1
2016-09-27T09:52:20Z
[ "python", "matplotlib", "sankey-diagram" ]
Grouping continguous values in a numpy array with their length
39,594,631
<p>In numpy / scipy (or pure python if you prefer), what would be a good way to group contiguous regions in a numpy array and count the length of these regions?</p> <p>Something like this:</p> <pre><code>x = np.array([1,1,1,2,2,3,0,0,0,0,0,1,2,3,1,1,0,0,0]) y = contiguousGroup(x) print y &gt;&gt; [[1,3], [2,2], [3,1...
2
2016-09-20T12:51:15Z
39,594,730
<p>Here's a vectorized approach -</p> <pre><code>idx = np.concatenate(([0],np.flatnonzero(x[:-1]!=x[1:])+1,[x.size])) out = zip(x[idx[:-1]],np.diff(idx)) </code></pre> <p>Sample run -</p> <pre><code>In [34]: x Out[34]: array([1, 1, 1, 2, 2, 3, 0, 0, 0, 0, 0, 1, 2, 3, 1, 1, 0, 0, 0]) In [35]: out Out[35]: [(1, 3), (...
0
2016-09-20T12:56:38Z
[ "python", "arrays", "performance", "numpy" ]
Grouping continguous values in a numpy array with their length
39,594,631
<p>In numpy / scipy (or pure python if you prefer), what would be a good way to group contiguous regions in a numpy array and count the length of these regions?</p> <p>Something like this:</p> <pre><code>x = np.array([1,1,1,2,2,3,0,0,0,0,0,1,2,3,1,1,0,0,0]) y = contiguousGroup(x) print y &gt;&gt; [[1,3], [2,2], [3,1...
2
2016-09-20T12:51:15Z
39,595,127
<p>here is a Numpyhonic-pythonic approach:</p> <pre><code>In [192]: [(i[0], len(i)) for i in np.split(x, np.where(np.diff(x) != 0)[0]+1)] Out[192]: [(1, 3), (2, 2), (3, 1), (0, 5), (1, 1), (2, 1), (3, 1), (1, 2), (0, 3)] </code></pre> <p>Here is a generator based approach using <code>itertools.groupby()</code>:</p> ...
1
2016-09-20T13:14:15Z
[ "python", "arrays", "performance", "numpy" ]
Grouping continguous values in a numpy array with their length
39,594,631
<p>In numpy / scipy (or pure python if you prefer), what would be a good way to group contiguous regions in a numpy array and count the length of these regions?</p> <p>Something like this:</p> <pre><code>x = np.array([1,1,1,2,2,3,0,0,0,0,0,1,2,3,1,1,0,0,0]) y = contiguousGroup(x) print y &gt;&gt; [[1,3], [2,2], [3,1...
2
2016-09-20T12:51:15Z
39,597,153
<p>All you may need is <code>np.diff</code> and is a little easier to read. Create a mask ...</p> <pre><code>x = np.array([1,1,1,2,2,3,0,0,0,0,0,1,2,3,1,1,0,0,0]) mask = np.where( np.diff(x) != 0)[0] mask = np.hstack((-1, mask, len(x)-1 )) zip( x[mask[1:]], np.diff(mask) ) </code></pre> <p>This should be easiest ...
0
2016-09-20T14:44:22Z
[ "python", "arrays", "performance", "numpy" ]
add multiple values per key to a dictionary depending on if statement
39,594,722
<p>I need to transform a path into a python dictionary where <code>parent folder = key</code> and <code>folder content = values (e.g 'a/foo' 'a/bar' 'b/root' 'b/data'</code> needs to be <code>{ 'a': ['foo', 'bar'], 'b': ['root', 'data']}</code>) I got my dictionary initialized <code>d = {'a': [], 'b': [] }</code>and my...
1
2016-09-20T12:56:15Z
39,594,837
<p>Considering the structure of your result, <a href="https://docs.python.org/2/library/collections.html#collections.defaultdict" rel="nofollow"><code>collections.defaultdict</code></a> can handle this more easily:</p> <pre><code>from collections import defaultdict d = defaultdict(list) lst = ['a/foo', 'a/bar', 'b/r...
1
2016-09-20T13:00:49Z
[ "python", "dictionary" ]
add multiple values per key to a dictionary depending on if statement
39,594,722
<p>I need to transform a path into a python dictionary where <code>parent folder = key</code> and <code>folder content = values (e.g 'a/foo' 'a/bar' 'b/root' 'b/data'</code> needs to be <code>{ 'a': ['foo', 'bar'], 'b': ['root', 'data']}</code>) I got my dictionary initialized <code>d = {'a': [], 'b': [] }</code>and my...
1
2016-09-20T12:56:15Z
39,594,934
<p>Use <code>split</code> to split to folder and subfolder.</p> <pre><code>d = {'a': [], 'b': [] } l = ['a/foo', 'a/bar', 'b/root', 'b/data'] for key in d: for value in l: sep = value.split('/') if key == sep[0]: d[key].append(sep[1]) print(d) # {'b': ['root', 'data'], 'a': ['foo', 'bar...
0
2016-09-20T13:05:16Z
[ "python", "dictionary" ]
add multiple values per key to a dictionary depending on if statement
39,594,722
<p>I need to transform a path into a python dictionary where <code>parent folder = key</code> and <code>folder content = values (e.g 'a/foo' 'a/bar' 'b/root' 'b/data'</code> needs to be <code>{ 'a': ['foo', 'bar'], 'b': ['root', 'data']}</code>) I got my dictionary initialized <code>d = {'a': [], 'b': [] }</code>and my...
1
2016-09-20T12:56:15Z
39,595,020
<p>you have a problem with the way you initialize your dictionary <strong>customersDatabases</strong> :</p> <p>Instead of :</p> <pre><code>customersDatabases = d # problem with keys initialization (pointer to same empty list) </code></pre> <p>Try :</p> <pre><code>customersDatabases = dict(d) # new instance properly...
0
2016-09-20T13:09:09Z
[ "python", "dictionary" ]
Python: find all urls which contain string
39,594,926
<p>I am trying to find all pages that contain a certain string in the name, on a certain domain. For example: </p> <pre><code>www.example.com/section/subsection/406751371-some-string www.example.com/section/subsection/235824297-some-string www.example.com/section/subsection/146783214-some-string </code></pre> <p>Wh...
-2
2016-09-20T13:05:00Z
39,595,557
<p>I understood your situation, the numeric value before -some-string is a kind of object id for that web site (for example, this question has a id 39594926, and the url is stackoverflow.com/questions/<strong>39594926</strong>/python-find-all-urls-which-contain-string)</p> <p>I don't think there is a way to find all v...
0
2016-09-20T13:32:27Z
[ "python", "url" ]
Python: find all urls which contain string
39,594,926
<p>I am trying to find all pages that contain a certain string in the name, on a certain domain. For example: </p> <pre><code>www.example.com/section/subsection/406751371-some-string www.example.com/section/subsection/235824297-some-string www.example.com/section/subsection/146783214-some-string </code></pre> <p>Wh...
-2
2016-09-20T13:05:00Z
39,606,981
<p>If these articles are all linked to on one page you could parse the html of this index page since all links will be contained in the href tags.</p>
0
2016-09-21T03:19:27Z
[ "python", "url" ]
How to set default value from 'on delivery order' to 'on demand' in create invoice field in quotations in odoo?
39,595,152
<p>I am trying to set default value from <code>'on delivery order'</code> to <code>'on demand'</code> in create invoice field in quotation's other information tab in odoo. But its not setting as default value to on demand. Can anyone help me out how to set default value of create invoice in 'on demand'. </p> <p><stron...
0
2016-09-20T13:15:38Z
39,595,626
<p>You can use default attribute in the field </p> <pre><code>'order_policy': fields.selection([ ('manual', 'On Demand'), ('picking', 'On Delivery Order'), ('prepaid', 'Before Delivery'), ], 'Create Invoice', de...
1
2016-09-20T13:35:34Z
[ "python", "openerp", "default", "odoo-8", "default-value" ]
How to set default value from 'on delivery order' to 'on demand' in create invoice field in quotations in odoo?
39,595,152
<p>I am trying to set default value from <code>'on delivery order'</code> to <code>'on demand'</code> in create invoice field in quotation's other information tab in odoo. But its not setting as default value to on demand. Can anyone help me out how to set default value of create invoice in 'on demand'. </p> <p><stron...
0
2016-09-20T13:15:38Z
39,607,906
<p>You can do it by two way.</p> <p>1). As @KHELILI Hamza suggested you should redefine that field and set default value.</p> <p>2). You need to override default_get method.</p> <p><strong>Solution:</strong></p> <pre><code>def default_get(self, cr, uid, fields, context=None): res = super(class_name, self).defau...
1
2016-09-21T05:01:39Z
[ "python", "openerp", "default", "odoo-8", "default-value" ]
cv2.stereocalibrate() error about "cameraMatrix" not being a numerical tuple
39,595,291
<p>I'm working on estimating distance from stereo cameras. I am using python 2.7.11 and OpenCV 3.1 versions.I calibrated every camera separately and found intrinsic parameters. the problem is that when I use cv2.stereocalibtare() function in the way stated in OpenCV documents I get the error: "TypeError: cameraMatrix1...
0
2016-09-20T13:20:26Z
39,779,805
<p>Problem fixed.I used the lines below and errors were fixed.</p> <pre><code>`cameraMatrix1 =None cameraMatrix2 = None distCoeffs1 = None distCoeffs2 = None R =None T = None E = None F = None retval, cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, R, T, E, F = cv2.stereoCalibrate(objpointsL,imgpointsL, imgpoi...
0
2016-09-29T20:51:59Z
[ "python", "opencv", "camera", "calibration" ]
Windows Theano Keras - lazylinker_ext\mod.cpp: No such file or directory
39,595,392
<p>I am installing Theano and Keras follwing the <a href="http://stackoverflow.com/questions/34097988/how-do-i-install-keras-and-theano-in-anaconda-python-2-7-on-windows?answertab=votes#tab-top">How do I install Keras and Theano in Anaconda Python 2.7 on Windows?</a>, which worked fine for me with an older release befo...
0
2016-09-20T13:24:50Z
39,721,049
<p>Answer is from here: <a href="http://stackoverflow.com/questions/34346839/theano-change-base-compiledir-to-save-compiled-files-in-another-directory">Theano: change `base_compiledir` to save compiled files in another directory</a></p> <p>i.e. in ~/.theanorc file (or create it) add this line :</p> <pre><code>[global...
0
2016-09-27T09:30:03Z
[ "python", "g++", "mingw", "theano", "keras" ]
Write output of a python script calling a sql script to a file
39,595,423
<p>I'm learning python and sql at the same time. ;) The following python script calls a sql script. I am trying to figure out how to get the output from the query to go to a csv. I have gotten this far: </p> <hr> <pre><code>#!/usr/bin/env python import cx_Oracle import sys import csv import os.path import subproc...
0
2016-09-20T13:25:53Z
39,596,745
<p>May be this will help you. <a href="https://cx-oracle.readthedocs.io/en/latest/cursor.html" rel="nofollow">Documentation</a> </p> <p>There is function fetchall() which fetches all rows of query result.</p> <p>You can use it as</p> <pre><code>cur.execute("sql_command") query_result = cur.fetchall() </code></pre> ...
0
2016-09-20T14:27:03Z
[ "python", "sql", "oracle" ]
Using only a slice of meshgrid or replacing it for evaluting a function
39,595,564
<p>Edit: Solution</p> <p>The answer was posted below, using list prod from itertools greatly reduces memory usage as it is a list object, something I overlooked in the thread I linked.</p> <p>Code:</p> <pre><code>n = 2 #dimension r = np.arange(0.2,2.4,0.1) #range grid = product(r,repeat=n) for g in grid: y = n...
0
2016-09-20T13:32:44Z
39,595,965
<p>You may want to try iterator. It seems <a href="https://docs.python.org/3.6/library/itertools.html#itertools.product" rel="nofollow">itertools.product</a> fits your need.</p> <pre><code>r = np.arange(0,3,1) #determine range list(product(r,r)) #[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2), (2, 0), (2, 1), (2, 2)]...
0
2016-09-20T13:51:35Z
[ "python", "arrays", "python-3.x", "numpy" ]
Python os.walk netCDF4 not working together
39,595,735
<p>I am trying to go through a series of .nc files to run a small bit of code. The test script below prints the first filename in the directory but when I use <code>ncfile = netCDF4.Dataset(fname, 'r')</code> I get the error </p> <pre><code>File "netCDF4\_netCDF4.pyx", line 1795, in netCDF4._netCDF4.Dataset.__init__...
0
2016-09-20T13:40:42Z
39,596,127
<p>It seems it was a simple problem of needing the path and directory in</p> <p><code>ncfile = netCDF4.Dataset(fname, 'r')</code> </p> <p>so I have replaced it with</p> <p><code>ncfile = netCDF4.Dataset(os.path.join(fdir,fname), 'r')</code> </p> <p>and specified <code>fdir</code> outside the loop. For simplicity I ...
1
2016-09-20T13:57:57Z
[ "python", "netcdf", "os.walk" ]
luigi per-task retry policy
39,595,786
<p>I have an issue configuring luigi per-task retry-policy. I've configured the global luigi.cfg file as follows:</p> <pre><code>[scheduler] retry-delay: 1 retry_count: 5 [worker] keep_alive: true wait_interval: 3 </code></pre> <p>Furthermore, it states in the luigi configuration manual that writing a task as follow...
0
2016-09-20T13:43:03Z
39,869,332
<p>If even the example does not work. I believe your server or client code is out of date. Note that the <code>luigi</code> command will run your installed version and the central server needs to be restarted after a package upgrade.</p>
0
2016-10-05T08:46:48Z
[ "python", "luigi" ]
How to configure ruamel.yaml.dump output?
39,595,807
<p>With this data structure:</p> <pre><code>d = { (2,3,4): { 'a': [1,2], 'b': 'Hello World!', 'c': 'Voilà!' } } </code></pre> <p>I would like to get this YAML:</p> <pre><code>%YAML 1.2 --- [2,3,4]: a: - 1 - 2 b: Hello World! c: 'Voilà!' </code></pre> <p>Unfortunately...
1
2016-09-20T13:44:06Z
39,611,010
<p>You cannot get exactly what you want as output using <code>ruamel.yaml.dump()</code> without major rework of the internals.</p> <ul> <li>The output you like has indentation 2 for the values of the top-level mapping (key <code>a</code>, <code>b</code>, etc) and indentation 4 for the elements of the sequence that is...
1
2016-09-21T08:15:00Z
[ "python", "yaml", "ruamel.yaml" ]
Python CSV: Can I do this with one 'with open' instead of two?
39,595,820
<p>I am a noobie.</p> <p>I have written a couple of scripts to modify CSV files I work with.</p> <p>The scripts:</p> <p>1.) change the headers of a CSV file then save that to a new CSV file,.</p> <p>2.) Load that CSV File, and change the order of select columns using DictWriter.</p> <pre><code>from tkinter import ...
0
2016-09-20T13:44:26Z
39,596,366
<p><code>csvfile</code> can be any object with a <code>write()</code> method. You could craft a custom element, or use <a href="https://docs.python.org/2/library/stringio.html" rel="nofollow">StringIO</a>. You'd have to verify efficiency yourself.</p>
0
2016-09-20T14:08:13Z
[ "python", "csv", "dictionary", "header", "temporary-files" ]
Not getting required output using findall in python
39,595,840
<p>Earlier ,I could not put the exact question.My apologies.</p> <p>Below is what I am looking for :</p> <p>I am reading a string from file as below and there can be multiple such kind of strings in the file.</p> <pre><code>" VEGETABLE 1 POTATOE_PRODUCE 1.1 1SIMLA(INDIA) BANANA 1.2 A_BRAZIL(O...
1
2016-09-20T13:45:23Z
39,597,244
<p>Solution in last snippet in this answer.</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; str2='d1 talk walk joke' &gt;&gt;&gt; re.findall('(\d\s+)(\w+\s)+',str2) [('1 ', 'walk ')] </code></pre> <p>output is a list with only one occurrence of the given pattern. The tuple in the list contains two strings that ...
0
2016-09-20T14:49:17Z
[ "python", "regex", "findall" ]
Unpack *args to string using ONLY format function
39,595,924
<p>As in the title, how to unpack <code>*args</code> to string using <strong>ONLY</strong> <code>format</code> function (without <code>join</code> function), so having:</p> <pre><code>args = ['a', 'b', 'c'] </code></pre> <p>trying something like that (pseudocode):</p> <pre><code>'-{}-'.format(*args) </code></pre> ...
-2
2016-09-20T13:49:12Z
39,596,062
<p><strong>EDIT:</strong> There you go:</p> <pre><code>("-{}" * len(args) + "-").format(*args) </code></pre> <p><em>Before I realized that it shouldn't use <code>join()</code> it was:</em></p> <pre><code>"-{}-".format("-".join(["{}"] * len(args)).format(*args)) </code></pre>
3
2016-09-20T13:55:15Z
[ "python" ]
Unpack *args to string using ONLY format function
39,595,924
<p>As in the title, how to unpack <code>*args</code> to string using <strong>ONLY</strong> <code>format</code> function (without <code>join</code> function), so having:</p> <pre><code>args = ['a', 'b', 'c'] </code></pre> <p>trying something like that (pseudocode):</p> <pre><code>'-{}-'.format(*args) </code></pre> ...
-2
2016-09-20T13:49:12Z
39,596,176
<p>With a slight modification of the <em>format string</em> into <code>'{}-'</code>:</p> <pre><code>&gt;&gt;&gt; args = ['a', 'b', 'c'] &gt;&gt;&gt; l = len(args) &gt;&gt;&gt; ('{}-'*(l+1)).format('', *args) '-a-b-c-' </code></pre>
2
2016-09-20T14:00:11Z
[ "python" ]
Unpack *args to string using ONLY format function
39,595,924
<p>As in the title, how to unpack <code>*args</code> to string using <strong>ONLY</strong> <code>format</code> function (without <code>join</code> function), so having:</p> <pre><code>args = ['a', 'b', 'c'] </code></pre> <p>trying something like that (pseudocode):</p> <pre><code>'-{}-'.format(*args) </code></pre> ...
-2
2016-09-20T13:49:12Z
39,596,178
<p>Without <code>.join</code>:</p> <pre><code>from functools import reduce l = [1,2,3] s = reduce('{}{}-'.format, l, '-') print(s) </code></pre>
1
2016-09-20T14:00:13Z
[ "python" ]
Parsing DeepDiff result
39,595,934
<p>I am working with <a href="http://deepdiff.readthedocs.io/en/latest/" rel="nofollow">DeepDiff</a>. So I have results like:</p> <pre><code>local = [{1: {'age': 50, 'name': 'foo'}}, {2: {'age': 90, 'name': 'bar'}}, {3: {'age': 60, 'name': 'foobar'}}] online = [{1: {'age': 50, 'name': 'foo'}}, {2: {'age': 40, 'name':...
2
2016-09-20T13:49:54Z
39,602,787
<p>So, I'd go with something like this:</p> <pre><code>import re def foo(diff): modded = [] for key in diff.keys(): m = re.search('\[(.+)\]', key) modded.append(tuple(m.group(1).split(']['))) return modded </code></pre> <p>It'll read each key, extract only the indices (whether numeric or string), then slic...
1
2016-09-20T19:58:07Z
[ "python", "regex", "algorithm", "diff" ]
Parsing DeepDiff result
39,595,934
<p>I am working with <a href="http://deepdiff.readthedocs.io/en/latest/" rel="nofollow">DeepDiff</a>. So I have results like:</p> <pre><code>local = [{1: {'age': 50, 'name': 'foo'}}, {2: {'age': 90, 'name': 'bar'}}, {3: {'age': 60, 'name': 'foobar'}}] online = [{1: {'age': 50, 'name': 'foo'}}, {2: {'age': 40, 'name':...
2
2016-09-20T13:49:54Z
39,603,030
<ul> <li><p>One solution can be regex and custom parsing of the matches.</p></li> <li><p>Another can be using <code>literal_eval</code> after regex parsing on these strings, if the output format of <code>deepdiff</code> is consistent</p> <pre><code>from ast import literal_eval import re def str_diff_parse(str_diff):...
1
2016-09-20T20:14:51Z
[ "python", "regex", "algorithm", "diff" ]
Parsing DeepDiff result
39,595,934
<p>I am working with <a href="http://deepdiff.readthedocs.io/en/latest/" rel="nofollow">DeepDiff</a>. So I have results like:</p> <pre><code>local = [{1: {'age': 50, 'name': 'foo'}}, {2: {'age': 90, 'name': 'bar'}}, {3: {'age': 60, 'name': 'foobar'}}] online = [{1: {'age': 50, 'name': 'foo'}}, {2: {'age': 40, 'name':...
2
2016-09-20T13:49:54Z
39,603,170
<p>This is what I did:</p> <pre><code>def getFromSquareBrackets(s): return re.findall(r"\['?([A-Za-z0-9_]+)'?\]", s) def auxparse(e): try: e = int(e) except: pass return e def castInts(l): return list((map(auxparse, l))) def parseRoots(dics): """ Returns pos id for li...
1
2016-09-20T20:26:56Z
[ "python", "regex", "algorithm", "diff" ]
LDA: different sample sizes within the classes
39,596,151
<p>I'm trying to fit a LDA model on a data set that has different sample sizes for the classes.</p> <h1>TL;DR</h1> <p>lda.predict() doesn't work correctly if I trained the classifier with classes that don't have the same number of samples.</p> <h1>Long explanation</h1> <p>I have 7 classes with 3 samples each, and o...
0
2016-09-20T13:59:16Z
39,611,696
<p>It took me a while to figure this one out. The preprocessing step is responsible for the misclassification. Changing </p> <pre><code>preprocessing.scale(all_samples, axis=0, with_mean=True, with_std=True, copy=False) </code></pre> <p>to </p> <pre><code>preprocessing.scale(all_samples, axis=0, with...
0
2016-09-21T08:48:44Z
[ "python", "scikit-learn" ]
Numpy one hot encoder is only displaying huge arrays with zeros
39,596,305
<p>I have a <code>(400, 1)</code> numpy array that has values such <code>4300, 4450, 4650...</code> where these values can be distributed around 20 classes i.e. <code>4300 class 1, 4450 class 2...</code> and tried the below code to transform that array to one hot encoded list. The <code>y_train_onehot</code> is showing...
1
2016-09-20T14:05:28Z
39,596,939
<p>Here is some not optimized example:</p> <pre><code>def convert_to_one_hot(y): levels=np.unique(y) n_classes=levels.shape[0] one_hot=np.zeros((y.shape[0],n_classes),"uint8") for i in xrange(y.shape[0]): for index,level in enumerate(levels): if y[i]==level: one_hot[i,index]=1 return one_h...
2
2016-09-20T14:35:02Z
[ "python", "numpy" ]
Numpy one hot encoder is only displaying huge arrays with zeros
39,596,305
<p>I have a <code>(400, 1)</code> numpy array that has values such <code>4300, 4450, 4650...</code> where these values can be distributed around 20 classes i.e. <code>4300 class 1, 4450 class 2...</code> and tried the below code to transform that array to one hot encoded list. The <code>y_train_onehot</code> is showing...
1
2016-09-20T14:05:28Z
39,601,786
<p>I used Pandas Dummies and it's very simple.</p> <pre><code>&gt;&gt;&gt; import pandas as pd &gt;&gt;&gt; s = pd.Series(y_train) </code></pre> <p>And then</p> <pre><code>y_train_onehot = pd.get_dummies(s) </code></pre> <p><a href="http://i.stack.imgur.com/Vs5Cw.png" rel="nofollow"><img src="http://i.stack.imgur.c...
1
2016-09-20T18:55:37Z
[ "python", "numpy" ]
Make basic cipher function more readable
39,596,422
<p>I have this basic cipher function:</p> <pre><code>def encrypt_decrypt(data, in_or_out): pass_lst = list(data) return_list = [] if in_or_out == "in": for i in pass_lst: num = ord(i) + 10 return_list.append(chr(num)) else: for i in pass_lst: num = o...
1
2016-09-20T14:11:00Z
39,596,641
<p>You ca make it DRYer by computing the ±10 from the <code>in_or_out</code> parameter. Eg,</p> <pre><code>def encrypt_decrypt(data, in_or_out): delta = {'in': 10, 'out': -10}[in_or_out] return_list = [] for i in list(data): num = ord(i) + delta return_list.append(chr(num)) return ''.j...
1
2016-09-20T14:21:20Z
[ "python", "python-2.7" ]
Make basic cipher function more readable
39,596,422
<p>I have this basic cipher function:</p> <pre><code>def encrypt_decrypt(data, in_or_out): pass_lst = list(data) return_list = [] if in_or_out == "in": for i in pass_lst: num = ord(i) + 10 return_list.append(chr(num)) else: for i in pass_lst: num = o...
1
2016-09-20T14:11:00Z
39,597,905
<p>As a general rule, functions should do <em>one</em> thing; combining two functions into one, then using an argument to trigger which "embedded" function actually runs, is a bit of an antipattern. You can still abstract out the common code (here, following PM 2Ring's definition):</p> <pre><code>def encrypt(data): ...
1
2016-09-20T15:19:37Z
[ "python", "python-2.7" ]
Get empty cell coodinates with openpyxl
39,596,433
<p>I work at a script to extract some very messy data from a huge excel file and I run into a bump. There is any way to get coordinates from an empty cell with openpyxl?</p> <p>This will return an error saying EmptyCell has no row/column attribute</p> <pre><code>for row in sheet.iter_rows(): for cell in row: ...
0
2016-09-20T14:11:35Z
39,610,715
<p>EmptyCell's are special cells in the read-only context: they are fillers created where there are no cells in the original XML so that rows from a range are of equal length. As such they do not really exist and hence do not have coordinates. If you need their coordinates then you can simply use <code>enumerate</code>...
0
2016-09-21T08:00:17Z
[ "python", "excel", "openpyxl" ]
Using a folder for personal modules in Python
39,596,444
<p>I have created a folder named <code>C:\Python27\Lib\site-packages\perso</code> and inside I have put a file <code>mymodule.py</code>. The goal is to have this module accessible from any future Python script.</p> <p>Let's do a <code>D:\My Documents\test.py</code> file:</p> <pre><code>import mymodule #fails import...
2
2016-09-20T14:12:12Z
39,596,540
<ol> <li>check PythonPath</li> <li>create <code>__init__.py</code> to use perso as package</li> </ol>
3
2016-09-20T14:16:31Z
[ "python", "module", "python-module" ]
Using a folder for personal modules in Python
39,596,444
<p>I have created a folder named <code>C:\Python27\Lib\site-packages\perso</code> and inside I have put a file <code>mymodule.py</code>. The goal is to have this module accessible from any future Python script.</p> <p>Let's do a <code>D:\My Documents\test.py</code> file:</p> <pre><code>import mymodule #fails import...
2
2016-09-20T14:12:12Z
39,596,909
<p><strong>Python Modules:</strong></p> <p>In order to create a module you can do the following:</p> <ol> <li>under <code>&lt;Python_DIR&gt;\Lib\site-packages</code>:<br> put you directory <code>&lt;module&gt;</code>. This directory contains your classes.</li> <li>In <code>&lt;Python_DIR&gt;\Lib\site-packages\&lt;mod...
1
2016-09-20T14:33:52Z
[ "python", "module", "python-module" ]
Error "No such file or directory" when i import a ".so" file and that file is available in python
39,596,506
<p>I have a python code and some nao files(naoqi.py,_inaoqi.so, ...) in a folder in a raspberry pi 3 model B v1.2 with armv7l. my code has some import line:</p> <pre><code>import sys from naoqi import ALProxy import time import almath import os import socket </code></pre> <p>when i run this code i see "cannot open sh...
0
2016-09-20T14:14:48Z
39,647,922
<p>Just dumping the inaoqi files into your program directory isn't sufficient, you have to package them properly as a "python module." Is there an installer available for an inaoqi package, or can it be installed using pip?</p> <p>Also, if you're running Python on Windows, the <code>.so</code> file isn't going to do ...
0
2016-09-22T20:01:14Z
[ "python", "importerror", "raspberry-pi3", "nao-robot" ]
This doesn't produce a window and I don't know why
39,596,524
<p>I am using VPython in my attempt to model a ball bouncing off a wall. </p> <p>To make my code more elegant, I have decided to use class inheritance to set the dimensions and properties of my objects (at the moment, it's the ball and a wall). After I ran the code, the shell didn't produce any errors, however, it did...
1
2016-09-20T14:15:28Z
39,604,164
<p>I take it you never dealt with graphic aspects before, as there is nothing about it in the code you posted. Then it is time to begin ! By default, python works in console mode. To show an actual window, with icons and stuff going across it, you'll need to write it explicitly in your code, using modules like <strong>...
0
2016-09-20T21:40:14Z
[ "python", "python-2.7", "vpython" ]
Custom End a Modal operator Blender Python
39,596,525
<p>I have the following code:</p> <pre><code>class audio_visualizer_create(bpy.types.Operator): bl_idname = "myop.audio_visualizer_create" bl_label = "Audio Visualizer Create" bl_description = "" bl_options = {"REGISTER"} @classmethod def poll(cls, context): return True def invok...
0
2016-09-20T14:15:38Z
39,622,875
<p>Firstly the example you show doesn't benefit from being a modal operator. A modal operator is one that allows the 3DView to be updated as the user input alters what the operator does. An example of a modal operator is the knife tool, once started it changes the final result based on user input while it is running.</...
0
2016-09-21T17:22:47Z
[ "python", "modal-dialog", "operator-keyword", "blender" ]
web.input fails in cx_Oracle
39,596,614
<p>I have a webserver and I will add the user data into my sql query. It works psycopg but not with cx_Oracle.</p> <pre><code>... class grid: def GET(self): web.header('Access-Control-Allow-Origin', '*') web.header('Access-Control-Allow-Credentials', 'true') web.header('Content-Type', 'appl...
0
2016-09-20T14:20:09Z
39,597,410
<p>I know what was wrong. I should not use %s for the data. Apparently, cx_Oracle defaults to a "named" paramstyle .</p> <pre><code>data = web.input(ID='') query = "SELECT ... FROM... WHERE a.id =:grid_id " cursor.execute(query, {'grid_id':data.ID}) </code></pre>
1
2016-09-20T14:56:23Z
[ "python", "web.py", "cx-oracle" ]
Why got type error :takes 1 position argument but 2 were given?
39,596,669
<p>I have faced a problem with my django project. It is as following:</p> <p>Get Result: <code>__init__() takes 1 positional argument but 2 were given</code></p> <p>My code:</p> <p><strong>urls.py</strong></p> <pre><code>url(r'^_get_weather', views._get_weather, name='_get_weather') </code></pre> <p><strong>views....
1
2016-09-20T14:22:55Z
39,596,710
<p>Your view function should return an <a href="https://docs.djangoproject.com/en/1.10/ref/request-response/#httpresponse-objects"><code>HttpResponse</code></a> not an <a href="https://docs.djangoproject.com/en/1.10/ref/request-response/#httprequest-objects"><code>HttpRequest</code></a>.</p>
6
2016-09-20T14:25:05Z
[ "python", "django" ]
How to get a list of numbers in a for statement
39,596,682
<p>I am currently trying to figure how to get numbers organized.</p> <pre><code>def convert(temp_celsius): return temp_celsius * 1.8 + 32 def table(b): print('C F') for x in b: print('{:10}'.format(convert(x))) table(range(-30, 50, 10)) </code></pre> <p>I need a list of numbers that range...
1
2016-09-20T14:23:52Z
39,596,771
<p>It's really just a matter of formatting <em>two</em> numbers instead of one:</p> <pre><code>print('{:10} {:10}'.format(x, convert(x))) </code></pre> <p>Of course, you'll need to fix up the alignments but that's something you can do yourself.</p>
1
2016-09-20T14:27:54Z
[ "python", "for-loop" ]
How to get a list of numbers in a for statement
39,596,682
<p>I am currently trying to figure how to get numbers organized.</p> <pre><code>def convert(temp_celsius): return temp_celsius * 1.8 + 32 def table(b): print('C F') for x in b: print('{:10}'.format(convert(x))) table(range(-30, 50, 10)) </code></pre> <p>I need a list of numbers that range...
1
2016-09-20T14:23:52Z
39,596,783
<p>With two format statements:</p> <pre><code>for x in b: print('{:10} {:10}'.format(x, convert(x))) </code></pre> <p>Certainly, you just forgot to add the other output.</p>
0
2016-09-20T14:28:20Z
[ "python", "for-loop" ]
Deprecated Warning: Why won't my Matrix print?
39,596,705
<p>So I am doing a little project for my linear algebra class and I wanted to make a program that could construct an i by j matrix and then do a Row Echelon form-esque algorithm. But before any of that I wanted python to print a matrix before it performed the task so you could see the original matrix. This is what I ha...
-1
2016-09-20T14:24:56Z
39,600,323
<p>The solution was so easy as to write a return in the define fuction</p> <pre><code>def make_matrix(i,j): matrix = numpy.random.randint(0,50,(i,j)) return(matrix) print(make_matrix(i,j)) </code></pre>
0
2016-09-20T17:28:32Z
[ "python", "matrix", "printing", "deprecated" ]
How wrap list within the frame boundaries in python Tkinter?
39,596,715
<p><a href="http://i.stack.imgur.com/pGJG2.png" rel="nofollow"><img src="http://i.stack.imgur.com/pGJG2.png" alt="How to make sure my radio button list is within the frame"></a></p> <p>I am trying to list all the categories placed left of each other. The problem I am facing is that it is going beyond the frame boundar...
0
2016-09-20T14:25:17Z
39,598,647
<p>If you use the .grid layout manager for Tkinter you can specify the row and column of where you would like to place each item. There is no built in function to split items in to a new row.</p> <p><a href="http://effbot.org/tkinterbook/grid.htm" rel="nofollow">Tkinter Grid Layout</a></p>
2
2016-09-20T15:52:14Z
[ "python", "tkinter", "radiobuttonlist" ]