Reputation: 168
I am having a issue with getting my desired output (Shown after code) I have tried several different ways and nothing seems to have worked. The following code is just what I left off with when attempting to fix the issue
song_list = []
def get_songs(): # Just gets all songs ready and loaded for other things
global song_names
global song_amount
global song_list
############### Variables
songs_in_folder = list(os.listdir(input_folder)) # Grabs all files in folder Will add for actual .osz detection later on for this stage.
song_list.append(songs_in_folder) # Adds to song_list which is currently just used for testing else where.
# Checks if files are even in folder or not, does not check extentions, must fix in the future
if songs_in_folder >= 1:
song_amount = 1
else:
print("No Songs were found in the directory!")
time.sleep(2)
exit()
############### Code to clean up file names for users and stuff
for elem in songs_in_folder:
beatmap_name = elem[6:] # Cuts off the first 6 characters which are always 6 different numbers ex) 827212 nameless- Milk Crown On Sonnetica => nameless- Milk Crown On Sonnetica
songs_in_folder = string.strip(beatmap_name,'.osz') # Removes file extention '.osz' leaving just each songs name => nameless- Milk Crown On Sonnetica
######## Add song number and name together
song_list = ("[",song_amount,"]",songs_in_folder) # Fixes lists look without numbers or .osz extention. Easy to read this way.
song_amount = int(song_amount)
song_amount = song_amount + 1
song_list = str(song_list)
song_list = ''.join(song_list)
print(song_list)
get_songs()
Issue:
Output results in: ('[', 18, ']', ' nameless - Milk Crown On Sonnetica')
While the desired output/result should be: [song_number] Song name
Please note that song_number
is really just song_amount
A more visual example of how this should look [18] nameless- Milk Crown On Sonnetica
If anyone has any questions or comments, please comment off this question and I will get back to you as soon as I see it.
Upvotes: 0
Views: 36
Reputation: 21654
You have a problem with string-formatting. You seemingly didn't test the steps your algorithm is composed of in isolation, so you didn't know where to watch for the error.
These are possible solutions for your problem:
song_amount = 18
songs_in_folder = "nameless- Milk Crown On Sonnetica"
'[%d] %s' % (song_amount, songs_in_folder)
# '[18] nameless- Milk Crown On Sonnetica'
'[{}] {}'.format(song_amount, songs_in_folder)
# '[18] nameless- Milk Crown On Sonnetica'
# or for Python 3.6+
f'[{song_amount}] {songs_in_folder}'
# '[18] nameless- Milk Crown On Sonnetica'
The main takeaway should be, that you test every step possible before you compose a lenghty function out of it.
Upvotes: 1