Answers for "yaml files in python"

4

python read yaml

# read_categories.py file

import yaml

with open(r'E:datacategories.yaml') as file:
    documents = yaml.full_load(file)

    for item, doc in documents.items():
        print(item, ":", doc)
Posted by: Guest on March-25-2020
4

python write yaml

import yaml

dict_file = [{'sports' : ['soccer', 'football', 'basketball', 'cricket', 'hockey', 'table tennis']},
{'countries' : ['Pakistan', 'USA', 'India', 'China', 'Germany', 'France', 'Spain']}]

with open(r'E:datastore_file.yaml', 'w') as file:
    documents = yaml.dump(dict_file, file)
Posted by: Guest on March-25-2020
0

how to download file in python

import urllib2

filedata = urllib2.urlopen('http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg')
datatowrite = filedata.read()
 
with open('/Users/scott/Downloads/cat2.jpg', 'wb') as f:
    f.write(datatowrite)
Posted by: Guest on March-16-2020
0

how to download file in python

import urllib.request

print('Beginning file download with urllib2...')

url = 'http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg'
urllib.request.urlretrieve(url, '/Users/scott/Downloads/cat.jpg')
Posted by: Guest on March-16-2020

Python Answers by Framework

Browse Popular Code Answers by Language