0

我有一个二维列表列表,我需要根据第一个记录字段进行搜索,内容是包含正斜杠字符的字符串。

测试 arg_size 时,如果存在正斜杠字符,则搜索总是失败。为了排除故障,我对参数进行了硬编码。

提前致谢。

# -*- coding: UTF-8 -*-
bolt = {}    # create empty dictionary
thread_geometry = {}    # create empty dictionary

#  variables for record position
size = 0
dia_in = 1
dia_mm = 2
tpi_UNC = 3
pitch_UNC_in = 4
pitch_UNC_mm = 5
tpi_UNF = 6
pitch_UNF_in = 7
pitch_UNF_mm = 8
tpi_UNEF = 9
pitch_UNEF_in = 10
pitch_UNEF_mm = 11

# lookup table for bolt standards,negative values represents NULL
bolt_table = [
        [r"#0", 0.06, 1.524, -1, -1, -1, 80, 0.0125, 0.3175, -1, -1, -1 ],
        [r"#1", 0.073, 1.8542, 64, 0.015625, 0.3969, 72, 0.013888, 0.3528, -1, -1, -1 ],
        [r"#2", 0.086, 2.1844, 56, 0.017857, 0.4536, 64, 0.015625, 0.3969, -1, -1, -1 ],
        [r"#3", 0.099, 2.5146, 48, 0.020833, 0.5292, 56, 0.017857, 0.4536, -1, -1, -1 ],
        [r"#4", 0.112, 2.8448, 40, 0.025, 0.635, 48, 0.020833, 0.5292, -1, -1, -1 ],
        [r"#5", 0.125, 3.175, 40, 0.025, 0.635, 44, 0.022727, 0.5773, -1, -1, -1 ],
        [r"#6", 0.138, 3.5052, 32, 0.03125, 0.7938, 40, 0.025, 0.635, -1, -1, -1 ],
        [r"#8", 0.164, 4.1656, 32, 0.03125, 0.7938, 36, 0.027778, 0.7056, -1, -1, -1 ],
        [r"#10", 0.19, 4.826, 24, 0.041667, 1.0583, 32, 0.03125, 0.7938, -1, -1, -1 ],
        [r"#12", 0.216, 5.4864, 24, 0.041667, 1.0583, 28, 0.035714, 0.9071, 32, 0.03125, 0.7938 ],
        [r"1/4", 0.25, 6.35, 20, 0.05, 1.27, 28, 0.035714, 0.9071, 32, 0.03125, 0.7938 ],
        [r"5⁄16", 0.3125, 7.9375, 18, 0.055556, 1.4111, 24, 0.041667, 1.0583, 32, 0.03125, 0.7938 ],
        [ur"3⁄8", 0.375, 9.525, 16, 0.0625, 1.5875, 24, 0.041667, 1.0583, 32, 0.03125, 0.7938 ],
        [r"7⁄16", 0.4375, 11.1125, 14, 0.071428, 1.8143, 20, 0.05, 1.27, 28, 0.035714, 0.9071 ],
        [r"1⁄2", 0.5, 12.7, 13, 0.076923, 1.9538, 20, 0.05, 1.27, 28, 0.035714, 0.9071 ],
        [r"9⁄16", 0.5625, 14.2875, 12, 0.083333, 2.1167, 18, 0.055556, 1.4111, 24, 0.041667, 1.0583 ],
        [r"5⁄8", 0.625, 15.875, 11, 0.090909, 2.3091, 18, 0.055556, 1.4111, 24, 0.041667, 1.0583 ],
        [r"3⁄4", 0.75, 19.05, 10, 0.1, 2.54, 16, 0.0625, 1.5875, 20, 0.05, 1.27 ],
        [r"7⁄8", 0.875, 22.225, 9, 0.111111, 2.8222, 14, 0.071428, 1.8143, 20, 0.05, 1.27 ],
        [r"1", 1, 25.4, 8, 0.125, 3.175, 12, 0.083333, 2.1167, 20, 0.05, 1.27 ],
        ]



# # # # ------------------- Main -------------------------------------------- # # # #


#  Get bolt parameters
#  if the no value is entered the value will be NULL or set to a default

arg_unit = 'mm'
if arg_unit.lower() == 'mm':
    bolt['unit'] = 'mm'
else:
    bolt['unit'] = 'in'

arg_size = '3/8'
for x in bolt_table:
    if str(x[size]) == str(arg_size):
        bolt['size'] = str(arg_size)

arg_length = 2.5
if arg_length > 0:
    bolt['length'] = arg_length
else:
    sys.stderr.write(" Bolt length is a required field!!!")
    sys.exit()

arg_thread = 'UNC'
if arg_thread.upper() == 'UNC' or arg_thread.upper() == 'UNF' or arg_thread.upper() == 'UNEF':
    bolt['thread'] = arg_thread.upper()

print bolt.viewitems()
4

1 回答 1

1

键盘上的斜线与桌子上的斜线不同。有不同的符号。修改您的表以将 unicode 斜杠替换为 ascii 斜杠或使用如何在 Python 中读取 Unicode 输入和比较 Unicode 字符串的规范化解决方案?

我认为你从网上复制粘贴表格的值)

于 2013-07-28T21:14:53.317 回答