2013-10-27 85 views
-2

我有一個SQLite數據庫創建當前代碼:Python中創建的SQLite數據庫

import storage 
import os 
import audiotools 

def store_dir(d): 
    store = storage.HashStore() 
    for root, bar, files in os.walk(d): 
     for filename in files: 
      filename = root + '/' + filename 

      try: 
       store.store_file(filename) 
       print ("Stored %s% filename") 
      except audiotools.UnsupportedFile: 
       print ('Skipping unsupported file %s') % filename 
      except Exception, e: 
       print (e) 

def main(): 
    d = input('Enter the path to the music directory: ') 
    store_dir(d) 
    print ("Done.") 

if __name__ == '__main__': 
    main() 

運行此代碼時,我得到一個語法錯誤味精。請幫忙 ! 在此先感謝

+2

請包括錯誤堆棧跟蹤。 – tacaswell

+6

以及在這段代碼中你在做什麼與sqlite? – tacaswell

回答

0

這裏有幾件事要解決。

首先,這條線:

print ('Skipping unsupported file %s') % filename 

需求是這樣的:

print ('Skipping unsupported file %s' % filename) 

其次,你需要在這裏使用raw_input

d = input('Enter the path to the music directory: ') 

它返回一個字符串對象,而不是input,它將輸入評估爲真正的Python代碼。

第三,您的縮進已關閉。我很確定這只是一個SO格式錯誤。

最後,你應該在這裏使用os.path.join

filename = root + '/' + filename 

這是不是一個錯誤,雖然,只是一個提示。

總而言之,你的代碼應該是這樣的:

import storage 
import os 
import audiotools 

def store_dir(d): 
    store = storage.HashStore() 
    for root, bar, files in os.walk(d): 
     for filename in files: 
      filename = os.path.join(root, filename) 

      try: 
       store.store_file(filename) 
       print ("Stored %s% filename") 
      except audiotools.UnsupportedFile: 
       print ('Skipping unsupported file %s' % filename) 
      except Exception, e: 
       print (e) 

def main(): 
    d = raw_input('Enter the path to the music directory: ') 
    store_dir(d) 
    print ("Done.") 

if __name__ == '__main__': 
    main()