0

在 Python 中使用 CSV Schema 包,并且正在使用许多登记值验证字符串列。问题是no permissible values found即使它们在那里,包也会给出错误。我仔细检查了一遍。

有任何想法的人吗?

代码在我定义规则的地方剪断:

# -*- coding: utf-8 -*-
# wrapper to work with csv files in python 
import codecs, ucsv as csv, unicodedata, sys, os
# opening an output file with write access, change to rw+ if working with linux
fo = open("C:/Users/Romi/Desktop/Level1Test/result.txt", "r+") 
# Open the feeds here, use os.walk for running through directory.
from csv_schema.structure.base import BaseCsvStructure
from csv_schema.columns import (
  IntColumn,
  DecimalColumn,
  StringColumn,
)

class TestCsvStructure(BaseCsvStructure):
  a = StringColumn(blank = True, min_length = 0, max_length = 12345,)
  b = StringColumn(blank = True, min_length = 0, max_length = 12345,)
  c = StringColumn(blank = True, min_length = 0, max_length = 12345, permissible_values = ["Null","Male","Female","Unknown"])
  d = StringColumn(blank = True, min_length = 0, max_length = 12345,permissible_values = ["No","Yes"])
  e = StringColumn(blank = True, min_length = 0, max_length = 12345,permissible_values = ["Inactive", "Active"])

我得到的结果/错误是:

False,u'第 309 行,第 0 列:值不是可接受的之一',u'第 309 行,第 1 列:值不是可接受的之一',......

从结果.txt:

309 line : [u'Line 309, column 2: The value is not one of the acceptable', u'Line 309, column 3: The value is not one of the acceptable', u'Line 309, column 4: The value is not one of the acceptable', u'Line 309, column 5: The value is not one of the acceptable', u'Line 309, column 6: The value is not one of the acceptable', u'Line 309, column 7: The value is not one of the acceptable', u'Line 309, column 8: The value is not one of the acceptable', u'Line 309, column 9: The value is not one of the acceptable', u'Line 309, column 10: The value is not one of the acceptable', u'Line 309, column 11: The value is not one of the acceptable', u'Line 309, column 12: The value is not one of the acceptable', u'Line 309, column 13: The value is not one of the acceptable', u'Line 309, column 14: The value is not one of the acceptable', u'Line 309, column 15: The value is not one of the acceptable', u'Line 309, column 16: 
    ...
    False

它显示第 47 列和第 48 列没有可接受的值,但它们显然有。在允许的值中,我粘贴了“[u'value']”,它可以识别除这两个之外的其他值。

4

0 回答 0