Last active 1732611013

GGORG revised this gist 1732611012. Go to revision

1 file changed, 0 insertions, 0 deletions

gistfile1.txt renamed to main.py

File renamed without changes

GGORG revised this gist 1732611004. Go to revision

1 file changed, 128 insertions

gistfile1.txt(file created)

@@ -0,0 +1,128 @@
1 + # %%
2 + tekst = open('lem.txt', encoding='utf-8').readlines()
3 +
4 + # %%
5 + tekst
6 +
7 + # %%
8 + tekst = []
9 + for wiersz in open('lem.txt', encoding='utf-8'):
10 + tekst.append(wiersz)
11 +
12 + # %%
13 + tekst = [wiersz.strip() for wiersz in open('lem.txt', encoding='utf-8')]
14 + tekst
15 +
16 + # %%
17 + plik = open('lem.txt', 'a', encoding='utf-8')
18 + print('\n\nKazimierz Wielki wpadł do butelki', file=plik)
19 + plik.close()
20 +
21 + # %%
22 + with open('lem.txt', 'a', encoding='utf-8') as plik:
23 + print('\n\n\n', file=plik)
24 + for _ in range(100):
25 + print('\nKazimierz Wielki wpadł do butelki', file=plik)
26 +
27 + # %%
28 + with open('lem.txt', mode='a', encoding='utf-8') as plik:
29 + plik.writelines(['Wanda, co nie chciała Niemca\n', 'Ale wolała Włocha'])
30 +
31 + # %%
32 + with open('lem.txt', 'r', encoding='utf-8' ) as plik:
33 + wiersz = plik.readline().strip()
34 +
35 + print(wiersz)
36 + print(wiersz.split())
37 +
38 + # %%
39 + with open('adresy.txt', 'r', encoding='utf-8' ) as plik:
40 + tekst = plik.readlines()
41 +
42 + # usuń białe znaki
43 + tekst = [wiersz.strip() for wiersz in tekst]
44 +
45 + # usuń średniki
46 + metody = ('wycinek', 'replace')
47 + metoda = 'replace'
48 + if metoda == 'wycinek':
49 + tekst = [wiersz[:-1] for wiersz in tekst]
50 + elif metoda == 'replace':
51 + tekst = [wiersz.replace(';','') for wiersz in tekst]
52 +
53 +
54 +
55 + for i, mail in enumerate(tekst):
56 + prefiks, skrzynka = mail.split('@')
57 + print(f'Osoba numer {i+1} ma prefiks {prefiks} na skrzynce {skrzynka}')
58 +
59 +
60 +
61 + # %%
62 + for i in range(len(tekst)):
63 + prefiks, skrzynka = tekst[i].split('@')
64 + print(f'Osoba numer {i+1} ma prefiks {prefiks} na skrzynce {skrzynka}')
65 +
66 + # %%
67 + list(enumerate(tekst))
68 +
69 + # %%
70 + import os
71 + os.getcwd()
72 +
73 + # %%
74 + sciezka = r"C:\Users\Nauczyciel\VS programy"
75 + print(sciezka)
76 +
77 + # %%
78 + os.listdir()
79 +
80 + # %%
81 + os.path.isdir('.venv'), os.path.isfile('.venv'), os.path.isfile('adresy.txt'),
82 +
83 + # %%
84 + list(os.scandir())
85 +
86 + # %% [markdown]
87 + # #### Dlaczego `with` w tym miejscu, skoro nie ma z tego korzyści dla komputera?
88 + #
89 + # Bo <font color="green"> **kod źródłowy jest dla człowieka, nie dla komputera** </font>
90 + #
91 + # Dla człowieka takie użycie `with` jest podprogowym przekazem: wszystko co jest do zrobienia z katalogami ma być w obrębie tego fragmentu kodu, a nie gdzieś poza nim.
92 + #
93 + # Dobrą praktyką jest pisanie <font color="green"> *kodów samokomentujących się* </font>.
94 + #
95 + # Komentarze w kodzie mile widziane są tylko w książkach i artykułach demonstrujących użycie kodu, nie w prawdziwych projektach.
96 +
97 + # %%
98 + with os.scandir() as zawartosc_folder:
99 + for elem in zawartosc_folder:
100 + print(f'Katalog: {elem.name}') if elem.is_dir() else print(f'Plik: {elem.name}')
101 +
102 +
103 + # %%
104 + def relu(input):
105 + if input >= 0:
106 + return input
107 + else:
108 + return 0
109 +
110 + # %%
111 + def relu(input):
112 + if input >= 0:
113 + return input
114 + return 0
115 +
116 + # %%
117 + def relu(input):
118 +
119 + output = input if input >= 0 else 0
120 + return output
121 +
122 + # %%
123 + '------'.join(tekst)
124 +
125 + # %%
126 +
127 +
128 +
Newer Older