035 Road King absolute and relative paths

Absolute path

  • Absolute path from the Windows system drive letter (C:, D :) began to write a full path.

    path = r'D:\上海Python11期视频\python11期视频\day 09\test.py'  # 鼠标右键点击文件,
    copy pathf = open(path, 'w')  # r-->read 只读 ; w-->只写,清空当前文件后写入,自动创建文件
    f.write('nick handsome')
    f.close()

relative path

  • Relative to the currently executing file folder sitting began looking for

    path = r'test.py'  # 鼠标右键点击文件,copy path
    
    f = open(path, 'r')  # r-->read 只读 ; w-->只写,清空当前文件后写入,自动创建文件
    
    print(f.read())

Guess you like

Origin www.cnblogs.com/xichenHome/p/11311471.html