Name file with sql query data

Asked

Viewed 81 times

0

Hello, I need to name each file created by the script with a data from a single column of my data bank. Follows the code:

for index, source in zip(list(range(0, len(self.sources))), self.sources):
  if self.jsonfile is not None and self.outdir is not None:
    path_file = '{}/{}_{}_{}'.format(self.outdir,datetime.now().strftime('%Y%m%d%H%M%S'), index, code[index]+'.json')

Where "code" is the data of my database column, and index is the number of the files and it will be like this:

20170920145732_0_CODE1.json

20170920145732_1_CODE2.json

20170920145732_2_CODE3.json

The starting numbers are date and time and after the first underscore comes the index, and finally comes the data from the database column.

My sql query:

sql = 'SELECT code from data.est where name = code and id = 13'
  • Disregarding indentation errors and a for poorly built, what’s the problem? You said what you intend to do, but did not explain what you did or what the difficulty found.

  • The indentation errors are only here in the post, the script is correct. What happens is this, it does not rename the files as desired nor creates the file. As you can see in the image, the code is indented correctly: https://imgur.com/YApOJAT

  • Can you give me what the . json tree would look like as a result?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.