Categories > WeAreDevs > Hangout >

Need help in Python lol

Wabz

Winning.js

Posts: 2410

Threads: 194

Joined: Apr, 2020

Reputation: 27

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

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

JOSHMISTY

Advantages

Posts: 1019

Threads: 99

Joined: Jul, 2020

Reputation: 10

Replied

HM...

Now thats what i call out of my league sorry

  • 0

NemesisX

Spoon#8225

Posts: 178

Threads: 56

Joined: Nov, 2018

Reputation: 4

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'.

  • 0

https://cdn.discordapp.com/attachments/744131168018104320/749027674323812373/kekw.mp4 

 

Wabz

Winning.js

Posts: 2410

Threads: 194

Joined: Apr, 2020

Reputation: 27

Replied

@NemesisX Still does the same thing

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

PoopMaster

SoundInfinity

noticed

Posts: 120

Threads: 23

Joined: Jul, 2019

Reputation: 9

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

  • 0

Proud creator of: WRD+

Wabz

Winning.js

Posts: 2410

Threads: 194

Joined: Apr, 2020

Reputation: 27

Replied

@PoopMaster Nice, but i still have the error at line 50-51.

Did you get this error?

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

PoopMaster

SoundInfinity

noticed

Posts: 120

Threads: 23

Joined: Jul, 2019

Reputation: 9

Replied

@Wabz

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]

  • 0

Proud creator of: WRD+

Wabz

Winning.js

Posts: 2410

Threads: 194

Joined: Apr, 2020

Reputation: 27

Replied

@PoopMaster ok thanks but i already fixed it

  • 0

My new discord is Wabz#1337 with ID 777154062789509130

Users viewing this thread:

( Members: 0, Guests: 1, Total: 1 )