AttributeError:' NoneType'对象没有属性'追加'同时附加在列表中

时间:2017-02-27 08:45:05

标签: python

我尝试了类似问题中提出的不同解决方案,但我不知道他们为什么不为我工作。如果你帮助我,我将非常感激。下面是初始代码。我想为6个不同的属性生成1 mil记录并将其导出为csv,但我无法在列表中保存随机生成的值。

import string
import random
import csv
#choice_list
os_version = ['release 5.7', 'release 5.1', 'release 6.7']
os_name = ['Linux', 'HP/UX', 'AIX', 'SunOS']
#output
id_gen = []
ram_gen = []
name_gen = []
sn_gen = []
osn_gen = []
osv_gen = []

def id_generator(size=32, chars=string.ascii_lowercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

def name_generator(size=32, chars=string.ascii_uppercase):
    return ''.join(random.choice(chars) for _ in range(size))

def serial_number_generator(size=16, chars=string.ascii_uppercase + string.digits):
    return ''.join(random.choice(chars) for _ in range(size))

def os_name_generator():
    return random.choice(os_name)

def os_version_generator():
    return random.choice(os_version)

def ram_generator():
    return 2048



for _ in range(0, 10):
    #print('{}\t{}\t{}\t{}\t{}\t{}'.format(id_generator(), ram_generator(), name_generator(), serial_number_generator(), os_version_generator(), os_name_generator()))
    id_gen = id_gen.append(id_generator())
    ram_gen = ram_gen.append(ram_generator())
    name_gen = name_gen.append(name_generator())
    sn_gen = sn_gen.append(serial_number_generator())
    osn_gen = osn_gen.append(os_version_generator())
    osv_gen = osv_gen.append(os_name_generator())

0 个答案:

没有答案