erwartet laufen Wenn ich es laufen, passiert nichts, aber es wirft keine Fehler, was es tun sollte, ist schnell der Benutzer für die Alaun Zahlen aus der DB zu ziehen, dann diese Alben aus der Bewegung db zu einem tragbaren Gerät. Irgendwelche Ideen, warum es nicht läuft ???Python-Programm nicht als
#!/usr/bin/python
import sqlite3
import os
import shutil
get_albums = []
def makedatabase(dbname):
#dbname = 'mp3_database.db'
if not os.path.exists(dbname):
print"Creating new database", dbname, "and tables", "in dir", os.getcwd()
connection = sqlite3.connect(dbname)
cursor = connection.cursor()
cursor.execute("""CREATE TABLE albums (music_location TEXT, genre TEXT, artist TEXT, album TEXT, album_number int)""")
connection.commit()
connection.close()
print"\nDatabase creation complete proceeding to program"
else:
print"Database name already exists!!!!!"
def album_input(selection):
while True:
response = int(raw_input(selection))
get_albums.append(response)
if response == 0:
print 'continuing'
def process_albums():
for num in get_albums:
connection = sqlite3.connect(dbname)
cursor = connection.cursor()
connection.text_factory = str
album_results = cursor.execute("SELECT genre, music_location, artist, album FROM albums where album_number =?", (num,))
(genre, music_location, artist, album) = album_results.fetchone()
connection.commit()
connection.close()
print genre
print album
genre_dir = os.path.join(dest_dir, genre)
artist_dir = os.path.join(genre_dir, artist)
album_dir = os.path.join(artist_dir, album)
if not os.path.isdir(genre_dir):
os.makedirs(genre_dir)
if not os.path.isdir(artist):
os.makedirs(artist)
if not os.path.isdir(album):
os.makedirs(album)
songs = []
for root, dirs, files in os.walk(music_location):
for fname in files:
songs.append(fname)
sorted_songs = songs.sort
for test in sorted_songs:
finished_song = os.path.join(music_location, test)
new_finished_song = os.path.join(artist, test)
shutil.copyfile(finished_song, new_finished_song)
#main
dest_dir = raw_input("Enter the destination directory to move files to: ")
start_database = makedatabase("mp3database.db")
get_selections = album_input("Enter album numbers, Press 0 to process: ")
start = process_albums
finished = raw_input("Press Enter to exit")
Sie müssen 'process_albums()' statt 'process_albums' – zondo
Ich reparierte das, und ich nahm auch die print‚fort‘Aussage und eine break-Anweisung dort platziert, jetzt, wo ich bin immer globaler Name dbname nicht definiert – bigclampx
'sorted_songs = songs.sort' ist würde sorted_songs zu einem Hinweis auf die' list.sort' Methode, auch wenn Sie es richtig genannt zuweisen Sie es sorted_songs gleich None, .'list.sort() 'Einstellung ist ein Inplace-Verfahren, so dass es nur auf der Liste aufrufen und über die Liste iterieren oder sonst verwenden 'sorted_songs = sortiert (Lieder)' –