I have a subject_id which is a dynamic number.For instance, it could be equal to 60. I am manually defining some file names as follows:
x_file = "50.txt"
x_csv_file = "50.csv"
The number (50) could have been 1 or any-number else. Is there any way that I can define subject_id=50 JUST one time and then use those names as x_file = "subject_id.txt" and x_csv_file = "subject_id.csv"?.
Thanks For your help
1 Answer
You might want to define a simple function for this
def file_name(subject_id):
x_file = '{}.txt'.format(subject_id)
x_csv_file = '{}.csv'.format(subject_id)
return x_file, x_csv_file
3 Comments
Nevi
Worked as a charm!
wilson tao
You can do
x_csv_file = str(subject_id) + '.csv' with Lukas' solution too : )AMC
Why not use f-strings?
subject_id='50'and then dox_file=subject_id + '.txt'andx_csv_file=subject_id + '.csv:The+between two strings acts as the concatenation operator, hence the strings are pasted together to produce your desired output