Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 无法将字符串与带有'/';性格_Python_String_List - Fatal编程技术网

Python 无法将字符串与带有'/';性格

Python 无法将字符串与带有'/';性格,python,string,list,Python,String,List,我有一个二维列表,需要根据第一个记录字段进行搜索,内容是包含正斜杠字符的字符串 测试arg_大小时,如果存在正斜杠字符,则搜索总是失败。为了排除故障,我对参数进行了硬编码 提前谢谢 # -*- coding: UTF-8 -*- bolt = {} # create empty dictionary thread_geometry = {} # create empty dictionary # variables for record position size = 0 dia

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

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

提前谢谢

# -*- 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()

键盘上的斜杠与桌面上的斜杠不同。有不同的符号。 修改表以将unicode斜杠替换为ascii斜杠,或使用


我认为您从web复制了表的粘贴值)

当我查看调试器中的值时,我看到列表中的值已从“3/8”u'3\u20448”更改。我尝试在字符串前面加上r、u和ur,但得到的结果是相同的。是的,我从维基百科网站复制了这个表。我返回并重新键入斜杠,代码现在可以运行了。非常感谢。