Problem About Read file .txt

Hello everybody.

How do you read separate lines from a .txt file?

I know that you can get the whole text file by doing:

but that imports the whole text file, and cannot read ‘enter’ so replaces it with a rectangle, but what if i wanted to read say; line 1, and line 2 separately from each other, i think you used to be able to do


but this doesn’t work anymore.

any help appreciated
Thanks a lot!

I suggest to look for some Python libraries that read a file and place the content into sufficient data structures.

you mean JSON ?

in that case, I’d be happy to find why my attempt here in att. to load/save a dictionnary in a txt file in json is not working …

I can’t find any simple working exemple… it’s needed because GlobalDict is not meant for that… (If I read correctly)

In the .blend I tried with custom dictionnary and global dictionnary, without luck … (and probably I did something stupid, as always…)


loadsavetest.blend (466 KB)

I’m more pointing into the direction of reading .ini, .properties or .config files. This comes on an higher abstraction level.

JSON can be helpful too. It is focused on converting between Python objects and String representations. Saving/Loading strings is mentioned above already :D.

A file object can be iterated as if it was a list.

for line in file:
 #do something with line

Also, readline should be working. Have you written it entirely in lower case?