标签:amd strftime read mysql安装 ima hone ftime 引入 pen
py -2
py -3
py -2 -m pip install xxxx
py -3 -m pip install xxxx
pip3 install nose 这个也可以
py -2 a.py
py -3 a.py
把python.exe 修改为python3.exe
在环境变量里面加入这个Python3.6的路径
D:\test\pytyon3>py -3
Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> print ("hello")
hello
>>> print ("hello",end="")
hello>>>
>>> range(1,10)
range(1, 10)
>>> list(range(1,10))
[1, 2, 3, 4, 5, 6, 7, 8, 9]
>>>
>>> for i in range(1,10,2):
... print (i)
...
1
3
5
7
9
>>> a=iter(range(10))
>>> next(a)
0
>>> next(a)
1
>>> next(a)
2
>>> s="s"
>>> type(s)
<class ‘str‘>
>>>
>>> s="s"
>>> type(s)
<class ‘str‘>
>>> type(s.encode(‘utf-8‘))
<class ‘bytes‘>
>>> s="我们"
>>> print (s)
我们
>>> print (s.encode("gbk"))
b‘\xce\xd2\xc3\xc7‘
>>> print (s.encode("gbk").decode("gbk"))
我们
Python3默认是unicode类型
>>> fp=open("d:\\a.txt","r",encoding="utf-8")
>>> fp.read()
‘\ufeff光荣之路学习,\n夏晓旭\n嘻嘻嘻嘻 ‘
>>> with open("d:\\a.txt","r",encoding="utf-8") as fp:
... print (fp.read())
...
光荣之路学习,
夏晓旭
嘻嘻嘻嘻
>>>
pip3 install PyMySQL
import pymysql
# 打开数据库连接
db = pymysql.connect("localhost","testuser","test123","TESTDB" )
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 使用 execute() 方法执行 SQL 查询
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()
print ("Database version : %s " % data)
# 关闭数据库连接
db.close()
pickle可以把变量的放在文本里,下次打开时可以从文本里取
import pickle
21:40 听反序列化
data2 = [1,2,3,4]
det_str = pickle.dumps(data2)
print(det_str)
https://www.cnblogs.com/zhangxinqi/p/8034380.html
thread 模块已被废弃。用户可以使用 threading 模块代替。所以,在 Python3 中不能再使用"thread" 模块。为了兼容性,Python3 将 thread 重命名为 "_thread"。
>>> import queue
>>> import Queue
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named ‘Queue‘
>>> queue.Queue(10)
<queue.Queue object at 0x000001C4882AE860>
>>> q=queue.Queue(10)
>>> q.put(0)
>>> q.get()
0
>>> import time
>>> import locale
>>> locale.setlocale(locale.LC_CTYPE, ‘chinese‘)
‘Chinese_China.936‘
>>> print(time.strftime(‘%Y年%m月%d日‘))
2018年08月16日
写文件后返回一个写入的字节数
>>> with open("e:\\x.txt","w",encoding="utf-8") as fp:
... fp.write("我们\n你们\n")
...
6
>>>
>>> with open("d:\\a.txt","w",encoding="utf-8") as fp:
... fp.write("我们")
...
2
标签:amd strftime read mysql安装 ima hone ftime 引入 pen
原文地址:https://www.cnblogs.com/xiaxiaoxu/p/9529025.html