I have a list in Python that stores objects with randomly assigned attributes, and I'm looking to print them in a specific format so that I can do some machine learning. The basic structure is like this:
import random
skills=['python', 'java', 'c++', 'c#']
student_names=['sam', 'tom', 'charlie']
people = []
class person:
skills = []
def __init__(self, skills, name):
self.skills = []
self.name=name[random.randint(0,(len(name))-1)]
self.age=random.randint(20,30)
for i in range(0,2):
self.skills.append(skills[random.randint(0,(len(skills))-1)])
for i in range(0,3):
people.append(person(skills, student_names))
I'd really like to write them to a .txt file so that it looks like this, for example:
sam,python c++,29
charlie,c# java, 22
tom,java python, 21
But every time I try to write to text or print to the console I get an output like this:
sam,[python, c++],29
charlie,[c#, java], 22
tom,[java, python], 21
Any ideas how I can achieve the first output? Thanks very much stack overflow community.