<shape_names.txt>
airplane
bathtub
bed
bench
bookshelf
bottle
bowl
car
chair
cone
cup
read
使用line.rstrip()
>>> file=open(('/shape_names.txt'))
>>> file
<_io.TextIOWrapper name='/shape_names.txt' mode='r' encoding='ANSI_X3.4-1968'>
>>> a=[line.rstrip() for line in file]
>>> a
['airplane', 'bathtub', 'bed', 'bench', 'bookshelf', 'bottle', 'bowl', 'car', 'chair', 'cone', 'cup', 'curtain', 'desk', 'door', 'dresser', 'flower_pot', 'glass_box', 'guitar', 'keyboard', 'lamp', 'laptop', 'mantel', 'monitor', 'night_stand', 'person', 'piano', 'plant', 'radio', 'range_hood', 'sink', 'sofa', 'stairs', 'stool', 'table', 'tent', 'toilet', 'tv_stand', 'vase', 'wardrobe', 'xbox']
网友评论