# Importing Local CSV

**URL:** <https://forum.inductiveautomation.com/t/importing-local-csv/87650>\
**Category:** General Discussion\
**Tags:** perspective\
**Created:** [March 20, 2024, 6:20pm UTC](https://forum.inductiveautomation.com/t/importing-local-csv/87650 "2024-03-20T18:20:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pico\_Sankari](https://avatars.discourse-cdn.com/v4/letter/p/aeb1de/32.png) [@Pico\_Sankari](https://forum.inductiveautomation.com/u/Pico_Sankari)\
**Post date:** [March 20, 2024, 6:20pm UTC](https://forum.inductiveautomation.com/t/importing-local-csv/87650/1 "2024-03-20T18:20:16Z")

</div>

I'm trying to import a local CSV to serve as a reference table on a component in perspective. I've run this line in both the script console and as part of a script that runs on the component:

```auto
	filePath = "C:/myfile.csv"
	isFile = system.file.fileExists(filePath)

```

In the console, isFile returns True. When run on a component script, it returns False. I think that this is because of the restricted access in Perspective. Is there a way to write my data to the component from the script console? This only needs to be done once. Any other ideas for making a static table that a component can reference (other than manually creating and filling in a table) would be appreciated.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 20, 2024, 6:28pm UTC](https://forum.inductiveautomation.com/t/importing-local-csv/87650/2 "2024-03-20T18:28:12Z")

</div>

Scripts in Perspective are run on the gateway. The script console is running code on your local computer.  
You wont directly be able to access a file on your local machine in perspective, you would need to upload it to the gateway, or otherwise make the data accessible to the gateway.

---

<div class="post-metadata">

**Author:** ![Pico\_Sankari](https://avatars.discourse-cdn.com/v4/letter/p/aeb1de/32.png) [@Pico\_Sankari](https://forum.inductiveautomation.com/u/Pico_Sankari)\
**Post date:** [March 20, 2024, 6:29pm UTC](https://forum.inductiveautomation.com/t/importing-local-csv/87650/3 "2024-03-20T18:29:08Z")

</div>

How can I upload it to the gateway? FileUpload Component?

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 20, 2024, 6:29pm UTC](https://forum.inductiveautomation.com/t/importing-local-csv/87650/4 "2024-03-20T18:29:38Z")

</div>

Yes, that would work.

---

<div class="post-metadata">

**Author:** ![josborn](https://avatars.discourse-cdn.com/v4/letter/j/4bbf92/32.png) [@josborn](https://forum.inductiveautomation.com/u/josborn)\
**Post date:** [March 20, 2024, 7:23pm UTC](https://forum.inductiveautomation.com/t/importing-local-csv/87650/5 "2024-03-20T19:23:03Z")

</div>

I copied @Travis_Opperud's code from here, which quite nicely parses the csv from the file upload without needing to save the file to the gateway's disk.

> [@Upload csv to dataset](https://forum.inductiveautomation.com/t/upload-csv-to-dataset/79797/2):
>
> Figured it out, Not sure why I got hung up like I did. If anyone else gets stuck: the following class can parse csv files and store as a dataset: class CSVParser: def \_\_init\_\_(self, file\_in): self.file = file\_in self.file\_string = file\_in.getString() self.rows = [row.split(',') for row in self.file\_string.split('\r')] self.num\_cols = max([len(row) for row in self.rows]) self.num\_rows = len(self.rows) self.headers = self.rows[0] self.data = self.rows[1:] @property def extend…
