Python Forum
Invalid Syntax problem (?!?)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid Syntax problem (?!?)
#5
Hello!
In Python 3 str.translate() works a bit different.
Python 3.5.2 (default, Sep 10 2016, 08:21:44) 
Type "copyright", "credits" or "license" for more information.

IPython 5.1.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: file_name = '0012ow32jioo123.hh1'

In [2]: table = {}

In [3]: for key in range(10):
   ...:     table[ord(str(key))] = None
   ...:     

In [4]: table
Out[4]: 
{48: None,
 49: None,
 50: None,
 51: None,
 52: None,
 53: None,
 54: None,
 55: None,
 56: None,
 57: None}

In [5]: new_file = file_name.translate(table)

In [6]: new_file
Out[6]: 'owjioo.hh'
I suppose you want to do this on the base name of the file not to an extension too. As you see is 'hh' now. This will ruin your mp3 collection  Smile
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply


Messages In This Thread
Invalid Syntax problem (?!?) - by harley_quinn - Nov-08-2016, 06:45 PM
RE: Invalid Syntax problem (?!?) - by nilamo - Nov-08-2016, 06:49 PM
RE: Invalid Syntax problem (?!?) - by micseydel - Nov-08-2016, 06:59 PM
RE: Invalid Syntax problem (?!?) - by snippsat - Nov-08-2016, 07:00 PM
RE: Invalid Syntax problem (?!?) - by wavic - Nov-08-2016, 07:54 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Invalid syntax Slome 2 1,953 May-13-2022, 08:31 PM
Last Post: Slome
  print(f"{person}:") SyntaxError: invalid syntax when running it AryaIC 11 16,302 Nov-07-2020, 10:17 AM
Last Post: snippsat
  Invalid syntax error, where? tucktuck9 2 3,417 May-03-2020, 09:40 AM
Last Post: pyzyx3qwerty
  Invalid syntax defining a dictionary? ep595 6 5,078 Nov-19-2019, 08:06 PM
Last Post: ThomasL
  Syntax Error: Invalid Syntax in a while loop sydney 1 4,068 Oct-19-2019, 01:40 AM
Last Post: jefsummers
  [split] Please help with SyntaxError: invalid syntax Mason 1 2,187 Apr-28-2019, 06:58 PM
Last Post: Yoriz
  SyntaxError: Invalid syntax in a while loop ludegrae 3 14,702 Dec-18-2018, 04:12 PM
Last Post: Larz60+
  SyntaxError: invalid syntax at run .py tuxo9999 10 7,240 Aug-23-2018, 03:58 PM
Last Post: Axel_Erfurt
  Homework: Invalid syntax using if statements chehortop 3 3,641 Mar-01-2018, 04:38 AM
Last Post: micseydel
  invalid syntax error penlemon 4 3,817 Jan-27-2018, 02:46 PM
Last Post: sparkz_alot

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020