8.37. PikaStdLib 模块 API 文档
8.37.1. API
8.37.1.1. class MemChecker:
def max(self):...
def now(self):...
def getMax(self)->float:...
def getNow(self)->float:...
def resetMax(self):...
8.37.1.2. class SysObj:
8.37.2. Examples
8.37.2.1. file_nofound.py
try:
f = open("_no_file.txt", "r")
except:
print("File not found")
8.37.2.2. file3.py
f = open('test/out/file3.txt', 'w')
seq = [
'This is the first line.\n',
'This is the second line.\n',
'This is the third line.\n'
]
f.writelines(seq)
f.close()
8.37.2.3. type.py
mylist = [1, 2, 3]
if str(type(mylist)) == "<class 'list'>":
print('OK')
8.37.2.4. file.py
f = open('test/python/main.py', 'r')
s = f.read(10)
print(s)
f.close()
f = open('test/assets/test.jpg', 'rb')
b = f.read(-1)
print(b)
f.close()
f = open('test/out/write.txt', 'w')
f.write('Hello World!\n')
f.close()
8.37.2.5. dict.py
d = {
'a': 1,
'b': 2,
'c': 'test'
}
print(d)
for item in d:
print(item)
keys = d.keys()
for k in keys:
print(k)
print(keys)
dd = {
'list': [1, 2, 3],
'len': 3
}
print(dd)
8.37.2.6. bytes.py
def test():
a = bytes(10)
a[1] = 1
return a
print(test())
res = test()
8.37.2.7. print.py
print('test')
print('my name is', 'old wang', 'my age is', 43)
print('format: %s,%04d,%.2f' % ('test', 123, 15.5))
8.37.2.8. bigfile.py
f = open('test/assets/pic1.jpg', 'rb')
b = f.read(-1)
f.close()
8.37.2.9. ctypes.py
import ctypes
read_data = ctypes.c_buffer(b'', 16)
print("----read size----")
datalen = len(read_data.raw)
print(datalen)
print(read_data.raw)
print("----read data----")
for i in range(0,datalen):
print(read_data.raw[i])
8.37.2.10. file2.py
f = open('test/python/main.py', 'r')
s = f.readline()
print(s)
lines = f.readlines()
print(lines)
f.close()
8.37.2.11. seek.py
f = open('test/assets/test.jpg', 'rb')
len = f.seek(0, 2)
print(len)
f.close()
8.37.2.12. encode_decode.py
from PikaStdData import String as string
from PikaStdData import ByteArray as bytearray
b = bytearray(b'test')
b_s = b.decode()
print(b_s)
s = string('test')
s_b = s.encode()
print(s_b)
8.37.2.13. utf8.py
import PikaStdLib
import PikaStdData as std
import re
s2 = std.String('你好,Hello, Bonjour.')
i = 0
for c in s2:
print(i, c)
i += 1
print(s2[2])
s2[2] = ','
print(s2)
s2[2] = ','
print(s2)
print(s2.replace('你好,', 'Hi, '))
8.37.2.14. function.py
def test(a, b, e=10, *vars, **keys):
print(keys['c'], keys['d'], a, b, vars[0], e)
test(3, 4, 5, c=1, d= 2)
test(3, 4, 5, c=1, d= 2, e = 12)