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
R &R :stage 4: Create and train the ranker,
37,911,004
<p>I followed the <a href="https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/retrieve-rank/get_start.shtml" rel="nofollow">tutorial</a> for Retrieve &amp; Rank, I did stage 1,2 and 3, however I couldn't finish stage 4: Create and train the ranker, When ever I followed the steps listed in stage 4, I r...
-1
2016-06-19T19:26:49Z
37,913,711
<p>Python is telling you it can't find the script <code>train.py</code> in the current working directory. Did you skip this step in the <a href="https://www.ibm.com/smarterplanet/us/en/ibmwatson/developercloud/doc/retrieve-rank/get_start.shtml" rel="nofollow">tutorial</a>?</p> <blockquote> <p>Navigate to the downlo...
0
2016-06-20T02:00:47Z
[ "python" ]
How to groupby count across multiple columns in pandas
37,911,043
<p>I have the following sample dataframe in Python pandas:</p> <pre><code>+---+------+------+------+ | | col1 | col2 | col3 | +---+------+------+------+ | 0 | a | d | b | +---+------+------+------+ | 1 | a | c | b | +---+------+------+------+ | 2 | c | b | c | +---+------+------+------+ | ...
2
2016-06-19T19:31:03Z
37,911,066
<p>You can <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.apply.html" rel="nofollow"><code>apply</code></a> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html" rel="nofollow"><code>value_counts</code></a> with <a href="http://pandas.pydata.org...
1
2016-06-19T19:34:41Z
[ "python", "pandas", "dataframe", "counter", "data-analysis" ]
How to groupby count across multiple columns in pandas
37,911,043
<p>I have the following sample dataframe in Python pandas:</p> <pre><code>+---+------+------+------+ | | col1 | col2 | col3 | +---+------+------+------+ | 0 | a | d | b | +---+------+------+------+ | 1 | a | c | b | +---+------+------+------+ | 2 | c | b | c | +---+------+------+------+ | ...
2
2016-06-19T19:31:03Z
37,911,110
<p>You can <code>stack()</code> the dataframe to put all columns into rows and then do <code>value_counts</code>:</p> <pre><code>df.stack().value_counts() b 5 c 4 a 4 d 2 dtype: int64 </code></pre>
3
2016-06-19T19:38:34Z
[ "python", "pandas", "dataframe", "counter", "data-analysis" ]
How to obtain the right alpha value to perfectly blend two images?
37,911,062
<p>I've been trying to blend two images. The current approach I'm taking is, I obtain the coordinates of the overlapping region of the two images, and only for the overlapping regions, I blend with a hardcoded alpha of 0.5, before adding it. SO basically I'm just taking half the value of each pixel from overlapping reg...
9
2016-06-19T19:34:00Z
37,918,596
<p>Here is the way I would do it in general:</p> <pre><code>int main(int argc, char* argv[]) { cv::Mat input1 = cv::imread("C:/StackOverflow/Input/pano1.jpg"); cv::Mat input2 = cv::imread("C:/StackOverflow/Input/pano2.jpg"); // compute the vignetting masks. This is much easier before warping, but I will t...
8
2016-06-20T09:10:55Z
[ "python", "opencv", "image-processing", "computer-vision", "alphablending" ]
How to obtain the right alpha value to perfectly blend two images?
37,911,062
<p>I've been trying to blend two images. The current approach I'm taking is, I obtain the coordinates of the overlapping region of the two images, and only for the overlapping regions, I blend with a hardcoded alpha of 0.5, before adding it. SO basically I'm just taking half the value of each pixel from overlapping reg...
9
2016-06-19T19:34:00Z
37,919,173
<p>There are 2 obvious problems with your images:</p> <ol> <li><p><strong>Border area has distorted lighting conditions</strong></p> <p>That is most likely caused by the optics used to acquire images. So to remedy that you should use only inside part of the images (cut off few pixels from border.</p> <p>So when cut ...
4
2016-06-20T09:38:51Z
[ "python", "opencv", "image-processing", "computer-vision", "alphablending" ]
Lists: using better slicing to find iterative sums of subsets
37,911,091
<p>Say I have a list, </p> <pre><code>A = range(1, 6) = [1, 2, 3, 4, 5] </code></pre> <p><code>B</code>, the end result, is a list of lists. Given <code>i</code> and <code>j</code>, how would you make a list of iterative sums where index <code>i</code> bounds one side and <code>j</code> the other? </p> <p><code>B[j]...
0
2016-06-19T19:36:46Z
37,911,179
<p>You end up recalculating the sums many times. Instead create them once and look them up for each element of <code>b</code>:</p> <pre><code>A = range(1,6) n = len(A) mapping = {} for i in xrange(n): for j in xrange(i,n): mapping[i,j] = sum(A[i:j+1]) B = [] for j in xrange(n): b = [] for i in xr...
1
2016-06-19T19:46:55Z
[ "python", "list", "slice", "reduce" ]
How to get all circles that intersect a given circle in PostGIS?
37,911,109
<p>I'm trying to find out all the circles stored in the database(The circles are present all over the world) that intersect or overlap a given circle. I've stored the circles like this:</p> <pre><code>CREATE TABLE circles(gid serial PRIMARY KEY, name varchar, code integer, the_geog geography(POLYGON,4326) ); INSERT I...
0
2016-06-19T19:38:34Z
37,911,288
<p>I got this working by using:</p> <pre><code>select * from circles where st_intersects (circles.the_geog,geometry(ST_Buffer(geography(ST_GeomFromText('POINT(13.28527 52.521711)')), 1000))); </code></pre>
0
2016-06-19T20:00:28Z
[ "python", "postgresql", "geometry", "postgis", "intersection" ]
Variable loses reference inside nested loop
37,911,126
<p>My variable <code>tag</code> loses its reference when enters the nested <code>for</code>:</p> <pre><code>file_with_all_tags = open("tags.txt", "r") origem = open("origem.html", "r") for tag in file_with_all_tags: final_file_name = "tag-" + tag + ".html" final_file = open(final_file_name, "w") for lin...
-2
2016-06-19T19:40:20Z
37,931,208
<p>Problem solved! Actually my iteration over the file "origem.html" was getting exhausted. I had to move the open() and close() functions to inside the loop. Thanks guys! Thanks @rrauenza!</p>
0
2016-06-20T20:23:08Z
[ "python", "loops", "scope" ]
Use loc and iloc together in pandas
37,911,147
<p>Say I have the following dataframe, and I want to change the two elements in column <code>c</code> that correspond to the first two elements in column <code>a</code> that are equal to <code>1</code> to equal <code>2</code>.</p> <pre><code>&gt;&gt;&gt; df = pd.DataFrame({"a" : [1,1,1,1,2,2,2,2], "b" : [2,3,1,4,5,6,7...
4
2016-06-19T19:42:27Z
37,911,207
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.isin.html" rel="nofollow"><code>Index.isin</code></a>:</p> <pre><code>import pandas as pd df = pd.DataFrame({"a" : [1,1,1,1,2,2,2,2], "b" : [2,3,1,4,5,6,7,2], "c" : [1,2,3,4,5,6,7,8]}) #m...
2
2016-06-19T19:50:45Z
[ "python", "pandas", "indexing", "dataframe" ]
Use loc and iloc together in pandas
37,911,147
<p>Say I have the following dataframe, and I want to change the two elements in column <code>c</code> that correspond to the first two elements in column <code>a</code> that are equal to <code>1</code> to equal <code>2</code>.</p> <pre><code>&gt;&gt;&gt; df = pd.DataFrame({"a" : [1,1,1,1,2,2,2,2], "b" : [2,3,1,4,5,6,7...
4
2016-06-19T19:42:27Z
37,911,231
<p>A dirty way would be:</p> <pre><code>df.loc[df[df['a']==1][:2].index, 'c'] = 2 </code></pre>
3
2016-06-19T19:53:08Z
[ "python", "pandas", "indexing", "dataframe" ]
Celery use wrong python version
37,911,169
<p>I have a Django project, and I want to use Celery. I've installed Celery for python3, and then I run this command : <code>sudo celery -A myApp worker -l info</code></p> <p>But in the log, I see that it's Celery of python2.7 which is used : <code>File "/Library/Python/2.7/site-packages</code></p> <p>Any idea how fo...
0
2016-06-19T19:45:26Z
38,028,133
<p>Ok, thanks to @Wayne I've found the solution.</p> <p>First, use this command to see where the head of celery is : <code>head -n 10 /usr/local/bin/celery</code> For myself, this is what I get : </p> <pre><code>#!/usr/bin/python # EASY-INSTALL-ENTRY-SCRIPT: 'celery==3.1.23','console_scripts','celery' __requires__ = ...
1
2016-06-25T11:44:15Z
[ "python", "django", "celery" ]
How can I relatively scale something between two points?
37,911,194
<p>This is more of a math question, and I couldn't seem to find any answers online.</p> <p>So here is what I am trying to accomplish:</p> <p>Lets say I have a circle, starting at <code>Ay</code>. Now as this circle moves towards <code>By</code>, I want it to scale proportionally to a certain size.</p> <p>So for exam...
0
2016-06-19T19:49:06Z
37,911,831
<p>If vector <code>v=(By-Ay)</code>, the line between <code>Ay</code> and <code>By</code> can be defined as <code>l(t)=Ay+vt</code>. Therefore any point on <code>l(t)</code> with parameter <code>t</code> has scaling factor of <code>s=47.5t+5</code>. For instance at t=0 that gives point <code>Ay</code> on the line has s...
1
2016-06-19T21:03:29Z
[ "python", "math", "pygame", "2d-games" ]
How can I relatively scale something between two points?
37,911,194
<p>This is more of a math question, and I couldn't seem to find any answers online.</p> <p>So here is what I am trying to accomplish:</p> <p>Lets say I have a circle, starting at <code>Ay</code>. Now as this circle moves towards <code>By</code>, I want it to scale proportionally to a certain size.</p> <p>So for exam...
0
2016-06-19T19:49:06Z
37,913,698
<p>For linear scaling if</p> <ul> <li><code>D[Ay]</code> is the diameter/side of circle/square when it is at <code>Ay</code></li> <li><code>D[By]</code> is the diameter/side of circle/square when it is at <code>By</code></li> <li><code>D[Cy]</code> is the diameter/side of circle/square when it is at <code>Cy</code></l...
2
2016-06-20T01:57:39Z
[ "python", "math", "pygame", "2d-games" ]
How can I relatively scale something between two points?
37,911,194
<p>This is more of a math question, and I couldn't seem to find any answers online.</p> <p>So here is what I am trying to accomplish:</p> <p>Lets say I have a circle, starting at <code>Ay</code>. Now as this circle moves towards <code>By</code>, I want it to scale proportionally to a certain size.</p> <p>So for exam...
0
2016-06-19T19:49:06Z
37,916,118
<h2>Tweening in terms of position.</h2> <p><strong>Keys and keyFrames</strong></p> <p>In animation we define known positions and states as key frames, normally we index the key frames in terms of time.</p> <pre class="lang-js prettyprint-override"><code>// an array of keys. The ? represents the applicable number val...
1
2016-06-20T06:45:51Z
[ "python", "math", "pygame", "2d-games" ]
Impulse length - Arduino -> Raspberry
37,911,220
<p>I dont know why is this happening but am quite pissed off :-), because am struggling with this for two days now..</p> <p>HW: Arduino board --> Raspberry Model 2 B</p> <p>Am sending one second impulse from arduino mega digital pin 8 to raspberry. I added voltage divider so i have clean 3,25V impulse.</p> <p>RSP re...
1
2016-06-19T19:51:56Z
37,911,423
<p>For me, it's more a matter of electronic. </p> <p>In fact, for that kind of library, <strong>we can assume that the functions work correctly</strong> (I suppose that you wrote correct code that was built like that: <a href="https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/buttons_and_switches/" rel="no...
0
2016-06-19T20:16:48Z
[ "python", "arduino", "raspberry-pi" ]
Impulse length - Arduino -> Raspberry
37,911,220
<p>I dont know why is this happening but am quite pissed off :-), because am struggling with this for two days now..</p> <p>HW: Arduino board --> Raspberry Model 2 B</p> <p>Am sending one second impulse from arduino mega digital pin 8 to raspberry. I added voltage divider so i have clean 3,25V impulse.</p> <p>RSP re...
1
2016-06-19T19:51:56Z
37,925,054
<p>Thank you for replay. This are the test's that I made today. - I have connected the zener diode to get the 3,3v and this part is good - tested with different impulse lengths None of them worked.</p> <p>It's interesting, if i start the RSP script and if i just wait for impulse ( without triggering it ) i will get so...
0
2016-06-20T14:26:27Z
[ "python", "arduino", "raspberry-pi" ]
pixelsorting self-calling function explanation request
37,911,228
<p>what does that function do exactly? I understand it sorts pixels by brightness in three diferent lists (lesser, pivot, greater). But i do not quite know how, the self-calling aspect is realy confusing. I am not very experienced with python and programming in general.</p> <pre><code>def quick_sort(pixels): #Quicksor...
0
2016-06-19T19:52:58Z
37,911,261
<p>It's <strong>just a simple implementation of famous quick-sort</strong> algorithm for array of 3D vectors. The reference algorithm is: <a href="https://en.wikipedia.org/wiki/Quicksort" rel="nofollow">https://en.wikipedia.org/wiki/Quicksort</a></p> <p>If you want to sort [5 2 8 4 1 7 9], you pick a "pivot", and sor...
0
2016-06-19T19:57:43Z
[ "python", "rgb" ]
Error in displaying web pages using Flask
37,911,235
<p>I used flask to make a web portal for the users to register but when I run the html file using a local host, the display looks like below:</p> <p><a href="http://i.stack.imgur.com/mbJzJ.png" rel="nofollow"><img src="http://i.stack.imgur.com/mbJzJ.png" alt="enter image description here"></a></p>
-1
2016-06-19T19:53:31Z
37,911,326
<p>This html file is not actually an html file but rather a Jinja template. Thus, you need it to be served via your flask app render_template function. So it makes not sense to open this page via browser as html.</p>
0
2016-06-19T20:05:08Z
[ "python", "web", "flask", "website" ]
Theano tutorial: UnusedInputError: theano.function
37,911,325
<p>Attempting to teach myself neural nets, I have begun working my way through the Theano tutorials over at deeplearning.net. I just encountered an error that I was not expecting as I have literally copied and pasted every line of code from the tutorial. I'm sure whatever is wrong is something small and I'm just lookin...
0
2016-06-19T20:04:58Z
38,149,534
<p>I'm also new at theano, and I just ran into this. It seems to be a bug in the tutorial. The error message suggests using the parameter on_unused_input to suppress the error, but this isn't a keyword argument for <a href="http://deeplearning.net/software/theano/library/compile/function.html#theano.compile.function_mo...
0
2016-07-01T15:53:34Z
[ "python", "theano" ]
Recognizing "return" key input in Python | Pygame
37,911,385
<p>Im trying to figure out how to implement keybindings into my game. By pressing "return", the player should be able to do something. </p> <p>But I am not able to get my code to recognize when the player presses the return key. My Code is below. I get to the "yay!" part, but "bla" is never written on the commandline,...
0
2016-06-19T20:12:12Z
37,911,414
<p>The event type attribute does not tell you what key is pressed. The type will always be "KEYDOWN" or "KEYUP" etc.. The actual key that was pressed is stored in the key attribute. From the Pygame documentation:</p> <blockquote> <p>The event queue gets pygame.KEYDOWN and pygame.KEYUP events when the keyboard butt...
2
2016-06-19T20:15:52Z
[ "python", "pygame" ]
Dataframe to .csv - is only writing last value - Python/Pandas
37,911,483
<p>I'm trying to write a dataframe to a .csv using df.to_csv(). For some reason, its only writing the last value (data for the last ticker). It reads through a list of tickers (turtle, all tickers are in first column) and spits out price data for each ticker. I can print all the data without a problem but can't seem to...
-2
2016-06-19T20:22:52Z
37,911,582
<p>Use <code>a</code> for appending instead of <code>wb</code> because it overwrites the data in every iteration of loop.For different modes of opening a file see <a href="http://www.tutorialspoint.com/python/python_files_io.htm" rel="nofollow">here</a>.</p>
2
2016-06-19T20:36:00Z
[ "python", "csv", "pandas", "dataframe" ]
Python selenium presence_of_element_located((By.XPATH, ) need case insensitive
37,911,491
<p>I stumbled upon fact then <code>xref</code> maybe in upper case or lower case (even partly) on searched page. How to ensure script finds xref if xref is present on page regardless of case?</p> <p>Post <a href="http://stackoverflow.com/questions/20228962/python-selenium-xpath-to-find-element-with-case-insensitive-ch...
1
2016-06-19T20:24:10Z
37,912,698
<p>Looks like <code>lower-case(@href)</code> is not working (at least for my Firefox on Windows 7), also not <code>fn:lower-case(@href)</code>.</p> <p>I resort to <code>translate</code> which I've found in posts:</p> <pre><code>'//a[contains(translate(@href, "ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz"),...
2
2016-06-19T22:59:58Z
[ "python", "selenium", "xpath", "case-sensitive" ]
Form field with underscore doesn't work
37,911,581
<p>I'm using a form to obtain the data from a post request and I noticed some behavior I'm not familiar with. I have two versions of my form shown below. The only variation is that in the second version of the form, I have an underscore in my variable names. </p> <pre><code>class EditTitleForm(Form): newTitle =...
0
2016-06-19T20:35:36Z
37,911,979
<p>The names of the fields correspond to the keys in the data being read. If you change the field names, you need to change the keys in the JSON data as well. Setting the label (the first argument to a field) doesn't effect this, that's only used when rendering the fields as HTML.</p> <pre><code># if attribute name ...
0
2016-06-19T21:23:39Z
[ "python", "flask", "wtforms" ]
How can I schedule or queue api calls to maintain rate limit?
37,911,620
<p>I am trying to continuously crawl a large amount of information from a site using the REST api they provide. I have following constraints-</p> <ol> <li>Stay within api limit (5 calls/sec)</li> <li>Utilising the full limit (making exactly 5 calls per second, 5*60 calls per minute)</li> <li>Each call will be with dif...
0
2016-06-19T20:40:20Z
37,914,328
<p>You needn't add an external dependency just for rate-limiting, as your use case is rather straightforward.</p> <p>I can think of two options:</p> <ul> <li>Modify the script (that currently wakes up every minute and makes 10-20 API calls) to wake up every second and make 5 calls (sequentially or in parallel). <ul>...
1
2016-06-20T03:41:32Z
[ "python", "amazon-web-services", "scheduled-tasks", "celery", "task-queue" ]
Python decorators with *args and **kwargs failing to execute with error message about too many positional arguments
37,911,641
<p>Any article, tutorial, etc. I have read on writing decorators in Python has pointed me to using *args and **kwargs to write decorators which can be applied to any function and / or method (including <a href="https://stackoverflow.com/questions/739654/how-can-i-make-a-chain-of-function-decorators-in-python">this grea...
-1
2016-06-19T20:42:56Z
37,913,028
<p>It may because you are trying to wrap a method of a class with the decorator. The requirements for writing decorators which work on methods of a class are a bit different, even worse if you need the one decorator which can work on both normal functions and methods of a class.</p> <p>You are much better off using a ...
0
2016-06-19T23:53:49Z
[ "python", "python-3.x", "python-decorators" ]
OpenCV HSV value changes depending on location on the screen/camera
37,911,669
<p>I'm pretty new to all programming and have been trying to get a grasp on Python (2.7.6), OpenCV, and ROS to be able to use a neural network in a robot. </p> <p>I am now stuck in an OpenCV (2.4.8) problem with getting the correct HSV-values, in short, it suddenly changes from red (around 5 for Hue) or blue (about 11...
1
2016-06-19T20:45:51Z
37,947,452
<p>After two days of struggling with this problem I finally found where I went wrong:</p> <p>The coordinates returned by this:</p> <pre><code>(x, y), radius = cv2.minEnclosingCircle(cnt) </code></pre> <p>Are not x and y coordinates but a row and column index. So when I moved my camera or the circle from left to rig...
1
2016-06-21T14:38:58Z
[ "python", "opencv", "numpy", "image-processing", "computer-vision" ]
Seaborn histogram with 4 panels (2 x 2) in Python
37,911,731
<p>I'm trying to recreate this image using <code>sklearn.datasets.load_iris</code> and <code>seaborn</code>. I really like the idea of doing <code>fig, ax = plt.subplots()</code> and then using <code>seaborn</code>'s <code>ax=ax</code> attribute. I can't figure out how to recreate this plot: <a href="http://i.stack.i...
1
2016-06-19T20:53:33Z
37,915,066
<p>The problem here is that you are indexing a numpy array with a boolean series instead of a boolean numpy array.</p> <pre><code>sns.distplot(DF_data.as_matrix()[Se_targets==idx_target, idx_feature], label=D_targets[idx_target], kde=False, bins=10, ax=ax[i][j]) </co...
2
2016-06-20T05:19:52Z
[ "python", "matplotlib", "plot", "histogram", "seaborn" ]
Seaborn histogram with 4 panels (2 x 2) in Python
37,911,731
<p>I'm trying to recreate this image using <code>sklearn.datasets.load_iris</code> and <code>seaborn</code>. I really like the idea of doing <code>fig, ax = plt.subplots()</code> and then using <code>seaborn</code>'s <code>ax=ax</code> attribute. I can't figure out how to recreate this plot: <a href="http://i.stack.i...
1
2016-06-19T20:53:33Z
37,924,368
<p>Or you could do</p> <pre><code>import pandas as pd import seaborn as sns import matplotlib.pyplot as plt iris = sns.load_dataset("iris") iris_long = pd.melt(iris, "species", var_name="measurement") g = sns.FacetGrid(iris_long, hue="species", col="measurement", col_wrap=2, sharex=False) g.map(plt.hist, "value", alp...
1
2016-06-20T13:54:54Z
[ "python", "matplotlib", "plot", "histogram", "seaborn" ]
How to mix charts with django and the Chartkick library
37,911,837
<p>I've been searching and trying on my own but I can't manage to mix two different charts with this library. I can have two column-charts on the same board but I can't have a line and a column and I didn't see any references to that on the webdoc of <code>Chartkick</code>so far. </p> <p>views.py : </p> <pre><code>s...
0
2016-06-19T21:03:56Z
37,950,637
<p>Apparently it seems you can't do it with any django wrapper available yet. I would advise to use directly the JS regarding <code>google chart</code>or <code>highchart</code>.</p>
0
2016-06-21T17:13:38Z
[ "python", "django", "google-visualization", "chartkick" ]
Python puts tabs in where none should be
37,911,841
<p>Need help formatting my Python web scrape . For whatever reason when I get the info I need it seems that the words have been tabbed out of place and not sure how to fix it. </p> <p>Any help is appreciated</p> <p>Thanks</p> <pre><code>import requests from bs4 import BeautifulSoup r = requests.get("http://www.ca...
0
2016-06-19T21:04:30Z
37,911,966
<p>Use <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#get-text" rel="nofollow"><code>.get_text()</code></a> providing the <code>strip</code> argument. Additionally, replace newlines with spaces:</p> <pre><code>g_data = soup.find_all("h2", {"class": "product_link"}) for item in g_data: print(item.g...
1
2016-06-19T21:22:05Z
[ "python" ]
Python 3.5 - Number Picker game, while loop & variables(beginner)
37,911,907
<p>so i am quite new to python and there seems to be a problem with my while loop or the boolean win value, it keeps asking for another number even after i have won. There is also a problem with my life variable as whenever i get an answer wrong it comes up with an error; "UnboundLocalError: local variable 'lives' refe...
0
2016-06-19T21:13:38Z
37,911,931
<p>At the beginning of your compare function add the line <code>global lives</code>.</p> <p>The error that you are getting <code>local variable lives referenced before assignment</code> means that you are accessing a local variable, but that variable does not exist. In this case, you need to tell python that the vari...
0
2016-06-19T21:17:43Z
[ "python", "loops", "variables", "while-loop", "boolean" ]
Python 3.5 - Number Picker game, while loop & variables(beginner)
37,911,907
<p>so i am quite new to python and there seems to be a problem with my while loop or the boolean win value, it keeps asking for another number even after i have won. There is also a problem with my life variable as whenever i get an answer wrong it comes up with an error; "UnboundLocalError: local variable 'lives' refe...
0
2016-06-19T21:13:38Z
37,911,948
<p>Both lives and win variable in your compare function are not the same as the global ones - you create new ones.</p>
-1
2016-06-19T21:19:43Z
[ "python", "loops", "variables", "while-loop", "boolean" ]
Python 3.5 - Number Picker game, while loop & variables(beginner)
37,911,907
<p>so i am quite new to python and there seems to be a problem with my while loop or the boolean win value, it keeps asking for another number even after i have won. There is also a problem with my life variable as whenever i get an answer wrong it comes up with an error; "UnboundLocalError: local variable 'lives' refe...
0
2016-06-19T21:13:38Z
37,911,962
<p>First, add global lives in the beginning of your function, then turn the if statement to part of the while loop, like so:</p> <pre><code>def compare(): global lives,win if guess == rand_num: print("You guessed correct!") win = True elif guess &gt; rand_num: print ("Guess lower!")...
-1
2016-06-19T21:21:41Z
[ "python", "loops", "variables", "while-loop", "boolean" ]
Python 3.5 - Number Picker game, while loop & variables(beginner)
37,911,907
<p>so i am quite new to python and there seems to be a problem with my while loop or the boolean win value, it keeps asking for another number even after i have won. There is also a problem with my life variable as whenever i get an answer wrong it comes up with an error; "UnboundLocalError: local variable 'lives' refe...
0
2016-06-19T21:13:38Z
37,911,982
<p>Right now, your code is taking for granted that the "compare" function will know what variables to use. Functions do not know what values to use inside unless you explicitly define or provide those variables. To fix your code, you should write:</p> <pre><code>def compare(guess, lives, rand_num): ... </code></pr...
0
2016-06-19T21:23:55Z
[ "python", "loops", "variables", "while-loop", "boolean" ]
Add 3 columns to DataFrame via map
37,911,976
<p>Is it possible to add 3 new columns to this little DataFrame in one map?</p> <pre><code>import datetime as dt import pandas as pd from pandas import * df = pd.DataFrame({'myDate':['2006-02-12' ,'2007-07-20' ,'2009-05-19']}) def convert_date(val): ...
3
2016-06-19T21:23:18Z
37,911,990
<p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.split.html#pandas.Series.str.split" rel="nofollow">.str.split()</a>:</p> <pre><code>In [11]: df[['day', 'year','month']] = df.myDate.str.split('-', expand=True).astype(int) In [12]: df Out[12]: myDate day year m...
2
2016-06-19T21:25:01Z
[ "python", "pandas", "dataframe" ]
Add 3 columns to DataFrame via map
37,911,976
<p>Is it possible to add 3 new columns to this little DataFrame in one map?</p> <pre><code>import datetime as dt import pandas as pd from pandas import * df = pd.DataFrame({'myDate':['2006-02-12' ,'2007-07-20' ,'2009-05-19']}) def convert_date(val): ...
3
2016-06-19T21:23:18Z
37,912,037
<p>I think you can convert column <code>myDate</code> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.year.html" rel="nofollow"><code>dt.year</...
2
2016-06-19T21:31:15Z
[ "python", "pandas", "dataframe" ]
Pandas vectorized operations not working on large dataset
37,911,994
<p>I ran the following code and found it to be working as expected on rather small datasets, but not on large ones. You can try it for yourself:</p> <pre><code>import pandas as pd import numpy as np # generating dataframe of one million observations observations = 1000000 df = pd.DataFrame(np.random.randint(0,100,siz...
1
2016-06-19T21:25:10Z
37,912,486
<p>After completely de-installing all Python versions and packages, I re-installed Anaconda. This solved the issue for me. I don't know exactly the cause of the issue I had though... I must have messed with packages or versions of Python.</p> <p>Thanks for the comments which helped me understand what was needed !</p>
2
2016-06-19T22:31:43Z
[ "python", "pandas", "vectorization" ]
Python [float(n) for n in line.split()] over a file that contains only one column
37,912,014
<p>I have created a python script where I write in a file an array of <code>V</code> (volumes) in a column:</p> <pre><code> import numpy as np volume_pressure_energy = open('datafile.dat', 'w') # Open the file, 'w' for writing V = np.linspace(62, 72, 5) with open('datafile.dat') as volume_pressure_energy: np.s...
0
2016-06-19T21:27:45Z
37,912,075
<p>You're splitting each line and passing the list comprehension (a list) instead of the number, float, that you should be passing to the methods.</p> <p>I think what you want to do is:</p> <pre><code>volume = [float(n) for n in line.split()][0] </code></pre> <p>Which could be further simplified to not treat all ele...
1
2016-06-19T21:35:42Z
[ "python", "file", "split", "line" ]
Python [float(n) for n in line.split()] over a file that contains only one column
37,912,014
<p>I have created a python script where I write in a file an array of <code>V</code> (volumes) in a column:</p> <pre><code> import numpy as np volume_pressure_energy = open('datafile.dat', 'w') # Open the file, 'w' for writing V = np.linspace(62, 72, 5) with open('datafile.dat') as volume_pressure_energy: np.s...
0
2016-06-19T21:27:45Z
37,912,078
<p>The error is telling you that you can't divide an integer by a list. I suspect you're confusing lists and numpy arrays. Perhaps you can convert the list into an array using something like <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.asarray.html" rel="nofollow"><code>asarray()</code></a>.</p> ...
1
2016-06-19T21:36:06Z
[ "python", "file", "split", "line" ]
Python [float(n) for n in line.split()] over a file that contains only one column
37,912,014
<p>I have created a python script where I write in a file an array of <code>V</code> (volumes) in a column:</p> <pre><code> import numpy as np volume_pressure_energy = open('datafile.dat', 'w') # Open the file, 'w' for writing V = np.linspace(62, 72, 5) with open('datafile.dat') as volume_pressure_energy: np.s...
0
2016-06-19T21:27:45Z
37,912,146
<p>If there's going to be just one number on each line, then to read you should do</p> <pre><code>volume = float(line) </code></pre> <p>line.split() returns a list with a single element containing the string on that line. So when you do</p> <pre><code>volume = [float(n) for n in line.split()] </code></pre> <p>You'r...
1
2016-06-19T21:44:29Z
[ "python", "file", "split", "line" ]
Python [float(n) for n in line.split()] over a file that contains only one column
37,912,014
<p>I have created a python script where I write in a file an array of <code>V</code> (volumes) in a column:</p> <pre><code> import numpy as np volume_pressure_energy = open('datafile.dat', 'w') # Open the file, 'w' for writing V = np.linspace(62, 72, 5) with open('datafile.dat') as volume_pressure_energy: np.s...
0
2016-06-19T21:27:45Z
37,912,451
<p>A more versatile solution is to use <a href="http://docs.scipy.org/doc/numpy-1.10.0/reference/generated/numpy.fromfile.html" rel="nofollow"><code>numpy.fromfile</code></a>. It handles binary files and reads it directly to a ndarray.</p> <pre><code>volume_pressure_energy = np.fromfile('datafile.dat',dtype=float) </c...
1
2016-06-19T22:26:15Z
[ "python", "file", "split", "line" ]
Installed older version of Python, can't get PATH to direct
37,912,021
<p>I'm receiving the message:</p> <blockquote> <p>The program can't start because python34.dll is missing from your computer. Try reinstalling the program to fix this problem.</p> </blockquote> <p>I want to use python27, so I uninstalled python34, but can't get the cmd prompt to redirect to the python27 .dlls.</p> ...
0
2016-06-19T21:29:04Z
37,913,217
<p>I would suggest you manually edit your PATH (through Windows' GUI instead of CMD) and ensure two things:</p> <p>a) That <code>C:\python27</code> is in there and</p> <p>b) That <code>C:\python34</code> is <strong>not</strong> in there</p> <p>Also, after doing that, make sure you close all open cmd.exe dialogs befo...
0
2016-06-20T00:24:19Z
[ "python", "dll" ]
Installing vpython
37,912,071
<p>I have installed vpython on the anaconda IDE. However when I import it and use a simple command</p> <pre><code>import vpython as v v.sphere() </code></pre> <p>Nothing appears. How do I rectify this?</p>
0
2016-06-19T21:35:25Z
37,913,616
<p>Are you on RHEL or Ubuntu? You might want to try reinstalling and making sure that the installation is correct. You can install from <a href="http://vpython.org/contents/download_linux.html" rel="nofollow">http://vpython.org/contents/download_linux.html</a></p>
0
2016-06-20T01:43:07Z
[ "python", "vpython" ]
Regex match everything between special tag
37,912,135
<p>I have the following string that I need to parse and get the values of anything inside the defined <code>\$</code> tags</p> <p>for example, the string</p> <pre><code>The following math equation: \$f(x) = x^2\$ is the same as \$g(x) = x^(4/2) \$ </code></pre> <p>I want to parse whatever is in between the <code>\$<...
-1
2016-06-19T21:42:34Z
37,912,205
<p>You almost got it, just missing a backslash and a question mark (so it stops as soon as it finds the second <code>\$</code> and doesn't match the longest string possible): <code>r'\\\$(.*?)\\\$'</code></p> <pre><code>&gt;&gt;&gt; pattern = r'\\\$(.*?)\\\$' &gt;&gt;&gt; data = "The following math equation: \$f(x) = ...
1
2016-06-19T21:51:33Z
[ "python", "regex" ]
Regex match everything between special tag
37,912,135
<p>I have the following string that I need to parse and get the values of anything inside the defined <code>\$</code> tags</p> <p>for example, the string</p> <pre><code>The following math equation: \$f(x) = x^2\$ is the same as \$g(x) = x^(4/2) \$ </code></pre> <p>I want to parse whatever is in between the <code>\$<...
-1
2016-06-19T21:42:34Z
37,912,222
<p>This works:</p> <pre><code>import re regex = r'\\\$(.*)\\\$' r = re.compile(regex) print r.match("\$f(x) = x^2\$").group(1) print r.match("\$g(x) = x^(4/2) \$").group(1) </code></pre>
0
2016-06-19T21:53:02Z
[ "python", "regex" ]
Regex match everything between special tag
37,912,135
<p>I have the following string that I need to parse and get the values of anything inside the defined <code>\$</code> tags</p> <p>for example, the string</p> <pre><code>The following math equation: \$f(x) = x^2\$ is the same as \$g(x) = x^(4/2) \$ </code></pre> <p>I want to parse whatever is in between the <code>\$<...
-1
2016-06-19T21:42:34Z
37,912,246
<p>That regex can fit:</p> <pre><code>/\\\$.{0,}\\\$/g </code></pre> <p><code>/</code> - begin<br/> <code>\\\$</code> - escaped: \$<br/> <code>.</code> - any character between<br/> <code>{0,}</code> - at least 0 chars (any number of chars, actually)<br/> <code>\\\$</code> - escaped: \$<br/> <code>/</code> - end<br/> ...
1
2016-06-19T21:56:34Z
[ "python", "regex" ]
Most pythonic way of getting index of the last list item
37,912,206
<p>Given a list:</p> <pre><code>l1 = [0, 211, 576, 941, 1307, 1672, 2037] </code></pre> <p>What is the most pythonic way of getting the index of the last element of the list. Given that Python lists are zero-indexed, is it:</p> <pre><code>len(l1) - 1 </code></pre> <p>Or, is it the following which uses Python's list...
2
2016-06-19T21:51:42Z
37,912,232
<p>Only the first is correct:</p> <pre><code>&gt;&gt;&gt; lst = [1, 2, 3, 4, 1] &gt;&gt;&gt; len(lst) - 1 4 &gt;&gt;&gt; lst.index(lst[-1]) 0 </code></pre> <p>However it depends on what do you mean by "the index of the last element".</p> <p>Note that <code>index</code> must traverse the whole list in order to provid...
2
2016-06-19T21:54:49Z
[ "python" ]
Most pythonic way of getting index of the last list item
37,912,206
<p>Given a list:</p> <pre><code>l1 = [0, 211, 576, 941, 1307, 1672, 2037] </code></pre> <p>What is the most pythonic way of getting the index of the last element of the list. Given that Python lists are zero-indexed, is it:</p> <pre><code>len(l1) - 1 </code></pre> <p>Or, is it the following which uses Python's list...
2
2016-06-19T21:51:42Z
37,912,234
<p>You should use the first. Why?</p> <pre><code>&gt;&gt;&gt; l1 = [1,2,3,4,3] &gt;&gt;&gt; l1.index(l1[-1]) 2 </code></pre>
2
2016-06-19T21:54:57Z
[ "python" ]
Most pythonic way of getting index of the last list item
37,912,206
<p>Given a list:</p> <pre><code>l1 = [0, 211, 576, 941, 1307, 1672, 2037] </code></pre> <p>What is the most pythonic way of getting the index of the last element of the list. Given that Python lists are zero-indexed, is it:</p> <pre><code>len(l1) - 1 </code></pre> <p>Or, is it the following which uses Python's list...
2
2016-06-19T21:51:42Z
37,912,383
<p>Bakuriu's answer is great!</p> <p>In addition, it should be mentioned that you rarely need this value. There are usually other and better ways to do what you want to do. Consider this answer as a sidenote :)</p> <p>As you mention, getting the last element can be done this way:</p> <pre><code>lst = [1,2,4,2,3] pri...
0
2016-06-19T22:17:30Z
[ "python" ]
Disable descriptor object in Python
37,912,229
<p>Here is a simple example of <a href="https://docs.python.org/2/howto/descriptor.html" rel="nofollow">descriptor</a> usage in Python:</p> <pre><code>class MyDescriptor(object): def __get__(self, obj, objtype): return 42 class MyClass(object): d = MyDescriptor() print MyClass().d # 42 </code></pre> <p>But...
0
2016-06-19T21:54:25Z
37,912,340
<p>There are many ways to get what you want, depending on what exactly it is that you want.</p> <p>If all you want is to access the descriptor object (i.e., you don't care whether it is actually stored directly as an attribute on the class), then just store it in a list or something:</p> <pre><code>class Foo(object):...
1
2016-06-19T22:09:51Z
[ "python", "metaprogramming", "descriptor" ]
Disable descriptor object in Python
37,912,229
<p>Here is a simple example of <a href="https://docs.python.org/2/howto/descriptor.html" rel="nofollow">descriptor</a> usage in Python:</p> <pre><code>class MyDescriptor(object): def __get__(self, obj, objtype): return 42 class MyClass(object): d = MyDescriptor() print MyClass().d # 42 </code></pre> <p>But...
0
2016-06-19T21:54:25Z
37,912,358
<p>use <a href="https://docs.python.org/3/library/inspect.html?highlight=inspect#inspect.getattr_static" rel="nofollow"><code>inspect.getattr_static</code></a></p> <blockquote> <p>getattr_static() <strong>does not resolve descriptors</strong>, for example slot descriptors or getset descriptors on objects implement...
1
2016-06-19T22:12:34Z
[ "python", "metaprogramming", "descriptor" ]
Disable descriptor object in Python
37,912,229
<p>Here is a simple example of <a href="https://docs.python.org/2/howto/descriptor.html" rel="nofollow">descriptor</a> usage in Python:</p> <pre><code>class MyDescriptor(object): def __get__(self, obj, objtype): return 42 class MyClass(object): d = MyDescriptor() print MyClass().d # 42 </code></pre> <p>But...
0
2016-06-19T21:54:25Z
37,915,624
<p>The simpliest idea I have is to wrap this descriptor into another one. It would work since only one <code>__get__</code> would be called.</p> <pre><code>class TrivialDescriptor(object): def __init__(self, data): self._data = data def __get__(self, obj, objtype): return self._data class MyDescriptor(ob...
0
2016-06-20T06:11:14Z
[ "python", "metaprogramming", "descriptor" ]
Plotting graph using python and dispaying it using HTML
37,912,260
<p>I want build an offline application using plotly for displaying graphs . I am using python(flask) at the back end and HTML(javascript) for the front end . Currently I am able to plot the graph by sending the graph data as JSON object to front end and building the graph using plotly.js at the front end itself . But w...
0
2016-06-19T21:58:24Z
37,913,631
<p>My suggestion would be to use the <code>plotly.offline</code> module, which creates an offline version of a plot for you. The plotly API on their website is horrendous (we wouldn't actually want to know what arguments each function takes, would we??), so much better to turn to the source code on Github.</p> <p>If y...
1
2016-06-20T01:44:51Z
[ "python", "html", "plotly" ]
Finding Future Investment Value in Python
37,912,296
<p>I am a beginner programmer and have a question regarding the calculation of future investment values based on the following formula : futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate)numberOfMonths ... ofc the numberOfMonths value is an exponent. I have created this so far but seem to receive inc...
-1
2016-06-19T22:04:19Z
37,912,504
<p><code>annualInterestRate</code> should be divided by 12 to get <code>monthlyInterestRate</code>.</p> <p>The correct final formula should be</p> <pre><code>futureInvestmentValue = investmentAmount * (1 + (monthlyInterestRate/100) ** \ numberOfMonths </code></pre>
0
2016-06-19T22:33:47Z
[ "python" ]
Finding Future Investment Value in Python
37,912,296
<p>I am a beginner programmer and have a question regarding the calculation of future investment values based on the following formula : futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate)numberOfMonths ... ofc the numberOfMonths value is an exponent. I have created this so far but seem to receive inc...
-1
2016-06-19T22:04:19Z
37,912,567
<p>You can do it like this:</p> <pre><code>from __future__ import division # assuming python 2.7.xxxxx investmentAmount = float(input("Enter investment amount: ")) annualInterestRate = float(input("Enter annual interest rate: ")) monthlyInterestRate = ((annualInterestRate)/10)/12 try: numberOfYears = int(input(...
0
2016-06-19T22:43:04Z
[ "python" ]
Finding Future Investment Value in Python
37,912,296
<p>I am a beginner programmer and have a question regarding the calculation of future investment values based on the following formula : futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate)numberOfMonths ... ofc the numberOfMonths value is an exponent. I have created this so far but seem to receive inc...
-1
2016-06-19T22:04:19Z
37,912,616
<p>The errors are in:</p> <pre><code>monthlyInterestRate = ((annualInterestRate)/10)/12 futureInvestmentValue = investmentAmount * (1 + monthlyInterestRate) **\ numberOfMonths </code></pre> <p>There are two errors i think. The first is that the interest rate is being divided by 10 when it should ...
0
2016-06-19T22:50:12Z
[ "python" ]
django - AttributeError: 'NoneType' object has no attribute 'first_name'
37,912,297
<p>Would appreciate some help understanding whenever I try to setup my <code>client</code> I am getting the following error: <code>AttributeError: 'NoneType' object has no attribute 'first_name'</code>.</p> <p>Here is the log:</p> <pre><code>Environment: Request Method: GET Request URL: http://192.168.33.10:8000/po...
1
2016-06-19T22:04:22Z
37,912,342
<p>According to the documentation <a href="https://docs.djangoproject.com/en/1.9/ref/models/querysets/#django.db.models.query.QuerySet.first" rel="nofollow"><code>first()</code></a> would return <code>None</code> if there was nothing matched:</p> <blockquote> <p>Returns the first object matched by the queryset, or N...
1
2016-06-19T22:10:06Z
[ "python", "django", "django-models", "django-views", "django-class-based-views" ]
django - AttributeError: 'NoneType' object has no attribute 'first_name'
37,912,297
<p>Would appreciate some help understanding whenever I try to setup my <code>client</code> I am getting the following error: <code>AttributeError: 'NoneType' object has no attribute 'first_name'</code>.</p> <p>Here is the log:</p> <pre><code>Environment: Request Method: GET Request URL: http://192.168.33.10:8000/po...
1
2016-06-19T22:04:22Z
37,912,346
<p>The line were you check <code>if client is not None</code> should come immediately after reading from the database as <code>first</code> may return <code>None</code> if there are no items:</p> <pre><code>client = Client.objects.filter(user=user).first() if client is not None: initial_values['first_name'] = clie...
1
2016-06-19T22:11:02Z
[ "python", "django", "django-models", "django-views", "django-class-based-views" ]
How to read file of subprocess output
37,912,386
<p><br> In this code, subprocess.Popen creates /tmp/test.txt with <code>date</code> output. Why doesn't the 2nd "print lines" work ? I would appreciate for your help.</p> <pre><code>test]# touch /tmp/test.txt test]# ./x1.py /tmp/test.txt () /tmp/test.txt () test]# ./x1.py /tmp/test.txt ('Sun Jun 19 15:10:21 PDT 2016\n...
0
2016-06-19T22:18:03Z
37,912,733
<p>You need to <code>.wait()</code> for the <code>Popen</code> to finish before closing the stdout, otherwise you get undefined behaviour. </p> <pre><code>Popen("date", shell=True, stdout=file_).wait() # ^ add this part! </code></pre> <p>I can't say for sure how the file was wri...
2
2016-06-19T23:05:22Z
[ "python" ]
pandas subset and drop rows based on column value
37,912,487
<p>my df:</p> <pre><code>dframe = pd.DataFrame({"A":list("aaaabbbbccc"), "C":range(1,12)}, index=range(1,12)) Out[9]: A C 1 a 1 2 a 2 3 a 3 4 a 4 5 b 5 6 b 6 7 b 7 8 b 8 9 c 9 10 c 10 11 c 11 </code></pre> <p>to subset based on column value: </p> <pre><code>In[11]: fi...
0
2016-06-19T22:31:46Z
37,912,653
<p>It's not really in one shot, but typically the way to do this is reuse a boolean mask, like this:</p> <pre><code>In [28]: mask = dframe['A'] == 'a' In [29]: first, dframe = dframe[mask], dframe[~mask] In [30]: first Out[30]: A C 1 a 1 2 a 2 3 a 3 4 a 4 In [31]: dframe Out[31]: A C 5 b 5 6 ...
2
2016-06-19T22:54:35Z
[ "python", "pandas" ]
pandas subset and drop rows based on column value
37,912,487
<p>my df:</p> <pre><code>dframe = pd.DataFrame({"A":list("aaaabbbbccc"), "C":range(1,12)}, index=range(1,12)) Out[9]: A C 1 a 1 2 a 2 3 a 3 4 a 4 5 b 5 6 b 6 7 b 7 8 b 8 9 c 9 10 c 10 11 c 11 </code></pre> <p>to subset based on column value: </p> <pre><code>In[11]: fi...
0
2016-06-19T22:31:46Z
37,912,793
<p>You can also use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop.html" rel="nofollow">drop()</a></p> <pre><code>dframe = dframe.drop(dframe.index[dframe.A == 'a']) </code></pre> <p>Output:</p> <pre><code> A C 5 b 5 6 b 6 7 b 7 8 b 8 9 c 9 10 c 10 11...
0
2016-06-19T23:14:51Z
[ "python", "pandas" ]
pandas subset and drop rows based on column value
37,912,487
<p>my df:</p> <pre><code>dframe = pd.DataFrame({"A":list("aaaabbbbccc"), "C":range(1,12)}, index=range(1,12)) Out[9]: A C 1 a 1 2 a 2 3 a 3 4 a 4 5 b 5 6 b 6 7 b 7 8 b 8 9 c 9 10 c 10 11 c 11 </code></pre> <p>to subset based on column value: </p> <pre><code>In[11]: fi...
0
2016-06-19T22:31:46Z
37,913,109
<p>An alternate way to think about it.</p> <pre><code>gb = dframe.groupby(dframe.A == 'a') isa, nota = gb.get_group(True), gb.get_group(False) </code></pre>
0
2016-06-20T00:05:32Z
[ "python", "pandas" ]
Is auto-chunking enabled by default when GZIP compression is used in the HDF5 C++ api?
37,912,496
<p>I am writing an HDF5 file using the C++ HDF api and performing a few comparisons against the H5py Python library. </p> <p>In the H5py Python library <a href="https://www.safaribooksonline.com/library/view/python-and-hdf5/9781491944981/ch04.html" rel="nofollow">autochunking</a> is applied by default when a compressi...
2
2016-06-19T22:33:09Z
37,924,660
<p>According to <a href="https://www.hdfgroup.org/HDF5/faq/compression.html" rel="nofollow">https://www.hdfgroup.org/HDF5/faq/compression.html</a>:</p> <blockquote> <p>To apply a compression filter to a dataset it must be created with a chunked dataset storage layout.</p> </blockquote> <p>And you have to do it manu...
0
2016-06-20T14:07:48Z
[ "python", "c++", "hdf5", "h5py", "hdf" ]
Python NumbaPro GPU vectorization with Error : TypingError: Failed at nopython (nopython frontend)
37,912,517
<p>I am trying to use numbapro to run a basic simulation of object interactions. But I am getting this error and im not sure what the problem is. I am pretty new with trying to do GPU acceleration :( Here is my code:</p> <pre><code>from turtle import * import numpy as np from numbapro import vectorize setup( width...
0
2016-06-19T22:35:28Z
37,921,289
<p>There are a number of issues that I see just from inspecting your code:</p> <ul> <li><p>You can't use the <code>global</code> keyword in Numba the same way that you can in standard python. All global arrays called within a numba function become static at compile time (<a href="http://numba.pydata.org/numba-doc/0.26...
0
2016-06-20T11:23:54Z
[ "python", "numpy", "gpu", "numba" ]
Converting a log file into a csv file using Python
37,912,556
<p>I have the following problem at work - I need to take a log file with items arranged as follows:</p> <pre><code>A1 B1 C1 A2 B2 C2 . . . An Bn Cn </code></pre> <p>I need a complete csv file like so:</p> <pre><code>A1,B1,C1 A2,B2,C2 A3,B3,C3 ... An,Bn,Cn </code></pre> <p>How can I do this using a python script?</p...
-1
2016-06-19T22:40:30Z
37,912,623
<p>A simple solution using numpy:</p> <pre><code>import numpy as np data = np.genfromtxt("d.csv", dtype=str) data = np.reshape(data, (3,-1)) np.savetxt('data.csv', data, delimiter=',', fmt="%s") </code></pre> <p>Result:</p> <pre><code>A1,B1,C1 A2,B2,C2 An,Bn,Cn </code></pre> <p>If you are not using numpy, please p...
-1
2016-06-19T22:50:56Z
[ "python", "csv" ]
Converting a log file into a csv file using Python
37,912,556
<p>I have the following problem at work - I need to take a log file with items arranged as follows:</p> <pre><code>A1 B1 C1 A2 B2 C2 . . . An Bn Cn </code></pre> <p>I need a complete csv file like so:</p> <pre><code>A1,B1,C1 A2,B2,C2 A3,B3,C3 ... An,Bn,Cn </code></pre> <p>How can I do this using a python script?</p...
-1
2016-06-19T22:40:30Z
37,912,770
<pre><code>import csv with open('myfile.log') as file: lines = file.read().splitlines() lines = [lines[x:x+3] for x in range(0, len(lines), 3)] with open('yourcsv.csv', 'w+') as csvfile: w = csv.writer(csvfile) w.writerows(lines) </code></pre> <p>Note that the dots are still there and the...
1
2016-06-19T23:11:26Z
[ "python", "csv" ]
Bypass Software Wizard and Install with Default Parameters
37,912,561
<p>I would like to create a script which will download a piece of software, docker, and install it on my PC. I can do it by using dockers installation wizard, but I'm wondering how I can bypass the wizard and just install it. Is this possible?</p> <p>The wizard accepts a few commands such as selecting main and addit...
2
2016-06-19T22:41:20Z
37,912,726
<p>According to <a href="https://github.com/docker/toolbox/issues/322" rel="nofollow">issue #322</a> the installer was created with Inno Setup, so launching it with the <code>/silent</code> or <code>/verysilent</code> parameter should make it run non-interactively. Run the executable with the option <code>/?</code> or ...
1
2016-06-19T23:04:10Z
[ "python", "powershell", "docker", "wizard" ]
Connect mouseMoveEvent to widget by creating a subclass
37,912,598
<p>I have a QGraphicsView created in the QtDesigner. Now I want to connect a mouseMoveEvent to it. I understand that I must define a new class that inherits from QGraphicsView and in which mouseMoveEvent is overwritten. <a href="http://stackoverflow.com/questions/7524307/pyqt-signals-slots-with-qtdesigner">Here</a> is ...
1
2016-06-19T22:47:30Z
37,932,512
<p>I solved the problem by trial and error:</p> <p>Firstly (not the solution of the problem), myView must be replaced by the name of the newly defined class. And pyqtsignal and QMouseEvent must get the respective module names (both my fault):</p> <pre><code>from PyQt4 import QtCore, QtGui class floorplanViewClass(Qt...
0
2016-06-20T22:00:19Z
[ "python", "pyqt", "pyqt4" ]
Django -- Process Multiple Form Fields
37,912,611
<p>I am very new to Python / Django and would appreciate any and all help I can get here! </p> <p>I am trying to take in multiple form fields and haven't been able to find a great clean way to do so. My code is trying to take in a foreign Key radio selection (the team), and a number (the bet size), for each instance. ...
0
2016-06-19T22:49:39Z
37,914,417
<p>I think your manual approach is quite OK, and all you have to do is find a way to uniquely identify the Bet field for each game. You could to this in your html:</p> <pre><code>&lt;input type="number" name="{{game.pk}}-Bet"&gt; </code></pre> <p>And then get the value in your view just before creating your PlayerPic...
0
2016-06-20T03:54:33Z
[ "python", "django", "forms" ]
Splitting python list based on regular expression
37,912,620
<p>I have the following python list:</p> <pre><code>['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv', 'daman_and_diu_2000_aa.csv', 'daman_and_diu_2001_aa.csv', 'daman_and_diu_2002_aa.csv'] </code></pre> <p>How do I separate it into 2 lists:</p> <pre><code>['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv...
2
2016-06-19T22:50:49Z
37,912,801
<p>Here is one way to get a dictionary, where for each "name" key the value is a list of the strings starting with that name, keeping the order of the original list. This does not use regex and in fact uses no modules at all. You can easily modify this to make a function, remove the trailing underscore from each name, ...
4
2016-06-19T23:16:10Z
[ "python", "regex" ]
Splitting python list based on regular expression
37,912,620
<p>I have the following python list:</p> <pre><code>['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv', 'daman_and_diu_2000_aa.csv', 'daman_and_diu_2001_aa.csv', 'daman_and_diu_2002_aa.csv'] </code></pre> <p>How do I separate it into 2 lists:</p> <pre><code>['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv...
2
2016-06-19T22:50:49Z
37,912,804
<p>You can use <code>itertools.groupby</code> here:</p> <pre><code>import itertools import re list = ['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv', 'daman_and_diu_2000_aa.csv', 'daman_and_diu_2001_aa.csv', 'daman_and_diu_2002_aa.csv'] grouped = itertools.groupby(sorted(list), lambda x: re.m...
4
2016-06-19T23:16:44Z
[ "python", "regex" ]
Splitting python list based on regular expression
37,912,620
<p>I have the following python list:</p> <pre><code>['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv', 'daman_and_diu_2000_aa.csv', 'daman_and_diu_2001_aa.csv', 'daman_and_diu_2002_aa.csv'] </code></pre> <p>How do I separate it into 2 lists:</p> <pre><code>['chhattisgarh_2015_aa.csv', 'chhattisgarh_2016_aa.csv...
2
2016-06-19T22:50:49Z
37,912,824
<p>Another option to use regular expression combined with dictionary:</p> <pre><code>files = ["chhattisgarh_2015_aa.csv", "chhattisgarh_2016_aa.csv", "daman_and_diu_2000_aa.csv", "daman_and_diu_2001_aa.csv", "daman_and_diu_2002_aa.csv"] import re from collections import defaultdict groupedFiles = defaultdict(list) f...
2
2016-06-19T23:20:42Z
[ "python", "regex" ]
subprocess of sudo, accessing /dev/sda : strange error: [Errno 2] No such file or directory
37,912,718
<p>I'm trying to read smart (by nagios user) with this script: <a href="https://gist.github.com/mastbaum/10663894#file-smart_watch-py" rel="nofollow">https://gist.github.com/mastbaum/10663894#file-smart_watch-py</a></p> <p>I did enable nagios to execute that file (/etc/sudoers):</p> <pre><code>nagios ALL= NOPASSWD: ...
0
2016-06-19T23:02:56Z
37,912,797
<p>Found it </p> <p>command was not finding smartclt, changed to: /usr/sbin/smartctl</p>
2
2016-06-19T23:15:26Z
[ "python", "subprocess", "sudo" ]
Python regex match numbers or nothing
37,912,762
<p>I have strings:</p> <p>1st one</p> <pre><code>\-1,1\N,0.0464128206,0.1106913625,-0.0261445305\ </code></pre> <p>2nd one</p> <pre><code>\-1,1\N,0.,0.,0.\ </code></pre> <p>It can be done manually to the </p> <pre><code> \-1,1\N,0.0,0.0,0.0\ </code></pre> <p>but I am trying to make script working without any edi...
0
2016-06-19T23:10:10Z
37,913,007
<p>Change the part after the <code>.</code> from <code>\d+</code> to <code>\d*</code>, like this:</p> <pre><code>\d,\d\\[A-Z],[-]?\d+\.\d*,[-]?\d+\.\d*,[-]?\d+\.\d* </code></pre> <p>The interpretation of <code>\d+\.\d*</code> being:</p> <p><strong>at least one digit then exactly one dot then zero or one or several d...
1
2016-06-19T23:51:23Z
[ "python", "regex", "python-2.7", "match" ]
Python: Finding a substring within a string from a list, but saving the substring
37,912,795
<p>Basically, I have a list of substrings I am searching a string for. I'm using any() currently and doing some work if one of the words are found in the string. I want to start logging the matches to keep some stats on the matches. I am using any() right now. </p> <p>Is there a way to do the same thing as any, but st...
1
2016-06-19T23:14:54Z
37,912,840
<p>For this sort of thing, you could use the <code>re</code> module.</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; m = re.search(r"substring1, substring2, substring3", string) </code></pre> <p><code>string</code> would be the string you're searching through, and <code>m</code> would be the variable that contains...
0
2016-06-19T23:22:50Z
[ "python", "string", "list", "substring", "any" ]
Python: Finding a substring within a string from a list, but saving the substring
37,912,795
<p>Basically, I have a list of substrings I am searching a string for. I'm using any() currently and doing some work if one of the words are found in the string. I want to start logging the matches to keep some stats on the matches. I am using any() right now. </p> <p>Is there a way to do the same thing as any, but st...
1
2016-06-19T23:14:54Z
37,912,893
<p>There are multiple ways to do this. Regular expressions (As FreddieV4 suggested) are very powerful.</p> <p>However another simple approach is using a list comprehension like:</p> <pre><code>matches = [x for x in string.split() if x in substrings] </code></pre> <p>Which will loop over the the words in the string a...
1
2016-06-19T23:30:25Z
[ "python", "string", "list", "substring", "any" ]
Python: Finding a substring within a string from a list, but saving the substring
37,912,795
<p>Basically, I have a list of substrings I am searching a string for. I'm using any() currently and doing some work if one of the words are found in the string. I want to start logging the matches to keep some stats on the matches. I am using any() right now. </p> <p>Is there a way to do the same thing as any, but st...
1
2016-06-19T23:14:54Z
37,913,858
<p>Let's look at this example: </p> <pre><code>s = "Thisisarandomstringthatiwanttotype" subst = ["This", "random", "hullo", "type"] </code></pre> <p>To return all the substrings that match:</p> <pre><code>filter(lambda x: x in s, subs) &gt;&gt; ['This', 'random', 'type'] </code></pre> <p>To return the starting ind...
0
2016-06-20T02:26:14Z
[ "python", "string", "list", "substring", "any" ]
Start a subprocess, wait for it to complete and then retrieve data in Python
37,912,862
<p>I'm struggling to get some python script to start a subprocess, wait until it completes and then retrieve the required data. I'm quite new to Python.</p> <p>The command I wish to run as a subprocess is</p> <pre><code> ./bin.testing/Eva -t --suite="temp0" </code></pre> <p>Running that command by hand in the Lin...
2
2016-06-19T23:26:27Z
37,912,987
<p>Since the 2nd line is an <em>error message</em>, it's probably stored in your <code>stderr</code> variable!</p> <p>To know for sure you can print your <code>stderr</code> in your code, or you can run the program on the command line and see if the output is split into <code>stdout</code> and <code>stderr</code>. On...
2
2016-06-19T23:47:25Z
[ "python", "linux", "subprocess" ]
Start a subprocess, wait for it to complete and then retrieve data in Python
37,912,862
<p>I'm struggling to get some python script to start a subprocess, wait until it completes and then retrieve the required data. I'm quite new to Python.</p> <p>The command I wish to run as a subprocess is</p> <pre><code> ./bin.testing/Eva -t --suite="temp0" </code></pre> <p>Running that command by hand in the Lin...
2
2016-06-19T23:26:27Z
37,913,394
<p>Try using subprocess check_output.</p> <pre><code>output_lines = subprocess.check_output(['./bin.testing/Eva', '-t', '--suite="temp0"']) for line in output_lines.splitlines(): print(line) </code></pre>
0
2016-06-20T00:59:13Z
[ "python", "linux", "subprocess" ]
Renaming a single file in python
37,912,867
<p>I'm trying to rename an audio file but I keep getting <code>OSError: [Errno 2] No such file or directory</code>. </p> <p>In my program, each user has a directory that holds the users files. I obtain the path for each user by doing the following:</p> <pre><code>current_user_path = os.path.join(current_app.config['...
1
2016-06-19T23:27:08Z
37,913,031
<p>If the OS says there's no such file or directory, that's the gospel truth. You're making a lot of assumptions about where the file is, constructing a path to it, and renaming it. It's a safe bet there's no such file as the one named by <code>current_file_path</code>, or no directory to <code>new_file_path</code>. ...
1
2016-06-19T23:53:57Z
[ "python" ]
Renaming a single file in python
37,912,867
<p>I'm trying to rename an audio file but I keep getting <code>OSError: [Errno 2] No such file or directory</code>. </p> <p>In my program, each user has a directory that holds the users files. I obtain the path for each user by doing the following:</p> <pre><code>current_user_path = os.path.join(current_app.config['...
1
2016-06-19T23:27:08Z
37,913,348
<p>you can use <a href="https://docs.python.org/2/library/os.html" rel="nofollow">os.rename</a> for rename single file.</p> <p>to avoid</p> <pre><code>OSError: [Errno 2] No such file or directory. </code></pre> <p>check if file exist or not.</p> <p>here is the working example:</p> <pre><code>import os src = "D:/t...
0
2016-06-20T00:51:06Z
[ "python" ]
Python Plotly library for networks: how to color nodes with different colors
37,912,881
<p>The Python Plotly library enables to <a href="https://plot.ly/ipython-notebooks/networks/" rel="nofollow">plot graphs or networks</a>.</p> <p>The following code (from this <a href="https://plot.ly/ipython-notebooks/networks/" rel="nofollow">link</a>) is a function that returns a dictionary with different attributes...
0
2016-06-19T23:28:33Z
37,921,238
<p>Simple answer: just need to define <code>color</code> as a list of colors which are automatically indexed with the nodes.</p>
0
2016-06-20T11:21:13Z
[ "python", "plotly" ]
Fill the outside of contours OpenCV
37,912,928
<p>I am trying to color in black the outside region of a contours using openCV and python language. Here is my code :</p> <pre><code>contours, hierarchy = cv2.findContours(copy.deepcopy(img_copy),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) areas = [cv2.contourArea(c) for c in contours] max_index = np.argmax(areas) cnt=cont...
1
2016-06-19T23:35:37Z
37,914,138
<p>Here's how you can fill an image with black color outside of a set of contours:</p> <pre><code>import cv2 import numpy img = cv2.imread("zebra.jpg") stencil = numpy.zeros(img.shape).astype(img.dtype) contours = [numpy.array([[100, 180], [200, 280], [200, 180]]), numpy.array([[280, 70], [12, 20], [80, 150]])] color ...
1
2016-06-20T03:12:55Z
[ "python", "image", "python-2.7", "opencv", "opencv-contour" ]
Plotting a wire frame sphere using MatPlotLib
37,912,973
<p>Using MatPlotLib, I want to draw a sphere by plotting a set of spherical coordinates. I have got halfway there, but I cannot quite achieve what I want exactly.</p> <p>So far, the following code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d.axes3d as axes3d theta, p...
0
2016-06-19T23:43:42Z
37,913,124
<ol> <li><p>Set <code>shade=False</code>, but also set <code>linewidth</code> to anything other than 0 (e.g. <code>linewidth=1</code>). <em>(Alternatively, use <a href="http://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html#mpl_toolkits.mplot3d.Axes3D.plot_wireframe" rel="nofollow"><code>ax.plot_wireframe()</code></a...
1
2016-06-20T00:08:13Z
[ "python", "matplotlib" ]
Django Celery Persistent revoke
37,913,013
<p>So I have a project in Django that uses Celery and sometimes I am revoking tasks.</p> <p>Celery has the ability to persist revokes even if the worker is restarted (<a href="http://docs.celeryproject.org/en/latest/userguide/workers.html#worker-persistent-revokes" rel="nofollow">http://docs.celeryproject.org/en/lates...
0
2016-06-19T23:52:08Z
37,915,850
<p>So I worked it out in the end.</p> <p>By adding this to settings.py it started working:</p> <pre><code>CELERYD_STATE_DB = "celery_state.db" </code></pre>
0
2016-06-20T06:29:02Z
[ "python", "django", "celery", "django-celery", "celery-task" ]
Django Python manage.py migrate doesnt work
37,913,141
<p>I'm having trouble with installing django. This is what I got. I only installed python and django. didnt change any files, there is an error that come out</p> <pre><code>(myvenv) C:\Users\admin\Desktop\smat&gt;manage.py migrate Traceback (most recent call last): File "C:\Users\admin\Desktop\smat\manage.py", line ...
-2
2016-06-20T00:12:19Z
37,913,312
<p>The error says your <code>STATIC_URL</code> value doesn't end with a slash. Checking your settings.py file and make sure it has a slash at the end of the value - a forward slash.</p> <pre><code>STATIC_URL = '/static/' </code></pre>
1
2016-06-20T00:43:43Z
[ "python", "django", "installation" ]
Django Python manage.py migrate doesnt work
37,913,141
<p>I'm having trouble with installing django. This is what I got. I only installed python and django. didnt change any files, there is an error that come out</p> <pre><code>(myvenv) C:\Users\admin\Desktop\smat&gt;manage.py migrate Traceback (most recent call last): File "C:\Users\admin\Desktop\smat\manage.py", line ...
-2
2016-06-20T00:12:19Z
37,916,042
<pre><code>STATIC_URL = '/static/' STATIC_ROOT = os.path.join(BASE_DIR, "static") </code></pre> <p>This is exact copy of <code>static</code> in <code>settings.py</code></p>
0
2016-06-20T06:40:19Z
[ "python", "django", "installation" ]
xlswrite: Showing variable name in sheet name or somewhere
37,913,171
<ol> <li>I am using xlswrite.</li> </ol> <p>I am putting lots of variables into different sheets of one xlsx file. </p> <p>One variable for one sheet. </p> <p>So I want to put the name of the variable as the name of the sheet.</p> <p>I couldn't find any command which does this. So perhaps this should be done by cod...
0
2016-06-20T00:17:20Z
37,913,741
<p>The reason for your issue is that you're attempting to vertically concatenate a string that is <code>1 x 1</code> with data that is <code>2 x 2</code> so you obviously are going to have a dimension mis-match.</p> <p>If you want to specify the sheet name, then simply use the <a href="http://www.mathworks.com/help/ma...
1
2016-06-20T02:05:05Z
[ "python", "matlab" ]
Why am I getting errors relating to strip() when I'm not using it? (Python)
37,913,192
<p>I'm working through a scraping task in Python using BeautifulSoup and am getting some strange errors. It's mentioning strip, which I'm not using, but I'm guessing might be related to the processes of BSoup? </p> <p>In the task I'm trying to go to the original url, find the 18th link, click that link 7 times, and ...
1
2016-06-20T00:20:12Z
37,913,334
<p><code>re.findall()</code> returns <em>a list of matches</em>. <code>urlToUse</code> is a list and you are trying to pass it to <code>urlopen()</code> which expects a URL string instead.</p>
3
2016-06-20T00:47:40Z
[ "python", "web-scraping", "beautifulsoup" ]
Why am I getting errors relating to strip() when I'm not using it? (Python)
37,913,192
<p>I'm working through a scraping task in Python using BeautifulSoup and am getting some strange errors. It's mentioning strip, which I'm not using, but I'm guessing might be related to the processes of BSoup? </p> <p>In the task I'm trying to go to the original url, find the 18th link, click that link 7 times, and ...
1
2016-06-20T00:20:12Z
37,918,423
<p><em>Alexce</em> has explained your error but you don't need a regex at all, you just want to get the 18th li tag and extract the href from the anchor tag inside that, you can use <em>find</em> with <em>find_all</em>:</p> <pre><code>from bs4 import BeautifulSoup import requests soup = BeautifulSoup(requests.get("ht...
2
2016-06-20T09:01:53Z
[ "python", "web-scraping", "beautifulsoup" ]
Python: translating the program
37,913,202
<p>Given a string with codon letters I can´t figure what the following program is explicitly doing. I know that it goes through the whole string but what is it doing exactly ? </p> <pre><code>s = "AVGGGKGDEMAWTWVRPMGVIDWEEGGVKLVAGLLP" [i for i in range(1,len(s)) if s[i] in 'VE' and s[i-1]!= 'W'] ? </code></pre> <...
-1
2016-06-20T00:21:12Z
37,913,243
<p>This list comprehension goes through string <code>s</code> one index at a time and checks 2 conditions:</p> <ul> <li>Is the character at index <code>i</code> in the string <code>'VE'</code>?</li> <li>Is the character before the character at index <code>i</code> not equal to <code>'W'</code>?</li> </ul> <p>If both ...
1
2016-06-20T00:28:51Z
[ "python", "string" ]
Python concat pairs of tuples in a list
37,913,231
<p><strong>I have a list of tuples that looks like this:</strong></p> <pre><code>l1 = [('X', 123, 456, 'a'), ('Y', 123, 456, 'b'), ('X', 123, 456, 'c'), ('Y', 123, 456, 'd')] </code></pre> <p>for each tuple, the first item alternates between 'X' and 'Y' only. The second and third item in the index are constants and ...
0
2016-06-20T00:27:04Z
37,913,397
<p>Here's a solution. Essentially you need to step through the list in "twos", and then recompose the new list.</p> <pre><code>l1 = [('X', 123, 456, 'a'), ('Y', 123, 456, 'b'), ('X', 123, 456, 'c'), ('Y', 123, 456, 'd')] l2 = [] for i in range(0, len(l1), 2): x = l1[i] y = l1[i+1] assert x[0] == 'X' ...
0
2016-06-20T00:59:48Z
[ "python", "mysql", "list", "tuples" ]
Python concat pairs of tuples in a list
37,913,231
<p><strong>I have a list of tuples that looks like this:</strong></p> <pre><code>l1 = [('X', 123, 456, 'a'), ('Y', 123, 456, 'b'), ('X', 123, 456, 'c'), ('Y', 123, 456, 'd')] </code></pre> <p>for each tuple, the first item alternates between 'X' and 'Y' only. The second and third item in the index are constants and ...
0
2016-06-20T00:27:04Z
37,913,544
<p>You can do it like this </p> <pre><code> l1 = [('X', 123, 456, 'a'), ('Y', 123, 456, 'b'), ('X', 123, 456, 'c'), ('Y', 123, 456, 'd')] l1 = tuple((x[1],x[2],x[3],l1[i+1][3]) for x,i in zip(l1,range(0,len(l1)-1))) l2 = (l1[0],l1[2]) #resulting tuple print l2 </code></pre>
0
2016-06-20T01:30:28Z
[ "python", "mysql", "list", "tuples" ]
Python concat pairs of tuples in a list
37,913,231
<p><strong>I have a list of tuples that looks like this:</strong></p> <pre><code>l1 = [('X', 123, 456, 'a'), ('Y', 123, 456, 'b'), ('X', 123, 456, 'c'), ('Y', 123, 456, 'd')] </code></pre> <p>for each tuple, the first item alternates between 'X' and 'Y' only. The second and third item in the index are constants and ...
0
2016-06-20T00:27:04Z
37,913,882
<pre class="lang-py prettyprint-override"><code>result = [l1[i][1: ] + (l1[i + 1][3], ) for i in xrange(0, len(l1), 2)] </code></pre>
0
2016-06-20T02:30:19Z
[ "python", "mysql", "list", "tuples" ]
Python MySQLdb TypeError("not all arguments converted during string formatting")
37,913,262
<p>I know this is a popular topic but I searched the various answers and didn't see a clear answer to my issue. I have a function that I want to use to insert records into my NDBC database that is giving me the error I mentioned in the title. The function is below:</p> <pre><code>def insertStdMet(station,cursor,data...
0
2016-06-20T00:34:16Z
37,913,421
<p>You haven't given your SQL query a value for either <code>station_id</code> or <code>date_time</code>, so when it goes to unpack your arguments, there are two missing.</p> <p>I suspect you want the final call to be something like:</p> <pre><code>REPLACE INTO std_met (station_id,date_time,WDIR,WSPD,GST,WVHT,DPD,AP...
0
2016-06-20T01:04:50Z
[ "python", "python-3.x", "mysql-python" ]
Decrementing Function Arguments (PYTHON)
37,913,269
<p>I'm calling functions similar to those that follow, inside a loop:</p> <pre><code> def bigAnim(tick,firstRun): smallAnim(x,y,duration) #more anims and logic... def smallAnim(x, y,duration): duration -= 1 if duration != 0: Anim.blit(screen,(x ,y)) Ani...
0
2016-06-20T00:35:16Z
37,913,336
<p>You need to do the counting in <code>bigAnim</code> and only call <code>smallAnim()</code> when the value is greater than zero.</p> <p>Or you can return the current duration:</p> <pre><code>def bigAnim(tick,firstRun): duration = smallAnim(x,y,duration) #more anims and logic... def smallAnim(x, y, duration...
1
2016-06-20T00:48:28Z
[ "python", "function", "pygame", "arguments" ]
Exception: "can't multiply sequence by non-int of type 'float'
37,913,337
<p>I'm trying to write very simple code to calculate the discount on a article. Following is the code and it throws the exception on the 3rd line in the code. The exception is:</p> <pre><code>Traceback (most recent call last): File "C:/Users/basam/AppData/Local/Programs/Python/Python35/discounts.py", line 3, in &lt;...
2
2016-06-20T00:48:31Z
37,913,349
<p>As @Silvio Mayolo has stated, the problem is that your price variable is of type String. You can wrap your input() call to cast the input value to an integer which should allow for the calculation to work</p> <pre><code>price = int(input('how much is your item?')) if price &lt;= 10: discount = 0.1 * price prin...
2
2016-06-20T00:51:07Z
[ "python", "python-3.x" ]
Exception: "can't multiply sequence by non-int of type 'float'
37,913,337
<p>I'm trying to write very simple code to calculate the discount on a article. Following is the code and it throws the exception on the 3rd line in the code. The exception is:</p> <pre><code>Traceback (most recent call last): File "C:/Users/basam/AppData/Local/Programs/Python/Python35/discounts.py", line 3, in &lt;...
2
2016-06-20T00:48:31Z
37,913,355
<p>Change to <code>discount=0.1*float(price)</code> </p>
-1
2016-06-20T00:51:53Z
[ "python", "python-3.x" ]
Exception: "can't multiply sequence by non-int of type 'float'
37,913,337
<p>I'm trying to write very simple code to calculate the discount on a article. Following is the code and it throws the exception on the 3rd line in the code. The exception is:</p> <pre><code>Traceback (most recent call last): File "C:/Users/basam/AppData/Local/Programs/Python/Python35/discounts.py", line 3, in &lt;...
2
2016-06-20T00:48:31Z
37,913,359
<p>The key is <code>int(price)</code>. The <code>input</code> command returns a string which is stored in the variable <code>price</code>.</p> <p>In the second line, <code>price</code> is converted to a number by the call <code>int(price)</code>, but that result is not stored anywhere. It is used for the comparison an...
5
2016-06-20T00:52:16Z
[ "python", "python-3.x" ]
Having trouble with Tryton/GNU Health installation
37,913,396
<p>I have installed Tryton server and client as instructed on the GNU Health website. The server is running fine. The pre-requisites required - Postgresql, Python had been installed before hand. I have created a GNU Health user but whenever I attempt creating a database in postgres, i get the error shown in the termina...
0
2016-06-20T00:59:30Z
37,921,728
<p>AFAIU you have to specify a username and password to let PostgreSQL trust your connection. Also take care that you are allowing anyone to conect to your server with any login. This may be a security issue.</p> <p>Using the following URI works for me:</p> <blockquote> <p>postgresql://username:sometext@localhost:5...
0
2016-06-20T11:46:10Z
[ "python", "postgresql", "tryton" ]