Python Forum
My program won't recognize the filename.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My program won't recognize the filename.
#1
I'm working on a Markov bot for Twitter that reads off of a static directory and I know barely anything about coding. The program I got from a library and tweaked it to fit my needs.

For some reason, the Markov bot code I tweaked, Program A, reads the filename just fine. I don't get errors when I import that one into Python. Program B has code in it to import Program A into it and has a few basic commands. When I import that one into Python, it throws up an error message that the file name doesn't exist.

Error message in full:

Error:
>>>import pookebot Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\slean\pookebot.py", line 15, in <module> tweetbot.read(book) File "C:\Users\slean\PokeBot.py", line 360, in read self._error(u'read', u"File does not exist: '%s'" % (filename)) File "C:\Users\slean\PokeBot.py", line 1371, in _error raise Exception(u"ERROR in Markovbot.%s: %s" % (methodname, msg)) Exception: ERROR in Markovbot.read: File does not exist: 'C:\Users\slean\PokeBot\pokemoncanon.txt'
I am making sure in the code to make all the \ in the filenames \\ but it shows up as \ in the error message.

I am terrible at coding and I think I jumped into the deep end with this. Please help!
Larz60+ write Jan-07-2022, 11:43 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use bbcode tags on future posts.
Reply
#2
"\" is used in Python strings to indicate the following is a control character. The first backslash in "\\" tells Python that the second backslash is just a backslash and not the start of a control character. When Python prints a string with control characters it converts them to their unicode equivalent. "\n" becomes a new line/line feed, "\t" becomes a tab and "\\" becomes "\".

That explains why "\\" appears as "\" in the error message. It does not explain why your program cannot see 'C:\Users\slean\PokeBot\pokemoncanon.txt'. Does that file exist?

it would be helpful to see your programs A and B. At least the program B that appears to be causing problems. I have concerns about PokeBot.py and a folder supposedly named PokeBot that contains pokemoncanon.txt
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  python cant recognize PIP siubikYT 2 745 Jul-19-2023, 06:30 PM
Last Post: Lahearle
  Is it possible to make a program recognize how many clicks it has had on the monitor? jao 0 1,152 Feb-25-2022, 06:31 PM
Last Post: jao
Star NameError – function doesn't recognize imported modules Sir 4 3,483 Dec-01-2020, 06:36 AM
Last Post: Sir
  Player object wont recognize collision with other objects. Jan_97 3 2,710 Dec-22-2019, 04:08 PM
Last Post: joe_momma
  How to recognize space or enter as one-character input? Mark17 5 5,604 Oct-17-2019, 08:19 PM
Last Post: jefsummers
  Pynput doesn't recognize shift button and special characters VirtualDreamer 0 3,017 Jul-17-2019, 11:55 AM
Last Post: VirtualDreamer
  How to recognize, what functions are filled in of the Python interpreter stack? AlekseyPython 3 2,680 Mar-13-2019, 12:14 PM
Last Post: AlekseyPython
  Variable defined but python wont recognize it. FWendeburg 3 3,306 Feb-19-2019, 10:43 PM
Last Post: woooee
  How I can recognize that member is classmethod of staticmethod? AlekseyPython 0 1,829 Feb-17-2019, 07:01 AM
Last Post: AlekseyPython
  pyspark sql unable to recognize SQL query command cpatte7372 6 16,582 Jul-31-2018, 04:17 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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