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 |
|---|---|---|---|---|---|
66,977,521 | I want to run arbitrary "code" in an argument like an anonymous function in Python.
How to do this in one single line?
Lambdas seems that does not work since they only take one expression.
```
def call_func(callback):
callback()
def f():
pkg_set_status(package_name, status)
print('ok')
call_func(f)
```
... | 2021/04/06 | [
"https://Stackoverflow.com/questions/66977521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3274630/"
] | The structure defined by myList with the `<ol>` elements is never actually added to the document. If you concatenate the `<ol>`, then the `<li>` entries, then `</ol>` all to wrapper.innerHTML then it should work.
For example something like...
```
var myList = "<ol>";
for (var i = 0; i < properties.length; i++) {
... | You need to loop first then place the concatenated value into the wrapper...
If you look closely at your code when you inspect the parsed code in the browser inspector, you'll see that only the list items make it into the code. Then look at your myList variable, you never add that to the DOM. So by concatenating the v... |
66,977,521 | I want to run arbitrary "code" in an argument like an anonymous function in Python.
How to do this in one single line?
Lambdas seems that does not work since they only take one expression.
```
def call_func(callback):
callback()
def f():
pkg_set_status(package_name, status)
print('ok')
call_func(f)
```
... | 2021/04/06 | [
"https://Stackoverflow.com/questions/66977521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3274630/"
] | The structure defined by myList with the `<ol>` elements is never actually added to the document. If you concatenate the `<ol>`, then the `<li>` entries, then `</ol>` all to wrapper.innerHTML then it should work.
For example something like...
```
var myList = "<ol>";
for (var i = 0; i < properties.length; i++) {
... | What you are trying to do is adding the innerHTML of `wrapper` directly as a `list`. You need to concat your data into `li` that will concat with your `ol` and at last add in DOM.
```js
function onloadFunction() {
var properties = [{
unitNo: "C-8-1",
owner: "Foo Yoke Wai"
},
{
unitNo: "C-3A... |
46,966,690 | I have data like this:
```
0,tcp,http,SF,181,5450,0.11,0.00,0.00,0.00,,normal.
0,tcp,http,SF,239,486,0.05,0.00,0.00,0.00,normal.
0,tcp,http,SF,235,1337,0.03,0.00,0.00,0.00,normal.
0,tcp,http,SF,219,1337,0.03,0.00,0.00,0.00,normal.
```
The original data was stored in txt. I used list to store them in python. But the ... | 2017/10/27 | [
"https://Stackoverflow.com/questions/46966690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7428504/"
] | When accessing data or methods from within the vue object, use `this.thing`. In your case, that would be `this.strSlug(this.shop.name)`. | Does not work even with 'this.' because that function has not been defined at the time data is being initialized. I think you have to do it in the created() life-cycle hook. |
46,966,690 | I have data like this:
```
0,tcp,http,SF,181,5450,0.11,0.00,0.00,0.00,,normal.
0,tcp,http,SF,239,486,0.05,0.00,0.00,0.00,normal.
0,tcp,http,SF,235,1337,0.03,0.00,0.00,0.00,normal.
0,tcp,http,SF,219,1337,0.03,0.00,0.00,0.00,normal.
```
The original data was stored in txt. I used list to store them in python. But the ... | 2017/10/27 | [
"https://Stackoverflow.com/questions/46966690",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7428504/"
] | If you have a function in `data` that will be used in a context of another object (like an event handler, for example), then `this` will not point to the Vue instance. You will have to preserve the reference in another variable from the scope of `data()`:
```
methods: {
shuffle() {}
},
data() {
var self = this... | Does not work even with 'this.' because that function has not been defined at the time data is being initialized. I think you have to do it in the created() life-cycle hook. |
61,605,694 | I'm implementing a two-link acrobot simulation using pydrake and would like to enforce joint limits to prevent the lower link from colliding with the upper link. I've added the joint limits to the URDF and am parsing this URDF to generate an acrobot multibodyplant object. I've used functions to successfully verify that... | 2020/05/05 | [
"https://Stackoverflow.com/questions/61605694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13471747/"
] | I just tried to reproduce, and was also surprised that it doesn't appear to work.
Here is a runnable reproduction that violates the joint lower limit at the elbow, which is set to 0.0.
It also prints out the limit from the joint, confirming that the parsing worked.
<https://www.dropbox.com/s/2m12ws0g88t5uei/joint_l... | >
> ...but my simulation is not responding to those limits
>
>
>
what do you mean exactly?.
First, you should know that our joint limits are "soft", meaning that they are not constraints but more like stiff springs. `MultibodyPlant` computes the stiffness of these springs automatically for you to ensure the stab... |
61,605,694 | I'm implementing a two-link acrobot simulation using pydrake and would like to enforce joint limits to prevent the lower link from colliding with the upper link. I've added the joint limits to the URDF and am parsing this URDF to generate an acrobot multibodyplant object. I've used functions to successfully verify that... | 2020/05/05 | [
"https://Stackoverflow.com/questions/61605694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13471747/"
] | I just tried to reproduce, and was also surprised that it doesn't appear to work.
Here is a runnable reproduction that violates the joint lower limit at the elbow, which is set to 0.0.
It also prints out the limit from the joint, confirming that the parsing worked.
<https://www.dropbox.com/s/2m12ws0g88t5uei/joint_l... | We just were talking with @Russ Tedrake.
As I mentioned, this is a "corner" case for MultibodyPlant that unfortunately it does not handle well, see Drake's issue [#12775](https://github.com/RobotLocomotion/drake/issues/12775).
The "corner" case here is that the rotational inertia of the upper arm about elbow's axis i... |
57,221,919 | I try to install `docker-ce` on `redhat 8` but it failed
first, I try
```
# systemctl enable docker
Failed to enable unit: Unit file docker.service does not exist.
```
So, I want to install `docker-ce` for the daemon
```
# yum install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/cen... | 2019/07/26 | [
"https://Stackoverflow.com/questions/57221919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11841974/"
] | yum install docker-ce --no-best worked for me
( Installed: docker-ce-3:18.09.1-3.el7.x86\_64 and Skipped: docker-ce-3:19.03.1-3.el7.x86\_64) | My guess, due to a missing subscription you cannot download packages from repositories the docker-ce package needs. So first register for a development account with redhat, then subscribe your host using the subscription Manager (remember, no production usage allowed then) and then retry the installation.
Edit: Here ar... |
57,221,919 | I try to install `docker-ce` on `redhat 8` but it failed
first, I try
```
# systemctl enable docker
Failed to enable unit: Unit file docker.service does not exist.
```
So, I want to install `docker-ce` for the daemon
```
# yum install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/cen... | 2019/07/26 | [
"https://Stackoverflow.com/questions/57221919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11841974/"
] | Disabling the `container-tools` module (installed by default) resolves the conflict: `dnf module disable container-tools`
However, you first need to install the `container-selinux` dependency, which is provided by the same module:
```
[root@centos8-2gb-hel1-1 ~]# yum install container-selinux
...
[root@centos8-2gb-he... | My guess, due to a missing subscription you cannot download packages from repositories the docker-ce package needs. So first register for a development account with redhat, then subscribe your host using the subscription Manager (remember, no production usage allowed then) and then retry the installation.
Edit: Here ar... |
57,221,919 | I try to install `docker-ce` on `redhat 8` but it failed
first, I try
```
# systemctl enable docker
Failed to enable unit: Unit file docker.service does not exist.
```
So, I want to install `docker-ce` for the daemon
```
# yum install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/cen... | 2019/07/26 | [
"https://Stackoverflow.com/questions/57221919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11841974/"
] | There is a dependency issue in `Centos 8` which references the `containerd` from `Centos 7`.
Just install the `containerd` package manually, and it will work
```
yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm
``` | My guess, due to a missing subscription you cannot download packages from repositories the docker-ce package needs. So first register for a development account with redhat, then subscribe your host using the subscription Manager (remember, no production usage allowed then) and then retry the installation.
Edit: Here ar... |
57,221,919 | I try to install `docker-ce` on `redhat 8` but it failed
first, I try
```
# systemctl enable docker
Failed to enable unit: Unit file docker.service does not exist.
```
So, I want to install `docker-ce` for the daemon
```
# yum install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/cen... | 2019/07/26 | [
"https://Stackoverflow.com/questions/57221919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11841974/"
] | Disabling the `container-tools` module (installed by default) resolves the conflict: `dnf module disable container-tools`
However, you first need to install the `container-selinux` dependency, which is provided by the same module:
```
[root@centos8-2gb-hel1-1 ~]# yum install container-selinux
...
[root@centos8-2gb-he... | yum install docker-ce --no-best worked for me
( Installed: docker-ce-3:18.09.1-3.el7.x86\_64 and Skipped: docker-ce-3:19.03.1-3.el7.x86\_64) |
57,221,919 | I try to install `docker-ce` on `redhat 8` but it failed
first, I try
```
# systemctl enable docker
Failed to enable unit: Unit file docker.service does not exist.
```
So, I want to install `docker-ce` for the daemon
```
# yum install yum-utils
# yum-config-manager --add-repo https://download.docker.com/linux/cen... | 2019/07/26 | [
"https://Stackoverflow.com/questions/57221919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11841974/"
] | Disabling the `container-tools` module (installed by default) resolves the conflict: `dnf module disable container-tools`
However, you first need to install the `container-selinux` dependency, which is provided by the same module:
```
[root@centos8-2gb-hel1-1 ~]# yum install container-selinux
...
[root@centos8-2gb-he... | There is a dependency issue in `Centos 8` which references the `containerd` from `Centos 7`.
Just install the `containerd` package manually, and it will work
```
yum install -y https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.10-3.2.el7.x86_64.rpm
``` |
28,299,754 | ```
a = [(24, 13), (23, 13), (22, 13), (21, 13), (20, 13),
(19, 13), (19, 14), (19, 15), (18, 15), (17, 15),
(16, 15), (15, 15), (14, 15), (13, 15), (13, 14),
(13, 13), (13, 12), (13, 11), (13, 10), (12, 10),
(11, 10), (10, 10), (9, 10), (8, 10), (7, 10),
(7, 9), (7, 8), (7, 7), (7, 6), (7, 5),... | 2015/02/03 | [
"https://Stackoverflow.com/questions/28299754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4296482/"
] | Probably not the prettiest solution, but the straightforward way would be this:
```
a = [(24, 13), (23, 13), (22, 13), (21, 13), (20, 13),
(19, 13), (19, 14), (19, 15), (18, 15), (17, 15),
(16, 15), (15, 15), (14, 15), (13, 15), (13, 14),
(13, 13), (13, 12), (13, 11), (13, 10), (12, 10),
(11, 10), ... | you can convert the tuples to numpy array, and check if after two legs, you moved in both axis.
```
arr = np.array(a)
((np.abs(arr[2:] - arr[:-2])>0).sum(axis=1)==2).sum()
``` |
28,299,754 | ```
a = [(24, 13), (23, 13), (22, 13), (21, 13), (20, 13),
(19, 13), (19, 14), (19, 15), (18, 15), (17, 15),
(16, 15), (15, 15), (14, 15), (13, 15), (13, 14),
(13, 13), (13, 12), (13, 11), (13, 10), (12, 10),
(11, 10), (10, 10), (9, 10), (8, 10), (7, 10),
(7, 9), (7, 8), (7, 7), (7, 6), (7, 5),... | 2015/02/03 | [
"https://Stackoverflow.com/questions/28299754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4296482/"
] | Probably not the prettiest solution, but the straightforward way would be this:
```
a = [(24, 13), (23, 13), (22, 13), (21, 13), (20, 13),
(19, 13), (19, 14), (19, 15), (18, 15), (17, 15),
(16, 15), (15, 15), (14, 15), (13, 15), (13, 14),
(13, 13), (13, 12), (13, 11), (13, 10), (12, 10),
(11, 10), ... | Here is what I suggest :
```
x0, y0 = a[0]
previous_move_dir = ''
turns_nb = -1 # start is not a turn
for x1, y1 in a[1:]:
if x1 == x0 and abs(y1-y0) == 1: # move is 1 in Y direction
move_dir = 'Y'
elif y1 == y0 and abs(x1-x0) == 1: # move is 1 in X direction
move_dir = 'X'
else: # move... |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Incidentally, in case it's helpful to another who lands here, I have the same issue on an M1 Max MacBook Pro laptop attempting to do a `docker build` from a company repo that should be a pretty well traveled path, but I might be the only one (it's a small company) that has an ARM64 M1 "Apple Silicon" Mac. ***However I ... | this resolved my issue.
```
FROM ubuntu:focal
RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN curl -OL https://golang.org/dl/go1.17.linux-arm64.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-arm64.ta... |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | this resolved my issue.
```
FROM ubuntu:focal
RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN curl -OL https://golang.org/dl/go1.17.linux-arm64.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-arm64.ta... | Passing following flag to C preprocessor as `CPPFLAGS` solved similar issue in my M1
```
-DPNG_ARM_NEON_OPT=0
```
Pass the value as env var with key `CPPFLAGS` to relevant service. |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | this resolved my issue.
```
FROM ubuntu:focal
RUN apt update; apt install -y curl jq build-essential python3.8 python3-pip docker-compose jsonnet bison mercurial
RUN ln -s /usr/bin/python3.8 /usr/bin/python
RUN curl -OL https://golang.org/dl/go1.17.linux-arm64.tar.gz; mkdir /etc/golang; tar -xvzf go1.17.linux-arm64.ta... | Provided the base image includes the target architecture, another option that might work in your case is using Docker's built-in [`TARGETARCH`](https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope) build arg. This works for me on macOS M1.
```
FROM ubuntu:focal
ARG TARGETARCH
R... |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Incidentally, in case it's helpful to another who lands here, I have the same issue on an M1 Max MacBook Pro laptop attempting to do a `docker build` from a company repo that should be a pretty well traveled path, but I might be the only one (it's a small company) that has an ARM64 M1 "Apple Silicon" Mac. ***However I ... | Passing following flag to C preprocessor as `CPPFLAGS` solved similar issue in my M1
```
-DPNG_ARM_NEON_OPT=0
```
Pass the value as env var with key `CPPFLAGS` to relevant service. |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Incidentally, in case it's helpful to another who lands here, I have the same issue on an M1 Max MacBook Pro laptop attempting to do a `docker build` from a company repo that should be a pretty well traveled path, but I might be the only one (it's a small company) that has an ARM64 M1 "Apple Silicon" Mac. ***However I ... | Modifying `Dockerfile` seems to be the most popular answer but you can also set the `DOCKER_DEFAULT_PLATFORM` environment variable to `linux/amd64`.
```bash
export DOCKER_DEFAULT_PLATFORM=linux/amd64
```
The cause seems to reside in the AArch64 image. |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Incidentally, in case it's helpful to another who lands here, I have the same issue on an M1 Max MacBook Pro laptop attempting to do a `docker build` from a company repo that should be a pretty well traveled path, but I might be the only one (it's a small company) that has an ARM64 M1 "Apple Silicon" Mac. ***However I ... | Provided the base image includes the target architecture, another option that might work in your case is using Docker's built-in [`TARGETARCH`](https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope) build arg. This works for me on macOS M1.
```
FROM ubuntu:focal
ARG TARGETARCH
R... |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Modifying `Dockerfile` seems to be the most popular answer but you can also set the `DOCKER_DEFAULT_PLATFORM` environment variable to `linux/amd64`.
```bash
export DOCKER_DEFAULT_PLATFORM=linux/amd64
```
The cause seems to reside in the AArch64 image. | Passing following flag to C preprocessor as `CPPFLAGS` solved similar issue in my M1
```
-DPNG_ARM_NEON_OPT=0
```
Pass the value as env var with key `CPPFLAGS` to relevant service. |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Passing following flag to C preprocessor as `CPPFLAGS` solved similar issue in my M1
```
-DPNG_ARM_NEON_OPT=0
```
Pass the value as env var with key `CPPFLAGS` to relevant service. | Provided the base image includes the target architecture, another option that might work in your case is using Docker's built-in [`TARGETARCH`](https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope) build arg. This works for me on macOS M1.
```
FROM ubuntu:focal
ARG TARGETARCH
R... |
71,040,681 | I have a Rancher Deskop(dockerd) on M1 MacOS and when I am trying to build below dockerfile I am getting an error such as below. Here is the command how I am trying to build the image `docker build -t te-grafana-dashboards-toolchain --no-cache .`
I tried to change the platforms but nonae of them worked for me. I am a ... | 2022/02/08 | [
"https://Stackoverflow.com/questions/71040681",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12530530/"
] | Modifying `Dockerfile` seems to be the most popular answer but you can also set the `DOCKER_DEFAULT_PLATFORM` environment variable to `linux/amd64`.
```bash
export DOCKER_DEFAULT_PLATFORM=linux/amd64
```
The cause seems to reside in the AArch64 image. | Provided the base image includes the target architecture, another option that might work in your case is using Docker's built-in [`TARGETARCH`](https://docs.docker.com/engine/reference/builder/#automatic-platform-args-in-the-global-scope) build arg. This works for me on macOS M1.
```
FROM ubuntu:focal
ARG TARGETARCH
R... |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | You should use a proper HTML parsing library, such as the [HTMLParser](http://docs.python.org/library/htmlparser.html) module. | ```
string = '<a href="#tips">Visit the Useful Tips Section</a>'
re.findall('<[^>]*>(.*)<[^>]*>', string) //return 'Visit the Useful Tips Section'
``` |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | You should use a proper HTML parsing library, such as the [HTMLParser](http://docs.python.org/library/htmlparser.html) module. | I understand you are trying to strip out the HTML tags and keep only the text.
You can define a regular expression that represents the tags.
Then substitute all matches with the empty string.
Example:
```
def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
```
References:
[Example]... |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | You should use a proper HTML parsing library, such as the [HTMLParser](http://docs.python.org/library/htmlparser.html) module. | You can use [`lxml`](http://lxml.de/) html parser.
```
>>> import lxml.html as lh
>>> st = ''' load your above html content into a string '''
>>> d = lh.fromstring(st)
>>> d.text_content()
'Visit the Useful Tips Section \nand I would like to get result : Visit the Useful Tips Section\n\n\nMenu\nHTML\nCSS\nand I would... |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | You should use a proper HTML parsing library, such as the [HTMLParser](http://docs.python.org/library/htmlparser.html) module. | I'd use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) - it gets much less cranky with mal-formed html. |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | ```
string = '<a href="#tips">Visit the Useful Tips Section</a>'
re.findall('<[^>]*>(.*)<[^>]*>', string) //return 'Visit the Useful Tips Section'
``` | I understand you are trying to strip out the HTML tags and keep only the text.
You can define a regular expression that represents the tags.
Then substitute all matches with the empty string.
Example:
```
def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
```
References:
[Example]... |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | ```
string = '<a href="#tips">Visit the Useful Tips Section</a>'
re.findall('<[^>]*>(.*)<[^>]*>', string) //return 'Visit the Useful Tips Section'
``` | I'd use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) - it gets much less cranky with mal-formed html. |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | You can use [`lxml`](http://lxml.de/) html parser.
```
>>> import lxml.html as lh
>>> st = ''' load your above html content into a string '''
>>> d = lh.fromstring(st)
>>> d.text_content()
'Visit the Useful Tips Section \nand I would like to get result : Visit the Useful Tips Section\n\n\nMenu\nHTML\nCSS\nand I would... | I understand you are trying to strip out the HTML tags and keep only the text.
You can define a regular expression that represents the tags.
Then substitute all matches with the empty string.
Example:
```
def remove_html_tags(data):
p = re.compile(r'<.*?>')
return p.sub('', data)
```
References:
[Example]... |
10,851,121 | I am trying to use python to extract certain information from html code.
for example:
```
<a href="#tips">Visit the Useful Tips Section</a>
and I would like to get result : Visit the Useful Tips Section
<div id="menu" style="background-color:#FFD700;height:200px;width:100px;float:left;">
<b>Menu</b><br />
HTML<br />... | 2012/06/01 | [
"https://Stackoverflow.com/questions/10851121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1401233/"
] | You can use [`lxml`](http://lxml.de/) html parser.
```
>>> import lxml.html as lh
>>> st = ''' load your above html content into a string '''
>>> d = lh.fromstring(st)
>>> d.text_content()
'Visit the Useful Tips Section \nand I would like to get result : Visit the Useful Tips Section\n\n\nMenu\nHTML\nCSS\nand I would... | I'd use [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) - it gets much less cranky with mal-formed html. |
2,509,927 | i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful.... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2509927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275695/"
] | You can use the [system](http://www.mathworks.com/access/helpdesk/help/techdoc/ref/system.html) command to execute the Python code externally. To link it in more "natively" I think you'll have to go through C. That is, embed your Python code in C code and then expose it with a DLL to Matlab.
P.S. On windows you can al... | There is a library called [PyMat](http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html). It allows to call python code from matlab. |
2,509,927 | i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful.... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2509927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275695/"
] | You should probably avoid this. Use one or the other - preferably Python.
But if you have to use both, you could try this:
<http://github.com/kw/pymex> (scroll down for the readme)
Disclaimer: I wrote this. It may be somewhat difficult to get it to compile and work, particularly if you're on Windows (there is a pre-c... | You can use the [system](http://www.mathworks.com/access/helpdesk/help/techdoc/ref/system.html) command to execute the Python code externally. To link it in more "natively" I think you'll have to go through C. That is, embed your Python code in C code and then expose it with a DLL to Matlab.
P.S. On windows you can al... |
2,509,927 | i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful.... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2509927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275695/"
] | The only thing I know of is pythoncall but it is a little out of date and I'm not sure it will work reliably with recent versions of matlab.
<http://www.elisanet.fi/ptvirtan/software/pythoncall/index.html>
Otherwise you would have to interact with matlab through the shell (a bit of a pain I know). If you are dealing ... | There is a library called [PyMat](http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html). It allows to call python code from matlab. |
2,509,927 | i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful.... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2509927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275695/"
] | You should probably avoid this. Use one or the other - preferably Python.
But if you have to use both, you could try this:
<http://github.com/kw/pymex> (scroll down for the readme)
Disclaimer: I wrote this. It may be somewhat difficult to get it to compile and work, particularly if you're on Windows (there is a pre-c... | There is a library called [PyMat](http://claymore.engineer.gvsu.edu/~steriana/Python/pymat.html). It allows to call python code from matlab. |
2,509,927 | i have some python code(some functions) and i want to implement this in bigger matlab program!how can i do this?any help will be useful.... | 2010/03/24 | [
"https://Stackoverflow.com/questions/2509927",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/275695/"
] | You should probably avoid this. Use one or the other - preferably Python.
But if you have to use both, you could try this:
<http://github.com/kw/pymex> (scroll down for the readme)
Disclaimer: I wrote this. It may be somewhat difficult to get it to compile and work, particularly if you're on Windows (there is a pre-c... | The only thing I know of is pythoncall but it is a little out of date and I'm not sure it will work reliably with recent versions of matlab.
<http://www.elisanet.fi/ptvirtan/software/pythoncall/index.html>
Otherwise you would have to interact with matlab through the shell (a bit of a pain I know). If you are dealing ... |
39,136,134 | **cat test.py**
```
from importlib import import_module
bar = import_module('bar', package='project')
```
**ls project/**
```
__init__.py
__init__.pyc
bar.py
bar.pyc
```
**python test.py**
```
Traceback (most recent call last):
File "test.py", line 5, in <module>
bar = import_module('bar', package='pro... | 2016/08/25 | [
"https://Stackoverflow.com/questions/39136134",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1252307/"
] | It needs a dot in front of bar .. :-(
```
bar = import_module('.bar', package='project')
``` | The documentation for [import\_lib](https://docs.python.org/2/library/importlib.html) says that
>
> If the name is specified in relative terms, then the package argument must be specified to the package which is to act as the anchor for resolving the package name (e.g. import\_module('..mod', 'pkg.subpkg') will impo... |
43,600,114 | Im using python 3.4 and I am trying to make a recursive guessing game. The game should take a min value and a max value and have a "magic" number. The game is going to generate a random number in between the range of x and y. Then ask the user to insert y for yes l for too low, and h for too high. if it is yes 'congrat... | 2017/04/25 | [
"https://Stackoverflow.com/questions/43600114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7916637/"
] | This can be done with a simple function using four `if` statements to avoid adding out-of-bounds values:
```
#include <stdio.h>
#define BOARD_SZ 10
int sum_neighborhood(int, int, int [][BOARD_SZ], int, int);
int main(void)
{
int board[BOARD_SZ][BOARD_SZ] = { { 1, 0, 0, 1, 1, 1, 1, 1, 0, 1 },
... | ```
int add(const int **arr, size_t nrows, size_t ncols)
{
int sum = 0;
for (size_t i = 0; i < nrows; ++i)
for (size_t j = 0; j < ncols; ++j)
sum += arr[i][j];
return sum;
}
```
Use a pair of nested loops to walk the rows and columns. |
43,600,114 | Im using python 3.4 and I am trying to make a recursive guessing game. The game should take a min value and a max value and have a "magic" number. The game is going to generate a random number in between the range of x and y. Then ask the user to insert y for yes l for too low, and h for too high. if it is yes 'congrat... | 2017/04/25 | [
"https://Stackoverflow.com/questions/43600114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7916637/"
] | This can be done with a simple function using four `if` statements to avoid adding out-of-bounds values:
```
#include <stdio.h>
#define BOARD_SZ 10
int sum_neighborhood(int, int, int [][BOARD_SZ], int, int);
int main(void)
{
int board[BOARD_SZ][BOARD_SZ] = { { 1, 0, 0, 1, 1, 1, 1, 1, 0, 1 },
... | One easy approach is to only consider values with valid indices, but iterate over the entire square around a given index `i`, `j`. Thus:
```
typedef struct {
int ** data; ///< data in row order
int rows, columns; ///< size of the data
} Array;
/// arr - pointer to the data
/// i, j - row and column to add ... |
11,463,749 | I visited <http://www.sublimetext.com> today and was intrigued by the screencast animation the website has on its opening page. It looks like a mashup between video and slideshow. I've seen them at other modern websites as well, but I assumed it was some HTML5 video tag trickery. But when I looked at the source of subl... | 2012/07/13 | [
"https://Stackoverflow.com/questions/11463749",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/174527/"
] | Jon Skinner, the creator of Sublime Text wrote about the process [on his website](http://www.sublimetext.com/~jps/animated_gifs_the_hard_way.html)
He also published the encoder he wrote [on GitHub](https://github.com/sublimehq/anim_encoder) | look at one of their images and you'll understand how it works:
<http://www.sublimetext.com/anim/command_palette_packed.png>
they just cutting and inserting appropriate portions of image into the appropriate positions of canvas element, but if your question is how to make such image, I don't have an idea.
I guess wit... |
52,678,981 | I'm new to programing on python and working with scrapy. I am facing an error with the web crawling. I have used similar help pages on this site and even followed a tutorial from beginning to end to no avail, any help will be appreciated.
Error says: Spider error processing http://quotes.toscrape.com/> (referer: None)... | 2018/10/06 | [
"https://Stackoverflow.com/questions/52678981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10465578/"
] | The problem is your command prompt uses [cp437](https://en.wikipedia.org/wiki/Code_page_437) character set, which doesn't support some characters that you have just scraped (for example, “ and ”)
I don't think it is possible to print that characters to windows shell (maybe new PowerShells support it, I don't know). Yo... | I change a little my code and its work the way expected here is updated code:
```
#-*- coding: utf-8 -*-
import scrapy
class QuotesSpider(scrapy.Spider):
name = "quotes"
allowed_domains = ["quotes.toscrape.com"]
start_urls = (
'http://quotes.toscrape.com/',
)
def parse(self, response):
... |
356,138 | I'm having a very peculiar problem in my Python FastCGI code - sys.stdout has a file descriptor of '-1', so I can't write to it.
I'm checking this at the first line of my program, so I know it's not any of my code changing it.
I've tried `sys.stdout = os.fdopen(1, 'w')`, but anything written there won't get to my brow... | 2008/12/10 | [
"https://Stackoverflow.com/questions/356138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44992/"
] | Forgive me if this is a dumb question, but I notice this line in your config file:
>
> Arguments=-u C:\app\app\_wsgi.py
>
>
>
Are you running a WSGI application or a FastCGI app? There *is* a difference. In WSGI, writing to stdout isn't a good idea. Your program should have an application object that can be calle... | On windows, it's possible to launch a proces without a valid stdin and stdout. For example, if you execute a python script with pythonw.exe, the stdout is invdalid and if you insist on writing to it, it will block after 140 characters or something.
Writing to another destination than stdout looks like the safest solut... |
356,138 | I'm having a very peculiar problem in my Python FastCGI code - sys.stdout has a file descriptor of '-1', so I can't write to it.
I'm checking this at the first line of my program, so I know it's not any of my code changing it.
I've tried `sys.stdout = os.fdopen(1, 'w')`, but anything written there won't get to my brow... | 2008/12/10 | [
"https://Stackoverflow.com/questions/356138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44992/"
] | Forgive me if this is a dumb question, but I notice this line in your config file:
>
> Arguments=-u C:\app\app\_wsgi.py
>
>
>
Are you running a WSGI application or a FastCGI app? There *is* a difference. In WSGI, writing to stdout isn't a good idea. Your program should have an application object that can be calle... | Following the PEP 333 you can try to log to environ['wsgi.errors'] which is usualy the logger of the web server itself when you use fastcgi. Of course this is only available when a request is called but not during application startup.
You can get an example in the pylons code: <http://pylonshq.com/docs/en/0.9.7/loggin... |
356,138 | I'm having a very peculiar problem in my Python FastCGI code - sys.stdout has a file descriptor of '-1', so I can't write to it.
I'm checking this at the first line of my program, so I know it's not any of my code changing it.
I've tried `sys.stdout = os.fdopen(1, 'w')`, but anything written there won't get to my brow... | 2008/12/10 | [
"https://Stackoverflow.com/questions/356138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44992/"
] | Do you have to use FastCGI? If not, you may want to try a ISAPI WSGI method. I have had success using:
<http://code.google.com/p/isapi-wsgi/>
and have also used PyISAPIe in the past:
<http://sourceforge.net/apps/trac/pyisapie> | On windows, it's possible to launch a proces without a valid stdin and stdout. For example, if you execute a python script with pythonw.exe, the stdout is invdalid and if you insist on writing to it, it will block after 140 characters or something.
Writing to another destination than stdout looks like the safest solut... |
356,138 | I'm having a very peculiar problem in my Python FastCGI code - sys.stdout has a file descriptor of '-1', so I can't write to it.
I'm checking this at the first line of my program, so I know it's not any of my code changing it.
I've tried `sys.stdout = os.fdopen(1, 'w')`, but anything written there won't get to my brow... | 2008/12/10 | [
"https://Stackoverflow.com/questions/356138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44992/"
] | I believe having stdout closed/invalid is in accordance to the [FastCGI spec](http://www.fastcgi.com/devkit/doc/fcgi-spec.html):
>
> The Web server leaves a single file
> descriptor, FCGI\_LISTENSOCK\_FILENO,
> open when the application begins
> execution. This descriptor refers to a
> listening socket created by... | On windows, it's possible to launch a proces without a valid stdin and stdout. For example, if you execute a python script with pythonw.exe, the stdout is invdalid and if you insist on writing to it, it will block after 140 characters or something.
Writing to another destination than stdout looks like the safest solut... |
356,138 | I'm having a very peculiar problem in my Python FastCGI code - sys.stdout has a file descriptor of '-1', so I can't write to it.
I'm checking this at the first line of my program, so I know it's not any of my code changing it.
I've tried `sys.stdout = os.fdopen(1, 'w')`, but anything written there won't get to my brow... | 2008/12/10 | [
"https://Stackoverflow.com/questions/356138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44992/"
] | Do you have to use FastCGI? If not, you may want to try a ISAPI WSGI method. I have had success using:
<http://code.google.com/p/isapi-wsgi/>
and have also used PyISAPIe in the past:
<http://sourceforge.net/apps/trac/pyisapie> | Following the PEP 333 you can try to log to environ['wsgi.errors'] which is usualy the logger of the web server itself when you use fastcgi. Of course this is only available when a request is called but not during application startup.
You can get an example in the pylons code: <http://pylonshq.com/docs/en/0.9.7/loggin... |
356,138 | I'm having a very peculiar problem in my Python FastCGI code - sys.stdout has a file descriptor of '-1', so I can't write to it.
I'm checking this at the first line of my program, so I know it's not any of my code changing it.
I've tried `sys.stdout = os.fdopen(1, 'w')`, but anything written there won't get to my brow... | 2008/12/10 | [
"https://Stackoverflow.com/questions/356138",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44992/"
] | I believe having stdout closed/invalid is in accordance to the [FastCGI spec](http://www.fastcgi.com/devkit/doc/fcgi-spec.html):
>
> The Web server leaves a single file
> descriptor, FCGI\_LISTENSOCK\_FILENO,
> open when the application begins
> execution. This descriptor refers to a
> listening socket created by... | Following the PEP 333 you can try to log to environ['wsgi.errors'] which is usualy the logger of the web server itself when you use fastcgi. Of course this is only available when a request is called but not during application startup.
You can get an example in the pylons code: <http://pylonshq.com/docs/en/0.9.7/loggin... |
41,231,316 | I've been trying to write this reduce method and I can't find a nice way to do it in java. I managed in python but it makes use of lots of python stuff and porting that to java seems like a real pain. Is there a more java way to do it?
Here's some test code, that should show what I mean if the title wasn't clear.
My ... | 2016/12/19 | [
"https://Stackoverflow.com/questions/41231316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4058774/"
] | Not sure about "nice", but it works:
```
public static <T> T[] reduce(T[] duplicated)
{
int len = duplicated.length;
for (int i = 1; i <= len / 2; i++) {
if (len % i == 0) {
if (checkFactors(i, duplicated)) {
return Arrays.copyOf(duplicated, i);
}
}
}... | So you want to test if an array is a smaller array repeated - now if, by your definition, `bigArray.length % smallArray.length != 0` means that it is NOT the smaller array repeated, I can give you a solution. In other words: If the smaller array doesn't fit inside the bigger array an even number of times, does that mea... |
41,231,316 | I've been trying to write this reduce method and I can't find a nice way to do it in java. I managed in python but it makes use of lots of python stuff and porting that to java seems like a real pain. Is there a more java way to do it?
Here's some test code, that should show what I mean if the title wasn't clear.
My ... | 2016/12/19 | [
"https://Stackoverflow.com/questions/41231316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4058774/"
] | Not sure about "nice", but it works:
```
public static <T> T[] reduce(T[] duplicated)
{
int len = duplicated.length;
for (int i = 1; i <= len / 2; i++) {
if (len % i == 0) {
if (checkFactors(i, duplicated)) {
return Arrays.copyOf(duplicated, i);
}
}
}... | How about this? Return value is 0 = not a duplicate, 1 = same, 2 = repeated once, 3 = repeated twice etc
```
public int FindDuplicates(Integer[] a, Integer[] b)
{
int bigIndex = 0;
int smallIndex = 0;
int duplicates = 0;
if(b.length % a.length == 0)
while(bigIndex < b.length)
{
if(a[sm... |
46,028,830 | I've been fooling around with `__slots__` and searching about them a little, but I'm still confused about some specifics:
I'm aware that `__slots__` generates some kind of descriptors:
```py
>>> class C:
... __slots__ = ('x',)
...
>>> C.x
<member 'x' of 'C' objects>
>>> C.x.__get__
<method-wrapper '__get__' of ... | 2017/09/04 | [
"https://Stackoverflow.com/questions/46028830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7770274/"
] | >
> Where are actually storerd the values (since there is no dict) ? I was thinking it's something implemented in C and not directly accessible with Python code.
>
>
>
Memory is allocated for the `PyObject *` pointers directly in the object itself. You can see the handling in [`Objects/typeobject.c`](https://githu... | looking at your overall outlook, I've been working on performative solutions for custom setters on member descriptors for some time now, and this is the best I've come up with so far:
(tested with Anaconda 2.3.0 (Python 3.4.3) on wine, and Python 3.5.2 on linux)
**Note: This solution does not attempt to be pythonic... |
65,767,823 | I am new to using terminal in Mac. When I type any python3 command it only checks the users folder on my PC, HOW can I change the directory to open a folder in the users section and check for the .py file there? | 2021/01/18 | [
"https://Stackoverflow.com/questions/65767823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15026906/"
] | Access the desired path using `cd` command
```
cd path/to/access
```
Then you can run the python command to run the scripts. | If you know the name of the folder in which you want to check, you can change the current python directory using: `os.chdir`
<https://docs.python.org/3/library/os.html#os.chdir>
In that case it doesn't matter from where you're running your python script. |
65,767,823 | I am new to using terminal in Mac. When I type any python3 command it only checks the users folder on my PC, HOW can I change the directory to open a folder in the users section and check for the .py file there? | 2021/01/18 | [
"https://Stackoverflow.com/questions/65767823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15026906/"
] | Access the desired path using `cd` command
```
cd path/to/access
```
Then you can run the python command to run the scripts. | You can use the **OS** library which comes shipped with Python.
to change the current directory inside the script, you can simply write:
```
import os
os.chdir("newDir/")
```
if you should want to get all directories which are in the user's current location, you can use the method:
```
os.listdir()
```
Hope that... |
65,767,823 | I am new to using terminal in Mac. When I type any python3 command it only checks the users folder on my PC, HOW can I change the directory to open a folder in the users section and check for the .py file there? | 2021/01/18 | [
"https://Stackoverflow.com/questions/65767823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15026906/"
] | Access the desired path using `cd` command
```
cd path/to/access
```
Then you can run the python command to run the scripts. | You have to use the command cd to your folder first. |
62,292,262 | I am making a simple program in Python and I want from one file import a class that I made in another class. My code is the following:
```
#file cPoint.py
import math
class Point:
def __init__(self,x,y):
self.x=x
self.y=y
def printC(self):
print ("(",self.x,",",self.y,")")
```
and my... | 2020/06/09 | [
"https://Stackoverflow.com/questions/62292262",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1960266/"
] | Create another row above your column title with the following formula. This will isolate the number, which can then be sorted according to its numerical value (tested, see screenshot below):
```
=LEFT(RIGHT(A3;LEN(A3)-16);LEN(A3)-21)
```
[](https://... | Try putting a zero in front of the single digits. Pad with more zeros if you have higher numbers.
56g\_flux\_data39(01)1992, 56g\_flux\_data39(02)1992, 56g\_flux\_data39(03)1992, all the way to 56g\_flux\_data39(11)1992 |
61,169,193 | I have a python code that prints Arabic text on vscode terminal, the output in the terminal appears in "unreadable" format.
code:
```
print('مرحبا')
```
output:
```
مرحبا
```
How can I solve this issue? | 2020/04/12 | [
"https://Stackoverflow.com/questions/61169193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3261292/"
] | to have a `String` variable formatted as {"Head1","Head2","Head3";1,2,3;4,5,6;7,8,9}, you can do as follows
```
Dim sValue As String, r As Range
For Each r In ThisWorkbook.Names("MyRange").RefersToRange.Rows
sValue = sValue & Join(Application.Transpose(Application.Transpose(r.Value)), ",") & ";"
Ne... | I think you are looking for
```
sValue = ThisWorkbook.Names("MyRange"),name
```
to find all names on Activesheet:
```
Sub test_names()
Dim wsName As String
wsName = ActiveSheet.Name
Dim nameRange As Variant
For Each nameRange In ThisWorkbook.Names
Set rngName = Range(nameRange)
wsP... |
16,569,784 | I'm using a *private* view in my Django project for an AJAX request.
```python
def HereIsSomeJSON(request, label):
if not request.method == "POST":
raise PermissionDenied
# Here is the job of my AJAX, basically feeding a JSON
json = {...}
return HttpResponse(json, "application/json")
```
Usi... | 2013/05/15 | [
"https://Stackoverflow.com/questions/16569784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1824222/"
] | Your approach of requiring POST for your ajax views is basically OK, and there is an [existing decorator](https://docs.djangoproject.com/en/dev/topics/http/decorators/) to handle it:
```
from django.views.decorators.http import require_POST
@require_POST
def my_view(request):
# I can assume now that only POST req... | As [@armonge](https://stackoverflow.com/users/407762/armonge) said, just checking for POST method doesn't do any protection. Suppose you need some checks, that user is registered and maybe have some permissions or needed properties. For this purpose, such decorator can be used (probably needs to be customized):
```
de... |
16,569,784 | I'm using a *private* view in my Django project for an AJAX request.
```python
def HereIsSomeJSON(request, label):
if not request.method == "POST":
raise PermissionDenied
# Here is the job of my AJAX, basically feeding a JSON
json = {...}
return HttpResponse(json, "application/json")
```
Usi... | 2013/05/15 | [
"https://Stackoverflow.com/questions/16569784",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1824222/"
] | Your approach of requiring POST for your ajax views is basically OK, and there is an [existing decorator](https://docs.djangoproject.com/en/dev/topics/http/decorators/) to handle it:
```
from django.views.decorators.http import require_POST
@require_POST
def my_view(request):
# I can assume now that only POST req... | I figured out that requiring POST is not enough, one could possibly cheat using `curl` for example.
That is why a custom decorator is - in my opinion - the way to go.
```py
from django.http import HttpResponseBadRequest
def require_AJAX(function):
"""Return a bad request instance if the view is not using AJAX
... |
5,523,279 | it seems that I have some trouble understanding the semantics of the SUID bit, perhaps someone can help me clarify the situation.
My understanding of the semantic of the SUID bit are as follows:
When I set the SUID bit with a file, then the file will be executed as the owner of the file and not as the caller of the fi... | 2011/04/02 | [
"https://Stackoverflow.com/questions/5523279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/350403/"
] | Setting the SUID bit on a \*.py file does not help in any way here since the script is executed by the Python interpreter which must be set SUID in this case. Using 'sudo' is your better friend here. | Setting SUID does not work for scripts, because the kernel sees the #! (shebang - magic number 0x23 0x21 - man magic) and drops the privileges before calling the interpreter /usr/bin/python with the script as input. A way around is setting the python interpreter SUID root and add functionality to change privileges to t... |
5,523,279 | it seems that I have some trouble understanding the semantics of the SUID bit, perhaps someone can help me clarify the situation.
My understanding of the semantic of the SUID bit are as follows:
When I set the SUID bit with a file, then the file will be executed as the owner of the file and not as the caller of the fi... | 2011/04/02 | [
"https://Stackoverflow.com/questions/5523279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/350403/"
] | Setting the SUID bit on a \*.py file does not help in any way here since the script is executed by the Python interpreter which must be set SUID in this case. Using 'sudo' is your better friend here. | I found this [link](http://selliott.org/python/suid-python.c) in the web. you can set SUID to this wrapper and use this one.
but personally prefer sudo solution. ;) |
5,523,279 | it seems that I have some trouble understanding the semantics of the SUID bit, perhaps someone can help me clarify the situation.
My understanding of the semantic of the SUID bit are as follows:
When I set the SUID bit with a file, then the file will be executed as the owner of the file and not as the caller of the fi... | 2011/04/02 | [
"https://Stackoverflow.com/questions/5523279",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/350403/"
] | Setting SUID does not work for scripts, because the kernel sees the #! (shebang - magic number 0x23 0x21 - man magic) and drops the privileges before calling the interpreter /usr/bin/python with the script as input. A way around is setting the python interpreter SUID root and add functionality to change privileges to t... | I found this [link](http://selliott.org/python/suid-python.c) in the web. you can set SUID to this wrapper and use this one.
but personally prefer sudo solution. ;) |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | You can do something like this perhaps:
```
file1 = [[224,43,234],[22,5,224],[234,254,220]]
for idx, inner_list in enumerate(file1):
print('max_'+str(idx+1)+' : '+str(max(inner_list)))
``` | You said you have a data frame, so I assume it's a `pandas` `DataFrame` object.
In which case, you can use list comprehension to take the max from each sub-list in the list, and assign each element to a new column (this loop isn't elegant but will work):
```
df['max_colors'] = df['RGB'].apply(lambda x: [np.max(color)... |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | I'll assume that you want the max values of R, G and B respectively.
If you want this then, here is one way to do it:
```
a = np.array([ [224,43,234], [22,5,224], [234,254,220]])
r_max = a.T[0].max()
g_max = a.T[1].max()
b_max = a.T[2].max()
``` | You can do something like this perhaps:
```
file1 = [[224,43,234],[22,5,224],[234,254,220]]
for idx, inner_list in enumerate(file1):
print('max_'+str(idx+1)+' : '+str(max(inner_list)))
``` |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | Using `list-comprehension`:
```
a = np.array([[224,43,234], [22,5,224], [234,254,220]])
print([x.max() for x in a])
```
**OUTPUT**:
```
[234, 224, 254]
``` | Solved the problem like this. Thanks for having all the answers.
```
df['max_1'] = 0
df['max_2'] = 0
df['max_3'] = 0
for i in range(5):
df['max_1'][i] = df['RGB'][i][0].max()
df['max_2'][i] = df['RGB'][i][1].max()
df['max_3'][i] = df['RGB'][i][2].max()
``` |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | Another way:
```
import numpy as np
a=np.array([[1,2,3],[11,12,13],[21,22,23]])
print(a)
maxInRows = np.amax(a, axis=1)
print('Max value of every Row: ', maxInRows)
``` | You said you have a data frame, so I assume it's a `pandas` `DataFrame` object.
In which case, you can use list comprehension to take the max from each sub-list in the list, and assign each element to a new column (this loop isn't elegant but will work):
```
df['max_colors'] = df['RGB'].apply(lambda x: [np.max(color)... |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | I'll assume that you want the max values of R, G and B respectively.
If you want this then, here is one way to do it:
```
a = np.array([ [224,43,234], [22,5,224], [234,254,220]])
r_max = a.T[0].max()
g_max = a.T[1].max()
b_max = a.T[2].max()
``` | Another way:
```
import numpy as np
a=np.array([[1,2,3],[11,12,13],[21,22,23]])
print(a)
maxInRows = np.amax(a, axis=1)
print('Max value of every Row: ', maxInRows)
``` |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | I'll assume that you want the max values of R, G and B respectively.
If you want this then, here is one way to do it:
```
a = np.array([ [224,43,234], [22,5,224], [234,254,220]])
r_max = a.T[0].max()
g_max = a.T[1].max()
b_max = a.T[2].max()
``` | You said you have a data frame, so I assume it's a `pandas` `DataFrame` object.
In which case, you can use list comprehension to take the max from each sub-list in the list, and assign each element to a new column (this loop isn't elegant but will work):
```
df['max_colors'] = df['RGB'].apply(lambda x: [np.max(color)... |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | Another way:
```
import numpy as np
a=np.array([[1,2,3],[11,12,13],[21,22,23]])
print(a)
maxInRows = np.amax(a, axis=1)
print('Max value of every Row: ', maxInRows)
``` | Solved the problem like this. Thanks for having all the answers.
```
df['max_1'] = 0
df['max_2'] = 0
df['max_3'] = 0
for i in range(5):
df['max_1'][i] = df['RGB'][i][0].max()
df['max_2'][i] = df['RGB'][i][1].max()
df['max_3'][i] = df['RGB'][i][2].max()
``` |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | I'll assume that you want the max values of R, G and B respectively.
If you want this then, here is one way to do it:
```
a = np.array([ [224,43,234], [22,5,224], [234,254,220]])
r_max = a.T[0].max()
g_max = a.T[1].max()
b_max = a.T[2].max()
``` | Solved the problem like this. Thanks for having all the answers.
```
df['max_1'] = 0
df['max_2'] = 0
df['max_3'] = 0
for i in range(5):
df['max_1'][i] = df['RGB'][i][0].max()
df['max_2'][i] = df['RGB'][i][1].max()
df['max_3'][i] = df['RGB'][i][2].max()
``` |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | Using `list-comprehension`:
```
a = np.array([[224,43,234], [22,5,224], [234,254,220]])
print([x.max() for x in a])
```
**OUTPUT**:
```
[234, 224, 254]
``` | Another way:
```
import numpy as np
a=np.array([[1,2,3],[11,12,13],[21,22,23]])
print(a)
maxInRows = np.amax(a, axis=1)
print('Max value of every Row: ', maxInRows)
``` |
55,683,072 | Actually, i'm very new to python and working on some image problem statement. Stuck in a problem and not able to get out of this.
I have data frame like:
```
Image RGB max_1 max_2 max_3
file1 [[224,43,234][22,5,224][234,254,220]] 234 224 254
file2 [[22,143,113][221,12... | 2019/04/15 | [
"https://Stackoverflow.com/questions/55683072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7721819/"
] | Using `list-comprehension`:
```
a = np.array([[224,43,234], [22,5,224], [234,254,220]])
print([x.max() for x in a])
```
**OUTPUT**:
```
[234, 224, 254]
``` | You can do something like this perhaps:
```
file1 = [[224,43,234],[22,5,224],[234,254,220]]
for idx, inner_list in enumerate(file1):
print('max_'+str(idx+1)+' : '+str(max(inner_list)))
``` |
59,333,904 | (I'm very new to both python and stackoverflow.)
```
def A():
def B():
print("I'm B")
A.B = B
A()
A.B()
```
output:
```
"I'm B"
```
This works well. What I want is to put that in a class like this(doesn't work. I just tried..)
```
class Student:
def A(self):
def B():
prin... | 2019/12/14 | [
"https://Stackoverflow.com/questions/59333904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12386013/"
] | You don't need to reference *self* because the inner function *B* is defined there. It should be like this:
```
class Student:
def A(self):
def B():
print("I'm B")
B()
``` | I never use classes, but could you do it this way?
```
class A:
def __call__(self): // so you can call it like a function
def B():
print("i am B")
B()
call_A = A() // make the class callable
call_A() ... |
59,333,904 | (I'm very new to both python and stackoverflow.)
```
def A():
def B():
print("I'm B")
A.B = B
A()
A.B()
```
output:
```
"I'm B"
```
This works well. What I want is to put that in a class like this(doesn't work. I just tried..)
```
class Student:
def A(self):
def B():
prin... | 2019/12/14 | [
"https://Stackoverflow.com/questions/59333904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12386013/"
] | Python functions are `first-class objects`. [What is first class function in Python](https://stackoverflow.com/questions/27392402/what-is-first-class-function-in-python)
So the first piece of code is perfectly valid. It just adds a property `B` to the function, which can later be called using `A.B()`.
But for the sec... | You don't need to reference *self* because the inner function *B* is defined there. It should be like this:
```
class Student:
def A(self):
def B():
print("I'm B")
B()
``` |
59,333,904 | (I'm very new to both python and stackoverflow.)
```
def A():
def B():
print("I'm B")
A.B = B
A()
A.B()
```
output:
```
"I'm B"
```
This works well. What I want is to put that in a class like this(doesn't work. I just tried..)
```
class Student:
def A(self):
def B():
prin... | 2019/12/14 | [
"https://Stackoverflow.com/questions/59333904",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12386013/"
] | Python functions are `first-class objects`. [What is first class function in Python](https://stackoverflow.com/questions/27392402/what-is-first-class-function-in-python)
So the first piece of code is perfectly valid. It just adds a property `B` to the function, which can later be called using `A.B()`.
But for the sec... | I never use classes, but could you do it this way?
```
class A:
def __call__(self): // so you can call it like a function
def B():
print("i am B")
B()
call_A = A() // make the class callable
call_A() ... |
21,175,923 | The problem I am tackle with is to find the first occurrence node in its inorder traversal in a BST.
The code I have is given below
```
def Inorder_search_recursive(node,key):
if not node:
return None
InOrder_search_recursive(node.lChild)
if node.value==key:
return node
InOrder_search_... | 2014/01/17 | [
"https://Stackoverflow.com/questions/21175923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1824922/"
] | When you call yourself recursively, like this:
```
InOrder_search_recursive(node.lChild)
```
That's just a normal function call, like any other. It just calls the function and gets back a result. It doesn't automatically `return` the value from that function, or do anything else.
So, you do the left-subtree search,... | Since your problem is `to find the first occurrence node in its inorder traversal`, you should 1) traverse the tree in-order and 2) stop when you find the first occurrence.
```
def search(node, key):
if node is None:
return None
# Search the left subtree and return early if key is found
n = search(... |
21,175,923 | The problem I am tackle with is to find the first occurrence node in its inorder traversal in a BST.
The code I have is given below
```
def Inorder_search_recursive(node,key):
if not node:
return None
InOrder_search_recursive(node.lChild)
if node.value==key:
return node
InOrder_search_... | 2014/01/17 | [
"https://Stackoverflow.com/questions/21175923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1824922/"
] | When you call yourself recursively, like this:
```
InOrder_search_recursive(node.lChild)
```
That's just a normal function call, like any other. It just calls the function and gets back a result. It doesn't automatically `return` the value from that function, or do anything else.
So, you do the left-subtree search,... | My other answer gives the novice-friendly solution, but if you want more powerful and concise answer:
```
def Inorder_search_recursive_all(node, key):
if not node:
return
yield from InOrder_search_recursive(node.lChild, key)
if node.value==key:
yield node
yield from InOrder_search_recur... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | You didn't show a full output. It probably looks like
```
$ gunicorn elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1
[2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429)
[2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync
[2015-10-27 21:01:47 +0... | For anyone facing the same issue, the problem is usually something in django itself.
Activate your venv and run ./manage.py runserver
This will usually give you a more detailed error message. |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | run guncorn with --preload can see the error log, like this
```
gunicorn app:application --preload -b 0.0.0.0:5000
```
This will usually give you a more detailed error message. | I got the very same error.
[Gunicorn](http://gunicorn.org/) was working when executed as root, but failed this way when executed as non-privileged user.
In my case I install the 'dataset' python module with 'pip install dataset' and it screwed the permissions on `/usr/lib/python2.7/site-packages/dataset` to be readable... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | run guncorn with --preload can see the error log, like this
```
gunicorn app:application --preload -b 0.0.0.0:5000
```
This will usually give you a more detailed error message. | I also had a similar error in Ubuntu 16.04, Django 1.11, using systemd.
My problem was that I had split my settings out into separate files; ie: instead of having all settings in project/settings.py, I have a few settings files like project/settings/dev.py.
I had to update DJANGO\_SETTINGS\_MODULE in the project/wsgi... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | For anyone facing the same issue, the problem is usually something in django itself.
Activate your venv and run ./manage.py runserver
This will usually give you a more detailed error message. | I got the very same error.
[Gunicorn](http://gunicorn.org/) was working when executed as root, but failed this way when executed as non-privileged user.
In my case I install the 'dataset' python module with 'pip install dataset' and it screwed the permissions on `/usr/lib/python2.7/site-packages/dataset` to be readable... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | You didn't show a full output. It probably looks like
```
$ gunicorn elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1
[2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429)
[2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync
[2015-10-27 21:01:47 +0... | I also had a similar error in Ubuntu 16.04, Django 1.11, using systemd.
My problem was that I had split my settings out into separate files; ie: instead of having all settings in project/settings.py, I have a few settings files like project/settings/dev.py.
I had to update DJANGO\_SETTINGS\_MODULE in the project/wsgi... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | You didn't show a full output. It probably looks like
```
$ gunicorn elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1
[2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429)
[2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync
[2015-10-27 21:01:47 +0... | I got the very same error.
[Gunicorn](http://gunicorn.org/) was working when executed as root, but failed this way when executed as non-privileged user.
In my case I install the 'dataset' python module with 'pip install dataset' and it screwed the permissions on `/usr/lib/python2.7/site-packages/dataset` to be readable... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | run guncorn with --preload can see the error log, like this
```
gunicorn app:application --preload -b 0.0.0.0:5000
```
This will usually give you a more detailed error message. | For anyone facing the same issue, the problem is usually something in django itself.
Activate your venv and run ./manage.py runserver
This will usually give you a more detailed error message. |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | Actually the problem here was the wsgi file itself, previously before django 1.3 the wsgi file was named with an extension of `.wsgi`, but now in the recent versions it will be created with and extension of `.py` that is the wsgi file must be a python module
so the file should be `hello_wsgi.py` and command should be
... | You didn't show a full output. It probably looks like
```
$ gunicorn elcarweb.wsgi
[2015-10-27 21:01:47 +0000] [5429] [INFO] Starting gunicorn 19.2.1
[2015-10-27 21:01:47 +0000] [5429] [INFO] Listening at: http://127.0.0.1:8000 (5429)
[2015-10-27 21:01:47 +0000] [5429] [INFO] Using worker: sync
[2015-10-27 21:01:47 +0... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | Actually the problem here was the wsgi file itself, previously before django 1.3 the wsgi file was named with an extension of `.wsgi`, but now in the recent versions it will be created with and extension of `.py` that is the wsgi file must be a python module
so the file should be `hello_wsgi.py` and command should be
... | I also had a similar error in Ubuntu 16.04, Django 1.11, using systemd.
My problem was that I had split my settings out into separate files; ie: instead of having all settings in project/settings.py, I have a few settings files like project/settings/dev.py.
I had to update DJANGO\_SETTINGS\_MODULE in the project/wsgi... |
24,488,891 | I have a django app and trying to set it up with gunicorn first and later with supervisor and nginx.
The app is running with the normal django command perfectly like `python manage.py runserver`
I installed the gunicorn using pip like `pip install gunicorn` and django version is `1.5.3`
when i run the below command ... | 2014/06/30 | [
"https://Stackoverflow.com/questions/24488891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1342109/"
] | For anyone facing the same issue, the problem is usually something in django itself.
Activate your venv and run ./manage.py runserver
This will usually give you a more detailed error message. | I also had a similar error in Ubuntu 16.04, Django 1.11, using systemd.
My problem was that I had split my settings out into separate files; ie: instead of having all settings in project/settings.py, I have a few settings files like project/settings/dev.py.
I had to update DJANGO\_SETTINGS\_MODULE in the project/wsgi... |
2,337,216 | Besides wrapping all your code in `try` `except`, is there any way of achieving the same thing as running your script like `python -mpdb script`? I'd like to be able to see what went wrong when an exception gets raised. | 2010/02/25 | [
"https://Stackoverflow.com/questions/2337216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] | If you do not want to modify the source then yOu could run it from [ipython](http://ipython.scipy.org/moin/) - an enhanced interactive python shell.
e.g. run ipython then execute `%pdb on` to enable post-mortem debugging. `%run scriptname` will then run the script and automatically enter the debugger on any uncaught e... | `import pdb; pdb.set_trace()`
Source: <http://docs.python.org/library/pdb.html> |
2,337,216 | Besides wrapping all your code in `try` `except`, is there any way of achieving the same thing as running your script like `python -mpdb script`? I'd like to be able to see what went wrong when an exception gets raised. | 2010/02/25 | [
"https://Stackoverflow.com/questions/2337216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] | ```
python -i script
```
will leave you in the interactive shell when an exception gets raised; then
```
import pdb
pdb.pm()
```
will put you into the post-mortem debugger so you can do all the usual debugging things.
This should work as long as your script does not call sys.exit. (Which scripts should never do, ... | `import pdb; pdb.set_trace()`
Source: <http://docs.python.org/library/pdb.html> |
2,337,216 | Besides wrapping all your code in `try` `except`, is there any way of achieving the same thing as running your script like `python -mpdb script`? I'd like to be able to see what went wrong when an exception gets raised. | 2010/02/25 | [
"https://Stackoverflow.com/questions/2337216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] | If you do not want to modify the source then yOu could run it from [ipython](http://ipython.scipy.org/moin/) - an enhanced interactive python shell.
e.g. run ipython then execute `%pdb on` to enable post-mortem debugging. `%run scriptname` will then run the script and automatically enter the debugger on any uncaught e... | ```
python -i script
```
will leave you in the interactive shell when an exception gets raised; then
```
import pdb
pdb.pm()
```
will put you into the post-mortem debugger so you can do all the usual debugging things.
This should work as long as your script does not call sys.exit. (Which scripts should never do, ... |
19,298,147 | I always get this error for this code:
```
Traceback (most recent call last):
File "E:/ankosh/trial13.py", line 14, in <module>
if grades_mix[index_no]=="HM1":
IndexError: list index out of range)
```
I would really appreciate the help.
```
`file_pointer=open("C:/python27/Doc/student_grades.txt", "r")
r... | 2013/10/10 | [
"https://Stackoverflow.com/questions/19298147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2833577/"
] | You have, in abbreviated form:
```
while 0==0:
if grades_mix[index_no]=="HM1":
index_no+=1
```
with no break statement to ever get out of the loop (which, how about `while True`?). Sooner or later you're going to go out of range. | The error message
```
IndexError: list index out of range
```
indicates that you are using an index that does not exist in the array. Try to check the size of the array by printing out its length
print "length of array grades\_mix =" ,len(grades\_mix)
If the length of the array is less than or equal to 1, then you... |
2,408,677 | I'm trying to implement the calculation of correlation coefficient of people between two sets of data in php.
I'm just trying to do the porting python script that can be found at this url
<http://answers.oreilly.com/topic/1066-how-to-find-similar-users-with-python/>
my implementation is the following:
```
class LB_Si... | 2010/03/09 | [
"https://Stackoverflow.com/questions/2408677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/76593/"
] | Your algorithm looks mathematically correct but numerically unstable. Finding the sum of squares explicitly is a recipe for disaster. What if you have numbers like `array(10000000001, 10000000002, 10000000003)`? A numerically stable one-pass algorithm for calculating the variance can be [found on Wikipedia](http://en.w... | try my package here
<http://www.phpclasses.org/browse/package/5854.html> |
2,408,677 | I'm trying to implement the calculation of correlation coefficient of people between two sets of data in php.
I'm just trying to do the porting python script that can be found at this url
<http://answers.oreilly.com/topic/1066-how-to-find-similar-users-with-python/>
my implementation is the following:
```
class LB_Si... | 2010/03/09 | [
"https://Stackoverflow.com/questions/2408677",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/76593/"
] | This is my solution:
```
function php_correlation($x,$y){
if(count($x)!==count($y)){return -1;}
$x=array_values($x);
$y=array_values($y);
$xs=array_sum($x)/count($x);
$ys=array_sum($y)/count($y);
$a=0;$bx=0;$by=0;
for($i=0;$i<count($x);$i++){
$xr=$x[$i]-$xs;
... | try my package here
<http://www.phpclasses.org/browse/package/5854.html> |
17,550,136 | My background is in more managed languages (C#, python) but I am becoming more experienced in C/C++. I am familiar with why the selection by reference (.) and selection through pointer operation (->) operators are different. In all cases I have encountered, if you use the incorrect one, it will result in a compile erro... | 2013/07/09 | [
"https://Stackoverflow.com/questions/17550136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2518451/"
] | In C++ you can overload the `->`-operator, which is used in pretty much all smart pointer implementations. However, some of those also have their own methods, i.e. to release a reference.
```
struct test {
int x;
};
std::shared_ptr<int> ptr(new test);
// Write to member x of the allocated object
ptr->x = 3;
// R... | You cannot apply `->` to a reference to a basic type and you cannot apply `.` to a pointer, but you can apply both to a user-defined type and they will have different meanings. The simplest example is a smart pointer, like `std::shared_ptr`:
```
struct A { int x; };
std::shared_ptr<A> p(new A);
p->x = 10;
p.reset();
... |
17,550,136 | My background is in more managed languages (C#, python) but I am becoming more experienced in C/C++. I am familiar with why the selection by reference (.) and selection through pointer operation (->) operators are different. In all cases I have encountered, if you use the incorrect one, it will result in a compile erro... | 2013/07/09 | [
"https://Stackoverflow.com/questions/17550136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2518451/"
] | In C++ you can overload the `->`-operator, which is used in pretty much all smart pointer implementations. However, some of those also have their own methods, i.e. to release a reference.
```
struct test {
int x;
};
std::shared_ptr<int> ptr(new test);
// Write to member x of the allocated object
ptr->x = 3;
// R... | >
> Is there a case where element selection by reference and element selection through pointer operation are both valid?
>
>
>
Since you can overload `operator->()` in C++, you can actually arrive at situations where you can use `->` and `.` interchangeably on the same object. You can even engineer things so that ... |
17,550,136 | My background is in more managed languages (C#, python) but I am becoming more experienced in C/C++. I am familiar with why the selection by reference (.) and selection through pointer operation (->) operators are different. In all cases I have encountered, if you use the incorrect one, it will result in a compile erro... | 2013/07/09 | [
"https://Stackoverflow.com/questions/17550136",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2518451/"
] | In C++ you can overload the `->`-operator, which is used in pretty much all smart pointer implementations. However, some of those also have their own methods, i.e. to release a reference.
```
struct test {
int x;
};
std::shared_ptr<int> ptr(new test);
// Write to member x of the allocated object
ptr->x = 3;
// R... | the short answer would be a smart pointer
you can access the smart pointer class arguments using the "." (if you make your own smart pointer class you can extract from there for instance the current reference count) while you would use the "->" operator to access whatever is being stored using the smart pointer. |
72,623,017 | As of may 30th, smtp is no longer accepted.
<https://support.google.com/accounts/answer/6010255?hl=en&ref_topic=7188673>
What is the new way to make a simple python emailer rather than a full application with the "login with google" option?
Not sure why I was asked for the code and error, given that I already diagno... | 2022/06/14 | [
"https://Stackoverflow.com/questions/72623017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12339133/"
] | Correction after May 30 2022, sending the users actual password is no longer accepted by googles smtp server
You should configuring an [apps password](https://support.google.com/accounts/answer/185833?hl=en#:%7E:text=An%20App%20Password%20is%20a,2%2DStep%20Verification%20turned%20on.) this works. Then replace the pass... | ```
import smtplib
host = "server.smtp.com"
server = smtplib.SMTP(host)
FROM = "[email protected]"
TO = "[email protected]"
MSG = "Subject: Test email python\n\nBody of your message!"
server.sendmail(FROM, TO, MSG)
server.quit()
print ("Email Send")
``` |
65,526,849 | I run through the following steps to attempt to start up an app for production:
```
-Setup a virtualenv for the python dependencies: virtualenv -p /usr/bin/python3.8 ~/app_env
-Install pip dependencies: . ~/app_env/bin/activate && pip install -r ~/app/requirements.txt
-Un-comment the lines for privilege dropping in ... | 2021/01/01 | [
"https://Stackoverflow.com/questions/65526849",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12027484/"
] | What solved it for me was apparently just reinstalling UWSGI, like in [this](https://stackoverflow.com/questions/21669354/rebuild-uwsgi-with-pcre-support?noredirect=1&lq=1) thread, in my virtual env while forcing it to ignore the cache so it could know to use the pcre library I installed.
In order, doing this
```
uws... | I tried to solve this error but it did not work no matter what I did and then reinstalled uwsgi, but the following 2 lines solved my problem
```
sudo find / -name libpcre.so.*
```
#change the path of the /home/anaconda3/lib/libpcre.so.1 with the one appears after above one.
```
sudo ln -s /home/anaconda3/lib/libpcr... |
41,285,789 | I came across a python library which has docs, which start like this:
>
> Quickstart
>
>
> Include foolib in your requirements.txt file.
>
>
>
AFAIK dependencies should be specified via `install_requires` in `setup.py`.
Should I talk the maintainer of the library and create a pull-request for the docs? | 2016/12/22 | [
"https://Stackoverflow.com/questions/41285789",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/633961/"
] | Both are acceptable. The difference is that specifying something in your `install_requires` will auto-download / install that package when you install the package using setup.py. Having a `requirements.txt` makes it easier to see at a glance what the requirements are. I personally prefer seeing libraries with a `requir... | Add your dependencies in a requirements file and then parse this file in the setup.py. This will help you to:
* Easily install dependencies without installing the entire package through pip
* Get only one source for your dependencies
* Get all way to install your package available (pip, easy\_install, command line, et... |
55,721,564 | Here is the 'smem' command I run on the Redhat/CentOS Linux system. I expect the output be printed without the fields with zero size however I would expect the heading columns.
```
smem -kt -c "pid user command swap"
PID User Command Swap
7894 root /sbin/agetty --noclear tty1 ... | 2019/04/17 | [
"https://Stackoverflow.com/questions/55721564",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11096022/"
] | Like this?:
```
$ awk '$NF!=0' file
PID User Command Swap
7850 root /sbin/auditd 236.0K
...
7883 root /opt/traps/bin/trapsd 64.0K
----------------------------------------------------
54 10 5.1M
```
But instead ... | Could you please try following, for extra precautions removing the space from last fields(in case it is there).
```
smem -kt -c "pid user command swap" | awk 'FNR==1{print;next} {sub(/[[:space:]]+$/,"")} $NF==0{next} 1'
``` |
35,282,609 | I'm a new Python programmer working through the book *Automate the Boring Stuff with Python*. One of the end-of-chapter projects is to build a mad libs program. Based on what has been introduced so far, I think that the author intends for me to use regular expressions.
Here is my code:
```
#! python3
#
# madlibs.py -... | 2016/02/09 | [
"https://Stackoverflow.com/questions/35282609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5901044/"
] | This is covered in detail in [BashFAQ #004](http://mywiki.wooledge.org/BashFAQ/004). Notably, [use of `ls` for this purpose is an antipattern and should be avoided](http://mywiki.wooledge.org/ParsingLs).
```
shopt -s dotglob # if including hidden files is desired
files=( "$dir"/* )
[[ -e $files || -L $files ]] && ec... | **Robust pure Bash** solutions:
For background on ***why* a pure Bash solution with globbing is superior to using `ls`**, see **[Charles Duffy's helpful answer](https://stackoverflow.com/a/35282784/45375)**, which also contains a **`find`-based alternative**, which is **much faster and less memory-intensive with *larg... |
35,282,609 | I'm a new Python programmer working through the book *Automate the Boring Stuff with Python*. One of the end-of-chapter projects is to build a mad libs program. Based on what has been introduced so far, I think that the author intends for me to use regular expressions.
Here is my code:
```
#! python3
#
# madlibs.py -... | 2016/02/09 | [
"https://Stackoverflow.com/questions/35282609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5901044/"
] | This is covered in detail in [BashFAQ #004](http://mywiki.wooledge.org/BashFAQ/004). Notably, [use of `ls` for this purpose is an antipattern and should be avoided](http://mywiki.wooledge.org/ParsingLs).
```
shopt -s dotglob # if including hidden files is desired
files=( "$dir"/* )
[[ -e $files || -L $files ]] && ec... | Here is a solution based on `stat` command that can return **number of hard links** if run against a directory (or link to a directory). It starts incrementing *number of hard links* from 3 as first two are `.` and `..` entries thus subtracting `2` from this number gives as actual number of entries in the given directo... |
35,282,609 | I'm a new Python programmer working through the book *Automate the Boring Stuff with Python*. One of the end-of-chapter projects is to build a mad libs program. Based on what has been introduced so far, I think that the author intends for me to use regular expressions.
Here is my code:
```
#! python3
#
# madlibs.py -... | 2016/02/09 | [
"https://Stackoverflow.com/questions/35282609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5901044/"
] | **Robust pure Bash** solutions:
For background on ***why* a pure Bash solution with globbing is superior to using `ls`**, see **[Charles Duffy's helpful answer](https://stackoverflow.com/a/35282784/45375)**, which also contains a **`find`-based alternative**, which is **much faster and less memory-intensive with *larg... | Here is a solution based on `stat` command that can return **number of hard links** if run against a directory (or link to a directory). It starts incrementing *number of hard links* from 3 as first two are `.` and `..` entries thus subtracting `2` from this number gives as actual number of entries in the given directo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.