Get name of users(persons, not applications) in linux system using psutil library
<p>I am trying to use psutil library to get users logged in to linux system.</p>

<p>For that i used function psutil.users()</p>

<pre><code>&gt;&gt;&gt; import psutil
&gt;&gt;&gt; psutil.users()
[suser(name='vibhcool', terminal='tty2',host='localhost',started=1473815296.0)]
</code></pre>

<p>I want to extract the username from this list, what shall i do?
Also what is suser here?</p>

<p>I don't know why they choose the name <code>suser</code>, but it's actually a namedtuple.</p>

<p>That shouldn't matter, you get the name of a user like so:</p>

<pre><code>&gt;&gt;&gt; import psutil
&gt;&gt;&gt; users = psutil.users()
&gt;&gt;&gt; first_user = users[0]
&gt;&gt;&gt; name = first_user.name
&gt;&gt;&gt; print(name)
'vibhcool'
</code></pre>

<p>In short:</p>

<pre><code>&gt;&gt;&gt; import psutil
&gt;&gt;&gt; print(psutil.users()[0].name)
'vibhcool'
</code></pre>

python linux psutil