<div dir="ltr"><div>Hello folks who know about the python script construction :)</div><div><br></div><div>The pattern used in all of the python scripts under swig/python/gdal-utils is foreign to me. Can someone explain what's going on and why it's used? (or point to where this has been explored already).</div><div><br></div><div>
<div>
<div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(0,0,255)">if</span><span style="color:rgb(0,0,0)"> __name__ == </span><span style="color:rgb(163,21,21)">'__main__'</span><span style="color:rgb(0,0,0)">:</span></div><div><span style="color:rgb(0,0,0)"> sys.exit(main(sys.argv))</span></div></div>
</div>
</div><div><br></div><div>Gdal utils .py all end with the block above. Everything else I've used to this point are more like:</div><div><br></div><div>
<div>
<div style="color:rgb(0,0,0);background-color:rgb(255,255,255);font-family:Consolas,"Courier New",monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(0,0,255)">if</span><span style="color:rgb(0,0,0)"> __name__ == </span><span style="color:rgb(163,21,21)">'__main__'</span><span style="color:rgb(0,0,0)">:</span></div><div><span style="color:rgb(0,0,0)"> main(sys.argv)</span></div></div>
</div>
</div><br><div>The motivation for asking (besides just being curious about something new!) is that I'm trying to figure out how we can use pip to create standard launch wrappers in PYTHONHOME\Scripts instead of manual post-install setup of the batch files we use now. When I change setup.py to do this via console_scripts the resulting wrappers fail on this main construct. So I need to understand what the original intent is to try and come up with a remedy.<br></div><div><br></div><div>```<br></div><div>» gdal_edit fooo<br>Traceback (most recent call last):<br> File "C:\Users\Matt\.conda\envs\gdal\Scripts\gdal_edit-script.py", line 33, in <module><br> sys.exit(load_entry_point('gdal-utils', 'console_scripts', 'gdal_edit')())<br>TypeError: main() missing 1 required positional argument: 'argv'</div><div>```<br></div><div><br></div>Thanks!<br><br>Matt</div>