简体   繁体   中英

Is it possible to assign a module to different objects and use variables of imported module in Python?

I created a module in Python, that simply sets variables(global). Let the file name of module created be date.py. It has int variables day, month, year

In another Python file, I import this module as:

import date

It is possible to access date variables if I use:

print(date.day)

but if I try to store date in different variables like:

Date1 = date(12,4,2012) Date2= date(3,7,2021)

Now if I try to access particular object for comparison purposes, it is not being possible: ie:

if((Date1.day) == (Date2.day)): pass

Is there a way to handle this usecase?

It is not possible to do a comparison on the date, year, or time because when we get data using direct function if follow her standard functionality like when we got data is: 25/07/2022 this kind of not possible.

If you still wish to do a comparison you can try to do it as first get date then get year inside on conditions like:

if(day1 == day2):
    if(year1==year2):
        print(day.year)
    else:
        break

Maybe you can try this when you compare days and times as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM