问:
In Ubuntu 16.04 Python 3.7 these requirements unable to install for Odoo 13
I am unable to figure out whats going on ?
It throws some error while I am installing these requirements. I am installing this in the virtual environment. I tried this installation with python 3.8 many times and get the same error.
The details are:

requirements.txt file used to install

```<code>Babel==2.6.0
chardet==3.0.4
decorator==4.3.0
docutils==0.14
ebaysdk==2.1.5
feedparser==5.2.1
gevent==1.1.2 ; sys_platform != 'win32' and python_version < '3.7'
gevent==1.3.7 ; sys_platform != 'win32' and python_version >= '3.7'
gevent==1.4.0 ; sys_platform == 'win32'
greenlet==0.4.10 ; python_version < '3.7'
greenlet==0.4.15 ; python_version >= '3.7'
html2text==2018.1.9
Jinja2==2.10.1
libsass==0.17.0
lxml==3.7.1 ; sys_platform != 'win32' and python_version < '3.7'
lxml==4.3.2 ; sys_platform != 'win32' and python_version >= '3.7'
lxml ; sys_platform == 'win32'
Mako==1.0.7
MarkupSafe==1.1.0
mock==2.0.0
num2words==0.5.6
ofxparse==0.19
passlib==1.7.1
Pillow==5.4.1 ; python_version < '3.7' or sys_platform != 'win32'
Pillow==6.1.0 ; sys_platform == 'win32' and python_version >= '3.7'
polib==1.1.0
psutil==5.5.1
psycopg2==2.7.7; sys_platform != 'win32'
psycopg2==2.8.3; sys_platform == 'win32'
pydot==1.4.1
pyldap==2.4.28; sys_platform != 'win32'
pyparsing==2.2.0
PyPDF2==1.26.0
pyserial==3.4
python-dateutil==2.7.3
pytz==2019.1
pyusb==1.0.2
qrcode==6.1
reportlab==3.5.13
requests==2.21.0
zeep==3.2.0
vatnumber==1.2
vobject==0.9.6.1
Werkzeug==0.14.1
XlsxWriter==1.1.2
xlwt==1.3.*
xlrd==1.1.0
pypiwin32 ; sys_platform == 'win32'
</code>```

Installation command:

```<code> pip install -r ./odoo-13.0/requirements.txt

Ignoring gevent: markers 'sys_platform != "win32" and python_version < "3.7"' don't match your environment
Ignoring gevent: markers 'sys_platform == "win32"' don't match your environment
Ignoring greenlet: markers 'python_version < "3.7"' don't match your environment
Ignoring lxml: markers 'sys_platform != "win32" and python_version < "3.7"' don't match your environment
Ignoring lxml: markers 'sys_platform == "win32"' don't match your environment
Ignoring Pillow: markers 'sys_platform == "win32" and python_version >= "3.7"' don't match your environment
Ignoring psycopg2: markers 'sys_platform == "win32"' don't match your environment
Ignoring pypiwin32: markers 'sys_platform == "win32"' don't match your environment
Collecting Babel==2.6.0
  Using cached Babel-2.6.0-py2.py3-none-any.whl (8.1 MB)
Collecting chardet==3.0.4
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting decorator==4.3.0
  Using cached decorator-4.3.0-py2.py3-none-any.whl (9.2 kB)
Collecting docutils==0.14
  Using cached docutils-0.14-py3-none-any.whl (543 kB)
Collecting ebaysdk==2.1.5
  Using cached ebaysdk-2.1.5.tar.gz (42 kB)
Collecting feedparser==5.2.1
  Using cached feedparser-5.2.1.tar.bz2 (192 kB)
Collecting gevent==1.3.7
  Downloading gevent-1.3.7-cp37-cp37m-manylinux1_x86_64.whl (4.5 MB)
     |████████████████████████████████| 4.5 MB 334 kB/s
Collecting greenlet==0.4.15
  Downloading greenlet-0.4.15-cp37-cp37m-manylinux1_x86_64.whl (42 kB)
     |████████████████████████████████| 42 kB 78 kB/s
Collecting html2text==2018.1.9
  Using cached html2text-2018.1.9-py3-none-any.whl (21 kB)
Collecting Jinja2==2.10.1
  Using cached Jinja2-2.10.1-py2.py3-none-any.whl (124 kB)
Collecting libsass==0.17.0
  Downloading libsass-0.17.0-cp37-cp37m-manylinux1_x86_64.whl (9.2 MB)
     |████████████████████████████████| 9.2 MB 36 kB/s
Collecting lxml==4.3.2
  Downloading lxml-4.3.2-cp37-cp37m-manylinux1_x86_64.whl (5.7 MB)
     |████████████████████████████████| 5.7 MB 646 kB/s
Collecting Mako==1.0.7
  Using cached Mako-1.0.7.tar.gz (564 kB)
Collecting MarkupSafe==1.1.0
  Downloading MarkupSafe-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (27 kB)
Collecting mock==2.0.0
  Using cached mock-2.0.0-py2.py3-none-any.whl (56 kB)
Collecting num2words==0.5.6
  Using cached num2words-0.5.6-py2.py3-none-any.whl (64 kB)
Collecting ofxparse==0.19
  Using cached ofxparse-0.19.tar.gz (54 kB)
Collecting passlib==1.7.1
  Using cached passlib-1.7.1-py2.py3-none-any.whl (498 kB)
Collecting Pillow==5.4.1
  Downloading Pillow-5.4.1-cp37-cp37m-manylinux1_x86_64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 636 kB/s
Collecting polib==1.1.0
  Using cached polib-1.1.0-py2.py3-none-any.whl (25 kB)
Collecting psutil==5.5.1
  Using cached psutil-5.5.1.tar.gz (426 kB)
Collecting psycopg2==2.7.7
  Downloading psycopg2-2.7.7-cp37-cp37m-manylinux1_x86_64.whl (2.7 MB)
     |████████████████████████████████| 2.7 MB 848 kB/s
Collecting pydot==1.4.1
  Using cached pydot-1.4.1-py2.py3-none-any.whl (19 kB)
Collecting pyldap==2.4.28
  Using cached pyldap-2.4.28.tar.gz (130 kB)
Collecting pyparsing==2.2.0
  Using cached pyparsing-2.2.0-py2.py3-none-any.whl (56 kB)
Collecting PyPDF2==1.26.0
  Using cached PyPDF2-1.26.0.tar.gz (77 kB)
Collecting pyserial==3.4
  Using cached pyserial-3.4-py2.py3-none-any.whl (193 kB)
Collecting python-dateutil==2.7.3
  Using cached python_dateutil-2.7.3-py2.py3-none-any.whl (211 kB)
Collecting pytz==2019.1
  Using cached pytz-2019.1-py2.py3-none-any.whl (510 kB)
Collecting pyusb==1.0.2
  Using cached pyusb-1.0.2.tar.gz (54 kB)
Collecting qrcode==6.1
  Using cached qrcode-6.1-py2.py3-none-any.whl (31 kB)
Collecting reportlab==3.5.13
  Downloading reportlab-3.5.13-cp37-cp37m-manylinux1_x86_64.whl (2.6 MB)
     |████████████████████████████████| 2.6 MB 363 kB/s
Collecting requests==2.21.0
  Using cached requests-2.21.0-py2.py3-none-any.whl (57 kB)
Collecting zeep==3.2.0
  Using cached zeep-3.2.0-py2.py3-none-any.whl (98 kB)
Collecting vatnumber==1.2
  Using cached vatnumber-1.2.tar.gz (19 kB)
Collecting vobject==0.9.6.1
  Using cached vobject-0.9.6.1.tar.gz (58 kB)
Collecting Werkzeug==0.14.1
  Using cached Werkzeug-0.14.1-py2.py3-none-any.whl (322 kB)
Collecting XlsxWriter==1.1.2
  Using cached XlsxWriter-1.1.2-py2.py3-none-any.whl (142 kB)
Collecting xlwt==1.3.*
  Using cached xlwt-1.3.0-py2.py3-none-any.whl (99 kB)
Collecting xlrd==1.1.0
  Using cached xlrd-1.1.0-py2.py3-none-any.whl (108 kB)
Collecting six
  Using cached six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting pbr>=0.11
  Using cached pbr-5.4.4-py2.py3-none-any.whl (110 kB)
Collecting beautifulsoup4
  Using cached beautifulsoup4-4.8.2-py3-none-any.whl (106 kB)
Requirement already satisfied: setuptools in ./venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg (from pyldap==2.4.28->-r ./odoo-13.0/requirements.txt (line 31)) (40.8.0)
Collecting certifi>=2017.4.17
  Using cached certifi-2019.11.28-py2.py3-none-any.whl (156 kB)
Collecting idna<2.9,>=2.5
  Using cached idna-2.8-py2.py3-none-any.whl (58 kB)
Collecting urllib3<1.25,>=1.21.1
  Using cached urllib3-1.24.3-py2.py3-none-any.whl (118 kB)
Collecting attrs>=17.2.0
  Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting isodate>=0.5.4
  Using cached isodate-0.6.0-py2.py3-none-any.whl (45 kB)
Collecting defusedxml>=0.4.1
  Using cached defusedxml-0.6.0-py2.py3-none-any.whl (23 kB)
Collecting appdirs>=1.4.0
  Using cached appdirs-1.4.3-py2.py3-none-any.whl (12 kB)
Collecting requests-toolbelt>=0.7.1
  Using cached requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
Collecting cached-property>=1.3.0
  Using cached cached_property-1.5.1-py2.py3-none-any.whl (6.0 kB)
Collecting python-stdnum
  Using cached python_stdnum-1.13-py2.py3-none-any.whl (839 kB)
Collecting soupsieve>=1.2
  Using cached soupsieve-1.9.5-py2.py3-none-any.whl (33 kB)
Installing collected packages: pytz, Babel, chardet, decorator, docutils, lxml, certifi, idna, urllib3, requests, ebaysdk, feedparser, greenlet, gevent, html2text, MarkupSafe, Jinja2, six, libsass, Mako, pbr, mock, num2words, soupsieve, beautifulsoup4, ofxparse, passlib, Pillow, polib, psutil, psycopg2, pyparsing, pydot, pyldap, PyPDF2, pyserial, python-dateutil, pyusb, qrcode, reportlab, attrs, isodate, defusedxml, appdirs, requests-toolbelt, cached-property, zeep, python-stdnum, vatnumber, vobject, Werkzeug, XlsxWriter, xlwt, xlrd
    Running setup.py install for ebaysdk ... done
    Running setup.py install for feedparser ... done
    Running setup.py install for Mako ... done
    Running setup.py install for ofxparse ... done
    Running setup.py install for psutil ... error
    ERROR: Command errored out with exit status 1:
     command: /home/dev/odoo13_home/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-1e926ya6/install-record.txt --single-version-externally-managed --compile --install-headers /home/dev/odoo13_home/venv/include/site/python3.7/psutil
         cwd: /tmp/pip-install-1upsixt0/psutil/
    Complete output (41 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psosx.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_pslinux.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psbsd.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psaix.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psposix.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_pssunos.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_common.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_compat.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/__init__.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_pswindows.py -> build/lib.linux-x86_64-3.7/psutil
    creating build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_connections.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_contracts.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_system.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_aix.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/__init__.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_unicode.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/__main__.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_memory_leaks.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_process.py -> build/lib.linux-x86_64-3.7/psutil/tests
    running build_ext
    building 'psutil._psutil_linux' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/psutil
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=551 -DPSUTIL_LINUX=1 -I/home/dev/odoo13_home/venv/include -I/usr/include/python3.7m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.7/psutil/_psutil_common.o
    psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/dev/odoo13_home/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-1e926ya6/install-record.txt --single-version-externally-managed --compile --install-headers /home/dev/odoo13_home/venv/include/site/python3.7/psutil Check the logs for full command output.
</code>```

