Reading multiple files from Unix directory. I am trying to read multiple files stored in Unix folder and extract Key Value Pair after this bit of text "input1".
Each Files consist data in below formats:-
input1 = {'hostname' : 'host', 'port' : '22', 'basedn' : 'CN=Users', 'bindusername' : 'admin']
Need to read dict and extract Key Value pair and print in below format:
Col1 Col2
xyz 123
abc 456
def 756
path = '/home/var/testfile/'
basepath =os.path.dirname(path)
with os.scandir(basepath) as entries:
for entry in entries:
if entry.is_file():
fn=entry.name
def f(fn):
with open(fn) as f:
for s in f:
data = pd.DataFrame()
key = []
value = []
for k, v in s.items():
key.append(k)
value.append(v)
data["Col1"] = key
data["Col2"] = value
print(data)
Above script does wotk when for a single file , but when i loop to read all the files from the folder , it stucked .