Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json load problem
#6
if __name__ == '__main__':
   obj.method()
This allows the program to execute code differently, depending on how it's started

To illustrate how this works, create the following two very short program:

short.py
def func1():
    print('__name__: {}'.format(__name__))

func1()
stillshort.py
import short

short
Now from a command line, first run:
python short.py
result:
Output:
__name__: __main__
now run:
python stillshort.py
result:
Output:
__name__: short
So, the if
__name__ == '__main__':
will only be true if the program was called directly.
Reply


Messages In This Thread
json load problem - by mepyyeti - Dec-27-2017, 06:10 AM
RE: json load problem - by buran - Dec-27-2017, 07:32 AM
RE: json load problem - by mepyyeti - Dec-27-2017, 07:13 PM
RE: json load problem - by Larz60+ - Dec-27-2017, 08:32 PM
RE: json load problem - by mepyyeti - Dec-27-2017, 09:44 PM
RE: json load problem - by Larz60+ - Dec-28-2017, 02:05 AM
RE: json load problem - by Larz60+ - Dec-28-2017, 02:15 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  JSON Dump and JSON Load foxholenoob 8 1,394 Oct-12-2023, 07:21 AM
Last Post: foxholenoob
  Problem with nested JSON Kalet 7 2,959 Dec-09-2021, 11:13 PM
Last Post: Gribouillis
  Problem With Database Calls and Load Timbo03 1 2,184 Nov-21-2021, 10:48 AM
Last Post: Timbo03
  Problem with Json Array kwekey 2 1,750 Aug-02-2021, 05:11 PM
Last Post: kwekey
  Problem to parse a json enigma619 3 2,474 Dec-04-2020, 08:16 AM
Last Post: enigma619
  Python - help with getting JSON from one DB and load to another DB qIekm 4 3,459 Apr-16-2020, 07:07 AM
Last Post: qIekm
  json problem enigma619 9 3,899 Dec-19-2019, 08:29 AM
Last Post: enigma619
  problem with mapnik in anaconda python 2: from _mapnik import * ImportError: DLL load parsley 0 1,971 Dec-11-2019, 07:50 AM
Last Post: parsley
  Output to a json file problem Netcode 3 3,860 Nov-22-2019, 01:44 AM
Last Post: Skaperen
  Load JSON file data into mongodb using pymongo klllmmm 1 11,993 Jun-28-2019, 12:47 AM
Last Post: klllmmm

Forum Jump:

User Panel Messages

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