答:
```<code>fatal error: Python.h: No such file or directory
</code>```

This error means that there is no Python development package installed in your system, which is required to compile those Python packages. For default Python3 package you can install development package using following command:

```<code>sudo apt-get install python3-dev
</code>```

This command will install Python3 development package from Ubuntu default repo, which contains Python version 3.5. You can check with following command:

```<code>apt-cache madison python3-dev
</code>```

If you want to install for other versions, you can use deadsnakes repo

```<code>sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.7-dev
</code>```

Body:
I am unable to figure out whats going on ?
It throws some error while I am installing these requirements. I am installing this in the virtual environment. I tried this installation with python 3.8 many times and get the same error.
The details are:

requirements.txt file used to install

Babel==2.6.0
chardet==3.0.4
decorator==4.3.0
docutils==0.14
ebaysdk==2.1.5
feedparser==5.2.1
gevent==1.1.2 ; sys_platform != 'win32' and python_version < '3.7'
gevent==1.3.7 ; sys_platform != 'win32' and python_version >= '3.7'
gevent==1.4.0 ; sys_platform == 'win32'
greenlet==0.4.10 ; python_version < '3.7'
greenlet==0.4.15 ; python_version >= '3.7'
html2text==2018.1.9
Jinja2==2.10.1
libsass==0.17.0
lxml==3.7.1 ; sys_platform != 'win32' and python_version < '3.7'
lxml==4.3.2 ; sys_platform != 'win32' and python_version >= '3.7'
lxml ; sys_platform == 'win32'
Mako==1.0.7
MarkupSafe==1.1.0
mock==2.0.0
num2words==0.5.6
ofxparse==0.19
passlib==1.7.1
Pillow==5.4.1 ; python_version < '3.7' or sys_platform != 'win32'
Pillow==6.1.0 ; sys_platform == 'win32' and python_version >= '3.7'
polib==1.1.0
psutil==5.5.1
psycopg2==2.7.7; sys_platform != 'win32'
psycopg2==2.8.3; sys_platform == 'win32'
pydot==1.4.1
pyldap==2.4.28; sys_platform != 'win32'
pyparsing==2.2.0
PyPDF2==1.26.0
pyserial==3.4
python-dateutil==2.7.3
pytz==2019.1
pyusb==1.0.2
qrcode==6.1
reportlab==3.5.13
requests==2.21.0
zeep==3.2.0
vatnumber==1.2
vobject==0.9.6.1
Werkzeug==0.14.1
XlsxWriter==1.1.2
xlwt==1.3.*
xlrd==1.1.0
pypiwin32 ; sys_platform == 'win32'

Installation command:

 pip install -r ./odoo-13.0/requirements.txt

Ignoring gevent: markers 'sys_platform != "win32" and python_version < "3.7"' don't match your environment
Ignoring gevent: markers 'sys_platform == "win32"' don't match your environment
Ignoring greenlet: markers 'python_version < "3.7"' don't match your environment
Ignoring lxml: markers 'sys_platform != "win32" and python_version < "3.7"' don't match your environment
Ignoring lxml: markers 'sys_platform == "win32"' don't match your environment
Ignoring Pillow: markers 'sys_platform == "win32" and python_version >= "3.7"' don't match your environment
Ignoring psycopg2: markers 'sys_platform == "win32"' don't match your environment
Ignoring pypiwin32: markers 'sys_platform == "win32"' don't match your environment
Collecting Babel==2.6.0
  Using cached Babel-2.6.0-py2.py3-none-any.whl (8.1 MB)
Collecting chardet==3.0.4
  Using cached chardet-3.0.4-py2.py3-none-any.whl (133 kB)
Collecting decorator==4.3.0
  Using cached decorator-4.3.0-py2.py3-none-any.whl (9.2 kB)
Collecting docutils==0.14
  Using cached docutils-0.14-py3-none-any.whl (543 kB)
Collecting ebaysdk==2.1.5
  Using cached ebaysdk-2.1.5.tar.gz (42 kB)
Collecting feedparser==5.2.1
  Using cached feedparser-5.2.1.tar.bz2 (192 kB)
Collecting gevent==1.3.7
  Downloading gevent-1.3.7-cp37-cp37m-manylinux1_x86_64.whl (4.5 MB)
     |████████████████████████████████| 4.5 MB 334 kB/s
Collecting greenlet==0.4.15
  Downloading greenlet-0.4.15-cp37-cp37m-manylinux1_x86_64.whl (42 kB)
     |████████████████████████████████| 42 kB 78 kB/s
Collecting html2text==2018.1.9
  Using cached html2text-2018.1.9-py3-none-any.whl (21 kB)
Collecting Jinja2==2.10.1
  Using cached Jinja2-2.10.1-py2.py3-none-any.whl (124 kB)
Collecting libsass==0.17.0
  Downloading libsass-0.17.0-cp37-cp37m-manylinux1_x86_64.whl (9.2 MB)
     |████████████████████████████████| 9.2 MB 36 kB/s
Collecting lxml==4.3.2
  Downloading lxml-4.3.2-cp37-cp37m-manylinux1_x86_64.whl (5.7 MB)
     |████████████████████████████████| 5.7 MB 646 kB/s
Collecting Mako==1.0.7
  Using cached Mako-1.0.7.tar.gz (564 kB)
Collecting MarkupSafe==1.1.0
  Downloading MarkupSafe-1.1.0-cp37-cp37m-manylinux1_x86_64.whl (27 kB)
Collecting mock==2.0.0
  Using cached mock-2.0.0-py2.py3-none-any.whl (56 kB)
Collecting num2words==0.5.6
  Using cached num2words-0.5.6-py2.py3-none-any.whl (64 kB)
Collecting ofxparse==0.19
  Using cached ofxparse-0.19.tar.gz (54 kB)
Collecting passlib==1.7.1
  Using cached passlib-1.7.1-py2.py3-none-any.whl (498 kB)
Collecting Pillow==5.4.1
  Downloading Pillow-5.4.1-cp37-cp37m-manylinux1_x86_64.whl (2.0 MB)
     |████████████████████████████████| 2.0 MB 636 kB/s
Collecting polib==1.1.0
  Using cached polib-1.1.0-py2.py3-none-any.whl (25 kB)
Collecting psutil==5.5.1
  Using cached psutil-5.5.1.tar.gz (426 kB)
Collecting psycopg2==2.7.7
  Downloading psycopg2-2.7.7-cp37-cp37m-manylinux1_x86_64.whl (2.7 MB)
     |████████████████████████████████| 2.7 MB 848 kB/s
