python 我发现Crystal Reports创建的CSV文件具有双引号字段,其中一些字段在引号之间包含逗号。我们不想

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 我发现Crystal Reports创建的CSV文件具有双引号字段,其中一些字段在引号之间包含逗号。我们不想相关的知识,希望对你有一定的参考价值。

def splitStringWithBadlyFormedCSV(aString):
    """
    Return list of fields in aString, splitting by commas while ignoring 
    commas that appear within double-quoted strings.
    """
    ignore = False
    splices = list()
    anchor = 0
    for cursor in range(len(aString)):
        character = aString[cursor]
        # Flag toggles each time it encounters a double quote.
        ignore = not ignore if character == '"' else ignore
        if character == ',' and not ignore:
            splices.append((anchor, cursor))
            # We want to drop anchor 1 past the comma.
            anchor = cursor + 1
    # Last field.
    splices.append((anchor, len(aString)))
    # Now we can strip out the stupid double quotes in each field.
    fields = [aString[start: end].replace('"', '') for start, end in splices]
    return fields
    

以上是关于python 我发现Crystal Reports创建的CSV文件具有双引号字段,其中一些字段在引号之间包含逗号。我们不想的主要内容,如果未能解决你的问题,请参考以下文章

Crystal Reports bobj未定义VS 2012和Windows 10

会用水晶报表crystal reports的请进

Crystal Reports并列数据比较

Crystal Reports中的条件总和?

使用Crystal Reports ReportDocument

解决正确案例Crystal Reports