f-string: expressions nested too deeply 해결법
Language/Python

f-string: expressions nested too deeply 해결법

뉴비뉴 2019. 11. 28.

NHN Toast를 보게되면 아래와 같이 데이터를 전송한다. (Kakao 비지니스)

 

curl -X POST -H "Content-Type: application/json;charset=UTF-8" -H "X-Secret-Key:{secretkey}" https://api-alimtalk.cloud.toast.com/alimtalk/v1.4/appkeys/{appkey}/messages -d

'{"plusFriendId":"{플러스친구 아이디}","templateCode":"{템플릿 코드}","requestDate":"2018-10-01 00:00","recipientList":[{"recipientNo":"{수신번호}","templateParameter":{"{치환자 필드}":"{치환 데이터}"}}]}'

 

여기서 나는 f-string을 사용하고 싶었고, 당연히 오류가 발생했다. 왜냐하면 중첩 된 {} 안에 f-string의 문법인 {}을 사용해야되기 때문이다.

그래서 난 아래와 같은 방법으로 해결했다.

 

data = f'|"plusFriendId":"{ID}","templateCode":"{Code}","requestDate":"{Date}","recipientList":[|"recipientNo":"{phonenumber}","templateParameter":|"{TEST1}":"{TEST2}"??]?'

 

change1 = data.replace("|", "{")
change2 = change1.replace("?", "}")

 

 

'Language > Python' 카테고리의 다른 글

pip install Pillow 에러해결  (0) 2019.12.22
HTTP Method ( GET, POST )  (0) 2019.12.12
AWS, Docker  (0) 2019.11.22
구글 트렌드(실시간 인기 급상승 검색어) selenium 삽질일기  (0) 2019.09.23
피보나치 수열  (0) 2019.07.17

댓글

💲 추천 글