Opening and reading from a text file using python on Prime G2 - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html) +--- Forum: HP Prime (/forum-5.html) +--- Thread: Opening and reading from a text file using python on Prime G2 (/thread-20028.html) |
Opening and reading from a text file using python on Prime G2 - Farlanw - 05-29-2023 07:00 AM Hi, am so far unable to open a one-line text file created in notes -get a system error . Please see code below from uio import * fpath="testxt.hpnote" f=open(fpath) readline(f) end Appreciate any comments or hints!! Many thanks, Farlan RE: Opening and reading from a text file using python on Prime G2 - Guenter Schink - 05-30-2023 09:03 PM (05-29-2023 07:00 AM)Farlanw Wrote: Hi, am so far unable to open a one-line text file created in notes -get a system error .That seems to be quite a challenge. First: you need to properly address the "Note". In this case: fpath=open("../testxt.hpnote") Second: readline isn't a function, but a method of the object "fpath" that you've created with the "open" function. "open" is an alias for various IO classes. Therefore you need to apply "readline" as a "method" of this object. I store it in a list for further processing, right away. line = list(fpath.readline()) now you have a list of garbage, of which you can extract your text with: line = "".join(line[0:len(line):2]) result is a string with an arbitrary amount of additional random characters. Unfortunately MicroPython doesn't have the string method "decode" may still not be what you want, but perhaps usable somehow. HTH Günter |