python 入门笔记

来源:互联网 发布:mac网络诊断工具 编辑:程序博客网 时间:2024/06/18 13:55
如何运行一个py文件
命令行进入python项目路径
格式:python test.py     //文件名 test.py


print输出   raw_input 输入


列表
list=['','',''] 
listfuck=['']
print list 打印数组
print list+fuck  组合输出


元字典
定义fuck={'name':'john','age':22,'sex':'man'}
输出keys    print fuck.keys()
输出values  print fuck.values()




条件判断   0-5  or  10-15 很强大
if (num >= 0 and num <= 5) or (num >= 10 and num <= 15):  
print ‘’
else:
print ‘’
需要缩进


循环
for letter in 'Python':     # 第一个实例
   print '当前字母 :', letter


fruits = ['banana', 'apple',  'mango']
for fruit in fruits:        # 第二个实例
   print '当前字母 :', fruit


函数  def 函数名(参数):
函数体


模块化编程
将函数封装在其他py文件中  用import 文件名 来调用,或者用 from 文件名 import 函数名 来调用    


文件读写
fo=open('文件名','wb')
str=''
fo.write(str);//写
fo.read();//读


pyqt界面程序
需要添加主函数


import sys
from PyQt4 import QtCore, QtGui, uic
 
qtCreatorFile = "test.ui"     #改下里面的文件名就可以了
 
Ui_MainWindow, QtBaseClass = uic.loadUiType(qtCreatorFile)
 
class MyApp(QtGui.QMainWindow, Ui_MainWindow):
    def __init__(self):
        QtGui.QMainWindow.__init__(self)
        Ui_MainWindow.__init__(self)
        self.setupUi(self)
 
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    window = MyApp()
    window.show()
    sys.exit(app.exec_())




=====================================================================================
将ui文件转为py文件
pyuic4 test.ui -o test.py
1 0
原创粉丝点击