Collecting pydot==1.4.1
  Using cached pydot-1.4.1-py2.py3-none-any.whl (19 kB)
Collecting pyldap==2.4.28
  Using cached pyldap-2.4.28.tar.gz (130 kB)
Collecting pyparsing==2.2.0
  Using cached pyparsing-2.2.0-py2.py3-none-any.whl (56 kB)
Collecting PyPDF2==1.26.0
  Using cached PyPDF2-1.26.0.tar.gz (77 kB)
Collecting pyserial==3.4
  Using cached pyserial-3.4-py2.py3-none-any.whl (193 kB)
Collecting python-dateutil==2.7.3
  Using cached python_dateutil-2.7.3-py2.py3-none-any.whl (211 kB)
Collecting pytz==2019.1
  Using cached pytz-2019.1-py2.py3-none-any.whl (510 kB)
Collecting pyusb==1.0.2
  Using cached pyusb-1.0.2.tar.gz (54 kB)
Collecting qrcode==6.1
  Using cached qrcode-6.1-py2.py3-none-any.whl (31 kB)
Collecting reportlab==3.5.13
  Downloading reportlab-3.5.13-cp37-cp37m-manylinux1_x86_64.whl (2.6 MB)
     |████████████████████████████████| 2.6 MB 363 kB/s
Collecting requests==2.21.0
  Using cached requests-2.21.0-py2.py3-none-any.whl (57 kB)
Collecting zeep==3.2.0
  Using cached zeep-3.2.0-py2.py3-none-any.whl (98 kB)
Collecting vatnumber==1.2
  Using cached vatnumber-1.2.tar.gz (19 kB)
Collecting vobject==0.9.6.1
  Using cached vobject-0.9.6.1.tar.gz (58 kB)
Collecting Werkzeug==0.14.1
  Using cached Werkzeug-0.14.1-py2.py3-none-any.whl (322 kB)
Collecting XlsxWriter==1.1.2
  Using cached XlsxWriter-1.1.2-py2.py3-none-any.whl (142 kB)
Collecting xlwt==1.3.*
  Using cached xlwt-1.3.0-py2.py3-none-any.whl (99 kB)
Collecting xlrd==1.1.0
  Using cached xlrd-1.1.0-py2.py3-none-any.whl (108 kB)
Collecting six
  Using cached six-1.14.0-py2.py3-none-any.whl (10 kB)
Collecting pbr>=0.11
  Using cached pbr-5.4.4-py2.py3-none-any.whl (110 kB)
Collecting beautifulsoup4
  Using cached beautifulsoup4-4.8.2-py3-none-any.whl (106 kB)
Requirement already satisfied: setuptools in ./venv/lib/python3.7/site-packages/setuptools-40.8.0-py3.7.egg (from pyldap==2.4.28->-r ./odoo-13.0/requirements.txt (line 31)) (40.8.0)
Collecting certifi>=2017.4.17
  Using cached certifi-2019.11.28-py2.py3-none-any.whl (156 kB)
Collecting idna<2.9,>=2.5
  Using cached idna-2.8-py2.py3-none-any.whl (58 kB)
Collecting urllib3<1.25,>=1.21.1
  Using cached urllib3-1.24.3-py2.py3-none-any.whl (118 kB)
Collecting attrs>=17.2.0
  Using cached attrs-19.3.0-py2.py3-none-any.whl (39 kB)
Collecting isodate>=0.5.4
  Using cached isodate-0.6.0-py2.py3-none-any.whl (45 kB)
Collecting defusedxml>=0.4.1
  Using cached defusedxml-0.6.0-py2.py3-none-any.whl (23 kB)
Collecting appdirs>=1.4.0
  Using cached appdirs-1.4.3-py2.py3-none-any.whl (12 kB)
Collecting requests-toolbelt>=0.7.1
  Using cached requests_toolbelt-0.9.1-py2.py3-none-any.whl (54 kB)
Collecting cached-property>=1.3.0
  Using cached cached_property-1.5.1-py2.py3-none-any.whl (6.0 kB)
Collecting python-stdnum
  Using cached python_stdnum-1.13-py2.py3-none-any.whl (839 kB)
Collecting soupsieve>=1.2
  Using cached soupsieve-1.9.5-py2.py3-none-any.whl (33 kB)
Installing collected packages: pytz, Babel, chardet, decorator, docutils, lxml, certifi, idna, urllib3, requests, ebaysdk, feedparser, greenlet, gevent, html2text, MarkupSafe, Jinja2, six, libsass, Mako, pbr, mock, num2words, soupsieve, beautifulsoup4, ofxparse, passlib, Pillow, polib, psutil, psycopg2, pyparsing, pydot, pyldap, PyPDF2, pyserial, python-dateutil, pyusb, qrcode, reportlab, attrs, isodate, defusedxml, appdirs, requests-toolbelt, cached-property, zeep, python-stdnum, vatnumber, vobject, Werkzeug, XlsxWriter, xlwt, xlrd
    Running setup.py install for ebaysdk ... done
    Running setup.py install for feedparser ... done
    Running setup.py install for Mako ... done
    Running setup.py install for ofxparse ... done
    Running setup.py install for psutil ... error
    ERROR: Command errored out with exit status 1:
     command: /home/dev/odoo13_home/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-1e926ya6/install-record.txt --single-version-externally-managed --compile --install-headers /home/dev/odoo13_home/venv/include/site/python3.7/psutil
         cwd: /tmp/pip-install-1upsixt0/psutil/
    Complete output (41 lines):
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.7
    creating build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psosx.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_pslinux.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psbsd.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psaix.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_psposix.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_pssunos.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_common.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_compat.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/__init__.py -> build/lib.linux-x86_64-3.7/psutil
    copying psutil/_pswindows.py -> build/lib.linux-x86_64-3.7/psutil
    creating build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_connections.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_contracts.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_system.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_osx.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_bsd.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_aix.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/__init__.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_linux.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_windows.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_misc.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_unicode.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_posix.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_sunos.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/__main__.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_memory_leaks.py -> build/lib.linux-x86_64-3.7/psutil/tests
    copying psutil/tests/test_process.py -> build/lib.linux-x86_64-3.7/psutil/tests
    running build_ext
    building 'psutil._psutil_linux' extension
    creating build/temp.linux-x86_64-3.7
    creating build/temp.linux-x86_64-3.7/psutil
    x86_64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DPSUTIL_POSIX=1 -DPSUTIL_VERSION=551 -DPSUTIL_LINUX=1 -I/home/dev/odoo13_home/venv/include -I/usr/include/python3.7m -c psutil/_psutil_common.c -o build/temp.linux-x86_64-3.7/psutil/_psutil_common.o
    psutil/_psutil_common.c:9:20: fatal error: Python.h: No such file or directory
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /home/dev/odoo13_home/venv/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"'; __file__='"'"'/tmp/pip-install-1upsixt0/psutil/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /tmp/pip-record-1e926ya6/install-record.txt --single-version-externally-managed --compile --install-headers /home/dev/odoo13_home/venv/include/site/python3.7/psutil Check the logs for full command output.

Body:
fatal error: Python.h: No such file or directory

This error means that there is no Python development package installed in your system, which is required to compile those Python packages. For default Python3 package you can install development package using following command:

sudo apt-get install python3-dev

This command will install Python3 development package from Ubuntu default repo, which contains Python version 3.5. You can check with following command:

apt-cache madison python3-dev

If you want to install for other versions, you can use deadsnakes repo

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.7-dev


来源: stackexchange

问:
Using the unite function in R and removing duplicated values
I'm trying to use the unite function in R to concatenate values across columns, but also deduplicate the values. How can I accomplish this?

Here is the input data:

```<code>input <- tibble(
  id = c('aa', 'ss', 'dd', 'qq'),
  '2017' = c('tv', NA, NA, 'web'),
  '2018' = c('tv', 'web', NA, NA),
  '2019' = c(NA, 'web', 'book', 'tv')
)

# A tibble: 4 x 4
  id    `2017` `2018` `2019`
  <chr> <chr>  <chr>  <chr>
1 aa    tv     tv     NA
2 ss    NA     web    web
3 dd    NA     NA     book
4 qq    web    NA     tv
</code>```

The desired output with the ALL column is:

```<code>> output
# A tibble: 4 x 5
  id    `2017` `2018` `2019` ALL
  <chr> <chr>  <chr>  <chr>  <chr>
1 aa    tv     tv     NA     tv
2 ss    NA     web    web    web
3 dd    NA     NA     book   book
4 qq    web    NA     tv     web, tv
</code>```

答:
I am not sure if deduplicating is possible with unite, however you can use apply row-wise.

```<code>input$ALL <- apply(input[-1], 1, function(x) toString(na.omit(unique(x))))
</code>```

Or a tidyverse way could be using pmap

```<code>library(tidyverse)

input %>%
  mutate(ALL = pmap_chr(select(., -id), ~toString(unique(na.omit(c(...))))))

#  id    `2017` `2018` `2019` ALL
#  <chr> <chr>  <chr>  <chr>  <chr>
#1 aa    tv     tv     NA     tv
#2 ss    NA     web    web    web
#3 dd    NA     NA     book   book
#4 qq    web    NA     tv     web, tv
</code>```

