add tab in python output - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: add tab in python output (/thread-19322.html) |
add tab in python output - evilcode1 - Jun-23-2019 hello all ... how i can print this output with tab's like this : RE: add tab in python output - Gribouillis - Jun-23-2019 Which python code generated the output without the tabs? RE: add tab in python output - evilcode1 - Jun-23-2019 (Jun-23-2019, 06:26 AM)Gribouillis Wrote: Which python code generated the output without the tabs? import magic import os import pathlib from colorama import Fore, Back import colorama colorama.init(autoreset=True) #p = r"C:\Users\adam\Desktop" p = r"/root/Downloads/image-mount/data/com.google.android.gms/databases" i = 0 for dirName, subdirList, fileList in os.walk(p): i = i + 1 print( '[+]Found Directory:#{0}\t'.format(str(i)) + "|SubDirectory:\t" + str(len(subdirList)) + " | Files:\t" +str(len(fileList))+ Fore.RED +" \t> PATH = " +Fore.RESET + dirName ) try: for fname in fileList: q = os.path.join(dirName, fname) d = magic.from_file(q, mime=True) if d == "application/x-sqlite3": print(Fore.BLUE + ' \t Filename: {0}\t[{1}]'.format(fname,d[12:])) #print("{}. {} appears {} times.".format(i, key, wordBank[key])) except: continue RE: add tab in python output - Gribouillis - Jun-23-2019 You could use a third party module such as prettytable >>> from prettytable import PrettyTable >>> t = PrettyTable() >>> t.add_row(['foo', 'bar']) >>> t.add_row(['baz', 'qux']) >>> t.add_row(['spam', 'eggs']) >>> str(t) '+---------+---------+\n| Field 1 | Field 2 |\n+---------+---------+\n| foo | bar |\n| baz | qux |\n| spam | eggs |\n+---------+---------+' >>> print(t) +---------+---------+ | Field 1 | Field 2 | +---------+---------+ | foo | bar | | baz | qux | | spam | eggs | +---------+---------+ >>> t.header = False >>> t.align = 'l' >>> from prettytable import NONE >>> t.hrules = NONE >>> t.vrules = NONE >>> print(t) foo bar baz qux spam eggs RE: add tab in python output - snippsat - Jun-23-2019 You could use string formatting,should always use f-string .import os insert = '[x-sqlite3]' for fn in os.scandir('.'): print(f'{fn.name:<35}{insert}') Your line 12 is not nice,could delete all + and str and use f-string Here the start of line. >>> i = 999 >>> subdirList = [1,2,3] >>> print('[+]Found Directory:#{0}\t'.format(str(i)) + "|SubDirectory:\t" + str(len(subdirList))) [+]Found Directory:#999 |SubDirectory: 3 >>> >>> # Now the same with f-string >>> print(f'[+]Found Directory:#{i} |SubDirectory: {len(subdirList)}') [+]Found Directory:#999 |SubDirectory: 3 RE: add tab in python output - evilcode1 - Jun-28-2019 thank u all ... snippsat : thank u man this is the simple way :) best solution <3 (Jun-23-2019, 09:00 AM)Gribouillis Wrote: You could use a third party module such as prettytablewhen i use pretytable in my loop it's print them like this way : how i can make add them to the same table ?? not table for each file
|