TypeError: split () missing 1 required positional argument: 'string'

1

One more basic question on my part. I am 'Pythonista' super basic level and am trying to simply read a text line by line and make a split each time I find a punctuation mark or a space.

I tried this:

import re

with open('est.txt', 'r') as f: 
for ligne in f: 
    ligne=re.split('; |, |\s|\.|\n') 
    print (ligne)

I just got the following error:

Traceback (most recent call last):
File "C:/Users/Janaina/Desktop/exo/stats_python/estpy.py", line 5, in <module> ligne=re.split('; |, |\s|\n')
TypeError: split() missing 1 required positional argument: 'string'

Can anyone help me? I know it's something super basic, but I've been blocked for some time looking for the answer ...

    
asked by anonymous 16.10.2016 / 13:03

1 answer

1

The re.split function should receive at least two arguments, the regular expression and the string where you will apply it. You are only reporting the regular expression.

Maybe this is what you want to do:

import re

with open('est.txt', 'r') as f: 
    for ligne in f: 
        ligne = re.split('; |, |\s|\.|\n', ligne) 
        print (ligne)
    
16.10.2016 / 14:09