python笔记
来源:互联网 发布:python列表推导式 编辑:程序博客网 时间:2024/06/14 10:50
一、OS模块
#1.查看当前工作路径import osos.getcwd()#2.设置当前工作路径为D:\mypythonos.chdir('D:\\mypython\\')#3.获取一个环境变量,如果没有返回noneos.getenv()#4.返回指定目录下的所有文件和目录名os.listdir('D:\\mypython\\')#5.函数用来删除指定路径下的一个文件。os.remove('D:\\mypython\\test.py')
二、类相关问题
1、创建类实例问题
class firstclass: def setdata(self,value): self.data=value def display(self): print(self.data)
导入模块后出现下面这个问题:
>>> import firstclass>>> x=firstclass()Traceback (most recent call last): File "<interactive input>", line 1, in <module>TypeError: 'module' object is not callable
解决方法:
Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
>>> x = firstclass.firstclass()>>> x<firstclass.firstclass object at 0x013D5D90>
三、支持中文注释
#coding:gbk#coding:utf-8#-*- coding : gbk -*-#加入以上三个任意一个在脚本开头都可以使脚本支持中文注释。
待续。。。。
0 0
- Python笔记
- python笔记
- python笔记
- python笔记
- python笔记
- PYTHON笔记
- python笔记
- python笔记
- python笔记
- Python笔记
- Python笔记
- Python笔记
- PYTHON笔记
- Python笔记
- python笔记-------------
- python笔记
- Python笔记
- python 笔记
- 字符串编码转换
- Codeforces Gym 100500A Poetry Challenge (博弈论基础题)
- String转SecureString
- android开发环境 安装ADT 一直pending解决办法
- 蓝桥杯真题——稍大的串
- python笔记
- 三、FPGA之8位全加器设计
- greenplum的扩容(4)-删除数据节点
- 短信发送器的详解
- VC++中Format用法
- Android在代码中打开Wifi、移动网络和GPS
- UIApplication深入研究
- finally语句
- Android组件——使用DrawerLayout仿网易新闻v4.4侧滑菜单