Learn to Code via Tutorials on Repl.it!

← Back to all posts
Importing Env the OLD WAY
FishballNooodle (211)

Normally, you would import a .env file in python something like this...

token = "wibfwuiofnweongmarhk4"
secret = "7289r;3'4h39'ae"

However, Replit has recently disabled the adding of .env files and requires the key, values to be entered manually or in json format.
This is not good if you have an env file 50 lines long.

I found out a way around this and wanted to share it with you all.

Steps


  1. First, create a file with a .txt extension (anyname)
  2. Add the key values like you normally do (aka the old method using "=")
  3. Go to the Shell and type the following commands
    a = open("filename.txt").read()
    f = open(".env","w)
    f.write(a)
    f.close()
    You can see your keys in the Secrets tab now and you can delete that .txt file

Boom You're done

Upvote this if you think it helps or if it helped you

Comments
hotnewtop
MrVoo (95)

These wouldn’t be secret though?

FishballNooodle (211)

@MrVoo ?
It will go into the Secrets Tab

MrVoo (95)

@FishballNooodle I mean the text file and the open/read stuff.

FishballNooodle (211)

@MrVoo
You delete the text file after that, you just use it to parse it in

CodingEssence (132)

@FishballNooodle Can't you just use the secrets tab instead?

FishballNooodle (211)

@CodingEssence
Like i said if you have a large env file in the old format
Please read before commenting