Return a List of Files and Folders With Glob in Python

There’s a great library added in Python 3.5 that lets you return a list of filenames and folders called glob, here’s how to use it. Return files and folders in current folder. >>> glob('**') ['scaffolds', 'node_modules', 'yarn.lock', '_config.yml', 'source', 'db.json', 'themes', 'package.json', 'package-lock.json'] Return files and folders recursively >>> glob('**', recursive=True) ['scaffolds', 'scaffolds/post.md', 'scaffolds/page.md', 'scaffolds/draft.md', 'node_modules', '...'] Return only specific type of files recursively >>> glob('*.json', recursive=True) ['db.json', 'package.json', 'package-lock.json'] non-recursively >>> glob('**/*....

<span title='2018-03-29 19:20:39 +0000 UTC'>March 29, 2018</span>&nbsp;·&nbsp;1 min&nbsp;·&nbsp;Franccesco Orozco

HTTP Requests in Python

Before starting lets try HTTP requests with httpbin.org to test multiple HTTP methods with requests and JSON data. We’ll see how to extract data from a JSON-encoded response (e.g. {‘key’: ‘value’}) Install requests library With pipenv (recommended): pipenv install requests With pip: pip install requests GET request Check our IP address: import requests # get request, response is JSON-encoded myIP = requests.get('https://httpbin.org/ip') # extract value from JSON key 'origin' # {'origin': '38....

<span title='2018-02-20 19:52:45 +0000 UTC'>February 20, 2018</span>&nbsp;·&nbsp;2 min&nbsp;·&nbsp;Franccesco Orozco