1

I have these text files that are metadata, in these files, there are always (at the same position) numbers that I have to put in quotes, so just that you can undersand here is an exeample

...
    {
      "trait_type": "Number of lines",
      "value":1 
    },
    {
      "trait_type": "Number of circles",
      "value":4 
    },
...

So as you can see, I forgot to put these numbers between quotes.

What I was thinking about (if that's the best solution) is to store these numbers in a variable, rewrite the line but this time with the variable in quotes.

I know that I could use the file.read() method, but what I don't understand is how can I make it read a very specific character since it reads the file from top to bottom.

  • This looks like regular JSON, where numbers don't have to be quoted. There doesn't seem to be a "fixed position", just a location in a specific structure. – tripleee Feb 26 '22 at 10:10
  • 1
    You generally have to read and rewrite the entire file anyway. – tripleee Feb 26 '22 at 10:11

1 Answers1

0

I found the solution : I used the seek() method, which allows me to go to any place in the text file.

file = open('1.json', 'r')
     
file.seek(556)
char = file.read(1)               
print(char)

file.seek(631)
miaou = file.read(1)               
print(miaou)
 
file.close()