ro  fr  en  es  pt  ar  zh  hi  de  ru
ART 2.0 ART 3.0 ART 4.0 ART 5.0 ART 6.0 Pinterest

Python: Kopiearje de ynhâld fan tekstbestannen yn it lichem fan HTML-bestannen

On December 23, 2021, in Leadership Quantum-XX, by Neculai Fantanaru

Jo kinne hjir de folsleine koade besjen:Https: // passatin.com / va56 8pn

YnstallearjePython.

Litte wy sizze dat wy ferskate .txt-bestannen hawwe. En wy hawwe mar ien .html-bestân

Yn it lichem fan it .html-bestân is d'r dizze seksje:en. De tekst yn it .txt-bestân sil hjir kopieare wurde.

Jo sille ek in map neamd moatte oanmeitsje:FILS_HTML(Alle nije bestannen sille hjir wurde bewarre). Alle oare bestannen. txt en it .html-bestân binne fergees bûten de map:FILS_HTML

Jo kinne safolle .txt-bestannen hawwe as jo wolle. Sa'n .txt-bestân sil allinich tekst befetsje, lykas:

My name probably does not say anything to you, Walter Elias Disney, 
because I just came back from New York and got only 40 dollars in my pocket.
Increasingly, I need spiritual points to help me not get swallowed by the
most painful miscarriage, the saddest abandon in a labyrinth of vanity
where the only marks are self-forgetting and the others, followed in the
end of supreme sacrifice.

Jo sille allinich ien nedich wêze .html-bestân dat de folgjende seksje befettet:



<p class="obisnuit"><em>Honor your moral and spiritual obligations.em>p>
<p class="nint">Bishop knew how to say the most meaningful of things speech.p>

Utfier:Nei it útfieren fan de koade, sille wy hawwe:



My name probably does not say anything to you, Walter Elias Disney, 
because I just came back from New York and got only 40 dollars in my pocket.
Increasingly, I need spiritual points to help me not get swallowed by the
most painful miscarriage, the saddest abandon in a labyrinth of vanity
where the only marks are self-forgetting and the others, followed in the
end of supreme sacrifice.

CODUL: KOPJE EN RUN DE KODE HJIR LIKE IN ELKE INTERPRETE PROGRAM(Ik brûkPyscripter.Ferjit net it paad te feroarjen op 'e line "crale_fisiere_html". HTML generearre mei Hilite.me

ymport jo
ymport hyt

Def read_text_from_file(File_path):"" "
Dizze funksje jout in bestânynhâld werom.
File_path: De wei nei it bestân dat jo wolle lêze
"" "
    mei iepen(File_path, kodearring='Fail 8')asF:
         tekst=F.lêze()weromkommetekstDef WRITS_TO_FILE(tekst, File_path):"" "
Dizze funksje skriuwt in tekst yn in bestân.
Tekst: De tekst dy't jo wolle skriuwe
File_path: De wei nei it bestân dat jo wolle skriuwe
"" "
    mei iepen(File_path,'Wb')asF:
         F.Skriuw (tekst.Encode ('Fail 8','Negearje'))Def copiaza_continut_txt_html(Path_Fisier_txt, Path_Fisier_HTMl):# Dit binne de arguminten fan 'e funksje, dat is as ik de funksje oansprekke
    # Lês de tekst yn it bestânTEXT_TXT=read_TEXT_FROM_FILE (CALE_FISIER_TXT)
     TEXT_HTML=read_TEXT_FROM_FILE (CALE_FISIER_HTML)# Wy wurde tekst útskeakelje fan bestân yn in tekenrigeTEXT_TXT= Str(text_txt)
     TEXT_HTML= Str(text_html)# Hjir is it patroan foar útdrukking Regex;  (. *?) betsjut dat alles is tusken tags
    # Wizigje reguliere útdrukking ôfhinklik fan hokker tag jout as argumint foar de funksjeartikel_pattern=hyt.gearstalle (' ([\ S] *?)  [\ S \ s] *?')
     Tekst_articol=hyt.Findall (artikol_pattern, text_html)as Len.(Tekst_articol)! = 0List
         Tekst_articol= Str(Tekst_articol [0]))
         TEXT_TXT= '\ n \ n' +TEXT_TXT+ '\ n \ n'TEXT_HTML=TEXT_HTML.ferfange (text_articol, text_txt)
         file_path=jo.paad.dirname (cale_fisier_txt)+ "\\" + "file_html" + "\\" +jo.paad.Splitext (de.paad.Basename (Cale_Fisier_txt)) [0]+ '.html'WRIT_TO_FILE (TEXT_HTML, FILE_PATH)ôfdrukke("Mei súkses skriuwe.")oarsListôfdrukke("HTML-bestân sûnder start / finale item.")Def Creation_Fisiere_HTML(paad_folder_txt, paad_fisier_html):"" "
De funksje wurdt betsjinne troch in map dy't TXT-bestannen befettet en passende HTML-bestannen soarget
"" "
    foarFynjo.ListDIR (Cale_Folder_TXT):asF.Endswith ('txt'):
                 Path_Fisier_txt=cale_folder_txt+ "\\" +F.
                 copiaza_continut_txt_html (paad_fisier_txt, paad_fisier_html)oarsListtrochgean

Def foarnaamste():
     Creation_Fisiere_HTML ("C:\\Folder1 ","C:\\Folder1.\\Oana.tuth ")as__Sa__== '__foarnaamste__'List
     foarnaamste()

That's all folks.

Sjoch ek ditFerzje 2of Ferzje 3ofFerzje 4ofFerzje 5ofFerzje 6ofFerzje 7


Latest articles accessed by readers:

  1. An Eye To See And A Mind To Understand
  2. Turn Towards Me With An Eye Full Of Your Own Gaze
  3. The Snapshot Of Magic In God's Universe
  4. Rhythm Of My Heart

Donate via Paypal

Alternate Text

RECURRENT DONATION

Donate monthly to support
the NeculaiFantanaru.com project

SINGLE DONATION

Donate the desired amount to support
the NeculaiFantanaru.com project

Donate by Bank Transfer

Account Ron: RO34INGB0000999900448439

Open account at ING Bank

Join The Neculai Fantanaru Community



* Note: If you want to read all my articles in real time, please check the romanian version !

decoration
About | Site Map | Partners | Feedback | Terms & Conditions | Privacy | RSS Feeds
© Neculai Fântânaru - All rights reserved