Or getting the data in long format and then joining

```<code>input %>%
  pivot_longer(cols = -id, values_drop_na = TRUE) %>%
  group_by(id) %>%
  summarise(ALL = toString(unique(value))) %>%
  left_join(input)
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I'm trying to use the unite function in R to concatenate values across columns, but also deduplicate the values. How can I accomplish this?

Here is the input data:

input <- tibble(
  id = c('aa', 'ss', 'dd', 'qq'),
  '2017' = c('tv', NA, NA, 'web'),
  '2018' = c('tv', 'web', NA, NA),
  '2019' = c(NA, 'web', 'book', 'tv')
)

# A tibble: 4 x 4
  id    `2017` `2018` `2019`
  <chr> <chr>  <chr>  <chr>
1 aa    tv     tv     NA
2 ss    NA     web    web
3 dd    NA     NA     book
4 qq    web    NA     tv

The desired output with the ALL column is:

> output
# A tibble: 4 x 5
  id    `2017` `2018` `2019` ALL
  <chr> <chr>  <chr>  <chr>  <chr>
1 aa    tv     tv     NA     tv
2 ss    NA     web    web    web
3 dd    NA     NA     book   book
4 qq    web    NA     tv     web, tv

Body:
I am not sure if deduplicating is possible with unite, however you can use apply row-wise.

input$ALL <- apply(input[-1], 1, function(x) toString(na.omit(unique(x))))

Or a tidyverse way could be using pmap

library(tidyverse)

input %>%
  mutate(ALL = pmap_chr(select(., -id), ~toString(unique(na.omit(c(...))))))

#  id    `2017` `2018` `2019` ALL
#  <chr> <chr>  <chr>  <chr>  <chr>
#1 aa    tv     tv     NA     tv
#2 ss    NA     web    web    web
#3 dd    NA     NA     book   book
#4 qq    web    NA     tv     web, tv

Or getting the data in long format and then joining

input %>%
  pivot_longer(cols = -id, values_drop_na = TRUE) %>%
  group_by(id) %>%
  summarise(ALL = toString(unique(value))) %>%
  left_join(input)


问:
Switch, case, try and catch in C# probelm
I am very new to C# programming. I wanted to catch the errors for example invalid input (not a number from 1-6) and print out a message stating the error. This is my code.

```<code>private static bool ManageStudents()
    {
        Console.Clear();
        Console.WriteLine("========================");
        Console.WriteLine(" Choose an option:");
        Console.WriteLine("  1. Add a new student");
        Console.WriteLine("  2. View all students");
        Console.WriteLine("  3. Search students");
        Console.WriteLine("  4. Delete students");
        Console.WriteLine("  5. Update students");
        Console.WriteLine("  6. Back to main menu");
        Console.WriteLine("========================");
        Console.Write("\r\nPlease choose: ");

        try
        {
            switch (Console.ReadLine())
            {
                case "1":
                    AddStudents();
                    return true;
                case "2":
                    ViewStudents();
                    return true;
                case "3":
                    SearchStudents();
                    return true;
                case "4":
                    DeleteStudents();
                    return true;
                case "5":
                    UpdateStudents();
                    return true;
                case "6":
                    return false;
                default:
                    return true;
            }
        }

        catch (Exception e)
        {
            Console.WriteLine("error message");
            Console.ReadLine();
            return true;
        }

    }
</code>```

When I run the program the message "error message" didn't appear after I enter an invalid character.

答:
You have pretty clear logic: If given number not in the valid numbers list - print error message.

So, don't use exception as part of the logic, exceptions are for the exceptions, for not expected cases. In addition throwing exception will be slightly more expensive than handle it with switch case.

DA0007: Avoid using exceptions for control flow

```<code>private static bool ManageStudents()
{
    switch (Console.ReadLine())
    {
        case "1":
            AddStudents();
            return true;
        case "2":
            ViewStudents();
            return true;
        case "3":
            SearchStudents();
            return true;
        case "4":
            DeleteStudents();
            return true;
        case "5":
            UpdateStudents();
            return true;
        case "6":
            return false;
        default:
            Console.WriteLine("Invalid selection");
            return true;
    }
}
</code>```

Now you can remove all try .. catch blocks.

Body:
I am very new to C# programming. I wanted to catch the errors for example invalid input (not a number from 1-6) and print out a message stating the error. This is my code.

private static bool ManageStudents()
    {
        Console.Clear();
        Console.WriteLine("========================");
        Console.WriteLine(" Choose an option:");
        Console.WriteLine("  1. Add a new student");
        Console.WriteLine("  2. View all students");
        Console.WriteLine("  3. Search students");
        Console.WriteLine("  4. Delete students");
        Console.WriteLine("  5. Update students");
        Console.WriteLine("  6. Back to main menu");
        Console.WriteLine("========================");
        Console.Write("\r\nPlease choose: ");

        try
        {
            switch (Console.ReadLine())
            {
                case "1":
                    AddStudents();
                    return true;
                case "2":
                    ViewStudents();
                    return true;
                case "3":
                    SearchStudents();
                    return true;
                case "4":
                    DeleteStudents();
                    return true;
                case "5":
                    UpdateStudents();
                    return true;
                case "6":
                    return false;
                default:
                    return true;
            }
        }

        catch (Exception e)
        {
            Console.WriteLine("error message");
            Console.ReadLine();
            return true;
        }

    }

When I run the program the message "error message" didn't appear after I enter an invalid character.

Body:
You have pretty clear logic: If given number not in the valid numbers list - print error message.

So, don't use exception as part of the logic, exceptions are for the exceptions, for not expected cases. In addition throwing exception will be slightly more expensive than handle it with switch case.

DA0007: Avoid using exceptions for control flow

private static bool ManageStudents()
{
    switch (Console.ReadLine())
    {
        case "1":
            AddStudents();
            return true;
        case "2":
            ViewStudents();
            return true;
        case "3":
            SearchStudents();
            return true;
        case "4":
            DeleteStudents();
            return true;
        case "5":
            UpdateStudents();
            return true;
        case "6":
            return false;
        default:
            Console.WriteLine("Invalid selection");
            return true;
    }
}

Now you can remove all try .. catch blocks.


问:
jquery select after all elements with certain class
I have a few divs with the same class.  The divs are generated dynamically, so I don't always know the exact number of these divs.

I want to place another div after the last div.

```<code><div class="someclassname">content here</div>
<div class="someclassname">content here</div>
<div class="someclassname">content here</div>
</code>```

When I do this:

```<code>$('.someclassname').after('place another div here');
</code>```

It places it after each one.
Is there a way to select the last div with .someclassname?

答:
Use jQuery's last selector like so:

```<code>$('.someclassname:last').after('place another div here');
</code>```

If you want to select the last div with someclassname, and no other element type, then use this instead:

```<code>$('div.someclassname:last').after('place another div here');
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I have a few divs with the same class.  The divs are generated dynamically, so I don't always know the exact number of these divs.

I want to place another div after the last div.

content here

content here

content here

When I do this:

$('.someclassname').after('place another div here');

It places it after each one.
Is there a way to select the last div with .someclassname?

Body:
Use jQuery's last selector like so:

$('.someclassname:last').after('place another div here');

If you want to select the last div with someclassname, and no other element type, then use this instead:

$('div.someclassname:last').after('place another div here');


问:
Just want to add a darken layer or make the UIImageView darken by Swift
As people already know that this seems simple but Stackoverflow has no answers for me. Basically I want to make an image darker like the bg image of Beijing ancient building below:

to make it darker so that the tags on it can be more contrasting obvious.

I tried adding a layer which is one of the answers from Stackoverflow or adding tintColor but none of them worked, is there any method that can really work?  Thank you, guys.

I'm under iOS 13 and swift 5.1

答:
Add this UIView extension to your project

```<code>extension UIView {
func addoverlay(color: UIColor = .black,alpha : CGFloat = 0.6) {
    let overlay = UIView()
    overlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    overlay.frame = bounds
    overlay.backgroundColor = color
    overlay.alpha = alpha
    addSubview(overlay)
    }
    //This function will add a layer on any `UIView` to make that `UIView` look darkened
}
</code>```

then use it like on any UIView(In your Case yourImageView)

```<code>yourImageView.addoverlay()
</code>```

Or you can specify your own overlay color and alpha value

```<code>yourImageView.addoverlay(color: .blue, alpha: 0.5)
</code>```

Body:
Add this UIView extension to your project

extension UIView {
func addoverlay(color: UIColor = .black,alpha : CGFloat = 0.6) {
    let overlay = UIView()
    overlay.autoresizingMask = [.flexibleWidth, .flexibleHeight]
    overlay.frame = bounds
    overlay.backgroundColor = color
    overlay.alpha = alpha
    addSubview(overlay)
    }
    //This function will add a layer on any `UIView` to make that `UIView` look darkened
}

then use it like on any UIView(In your Case yourImageView)

yourImageView.addoverlay()

Or you can specify your own overlay color and alpha value

yourImageView.addoverlay(color: .blue, alpha: 0.5)


