Accrington Web
   

Home Gallery Arcade Blogs Members List Today's Posts
Go Back   Accrington Web > Technical & User to User help > Tech Talk
Donate! Join Today

Tech Talk Modern technology eh? Talk about it here! Please use the seperate forums for gaming or photography talk...


Welcome to Accrington Web!

We are a discussion forum dedicated to the towns of Accrington, Oswaldtwistle and the surrounding areas, sometimes referred to as Hyndburn! We are a friendly bunch please feel free to browse or read on for more info.
You are currently viewing our site as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, photos, play in the community arcade and use our blog section. Registration is fast, simple and absolutely free, so please, join our community today!



Reply
 
LinkBack Thread Tools
Old 27-03-2012, 16:53   #1
Full Member
 

Setting a maximum line length

I have an MP4 player which can display e-books but only as text files (.TXT).

I have software to convert files to that format but, unfortunately, the converted files do not wrap properly on the screen. Instead of line breaking where a line is too long for the screen, words continue across the screen edge, so that the first few letters are on one line and the remainder on the next.

I want to format the files so that they suit the screen width i.e. line break every 30 characters.

I've tried numerous text editors to no avail. Any ideas?
Thin Monkey is offline   Reply With Quote
Accrington Web
Old 28-03-2012, 09:22   #2
God Member
 
entwisi's Avatar
 

Re: Setting a maximum line length

Geek Warning!!!!!!

Python can do this easily in scripting. install python from Python 3.2.2 Release

create a folder on your C drive called ebooks ( i tested under Linux obviously but Python is Platform agnostic so should be OK)

save the following as ebook.py in it altering the text inside the quotes to the name of your ebook text file ( e.g. howtoprograminpython.txt to sausagesaretasty.txt & howtoprograminpython_fixed.txt to sauasgesaretasty_fixed.txt)

Code:
def word_wrap(string, width=80, ind1=0, ind2=0, prefix=''):
   
    string = prefix + ind1 * " " + string
    newstring = ""
    while len(string) > width:
        # find position of nearest whitespace char to the left of "width"
        marker = width - 1
        while not string[marker].isspace():
            marker = marker - 1

        # remove line from original string and add it to the new string
        newline = string[0:marker] + "\n"
        newstring = newstring + newline
        string = prefix + ind2 * " " + string[marker + 1:]

    return newstring + string
f=open('howtoprograminpython.txt', 'r')
o=open('howtoprograminpython_fixed.txt', 'w')

string=f.read()
o.write(word_wrap(string,30))
run it on a command line from the folder that you are in with

Code:
python ebook.py
repeat for all you want to fix
__________________
Ian

Technical God, No 1 Geek And Linux Guru

Have you seen my Flickr pictures?

entwisi is offline   Reply With Quote
Old 28-03-2012, 09:50   #3
God Member
 
entwisi's Avatar
 

Re: Setting a maximum line length

forgot to say, you need to place the original text files in the ebooks folder you created....
__________________
Ian

Technical God, No 1 Geek And Linux Guru

Have you seen my Flickr pictures?

entwisi is offline   Reply With Quote
Old 28-03-2012, 11:38   #4
Full Member
 

Re: Setting a maximum line length

Thanks for the advice.

It's a bit daunting, I'm no programer, but I would have given it a try. However I've managed to find a more idiot proof solution using "Text Mechanic".

Add/Remove Line Breaks

A little long-winded perhaps, buy I understand much better what I'm doing.

Thanks again.
Thin Monkey is offline   Reply With Quote
Reply




Other sites of interest.. More town sites..




All times are GMT. The time now is 11:43.


© 2003-2013 AccringtonWeb.com



Search Engine Friendly URLs by vBSEO 3.6.1