title
stringlengths
10
172
question_id
int64
469
40.1M
question_body
stringlengths
22
48.2k
question_score
int64
-44
5.52k
question_date
stringlengths
20
20
answer_id
int64
497
40.1M
answer_body
stringlengths
18
33.9k
answer_score
int64
-38
8.38k
answer_date
stringlengths
20
20
tags
list
How can I kill omxplayer player on a Raspberry Pi using Python
39,515,757
<p>I'm doing a DIY project using a Raspberry Pi 3 where I need to play 4 videos using omxplayer. </p> <p>Each video is played once you press a certain button on the protoboard:</p> <ul> <li>Press Button 1 - Play Video 1</li> <li>Press Button 2 - Play Video 2</li> <li>Press Button 3 - Play Video 3</li> <li>Press Butto...
0
2016-09-15T16:10:50Z
39,730,666
<p>I modified <strong>reproducirVideos()</strong> function with the following code in order to kill any process of <strong>omxplayer</strong> </p> <pre><code>def reproducirVideos(nameVideo): command1 = "sudo killall -s 9 omxplayer.bin" os.system(command1) command2 = "omxplayer -p -o hdmi %s/%s.mp4 &amp;" %...
0
2016-09-27T17:14:21Z
[ "python", "raspberry-pi", "omxplayer" ]
Print function input into int
39,515,788
<p>My goal is very simple, which makes it all the more irritating that I'm repeatedly failing:</p> <p>I wish to turn an input integer into a string made up of all numbers within the input range, so if the input is <code>3</code>, the code would be: <code>print(*range(1, 3+1), sep="")</code> </p> <p>which obviously w...
0
2016-09-15T16:12:26Z
39,516,571
<p>I see no reason why you would use <code>str</code> here, you should use <code>int</code>; the value returned from <code>input</code> is of type <code>str</code> and you need to transform it.</p> <p>A one-liner could look like this:</p> <pre><code>print(*range(1, int(input()) + 1), sep=' ') </code></pre> <p>Where ...
3
2016-09-15T16:58:37Z
[ "python", "python-3.x" ]
Print function input into int
39,515,788
<p>My goal is very simple, which makes it all the more irritating that I'm repeatedly failing:</p> <p>I wish to turn an input integer into a string made up of all numbers within the input range, so if the input is <code>3</code>, the code would be: <code>print(*range(1, 3+1), sep="")</code> </p> <p>which obviously w...
0
2016-09-15T16:12:26Z
39,516,637
<p>In your code, you should just be able to do:</p> <pre><code>n = int(input()) print(*range(1,n+1),sep="") </code></pre> <p>But you would also want to have some error checking to ensure that a number is actually entered into the prompt.</p> <p>A one-liner that works:</p> <pre><code>print(*range(1, int(input()) + 1...
2
2016-09-15T17:03:03Z
[ "python", "python-3.x" ]
Does python threading module speed up the execution time?
39,515,821
<p>I have a database containing employee information. I have 4000 employees. Each employee has an unique identification number. I try to fetch employee information for each employee from the database using a python script. For 1 employee, the execution time for fetching info is 1 seconds. For 4000 employees, it makes <...
0
2016-09-15T16:13:42Z
39,515,956
<p>I think you're confusing <em>threading</em> with <em>concurrency</em>.</p> <p>Threading is the act of simply using multiple threads of execution at the same time. This doesn't mean multiple actions are done simultaneously though... your processor still has to switch between the threads. This technique is useful whe...
0
2016-09-15T16:22:20Z
[ "python", "database", "multithreading" ]
Parsing paragraph out of text file in Python?
39,515,844
<p>I am trying to parse certain paragraphs out of multiple text file and store them in list. All the text file have some similar format to this:</p> <pre><code>MODEL NUMBER: A123 MODEL INFORMATION: some info about the model DESCRIPTION: This will be a description of the Model. It could be multiple lines but an empt...
0
2016-09-15T16:14:53Z
39,516,446
<p>Regular expression. Think about it this way: you have a pattern that will allow you to cut any file into pieces you will find palatable: "newline followed by capital letter"</p> <p>re.split is your friend</p> <p>Take a string</p> <pre><code>"THE BEST things in life are free IS YET TO COME" </code></pre> <p>As a...
0
2016-09-15T16:51:23Z
[ "python", "list", "python-2.7", "file" ]
Python libraries imported but unused
39,515,845
<p>The code is actually re-written from an application that worked Using the latest version of python via Anaconda and Spyder ide With Spyder <a href="http://i.stack.imgur.com/MxgeS.jpg" rel="nofollow">code screenshot</a></p> <pre><code>from pandas import Series, DataFrame import pandas as pd import numpy as np imp...
-3
2016-09-15T16:15:13Z
39,515,954
<p>Spyder is doing a <a href="https://en.wikipedia.org/wiki/Extended_static_checking" rel="nofollow">static check</a> to help with the correctness of your python program. You probably can run it just fine as it is, but the tool is helping you with python style and conciseness.</p> <p>Try removing the line </p> <pre><...
2
2016-09-15T16:22:05Z
[ "python", "pandas" ]
Cryptography: converting C function to python
39,515,934
<p>I am trying to solve a cryptography problem (<a href="https://callicode.fr/pydefis/Reverse/txt" rel="nofollow">https://callicode.fr/pydefis/Reverse/txt</a>), the alghorithm make use of the following C function (F1). I don't know C, I tried to convert it to python(F2) without success. Thank you in advance for lettin...
-1
2016-09-15T16:20:57Z
39,516,690
<p>Here's a little working example:</p> <pre><code>def Encrypt(key, pPlainBuffer): nKeyPos = 0 KeyA = 0 if pPlainBuffer is not None: pCipherBuffer = [] for n in range(20): KeyA = KeyA ^ key[n] nKeyPos = KeyA % 20 for n in range(len(pPlainBuffer)): p...
1
2016-09-15T17:06:30Z
[ "python", "c", "cryptography" ]
Cryptography: converting C function to python
39,515,934
<p>I am trying to solve a cryptography problem (<a href="https://callicode.fr/pydefis/Reverse/txt" rel="nofollow">https://callicode.fr/pydefis/Reverse/txt</a>), the alghorithm make use of the following C function (F1). I don't know C, I tried to convert it to python(F2) without success. Thank you in advance for lettin...
-1
2016-09-15T16:20:57Z
39,516,742
<p>you have many issues... the most glaring being that python integers are not constrained to a byte width by default so you must explicitly set the width</p> <p>additionally you must convert the letters to numbers in python as they are fundamentally different things (in C/c++ letters are really just numbers)</p> <pr...
1
2016-09-15T17:10:33Z
[ "python", "c", "cryptography" ]
Matplotlib Rotating 3d Disk
39,515,937
<p>I have a line and some points that are on that are on that line in 3D space. I know there is a certain amount of error in the the point, but the error only extends perpendicular to the line. To view this I'd like to have disks with a radius of the error that are centered on the line and orthogonal to the directio...
0
2016-09-15T16:21:15Z
39,520,369
<p>Here is the solution I've come up with. I decided to take the difference between where the point falls on the line and where the first point in <code>p.._segment3d</code>. This gives me how far away my circle is from where I want it to be, then I simply translated the patch that distance minus the radius of the ci...
0
2016-09-15T21:06:50Z
[ "python", "matplotlib", "3d" ]
What is error code 35, returned by the telegram.org server
39,515,953
<p>My client often receives the following message container from the telegram server, seemingly at random:</p> <pre><code>{'MessageContainer': [{'msg': {u'bad_msg_notification': {u'bad_msg_seqno': 4, u'bad_msg_id': 6330589643093583872L, u'error_code': 35}}, 'seqno': 4, 'msg_id': 6330589645303624705L}, {'msg': {u'msgs_...
1
2016-09-15T16:22:04Z
39,516,162
<p>As <a href="https://core.telegram.org/mtproto/service_messages_about_messages" rel="nofollow">Telegram API docs</a> says, error with code 35 is "odd msg_seqno expected (relevant message), but even received"</p>
1
2016-09-15T16:34:53Z
[ "python", "api", "telegram" ]
What is error code 35, returned by the telegram.org server
39,515,953
<p>My client often receives the following message container from the telegram server, seemingly at random:</p> <pre><code>{'MessageContainer': [{'msg': {u'bad_msg_notification': {u'bad_msg_seqno': 4, u'bad_msg_id': 6330589643093583872L, u'error_code': 35}}, 'seqno': 4, 'msg_id': 6330589645303624705L}, {'msg': {u'msgs_...
1
2016-09-15T16:22:04Z
39,755,683
<p>There are a set of errors associated with <strong><em>bad_msg_seqno</em></strong> </p> <p><strong>From the documentation:</strong> </p> <blockquote> <p>Here, error_code can also take on the following values:</p> <ol start="32"> <li>msg_seqno too low (the server has already received a message with a lowe...
1
2016-09-28T19:03:22Z
[ "python", "api", "telegram" ]
how to sort items in a list alphabetically by the letters in their respective names.
39,516,032
<p>I am trying to sort values in a list by the letters in their name: I want, for example, ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>
0
2016-09-15T16:27:01Z
39,516,100
<p>You can accomplish this by sorting it by a list.</p> <pre><code>list = ["8a", "8c", "8b", "8d"] list.sort() print(list) </code></pre>
0
2016-09-15T16:31:24Z
[ "python" ]
how to sort items in a list alphabetically by the letters in their respective names.
39,516,032
<p>I am trying to sort values in a list by the letters in their name: I want, for example, ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>
0
2016-09-15T16:27:01Z
39,516,107
<p>That would solve solve your problem:</p> <pre><code>_list = ["8a", "8c", "8b", "8d"] _list.sort() print _list </code></pre> <p>Output:</p> <pre><code>['8a', '8b', '8c', '8d'] </code></pre>
0
2016-09-15T16:31:36Z
[ "python" ]
how to sort items in a list alphabetically by the letters in their respective names.
39,516,032
<p>I am trying to sort values in a list by the letters in their name: I want, for example, ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>
0
2016-09-15T16:27:01Z
39,516,153
<p>The answer is easy if the data looks like in your question. If the data is more complex you will have to give the <code>sort</code> method a key which contains only characters from the alphabet.</p> <pre><code>data = ["34b", "2a5t", "2a5s", "abcd"] data.sort(key=lambda x: ''.join(c for c in x if c.isalpha())) prin...
3
2016-09-15T16:34:20Z
[ "python" ]
how to sort items in a list alphabetically by the letters in their respective names.
39,516,032
<p>I am trying to sort values in a list by the letters in their name: I want, for example, ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>
0
2016-09-15T16:27:01Z
39,516,165
<p>The .sort() method for lists has been mentioned; there's a sorting function that takes the list as an argument, and returns a sorted list without modifying the list in place:</p> <pre><code>&gt;&gt;&gt; mylist = ["8a", "8c", "8b", "8d"] &gt;&gt;&gt; sorted(list) ['8a', '8b', '8c', '8d'] &gt;&gt;&gt; mylist ['8a', '...
0
2016-09-15T16:35:20Z
[ "python" ]
how to sort items in a list alphabetically by the letters in their respective names.
39,516,032
<p>I am trying to sort values in a list by the letters in their name: I want, for example, ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>
0
2016-09-15T16:27:01Z
39,516,195
<p>Assuming your format is always number followed by letter, you need to give the sort method a specific key to sort by: in this case you want to sort by the last character. A lot of the other answers are just sorting your list alphabetically using the number followed by letter whereas I get the feeling you only want t...
1
2016-09-15T16:36:37Z
[ "python" ]
how to sort items in a list alphabetically by the letters in their respective names.
39,516,032
<p>I am trying to sort values in a list by the letters in their name: I want, for example, ["8a", "8c", "8b", "8d"] to become ["8a", "8b","8c", "8d"]. Does this have something to do with a key?</p>
0
2016-09-15T16:27:01Z
39,516,406
<blockquote> <p>trying to sort values in a list by the letters in their name</p> </blockquote> <p>The example you mentioned is very simple. Based on your requirement, below is the code using <code>re.findall()</code> and <code>sorted()</code> to sort based on letters in any order within string:</p> <pre><code>&gt;&...
0
2016-09-15T16:48:31Z
[ "python" ]
How do I can get list of Google YouTube API methods?
39,516,051
<p>I need to get list of YouTube API (v3) methods, because I want to implement a simple client library, which will not contain URL to every method, and just call them with their name. I'll use Python for this.</p>
0
2016-09-15T16:28:14Z
39,532,811
<p>As @sous2817 said, you can see all the methods that the YouTube API supports in this <a href="https://developers.google.com/youtube/v3/docs/" rel="nofollow">documentation</a>. </p> <blockquote> <p>This reference guide explains how to use the API to perform all of these operations. The guide is organized by resour...
1
2016-09-16T13:32:38Z
[ "python", "python-2.7", "youtube", "youtube-api", "youtube-data-api" ]
python pandas: date/time function to compute time period
39,516,055
<p>I have the following working code, trying to filter in the data within 14 days of the reference date. However, I had to hard code the date:</p> <pre><code>reference_ts = "2016-09-15 00:00:00" df1 = df[df.my_ts &gt;= "2016-09-01 00:00:00"] </code></pre> <p>I am wondering is there any function that I can use to comp...
-1
2016-09-15T16:28:29Z
39,516,192
<p>Yes, there is.</p> <p>You can just check <a href="https://docs.python.org/2/library/datetime.html" rel="nofollow">timedelta</a></p> <p>It is gonna solve your problem.</p>
0
2016-09-15T16:36:23Z
[ "python", "datetime", "pandas" ]
python pandas: date/time function to compute time period
39,516,055
<p>I have the following working code, trying to filter in the data within 14 days of the reference date. However, I had to hard code the date:</p> <pre><code>reference_ts = "2016-09-15 00:00:00" df1 = df[df.my_ts &gt;= "2016-09-01 00:00:00"] </code></pre> <p>I am wondering is there any function that I can use to comp...
-1
2016-09-15T16:28:29Z
39,516,418
<p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/timedeltas.html" rel="nofollow">pd.Timedelta()</a>:</p> <pre><code>reference_ts = pd.to_datetime("2016-09-15 00:00:00") df1 = df[df.my_ts &gt;= reference_ts - pd.Timedelta(days=14)] </code></pre>
1
2016-09-15T16:49:31Z
[ "python", "datetime", "pandas" ]
Looping not happening correctly in Python
39,516,173
<p>This is my python code that works on some data (a list) that looks like:</p> <pre><code>1 Check _ VERB VB _ 0 ROOT _ _ 2 out _ PRT RP _ 1 prt _ _ 3 this _ DET DT _ 4 det _ _ 4 video _ NOUN NN _ 1 dobj _ _ 5 about _ ADP IN _ 4 prep _ _ 6 Northwest _ NOUN NNP _ 7 nn _ _ 7 Arkansas _ NOUN NNP _ 5 pobj _ _ 8 - _...
0
2016-09-15T16:35:42Z
39,516,943
<p>I don't have enough rep to comment, so I'll write a super short answer.</p> <p>I think you just need a blank line at the end of your data list.</p>
0
2016-09-15T17:23:05Z
[ "python", "python-2.7", "loops", "debugging", "for-loop" ]
How to call a redis command and send output to a file?
39,516,196
<p>I want to run a redis command using a python script like:</p> <pre><code>redis-cli hget "User-123" </code></pre> <p>And I want the output to be written to a file.</p> <p>I cannot actually install the redis client because this script has to have no dependancies. </p> <p>I have python 2.6.6</p>
0
2016-09-15T16:36:38Z
39,518,913
<p>Use <a href="https://github.com/andymccurdy/redis-py" rel="nofollow">redis-py</a>, it works with 2.6. Then use python's builtin <a href="https://docs.python.org/2.6/tutorial/inputoutput.html#reading-and-writing-files" rel="nofollow">file i/o</a> functions to write to a file.</p>
0
2016-09-15T19:29:17Z
[ "python", "redis" ]
Python: Get Gmail server with smtplib never ends
39,516,200
<p>I simply tried:</p> <pre><code>&gt;&gt;&gt; import smtplib &gt;&gt;&gt; server = smtplib.SMTP('smtp.gmail.com:587') </code></pre> <p>in my Python interpreter but the second statement never ends.</p> <p>Can someone help? </p>
0
2016-09-15T16:36:59Z
39,516,410
<p>You might find that you need a login and password as a prerequisite to a successful login-in.<br> Try something like this:</p> <pre><code>import smtplib ServerConnect = False try: smtp_server = smtplib.SMTP('smtp.gmail.com','587') smtp_server.login('your_login', 'password') ServerConnect = True except S...
0
2016-09-15T16:49:07Z
[ "python", "smtplib" ]
Theano - SGD with 1 hidden layer
39,516,254
<p>I was using <a href="https://github.com/Newmu/Theano-Tutorials/blob/master/2_logistic_regression.py" rel="nofollow">Newmu tutorial</a> for logistic regression from his github. Wanted to add one hidden layer to his model, so I divided weights variable into two arrays h_w and o_w. The problem is - when I'm trying to m...
0
2016-09-15T16:39:47Z
39,516,894
<p><code>T.grad(..)</code> returns <a href="http://deeplearning.net/software/theano/tutorial/gradients.html" rel="nofollow">gradient</a> w.r.t to each parameter, so you cannot do <code>[w, w - gradient * 0.05]</code>, you have to specify which gradient[*] parameter you are referring to. Also it's not a good idea to use...
1
2016-09-15T17:20:08Z
[ "python", "numpy", "theano" ]
Loop through object functions
39,516,322
<p><code>dir(object)</code> returns a list of object attributes and functions. How can I iterate over all callable functions and get the output of the functions? (ASSUMING NO FUNCTION ARGS)</p> <pre><code>for a in dir(obj) if not a.startswith('__') and callable(getattr(obj,a)): response = obj.a() </code></pre> <p...
-2
2016-09-15T16:44:09Z
39,516,344
<p>you need to use getattr to actually get the callable and then call it ...</p> <p>do this</p> <pre><code>fn = getattr(obj,a) fn() </code></pre> <p>not this</p> <pre><code>obj.a() </code></pre> <p>of coarse you are not checking if the callable has any required arguments or anything like that ... im not sure what ...
1
2016-09-15T16:45:16Z
[ "python", "python-2.7" ]
How move a multipolygon with geopandas in python2
39,516,553
<p>I'm novice in GIS world in python (geopandas, shapely, etc). I need "move" a Multipolygon upwards, but I don't know how to do that.</p> <h3>The Problem</h3> <pre><code>import pandas as pd import numpy as np import matplotlib from matplotlib import pyplot as plt import seaborn as sns import pysal as ps from pysal.c...
1
2016-09-15T16:57:44Z
39,671,488
<p>I think you are looking for <code>shapely.affinity.translate</code>. From the docs:</p> <pre><code>Signature: shapely.affinity.translate(geom, xoff=0.0, yoff=0.0, zoff=0.0) Docstring: Returns a translated geometry shifted by offsets along each dimension. The general 3D affine transformation matrix for translation ...
2
2016-09-24T01:01:25Z
[ "python", "python-2.7", "shapely", "geopandas" ]
Blocking button click signals in PyQt
39,516,651
<p>I have a program that uses pyqt's .animateClick() feature to show the user a sequence of different button clicks that the user has to copy in that specific order. The problem is I don't want the animateClick() to send a signal, I only want the button click signals from the user. Here is some of my code to demonstrat...
0
2016-09-15T17:04:09Z
39,521,373
<p>Never use global variables unless you really have to. If you need shared access to variables, use instance attributes:</p> <pre><code>from PyQt4 import QtCore,QtGui class Program(object): def __init__(self): self.ai_states = [] self.user_states = [] self.flag = 1 # Set up th...
1
2016-09-15T22:40:24Z
[ "python", "user-interface", "pyqt", "signals" ]
extend a pandas datetimeindex by 1 period
39,516,671
<p>consider the <code>DateTimeIndex</code> <code>dates</code></p> <pre><code>dates = pd.date_range('2016-01-29', periods=4, freq='BM') dates DatetimeIndex(['2016-01-29', '2016-02-29', '2016-03-31', '2016-04-29'], dtype='datetime64[ns]', freq='BM') </code></pre> <p>I want to extend the index by one peri...
1
2016-09-15T17:05:16Z
39,516,881
<p>try this:</p> <pre><code>In [207]: dates = dates.append(pd.DatetimeIndex(pd.Series(dates[-1] + pd.offsets.BusinessMonthEnd()))) In [208]: dates Out[208]: DatetimeIndex(['2016-01-29', '2016-02-29', '2016-03-31', '2016-04-29', '2016-05-31'], dtype='datetime64[ns]', freq=None) </code></pre> <p>or using <code>list</c...
1
2016-09-15T17:19:30Z
[ "python", "pandas", "datetimeindex" ]
extend a pandas datetimeindex by 1 period
39,516,671
<p>consider the <code>DateTimeIndex</code> <code>dates</code></p> <pre><code>dates = pd.date_range('2016-01-29', periods=4, freq='BM') dates DatetimeIndex(['2016-01-29', '2016-02-29', '2016-03-31', '2016-04-29'], dtype='datetime64[ns]', freq='BM') </code></pre> <p>I want to extend the index by one peri...
1
2016-09-15T17:05:16Z
39,517,022
<p>The timestamps in your <code>DatetimeIndex</code> already know that they are describing business month ends, so you can simply add 1:</p> <pre><code>import pandas as pd dates = pd.date_range('2016-01-29', periods=4, freq='BM') print(repr(dates[-1])) # =&gt; Timestamp('2016-04-29 00:00:00', offset='BM') print(repr...
4
2016-09-15T17:28:32Z
[ "python", "pandas", "datetimeindex" ]
"OpenSSL: EC_KEY_generate_key FAIL ... error:00000000:lib(0):func(0):reason(0)" on pyelliptic.ECC()
39,516,710
<p>I'm getting the above error while using <code>pyelliptic</code> (versions given below).</p> <p>The python code which triggers it: </p> <pre><code>print("Salt: %s" % salt) server_key = pyelliptic.ECC(curve="prime256v1") # -----&gt;&gt; Line2 print("Server_key: %s" % server_key) # -----&gt;&gt; Line3 server_key_i...
0
2016-09-15T17:08:07Z
39,614,611
<p>Just added the following:<code>WSGIApplicationGroup %{GLOBAL}</code></p> <p>in <code>/etc/apache2/sites-available/default-ssl.conf</code> file and all these errors got resolved. </p>
0
2016-09-21T10:56:48Z
[ "python", "django", "google-compute-engine" ]
Scrapping row of info underneath a table header when the html tags for the row are not nested under the header tag
39,516,833
<p>I'm trying to scrape a <a href="https://wd.kyepsb.net/EPSB.WebApps/KECI/view_data.aspx?id=37161" rel="nofollow">table</a> but I've run into a bit of a snag. I want to make sure that the data underneath each header (ex. <code>Cert Issued (30)</code>) is grouped with the corresponding header. </p> <p>The problem aris...
2
2016-09-15T17:17:09Z
39,516,972
<p>I would locate every subheader and iterate over the <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#find-next-siblings-and-find-next-sibling" rel="nofollow">next <code>tr</code> siblings</a> breaking the loop once another header is met, or reached the end of the table:</p> <pre><code>from collection...
2
2016-09-15T17:24:44Z
[ "python", "python-2.7", "beautifulsoup", "lxml" ]
Scrapping row of info underneath a table header when the html tags for the row are not nested under the header tag
39,516,833
<p>I'm trying to scrape a <a href="https://wd.kyepsb.net/EPSB.WebApps/KECI/view_data.aspx?id=37161" rel="nofollow">table</a> but I've run into a bit of a snag. I want to make sure that the data underneath each header (ex. <code>Cert Issued (30)</code>) is grouped with the corresponding header. </p> <p>The problem aris...
2
2016-09-15T17:17:09Z
39,518,565
<p>using <em>lxml</em></p> <pre><code>def pair(): tree = html.fromstring(requests.get(url).content) # get table and iterate over the trs iter_trs = tree.cssselect("table.EPSBResultGrid")[0].iter("tr") # skip the initial tr next(iter_trs) # first EPSBResultGridHeader start = next(iter_trs).x...
2
2016-09-15T19:04:55Z
[ "python", "python-2.7", "beautifulsoup", "lxml" ]
Return result from Python to Vba
39,516,875
<p>I'm using a VBA code that calls a python script. I can send a parameter to my python script and reading it using <code>sys.argv[1]</code>.</p> <p>In the python code I have a function that takes the given argument and return a value.</p> <p>Please how can I get the return value in VBA? </p>
-1
2016-09-15T17:19:08Z
39,517,658
<p>Consider using VBA Shell's <code>StdOut</code> to capture a stream of the output lines. Be sure to have the Python script print to screen the value:</p> <p><strong>Python</strong></p> <pre><code>... print(outputval) </code></pre> <p><strong>VBA</strong> <em>(<code>s</code> below would be string output)</em></p> ...
0
2016-09-15T18:08:39Z
[ "python", "vba" ]
column width in QTableWidget and PyQt4
39,516,891
<p>I have a QTableWidget and I want to make sure that all the columns are stretched, i.e occupy all of the form. The solution that I found is provided <a href="http://stackoverflow.com/a/23215842/1636521">here</a> but it seems to be for <code>Qt5</code> and <code>C++</code>. I'm working with <code>PyQt4</code> and <cod...
0
2016-09-15T17:20:04Z
39,524,213
<p>the function for PyQt that is similar to that and which also apply to QHeaderView is :</p> <pre><code>setResizeMode (self, ResizeMode mode) </code></pre> <p>with possible values for resize mode </p> <pre><code>enum ResizeMode { Interactive, Fixed, Stretch, ResizeToContents, Custom } </code></pre> <p>more inform...
0
2016-09-16T05:25:22Z
[ "python", "python-2.7", "qt", "qt4", "pyqt4" ]
How can i easily handle numberseries formated with brackets?
39,516,950
<p>I have a long list of numberseries formated like this:</p> <pre><code>["4450[0-9]", "6148[0-9][0-9]"] </code></pre> <p>I want to make a list from one of those series with single numbers:</p> <pre><code>[44500,44501,..., 44509] </code></pre> <p>i need to do this for many series within the original list and i'm wo...
1
2016-09-15T17:23:19Z
39,517,249
<pre><code>def invertRE(x): if not x: yield [] else: idx = 1 if not x.startswith("[") else x.index("]") + 1 for rest in invertRE(x[idx:]): if x.startswith("["): v1,v2 = map(int,x[1:idx-1].split("-")) for i in range(v1,v2+1): yield ...
1
2016-09-15T17:43:18Z
[ "python", "numbers", "series", "number-sequence" ]
How can i easily handle numberseries formated with brackets?
39,516,950
<p>I have a long list of numberseries formated like this:</p> <pre><code>["4450[0-9]", "6148[0-9][0-9]"] </code></pre> <p>I want to make a list from one of those series with single numbers:</p> <pre><code>[44500,44501,..., 44509] </code></pre> <p>i need to do this for many series within the original list and i'm wo...
1
2016-09-15T17:23:19Z
39,517,251
<p>Probably not the best solution, but you can approach it recursively looking for the <code>[x-y]</code> ranges and <a href="https://wiki.python.org/moin/Generators" rel="nofollow">generating</a> values (using <code>yield</code> and <a href="https://docs.python.org/3/whatsnew/3.3.html#pep-380" rel="nofollow"><code>yie...
2
2016-09-15T17:43:28Z
[ "python", "numbers", "series", "number-sequence" ]
How can i easily handle numberseries formated with brackets?
39,516,950
<p>I have a long list of numberseries formated like this:</p> <pre><code>["4450[0-9]", "6148[0-9][0-9]"] </code></pre> <p>I want to make a list from one of those series with single numbers:</p> <pre><code>[44500,44501,..., 44509] </code></pre> <p>i need to do this for many series within the original list and i'm wo...
1
2016-09-15T17:23:19Z
39,530,391
<p>Found this module which seems to do what i want.</p> <p><a href="https://pypi.python.org/pypi/braceexpand/0.1.1" rel="nofollow">https://pypi.python.org/pypi/braceexpand/0.1.1</a></p> <pre><code>&gt;&gt;&gt; from braceexpand import braceexpand &gt;&gt;&gt; s = "1[0-2]" &gt;&gt;&gt; ss = "1[0-2][0-9]" &gt;&gt;&gt; l...
0
2016-09-16T11:29:04Z
[ "python", "numbers", "series", "number-sequence" ]
No newline character at end of file even after writing it
39,516,995
<pre><code># Create strings for preparation of file writing s = ";" seq = (risd41Email, risd41Pass, rimsd41Email, rimsd41Pass); textString = s.join(seq); # Create file, write contents, move to usertxtfiles dir with open(filename, "w") as text_file: text_file.write(str(textString)) text_file.write('\n') os.ren...
2
2016-09-15T17:26:23Z
39,517,344
<p>Try that:</p> <pre><code> text_file.write('\n\n') </code></pre> <p>This should work!</p>
1
2016-09-15T17:49:31Z
[ "python" ]
'expected string or buffer' when using re.match with pandas
39,517,013
<p>I am trying to clean some data from a csv file. I need to make sure that whatever is in the 'Duration' category matches a certain format. This is how I went about that:</p> <pre><code>import re import pandas as pd data_path = './ufos.csv' ufos = pd.read_csv(data_path) valid_duration = re.compile('^[0-9]+ (seconds...
1
2016-09-15T17:27:41Z
39,517,176
<p>I guess you want it the other way round (not tested):</p> <pre><code>import re import pandas as pd data_path = './ufos.csv' ufos = pd.read_csv(data_path) def cleanit(val): # your regex solution here pass ufos['ufos_clean'] = ufos['Duration'].apply(cleanit) </code></pre> <p>After all, <code>ufos</code> i...
0
2016-09-15T17:38:06Z
[ "python", "regex", "pandas", "dataframe" ]
'expected string or buffer' when using re.match with pandas
39,517,013
<p>I am trying to clean some data from a csv file. I need to make sure that whatever is in the 'Duration' category matches a certain format. This is how I went about that:</p> <pre><code>import re import pandas as pd data_path = './ufos.csv' ufos = pd.read_csv(data_path) valid_duration = re.compile('^[0-9]+ (seconds...
1
2016-09-15T17:27:41Z
39,518,084
<p>You can use vectorized <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.match.html" rel="nofollow">.str.match()</a> method:</p> <pre><code>valid_duration_RE = '^[0-9]+ (seconds|minutes|hours|days)$' ufos_clean = ufos[ufos.Duration.str.contains(valid_duration_RE)] </code></pre>
1
2016-09-15T18:33:09Z
[ "python", "regex", "pandas", "dataframe" ]
Finding closest value in a dictionary
39,517,040
<p>I have a dictionary, <code>T</code>, with keys in the form <code>k,i</code> with an associated value that is a real number (float). Let's suppose I choose a particular key <code>a,b</code> from the dictionary <code>T</code> with corresponding value <code>V1</code>—what's the most efficient way to find the closest ...
1
2016-09-15T17:29:35Z
39,517,206
<p>Since the values for a given <code>a</code> are strictly increasing with successive <code>i</code> values, you can do a binary search for the value that is closest to your target.</p> <p>While it's certainly possible to write your own binary search code on your dictionary, I suspect you'd have an easier time with a...
0
2016-09-15T17:40:03Z
[ "python", "python-2.7", "loops", "dictionary", "iteration" ]
Finding closest value in a dictionary
39,517,040
<p>I have a dictionary, <code>T</code>, with keys in the form <code>k,i</code> with an associated value that is a real number (float). Let's suppose I choose a particular key <code>a,b</code> from the dictionary <code>T</code> with corresponding value <code>V1</code>—what's the most efficient way to find the closest ...
1
2016-09-15T17:29:35Z
39,517,400
<pre><code>import numpy as np target_value = 0.9 dict = {(1, 2): 0, (4, 3): 1} k = list(dict.keys()) v = np.array(list(dict.values())) dist = abs(v - target_value) arg = np.argmin(dist) answer = k[arg] print(answer) </code></pre>
0
2016-09-15T17:52:47Z
[ "python", "python-2.7", "loops", "dictionary", "iteration" ]
Finding closest value in a dictionary
39,517,040
<p>I have a dictionary, <code>T</code>, with keys in the form <code>k,i</code> with an associated value that is a real number (float). Let's suppose I choose a particular key <code>a,b</code> from the dictionary <code>T</code> with corresponding value <code>V1</code>—what's the most efficient way to find the closest ...
1
2016-09-15T17:29:35Z
39,519,502
<p>I propose to use bisect module.</p> <pre><code>import bisect import numpy as np t = np.array([[1.1, 2.0, 3.7], [3.5, 5.6, 7.8], [2.5, 3.4, 10.0]]) def find_closest(t, a, i): """ &gt;&gt;&gt; find_closest(t, 0, 2) (1, 0) """ v = t[a, i] b_index = bisect.bisect_...
0
2016-09-15T20:06:51Z
[ "python", "python-2.7", "loops", "dictionary", "iteration" ]
Is it possible to use references in JSON?
39,517,184
<p>I have this JSON:</p> <pre><code>{ "app_name": "my_app", "version": { "1.0": { "path": "/my_app/1.0" }, "2.0": { "path": "/my_app/2.0" } } } </code></pre> <p>Is it somehow possible to reference the keywords <code>app_name</code> and the key of ...
0
2016-09-15T17:38:46Z
39,517,222
<p>No, JSON does not have references. (The functionality you request here, with substring expansion, would open itself to memory attacks against the parser; by not supporting this functionality, JSON avoids vulnerability to such attacks).</p> <p>If you want such functionality, you need to implement it yourself.</p>
1
2016-09-15T17:41:22Z
[ "python", "json", "yaml" ]
Is it possible to use references in JSON?
39,517,184
<p>I have this JSON:</p> <pre><code>{ "app_name": "my_app", "version": { "1.0": { "path": "/my_app/1.0" }, "2.0": { "path": "/my_app/2.0" } } } </code></pre> <p>Is it somehow possible to reference the keywords <code>app_name</code> and the key of ...
0
2016-09-15T17:38:46Z
39,517,226
<p>Not in pure JSON, but you could performs string substitution after you parse the JSON.</p>
0
2016-09-15T17:41:55Z
[ "python", "json", "yaml" ]
How can I use references in YAML?
39,517,356
<p>I have this YAML:</p> <pre><code>app_name: my_app version: 1.0: path: /my_app/1.0 2.0: path: /my_app/2.0 </code></pre> <p>Is it possible to somehow avoid typing out "my_app" and its version and instead read that from the YAML itself by using some sort of referencing?</p> <p>I had something like this i...
0
2016-09-15T17:50:13Z
39,517,579
<p>There is no mechanism in YAML that does substitution on substrings of scalars, the best you have are anchors and aliases, and they refer to whole scalars or collections (mappings, sequences).</p> <p>If you want to do such thing you will have to do the substitution after parsing in the YAML, interpreting the various...
1
2016-09-15T18:04:14Z
[ "python", "yaml" ]
Writing a program that finds perfect numbers - error
39,517,496
<p>I'm working on a program that finds perfect numbers (i.e., 6, because its factors, 1, 2, and 3, add up to itself). My code is</p> <pre><code>k=2 mprim = [] mprimk = [] pnum = [] def isprime(n): """Returns True if n is prime.""" if n == 2: return True if n == 3: return True if n % 2 ...
0
2016-09-15T17:58:36Z
39,520,221
<p>The error clearly states that you are trying to call an int type, which isn't callable. </p> <p>In practice it means you trying to do something like <code>123()</code></p> <p>And code responsible for it is <code>((2**i)-1)(2**i)</code> because you forgot <code>*</code> and it should be <code>(((2**i)-1)*(2**i))/(2...
1
2016-09-15T20:56:19Z
[ "python", "math", "compiler-errors", "listiterator" ]
Download file from Blob URL with Python
39,517,522
<p>I wish to have my Python script download the <em>Master data (Download, XLSX)</em> Excel file from this <a href="http://www.xetra.com/xetra-en/instruments/etf-exchange-traded-funds/list-of-tradable-etfs" rel="nofollow">Frankfurt stock exchange webpage</a>.</p> <p>When to retrieve it with <code>urrlib</code> and <co...
0
2016-09-15T18:00:21Z
39,517,774
<p>That 289 byte long thing might be a HTML code for <code>403 forbidden</code> page. This happen because the server is smart and rejects if your code does not specify a user agent.</p> <h1>Python 3</h1> <pre><code># python3 import urllib.request as request url = 'http://www.xetra.com/blob/1193366/b2f210876702b8e08e...
1
2016-09-15T18:15:12Z
[ "python", "download", "blob", "urllib" ]
Download file from Blob URL with Python
39,517,522
<p>I wish to have my Python script download the <em>Master data (Download, XLSX)</em> Excel file from this <a href="http://www.xetra.com/xetra-en/instruments/etf-exchange-traded-funds/list-of-tradable-etfs" rel="nofollow">Frankfurt stock exchange webpage</a>.</p> <p>When to retrieve it with <code>urrlib</code> and <co...
0
2016-09-15T18:00:21Z
39,518,081
<pre><code>from bs4 import BeautifulSoup import requests import re url='http://www.xetra.com/xetra-en/instruments/etf-exchange-traded-funds/list-of-tradable-etfs' html=requests.get(url) page=BeautifulSoup(html.content) reg=re.compile('Master data') find=page.find('span',text=reg) #find the file url file_url='http://w...
1
2016-09-15T18:33:01Z
[ "python", "download", "blob", "urllib" ]
Spark coalesce vs collect, which one is faster?
39,517,541
<p>I am using <code>pyspark</code> to process 50Gb data using AWS EMR with ~15 m4.large cores. </p> <p>Each row of the data contains some information at a specific time on a day. I am using the following <code>for</code> loop to extract and aggregate information for every hour. Finally I <code>union</code> the data, a...
2
2016-09-15T18:01:34Z
39,517,877
<p>Both <code>coalesce(1)</code> and <code>collect</code> are pretty bad in general but with expected output size around 1MB it doesn't really matter. It simply shouldn't be a bottleneck here.</p> <p>One simple improvement is to drop <code>loop</code> -> <code>filter</code> -> <code>union</code> and perform a single a...
1
2016-09-15T18:21:27Z
[ "python", "apache-spark", "pyspark" ]
Spark coalesce vs collect, which one is faster?
39,517,541
<p>I am using <code>pyspark</code> to process 50Gb data using AWS EMR with ~15 m4.large cores. </p> <p>Each row of the data contains some information at a specific time on a day. I am using the following <code>for</code> loop to extract and aggregate information for every hour. Finally I <code>union</code> the data, a...
2
2016-09-15T18:01:34Z
39,518,016
<p>To save as single file these are options</p> <p>Option 1 : <code>coalesce</code>(1) (no shuffle data over network) or <code>repartition</code>(1) or <code>collect</code> may work for small data-sets, but large data-sets it may not perform, as expected.since all data will be moved to one partition on one node </p> ...
1
2016-09-15T18:29:13Z
[ "python", "apache-spark", "pyspark" ]
Adding Grouped Dataframes
39,517,555
<p>I have two dataframes. I like the to add add the values in the columns together if the grouping is the same. Doing this with a simple addition works great as long as both group values are in each table. If they are not, it returns <code>nan</code>. I am assuming because you can't add <code>nan</code> and an <code>in...
2
2016-09-15T18:02:22Z
39,517,619
<p><strong>UPDATE:</strong></p> <pre><code>In [40]: funcs = ['count','sum'] In [41]: df.groupby('Person').agg(funcs).add(df1.groupby('Person').agg(funcs), fill_value=0) Out[41]: Days count sum Person A 4.0 2 B 2.0 1 C 2.0 1 </code></pre> <p><strong>Old answer:</strong></p> ...
2
2016-09-15T18:06:37Z
[ "python", "python-2.7", "pandas" ]
conversion of np.array(dtype='str') in an np.array(dtype='datetime')
39,517,660
<p>I have a very simple python question. I need to transform the string values within an np.array into datetime values. The string values contain the following format: ('%Y%m%d'). Does any one know how to this? Here my test data:</p> <pre><code>date_str = np.array([['20121002', '20121002', '20121002'], ...
-1
2016-09-15T18:08:45Z
39,517,742
<p>You can create a DataFrame, then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow"><code>apply</code></a> to it <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>pd.to_datetime</code></a>:</p> <pre><c...
0
2016-09-15T18:13:49Z
[ "python", "datetime", "pandas", "numpy" ]
conversion of np.array(dtype='str') in an np.array(dtype='datetime')
39,517,660
<p>I have a very simple python question. I need to transform the string values within an np.array into datetime values. The string values contain the following format: ('%Y%m%d'). Does any one know how to this? Here my test data:</p> <pre><code>date_str = np.array([['20121002', '20121002', '20121002'], ...
-1
2016-09-15T18:08:45Z
39,517,795
<p>Convert each element of the array to a <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.html" rel="nofollow">pandas series</a>, and perform the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow">to_datetime()</a> operation.</p> <pre><co...
0
2016-09-15T18:16:32Z
[ "python", "datetime", "pandas", "numpy" ]
Setting the SendAs via python gmail api returns "Custom display name disallowed"
39,517,707
<p>I can't find any results when searching Google for this response. </p> <p>I'm using the current Google Python API Client to make requests against the Gmail API. I can successfully insert a label, I can successfully retrieve a user's SendAs settings, but I cannot update, patch, or create a SendAS without receiving t...
0
2016-09-15T18:11:41Z
39,777,352
<p>This was a bug in the Gmail API. It is fixed now.</p>
0
2016-09-29T18:18:39Z
[ "python", "gmail-api", "google-api-python-client" ]
slow script trying to find unique values in list
39,517,737
<p>I've got a problem in Python: I want to find how many UNIQUE <code>a**b</code> values exist if:<br> &nbsp;&nbsp;&nbsp;&nbsp;<code>2 ≤ a ≤ 100</code>and <code>2 ≤ b ≤ 100</code>?</p> <p>I wrote the following script, but it's too slow on my laptop (and doesnt even produce the results):</p> <pre><code>List=[]...
1
2016-09-15T18:13:36Z
39,517,964
<p>The reason your script is slow and doesn't return a value is that you have created an infinite loop. You need to dedent the <code>a += 1</code> line by one level, otherwise, after the first time through the inner <code>while</code> loop <code>a</code> will not get incremented again.</p> <p>There are some additional...
0
2016-09-15T18:26:12Z
[ "python" ]
slow script trying to find unique values in list
39,517,737
<p>I've got a problem in Python: I want to find how many UNIQUE <code>a**b</code> values exist if:<br> &nbsp;&nbsp;&nbsp;&nbsp;<code>2 ≤ a ≤ 100</code>and <code>2 ≤ b ≤ 100</code>?</p> <p>I wrote the following script, but it's too slow on my laptop (and doesnt even produce the results):</p> <pre><code>List=[]...
1
2016-09-15T18:13:36Z
39,517,989
<p>This code doesn't work; it's an infinite loop because of the way you don't increment <code>a</code> on every iteration of the loop. After you fix that, you still won't get the right answer because you never reset <code>a</code> to 2 when <code>b</code> reaches <code>101</code>. </p> <p>Then, <code>List</code> will...
3
2016-09-15T18:27:57Z
[ "python" ]
slow script trying to find unique values in list
39,517,737
<p>I've got a problem in Python: I want to find how many UNIQUE <code>a**b</code> values exist if:<br> &nbsp;&nbsp;&nbsp;&nbsp;<code>2 ≤ a ≤ 100</code>and <code>2 ≤ b ≤ 100</code>?</p> <p>I wrote the following script, but it's too slow on my laptop (and doesnt even produce the results):</p> <pre><code>List=[]...
1
2016-09-15T18:13:36Z
39,518,018
<p>Your code is not good, since it does not produce correct results. As the comment by @grael pointed out, you do not recalculate the value of <code>c</code> inside the loop, so you are counting only one value over and over again. There are also other problems, as other people have noted.</p> <p>Your code is not fast ...
0
2016-09-15T18:29:14Z
[ "python" ]
Why is exit() or exec needed after telnetlib read_all()
39,517,861
<p>A lot of resources, including the example in the official documentation at <a href="https://docs.python.org/2/library/telnetlib.html" rel="nofollow">telnetlib</a> suggest that at the end before you do a read_all(), you need to write exit after the command as: </p> <pre><code>tn.write("ls\n") tn.write("exit\n") </co...
0
2016-09-15T18:20:34Z
39,518,037
<p>read_all() reads all the output until EOF. In other words, it waits until remote server closes connection and returns you all the data it has sent. If you have not previously notified the server with an "exit" command that you have no more commands for it, it will wait for them. And a deadlock occurs: you are holdin...
0
2016-09-15T18:30:20Z
[ "python", "exec", "telnet", "exit", "telnetlib" ]
How do I input I change the letters in a string to numbers for a frequency count?
39,517,867
<p>In preparation for an upcoming national cipher challenge, I was hoping to create a piece of code that would take the coded message as a string and record the frequency of each letter in order to try and figure out what the letter is most likely to be when decoded (I'm sorry if that's not very clear!). This is how I ...
-2
2016-09-15T18:20:59Z
39,517,976
<p>You can try <code>Counter</code> for counting frequency:</p> <pre><code>from collections import Counter s = 'abahvhavsvgs' print(Counter(s)) </code></pre> <p><strong>Output:</strong></p> <pre><code>Counter({'v': 3, 'a': 3, 'h': 2, 's': 2, 'b': 1, 'g': 1}) </code></pre> <p>For iterating over Counter (i.e. accessi...
2
2016-09-15T18:26:45Z
[ "python", "string" ]
How do I input I change the letters in a string to numbers for a frequency count?
39,517,867
<p>In preparation for an upcoming national cipher challenge, I was hoping to create a piece of code that would take the coded message as a string and record the frequency of each letter in order to try and figure out what the letter is most likely to be when decoded (I'm sorry if that's not very clear!). This is how I ...
-2
2016-09-15T18:20:59Z
39,519,053
<p>Your post leads me to believe that you're an absolute beginner, so I think that it would be valuable for you to implement this on your own, so that you understand what's going on. </p> <p>First: reading the cipher.</p> <p>Instead of editing your code every time, you can read the contents of a file. Copy the ciph...
1
2016-09-15T19:38:10Z
[ "python", "string" ]
pip install nose==1.3.7 installs version 0.10.4
39,517,887
<p>I'm trying to force pip to install nose v1.3.7. Using the following command:</p> <pre><code>pip install --proxy **** --no-cache -I nose==1.3.7 </code></pre> <p>but, I get the following output:</p> <p><a href="http://i.stack.imgur.com/nTJAQ.png" rel="nofollow"><img src="http://i.stack.imgur.com/nTJAQ.png" alt="ent...
1
2016-09-15T18:21:47Z
39,518,129
<p>Forcing an uninstall of nose and reinstalling it seems to have worked. Still uncertain why the -I flag didn't do as it's intended to do.</p>
0
2016-09-15T18:35:42Z
[ "python", "pip", "nose" ]
Error in program-censor(codecademy)-Practice makes perfect
39,517,934
<p>I tried executing this code but in the output the last <em>word-hack</em> is not turning into <em>asterisk</em> and is not even shown. </p> <p>Enter code here:</p> <pre><code>def censor(text,word): w="" text1="" for i in text: if i==" ": if w==word: text1=text1+"*"*...
1
2016-09-15T18:24:39Z
39,518,049
<p>The error is happening in the fourth line of the function. If you add an extra space to the end of "text" in your example, you get it it print what you want. Without digging too much into why the problem is happening, the following will work.</p> <pre><code>def censor(text,word): text = text + " " w="" ...
0
2016-09-15T18:31:11Z
[ "python" ]
Function that returns a list of the count of positive numbers and sum of negative numbers
39,518,074
<p>I have a problem when I ran my code against the unit test. Any advice would be appreciated. Please find the code below:</p> <pre><code>def manipulate_data(data): count = 0 sum1 = 0 new_list = [] for x in data: if x &gt; 0: count += 1 if x &lt; 0: sum1 += x ...
0
2016-09-15T18:32:41Z
39,518,140
<p>The results are correct. In <code>test_only_lists_allowed()</code> you are comparing the list returned by the function to the string <code>'Only lists allowed'</code>.</p> <p>That test will fail.</p>
0
2016-09-15T18:36:37Z
[ "python" ]
Function that returns a list of the count of positive numbers and sum of negative numbers
39,518,074
<p>I have a problem when I ran my code against the unit test. Any advice would be appreciated. Please find the code below:</p> <pre><code>def manipulate_data(data): count = 0 sum1 = 0 new_list = [] for x in data: if x &gt; 0: count += 1 if x &lt; 0: sum1 += x ...
0
2016-09-15T18:32:41Z
39,518,583
<p>For the case of {}, the result of manipulate_data is [0,0] try this:</p> <pre><code>def manipulate_data(data): if not isinstance(data, list): return 'Only lists allowed' count = 0 sum1 = 0 new_list = [] for x in data: if x &gt; 0: count += 1 if x &lt; 0: ...
0
2016-09-15T19:05:59Z
[ "python" ]
Function that returns a list of the count of positive numbers and sum of negative numbers
39,518,074
<p>I have a problem when I ran my code against the unit test. Any advice would be appreciated. Please find the code below:</p> <pre><code>def manipulate_data(data): count = 0 sum1 = 0 new_list = [] for x in data: if x &gt; 0: count += 1 if x &lt; 0: sum1 += x ...
0
2016-09-15T18:32:41Z
39,518,587
<p>Did you write your unit test? The person who did thinks that you should only be checking lists. The way to do this in python is:</p> <pre><code>&gt;&gt;&gt;l = [] &gt;&gt;&gt;isinstance(l, list) True &gt;&gt;&gt;d = {} &gt;&gt;&gt;isinstance(d, dict) True &gt;&gt;&gt;isinstance(d, list) False </code></pre> <p>Th...
0
2016-09-15T19:06:17Z
[ "python" ]
Function that returns a list of the count of positive numbers and sum of negative numbers
39,518,074
<p>I have a problem when I ran my code against the unit test. Any advice would be appreciated. Please find the code below:</p> <pre><code>def manipulate_data(data): count = 0 sum1 = 0 new_list = [] for x in data: if x &gt; 0: count += 1 if x &lt; 0: sum1 += x ...
0
2016-09-15T18:32:41Z
39,542,036
<p>def manipulate_data(data): if not isinstance(data, list): return 'Only lists allowed'</p> <pre><code>count = 0 sum1 = 0 new_list = [] for x in data: if x &gt; 0: count += 1 if x &lt; 0: sum1 += x new_list.append(count) new_list.append(sum1) return new_list </code></pre>
1
2016-09-17T01:27:51Z
[ "python" ]
how to add coordinate array as rows in panda dataframe
39,518,141
<p>I have a text file that looks like this </p> <pre><code>,A,B 0,"[[-81.03443909 29.22855949] [-81.09729767 29.27094078] [-80.9937973 29.19698906] [-81.03072357 29.27445984] [-81.00499725 29.22187805]]","[[-81.42427063 28.30874634] [-81.42427063 28.30874634] [-81.42427063 28.30874634] [-81.36068726 2...
2
2016-09-15T18:36:49Z
39,519,844
<p>Here is a starting point:</p> <pre><code>In [72]: (pd.concat([pd.DataFrame(c, columns=['lat','lon']).assign(cluster=i) ....: for i,c in enumerate(clusters)]) ....: .reset_index() ....: .rename(columns={'index':'point'}) ....: ) Out[72]: point lat lon cluster 0 ...
1
2016-09-15T20:30:26Z
[ "python", "pandas", "numpy", "dataframe" ]
Can't assign to function call, yet code seems correct
39,518,205
<p>I was making a VERY simple calculator, because I was bored, but for some reason it errors out with 'Can't assign to function call'. This is the code:</p> <pre><code>type=input("Please select a method.\n\n1.) Addition\n2.) Subtraction\n3.) Multiplication\n4.) Division\n\n") if type == "1": int(number1)=input("Fi...
0
2016-09-15T18:41:13Z
39,518,246
<p>You are casting your variables to <code>int</code> at the wrong time. You need to cast the input given to you as an integer, rather than cast the variable to an integer before a string value is given to you.</p> <p>All instances similar to <code>int(number1)=input("First number?")</code> need to be changed to <code...
0
2016-09-15T18:43:35Z
[ "python", "python-3.x" ]
Can't assign to function call, yet code seems correct
39,518,205
<p>I was making a VERY simple calculator, because I was bored, but for some reason it errors out with 'Can't assign to function call'. This is the code:</p> <pre><code>type=input("Please select a method.\n\n1.) Addition\n2.) Subtraction\n3.) Multiplication\n4.) Division\n\n") if type == "1": int(number1)=input("Fi...
0
2016-09-15T18:41:13Z
39,518,247
<p>You need to convert the input string to int, not the variable it is getting assigned to:</p> <pre><code>if type == "1": number1=int(input("First number?")) number2=int(input("Second number?")) answer=number1+number2 </code></pre>
2
2016-09-15T18:43:38Z
[ "python", "python-3.x" ]
Syntax Error: no ascii character input operation
39,518,206
<p>I've got quite a problem with python right now. I try around to just calculate a few integers in an array. So it should not be too complicated. I worked on it over a 2 days now, but can't get it to work.</p> <pre><code>def calculate( str ): global x if (len(x)==9): a = [] for i in x_str: ...
1
2016-09-15T18:41:14Z
39,518,442
<p>I changed:</p> <ul> <li><code>a.append(i)</code> to <code>a.append(int(i))</code></li> <li>removed <code>global x</code></li> <li><code>for i in x_str:</code> to <code>for i in x:</code></li> <li>changed your <code>isdn</code> variable to <code>x</code></li> </ul> <hr> <pre><code>def calculate( x ): if (len(x...
1
2016-09-15T18:56:39Z
[ "python", "python-3.x", "syntax" ]
I can connect to an AWS region but am not authorized to get the spot prices
39,518,236
<p>I am trying to get AWS spot price history and I have been getting help from this tutorial: <a href="https://medium.com/cloud-uprising/the-data-science-of-aws-spot-pricing-8bed655caed2#.nk3k2m1z0" rel="nofollow">https://medium.com/cloud-uprising/the-data-science-of-aws-spot-pricing-8bed655caed2#.nk3k2m1z0</a></p> <p...
1
2016-09-15T18:43:02Z
39,519,110
<p>The AWS credentials that you are using do not have permission to execute the <code>ec2:DescribeSpotPriceHistory</code> command.</p> <p>To resolve this:</p> <ol> <li>Go to the IAM Management Console</li> <li>Find the IAM user or role that you're using during your connection</li> <li>Give yourself permission to exec...
-1
2016-09-15T19:41:14Z
[ "python", "amazon-web-services", "amazon-ec2", "boto", "unauthorized" ]
I can connect to an AWS region but am not authorized to get the spot prices
39,518,236
<p>I am trying to get AWS spot price history and I have been getting help from this tutorial: <a href="https://medium.com/cloud-uprising/the-data-science-of-aws-spot-pricing-8bed655caed2#.nk3k2m1z0" rel="nofollow">https://medium.com/cloud-uprising/the-data-science-of-aws-spot-pricing-8bed655caed2#.nk3k2m1z0</a></p> <p...
1
2016-09-15T18:43:02Z
39,519,332
<p>I figured out the problem. It turns out my pc time was 7 minutes slower. and I read somewhere that AWS in addition to your credentials also uses your CPU time.</p> <p>Basically I manually changed the time, and now it works:)</p>
0
2016-09-15T19:54:22Z
[ "python", "amazon-web-services", "amazon-ec2", "boto", "unauthorized" ]
GtkFileChooserButon reset to initial state before file selection
39,518,302
<p>How to reset a <code>GtkFileChooserButton</code> for its initial state, ie before file selection?</p> <p>code:</p> <pre><code>#!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk def file_changed(filechooserbutton): print("File selected: %s" % filechooserbutton.get_...
1
2016-09-15T18:46:47Z
39,526,252
<p>GtkFileChooserButton implements GtkFileChooser, so you can use the <a href="https://developer.gnome.org/gtk3/stable/GtkFileChooser.html#gtk-file-chooser-unselect-all" rel="nofollow">unselect_all</a> function.</p>
1
2016-09-16T07:45:25Z
[ "python", "gtk" ]
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TAB LESPACE, but settings are not configured
39,518,350
<p>I’m using Django 1.9.1 with Python 3.5.2 and I'm having a problem running a Python script that uses Django models.</p> <pre><code>C:\Users\admin\trailers&gt;python load_from_api.py Traceback (most recent call last): File "load_from_api.py", line 6, in &lt;module&gt; from movies.models import Movie File "C...
1
2016-09-15T18:49:53Z
39,525,966
<p>I would recommend using <a href="https://docs.djangoproject.com/en/1.10/howto/custom-management-commands/" rel="nofollow">Django Custom Management Commands</a> - they are really simple to use, they use your settings, your environment, you can pass parameters and also you can write help strings so you can use <code>-...
0
2016-09-16T07:26:54Z
[ "python", "django" ]
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TAB LESPACE, but settings are not configured
39,518,350
<p>I’m using Django 1.9.1 with Python 3.5.2 and I'm having a problem running a Python script that uses Django models.</p> <pre><code>C:\Users\admin\trailers&gt;python load_from_api.py Traceback (most recent call last): File "load_from_api.py", line 6, in &lt;module&gt; from movies.models import Movie File "C...
1
2016-09-15T18:49:53Z
39,538,836
<p>I figured out how to run it without changing the script and that's by using</p> <p><code>python manag.py shell</code></p> <p>and then </p> <p><code>exec(open('filename').read())</code></p> <p>that seemed to work just fine.</p>
0
2016-09-16T19:27:11Z
[ "python", "django" ]
Receiving getaddrinfo [Errno -2] when trying to use Beaglebone Black to send email
39,518,411
<p>I'm trying to use a Beaglebone Black (BBB) to send email notifications, but I'm getting caught up on this getaddrinfo error that reads as follows; </p> <blockquote> <p>socket.gaierror: [Errno -2] Name or service not known</p> </blockquote> <p>I've been working on this for a while and can't find why this isn't wo...
3
2016-09-15T18:54:40Z
39,518,649
<p><code>socket.gaierror</code> means that (underlying in libc) <code>getaddrinfo</code> function failed to get IP addresses for domain names you provided. It explains why it failed: <code>[Errno -2] Name or service not known</code>, so it doesn't know about a domain with such a name, <code>smtp.gmail.com</code>. This ...
1
2016-09-15T19:10:37Z
[ "python", "email", "smtp", "beagleboneblack", "errno" ]
I can't load multiple times a file with inside of it an empty list
39,518,431
<p>I need to load more than one time a file with inside of it and empty list. At first I tried:</p> <pre><code>import pickle file_example = open("file.cpk","wb") empty_list = [] pickle.dump(empty_list,file_example) file_example.close() def file_open(): file_open.file = open("file.pck","rb") file_open.empty_li...
1
2016-09-15T18:55:54Z
39,518,516
<p>You need to call seek on the file object:</p> <pre><code>import pickle file_example = open("file.pck","wb") empty_list = [] pickle.dump(empty_list,file_example) file_example.close() def file_open(): file_open.file = open("file.pck","rb") file_open.empty_list = pickle.load(file_open.file) file_open.file...
1
2016-09-15T19:01:03Z
[ "python" ]
python default configuration reuse of variables
39,518,488
<pre><code>class DefaultConfig(object): class S3(object): DATA_ROOT = 's3://%(bucket_name)s/NAS' DATA_LOCATION = '{}/%(instrument_id)s/%(run_id)s'.format(DefaultConfig.S3.DATA_ROOT) </code></pre> <p>The code above gives me the following error. </p> <pre><code> File "./s3Utils.py", line 5, in ...
1
2016-09-15T18:59:07Z
39,518,524
<p>You should use it without any prefixes:</p> <pre><code>class DefaultConfig(object): class S3(object): DATA_ROOT = 's3://%(bucket_name)s/NAS' DATA_LOCATION = '{}/%(instrument_id)s/%(run_id)s'.format(DATA_ROOT) print DefaultConfig.S3.DATA_LOCATION </code></pre> <p>returns:</p> <pre><code>&gt; s3://%(buc...
1
2016-09-15T19:01:38Z
[ "python" ]
python default configuration reuse of variables
39,518,488
<pre><code>class DefaultConfig(object): class S3(object): DATA_ROOT = 's3://%(bucket_name)s/NAS' DATA_LOCATION = '{}/%(instrument_id)s/%(run_id)s'.format(DefaultConfig.S3.DATA_ROOT) </code></pre> <p>The code above gives me the following error. </p> <pre><code> File "./s3Utils.py", line 5, in ...
1
2016-09-15T18:59:07Z
39,518,552
<p>It is unable to find the <code>DefaultConfing</code> because <code>DefaultConfig</code> is not defined at the moment <code>S3</code> is created.</p> <p>Remember that class are objects. Because there are objects, that means they need to be instantiate. Python instantiate a class at the end of its definition, and the...
2
2016-09-15T19:03:38Z
[ "python" ]
django getattr and issues with updating
39,518,520
<p>In django I built a simple method that gets called and is passed a uniqueid, field specifier, and a value. It then does a simple addition to update the value in the field. I've coded it a number of ways and have come to the conclusion that getattr does not work when trying to save, update, or refresh the database. ...
1
2016-09-15T19:01:22Z
39,518,610
<p>I'm not sure what you're expecting here, but this is nothing to do with Django wanting anything, and nothing to do with <code>setattr</code>.</p> <p>Integers are immutable. However you get the value of fieldname and store it in <code>call</code>, you cannot modify it. Doing <code>call += value</code> creates a new ...
0
2016-09-15T19:07:49Z
[ "python", "django", "django-models", "getattr" ]
Pandas series.rename gives TypeError: 'str' object is not callable error
39,518,534
<p>I can't figure out why this happens. I know this could happen if I have the function name "shadowed" somehow. But how could I in this scenario? </p> <p>If I open iPython in my terminal and then type:</p> <pre><code>import pandas as pd a = pd.Series([1,2,3,4]) a.rename("test") </code></pre> <p>I get TypeError: 'st...
2
2016-09-15T19:02:06Z
39,518,872
<p>Great, thanks to Nickil Maveli who pointed out I need 0.18.1, now it works. My mistake thinking <code>brew upgrade</code> would have sorted out me having the latest version.</p>
0
2016-09-15T19:26:26Z
[ "python", "python-2.7", "pandas", "dataframe" ]
Creating active users via Google Directory API
39,518,568
<p>I am the admin for my Google domain and I am trying to automate provisioning of new users. I first attempted to do so using a command line tool called GAM.</p> <p><a href="https://github.com/jay0lee/GAM" rel="nofollow">https://github.com/jay0lee/GAM</a></p> <p>While this tool works, at least half of the users I cr...
1
2016-09-15T19:05:06Z
39,529,622
<p>Take note of the following statement from Directory API about <a href="https://developers.google.com/admin-sdk/directory/v1/guides/manage-users" rel="nofollow">Creating accounts</a>:</p> <blockquote> <p>If the Google account has purchased mail licenses, the new user account is automatically assigned a mailbox. ...
0
2016-09-16T10:47:42Z
[ "python", "google-admin-sdk", "google-directory-api" ]
Creating active users via Google Directory API
39,518,568
<p>I am the admin for my Google domain and I am trying to automate provisioning of new users. I first attempted to do so using a command line tool called GAM.</p> <p><a href="https://github.com/jay0lee/GAM" rel="nofollow">https://github.com/jay0lee/GAM</a></p> <p>While this tool works, at least half of the users I cr...
1
2016-09-15T19:05:06Z
39,623,164
<p>This issue ended up being attributed to testing on a free trial domain. Using a trial domain, both GAM and the python program above created some suspended users and some active users. However, when I tried both methods on my paid full version google domain I was able to consistently create all active users.</p>
0
2016-09-21T17:39:59Z
[ "python", "google-admin-sdk", "google-directory-api" ]
http POST message body not received
39,518,577
<p>Im currently creating a python socket http server, and I'm working on my GET and POST requests. I got my GET implementation working fine, but the body element of the POST requests won't show up. Code snippet:</p> <pre><code>self.host = '' self.port = 8080 self.listener = socket.socket(socket.AF_INET, socket.SOCK_S...
1
2016-09-15T19:05:31Z
39,519,337
<pre><code>while True: client_connection, client_address = self.listener.accept() request = client_connection.recv(2048) print request </code></pre> <p><code>recv</code> does not read exactly 2048 bytes but it reads up to 2048 bytes. If some data arrive <code>recv</code> will return with the d...
0
2016-09-15T19:54:34Z
[ "python", "sockets", "http", "http-1.1" ]
Select single item in MYSQLdb - Python
39,518,620
<p>I've been learning Python recently and have learned how to connect to the database and retrieve data from a database using MYSQLdb. However, all the examples show how to get multiple rows of data. I want to know how to retrieve only one row of data. </p> <p>This is my current method. </p> <pre><code>cur.execute("S...
1
2016-09-15T19:09:06Z
39,518,647
<p><code>.fetchone()</code> to the rescue:</p> <pre><code>result = cur.fetchone() </code></pre>
2
2016-09-15T19:10:31Z
[ "python", "mysql-python" ]
Select single item in MYSQLdb - Python
39,518,620
<p>I've been learning Python recently and have learned how to connect to the database and retrieve data from a database using MYSQLdb. However, all the examples show how to get multiple rows of data. I want to know how to retrieve only one row of data. </p> <p>This is my current method. </p> <pre><code>cur.execute("S...
1
2016-09-15T19:09:06Z
39,518,657
<p>use <code>.pop()</code></p> <pre><code>if results: result = results.pop() number = result['number'] name = result['name'] </code></pre>
1
2016-09-15T19:10:51Z
[ "python", "mysql-python" ]
Append or Add to string of specific index
39,518,734
<p>I have a list of class objects 'x'. I am trying to create a new list by appending certain attribute values of the objects but I would like to append more that one attribute per index. For example, what I currently get:</p> <pre><code>x = blah.values() newList = [] for i in range(len(x)): if x[i].status == 'ACT...
2
2016-09-15T19:17:00Z
39,518,754
<p>You can use <code>.format()</code> in order to format your string. Notice the space between <code>{} {}</code></p> <pre><code>for i in range(len(x)): if x[i].status == 'ACT': newList.append("{} {}".format(x[i].full_name,x[i].team) ) </code></pre> <p>Another way is using <code>"%s" % string</code> notat...
2
2016-09-15T19:18:31Z
[ "python", "python-2.7" ]
Append or Add to string of specific index
39,518,734
<p>I have a list of class objects 'x'. I am trying to create a new list by appending certain attribute values of the objects but I would like to append more that one attribute per index. For example, what I currently get:</p> <pre><code>x = blah.values() newList = [] for i in range(len(x)): if x[i].status == 'ACT...
2
2016-09-15T19:17:00Z
39,518,758
<p>You could put the items into one string using <code>.format()</code> and <code>append</code> the string once:</p> <pre><code>for i in range(len(x)): if x[i].status == 'ACT': newList.append('{} {}'.format(x[i].full_name, x[i].team)) </code></pre> <hr> <p>On a lighter note, using a <em>list comprehensio...
2
2016-09-15T19:19:02Z
[ "python", "python-2.7" ]
Looping SQL query in python
39,518,814
<p>I am writing a python script which queries the database for a URL string. Below is my snippet.</p> <pre><code>db.execute('select sitevideobaseurl,videositestring ' 'from site, video ' 'where siteID =1 and site.SiteID=video.VideoSiteID limit 1') result = db.fetchall() filename = '/home/Site_info...
2
2016-09-15T19:22:20Z
39,519,812
<p>I'm not sure if I completely understand what you're trying to do. I think your goal is to get a list of all links to videos. You get a link to a video by joining the <code>sitevideobaseurl</code> from <code>site</code> and <code>videositestring</code> from <code>video</code>.</p> <p>From my experience it's much eas...
1
2016-09-15T20:28:17Z
[ "python", "mysql", "loops" ]
for loop in a switch-dictionary for interactive menu
39,518,850
<p>I have a problem in a SWITCH /CASE Disctionary I am trying to implement. I got an example from <a href="http://www.pydanny.com/why-doesnt-python-have-switch-case.html" rel="nofollow">here</a> </p> <p>I simply create an interactive menu in which you can choose more than 1 option at the same time in the order you cho...
1
2016-09-15T19:24:53Z
39,518,974
<p>You actually make the function call, and not use the reference to those functions.</p> <p>If you define your dictionary as following:</p> <pre><code>switcher = { 1: func1(ips) 2: func2(ips) } </code></pre> <p>You already made the call to <code>func1</code> and <code>func2</code>. The solution here is just...
0
2016-09-15T19:32:45Z
[ "python", "for-loop", "switch-statement" ]
AttributeError: 'module' object has no attribute 'get_frontal_face_detector'
39,518,871
<p>I was trying to use python's dlib library to detect the facial landmarks. I was using the example given on <a href="http://dlib.net/face_landmark_detection.py.html" rel="nofollow">face detector</a>. I have installed all the dependencies before installing dlib.</p> <p>First I installed cmake and libboost using "sudo...
1
2016-09-15T19:26:20Z
39,518,947
<p>Rename your file from <code>dlib.py</code> to something else, say <code>dlib_project.py</code>. </p> <p>Your file, named so, is shadowing the <code>dlib</code> library that has all of the functionality you need, as it is imported instead of the library, being first in the hierarchy.</p>
2
2016-09-15T19:31:23Z
[ "python", "opencv", "dlib" ]
Comparing list comprehensions and explicit loops (3 array generators faster than 1 for loop)
39,518,899
<p>I did homework and I accidentally found a strange inconsistency in the speed of the algorithm. Here is 2 versions of code of same function bur with 1 difference: in first version i use 3 times array generator to filter some array and in second version i use 1 for loop with 3 if statements to do same filter work.</p>...
3
2016-09-15T19:28:06Z
39,518,977
<p>Using simple <code>for</code> is faster than <code>list comprehesion</code>. It is almost 2 times faster. Check below results:</p> <p>Using <code>list comprehension</code>: <em>58 usec</em> </p> <pre><code>moin@moin-pc:~$ python -m timeit "[i for i in range(1000)]" 10000 loops, best of 3: 58 usec per loop </code><...
6
2016-09-15T19:32:59Z
[ "python", "arrays", "python-2.7", "time" ]
Comparing list comprehensions and explicit loops (3 array generators faster than 1 for loop)
39,518,899
<p>I did homework and I accidentally found a strange inconsistency in the speed of the algorithm. Here is 2 versions of code of same function bur with 1 difference: in first version i use 3 times array generator to filter some array and in second version i use 1 for loop with 3 if statements to do same filter work.</p>...
3
2016-09-15T19:28:06Z
39,519,199
<p>The algorithmic structure differs and the conditional structure is to be incriminated. the test to append into r and m can be discarded by the previous test. A more strict comparison regarding a for loop with <code>append</code>, and list comprehension would be against the non-optimal following </p> <pre><code>for ...
2
2016-09-15T19:46:24Z
[ "python", "arrays", "python-2.7", "time" ]
Comparing list comprehensions and explicit loops (3 array generators faster than 1 for loop)
39,518,899
<p>I did homework and I accidentally found a strange inconsistency in the speed of the algorithm. Here is 2 versions of code of same function bur with 1 difference: in first version i use 3 times array generator to filter some array and in second version i use 1 for loop with 3 if statements to do same filter work.</p>...
3
2016-09-15T19:28:06Z
39,519,661
<p>Let's define the functions we will need to answer the question and timeit them:</p> <p><a href="http://i.stack.imgur.com/M8Chj.png" rel="nofollow"><img src="http://i.stack.imgur.com/M8Chj.png" alt="enter image description here"></a></p> <p>we can see that the for loops without the append command is as fast as the ...
4
2016-09-15T20:17:32Z
[ "python", "arrays", "python-2.7", "time" ]
Comparing list comprehensions and explicit loops (3 array generators faster than 1 for loop)
39,518,899
<p>I did homework and I accidentally found a strange inconsistency in the speed of the algorithm. Here is 2 versions of code of same function bur with 1 difference: in first version i use 3 times array generator to filter some array and in second version i use 1 for loop with 3 if statements to do same filter work.</p>...
3
2016-09-15T19:28:06Z
39,520,286
<p>Let's dissipate that doubt : The <strong>second version</strong> is slightly faster : <strong>list comprehension are faster</strong>, yet two arrays looping and as much conditionals are discarded in one iteration. </p> <pre><code>def kth_order_statistic1(array,k): pivot = (array[0] + array[len(array) - 1]) // 2...
2
2016-09-15T20:59:53Z
[ "python", "arrays", "python-2.7", "time" ]
How to print info when 2 things are correct and to use the input fuction when the those two things are incorrect
39,518,960
<p>I am doing a controlled assessment. I have this code : </p> <pre><code># user Qualifications print("\nQualification Level") print("\n""\"AP\" = Apprentice", "\n\"FQ\" = Fully-Qualified") user_qual = input("Enter you Qualification Level: ") </code></pre> <p>When the <code>user_qual</code> is equal to <code>A...
0
2016-09-15T19:31:56Z
39,519,099
<p>You can try defining the qualification levels within a variable. In this simple case a <a href="http://openbookproject.net/thinkcs/python/english3e/tuples.html" rel="nofollow">tuple</a> suffices, but if there were to be more qualification levels, a <a href="http://openbookproject.net/thinkcs/python/english3e/diction...
0
2016-09-15T19:40:31Z
[ "python", "python-3.x" ]
How to print info when 2 things are correct and to use the input fuction when the those two things are incorrect
39,518,960
<p>I am doing a controlled assessment. I have this code : </p> <pre><code># user Qualifications print("\nQualification Level") print("\n""\"AP\" = Apprentice", "\n\"FQ\" = Fully-Qualified") user_qual = input("Enter you Qualification Level: ") </code></pre> <p>When the <code>user_qual</code> is equal to <code>A...
0
2016-09-15T19:31:56Z
39,519,154
<p>You need to turn your code into a function so it can be called again, if the criteria are not met:</p> <pre><code>def prompt(): # user Qualifications print('\nQualification Level') print('\n"AP" = Apprentice\n"FQ" = Fully-Qualified') user_qual = input('Enter you Qualification Level: ') if user...
0
2016-09-15T19:43:18Z
[ "python", "python-3.x" ]
When trying to install lxml in python, get error ftp error 200 type set to I
39,518,975
<p>These are the specific error message i got when trying to install lxml in python. I have installed C++ 9.0. Can anyone tell how to fix it? Thanks a lot.</p> <p>C:\Python27\Scripts></p> <pre><code>pip install lxml Collecting lxml Using cached lxml-3.6.4.tar.gz Complete output from command python setup.py egg_in...
0
2016-09-15T19:32:54Z
39,900,926
<p>Add </p> <p>urlcleanup() </p> <p>before </p> <p>File "buildlibxml.py", line 55, in download_and_extract_zlatkovic_binaries</p> <pre><code> urlretrieve(srcfile, destfile) </code></pre> <p><a href="http://stackoverflow.com/a/39900735/6932850">See Here</a></p>
0
2016-10-06T16:12:43Z
[ "python", "ftp", "lxml" ]
From django rest framework 3 pre_save, pre_delete is not available than how to manipulate and insert requested user name in any field?
39,519,019
<p>I am using django rest framework. I want to insert request user name in the author field of posts. But I cannot manipulate the data before saving as the pre_save method is depreciated from drf 3 <a href="http://www.django-rest-framework.org/api-guide/generic-views/" rel="nofollow">drf generic view</a>. </p> <pre><...
0
2016-09-15T19:35:40Z
39,519,097
<p>You can use <code>perfom_create</code> and <code>perform_update</code> in your views </p> <blockquote> <p>The pre_save and post_save hooks no longer exist, but are replaced with perform_create(self, serializer) and perform_update(self, serializer).</p> <p>These methods should save the object instance by ...
0
2016-09-15T19:40:21Z
[ "python", "django", "rest", "python-3.x", "django-rest-framework" ]