網(wǎng)站首頁 編程語言 正文
pycharm三個(gè)有引號(hào)不能自動(dòng)生成函數(shù)注釋
函數(shù)注釋
自動(dòng)生成函數(shù)注釋,包括參數(shù)和返回值。
使用方法,函數(shù)定義時(shí),直接輸入三個(gè)雙引號(hào)后回車,例如:
? ? def add_script_flow(self, script_name, ip): ? ? ? ? """ ? ? ? ? 點(diǎn)擊一個(gè)腳本命令圖標(biāo),彈出參數(shù)配置框,選擇腳本,輸入執(zhí)行ip和 ? ? ? ? :param script_name: 腳本名稱 ? ? ? ? :param ip: 執(zhí)行ip ? ? ? ? :return: ? ? ? ? """
突然發(fā)現(xiàn),不能自動(dòng)生成注釋參數(shù)了
去File | Settings | Tools | Python Integrated Tools | Docstring format 這里改成你想要的格式,然后再回去看看你的三個(gè)引號(hào)。沒有函數(shù)注釋的情況下是plain。改成reStucturedText。
Python的三引號(hào)的用法
python中三引號(hào)可以將復(fù)雜的字符串進(jìn)行復(fù)制
- python三引號(hào)允許一個(gè)字符串跨多行,字符串中可以包含換行符、制表符以及其他特殊字符。
- 三引號(hào)的語法是一對(duì)連續(xù)的單引號(hào)或者雙引號(hào)(通常都是成對(duì)的用)。
跨多行、換行符、制表符
chat = """how are you? i'm fine, than you,and you? me too!""" print(chat)
加注釋
data = """name # 姓名 age # 年齡 sex # 性別 """ print(data)
多行注釋
Python中的注釋是用# ,但是#通常是單行注釋,在注釋有多行時(shí),每一行多要寫一個(gè)# ,而用""""""卻可以一次性解決
""" 這是一個(gè) 多行注釋 注釋 """ data = """name # 姓名 age # 年齡 sex # 性別 """ print(data)
sql語句:對(duì)于sql語句我們通常不建議用字符串拼接,而使用參數(shù),在表達(dá)式中沒有變量時(shí),我們可以使用三引號(hào)來讓sql語句更清晰
import pymysql try: # 建立連接 db = pymysql.connect(host='localhost', user='root', passwd='root', db='scraping') # 創(chuàng)建游標(biāo)對(duì)象 cur = db.cursor() # 新建表,三引號(hào) sql = """CREATE TABLE EMPLOYEE ( FIRST_NAME CHAR(20) NOT NULL, LAST_NAME CHAR(20), AGE INT, SEX CHAR(1), INCOME FLOAT )""" cur.execute(sql) finally: # 關(guān)閉數(shù)據(jù)庫連接 cur.close()
還有插入數(shù)據(jù)
import pymysql try: # 建立連接 db = pymysql.connect(host='localhost', user='root', passwd='root', db='scraping') # 創(chuàng)建游標(biāo)對(duì)象 cur = db.cursor() # SQL 插入語句 sql = """INSERT INTO EMPLOYEE(FIRST_NAME, LAST_NAME, AGE, SEX, INCOME) VALUES ('Mac', 'Mohan', 20, 'M', 2000)""" try: # 執(zhí)行sql語句 cur.execute(sql) # 提交到數(shù)據(jù)庫執(zhí)行 db.commit() except: # 如果發(fā)生錯(cuò)誤則回滾 db.rollback() finally: # 關(guān)閉數(shù)據(jù)庫連接 cur.close()
如果使用單引號(hào)
import pymysql try: # 建立連接 db = pymysql.connect(host='localhost', user='root', passwd='root', db='scraping') # 創(chuàng)建游標(biāo)對(duì)象 cur = db.cursor() # SQL 插入語句 sql = "INSERT INTO EMPLOYEE(FIRST_NAME, \ LAST_NAME, AGE, SEX, INCOME) \ VALUES ('%s', '%s', '%d', '%c', '%d' )" % \ ('Mac', 'Mohan', 20, 'M', 2000) try: # 執(zhí)行sql語句 cur.execute(sql) # 提交到數(shù)據(jù)庫執(zhí)行 db.commit() except: # 如果發(fā)生錯(cuò)誤則回滾 db.rollback() finally: # 關(guān)閉數(shù)據(jù)庫連接 cur.close()
原文鏈接:https://www.cnblogs.com/l7planet/p/13807646.html
相關(guān)推薦
- 2022-05-11 使用postman訪問k8s api
- 2022-01-16 1.把字符串轉(zhuǎn)化為時(shí)間戳,再將時(shí)間戳轉(zhuǎn)化為Date對(duì)象 /** *@parame time = 2
- 2022-06-02 python獲取字符串中的email_python
- 2022-10-10 React?Hooks鉤子中API的使用示例分析_React
- 2022-10-05 Python線程池的實(shí)現(xiàn)淺析_python
- 2022-03-16 c#語言程序構(gòu)建基塊_C#教程
- 2022-07-13 Android Canvas - save() & restore()
- 2022-08-23 使用Python腳本提取基因組指定位置序列_python
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支