WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-04-2011, 04:21 PM
EnvisMJ EnvisMJ is offline
Member
 
Join Date: May 2009
Location: Purdue University, West Lafayette, Indiana
Posts: 44
Using wordwrap or reading in newline (\n) comands from a .txt document

I'm reading in text from a .txt document that is to be read in as a string, and displayed within an infobox on screen. Problem is, some of the text chunks that need to be displayed are short paragraphs, so when the infobox shows up, it spans the screen, and only some of the text is visible.

How do I format this text into manageable lines?

A. I've added '\n' within the .txt file to format it, but it's just ignoring them and actually writing out the \n when displayed. Is there a way to get it to not ignore them?

B. Is there a wordwrap option that I can use? or even just a way of adding a newline every X number of characters?
Reply With Quote
  #2  
Old 04-04-2011, 04:52 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
If you are manually placing the \n characters in your text file, then you will need to use the following code to manually escape special characters (e.g \n):
Code:
s = s.decode('string_escape')
Alternatively, you could use the textwrap module to automatically wrap the text:
Code:
import textwrap
s = '\n'.join(textwrap.wrap(s,100)) #Wrap every 100 characters
Reply With Quote
Reply

Tags
formatting, infobox, newline, text, wordwrap


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:22 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC