Skip to content
Sign upLog in
← Back to Community

Obtaining account name and repl name programmatically

Profile icon
saulbaizman

Is there a way to obtain the account name and repl name programmatically, say, via Python?

I've looked at the Linux command-line environment, and the $USER value is "runner."

I'm aware that key/value pairs can be stored in ~/.env, but I wish to avoid having to create and customize a .env file for every repl I create.

Thanks.

Saul

Answered by programmeruser [earned 5 cycles]
View Answer
Voters
Profile icon
saulbaizman
Comments
hotnewtop
Profile icon
programmeruser

Here:

import os os.environ['REPL_OWNER'] # the person who's running the repl os.environ['REPL_SLUG'] # the repl name stripped of special characters

Try listing all the environment variables to see if they contain any useful information: https://repl.it/@programmeruser/osenviron#main.py

Profile icon
saulbaizman

@programmeruser
Thanks! I overlooked these two variables when I ran 'env' from the Linux command line (Command + Shift + S on macOS).

Entering "os.environ" at the Python prompt also prints out the same list as the repl you provided.

Thanks again!

Profile icon
3IMAD69

javascript :

process.env['REPL_SLUG']

so it would be like :
/home/runner/"+process.env['REPL_SLUG']

Profile icon
RYANTADIPARTHI

solution

Try this:

import os os.environ['REPL_OWNER]

That gets it
Which works

Profile icon
Coder100

Well, you could maybe go to the root directory and see the folder?
I know it looks something like:

/home/runner/ (Repl Name) python_tests
Profile icon
angrydoge

So I use

import os os.environ['REPL_OWNER']

I might have got the code wrong, but the repl owner is whoever runs the repl. If your in a multiplayer repl, itll just say the owners, but if you run it in the embed on a post, it most likely work. I hop I helped!

Profile icon
saulbaizman

@dabombdgdzjr
Thanks, that's perfect for grabbing the repl owner! I overlooked that variable when I typed printenv at the shell prompt.

I think I can get the name of the repl by grabbing the last part of the path of the pwd command. For example, if pwd is this:

/home/runner/whatever

I can retrieve "whatever."

Thanks again for your help, and good luck creating your new programming language!