If you need to call some external files or export files in the script, you need to get the file path, etc., you need to open the file selection window. This describes how to call the Maya window to select the file and get the file path
Related documents
Document: http://help.autodesk.com/view/MAYAUL/2019/CHS/?guid=__CommandsPython_index_html , select fileMode
Official routine
import maya.cmds as cmds
basicFilter = "*.mb"
cmds.fileDialog2(fileFilter=basicFilter, dialogStyle=2)
singleFilter = "All Files (*.*)"
cmds.fileDialog2(fileFilter=singleFilter, dialogStyle=2)
multipleFilters = "Maya Files (*.ma *.mb);;Maya ASCII (*.ma);;Maya Binary (*.mb);;All Files (*.*)"
cmds.fileDialog2(fileFilter=multipleFilters, dialogStyle=2)
My use
There are two types in the document, fileDialog and fileDialog2, and fileDialog2 is used here
as follows
import maya.cmds as cmds
basicFilter = "*.txt"
path = cmds.fileDialog2(fileFilter=basicFilter, dialogStyle=2, fileMode=0)
print path