This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
url = 'http://maps.googleapis.com/maps/api/directions/json' | |
params = dict( | |
origin='Chicago,IL', | |
destination='Los+Angeles,CA', | |
waypoints='Joplin,MO|Oklahoma+City,OK', | |
sensor='false' | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getopt, sys | |
def main(): | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "ho:v", ["help", "output="]) | |
except getopt.GetoptError as err: | |
# print help information and exit: | |
print(err) # will print something like "option -a not recognized" | |
usage() | |
sys.exit(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import getopt | |
import sys | |
argv = sys.argv[1:] | |
opts, args = getopt.getopt(argv, 'x:y:') | |
# list of options tuple (opt, value) | |
print(f'Options Tuple is {opts}') | |
# list of remaining command-line arguments |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
soup = BeautifulSoup(response.text, 'lxml') | |
csrf_token = soup.select_one('meta[name="csrf-token"]')['content'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class dotdict(dict): | |
"""dot.notation access to dictionary attributes""" | |
__getattr__ = dict.get | |
__setattr__ = dict.__setitem__ | |
__delattr__ = dict.__delitem__ | |
mydict = {'val':'it works'} | |
nested_dict = {'val':'nested works too'} | |
mydict = dotdict(mydict) | |
mydict.val |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
os.path.getsize("/path/isa_005.mp3") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
with open('data.json', 'w') as f: | |
json.dump(data, f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
with open( "a.txt" ) as f : | |
print f.readlines() | |
except EnvironmentError: # parent of IOError, OSError *and* WindowsError where available | |
print 'oops' |