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 |
|---|---|---|---|---|---|---|---|---|---|
Parsing argparse input bit by bit | 37,824,316 | <p>I am using <a href="https://docs.python.org/2/library/argparse.html#sub-commands" rel="nofollow">Argparse</a> to parse shell input to my Python function. </p>
<p>The tricky part is that this script first reads in a file that partially determines what kind of arguments are available to Argparse (it's a JSON file co... | 2 | 2016-06-15T00:36:29Z | 37,824,948 | <p><code>parse_args</code> calls <code>parse_known_args</code>. This returns the <code>args</code> namesparse along with a list of strings (from <code>sys.argv</code>) that it could not process (<code>extras</code>). <code>parse_args</code> raises this error if this list is not empty.</p>
<p><a href="https://docs.py... | 1 | 2016-06-15T02:08:04Z | [
"python",
"parsing",
"parameter-passing",
"argparse"
] |
Computing numpy array mean across axis | 37,824,321 | <p>I have a numpy array with shape:</p>
<p><code>(16L, 360L, 720L)</code></p>
<p>How do I find the mean so that the resulting array has the shape <code>(16)</code> i.e. I want mean of all 360 * 720 values for each of the 16 axis elements.</p>
<p>I tried this:</p>
<pre><code>np.mean(arr, axis=0)
</code></pre>
<p>bu... | 1 | 2016-06-15T00:36:54Z | 37,824,535 | <p>What does</p>
<pre><code>np.mean(arr, axis=(1,2)
</code></pre>
<p>produce?</p>
<p>From the <code>mean</code> docs</p>
<pre><code> axis : None or int or tuple of ints, optional
Axis or axes along which the means are computed. The default is to
compute the mean of the flattened array.
..... | 2 | 2016-06-15T01:06:05Z | [
"python",
"numpy"
] |
Kivy list view padding between rows | 37,824,345 | <p>Is it possible to apply vertical padding between rows on a Kivy list view? I have tried modifying the kv file padding on both the list view and the gridlayout to no avail.</p>
<pre><code>+++++++
+ Row +
+++++++
+ Pad +
+++++++
+ Row +
+++++++
</code></pre>
| 1 | 2016-06-15T00:40:35Z | 37,837,321 | <p>The following will add padding between the ListView items by using a ListAdapter and list_items_arg_converter where you can modify the look of your ListItems. It does not change the padding of the underlying GridLayout but just changes the height of the items.</p>
<p>Hope this helps,<br>
Cheers </p>
<p>[Kivy ... | 2 | 2016-06-15T13:46:22Z | [
"python",
"kivy"
] |
Python serial write doesn't work FIRST run | 37,824,371 | <p>I have 2 programs to test serial communication, an simple arduino program that echoes whatever is on the serial port and a python program that writes to the serial port and prints the reply. </p>
<p>I'm having an issue where whenever I upload the arduino program and try to run the python the first time after I upl... | 0 | 2016-06-15T00:44:08Z | 37,848,085 | <p>By default python Serial might be blocking by default try removing the timeout:</p>
<pre><code>ser = serial.Serial('/dev/ttyACM1', 115200,timeout=0)
</code></pre>
<p>additionally have a peek at the <a href="https://pythonhosted.org/pyserial/pyserial_api.html?highlight=serial#module-serial.threaded" rel="nofollow">... | 0 | 2016-06-16T00:43:47Z | [
"python",
"arduino",
"serial-port"
] |
Python serial write doesn't work FIRST run | 37,824,371 | <p>I have 2 programs to test serial communication, an simple arduino program that echoes whatever is on the serial port and a python program that writes to the serial port and prints the reply. </p>
<p>I'm having an issue where whenever I upload the arduino program and try to run the python the first time after I upl... | 0 | 2016-06-15T00:44:08Z | 38,089,330 | <p>I added</p>
<pre><code>time.sleep(1)
ser.setDTR(level=0)
time.sleep(1)
</code></pre>
<p>after opening the serial port and the issue was fixed.</p>
| 0 | 2016-06-29T02:26:29Z | [
"python",
"arduino",
"serial-port"
] |
mock function called actual function | 37,824,374 | <p>I have code for cassandra python driver.</p>
<pre><code>from cassandra.cqlengine.management import sync_table
def sync_my_tables():
print sync_table
print "*" * 80
sync_table(my_models.student)
</code></pre>
<p>When I try to write UT for this, i mocked <code>sync_table</code> using <code>@patch</code>... | 0 | 2016-06-15T00:44:17Z | 37,824,560 | <p>Python cannot mock (replace) things that are already in the module scope. Once imported, you cannot change it from the outside. To make the code testable, you need to import the higher level module and use the method from there as then it becomes just a property that can be changed.</p>
<pre><code>from cassandra.cq... | 1 | 2016-06-15T01:09:31Z | [
"python",
"cassandra",
"mocking",
"python-unittest"
] |
mock function called actual function | 37,824,374 | <p>I have code for cassandra python driver.</p>
<pre><code>from cassandra.cqlengine.management import sync_table
def sync_my_tables():
print sync_table
print "*" * 80
sync_table(my_models.student)
</code></pre>
<p>When I try to write UT for this, i mocked <code>sync_table</code> using <code>@patch</code>... | 0 | 2016-06-15T00:44:17Z | 37,824,567 | <p>When using patch you need to patch the object where it is used. So if <code>sync_my_tables</code> is located in a file with a path of <code>foo/bar/baz.py</code> you will need to call patch like this:</p>
<pre><code>@patch('foo.bar.baz.sync_table')
def test_sync_table(self, _):
# test code
</code></pre>
| 1 | 2016-06-15T01:10:12Z | [
"python",
"cassandra",
"mocking",
"python-unittest"
] |
How to use selenium capabilities for Firefox in splinter? | 37,824,438 | <p>I'm using python splinter which is built on selenium, i want to use another webdriver for firefox as starting from version 47 firefox changed the webdriver as per below link</p>
<p><a href="https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver" rel="nofollow">https://developer.mozilla.org/en-US/d... | -1 | 2016-06-15T00:51:25Z | 37,824,558 | <p>You are looking at the documentation generated for the <em><code>master</code> branch</em> of the <code>splinter</code> project.</p>
<p>For <code>capabilities</code> to work, you need to uninstall <code>splinter</code> and install it <a href="https://github.com/cobrateam/splinter" rel="nofollow"><em>directly from g... | 0 | 2016-06-15T01:09:20Z | [
"python",
"selenium",
"webdriver",
"splinter"
] |
Writing on the topmost row of a CSV file | 37,824,439 | <p>I have this sample.csv file:</p>
<pre><code>a 1 apple
b 2 banana
c 3 cranberry
d 4 durian
e 5 eggplant
</code></pre>
<p>And have the following code:</p>
<pre><code>samplefile = open(sample.csv,'rb')
rows = samplefile .readlines()
outputfile = open(output.csv,'wb')
wr = csv.writer(outputfile)
f... | 0 | 2016-06-15T00:51:30Z | 37,826,982 | <p>If you want to add to the end of the file(append to it):</p>
<pre><code>with open("sample.csv", "a") as fp:
fp.write("new text")
</code></pre>
<p>If you want to overwrite the file:</p>
<pre><code>with open("sample.csv", "w") as fp:
fp.write("new text")
</code></pre>
<p>If you want to <a href="http://st... | 2 | 2016-06-15T05:40:18Z | [
"python",
"python-2.7",
"csv"
] |
OpenCV Python - Reading pgm files | 37,824,502 | <p>I'm trying to read a bunch of pgm files for a facial recognition project.</p>
<p>These files lie in an overall folder called "negative" and within the negative folder are subfolders. This portion of my script is supposed to go into all of the directories, store the filenames in an array, and store the "image file"... | 0 | 2016-06-15T01:01:41Z | 37,859,097 | <p>Just in case anyone else runs into this issue, I found a solution:</p>
<p>I figured out the issue I was having had to do with the path that I was sending into the function "imread". The full path of the file needs to be passed into the function in order for it to read properly. The issue was resolved when I entered... | 0 | 2016-06-16T12:22:01Z | [
"python",
"opencv",
"pgm",
"imread"
] |
create heatmap of 3 list using matplotlib and numpy | 37,824,663 | <p>I have 3 Python list: <code>x = [x0, x1, x2, ..., xn]</code>, <code>y = [y0, y1, y2, ..., yn]</code> and <code>v = [v0, v1, v2, ..., vn]</code> and what I need to do it to visualize the data by creating a heatmap, where at coordinate <code>(x[k], y[k])</code>, value <code>v[k]</code> is visualized, the result could ... | 0 | 2016-06-15T01:24:58Z | 37,825,797 | <p>If the encoded matrix is not too large for memory, it can easily be converted to a dense numpy array using array slicing:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
x = [1, 0]
y = [0, 1]
v = [2, 3]
M = np.zeros((max(x) + 1, max(y) + 1))
M[x, y] = v
fig, ax = plt.subplots()
ax.matshow(M)
</... | 1 | 2016-06-15T03:52:27Z | [
"python",
"numpy",
"matplotlib",
"heatmap"
] |
How to add GeoTIFF tags into EXIF image data in Python? | 37,824,696 | <p>I wrote a script that gets an image as input and then convert it to tiff format. Now I need to add some GeoTIFF tags into the EXIF image data (e.g. pixel size, coordinates, etc) so I could work with this image in QGIS.</p>
<p>If Python doens't have any lib that can handle this I could migrate this script to C++. An... | 0 | 2016-06-15T01:30:39Z | 37,854,162 | <p>You need use gdal library.</p>
<pre><code>import gdal
gdal.AllRegister()
inputImagePath = "your geotiff"
inputdataset = gdal.Open(inputImagePath)
inputdataset.SetMetadataItem("TEST","TEST METADATA")
inputdataset = None
</code></pre>
<p>this code add a metadata item "TEST" in the image.</p>
| 0 | 2016-06-16T08:44:51Z | [
"python",
"exif",
"qgis",
"geotiff"
] |
Making a tkinter memory game | 37,824,728 | <p>I am making a memory game in Tkinter. However, I am at the point where I'm trying to flip cards over. The first card works, it flips over. Then the second card doesn't flip over, maybe immediately flips over again. Can you please help me</p>
<pre><code>import tkinter as tk
import time
from random import randint
fro... | 1 | 2016-06-15T01:36:11Z | 37,827,903 | <p>Even though you are changing tile's face up/face down state you are not clearing <code>flippedTiles</code>. Also, if both are correct, correct ones should stay in <code>flippedTiles</code> hence after a match, <code>len(flippedTiles)</code> will not go under 2. To solve it, you should track number of tiles flipped ... | 0 | 2016-06-15T06:45:15Z | [
"python",
"tkinter"
] |
How to use random.randint to find random 0 and 1 with not equal propbability | 37,824,729 | <p>I am using <a href="https://pypi.python.org/pypi/deap" rel="nofollow">DEAP</a> toolbox in Python for Genetic Algorithm. </p>
<p><code>toolbox.register("attr_bool", random.randint, 0, 1)</code> is a function randomly chooses 0 and 1 for populations in GA. I want to force GA to choose 0 and 1 randomly but with for ex... | 2 | 2016-06-15T01:36:26Z | 37,824,791 | <p><code>random.randint</code> does not provide such functionality, but if you wanted to stay in the <code>random</code> package, you could use <code>random.choice([0] * 1 + [1] * 4)</code>.</p>
<p><code>numpy.random</code> also provides this functionality with <code>np.random.choice([0, 1], p=[0.2, 0.8])</code>.</p>
| 1 | 2016-06-15T01:46:10Z | [
"python",
"random",
"genetic-algorithm",
"deap"
] |
How to use random.randint to find random 0 and 1 with not equal propbability | 37,824,729 | <p>I am using <a href="https://pypi.python.org/pypi/deap" rel="nofollow">DEAP</a> toolbox in Python for Genetic Algorithm. </p>
<p><code>toolbox.register("attr_bool", random.randint, 0, 1)</code> is a function randomly chooses 0 and 1 for populations in GA. I want to force GA to choose 0 and 1 randomly but with for ex... | 2 | 2016-06-15T01:36:26Z | 37,824,848 | <p>A natural way is to use the expression</p>
<pre><code>1 if random.random() <= 0.8 else 0
</code></pre>
<p>You can abstract this into a function:</p>
<pre><code>def bernoulli(p): return 1 if random.random() <= p else 0
</code></pre>
<p>Then <code>bernoulli(0.8)</code> will give 1 or 0 with the requisite pro... | 2 | 2016-06-15T01:54:13Z | [
"python",
"random",
"genetic-algorithm",
"deap"
] |
How to use random.randint to find random 0 and 1 with not equal propbability | 37,824,729 | <p>I am using <a href="https://pypi.python.org/pypi/deap" rel="nofollow">DEAP</a> toolbox in Python for Genetic Algorithm. </p>
<p><code>toolbox.register("attr_bool", random.randint, 0, 1)</code> is a function randomly chooses 0 and 1 for populations in GA. I want to force GA to choose 0 and 1 randomly but with for ex... | 2 | 2016-06-15T01:36:26Z | 37,825,049 | <p>The arguments to <a href="http://deap.gel.ulaval.ca/doc/default/api/base.html#deap.base.Toolbox.register" rel="nofollow"><code>toolbox.register</code></a> must be a function and the arguments that you want to pass to that function when you run it</p>
<p>Since <code>0 if random.randint(0, 4) == 0 else 1</code> is no... | 2 | 2016-06-15T02:20:33Z | [
"python",
"random",
"genetic-algorithm",
"deap"
] |
Python BeautifulSoup issue parsing table | 37,824,895 | <p>Hi I am using beautifulsoup to parse tables in the following website, but not all the rows are getting returned. I looking for article tags (<a href="http://itp.ne.jp/result/?kw=%92J%98e%8E%95%89%C8%83N%83%8A%83j%83b%83N" rel="nofollow">http://itp.ne.jp/result/?kw=%92J%98e%8E%95%89%C8%83N%83%8A%83j%83b%83N</a>)</p>
... | 0 | 2016-06-15T02:00:39Z | 37,827,611 | <p>Use the parser <code>html5lib</code> instead of <code>html.parser</code> and it will work like a charm. You just need to change the following line of code - </p>
<pre><code>prefsoup = BeautifulSoup(page.content,"html.parser")
</code></pre>
<p>to - </p>
<pre><code>prefsoup = BeautifulSoup(page.content,"html5lib")
... | 0 | 2016-06-15T06:26:35Z | [
"python",
"parsing",
"beautifulsoup"
] |
Flask CRUD using SQLAlchemy, how can I load data column | 37,824,911 | <p>I want to load database value? using sql alchmey.
If I ask using get mehtod '127.0.0.1/api/v1/user/25/'</p>
<p>There is a value in database(id=5, username=jaeyeon, email=jae@naver.com)
I want to show this column.
but it can't. Where can I fix the code?<br>
I don't know how parameter deliver.. Please help me :(</p>
... | -2 | 2016-06-15T02:02:58Z | 37,829,109 | <p>You've set up your session a bit differently than I'm used to doing, so I'm not sure whether that makes any difference, but I can see some issues with the query you're making. Try this instead:</p>
<pre><code>user_id = db.session.query(User).filter_by(id = args['id']).one()
</code></pre>
<p>Assuming that <code>ar... | 0 | 2016-06-15T07:43:09Z | [
"python",
"flask",
"flask-sqlalchemy"
] |
Need help finding the correct regex pattern for my string pattern | 37,824,917 | <p>I'm terrible with RegEx patterns, and I'm writing a simple python program that requires splitting lines of a file into a 'content' part and a 'tags' part, and then further splitting the tags parts into individual tags. Here's a simple example of what one line of my file might look like:</p>
<p><code>The Beatles <... | 0 | 2016-06-15T02:03:53Z | 37,824,999 | <p>This is a solution that gets around the problem without using by relying on multiple splits.</p>
<pre><code># This separates the string into the content and the remainder
content, tagStr = line.split('<')
# This splits the tagStr into individual tags. [:-1] is used to remove trailing '>'
tags = tagStr[:-1].s... | 1 | 2016-06-15T02:13:57Z | [
"python",
"regex",
"string",
"parsing",
"split"
] |
Using Python (and DataNitro) to copy cells from a particular sheet in one Excel workbook, to a particular sheet in another Excel workbook | 37,824,926 | <p>I do a lot of data analysis in Excel and have been exploring Python and DataNitro to streamline my workflow. I specifically am trying to copy certain cells from one sheet in one Excel workbook, and paste them into certain cells in a certain sheet in another Excel workbook.
I have been storing ("copying") using Cell... | 4 | 2016-06-15T02:04:49Z | 37,900,431 | <p>Here's an example of copying:</p>
<pre><code>data = CellRange("A1:A10").value
active_wkbk("Book2.xlsx")
CellRange("A1:A10").value = data
</code></pre>
<p>You can make the range conditional using regular Python logic (<code>if</code> statements, etc.).</p>
| 0 | 2016-06-18T18:41:31Z | [
"python",
"excel",
"datanitro"
] |
How do you find the database a Django object is using? | 37,824,936 | <p>Django supports using <a href="https://docs.djangoproject.com/en/1.9/topics/db/multi-db/" rel="nofollow">multiple databases</a> simultaneously, and the docs explain how to specify the database when saving or retrieving an object. However, given a Django model instance, how do you determine which database it's curren... | 0 | 2016-06-15T02:06:00Z | 37,825,016 | <p>From the <a href="https://docs.djangoproject.com/en/1.9/topics/db/multi-db/#using-routers" rel="nofollow">Using routers documentation</a>, you can use <code>model_instance._state.db</code> to inspect the database which the current model instance is using.</p>
| 1 | 2016-06-15T02:16:11Z | [
"python",
"django",
"django-models"
] |
ImportError: No module named 'tweepy.auth' | 37,824,955 | <p>I'm trying to make a twitter bot using python and twitter but was getting an error. I fixed the first error with this solution but now I have another and at this point I am not sure what to do ( <a href="http://stackoverflow.com/questions/26075001/error-with-tweepy-oauthhandler">Error with tweepy OAuthHandler</a>) <... | 0 | 2016-06-15T02:08:46Z | 37,825,011 | <p>try removing that <code>.auth</code> from the module import portion, and get <code>OAuthHandler</code> directly from <code>tweepy</code>.
Also check your tweepy module if it contains auth scrpit</p>
| 1 | 2016-06-15T02:15:24Z | [
"python",
"twitter"
] |
compare 2 methods data.get('key_name') vs. `data['key_name'] or None` | 37,825,037 | <p>I got a python dictionary variable called <code>data</code>, I am trying to get value of 'key_name', if it doesn't exists, I want it to be None.</p>
<pre><code>A = data.get('key_name')
B = data['key_name'] or None
</code></pre>
<p>I know if the 'key_name' is a empty string, A is '' and B is None, and maybe there ... | 0 | 2016-06-15T02:18:42Z | 37,825,079 | <p>This will throw a KeyError so you can't use this:</p>
<pre><code>B = data['key_name'] or None
</code></pre>
<p>As far as Python goes, the first option is the most standard way to do that:</p>
<pre><code>A = data.get('key_name')
</code></pre>
<p>If you are open to other data types, you can always use a <a href="h... | 2 | 2016-06-15T02:24:03Z | [
"python"
] |
Reconstructing a pandas object versus copy() | 37,825,058 | <p>Does anyone know why a pandas object <code>copy()</code> method seems much slower than reconstructing the object? Is there any reason to use the <code>copy()</code> method over a standard constructor?</p>
<p>Here is a quick result:</p>
<pre><code>In [42]: import pandas as pd
In [43]: df = pd.DataFrame(np.random.r... | 4 | 2016-06-15T02:21:50Z | 37,826,296 | <p>It's because the copy actually creates a new internal representation of the DataFrame, whilst using the contructor just points to the same one:</p>
<pre><code>In [11]: df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"])
In [12]: id(df._data) # internal attribute, don't futz with it!
Out[12]: 4472136472
In [1... | 3 | 2016-06-15T04:41:24Z | [
"python",
"pandas"
] |
How to add a space in between the output when reversing the string on python? | 37,825,062 | <p>This is what I have to do:</p>
<p>Write a Python program which accept the user's first and last name and print them in reverse order with a space between them. THE LETTERS OF THE FIRST AND LAST NAMES SHOULD ALSO BE IN REVERSE ORDER!!!!! For example if a person enters first name is Sam and last name is Murrow then ... | 1 | 2016-06-15T02:22:12Z | 37,825,073 | <p>In your solution you are only reversing the <code>firstname</code> string. What you can do instead is build your full string including both <code>firstname</code>, <code>lastname</code> and a space between them, and then reverse the entire string.</p>
<p>For example:</p>
<pre><code>firstname = input("What is your ... | 1 | 2016-06-15T02:23:45Z | [
"python"
] |
How to add a space in between the output when reversing the string on python? | 37,825,062 | <p>This is what I have to do:</p>
<p>Write a Python program which accept the user's first and last name and print them in reverse order with a space between them. THE LETTERS OF THE FIRST AND LAST NAMES SHOULD ALSO BE IN REVERSE ORDER!!!!! For example if a person enters first name is Sam and last name is Murrow then ... | 1 | 2016-06-15T02:22:12Z | 37,825,102 | <p><code>print("{last} {first}".format(last=lastname[::-1], first=firstname[::-1]))</code></p>
| -1 | 2016-06-15T02:26:20Z | [
"python"
] |
How to add a space in between the output when reversing the string on python? | 37,825,062 | <p>This is what I have to do:</p>
<p>Write a Python program which accept the user's first and last name and print them in reverse order with a space between them. THE LETTERS OF THE FIRST AND LAST NAMES SHOULD ALSO BE IN REVERSE ORDER!!!!! For example if a person enters first name is Sam and last name is Murrow then ... | 1 | 2016-06-15T02:22:12Z | 37,825,525 | <p>Try this: </p>
<pre><code> firstname = input("What is your first name?:")
lastname = input("What's your last name?: ")
fn = firstname[::-1]
ln = lastname[::-1]
print (fn,"",ln)
</code></pre>
| 0 | 2016-06-15T03:20:28Z | [
"python"
] |
How can I find out what distribution of Python I'm using? | 37,825,196 | <p>I'm not just looking for the version but specifically the distribution, i.e. whether it's Anaconda, Python(x,y), etc.</p>
| 0 | 2016-06-15T02:38:26Z | 37,825,264 | <p>A few solutions:</p>
<ol>
<li>Open a terminal, type <code>python</code>, and see what it says in the preamble.</li>
<li>In linux, type <code>which python</code></li>
<li>On windows, type <code>where python</code></li>
</ol>
| 0 | 2016-06-15T02:45:21Z | [
"python"
] |
How can I find out what distribution of Python I'm using? | 37,825,196 | <p>I'm not just looking for the version but specifically the distribution, i.e. whether it's Anaconda, Python(x,y), etc.</p>
| 0 | 2016-06-15T02:38:26Z | 37,826,030 | <p>Open a terminal (or command line on Windows) and type <code>python --version</code>. For instance, on my Windows machine this returns:</p>
<blockquote>
<p>Python 3.4.4 :: Anaconda 4.0.0 (64-bit)</p>
</blockquote>
<p>Unless I'm in my Python 2.7 virtual env, in which case it returns:</p>
<blockquote>
<p>Python ... | 1 | 2016-06-15T04:15:09Z | [
"python"
] |
Tensorflow convert array of tensors into single tensor | 37,825,209 | <p>I'm building a LSTM RNN with Tensorflow that performs pixel-wise classification (or, maybe a better way to put it is, pixel-wise prediction?) </p>
<p>Bear with me as I explain the title.</p>
<p>The network looks like the following drawing...</p>
<p><a href="http://i.stack.imgur.com/djRCX.jpg" rel="nofollow"><img ... | 2 | 2016-06-15T02:39:39Z | 37,838,315 | <p>A more convenient way to report shapes is with tf.shape(). In your case:</p>
<pre><code>size1 = tf.shape(temp)
sess = tf.Session()
size1_fetched = sess.run(size1, feed_dict = your_feed_dict)
</code></pre>
<p>That way, the size1_fetched is something like you would get from NumPy. Moreover, also your sizes for that ... | 0 | 2016-06-15T14:29:05Z | [
"python",
"machine-learning",
"neural-network",
"artificial-intelligence",
"tensorflow"
] |
Fastest way to read and process 100,000 URLs in Python | 37,825,218 | <p>I have a file with 100,000 URLs that I need to request then process. The processing takes a non-negligible amount of time compared to the request, so simply using multithreading seems to only give me a partial speed-up. From what I have read, I think using the <code>multiprocessing</code> module, or something simila... | 0 | 2016-06-15T02:40:27Z | 37,829,125 | <p>If the file isn't bigger than your available memory, instead of opening it with the "open" method use mmap ( <a href="https://docs.python.org/3/library/mmap.html" rel="nofollow">https://docs.python.org/3/library/mmap.html</a> ). It will give the same speed as if you were working with memory and not a file.</p>
<pre... | 0 | 2016-06-15T07:44:19Z | [
"python",
"multithreading",
"http",
"concurrency",
"multiprocessing"
] |
py2neo command in neo4j BOLT driver | 37,825,219 | <p>I have a command written in python using the py2neo to access the name of an exchange. This works.</p>
<pre><code>graph = Graph()
stmt = 'MATCH (i:Index{uniqueID: 'SPY'})-[r:belongsTo]->(e:Exchange) RETURN e.name'
exchName = graph.cypher.execute(stmt)[0][0]
</code></pre>
<p>Can this be converted to a BOLT neo4j... | 0 | 2016-06-15T02:40:44Z | 37,834,984 | <p>Try to store the results of <code>session.run()</code> in a <code>list</code> to retain them:</p>
<pre><code>driver = GraphDatabase.driver("bolt://localhost", auth=basic_auth("neo4j", "neo4j"))
session = driver.session()
stmt = 'MATCH (i:Index{uniqueID: 'SPY'})-[r:belongsTo]->(e:Exchange) RETURN e.name'
# trans... | 1 | 2016-06-15T12:06:10Z | [
"python",
"neo4j",
"py2neo"
] |
Object has no attribute error on MVC like Python project | 37,825,257 | <p>I'm getting "MainView has no atribute ct", even though it is being set on its <code>__init__</code></p>
<p>ct would be the reference to the controller</p>
<p>Here's MainView.py</p>
<pre><code>import tkinter as tk
class MainView(tk.Frame):
def __init__(self, root, ct):
tk.Frame.__init__(root)
... | 0 | 2016-06-15T02:44:49Z | 37,826,220 | <p>Few things I see that you are missing. </p>
<ol>
<li>Need to put the button into the <code>root</code>.</li>
</ol>
<p></p>
<pre><code>botaoProdutos = tk.Button(self.root, text="Produtos", command=self.toProdutos, padx=5, pady=5)
</code></pre>
<p>To do that, you need to add <code>self.root = root</code> to the <c... | 0 | 2016-06-15T04:33:32Z | [
"python",
"tkinter"
] |
__init__.py :: make a sub module routines available at top level import | 37,825,318 | <p>Assume the following structure...</p>
<pre><code>root/test.py
root/myapp/__init__.py
root/myapp/myapp.py # contains My_App_Class()
root/myapp/SomeObject.py # contains My_Obj_Class()
</code></pre>
<p>If my <code>__init__.py</code> contains the following structure:</p>
<pre><code>from myapp import *
import S... | 0 | 2016-06-15T02:51:45Z | 37,825,629 | <p>The <code>__all__</code> attribute in yur <code>__init__.py</code> file is what is preventing other names (imported from myapp/myapp.py) from being visible when using the <code>myapp</code> package.</p>
<p>Just don't use the <code>all</code> - and maybe, to avoid ambiguity, change the import written as:</p>
<pre><... | 1 | 2016-06-15T03:32:36Z | [
"python",
"import",
"initialization",
"package"
] |
Python3.5.1 definitions | 37,825,353 | <p>I am trying to write a script (macro?) in Python 3.5.1 (on Windows) that will read from 1 file and type it into another. The second program is a emulator that does not allow copy & paste or the typewrite function in pyautogui. I am able to write the script to pull the info per line and enter it using ctypes. I ... | 1 | 2016-06-15T02:55:59Z | 37,825,875 | <p>From the pattern you've shown which maps <code>Product[0]</code> to a certain key press, it appears that you want to just add <code>Product[0]</code> into <code>0x30</code>. That is,</p>
<pre><code>def Product(line):
if len(line) == 2:
PressKey(0x30 + int(line[0]))
</code></pre>
| 0 | 2016-06-15T04:00:36Z | [
"python",
"python-3.x"
] |
Determine what GPU is running through WMI | 37,825,360 | <p>I am trying to write a python script for to figure out which GPU (dedicated or integrated) is currently running. I have managed to make it work so far by running dxdiag and parsing the output for the mode of each gpu device, but this is taking way too long. Does anyone know how dxdiag gets this information? Is there... | 2 | 2016-06-15T02:57:00Z | 37,838,613 | <p><code>DXDiag</code> most <strong>probably</strong> picks up data from <code>WMI</code> tables. <em>I need to confirm it though.</em></p>
<pre><code>wmic PATH Win32_VideoController GET Adapterram
</code></pre>
<p>will provide you the information that you are looking for. If you want more information just run below ... | 1 | 2016-06-15T14:41:41Z | [
"python",
"windows",
"wmi",
"gpu"
] |
Sort word frequencies by descending order of frequencies | 37,825,491 | <p>I have a text file that has word frequencies in the format:</p>
<pre><code>word<space>freq
</code></pre>
<p>where freq is a number. I want to sort the file such as the frequencies are in descending order. For that, I have tried the following:</p>
<p>Read the file into a dictionary:</p>
<pre><code>kvp = {}
... | -2 | 2016-06-15T03:15:36Z | 37,825,759 | <p>Instead of <code>json.dump</code>, try writing to the file with <code>file.write</code>, formatting the strings as needed.</p>
<pre><code>import json
kvp = {}
d = {}
with open("a.txt", "r") as f:
for line in f:
word, freq = line.partition(" ")[::2]
kvp[word.strip()] = int(freq)
d = sorted(kvp.... | 0 | 2016-06-15T03:49:05Z | [
"python",
"sorting",
"dictionary"
] |
Flipping an image vertically using for loops in Python | 37,825,635 | <p>Im trying to flip an image vertically, but the image saved ends up being the same one. I thought doing new_image.set_pixel(height-1)-r.... would have sent the pixel into the transposed vertical part. Can you give me some guidance as to what I have done wrong?</p>
<pre><code>def flip_vert(filename):
img = load_imag... | 1 | 2016-06-15T03:33:38Z | 37,825,687 | <p>In your last line you need:</p>
<pre><code>new_img.save(new_filename)
</code></pre>
<p>As it is written now you are saving <code>img</code>, which is the original version.</p>
| 2 | 2016-06-15T03:38:54Z | [
"python",
"image",
"loops",
"for-loop",
"flip"
] |
Deleted anaconda to remove python3 in the hopes of going back to python2 | 37,825,637 | <p>I installed python3 with anaconda when I did some of my ML stuff. Now I wanted to use python2 for a script I'm building but python defaults to python3 and I couldn't find any solution to switch or remove python3 so I deleted anaconda folder hoping python to revert back to python 2 since it won't be able to locate th... | -2 | 2016-06-15T03:33:42Z | 37,825,676 | <p>When you deleted your install, you didn't really change where your system is looking for Python. You could change your system's <code>PATH</code> variable so that it doesn't look in the <code>anaconda</code> folder, but I sometimes find environment variables wonky (I probably shouldn't). You could add a line like:</... | 0 | 2016-06-15T03:37:10Z | [
"python",
"osx",
"python-2.7",
"python-3.x"
] |
Deleted anaconda to remove python3 in the hopes of going back to python2 | 37,825,637 | <p>I installed python3 with anaconda when I did some of my ML stuff. Now I wanted to use python2 for a script I'm building but python defaults to python3 and I couldn't find any solution to switch or remove python3 so I deleted anaconda folder hoping python to revert back to python 2 since it won't be able to locate th... | -2 | 2016-06-15T03:33:42Z | 37,826,799 | <p>Try</p>
<pre><code>python2 myscript.py
</code></pre>
<p>instead of</p>
<pre><code>python myscript.py
</code></pre>
<p>Since python points to python3 in your case. If you want to uninstall python3: <a href="http://superuser.com/questions/276840/uninstalling-python-3-on-a-mac">refer this</a></p>
<p>Alternatively,... | 0 | 2016-06-15T05:25:44Z | [
"python",
"osx",
"python-2.7",
"python-3.x"
] |
Scrapy How to check if certain class exists in a given element | 37,825,706 | <pre><code><li class="a">category1</li>
<li>subcatergory1</li>
<li>subcatergory2</li>
<li class="a">category2</li>
<li>subcatergory1</li>
<li>subcatergory2</li>
</code></pre>
<p>I'm looping through an <code>ul</code> which contains 2 kinds of <cod... | 0 | 2016-06-15T03:41:18Z | 37,825,880 | <p>li.css('.a') should do it
or
li.xpath('@id').extract()</p>
<p>if you need only class=a elements than
ul.css('li.a') will do it.</p>
| 0 | 2016-06-15T04:00:52Z | [
"python",
"scrapy"
] |
Not being passed desired value for python tree | 37,825,722 | <p>I couldn't find a python tree I could use to create a tree structure for chess openings, so I tried to write my own. To progress deeper into the tree I try to return a subroot when I add a new position, but it seems all the positions are getting added to the root, and I'm not being given a reference to the subroot l... | 0 | 2016-06-15T03:43:55Z | 37,826,069 | <p>Your code fails because you have misused <a href="https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables" rel="nofollow">class variables.</a></p>
<p>Basically, when you declare <code>children</code> outside of any function it is scoped at the class-level, and all <code>Node</code> objects shar... | 0 | 2016-06-15T04:18:46Z | [
"python",
"tree",
"parameter-passing",
"pass-by-reference",
"chess"
] |
Print Dictionary to CSV file with Python | 37,825,743 | <p>I would like to print my dictionary <code>TimeSheet</code> to my CSV file. However it is only writing the last row into my CSV file. How can I fix this? I am able to print all the contents from my <code>TimeSheet</code> in console but not all of the dictionary prints to CSV. </p>
<pre><code>import glob
import openp... | 1 | 2016-06-15T03:46:31Z | 37,826,306 | <p>The problem is probably that you recreate the CSV file for each iteration.<br>
It should work when you move the creation of the CSV file incl. heading line out of the inner loop like so: </p>
<pre><code>import glob
import openpyxl
import csv
#loops through .xlsx files in folder path
with open('TestOutput.csv', '... | 2 | 2016-06-15T04:43:02Z | [
"python",
"csv",
"dictionary"
] |
Print Dictionary to CSV file with Python | 37,825,743 | <p>I would like to print my dictionary <code>TimeSheet</code> to my CSV file. However it is only writing the last row into my CSV file. How can I fix this? I am able to print all the contents from my <code>TimeSheet</code> in console but not all of the dictionary prints to CSV. </p>
<pre><code>import glob
import openp... | 1 | 2016-06-15T03:46:31Z | 37,826,309 | <p>The issue is 'TestOutput.csv' is opened for each row with 'w' mode, which will truncate the file (see <a href="https://docs.python.org/3/library/functions.html#open" rel="nofollow">https://docs.python.org/3/library/functions.html#open</a>). It only writes the last row because all the others were deleted.</p>
<p>At... | 1 | 2016-06-15T04:43:39Z | [
"python",
"csv",
"dictionary"
] |
Print Dictionary to CSV file with Python | 37,825,743 | <p>I would like to print my dictionary <code>TimeSheet</code> to my CSV file. However it is only writing the last row into my CSV file. How can I fix this? I am able to print all the contents from my <code>TimeSheet</code> in console but not all of the dictionary prints to CSV. </p>
<pre><code>import glob
import openp... | 1 | 2016-06-15T03:46:31Z | 37,826,452 | <p>As stated in earlier responses, create the CSV file before hand.</p>
<p>If you wish for a single csv to consolidate all the data from the excel file(s), the solution from DAXaholic should work.</p>
<p>If you wish to have a csv file for each excel file, the following may help:</p>
<pre><code>import glob
import ope... | 1 | 2016-06-15T04:55:53Z | [
"python",
"csv",
"dictionary"
] |
Encrypt String In Ruby and Decrypt in Python | 37,825,758 | <p>I am brand new to Ruby, so I apologize if this question is simple. I have to update a rails app so that it encrypts a string using a key. This is passed to an api written in django, where the encrypted string will be decrypted using the same key. I have the following code in Python, but I'm not sure how to encrypt t... | 0 | 2016-06-15T03:48:52Z | 37,827,388 | <p>After feedback by ArtjomB I looked deeper into the proposed library. It is nothing but a thin wrapper around ruby openssl. So you can write a ruby version of your AESCipher on your own.
It took some fiddling and research to find the right way:</p>
<pre><code>require 'base64'
require 'securerandom'
require 'openssl... | 1 | 2016-06-15T06:11:36Z | [
"python",
"ruby-on-rails",
"ruby",
"django",
"encryption"
] |
how to compare two dictionaries to check if a key is present in both of them | 37,825,844 | <p>I am trying to compare two dictionaries and check if each key in dict1 is present(or not) in either of dict2 or dict3 using the below logic? Is there a better way to check if any of the keys in dict1 are present in dict2 or dict3 and get the corresponding value?</p>
<pre><code>dict1 = {'1234': 'john','5678': 'james... | 0 | 2016-06-15T03:57:49Z | 37,825,907 | <pre><code>shared_keys = set(dict1).intersection(dict2)
</code></pre>
<p>is how I would do it</p>
<pre><code>>>> dict1 = {'1234': 'john','5678': 'james'}
>>> dict2 = {'1234': 'technician'};
>>> set(dict1).intersection(dict2)
set(['1234'])
>>> if set(dict1).intersection(dict2):
..... | 2 | 2016-06-15T04:03:19Z | [
"python"
] |
how to compare two dictionaries to check if a key is present in both of them | 37,825,844 | <p>I am trying to compare two dictionaries and check if each key in dict1 is present(or not) in either of dict2 or dict3 using the below logic? Is there a better way to check if any of the keys in dict1 are present in dict2 or dict3 and get the corresponding value?</p>
<pre><code>dict1 = {'1234': 'john','5678': 'james... | 0 | 2016-06-15T03:57:49Z | 37,825,923 | <p><code>in</code> on a <code>dict</code> will return if a key is present in a dictionary:</p>
<pre><code>>>> a = {'b': 1, 'c': '2'}
>>> 'b' in a
True
>>> 'd' in a
False
</code></pre>
<p>So your code could be written as:</p>
<pre><code>dict1 = {'1234': 'john','5678': 'james'};
dict2 = {'12... | 3 | 2016-06-15T04:04:54Z | [
"python"
] |
how to compare two dictionaries to check if a key is present in both of them | 37,825,844 | <p>I am trying to compare two dictionaries and check if each key in dict1 is present(or not) in either of dict2 or dict3 using the below logic? Is there a better way to check if any of the keys in dict1 are present in dict2 or dict3 and get the corresponding value?</p>
<pre><code>dict1 = {'1234': 'john','5678': 'james... | 0 | 2016-06-15T03:57:49Z | 37,825,938 | <pre><code>for key in dict1:
try:
print dict1[key] + dict2[key]
except KeyError:
continue
</code></pre>
<p>Your first function doesn't need to take key or dict1 as parameters. I don't think its doing what you want it to do either. That <code>for</code> should probably be an <code>if</code>. It ... | 0 | 2016-06-15T04:06:08Z | [
"python"
] |
python sending TCP/IP data instantly | 37,825,871 | <p>I am currently sending data over TCP/IP in myserver using something like this </p>
<pre><code>for str in lst:
data = str + "\n"
self._conn.sendall(data)
</code></pre>
<p>Now suppose my list has the following two string in it</p>
<pre><code>1-This is statement 1 in list
2-This is statement 2 in list
</code></... | 3 | 2016-06-15T04:00:21Z | 37,826,351 | <p>TCP is based on a stream, not individual messages. So you need to parse the end point of each message yourself. One idea in your case would be to read until you get a newline, then process the line. Note that you might read this:</p>
<pre><code>This is statement 1 in list
This is
</code></pre>
<p>Then you need... | 0 | 2016-06-15T04:47:32Z | [
"python",
"sockets",
"tcp",
"network-programming"
] |
python sending TCP/IP data instantly | 37,825,871 | <p>I am currently sending data over TCP/IP in myserver using something like this </p>
<pre><code>for str in lst:
data = str + "\n"
self._conn.sendall(data)
</code></pre>
<p>Now suppose my list has the following two string in it</p>
<pre><code>1-This is statement 1 in list
2-This is statement 2 in list
</code></... | 3 | 2016-06-15T04:00:21Z | 37,925,496 | <p>TCP has a local buffer that is not sent until it's full. You can force flushing of the local buffer so it's sent after every message, but when the other party receives these packages they get stored in another local buffer and your separation may disappear. TCP is a stream, use it as a stream. You have to use separa... | 0 | 2016-06-20T14:48:30Z | [
"python",
"sockets",
"tcp",
"network-programming"
] |
python sending TCP/IP data instantly | 37,825,871 | <p>I am currently sending data over TCP/IP in myserver using something like this </p>
<pre><code>for str in lst:
data = str + "\n"
self._conn.sendall(data)
</code></pre>
<p>Now suppose my list has the following two string in it</p>
<pre><code>1-This is statement 1 in list
2-This is statement 2 in list
</code></... | 3 | 2016-06-15T04:00:21Z | 37,927,308 | <p>TCP works with streams of data, not individual packets. It's like reading data from a file. The sender puts data in its send buffer, and TCP can decide for itself when to send it. The timing of the arrival at the receiving application depends on when the data was sent and on (often unpredictable) network conditions.... | 4 | 2016-06-20T16:18:51Z | [
"python",
"sockets",
"tcp",
"network-programming"
] |
Round python decimal to nearest 0.05 | 37,825,909 | <p>I'm trying to round money numbers in Decimal to the nearest 0.05. Right now, I'm doing this:</p>
<pre><code>def round_down(amount):
amount *= 100
amount = (amount - amount % 5) / Decimal(100)
return Decimal(amount)
def round_up(amount):
amount = int(math.ceil(float(100 * amount) / 5)) * 5 / Decimal... | 1 | 2016-06-15T04:03:29Z | 37,826,962 | <p>With floats, simply use <code>round(x * 2, 1) / 2</code>. This doesn't give control over the rounding direction, though.</p>
<p>Using <code>Decimal.quantize</code> you also get complete control over the type and direction of rounding (Python 3.5.1):</p>
<pre><code>>>> from decimal import Decimal, ROUND_UP... | 4 | 2016-06-15T05:38:34Z | [
"python"
] |
Round python decimal to nearest 0.05 | 37,825,909 | <p>I'm trying to round money numbers in Decimal to the nearest 0.05. Right now, I'm doing this:</p>
<pre><code>def round_down(amount):
amount *= 100
amount = (amount - amount % 5) / Decimal(100)
return Decimal(amount)
def round_up(amount):
amount = int(math.ceil(float(100 * amount) / 5)) * 5 / Decimal... | 1 | 2016-06-15T04:03:29Z | 38,239,485 | <p>First note this problem (unexpected rounding down) only <strong><em>sometimes</em></strong> occurs when the digit immediately inferior (to the left of) the digit you're rounding to has a <code>5</code>.</p>
<p>i.e.</p>
<pre><code>>>> round(1.0005,3)
1.0
>>> round(2.0005,3)
2.001
>>> roun... | 0 | 2016-07-07T07:10:51Z | [
"python"
] |
Python 3.5 install pyvenv | 37,825,910 | <p>I am trying to get a virtual environment for a repo that requires python 3.5. I am using Debian, and from what I can tell, python 3.5 does not have an aptitude package. After reading some posts, it was recommended to download 3.5 source code and compile it.</p>
<p>After running the make and install, python3.5 was i... | 1 | 2016-06-15T04:03:33Z | 37,825,945 | <p>Try installing it locally:</p>
<pre><code>pip install --user -r requirements.txt
</code></pre>
<p>which would, I believe, install the file in a sub-directory of your <code>$HOME</code> directory (which your virtual env I would think would set). Otherwise I think you could just use:</p>
<pre><code>/path/to/virtual... | 1 | 2016-06-15T04:06:49Z | [
"python",
"debian",
"python-3.5"
] |
Python 3.5 install pyvenv | 37,825,910 | <p>I am trying to get a virtual environment for a repo that requires python 3.5. I am using Debian, and from what I can tell, python 3.5 does not have an aptitude package. After reading some posts, it was recommended to download 3.5 source code and compile it.</p>
<p>After running the make and install, python3.5 was i... | 1 | 2016-06-15T04:03:33Z | 37,826,244 | <p><strong>Option 1</strong>
You can upgrade pip in a virtual environment manually by executing</p>
<pre><code>pip install -U pip
</code></pre>
<p><strong>Option 2</strong>
Good method to upgrade pip inside that package
<code>python -m ensurepip --upgrade</code> does indeed upgrade the pip version in the system (if i... | 2 | 2016-06-15T04:36:16Z | [
"python",
"debian",
"python-3.5"
] |
Python 3.5 install pyvenv | 37,825,910 | <p>I am trying to get a virtual environment for a repo that requires python 3.5. I am using Debian, and from what I can tell, python 3.5 does not have an aptitude package. After reading some posts, it was recommended to download 3.5 source code and compile it.</p>
<p>After running the make and install, python3.5 was i... | 1 | 2016-06-15T04:03:33Z | 37,848,036 | <p>Kesh's answer led me in the right direction. </p>
<p>The problem was that I didn't actually have pip installed in my venv.</p>
<p>It turns out, when I built python3.5 from source, I did not have the libssl-dev package. It looks like one of the dependencies of ensurepip was the python ssl package that didn't get in... | 1 | 2016-06-16T00:37:52Z | [
"python",
"debian",
"python-3.5"
] |
Can we have a different __name__ attribute for different aliasess of a Python class? | 37,825,926 | <p>I have a very simple generic class with keyword arguments only:</p>
<pre><code>class genObj(object):
def __init__(self, **kwargs):
for kwa in kwargs:
self.__setattr__(kwa, kwargs[kwa])
</code></pre>
<p>Now I want to use this for different objects, with different parameters, using the alias ... | 1 | 2016-06-15T04:05:15Z | 37,826,411 | <p>The issue is that the way you have it set up, <code>circle</code> and <code>rectangle</code> are the same object (same type in this case) so <code>circle.__name__ is rectangle.__name__</code>. The cleanest way to get what you what imo, is to make <code>circle</code> and <code>rectangle</code> both sub-classes of <co... | 1 | 2016-06-15T04:52:12Z | [
"python",
"alias",
"classname"
] |
How do I check if a key exists in Memcache (AWS Elastic Cache instance) using python? | 37,825,931 | <p>I'm trying to create a dynamic query which will be a part of memcache key. Is there any way to lookup keys in the memcache? I'm trying to acheive this because if there is any way, I would first lookup in that keymap and will create a new key only if it doesn't exist. </p>
<p>I'm using python + Pymemcache module. </... | -1 | 2016-06-15T04:05:43Z | 37,829,335 | <p>Nevertheless, I found one simple way to check that. So, posting it as an answer. </p>
<pre><code>if client.get(key) is None:
//your_code
</code></pre>
| 0 | 2016-06-15T07:55:05Z | [
"python",
"amazon-web-services",
"caching",
"memcached"
] |
Intellisence in IDLE is slow. Is the slowness of python the reason? | 37,825,965 | <p>I am playing with IDLE. But it seems that intellisense in IDLE is a bit slow. When we type <code>time.</code> I need to wait a second or more for the intellisense to appear. What is the reason for this? I have heard that IDLE is developed in Python itself and that Python is a bit slower than other languages (slower ... | 1 | 2016-06-15T04:08:26Z | 37,826,190 | <p>This delay is intentional! IDLE waits for two seconds before popping up the completion window, to avoid having it always pop up when often you just want to continue typing.</p>
<p>This delay is configurable, though currently IDLE does not make changing this easy. To change this:</p>
<p><strong>EDIT: Recent version... | 4 | 2016-06-15T04:30:30Z | [
"python",
"python-idle"
] |
Intellisence in IDLE is slow. Is the slowness of python the reason? | 37,825,965 | <p>I am playing with IDLE. But it seems that intellisense in IDLE is a bit slow. When we type <code>time.</code> I need to wait a second or more for the intellisense to appear. What is the reason for this? I have heard that IDLE is developed in Python itself and that Python is a bit slower than other languages (slower ... | 1 | 2016-06-15T04:08:26Z | 37,849,395 | <p>You did not specify the exact release you are using, but currently (Since about Sept 2014), IDLE makes changing the popup delay easy. Select Options and Configure Extensions if you see that choice. Otherwise select Configure IDLE and then the Extensions tab (since Fall 2015). In either case, select AutoComplete a... | 1 | 2016-06-16T03:26:51Z | [
"python",
"python-idle"
] |
Error while running Minimal Flask application | 37,826,016 | <p>I am trying to follow the flask documentation on my windows machine given at the following link:
<a href="http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode" rel="nofollow">http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode</a></p>
<p>Firstly I wrote the code below in a python script:</p>
<pre><code><... | 1 | 2016-06-15T04:13:41Z | 37,901,654 | <p>Your code is correct. Try setting the Command-Line variable like this : </p>
<pre><code>setx FLASK_APP run.py
</code></pre>
<p>And then run it : <code>flask run</code>.</p>
| 0 | 2016-06-18T21:08:34Z | [
"python",
"flask"
] |
Error while running Minimal Flask application | 37,826,016 | <p>I am trying to follow the flask documentation on my windows machine given at the following link:
<a href="http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode" rel="nofollow">http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode</a></p>
<p>Firstly I wrote the code below in a python script:</p>
<pre><code><... | 1 | 2016-06-15T04:13:41Z | 38,006,331 | <p>I fixed the same problem by closing the command window and restart it. </p>
| 0 | 2016-06-24T05:44:27Z | [
"python",
"flask"
] |
Error while running Minimal Flask application | 37,826,016 | <p>I am trying to follow the flask documentation on my windows machine given at the following link:
<a href="http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode" rel="nofollow">http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode</a></p>
<p>Firstly I wrote the code below in a python script:</p>
<pre><code><... | 1 | 2016-06-15T04:13:41Z | 38,082,481 | <p>You have to set the FLASK_APP variable outside of the virtual environment. I'm assuming the reason that it worked after @Fang restarted the command window is because that action automatically exited the virtual environment.</p>
<p>So, if you're in the virtual environment (indicated by a <code>(venv)</code> at the s... | 0 | 2016-06-28T17:17:30Z | [
"python",
"flask"
] |
Error while running Minimal Flask application | 37,826,016 | <p>I am trying to follow the flask documentation on my windows machine given at the following link:
<a href="http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode" rel="nofollow">http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode</a></p>
<p>Firstly I wrote the code below in a python script:</p>
<pre><code><... | 1 | 2016-06-15T04:13:41Z | 38,214,351 | <p>Did you run your terminal as administrator? I had the same problem, and running cmd/PowerShell as admin fixed it for me.</p>
<p>Edit: I spoke too soon. Running as admin did nothing.</p>
<p>The real answer (to my problem, at least) is a combination of some of the other answers.</p>
<ol>
<li>Instead of using <co... | 1 | 2016-07-05T23:26:29Z | [
"python",
"flask"
] |
Error while running Minimal Flask application | 37,826,016 | <p>I am trying to follow the flask documentation on my windows machine given at the following link:
<a href="http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode" rel="nofollow">http://flask.pocoo.org/docs/0.11/quickstart/#debug-mode</a></p>
<p>Firstly I wrote the code below in a python script:</p>
<pre><code><... | 1 | 2016-06-15T04:13:41Z | 38,968,084 | <ol>
<li><code>export FLASK_APP=run.py</code></li>
<li><code>flask run --host=0.0.0.0</code></li>
</ol>
<p>then can run normally, output something like:</p>
<pre><code> * Serving Flask app "hello"
* Forcing debug mode on
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is... | 0 | 2016-08-16T06:36:06Z | [
"python",
"flask"
] |
Python scripts not working after switch_to.context('webview') when testing on hybrid Android app? | 37,826,018 | <p>My python scripts as below:</p>
<p>wrong at the red arrow:</p>
| 0 | 2016-06-15T04:13:51Z | 37,913,958 | <p>Question has resolved via update chrome driver to latest version(51.0.2704.103 m (64-bit)).</p>
| 0 | 2016-06-20T02:40:28Z | [
"python",
"hybrid-mobile-app",
"python-appium"
] |
Unmatching variable names and parameters inside a function but code is still working! Can someone please explain why? | 37,826,024 | <p>This is a simple calculator application implemented in a very basic python program. Though the function have a and b as parameters, inside their definition they are able to do the calculation with different variable names (the variable names in which the arguments of the function were stored). The variables x and y ... | 0 | 2016-06-15T04:14:25Z | 37,826,098 | <p>The x and y values are implicitly global. Your function is using the x and y defined in lines</p>
<pre><code>x=float(input("Enter the first number: "))
y=float(input("Enter the second number: "))
</code></pre>
<p>This is considered a bad practice by most since your functions may have side effects and aren't explic... | 0 | 2016-06-15T04:22:08Z | [
"python"
] |
Unmatching variable names and parameters inside a function but code is still working! Can someone please explain why? | 37,826,024 | <p>This is a simple calculator application implemented in a very basic python program. Though the function have a and b as parameters, inside their definition they are able to do the calculation with different variable names (the variable names in which the arguments of the function were stored). The variables x and y ... | 0 | 2016-06-15T04:14:25Z | 37,826,099 | <p>Think about the stack as your program is executing. Because x and y are declared prior to the first call to add you are just adding 'global' variables. As its executing it goes through and does</p>
<pre><code>x=float(input("Enter the first number: ")) # enters 5
y=float(input("Enter the second number: ")) # enters... | 1 | 2016-06-15T04:22:16Z | [
"python"
] |
Manipulating a DataFrame created from a dict(tuple-float) | 37,826,045 | <p>I have been trying to create a DataFrame from a dictionary that has the below structure.</p>
<pre><code>imgAlbmShrDict = {('10', 'photo_album_57'): 20.0,
('10', 'photo_album_8'): 20.0,
('1061', 'photo_album_29'): 100.0,
('1061', 'photo_album_90'): 90.0,
('1102', 'photo_album_29'): 80.0,
('1102', 'photo_album_9... | 1 | 2016-06-15T04:16:19Z | 37,826,127 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Index.get_level_values.html" rel="nofollow"><code>get_level_values</code></a>, because first two columns is <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow"><code>Multiindex</code></a>:</p>
<pre><code... | 2 | 2016-06-15T04:24:49Z | [
"python",
"python-3.x",
"dictionary",
"pandas",
"dataframe"
] |
How to Speed up Test Execution Using Selenium Grid on single machine | 37,826,093 | <p>I am selenium python and I would like to speed up my tests. let's say 5 tests simultaneously. How can I achieve that on the single machine with the help of selenium grid</p>
| 0 | 2016-06-15T04:21:52Z | 37,828,643 | <p>You won't need a Selenium Grid for this. The Grid is used to distribute the test execution across multiple machines. Since you're only using one machine you don't need to use it.</p>
<p>You are running tests so I'm assuming you are using a test framework. You should do some research on how you can run tests in para... | 0 | 2016-06-15T07:21:22Z | [
"python",
"selenium"
] |
How to Speed up Test Execution Using Selenium Grid on single machine | 37,826,093 | <p>I am selenium python and I would like to speed up my tests. let's say 5 tests simultaneously. How can I achieve that on the single machine with the help of selenium grid</p>
| 0 | 2016-06-15T04:21:52Z | 37,844,139 | <p>This is my base class:</p>
<pre><code>class BaseTestCase(object):
_multiprocess_can_split_ = True
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("https://login.com")
self.assertEqual("Authorization required", self.driver.title)
def tearDown(self):
i... | 0 | 2016-06-15T19:26:28Z | [
"python",
"selenium"
] |
Pygame -> Moving a rect inside a class method | 37,826,201 | <p>I have a class called Block, which I use to draw and move the block:</p>
<pre><code>class Block:
def __init__(self, pos_x, pos_y, size_x, size_y):
self._posX = pos_x
self._posY = pos_y
self._sizeX = size_x
self._r = pygame.draw.rect(gameDisplay, (200,100,100), (pos_x,pos_y,size_x... | 2 | 2016-06-15T04:31:30Z | 37,826,650 | <p><code>__init__</code> gets called only once, when you create an instance of a class.</p>
<p>You are trying to update the Block's position and draw it, so you need to have a method that can do that repeatedly.</p>
<pre><code>class Block:
def __init__(self, pos_x, pos_y, size_x, size_y):
self._posX = pos... | 1 | 2016-06-15T05:12:46Z | [
"python",
"class",
"pygame"
] |
Django is checking my ListView again when I am leaving it | 37,826,249 | <p>I got two views, when I go to the url(view1) the view1's Template works perfectly, but, in that template I have a link that send me to the url(view2) and when I click it, the browser show me an error that belongs to the view1. Even if I manually type the second url, it shows me the error from the view1.</p>
<p><str... | 0 | 2016-06-15T04:37:07Z | 37,826,395 | <p>Am not sure how you generating your token with every user, </p>
<p>in this case your token is None, and you are trying to cast to int</p>
<p>this may be the problem </p>
| 0 | 2016-06-15T04:51:01Z | [
"python",
"django"
] |
Django is checking my ListView again when I am leaving it | 37,826,249 | <p>I got two views, when I go to the url(view1) the view1's Template works perfectly, but, in that template I have a link that send me to the url(view2) and when I click it, the browser show me an error that belongs to the view1. Even if I manually type the second url, it shows me the error from the view1.</p>
<p><str... | 0 | 2016-06-15T04:37:07Z | 37,850,404 | <p>As @Daniel Roseman said, the problem was in the end of the url pattern, I didn't terminate the first expression with the $, so it must be like this:</p>
<pre><code>urlpatterns = [
url(r'^activation$', Activation_vw.as_view(), name='activation'),
url(r'^activation-2/$', Activation2_vw.as_view(), name='activation-2'... | 0 | 2016-06-16T05:17:46Z | [
"python",
"django"
] |
Get a specific input in python | 37,826,322 | <p>How do I get a specific input in python such as</p>
<pre><code>variable = input()
if variable == "Specific input":
do stuff
</code></pre>
<p>I need the input to be one of two options say <code>X</code> or <code>O</code></p>
| 0 | 2016-06-15T04:44:31Z | 37,826,534 | <p>Define a list</p>
<pre><code>specific_input = [0, 'x']
</code></pre>
<p>and so</p>
<pre><code>if variable in specific_input:
do awesome_stuff
</code></pre>
| 0 | 2016-06-15T05:03:27Z | [
"python",
"input"
] |
Get a specific input in python | 37,826,322 | <p>How do I get a specific input in python such as</p>
<pre><code>variable = input()
if variable == "Specific input":
do stuff
</code></pre>
<p>I need the input to be one of two options say <code>X</code> or <code>O</code></p>
| 0 | 2016-06-15T04:44:31Z | 37,826,569 | <p>Its Simple Example to use specefic Variable:
This is Simple Code For Convert Between inch 2 CM OR CM 2 Inch:</p>
<pre><code>conv=input("Please Type cm or inch?")
if conv=="cm" :
number=int(input("Please Type Your number: "))
inch=number*0.39370
print(inch)
elif conv=="inch":
number=int(input("Please... | 1 | 2016-06-15T05:06:55Z | [
"python",
"input"
] |
Get a specific input in python | 37,826,322 | <p>How do I get a specific input in python such as</p>
<pre><code>variable = input()
if variable == "Specific input":
do stuff
</code></pre>
<p>I need the input to be one of two options say <code>X</code> or <code>O</code></p>
| 0 | 2016-06-15T04:44:31Z | 37,826,679 | <p>I understand the question more on looping for relevant input (as @SvbZ3r0 has pointed out in comment). For a very beginner in Python it may be hard to even copy code from tutorials, so:</p>
<pre><code>#! /usr/bin/env python
from __future__ import print_function
# HACK A DID ACK to run unchanged under Python v2 and... | 0 | 2016-06-15T05:16:31Z | [
"python",
"input"
] |
Get a specific input in python | 37,826,322 | <p>How do I get a specific input in python such as</p>
<pre><code>variable = input()
if variable == "Specific input":
do stuff
</code></pre>
<p>I need the input to be one of two options say <code>X</code> or <code>O</code></p>
| 0 | 2016-06-15T04:44:31Z | 37,827,696 | <p>The simplest solution would be:</p>
<p><code>variable = input("Enter x or y")
acceptedVals = ['x','y']
if variable in acceptedVals:
do stuff
</code></p>
<p>Or if you want to keep prompting the user for the right use a while loop
<code>
acceptedVals = ['x','y']
while variable not in acceptedVals
variable = ... | 0 | 2016-06-15T06:31:51Z | [
"python",
"input"
] |
HTML data grabbing in python? | 37,826,328 | <p>I'm fairly new to programming and I am trying to take data from a webpage and use it in my python code. Basically, I'm trying to take the price of an item for a game by having python grab the data whenever I run my code, if that makes sense. Here's what I'm struggling with in particular:</p>
<p>The HTML page I'm ... | 0 | 2016-06-15T04:45:17Z | 37,826,435 | <p>If the webpage returns a json-encoded data, then do something like this:</p>
<pre><code>import urllib2
import json
response = urllib2.urlopen("http://services.runescape.com/m=itemdb_oldschool/api/catalogue/detail.json?item=4151")
data = json.load(response)
print(data)
</code></pre>
<p>Extract the relevant key... | 2 | 2016-06-15T04:54:28Z | [
"python",
"web-scraping"
] |
Access web server running on Virtual box ubuntu on host windows machine | 37,826,333 | <p>I'm running Ubuntu using Virtual Box Manager from windows machine. Inside the VM box ubuntu i'm running a python flask application which is running at <a href="http://localhost:5000" rel="nofollow">http://localhost:5000</a>.</p>
<p>I tried to access the VM box localhost URL on windows machine using the VM box IP wh... | 0 | 2016-06-15T04:45:41Z | 37,826,501 | <p>You need to specify a host='0.0.0.0' while starting your app. By default it will only accept requests from localhost. So if you are sending a request from some other IP then you must have to specify a host.</p>
<p>See below example.</p>
<pre><code>from flask import Flask
app = Flask(__name__)
@app.route("/")
def ... | 2 | 2016-06-15T05:00:44Z | [
"python",
"flask",
"virtualbox"
] |
Access web server running on Virtual box ubuntu on host windows machine | 37,826,333 | <p>I'm running Ubuntu using Virtual Box Manager from windows machine. Inside the VM box ubuntu i'm running a python flask application which is running at <a href="http://localhost:5000" rel="nofollow">http://localhost:5000</a>.</p>
<p>I tried to access the VM box localhost URL on windows machine using the VM box IP wh... | 0 | 2016-06-15T04:45:41Z | 37,840,801 | <p>Below code will allow you to access Flask web from any public IP instead of 127.0.0.1</p>
<pre><code>if __name__ == '__main__':
app.run(host='0.0.0.0', debug='TRUE')
</code></pre>
<p>By default Flask runs on port: 5000. Sometime on VM this port will be blocked. To allow traffic on this port execute below comman... | 0 | 2016-06-15T16:20:58Z | [
"python",
"flask",
"virtualbox"
] |
how to understand this example of __getattr__ as metaclass method | 37,826,361 | <p>Here is a snippet of example from Mark Lutz's book "Learning Python". I found it difficult to understand as to how name accesses are translated into getattr() calls in the metaclass:</p>
<pre><code>>>> class A(type):
def __getattr__(cls, name):
return getattr(cls.data, name)
>>... | 3 | 2016-06-15T04:48:44Z | 37,826,669 | <ol>
<li><code>B.upper()</code> first looks up <code>B.upper</code> and then calls it with no arguments. <code>B.upper</code> is looked up by trying several options in a certain order, eventually trying <code>type(B).__getattr__(B, 'upper')</code>, which in this case is <code>A.__getattr__(B, 'upper')</code>, which ret... | 2 | 2016-06-15T05:14:55Z | [
"python"
] |
how to understand this example of __getattr__ as metaclass method | 37,826,361 | <p>Here is a snippet of example from Mark Lutz's book "Learning Python". I found it difficult to understand as to how name accesses are translated into getattr() calls in the metaclass:</p>
<pre><code>>>> class A(type):
def __getattr__(cls, name):
return getattr(cls.data, name)
>>... | 3 | 2016-06-15T04:48:44Z | 37,826,765 | <p>First you don't need to add the usual confusion of a meta class to get this behaviour, you can just as easily use a regular class and an instance to use as an example:</p>
<pre><code>class A():
def __getattr__(cls, name):
return getattr(cls.data, name)
B = A()
B.data = "spam"
>>> B.data
'sp... | 1 | 2016-06-15T05:23:23Z | [
"python"
] |
Iterating over list element to get specific data | 37,826,600 | <p>I have following data which is a part of gedcom file (family tree data file)</p>
<pre><code>0 @I4@ INDI
1 NAME Milo /Vettle/
2 GIVN Milo
2 SURN Vettle
2 _MARNM Vettle
1 SEX M
1 BIRT
2 DATE 23 OCT 1930
1 FAMS @F3@
0 @I5@ INDI
1 NAME Rosy /Huleknberg/
2 GIVN Rosy
2 SURN Huleknberg
2 _MARNM Vettle
1 SEX F
1 BIRT
2 DAT... | 0 | 2016-06-15T05:09:06Z | 37,826,931 | <p>THanks for editing the question with sample code. Here is a solution that sets a trigger when encountering 'BIRT' in a line, and only if set, outputs a line with 'DATE' in it. Note, if you would also only want lines with 'DATE' in it <strong>directly</strong> following the 'BIRT' line, you have to modify the code a ... | 0 | 2016-06-15T05:36:29Z | [
"python"
] |
Iterating over list element to get specific data | 37,826,600 | <p>I have following data which is a part of gedcom file (family tree data file)</p>
<pre><code>0 @I4@ INDI
1 NAME Milo /Vettle/
2 GIVN Milo
2 SURN Vettle
2 _MARNM Vettle
1 SEX M
1 BIRT
2 DATE 23 OCT 1930
1 FAMS @F3@
0 @I5@ INDI
1 NAME Rosy /Huleknberg/
2 GIVN Rosy
2 SURN Huleknberg
2 _MARNM Vettle
1 SEX F
1 BIRT
2 DAT... | 0 | 2016-06-15T05:09:06Z | 37,826,968 | <p>Following is something I came up in one shot, its not pretty and elegant but you can use it as reference to build on your own solution</p>
<pre><code>def test():
text = ''' 0 @I4@ INDI
1 NAME Milo /Vettle/
2 GIVN Milo
2 SURN Vettle
2 _MARNM Vettl... | 0 | 2016-06-15T05:39:19Z | [
"python"
] |
Iterating over list element to get specific data | 37,826,600 | <p>I have following data which is a part of gedcom file (family tree data file)</p>
<pre><code>0 @I4@ INDI
1 NAME Milo /Vettle/
2 GIVN Milo
2 SURN Vettle
2 _MARNM Vettle
1 SEX M
1 BIRT
2 DATE 23 OCT 1930
1 FAMS @F3@
0 @I5@ INDI
1 NAME Rosy /Huleknberg/
2 GIVN Rosy
2 SURN Huleknberg
2 _MARNM Vettle
1 SEX F
1 BIRT
2 DAT... | 0 | 2016-06-15T05:09:06Z | 37,836,067 | <p>Use <a href="http://linux.die.net/man/1/grep" rel="nofollow"><code>grep</code></a>:</p>
<pre><code>$ grep -A1 '1 BIRT' so.txt | grep -E '^2'
2 DATE 23 OCT 1930
2 DATE 15 SEP 1928
</code></pre>
| 0 | 2016-06-15T12:53:27Z | [
"python"
] |
Python: Not all arguments converted during string formation | 37,826,690 | <p>I'm writing a game of Pong in Pygame but when I try to run it, I get this error stating: </p>
<pre><code>TypeError: not all arguments converted during string formatting
</code></pre>
<p>I'm still new to Python and don't quite understand what's happened. Code from problem below:</p>
<pre><code>def displayScore(pla... | 0 | 2016-06-15T05:18:12Z | 37,827,147 | <p>Since you are "new": </p>
<blockquote>
<p>not all arguments converted during string formatting</p>
</blockquote>
<p>indicates that your are not passing enough or too many variables for the string substitution. Using str() explicitly might also help you get to your own answer, as the output of the text will hint ... | 1 | 2016-06-15T05:54:14Z | [
"python",
"string",
"formatting"
] |
finding the difference between two values of a dictionary inside a list in python | 37,826,809 | <p>I have a list like </p>
<pre><code>d=[{'temp': 39.1, 'date': datetime.datetime(2016, 6, 3, 12, 32, 35)}, {'temp': 39.1, 'date': datetime.datetime(2016, 6, 3, 13, 32, 35)}, {'temp': 39.1, 'date': datetime.datetime(2016, 6, 3, 22, 32, 35)}]
</code></pre>
<p>I want to iterate the list and check whether the difference... | -4 | 2016-06-15T05:26:42Z | 37,827,232 | <p>Hope this helps.</p>
<pre><code>import datetime
d = [{'temp': 39.1, 'date': datetime.datetime(2017, 6, 3, 13, 32, 35)}, {'temp': 39.1, 'date': datetime.datetime(2016, 6, 3, 12, 32, 35)}, {'temp': 39.1, 'date': datetime.datetime(2016, 6, 3, 12, 32, 35)}]
def compare(data, field):
#the code
if len(data) <... | 1 | 2016-06-15T06:00:23Z | [
"python"
] |
What is the difference between the two python statements? | 37,826,954 | <p>Please explain the meaning of the two statements:</p>
<p><code>obj = ClassName</code> and
<code>obj = ClassName()</code></p>
| -10 | 2016-06-15T05:38:07Z | 37,826,991 | <p><code>ClassName</code> is a reference to the class. <code>Classname()</code> instantiates an object of that class.</p>
| 1 | 2016-06-15T05:41:08Z | [
"python"
] |
What is the difference between the two python statements? | 37,826,954 | <p>Please explain the meaning of the two statements:</p>
<p><code>obj = ClassName</code> and
<code>obj = ClassName()</code></p>
| -10 | 2016-06-15T05:38:07Z | 37,827,101 | <p>Everything is a first class object in Python. </p>
<p><code>ClassName</code> will return a reference to the type <code>ClassName</code> and <code>ClassName()</code> calls the <code>__init__()</code> method of class <code>ClassName</code>.</p>
<p>If you are familiar with Java, then <code>ClassName()</code> calls th... | 0 | 2016-06-15T05:51:16Z | [
"python"
] |
How to use sqlite3 in python on FreeBSD? | 37,827,089 | <p>I want to use <code>sqlite3</code> in <code>python</code> on my <code>FreeBSD 10.3</code>. After installing <code>python</code>, it prompts I should install the following additional packages: </p>
<pre><code>......
===========================================================================
Note that some standard... | 0 | 2016-06-15T05:49:44Z | 37,848,932 | <p>The root cause has been found, I installed <strong>databases/sqlite3</strong>, not <strong>databases/py-sqlite3</strong>. After installing <strong>databases/py-sqlite3</strong>, it works.</p>
| 0 | 2016-06-16T02:32:27Z | [
"python",
"sqlite3",
"freebsd"
] |
How to get value using key in python multi dictionary | 37,827,133 | <pre><code>{
"card_quota": 0,
"custom_data": "{\"child_name\":\"íì¤\",\"uid\":\"29\",\"lid\":\"56\",\"count\":\"1\",\"schedule\":\"2016-06-18(í )\"}",
"escrow": false
}
</code></pre>
<p>This is dictionary type of python. I konw to get value using a code like temp['card_quata']. But i want to know using key in [... | 1 | 2016-06-15T05:53:22Z | 37,827,185 | <p>You can simply get the values of any dictionary using the keys. So lets take it step by step:
first, lets get the dictionary - </p>
<pre><code>temp['custom_data']
</code></pre>
<p>will give you the child dictionary, then, in order to access the items of this child dict, you can use the child keys:</p>
<pre><code>... | -1 | 2016-06-15T05:56:57Z | [
"python",
"json",
"dictionary"
] |
How to get value using key in python multi dictionary | 37,827,133 | <pre><code>{
"card_quota": 0,
"custom_data": "{\"child_name\":\"íì¤\",\"uid\":\"29\",\"lid\":\"56\",\"count\":\"1\",\"schedule\":\"2016-06-18(í )\"}",
"escrow": false
}
</code></pre>
<p>This is dictionary type of python. I konw to get value using a code like temp['card_quata']. But i want to know using key in [... | 1 | 2016-06-15T05:53:22Z | 37,827,219 | <p>You can parse <code>custom_data</code> with <a href="https://docs.python.org/2/library/json.html#json.loads" rel="nofollow"><code>json.loads</code></a> and then access the returned <code>dict</code>:</p>
<pre><code>>>> import json
>>> json.loads(temp['custom_data'])['child_name']
'íì¤'
</code><... | 4 | 2016-06-15T05:59:40Z | [
"python",
"json",
"dictionary"
] |
Python how to replace content in the capture group of regex? | 37,827,159 | <p><code>-abc1234567-abc.jpg</code> </p>
<p>I wish to remove <code>-abc</code> before <code>.jpg</code>, and get <code>-abc1234567.jpg</code>. I tried <code>re.sub(r'\d(-abc).jpg$', '', string)</code>, but it will also replace contents outside of the capture group, and give me <code>-abc123456</code>. Is it possible t... | 0 | 2016-06-15T05:54:46Z | 37,827,226 | <p>One solution is to use positive lookahead as follows.</p>
<pre><code>import re
p = re.compile(ur'(\-abc)(?=\.jpg)')
test_str = u"-abc1234567-abc.jpg"
subst = u""
result = re.sub(p, subst, test_str)
</code></pre>
<p>OR </p>
<p>You can use two capture groups as follows. </p>
<pre><code>import re
p = re.compi... | 2 | 2016-06-15T06:00:10Z | [
"python",
"regex"
] |
Python how to replace content in the capture group of regex? | 37,827,159 | <p><code>-abc1234567-abc.jpg</code> </p>
<p>I wish to remove <code>-abc</code> before <code>.jpg</code>, and get <code>-abc1234567.jpg</code>. I tried <code>re.sub(r'\d(-abc).jpg$', '', string)</code>, but it will also replace contents outside of the capture group, and give me <code>-abc123456</code>. Is it possible t... | 0 | 2016-06-15T05:54:46Z | 37,827,348 | <p>If you only want to remove -abc in only jpg files, you could use:</p>
<pre><code>re.sub(r"-abc\.jpg$", ".jpg", string)
</code></pre>
<p>To use your code as close as possible: you should place '()' around the part you want to keep, not the part you want to remove. Then use <code>\g<NUMBER></code> to select th... | 0 | 2016-06-15T06:09:07Z | [
"python",
"regex"
] |
Convert Mysql timestamp to Python's datetime | 37,827,160 | <p>I have a table in MySQL that has a column with <code>TIMESTAMP</code> datatype.
This is what the value on that column looks like on MySQL. </p>
<p><a href="http://i.stack.imgur.com/LsfEH.png" rel="nofollow"><img src="http://i.stack.imgur.com/LsfEH.png" alt="enter image description here"></a></p>
<p>When I try to f... | 1 | 2016-06-15T05:54:46Z | 37,827,267 | <p>You're using <code>%m</code> as the third argument which is month. There is no 26th month, so it is advancing the time forward to compensate.</p>
<p>This should most likely be <code>%d</code>.</p>
| 4 | 2016-06-15T06:04:05Z | [
"python",
"mysql",
"datetime"
] |
Simple images will detect but complex images wont get detected by HoughLine modified code | 37,827,224 | <p>I'm working on a project which I needed to detect the roof.For the moment, I'm detecting the angled lines. After some attempt, I was able to come up with a solution to detect a roof. But when I'm testing it with various type of roof plane(complex one) it isn't accurate to do the detection.</p>
<p>This is the code w... | 4 | 2016-06-15T06:00:01Z | 37,827,950 | <p>In your first version you have this part of code:</p>
<pre><code>for rho,theta in lines[0]:
if( 20 < 180*theta/np.pi < 88):
cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255),3)
plt.scatter(x1, y1)
plt.scatter(x2, y2)
if (160 > 180 * theta / np.pi > 93):
cv2.line(i... | 1 | 2016-06-15T06:47:36Z | [
"python",
"opencv",
"image-processing",
"hough-transform"
] |
Tensorflow ImportError on OS X | 37,827,290 | <p>TL;DR getting <code>ImportError: cannot import name pywrap_tensorflow
</code> when trying to use TensorFlow on El Capitan.</p>
<p>Details: I followed the TensorFlow installation instructions for Mac OS X from <a href="https://www.tensorflow.org/versions/r0.9/get_started/os_setup.html#pip-installation" rel="nofoll... | 1 | 2016-06-15T06:05:18Z | 37,827,848 | <p><strong>TL;DR:</strong> Don't run <code>ipython</code> (or <code>python</code>) from the root of the TensorFlow git repository when you want to <code>import tensorflow</code>.</p>
<p>I answered a similar question <a href="http://stackoverflow.com/a/35963479/3574081">here</a>. The easiest solution is to <code>cd</co... | 1 | 2016-06-15T06:41:38Z | [
"python",
"osx",
"tensorflow"
] |
getting an error called break out of loop | 37,827,327 | <pre><code>class random:
name=input("please enter your name")
def check(self):
if(self.name=="xyz"):
print("hello",name)
break
else:
print("get the owner!!!!")
while True:
nam=random()
nam.check()
</code></pre>
| -5 | 2016-06-15T06:07:16Z | 37,827,467 | <p>Your <code>break</code> is not directly inside of a loop, even though the function that contains the <code>break</code> is called from a loop it doesn't work. There is also absolutely no reason to use a class with a method to do the simple example above. I have refactored your example!</p>
<pre><code>def is_valid_n... | 0 | 2016-06-15T06:17:37Z | [
"python"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.