๋ชฉ์ฐจ
https://codechacha.com/ko/python-extract-integers-from-string/
Python - ๋ฌธ์์ด์์ ์ซ์๋ง ์ถ์ถํ๋ ๋ฐฉ๋ฒ
String์์ ์ซ์(Integer)๋ง ์ถ์ถํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํฉ๋๋ค. `re.sub()`์ Syntax๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. string์์ Pattern๊ณผ ์ผ์นํ๋ ๋ฌธ์๋ค์ด repl์ผ๋ก ๊ต์ฒด๋ฉ๋๋ค. `re.findall(pattern, string)`์ string์์ pattern์
codechacha.com
ํ์ฌ operation_solution์ ์๋ ์ฐ์ฐ ์ ex) 5+2
์ค์์ ์ฐ์ฐ๊ธฐํธ ๋ค์ ์๋ ์ฆ ํ์ฌ ์ ๋ ฅ๋ ์๋ง ์ง์์ฃผ์ด์ผํ๋ค.
๋ง์ฝ ์ฐ์ฐ๊ธฐํธ ๋ค์ ์๊ฐ ์๋ค๋ฉด ๊ทธ ์์ ์ ๋ ฅ๋ ์๋ฅผ ์ง์์ค๋ค.
์ผ๋จ ์๋ง ์ง์์ฃผ์ด์ผ ํ๋ค.
### CE ๋ฒํผ์ ํ์ฌ ์
๋ ฅํ ์๋ง ์ง์ฐ๋ ๊ธฐ๋ฅ
def button_clear_entry_clicked(self):
operation_solution = self.operation_solution.text()
numbers = re.findall(r'\d+',operation_solution)
self.operation_solution.setText(str(numbers))

CE๋ฒํผ ๋๋ฅด๋ฉด

์ ์์๋ค์ type๋ฅผ ์์์ฃผ๊ธฐ ์ํด์
print(type(numbers))
๋ฅผ ์ถ๊ฐํด์ฃผ๋ฉด list์์ ์ ์ ์๋ค.

https://codechacha.com/ko/python-remove-last-index-in-list/
Python - ๋ฆฌ์คํธ์ ๋ง์ง๋ง ์์ ์ ๊ฑฐ
Python์ ๋ฆฌ์คํธ์์ ๋ง์ง๋ง ์์๋ฅผ ์ ๊ฑฐํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํฉ๋๋ค. pop()์ ๋ฆฌ์คํธ์ ๋ง์ง๋ง ์์๋ฅผ ๋ฆฌ์คํธ์์ ์ ๊ฑฐํ๊ณ , ๊ทธ ๊ฐ์ ๋ฆฌํดํฉ๋๋ค. pop(index)๋ ์ธ์๋ก ์ ๋ฌ๋ index์ ํด๋นํ๋ ์์๋ฅผ ์
codechacha.com
์ ๋ด์ฉ์ ์ฐธ๊ณ ํ์ฌ ๋ฆฌ์คํธ์ ๋ง์ง๋ง ์์๋ฅผ ์ ๊ฑฐํด์ฃผ๊ณ
self.operand_solution์ ์ถ๋ ฅํด์ฃผ๋ฉด CE ๊ธฐ๋ฅ์ ๊ตฌํํ ์ ์์ ๊ฒ ๊ฐ๋ค!
๊ทผ๋ฐ del numbers[-1]์ ํด์ฃผ๋๊น ๋ค ์ง์์ง๋ค
์์ง?????????/
์ฝ๋ ๋ด์์ ํจ์๊ฐ ๋ ๋ฒ ํธ์ถ๋๊ณ ์์ด์ ๊ทธ๋ฌ๋ค! ํ๋ ์์ ์ฃผ๋๊น ์ ์๋์ํจ
def button_clear_entry_clicked(self):
operation_solution = self.operation_solution.text()
numbers = re.split('([^0-9])',operation_solution)
del numbers[-1]
operation_solution = ''.join(s for s in numbers)
self.operation_solution.setText(operation_solution)
์ด์ del number[-1] ๋ก numbers ๋ฆฌ์คํธ์ ๋ง์ง๋ง ์์๋ฅผ ์ ๊ฑฐํ๊ณ ,
๊ทธ ๋ฆฌ์คํธ๋ฅผ ๋ค์ ๋ฌธ์์ด ํํ๋ก ๋ฐ๊ฟ์ ํ๋ฉด์ ์ถ๋ ฅํด์ผํ๊ธฐ ๋๋ฌธ์ ''.join(s for s in numbers)๋ฅผ ํตํด ๋ฌธ์์ด๋ก ๋ค์ ๋ฐ๊ฟ ์ฃผ์๋ค.
https://codechacha.com/ko/python-convert-list-to-string/
Python - ๋ฆฌ์คํธ๋ฅผ ๋ฌธ์์ด๋ก ๋ณํ
List๋ฅผ ๋ฌธ์์ด๋ก ๋ณํํ๋ ๋ฐฉ๋ฒ์ ์๊ฐํฉ๋๋ค. ๋ฐ๋ณต๋ฌธ์ ์ด์ฉํ์ฌ ๋ฆฌ์คํธ๋ฅผ ๋ฌธ์์ด๋ก ๋ณํํ๋ ์ฝ๋๋ฅผ ๊ตฌํํ ์ ์์ต๋๋ค. `join()`์ ์ด์ฉํ๋ฉด ๋ค์๊ณผ ๊ฐ์ด ๋ฆฌ์คํธ๋ฅผ ๋ฌธ์์ด๋ก ๋ณํํ ์ ์์ต๋
codechacha.com
์ ์๋์
'2022 > ์คํ์์ค ์ํํธ์จ์ด ํ๋ก์ ํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
git branch ๋ณํฉํ๊ธฐ (0) | 2022.12.01 |
---|---|
= ๋ฒํผ ์ด๋ฒคํธ (0) | 2022.11.27 |
. ๋ฒํผ ๊ธฐ๋ฅ ์ถ๊ฐ ์์ (0) | 2022.11.27 |
float๊ฐ ์ ์์ธ์ง ํ์ธํ๊ธฐ (0) | 2022.11.27 |
UI ์์ ํ๊ธฐ (0) | 2022.11.23 |