Skip to content Skip to sidebar Skip to footer

Remove Parenthesis And Text In A File Using Python

I have a text file that contains something like this: Cl1 Cl 0.21988(6) 0.2500 0.15016(5) 0.01587(14) Uani 1 2 d S T P . . O1 O 1.05820(17) 0.2500 0.48327(16) 0.0206(3) Uani 1 2 d

Solution 1:

output = re.sub('\(\w*\)', '', input)

EDIT:

There's a mistake in the code you recently put: you are not assigning the result of the re.sub function. Change re.sub(...) for line = re.sub(...).

Solution 2:

import re

withopen('file') as f:
    input = f.read()
    output = re.sub(r'\(\w*\)', '', input)

Post a Comment for "Remove Parenthesis And Text In A File Using Python"