Post Reply 
Opening and reading from a text file using python on Prime G2
05-30-2023, 09:03 PM
Post: #2
RE: Opening and reading from a text file using python on Prime G2
(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 .

Please see code below

from uio import *
fpath="testxt.hpnote"
f=open(fpath)
readline(f)
end

Appreciate any comments or hints!!

Many thanks,
Farlan
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
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Opening and reading from a text file using python on Prime G2 - Guenter Schink - 05-30-2023 09:03 PM



User(s) browsing this thread: 1 Guest(s)