import random import os import string first = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" second = "abcdefghijklmnopqrstuvwxyz" number = "345" index = 0 array = [] #for i in range(500): for i in range(30): final=(random.choice(first)) index = random.randint(3, 5) for i in range(index): final+=(random.choice(second)) final += (random.choice(first)) for i in range(index): final+=(random.choice(second)) array.append(final) print (array) # -*- coding: utf-8 -*- # .h def text_createH(fileNmae,msg,msg1,propertyNumber,methodArray,msg3): full_path = 'G:/py_ios_test/t/' + fileNmae + '.h' file = open(full_path, 'w') #file.write('// // '+fileNmae+'.h // SajiaoShopping ') file.write('// // '+fileNmae+'.h // ') file.write(msg) file.write(msg1) propryNameArray = [] for index in range(1,propertyNumber): propryNameArray.append(random.choice(array)) propryNameArray = list(set(propryNameArray)) for propertyName in propryNameArray: file.write('@property(nonatomic,strong)'+random.choice(classArray)+' * '+propertyName+'; ') file.write(' ') for methodName in methodArray: file.write('- (void)pushTo'+methodName+'VC:(NSDictionary *)info; ') file.write(msg3) file.close() print('Done') # .m def text_createM(fileNmae,msg,msg1,methodArray,msg3): full_path = 'G:/py_ios_test/t/' + fileNmae + '.m' file = open(full_path, 'w') #file.write('// // '+fileNmae+'.h // SajiaoShopping ') file.write('// // '+fileNmae+'.h // ') file.write(msg) file.write(msg1) for methodName in methodArray: file.write('- (void)pushTo'+methodName+'VC:(NSDictionary *)info { NSMutableArray *array = [NSMutableArray array]; ') number = random.randint(3, 10) for i in range(1,number): file.write(' [array addObject:@"'+random.choice(array)+'"]; ') file.write(' } ') file.write(msg3) file.close() print('Done') classArray = ['NSString','UILabel','NSDictionary','NSData','UIScrollView','UIView'] #array = ['HwxrFvrj', 'QnzduQbtdd', 'PvcrwLtqhf', 'UvdhDbjn', 'SuntmyTxvyzg', 'CvlxwBipbp', 'GzrdyzIbimvz', 'CqsjqMmgsp', 'OxaaeuWjhasc', 'NjiardRvwgbi', 'NcculmLtpljq', 'ApoqQrll', 'GkgokDyvjb', 'EblldkVouplj', 'KfdrFvnw', 'SfhyhObftc', 'SmruByoc', 'YzcccvXmpmit', 'OmqvaHpxat', 'XzytsUyvyd', 'MjforNnnyi', 'ZvjhuIdogs', 'BzfrxzSeahxc', 'PycycwFjtpny', 'XvngtoSedljr', 'DktiaCbucd', 'AqbplNuodc', 'MzkvgZuala', 'KdwzIoej', 'AaynatUpqcfd', 'IyvwhZvtjc', 'UmijGmsy', 'AoayndXxghym'] array = list(set(array)) for name in array: number = random.randint(3, 10) methodArray = [] for i in range(1,5): methodArray.append(random.choice(array)) methodArray = list(set(methodArray)) #zname = name + 'ViewController' zname = name + 'VCtr' text_createH(zname, '#import <UIKit/UIKit.h> ','@interface '+zname+ ':'+ 'UIViewController ',number,methodArray,' @end') text_createM(zname, '#import "'+zname+'.h" ' '@interface '+ zname+'() @end ','@implementation '+zname+' - (void)viewDidLoad { [super viewDidLoad]; } ',methodArray,' @end')
参考地址:https://blog.csdn.net/u013857988/article/details/79582697#comments