Python 2.7을 사용하여 print 문에서 대괄호를 제거하려고합니다. 여러 포럼에서 제안을 시도했지만 기대했던대로 작동하지 않았습니다.Python 2.7에서 대괄호와 따옴표를 제거하는 방법
코드 :
with open('buttonpress_and_commandstarted','r') as buttonpress_commandstarted:
for line in buttonpress_commandstarted:
button_press_command_time = ''
if os.path.getsize('buttonpress_and_commandstarted') > 0:
button_press_command_time = line.split()[2]
else:
print " > Cannot get time stamp as the file is empty"
button_press = re.findall(r"\:12\:(.*?)\.",line)
command_executed = re.findall(r"\:4\:(.*?) started\.",line)
with open('timestamp_buttons_and_commands', 'w') as timestamp_buttons_and_commands:
timestamp_buttons_and_commands.write(str(button_press_command_time) + str(button_press) + str(command_executed))
with open("timestamp_buttons_and_commands", "r+") as timestamp_buttons_and_commands:
contents = timestamp_buttons_and_commands.readlines()
from string import join
result = ''.join(contents)
print result
내가 뭘해야 다음과 같은 출력
00:22:12['Button 9 pressed'][]
00:22:13['Button 9 pressed'][]
00:22:14['Button 9 pressed'][]
00:22:15['Button 9 pressed'][]
00:22:15[]['Command MediaCodec (2)']
00:22:17['Button 9 pressed'][]
00:22:19['Button 9 pressed'][]
00:22:19[]['Command SetSensorFormat (3)']
00:22:22[]['CDC']
00:22:22[]['Command Hello']
00:22:22[]['Command Hello']
00:22:22[]['Command Hello']
00:22:22[]['Command Hello']
00:22:22[]['Command Hello']
00:22:25['Button 10 pressed'][]
를 얻을 누구인지 실수 확실하지 않다 그러나 나는
일반 팁 : 코드 –
의 중간에 망가 가져 오기 모듈은 물론 당신의 문제가 무엇인지 분명하지 않다 당신에게 @TimCastelijns – user89
감사합니다 - 당신이 아래의 코드를 줄일 수 [최소 예] (http://stackoverflow.com/help/mcve) 입력과 예상 및 실제 출력을 제공합니까? – jonrsharpe