How to run program in Linux

Dave Angel davea at ieee.org
Fri Apr 16 10:32:02 EDT 2010


Jim Byrnes wrote:
> Dave Angel wrote:
>> Jim Byrnes wrote:
>>> <div class="moz-text-flowed" style="font-family: -moz-fixed">I am just
>>> learning Python and am new to Linux so I am probably doing something
>>> to trip myself up. I am trying to run an example GUI program that
>>> fetches a record from a database. All the files are in the same folder.
>>>
>>> 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
>>>
>> Presumably you're also new to mailing lists.
>
> Not really.
>
>> 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.
>
> The error was generated by the program, not Python.  The 'key' I was 
> referring to was a dictionary type key, not a physical one on the 
> keyboard.
>
>> 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.
>
> Python 2.6,  Ubuntu 9.10,  tkinter
>
>> 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)
>
> OK, thanks.  If that is the case how do I correct it?
>
>> But of course how you print that depends on what GUI package you're
>> running.
>>
>> DaveA
>>
>
> Regards,  Jim
>
>
You forgot to include the list in your reply.  Try using reply-all instead.

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




More information about the Python-list mailing list