Ask a Question

how to create CSV file and write data?

veerasureshk
Occasional Contributor

how to create CSV file and write data?

Hi, I need to create a new csv file using python scripting and write data in file as per functionality. I know trough aqFile we can create but except this any other methods/way to create a CSV file like Excel  method to create excel files.

 

Thanks in advance.

8 REPLIES 8
rraghvani
Regular Contributor

You can read comma-separated values using DDT.CSVDriver Method, but you can't write.

veerasureshk
Occasional Contributor

Thanks but already I know this method and my requirement is need to create a new CSV file and write data on it.

Marsha_R
Community Hero

aqFile.Create and aqFile.WriteToTextFile should work for you. Why don't you want to use aqFile?


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
veerasureshk
Occasional Contributor

Thank you very much. I can agree with your point but with WriteToTextFile or any other method, shall we write data on particular row or column with respective header. Is it possible? 

 

It looks like this might work better for you. The properties give you access to the row and column numbers in a text file.

 

 https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqtextfile/index.html


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
veerasureshk
Occasional Contributor

Thank you very much for this info. In that link they clearly mentioned for text files only(The aqTextFile object provides programming access to text files.) Then may I know how it will support for other format files and why don't TC provide relevant method for .CSV files. I could see for retrieve data from CSV we have CSVDriver method.

You might want to add your .csv idea here

https://community.smartbear.com/t5/TestComplete-Feature-Requests/idb-p/TestXCompleteFeatureRequests

 

In the meantime, if you tell us what you are actually trying to accomplish with this test, perhaps we can find another way to do it.


Marsha_R
[Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
rraghvani
Regular Contributor

My suggestion is to create a Data Structure, a B-tree may be complex to write, but an Array will be able store the data, read from the csv file. You can then manipulate the Array, using rows and columns to perform the required actions you need, and then write the Array data back to the csv file.

 

Examples, Convert from CSV to array in PythonDump a NumPy array into a csv file 

cancel
Showing results for 
Search instead for 
Did you mean: