I understand that this question may exist, however I am just trying to figure out my formatting. I am not the best when it comes to formatting things like this and am just doing a bit of guess work that just leads to issues.
I have a custom file type that it must save to, a .gcom and a file name that is declared with the function. Currently the function looks like this:
def cComFile(): # This will NOT write command code (Yet) I want to see if file creation works!
filetype='.gcom'
commands_Directory = 'C:\\Genisis_AI\\Commands\\' # Unused at the moment
file_name = command
if os.path.isfile(("C:\\Genisis_AI\\Commands\\{}").format(file_name).join("{}").format(filetype)):
a = raw_input(('{} already exists! Would you like to overwrite this? [Y/N]: ').format(cComFile.file_name))
string.lower(a)
if a == 'y':
print(("Command: {} , has been rewritten!").format(file_name))
elif a == 'n':
pass
else:
f = open((cComFile.commands_Directory.join(cComFile.file_name.join(cComFile.filetype)),'w+'))
f.write('command was made')
print(('Command made" {}').format(cComFile.command))
I am getting an issue with line 135 which is the following line:
if os.path.isfile(("C:\\Genisis_AI\\Commands\\{}").format(file_name).join("{}").format(filetype)):
The error I am receiving is the following:
Traceback (most recent call last):
File "testing/aaa.py", line 149, in <module>
cComFile('test')
File "testing/aaa.py", line 135, in cComFile
if os.path.isfile(("C:\\Genisis_AI\\Commands\\{}").format(file_name).join("{}").format(filetype)):
KeyError: 'C'
I understand that I am most likely doing this all the wrong way but its a learning experience I suppose. And the chances are that me getting that wrong means that the formatting for the rest of this function are also incorrect as well. Thank you for reading and any help would be nice.
(I understand this is messy and I don't mind it at the moment, I tend to clean up after things work)
.join("{}")supposed to accomplish? Are you just trying to append"{}"to the end of the string? Because that's not how you do it.("C:\\Genisis_AI\\Commands\\{}").format(file_name).join("{}")and compare that to your expectation. It should become apparent what's happening.