Too long of a process to save .py scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jimpy
    New Member
    • Mar 2008
    • 7

    Too long of a process to save .py scripts

    Greetings,
    Using Ubuntu 7.10 and Python 2.5.1 (r251:54863, Mar 7 2008, 04:10:12)
    [GCC 4.1.3 20070929 (prerelease) (Ubuntu 4.1.2-16ubuntu2)] on linux2

    I am presently going through the "A Byte Of Python" tutorial.

    When I copy the little .py scripts and save them, I find they must be in the /usr/bin directory.

    But I cannot directly save them to that location. I have to save them to my Documents folder, then execute a "gksudo nautilus" command to access /usr/bin. Then click and drag the file into the /usr/bin directory.

    Very cumbersoe, but I don't know any other way to get them in the right location.

    Obviously, I am relatively new to Ubuntu, and absolutely new to Pythoon.

    Thank you
  • Laharl
    Recognized Expert Contributor
    • Sep 2007
    • 849

    #2
    You do not need to save python scripts in /usr/bin. Make the first line of the script (every script) #!/usr/bin/python if you want to use ./ to run it after marking it executable with chmod. Otherwise, you can use python to run the script with the command 'python foo.py'.

    Comment

    • jimpy
      New Member
      • Mar 2008
      • 7

      #3
      Thank you for the reply, Lahari -
      I do make the first line #! /usr/bin/python.
      And I do make the scripts executable.
      You last answer,
      "Otherwise you can use python to run the script with the command python foo.py",
      went over my head.
      With the script residing in /usr/bin, I can open a terminal and type the just the script name, and it will execute.
      My problem is getting the scripts into place without so much effort.
      I know I am missing something here, but I just don't know what it is.

      Comment

      • micmast
        New Member
        • Mar 2008
        • 144

        #4
        I think you want to execute it like this:

        $> myprogram.py

        right?

        if so you need to add the directory to your working path

        $> PATH=/my/home/dir/with/python/scripts/:$PATH

        Don't forget the $PATH at the end!!!!


        The easy way:

        just add ./ in front of the script

        $> ./myprogram.py

        Comment

        • jimpy
          New Member
          • Mar 2008
          • 7

          #5
          Ah yes ... that is good. Problem solved. Sometimes I can be very very dense.

          Many thanks for the replies. It's really appreciated.

          And now, onward and upward!

          Comment

          • Laharl
            Recognized Expert Contributor
            • Sep 2007
            • 849

            #6
            The 'python foo.py' is telling python to run the file foo.py. If you had a different file, say myfile.py, the command would be python myfile.py. This is more secure than adding . to your path. If you just type 'python' in, you'd get an interactive Python shell you can use to try things out that can be quite useful sometimes.

            Comment

            Working...