Reputation: 11
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'
Upvotes: 1
Views: 2397
Reputation: 1439
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(',')
Upvotes: 0
Reputation: 117946
Change this
dataLine = string.split(line[:-1], ',')
to this
dataLine = line[:-1].split(',')
Upvotes: 1