鱼C论坛

 找回密码
 立即注册
查看: 2470|回复: 8

[已解决]关于46python课后作业的问题

[复制链接]
发表于 2019-11-30 22:05:56 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 1059389705 于 2019-12-1 20:02 编辑
  1. import time as t

  2. class Record:
  3.     def __init__(self,value=None,name=None):
  4.         self.na = name
  5.         self.val = value
  6.         self.time = []
  7.         self.unit = ['年','月','日','时','分','秒']
  8.         self.prompt = '于北京时间'

  9.     def __get__(self,instance,owner):
  10.         self._timer()
  11.         return self.val

  12.     def __set__(self,instance,value):
  13.         self.val = value
  14.         self._timer()


  15.     def _timer(self):
  16.         current = t.localtime()
  17.         f = open('D:\\record.txt','a',encoding = 'utf-8')
  18.         for index in range(6):
  19.             self.prompt += str(self.time.append(current[index])) + self.unit[index]
  20.         print(self.prompt)
  21.         f.write('%s变量 %s 被修改 %s = %s \n '% (self.na,self.prompt,self.na,str(self.val)))
  22.         f.close()
  23.         #初始化prompt
  24.         self.prompt = '于北京时间
复制代码


class Test:
    x = Record(10,'x')
    y = Record(8.8,'y')
最佳答案
2019-12-1 20:06:49
应该这样改:

  1. import time as t

  2. class Record:
  3.     def __init__(self,value=None,name=None):
  4.         self.na = name
  5.         self.val = value
  6.         self.time = []
  7.         self.unit = ['年','月','日','时','分','秒']
  8.         self.prompt = '于北京时间'

  9.     def __get__(self,instance,owner):
  10.         self._timer()
  11.         return self.val

  12.     def __set__(self,instance,value):
  13.         self.val = value
  14.         self._timer()


  15.     def _timer(self):
  16.         current = t.localtime()
  17.         f = open('E:\\record.txt','a',encoding = 'utf-8')
  18.         for index in range(6):
  19.             self.prompt += str(current[index]) + self.unit[index]
  20.         print(self.prompt)
  21.         f.write('%s变量 %s 被修改 %s = %s \n '% (self.na,self.prompt,self.na,str(self.val)))
  22.         f.close()
  23.         #初始化prompt
  24.         self.prompt = '于北京时间'
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-11-30 22:07:15 | 显示全部楼层
结果:于北京时间None年None月None日None时None分None秒
为什么我的打印出来是这样的啊 这是我自己写的 和小甲鱼方法不太一样 ,其他的都成功就是这个时间都是None啊,求大神指导
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-1 10:24:11 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2019-12-1 11:23:30 | 显示全部楼层
有没有大佬回答一下呀
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-1 14:15:20 From FishC Mobile | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-12-1 16:43:33 | 显示全部楼层
代码不全
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-1 20:03:31 | 显示全部楼层

ok我把代码全打出来啦  麻烦大佬看看什么问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2019-12-1 20:06:49 | 显示全部楼层    本楼为最佳答案   
应该这样改:

  1. import time as t

  2. class Record:
  3.     def __init__(self,value=None,name=None):
  4.         self.na = name
  5.         self.val = value
  6.         self.time = []
  7.         self.unit = ['年','月','日','时','分','秒']
  8.         self.prompt = '于北京时间'

  9.     def __get__(self,instance,owner):
  10.         self._timer()
  11.         return self.val

  12.     def __set__(self,instance,value):
  13.         self.val = value
  14.         self._timer()


  15.     def _timer(self):
  16.         current = t.localtime()
  17.         f = open('E:\\record.txt','a',encoding = 'utf-8')
  18.         for index in range(6):
  19.             self.prompt += str(current[index]) + self.unit[index]
  20.         print(self.prompt)
  21.         f.write('%s变量 %s 被修改 %s = %s \n '% (self.na,self.prompt,self.na,str(self.val)))
  22.         f.close()
  23.         #初始化prompt
  24.         self.prompt = '于北京时间'
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2019-12-2 20:07:22 | 显示全部楼层

谢谢啦  OK啦
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-14 01:12

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表