FileNameG = FileName.section(".", 0, 0);什么意思
时间: 2024-05-18 14:12:08 浏览: 11
这段代码的作用是从文件名(FileName)中提取文件名(FileNameG),并将其赋值给变量FileNameG。函数`section()`是QString类的一个成员函数,用于从字符串中提取指定位置的子字符串。在该代码中,点号 "." 是分隔符,0是起始位置,0是结束位置,意味着只提取第一个点号前的字符串,即文件名。
相关问题
添加注释:filename1 = 'alice.txt' filename2 = "box.txt" filename3 = "cap.txt" filename4 = "did.txt" try: with open(filename1) as fp1, open(filename2) as fp2, open(filename3) as fp3, open(filename4) as fp4: contents = fp1.read() + fp2.read() + fp3.read() + fp4.read() except FileNotFoundError(): print("Sorry, the file does exist.") else: words = contents.split() wordNum = len(words) print(words) print("The file has about " + str(wordNum) + " words.")
# 这段代码通过打开4个文件并将它们的内容拼接在一起,然后对拼接后的字符串进行单词计数并输出单词列表和单词数目。
# 如果任意一个文件不存在,则会捕获FileNotFoundError异常并打印错误信息。
filename1 = 'alice.txt'
filename2 = "box.txt"
filename3 = "cap.txt"
filename4 = "did.txt"
try:
with open(filename1) as fp1, open(filename2) as fp2, open(filename3) as fp3, open(filename4) as fp4:
contents = fp1.read() + fp2.read() + fp3.read() + fp4.read()
except FileNotFoundError:
print("Sorry, the file does not exist.")
else:
words = contents.split()
wordNum = len(words)
print(words)
print("The file has about " + str(wordNum) + " words.")
已知filename='testcprogram.c',现要将其改名为’testcprogram. exe’, 则语句为filename =...
filename = 'testcprogram.c'
new_filename = filename.replace('.c', '.exe')
print(new_filename)
输出结果为:testcprogram.exe
所以语句为:filename = filename.replace('.c', '.exe')
相关推荐
![ini-development](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)
![gz](https://img-home.csdnimg.cn/images/20210720083447.png)