I'm new to Python and posting my first Python post :) I'm using python to script creating 100 JSON messages. The JSON has loads of records so I am automating randomly generating test data by printing it using random functions etc. The hierarchy of the JSON is as follows:
- JSON Header
- Message Transaction Details
- Main Message Content
- Item Specific Message Content
- Other Message Content
In the Main Message Content there is an item field that is one of three options and if One is selected then the script will print whatever is relevant to One and so on as each item will have different attributes.
Below is my code, for whatever reason I am not able to get the code working to say if one is selected in the print statement then do X and if two is printed then do Y and so on.
Can anyone help me with my logic
import random
item = ["One", "Two", "Three"]
c = 100
while c > 0:
# JSON Header
print('{JSON Header Goes Here')
print(" }", "\n"
"}")
# Message Transaction Data
print("Loads of stuff related to the transaction")
# Main Message Content Item
items = print(random.choice(item))
print("Loads of stuff stuff related to the message content")
if item == "One":
print("Loads of stuff related to the item 1")
elif item == "Two":
print("Loads of stuff related to the item 3")
elif item == "Three":
print("Loads of stuff related to the item 3")
continue
# Other Message Content
print("Loads of stuff related to other message content")
print('\n')
c = c - 1
NB - The reason for doing this is in Python was to help me learn Python, not sure if this is best practice or the right way to do stuff but thought it'd get me coding and I'm enjoying it ;)
Aucun commentaire:
Enregistrer un commentaire