Python Forum

Full Version: My program won't recognize the filename.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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!
"\" 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