Skip to content

Instantly share code, notes, and snippets.

@ncole458
Created January 14, 2019 02:53
Show Gist options
  • Save ncole458/4f40704b41c595516d17fc8fbda79475 to your computer and use it in GitHub Desktop.
Save ncole458/4f40704b41c595516d17fc8fbda79475 to your computer and use it in GitHub Desktop.
Python Encode
# test .encode() and str()
a_string = 'test éurope'
print('a_string normal: ', a_string)
a_string = 'test éurope'
print('a_string utf-8 encoded: ', a_string.encode('utf-8')) # utf-8 is default so .encode() is same result
print('a_string ascii encoded: ', a_string.encode('ascii', 'replace')) # with error, i.e. replace, ignore etc.
print('a_string str: ', str(a_string))
company = 'éuropean company'
pro_comp_name = 'a løng campaigné name'
report_name = company + " - " + pro_comp_name + ".pdf"
print('report_name: ', report_name)
print(f'report_name: {report_name}')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment