自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

ChatGPT 的五大功能可以幫助你提高代碼質(zhì)量

人工智能
ChatGPT 目前徹底改變了開發(fā)代碼的方式,然而,大多數(shù)軟件開發(fā)人員和數(shù)據(jù)專家仍然沒有使用 ChatGPT 來改進和簡化他們的工作。

ChatGPT 目前徹底改變了開發(fā)代碼的方式,然而,大多數(shù)軟件開發(fā)人員和數(shù)據(jù)專家仍然沒有使用 ChatGPT 來改進和簡化他們的工作。

這就是為什么我在這里概述 5 個不同的功能,以提高我們的日常工作速度和質(zhì)量。

我們可以在日常工作中使用它們?,F(xiàn)在,我們一起來了解一下吧。

注意:切勿在 ChatGPT 中使用關鍵代碼或信息。

01.生成項目代碼的框架

從頭開始構建新項目時,ChatGPT 是我的秘密武器。只需幾個提示,它就可以生成我需要的代碼框架,包括我選擇的技術、框架和版本。它不僅為我節(jié)省了至少一個小時左右的工作時間,而且還有助于使我的文檔(或團隊的文檔)井井有條并保持最新,這就好像在給團隊加外掛,感覺無形之中多了一雙手!

例如,假設我想使用一些外部 API,我可以要求 ChatGPT 為我起草一個初始代碼結構。

使用 Python 生成集成外部 API 的樣板代碼。

ChatGPT 立即回答:

圖片

甚至,我可以請求一個框架來使用 Selenium 抓取 LinkedIn,ChatGPT 會給我以下輸出。


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time

# Initialize the web driver
driver = webdriver.Firefox()

# Navigate to LinkedIn
driver.get("https://www.linkedin.com/")

# Find the email and password input fields
email = driver.find_element_by_id("username")
password = driver.find_element_by_id("password")

# Enter your credentials
email.send_keys("YOUR_EMAIL")
password.send_keys("YOUR_PASSWORD")

# Click the login button
driver.find_element_by_xpath("http://button[@type='submit']").click()

# Wait for the page to load
time.sleep(5)

# Navigate to the profile of the desired user
driver.get("https://www.linkedin.com/in/USER_PROFILE_NAME")

# Extract the information you want from the page
name = driver.find_element_by_xpath("http://span[@class='inline t-24 t-black t-normal break-words']").text
location = driver.find_element_by_xpath("http://span[@class='t-16 t-black t-normal inline-block']").text

print(name)
print(location)

# close the browser
driver.quit()

很容易,對吧?嘗試用您能想象到的任何項目來挑戰(zhàn) ChatGPT。

02.研究和比較

就如何實施某些事情做出決定可能很困難,尤其是當有多種選擇可供選擇時。我的首選方法是為每種方法創(chuàng)建一個基本的概念證明,然后將它們進行比較。但是,在 ChatGPT 的幫助下,這個過程變得簡單多了。

我現(xiàn)在可以直接詢問它的專家意見,了解哪個選項或庫最適合我的代碼開發(fā)。這節(jié)省了我在決策過程中的時間和精力,并確保我使用最好的工具來完成工作。

假設我想處理地理空間數(shù)據(jù),但不確定是否應該使用 Geopandas 或 Plotly。我可以讓 ChatGPT 為我進行比較——包含一個類型 ;它會立即回答兩個庫之間的主要區(qū)別。

屏幕截圖來源與ChatGPT 聊天,ChatGPT 向我解釋了 geopandas 和 plotly 之間的區(qū)別

如果現(xiàn)在我想抓取一個網(wǎng)站,我可以問問最好的庫是什么。ChatGPT 使用 Python 中最流行的網(wǎng)絡抓取庫來回答。

圖片

屏幕截圖來源與ChatGPT 聊天,ChatGPT 解釋最流行的抓取網(wǎng)站

你甚至可以詢問你想要抓取的網(wǎng)站的最佳選擇是什么——盡管 ChatGPT 很可能會警告你這將違反該網(wǎng)站的內(nèi)容政策——所以要小心。

抓取社交網(wǎng)絡的最佳選擇是什么?

圖片

03.理解代碼

我們都去過那里,努力理解不是我們創(chuàng)建的代碼庫。瀏覽復雜且組織不當?shù)拇a(也稱為意大利面條代碼)可能是一項令人沮喪且耗時的任務。

但是,有了 ChatGPT,理解新的代碼庫就變得容易多了。我現(xiàn)在可以簡單地要求它解釋代碼的功能并立即理解它。無需再浪費寶貴的時間和精力來破譯糟糕的代碼。

假設我正在嘗試抓取 Linkedin,我在互聯(lián)網(wǎng)上發(fā)現(xiàn)了一個隨機代碼,該代碼應該可以向下滾動 Linkedin 工作機會網(wǎng)站。

以下代碼的作用是什么?


#We find how many jobs are offered.
jobs_num = driver.find_element(By.CSS_SELECTOR,"h1>span").get_attribute("innerText")
if len(jobs_num.split(',')) > 1:
jobs_num = int(jobs_num.split(',')[0])*1000
else:
jobs_num = int(jobs_num)

jobs_num = int(jobs_num)

#Here I choose manually a number of jobs, so it wont take that long:
jobs_num = 1000;


