Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

keep text formatting when reading in from file python

Options
  • 30-07-2009 8: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 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