1

When I run the following code (from chapter 19 of Introduction to Computation and Programming Using Python by John Guttag):

dataFile = open(fName, 'r')
    for line in dataFile:
        dataLine = string.split(line[:-1], ',')

I receive the following error:

error message:module 'string' has no attribute 'split'
1
  • That must be a really old book. In Python 2, the string.split function has been deprecated in favour of the str type's .split method for ages. Commented Oct 24, 2017 at 19:12

2 Answers 2

1

Change this

dataLine = string.split(line[:-1], ',')

to this

dataLine = line[:-1].split(',')
Sign up to request clarification or add additional context in comments.

Comments

0

You don't define the string anywhere. It shouldn't work on python 2 or 3. You might want two ::, but that's for you to find out.

dataFile = open(fName, 'r')
    for line in dataFile:
        dataLine = line[:-1].split(',')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.