Python - How to find UUID of computer and set as variable
<p>I have been looking all over the internet for a way to find a way to get UUID for a computer and set it as a variable in python. </p>

<p>Some of the ways I tried doing didn't work.</p>

<p>Original idea:</p>

<pre><code>import os
x = os.system("wmic diskdrive get serialnumber")
print(x)
</code></pre>

<p>However this does not work, and only returns 0. </p>

<p>I am wondering if their is a way i can find a unique Harddrive ID or any other type of identifier in python. </p>

<p>The os.system function returns the exit code of the executed command, not the standard output of it.</p>

<p>According to <a href="https://docs.python.org/3.4/library/os.html#os.system" rel="nofollow">Python official documentation</a>:</p>

<blockquote>
  <p>On Unix, the return value is the exit status of the process encoded in the format specified for wait(). </p>
  
  <p>On Windows, the return value is that returned by the system shell
  after running command.</p>
</blockquote>

<p>To get the output as you want, the recommended approach is to use some of the functions defined in the subprocess module. Your scenario is pretty simple, so subprocess.check_output works just fine for it.</p>

<p>You just need to replace the code you posted code with this instead:</p>

<pre><code>import subprocess
x = subprocess.check_output('wmic csproduct get UUID')
print(x)
</code></pre>

python python-3.x hwid