Skip to content
Sign upLog in
← Back to Community

Is it possible to get a user's username in python?

Profile icon
HoogidyBoogidy

I'm trying to say "Welcome * USERNAME ", but I don't know
what to put as "
USERNAME *". Is it even possible to get the user's repl username in python?

Answered by Coder100 [earned 5 cycles]
View Answer
Voters
Profile icon
HoogidyBoogidy
Comments
hotnewtop
Profile icon
Coder100

EDIT:
ok justification for why REPL_OWNER works.

Each time someone views ur repl, they 'fork' it without even them knowing it. This fork will be deleted after they leave, but they need to fork it so the program even can be run. Now your can get any user name!

Profile icon
Fortran95

I got this from

@HyperHacker
:import os

username = os.environ["REPL_OWNER"]

Profile icon
HoogidyBoogidy

OHHHHHHH. I see, it wasn't, "environ()" but, "environ[]". BRUH TO ME.

@EpicRaisin
and
@RYANTADIPARTHI
Sorry for being blind.

Does it work for any user though? As in, if a different user's name was Johny, would it say Johny or would it say "HoogidyBoogidy"? If it doesn't work like that, then I need something else.

Profile icon
EpicRaisin

@HoogidyBoogidy
lol its ok

Profile icon
RYANTADIPARTHI
Profile icon
Coder100

Gives you HoogidyBoogidy. If you want the name, you can't anymore due to repl.it shutting down their api to the public

@HoogidyBoogidy

Profile icon
RYANTADIPARTHI

Solution

Try this:

import os owner = os.environ['REPL_OWNER'] # to print, use owner print("hello " + owner)

like that.
That should work

Profile icon
EpicRaisin

I believe it's this:

import os user = os.environ["REPL_OWNER"]
Profile icon
HoogidyBoogidy

I tried "print(os.environ("REPL_OWNER"))", but still didn't work.

Profile icon
EpicRaisin

@HoogidyBoogidy
It's not os.environ('REPL_OWNER'), it's a dictionary, so it's os.environ['REPL_OWNER'].