类型错误:'str' 对象不可通过 win32com 与 A​​ttachmate 接口调用 [英] TypeError: 'str' object is not callable with win32com interfacing with Attachmate

查看:35
本文介绍了类型错误:'str' 对象不可通过 win32com 与 A​​ttachmate 接口调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using Python to try to automate Attachmate - EXTRA!, similar to how most do in VBA.

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

I'm using the package pywin32 found here. I'm using the documentation of how OLE works with Attachmate (where both GetString and PutString methods can be found) here.

我的代码:

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 中尝试这种语法时产生了上面的错误.

The method GetString, is said to have syntax: rc = object.GetString (Row, Col, Length, [Page]), but my above attempt at this syntax in Python produces the error above.

我研究了这个错误,发现它相当于尝试做:"mystring"().这不应该是,因为当我检查 sess0 的类型时,它确实是:.

I've researched this error and found that it's the equivalent of trying to do: "mystring"(). This shouldn't be, because when I check the type of my sess0 it indeed is a: <class 'win32com.client.CDispatch'>.

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

I know this problem may stem from the syntax being different than what is explained on the Attachmate/OLE page. However, the PutString method is explained to have this syntax: object.PutString String [,Row][,Col][,Page], but I got it working fine using: sess0.screen.PutString("90", 1, 79). That code correctly puts the string "90" at location 1, 79 in my Attachmate session.

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

I'm curious if maybe this is an issue with the package itself. If anyone has experience trying to automate Attachmate with Python, their help would be greatly appreciated!

推荐答案

我使用这些函数在 Attachmate EXTRA 上读写!屏幕

I use these functions to read and write on an Attachmate EXTRA! Screen

尝试以下操作:

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])

SendKeys(String)

这篇关于类型错误:'str' 对象不可通过 win32com 与 A​​ttachmate 接口调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