#We create a while loop to browse all jobs.
i = 2
while i <= int(jobs_num/2)+1:
#We keep scrollind down to the end of the view.
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
i = i + 1
print("Current at: ", i, "Percentage at: ", ((i+1)/(int(jobs_num/2)+1))*100, "%",end="\r")
try:
#We try to click on the load more results buttons in case it is already displayed.
infinite_scroller_button = driver.find_element(By.XPATH, ".//button[@aria-label='Load more results']")
infinite_scroller_button.click()
time.sleep(0.1)
except:
#If there is no button, there will be an error, so we keep scrolling down.
time.sleep(0.1)
pass

ChatGPT 會立即對上面的代碼進行非常詳細的解釋,你甚至可以在代碼給定部分中詢問更多詳細信息——只需稍微玩一下 ChatGPT,您就會發(fā)現(xiàn)它可以創(chuàng)造很多奇跡。

圖片

屏幕截圖 ChatGPT 聊天,ChatGPT 解釋了我沒看懂的代碼

04.在我們的代碼中添加注釋

ChatGPT 還可以幫助我們提高自己代碼的質(zhì)量和可維護性,通過你提出的要求,它會逐行添加注釋,我們可以確保我們的代碼在發(fā)布前得到正確記錄。這幫助我們實現(xiàn)了對代碼添加注釋的要求,并使其他人更容易理解和使用我們的代碼。

ChatGPT 可以明顯提高了代碼可讀性、可維護性和與他人協(xié)作的能力。

假設之前的代碼根本沒有注釋,我們可以讓 ChaGPT 直接給它添加注釋。

以下是ChatGPT為代碼添加注釋 :


# Find the number of jobs offered on the website
jobs_num = driver.find_element(By.CSS_SELECTOR,"h1>span").get_attribute("innerText")

# Check if the number of jobs contains a ',' and if so, convert it to number * 1000
if len(jobs_num.split(',')) > 1:
jobs_num = int(jobs_num.split(',')[0])*1000
else:
jobs_num = int(jobs_num)

# Convert jobs_num to an integer
jobs_num = int(jobs_num)

# Set the number of jobs to scrape to 1000
jobs_num = 1000;

# Initialize a counter variable to scroll through the jobs
i = 2

# Start a while loop to scroll through the jobs
while i <= int(jobs_num/2)+1:
# Scroll to the bottom of the page
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
# Increment the counter variable
i = i + 1
# Print the current number of jobs scrolled through and the percentage of completion
print("Current at: ", i, "Percentage at: ", ((i+1)/(int(jobs_num/2)+1))*100, "%",end="\r")
try:
# Try to locate the "Load more results" button and click on it
infinite_scroller_button = driver.find_element(By.XPATH, ".//button[@aria-label='Load more results']")
infinite_scroller_button.click()
# Sleep for 0.1 seconds
time.sleep(0.1)
except:
# If the button is not present, sleep for 0.1 seconds and continue scrolling
time.sleep(0.1)
pass

令人印象深刻吧?基本可以添加注釋的代碼均添加了。

05.使用某種風格重寫我們的代碼

ChatGPT 不僅是理解陌生代碼的寶貴工具,而且還可以幫助我們確保自己的代碼遵循行業(yè)標準和慣例,通過要求它更正我們的代碼以符合 Pep-8 約定,或者甚至為我們的編碼風格創(chuàng)建自定義約定,我們可以避免在合并來自不同存儲庫或團隊的代碼時進行昂貴且耗時的重構。

這有助于簡化協(xié)作流程并提高效率,總的來說,ChatGPT 是一個多功能工具,可以提高我們代碼庫的質(zhì)量和可維護性。

如果我們讓ChatGPT用Pep-8標準寫之前的代碼,它會直接給我們重構后的代碼。

你能用 Pep8 標準重寫下面的代碼嗎 ?

圖片

屏幕截圖 ChatGPT 聊天,ChatGPT 按照 Pep8 標準提供我們的代碼

總結

我希望讀完本文后,您會意識到 ChatGPT 可以幫助我們提高工作效率并創(chuàng)造更高質(zhì)量的輸出。我知道很容易陷入認為人工智能最終會接管我們工作的陷阱,但正確的人工智能可以成為一種強大的資產(chǎn),想辦法讓它可以為我們所用。

然而,重要的是要記住,批判性思維在與 AI 合作時仍然是關鍵,就像在與我們的人類同事合作時一樣。

因此,在您急于實施 AI 生成的響應之前,請確保先花時間審查和評估它們。相信我,這最終是值得的!

如果 ChatGPT 的其他一些優(yōu)秀功能讓您感到驚訝,請您在留言區(qū)告訴我,讓我們一起努力讓人工智能為我們服務。

責任編輯:華軒 來源: web前端開發(fā)
相關推薦

2013-01-21 09:38:47

交換機交換技術網(wǎng)絡設備

2012-04-17 14:23:49

2011-05-13 17:24:46

金山Android版

2014-02-18 09:42:34

云存儲公有云混合云

2010-12-16 20:54:07

Windows Azu

2013-09-12 13:42:48

企業(yè)郵箱高效辦公

2016-08-02 13:38:31

2010-11-10 10:29:51

職場

2009-07-01 09:41:00

無線路由器固件番茄固件

2010-06-10 22:25:37

2023-05-17 08:00:00

ChatGPT人工智能

2024-05-14 15:04:04

ChatGPT人工智能大型語言模型

2020-08-01 16:40:09

代碼語言Python

2024-03-21 17:29:45

2018-04-03 12:26:14

2011-09-20 11:06:26

網(wǎng)易郵箱極速4.0

2011-12-24 22:08:51

Siri

2018-03-16 15:16:46

2018-08-17 05:09:29

電腦軟件清理電腦

2010-07-06 10:53:41

RationalJazz測試管理
點贊
收藏

51CTO技術棧公眾號