参数在python中不正确

2024-06-17 12:45:20 发布

您现在位置:Python中文网/ 问答频道 /正文

import os
import linecache
gg = "C:\Users\gnk.n\Desktop\stg"
os.system('dir /s' +gg+ '>> gadt11110.txt')
with open("C:\Users\gnk\Desktop\scripts\gadt11110.txt") as f:
    nofolines = len(f.readlines())
    Fileline = nofolines -1
    liness = linecache.getline("C:\Users\gnk\Desktop\scripts\gadt11110.txt", Fileline)
    print liness

在上面的代码中什么是错误的,当我运行get参数时是错误的。请帮忙 错误:参数格式不正确-“sC:\Users\gnk\Desktop\stg”。你知道吗


Tags: importtxtos错误scriptsusersdesktoplinecache
1条回答
网友
1楼 · 发布于 2024-06-17 12:45:20

os.system('dir /s' +gg+ '>> gadt11110.txt')更改为os.system('dir /s ' +gg+ '>> gadt11110.txt')。你知道吗

请注意dir /s后面添加的空格。你知道吗

您还可能遇到无法转义\字符的问题。你知道吗

相关问题 更多 >