# Read and write to txt file in HLA

**URL:** <https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790>\
**Category:** Logic 2 Software\
**Created:** [August 30, 2022, 8:08pm UTC](https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790 "2022-08-30T20:08:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel.vo](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@daniel.vo](https://discuss.saleae.com/u/daniel.vo)\
**Post date:** [August 30, 2022, 8:08pm UTC](https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790/1 "2022-08-30T20:08:33Z")

</div>

I am trying to make an HLA and I would like to read from a txt file and output a txt file. which gives permission errors. I can solve this by running as admin and changing file permissions but this is cumbersome. Is there a better way to do this?

---

<div class="post-metadata">

**Author:** ![huffman](https://avatars.discourse-cdn.com/v4/letter/h/71e660/32.png) [@huffman](https://discuss.saleae.com/u/huffman)\
**Post date:** [August 30, 2022, 8:26pm UTC](https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790/2 "2022-08-30T20:26:04Z")

</div>

Hi @daniel.vo, the permissions should be dependent on the user that launches Logic 2. Does the user have permission to read/write from the file and directory you are interacting with? If you try doing the same thing from a Python script outside of Logic 2, does it work?

Ryan

---

<div class="post-metadata">

**Author:** ![daniel.vo](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@daniel.vo](https://discuss.saleae.com/u/daniel.vo)\
**Post date:** [August 30, 2022, 9:00pm UTC](https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790/3 "2022-08-30T21:00:10Z")

</div>

Yes, I can do this with python scripts outside of Logic 2. I can run it in Visual studio and the python program by itself with no issue. The weird thing is that even If I run logic 2 as admin and make a txt file and write to it, I need to go into the security settings in order to edit the txt file. Can someone confirm if they are able to get txt read/writes in HLAs working? If others are able to get it working it’s probably an issue on my end.

---

<div class="post-metadata">

**Author:** ![huffman](https://avatars.discourse-cdn.com/v4/letter/h/71e660/32.png) [@huffman](https://discuss.saleae.com/u/huffman)\
**Post date:** [August 30, 2022, 11:30pm UTC](https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790/4 "2022-08-30T23:30:42Z")

</div>

@daniel.vo This works for me in 2.3.59 on Windows using the following code. Note that I am using an absolute path instead of a relative path - a relative path will be relative to the Logic 2 process’s working directory (in my case this would be `C:\Program Files\Logic\`, which will not be writeable if not running as admin).

```python
from saleae.analyzers import HighLevelAnalyzer, AnalyzerFrame
import os.path

class Hla(HighLevelAnalyzer):
    def __init__ (self):

        path = os.path.expanduser('~/hla_file.txt')
        print("Filepath: ", path)

        with open(path, 'w') as f:
            f.write('test string')

        with open(path) as f:
            print('contents of ~/hla_file.txt: ', f.read())

    def decode(self, frame: AnalyzerFrame):
        pass

```

You can see the output in the Logic 2 terminal:

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/saleae/original/2X/0/0bc3aad3c0f025e42004484514f328a646db0087.png)

---

<div class="post-metadata">

**Author:** ![daniel.vo](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@daniel.vo](https://discuss.saleae.com/u/daniel.vo)\
**Post date:** [August 31, 2022, 3:15pm UTC](https://discuss.saleae.com/t/read-and-write-to-txt-file-in-hla/1790/5 "2022-08-31T15:15:15Z")

</div>

Okay I see what I was doing wrong, I was using the relative path instead of the absolute path. Using the absolute path works for me. Thanks for the help!