问:
How to dynamically create a sitemap.xml in .NET core 2?
Can anyone tell me how to create a Sitemap in .NET Core 2?

These articles/alternate link are not working in .NET Core 2.

答:
Dynamic site map "sitemap-blog.xml" for Blog section and 24h cache. (ASP.NET Core 3.1)

sitemap.xml exists in wwwroot (generated by xml-sitemaps.com or ...).

sitemap-blog.xml generate dynamically.

robots.txt

```<code>User-agent: *
Disallow: /Admin/
Disallow: /Identity/
Sitemap: https://example.com/sitemap.xml
Sitemap: https://example.com/sitemap-blog.xml
</code>```

Startup.cs

```<code>services.AddMemoryCache();
</code>```

HomeController.cs

```<code>namespace MT.Controllers
{
    public class HomeController : Controller
    {
        private readonly ApplicationDbContext _context;
        private readonly IMemoryCache _cache;

        public HomeController(
            ApplicationDbContext context,
            IMemoryCache cache)
        {
            _context = context;
            _cache = cache;

        }

        [Route("/sitemap-blog.xml")]
        public async Task<IActionResult> SitemapBlog()
        {
            string baseUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}";
            string segment = "blog";
            string contentType = "application/xml";

            string cacheKey = "sitemap-blog.xml";

            // For showing in browser (Without download)
            var cd = new System.Net.Mime.ContentDisposition
            {
                FileName = cacheKey,
                Inline = true,
            };
            Response.Headers.Append("Content-Disposition", cd.ToString());

            // Cache
            var bytes = _cache.Get<byte[]>(cacheKey);
            if (bytes != null)
                return File(bytes, contentType);

            var blogs = await _context.Blogs.ToListAsync();

            var sb = new StringBuilder();
            sb.AppendLine($"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            sb.AppendLine($"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"");
            sb.AppendLine($"   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
            sb.AppendLine($"   xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">");

            foreach (var m in blogs)
            {
                var dt = m.LastModified;
                string lastmod = $"{dt.Year}-{dt.Month.ToString("00")}-{dt.Day.ToString("00")}";

                sb.AppendLine($"    <url>");

                sb.AppendLine($"        <loc>{baseUrl}/{segment}/{m.Slug}</loc>");
                sb.AppendLine($"        <lastmod>{lastmod}</lastmod>");
                sb.AppendLine($"        <changefreq>daily</changefreq>");
                sb.AppendLine($"        <priority>0.8</priority>");

                sb.AppendLine($"    </url>");
            }

            sb.AppendLine($"</urlset>");

            bytes = Encoding.UTF8.GetBytes(sb.ToString());

            _cache.Set(cacheKey, bytes, TimeSpan.FromHours(24));
            return File(bytes, contentType);
        }
    }
}
</code>```

Body:
Dynamic site map "sitemap-blog.xml" for Blog section and 24h cache. (ASP.NET Core 3.1)

sitemap.xml exists in wwwroot (generated by xml-sitemaps.com or ...).

sitemap-blog.xml generate dynamically.

robots.txt

User-agent: *
Disallow: /Admin/
Disallow: /Identity/
Sitemap: https://example.com/sitemap.xml
Sitemap: https://example.com/sitemap-blog.xml

Startup.cs

services.AddMemoryCache();

HomeController.cs

namespace MT.Controllers
{
    public class HomeController : Controller
    {
        private readonly ApplicationDbContext _context;
        private readonly IMemoryCache _cache;

        public HomeController(
            ApplicationDbContext context,
            IMemoryCache cache)
        {
            _context = context;
            _cache = cache;

        }

