-3

I get some cyclic import problems and I wish to avoid them by importing a module inside a class at a Class level so that the module is available for all methods of that class. How can this be done? Ideally I would like to do something like this in the dummye xample below, but it doesn't work:

class MyClass:
    import datetime as dt

    def date_now(self):
        return dt.datetime.now()

    def hour_now(self):
        return dt.datetime.now().hour

1 Answers1

-2

Try:

from filename.MyClass import date_now
Omar
  • 297
  • 5
  • 16
  • no the datetime import does not work like I describe it, this is something that I would like to achieve but importing it like this does not work. How can I import datetime inside my class and have the methods of the class to be able to use it? –  Aug 03 '22 at 08:59