欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

5個ChatGPT功能幫助你提升日常編碼效率

 更新時間:2023年02月17日 08:34:40   作者:Python數(shù)據(jù)挖掘  
ChatGPT?作為最快完成億活用戶的應(yīng)用,最近真的是火出天際了。今天分享5個?ChatGPT?功能,來提升我們的日常工作以及如何使用它提高代碼質(zhì)量

ChatGPT 的出現(xiàn),徹底改變了開發(fā)代碼的方式。但是目前為止,大多數(shù)軟件開發(fā)人員和數(shù)據(jù)專業(yè)人員仍然沒有習(xí)慣使用 ChatGPT 來改進(jìn)和簡化自己的工作。

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

下面讓我們一起探索如何在日常工作中使用它們

1.生成編碼框架

ChatGPT 是我們從頭開始構(gòu)建新項目的秘密武器。只需幾個提示,它就可以生成我們所需的代碼框架,以及所選擇的技術(shù)、框架和版本。它不僅每次為我們節(jié)省了至少一個小時左右的工作時間,而且有助于保持文檔(或團(tuán)隊的文檔)的有效組織和更新,這就像團(tuán)隊中多了一雙手,一雙勤勞的手!

例如,我們想使用一些外部API,可以請 ChatGPT 為我們起草一個初始代碼結(jié)構(gòu)。

問:Generate boiler plate code that integrates an extern API using Python.

或者我們甚至可以要求這個框架使用 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 吧。

2.研究和比較

決定如何實施某件事可能是很困難的,特別是當(dāng)有多種情況可供選擇時。我的方法是為每種選擇創(chuàng)建一個基本的概念模型,然后比較它們。

但是,在 ChatGPT 的幫助下,這個過程變得簡單多了。

我們現(xiàn)在可以直接向它征求專家級別的意見,以確定哪種選項或庫最適合我們的代碼開發(fā)。這節(jié)省了我們在決策過程中的時間和精力,并確保使用了最佳的工具。

讓我們想象一下,我想使用地理空間數(shù)據(jù),但我不確定是否應(yīng)該使用 Geostandard 或 Plotly。我們可以要求 ChatGPT 進(jìn)行比較,它立即回答了兩個庫之間的主要區(qū)別。

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

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

問:What’s the best option to scrape a social network?

3.理解代碼

在日常工作當(dāng)中,我們都在努力理解一個不是由我們創(chuàng)建的代碼庫。瀏覽一個復(fù)雜且組織不良的代碼可能是一項令人崩潰的任務(wù)。

但是,通過 ChatGPT,理解新的代碼庫變得容易多了。我現(xiàn)在可以簡單地要求它解釋代碼的功能,不需要再浪費寶貴的時間和精力來破譯寫得不好的代碼。

讓我們想象一下,當(dāng)我們正在嘗試抓取 Linkedin,此時在互聯(lián)網(wǎng)上發(fā)現(xiàn)了一個樣例代碼,該代碼應(yīng)該可以滾動 Linkedin 招聘網(wǎng)站。

問:What does the following code do? [insert code here]

#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 立即對上面的代碼進(jìn)行了非常詳細(xì)的解釋。我們甚至可以要求在代碼的給定部分提供更多的細(xì)節(jié)。

4.向代碼添加注釋

ChatGPT 還可以幫助我們提高自己代碼的質(zhì)量和可維護(hù)性。通過要求它逐行添加注釋,使其他人更容易理解和使用我們的代碼。

ChatGPT 可以顯著提高可讀性、可維護(hù)性以及與他人的協(xié)作。

讓我們假設(shè)下面的代碼根本沒有注釋。我們可以要求 ChaGPT 直接向其添加注釋。

問:Add comments to the following code [insert code here]

# 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

5.使用某種樣式重寫代碼

ChatGPT 不僅是理解不熟悉代碼的寶貴工具,還可以幫助我們確保自己的代碼符合行業(yè)標(biāo)準(zhǔn)和慣例。通過要求它糾正我們的代碼以符合 Pep-8 約定,甚至為我們的編碼風(fēng)格創(chuàng)建一個自定義約定,我們可以避免在合并來自不同 repo 或團(tuán)隊的代碼時進(jìn)行昂貴且耗時的重構(gòu)。

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

如果我們要求 ChatGPT 使用 Pep-8 標(biāo)準(zhǔn)編寫以前的代碼,它將直接為我們提供重構(gòu)的代碼。

問:Can you rewrite the following code using Pep8 standard [Insert code here]

好了,這就是今天分享的5個 ChatGPT 功能,對于提升日常工作效率,還是非常棒的,要不要嘗試一下呢~

到此這篇關(guān)于5個ChatGPT功能幫助你提升日常編碼效率的文章就介紹到這了,更多相關(guān)ChatGPT功能內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論