Hello,
I am posting this here to see if anyone knows about this problem, but as it is Python related, I will try Stack Overflow if I can't get help here. I am running this on Linux Mint, and part of my problem is getting the program to recognise the Linux file structure.
I am trying to tell my program to open a new file in write mode in a specific directory, but the program does not appear to recognise any instructions. I am consulting Learn Python the Hard Way, which has a section in Exercise 16 on writing files, however he simply supplies file names on the command line when running the program. I would like my program to create files on its own, setting the title to include the date of creation.
If I simply ask it to open a new file it states that the name 'new_file' is not defined.
Code:
a = open(new_file.py, 'w')
a.write("Hello World.")
a.close()
If I include an absolute path from the root directory, the terminal simply points at the '/' in front of 'home' and states 'invalid syntax'. The same goes for a relative path, using './'.
I have tried importing os as well. The code suggested on Stack Overflow for another problem was:
Code:
import os
directory = os.path.dirname(__file__)
filename = os.path.join(directory, new_file.py)
This also states that the name 'new_file' is not defined.
I saw a suggestion elsewhere about importing the glob module, but this did not look relevant to my issue.
What I am specifically trying to do is write the contents of a dictionary from my module to a separate file, however if I can simply figure out how to write any string from the module to a file, I will be happy with that for a start.
Any insight will be greatly appreciated.
Thanks.