You want to download a URL to a file using the requests python library, but you want to skip the download if it doesn’t exist
Use the following functions:
def download_file(filename, url):
Download an URL to a file
with open(filename, 'wb') as fout:
response = requests.get(url, stream=True)
# Write response data to file
for block in response.iter_content(4096):
def download_if_not_exists(filename, url):
Download a URL to a file if the file
does not exist already.
True if the file was downloaded,
False if it already existed
if not os.path.exists(filename):
You have a list of X/Y coordinates, for example:
coords = [(6.74219, -53.57835),
For these coordinates you want to compute the minimum bounding box.
Occasionally I have to clean up some HTML code – mostly because parts of it were pasted into a CMS like WordPress from rich text editor like Word.
I’ve noticed that the formatting I want to remove is mostly based on
div elements with a
style attribute. Therefore, I’ve written a simple Python script based on BeautifulSoup4 which will replace certain tags with their contents if they have a
style attribute. While in some cases some other formatting might be destroyed by such a script, it is very useful for some recurring usecases.
The LP2980–ADJ is a 50 mA LDO that be configured for an output voltage from 1.23V to 15V using a pair of resistors.
The datasheet lists a formula for the output voltage, however no easy-to-use customizable software is provided that can be used to directly compute the correct resistor in a reproducible way. Mehr lesen
The following html code can be used to create an html form that allows uploading multiple files at once:
<form enctype="multipart/form-data" method="POST" action="upload.py">
<table style="width: 100%">
<td>Choose the files to upload:</td>
<td style="text-align: right"><input type="file" multiple="" id="files" name="files"></td>
<td><input id="fileUploadButton" type="submit" value="Upload >>"></td>
In electronics engineering there is a wide variety of notations for values that need to be recognized by intuitive user interfaces. Examples include:
- 4,500.123 A
- 4k0 A
The wide variety of options, including thousands separators, comma-as-decimal-separator and suffix-as-decimal-separator, optional whitespace and scientific notations makes it difficult to normalize values without using specialized libraries. Mehr lesen
You want to calculate the correct value for the Ilim resistor for the NCP380 current limiter IC with a custom current limit. Mehr lesen
You want to find the E24/E48/E96 resistor value that is closest to a given exact value programmatically using python. Mehr lesen
In electronics engineering, from time to time you have to use standard formulas to characterize your circuits. To what extent you need to calculate all parameters most often depends on the requirement.
For example, consider the formula for the -3dB cutoff frequency of a 1st order RC lowpass filter:
Although this equation is fairly simple and most people won’t have any problem solving it for any particular variable in a few seconds, it can serve as a basic example on how to solve an equation symbolically.
One of the easiest ways of performing this task is to use SymPy, a Python library for symbolic mathematics.
Similar to our previously published UniPruot parser, MeSH provides an ASCII format that can easily be parsed using Python.
Just like the UniProt parser, this function yields MeSH entries represented by dictionaries. Example code is included at the bottom of the file.