AttributeError: 'str' object has no attribute 'next'
1
0
Entering edit mode
9.6 years ago
Renesh ★ 2.2k

For the following code in python, I am getting the error--AttributeError: 'str' object has no attribute 'next'

InFile = open(GffFile, 'rU')
    i = 1
    for line in InFile:
        print line
        if line.startswith("#"):                                 
            line.next()

Where is the error in code?

Please help me to solve issue.

python • 17k views
ADD COMMENT
2
Entering edit mode
9.6 years ago

The method next() is used when a file is used as an iterator. This method returns the next input line, or raises StopIteration when EOF is hit. You should call next() on file object and not the line (string). In your case it should be line = InFile.next() and not line.next()

ADD COMMENT
0
Entering edit mode

Thanks a lot. This works!!!

ADD REPLY

Login before adding your answer.

Traffic: 2241 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6