Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> sys.getdefaultencoding()
- 'ascii'
- >>> sys.getfilesystemencoding()
- 'mbcs'
- def setencoding():
- """Set the string encoding used by the Unicode implementation. The
- default is 'ascii', but if you're willing to experiment, you can
- change this."""
- encoding = "ascii" # Default value set by _PyUnicode_Init()
- if 0:
- # Enable to support locale aware default string encodings.
- import locale
- loc = locale.getdefaultlocale()
- if loc[1]:
- encoding = loc[1]
- if 0:
- # Enable to switch off string to Unicode coercion and implicit
- # Unicode to string conversion.
- encoding = "undefined"
- if encoding != "ascii":
- # On Non-Unicode builds this will raise an AttributeError...
- sys.setdefaultencoding(encoding) # Needs Python Unicode build !
- >>> sys.getdefaultencoding()
- 'utf-8'
- from BeautifulSoup import BeautifulStoneSoup
- soup = BeautifulStoneSoup(urllib2.urlopen(URL),
- convertEntities=BeautifulStoneSoup.ALL_ENTITIES)
- import sys
- sys.setdefaultencoding('utf-8')
Add Comment
Please, Sign In to add comment