0

My plan is to rename the mechs in a game (Battletech) from "Mech Name" to "(Viewer)s Mech Name"

(Viewer) should get pulled from a textfile where I'll add more and more Names.

I found this code on Stack Overflow:

#!/usr/bin/env python3
import fileinput

with fileinput.FileInput('C:/Users/User/Desktop/test_2/mechdef_atlas_AS7-D-HT.json', inplace=True,) as file:
    for line in file:
        print(line.replace('''UIName": "''', '''UIName": "(Viewer)''' + 's '), end='')

and it's working like a charm. But I need it to pull the viewer names out of a file and also repeat the process for all 32 mechdef.json-files in the directory, without knowing the exact name of the files. The directory is only filled with those 32 files, all files in there have to be edited.

My biggest difficulty is propably going to be not pulling same name twice out of the Viewers.txt.

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
CrysowR
  • 1
  • 3

0 Answers0