Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print output none
#1
Photo 
Hi! I have an json (I will attach photo) and I want to extract from it a dictionary e.g. {name: [longitude, longitude]}
    import json
    tags = {} 
    coordonate = {}
    dictionar_coordonate = {}

    with open('json_generat.json') as f:
        data = json.load(f)

    def get_names(data):
        lista_nume = []
        for el in data:
            lista_nume.append(el['name'])
        return lista_nume

    def get_coordonate(name):
        lista_coordonate = []
        for el in data:
            if el['name'] == name:
                lista_coordonate.extend([el['latitude'],el['longitude']]) [u]-> the list is created[/u]
            break

    def get_latitude_longitude():
        global dictionar_coordonate
        names = get_names(data)
        for name in names:
            dictionar_coordonate[name] = get_coordonate(name) -> [u]when I get here the output is {'name': None, ...}[/u]

    def afiseaza():
        for name in dictionar_coordonate.keys():
            print('#'*50)
            print('*'*10, 'Tags of', name, '*'*10)
            print('-'*50)
            print(', '.join(dictionar_coordonate[name]))
            print('-'*50)

    def start():
        get_tags()
        afiseaza()
        get_latitude_longitude()

    start()
buran write Nov-01-2021, 06:39 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.

Attached Files

Thumbnail(s)
   
Reply
#2
Please take down the thumbnail. You shouldn't post addresses and phone numbers. It is also harder to test json code without a json file. Make a fake json file for testing and post that along with your code.
buran likes this post
Reply
#3
(Nov-01-2021, 08:10 PM)deanhystad Wrote: Please take down the thumbnail. You shouldn't post addresses and phone numbers. It is also harder to test json code without a json phone. Make a fake json file for testing and post that along with your code.
it's a fake one, it's random generated
Reply
#4
cross-posted on StackOverflow
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
i found the problem
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python VS Code: using print command twice but not getting output from terminal kdx264 4 1,035 Jan-16-2023, 07:38 PM
Last Post: Skaperen
  How to output one value per request of the CSV and print it in another func? Student44 3 1,280 Nov-11-2022, 10:45 PM
Last Post: snippsat
  How to print the output of a defined function bshoushtarian 4 1,237 Sep-08-2022, 01:44 PM
Last Post: deanhystad
Sad Want to Save Print output in csv file Rasedul 5 10,689 Jan-11-2022, 07:04 PM
Last Post: snippsat
  output correction using print() function afefDXCTN 3 10,966 Sep-18-2021, 06:57 PM
Last Post: Sky_Mx
  print (output) taaperaban 3 1,882 Sep-03-2021, 04:23 PM
Last Post: deanhystad
  print function output wrong with strings. mposwal 5 3,047 Feb-12-2021, 09:04 AM
Last Post: DPaul
  Print output not working xninhox 7 3,942 Jan-16-2021, 09:42 AM
Last Post: xninhox
  Output with none, print(x) in function Vidar567 3 2,454 Nov-24-2020, 05:40 PM
Last Post: deanhystad
  Print output in single file using pramika loop deepakkhw 1 2,037 Jul-11-2020, 11:57 AM
Last Post: j.crater

Forum Jump:

User Panel Messages

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