我有大约1000个文件名读取os.listdir(),其中一些以UTF8编码,一些是CP1252.
我想将它们全部解码为Unicode,以便在我的脚本中进一步处理.有没有办法让源编码正确解码为Unicode?
例:
for item in os.listdir(rootPath):
#Convert to Unicode
if isinstance(item, str):
item = item.decode('cp1252') # or item = item.decode('utf-8')
print item
Run Code Online (Sandbox Code Playgroud) 有没有办法在添加哈希表时保持键的顺序?像推/弹机制一样.
例:
$hashtable = @{}
$hashtable.Add("Switzerland", "Bern")
$hashtable.Add("Spain", "Madrid")
$hashtable.Add("Italy", "Rome")
$hashtable.Add("Germany", "Berlin")
$hashtable
Run Code Online (Sandbox Code Playgroud)
我想保留我将元素添加到哈希表的顺序.