# 1 # #获取输入值
1 a = Raw_input (" Please enter:")2if a = = str (1):3 print"success"4Else: 5 Print " Failure "
# 2 # #利用sys获取脚本文件的当前路径
1 ImportSys,os2 defCur_file_dir ():3Path = Sys.path[0]#Get Script Path4 #Determine whether the script file or Py2exe compiled file, if it is a script file, the script is returned to the directory5 #, the compiled file path is returned if it is a py2exe compiled file6 ifOs.path.isdir (path):7 returnPath +"1"8 elifos.path.isfile (path):9 returnOs.path.dirname (PATH) +"2"Ten PrintCur_file_dir ()#Print Results
# 3 # #利用os获取脚本文件的当前路径
1 Import OS 2 homedir = os.getcwd ()3print homedir
# # 4 # #获得模块的属性, classes, functions and other information.
1 # # Once obtained, the parameters and other sub-information are displayed when called in arcpy 2 Import arcpy 3 Shppath = R"a.shp"4 rows = arcpy. Updatecursor (Shppath)5 for in dir (rows):6 Print I
# # 5 # #编码错误. ASCII to Unicode Method:
1 unicode1 = u'ascii1'
# 6 # #遍历文件夹下的文件
1 index = 02for in os.walk (srcpath):3 for inch FS: 4 if f[-4:]==". SHP":5 index = index +1
Examples Show
D-Plate
Folder: Path folder
D1 folder
F1.txt
D2 folder
F2.txt
F3.txt
F4.txt
For R,ds,fs in Os.walk (path):
First loop R = Path Folder ds for path under Folder List (D1,D2) fs for path under File list (F3,F4)
Second loop R = D1 Folder ds for NULL FS for D1 under File list (F1)
Third Loop R = D2 folder DS for NULL FS for D2 under File list (F2)
Python common functions (i)