2023-02-25 01:48
This commit is contained in:
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"python.analysis.typeCheckingMode": "basic"
|
||||||
|
}
|
||||||
5
datatypes.py
Executable file
5
datatypes.py
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
table = str.maketrans('aeiou', 'AEIOU')
|
||||||
|
a = 'i like an apple'.translate(table)
|
||||||
|
|
||||||
|
print(a)
|
||||||
22
file_io.py
Executable file
22
file_io.py
Executable file
@@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
def read_file(file_name):
|
||||||
|
file = open(file_name, "r")
|
||||||
|
while True:
|
||||||
|
line = file.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
print(line)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
def write_file(file_name):
|
||||||
|
file = open(file_name, "w", encoding="UTF-8")
|
||||||
|
file.write("Hello,\n")
|
||||||
|
file.write("There")
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
read_file("./file_io.py")
|
||||||
|
write_file("./test.txt")
|
||||||
18
filewalk.py
Executable file
18
filewalk.py
Executable file
@@ -0,0 +1,18 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import os
|
||||||
|
from posixpath import dirname
|
||||||
|
|
||||||
|
|
||||||
|
def main(rootDir):
|
||||||
|
for (root, dirs, files) in os.walk(rootDir):
|
||||||
|
print("-> " + root)
|
||||||
|
if len(dirs) > 0:
|
||||||
|
for dirName in dirs:
|
||||||
|
print(dirName)
|
||||||
|
if len(files) > 0:
|
||||||
|
for fileName in files:
|
||||||
|
print(fileName)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main("/home/elex/Workspace/ELEX")
|
||||||
7
flow.py
Executable file
7
flow.py
Executable file
@@ -0,0 +1,7 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
a = 10
|
||||||
|
if (a > 0):
|
||||||
|
print(a)
|
||||||
|
|
||||||
|
for a in reversed(range(5)):
|
||||||
|
print(a)
|
||||||
59
regex.py
Executable file
59
regex.py
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
def fn_match():
|
||||||
|
# 문자열의 전체가 정규식과 일치하는지 판별합니다.
|
||||||
|
# 일치할 때에는 Match 객체를, 일치하지 않으면 None을 돌려줍니다.
|
||||||
|
str = "bat"
|
||||||
|
|
||||||
|
pattern = re.compile("[a-z]at")
|
||||||
|
match = pattern.match(str)
|
||||||
|
if match:
|
||||||
|
print("Matches: ", match.group())
|
||||||
|
else:
|
||||||
|
print("Not matches.")
|
||||||
|
|
||||||
|
|
||||||
|
def fn_search():
|
||||||
|
# 문자열 중에서 정규식과 일치하는 부분을 찾습니다.
|
||||||
|
# 일치할 때에는 Match 객체를, 일치하지 않으면 None을 돌려줍니다.
|
||||||
|
str = "I'm the bat man. Where is the rat?"
|
||||||
|
|
||||||
|
pattern = re.compile("[a-z]at")
|
||||||
|
match = pattern.search(str)
|
||||||
|
if match:
|
||||||
|
print("Matches: ", match.group())
|
||||||
|
else:
|
||||||
|
print("Not matches.")
|
||||||
|
|
||||||
|
|
||||||
|
def fn_findall():
|
||||||
|
# 정규식과 일치되는 모든 문자열을 리스트로 반환합니다.
|
||||||
|
str = "I'm the bat man. Where is the rat?"
|
||||||
|
|
||||||
|
pattern = re.compile("[a-z]at")
|
||||||
|
list = pattern.findall(str)
|
||||||
|
print(list)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
fn_match()
|
||||||
|
fn_search()
|
||||||
|
fn_findall()
|
||||||
|
|
||||||
|
|
||||||
|
def test_1():
|
||||||
|
line = '\tid("com.github.ben-manes.versions") version "0.42.0"'
|
||||||
|
pattern = re.compile(
|
||||||
|
'id\("com.github.ben-manes.versions"\) version "([0-9.]+)"')
|
||||||
|
match = pattern.search(line)
|
||||||
|
if match:
|
||||||
|
line = line.replace(match.group(1), "0.46.0")
|
||||||
|
print(line)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# main()
|
||||||
|
test_1()
|
||||||
17
switch.py
Executable file
17
switch.py
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
def function_1():
|
||||||
|
return 1
|
||||||
|
|
||||||
|
def function_2():
|
||||||
|
return 2
|
||||||
|
|
||||||
|
def function_3():
|
||||||
|
return 3
|
||||||
|
|
||||||
|
switch = {1:function_1, 2:function_2, 3:function_3}
|
||||||
|
|
||||||
|
val = 2
|
||||||
|
function = switch[val]
|
||||||
|
result = function()
|
||||||
|
print(result)
|
||||||
17
sys_call.py
Executable file
17
sys_call.py
Executable file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
|
def fn_system():
|
||||||
|
os.system("ls -al")
|
||||||
|
|
||||||
|
|
||||||
|
def fn_call():
|
||||||
|
result = subprocess.call(["ls", "-al"])
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# fn_system()
|
||||||
|
fn_call()
|
||||||
Reference in New Issue
Block a user