Good day! There is a function


def conv(self): self.iniString = [] for self.files in os.listdir(self.dir): # Фильтр на .ini файлы. if fnmatch.fnmatch(self.files, '*.ini'): with open(self.dir + '/' + self.files) as file: # Считываем .ini файл в список self.iniString = file.read().splitlines() # Забираем имя файла self.fileName = os.path.splitext(self.files)[0] # Создаем в заданной директории файл с именем self.fileName.json self.jsonFiles = open(self.dir + '/' + self.fileName + '.json', 'w') self.jsonFile = ' \n'.join(self.iniString) self.jsonFiles.write(self.jsonFile) 

This self.iniString problem self.iniString assigned 2 lists, self.iniString selected directory stores 2 - .ini files, then 2 - .json files are created in the specified directory, as it should be, but the contents of the 2 lists from self.iniString written in the first .json. How to fix in such a way that the 1st list in 1.json, and the 2nd in the second?

Closed due to the fact that off-topic participants Timofei Bondarev , PashaPash , pavlofff , awesoon , deivan_ 4 May '15 at 9:11 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - Timofei Bondarev, PashaPash, pavlofff, awesoon, deivan_
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • The code given by you and so writes data in the corresponding files. The problem does not reproduce. - Timofei Bondarev

1 answer 1

After writing data to a .json file

 self.jsonFiles.write(self.jsonFile) 

close the file with the close () function.

 self.jsonFiles.close()