#やりたいこと
数値のプラスとマイナスを判定しテキストにアウトプットしたいと考えています。
-62, -32, 22, 52, -42
完成形
00110
#試したこと
with open('array.txt') as file: filedata = file.read() filedata = filedata.replace('e-0', '') filedata = filedata.replace(' ', ', ') with open(r'array.txt', 'w', encoding='utf-8') as file: file.write(filedata) with open('array.txt') as file: number = file.read() int_list = map(int, number) num_list = list(int_list) output = [] for value in num_list: if value > 0: output.append('1') else: output.append('0') with open(r'number.txt', 'w', encoding='utf-8') as file: file.write(output)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-57-11d5f6dcd74f> in <module> 20 number = file.read() 21 int_list = map(int, number) ---> 22 num_list = list(int_list) 23 24 output = [] ValueError: invalid literal for int() with base 10: '-'
#環境
python 3.6.7
numpy 1.15.4
ubuntu 18.04
回答2件
あなたの回答
tips
プレビュー