Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

File Name Split on Dashes

Name: Anonymous 2012-01-21 21:32

Hay guys. I'm developing an MP3 player of sorts in Python, and I've devised a way to split a file name by dashes, and return the artist and track separately, but I'm struggling with returning something if no dash is found. In that case, I'd like to return the original file name, and an empty string. As it is now, if no dash is found in a file name, it will just return "None".

Here is my function:

def parseName(song):
    flags = chr(6), chr(45), chr(173), chr(8211)
    for flag in flags:
        for letter in song:
            if flag == letter:
                        return song.split(flag)

Could anyone help? I'd appreciate it.

Name: Anonymous 2012-01-21 21:53

def parseName(song):
    flags = chr(6), chr(45), chr(173), chr(8211)
    for flag in flags:
        for letter in song:
            if flag == letter:
                        return song.split(flag)
    return song, ""

Name: Anonymous 2012-01-21 22:49

>>2

Wow, I tried that very thing earlier, and it didn't seem to work. Maybe I unknowingly typed it wrong?

Anyways, thanks!

Name: Anonymous 2012-01-22 1:55

why don't you just read the ID3 tags?

Name: Anonymous 2012-01-22 20:10

>>4

I honestly wasn't aware such a thing was possible. I'm a fair programmer, but this is the first time I've ever attempted to make a whole entire app, especially one that involves file handling, so my first instinct was to approach it in an elemental, manual way. Knowing of that really helps, though. I've looked it up and it already looks like it'll make everything x1000 easier. Thanks for the advice!

Name: Anonymous 2012-01-22 20:49

>>5
I'm a fair programmer
Protip: You're not

Name: sage 2012-01-22 21:43

And why is >>1 not using regexes?

Don't change these.
Name: Email:
Entire Thread Thread List