-
Notifications
You must be signed in to change notification settings - Fork 0
/
readFilesA.py
71 lines (62 loc) · 1.64 KB
/
readFilesA.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#File Processing (r - READ / W - write)
xfile = open("texto.txt","r")
for line in xfile:
print(line)
print("\n***************************")
#Couting lines
xfile = open("texto.txt")
count = 0
for line in xfile:
count = count +1
print("Linhas = ", count)
print("\n***************************")
#Read de whole file into a single string
xfile = open("texto.txt")
inp = xfile.read()
print(len(inp))
print(inp[:20])
print("\n***************************")
#Search through a file
xfile = open("texto.txt")
for line in xfile:
if line.startswith("De"):
print(line)
print("\n***************************")
#Remover \n do final das linhas
xfile = open("texto.txt")
for line in xfile:
line = line.rstrip() # aqui
if line.startswith("De"):
print(line)
print("\n***************************")
#Skipping with continue
xfile = open("texto.txt")
for line in xfile:
line = line.rstrip()
if not line.startswith("De"): # aqui
continue # aqui
print(line)
print("\n***************************")
#Using in to select lines
xfile = open("texto.txt")
for line in xfile:
line = line.rstrip()
if not "De" in line: # aqui
continue
print(line)
print("\n**in************************")
#Prompt for File name and Bad Names
fname = input("Enter the file name: ")
try:
xfile = open(fname)
except:
print("File cannot be open: ", fname)
quit()
#Skipping with continue
xfile = open("texto.txt")
for line in xfile:
line = line.rstrip()
if not line.startswith("C"): # aqui
continue # aqui
print(line)
print("\n***************************")