Ask coding questions

← Back to all posts
Is it possible to get a user's username in python?
HoogidyBoogidy (3)

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 (12485) [earned 5 cycles]
View Answer
Coder100 (12485)

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!

HoogidyBoogidy (3)

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.

Coder100 (12485)

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



Try this:

import os

owner = os.environ['REPL_OWNER']
# to print, use owner

print("hello " + owner)

like that.
That should work

EpicRaisin (227)

I believe it's this:

import os
user = os.environ["REPL_OWNER"]
HoogidyBoogidy (3)

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

EpicRaisin (227)

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