Categories > WeAreDevs > Hangout >
Need help in Python lol
Posted
There is no python area and no other area so i guess ill ask here
so im trying to make a dumb script for a tutorial i will be making and essentially it would be how to hide your entire source code in a .env (ik thats dumb, but i dont wanna reveal too much info now)
so at one point, the script creates a file in a folder that is inside the root folder, but it wont create it, and it gives FileNotFoundError, even though im trying to make the file. btw the mode that im using is w+
here is how the folder looks like:
/ (root folder)
randomfolder
create file here
randomfile.py (the code for creating file is located here)
anotherrandomfile.py
Here are the files im working with: https://anonfiles.com/36V466L9o8/dotenvprotect_rar
It's source files, so don't ask me for a VT.
Also the line where it errors is 50-51
also, there is some dumb code in there, i just did it to avoid errors, without caring about how to do it properly
My new discord is Wabz#1337 with ID 777154062789509130
Replied
HM...
Now thats what i call out of my league sorry
Cancel
Post
Replied
Try using 'a'. It appends to file but if there isnt any files there, it creates one and puts script there.
If you wanna write to it again, use 'w'.
Cancel
Post
https://cdn.discordapp.com/attachments/744131168018104320/749027674323812373/kekw.mp4Â
Â
My new discord is Wabz#1337 with ID 777154062789509130
Replied
I replaced lines 31-34 with:
[code]
dotenv = None
with open('.\\examplenode\\.env', 'w+') as f:
dotenv = f.read().split('\n')
print(dotenv)
[/code]
And didn't show up any errors
Cancel
Post
Proud creator of: WRD+
Replied
@PoopMaster Nice, but i still have the error at line 50-51.
Did you get this error?
Cancel
Post
My new discord is Wabz#1337 with ID 777154062789509130
Replied
I figured out a way to do it, by making multiple checks for the existance of those files and folders. It didn't took long, and I got the idea from a a py script I was making myself.
[code]
# protect.py
# Changed lines 23 to 43
# List of directories used in the code below
dirs = {
'exampleNode': os.path.join('.', 'examplenode')
}
# Checks if the example node folder exists...
# and checks if it's a directory.
if os.path.exists(dirs['exampleNode']):
if not os.path.isdir(dirs['exampleNode']):
Exception("There is a file named after a directory. Remove 'examplenode'")
exit()
else:
# Makes directory
os.mkdir(dirs['exampleNode'])
# Another check but for the '.env' file, if it doesn't exists it creates a new one.
# [Depends on the previous code]
if not os.path.exists(os.path.join(dirs['exampleNode'], '.env')):
with open(os.path.join(dirs['exampleNode'], '.env'), 'w+') as f:
f.write('')
[/code]
Cancel
Post
Proud creator of: WRD+
My new discord is Wabz#1337 with ID 777154062789509130
Users viewing this thread:
( Members: 0, Guests: 2, Total: 2 )
Cancel
Post