qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
68,083,635
I am using a Queensland government API. The format for it is JSON, and the keys have spaces in them. I am trying to access them with python and flask. I can pass through the data required to the HTML file yet cannot print it using flask. ``` {% block content %} <div> {% for suburb in data %} <p>{{ suburb.Age }...
2021/06/22
[ "https://Stackoverflow.com/questions/68083635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16289640/" ]
There's lots of fundamental problems in the code. Most notably, `int**` is not a 2D array and cannot point at one. * `i<2` typo in the `for(int j...` loop. * `i < n` in the `for(int k...` loop. * To allocate a 2D array you must do: `int (*a)[2] = malloc(sizeof(int) * 2 * 2);`. Or if you will `malloc( sizeof(int[2][2])...
You need to fix multiple errors here: 1/ line 5/24/28: `int **c = malloc(sizeof(int*) * n )` 2/ line 15: `k<n` 3/ Remark: use `a[i][j]` instead of `*(*(a+i)+j)` 4/ line 34: `j<2` 5/ check how to create a 2d matrix using pointers. ``` #include <stdio.h> #include <stdlib.h> int** multiply(int** a, int** b, int n) ...
68,083,635
I am using a Queensland government API. The format for it is JSON, and the keys have spaces in them. I am trying to access them with python and flask. I can pass through the data required to the HTML file yet cannot print it using flask. ``` {% block content %} <div> {% for suburb in data %} <p>{{ suburb.Age }...
2021/06/22
[ "https://Stackoverflow.com/questions/68083635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16289640/" ]
From the updated requirement, the actual function prototype is `int *multiply(int *a, int *b, int n);` so the code should use a "flattened" matrix representation consisting of a 1-D array of length `n * n`. Using a flattened representation, element (`i`, `j`) of the `n * n` matrix `m` is accessed as `m[i * n + j]` or ...
You need to fix multiple errors here: 1/ line 5/24/28: `int **c = malloc(sizeof(int*) * n )` 2/ line 15: `k<n` 3/ Remark: use `a[i][j]` instead of `*(*(a+i)+j)` 4/ line 34: `j<2` 5/ check how to create a 2d matrix using pointers. ``` #include <stdio.h> #include <stdlib.h> int** multiply(int** a, int** b, int n) ...
47,969,587
I can't figure out how to open a dng file in opencv. The file was created when using the pro options of the Samsung Galaxy S7. The images that are created when using those options are a dng file as well as a jpg of size 3024 x 4032 (I believe that is the dimensions of the dng file as well). I tried using the answer fr...
2017/12/25
[ "https://Stackoverflow.com/questions/47969587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8461821/" ]
As far as i know it is possible that DNG files can be compressed (even though it is lossless format), so you will need to decode your dng image first. <https://www.libraw.org/> is capable of doing that. There is python wrapper for that library (<https://pypi.python.org/pypi/rawpy>) ``` import rawpy import imageio pa...
[process\_raw](https://github.com/DIYer22/process_raw) supports both read and write `.dng` format raw image. Here is a python example: ```py import cv2 from process_raw import DngFile # Download raw.dng for test: # wget https://github.com/yl-data/yl-data.github.io/raw/master/2201.process_raw/raw-12bit-GBRG.dng dng_pa...
43,287,649
Let's say this is normal: ``` @api.route('/something', methods=['GET']) def some_function(): return jsonify([]) ``` **Is it possible to use a function that is already defined?** ``` def some_predefined_function(): return jsonify([]) @api.route('/something', methods=['GET']) some_predefined_function() ``` ...
2017/04/07
[ "https://Stackoverflow.com/questions/43287649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/680578/" ]
There are a few ways to add routes in Flask, and although `@api.route` is the most elegant one, it is not the only one. Basically a decorator is just a fancy function, you can use it inline like this: ``` api.route('/api/galleries')(some_func) ``` Internally `route` is calling [add\_url\_rule](http://flask.pocoo.or...
Try this: ``` def some_predefined_function(): return jsonify([]) @api.route('/something', methods=['GET']) def something(): return some_predefined_function() ```
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
When looping through collections, you can use enhanced loops: ``` int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println(item); } ```
Since a few people asked for something like this, here are a few things you could do, although whether these are really better is arguable and a matter of taste: ``` void times(int n, Runnable r) { for (int i = 0; i < n; i++) { r.run(); } } ``` Usage: ``` times(10, () -> System.out.println("Hello, w...
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
There is a way to write shorter for loop. If "for" loop is the concern, you may find this interesting ``` for(int i = -1; ++i < max;) { //do something } ``` Notice that the counter increment was done before the comparison with max is done. Also notice that the index i starts from -1 instead of normal 0.
you can use this way for List's Normal Mode: ``` List<String> myList = Arrays.asList(new String[]{"a","b","c","d","e","f"}); for (int i=0;i<myList.size();i++){ System.out.println(myList.get(i)); } ``` Short Mode 1: ``` List<String> myList = Arrays.asList(new String[]{"a","b","c","d","e","f"}); myList.forEach((...
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
There is a way to write shorter for loop. If "for" loop is the concern, you may find this interesting ``` for(int i = -1; ++i < max;) { //do something } ``` Notice that the counter increment was done before the comparison with max is done. Also notice that the index i starts from -1 instead of normal 0.
The for shortcut I thought of is: **for (int i : val)** which works pretty fine for me. Take as an exemple the following code: ``` for (int i = 0; x < val.length; i++) System.out.print(val[i] + ", "); ``` is equivalent with ``` for (int i : val) System.out.print(i + ", "); ``` After having some research, I found ...
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
Since a few people asked for something like this, here are a few things you could do, although whether these are really better is arguable and a matter of taste: ``` void times(int n, Runnable r) { for (int i = 0; i < n; i++) { r.run(); } } ``` Usage: ``` times(10, () -> System.out.println("Hello, w...
you can use this way for List's Normal Mode: ``` List<String> myList = Arrays.asList(new String[]{"a","b","c","d","e","f"}); for (int i=0;i<myList.size();i++){ System.out.println(myList.get(i)); } ``` Short Mode 1: ``` List<String> myList = Arrays.asList(new String[]{"a","b","c","d","e","f"}); myList.forEach((...
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
When looping through collections, you can use enhanced loops: ``` int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println(item); } ```
The for shortcut I thought of is: **for (int i : val)** which works pretty fine for me. Take as an exemple the following code: ``` for (int i = 0; x < val.length; i++) System.out.print(val[i] + ", "); ``` is equivalent with ``` for (int i : val) System.out.print(i + ", "); ``` After having some research, I found ...
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
When looping through collections, you can use enhanced loops: ``` int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println(item); } ```
There is a way to write shorter for loop. If "for" loop is the concern, you may find this interesting ``` for(int i = -1; ++i < max;) { //do something } ``` Notice that the counter increment was done before the comparison with max is done. Also notice that the index i starts from -1 instead of normal 0.
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
There is a way to write shorter for loop. If "for" loop is the concern, you may find this interesting ``` for(int i = -1; ++i < max;) { //do something } ``` Notice that the counter increment was done before the comparison with max is done. Also notice that the index i starts from -1 instead of normal 0.
In many cases max value is unknown (data from files, databases etc.). For me the best is loading everything to List (ArrayList etc.) and use for-each loop. Looping through collections is the best way to short loop syntax in my opinion.
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
Since a few people asked for something like this, here are a few things you could do, although whether these are really better is arguable and a matter of taste: ``` void times(int n, Runnable r) { for (int i = 0; i < n; i++) { r.run(); } } ``` Usage: ``` times(10, () -> System.out.println("Hello, w...
In many cases max value is unknown (data from files, databases etc.). For me the best is loading everything to List (ArrayList etc.) and use for-each loop. Looping through collections is the best way to short loop syntax in my opinion.
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
When looping through collections, you can use enhanced loops: ``` int[] numbers = {1,2,3,4,5,6,7,8,9,10}; for (int item : numbers) { System.out.println(item); } ```
you can use this way for List's Normal Mode: ``` List<String> myList = Arrays.asList(new String[]{"a","b","c","d","e","f"}); for (int i=0;i<myList.size();i++){ System.out.println(myList.get(i)); } ``` Short Mode 1: ``` List<String> myList = Arrays.asList(new String[]{"a","b","c","d","e","f"}); myList.forEach((...
42,077,768
the code is ``` for(int i = 0; i < max; i++) { //do something } ``` I use this exact code many times when I program, always starting at 0 and using the interval i++. There is really only one variable that changes (max) It could not be that much shorter, but considering how much this code is used, it would be...
2017/02/06
[ "https://Stackoverflow.com/questions/42077768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7525600/" ]
If you use Java 8, you can use `IntStream.range(min, max).foreach(i ->{})`
The for shortcut I thought of is: **for (int i : val)** which works pretty fine for me. Take as an exemple the following code: ``` for (int i = 0; x < val.length; i++) System.out.print(val[i] + ", "); ``` is equivalent with ``` for (int i : val) System.out.print(i + ", "); ``` After having some research, I found ...
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
``` #Creating array x = np.array([[1, 2, 7],[4,5, 6],[7,8,9]]) x Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) #Deletion a = np.delete(x,np.where(x ==7),axis=1) a Out[]: array([[2], [5], [8]]) ```
`numpy` can help you do this! ``` import numpy as np a = np.array([1, 2, 7, 4, 5, 6, 7, 8, 9]).reshape((3, 3)) b = np.array([col for col in a.T if 7 not in col]).T print(b) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
`numpy` can help you do this! ``` import numpy as np a = np.array([1, 2, 7, 4, 5, 6, 7, 8, 9]).reshape((3, 3)) b = np.array([col for col in a.T if 7 not in col]).T print(b) ```
you can use `argwhere` for column index and then delete. ``` import numpy a = numpy.array([[5, 2, 4],[1, 7, 3],[1, 2, 7]]) index = numpy.argwhere(a==7) y = numpy.delete(a, index, axis=1) print(y) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
`numpy` can help you do this! ``` import numpy as np a = np.array([1, 2, 7, 4, 5, 6, 7, 8, 9]).reshape((3, 3)) b = np.array([col for col in a.T if 7 not in col]).T print(b) ```
``` A = np.array([[1,2,7],[4,5,6],[7,8,9]]) for i in range(0,3): ... B=A[:,i] ... if(7 in B): ... A=np.delete(A,i,1) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
``` #Creating array x = np.array([[1, 2, 7],[4,5, 6],[7,8,9]]) x Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) #Deletion a = np.delete(x,np.where(x ==7),axis=1) a Out[]: array([[2], [5], [8]]) ```
you can use `argwhere` for column index and then delete. ``` import numpy a = numpy.array([[5, 2, 4],[1, 7, 3],[1, 2, 7]]) index = numpy.argwhere(a==7) y = numpy.delete(a, index, axis=1) print(y) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
``` #Creating array x = np.array([[1, 2, 7],[4,5, 6],[7,8,9]]) x Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) #Deletion a = np.delete(x,np.where(x ==7),axis=1) a Out[]: array([[2], [5], [8]]) ```
If you don't actually want to delete parts of the original matrix, you can just use boolean indexing: ``` a Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) a[:, ~np.any(a == 7, axis = 1)] Out[]: array([[2], [5], [8]]) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
``` #Creating array x = np.array([[1, 2, 7],[4,5, 6],[7,8,9]]) x Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) #Deletion a = np.delete(x,np.where(x ==7),axis=1) a Out[]: array([[2], [5], [8]]) ```
``` A = np.array([[1,2,7],[4,5,6],[7,8,9]]) for i in range(0,3): ... B=A[:,i] ... if(7 in B): ... A=np.delete(A,i,1) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
If you don't actually want to delete parts of the original matrix, you can just use boolean indexing: ``` a Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) a[:, ~np.any(a == 7, axis = 1)] Out[]: array([[2], [5], [8]]) ```
you can use `argwhere` for column index and then delete. ``` import numpy a = numpy.array([[5, 2, 4],[1, 7, 3],[1, 2, 7]]) index = numpy.argwhere(a==7) y = numpy.delete(a, index, axis=1) print(y) ```
44,560,051
For example, I have a 2D Array with dimensions 3 x 3. ``` [1 2 7 4 5 6 7 8 9] ``` And I want to remove all columns which contain 7 - so first and third, outputting a 3 x 1 matrix of: ``` [2 5 8] ``` How do I go about doing this in python? I want to apply it to a large matrix of n x n dimensions. T...
2017/06/15
[ "https://Stackoverflow.com/questions/44560051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8164362/" ]
If you don't actually want to delete parts of the original matrix, you can just use boolean indexing: ``` a Out[]: array([[1, 2, 7], [4, 5, 6], [7, 8, 9]]) a[:, ~np.any(a == 7, axis = 1)] Out[]: array([[2], [5], [8]]) ```
``` A = np.array([[1,2,7],[4,5,6],[7,8,9]]) for i in range(0,3): ... B=A[:,i] ... if(7 in B): ... A=np.delete(A,i,1) ```
58,338,523
The [documentation](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blockblobservice.blockblobservice?view=azure-python#batch-set-standard-blob-tier-batch-set-blob-tier-sub-requests--timeout-none-) for the batch\_set\_standard\_blob\_tier function part of BlockBlobService in azure pyt...
2019/10/11
[ "https://Stackoverflow.com/questions/58338523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6603039/" ]
You need add `allowSyntheticDefaultImports` in your `tsconfig.json`. `tsconfig.json` ``` { "allowSyntheticDefaultImports": true, "resolveJsonModule": true } ``` TS ``` import countries from './countries/es.json'; ```
import is not a good idea here later on if you want to move your file to some server you will need to rewrite the whole logic i would suggest to use [httpclient](https://angular.io/guide/http) get call here.So move you file to assets folder and then ``` constructor(private http:HttpClient){ this.http.get('assets/yourf...
58,338,523
The [documentation](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blockblobservice.blockblobservice?view=azure-python#batch-set-standard-blob-tier-batch-set-blob-tier-sub-requests--timeout-none-) for the batch\_set\_standard\_blob\_tier function part of BlockBlobService in azure pyt...
2019/10/11
[ "https://Stackoverflow.com/questions/58338523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6603039/" ]
import is not a good idea here later on if you want to move your file to some server you will need to rewrite the whole logic i would suggest to use [httpclient](https://angular.io/guide/http) get call here.So move you file to assets folder and then ``` constructor(private http:HttpClient){ this.http.get('assets/yourf...
What worked form me was: ``` import countries from './countries/es.json'; ``` This is the "default import"
58,338,523
The [documentation](https://learn.microsoft.com/en-us/python/api/azure-storage-blob/azure.storage.blob.blockblobservice.blockblobservice?view=azure-python#batch-set-standard-blob-tier-batch-set-blob-tier-sub-requests--timeout-none-) for the batch\_set\_standard\_blob\_tier function part of BlockBlobService in azure pyt...
2019/10/11
[ "https://Stackoverflow.com/questions/58338523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6603039/" ]
You need add `allowSyntheticDefaultImports` in your `tsconfig.json`. `tsconfig.json` ``` { "allowSyntheticDefaultImports": true, "resolveJsonModule": true } ``` TS ``` import countries from './countries/es.json'; ```
What worked form me was: ``` import countries from './countries/es.json'; ``` This is the "default import"
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
You have to give the assertion message by hand: ``` assert a == b, '%s != %s' % (a, b) # AssertionError: 3 != 4 ```
have you looked at numpy.testing? <https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.testing.html> Amongst others it has: assert\_almost\_equal(actual, desired[, ...]) Raises an AssertionError if two items are not equal up to desired precision. This assert prints out actual and desired. If you ramp up pre...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
You have to give the assertion message by hand: ``` assert a == b, '%s != %s' % (a, b) # AssertionError: 3 != 4 ```
I had similar in the past and end-up writing short custom assert which accept any condition as input. ``` import inspect def custom_assert(condition): if not condition: frame = inspect.currentframe() frame = inspect.getouterframes(frame)[1] call_signature = inspect.getframeinfo(frame[0]).c...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
You have to give the assertion message by hand: ``` assert a == b, '%s != %s' % (a, b) # AssertionError: 3 != 4 ```
The assertEqual or any other assertXxx() method expects the first argument to be an object reference. Generally we call the method as `self.assertEqual(first, second, msg=None)`. Here `self` satisfies the first expected argument. To circumvent this situation we can do the following: ``` from unittest import TestCase a...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
It is possible to create a "helper" new module that provides access to the assert functions. `AssertsAccessor` in this case: ``` from unittest import TestCase # Dummy TestCase instance, so we can initialize an instance # and access the assert instance methods class DummyTestCase(TestCase): def __init__(self): ...
have you looked at numpy.testing? <https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.testing.html> Amongst others it has: assert\_almost\_equal(actual, desired[, ...]) Raises an AssertionError if two items are not equal up to desired precision. This assert prints out actual and desired. If you ramp up pre...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
have you looked at numpy.testing? <https://docs.scipy.org/doc/numpy-1.13.0/reference/routines.testing.html> Amongst others it has: assert\_almost\_equal(actual, desired[, ...]) Raises an AssertionError if two items are not equal up to desired precision. This assert prints out actual and desired. If you ramp up pre...
The assertEqual or any other assertXxx() method expects the first argument to be an object reference. Generally we call the method as `self.assertEqual(first, second, msg=None)`. Here `self` satisfies the first expected argument. To circumvent this situation we can do the following: ``` from unittest import TestCase a...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
It is possible to create a "helper" new module that provides access to the assert functions. `AssertsAccessor` in this case: ``` from unittest import TestCase # Dummy TestCase instance, so we can initialize an instance # and access the assert instance methods class DummyTestCase(TestCase): def __init__(self): ...
I had similar in the past and end-up writing short custom assert which accept any condition as input. ``` import inspect def custom_assert(condition): if not condition: frame = inspect.currentframe() frame = inspect.getouterframes(frame)[1] call_signature = inspect.getframeinfo(frame[0]).c...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
It is possible to create a "helper" new module that provides access to the assert functions. `AssertsAccessor` in this case: ``` from unittest import TestCase # Dummy TestCase instance, so we can initialize an instance # and access the assert instance methods class DummyTestCase(TestCase): def __init__(self): ...
The assertEqual or any other assertXxx() method expects the first argument to be an object reference. Generally we call the method as `self.assertEqual(first, second, msg=None)`. Here `self` satisfies the first expected argument. To circumvent this situation we can do the following: ``` from unittest import TestCase a...
52,907,038
I am looking for a method (if available) that can compare two values and raise an assertion error with a meaningful message when the comparison fails. If I use `assert`, the failure message does not contain what values were compared when then assertion failed. ``` >>> a = 3 >>> b = 4 >>> assert a == b Traceback (most...
2018/10/20
[ "https://Stackoverflow.com/questions/52907038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278326/" ]
I had similar in the past and end-up writing short custom assert which accept any condition as input. ``` import inspect def custom_assert(condition): if not condition: frame = inspect.currentframe() frame = inspect.getouterframes(frame)[1] call_signature = inspect.getframeinfo(frame[0]).c...
The assertEqual or any other assertXxx() method expects the first argument to be an object reference. Generally we call the method as `self.assertEqual(first, second, msg=None)`. Here `self` satisfies the first expected argument. To circumvent this situation we can do the following: ``` from unittest import TestCase a...
69,843,983
I main java and just started on python, and I ran into this error when I was trying to create a class. Can anyone tell me what is wrong? ``` import rectangle a = rectangle(4, 5) print(a.getArea()) ``` this is what is in the rectangle class: ``` class rectangle: l = 0 w = 0 def __init__(self, l, w): ...
2021/11/04
[ "https://Stackoverflow.com/questions/69843983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16533352/" ]
I don't know what you have implemented in the rectangle module but I suspect that what you're actually looking for is this: ``` from rectangle import rectangle a = rectangle(4, 5) print(a.getArea()) ``` If not, give us an indication of what's in rectangle.py
your gonna need to specify what module the function is from so either import all the functions so change `import rectangle` to `from rectangle import *` or switch the `rectangle(4,5)` to `rectangle.rectangle(4,5)`
32,967,460
I have a django site that is deployed in production and already ran `python manage.py runserver` and so now the server is running on the port of `8000`. So what I want to do is to hit the running server and visited this on the domain `domainname.com:8000` and am not getting any response from the server. Should I be d...
2015/10/06
[ "https://Stackoverflow.com/questions/32967460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1140228/" ]
> > I have a django site that is deployed in production and already ran python manage.py runserver > > > That's not how you deploy Django projects in production, cf <https://docs.djangoproject.com/en/1.8/howto/deployment/> The builtin dev server is only made for dev - it's unsafe, doesn't handle concurrent reque...
Additionally to @bruno desthuilliers answer, with which I totally agree, if nevertheless you insist, you have to run the server as: ``` python manage.py runserver 0.0.0.0:8000 ``` so that to let it listen to any interface. Relevant documentation: [django-admin](https://docs.djangoproject.com/en/1.8/ref/django-admin...
61,114,206
Recently I created a 24 game solver with python Read this website if you do not know what the 24 game is: <https://www.pagat.com/adders/24.html> Here is the code: ``` from itertools import permutations, product, chain, zip_longest from fractions import Fraction as F solutions = [] def ask4(): num1 = input...
2020/04/09
[ "https://Stackoverflow.com/questions/61114206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10379866/" ]
On the network tab, you must select the post request and then go to the parameters you are sending and check if you are sending the data and if it is the right structure. This is how it looks like on Chrome there is where you check the data you are sending [![This is how it looks on Chrome](https://i.stack.imgur.com/fF...
meaby you can try with axios instance ajax
15,969,213
I have recently been working on a pet project in python using flask. It is a simple pastebin with server-side syntax highlighting support with pygments. Because this is a costly task, I delegated the syntax highlighting to a celery task queue and in the request handler I'm waiting for it to finish. Needless to say this...
2013/04/12
[ "https://Stackoverflow.com/questions/15969213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/492162/" ]
It should be thread-safe to do something like the following to separate cpu intensive tasks into asynchronous threads: ``` from threading import Thread def send_async_email(msg): mail.send(msg) def send_email(subject, sender, recipients, text_body, html_body): msg = Message(subject, sender = sender, recipien...
How about simply using ThreadPool and Queue? You can then process your stuff in a seperate thread in a synchronous manner and you won't have to worry about blocking at all. Well, Python is not suited for CPU bound tasks in the first place, so you should also think of spawning subprocesses.
27,260,199
So I have this issue where libv8-3.16.14.3 fails to install, even though it deceptively tells you it did install. So the first sign of issue was when it did: ``` An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue. Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundlin...
2014/12/02
[ "https://Stackoverflow.com/questions/27260199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4005826/" ]
I got this to work by first using Homebrew to install V8: ``` $ brew install v8 ``` Then running the command you mentioned you found on Google: ``` $ gem install libv8 -v '3.16.14.3' -- --with-system-v8 ``` And finally re-running bundle install: ``` $ bundle install ```
As others have suggested: ``` $ brew install v8 $ gem install libv8 -v '3.16.14.3' -- --with-system-v8 $ bundle install ``` If that does not work, try running `bundle update`. Running `bundle update` in addition was the only way it worked
27,260,199
So I have this issue where libv8-3.16.14.3 fails to install, even though it deceptively tells you it did install. So the first sign of issue was when it did: ``` An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue. Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundlin...
2014/12/02
[ "https://Stackoverflow.com/questions/27260199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4005826/" ]
I got this to work by first using Homebrew to install V8: ``` $ brew install v8 ``` Then running the command you mentioned you found on Google: ``` $ gem install libv8 -v '3.16.14.3' -- --with-system-v8 ``` And finally re-running bundle install: ``` $ bundle install ```
This error is common with projects with therubyracer and the other answers didn't solve it for me. They helped though. Order of install seem to be the clue. ``` $ gem uninstall libv8 Successfully uninstalled libv8-3.16.14.13 $ gem install therubyracer -v '0.12.2' 2 gems installed $ bundle CRASH $ gem install libv8 -v ...
27,260,199
So I have this issue where libv8-3.16.14.3 fails to install, even though it deceptively tells you it did install. So the first sign of issue was when it did: ``` An error occurred while installing libv8 (3.16.14.3), and Bundler cannot continue. Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundlin...
2014/12/02
[ "https://Stackoverflow.com/questions/27260199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4005826/" ]
This error is common with projects with therubyracer and the other answers didn't solve it for me. They helped though. Order of install seem to be the clue. ``` $ gem uninstall libv8 Successfully uninstalled libv8-3.16.14.13 $ gem install therubyracer -v '0.12.2' 2 gems installed $ bundle CRASH $ gem install libv8 -v ...
As others have suggested: ``` $ brew install v8 $ gem install libv8 -v '3.16.14.3' -- --with-system-v8 $ bundle install ``` If that does not work, try running `bundle update`. Running `bundle update` in addition was the only way it worked
3,442,920
I can't seem to find any information on debugging a python web application, specifically stepping through the execution of a web request. is this just not possible? if no, why not?
2010/08/09
[ "https://Stackoverflow.com/questions/3442920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39677/" ]
If you put ``` import pdb pdb.set_trace() ``` in your code, the web app will drop to a pdb debugger session upon executing `set_trace`. Also useful, is ``` import code code.interact(local=locals()) ``` which drops you to the python interpreter. Pressing Ctrl-d resumes execution. Still more useful, is ``` im...
use Python Debbuger, `import pdb; pdb.set_trace()` exactly where you want to start debugging, and your terminal will pause in that line. More info here: <http://plone.org/documentation/kb/using-pdb>
3,442,920
I can't seem to find any information on debugging a python web application, specifically stepping through the execution of a web request. is this just not possible? if no, why not?
2010/08/09
[ "https://Stackoverflow.com/questions/3442920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39677/" ]
If you put ``` import pdb pdb.set_trace() ``` in your code, the web app will drop to a pdb debugger session upon executing `set_trace`. Also useful, is ``` import code code.interact(local=locals()) ``` which drops you to the python interpreter. Pressing Ctrl-d resumes execution. Still more useful, is ``` im...
If you are running your web application through apache and [mod\_wsgi](http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Python_Interactive_Debugger) or [mod\_python](http://www.modpython.org/python10/), both provide some support for step through debugging with pdb. The trick is you have to run apache in foregr...
3,442,920
I can't seem to find any information on debugging a python web application, specifically stepping through the execution of a web request. is this just not possible? if no, why not?
2010/08/09
[ "https://Stackoverflow.com/questions/3442920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39677/" ]
If you are running your web application through apache and [mod\_wsgi](http://code.google.com/p/modwsgi/wiki/DebuggingTechniques#Python_Interactive_Debugger) or [mod\_python](http://www.modpython.org/python10/), both provide some support for step through debugging with pdb. The trick is you have to run apache in foregr...
use Python Debbuger, `import pdb; pdb.set_trace()` exactly where you want to start debugging, and your terminal will pause in that line. More info here: <http://plone.org/documentation/kb/using-pdb>
17,919,788
I tried to run my python scripts using crontab. As the amount of my python scripts accumulates, it is hard to manage in crontab. Then I tries two python schedule task libraries named [Advanced Python Scheduler](http://pythonhosted.org/APScheduler/) and [schedule](https://github.com/dbader/schedule). The two librarie...
2013/07/29
[ "https://Stackoverflow.com/questions/17919788", "https://Stackoverflow.com", "https://Stackoverflow.com/users/975222/" ]
In 2013 - when this question was created - there were not as many workflow/scheduler management tools freely available on the market as they are today. So, writing this answer in 2021, I would suggest using Crontab as long as you have only few scripts on very few machines. With a growing collection of scripts, the ne...
One way is to use [management commands](https://docs.djangoproject.com/en/dev/howto/custom-management-commands/) and setup a crontab to run those. We use that in production and it works really well. Another is to use something like celery to [schedule tasks](http://docs.celeryproject.org/en/latest/reference/celery.sch...
15,096,667
I'm trying to convert code from TCL into python using Tkinter. I was wondering what would be the equivalent code in Tkinter for "spawn ssh", "expect", and "send"? For example, my simple tcl program would be something like: ``` spawn ssh [email protected].###.### expect "(yes/no)?" {send -- "yes\r"} expect "password" {send...
2013/02/26
[ "https://Stackoverflow.com/questions/15096667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1988580/" ]
You could try to use [pexpect](http://www.noah.org/wiki/pexpect). Expect is used to automate other command line tools. Edit: Of curse you could just try to execute `package require Expect` through Tkinter, but what benefit would that have over a pure Tcl script? After all you write Tcl code then, wraped in python. A...
[pxpect](http://pexpect.sourceforge.net) has a module called pxssh, that takes a lot of the the work out of manipulating simple ssh sessions. I found that this wasn't sufficient for heavy automation and wrote [remote](http://gethub.com/Telenav/python-remote) as an add-on to increase error handling. using pxssh ``` fr...
22,791,074
![enter image description here](https://i.stack.imgur.com/U10sa.jpg) what function should i use to draw the above performance profile of different algorithms, the running time data is from python implementation, stored in lists for different algorithm. Is there any build-in function in Python or Matlab to draw this ki...
2014/04/01
[ "https://Stackoverflow.com/questions/22791074", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3029108/" ]
You can absolutely have a state without a URL. In fact, none of your states need URLs. That's a core part of the design. Having said that, I wouldn't do what you did above. If you want two states to have the same URL, create an [abstract parent state](https://github.com/angular-ui/ui-router/wiki/Nested-States-%26-Nest...
To add to the other answer, Multiple Named Views do not use a URL. From the docs: > > If you define a views object, your state's templateUrl, template and > templateProvider will be ignored. So in the case that you need a > parent layout of these views, you can define an abstract state that > contains a template...
25,185,015
I am using python request module for doing HTTP communications. I was using proxy before doing any communication. ``` import requests proxy = {'http': 'xxx.xxx.xxx.xxx:port'} OR proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'} OR proxy = {'http://xxx.xxx.xxx.xxx:port'} request...
2014/08/07
[ "https://Stackoverflow.com/questions/25185015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1000683/" ]
Try this: ``` proxy = {'http': 'http://xxx.xxx.xxx.xxx:port'} ``` I guess you just missed the `http://` in the value of the proxy dict. Check: <http://docs.python-requests.org/en/latest/user/advanced/#proxies>
[Documentation](http://docs.python-requests.org/en/latest/user/advanced/#proxies) says: > > If you need to use a proxy, you can configure individual requests with > the proxies argument to any request method: > > > ``` import requests proxies = {"http": "http://10.10.1.10:3128"} requests.get("http://example.org"...
61,226,690
I am relatively new to Python so please pardon my ignorance. I want to know answer to following questions 1. How does pip know the location to install packages that it installs? After a built of trial and error I suspect that it maybe hardcoded at time of installation. 2. Are executables like pip.exe what they call f...
2020/04/15
[ "https://Stackoverflow.com/questions/61226690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10796482/" ]
as I understand you only want to save user input only if contains text so you have to clean the user input from HTML then check the output length ``` var regex = /(<([^>]+)>)/ig body = "<p>test</p>" hasText = !!body.replace(regex, "").length; if(hasText) save() ```
This worked for me so it wouldn't escape images. ``` function isQuillEmpty(value: string) { if (value.replace(/<(.|\n)*?>/g, '').trim().length === 0 && !value.includes("<img")) { return true; } return false; } ```
37,308,794
I'm new to this and trying to deploy a first app to the app engine. However, when i try to i get this message: "This application does not exist (app\_id=u'udacity')." I fear it might have to do with the app.yaml file so i'll just leave here what i have there: application: udacity version: 1 runtime: python27 api\_vers...
2016/05/18
[ "https://Stackoverflow.com/questions/37308794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6002144/" ]
Blocks are normal objects so you can store them in NSArray/NSDictionary. Having that said the implementation is straightforward. ``` #import <Foundation/Foundation.h> /** LBNotificationCenter.h */ typedef void (^Observer)(NSString *name, id data); @interface LBNotificationCenter : NSObject - (void)addObserverForN...
Why don't you just add the blocks into the `NSDictionary` ? You can do it like it's explained [in this answer](https://stackoverflow.com/questions/6364648/keep-blocks-inside-a-dictionary)
38,435,845
I am newbie to elasticsearch, I know there is two official client elasticsearch supplies, but when I use the python elasticsearch, i can't find how to use the transport client.. I read the whole doc which is as following: ``` https://elasticsearch-py.readthedocs.io/en/master/index.html ``` I also search some docs...
2016/07/18
[ "https://Stackoverflow.com/questions/38435845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6114947/" ]
The transport client is written in Java, so the only way to use it from Python is by switching to Jython.
I think the previous answer is out of date now, if this is [the transport client you mean](https://elasticsearch-py.readthedocs.io/en/master/transports.html). I've made use of this API to do things like use the [\_rank\_eval](https://www.elastic.co/guide/en/elasticsearch/reference/6.7/search-rank-eval.html) API, whic...
56,415,470
IPython 7.5 documentation states: > > Change to Nested Embed > > > The introduction of the ability to run async code had some effect on the IPython.embed() API. By default, embed > will not allow you to run asynchronous code unless an event loop is specified. > > > However, there seem to be no description how ...
2019/06/02
[ "https://Stackoverflow.com/questions/56415470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6543759/" ]
``` from IPython import embed import nest_asyncio nest_asyncio.apply() ``` Then `embed(using='asyncio')` might somewhat work. I don't know why they don't give us a real solution though.
This seems to be possible, but you have to use `ipykernel.embed.embed_kernel()` instead of `IPython.embed()`. `ipykernel` requires you to connect to the embedded kernel remotely from a separate jupyter console though, so it is not as convenient as just being able to spawn the shell on the same window, but at least it ...
62,175,337
I want to fetch the next 5 records after the specific index. For example, this is my dataframe: ``` Id Name code 1 java 45 2 python 78 3 c 65 4 c++ 25 5 html 74 6 css 63 7 javascript 45 8 php 44 ...
2020/06/03
[ "https://Stackoverflow.com/questions/62175337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10971762/" ]
Set up properties on the file attached to the solution, basically you need to make sure the file is included to the solution output: 1. Set the `Build Action` property to `Content`. 2. Set the `Copy to the Output Directory` property to `Copy Always`. For example, if the file is added to the project and you select it ...
You really need to add that that utility to you installer project. Or you can embed the utility as a resource in your dll, extract it at run-time, copy to some folder, and execute.
62,175,337
I want to fetch the next 5 records after the specific index. For example, this is my dataframe: ``` Id Name code 1 java 45 2 python 78 3 c 65 4 c++ 25 5 html 74 6 css 63 7 javascript 45 8 php 44 ...
2020/06/03
[ "https://Stackoverflow.com/questions/62175337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10971762/" ]
So, To whomever it may be useful, on top of Eugene's answer, what was missing is that I needed to add the Content files to my project output. To do that, right-click on your Setup project and Add...> Project Output...> Content Files. [![enter image description here](https://i.stack.imgur.com/XRq9m.png)](https://i.sta...
You really need to add that that utility to you installer project. Or you can embed the utility as a resource in your dll, extract it at run-time, copy to some folder, and execute.
62,579,298
I have a data frame that looks like this: ``` name Title abc 'Tech support' xyz 'UX designer' ghj 'Manager IT' ... .... ``` I want to iterate through the data frame and using `df.str.contains` make another column that will categorize those jobs. T...
2020/06/25
[ "https://Stackoverflow.com/questions/62579298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12724372/" ]
You can do something like this: ``` cat_dict = {"Support":"Support", "designer":"Designer", "Manager": "Management"} df['category'] = (df['Title'].str.extract(fr"\b({'|'.join(cat_dict.keys())})\b")[0] .map(cat_dict) ) ```
General syntax of python if statement is: ``` if test expression: Body of if elif test expression: Body of elif else: Body of else ``` As you can see in the syntax, to evaluate a *test expression*, it should be in the *if* or in the *elif* construct. The code throws the syntax error as the test expre...
62,579,298
I have a data frame that looks like this: ``` name Title abc 'Tech support' xyz 'UX designer' ghj 'Manager IT' ... .... ``` I want to iterate through the data frame and using `df.str.contains` make another column that will categorize those jobs. T...
2020/06/25
[ "https://Stackoverflow.com/questions/62579298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12724372/" ]
You can do something like this: ``` cat_dict = {"Support":"Support", "designer":"Designer", "Manager": "Management"} df['category'] = (df['Title'].str.extract(fr"\b({'|'.join(cat_dict.keys())})\b")[0] .map(cat_dict) ) ```
This answer: [Iterate through rows and change value](https://stackoverflow.com/questions/56187195/iterate-through-rows-in-a-dataframe-and-change-value-of-a-column-based-on-other) should get you going! Lmk, if you have more questions!
62,579,298
I have a data frame that looks like this: ``` name Title abc 'Tech support' xyz 'UX designer' ghj 'Manager IT' ... .... ``` I want to iterate through the data frame and using `df.str.contains` make another column that will categorize those jobs. T...
2020/06/25
[ "https://Stackoverflow.com/questions/62579298", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12724372/" ]
You can do something like this: ``` cat_dict = {"Support":"Support", "designer":"Designer", "Manager": "Management"} df['category'] = (df['Title'].str.extract(fr"\b({'|'.join(cat_dict.keys())})\b")[0] .map(cat_dict) ) ```
Here you go: ```py import pandas as pd from io import StringIO df = pd.read_csv(StringIO(""" name Title abc Tech support xyz UX designer ghj Manager IT """), sep='\s{2,}', engine='python') masks = [df.Title.str.lower().str.contains('support'), df.Title.str.lower().str.conta...
57,309,209
I am working on a data frame with DateTimeIndex of hourly temperature data spanning a couple of years. I want to add a column with the minimum temperature between 20:00 of a day and 8:00 of the *following* day. Daytime temperatures - from 8:00 to 20:00 - are not of interest. The result can either be at the same hourly ...
2019/08/01
[ "https://Stackoverflow.com/questions/57309209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7057547/" ]
Use the `base` option to `resample`: ``` rs = df.resample('12h', base=8).min() ``` Then keep only the rows for 20:00: ``` rs[rs.index.hour == 20] ```
you can use `TimeGrouper` with `freq=12h` and `base=8` to chunk the dataframe every 12h from 20:00 - (+day)08:00, then you can just use `.min()` try this: ```py import pandas as pd from io import StringIO s = """ datetime temp 2009-07-01 01:00:00 17.16 2009-07-01 02:00:00 16.64 2009-07-01 ...
54,403,437
I want to script with python using Notepad ++ but it works strangely, actually it does not work, so I have pycharm an everything is going well but in notepad ++ when I save file with .py and click run it does not work is there a step by step instruction to follow? I have same problem with sublime text editor so I am lu...
2019/01/28
[ "https://Stackoverflow.com/questions/54403437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10979398/" ]
You call `setPreferredSize` twice, which results in the first call doing basically nothing. That means you always have a `preferredSize` equal to the dimensions of the second image. What you *should* do is to set the size to `new Dimension(image.getWidth() + image2.getWidth(), image2.getHeight())` assuming both have th...
I found some errors in your code and I did not got what are you trying to do... 1] Over there you are actually not using the first setup ``` Dimension dimension = new Dimension(image.getWidth(), image.getHeight()); setPreferredSize(dimension); //not used Dimension dimension2 = new Dimension(image2.getWidt...
54,403,437
I want to script with python using Notepad ++ but it works strangely, actually it does not work, so I have pycharm an everything is going well but in notepad ++ when I save file with .py and click run it does not work is there a step by step instruction to follow? I have same problem with sublime text editor so I am lu...
2019/01/28
[ "https://Stackoverflow.com/questions/54403437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10979398/" ]
You call `setPreferredSize` twice, which results in the first call doing basically nothing. That means you always have a `preferredSize` equal to the dimensions of the second image. What you *should* do is to set the size to `new Dimension(image.getWidth() + image2.getWidth(), image2.getHeight())` assuming both have th...
I would join the images whenever something changes and draw them to another buffered image. Then I can just redraw the combined image whenever the panel needs to be redrawn. [![Application](https://i.stack.imgur.com/d8QSk.png)](https://i.stack.imgur.com/d8QSk.png) ``` import java.awt.*; import java.awt.image.Buffered...
54,403,437
I want to script with python using Notepad ++ but it works strangely, actually it does not work, so I have pycharm an everything is going well but in notepad ++ when I save file with .py and click run it does not work is there a step by step instruction to follow? I have same problem with sublime text editor so I am lu...
2019/01/28
[ "https://Stackoverflow.com/questions/54403437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10979398/" ]
The logic of the math was incorrect. See the `getPreferredSize()` method for the correct way to calculate the required width, and the changes to the `paintComponent(Graphics)` method to place them side-by-side. An alternative (not examined in this answer) is to put each image into a `JLabel`, then add the labels to a ...
I found some errors in your code and I did not got what are you trying to do... 1] Over there you are actually not using the first setup ``` Dimension dimension = new Dimension(image.getWidth(), image.getHeight()); setPreferredSize(dimension); //not used Dimension dimension2 = new Dimension(image2.getWidt...
54,403,437
I want to script with python using Notepad ++ but it works strangely, actually it does not work, so I have pycharm an everything is going well but in notepad ++ when I save file with .py and click run it does not work is there a step by step instruction to follow? I have same problem with sublime text editor so I am lu...
2019/01/28
[ "https://Stackoverflow.com/questions/54403437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10979398/" ]
The logic of the math was incorrect. See the `getPreferredSize()` method for the correct way to calculate the required width, and the changes to the `paintComponent(Graphics)` method to place them side-by-side. An alternative (not examined in this answer) is to put each image into a `JLabel`, then add the labels to a ...
I would join the images whenever something changes and draw them to another buffered image. Then I can just redraw the combined image whenever the panel needs to be redrawn. [![Application](https://i.stack.imgur.com/d8QSk.png)](https://i.stack.imgur.com/d8QSk.png) ``` import java.awt.*; import java.awt.image.Buffered...
44,857,219
When I use the command "pip install pyperclip" it gives me this error ``` creating /Library/Python/2.7/site-packages/pyperclip error: could not create '/Library/Python/2.7/site-packages/pyperclip': Permission denied ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, token...
2017/07/01
[ "https://Stackoverflow.com/questions/44857219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4081977/" ]
When ever you get error `Permission denied` its because you are trying to access the root using normal commands. So trying running the command as root to get rid of `Permissin denied` error. Run `sudo command` i.e `sudo pip install pyperclip`
Try it with > > sudo pip install pyperclip > > > Now if it throws some access deny error, try this: > > sudo pip -H install pyperclip > > >
44,857,219
When I use the command "pip install pyperclip" it gives me this error ``` creating /Library/Python/2.7/site-packages/pyperclip error: could not create '/Library/Python/2.7/site-packages/pyperclip': Permission denied ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, token...
2017/07/01
[ "https://Stackoverflow.com/questions/44857219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4081977/" ]
When ever you get error `Permission denied` its because you are trying to access the root using normal commands. So trying running the command as root to get rid of `Permissin denied` error. Run `sudo command` i.e `sudo pip install pyperclip`
//These below three commands worked for MacBook Pro to install Pip & Pyperclip 1./Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m pip install --upgrade pip 2./Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/scripts 3.sudo pip3 install pyperclip output: Downloading pip-21.2.4-py3-non...
44,857,219
When I use the command "pip install pyperclip" it gives me this error ``` creating /Library/Python/2.7/site-packages/pyperclip error: could not create '/Library/Python/2.7/site-packages/pyperclip': Permission denied ---------------------------------------- Command "/usr/bin/python -u -c "import setuptools, token...
2017/07/01
[ "https://Stackoverflow.com/questions/44857219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4081977/" ]
Try it with > > sudo pip install pyperclip > > > Now if it throws some access deny error, try this: > > sudo pip -H install pyperclip > > >
//These below three commands worked for MacBook Pro to install Pip & Pyperclip 1./Library/Frameworks/Python.framework/Versions/3.9/bin/python3.9 -m pip install --upgrade pip 2./Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/scripts 3.sudo pip3 install pyperclip output: Downloading pip-21.2.4-py3-non...
7,238,401
I've found similar but not identical questions [742371](https://stackoverflow.com/questions/742371/python-strange-behavior-in-for-loop-or-lists) and [4081217](https://stackoverflow.com/questions/4081217/how-to-modify-list-entries-during-for-loop) with great answers, but haven't come to a solution to my problem. I'm tr...
2011/08/30
[ "https://Stackoverflow.com/questions/7238401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/563343/" ]
How about something like this (just made up a silly condition so I could test it): ``` import random myList = ['it1', 'test', 'blah', 10] newList = [] def someCondition(var): return random.randrange(0,2) == 0 def test(): while len(myList) > 0: pos = 0 while pos < len(myList): if...
A brute force approach would be to create a temporary list of booleans the same size as your original list initialized to `False` everywhere. In each pass, whenever the item at index `i` of the original list meets the condition, update the value in the temporary array at index `i` with False. In each subsequent pass,...
7,238,401
I've found similar but not identical questions [742371](https://stackoverflow.com/questions/742371/python-strange-behavior-in-for-loop-or-lists) and [4081217](https://stackoverflow.com/questions/4081217/how-to-modify-list-entries-during-for-loop) with great answers, but haven't come to a solution to my problem. I'm tr...
2011/08/30
[ "https://Stackoverflow.com/questions/7238401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/563343/" ]
``` current = ['it1', 'test', 'blah', 10] results = [] while current: remaining = [] for item in current: (results if meets_conditional(item) else remaining).append(item) current = remaining ```
A brute force approach would be to create a temporary list of booleans the same size as your original list initialized to `False` everywhere. In each pass, whenever the item at index `i` of the original list meets the condition, update the value in the temporary array at index `i` with False. In each subsequent pass,...
7,238,401
I've found similar but not identical questions [742371](https://stackoverflow.com/questions/742371/python-strange-behavior-in-for-loop-or-lists) and [4081217](https://stackoverflow.com/questions/4081217/how-to-modify-list-entries-during-for-loop) with great answers, but haven't come to a solution to my problem. I'm tr...
2011/08/30
[ "https://Stackoverflow.com/questions/7238401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/563343/" ]
``` current = ['it1', 'test', 'blah', 10] results = [] while current: remaining = [] for item in current: (results if meets_conditional(item) else remaining).append(item) current = remaining ```
How about something like this (just made up a silly condition so I could test it): ``` import random myList = ['it1', 'test', 'blah', 10] newList = [] def someCondition(var): return random.randrange(0,2) == 0 def test(): while len(myList) > 0: pos = 0 while pos < len(myList): if...
65,063,178
I am trying to create a hangman game using python in VScode. I imported pygame and now it won't let me do pygame.init(). I looked at other posts here and I tried it but I'm not sure why it is not working. Other posts said to go to setting.json and add ``` { "python.linting.pylintArgs": [ "--extension-pkg-whitelist...
2020/11/29
[ "https://Stackoverflow.com/questions/65063178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14730665/" ]
1. If you want to turn off Pylint notifications via settings, please use the following format: > > > ``` > "python.linting.pylintArgs": > [ > "--extension-pkg-whitelist=lxml", // The extension is "lxml" not "1xml" > "--unsafe-load-any-extension=y" > ], > > ``` > > [![enter image d...
Vscode has launched new python language server `pylance` install it from extensions. After that change you language server to pylance. You will get amazing features like autoimport, auto completion, linter, debugger, etc. Also check in which environment you have installed pygame. Switch the python interpreter using ctr...
66,321,777
I have a Flask server that will fetch keys from Redis. How would I maintain a list of already deleted keys? Every time I delete a key, it needs to be added to this list within Redis. Every time I try to check for a key in the cache, if it cannot be found I want to check if it is already deleted. This would allow me to ...
2021/02/22
[ "https://Stackoverflow.com/questions/66321777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/127251/" ]
I think you should separate the name and the number into different attributes: ``` name | number | id ``` and the SQL query should be something like this: ``` select ... group by name, number; ``` depending on what you want to do. Is something like this?
The grouping SQL statement will be ``` select id, name from commande_ligne group by name order by name ``` The outcome should show product 78 id 5 6 11 Product 12 Id 14 15 That's the result that you will get
66,321,777
I have a Flask server that will fetch keys from Redis. How would I maintain a list of already deleted keys? Every time I delete a key, it needs to be added to this list within Redis. Every time I try to check for a key in the cache, if it cannot be found I want to check if it is already deleted. This would allow me to ...
2021/02/22
[ "https://Stackoverflow.com/questions/66321777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/127251/" ]
If you want all the values of `id` among the duplicates, you can do it this way: ``` select name, GROUP_CONCAT(id) from commande_ligne group by name having count(name) > 1; ``` Read more about the [GROUP\_CONCAT() function](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat).
I think you should separate the name and the number into different attributes: ``` name | number | id ``` and the SQL query should be something like this: ``` select ... group by name, number; ``` depending on what you want to do. Is something like this?
66,321,777
I have a Flask server that will fetch keys from Redis. How would I maintain a list of already deleted keys? Every time I delete a key, it needs to be added to this list within Redis. Every time I try to check for a key in the cache, if it cannot be found I want to check if it is already deleted. This would allow me to ...
2021/02/22
[ "https://Stackoverflow.com/questions/66321777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/127251/" ]
With the data sample provided with name as Product 78 with an Id, the result you looking for cannot be achieved because under the Unique ID there is always one Product 78 with a unique ID, so that cannot be grouped by IDs, however, you can group by Name for the different ID for grouped records by name for Product 78 it...
The grouping SQL statement will be ``` select id, name from commande_ligne group by name order by name ``` The outcome should show product 78 id 5 6 11 Product 12 Id 14 15 That's the result that you will get
66,321,777
I have a Flask server that will fetch keys from Redis. How would I maintain a list of already deleted keys? Every time I delete a key, it needs to be added to this list within Redis. Every time I try to check for a key in the cache, if it cannot be found I want to check if it is already deleted. This would allow me to ...
2021/02/22
[ "https://Stackoverflow.com/questions/66321777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/127251/" ]
If you want all the values of `id` among the duplicates, you can do it this way: ``` select name, GROUP_CONCAT(id) from commande_ligne group by name having count(name) > 1; ``` Read more about the [GROUP\_CONCAT() function](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat).
With the data sample provided with name as Product 78 with an Id, the result you looking for cannot be achieved because under the Unique ID there is always one Product 78 with a unique ID, so that cannot be grouped by IDs, however, you can group by Name for the different ID for grouped records by name for Product 78 it...
66,321,777
I have a Flask server that will fetch keys from Redis. How would I maintain a list of already deleted keys? Every time I delete a key, it needs to be added to this list within Redis. Every time I try to check for a key in the cache, if it cannot be found I want to check if it is already deleted. This would allow me to ...
2021/02/22
[ "https://Stackoverflow.com/questions/66321777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/127251/" ]
If you want all the values of `id` among the duplicates, you can do it this way: ``` select name, GROUP_CONCAT(id) from commande_ligne group by name having count(name) > 1; ``` Read more about the [GROUP\_CONCAT() function](https://dev.mysql.com/doc/refman/8.0/en/aggregate-functions.html#function_group-concat).
The grouping SQL statement will be ``` select id, name from commande_ligne group by name order by name ``` The outcome should show product 78 id 5 6 11 Product 12 Id 14 15 That's the result that you will get
67,108,896
I am using python for webscraping (new to this) and am trying to grab the brand name from a website. It is not visible on the website but I have found the element for it: `<span itemprop="Brand" style="display:none;">Revlon</span>` I want to extract the "Revlon" text in the HTML. I am currently using html requests a...
2021/04/15
[ "https://Stackoverflow.com/questions/67108896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11472545/" ]
Here is a working solution with Selenium: ``` from seleniumwire import webdriver from webdriver_manager.chrome import ChromeDriverManager driver = webdriver.Chrome(ChromeDriverManager().install()) website = 'https://www.boots.com/revlon-colorstay-makeup-for-normal-dry-skin-10212694' driver.get(website) brand_name ...
try this method .find("span", itemprop="Brand") I think it's work ``` from bs4 import BeautifulSoup import requests urlpage = 'https://www.boots.com/revlon-colorstay-makeup-for-normal-dry-skin-10212694' page = requests.get(urlpage) # parse the html using beautiful soup and store in variable 'soup' soup = BeautifulSo...
56,613,286
Say that I have a list of strings, such as ``` listStrings = [ 'cat', 'bat', 'hat', 'dad', 'look', 'ball', 'hero', 'up'] ``` Is there a way would return all rows if a particular column contains 3 or more of the strings from the list? For example If the column contained 'My dad is a hero for saving the cat' Then...
2019/06/15
[ "https://Stackoverflow.com/questions/56613286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3259896/" ]
You could use something like this: ``` $reviews = Review::orderBy('created_at', 'DESC') ->orWhere('created_at','>=',now()->subDays($request->review == 7 ? 7 : 30) ->where('listing_id', $id) ->where('user_id', Auth::user()->id) ->paginate(6, ['*'], 'review'); ``` but keep in mind you might still get w...
You can split Eloquent Builder by cursor. ```php $cursor = Review::orderByDesc('created_at'); if ($request->review == "7") { $cursor->orWhere('created_at','>=', 7)); } $reviews = $cursor->where('listing_id', $id) ->where('user_id', Auth::user()->id) ->paginate(6, ['*'], 'review'); ```
56,613,286
Say that I have a list of strings, such as ``` listStrings = [ 'cat', 'bat', 'hat', 'dad', 'look', 'ball', 'hero', 'up'] ``` Is there a way would return all rows if a particular column contains 3 or more of the strings from the list? For example If the column contained 'My dad is a hero for saving the cat' Then...
2019/06/15
[ "https://Stackoverflow.com/questions/56613286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3259896/" ]
You could use something like this: ``` $reviews = Review::orderBy('created_at', 'DESC') ->orWhere('created_at','>=',now()->subDays($request->review == 7 ? 7 : 30) ->where('listing_id', $id) ->where('user_id', Auth::user()->id) ->paginate(6, ['*'], 'review'); ``` but keep in mind you might still get w...
``` $reviews = Review::where('listing_id', $id) ->where('user_id', Auth::user()->id); if($request->review == 7){ $reviews->Where('created_at','>=',now()->subDays($request->review)); } if($request->review != 7){ $reviews->Where('created_at','>=',now()->subDays(30)); } $reviews->orderBy('creat...
56,613,286
Say that I have a list of strings, such as ``` listStrings = [ 'cat', 'bat', 'hat', 'dad', 'look', 'ball', 'hero', 'up'] ``` Is there a way would return all rows if a particular column contains 3 or more of the strings from the list? For example If the column contained 'My dad is a hero for saving the cat' Then...
2019/06/15
[ "https://Stackoverflow.com/questions/56613286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3259896/" ]
You could use something like this: ``` $reviews = Review::orderBy('created_at', 'DESC') ->orWhere('created_at','>=',now()->subDays($request->review == 7 ? 7 : 30) ->where('listing_id', $id) ->where('user_id', Auth::user()->id) ->paginate(6, ['*'], 'review'); ``` but keep in mind you might still get w...
$reviews = Review::orderBy('created\_at', 'DESC'); if ($request->review == "7") { ``` $reviews->orWhere('created_at','>=', 7)); ``` } $reviews = $reviews->where('listing\_id', $id) ``` ->where('user_id', Auth::User()->id) ->paginate(6, ['*'], 'review'); ```
21,449,085
I may get slammed because this question is too broad, but anyway I going to ask cause what else do I do? Digging through the Python source code should surely give me enough "good effort" points to warrant helping me? I am trying to use Python 3.4's new email content manager <http://docs.python.org/dev/library/email.co...
2014/01/30
[ "https://Stackoverflow.com/questions/21449085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/627492/" ]
First: the “address fields” in an email are in fact simply headers whose names have been agreed upon in standards, like `To` and `From`. So all you need are the email headers and body and you are done. Given a modern `contentmanager`-powered `EmailMessage` instance such as Python 3.4 returns if you specify a policy (l...
If you have an email in a file and want to read it into Python, it's the [`email.Parser` you should probably look at](http://docs.python.org/dev/library/email.parser.html#parser-class-api) first. [Like Brandon](https://stackoverflow.com/a/22697432/923794), I don't quite see the need for using the `contentmanager`, but ...
48,065,360
I want to use python interpolate polynomial on points from a finite-field and get a polynomial with coefficients in that field. Currently I'm trying to use SymPy and specifically interpolate (from `sympy.polys.polyfuncs`), but I don't know how to force the interpolation to happen in a specific gf. If not, can this be ...
2018/01/02
[ "https://Stackoverflow.com/questions/48065360", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5603149/" ]
SymPy's [interpolating\_poly](http://docs.sympy.org/latest/modules/polys/reference.html#sympy.polys.specialpolys.interpolating_poly) does not support polynomials over finite fields. But there are enough details under the hood of SymPy to put together a class for finite fields, and find the coefficients of [Lagrange pol...
I'm the author of the [`galois`](https://github.com/mhostetter/galois) Python library. Polynomial interpolation can be performed with the `lagrange_poly()` function. Here's a simple example. ```py In [1]: import galois In [2]: galois.__version__ Out[2]: '0.0.32' In [3]: GF = galois.GF(3**5) In [4]: x = GF.Random(10...
16,809,248
My works relates to instrumentation of code fragments in python code. So in my work i would be writing a script in python such that I take another python file as input and insert any necessary code in the required place with my script. The following code is a sample code of a file which i would be instrumenting: ``` ...
2013/05/29
[ "https://Stackoverflow.com/questions/16809248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2135762/" ]
Use the [`ast` module](http://docs.python.org/2/library/ast.html) to parse the file properly. This code prints the line number and column offset of each `def` statement: ``` import ast with open('mymodule.py') as f: tree = ast.parse(f.read()) for node in ast.walk(tree): if isinstance(node, ast.FunctionDef): ...
You could use a Regular Expression. To avoid `def` inside quotes then you can use negative look-arounds: ``` import re for line in open('A.py'): m = re.search(r"(?!<[\"'])\bdef\b(?![\"'])", line) if m: print r'@decorator #<------ inserted code' print line ``` However, there might be other ...
26,027,271
I have a dictionary of configs (defined by the user as settings for a Django app). And I need to check the config to make sure it fits the rules. The rule is very simple. The 'range' within each option must be unique. sample settings =============== ``` breakpoints = { 'small': { 'verbose_name': _('Sma...
2014/09/24
[ "https://Stackoverflow.com/questions/26027271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1682844/" ]
Its easy to scan for overlapping ranges if you sort the dataset first. 'None' appears to be used for different things in different places (as min its zero) as max its "greater than anything" - but that's harder to compare. If you have a real maximum, it makes the sorting a bit easier. (edit: scan for max because there...
You can get from that a dict with the ranges as pairs: ``` ranges = { 'small': (None, 640), 'medium': (641, 1024), ...} ``` and then check, say, that `len(set(ranges.values())) == len(ranges)` EDIT: this works if the requirement is for ranges to be different. See @tdelaney's answer for disjoint ranges.
8,510,972
I have seen a lot of posts on this topic, however I have not found regarding this warning: ``` CMake Warning: Manually-specified variables were not used by the project: BUILD_PYTHON_SUPPORT ``` when I compile with cmake. When building OpenCV with this warning, it turns out that it doesn't include python suppo...
2011/12/14
[ "https://Stackoverflow.com/questions/8510972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/256664/" ]
It looks like you're using an old install guide. Use `BUILD_NEW_PYTHON_SUPPORT` instead. So, execute CMake like this: ``` cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON .. ``` Also, if you use the CMake GUI, it is easier to see all of the opt...
**Simple instructions to install opencv with python bindings in Linux - Ubuntu/Fedora** 1. Install gcc, g++/gcc-c++, cmake (apt-get or yum, in case of yum use gcc-c++). **#apt-get install gcc, g++, cmake** 2. Downlaod latest opencv from openCV's website (<http://opencv.org/downloads.html>). 3. Untar it **#tar - xvf op...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
In Windows there is no real notion of "executable", like the specific permission that exists in \*NIX systems. You have two options. The first one, like saurabh had suggested before me, is to rely on the system to associate between the file extension and the command to be performed. This approach (of using Process.St...
if you are using .net than Process.Start do lot of things for you. if you pass a exe , it will run the exe. If you pass a word document , it will open the word document and may more
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
The only way to do this is to use P/Invoke calls in to the Win32 API. You need to use the SHGetFileInfo method and then unpack the return value: ``` [Flags] internal enum SHGFI : uint { ADDOVERLAYS = 0x20, ATTR_SPECIFIED = 0x20000, ATTRIBUTES = 0x800, DISPLAYNAME = 0x200, EXETYPE = 0x2000, ICON...
if you are using .net than Process.Start do lot of things for you. if you pass a exe , it will run the exe. If you pass a word document , it will open the word document and may more
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
The only way to do this is to use P/Invoke calls in to the Win32 API. You need to use the SHGetFileInfo method and then unpack the return value: ``` [Flags] internal enum SHGFI : uint { ADDOVERLAYS = 0x20, ATTR_SPECIFIED = 0x20000, ATTRIBUTES = 0x800, DISPLAYNAME = 0x200, EXETYPE = 0x2000, ICON...
In Windows there is no real notion of "executable", like the specific permission that exists in \*NIX systems. You have two options. The first one, like saurabh had suggested before me, is to rely on the system to associate between the file extension and the command to be performed. This approach (of using Process.St...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
In Windows there is no real notion of "executable", like the specific permission that exists in \*NIX systems. You have two options. The first one, like saurabh had suggested before me, is to rely on the system to associate between the file extension and the command to be performed. This approach (of using Process.St...
You should be able to pretty much start with step 5. Ie check the file extension first. Windows lives for file extensions. There's not much you can do without them. If you recognise the extension as an executable, then you can pass it to Process.Start or open the file and find out which executable you should be passin...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
In Windows there is no real notion of "executable", like the specific permission that exists in \*NIX systems. You have two options. The first one, like saurabh had suggested before me, is to rely on the system to associate between the file extension and the command to be performed. This approach (of using Process.St...
Since you mention Linux, you might consider using the 'file' command. I believe gnuwin32 has a port of this command for windows. Of course, that'd mean parsing the output returned by 'file' (the file MIME type such as "application/x-executable"). So depending on the number of executables you want to be able to recognis...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
In Windows there is no real notion of "executable", like the specific permission that exists in \*NIX systems. You have two options. The first one, like saurabh had suggested before me, is to rely on the system to associate between the file extension and the command to be performed. This approach (of using Process.St...
Using some information from Scott's answer, I wrote my own method which returns an Enum value specifying the type of the file. What I noticed with his solution is that it will return 'Unknown' even if the file does not exist. Additionally, I simplified a couple of the `if` conditions and added an additional condition f...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
The only way to do this is to use P/Invoke calls in to the Win32 API. You need to use the SHGetFileInfo method and then unpack the return value: ``` [Flags] internal enum SHGFI : uint { ADDOVERLAYS = 0x20, ATTR_SPECIFIED = 0x20000, ATTRIBUTES = 0x800, DISPLAYNAME = 0x200, EXETYPE = 0x2000, ICON...
You should be able to pretty much start with step 5. Ie check the file extension first. Windows lives for file extensions. There's not much you can do without them. If you recognise the extension as an executable, then you can pass it to Process.Start or open the file and find out which executable you should be passin...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
The only way to do this is to use P/Invoke calls in to the Win32 API. You need to use the SHGetFileInfo method and then unpack the return value: ``` [Flags] internal enum SHGFI : uint { ADDOVERLAYS = 0x20, ATTR_SPECIFIED = 0x20000, ATTRIBUTES = 0x800, DISPLAYNAME = 0x200, EXETYPE = 0x2000, ICON...
Since you mention Linux, you might consider using the 'file' command. I believe gnuwin32 has a port of this command for windows. Of course, that'd mean parsing the output returned by 'file' (the file MIME type such as "application/x-executable"). So depending on the number of executables you want to be able to recognis...
3,693,891
I'm writing a program that (part of what is does is) executes other programs. I want to to be able to run as many types of programs (written in different languages) as possible using `Process.Start` . So, I'm thinking I should: 1. Open the file 2. Read in the first line 3. Check if it starts with `#!` 4. If so, use wh...
2010/09/12
[ "https://Stackoverflow.com/questions/3693891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/65387/" ]
The only way to do this is to use P/Invoke calls in to the Win32 API. You need to use the SHGetFileInfo method and then unpack the return value: ``` [Flags] internal enum SHGFI : uint { ADDOVERLAYS = 0x20, ATTR_SPECIFIED = 0x20000, ATTRIBUTES = 0x800, DISPLAYNAME = 0x200, EXETYPE = 0x2000, ICON...
Using some information from Scott's answer, I wrote my own method which returns an Enum value specifying the type of the file. What I noticed with his solution is that it will return 'Unknown' even if the file does not exist. Additionally, I simplified a couple of the `if` conditions and added an additional condition f...
16,082,243
``` <Control-Shift-Key-0> <Control-Key-plus> ``` works but ``` <Control-Key-/> ``` doesn't. I am unable to bind `ctrl` + `/` in python. Is there any documentation of all the possible keys?
2013/04/18
[ "https://Stackoverflow.com/questions/16082243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2219529/" ]
Use `<Control-slash>`: ``` def quit(event): print "you pressed control-forwardslash" root.quit() root = tk.Tk() root.bind('<Control-slash>', quit) # forward-slash # root.bind('<Control-backslash>', quit) # backslash root.mainloop() ``` --- I don't have a link to a complete list of these event names. ...
Here is a list of all the tk keysysm codes: <https://www.tcl.tk/man/tcl8.6/TkCmd/keysyms.htm> The two I was looking for was `<Win_L>` and `<Win_R>`.
68,005,264
I'm executing an extract query to google storage as follows: ``` job_config = bigquery.ExtractJobConfig() job_config.compression = bigquery.Compression.GZIP job_config.destination_format = (bigquery.DestinationFormat.CSV) job_config.print_header = False job_config.field_delimiter = "|" extract_job = client.extract_ta...
2021/06/16
[ "https://Stackoverflow.com/questions/68005264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3447863/" ]
First of all, Start Events must not have an incoming Edge. It is not allowed by the BPMN standard. So you should replace your Start Events 2 and 3 within the process with intermediate Events. The decission logic to skip or execute the Intermediate Event now representing the event of what was before Start Event 3 could...
Based on Simulat's answer I found a alternative solution which I think is the better fit. The red path should not be possible because of the logic gate with the red circle (the top path is only viable if `Start Event 3` has not occurred). The problem I have with Simulat's answer are the intermediate events and the eve...
54,272,604
I have a recursive solution that works, but it turns out a lot of subproblems are being recalculated. I need help with MEMOIZATION. So here's the problem statement: > > You are a professional robber planning to rob houses along a street. > Each house has a certain amount of money stashed, the only constraint > sto...
2019/01/20
[ "https://Stackoverflow.com/questions/54272604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7938658/" ]
The `helper` can be called with different `value` parameter for same `index`. So the `value` must be removed (subtracted from the stored `max_dict`). One way to do this is to add `value` just before returning, not earlier: ``` money = [2, 1, 1, 2] max_dict = {} def helper(value, index): if index in max_dict: ...
Your approach for memoization won't work because when you reach some index `i`, if you've already computed some result for `i`, your algorithm fails to consider the fact that there might be a *better* result available by robbing a more optimal set of houses in the left portion of the array. The solution to this dilemm...
54,272,604
I have a recursive solution that works, but it turns out a lot of subproblems are being recalculated. I need help with MEMOIZATION. So here's the problem statement: > > You are a professional robber planning to rob houses along a street. > Each house has a certain amount of money stashed, the only constraint > sto...
2019/01/20
[ "https://Stackoverflow.com/questions/54272604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7938658/" ]
The `helper` can be called with different `value` parameter for same `index`. So the `value` must be removed (subtracted from the stored `max_dict`). One way to do this is to add `value` just before returning, not earlier: ``` money = [2, 1, 1, 2] max_dict = {} def helper(value, index): if index in max_dict: ...
I solved this dynamic programming problem using below method. And it is happenning in O(n) time. Do try this. ``` class Solution: # @param {integer[]} nums # @return {integer} def rob(self, nums): n = len(nums) if n==0: return 0; if n == 1...
54,272,604
I have a recursive solution that works, but it turns out a lot of subproblems are being recalculated. I need help with MEMOIZATION. So here's the problem statement: > > You are a professional robber planning to rob houses along a street. > Each house has a certain amount of money stashed, the only constraint > sto...
2019/01/20
[ "https://Stackoverflow.com/questions/54272604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7938658/" ]
Your approach for memoization won't work because when you reach some index `i`, if you've already computed some result for `i`, your algorithm fails to consider the fact that there might be a *better* result available by robbing a more optimal set of houses in the left portion of the array. The solution to this dilemm...
I solved this dynamic programming problem using below method. And it is happenning in O(n) time. Do try this. ``` class Solution: # @param {integer[]} nums # @return {integer} def rob(self, nums): n = len(nums) if n==0: return 0; if n == 1...
150,532
Similar to [this](https://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python) question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python. I first read all ten bytes into a string. I then want to parse out the individual ...
2008/09/29
[ "https://Stackoverflow.com/questions/150532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
If you have a string, with 2 bytes that you wish to interpret as a 16 bit integer, you can do so by: ``` >>> s = '\0\x02' >>> struct.unpack('>H', s) (2,) ``` Note that the > is for big-endian (the largest part of the integer comes first). This is the format id3 tags use. For other sizes of integer, you use differen...
I was going to recommend the `struct` package but then you said you had tried it. Try this: ``` self.major_version = struct.unpack('H', self.whole_string[3:5]) ``` The `pack()` function convers Python data types to bits, and the `unpack()` function converts bits to Python data types.
150,532
Similar to [this](https://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python) question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python. I first read all ten bytes into a string. I then want to parse out the individual ...
2008/09/29
[ "https://Stackoverflow.com/questions/150532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
If you have a string, with 2 bytes that you wish to interpret as a 16 bit integer, you can do so by: ``` >>> s = '\0\x02' >>> struct.unpack('>H', s) (2,) ``` Note that the > is for big-endian (the largest part of the integer comes first). This is the format id3 tags use. For other sizes of integer, you use differen...
Why write your own? (Assuming you haven't checked out these other options.) There's a couple options out there for reading in ID3 tag info from MP3s in Python. Check out my [answer](https://stackoverflow.com/questions/8948/accessing-mp3-meta-data-with-python#102285) over at [this](https://stackoverflow.com/questions/89...
150,532
Similar to [this](https://stackoverflow.com/questions/5415/convert-bytes-to-floating-point-numbers-in-python) question, I am trying to read in an ID3v2 tag header and am having trouble figuring out how to get individual bytes in python. I first read all ten bytes into a string. I then want to parse out the individual ...
2008/09/29
[ "https://Stackoverflow.com/questions/150532", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
If you have a string, with 2 bytes that you wish to interpret as a 16 bit integer, you can do so by: ``` >>> s = '\0\x02' >>> struct.unpack('>H', s) (2,) ``` Note that the > is for big-endian (the largest part of the integer comes first). This is the format id3 tags use. For other sizes of integer, you use differen...
> > I am trying to read in an ID3v2 tag header > > > FWIW, there's [already a module](http://id3-py.sourceforge.net/) for this.
64,647,954
I want to webscrape german real estate website immobilienscout24.de. I would like to download the HTML of a given URL and then work with the HTML offline. It is not intended for commercial use or publication and I do not intend on spamming the site, it is merely for coding practice. I would like to write a python tool ...
2020/11/02
[ "https://Stackoverflow.com/questions/64647954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14361382/" ]
Try to set `Accept-Language` HTTP header (this worked for me to get correct response from server): ``` import requests from bs4 import BeautifulSoup url = "https://www.immobilienscout24.de/Suche/de/wohnung-mieten?sorting=2#" headers = { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:82.0) Gecko/201001...
Maybe have a go with [requests](https://requests.readthedocs.io/en/master/), the code below seems to work fine for me: ``` import requests from bs4 import BeautifulSoup r = requests.get('https://www.immobilienscout24.de/') soup = BeautifulSoup(r.text, 'html.parser') print(soup.prettify) ``` Another approach is to ...