• python生成.h和.m文件


    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

  • 相关阅读:
    ORA01033:ORCLE initialization or shutdown in progress问题的解决
    OA、SOA和SOAP
    [导入]循环赛如何排列问题
    [导入]Free Compilers / Interpreters
    终于知道纹理的GL_MODULATE是怎么回事了
    怎么acm.tongji.edu.cn又关机了?
    [导入]一个2002罗马尼亚赛区的ACM的题目
    netcraft at tongji.edu.cn
    [导入]对编写安全的代码这个方法有用吗?
    [导入]最简单的方法输出下列图形
  • 原文地址:https://www.cnblogs.com/wodehao0808/p/12673429.html
Copyright © 2020-2023  润新知