Python Forum
Creating csv file from another file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating csv file from another file
#1
I have a file that is exported from an upstream system and data is not the same in each row.

But the main attributes in the file are below. Not all the rows might have all the attributes.

unitnumber
idnumber
mail
givenname
manager
department
city
title
mobile

Contents in the file are as below and can only have the above attributes.

i/p:
Quote:('uid=test.test51,ou=People,o=ic.com,o=xerox', {'city': ['Irving'], 'title': ['Application Developer'], 'mobile': ['2054444444'], 'manager': ['test.test100'], 'idnumber': ['44451'], 'department': ['National Claims'], 'mail': ['[email protected]'], 'givenname': ['Test1'], 'unitnumber': ['551']})
('uid=pinuser,ou=People,o=ic.com,o=xerox', {'givenname': ['Pin']})
('uid=jim.gober,ou=People,o=ic.com,o=xerox', {'city': ['Birmingham'], 'title': ['CEO'], 'manager': ['jim.gober'], 'idnumber': ['137741'], 'department': ['Executive'], 'givenname': ['James'], 'unitnumber': ['887']})
('uid=ServiceAdmin,ou=People,o=ic.com,o=xerox', {})
('uid=joann.kerr,ou=People,o=ic.com,o=xerox', {'city': ['Alpharetta'], 'title': ['Senior Software Architect'], 'manager': ['Cynthia Berger'], 'idnumber': ['0003677'], 'department': ['Information Technology'], 'givenname': ['Joann'], 'unitnumber': ['SHD']})

I need to create a csv file from this that has the data in the below format


required o/p:

1st line with header that can be static followed by the data from the above file.
Quote:unitnumber,idnumber,mail,givenname,manager,department,city,title,mobile
551,44451,[email protected],Test1,test.test100,National Claims,Irving,Application Developer,2054444444
,,,Pin,,,,,
887,137741,,James,jim.gober,Executive,Birmingham,CEO,
,,,,,,,,
SHD,0003677,,Joann,Cynthia Berger,Information Technology,Alpharetta,Senior Software Architect,

Any help is appreciated
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to write variable in a python file then import it in another python file? tatahuft 4 1,005 Jan-01-2025, 12:18 AM
Last Post: Skaperen
  JSON File - extract only the data in a nested array for CSV file shwfgd 2 1,129 Aug-26-2024, 10:14 PM
Last Post: shwfgd
  FileNotFoundError: [Errno 2] No such file or directory although the file exists Arnibandyo 0 1,125 Aug-12-2024, 09:11 AM
Last Post: Arnibandyo
  "[Errno 2] No such file or directory" (.py file) IbrahimBennani 13 6,738 Jun-17-2024, 12:26 AM
Last Post: AdamHensley
  file open "file not found error" shanoger 8 8,935 Dec-14-2023, 08:03 AM
Last Post: shanoger
  Help creating shell scrip for python file marciokoko 10 3,555 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Need to replace a string with a file (HTML file) tester_V 1 1,982 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  How can I change the uuid name of a file to his original file? MaddoxMB 2 2,269 Jul-17-2023, 10:15 PM
Last Post: Pedroski55
  Reading data from excel file –> process it >>then write to another excel output file Jennifer_Jone 0 2,147 Mar-14-2023, 07:59 PM
Last Post: Jennifer_Jone
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 2,090 Dec-15-2022, 04:32 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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