title: How can I replace "cat" and "echo" read/write command with python/c program?
body: <p>I have trouble replacing device in/output commands like:</p>
  
  <pre><code>echo 100 &gt; /dev/rtmotor_raw_l0   # output 100hz frequency
  </code></pre>
  
  <pre><code>cat /dev/rtswitch0 # read switch state
  </code></pre>
  
  <h2>output problem(python)</h2>
  
  <p>I tried replacing that command with python.</p>
  
  <pre><code>file = open('/dev/rtmotor_raw_l0','w')
  file.write('100\n')            # I want output in this timing
  file.close()                   # output reflected after closing file
  </code></pre>
  
  <p>The problem is that the output appears after closing the file.
  Does this mean I have to open and close this device each time I want to change its value? Also, changing <code>'w'</code> to <code>'a'</code> did not work.</p>
  
  <h2>input problem(python)</h2>
  
  <p>Almost the same problem happens in input observation.</p>
  
  <pre><code>file = open('/dev/rtswitch','r')
  file.read()  # works
  file.read()  # after first read it does't work anymore
  file.close() # need to reopen the file to get newer value
  </code></pre>
  
  <p>I could only read 1 input in each opening files.</p>
  
  <p>So, currently <strong>I have to reopen the devices each time I want to write/read new values</strong>.
  Are there any way to avoid this problem? </p>
  
  <p>Thank you.</p>