Python tutorial阅读之使用 Python 解释器
- 配置环境变量后,一般可以直接通过Python或指定Python版本号来调用Python。
Python 解释器有些操作类似 Unix shell:当使用终端设备(tty)作为标准输入调用时,它交互的解释并执行命令;当使用文件名参数或以文件作为标准输入调用时,它读取文件并将文件作为 脚本 执行。
Python -m 模块名 [arg] ... #可以直接执行模块,类似于直接读取文件并作为脚本执行
python -c command [arg] ... #直接执行命令
python -c "print('hello world')"
$ hello world - 参数传递
调用解释器时,脚本名和附加参数传入一个名为
sys.argv的字符串列表。你能够获取这个列表通过执行import sys,列表的长度大于等于1;没有给定脚本和参数时,它至少也有一个元素:sys.argv[0]此时为空字符串。脚本名指定为'-'(表示标准输入)时,sys.argv[0]被设定为'-',使用 -c指令 时,sys.argv[0]被设定为'-c'。使用 -m模块 参数时,sys.argv[0]被设定为指定模块的全名。-c指令 或者 -m模块 之后的参数不会被 Python 解释器的选项处理机制所截获,而是留在sys.argv中,供脚本命令操作。
- 指定编码
# -*- coding: UTF-8 -*-
特殊的编码注释必须在文件中的 第一或第二 行定义。
Python tutorial阅读之使用 Python 解释器的更多相关文章
- [译]The Python Tutorial#2. Using the Python Interpreter
[译]The Python Tutorial#Using the Python Interpreter 2.1 Invoking the Interpreter Python解释器通常安装在目标机器的 ...
- Python tutorial阅读之函数的定义与使用
函数的定义 Python 使用关键字def定义函数,格式与C语言类似,但是没有返回类型,参数也不需要设置类型. def add(a, b): """这是函数的文档字符串& ...
- Python tutorial阅读之Python基本运算与基本变量
将 Python 当做计算器 除法运算 用/表示除法运算时,一般得到的是浮点数,如果我们需要得到整数,可以用运算符// 余数计算 % 幂乘方 系统内置变量_ 内置变量_,存储了最近的结果.如图 字符串 ...
- [译]The Python Tutorial#7. Input and Output
[译]The Python Tutorial#Input and Output Python中有多种展示程序输出的方式:数据可以以人类可读的方式打印出来,也可以输出到文件中以后使用.本章节将会详细讨论 ...
- The Python Tutorial 和 documentation和安装库lib步骤
链接: The Python Tutorial : https://docs.python.org/3.6/tutorial/index.html Documentation: https://doc ...
- [Python 3.x 官方文档翻译]The Python Tutorial Python教程
Python is an easy to learn, powerful programming language. It has efficient high-level data structur ...
- [译]The Python Tutorial#1. Whetting Your Appetite
[译]The Python Tutorial#Whetting Your Appetite 1. Whetting Your Appetite 如果你需要使用计算机做很多工作,最终会发现很多任务需要自 ...
- [译]The Python Tutorial#4. More Control Flow Tools
[译]The Python Tutorial#More Control Flow Tools 除了刚才介绍的while语句之外,Python也从其他语言借鉴了其他流程控制语句,并做了相应改变. 4.1 ...
- [译]The Python Tutorial#6. Modules
[译]The Python Tutorial#Modules 6. Modules 如果你从Python解释器中退出然后重新进入,之前定义的名字(函数和变量)都丢失了.因此,如果你想写长一点的程序,使 ...
随机推荐
- Flume环境搭建_五种案例
Flume环境搭建_五种案例 http://flume.apache.org/FlumeUserGuide.html A simple example Here, we give an example ...
- PHP开发api接口安全验证
php的api接口 在实际工作中,使用PHP写api接口是经常做的,PHP写好接口后,前台就可以通过链接获取接口提供的数据,而返回的数据一般分为两种情况,xml和json,在这个过程中,服务器并不知道 ...
- 关于 httpUrlConnection 的 setDoOutput 与 setDoInput的区别
httpUrlConnection.setDoOutput(true) httpUrlConnection.setDoInput(true) 这两个方法在develope的httpUrlConnect ...
- 百度Apollo 尝试
从Git-Hub上下载了Apollo源码在Ubuntu上准备运行一下 完成了以下步骤: bash docker/scripts/install_docker.sh bash docker/script ...
- Hystrix-Dashboard仪表盘
Hystrix Dashboard,它主要用来实时监控Hystrix的各项指标信息.通过Hystrix Dashboard反馈的实时信息,可以帮助我们快速发现系统中存在的问题.下面通过一个例子来学习. ...
- error: stray '\357' in program编程出错的总结
错误: 编译报错:error: stray '\357' in program 原因:在程序中打入了全角字符 具体分析产生原因: 在编程中,由于打字的快速,按下ctrl键后紧接着按下了space键 ...
- Universe Design Tool Using JDBC connect Sybase/Oracle Get Error
一.针对Sybase 1 使用SAP Universe 设计工具连接Sybase数据库报错,报错如下: “CS: Java Class not found in classpath : com.syb ...
- 用Python实现几种排序算法
#coding=utf-8 # 1 快速排序算法 def qksort(list): if len(list)<=1: return list else: pivot = list[0] les ...
- Linux指令--more,less
文章出处:http://www.cnblogs.com/peida/archive/2012/11/05/2754477.html,感谢原作者无私的分享. more命令,功能类似 cat ,cat命令 ...
- Redis清空数据
进入redis目录下 redis-cli -h IP -p 端口 -a 密码 flushall