from os.path import join def decode(string): """ decode string with utf if possible """ try: return string.decode("utf8", "replace") except: return string if sys.getfilesystemencoding().startswith('ANSI'): def fs_encode(string): try: string = string.encode('utf-8') finally: return string fs_decode = decode #decode utf8 else: fs_encode = fs_decode = lambda x: x # do nothing def save_join(*args): """ joins a path, encoding aware """ return fs_encode(join(*[x if type(x) == unicode else decode(x) for x in args])) filepath = save_join("MyDir", "%(season)02dx%(episode)02d - %(name)s" % \ {'season': 1, 'episode': 1, 'name': "myName" }) filepath = save_join("MyDir", "") print filepath copyToShows = True copyT = True if copyToShows and copyT: print "Yes"
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question