[Tutor] Path?

Jim Byrnes jf_byrnes at comcast.net
Wed Jul 14 18:41:22 CEST 2010


Adam Bark wrote:
> On 14 July 2010 02:53, Jim Byrnes<jf_byrnes at comcast.net>  wrote:
>
>> Adam Bark wrote:
>>
>> <snipped some old stuff>
>>
>>
>>   If I use the terminal to start the program it has no problem using the
>>>>>> file.  There are multiple files in multiple directories so I was
>>>>>> looking
>>>>>> for
>>>>>> a way to just double click them and have them run.  If it turns out
>>>>>> that
>>>>>> I
>>>>>> must make changes to or for each of the files it will be easier to just
>>>>>> keep
>>>>>> using the terminal.  I've only been using Ubuntu for a few months so I
>>>>>> was
>>>>>> surprised that the program could not see a file that is in the same
>>>>>> directory.
>>>>>>
>>>>>> Regards,  Jim
>>>>>>
>>>>>>
>>>>>
>>>>> The problem is ubuntu doesn't run the script from the directory it's in
>>>>> so
>>>>> it's looking for wxPython.jpg somewhere else.
>>>>>
>>>>>
>>>>>   OK, I mistakenly thought that double-clicking on file in Nautilus would
>>>> take care of the path info.
>>>>
>>>> In my reply above I also mentioned that I tried by dropping it on a
>>>> Launcher on the top panel and that the command the launcher uses is
>>>> usr/bin/python2.6.  Is there a way that the command can be changed so
>>>> that
>>>> it will look in the same directory the python script is in for any file
>>>> it
>>>> needs?
>>>>
>>>> Thanks,  Jim
>>>>
>>>
>>>
>>> Not sure if you got my previous email but you could try writing the bash
>>> script I posted (with the $1 line to get the path) and setting that as
>>> your
>>> launcher, I think it should work.
>>>
>>> Let me know if you didn't get it or it doesn't work.
>>>
>>> HTH,
>>> Adam.
>>>
>>>
>> I got it, got sidetracked and then forgot to look at it again.  Thanks for
>> reminding me.  Your idea works, but with one little downside.  The
>> directories I am working with are chapters in a book.  So as I move from
>> chapter to chapter I will need to change the bash script, but this seems to
>> be less typing than using the terminal.
>>
>>
>> Thanks,  Jim
>>
>
> Ok cool, glad it works. It might be possible to get the path so you don't
> have to set it each time, try this:
>
> #!/bin/bash
> IFS="/"
> path=($1)
> cd $(path[0:#path[*]])
> python $1
>
>
> # Warning, I'm not exactly a competent bash programmer so this may not work
> :-p
>
> Let me know if you need a hand to fix it,
>
> HTH,
> Adam.
>

I tried the new bash code but when I dropped a file on the launcher it 
just flashed an gave no output.  So I tried running the bash script 
(name=runpython) in a terminal and got this error:

/home/jfb/runpython: line 4: path[0:#path[*]]: command not found
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 >>>

I know even less about bash than you do, so I don't where to start to 
debug this.

Thanks,  Jim



More information about the Tutor mailing list