Python os.environ[“HOME”] works on idle but not in a script

前端 未结 3 1836
甜味超标
甜味超标 2021-02-07 08:18

I am working on a simple Python (2.7.3) script, but I have to get the user\'s Home Folder. I tried:

import os
home_folder = os.environ[\"HOME\"]
<
3条回答
  •  北荒
    北荒 (楼主)
    2021-02-07 08:41

    Sounds like you're trying to run this on Windows based entirely on your "[launching] it from the cmd". IDLE is giving you that as a convenience; on Windows use USERPROFILE instead of HOME. The %USERPROFILE% envar is the Win32 $HOME.

提交回复
热议问题