Skip to content

Commit d9d963b

Browse files
committed
test
1 parent 65db57d commit d9d963b

File tree

11 files changed

+130
-23
lines changed

11 files changed

+130
-23
lines changed

.invest4.py.swp

12 KB
Binary file not shown.

class_fakeuser.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ln_path = '~/downloads/d.txt'
2+
fn_path = '~/downloads/d.txt'
3+
fn = []
4+
ln1 = []
5+
ln2 = []
6+
with open(fn_path,'r') as f:
7+
for line in f.readlines():
8+
fn.append(line.split('\n')[0])
9+
print(fn)
10+
with open(ln_path,'r') as f:
11+
for line in f.readlines():
12+
if len(line.split('\n')[0]) == 1:
13+
ln1.append(line.split('\n')[0])
14+
else:
15+
ln2.append(line.split('\n')[0])
16+
print(ln1)
17+
print('='*70)
18+
print(ln2)
19+
20+
import random
21+
class FakeUser:
22+
def fake_name(self,amount=1,one_word=False,two_word=False):
23+
n = 0
24+
while n <= amount:
25+
if one_word:
26+
full_name = random.choice(fn) + random.choice(ln1)
27+
elif two_words:
28+
full_name = random.choice(fn) + random.choice(ln2)
29+
else:
30+
full_name = random.choice(fn) + random.choice(ln1 + ln2)
31+
yield full_name
32+
n += 1
33+
def fake_gender(self,amount=1):
34+
gender = random.choice(['man','woman','unknown'])
35+
yield gender
36+
n += 1
37+
38+
class SnsUser(FakeUser):
39+
def get_followers(self,few=True,a_lot=False):
40+
n = 0
41+
while n <= amount:
42+
if few:
43+
followers = random.randrange(1,50)
44+
elif a_lot:
45+
followers = random.randrange(200,10000)
46+
yield followers
47+
n += 1
48+
user_a = FakerUser()
49+
user_b = SnsUser()
50+
for name in user_a.fake_name(30):
51+
print(name)
52+
for name in user_b.fake_gemder(30):
53+
print(gender)

class_test01.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class CocaCola():
2+
formula = ['caffeine','sugar','water','soda']
3+
def __init__(self):
4+
self.local_logo = '可口可乐'
5+
6+
for element in self.formula:
7+
print('Coke has {}!'.format(element))
8+
9+
def drink(self):
10+
print('Energy!')
11+
coke = CocaCola()
12+
print(coke.local_logo)

class_test02.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class CocaCola:
2+
formula = ['caffeine','sugar','water','soda']
3+
local_logo = 'CocaCola'
4+
coke_for_me = CocaCola()
5+
coke_for_you = CocaCola()
6+
coke_for_China = CocaCola()
7+
coke_for_China.local_logo = '可口可乐'#创建实例属性
8+
coke_for_USA = CocaCola()
9+
print(coke_for_USA.local_logo)
10+
print(coke_for_China.local_logo)#打印实例属性
11+
print(CocaCola.formula)
12+
print(coke_for_me.formula)
13+
for element in coke_for_me.formula:
14+
print(element)

class_test03.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class CocaCola:
2+
def drink(self,how_much):
3+
if how_much == 'a sip':
4+
print('Cool~')
5+
elif how_much == 'whole bottle':
6+
print('headache')
7+
coke = CocaCola()
8+
coke.drink('a sip')

class_test04.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
class CocaCola:
2+
calories = 140
3+
sodium = 45
4+
total_carb = 39
5+
caffeine = 34
6+
ingredients = [
7+
'High Fructose Corn Syrup',
8+
'Carbonated Water',
9+
'Caramel Color',
10+
'Caffeine'
11+
]
12+
def __init__(self,logo_name):
13+
self.local_logo = logo_name
14+
15+
def drink(self):
16+
print('You got {} cal energy!'.format(self.calories))
17+
18+
class CaffeineFree(CocaCola):
19+
caffeine = 0
20+
ingredients = [
21+
'High Fructose Corn Syrup',
22+
'Carbonated Water',
23+
'Caramel Color'
24+
]
25+
coke_a = CaffeineFree('CocaCola-FREE')
26+
coke_a.drink()

class_test05.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class TestA:
2+
attr = 1
3+
def __init__(self):
4+
self.attr = 42
5+
obj_a = TestA()
6+
obj_b = TestA()#实例属性被重新赋值,不会影响类属性的引用
7+
8+
obj_a.attr = 42#类属性被重新赋值,会影响到类属性的引用
9+
print(obj_b.attr)
10+
print(obj_a.attr)
11+
print(TestA.__dict__)
12+
print(obj_a.__dict__)

hw.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import androidhelper
2+
droid = androidhelper.Android()
3+
droid.makeToast('Hello, Android!')
4+
print('Hello world!')
5+

pycode

Lines changed: 0 additions & 1 deletion
This file was deleted.

test.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)