作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
from pathlib import Path
import os
folderpath = input("What is the absolute path to Superman's folder?")
mypath = Path(folderpath)
mypath = os.listdir(folderpath)
for files in mypath:
print ("Found one of Superman's's files..." + files)
#up to here, the code is good
for read in byfiles:
byfiles = ('mypath\\files')
byfiles.read_text()
if "Superman" in read:
print("Found Superman in file " + read)
我需要搜索输入路径中的文件并找到单词 Superman,然后打印找到该单词的位置。我无法让连接与 .read_text() 一起工作。
这是输出:
What is the absolute path to Superman's folder?C:\Users\OneDrive\Documents\Superman_files
Found one of Superman's files...boring_document.txt
Found one of Superman's files...eggs.txt
Found one of Superman's files...hello.txt
Found one of Superman's files...secret_document.txt
Found one of Superman's files...spam.txt
任何帮助将不胜感激。
最佳答案
os.listdir
返回一个字符串列表,以便您可以检查:
for read in mypath:
if "Superman" in read:
print("Found Superman in file " + read)
如果您想检查文件的内容,可以使用:
from pathlib import Path
folderpath = input("What is the absolute path to Superman's folder?")
mypath = Path(folderpath)
for child in mypath.iterdir():
if child.is_file():
with open(child, 'r') as file:
if "Superman" in file.read():
print("Found Superman in file ", child.relative_to(mypath))
关于python - 如何用正斜杠连接文件夹和文件名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60364354/
我有一个右下角倾斜的元素,我必须在其上放置一个盒子阴影。有时倾斜的 Angular 被徽章覆盖 - 我的问题不适用,如果是这样的话: 这是信息框及其边 Angular 的 (s)css 部分(还有更多
是否可以在纯 html/css 中创建类似下面的内容? 我想做这个响应式和全 (100%) 宽度(最大左 Angular 100 像素,右边最小 50 像素,类似的东西)。 最佳答案 您可以通过转换(
如何在 fabricjs 文本中为文本提供渐变或斜 Angular 效果?? http://fabricjs.com/fabric-intro-part-2/ 这里给出了形状和所有示例,我将其与文本绑
我用过: http://apps.eky.hk/css-triangle-generator/ 为彼此对 Angular 放置的两个不等边三 Angular 形生成 css: 左下三 Angular
我是一名优秀的程序员,十分优秀!