vscode import error for python module

I tried to add this in my launch.json, then it works! “env”: {“PYTHONPATH”: “${workspaceRoot}”} below is my launch.json “name”: “Python: Current File (Integrated Terminal)”, “type”: “python”, “request”: “launch”, “program”: “${file}”, “cwd”: “${workspaceRoot}”, “env”: {“PYTHONPATH”: “${workspaceRoot}”}, “console”: “integratedTerminal” wish it can help u! 🙂

How to control the download of files with Selenium + Python bindings in Chrome

The path you declared for the default directory is invalid. Either escape the back slashes or provide a literal string. options = webdriver.ChromeOptions() options.add_experimental_option(“prefs”, { “download.default_directory”: r”C:\Users\xxx\downloads\Test”, “download.prompt_for_download”: False, “download.directory_upgrade”: True, “safebrowsing.enabled”: True }) driver = webdriver.Chrome(chrome_options=options) Here are the available preferences: https://cs.chromium.org/chromium/src/chrome/common/pref_names.cc

Python struct.pack() behavior

From [Python 2.Docs]: struct – Interpret bytes as packed binary data: This module performs conversions between Python values and C structs represented as Python strings. This means that it will print the memory representation of the argument(s) as char sequences. Memory (and everything that resides in it) is a sequence of bytes. Each byte has … Read more

“This browser or app may not be secure” error while attempting to login in to Gmail account using GeckoDriver Firefox through Selenium and Python

First install undetected-chromedriver using pip. It’s a library which bypass Chrome security and allow you to proceed further. pip install undetected-chromedriver Then instead of creating using chromedriver.exe like driver = webdriver.Chrome(r”chromedriver.exe”), use the Chrome() function from the library you just installed. Full Code Example in Python: import undetected_chromedriver.v2 as uc from time import sleep username=”[email protected]” … Read more

connected component labeling in python

The OpenCV 3.0 docs for connectedComponents() don’t mention Python but it actually is implemented. See for e.g. this SO question. On OpenCV 3.4.0 and above, the docs do include the Python signatures, as can be seen on the current master docs. The function call is simple: num_labels, labels_im = cv2.connectedComponents(img) and you can specify a … Read more

Set scientific notation with fixed exponent and significant digits for multiple subplots

You can subclass matplotlib.ticker.ScalarFormatter and fix the orderOfMagnitude attribute to the number you like (in this case -4). In the same way you can fix the format to be used. import numpy as np import matplotlib.pyplot as plt import matplotlib.ticker class OOMFormatter(matplotlib.ticker.ScalarFormatter): def __init__(self, order=0, fformat=”%1.1f”, offset=True, mathText=True): self.oom = order self.fformat = fformat matplotlib.ticker.ScalarFormatter.__init__(self,useOffset=offset,useMathText=mathText) … Read more