python csv list separator based on regional settings

前端 未结 3 1718
臣服心动
臣服心动 2021-01-12 03:48

how to detect list separator in users machine with Python?

CSV file needs to be created on users machine and the list separator must be detected automatically (so th

3条回答
  •  时光取名叫无心
    2021-01-12 04:18

    • How to read 'List separator' from OS in Java?

    Provided the idea to read the list separator symbol from the Windows registry.

    • Python code to read registry

    Provided the code to access Windows Registry values.

    Using the _winreg package, the Windows list separator value can be retrieved from the registry as follows:

    from _winreg import *
    
    def getListSeparator():
        '''Retrieves the Windows list separator character from the registry'''
        aReg = ConnectRegistry(None, HKEY_CURRENT_USER)
        aKey = OpenKey(aReg, r"Control Panel\International")
        val = QueryValueEx(aKey, "sList")[0]
        return val
    
    print getListSeparator()
    

提交回复
热议问题