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
Python readinto: How to convert from an array.array to a custom ctype structure
39,162,028
<p>I have created an array of integers and I would like them to be interpreted by the structure definition which I have created</p> <pre><code>from ctypes import * from array import array class MyStruct(Structure): _fields_ = [("init", c_uint), ("state", c_char), ("constant", c_int...
0
2016-08-26T08:41:59Z
39,252,109
<h2>Solution #1: Star unpacking for one-line initialization</h2> <p>Star-unpacking will work, but only if all the fields in your structure are integer types. In Python 2.x, <code>c_char</code> cannot be initialized from an <code>int</code> (it works fine in 3.5). If you change the type of <code>state</code> to <code>c...
1
2016-08-31T14:16:45Z
[ "python", "arrays", "ctypes", "python-2.x" ]
html5lib requires setuptools version 18.5 or above; please upgrade before installing (you have 0.6)
39,162,033
<p>When i try to give a pip install on my <code>requirements.txt</code> file, it fails as mentioned below: </p> <pre><code>html5lib requires setuptools version 18.5 or above; please upgrade before installing (you have 0.6) Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-5xXCfM/html5lib/ ...
1
2016-08-26T08:42:22Z
39,162,121
<p>Are you on a mac per chance? try adding the --user flag to your pip command</p>
0
2016-08-26T08:46:33Z
[ "python", "pip" ]
html5lib requires setuptools version 18.5 or above; please upgrade before installing (you have 0.6)
39,162,033
<p>When i try to give a pip install on my <code>requirements.txt</code> file, it fails as mentioned below: </p> <pre><code>html5lib requires setuptools version 18.5 or above; please upgrade before installing (you have 0.6) Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-5xXCfM/html5lib/ ...
1
2016-08-26T08:42:22Z
39,644,482
<p>It seems there's a <a href="https://github.com/html5lib/html5lib-python/issues/280" rel="nofollow">bug</a> in older <code>html5lib</code> versions that didn't support old <code>setuptools</code> versions, this is fixed in newer <code>html5lib</code> versions.</p> <p>So you can require a newer version of <code>html5...
2
2016-09-22T16:38:11Z
[ "python", "pip" ]
Spark - How many Executors and Cores are allocated to my spark job
39,162,063
<p>Spark architecture is entirely revolves around the concept of executors and cores. I would like to see practically how many executors and cores running for my spark application running in a cluster. </p> <p>I was trying to use below snippet in my application but no luck.</p> <pre><code>val conf = new SparkConf().s...
2
2016-08-26T08:44:12Z
39,163,142
<h1>Scala (Programmatic way) :</h1> <p><code>getExecutorStorageStatus</code> and <code>getExecutorMemoryStatus</code> both return the number of executors including driver. like below example snippet.</p> <pre><code>/** Method that just returns the current active/registered executors * excluding the driver. ...
1
2016-08-26T09:36:38Z
[ "python", "scala", "hadoop", "apache-spark", "executors" ]
Spark - How many Executors and Cores are allocated to my spark job
39,162,063
<p>Spark architecture is entirely revolves around the concept of executors and cores. I would like to see practically how many executors and cores running for my spark application running in a cluster. </p> <p>I was trying to use below snippet in my application but no luck.</p> <pre><code>val conf = new SparkConf().s...
2
2016-08-26T08:44:12Z
40,105,334
<p>This is python Example to get number of cores (including master's) <code>def workername(): import socket return str(socket.gethostname()) anrdd=sc.parallelize(['','']) namesRDD = anrdd.flatMap(lambda e: (1,workername())) namesRDD.count()</code></p>
0
2016-10-18T10:07:16Z
[ "python", "scala", "hadoop", "apache-spark", "executors" ]
how to increment mac address in python
39,162,221
<p>I am trying to send a request with name, id.no and mac address. This process i need to do for 100 times. i mean 100 different names and id.no's and mac address. I tried doing this. I want output as name1, 1234567679 and aa:bb:cc:dd:11:22. can someone please help me. I have pasted my code and output below </p> <pre...
0
2016-08-26T08:52:30Z
39,163,460
<p>Try this code</p> <pre><code>import time, random mac = "aa:bb:cc:dd:" for i in range(1,100): name = 'name'+ str(i) # getting random number for id id = int(time.time()) + random.randrange(0, 100, 1) # quotient in part 1 mac_end1 = "0" + str(int(i/10)) # remainder in part 2 mac_end2 = ...
0
2016-08-26T09:52:53Z
[ "python" ]
Alternative for numpy.choose that allows an arbitrary or at least more than 32 arguments?
39,162,235
<p>With my code I'm running into an issue where the <code>numpy.choose</code> methods does not accept all the arguments since it is limited by <code>NPY_MAXARGS</code> (<code>=32</code>). Is there an alternative available, that allows an arbitrary number of argument arrays or at least more than <code>32</code> that is ...
2
2016-08-26T08:53:24Z
39,169,371
<p>The indices can be given as lists. Assuming that <code>selections</code> has the same length as <code>choices</code>:</p> <pre><code>b = numpy.array(choices) result = b[range(len(selections)), selections] </code></pre> <p>will give the value in choices specified by the index in selections. See it in action:</p> <...
2
2016-08-26T15:05:51Z
[ "python", "numpy" ]
Alternative for numpy.choose that allows an arbitrary or at least more than 32 arguments?
39,162,235
<p>With my code I'm running into an issue where the <code>numpy.choose</code> methods does not accept all the arguments since it is limited by <code>NPY_MAXARGS</code> (<code>=32</code>). Is there an alternative available, that allows an arbitrary number of argument arrays or at least more than <code>32</code> that is ...
2
2016-08-26T08:53:24Z
39,170,451
<p><code>choose</code> has the 32 object limit because it broadcasts the arrays together. Consider the error messages for these two actions:</p> <pre><code>In [982]: np.arange(33).choose(np.ones((33,33))) ... ValueError: Need at least 1 and at most 32 array objects. In [983]: np.broadcast(*range(33)) ... ValueError: ...
1
2016-08-26T16:06:20Z
[ "python", "numpy" ]
Fit Points With a Smooth Curve
39,162,261
<p>I want to fit a set of points on a image with a <strong>smooth</strong> curve in python. The curve may be open or closed. Moreover, I want to get the curve plotted over the image as a mask that has the same size as the image. Is there any modules or functions I can refer to? Thanks.</p>
-2
2016-08-26T08:54:45Z
39,166,624
<p>This is generally called Parametric Interpolation. There is a scipy function that does just that called <a href="http://scipy.github.io/devdocs/generated/scipy.interpolate.splprep.html" rel="nofollow">splprep</a>. The steps you are requesting are:</p> <p><strong>1)</strong> Smooth a shape (built with ordered points...
0
2016-08-26T12:41:55Z
[ "python", "opencv", "matplotlib", "computer-vision", "skimage" ]
system cannot find the path specified in Python2.7
39,162,304
<p>I am using Python 2.7 on windows. I am getting "Calling function "tests/scripts/Script.py"... The system cannot find the path specified when the tests are executed.</p> <p>How to resolve this?</p>
-1
2016-08-26T08:57:32Z
39,162,542
<p>You need to add python Lib and Scrip path to your system environment. To do that type > Edit the system environment variables in search box of start menu. go to edit variable and add python required path to system path.</p>
0
2016-08-26T09:08:29Z
[ "python", "python-2.7" ]
Python add constant values to argparse parameter
39,162,308
<p>I have googled this around but can't seem to find if this question has been asked already. I want to have a value (say "blah") to be always present for a list option, plus additional arguments if they are provided.</p> <p>e.g.</p> <pre><code>import argparse args = argparse.ArgumentParser() args.add_argument("--foo...
0
2016-08-26T08:57:43Z
39,162,344
<p><code>argparse</code> has no facility to <em>add</em> a fixed set of values to <code>nargs</code> lists. </p> <p>Just do what you already do and explicitly append to the list produced. </p>
0
2016-08-26T08:59:25Z
[ "python", "argparse" ]
Python add constant values to argparse parameter
39,162,308
<p>I have googled this around but can't seem to find if this question has been asked already. I want to have a value (say "blah") to be always present for a list option, plus additional arguments if they are provided.</p> <p>e.g.</p> <pre><code>import argparse args = argparse.ArgumentParser() args.add_argument("--foo...
0
2016-08-26T08:57:43Z
39,162,978
<p>Inspired by <a href="http://stackoverflow.com/questions/8526675/python-argparse-optional-append-argument-with-choices">python argparse - optional append argument with choices</a>, this may be a little overkill, but it may be useful for others that want to use sets and add constant values to options:</p> <pre><code>...
0
2016-08-26T09:29:02Z
[ "python", "argparse" ]
Why does statistics.variance use 'unbiased' sample variance by default?
39,162,505
<p>I have recently started using the statistics module for python.</p> <p>I've noticed that by default the variance() method returns the 'unbiased' variance or sample variance:</p> <pre><code>import statistics as st from random import randint def myVariance(data): # finds the variance of a given set of numbers ...
1
2016-08-26T09:06:44Z
39,195,083
<p>I would argue that almost all the time when people estimate the variance from data they work with a sample. And, by the definition of <em>unbiased estimate</em>, the expected value of the unbiased estimate of the variance equals the population variance.</p> <p>In your code, you use <code>random.randint(0, 1000)</c...
0
2016-08-28T19:39:21Z
[ "python", "statistics", "variance" ]
Use ipdb instead of pdb with py.test --pdb option
39,162,569
<p>I want to use <a href="https://pypi.python.org/pypi/ipdb" rel="nofollow">ipdb</a> instead of <a href="https://docs.python.org/2/library/pdb.html" rel="nofollow">pdb</a> with <a href="http://docs.pytest.org/en/latest/contents.html" rel="nofollow">py.test --pdb</a> option. Is this possible? If so, how?</p> <p>Clearly...
0
2016-08-26T09:09:29Z
39,172,917
<p>Have you tried <a href="https://github.com/mverteuil/pytest-ipdb" rel="nofollow">pytest-ipdb</a>?</p> <p>Looks like it's exactly what you are looking for?</p>
1
2016-08-26T18:46:57Z
[ "python", "py.test", "pdb", "ipdb" ]
AJAX/PYTHON : how to send json value to server
39,162,601
<p>I am a new to Ajax/Python, I don't know how to POST a json value to my python server.</p> <p>Python code: </p> <pre><code>@app.route('/ajouterContact', methods = ['POST']) def ajouterContact(): data = json.loads(request.data) #nom = request.form['nomContact']; contact.append(data) ...
0
2016-08-26T09:11:08Z
39,162,757
<p>You need to provide the contentType in your ajax request:</p> <pre><code>contentType: 'application/json;charset=UTF-8', </code></pre> <p>Then in your server try to debug something like this:</p> <pre><code>request.json </code></pre>
0
2016-08-26T09:19:31Z
[ "python", "ajax" ]
Split each element by bracket in variable and find occurrence
39,162,681
<p>I have a text file which has arrays appended to them<a href="http://i.stack.imgur.com/2B1zP.png" rel="nofollow"><img src="http://i.stack.imgur.com/2B1zP.png" alt="&#39;image&#39;"></a> What I want to do is extract it from the text file and work out how many times <code>index[2]</code> occurs for each word in the tex...
0
2016-08-26T09:15:02Z
39,162,820
<p>To convert your <code>string</code> into <code>list</code>, do:</p> <pre><code>&gt;&gt;&gt; s = "(12, 'a', 'hablar', 'to speak')(51, 'a', 'ocurrir', 'to occur/happen')(12, 'a', 'hablar', 'to speak')(2, 'a', 'poder', 'to be able')(11, 'a', 'llamar', 'to call/name')" &gt;&gt;&gt; s = s.replace(')(', '),(') # s = "(12...
0
2016-08-26T09:21:56Z
[ "python", "text", "matplotlib", "find-occurrences" ]
How to find sum of list of lists using for-loop
39,162,845
<pre><code>prefer_indic = [[[0, 4, 6, 5, 45, 1], [2, 3, 5, 6, 7, 1]],[[0, 0.27, 6, 7, 32, 3], [0.01, 0.39, 0, 0, 0, 0]]] </code></pre> <p>I want to create a sum list that will add every value from every list of lists with each corresponding ones. To be accurate i want: </p> <p><code>sum = [[0+0, 4+0.27, 6+6, 5+7, 45+...
1
2016-08-26T09:23:06Z
39,162,940
<p>Use the <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow"><code>zip()</code> function</a> to pair up elements from 2 or more lists, then use <a href="https://docs.python.org/2/library/functions.html#sum" rel="nofollow"><code>sum()</code></a> to add up the combined values:</p> <pre><code>...
3
2016-08-26T09:27:31Z
[ "python", "python-2.7", "for-loop", "sum" ]
How to find sum of list of lists using for-loop
39,162,845
<pre><code>prefer_indic = [[[0, 4, 6, 5, 45, 1], [2, 3, 5, 6, 7, 1]],[[0, 0.27, 6, 7, 32, 3], [0.01, 0.39, 0, 0, 0, 0]]] </code></pre> <p>I want to create a sum list that will add every value from every list of lists with each corresponding ones. To be accurate i want: </p> <p><code>sum = [[0+0, 4+0.27, 6+6, 5+7, 45+...
1
2016-08-26T09:23:06Z
39,163,054
<p>I would define a function that adds two lists, then use a list comprehension to compute your desired result:</p> <pre><code>def add_lists(a, b): return list(x+y for x, y in zip(a, b)) s = list(add_lists(*l) for l in zip(*prefer_indic)) </code></pre> <p>For you example</p> <pre><code>prefer_indic = [[[0, 4, 6...
0
2016-08-26T09:32:38Z
[ "python", "python-2.7", "for-loop", "sum" ]
Python list of lists conversion into dictionary
39,162,857
<p>I'm trying to convert a list of lists into dictionary, but I'm getting troubles. Would anyone give some tips ?</p> <p>This my input:</p> <pre><code>[['Column1', 'Column2', 'Column3', 'Column4', 'Column5'], ['Value1Column1', 'Value1Column2', 'Value1Column3', 'Value1Column4', 'Value1Column5'], ['Value2Column...
0
2016-08-26T09:23:47Z
39,162,956
<pre><code>a = [['Column1', 'Column2', 'Column3', 'Column4', 'Column5'], ['Value1Column1', 'Value1Column2', 'Value1Column3', 'Value1Column4', 'Value1Column5'], ['Value2Column1', 'Value2Column2', 'Value2Column3', 'Value2Column4', 'Value2Column5']] [{a[0][i]: [j[i] for j in a[1:]] for i in range(len(a[0]))}] </code></pr...
0
2016-08-26T09:28:14Z
[ "python", "dictionary", "data-type-conversion" ]
Python list of lists conversion into dictionary
39,162,857
<p>I'm trying to convert a list of lists into dictionary, but I'm getting troubles. Would anyone give some tips ?</p> <p>This my input:</p> <pre><code>[['Column1', 'Column2', 'Column3', 'Column4', 'Column5'], ['Value1Column1', 'Value1Column2', 'Value1Column3', 'Value1Column4', 'Value1Column5'], ['Value2Column...
0
2016-08-26T09:23:47Z
39,162,961
<p>This is the verbose, but straight forward version:</p> <pre><code>from collections import defaultdict keys = lst[0] rows = lst[1:] result = defaultdict(list) for row in rows: for key, value in zip(keys, row): result[key].append(value) </code></pre>
1
2016-08-26T09:28:23Z
[ "python", "dictionary", "data-type-conversion" ]
Python list of lists conversion into dictionary
39,162,857
<p>I'm trying to convert a list of lists into dictionary, but I'm getting troubles. Would anyone give some tips ?</p> <p>This my input:</p> <pre><code>[['Column1', 'Column2', 'Column3', 'Column4', 'Column5'], ['Value1Column1', 'Value1Column2', 'Value1Column3', 'Value1Column4', 'Value1Column5'], ['Value2Column...
0
2016-08-26T09:23:47Z
39,162,968
<p>It's really simple with <a href="http://stackoverflow.com/questions/1747817/create-a-dictionary-with-list-comprehension-in-python">dict comprehension</a> and <a href="https://docs.python.org/3.5/library/functions.html#zip" rel="nofollow">zip function</a>.</p> <pre><code>seq_of_seq = [['Column1', 'Column2', 'Column3...
4
2016-08-26T09:28:38Z
[ "python", "dictionary", "data-type-conversion" ]
Python access and list the files in network share with username and password
39,162,869
<p>I would like to get list of filenames(Only) from the given FileShare location using Python Language. Here is my Code snippet, but it is not running listing any files.</p> <pre><code> import os from os import walk SQLSR_USER= 'username' SQLSR_PASS= 'password' BACKUP_REPOSITORY_PATH= '\\fileshare\l...
0
2016-08-26T09:24:17Z
39,205,661
<p>Finally I solved my problem using pywin32 module. Below is the code for that.</p> <pre><code> def wnet_connect(host, username, password): unc = ''.join(['\\\\', host]) try: win32wnet.WNetAddConnection2(0, None, unc, None, username, password) except Exception, err: ...
0
2016-08-29T11:51:45Z
[ "python", "python-2.7", "subprocess" ]
Regex for log lines that may be slightly different from each other- in spark
39,162,999
<p>I could write a regex for matching one log line. But my file contains some log lines which differ from the other log lines in that there are just a few extra fields or in a few, the key value pairs are mixed up. </p> <p>Eg. one log line : <code>case_id=1 event_id=35654423 date=30-12-2010 time=11.02 activity=regist...
1
2016-08-26T09:30:06Z
39,163,593
<p>I suggest you use a simple regex to grab keys and values:</p> <pre><code>rx = "(\\S+)=(\\S+)" </code></pre> <p>or</p> <pre><code>rx = "(\\w+)=(\\S+)" </code></pre> <p>See a <a href="https://regex101.com/r/jA0zB2/1" rel="nofollow">regex demo</a>.</p> <p>Then, create a dictionary with <code>re.findall</code>:</p>...
1
2016-08-26T09:59:49Z
[ "python", "regex", "apache-spark", "pyspark" ]
Mock for context-manager fails with AttributeError: __exit__
39,163,207
<p>I am trying to patch some context manager function using a Mock so I can test that the code does sensible things given good, bad, and garbage input. Here is the test code with the <code>with</code> statement in it. The patch is done in the correct place in my code.</p> <pre><code>@patch("__main__.opened_w_error") d...
1
2016-08-26T09:39:33Z
39,163,509
<p>Note that the object you pass to the <em>with</em> statement is the one that should have <code>__enter__</code> and <code>__exit__</code> methods, with the return value from <code>__enter__</code> used for the <code>as</code> construct. In your case, you are calling <code>mo(...)</code>, which returns <code>(Mock(),...
1
2016-08-26T09:55:40Z
[ "python", "mocking" ]
Mock for context-manager fails with AttributeError: __exit__
39,163,207
<p>I am trying to patch some context manager function using a Mock so I can test that the code does sensible things given good, bad, and garbage input. Here is the test code with the <code>with</code> statement in it. The patch is done in the correct place in my code.</p> <pre><code>@patch("__main__.opened_w_error") d...
1
2016-08-26T09:39:33Z
39,164,160
<p>The issue is when you're calling <code>mo(..)</code> the object it is returning(<code>tuple</code>) doesn't have <code>__enter__</code> and <code>__exit__</code> attributes on it.</p> <p>To fix this assign <code>mo</code> to <code>mo</code>'s <code>return_value</code> so that the context manager attributes you're s...
1
2016-08-26T10:29:47Z
[ "python", "mocking" ]
Python HMAC hashed value encoding to base64
39,163,297
<p>I am trying to make a twitter auth with the help of django middleware, where I calculate the signature of a request like this (<a href="https://dev.twitter.com/oauth/overview/creating-signatures" rel="nofollow">https://dev.twitter.com/oauth/overview/creating-signatures</a>):</p> <pre><code> key = b"MY_KEY&amp;" ...
0
2016-08-26T09:43:40Z
39,165,115
<p>The trick is to use <code>base64</code> module directly instead of str/byte encoding, which supports binary.</p> <blockquote> <p>You can fit it like this (untested in your context, should work):</p> </blockquote> <pre><code>import base64 #byte encoding for HMAC, otherwise it returns "expected bytes or bytearray,...
0
2016-08-26T11:20:30Z
[ "python", "django", "twitter", "base64", "hmacsha1" ]
How does one copy the users on protected ranges of Google Sheets with the REST API?
39,163,323
<p>I am trying to copy a Google sheet using an HTTP get request. The following is an excerpt from my code.</p> <pre><code> data = {"title": name_gdocs, "description": record_url, "parents": fields_dict['parents']} request_url = "https://www.googleapis.com/drive/v2/files/%s/copy?access_token=%s" % (template_id, ...
1
2016-08-26T09:45:04Z
39,185,515
<p>The solution <em>is</em> to use the Sheets API. The Drive API does not have the functionality to duplicate the owners on the protected ranges. Keep in mind that I used the REST API but the same function calls should essentially be made with language specific libraries.</p> <h1>Making the copy</h1> <p>The url synta...
0
2016-08-27T20:34:20Z
[ "python", "http", "google-drive-sdk" ]
Scraping a website that requires authentication
39,163,352
<p>I know this question might seem quite straight forward, but I have tried every suggestion and none has worked.</p> <p>I want to build a Python script that checks my school website to see if new grades have been put up. However I cannot for the life of me figure out how to scrape it.</p> <p>The website redirects to...
0
2016-08-26T09:46:47Z
39,164,406
<p>You can try with requests: <a href="http://docs.python-requests.org/en/master/" rel="nofollow">http://docs.python-requests.org/en/master/</a></p> <p>from the web site:</p> <pre><code>import requests r = requests.get('https://api.github.com/user', auth=('user', 'pass')) </code></pre>
0
2016-08-26T10:43:33Z
[ "python" ]
Scraping a website that requires authentication
39,163,352
<p>I know this question might seem quite straight forward, but I have tried every suggestion and none has worked.</p> <p>I want to build a Python script that checks my school website to see if new grades have been put up. However I cannot for the life of me figure out how to scrape it.</p> <p>The website redirects to...
0
2016-08-26T09:46:47Z
39,166,053
<p>Maybe you can use Selenium library.</p> <p>I let you my code example:</p> <pre><code>from selenium import webdriver def loging(): browser = webdriver.Firefox() browser.get("www.your_url.com") #Edit the XPATH of Loging INPUT username xpath_username = "//input[@class='username']" #Edit the X...
0
2016-08-26T12:12:16Z
[ "python" ]
Evaluating Logistic regression with cross validation
39,163,354
<p>I would like to use cross validation to test/train my dataset and evaluate the performance of the logistic regression model on the entire dataset and not only on the test set (e.g. 25%). </p> <p>These concepts are totally new to me and am not very sure if am doing it right. I would be grateful if anyone could advis...
1
2016-08-26T09:46:52Z
39,169,661
<p>You got it almost right. <code>cross_validation.cross_val_predict</code> gives you predictions for the entire dataset. You just need to remove <code>logreg.fit</code> earlier in the code. Specifically, what it does is the following: It divides your dataset in to <code>n</code> folds and in each iteration it leaves o...
1
2016-08-26T15:22:20Z
[ "python", "scikit-learn", "logistic-regression", "cross-validation" ]
Django Rest Framework upload multiply images at once with serializer
39,163,363
<p>I had some research on web for this problem on DRF. When one image is in post DRF works great. But when 3 or 5 images are in one post there is problem that Django save only first image from POST query and others are not saved in database. The question is how to properly handle multiply images upload in one post.</p>...
0
2016-08-26T09:47:29Z
39,163,492
<p>Try setting filenames for your images, I mean replace <code>filename=""</code> with something like <code>filename="image-1"</code>, <code>filename="image-2"</code>, etc. Files should have different filenames or they override each other.</p>
0
2016-08-26T09:54:52Z
[ "python", "django", "image", "rest", "file-upload" ]
Django Rest Framework upload multiply images at once with serializer
39,163,363
<p>I had some research on web for this problem on DRF. When one image is in post DRF works great. But when 3 or 5 images are in one post there is problem that Django save only first image from POST query and others are not saved in database. The question is how to properly handle multiply images upload in one post.</p>...
0
2016-08-26T09:47:29Z
39,163,493
<p>Simply add</p> <pre><code>many=True </code></pre> <p>with the serializer initializer. For eg.:</p> <pre><code>serializer = SerializerUserImages(data=request.data, many=True) </code></pre> <p>This should do the trick. </p> <p>Also have a look at <a href="http://www.django-rest-framework.org/api-guide/serializers...
0
2016-08-26T09:54:55Z
[ "python", "django", "image", "rest", "file-upload" ]
Django Rest Framework upload multiply images at once with serializer
39,163,363
<p>I had some research on web for this problem on DRF. When one image is in post DRF works great. But when 3 or 5 images are in one post there is problem that Django save only first image from POST query and others are not saved in database. The question is how to properly handle multiply images upload in one post.</p>...
0
2016-08-26T09:47:29Z
39,166,607
<p>Ok here is my some logic about this problem, so I hope someone will use this code (hack) for this purpose:</p> <h1>Serializer change</h1> <pre><code>class SerializerTest(serializers.Serializer): image = serializers.ListField(child=serializers.ImageField(required=True)) def create(self, validated_data): ...
0
2016-08-26T12:41:01Z
[ "python", "django", "image", "rest", "file-upload" ]
Is thre a better way to build it so it print all attributes from class/parent-class
39,163,495
<p>I have a <code>Student</code> class extending <code>Person</code> class, both class implemented <code>__str__</code> to list out all attributes in both <code>Person</code> and <code>Student</code> class. </p> <p>However, I am having issues with trying to do a print of <code>__str__</code> in the <code>__init__</cod...
2
2016-08-26T09:54:58Z
39,163,560
<p>Yes there is. Use <a href="https://docs.python.org/3.5/library/functions.html#super" rel="nofollow"><code>super</code></a> which calls "parent's" function realization. I'm quoting parent because it is little different than in other programming languages. There is awesome presentation by Raymond Hettinger on Pycon 20...
1
2016-08-26T09:58:12Z
[ "python", "class", "oop", "initialization" ]
Is thre a better way to build it so it print all attributes from class/parent-class
39,163,495
<p>I have a <code>Student</code> class extending <code>Person</code> class, both class implemented <code>__str__</code> to list out all attributes in both <code>Person</code> and <code>Student</code> class. </p> <p>However, I am having issues with trying to do a print of <code>__str__</code> in the <code>__init__</cod...
2
2016-08-26T09:54:58Z
39,163,565
<p>You may use the <code>getmembers</code> function of <a href="https://docs.python.org/3/library/inspect.html#inspect.getmembers" rel="nofollow"><code>inspect</code></a> module to get the all the members of the class dynamically. </p> <p>Generic function to <code>return</code> attributes based on passed <code>class</...
0
2016-08-26T09:58:37Z
[ "python", "class", "oop", "initialization" ]
Pyephem calculate current solar time
39,163,549
<p>I am trying to calculate the local solar time based on UTC hour and longitude. I have looked through the <code>ephem</code> package but was not able to identify a direct method to do so. Similar questions on this matter either evoke the calculation of fixed positions (sunrise, moon, sunset) (e.g. <a href="http://sta...
1
2016-08-26T09:57:46Z
39,184,871
<p>To compute local solar time, I think that you can just ask for the current right ascension of the point directly beneath the location (its nadir point), and subtract the right ascension of the Sun to learn exactly how far from local midnight it is: </p> <pre><code>from ephem import Sun, Observer, pi, hours dt = '2...
0
2016-08-27T19:21:40Z
[ "python", "pyephem" ]
How to append elements to a list by using reduceByKey in pyspark
39,163,703
<p>I'm kind of stuck trying to solve a problem in pyspark. After do same calculations by using map function, I have a RDD that contains a list of dicts in this way:</p> <pre><code>[{key1: tuple1}, {key1: tuple2}....{key2: tuple1}, {keyN: tupleN}] </code></pre> <p>I pretend to append for each key a list with all the ...
0
2016-08-26T10:06:17Z
39,163,839
<p>Here's a possible solution without using reduceByKey but just python builtin functions:</p> <pre><code>from collections import defaultdict inp = [{0: (0, 1.0)}, {0: (1, 0.0)}, {1: (0, 0.0)}, {1: (1, 1.0)}, {2: (0, 0.0)}] out = defaultdict(list) for v in inp: for k, v1 in v.iteritems(): out[k]...
0
2016-08-26T10:13:23Z
[ "python", "append", "pyspark", "rdd", "reduce" ]
How to get rows affected in a UPDATE statement by PyMSQL
39,163,776
<p>See the title,I need to update some rows on mysql database by PyMYSQL and I want to know <strong>how many rows had been changed.</strong></p> <p>code: <code> import pymysql db = pymysql.connect(xxxx) cur = db.cursor() sql = "update TABLE set A = 'abc' where B = 'def'" cur.execute(sql, params) ...
0
2016-08-26T10:10:03Z
39,163,989
<p>Mysql provides a special call that will help you achieve exactly that: <code>mysql-affected-rows</code>. This function is especially useful on updates as it will return only the number of rows that were affected, not the ones where the updated value was similar. Documentation is <a href="https://dev.mysql.com/doc/re...
1
2016-08-26T10:20:51Z
[ "python", "mysql", "pymysql" ]
How to get rows affected in a UPDATE statement by PyMSQL
39,163,776
<p>See the title,I need to update some rows on mysql database by PyMYSQL and I want to know <strong>how many rows had been changed.</strong></p> <p>code: <code> import pymysql db = pymysql.connect(xxxx) cur = db.cursor() sql = "update TABLE set A = 'abc' where B = 'def'" cur.execute(sql, params) ...
0
2016-08-26T10:10:03Z
39,164,309
<p>You can do this by <code>cursor.rowcount</code> after executing stage. Ff return value of this is opposite of 0 it means one or more rows are affected.</p>
0
2016-08-26T10:38:57Z
[ "python", "mysql", "pymysql" ]
How to insert huge CSV file at once into SQL Server in python?
39,163,849
<p>I have a large CSV file and I want to insert it all at once, instead of row by row. This is my code:</p> <pre><code>import pypyodbc import csv con = pypyodbc.connect('driver={SQL Server};' 'server=server_name;' 'database=DB-name;' 'trusted_connection=true') cur = con.cursor() csfile = open('out2.csv','r') csv_...
1
2016-08-26T10:14:05Z
39,164,253
<p>It really depends on your system resources. You can store CSV file in memory and then insert it into database. But if your CSV file is larger than your RAM there should be some Time issue. You can save each row of csv file as an element in python List.here is my code:</p> <pre><code>csvRows = [] csvFileObj = open('...
0
2016-08-26T10:35:35Z
[ "python", "sql-server", "csv" ]
Openpyxl - create styles as variables
39,163,882
<p>I want apply formats to excel cells (change default fonts and cells fills). I can set the cell attributes one by one:</p> <pre><code>from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font, Color ws1.cell(row=1,column=1).font=Font(color=colors.WHITE,size=9) ws1.cell(row=1,column=1).fill=...
0
2016-08-26T10:15:26Z
39,859,531
<p>Maybe 'named styles' are an option. I think this is what @Charlie Clark was talking about. You can find a rather limited explanation on the <a href="http://openpyxl.readthedocs.io/en/default/styles.html#creating-a-named-style" rel="nofollow">openpyxl 2.4.0 documentation</a></p> <p>This could look something like the...
0
2016-10-04T18:42:06Z
[ "python", "styles", "openpyxl" ]
Determine column value based on 2 other columns
39,164,079
<p>There are 2 column, Label1 and Label2. Both of them are cluster labels using different methods. </p> <pre><code> Label1 Label2 0 0 1024 1 1 1024 2 2 1025 3 3 1026 4 3 1027 5 4 1028 </code></pre> <p>I wanna get the final cluster label based these 2 columns. Compared each row, as long ...
1
2016-08-26T10:26:03Z
39,164,930
<p>Not sure I've understood correctly your question but here's a possible way to identify clusters:</p> <pre><code>import pandas as pd import collections df = pd.DataFrame( {'Label1': [0, 1, 2, 3, 3, 4], 'Label2': [1024, 1024, 1025, 1026, 1027, 1028]}) df['Cluster ID'] = [0] * 6 counter1 = {k: v for k, v in coll...
1
2016-08-26T11:10:41Z
[ "python", "pandas", "dataframe" ]
Determine column value based on 2 other columns
39,164,079
<p>There are 2 column, Label1 and Label2. Both of them are cluster labels using different methods. </p> <pre><code> Label1 Label2 0 0 1024 1 1 1024 2 2 1025 3 3 1026 4 3 1027 5 4 1028 </code></pre> <p>I wanna get the final cluster label based these 2 columns. Compared each row, as long ...
1
2016-08-26T10:26:03Z
39,165,298
<p>Here is how you can implement this:</p> <ol> <li><p>Check previous row for same value for the two columns</p></li> <li><p>If either of the values is same, do not increment cluster number and add to cluster list</p></li> <li><p>If none of the values is same, increment cluster number and add to cluster list</p></li> ...
1
2016-08-26T11:30:25Z
[ "python", "pandas", "dataframe" ]
Determine column value based on 2 other columns
39,164,079
<p>There are 2 column, Label1 and Label2. Both of them are cluster labels using different methods. </p> <pre><code> Label1 Label2 0 0 1024 1 1 1024 2 2 1025 3 3 1026 4 3 1027 5 4 1028 </code></pre> <p>I wanna get the final cluster label based these 2 columns. Compared each row, as long ...
1
2016-08-26T10:26:03Z
39,166,174
<p>IIUC, you could group the clusters as follows:</p> <p>Taking the difference between the row and it's next row , filling the topmost row with 0 and finding it's cumulative sum for both the Labels[1 and 2].</p> <pre><code>In [2]: label1_ = df['Label1'].diff().fillna(0).cumsum() In [3]: label2_ = df['Label2'].diff()...
2
2016-08-26T12:17:45Z
[ "python", "pandas", "dataframe" ]
Determine column value based on 2 other columns
39,164,079
<p>There are 2 column, Label1 and Label2. Both of them are cluster labels using different methods. </p> <pre><code> Label1 Label2 0 0 1024 1 1 1024 2 2 1025 3 3 1026 4 3 1027 5 4 1028 </code></pre> <p>I wanna get the final cluster label based these 2 columns. Compared each row, as long ...
1
2016-08-26T10:26:03Z
39,169,864
<p>Try this: Use np.where and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.duplicated.html" rel="nofollow">pandas.duplicated</a></p> <pre><code>df = df.sort_values(['Label1', 'Label2']) df['Cluster'] = np.where( (df.Label1.duplicated()) | (df.Label2.duplicated()),0,1).cu...
2
2016-08-26T15:33:11Z
[ "python", "pandas", "dataframe" ]
How to append characters to a string being used as a python dictionary key (when there are multiple entries related to that string)?
39,164,114
<p>I am pulling out sequence coordinates from the output file produced by HMMER (finds DNA sequences, matching a query, in a genome assembly file).</p> <p>I create a python dictionary where the key is the source sequence name (a string), and the value is a list comprising the start and end coordinates of the target se...
1
2016-08-26T10:27:22Z
39,164,299
<p>It's not a proper way to go to create different keys while the are equal, instead you can use a list for your values and preserve the coordinates in it, for duplicate keys. You can use <code>collections.defaultdict()</code> for this aim:</p> <pre><code>&gt;&gt;&gt; coords = [['4415', '16723', '17556'], ['127', '129...
0
2016-08-26T10:38:16Z
[ "python", "dictionary", "key", "unique" ]
How to append characters to a string being used as a python dictionary key (when there are multiple entries related to that string)?
39,164,114
<p>I am pulling out sequence coordinates from the output file produced by HMMER (finds DNA sequences, matching a query, in a genome assembly file).</p> <p>I create a python dictionary where the key is the source sequence name (a string), and the value is a list comprising the start and end coordinates of the target se...
1
2016-08-26T10:27:22Z
39,165,538
<p>You can do something like this:</p> <pre><code>matches = {'127': ['1290', '1145'], '1263': ['34900', '37834'], '4415': ['4580', '6004']} # sample key_name key_name = '4415' if key_name in matches.keys(): for i in xrange(1,26): if key_name+chr(ord('a') + i) not in matches.keys(): matches...
0
2016-08-26T11:45:41Z
[ "python", "dictionary", "key", "unique" ]
Django : authenticate() is not working for users created by register page, but working for those users who were created by admin
39,164,249
<p>I want to make a register/login API for users. Problem is like this : If I create user via admin site, login is working properly.</p> <p>If I create user via register page made by me, login isn't working.(authenticate() function is returning None, even though that user is still in user table.)</p> <p>I go to adm...
0
2016-08-26T10:35:22Z
39,164,579
<p>The issue is in how you set the password. You've excluded the password from the list of fields on the model form, so it is not set on save. So doing <code>user.set_password(user.password)</code> is effectively setting the password to the hash of None. Instead, do this:</p> <pre><code>user = user_form.save(commit=Fa...
0
2016-08-26T10:53:02Z
[ "python", "django", "django-views" ]
Django : authenticate() is not working for users created by register page, but working for those users who were created by admin
39,164,249
<p>I want to make a register/login API for users. Problem is like this : If I create user via admin site, login is working properly.</p> <p>If I create user via register page made by me, login isn't working.(authenticate() function is returning None, even though that user is still in user table.)</p> <p>I go to adm...
0
2016-08-26T10:35:22Z
39,166,353
<p>Use the below code to solve it..</p> <pre><code>def register(request, template_name="registration/register.html"): if request.method == "POST": postdata = request.POST.copy() username = postdata.get('username', '') email = postdata.get('email', '') password = postdata.get('passwo...
0
2016-08-26T12:27:06Z
[ "python", "django", "django-views" ]
Inserting data to table psycopg2 with no duplicates
39,164,347
<p>I am new to psycopg2. I have to insert data into the table with no duplicates. So, first I created a temporary table where I dumped all the data. And then, I check and add the data to the actual table. Here is the code till now:</p> <pre><code>for eachline in content: pmid ,first_name, last_name,initial,arti...
0
2016-08-26T10:40:31Z
39,164,660
<p>Try inserting query with triple quotes instead of single like below</p> <pre><code>for eachline in content: pmid ,first_name, last_name,initial,article_title,journal,language = eachline.split("\t") cur.execute ("""INSERT INTO AUTHOR_PMID(pmid, Author_lastname, Author_firstname, Author_initial,Article_...
1
2016-08-26T10:56:18Z
[ "python", "psycopg2" ]
Best way to create a similarity matrix for given set of items with tags
39,164,482
<p>We have data in format:</p> <pre><code>{ '1': ['Lathi Charge', 'NIT', 'Nirmal Singh'] '2': ['Kangana Ranaut', 'Hrithik Roshan'] '3': ['Hrithik Roshan', 'mohenjo daro', 'release date'], '4': ['NIT', 'Placements'] ... } </code></pre> <p>Keys of dictionary are items and values are tags associated with them....
1
2016-08-26T10:48:24Z
39,183,722
<p>There's only one similarity score that I can think of which would reliably handle the data you're looking at (it looks like your data is similar to that which would be gathered in a corpus study where documents are represented as bags of words, each potentially containing several words not present in the other docum...
0
2016-08-27T17:11:46Z
[ "python", "nlp", "scikit-learn" ]
Python strip Google Alerts URL
39,164,524
<p>I've currently got a dataframe filled with Google Alert URLS that look like:</p> <pre><code>link = 'https://www.google.com/url?rct=j&amp;sa=t&amp;url=http://3dprint.com/4353/littledlper-dlp-3d-printer-kickstarter/&amp;ct=ga&amp;cd=CAEYBCoSODQ1OTg1ODMwMzQwNDUzMTUxMhw2NTFlMTg3MTI1ZGE4Nzc3OmNvLnVrOmVuOkdC&amp;usg=AFQj...
1
2016-08-26T10:50:38Z
39,164,685
<p>You may use a regex on <code>parsed[4]</code> to extract that URL:</p> <pre><code>(?:^|&amp;)url=([^&amp;]+) </code></pre> <p>See the <a href="https://regex101.com/r/sG7yY1/1" rel="nofollow">regex demo</a></p> <p><em>Details</em>:</p> <ul> <li><code>(?:^|&amp;)</code> - either start of string or <code>&amp;</cod...
1
2016-08-26T10:57:40Z
[ "python", "regex", "urllib2" ]
How can i use autocomplete in IDE in this case in python
39,164,599
<pre><code>class Event(object): can_i_autocomplete_this = True class App(object): def decorator(self, func): self.func = func def call(): self.func(Event()) app = App() @app.decorator def hello(something): print(something.can_i_autocomplete_this) app.call() </code></pre> <p>I use dec...
0
2016-08-26T10:54:06Z
39,331,253
<p>Usages of function are not analyzed in inferring types of parameters.</p> <p>You could specify type of parameter inside doc:</p> <pre><code>@app.decorator def hello(something): """ :param something: :type something: Event :return: """ print(something.can_i_autocomplete_this) </code></pre> ...
2
2016-09-05T13:05:22Z
[ "python", "autocomplete", "pycharm", "python-decorators" ]
Membership checking in Numpy ndarray
39,164,636
<p>I have written a script that evaluates if some entry of <code>arr</code> is in <code>check_elements</code>. My approach does <em>not</em> compare single entries, but whole vectors inside of <code>arr</code>. Thus, the script checks if <code>[8, 3]</code>, <code>[4, 5]</code>, ... is in <code>check_elements</code>.</...
2
2016-08-26T10:55:21Z
39,164,996
<p>The <a href="https://github.com/EelcoHoogendoorn/Numpy_arraysetops_EP" rel="nofollow">numpy_indexed</a> package (disclaimer: I am its author) contains functionality to perform these kind of queries; specifically, containment relations for nd (sub)arrays:</p> <pre><code>import numpy_indexed as npi flatidx = npi.indi...
2
2016-08-26T11:13:46Z
[ "python", "numpy", "indexing" ]
Membership checking in Numpy ndarray
39,164,636
<p>I have written a script that evaluates if some entry of <code>arr</code> is in <code>check_elements</code>. My approach does <em>not</em> compare single entries, but whole vectors inside of <code>arr</code>. Thus, the script checks if <code>[8, 3]</code>, <code>[4, 5]</code>, ... is in <code>check_elements</code>.</...
2
2016-08-26T10:55:21Z
39,165,059
<p>Here is a Numpythonic approach using <a href="http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html" rel="nofollow"><em>broadcasting</em></a>:</p> <pre><code>&gt;&gt;&gt; (check_elements == arr[:,:,None]).reshape(2, 3, 6).any(axis=2) array([[False, True, False], [ True, False, True]], dtype=bool) <...
2
2016-08-26T11:17:39Z
[ "python", "numpy", "indexing" ]
Membership checking in Numpy ndarray
39,164,636
<p>I have written a script that evaluates if some entry of <code>arr</code> is in <code>check_elements</code>. My approach does <em>not</em> compare single entries, but whole vectors inside of <code>arr</code>. Thus, the script checks if <code>[8, 3]</code>, <code>[4, 5]</code>, ... is in <code>check_elements</code>.</...
2
2016-08-26T10:55:21Z
39,165,104
<p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html" rel="nofollow"><code>np.in1d</code></a> even though it is meant for 1D arrays by giving it a 1D view of your array, containing one element per last axis:</p> <pre><code>arr_view = arr.view((np.void, arr.dtype.itemsize*arr.shap...
1
2016-08-26T11:19:53Z
[ "python", "numpy", "indexing" ]
Invert 0 and 1 in a binary array
39,164,786
<p>Is there a function in Numpy to invert 0 and 1 in a binary array? If</p> <pre><code>a = np.array([0, 1, 0, 1, 1]) </code></pre> <p>I would like to get:</p> <pre><code>b = [1, 0, 1, 0, 0] </code></pre> <p>I use:</p> <pre><code>b[a==0] = 1 b[a==1] = 0 </code></pre> <p>but maybe it already exist something in Nump...
0
2016-08-26T11:02:55Z
39,164,837
<p>A functional approach:</p> <pre><code>&gt;&gt;&gt; np.logical_not(a).astype(int) array([1, 0, 1, 0, 0]) </code></pre>
3
2016-08-26T11:06:11Z
[ "python", "numpy" ]
Invert 0 and 1 in a binary array
39,164,786
<p>Is there a function in Numpy to invert 0 and 1 in a binary array? If</p> <pre><code>a = np.array([0, 1, 0, 1, 1]) </code></pre> <p>I would like to get:</p> <pre><code>b = [1, 0, 1, 0, 0] </code></pre> <p>I use:</p> <pre><code>b[a==0] = 1 b[a==1] = 0 </code></pre> <p>but maybe it already exist something in Nump...
0
2016-08-26T11:02:55Z
39,164,876
<p>you can simply do:</p> <pre><code>In[1]:b=1-a In[2]:b Out[2]: array([1, 0, 1, 0, 0]) </code></pre> <p>or </p> <pre><code>In[22]:b=(~a.astype(bool)).astype(int) Out[22]: array([1, 0, 1, 0, 0]) </code></pre>
5
2016-08-26T11:07:55Z
[ "python", "numpy" ]
global legend for all subplots
39,164,828
<p>I create an n x n matrix of matplot subplots which contain the same type of curve (lets name them signal1 and signal2):</p> <pre><code>n=5 f, axarr = plt.subplots(n,n) for i,signal_generator in enumerate(signal_generators): y=i%n x=(i-y)/n axarr[x, y].plot(signal_generator.signal1) axarr[x, y].plot(signal_g...
-1
2016-08-26T11:05:41Z
39,170,018
<p>One way to do it is to force some extra space below the plots. Then you can fit the legend right there and have one "global" legend.</p> <pre><code>import matplotlib.pyplot as plt import numpy as np plt.close('all') fig, axlist = plt.subplots(3, 3) for ax in axlist.flatten(): line1, = ax.plot(np.random.rando...
1
2016-08-26T15:42:24Z
[ "python", "matplotlib", "subplot" ]
Multiprocessing in Python crashes when code reaches start()
39,164,865
<p>I am new in Python. I tried to use some multiprocessing to make my work faster. First I tried an example and everything worked fine. Here is the code:</p> <pre><code>from multiprocessing import Process import time def f(name, n, m): if name == 'bob': time.sleep(2) print 'hello', name, ' ', n, m de...
0
2016-08-26T11:07:27Z
39,166,000
<p>There seems to be a problem with <a href="https://docs.python.org/2/library/pickle.html" rel="nofollow">pickling</a> <code>soup</code> (see <a href="https://docs.python.org/2/library/multiprocessing.html#programming-guidelines" rel="nofollow">Programming Guidelines</a>) so a simple solution would be to move the call...
0
2016-08-26T12:09:17Z
[ "python", "python-2.7", "multiprocessing", "python-multiprocessing" ]
Define blender Propertys in a Cycle
39,164,889
<p>I am trying to define a number blender property that is the same as the face of a cube, without defyning them manually.</p> <p>So something like this:</p> <pre><code>atr = bpy.types.Scene for i in range(0,20): //Define a intProperty to do stuffs. </code></pre> <p>And the call them separately in the panel draw...
0
2016-08-26T11:08:36Z
39,190,526
<p>There are two ways to add new properties to objects in blender. A simple dynamic way is to use <a href="https://www.blender.org/api/blender_python_api_current/info_quickstart.html#custom-properties" rel="nofollow">custom properties</a> by assigning a value to a key as if the object was a dictionary. This is the same...
0
2016-08-28T10:54:29Z
[ "python", "properties", "blender" ]
How install and use another version python(python 2.7) on linux with the default python version is python 2.6
39,164,943
<p>There is a default python version, namely python 2.6, on the GPU server with Linux OS. Now I want to install a new python version on the server from its source, namely python 2.7. I should not change the default python version since I am not the administrator and some reason. So what should I do? </p>
0
2016-08-26T11:11:19Z
39,165,141
<p>You can install your new version of Python. It should be accessible with the <code>python27</code> command (which may be a symbolic link). Then you will just have to check that the <code>python</code> symbolic link still points to <code>python26</code>.</p> <p>Doing this, <code>python</code> will keep on execute Py...
0
2016-08-26T11:21:24Z
[ "python", "linux", "python-2.7" ]
How install and use another version python(python 2.7) on linux with the default python version is python 2.6
39,164,943
<p>There is a default python version, namely python 2.6, on the GPU server with Linux OS. Now I want to install a new python version on the server from its source, namely python 2.7. I should not change the default python version since I am not the administrator and some reason. So what should I do? </p>
0
2016-08-26T11:11:19Z
39,165,757
<p>You can use <code>virtualenv</code>, to execute your programm in an environment with python 2.7.</p> <p>Install <code>virtualenv</code> and <a href="https://virtualenvwrapper.readthedocs.io/en/latest/" rel="nofollow"><code>virtualenvwrapper</code></a> (for comfotable use.)</p> <p><code>mkvirtualenv -p &lt;your-pyt...
0
2016-08-26T11:57:15Z
[ "python", "linux", "python-2.7" ]
How install and use another version python(python 2.7) on linux with the default python version is python 2.6
39,164,943
<p>There is a default python version, namely python 2.6, on the GPU server with Linux OS. Now I want to install a new python version on the server from its source, namely python 2.7. I should not change the default python version since I am not the administrator and some reason. So what should I do? </p>
0
2016-08-26T11:11:19Z
39,174,922
<p>To build on Tryph's answer, you can install that new version to your home directory, then in a directory specified within your PATH (like in .bash_profile), you can point to that directory and within there create a sym-link that points to the new python.</p> <p>For instance, if you have a bin folder in your home di...
0
2016-08-26T21:34:34Z
[ "python", "linux", "python-2.7" ]
Pycharm py.test coverage 'Coverage' object has no attribute 'export'
39,164,944
<p>I'm trying to run a py.test with coverage in pycharm. On my home pc it works like a charm, however on my laptop I'm getting this stacktrace</p> <pre><code>/home/david/PycharmProjects/pyCardDeck/virtualenv/bin/python /opt/pycharm/helpers/coverage_runner/run_coverage.py run --omit=\"/opt/pycharm/helpers*\" /opt/pycha...
0
2016-08-26T11:11:23Z
39,187,098
<p>That line in cmdline.py should read <code>self.coverage.save()</code>. It's never said <code>export</code>. You should reinstall coverage.py. I have no idea what changed it.</p>
1
2016-08-28T00:55:30Z
[ "python", "pycharm", "py.test", "coverage.py" ]
referencing multiple lists and dictionaries in novelty ways
39,165,032
<p>first post so please forgive formatting etc.</p> <p>I was trying to create a program that gave an alarm time based on whether it was a week day / weekend and whether it was a vacation</p> <p>heres the code:</p> <pre><code>days = {0:"sun", 1:"mon", 2:"tue", 3:"wed", 4:"thurs", ...
0
2016-08-26T11:16:22Z
39,167,083
<p>I give you credit for apologising for the formatting, but if you want people to help you with your code, they have to understand it.</p> <h3>Possible issue</h3> <p>I don't know if I see it correctly but on the line where <em>'y'</em> is defined, there is an empty <em>'.index()'</em> function ( possibly the one cau...
0
2016-08-26T13:07:26Z
[ "python", "list", "dictionary" ]
Python help, reading and writing to a txt file
39,165,060
<p>I have posted the relevant part of my code below. Before that are just load functions, which I am pretty sure have no errors.</p> <p>I am recieving error</p> <pre><code>IndexError: list index out of range( "namestaj["Naziv"] = deon[1]") </code></pre> <p>Does anyone see something out of order?</p> <pre><code>#loa...
-1
2016-08-26T11:17:39Z
39,165,299
<p>Couple of things first, try always to provide a <a href="http://stackoverflow.com/help/mcve">mcve</a> and make sure you use properly the SO code directives, otherwise your question is unreadable.</p> <p>Now, probably what's happening is your file has some empty lines and you're not skipping those, try this:</p> <p...
0
2016-08-26T11:30:33Z
[ "python", "eclipse", "pydev" ]
What is the best way to split long line with several exceptions?
39,165,071
<p>Say I have next code:</p> <pre><code>try: ... except (some_lib.LongNameError1, lib.LongNameError2, lib.LongNameError3, lib.LongNameError3) as e: print str(e) </code></pre> <p>As you can see line with exceptions is too long.</p> <p>I need to split it to meet requirement about a maximum of line length of 79...
0
2016-08-26T11:18:15Z
39,165,153
<p>You could take advantage of using parenthesis like this:</p> <pre><code>try: ... except (some_lib.LongNameError1, some_lib.LongNameError2, some_lib.LongNameError3, some_lib.LongNameError4, some_lib.LongNameErrorN) as e: ... </code></pre>
4
2016-08-26T11:22:01Z
[ "python", "python-2.7", "exception" ]
Taking mean along columns with masks in Python
39,165,078
<p>I have a 2D array containing data from some measurements. I have to take mean along each column considering good data only. Hence I have another 2D array of the same shape which contains 1s and 0s showing whether data at that (i,j) is good or bad. Some of the "bad" data can be nan as well.</p> <pre><code>def mean_...
0
2016-08-26T11:18:39Z
39,165,283
<p>The code seems to work for me, but you can do it a whole lot simpler by using the build-in aggregation in Numpy:</p> <p><code>(x*(m==0)).sum(axis=0)/(m==0).sum(axis=0)</code></p> <p>I tried it with:</p> <p><code>x=np.array([[-0.32220561, -0.93043128, 0.37695923],[ 0.08824206, -0.86961453, -0.54558324],[-0.409423...
1
2016-08-26T11:29:10Z
[ "python", "arrays", "numpy", "mask" ]
How can I connect a git repository to heroku app
39,165,085
<p>I'm trying to connect my heroku app to git repository.And also I can't able to push an existing repository with heroku app.While I'm trying to push with</p> <pre><code>git push heroku master </code></pre> <p>I found </p> <pre><code>fatal: 'heroku' does not appear to be a git repository fatal: Could not read from ...
0
2016-08-26T11:19:08Z
39,170,238
<p>That error means that: in your current project you have not yet 'initialized' Heroku.</p> <p>Are you creating a NEW Heroku app? If so, you can run the following command to fix things:</p> <pre><code>heroku create </code></pre> <p>If you're trying to work with an EXISTING Heroku app, you need to setup your 'heroku...
0
2016-08-26T15:54:14Z
[ "python", "heroku", "github" ]
drawing svg in python with paths not shapes or convert them
39,165,287
<p>I'm making a microscope filter generator, first it draws svg image then they are converted in 3D for 3d printing.</p> <p>I used 'svgwrite'</p> <p>However this librayry generates svg with shapes (line, circle, etc), at the time I didn't know but every 3D conversion librayry/softwares needs the svg to contain path.<...
8
2016-08-26T11:29:25Z
39,206,499
<p>Line and Circle have a straightforward translation to a Path entity, using MoveTo/LineTo/EllipticalArc.</p> <p>It shouldn't be a great deal to just replace those lines in the Xml source and keep all the rest, with a home-made script.</p>
0
2016-08-29T12:35:05Z
[ "python", "svg" ]
drawing svg in python with paths not shapes or convert them
39,165,287
<p>I'm making a microscope filter generator, first it draws svg image then they are converted in 3D for 3d printing.</p> <p>I used 'svgwrite'</p> <p>However this librayry generates svg with shapes (line, circle, etc), at the time I didn't know but every 3D conversion librayry/softwares needs the svg to contain path.<...
8
2016-08-26T11:29:25Z
39,300,480
<p>I have already written some stuff for my own needs to process some similar tasks with SVG elements, like evaluating of bounding boxes, transformations and so on. Thus, this task seems relatively simple for me to implement such a conversion. All you need for it is only knowledge of what paths "d" attribute consists f...
1
2016-09-02T20:46:36Z
[ "python", "svg" ]
Capturing screenshot and parsing data from the captured image
39,165,347
<p>I need to write a desktop application that performs the following operations. I'm thinking of using Python as the programming language, but I'd be more than glad to switch, if there's an appropriate approach or library in any other languages.</p> <p>The file I wish to capture is an HWP file, that only certain word ...
0
2016-08-26T11:33:42Z
39,171,923
<p>If i got it correctly , you need to extract text from image. For this one you should use an OCR like tesseract. Before using an OCR, try to clear noises from image. To split the image try to add some unique strings to distinguish between the quiz Q/A</p>
0
2016-08-26T17:40:59Z
[ "python", "image", "parsing", "screenshot" ]
Why can I not grab certain tags using BeautifulSoup?
39,165,468
<p>I want to get the number of votes on quora answers(In this specific case the number "13"):</p> <p><a href="http://i.stack.imgur.com/scoHP.png" rel="nofollow">Image of the element I want to grab:</a></p> <p>What I have tried:</p> <pre><code>import requests from bs4 import BeautifulSoup url1 = "https://www.quora.c...
1
2016-08-26T11:41:38Z
39,165,628
<p>You have the picture but not the data structure, so this may or may not be correct -- But based on previous BeautifulSoup issues try this:</p> <pre><code>z = soup.find('span', class_='count') </code></pre> <p>Depending on the content, print z probably won't work. It'll probably print an object identifier. print(z....
0
2016-08-26T11:50:41Z
[ "python", "web-scraping", "beautifulsoup" ]
Why can I not grab certain tags using BeautifulSoup?
39,165,468
<p>I want to get the number of votes on quora answers(In this specific case the number "13"):</p> <p><a href="http://i.stack.imgur.com/scoHP.png" rel="nofollow">Image of the element I want to grab:</a></p> <p>What I have tried:</p> <pre><code>import requests from bs4 import BeautifulSoup url1 = "https://www.quora.c...
1
2016-08-26T11:41:38Z
39,165,659
<p>It seems you need to be registered in Quora first, otherwise you <a href="http://screencast.com/t/yHAag3Fn" rel="nofollow">won't get directly</a> the information you're looking for, make sure that information is available to you first</p>
0
2016-08-26T11:52:07Z
[ "python", "web-scraping", "beautifulsoup" ]
Change values of a column in CSV file using python
39,165,533
<p>I am new to python and just need a small help.</p> <p>We have a Pipe delimited CSV file which looks like this </p> <pre><code>DATE|20160101 ID | Name | Address | City | State | Zip | Phone | OPEID | IPEDS | 10 | A... | 210 W.. | Mo.. | AL... | '31.. | 334.. | '01023 | 10063 | 20 | B... | 240 N.. | Ne.. | Ut... ...
-1
2016-08-26T11:45:20Z
39,166,125
<p>The code below would be the same for all file formats. The fact that it is a *.csv doesn't change a thing. What it actually does, is that it goes in the file from which you want to remove the apostrophes, <code>my_csv_in</code>, and parses it line by line each time replacing them with nothing (a.k.a removing). The m...
0
2016-08-26T12:15:18Z
[ "python", "csv" ]
Change values of a column in CSV file using python
39,165,533
<p>I am new to python and just need a small help.</p> <p>We have a Pipe delimited CSV file which looks like this </p> <pre><code>DATE|20160101 ID | Name | Address | City | State | Zip | Phone | OPEID | IPEDS | 10 | A... | 210 W.. | Mo.. | AL... | '31.. | 334.. | '01023 | 10063 | 20 | B... | 240 N.. | Ne.. | Ut... ...
-1
2016-08-26T11:45:20Z
39,166,163
<p>To remove apostrophes you can use the <a href="https://docs.python.org/2/library/string.html" rel="nofollow">replace function</a>, you just need to get the content of every cell one by one, and replace the apostrophes with:</p> <pre><code>new = old.replace("'", "") </code></pre> <p>More simply, open your csv file ...
0
2016-08-26T12:17:07Z
[ "python", "csv" ]
Change values of a column in CSV file using python
39,165,533
<p>I am new to python and just need a small help.</p> <p>We have a Pipe delimited CSV file which looks like this </p> <pre><code>DATE|20160101 ID | Name | Address | City | State | Zip | Phone | OPEID | IPEDS | 10 | A... | 210 W.. | Mo.. | AL... | '31.. | 334.. | '01023 | 10063 | 20 | B... | 240 N.. | Ne.. | Ut... ...
-1
2016-08-26T11:45:20Z
39,166,199
<p>It worked for me... Try this.</p> <pre><code>res=[] with open('hi.csv','rb') as f: content=csv.reader(f,delimiter='|') for row in content: for str in range (len(row)): row[str]=row[str].replace('\'','') res.append(row) f.close() with open('hi.csv','wb') as ff: sw=csv.writ...
0
2016-08-26T12:19:43Z
[ "python", "csv" ]
Change values of a column in CSV file using python
39,165,533
<p>I am new to python and just need a small help.</p> <p>We have a Pipe delimited CSV file which looks like this </p> <pre><code>DATE|20160101 ID | Name | Address | City | State | Zip | Phone | OPEID | IPEDS | 10 | A... | 210 W.. | Mo.. | AL... | '31.. | 334.. | '01023 | 10063 | 20 | B... | 240 N.. | Ne.. | Ut... ...
-1
2016-08-26T11:45:20Z
39,166,470
<p>You can do it very efficiently with Pandas--this will be good if your file is very large:</p> <pre><code>import pandas as pd import sys with open('t.txt') as infile: title = next(infile) infile.seek(0) table = pd.read_csv(infile, '|', header=1, dtype=str) table.rename(columns={'Unnamed: 9':''}, inplac...
0
2016-08-26T12:33:02Z
[ "python", "csv" ]
Assert value for key in cookie dict
39,165,567
<p>I've just started working with python test automation, and I'm trying to assert that a certain cookie with a certain value is being set when clicking on a certain button. I'm automating tests using splinter, and so far I have this:</p> <pre><code>cookie_bar = browser.find_link_by_text('Yes') manage_cookies = browse...
0
2016-08-26T11:47:15Z
39,166,032
<p>You are saying that <code>browser.cookies.all()</code> return a dict, therefore, you should use it as a dict and not as a list.</p> <p>For example you can do:</p> <pre><code>assert cookies_list.get('cookie1', None) == 'value1' </code></pre> <p>Find some more info about dictionary <a href="https://docs.python.org/...
1
2016-08-26T12:11:13Z
[ "python", "cookies", "automated-tests", "splinter" ]
want to store elements in array or list using python
39,165,577
<p>I am learning python. I want to store one by one element in array or list. this is my code. </p> <pre><code>for u in durl: p2 = requests.get(u) tree = html.fromstring(p2.content) dcode.append = tree.xpath(ecode) print(dcode) </code></pre> <p>in dcode variable the elements are overridin...
0
2016-08-26T11:47:42Z
39,165,648
<p><code>tree.xpath(...)</code> returns a list so if you want to merge it with an existing list <code>dcode</code> of selected elements, you might do</p> <pre><code>dcode.extend(tree.xpath(ecode)) </code></pre>
0
2016-08-26T11:51:38Z
[ "python", "arrays", "list", "python-2.7" ]
want to store elements in array or list using python
39,165,577
<p>I am learning python. I want to store one by one element in array or list. this is my code. </p> <pre><code>for u in durl: p2 = requests.get(u) tree = html.fromstring(p2.content) dcode.append = tree.xpath(ecode) print(dcode) </code></pre> <p>in dcode variable the elements are overridin...
0
2016-08-26T11:47:42Z
39,165,856
<p>append is a method not a variable so if you want to append <code>tree.xpath(ecode)</code> to <code>dcode</code> then you should write <code>dcode.append(tree.xpath(ecode))</code> rather than <code>dcode.append =</code> which is an assignment not a method call.</p>
2
2016-08-26T12:02:13Z
[ "python", "arrays", "list", "python-2.7" ]
want to store elements in array or list using python
39,165,577
<p>I am learning python. I want to store one by one element in array or list. this is my code. </p> <pre><code>for u in durl: p2 = requests.get(u) tree = html.fromstring(p2.content) dcode.append = tree.xpath(ecode) print(dcode) </code></pre> <p>in dcode variable the elements are overridin...
0
2016-08-26T11:47:42Z
39,166,135
<p>You can do it this way, it appends new value to the list and it makes more sense...sort of data structure</p> <pre><code>def main(decode=[]): for u in durl: p2 = requests.get(u) tree = html.fromstring(p2.content) dcode.append(tree.xpath(ecode)) print(dcode) </code></pre>
0
2016-08-26T12:15:49Z
[ "python", "arrays", "list", "python-2.7" ]
How to send data to Python script from C#
39,165,595
<p>i have been experimented with Python from C# and i do not know how to execute a Python script and write It commands/data. I have been looking this link: "<a href="https://code.msdn.microsoft.com/windowsdesktop/C-and-Python-interprocess-171378ee" rel="nofollow">https://code.msdn.microsoft.com/windowsdesktop/C-and-Pyt...
4
2016-08-26T11:48:48Z
39,165,894
<p>Do you need that the C# program and the python one work at the same time? If no, you can gather all the data from the C# program and send them to the python script either as arguments in the command line, or in a file that the two programs share.</p> <p>To use arguments in a python script you can use the <a href="h...
0
2016-08-26T12:04:01Z
[ "c#", "python" ]
Zipline: momentum pipeline example - TypeError: a float is required
39,165,596
<p>I have been trying to run the example on Zipline called <code>momentum_pipeline.py</code>. It is just not running properly, I'm calling the following on terminal:</p> <pre><code>python -m zipline run -f momentum_pipeline.py --start 2000-1-1 --end 2014-1-1 --output pipeline.pickle </code></pre> <p>The output is an ...
0
2016-08-26T11:48:49Z
39,264,953
<p>I think the date range I was using was too long (from 2000 - 2014) therefore some of the data was not available. I think Quantopian only has stock market data from 2002 only. If you change the date range to the ones found on the test_args, the example will work:</p> <pre><code>return { # We run through october ...
0
2016-09-01T07:13:31Z
[ "python", "zipline" ]
Using Forms in Django - Adding people to a specific date
39,165,670
<p>I've searched the site, which has been extremely helpful with other issues being that I'm new to Django. I can't seem to figure out how to add people to a date/event. </p> <p><a href="http://i.stack.imgur.com/g2OC2.png" rel="nofollow">Models</a></p> <pre><code>class PeopleList(models.Model): first_name = models....
0
2016-08-26T11:52:46Z
39,165,939
<p>If i understand you correctly, you want to sort by date and check people on the list based on the date... you can use django order by to do that( query based on date and fetch people that matches, let me know if you need practical proof so i can add it.</p>
0
2016-08-26T12:06:12Z
[ "python", "django" ]
Using Forms in Django - Adding people to a specific date
39,165,670
<p>I've searched the site, which has been extremely helpful with other issues being that I'm new to Django. I can't seem to figure out how to add people to a date/event. </p> <p><a href="http://i.stack.imgur.com/g2OC2.png" rel="nofollow">Models</a></p> <pre><code>class PeopleList(models.Model): first_name = models....
0
2016-08-26T11:52:46Z
39,166,699
<p>Code your form like this</p> <pre><code>#### forms.py from django import form from app.models import PeopleList, Date class CustomForm(forms.Form): person = forms.ModelField(queryset=PeopleList.Objects.all()) date = forms.ModelField(queryset=Date.Objects.all()) #### views.py from app.forms import CustomF...
0
2016-08-26T12:45:38Z
[ "python", "django" ]
Django Photologue zip upload keep images names
39,165,686
<p>I'm working on photologue and till now it's perfect. I just want to know how can I keep the images names when uploading zip images.</p> <p>Here is a the code of the save function after the zip file upload. :</p> <pre><code> def save(self, request=None, zip_file=None): if not zip_file: zip_file = self...
0
2016-08-26T11:53:45Z
39,167,948
<p>I solved it Finally the code became as below if one want's to get benefit from my solution for this problem .</p> <pre><code>def save(self, request=None, zip_file=None): if not zip_file: zip_file = self.cleaned_data['zip_file'] zip = zipfile.ZipFile(zip_file) count = 1 current_site = Site.ob...
0
2016-08-26T13:50:09Z
[ "python", "django", "photologue" ]
Ball Tracker using OpenCV, Python, Raspberry Pi 3
39,165,715
<p>I have tried to run this script on my Raspberry Pi however I keep encountering an attribute error. <strong>Any help or indication as to what the problem might be would be much appreciated.</strong></p> <h1>Here is the error:</h1> <pre><code>Traceback (most recent call last): File "/home/pi/ball-tracking/ball_tra...
0
2016-08-26T11:55:00Z
39,166,176
<p>It seems that <code>frame</code> was returned as <code>None</code> in this line as if you camera couldn't read an image:</p> <pre><code>(grabbed, frame) = camera.read() </code></pre> <p>Then, when resizing a <code>None</code> object, the program blows up as we described in the error message <code>AttributeError: '...
1
2016-08-26T12:17:47Z
[ "python", "opencv", "computer-vision", "raspberry-pi3" ]
Ball Tracker using OpenCV, Python, Raspberry Pi 3
39,165,715
<p>I have tried to run this script on my Raspberry Pi however I keep encountering an attribute error. <strong>Any help or indication as to what the problem might be would be much appreciated.</strong></p> <h1>Here is the error:</h1> <pre><code>Traceback (most recent call last): File "/home/pi/ball-tracking/ball_tra...
0
2016-08-26T11:55:00Z
40,133,332
<p>The 'NoneType' error indicated that a frame was not passed to the resize function. When using the cv2.capture method one must ensure that the correct drivers are loaded otherwise you will end up with the same NoneType error.</p> <p>The solution is to manually add the driver to etc/modules or to enter the following ...
1
2016-10-19T13:50:34Z
[ "python", "opencv", "computer-vision", "raspberry-pi3" ]
Duplicate column name 'model_id' django mysql error on migrate
39,165,779
<p>I am using Django and MySQL on my VPS. Whenever I run <code>python manage.py migrate</code> I get the following error. But on my development server I use sqlite, and migrate works fine.</p> <pre><code>Running migrations: Rendering model states... DONE Applying bloupergroups.0002_auto_20160826_1138...Traceback (...
0
2016-08-26T11:58:28Z
39,169,467
<p>Django is probably trying to apply migrations that have already been applied.</p> <p>Try running <code>python manage.py migrate --fake-initial</code></p> <p>From the docs:</p> <blockquote> <p>--fake-initial Allows Django to skip an app’s initial migration if all database tables with the names of all models ...
0
2016-08-26T15:10:55Z
[ "python", "mysql", "django", "sqlite", "django-models" ]
How to use `pip` and setup.py to automatically install dependencies that may be private repositories hosted on github
39,165,976
<p>I don't think this is a dupicate, because I tried all links I could find for the past 2 hours and none of the solutions worked. I want the user to be able to clone a repository, <code>cd</code> into the directory, and run <code>$ pip install .</code> (or at least <code>pip install --process-dependency-links .</code>...
1
2016-08-26T12:07:44Z
39,494,943
<p>pip expects to have a link to index page (such as PyPI) in <code>dependency_links</code>. Any link to VCS is going to be skipped. This behavior was changed in commit <a href="https://github.com/pypa/pip/commit/26facddaa81be3447b8e06a9886c03b90fd68309" rel="nofollow">26facdd</a>.</p> <p>I recommend to define all ext...
1
2016-09-14T15:59:43Z
[ "python", "pip", "setuptools", "packaging", "setup.py" ]
converting appended images list in Pandas dataframe
39,165,992
<p>I have a list which I created after appending the images from a folder </p> <pre><code>samples=[] for filename in glob.glob(path + '/*.png'): samples.append(misc.imread(filename)) </code></pre> <p>And a sample of the list looks like </p> <pre><code>[array([[ 4, 4, 4, ..., 5, 5, 4], [ 5, 5, 5, .....
0
2016-08-26T12:08:49Z
39,166,939
<p>Try converting it into a pandas <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Panel.html" rel="nofollow">panel</a></p> <pre><code>import cv2 img = cv2.imread('path/Picture_1.png') imgPanel = pd.Panel(img) </code></pre> <p>For more info see: <a href="http://pandas-docs.github.io/pandas-docs-...
0
2016-08-26T12:59:11Z
[ "python", "pandas", "dataframe", "scipy" ]
converting appended images list in Pandas dataframe
39,165,992
<p>I have a list which I created after appending the images from a folder </p> <pre><code>samples=[] for filename in glob.glob(path + '/*.png'): samples.append(misc.imread(filename)) </code></pre> <p>And a sample of the list looks like </p> <pre><code>[array([[ 4, 4, 4, ..., 5, 5, 4], [ 5, 5, 5, .....
0
2016-08-26T12:08:49Z
40,058,708
<p>Try adding .reshape(-1) while appending an image. </p> <pre><code>for filename in glob.glob(path + '/*.png'): samples.append(misc.imread(filename).reshape(-1)) df = pd.DataFrame.from_records(samples) </code></pre> <p>If you want to 3d version please read <a href="http://stackoverflow.com/questions/6627647/res...
0
2016-10-15T11:55:00Z
[ "python", "pandas", "dataframe", "scipy" ]
Can't create an SQL Table in Python using input as name
39,166,102
<p>I have a little issue with my python code. I want to take the input from user and based on that create an SQL table with that name. I take the input in table_name variable and want to do it so:</p> <pre><code>sql = "CREATE TABLE %s" % table_name cur.execute(sql) </code></pre> <p>Let's say I run it with input "book...
1
2016-08-26T12:13:59Z
39,166,151
<p>That's most probably cause you are not passing the table definition (column names and their type , size). What I see from posted code is that you are passing only table name and so your query becomes below which is totally wrong</p> <pre><code>CREATE TABLE books </code></pre>
4
2016-08-26T12:16:25Z
[ "python", "sql", "sqlite" ]
Connection refused error in python socket (stream)?
39,166,156
<p>My script is launching multiple clients in a machine-1 and tries to connect to a server running on different machines on a specific port. These machines running the server are launched by boto3 and then wait for 5 min for the instances to be in running state. Then a sftp connection is made to transfer files. Then th...
0
2016-08-26T12:16:38Z
39,245,447
<p>The issue was regarding the time mismatch between starting the server and client. Actually its takes little while to start the server and in the meantime the client request to connect. So I put a 2 sec delay before starting the client and the issue resolved.</p>
0
2016-08-31T09:14:18Z
[ "python", "sockets", "amazon-web-services", "boto" ]
How to apply a transformation to a certain tonal range in VIPS/Python
39,166,164
<p>I have to apply various transformations to different tonal ranges of 16-bit tiff files in VIPS (and Python). I have managed to do so, but I am new to VIPS and I am not convinced I am doing this in an efficient manner. These images are several hundred megabytes each, and cutting each excess step can save me a few sec...
1
2016-08-26T12:17:12Z
39,492,969
<p>I made you a demo program showing how to do something like this with the vips histogram functions:</p> <pre><code>#!/usr/bin/python import sys import gi gi.require_version('Vips', '8.0') from gi.repository import Vips im = Vips.Image.new_from_file(sys.argv[1]) # find the image histogram # # we'll get a uint i...
2
2016-09-14T14:26:54Z
[ "python", "image-processing", "vips" ]
Create csv file in python
39,166,256
<p>I created one program in python in which I used collaborative filtering to find Item based CF. My code is,</p> <pre><code># Create a placeholder items for closes neighbours to an item data_neighbours = pd.DataFrame(index=data_ibs.columns,columns=[range(1,13)]) print data_neighbours # Loop through our similarity...
0
2016-08-26T12:22:24Z
39,166,327
<p>You should consider to use the <a href="https://docs.python.org/2/library/csv.html" rel="nofollow">csv module</a>. In the documentation there is all the explanations and examples you need to create your csv file.</p>
0
2016-08-26T12:25:52Z
[ "python" ]
Create csv file in python
39,166,256
<p>I created one program in python in which I used collaborative filtering to find Item based CF. My code is,</p> <pre><code># Create a placeholder items for closes neighbours to an item data_neighbours = pd.DataFrame(index=data_ibs.columns,columns=[range(1,13)]) print data_neighbours # Loop through our similarity...
0
2016-08-26T12:22:24Z
39,166,477
<pre><code>with open('hi.csv','wb') as ff: sw=csv.writer(ff,delimiter=',',quoting=csv.QUOTE_MINIMAL) for rows in data_neighbours: sw.writerow(rows) </code></pre> <p>data_neighbours must contain lists in row wise....</p>
0
2016-08-26T12:33:24Z
[ "python" ]
Comparing lists containing NaNs
39,166,292
<p>I am trying to compare two different lists to see if they are equal, and was going to remove NaNs, only to discover that my list comparisons still work, despite <code>NaN == NaN -&gt; False</code>. </p> <p>Could someone explain why the following evaluate <code>True</code> or <code>False</code>, as I am finding this...
3
2016-08-26T12:24:18Z
39,166,585
<p>To understand what happens here, simply replace <code>nan = np.nan</code> by <code>foo = float('nan')</code>, you will get exactly the same result, why?</p> <pre><code>&gt;&gt;&gt; foo = float('nan') &gt;&gt;&gt; foo is foo # This is obviously True! True &gt;&gt;&gt; foo == foo # This is False per the standard (na...
1
2016-08-26T12:39:29Z
[ "python", "list", "comparison", null ]