Print a list of objects as string in Python

Asked

Viewed 2,870 times

1

I am making a program in python(2,7) where I take texts from a file,and storing as objects in a list, I would like to print the list but only returns the addresses, I am learning to program in python and no answer I find for it serves me. How can I print this as a string?

Example of the file:(I don’t know how to leave in the correct format but between the spaces there is a tab) 3 s 43-12 31

Class that functions as a struct:

class Expressao(object):

def __init__(self, nivel, tipo, expressao, resposta):
    self.nivel = nivel
    self.tipo = tipo
    self.expressao = expressao
    self.resposta = resposta

Class that takes the file and stores it in a list as objects:

class FonteDeExpressoes(object):
import csv
def lista (self):
    expressoes = []
    with open('exp.txt') as f:
        for line in f:
            row = line.split('\t')
            exp = Expressao(row[0], row[1], row[2], row[3])
            expressoes.append(exp)
    #print expressoes
    return expressoes

Output from Print Fontedeexpressions(). list()

[<__main__.Expressao object at 0x7f09343ad710>, <__main__.Expressao object at 0x7f093b7e25d0>, <__main__.Expressao object at 0x7f093b7e2e90>, <__main__.Expressao object at 0x7f0934017050>, <__main__.Expressao object at 0x7f0934017090>, <__main__.Expressao object at 0x7f09340170d0>, <__main__.Expressao object at 0x7f0934017110>, <__main__.Expressao object at 0x7f0934017150>, <__main__.Expressao object at 0x7f0934017190>, <__main__.Expressao object at 0x7f09340171d0>, <__main__.Expressao object at 0x7f0934017210>, <__main__.Expressao object at 0x7f0934017250>, <__main__.Expressao object at 0x7f0934017290>, <__main__.Expressao object at 0x7f09340172d0>, <__main__.Expressao object at 0x7f0934017310>, <__main__.Expressao object at 0x7f0934017350>, <__main__.Expressao object at 0x7f0934017390>, <__main__.Expressao object at 0x7f09340173d0>, <__main__.Expressao object at 0x7f0934017410>, <__main__.Expressao object at 0x7f0934017450>, <__main__.Expressao object at 0x7f0934017490>, <__main__.Expressao object at 0x7f09340174d0>, <__main__.Expressao object at 0x7f0934017510>, <__main__.Expressao object at 0x7f0934017550>, <__main__.Expressao object at 0x7f0934017590>, <__main__.Expressao object at 0x7f09340175d0>, <__main__.Expressao object at 0x7f0934017610>, <__main__.Expressao object at 0x7f0934017650>, <__main__.Expressao object at 0x7f0934017690>, <__main__.Expressao object at 0x7f09340176d0>, <__main__.Expressao object at 0x7f0934017710>, <__main__.Expressao object at 0x7f0934017750>, <__main__.Expressao object at 0x7f0934017790>, <__main__.Expressao object at 0x7f09340177d0>, <__main__.Expressao object at 0x7f0934017810>, <__main__.Expressao object at 0x7f0934017850>, <__main__.Expressao object at 0x7f0934017890>, <__main__.Expressao object at 0x7f09340178d0>, <__main__.Expressao object at 0x7f0934017910>, <__main__.Expressao object at 0x7f0934017950>, <__main__.Expressao object at 0x7f0934017990>, <__main__.Expressao object at 0x7f09340179d0>, <__main__.Expressao object at 0x7f0934017a10>, <__main__.Expressao object at 0x7f0934017a50>, <__main__.Expressao object at 0x7f0934017a90>, <__main__.Expressao object at 0x7f0934017ad0>, <__main__.Expressao object at 0x7f0934017b10>, <__main__.Expressao object at 0x7f0934017b50>, <__main__.Expressao object at 0x7f0934017b90>, <__main__.Expressao object at 0x7f0934017bd0>, <__main__.Expressao object at 0x7f0934017c10>, <__main__.Expressao object at 0x7f0934017c50>, <__main__.Expressao object at 0x7f0934017c90>, <__main__.Expressao object at 0x7f0934017cd0>, <__main__.Expressao object at 0x7f0934017d10>, <__main__.Expressao object at 0x7f0934017d50>, <__main__.Expressao object at 0x7f0934017d90>, <__main__.Expressao object at 0x7f0934017dd0>, <__main__.Expressao object at 0x7f0934017e10>, <__main__.Expressao object at 0x7f0934017e50>, <__main__.Expressao object at 0x7f0934017e90>, <__main__.Expressao object at 0x7f0934017ed0>, <__main__.Expressao object at 0x7f0934017f10>, <__main__.Expressao object at 0x7f0934017f50>, <__main__.Expressao object at 0x7f0934017f90>, <__main__.Expressao object at 0x7f0934017fd0>, <__main__.Expressao object at 0x7f0934045050>, <__main__.Expressao object at 0x7f0934045090>, <__main__.Expressao object at 0x7f09340450d0>, <__main__.Expressao object at 0x7f0934045110>, <__main__.Expressao object at 0x7f0934045150>, <__main__.Expressao object at 0x7f0934045190>, <__main__.Expressao object at 0x7f09340451d0>, <__main__.Expressao object at 0x7f0934045210>, <__main__.Expressao object at 0x7f0934045250>, <__main__.Expressao object at 0x7f0934045290>, <__main__.Expressao object at 0x7f09340452d0>, <__main__.Expressao object at 0x7f0934045310>, <__main__.Expressao object at 0x7f0934045350>, <__main__.Expressao object at 0x7f0934045390>, <__main__.Expressao object at 0x7f09340453d0>, <__main__.Expressao object at 0x7f0934045410>, <__main__.Expressao object at 0x7f0934045450>, <__main__.Expressao object at 0x7f0934045490>, <__main__.Expressao object at 0x7f09340454d0>, <__main__.Expressao object at 0x7f0934045510>, <__main__.Expressao object at 0x7f0934045550>, <__main__.Expressao object at 0x7f0934045590>, <__main__.Expressao object at 0x7f09340455d0>, <__main__.Expressao object at 0x7f0934045610>, <__main__.Expressao object at 0x7f0934045650>, <__main__.Expressao object at 0x7f0934045690>, <__main__.Expressao object at 0x7f09340456d0>, <__main__.Expressao object at 0x7f0934045710>, <__main__.Expressao object at 0x7f0934045750>, <__main__.Expressao object at 0x7f0934045790>, <__main__.Expressao object at 0x7f09340457d0>, <__main__.Expressao object at 0x7f0934045810>, <__main__.Expressao object at 0x7f0934045850>, <__main__.Expressao object at 0x7f0934045890>, <__main__.Expressao object at 0x7f09340458d0>, <__main__.Expressao object at 0x7f0934045910>, <__main__.Expressao object at 0x7f0934045950>, <__main__.Expressao object at 0x7f0934045990>, <__main__.Expressao object at 0x7f09340459d0>, <__main__.Expressao object at 0x7f0934045a10>, <__main__.Expressao object at 0x7f0934045a50>, <__main__.Expressao object at 0x7f0934045a90>, <__main__.Expressao object at 0x7f0934045ad0>, <__main__.Expressao object at 0x7f0934045b10>, <__main__.Expressao object at 0x7f0934045b50>, <__main__.Expressao object at 0x7f0934045b90>, <__main__.Expressao object at 0x7f0934045bd0>, <__main__.Expressao object at 0x7f0934045c10>, <__main__.Expressao object at 0x7f0934045c50>, <__main__.Expressao object at 0x7f0934045c90>, <__main__.Expressao object at 0x7f0934045cd0>, <__main__.Expressao object at 0x7f0934045d10>, <__main__.Expressao object at 0x7f0934045d50>, <__main__.Expressao object at 0x7f0934045d90>, <__main__.Expressao object at 0x7f0934045dd0>, <__main__.Expressao object at 0x7f0934045e10>, <__main__.Expressao object at 0x7f0934045e50>, <__main__.Expressao object at 0x7f0934045e90>, <__main__.Expressao object at 0x7f0934045ed0>, <__main__.Expressao object at 0x7f0934045f10>, <__main__.Expressao object at 0x7f0934045f50>, <__main__.Expressao object at 0x7f0934045f90>, <__main__.Expressao object at 0x7f0934045fd0>, <__main__.Expressao object at 0x7f0934029050>, <__main__.Expressao object at 0x7f0934029090>, <__main__.Expressao object at 0x7f09340290d0>, <__main__.Expressao object at 0x7f0934029110>, <__main__.Expressao object at 0x7f0934029150>, <__main__.Expressao object at 0x7f0934029190>, <__main__.Expressao object at 0x7f09340291d0>, <__main__.Expressao object at 0x7f0934029210>, <__main__.Expressao object at 0x7f0934029250>, <__main__.Expressao object at 0x7f0934029290>, <__main__.Expressao object at 0x7f09340292d0>, <__main__.Expressao object at 0x7f0934029310>, <__main__.Expressao object at 0x7f0934029350>, <__main__.Expressao object at 0x7f0934029390>, <__main__.Expressao object at 0x7f09340293d0>, <__main__.Expressao object at 0x7f0934029410>, <__main__.Expressao object at 0x7f0934029450>, <__main__.Expressao object at 0x7f0934029490>, <__main__.Expressao object at 0x7f09340294d0>, <__main__.Expressao object at 0x7f0934029510>, <__main__.Expressao object at 0x7f0934029550>, <__main__.Expressao object at 0x7f0934029590>, <__main__.Expressao object at 0x7f09340295d0>, <__main__.Expressao object at 0x7f0934029610>, <__main__.Expressao object at 0x7f0934029650>, <__main__.Expressao object at 0x7f0934029690>, <__main__.Expressao object at 0x7f09340296d0>, <__main__.Expressao object at 0x7f0934029710>, <__main__.Expressao object at 0x7f0934029750>, <__main__.Expressao object at 0x7f0934029790>, <__main__.Expressao object at 0x7f09340297d0>, <__main__.Expressao object at 0x7f0934029810>, <__main__.Expressao object at 0x7f0934029850>, <__main__.Expressao object at 0x7f0934029890>, <__main__.Expressao object at 0x7f09340298d0>, <__main__.Expressao object at 0x7f0934029910>, <__main__.Expressao object at 0x7f0934029950>, <__main__.Expressao object at 0x7f0934029990>, <__main__.Expressao object at 0x7f09340299d0>, <__main__.Expressao object at 0x7f0934029a10>, <__main__.Expressao object at 0x7f0934029a50>, <__main__.Expressao object at 0x7f0934029a90>, <__main__.Expressao object at 0x7f0934029ad0>, <__main__.Expressao object at 0x7f0934029b10>, <__main__.Expressao object at 0x7f0934029b50>, <__main__.Expressao object at 0x7f0934029b90>, <__main__.Expressao object at 0x7f0934029bd0>, <__main__.Expressao object at 0x7f0934029c10>, <__main__.Expressao object at 0x7f0934029c50>, <__main__.Expressao object at 0x7f0934029c90>, <__main__.Expressao object at 0x7f0934029cd0>, <__main__.Expressao object at 0x7f0934029d10>, <__main__.Expressao object at 0x7f0934029d50>, <__main__.Expressao object at 0x7f0934029d90>, <__main__.Expressao object at 0x7f0934029dd0>, <__main__.Expressao object at 0x7f0934029e10>, <__main__.Expressao object at 0x7f0934029e50>, <__main__.Expressao object at 0x7f0934029e90>, <__main__.Expressao object at 0x7f0934029ed0>, <__main__.Expressao object at 0x7f0934029f10>, <__main__.Expressao object at 0x7f0934029f50>, <__main__.Expressao object at 0x7f0934029f90>, <__main__.Expressao object at 0x7f0934029fd0>, <__main__.Expressao object at 0x7f093401f050>, <__main__.Expressao object at 0x7f093401f090>, <__main__.Expressao object at 0x7f093401f0d0>, <__main__.Expressao object at 0x7f093401f110>, <__main__.Expressao object at 0x7f093401f150>, <__main__.Expressao object at 0x7f093401f190>, <__main__.Expressao object at 0x7f093401f1d0>, <__main__.Expressao object at 0x7f093401f210>, <__main__.Expressao object at 0x7f093401f250>, <__main__.Expressao object at 0x7f093401f290>, <__main__.Expressao object at 0x7f093401f2d0>, <__main__.Expressao object at 0x7f093401f310>, <__main__.Expressao object at 0x7f093401f350>, <__main__.Expressao object at 0x7f093401f390>, <__main__.Expressao object at 0x7f093401f3d0>, <__main__.Expressao object at 0x7f093401f410>, <__main__.Expressao object at 0x7f093401f450>, <__main__.Expressao object at 0x7f093401f490>, <__main__.Expressao object at 0x7f093401f4d0>, <__main__.Expressao object at 0x7f093401f510>, <__main__.Expressao object at 0x7f093401f550>, <__main__.Expressao object at 0x7f093401f590>, <__main__.Expressao object at 0x7f093401f5d0>, <__main__.Expressao object at 0x7f093401f610>, <__main__.Expressao object at 0x7f093401f650>, <__main__.Expressao object at 0x7f093401f690>, <__main__.Expressao object at 0x7f093401f6d0>, <__main__.Expressao object at 0x7f093401f710>, <__main__.Expressao object at 0x7f093401f750>, <__main__.Expressao object at 0x7f093401f790>, <__main__.Expressao object at 0x7f093401f7d0>, <__main__.Expressao object at 0x7f093401f810>, <__main__.Expressao object at 0x7f093401f850>, <__main__.Expressao object at 0x7f093401f890>, <__main__.Expressao object at 0x7f093401f8d0>, <__main__.Expressao object at 0x7f093401f910>, <__main__.Expressao object at 0x7f093401f950>, <__main__.Expressao object at 0x7f093401f990>, <__main__.Expressao object at 0x7f093401f9d0>, <__main__.Expressao object at 0x7f093401fa10>, <__main__.Expressao object at 0x7f093401fa50>, <__main__.Expressao object at 0x7f093401fa90>, <__main__.Expressao object at 0x7f093401fad0>, <__main__.Expressao object at 0x7f093401fb10>, <__main__.Expressao object at 0x7f093401fb50>, <__main__.Expressao object at 0x7f093401fb90>, <__main__.Expressao object at 0x7f093401fbd0>, <__main__.Expressao object at 0x7f093401fc10>, <__main__.Expressao object at 0x7f093401fc50>, <__main__.Expressao object at 0x7f093401fc90>, <__main__.Expressao object at 0x7f093401fcd0>, <__main__.Expressao object at 0x7f093401fd10>, <__main__.Expressao object at 0x7f093401fd50>, <__main__.Expressao object at 0x7f093401fd90>, <__main__.Expressao object at 0x7f093401fdd0>, <__main__.Expressao object at 0x7f093401fe10>, <__main__.Expressao object at 0x7f093401fe50>, <__main__.Expressao object at 0x7f093401fe90>, <__main__.Expressao object at 0x7f093401fed0>, <__main__.Expressao object at 0x7f093401ff50>, <__main__.Expressao object at 0x7f093401ff10>, <__main__.Expressao object at 0x7f093401ff90>, <__main__.Expressao object at 0x7f0934039050>, <__main__.Expressao object at 0x7f093401ffd0>, <__main__.Expressao object at 0x7f0934039090>, <__main__.Expressao object at 0x7f09340390d0>, <__main__.Expressao object at 0x7f0934039110>, <__main__.Expressao object at 0x7f0934039150>, <__main__.Expressao object at 0x7f0934039190>, <__main__.Expressao object at 0x7f09340391d0>, <__main__.Expressao object at 0x7f0934039210>, <__main__.Expressao object at 0x7f0934039250>, <__main__.Expressao object at 0x7f0934039290>, <__main__.Expressao object at 0x7f09340392d0>, <__main__.Expressao object at 0x7f0934039310>, <__main__.Expressao object at 0x7f0934039350>, <__main__.Expressao object at 0x7f0934039390>, <__main__.Expressao object at 0x7f09340393d0>, <__main__.Expressao object at 0x7f0934039410>, <__main__.Expressao object at 0x7f0934039450>, <__main__.Expressao object at 0x7f0934039490>, <__main__.Expressao object at 0x7f09340394d0>, <__main__.Expressao object at 0x7f0934039510>, <__main__.Expressao object at 0x7f0934039550>, <__main__.Expressao object at 0x7f0934039590>, <__main__.Expressao object at 0x7f09340395d0>, <__main__.Expressao object at 0x7f0934039610>, <__main__.Expressao object at 0x7f0934039650>, <__main__.Expressao object at 0x7f0934039690>, <__main__.Expressao object at 0x7f09340396d0>, <__main__.Expressao object at 0x7f0934039710>, <__main__.Expressao object at 0x7f0934039750>, <__main__.Expressao object at 0x7f0934039790>, <__main__.Expressao object at 0x7f09340397d0>, <__main__.Expressao object at 0x7f0934039810>, <__main__.Expressao object at 0x7f0934039850>, <__main__.Expressao object at 0x7f0934039890>, <__main__.Expressao object at 0x7f09340398d0>, <__main__.Expressao object at 0x7f0934039910>, <__main__.Expressao object at 0x7f0934039950>, <__main__.Expressao object at 0x7f0934039990>, <__main__.Expressao object at 0x7f09340399d0>, <__main__.Expressao object at 0x7f0934039a10>, <__main__.Expressao object at 0x7f0934039a50>, <__main__.Expressao object at 0x7f0934039a90>, <__main__.Expressao object at 0x7f0934039ad0>, <__main__.Expressao object at 0x7f0934039b10>, <__main__.Expressao object at 0x7f0934039b50>, <__main__.Expressao object at 0x7f0934039b90>, <__main__.Expressao object at 0x7f0934039bd0>, <__main__.Expressao object at 0x7f0934039c10>, <__main__.Expressao object at 0x7f0934039c50>, <__main__.Expressao object at 0x7f0934039c90>, <__main__.Expressao object at 0x7f0934039cd0>, <__main__.Expressao object at 0x7f0934039d10>, <__main__.Expressao object at 0x7f0934039d50>, <__main__.Expressao object at 0x7f0934039d90>, <__main__.Expressao object at 0x7f0934039dd0>, <__main__.Expressao object at 0x7f0934039e10>, <__main__.Expressao object at 0x7f0934039e50>, <__main__.Expressao object at 0x7f0934039e90>, <__main__.Expressao object at 0x7f0934039ed0>, <__main__.Expressao object at 0x7f0934039f10>, <__main__.Expressao object at 0x7f0934039f50>, <__main__.Expressao object at 0x7f0934039f90>, <__main__.Expressao object at 0x7f0934039fd0>, <__main__.Expressao object at 0x7f0926744050>, <__main__.Expressao object at 0x7f0926744090>, <__main__.Expressao object at 0x7f09267440d0>, <__main__.Expressao object at 0x7f0926744110>, <__main__.Expressao object at 0x7f0926744190>, <__main__.Expressao object at 0x7f0926744150>, <__main__.Expressao object at 0x7f09267441d0>, <__main__.Expressao object at 0x7f0926744210>, <__main__.Expressao object at 0x7f0926744250>, <__main__.Expressao object at 0x7f0926744290>, <__main__.Expressao object at 0x7f09267442d0>, <__main__.Expressao object at 0x7f0926744310>, <__main__.Expressao object at 0x7f0926744350>, <__main__.Expressao object at 0x7f0926744390>, <__main__.Expressao object at 0x7f09267443d0>, <__main__.Expressao object at 0x7f0926744410>, <__main__.Expressao object at 0x7f0926744450>, <__main__.Expressao object at 0x7f0926744490>, <__main__.Expressao object at 0x7f09267444d0>, <__main__.Expressao object at 0x7f0926744510>, <__main__.Expressao object at 0x7f0926744550>, <__main__.Expressao object at 0x7f0926744590>, <__main__.Expressao object at 0x7f09267445d0>, <__main__.Expressao object at 0x7f0926744610>, <__main__.Expressao object at 0x7f0926744650>, <__main__.Expressao object at 0x7f0926744690>, <__main__.Expressao object at 0x7f09267446d0>, <__main__.Expressao object at 0x7f0926744710>, <__main__.Expressao object at 0x7f0926744750>, <__main__.Expressao object at 0x7f0926744790>, <__main__.Expressao object at 0x7f09267447d0>, <__main__.Expressao object at 0x7f0926744810>, <__main__.Expressao object at 0x7f0926744850>, <__main__.Expressao object at 0x7f0926744890>, <__main__.Expressao object at 0x7f09267448d0>, <__main__.Expressao object at 0x7f0926744910>, <__main__.Expressao object at 0x7f0926744950>, <__main__.Expressao object at 0x7f0926744990>, <__main__.Expressao object at 0x7f09267449d0>, <__main__.Expressao object at 0x7f0926744a10>, <__main__.Expressao object at 0x7f0926744a50>, <__main__.Expressao object at 0x7f0926744a90>, <__main__.Expressao object at 0x7f0926744ad0>, <__main__.Expressao object at 0x7f0926744b10>, <__main__.Expressao object at 0x7f0926744b50>, <__main__.Expressao object at 0x7f0926744b90>, <__main__.Expressao object at 0x7f0926744bd0>, <__main__.Expressao object at 0x7f0926744c10>, <__main__.Expressao object at 0x7f0926744c50>, <__main__.Expressao object at 0x7f0926744c90>, <__main__.Expressao object at 0x7f0926744cd0>, <__main__.Expressao object at 0x7f0926744d10>, <__main__.Expressao object at 0x7f0926744d50>, <__main__.Expressao object at 0x7f0926744d90>, <__main__.Expressao object at 0x7f0926744dd0>, <__main__.Expressao object at 0x7f0926744e10>, <__main__.Expressao object at 0x7f0926744e50>, <__main__.Expressao object at 0x7f0926744e90>, <__main__.Expressao object at 0x7f0926744ed0>, <__main__.Expressao object at 0x7f0926744f10>, <__main__.Expressao object at 0x7f0926744f50>, <__main__.Expressao object at 0x7f0926744f90>, <__main__.Expressao object at 0x7f0926744fd0>, <__main__.Expressao object at 0x7f0926772050>, <__main__.Expressao object at 0x7f0926772090>, <__main__.Expressao object at 0x7f09267720d0>, <__main__.Expressao object at 0x7f0926772110>, <__main__.Expressao object at 0x7f0926772150>, <__main__.Expressao object at 0x7f0926772190>, <__main__.Expressao object at 0x7f09267721d0>, <__main__.Expressao object at 0x7f0926772210>, <__main__.Expressao object at 0x7f0926772250>, <__main__.Expressao object at 0x7f0926772290>, <__main__.Expressao object at 0x7f09267722d0>, <__main__.Expressao object at 0x7f0926772310>, <__main__.Expressao object at 0x7f0926772390>, <__main__.Expressao object at 0x7f0926772350>, <__main__.Expressao object at 0x7f09267723d0>, <__main__.Expressao object at 0x7f0926772450>, <__main__.Expressao object at 0x7f0926772410>, <__main__.Expressao object at 0x7f0926772490>, <__main__.Expressao object at 0x7f09267724d0>, <__main__.Expressao object at 0x7f0926772510>, <__main__.Expressao object at 0x7f0926772550>, <__main__.Expressao object at 0x7f0926772590>, <__main__.Expressao object at 0x7f09267725d0>, <__main__.Expressao object at 0x7f0926772610>, <__main__.Expressao object at 0x7f0926772650>, <__main__.Expressao object at 0x7f0926772690>, <__main__.Expressao object at 0x7f09267726d0>, <__main__.Expressao object at 0x7f0926772710>, <__main__.Expressao object at 0x7f0926772750>, <__main__.Expressao object at 0x7f0926772790>, <__main__.Expressao object at 0x7f09267727d0>, <__main__.Expressao object at 0x7f0926772810>, <__main__.Expressao object at 0x7f0926772850>, <__main__.Expressao object at 0x7f0926772890>, <__main__.Expressao object at 0x7f09267728d0>, <__main__.Expressao object at 0x7f0926772910>, <__main__.Expressao object at 0x7f0926772950>, <__main__.Expressao object at 0x7f0926772990>, <__main__.Expressao object at 0x7f09267729d0>, <__main__.Expressao object at 0x7f0926772a10>, <__main__.Expressao object at 0x7f0926772a50>, <__main__.Expressao object at 0x7f0926772a90>, <__main__.Expressao object at 0x7f0926772ad0>, <__main__.Expressao object at 0x7f0926772b10>, <__main__.Expressao object at 0x7f0926772b50>, <__main__.Expressao object at 0x7f0926772b90>, <__main__.Expressao object at 0x7f0926772bd0>, <__main__.Expressao object at 0x7f0926772c10>, <__main__.Expressao object at 0x7f0926772c50>, <__main__.Expressao object at 0x7f0926772c90>]
  • 1

    You can put some examples of lines from this file in your question?

1 answer

4


Define a method in your class __repr__():

class Expressao(object):
    def __init__(self, nivel, tipo, expressao, resposta):
        self.nivel = nivel
        self.tipo = tipo
        self.expressao = expressao
        self.resposta = resposta

    def __repr__(self):
        return self.nivel + ", " + self.tipo + ", " + self.expressao + ", " + self.resposta

When printing the object, its values should appear separated by commas.

>>> e = Expressao('3', 's', '43-12', '31')
>>> e
3, s, 43-12, 31
  • 1

    A hint: Python does not use much strigns concatenation with + to assemble answers - except realemtne where it is most practical, The normal is to use the string format méotodo, or the operator "%" - so avoid the need to type, and have to read several sequences of " + variavel + ". In that case it could be so: "{}, {}, {}, {}".format(self.nivel, self.tipo, self.expressao, self.resposta"

  • Yes, and this way is better for data sanitation. I am more of the world . NET and I recognize that I am full of addictions. Studying Python is being good to broaden horizons. Thanks for the tip!

  • 1

    Ppois is - I noticed in your repsostas that you know some of the more advanced aspects of Python - what you really need for serious applications, but you haven’t had time to see the things "on the surface" that make Python so "awesome". I’ll touch the comments, when appropriate.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.