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
To print http status code in Python 3 (urllib)
37,779,795
<p>I'm trying to get http status codes including 3XX, but from my code I'm not able to print it. </p> <p>Here is the code:</p> <pre><code>import urllib import urllib.request import urllib.error urls = ['http://hotdot.pro/en/404/', 'http://www.google.com', 'http://www.yandex.ru', 'http://www.python.org', 'http://www....
0
2016-06-12T22:43:38Z
37,780,010
<p>Not all errors of class <code>URLError</code> will have a <code>code</code>, some will only have a <code>reason</code>. </p> <p>Besides, <em>catching</em> <code>URLError</code> and <code>HTTPError</code> in the same <code>except</code> block is not a good idea (see <a href="https://docs.python.org/3.0/howto/urllib2...
1
2016-06-12T23:12:59Z
[ "python", "windows", "visual-studio", "python-3.x", "urllib" ]
How to use structure arrays in python?
37,779,796
<p>I´m writing this question because I´m not sure with the use of "structure arrays". I did a matrix from keyboard with different inputs (integer, float, etc.) using the "dtype" command. Then, I want find repeated elements in the column "p" and "q", when I have these elements, I want to sum the respective elements fr...
-2
2016-06-12T22:43:40Z
37,780,723
<p>Let me suggest some changes:</p> <pre><code>import numpy as np # not * .... numero_lines=int(number_lines_) ... # don't use numpy function names as variable names # even the np import dt=np.dtype([('p',int),('q',int),('r',float),('x',float),('b',complex),('z',complex),('y',complex)]) ... yinfo=np.zeros((numero_lin...
0
2016-06-13T01:26:36Z
[ "python", "arrays", "numpy" ]
Efficiently query missing integers in a range on a field?
37,779,798
<p>I have a database for a backup service I'm writing <a href="https://github.com/csaftoiu/yahoo-groups-backup" rel="nofollow">to backup Yahoo! Groups</a>. It incrementally retrieves messages, which have a contiguous numeric id. stored in a <code>'message_id'</code> field. So, if the last message on the service is mess...
0
2016-06-12T22:44:19Z
37,780,117
<p>in SQL word one could use CTE for that, in mongo we can use aggregation with <code>$lookup</code> as a kind of CTE (common table expressions)</p> <p>having this data structure</p> <pre><code>{ "_id" : ObjectId("575deea531dcfb59af388e17"), "mesId" : 4.0 }, { "_id" : ObjectId("575deea531dcfb59af388e18"),...
0
2016-06-12T23:32:24Z
[ "python", "database", "mongodb", "performance" ]
Pygame compile() expected string without null bytes
37,779,821
<p>So I'm new to pygame and I'm trying to compile the simplest program I can think of, to open a window. However, I tried two different compiling methods I found on the internet and both of them give me this:</p> <pre><code>error: compiling 'C:\Python27\lib\email\parser.py' failed TypeError: compile() expected string ...
0
2016-06-12T22:48:09Z
37,780,507
<p>welcome to stackoverflow. You had made a slight typo in your code in the DISPLAYSURF. Instead of </p> <pre><code>DISPLAYSURF = pygame.display.set_mode((400,300)) </code></pre> <p>You have to add brackets around 400 and 300 to make it a tuple.</p> <pre><code>DISPLAYSURF = pygame.display.set_mode([400,300]) </code>...
0
2016-06-13T00:48:17Z
[ "python", "compiler-errors", "pygame" ]
Pygame compile() expected string without null bytes
37,779,821
<p>So I'm new to pygame and I'm trying to compile the simplest program I can think of, to open a window. However, I tried two different compiling methods I found on the internet and both of them give me this:</p> <pre><code>error: compiling 'C:\Python27\lib\email\parser.py' failed TypeError: compile() expected string ...
0
2016-06-12T22:48:09Z
37,783,212
<p>Or you can assign the values of screen size and width before.<br> Like,</p> <pre><code>display_width = 1080 display_height = 720 gameDisplay = pygame.display.set_mode((display_width,display_height)) </code></pre> <p>This will work perfectly.</p>
0
2016-06-13T06:38:36Z
[ "python", "compiler-errors", "pygame" ]
How to develop a calendar GUI in Python?
37,779,845
<p>here's the code I currently have... My class barely introduced Tkinter and the book we're using doesn't help with understanding how to use the Calendar library. The labels Mon/Tu/Wed/Etc work, but the calendar isn't showing. </p> <p>Images: <a href="http://i.stack.imgur.com/vbMYM.jpg" rel="nofollow">problem</a> <a ...
0
2016-06-12T22:50:57Z
37,779,961
<p>First, you should consider creating, at the end, the mainloop:</p> <pre><code>root = tk() app = Application(root) root.mainloop() </code></pre> <p>It should work fine now.</p>
0
2016-06-12T23:06:15Z
[ "python", "python-3.x", "user-interface", "tkinter", "calendar" ]
ImportError when importing scitools
37,779,873
<p>I am using python 3.4, and every time I use <code>scitools</code>, I get this error:</p> <pre><code> File "&lt;stdin&gt;", line 1, in &lt;module&gt; ImportError: No module named 'scitools' </code></pre>
-2
2016-06-12T22:53:54Z
37,793,431
<p>Try using pip to install it. Pip will automatically install</p>
-1
2016-06-13T15:17:53Z
[ "python", "python-3.4", "scitools" ]
Loop Through a Random List Generator
37,779,880
<p>This code I'm using is part of something bigger on I'm writing. In this part I create a random list of smaller size from a source list. Is there a way to loop over this random list creator x times and then save the new lists (e.g. <code>list1</code>, <code>list2</code>, <code>list3</code>, ..., <code>listx</code>)?<...
0
2016-06-12T22:54:36Z
37,779,917
<p>You can create a list of lists by extending your code a bit. This will create a list containing <code>list_count</code> lists, each containing random elements from <code>positive</code>. </p> <pre><code>list_count = 5 positive_classifier = [ [positive[i] for i in sorted(random.sample(xrange(len(positive)), n_pr...
0
2016-06-12T23:00:31Z
[ "python", "list", "loops", "random" ]
Cannot find element from a jump out window. How can I switch to a new jump out window?
37,779,884
<p>I'm trying to automate our system with Python2.7, Selenium-webdriver, and Sikuli. I have a problem on login. Every time I open our system, the first page is an empty page, and it will jump to another page automatically; the new page is the main login page, so Python is always trying to find the element from the firs...
-1
2016-06-12T22:54:52Z
37,781,678
<p>First of all, I can't see any Sikuli usage in your example. If you were using Sikuli, it wouldn't matter how the other page was launched as you'd be interacting with whatever is visible on your screen at that time. </p> <p>In Selenium, if you have multiple windows you have to switch your driver to the correct one. ...
0
2016-06-13T04:07:22Z
[ "python", "python-2.7", "selenium-webdriver", "sikuli" ]
How to change the values of multiple indexes?
37,779,919
<pre><code>worldArray = [["." for i in range(5)] for i in range(5)] </code></pre> <p>This produces a map that I can use for my game. It should look something like:</p> <pre><code>[['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]...
1
2016-06-12T23:00:56Z
37,780,029
<p>You could write a helper function</p> <pre><code>def replace_at_position(world_array, row_col_dict, repl_char): """ Use row_col_dict in format of {row : (startOfRange, endOfRange)} to replace the characters inside the specific range at the specific row with repl_char """ for row in row_col_dict...
1
2016-06-12T23:15:10Z
[ "python", "arrays" ]
How to change the values of multiple indexes?
37,779,919
<pre><code>worldArray = [["." for i in range(5)] for i in range(5)] </code></pre> <p>This produces a map that I can use for my game. It should look something like:</p> <pre><code>[['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]...
1
2016-06-12T23:00:56Z
37,780,043
<p>I would define a function that returns whether or not to make it <code>~</code> instead of <code>.</code>.</p> <pre><code>""" Determines if the game position is regular or not """ def isRegular(x,y): # Only replace Row 4 column 1 and 2 with ~ return not (x==4 and y in [1,2]) worldArray = [["." if isRegular...
0
2016-06-12T23:18:59Z
[ "python", "arrays" ]
How to change the values of multiple indexes?
37,779,919
<pre><code>worldArray = [["." for i in range(5)] for i in range(5)] </code></pre> <p>This produces a map that I can use for my game. It should look something like:</p> <pre><code>[['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]...
1
2016-06-12T23:00:56Z
37,780,115
<p>Slice notation is perfect for this:</p> <pre><code>from functools import partial def tile(icon, row, col_start, col_end): worldArray[row][col_start:col_end] = icon * (col_end - col_start) water = partial(tile, '~') mountain = partial(tile, '^') water(3, 0, 2) water(4, 0, 3) </code></pre>
3
2016-06-12T23:32:20Z
[ "python", "arrays" ]
How to change the values of multiple indexes?
37,779,919
<pre><code>worldArray = [["." for i in range(5)] for i in range(5)] </code></pre> <p>This produces a map that I can use for my game. It should look something like:</p> <pre><code>[['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.'], ['.', '.', '.', '.', '.']]...
1
2016-06-12T23:00:56Z
37,780,255
<p>Based on your question I threw together a simple function you can run. Feel free to copy and paste it into the IDLE console:</p> <pre><code>&gt;&gt;&gt; def a(): global worldArray b = 1 while b &lt; 2: c = (int(input('Row #: ')),int(input('Column-Leftbound: ')),int(input('Column-Rightbound: '))) worldArray[...
0
2016-06-12T23:55:37Z
[ "python", "arrays" ]
Explanation on Numpy Broadcasting Answer
37,780,057
<p>I recently posted a question <a href="http://stackoverflow.com/questions/37737368/python-list-of-lists-vs-numpy/">here</a> which was answered exactly as I asked. However, I think I overestimated my ability to manipulate the answer further. I read the broadcasting doc, and followed a few links that led me way back to...
3
2016-06-12T23:21:27Z
37,780,408
<p>You can adjust your current code just a little bit to make it work.</p> <pre><code>&gt;&gt;&gt; out = np.zeros((4*5*10,4)) &gt;&gt;&gt; out[:,:3] = (np.arange(4*5*10)[:,None]//(5*10, 10, 1)*(0.5, 0.2, 1)%(2, 1, 10)) &gt;&gt;&gt; out array([[ 0. , 0. , 0. , 0. ], [ 0. , 0. , 1. , 0. ], [ 0. , 0....
4
2016-06-13T00:26:41Z
[ "python", "arrays", "numpy", "numpy-broadcasting" ]
Explanation on Numpy Broadcasting Answer
37,780,057
<p>I recently posted a question <a href="http://stackoverflow.com/questions/37737368/python-list-of-lists-vs-numpy/">here</a> which was answered exactly as I asked. However, I think I overestimated my ability to manipulate the answer further. I read the broadcasting doc, and followed a few links that led me way back to...
3
2016-06-12T23:21:27Z
37,780,768
<p>This small example helps me understand what is going on:</p> <pre><code>In [123]: N=2 In [124]: np.arange(N**3)[:,None]/[N**2, N, 1] Out[124]: array([[ 0. , 0. , 0. ], [ 0.25, 0.5 , 1. ], [ 0.5 , 1. , 2. ], [ 0.75, 1.5 , 3. ], [ 1. , 2. , 4. ], [ 1.25, 2....
3
2016-06-13T01:35:17Z
[ "python", "arrays", "numpy", "numpy-broadcasting" ]
GeoDjango - lon/lat PointFields distance are using geometry instead of geography
37,780,072
<p>I'm trying to use GeoDjango to store lat/lon in a <code>PointField</code> and then query the distance between two <code>PointField</code>s in kilometres. Something is not working to cause the distance calculation to return the geometric distance rather than the geographic distance. I'm using <code>geography=True</co...
0
2016-06-12T23:25:06Z
37,796,973
<p>Reading through the documentation I found that this distance calculation in the GEOSGeometry class does not respect the SRID and is different than the one provided directly by the PostGIS database.</p> <p>I used the python libray <a href="http://geopy.readthedocs.io/en/1.11.0/" rel="nofollow">geopy</a> which provid...
0
2016-06-13T18:41:42Z
[ "python", "django", "geolocation", "distance", "geodjango" ]
matplotlib: AttributeError: 'AxesSubplot' object has no attribute 'add_axes'
37,780,100
<p>Not sure exactly sure how to fix the following attribute error:</p> <pre><code>AttributeError: 'AxesSubplot' object has no attribute 'add_axes' </code></pre> <p>The offending problem seems to be linked to the way I have set up my plot:</p> <pre><code>gridspec_layout = gridspec.GridSpec(3,3) pyplot_2 = fig.add_sub...
0
2016-06-12T23:29:35Z
37,781,774
<p>There's not much details to go on in your question but I'll wager a guess. The error is pretty self-explanatory. You can't <code>add_axes</code> to <code>pyplot_2</code> because <code>pyplot_2</code> is a <code>matplotlib.axes.AxesSubplot</code> object and they don't have an <code>add_axes</code> method defined. </p...
0
2016-06-13T04:20:27Z
[ "python", "matplotlib", "axes" ]
KNN with RFECV returns: "The classifier does not expose "coef_" or "feature_importances_" attributes"
37,780,139
<p>I am trying to apply RFECV on KNeighborsClassifier to eliminate insignificant features. In order to make the issue repeatable, here is an example with iris data:</p> <pre><code>from sklearn.datasets import load_iris from sklearn.feature_selection import RFECV from sklearn.neighbors import KNeighborsClassifier iris ...
1
2016-06-12T23:34:48Z
37,780,243
<p>Error is pretty self explanatory - knn does not provide logic to do feature selection. You cannot use it (sklearn's implementation) to achieve such goal, unless you define your own measure of feature importance for KNN. As far as I know - there is no such general object, and so - scikit-learn does not implement it. ...
0
2016-06-12T23:53:37Z
[ "python", "machine-learning", "scikit-learn" ]
KNN with RFECV returns: "The classifier does not expose "coef_" or "feature_importances_" attributes"
37,780,139
<p>I am trying to apply RFECV on KNeighborsClassifier to eliminate insignificant features. In order to make the issue repeatable, here is an example with iris data:</p> <pre><code>from sklearn.datasets import load_iris from sklearn.feature_selection import RFECV from sklearn.neighbors import KNeighborsClassifier iris ...
1
2016-06-12T23:34:48Z
37,971,791
<p>You may have a partial solution from the <code>mlxtend</code> library:</p> <p><a href="http://rasbt.github.io/mlxtend/user_guide/feature_selection/SequentialFeatureSelector/" rel="nofollow">http://rasbt.github.io/mlxtend/user_guide/feature_selection/SequentialFeatureSelector/</a></p> <p>see <a href="https://github...
0
2016-06-22T15:01:17Z
[ "python", "machine-learning", "scikit-learn" ]
How to Log a Python Crash in Windows
37,780,309
<p>How can a log of the crash of a Python script running on Windows be generated? A python program mysteriously crashes every few hours and the application window is closed so there is not sign of the error messages from the crash.</p> <p>On Linux we can do <code>python script.py &gt;&gt; /logdir/script.py.log 2&gt;&a...
0
2016-06-13T00:05:17Z
37,780,354
<p>how about</p> <pre><code>logger = logging.getLogger("myApplication") while True: try: if ... ... else: .... except Exception: logger.exception("???") </code></pre> <p>and <a href="https://docs.python.org/2/howto/logging.html#logging-to-a-file" rel="nofollow">setup logging to log to...
0
2016-06-13T00:13:32Z
[ "python", "python-2.7", "logging" ]
TF/IDF in Python
37,780,401
<p>Need to calculate TF/IDF for all possible n-terms for a corpus (corpus is not big, can be processed in local machine), using Python 2.7 and wondering if any reference implementation or library I can use directly? Thanks.</p> <p>regards, Lin</p>
0
2016-06-13T00:24:52Z
37,780,417
<p>scikit-learn solves this issue.</p> <p><a href="http://scikit-learn.org/stable/modules/feature_extraction.html" rel="nofollow">http://scikit-learn.org/stable/modules/feature_extraction.html</a></p>
1
2016-06-13T00:29:25Z
[ "python", "python-2.7", "tf-idf" ]
How to change the output color of a specific string, stored within an array, to Linux terminal?
37,780,461
<p>I'm writing a small RPG in Python, and I want my different world objects to have varying colors. I've tried exploring colorama and some similar modules; however, the string always prints as a small box with some numbers and letters in it, instead of, let's say, a blue '~' character for a water tile. </p> <p>I cre...
0
2016-06-13T00:38:59Z
37,780,532
<p>You can add ASCII escape codes to the strings you add to your <code>worldArray</code>. To make your water blue, just replace <code>grid[row][i] = char</code> with <code>grid[row][i] = "\033[34m" + char + "\033[0m"</code>.</p> <p>For more color codes, see: <a href="https://en.wikipedia.org/wiki/ANSI_escape_code#Colo...
0
2016-06-13T00:53:29Z
[ "python", "arrays" ]
How to change the output color of a specific string, stored within an array, to Linux terminal?
37,780,461
<p>I'm writing a small RPG in Python, and I want my different world objects to have varying colors. I've tried exploring colorama and some similar modules; however, the string always prints as a small box with some numbers and letters in it, instead of, let's say, a blue '~' character for a water tile. </p> <p>I cre...
0
2016-06-13T00:38:59Z
37,780,573
<p>You can use this package called termcolor, instead of hard coding the values.</p> <pre><code>import sys from termcolor import colored, cprint text = colored('Hello, World!', 'red', attrs=['reverse', 'blink']) print(text) cprint('Hello, World!', 'green', 'on_red') </code></pre>
0
2016-06-13T00:59:08Z
[ "python", "arrays" ]
PANDAS count on condition
37,780,473
<p>I am trying to tabulate a change in condition using a 'groupby' but am stumped and would appreciate any guidance. I have a data frame as follows:</p> <pre><code>SUBJECT TYPE 1 1 1 2 1 2 2 1 2 1 3 1 3 3 3 5 </code></pre> <p>I would like to g...
0
2016-06-13T00:41:06Z
37,780,631
<pre><code>import pandas as pd df = pd.DataFrame({'SUBJECT': [1, 1, 1, 2, 2, 3, 3, 3], 'TYPE': [1, 2, 2, 1, 1, 1, 3, 5]}) grouped = df.groupby('SUBJECT') df['TYPE'] = grouped['TYPE'].diff() &gt; 0 result = grouped['TYPE'].agg('sum') </code></pre> <p>yields</p> <pre><code>SUBJECT 1 1.0 2 0.0 ...
1
2016-06-13T01:10:23Z
[ "python", "pandas" ]
How to blit on the screen only once at mouse position
37,780,492
<p>I have been trying to blit an image to my screen using the mouse position. This is my code.</p> <pre><code>#Placing the farm if farm: if pygame.mouse.get_pressed()[0]: hi = True if hi: screen.blit(farm_image,mouse_pos) </code></pre> <p>So basically I want it to blit an image to screen onl...
0
2016-06-13T00:45:12Z
37,780,557
<p>You could try using another variable to check to see if it was your first click or not:</p> <pre><code>if pygame.mouse.get_pressed()[0]: if first_click == False: hi = true first_click = True else: pass </code></pre> <p>Make sure to define <code>first_click</code> before you use it. ...
1
2016-06-13T00:57:13Z
[ "python", "pygame" ]
How to blit on the screen only once at mouse position
37,780,492
<p>I have been trying to blit an image to my screen using the mouse position. This is my code.</p> <pre><code>#Placing the farm if farm: if pygame.mouse.get_pressed()[0]: hi = True if hi: screen.blit(farm_image,mouse_pos) </code></pre> <p>So basically I want it to blit an image to screen onl...
0
2016-06-13T00:45:12Z
37,788,152
<p>Building on PythonMaster's answer something like that might work and ensure the farm remains blitted at every frame in case you refresh all your screen with a background every time:</p> <pre><code>#Placing the farm if farm: if pygame.mouse.get_pressed()[0] == False: #resets the first_click to False everytime t...
1
2016-06-13T11:05:42Z
[ "python", "pygame" ]
How to blit on the screen only once at mouse position
37,780,492
<p>I have been trying to blit an image to my screen using the mouse position. This is my code.</p> <pre><code>#Placing the farm if farm: if pygame.mouse.get_pressed()[0]: hi = True if hi: screen.blit(farm_image,mouse_pos) </code></pre> <p>So basically I want it to blit an image to screen onl...
0
2016-06-13T00:45:12Z
37,790,293
<p>You can also use event checking instead of state checking when you only want a single click. This is especially useful because it means you won't miss a click (which might happen if the user clicks and releases the mouse at a moment when your code isn't checking for user input). Pygame has the events <code>MOUSEBUTT...
1
2016-06-13T12:49:00Z
[ "python", "pygame" ]
compare one list to another and show the result
37,780,519
<p>I have to make some to convert hex to binary, and them compare to some list and show the results.</p> <p>The part of conversion I already did, but the part to compare I am struggling with.</p> <pre><code>bitmap = input("inform your bitmap: ") h_size = len(bitmap)*4 bitmap = (bin(int(bitmap,16))[2:]).zfill(h_size) ...
-1
2016-06-13T00:50:52Z
37,780,570
<p>You could have the strings in a dict and then use list comprehension to pick them up if <code>b == '1'</code>:</p> <pre><code>&gt;&gt;&gt; str_bitmap = '01111010' &gt;&gt;&gt; names = {1:'bakery', 2:'banana', 3:'car', 4:'house', 5:'keyboard', 6:'mouse'} &gt;&gt;&gt; [names[a] for a, b in enumerate(str_bitmap) if b ...
0
2016-06-13T00:58:51Z
[ "python", "binary", "compare", "python-3.4" ]
compare one list to another and show the result
37,780,519
<p>I have to make some to convert hex to binary, and them compare to some list and show the results.</p> <p>The part of conversion I already did, but the part to compare I am struggling with.</p> <pre><code>bitmap = input("inform your bitmap: ") h_size = len(bitmap)*4 bitmap = (bin(int(bitmap,16))[2:]).zfill(h_size) ...
-1
2016-06-13T00:50:52Z
37,780,730
<p>You print the corresponding list item based on the current enumerated binary digit:</p> <pre><code>bitmap = input("inform your bitmap: ") h_size = len(bitmap)*4 bitmap = (bin(int(bitmap, 16))[2:]).zfill(h_size) str_bitmap = str(bitmap) items = [ "", "bakery", #1 "banana", #2 "car", #3 "...
0
2016-06-13T01:28:59Z
[ "python", "binary", "compare", "python-3.4" ]
DB browser for sqlite does not work
37,780,592
<p>I write a python code to create a table,but when I open DB browser for SQLite, it does not the table I have created, I am new to database, so can anyone tell me what is wrong with it ? Many thanks!</p> <pre><code>import sqlite3 conn = sqlite3.connect('test1.sqlite') cur = conn.cursor() cur.execute(''' DROP TABLE ...
0
2016-06-13T01:02:21Z
37,780,637
<p>Your code is right and if you try: </p> <pre><code>import sqlite3 conn = sqlite3.connect('test1.sqlite') row = conn.execute('SELECT * FROM Test').fetchone() print("azaz=", row[0]) print("count=", row[1]) </code></pre> <p>You will see this output:</p> <pre><code>('azaz=', u'aa') ('count=', 1) </code></pre> <p...
0
2016-06-13T01:11:43Z
[ "python", "sql" ]
DB browser for sqlite does not work
37,780,592
<p>I write a python code to create a table,but when I open DB browser for SQLite, it does not the table I have created, I am new to database, so can anyone tell me what is wrong with it ? Many thanks!</p> <pre><code>import sqlite3 conn = sqlite3.connect('test1.sqlite') cur = conn.cursor() cur.execute(''' DROP TABLE ...
0
2016-06-13T01:02:21Z
37,780,676
<p>I have just tested your code and it works flawlessly. I have used python-3.5 and DB Broswer for sqlite, tested on window 7 pro.</p>
0
2016-06-13T01:18:13Z
[ "python", "sql" ]
'Bullet' object has no attribute '_Sprite__g' when adding Sprite to Group
37,780,639
<p>I wrote a simple game in Python and I got an error.</p> <pre><code>import pygame import random BLACK = ( 0, 0, 0) WHITE = ( 255, 255, 255) RED = ( 255, 0, 0) BLUE = ( 0, 0, 255) class Block(pygame.sprite.Sprite): def __init__(self, color): super().__init__() self.image = pygame...
-2
2016-06-13T01:12:09Z
37,785,640
<p>I think you are missing the Super call in your Bullet <strong>init</strong>.</p> <pre><code>Try: class Bullet(pygame.sprite.Sprite): def __init__(self): super().__init__() #adding super call to make Bullet a pygame Sprite self.image = pygame.Surface([4, 10]) self.image.fill(BLACK) ...
1
2016-06-13T09:04:20Z
[ "python", "pygame" ]
'Bullet' object has no attribute '_Sprite__g' when adding Sprite to Group
37,780,639
<p>I wrote a simple game in Python and I got an error.</p> <pre><code>import pygame import random BLACK = ( 0, 0, 0) WHITE = ( 255, 255, 255) RED = ( 255, 0, 0) BLUE = ( 0, 0, 255) class Block(pygame.sprite.Sprite): def __init__(self, color): super().__init__() self.image = pygame...
-2
2016-06-13T01:12:09Z
38,966,443
<pre><code>class Bullet(pygame.sprite.Sprite): def __init__(self, x, y): ##You did not add this line below pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface((10,20)) self.image.fill(GREEN) self.rect = self.image.get_rect() self.rect.bottom = y self.rect...
1
2016-08-16T03:58:53Z
[ "python", "pygame" ]
Python: How get second columns in unbalanced multiple lists?
37,780,699
<pre><code>lists=may['barrier'] lists def column(matrix, i): return [row[i] for row in matrix] column(lists,0) barr_col=column(lists,0) barr_col </code></pre> <p>Then it gives the first columns data.</p> <p>But</p> <pre><code>lists=may['barrier'] lists def column(matrix, i): return [row[i] for row in matrix]...
-1
2016-06-13T01:22:00Z
37,780,977
<p>try defining <code>column</code> like this:</p> <pre><code>def column(matrix, i): return [row[i] if i &lt; len(row) else None for row in matrix] </code></pre> <p>The way you currently have it defined, I'd expect it to fail whenever i exceeds the length of the <code>row</code> in that iteration. Get around tha...
0
2016-06-13T02:17:05Z
[ "python", "pandas" ]
Errors on a python word game
37,780,721
<p>I am a beginner in python and It always says I have a bad input on lines 2,4, and 10 and when I put a &lt; in front of the second line it approves it and when I put > for the 4th line it approves it and I tried it for the 10th line but it didn't work </p> <pre><code>start = int(input("type 1 to begin or 2 to buy it...
-3
2016-06-13T01:26:16Z
37,780,749
<p>The "=" sign in Python is for assigning a value to a variable. Example:</p> <pre><code>&gt;&gt;&gt; x = 3 &gt;&gt;&gt; x+1 4 </code></pre> <p>For comparison use "==". Example:</p> <pre><code>&gt;&gt;&gt; if x == 3: ... print "That is true" ... That is true &gt;&gt;&gt; if x == 2: ... print "that is true" ...
1
2016-06-13T01:32:31Z
[ "python" ]
Kivy ReferenceListProperty with more than two arguments
37,780,745
<p>I've just begun to use Kivy and was wondering if one could give a class a <code>ReferenceListProperty</code> with more than two components? For example, if I have <code>Numeric Properties</code> called <code>r</code>, <code>g</code>, <code>b</code> and <code>a</code>, and try to give my class such a property</p> <p...
0
2016-06-13T01:31:51Z
37,783,858
<p>As stated in the <a href="https://kivy.org/docs/api-kivy.properties.html?highlight=referencelistproperty#kivy.properties.ReferenceListProperty" rel="nofollow">kivy docs</a> <code>ReferenceListProperty</code> is a property that allows the creation of a tuple containing other properties. Have you actually defined <cod...
1
2016-06-13T07:22:08Z
[ "python", "kivy", "rgba" ]
NameError: name 's2gradefloat' is not defined
37,780,785
<p>I'm very new to python and i'm trying to create a GUI using tkinter that calculates the score you need on your final exam to get a certain grade. This is what I have so far:</p> <pre><code>from tkinter import * root = Tk() root.geometry("600x550+300+50") root.title("") backgroundcolor = '#%02x%02x%02x' %(0,0,0) ro...
-1
2016-06-13T01:39:27Z
37,780,837
<p>in your calculation function:</p> <pre><code>#------------------Calculation----------------------# def crscore(): s2grade = float(s2gradef.get()) dgrade = float(dgradef.get()) s2gradefloat is not defined --- </code></pre> <p>basically, you are trying to get the value from your entry box I am asuming?</p...
0
2016-06-13T01:51:57Z
[ "python", "user-interface", "tkinter", "nameerror" ]
RuntimeWarning: overflow encountered in double_scalars
37,780,787
<p>I am applying Eulers method to solve a differential equation. This is my code; </p> <pre><code>def f(x, y): return ((x**(2))*y)/((x**(4))+(y**(4))) di=0.01 I=100 x=np.linspace(-I, I, int(I/di)+1) w =np.zeros(len(x)) x[0], w[0] for i in range(1, len(w)): w[i]=w[i-1]+f(x[i-1], w[i-1])*di plt.plot( x, w, l...
1
2016-06-13T01:39:47Z
37,784,106
<p>Your code is running into <strong>Divide by Zero Error</strong>. Try this to convince yourself:</p> <pre><code>&gt;&gt;&gt; def f(x, y): ... return ((x**(2))*y)/((x**(4))+(y**(4))) ... &gt;&gt;&gt; I, di = 100, 0.01 &gt;&gt;&gt; x = np.linspace(-I, I, int(I/di) + 1) &gt;&gt;&gt; w = np.zeros(len(x)) &gt;&gt;&gt...
0
2016-06-13T07:36:16Z
[ "python" ]
Gtk +3 TextView application crashes
37,780,799
<p>I have an application using a GtkTextView and GtkTextBuffer. Lines are added to the buffer with the following python code which runs in a separate thread from the main process:</p> <pre><code> while True: if aLogQueue.qsize() &gt; 0: aBuffer = aLogTextView.get_buffer() try: ...
0
2016-06-13T01:43:22Z
37,781,050
<p>You cannot access the GtkTextBuffer — or any part of GTK+, for that matter — from a separate thread. You must access it from the GUI thread. You will need to use <code>GLib.idle_add()</code> to queue the buffer update on the GUI thread.</p>
3
2016-06-13T02:30:53Z
[ "python", "gtk", "gtktextview" ]
How do I code this loop in Python?
37,780,809
<p>I want the user to enter a number and print out messages according to the value of the number they input.</p> <pre><code>a=int(input("enter a number")) while a&lt;1: int(input("enter another number please")) if a&gt;0 and a&lt;7: print a,"medium value number" elif a&gt;6: print a,"high value number" ...
0
2016-06-13T01:47:11Z
37,781,395
<p>You just forgot to assign variable 'a' to Input </p> <pre><code>a=int(input("enter a number")) while a&lt;1: #assign 'a' Here a=int(input("enter another number please")) if a&gt;0 and a&lt;7: print (a,"medium value number") elif a&gt;6: print (a,"high value number") </code></pre>
0
2016-06-13T03:25:31Z
[ "python", "loops", "while-loop" ]
Python Beautifulsoup Duplicate entry's
37,780,822
<p>This scrapes images from 4chans photography board. The problem is that it scrapes the same image twice. I can't figure out why I am getting duplicate photo's, if anyone could help me that would be awesome. </p> <pre><code>from bs4 import BeautifulSoup import requests import re import urllib2 import os def get_sou...
1
2016-06-13T01:49:00Z
37,786,197
<p>Don't pull every anchor, use the class name to get certain links:</p> <pre><code>import requests from bs4 import BeautifulSoup soup = BeautifulSoup(requests.get("http://boards.4chan.org/p/").content) imgs = [a["href"] for a in soup.select("div.fileText a")] print(imgs) </code></pre> <p>The reason you have dupe...
0
2016-06-13T09:30:00Z
[ "python", "image", "beautifulsoup", "duplicates", "screen-scraping" ]
subprocess.Popen - redirect stdin again
37,780,898
<p>Let's assume there's a program named 'ABC', which reads 4 integers from stdin and does something with them.</p> <p>Recently, I leanred that we can use pipeline to feed the inputs to ABC, like following :</p> <pre><code># send.py import subprocess p = subprocess.Popen(['ABC'], stdin = subprocess.PIPE) print &gt;&g...
2
2016-06-13T02:02:31Z
37,790,801
<p>The redirection occurs before <code>ABC</code> is executed e.g., (on Unix) after the <code>fork()</code> but before <code>execv()</code> (<a href="http://ru.stackoverflow.com/a/530437/23044">look at <code>dup2()</code> calls</a>). It is too late to use the same OS level mechanism for the redirection after <code>Pope...
1
2016-06-13T13:14:00Z
[ "python", "python-2.7", "subprocess", "popen" ]
subprocess.Popen - redirect stdin again
37,780,898
<p>Let's assume there's a program named 'ABC', which reads 4 integers from stdin and does something with them.</p> <p>Recently, I leanred that we can use pipeline to feed the inputs to ABC, like following :</p> <pre><code># send.py import subprocess p = subprocess.Popen(['ABC'], stdin = subprocess.PIPE) print &gt;&g...
2
2016-06-13T02:02:31Z
37,791,456
<p>You can ask for the fourth integer up front, then send it in along with the other 3:</p> <pre><code>p = subprocess.Popen(['ABC'], stdin=subprocess.PIPE) fourth_int = raw_input('Enter the 4th integer: ') all_ints = '1 2 3 ' + fourth_int p.communicate(input=all_ints) </code></pre>
1
2016-06-13T13:47:22Z
[ "python", "python-2.7", "subprocess", "popen" ]
My selenium says that Element is not currently visible and so may not be interacted with
37,780,948
<p>I tried to click a button on a ui-popup but always failed. HTML: <a href="http://i.stack.imgur.com/3b2iN.png" rel="nofollow"><img src="http://i.stack.imgur.com/3b2iN.png" alt="enter image description here"></a></p> <p>The web looks like this :</p> <p><img src="http://i.stack.imgur.com/MSTkQ.jpg" alt=""></p> <p>An...
-3
2016-06-13T02:12:16Z
37,781,330
<p><strong>Use javascript executor</strong> </p> <pre><code> WebElement element = driver.findElement(By.xpath("//a[@id='focussuccesstipsclose']")); JavascriptExecutor executor = (JavascriptExecutor)driver; executor.executeScript("arguments[0].click();", element); </code></pre> <p><strong>If element not visible exc...
-1
2016-06-13T03:15:33Z
[ "python", "selenium" ]
My selenium says that Element is not currently visible and so may not be interacted with
37,780,948
<p>I tried to click a button on a ui-popup but always failed. HTML: <a href="http://i.stack.imgur.com/3b2iN.png" rel="nofollow"><img src="http://i.stack.imgur.com/3b2iN.png" alt="enter image description here"></a></p> <p>The web looks like this :</p> <p><img src="http://i.stack.imgur.com/MSTkQ.jpg" alt=""></p> <p>An...
-3
2016-06-13T02:12:16Z
37,783,851
<p>This happen when some other element covers the element on which you are going to perform action. In your case<br> <code>driver.find_element_by_xpath('//*[@id="focussuccesstipsclose"]').click()</code></p> <p>Check whether you are performing any other action before this step, if so, then check whether that action cov...
-1
2016-06-13T07:21:39Z
[ "python", "selenium" ]
Pandas: Filtering on describe output (count)
37,780,949
<p>I am trying to limit the output returned by the describe output to a subset of only those records with a count great than or equal to any given number.</p> <p>My dataframe is a subset of a larger one, and is defined as:</p> <pre><code> df = evaluations[['score','garden_id']] </code></pre> <p>When I run describe o...
0
2016-06-13T02:12:54Z
37,781,736
<p>If you looking for counts of score greater than 3 Try this: </p> <pre><code>df2 = df.groupby('garden_id').count() df2[df2['score']&gt; 3] </code></pre>
0
2016-06-13T04:15:43Z
[ "python", "pandas" ]
Pandas: Filtering on describe output (count)
37,780,949
<p>I am trying to limit the output returned by the describe output to a subset of only those records with a count great than or equal to any given number.</p> <p>My dataframe is a subset of a larger one, and is defined as:</p> <pre><code> df = evaluations[['score','garden_id']] </code></pre> <p>When I run describe o...
0
2016-06-13T02:12:54Z
37,782,756
<p>I think you can use <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html#using-slicers" rel="nofollow">slicers</a> for selecting and then <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> for finding <code>index</code> ...
1
2016-06-13T06:04:21Z
[ "python", "pandas" ]
Python - Storing user input and checking if the input has already been entered?
37,780,979
<p>How would I go about allowing users to enter one word at a time then press enter and if the user enters a word they have already entered before, the program will tell them they have made a mistake and then continue letting them enter new words? </p>
-2
2016-06-13T02:17:18Z
37,781,003
<p>add the input value to a list</p> <pre><code>alist = [] </code></pre> <p>and each time the user inputs something, </p> <pre><code>while True: #have user input something if "input" in alist: #tell user his variable is already stored else: alist.append(userinput) </code></pre>
1
2016-06-13T02:21:34Z
[ "python" ]
CSV: Counting a string in a column if another column has a certain value
37,781,066
<p>I'm having a problem with a csv file where I need some information from. The following is what I need to do:</p> <p>I have a CSV file that is ordered like this:</p> <pre><code>bla country bla bla value Germany Y Germany Y Germany N Denmark ...
0
2016-06-13T02:34:43Z
37,781,116
<p>Is this what you're looking for?</p> <pre><code>import csv from collections import Counter data = '''country,value Germany,Y Germany,Y Germany,N Denmark,N Denmark,N Denmark,Y''' r = csv.DictReader(data.split('\n')) counter = Counter( row.get('country') for row in r if row.get('value') == 'Y') for k...
1
2016-06-13T02:41:42Z
[ "python", "csv", "iteration" ]
CSV: Counting a string in a column if another column has a certain value
37,781,066
<p>I'm having a problem with a csv file where I need some information from. The following is what I need to do:</p> <p>I have a CSV file that is ordered like this:</p> <pre><code>bla country bla bla value Germany Y Germany Y Germany N Denmark ...
0
2016-06-13T02:34:43Z
37,781,444
<p>I think @smarx's answer is the most beautiful way to do it. Here is a more verbose and pragmatical approach:</p> <pre><code>import csv d = {} with open('airlines.csv', 'r') as f: # Sniff the CSV dialect dialect = csv.Sniffer().sniff(f.read(1024)) # Move back to beginning of file f.seek(0) # ...
0
2016-06-13T03:32:49Z
[ "python", "csv", "iteration" ]
how to write a method to create sqlite table in python
37,781,215
<p>I'm trying to write a class in order to create an sqlite table since I have to create quite a few tables for this assignment.</p> <p>This is how I tried to approach:</p> <pre><code>def connect_database(database_name): table_connect = lite.connect(database_name) print "connected successfully" return tab...
0
2016-06-13T02:57:04Z
37,781,345
<p>really you should probably consider using an ORM like sqlalchemy ... writing your own database abstraction, based on the your current skill level is probably a recipe for disaster, however if you really must try something like this</p> <pre><code>def create_table_string(table_name,*fields): return "CREATE TABLE...
1
2016-06-13T03:18:43Z
[ "python", "sqlite" ]
plot N planes parallel to XZ axis in 3D in python
37,781,319
<p>I want to plot N planes (say 10) parallel to XZ axis and equidistant to each other using python. If possible it would be nice to select the number of planes from user. It will be like, if user gives "20" then 20 planes will be drawn in 3D. This is what I did.But I would like to know is there a method to call each pl...
-3
2016-06-13T03:13:26Z
37,781,641
<p>Here is an example how to implement what you need in a very generic way.</p> <pre><code>from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt from matplotlib import cm from pylab import meshgrid,linspace,zeros,dot,norm,cross,vstack,array,matrix,sqrt def rotmatrix(axis,costheta): """ Calcula...
1
2016-06-13T04:02:16Z
[ "python", "python-2.7", "numpy", "matplotlib" ]
Python shell is restarted every time I do “run module” inside editor?
37,781,380
<p>I am using python 2 on Ubuntu and when writing <code>import webbrowser webbrowser.open("fb.com")</code> and run the module, the shell restarts and nothing happens. What is the problem here?</p>
0
2016-06-13T03:23:02Z
37,781,672
<p>It's hard to say without any code presented, but most likely you have not defined which browser it should use and/or you don't have one set as a default. </p> <p>Try registering a controller for the browser you want:</p> <pre><code>import webbrowser ff_controller = webbrowser.get("firefox") ff_controller.open("fb...
1
2016-06-13T04:06:20Z
[ "python", "python-2.7", "shell", "ubuntu" ]
Python shell is restarted every time I do “run module” inside editor?
37,781,380
<p>I am using python 2 on Ubuntu and when writing <code>import webbrowser webbrowser.open("fb.com")</code> and run the module, the shell restarts and nothing happens. What is the problem here?</p>
0
2016-06-13T03:23:02Z
37,781,709
<p>I am not sure what you mean by <em>run the module</em>.</p> <p>If you just want to open fb.com, then try <code>webbrowser.open('http://fb.com')</code>. Give the <code>http://</code> so it doesn't try to open with <code>file://</code> or something.</p>
1
2016-06-13T04:11:51Z
[ "python", "python-2.7", "shell", "ubuntu" ]
Pandas 'bool object is not callable'
37,781,415
<p>I have a dataframe with several columns, and I'm trying to group it in respect to a column and sort it according to another column. If I apply groupby() like this:</p> <pre><code>data.groupby(columnA) </code></pre> <p>it doesn't spit out any errors, yet if I try to sort it like this:</p> <pre><code>data.groupby(c...
2
2016-06-13T03:28:36Z
37,781,942
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.apply.html" rel="nofollow"><code>GroupBy.apply</code></a> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.sort_values.html" rel="nofollow"><code>sort_values</code></a>: </p> <p>E...
1
2016-06-13T04:43:23Z
[ "python", "sorting", "pandas", "dataframe" ]
Pandas 'bool object is not callable'
37,781,415
<p>I have a dataframe with several columns, and I'm trying to group it in respect to a column and sort it according to another column. If I apply groupby() like this:</p> <pre><code>data.groupby(columnA) </code></pre> <p>it doesn't spit out any errors, yet if I try to sort it like this:</p> <pre><code>data.groupby(c...
2
2016-06-13T03:28:36Z
37,782,053
<p>Since you want to sort by columnA first followed by columnB, you can do this using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html" rel="nofollow"><code>sort_values</code></a> only:</p> <pre><code># using jezrael's example In [11]: data.sort_values(["columnA", "colum...
2
2016-06-13T04:55:35Z
[ "python", "sorting", "pandas", "dataframe" ]
How to find the index number of list that in dictionary?
37,781,420
<p>The example list</p> <pre><code>{ 'date': array(['06/08/2016', '06/09/2016', '06/10/2016']), 'close': array([ 923.13, 914.25, 909.42]) } </code></pre> <p>I try to get the Date of close is 914.25 that is list['date'][2] but i don't know how to get index 2 for close.</p> <p>Thank you.</p>
1
2016-06-13T03:28:54Z
37,781,434
<p>Ideally, if you would do this kind of queries often, you should <em>restructure your data</em> to fit the use case better. For instance, have a dictionary where the keys are amounts and dates are values. Then, you would have quick <code>O(1)</code> lookups into the dictionary by key.</p> <p>But, in this state of th...
2
2016-06-13T03:31:29Z
[ "python" ]
How to find the index number of list that in dictionary?
37,781,420
<p>The example list</p> <pre><code>{ 'date': array(['06/08/2016', '06/09/2016', '06/10/2016']), 'close': array([ 923.13, 914.25, 909.42]) } </code></pre> <p>I try to get the Date of close is 914.25 that is list['date'][2] but i don't know how to get index 2 for close.</p> <p>Thank you.</p>
1
2016-06-13T03:28:54Z
37,781,446
<p>You can try this :</p> <pre><code>&gt;&gt;&gt; data = { 'date': ['06/08/2016', '06/09/2016', '06/10/2016'],'close': [ 923.13, 914.25, 909.42]} &gt;&gt;&gt; data['date'][data['close'].index(914.25)] '06/09/2016' </code></pre> <p>Thanks to <code>index()</code>, you are able to get the index of the required value (...
1
2016-06-13T03:33:20Z
[ "python" ]
How to find the index number of list that in dictionary?
37,781,420
<p>The example list</p> <pre><code>{ 'date': array(['06/08/2016', '06/09/2016', '06/10/2016']), 'close': array([ 923.13, 914.25, 909.42]) } </code></pre> <p>I try to get the Date of close is 914.25 that is list['date'][2] but i don't know how to get index 2 for close.</p> <p>Thank you.</p>
1
2016-06-13T03:28:54Z
37,781,637
<p>Where is the example from? I don't think you can have an <code>array</code> of strings in Python.</p> <p>Assuming that the Python data structure is:</p> <pre><code>{ 'date': ['06/08/2016', '06/09/2016', '06/10/2016'], 'close': [923.13, 914.25, 909.42] } </code></pre> <p>and the indexes of <code>close</c...
0
2016-06-13T04:01:42Z
[ "python" ]
multiple step math equations python
37,781,429
<p>I'm trying to write a program that prompts the user to enter two numbers and then have the system figure out the sum, difference, product and quotient of the given numbers and print the results out. This is what I have so far. When I ran the code for sum it came back correct, when I added the difference function it ...
-1
2016-06-13T03:30:31Z
37,781,566
<p>The problem is that you are trying to use the sum method which must iterate through a list, you are trying to do this with a tuple.</p> <p>you have the equivalent of:</p> <pre><code>a = sum(1,2) print(a) </code></pre> <p>which will return <code>TypeError: 'float' object is not iterable</code></p> <p>instead you ...
1
2016-06-13T03:51:36Z
[ "python", "function" ]
multiple step math equations python
37,781,429
<p>I'm trying to write a program that prompts the user to enter two numbers and then have the system figure out the sum, difference, product and quotient of the given numbers and print the results out. This is what I have so far. When I ran the code for sum it came back correct, when I added the difference function it ...
-1
2016-06-13T03:30:31Z
37,781,573
<p>Few mistakes,</p> <ol> <li>You missed the <code>'</code> as pointed out in comments by Andrew.</li> <li>You made a mistake in the <code>.format</code>.</li> <li>You had used <code>results</code> in your difference function where you were returning result. </li> </ol> <p>Here's the corrected code:</p> <pre><code>...
0
2016-06-13T03:52:46Z
[ "python", "function" ]
Trouble with relative / absolute functions import in scikit-image
37,781,435
<p>I'm trying to submit a <a href="https://github.com/scikit-image/scikit-image/pull/2139" rel="nofollow">PR</a> for scikit-image, but I get a Travis-CI <a href="https://travis-ci.org/scikit-image/scikit-image/builds/137117004" rel="nofollow">error</a>:</p> <pre><code> Traceback (most recent call last): File "doc/e...
8
2016-06-13T03:31:43Z
37,784,169
<p>One ugly hack to resolve this would be to move that import inside the function, like</p> <pre><code>def hessian_filter(image, scale=(1, 10), scale_ratio=2, beta1=0.5, beta2=15): """ Blah-blah-blah """ from ..feature import hessian_matrix, hessian_matrix_eigvals # function body </code></pre> ...
6
2016-06-13T07:39:53Z
[ "python", "scikit-image" ]
Is is possible to use shorthand option_settings with boto3?
37,781,661
<p>When writing <code>.ebextensions</code> <code>.config</code> files, Amazon allows for long and shortform entries, for example these two configurations are identical:</p> <p>Long form:</p> <pre><code>"option_settings": [ { 'Namespace': 'aws:rds:dbinstance', 'OptionName': 'DBEngine', 'Val...
0
2016-06-13T04:05:04Z
37,781,811
<p>Trial and error suggests <strong>no, you can not use the shortform config type</strong>.</p> <p>However, if you are of that sort of persuasion you can do this:</p> <pre><code>def short_to_long(_in): out = [] for namespace,key_vals in _in.items(): for optname,value in key_vals.items(): o...
2
2016-06-13T04:25:06Z
[ "python", "amazon-web-services", "boto", "boto3" ]
Display options for FK select - Django Rest Framework
37,781,801
<p>How do I display the options for the foreign key select element (drop-down) in a more meaningful way than <code>&lt;class name&gt; object</code>?</p> <p>Here's a picture of what isn't so helpful:</p> <p><a href="http://i.stack.imgur.com/KePtF.png" rel="nofollow"><img src="http://i.stack.imgur.com/KePtF.png" alt="e...
0
2016-06-13T04:23:54Z
37,781,967
<p>Did you add a <code>__unicode__</code> or <code>__str__</code> method on your Foo model?</p>
0
2016-06-13T04:47:09Z
[ "python", "django", "rest", "django-rest-framework", "html-select" ]
Display options for FK select - Django Rest Framework
37,781,801
<p>How do I display the options for the foreign key select element (drop-down) in a more meaningful way than <code>&lt;class name&gt; object</code>?</p> <p>Here's a picture of what isn't so helpful:</p> <p><a href="http://i.stack.imgur.com/KePtF.png" rel="nofollow"><img src="http://i.stack.imgur.com/KePtF.png" alt="e...
0
2016-06-13T04:23:54Z
37,782,079
<p>For client side representation you can implement <code>__str__</code>:</p> <pre><code>class Foo(models.Model): title = models.CharField(max_length=100,blank=True,null=True) def __str__(self): return self.title </code></pre>
1
2016-06-13T04:58:57Z
[ "python", "django", "rest", "django-rest-framework", "html-select" ]
Django, how to use filter to check if string field is contained in parameter
37,781,832
<p>Say, I have a model with a text field:</p> <pre><code>class SomeModel keyword=models.CharField(null=True, max_length=255) </code></pre> <p>Now, I know how to check if a parameter string (lets call the variable "querystring" is contained in the field keyword:</p> <pre><code>results = SomeModel.objects.filter(k...
-1
2016-06-13T04:28:15Z
37,783,117
<p>You'll have to split your input into words (depending on your definition of "word"), and then iterate over them, concatenating the various resulting querysets (most of which are likely to be empty).</p> <p>To split, you could use a regex, catching all letters and the apostrophe (but you'll miss a smart-quote, if so...
0
2016-06-13T06:31:29Z
[ "python", "django" ]
How to show version info on index.html page
37,781,940
<p>I am using sphinx and I would like to show the version of my project from conf.py on my main page for documentation.</p>
1
2016-06-13T04:43:17Z
37,791,566
<p>I actually never use Python Sphinx, but I remember seeing a similar question on SO. After searching through, I found the Q+A <a href="https://stackoverflow.com/questions/10030149/how-do-i-output-a-config-value-in-a-sphinx-rst-file">here</a></p> <p>So you could output the config value directly into your index.rst ma...
0
2016-06-13T13:52:58Z
[ "python", "python-sphinx" ]
How to show version info on index.html page
37,781,940
<p>I am using sphinx and I would like to show the version of my project from conf.py on my main page for documentation.</p>
1
2016-06-13T04:43:17Z
37,800,352
<p>You can use <code>:Version: |version|</code> in your rst</p>
0
2016-06-13T22:48:48Z
[ "python", "python-sphinx" ]
Connecting Models from different Apps - Django
37,781,943
<p>Given that I have 4 models:</p> <ul> <li><code>Project</code></li> <li><code>User</code> (from django.contrib.auth.models)</li> <li><code>Sentence</code></li> <li><code>Translation</code></li> </ul> <p>My django project directories are structured as such:</p> <pre><code> \myprojname \project models....
0
2016-06-13T04:43:25Z
37,782,061
<p>Your import should be <code>from data.models import Sentence</code> instead of <code>from myprojname.data import Sentence</code>.</p>
1
2016-06-13T04:56:36Z
[ "python", "django", "web-applications", "django-models", "orm" ]
Teradata Python module show table statement does not work
37,781,974
<p>I am experimenting with <a href="http://developer.teradata.com/tools/reference/teradata-python-module" rel="nofollow">Teradata-Python module</a> and I am new to python</p> <p>I am trying to fetch table ddl with the help of SHOW TABLE statement and it behaves weird and only returns a few words out of whole DDL. Plea...
0
2016-06-13T04:47:53Z
37,791,527
<p>This is a known issue for Teradata's Python module. You can see in the comments on the <a href="http://developer.teradata.com/tools/reference/teradata-python-module#ExecuteParameters" rel="nofollow">Teradata Python Module</a> page where someone runs into the exact same problem. Thankfully they identified the solutio...
2
2016-06-13T13:51:04Z
[ "python", "sql", "teradata", "ddl" ]
Python openpyxl .xlsx if column is X print current row
37,781,993
<p>I can't seem to figure this out. </p> <p>I am trying to go through a whole column in a spreadsheet and return the row of data if value is found.</p> <p>Any help would be appreciated..</p>
0
2016-06-13T04:49:52Z
37,782,193
<p>Please Import xlrd and run this code and modify as you</p> <pre><code>import xlrd workbook = xlrd.open_workbook('file.xls') for s in workbook.sheets(): for r in range(s.nrows): for c in range(s.ncols): print "row::::: ", r print "column:: ", c print "value::: ", s.cell(r,c).value </code>...
-1
2016-06-13T05:09:56Z
[ "python", "excel", "xlsx", "openpyxl" ]
Python openpyxl .xlsx if column is X print current row
37,781,993
<p>I can't seem to figure this out. </p> <p>I am trying to go through a whole column in a spreadsheet and return the row of data if value is found.</p> <p>Any help would be appreciated..</p>
0
2016-06-13T04:49:52Z
37,786,708
<p>The simplest thing is simply to loop through all the rows of the worksheet, check the cell in the relevant column and break when you get the value.</p> <pre><code>from openpyxl import load_workbook wb = load_workbook(filename) ws = wb[sheetname] for row in ws: cell = row[0] # for column 'A' if cell.value ==...
0
2016-06-13T09:55:35Z
[ "python", "excel", "xlsx", "openpyxl" ]
How can I force 2 fields in a Django model to share the same default value?
37,782,083
<p>I have a Django model <code>MyModel</code> as shown below. </p> <p>It has two fields of type DateTimeField: <code>my_field1</code>, <code>my_field2</code></p> <pre><code>from django.db import models from datetime import datetime class MyModel(models.Model): my_field1 = models.DateTimeField(default=datetime.ut...
1
2016-06-13T04:59:24Z
37,782,129
<p>As stated in the <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#default" rel="nofollow">docs</a>:</p> <blockquote> <p>The default value is used when new model instances are created and a value isn’t provided for the field.</p> </blockquote> <p>So to solve your task, I would fill the default ...
0
2016-06-13T05:03:43Z
[ "python", "django", "django-models", "default" ]
How can I force 2 fields in a Django model to share the same default value?
37,782,083
<p>I have a Django model <code>MyModel</code> as shown below. </p> <p>It has two fields of type DateTimeField: <code>my_field1</code>, <code>my_field2</code></p> <pre><code>from django.db import models from datetime import datetime class MyModel(models.Model): my_field1 = models.DateTimeField(default=datetime.ut...
1
2016-06-13T04:59:24Z
37,803,104
<p>The proper way to do this is by over riding the save method rather than the <code>__init__</code> method. In fact it's not recommended to over ride the <strong>init</strong> method, the better way is to over ride from_db if you wish to control how the objects are read or save method if you want to control how they a...
1
2016-06-14T04:37:57Z
[ "python", "django", "django-models", "default" ]
how to split findall result which contain "," in data
37,782,094
<pre><code>x = re.findall(r'FROM\s(.*?\s)(WHERE|INNER|OUTER|JOIN|GROUP,data,re.DOTALL) </code></pre> <p>I am using above expression to parse oracle sql query and get the result. I get multiple matches and want to print them each line by line. How can i do that. Some result even have "," in between them.</p>
0
2016-06-13T05:00:25Z
37,782,203
<p>You can try this :</p> <pre><code>for elt in x: print('\n'.join(elt.split(','))) </code></pre> <p><code>join</code> returns a list of the comma-separated elements, which are then joined again with <code>\n</code> (new line). Therefore, you get one result per line.</p>
1
2016-06-13T05:11:02Z
[ "python" ]
how to split findall result which contain "," in data
37,782,094
<pre><code>x = re.findall(r'FROM\s(.*?\s)(WHERE|INNER|OUTER|JOIN|GROUP,data,re.DOTALL) </code></pre> <p>I am using above expression to parse oracle sql query and get the result. I get multiple matches and want to print them each line by line. How can i do that. Some result even have "," in between them.</p>
0
2016-06-13T05:00:25Z
37,782,264
<p>Your result is returned in a list. from <a href="https://docs.python.org/2/library/re.html" rel="nofollow">https://docs.python.org/2/library/re.html</a>:</p> <blockquote> <p>re.findall(pattern, string, flags=0) Return all non-overlapping matches of pattern in string, as a list of strings.</p> </blockquote> <p>...
0
2016-06-13T05:16:45Z
[ "python" ]
400 Bad request Error..... Flask python 2.7
37,782,144
<p>I am trying to execute a simple python function, Through which I want to update database dynamically though a bootstrap modal window. Unable to Identify any mistake there... and the same error occurs again... kindly help me out here..</p> <pre><code>from flask import Flask, render_template, redirect, json, request,...
-1
2016-06-13T05:04:45Z
37,782,351
<p>it would seem that you are not handling your request.post under updatepost():</p> <pre><code>@app.route('/something', methods=['GET', 'POST']) def something(): """ form, retrieves variables when using POST """ try: if request.method == 'POST': #do something else: ...
0
2016-06-13T05:26:34Z
[ "python", "flask" ]
fread with fopen64 under MinGW64 kills the process
37,782,202
<p>I'm building my x64 python c library extension from x86 one.</p> <p>I found out <code>fread</code> with a file pointer opend by <code>fopen64</code> killed the python process because of an error <code>APPCRASH</code>of <code>ntdll.dll</code>. It doesn't happen under x86 build and neither happen if the file pointer ...
0
2016-06-13T05:10:56Z
37,782,265
<p>For now, I'm using the code below.</p> <pre><code>#if defined(_WIN64) #define _fopen fopen #else #define _fopen fopen64 #endif </code></pre>
0
2016-06-13T05:16:56Z
[ "python", "fopen", "windows-7-x64", "python-c-extension", "mingw64" ]
how to plot 2d-filled contour plot with dataset including NaN values in python
37,782,334
<p>I made a 2d filled contour plot with dataset including NaN values in python but this plot has many gaps. So I used plotly package(connectgaps=True) to improve this plot.</p> <p>I'm finding alternative method not to use plotly package. How can I improve contour plot not using plotly package in python?</p> <p>origi...
0
2016-06-13T05:24:31Z
37,782,759
<p>You may use matplolib functions <code>countour</code> <a href="http://matplotlib.org/examples/pylab_examples/contour_demo.html" rel="nofollow">http://matplotlib.org/examples/pylab_examples/contour_demo.html</a> and <code>contourf</code> <a href="http://matplotlib.org/examples/pylab_examples/contourf_demo.html" rel="...
0
2016-06-13T06:04:27Z
[ "python", "plot", null, "contour" ]
Simple arithmetic average in Python
37,782,414
<p>I'm a total newbie on Python and I would like to calculate the arithmetic average.</p> <pre><code>a = [int(i) for i in input().split()] average=sum(a)/len(a) print('The average is:' ,average) </code></pre> <p>I'm aware that such code do solve my problems but that is not exactly what I'm looking for.</p> <p>I wa...
0
2016-06-13T05:32:42Z
37,782,434
<p>Try:</p> <pre><code>n = int(input('Number of terms')) sum = 0 for i in range (1,n+1): a=int(input('Term number '+str(i)+': ')) sum += a avg = sum/n </code></pre>
-1
2016-06-13T05:35:00Z
[ "python", "loops", "math", "average" ]
Simple arithmetic average in Python
37,782,414
<p>I'm a total newbie on Python and I would like to calculate the arithmetic average.</p> <pre><code>a = [int(i) for i in input().split()] average=sum(a)/len(a) print('The average is:' ,average) </code></pre> <p>I'm aware that such code do solve my problems but that is not exactly what I'm looking for.</p> <p>I wa...
0
2016-06-13T05:32:42Z
37,782,477
<pre><code>n = input('Number of terms') acc = 0 for i in range(1,int(n)+1): a=input('Term number '+str(int(i))+': ') acc += float(a) print('The average is ',acc/int(n)) </code></pre> <p>The idea is to create an accumulator variable <code>acc</code> to which the entered numbers are added. After the loop <code>a...
0
2016-06-13T05:39:12Z
[ "python", "loops", "math", "average" ]
how to catch for/while statement with clang in python
37,782,539
<p>I calculate C/C++ code's cyclomatic complexity with clang in python module.</p> <p>And, I caught almost statement but, I can't catch several statement that don't</p> <p>have a brace.</p> <p>example, if below statement can catch and calculate cyclomatic complexity.</p> <pre><code>if (i == 1 &amp;&amp; k ==2) { ...
0
2016-06-13T05:45:02Z
37,783,233
<p>The only block I can think of that is not necessarily brace-enclosed (except for <code>goto</code> but we won't go in to that) would be the <code>case</code>s of a <code>switch</code>/<code>case</code> block. In that case you could check for delimiters. Unlike python, you don't have indentation check. So either the ...
0
2016-06-13T06:40:05Z
[ "python", "clang", "llvm-clang" ]
Calculate the row average of selected columns
37,782,720
<p>I have a csv file:</p> <pre><code>#col1 #col2 ... #col253 33, 123, ... 99 19, 409, ... 24 34, 239, ... 60 ... ... ... .. </code></pre> <p>and a dictionary whose values store the start and end index of selected columns:</p> <pre><code>d = { 'win': [(11, 55), (194, 233)], 'lose': [(...
0
2016-06-13T06:01:26Z
37,783,082
<p>Numpy arrays support <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/arrays.indexing.html" rel="nofollow">rich indexing</a>, so this can be achieved for example by slicing over all the rows and passing a list of columns to select.</p> <p>To calculate for each row separately you can pass the <code>axis</co...
2
2016-06-13T06:28:30Z
[ "python", "csv", "numpy" ]
Calculate the row average of selected columns
37,782,720
<p>I have a csv file:</p> <pre><code>#col1 #col2 ... #col253 33, 123, ... 99 19, 409, ... 24 34, 239, ... 60 ... ... ... .. </code></pre> <p>and a dictionary whose values store the start and end index of selected columns:</p> <pre><code>d = { 'win': [(11, 55), (194, 233)], 'lose': [(...
0
2016-06-13T06:01:26Z
37,783,519
<p>You can create an array of columns that covers all those <em>interval-ed</em> ranges in a vectorized manner using <a href="http://stackoverflow.com/a/37626057/3293881"><code>this other solution</code></a>. Then, index into the columns of input array, <code>x</code> with those and calculate the average along the seco...
1
2016-06-13T06:58:35Z
[ "python", "csv", "numpy" ]
comparing multiple values given to a key in python
37,782,885
<p>I am actually trying to develop a mapper and reducer using python for a certain data. I have written the mapper code which would give the store name and the cost of the transaction that was done at the store.</p> <p>For example:</p> <p><code>Nike $45.99 Adidas $72.99 Puma $56.99 Nike $109.99 Adidas $85.99</code></...
0
2016-06-13T06:13:46Z
37,783,179
<p>Well, the <code>MapReduce</code> paradigm is a key-value pairs that each mapper should output in the exact format.</p> <p>As for the reducer, the hadoop framework guarantees that each reducer using a shuffle-sort algorithm, will get all the values for a certain key, so there's no way that two different reducers wil...
1
2016-06-13T06:36:45Z
[ "python", "hadoop", "key-value" ]
comparing multiple values given to a key in python
37,782,885
<p>I am actually trying to develop a mapper and reducer using python for a certain data. I have written the mapper code which would give the store name and the cost of the transaction that was done at the store.</p> <p>For example:</p> <p><code>Nike $45.99 Adidas $72.99 Puma $56.99 Nike $109.99 Adidas $85.99</code></...
0
2016-06-13T06:13:46Z
37,783,473
<pre><code>def largets_value(_dict): d = {} for i, v in enumerate(_dict.keys()): d[v] = max(_dict.values()[i]) return d def dict_from_txt(file, sep): d = {} f = [x.rstrip().replace('$', '').split(sep) for x in open(file, 'rb').readlines()] for i in f: if i[0] in d: d...
0
2016-06-13T06:55:24Z
[ "python", "hadoop", "key-value" ]
comparing multiple values given to a key in python
37,782,885
<p>I am actually trying to develop a mapper and reducer using python for a certain data. I have written the mapper code which would give the store name and the cost of the transaction that was done at the store.</p> <p>For example:</p> <p><code>Nike $45.99 Adidas $72.99 Puma $56.99 Nike $109.99 Adidas $85.99</code></...
0
2016-06-13T06:13:46Z
37,783,954
<p>Hadoop should be sorting the output of your mapper before passing it to your reducers. Given that you can use <code>itertools.groupby()</code> to group like keys into a list, and then select the biggest from each grouped list:</p> <pre><code>#!/usr/bin/env python import sys from itertools import groupby for store...
0
2016-06-13T07:27:41Z
[ "python", "hadoop", "key-value" ]
SqlAlchemy check if relationship property is in list
37,783,022
<p>I have 2 tables: 1) Shop that have column item that have relationship with the second table 2) Items table - have some details like brand etc..</p> <p>I am trying to make query that will give me all raws from shop where the brand is in list of brands.</p> <pre><code>brands = self.session.query(Items).filter(Items....
0
2016-06-13T06:24:05Z
37,783,153
<p>SQLAlchemy still does not support in_ with objects. Hence you can try two ways.</p> <ol> <li><p>get the brand ids and filter them with in_ in the second query.</p> <p>brands = self.session.query(Items).filter(Items.brand.in_(list)) brand_ids = [obj.id for obj in brands]<br> self.session.query(Shop).filter((Shop.ac...
1
2016-06-13T06:34:39Z
[ "python", "mysql", "database", "python-2.7", "sqlalchemy" ]
Python: Break DAT files in modules and search specific lines
37,783,043
<p>I have a large DAT file of this type: </p> <pre><code>// AC T00020 OS rat, Rattus norvegicus BS R02959; HS$APOA1_02; Quality: 6; APOA1, G000203; human, Homo sapiens. I have a large dat file of this type: // AC T00024 OS rat, Rattus norvegicus BS R00135; HS$APOA1_01; Quality: 6; APOA1, G000203; human, Homo sap...
-1
2016-06-13T06:25:36Z
37,783,255
<p><a href="http://www.tutorialspoint.com/python/python_files_io.htm" rel="nofollow">Open file and read</a> the contents, (not line by line) using <code>f.read()</code>.</p> <p><a href="http://www.tutorialspoint.com/python/string_split.htm" rel="nofollow">Split</a> by a chosen character or string.</p> <pre><code># pu...
0
2016-06-13T06:41:57Z
[ "python", "database", "file" ]
How to display graph and Video file in a single frame/Window in python?
37,783,060
<p><a href="http://i.stack.imgur.com/m4FXc.jpg" rel="nofollow">I want something similar like this image and this is same layout which I supposed to want.</a></p> <p>And with additional note,I want to generate a graph based on the video file timings.For Eg. 10 sec this graph should be generated and after 20 sec another...
0
2016-06-13T06:26:45Z
37,844,954
<p>I wanted to show that it's even possible to update the plot for each frame at video rate.</p> <p>This example will calculate the average pixel intensity along x-axis and update the plot for every frame. Since you want to update every 10 sec, you will need some modification. This Clip (Jenny Mayhem) is taken from <a...
1
2016-06-15T20:15:52Z
[ "python", "python-3.x", "matplotlib", "graph", "wxpython" ]
How to run playbook api in Ansible v2
37,783,145
<p>I want to run ansible playbook via Ansible V2 python api. Here is my way:</p> <pre><code>from ansible.parsing.dataloader import DataLoader from ansible.vars import VariableManager from ansible.inventory import Inventory from ansible.executor.playbook_executor import PlaybookExecutor variable_manager = VariableManag...
0
2016-06-13T06:34:00Z
37,790,180
<p>Once loading an Inventory, set the variable_manager to use that inventory.</p> <p>From <a href="http://docs.ansible.com/ansible/developing_api.html" rel="nofollow">Python API - Ansible</a> (Line 19):</p> <pre><code>variable_manager.set_inventory(inventory) </code></pre>
2
2016-06-13T12:43:29Z
[ "python", "ansible", "ansible-playbook", "ansible-api" ]
How to make a python command executed via Jupyter.kernel.execute command visible in an Input Cell in Jupyter Notebook
37,783,231
<p>I can execute a python command from Javascript side via Jupyter.kernel.execute(command). For example the command may be something like "a = 3". I can see a new variable named "a" is set to 3, that is OK. </p> <p>I would like to have this command echoed in the INPUT CELL, as if it is entered manually. Is it possible...
0
2016-06-13T06:39:54Z
37,788,136
<p>A very simple example would be (paste the code below in a notebook cell):</p> <pre><code>%%javascript // Function that accepts a string of code var create_and_execute_cell_below = function (code){ var nb = Jupyter.notebook // create cell below this one nb.insert_cell_below() // select cell below ...
1
2016-06-13T11:04:43Z
[ "python", "kernel", "execute", "jupyter" ]
QProcess execution time
37,783,271
<p>I would like to measure execution time of a <code>QProcess</code> object.</p> <p>Is there an internal attribute, method or object in PySide for execution time measurements?</p> <p>The current approach is to measure it from the outside using time.time().</p> <p>Example code:</p> <pre><code>from PySide import QtCo...
2
2016-06-13T06:42:51Z
37,813,136
<p>One way you could do this is as follows. This uses the systems <code>time</code> command to get the time of execution.</p> <pre><code>from PySide import QtCore import time p = QtCore.QProcess() p.start('time -p ping -n 5 127.0.0.1 &gt;nul') p.waitForFinished(-1) stdOut = p.readAllStandardOutput() print(stdOut) #TO...
1
2016-06-14T13:14:32Z
[ "python", "pyqt", "pyside", "qprocess" ]
how to create a pipe model in vtk with repeatability
37,783,341
<p>I created a pipe model by rotating a bunch of cylinders but I donno how to filter common part and ,I am running a for loop to create cylinders and rotating them on a circle.This has a problem that I need to set the position in loop ,I want to attach all cylinders to one polydata object and then use it This is my cod...
0
2016-06-13T06:47:51Z
37,804,281
<p>To add several <code>PolyData</code> objects into one use the <code>vtkAppendPolyData</code>object:</p> <pre><code>import vtk append = vtk.vtkAppendPolyData() for i in range(0, 360): (...) append.SetInputData(sourc[i].GetOutput()) append.Update() </code></pre> <p>then you can add the actor and render ou...
0
2016-06-14T06:17:48Z
[ "python", "vtk" ]
Pass post data to a script flask
37,783,368
<p>I have a page that needs to take two arguments which I want to send in a POST request, Login and Password. I keep getting an IndexError: list index out of range from flask, I'm assuming because it is not receiving the arguments for the script.</p> <p>This is my view.py </p> <pre><code>@app.route("/login/", methods...
0
2016-06-13T06:49:09Z
37,784,889
<p>Your script is receiving the POST values just fine; it is returning the response from your view that is the issue here. You are not returning something that <a href="http://flask.pocoo.org/docs/0.11/quickstart/#about-responses" rel="nofollow">Flask expects to be returned</a>.</p> <p>You are returning a <em>tuple</e...
0
2016-06-13T08:22:34Z
[ "python", "flask" ]
How to not have set written on my file- python 2
37,783,387
<p>So I basically just want to have a list of all the pixel colour values that overlap written in a text file so I can then access them later.</p> <p>The only problem is that the text file is having (set([ or whatever written with it.</p> <p>Heres my code</p> <pre><code>import cv2 import numpy as np import time om=...
0
2016-06-13T06:50:13Z
37,783,459
<p>How would you like the data to be written? Replace the final line by</p> <pre><code>File.write(str(list(ColourCount))) </code></pre> <p>Maybe you like that more.</p> <p>If you run that program, it will overwrite the previous content of the file. If you prefer to apprend the data open the file with:</p> <pre><cod...
-1
2016-06-13T06:54:42Z
[ "python", "text", "set" ]
How to not have set written on my file- python 2
37,783,387
<p>So I basically just want to have a list of all the pixel colour values that overlap written in a text file so I can then access them later.</p> <p>The only problem is that the text file is having (set([ or whatever written with it.</p> <p>Heres my code</p> <pre><code>import cv2 import numpy as np import time om=...
0
2016-06-13T06:50:13Z
37,783,654
<p>You opened the file with the <code>'w'</code> mode, write mode, which will <em>truncate</em> (empty) the file when you open it. Use <code>'a'</code> append mode if you want data to be added to the end each time</p> <p>You are writing the <code>str()</code> conversion of a set object to your file:</p> <pre><code>Co...
0
2016-06-13T07:06:30Z
[ "python", "text", "set" ]
How to not have set written on my file- python 2
37,783,387
<p>So I basically just want to have a list of all the pixel colour values that overlap written in a text file so I can then access them later.</p> <p>The only problem is that the text file is having (set([ or whatever written with it.</p> <p>Heres my code</p> <pre><code>import cv2 import numpy as np import time om=...
0
2016-06-13T06:50:13Z
37,783,820
<p>If you replace these lines:</p> <pre><code>im=cv2.imread('RGB.png') File= open('Weedlist', 'w') File.write(str(ColourCount)) </code></pre> <p>with:</p> <pre><code>import sys im=cv2.imread(sys.argv[1]) open(sys.argv[1]+'Weedlist', 'w').write(str(list(ColourCount))) </code></pre> <p>you will get a new file for ...
0
2016-06-13T07:18:58Z
[ "python", "text", "set" ]
NameError which isn't name error! python
37,783,437
<p>I'm getting weird NameError! i have a bash script who checks CPU status, puts it inside file (linux, btw), then executes python script who's doing the math, then runs another script that checks which core in working too hard, creates a file with the core number (so I can later check if the right core is still workin...
0
2016-06-13T06:53:29Z
37,789,481
<p>It does not work for the same reason the following code:</p> <pre><code>class Test: import math def fn(): print(math.sin(1)) fn() # NameError: name 'math' is not defined </code></pre> <p>From the <a href="https://docs.python.org/2/library/functions.html#execfile" rel="nofollow">documentation of execfile<...
1
2016-06-13T12:08:23Z
[ "python", "python-3.x", "smtplib" ]
Running security import command from Python has different behaviour than command line
37,783,438
<p>I am trying to import a <code>pkcs#12</code> certificate into OS X Keychain using the following command:</p> <pre><code>security import filename -k ~/Library/Keychains/login.keychain -P password -f pkcs12 </code></pre> <p>In python I use <code>subprocess</code> like this:</p> <pre><code> if os.path.isfile(_file)...
0
2016-06-13T06:53:30Z
37,787,924
<p>This was actually due to another problem.</p> <p>I was using a tmpfile which was not being flushed or closed.</p> <p>While the script was running the function could not find any content on that file.</p> <p>Once the script ended, the file (which had 'delete=False') was flushed and for this reason the command line...
0
2016-06-13T10:54:28Z
[ "python", "osx", "keychain", "pkcs#12", "pyopenssl" ]