# my Python script
# to create script file
#!/usr/bin/env python#-*-coding:utf-8-*-ImportOs,subprocesschild= subprocess. Popen ('which Python', stdout = subprocess. Pipe,shell=True) (Pypath,error)=child.communicate () Pypath= Pypath.strip ('\ n') MyFile= Raw_input ('Please input the file name (like home/test.py)') (Path,filename)=os.path.split (myfile)ifPath:Print 'Check dir path ...' ifos.path.exists (path):Print 'dir already exists!' Else: Print 'dir:%s does not exist!'%PathPrint 'Create dir:%s ...'%PathTry: Os.makedirs (path)Print 'dir:%s is created successfully!'%PathexceptException, E:Print 'exception occur while try to create dirs%s'%PathPrinteElse: PassPrint 'Create script file:%s ...'%filenameTry: F= Open (MyFile,'W') F.write ('#!'+ Pypath +'\ n') F.write ('#!-*-coding:utf-8-*-') F.write ('\ n') F.write ('\ n') F.write ('if __name__ = ='+"' __main__ ': \ n") F.write ('print "Hello world!" \ n') F.close ()Print 'script is created successfully!'exceptexception,e:Print 'exception occur while try to write file:%s'%filenamePrintE
# Victor
My Python script (1)---------Create model script file