title: How to bcp from SQL server using Python to text file
body: <p>I am having problems with Using python with sqlserver.
  I want to bcp out the results of sql query and save to a pipe delimited file.
  Here's the code I have.</p>
  
  <pre><code>import pypyodbc
  
  connection = pypyodbc.connect('Driver={SQL Server};'
                                  'Server=testserver\dev01;'
                                  'Database=mytestdb;'
                                  'uid=testuser;pwd=readonly')
  cursor = connection.cursor()
  
  SQLCommand = "bcp SELECT * FROM mytestdb.dbo.testReports queryout ""C:/Users/PythonProjects/test.txt"" -Stestserver\dev01 -Utestuser -Preadonly -c -t|"
  cursor.execute(SQLCommand)
  result_set = cursor.fetchall()
  with open('output.txt', 'w') as f:
      for row in result_set:
          f.write();
  </code></pre>
  
  <p>This is the error I get
   pypyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '/'.")</p>
  
  <p>I am a newbie in python and need some help with this.</p>
  
  <p>Thanks
  MR</p>