How to Retrieve name of current Windows User (AD or local) using Python?

How can I retrieve the name of the currently logged in user, using a python script? The function should work regardless of whether it is a domain/ad user or a local user. Try this: import os; print os.environ.get( "USERNAME" ) That should do the job. as in https://stackoverflow.com/a/842096/611007 by Konstantin Tenzin Look at getpass module import getpass getpass.getuser() Availability

如何使用Python检索当前Windows用户的名称(AD或本地)?

如何使用python脚本检索当前登录用户的名称? 无论是域/广告用户还是本地用户,该功能都应该可以工作。 尝试这个: import os; print os.environ.get( "USERNAME" ) 这应该能够完成这项工作。 如Konstantin Tenzin的https://stackoverflow.com/a/842096/611007中所述 看看getpass模块 import getpass getpass.getuser() 可用性:Unix,Windows 注意:“该函数查看各种环境变量的值来确定用户名,因此,不应该将此函

How to make Python get the username in windows and then implement it in a script

I know that using getpass.getuser() command, I can get the username, but how can I implement it in the following script automatically? So i want python to find the username and then implement it in the following script itself. Script: os.path.join('..','Documents and Settings','USERNAME','Desktop')) (Python Version 2.7 being used) os.getlogin() return the us

如何让Python在Windows中获取用户名,然后在脚本中实现它

我知道使用getpass.getuser()命令,我可以获得用户名,但是如何在下面的脚本中自动实现它? 所以我想Python找到用户名,然后在下面的脚本本身实现它。 脚本: os.path.join('..','Documents and Settings','USERNAME','Desktop')) (正在使用Python版本2.7) os.getlogin()返回正在执行的用户,所以它可以是: path = os.path.join('..','Documents and Settings',os.g

How to change directory according to the username?

This question already has an answer here: Is there a portable way to get the current username in Python? 11 answers pwd.getpwnam(username).pw_dir is the home directory of username . The user executing the program has username os.getlogin() . "I know that python doesn't have variables" -- that's nonsense. You obviously mean environment variables, which you can access usi

如何根据用户名更改目录?

这个问题在这里已经有了答案: 有没有一种可移植的方式来获取Python中的当前用户名? 11个答案 pwd.getpwnam(username).pw_dir 是username的主目录。 执行该程序的用户具有用户名os.getlogin() 。 “我知道python没有变量” - 这是无稽之谈。 你显然是指可以使用os.getenv或os.environ访问的环境变量。 也许有更好的答案,但你总是可以使用命令调用: import commands user_dir = commands.getoutput("cd; pwd")

How do I dynamically generate a file name in python?

This question already has an answer here: Is there a portable way to get the current username in Python? 11 answers 既然你只需要用户名: import getpass user = getpass.getuser() fname = "com.strange.things." + user + ".more.strange.things"

我如何在python中动态生成文件名?

这个问题在这里已经有了答案: 有没有一种可移植的方式来获取Python中的当前用户名? 11个答案 既然你只需要用户名: import getpass user = getpass.getuser() fname = "com.strange.things." + user + ".more.strange.things"

Getting User From Within Python Script

This question already has an answer here: Is there a portable way to get the current username in Python? 11 answers As noted in my comment, the answer is given here: https://stackoverflow.com/a/842096/2531279 Note: this is available for Windows and Unix Wouldn't it depend on what OS you are running the script on? Running shell commands is more common on some flavor of Linux but it c

从Python脚本中获取用户

这个问题在这里已经有了答案: 有没有一种可移植的方式来获取Python中的当前用户名? 11个答案 正如我的评论中指出的那样,答案在这里给出:https://stackoverflow.com/a/842096/2531279 注意:这适用于Windows和Unix 这不取决于你在哪个操作系统上运行脚本? 运行shell命令在某些Linux上更常见,但它可能是Windows或Mac机器。 Python可能有办法跨平台,我不知道。

how to get linux username in a python program

This question already has an answer here: Is there a portable way to get the current username in Python? 11 answers Could os.getlogin() be what you are looking for? (https://docs.python.org/3/library/os.html#os.getlogin) >>> import os >>> os.getlogin() 'msurrow' >>> Or maybe getpass.getuser() (https://docs.python.org/3.1/library/getpass.html) >>> impo

如何在python程序中获取linux用户名

这个问题在这里已经有了答案: 有没有一种可移植的方式来获取Python中的当前用户名? 11个答案 可能os.getlogin()是你在找什么? (https://docs.python.org/3/library/os.html#os.getlogin) >>> import os >>> os.getlogin() 'msurrow' >>> 或者,也许getpass.getuser()(https://docs.python.org/3.1/library/getpass.html) >>> import getpass >>> getpass.getu

Cross platform solution for getting current login name in Python

This question already has an answer here: Is there a portable way to get the current username in Python? 11 answers getpass.getuser()是你的朋友。 这是我使用的: import os username = getattr(os, "getlogin", None) if not username: for var in ['USER', 'USERNAME','LOGNAME']: if var in os.environ: username = os.environ[var] print("username: %s" % (username))

用Python获取当前登录名的跨平台解决方案

这个问题在这里已经有了答案: 有没有一种可移植的方式来获取Python中的当前用户名? 11个答案 getpass.getuser()是你的朋友。 这是我使用的: import os username = getattr(os, "getlogin", None) if not username: for var in ['USER', 'USERNAME','LOGNAME']: if var in os.environ: username = os.environ[var] print("username: %s" % (username))

How do I get the username in Python?

Possible Duplicate: Is there a portable way to get the current username in Python? How can I get the username of the account by which the given script is being executed? import getpass print getpass.getuser()

我如何在Python中获取用户名?

可能重复: 有没有一种可移植的方式来获取Python中的当前用户名? 我如何获得指定脚本执行的帐户的用户名? import getpass print getpass.getuser()

whoami in python

This question already has an answer here: Is there a portable way to get the current username in Python? 11 answers import getpass print getpass.getuser() See the documentation of the getpass module. getpass.getuser() Return the “login name” of the user. Availability: Unix, Windows. This function checks the environment variables LOGNAME, USER, LNAME and USERNAME, in order, and returns

蟒蛇中的whoami

这个问题在这里已经有了答案: 有没有一种可移植的方式来获取Python中的当前用户名? 11个答案 import getpass print getpass.getuser() 请参阅getpass模块的文档。 getpass.getuser() 返回用户的“登录名”。 可用性:Unix,Windows。 该函数按顺序检查环境变量LOGNAME,USER,LNAME和USERNAME,并返回第一个设置为非空字符串的值。 如果没有设置,则会在支持pwd模块的系统上返回密码数据库的登录名,否则会引发异

Python Using Multiprocessing

I am trying to use multiprocessing in python 3.6. I have a for loop that runs a method with different arguments. Currently, it is running one at a time which is taking quite a bit of time so I am trying to use multiprocessing. Here is what I have: def test(self): for key, value in dict.items(): pool = Pool(processes=(cpu_count() - 1)) pool.apply_async(self.thread_process,

Python使用多处理

我想在python 3.6中使用多处理。 我有一个用不同参数运行一个method的for loop 。 目前,它每次都在运行一个,这需要花费很长时间,所以我正在尝试使用多处理。 这是我的: def test(self): for key, value in dict.items(): pool = Pool(processes=(cpu_count() - 1)) pool.apply_async(self.thread_process, args=(key,value)) pool.close() pool.join() def thread_process(self, k