E.W
E.W

Reputation: 47

name 'split' is not defined issue

I have this code snippet that do some basic calculation on two text files. My code:

with open('one.txt', 'r') as one, open('two.txt', 'r') as two:
    next(two) # skip first line in two.txt
    for line_one, line_two in zip(one, two):
        one_a = int(split(line_one, ",")[0])
        two_b = int(split(line_two, " ")[1])
        print(one_a - two_b)

I am getting the following error:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    one_a = split(line_one, ",")[0]
NameError: name 'split' is not defined

I have no idea why, help would be much appreciated!

Upvotes: 2

Views: 8584

Answers (1)

Shobi
Shobi

Reputation: 11491

split function can't be used like this, you should use "some string".split(' ');

so your code should be

one_a = int((line_one.split(",")[0])
two_b = int(line_two.split(" ")[1])

Upvotes: 2

Related Questions