title: Convert numpy, list or float to string in python
body: <p>I'm writing a python function to append data to text file, as shown in the following,</p>
  
  <p>The problem is the variable, <code>var</code>, could be a 1D numpy array, a 1D list, or just a float number, I know how to convert <code>numpy.array</code>/<code>list</code>/<code>float</code> to string separately (meaning given the type), but is there a method to convert <code>var</code> to string without knowing its type?  </p>
  
  <pre><code>def append_txt(filename, var):
      my_str = _____    # convert var to string
      with open(filename,'a') as f:
          f.write(my_str + '\n')
  </code></pre>
  
  <p>Edit 1: Thanks for the comments, sorry maybe my question was not clear enough. 
  <code>str(var)</code> on numpy would give something like <code>[]</code>. For example, <code>var = np.ones((1,3)), str(var)</code> will give <code>[[1. 1. 1.]]</code>, and <code>[]</code> is unwanted,</p>
  
  <p>Edit 2: Since I want to write clean numbers (meaning no <code>[</code> or <code>]</code>), it seems type checking is inevitable.</p>