Skip to content
Sign upLog in
← Back to Community

Classes

Profile icon
ShivankChhaya

This repl has a bunch of different classes. I made this based on discord(sort of) and when str(classname) is run on the class, I don't want it to say <class __main__.'classname'>, I want it to say classname.
vvvvvvv Just Like what this does. vvvvvvv
Screen Shot 2021-02-01 at 7.33.27 PM

Voters
Profile icon
0201630
Profile icon
ShivankChhaya
Comments
hotnewtop
Profile icon
btfuss

Question:

Are you trying to take a variable (classtime) and access a class with that? If yes, it is not possible.

Workaround:

A substitute for this is to find and attribute using a function and work with that from there

:D

Profile icon
ShivankChhaya

@2plus2is4hoi
not exactly. Have you ever created a discord bot?

Profile icon
btfuss

@ShivankChhaya

You just want it to print classname. Just do this:
modify = str(classname)
modify = modify[7:-1]
or another method
modify = list(str(classname).split('\''))
modify = modify[1]

sorry if this didnt help

Profile icon
ShivankChhaya

@2plus2is4hoi
That does work... But i want it to work without the [7:-1](or the other one).

Profile icon
btfuss

@ShivankChhaya

if you dont mind me asking, why does it matter if it works without the [7:-1]

Profile icon
ShivankChhaya

@2plus2is4hoi
well i want it on the classes I have here, and I dont want people doing [7:-1] each time.

Profile icon
btfuss

@ShivankChhaya

cant you just take input and run the output that is modified?

Profile icon
btfuss

@ShivankChhaya
this modification would work for any name

Profile icon
ShivankChhaya

@2plus2is4hoi
o well true

Profile icon
ShivankChhaya

@2plus2is4hoi
I know that

Profile icon
btfuss

@ShivankChhaya
i just dont see why you wouldnt use it :/

:D

Profile icon
ShivankChhaya

@2plus2is4hoi
wellll have you ever made a discord bot?

Profile icon
btfuss

@ShivankChhaya
it seems pretty simple. if print() prints for the server, then just do print(str(classname)[7:-1])

Substitute this for whatever function print is for discord

Profile icon
ShivankChhaya

@2plus2is4hoi
ok fine ill do that(I've done it before, and FYI its [17:-2]).

Profile icon
btfuss

@ShivankChhaya
okay lol i tried

Profile icon
btfuss

@ShivankChhaya

good luck! if i helped can u pls mark lol

Profile icon
ShivankChhaya

@2plus2is4hoi
lol ok did u notice that when you did str(GuildObject) it returned the guild's name? That's what I want.