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
Pandas Get a list of index from dataframe.loc
40,059,994
<p>I have looked through various sites and SO posts.Seems easy but somehow i am stuck with this.I am using</p> <pre><code>print frame.loc[(frame['RR'].str.contains("^[^123]", na=False)), 'RR'].isin(series1.str.slice(1)) </code></pre> <p>to get</p> <pre><code>3 True 4 False 8 False Name: RR, dtype: bool </c...
2
2016-10-15T14:06:41Z
40,060,245
<p>You are testing two conditions on the same column so these can be combined (and negated):</p> <pre><code>frame[~((frame['RR'].str.contains("^[^123]", na=False)) &amp; (frame['RR'].isin(series1.str.slice(1))))] </code></pre> <p>Here, after <code>~</code> operator, it checks whether a particular row satisfies both c...
1
2016-10-15T14:29:14Z
[ "python", "python-2.7", "pandas" ]
Google Sheets API HttpError 500 and 503
40,059,997
<p>Edit: solved, the issue was on Google's side. Occurs when requesting a sheet which had diagrams that had invalid intervals in them. Reported bug to Google.</p> <p>Note: This issue has persisted for more than 2 days. I had it previously but it was automatically resolved after waiting a day. It has since rearisen.</p...
0
2016-10-15T14:06:43Z
40,071,563
<p>500 and 503 are Google Server issues. You will need to implement exponential backoff so that you can retry the transaction again. Check this link - <a href="https://developers.google.com/admin-sdk/directory/v1/limits" rel="nofollow">https://developers.google.com/admin-sdk/directory/v1/limits</a></p> <p>And, there...
0
2016-10-16T14:44:01Z
[ "python", "google-spreadsheet", "google-api", "google-api-client", "google-sheets-api" ]
Google Sheets API HttpError 500 and 503
40,059,997
<p>Edit: solved, the issue was on Google's side. Occurs when requesting a sheet which had diagrams that had invalid intervals in them. Reported bug to Google.</p> <p>Note: This issue has persisted for more than 2 days. I had it previously but it was automatically resolved after waiting a day. It has since rearisen.</p...
0
2016-10-15T14:06:43Z
40,072,468
<p>As described in <a href="https://developers.google.com/analytics/devguides/reporting/core/v3/coreErrors#standard_errors" rel="nofollow">Standard Error Responses</a>, error codes #500 and #503 are errors associated with servers. Recommended action for this is not to retry the query more than once.</p> <p>To handle t...
0
2016-10-16T16:17:21Z
[ "python", "google-spreadsheet", "google-api", "google-api-client", "google-sheets-api" ]
Google Sheets API HttpError 500 and 503
40,059,997
<p>Edit: solved, the issue was on Google's side. Occurs when requesting a sheet which had diagrams that had invalid intervals in them. Reported bug to Google.</p> <p>Note: This issue has persisted for more than 2 days. I had it previously but it was automatically resolved after waiting a day. It has since rearisen.</p...
0
2016-10-15T14:06:43Z
40,113,172
<p>Solved, the issue was on Google's side. Occurs when requesting a sheet which had diagrams that had invalid/unselected intervals in them. Reported bug to Google.</p> <p>Fix by changing all invalid diagrams to valid ranges.</p>
0
2016-10-18T16:10:55Z
[ "python", "google-spreadsheet", "google-api", "google-api-client", "google-sheets-api" ]
Can't access the key from my hashtable python
40,060,017
<p>So I have a hash table class which is fully functioning, now I want to define another function let say will take a parameter of hash_table and print out every keys from my hash table where </p> <pre><code>def to_print(hash_table): for a in hash_table: if a is not None: print(a) <...
0
2016-10-15T14:08:13Z
40,060,062
<p><code>__iter__</code> must return iterator, try to do something like:</p> <pre><code>def __iter__(self): return (item[0] for item in self.array if item is not None) </code></pre>
1
2016-10-15T14:12:01Z
[ "python", "class", "iterator", "hashtable" ]
Python script stuck in infinite loop
40,060,069
<p>I am writing a beginner python script for the python challenge ARG. The basic aim is to write a script that will read through a mass of text, pass through only the lower-case characters with exactly 3 capitals either side. The script is supposed to look at an incoming character from a list, store the next 3 characte...
0
2016-10-15T14:12:58Z
40,060,248
<p>For starters, you have no variable named limit. Second, it would be easier to use stack type of list. Think of the stack as a stack of papers. You can parse the letters from the file into the stack (using a for loop), but then you can compare each character before it enters the stack, making this module useful for t...
0
2016-10-15T14:29:28Z
[ "python", "python-2.7" ]
kwargs overriding dict subclass
40,060,094
<p>A minimal example is as follows:</p> <pre><code>class sdict(dict): class dval: def __init__(self, val): self.val = val def __init__(self, args): dictionary = dict(args) for k,v in dictionary.items(): self[k] = v def __setitem__(self,key,value): ...
2
2016-10-15T14:15:37Z
40,062,418
<p>Found the answer here, and there should be a way to make this easier to find: <a href="http://stackoverflow.com/questions/19526300/does-argument-unpacking-use-iteration-or-item-getting#19526400">Does argument unpacking use iteration or item-getting?</a></p> <p>Summary: Inheriting from builtins (dict,list...) is pro...
1
2016-10-15T17:59:31Z
[ "python", "dictionary", "kwargs" ]
Navigating through a string and updating the value of string while navigating
40,060,116
<p>I have got the following code in Python (in PyCharm Community Edition):</p> <pre><code>def defer_tags(sentence): for letter in sentence: print(letter) if letter == '&lt;': end_tag = sentence.find('&gt;') sentence = sentence[end_tag+1:] print(sentence) defer_...
0
2016-10-15T14:16:52Z
40,060,327
<p>Better way to catch phrases from tags is just simple to use re.</p> <pre><code>import re def defer_tags(sentence): return re.findall(r'&gt;(.+)&lt;', sentence) defer_tags('&lt;h1&gt;Hello&lt;h1&gt;') &gt; ['Hello'] defer_tags('&lt;h1&gt;Hello&lt;/h1&gt;&lt;h2&gt;Ahoy&lt;/h2&gt;') &gt; ['Hello', 'Ahoy'] </code>...
-1
2016-10-15T14:34:56Z
[ "python", "string", "for-loop" ]
Navigating through a string and updating the value of string while navigating
40,060,116
<p>I have got the following code in Python (in PyCharm Community Edition):</p> <pre><code>def defer_tags(sentence): for letter in sentence: print(letter) if letter == '&lt;': end_tag = sentence.find('&gt;') sentence = sentence[end_tag+1:] print(sentence) defer_...
0
2016-10-15T14:16:52Z
40,061,374
<p>You can use beautiful soup library in python to do the same. please refer to this <a href="http://stackoverflow.com/questions/5598524/can-i-remove-script-tags-with-beautifulsoup">Can I remove script tags with BeautifulSoup?</a> </p>
-1
2016-10-15T16:15:55Z
[ "python", "string", "for-loop" ]
Navigating through a string and updating the value of string while navigating
40,060,116
<p>I have got the following code in Python (in PyCharm Community Edition):</p> <pre><code>def defer_tags(sentence): for letter in sentence: print(letter) if letter == '&lt;': end_tag = sentence.find('&gt;') sentence = sentence[end_tag+1:] print(sentence) defer_...
0
2016-10-15T14:16:52Z
40,070,234
<p>To be explicit, try using beautiful soup following way:</p> <pre><code>&gt;&gt;&gt; from BeautifulSoup import BeautifulSoup &gt;&gt;&gt; soup = BeautifulSoup('&lt;h1&gt;Hello&lt;h1&gt;') &gt;&gt;&gt; soup.text u'Hello' </code></pre>
0
2016-10-16T12:26:14Z
[ "python", "string", "for-loop" ]
working with images in pymongo API
40,060,158
<p>Im doing a pymongo connectivity program that uses python to create a gridfs database on mongodb and adds an image into the database.I've use command line parser to call the methods.I have successfully added the image in the db and it also reflects in the mongodb db but when I call show function it says image not fou...
0
2016-10-15T14:20:31Z
40,085,680
<p>You may need to convert the <code>im_stream</code> to bytes for reading using the <a href="https://docs.python.org/2/library/io.html#buffered-streams" rel="nofollow">BytesIO</a> class.</p> <pre><code>im = Image.open(io.BytesIO(im_stream.read()), 'r') </code></pre>
0
2016-10-17T11:51:00Z
[ "python", "mongodb", "pymongo" ]
Quadratic Formula Solver Error
40,060,179
<p>I'm writing a python quadratic equation solver, and it was working fine, then I ran it another time, and it gave me the following error:</p> <pre><code>Traceback (most recent call last): File "/Users/brinbrody/Desktop/PythonRunnable/QuadraticSolver.py", line 18, in &lt;module&gt; rted = math.sqrt(sqb-ac4) Val...
0
2016-10-15T14:22:38Z
40,060,369
<p>As xli said, this is due to <code>sqb-ac4</code> returning a negative value, and the python math module can't take the square root of a negative value.</p> <p>A way to fix this is:</p> <pre><code>import sys determin = sqb - ac4 if determin &lt; 0: print("Complex roots") sys.exit() else: rted = math.sqr...
0
2016-10-15T14:38:59Z
[ "python", "math.sqrt" ]
Loop only reads 1st line of file
40,060,211
<p>I'm trying to convert a JSON file to XML using a small python script, but for some reason the loop only seems to read the first line of the JSON file. </p> <pre><code>from xml.dom import minidom from json import JSONDecoder import json import sys import csv import os import re import dicttoxml from datetime import ...
0
2016-10-15T14:25:47Z
40,060,517
<p>Try json.load to load the file into a dict and then iterate the dict for your output.</p> <pre><code>import sys import json json_file = sys.argv[1] data = {} with open(json_file) as data_file: data = json.load(data_file) for key in data: #do your things </code></pre>
0
2016-10-15T14:54:50Z
[ "python", "json", "xml", "loops" ]
Django Unitest: Table doesn't exist
40,060,253
<p>I created a simple test case like this:</p> <pre><code>from unittest import TestCase import user_manager class UserTest(TestCase): def test_register(self): email = "dung7@gmail.com" password = "123456" result, user = user_manager.setup_new_user(email, password) self.assertEqual...
-1
2016-10-15T14:29:39Z
40,060,331
<p>Your test database needs to be different than your production database. Test databases are destroyed once the test cases are run. In your case the database was not created. You should go through this documentation for detailed information <a href="https://docs.djangoproject.com/en/1.10/topics/testing/overview/" rel=...
0
2016-10-15T14:35:08Z
[ "python", "mysql", "django", "django-unittest" ]
Django Unitest: Table doesn't exist
40,060,253
<p>I created a simple test case like this:</p> <pre><code>from unittest import TestCase import user_manager class UserTest(TestCase): def test_register(self): email = "dung7@gmail.com" password = "123456" result, user = user_manager.setup_new_user(email, password) self.assertEqual...
-1
2016-10-15T14:29:39Z
40,084,140
<p>So I found out I need to put my models.py in my users folder, and add 'users' into the INSTALL_APPS setting. Now it worked.</p>
0
2016-10-17T10:35:04Z
[ "python", "mysql", "django", "django-unittest" ]
How to color text to later be put in a docx file?
40,060,349
<p>I want to color a text present in the string and pass the string to another python file so that to put received colored string into a docx file. I tried in this way but it is not working.</p> <pre><code>from termcolor import colored from docx import Document document = Document() item_i="\n\n Comma is required in ...
-2
2016-10-15T14:37:11Z
40,060,519
<p>You should be using <code>docx</code>'s text formatting since, as Jacques de Hooge said, <code>termcolor</code> is for terminal. See <a href="http://python-docx.readthedocs.io/en/latest/user/text.html#apply-character-formatting" rel="nofollow">here</a>.</p> <pre><code>from docx.shared import RGBColor </code></pre> ...
2
2016-10-15T14:54:55Z
[ "python", "python-2.7", "python-docx", "termcolor" ]
Not able to install packages in Pycharm
40,060,353
<p>I have pycharm community edition(latest stable build) installed on my Ubuntu 16.04 LTS, I am not able to install packages via pycharm, was able to install them before. I can install the packages via pip, but would like to solve this issue.</p> <p>Below is the Screenshot of the problem</p> <p><a href="https://i.st...
1
2016-10-15T14:37:37Z
40,061,466
<p>I have got a solution, i reffered to <a href="https://youtrack.jetbrains.com/issue/PY-20081#u=1468410176856" rel="nofollow">https://youtrack.jetbrains.com/issue/PY-20081#u=1468410176856</a>.</p> <p>Here they have tried to add <a href="https://pypi.python.org/pypi" rel="nofollow">https://pypi.python.org/pypi</a> as ...
1
2016-10-15T16:23:50Z
[ "python", "pycharm" ]
Weird behaviour when running the script
40,060,380
<p>I started to code a guess the number type of game. When I execute the program, it either flows perfectly, either doesn't work...</p> <pre><code>import random from random import randint print("Welcome to guess the number!\nDo you want to play the game?") question = input("") if question == "Yes".lower(): print("S...
0
2016-10-15T14:40:09Z
40,060,613
<p>Changelog:</p> <p>a) You do not need "import random" as you are importing randint on the line below it.</p> <p>b) lower() is not in the right place as it will not work in inputs that are not all lowercase. It needs to be in the question variable</p> <p>c) You use a while loop so that you keep asking for a guess u...
-1
2016-10-15T15:03:47Z
[ "python", "pycharm" ]
Weird behaviour when running the script
40,060,380
<p>I started to code a guess the number type of game. When I execute the program, it either flows perfectly, either doesn't work...</p> <pre><code>import random from random import randint print("Welcome to guess the number!\nDo you want to play the game?") question = input("") if question == "Yes".lower(): print("S...
0
2016-10-15T14:40:09Z
40,060,672
<p>You really need a while loop. If the first guess is too high then you get another chance, but it then only tests to see if it is too low or equal. If your guess is too low then your second chance has to be correct.</p> <p>So you don't need to keep testing, you can simplify, but you should really do this at the desi...
0
2016-10-15T15:09:15Z
[ "python", "pycharm" ]
Weird behaviour when running the script
40,060,380
<p>I started to code a guess the number type of game. When I execute the program, it either flows perfectly, either doesn't work...</p> <pre><code>import random from random import randint print("Welcome to guess the number!\nDo you want to play the game?") question = input("") if question == "Yes".lower(): print("S...
0
2016-10-15T14:40:09Z
40,061,087
<p>Here is a variation on the 2 themes already offered as answers.<br> In this option the guessing part is defined as a function, which allows us to offer the option of repeatedly playing the game until the user is bored stiff! The other option offered is to not require the user to input "yes" or "no" but simply someth...
0
2016-10-15T15:47:42Z
[ "python", "pycharm" ]
Add quotation at start and end of every other line ignoring empty line
40,060,461
<p>I need help on organizing texts. I have the list of thousands vocabs in csv. There are term, definition, and sample sentence for each word. Term and definition is separated by the tab and sample sentence is separated by an empty line.</p> <p>For example:</p> <pre><code>exacerbate worsen This attack will exacerba...
1
2016-10-15T14:49:56Z
40,060,726
<p>Not necessarily bullet-proof, but this script will do the job based on your example:</p> <pre><code>import sys import re input_file = sys.argv[1] is_definition = True current_entry = "" current_definition = "" for line in open(input_file, 'r'): line = line.strip() if line != "": if is_definitio...
0
2016-10-15T15:14:23Z
[ "python", "regex", "osx", "textedit" ]
Add quotation at start and end of every other line ignoring empty line
40,060,461
<p>I need help on organizing texts. I have the list of thousands vocabs in csv. There are term, definition, and sample sentence for each word. Term and definition is separated by the tab and sample sentence is separated by an empty line.</p> <p>For example:</p> <pre><code>exacerbate worsen This attack will exacerba...
1
2016-10-15T14:49:56Z
40,060,739
<p>Try:</p> <pre><code>suffixList = ["s", "ed", "es", "ing"] #et cetera file = vocab.read() file.split("\n") vocab_words = [file[i] for i in range(0, len(file)-2, 4)] vocab_defs = [file[i] for i in range(2, len(file), 4)] for defCount in range(len(vocab_defs)): vocab_defs[defCount] = "\"" + vocab_defs[defCount] ...
0
2016-10-15T15:15:17Z
[ "python", "regex", "osx", "textedit" ]
Add quotation at start and end of every other line ignoring empty line
40,060,461
<p>I need help on organizing texts. I have the list of thousands vocabs in csv. There are term, definition, and sample sentence for each word. Term and definition is separated by the tab and sample sentence is separated by an empty line.</p> <p>For example:</p> <pre><code>exacerbate worsen This attack will exacerba...
1
2016-10-15T14:49:56Z
40,060,756
<p>Open the terminal to the directory where you have the input file. Save the following code in a <code>.py</code> file:</p> <pre><code>import sys import string import difflib import itertools with open(sys.argv[1]) as fobj: lines = fobj.read().split('\n\n') with open(sys.argv[2], 'w') as out: for i in rang...
1
2016-10-15T15:16:36Z
[ "python", "regex", "osx", "textedit" ]
Add quotation at start and end of every other line ignoring empty line
40,060,461
<p>I need help on organizing texts. I have the list of thousands vocabs in csv. There are term, definition, and sample sentence for each word. Term and definition is separated by the tab and sample sentence is separated by an empty line.</p> <p>For example:</p> <pre><code>exacerbate worsen This attack will exacerba...
1
2016-10-15T14:49:56Z
40,061,125
<pre><code>#!/usr/local/bin/python3 import re with open('yourFile.csv', 'r') as myfile: data = myfile.read() print(re.sub(r'(^[A-Za-z]+)\t(.+)\n\n(.+)\1[s|ed|es|ing]*(.+)$',r'\1\t\2 "\3-\4"', data, flags = re.MULTILINE)) </code></pre> <p>Output:</p> <blockquote> <p>exacerbate worsen "This attack will ...
0
2016-10-15T15:51:16Z
[ "python", "regex", "osx", "textedit" ]
Infinite loop when try to redirect stdout
40,060,556
<p>I'm trying to send stdout to both console and <code>QTextBrowser</code> widget. But I'm getting some kind of infinite loop and then application exits.</p> <p>Here is my code:</p> <pre><code>import sys from PyQt5 import QtWidgets, uic from PyQt5.QtCore import * qtCreatorFile = "qt_ui.ui" Ui_MainWindow, QtBaseClass...
0
2016-10-15T14:58:42Z
40,061,749
<p>Looks like the code you posted is not code you have run, but assuming it is representative, there are two errors: base class of Logger must be inited, and self.log_browser is not defined anywhere. But this does not cause loop, app exits (because there is an exception but no exception hook, see ). Since I don't know ...
0
2016-10-15T16:54:24Z
[ "python", "qt", "python-3.x", "pyqt" ]
Infinite loop when try to redirect stdout
40,060,556
<p>I'm trying to send stdout to both console and <code>QTextBrowser</code> widget. But I'm getting some kind of infinite loop and then application exits.</p> <p>Here is my code:</p> <pre><code>import sys from PyQt5 import QtWidgets, uic from PyQt5.QtCore import * qtCreatorFile = "qt_ui.ui" Ui_MainWindow, QtBaseClass...
0
2016-10-15T14:58:42Z
40,066,161
<p>You could emit a custom signal from <code>Logger</code> and connect it to the log browser:</p> <pre><code>class Logger(QObject): loggerMessage = pyqtSignal(str) def __init__(self): super().__init__() self.terminal = sys.stdout def write(self, message): self.terminal.write(messa...
0
2016-10-16T02:17:38Z
[ "python", "qt", "python-3.x", "pyqt" ]
How to sum all the keys of a dictionary value to the same dictionary value
40,060,568
<p>Let's say I have a dictionary that has {'a' : '0', 'b' : '2', 'a' : '3', 'b' : '5',}</p> <p>I want the dictionary to say {'a' : '3' 'b' : '7'}</p> <p>How would I do this ? </p>
-2
2016-10-15T15:00:00Z
40,060,774
<p>You can't create dictionary which contains the same key twice. The definition of the dictionary is that you can store in it every key-value option only once.</p>
0
2016-10-15T15:17:57Z
[ "python", "dictionary", "key" ]
How to get argparse to read arguments from a file with an option after positional arguments
40,060,571
<p>I would like to be able to put command-line arguments in a file, and then pass them to a python program, with argparse, using an option rather than a prefix character, for instance: <code> $ python myprogram.py 1 2 --foo 1 -A somefile.txt --bar 2 </code> This is almost the same as <a href="http://stackoverflow.com/q...
0
2016-10-15T15:00:14Z
40,062,344
<p>If <code>somefile.txt</code> contains</p> <pre><code>one two three </code></pre> <p>then </p> <pre><code>$ python myprogram.py 1 2 --foo 1 @somefile.txt --bar 2 </code></pre> <p>using the <code>prefix char</code> is effectively the same as</p> <pre><code>$ python myprogram.py 1 2 --foo 1 one two three --bar 2 <...
1
2016-10-15T17:51:09Z
[ "python", "argparse" ]
Dictionary removing duplicate along with subtraction and addition of values
40,060,580
<p>New to python here. I would like to eliminate duplicate dictionary key into just one along with performing arithmetic such as adding/subtracting the values if duplicates are found.</p> <p><strong>Current Code Output</strong></p> <blockquote> <p>{('GRILLED AUSTRALIA ANGU',): (('1',), ('29.00',)), ('Beer', 'Carro...
-2
2016-10-15T15:00:52Z
40,060,730
<p>Working with your current output as posted in the question, you can just <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow"><code>zip</code></a> the different lists of tuples of items and quantities and prices to align the items with each other, add them up in two <code>defaultdicts</code>...
2
2016-10-15T15:14:47Z
[ "python", "dictionary" ]
Python screen capture error
40,060,653
<p>I am trying to modify the code given <a href="https://blog.miguelgrinberg.com/post/video-streaming-with-flask" rel="nofollow">here</a> for screen streaming. In the above tutorial it was for reading images from disk whereas I am trying to take screenshots. I receive this error.</p> <blockquote> <p>assert isinstanc...
0
2016-10-15T15:07:11Z
40,061,207
<p>The response payload must be a sequence of bytes. In the example, the images returned are JPEGs as <code>bytes</code> objects. </p> <p>However, the image returned by <code>ImageGrab.grab()</code> is some PIL image class instead of bytes. So, try saving the image as JPEG as <code>bytes</code>:</p> <pre><code>import...
0
2016-10-15T15:59:07Z
[ "python", "image", "flask" ]
How to input from input direcory folder and save output file in same name as input file in output folder in python
40,060,691
<p>I want to create input directory for my code will take input files from input directory and save same name as input file in output (different folder) directory.</p> <p>Script: </p> <pre><code>import sys import glob import errno import os d = {} chainIDs = ('A', 'B') atomIDs = ('C4B', 'O4B', 'C1B', 'C2B', 'C3B', ...
0
2016-10-15T15:10:53Z
40,060,713
<p>The <code>IndentationError</code> is showing up because you seem to have indented two tabs underneath your <code>with open(doc) as pdbfile:</code> line. </p> <p>Hope this helps! </p>
0
2016-10-15T15:12:58Z
[ "python", "python-2.7", "python-3.x", "bioinformatics" ]
How to input from input direcory folder and save output file in same name as input file in output folder in python
40,060,691
<p>I want to create input directory for my code will take input files from input directory and save same name as input file in output (different folder) directory.</p> <p>Script: </p> <pre><code>import sys import glob import errno import os d = {} chainIDs = ('A', 'B') atomIDs = ('C4B', 'O4B', 'C1B', 'C2B', 'C3B', ...
0
2016-10-15T15:10:53Z
40,060,799
<pre><code>import sys import glob import errno import os d = {} chainIDs = ('A', 'B') atomIDs = ('C4B', 'O4B', 'C1B', 'C2B', 'C3B', 'C4B', 'O4B', 'C1B') count = 0 doc_path=r'C:\Users\Vishnu\Desktop\Test_folder\Input' tar_path=r'C:\Users\Vishnu\Desktop\Test_folder\Output' for doc in os.listdir(doc_path): doc1 = do...
0
2016-10-15T15:20:43Z
[ "python", "python-2.7", "python-3.x", "bioinformatics" ]
scipy.ndimage.interpolate.affine_transform fails
40,060,786
<p>This code:</p> <pre><code>from scipy.ndimage.interpolation import affine_transform import numpy as np ... nzoom = 1.2 newimage = affine_transform(self.image, matrix=np.array([[nzoom, 0],[0, nzoom]])) </code></pre> <p>fails with:</p> <pre><code>RuntimeError: affine matrix has wrong number of rows </code></pre> <p...
0
2016-10-15T15:19:23Z
40,071,123
<p>The reason why the original code does not work with a 2x2 matrix is because the image in question is 3-dimensional. Mind you, the 3rd dimension is<code>[R,G,B]</code>, but <code>scipy.ndimage</code> does not know about non-spatial dimensions; it treats all dimensions as spatial. The examples using 2x2 matrices were ...
0
2016-10-16T13:58:32Z
[ "python", "scipy", "affinetransform" ]
Moving Average- Pandas
40,060,842
<p>I would like to add a moving average calculation to my exchange time series.</p> <p>Original data from Quandl</p> <p>Exchange = Quandl.get("BUNDESBANK/BBEX3_D_SEK_USD_CA_AC_000", authtoken="xxxxxxx")</p> <pre><code> Value Date 1989-01-02 6.10500 1989-01-03 6.07500 1989-01-04 6.10750 1989-01-0...
0
2016-10-15T15:25:31Z
40,060,995
<p>The rolling mean returns a <code>Series</code> you only have to add it as a new column of your <code>DataFrame</code> (<code>MA</code>) as described below. </p> <p>For information, the <code>rolling_mean</code> function has been deprecated in pandas newer versions. I have used the new method in my example, see belo...
2
2016-10-15T15:39:28Z
[ "python", "python-3.x", "pandas", "moving-average" ]
Speed up inserts into SQL Server from pyodbc
40,060,864
<p>In <code>python</code>, I have a process to select data from one database (<code>Redshift</code> via <code>psycopg2</code>), then insert that data into <code>SQL Server</code> (via <code>pyodbc</code>). I chose to do a read / write rather than a read / flat file / load because the row count is around 100,000 per d...
1
2016-10-15T15:27:29Z
40,061,564
<p><s>It's good that you're already using <code>executemany()</code>.</s> [<em>Struck out after reading other answer.</em>] </p> <p>It should speed up a (very little) bit if you move the <code>connect()</code> and <code>cursor()</code> calls for your <code>insert_cnxn</code> and <code>insert_cursor</code> outside of...
0
2016-10-15T16:34:37Z
[ "python", "pyodbc" ]
Speed up inserts into SQL Server from pyodbc
40,060,864
<p>In <code>python</code>, I have a process to select data from one database (<code>Redshift</code> via <code>psycopg2</code>), then insert that data into <code>SQL Server</code> (via <code>pyodbc</code>). I chose to do a read / write rather than a read / flat file / load because the row count is around 100,000 per d...
1
2016-10-15T15:27:29Z
40,065,211
<p>Your code does follow proper form (aside from the few minor tweaks mentioned in the other answer), but be aware that when pyodbc performs an <code>.executemany</code> what it actually does is submit a separate <code>sp_prepexec</code> for each individual row. That is, for the code</p> <pre class="lang-python pretty...
1
2016-10-15T23:18:23Z
[ "python", "pyodbc" ]
recursive subset sum function
40,060,892
<p>Our professor shared the following Python code for our class on recursion. It's a solution for the 'subset sum' problem. </p> <p>I've read it again and again and tried checking it and following the parameters step by step with an online tool, but I just don't get it at all. </p> <p>I understand that the code check...
-1
2016-10-15T15:30:11Z
40,061,404
<h3>Summary</h3> <pre><code>def possible(L,som=0,used=False): if the list is empty: return (is our running sum 0 and have we used at least one element?) else: return (what if we ignore the first element?) or \ (what if we use the first element?) </code></pre> <h3>Basic idea</h3>...
1
2016-10-15T16:18:19Z
[ "python", "subset-sum" ]
Why does list index go out of range when using random module?
40,060,952
<p>I am building a Chatbot and I was able to make it answer to me randomly. I added all the responses in a list and whenever I greet it, It shoots me a random answer. Now this is fine, but sometimes, the program throws an exception - <code>IndexError: list index out of range</code>. I don't understand why the list inde...
0
2016-10-15T15:36:12Z
40,060,974
<p>That is because list indexes start at <code>0</code> and <code>randint</code> will choose a number in the range you specify <code>inclusively</code> with the upper bound. Observe this example: </p> <pre><code>&gt;&gt;&gt; a = [1,2,3] &gt;&gt;&gt; len(a) 3 </code></pre> <p>So, now try to get the value at index <cod...
0
2016-10-15T15:38:12Z
[ "python", "python-3.x", "random" ]
Why does list index go out of range when using random module?
40,060,952
<p>I am building a Chatbot and I was able to make it answer to me randomly. I added all the responses in a list and whenever I greet it, It shoots me a random answer. Now this is fine, but sometimes, the program throws an exception - <code>IndexError: list index out of range</code>. I don't understand why the list inde...
0
2016-10-15T15:36:12Z
40,060,998
<p><code>randint</code> does not act like the rest of Python (for historical reasons relating to other computer languages). In particular, <code>randint()</code> <em>does</em> include the upper bound, unlike Python's list indices and <code>len()</code>.</p> <p>So use <code>randint(0,len(self.AI_Greeted) - 1)</code>.</...
2
2016-10-15T15:39:47Z
[ "python", "python-3.x", "random" ]
How to use a previously trained model to get labels of images - TensorFlow
40,060,983
<p>After training a model (according to the <a href="https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html" rel="nofollow">mnist tutorial</a>), and saving it using this code:</p> <pre><code>saver = tf.train.Saver() save_path = saver.save(sess,'/path/to/model.ckpt') </code></pre> <p>I want to use t...
0
2016-10-15T15:38:43Z
40,062,398
<p>Define an OP for performing classification, like</p> <pre><code>predictor = tf.argmax(y_conv,1) </code></pre> <p>and then run it on trained model with new inputs</p> <pre><code>print(sess.run(predictor, feed_dict={ x = new_data })) </code></pre> <p>since "predictor" does not depend on <code>y</code> you do not h...
2
2016-10-15T17:57:45Z
[ "python", "python-2.7", "machine-learning", "neural-network", "tensorflow" ]
How to use a previously trained model to get labels of images - TensorFlow
40,060,983
<p>After training a model (according to the <a href="https://www.tensorflow.org/versions/r0.11/tutorials/mnist/pros/index.html" rel="nofollow">mnist tutorial</a>), and saving it using this code:</p> <pre><code>saver = tf.train.Saver() save_path = saver.save(sess,'/path/to/model.ckpt') </code></pre> <p>I want to use t...
0
2016-10-15T15:38:43Z
40,062,458
<p>Another option to what lejlot just answered(and this option is primarily for learning and understanding what the network is doing ) could be:You can make predictions using feedforward using the weights and biases that your network already learned that means that al the computations you defined in your "BUILD AND ...
-1
2016-10-15T18:03:46Z
[ "python", "python-2.7", "machine-learning", "neural-network", "tensorflow" ]
Keep pandas matplotlib plot open after code completes
40,061,044
<p>I am using pandas builtin plotting as per below. However as soon as the plotting method returns, the plot disappears. How can I keep the plot(s) open until I click on them to close?</p> <pre><code>import matplotlib matplotlib.use('TkAgg') import matplotlib.pyplot as plt def plot_data(): #...create dataframe df...
0
2016-10-15T15:44:22Z
40,061,180
<p>Use a <code>plt.show(block=True)</code> command to keep the plotting windows open.</p> <pre><code>[...] df1.boxplot() df1.hist() plt.show(block=True) </code></pre> <p>In my version of matplotlib (1.4.3), <code>block=True</code> is necessary, but that may not be the case for all versions (<a href="http://stackoverf...
2
2016-10-15T15:56:47Z
[ "python", "pandas", "matplotlib" ]
Python Flask: Go from Swagger YAML to Google App Engine?
40,061,085
<p>I have used the Swagger Editor to create a REST API and I have requested the server code download for Python Flask. I'm trying to deploy this out to Google Cloud Platform (I think that's the latest name? Or is it still GAE?) but I need to fill in some gaps. </p> <p>I know the Swagger code works because I have deplo...
0
2016-10-15T15:47:31Z
40,078,854
<p>You seem to have some inconsistencies in your file, it's unclear if you intended it to be a <a href="https://cloud.google.com/appengine/docs/python/config/appref" rel="nofollow">standard environment <code>app.yaml</code> file</a> or a <a href="https://cloud.google.com/appengine/docs/flexible/python/runtime#overview"...
0
2016-10-17T05:08:58Z
[ "python", "google-app-engine", "flask", "swagger", "google-cloud-platform" ]
pysd library ParseError
40,061,091
<p>I'm using a library called <code>pysd</code> to translate <code>vensim</code> files to Python, but when I try to do it (library functions) I get a parse error but don't understand what it means.</p> <p>This is my log.</p> <hr> <pre class="lang-none prettyprint-override"><code>ParseError ...
-1
2016-10-15T15:48:15Z
40,115,778
<p><code>.itmx</code> is an iThink extension, which unfortunately PySD doesn't support (yet). In the future, we'll work out a conversion pathway that lets you bring these in. </p>
0
2016-10-18T18:44:03Z
[ "python" ]
awkward lambda function
40,061,106
<p>I cannot find out what <code>key=key</code> does in this simple python code:</p> <pre><code>for key in dict: f = (lambda key=key: print(key)) print(f()) </code></pre>
1
2016-10-15T15:50:11Z
40,061,165
<p>The first key in 'key=key' is the name of the argument of the lambda function. The second key is a local variable, in your case the for loop variable. </p> <p>So, in each iteration a local key variable is defined, then f is defined as a lambda function receiving one argument with a default the same as this local - ...
0
2016-10-15T15:55:41Z
[ "python" ]
awkward lambda function
40,061,106
<p>I cannot find out what <code>key=key</code> does in this simple python code:</p> <pre><code>for key in dict: f = (lambda key=key: print(key)) print(f()) </code></pre>
1
2016-10-15T15:50:11Z
40,061,324
<p>In <em>this</em> piece of code, <code>key=key</code> does nothing useful at all. You can just as well write the loop as </p> <pre><code>for key in [1,2,3]: f = lambda: key print(f()) </code></pre> <p>This will print <code>1</code>, <code>2</code>, and <code>3</code>. (Note that -- unrelated to the problem ...
3
2016-10-15T16:10:35Z
[ "python" ]
awkward lambda function
40,061,106
<p>I cannot find out what <code>key=key</code> does in this simple python code:</p> <pre><code>for key in dict: f = (lambda key=key: print(key)) print(f()) </code></pre>
1
2016-10-15T15:50:11Z
40,061,471
<p>This code is not "simple", it's actually somewhat tricky to understand for a Python novice.</p> <p>The <code>for key in dict:</code> simply loops over what <code>dict</code> is. Normally <code>dict</code> is a predefined system library class (the class of standard dictionaries) and iterating over a class object is ...
2
2016-10-15T16:24:10Z
[ "python" ]
If strings are immutable, then how is this possible?
40,061,167
<p>I am new to python and was going through the python3 docs. In python strings are said to be immutable, then how is this possible:</p> <pre><code>if __name__ == '__main__': l = 'string' print(l) l = l[:2] print(l) </code></pre> <p>returns this output:</p> <pre><code>string st </code...
1
2016-10-15T15:55:43Z
40,061,182
<p>Informally, <code>l</code> now points to a new immutable string, which is a copy of a part of the old one.</p> <p>What you cannot do is modify a string in place. </p> <pre><code>a = "hello" a[0] = "b" # not allowed to modify the string `a` is referencing; raises TypeError print(a) # not reached, since we got an...
3
2016-10-15T15:57:03Z
[ "python", "python-3.x", "immutability" ]
If strings are immutable, then how is this possible?
40,061,167
<p>I am new to python and was going through the python3 docs. In python strings are said to be immutable, then how is this possible:</p> <pre><code>if __name__ == '__main__': l = 'string' print(l) l = l[:2] print(l) </code></pre> <p>returns this output:</p> <pre><code>string st </code...
1
2016-10-15T15:55:43Z
40,061,230
<p>The key to understand this problem is to realize that variable in Python is just a "pointer" pointing to an underlying object. And you confused the concept of immutable object and immutable variable(which does not exist in Python).</p> <p>For instance, in your case, <code>l</code> was initially a pointer pointing t...
2
2016-10-15T16:01:28Z
[ "python", "python-3.x", "immutability" ]
Easiest way to return sum of a matrix's neighbors in numpy
40,061,185
<p>I am trying to make a program that needs a matrix's neighbor(excluding itself) sum ex:</p> <pre><code> matrix([[0, 0, 0], [1, 0, 1], [0, 1, 0]]) </code></pre> <p>would return:</p> <pre><code>matrix([[1, 2, 1], [1, 3, 1], [2, 2, 2]]) </code></pre> <p>I have a working code here bu...
3
2016-10-15T15:57:26Z
40,061,601
<p>You are summing all values in that <code>3x3</code> neighbourhood, but excluding the element itself. So, we can use <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve2d.html" rel="nofollow"><code>Scipy's 2D convolution</code></a> and subtract that input array/matrix from it for the de...
3
2016-10-15T16:38:20Z
[ "python", "python-3.x", "numpy", "matrix", "scipy" ]
Easiest way to return sum of a matrix's neighbors in numpy
40,061,185
<p>I am trying to make a program that needs a matrix's neighbor(excluding itself) sum ex:</p> <pre><code> matrix([[0, 0, 0], [1, 0, 1], [0, 1, 0]]) </code></pre> <p>would return:</p> <pre><code>matrix([[1, 2, 1], [1, 3, 1], [2, 2, 2]]) </code></pre> <p>I have a working code here bu...
3
2016-10-15T15:57:26Z
40,062,334
<p>Define a function which computes the sum of all neighbors for a matrix entry, if they exist:</p> <pre><code>def sumNeighbors(M,x,y): l = [] for i in range(max(0,x-1),x+2): # max(0,x-1), such that no negative values in range() for j in range(max(0,y-1),y+2): try: t = M[i]...
1
2016-10-15T17:50:25Z
[ "python", "python-3.x", "numpy", "matrix", "scipy" ]
Why can yield be indexed?
40,061,280
<p>I thought I could make my python (2.7.10) code simpler by directly accessing the index of a value passed to a generator via <code>send</code>, and was surprised the code ran. I then discovered an index applied to <code>yield</code> doesn't really do anything, nor does it throw an exception:</p> <pre><code>def gen1(...
6
2016-10-15T16:06:41Z
40,061,337
<p>You are not indexing. You are yielding a list; the expression <code>yield[0]</code> is really just the same as the following (but without a variable):</p> <pre><code>lst = [0] yield lst </code></pre> <p>If you look at what <code>next()</code> returned you'd have gotten that list:</p> <pre><code>&gt;&gt;&gt; def g...
12
2016-10-15T16:11:49Z
[ "python", "python-2.7", "indexing", "generator", "yield" ]
Automate students tests run
40,061,297
<p>I have a folders structure for some tasks, they are like this:</p> <pre><code>- student_id1/answers.py - student_id2/answers.py - student_id3/answers.py - student_id4/answers.py - ... </code></pre> <p>I have a main file: <code>run_tests.py</code>:</p> <pre><code>from student_id1.answers import run_test as test1 f...
4
2016-10-15T16:08:14Z
40,061,352
<p>You can use <code>importlib</code> module: <a href="https://docs.python.org/3/library/importlib.html" rel="nofollow">https://docs.python.org/3/library/importlib.html</a></p> <pre><code>import os import importlib for student_dir in os.listdir(): if os.path.isdir(student_dir): # here you may add an addit...
3
2016-10-15T16:13:21Z
[ "python" ]
Comparatively slow python numpy 3D Fourier Transformation
40,061,307
<p>Dear StackOverflow community!</p> <p>For my work I need to perform discrete fourier transformations (DFTs) on large images. In the current example I require a 3D FT for a 1921 x 512 x 512 image (along with 2D FFTs of 512 x 512 images). Right now, I am using the numpy package and the associated function <a href="htt...
4
2016-10-15T16:08:54Z
40,064,319
<p>Yes, there is a chance that using FFTW through the interface <code>pyfftw</code> will reduce your computation time compared to <code>numpy.fft</code> or <code>scipy.fftpack</code>. The performances of these implementations of DFT algorithms can be compared in benchmarks such as <a href="https://gist.github.com/fniel...
2
2016-10-15T21:17:53Z
[ "python", "performance", "numpy", "fft" ]
Creating a Django model that can have a many-to-many relationship with itself
40,061,325
<p>I'm trying to write a Django model that can have a many-to-many relationship with itself.</p> <p>This is my <strong>models.py</strong>:</p> <pre><code>class Apps(models.Model): name = models.CharField( verbose_name = 'App Name', max_length = 30 ) logo = models.ImageField( verbos...
0
2016-10-15T16:10:35Z
40,061,917
<p>This has just got through <code>makemigrations</code> and I'm going to test it:</p> <pre><code>class App(models.Model): name = models.CharField( verbose_name = 'App Name', max_length = 30 ) logo = models.ImageField( verbose_name = 'Logo' ) description = mod...
0
2016-10-15T17:09:18Z
[ "python", "django" ]
MQTT Client not receiving messages
40,061,342
<p>I'm using the following code from MQTT Paho project to subscribe to messages from my mqtt broker. I tested the connection using <code>mosquitto_sub</code> and I receive the messages there. However, when I run the following code it doesn't receive any messages and no output is printed. I checked the topic and host.</...
0
2016-10-15T16:12:07Z
40,061,644
<p>This is most likely because you are using an old version of mosquitto and the python is expecting a newer build that supports MQTT 3.1.1</p> <p>Try changing the code as shown:</p> <pre><code>import paho.mqtt.client as mqtt # The callback for when the client receives a CONNACK response from the server. def on_conn...
1
2016-10-15T16:43:29Z
[ "python", "publish-subscribe", "mqtt" ]
Scatterplot of two Pandas Series, coloured by date and with legend
40,061,493
<p>I am studying financial time series, in the format of pandas series. To compare two series I do a scatterplot, and to visualise the time evolution in the scatterplot I can colour them. This is all fine.</p> <p>My question relates to the legend showing the colours. I would like the legend to show the date/year that ...
0
2016-10-15T16:27:48Z
40,065,339
<p>While there might be an easier answer out there (anyone?), to me the most straightforward way is to change the colorbar ticks manually. </p> <p>Try the following before you invoke <code>plt.show()</code>:</p> <pre><code>clb = plt.gci().colorbar # get the colorbar artist # get the old tick labels (index numbers of ...
0
2016-10-15T23:40:00Z
[ "python", "pandas", "matplotlib", "legend", "series" ]
How to get n variables in one line?
40,061,538
<p>I have a number <strong>n</strong> and I need to get from a user <strong>n</strong> variables in one line.</p> <p>As far as i know, it's pretty easy to do if you know exactly how many variables you have.</p> <pre><code>*variables* = map(int, input().split()) </code></pre> <p>But if I don't know how many variables...
1
2016-10-15T16:31:50Z
40,061,602
<p>User input being taken as a space separated string: </p> <pre><code>1 2 3 4 5 </code></pre> <p>This being the code you are dealing with: </p> <pre><code>map(int, input().split()) </code></pre> <p>Stating you need a list, then just store it in a single variable: </p> <pre><code>inputs = map(int, input().split())...
2
2016-10-15T16:38:26Z
[ "python" ]
Using other file names than models.py for Django models?
40,061,555
<p>When creating a reusable app, should I put all models I define into single file <code>models.py</code> or can I group the models into several files like <code>topic1.py</code>, <code>topic2.py</code>?</p> <p>Please describe all reasons pro and contra.</p>
0
2016-10-15T16:33:52Z
40,061,691
<p>The <code>models</code> submodule is special in that it is automatically imported at a specific time during the initialization process. All your models should be imported at this time as well. You can't import them earlier than that, and importing them later may cause errors. </p> <p>You can define your models in a...
1
2016-10-15T16:47:26Z
[ "python", "django", "model" ]
Using other file names than models.py for Django models?
40,061,555
<p>When creating a reusable app, should I put all models I define into single file <code>models.py</code> or can I group the models into several files like <code>topic1.py</code>, <code>topic2.py</code>?</p> <p>Please describe all reasons pro and contra.</p>
0
2016-10-15T16:33:52Z
40,061,752
<p>it depend how much model you define, if you have only 1 to 5 class model, just put it into single file, but if you have more than 5 class model, i suggesting put it on several files,</p> <p>but in my experience, if the model put in a serveral files, it become little cumbersome when it comes to importing stuff,</p>
0
2016-10-15T16:54:35Z
[ "python", "django", "model" ]
Call field from inherited model Odoo v9 community
40,061,786
<p>Let me explain what I'm trying to do.</p> <p>On <code>stock</code> module, when You navigate to whatever operation (picking) type, being it a tree or form view, some of the fields that are shown are from <code>product.product</code>, like, for example <code>name</code>.</p> <p>Now, the model <code>product.product<...
0
2016-10-15T16:57:00Z
40,062,099
<p>Try with following code:</p> <p>Replace</p> <pre><code>price_unit = fields.Float( digits_compute=dp.get_precision('Product Price'), string='Price') </code></pre> <p>with</p> <pre><code>price_unit = fields.Float(string='Price', digits=dp.get_precision('Product Price')) </code></pre> <p>And write below line in im...
1
2016-10-15T17:27:57Z
[ "python", "inheritance", "openerp", "odoo-9" ]
Python requests add extra headers to HTTP GET
40,061,869
<p>I am using python 2.7 requests module.</p> <p>I made this HTTP GET with the custom header below;</p> <pre><code>header ={ "projectName": "zhikovapp", "Authorization": "Bearer HZCdsf=" } response = requests.get(bl_url, headers = header) </code></pre> <p>The server returns a response...
0
2016-10-15T17:04:39Z
40,061,938
<p>you can do a prepared request.</p> <p><a href="http://docs.python-requests.org/en/latest/user/advanced/#prepared-requests" rel="nofollow">http://docs.python-requests.org/en/latest/user/advanced/#prepared-requests</a></p> <p>then you can delete the headers manually</p> <pre><code>del prepped.headers['Content-Type'...
1
2016-10-15T17:11:52Z
[ "python", "python-2.7", "http-headers", "python-requests" ]
Read the contents of each file into a separate list in Python
40,061,884
<p>I would like to ready the contents of each file into a separate list in Python. I am used to being able to do something similar with a bash for loop where I can say:</p> <pre><code>for i in file_path; do writing stuff; done </code></pre> <p>With glob I can load each of the files but I want to save the contents in...
0
2016-10-15T17:06:06Z
40,062,023
<pre><code>import sys import glob import errno list_$name[] ##&lt;this is not python path = './dir_name/*' files = glob.glob(path) contents = [] for name in files: try: with open(name) as f: lines = f.read().splitlines() contents.append (lines) except IOError as exc: ...
1
2016-10-15T17:21:35Z
[ "python", "bash", "list", "glob" ]
Problems mapping a series to a min(list, key=lambda x: abs(series)) function
40,061,889
<p>I want to find a number in <code>series</code>, and find which number it's closest to in <code>[1,2,3]</code>. Then use the <code>key</code> to replace the series value with the appropriate letter.</p> <pre><code>key = {1: 'A', 2:'B', 3:'C') series = pd.Series([x*1.2 for x in range(10)]) pd.DataFrame = key[min([1...
1
2016-10-15T17:06:28Z
40,062,008
<p>use the <code>apply</code> method and then <code>map</code> your <code>Series</code> such has:</p> <pre><code>key = {1: 'A', 2:'B', 3:'C'} series = pd.Series([x*1.2 for x in range(10)]) def find(myNumber): return min([1,2,3], key=lambda x:abs(x-myNumber)) series.apply(find).map(key) Out[50]: 0 A 1 A 2 ...
1
2016-10-15T17:19:29Z
[ "python", "pandas", "numpy", "dataframe", "series" ]
Python decorator that returns a function with one or more arguments replaced
40,061,956
<p>I would like to create a decorator to a set of functions that replaces one or more of the arguments of the functions. The first thought that came to my mind was to create a decorator that returns a partial of the function with the replaced arguments. I'm unhappy with the way the decorated function is called, but eve...
0
2016-10-15T17:13:14Z
40,061,972
<p>You'd have to return the partial as the decoration result:</p> <pre><code>def decor(func): return partial(func, v=100) </code></pre> <p>However, this <em>always</em> sets <code>v=100</code>, even if you passed in another value for <code>v</code> by position. You'd still have the same issue.</p> <p>You'd need ...
2
2016-10-15T17:15:33Z
[ "python", "decorator", "partial", "python-decorators" ]
Patch method only in one module
40,062,073
<p>For example, I have some module(<code>foo.py</code>) with next code:</p> <pre><code>import requests def get_ip(): return requests.get('http://jsonip.com/').content </code></pre> <p>And module <code>bar.py</code> with similiar code:</p> <pre><code>import requests def get_fb(): return requests.get('https:...
1
2016-10-15T17:25:53Z
40,062,556
<p>The two locations <code>foo.requests.get</code> and <code>bar.requests.get</code> refer to the same object, so mock it in one place and you mock it in the other. </p> <p>Imagine how you might implement patch. You have to find where the symbol is located and replace the symbol with the mock object. On exit from t...
2
2016-10-15T18:13:25Z
[ "python", "python-3.x", "python-unittest", "python-mock", "python-unittest.mock" ]
Patch method only in one module
40,062,073
<p>For example, I have some module(<code>foo.py</code>) with next code:</p> <pre><code>import requests def get_ip(): return requests.get('http://jsonip.com/').content </code></pre> <p>And module <code>bar.py</code> with similiar code:</p> <pre><code>import requests def get_fb(): return requests.get('https:...
1
2016-10-15T17:25:53Z
40,062,863
<p>Not to steal <strong>@Neapolitan</strong>'s thunder, but another option would be to simply mock <code>foo.requests</code> instead of <code>foo.requests.get</code>:</p> <pre><code>with patch('foo.requests'): print(get_ip()) print(get_fb()) </code></pre> <p>I think the reason why both methods get mocked in y...
0
2016-10-15T18:44:20Z
[ "python", "python-3.x", "python-unittest", "python-mock", "python-unittest.mock" ]
Mapping in Python
40,062,085
<p>I have at my dispositions a JSON list with all the bike stations called Velib in Paris with their latitude, longitude, number of bikes and capacity. </p> <p>I am trying to calculate proportion <code>averages(number_of_bikes/bike_capacity)</code> of the number of bikes for the bike stations in different districts of...
1
2016-10-15T17:26:30Z
40,062,166
<p>You'll need an approximate contour map of your districts, so the boundaries of the districts as a number of e.g. straight line segments. And then you need a way to find out if you're inside such a closed contour.</p> <p>You'll find how to do that <a href="https://www.quora.com/How-do-I-know-a-point-is-inside-a-clos...
1
2016-10-15T17:34:01Z
[ "python", "mapping", "geocoding", "reverse-geocoding" ]
Mapping in Python
40,062,085
<p>I have at my dispositions a JSON list with all the bike stations called Velib in Paris with their latitude, longitude, number of bikes and capacity. </p> <p>I am trying to calculate proportion <code>averages(number_of_bikes/bike_capacity)</code> of the number of bikes for the bike stations in different districts of...
1
2016-10-15T17:26:30Z
40,062,204
<p>If you can find the coordinates for the vertices of a polygon that approximates Paris' districts, then this reduces to a <a href="https://en.wikipedia.org/wiki/Point_in_polygon" rel="nofollow">point-in-polygon</a> problem. You can use the ray-casting or the winding number algorithm to solve it, as mentioned in that ...
1
2016-10-15T17:37:22Z
[ "python", "mapping", "geocoding", "reverse-geocoding" ]
Mapping in Python
40,062,085
<p>I have at my dispositions a JSON list with all the bike stations called Velib in Paris with their latitude, longitude, number of bikes and capacity. </p> <p>I am trying to calculate proportion <code>averages(number_of_bikes/bike_capacity)</code> of the number of bikes for the bike stations in different districts of...
1
2016-10-15T17:26:30Z
40,062,239
<p>You can do get the district information by coordinate using Google's geocoding API</p> <p><a href="https://maps.googleapis.com/maps/api/geocode/json?latlng=48.874809,2.396988" rel="nofollow">https://maps.googleapis.com/maps/api/geocode/json?latlng=48.874809,2.396988</a></p> <p>In the response:</p> <pre><code>{ ...
2
2016-10-15T17:41:09Z
[ "python", "mapping", "geocoding", "reverse-geocoding" ]
Can the SoundCloud API be accessed from Windows directly (with a python script, say) or must it be an internet application run from a server?
40,062,189
<p>I'm looking to put together something that automatically uploads songs to SoundCloud and it would be really easy if I could integrate it with my current project by just executing a python script. </p> <p>I don't need an Apache server or something along those lines to run it from, do I?</p>
1
2016-10-15T17:36:15Z
40,062,223
<p>That is possible with Javascript, Python, or ruby (you listed these in the tags, but you can pretty much use anything).</p> <p>To read more about using the API to upload sounds see <a href="https://developers.soundcloud.com/docs/api/guide#uploading" rel="nofollow">this section of the documentation</a>.</p> <p>You ...
1
2016-10-15T17:39:18Z
[ "javascript", "python", "ruby", "apache", "soundcloud" ]
What is difference between if (False,) and True == (False,)
40,062,285
<p>I learned python 3 last year, but I have barely experience.</p> <p>I am reviewing about tuple again.</p> <p>I would like to figure out difference between <code>if (False,)</code> and <code>True == (False,)</code></p> <p>Since <code>if (False,):</code> is true, but <code>True == (False,)</code> is false, I am ver...
0
2016-10-15T17:46:01Z
40,062,309
<ol> <li><p>The boolean value of a tuple is <code>True</code> if it has contents, if it is empty it is <code>False</code>. Because <code>(False,)</code> is a tuple with one element it's boolean value is <code>True</code>.</p></li> <li><p>You are comparing a <code>tuple</code> to a <code>bool</code>, that will always re...
1
2016-10-15T17:48:16Z
[ "python", "tuples" ]
What is difference between if (False,) and True == (False,)
40,062,285
<p>I learned python 3 last year, but I have barely experience.</p> <p>I am reviewing about tuple again.</p> <p>I would like to figure out difference between <code>if (False,)</code> and <code>True == (False,)</code></p> <p>Since <code>if (False,):</code> is true, but <code>True == (False,)</code> is false, I am ver...
0
2016-10-15T17:46:01Z
40,062,333
<p><code>if</code> does not test for <code>== True</code>. It tests for the <a href="https://docs.python.org/3/library/stdtypes.html#truth-value-testing" rel="nofollow"><em>truth value</em></a> of an object:</p> <blockquote> <p>Any object can be tested for truth value, for use in an <code>if</code> or <code>while</c...
5
2016-10-15T17:50:17Z
[ "python", "tuples" ]
What is difference between if (False,) and True == (False,)
40,062,285
<p>I learned python 3 last year, but I have barely experience.</p> <p>I am reviewing about tuple again.</p> <p>I would like to figure out difference between <code>if (False,)</code> and <code>True == (False,)</code></p> <p>Since <code>if (False,):</code> is true, but <code>True == (False,)</code> is false, I am ver...
0
2016-10-15T17:46:01Z
40,062,362
<p>Perhaps this highlights the difference. </p> <p><code>if (False,):</code> will <em>evaluate</em> because a non-empty tuple is a truth-y value. It is not true itself. And comparing a tuple against a boolean shouldn't be expected to return true in any case, regardless of the content of said tuple. </p> <pre><code>t ...
1
2016-10-15T17:53:16Z
[ "python", "tuples" ]
What is difference between if (False,) and True == (False,)
40,062,285
<p>I learned python 3 last year, but I have barely experience.</p> <p>I am reviewing about tuple again.</p> <p>I would like to figure out difference between <code>if (False,)</code> and <code>True == (False,)</code></p> <p>Since <code>if (False,):</code> is true, but <code>True == (False,)</code> is false, I am ver...
0
2016-10-15T17:46:01Z
40,062,381
<p>For any <code>x</code> whatsoever,</p> <pre><code>if (x,): </code></pre> <p>succeeds, because <code>(x,)</code> is a non-empty tuple, and all non-empty tuples evaluate to <code>True</code> in a boolean context.</p> <p>And again for any <code>x</code> whatsoever,</p> <pre><code>if True == (x,): </code></pre> <p>...
0
2016-10-15T17:55:39Z
[ "python", "tuples" ]
What is difference between if (False,) and True == (False,)
40,062,285
<p>I learned python 3 last year, but I have barely experience.</p> <p>I am reviewing about tuple again.</p> <p>I would like to figure out difference between <code>if (False,)</code> and <code>True == (False,)</code></p> <p>Since <code>if (False,):</code> is true, but <code>True == (False,)</code> is false, I am ver...
0
2016-10-15T17:46:01Z
40,062,499
<p>Not empty values are equivalent to <code>True</code> while empty values are equivalent to <code>False</code>. The tuple <code>(False,)</code> is not an empty tuple so <code>if (False,)</code> always succeeds. On the other hand <code>True</code> is not equal to the singleton tuple <code>(False,)</code> so the logical...
1
2016-10-15T18:08:34Z
[ "python", "tuples" ]
How many times a button is clicked?
40,062,388
<p>How to know how many times a button is clicked in pyqt ? where ui is prepared in qt-designer and imported into python as .ui file.</p> <p>Example:</p> <pre><code>self.submit.clicked.connect(self.submit_application) </code></pre> <p>and in </p> <pre><code>def submit_application: </code></pre> <p>how to know tha...
0
2016-10-15T17:56:31Z
40,062,522
<p>Assuming your <em>self</em> is a parent widget, you may add a counter member which will be updated any time the slot is called. Something like:</p> <pre><code>class MyWidget(QWidget): def __init__(*args, **kwargs): ... #Your widget initialization, including *sumbit* button self.submit.clicked.co...
0
2016-10-15T18:10:03Z
[ "python", "pyqt", "pyqt4", "qt-designer" ]
Updating properties of an object in Python OOP
40,062,498
<p>I am trying to create a simple game in Python using the OOP style. The parent class is set up and there are two sub-classes, one for the hero and one for the ork.</p> <p>Basically, when the hero attacks the ork (or vice versa) I want the health to be updated based on the damage done (damage is the amount of power t...
-1
2016-10-15T18:08:28Z
40,062,730
<p>A quick fix to your code. Remove all these unecessary attributes, e.g. <code>self.attacker</code> (that's just <code>self</code>), <code>self.attackPower</code> (that's just <code>self.power</code>). <code>self.victim = attackObj.character</code> just gives your object a new attribute that is the same string as what...
0
2016-10-15T18:30:16Z
[ "python", "oop" ]
How to convert an input to string
40,062,536
<pre><code>while n == 1: w = inputs.append(input('Enter the product code: ')) with open('items.txt') as f: found = False for line in f: if w in line: </code></pre> <p>So this is the part of the code with the issue. After the last line a bunch of stuff happens which is irrelevant t...
0
2016-10-15T18:11:14Z
40,062,629
<p><a href="https://docs.python.org/3/library/functions.html#input" rel="nofollow"><code>input()</code></a> already returns a string, so there is no need to convert it.</p> <p>You have this:</p> <pre><code>w = inputs.append(input('Enter the product code: ')) </code></pre> <p>You should be doing this in two steps, s...
1
2016-10-15T18:20:08Z
[ "python" ]
Simulate Python interactive mode
40,062,539
<p>Im writing a private online Python interpreter for <a href="http://vk.com" rel="nofollow">VK</a>, which would closely simulate IDLE console. Only me and some people in whitelist would be able to use this feature, no unsafe code which can harm my server. But I have a little problem. For example, I send the string wit...
1
2016-10-15T18:11:33Z
40,074,450
<p>It boils down to reading input, then</p> <pre><code>exec &lt;code&gt; in globals,locals </code></pre> <p>in an infinite loop.</p> <p>See e.g. <a href="https://github.com/ipython/ipython/blob/master/IPython/terminal/interactiveshell.py#L444" rel="nofollow"><code>IPython.frontend.terminal.console.interactiveshell.T...
2
2016-10-16T19:22:45Z
[ "python", "read-eval-print-loop", "simulate" ]
Simulate Python interactive mode
40,062,539
<p>Im writing a private online Python interpreter for <a href="http://vk.com" rel="nofollow">VK</a>, which would closely simulate IDLE console. Only me and some people in whitelist would be able to use this feature, no unsafe code which can harm my server. But I have a little problem. For example, I send the string wit...
1
2016-10-15T18:11:33Z
40,074,632
<p>The Python standard library provides the <a href="https://docs.python.org/2/library/code.html" rel="nofollow"><code>code</code></a> and <a href="https://docs.python.org/2/library/codeop.html" rel="nofollow"><code>codeop</code></a> modules to help you with this. The <code>code</code> module just straight-up simulates...
2
2016-10-16T19:39:49Z
[ "python", "read-eval-print-loop", "simulate" ]
sqlalchemy database creation error
40,062,544
<p>I have a project i am working on and i am getting a small error that is preventing me from creating all the tables and my database. I am getting the following error:</p> <pre><code>vagrant@vagrant-ubuntu-trusty-32:/vagrant/PayUp$ python setup_database.py Traceback (most recent call last): File "setup_database.py"...
0
2016-10-15T18:11:54Z
40,062,610
<p>Have you tried replacing __table__ with __tablename__</p> <p><a href="http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/table_config.html" rel="nofollow">http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/table_config.html</a></p>
1
2016-10-15T18:18:33Z
[ "python", "database", "sqlite", "sqlalchemy" ]
CSV to Excel conversion using Python
40,062,576
<p>I wrote a piece of code that parse a .csv and save the data in excel format. The problem is that all my data in excel appear as "number stored as text" and i need the data starting with column 3 to be converted as number type so i can represent it using a chart. My table is looking something like this:</p> <pre><co...
0
2016-10-15T18:15:33Z
40,062,801
<p>Does your CSV file contain numeric elements that are in quotation marks? If so, that would result in what you're seeing. For example, consider this:</p> <pre><code>import openpyxl wb = openpyxl.Workbook() ws = wb.active for i in [['100', 100]]: ws.append(i) wb.save("excel_file.xlsx") </code></pre> <p>The <...
0
2016-10-15T18:38:32Z
[ "python", "excel", "csv", "openpyxl" ]
CSV to Excel conversion using Python
40,062,576
<p>I wrote a piece of code that parse a .csv and save the data in excel format. The problem is that all my data in excel appear as "number stored as text" and i need the data starting with column 3 to be converted as number type so i can represent it using a chart. My table is looking something like this:</p> <pre><co...
0
2016-10-15T18:15:33Z
40,062,807
<p>I suggest to use pandas pandas.read_csv and pandas.to_excel</p>
-3
2016-10-15T18:38:58Z
[ "python", "excel", "csv", "openpyxl" ]
CSV to Excel conversion using Python
40,062,576
<p>I wrote a piece of code that parse a .csv and save the data in excel format. The problem is that all my data in excel appear as "number stored as text" and i need the data starting with column 3 to be converted as number type so i can represent it using a chart. My table is looking something like this:</p> <pre><co...
0
2016-10-15T18:15:33Z
40,062,817
<p>If you haven't defined what column is a float, you can try to convert the value to float with an exception handler. The code could become:</p> <pre><code>reader = csv.reader(f, delimiter=',') for i in reader: try: ws.append(float(i)) except ValueError: ws.append(i) f.close() </code></pre>
1
2016-10-15T18:39:44Z
[ "python", "excel", "csv", "openpyxl" ]
how to print this pattern using python iterator
40,062,584
<pre><code>L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] head = 'head' tail = 'tail' </code></pre> <p>suppose we can and can only get the iterator of some iterable(L). and we can not know the length of L. Is that possible to print the iterable as:</p> <pre><code>'head123tail' 'head456tail' 'head789tail' 'head10tail' </code><...
0
2016-10-15T18:16:00Z
40,062,691
<p>Here's one way to do it with <a href="https://docs.python.org/3/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> and <a href="https://docs.python.org/3/library/itertools.html#itertools.count" rel="nofollow"><code>itertools.count</code></a>. </p> <p><code>groupby</code> on ...
2
2016-10-15T18:26:19Z
[ "python" ]
how to print this pattern using python iterator
40,062,584
<pre><code>L = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] head = 'head' tail = 'tail' </code></pre> <p>suppose we can and can only get the iterator of some iterable(L). and we can not know the length of L. Is that possible to print the iterable as:</p> <pre><code>'head123tail' 'head456tail' 'head789tail' 'head10tail' </code><...
0
2016-10-15T18:16:00Z
40,062,742
<p>You can <a href="http://stackoverflow.com/a/24527424/1639625">split the iterator into chunks</a> of three, using <code>chain</code> and <code>slice</code> from <code>itertools</code> and a <code>for</code> loop, and then join them. The <code>for</code> loop will do most of what your <code>try/while True/except</code...
1
2016-10-15T18:31:15Z
[ "python" ]
Drop duplicates for rows with interchangeable name values (Pandas, Python)
40,062,621
<p>I have a DataFrame of form</p> <pre><code>person1, person2, ..., someMetric John, Steve, ..., 20 Peter, Larry, ..., 12 Steve, John, ..., 20 </code></pre> <p>Rows 0 and 2 are interchangeable duplicates, so I'd want to drop the last row. I can't figure out how to do this in Pandas.</p> <p>Thanks!</p>
2
2016-10-15T18:19:16Z
40,062,776
<p>Here's a NumPy based solution -</p> <pre><code>df[~(np.triu(df.person1.values[:,None] == df.person2.values)).any(0)] </code></pre> <p>Sample run -</p> <pre><code>In [123]: df Out[123]: person1 person2 someMetric 0 John Steve 20 1 Peter Larry 13 2 Steve John 19 3 Peter ...
2
2016-10-15T18:35:18Z
[ "python", "pandas", "duplicates" ]
Drop duplicates for rows with interchangeable name values (Pandas, Python)
40,062,621
<p>I have a DataFrame of form</p> <pre><code>person1, person2, ..., someMetric John, Steve, ..., 20 Peter, Larry, ..., 12 Steve, John, ..., 20 </code></pre> <p>Rows 0 and 2 are interchangeable duplicates, so I'd want to drop the last row. I can't figure out how to do this in Pandas.</p> <p>Thanks!</p>
2
2016-10-15T18:19:16Z
40,063,593
<p>an approach in pandas</p> <pre><code>df = pd.DataFrame( {'person2': {0: 'Steve', 1: 'Larry', 2: 'John', 3: 'Parker', 4: 'Peter'}, 'person1': {0: 'John', 1: 'Peter', 2: 'Steve', 3: 'Peter', 4: 'Larry'}, 'someMetric': {0: 20, 1: 13, 2: 19, 3: 5, 4: 7}}) print(df) person1 person2 someMetric 0 John Steve ...
0
2016-10-15T19:56:10Z
[ "python", "pandas", "duplicates" ]
Finding values that exist for every dictionary in a list
40,062,650
<p>I have a list of lists that each have several dictionaries. The first list represents every coordinate involved in a triangulation. The second list represents a list of dictionaries associated with that grid coordinate. Each dictionary within the list represents every possible coordinate that is a certain Manhattan ...
0
2016-10-15T18:22:29Z
40,062,913
<p>There is no magic. You just need to be a bit more careful with your data structures. You are putting coordinates in a dict which are not hashable. So you cannot add them to a set. You need to use tuples. So your data structure should look like this:</p> <pre><code>my_list = [ set([ (1, 0), (-1, ...
2
2016-10-15T18:48:41Z
[ "python" ]
cipher encoder in python using dictionaries
40,062,728
<p>I'm trying to practice using dictionaries and functions on python. I am trying to write a program that encrypts a simple phrase or sentence with an encrypted alphabet: </p> <pre><code>Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ Encrypted alphabet: TDLOFAGJKRICVPWUXYBEZQSNMH. </code></pre> <p>The user is to ente...
0
2016-10-15T18:30:05Z
40,063,072
<p>You should exclude those cases with unknown symbols and that could be done by:</p> <pre><code> cipher ={"A":"T","a":"T","B":"D","b":"D","C":"L","c":"L","D":"O","d":"O","E":"F","e":"F","F":"A","f":"A","G":"G","g":"G","H":"J","h":"J","I":"K","i":"K","J":"R","j":"R","K":"I","k":"I","L":"C","l":"C","M":"V","m":"V","...
0
2016-10-15T19:03:25Z
[ "python", "dictionary", "encryption" ]
cipher encoder in python using dictionaries
40,062,728
<p>I'm trying to practice using dictionaries and functions on python. I am trying to write a program that encrypts a simple phrase or sentence with an encrypted alphabet: </p> <pre><code>Original alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ Encrypted alphabet: TDLOFAGJKRICVPWUXYBEZQSNMH. </code></pre> <p>The user is to ente...
0
2016-10-15T18:30:05Z
40,065,324
<p>Sometimes it's better to ask forgiveness then permission. You could remove half your key: values and replace them with str.upper(), that way small letters become big letters. If you call dict().get(key) you get the value of the key or you get None. The or operator between the dict and character evaluates to the char...
0
2016-10-15T23:37:27Z
[ "python", "dictionary", "encryption" ]
digits to words from sys.stdin
40,062,780
<p>I'm trying to convert digits to words from std input (txt file). If the input is for example : 1234, i want the output to be one two three four, for the next line in the text file i want the output to be on a new line in the shell/terminal: 1234 one two three four 56 five six The problem is that i can't get it to ou...
0
2016-10-15T18:35:56Z
40,063,000
<p>Put the words in a list, join them, and print the line.</p> <pre><code>#!/usr/bin/python3 import sys import math def main(): number_list = ["zero","one","two","three","four","five","six","seven","eight","nine"] for line in sys.stdin: digits = list(line.strip()) words...
1
2016-10-15T18:57:03Z
[ "python", "words", "digits" ]
print the first item in list of lists
40,062,783
<p>I am trying to print the first item in a list of lists. This is what I have:</p> <p>My list is like this:</p> <pre><code>['32 2 6 6', '31 31 31 6', '31 2 6 6'] </code></pre> <p>My code is:</p> <pre><code>from operator import itemgetter contents = [] first_item = list(map(itemgetter(0), contents)) print first_i...
1
2016-10-15T18:36:14Z
40,062,811
<p>You are dealing with a list of strings, so you are getting the first index of each string, which is in fact <code>3</code> for all of them. What you should do is a comprehension where you split each string on space (which is the default of split) and get the first index:</p> <pre><code>first_element = [s.split(None...
5
2016-10-15T18:39:09Z
[ "python", "list" ]
print the first item in list of lists
40,062,783
<p>I am trying to print the first item in a list of lists. This is what I have:</p> <p>My list is like this:</p> <pre><code>['32 2 6 6', '31 31 31 6', '31 2 6 6'] </code></pre> <p>My code is:</p> <pre><code>from operator import itemgetter contents = [] first_item = list(map(itemgetter(0), contents)) print first_i...
1
2016-10-15T18:36:14Z
40,066,665
<pre><code>&gt;&gt;&gt; items = ['32 2 6 6', '31 31 31 6', '31 2 6 6'] &gt;&gt;&gt; [s.partition(' ')[0] for s in items] ['32', '31', '31'] </code></pre>
0
2016-10-16T03:58:35Z
[ "python", "list" ]
Save and Load data in Python 3
40,062,790
<p>I have to create a team roster that saves and loads the data. I have it to the point where everything else works but saving and loading.</p> <pre><code>memberList = [] #get first menu selection from user and store in control value variable def __init__(self, name, phone, number): self.__name = name self.__p...
-1
2016-10-15T18:37:07Z
40,064,098
<p>Try <code>name = memberList[int(x)].getName()</code>. When it reads the data from a file it reads a string, and in order to put that into a list you need to make it an integer.</p>
0
2016-10-15T20:52:19Z
[ "python", "file", "save", "load" ]
Scrapy XPath Incorrectly when there is Unicode in the page
40,062,836
<p>I want to get all divs that have category class.</p> <p>Take a look at this page: www.postkhmer.com/ព័ត៌មានជាតិ </p> <p><a href="https://i.stack.imgur.com/WvFAN.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/WvFAN.jpg" alt="enter image description here"></a></p> <p>in scrapy shell: ...
2
2016-10-15T18:42:11Z
40,067,637
<p>when you save the page into a local file <code>page.html</code>, you skip the http header that contains encoding information. Later on, when you open this file , either with scrapy or sublime, they have no clue what was the original encoding of the document.</p> <p><strong>Recommendation</strong>: never used docume...
0
2016-10-16T06:44:26Z
[ "python", "xpath", "scrapy" ]
Scrapy XPath Incorrectly when there is Unicode in the page
40,062,836
<p>I want to get all divs that have category class.</p> <p>Take a look at this page: www.postkhmer.com/ព័ត៌មានជាតិ </p> <p><a href="https://i.stack.imgur.com/WvFAN.jpg" rel="nofollow"><img src="https://i.stack.imgur.com/WvFAN.jpg" alt="enter image description here"></a></p> <p>in scrapy shell: ...
2
2016-10-15T18:42:11Z
40,069,568
<p>Only 2 things can be happening here. Either the html is malformed and scrapy can't parse it or there's some trouble with scrapy and encoding. I think the first one is more likely. <a href="http://www.freeformatter.com/html-validator.html" rel="nofollow">http://www.freeformatter.com/html-validator.html</a> kind of gi...
0
2016-10-16T11:07:59Z
[ "python", "xpath", "scrapy" ]
Multiprocessing: Use Win32 API to modify Excel-Cells from Python
40,062,841
<p>I'm really looking for a good solution here, maybe the complete concept how I did it or at elast tried to do it is wrong!?</p> <p>I want to make my code capable of using all my cores. In the code I'm modifying Excel Cells using Win32 API. I wrote a small xls-Class which can check whether the desired file is already...
0
2016-10-15T18:42:37Z
40,068,543
<p>While Excel can use multiple cores when recalculating spreadsheets, its programmatic interface is strongly tied to the UI model, which is single threaded. The active workbook, worksheet, and selection are all singleton objects; this is why you cannot interact with the Excel UI at the same time you're driving it usi...
1
2016-10-16T08:50:26Z
[ "python", "excel", "winapi", "multiprocessing" ]
python: i have an error while trying this on my mac using IDLE on mac or terminal
40,062,854
<p>i want to see some info and get info about my os with python as in my tutorial but actually can't run this code:</p> <pre><code>import os F = os.popen('dir') </code></pre> <p>and this :</p> <pre><code>F.readline() ' Volume in drive C has no label.\n' F = os.popen('dir') # Read by sized blocks F.rea...
0
2016-10-15T18:43:52Z
40,062,940
<p>The code you are following looks like it was written for Windows. <code>popen</code> runs a command -- but there is no <code>dir</code> command on a Mac. <code>dir</code> in DOS shows you files in a directory (folder); the equivalent command on a Mac is <code>ls</code>.</p>
0
2016-10-15T18:51:39Z
[ "python", "osx" ]