Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

keep text formatting when reading in from file python

  • 30-07-2009 08:51PM
    #1
    Closed Accounts Posts: 34


    Hi Guys,

    I'm reading in text from a file and showing it to the user via a scrolled message dialog. The file displays correctly when I open it with my texteditor and when I do the "print pmsg". When I display it with the scrolled message dialog it comes out all messed up. Looks like its losing some tabs or white spaces. Does anyone know anything I can do to preserve the formatting ?

    Here's some of my code:
    for line in f.readlines():
     pmsg = pmsg + line
    
    print pmsg
    
    ptitlemsg = "Listing Processes"
    dlg = wx.lib.dialogs.ScrolledMessageDialog(self, pmsg, ptitlemsg, size=(800,400))
    dlg.ShowModal()
    
    

    - Jack


Comments

  • Registered Users, Registered Users 2 Posts: 304 ✭✭PhantomBeaker


    Ok, the problem seems to be with the wx libraries.

    I know for a fact that readlines() will just read straight in, without killing any major characters - it even keeps the "\n" at the end.

    So, the only thing left is the wx library. The docs aren't a huge help. So, let's verify if wx really is the problem - start chucking weird strings at it. Don't bother even trying to read a file, but throw in things like "This\t is <a whole load of spaces>\n\nA test". Print it to standard out to see what to expect.

    Then try the wx version. If it screws up there, you have issues with wx, and may have to contact the support lists, or fora to see if that's a goer.

    Hope that helps you get on your way.

    Aoife


Advertisement