วิธีรัน
1.เข้า Terminal ด้วยสิทธิ์ Root
2.เมื่อสร้างไฟล์เสร็จให้ทำการเปลี่ยนไฟล์ให้ execute ได้ ด้วย
chmod +x genword.py
3. รันด้วยคำสั่ง
./genword.py -f <fileName.txt> -n <line Of Number> -w <word Generate>
#!/usr/bin/python ###################################################### #____________________________________________________# #_______________Mr.Pornmongkon Pongsai_______________# #________________Computer Engineering________________# #_____________Generate Word for Project______________# #____________Create Date : 28 April 2015_____________# #____________________________________________________# ###################################################### import sys import getopt def main(argv): fileName = 'default' lineNumber = 0 wordGen = 'default' try: opts, args = getopt.getopt(argv,"hf:n:w:",["file=","number=","word="]) except getopt.GetoptError: print 'Help : genword.py -f-n -w ' sys.exit(2) for opt, arg in opts: if opt == '-h': print 'Help : genword.py -f -n -w ' sys.exit() elif opt in ("-f", "--file"): fileName = arg elif opt in ("-n", "--number"): lineNumber = int(arg) elif opt in ("-w", "--word"): wordGen = arg print '[log] : generate word start!' dataFile = open(fileName, 'w') i = 0 while ( i < lineNumber ): dataFile.write(wordGen+'\n') i = i + 1 dataFile.close() print '[log] : generate word finish!' if __name__ == "__main__": print '######################################################' print '#____________________________________________________#' print '#_______________Mr.Pornmongkon Pongsai_______________#' print '#________________Computer Engineering________________#' print '#_____________Generate Word for Project______________#' print '#____________Create Date : 28 April 2015_____________#' print '#____________________________________________________#' print '######################################################' print '!!!-h for help!!!' main(sys.argv[1:])