Changing file extensions with python

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
TsukiWorks
Regular
Posts: 27
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Changing file extensions with python

#1 Post by TsukiWorks »

Hello! I tried to change a file's extension (from .txt to .png). I created the file at a certain moment of the story and I wrote it in binary, and I wanted to convert it into pixels..
I don't know if it's possible...but I used this code:

Code: Select all

python:
        f = open("hello.txt", "wb")
        f.write("01010011 01100001 01100100 01101100 01111001 00100000 01110100 01101000 01100101 00100000 01110000 01100001 01101001 01101110 00100000 01110111 01101001 01101100 01101100 00100000 01101110 01100101 01110110 01100101 01110010 00100000 01100101 01101110 01100100 00101110 0001010 01010011 01101111 01110010 01110010 01111001 00101100 00100000 01001001 00100000 01101000 01100001 01100100 00100000 01110100 01101111 00100000 01110011 01100001 01111001 00100000 01100111 01101111 01101111 01100100 01100010 01111001 01100101 00101100 00100000 01101101 01111001 00100000 01100110 01110010 01101001 01100101 01101110 01100100 00101110")
        import os
        os.rename("hello.txt", "hello.png")
I got the WindowsError [Error 32].
Any help will be appreciated!

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Changing file extensions with python

#2 Post by MaydohMaydoh »

"WindowsError: [Error 32] The process cannot access the file beacause it is being used by another process."
I think you need to close the file before you can change the name and stuff.

Code: Select all

f.close()

User avatar
TsukiWorks
Regular
Posts: 27
Joined: Sat Jun 23, 2018 6:50 am
Projects: The Misunderstood
Deviantart: TsukiWorks
Contact:

Re: Changing file extensions with python

#3 Post by TsukiWorks »

MaydohMaydoh wrote: Sat Aug 11, 2018 8:10 am "WindowsError: [Error 32] The process cannot access the file beacause it is being used by another process."
I think you need to close the file before you can change the name and stuff.

Code: Select all

f.close()
Thanks! It's working now. The only thing that doesn't work is the convertion...but it might not be possible to do that.

Post Reply

Who is online

Users browsing this forum: Google [Bot]