Works only in interactive mode

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • qwweeeit@yahoo.it

    #1

    Works only in interactive mode

    Hi all,
    using Python 2.4 under Linux (SUSE 9.3) I was developping a script to
    get various lists related with DCOP.
    In interactive Python all is working correctly:

    import pcop

    # application's registration with DCOP
    x=pcop.register _as('kate')
    print x
    kate-7497

    # list of DCOP registered applications
    print pcop.app_list(' kate')
    ['kwin', 'kicker', 'konqueror-7203', 'kate', 'kded', 'kmix',
    'kate-7497', 'knotify', 'susewatcher', 'suseplugger',
    'kio_uiserver', 'kcookiejar', 'klauncher', 'khotkeys', 'kdesktop',
    'konsole-7340', 'klipper', 'ksmserver', 'kaccess', 'kpowersave']

    Instead as a script:

    1 import pcop
    2
    3 # application's registration with DCOP
    4 x=pcop.register _as('kate')
    5 print x
    6
    7 # list of DCOP registered applications (emula dcop)
    8 print pcop.app_list(' kate')

    you get:
    0
    Traceback (most recent call last):
    File "/home/bf/python/pippo.py", line 4, in ?
    x=pcop.register _as('kate')
    AttributeError: 'module' object has no attribute 'register_as'

    How is it possible?
    Bye.

  • Sam Pointon

    #2
    Re: Works only in interactive mode

    That looks like a different module named pcop getting in the way. If
    there's another pcop.py in the directory where you're running it as a
    script, then that gets priority and you'll end up with an error like
    the one you got. However, if you run it interactively, then that
    directory is not checked, or is (normally) checked lower-down than,
    say, Python's standard library. Try checking if help(pcop) and
    dir(pcop) are what you expect in the script, and looking at where
    sys.path is looking for scripts.

    Comment

    • qwweeeit@yahoo.it

      #3
      Re: Works only in interactive mode

      Hi Sam,
      thank you very much. Your diagnosis was perfect!
      Bye.

      Comment

      Working...