'The function doesn't work when called within other functions
I am learning Python and trying to write a Python program to read a json file and based on a key in the json I want to get the values. I have not finished the complete code but just some part of it and got stuck in between when using the function. Following is the code:
import json
def read_txt_file(file2):
with open(file2,'r') as fc:
client_data = fc.readlines()
#print("----------------------")
#print("client data is", type(client_data))
#print ("length is", len(client_data))
for i in range(len(client_data)):
client_data[i] = client_data[i].lower().strip()
return client_data
def getting_values_from_dict():
print("hello")
def read_json_file(file1):
with open(file1, 'r') as fh:
data = json.load(fh)
for key,value in sorted(data.items()):
return read_txt_file("client.txt")
getting_values_from_dict()
o=read_json_file("data_usage_20220203.json")
print(o)
Here the output I am getting is a list with values from the file client.txt which is correct if the function getting_values_from_dict is not included. But when I include the function getting_values_from_dict which just prints "Hello" as shown above, it is not working. This function when called within any of the above function is not printing hello in the terminal. Why so? What is the mistake in this code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
