1

我正在使用 Python 尝试自动化 Attachmate - EXTRA!,类似于 VBA 中的大多数操作。

我正在使用此处找到的包 pywin32。 我在这里使用 OLE 如何与 Attachmate 一起工作的文档(可以找到 GetString 和 PutString 方法)

我的代码:

system = win32com.client.Dispatch("EXTRA.System")
sess0 = system.ActiveSession

product = sess0.screen.GetString(0, 1, 2)

产生错误:

line13: product = sess0.screen.GetString(1, 1, 2)
TypeError: 'str' object is not callable

据说 GetString 方法具有语法:rc = object.GetString (Row, Col, Length, [Page]),但我在 Python 中对这种语法的上述尝试会产生上述错误。

我研究了这个错误,发现它相当于尝试做:“mystring”()。这不应该是,因为当我检查 sess0 的类型时,它确实是 a: <class 'win32com.client.CDispatch'>

我知道这个问题可能源于语法与 Attachmate/OLE 页面上解释的不同。但是,PutString 方法被解释为具有这种语法:object.PutString String [,Row][,Col][,Page],但我使用它可以正常工作:sess0.screen.PutString("90", 1, 79)。该代码正确地将字符串“90”放置在我的 Attachmate 会话中的位置 1, 79。

我很好奇这是否是包裹本身的问题。如果有人有尝试使用 Python 自动化 Attachmate 的经验,将不胜感激他们的帮助!

4

1 回答 1

1

我使用这些功能在 Attachmate EXTRA 上进行读写!屏幕

尝试以下操作:

import win32com.client

def write(screen,row,col,text):
    screen.row = row
    screen.col = col
    screen.SendKeys(text)


def read(screen,row,col,length,page=None):
    if page is None:
        return screen.Area(row, col, row, col+length).value
    else:
        return screen.Area(row, col, row, col+length, page).value


def test():
    system = win32com.client.Dispatch("EXTRA.System")
    sess0 = system.ActiveSession
    screen = sess0.Screen

    product = read(screen, 1, 1, 2)
    print(product)
    write(screen, 1, 79, "90")

文档:

Screen.Area(StartRow,StartCol,EndRow,EndCol[,Page][,Type])

发送键(字符串)

于 2016-12-21T14:23:29.037 回答