title: Why my code is working in python2 and not in python3
body: <pre><code>import os
  import time
  
  CONSOLE = &quot;/dev/tty0&quot;
  logfd = None
  def log_me(logstr):
      global logfd
      global CONSOLE
  
      print(time.strftime(&quot;%c&quot;)+&quot;: &quot;+logstr)
      if not logfd:
          if not os.path.exists(CONSOLE):
              return
          logfd = open(CONSOLE, &quot;a&quot;)
          if not logfd:
              return
  
      logfd.write(logstr+&quot;\n&quot;)
      logfd.flush()
  
      return
  </code></pre>
  <p>test.py  <br/></p>
  <pre><code>from consolelog import log_me
  
  print (&quot;Hello World!&quot;)
  log_me(&quot;This is a Hello World script&quot;)
  log_me(&quot;Logging 2nd time to see how it works.&quot;)
  log_me(&quot;loging 3rd time&quot;)
  </code></pre>
  <p>The same code is working when used with python2 but throwing error 29 illegal seek when run with python3</p>
  <p>[root@869ebe33-77e8-41b4-918b-eafda978fd98 ~]# python test.py  <br/>
  Hello World!  <br/>
  Wed Apr 14 07:37:03 2021: This is a Hello World script  <br/>
  Wed Apr 14 07:37:03 2021: Logging 2nd time to see how it works.  <br/>
  Wed Apr 14 07:37:03 2021: loging 3rd time  <br/></p>
  <p>output with python3  <br/></p>
  <p>[root@869ebe33-77e8-41b4-918b-eafda978fd98 ~]# python3 test.py  <br/>
  Hello World!  <br/>
  Wed Apr 14 07:37:10 2021: This is a Hello World script  <br/>
  Traceback (most recent call last):  <br/>
  File &quot;test.py&quot;, line 4, in   <br/>
  log_me(&quot;This is a Hello World script&quot;)  <br/>
  File &quot;/root/consolelog.py&quot;, line 14, in log_me  <br/>
  logfd = open(CONSOLE, &quot;a&quot;)  <br/>
  OSError: [Errno 29] Illegal seek  <br/></p>