        [Route("/sitemap-blog.xml")]
        public async Task<IActionResult> SitemapBlog()
        {
            string baseUrl = $"{Request.Scheme}://{Request.Host}{Request.PathBase}";
            string segment = "blog";
            string contentType = "application/xml";

            string cacheKey = "sitemap-blog.xml";

            // For showing in browser (Without download)
            var cd = new System.Net.Mime.ContentDisposition
            {
                FileName = cacheKey,
                Inline = true,
            };
            Response.Headers.Append("Content-Disposition", cd.ToString());

            // Cache
            var bytes = _cache.Get<byte[]>(cacheKey);
            if (bytes != null)
                return File(bytes, contentType);

            var blogs = await _context.Blogs.ToListAsync();

            var sb = new StringBuilder();
            sb.AppendLine($"<?xml version=\"1.0\" encoding=\"utf-8\"?>");
            sb.AppendLine($"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"");
            sb.AppendLine($"   xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
            sb.AppendLine($"   xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">");

            foreach (var m in blogs)
            {
                var dt = m.LastModified;
                string lastmod = $"{dt.Year}-{dt.Month.ToString("00")}-{dt.Day.ToString("00")}";

                sb.AppendLine($"    <url>");

                sb.AppendLine($"        <loc>{baseUrl}/{segment}/{m.Slug}</loc>");
                sb.AppendLine($"        <lastmod>{lastmod}</lastmod>");
                sb.AppendLine($"        <changefreq>daily</changefreq>");
                sb.AppendLine($"        <priority>0.8</priority>");

                sb.AppendLine($"    </url>");
            }

            sb.AppendLine($"</urlset>");

            bytes = Encoding.UTF8.GetBytes(sb.ToString());

            _cache.Set(cacheKey, bytes, TimeSpan.FromHours(24));
            return File(bytes, contentType);
        }
    }
}


问:
Problem with using git with mongodb in command prompt
I am having trouble getting go get go.mongodb.org/mongo-driver/mongo working:

As I type it into my command prompt nothing shows up after, it just leaves it blank after a few mometns and it returns to my c:\user.

Can anyone let me know what i am doing incorrectly

Using any other go get with other packages works fine.

When I create a directory and use

```<code>go mod init github.com/example/example
</code>```

it installs fine, but can not be used in my program

答:
Double-check your %GOPATH%\bin folder (if GOPATH is not defined: %USERPROFILE%\go\bin)

```<code>dir /OD %USERPROFILE%\go\bin
</code>```

If you see a binary created recently, the go get shoul have worked (build+install)

If the build was enough( meaning no binary to install), check if a simple program at least compile:

```<code>import (
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
)

client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
</code>```

Body:
I am having trouble getting go get go.mongodb.org/mongo-driver/mongo working:

As I type it into my command prompt nothing shows up after, it just leaves it blank after a few mometns and it returns to my c:\user.

Can anyone let me know what i am doing incorrectly

Using any other go get with other packages works fine.

When I create a directory and use

go mod init github.com/example/example

it installs fine, but can not be used in my program

Body:
Double-check your %GOPATH%\bin folder (if GOPATH is not defined: %USERPROFILE%\go\bin)

dir /OD %USERPROFILE%\go\bin

If you see a binary created recently, the go get shoul have worked (build+install)

If the build was enough( meaning no binary to install), check if a simple program at least compile:

import (
    "go.mongodb.org/mongo-driver/mongo"
    "go.mongodb.org/mongo-driver/mongo/options"
)

client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))


问:
how to generate a php image for src
I would like to use:

```<code>src="my_generated_image_from_php.jpg"
</code>```

instead of

src="my_php_image.php"

How do I do it?

my_php_image.php like:

```<code><?php
     ......
     Header('Content-type: image/png');
     imagepng($im2);
     imagedestroy($im2);
     ......
?>
</code>```

答:
If I understand you correctly you will need to save your php generated image as an actual image file. I would start reading here:

http://php.net/manual/en/function.imagejpeg.php

Title: how to generate a php image for src

Body:
I would like to use:

src="my_generated_image_from_php.jpg"

instead of

src="my_php_image.php"

How do I do it?

my_php_image.php like:

<?php
     ......
     Header('Content-type: image/png');
     imagepng($im2);
     imagedestroy($im2);
     ......
?>


问:
Confused with Join logic
I find it so confused that my simple logic doesn't work.

I have a data with 2 columns ID and code.

1 ID can link to multiple code.

So the sample data is like this:

```<code>ID   Code
--   ----
a    1
a    2
a    3
b    1
b    3
c    1
c    3
c    4
d    2
d    3
d    4
</code>```

The rule is that:

Find ID that has code = 1 AND code not equal to 2 AND code =3

So clearly a is fail, b is good, c is good, d is fail.

I have 2 approaches below and neither of them work!

Can you please help?

Many thanks,

Harry

Approach #1:

```<code>create table mytable (
ID int,
code varchar(255)
);

insert into mytable (ID, code)
values('a','1'),('a','2'),('a','3'),('b','1'),('b','3'),('c','1'),('c','3'),('c','4'),('d','2'),('d','3'),('d','4');

select distinct
    ID
from
    mytable
where
    code = 1
    and ID not in (select ID from mytable where code = 2)
    and ID in (select ID from mytable where code = 3);
</code>```

Approach #2: join my table 2 times

```<code>select distinct(T1.ID)
from
    (select distinct(mytable1.ID)
     from mytable mytable1
     join mytable mytable2 on  mytable1.ID = mytable2.ID
     where mytable1.code = 1
       and mytable2.code not in ('2')) as T1
join
    (select distinct(mytable3.ID)
     from mytable mytable3
     where mytable3.code = 3) as T2
on T1.ID = T2.ID
</code>```

答:
Welcome to S/O.  Your posts will get better with time with reading others and additional feedback.  Your question states one thing, but query offers another.

Your WHERE clause on its individual parts is asking for the code = 1, and the corresponding "ID" does not have a code = 2, but it DOES have a code = 3 IN ADDITION to code = 1.

```<code>where
    code = 1
    and ID not in (select ID from mytable where code = 2)
    and ID in (select ID from mytable where code = 3);
</code>```

Aside from aggregations, you can use the same table and self-join on the conditions you want.  In this case, I might start with your base query of just the code = 1.  Then I would join again on same ID, but it also having a code 3 (both 1 and 3 required).  Then a third LEFT JOIN for code 2 and ensuring it is NOT found

```<code>select
      t1.id
   from
      MyTable t1
         -- now, does it also exist for the same "ID" but also have code = 3
         JOIN MyTable t2
            on t1.id = t2.id
            AND t2.code = 3
         -- here, I am explicitly LOOKING for code = 2 for same ID.
         -- but by doing a LEFT-JOIN, I only want where it does NOT exist
         LEFT JOIN MyTable t3
            on t1.id = t3.id
            AND t3.code = 2
   where
          t1.code = 1
      -- explicitly making sure the is no match for same ID, code = 2
      AND t3.id IS NULL
</code>```

Another approach is via aggregation, but getting a count of 1 & 3, another for code = 2 but making sure counts make sense to your needs.

```<code>select
      t1.id
   from
      MyTable t1
   having
          sum( case when t1.code = 1 then 1 else 0 end ) > 0
      AND sum( case when t1.code = 3 then 1 else 0 end ) > 0
      AND sum( case when t1.code = 2 then 1 else 0 end ) = 0
   group by
      t1.id
</code>```

In the above, say you have multiple records for a given ID that are code = 1, you MAY get a count higher than 1.  Hence I am summing just for code 1 and only care if it has AT LEAST 1.  Similar requirement for code = 3 having the sum of AT LEAST 1.  Finally, the sum of code = 2 making sure it is = 0 for its count.

FEEDBACK on SECOND query from OP

The reason for your failure on the second query is in the first part before your join for code test = 3

```<code>select distinct(T1.ID)
from
    (select distinct(mytable1.ID)
     from mytable mytable1
     join mytable mytable2 on  mytable1.ID = mytable2.ID
     where mytable1.code = 1
       and mytable2.code not in ('2')) as T1
</code>```

You are querying where table1.code = 1 which is ok, and then your join from table1 to table2 is only on the ID.  So, for example on your data with

```<code>id   code
a    1
a    2
a    3
</code>```

your self join is returning records with codes 1, 2 AND 3.  So even though you may not want #2, it is still pulling in IDs 1 & 3 which DO qualify, hence the logical failure.  That is why in my FIRST example, I am doing a LEFT JOIN on same id and explicitly code = 2... but the where clause is explicitly EXCLUDING by where the table 3 alias ID is NULL, meaning it does NOT see a record for same ID, code = 2.

Title: Confused with Join logic

Body:
I find it so confused that my simple logic doesn't work.

I have a data with 2 columns ID and code.

1 ID can link to multiple code.

So the sample data is like this:

ID   Code
--   ----
a    1
a    2
a    3
b    1
b    3
c    1
c    3
c    4
d    2
d    3
d    4

The rule is that:

Find ID that has code = 1 AND code not equal to 2 AND code =3

So clearly a is fail, b is good, c is good, d is fail.

I have 2 approaches below and neither of them work!

Can you please help?

Many thanks,

Harry

Approach #1:

create table mytable (
ID int,
code varchar(255)
);

insert into mytable (ID, code)
values('a','1'),('a','2'),('a','3'),('b','1'),('b','3'),('c','1'),('c','3'),('c','4'),('d','2'),('d','3'),('d','4');

select distinct
    ID
from
    mytable
where
    code = 1
    and ID not in (select ID from mytable where code = 2)
    and ID in (select ID from mytable where code = 3);

Approach #2: join my table 2 times

select distinct(T1.ID)
from
    (select distinct(mytable1.ID)
     from mytable mytable1
     join mytable mytable2 on  mytable1.ID = mytable2.ID
     where mytable1.code = 1
       and mytable2.code not in ('2')) as T1
join
    (select distinct(mytable3.ID)
     from mytable mytable3
     where mytable3.code = 3) as T2
on T1.ID = T2.ID

Body:
Welcome to S/O.  Your posts will get better with time with reading others and additional feedback.  Your question states one thing, but query offers another.

Your WHERE clause on its individual parts is asking for the code = 1, and the corresponding "ID" does not have a code = 2, but it DOES have a code = 3 IN ADDITION to code = 1.

where
    code = 1
    and ID not in (select ID from mytable where code = 2)
    and ID in (select ID from mytable where code = 3);

Aside from aggregations, you can use the same table and self-join on the conditions you want.  In this case, I might start with your base query of just the code = 1.  Then I would join again on same ID, but it also having a code 3 (both 1 and 3 required).  Then a third LEFT JOIN for code 2 and ensuring it is NOT found

select
      t1.id
   from
      MyTable t1
         -- now, does it also exist for the same "ID" but also have code = 3
         JOIN MyTable t2
            on t1.id = t2.id
            AND t2.code = 3
         -- here, I am explicitly LOOKING for code = 2 for same ID.
         -- but by doing a LEFT-JOIN, I only want where it does NOT exist
         LEFT JOIN MyTable t3
            on t1.id = t3.id
            AND t3.code = 2
   where
          t1.code = 1
      -- explicitly making sure the is no match for same ID, code = 2
      AND t3.id IS NULL

Another approach is via aggregation, but getting a count of 1 & 3, another for code = 2 but making sure counts make sense to your needs.

select
      t1.id
   from
      MyTable t1
   having
          sum( case when t1.code = 1 then 1 else 0 end ) > 0
      AND sum( case when t1.code = 3 then 1 else 0 end ) > 0
      AND sum( case when t1.code = 2 then 1 else 0 end ) = 0
   group by
      t1.id

In the above, say you have multiple records for a given ID that are code = 1, you MAY get a count higher than 1.  Hence I am summing just for code 1 and only care if it has AT LEAST 1.  Similar requirement for code = 3 having the sum of AT LEAST 1.  Finally, the sum of code = 2 making sure it is = 0 for its count.

FEEDBACK on SECOND query from OP

The reason for your failure on the second query is in the first part before your join for code test = 3

select distinct(T1.ID)
from
    (select distinct(mytable1.ID)
     from mytable mytable1
     join mytable mytable2 on  mytable1.ID = mytable2.ID
     where mytable1.code = 1
       and mytable2.code not in ('2')) as T1

You are querying where table1.code = 1 which is ok, and then your join from table1 to table2 is only on the ID.  So, for example on your data with

id   code
a    1
a    2
a    3

your self join is returning records with codes 1, 2 AND 3.  So even though you may not want #2, it is still pulling in IDs 1 & 3 which DO qualify, hence the logical failure.  That is why in my FIRST example, I am doing a LEFT JOIN on same id and explicitly code = 2... but the where clause is explicitly EXCLUDING by where the table 3 alias ID is NULL, meaning it does NOT see a record for same ID, code = 2.


问:
Tkinter messagebox, which lists all empty variables
I am coding a gui, which has several varibales for entry boxes and drop-down menus. When pressing the "Calculate-Button", I want it to check if all fields are filled. If not it shall pop up a messagebox and lists the empty widgets. I am not getting how to do it...</p>

```<code>    def next_button_open_results(self):
        if not self.state.varCR.get() or self.state.varTR.get() \
                or self.state.annual_distance_entry.get() or self.state.varStyle or self.state.lifetime_entry.get():
            messagebox.showinfo("Invalid configuration", "Please select:" + ???)
        else:
"CALCULATE"

</code>```

答:
You can save the empty widget names to an array and then show the messagebox if the array is not empty:</p>

```<code>def next_button_open_results():
  widgets = []
  if self.state.varCR.get().strip() == '':
    widgets.append('varCR')
  if self.state.varTR.get().strip() == '':
    widgets.append('varTR')
  if self.state.varStyle.get().strip() == '':
    widgets.append('varStyle')
  if self.state.annual_distance_entry.get().strip() == '':
    widgets.append('annual_distance_entry')
  if self.state.lifetime_entry.get().strip() == '':
    widgets.append('lifetime_entry')
  if len(widgets) > 0:
    messagebox.showinfo('Invalid configuration', 'Please select: '+', '.join(widgets))
  else:
    # do whatever you want
    pass
</code>```

Body:
I am coding a gui, which has several varibales for entry boxes and drop-down menus. When pressing the "Calculate-Button", I want it to check if all fields are filled. If not it shall pop up a messagebox and lists the empty widgets. I am not getting how to do it...

