使用 python 编辑文本文件中的行

发布于 2025-01-11 04:10:54 字数 469 浏览 0 评论 0原文

我正在尝试创建一个文件列表,包括其完整地址。它们存储在 CERN 的网格文件访问库中,这意味着我使用 gfal-ls 访问它们,据我所知 gfal-find 不存在。

我当前的 python 2.7 代码是:

lscommand = "gfal-ls root://address/moreaddress/MyFiles | head -20 > MyListName.txt"
os.system(lsCommand)

它创建 MyListName.txt 如下:

file1.root
file2.root
...
file20.root

我现在想要做的是打开此列表并添加 root://address/moreaddress/MyFiles / 在每个文件名之前。

我怎样才能在Python中做到这一点?

I am trying to create a list of files including their full addresses. They're stored on the Grid File Access Library from CERN which means I access them using gfal-ls, and as far as I know gfal-find doesn't exist.

My current python 2.7 code is:

lscommand = "gfal-ls root://address/moreaddress/MyFiles | head -20 > MyListName.txt"
os.system(lsCommand)

which creates MyListName.txt as so:

file1.root
file2.root
...
file20.root

What I now want to be able to do is to open this list and add root://address/moreaddress/MyFiles/ before each filename.

How can I do this in python?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

热风软妹 2025-01-18 04:10:54

我当前的解决方案如下所示:

lscommand = "gfal-ls root://address/moreaddress/MyFiles | head -20 > MyListName.txt"

FileList = commands.getstatusoutput(lsCommand)[1]
FileList=FileList.split('\n')

with open(ListFileName,"w") as fulllist: 
    for MyFile in FileList:
        fulllist.write("directoryname/"+MyFile+"\n")
        

My current solution looks like this:

lscommand = "gfal-ls root://address/moreaddress/MyFiles | head -20 > MyListName.txt"

FileList = commands.getstatusoutput(lsCommand)[1]
FileList=FileList.split('\n')

with open(ListFileName,"w") as fulllist: 
    for MyFile in FileList:
        fulllist.write("directoryname/"+MyFile+"\n")
        
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文