Skip to main content
Stack Overflow
  1. About
  2. For Teams

Return to Revisions

1 of 3
Godsent
  • 1k
  • 2
  • 10
  • 24

relative import in Python 3

Say my project is structured like this:

myproject
├── calendar.py
└── foo.py
└── __init__.py

In foo.py, I have

from calendar import isleap

I thought in Python 3.x, without using the explicit .calendar this will load the build-in calendar module instead my own calendar module, but apparently my local calendar.py is still being imported and it throws an error because there's no 'isleap' in mypkg/calendar.py

I had to rename calendar.py to cal.py to get this work..

Godsent
  • 1k
  • 2
  • 10
  • 24
lang-py

AltStyle によって変換されたページ (->オリジナル) /