Home > other >  Prompt list index out of range and reason
Prompt list index out of range and reason

Time:10-10

Want to written in python, because of work requirements, a small extract word file content to Excel program, learn some of the code from the Internet, with the next tip

List index out of range error, check the list of cross-border errors, but because people could not weak code to check the specific problem, also the crawler great god please help help to solve! Thank you care!

The import OS
The import win32com
The from win32com. Client import Dispatch, constants
The from docx import Document

Def parse_docx (f) :
"" "read docx, return name and industry
"" "
D=Document (f)
T=which ables [0]
T_next=which ables [1]
# title=tc ell (0, 1). The text//such as the title in the table is located in the (0, 1)
Company_name=tc ell (1, 1). The text # 1
Tax_num=tc ell (1, 3). The text # 1
Reg_address=tc ell (2, 1). The text # 1
Tel=tc ell (2, 3). The text # 1
Bank_name=tc ell (3, 1). The text # 1
Bank_Account=tc ell (3, 3). The text # 1
Send_address=tc ell (4, 1). The text # 1
Receiver_tel=tc ell (4, 3). Text# 1

# Other=t_next. Cell (1, 1). The text
Print (Company_name, Tax_num Reg_address, Tel, Bank_name, Bank_Account, Send_Account, Receiver_tel, end='\ n')


"' the above function main implementation file read '"'
If __name__=="__main__" :
W=win32com. Client. Dispatch (' Word. Application)

# traverse the file
PATH="D: \ \ worktest \ " # Windows file PATH
Doc_files=OS. Listdir (PATH)
For doc in doc_files:
If OS. Path. Splitext (doc) [1]=='docx' :
Try:
Parse_docx (PATH + '\ \' + doc)
Except the Exception as e:
Print (e)
 


To extract the file is in the picture document form inside, want to have more than a similar word file content into a Excel file. Please great god myself!!!!!!


CodePudding user response:

please advise!

CodePudding user response:

Error message stick, error message which line is wrong

CodePudding user response:

refer to the second floor dabingsou response:
error message stick, error which line the wrong


No one line is only a mistake sent the

CodePudding user response:

List index out of range

An error message, the index beyond,
General questions such as, above the line in the error message to add an if judgment can solve,

CodePudding user response:

reference KaiserChen8273 reply: 3/f
Quote: refer to the second floor dabingsou response:

Error message stick, error message which line the wrong


No one line is only a mistake sent the

Single pace, to see which step error

CodePudding user response:

The
yellow elder brother Python training reference 4 floor response:
list index out of range

An error message, the index beyond,
General questions such as, above the line in the error message to add an if judgment can solve,


A great god whether it can guide with my code?? Thank you very much!
  • Related