我有文件x1.py,在该类vpn()中,我具有check_vpn()和connect_vpn()函数。我试图在另一个文件x2.py中调用此2函数,但get模块没有属性错误。
print(sortedData.to_string(index=False))
custID purchase_date
100 12/01/2019
100 23/01/2019
110 05/01/2019
110 05/05/2019
110 06/05/2019
110 23/01/2019
110 23/01/2019
160 02/07/2019
160 11/01/2019
160 19/01/2019
我想要在x2.py中输出check_vpn()和connect_vpn(),但是我得到了
回溯(最近通话最近一次):
“ ./ x2.py”文件,第4行,位于
import x1
from x1 import check_vpn
from x1 import connect_vpn
class vpn():
vpn_bin= '/home/'
flag= False
def check_vpn(self):
myCmd = os.popen('ps aux | grep vpnc').read()
print(myCmd)
for data in myCmd:
if re.search(r'vpn.conf\b',myCmd):
print("Vpn connected")
self.flag = True
return self.flag
break
def connect_vpn(self,token1):
print("#########")
AttributeError:模块'x1'没有属性'check_vpn'
答案 0 :(得分:0)
您的代码有一些问题
我进行了一些更改以解决上述错误,但可能还有更多我没抓住的地方
x1
WITH CTE AS (
SELECT tid,
aid,
count(aid) as cnt
FROM startingtable
GROUP BY tid, aid
)
insert into #temp (tid,aid,cnt)
select t2.tid,
t2.aid,
t2.cnt
from (
SELECT *,ROW_NUMBER() OVER(PARTITION BY tid order by cnt desc) rn
FROM CTE
) t2
where rn = 1
x2
import os
import re
class vpn():
vpn_bin= '/home/'
flag= False
def check_vpn(self):
myCmd = os.popen('ps aux | grep vpnc').read()
print(myCmd)
for data in myCmd:
if re.search(r'vpn.conf\b',data):
print("Vpn connected")
self.flag = True
return self.flag
def connect_vpn(self,token1):
print("#########")