【发布时间】:2019-03-14 01:36:21
【问题描述】:
我不断收到以下错误
g:\python_test>py3 lib\libtest.py p = g:\python_test\SqlLogon.txt 回溯(最近一次通话最后): 文件“lib\libtest.py”,第 43 行,在
i.printit('c:\mylog.log')
文件“lib\libtest.py”,第 32 行,在 printit 中
s = wos()
NameError: name 'wos' 未定义
如果我删除对 os 的调用并让 s = 'WINDOWS' 一切正常。 为什么我不能调用该函数?以下是给出问题的代码!
import sys
import platform
import os
import subprocess
class utl:
def __init__(self,path):
self.path = path
print ('p = ' + self.path)
def usr(self):
lc = open(self.path,'r')
up = lc.readlines()
u = up[0]
u = u.strip('\n')
p = up[1]
p = p.strip('\n')
return u,p
def wos(self):
p = platform.system()
print ('type = ' + str(type(p)))
return p.upper()
def printit(self,filetoprt):
s = wos() # undefined wos
#s = "WINDOWS"
print ('os1 = ' + s + ' ' + filetoprt)
if s == ('WINDOWS'):
os.startfile(filetoprt,'print')
#x = LogonSql.usr('g:\python_test\lib\jcd.txt')
i= utl('g:\python_test\SqlLogon.txt')
p = i.usr()
#t = i.wos()
i.printit('c:\mylog.log')
【问题讨论】:
标签: python