0

I have a 2 dimensional list of lists, which I need to search based on the first record field, the content are strings which include the forward slash character.

When testing the arg_size the search always fails if the forward slash character is present. I have hard coded the arguments for troubleshooting purposes.

Thanks in advance.

# -*- 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()
salatwork
  • 15
  • 3
  • When I look at the values in the debugger I see that the value in the list is changed from '3/8' u'3\u20448' . I have tried to prefix the string with both r, u, and ur but I get the same results. – salatwork Jul 28 '13 at 21:06

1 Answers1

1

Slash in your keyboard is not same with slash on your table. There are different symbols. Modify your table to replace unicode slash to ascii slash or use normalization solution from How to read Unicode input and compare Unicode strings in Python?

I think you copy-paste values of table from web)

Community
  • 1
  • 1
eri
  • 3,133
  • 1
  • 23
  • 35
  • Yes I had copied the table from a wikipedia website. I went back and retyped the slashes and the code now works. Thank you. – salatwork Jul 29 '13 at 00:29