Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to pass variable values to a string in python

Tags:

python

I have requirement where I am reading a string from json file and assign values to it to make it as a configurable file name.

String I am reading from json:

data_file_format =  "sourcesystem_batchid_extractname_loadtype"

I have variable which holds the values in my code like

sourcesystem ="xyz"
  batchid = "101"
  extractname = "abc"
  loadtype = "Delta"

so my data_file_format should yeild value like

data_file_format = "xyz_101_abc_Delta"
like image 465
Sasidhar_gubbala Avatar asked Oct 17 '25 19:10

Sasidhar_gubbala


1 Answers

There are multiple methods to do that.:

fstring

data_file_format = f'{sourcesystem}_{batchid}_{extractname}_{loadtype}'

or using .format

data_file_format = '{}_{}_{}_{}'.format(sourcetype,batchid,extractname,loadtype)
like image 186
ThunderMind Avatar answered Oct 20 '25 09:10

ThunderMind



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!