Last active 1732611013

Revision ddc6763cb6e6cded1f69e50c8ccdc2c3a5ed43b8

gistfile1.txt Raw
1# %%
2tekst = open('lem.txt', encoding='utf-8').readlines()
3
4# %%
5tekst
6
7# %%
8tekst = []
9for wiersz in open('lem.txt', encoding='utf-8'):
10 tekst.append(wiersz)
11
12# %%
13tekst = [wiersz.strip() for wiersz in open('lem.txt', encoding='utf-8')]
14tekst
15
16# %%
17plik = open('lem.txt', 'a', encoding='utf-8')
18print('\n\nKazimierz Wielki wpadł do butelki', file=plik)
19plik.close()
20
21# %%
22with 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# %%
28with 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# %%
32with open('lem.txt', 'r', encoding='utf-8' ) as plik:
33 wiersz = plik.readline().strip()
34
35print(wiersz)
36print(wiersz.split())
37
38# %%
39with open('adresy.txt', 'r', encoding='utf-8' ) as plik:
40 tekst = plik.readlines()
41
42# usuń białe znaki
43tekst = [wiersz.strip() for wiersz in tekst]
44
45# usuń średniki
46metody = ('wycinek', 'replace')
47metoda = 'replace'
48if metoda == 'wycinek':
49 tekst = [wiersz[:-1] for wiersz in tekst]
50elif metoda == 'replace':
51 tekst = [wiersz.replace(';','') for wiersz in tekst]
52
53
54
55for 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# %%
62for 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# %%
67list(enumerate(tekst))
68
69# %%
70import os
71os.getcwd()
72
73# %%
74sciezka = r"C:\Users\Nauczyciel\VS programy"
75print(sciezka)
76
77# %%
78os.listdir()
79
80# %%
81os.path.isdir('.venv'), os.path.isfile('.venv'), os.path.isfile('adresy.txt'),
82
83# %%
84list(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# %%
98with 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# %%
104def relu(input):
105 if input >= 0:
106 return input
107 else:
108 return 0
109
110# %%
111def relu(input):
112 if input >= 0:
113 return input
114 return 0
115
116# %%
117def relu(input):
118
119 output = input if input >= 0 else 0
120 return output
121
122# %%
123'------'.join(tekst)
124
125# %%
126
127
128
129