readin .csv file - character at the end of a line

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
Ryue
Miko-Class Veteran
Posts: 745
Joined: Fri Nov 02, 2012 8:41 am
Projects: Red eyes in the darkness
Contact:

readin .csv file - character at the end of a line

#1 Post by Ryue »

I've a question, I'm using renpy.file to read a .csv file (made under windows), but at the end I see a strange character.
When I use fileData.split("\n") it functions normally, but the strange character is still printed when I print the lines.
So my question is: What is this character and how to get rid of it? (as I need to get rid of it to be able to parse the files correctly).

I'm using the following code:

Code: Select all

    fileList=renpy.list_files()
        msg=""
        for fileAndPath in fileList:
            if (fileAndPath[:9]=="data/map/"):
                fileData=renpy.file(fileAndPath).read().decode('utf-8')
                msg+=fileData
        narrator(msg)
It produces the following output:
ARenpyGame.png

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: readin .csv file - character at the end of a line

#2 Post by PyTom »

It's the newline character, \r. You can call .rstrip("\r") on each line to remove it.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot]