I am using python 3.3
in Windows 7.
The python file, main.py
is in D:\\my proj\\$MY\\1
I wrote the following code in that file:
import os
file_usage = "usage.txt"
p1 = os.getcwd()
print ("os.getcwd(): ", p1)
p5 = os.path.join(p1,"report")
print ("os.path.join: ", p5)
file = open(file_usage, "a")
file.write ("*****BLAH-BLAH*****")
file.close()
So, When I run my program in cmd, it gives me output like:
os.getcwd(): D:\my proj\$MY\1
os.path.join: D:\my proj\$MY\1\report
Now, usage.txt
file is generating in the directory where my main.py
is located means inside the 1
folder.
But I have tried to modify the path that it should be saved in report
folder as you can see the value of os.path.join
.
So, I want to save the generated usage.txt
in the report
folder instead of 1
. What type of changes should I do? or what other modules do I need to use?
I'm a novice user. So, please try to tell me in-depth or send me links from where I can get more knowledge or examples related to this. I'm awaiting for your reply.
open(os.path.join(p5, "usage.txt"), "w")
由于p5
是报告目录的路径,因此将在该目录中打开usage.txt
文件。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.