[Python] How to print to console a clickable link to project file in python?

Discussão em 'Python' iniciado por Stack, Setembro 1, 2025.

  1. Stack

    Stack Membro Participativo

    I want to print to PyCharm's console clickable links to my project's files with line numbers.
    Almost the same thing works when exception stack is printed with traceback.format_exc():

    import traceback

    try:
    raise Exception('test exc')
    except Exception:
    print(traceback.format_exc())


    The above code prints:

    Traceback (most recent call last):
    File "C:\Users\home\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch1.py", line 4, in <module>
    raise Exception('test exc')
    Exception: text exc


    and the "C:\Users\home\AppData\Roaming\JetBrains\PyCharmCE2022.2\scratches\scratch1.py" part is clickable and opens that file on line 4 in PyCharm.

    How to print the same link without causing exception? Is it built-in methods to print link to file in project?

    Continue reading...

Compartilhe esta Página