1

My video_man.txt file contains a table I created using PrettyTable to organize the output. Is there a way to get a similar output as shown without using PrettyTable module?

Type Name                        Video Version

Sole/Viewer                         0.2.5
Sole/Pedal                          0.1.5
Cram/Node                           0.2.8

Here is code I created using PrettyTable:

def create_table(TypeList):
    p = PrettyTable()
    p.field_names = ["Type Name", "Video Version"]
    for (typeName, testPath) in TypeList:
        video_version_string = extract_video_version(testPath)
        p.add_row([typeName, video_version_string])
        # Generate text file
        print(root_directory)
        file = open(root_directory + "/video_release.txt", "w")
        file.write(str(p))
        file.close()

This code yields the following output

+---------------------------------------+------------------+
|              Type Name                |   Video Version  |
+---------------------------------------+------------------+
|             Sole/Viewer               |       0.2.5      |
|             Sole/Pedal                |       0.1.5      | 
|             Cram/Node                 |       0.2.8      |
|                                       |                  |
+---------------------------------------+------------------+

I was simply experimenting with PrettyTable but don't want to use it since I can't use modules in my scenario. I tried to manipulate the code a bit to try and get the output shown in the first result in the beginning, but I am struggling to get the correct output. Here is the code:

def create_table(TypeList):
    field_names = ["Type Name", "Video Version"]
    for (typeName, testPath) in TypeList:
        video_version_string = extract_video_version(testPath)
        test_list = [
            [typeName, video_version_string]
        ]
        print("{:<8} {:<15} {:<10}".format('Type Name','Video Version'))
        for data in test_list:
            typeName, video_version_string = data
            print("{:<8} {:<15} {:<10}".format(typeName, video_version_string))
        # Generate text file
        print(root_directory)
        file = open(root_directory + "/video_release.txt", "w")
        file.write(test_list)
        file.close()

Your help is appreciated. Thank you.

CodeBron
  • 25
  • 5
  • Why don't you want to use `PrettyTable`? What "scenario" is this where you "can't use modules"? – Karl Knechtel Jul 08 '21 at 23:38
  • I'm basically building through command line and this file is getting executed so I would have to change some things around in different files to allow the build to run properly, which I'm not allowed to do. Another user would have to install PrettyTable on their machine and I don't want that. – CodeBron Jul 08 '21 at 23:39
  • What do you mean "allowed to do"? Who or what is preventing you? – Karl Knechtel Jul 08 '21 at 23:40
  • Does it matter? It's a personal project I'm working on with friends and we don't want to make changes to build scripts yet. I'm simply just trying to find a way to get it to work without libraries. – CodeBron Jul 08 '21 at 23:42

0 Answers0