TypeError: 'str' object is not callable with win32com interfacing with Attachmate

别来无恙 提交于 2021-01-28 21:26:38

问题


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

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.

My code:

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

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

Produces the error:

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

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.

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'>.

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.

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!


回答1:


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

Try the following:

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

Documentation:

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

SendKeys(String)



来源:https://stackoverflow.com/questions/40388219/typeerror-str-object-is-not-callable-with-win32com-interfacing-with-attachmat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!