为什么os.path.join无法处理字符串格式

时间:2019-04-16 14:15:01

标签: python

我想使用os.path.join收集我的文件路径。 但是有一些麻烦。 请帮助我。

#open file
with open(filename, 'r') as f:
    lines = f.readlines()

#find index of line to remove
for index, line in enumerate(lines):
    if 'delete me' in line:
        #remove line
        lines.pop(index)
        break

#write new file
with open(filename, 'w') as f:
    f.write(''.join(lines))

为什么结果不是hw2 / {:s} .txt? 我已经问过其他人,它可以为他们工作。 我的python版本是3.6.8。

1 个答案:

答案 0 :(得分:3)

在Windows上, //ommitted some redundant code baseUrl: string = "api/Category"; createCategory(newCategory: Category) : Observable<any> { //Not too sure if newCategory is added correctly here return this.httpClient.get<any>(this.baseUrl+"username="+this.sessionService.getUsername()+"&password="+this.sessionService.getPassword() + newCategory).pipe ( catchError(this.handleError) ); } 对于它认为的驱动器号似乎不太挑剔。初始的<td><input id="name" name="name" #name="ngModel" type="text" [(ngModel)]="newCategory.name" required="true" /></td> 导致第二个参数被视为驱动器{上的绝对路径,导致第一个参数被忽略。

作为一种解决方法,请提供一个明确的字段编号以将冒号与字符串的第一个字符分开:

os.path.join

(我认为,值得在bugs.python.org上提交错误报告。)