Skill File I/O

I keep having to look this up, so I’m going to put it here for easy reference:

Open a File


h = outfile("new_file.txt", "w")
h = infile("existing_file.txt")
h = outfile("partial_file.txt", "a")

Opens new file for writing, existing file for reading, and partial file for appending, respectively.

Write to a file


write("Hello World!\n", h)
fprintf(h, "gm = %f", OP("/M23" "gm"))
print(OP("/M23" "gm"), h)
pprint(OP("/M23" "gm"), h)

Write “Hello World!” to a file (newlines are explicit); construct formatted string and write to file; print using native format to a file; pretty-print (useful for nested lists etc) to a file. File handle is h.

Read from a file


str = lineread(h)

Reads a single line as a string

This entry was posted in Analog Professional and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

You must be logged in to post a comment.