Python Forum
Invalid Identifier In Long Text File
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Invalid Identifier In Long Text File
#1
I am currently doing a project that requires storing a lot of data, in the form of a list of dictionaries. Currently, I do this by writing it to a text file, and then using exec on the string we get from reading the file.

Unfortunately, I cannot get anything from one of the files. I can extract it as a string, but when I call exec on it, I get the following error:

SyntaxError: invalid character in identifier

I assume there's just a bad character somewhere in the file, but I'm not sure. Is there some automated tool for finding invalid characters in text files?
Reply
#2
What is the full text of the error? Is it not giving you any indication of where in the text file the error is, or is it just pointing to the exec statement? If it's pointing to the exec statement, try running the data file as a Python program and seeing where the problem is. I mean, if it can be read by exec, it's just Python code, right?

Personally, I think the problem is using exec. I expect coming up with a file format for your data, and some code that can read and write that format, is going to be better in the long run than relying on exec to solve all your problems. It will certainly make it easier to find problems like this.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Decoding lat/long in file name johnmcd 4 270 Mar-22-2024, 11:51 AM
Last Post: johnmcd
Thumbs Up Need to compare the Excel file name with a directory text file. veeran1991 1 1,067 Dec-15-2022, 04:32 PM
Last Post: Larz60+
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,580 Apr-13-2022, 06:02 AM
Last Post: Paqqno
  Converted Pipe Delimited text file to CSV file atomxkai 4 6,843 Feb-11-2022, 12:38 AM
Last Post: atomxkai
  [split] How to convert the CSV text file into a txt file Pinto94 5 3,256 Dec-23-2020, 08:04 AM
Last Post: ndc85430
  Saving text file with a click: valueerror i/o operation on closed file vizier87 5 4,329 Nov-16-2020, 07:56 AM
Last Post: Gribouillis
  Graph identifier samuelbachorik 4 2,600 Oct-04-2020, 01:25 PM
Last Post: scidam
  saving data from text file to CSV file in python having delimiter as space K11 1 2,356 Sep-11-2020, 06:28 AM
Last Post: bowlofred
  Web Form to Python Script to Text File to zip file to web wfsteadman 1 2,099 Aug-09-2020, 02:12 PM
Last Post: snippsat
  Convert Excel file to Text file marvel_plato 6 19,423 Jul-17-2020, 01:45 PM
Last Post: marvel_plato

Forum Jump:

User Panel Messages

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