    def next_button_open_results(self):
        if not self.state.varCR.get() or self.state.varTR.get() \
                or self.state.annual_distance_entry.get() or self.state.varStyle or self.state.lifetime_entry.get():
            messagebox.showinfo("Invalid configuration", "Please select:" + ???)
        else:
"CALCULATE"

Body:
You can save the empty widget names to an array and then show the messagebox if the array is not empty:

def next_button_open_results():
  widgets = []
  if self.state.varCR.get().strip() == '':
    widgets.append('varCR')
  if self.state.varTR.get().strip() == '':
    widgets.append('varTR')
  if self.state.varStyle.get().strip() == '':
    widgets.append('varStyle')
  if self.state.annual_distance_entry.get().strip() == '':
    widgets.append('annual_distance_entry')
  if self.state.lifetime_entry.get().strip() == '':
    widgets.append('lifetime_entry')
  if len(widgets) > 0:
    messagebox.showinfo('Invalid configuration', 'Please select: '+', '.join(widgets))
  else:
    # do whatever you want
    pass


问:
Handling AWS credentials within an Angular app
I have an Angular application that makes use of the following AWS credentials:

```<code>  awsAccessKeyId
  awssecretAccessKey
  awsBucket
  awsEndpointUrl
  awsRegion
  awsKey
</code>```

I wanted to store them in the environment.ts file of my application but have been told that it is a bad idea. Where else can I store them? I was thinking Firebase, but only allowing the document to be read with an authenticated user with a particular UID via an API call.

答:
As you said, it's not safe to store AWS credentials in the frontend javascript files since it's publicly readable by anyone who can access your website.

I suggest you develop a server-side API and call the API from your angular application. The API is used to talk to aws services. In this way, you do not have to store the aws credential in the static website.

Using an API

Create an API to talk to AWS services.

User login

The angular should be protected by login to allow users to authenticate against an authentication service (such as Amazon Cognito) or your own authentication API. Once the user is successfully logged in, The authentication service will return a token of some sort. You can store this token in the browser's Local Stoage.

call your api

When you call the API endpoint, you will need to provide this token. The API should verify the token before allowing the call to proceed.

Reference:
https://www.techopedia.com/definition/27674/html5-local-storage

Hope this helps.

Body:
I have an Angular application that makes use of the following AWS credentials:

  awsAccessKeyId
  awssecretAccessKey
  awsBucket
  awsEndpointUrl
  awsRegion
  awsKey

I wanted to store them in the environment.ts file of my application but have been told that it is a bad idea. Where else can I store them? I was thinking Firebase, but only allowing the document to be read with an authenticated user with a particular UID via an API call.


问:
How to handle errors on RxKotlin + Graphql
I am getting:

io.reactivex.exceptions.OnErrorNotImplementedException: The exception
  was not handled due to missing onError handler in the subscribe()
  method call

I had tried to add

```<code>.doOnError { error ->
            Log.i("reverser code error",error.localizedMessage)
       }.onErrorReturn { err ->
          "Return method"
     }
</code>```

But it's not working.

答:
doOnError and other Side Effect operators do not affect your stream in itself. Instead they are invoked when certain events occur to allow you to react to those events, in another words they just anticipate the values emitted for side-effect operations like logging for example

You can pass another lambda to subscribe to handle the errors for a specific stream like this:

```<code>.subscribe( { /*on subscribe method here*/}, { throwable -> /*handle error*/ } )
</code>```

Take a look at this tutorial -> https://www.grokkingandroid.com/rxjavas-side-effect-methods/

Body:
I am getting:

io.reactivex.exceptions.OnErrorNotImplementedException: The exception
  was not handled due to missing onError handler in the subscribe()
  method call

I had tried to add

.doOnError { error ->
            Log.i("reverser code error",error.localizedMessage)
       }.onErrorReturn { err ->
          "Return method"
     }

But it's not working.

Body:
doOnError and other Side Effect operators do not affect your stream in itself. Instead they are invoked when certain events occur to allow you to react to those events, in another words they just anticipate the values emitted for side-effect operations like logging for example

You can pass another lambda to subscribe to handle the errors for a specific stream like this:

.subscribe( { /*on subscribe method here*/}, { throwable -> /*handle error*/ } )

Take a look at this tutorial -> https://www.grokkingandroid.com/rxjavas-side-effect-methods/


问:
How to read one full line, followed by reading only the last five characters?
I am new to Python. I want to read a JSON file from monitoring. The file looks like this

I only want the timestamp, the system name like "test-1" and the numbers from power, disk and CPU.

My script looks like this

```<code>#!/usr/bin/env python3.3

import os
import json

    with open('test.json', 'r') as f:
        distros_dict = json.load(f)

    for distro in distros_dict:
        print(distro['"power [W]"'])
</code>```

Update:
How do i write them to variables?

New Sample Data:

```<code>[
   {
      "Area":"CLOUD",
      "timestamp":"2019-11-06T00:00:00",
      "Systeme":{
         "test-4":{
            "power [W]":181.05,
            "disk [%]":52.28
         },
         "test-1":{
            "power [W]":280.56,
            "disk[%]":6.33,
            "cpu[%]":0.1
         },
         "test-2":{
            "power [W]":271.84,
            "disk[%]":6.52,
            "cpu[%]":0.1
         },
         "test-8":{
            "power [W]":453.56,
            "disk[%]":93.63,
            "cpu[%]":5.04
         }
      }
   }
]
</code>```

The Output variables i want are cpu,power and disk
Instead of printing them to commandline i want write them in the three variables

答:
You can use a list of tuples to store your variables. Here is an example of how you can do this.</p>

```<code>import json
import sys

data = None

with open('test.json', 'r') as file:
    data = json.load(file)

# since we are dealing with input from another source, we should validate it every step of the way
# check if there was no data in the file
if not data:
    sys.exit(0)

variables = []  # this list would contain tuples. The tuple would contain system name, cpu, power, and disk. Any missing data would be set as None
for distro in data:
    if 'Systeme' not in distro:  # we verify this attribute exists
        continue
    for system_name, system in distro['Systeme'].items():
         variables.append(
             (system_name, system.get('cpu[%]'), system.get('power [W]'), system.get('disk[%]'))
         )

# now that we have them stored inside the 'variables' list, we can print them to verify that they are stored.
for system_name, cpu, power, disk in variables:
    print(system_name, cpu, power, disk)
    # do other stuff with these variables here if you want.
</code>```

Body:
I am new to Python. I want to read a JSON file from monitoring. The file looks like this

I only want the timestamp, the system name like "test-1" and the numbers from power, disk and CPU.

My script looks like this

#!/usr/bin/env python3.3

import os
import json

    with open('test.json', 'r') as f:
        distros_dict = json.load(f)

    for distro in distros_dict:
        print(distro['"power [W]"'])

Update:
How do i write them to variables?

New Sample Data:

[
   {
      "Area":"CLOUD",
      "timestamp":"2019-11-06T00:00:00",
      "Systeme":{
         "test-4":{
            "power [W]":181.05,
            "disk [%]":52.28
         },
         "test-1":{
            "power [W]":280.56,
            "disk[%]":6.33,
            "cpu[%]":0.1
         },
         "test-2":{
            "power [W]":271.84,
            "disk[%]":6.52,
            "cpu[%]":0.1
         },
         "test-8":{
            "power [W]":453.56,
            "disk[%]":93.63,
            "cpu[%]":5.04
         }
      }
   }
]

The Output variables i want are cpu,power and disk
Instead of printing them to commandline i want write them in the three variables

Body:
You can use a list of tuples to store your variables. Here is an example of how you can do this.

import json
import sys

data = None

with open('test.json', 'r') as file:
    data = json.load(file)

# since we are dealing with input from another source, we should validate it every step of the way
# check if there was no data in the file
if not data:
    sys.exit(0)

variables = []  # this list would contain tuples. The tuple would contain system name, cpu, power, and disk. Any missing data would be set as None
for distro in data:
    if 'Systeme' not in distro:  # we verify this attribute exists
        continue
    for system_name, system in distro['Systeme'].items():
         variables.append(
             (system_name, system.get('cpu[%]'), system.get('power [W]'), system.get('disk[%]'))
         )

# now that we have them stored inside the 'variables' list, we can print them to verify that they are stored.
for system_name, cpu, power, disk in variables:
    print(system_name, cpu, power, disk)
    # do other stuff with these variables here if you want.


问:
reversing the order of elements in Array
i'm  currently stuck on an assignment where I have to reverse the order of the elements in my Array.
But the problem is that I only get the 10 10 times and not 10 9 8...</p>
```<code>package JavaSection4;

public class Assignment4Nr2 {

    public static void main(String[] args) {

        int[] ranNum = new int[10];

        ranNum[0] = 1;
        ranNum[1] = 2;
        ranNum[2] = 3;
        ranNum[3] = 4;
        ranNum[4] = 5;
        ranNum[5] = 6;
        ranNum[6] = 7;
        ranNum[7] = 8;
        ranNum[8] = 9;
        ranNum[9] = 10;

        for(int i = 0; i < ranNum.length; i++) {

            int l = 0;

            l = ranNum.length - 1;

            System.out.println(ranNum[l]);
        }
    }
}
</code>```

答:
You're not reversing the order, You're just trying to read it from the end.

Reversing the order would be

```<code>Integer[] integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
ArrayUtils.reverse(integers);
</code>```

By using the appripriate tools (in this case apache-commons). Finding out how it's done is easy by checking the tools source code:

```<code>public static void reverse(Object[] array) {
    if (array == null) {
        return;
    }
    int i = 0;
    int j = array.length - 1;
    Object tmp;
    while (j > i) {
        tmp = array[j];
        array[j] = array[i];
        array[i] = tmp;
        j--;
        i++;
    }
}
</code>```

Body:
i'm  currently stuck on an assignment where I have to reverse the order of the elements in my Array.
But the problem is that I only get the 10 10 times and not 10 9 8...

package JavaSection4;

public class Assignment4Nr2 {

