What is __name__ for in Python /

What is the if __name__ condition in Python for? If you've seen __main__ at the end of a Python script and wondered why that is there it is to avoid side effects when importing and allowing you to run the file as a script on the terminal. If you want more details, watch this short video where w...

Full description

Bibliographic Details
Main Authors: Deza, Alfredo (Author), Gift, Noah (Author)
Corporate Author: Safari, an O'Reilly Media Company
Format: eBook
Language:English
Published: Pragmatic AI Solutions, 2022.
Edition:1st edition
Subjects:
Online Access:Connect to this electronic resource

MARC

Tag First Indicator Second Indicator Subfields
LEADER 00000ngm a2200000 a 4500
001 in00004560421
006 m o d
007 cr cn
008 110222s2022 xx o v eng
005 20260122202654.3
020 |z 50130VIDEOPAIML 
024 8 |a 50130VIDEOPAIML 
035 |a (CaSebORM)50130VIDEOPAIML 
041 0 |a eng 
100 1 |a Deza, Alfredo,  |e author. 
245 1 0 |a What is __name__ for in Python /  |c Deza, Alfredo. 
250 |a 1st edition 
264 1 |b Pragmatic AI Solutions,  |c 2022. 
300 |a 1 online resource (1 video file, approximately 3 min.) 
336 |a two-dimensional moving image  |b tdi  |2 rdacontent 
337 |a computer  |b c  |2 rdamedia 
338 |a online resource  |b cr  |2 rdacarrier 
347 |a video file 
520 |a What is the if __name__ condition in Python for? If you've seen __main__ at the end of a Python script and wondered why that is there it is to avoid side effects when importing and allowing you to run the file as a script on the terminal. If you want more details, watch this short video where we work with a Python script to find out those side effects and how the Python script can change once the if condition with __name__ is done at the end. Next Steps Now that you know about the conditional at the end, you might want to explore writing Python scripts that use this trick. There are several examples you can follow in these GitHub repositories with argparse , the Click framework and using sys.argv : argparse GitHub repo examples sys.argv GitHub repo examples Build Python applications from scratch 
533 |a Electronic reproduction.  |b Boston, MA :  |c Safari,  |n Available via World Wide Web.  |d 2022. 
538 |a Mode of access: World Wide Web. 
542 |f © Pragmatic AI Solutions  |g 2022 
550 |a Made available through: Safari, an O'Reilly Media Company. 
588 0 |a Online resource; Title from title screen (viewed February 11, 2022) 
655 7 |a Electronic videos.  |2 local 
700 1 |a Gift, Noah,  |e author. 
710 2 |a Safari, an O'Reilly Media Company. 
856 4 0 |u https://proxy.library.tamu.edu/login?url=https://go.oreilly.com/TAMU/library/view/-/50130VIDEOPAIML/?ar  |z Connect to this electronic resource  |t 0 
999 f f |s 091ad08c-aece-48e5-aeb8-0c023e17b0ce  |i 091ad08c-aece-48e5-aeb8-0c023e17b0ce  |t 0 
952 f f |a Texas A&M University  |b College Station  |c Electronic Resources  |s www_evans  |d Available Online  |t 0  |h Library of Congress classification 
998 f f |t 0  |l Available Online