This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients docs@python, georg.brandl, jgehrcke, jwilk, krivushinme, pitrou, r.david.murray, vstinner, zach.ware
Date 2020-06-08.17:25:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591637118.48.0.413477965829.issue23427@roundup.psfhosted.org>
In-reply-to
Content
Example of sys.orig_argv usage to re-execute the Python process with different options:
---
import sys
import os
if not sys.flags.utf8_mode:
    # Force UTF-8 mode
    argv = sys.orig_argv.copy()
    argv[1:1] = ["-X", "utf8"]
    print(f"Re-execute to force UTF-8 mode! argv={argv}")
    os.execv(argv[0], argv)

print(f"Everybody loves UTF-8! utf8_mode={sys.flags.utf8_mode}")
---

Example coming from discussions on the PEP 597 :-)

Output:
---
$ ./python force_utf8_mode.py 
Re-execute to force UTF-8 mode! argv=['./python', '-X', 'utf8', 'force_utf8_mode.py']
Everybody loves UTF-8! utf8_mode=1
---
History
Date User Action Args
2020-06-08 17:25:18vstinnersetrecipients: + vstinner, georg.brandl, pitrou, jwilk, r.david.murray, jgehrcke, docs@python, zach.ware, krivushinme
2020-06-08 17:25:18vstinnersetmessageid: <1591637118.48.0.413477965829.issue23427@roundup.psfhosted.org>
2020-06-08 17:25:18vstinnerlinkissue23427 messages
2020-06-08 17:25:18vstinnercreate