I am trying to replace square brackets in a tuple with round brackets which I had converted into a String and then tried to replace. Below is the code I am trying.
JavaScript
x
13
13
1
def fetch_values_from_csv_and_store_it_in_tuple(test_case_name,file_name):
2
df = expected_df = read_csv(
3
"{}/output/Float_Ingestion_Expected_Output_files/{}/{}.csv".format(str(parentDir), test_case_name, file_name),
4
',', False)
5
# list of strings
6
tables = list(df["factset_entity_id"])
7
# list of single tuples
8
table_tuples = [(t) for t in df["factset_entity_id"]]
9
table_tpl=str(table_tuples)
10
table_tpl.replace('[','(')
11
table_tpl.replace(']',')')
12
print(table_tpl)
13
But this is printing [‘ABCXYZ-I’, ‘ABCXYZ-I’, ‘ABCXYZ-I’]. I want to print (‘ABCXYZ-I’, ‘ABCXYZ-I’, ‘ABCXYZ-I’). Am I missing something here?
Advertisement
Answer
table_tpl.replace('[','(')
.replace
returns the new string, but you are just throwing the return value away. You will have to do something like
JavaScript
1
3
1
table_tpl = table_tpl.replace('[','(')
2
table_tpl = table_tpl.replace(']',')')
3