-1

I want to use the variable of a for loop in my main function.

This will throw an error saying x is undefined:

text = 'rough example'
def splitter(text):
    for x in sent_tokenize(text):
        print(x)
        return x

def main():
    x = splitter(text)

main()
Graham
  • 7,431
  • 18
  • 59
  • 84

1 Answers1

0

try adding in the beginning of your code:

import nltk
nltk.download('punkt')

It worked for me... (printing "rough example", no error thrown)

Look here.

noamgot
  • 3,962
  • 4
  • 24
  • 44