本文目录一览:
用python写的关机命令怎么让他每次开关机自启功
win7运行输入
shell:Startup
在路径下面类似
C:\Users\Default\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\文件夹下把你要放的python文件放进去~~
开机就运行~
有的一般病毒都是在这应该开机启动
python问题,我的function不能return,讲的是一个开关灯的类
# 标有”#”的行是修改过的,对比一下看看。
class LightSwitch:
def __init__(self,condition):
self.is_on = condition
if not isinstance(condition,bool):
InvaildSwitchExpection = TypeError(“it is not a right state”.format(condition))
raise InvaildSwitchExpection
def turn_on(self):
self.is_on = True
def turn_off(self):
self.is_on = False
def filp(self):
if self.is_on == False:
self.is_on = True
else:
self.is_on = False
def __str__(self):
if self.is_on == True:
return “I am on”
else:
return “I am off”
class SwitchBoard(LightSwitch):
def __init__(self, number):
self._lights = []
for i in range(0, number):
i = LightSwitch(False)
self._lights.append(i)
def which_switch(self):
result = []
for i in range(0, len(self._lights)):
if self._lights[i].is_on == True:
result.append(str(i)) #
return result
def __str__(self):
result = self.which_switch() #
result_str = ‘,’.join(result)
return ‘The following switches are on: ‘ + result_str
def filp(self, n):
if self._lights[n] == False:
self._lights[n].is_on = True
else:
self._lights[n].is_on = False
def filp_every(self, n):
k = 0
while n * k = len(self._lights) – 1:
if self._lights[n * k].is_on == False:
self._lights[n * k].is_on = True
else:
self._lights[n * k].is_on = False
k = k + 1
def reset(self):
for light in self._lights:
light.is_on = False #
light_board = SwitchBoard(10)
print(light_board)
light_board.filp_every(2)
print(light_board)
light_board.filp(2)
print(light_board)
light_board.reset()
print(light_board)
light_board.filp_every(1)
print(light_board)
有的代码可以写得更简洁,基类已经提供的服务(接口),在派生类中直接使用就可以了。下面的仅供参考。
class LightSwitch:
def __init__(self,condition):
self.is_on = condition
if not isinstance(condition,bool):
InvaildSwitchExpection = TypeError(“it is not a right state”.format(condition))
raise InvaildSwitchExpection
def turn_on(self):
self.is_on = True
def turn_off(self):
self.is_on = False
def filp(self):
self.is_on = not self.is_on ##
def __str__(self):
if self.is_on == True:
return “I am on”
else:
return “I am off”
class SwitchBoard(LightSwitch):
def __init__(self, number):
self._lights = []
for i in range(number):
i = LightSwitch(False)
self._lights.append(i)
def which_switch(self):
result = []
for i in range(len(self._lights)): ##
if self._lights[i].is_on == True:
result.append(str(i)) #
return result
def __str__(self):
result = self.which_switch() #
result_str = ‘,’.join(result)
return ‘The following switches are on: ‘ + result_str
def filp(self, n):
self._lights[n].filp() ##
def filp_every(self, n):
k = 0
while n * k = len(self._lights) – 1:
self.filp(n * k) ##
k = k + 1
def reset(self):
for light in self._lights:
light.turn_off() ##
light_board = SwitchBoard(10)
print(light_board)
light_board.filp_every(2)
print(light_board)
light_board.filp(2)
print(light_board)
light_board.reset()
print(light_board)
light_board.filp_every(1)
print(light_board)
python -o 是怎么使用的
这是python自己的说明:
-O : optimize generated bytecode slightly
-O 通常是在将py编译为pyo而不是pyc,pyo比pyc小一些所以理论上加载速度会快些(注意是加载速度不是执行速度)。
另外还有一个开关是-OO 这是在-O的基础上再删除去除assert语句和docstring,但是有些模块可能会依赖这些语句,所以要慎用这个开关。
原创文章,作者:B4H6U,如若转载,请注明出处:https://www.506064.com/n/127461.html