2

I'm making a tk application in which I have to execute a command line application (MP4Box) from python, using subprocess.check_call(). The filename (used in the command) is retrieved from youtube and hence has all types of special characters. I want to remove all characters that can't be used as filenames in the Operating system also btw (i want the implementation would work across multiple platforms)

I tried the solution over here . windows seems accept the filename but but it returns an error with subproces.check_call(). I tried manually removing the special char from filename and it works good after that. so it isnt a problem with the command.

EDIT:
For eg, i tested for this video. The solution in above link won't remove 'ä' and cause a problem in the command line.

Community
  • 1
  • 1
Dev Aggarwal
  • 7,627
  • 3
  • 38
  • 50
  • Hi! Welcome to StackOverflow. In ordem to allow SO members to better understand your question and to let them help you, it is recommended that you include a Minimal, Complete, and Verifiable example (https://stackoverflow.com/help/mcve). – Victor Domingos May 04 '17 at 11:33
  • @VictorDomingos done :) – Dev Aggarwal May 05 '17 at 04:38

1 Answers1

0

I eventually found the correct answer. Ascii did the trick :)

''.join([t for t in <filenmae> if t.isalnum()]).encode('ascii', 'ignore'))
Dev Aggarwal
  • 7,627
  • 3
  • 38
  • 50