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 |
|---|---|---|---|---|---|
48,402,276 | I am taking a Udemy course. The problem I am working on is to take two strings and determine if they are 'one edit away' from each other. That means you can make a single change -- change one letter, add one letter, delete one letter -- from one string and have it become identical to the other.
Examples:
```
s1a = "a... | 2018/01/23 | [
"https://Stackoverflow.com/questions/48402276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7535419/"
] | Here's a solution using differences found by list comprehension.
```
def one_away(s1, s2):
diff1 = [el for el in s1 if el not in s2]
diff2 = [el for el in s2 if el not in s1]
if len(diff1) < 2 and len(diff2) < 2:
return True
return False
```
Unlike a set-based solution, this one doesn't lose ... | Here is solving one away where set is used to find the unique character. Done not completely using set but set is used to find the unique character in two given strings. List as a stack is used to pop item from both stacks, and then to compare them.
Using stack, pop items from both items and see if they match.
Find th... |
54,938,607 | I have already read answer of this question [Image.open() cannot identify image file - Python?](https://stackoverflow.com/q/19230991/9235408), that question was solved by using `from PIL import Image`, but my situation is different. I am using `image_slicer`, and there I am getting these errors:
```
Traceback (most re... | 2019/03/01 | [
"https://Stackoverflow.com/questions/54938607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9235408/"
] | [Image slicer](https://image-slicer.readthedocs.io/en/latest/) is not intended for reading `nii` format. Here is the [list](https://pillow.readthedocs.io/en/5.1.x/handbook/image-file-formats.html#image-file-formats) of supported formats. | This error also occurs whenever the image file itself is corrupted. I once accidentally was in the process of deleting the subject image, until canceling mid-way through.
TL;DR - open image file to see if it's ok. |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Whether you're able to keep 1000 files at once is a separate issue and depends on your OS and its configuration; if not, you'll have to proceed in two steps -- merge groups of N files into temporary ones, then merge the temporary ones into the final-result file (two steps should suffice, as they let you merge a total o... | You want to use merge sort, e.g. `heapq.merge`. I'm not sure if your OS allows you to open 1000 files simultaneously. If not you may have to do it in 2 or more passes. |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Whether you're able to keep 1000 files at once is a separate issue and depends on your OS and its configuration; if not, you'll have to proceed in two steps -- merge groups of N files into temporary ones, then merge the temporary ones into the final-result file (two steps should suffice, as they let you merge a total o... | Why don't you divide the domains by first letter, so you would just split the source files into 26 or more files which could be named something like: domains-a.dat, domains-b.dat. Then you can load these entirely into RAM and sort them and write them out to a common file.
So:
3 input files split into 26+ source files
... |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Whether you're able to keep 1000 files at once is a separate issue and depends on your OS and its configuration; if not, you'll have to proceed in two steps -- merge groups of N files into temporary ones, then merge the temporary ones into the final-result file (two steps should suffice, as they let you merge a total o... | Your algorithm for merging sorted files is incorrect. What you do is read one line from each file, find the lowest-ranked item among all the lines read, and write it to the output file. Repeat this process (ignoring any files that are at EOF) until the end of all files has been reached. |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Whether you're able to keep 1000 files at once is a separate issue and depends on your OS and its configuration; if not, you'll have to proceed in two steps -- merge groups of N files into temporary ones, then merge the temporary ones into the final-result file (two steps should suffice, as they let you merge a total o... | ```
#! /usr/bin/env python
"""Usage: unconfuse.py file1 file2 ... fileN
Reads a list of domain names from each file, and writes them to standard output grouped by TLD.
"""
import sys, os
spools = {}
for name in sys.argv[1:]:
for line in file(name):
if (line == "\n"): continue
tld = line[line.ri... |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | You want to use merge sort, e.g. `heapq.merge`. I'm not sure if your OS allows you to open 1000 files simultaneously. If not you may have to do it in 2 or more passes. | Your algorithm for merging sorted files is incorrect. What you do is read one line from each file, find the lowest-ranked item among all the lines read, and write it to the output file. Repeat this process (ignoring any files that are at EOF) until the end of all files has been reached. |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | You want to use merge sort, e.g. `heapq.merge`. I'm not sure if your OS allows you to open 1000 files simultaneously. If not you may have to do it in 2 or more passes. | ```
#! /usr/bin/env python
"""Usage: unconfuse.py file1 file2 ... fileN
Reads a list of domain names from each file, and writes them to standard output grouped by TLD.
"""
import sys, os
spools = {}
for name in sys.argv[1:]:
for line in file(name):
if (line == "\n"): continue
tld = line[line.ri... |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Why don't you divide the domains by first letter, so you would just split the source files into 26 or more files which could be named something like: domains-a.dat, domains-b.dat. Then you can load these entirely into RAM and sort them and write them out to a common file.
So:
3 input files split into 26+ source files
... | Your algorithm for merging sorted files is incorrect. What you do is read one line from each file, find the lowest-ranked item among all the lines read, and write it to the output file. Repeat this process (ignoring any files that are at EOF) until the end of all files has been reached. |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Why don't you divide the domains by first letter, so you would just split the source files into 26 or more files which could be named something like: domains-a.dat, domains-b.dat. Then you can load these entirely into RAM and sort them and write them out to a common file.
So:
3 input files split into 26+ source files
... | ```
#! /usr/bin/env python
"""Usage: unconfuse.py file1 file2 ... fileN
Reads a list of domain names from each file, and writes them to standard output grouped by TLD.
"""
import sys, os
spools = {}
for name in sys.argv[1:]:
for line in file(name):
if (line == "\n"): continue
tld = line[line.ri... |
3,561,221 | this is similar to the question in [merge sort in python](https://stackoverflow.com/questions/3559807/merge-sort-in-python)
I'm restating because I don't think I explained the problem very well over there.
basically I have a series of about 1000 files all containing domain names. altogether the data is > 1gig so I'm ... | 2010/08/24 | [
"https://Stackoverflow.com/questions/3561221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/410296/"
] | Your algorithm for merging sorted files is incorrect. What you do is read one line from each file, find the lowest-ranked item among all the lines read, and write it to the output file. Repeat this process (ignoring any files that are at EOF) until the end of all files has been reached. | ```
#! /usr/bin/env python
"""Usage: unconfuse.py file1 file2 ... fileN
Reads a list of domain names from each file, and writes them to standard output grouped by TLD.
"""
import sys, os
spools = {}
for name in sys.argv[1:]:
for line in file(name):
if (line == "\n"): continue
tld = line[line.ri... |
15,351,515 | I wrote my own implementation of the `ISession` [interface](http://docs.pylonsproject.org/projects/pyramid/en/1.0-branch/_modules/pyramid/interfaces.html#ISession) of Pyramid which should store the Session in a database. Everything works real nice, but somehow `pyramid_tm` throws up on this. As soon as it is activated ... | 2013/03/12 | [
"https://Stackoverflow.com/questions/15351515",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1326104/"
] | I believe what you're seeing here is a quirk to the fact that response callbacks and finished callbacks are actually executed after tweens. They are positioned just between your app's egress, and middleware. `pyramid_tm`, being a tween, is committing the transaction before your response callback executes - causing the ... | I first tried with registering a tween and it worked somehow, but the data did not get saved. I then stumpled upon the [SQLAlchemy Event System](http://docs.sqlalchemy.org/en/latest/core/event.html). I found the [after\_commit](http://docs.sqlalchemy.org/en/latest/orm/events.html#sqlalchemy.orm.events.SessionEvents.aft... |
51,118,801 | i am very new in python (and programming in general) and here is my issue. i would like to replace (or delete) a part of a string from a txt file which contains hundreds or thousands of lines. each line starts with the very same string which i want to delete.
i have not found a method to delete it so i tried a replac... | 2018/06/30 | [
"https://Stackoverflow.com/questions/51118801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8741601/"
] | >
> each line starts with the very same string which i want to delete.
>
>
>
The problem is you're passing a string `"text_to_replace"` rather than the variable `text_to_replace`.
But, for this specific problem, you could just remove the first *n* characters from each line:
```
text_to_replace = "Chart: Bar Back... | If you quote a variable it becomes a string literal and won't be evaluated as a variable.
Change your line for replacement to:
```
new_line = each_line.replace(text_to_replace, " ")
``` |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | On M1 MacBook Pro, I've had success using `docker run --platform linux/amd64`
**Example**
```
docker run --platform linux/amd64 node
``` | With docker-compose you also have the `platform` option.
```
version: "2.4"
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.1.1
hostname: zookeeper
container_name: zookeeper
platform: linux/amd64
ports:
- "2181:2181"
``` |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | If you're planning to run the image in your laptop, you need to build it for the cpu architecture of that particular machine. You can provide the `--platform` option to docker build (or even to `docker-compose`) to define the target platform you want to build the image for.
For example:
```
docker build --platform li... | You might need to run
```
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
```
in order to register foreign file formats with the kernel. |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | On M1 MacBook Pro, I've had success using `docker run --platform linux/amd64`
**Example**
```
docker run --platform linux/amd64 node
``` | You might need to run
```
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
```
in order to register foreign file formats with the kernel. |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | If you're planning to run the image in your laptop, you need to build it for the cpu architecture of that particular machine. You can provide the `--platform` option to docker build (or even to `docker-compose`) to define the target platform you want to build the image for.
For example:
```
docker build --platform li... | You should have the docker buildx installed. If you don't have the docker-desktop you can download the binary buildx from github: <https://github.com/docker/buildx/>
After installation you can build your image like Theofilos Papapanagiotou said
<downloaded\_path>/buildx --platform linux/amd64 ... |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | Build the image by passing the list of architecture
Try this:
```
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t username/demo:latest --push .
```
Note: ensure to place "." at the end | You should have the docker buildx installed. If you don't have the docker-desktop you can download the binary buildx from github: <https://github.com/docker/buildx/>
After installation you can build your image like Theofilos Papapanagiotou said
<downloaded\_path>/buildx --platform linux/amd64 ... |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | With docker-compose you also have the `platform` option.
```
version: "2.4"
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.1.1
hostname: zookeeper
container_name: zookeeper
platform: linux/amd64
ports:
- "2181:2181"
``` | You might need to run
```
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
```
in order to register foreign file formats with the kernel. |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | If you're planning to run the image in your laptop, you need to build it for the cpu architecture of that particular machine. You can provide the `--platform` option to docker build (or even to `docker-compose`) to define the target platform you want to build the image for.
For example:
```
docker build --platform li... | Build the image by passing the list of architecture
Try this:
```
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t username/demo:latest --push .
```
Note: ensure to place "." at the end |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | With docker-compose you also have the `platform` option.
```
version: "2.4"
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.1.1
hostname: zookeeper
container_name: zookeeper
platform: linux/amd64
ports:
- "2181:2181"
``` | You should have the docker buildx installed. If you don't have the docker-desktop you can download the binary buildx from github: <https://github.com/docker/buildx/>
After installation you can build your image like Theofilos Papapanagiotou said
<downloaded\_path>/buildx --platform linux/amd64 ... |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | On M1 MacBook Pro, I've had success using `docker run --platform linux/amd64`
**Example**
```
docker run --platform linux/amd64 node
``` | Build the image by passing the list of architecture
Try this:
```
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t username/demo:latest --push .
```
Note: ensure to place "." at the end |
69,054,921 | I want to run a docker container for `Ganache` on my MacBook M1, but get the following error:
```
The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
```
After this line nothing else will happen anymore and the whole process i... | 2021/09/04 | [
"https://Stackoverflow.com/questions/69054921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6727976/"
] | With docker-compose you also have the `platform` option.
```
version: "2.4"
services:
zookeeper:
image: confluentinc/cp-zookeeper:7.1.1
hostname: zookeeper
container_name: zookeeper
platform: linux/amd64
ports:
- "2181:2181"
``` | Build the image by passing the list of architecture
Try this:
```
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 -t username/demo:latest --push .
```
Note: ensure to place "." at the end |
49,924,302 | I have couple of date string with following pattern MM DD(st, nd, rd, th) YYYY HH:MM am. what is the most pythonic way for me to replace (st, nd, rd, th) as empty string ''?
```
s = ['st', 'nd', 'rd', 'th']
string = 'Mar 1st 2017 00:00 am'
string = 'Mar 2nd 2017 00:00 am'
string = 'Mar 3rd 2017 00:00 am'
string = 'Mar... | 2018/04/19 | [
"https://Stackoverflow.com/questions/49924302",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6373357/"
] | The most pythonic way is to use `dateutil`.
```
from dateutil.parser import parse
import datetime
t = parse("Mar 2nd 2017 00:00 am")
# you can access the month, hour, minute, etc:
t.hour # 0
t.minute # 0
t.month # 3
```
And then, you can use `t.strftime()`, where the formatting of the resulting string is any of th... | You could use a regular expression as follows:
```
import re
strings = ['Mar 1st 2017 00:00 am', 'Mar 2nd 2017 00:00 am', 'Mar 3rd 2017 00:00 am', 'Mar 4th 2017 00:00 am']
for string in strings:
print(re.sub('(.*? \d+)(.*?)( .*)', r'\1\3', string))
```
This would give you:
```none
Mar 1 2017 00:00 am
... |
30,522,420 | I'm going through the new book "Data Science from Scratch: First Principles with Python" and I think I've found an errata.
When I run the code I get `"TypeError: 'int' object has no attribute '__getitem__'".` I think this is because when I try to select `friend["friends"]`, `friend` is an integer that I can't subset. ... | 2015/05/29 | [
"https://Stackoverflow.com/questions/30522420",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2469211/"
] | Yes, you've found an incorrect piece of code in the book.
Implementation for `friends_of_friend_ids_bad` function should be like this:
```
def friends_of_friend_ids_bad(user):
#foaf is friend of friend
return [users[foaf]["id"]
for friend in user["friends"]
for foaf in users[friend]["friends"... | The error is on:
```
return [foaf["id"] for friend in user["friends"] for foaf in friend["friends"]]
```
In the second for loop, you're trying to access `__getitem__` of `users[0]["friends"]`, which is exactly 5 (ints don't have `__getitem__`).
You're trying to store on the list `foaf["id"]` for each friend in `use... |
65,154,521 | When I want to selenium click this code button , selenium write me this error
This is my code:
```
#LOGIN IN WEBSITE
browser = webdriver.Firefox()
browser.get("http://class.apphafez.ir/")
username_input = browser.find_element_by_css_selector("input[name='UserName']")
password_input = browser.find_ele... | 2020/12/05 | [
"https://Stackoverflow.com/questions/65154521",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13937766/"
] | You were close enough. The value of the *class* attribute is **`btn btn-palegreen enterClassBtn`** but not `btn btn- palegreen enterClassBtn` and you can't add extra spaces within the attribute value.
---
Solution
--------
To click on the element you need to induce [WebDriverWait](https://stackoverflow.com/questions... | Multiple class names for css values are tough to handle. usually easiest way is to use a css selector:
```
button.btn.btn-palegreen.enterClassBtn
```
Specifically:
```
go_to_class = wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR , ("button.btn.btn-palegreen.enterClassBtn"))))
```
See also [How to get elem... |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could reshape the array to a `10x10`, then use slicing to pick the first 4 elements of each row. Then flatten the reshaped, sliced array:
```
In [46]: print a
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 ... | Use `% 10`:
```
print [i for i in range(100) if i % 10 in (0, 1, 2, 3)]
[0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33, 40, 41, 42, 43, 50, 51, 52, 53, 60, 61, 62, 63, 70, 71, 72, 73, 80, 81, 82, 83, 90, 91, 92, 93]
``` |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could use [`NumPy slicing`](http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html#basic-slicing-and-indexing) to solve your case.
For a `1D` array case -
```
A.reshape(-1,10)[:,:4].reshape(-1)
```
This can be extended to a `2D` array case with the selection to be made along the first axis -
```... | Use `% 10`:
```
print [i for i in range(100) if i % 10 in (0, 1, 2, 3)]
[0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33, 40, 41, 42, 43, 50, 51, 52, 53, 60, 61, 62, 63, 70, 71, 72, 73, 80, 81, 82, 83, 90, 91, 92, 93]
``` |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | Use `% 10`:
```
print [i for i in range(100) if i % 10 in (0, 1, 2, 3)]
[0, 1, 2, 3, 10, 11, 12, 13, 20, 21, 22, 23, 30, 31, 32, 33, 40, 41, 42, 43, 50, 51, 52, 53, 60, 61, 62, 63, 70, 71, 72, 73, 80, 81, 82, 83, 90, 91, 92, 93]
``` | In the example in OP, the input array is divisible by `m+n`. If it's not, then you could use the below function `take_n_skip_m`. It expands on @Divakar's answer by padding the input array to make it reshapeable into a proper 2D matrix; slice, flatten and slice again to get the desired outcome:
```
def take_n_skip_m(ar... |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could reshape the array to a `10x10`, then use slicing to pick the first 4 elements of each row. Then flatten the reshaped, sliced array:
```
In [46]: print a
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 ... | ```
shorter_arr = arr[np.arange(len(arr))%10 < 4]
``` |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could use [`NumPy slicing`](http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html#basic-slicing-and-indexing) to solve your case.
For a `1D` array case -
```
A.reshape(-1,10)[:,:4].reshape(-1)
```
This can be extended to a `2D` array case with the selection to be made along the first axis -
```... | ```
shorter_arr = arr[np.arange(len(arr))%10 < 4]
``` |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | ```
shorter_arr = arr[np.arange(len(arr))%10 < 4]
``` | In the example in OP, the input array is divisible by `m+n`. If it's not, then you could use the below function `take_n_skip_m`. It expands on @Divakar's answer by padding the input array to make it reshapeable into a proper 2D matrix; slice, flatten and slice again to get the desired outcome:
```
def take_n_skip_m(ar... |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could use [`NumPy slicing`](http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html#basic-slicing-and-indexing) to solve your case.
For a `1D` array case -
```
A.reshape(-1,10)[:,:4].reshape(-1)
```
This can be extended to a `2D` array case with the selection to be made along the first axis -
```... | You could reshape the array to a `10x10`, then use slicing to pick the first 4 elements of each row. Then flatten the reshaped, sliced array:
```
In [46]: print a
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 ... |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could reshape the array to a `10x10`, then use slicing to pick the first 4 elements of each row. Then flatten the reshaped, sliced array:
```
In [46]: print a
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
50 ... | In the example in OP, the input array is divisible by `m+n`. If it's not, then you could use the below function `take_n_skip_m`. It expands on @Divakar's answer by padding the input array to make it reshapeable into a proper 2D matrix; slice, flatten and slice again to get the desired outcome:
```
def take_n_skip_m(ar... |
33,801,170 | Let's say I have an ndarray with 100 elements, and I want to select the first 4 elements, skip 6 and go ahead like this (in other words, select the first 4 elements every 10 elements).
I tried with python slicing with step but I think it's not working in my case. How can I do that? I'm using Pandas and numpy, can the... | 2015/11/19 | [
"https://Stackoverflow.com/questions/33801170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5580662/"
] | You could use [`NumPy slicing`](http://docs.scipy.org/doc/numpy-1.10.0/reference/arrays.indexing.html#basic-slicing-and-indexing) to solve your case.
For a `1D` array case -
```
A.reshape(-1,10)[:,:4].reshape(-1)
```
This can be extended to a `2D` array case with the selection to be made along the first axis -
```... | In the example in OP, the input array is divisible by `m+n`. If it's not, then you could use the below function `take_n_skip_m`. It expands on @Divakar's answer by padding the input array to make it reshapeable into a proper 2D matrix; slice, flatten and slice again to get the desired outcome:
```
def take_n_skip_m(ar... |
51,500,519 | I can't use boto3 to connect to S3 with a role arn provided 100% programmatically.
```python
session = boto3.Session(role_arn="arn:aws:iam::****:role/*****",
RoleSessionName="****")
s3_client = boto3.client('s3',
aws_access_key_id="****",
aws_s... | 2018/07/24 | [
"https://Stackoverflow.com/questions/51500519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6227500/"
] | You need to understand how temporary credentials are created.
First you need to create a client using your current access keys. These credentials are then used to verify that you have the permissions to call assume\_role and have the rights to issue credentials from the IAM role.
If someone could do it your way, ther... | Firstly, *never* put an Access Key and Secret Key in your code. Always store credentials in a `~/.aws/credentials` file (eg via `aws configure`). This avoids embarrassing situations where your credentials are accidentally released to the world. Also, if you are running on an Amazon EC2 instance, then simply assign an I... |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | You should go one level up in your data abstraction. You are not trying to access the entries by their individual names -- you rather use `names` to denote the whole collection of values, so a simple list might be what you want.
If you want both, a name for the collection *and* names for the individual items, then a d... | You should use a [**`dict`**](http://docs.python.org/library/stdtypes.html#mapping-types-dict):
```
>>> d = {"a": 1, "b": 2, "c": 3}
>>> d.update({"a": 8})
>>> print(d)
{"a": 8, "c": 3, "b": 2}
``` |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | You should go one level up in your data abstraction. You are not trying to access the entries by their individual names -- you rather use `names` to denote the whole collection of values, so a simple list might be what you want.
If you want both, a name for the collection *and* names for the individual items, then a d... | I've realised that "exotic" syntax is probably unnecessary. Instead the following achieves what I wanted: (1) to avoid repeating the names and (2) to capture them as a sequence:
```
sequence = (a,b,c) = (1,2,3)
```
Of course, this won't allow:
```
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> Tr... |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | This?
```
>>> from collections import namedtuple
>>> names = namedtuple( 'names', ['a','b','c'] )
>>> thing= names(3,2,1)
>>> thing.a
3
>>> thing.b
2
>>> thing.c
1
``` | I've realised that "exotic" syntax is probably unnecessary. Instead the following achieves what I wanted: (1) to avoid repeating the names and (2) to capture them as a sequence:
```
sequence = (a,b,c) = (1,2,3)
```
Of course, this won't allow:
```
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> Tr... |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | You should use a [**`dict`**](http://docs.python.org/library/stdtypes.html#mapping-types-dict):
```
>>> d = {"a": 1, "b": 2, "c": 3}
>>> d.update({"a": 8})
>>> print(d)
{"a": 8, "c": 3, "b": 2}
``` | Not sure whether this is what you want...
```
>>> a,b,c = (1,2,3)
>>> names = (a,b,c)
>>> names
(1, 2, 3)
>>> (a,b,c) == names
True
>>> (a,b,c) == (1,2,3)
True
``` |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | This?
```
>>> from collections import namedtuple
>>> names = namedtuple( 'names', ['a','b','c'] )
>>> thing= names(3,2,1)
>>> thing.a
3
>>> thing.b
2
>>> thing.c
1
``` | Not sure whether this is what you want...
```
>>> a,b,c = (1,2,3)
>>> names = (a,b,c)
>>> names
(1, 2, 3)
>>> (a,b,c) == names
True
>>> (a,b,c) == (1,2,3)
True
``` |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | Python has such an elegant namespace system:
```
#!/usr/bin/env python
class GenericContainer(object):
def __init__(self, *args, **kwargs):
self._names = []
self._names.extend(args)
self.set(**kwargs)
def set(self, *args, **kwargs):
for i, value in enumerate(args):
... | Not sure whether this is what you want...
```
>>> a,b,c = (1,2,3)
>>> names = (a,b,c)
>>> names
(1, 2, 3)
>>> (a,b,c) == names
True
>>> (a,b,c) == (1,2,3)
True
``` |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | This?
```
>>> from collections import namedtuple
>>> names = namedtuple( 'names', ['a','b','c'] )
>>> thing= names(3,2,1)
>>> thing.a
3
>>> thing.b
2
>>> thing.c
1
``` | Well, you shouldn't do this, since it's potentially unsafe, but you can [use the `exec` statement](http://docs.python.org/reference/simple_stmts.html#exec)
```
>>> names = "a, b, c"
>>> tup = 1,2,3
>>> exec names + "=" + repr(tup)
>>> a, b, c
(1, 2, 3)
``` |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | I've realised that "exotic" syntax is probably unnecessary. Instead the following achieves what I wanted: (1) to avoid repeating the names and (2) to capture them as a sequence:
```
sequence = (a,b,c) = (1,2,3)
```
Of course, this won't allow:
```
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> Tr... | Python has such an elegant namespace system:
```
#!/usr/bin/env python
class GenericContainer(object):
def __init__(self, *args, **kwargs):
self._names = []
self._names.extend(args)
self.set(**kwargs)
def set(self, *args, **kwargs):
for i, value in enumerate(args):
... |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | You should use a [**`dict`**](http://docs.python.org/library/stdtypes.html#mapping-types-dict):
```
>>> d = {"a": 1, "b": 2, "c": 3}
>>> d.update({"a": 8})
>>> print(d)
{"a": 8, "c": 3, "b": 2}
``` | Python has such an elegant namespace system:
```
#!/usr/bin/env python
class GenericContainer(object):
def __init__(self, *args, **kwargs):
self._names = []
self._names.extend(args)
self.set(**kwargs)
def set(self, *args, **kwargs):
for i, value in enumerate(args):
... |
9,433,021 | Is there a way to group names together in python, to repeatedly assign to them *en masse*?
While we can do:
```
a,b,c = (1,2,3)
```
I would like to be able to do something like:
```
names = a,b,c
*names = (3,2,1) # this syntax doesn't work
a,b,c == (3,2,1) #=> True
```
Is there a built-in syntax for this? If n... | 2012/02/24 | [
"https://Stackoverflow.com/questions/9433021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21640/"
] | You should go one level up in your data abstraction. You are not trying to access the entries by their individual names -- you rather use `names` to denote the whole collection of values, so a simple list might be what you want.
If you want both, a name for the collection *and* names for the individual items, then a d... | Not sure whether this is what you want...
```
>>> a,b,c = (1,2,3)
>>> names = (a,b,c)
>>> names
(1, 2, 3)
>>> (a,b,c) == names
True
>>> (a,b,c) == (1,2,3)
True
``` |
40,367,569 | I am trying to set up a Python extension (Gambit, <http://gambit.sourceforge.net/gambit13/build.html>) and am getting an error when trying to build setup.py:
>
> Traceback (most recent call last): File "setup.py", line 32, in <module>
>
>
> m.Extension.**dict** = m.\_Extension.**dict**
>
>
> AttributeError: attri... | 2016/11/01 | [
"https://Stackoverflow.com/questions/40367569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2537443/"
] | You are getting **[NullPointerException](https://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html)** at ***[android.support.v4.widget.drawerlayout](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html)***
>
> NullPointerException is thrown when an application attemp... | ```
android{
buildTypes{
release{
minifyEnabled false
}
}
}
```
Try this in your build.grade.
Or
Try to restart your Android Studio as well as your computer.As is known to all,Android Studio may perform stupid occasionally. |
40,367,569 | I am trying to set up a Python extension (Gambit, <http://gambit.sourceforge.net/gambit13/build.html>) and am getting an error when trying to build setup.py:
>
> Traceback (most recent call last): File "setup.py", line 32, in <module>
>
>
> m.Extension.**dict** = m.\_Extension.**dict**
>
>
> AttributeError: attri... | 2016/11/01 | [
"https://Stackoverflow.com/questions/40367569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2537443/"
] | You are getting **[NullPointerException](https://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html)** at ***[android.support.v4.widget.drawerlayout](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html)***
>
> NullPointerException is thrown when an application attemp... | if you are using proguard at release,
decrease your gradle version to 2.1.2
```
classpath 'com.android.tools.build:gradle:2.1.2'
``` |
40,367,569 | I am trying to set up a Python extension (Gambit, <http://gambit.sourceforge.net/gambit13/build.html>) and am getting an error when trying to build setup.py:
>
> Traceback (most recent call last): File "setup.py", line 32, in <module>
>
>
> m.Extension.**dict** = m.\_Extension.**dict**
>
>
> AttributeError: attri... | 2016/11/01 | [
"https://Stackoverflow.com/questions/40367569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2537443/"
] | You are getting **[NullPointerException](https://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html)** at ***[android.support.v4.widget.drawerlayout](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html)***
>
> NullPointerException is thrown when an application attemp... | ```
buildTypes {
release {
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
lintOptions {
abortOnError false
checkReleaseBuilds false
disable 'MissingTranslation'
}
```
Try this or just clean p... |
40,367,569 | I am trying to set up a Python extension (Gambit, <http://gambit.sourceforge.net/gambit13/build.html>) and am getting an error when trying to build setup.py:
>
> Traceback (most recent call last): File "setup.py", line 32, in <module>
>
>
> m.Extension.**dict** = m.\_Extension.**dict**
>
>
> AttributeError: attri... | 2016/11/01 | [
"https://Stackoverflow.com/questions/40367569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2537443/"
] | You are getting **[NullPointerException](https://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html)** at ***[android.support.v4.widget.drawerlayout](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html)***
>
> NullPointerException is thrown when an application attemp... | Here are some steps you can take to fix these types of errors and make sure your app doesn't crash on future platform updates:
* If your app uses private platform libraries, you should update it to include its own copy of those libraries or use the public NDK APIs.
* If your app uses a third-party library that accesse... |
40,367,569 | I am trying to set up a Python extension (Gambit, <http://gambit.sourceforge.net/gambit13/build.html>) and am getting an error when trying to build setup.py:
>
> Traceback (most recent call last): File "setup.py", line 32, in <module>
>
>
> m.Extension.**dict** = m.\_Extension.**dict**
>
>
> AttributeError: attri... | 2016/11/01 | [
"https://Stackoverflow.com/questions/40367569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2537443/"
] | You are getting **[NullPointerException](https://docs.oracle.com/javase/7/docs/api/java/lang/NullPointerException.html)** at ***[android.support.v4.widget.drawerlayout](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html)***
>
> NullPointerException is thrown when an application attemp... | According to the android api reference - [Android Developer Api Reference](https://developer.android.com/reference/android/support/v4/widget/DrawerLayout.html,)
***If your layout configures more than one drawer view per vertical edge of the window, an exception will be thrown at runtime.*** I suspect your drawer layou... |
55,373,867 | I have very basic producer-consumer code written with pika framework in python. The problem is - consumer side runs too slow on messages in queue. I ran some tests and found out that i can speed up the workflow up to 27 times with multiprocessing. The problem is - I don't know what is the right way to add multiprocessi... | 2019/03/27 | [
"https://Stackoverflow.com/questions/55373867",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7047471/"
] | Pika has extensive [example code](https://github.com/pika/pika/blob/0.13.1/examples/basic_consumer_threaded.py) that I recommend you check out. Note that this code is for **example** use only. In the case of doing work on threads, you will have to use a more intelligent way to manage your threads.
The goal is to not b... | ```
import pika
import json
from multiprocessing import Process
from datetime import datetime
from functions import download_xmls
import multiprocessing
import concurrent.futures
def do_job(body):
body = json.loads(body)
type = body[-1]['Type']
print('Object type in work currently ' + type)
cnums = [x[... |
42,740,284 | I have question that I am having a hard time understanding what the code might look like so I will explain the best I can. I am trying to view and search a NUL byte and replace it with with another NUL type byte, but the computer needs to be able to tell the difference between the different NUL bytes. an Example would ... | 2017/03/11 | [
"https://Stackoverflow.com/questions/42740284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7620511/"
] | If you are on Python 3, you should really work with `bytes` objects. Python 3 strings are sequences of unicode code points. To work with byte-strings, use `bytes` (which is pretty much the same as a Python 2 string, which used the "sequence of bytes" model).
```
>>> bytes([97, 98, 99])
b'abc'
>>>
```
Note, to write ... | another equivalent way to get the value of `\x00` in python is `chr(0)` i like that way a little better over the literal versions |
33,697,263 | i try to install snap7 (to read from a S7-1200) with it's python-snap7 0.4 wrapper but i get always a traceback with the following simple code.
```
from time import sleep
import snap7
from snap7.util import *
import struct
plc = snap7.client.Client()
```
Traceback:
```
>>>
Traceback (most recent call last):
Fi... | 2015/11/13 | [
"https://Stackoverflow.com/questions/33697263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4801693/"
] | After some try and error experiments and with some infos of snap7 involved developers, i fixed the problem. The folder where the snap7.dll and .lib file are located must be present in the Enviroment variables of Windows. Alternative you can copy the files to the Python install dir if you have checked the "add path" opt... | Try this:
Search the snap7 folder for snap7.dll and snap7.lib files
Copy the snap7.dll and snap7.lib into the "C:/PythonXX/site-packages/snap7 " directory and run you code again. You can figure out this in the common.py file in the same directory. |
33,697,263 | i try to install snap7 (to read from a S7-1200) with it's python-snap7 0.4 wrapper but i get always a traceback with the following simple code.
```
from time import sleep
import snap7
from snap7.util import *
import struct
plc = snap7.client.Client()
```
Traceback:
```
>>>
Traceback (most recent call last):
Fi... | 2015/11/13 | [
"https://Stackoverflow.com/questions/33697263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4801693/"
] | After some try and error experiments and with some infos of snap7 involved developers, i fixed the problem. The folder where the snap7.dll and .lib file are located must be present in the Enviroment variables of Windows. Alternative you can copy the files to the Python install dir if you have checked the "add path" opt... | The latest setup to use snap7 looks as follows for me:
* install snap7 for python with pip in the command line by "pip install
python-snap7"
* download the latest snap7 package from [sourceforge](https://sourceforge.net/projects/snap7/files/)
* copy the 32 or 64bit version to any folder, for example your project folde... |
33,697,263 | i try to install snap7 (to read from a S7-1200) with it's python-snap7 0.4 wrapper but i get always a traceback with the following simple code.
```
from time import sleep
import snap7
from snap7.util import *
import struct
plc = snap7.client.Client()
```
Traceback:
```
>>>
Traceback (most recent call last):
Fi... | 2015/11/13 | [
"https://Stackoverflow.com/questions/33697263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4801693/"
] | After some try and error experiments and with some infos of snap7 involved developers, i fixed the problem. The folder where the snap7.dll and .lib file are located must be present in the Enviroment variables of Windows. Alternative you can copy the files to the Python install dir if you have checked the "add path" opt... | **Copy** `snap7.dll and snap7.lib` **from** `"\snap7-full-1.2.1\release\Windows\Win64"` and **paste** them in to `"C:\snap7-full-1.2.1\release\Windows\Win64"` folder.
then "import snap7" is working. but it gives error in next step.
snap7.client.Client() -> AttributeError: module 'snap7' has no attribute 'client'
i us... |
33,697,263 | i try to install snap7 (to read from a S7-1200) with it's python-snap7 0.4 wrapper but i get always a traceback with the following simple code.
```
from time import sleep
import snap7
from snap7.util import *
import struct
plc = snap7.client.Client()
```
Traceback:
```
>>>
Traceback (most recent call last):
Fi... | 2015/11/13 | [
"https://Stackoverflow.com/questions/33697263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4801693/"
] | **Copy** `snap7.dll and snap7.lib` **from** `"\snap7-full-1.2.1\release\Windows\Win64"` and **paste** them in to `"C:\snap7-full-1.2.1\release\Windows\Win64"` folder.
then "import snap7" is working. but it gives error in next step.
snap7.client.Client() -> AttributeError: module 'snap7' has no attribute 'client'
i us... | Try this:
Search the snap7 folder for snap7.dll and snap7.lib files
Copy the snap7.dll and snap7.lib into the "C:/PythonXX/site-packages/snap7 " directory and run you code again. You can figure out this in the common.py file in the same directory. |
33,697,263 | i try to install snap7 (to read from a S7-1200) with it's python-snap7 0.4 wrapper but i get always a traceback with the following simple code.
```
from time import sleep
import snap7
from snap7.util import *
import struct
plc = snap7.client.Client()
```
Traceback:
```
>>>
Traceback (most recent call last):
Fi... | 2015/11/13 | [
"https://Stackoverflow.com/questions/33697263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4801693/"
] | **Copy** `snap7.dll and snap7.lib` **from** `"\snap7-full-1.2.1\release\Windows\Win64"` and **paste** them in to `"C:\snap7-full-1.2.1\release\Windows\Win64"` folder.
then "import snap7" is working. but it gives error in next step.
snap7.client.Client() -> AttributeError: module 'snap7' has no attribute 'client'
i us... | The latest setup to use snap7 looks as follows for me:
* install snap7 for python with pip in the command line by "pip install
python-snap7"
* download the latest snap7 package from [sourceforge](https://sourceforge.net/projects/snap7/files/)
* copy the 32 or 64bit version to any folder, for example your project folde... |
39,457,209 | I am trying to do some white blob detection using OpenCV. But my script failed to detect the big white block which is my goal while some small blobs are detected. I am new to OpenCV, and am i doing something wrong when using simpleblobdetection in OpenCV? [Solved partially, please read below]
And here is the script:
... | 2016/09/12 | [
"https://Stackoverflow.com/questions/39457209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6779632/"
] | If you just want to detect the white rectangle you can try to set a higher threshold, e.g. 253, erase small object with an opening and take the biggest blob. I first smoothed your image, then thresholding it:
[](https://i.stack.imgur.com/UrrBT.png)
a... | You could try setting params.maxArea to something obnoxiously large (somewhere in the tens of thousands): the default may be something lower than the area of the rectangle you're trying to detect. Also, I don't know how true this is or not, but I've heard that detection by color is bugged with a logic error, so it may ... |
68,010,585 | I can edit python code in a folder located in a Docker Volume. I use Visual Studio Code and in general lines it works fine.
The only problem that I have is that the libraries (such as pandas and numpy) are not installed in the container that Visual Studio creates to mount the volume, so I get warning errors.
How to i... | 2021/06/16 | [
"https://Stackoverflow.com/questions/68010585",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1362485/"
] | you can use this way. Put a img in div tag and use text-aling: center. There are many ways you can do this.
```css
.fotos-block{
text-align: center;
}
```
```html
<div class="fotos-block">
<img src = "https://www.imagemhost.com.br/images/2021/06/13/mail.png" class="fotos" id="foto1f">
</div>
``` | And you can also use this way to center the img.
```css
.fotos{
display: block;
margin: auto;
text-align: center;
}
``` |
69,726,911 | I need to return within this FOR only values equal to or less than 6 in each column.
```
colunas = list(df2.columns[8:19])
colunas
['Satisfação geral',
'Comunicação',
'Expertise da industria',
'Inovação',
'Parceira',
'Proatividade',
'Qualidade',
'responsividade',
'Pessoas',
'Expertise técnico',
'Pontuali... | 2021/10/26 | [
"https://Stackoverflow.com/questions/69726911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17161157/"
] | I found the solution: seems like AWS is using the term "Subnet Group" in multiple services. I created the group in the service "ElastiCache" but it needs to be created in service "DocumentDB" (see screenshot below).
[](https://i.stack.imgur.com/NGPT3.... | I had a similar issue. Before you create the cluster, you need to have a Security Group setup, and there, you should be able to change the VPC selected by default.
[](https://i.stack.imgur.com/lsPTl.png)
Additional info [here](https://docs.aws.amazon... |
68,736,258 | We successfully trained a TensorFlow model based on five climate features and one binary (0 or 1) label. We want an output for an outside input of five new climate variable values that will be inputted into model.predict(). However, we got an error when we tried to input an array of five values. Thanks in advance!
```... | 2021/08/11 | [
"https://Stackoverflow.com/questions/68736258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16637888/"
] | This is because of the non-blocking, asynchronous nature of the `con.query()` function call. It starts the asynchronous operation and then executes the lines of code after it. Then, sometime LATER, it calls its callback. So, in this code of yours with my adding logging:
```
router.post('/login', (req, res) => {
co... | It can be sometimes that the express session is saved when the out direct handler/function finished.
On that situation, if you want to save your session within a new async function, you should add the `next` function variable in your handler.
Then use it as the callback function to save you session.
It should look l... |
55,392,952 | I have a Python script that runs selenium webdriver that executes in the following steps:
1) Execute a for loop that runs for x number of times
2) Within the main for loop, selenium web driver finds buttons on the page using xpath
3) For each button found by selenium, the nested for loop clicks each button
4) Once a b... | 2019/03/28 | [
"https://Stackoverflow.com/questions/55392952",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/601787/"
] | Finally instead of:
```py
conn2 = conn.connect_as_project(project_id)
```
I used:
```py
conn2 = openstack.connection.Connection(
region_name='RegionOne',
auth=dict(
auth_url='http://controller:5000/v3',
username=u_name,
password=password,
project_id=project_id,
user_d... | I did this just fine...the only difference is that the project is a new project and I have to give credentials to the user I was using.
It was something like that:
```py
project = sconn.create_project(
name=name, domain_id='default')
user_id = conn.current_user_id
user = conn.get_user(user_id)
roles = conn.list_r... |
40,307,635 | In the R xgboost package, I can specify `predictions=TRUE` to save the out-of-fold predictions during cross-validation, e.g.:
```
library(xgboost)
data(mtcars)
xgb_params = list(
max_depth = 1,
eta = 0.01
)
x = model.matrix(mpg~0+., mtcars)
train = xgb.DMatrix(x, label=mtcars$mpg)
res = xgb.cv(xgb_params, train, 1... | 2016/10/28 | [
"https://Stackoverflow.com/questions/40307635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/345660/"
] | I'm not sure if this is what you want, but you can accomplish this by using the sklearn wrapper for xgboost: (I know I'm using iris dataset as regression problem -- which it isn't but this is for illustration).
```
import xgboost as xgb
from sklearn.cross_validation import cross_val_predict as cvp
from sklearn import ... | This is possible with `xgboost.cv()` but it is a bit hacky. It uses the callbacks and ... a global variable which I'm told is not desirable.
```
def oof_prediction():
"""
Dirty global variable callback hack.
"""
global cv_prediction_dict
def callback(env):
"""internal function"""
... |
40,307,635 | In the R xgboost package, I can specify `predictions=TRUE` to save the out-of-fold predictions during cross-validation, e.g.:
```
library(xgboost)
data(mtcars)
xgb_params = list(
max_depth = 1,
eta = 0.01
)
x = model.matrix(mpg~0+., mtcars)
train = xgb.DMatrix(x, label=mtcars$mpg)
res = xgb.cv(xgb_params, train, 1... | 2016/10/28 | [
"https://Stackoverflow.com/questions/40307635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/345660/"
] | I'm not sure if this is what you want, but you can accomplish this by using the sklearn wrapper for xgboost: (I know I'm using iris dataset as regression problem -- which it isn't but this is for illustration).
```
import xgboost as xgb
from sklearn.cross_validation import cross_val_predict as cvp
from sklearn import ... | Here is an example of use a custom `callback` function. This function can also save the best models.
```
import os
def cv_misc_callback(model_dir:str=None, oof_preds:list=None, maximize=True):
"""
To reduce memory and disk storage, only best models and best oof preds and stored
For classification, the pred... |
40,307,635 | In the R xgboost package, I can specify `predictions=TRUE` to save the out-of-fold predictions during cross-validation, e.g.:
```
library(xgboost)
data(mtcars)
xgb_params = list(
max_depth = 1,
eta = 0.01
)
x = model.matrix(mpg~0+., mtcars)
train = xgb.DMatrix(x, label=mtcars$mpg)
res = xgb.cv(xgb_params, train, 1... | 2016/10/28 | [
"https://Stackoverflow.com/questions/40307635",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/345660/"
] | This is possible with `xgboost.cv()` but it is a bit hacky. It uses the callbacks and ... a global variable which I'm told is not desirable.
```
def oof_prediction():
"""
Dirty global variable callback hack.
"""
global cv_prediction_dict
def callback(env):
"""internal function"""
... | Here is an example of use a custom `callback` function. This function can also save the best models.
```
import os
def cv_misc_callback(model_dir:str=None, oof_preds:list=None, maximize=True):
"""
To reduce memory and disk storage, only best models and best oof preds and stored
For classification, the pred... |
33,879,523 | is there a way in python to generate a continuous series of beeps in increasing amplitude and export it into a WAV file? | 2015/11/23 | [
"https://Stackoverflow.com/questions/33879523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5192982/"
] | I've based this on the answer to the previous question and added a lot of comments. Hopefully this makes it clear. You'll probably want to introduce a for loop to control the number of beeps and the increasing volume.
```
#!/usr/bin/python
# based on : www.daniweb.com/code/snippet263775.html
import math
import wave
... | I added minor improvements to the [JCx](https://stackoverflow.com/users/3818191/jcx) code above. As author said, its not cool to use global variables. So I wrapped his solution into class, and it works just fine:
```
import math
import wave
import struct
class BeepGenerator:
def __init__(self):
# Audio wi... |
3,263,665 | I am trying to create a line-by-line filter in python. However, `stdin.readlines()` reads all lines in before starting to process, and python runs out of memory (`MemoryError`).
How can I have *just one line* in memory at a time?
The kind of code I have:
```
for line in sys.stdin.readlines():
if( filter.apply( l... | 2010/07/16 | [
"https://Stackoverflow.com/questions/3263665",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6610/"
] | ```
for line in sys.stdin:
...
```
Or call `.readline()` in a loop. | ```
import sys
while 1:
line = sys.stdin.readline()
if not line:
break
if (filter.apply(line)):
print(line)
``` |
62,232,923 | I'm pretty new to python but I need some help parsing a string with a unique structure. I have a CSV file with a column with the following structure:
```
[Chakroff, Alek; Young, Liane] Boston Coll, Chestnut Hill, MA 02167 USA; [Russell, Pascale Sophie] Univ Surrey, Guildford, Surrey, England; [Piazza, Jared] Univ Lanc... | 2020/06/06 | [
"https://Stackoverflow.com/questions/62232923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13694393/"
] | You can take advantage of the unique substring before the elements you want:
```
# split string on substring '; ['
for i in s.split('; ['):
# split each resulting string on space char, return last element of array
print(i.split()[-1])
USA
England
England
``` | You can use the split() method for strings
```
states = [person_record.split(",")[-1] for person_record in records.split("; [")]
```
Where records is the string you get from your input. |
62,232,923 | I'm pretty new to python but I need some help parsing a string with a unique structure. I have a CSV file with a column with the following structure:
```
[Chakroff, Alek; Young, Liane] Boston Coll, Chestnut Hill, MA 02167 USA; [Russell, Pascale Sophie] Univ Surrey, Guildford, Surrey, England; [Piazza, Jared] Univ Lanc... | 2020/06/06 | [
"https://Stackoverflow.com/questions/62232923",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13694393/"
] | You can take advantage of the unique substring before the elements you want:
```
# split string on substring '; ['
for i in s.split('; ['):
# split each resulting string on space char, return last element of array
print(i.split()[-1])
USA
England
England
``` | Using a regular expression:
```
import regex as re
data = "[Chakroff, Alek; Young, Liane] Boston Coll, Chestnut Hill, MA 02167 USA; [Russell, Pascale Sophie] Univ Surrey, Guildford, Surrey, England; [Piazza, Jared] Univ Lancaster, Lancaster, England"
outer_pattern = re.compile(r'\[[^][]+\](*SKIP)(*FAIL)|;')
inner_pat... |
51,688,822 | Can anybody help me please? I am new to machine learning Studio.
I am using free azure machine learning studio workspace
trying to use in cell run all got the following error.
```
ValueError Traceback (most recent call last)
<ipython-input-1-17afe06b8f16> in <module>()
1 from azur... | 2018/08/04 | [
"https://Stackoverflow.com/questions/51688822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5892761/"
] | I have same problem as you. I have contacted tech support so once I get an answer, I will update this post. Meanwhile, you can use this **WORKAROUND**:
Get missing parameters and input them as Strings.
```
ws = Workspace("[WORKSPACE_ID]", "[AUTH_TOKEN]")
```
Where to get them:
[WOKRSPACE\_ID]: Azure ML Studio ... | the easiest way is to right click on the data set you have and choose Generate Data Access Code, the system will do it for you and all you have to do is to copy it to the frame and it all will be there.
I hope this helps! |
51,688,822 | Can anybody help me please? I am new to machine learning Studio.
I am using free azure machine learning studio workspace
trying to use in cell run all got the following error.
```
ValueError Traceback (most recent call last)
<ipython-input-1-17afe06b8f16> in <module>()
1 from azur... | 2018/08/04 | [
"https://Stackoverflow.com/questions/51688822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5892761/"
] | You can also go to Dataset-> Check/highlight the dataset you are working on -> Generate Data Access Code (down below).
Copy and paste the generated code into the first cell in your python notebook. It should look similar to this.
```
from azureml import Workspace
ws = Workspace(
workspace_id='WORKSPACEID',
au... | the easiest way is to right click on the data set you have and choose Generate Data Access Code, the system will do it for you and all you have to do is to copy it to the frame and it all will be there.
I hope this helps! |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | To avoid this error, you need to redefine `maven-war-plugin` to a newer one. For example:
```xml
<plugins>
. . .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
```
---
Works for `jdk-12`... | Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:
Change version from:
```xm... |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | The *ideal* way to resolve this would be to
>
> **reporting this to the maintainers of org.python.core.PySystemState**
>
>
>
and asking them to fix such reflective access going forward.
---
>
> If the default mode permits illegal reflective access, however, then
> it's essential to make that known so that peop... | Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:
Change version from:
```xm... |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | The *ideal* way to resolve this would be to
>
> **reporting this to the maintainers of org.python.core.PySystemState**
>
>
>
and asking them to fix such reflective access going forward.
---
>
> If the default mode permits illegal reflective access, however, then
> it's essential to make that known so that peop... | To avoid this error, you need to redefine `maven-war-plugin` to a newer one. For example:
```xml
<plugins>
. . .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
```
---
Works for `jdk-12`... |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | Jython developers do not have any practical solution for jdk9, according to this post <http://bugs.jython.org/issue2582>.
The previous explanation seems very long to figure out what should done. I just want jdk9 behaves exactly as jdk1.4 - 1.8, i.e be totally silent. The JVM strength in backward comparability. I'm tota... | Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:
Change version from:
```xm... |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:
Change version from:
```xm... | Came here while working on a Kotlin Spring project. Resolved the issue by:
```
cd /project/root/
touch .mvn/jvm.config
echo "--illegal-access=permit" >> .mvn/jvm.config
``` |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | The *ideal* way to resolve this would be to
>
> **reporting this to the maintainers of org.python.core.PySystemState**
>
>
>
and asking them to fix such reflective access going forward.
---
>
> If the default mode permits illegal reflective access, however, then
> it's essential to make that known so that peop... | DMelt seems to use Jython and this warning is something that the Jython maintainers will need to address. There is an issue tracking it here:
<http://bugs.jython.org/issue2582> |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | To avoid this error, you need to redefine `maven-war-plugin` to a newer one. For example:
```xml
<plugins>
. . .
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
```
---
Works for `jdk-12`... | Some recent feedback.
as stated in the java error code
```
WARNING: All illegal access operations will be denied in a future release
```
This future release is JDK 17, where the launcher parameter `--illegal-access` will stop working.
More information direct from Oracle can be found here: [JEP 403 link 1](https://... |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:
Change version from:
```xm... | Perhaps the fix below works for java 9 as well:
In my case the java open jdk version was 10.0.2 and got the same error (An illegal reflective access opeeration has occurred). I upgraded maven to version 3.6.0 on linux, and the problem was gone. |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | DMelt seems to use Jython and this warning is something that the Jython maintainers will need to address. There is an issue tracking it here:
<http://bugs.jython.org/issue2582> | Some recent feedback.
as stated in the java error code
```
WARNING: All illegal access operations will be denied in a future release
```
This future release is JDK 17, where the launcher parameter `--illegal-access` will stop working.
More information direct from Oracle can be found here: [JEP 403 link 1](https://... |
46,230,413 | I'm trying to run DMelt programs (<http://jwork.org/dmelt/>) program using Java9 (JDK9), and it gives me errors such as:
```
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.python.core.PySystemState (file:/dmelt/jehep/lib/jython/jython.jar) to method java.io.Conso... | 2017/09/15 | [
"https://Stackoverflow.com/questions/46230413",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8612074/"
] | Since the Java update 9, the "illegal reflective access operation has occurred" warning occurs.
To remove the warning message. You can replace maven-compiler-plugin with maven-war-plugin and/or updating the maven-war-plugin with the latest version in your pom.xml. Following are 2 examples:
Change version from:
```xm... | Some recent feedback.
as stated in the java error code
```
WARNING: All illegal access operations will be denied in a future release
```
This future release is JDK 17, where the launcher parameter `--illegal-access` will stop working.
More information direct from Oracle can be found here: [JEP 403 link 1](https://... |
17,586,599 | Using win32com.client, I'm attempting to create a simple shortcut in a folder. The shortcut however I would like to have arguments, except I keep getting the following error.
```
Traceback (most recent call last):
File "D:/Projects/Ms/ms.py", line 153, in <module>
scut.TargetPath = '"C:/python27/python.exe" "D:/... | 2013/07/11 | [
"https://Stackoverflow.com/questions/17586599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/721386/"
] | Your code works for me without error. (Windows XP 32bit, Python 2.7.5, pywin32-216).
(I slightly modified your code because `TargetPath` should contain only executable path.)
```
import win32com.client
ws = win32com.client.Dispatch("wscript.shell")
scut = ws.CreateShortcut('run_idle.lnk')
scut.TargetPath = '"c:/pytho... | "..TargetPath should contain only [an] executable path." is incorrect in two ways :
1. The target may also contain the executable's arguments.
For instance, I have a file [ D:\DATA\CCMD\Expl.CMD ] whose essential line of code is
START Explorer.exe "%Target%"
An example of its use is
D:\DATA\CCMD\Expl.CMD "D:\DATA\... |
59,209,756 | I'm new to Django 1.11 LTS and I'm trying to solve this error from a very long time. Here is my code where the error is occurring:
model.py:
```
name = models.CharField(db_column="name", db_index=True, max_length=128)
description = models.TextField(db_column="description", null=True, blank=True)
created =... | 2019/12/06 | [
"https://Stackoverflow.com/questions/59209756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5368168/"
] | <https://www.anylogic.com/files/anylogic-professional-8.3.3.exe>
For any version, just put the version you want and you will likely be able to download it
if using mac:
<https://www.anylogic.com/files/anylogic-professional-8.3.3.dmg> | In addition to Felipe's answer, you can always ask
>
> [email protected]
>
>
>
if you need *very* old versions. I believe that AL7.x is not available online anymore but they happily send the installers if you need them. |
7,454,590 | I'm trying to unit test a handler with webapp2 and am running into what has to be just a stupid little error.
I'd like to be able to use webapp2.uri\_for in the test, but I can't seem to do that:
```
def test_returns_200_on_home_page(self):
response = main.app.get_response(webapp2.uri_for('index'))
... | 2011/09/17 | [
"https://Stackoverflow.com/questions/7454590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/233242/"
] | I think the only option is to set a dummy request just to be able to create URIs for the test:
```
def test_returns_200_on_home_page(self):
// Set a dummy request just to be able to use uri_for().
req = webapp2.Request.blank('/')
req.app = main.app
main.app.set_globals(app=main.app, request=req)
r... | `webapp2.uri_for()` assumes that you are in a web request context and it fails because it cannot find the `request` object.
Instead of working around this you could think of your application as a black box and call it using literal URIs, like `'/'` as you mention it. After all, you want to simulate a normal web reques... |
45,949,105 | I had used created a GUI by wxpython to run stats model using statsmodels SARIMAX(). I put all five scripts in one file and tried to use
```
pyinstaller --onedir <mainscript.py>
```
to create compiled application.
After the pyinstaller process completed, I ran the generated application in dist file but it gave thi... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45949105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644284/"
] | If you have dark background in your application and want to use light colors for your ngx charts then you can use this method. It will use official code for ngx dark theme and show light colors for the chart labels. You can also change the color code in sccss variables and things work as you need.
I solved it using th... | Axis ticks formatting can be done like this
<https://github.com/swimlane/ngx-charts/blob/master/demo/app.component.html>
this has individual element classes. |
45,949,105 | I had used created a GUI by wxpython to run stats model using statsmodels SARIMAX(). I put all five scripts in one file and tried to use
```
pyinstaller --onedir <mainscript.py>
```
to create compiled application.
After the pyinstaller process completed, I ran the generated application in dist file but it gave thi... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45949105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644284/"
] | **Finally**
I was struggling with this information and found something neat, just adding a line within the ngx tag. Hope help someone in the future.
[Problem Reference - github #540](https://github.com/swimlane/ngx-charts/issues/540)
`style="fill: #2B2B2B"`
```
<ngx-charts-bar-horizontal
[results]="results"
... | Axis ticks formatting can be done like this
<https://github.com/swimlane/ngx-charts/blob/master/demo/app.component.html>
this has individual element classes. |
45,949,105 | I had used created a GUI by wxpython to run stats model using statsmodels SARIMAX(). I put all five scripts in one file and tried to use
```
pyinstaller --onedir <mainscript.py>
```
to create compiled application.
After the pyinstaller process completed, I ran the generated application in dist file but it gave thi... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45949105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644284/"
] | If you have dark background in your application and want to use light colors for your ngx charts then you can use this method. It will use official code for ngx dark theme and show light colors for the chart labels. You can also change the color code in sccss variables and things work as you need.
I solved it using th... | According to this [GitHub issue](https://github.com/swimlane/ngx-charts/issues/540) you might use following CSS to style the labels (worked for me):
```
.ngx-charts text { fill: #fff; }
```
The xAxisTickFormatting/yAxisTickFormatting that you've mentioned can be used to supply a formatting function which is used to ... |
45,949,105 | I had used created a GUI by wxpython to run stats model using statsmodels SARIMAX(). I put all five scripts in one file and tried to use
```
pyinstaller --onedir <mainscript.py>
```
to create compiled application.
After the pyinstaller process completed, I ran the generated application in dist file but it gave thi... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45949105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644284/"
] | **Finally**
I was struggling with this information and found something neat, just adding a line within the ngx tag. Hope help someone in the future.
[Problem Reference - github #540](https://github.com/swimlane/ngx-charts/issues/540)
`style="fill: #2B2B2B"`
```
<ngx-charts-bar-horizontal
[results]="results"
... | According to this [GitHub issue](https://github.com/swimlane/ngx-charts/issues/540) you might use following CSS to style the labels (worked for me):
```
.ngx-charts text { fill: #fff; }
```
The xAxisTickFormatting/yAxisTickFormatting that you've mentioned can be used to supply a formatting function which is used to ... |
45,949,105 | I had used created a GUI by wxpython to run stats model using statsmodels SARIMAX(). I put all five scripts in one file and tried to use
```
pyinstaller --onedir <mainscript.py>
```
to create compiled application.
After the pyinstaller process completed, I ran the generated application in dist file but it gave thi... | 2017/08/29 | [
"https://Stackoverflow.com/questions/45949105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7644284/"
] | If you have dark background in your application and want to use light colors for your ngx charts then you can use this method. It will use official code for ngx dark theme and show light colors for the chart labels. You can also change the color code in sccss variables and things work as you need.
I solved it using th... | **Finally**
I was struggling with this information and found something neat, just adding a line within the ngx tag. Hope help someone in the future.
[Problem Reference - github #540](https://github.com/swimlane/ngx-charts/issues/540)
`style="fill: #2B2B2B"`
```
<ngx-charts-bar-horizontal
[results]="results"
... |
30,489,449 | How can I see a warning again without restarting python. Now I see them only once.
Consider this code for example:
```
import pandas as pd
pd.Series([1]) / 0
```
I get
```
RuntimeWarning: divide by zero encountered in true_divide
```
But when I run it again it executes silently.
**How can I see the warni... | 2015/05/27 | [
"https://Stackoverflow.com/questions/30489449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3549680/"
] | >
> How can I see the warning again without restarting python?
>
>
>
As long as you do the following at the beginning of your script, you will not need to restart.
```
import pandas as pd
import numpy as np
import warnings
np.seterr(all='warn')
warnings.simplefilter("always")
```
At this point every time you a... | `warnings` is a pretty awesome standard library module. You're going to enjoy getting to know it :)
A little background
-------------------
The default behavior of `warnings` is to only show a particular warning, coming from a particular line, on its first occurrence. For instance, the following code will result in t... |
15,784,537 | Purpose: Given a PDB file, prints out all pairs of Cysteine residues forming disulfide bonds in the tertiary protein structure. Licence: GNU GPL Written By: Eric Miller
```
#!/usr/bin/env python
import math
def getDistance((x1,y1,z1),(x2,y2,z2)):
d = math.sqrt(pow((x1-x2),2)+pow((y1-y2),2)+pow((z1-z2),2));
retu... | 2013/04/03 | [
"https://Stackoverflow.com/questions/15784537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2176228/"
] | For me the indentation is broken within 'prettyPrint' and in '**main**'. Also no need to use ';'. Try this:
```
#!/usr/bin/env python
import math
# Input: Two 3D points of the form (x,y,z).
# Output: Euclidean distance between the points.
def getDistance((x1, y1, z1), (x2, y2, z2)):
d = math.sqrt(pow((x1 - x2), 2)... | This:
```
if __name__ == "__main__":
main()
```
Should be:
```
if __name__ == "__main__":
main()
```
Also, the python interpreter will give you information on the IndentationError *down to the line*. I strongly suggest reading the error messages provided, as developers write them for a reason. |
15,784,537 | Purpose: Given a PDB file, prints out all pairs of Cysteine residues forming disulfide bonds in the tertiary protein structure. Licence: GNU GPL Written By: Eric Miller
```
#!/usr/bin/env python
import math
def getDistance((x1,y1,z1),(x2,y2,z2)):
d = math.sqrt(pow((x1-x2),2)+pow((y1-y2),2)+pow((z1-z2),2));
retu... | 2013/04/03 | [
"https://Stackoverflow.com/questions/15784537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2176228/"
] | For me the indentation is broken within 'prettyPrint' and in '**main**'. Also no need to use ';'. Try this:
```
#!/usr/bin/env python
import math
# Input: Two 3D points of the form (x,y,z).
# Output: Euclidean distance between the points.
def getDistance((x1, y1, z1), (x2, y2, z2)):
d = math.sqrt(pow((x1 - x2), 2)... | You didn't say where the error was flagged to be but:
```
if __name__ == "__main__":
main()
```
Should be:
```
if __name__ == "__main__":
main()
``` |
72,060,798 | In python I am trying to lookup the relevant price depending on qty from a list of scale prices. For example when getting a quotation request:
```
Product Qty Price
0 A 6
1 B 301
2 C 1
3 D 200
4 E 48
```
Price list with scale prices:
```
Product Scale Qty Scale Price... | 2022/04/29 | [
"https://Stackoverflow.com/questions/72060798",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18991198/"
] | Try with `merge_asof`:
```
output = (pd.merge_asof(df2.sort_values("Qty"),df1.sort_values("Scale Qty"),left_on="Qty",right_on="Scale Qty",by="Product")
.sort_values("Product", ignore_index=True)
.drop("Scale Qty", axis=1)
.rename(columns={"Scale Price":"Price"}))
>>> output
Product Qt... | Assuming `df1` and `df2`, use `merge_asof`:
```
pd.merge_asof(df1.sort_values(by='Qty'),
df2.sort_values(by='Scale Qty').rename(columns={'Scale Price': 'Price'}),
by='Product', left_on='Qty', right_on='Scale Qty')
```
output:
```
Product Qty Scale Qty Price
0 C 1 1... |
58,143,742 | I'm working on a project using keras (python 3), and I've encountered a problem - I've installed using pip tensorflow, and imported it into my prject, but whenether I try to run it, I get an error saying:
```
ModuleNotFoundError: No module named 'tensorflow'
```
it seems my installation completed successfully, and I... | 2019/09/28 | [
"https://Stackoverflow.com/questions/58143742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9126289/"
] | Use [`Series.str.replace`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html) with replace `uppercase` by same vales with space before and then remove first space:
```
df = pd.DataFrame({'U.N.Region':['WestAfghanistan','NorthEastAfghanistan']})
df['U.N.Region'] = df['U.N.Region'... | Another option would be,
```
import pandas as pd
import re
df = pd.DataFrame({'U.N.Region': ['WestAfghanistan', 'NorthEastAfghanistan']})
df['U.N.Region'] = df['U.N.Region'].str.replace(
r"(?<=[a-z])(?=[A-Z])", " ")
print(df)
``` |
58,143,742 | I'm working on a project using keras (python 3), and I've encountered a problem - I've installed using pip tensorflow, and imported it into my prject, but whenether I try to run it, I get an error saying:
```
ModuleNotFoundError: No module named 'tensorflow'
```
it seems my installation completed successfully, and I... | 2019/09/28 | [
"https://Stackoverflow.com/questions/58143742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9126289/"
] | Use [`Series.str.replace`](http://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.replace.html) with replace `uppercase` by same vales with space before and then remove first space:
```
df = pd.DataFrame({'U.N.Region':['WestAfghanistan','NorthEastAfghanistan']})
df['U.N.Region'] = df['U.N.Region'... | Yet another solution:
```
df.apply(lambda col: col.str.replace(r"([a-z])([A-Z])",r"\1 \2"))
Out:
U.N. Region Centers
0 North East Afghanistan Fayzabad
1 West Afghanistan Qala Naw
``` |
58,143,742 | I'm working on a project using keras (python 3), and I've encountered a problem - I've installed using pip tensorflow, and imported it into my prject, but whenether I try to run it, I get an error saying:
```
ModuleNotFoundError: No module named 'tensorflow'
```
it seems my installation completed successfully, and I... | 2019/09/28 | [
"https://Stackoverflow.com/questions/58143742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9126289/"
] | Yet another solution:
```
df.apply(lambda col: col.str.replace(r"([a-z])([A-Z])",r"\1 \2"))
Out:
U.N. Region Centers
0 North East Afghanistan Fayzabad
1 West Afghanistan Qala Naw
``` | Another option would be,
```
import pandas as pd
import re
df = pd.DataFrame({'U.N.Region': ['WestAfghanistan', 'NorthEastAfghanistan']})
df['U.N.Region'] = df['U.N.Region'].str.replace(
r"(?<=[a-z])(?=[A-Z])", " ")
print(df)
``` |
40,138,090 | My data is organized in a dataframe:
```
import pandas as pd
import numpy as np
data = {'Col1' : [4,5,6,7], 'Col2' : [10,20,30,40], 'Col3' : [100,50,-30,-50], 'Col4' : ['AAA', 'BBB', 'AAA', 'CCC']}
df = pd.DataFrame(data=data, index = ['R1','R2','R3','R4'])
```
Which looks like this (only much bigger):
```
Co... | 2016/10/19 | [
"https://Stackoverflow.com/questions/40138090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2301970/"
] | The tint property does not affect the color of the title. To set the title color (along with other attributes like font) globally, you can set the `titleTextAttributes` property of the `UINavigationBar` appearance to suit your needs. Just place this code in your AppDelegate or somewhere else appropriate that gets calle... | No you work correctly. But you should to set color for second view. You can use this code to solve your problem.
In second view write this code to set color and font for your navigation title.
---
```
navigationController!.navigationBar.titleTextAttributes = ([NSFontAttributeName: UIFont(name: "Helvetica", size: 25)!... |
29,035,115 | I am working with an existing SQLite database and experiencing errors due to the data being encoded in CP-1252, when Python is expecting it to be UTF-8.
```
>>> import sqlite3
>>> conn = sqlite3.connect('dnd.sqlite')
>>> curs = conn.cursor()
>>> result = curs.execute("SELECT * FROM dnd_characterclass WHERE id=802")
Tr... | 2015/03/13 | [
"https://Stackoverflow.com/questions/29035115",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1191425/"
] | SQLAlchemy and SQLite are behaving normally. The solution is to fix the non-UTF-8 data in the database.
I wrote the below, drawing inspiration from <https://stackoverflow.com/a/2395414/1191425> . It:
* loads up the target SQLite database
* lists all columns in all tables
* if the column is a `text`, `char`, or `clob`... | If you have a connection URI then you can add the following options to your DB connection URI:
```
DB_CONNECTION = mysql+pymysql://{username}:{password}@{host}/{db_name}?{options}
DB_OPTIONS = {
"charset": "cp-1252",
"use_unicode": 1,
}
connection_uri = DB_CONNECTION.format(
username=???,
...,
opti... |
58,647,020 | I am trying to run the cvxpy package in an AWS lambda function. This package isn't in the SDK, so I've read that I'll have to compile the dependencies into a zip, and then upload the zip into the lambda function.
I've done some research and tried out the links below, but when I try to pip install cvxpy I get error mes... | 2019/10/31 | [
"https://Stackoverflow.com/questions/58647020",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10756193/"
] | For installing `cvxpy` on windows it requires c++ build tools (please refer: <https://buildmedia.readthedocs.org/media/pdf/cvxpy/latest/cvxpy.pdf>)
On Windows:
-----------
* I created a lambda layer python directory structure `python/lib/python3.7/site-packages` (refer: <https://docs.aws.amazon.com/lambda/latest/dg/c... | You can wrap all your dependencies along with lambda source into a single zipfile and deploy it. Doing this, you will end up having additional repetitive code in multiple lambda functions. Suppose, if more than one of your lambda functions needs the same package `cvxpy`, you will have to package it twice for both the f... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.