python - "import x" vs "from x import y" clashes, how do I fix? -



python - "import x" vs "from x import y" clashes, how do I fix? -

i have loads of different scripts , whenever seek , merge them tons of problems, illustration in 1 script im using:

import os.path time import time, sleep, strftime, mktime datetime import date, timedelta, datetime

now in sec script have:

import os.path, time datetime import date, timedelta, datetime open('test.txt') filetoread: last_check = float(filetoread.read()) fulldate = time.ctime(os.path.getctime("../main.xml")) struct = time.strptime(fulldate) filetime = datetime.fromtimestamp(time.mktime(struct)) filedate = filetime.replace(hour=0, minute=0, second=0, microsecond=0) if last_check != 1: if last_check+ 1 <= time.time(): if str(filetime)[:10] != str(datetime.now())[:10]: open("test.txt", 'wb') filetowrite: filetowrite.write(str(time.time())) print "time wrote" else: open("test.txt", 'wb') filetowrite: filetowrite.write("1") print "correct" else: if str(filetime)[:10] == str(datetime.now())[:10]: open("test.txt", 'wb') filetowrite: filetowrite.write("1") print "correct" else: print "30 mins not up" else: print "correct"

now when seek alter imports to:

import os.path time import time, sleep, strftime, mktime, ctime datetime import date, timedelta, datetime

i next traceback:

traceback (most recent phone call last): file "c:\testimports.py", line 40, in <module> fulldate = time.ctime(os.path.getctime("../main.xml")) attributeerror: 'builtin_function_or_method' object has no attribute 'ctime'

i prefer import time, datetime, os.path, os route on importing of different parts of module.

any advice?

you imported time.ctime() global name now, as well time.time() function:

from time import time, sleep, strftime, mktime, ctime

so time.ctime() refers attribute of time.time() function.

change reference:

fulldate = ctime(os.path.getctime("../main.xml"))

the question remains then, why did alter it. fine limit number of globals importing module object globals.

python python-2.7 python-import

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -