zoukankan      html  css  js  c++  java
  • python中sys模块的argv

    """笨办法学python,启动时在命令行中python 脚本文件名 filename"""
    from sys import argv

    # argv - 命令行参数; argv[0]是脚本路径名python,sys.argv[0]表示脚本路径名
    script, filename = argv # 脚本和文件名称
    print("We're going to erase %r." % filename) # 正常使用%s,在这里%r是为了重现它代表的对象
    print("If you don't want that, hit RETURN-C (^C).")
    print("If you do want that, hit RETURN.")
    input("?") # 单纯的?号
    print("Opening the file...")
    target = open(filename, "w") # 以"w"写入的形式打开文件,a表示追加,r表示读取。不写默认是读取操作
    print("Truncating the file. Goodbye!")
    target.truncate() # 清除之前的数据
    print("Now I'm going to ask you for three lines.")
    line1 = input("line 1: ") # 获取用户输入
    line2 = input("line 2: ")
    line3 = input("line 3: ")
    print("I'm going to write these to the file.")
    target.write(line1) # 写入用户输入
    target.write(" ")
    target.write(line2)
    target.write(" ")
    target.write(line3)
    target.write(" ")
    print("And finally, we close it.")
    target.close() # 关闭已打开的文件
  • 相关阅读:
    TS的一些小东西
    关于Vue懒加载问题
    react子传父
    MYSQL存储过程以及结果集
    MYSQL视图 事务 游标 索引及其使用
    MYSQL数据库的修复方法MAC
    MYSQL用户授权以及SQL语句
    MySQL数据库基础知识
    JavaScript对象
    JavaScript控制语句
  • 原文地址:https://www.cnblogs.com/Guishuzhe/p/10206384.html
Copyright © 2011-2022 走看看