Python Forum
Creating Dictionary form LOG /text file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Creating Dictionary form LOG /text file
#6
(Feb-12-2019, 11:08 PM)DG1234 Wrote: My requirements how to create DICTIONARY FROM THAT TEXT/LOG FILE. We have to create data in a Dictionary form from the file.
@buran dos that.
message = json.loads(json_message)
After json.load() it's a Python dictionary.
>>> type(message)
<class 'dict'>

>>> message
{'sourceSysAcctNumber': '22222222222',
 'sourceSysCode': 'TP',
 'transactions': [{'AcctTypeCode': 'DD',
                   'BranchNumber': '000y',
                   'Desc': '02/05 FEDEXOFFICE 00 YYYYY',
                   'ProductCode': '104',
                   'TransCode': 'YYY'}]}

>>> message['sourceSysAcctNumber']
'22222222222'

# When coming from json is also normal to have list mixed into the dictionary
>>> message['transactions'][0]['ProductCode']
'104'
Reply


Messages In This Thread
Creating Dictionary form LOG /text file - by DG1234 - Feb-12-2019, 07:51 PM
RE: Creating Dictionary form LOG /text file - by snippsat - Feb-12-2019, 11:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Help creating shell scrip for python file marciokoko 10 1,579 Sep-16-2023, 09:46 PM
Last Post: snippsat
  Form that puts diacritics on the words in the text Melcu54 13 1,738 Aug-22-2023, 07:07 AM
Last Post: Pedroski55
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,226 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Creating csv files from Excel file azizrasul 40 6,404 Nov-03-2022, 08:33 PM
Last Post: azizrasul
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,836 Apr-13-2022, 06:02 AM
Last Post: Paqqno
Question How do I skipkeys on json file read to python dictionary? BrandonKastning 3 2,016 Mar-08-2022, 09:34 PM
Last Post: BrandonKastning
  trying to write a dictionary in a csv file CompleteNewb 13 6,928 Mar-04-2022, 04:43 AM
Last Post: deanhystad
  Converted Pipe Delimited text file to CSV file atomxkai 4 7,247 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  Creating file with images BobSmoss 1 1,458 Jan-08-2022, 08:46 PM
Last Post: snippsat
  Class-Aggregation and creating a list/dictionary IoannisDem 1 2,016 Oct-03-2021, 05:16 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

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