-
Notifications
You must be signed in to change notification settings - Fork 1
/
files.rid
53 lines (41 loc) · 1.11 KB
/
files.rid
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
# Shows how files work with Riddim
path = 'testfile.txt'
# Writing text
f = File(path, 'w')
f.write('Hello world !\nThis file has been created by Riddim')
# Note that all files are closed at the end of
# the program but it is necessary to close it
# now if we want to open it again in another mode
f.close()
print 'Written'
# Reading text
f = File(path)
content = f.read()
print 'Read', content
f.close()
# Writing binary content
f = File(path, 'wb')
f.write([0x43, 0x0A, 0x63])
f.close()
# Reading binary content
f = File(path, 'rb')
print f.read()
f.close()
# Special (virtual) files
# Standard output
File.stdout.write('I am printing without line feed')
print ' (this text is not written but printed)'
# Standard error output
File.stderr.write('This message is on stderr\n')
# Standard input
# You can pipe an output and try `print File.stdin.read()`
print File.stdin
# Reading next line / character
f = File(path, 'w')
f.write('Hello world !\nThis file has been created by Riddim')
f.close()
f = File(path)
# These methods return null on end of file
print f.read_char() # H
print f.read_line() # ello world!
f.close()