FAQ
I try to start a default application for reading a pdf file inside the
python script.

I try

os.startfile(name,option) but say me startfile not implemented

there are some system to start for example acrobar or okular from the
script with a name of pdf file?

thenks Angelo

Search Discussions

  • Grant Edwards at Sep 8, 2009 at 8:01 pm

    On 2009-09-08, Angelo Ballabio wrote:

    I try to start a default application for reading a pdf file
    inside the python script.

    I try

    os.startfile(name,option) but say me startfile not implemented
    Are you _sure_ it says startfile not implemented? Or does
    it say this:
    os.startfile("foo.bar")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'startfile'

    [You'll always get better answers if your questions are
    specific and precise -- whenever possible, you should paste in
    actual code and error messages.]
    there are some system to start for example acrobar or okular
    from the script with a name of pdf file?
    Google tells me that Okular is something for KDE. That implies
    that you're running Linux or Unix? [When asking a question, you
    also need to provide OS, Python version, etc.]

    If you are running Linux/Unix, then I suspect the answer to
    your problem can be seen in the fine documentation at

    http://docs.python.org/library/os.html#process-management

    os.startfile(path[, operation])

    Start a file with its associated application.
    [...]
    Availability: Windows.

    If you want to do something similar on Unix/Linux, you'll
    probably need to call some desktop-specific.

    Googling for python+startfile+linux found me these links:

    http://mail.python.org/pipermail/python-list/2003-March/193897.html
    http://lists.freebsd.org/pipermail/freebsd-python/2004-August/000138.html


    --
    Grant Edwards grante Yow! FOOLED you! Absorb
    at EGO SHATTERING impulse
    visi.com rays, polyester poltroon!!
  • Angelo Ballabio at Sep 8, 2009 at 8:22 pm
    Sorry to not be very specific

    My problem is a way to run a default application to read and show a pdf
    file from unix or windows, i have a mixed ambient in the office, so I am
    try to find a way to start a application to show this pdf file I
    generate whith reportlab. actualy I write a file in a directory and then
    I have to open the directory find a file and open it, I try to find a
    way to do this automatic, in this way then they only have to close the
    windows.

    sorry I do not see before is only for windows, so this means under unix
    system I cant to use.

    thenks for the suggestion


    Angelo


    Grant Edwards ha scritto:
    On 2009-09-08, Angelo Ballabio wrote:

    I try to start a default application for reading a pdf file
    inside the python script.

    I try

    os.startfile(name,option) but say me startfile not implemented
    Are you _sure_ it says startfile not implemented? Or does
    it say this:
    os.startfile("foo.bar")
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    AttributeError: 'module' object has no attribute 'startfile'
  • Albert Hopkins at Sep 8, 2009 at 11:22 pm

    On Tue, 2009-09-08 at 22:22 +0200, Angelo Ballabio wrote:
    My problem is a way to run a default application to read and show a
    pdf
    file from unix or windows, i have a mixed ambient in the office, so I
    am
    try to find a way to start a application to show this pdf file I
    generate whith reportlab.
    The (most) portable way to do so in Linux (not necessarily Unix) is to
    use the xdg-open command. Ex,

    subprocess.Popen(['xdg-open', 'my-document.pdf'])

    If you want cross-platform between Linux/Windows, then it's advisable to
    write a wrapper function that checks the value of sys.platform and and
    acts accordingly.

    -a
  • Angelo Ballabio at Sep 9, 2009 at 7:59 pm
    Thenks for this suggestion, at the end I find this solution

    import os
    .
    .
    #then where I decide to show the file in the default application I put this

    #file_name the name I construct with path and all necessary
    #recor contain all the data of one record end the 4th position
    #the name of the file
    #for example
    file_name = os.path.join('document',str(record[3]) + ".pdf")
    #the joun function make the separator from ducoment to the file
    #name relative to operatin system (windows '\') , (unix '/')

    #then where I call the default program
    if os.name == "nt":
    os.filestart("%s" % nome_file)
    elif os.name == "posix":
    os.system("/usr/bin/xdg-open %s" % nome_file)

    Other nice solution is

    import webbrowser
    .
    .
    .
    webbrowser.open(file_name)

    The difference is in unix sistem, the first call the default program for
    read the file of type, in this case pdf, this meens okular, acroread, or
    whatever, the second open the konqueror in kde desktop, in windows the
    function os.filestart call the default application for thet type of file

    interesting discussion about this I find in :

    http://ubuntuforums.org/showthread.php?t03198

    very thenks to all
    Angelo

    Albert Hopkins ha scritto:
    The (most) portable way to do so in Linux (not necessarily Unix) is to
    use the xdg-open command. Ex,

    subprocess.Popen(['xdg-open', 'my-document.pdf'])

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedSep 8, '09 at 7:42p
activeSep 9, '09 at 7:59p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase