Python Forum
File loop curiously skipping files - FIXED
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
File loop curiously skipping files - FIXED
#4
Sorry, I don't understand.

I believe you want to put the path and names of video files in an html table. Is that correct?

These names are just strings, not the actual files. So I am not sure where you are getting 60K from??

html is just a text file. So create the html table as a list, then ''.join(html_list).

You need something like these basic tags to make the html table list. In my case, the formatting is done in separate css files (which you can also generate using Python!)

tableStart = '<div class="div-table">\n<table>\n'
rowBegin = '<tr>'
if header[0] == 'False':
    tableHeader = '<td>X</td>'
elif header[0] == 'True':
    tableHeader = '<th>X</th>'
tableData = '<td>X</td>'
rowEnd = '</tr> \n'
tableEnd = '</table><br> \n  </div><br> \n \n \n'
numCols = int(numberColumns[0])  


glob.glob() above produces a list of 4 lists, 1 list for each type of video file you want.

If you loop through these lists, appending each list element to a list like dataTable = [], below, according to the number of columns you want, just replace X in '<td>X</td>' with each path or file in the lists. Add <tr> and </tr> to each row.

Finally, you join dataTable

newTable = []
newTable.append(tableStart)
for i in range(0, len(dataTable)):
    newTable.append(dataTable[i])
    newTable.append(tableEnd)
# join the list to a string, write the string to your html
newTableString = ' '.join(newTable) 
Write newTableString to your html file.

Most of the time I do this starting with a text file of words or phrases in English and Chinese, so my tables usually only have 2 columns.
Reply


Messages In This Thread
RE: File loop curiously skipping files - by mbk34 - Feb-09-2024, 09:13 AM
RE: File loop curiously skipping files - by Pedroski55 - Feb-09-2024, 09:58 AM
RE: File loop curiously skipping files - by mbk34 - Feb-09-2024, 09:32 PM
RE: File loop curiously skipping files - by mbk34 - Feb-09-2024, 09:32 PM
RE: File loop curiously skipping files - by mbk34 - Feb-09-2024, 12:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [SOLVED] Loop through directories and files one level down? Winfried 3 398 Apr-28-2024, 02:31 PM
Last Post: Gribouillis
  Loop through all files in a directory? Winfried 10 753 Apr-23-2024, 07:38 PM
Last Post: FortuneCoins
  How to do "fixed size" (wrapping) math in Python? AlexanderWulf 13 2,138 Jul-19-2023, 04:13 PM
Last Post: deanhystad
  Fixed colum width for rowLabels i Matplotlib pandabay 0 484 Jun-10-2023, 03:40 PM
Last Post: pandabay
  How to loop through all excel files and sheets in folder jadelola 1 4,726 Dec-01-2022, 06:12 PM
Last Post: deanhystad
  Skipping line in text without Restarting Loop IdMineThat 4 1,601 Apr-05-2022, 04:23 AM
Last Post: deanhystad
  Encrypt and decrypt in python using own fixed key SriRajesh 3 5,278 Feb-20-2022, 01:18 PM
Last Post: dboxall123
  python seems to be skipping lines of code alansandbucket 1 4,291 Jun-22-2021, 01:18 AM
Last Post: Larz60+
  Play fixed frequency sound in python 3 jpezz 2 2,875 Feb-07-2021, 08:21 PM
Last Post: jpezz
  Referencing a fixed cell Mark17 2 2,150 Dec-17-2020, 07:14 PM
Last Post: Mark17

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020