qid int64 46k 74.7M | question stringlengths 54 37.8k | date stringlengths 10 10 | metadata listlengths 3 3 | response_j stringlengths 17 26k | response_k stringlengths 26 26k |
|---|---|---|---|---|---|
21,962,250 | I have a string that hold a binary number as a string
```
string = '0b100111'
```
I want to have that value not be a string type but a value (pseudo-code)
```
bin(string) = 0b100111
```
Any pythoners know an easy way to do this?
It is all part of this code for a Codecademy: (After answer implemented)
```
def fl... | 2014/02/22 | [
"https://Stackoverflow.com/questions/21962250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2918785/"
] | What about calling `int` function with base `2`?
```
>>>s = '0b100111'
>>>b = int(s, 2)
>>>print b
39
``` | you can make it binary by putting a b before the quotes:
```
>>> s = b'hello'
>>> s.decode()
'hello'
``` |
21,962,250 | I have a string that hold a binary number as a string
```
string = '0b100111'
```
I want to have that value not be a string type but a value (pseudo-code)
```
bin(string) = 0b100111
```
Any pythoners know an easy way to do this?
It is all part of this code for a Codecademy: (After answer implemented)
```
def fl... | 2014/02/22 | [
"https://Stackoverflow.com/questions/21962250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2918785/"
] | What about calling `int` function with base `2`?
```
>>>s = '0b100111'
>>>b = int(s, 2)
>>>print b
39
``` | I'm afraid that making it as idealised in your question is impossible. As what you want is a a series of characters, it can only be a string (or you could convert it to an integer). But it is still workable as a number with built in functions- for example:
```
num1 = '0b0110'
num1 = '0b0101'
result = int(num1, 2) + i... |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | In the first for-loop, **enumerate()** walks through the array and makes the index,value of each element available to the second for-loop. In the second loop, **range()** makes j = i+1 --> len(a) available. At this point you'd have exactly what you need which is `i` & `j` to do your operation.
```
>>> a = [1,2,3,4]
>... |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | You can use `xrange` to generate values for i and j respectively as show below:
```
for i in xrange(0, n):
for j in xrange(i + 1, n):
# do stuff
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | I intepret what you're asking as
>
> How can I iterate over all pairs of distinct elements of a container?
>
>
>
Answer:
```
>>> x = {1,2,3}
>>> import itertools
>>> for a, b in itertools.permutations(x, 2):
... print a, b
...
1 2
1 3
2 1
2 3
3 1
3 2
```
EDIT: If you don't want both `(a,b)` and `(b,a)`, j... | Still can't leave comments.. but basically what the other two posts said - but get in the habit of using xrange instead of range.
```
for i in xrange(0,n):
for j in xrange(i+1,n):
# do stuff
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | Another way to approach this is - if **n** is an sequence that provides the iterable interface, then in Python you can simplify your code by iterating over the object directly:
```
for i in n:
for some_var in n[n.index(i):]: # rest of items
# do something
```
I hope I understood your loop correctly, because ... |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | I intepret what you're asking as
>
> How can I iterate over all pairs of distinct elements of a container?
>
>
>
Answer:
```
>>> x = {1,2,3}
>>> import itertools
>>> for a, b in itertools.permutations(x, 2):
... print a, b
...
1 2
1 3
2 1
2 3
3 1
3 2
```
EDIT: If you don't want both `(a,b)` and `(b,a)`, j... | You could make the inner loop directly over a slice. Not saying this is any better, but it is another approach.
```
for i in range(0,len(x)):
a = x[i]
for b in x[i+1:]:
print a, b
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | Still can't leave comments.. but basically what the other two posts said - but get in the habit of using xrange instead of range.
```
for i in xrange(0,n):
for j in xrange(i+1,n):
# do stuff
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | ```
for i in range(0,n):
for j in range(i+1,n):
# do stuff
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | For the first one of your questions, as already mentioned in other answers:
```
for i in xrange(n):
for j in xrange(i+1, n):
# do stuff with A[i] and A[j]
```
For the second one:
```
for i, a in enumerate(A):
for b in A[i+1:]:
# do stuff with a and b
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | Since your two questions are different, here is solution for your second problem:
```
for i in xrange(len(A)):
for j in xrange(len(A)):
if i != j:
do_stuff(A[i], A[j])
```
or **using** `itertools` (I think using the included **batteries** is very pythonic!):
```
import itertools
for a, b in... | You could make the inner loop directly over a slice. Not saying this is any better, but it is another approach.
```
for i in range(0,len(x)):
a = x[i]
for b in x[i+1:]:
print a, b
``` |
9,787,741 | What is the equivalent of the following in python?
```
for (i=0; i<n; i++)
for (j=i+1; j<n; j++)
//do stuff with A[i], A[j]
```
Or in some sense, the following. It should also remove the element from A at the completion of each round of the loop.
```
for a in A:
for a' in A/{a}: #i.e. rest of the el... | 2012/03/20 | [
"https://Stackoverflow.com/questions/9787741",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/408412/"
] | I intepret what you're asking as
>
> How can I iterate over all pairs of distinct elements of a container?
>
>
>
Answer:
```
>>> x = {1,2,3}
>>> import itertools
>>> for a, b in itertools.permutations(x, 2):
... print a, b
...
1 2
1 3
2 1
2 3
3 1
3 2
```
EDIT: If you don't want both `(a,b)` and `(b,a)`, j... | In the first for-loop, **enumerate()** walks through the array and makes the index,value of each element available to the second for-loop. In the second loop, **range()** makes j = i+1 --> len(a) available. At this point you'd have exactly what you need which is `i` & `j` to do your operation.
```
>>> a = [1,2,3,4]
>... |
9,403,415 | I'm using the great [quantities](http://pypi.python.org/pypi/quantities) package for Python. I would like to know how I can get at just the numerical value of the quantity, without the unit.
I.e., if I have
```
E = 5.3*quantities.joule
```
I would like to get at just the 5.3. I know I can simply divide by the "und... | 2012/02/22 | [
"https://Stackoverflow.com/questions/9403415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/633318/"
] | `E.item()` seems to be what you want, if you want a Python float. `E.magnitude`, offered by tzaman, is a 0-dimensional NumPy array with the value, if you'd prefer that.
The documentation for `quantities` doesn't seem to have a very good API reference. | I believe `E.magnitude` gets you what you want. |
9,403,415 | I'm using the great [quantities](http://pypi.python.org/pypi/quantities) package for Python. I would like to know how I can get at just the numerical value of the quantity, without the unit.
I.e., if I have
```
E = 5.3*quantities.joule
```
I would like to get at just the 5.3. I know I can simply divide by the "und... | 2012/02/22 | [
"https://Stackoverflow.com/questions/9403415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/633318/"
] | `E.item()` seems to be what you want, if you want a Python float. `E.magnitude`, offered by tzaman, is a 0-dimensional NumPy array with the value, if you'd prefer that.
The documentation for `quantities` doesn't seem to have a very good API reference. | ```
>>> import quantities
>>> E=5.3*quantities.joule
>>> E.item()
5.3
``` |
7,758,913 | How can I implement graph colouring in python using adjacency matrix? Is it possible? I implemented it using list. But it has some problems. I want to implement it using matrix. Can anybody give me the answer or suggestions to this? | 2011/10/13 | [
"https://Stackoverflow.com/questions/7758913",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/992874/"
] | Is it possible? Yes, of course. But are your problems with making Graphs, or coding algorithms that deal with them?
Separating the algorithm from the data type might make it easier for you. Here are a couple suggestions:
* create (or use) an abstract data type Graph
* code the coloring algorithm against the Graph int... | Implementing using adjacency is somewhat easier than using lists, as lists take a longer time and space. igraph has a quick method neighbors which can be used. However, with adjacency matrix alone, we can come up with our own graph coloring version which may not result in using minimum chromatic number. A quick strateg... |
34,567,484 | I have a list that has several days in it. Each day have several timestamps. What I want to do is to make a new list that only takes the start time and the end time in the list for each date.
I also want to delete the Character between the date and the time on each one, the char is always the same type of letter.
the t... | 2016/01/02 | [
"https://Stackoverflow.com/questions/34567484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5738256/"
] | First of all, you should convert all your strings into proper dates, Python can work with. That way, you have a lot more control on it, also to change the formatting later. So let’s parse your dates using [`datetime.strptime`](https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime) in `list2`:
```
... | Because your data is ordered you just need to pull the first and last value from each group, you can use re.sub to remove the single letter replacing it with a space then split each date string just comparing the dates:
```
from re import sub
def grp(l):
it = iter(l)
prev = start = next(it).replace("A"," ")
... |
24,557,707 | I have an Echoprint local webserver (uses tokyotyrant, python, solr) set up on a Linux virtual machine.
I can access it through the browser or curl in the virtual machine using http//localhost:8080 and in the non-virtual machine (couldn't find out how to say it better) I use the IP on the virtual machine also with the... | 2014/07/03 | [
"https://Stackoverflow.com/questions/24557707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2996499/"
] | Took a while to figure it out but here's the working code.
```
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
using System.Threading;
namespace Foreground {
class GetForegroundWindowTest {
/// Foreground dll's
[DllImport("user32.dll", CharSet=CharSet.Auto, ExactSpel... | You can also use
```
private static extern int ShowWindow(int hwnd, int nCmdShow);
```
to hide a window. This method takes the integer handler of the window (instead of pointer). Using **[Spy++](https://msdn.microsoft.com/en-us/library/dd460729.aspx)** (in Visual Studio tools) you can get the **Class Name** and **Wi... |
66,102,225 | I'm using `jwilder/nginx-proxy` and `jrcs/letsencrypt-nginx-proxy-companion` images to create the ssl certificates automatically. When the server is updated and I run `docker-compose down` and `docker-compose up -d` the following error appears:
```
letsencrypt_1 | [Mon Feb 8 11:48:47 UTC 2021] Please check log file ... | 2021/02/08 | [
"https://Stackoverflow.com/questions/66102225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10279746/"
] | I had this problem and finally got it figured out.
You need to add a volume to the `nginx-proxy:` and `letsencrypt:` services' `volumes:` sections - something like this:
```
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- certs:/etc/nginx/certs:ro
- vhostd:/etc/nginx/vhost.d
- html:/usr/share/nginx/html... | You need to mount `acme:/etc/acme.sh` folder for `nginx-proxy` because it's created each time when you do up/down. Plus, add `acme:` to the last `volumes:` section.
Entry from your log file proves it:
```
letsencrypt_1 | [Mon Feb 8 11:48:48 UTC 2021] The domain key is here: /etc/acme.sh/[email protected]/example.com/... |
26,061,610 | I am using `python version 2.7` and `pip version is 1.5.6`.
I want to install extra libraries from url like a git repo on setup.py is being installed.
I was putting extras in `install_requires` parameter in `setup.py`. This means, my library requires extra libraries and they must also be installed.
```
...
install... | 2014/09/26 | [
"https://Stackoverflow.com/questions/26061610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1029816/"
] | You need to make sure you include the dependency in your `install_requires` too.
Here's an example `setup.py`
```
#!/usr/bin/env python
from setuptools import setup
setup(
name='foo',
version='0.0.1',
install_requires=[
'balog==0.0.7'
],
dependency_links=[
'https://github.com/bala... | Pip removed support for dependency\_links a while back. The [latest version of pip that supports dependency\_links is 1.3.1](https://pip.pypa.io/en/latest/news.html), to install it
```
pip install pip==1.3.1
```
your dependency links should work at that point. Please note, that dependency\_links were always the last... |
26,061,610 | I am using `python version 2.7` and `pip version is 1.5.6`.
I want to install extra libraries from url like a git repo on setup.py is being installed.
I was putting extras in `install_requires` parameter in `setup.py`. This means, my library requires extra libraries and they must also be installed.
```
...
install... | 2014/09/26 | [
"https://Stackoverflow.com/questions/26061610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1029816/"
] | You need to make sure you include the dependency in your `install_requires` too.
Here's an example `setup.py`
```
#!/usr/bin/env python
from setuptools import setup
setup(
name='foo',
version='0.0.1',
install_requires=[
'balog==0.0.7'
],
dependency_links=[
'https://github.com/bala... | I faced a similar situation where I want to use shapely as one of my package dependency. Shapely, however, has a caveat that if you are using windows, you have to use the .whl file from <http://www.lfd.uci.edu/~gohlke/pythonlibs/>. Otherwise, you have to install a C compiler, which is something I don't want. I want the... |
26,061,610 | I am using `python version 2.7` and `pip version is 1.5.6`.
I want to install extra libraries from url like a git repo on setup.py is being installed.
I was putting extras in `install_requires` parameter in `setup.py`. This means, my library requires extra libraries and they must also be installed.
```
...
install... | 2014/09/26 | [
"https://Stackoverflow.com/questions/26061610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1029816/"
] | Pip removed support for dependency\_links a while back. The [latest version of pip that supports dependency\_links is 1.3.1](https://pip.pypa.io/en/latest/news.html), to install it
```
pip install pip==1.3.1
```
your dependency links should work at that point. Please note, that dependency\_links were always the last... | I faced a similar situation where I want to use shapely as one of my package dependency. Shapely, however, has a caveat that if you are using windows, you have to use the .whl file from <http://www.lfd.uci.edu/~gohlke/pythonlibs/>. Otherwise, you have to install a C compiler, which is something I don't want. I want the... |
26,061,610 | I am using `python version 2.7` and `pip version is 1.5.6`.
I want to install extra libraries from url like a git repo on setup.py is being installed.
I was putting extras in `install_requires` parameter in `setup.py`. This means, my library requires extra libraries and they must also be installed.
```
...
install... | 2014/09/26 | [
"https://Stackoverflow.com/questions/26061610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1029816/"
] | The `--process-dependency-links` option to enable `dependency_links` was [removed in Pip 19.0](https://pip.pypa.io/en/stable/news/).
Instead, you can use a [PEP 508](https://www.python.org/dev/peps/pep-0508/) URL to specify your dependency, which is [supported since Pip 18.1](https://pip.pypa.io/en/stable/news/). Here... | Pip removed support for dependency\_links a while back. The [latest version of pip that supports dependency\_links is 1.3.1](https://pip.pypa.io/en/latest/news.html), to install it
```
pip install pip==1.3.1
```
your dependency links should work at that point. Please note, that dependency\_links were always the last... |
26,061,610 | I am using `python version 2.7` and `pip version is 1.5.6`.
I want to install extra libraries from url like a git repo on setup.py is being installed.
I was putting extras in `install_requires` parameter in `setup.py`. This means, my library requires extra libraries and they must also be installed.
```
...
install... | 2014/09/26 | [
"https://Stackoverflow.com/questions/26061610",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1029816/"
] | The `--process-dependency-links` option to enable `dependency_links` was [removed in Pip 19.0](https://pip.pypa.io/en/stable/news/).
Instead, you can use a [PEP 508](https://www.python.org/dev/peps/pep-0508/) URL to specify your dependency, which is [supported since Pip 18.1](https://pip.pypa.io/en/stable/news/). Here... | I faced a similar situation where I want to use shapely as one of my package dependency. Shapely, however, has a caveat that if you are using windows, you have to use the .whl file from <http://www.lfd.uci.edu/~gohlke/pythonlibs/>. Otherwise, you have to install a C compiler, which is something I don't want. I want the... |
69,450,482 | I was trying to install matplotlib but I'm getting this long error. I don't really have any idea what is wrong.
```
ERROR: Command errored out with exit status 1:
command: 'C:\Python310\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Bilguun\\AppData\\Local\\Temp\\pip-insta... | 2021/10/05 | [
"https://Stackoverflow.com/questions/69450482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17079850/"
] | >
> *"What causes the segmentation fault..."*
>
>
>
There are several places that have potential for segmentation fault. One that stands out is this:
```
char filename[4];
...
sprintf(filename, "%03i.jpg", 0);
```
In this example, `filename` has enough space to contain 3 characters + `nul` terminator. It needs ... | as ryker stated, there are several points of possible failures here.
another is
`int SIZE = sizeof(raw);`
sets SIZE to be the size of a pointer (4/8 bytes). |
69,450,482 | I was trying to install matplotlib but I'm getting this long error. I don't really have any idea what is wrong.
```
ERROR: Command errored out with exit status 1:
command: 'C:\Python310\python.exe' -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\Bilguun\\AppData\\Local\\Temp\\pip-insta... | 2021/10/05 | [
"https://Stackoverflow.com/questions/69450482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17079850/"
] | In addition to what the other answers tell, the handling of file pointers is also broken:
```
if(buffer[0] == 0xff && buffer[1] == 0xd8 && (buffer[3] >= 0xe0 && buffer[3] <= 0xef))
{ // We found a new header, lets create a new file...
if(JPEG_num == 0)
{
sprintf... | as ryker stated, there are several points of possible failures here.
another is
`int SIZE = sizeof(raw);`
sets SIZE to be the size of a pointer (4/8 bytes). |
23,985,903 | I was wondering if there are any BDD-style 'describe-it' unit-testing frameworks for Python that are maintained and production ready. I have found [describe](https://pypi.python.org/pypi/describe/0.1.2), but it doesn't seem to be maintained and has no documentation. I've also found [sure](http://falcao.it/sure) which r... | 2014/06/02 | [
"https://Stackoverflow.com/questions/23985903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2483075/"
] | I've been looking for this myself and came across [mamba](https://github.com/nestorsalceda/mamba). In combination with the fluent assertion library [expects](https://github.com/jaimegildesagredo/expects) it allows you to write BDD-style unit tests in Python that look like this:
```
from mamba import describe, context,... | If you are expecting something exactly like rspec/capybara in python, then I am afraid you are in for a disappointment. The problem is ruby provides you much more freedom than python does (with much more support for open classes and extensive metaprogramming). I have to say there is a fundamental difference between phi... |
49,425,827 | I want to import some tables from a postgres database into Elastic search and also hold the tables in sync with the data in elastic search. I have looked at a course on udemy, and also talked with a colleague who has a lot of experience with this issue to see what the best way to do it is. I am surprised to hear from b... | 2018/03/22 | [
"https://Stackoverflow.com/questions/49425827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4415079/"
] | It depends on your use case. A common practice is to handle this on the application layer. Basically what you do is to replicate the actions of one db to the other. So for example if you save one entry in postgres you do the same in elasticsearch.
If you do this however you'll have to have a queuing system in place. ... | As anything in life,best is subjective.
Your colleague likes to write and maintain code to keep this in sync. There's nothing wrong with that.
I would say the best way would be to use some data pipeline. There's plethora of choices, really overwheleming, you can explore the various solutions which support Postgres a... |
49,425,827 | I want to import some tables from a postgres database into Elastic search and also hold the tables in sync with the data in elastic search. I have looked at a course on udemy, and also talked with a colleague who has a lot of experience with this issue to see what the best way to do it is. I am surprised to hear from b... | 2018/03/22 | [
"https://Stackoverflow.com/questions/49425827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4415079/"
] | There is a more recent tool called "abc", developped by appbase.io
It's performance is uncomparable with logstash:
- abc is based on go
- logstash is jruby
Anybody who's ever used logstash knows that it takes at least 20 seconds just to start.
The same basic table import task from postgresql to elasticsearch takes ~1... | As anything in life,best is subjective.
Your colleague likes to write and maintain code to keep this in sync. There's nothing wrong with that.
I would say the best way would be to use some data pipeline. There's plethora of choices, really overwheleming, you can explore the various solutions which support Postgres a... |
49,425,827 | I want to import some tables from a postgres database into Elastic search and also hold the tables in sync with the data in elastic search. I have looked at a course on udemy, and also talked with a colleague who has a lot of experience with this issue to see what the best way to do it is. I am surprised to hear from b... | 2018/03/22 | [
"https://Stackoverflow.com/questions/49425827",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4415079/"
] | It depends on your use case. A common practice is to handle this on the application layer. Basically what you do is to replicate the actions of one db to the other. So for example if you save one entry in postgres you do the same in elasticsearch.
If you do this however you'll have to have a queuing system in place. ... | There is a more recent tool called "abc", developped by appbase.io
It's performance is uncomparable with logstash:
- abc is based on go
- logstash is jruby
Anybody who's ever used logstash knows that it takes at least 20 seconds just to start.
The same basic table import task from postgresql to elasticsearch takes ~1... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | [PyInstaller](http://www.pyinstaller.org) lets you import external files as well. If you run it over your application, it will not package those files within the executable. You will then have to make sure that paths are correct (that is, your application can find the modules on the disk in the correct directory), and ... | I suggest you use pkg\_resources entry\_points features (from setuptools/distribute) to implement plugin discovery and instantiation: first, it's a standard way to do that; second, it does not suffer the problem you mention AFAIK. All you have to do to extend the application is to package some plugins into an egg that ... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | If you don't mind that plugin's will be release as .py files, you can do something like the following. Put all your plugin's under a "plugin" subdir, and create an empty "\_\_init\_\_.py". Doing runtime, it will import the package along with all the modules in that directory. Check [Dive In Python](http://diveintopytho... | I suggest you use pkg\_resources entry\_points features (from setuptools/distribute) to implement plugin discovery and instantiation: first, it's a standard way to do that; second, it does not suffer the problem you mention AFAIK. All you have to do to extend the application is to package some plugins into an egg that ... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | [PyInstaller](http://www.pyinstaller.org) lets you import external files as well. If you run it over your application, it will not package those files within the executable. You will then have to make sure that paths are correct (that is, your application can find the modules on the disk in the correct directory), and ... | I'm not sure you have to put plugin files in the zip library.
This may be because you're using the default for py2exe packaging your script.
You could try using compressed = False (as documented in [py2exe ListOfOptions](http://www.py2exe.org/index.cgi/ListOfOptions) ) which would eliminate the library.zip generated ... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | If you don't mind that plugin's will be release as .py files, you can do something like the following. Put all your plugin's under a "plugin" subdir, and create an empty "\_\_init\_\_.py". Doing runtime, it will import the package along with all the modules in that directory. Check [Dive In Python](http://diveintopytho... | I'm not sure you have to put plugin files in the zip library.
This may be because you're using the default for py2exe packaging your script.
You could try using compressed = False (as documented in [py2exe ListOfOptions](http://www.py2exe.org/index.cgi/ListOfOptions) ) which would eliminate the library.zip generated ... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | If you don't mind that plugin's will be release as .py files, you can do something like the following. Put all your plugin's under a "plugin" subdir, and create an empty "\_\_init\_\_.py". Doing runtime, it will import the package along with all the modules in that directory. Check [Dive In Python](http://diveintopytho... | [PyInstaller](http://www.pyinstaller.org) lets you import external files as well. If you run it over your application, it will not package those files within the executable. You will then have to make sure that paths are correct (that is, your application can find the modules on the disk in the correct directory), and ... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | [PyInstaller](http://www.pyinstaller.org) lets you import external files as well. If you run it over your application, it will not package those files within the executable. You will then have to make sure that paths are correct (that is, your application can find the modules on the disk in the correct directory), and ... | I found how to do import external modules (on top of the compiled executable, at runtime) with pyinstaller.
it figures that originally, the path of the executable was automatically added to sys.path, but for security reasons they removed this at some point.
to re-enable this, use:
```
sys.path.append(os.path.dirname(s... |
3,254,096 | My Python application is constructed as such that some functionality is available as plugins. The plugin architecture currently is very simple: I have a plugins folder/package which contains some python modules. I load the relevant plugin as follows:
```
plugin_name = blablabla
try:
module = __import__(plugin_nam... | 2010/07/15 | [
"https://Stackoverflow.com/questions/3254096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50899/"
] | If you don't mind that plugin's will be release as .py files, you can do something like the following. Put all your plugin's under a "plugin" subdir, and create an empty "\_\_init\_\_.py". Doing runtime, it will import the package along with all the modules in that directory. Check [Dive In Python](http://diveintopytho... | I found how to do import external modules (on top of the compiled executable, at runtime) with pyinstaller.
it figures that originally, the path of the executable was automatically added to sys.path, but for security reasons they removed this at some point.
to re-enable this, use:
```
sys.path.append(os.path.dirname(s... |
23,599,970 | I would like to ask your help. I have started learning python, and there are a task that I can not figure out how to complete. So here it is.
We have a input.txt file containing the next 4 rows:
```
f(x, 3*y) * 54 = 64 / (7 * x) + f(2*x, y-6)
x + f(21*y, x - 32/y) + 4 = f(21 ,y)
86 - f(7 + x*10, y+ 232) = f(12*x-4... | 2014/05/12 | [
"https://Stackoverflow.com/questions/23599970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3626828/"
] | The Firemonkey canvas on Windows is probably not using the GPU. If you are using XE6 you can
>
> set the global variable FMX.Types.GlobalUseGPUCanvas to true in the initialization section.
>
>
>
[Documentation](http://docwiki.embarcadero.com/Libraries/en/FMX.Types.GlobalUseGPUCanvas)
Otherwise, in XE5 stick a T... | When you draw a circle in canvas (ie GPUCanvas) then you draw in fact around 50 small triangles. this is how GPUCanvas work. it's even worse with for exemple Rectangle with round rect. I also found that Canvas.BeginScene and Canvas.endScene are very slow operation. you can try to put form.quality to highperformance to ... |
25,279,746 | I am writing a test application in python and to test some particular scenario, I need to launch my python child process in windows SYSTEM account.
I can do this by creating exe from my python script and then use that while creating windows service. But this option is not good for me because in future if I change anyth... | 2014/08/13 | [
"https://Stackoverflow.com/questions/25279746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1811739/"
] | 1. Create a service that runs permanently.
2. Arrange for the service to have an IPC communications channel.
3. From your desktop python code, send messages to the service down that IPC channel. These messages specify the action to be taken by the service.
4. The service receives the message and performs the action. Th... | You could also use Windows Task Scheduler, it can run a script under SYSTEM account and its interface is easy (if you do not test too often :-) ) |
25,279,746 | I am writing a test application in python and to test some particular scenario, I need to launch my python child process in windows SYSTEM account.
I can do this by creating exe from my python script and then use that while creating windows service. But this option is not good for me because in future if I change anyth... | 2014/08/13 | [
"https://Stackoverflow.com/questions/25279746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1811739/"
] | 1. Create a service that runs permanently.
2. Arrange for the service to have an IPC communications channel.
3. From your desktop python code, send messages to the service down that IPC channel. These messages specify the action to be taken by the service.
4. The service receives the message and performs the action. Th... | To run a file with system account privileges, you can use `psexec`. Download this :
[Sysinternals](https://technet.microsoft.com/en-us/sysinternals/bb896649.aspx)
Then you may use :
```
os.system
```
or
```
subprocess.call
```
And execute:
```
PSEXEC -i -s -d CMD "path\to\yourfile"
``` |
25,279,746 | I am writing a test application in python and to test some particular scenario, I need to launch my python child process in windows SYSTEM account.
I can do this by creating exe from my python script and then use that while creating windows service. But this option is not good for me because in future if I change anyth... | 2014/08/13 | [
"https://Stackoverflow.com/questions/25279746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1811739/"
] | 1. Create a service that runs permanently.
2. Arrange for the service to have an IPC communications channel.
3. From your desktop python code, send messages to the service down that IPC channel. These messages specify the action to be taken by the service.
4. The service receives the message and performs the action. Th... | Just came across this one - I know, a bit late, but anyway. I encountered a similar situation and I solved it with NSSM ([Non\_Sucking Service Manager](https://nssm.cc/)). Basically, this program enables you to start any executable as a service, which I did with my Python executable and gave it the Python script I was ... |
49,551,704 | I'm new to python and selenium and wondering how I could take a group of text from a web page and input it into an array. Currently, what I have now is a method that, instead of using an array, uses a string and un-neatly displays it.
```
# returns a list of names in the order it is displayed
def gather_names(self): ... | 2018/03/29 | [
"https://Stackoverflow.com/questions/49551704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9519161/"
] | When you use `pyinstaller` to compile your script to `executable` in `windows 10` and want to use it in `window 7` it won't work.
But you can compile it with `pyinstaller` in `windows 7` and use the executable in `windows 7, 8, and 10`
Also take note of this, take into consideration `32-bit and 64-bit` version of the... | maybe you could try using cx\_Freeze package to build your app, in windows (Note: if your PC is 64 Bits the app gonna be in that architecture and 32Bits if is x86 or 32 Bits)
run cmd and type this
```
pip install cx_Freeze
```
Then make a file called setup.py ubicated in the same directory into that and add this co... |
66,132,304 | i am trying to post on facebook wall using selenium in python. I am able to login but after login it cant find class name of status box which i copied from browser
here is my code-
```
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
user_name = "email"
password = "password"... | 2021/02/10 | [
"https://Stackoverflow.com/questions/66132304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11942305/"
] | try to find element by Xpath for example:
**driver.find\_element(By.XPATH, '//button[text()="Some text"]')**
to find the xpath from the browser, just right click on something in the webpage and press inspect after that right click, a menu will appear, navigate to copy then another menu will appear, press copy fullpath... | The problem is that `driver.find_element_by_class_name()` can be used for one class, and not multiple classes as you have: `a8c37x1j ni8dbmo4 stjgntxs l9j0dhe7` which are multiple classes separated by spaces.
Refer to the solution [suggested here](https://stackoverflow.com/a/44760303/12106481), it suggests using `find... |
53,384,795 | I have this data structure:
```
[array([[0, 1, 0, 1, 1, 1, 0, 5, 1, 0, 2, 1]]), array([[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0],
[1, 3, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0]]), array([[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], etc....
```
I want to flatten this into a list of lists... | 2018/11/20 | [
"https://Stackoverflow.com/questions/53384795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I believe you're looking for `vstack`:
```
>>> np.vstack(l)
array([[0, 1, 0, 1, 1, 1, 0, 5, 1, 0, 2, 1],
[0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0],
[1, 3, 1, 0, 0, 1, 1, 1, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
[0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
```
Note that this is equivalen... | Use `flatten`:
```
print([i.flatten() for i in l])
```
Or:
```
print(list(map(lambda x: x.flatten(),l)))
```
Both output:
```
[array([0, 1, 0, 1, 1, 1, 0, 5, 1, 0, 2, 1]), array([0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 1, 0, 1, 3, 1, 0, 0, 1, 1, 1, 1, 0, 1,
0]), array([0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 0, 0,... |
62,262,007 | ```
import base64
s = "05052020"
```
python2.7
```
base64.b64encode(s)
```
output is string `'MDUwNTIwMjA='`
python 3.7
```
base64.b64encode(b"05052020")
```
output is bytes
```
b'MDUwNTIwMjA='
```
I want to replace = with "a"
```
s = str(base64.b64encode(b"05052020"))[2:-1]
s = s.replace("=", "a")
```
... | 2020/06/08 | [
"https://Stackoverflow.com/questions/62262007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4450090/"
] | If you tried both language servers and VS Code made you reload then you have tried the options currently available to you from the Python extension. We are actively working on making it better, though, and hope to having something to say about it shortly.
But if you can't wait you can try something like <https://marke... | It might be a problem related to Pylance. By default, Pylance only looks for modules in the root directory. Making some tweaks in the settings made sure everything I import in VSCode works as if it's imported in PyCharm.
Please see:
<https://stackoverflow.com/a/67099842/6381389> |
69,675,173 | Following is the content of `foo.py`
```py
import sys
print(sys.executable)
```
When I execute this, I can get the full path of the the Python interpreter that called this script.
```sh
$ /mingw64/bin/python3.9.exe foo.py
/mingw64/bin/python3.9.exe
```
How to do this in nim (`nimscript`)? | 2021/10/22 | [
"https://Stackoverflow.com/questions/69675173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1805129/"
] | The question mentions [NimScript](https://nim-lang.github.io/Nim/nims.html), which has other uses in the Nim ecosystem, but can also be used to write executable scripts instead of using, e.g., Bash or Python. You can use the [`selfExe`](https://nim-lang.github.io/Nim/nimscript.html#selfExe) proc to get the path to the ... | Nim is compiled, so I assume you want to get the path of the application's own binary? If so, you can do that with:
```
import std/os
echo getAppFilename()
``` |
69,675,173 | Following is the content of `foo.py`
```py
import sys
print(sys.executable)
```
When I execute this, I can get the full path of the the Python interpreter that called this script.
```sh
$ /mingw64/bin/python3.9.exe foo.py
/mingw64/bin/python3.9.exe
```
How to do this in nim (`nimscript`)? | 2021/10/22 | [
"https://Stackoverflow.com/questions/69675173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1805129/"
] | The question mentions [NimScript](https://nim-lang.github.io/Nim/nims.html), which has other uses in the Nim ecosystem, but can also be used to write executable scripts instead of using, e.g., Bash or Python. You can use the [`selfExe`](https://nim-lang.github.io/Nim/nimscript.html#selfExe) proc to get the path to the ... | If you want to do that in Nim (not NimScript), you can take compiler executable path using <https://nim-lang.org/docs/os.html#getCurrentCompilerExe>
```
import os
echo getCurrentCompilerExe()
``` |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | I hope this will help you and it works fine on my project.
```
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 123;
public static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 124;
public static final int MY_PERMISSIONS_REQUEST_CAMERA = 124;
@TargetApi(Build... | Try adding permission to MANIFEST file.
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your checkPermissionsR() get this permission
```
ContextCompat.checkSelfPermission(this, Manifest.permission.Camera)
``` |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | In your case 1 , You are taking permission about writing external storage , you should take permission about using camera, SO first mentioned permission in your manifest like this .
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your **checkPermissionsR()** get this permission
```
Con... | Try adding permission to MANIFEST file.
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your checkPermissionsR() get this permission
```
ContextCompat.checkSelfPermission(this, Manifest.permission.Camera)
``` |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | Try requesting all the permissions at once at the start up of your application.
Like in your `MainActivity`
First in your `onCreate` method call this:
```
checkPermissions();
```
Then try calling these methods:
```
private void checkPermissions() {
if (Build.VERSION.SDK_INT >= 23) {
if (!check... | Try adding permission to MANIFEST file.
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your checkPermissionsR() get this permission
```
ContextCompat.checkSelfPermission(this, Manifest.permission.Camera)
``` |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | >
> Try this one
>
>
>
```
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
... | Try adding permission to MANIFEST file.
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your checkPermissionsR() get this permission
```
ContextCompat.checkSelfPermission(this, Manifest.permission.Camera)
``` |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | In your case 1 , You are taking permission about writing external storage , you should take permission about using camera, SO first mentioned permission in your manifest like this .
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your **checkPermissionsR()** get this permission
```
Con... | I hope this will help you and it works fine on my project.
```
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 123;
public static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 124;
public static final int MY_PERMISSIONS_REQUEST_CAMERA = 124;
@TargetApi(Build... |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | Try requesting all the permissions at once at the start up of your application.
Like in your `MainActivity`
First in your `onCreate` method call this:
```
checkPermissions();
```
Then try calling these methods:
```
private void checkPermissions() {
if (Build.VERSION.SDK_INT >= 23) {
if (!check... | I hope this will help you and it works fine on my project.
```
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 123;
public static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 124;
public static final int MY_PERMISSIONS_REQUEST_CAMERA = 124;
@TargetApi(Build... |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | I hope this will help you and it works fine on my project.
```
public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 123;
public static final int MY_PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 124;
public static final int MY_PERMISSIONS_REQUEST_CAMERA = 124;
@TargetApi(Build... | >
> Try this one
>
>
>
```
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
... |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | In your case 1 , You are taking permission about writing external storage , you should take permission about using camera, SO first mentioned permission in your manifest like this .
```
<uses-permission android:name="android.permission.CAMERA" />
```
and in your **checkPermissionsR()** get this permission
```
Con... | >
> Try this one
>
>
>
```
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
... |
47,405,748 | I am reading python official documentation word by word.
In the 3.3. Special method names [3.3.1. Basic customization](https://docs.python.org/3/reference/datamodel.html#basic-customization)
It does specify 16 special methods under `object` basic customization, I collect them as following:
```
In [47]: bc =['__new__... | 2017/11/21 | [
"https://Stackoverflow.com/questions/47405748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7301792/"
] | Try requesting all the permissions at once at the start up of your application.
Like in your `MainActivity`
First in your `onCreate` method call this:
```
checkPermissions();
```
Then try calling these methods:
```
private void checkPermissions() {
if (Build.VERSION.SDK_INT >= 23) {
if (!check... | >
> Try this one
>
>
>
```
if (ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
... |
59,783,094 | I am running `py.test` 4.3.1 with `python` 3.7.6 on a Mac (Mojave) and I want to get the list of markers for the 'session', once at the begin of the run.
In `conftest.py` I have tried using the following function:
```
@pytest.fixture(scope="session", autouse=True)
def collab_setup(request):
print([marker.name fo... | 2020/01/17 | [
"https://Stackoverflow.com/questions/59783094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1581090/"
] | If the `locationName` gets as input `[1,5]` then the code should look like this:
```
filterData(locationName: number[]) {
return ELEMENT_DATA.filter(object => {
return locationName.includes(object.position);
});
}
``` | You can use [Array.prototype.filter()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter)
```
ELEMENT_DATA.filter(function (object) {
return locationName.indexOf(object.position) !== -1; // -1 means not present
});
```
or with underscore JS , using the same predicate:
`... |
14,490,845 | Python 2.6 on Redhat 6.3
I have a device that saves 32 bit floating point value across 2 memory registers, split into most significant word and least significant word.
I need to convert this to a float.
I have been using the following code found on SO and it is similar to code I have seen elsewhere
```
#!/usr/bin/en... | 2013/01/23 | [
"https://Stackoverflow.com/questions/14490845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1635823/"
] | If you have the raw bytes (e.g. read from memory, from file, over the network, ...) you can use `struct` for this:
```
>>> import struct
>>> struct.unpack('>f', '\x3f\x9a\xec\xb5')[0]
1.2103487253189087
```
Here, `\x3f\x9a\xec\xb5` are your input registers, 16282 (hex 0x3f9a) and 60597 (hex 0xecb5) expressed as byte... | The way you've converting the two `int`s makes implicit assumptions about [endianness](http://en.wikipedia.org/wiki/Endianness) that I believe are wrong.
So, let's back up a step. You know that the first argument is the most significant word, and the second is the least significant word. So, rather than try to figure ... |
58,770,519 | How to do this
```
c++ -> Python -> c++
^ |
| |
-----------------
```
1. C++ app is hosting python.
2. Python creates a class, which is actually a wrapping to c/c++ object
3. How to get access from hosting c++ to c/c++ pointer of this object created by python?
**Example with code:**
... | 2019/11/08 | [
"https://Stackoverflow.com/questions/58770519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/548894/"
] | ```
#include <Python.h>
int main(int argc, char *argv[])
{
Py_SetProgramName(argv[0]);
Py_Initialize();
object module = import("__main__");
object space = module.attr("__dict__");
exec("from cat import Cat \n"
"cat = Cat(10) \n",
space);
Cat& cat = extract<Cat&>(space["cat"]);
std::cout<... | In case the wrapper is open source, use the wrapper's python object struct from C++. Cast the PyObject \* to that struct which should have a PyObject as its first member iirc, and simply access the pointer to the C++ instance.
Make sure that the instance is not deleted while you're using it by keeping the wrapper inst... |
6,124,701 | I feel like this is simple, but I just don't know enough about python to do it correctly.
I have two files:
1. File with lines listing an id number and whether that id is used. Format is 'id, isUsed'.
2. File with rules containing one rule for each id.
So what I want to do is to parse through the file with id-used p... | 2011/05/25 | [
"https://Stackoverflow.com/questions/6124701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/240522/"
] | I suggest you read the rules file into a dictionary (id -> rule). Then, as you read the config file, write out the corresponding rule (including a comment if you need to).
some pseudocode:
```
rules = {}
for id, rule in read_rules_file():
rules[id] = rule
for id, isUsed in read_pairs_file():
if isUsed:
... | I don't know why I didn't think of this before, but there is another way to do this.
First, you read which rules should be used (or not used) into memory, I stored it into a dictionary.
```
def readRulesIntoMemory(fileName):
rules = {}
# Open csv file with rule id, isUsed pairs
fd = open(fileName, 'r')
... |
63,749,945 | I'm a beginner at python and I made this random date generator which should generate year-month-date output. And 4,6,9,11 months have 30 days, all others 31.
But I'm having a problem where february in leap year still generates date=30 despite if and elif having the condition where M must be 2.
```
import random
impor... | 2020/09/05 | [
"https://Stackoverflow.com/questions/63749945",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14224115/"
] | Several problems mentioned in comments:
* you are using `rand` instead of `random`
* you are using `G` when presumably it should be `Y`
See a refactored code, rewriting the `if` statements to first test `M` then test `Y`.
```
import random
import calendar
for i in range(500):
Y = random.randint(0, 170)
M = r... | The final else-block is executed if `M == 2` and overwrites `D`.
Simple solution can be to reorder the two if parts:
```
import random as rand
import calendar
for i in range(500):
G = rand.randint(0, 170)
M = rand.randint(1, 12)
if M == 4 or M == 6 or M == 9 or M == 11:
D=rand.randint(1, 30)
... |
6,132,423 | I was trying to install SCRAPY and play with it.
The tutorial says to run this:
```
scrapy startproject tutorial
```
Can you please break this down to help me understand it. I have various releases of Python on my Windows 7 machine for various conflicting projects, so when I installed Scrapy with their .exe, i... | 2011/05/26 | [
"https://Stackoverflow.com/questions/6132423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/160245/"
] | scrapy is a batch file which execute a python file called "scrapy", so you need to add the file "scrapy"'s path to your PATH environment.
if that is still not work, make "scrapy.py" file with content
```
from scrapy.cmdline import execute
execute()
```
and run `\python26_32bit\python.exe scrapy.py startproject tuto... | Try
```
C:\Python26_32bit\Scripts\Scrapy startproject tutorial
```
or
add `C:\Python26_32bit\Scripts` to your path |
6,132,423 | I was trying to install SCRAPY and play with it.
The tutorial says to run this:
```
scrapy startproject tutorial
```
Can you please break this down to help me understand it. I have various releases of Python on my Windows 7 machine for various conflicting projects, so when I installed Scrapy with their .exe, i... | 2011/05/26 | [
"https://Stackoverflow.com/questions/6132423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/160245/"
] | scrapy is a batch file which execute a python file called "scrapy", so you need to add the file "scrapy"'s path to your PATH environment.
if that is still not work, make "scrapy.py" file with content
```
from scrapy.cmdline import execute
execute()
```
and run `\python26_32bit\python.exe scrapy.py startproject tuto... | I ran accross this error with the following setup: Python installed on Windows. Cygwin (babun) installed. Used `pip install Scrapy` from the Windows installation (Scrapy now in C:\Python27\Lib\site-packages\scrapy). Wanted to use Scrapy from within babun. Got the same error as you. What you can do:
In your .bashrc/.zs... |
6,132,423 | I was trying to install SCRAPY and play with it.
The tutorial says to run this:
```
scrapy startproject tutorial
```
Can you please break this down to help me understand it. I have various releases of Python on my Windows 7 machine for various conflicting projects, so when I installed Scrapy with their .exe, i... | 2011/05/26 | [
"https://Stackoverflow.com/questions/6132423",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/160245/"
] | Try
```
C:\Python26_32bit\Scripts\Scrapy startproject tutorial
```
or
add `C:\Python26_32bit\Scripts` to your path | I ran accross this error with the following setup: Python installed on Windows. Cygwin (babun) installed. Used `pip install Scrapy` from the Windows installation (Scrapy now in C:\Python27\Lib\site-packages\scrapy). Wanted to use Scrapy from within babun. Got the same error as you. What you can do:
In your .bashrc/.zs... |
70,058,771 | Im trying to use python to determine the continued fractions of pi by following the stern brocot tree. Its simple, if my estimation of pi is too high, take a left, if my estimation of pi is too low, take a right.
Im using `mpmath` to get arbitrary precision floating numbers, as python doesn't support that, but no matt... | 2021/11/21 | [
"https://Stackoverflow.com/questions/70058771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16155472/"
] | Never fails that as soon as I post a question I find the answer. For anyone else looking for something similar:
The first bracket matches all slashes `[/]`
The parenthesis capture the group, in this case the group of numbers `([0-9])`
The `[0-9]` searches the range of numbers between 0 and 9
`{8}` is the quantifier, i... | Use
```php
/\d{8}/
```
See [regex proof](https://regex101.com/r/sPLT7b/1).
**EXPLANATION**
```php
--------------------------------------------------------------------------------
/ '/'
--------------------------------------------------------------------------------
\d{8} ... |
71,857,414 | **The error :**
from asyncio.windows\_events import NULL
File "/app/.heroku/python/lib/python3.10/asyncio/windows\_events.py", line 6, in
raise ImportError('win32 only')
ImportError: win32 only
**please how can i fix this ?** | 2022/04/13 | [
"https://Stackoverflow.com/questions/71857414",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18793327/"
] | I had the same error while trying to deploy:
```
File "/tmp/build_4a1c8563/base/models.py", line 1, in <module>
from asyncio.windows_events import NULL
File "/app/.heroku/python/lib/python3.9/asyncio/windows_events.py", line 6, in <module>
raise ImportError('win32 only')
```
I deleted the "from asyncio... | I had the same error while deploying:
your IDE have imported `from asyncio.windows_events import NULL` line automatically while you were typing NULL
Just delete this line
```
from asyncio.windows_events import NULL
``` |
42,164,772 | I can't achieve to make summaries work with the Estimator API of Tensorflow.
The Estimator class is very useful for many reasons: I have already implemented my own classes which are really similar but I am trying to switch to this one.
Here is the code sample:
```
import tensorflow as tf
import tensorflow.contrib.la... | 2017/02/10 | [
"https://Stackoverflow.com/questions/42164772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5184894/"
] | The intended use case is that you let the Estimator save summaries for you. There are options in [RunConfig](https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/learn/python/learn/estimators/run_config.py#L182) for configuring summary writing. RunConfigs get passed when [constructing the Estimator](... | Just have `tf.summary.scalar("loss", loss)` in the `model_fn`, and run the code without `summary_hook`. The loss is recorded and shown in the tensorboard.
---
See also:
* [Tensorflow - Using tf.summary with 1.2 Estimator API](https://stackoverflow.com/questions/45086109/tensorflow-using-tf-summary-with-1-2-estimator... |
24,021,831 | I'm a Transifex user, I need to retrieve my dashboard page with the list of all the projects of my organization.
that is, the page I see when I login: <https://www.transifex.com/organization/(my_organization_name)/dashboard>
I can access Transifex API with this code:
```
import urllib.request as url
usr = 'myusernam... | 2014/06/03 | [
"https://Stackoverflow.com/questions/24021831",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3704129/"
] | The call to
>
> /projects/
>
>
>
returns your projects along with all the public projects that you can have access (like what you said). You can search for the ones that you need by modifying the call to something like:
>
> <https://www.transifex.com/api/2/projects/?start=1&end=6>
>
>
>
Doing so the number ... | Transifex comes with an API, and you can use it to fetch all the projects you have.
I think that what you need [this](http://docs.transifex.com/developer/api/projects) GET request on projects. It returns a list of (slug, name, description, source\_language\_code) for all projects that you have access to in JSON format... |
60,202,828 | I have been learning about the Trie structure through python. What is a little bit different about his trie compared to other tries is the fact that we are trying to implement a counter into every node of the trie in order to do an autocomplete (that is the final hope for the project). So far, I decided that having a r... | 2020/02/13 | [
"https://Stackoverflow.com/questions/60202828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11659038/"
] | Try this
```
mapply(function(x,y){paste(intersect(x,y),collapse=", ")},
strsplit(as.character(df$text),"\\, | "),
strsplit(as.character(df$word),"\\, | "))
[1] "red, green" "red" "blue"
``` | ```
library(tidyverse)
df %>%
mutate(newcol = stringr::str_extract_all(text,gsub(", +","|",word)))
country text word newcol
1 CA paint red green green, red, blue red, green
2 IN painting red red red
3 US painting blue re... |
60,202,828 | I have been learning about the Trie structure through python. What is a little bit different about his trie compared to other tries is the fact that we are trying to implement a counter into every node of the trie in order to do an autocomplete (that is the final hope for the project). So far, I decided that having a r... | 2020/02/13 | [
"https://Stackoverflow.com/questions/60202828",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11659038/"
] | Another base R solution using `mapply` + `grep` + `regmatches`, i.e.,
```
df <- within(df, newcol <- mapply(function(x,y) toString(grep(x,y,value = TRUE)),
gsub("\\W+","|",word),
regmatches(text,gregexpr("\\w+",text))))
```
such that
```
> df
c... | ```
library(tidyverse)
df %>%
mutate(newcol = stringr::str_extract_all(text,gsub(", +","|",word)))
country text word newcol
1 CA paint red green green, red, blue red, green
2 IN painting red red red
3 US painting blue re... |
12,794,357 | I have 2 python scripts inside my c:\Python32
1)Tima\_guess.py which looks like this:
```
#Author:Roshan Mehta
#Date :9th October 2012
import random,time,sys
ghost ='''
0000 0 000----
00000-----0-0
----0000---0
'''
guess_taken = 0
print('Hello! What is your name?')
name = input()
light_switch = random.randint(1,12... | 2012/10/09 | [
"https://Stackoverflow.com/questions/12794357",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1716525/"
] | After building, add re.pyc to the library.zip file.
To get re.pyc, all you need to do is run re.py successfully, then open `__pycache__` folder, then you will see a file like re.cpython-32.pyc, rename it to re.pyc and voila! | **setup.py**
```
from cx_Freeze import setup, Executable
build_exe_options = {"includes": ["re"]}
setup(
name = "Console game",
version = "0.1",
description = "Nothing!",
options = {"build_exe": build_exe_options},
executables = [Executable("Tima_guess.py")])
``` |
55,577,991 | I am trying to install `fiona=1.6` but I get the following error
```
conda install fiona=1.6
WARNING: The conda.compat module is deprecated and will be removed in a future release.
Collecting package metadata: done
Solving environment: -
The environment is inconsistent, please check the package plan carefully
The fo... | 2019/04/08 | [
"https://Stackoverflow.com/questions/55577991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3590067/"
] | Python Versions
===============
The [Conda Forge channel only has gdal v1.11.4 for Python 2.7, 3.4, and 3.5](https://anaconda.org/conda-forge/gdal/files?version=1.11.4). You either need to use a newer version of Fiona (current is 1.8) or make a new env that includes one of those older Python versions.
For example,
... | Doing what the error message told me to,
>
> To search for alternate channels that may provide the conda package you're
> looking for, navigate to <https://anaconda.org>
>
>
>
and typing in `gdal` in the search box led me to <https://anaconda.org/conda-forge/gdal> which has this installation instruction:
>
> `... |
23,871,680 | I downloaded the git repo from the official link,
```
git clone git://
```
and I ran `./configure && make && make install` where the `make install` returns with error:
```
LINK(target) /usr/local/bin/node/out/Release/node: Finished
touch /usr/local/bin/node/out/Release/obj.target/node_dtrace_header.stamp
touc... | 2014/05/26 | [
"https://Stackoverflow.com/questions/23871680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1948292/"
] | You can use an injection interceptor.
>
> For EJB 3 Session Beans and Message-Driven Beans, Spring provides a
> convenient interceptor that resolves Spring 2.5's @Autowired
> annotation in the EJB component class:
> org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.
> This interceptor can be app... | I understand you question as: you have problem to inject a request scoped bean into another using spring.
so try this:
```
<bean id="boo" class="Boo" scope="request">
<aop:scoped-proxy/>
</bean>
<bean id="foo" class="Foo">
<property name="boo" ref="Boo" />
</bean>
``` |
13,549,699 | I wish to mock a class with the following requirements:
* The class has public read/write properties, defined in its `__init__()` method
* The class has public attribute which is auto-incremented on object creation
* I wish to use `autospec=True`, so the class's API will be strictly checks on calls
A simplified class... | 2012/11/25 | [
"https://Stackoverflow.com/questions/13549699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/499721/"
] | Since no answers are coming in, I'll post what worked for me (not necessarily the best approach, but here goes):
I've created a mock factory which creates a `Mock()` object, sets its `id` property using the syntax described [here](http://www.voidspace.org.uk/python/mock/mock.html#mock.PropertyMock), and returns the ob... | Sorry to dig up an old post, but something that would allow you to do precisely what you would like to achieve is to patch `calc_x_times_y` and `calc_x_div_y` and set `autospec=True` there, as opposed to Mocking the creation of the entire class.
Something like:
```
@patch('MyClass.calc_x_times_y')
@patch('MyClass.cal... |
58,016,261 | So, i am trying to create a linear functions in python such has `y = x` without using `numpy.linspace()`. In my understanding numpy.linspace() gives you an array which is discontinuous. But to fo
I am trying to find the intersection of `y = x` and a function unsolvable analytically ( such has the one in the picture ) ... | 2019/09/19 | [
"https://Stackoverflow.com/questions/58016261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12091717/"
] | Since your functions are differentiable, you could use the [Newton-Raphson method](https://en.wikipedia.org/wiki/Newton%27s_method) implemented by `scipy.optimize`:
```
>>> scipy.optimize.newton(lambda x: 1.5*(1-math.exp(-x))-x, 10)
0.8742174657987283
```
Computing the error is very straightforward:
```
>>> def f(x... | “Not solvable analytically” means there is no closed-form solution. In other words, you cant write down a single answer on paper like a number or equation and circle it and say ”thats my answer.” For some math problems it’s impossible to do so. Instead, for these kinds of problems, we can approximate the solution by ru... |
58,016,261 | So, i am trying to create a linear functions in python such has `y = x` without using `numpy.linspace()`. In my understanding numpy.linspace() gives you an array which is discontinuous. But to fo
I am trying to find the intersection of `y = x` and a function unsolvable analytically ( such has the one in the picture ) ... | 2019/09/19 | [
"https://Stackoverflow.com/questions/58016261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12091717/"
] | I'm not a mathematician so perhaps you can explain me sth here, but I don't understand what exactly you mean by "unsolvable analytically".
That's what sympy returns:
```
from sympy import *
x = symbols('x')
a = 1.5
y1 = x
y2 = a*(1 - exp(-x))
print(solve(y1-y2))
# [0.874217465798717]
``` | “Not solvable analytically” means there is no closed-form solution. In other words, you cant write down a single answer on paper like a number or equation and circle it and say ”thats my answer.” For some math problems it’s impossible to do so. Instead, for these kinds of problems, we can approximate the solution by ru... |
15,040,884 | I want to list all the keys stored in the memcached server.
I googled for the same, I got some python/php scripts that can list the same. I tested it but all went failed and none gave me full keys. I can see thousands of keys using telnet command
```
stats items
```
I used perl script that uses telnet to list keys,... | 2013/02/23 | [
"https://Stackoverflow.com/questions/15040884",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1308498/"
] | memcache does not provide an api to exhaustively list all keys. "stats items" is as good as it gets to list the first 1M of keys. More info here: <http://www.darkcoding.net/software/memcached-list-all-keys/>
Not sure if that helps you but redis (which could be considered a superset of memcache) provides a more compreh... | It you use python-memcached, and would like to export all the items in memcache server, I summerized two methods to the problem in this question: [Export all keys and values from memcached with python-memcache](https://stackoverflow.com/questions/5730276/export-all-keys-and-values-from-memcached-with-python-memcache) |
3,224,924 | Is there anything in python that lets me dump out a random object in such a way as to see its underlying data representation?
I am coming from Perl where Data::Dumper does a reasonable job of letting me see how a data structure is laid out. Is there anything that does the same thing in python?
Thanks! | 2010/07/11 | [
"https://Stackoverflow.com/questions/3224924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/365530/"
] | Well `Dumper` in Perl gives you a representation of an object that can be `eval`'d by the interpreter to give you the original object. An object's `repr` in Python tries to do that, and sometimes it's possible. A `dict`'s `repr` or a `str`'s `repr` do this, and some classes like `datetime` and `timedelta` also do this.... | After much searching about for this exactly myself, I came across this Dumper equivalent which I typically import now. <https://salmon-protocol.googlecode.com/svn-history/r24/trunk/salmon-playground/dumper.py> |
9,595,009 | What is the difference between [`warnings.warn()`](https://docs.python.org/library/warnings.html#warnings.warn) and [`logging.warn()`](https://docs.python.org/library/logging.html#logging.Logger.warning) in terms of what they do and how they should be used? | 2012/03/07 | [
"https://Stackoverflow.com/questions/9595009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84952/"
] | I agree with the other answer -- `logging` is for logging and `warning` is for warning -- but I'd like to add more detail.
Here is a tutorial-style HOWTO taking you through the steps in using the `logging` module.
<https://docs.python.org/3/howto/logging.html>
It directly answers your question:
>
> warnings.warn()... | Besides the [canonical explanation in official documentation](https://docs.python.org/2/howto/logging.html#when-to-use-logging)
>
> warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning
>
>
> logging.warning() if there is nothing the client ... |
9,595,009 | What is the difference between [`warnings.warn()`](https://docs.python.org/library/warnings.html#warnings.warn) and [`logging.warn()`](https://docs.python.org/library/logging.html#logging.Logger.warning) in terms of what they do and how they should be used? | 2012/03/07 | [
"https://Stackoverflow.com/questions/9595009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/84952/"
] | [`logging.warning`](https://docs.python.org/library/logging.html#logging.warning) just logs something at the `WARNING` level, in the same way that `logging.info` logs at the `INFO` level and `logging.error` logs at the `ERROR` level. It has no special behaviour.
[`warnings.warn`](https://docs.python.org/library/warnin... | Besides the [canonical explanation in official documentation](https://docs.python.org/2/howto/logging.html#when-to-use-logging)
>
> warnings.warn() in library code if the issue is avoidable and the client application should be modified to eliminate the warning
>
>
> logging.warning() if there is nothing the client ... |
2,248,699 | Is there something like twisted (python) or eventmachine (ruby) in .net land?
Do I even need this abstraction? I am listening to a single IO device that will be sending me events for three or four analog sensors attached to it. What are the risks of simply using a looped `UdpClient`? I can't miss any events, but will ... | 2010/02/11 | [
"https://Stackoverflow.com/questions/2248699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804/"
] | I think you are making it too complicated.
Just have 1 UDP socket open, and set an async callback on it. For every incoming packet put it in a queue, and set the callback again. Thats it.
make sure that when queuing and dequeueing you set a lock on the queue.
it's as simple as that and performance will be great.
R | I would recommend [ICE](http://www.zeroc.com) it's a communication engine that will abstract threading and communication to you (documentation is kind of exhaustive). |
2,248,699 | Is there something like twisted (python) or eventmachine (ruby) in .net land?
Do I even need this abstraction? I am listening to a single IO device that will be sending me events for three or four analog sensors attached to it. What are the risks of simply using a looped `UdpClient`? I can't miss any events, but will ... | 2010/02/11 | [
"https://Stackoverflow.com/questions/2248699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804/"
] | I think you are making it too complicated.
Just have 1 UDP socket open, and set an async callback on it. For every incoming packet put it in a queue, and set the callback again. Thats it.
make sure that when queuing and dequeueing you set a lock on the queue.
it's as simple as that and performance will be great.
R | Problem is that with Udp you are automatically assuming the risk of lost packets. I've read the documentation on ICE (as Steve suggested), and it is *very* exhaustive. It appears that ICE will work for Udp, however, it appears that Tcp is preferred by the developers. I gather from the ICE documentation that it does not... |
2,248,699 | Is there something like twisted (python) or eventmachine (ruby) in .net land?
Do I even need this abstraction? I am listening to a single IO device that will be sending me events for three or four analog sensors attached to it. What are the risks of simply using a looped `UdpClient`? I can't miss any events, but will ... | 2010/02/11 | [
"https://Stackoverflow.com/questions/2248699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/804/"
] | I think you are making it too complicated.
Just have 1 UDP socket open, and set an async callback on it. For every incoming packet put it in a queue, and set the callback again. Thats it.
make sure that when queuing and dequeueing you set a lock on the queue.
it's as simple as that and performance will be great.
R | It sounds like you are looking for reliable multicast -You could try [RMF](http://www.mesongo.com/rmf.aspx) , it will do the reliability and deliver the messages using asyc callbacks from the incoming message queue. IBM also does WebSphere which has a UDP component. EmCaster is also an option - however development seem... |
57,087,455 | I need to compare data in two tables. These tables are similar in schema but will have different data values. I want to export these data to csv or similar format and then check for differences.
I would like to perform this check with a python script. I have already figured out how to export the data to csv format. Bu... | 2019/07/18 | [
"https://Stackoverflow.com/questions/57087455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4817150/"
] | I finally managed to get it working by adding `contentContainerStyle={{borderRadius: 6, overflow: 'hidden'}}` to the FlatList. | Recreated the structure and for me its working fine with border radius
Snack link: <https://snack.expo.io/@msbot01/disrespectful-chocolate>
```
<View style={styles.container}>
<ImageBackground source={{uri: 'https://artofislamicpattern.com/wp-content/uploads/2012/10/3.jpg'}} style={{width: '100%', height: '100... |
57,087,455 | I need to compare data in two tables. These tables are similar in schema but will have different data values. I want to export these data to csv or similar format and then check for differences.
I would like to perform this check with a python script. I have already figured out how to export the data to csv format. Bu... | 2019/07/18 | [
"https://Stackoverflow.com/questions/57087455",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4817150/"
] | I finally managed to get it working by adding `contentContainerStyle={{borderRadius: 6, overflow: 'hidden'}}` to the FlatList. | To add styles use like this:
<ListItem
containerStyle={{
borderRadius: 8,
overflow: 'hidden',
}}
/> |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | Make sure that the same settings are used when migrating and running!
Thus I would recommend you change this kind of code in ***django.config***
```yaml
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: true
```
to:
```yaml
contain... | In reference to Oscar Chen answer, you can set environmental variables using eb cli with
```
eb setenv key1=value1 key2=valu2 ...etc
``` |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | Make sure that the same settings are used when migrating and running!
Thus I would recommend you change this kind of code in ***django.config***
```yaml
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: true
```
to:
```yaml
contain... | `django-admin` method not working as it was not configured properly. You can also use `python manage.py migrate` in
**.ebextentions/django.config**
```
container_commands:
01_migrate:
command: "python manage.py migrate"
leader_only: true
``` |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | Aside from the automatic migration that you can add to deploy script (which runs every time you update the environment, and may not be desirable if you have long running migration or other Django management commands), you can ssh into an EB instance to run migration manually.
Here is how to **manually run migration** ... | `django-admin` method not working as it was not configured properly. You can also use `python manage.py migrate` in
**.ebextentions/django.config**
```
container_commands:
01_migrate:
command: "python manage.py migrate"
leader_only: true
``` |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | I'm not sure there is a specific way to answer yes or no. but you can append `--noinput` to your container command. Use the `--noinput` option to suppress all user prompting, such as “Are you sure?” confirmation messages.
```
try
command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate --... | The trick is that the full output of `container_commands` is in `/var/log/cfn-init-cmd.log` (Amazon Linux 2 Elastic Beanstalk released November 2020).
To view this you would run:
```
eb ssh [environment-name]
sudo tail -n 50 -f /var/log/cfn-init-cmd.log
```
This doesn't seem to be documented anywhere obvious and it... |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | Make sure that the same settings are used when migrating and running!
Thus I would recommend you change this kind of code in ***django.config***
```yaml
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: true
```
to:
```yaml
contain... | The trick is that the full output of `container_commands` is in `/var/log/cfn-init-cmd.log` (Amazon Linux 2 Elastic Beanstalk released November 2020).
To view this you would run:
```
eb ssh [environment-name]
sudo tail -n 50 -f /var/log/cfn-init-cmd.log
```
This doesn't seem to be documented anywhere obvious and it... |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | I'm not sure there is a specific way to answer yes or no. but you can append `--noinput` to your container command. Use the `--noinput` option to suppress all user prompting, such as “Are you sure?” confirmation messages.
```
try
command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate --... | Make sure that the same settings are used when migrating and running!
Thus I would recommend you change this kind of code in ***django.config***
```yaml
container_commands:
01_migrate:
command: "source /opt/python/run/venv/bin/activate && python manage.py migrate"
leader_only: true
```
to:
```yaml
contain... |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | `django-admin` method not working as it was not configured properly. You can also use `python manage.py migrate` in
**.ebextentions/django.config**
```
container_commands:
01_migrate:
command: "python manage.py migrate"
leader_only: true
``` | [This answer](https://stackoverflow.com/questions/18869414/can-stale-content-types-be-automatically-deleted-in-django) looks like it will work for you if you just want to send "yes" to a few prompts.
You might also consider the `--noinput` flag so that your config looks like:
```
container_commands:
01_migrate:
... |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | I'm not sure there is a specific way to answer yes or no. but you can append `--noinput` to your container command. Use the `--noinput` option to suppress all user prompting, such as “Are you sure?” confirmation messages.
```
try
command: 'source /opt/python/run/venv/bin/activate && python app/manage.py migrate --... | `django-admin` method not working as it was not configured properly. You can also use `python manage.py migrate` in
**.ebextentions/django.config**
```
container_commands:
01_migrate:
command: "python manage.py migrate"
leader_only: true
``` |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | Aside from the automatic migration that you can add to deploy script (which runs every time you update the environment, and may not be desirable if you have long running migration or other Django management commands), you can ssh into an EB instance to run migration manually.
Here is how to **manually run migration** ... | The trick is that the full output of `container_commands` is in `/var/log/cfn-init-cmd.log` (Amazon Linux 2 Elastic Beanstalk released November 2020).
To view this you would run:
```
eb ssh [environment-name]
sudo tail -n 50 -f /var/log/cfn-init-cmd.log
```
This doesn't seem to be documented anywhere obvious and it... |
30,950,941 | I have my Django app set up on Elastic Beanstalk and recently made a change to the DB that I would like to have applied to the live DB now. I understand that I need to set this up as a container command, and after checking the DB I can see that the migration was run, but I can't figure out how to have more controls ove... | 2015/06/20 | [
"https://Stackoverflow.com/questions/30950941",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2989731/"
] | Aside from the automatic migration that you can add to deploy script (which runs every time you update the environment, and may not be desirable if you have long running migration or other Django management commands), you can ssh into an EB instance to run migration manually.
Here is how to **manually run migration** ... | [This answer](https://stackoverflow.com/questions/18869414/can-stale-content-types-be-automatically-deleted-in-django) looks like it will work for you if you just want to send "yes" to a few prompts.
You might also consider the `--noinput` flag so that your config looks like:
```
container_commands:
01_migrate:
... |
57,901,995 | i have a dockerfile which looks like this:
```
FROM python:3.7-slim-stretch
ENV PIP pip
RUN \
$PIP install --upgrade pip && \
$PIP install scikit-learn && \
$PIP install scikit-image && \
$PIP install rasterio && \
$PIP install geopandas && \
$PIP install matplotlib
COPY sentools sentool... | 2019/09/12 | [
"https://Stackoverflow.com/questions/57901995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11310755/"
] | If the base code is same, and only the container is supposed to run up with different Python Script, So then I will suggest using single Docker and you will not worry about the management of two docker image.
Set `vegetation.py` to default, when container is up without passing ENV it will run `vegetation.py` and if th... | If you insist in creating separate images, you can always use the [ARG](https://docs.docker.com/engine/reference/builder/#arg) command.
```
FROM python:3.7-slim-stretch
ARG file_to_copy
ENV PIP pip
RUN \
$PIP install --upgrade pip && \
$PIP install scikit-learn && \
$PIP install scikit-image && \
$PIP... |
57,901,995 | i have a dockerfile which looks like this:
```
FROM python:3.7-slim-stretch
ENV PIP pip
RUN \
$PIP install --upgrade pip && \
$PIP install scikit-learn && \
$PIP install scikit-image && \
$PIP install rasterio && \
$PIP install geopandas && \
$PIP install matplotlib
COPY sentools sentool... | 2019/09/12 | [
"https://Stackoverflow.com/questions/57901995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11310755/"
] | If the base code is same, and only the container is supposed to run up with different Python Script, So then I will suggest using single Docker and you will not worry about the management of two docker image.
Set `vegetation.py` to default, when container is up without passing ENV it will run `vegetation.py` and if th... | When you start a Docker container, you can specify what command to run at the end of the `docker run` command. So you can build a single image that contains both scripts and pick which one runs when you start the container.
The scripts should be "normally" executable: they need to have the executable permission bit se... |
57,901,995 | i have a dockerfile which looks like this:
```
FROM python:3.7-slim-stretch
ENV PIP pip
RUN \
$PIP install --upgrade pip && \
$PIP install scikit-learn && \
$PIP install scikit-image && \
$PIP install rasterio && \
$PIP install geopandas && \
$PIP install matplotlib
COPY sentools sentool... | 2019/09/12 | [
"https://Stackoverflow.com/questions/57901995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11310755/"
] | If you insist in creating separate images, you can always use the [ARG](https://docs.docker.com/engine/reference/builder/#arg) command.
```
FROM python:3.7-slim-stretch
ARG file_to_copy
ENV PIP pip
RUN \
$PIP install --upgrade pip && \
$PIP install scikit-learn && \
$PIP install scikit-image && \
$PIP... | When you start a Docker container, you can specify what command to run at the end of the `docker run` command. So you can build a single image that contains both scripts and pick which one runs when you start the container.
The scripts should be "normally" executable: they need to have the executable permission bit se... |
18,238,558 | I am new to python language. My problem is I have two python scripts : Automation script A and a main script B. Script A internally calls script B. Script B exits whenever an exception is caught using sys.exit(1) functionality. Now, whenever script B exits it result in exit of script A also. Is there any way to stop ex... | 2013/08/14 | [
"https://Stackoverflow.com/questions/18238558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2286286/"
] | You should encapsulate the code in a try except block. That will catch your exception, and continue executing script A. | `sys.exit()` actually raises a `SystemExit` exception which is caught and handled by the Python interpreter. All you have to do is put the call into to "script B" into a try/except block that catches `SystemExit` before it bubbles all the way up. For example:
```
try:
script_b.do_stuff()
except SystemExit as e:
... |
63,867,203 | I wrote some code in python to see how many times one number can be divided by a number, until it gets a value of one.
```
counter_var = 1
quotient = num1/num2
if quotient<1:
print('1 time')
else:
while quotient >= 1:
quotient = num1/num2
counter_var = counter_var + 1
print(counter_var)
... | 2020/09/13 | [
"https://Stackoverflow.com/questions/63867203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14108602/"
] | you are not changing the value of quotient in the while loop. it remains constant.
instead of **quotient = num1/num2** it should be **quotient /= num2** if I understand your problem correctly. | well to start, you're missing assignment to numbers,
in the case of num1>num2 , you will be entering an endless while loop and hence you will never get to the `print(counter_var)` snippet |
63,867,203 | I wrote some code in python to see how many times one number can be divided by a number, until it gets a value of one.
```
counter_var = 1
quotient = num1/num2
if quotient<1:
print('1 time')
else:
while quotient >= 1:
quotient = num1/num2
counter_var = counter_var + 1
print(counter_var)
... | 2020/09/13 | [
"https://Stackoverflow.com/questions/63867203",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14108602/"
] | you are not changing the value of quotient in the while loop. it remains constant.
instead of **quotient = num1/num2** it should be **quotient /= num2** if I understand your problem correctly. | I did a slight change to your code, since you are always defining the quotient as the initial numbers. Instead, divide your quotient against the num2.
```
counter_var = 1
quotient = num1/num2
if quotient<1:
print('1 time')
else:
quotient = num1/num2
while quotient >= 1:
quotient = quotient/num2
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.