title: Python Vs C - Handling environment variable in Windows
body: <p>I see a variation in output between C and python code in Windows trying to get the same functionality.  The c code ( similar to unix shell scripts ) shows the TEST1 environment variable in 'test.bat.output' with its value as empty string whereas the python code removes this environment variable.  </p>
  
  <p>Is there a way to ask Python not to remove the environment variable from environ table when it is empty?</p>
  
  <h2>C</h2>
  
  <pre><code>#include &lt;windows.h&gt;
  
  main()
  {
  
    DWORD dwRet;
    char pszOldVal[1024] = "abc";
  
    if(! SetEnvironmentVariable("TEST1", ""))  
      puts("Error\n");
  
    // _putenv("TEST1=");
  
    // GetEnvironmentVariable("TEST1", pszOldVal, dwRet);
    system("cmd /c test.bat &gt;test.bat.output");
  }
  </code></pre>
  
  <h2>Python</h2>
  
  <pre><code>import os
  os.environ['TEST1'] = ""
  os.environ['TEST2'] = "karthik"
  os.system("cmd /c test.bat &gt; test.bat.output.python")
  </code></pre>
  
  <p>-Karthik</p>