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 7967015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:35:10+00:00 2026-06-04T06:35:10+00:00

i need to replace special chars in the filename. Im trying this at the

  • 0

i need to replace special chars in the filename. Im trying this at the moment with translate, but its not really good working, and i hope you got an idea to do this. Its to make an clear playlist, ive got an bad player of mp3s in my car which cant do umlaute oder specialchars.

My code so far

# -*- coding: utf-8 -*-
import os
import sys
import id3reader
pfad = os.path.dirname(sys.argv[1])+"/"
ordner = ""

table = {
      0xe9: u'e',
      0xe4: u'ae',
      ord(u'ö'): u'oe',
      ord(u'ü'): u'ue',
      ord(u'ß'): u'ss',
      0xe1: u'ss',
      0xfc: u'ue',
    }
def replace(s):
return ''.join(c for c in s if (c.isalpha() or c == " " or c =="-") )
fobj_in = open(sys.argv[1])
fobj_out = open(sys.argv[1]+".new","w")

for line in fobj_in:
if (line.rstrip()[0:1]=="#" or line.rstrip()[0:1] ==" "):
    print line.rstrip()[0:1]
else:
    datei= pfad+line.rstrip()
    #print datei
    id3info = id3reader.Reader(datei)
    dateiname= str(id3info.getValue('performer'))+" - "+ str(id3info.getValue('title'))
    #print dateiname
    arrPfad = line.split('/')

    dateiname = replace(dateiname[0:60])
    print dateiname
#   dateiname = dateiname.translate(table)+".mp3"
    ordner = arrPfad[0]+"/"+dateiname
#   os.rename(datei,pfad+ordner)
    fobj_out.write(ordner+"\r\n")
fobj_in.close()

i get this error: UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xfc’ in position 37: ordinal not in range(128)
If i try to use the translate at the id3title i get TypeError: expected a character buffer object

  • 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-04T06:35:11+00:00Added an answer on June 4, 2026 at 6:35 am

    if I need to get rid of non-ascii-characters, I often use:

    >>> unicodedata.normalize("NFKD", u"spëcïälchärs").encode('ascii', 'ignore')
    'specialchars'
    

    which tries to convert characters to their ascii part of their normalized unicode decomposition.
    Bad thing is, it throws away everything it does not know, and is not smart enough to transliterate umlauts (to ue, ae, etc).

    But it might help you to at least play those mp3s.

    Of course, you are free to do your own str.translate first, and wrap the result in this, to eliminate every non-ascii-character still left. In fact, if your replace is correct, this will solve your problem. I’d suggest you’d take a look on str.translate and str.maketrans, though.

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

Sidebar

Related Questions

wondering how I can replace all special chars on my string like: hello this
I need to replace special characters from a string, like this: this.value = this.value.replace(/\n/g,'');
I have a string. In this string i need replace all special characters (0-31
I need to replace Stopwatch to avoid using getters for its properties. I am
I need to replace wrong symbols except chars and digits in my string with
I need to replace all special control character in a string in Java. I
Plone is showing the special chars from my mother language (Brazilian Portuguese) in its
This is a bit embarrassing scenario but I need solution. I am using some
I'm trying to replace two special characters using the replace function in ColdFusion: <cfset
I need a function that will clean a strings' special characters. I do NOT

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.