Hello,
Iam beginner in python and my english is not so good. Sorry.
I want (must) to write a program witch must read the .txt file and pursuant to the informations in text write another text to another file. :) example:
in .txt file:
<HEADLINE text="This is headline 1">
<PARAGRAPH file="path to the file.txt">

Python read this and write to another file this:

hd.append(Heading(1,"This is headline 1"))           
text = open("file.txt", "r").read( )
hd.append(Paragraph( PRE(text) ))

Thank you for anything...I dont know. Read the text term by term and when term=Headline then write to the other file hd.append(Heading(1,a)) and find the text between " " witch is a? I really dont know how to do this.
Thank you

Use startswith() on each record to test for <HEADLINE and the string find function to locate the double quotation marks.

Use startswith() on each record to test for <HEADLINE and the string find function to locate the double quotation marks.

Thanks.. I dont need startswith() becose the first file have no exact structure. I want generate a html page from the first file with HTMLgen module. So the structure of the first file is changing from what I want in the web page.
For example program read <HEADLINE text="This is headline 1"> and write to the sec. file: hd.append(Heading(1,"This is headline 1")) and this will generate with htmlgen: <h1>This is headline 1</h1> to the blabla.html file :)

I understand there is a language barrier so please explain if and how you identify this record

For example program read <HEADLINE text="This is headline 1"> and write to the sec. file:

if you are not using startswith(), and we can go on from there. If you have existing code that does this, or anything else, please post the code, or at least a summary of it, so we don't cover things already completed.

If you have existing code that does this, or anything else, please post the code, or at least a summary of it, so we don't cover things already completed.

I have nothing completed :) Iam trying to find out how I must do that..an algorithm.
I must make a program witch:

  1. will read a text file where the user will write the structure of web page (where is headline, picture and where is text files in witch are long texts for paragraphs etc.)
  2. and pursuant to this informations the program will generate a html page

I understand there is a language barrier so please explain if and how you identify this record

The program will read the text file, where is written what would be in the web page. So the program will read for example:
<HEADLINE text="This is headline 1">
<PARAGRAPH file="path to the file.txt">
And pursuant to this informations what will be the in the web page, the program will write another python program witch will generate the web page.
So I will have

  1. Program witch will generate a new program pursuant to the informations in text file
  2. a new program witch will generate the final web page
  3. The text file where is written by user, what will be in the web page and where are text files for paragraphs and pictures etc.
  4. Text files for paragraphs and pictures...

Yes I know it is difficult..to understand me. Please ask if you dont understand something

So first you do something like this.

html = '''\
<HEADLINE text="This is headline 1">
<PARAGRAPH file="path to the file.txt">'''

l = []
for item in html.split('\n'):
    if item.startswith('<HEADLINE'):
        l.append(item.split('"')[1])
        ll = ''.join(l)
print ll
'''Out-->
This is headline 1
'''

And then you want that text to go in a new html code?
Eksp. <p>This is headline 1p> .

To take out elements from webpages look at.
BeautifulSoup and lxml

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.