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 |
|---|---|---|---|---|---|
21,946,883 | I'm writing a function to shift text by 13 spaces. The converted chars need to preserve case, and if the characters aren't letters then they should pass through unshifted. I wrote the following function:
```
def rot13(str):
result = ""
for c in str:
if 65 <= ord(c) <= 96:
result += chr((ord... | 2014/02/21 | [
"https://Stackoverflow.com/questions/21946883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1036605/"
] | You are missing the "else" statement, so if the first if "fires" (`c` is an uppercase letter) then the "else" from the second if also "fires" (and concatenates the uppercase letter, as `ord(c)` is not between `97` and `122`)
```
def rot13(str):
result = ""
for c in str:
if 65 <= ord(c) <= 96:
... | This is an (rather contrived) one-liner implementation for the caesar cipher in python:
```
cipher = lambda w, s: ''.join(chr(a + (i - a + s) % 26) if (a := 65) <= (i := ord(c)) <= 90 or (a := 97) <= i <= 122 else c for c in w)
word = 'Hello, beautiful World!'
print(cipher(word, 13)) # positive shift
# Uryyb, ornhgvs... |
15,054,598 | So I created my project with a virtual environment and installed pip + distribute. Everything is fine so far, But when I click on the install button to install new packages it displays a beautiful : "Nothing to show".
Here is an image of it :

I hav... | 2013/02/24 | [
"https://Stackoverflow.com/questions/15054598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/970581/"
] | The problem is caused by recent server-side changes in PyPI, and will be addressed in the PyCharm 2.7.1 update. Please see <http://youtrack.jetbrains.com/issue/PY-8962> to track the status of the issue. | If you are behind a proxy (e.g. in a corporate environment), then you may need to configure your proxy settings for PyCharm to show the packages.
These are in Pycharm under:
>
> File -> Settings -> Appearance & Behaviour -> System Settings -> HTTP Proxy
>
>
>
Enter your proxy settings there, e.g. a host name and... |
15,054,598 | So I created my project with a virtual environment and installed pip + distribute. Everything is fine so far, But when I click on the install button to install new packages it displays a beautiful : "Nothing to show".
Here is an image of it :

I hav... | 2013/02/24 | [
"https://Stackoverflow.com/questions/15054598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/970581/"
] | The problem is caused by recent server-side changes in PyPI, and will be addressed in the PyCharm 2.7.1 update. Please see <http://youtrack.jetbrains.com/issue/PY-8962> to track the status of the issue. | I faced such problem man y times and every time I found that the problem corresponds to my internet connection. check your internet connection with tools like wget or curl in linux and browsers in windows. |
28,398,240 | I want to run my python function in console like this:
```
my_function_name
```
at any directory, I tried to follow arajek's answer in this question:
[run a python script in terminal without the python command](https://stackoverflow.com/questions/15587877/run-a-python-script-in-terminal-without-the-python-command)
... | 2015/02/08 | [
"https://Stackoverflow.com/questions/28398240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1154698/"
] | Change the name of the script to no longer have the `.py` extension. | Add this shebang to the top of your file: `#!/usr/bin/env python` and remove the file extension. |
1,131,582 | I am using Boost with Visual Studio 2008 and I have put the path to boost directory in configuration for the project in C++/General/"Additional Include Directories" and in Linker/General/"Additional Library Directories". (as it says here: <http://www.boost.org/doc/libs/1_36_0/more/getting_started/windows.html#build-fro... | 2009/07/15 | [
"https://Stackoverflow.com/questions/1131582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Where is the file located, and which include path did you specify? (And how is the file `#include`'d)
There's a mismatch between some of these But it's impossible to say what's wrong when you haven't shown what you actually did.
**Edit**:
Given the paths you mentioned in comments, the problem is that they don't add ... | How do you include it? You should write something like this:
```
#include <boost/python.hpp>
```
Note that `Additional Include Directories` settings are differs in `Release` and `Debug` configurations. You should make them the same.
If boost placed to `C:\Program Files\boost\boost_1_36_0\` you should set path to `C... |
61,713,057 | I'm working on [google colaboratory](https://colab.research.google.com/) and i have to do some elaboration to some files based on their extensions, like:
```
!find ./ -type f -name "*.djvu" -exec file '{}' ';'
```
and i expect an output:
```
./file.djvu: DjVu multiple page document
```
but when i try to mix bash ... | 2020/05/10 | [
"https://Stackoverflow.com/questions/61713057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8069500/"
] | I found an ugly workaround passing trought a file, so first i write the array to a file in python:
```
with open('/content/file_types.txt', 'w') as f:
for ft in file_types:
f.write(ft + '\n')
```
and than i read and use it from bash in another cell:
```
%%bash
filename=/content/protected_file_types.txt
w... | This works for me
```
declare -a my_array=("pdf" "py")
for i in ${my_array[*]}; do find ./ -type f -name "*.$i" -exec file '{}' ';'; done;
``` |
65,362,747 | I'd like to slice a tensor (multi-dimensional array) using Rust's [ndarray](https://docs.rs/ndarray) library, but the catch is that the tensor is dynamically shaped and the slice is stored in a user provided variable.
If I knew the dimensionality up front, I expect I could simply do the following, where `idx` is the u... | 2020/12/18 | [
"https://Stackoverflow.com/questions/65362747",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7681811/"
] | You want to get the **"Bin On Hand"** fields:
You can get Location, Bin Number and On Hand from this join in your Saved Search. When done your results fields should be:
* Bin On Hand:Location
* Bin On Hand:Bin Number
* Bin On Hand:On Hand
Todd Stafford | From Admin role: List > Search > Saved Searches > New > Inventory Balance
In the results menu:
1. Item
2. Inventory Location
3. Bin
4. Quantity On Hand. |
67,157,938 | Trying to search no of times word appears in a file using python file handling. For example was trying to search 'believer' in the lyrics of believer song that how many times believer comes. It appears 18 times but my program is giving 12. What are the conditions I am missing.
```
def no_words_function():
f=open("be... | 2021/04/19 | [
"https://Stackoverflow.com/questions/67157938",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7762964/"
] | I would suggest you adding object properties conditionally with ES6 syntax like this.
```js
const normalizeData = ({id, name = ""}) => {
const condition = !!name; // Equivalent to: name !== undefined && name !== "";
return {id, ...(condition && { name })};
}
console.log(normalizeData({id: 123, name: ""}));
consol... | You can create the object with the id first and then add a name afterwards:
```
const obj = {id: 123};
if(name) obj.name = name;
axios.post('saveUser', obj);
``` |
61,431,924 | here is my problem : I wrote a python bot that makes plenty of stuff, including printing colorful text for better understanding. I'm using the colorama package because it prints color even on windows command prompt.
Here is how I use colorama, which work both on unix and windows using python 3.8 :
```
from colorama im... | 2020/04/25 | [
"https://Stackoverflow.com/questions/61431924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13407332/"
] | Try:
```
pyinstaller.exe --onefile --hidden-import colorama script.py
```
This (--hidden-import colorama) should ensure that pyinstaller builds the application including colorama. | you should run `pip/pipenv install colorama` at first. |
14,260,714 | PyDev is reporting import errors which don't exist. The initial symptom was a fake "unresolved import" error, which was fixed by some combination of:
* Cleaning the Project
* Re-indexing the project (remove interpreter, add again)
* Restarting Eclipse
* Burning incense to the Python deities
Now the error is "unverifi... | 2013/01/10 | [
"https://Stackoverflow.com/questions/14260714",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/963250/"
] | Try `ctrl+1` at the line where the error and add a comment saying that you are expecting that import. This should resolve the PyDev error, as it does static code analysis and not runtime analysis. | I added # @UndefinedVariable to the end of the line throwing the error.
This isn't much of a permanent fix, but at least it got rid of the red from my screen for the time being. If there is a better long term fix, I would be happy to hear it. |
14,260,714 | PyDev is reporting import errors which don't exist. The initial symptom was a fake "unresolved import" error, which was fixed by some combination of:
* Cleaning the Project
* Re-indexing the project (remove interpreter, add again)
* Restarting Eclipse
* Burning incense to the Python deities
Now the error is "unverifi... | 2013/01/10 | [
"https://Stackoverflow.com/questions/14260714",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/963250/"
] | ***TL;DR version: read the fifth grey box.***
Your problem (and mine) appears to be due to multiple levels of imports that should be, but is not, handled correctly. Somewhere along the line, linkage is lost.
Assume for a moment that you have a file
```
foo/bar.py
```
and that within that file, you have a symbol na... | I added # @UndefinedVariable to the end of the line throwing the error.
This isn't much of a permanent fix, but at least it got rid of the red from my screen for the time being. If there is a better long term fix, I would be happy to hear it. |
38,542,675 | I'd appreciate some help with the diagnosis.
The error messages either point to the possibility that this package cannot be installed on a 64 bit machine or the wrong compiler is being selected.
**Edit:**
The [requirements](http://vmprof.readthedocs.io/en/latest/vmprof.html#requirements) for `vmprof` state that it w... | 2016/07/23 | [
"https://Stackoverflow.com/questions/38542675",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2409868/"
] | This is an issue on [vmprof's github repository](http://github.com/vmprof/vmprof-python/issues/92) which is unfixed at 8/23/2016. | Finally, `vmprof` from v0.4 officially supports 64bit Windows
See the closed [GitHub Issue](https://github.com/vmprof/vmprof-python/issues/85) |
27,032,218 | I am using emacs-for-python provided by gabrielelanaro at this [link](https://github.com/gabrielelanaro/emacs-for-python).
Indentation doesn't seem to be working for me at all.
It doesn't happen automatically when I create a class, function or any other block of code that requires automatic indentation(if, for etc.)... | 2014/11/20 | [
"https://Stackoverflow.com/questions/27032218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2696086/"
] | Check the value of `python-indent-offset`. If it is 0, change it `M-x set-variable RET python-indent-offset RET 4 RET`.
Emacs tries to guess the offset used in a Python file when opening it. It might get confused and set that variable to 0 for some badly-formatted Python file. If this is indeed the problem, please do ... | Can you comment the lines related to auto-complete in your init.el?
```
; (add-to-list 'load-path "~/.emacs.d/auto-complete-1.3.1")
; (require 'auto-complete)
; (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
; (require 'auto-complete-config)
; (ac-config-default)
; (global-auto-complete-mode t)
``` |
27,032,218 | I am using emacs-for-python provided by gabrielelanaro at this [link](https://github.com/gabrielelanaro/emacs-for-python).
Indentation doesn't seem to be working for me at all.
It doesn't happen automatically when I create a class, function or any other block of code that requires automatic indentation(if, for etc.)... | 2014/11/20 | [
"https://Stackoverflow.com/questions/27032218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2696086/"
] | It is related to this bug
<http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15975>
The quickest workaround which I found was too add Jorgens Answer into .emacs file, add the following at the end of your .emacs file
```
(add-hook 'python-mode-hook
(lambda () (setq python-indent-offset 4)))
``` | Can you comment the lines related to auto-complete in your init.el?
```
; (add-to-list 'load-path "~/.emacs.d/auto-complete-1.3.1")
; (require 'auto-complete)
; (add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
; (require 'auto-complete-config)
; (ac-config-default)
; (global-auto-complete-mode t)
``` |
27,032,218 | I am using emacs-for-python provided by gabrielelanaro at this [link](https://github.com/gabrielelanaro/emacs-for-python).
Indentation doesn't seem to be working for me at all.
It doesn't happen automatically when I create a class, function or any other block of code that requires automatic indentation(if, for etc.)... | 2014/11/20 | [
"https://Stackoverflow.com/questions/27032218",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2696086/"
] | Check the value of `python-indent-offset`. If it is 0, change it `M-x set-variable RET python-indent-offset RET 4 RET`.
Emacs tries to guess the offset used in a Python file when opening it. It might get confused and set that variable to 0 for some badly-formatted Python file. If this is indeed the problem, please do ... | It is related to this bug
<http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15975>
The quickest workaround which I found was too add Jorgens Answer into .emacs file, add the following at the end of your .emacs file
```
(add-hook 'python-mode-hook
(lambda () (setq python-indent-offset 4)))
``` |
69,895,751 | I try start my code, but process finishes on step with method cv2.namedWindow (without
any errors).
Do you have any suggestions, why it could be so?
```
import cv2
image_cv2 = cv2.imread('/home/spartak/PycharmProjects/python_base/lesson_016/python_snippets/external_data/girl.jpg')
def viewImage(image, name_of_window... | 2021/11/09 | [
"https://Stackoverflow.com/questions/69895751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14779400/"
] | I find out the problem.
I started this code in virtual environment.
Apparently, in virtual environment on UBUNTU/FEDORA, opencv have restrictions.
 | The code completes all 4 steps for me
I think there is a problem with the image path which you took
[](https://i.stack.imgur.com/zrqCV.png)
The function cv2.namedWindow creates a window that can be used as a placeholder for images and trackbars. Cre... |
69,895,751 | I try start my code, but process finishes on step with method cv2.namedWindow (without
any errors).
Do you have any suggestions, why it could be so?
```
import cv2
image_cv2 = cv2.imread('/home/spartak/PycharmProjects/python_base/lesson_016/python_snippets/external_data/girl.jpg')
def viewImage(image, name_of_window... | 2021/11/09 | [
"https://Stackoverflow.com/questions/69895751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14779400/"
] | I find out the problem.
I started this code in virtual environment.
Apparently, in virtual environment on UBUNTU/FEDORA, opencv have restrictions.
 | I do think the function
[cv2.destroyAllWindows](https://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html?highlight=destroyallwindows#destroyallwindows)
This function is deallocating some needed gui elements, I would guess.
So calling this multiple times will produce some trouble.
```
import cv2
image_cv2 =... |
41,487,605 | I am using DBSCAN from sklearn in python to cluster some data points. I am using a precomputed distance matrix to cluster the points.
```
import sklearn.cluster as cl
C = cl.DBSCAN(eps = 2, metric = 'precomputed', min_samples =2)
db = C.fit(Dist_Matrix)
```
Dist\_Matrix is precomputed distance matrix I am using. Ea... | 2017/01/05 | [
"https://Stackoverflow.com/questions/41487605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7342743/"
] | Clustering will *usually* not assign the same labels.
Because the label itself is *meaningless*. The only valueable information is what objects go *together*.
As for sklearn, if you use an old version, it will (unnecessarily) randomly shuffle the data. So it's not surprising you get a random permutation of the labels... | You can use a custom function to normalize the cluster labels.
```
def normalize_cluster_labels(labels):
min_value = min(labels)
if (min_value < 0):
labels = labels + abs(min(labels)) # normalize indexes
#idx = clustering.labels_ - min(clustering.labels_ )
return labels
``` |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | Had a similar problem i resolved it by removing the previous migration files.No technical explanation | I solved it by below:
1. First delete last migration that face problem
2. Then add like `venue_city = models.CharField(blank=True, null=True)`
3. Finally use `makemigrations` and `migrate` command |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | Looks like you added `null=True` after created migration file. Because `venue_city` is not a nullable field in your migration file
Follow these steps.
```
1) Drop venue_city & venue_country from your local table
3) Delete all the migration files you created for these `CharField to a ForeignKey` change
4) execute `pyt... | I solved it by below:
1. First delete last migration that face problem
2. Then add like `venue_city = models.CharField(blank=True, null=True)`
3. Finally use `makemigrations` and `migrate` command |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | Had a similar problem i resolved it by removing the previous migration files.No technical explanation | follow the below steps:-
* add *null=True, blank=True* in Venue model class
eg: venue\_city = models.ForeignKey(City, null=True, blank=True)
* delete *venues.0016\_auto\_20160514\_2141* migration file from migrations folder in your app
* then run *python manage.py makemigrations*
* then run *python manage.py migrate*
... |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | I solved it by just adding `null = True` to both the (automatically generated) migration file that was causing the issue and in the Model. Then `migrate` again and your failed migration will now succeed. As you changed it also in your model, `makemigration` will detect no changes after that. | follow the below steps:-
* add *null=True, blank=True* in Venue model class
eg: venue\_city = models.ForeignKey(City, null=True, blank=True)
* delete *venues.0016\_auto\_20160514\_2141* migration file from migrations folder in your app
* then run *python manage.py makemigrations*
* then run *python manage.py migrate*
... |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | follow the below steps:-
* add *null=True, blank=True* in Venue model class
eg: venue\_city = models.ForeignKey(City, null=True, blank=True)
* delete *venues.0016\_auto\_20160514\_2141* migration file from migrations folder in your app
* then run *python manage.py makemigrations*
* then run *python manage.py migrate*
... | As the error says, you have a null value in the "venue\_city" column.
It seems at the time of defining your model you had not included "null=True".
So it returns null because there is nothing in your 'venue\_city" variable. Consider deleting the last migration file and perform another migration using
`python manage.p... |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | I solved it by just adding `null = True` to both the (automatically generated) migration file that was causing the issue and in the Model. Then `migrate` again and your failed migration will now succeed. As you changed it also in your model, `makemigration` will detect no changes after that. | I solved it by below:
1. First delete last migration that face problem
2. Then add like `venue_city = models.CharField(blank=True, null=True)`
3. Finally use `makemigrations` and `migrate` command |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | Looks like you added `null=True` after created migration file. Because `venue_city` is not a nullable field in your migration file
Follow these steps.
```
1) Drop venue_city & venue_country from your local table
3) Delete all the migration files you created for these `CharField to a ForeignKey` change
4) execute `pyt... | As the error says, you have a null value in the "venue\_city" column.
It seems at the time of defining your model you had not included "null=True".
So it returns null because there is nothing in your 'venue\_city" variable. Consider deleting the last migration file and perform another migration using
`python manage.p... |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | Looks like you added `null=True` after created migration file. Because `venue_city` is not a nullable field in your migration file
Follow these steps.
```
1) Drop venue_city & venue_country from your local table
3) Delete all the migration files you created for these `CharField to a ForeignKey` change
4) execute `pyt... | Had a similar problem i resolved it by removing the previous migration files.No technical explanation |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | follow the below steps:-
* add *null=True, blank=True* in Venue model class
eg: venue\_city = models.ForeignKey(City, null=True, blank=True)
* delete *venues.0016\_auto\_20160514\_2141* migration file from migrations folder in your app
* then run *python manage.py makemigrations*
* then run *python manage.py migrate*
... | I solved it by below:
1. First delete last migration that face problem
2. Then add like `venue_city = models.CharField(blank=True, null=True)`
3. Finally use `makemigrations` and `migrate` command |
37,241,819 | I have read a lot of other posts here on stackoverflow and google but I could not find a solution.
It all started when I changed the model from a CharField to a ForeignKey.
The error I recieve is:
```
Operations to perform:
Synchronize unmigrated apps: gis, staticfiles, crispy_forms, geoposition, messages
Apply ... | 2016/05/15 | [
"https://Stackoverflow.com/questions/37241819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1067213/"
] | I solved it by just adding `null = True` to both the (automatically generated) migration file that was causing the issue and in the Model. Then `migrate` again and your failed migration will now succeed. As you changed it also in your model, `makemigration` will detect no changes after that. | As the error says, you have a null value in the "venue\_city" column.
It seems at the time of defining your model you had not included "null=True".
So it returns null because there is nothing in your 'venue\_city" variable. Consider deleting the last migration file and perform another migration using
`python manage.p... |
21,758,560 | I've been struggling with an algorithm tied to comparisons with 3d triangle vectors. Unfortunately its very slow in places and I've gone back and forth on different methods to try and improve it. One thing I'm struggling with is speeding up a distance calculation.
I have two groups of triangles which have been broken... | 2014/02/13 | [
"https://Stackoverflow.com/questions/21758560",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1942439/"
] | The problem is that brute force testing of all triangles versus eachother takes quadratic time. It is better to use a datastructure which is specialized to perform such computations. Luckily, scipy contains one.
Take a look at scipy.spatial.cKDTree. The help should be self-explanatory. | I think diffverts is taking up enough memory to cause cache misses. Unfortunately while this solution is very elegant, you're probably better off computing the whole distance in one go, to avoid having to save an n\*m\*3 array of intermediate values. As ugly as it is, I would just do nested for loops. |
15,415,093 | For a system I am developing I need to programmatically go to a specific page. Fill out one field in the form (I know the id and name of the input element), submit it and store the results.
I have seen a few different Perl, python and java classes that do this. However I would like to do this using PHP and havent foun... | 2013/03/14 | [
"https://Stackoverflow.com/questions/15415093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1364791/"
] | Take a look at David Walsh's simple explanation.
<http://davidwalsh.name/curl-post>
You can easily store the response (in this example, $result) in your database or logfile. | Usually PHP crawlers/scrapers use CURL - <http://php.net/manual/en/book.curl.php>.
It allows you to make a query from the server where PHP runs and get response from the website that you need to crawl. It returns response data in plain format and parsing it is up to you. You can manually check what does the form submit... |
15,415,093 | For a system I am developing I need to programmatically go to a specific page. Fill out one field in the form (I know the id and name of the input element), submit it and store the results.
I have seen a few different Perl, python and java classes that do this. However I would like to do this using PHP and havent foun... | 2013/03/14 | [
"https://Stackoverflow.com/questions/15415093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1364791/"
] | Take a look at David Walsh's simple explanation.
<http://davidwalsh.name/curl-post>
You can easily store the response (in this example, $result) in your database or logfile. | You also may try phpcrawl (<http://phpcrawl.cuab.de>), seems to fit all your needs.
(See "addPostData()"-method) |
15,415,093 | For a system I am developing I need to programmatically go to a specific page. Fill out one field in the form (I know the id and name of the input element), submit it and store the results.
I have seen a few different Perl, python and java classes that do this. However I would like to do this using PHP and havent foun... | 2013/03/14 | [
"https://Stackoverflow.com/questions/15415093",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1364791/"
] | Usually PHP crawlers/scrapers use CURL - <http://php.net/manual/en/book.curl.php>.
It allows you to make a query from the server where PHP runs and get response from the website that you need to crawl. It returns response data in plain format and parsing it is up to you. You can manually check what does the form submit... | You also may try phpcrawl (<http://phpcrawl.cuab.de>), seems to fit all your needs.
(See "addPostData()"-method) |
50,991,402 | I'm trying to create a new tables in a new app added to my project .. `makemigrations` worked great but `migrate` is not working .. here is my models
**blog/models.py**
```
from django.db import models
# Create your models here.
from fostania_web_app.models import UserModel
class Tag(models.Model):
tag_name = m... | 2018/06/22 | [
"https://Stackoverflow.com/questions/50991402",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9494140/"
] | Error message: `ValueError: invalid literal for int() with base 10: '??? ??? ?????'`
As per exception int() with base 10: `'??? ??? ?????'` doesn't qualify as int.
Check in `blog.0001_initial` migrations for `'??? ??? ?????'` and modify that value with a valid int.
You might have accidentally provided garbage default... | I had the same error.
My problem:
I had:
```
models.y
expiration_date = models.DateField(null=True, max_length=20)
```
And a validation in my:
```
forms.py
def clean_expiration_date(self):
data = self.cleaned_data['expiration_date']
if data < datetime.date.today():
return data
```
And it gave me the he... |
16,247,828 | Now our code have 3,000,000 id stored in set, the format is string, I try to convert it to int using list comprehension. But it cost 5 sec, how can I reduce the cost of converting string to int for these 3,000,000 id?
Here is my testing code:
```
import random
import time
a = set()
for i in xrange(3088767):
a.ad... | 2013/04/27 | [
"https://Stackoverflow.com/questions/16247828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/472880/"
] | ```
ld = map(int, a)
```
should be quite faster, and also your only option not considering other python implementations | Try using [Pypy](http://pypy.org) or [Cython](http://cython.org).
These tools can made your code fly! (Pypy, specially, in my PC Pypy speed up the code 4 times..) |
46,164,419 | Getting a 'Label out of bound' error while running the testing script. Error is thrown in the confusion\_matrix function when the annotation values are compared with the number of classes. In my case annotation value is an image(560x560) and number\_of\_classes = 2.
```
[check_ops.assert_less(labels, num_classes_int64... | 2017/09/11 | [
"https://Stackoverflow.com/questions/46164419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8485184/"
] | In the Annotation file, the labels were 0,1,2,255. The range of label was given 3. So when 255 was detected in the annotation file above error was thrown. After I removed all 255 values the code worked without any error. | under tensorflow 1.15.2, tensorflow/models/research/deeplab is basically quite ok.
error message like:
Invalid argument: assertion failed: [`labels` out of bound] [Condition x < y did not hold element-wise:] [x (mean\_iou/confusion\_matrix/control\_dependency:0) = ]
likely due not considering background as 1 class.... |
46,164,419 | Getting a 'Label out of bound' error while running the testing script. Error is thrown in the confusion\_matrix function when the annotation values are compared with the number of classes. In my case annotation value is an image(560x560) and number\_of\_classes = 2.
```
[check_ops.assert_less(labels, num_classes_int64... | 2017/09/11 | [
"https://Stackoverflow.com/questions/46164419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8485184/"
] | In the Annotation file, the labels were 0,1,2,255. The range of label was given 3. So when 255 was detected in the annotation file above error was thrown. After I removed all 255 values the code worked without any error. | Same error here.
My error was due to I was using the checkpoint of cityscapes. `Cityscapes` have more labels than my data, so when I change the label number from 2 to 19 (which is the label number of cityscapes), `eval.py` runs perfectly. However, there might be some conflicts between `cityscapes` labels and own data l... |
46,164,419 | Getting a 'Label out of bound' error while running the testing script. Error is thrown in the confusion\_matrix function when the annotation values are compared with the number of classes. In my case annotation value is an image(560x560) and number\_of\_classes = 2.
```
[check_ops.assert_less(labels, num_classes_int64... | 2017/09/11 | [
"https://Stackoverflow.com/questions/46164419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8485184/"
] | Same problem here.
The 'labels' array, `Y_true`, had values `0, 255`. I used:
```
Y_true = Y_true/255
```
to squash `Y_true` to `0, 1`.
That removed the error. | under tensorflow 1.15.2, tensorflow/models/research/deeplab is basically quite ok.
error message like:
Invalid argument: assertion failed: [`labels` out of bound] [Condition x < y did not hold element-wise:] [x (mean\_iou/confusion\_matrix/control\_dependency:0) = ]
likely due not considering background as 1 class.... |
46,164,419 | Getting a 'Label out of bound' error while running the testing script. Error is thrown in the confusion\_matrix function when the annotation values are compared with the number of classes. In my case annotation value is an image(560x560) and number\_of\_classes = 2.
```
[check_ops.assert_less(labels, num_classes_int64... | 2017/09/11 | [
"https://Stackoverflow.com/questions/46164419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8485184/"
] | Same problem here.
The 'labels' array, `Y_true`, had values `0, 255`. I used:
```
Y_true = Y_true/255
```
to squash `Y_true` to `0, 1`.
That removed the error. | Same error here.
My error was due to I was using the checkpoint of cityscapes. `Cityscapes` have more labels than my data, so when I change the label number from 2 to 19 (which is the label number of cityscapes), `eval.py` runs perfectly. However, there might be some conflicts between `cityscapes` labels and own data l... |
46,164,419 | Getting a 'Label out of bound' error while running the testing script. Error is thrown in the confusion\_matrix function when the annotation values are compared with the number of classes. In my case annotation value is an image(560x560) and number\_of\_classes = 2.
```
[check_ops.assert_less(labels, num_classes_int64... | 2017/09/11 | [
"https://Stackoverflow.com/questions/46164419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8485184/"
] | In case anyone has encountered this issue and not been able to resolve by rescaling or adjusting channels, I found that the MeanIOU metric also causes this issue. Getting rid of it and training with only loss as a metric or defining another one worked for me. | under tensorflow 1.15.2, tensorflow/models/research/deeplab is basically quite ok.
error message like:
Invalid argument: assertion failed: [`labels` out of bound] [Condition x < y did not hold element-wise:] [x (mean\_iou/confusion\_matrix/control\_dependency:0) = ]
likely due not considering background as 1 class.... |
46,164,419 | Getting a 'Label out of bound' error while running the testing script. Error is thrown in the confusion\_matrix function when the annotation values are compared with the number of classes. In my case annotation value is an image(560x560) and number\_of\_classes = 2.
```
[check_ops.assert_less(labels, num_classes_int64... | 2017/09/11 | [
"https://Stackoverflow.com/questions/46164419",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8485184/"
] | In case anyone has encountered this issue and not been able to resolve by rescaling or adjusting channels, I found that the MeanIOU metric also causes this issue. Getting rid of it and training with only loss as a metric or defining another one worked for me. | Same error here.
My error was due to I was using the checkpoint of cityscapes. `Cityscapes` have more labels than my data, so when I change the label number from 2 to 19 (which is the label number of cityscapes), `eval.py` runs perfectly. However, there might be some conflicts between `cityscapes` labels and own data l... |
45,318,255 | **Code:**
```
import numpy as np
z = np.array([[1,3,5],[2,4,6]])
print(z[0:, :2])
```
**Answer:**
```
[[1, 3] [2, 4]]
```
I am a python beginner, I was solving an interactive exercise when the above mentioned question appeared.
I am not able to understand, how z[0:, :2] works in this case? If possible, please ... | 2017/07/26 | [
"https://Stackoverflow.com/questions/45318255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4282170/"
] | You can read about Numpy slicing and indexing here:
<https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>
In this case, `0:` means "all the rows, starting from (and including) row 0 and going until the end" (you could also just use the equivalent `:`, which means "all the rows, starting from the beginning... | First you ask to get all rows (`0:` is the same as `:`):
```
[[1,3,5],
[2,4,6]]
```
Then you ask for columns 0 and 1 (`:2` is the same as `0:2` which means from 0 until 2 exclusive):
```
[[1,3],
[2,4]]
``` |
45,318,255 | **Code:**
```
import numpy as np
z = np.array([[1,3,5],[2,4,6]])
print(z[0:, :2])
```
**Answer:**
```
[[1, 3] [2, 4]]
```
I am a python beginner, I was solving an interactive exercise when the above mentioned question appeared.
I am not able to understand, how z[0:, :2] works in this case? If possible, please ... | 2017/07/26 | [
"https://Stackoverflow.com/questions/45318255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4282170/"
] | First you ask to get all rows (`0:` is the same as `:`):
```
[[1,3,5],
[2,4,6]]
```
Then you ask for columns 0 and 1 (`:2` is the same as `0:2` which means from 0 until 2 exclusive):
```
[[1,3],
[2,4]]
``` | This is a feature of numpy arrays, and, in this example, applies to 2D arrays.
If `z = np.array([l0, l1, l2, l3])` where l0, l1, l2, l3 are lists,
then `z[1:3,2:5] = [l1[2:5], l2[2:5]]`
So the first slice argument applies to the outer list, while the second argument applies to the inner lists. This generalizes to 3D... |
45,318,255 | **Code:**
```
import numpy as np
z = np.array([[1,3,5],[2,4,6]])
print(z[0:, :2])
```
**Answer:**
```
[[1, 3] [2, 4]]
```
I am a python beginner, I was solving an interactive exercise when the above mentioned question appeared.
I am not able to understand, how z[0:, :2] works in this case? If possible, please ... | 2017/07/26 | [
"https://Stackoverflow.com/questions/45318255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4282170/"
] | You can read about Numpy slicing and indexing here:
<https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>
In this case, `0:` means "all the rows, starting from (and including) row 0 and going until the end" (you could also just use the equivalent `:`, which means "all the rows, starting from the beginning... | `z[0:, :2]` selects all elements in all (ie., both) rows (`0:` selects the range of row indices starting with 0) and in the first two columns (`:2` selects the column indices 0 and 1.)
```
column 0 1 2
--------------
row 0 | 1 3 5
row 1 | 2 4 6
``` |
45,318,255 | **Code:**
```
import numpy as np
z = np.array([[1,3,5],[2,4,6]])
print(z[0:, :2])
```
**Answer:**
```
[[1, 3] [2, 4]]
```
I am a python beginner, I was solving an interactive exercise when the above mentioned question appeared.
I am not able to understand, how z[0:, :2] works in this case? If possible, please ... | 2017/07/26 | [
"https://Stackoverflow.com/questions/45318255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4282170/"
] | You can read about Numpy slicing and indexing here:
<https://docs.scipy.org/doc/numpy/reference/arrays.indexing.html>
In this case, `0:` means "all the rows, starting from (and including) row 0 and going until the end" (you could also just use the equivalent `:`, which means "all the rows, starting from the beginning... | This is a feature of numpy arrays, and, in this example, applies to 2D arrays.
If `z = np.array([l0, l1, l2, l3])` where l0, l1, l2, l3 are lists,
then `z[1:3,2:5] = [l1[2:5], l2[2:5]]`
So the first slice argument applies to the outer list, while the second argument applies to the inner lists. This generalizes to 3D... |
45,318,255 | **Code:**
```
import numpy as np
z = np.array([[1,3,5],[2,4,6]])
print(z[0:, :2])
```
**Answer:**
```
[[1, 3] [2, 4]]
```
I am a python beginner, I was solving an interactive exercise when the above mentioned question appeared.
I am not able to understand, how z[0:, :2] works in this case? If possible, please ... | 2017/07/26 | [
"https://Stackoverflow.com/questions/45318255",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4282170/"
] | `z[0:, :2]` selects all elements in all (ie., both) rows (`0:` selects the range of row indices starting with 0) and in the first two columns (`:2` selects the column indices 0 and 1.)
```
column 0 1 2
--------------
row 0 | 1 3 5
row 1 | 2 4 6
``` | This is a feature of numpy arrays, and, in this example, applies to 2D arrays.
If `z = np.array([l0, l1, l2, l3])` where l0, l1, l2, l3 are lists,
then `z[1:3,2:5] = [l1[2:5], l2[2:5]]`
So the first slice argument applies to the outer list, while the second argument applies to the inner lists. This generalizes to 3D... |
68,434,126 | In a Tkinter window of the Test.py file, I would like to display in a textobox what is printed in the Python console.
By clicking on button, you start a function in the Test.py file that calls the X.py and Y.py scripts (more precisely their functions). The results of the scripts are printed correctly in the Python con... | 2021/07/19 | [
"https://Stackoverflow.com/questions/68434126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16472472/"
] | For Python 3.4+, you can use `contextlib.redirect_stdout` (see [official document](https://docs.python.org/3/library/contextlib.html#contextlib.redirect_stdout)) to redirect `sys.stdout` to another file or file-like object temporarily.
```py
import tkinter as tk
from contextlib import redirect_stdout
from File.X impor... | Ok, so after a lot of trial and error I finally found a way to accomplish what You want (to be fair though, You were the one that was supposed to go through this phase AND show Your attempts which You failed to do, either how I don't mind much since I learned stuff too):
```py
from tkinter import Tk, Text
import subpr... |
48,908,156 | I am using **Django-Cookiecutter** which uses **Django-Allauth** to handle all the authentication and there is one App installed called **user** which handles everything related to users like sign-up, sign-out etc.
I am sharing the models.py file for users
```
@python_2_unicode_compatible
class User(AbstractUser):
... | 2018/02/21 | [
"https://Stackoverflow.com/questions/48908156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5881652/"
] | Unless you are offering a course to just one user, it does not make sense to have a one-to-many relationship between User and Course models. So, you need a many-to-many relationship. It is also wise to extend the user model by creating a UserProfile model and relate UserProfile to your course. You can look [here](https... | You can directly add foreign key as:
```
user = models.Foreignkey(User,related_name="zyz")
``` |
72,184,482 | I have a project trying to imagescrape from a website. I use a csv file with all the urls. Some urls i dont have the premission to open(or they dont exist). I get a Http error 403 in phyton from those. I just want the try the next url in the csv file and ignore the error.
```python
import urllib.request
import csv
wi... | 2022/05/10 | [
"https://Stackoverflow.com/questions/72184482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19084463/"
] | You may have an issue with the SNS access policy. There is a video of troubleshooting this issue at <https://youtu.be/RjSW75YsBMM>. | Make sure that your SNS topic has the proper Access Policy set. In my case, the default Access Policy included an `AWS:SourceOwner` condition which I needed to remove in order to allow the S3 event configuration to perform the `SNS:Publish` action against the topic. |
26,207,097 | I am wondering how one would create a GUI application, and interact with it from the console that started it.
As an example, I would like to create a GUI in PyQt and work with it from the console. This could be for testing settings without restarting the app, but in larger projects also for calling functions etc.
Her... | 2014/10/05 | [
"https://Stackoverflow.com/questions/26207097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1356998/"
] | ops, posted wrong answer before
there is a post in Stack about that
[Execute Python code from within PyQt event loop](https://stackoverflow.com/questions/4893748/execute-python-code-from-within-pyqt-event-loop) | The easiest way is to use IPython:
```
ipython --gui=qt4
```
See `ipython --help` or the [online documentation](http://ipython.org/ipython-doc/dev/config/options/terminal.html) for more options (e.g. gtk, tk, etc). |
26,207,097 | I am wondering how one would create a GUI application, and interact with it from the console that started it.
As an example, I would like to create a GUI in PyQt and work with it from the console. This could be for testing settings without restarting the app, but in larger projects also for calling functions etc.
Her... | 2014/10/05 | [
"https://Stackoverflow.com/questions/26207097",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1356998/"
] | The following example uses the [code](https://docs.python.org/3/library/code.html) module to run a console in the command prompt (be sure to run the script from the command line). [Subclassing QThread](https://kushaldas.in/posts/pyqt5-thread-example.html) provides a route by which the console can be run in a separate t... | The easiest way is to use IPython:
```
ipython --gui=qt4
```
See `ipython --help` or the [online documentation](http://ipython.org/ipython-doc/dev/config/options/terminal.html) for more options (e.g. gtk, tk, etc). |
2,157,208 | In python, I have a global variable defined that gets read/incremented by different threads. Because of the GIL, will this ever cause problems without using any kind of locking mechanism? | 2010/01/28 | [
"https://Stackoverflow.com/questions/2157208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/261273/"
] | The GIL only requires that the interpreter completely executes a single bytecode instruction before another thread can take over. However, there is no reason to assume that an increment operation is a single instruction. For example:
```
>>> import dis
>>> dis.dis(compile("x=753","","exec"))
1 0 LOAD_CONST... | Yes, multithreading without locking almost always causes problems, with or without a GIL. |
56,120,774 | In the case where python executes more operations, it is slower.
The following is a very simple comparison of two separate nested loops (for finding a Pythagorean triple `(a,b,c)` which sum to 1000):
```
#Takes 9 Seconds
for a in range(1, 1000):
for b in range(a, 1000):
ab = 1000 - (a + b)
for c in range(ab... | 2019/05/13 | [
"https://Stackoverflow.com/questions/56120774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11495271/"
] | You can just count total amount of iterations in each solution and see that A takes more iterations to find the result:
```
#Takes 9 Seconds
def A():
count = 0
for a in range(1, 1000):
for b in range(a, 1000):
ab = 1000 - (a + b)
for c in range(ab, 1000):
count += 1
if(((a + b + c) == 1000) and... | You have two false premises in your confusion:
* The methods find all triples. They do not; each one finds a single triple and then aborts.
* The upper method (aka "solution A") does fewer comparisons.
I added some basic instrumentation to test your premises:
import time
```
#Takes 9 Seconds
count = 0
start = time.... |
56,120,774 | In the case where python executes more operations, it is slower.
The following is a very simple comparison of two separate nested loops (for finding a Pythagorean triple `(a,b,c)` which sum to 1000):
```
#Takes 9 Seconds
for a in range(1, 1000):
for b in range(a, 1000):
ab = 1000 - (a + b)
for c in range(ab... | 2019/05/13 | [
"https://Stackoverflow.com/questions/56120774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11495271/"
] | You can just count total amount of iterations in each solution and see that A takes more iterations to find the result:
```
#Takes 9 Seconds
def A():
count = 0
for a in range(1, 1000):
for b in range(a, 1000):
ab = 1000 - (a + b)
for c in range(ab, 1000):
count += 1
if(((a + b + c) == 1000) and... | Yes there is a performance difference, but because your code is doing different things:
* Solution A runs c over the `range(1000-(a+b), 1000)`, which will be much shorter. (in fact it doesn't need to run c, it only needs to check for one value `c = 1000-(a+b)`, since that's the only c-value for given a,b that satisfie... |
56,120,774 | In the case where python executes more operations, it is slower.
The following is a very simple comparison of two separate nested loops (for finding a Pythagorean triple `(a,b,c)` which sum to 1000):
```
#Takes 9 Seconds
for a in range(1, 1000):
for b in range(a, 1000):
ab = 1000 - (a + b)
for c in range(ab... | 2019/05/13 | [
"https://Stackoverflow.com/questions/56120774",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11495271/"
] | You have two false premises in your confusion:
* The methods find all triples. They do not; each one finds a single triple and then aborts.
* The upper method (aka "solution A") does fewer comparisons.
I added some basic instrumentation to test your premises:
import time
```
#Takes 9 Seconds
count = 0
start = time.... | Yes there is a performance difference, but because your code is doing different things:
* Solution A runs c over the `range(1000-(a+b), 1000)`, which will be much shorter. (in fact it doesn't need to run c, it only needs to check for one value `c = 1000-(a+b)`, since that's the only c-value for given a,b that satisfie... |
37,464,116 | I have found some ways to using python to build android app.But all of them need to install sl4a and pythonforandroid.
It is so complicated,so is there any way to package sl4a to my android app project,and once I install the apk,I needn't install sl4a any more. | 2016/05/26 | [
"https://Stackoverflow.com/questions/37464116",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5867427/"
] | You can use Kivy at following link :
[Python for Android](https://github.com/kivy/python-for-android)
It will can help u have a look to the following topic :
[How can I integrate a Python code in the Android Java app?](https://www.quora.com/How-can-I-integrate-a-Python-code-in-the-Android-Java-app)
hope this help y... | You *can* do this. What it comes down to is packaging the Python interpreter (compiled by the NDK) in your app, and starting it via the standard NDK mechanisms. This is the same thing that e.g. Kivy does, but you'd be adding the code to your own app rather than (like Kivy) using a java bootstrap then letting the Python... |
21,717,995 | How can i set the python on my mac back to the default reference location? When I to do
```
sudo easy_install virtualenv
```
I get the following results
```
dyld: Library not loaded: @rpath/Python
Referenced from: /Users/a1ctesta/Library/Enthought/Canopy_64bit/User/bin/python
Reason: image not found
```
I do ... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21717995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3221720/"
] | You probably need to modify your `$PATH` environment variable so that `/usr/bin` is before your custom path. To check if this is the issue, run the following command and see if `/usr/bin` is before or after your custom path
```
$ echo $PATH
```
The PATH environment variable is often set in `~/.bash_profile`, for exa... | I had the same issue. It was easiest to reinstall Canopy. From the Canopy preferences menu, Unset Canopy as your default Python. Then restart your computer. <https://support.enthought.com/hc/en-us/articles/204469700-Uninstalling-and-resetting-Canopy> |
21,717,995 | How can i set the python on my mac back to the default reference location? When I to do
```
sudo easy_install virtualenv
```
I get the following results
```
dyld: Library not loaded: @rpath/Python
Referenced from: /Users/a1ctesta/Library/Enthought/Canopy_64bit/User/bin/python
Reason: image not found
```
I do ... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21717995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3221720/"
] | You probably need to modify your `$PATH` environment variable so that `/usr/bin` is before your custom path. To check if this is the issue, run the following command and see if `/usr/bin` is before or after your custom path
```
$ echo $PATH
```
The PATH environment variable is often set in `~/.bash_profile`, for exa... | I had this issue as well. If you edit your ~/.bash\_profile it will permanently fix the issue.
In terminal enter
```
nano ~/.bash_profile
```
It will then show something along the lines of
```
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.fram... |
21,717,995 | How can i set the python on my mac back to the default reference location? When I to do
```
sudo easy_install virtualenv
```
I get the following results
```
dyld: Library not loaded: @rpath/Python
Referenced from: /Users/a1ctesta/Library/Enthought/Canopy_64bit/User/bin/python
Reason: image not found
```
I do ... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21717995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3221720/"
] | Make sure
>
> /usr/bin
>
>
>
precedes
>
> /Users/a1ctesta/Library/Enthought/Canopy\_64bit/User/bin/python
>
>
>
To do that:
1. In the terminal,
>
> export PATH
> =/usr/bin:/Users/a1ctesta/Library/Enthought/Canopy\_64bit/User/bin/python
>
>
>
2. Verify this using,
>
> echo $PATH
>
>
> | I had the same issue. It was easiest to reinstall Canopy. From the Canopy preferences menu, Unset Canopy as your default Python. Then restart your computer. <https://support.enthought.com/hc/en-us/articles/204469700-Uninstalling-and-resetting-Canopy> |
21,717,995 | How can i set the python on my mac back to the default reference location? When I to do
```
sudo easy_install virtualenv
```
I get the following results
```
dyld: Library not loaded: @rpath/Python
Referenced from: /Users/a1ctesta/Library/Enthought/Canopy_64bit/User/bin/python
Reason: image not found
```
I do ... | 2014/02/12 | [
"https://Stackoverflow.com/questions/21717995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3221720/"
] | Make sure
>
> /usr/bin
>
>
>
precedes
>
> /Users/a1ctesta/Library/Enthought/Canopy\_64bit/User/bin/python
>
>
>
To do that:
1. In the terminal,
>
> export PATH
> =/usr/bin:/Users/a1ctesta/Library/Enthought/Canopy\_64bit/User/bin/python
>
>
>
2. Verify this using,
>
> echo $PATH
>
>
> | I had this issue as well. If you edit your ~/.bash\_profile it will permanently fix the issue.
In terminal enter
```
nano ~/.bash_profile
```
It will then show something along the lines of
```
# Setting PATH for Python 2.7
# The orginal version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.fram... |
73,409,909 | No matter what I install, it's either opencv-python, opencv-contrib-python or both at the same time, I keep getting the "No module named 'cv2'" error. I couldn't find an answer here. Some say that only opencv-python works, others say opencv-contrib-python works. I tried everything but nothing seems to work. I'm trying ... | 2022/08/18 | [
"https://Stackoverflow.com/questions/73409909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11672955/"
] | You need update your EAS to 0.60.0
npm install -g eas-cli
I had the same problem.
Work for me, friend | We fixed this issue by next steps
1: Upgrade your eas-cli running: `npm install -g eas-cli`
2: If you're publishing by first time your app, you need request access in to your App Store Connet, by this link,
<https://appstoreconnect.apple.com/access/api>
```
Select Users and Access, and then select the API Keys tab... |
73,409,909 | No matter what I install, it's either opencv-python, opencv-contrib-python or both at the same time, I keep getting the "No module named 'cv2'" error. I couldn't find an answer here. Some say that only opencv-python works, others say opencv-contrib-python works. I tried everything but nothing seems to work. I'm trying ... | 2022/08/18 | [
"https://Stackoverflow.com/questions/73409909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11672955/"
] | You need update your EAS to 0.60.0
npm install -g eas-cli
I had the same problem.
Work for me, friend | There is a bug in Apple's infrastructure that does not propagate newly created objects for a long time (up to 14 seconds in my experiments). Apple responds saying the resource does not exist when the cli tries to download the key and it hasn't fully propagated. I just released a fix in `eas-cli` to retry in this scenar... |
73,409,909 | No matter what I install, it's either opencv-python, opencv-contrib-python or both at the same time, I keep getting the "No module named 'cv2'" error. I couldn't find an answer here. Some say that only opencv-python works, others say opencv-contrib-python works. I tried everything but nothing seems to work. I'm trying ... | 2022/08/18 | [
"https://Stackoverflow.com/questions/73409909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11672955/"
] | We fixed this issue by next steps
1: Upgrade your eas-cli running: `npm install -g eas-cli`
2: If you're publishing by first time your app, you need request access in to your App Store Connet, by this link,
<https://appstoreconnect.apple.com/access/api>
```
Select Users and Access, and then select the API Keys tab... | There is a bug in Apple's infrastructure that does not propagate newly created objects for a long time (up to 14 seconds in my experiments). Apple responds saying the resource does not exist when the cli tries to download the key and it hasn't fully propagated. I just released a fix in `eas-cli` to retry in this scenar... |
66,937,068 | **Please help me fix my regex :).**
Summary: How can I make a repeating group (tags) match greedily even if it means a preceding optional group (a label) is empty.
For some reason, my regex is not acting as desired:
```
code: re.match("^foo(-.*?)?((?:-(?:a|b))*)$", "foo-a-b").groups()
output: ('-a', '-b')
expe... | 2021/04/04 | [
"https://Stackoverflow.com/questions/66937068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4089332/"
] | This boils down to stylistic preferences. I personally don't have qualms with having some of the attributes defined outside of `__init__(...)`, and so would opt for something like:
```
class TriangleData():
def __init__(self, contour_data: np.ndarray):
self.get_triangle_data(contour_data)
def get_tri... | There is a wide spectrum of approaches and libraries to eliminate redundancy of a plain `__init__()`. Please take a look at the [dataclasses](https://docs.python.org/3/library/dataclasses.html), [attrs](https://www.attrs.org/en/stable/), [NamedTuple](https://docs.python.org/3/library/typing.html#typing.NamedTuple) and ... |
66,937,068 | **Please help me fix my regex :).**
Summary: How can I make a repeating group (tags) match greedily even if it means a preceding optional group (a label) is empty.
For some reason, my regex is not acting as desired:
```
code: re.match("^foo(-.*?)?((?:-(?:a|b))*)$", "foo-a-b").groups()
output: ('-a', '-b')
expe... | 2021/04/04 | [
"https://Stackoverflow.com/questions/66937068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4089332/"
] | There is a wide spectrum of approaches and libraries to eliminate redundancy of a plain `__init__()`. Please take a look at the [dataclasses](https://docs.python.org/3/library/dataclasses.html), [attrs](https://www.attrs.org/en/stable/), [NamedTuple](https://docs.python.org/3/library/typing.html#typing.NamedTuple) and ... | To follow the pattern of setting/initializing variables in the constructor, from [Instance variables in methods outside the constructor (Python) -- why and how?](https://stackoverflow.com/questions/38377276/instance-variables-in-methods-outside-the-constructor-python-why-and-how/38378757#38378757) (see answer from Bria... |
66,937,068 | **Please help me fix my regex :).**
Summary: How can I make a repeating group (tags) match greedily even if it means a preceding optional group (a label) is empty.
For some reason, my regex is not acting as desired:
```
code: re.match("^foo(-.*?)?((?:-(?:a|b))*)$", "foo-a-b").groups()
output: ('-a', '-b')
expe... | 2021/04/04 | [
"https://Stackoverflow.com/questions/66937068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4089332/"
] | This boils down to stylistic preferences. I personally don't have qualms with having some of the attributes defined outside of `__init__(...)`, and so would opt for something like:
```
class TriangleData():
def __init__(self, contour_data: np.ndarray):
self.get_triangle_data(contour_data)
def get_tri... | To follow the pattern of setting/initializing variables in the constructor, from [Instance variables in methods outside the constructor (Python) -- why and how?](https://stackoverflow.com/questions/38377276/instance-variables-in-methods-outside-the-constructor-python-why-and-how/38378757#38378757) (see answer from Bria... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | There is a handy event scheduler that might do what you need. Here's a link to the documentation:
<http://docs.python.org/library/sched.html> | Many programmers try to avoid multi-threaded code, since it is highly bug-prone in imperative programming.
If you want to a scheduled task in a single-threaded environment, then you probably need some kind of "[Reactor](http://en.wikipedia.org/wiki/Reactor_pattern)". You may want to use a ready-made one like [Twisted]... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | There is a handy event scheduler that might do what you need. Here's a link to the documentation:
<http://docs.python.org/library/sched.html> | Python has a Timer class in threading module but that is one-shot timer, so you would be better doing something as you have seen links.
<http://code.activestate.com/recipes/65222/>
Why do you think that is ugly, once you have written such a class usage will be as simple as in java.
if you are using it inside some GU... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | There is a handy event scheduler that might do what you need. Here's a link to the documentation:
<http://docs.python.org/library/sched.html> | Not direct response to the question.
On Linux/Unix operating system there are few ways to do so and usually I just write my program / script normally and then add it to cron or something similar (like [launchd](http://nb.nathanamy.org/2012/07/schedule-jobs-using-launchd/) on OS X)
Response to the question starts here... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | There is a handy event scheduler that might do what you need. Here's a link to the documentation:
<http://docs.python.org/library/sched.html> | try the [multiprocessing](http://docs.python.org/library/multiprocessing.html) module.
```
from multiprocessing import Process
import time
def doWork():
while True:
print "working...."
time.sleep(10)
if __name__ == "__main__":
p = Process(target=doWork)
p.start()
while True:
... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | Many programmers try to avoid multi-threaded code, since it is highly bug-prone in imperative programming.
If you want to a scheduled task in a single-threaded environment, then you probably need some kind of "[Reactor](http://en.wikipedia.org/wiki/Reactor_pattern)". You may want to use a ready-made one like [Twisted]... | Python has a Timer class in threading module but that is one-shot timer, so you would be better doing something as you have seen links.
<http://code.activestate.com/recipes/65222/>
Why do you think that is ugly, once you have written such a class usage will be as simple as in java.
if you are using it inside some GU... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | Not direct response to the question.
On Linux/Unix operating system there are few ways to do so and usually I just write my program / script normally and then add it to cron or something similar (like [launchd](http://nb.nathanamy.org/2012/07/schedule-jobs-using-launchd/) on OS X)
Response to the question starts here... | Python has a Timer class in threading module but that is one-shot timer, so you would be better doing something as you have seen links.
<http://code.activestate.com/recipes/65222/>
Why do you think that is ugly, once you have written such a class usage will be as simple as in java.
if you are using it inside some GU... |
1,038,907 | >
> **Possible Duplicate:**
>
> [Suggestions for a Cron like scheduler in Python?](https://stackoverflow.com/questions/373335/suggestions-for-a-cron-like-scheduler-in-python)
>
>
>
What would be the most pythonic way to schedule a function to run periodically as a background task? There are some ideas [here](h... | 2009/06/24 | [
"https://Stackoverflow.com/questions/1038907",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7581/"
] | try the [multiprocessing](http://docs.python.org/library/multiprocessing.html) module.
```
from multiprocessing import Process
import time
def doWork():
while True:
print "working...."
time.sleep(10)
if __name__ == "__main__":
p = Process(target=doWork)
p.start()
while True:
... | Python has a Timer class in threading module but that is one-shot timer, so you would be better doing something as you have seen links.
<http://code.activestate.com/recipes/65222/>
Why do you think that is ugly, once you have written such a class usage will be as simple as in java.
if you are using it inside some GU... |
48,075,739 | django version: 1.11, python version: 3.6.3
I found this stackoverflow question:
[Unit Testing a Django Form with a FileField](https://stackoverflow.com/questions/2473392/unit-testing-a-django-form-with-a-filefield)
and I like how there isn't an actual image/external file used for the unittest; however I tried these... | 2018/01/03 | [
"https://Stackoverflow.com/questions/48075739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3329127/"
] | `image_data` should be dict, without providing key `{value}` will create set object. You need to define it like this `{key: value}`. Fix to this:
```
image_data = {
'image_field': InMemoryUploadedFile(im_io, None, 'random.jpg', 'image/jpeg', len(im_io.getvalue()), None)
}
``` | Without External File Code
```
from django.core.files.uploadedfile import SimpleUploadedFile
testfile = (
b'\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x00\x00\x00\x21\xf9\x04'
b'\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02'
b'\x02\x4c\x01\x00\x3b')
avatar = SimpleUploadedFile('small.gif', testfile, ... |
3,319,788 | I am trying to retrieve data in a sybase data base from python and I was wondering which would be the best way to do it. I found this module but may be you have some other suggestions:
<http://python-sybase.sourceforge.net/>
Thanks | 2010/07/23 | [
"https://Stackoverflow.com/questions/3319788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/400413/"
] | The sybase module you linked is by far the easiest way. You can get data like so:
```
import Sybase
db = Sybase.connect('server','name','pass','database')
c = db.cursor()
c.execute("sql statement")
list1 = c.fetchall()
print list1
```
You will have to use something like freetds to setup the interfaces for sybase, ... | you can also connect through [ODBC](http://tinyurl.com/255plm2). |
3,319,788 | I am trying to retrieve data in a sybase data base from python and I was wondering which would be the best way to do it. I found this module but may be you have some other suggestions:
<http://python-sybase.sourceforge.net/>
Thanks | 2010/07/23 | [
"https://Stackoverflow.com/questions/3319788",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/400413/"
] | The sybase module you linked is by far the easiest way. You can get data like so:
```
import Sybase
db = Sybase.connect('server','name','pass','database')
c = db.cursor()
c.execute("sql statement")
list1 = c.fetchall()
print list1
```
You will have to use something like freetds to setup the interfaces for sybase, ... | There is also `python-pymssql` which is in Debian / Ubuntu. This can connect to MS-SQL-Server or Sybase using freetds. I'm not sure how it compares to the other options.
<http://www.pymssql.org/>
Example code, abridged from their website:
```
import pymssql
conn = pymssql.connect('server','user','pass','database')
... |
28,724,785 | I am currently working on a project that makes use of Python 3.2.3 and thought to do some tests of my code in IPython but it seems that IPython does not support the version of python I am using.
I get the following ImportError when trying to run Ipython on my Ubuntu machine.
```
ImportError: IPython requires Python v... | 2015/02/25 | [
"https://Stackoverflow.com/questions/28724785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3166105/"
] | You can find some discussion about dropping 2.6 and 3.2 support [here](https://github.com/ipython/ipython/pull/4002). One of the main reasons was that 3.2 does not support 2.x-style unicode strings - `u"I love IPython!"`, while 3.3 and above do. This change made it possible to support 2.7 and 3.3+ in a single codebase. | [Quickstart](http://ipython.org/ipython-doc/2/install/install.html):
IPython requires Python 2.7 or ≥ 3.3.
If you need to use Python 2.6 or 3.2, you can find IPython 1.0 [here](http://archive.ipython.org/release/).
PS:
The deadsnakes PPA has packages for old and new python versions:
```
sudo apt-get install python... |
68,081,171 | This is a problem of the missing number in python.
```
class Missing:
n = int(input())
arr = list(map(int,input().split(" ")))
def __init__(self,arr,n):
self.arr = arr
self.n = n
def MissingNumber(self):
self.res = self.n*(self.n+1)/2
self.sum_array = sum(self.arr)
... | 2021/06/22 | [
"https://Stackoverflow.com/questions/68081171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14643490/"
] | you need put the input outside class,and assign it when you create instance by `Obj = Missing(arr,n)`
code:
```
class Missing:
def __init__(self,arr,n):
self.arr = arr
self.n = n
def MissingNumber(self):
self.res = self.n*(self.n+1)/2
self.sum_array = sum(self.arr)
ret... | your constructor need two parameter. You need to assign it before it run.
you need to assign n and arr outside class object
```
class Missing:
def __init__(self,arr,n):
self.arr = arr
self.n = n
def MissingNumber(self):
self.res = self.n*(self.n+1)/2
self.sum_array = sum(self.... |
6,715,486 | So I am fairly new to python. But would like your help solving this minor issue I having removing similar duplicates out of a list.
So I have a list of urls: `myList = ['http://www.mywebsite.com/shoes', 'http://wwww.yourwebsite.com/', 'http://www.mywebsite.com/shoes/']`
I want to remove similar url's as you can see <... | 2011/07/16 | [
"https://Stackoverflow.com/questions/6715486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/841342/"
] | If similarity for you is difference in '\' thab you can use sets[(read tutorial here)](http://docs.python.org/tutorial/datastructures.html#sets) [and here](http://docs.python.org/library/stdtypes.html?highlight=frozenset#set-types-set-frozenset) to remove duplicates from your list since:
>
> A set object is an unorde... | The issue may be that you haven't figured out exactly what it means for two URLs to be similar. We can't help you with that because only you know what your requirements are. Once you do figure that out, though, the rest is simple enough. There are two ways to do it:
* If your similarity relation is transitive - that i... |
6,715,486 | So I am fairly new to python. But would like your help solving this minor issue I having removing similar duplicates out of a list.
So I have a list of urls: `myList = ['http://www.mywebsite.com/shoes', 'http://wwww.yourwebsite.com/', 'http://www.mywebsite.com/shoes/']`
I want to remove similar url's as you can see <... | 2011/07/16 | [
"https://Stackoverflow.com/questions/6715486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/841342/"
] | You could do:
1. First, remove last slash
2. List item
Remove duplicates:
```
set(map(lambda url: url.rstrip('/'), myList))
``` | The issue may be that you haven't figured out exactly what it means for two URLs to be similar. We can't help you with that because only you know what your requirements are. Once you do figure that out, though, the rest is simple enough. There are two ways to do it:
* If your similarity relation is transitive - that i... |
15,848,156 | I use the package named python-snappy. This package requires [snappy](https://code.google.com/p/snappy/) library. So, I download and install snappy successfully by the following commands such as:
```
./configure
make
sudo make install
```
When I import snappy, I receive the errors:
```
from _snappy import CompressE... | 2013/04/06 | [
"https://Stackoverflow.com/questions/15848156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/875781/"
] | Traditionally you might have to run the `ldconfig` utility to update your */etc/ld.so.cache* (or equivalent as appropriate to your OS). Sometimes it might be necessary to add new entries (paths) to your */etc/ld.so.conf*.
Basically the shared object (so) loaders on many versions of Unix (and probably other Unix-like o... | You can install the [python-snappy](http://packages.ubuntu.com/precise/python-snappy) and [libsnappy1](http://packages.ubuntu.com/precise/libsnappy1) from the ubuntu repos:
```
$ sudo apt-get install libsnappy1 python-snappy
```
You should not have to download anything. |
15,848,156 | I use the package named python-snappy. This package requires [snappy](https://code.google.com/p/snappy/) library. So, I download and install snappy successfully by the following commands such as:
```
./configure
make
sudo make install
```
When I import snappy, I receive the errors:
```
from _snappy import CompressE... | 2013/04/06 | [
"https://Stackoverflow.com/questions/15848156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/875781/"
] | You can install the [python-snappy](http://packages.ubuntu.com/precise/python-snappy) and [libsnappy1](http://packages.ubuntu.com/precise/libsnappy1) from the ubuntu repos:
```
$ sudo apt-get install libsnappy1 python-snappy
```
You should not have to download anything. | Here for e.g. anaconda python
1. Download snappy from [github](http://google.github.io/snappy/)
2. also download the python file
3. extract both files
4. google-snappy folder
`$ ./configure`
`$ make`
`$ sudo make install`
5. Then in python folder:
`$ python setup.py build # here I get the same import _snappy error... |
15,848,156 | I use the package named python-snappy. This package requires [snappy](https://code.google.com/p/snappy/) library. So, I download and install snappy successfully by the following commands such as:
```
./configure
make
sudo make install
```
When I import snappy, I receive the errors:
```
from _snappy import CompressE... | 2013/04/06 | [
"https://Stackoverflow.com/questions/15848156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/875781/"
] | You can install the [python-snappy](http://packages.ubuntu.com/precise/python-snappy) and [libsnappy1](http://packages.ubuntu.com/precise/libsnappy1) from the ubuntu repos:
```
$ sudo apt-get install libsnappy1 python-snappy
```
You should not have to download anything. | the following worked for me:
```
$ conda install python-snappy
```
then in my code I used:
```
import snappy
``` |
15,848,156 | I use the package named python-snappy. This package requires [snappy](https://code.google.com/p/snappy/) library. So, I download and install snappy successfully by the following commands such as:
```
./configure
make
sudo make install
```
When I import snappy, I receive the errors:
```
from _snappy import CompressE... | 2013/04/06 | [
"https://Stackoverflow.com/questions/15848156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/875781/"
] | Traditionally you might have to run the `ldconfig` utility to update your */etc/ld.so.cache* (or equivalent as appropriate to your OS). Sometimes it might be necessary to add new entries (paths) to your */etc/ld.so.conf*.
Basically the shared object (so) loaders on many versions of Unix (and probably other Unix-like o... | Here for e.g. anaconda python
1. Download snappy from [github](http://google.github.io/snappy/)
2. also download the python file
3. extract both files
4. google-snappy folder
`$ ./configure`
`$ make`
`$ sudo make install`
5. Then in python folder:
`$ python setup.py build # here I get the same import _snappy error... |
15,848,156 | I use the package named python-snappy. This package requires [snappy](https://code.google.com/p/snappy/) library. So, I download and install snappy successfully by the following commands such as:
```
./configure
make
sudo make install
```
When I import snappy, I receive the errors:
```
from _snappy import CompressE... | 2013/04/06 | [
"https://Stackoverflow.com/questions/15848156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/875781/"
] | Traditionally you might have to run the `ldconfig` utility to update your */etc/ld.so.cache* (or equivalent as appropriate to your OS). Sometimes it might be necessary to add new entries (paths) to your */etc/ld.so.conf*.
Basically the shared object (so) loaders on many versions of Unix (and probably other Unix-like o... | the following worked for me:
```
$ conda install python-snappy
```
then in my code I used:
```
import snappy
``` |
15,848,156 | I use the package named python-snappy. This package requires [snappy](https://code.google.com/p/snappy/) library. So, I download and install snappy successfully by the following commands such as:
```
./configure
make
sudo make install
```
When I import snappy, I receive the errors:
```
from _snappy import CompressE... | 2013/04/06 | [
"https://Stackoverflow.com/questions/15848156",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/875781/"
] | the following worked for me:
```
$ conda install python-snappy
```
then in my code I used:
```
import snappy
``` | Here for e.g. anaconda python
1. Download snappy from [github](http://google.github.io/snappy/)
2. also download the python file
3. extract both files
4. google-snappy folder
`$ ./configure`
`$ make`
`$ sudo make install`
5. Then in python folder:
`$ python setup.py build # here I get the same import _snappy error... |
59,412,006 | I am new to python and having a problem:
my task was `"Given a sentence, return a sentence with the words reversed"`
e.g. `Tea is hot --------> hot is Tea`
my code was:
```
def funct1 (x):
a,b,c = x.split()
return c + " "+ b + " "+ a
funct1 ("I am home")
```
It did solve the answer, but i have 2 questi... | 2019/12/19 | [
"https://Stackoverflow.com/questions/59412006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12565719/"
] | Your code is heavily dependent on the assumption that the string will always contain **exactly** 2 spaces. The task description you provided does not say that this will always be the case.
This assumption can be eliminated by using `str.join` and `[::-1]` to reverse the list:
```
def funct1(x):
return ' '.join(x.... | A pythonic way to do this would be:
```
def reverse_words(sentence):
return " ".join(reversed(sentence.split()))
```
To answer the subquestions:
1. Yes, use [`str.join`](https://docs.python.org/3/library/stdtypes.html#str.join).
2. Yes, you can use a [slice](https://stackoverflow.com/questions/509211/understand... |
32,780,946 | I have this database layout
```
class Clinic(models.Model):
class Menu(models.Model):
...
menu = models.OneToOneField(Clinic, related_name='menu')
class Item(models.Model):
...
menu = models.ForeignKey('Menu')
```
and I would like to access my Menu model and the Items linked to that menu from my Cl... | 2015/09/25 | [
"https://Stackoverflow.com/questions/32780946",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3282276/"
] | `clinic.menu.objects` is the `ModelManager` for the `Menu` model - note that it's an attribute of the `Menu` *class*, not of your `clinic.menu` instance. `ModelManager` classes are used to query the underlying table, and are not supposed to be called directly from instances (which wouldn't make much sense anyway), henc... | Try this:
```
Clinic.objects.get(pk=1).menu.item_set.all()
``` |
8,264,569 | I've got 32 SQLite (3.7.9) databases with 3 tables each that I'm trying to merge together using the idiom that I've found elsewhere (each db has the same schema):
```
attach db1.sqlite3 as toMerge;
insert into tbl1 select * from toMerge.tbl1;
insert into tbl2 select * from toMerge.tbl2;
insert into tbl3 select * from ... | 2011/11/25 | [
"https://Stackoverflow.com/questions/8264569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126321/"
] | You can do it somewhat with HTML5's new input types
See: <http://www.456bereastreet.com/archive/201004/html5_input_types/> | Using HTML5, kind of yes. Link: <http://thereforei.am/2011/07/01/css-selectors-for-html5-input-validation/> |
8,264,569 | I've got 32 SQLite (3.7.9) databases with 3 tables each that I'm trying to merge together using the idiom that I've found elsewhere (each db has the same schema):
```
attach db1.sqlite3 as toMerge;
insert into tbl1 select * from toMerge.tbl1;
insert into tbl2 select * from toMerge.tbl2;
insert into tbl3 select * from ... | 2011/11/25 | [
"https://Stackoverflow.com/questions/8264569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126321/"
] | Using HTML5, kind of yes. Link: <http://thereforei.am/2011/07/01/css-selectors-for-html5-input-validation/> | As others writes: Yes, with HTML5. BUT HTML5 is NOT fully supported by most browsers. So don't use this approach yet.
You can't do it with CSS, you have to use JavaScript until HTML5 is fully supported.
But ALWAYS remember to validate server-side as well via ASP(.NET), PHP and such.. Doing both Client-side and Server-... |
8,264,569 | I've got 32 SQLite (3.7.9) databases with 3 tables each that I'm trying to merge together using the idiom that I've found elsewhere (each db has the same schema):
```
attach db1.sqlite3 as toMerge;
insert into tbl1 select * from toMerge.tbl1;
insert into tbl2 select * from toMerge.tbl2;
insert into tbl3 select * from ... | 2011/11/25 | [
"https://Stackoverflow.com/questions/8264569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126321/"
] | You can do it somewhat with HTML5's new input types
See: <http://www.456bereastreet.com/archive/201004/html5_input_types/> | As others writes: Yes, with HTML5. BUT HTML5 is NOT fully supported by most browsers. So don't use this approach yet.
You can't do it with CSS, you have to use JavaScript until HTML5 is fully supported.
But ALWAYS remember to validate server-side as well via ASP(.NET), PHP and such.. Doing both Client-side and Server-... |
49,461,537 | Using pycharm community python3.6.2 Django 2.0.3
views.py
```
from django.http import HttpResponse
def hello_world(request):
return HttpResponse('Hello World')
```
urls.py
```
from django.conf.urls import url
from django.contrib import admin
from . import views
urlpatterns = [
url(r'^admin/', admin.si... | 2018/03/24 | [
"https://Stackoverflow.com/questions/49461537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9511012/"
] | The error is telling you that there is no variable such as `hello_world` defined. You need to change it to:
```
url(r'^$', views.hello_world)
```
Where `views` is the views module that you have imported at the top. | This line of code is wrong
```
url(r'^$', views, hello_world)
```
You just imported the `view` which is the file view.py. Now you need to call the function view, which it is going to be like:
```
url(r'^$', views.hello_world)
```
And you might think it is going to be useful to give that url a name so you can use ... |
36,937,305 | I am running a shell script in cygwin where I am using python robot framework, but in that environment it's not getting 'pybot' as command.
```
$ pybot --version
```
Result-
```
-bash: pybot: command not found
```
However in cmd prompt the above command is working fine.
PS- I have already set python interpreter... | 2016/04/29 | [
"https://Stackoverflow.com/questions/36937305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4637378/"
] | I have explored and get to know that, in Cygwin we need to specify the file type as well. So, if we say-
```
pybot.bat --version
```
this should work. | worked for me in cygwin:
Adjetterpc@Pompina
$ robot.bat --version
Robot Framework 3.0.4 (Python 2.7.13 on win32)
Adjetterpc@Pompina
$ pybot.bat --version
Robot Framework 3.0.4 (Python 2.7.13 on win32) |
62,023,199 | I have a little problem on making ecounter for fast food, the problems is at continuing order.
I don't know how to use True and False in python..
I choose three food as a beginner. It's end up failing..
So I tried to use True by copying other people code.
at first the code was success, but when i changed a little thing... | 2020/05/26 | [
"https://Stackoverflow.com/questions/62023199",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13620217/"
] | Query is fairly self explanatory. I have added a should clause with a match on field c and no exists check on field c. Minimum\_should\_match is set as 1. A document which matches either of clause is returned i.e either it should not exist or should match the input string
```
{
"query": {
"bool": {
"must":... | Use filter and exist.
[exists](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html)
[filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-exists-query.html)
```
{
"query": {
"filtered": {
"filter": {
"bool": {
"must_no... |
48,886,423 | I have a address list as :
```
addr = ['100 NORTH MAIN ROAD',
'100 BROAD ROAD APT.',
'SAROJINI DEVI ROAD',
'BROAD AVENUE ROAD']
```
I need to do my replacement work in a following function:
```
def subst(pattern, replace_str, string):
```
by defining a pattern outside of this f... | 2018/02/20 | [
"https://Stackoverflow.com/questions/48886423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9385748/"
] | No need for regex, just use `replace`:
```
[x.replace('ROAD', 'RD') for x in addr]
```
If you only want to replace the `ROAD` as a word, no in the middle, use:
```
[re.sub(r'\bROAD\b', 'RD', x) for x in addr]
``` | Using `re`
```
import re
addr = ['100 NORTH MAIN ROAD',
'100 BROAD ROAD APT.',
'SAROJINI DEVI ROAD',
'BROAD AVENUE ROAD']
for i, v in enumerate(addr):
addr[i] = re.sub('ROAD', 'RD', v) #v.replace("ROAD", "RD")
print addr
```
**Output**:
```
['100 NORTH MAIN RD', '100 BRD R... |
48,886,423 | I have a address list as :
```
addr = ['100 NORTH MAIN ROAD',
'100 BROAD ROAD APT.',
'SAROJINI DEVI ROAD',
'BROAD AVENUE ROAD']
```
I need to do my replacement work in a following function:
```
def subst(pattern, replace_str, string):
```
by defining a pattern outside of this f... | 2018/02/20 | [
"https://Stackoverflow.com/questions/48886423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9385748/"
] | No need for regex, just use `replace`:
```
[x.replace('ROAD', 'RD') for x in addr]
```
If you only want to replace the `ROAD` as a word, no in the middle, use:
```
[re.sub(r'\bROAD\b', 'RD', x) for x in addr]
``` | *Using* **RegEx**..
```
import re
count = 0
for x in addr:
addr[count] = re.sub('ROAD', 'RD', x)
count = count + 1
addr # just to print the result.
``` |
48,886,423 | I have a address list as :
```
addr = ['100 NORTH MAIN ROAD',
'100 BROAD ROAD APT.',
'SAROJINI DEVI ROAD',
'BROAD AVENUE ROAD']
```
I need to do my replacement work in a following function:
```
def subst(pattern, replace_str, string):
```
by defining a pattern outside of this f... | 2018/02/20 | [
"https://Stackoverflow.com/questions/48886423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9385748/"
] | No need for regex, just use `replace`:
```
[x.replace('ROAD', 'RD') for x in addr]
```
If you only want to replace the `ROAD` as a word, no in the middle, use:
```
[re.sub(r'\bROAD\b', 'RD', x) for x in addr]
``` | I got the answer,
```
pattern=r'\bROAD\b'
```
passing this a parameter to
```
def subst(pattern, replace_str, string):
#susbstitute pattern and return it
new=[re.sub(pattern,'RD',x) for x in string]
return new
```
we can get the op :) |
70,332,822 | I am receiving an image as bytes that I would like to store using specifically with open command due to library restrictions. Therefore I am unable to use libs like opencv2 and PIL
```
mport numpy as np
import base64
import cv2
import io
from os.path import dirname, join
from com.chaquo.python import Python
def main(... | 2021/12/13 | [
"https://Stackoverflow.com/questions/70332822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | As you wrote most Databricks clusters use 1.2.17 so it is different version and version affected by vulnerability is not used by Databricks.
Only one problem is when you install different version by yourself on the cluster. Even when you installed affected version you can mitigate the problem by setting Spark config i... | you get complete e2e update on this here : <https://databricks.com/blog/2021/12/13/log4j2-vulnerability-cve-2021-44228-research-and-assessment.html> |
13,788,114 | Given the following Python (from <http://norvig.com/sudoku.html>)
```
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
cols = '123456789'
rows = 'ABCDEFGHI'
squares = cross(rows, cols)
```
This produces:
```
['A1', 'A2', 'A3', 'A4', 'A5', 'A6'... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163625/"
] | Well it's shorter to just present the code than to explain:
```
#include <iostream> // std::wcout, std::endl
#include <string> // std::string
#include <utility> // std::begin, std::end
#include <vector>
using namespace std;
string sum( char const a, char const b ) { return string() + a + b;... | templatize for classes A and B. then make pairs `std::pair<A, B>` |
13,788,114 | Given the following Python (from <http://norvig.com/sudoku.html>)
```
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
cols = '123456789'
rows = 'ABCDEFGHI'
squares = cross(rows, cols)
```
This produces:
```
['A1', 'A2', 'A3', 'A4', 'A5', 'A6'... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163625/"
] | You could certainly make this generic:
```
template <class InIt1, class InIt2, class OutIt>
void cross_product(InIt1 b1, InIt1 e1, InIt2 b2, InIt2 e2, OutIt out) {
for (auto i=b1; i != e1; ++i)
for (auto j=b2; j != e2; ++j)
*out++ = std::make_pair(*i, *j);
}
```
Note that you don't genera... | templatize for classes A and B. then make pairs `std::pair<A, B>` |
13,788,114 | Given the following Python (from <http://norvig.com/sudoku.html>)
```
def cross(A, B):
"Cross product of elements in A and elements in B."
return [a+b for a in A for b in B]
cols = '123456789'
rows = 'ABCDEFGHI'
squares = cross(rows, cols)
```
This produces:
```
['A1', 'A2', 'A3', 'A4', 'A5', 'A6'... | 2012/12/09 | [
"https://Stackoverflow.com/questions/13788114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1163625/"
] | Weirdly enough, `cross_product` is missing from the C++ algorithms library. It can easily be added but as Jerry’s and Alf’s answers show, opinions differ on how to do it best. In fact, I’d do it different still. Jerry’s interface conforms to that of the other C++ algorithms but he didn’t abstract away the cross product... | templatize for classes A and B. then make pairs `std::pair<A, B>` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.