Here is the original code:
import site;
import re
for i in site.getsitepackages():
package = re.search("^/usr/local/lib/.*/dist-packages$", i)
if package is None:
continue
print(package.string)
Output:
/usr/local/lib/python3.8/dist-packages
Here is the one line code:
import site; import re; for i in site.getsitepackages(): package = re.search("^/usr/local/lib/.*/dist-packages$", i); if package is None: continue; print(package.string)
Output:
File "/tmp/ipykernel_2984/3719293883.py", line 1
import site; import re; for i in site.getsitepackages(): package = re.search("^/usr/local/lib/.*/dist-packages$", i); if package is None: continue; print(package.string)
^
SyntaxError: invalid syntax
I want to convert the above multiple lines into one line, and then run it in the bash command line:
python3 -c "<one line python code>"