python for loop magic

python for loop amazing:

  You can write this statement:

    for i in range(10) :

      j= i**2

      print(j)

  You can also write this statement:

    with open('/path/to/file','r') as f:

      for line in f.readlines():

        print(line.strip())

    This time line is what type? .readline what order to execute?

 

Here is a delimiter ------- -----

 

# Read word document
Import win32com
Import win32com.client

DEF readWordFile (path):
# word calling system functions, can come out doc and docx two file
mw = win32com.client.Dispatch ( "of the Word.Application")
# Open word file
doc = mw.Documents.Open (path)
for paragraphsin in doc.Paragraphs: content extraction cycle #
Line = paragraphsin.Range.text
Print (Line)
# close the file
doc.close
# exit Word
mw.Quit ()

path R & lt = "D: \ learning \ Python \ pycharm \ 234 \ office software \ word read and write \ 2.docx "
readWordFile (path) # read the file


# read word and save the file to another
win32com Import 
Import win32com.client
DEF readWordFile (path, toPath):
mw = win32com.client.Dispatch ( "of the Word.Application")
DOC = mw.Documents.Open (path)
# save the data to another file word
doc. SaveAs (toPath, 2) # 2 is a txt file

doc.close
mw.Quit ()

path R & lt = "D: \ 2.docx"
topath R & lt = "D: (A) .txt"
readWordFile (path, topath) read # file

# However, the above code can not be executed under 3.8 + pyCharm environment, suggesting no win32com module, real pull.

# Page English fonts look good on Chinese crap.
# Today rest, smoke, sleep, tomorrow to continue fighting.

Guess you like

Origin www.cnblogs.com/Noah-Zhu/p/12364397.html