Python代码:

path = ["pages/detail/index", "pages/index/index", "pages/center/center.vue"]

with open('path.txt', 'w') as f:
    f.write('\n'.join(path))

这将把path数组中的元素写入到名为path.txt的文本文件中,每个元素占一行。

Golang代码:

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    file, err := os.Open("path.txt")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    scanner := bufio.NewScanner(file)
    count := 0
    for scanner.Scan() {
        count++
    }

    fmt.Println("Number of elements in path array:", count)
}

这将打开名为path.txt的文本文件,并使用bufio包创建一个扫描器来逐行读取文件内容。每次扫描器调用Scan()方法时,它将读取文件的下一行文本,并将其存储在扫描器的缓冲区中。通过在循环中调用Scan()方法,我们可以遍历整个文件并计算行数,即path数组的元素数量。最后,我们将打印元素数量

python种有path = pagesdetailindex pagesindexindex pagescentercentervue如何将path保存到txt然后用golang读取此txt计算path数组的元素数量

原文地址: https://www.cveoy.top/t/topic/gqnX 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录