Vinnaren i pepparkakshustävlingen!
2009-07-16, 21:45
  #1
Medlem
Kod:
import os
import time
import zipfile

source = '/Users/Andrea/Documents/Code'

target_dir = '/Users/Andrea/Desktop/Backup'

today = target_dir + os.sep + time.strftime('%Y%m%d')

now = time.strftime('%H%M%S')

comment = input("You may here enter a comment which will then be added to the filename.\
\n\
\n\
Please note that spaces in the comment will be replaced with underscores.\
\n\
\n\
You may skip this step by pressing Return.\
\n\
\n\Please enter a comment: ")
if len(comment) ==0:
    target = today + os.sep + now + 'zip'
else:
    target = today + os.sep + now + '_' + \
             comment.replace(' ', '_') + '.zip'

if not os.path.exists(today):
    os.mkdir(today)
    print('Successfully created directory', today)

#zipfile.ZipFile(file[, mode[, compression[, allowZip64]]])

zip = zipfile.ZipFile(target, 'w')#.format(target, ' '.join(source))
zip.write(source)
zip.close()


if zipfile(zip) ==0:
    print('Successfully backed up to', target)
else:
    print('Backup FAILED')

<<<<<<<<FELMEDDELANDE>>>>>>>>>>

Traceback (most recent call last):
  File "/Users/Andrea/Documents/Code/backup_ver5_1.py", line 39, in <module>
    if zipfile(zip) ==0:
TypeError: 'module' object is not callable

Jag skulle bli mycket tacksam till en pointer gällande anledningen till det här.

S
__________________
Senast redigerad av Sargaroth 2009-07-16 kl. 21:55.
Citera
2009-07-17, 00:52
  #2
Medlem
DrMegahertzs avatar
Anledningen är precis som felet antyder; en modul går inte att anropa som en funktion, vilket du försöker göra på rad 39.

Jag antar att du försöker kontrollera om ziparkivet skapades utan problem, men det gör du snarare genom att fånga exceptions från ZipFile.
Citera

Skapa ett konto eller logga in för att kommentera

Du måste vara medlem för att kunna kommentera

Skapa ett konto

Det är enkelt att registrera ett nytt konto

Bli medlem

Logga in

Har du redan ett konto? Logga in här

Logga in