The program runs but its results vary depending on how I started it. If
I run it from the terminal or Idle, I enter a key and the program
fetches the proper record. If I run it from Nautilis or a panel
launcher, I enter the proper key and I get an error message saying the
key does not exist.
I am assuming that I am having path issues but don't know how to correct it.
Thamks, Jim
At an absolute minimum when you describe an error, PASTE the error
message, complete with traceback, into your message. As it stands, I'm
left wondering which key on your keyboard can possibly "not exist."
Perhaps it's a non-ASCII code, and you're getting some encoding error.
That's a common discrepancy between running from a terminal and running
from some GUI.
Even better is to specify the version of Python this program is
presumably written in, and what Linux distro. Then you say it's a GUI
program, so you should specify which GUI library you're using.
Now if I do a bunch of guessing, I might come up with the likelihood
that your "Nautilus" is supplying a different current directory than the
one the script is located in. You can find that out by looking at:
os.path.abspath(os.curdir)
But of course how you print that depends on what GUI package you're running.
DaveA
If you determine that the current directory is your problem, and that
Nautilus isn't setting it the way you'd like, then you may have to
resort to other ways to identify the other files you mention. Easiest
way might be to use the __file__ attribute of each module, which gives
its complete path. So your code in the main script could do something
like (untested):
target = os.path.dirname(__file__)
os.chdir(target)
Better is usually to ignore current directory, and passed the desired
directory name into whatever function is going to use it.
HTH,
DaveA
I added target = os.path.dirname(__file__) and printed the result. If I
run the script in Idle it produces the correct result and shows the path
as /usr/bin. Running it form the terminal produces the correct result
but shows the path empty. Running it from Nautilus or a launcher does
not produce the correct result and shows the full path to the directory
that contains the script and its files.
If I add os.chdir(target) to the script, Idle and the terminal stop
producing the correct result and the launcher and Nautilius start
producing the correct result. This is exactly the opposite of what I
expected.
> Better is usually to ignore current directory, and passed the desired
> directory name into whatever function is going to use it.
I'll keep this in mind for anything I write. Right now I'm trying to
understand some examples that were produced in a Windows environment.
Like I said at the top I am new to Linux (Ubuntu) and don't fully
understand its requirements.
> HTH,
>
> DaveA
>
>
Thanks, Jim
target = os.path.abspath(os.path.dirname(__file__))
This should then be the same no matter how you launch the script.
Any other guesses would need some sample code that shows the failure.
But you probably need to simplify it substantially to convince a
volunteer to look at it.
DaveA
Just want to say thanks for furthering my python understanding.
Regards Jim