AttributeError: module 'virtkey' has no attribute 'press_unicode'

Asked by Archie Halliwell

(using python3)
Cannot use virtkey
This module is probably long outdated, but for some reason it is still built for Ubuntu 19.10, so why does it have no proper documentation whatsoever?

Code:
import virtkey
import time

v = virtkey.virtkey
for i in range(1, 10):
    v.press_unicode(ord("v"))
    time.sleep(1)

Error:
Traceback (most recent call last):
  File "virtkey.py", line 1, in <module>
    import virtkey
  File "/home/archie/Documents/virtkey/virtkey.py", line 6, in <module>
    v.press_unicode(ord("v"))
AttributeError: module 'virtkey' has no attribute 'press_unicode'

VScode gives the error:
Module 'virtkey' has no 'press_unicode' member

What I am trying to do is to press the "v" key ten times.
I have tried using virtkey.press_unicode as well as v.press_unicode, but nothing seems to work

using an example from c. 2007, it also doesn't work

Question information

Language:
English Edit question
Status:
Solved
For:
virtkey Edit question
Assignee:
No assignee Edit question
Solved by:
Archie Halliwell
Solved:
Last query:
Last reply:
Revision history for this message
Manfred Hampl (m-hampl) said :
#1

Even if there is not much documentation, you still should follow it closely:

You need

v = virtkey.virtkey()

with "()" at the end.

Revision history for this message
Archie Halliwell (archiolgy) said :
#2

Using parentheses creates the error:
Traceback (most recent call last):
  File "test.py", line 1, in <module>
    import virtkey
  File "/home/archie/Documents/virtkey/virtkey.py", line 4, in <module>
    v = virtkey.virtkey()
TypeError: 'module' object is not callable

Revision history for this message
Manfred Hampl (m-hampl) said :
#3

Which operating system (including version number if applicable) are you running, how did you install virtkey, which program example do you try to follow?

Revision history for this message
Manfred Hampl (m-hampl) said :
#4

And additionally: You seem to have a conflict between the virtkey python module and your own script, because they both use the same name - virtkey.

Revision history for this message
Archie Halliwell (archiolgy) said :
#5

Running ubuntu 19.10 and installed through apt

Changing the name of the file and deleting virtkey.pyc fixed the issue, so now I can hold the v key all I want

Thanks for pointing out the obvious trap for young players.