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 |
|---|---|---|---|---|---|
11,632,154 | In python if I have two dictionaries, specifically Counter objects that look like so
```
c1 = Counter({'item1': 4, 'item2':2, 'item3': 5, 'item4': 3})
c2 = Counter({'item1': 6, 'item2':2, 'item3': 1, 'item5': 9})
```
Can I combine these dictionaries so that the results is a dictionary of lists, as follows:
```
c3 =... | 2012/07/24 | [
"https://Stackoverflow.com/questions/11632154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/801348/"
] | Or with a list comprehension:
```
from collections import Counter
c1 = Counter({'item1': 4, 'item2':2, 'item3': 5, 'item4': 3})
c2 = Counter({'item1': 6, 'item2':2, 'item3': 1, 'item5': 9})
merged = {}
for k in set().union(c1, c2):
merged[k] = [d[k] for d in [c1, c2] if k in d]
>>> merged
{'item2': [2, 2], 'item3... | You can use `defaultdict`:
```
>>> from collections import Counter, defaultdict
>>> c1 = Counter({'item1': 4, 'item2':2, 'item3': 5, 'item4': 3})
>>> c2 = Counter({'item1': 6, 'item2':2, 'item3': 1, 'item5': 9})
>>> c3 = defaultdict(list)
>>> for c in c1, c2:
... for k, v in c.items():
... c3[k].append(v)
... |
51,745,894 | I am new to using python, and am wanting to be able to install packages for python using pip. I am having trouble running pip on my windows computer. When typing in "pip --version" into command prompt I get:
```
ModuleNotFoundError: No module named 'pip._internal'; 'pip' is not a package
```
I have added the scripts... | 2018/08/08 | [
"https://Stackoverflow.com/questions/51745894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6814024/"
] | Force a reinstall of pip:
```
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python3 get-pip.py --force-reinstall
```
For windows you may have to `choco install curl` or set PATH to where python3 is located | In cmd try using
`py -3.6 -m pip install pygmae`
replace 3.6 with your version of python and add -32 fot 32 bit version
```
py -3.6-32 pip install pygame
```
replace pygame with the module you want to install
this works for most people using python on windows also reboot your pc after adding system variable pat... |
62,713,607 | I deployed an Azure Functions App with Python `3.8`. Later on I tried to use dataclasses and it failed with the exception that the version available does not support dataclasses. I then SSHed to the host of the Function App and by using `python --version` figured out that version `3.6` was actually installed. As datacl... | 2020/07/03 | [
"https://Stackoverflow.com/questions/62713607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7009990/"
] | This is a known issue (see e.g. <https://learn.microsoft.com/en-us/answers/questions/39124/azure-functions-always-using-python-36.html>) and hopefully fixed soon.
As workaround you can run the following command e.g. in the Cloud shell:
`az functionapp config set --name <func app name> --resource-group <rg name> --sub... | For anyone running into this problem downgrading to Python 3.6 is a workaround.
I tried @quervernetzt solution but it didn't work, my pipelines started giving the following error.
```
##[error]Error: Error: Failed to deploy web package to App Service. Conflict (CODE: 409)
``` |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | Based on the ex48 instructions, you could create a few lists for each kind of word. Here's a sample for the first test case. The returned value is a list of tuples, so you can append to that list for each word given.
```
direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back']
class Lexic... | Like the most here I am new to the world of coding and I though I attach my solution below as it might help other students.
I already saw a few more efficient approaches that I could implement. However, the code handles every use case of the exercise and since I am wrote it on my own with my beginners mind it does no... |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | This is a really cool exercise. I had to research for days and finally got it working. The other answers here don't show how to actually use a list with tuples inside like the e-book sugests, so this will do it like that. Owner's answer doesn't quite work, lexicon[word] asks for interger and not str.
```
lexicon = [('... | clearly Lexicon is another python file in ex48 folder.
>
>
> ```
> like: ex48
> ----lexicon.py
>
> ```
>
>
so you are importing lexicon.py from ex 48 folder.
scan is a function inside lexicon.py |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | I wouldn't use a list to make the lexicon. You're mapping words to their types, so make a dictionary.
Here's the biggest hint that I can give without writing the entire thing:
```
lexicon = {
'north': 'directions',
'south': 'directions',
'east': 'directions',
'west': 'directions',
'go': 'verbs',
... | clearly Lexicon is another python file in ex48 folder.
>
>
> ```
> like: ex48
> ----lexicon.py
>
> ```
>
>
so you are importing lexicon.py from ex 48 folder.
scan is a function inside lexicon.py |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | Finally I did it!
```
lexicon = {
('directions', 'north'),
('directions', 'south'),
('directions', 'east'),
('directions', 'west'),
('verbs', 'go'),
('verbs', 'stop'),
('verbs', 'look'),
('verbs', 'give'),
('stops', 'the'),
('stops', 'in'),
('stops', 'of'),
('stops', 'fr... | Like the most here I am new to the world of coding and I though I attach my solution below as it might help other students.
I already saw a few more efficient approaches that I could implement. However, the code handles every use case of the exercise and since I am wrote it on my own with my beginners mind it does no... |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | This is a really cool exercise. I had to research for days and finally got it working. The other answers here don't show how to actually use a list with tuples inside like the e-book sugests, so this will do it like that. Owner's answer doesn't quite work, lexicon[word] asks for interger and not str.
```
lexicon = [('... | This is my version of scanning lexicon for ex48. I am also beginner in programming, python is my first language. So the program may not be efficient for its purpose, anyway the result is good after many testing. Please feel free to improve the code.
**WARNING**
===========
If you haven't try to do the exercise by you... |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | Finally I did it!
```
lexicon = {
('directions', 'north'),
('directions', 'south'),
('directions', 'east'),
('directions', 'west'),
('verbs', 'go'),
('verbs', 'stop'),
('verbs', 'look'),
('verbs', 'give'),
('stops', 'the'),
('stops', 'in'),
('stops', 'of'),
('stops', 'fr... | This is my version of scanning lexicon for ex48. I am also beginner in programming, python is my first language. So the program may not be efficient for its purpose, anyway the result is good after many testing. Please feel free to improve the code.
**WARNING**
===========
If you haven't try to do the exercise by you... |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | Based on the ex48 instructions, you could create a few lists for each kind of word. Here's a sample for the first test case. The returned value is a list of tuples, so you can append to that list for each word given.
```
direction = ['north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back']
class Lexic... | clearly Lexicon is another python file in ex48 folder.
>
>
> ```
> like: ex48
> ----lexicon.py
>
> ```
>
>
so you are importing lexicon.py from ex 48 folder.
scan is a function inside lexicon.py |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | Like the most here I am new to the world of coding and I though I attach my solution below as it might help other students.
I already saw a few more efficient approaches that I could implement. However, the code handles every use case of the exercise and since I am wrote it on my own with my beginners mind it does no... | This is my version of scanning lexicon for ex48. I am also beginner in programming, python is my first language. So the program may not be efficient for its purpose, anyway the result is good after many testing. Please feel free to improve the code.
**WARNING**
===========
If you haven't try to do the exercise by you... |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | This is a really cool exercise. I had to research for days and finally got it working. The other answers here don't show how to actually use a list with tuples inside like the e-book sugests, so this will do it like that. Owner's answer doesn't quite work, lexicon[word] asks for interger and not str.
```
lexicon = [('... | Like the most here I am new to the world of coding and I though I attach my solution below as it might help other students.
I already saw a few more efficient approaches that I could implement. However, the code handles every use case of the exercise and since I am wrote it on my own with my beginners mind it does no... |
15,424,895 | I'm new here in the world of coding and I haven't received a very warm welcome. I've been trying to learn python via the online tutorial <http://learnpythonthehardway.org/book/>. I've been able to struggle my way through the book up until exercise 48 & 49. That's where he turns students loose and says "You figure it ou... | 2013/03/15 | [
"https://Stackoverflow.com/questions/15424895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2172498/"
] | I wouldn't use a list to make the lexicon. You're mapping words to their types, so make a dictionary.
Here's the biggest hint that I can give without writing the entire thing:
```
lexicon = {
'north': 'directions',
'south': 'directions',
'east': 'directions',
'west': 'directions',
'go': 'verbs',
... | Like the most here I am new to the world of coding and I though I attach my solution below as it might help other students.
I already saw a few more efficient approaches that I could implement. However, the code handles every use case of the exercise and since I am wrote it on my own with my beginners mind it does no... |
12,424,351 | I want to run a shell command from python and receive its output with subprocess.Popen. The problem is, when I close the process, sending Ctrl-C, I don't get any output. What am I doing wrong? Code:
```
>>> import subprocess
>>> sub = subprocess.Popen(["xinput", "test", "8"], stdout=subprocess.PIPE) #receive mouse eve... | 2012/09/14 | [
"https://Stackoverflow.com/questions/12424351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1360544/"
] | The issue here is that the `KeyboardInterrupt` is sent during the call to `communicate`. As a result, `communicate` never returns and so it's output is never stored in the variable `output` and you get the `NameError` when you try to use it. One workaround would be the following:
```
import subprocess
sub = subproce... | @pythonm already explained the `NameError`.
Furthermore, you're using the output of `Popen.communicate()` conceptually wrong. It returns a 2-tuple of strings: `(stdout, stderr)`. It does not return two file-like objects. That's why your `sub.communicate()[0].read()` would fail if `communicate()` returned.
Until the ... |
65,495,956 | I have searched far and wide, and have followed just about everything... I cannot figure out why this keeps happening to my Python package I've created. It's not a simple "install dependency and you're good" as it's my own project I am attempting to create.
Here's my file structure:
```
-jarvis-discord
--jarvis_disco... | 2020/12/29 | [
"https://Stackoverflow.com/questions/65495956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13002900/"
] | If you are using relative file paths, you have to use
`from .cogs import (`
because it jarvis.py can't see jarvis\_discord\_bot from one level below.
The . in front of cogs means that it is one level up. | Figured out what was the issue!
In my run file, I had to set `PYTHONPATH` from `PWD` to the actual folder of the project. Good luck to anyone reading this in the future! |
50,151,698 | i have two table like this:
```
table1
id(int) | desc(TEXT)
--------------------
0 | "desc1"
1 | "desc2"
table2
id(int) | table1_id(TEXT)
------------------------
0 | "0"
1 | "0;1"
```
i want to select data into table2 and replace table1\_id by the desc field in table1, when i have string wi... | 2018/05/03 | [
"https://Stackoverflow.com/questions/50151698",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5494686/"
] | You can convert the CSV value into an array, then join on that:
```
select string_agg(t1.descr, ',') as descr
from table2 t2
join table1 t1 on t1.id = any (string_to_array(t2.table1_id, ';')::int[])
where t2.id = 1
``` | That is really an abominable data design.
Consequently you will have to write a complicated query to get your desired result:
```
SELECT string_agg(table1."desc", ', ')
FROM table2
CROSS JOIN LATERAL regexp_split_to_table(table2.table1_id, ';') x(d)
JOIN table1 ON x.d::integer = table1.id
WHERE table2.id = 1;
... |
64,791,458 | Here is my docker-compose.yml used to create the database container.
```
version: '3.7'
services:
application:
build:
context: ./app
dockerfile: dockerfile #dockerfile-prod
depends_on:
- database_mongo
- database_neo4j
- etl_pipeline
environment:
- flask_env=dev #flas... | 2020/11/11 | [
"https://Stackoverflow.com/questions/64791458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14620901/"
] | Usually languages implement functionalities as simply as possible.
Class methods are under the hood just simple functions containing object pointer as an argument, where object in fact is just data structure + functions that can operate on this data structure.
Normally compiler knows which function should operate on ... | No, it does not. Functions are class-wide. When you allocate an object in C++ it will contain space for all its attributes plus a VTable with pointers to all its methods/functions, be it from its own class or inherited from parent classes.
When you call a method on that object, you essentially perform a look-up on tha... |
45,155,336 | I am running Ubuntu Desktop 16.04 on a VM and am trying to run [Volttron](https://github.com/VOLTTRON/volttron) using the standard install instructions, however I keep getting an error after the following steps:
```
sudo apt-get update
sudo apt-get install build-essential python-dev openssl libssl-dev libevent-dev git... | 2017/07/17 | [
"https://Stackoverflow.com/questions/45155336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8322226/"
] | I would recommend passing in the name of the value you would like to update into the handle change function, for example:
```
import React, { Component } from 'react'
import { Dropdown, Grid } from 'semantic-ui-react'
class DropdownExampleRemote extends Component {
componentWillMount() {
this.setState({
o... | Something along these lines can maybe work for you.
```
handleChange = (propName, e) => {
let state = Object.assign({}, state);
state[propName] = e.target.value;
this.setState(state)
}
```
You can pass in the name of the property you want to update and then use bracket notation to update that part of your stat... |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | Just run this to uninstall plotly and then build it from source. That should fix the import
```
pip uninstall plotly && python -m pip install plotly
``` | That sounds like a classic dependency issue.
* Check that your pip version is using the same python version (3.6) as what you launch your script with (IE: Use `python3(.6)` to launch your script, not just `python`)
* Your logs aren't showing plotly already installed. In fact, you probably forgot a line when pasting bu... |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | * First of all, Make sure your Python file is NOT called `plotly.py`
but something else.
* If you are using Anaconda, open Anaconda Navigator and launch cmd
prompt (cmd.exe) from there. Then run `pip install plotly` or
`conda install -c plotly` from that terminal window.
* Or just type `pip install plotly` it will inst... | That sounds like a classic dependency issue.
* Check that your pip version is using the same python version (3.6) as what you launch your script with (IE: Use `python3(.6)` to launch your script, not just `python`)
* Your logs aren't showing plotly already installed. In fact, you probably forgot a line when pasting bu... |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | Just run this to uninstall plotly and then build it from source. That should fix the import
```
pip uninstall plotly && python -m pip install plotly
``` | I could with:
```sh
conda install -c https://conda.anaconda.org/plotly plotly
``` |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | * First of all, Make sure your Python file is NOT called `plotly.py`
but something else.
* If you are using Anaconda, open Anaconda Navigator and launch cmd
prompt (cmd.exe) from there. Then run `pip install plotly` or
`conda install -c plotly` from that terminal window.
* Or just type `pip install plotly` it will inst... | I could with:
```sh
conda install -c https://conda.anaconda.org/plotly plotly
``` |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | Just run this to uninstall plotly and then build it from source. That should fix the import
```
pip uninstall plotly && python -m pip install plotly
``` | I did pip install plotly. It did not work.
Then, I just closed my jupyter-notebook from terminal and opened it again. It worked. Strangely restarting the kernel did not work! |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | * First of all, Make sure your Python file is NOT called `plotly.py`
but something else.
* If you are using Anaconda, open Anaconda Navigator and launch cmd
prompt (cmd.exe) from there. Then run `pip install plotly` or
`conda install -c plotly` from that terminal window.
* Or just type `pip install plotly` it will inst... | I did pip install plotly. It did not work.
Then, I just closed my jupyter-notebook from terminal and opened it again. It worked. Strangely restarting the kernel did not work! |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | Just run this to uninstall plotly and then build it from source. That should fix the import
```
pip uninstall plotly && python -m pip install plotly
``` | If you are using Jupyter notebook, try below:
```py
import sys
!conda install --yes --prefix {sys.prefix} plotly
``` |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | Just run this to uninstall plotly and then build it from source. That should fix the import
```
pip uninstall plotly && python -m pip install plotly
``` | best way is to
1-run anaconda navigator
2-go to environment
3- select all
4-and search plotly
5- if not their install it.
[](https://i.stack.imgur.com/hQF5i.png)
got my issue fixed |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | * First of all, Make sure your Python file is NOT called `plotly.py`
but something else.
* If you are using Anaconda, open Anaconda Navigator and launch cmd
prompt (cmd.exe) from there. Then run `pip install plotly` or
`conda install -c plotly` from that terminal window.
* Or just type `pip install plotly` it will inst... | If you are using Jupyter notebook, try below:
```py
import sys
!conda install --yes --prefix {sys.prefix} plotly
``` |
53,435,428 | After reading all the existing post related to this issue, i still did not manage to fix it.
```
ModuleNotFoundError: No module named 'plotly'
```
I have tried all the following:
```
pip3 install plotly
pip3 install plotly --upgrade
```
as well as uninstalling plotly with:
```
pip3 uninstall plotly
```
And re... | 2018/11/22 | [
"https://Stackoverflow.com/questions/53435428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10438271/"
] | * First of all, Make sure your Python file is NOT called `plotly.py`
but something else.
* If you are using Anaconda, open Anaconda Navigator and launch cmd
prompt (cmd.exe) from there. Then run `pip install plotly` or
`conda install -c plotly` from that terminal window.
* Or just type `pip install plotly` it will inst... | best way is to
1-run anaconda navigator
2-go to environment
3- select all
4-and search plotly
5- if not their install it.
[](https://i.stack.imgur.com/hQF5i.png)
got my issue fixed |
73,646,583 | In short, is there a pythonic way to write `SETTING_A = os.environ['SETTING_A']`?
I want to provide a module `environment.py` from which I can import constants that are read from environment variables.
##### Approach 1:
```
import os
try:
SETTING_A = os.environ['SETTING_A']
SETTING_B = os.environ['SETTING_B... | 2022/09/08 | [
"https://Stackoverflow.com/questions/73646583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10909217/"
] | You should describe the type of PersonDto:
```js
interface PersonDto {
id: string;
name: string;
country: string;
}
class Person {
private id: string;
private name: string;
private country: string;
constructor(personDto: PersonDto) {
this.id = personDto.id;
this.name = personDto.name;
this.... | Try [`Object.assign`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign) to not have to type every property.
```typescript
interface PersonDto {
id: string;
name: string;
country: string;
}
class Person {
private id: string;
private name: string;
private countr... |
21,890,220 | tried multiplication of 109221975\*123222821 in python 2.7 prompt in two different ways
```
Python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 109221975*123222821
13458639874691475L
>>> 109221975*123222821.0
1.3458639874691476... | 2014/02/19 | [
"https://Stackoverflow.com/questions/21890220",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1955093/"
] | Your `int` is 54 bits long. `float` can hold 53 significant digits, so effectively the last digit is rounded to an even number.
Internally, your float is represented as:
>
> 2225720309975242\*2-1
>
>
>
Your `int` and `float` is stored in binary like the following:
```
101111110100001000111111001000... | Because `int` in python has infinite precision, but `float` does not. (`float` is a double precision floating point number, which has 53 bits of precision.) |
21,890,220 | tried multiplication of 109221975\*123222821 in python 2.7 prompt in two different ways
```
Python 2.7.3 (default, Sep 26 2013, 20:08:41)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 109221975*123222821
13458639874691475L
>>> 109221975*123222821.0
1.3458639874691476... | 2014/02/19 | [
"https://Stackoverflow.com/questions/21890220",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1955093/"
] | Once upon a time, there was a string named `st` that wanted to be a number. What number should I be said st?
The string's fairy god mother said: Well st, if you want to be an accurate number, a number for counting whole things, I would be an arbitrary precision integer:
```
>>> st='123456789123456789'
>>> int(st)
123... | Because `int` in python has infinite precision, but `float` does not. (`float` is a double precision floating point number, which has 53 bits of precision.) |
66,395,018 | I am new to python. at the moment I am coding a game with a friend. we are currently working on a combat system the only problem is we don't know how to update the the enemy's health once damage has been dealt. The code is as following.
```
enemy1_health = 150
broadsword_attack = 20
rusty_knife = 10.5
attacks = ["b... | 2021/02/27 | [
"https://Stackoverflow.com/questions/66395018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15293735/"
] | You need to change the enemy health outside of the print statement with a statement like this:
```
enemy1_health = enemy1_health - 20
```
or like this, which does the same thing:
```
enemy1_health -= 20
```
You also reset enemy1\_health every time the loop loops, remove that.
You don't define player\_health, def... | You need to change the enemy health outside the print statement.
do:
```
if attackchoice == ("rusty knife jab"):
enemy1_health = enemy1_health - 10.5
print(enemy1_health)
```
and you can do the same for the other attacks.
You also have enemy health defined in the while loop. you need to define it outside o... |
66,395,018 | I am new to python. at the moment I am coding a game with a friend. we are currently working on a combat system the only problem is we don't know how to update the the enemy's health once damage has been dealt. The code is as following.
```
enemy1_health = 150
broadsword_attack = 20
rusty_knife = 10.5
attacks = ["b... | 2021/02/27 | [
"https://Stackoverflow.com/questions/66395018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15293735/"
] | You have to define the health above the while loops like this :
```
broadsword_attack = 20
rusty_knife = 10.5
attacks = ["broadsword swing " + str(broadsword_attack), "rusty knife jab " + str(rusty_knife) ]
enemy1_health = 150
while enemy1_health > 0:
while player_health > 0:
print(attacks)
attackchoice ... | You need to change the enemy health outside the print statement.
do:
```
if attackchoice == ("rusty knife jab"):
enemy1_health = enemy1_health - 10.5
print(enemy1_health)
```
and you can do the same for the other attacks.
You also have enemy health defined in the while loop. you need to define it outside o... |
44,659,242 | During development of Pylint, we encountered [interesting problem related to non-dependency that may break `pylint` package](https://github.com/PyCQA/pylint/issues/1318).
Case is following:
* `python-future` had a conflicting alias to `configparser` package. [Quoting official docs](http://python-future.org/whatsnew.h... | 2017/06/20 | [
"https://Stackoverflow.com/questions/44659242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2912340/"
] | ```
kw = {}
try:
import future
except ImportError:
pass
else:
kw['install_requires'] = ['future>=0.16']
setup(
…
**kw
)
``` | One workaround for this issue is to define this requirement only for the `all` target, so only if someone adds `pylint[all]>=1.2.3` as a requirement they will have futures installed/upgraded.
At this moment I don't know another way to "ignore or upgrade" a dependency.
Also, I would avoid adding Python code to `setup.... |
44,659,242 | During development of Pylint, we encountered [interesting problem related to non-dependency that may break `pylint` package](https://github.com/PyCQA/pylint/issues/1318).
Case is following:
* `python-future` had a conflicting alias to `configparser` package. [Quoting official docs](http://python-future.org/whatsnew.h... | 2017/06/20 | [
"https://Stackoverflow.com/questions/44659242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2912340/"
] | ```
kw = {}
try:
import future
except ImportError:
pass
else:
kw['install_requires'] = ['future>=0.16']
setup(
…
**kw
)
``` | There is no supported way to tell pip or setuptools that a package needs to satisfy a constraint only if installed. There might be some hacks but I imagine they'll all be fragile and likely breaking in the future versions of pip/setuptools.
Honestly, the only *good* way is to document it for users that `future < 16.0`... |
37,369,079 | I have a lab colorspace
[](https://i.stack.imgur.com/3pXgm.png)
And I want to "bin" the colorspace in a grid of 10x10 squares.
So the first bin might be (-110,-110) to (-100,-100) then the next one might be (-100,-110) to (-90,-100) and so on. The... | 2016/05/21 | [
"https://Stackoverflow.com/questions/37369079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1123905/"
] | The answer is to not use SSTATE\_DUPWHITELIST for this at all. Instead, in the libftdi recipe's do\_install (or do\_install\_append, if the recipe itself doesn't define its own do\_install) you should delete the duplicate files from within ${D} and then they won't get staged and the error won't occur. | I managed to solve this problem by adding the SSTATE\_DUPWHITELIST to the bitbake recipe of the package as follows:
SSTATE\_DUPWHITELIST = "${TMPDIR}/PATH/TO/THE/FILES"
I added the absolute path of all of the 6,7 files that had the conflict to the list. I did that because they were basically coming from a same source... |
37,369,079 | I have a lab colorspace
[](https://i.stack.imgur.com/3pXgm.png)
And I want to "bin" the colorspace in a grid of 10x10 squares.
So the first bin might be (-110,-110) to (-100,-100) then the next one might be (-100,-110) to (-90,-100) and so on. The... | 2016/05/21 | [
"https://Stackoverflow.com/questions/37369079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1123905/"
] | I got it to work by using:
SSTATE\_DUPWHITELIST = "/"
Dont forget the quotes. Here's my bb excerpt:
```
SSTATE_DUPWHITELIST = "/"
DEPENDS = ""
do_unpack() {
mkdir -pv ${S}
tar xvf ${DL_DIR}/${FILENAME}.tar -C ${S}
}
do_install() {
install -d -m 755 ${D}${includedir}
install -m 644 ${S}/${MYPATH}... | I managed to solve this problem by adding the SSTATE\_DUPWHITELIST to the bitbake recipe of the package as follows:
SSTATE\_DUPWHITELIST = "${TMPDIR}/PATH/TO/THE/FILES"
I added the absolute path of all of the 6,7 files that had the conflict to the list. I did that because they were basically coming from a same source... |
37,369,079 | I have a lab colorspace
[](https://i.stack.imgur.com/3pXgm.png)
And I want to "bin" the colorspace in a grid of 10x10 squares.
So the first bin might be (-110,-110) to (-100,-100) then the next one might be (-100,-110) to (-90,-100) and so on. The... | 2016/05/21 | [
"https://Stackoverflow.com/questions/37369079",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1123905/"
] | The answer is to not use SSTATE\_DUPWHITELIST for this at all. Instead, in the libftdi recipe's do\_install (or do\_install\_append, if the recipe itself doesn't define its own do\_install) you should delete the duplicate files from within ${D} and then they won't get staged and the error won't occur. | I got it to work by using:
SSTATE\_DUPWHITELIST = "/"
Dont forget the quotes. Here's my bb excerpt:
```
SSTATE_DUPWHITELIST = "/"
DEPENDS = ""
do_unpack() {
mkdir -pv ${S}
tar xvf ${DL_DIR}/${FILENAME}.tar -C ${S}
}
do_install() {
install -d -m 755 ${D}${includedir}
install -m 644 ${S}/${MYPATH}... |
70,008,841 | I was able to follow this example1 and let my ec2 instance read from S3.
In order to write to the same bucket I thought changing line 572 from `grant_read()` to `grant_read_write()`
should work.
```py
...
# Userdata executes script from S3
instance.user_data.add_execute_file_command(
... | 2021/11/17 | [
"https://Stackoverflow.com/questions/70008841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1172907/"
] | This is the [documentation](https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_s3_assets/Asset.html) for Asset:
>
> An asset represents a local file or directory, which is automatically
> uploaded to S3 and then can be referenced within a CDK application.
>
>
>
The method grant\_read\_write isn't provi... | an asset is just a Zip file that will be uploded to the bootstraped CDK s3 bucket, then referenced by Cloudformation when deploying.
if you have an script you want ot put into an s3 bucket, you dont want to use any form of asset cause that is a zip file. You would be better suited using a boto3 command to upload it on... |
2,433,703 | I am running Cygwin Python version 2.5.2.
I have a three-line source file, called import.py:
```
#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
```
When I execute "python import.py", it works:
```
C:\Temp>python import.py
Success!
```
When I run the python interpreter and type the commands... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2433703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5397/"
] | Probably py extension is connected to some other python interpreter than the one in /usr/bin/python | Try:
```
./import.py
```
Most people don't have "." in their path.
just typing python will call the cygwin python.
import.py will likely call whichever python is associated with .py files under windows.
You are using two different python executables. |
2,433,703 | I am running Cygwin Python version 2.5.2.
I have a three-line source file, called import.py:
```
#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
```
When I execute "python import.py", it works:
```
C:\Temp>python import.py
Success!
```
When I run the python interpreter and type the commands... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2433703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5397/"
] | I have the feeling that
```
C:\Temp>import.py
```
uses a different interpreter. Can you try with the following scripts:
```
#!/usr/bin/env python
import sys
print sys.executable
import xml.etree.ElementTree as ET
print "Success!"
``` | Try:
```
./import.py
```
Most people don't have "." in their path.
just typing python will call the cygwin python.
import.py will likely call whichever python is associated with .py files under windows.
You are using two different python executables. |
2,433,703 | I am running Cygwin Python version 2.5.2.
I have a three-line source file, called import.py:
```
#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
```
When I execute "python import.py", it works:
```
C:\Temp>python import.py
Success!
```
When I run the python interpreter and type the commands... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2433703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5397/"
] | Probably py extension is connected to some other python interpreter than the one in /usr/bin/python | Create a batch file next to your program that calls it the right way ... and I'm fairly sure you've got the problem because of an ambiguity between "windows python" (a python interpreter compiled for windows) and "cygwin python" (a python interpreter running on cygwin). |
2,433,703 | I am running Cygwin Python version 2.5.2.
I have a three-line source file, called import.py:
```
#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
```
When I execute "python import.py", it works:
```
C:\Temp>python import.py
Success!
```
When I run the python interpreter and type the commands... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2433703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5397/"
] | I have the feeling that
```
C:\Temp>import.py
```
uses a different interpreter. Can you try with the following scripts:
```
#!/usr/bin/env python
import sys
print sys.executable
import xml.etree.ElementTree as ET
print "Success!"
``` | Probably py extension is connected to some other python interpreter than the one in /usr/bin/python |
2,433,703 | I am running Cygwin Python version 2.5.2.
I have a three-line source file, called import.py:
```
#!/usr/bin/python
import xml.etree.ElementTree as ET
print "Success!"
```
When I execute "python import.py", it works:
```
C:\Temp>python import.py
Success!
```
When I run the python interpreter and type the commands... | 2010/03/12 | [
"https://Stackoverflow.com/questions/2433703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5397/"
] | I have the feeling that
```
C:\Temp>import.py
```
uses a different interpreter. Can you try with the following scripts:
```
#!/usr/bin/env python
import sys
print sys.executable
import xml.etree.ElementTree as ET
print "Success!"
``` | Create a batch file next to your program that calls it the right way ... and I'm fairly sure you've got the problem because of an ambiguity between "windows python" (a python interpreter compiled for windows) and "cygwin python" (a python interpreter running on cygwin). |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | At `{virtualenv}/lib/python2.7/site-packages/` (if not using virtualenv then `{system_dir}/lib/python2.7/dist-packages/`)
* Remove the egg file (e.g. `distribute-0.6.34-py2.7.egg`)
* If there is any from file `easy-install.pth`, remove the corresponding line (it should be a path to the source directory or of an egg fi... | **Install from local**
`python setup.py install`
**Uninstall from local**
`pip uninstall mypackage` |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | I think you can open the setup.py, locate the package name, and then ask pip to uninstall it.
Assuming the name is available in a 'METADATA' variable:
```
pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")
``` | **Install from local**
`python setup.py install`
**Uninstall from local**
`pip uninstall mypackage` |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | Probably you can do this as an alternative :-
1) Get the python version -
```
[linux machine]# python
Python 2.4.3 (#1, Jun 18 2012, 14:38:55)
```
-> The above command gives you the current python Version which is **2.4.3**
2) Get the installation directory of python -
```
[linux machine]# whereis python
python:... | It might be better to remove related files by using bash to read commands, like the following:
```
sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"
``` |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | Go to your python package directory and remove your .egg file,
e.g.:
In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/
In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/ | I think you can open the setup.py, locate the package name, and then ask pip to uninstall it.
Assuming the name is available in a 'METADATA' variable:
```
pip uninstall $(python -c "from setup import METADATA; print METADATA['name']")
``` |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | Now python gives you the choice to install `pip` during the installation (I am on Windows, and at least python does so for Windows!). Considering you had chosen to install `pip` during installation of python (you don't actually have to choose because it is default), `pip` is already installed for you. Then, type in `pi... | **Install from local**
`python setup.py install`
**Uninstall from local**
`pip uninstall mypackage` |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | For me, the following mostly works:
have pip installed, e.g.:
```
$ easy_install pip
```
Check, how is your installed package named from pip point of view:
```
$ pip freeze
```
This shall list names of all packages, you have installed (and which were detected by pip).
The name can be sometime long, then use just... | Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here's what I do...
```
for i in $(less install.record);
sudo rm $i;
done;
```
And presto. Uninstalled. |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | First record the files you have installed. You can repeat this command, even if you have previously run `setup.py install`:
```
python setup.py install --record files.txt
```
When you want to uninstall you can just:
```
sudo rm $(cat files.txt)
```
This works because the rm command takes a whitespace-seperated li... | I had run "python setup.py install" at some point in the past accidentally in my global environment, and had much difficulty uninstalling. These solutions didn't help. "pip uninstall " didn't work with "Can't uninstall 'splunk-appinspect'. No files were found to uninstall." "sudo pip uninstall " didn't work "Cannot uni... |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | Not exactly answering the question, but something that helps me every day:
Install your packages with
```
pip install .
```
This puts the package in `$HOME/.local`. Uninstall with
```
pip uninstall <package_name>
``` | Extending on what Martin said, recording the install output and a little bash scripting does the trick quite nicely. Here's what I do...
```
for i in $(less install.record);
sudo rm $i;
done;
```
And presto. Uninstalled. |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | Go to your python package directory and remove your .egg file,
e.g.:
In python 2.5(ubuntu): /usr/lib/python2.5/site-packages/
In python 2.6(ubuntu): /usr/local/lib/python2.6/dist-packages/ | **Install from local**
`python setup.py install`
**Uninstall from local**
`pip uninstall mypackage` |
1,550,226 | I have installed a python package with `python setup.py install`.
How do I uninstall it? | 2009/10/11 | [
"https://Stackoverflow.com/questions/1550226",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | Not exactly answering the question, but something that helps me every day:
Install your packages with
```
pip install .
```
This puts the package in `$HOME/.local`. Uninstall with
```
pip uninstall <package_name>
``` | It might be better to remove related files by using bash to read commands, like the following:
```
sudo python setup.py install --record files.txt
sudo bash -c "cat files.txt | xargs rm -rf"
``` |
49,093,290 | I'm trying to install Python 3 alongside 2.7 with Homebrew but am receiving an error message I can't find a resolution to.
When attempting `brew update && brew install python3` I get the following error:
```
Error: python 2.7.12_2 is already installed
To upgrade to 3.6.4_3, run `brew upgrade python`
```
I want to l... | 2018/03/04 | [
"https://Stackoverflow.com/questions/49093290",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3673055/"
] | You can press F9 inside [7zip](https://7zipguides.com/), you'll get two panes. In the first, you navigate to the archive you want to extract, and in the second you navigate to the folder where you want your files extracted. This will skip the temp folder step... | you can change **root** value in config/filesystems.php
```
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
``` |
69,476,449 | I was working with two instances of a python class when I realize they where using the same values. I think I have a missunderestanding of what classes are used for.
A much simpler example:
```
class C():
def __init__(self,err = []):
self.err = err
def add(self):
self.err.append(0)
a = C()... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69476449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11934583/"
] | The reason is here:
`def __init__(self,err = []):`
default `err` value is saved inside class `C`. But `err` itself is mutable, so every time you append anything to it, next time it will have stored value and this default `err` value is saved as `a.err` and `b.err`:
```
a = C()
print(a.err) # a.err is err ([])
... | I recommend that you check the Python core language *features* first. Check the official FAQs for Python 3, particularly <https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects> is what you are looking for.
According to the recommendations, you have to change your code like so
``... |
69,476,449 | I was working with two instances of a python class when I realize they where using the same values. I think I have a missunderestanding of what classes are used for.
A much simpler example:
```
class C():
def __init__(self,err = []):
self.err = err
def add(self):
self.err.append(0)
a = C()... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69476449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11934583/"
] | The reason is here:
`def __init__(self,err = []):`
default `err` value is saved inside class `C`. But `err` itself is mutable, so every time you append anything to it, next time it will have stored value and this default `err` value is saved as `a.err` and `b.err`:
```
a = C()
print(a.err) # a.err is err ([])
... | In here we want to identify a list is a mutable data structure in python. It is means we can change it as we want. Class is a blueprint of the object
so after creating the object it should be working individually<- this is your question. yeah typically it is correct but in here thing is when we
don't give the default v... |
69,476,449 | I was working with two instances of a python class when I realize they where using the same values. I think I have a missunderestanding of what classes are used for.
A much simpler example:
```
class C():
def __init__(self,err = []):
self.err = err
def add(self):
self.err.append(0)
a = C()... | 2021/10/07 | [
"https://Stackoverflow.com/questions/69476449",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11934583/"
] | I recommend that you check the Python core language *features* first. Check the official FAQs for Python 3, particularly <https://docs.python.org/3/faq/programming.html#why-are-default-values-shared-between-objects> is what you are looking for.
According to the recommendations, you have to change your code like so
``... | In here we want to identify a list is a mutable data structure in python. It is means we can change it as we want. Class is a blueprint of the object
so after creating the object it should be working individually<- this is your question. yeah typically it is correct but in here thing is when we
don't give the default v... |
46,906,854 | I just started to bash and I have been stuck for sometime on a simple if;then statement.
I use bash to run QIIME commands which are written in python. These commands allow me to deal with microbial DNA. From the raw dataset from the sequencing I first have to first check if they match the format that QIIME can deal wi... | 2017/10/24 | [
"https://Stackoverflow.com/questions/46906854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8759792/"
] | **Key idea :** You can add `UITapGestureRecognizer` to `UIImageView`. Setting up a `selector` which will be fired for each tap. In the `selector` you can check for the co-ordinate where the tap was done. If the co-ordinate satisfy your condition for firing up an event, you can execute your task then.
**Adding the gest... | Given a view (ora imageview) you should define a UIBezierPath of your shape.
Add a taprecognizer to this view, and set the same view as the recognizer delegate.
In the delegate method use UIBezierPath.contains(\_:) to know if the tap is inside the path or not and decide to fire the tap event or not.
Let me know if you... |
42,553,713 | Currently, I have some issue with Xcode and the proccess **IBDesignablesAgentCocoaTouch** freeze Xcode each time I edit Storyboard.
So, I want to kill this proccess with a bash or python script by checking every x seconds if this proccess is running.
I think I can use this script, but how to do with a timer ( each x ... | 2017/03/02 | [
"https://Stackoverflow.com/questions/42553713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4824110/"
] | Just use a while loop,
```
while sleep 20; do
pid=$(ps -fe | grep 'IBDesignablesAgentCocoaTouch' | awk '{print $2}')
if [[ -n $pid ]]; then
kill $pid
else
echo "Does not exist"
fi
done
```
The syntax `while sleep 20; do <code>` is similar to the one showed in comments `while true; do ... | Use this **If the process is named IBDesignablesAgentCocoaTouch**:
```
kill $(pgrep -x IBDesignablesAgentCocoaTouch)
```
If the process exists it will get killed, if not nothing will happen.
`pgrep` will get PID for you.
```
#!/bin/bash
while sleep 20; do
kill $(pgrep IBDesignablesAgentCocoaTouch)
done
```
I... |
42,553,713 | Currently, I have some issue with Xcode and the proccess **IBDesignablesAgentCocoaTouch** freeze Xcode each time I edit Storyboard.
So, I want to kill this proccess with a bash or python script by checking every x seconds if this proccess is running.
I think I can use this script, but how to do with a timer ( each x ... | 2017/03/02 | [
"https://Stackoverflow.com/questions/42553713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4824110/"
] | Just use a while loop,
```
while sleep 20; do
pid=$(ps -fe | grep 'IBDesignablesAgentCocoaTouch' | awk '{print $2}')
if [[ -n $pid ]]; then
kill $pid
else
echo "Does not exist"
fi
done
```
The syntax `while sleep 20; do <code>` is similar to the one showed in comments `while true; do ... | Have you tried to make it sleep for 20 seconds?
```bash
sleep 20
``` |
44,036,372 | Could anyone tell me what files I should download and which statements I must execute in the command line to install Matplotlib?
I have Python 2.7.13 on Windows 10 64 bit.
These are the files I unzipped:

All downloaded from: <http://www.lfd.uc... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44036372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5513436/"
] | Instead of iterating over a simple list of strings. You can store the section along with it's target element as an object then iterate.
```
<div id="introDiv"></div>
<div id="aboutDiv"></div>
<div id="linksDiv"></div>
var sections = [
{ section: "intro", target: "introDiv" },
{ section: "about", target: "abou... | Just set the Ajax to run synchronously, so the each loop will wait for your Ajax to finish before incrementing `counter`.
```
var counter = 1;
["intro","about","links"].each( function (index) {
var frag='<div id="id_'+counter+'"></div>\n";
$("#page").append(frag);
$.ajax({
url: "/data/"+index, ... |
44,036,372 | Could anyone tell me what files I should download and which statements I must execute in the command line to install Matplotlib?
I have Python 2.7.13 on Windows 10 64 bit.
These are the files I unzipped:

All downloaded from: <http://www.lfd.uc... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44036372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5513436/"
] | Instead of iterating over a simple list of strings. You can store the section along with it's target element as an object then iterate.
```
<div id="introDiv"></div>
<div id="aboutDiv"></div>
<div id="linksDiv"></div>
var sections = [
{ section: "intro", target: "introDiv" },
{ section: "about", target: "abou... | You don't need the `counter` variable, you can use `index` which should work as you want it to since you aren't incrementing it, rather it is managed by the loop.
I've not tested it, so I'm not sure if it works as expected.
```
["intro","about","links"].each( function (index) {
var frag='<div id="id_'+(index+1)... |
44,036,372 | Could anyone tell me what files I should download and which statements I must execute in the command line to install Matplotlib?
I have Python 2.7.13 on Windows 10 64 bit.
These are the files I unzipped:

All downloaded from: <http://www.lfd.uc... | 2017/05/17 | [
"https://Stackoverflow.com/questions/44036372",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5513436/"
] | Instead of iterating over a simple list of strings. You can store the section along with it's target element as an object then iterate.
```
<div id="introDiv"></div>
<div id="aboutDiv"></div>
<div id="linksDiv"></div>
var sections = [
{ section: "intro", target: "introDiv" },
{ section: "about", target: "abou... | Ideally you would have the server send the index back as part of the ajax response. Then you could just do something like this:
```
<div id="page"></div>
...
var counter = 1;
["intro","about","links"].each( function (index) {
var frag='<div id="id_'+counter+'"></div>\n";
$("#page").append(frag);
$.ajax({
... |
21,123,963 | I am trying to write a primes module in python. One thing I would like to be able to write is
```
>>> primes.primesLessThan(12)
[2, 3, 5, 7, 11]
```
However, I would also like to be able to write
```
>>> primes.primesLessThan.Sundaram(12)
[2, 3, 5, 7, 11]
```
to force it to use the Sieve of Sundaram. My original ... | 2014/01/14 | [
"https://Stackoverflow.com/questions/21123963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3195702/"
] | As a rule of thumb, if you have a class without any instance variables, an empty init method and just a bunch of static methods, then its probably going to be simpler to organize it as a module instead.
```
#sieves module
def Sundaram(n):
return [2,3,5,7]
def Eratosthenes(n):
return [2,3,5,7]
```
And then you c... | Two ways I can think of, to get these kinds of semantics.
* Make primes a class, and then make primesLessThan a property. It would also be a class, which implements `__iter__` etc. to simulate a list, while also having some subfunctions. primesLessThan would be a constructor to that class, with the argument having a d... |
42,230,269 | Searching for an alternative as OpenCV would not provide timestamps for **live** camera stream *(on Windows)*, which are required in my computer vision algorithm, I found ffmpeg and this excellent article <https://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/>
The solution uses ffm... | 2017/02/14 | [
"https://Stackoverflow.com/questions/42230269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/468716/"
] | Redirecting stderr works in python.
So instead of this `pipe = sp.Popen(command, stdout = sp.PIPE, stderr = sp.PIPE)`
do this `pipe = sp.Popen(command, stdout = sp.PIPE, stderr = sp.STDOUT)`
We could avoid redirection by adding an asynchronous call to read both the standard streams (stdout and stderr) of ffmpeg.... | You can use [MoviePy](http://zulko.github.io/moviepy/index.html):
```
import moviepy.editor as mpy
vid = mpy.VideoFileClip('e:\\sample.wmv')
for timestamp, raw_img in vid.iter_frames(with_times=True):
# do stuff
``` |
42,230,269 | Searching for an alternative as OpenCV would not provide timestamps for **live** camera stream *(on Windows)*, which are required in my computer vision algorithm, I found ffmpeg and this excellent article <https://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/>
The solution uses ffm... | 2017/02/14 | [
"https://Stackoverflow.com/questions/42230269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/468716/"
] | You can use [MoviePy](http://zulko.github.io/moviepy/index.html):
```
import moviepy.editor as mpy
vid = mpy.VideoFileClip('e:\\sample.wmv')
for timestamp, raw_img in vid.iter_frames(with_times=True):
# do stuff
``` | You can try to specify the buffer size so you're sure the whole frame fits in it :
```
bufsize = w*h*3 + 100
pipe = sp.Popen(command, bufsize=bufsize, stdout = sp.PIPE, stderr = sp.PIPE)
```
with this set up, you can normally read on pipe.stdout for your frames and pipe.stderr for its info |
42,230,269 | Searching for an alternative as OpenCV would not provide timestamps for **live** camera stream *(on Windows)*, which are required in my computer vision algorithm, I found ffmpeg and this excellent article <https://zulko.github.io/blog/2013/09/27/read-and-write-video-frames-in-python-using-ffmpeg/>
The solution uses ffm... | 2017/02/14 | [
"https://Stackoverflow.com/questions/42230269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/468716/"
] | Redirecting stderr works in python.
So instead of this `pipe = sp.Popen(command, stdout = sp.PIPE, stderr = sp.PIPE)`
do this `pipe = sp.Popen(command, stdout = sp.PIPE, stderr = sp.STDOUT)`
We could avoid redirection by adding an asynchronous call to read both the standard streams (stdout and stderr) of ffmpeg.... | You can try to specify the buffer size so you're sure the whole frame fits in it :
```
bufsize = w*h*3 + 100
pipe = sp.Popen(command, bufsize=bufsize, stdout = sp.PIPE, stderr = sp.PIPE)
```
with this set up, you can normally read on pipe.stdout for your frames and pipe.stderr for its info |
14,981,069 | How can I use [Brython](https://www.brython.info/) to compile Python to Javascript? I want to do this on my computer, so I can the run Javascript with nodejs, eg.
```
$ python hello.py
Hello world
$ brython hello.py -o hello.js
$ node hello.js
Hello world
```
The examples on the Brython website only explain how do t... | 2013/02/20 | [
"https://Stackoverflow.com/questions/14981069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/284795/"
] | It seems they are very browser oriented, there is no command line option out of the box.
You can try to use their code youself from node.js, perhaps it will work easily. It seems the `$py2js(src, module)` function does the actual conversion so maybe you can just run it with the python code string as first parameter.
... | Brython has a console that runs in the browser, but not a compiler. It is meant for you to either import your python scripts into the html file, or write your python code into the html file. See pyjs if you wish a conversion tool before the page loads. |
14,981,069 | How can I use [Brython](https://www.brython.info/) to compile Python to Javascript? I want to do this on my computer, so I can the run Javascript with nodejs, eg.
```
$ python hello.py
Hello world
$ brython hello.py -o hello.js
$ node hello.js
Hello world
```
The examples on the Brython website only explain how do t... | 2013/02/20 | [
"https://Stackoverflow.com/questions/14981069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/284795/"
] | It seems they are very browser oriented, there is no command line option out of the box.
You can try to use their code youself from node.js, perhaps it will work easily. It seems the `$py2js(src, module)` function does the actual conversion so maybe you can just run it with the python code string as first parameter.
... | It is possible to compile Python code to javascript and load it afterwards using import statement . See [brython:ticket:222](https://github.com/brython-dev/brython/issues/222) for further details. You'll have to load brython js lib in advance because , in the end, Python semantics are quite different from Javascript's ... |
14,981,069 | How can I use [Brython](https://www.brython.info/) to compile Python to Javascript? I want to do this on my computer, so I can the run Javascript with nodejs, eg.
```
$ python hello.py
Hello world
$ brython hello.py -o hello.js
$ node hello.js
Hello world
```
The examples on the Brython website only explain how do t... | 2013/02/20 | [
"https://Stackoverflow.com/questions/14981069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/284795/"
] | It is possible to compile Python code to javascript and load it afterwards using import statement . See [brython:ticket:222](https://github.com/brython-dev/brython/issues/222) for further details. You'll have to load brython js lib in advance because , in the end, Python semantics are quite different from Javascript's ... | Brython has a console that runs in the browser, but not a compiler. It is meant for you to either import your python scripts into the html file, or write your python code into the html file. See pyjs if you wish a conversion tool before the page loads. |
41,460,013 | ```
#!/usr/bin/env python2.7
import vobject
abfile='/foo/bar/directory/file.vcf' #ab stands for address book
ablist = []
with open(abfile) as source_file:
for vcard in vobject.readComponents(source_file):
ablist.append(vcard)
print ablist[0]==ablist[1]
```
Th... | 2017/01/04 | [
"https://Stackoverflow.com/questions/41460013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5965670/"
] | @Brian Barcelona, concerning your answer, just to let you know, instead of:
```
ablist = []
with open(abfile) as source_file:
for vcard in vobject.readComponents(source_file):
ablist.append(vcard)
```
You could do:
```
with open(abfile) as source_file:
ablist = list(vobject.readComponents(source_file... | I have found the following will work - the insight is to "serialize()" the vcard:
```
#!/usr/bin/env python2.7
import vobject
abfile='/foo/bar/directory/file.vcf' #ab stands for address book
ablist = []
with open(abfile) as source_file:
for vcard in vobject.readComponents(source_file):
ablist.append(v... |
32,652,485 | I'm trying to convert string date object to date object in python.
I did this so far
```
old_date = '01 April 1986'
new_date = datetime.strptime(old_date,'%d %M %Y')
print new_date
```
But I get the following error.
>
> ValueError: time data '01 April 1986' does not match format '%d %M %Y'
>
>
>
Any guess... | 2015/09/18 | [
"https://Stackoverflow.com/questions/32652485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2728494/"
] | `%M` parses *minutes*, a numeric value, not a month. Your date specifies the month as `'April'`, so use `%B` to parse a *named* month:
```
>>> from datetime import datetime
>>> old_date = '01 April 1986'
>>> datetime.strptime(old_date,'%d %B %Y')
datetime.datetime(1986, 4, 1, 0, 0)
```
From the [*`strftime()` and `... | You can first guess the type of date format the string is using and then convert to the same system recognised date format.
I wrote a simple date\_tools utilities that you can find here at [<https://github.com/henin/date_tools/]>
### Installation: pip install date-tools
### Usage:
>
> from date\_tools import date\_... |
64,934,782 | I am trying to read JSON File but it gives error as below
*Data reference:
<https://github.com/ankitgoel1602/data-science/blob/master/json-data/level_1.json>
<https://github.com/ankitgoel1602/data-science/blob/master/json-data/multiple_levels.json>*
Code
```
with open("multiple_levels.json", 'r') as j:
contents = j... | 2020/11/20 | [
"https://Stackoverflow.com/questions/64934782",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5866905/"
] | You will want to use something like `map` instead
This is a simply change to your code:
```
formatedCharcters = data.results.map(character => {
``` | I am not sure that I completely understand your question, but here is one way you could achieve the result you are probably looking for. I have kept the forEach loop in case there is a specific reason for keeping it:
```
// Json data example
function getCharacters() {
const data = {
info: {
count: 671,
... |
64,934,782 | I am trying to read JSON File but it gives error as below
*Data reference:
<https://github.com/ankitgoel1602/data-science/blob/master/json-data/level_1.json>
<https://github.com/ankitgoel1602/data-science/blob/master/json-data/multiple_levels.json>*
Code
```
with open("multiple_levels.json", 'r') as j:
contents = j... | 2020/11/20 | [
"https://Stackoverflow.com/questions/64934782",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5866905/"
] | Here's a guess of what you're trying to achieve. I think you're trying to map data into objects with a forEach loop. Sadly this is not possible with forEach , but rather with the map function instead. Let me know if this is what you wanted. I am willing to edit my answer depending on any other details.
```js
const... | I am not sure that I completely understand your question, but here is one way you could achieve the result you are probably looking for. I have kept the forEach loop in case there is a specific reason for keeping it:
```
// Json data example
function getCharacters() {
const data = {
info: {
count: 671,
... |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `count` is a string. Try `count = int(count)` | You should convert count to an int before comparing it to 10:
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if int(count) < 10:
x = count
else:
x = 'many'
print 'Number of donuts: %s' % x
def main():
donuts(sys.argv[1])
if __name__ == "__main__":
main()
``` |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `sys.argv` will only contain strings, even if you provide integers as arguments, so for example if you called this as `python donuts.py 4`, then `sys.argv[1]` would be `'4'` and you would attempt the comparison `'4' < 10` when you actually want `4 < 10`.
So first, try to convert `sys.argv[1]` to an int:
```
def main(... | You should convert count to an int before comparing it to 10:
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if int(count) < 10:
x = count
else:
x = 'many'
print 'Number of donuts: %s' % x
def main():
donuts(sys.argv[1])
if __name__ == "__main__":
main()
``` |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `count` is a string. Try `count = int(count)` | Try converting the `count` parameter to an int for the comparison:
```
if int (count) < 10:
x = str (count)
else:
x = 'many'
```
Because you're passing in a string argument for the `count` parameter, the comparison is failing. |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `sys.argv` will only contain strings, even if you provide integers as arguments, so for example if you called this as `python donuts.py 4`, then `sys.argv[1]` would be `'4'` and you would attempt the comparison `'4' < 10` when you actually want `4 < 10`.
So first, try to convert `sys.argv[1]` to an int:
```
def main(... | `count` is a string. Try `count = int(count)` |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `count` is a string. Try `count = int(count)` | You don't take the input in as an integer to begin with.
Change:
```
def main():
donuts(sys.argv[1])
```
to:
```
def main():
donuts(int(sys.argv[1]))
```
You will run into an issue if they put in a string or decimal instead of a numerical value, though. |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `sys.argv` will only contain strings, even if you provide integers as arguments, so for example if you called this as `python donuts.py 4`, then `sys.argv[1]` would be `'4'` and you would attempt the comparison `'4' < 10` when you actually want `4 < 10`.
So first, try to convert `sys.argv[1]` to an int:
```
def main(... | Try converting the `count` parameter to an int for the comparison:
```
if int (count) < 10:
x = str (count)
else:
x = 'many'
```
Because you're passing in a string argument for the `count` parameter, the comparison is failing. |
10,049,054 | I want it to give 'Number of donuts: many' when the argument is more than 10 and 'Number of donuts: ' when the argument is count<10. But it always gives me 'Number of donuts: many'
```
#!/usr/bin/python2.6 -tt
import sys
def donuts(count):
if count < 10:
x = str(count)
else:
x = 'many'
print 'Number of d... | 2012/04/06 | [
"https://Stackoverflow.com/questions/10049054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1318217/"
] | `sys.argv` will only contain strings, even if you provide integers as arguments, so for example if you called this as `python donuts.py 4`, then `sys.argv[1]` would be `'4'` and you would attempt the comparison `'4' < 10` when you actually want `4 < 10`.
So first, try to convert `sys.argv[1]` to an int:
```
def main(... | You don't take the input in as an integer to begin with.
Change:
```
def main():
donuts(sys.argv[1])
```
to:
```
def main():
donuts(int(sys.argv[1]))
```
You will run into an issue if they put in a string or decimal instead of a numerical value, though. |
28,656,559 | I am trying to build the \_pjsua C extension in windows, using Visual studio 2012.
I downloaded the source code from here - <http://www.pjsip.org/download.htm>.
I have Python27 installed, and have added the **C:\Python27\include** and the **C:\Python27\libs** directories to the project **include** and **library** dir... | 2015/02/22 | [
"https://Stackoverflow.com/questions/28656559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1662033/"
] | No, it not so.
You can use simple hack:
**Copy python27.lib** and rename it **to python24.lib**, then place it to **C:/Python27/libs** folder. Now you can build you extension, then run in cmd **python setup-vc.py install** command. | The right solution for this is:
1. Open python\_pjsua property pages (righ click->Properties);
2. Linker->Input->Additional Dependencies.
3. Change python24.lib to python27.lib (or python24\_d.lib to python27\_d.lib if debugging).
It should work and compile with no problem. |
33,326,193 | I need help finding a way to calculate the total cost of items when there is a change in the price once items go up to certain number in python 3.5.
For example,
First 6 items cost $8 each and after that, it costs $5 per item.
How can I achieve this without using an `if` statement and loop? | 2015/10/25 | [
"https://Stackoverflow.com/questions/33326193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5426865/"
] | I would agree with the replies to this post concerning MCVE.
As for an answer to the question (to get the grader to accept your answer), remember that when inheriting the (Parent) `class Person` for (child) `class USResident`, (Parent) `class Person` will need to be initialized in (child) `class USResident` with:
`Pe... | Actually it is very simple, just to test you if you can use a constant in the class.
Just like something: `STATUS = ("c", "i", "l")` and then raise the `ValueError` if the condition failed. |
42,689,852 | I'm trying to using the [Azure Python SDK](https://github.com/Azure/azure-sdk-for-python) to drive some server configuration management, but I'm having difficulty working out how I'm supposed to use the API to upload and configure SSL certificates.
I can successfully interrogate my Azure account to discovering the App... | 2017/03/09 | [
"https://Stackoverflow.com/questions/42689852",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/218383/"
] | If you follow the [App Service walkthrough for importing certificates from Key Vault](https://learn.microsoft.com/azure/app-service/configure-ssl-certificate#import-a-certificate-from-key-vault), it'll tell you that your app needs read permissions to access certificates from the vault. But to initially import your cert... | According to your description, based on my understanding, I think you want to upload a certificate and use it on Azure App Service.
Per my experience for Azure Python SDK, there seems not to be any Python API for directly uploading a certificate to Azure App Service. However, there is a workaround way for doing it via... |
63,482,435 | from the below table I want to pull records with ID 1 and ID 3.
```
ID Status assigned
1 low yes
1 High no
2 low no
3 high yes
3 low yes
```
Please let me know in python how can this be done. | 2020/08/19 | [
"https://Stackoverflow.com/questions/63482435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10214628/"
] | You can target attribute lang on the blockquote tag and add direction rule:
```
blockquote[lang="ar"] {
direction: rtl;
}
```
```css
blockquote {
background-color: #f4f7fc;
font-size: 20px;
color: #191514;
line-height: 1.7;
position: relative;
padding: 50px 30px 30px 115px;
font-family: 'Poppins', sa... | add class to blockquote element, and set the class styling direction attribute to rtl |
73,581,339 | I want to show status every second in a very slow loop in python code, e.g.
```
for i in range(100):
sleep(1000000) # think there is a very slow job
# I want to show status in console every second
# to know if the job stop or not
```
The output image is, e.g.
```
$ python somejob.py
> 2022-09-02 13:04:... | 2022/09/02 | [
"https://Stackoverflow.com/questions/73581339",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6766052/"
] | I think what you're looking for is someting like the tqdm library: [github repo](https://github.com/tqdm/tqdm)
for example
```
from tqdm import tqdm
for i in tqdm(range(1000)):
continue # do something complex here
``` | You may us the [rich module](https://pypi.org/project/rich/) to disply a progress bar:
```
import time
from rich.progress import track
for i in track(range(100)):
time.sleep(0.5)
```
Here's a screenshot within the run:
[](https://i.stack.imgur.... |
64,327,172 | I am running a django app with a postgreSQL database and I am trying to send a very large dictionary (consisting of time-series data) to the database.
My goal is to write my data into the DB as fast as possible. I am using the library requests to send the data via an API-call (built with django REST):
My API-view is ... | 2020/10/13 | [
"https://Stackoverflow.com/questions/64327172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9893391/"
] | You can solve your issues using two techniques.
Data Creation
-------------
Use bulk\_create to insert a large number of records, if SQL error happens due to large query size etc then provide the `batch_size` in `bulk_create`.
```
records = []
for elem, ts in request.data['time_series'] :
records.append(
... | @micromegas when your solution is correct theoretically, however calling create() many times in a loop, I believe that causes the ConnectionError exception.
try to refactor to something like:
```
big_data_holder = []
for elem, ts in request.data['time_series'] :
big_data_holder.append(
TimeSeries(data_js... |
46,145,221 | what is different between `os.path.getsize(path)` and `os.stat`? which one is best to used in python 3? and when do we use them? and why we have two same solution?
I found [this](https://stackoverflow.com/questions/18962166/python-os-statfile-name-st-size-versus-os-path-getsizefile-name) answer but I couldn't understan... | 2017/09/10 | [
"https://Stackoverflow.com/questions/46145221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4958447/"
] | `stat` is a POSIX system call (available on Linux, Unix and even Windows) which returns a bunch of information (size, type, protection bits...)
Python has to call it at some point to get the size ([and it does](https://stackoverflow.com/questions/18962166/python-os-statfile-name-st-size-versus-os-path-getsizefile-name... | The answer you are linking to shows that the one calls the other:
```
def getsize(filename):
"""Return the size of a file, reported by os.stat()."""
return os.stat(filename).st_size
```
so fundamentally, both functions are using `os.stat`.
Why? probably because they had similar needs in two different packa... |
68,856,582 | Is there a similar substituite to `.exit()` and `sys.exit()` that stops the program from running **but without terminating python entirely**?
Here's something similar to what I want to achieve:
```
import random
my_num = random.uniform(0, 1)
if my_num > 0.9:
# stop the code here
# some other huge blocks of code... | 2021/08/20 | [
"https://Stackoverflow.com/questions/68856582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14610650/"
] | When you run your script, use the `-i` option. Then call `sys.exit()` where you want to stop.
```
python3 -i myscript.py
```
```py
if my_num > 0.9:
sys.exit()
```
Python won't actually exit when the `-i` used. It will instead place you in the REPL prompt.
---
The next best method, if you can't use the `-i` o... | If you don't want to terminate the code, you can tell python to "sleep":
```
import random
import time
my_num = random.uniform(0, 1)
if my_num > 0.9:
time.sleep(50) #==== 50 seconds. Use any number.
``` |
15,661,841 | Is there any video tutorial or book from where I can learn python web programming in django platform in Eclipse(pydev).Please Help | 2013/03/27 | [
"https://Stackoverflow.com/questions/15661841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183898/"
] | Try [The Django Book](http://www.djangobook.com/en/2.0/index.html), or start with the [tutorial](https://docs.djangoproject.com/en/1.5/intro/tutorial01/). | <http://pydev.org/manual_adv_django.html> should get you started. If you're new to eclipse, I would find a tutorial on that first as they have a lot of their own lingo. |
15,661,841 | Is there any video tutorial or book from where I can learn python web programming in django platform in Eclipse(pydev).Please Help | 2013/03/27 | [
"https://Stackoverflow.com/questions/15661841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183898/"
] | If you insist to start with Eclipse, [this series is a good start point](https://www.youtube.com/watch?v=o1STjuSTKcU), I guess.. | <http://pydev.org/manual_adv_django.html> should get you started. If you're new to eclipse, I would find a tutorial on that first as they have a lot of their own lingo. |
38,219,216 | I'm using `python` to crawl a webpage and save it. And the code works properly. But when I open the web page it just shows the website name i.e., **<http://www.indiabix.com>** and not the actual content.
You can just go the website and save one of it's pages **NOT** the homepage but other pages like **<http://www.indi... | 2016/07/06 | [
"https://Stackoverflow.com/questions/38219216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3620992/"
] | in this version
```
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
```
try it
```
public class MainActivity extends AppCompatActivity {
private LineChart lc;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main)... | Version 3.0 is initialized like so:
```
LineChart lineChart = new LineChart(context);
lineChart.setMinimumHeight(ToolBox.dpToPixels(context, 300));
lineChart.setMinimumWidth(ToolBox.getScreenWidth());
ArrayList<Entry> yVals = new ArrayList<>();
for(int i = 0; i < frigbot.getEquipment().getTemperatures().size();... |
71,153,492 | I'm having multiple errors while running this VGG training code (code and errors shown below). I don't know if its because of my dataset or is it something else.
```
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tens... | 2022/02/17 | [
"https://Stackoverflow.com/questions/71153492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15336528/"
] | I faced the same error and tried to test everything with no value, but I heard that you have to make the number of **folders** in the **dataset** the SAME as the one in `Dense`.
I don't know if this will solve your specific bug or not but try this with your code:
```
vgg_model.add(tf.keras.layers.Dense(10, activation... | Check the image size. Size of image defined in model.add(.., input\_shape=(100,100,3)) should be same as the **target\_size=(100,100) in train\_gererator.**
And also check if number of neurons in last dense layer are equal to number of output classes or not.
By the way, there isn't any need to install any other module.... |
71,153,492 | I'm having multiple errors while running this VGG training code (code and errors shown below). I don't know if its because of my dataset or is it something else.
```
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tens... | 2022/02/17 | [
"https://Stackoverflow.com/questions/71153492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15336528/"
] | I faced the same error and tried to test everything with no value, but I heard that you have to make the number of **folders** in the **dataset** the SAME as the one in `Dense`.
I don't know if this will solve your specific bug or not but try this with your code:
```
vgg_model.add(tf.keras.layers.Dense(10, activation... | In my case, the reason was incompatible shapes. My model takes [batch\_size, 784] image shape, but data where [batch\_size, 28, 28, 1] shape. So I easily fixed it with tf.reshape(x, [-1]). |
71,153,492 | I'm having multiple errors while running this VGG training code (code and errors shown below). I don't know if its because of my dataset or is it something else.
```
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from tensorflow.keras.preprocessing import image
from tens... | 2022/02/17 | [
"https://Stackoverflow.com/questions/71153492",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15336528/"
] | In my case, the reason was incompatible shapes. My model takes [batch\_size, 784] image shape, but data where [batch\_size, 28, 28, 1] shape. So I easily fixed it with tf.reshape(x, [-1]). | Check the image size. Size of image defined in model.add(.., input\_shape=(100,100,3)) should be same as the **target\_size=(100,100) in train\_gererator.**
And also check if number of neurons in last dense layer are equal to number of output classes or not.
By the way, there isn't any need to install any other module.... |
20,893,752 | I started trying to make a script to send emails using python, but nothing worked. I eventually got to the point where I just started copying and pasting email scripts and filling in my info. Still nothing worked. So i eventually just got rid of everything except this:
```
#!/usr/bin/python
import smtplib
```
This s... | 2014/01/02 | [
"https://Stackoverflow.com/questions/20893752",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2402862/"
] | Change the name of your script from `email.py` to something else. It is interfering with the Python standard library module of the same name, `email`. | Read this: [Syntax: python smtplib not working in script](https://stackoverflow.com/questions/14102113/syntax-python-smtplib-not-working-in-script)
A user says that you have to remove email.py from the folder. |
28,262,400 | I am changing the original post to memory leak, as what i have observed that cassandra python driver do not release sessions from memory. And during heavy inserts its eat up all the memory (Thus crashes cassandra as not enough room left for GC).
This was raised earlier but i see the issue in latest drivers as well.
<... | 2015/02/01 | [
"https://Stackoverflow.com/questions/28262400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4460263/"
] | Calling `id.Hex()` will return a string representation of the `bson.ObjectId`.
This is also the default behavior if you try to marshal one `bson.ObjectId` to json string. | Things like to work [playground](https://play.golang.org/p/1LG1NlFEK-)
Just define dot `.` for your template
```
{{ .Name }} {{ .Food }}
<a href="/remove/{{ .Id }}">Remove me</a>
``` |
28,262,400 | I am changing the original post to memory leak, as what i have observed that cassandra python driver do not release sessions from memory. And during heavy inserts its eat up all the memory (Thus crashes cassandra as not enough room left for GC).
This was raised earlier but i see the issue in latest drivers as well.
<... | 2015/02/01 | [
"https://Stackoverflow.com/questions/28262400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4460263/"
] | The [bson.ObjectId](http://gopkg.in/mgo.v2/bson#ObjectId) type offers a [Hex](http://gopkg.in/mgo.v2/bson#ObjectId.Hex) method that will return the hex representation you are looking for, and the [template](http://golang.org/pkg/html/template) package allows one to call arbitrary methods on values you have at hand, so ... | Things like to work [playground](https://play.golang.org/p/1LG1NlFEK-)
Just define dot `.` for your template
```
{{ .Name }} {{ .Food }}
<a href="/remove/{{ .Id }}">Remove me</a>
``` |
28,262,400 | I am changing the original post to memory leak, as what i have observed that cassandra python driver do not release sessions from memory. And during heavy inserts its eat up all the memory (Thus crashes cassandra as not enough room left for GC).
This was raised earlier but i see the issue in latest drivers as well.
<... | 2015/02/01 | [
"https://Stackoverflow.com/questions/28262400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4460263/"
] | The [bson.ObjectId](http://gopkg.in/mgo.v2/bson#ObjectId) type offers a [Hex](http://gopkg.in/mgo.v2/bson#ObjectId.Hex) method that will return the hex representation you are looking for, and the [template](http://golang.org/pkg/html/template) package allows one to call arbitrary methods on values you have at hand, so ... | Calling `id.Hex()` will return a string representation of the `bson.ObjectId`.
This is also the default behavior if you try to marshal one `bson.ObjectId` to json string. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.