I got this error in python TypeError: 'NoneType' object is not subscriptable
Question:
I have a code that is supposed to take a link from a docx file and download it , The name of the file in witch the code is supposed to take the link from is One.docx. And than i have "take = doc.paragraphs[0].text " witch is supposed to take the first link from the docx file. But it gives my the "TypeError: ‘NoneType’ object is not subscriptable." error. Here is my code
import docx
name_of_file = "One.docx"
doc = docx.Document(name_of_file)
take = doc.paragraphs[0].text
url = print(take)[:-1]+".json"
Answers:
The error is produced by the last line because print(stuff)
returns None
, so print(stuff)[other stuff]
is invalid. print
should not be in your last line at all if you are trying to construct a url string from another string.
I have a code that is supposed to take a link from a docx file and download it , The name of the file in witch the code is supposed to take the link from is One.docx. And than i have "take = doc.paragraphs[0].text " witch is supposed to take the first link from the docx file. But it gives my the "TypeError: ‘NoneType’ object is not subscriptable." error. Here is my code
import docx
name_of_file = "One.docx"
doc = docx.Document(name_of_file)
take = doc.paragraphs[0].text
url = print(take)[:-1]+".json"
The error is produced by the last line because print(stuff)
returns None
, so print(stuff)[other stuff]
is invalid. print
should not be in your last line at all if you are trying to construct a url string from another string.