    public static void main(String[] args) {

        int[] ranNum = new int[10];

        ranNum[0] = 1;
        ranNum[1] = 2;
        ranNum[2] = 3;
        ranNum[3] = 4;
        ranNum[4] = 5;
        ranNum[5] = 6;
        ranNum[6] = 7;
        ranNum[7] = 8;
        ranNum[8] = 9;
        ranNum[9] = 10;

        for(int i = 0; i < ranNum.length; i++) {

            int l = 0;

            l = ranNum.length - 1;

            System.out.println(ranNum[l]);
        }
    }
}

Body:
You're not reversing the order, You're just trying to read it from the end.

Reversing the order would be

Integer[] integers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
ArrayUtils.reverse(integers);

By using the appripriate tools (in this case apache-commons). Finding out how it's done is easy by checking the tools source code:

public static void reverse(Object[] array) {
    if (array == null) {
        return;
    }
    int i = 0;
    int j = array.length - 1;
    Object tmp;
    while (j > i) {
        tmp = array[j];
        array[j] = array[i];
        array[i] = tmp;
        j--;
        i++;
    }
}


问:
jinja2.exceptions.TemplateNotFound: index.html
I try to open a index.html using Flask

run.py

```<code>from app import app
app.run(debug = True)
</code>```

__init__.py

```<code>from flask import Flask
app = Flask(__name__)
from app import routes
</code>```

routes.py

```<code>from flask import render_template
from app import app
@app.route('/')
@app.route('/index')
def index():
    user = 'Cala'
    return render_template('index.html', user=user)
</code>```

index.html

```<code><html>
    <body>
        {% for user in users %}
            <h1>Hola {{ user }}</h1>
            <h1>Bienvenido a Olivanders</h1>
        {% endfor %}
    </body>
</html>
</code>```

When i run the run.py file i have the error jinja2.exceptions.TemplateNotFound: index.html

The files are in the filed called app except the run.py, this filed is in the general filed

答:
Okay, let me elaborate in steps.

Step 1. Create a new folder called "templates"

Step 2. Move your "index.html" in to the "templates" folder

Step 3. In your index function, return render_template('index.html', user=user)

Hope this helps, feel free to ask any questions!

Body:
I try to open a index.html using Flask

run.py

from app import app
app.run(debug = True)

__init__.py

from flask import Flask
app = Flask(__name__)
from app import routes

routes.py

from flask import render_template
from app import app
@app.route('/')
@app.route('/index')
def index():
    user = 'Cala'
    return render_template('index.html', user=user)

index.html

        {% for user in users %}

Hola {{ user }}

Bienvenido a Olivanders

        {% endfor %}

When i run the run.py file i have the error jinja2.exceptions.TemplateNotFound: index.html

The files are in the filed called app except the run.py, this filed is in the general filed


问:
Typescript: Spread types may only be created from object types
```<code>function foo<T extends object>(t: T): T {

  return {
    ...t // Error: [ts] Spread types may only be created from object types.
  }
}
</code>```

I am aware that there are issues on github, but I can't figure out what is fixed and what is not and they have 2695 open issues. So I am posting here. I am using latest Typescript 2.9.2.

Should the above code not work? And how can I fix it if possible?

答:
This answer may help to fix the same problem while using angular and firestoe.

return { id: item.payload.doc.id,
...item.payload.doc.data()}
as Employee

this on will throw he same error. for fixing you have to change like this one.

return { id: item.payload.doc.id,
...item.payload.doc.data() as Employee }

Body:
function foo<T extends object>(t: T): T {

  return {
    ...t // Error: [ts] Spread types may only be created from object types.
  }
}

I am aware that there are issues on github, but I can't figure out what is fixed and what is not and they have 2695 open issues. So I am posting here. I am using latest Typescript 2.9.2.

Should the above code not work? And how can I fix it if possible?


问:
Does Java have support for multiline strings?
Coming from Perl, I sure am missing the "here-document" means of creating a multi-line string in source code:

```<code>$string = <<"EOF"  # create a three-line string
text
text
text
EOF
</code>```

In Java, I have to have cumbersome quotes and plus signs on every line as I concatenate my multiline string from scratch.

What are some better alternatives?  Define my string in a properties file?

Edit: Two answers say StringBuilder.append() is preferable to the plus notation.  Could anyone elaborate as to why they think so?  It doesn't look more preferable to me at all.  I'm looking for a way around the fact that multiline strings are not a first-class language construct, which means I definitely don't want to replace a first-class language construct (string concatenation with plus) with method calls.

Edit: To clarify my question further, I'm not concerned about performance at all.  I'm concerned about maintainability and design issues.

答:
Two answers to this question:

In you want to stick to pure Java, with Java 14 being released in March 2020, you can leverage the JEP 368 - Text Blocks, in Second Preview mode. Actually the feature is in preview mode in other releases (at least 13 has it). I created and example set here.

While this feature is useful, it can be easily abused. Remember that Java requires compilation - having large character arrays in your code can be an easy way to shoot yourself in the leg (if you want a quick change, you will need recompilation - that toolset might not be available to the guy operating your application).

In my experience, it is advisable to keep large strings (and generally strings that could/should be altered at runtime by app operators) in configuration files.

Summary: use text blocks responsibly :).

Body:
Coming from Perl, I sure am missing the "here-document" means of creating a multi-line string in source code:

$string = <<"EOF"  # create a three-line string
text
text
text
EOF

In Java, I have to have cumbersome quotes and plus signs on every line as I concatenate my multiline string from scratch.

What are some better alternatives?  Define my string in a properties file?

Edit: Two answers say StringBuilder.append() is preferable to the plus notation.  Could anyone elaborate as to why they think so?  It doesn't look more preferable to me at all.  I'm looking for a way around the fact that multiline strings are not a first-class language construct, which means I definitely don't want to replace a first-class language construct (string concatenation with plus) with method calls.

Edit: To clarify my question further, I'm not concerned about performance at all.  I'm concerned about maintainability and design issues.


问:
How to filter data in Flask?
I'm building advertisement service in Flask and want to let users filter adverts by category but dont know how to do that in python and flask.

For example, we have following Advert form:

```<code>class AdvertForm(FlaskForm):
    title = StringField('Title', validators=[DataRequired()])
    content = TextAreaField('Content', validators=[DataRequired()])
    category = SelectField('Caterogry', validators=[DataRequired()], choices=[('car','Car'), ('work','Work'), ('sport','Sport')])
    submit = SubmitField('Submit')
</code>```

And following html:

```<code>  <div class="categories">
    <div class="category-item">
      <a href="">Cars</a>
    </div>
    <div class="category-item">
      <a href="">Work</a>
    </div>
    <div class="category-item">
      <a href="">Sport</a>
    </div>
  </div>
</code>```

And when user clicks on Cars item in HTML I want to make subpage 127.0.0.1:5000/cars and display only adverts which have car category

答:
You could capture the category selected by the user and send it back to your Python function. Then, depending on the selection, route the user to the appropriate sub-page.

```<code>@app.route('/mainpage', methods=['GET','POST'])
def mainpage():
    form = AdvertForm()
    if form.validate_on_submit():
        selectedCategory = request.form['category']
        nextPage = selectedCategory + ".html"
        return render_template(nextPage)
    return render_template('mainpage.html', form=form)
</code>```

In the example above, if the users chooses Car and clicks Submit, they will be routed to http://localhost:5000/car.html. If they choose Work, they will be routed to http://localhost:5000/work.html. I'm sure you get the idea.

Title: How to filter data in Flask?

Body:
I'm building advertisement service in Flask and want to let users filter adverts by category but dont know how to do that in python and flask.

For example, we have following Advert form:

class AdvertForm(FlaskForm):
    title = StringField('Title', validators=[DataRequired()])
    content = TextAreaField('Content', validators=[DataRequired()])
    category = SelectField('Caterogry', validators=[DataRequired()], choices=[('car','Car'), ('work','Work'), ('sport','Sport')])
    submit = SubmitField('Submit')

And following html:

      Cars

      Work

      Sport

And when user clicks on Cars item in HTML I want to make subpage 127.0.0.1:5000/cars and display only adverts which have car category

Body:
You could capture the category selected by the user and send it back to your Python function. Then, depending on the selection, route the user to the appropriate sub-page.

@app.route('/mainpage', methods=['GET','POST'])
def mainpage():
    form = AdvertForm()
    if form.validate_on_submit():
        selectedCategory = request.form['category']
        nextPage = selectedCategory + ".html"
        return render_template(nextPage)
    return render_template('mainpage.html', form=form)

In the example above, if the users chooses Car and clicks Submit, they will be routed to http://localhost:5000/car.html. If they choose Work, they will be routed to http://localhost:5000/work.html. I'm sure you get the idea.