Works only in interactive mode

Q

qwweeeit

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

Sam Pointon

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top