Skip to content

Commit

Permalink
python mod
Browse files Browse the repository at this point in the history
  • Loading branch information
hunkier committed Dec 24, 2021
1 parent e4c6ab5 commit 80c0c1d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
36 changes: 36 additions & 0 deletions PythonDemo/class_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
user1 = {'name': 'tom', 'hp': 100}
user2 = {'name': 'jerry', 'hp': 80}


def print_role(rolename):
print('name is %s, hp is %s' % (rolename['name'], rolename['hp']))


print_role(user1)


class Player(): # 定义一个函数
def __init__(self, name, hp, occ):
self.__name = name # 下划线开头的属性只能通过方法访问和修改
self.hp = hp
self.occ = occ

def print_role(self):
print('%s: %s %s' % (self.__name, self.hp, self.occ))

def update_name(self,new_name):
self.__name = new_name


class Monster():
'定义怪物类'
pass


user1 = Player('tom', 100, 'war') # 类实例化
user2 = Player('jerry', 90, 'master')
user1.print_role()
user2.print_role()

user1.update_name('wilson')
user1.print_role()
18 changes: 18 additions & 0 deletions PythonDemo/mod_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import mymod

mymod.print_me()


#
# brew install autopep8 或者 pip install autopep8
# 打开PyCharm
#
# File → Settings → Tools → External Tools → +
#
# 配置参数
#
# Name: autopep8
# Program: autopep8
# Arguments: --in-place --aggressive --aggressive $FilePath$
# Working directory: $ProjectFileDir$
# Output filters: $FILE_PATH$\:$LINE$\:$COLUMN$\:.*
2 changes: 2 additions & 0 deletions PythonDemo/mymod.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def print_me():
print('me')
1 change: 1 addition & 0 deletions PythonDemo/sanguo.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
def func(filename):
print(open(filename).read())


func('name.txt')
5 changes: 4 additions & 1 deletion PythonDemo/sanguo_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,8 @@ def find_main_charecters(main_charecters):
weapon_dict[weapon_name] = weapon_number
i += 1

weapon_sorted = sorted(weapon_dict.items(), key=lambda item: item[1], reverse=True)
weapon_sorted = sorted(
weapon_dict.items(),
key=lambda item: item[1],
reverse=True)
print(weapon_sorted)

0 comments on commit 80c0c1d

Please sign in to comment.