2

Below is the code while running the code, getting an AttributeError: 'NoneType' object has no attribute 'format'.

import csv
import numpy
def loadCsv(filename):
    lines = csv.reader(open(filename,"r"))
    dataset = list(lines)
    for i in range(len(dataset)):
        dataset[i] = [float(x) for x in dataset[i]]
    return dataset
filename = 'data1.csv'
dataset = loadCsv(filename)
print('Loaded data file {0} with {1} rows').format(filename, len(dataset))
2
  • 3
    print('Loaded data file {0} with {1} rows').format(filename, len(dataset)) should be print('Loaded data file {0} with {1} rows'.format(filename, len(dataset))) - format is a string method. Commented Sep 13, 2018 at 11:27
  • The trace stack should say what object is NoneType, which is something you should have included in your question. Commented Sep 14, 2018 at 17:11

1 Answer 1

1

change this

print('Loaded data file {0} with {1} rows').format(filename, len(dataset))

to this

print('Loaded data file {0} with {1} rows'.format(filename, len(dataset)))

you get the error because you try to apply .format to the print-function, whereas it is a method which needs to be applied to a string.

Sign up to request clarification or add additional context in comments.

4 Comments

Extra parentheses must be added to the print statement.
this is not true!
Check that out once extra parentheses must be added for sure.
More precisely, print is a function that returns None. If had returned a string, this error wouldn't appear.

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.