Skip to content

__file__ returns differnet filenames #363

Open

Description

@HahnloserR

when a jython script runs for the first time, file returns the source filename.

while running the script another time, file returns the name of the bytecode file.

Shouldn't it return the sourcefilename all the time? Is there a parameter to change the behaviour?

The behaviour seems to be changed with the update from V2.7.2 to V2.74.

Activity

  1. jeff5 commented on Dec 3, 2024

    @jeff5
    Member

    I don't observe this in tests.

    PS 363> jython -V
    Jython 2.7.4
    PS 363> cat filename.py
    print __file__
    PS 363> jython filename.py
    filename.py
    PS 363> jython filename.py
    filename.py
    

    If you import a module, then yes it makes a compiled file and reads it the second time, but so does CPython.

    PS 363> jython -c"import filename"
    filename.py
    PS 363> jython -c"import filename"
    filename$py.class
    PS 363> python -c"import filename"
    filename.py
    PS 363> python -c"import filename"
    filename.pyc
    

    It may have changed since 2.7.2. We're always fixing things. :)

  2. HahnloserR commented on Dec 5, 2024

    @HahnloserR
    Author

    Sorry, you're absolutely right, I was talking about an imported module.

    I helped myself by disabling the generation of bytecode.
    Is there a significant difference in execution time using bytecode or not?

  3. jeff5 commented on Dec 6, 2024

    @jeff5
    Member

    I don't have any figures, and only the obvious to point out, that it does the compilation again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions