Platform independent code?

Discussion in 'Python' started by saneman, Jun 14, 2008.

  1. saneman

    saneman Guest

    I have read that Python is a platform independent language. But on this
    page:

    http://docs.python.org/tut/node4.html#SECTION004220000000000000000

    it seems that making a python script executable is platform dependant:

    2.2.2 Executable Python Scripts
    On BSD'ish Unix systems, Python scripts can be made directly executable,
    like shell scripts, by putting the line


    #! /usr/bin/env python
    (assuming that the interpreter is on the user's PATH) at the beginning of
    the script and giving the file an executable mode. The "#!" must be the
    first two characters of the file. On some platforms, this first line must
    end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or Windows
    ("\r\n") line ending. Note that the hash, or pound, character, "#", is used
    to start a comment in Python.

    The script can be given an executable mode, or permission, using the chmod
    command:


    $ chmod +x myscript.py



    Are there any guidelines (API'S) that gurantees that the python code will be
    platform independent?
     
    saneman, Jun 14, 2008
    #1
    1. Advertising

  2. Hi,

    Python is a platform independent language, period. You can always
    excute a Python script with python script.py. Now, with Windows, you
    can execute the script by doucle-clicking on it. With Linux, it's
    different, you have to use the shebang line to execute a script with
    the correct interpreter. But this has nothing to do with the fact that
    Python is a platform independent language.
    Some modules may not be available on all platform, for the answer to
    this question, see the documentation of the module ;)

    Matthieu

    2008/6/14 saneman <>:
    > I have read that Python is a platform independent language. But on this
    > page:
    >
    > http://docs.python.org/tut/node4.html#SECTION004220000000000000000
    >
    > it seems that making a python script executable is platform dependant:
    >
    > 2.2.2 Executable Python Scripts
    > On BSD'ish Unix systems, Python scripts can be made directly executable,
    > like shell scripts, by putting the line
    >
    >
    > #! /usr/bin/env python
    > (assuming that the interpreter is on the user's PATH) at the beginning of
    > the script and giving the file an executable mode. The "#!" must be the
    > first two characters of the file. On some platforms, this first line must
    > end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or Windows
    > ("\r\n") line ending. Note that the hash, or pound, character, "#", is used
    > to start a comment in Python.
    >
    > The script can be given an executable mode, or permission, using the chmod
    > command:
    >
    >
    > $ chmod +x myscript.py
    >
    >
    >
    > Are there any guidelines (API'S) that gurantees that the python code will be
    > platform independent?
    >
    >
    > --
    > http://mail.python.org/mailman/listinfo/python-list
    >




    --
    French PhD student
    Website : http://matthieu-brucher.developpez.com/
    Blogs : http://matt.eifelle.com and http://blog.developpez.com/?blog=92
    LinkedIn : http://www.linkedin.com/in/matthieubrucher
     
    Matthieu Brucher, Jun 14, 2008
    #2
    1. Advertising

  3. saneman

    bukzor Guest

    On Jun 14, 6:28 am, "saneman" <> wrote:
    > I have read that Python is a platform independent language.  But on this
    > page:
    >
    > http://docs.python.org/tut/node4.html#SECTION004220000000000000000
    >
    > it seems that making a python script executable is platform dependant:
    >
    > 2.2.2 Executable Python Scripts
    > On BSD'ish Unix systems, Python scripts can be made directly executable,
    > like shell scripts, by putting the line
    >
    > #! /usr/bin/env python
    > (assuming that the interpreter is on the user's PATH) at the beginning of
    > the script and giving the file an executable mode. The "#!" must be the
    > first two characters of the file. On some platforms, this first line must
    > end with a Unix-style line ending ("\n"), not a Mac OS ("\r") or Windows
    > ("\r\n") line ending. Note that the hash, or pound, character, "#", is used
    > to start a comment in Python.
    >
    > The script can be given an executable mode, or permission, using the chmod
    > command:
    >
    > $ chmod +x myscript.py
    >
    > Are there any guidelines (API'S) that gurantees that the python code will be
    > platform independent?


    The only guarantee is testing it on both yourself. Some modules are
    inherently os-dependant (much of the 'os' module for example), and
    some constructs just don't work on all platforms (using
    os.environ['LOGNAME'] or system('cat file') as examples).

    If you stick to python code that doesn't touch the OS directly, you
    won't (read: shouldn't) have a problem, but when you start interacting
    with the OS directly you have to think hard about what you're doing.

    --Buck
     
    bukzor, Jun 14, 2008
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ibeetb
    Replies:
    1
    Views:
    454
    Steve C. Orr [MVP, MCSD]
    Jun 1, 2004
  2. Harald Hein
    Replies:
    9
    Views:
    434
    Andrew Thompson
    Aug 17, 2003
  3. RA Scheltema
    Replies:
    10
    Views:
    556
    Joona I Palaste
    Jan 24, 2004
  4. RA Scheltema

    platform independent serialization of a long

    RA Scheltema, Jan 23, 2004, in forum: C Programming
    Replies:
    10
    Views:
    599
    Joona I Palaste
    Jan 24, 2004
  5. John Smith

    Platform independent code?

    John Smith, Aug 24, 2010, in forum: C++
    Replies:
    26
    Views:
    1,385
    John Smith
    Sep 6, 2010
Loading...

Share This Page