Найти - Пользователи
Полная версия: Повторение той же функции?
Начало » Python для новичков » Повторение той же функции?
1 2
Fibio
переменная text8 - нигде не определена а вы ее в search_replace передаете
e1maker
Fibio
переменная text8 - нигде не определена а вы ее в search_replace передаете
спасибо, ступил, все работает

def search_replace(file, find_str, replace_str):
app.Documents.Open(file)
app.Selection.Find.Text = find_str
found=app.Selection.Find.Execute()
doc=app.ActiveDocument
if found:
app.Selection.TypeText(replace_str)
doc.SaveAs(os.getcwd()+'\\pension.doc')
else:
doc.Close(SaveChanges=False)
return found
f= 'C:\\1.doc'
search_replace(f, 'text1', text1)
search_replace(f, 'text8', text8)
search_replace(f,'text9', text9)
app.Application.Quit(-1)
e1maker
Fibio
переменная text8 - нигде не определена а вы ее в search_replace передаете
спасибо, ступил, все работает

def search_replace(file, find_str, replace_str):
app.Documents.Open(file)
app.Selection.Find.Text = find_str
found=app.Selection.Find.Execute()
doc=app.ActiveDocument
if found:
app.Selection.TypeText(replace_str)
doc.SaveAs(os.getcwd()+'\\pension.doc')
else:
doc.Close(SaveChanges=False)
return found
f= 'C:\\1.doc'
search_replace(f, 'text1', text1)
search_replace(f, 'text8', text8)
search_replace(f,'text9', text9)
app.Application.Quit(-1)
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB