Tag Archives: Python
Shallow Copy vs Deep Copy in JavaScript and Python
The issue of preventing future mutation of the copied original exists both in JavaScript and Python. In Python, both lists and dictionaries are mutable reference types, similar to arrays and objects in JavaScript. When you copy these structures, you must be aware of whether you are making a shallow or deep copy. Deep Copy vs…
SFTP File Operations with Python Using an SSH Key
Below are some functions to read, write, and delete a file, list a directory, and check if a file exists in a remote SFTP server with Python. I have written these specifically for working with CSV files and pandas data frames. The argument file in the functions below should be the full path to the…
How to Take a Screenshot of a Website in Python Silently with Selenium
The code below will make a browser 1920px wide, and as long as the page and take its screenshot: If the page needs to load asynchronously to complete building the DOM, you may need to give it a few seconds before taking the screenshot: If the page requires scrolling down to load the rest of…
Splitting Flask Routing Functions into Different Modules
We can put group-related routing functions into separate modules to keep a big project organized and avoid having one long views.py in your project. For example, we can take the login and sign-up-related functions from views.py and move them into a module named auth.py. In auth.py, we need to register a new blueprint: In auth.py:…
Installing GeoPandas with Its Dependencies, without installing Microsoft Visual C++
The Problem If you try to install GeoPandas with pip install geopandas, you may get an error like below. Since you don’t have the dependency GDAL installed, the installer cannot find the config and exits. Then you try installing gdal with pip install gdal and you get another error saying: The Solution Christoph Gohlke from…
Python Shortcuts
*args and **kwargs Combine lists with zip() For Else and While Else Inline conditions Unpack a collection of items and assign them to variables Assign multiple variables in one line Initialize a collection in one line Itertools
How to Create HTML and PDF Files from Jupyter Notebooks
Converting to HTML You can convert the notebook named test.ipynb to HTML using the following command: Converting to PDF You can convert the notebook named test.ipynb to PDF using the following command: If you get an error saying “Please check that pandoc is installed”, you’ll need to install it by: Hiding the Code If you…