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
"Backlog" of a loop through a list in Python
39,785,543
<p>I have a weird Python beginner's question,.. playing around in my virtual env in the interpreter (python 3.5):</p> <p>I have a list with mixed types: </p> <pre><code>lissi = ["foo", "bar". "boo", "baz", 4, 7] </code></pre> <p>And then "accidentally" try to print out all elements in a <strong>for loop</strong> con...
0
2016-09-30T07:00:56Z
39,785,691
<p>It's not a backlog and nothing like "every successfully processed element is removed".<br> Basically on every iteration <code>for</code> loop assigns to variable <code>x</code> the value of next element of list <code>lissi</code> (doesn't have to be a list, can be any iterable).<br> Whenever the loop breaks, due to ...
1
2016-09-30T07:09:57Z
[ "python", "python-3.x", "for-loop", "memory" ]
Python button functions oddly not doing the same
39,785,577
<p>I currently have 2 buttons hooked up to my Raspberry Pi (these are the ones with ring LED's in them) and I'm trying to perform this code</p> <pre><code>#!/usr/bin/env python import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(17, GPIO.OUT) #green LED GPIO.setup(18, GPIO.OU...
12
2016-09-30T07:03:15Z
39,886,705
<p>I was able to reproduce your problem on my Raspberry Pi 1, Model B by running your script and connecting a jumper cable between ground and GPIO27 to simulate red button presses. (Those are pins 25 and 13 on my particular Pi model.) </p> <p>The python interpreter is crashing with a Segmentation Fault in the thread...
9
2016-10-06T02:45:36Z
[ "python", "raspberry-pi", "gpio" ]
ValueError: Filter must not be larger than the input
39,785,661
<p>I am pretty new to machine learning so I am playing around with examples and such. The image size specified in the code is (28,28) But for some reason I keep getting the same ValueError I cant figure out why this is happening.</p> <p>Here's the code:</p> <pre><code>import pandas as pd import numpy as np np.random....
-1
2016-09-30T07:08:19Z
39,805,029
<p>So the problem is with the convolution sizes used. Convolution operations usually <strong>reduce</strong> dimension of the image. Similarly - each pooling operation reduces the size. You have very small images yet applied model architecture which has been designed for a bigger ones, thus at some point, after one of ...
0
2016-10-01T09:31:37Z
[ "python", "pandas", "machine-learning", "keras" ]
I have tried to correct this Django Object set error but it has failed
39,785,662
<pre><code>from django.db import models class Gallery(models.Model): Title = models.CharField(max_length=250) Category = models.CharField(max_length=250) Gallery_logo = models.CharField(max_length=1000) def __str__(self): return self.Title + '_' + self.Gallery_logo class Picture (models.Mod...
1
2016-09-30T07:08:22Z
39,785,861
<p>Since you have just started to learn django , let me point out that field names should begin with a lower case letter. (It's not an error to use upper case but it's confusing and not the standard)</p> <pre><code>class Gallery(models.Model): title = models.CharField(max_length=250) category = models.CharFiel...
1
2016-09-30T07:20:23Z
[ "python", "django" ]
interacting with objects in execfile/subprocess.call on python file with arguments
39,785,663
<p>Python novice here.</p> <p>I am trying to interact with the variables/objects in a python file that requires arguments for its data. <strong>Let's say I can only get this data from arguments</strong>, rather than make a script that includes arguments that would be passed (which means I must use execfile or subproce...
0
2016-09-30T07:08:24Z
39,785,921
<p>Is foo.py under your control? If yes, simply change it, such that it can be run by being imported as module and interacted with. If no, you may need to catch the output as string and newly build your variable <code>bar</code> from it. How you capture the output of a subprocess is answered here for example: <a href=...
0
2016-09-30T07:24:16Z
[ "python", "ipython" ]
Azure python create empty vhd blob
39,785,735
<p>I am using Azure python API to create page blob create_blob and updating the header using the link provided <a href="http://blog.stevenedouard.com/create-a-blank-azure-vm-disk-vhd-without-attaching-it/" rel="nofollow">http://blog.stevenedouard.com/create-a-blank-azure-vm-disk-vhd-without-attaching-it/</a> and updati...
0
2016-09-30T07:12:15Z
39,788,280
<p>I think there may be something wrong with your vhd image. I would suggest you have a look at <a href="https://blogs.msdn.microsoft.com/narahari/2013/01/14/windows-azure-virtual-machines-gotchas/" rel="nofollow">this article</a>.</p> <p>Here is a snippet of that article:</p> <p>Please make sure of the following whe...
0
2016-09-30T09:34:45Z
[ "python", "azure" ]
Azure python create empty vhd blob
39,785,735
<p>I am using Azure python API to create page blob create_blob and updating the header using the link provided <a href="http://blog.stevenedouard.com/create-a-blank-azure-vm-disk-vhd-without-attaching-it/" rel="nofollow">http://blog.stevenedouard.com/create-a-blank-azure-vm-disk-vhd-without-attaching-it/</a> and updati...
0
2016-09-30T07:12:15Z
39,788,981
<p>I think that there are two points that you could focus on.</p> <p>1.The VHD file should be a .vhd file. So ,your code should be 'blob_name='a-new-vhd.vhd''</p> <p>2.The storage account and the VM which you created should be in the same location.</p> <p>Hope it helps. Any concerns, please feel free to let me know...
0
2016-09-30T10:08:34Z
[ "python", "azure" ]
Python compute a specific inner product on vectors
39,785,820
<p>Assume having two vectors with m x 6, n x 6</p> <pre><code>import numpy as np a = np.random.random(m,6) b = np.random.random(n,6) </code></pre> <p>using np.inner works as expected and yields</p> <pre><code>np.inner(a,b).shape (m,n) </code></pre> <p>with every element being the scalar product of each combination....
1
2016-09-30T07:17:26Z
39,786,194
<p>There seems to be an indexing based on some random indices for pairwise multiplication and summing on those two input arrays with function <code>pluckerSide</code>. So, I would list out those indices, index into the arrays with those and finally use <code>matrix-multiplication</code> with <a href="http://docs.scipy....
3
2016-09-30T07:41:04Z
[ "python", "numpy", "vector", "vectorization" ]
multiprocessing pool.map() got "TypeError: list indices must be integers, not str"
39,785,873
<p>I do a multiprocessing with python's <code>multiprocessing.Pool</code> module, but got <code>TypeError: list indices must be integers, not str</code> Error:</p> <p>Here is my code:</p> <pre><code> def getData(qid): r = requests.get("http://api.xxx.com/api?qid=" + qid) if r.status == 200: DBC.save...
0
2016-09-30T07:20:58Z
39,786,016
<p>When a worker task raises an exception, <code>Pool</code> catches it, sends it back to the parent process, and reraises the exception, but this doesn't preserve the original traceback (so you just see where it was reraised in the parent process, which isn't very helpful). At a guess, something in <code>DBC.save</cod...
1
2016-09-30T07:29:55Z
[ "python", "multiprocessing" ]
unable to install JQ via PIP
39,785,890
<p>I am trying to install JQ via PIP in python.</p> <pre><code>pip install jq </code></pre> <p>I am getting following error.</p> <p><strong>Failed building wheel for jq</strong></p> <p><a href="http://i.stack.imgur.com/ywWcL.png" rel="nofollow"><img src="http://i.stack.imgur.com/ywWcL.png" alt="enter image descript...
2
2016-09-30T07:22:24Z
39,786,170
<p>It doesn't appear that jq supports Windows; it says it requires gcc &amp; libtool, which generally means a Unix-like environment.</p>
1
2016-09-30T07:40:02Z
[ "python", "python-2.7", "jq" ]
unable to install JQ via PIP
39,785,890
<p>I am trying to install JQ via PIP in python.</p> <pre><code>pip install jq </code></pre> <p>I am getting following error.</p> <p><strong>Failed building wheel for jq</strong></p> <p><a href="http://i.stack.imgur.com/ywWcL.png" rel="nofollow"><img src="http://i.stack.imgur.com/ywWcL.png" alt="enter image descript...
2
2016-09-30T07:22:24Z
39,839,370
<p>Like you I had a difficult time installing jq </p> <p>In my attempts I had many various errors including the failed building wheel that you are getting. I assume that the problem was on my end and not that the host was temporarily down. My setup: python 2 &amp; 3, Jupyter, brew in addition to pip. The problem was l...
0
2016-10-03T19:53:23Z
[ "python", "python-2.7", "jq" ]
How to get logged in username in views.py in django
39,785,934
<p>Actually i'am very new to django and python. In /templates/home.html, added <strong>{{ user.username }}</strong> it's showing currently logged in username</p> <pre><code>&lt;p&gt;Welcome {{ user.username }} !!!&lt;/p&gt; </code></pre> <p>I want to get currently logged in username in <strong>views.py</strong> file....
0
2016-09-30T07:25:05Z
39,785,992
<p>Provided that you have enabled the <a href="https://docs.djangoproject.com/en/1.10/ref/middleware/#django.contrib.auth.middleware.AuthenticationMiddleware" rel="nofollow">authentication middleware</a>, you don't need to do any of this. The fact that the username shows up in your template indicates that you have enab...
1
2016-09-30T07:28:34Z
[ "python", "html", "django", "authentication", "oauth" ]
Speckle ( Lee Filter) in Python
39,785,970
<p>I am trying to do speckle noise removal in satellite SAR image.I am not getting any package which does speckle noise removal in SAR image. I have tried pyradar but it works with python 2.7 and I am working on Anaconda with python 3.5 on windows. Also Rsgislib is available but it is on Linux. Joseph meiring has also ...
2
2016-09-30T07:27:01Z
39,786,527
<p>This is a fun little problem. Rather than try to find a library for it, why not write it from the definition?</p> <pre><code>from scipy.ndimage.filters import uniform_filter from scipy.ndimage.measurements import variance def lee_filter(img, size): img_mean = uniform_filter(img, (size, size)) img_sqr_mean...
0
2016-09-30T08:01:15Z
[ "python", "python-3.x", "image-processing", "imagefilter", "sar" ]
custom decorator for class viewsets
39,785,980
<p>I have a view set like this </p> <pre><code>class NeProjectsViewSet(viewsets.ViewSet): def list(self, request,org_unique_id): ''' something ''' def create(self, request,org_unique_id): ''' something ''' def retrieve(self): ''' something ''' def update(self, request, pk): ...
0
2016-09-30T07:27:42Z
39,787,007
<p><em>Assuming you are using DRF.</em></p> <p>I think you are going in wrong direction. If this is part of your permission layer you should just add custom permission class to your viewset</p> <p><a href="http://www.django-rest-framework.org/api-guide/permissions/" rel="nofollow">http://www.django-rest-framework.org...
0
2016-09-30T08:30:07Z
[ "python", "django", "python-decorators" ]
How to create a formula that checks who won a tic-tac-toe game without lots of if statements?
39,786,013
<p>I have the following code and feel it could be more efficient. Meaning this is 3x3 board and could be done manually but what if it were a 30x30 board or bigger?</p> <pre><code>x = [[1, 2, 0],[2, 1, 0],[2, 1, 0]] for y in range (3): if ((x[0][0] == x[1][0] == x[2][0] == y) or (x[0][1] == x[1][1] == x[2][1]...
2
2016-09-30T07:29:47Z
39,786,384
<p>If you don't mind about importing numpy, this would work for any square grid and any number of player:</p> <pre><code>import numpy as np def check(arr): def check_one_dim(arr): for player in np.arange(Nplayer)+1: # instead of Nplayer you could write arr.max() arrtest = arr == player...
0
2016-09-30T07:52:37Z
[ "python" ]
How to create a formula that checks who won a tic-tac-toe game without lots of if statements?
39,786,013
<p>I have the following code and feel it could be more efficient. Meaning this is 3x3 board and could be done manually but what if it were a 30x30 board or bigger?</p> <pre><code>x = [[1, 2, 0],[2, 1, 0],[2, 1, 0]] for y in range (3): if ((x[0][0] == x[1][0] == x[2][0] == y) or (x[0][1] == x[1][1] == x[2][1]...
2
2016-09-30T07:29:47Z
39,788,018
<p>You could use a function generator like this:</p> <pre><code>def cell_owner(player): """returns a function which can check if a cell belongs to provided player""" def wrapped(cell): return player == cell return wrapped </code></pre> <p>So you can call <code>cell_owner(1)</code> to get a functio...
0
2016-09-30T09:20:31Z
[ "python" ]
How to create a formula that checks who won a tic-tac-toe game without lots of if statements?
39,786,013
<p>I have the following code and feel it could be more efficient. Meaning this is 3x3 board and could be done manually but what if it were a 30x30 board or bigger?</p> <pre><code>x = [[1, 2, 0],[2, 1, 0],[2, 1, 0]] for y in range (3): if ((x[0][0] == x[1][0] == x[2][0] == y) or (x[0][1] == x[1][1] == x[2][1]...
2
2016-09-30T07:29:47Z
39,815,136
<p>Your solution doesn't work, so efficiency is a secondary issue. Try:</p> <pre><code>x = [[0, 2, 1],[0, 2, 1],[0, 2, 0]] </code></pre> <p>You'll get two answers:</p> <pre><code>Nobody won Player 2 won!!! </code></pre> <p>When checking for no winners, you can't assume all zero in a row or a column means nobody wo...
-1
2016-10-02T08:17:24Z
[ "python" ]
Python join data lines together
39,786,091
<p>Hello i have dataset a few thousand lines which is split in even and odd number lines and i can't find a way to join them together again in the same line. Reading the file and overwriting it is fine or making a new file.</p> <p>I have found this <a href="http://stackoverflow.com/questions/17908317/python-even-numbe...
-1
2016-09-30T07:34:28Z
39,786,294
<p>You can use <code>%</code> (modulus) to determine if the line is odd or even. If it's even, then join together the last line and the current line.</p> <pre><code># Using your dataset as a string data_split = data.split("\n") for i in range(len(data_split)): if i % 2: lines = [data_split[i-1], data_spli...
0
2016-09-30T07:47:25Z
[ "python", "python-2.7", "dataset" ]
Python: Function to return index starting from the end for a string
39,786,203
<p>Is there a function to return the end index instead of the start index of a substring. For example, for</p> <pre><code>string = 'the rain in spain stays mainly in the plain' </code></pre> <p><code>string.foo('mainly ')</code> returns 31, instead of having to use <code>string.index('mainly ')+len('mainly ')</code>?...
0
2016-09-30T07:41:44Z
39,786,341
<p>It can be easily implemented in two lines:</p> <pre><code>def get_sub_end(s, sub): f = s.find(sub) return f if f == -1 else f + len(sub) </code></pre> <p>Usage:</p> <pre><code>test_str = 'the rain in spain stays mainly in the plain' if __name__ == '__main__': print get_sub_end(test_str, "mainly ") #...
0
2016-09-30T07:50:20Z
[ "python", "string", "indexing", "slice" ]
candlestick function not displaying results
39,786,253
<p>When i execute this piece of code the program produces <code>[None, None, None,...]</code></p> <p>I am expecting candlestick diagram</p> <pre><code>import matplotlib.finance as mpf import matplotlib.pyplot as plt start =(2014,5,1) end = (2014,6,30) quotes = mpf.quotes_historical_yahoo_ochl('^GDAXI',start, en...
0
2016-09-30T07:45:09Z
39,786,469
<p>You didn't actually <a href="http://stackoverflow.com/questions/8575062/how-to-show-matplotlib-plots-in-python">show</a> your plot on screen. When I copy your code and add</p> <pre><code>plt.show() </code></pre> <p>at the end of it, it runs just fine.</p>
0
2016-09-30T07:57:43Z
[ "python", "matplotlib" ]
Neural Network Inception v3 doesn't create labels
39,786,320
<p>I am facing an error with testing the Neural Network Inception v3 and Tensorflow.</p> <p>I avtivated and trained the model this way with Python:</p> <pre><code>source tf_files/tensorflow/bin/activate python tf_files/tensorflow/examples/image_retraining/retrain.py --bottleneck_dir=tf_files/bottlenecks --how_many_tr...
0
2016-09-30T07:49:12Z
39,789,136
<p>I solved it. The error occured <strong>because the folder hadn't got enough images to train with</strong>. So after increasing the number of the images from 14 to 38 it gives me the predictions!</p>
0
2016-09-30T10:16:00Z
[ "python", "neural-network", "tensorflow" ]
How to match multiple columns in pandas DataFrame for an "interval"?
39,786,406
<p>I have the following pandas DataFrame:</p> <pre><code>import pandas as pd df = pd.DataFrame('filename.csv') print(df) order start end value 1 1342 1357 category1 1 1459 1489 category7 1 1572 1601 category23 1 1587 1599 category2 1 1591 1639...
2
2016-09-30T07:54:23Z
39,786,538
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>, but if <code>DataFrames</code> are large, sca...
1
2016-09-30T08:01:52Z
[ "python", "pandas", "dataframe", "match", "intervals" ]
Portable PySide libraries?
39,786,420
<p>Is there any way to execute python with pyside on a computer that has only python installed?</p> <p>I need to distribute a simple tool on a lot of computers and we can't install pyside everywhere.</p>
1
2016-09-30T07:55:27Z
39,787,158
<p>PySide is a set of bindings for Qt, which is a library written in C++. And it is not part of the Python core.</p> <p>If you want a GUI that is portable and that can be used with a default Python installation, consider <a href="https://docs.python.org/3/library/tk.html" rel="nofollow"><code>tkinter</code></a>.</p>
2
2016-09-30T08:38:52Z
[ "python", "pyside", "portability" ]
Robot Framework - get span element from table
39,786,528
<p>I'm trying to write some test cases to automatically test my websites but I'm having trouble clicking on checkbox witch is situated on every single row in the left column. User can click on every cell in the row he wants and checkbox will became checked or unchcked.. </p> <p>But I'm not able to simulate this click...
0
2016-09-30T08:01:17Z
39,894,954
<p>Check whether this helps you-</p> <pre><code>${item1} Get Table Cell xpath=//table[contains(@id,'__table1-table')] 1 2 </code></pre> <p><strong>OR</strong></p> <p>${item1} = Get Text //table[contains(@id,'__table1-table')]//tr[1]//td[2]//div/span</p>
0
2016-10-06T11:35:45Z
[ "python", "testing", "automated-tests", "pycharm", "robotframework" ]
Skip some bytes of a file and return content
39,786,543
<p>Given a list of byte ranges that have to be skipped:</p> <pre><code>skip_ranges = [(1, 3), (5,7)] </code></pre> <p>and a binary file:</p> <pre><code>f = open('test', 'rb') </code></pre> <p>What is the fastest way to return file contents without bytes 1-3 and 5-7 without modifying the original file?</p> <p>Input...
0
2016-09-30T08:02:10Z
39,786,625
<p>You said the file might potentially be huge so I have adapted @juanpa.arrivillaga solution to read the file in chunks and yield the individual chunks as a generator:</p> <pre><code>def read_ranges(filename, skip_ranges, chunk_size=1024): with open(filename, 'rb') as f: prev = -1 for start, stop ...
2
2016-09-30T08:07:03Z
[ "python", "python-2.7" ]
Skip some bytes of a file and return content
39,786,543
<p>Given a list of byte ranges that have to be skipped:</p> <pre><code>skip_ranges = [(1, 3), (5,7)] </code></pre> <p>and a binary file:</p> <pre><code>f = open('test', 'rb') </code></pre> <p>What is the fastest way to return file contents without bytes 1-3 and 5-7 without modifying the original file?</p> <p>Input...
0
2016-09-30T08:02:10Z
39,786,961
<p>This approach should be relatively fast:</p> <pre><code>ba = bytearray() with open('test.dat','rb') as f: prev = -1 for start, stop in skip_ranges: ba.extend(f.read(start - prev - 1)) f.seek(stop + 1,0) prev = stop else: ba.extend(f.read()) </code></pre>
0
2016-09-30T08:27:30Z
[ "python", "python-2.7" ]
How to show animation in Python while function is working?
39,786,565
<p>I have a loading-function:</p> <pre><code>def animation(loadingtext): word = list(loadingtext) for i in range(0,len(word)): os.system('cls') lower=word[i-1].lower() word[i-1]=lower caps=word[i].upper() word[i]=caps wordstr=''.join(word) print(wor...
0
2016-09-30T08:03:24Z
39,787,225
<p>First I would not use <code>system("cls")</code> at all: it clears the screen when it might be interesting to still see what was written. I would just prepend a <code>\r</code> to <code>wordstr</code>.</p> <p>Then to have <code>animation</code> to do its display while some other work is done, you could just repeate...
0
2016-09-30T08:42:19Z
[ "python", "function", "animation", "loading" ]
python3 How do I click dropdown box using selenium
39,786,704
<p>I'm trying to click on dropbox using selenium on python3. but I got an error msg.</p> <pre><code> raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchWindowException: Message: Unable to find element on closed window </code></pre> <p>My code is below.</p> <pre><code>driver.find_elem...
0
2016-09-30T08:11:55Z
39,786,853
<p>You can use selenium's <strong>select</strong> Class and its APIs like select_by_index or select_by_value: refer : <a href="http://selenium-python.readthedocs.io/api.html" rel="nofollow">[http://selenium-python.readthedocs.io/api.html]</a></p>
0
2016-09-30T08:22:12Z
[ "python", "selenium" ]
Customising MPL in PyQt
39,786,721
<p>So I've been doing a great deal of research in to PyQt and MPL, and I'm still having some issues that I can't get past. </p> <p><strong>The first is this</strong>: How do you change the FigureCanvas background color (it's the gray part in <a href="http://i.stack.imgur.com/etvHq.jpg" rel="nofollow">this image</a>). ...
1
2016-09-30T08:13:08Z
39,794,379
<p>Thanks for providing a <a href="http://stackoverflow.com/help/mcve">MINIMAL WORKING example</a> and for googling before asking a question. That always saves a lot of time. </p> <p>So the following code produces the image shown below.</p> <pre><code>import sys from PyQt4 import QtGui, QtCore import matplotlib impo...
0
2016-09-30T14:53:21Z
[ "python", "matplotlib", "pyqt5" ]
Reformat datetime value with regex in a textfile
39,786,734
<p>I want to change the time format in some text lines with using regex. How can I use the old time values? My code until now:</p> <pre><code>def file_replace_words(file_in, word_to_replace, replace_with): f = open(file_in, "r+") data = f.readlines() f.seek(0) for line in data: line = re.sub(wo...
2
2016-09-30T08:13:46Z
39,786,795
<p>You may add some more capturing groups into your regex, and use a replacement pattern with corresponding backreferences.</p> <p>Use</p> <pre><code>r'(\d\d)/(\d\d)/(\d\d) - (\d\d:\d\d:\d\d):\d{3}' |- 1-| |- 2-| |-3 -| | ----- 4 ---- | </code></pre> <p>and replace with <code>r'\1.\2.\3 \4'</code>.</p> <p>See t...
1
2016-09-30T08:18:51Z
[ "python", "regex", "datetime", "reformatting" ]
Python: get list with nearest dates and same size for list with dates and values
39,786,772
<p>I am trying to get list of nearest dates for current list of lists (dates and value) </p> <p>Have two lists:</p> <pre><code>[["20160901", 0.244], ["20160902", 0.232], ["20160906", 0.214], ["20160909", 0.235], ["20160910", 0.244], ["20160911", 0.271], ["20160912", 0.239], ["20160914", 0.25], ...] </code></pre>...
0
2016-09-30T08:16:50Z
39,787,447
<pre><code>list_dates = [["20160901", 0.244], ["20160902", 0.232], ["20160906", 0.214], ["20160909", 0.235], ["20160910", 0.244], ["20160911", 0.271], ["20160912", 0.239], ["20160914", 0.25]] list_comp = [["20160907", -9.39979076385498, -6.318868160247803], ["20160913", -10.568793296813965, -6.815752029418945]] ...
-1
2016-09-30T08:53:20Z
[ "python" ]
Extract AJAX content and java scripted content using scrapy
39,786,788
<p>I am trying to crawling this <a href="http://www.freeindex.co.uk/profile(the-main-event-management-company)_266537.htm" rel="nofollow">site</a> and want to extract contact number which is inside the call button.</p> <p>How can I implement this code??</p>
0
2016-09-30T08:18:09Z
39,788,898
<p>Seems like a simple AJAX request is being made to retrieve html string with the phone numbers:</p> <p><a href="http://i.stack.imgur.com/HNQ7y.png" rel="nofollow"><img src="http://i.stack.imgur.com/HNQ7y.png" alt="enter image description here"></a></p> <pre><code>import re import scrapy class MySpider(scrapy.Spide...
1
2016-09-30T10:03:56Z
[ "python", "scrapy", "web-crawler" ]
Python regex not matching against pattern
39,786,906
<p>I'm trying to write a block that will take a file path from the user and check that the file path is a) actually a legitimate file path that opens a file, and b) that the first and last line of the .txt file fit this pattern:</p> <p>-53.750 120.900 49.805</p> <p>As it is now, the code that I'm using is not pattern...
0
2016-09-30T08:24:38Z
39,787,088
<p>You need to add <strong>\</strong> before <strong>.</strong> in you regular expression. like this : [0-9]+<strong>\.</strong>[0-9]</p> <p>Hope it helps, cheers.</p>
-1
2016-09-30T08:34:25Z
[ "python", "regex" ]
Python regex not matching against pattern
39,786,906
<p>I'm trying to write a block that will take a file path from the user and check that the file path is a) actually a legitimate file path that opens a file, and b) that the first and last line of the .txt file fit this pattern:</p> <p>-53.750 120.900 49.805</p> <p>As it is now, the code that I'm using is not pattern...
0
2016-09-30T08:24:38Z
39,787,262
<p>You have a problem of negation. What your code is currently doing is printing the error message only if the first line does not match and the last line does match.</p> <p>It works fine with <code>if not (re.match(regex,firstLine) and re.match(regex,lastLine)):</code>, or <code>if not re.match(regex,firstLine) or no...
1
2016-09-30T08:44:19Z
[ "python", "regex" ]
Python functions recursively calling each other using dictionary storing their name
39,786,925
<p>I have following scenario:</p> <ul> <li>there are multiple function each accepting certain arguments</li> <li>they call each other based on arguments recursively/iteratively till certain conditions that can be inferred from arguments are met</li> <li>I can do <code>if-elif</code> in those functions, but since that ...
0
2016-09-30T08:25:44Z
39,787,025
<p>The dictionary requires that the functions are already defined, while the first call to any of the functions requires that the dictionary is already defined. Therefore, you should define the dictionary <em>after</em> all the function definitions and <em>before</em> making the first call to any of the functions:</p> ...
0
2016-09-30T08:31:16Z
[ "python", "recursion" ]
Django Serializer - Create object with relations
39,786,969
<p>What I'm trying to accomplish is to create and App object through the Django REST Framework. I am using a nested Version object and relate this to a already existing client.</p> <p>This is the model that I have, so you could get a better idea:</p> <pre><code>class Client(models.Model): client = models.CharFiel...
0
2016-09-30T08:28:11Z
39,788,320
<p>Finally!</p> <p>If it helps to someone else, you need to pass the client object to the app when you create it!</p> <pre><code>class AppSerializer(serializers.ModelSerializer): version = VersionSerializer(many=True) client = ClientSerializer() class Meta: model = App fields = ('pk','cli...
0
2016-09-30T09:36:35Z
[ "python", "django", "django-rest-framework" ]
Indexing by datetime pandas dataframe fail
39,787,103
<p>I have the following dataframe <code>df</code>:</p> <pre><code> Candy Apple Banana 2016-09-14 19:00:00 109.202060 121.194138 130.372082 2016-09-14 20:00:00 109.199083 121.188817 130.380736 2016-09-14 21:00:00 109.198894 121.180553 130.366054 2016-09-14 22:00:00 109.1920...
3
2016-09-30T08:35:19Z
39,787,233
<p>You need add <code>[0]</code>, because you need select first item of list:</p> <pre><code>last_row = df.tail(1).index[0] print (last_row) 2016-09-15 11:00:00 </code></pre> <hr> <pre><code>last_row = df.tail(1).index print (last_row) DatetimeIndex(['2016-09-15 11:00:00'], dtype='datetime64[ns]', freq=None) </code>...
2
2016-09-30T08:42:54Z
[ "python", "datetime", "dataframe" ]
Access parameters in parameterized decorators
39,787,192
<p>I'm trying to understand python decorator from this <a href="https://realpython.com/blog/python/primer-on-python-decorators/" rel="nofollow">doc</a>. And was writing my own decorator required to handle API Exceptions.</p> <p>But in my decorator, I'm not getting how to access arguments (<code>method</code>, <code>ap...
0
2016-09-30T08:40:31Z
39,787,430
<p><code>data</code> and <code>api</code> are in the <code>args</code> inside <code>wrapper</code>. <code>method</code> you will have to provide separately, e.g. by parameterising the decorator (see e.g. <a href="http://stackoverflow.com/q/5929107/3001761">python decorators with parameters</a>). You could therefore do ...
2
2016-09-30T08:52:26Z
[ "python", "python-decorators" ]
Pandas - scatter matrix set title
39,787,204
<p>I'm searching for a way to set a title to Pandas <code>scatter matrix</code>:</p> <pre><code>from pandas.tools.plotting import scatter_matrix scatter_matrix(data, alpha=0.5,diagonal='kde') </code></pre> <p>I tried <code>plt.title('scatter-matrix')</code> but it creates a new figure.</p> <p>Any help is appreciate...
1
2016-09-30T08:41:04Z
39,787,437
<p>I think you need <code>suptitle</code>:</p> <pre><code>import matplotlib.pyplot as plt from pandas.tools.plotting import scatter_matrix scatter_matrix(df, alpha=0.5,diagonal='kde') plt.suptitle('scatter-matrix') plt.show() </code></pre>
1
2016-09-30T08:52:35Z
[ "python", "pandas", "plot", "title", "scatter-plot" ]
Regex to match an exact number of floating point numbers
39,787,218
<p>I have a string containing several float (or integer) numbers plus random stuff at the beginning and at the end. I want a regex that matches only the string that contains at least a given number of float and report as a group the first given number of floats.</p> <p>Example: Let's assume the string must contain exa...
0
2016-09-30T08:41:54Z
39,788,228
<p>This regex with otional groups should work for you to match at least 6 numbers in each line:</p> <pre><code>(?:[+-]?\d*\.?\d+(?:E[+-]?\d+)?(?:\s+|$)){6} </code></pre> <p><a href="https://regex101.com/r/valhn1/3" rel="nofollow">RegEx Demo</a></p>
0
2016-09-30T09:31:39Z
[ "python", "regex", "python-2.7" ]
Python SQLAlchemy get retruning ID after inserting
39,787,274
<p>I want to get the ID of the last inserted record after inserting in postgresql using SQLAlchemy. Here is code,</p> <pre><code>insert_record = {list of data} result = connection.execute(tbl_example.insert().returning(tbl_example.c.id), insert_record) print result.id </code></pre> <p>The inserting does fine but I ca...
0
2016-09-30T08:45:01Z
39,787,806
<p>It's located directly in returning object. There is example from <a href="http://docs.sqlalchemy.org/en/latest/core/dml.html" rel="nofollow">documentation:</a></p> <pre><code>stmt = table.update().\ where(table.c.data == 'value').\ values(status='X').\ returning(table.c.server_flag, ...
0
2016-09-30T09:09:29Z
[ "python", "mysql", "postgresql", "sqlalchemy" ]
Python stops at a print statement
39,787,333
<pre><code>while Winner == "": while First_Player_Turn == "Y": while rtd != "": try: rtd = input("{} press enter to roll the dice".format(First_Player)) if rtd == "": dice = random.randint(1, 6) First_Player_Position = dice ...
-3
2016-09-30T08:47:41Z
39,787,501
<p>You do not show the initialisation of the string variables. Your program starts with the following:</p> <pre><code>while Winner == "": while First_Player_Turn == "Y": while rtd != "": </code></pre> <ul> <li>If <code>Winner</code> is initialised as <code>""</code>, the outer loop will run.</li> <li>If <...
0
2016-09-30T08:55:17Z
[ "python" ]
Python stops at a print statement
39,787,333
<pre><code>while Winner == "": while First_Player_Turn == "Y": while rtd != "": try: rtd = input("{} press enter to roll the dice".format(First_Player)) if rtd == "": dice = random.randint(1, 6) First_Player_Position = dice ...
-3
2016-09-30T08:47:41Z
39,801,563
<p>I've figured it out myself, the rtd was conflicting with other rtd's sorry for wasting your time. </p>
0
2016-09-30T23:48:39Z
[ "python" ]
How to parse file and make a dataframe
39,787,518
<p>I have a text file in a bespoke format. I also have a parser that extracts the relevant columns from each line. I would like to read in the file one row at a time and add them to a dataframe.</p> <p>The problem is that appending a row to a dataframe is slow.</p> <p>What is the right way to do this?</p>
0
2016-09-30T08:55:54Z
39,787,622
<p>If the file is large, your code is probably bound by the time to read the file from disk, not the time to add rows to the dataframe, unless you have some concrete profiling data to suggest otherwise. For example on an SSD (read throughput ~ 400MB/s) a 4GB file will take 10 seconds just to load from disk. On an HDD (...
1
2016-09-30T09:01:15Z
[ "python", "pandas" ]
Packages in same namespace: declare version in code
39,787,557
<p>I'm curious about the following situation. Let's say I have two projects named <code>project_alpha</code> and <code>project_bravo</code>, both defining a top-level namespace package <code>mymeta</code>. The layout:</p> <pre><code>project_alpha/ -&gt; mymeta/ -&gt; __init__.py -&gt; project_alpha/...
1
2016-09-30T08:57:54Z
39,792,743
<p>As mentioned in the comments: The command</p> <pre><code>$ python setup.py sdist </code></pre> <p>for <code>mymeta.project_bravo</code> downloads an egg of <code>mymeta.project_alpha</code> from a private pypi repo.</p> <p>Namespace packages are very delicate concerning their imports. </p> <p>e.g. I found out th...
1
2016-09-30T13:29:53Z
[ "python", "setuptools" ]
"Unable to locate the SpatiaLite library." Django
39,787,700
<p>I'm trying to make Django's SQLite3 accept spatial queries. <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/gis/install/spatialite/" rel="nofollow">This tutorial</a> suggests that I add this to settings:</p> <pre><code>SPATIALITE_LIBRARY_PATH = 'mod_spatialite' </code></pre> <p>Which produces this erro...
2
2016-09-30T09:04:25Z
39,881,926
<p>Amusingly enough 5 days later I'm having the same issue. After a little bit of poking around I got it working:</p> <p>Set</p> <pre><code>SPATIALITE_LIBRARY_PATH = 'mod_spatialite' </code></pre> <p>and extract ALL the DLL files from the mod_spatialite-x.x.x-win-x86.7z to your Python installation directory. The dll...
1
2016-10-05T19:12:59Z
[ "python", "django", "sqlite3", "spatial", "geodjango" ]
"Unable to locate the SpatiaLite library." Django
39,787,700
<p>I'm trying to make Django's SQLite3 accept spatial queries. <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/gis/install/spatialite/" rel="nofollow">This tutorial</a> suggests that I add this to settings:</p> <pre><code>SPATIALITE_LIBRARY_PATH = 'mod_spatialite' </code></pre> <p>Which produces this erro...
2
2016-09-30T09:04:25Z
39,977,824
<p>This is how to install SpatiaLite (almost) inside virtualenv for Python 3:</p> <ol> <li>Download <a href="http://sourceforge.net/projects/cyqlite/" rel="nofollow">cyqlite</a> a special SQLite build with R-Tree enabled. It is <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/gis/install/spatialite/#sqlite"...
0
2016-10-11T12:59:04Z
[ "python", "django", "sqlite3", "spatial", "geodjango" ]
PYCURL get a json file with utf-8 encoding problems
39,787,756
<p>i'm facing a problem with my PYCURL request. My json file on the server is encoded in utf-8 and look like this :</p> <pre><code>{ "address" : "123 rue de Labège" } </code></pre> <p>I use PYCURL to get this json and copy it into a new file on my computer. I use Python 2.7 and here is my setup for PYCURL :</p> <...
1
2016-09-30T09:07:29Z
39,787,956
<p>Actually this is totally correct, once you do a <code>print</code> of the variable property, you can see it prints out fine.</p> <p>This is just how Python internally handles Unicode strings. Once PycURL receives the file it will be converted to whatever type is appropriate for the property. In your case this is a ...
2
2016-09-30T09:16:59Z
[ "python", "utf-8", "pycurl" ]
How to get the difference between two 24 hour times?
39,787,787
<p>Is there a simple way in pandas to tell the difference between 24 hour times as follows:</p> <pre><code>9:45 17:10 </code></pre> <p>The difference is 7 hours and 25 minutes which is 445 minutes.</p>
3
2016-09-30T09:08:25Z
39,787,879
<p>Sure:</p> <pre><code>&gt;&gt;&gt; from pandas import Timestamp &gt;&gt;&gt; Timestamp('9:45') Timestamp('2016-09-30 09:45:00') &gt;&gt;&gt; Timestamp('17:10') Timestamp('2016-09-30 17:10:00') &gt;&gt;&gt; Timestamp('17:10') - Timestamp('9:45') Timedelta('0 days 07:25:00') &gt;&gt;&gt; td = Timestamp('17:10') - ...
4
2016-09-30T09:13:42Z
[ "python", "pandas" ]
How to get the difference between two 24 hour times?
39,787,787
<p>Is there a simple way in pandas to tell the difference between 24 hour times as follows:</p> <pre><code>9:45 17:10 </code></pre> <p>The difference is 7 hours and 25 minutes which is 445 minutes.</p>
3
2016-09-30T09:08:25Z
39,788,395
<p>I think you can also use the Python standard library <code>datetime.datetime</code> without installing the pandas.</p> <pre><code>&gt;&gt;&gt; t1 = datetime.datetime.strptime('09:45', '%H:%M') &gt;&gt;&gt; t2 = datetime.datetime.strptime('17:10', '%H:%M') &gt;&gt;&gt; t1 datetime.datetime(1900, 1, 1, 9, 45) &gt;&gt...
2
2016-09-30T09:40:11Z
[ "python", "pandas" ]
How to convert all lists to sets when json file is loaded
39,787,795
<p>I have json files that look like this:</p> <pre><code>{ "K1": { "p": [ "A" ], "s": [ "B", "C" ] }, "K2": { "p": [ "A", "F" ], "s": [ "G", "H", "J"...
2
2016-09-30T09:08:56Z
39,787,955
<p>Below is the one liner expression to achieve this using <code>dict comprehension</code>:</p> <pre><code>&gt;&gt;&gt; {key: {k: set(v) for k, v in nested_dict.items()} for key, nested_dict in data.items()} {'K2': {'s': {'H', 'G', 'J'}, 'p': {'A', 'F'}}, 'K1': {'s': {'B', 'C'}, 'p': {'A'}}} </code></pre> <p>However,...
2
2016-09-30T09:16:59Z
[ "python", "json" ]
How to convert all lists to sets when json file is loaded
39,787,795
<p>I have json files that look like this:</p> <pre><code>{ "K1": { "p": [ "A" ], "s": [ "B", "C" ] }, "K2": { "p": [ "A", "F" ], "s": [ "G", "H", "J"...
2
2016-09-30T09:08:56Z
39,787,960
<p>Although the <code>json</code> library offers many hooks to alter decoding, there is no hook to hook into loading a JSON array.</p> <p>You'll have to recursively update the decoded result afterwards instead:</p> <pre><code>def to_sets(o): if isinstance(o, list): return {to_sets(v) for v in o} elif ...
5
2016-09-30T09:17:15Z
[ "python", "json" ]
How to cross-platform compile on windows for linux using gcc?
39,787,862
<p>My aim is to create cross-platform C++ python modules. I'm using<code>Cyther</code> (cross-platform The Cross-Platform Cython/Python Compiler).</p> <p>Cyther uses <code>GCC</code> to compile modules and gives the user the ability to add GCC command-line args.</p> <p>So, I need run compiler on Windows, but compile ...
1
2016-09-30T09:12:51Z
39,788,143
<p>Gcc must be built separately for each compilation target. It can be built for any target on any host. The target you need is <code>i386-linux-gnu</code> (or often <code>i586-linux-gnu</code>) for 32-bit and <code>x86_64-linux-gnu</code> for 64-bit Linux.</p> <p>Note that it provides separate binaries, <code>i386-li...
1
2016-09-30T09:27:17Z
[ "python", "c++", "linux", "gcc", "cross-compiling" ]
What is the code to ask a user to input a number and print the square and cube of that number in python 3.5?
39,788,059
<p>I'm using Python 3.5.2 and have been asked to write a small program to ask a user to enter a number and the program will then print out the square and the cube of the number entered. This is the code I've written so far:</p> <pre><code> number = input ('Please enter a number ') y = (number)**2 z = (number)**3 pr...
-1
2016-09-30T09:22:34Z
39,788,138
<p>when in doubt, add print statements</p> <pre><code>number = input ('Please enter a number ') print("number is %s of type %s" % (number, type(number))) print("number is {} of type {}".format(number, type(number))) y = number ** 2 print("y is {} of type {}".format(y, type(y))) z = number **3 print("z is {} of type ...
2
2016-09-30T09:26:57Z
[ "python" ]
What is the code to ask a user to input a number and print the square and cube of that number in python 3.5?
39,788,059
<p>I'm using Python 3.5.2 and have been asked to write a small program to ask a user to enter a number and the program will then print out the square and the cube of the number entered. This is the code I've written so far:</p> <pre><code> number = input ('Please enter a number ') y = (number)**2 z = (number)**3 pr...
-1
2016-09-30T09:22:34Z
39,788,151
<p>The error is quite self-explanatory :</p> <pre><code>TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' </code></pre> <p>Basically <code>(number)</code>is a string while <code>2</code>is an integer. What you need to do is convert <code>number</code> from <code>str</code> to <code>int</code>. T...
0
2016-09-30T09:27:48Z
[ "python" ]
Python: edit matrix row in parallel
39,788,140
<p>here is my problem:<br> I would like to define an array of persons and change the entries of this array in a for loop. Since I also would like to see the asymptotics of the resulting distribution, I want to repeat this simulation quiet a lot, thus I'm using a matrix to store the several array in each row. I know how...
0
2016-09-30T09:27:09Z
39,789,694
<p>OK, so this might not be much use, I haven't profiled it to see if there's a speed-up, but list comprehensions will be a little faster than normal loops anyway.</p> <pre><code>... y_ix = np.arange(rep) # create once as same for each loop for i in range(steps): # presumably the two locations in the population to...
0
2016-09-30T10:45:47Z
[ "python", "matrix", "multiprocessing", "row" ]
How do i change my code to not include builtin functions
39,788,247
<p>I had an assignment for school with a test to make a program that checks password strength. as you can see below i've made the program. When I turned it in, I received it back because it's to convenient to use the builtin function <code>any()</code>. how can i adjust or change my program to not include the <code>any...
-4
2016-09-30T09:32:45Z
39,794,108
<p>After fixing errors with the original</p> <pre><code>import time print ("Check of uw wachtwoord veilig genoeg is in dit programma.") time.sleep(1) print ("Uw wachtwoord moet tussen minimaal 6 en maximaal 12 karakters bestaan") print ("U kunt gebruik maken van hoofdletters,getallen en symbolen (@,#,$,%)") klein =...
0
2016-09-30T14:40:21Z
[ "python", "python-3.x" ]
Switching between python2 and python3 as the default python
39,788,251
<p>Is there a standard way to switch between python2 to python3 as the default python, similar to how virtualenv can be used to switch between different sandboxed python environments?</p> <p>I would like to avoid manually fiddling with symlinks and the PATH variable so that the solution is portable.</p> <p>Since it i...
0
2016-09-30T09:33:11Z
39,788,447
<p>I guess you're talking about using Python under Windows because you mention the PATH variable. Recent versions of Python3 ship with the so-called Python launcher. You can run <code>py -2</code> in order to start a Python2 interpreter and <code>py -3</code> in order to start a Python3 interpreter. I hope this answers...
0
2016-09-30T09:43:15Z
[ "python", "python-3.x", "virtualenv", "python-2.x", "pyenv" ]
Switching between python2 and python3 as the default python
39,788,251
<p>Is there a standard way to switch between python2 to python3 as the default python, similar to how virtualenv can be used to switch between different sandboxed python environments?</p> <p>I would like to avoid manually fiddling with symlinks and the PATH variable so that the solution is portable.</p> <p>Since it i...
0
2016-09-30T09:33:11Z
39,788,455
<p><a href="https://linuxconfig.org/how-to-change-from-default-to-alternative-python-version-on-debian-linux" rel="nofollow">This</a> shows us how to use <code>update-alternatives</code> and/or use an alias in <code>~./bashrc</code>: <code>alias python=/usr/local/bin/python2.7</code></p>
0
2016-09-30T09:44:02Z
[ "python", "python-3.x", "virtualenv", "python-2.x", "pyenv" ]
Switching between python2 and python3 as the default python
39,788,251
<p>Is there a standard way to switch between python2 to python3 as the default python, similar to how virtualenv can be used to switch between different sandboxed python environments?</p> <p>I would like to avoid manually fiddling with symlinks and the PATH variable so that the solution is portable.</p> <p>Since it i...
0
2016-09-30T09:33:11Z
39,788,540
<p>There is a way, and it is called <a href="http://conda.pydata.org/docs/intro.html" rel="nofollow">Conda</a> (you can install <a href="http://conda.pydata.org/miniconda.html" rel="nofollow">Miniconda</a> to start with).</p> <p>It lets you create virtual environments in which you can specify the Python interpreter ve...
1
2016-09-30T09:48:09Z
[ "python", "python-3.x", "virtualenv", "python-2.x", "pyenv" ]
Switching between python2 and python3 as the default python
39,788,251
<p>Is there a standard way to switch between python2 to python3 as the default python, similar to how virtualenv can be used to switch between different sandboxed python environments?</p> <p>I would like to avoid manually fiddling with symlinks and the PATH variable so that the solution is portable.</p> <p>Since it i...
0
2016-09-30T09:33:11Z
39,804,955
<p>After some more research it looks like a possible solution could have been <a href="https://github.com/yyuu/pyenv" rel="nofollow">pyenv</a> which is supposed to be used as described in the <a href="https://amaral.northwestern.edu/resources/guides/pyenv-tutorial" rel="nofollow">pyenv tutorial</a> <strong><em>but</em>...
0
2016-10-01T09:23:16Z
[ "python", "python-3.x", "virtualenv", "python-2.x", "pyenv" ]
Obtaining the most informative features after dimensionality reduction
39,788,262
<p>I basically have a python script that tries a variety of dimensionality reduction techniques combined with a variety of classifiers. I attempted to collect the most informative features for each classifier:</p> <pre><code>if 'forest' in type(classifier).__name__.lower(): importances = classifier.feature...
-1
2016-09-30T09:33:52Z
39,796,052
<p>You can't.</p> <p>When you do dimensionality reduction (like PCA), what you get is some new vectors and not a subset of the original feature set. And in the process you lose information. You project the the features of the original feature set, from a high dimensional space to a new (lower) space. You can't go back...
1
2016-09-30T16:27:32Z
[ "python", "machine-learning", "scikit-learn" ]
List index while loop python
39,788,290
<p>I have an issue with the following code. When i typed the exact secret words character, the following code wont match the secret codes. </p> <pre><code>#initiate words for guessing secretWords =['cat','mouse','donkey','ant','lion'] #Generate a random word to be guessed generateWord = (random.choice(secretWords)) ...
-2
2016-09-30T09:35:16Z
39,788,728
<p>You are overriding your selected word. <code>generateWord</code> is at the same time the secret word, and the user input. This can't work. Here is something that should do what you want (I also corrected some other problems):</p> <pre><code>import random secretWords = ["cat", "mouse", "donkey", "ant", "lion"] gen...
0
2016-09-30T09:56:20Z
[ "python" ]
List index while loop python
39,788,290
<p>I have an issue with the following code. When i typed the exact secret words character, the following code wont match the secret codes. </p> <pre><code>#initiate words for guessing secretWords =['cat','mouse','donkey','ant','lion'] #Generate a random word to be guessed generateWord = (random.choice(secretWords)) ...
-2
2016-09-30T09:35:16Z
39,788,802
<p>Why are you comparing one letter in generateWord to the entire userInput?</p> <pre><code>if(generateWord[LetterNumber] == userInput): </code></pre> <p>That line compares the character at "LetterNumber" index to the userInput, so if a user enters a word it will never return true. </p> <p>If you're attempting to co...
2
2016-09-30T09:59:27Z
[ "python" ]
Python NameError: name '' is not defined
39,788,458
<p>I am fairly new to python, i have created this code for a controlled assessment but it is suggesting that 'q11' (the first of the web opening commands) is not defined. It is the same as the others and was working fine before but now i have begun work on it again but it just won't work. </p> <p>Thank you in advance ...
-1
2016-09-30T09:44:13Z
39,790,134
<p>Alright, been working on this for some time for you and I have added the following bits of code:</p> <pre><code>list = [] q1 = str(input("Is your phone charging correctly? ")) characters = len(q1) for i in range(characters): lowercase = str.lower(q1[i]) list.append(lowercase) q1 = ("".join(list)) </code></p...
-1
2016-09-30T11:09:21Z
[ "python", "undefined", "defined" ]
Python NameError: name '' is not defined
39,788,458
<p>I am fairly new to python, i have created this code for a controlled assessment but it is suggesting that 'q11' (the first of the web opening commands) is not defined. It is the same as the others and was working fine before but now i have begun work on it again but it just won't work. </p> <p>Thank you in advance ...
-1
2016-09-30T09:44:13Z
39,790,409
<p>Alternatively you could just make it so they input either y or n which would be a lot less lines of code.</p> <p>All I did differently from my previous answer is simply only made it loop once to change the 'Y' to lowercase or 'N' to lowercase. It's better to make it like this because when people use a program and a...
-1
2016-09-30T11:24:33Z
[ "python", "undefined", "defined" ]
Python NameError: name '' is not defined
39,788,458
<p>I am fairly new to python, i have created this code for a controlled assessment but it is suggesting that 'q11' (the first of the web opening commands) is not defined. It is the same as the others and was working fine before but now i have begun work on it again but it just won't work. </p> <p>Thank you in advance ...
-1
2016-09-30T09:44:13Z
39,790,787
<p>You could even use a dictionary to get rid of all those variables such as sol1, sol2, sol3. That is really messy coding and inefficient. Try this dictionary:</p> <pre><code>solutions = {1: "Check if there is lint in the charging ports. This can be removed\ncarefully with a toothpick or similar implement", ...
-1
2016-09-30T11:45:06Z
[ "python", "undefined", "defined" ]
converter wave 24 bit to 16 bit
39,788,464
<p>i wish to convert some wavs that are 48kHz 24 bit file.wav to 48kHz 16 bit file-2.wav</p> <pre><code>import wave origAudio = wave.open("Sample_5073.wav","r") frameRate = origAudio.getframerate() nChannels = origAudio.getnchannels() sampWidth = origAudio.getsampwidth() nbframe=origAudio.getnframes() da = np.fr...
0
2016-09-30T09:44:33Z
39,804,023
<p>If converting files from 24 to 16 bit is the only thing you want to do, you could use <a href="http://sox.sourceforge.net/" rel="nofollow">SoX</a>, it doesn't get much easier than that:</p> <pre><code>sox file.wav -b 16 file-2.wav </code></pre> <p>SoX can also do many more things, just have a look at its <a href="...
0
2016-10-01T07:20:25Z
[ "python", "signals", "wave", "pyaudio" ]
moment.js date in Django template
39,788,572
<p>I want to display the date of the relevant text (for example, 3 days ago) using the moment.js. But my code does not work.</p> <p>My code, but it does not work:</p> <pre><code>&lt;div class="base"&gt; &lt;script type="text/javascript"&gt; var time = {{ obj.pub_date|date:'Ymd' }}; moment(time, "Y...
0
2016-09-30T09:49:26Z
39,788,691
<p>You are not assigning whatever is returned from your .fromNow() call to a variable, or doing anything with it.</p>
2
2016-09-30T09:54:23Z
[ "javascript", "python", "django", "momentjs" ]
Python SimpleHTTPServer to receive files
39,788,591
<p>I am using SimpleHTTPServer's do_POST method to receive file. The script is working fine if I upload the png file using curl but whenever I use python request library to upload file, File uploads but become corrupt. Here is the SimpleHTTPServer code</p> <pre><code>#!/usr/bin/env python # Simple HTTP Server With Upl...
1
2016-09-30T09:50:19Z
39,794,730
<p><code>curl</code> and <code>request</code> have a slightly different header, <code>curl</code> has an additional empty line while <code>requests</code> doesn't.</p> <p>Replace <code>preline = self.rfile.readline()</code> with the following block</p> <pre><code>if line.strip(): preline = line else: preline ...
0
2016-09-30T15:10:36Z
[ "python", "file-upload", "cgi", "python-requests", "simplehttpserver" ]
Speed optimisation in Flask
39,788,630
<p>My project (Python 2.7) consists of a screen scraper that collects data once a day, extracts what is useful and stores that in a couple of pickles. The pickles are rendered to an HTML-page using Flask/Ninja. All that works, but when running it on my localhost (Windows 10), it's rather slow. I plan to deploy it on Py...
1
2016-09-30T09:52:02Z
39,808,825
<h2>Your Question on Rendering</h2> <p>You can actually do a lot with Jinja. It is possible to run Jinja whenever you want and save it as a HTML file. This way every time you send a request for a file, it doesn't have to render it again. It just serves the static file.</p> <p>Here is some code. I have a view that doe...
1
2016-10-01T16:16:57Z
[ "python", "html", "flask", "ninja" ]
How can I copy one collection from MongoDB using pymongo and paste to another empty collection?
39,788,664
<ol> <li>I want to copy full collection (e.g. name 'home').</li> <li>Then do some changes in the 'home' collection or remove doc inside it (not a collection).</li> <li>And then replace changed 'home' collection to its default state from item 1.</li> </ol> <p>I do next: </p> <pre><code>db = client["database"] home = d...
0
2016-09-30T09:53:31Z
39,927,543
<p>The problem with your code example is that <code>find()</code> returns a <a href="https://docs.mongodb.com/manual/tutorial/iterate-a-cursor/" rel="nofollow">database cursor</a> to the collection, not all documents in the collection. So when you <code>remove</code> all documents from the <code>home</code> collection,...
1
2016-10-08T00:43:48Z
[ "python", "mongodb", "pymongo" ]
Tkinter ttk radiobutton variable update failure
39,788,665
<p>What's wrong with this?</p> <pre><code>var = StringVar() radBut1 = ttk.Radiobutton(root, text='A - Z', variable=var, value='AtoZ') radBut2= ttk.Radiobutton(root, text='Z - A', variable=var, value='ZtoA') </code></pre> <p>When I select either of the 2 radiobuttons, the var variable is not updated. I found a lot of ...
0
2016-09-30T09:53:36Z
39,803,642
<p>This works:</p> <pre><code>def updateRadioButtonVariable(radioButtonVar,updateString): radioButtonVar.set(updateString) #Sort Type Radio Button radioButtonVar = StringVar() radBut1= ttk.Radiobutton(root, text='A - Z', variable=radioButtonVar, value='AtoZ',command= lambda: updateRadioButtonVariable(radioButtonV...
0
2016-10-01T06:18:59Z
[ "python", "tkinter", "radio-button", "ttk" ]
Python - howto keep type of elements in list
39,788,683
<p>Sorry first to the pythonistas, C/C++ programmer having to do some python.</p> <p>I am porting some C (not C++), so I essentially want to create a list of structures to pass around for initialization, processing and writing on to a device over the serial port.</p> <p>I am keeping the python very close to the C so ...
1
2016-09-30T09:54:09Z
39,788,873
<p>You don't have to return True, it is True already if the dictionary is non empty. I would suggest </p> <pre><code>CHANNELS = 14 def init_arrays(): labels = [ "Gain_1:", "Gain_2:", "Gain_48:" ] return {lab: [0]* CHANNELS for lab in labels} </code></pre> <p>then you just process it using </p> <pre><code>Gai...
0
2016-09-30T10:02:40Z
[ "python", "arrays", "recordtype" ]
Python - howto keep type of elements in list
39,788,683
<p>Sorry first to the pythonistas, C/C++ programmer having to do some python.</p> <p>I am porting some C (not C++), so I essentially want to create a list of structures to pass around for initialization, processing and writing on to a device over the serial port.</p> <p>I am keeping the python very close to the C so ...
1
2016-09-30T09:54:09Z
39,789,266
<p>As I said in a comment, first of all, Python is not C. My suggestion is: take advantage of it, and use Python for your own good. Do not try to mimic C code. It will only make things harder.</p> <p>On the other hand, you are flattening your list in an unexpected way. I think instead of:</p> <pre><code>Gains.extend(...
0
2016-09-30T10:22:59Z
[ "python", "arrays", "recordtype" ]
Python - howto keep type of elements in list
39,788,683
<p>Sorry first to the pythonistas, C/C++ programmer having to do some python.</p> <p>I am porting some C (not C++), so I essentially want to create a list of structures to pass around for initialization, processing and writing on to a device over the serial port.</p> <p>I am keeping the python very close to the C so ...
1
2016-09-30T09:54:09Z
39,789,353
<p>I think you should check this string:</p> <pre><code>Gains.extend(entry) </code></pre> <p>which just puts both label and value one after another into Gains list.</p> <p>Consider using</p> <pre><code>Gains.append(entry) </code></pre> <p>which will not unpack the tuple but append it whole to your list.</p>
1
2016-09-30T10:27:40Z
[ "python", "arrays", "recordtype" ]
Python tkinter: Canvas scrollbar appears but doesn't work
39,788,860
<p>I've been trying to add a scrollbar to a canvas that contains a single frame, this frame is what holds the widgets. I have added the scroll bar which shows up correctly but it has no effect on the canvas.</p> <pre><code>area2=Frame(border2,bg="#FAFAFA") area2.pack(side="top",fill=BOTH,expand=True) scrollbar=Scroll...
0
2016-09-30T10:01:56Z
39,791,392
<p>You are trying to embed a frame which contains various other widgets into a canvas so that you can scroll around. However, after you create the <code>scrollcanvasframe</code> you pack it, with is incorrect. The canvas is a geometry manager in its own right and the correct way to make the canvas manage another widget...
1
2016-09-30T12:18:57Z
[ "python", "tkinter" ]
Python 2.7 Tk filedialog calling external programs
39,789,012
<p>I'm beginning to learn how to use python and need to develop some applications for a lab project.</p> <p>I am trying to create a GUI to select a couple of files I want to pass as arguments to another program. The GUI part seems to work, but when I try to call the external script using Popen method but the variables...
-1
2016-09-30T10:10:16Z
39,790,242
<p>Your <code>fasta</code> and <code>lista</code> variables are local to the <code>button_*</code> functions and are not visible where you try and call <code>Popen</code>. A quick fix would be to use <code>global</code> to make these visible as global variables. A better fix would be to refactor this use use a class an...
1
2016-09-30T11:15:13Z
[ "python", "tkinter", "tk" ]
Prediction of sinusoidal function using pybrain
39,789,128
<p>In an attempt to understand neural networks and pybrain, I tried to predict a sinusoidal function in noise using only the time index as input. The premise therefore is that a simple NN structure can mimic <em>y(t) = sin(t)</em>.</p> <p>The design is: 1 input layer (linear), 1 hidden layer (tanh) and 1 output layer ...
1
2016-09-30T10:15:25Z
39,793,150
<p>With a little bit tuning (more learning steps) it is possible to predict with a neural network exactly the sinus function. To determine the limits of neural networks the prediction of "inverse kinematics" will be more usefull. In that example most neural networks will fail because the solver produces high CPU demand...
-1
2016-09-30T13:50:59Z
[ "python", "neural-network", "time-series", "prediction", "pybrain" ]
Prediction of sinusoidal function using pybrain
39,789,128
<p>In an attempt to understand neural networks and pybrain, I tried to predict a sinusoidal function in noise using only the time index as input. The premise therefore is that a simple NN structure can mimic <em>y(t) = sin(t)</em>.</p> <p>The design is: 1 input layer (linear), 1 hidden layer (tanh) and 1 output layer ...
1
2016-09-30T10:15:25Z
39,823,709
<p>The issue is the range of input and output values. By <a href="https://en.wikipedia.org/wiki/Feature_scaling#Standardization" rel="nofollow">standardizing</a> these signals, the problem is solved.</p> <p><a href="http://i.stack.imgur.com/HmFIi.png" rel="nofollow"><img src="http://i.stack.imgur.com/HmFIi.png" alt="N...
0
2016-10-03T02:09:51Z
[ "python", "neural-network", "time-series", "prediction", "pybrain" ]
Proper way to check type when object might be an object() instance
39,789,249
<p>I'm looking for the proper way to check a type of object that might be an instance of object() now i'm doing this:</p> <pre><code>def _default_json_encoder(obj): """ Default encoder, encountered must have to_dict method to be serialized. """ if hasattr(obj, "to_dict"): return obj.to_dict() ...
0
2016-09-30T10:21:53Z
39,789,424
<p>If you really have instances of <code>object()</code> in your data structure, then you'd use:</p> <pre><code>type(obj) is object </code></pre> <p>to test for direct instances (classes are typically singletons).</p> <p>However, I'd rethink my data structure, and either use another primitive value (like <code>True<...
1
2016-09-30T10:31:29Z
[ "python", "python-3.x", "types" ]
Efficient matrix vector structure for improving cython code
39,789,262
<p>I have to run some simulations over a system of SODEs. Since I need to use random graphs I thought it was a good idea to use python for generating the adjacent matrix for the graph and then C for the simulations. So I turned to cython.</p> <p>I wrote my code following the hints of <a href="http://docs.cython.org/en...
1
2016-09-30T10:22:36Z
39,790,358
<p><code>cython -a</code> color codes the cython source. If you click on a line it shows the corrsponding C source. As a rule of thumb, you don't want anything yellow in your inner loops.</p> <p>A couple of things jump out in your code:</p> <ul> <li><code>x[j][i]</code> creates a temporary array for <code>x[j]</code>...
1
2016-09-30T11:21:29Z
[ "python", "numpy", "optimization", "cython" ]
Python Import Error not working
39,789,284
<p>I currently have the following directory structure: </p> <pre><code>Folder/ package/ __init__.py, .. many python files subfolder/ file1.py </code></pre> <p>Now, my problem is that I am in the <code>Folder</code> directory. I can run python and then run <code>import package</code>. This works fine....
0
2016-09-30T10:23:54Z
39,789,371
<p>Rename <code>_init_.py</code> to <code>__init__.py</code> (two underscores)</p>
0
2016-09-30T10:28:46Z
[ "python", "import" ]
Python Import Error not working
39,789,284
<p>I currently have the following directory structure: </p> <pre><code>Folder/ package/ __init__.py, .. many python files subfolder/ file1.py </code></pre> <p>Now, my problem is that I am in the <code>Folder</code> directory. I can run python and then run <code>import package</code>. This works fine....
0
2016-09-30T10:23:54Z
39,789,516
<p>In the latter case, Python cannot find <code>package</code> because it is not visible on <code>sys.path</code>. <code>sys.path</code> will contain amongst other things the parent directory of the script currently being executed.</p> <p>So when you run Python from <code>Folder</code>, this entry is <code>/path/to/Fo...
2
2016-09-30T10:35:51Z
[ "python", "import" ]
Tensorflow Variables and Ops vs. Python Equivalents
39,789,298
<p>I'm new to Tensorflow.</p> <ul> <li>Is it necessary to use tensorflow's function, such as using <code>tf.constant()</code> to replace <code>int32</code>, <code>float32</code> or else?</li> <li>Also during computation, using <code>tf.mul()</code> instead of normal Python multiplication <code>*</code>?</li> <li>Also ...
0
2016-09-30T10:24:18Z
39,797,939
<p>Because tensorflow is built upon a computation graph. When you construct the graph in python, you are just building is a description of computations (not actually doing the computation). To compute anything, a graph must be launched in a Session. So it's best to do the computation with the tensorflow ops.</p> <p><a...
1
2016-09-30T18:32:29Z
[ "python", "tensorflow" ]
Tensorflow Variables and Ops vs. Python Equivalents
39,789,298
<p>I'm new to Tensorflow.</p> <ul> <li>Is it necessary to use tensorflow's function, such as using <code>tf.constant()</code> to replace <code>int32</code>, <code>float32</code> or else?</li> <li>Also during computation, using <code>tf.mul()</code> instead of normal Python multiplication <code>*</code>?</li> <li>Also ...
0
2016-09-30T10:24:18Z
39,801,361
<p>As noted <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/g3doc/api_docs/python/framework.md#class-tftensor-tensor" rel="nofollow">here</a>, </p> <blockquote> <p>A Tensor is a symbolic handle to one of the outputs of an Operation. It does not hold the values of that operation's output, but...
1
2016-09-30T23:18:20Z
[ "python", "tensorflow" ]
hl7apy not displaying data with multiple OBX fields
39,789,299
<p>I am trying to parse hl7 files using <strong>hl7apy</strong> i am having below hl7 sample</p> <p><strong>sample :</strong></p> <pre><code>MSH|^~\&amp;|XXXX|C|PRIORITYHEALTH|PRIORITYHEALTH|20080511103530||ORU^R01|Q335939501T337311002|P|2.3||| PID|1||94000000000^^^Priority Health||LASTNAME^FIRSTNAME^INIT||19460101|M...
1
2016-09-30T10:24:18Z
39,804,189
<p>You have an error in your code. It should be</p> <pre><code>hl7.replace("\n", "\r") </code></pre> <p>You have to write all groups, if you want to access a field in (a) group(s)</p> <p>try <code>m.ORU_R01_RESPONSE.ORU_R01_ORDER_OBSERVATION.ORU_R01_OBSERVATION.OBX[0].obx_1.value</code> for the first value of the f...
1
2016-10-01T07:41:09Z
[ "python", "hl7", "hl7-v2" ]
Filling dataframe columns based on ranges described in other columns
39,789,503
<p>I have a very interesting problem here, I have a dataset like,</p> <pre><code> id, start, end 1234 200 400 1235 300 500 1236 100 900 1236 200 1200 1236 300 1400 </code></pre> <p><strong>Main Objective</strong> : I want to count the number of concurrent session...
0
2016-09-30T10:35:06Z
39,876,088
<p>In Pandas you could also do this: df[(df.start &lt;= t)&amp;(df.end >= t)].groupby("id").count()['start'].reset_index() where t is your desired time. Just rename the final column accordingly. But I don't know if this can be ported over the pyspark.@Khris</p>
0
2016-10-05T14:02:03Z
[ "python", "pandas", "dataframe", "pyspark-sql" ]
unable to use cmd command in python
39,789,535
<p>I am using this command to find disk usage in my shell script</p> <pre><code>df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}' </code></pre> <p>I want to use this command in my python script</p> <pre><code>ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("df -h | awk '$NF=="/"{printf "Disk...
0
2016-09-30T10:36:56Z
39,789,574
<p>You are not escaping your double quotes and they are terminating the string early:</p> <pre><code>ssh.exec_command("df -h | awk '$NF==\"/\"{printf \"Disk Usage: %d/%dGB (%s)\\n\", $3,$2,$5}'") </code></pre>
1
2016-09-30T10:39:17Z
[ "python", "shell" ]
unable to use cmd command in python
39,789,535
<p>I am using this command to find disk usage in my shell script</p> <pre><code>df -h | awk '$NF=="/"{printf "Disk Usage: %d/%dGB (%s)\n", $3,$2,$5}' </code></pre> <p>I want to use this command in my python script</p> <pre><code>ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command("df -h | awk '$NF=="/"{printf "Disk...
0
2016-09-30T10:36:56Z
39,790,211
<p>You can try the following using <a href="https://docs.python.org/2/library/shlex.html" rel="nofollow">shlex</a> and <a href="https://docs.python.org/2/library/subprocess.html" rel="nofollow">subprocess</a> to prepare your command string.</p> <pre><code>from subprocess import list2cmdline import shlex cmd = list2cm...
-1
2016-09-30T11:13:43Z
[ "python", "shell" ]
Progressbar to show amount of music played
39,789,577
<p>Suppose I use <code>mp3play</code> module to play mp3 files, and using <code>ttk.Progressbar</code>, I want to show the amount(duration) of music played. Is there any code to achieve it? </p> <p>I also want a timer a to show the duration of music played.</p> <pre><code>import ttk import mp3play self.music = mp3pl...
1
2016-09-30T10:39:30Z
39,789,945
<p>Looking at the code of <code>mp3play</code>module, <code>mp3play.load()</code> returns an <code>AudioClip</code> object. This object has the methods <code>seconds()</code> and <code>milliseconds()</code> that provide the length of the clip in seconds or milliseconds respectively.</p> <p>You can save the time when y...
3
2016-09-30T10:58:56Z
[ "python", "python-2.7", "tkinter" ]
Progressbar to show amount of music played
39,789,577
<p>Suppose I use <code>mp3play</code> module to play mp3 files, and using <code>ttk.Progressbar</code>, I want to show the amount(duration) of music played. Is there any code to achieve it? </p> <p>I also want a timer a to show the duration of music played.</p> <pre><code>import ttk import mp3play self.music = mp3pl...
1
2016-09-30T10:39:30Z
39,790,166
<p>It appears that the mp3play module <a href="https://github.com/michaelgundlach/mp3play/blob/master/mp3play/windows.py" rel="nofollow">uses</a> the Windows <a href="https://msdn.microsoft.com/en-us/library/vs/alm/dd743606(v=vs.85).aspx" rel="nofollow">winmm</a> library. Specifically, it uses function <a href="https:/...
1
2016-09-30T11:10:55Z
[ "python", "python-2.7", "tkinter" ]
How to make Django generic views accessible to logged in users only?
39,789,588
<p>I've implemented the social-auth for Google for users to log in. I cannot understand how to restrict the visitors from accessing the generic views like UpdateView, ListView or CreateView, if they are not logged in with the social-auth system. Here is the code.</p> <p><strong><em>views.py</em></strong></p> <pre><co...
0
2016-09-30T10:40:29Z
39,789,819
<p>You need to import the login_required decorator and put @login_reqired infront of the view. This view will than only be accesable when logged in.</p> <p>Example:</p> <pre><code> from django.contrib.auth.decorators import login_required @login_required #put your view here </code></pre>
0
2016-09-30T10:51:43Z
[ "python", "django", "django-socialauth" ]
How to make Django generic views accessible to logged in users only?
39,789,588
<p>I've implemented the social-auth for Google for users to log in. I cannot understand how to restrict the visitors from accessing the generic views like UpdateView, ListView or CreateView, if they are not logged in with the social-auth system. Here is the code.</p> <p><strong><em>views.py</em></strong></p> <pre><co...
0
2016-09-30T10:40:29Z
39,790,900
<p>We need to write mixins to check whether the user is logged in or not.</p> <p>Django 1.9 has introduced a LoginRequiredMixin:</p> <pre><code>from django.contrib.auth.mixins import LoginRequiredMixin class UserProfile(LoginRequiredMixin, View): login_url = '/login/' </code></pre> <p>The following code is a cu...
0
2016-09-30T11:52:15Z
[ "python", "django", "django-socialauth" ]
How to make Django generic views accessible to logged in users only?
39,789,588
<p>I've implemented the social-auth for Google for users to log in. I cannot understand how to restrict the visitors from accessing the generic views like UpdateView, ListView or CreateView, if they are not logged in with the social-auth system. Here is the code.</p> <p><strong><em>views.py</em></strong></p> <pre><co...
0
2016-09-30T10:40:29Z
39,795,966
<p>So you are using 'social-auth' for your login system. In your case, you will have to use a custom function. I'm assuming you can access the logged in user by referring to: <code>request.SESSION</code></p> <p>If so, then you can override the dispatch method of your CreateView:</p> <pre><code>class AchievementCreate...
0
2016-09-30T16:22:29Z
[ "python", "django", "django-socialauth" ]
Writing a list into the file by using Python
39,789,660
<p>I am trying to write a list into the file. I used:</p> <pre><code>studentFile = open("students1.txt", "w") for ele in studentList: studentFile.write(str(ele) + "\n") studentFile.close() </code></pre> <p>As a result, the output was:</p> <pre><code>['11609036', 'MIT', 'NE'] ['11611262', 'MIT', 'MD'] ['1161349...
0
2016-09-30T10:44:16Z
39,789,691
<p>Use <code>.join</code> to convert each <em>sublist</em> into a string: </p> <pre><code>studentFile.write(' '.join(ele) + "\n") </code></pre> <p>You may find the <a href="https://docs.python.org/3/whatsnew/2.6.html#pep-343-the-with-statement" rel="nofollow"><code>with</code></a> statement which creates a <em>cont...
4
2016-09-30T10:45:45Z
[ "python" ]
Writing a list into the file by using Python
39,789,660
<p>I am trying to write a list into the file. I used:</p> <pre><code>studentFile = open("students1.txt", "w") for ele in studentList: studentFile.write(str(ele) + "\n") studentFile.close() </code></pre> <p>As a result, the output was:</p> <pre><code>['11609036', 'MIT', 'NE'] ['11611262', 'MIT', 'MD'] ['1161349...
0
2016-09-30T10:44:16Z
39,789,843
<p>How does your <code>studentList</code> list look like? I suspect its a nested list and you need another loop to pick individual elements.</p> <pre><code>studentList = [['11609036', 'MIT', 'NE'], ['11611262', 'MIT', 'MD'], ['11613498', 'BIS', 'SA']] studentFile = open("students1.txt", ...
0
2016-09-30T10:53:06Z
[ "python" ]
Why collections.Callable provides __contains__(), __hash__(), __len__() and __call__()
39,789,876
<p>Why does the <a href="https://docs.python.org/2.7/library/collections.html?#collections.Callable" rel="nofollow">documentation</a> says:</p> <blockquote> <p>class collections.Callable</p> <p>ABCs for classes that provide respectively the methods <strong>contains</strong>(), <strong>hash</strong>(), <strong>l...
-1
2016-09-30T10:55:36Z
39,789,924
<p>You misunderstand what that text says. The documentation covers <strong>four</strong> ABCs:</p> <pre><code>class collections.Container class collections.Hashable class collections.Sized class collections.Callable </code></pre> <p>The <a href="http://english.stackexchange.com/questions/24525/what-does-the-word-resp...
1
2016-09-30T10:57:48Z
[ "python", "callable" ]
How to handle alerts with Python?
39,789,983
<p>I wuold like to handle alerts with Python. What I wuold like to do is:</p> <ul> <li>open a url</li> <li>submit a form or click some links</li> <li>check if an alert occurs in the new page</li> </ul> <p>I made this with Javascript using PhantomJS, but I would made even with Python. Here is the javascript code:</p> ...
1
2016-09-30T11:00:59Z
39,791,519
<p>PhantomJS uses GhostDriver to implement the WebDriver Wire Protocol, which is how it works as a headless browser within Selenium. </p> <p>Unfortunately, GhostDriver does not currently support Alerts. Although it looks like they would like help to implement the features:</p> <p><a href="https://github.com/detro/gho...
0
2016-09-30T12:26:20Z
[ "python", "selenium", "selenium-webdriver", "phantomjs", "alert" ]
Pandas dataframe comparison hangs without error message
39,789,990
<p>This is my first pandas attempt, so I was wondering what is the problem. I am trying to compare two dataframe of about 30.000 rows each. My first intuition led me to iterate both dataframes, so for every entry in the df1, we iterate all the rows in the df2 to see if it´s there. </p> <p>Maybe is not necessary at al...
2
2016-09-30T11:01:25Z
39,790,507
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a> with parameter <code>indicator=True</code> and then filter by <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing<...
2
2016-09-30T11:29:15Z
[ "python", "pandas" ]