Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9184697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:07:00+00:00 2026-06-17T19:07:00+00:00

I’ve coded a program which helps me to quickly toggle between lyrics of songs.

  • 0

I’ve coded a program which helps me to quickly toggle between lyrics of songs. It reads the lyrics from .lyr file and prints them out to me.

Here’s a simplified version, without any additional features like edit_line(). The problem still appears with this code.

import os

class Lyrics:

    def __init__(self, file):
        '''Initialize new Lyrics object'''
        self.file = file.replace("/", "\\")
        self.path = self.file.rsplit("\\", 1)[0] + "\\"
        self.suffix = "." + self.file.rsplit(".")[-2]
        self.name = self.file\
                    .replace(self.path, "")\
                    .replace(".lyr", "")\
                    .replace(self.suffix, "")

    def draw(self):
        '''Draw lyrics on user's screen'''
        maxlen = len(str(len(self.content)))
        print("[[ %s ]]"%self.name)
        for i,line in enumerate(self.content):
            print("%i  %s"%(i+1, line), end="")

    def play(self):
        '''View lyrics'''
        with open(self.file, "r") as f:
            self.content = f.readlines()
        #os.system("cls")
        self.draw()
        input("[[ Press enter to quit ... ]]")

def main(directory):
    # Get lyric files from directory
    lyric_files = []
    for file in os.listdir(directory):
        if file.endswith(".lyr"):
            lyric_files.append(Lyrics(directory + file))

    # Create variable for showing messages to user
    msg = ""

    # Main loop
    while True:

        # Print lyric files
        #os.system("cls")
        for i, file in enumerate(lyric_files):
            print("%i :: %s"%(i+1, file.name))

        # Handle input
        cmd = input("%s>"%msg)
        if cmd == "bye":
            break
        try:
            lyric_files[int(cmd)-1].play()
            msg = ""
        except ValueError:
            msg = "ValueError: Input must be an integer\n"
        except IndexError:
            msg = "IndexError: Integer must be between 1 and %i\n"%len(lyric_files)


if __name__ == "__main__":
    main("E:\\documents\\lyrics\\")

Files in E:\documents\lyrics\ are named with following format:

Artist - Song.format.lyr`

For example:

E:\documents\lyrics\Adele - Set Fire to the Rain.mp3.lyr

When I open the program, it lists all the files as it’s supposed to, asking me for an input after:

1 :: Adele - Set Fire to the Rain
2 :: Eminem - Not Afraid
3 :: Nicki Minaj - Starships
>

When I open up lyrics for Set Fire to the Rain with index 1, they open up just perfectly. However, when I try to open lyrics for Not Afraid, I can see around 50 lines of the lyrics on the output, when the lyric file is actually around 120 lines long. It then asks me for an input from the main() function with ValueError like so:

1  first_line_in_lyrics
2  second_line_in_lyrics
i  ...
42 fourty_second_line_in_lyrics
43 fourty_third_line_in_lyrics
1 :: Adele - Set Fire to the Rain
2 :: Eminem - Not Afraid
3 :: Nicki Minaj - Starships
ValueError: Input must be an integer
>

The files are pretty much identical to each other (well of course the lyrics are different). The program works just fine on IDLE, but not on python command line.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T19:07:01+00:00Added an answer on June 17, 2026 at 7:07 pm

    This problem seems pretty weird, but not impossible. Here’s what we got at the moment:

    1. Since the file does open and some of it gets printed out, the problem MUST be in the printing of the file.
    2. I triple checked your code, and the problem is NOT in your draw() method.
    3. Since the problem only occurs with some files and not with others, the problem is probably in the files themselves.
    4. Since the problem only occurs with python command line and not with IDLE: the problem has to be in printing some content of some of the files, which can be printed in IDLE but not in python command line.

    If you are CERTAIN that your draw function looks EXACTLY like this (took me a while to figure out the maxlen thing):

    def draw(self):
        '''Draw lyrics on user's screen'''
        maxlen = len(str(len(self.content)))
        print("[[ %s ]]"%self.name)
        for i,line in enumerate(self.content):
            print("%i  %s"%(i+1, line), end="")
    

    We’re only left with the fact that there’s something wrong with self.content and/or the file content itself.

    Simply put: I’m 99% sure there are some characters in your file which can be printed by IDLE but not by python command line. Such characters could be anything: %, ', ", ´, |, #, or even some invisible characters which you can’t see without scrolling through them with your arrow keys.

    If you could post the content of your lyrics, I could try helping more. Especially the lines which get printed last, and the first lines which don’t get printed at all.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I have a text area in my form which accepts all possible characters from
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want use html5's new tag to play a wav file (currently only supported
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I have an autohotkey script which looks up a word in a bilingual dictionary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.