-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.py
81 lines (62 loc) · 1.44 KB
/
file.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
70
71
72
73
74
75
76
77
78
79
80
import sys
import csv
args=sys.argv[1:]
index=args.index('bb')
a=args[index+1]
print("args=",args,"index=",index,"a=",a)
config={}
with open('config.cfg') as f:
for line in f.readlines():
key,value=line.strip().split('=')
config[key]=float(value)
print(config)
userdata_string=[]
userdata_int=[]
with open('userdata.csv') as f:
for line in f.readlines():
id,income=line.strip().split(',')
userdata_string.append(income)
userdata_int.append(int(income))
print(userdata_string)
print(userdata_int)
print((userdata_int))
a='hello'
b='world'
userdata_int+=[a,b]
print("after change",userdata_int)
with open('result.csv','w') as f:
writer=csv.writer(f)
writer.writerows(str(userdata_int))
class A(object):
def foo1(self):
print ("method-hello",self)
@staticmethod
def foo2():
print ("staticmethod-hello")
@classmethod
def foo3(cls):
print ("classmethod-hello",cls)
def writefile(self):
userdata=[]
userdata.append(userdata_int)
with open('result2.csv','w',newline='') as f:
writer=csv.writer(f)
writer.writerows(userdata)
def writefile2(self):
with open('result3.csv','w',newline='') as f:
writer=csv.writer(f)
writer.writerows(userdata_string)
def writefile3(self):
with open('result4.csv','w',newline='') as f:
writer=csv.writer(f)
writer.writerows([userdata_int])
if __name__=='__main__':
a=A()
a.foo1()
A.foo1(a)
A.foo2()
A.foo3()
print(A)
a.writefile()
a.writefile2()
a.writefile3()