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 |
|---|---|---|---|---|---|
16,794,663 | In python I'm trying to grab multiple inputs from string using regular expression; however, I'm having trouble. For the string:
```
inputs = 12 1 345 543 2
```
I tried using:
```
match = re.match(r'\s*inputs\s*=(\s*\d+)+',string)
```
However, this only returns the value `'2'`. I'm trying to capture all ... | 2013/05/28 | [
"https://Stackoverflow.com/questions/16794663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877334/"
] | You could try something like:
`re.findall("\d+", your_string)`. | You should look at this answer: <https://stackoverflow.com/a/4651893/1129561>
In short:
>
> In Python, this isn’t possible with a single regular expression: each capture of a group overrides the last capture of that same group (in .NET, this would actually be possible since the engine distinguishes between captures... |
16,794,663 | In python I'm trying to grab multiple inputs from string using regular expression; however, I'm having trouble. For the string:
```
inputs = 12 1 345 543 2
```
I tried using:
```
match = re.match(r'\s*inputs\s*=(\s*\d+)+',string)
```
However, this only returns the value `'2'`. I'm trying to capture all ... | 2013/05/28 | [
"https://Stackoverflow.com/questions/16794663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877334/"
] | You could try something like:
`re.findall("\d+", your_string)`. | You cannot do this with a single regex (unless you were using .NET), because each capturing group will only ever return one result even if it is repeated (the last one in the case of Python).
Since variable length lookbehinds are also not possible (in which case you could do `(?<=inputs.*=.*)\d+`), you will have to se... |
16,794,663 | In python I'm trying to grab multiple inputs from string using regular expression; however, I'm having trouble. For the string:
```
inputs = 12 1 345 543 2
```
I tried using:
```
match = re.match(r'\s*inputs\s*=(\s*\d+)+',string)
```
However, this only returns the value `'2'`. I'm trying to capture all ... | 2013/05/28 | [
"https://Stackoverflow.com/questions/16794663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877334/"
] | You could try something like:
`re.findall("\d+", your_string)`. | You can embed your regular expression:
```
import re
s = 'inputs = 12 1 345 543 2'
print re.findall(r'(\d+)', re.match(r'inputs\s*=\s*([\s\d]+)', s).group(1))
>>>
['12', '1', '345', '543', '2']
```
Or do it in layers:
```
import re
def get_inputs(s, regex=r'inputs\s*=\s*([\s\d]+)'):
match = re.match... |
16,794,663 | In python I'm trying to grab multiple inputs from string using regular expression; however, I'm having trouble. For the string:
```
inputs = 12 1 345 543 2
```
I tried using:
```
match = re.match(r'\s*inputs\s*=(\s*\d+)+',string)
```
However, this only returns the value `'2'`. I'm trying to capture all ... | 2013/05/28 | [
"https://Stackoverflow.com/questions/16794663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877334/"
] | You cannot do this with a single regex (unless you were using .NET), because each capturing group will only ever return one result even if it is repeated (the last one in the case of Python).
Since variable length lookbehinds are also not possible (in which case you could do `(?<=inputs.*=.*)\d+`), you will have to se... | You should look at this answer: <https://stackoverflow.com/a/4651893/1129561>
In short:
>
> In Python, this isn’t possible with a single regular expression: each capture of a group overrides the last capture of that same group (in .NET, this would actually be possible since the engine distinguishes between captures... |
16,794,663 | In python I'm trying to grab multiple inputs from string using regular expression; however, I'm having trouble. For the string:
```
inputs = 12 1 345 543 2
```
I tried using:
```
match = re.match(r'\s*inputs\s*=(\s*\d+)+',string)
```
However, this only returns the value `'2'`. I'm trying to capture all ... | 2013/05/28 | [
"https://Stackoverflow.com/questions/16794663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/877334/"
] | You can embed your regular expression:
```
import re
s = 'inputs = 12 1 345 543 2'
print re.findall(r'(\d+)', re.match(r'inputs\s*=\s*([\s\d]+)', s).group(1))
>>>
['12', '1', '345', '543', '2']
```
Or do it in layers:
```
import re
def get_inputs(s, regex=r'inputs\s*=\s*([\s\d]+)'):
match = re.match... | You should look at this answer: <https://stackoverflow.com/a/4651893/1129561>
In short:
>
> In Python, this isn’t possible with a single regular expression: each capture of a group overrides the last capture of that same group (in .NET, this would actually be possible since the engine distinguishes between captures... |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | Ypu have to remove ; which stands for commenting the line
; on\_motion\_detected python /home/pi/Desktop/Python/script.py
but
```
on_motion_detected python /home/pi/Desktop/Python/script.py
``` | Check that you have specified the process id properly in motion.conf:
**process\_id\_file /var/run/motion/motion.pid**
Once you have checked that, change the following settings to arbitrarily low values e.g.
**threshold 1**
**noise\_level 1** |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | if you use threads: threat1.conf, threat2.conf -- try to write script config to them.
My threads:
thread1.conf
```
videodevice /dev/video0
text_left USBWebcam-1
target_dir /samba/hdd/share/motion/usb
rotate 180
width 1024
height 768
#webcam_port 9081
#on_event_start /bin/bash /root/scripts/tg_msg.sh
on_picture_save /... | Check that you have specified the process id properly in motion.conf:
**process\_id\_file /var/run/motion/motion.pid**
Once you have checked that, change the following settings to arbitrarily low values e.g.
**threshold 1**
**noise\_level 1** |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | I have a simple solution but someone needs to explain how this works. Start motion as root. Add a line to /etc/rc.local 'sudo motion' reboot and most events will work if started as root, on\_event\_end sudo ...command or script... | Check that you have specified the process id properly in motion.conf:
**process\_id\_file /var/run/motion/motion.pid**
Once you have checked that, change the following settings to arbitrarily low values e.g.
**threshold 1**
**noise\_level 1** |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | Ypu have to remove ; which stands for commenting the line
; on\_motion\_detected python /home/pi/Desktop/Python/script.py
but
```
on_motion_detected python /home/pi/Desktop/Python/script.py
``` | sudo chown motion:motion /home/pi/Desktop/Python/script.py |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | Ypu have to remove ; which stands for commenting the line
; on\_motion\_detected python /home/pi/Desktop/Python/script.py
but
```
on_motion_detected python /home/pi/Desktop/Python/script.py
``` | if you use threads: threat1.conf, threat2.conf -- try to write script config to them.
My threads:
thread1.conf
```
videodevice /dev/video0
text_left USBWebcam-1
target_dir /samba/hdd/share/motion/usb
rotate 180
width 1024
height 768
#webcam_port 9081
#on_event_start /bin/bash /root/scripts/tg_msg.sh
on_picture_save /... |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | Ypu have to remove ; which stands for commenting the line
; on\_motion\_detected python /home/pi/Desktop/Python/script.py
but
```
on_motion_detected python /home/pi/Desktop/Python/script.py
``` | I have a simple solution but someone needs to explain how this works. Start motion as root. Add a line to /etc/rc.local 'sudo motion' reboot and most events will work if started as root, on\_event\_end sudo ...command or script... |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | if you use threads: threat1.conf, threat2.conf -- try to write script config to them.
My threads:
thread1.conf
```
videodevice /dev/video0
text_left USBWebcam-1
target_dir /samba/hdd/share/motion/usb
rotate 180
width 1024
height 768
#webcam_port 9081
#on_event_start /bin/bash /root/scripts/tg_msg.sh
on_picture_save /... | sudo chown motion:motion /home/pi/Desktop/Python/script.py |
35,469,118 | I have been using my Raspberry Pi 2 to do some motion detection using a USB webcam and the motion package and am incredibly frustrated.
**Can someone explain to me how the on\_motion\_detected method is supposed to work??????**
The idea is that when the camera detects motion, a script is executed. The script just ech... | 2016/02/17 | [
"https://Stackoverflow.com/questions/35469118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4851753/"
] | I have a simple solution but someone needs to explain how this works. Start motion as root. Add a line to /etc/rc.local 'sudo motion' reboot and most events will work if started as root, on\_event\_end sudo ...command or script... | sudo chown motion:motion /home/pi/Desktop/Python/script.py |
63,400,324 | I am relatively new to python and pandas. I am trying to replicate a battleship game. My goal is to locate the row and column that has 1 and storage that location as the Battleship location. I created a CSV file and it looks like this
```
col0,col1,col2,col3,col4,col5
0,0,0,0,0,0
0,0,0,0,0,0
0,0,0,0,0,0
0,1,0,0,0,0
0,... | 2020/08/13 | [
"https://Stackoverflow.com/questions/63400324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11763345/"
] | You really don't need to loop, you can use [`numpy.where`](https://numpy.org/doc/stable/reference/generated/numpy.where.html):
```
import pandas as pd
import numpy as np
df = pd.read_csv('/content/pandas_tutorial/My Drive/pandas/myBattleshipmap.csv',)
r, c = np.where(df.astype(bool))
print(r.tolist())
print(df.colum... | Use `where` to turn all values that are not 1 to `NaN`, then stack will leave you with a MultiIndex Series, whose index gives you the (row\_label, col\_label) tuples of everything that was 1.
```
df.where(df.eq(1)).stack().index
#MultiIndex([(3, 'col1')],
# )
```
---
If you don't want the column names, pe... |
47,145,930 | I read the Susan Fowler's book "production ready microservices" and in two places (until now) I found
* (page 26) "Avoid Versioning Microservices and Endpoints",
* "versioning microservices can easily become an organizational nightmare" (page 27),
* In microservice ecosystems, the versioning of microservices is disco... | 2017/11/06 | [
"https://Stackoverflow.com/questions/47145930",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1526119/"
] | Are you sure that she was not talking about incorporating the version into the **name** of the service or into the **name** of the endpoint?
Service called OrderProcessing\_2\_4\_1 with a versioned endpoint of get\_order\_2\_4\_1 is a very bad idea. OrderProcessing\_2\_4 with a versioned endpoint of get\_order\_2\_4 is... | The author of the book is correct in that it is difficult to update the version of an API, especially if it is popular. This is because you will have to either hunt down all the users of the older version and have them upgrade or you will have to support two versions of your software in production at the same time.
B... |
12,054,772 | I'm new to python (learning for 2 weeks only) and there's something I really can't even try (I have been googling for an hour and coulndn't find any).
`file1` and `file2` are both CSV files.
I've got a function that looks like:
```
def save(file1, file2):
```
it is for `file2` to have the same content as `file1`.... | 2012/08/21 | [
"https://Stackoverflow.com/questions/12054772",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1614184/"
] | Python has a standard module [`shutil`](https://docs.python.org/2/library/shutil.html) which is useful for these sorts of things.
If you need to write the code to do it yourself, simply open two files (the input and the output). Loop over the file object, Reading lines from the input file and write them into the outpu... | If you simply want to copy a file you can do this:
```
def save(file1, file2):
with open(file1, 'rb') as infile:
with open(file2, 'wb') as outfile:
outfile.write(infile.read())
```
this copies the file with name `file1` to the file with name `file2`. It really doesn't matter what the content ... |
38,709,118 | I'm trying to validate a certificate with a CA bundle file. The original Bash command takes two file arguments like this;
```
openssl verify -CAfile ca-ssl.ca cert-ssl.crt
```
I'm trying to figure out how to run the above command in python subprocess whilst having ca-ssl.ca and cert-ssl.crt as variable strings (as o... | 2016/08/01 | [
"https://Stackoverflow.com/questions/38709118",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1165419/"
] | Bash process substitution `<(...)` in the end is supplying a file path as an argument to `openssl`.
You will need to make a helper function to create this functionality since Python doesn't have any operators that allow you to inline pipe data into a file and present its path:
```
import subprocess
def validate_ca(c... | If you want to use process substitution, you will *have* to use `shell=True`. This is unavoidable. The `<(...)` process substitution syntax is bash syntax; you simply must call bash into service to parse and execute such code.
Additionally, you have to ensure that `bash` is invoked, as opposed to `sh`. On some systems... |
62,811,729 | mistakenly first i installed python 3.6 then install pip,then i install python 3.8 after that i checked the pip version its shows me.
```
pip 20.1.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
```
Can i change to
```
pip 20.1.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
``` | 2020/07/09 | [
"https://Stackoverflow.com/questions/62811729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2820094/"
] | I believe you can do that if you simply remove `col2` from your select and group by. Because `col2` will no longer be returned, you should also remove the having statement. I think it should look something like this:
```sql
select
c.col1,
count(1)
from
table_1 a,
table_2 b,
table_3 c
where
a.ke... | use sum() and only group by for the col1
```
select c.col1, sum(a.col2) as total
from table_1 a,table_2 b.table_3 c
where a.key =b.key and b.no = c.no
group by c.col1;
```
**Output---**
```
c.col1 total
aa1 10
aa2 5
``` |
62,811,729 | mistakenly first i installed python 3.6 then install pip,then i install python 3.8 after that i checked the pip version its shows me.
```
pip 20.1.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
```
Can i change to
```
pip 20.1.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
``` | 2020/07/09 | [
"https://Stackoverflow.com/questions/62811729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2820094/"
] | A "simple" option is to use your current query (rewritten to use `JOIN`s, which is nowadays preferred way of *joining* tables) as an inline view:
```
SELECT col1, SUM (cnt)
FROM ( SELECT c.col1, a.col2, COUNT (*) cnt --> your current query begins here
FROM table_1 a
JOIN tab... | I believe you can do that if you simply remove `col2` from your select and group by. Because `col2` will no longer be returned, you should also remove the having statement. I think it should look something like this:
```sql
select
c.col1,
count(1)
from
table_1 a,
table_2 b,
table_3 c
where
a.ke... |
62,811,729 | mistakenly first i installed python 3.6 then install pip,then i install python 3.8 after that i checked the pip version its shows me.
```
pip 20.1.1 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
```
Can i change to
```
pip 20.1.1 from /usr/local/lib/python3.8/dist-packages/pip (python 3.8)
``` | 2020/07/09 | [
"https://Stackoverflow.com/questions/62811729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2820094/"
] | A "simple" option is to use your current query (rewritten to use `JOIN`s, which is nowadays preferred way of *joining* tables) as an inline view:
```
SELECT col1, SUM (cnt)
FROM ( SELECT c.col1, a.col2, COUNT (*) cnt --> your current query begins here
FROM table_1 a
JOIN tab... | use sum() and only group by for the col1
```
select c.col1, sum(a.col2) as total
from table_1 a,table_2 b.table_3 c
where a.key =b.key and b.no = c.no
group by c.col1;
```
**Output---**
```
c.col1 total
aa1 10
aa2 5
``` |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | You should create a python controller which serves JSON formatted data, which any Javascript library (especially jQuery) can consume from. Then, setup the Jinja2 template to contain some Javascript which calls, loads and displays said data. | It has nothing to do with compatibility. Jinja is server side templating. You can use javascript for client side coding.
Using Jinja you can create HTML, which can be accessed by javascript like normal HTML.
To send datastore entities to your client you can use Jinja to pass a Python list or use a json webservice. |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | It works. I had to serialize(convert) my datastore entities to json format, which Javascript understands well. I created a function which converts every instance of my datastore into a dictionnary then encapsulates all these instances into a list which is then converted to Json using json.dumps. When I pass this result... | You should create a python controller which serves JSON formatted data, which any Javascript library (especially jQuery) can consume from. Then, setup the Jinja2 template to contain some Javascript which calls, loads and displays said data. |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | One more approach to consider: If the Python object is not dynamic, you may want to use json.dumps() to store it as a TextProperty, and simply JSON.parse(unescape(model\_text)) on the JS side. Reduces the overhead, and memory hit which can be important when trying to stay within an F1 limit. For example, I run an insta... | It has nothing to do with compatibility. Jinja is server side templating. You can use javascript for client side coding.
Using Jinja you can create HTML, which can be accessed by javascript like normal HTML.
To send datastore entities to your client you can use Jinja to pass a Python list or use a json webservice. |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | Jinja2 and Javascript play fine together. You need to arrange to have template expansion emit your Python data structures into a JS-friendly form.
<https://sites.google.com/a/khanacademy.org/forge/technical/autoescape-in-jinja2-templates> covers it fairly well. (Note the use of the `escapejs` filter.) | It has nothing to do with compatibility. Jinja is server side templating. You can use javascript for client side coding.
Using Jinja you can create HTML, which can be accessed by javascript like normal HTML.
To send datastore entities to your client you can use Jinja to pass a Python list or use a json webservice. |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | It works. I had to serialize(convert) my datastore entities to json format, which Javascript understands well. I created a function which converts every instance of my datastore into a dictionnary then encapsulates all these instances into a list which is then converted to Json using json.dumps. When I pass this result... | It has nothing to do with compatibility. Jinja is server side templating. You can use javascript for client side coding.
Using Jinja you can create HTML, which can be accessed by javascript like normal HTML.
To send datastore entities to your client you can use Jinja to pass a Python list or use a json webservice. |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | It works. I had to serialize(convert) my datastore entities to json format, which Javascript understands well. I created a function which converts every instance of my datastore into a dictionnary then encapsulates all these instances into a list which is then converted to Json using json.dumps. When I pass this result... | One more approach to consider: If the Python object is not dynamic, you may want to use json.dumps() to store it as a TextProperty, and simply JSON.parse(unescape(model\_text)) on the JS side. Reduces the overhead, and memory hit which can be important when trying to stay within an F1 limit. For example, I run an insta... |
19,737,844 | I know that the Jinja2 library allows me to pass datastore models from my python code to html and access this data from inside the html code as shown [in this example](https://developers.google.com/appengine/docs/python/gettingstartedpython27/templates) . However Jinja2 isn't compatible with javascript and I want to ac... | 2013/11/02 | [
"https://Stackoverflow.com/questions/19737844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2559007/"
] | It works. I had to serialize(convert) my datastore entities to json format, which Javascript understands well. I created a function which converts every instance of my datastore into a dictionnary then encapsulates all these instances into a list which is then converted to Json using json.dumps. When I pass this result... | Jinja2 and Javascript play fine together. You need to arrange to have template expansion emit your Python data structures into a JS-friendly form.
<https://sites.google.com/a/khanacademy.org/forge/technical/autoescape-in-jinja2-templates> covers it fairly well. (Note the use of the `escapejs` filter.) |
66,412,526 | I am quite new to python and I have a table of occupancy that looks like this:
```
| room | free| date | place
| room_1 | 0 | 2021-01-13| Boston|
|room_2 |1| 2021-02-14| Boston|
|room_2|0|2021-02-15|Boston|
```
...
How can I calculate how often a room was free within a timeframe of a month and a week for ea... | 2021/02/28 | [
"https://Stackoverflow.com/questions/66412526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10094012/"
] | Hopefully there aren't many holes in the Unity documentation, but when you do find one you can often find sample code in the [Unity Quickstarts](https://github.com/firebase/quickstart-unity) (as these are also used to validate changes to the Unity SDK).
From [`UIHandler.cs`](https://github.com/firebase/quickstart-unit... | <https://firebase.google.com/docs/auth/ios/game-center> This might answer your question. You may have to implement this feature in XCode when you export the project from unity |
66,412,526 | I am quite new to python and I have a table of occupancy that looks like this:
```
| room | free| date | place
| room_1 | 0 | 2021-01-13| Boston|
|room_2 |1| 2021-02-14| Boston|
|room_2|0|2021-02-15|Boston|
```
...
How can I calculate how often a room was free within a timeframe of a month and a week for ea... | 2021/02/28 | [
"https://Stackoverflow.com/questions/66412526",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10094012/"
] | Hopefully there aren't many holes in the Unity documentation, but when you do find one you can often find sample code in the [Unity Quickstarts](https://github.com/firebase/quickstart-unity) (as these are also used to validate changes to the Unity SDK).
From [`UIHandler.cs`](https://github.com/firebase/quickstart-unit... | To complete Patrick's answer I found the machahamster GitHub repo where they use the Game Center Auth with Firebase on Unity.
If it can helps someone:
<https://github.com/google/mechahamster/blob/b5ab9762cc95a2a36156d0cbd1dc08fb767c4080/Assets/Hamster/Scripts/Menus/GameCenterSignIn.cs#L45> |
52,459,081 | Good morning everyone!
I am new to programming and am learning python. I am trying to create a function that converts each individual char in string into each corresponding individuals ints and displays them one after another. The first error it generates is "c is not defined".
```
c=''
def encode(secret_message):
... | 2018/09/22 | [
"https://Stackoverflow.com/questions/52459081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10401403/"
] | It was very difficult to understand your code, but as you asked for logic to improve your understanding, so sharing psuedocode, which you could refer to correct your code accordingly.
```
Node delete (index i, Node n) // pass index and head reference node and return head
if (n==null) // if node is null
return... | after struggling i managed to solve the problem, here is the answer, but i am still not sure about the complexity whether it's O(n) or O(log n).
```
public void delete(int index){
//check if the index is valid
if((index<0)||(index>length())){
System.out.println("Array out of bound!");
... |
52,459,081 | Good morning everyone!
I am new to programming and am learning python. I am trying to create a function that converts each individual char in string into each corresponding individuals ints and displays them one after another. The first error it generates is "c is not defined".
```
c=''
def encode(secret_message):
... | 2018/09/22 | [
"https://Stackoverflow.com/questions/52459081",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10401403/"
] | ### A Java recursive delete method in a linked list
Ok, let's go through this with an example. It's simplistic, but once you get the hang of it and understand the `delete` recursion algorithm, you can easily make the sample classes `generic`, take care of encapsulation, optimize the code and then go on to production.
... | after struggling i managed to solve the problem, here is the answer, but i am still not sure about the complexity whether it's O(n) or O(log n).
```
public void delete(int index){
//check if the index is valid
if((index<0)||(index>length())){
System.out.println("Array out of bound!");
... |
54,021,168 | I am using flask and python3 to upload a video on server. The result is saved in format(filename)+result.jpg , where filename is the videoname
This image result was visible on browser with url /video\_feed before appending result.jpg with string
How can I now access the url to see result.jpg
```
@app.route('/video_... | 2019/01/03 | [
"https://Stackoverflow.com/questions/54021168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9781290/"
] | Using a [list comprehension](https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions):
```
return [x for x in xs if f(x) > 0]
```
Without using a list comprehension:
```
return filter(lambda x: f(x) > 0, xs)
```
Since you said it should return a list:
```
return list(filter(lambda x: f(x) > 0,... | Two solutions are possible using recursion, which do not use looping or comprehensions - which implement the iteration protocol internally.
**Method 1:**
```py
lst = list()
def foo(index):
if index < 0 or index >= len(xs):
return
if f(xs[index]) > 0:
lst.append(xs[index])
# print xs[i... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | You can add this to your script:
```
import sys
sys.stdout = open('logfile', 'w')
```
This will make the print statements write to `logfile`.
If you want the option of printing to `stdout` and a file, you can try this:
```
class Tee(object):
def __init__(self, *files):
self.files = files
def write(... | Here is a program that does what you describe:
```
#! /usr/bin/python3
class Tee:
def write(self, *args, **kwargs):
self.out1.write(*args, **kwargs)
self.out2.write(*args, **kwargs)
def __init__(self, out1, out2):
self.out1 = out1
self.out2 = out2
import sys
sys.stdout = Tee(o... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | You can add this to your script:
```
import sys
sys.stdout = open('logfile', 'w')
```
This will make the print statements write to `logfile`.
If you want the option of printing to `stdout` and a file, you can try this:
```
class Tee(object):
def __init__(self, *files):
self.files = files
def write(... | If you use the built in [logging module](http://docs.python.org/2/library/logging.html) you can configure your loggers with as many outputs as you need: to file, to databases, to emails, etc. However it sounds like you're mixing print for two different uses: logging (recording program flow for later inspection) and pro... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | You can add this to your script:
```
import sys
sys.stdout = open('logfile', 'w')
```
This will make the print statements write to `logfile`.
If you want the option of printing to `stdout` and a file, you can try this:
```
class Tee(object):
def __init__(self, *files):
self.files = files
def write(... | hm... is it hard to implement your own print() function and decorator that will log anything that is passed to your print function?
```
def logger(func):
def inner(*args, **kwargs):
log(*args, **kwargs) # your logging logic
return func(*args, **kwargs)
return inner
@logger
def lprint(string_... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | You can add this to your script:
```
import sys
sys.stdout = open('logfile', 'w')
```
This will make the print statements write to `logfile`.
If you want the option of printing to `stdout` and a file, you can try this:
```
class Tee(object):
def __init__(self, *files):
self.files = files
def write(... | When trying the best answer accepted on python 3.7 I had the following exception:
```
Exception ignored in: <__main__.Logger object at 0x7f04083760f0>
AttributeError: 'Logger' object has no attribute 'flush'
```
I added the following function to make it work:
```
def flush(self):
pass
``` |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | Here is a program that does what you describe:
```
#! /usr/bin/python3
class Tee:
def write(self, *args, **kwargs):
self.out1.write(*args, **kwargs)
self.out2.write(*args, **kwargs)
def __init__(self, out1, out2):
self.out1 = out1
self.out2 = out2
import sys
sys.stdout = Tee(o... | If you use the built in [logging module](http://docs.python.org/2/library/logging.html) you can configure your loggers with as many outputs as you need: to file, to databases, to emails, etc. However it sounds like you're mixing print for two different uses: logging (recording program flow for later inspection) and pro... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | Here is a program that does what you describe:
```
#! /usr/bin/python3
class Tee:
def write(self, *args, **kwargs):
self.out1.write(*args, **kwargs)
self.out2.write(*args, **kwargs)
def __init__(self, out1, out2):
self.out1 = out1
self.out2 = out2
import sys
sys.stdout = Tee(o... | hm... is it hard to implement your own print() function and decorator that will log anything that is passed to your print function?
```
def logger(func):
def inner(*args, **kwargs):
log(*args, **kwargs) # your logging logic
return func(*args, **kwargs)
return inner
@logger
def lprint(string_... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | Here is a program that does what you describe:
```
#! /usr/bin/python3
class Tee:
def write(self, *args, **kwargs):
self.out1.write(*args, **kwargs)
self.out2.write(*args, **kwargs)
def __init__(self, out1, out2):
self.out1 = out1
self.out2 = out2
import sys
sys.stdout = Tee(o... | When trying the best answer accepted on python 3.7 I had the following exception:
```
Exception ignored in: <__main__.Logger object at 0x7f04083760f0>
AttributeError: 'Logger' object has no attribute 'flush'
```
I added the following function to make it work:
```
def flush(self):
pass
``` |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | If you use the built in [logging module](http://docs.python.org/2/library/logging.html) you can configure your loggers with as many outputs as you need: to file, to databases, to emails, etc. However it sounds like you're mixing print for two different uses: logging (recording program flow for later inspection) and pro... | hm... is it hard to implement your own print() function and decorator that will log anything that is passed to your print function?
```
def logger(func):
def inner(*args, **kwargs):
log(*args, **kwargs) # your logging logic
return func(*args, **kwargs)
return inner
@logger
def lprint(string_... |
17,866,724 | I have a long python script that uses print statements often, I was wondering if it was possible to add some code that would log all of the print statements into a text file or something like that. I still want all of the print statements to go to the command line as the user gets prompted throughout the program. If po... | 2013/07/25 | [
"https://Stackoverflow.com/questions/17866724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1464660/"
] | When trying the best answer accepted on python 3.7 I had the following exception:
```
Exception ignored in: <__main__.Logger object at 0x7f04083760f0>
AttributeError: 'Logger' object has no attribute 'flush'
```
I added the following function to make it work:
```
def flush(self):
pass
``` | hm... is it hard to implement your own print() function and decorator that will log anything that is passed to your print function?
```
def logger(func):
def inner(*args, **kwargs):
log(*args, **kwargs) # your logging logic
return func(*args, **kwargs)
return inner
@logger
def lprint(string_... |
54,246,133 | I am an experienced programmer in ruby, python and javascript (specifically back-end node.js), I have worked in java, perl and c++, and I've used lisp and haskell academically, but I'm brand new to Scala and trying to learn some conventions.
I have a function that accepts a function as a parameter, similar to how a so... | 2019/01/18 | [
"https://Stackoverflow.com/questions/54246133",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5158185/"
] | Since Scala has explicit function types, I'd say that if you need to pass a function to your function, use the function type, i.e. your option B. They are explicitly there for this purpose.
It is not exactly clear what do you mean by saying that you "have never seen that before in scala", BTW. A lot of standard librar... | Another option is not to define anything and keep the function type explicit:
```
def apply(x: Int, y: Int => Int): Int = y(x)
```
This makes the code more readable by making it clear which arguments are data objects and which are function objects. (Purists will say that there is no distinction in a functional langu... |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | Send a signal to the group.
So instead of `kill 13231` do:
```
kill -- -13231
```
If you're starting from python then have a look at:
<http://www.pixelbeat.org/libs/subProcess.py>
which shows how to mimic the shell in starting
and killing a group | @Patrick's answer almost did the trick, but it doesn't work if the *parent* process of your *current* shell is in the same group (it kills the parent too).
I found this to be better:
`trap 'pkill -P $$' EXIT`
See [here](https://unix.stackexchange.com/a/124148) for more info. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | Was looking for an elegant solution to this issue and found the following solution elsewhere.
```
trap 'kill -HUP 0' EXIT
```
My own man pages say nothing about what `0` means, but from digging around, it seems to mean the current process group. Since the script get's it's own process group, this ends up sending SIG... | Just add a line like this to your script:
```
trap "kill $$" SIGINT
```
You might need to change 'SIGINT' to 'INT' on your setup, but this will basically kill your process and all child processes when you hit Ctrl-C. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | @Patrick's answer almost did the trick, but it doesn't work if the *parent* process of your *current* shell is in the same group (it kills the parent too).
I found this to be better:
`trap 'pkill -P $$' EXIT`
See [here](https://unix.stackexchange.com/a/124148) for more info. | Just add a line like this to your script:
```
trap "kill $$" SIGINT
```
You might need to change 'SIGINT' to 'INT' on your setup, but this will basically kill your process and all child processes when you hit Ctrl-C. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | I would do something like this:
```
#!/bin/bash
trap : SIGTERM SIGINT
echo $$
find / >/dev/null 2>&1 &
FIND_PID=$!
wait $FIND_PID
if [[ $? -gt 128 ]]
then
kill $FIND_PID
fi
```
Some explanation is in order, I guess. Out the gate, we need to change some of the default signal handling. `:` is a no-op command, ... | Was looking for an elegant solution to this issue and found the following solution elsewhere.
```
trap 'kill -HUP 0' EXIT
```
My own man pages say nothing about what `0` means, but from digging around, it seems to mean the current process group. Since the script get's it's own process group, this ends up sending SIG... |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | Send a signal to the group.
So instead of `kill 13231` do:
```
kill -- -13231
```
If you're starting from python then have a look at:
<http://www.pixelbeat.org/libs/subProcess.py>
which shows how to mimic the shell in starting
and killing a group | Just add a line like this to your script:
```
trap "kill $$" SIGINT
```
You might need to change 'SIGINT' to 'INT' on your setup, but this will basically kill your process and all child processes when you hit Ctrl-C. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | I would do something like this:
```
#!/bin/bash
trap : SIGTERM SIGINT
echo $$
find / >/dev/null 2>&1 &
FIND_PID=$!
wait $FIND_PID
if [[ $? -gt 128 ]]
then
kill $FIND_PID
fi
```
Some explanation is in order, I guess. Out the gate, we need to change some of the default signal handling. `:` is a no-op command, ... | @Patrick's answer almost did the trick, but it doesn't work if the *parent* process of your *current* shell is in the same group (it kills the parent too).
I found this to be better:
`trap 'pkill -P $$' EXIT`
See [here](https://unix.stackexchange.com/a/124148) for more info. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | I would do something like this:
```
#!/bin/bash
trap : SIGTERM SIGINT
echo $$
find / >/dev/null 2>&1 &
FIND_PID=$!
wait $FIND_PID
if [[ $? -gt 128 ]]
then
kill $FIND_PID
fi
```
Some explanation is in order, I guess. Out the gate, we need to change some of the default signal handling. `:` is a no-op command, ... | The thing you would need to do is trap the kill signal, kill the find command and exit. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | Send a signal to the group.
So instead of `kill 13231` do:
```
kill -- -13231
```
If you're starting from python then have a look at:
<http://www.pixelbeat.org/libs/subProcess.py>
which shows how to mimic the shell in starting
and killing a group | The thing you would need to do is trap the kill signal, kill the find command and exit. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | Was looking for an elegant solution to this issue and found the following solution elsewhere.
```
trap 'kill -HUP 0' EXIT
```
My own man pages say nothing about what `0` means, but from digging around, it seems to mean the current process group. Since the script get's it's own process group, this ends up sending SIG... | @Patrick's answer almost did the trick, but it doesn't work if the *parent* process of your *current* shell is in the same group (it kills the parent too).
I found this to be better:
`trap 'pkill -P $$' EXIT`
See [here](https://unix.stackexchange.com/a/124148) for more info. |
1,644,856 | For testing purposes I have this shell script
```
#!/bin/bash
echo $$
find / >/dev/null 2>&1
```
Running this from an interactive terminal, ctrl+c will terminate bash, and the find command.
```
$ ./test-k.sh
13227
<Ctrl+C>
$ ps -ef |grep find
$
```
Running it in the background, and killing the shell only will orp... | 2009/10/29 | [
"https://Stackoverflow.com/questions/1644856",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/126769/"
] | I would do something like this:
```
#!/bin/bash
trap : SIGTERM SIGINT
echo $$
find / >/dev/null 2>&1 &
FIND_PID=$!
wait $FIND_PID
if [[ $? -gt 128 ]]
then
kill $FIND_PID
fi
```
Some explanation is in order, I guess. Out the gate, we need to change some of the default signal handling. `:` is a no-op command, ... | Just add a line like this to your script:
```
trap "kill $$" SIGINT
```
You might need to change 'SIGINT' to 'INT' on your setup, but this will basically kill your process and all child processes when you hit Ctrl-C. |
22,415,345 | I have a unicode string in python code:
```
name = u'Mayte_Martín'
```
I would like to use it with a SPARQL query, which meant that I should encode the string using 'utf-8' and use urllib.quote\_plus or requests.quote on it. However, both these quote functions behave strangely as can be seen when used with and witho... | 2014/03/14 | [
"https://Stackoverflow.com/questions/22415345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/464476/"
] | I'm answering my own question, so that it may help others who face the same issue.
This particular issue arises when you make the following import in the current workspace before executing anything else.
```
from __future__ import unicode_literals
```
This has somehow turned out to be incompatible with the followin... | ```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import urllib
name = u'Mayte_Martín'
print urllib.quote_plus(name.encode('utf-8'), safe=':/')
```
works without problem for me (Py 2.7.9, Debian)
(I don't know the answer, but I cannot make comments with regard to reputation) |
22,415,345 | I have a unicode string in python code:
```
name = u'Mayte_Martín'
```
I would like to use it with a SPARQL query, which meant that I should encode the string using 'utf-8' and use urllib.quote\_plus or requests.quote on it. However, both these quote functions behave strangely as can be seen when used with and witho... | 2014/03/14 | [
"https://Stackoverflow.com/questions/22415345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/464476/"
] | I'm answering my own question, so that it may help others who face the same issue.
This particular issue arises when you make the following import in the current workspace before executing anything else.
```
from __future__ import unicode_literals
```
This has somehow turned out to be incompatible with the followin... | According to [this bug](https://bugs.python.org/issue23885), here is the workaround:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from urllib import quote_plus
name = u'Mayte_Martín'
quote_plus(name.encode('utf-8'), safe=':/'.encode('utf-8'))
```
You must `encode` both ar... |
22,415,345 | I have a unicode string in python code:
```
name = u'Mayte_Martín'
```
I would like to use it with a SPARQL query, which meant that I should encode the string using 'utf-8' and use urllib.quote\_plus or requests.quote on it. However, both these quote functions behave strangely as can be seen when used with and witho... | 2014/03/14 | [
"https://Stackoverflow.com/questions/22415345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/464476/"
] | According to [this bug](https://bugs.python.org/issue23885), here is the workaround:
```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from urllib import quote_plus
name = u'Mayte_Martín'
quote_plus(name.encode('utf-8'), safe=':/'.encode('utf-8'))
```
You must `encode` both ar... | ```
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import urllib
name = u'Mayte_Martín'
print urllib.quote_plus(name.encode('utf-8'), safe=':/')
```
works without problem for me (Py 2.7.9, Debian)
(I don't know the answer, but I cannot make comments with regard to reputation) |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | >
> Unhandled exception type FileNotFoundException myclass.java /myproject/src/mypackage
>
>
>
This is a compiler error. Eclipse is telling you that your program does not compile to java byte code (so of course you can't run it). For now, you can fix it by simply declaring that your program may throw this exceptio... | This is a compiler error. Eclipse is telling you that your program does not compile to java byte code (so of course you can't run it). For now, you can fix it by simply declaring that your program may throw this exception. Like so:
```
public static void main(String[] args) throws IOException{
}
``` |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | >
> Unhandled exception type FileNotFoundException myclass.java /myproject/src/mypackage
>
>
>
This is a compiler error. Eclipse is telling you that your program does not compile to java byte code (so of course you can't run it). For now, you can fix it by simply declaring that your program may throw this exceptio... | you can fix it simply declaring that throw this exception. Like this:
```html
public static void main(String args[]) throws FileNotFoundException{
FileReader reader=new FileReader("db.properties");
Properties p=new Properties();
p.load(reader);
}
``` |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | I see that you tried to specify the full path to your file, but failed because of the following **mistake**:
**you haven't declared or tried to catch** `java.io.FileNotFoundException`.
To fix it, you can replace the line
```
FileReader fr = new FileReader("myscript.abc");
```
with the code:
```
try {
FileRead... | you can fix it simply declaring that throw this exception. Like this:
```html
public static void main(String args[]) throws FileNotFoundException{
FileReader reader=new FileReader("db.properties");
Properties p=new Properties();
p.load(reader);
}
``` |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | I see that you tried to specify the full path to your file, but failed because of the following **mistake**:
**you haven't declared or tried to catch** `java.io.FileNotFoundException`.
To fix it, you can replace the line
```
FileReader fr = new FileReader("myscript.abc");
```
with the code:
```
try {
FileRead... | You are expecting Eclipse to run the program in the project root directory. Unless you did something special with your "Run" configuration, I'd be suprised if it really starts there.
Try printing out your current working directory to make sure this is the right path.
Then try verifying that the bin / build directory ... |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | I see that you tried to specify the full path to your file, but failed because of the following **mistake**:
**you haven't declared or tried to catch** `java.io.FileNotFoundException`.
To fix it, you can replace the line
```
FileReader fr = new FileReader("myscript.abc");
```
with the code:
```
try {
FileRead... | Instead of trying to figure out what's going on, why not *print* what's going on...
Make this change to your code:
```
log(myfile.getName() + "(full path=" + myfile.getAbsolutePath() + ") does not exist");
```
You might find it either isn't using the directory you think, or (depending on your filesystem) it might b... |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | >
> Unhandled exception type FileNotFoundException myclass.java /myproject/src/mypackage
>
>
>
This is a compiler error. Eclipse is telling you that your program does not compile to java byte code (so of course you can't run it). For now, you can fix it by simply declaring that your program may throw this exceptio... | I see that you tried to specify the full path to your file, but failed because of the following **mistake**:
**you haven't declared or tried to catch** `java.io.FileNotFoundException`.
To fix it, you can replace the line
```
FileReader fr = new FileReader("myscript.abc");
```
with the code:
```
try {
FileRead... |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | >
> Unhandled exception type FileNotFoundException myclass.java /myproject/src/mypackage
>
>
>
This is a compiler error. Eclipse is telling you that your program does not compile to java byte code (so of course you can't run it). For now, you can fix it by simply declaring that your program may throw this exceptio... | You are expecting Eclipse to run the program in the project root directory. Unless you did something special with your "Run" configuration, I'd be suprised if it really starts there.
Try printing out your current working directory to make sure this is the right path.
Then try verifying that the bin / build directory ... |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | This is a compiler error. Eclipse is telling you that your program does not compile to java byte code (so of course you can't run it). For now, you can fix it by simply declaring that your program may throw this exception. Like so:
```
public static void main(String[] args) throws IOException{
}
``` | you can fix it simply declaring that throw this exception. Like this:
```html
public static void main(String args[]) throws FileNotFoundException{
FileReader reader=new FileReader("db.properties");
Properties p=new Properties();
p.load(reader);
}
``` |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | Use the file descriptor that you created and verified before creating the file reader. Also, you will probably run into problems using relative paths. Why is the line with the full path commented out? In any case, here is the code:
```
if(file1.exists()) {
log(myfile + " exists. length : " + myfile.length());
... | Instead of trying to figure out what's going on, why not *print* what's going on...
Make this change to your code:
```
log(myfile.getName() + "(full path=" + myfile.getAbsolutePath() + ") does not exist");
```
You might find it either isn't using the directory you think, or (depending on your filesystem) it might b... |
6,488,345 | I have tried both terminate() and kill() but both have failed to stop a subprocess I start in my python code.
Is there any other way?
On Windows with Python 2.7
I have also tried the following with no results...
```
os.kill(p.pid, signal.SIGTERM)
```
and
```
import ctypes
PROCESS_TERMINATE = 1
handle = ctypes.wi... | 2011/06/27 | [
"https://Stackoverflow.com/questions/6488345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/775302/"
] | Use the file descriptor that you created and verified before creating the file reader. Also, you will probably run into problems using relative paths. Why is the line with the full path commented out? In any case, here is the code:
```
if(file1.exists()) {
log(myfile + " exists. length : " + myfile.length());
... | You are expecting Eclipse to run the program in the project root directory. Unless you did something special with your "Run" configuration, I'd be suprised if it really starts there.
Try printing out your current working directory to make sure this is the right path.
Then try verifying that the bin / build directory ... |
16,696,225 | How to instantiated a class if its name is given as a string variable (i.e. dynamically instantiate object of the class). Or alternatively, how does the following PHP 5.3+ code
```
<?php
namespace Foo;
class Bar {};
$classname = 'Foo\Bar';
$bar = new $classname();
```
can be spelled in python?
**Also see**
[Doe... | 2013/05/22 | [
"https://Stackoverflow.com/questions/16696225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/544463/"
] | What I would do is move the call to `get_int` into the condition of the while loop:
```
int main(void)
{
int integers;
printf("Enter some integers. Enter 0 to end.\n");
while ((integers = get_int()) != 0)
{
printf("%d is a number\n", integers);
}
return(0);
} // end main
```
The pro... | You are correct to suspect that you need to retool the `while` loop. Did you try something like this?
```
for (;;)
{
integers = get_int();
if (integers == 0) break;
printf("%d is a number\n", integers);
}
```
Also, your `get_int` would be better written with `fgets` (or `getline` if available) and ... |
16,696,225 | How to instantiated a class if its name is given as a string variable (i.e. dynamically instantiate object of the class). Or alternatively, how does the following PHP 5.3+ code
```
<?php
namespace Foo;
class Bar {};
$classname = 'Foo\Bar';
$bar = new $classname();
```
can be spelled in python?
**Also see**
[Doe... | 2013/05/22 | [
"https://Stackoverflow.com/questions/16696225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/544463/"
] | What I would do is move the call to `get_int` into the condition of the while loop:
```
int main(void)
{
int integers;
printf("Enter some integers. Enter 0 to end.\n");
while ((integers = get_int()) != 0)
{
printf("%d is a number\n", integers);
}
return(0);
} // end main
```
The pro... | Consider the core of your loop:
```
integers = get_int();
printf("%d is a number\n", integers);
```
No matter what `get_int()` returns, the `printf` line will be executed. That line needs a separate `if`:
```
integers = get_int();
if (integers != 0) printf("%d is a number\n", integers);
``` |
16,696,225 | How to instantiated a class if its name is given as a string variable (i.e. dynamically instantiate object of the class). Or alternatively, how does the following PHP 5.3+ code
```
<?php
namespace Foo;
class Bar {};
$classname = 'Foo\Bar';
$bar = new $classname();
```
can be spelled in python?
**Also see**
[Doe... | 2013/05/22 | [
"https://Stackoverflow.com/questions/16696225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/544463/"
] | What I would do is move the call to `get_int` into the condition of the while loop:
```
int main(void)
{
int integers;
printf("Enter some integers. Enter 0 to end.\n");
while ((integers = get_int()) != 0)
{
printf("%d is a number\n", integers);
}
return(0);
} // end main
```
The pro... | The simplest way is to put your condition and assignment into the while-loop. Right now your code relies on `integer` being set in the loop, then loops again to check if it's zero.
```
while((integer = get_int()) != 0)
```
will let you check at the same time as assigning integer. Don't forget the parenthesis, or yo... |
16,696,225 | How to instantiated a class if its name is given as a string variable (i.e. dynamically instantiate object of the class). Or alternatively, how does the following PHP 5.3+ code
```
<?php
namespace Foo;
class Bar {};
$classname = 'Foo\Bar';
$bar = new $classname();
```
can be spelled in python?
**Also see**
[Doe... | 2013/05/22 | [
"https://Stackoverflow.com/questions/16696225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/544463/"
] | You are correct to suspect that you need to retool the `while` loop. Did you try something like this?
```
for (;;)
{
integers = get_int();
if (integers == 0) break;
printf("%d is a number\n", integers);
}
```
Also, your `get_int` would be better written with `fgets` (or `getline` if available) and ... | Consider the core of your loop:
```
integers = get_int();
printf("%d is a number\n", integers);
```
No matter what `get_int()` returns, the `printf` line will be executed. That line needs a separate `if`:
```
integers = get_int();
if (integers != 0) printf("%d is a number\n", integers);
``` |
16,696,225 | How to instantiated a class if its name is given as a string variable (i.e. dynamically instantiate object of the class). Or alternatively, how does the following PHP 5.3+ code
```
<?php
namespace Foo;
class Bar {};
$classname = 'Foo\Bar';
$bar = new $classname();
```
can be spelled in python?
**Also see**
[Doe... | 2013/05/22 | [
"https://Stackoverflow.com/questions/16696225",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/544463/"
] | The simplest way is to put your condition and assignment into the while-loop. Right now your code relies on `integer` being set in the loop, then loops again to check if it's zero.
```
while((integer = get_int()) != 0)
```
will let you check at the same time as assigning integer. Don't forget the parenthesis, or yo... | Consider the core of your loop:
```
integers = get_int();
printf("%d is a number\n", integers);
```
No matter what `get_int()` returns, the `printf` line will be executed. That line needs a separate `if`:
```
integers = get_int();
if (integers != 0) printf("%d is a number\n", integers);
``` |
39,734,278 | Is it possible to receive google drive push notifications if coded on aws lambda via api gateway?
Google drive requires the webhook address to be verified so is it possible to verify api gateway endpoint?
Here are the possible ways of verifying the endpoint:
1) Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | @Atihska, it seems you have setup this API:
```
https://x8f3******.execute-api.us-east-1.amazonaws.com/prod/google-endpointverification
```
From what I understand, Google Drive's HTML tag verification method will try to verify the metadata in the **home page**. As per Google, the home page here is:
```
https://x8f3... | I don't know for sure how the registration process works for verifying the webhook address, but it is certainly possible to configure the webhook itself in API Gateway.
API Gateway supports [custom domain names](http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html "custom domain name... |
39,734,278 | Is it possible to receive google drive push notifications if coded on aws lambda via api gateway?
Google drive requires the webhook address to be verified so is it possible to verify api gateway endpoint?
Here are the possible ways of verifying the endpoint:
1) Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | I don't know for sure how the registration process works for verifying the webhook address, but it is certainly possible to configure the webhook itself in API Gateway.
API Gateway supports [custom domain names](http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html "custom domain name... | @Balaji I was able to figure our API mapping in order to link custom subdomain with the API. But I get 'Missing Authentication token' when I use <https://api.example.com>, in this case lambdanotifications.***.com. I also tried lambdanotifications.***.com/notifications and lambdanotifications.\*\*\*.com/notifications/te... |
39,734,278 | Is it possible to receive google drive push notifications if coded on aws lambda via api gateway?
Google drive requires the webhook address to be verified so is it possible to verify api gateway endpoint?
Here are the possible ways of verifying the endpoint:
1) Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | I got this working finally.
So as mentioned by @Balaji and @Jack Kohn, I have to use custom domains. I followed this tutorial <http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html>
And the last step of mapping body templates is here:
[ Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | I don't know for sure how the registration process works for verifying the webhook address, but it is certainly possible to configure the webhook itself in API Gateway.
API Gateway supports [custom domain names](http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html "custom domain name... | Looks like the question and answer to this are quite old. Providing updated references and typ. solution for this.
<https://cloud.google.com/monitoring/alerts/using-channels-api>
<https://developers.google.com/drive/api/guides/push>
**Initial request to establish the "channel"**. This will have a default life time of... |
39,734,278 | Is it possible to receive google drive push notifications if coded on aws lambda via api gateway?
Google drive requires the webhook address to be verified so is it possible to verify api gateway endpoint?
Here are the possible ways of verifying the endpoint:
1) Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | @Atihska, it seems you have setup this API:
```
https://x8f3******.execute-api.us-east-1.amazonaws.com/prod/google-endpointverification
```
From what I understand, Google Drive's HTML tag verification method will try to verify the metadata in the **home page**. As per Google, the home page here is:
```
https://x8f3... | @Balaji I was able to figure our API mapping in order to link custom subdomain with the API. But I get 'Missing Authentication token' when I use <https://api.example.com>, in this case lambdanotifications.***.com. I also tried lambdanotifications.***.com/notifications and lambdanotifications.\*\*\*.com/notifications/te... |
39,734,278 | Is it possible to receive google drive push notifications if coded on aws lambda via api gateway?
Google drive requires the webhook address to be verified so is it possible to verify api gateway endpoint?
Here are the possible ways of verifying the endpoint:
1) Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | I got this working finally.
So as mentioned by @Balaji and @Jack Kohn, I have to use custom domains. I followed this tutorial <http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html>
And the last step of mapping body templates is here:
[ Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | @Atihska, it seems you have setup this API:
```
https://x8f3******.execute-api.us-east-1.amazonaws.com/prod/google-endpointverification
```
From what I understand, Google Drive's HTML tag verification method will try to verify the metadata in the **home page**. As per Google, the home page here is:
```
https://x8f3... | Looks like the question and answer to this are quite old. Providing updated references and typ. solution for this.
<https://cloud.google.com/monitoring/alerts/using-channels-api>
<https://developers.google.com/drive/api/guides/push>
**Initial request to establish the "channel"**. This will have a default life time of... |
39,734,278 | Is it possible to receive google drive push notifications if coded on aws lambda via api gateway?
Google drive requires the webhook address to be verified so is it possible to verify api gateway endpoint?
Here are the possible ways of verifying the endpoint:
1) Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | I got this working finally.
So as mentioned by @Balaji and @Jack Kohn, I have to use custom domains. I followed this tutorial <http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html>
And the last step of mapping body templates is here:
[ Upload a file and test via /file and the rest are bel... | 2016/09/27 | [
"https://Stackoverflow.com/questions/39734278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2005490/"
] | I got this working finally.
So as mentioned by @Balaji and @Jack Kohn, I have to use custom domains. I followed this tutorial <http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-custom-domains.html>
And the last step of mapping body templates is here:
[:
self.radius = radius
... | 2021/12/17 | [
"https://Stackoverflow.com/questions/70393570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10254216/"
] | A small calculation may help:
```
...
WHERE
([user_id] = 1) AND
([year] * 100 + [week_number]) BETWEEN 202152 AND 202205
```
or
```
...
WHERE
([user_id] = 1) AND
(202152 <= [year] * 100 + [week_number]) AND
([year] * 100 + [week_number] <= 202205)
``` | You could...use variables:
```
DECLARE @myUser int = 1,
@startYear int = 2021,
@endYear int = 2022,
@startWeek int = 5,
@endWeek INT = 13;
SELECT *
FROM [db].[dbo].[table]
WHERE [user_id] = @myUser
AND (
(@startYear = [year] AND @startWeek = [week_number] AND @sta... |
46,032,570 | I have a Django REST backend, and it has a `/users` endpoint where I can add new users through `POST` method from frontend.
`/users` endpoint url:
`http://192.168.201.211:8024/users/`
In this endpoint I can view all users information and add new user, so I must avoid others entry it except Administrator. I create a ... | 2017/09/04 | [
"https://Stackoverflow.com/questions/46032570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2803344/"
] | From the docs:
You have to download and install the ARCore Services.
>
> You must use a supported, physical device. ARCore does not support virtual devices such as the Android Emulator. To prepare your device:
>
>
> Enable developer options
>
> Enable USB debugging
>
> Download the [ARCore Service](https:/... | I think you need to Install Tango core.
<https://play.google.com/store/apps/details?id=com.google.tango&hl=zh_TW> |
9,319,767 | I have a color photo of apple, how can I show only its outline (inside white, background black) with python/PIL? | 2012/02/16 | [
"https://Stackoverflow.com/questions/9319767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1212200/"
] | Something like this should work.
```
from PIL import Image, ImageFilter
image = Image.open('your_image.png')
image = image.filter(ImageFilter.FIND_EDGES)
image.save('new_name.png')
```
If that doesn't give you the result you are looking for then you try implementing either Prewitt edge detection, Sobel edge detect... | If your object and background have fairly well contrast
```
from PIL import Image
image = Image.open(your_image_file)
mask=image.convert("L")
th=150 # the value has to be adjusted for an image of interest
mask = mask.point(lambda i: i < th and 255)
mask.save(file_where_to_save_result)
```
if higher contrast is in o... |
9,319,767 | I have a color photo of apple, how can I show only its outline (inside white, background black) with python/PIL? | 2012/02/16 | [
"https://Stackoverflow.com/questions/9319767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1212200/"
] | Something like this should work.
```
from PIL import Image, ImageFilter
image = Image.open('your_image.png')
image = image.filter(ImageFilter.FIND_EDGES)
image.save('new_name.png')
```
If that doesn't give you the result you are looking for then you try implementing either Prewitt edge detection, Sobel edge detect... | [Apple vs Lines](https://i.stack.imgur.com/sN9qU.jpg)
You can do it just using PIL and Python in less than 200 lines of code. Would be easier to use canny-edge-detection from a library.
Here is the steps. Convert to grayscale for lumens. Using kernel image processing detect edges using Sobel. Thin the edge using the... |
9,319,767 | I have a color photo of apple, how can I show only its outline (inside white, background black) with python/PIL? | 2012/02/16 | [
"https://Stackoverflow.com/questions/9319767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1212200/"
] | If your object and background have fairly well contrast
```
from PIL import Image
image = Image.open(your_image_file)
mask=image.convert("L")
th=150 # the value has to be adjusted for an image of interest
mask = mask.point(lambda i: i < th and 255)
mask.save(file_where_to_save_result)
```
if higher contrast is in o... | [Apple vs Lines](https://i.stack.imgur.com/sN9qU.jpg)
You can do it just using PIL and Python in less than 200 lines of code. Would be easier to use canny-edge-detection from a library.
Here is the steps. Convert to grayscale for lumens. Using kernel image processing detect edges using Sobel. Thin the edge using the... |
51,434,996 | I have the following code:
```
#!/usr/bin/python2.7
import json, re, sys
x = json.loads('''{"status":{"code":"200","msg":"ok","stackTrace":null},"dbTimeCost":11,"totalTimeCost":12,"hasmore":false,"count":5,"result":[{"_type":"Compute","_oid":"555e262fe4b059c7fbd6af72","label":"lvs3b01c-ea7c.stratus.lvs.ebay.com"},{"_t... | 2018/07/20 | [
"https://Stackoverflow.com/questions/51434996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7005590/"
] | just change your code which is used to print the label
```
print x['result'][4]['label'] # here you are just printing the 4th label only
```
to
```
print [i["label"] for i in x['result']]
``` | Using a list comprehension to get all label
**Ex:**
```
import json, re, sys
x = json.loads('''{"status":{"code":"200","msg":"ok","stackTrace":null},"dbTimeCost":11,"totalTimeCost":12,"hasmore":false,"count":5,"result":[{"_type":"Compute","_oid":"555e262fe4b059c7fbd6af72","label":"lvs3b01c-ea7c.stratus.lvs.ebay.com"}... |
51,434,996 | I have the following code:
```
#!/usr/bin/python2.7
import json, re, sys
x = json.loads('''{"status":{"code":"200","msg":"ok","stackTrace":null},"dbTimeCost":11,"totalTimeCost":12,"hasmore":false,"count":5,"result":[{"_type":"Compute","_oid":"555e262fe4b059c7fbd6af72","label":"lvs3b01c-ea7c.stratus.lvs.ebay.com"},{"_t... | 2018/07/20 | [
"https://Stackoverflow.com/questions/51434996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7005590/"
] | just change your code which is used to print the label
```
print x['result'][4]['label'] # here you are just printing the 4th label only
```
to
```
print [i["label"] for i in x['result']]
``` | You need to loop all the result. You result is a list of object which has the label.
```
labels = [ i.get('label') for i in x.get('result')]
print(labels)
```
Use `.get()` it will not return None if the key is not available. |
47,422,284 | How can I elegantly do it in `go`?
In python I could use attribute like this:
```
def function():
function.counter += 1
function.counter = 0
```
Does `go` have the same opportunity? | 2017/11/21 | [
"https://Stackoverflow.com/questions/47422284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5537840/"
] | For example,
`count.go`:
```
package main
import (
"fmt"
"sync"
"time"
)
type Count struct {
mx *sync.Mutex
count int64
}
func NewCount() *Count {
return &Count{mx: new(sync.Mutex), count: 0}
}
func (c *Count) Incr() {
c.mx.Lock()
c.count++
c.mx.Unlock()
}
func (c *Count) C... | ```
var doThingCounter = 0
func DoThing() {
// Do the thing...
doThingCounter++
}
``` |
47,422,284 | How can I elegantly do it in `go`?
In python I could use attribute like this:
```
def function():
function.counter += 1
function.counter = 0
```
Does `go` have the same opportunity? | 2017/11/21 | [
"https://Stackoverflow.com/questions/47422284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5537840/"
] | Let me quote the atomic package documentation:
>
> Package atomic provides low-level atomic memory primitives useful for
> implementing synchronization algorithms.
> <https://golang.org/pkg/sync/atomic/>
>
>
>
Same code, but simpler and safe too.
```
package main
import (
"fmt"
"sync/atomic"
"time... | ```
var doThingCounter = 0
func DoThing() {
// Do the thing...
doThingCounter++
}
``` |
65,398,433 | **Problem description:** I want to create a program that can update one whole row (or cells in this row within given range) in one single line (i.e. one single API request).
This is what've seen in the **documentation**, that was related to my problem:
```py
# Updates A2 and A3 with values 42 and 43
# Note that updat... | 2020/12/21 | [
"https://Stackoverflow.com/questions/65398433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13682294/"
] | The error indicates that the data you are trying to write has more rows than the rows in the range. Each list inside your list represent single row of data in the spreadsheet.
In your example:
```
[['068222bb-c251-47ad-8c2a-e7ad7bad2f60'], ['urlLink'], ['100'], ['250'], ['20'], [''], [' ,'], ['0']]
```
It represent... | Hi you may try the following:
```
def gs_writer(sheet_name,dataframe,sheet_url,boolean,row,col):
import gspread
from gspread_dataframe import get_as_dataframe, set_with_dataframe
import google.oauth2
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.... |
42,214,228 | In numpy and tensorflow it's possible to add matrices (or tensors) of different dimensionality if the shape of smaller matrix is a suffix of bigger matrix. This is an example:
```
x = np.ndarray(shape=(10, 7, 5), dtype = float)
y = np.ndarray(shape=(7, 5), dtype = float)
```
For these two matrices operation `x+y` is... | 2017/02/13 | [
"https://Stackoverflow.com/questions/42214228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/766551/"
] | In NumPy, you could extend `y` to `3D` and then add -
```
x + y[:,None,:]
```
Haven't dealt with `tensorflow` really, but looking into its docs, it seems, we could use [`tf.expand_dims`](https://www.tensorflow.org/api_docs/python/array_ops/shapes_and_shaping#expand_dims) -
```
x + tf.expand_dims(y, 1)
```
The ext... | As correctly pointed out in the accepted answer the solution is to expand dimensions using available construct.
The point is to understand how numpy is doing the broadcasting of matrices in case of adding matrices if their dimensions don't match. The rule is that two matrices must have exactly the same dimensions with... |
16,918,063 | We're running into a problem (which is described <http://wiki.python.org/moin/UnicodeDecodeError>) -- read the second paragraph '...Paradoxically...'.
Specifically, we're trying to up-convert a string to unicode and we are receiving a UnicodeDecodeError.
Example:
```
>>> unicode('\xab')
Traceback (most recent... | 2013/06/04 | [
"https://Stackoverflow.com/questions/16918063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/590028/"
] | I think you're confusing Unicode strings and Unicode encodings (like UTF-8).
`os.walk(".")` returns the filenames (and directory names etc.) as strings that are *encoded* in the current codepage. It will silently *remove* characters that are not present in your current codepage ([see this question for a striking examp... | ```
'\xab'
```
Is a **byte**, number 171.
```
u'\xab'
```
Is a **character**, U+00AB Left-pointing double angle quotation mark («).
`u'\xab'` is a short-hand way of saying `u'\u00ab'`. It's not the same (not even the same datatype) as the byte `'\xab'`; it would probably have been clearer to always use the `\u` s... |
16,918,063 | We're running into a problem (which is described <http://wiki.python.org/moin/UnicodeDecodeError>) -- read the second paragraph '...Paradoxically...'.
Specifically, we're trying to up-convert a string to unicode and we are receiving a UnicodeDecodeError.
Example:
```
>>> unicode('\xab')
Traceback (most recent... | 2013/06/04 | [
"https://Stackoverflow.com/questions/16918063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/590028/"
] | I think you're confusing Unicode strings and Unicode encodings (like UTF-8).
`os.walk(".")` returns the filenames (and directory names etc.) as strings that are *encoded* in the current codepage. It will silently *remove* characters that are not present in your current codepage ([see this question for a striking examp... | As I understand it your issue is that `os.walk(unicode_path)` fails to decode some filenames to Unicode. This problem is fixed in Python 3.1+ (see [PEP 383: Non-decodable Bytes in System Character Interfaces](http://www.python.org/dev/peps/pep-0383/)):
>
> File names, environment variables, and command line arguments... |
16,918,063 | We're running into a problem (which is described <http://wiki.python.org/moin/UnicodeDecodeError>) -- read the second paragraph '...Paradoxically...'.
Specifically, we're trying to up-convert a string to unicode and we are receiving a UnicodeDecodeError.
Example:
```
>>> unicode('\xab')
Traceback (most recent... | 2013/06/04 | [
"https://Stackoverflow.com/questions/16918063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/590028/"
] | ```
for fname in files:
filename = unicode(fname)
```
The second line will complaint if `fname` is not ASCII. If you want to convert the string to Unicode, instead of `unicode(fname)` you should do `fname.decode('<the encoding here>')`.
I would suggest the encoding but you don't tell us what does `\xab` is in yo... | ```
'\xab'
```
Is a **byte**, number 171.
```
u'\xab'
```
Is a **character**, U+00AB Left-pointing double angle quotation mark («).
`u'\xab'` is a short-hand way of saying `u'\u00ab'`. It's not the same (not even the same datatype) as the byte `'\xab'`; it would probably have been clearer to always use the `\u` s... |
16,918,063 | We're running into a problem (which is described <http://wiki.python.org/moin/UnicodeDecodeError>) -- read the second paragraph '...Paradoxically...'.
Specifically, we're trying to up-convert a string to unicode and we are receiving a UnicodeDecodeError.
Example:
```
>>> unicode('\xab')
Traceback (most recent... | 2013/06/04 | [
"https://Stackoverflow.com/questions/16918063",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/590028/"
] | ```
for fname in files:
filename = unicode(fname)
```
The second line will complaint if `fname` is not ASCII. If you want to convert the string to Unicode, instead of `unicode(fname)` you should do `fname.decode('<the encoding here>')`.
I would suggest the encoding but you don't tell us what does `\xab` is in yo... | As I understand it your issue is that `os.walk(unicode_path)` fails to decode some filenames to Unicode. This problem is fixed in Python 3.1+ (see [PEP 383: Non-decodable Bytes in System Character Interfaces](http://www.python.org/dev/peps/pep-0383/)):
>
> File names, environment variables, and command line arguments... |
17,627,193 | I'm on a fresh Virtualbox install of CentOS 6.4.
After installing zsh 5.0.2 from source using `./configure --prefix=/usr && make && make install` and setting it as the shell with `chsh -s /usr/bin/zsh`, everything is good.
Then some time after, after installing python it seems, it starts acting strange.
1. Happens ... | 2013/07/13 | [
"https://Stackoverflow.com/questions/17627193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/340947/"
] | OK , I suggest you try
export TERM=xterm
in your .zshrc configuration
the Changing into Zsh caused the bug. | **sigh** I knew I solved this before.
It's too damn easy to forget things.
The solution is to compile and apply the proper terminfo data with `tic`, as I have a custom config with my terminal clients, `xterm-256color-italic`, that confuses zsh.
There appear to be other ways to configure this stuff too; I basically... |
17,627,193 | I'm on a fresh Virtualbox install of CentOS 6.4.
After installing zsh 5.0.2 from source using `./configure --prefix=/usr && make && make install` and setting it as the shell with `chsh -s /usr/bin/zsh`, everything is good.
Then some time after, after installing python it seems, it starts acting strange.
1. Happens ... | 2013/07/13 | [
"https://Stackoverflow.com/questions/17627193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/340947/"
] | **sigh** I knew I solved this before.
It's too damn easy to forget things.
The solution is to compile and apply the proper terminfo data with `tic`, as I have a custom config with my terminal clients, `xterm-256color-italic`, that confuses zsh.
There appear to be other ways to configure this stuff too; I basically... | I encounter the same problem when I manually install ZSH without root, when the backspace turns to blankspace but still functions as Backspace. Finally, I find it is because "ncurses" is not installed well.
>
> tic: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or... |
17,627,193 | I'm on a fresh Virtualbox install of CentOS 6.4.
After installing zsh 5.0.2 from source using `./configure --prefix=/usr && make && make install` and setting it as the shell with `chsh -s /usr/bin/zsh`, everything is good.
Then some time after, after installing python it seems, it starts acting strange.
1. Happens ... | 2013/07/13 | [
"https://Stackoverflow.com/questions/17627193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/340947/"
] | OK , I suggest you try
export TERM=xterm
in your .zshrc configuration
the Changing into Zsh caused the bug. | I encounter the same problem when I manually install ZSH without root, when the backspace turns to blankspace but still functions as Backspace. Finally, I find it is because "ncurses" is not installed well.
>
> tic: error while loading shared libraries: libncurses.so.6: cannot open shared object file: No such file or... |
58,777,374 | I was recently studying someone's code and a portion of code given below
```
class Node:
def __init__(self, height=0, elem=None):
self.elem = elem
self.next = [None] * height
```
What does it mean by `[None] * height` in the above code
I know what does `*` operator (as multiplication and unpacking) and `Non... | 2019/11/09 | [
"https://Stackoverflow.com/questions/58777374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8401374/"
] | It means a list of `None`s with a `height` number of elements. e.g., for `height = 3`, it is this list:
```
[None, None, None]
``` | ```
>>> [None] * 5
[None, None, None, None, None]
```
Gives you a list of size `height` in your case |
58,777,374 | I was recently studying someone's code and a portion of code given below
```
class Node:
def __init__(self, height=0, elem=None):
self.elem = elem
self.next = [None] * height
```
What does it mean by `[None] * height` in the above code
I know what does `*` operator (as multiplication and unpacking) and `Non... | 2019/11/09 | [
"https://Stackoverflow.com/questions/58777374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8401374/"
] | If you do -
```
[element] * 3
```
You get -
```
[element, element, element]
```
That's what the code does, `[None] * height`
That is, if -
```
height = 4
[None] * height
# equals [None, None, None, None]
``` | ```
>>> [None] * 5
[None, None, None, None, None]
```
Gives you a list of size `height` in your case |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.