Skip to main content
added 249 characters in body
Source Link
InSync
  • 439
  • 3
  • 10

This does nothing useful:

def main():
    ...

main()

The idiom to use is:

def main():
    ...

if __name__ == "__main__":
    main()

In accordance with this, these top-level statements should be moved into main() and the functions be redesigned so as not to rely on global constructs:

db = mysql.connector.connect(...)
cursor = db.cursor()
cursor.execute(...)

See also: What does if __name__ == "__main__": do?.

This does nothing useful:

def main():
    ...

main()

The idiom to use is:

def main():
    ...

if __name__ == "__main__":
    main()

See also: What does if __name__ == "__main__": do?.

This does nothing useful:

def main():
    ...

main()

The idiom to use is:

def main():
    ...

if __name__ == "__main__":
    main()

In accordance with this, these top-level statements should be moved into main() and the functions be redesigned so as not to rely on global constructs:

db = mysql.connector.connect(...)
cursor = db.cursor()
cursor.execute(...)

See also: What does if __name__ == "__main__": do?.

Source Link
InSync
  • 439
  • 3
  • 10

This does nothing useful:

def main():
    ...

main()

The idiom to use is:

def main():
    ...

if __name__ == "__main__":
    main()

See also: What does if __name__ == "__main__": do?.

Post Made Community Wiki by InSync