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

Return to Question

Post Timeline

edited tags
Link
jfs
  • 417.3k
  • 211
  • 1k
  • 1.7k
edited body
Source Link
Godsent
  • 1k
  • 2
  • 10
  • 24

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 willthe code above should 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. Why was my local calendar module imported here?

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

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..

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 the code above should 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. Why was my local calendar module imported here?

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

Source Link
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..

lang-py

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