| 1. |
Solve : How i can rewrap text?? |
|
Answer» Hi all!! import textwrapProgram print: "SyntaxError: invalid syntax" I use *.txt as "file" (I do it with my computer in house) Can you teach me? -I have other problem, I can't install any programming language on computer in my company. I use Wondow XP.Quote from: Star-Fire on March 26, 2009, 09:18:38 PM I don't know use python. When i install python and use your code. Program print: "SyntaxError: invalid syntax" I use *.txt as "file"the code is only used for ONE text file. if you want more that one text file, do it like this Code: [Select]import textwrap,glob for file in glob.glob("*.txt"): for line in open("file"): print '\n'.join(textwrap.wrap(line,30)) Quote I have other problem, I can't install any programming language on computer in my company. I use Wondow XP.if you can use USB, here's Portable python. Otherwise, you can just try to use vbscript. In that case, you would have to do a little bit of programming. 1) Open the file 2) Get each line, check total number of character 3) Divide them up by 30, which will give you how many lines there will be broken up. 4) Use a loop, do a substring , getting 30 characters each time...print them out , each time followed by a newline. 5) ....... Can I see your code for vbscript I want it can work more that one text file.Code: [Select]Set objFS = CreateObject("Scripting.FileSystemObject") strFile= "C:\test\file.txt" Set objFile = objFS.OpenTextFile(strFile,1) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine strLengthLine = Len(strLine) For i=0 To CInt(strLengthLine /30) WScript.Echo Mid(strLine,1,30) strLine= Mid(strLine,31) Next Loop i would expect you to read up on how to use vbscript. Here's a linkit's not working as expected Code: [Select]1. katy perry - thinking of yo u.mp3 2. kelly clarkson - my life, w ould suck without you 2009.mp3 3. akon and kardinal offishall and colby o donis - beautiful .mp3 requirement 1: Quote from: Star-Fire on March 26, 2009, 11:01:44 AM 1. katy perry - thinking of requirement 2: Quote from: Star-Fire on March 26, 2009, 09:45:38 PM Can I see your code for vbscript I want it can work more that one text file.this should be easy. base on your latest posts history, i have doubt that you can write code as per requirement.Quote from: Reno on March 27, 2009, 12:17:02 AM it's not working as expectedworks for me. OP just needs to tweak it a little. Code: [Select]C:\test>cscript /nologo test.vbs 1. katy perry - thinking of yo u.mp3 2. kelly clarkson - my life, w ould suck without you 2009.mp3 3. akon and kardinal offishall and colby o donis - beautiful .mp3 can you actually write code? the OP is asking a really simple script: 1. read more that one text file, eg. read all the txt file in a folder, or read all the txt file based on argument passing 2. rewarp text in file .txt but don't trim word (only trim space) with specified width (eg. 30 width). the code you posted is rather a generic code to read file. example of what output the OP ask: string=1. katy perry - thinking of you.mp3 incorrect ouput: 1. katy perry - thinking of yo u.mp3 correct output: 1. katy perry - thinking of you.mp3 Quote from: Reno on March 27, 2009, 12:50:30 AM can you actually write code?what's the matter with you? do you seriously doubt i can't code? I am also not obliged to provide FULL solutions every time i post. I believe i have provided enough for him to follow through and do it on his own. If you want, you can do that, but i think you will not be helping him LEARN at all. So would you please get off my back? Quote from: ghostdog74 on March 27, 2009, 12:59:24 AM what's the matter with you? do you seriously doubt i can't code? I am also not obliged to provide FULL solutions every time i post. I believe i have provided enough for him to follow through and do it on his own. If you want, you can do that, but i think you will not be helping him learn at all. So would you please get off my back? Now now boys CALM down |
|