本网站(662p.com)打包出售,且带程序代码数据,662p.com域名,程序内核采用TP框架开发,需要联系扣扣:2360248666 /wx:lianweikj
精品域名一口价出售:1y1m.com(350元) ,6b7b.com(400元) , 5k5j.com(380元) , yayj.com(1800元), jiongzhun.com(1000元) , niuzen.com(2800元) , zennei.com(5000元)
需要联系扣扣:2360248666 /wx:lianweikj
5个ChatGPT功能帮助你提升日常编码效率
沙雕mars · 118浏览 · 发布于2023-06-25 +关注

hatGPT 作为最快完成亿活用户的应用,最近真的是火出天际了。今天分享5个 ChatGPT 功能,来提升我们的日常工作以及如何使用它提高代码质量

ChatGPT 的出现,彻底改变了开发代码的方式。但是目前为止,大多数软件开发人员和数据专业人员仍然没有习惯使用 ChatGPT 来改进和简化自己的工作。

791b553c0b68b46c3c19ccb231cb6d06_202302170832391_202311783436.png

这就是为什么我在这里概述了5个不同的功能,以提高日常工作的速度和质量。

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

1.生成编码框架

ChatGPT 是我们从头开始构建新项目的秘密武器。只需几个提示,它就可以生成我们所需的代码框架,以及所选择的技术、框架和版本。它不仅每次为我们节省了至少一个小时左右的工作时间,而且有助于保持文档(或团队的文档)的有效组织和更新,这就像团队中多了一双手,一双勤劳的手!

例如,我们想使用一些外部API,可以请 ChatGPT 为我们起草一个初始代码结构。

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

8a584e81faf964c81d91e45bf53ccd15_202302170832392_20231178359.jpg

或者我们甚至可以要求这个框架使用 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("//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("//span[@class='inline t-24 t-black t-normal break-words']").
text
location = driver.find_element_by_xpath("//span[@class='t-16 t-black t-normal inline-block']").
text
 print(name)
print(location)
 # close the browser
driver.quit()

很简单对吧?尝试用我们能想象的任何项目去挑战 ChatGPT 吧。

2.研究和比较

决定如何实施某件事可能是很困难的,特别是当有多种情况可供选择时。我的方法是为每种选择创建一个基本的概念模型,然后比较它们。

但是,在 ChatGPT 的帮助下,这个过程变得简单多了。

我们现在可以直接向它征求专家级别的意见,以确定哪种选项或库最适合我们的代码开发。这节省了我们在决策过程中的时间和精力,并确保使用了最佳的工具。

让我们想象一下,我想使用地理空间数据,但我不确定是否应该使用 Geostandard 或 Plotly。我们可以要求 ChatGPT 进行比较,它立即回答了两个库之间的主要区别。

88891900cadfe439a02394135e29dae7_202302170832393_202311783616.jpg

如果现在我们想抓取网站,就可以问什么是最好的库。ChatGPT 会用 Python 中最流行的 web 抓取库来回答。

image.png

我们甚至可以询问想要抓取的网站的最佳方式是什么——尽管 ChatGPT 很可能会警告你这将违反该网站的内容政策——所以要小心。

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

590ab6cc590c4b58780152f08c69c967_202302170832405_202311783635.jpg

3.理解代码

在日常工作当中,我们都在努力理解一个不是由我们创建的代码库。浏览一个复杂且组织不良的代码可能是一项令人崩溃的任务。

但是,通过 ChatGPT,理解新的代码库变得容易多了。我现在可以简单地要求它解释代码的功能,不需要再浪费宝贵的时间和精力来破译写得不好的代码。

让我们想象一下,当我们正在尝试抓取 Linkedin,此时在互联网上发现了一个样例代码,该代码应该可以滚动 Linkedin 招聘网站。

问: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 立即对上面的代码进行了非常详细的解释。我们甚至可以要求在代码的给定部分提供更多的细节。

b0acf7644d277e899f590559bf00628d_202302170832406_202311783641.jpg

4.向代码添加注释

ChatGPT 还可以帮助我们提高自己代码的质量和可维护性。通过要求它逐行添加注释,使其他人更容易理解和使用我们的代码。

ChatGPT 可以显著提高可读性、可维护性以及与他人的协作。

让我们假设下面的代码根本没有注释。我们可以要求 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 不仅是理解不熟悉代码的宝贵工具,还可以帮助我们确保自己的代码符合行业标准和惯例。通过要求它纠正我们的代码以符合 Pep-8 约定,甚至为我们的编码风格创建一个自定义约定,我们可以避免在合并来自不同 repo 或团队的代码时进行昂贵且耗时的重构。

这有助于简化协作流程,提高效率。总之,ChatGPT 是一个多功能工具,可以提高代码库的质量和可维护性。

如果我们要求 ChatGPT 使用 Pep-8 标准编写以前的代码,它将直接为我们提供重构的代码。

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

12ba54210d1a7193db68b15dda499430_202302170832407_202311783745.jpg

好了,这就是今天分享的5个 ChatGPT 功能,对于提升日常工作效率,还是非常棒的,要不要尝试一下呢~


相关推荐

PHP实现部分字符隐藏

沙雕mars · 1325浏览 · 2019-04-28 09:47:56
Java中ArrayList和LinkedList区别

kenrry1992 · 908浏览 · 2019-05-08 21:14:54
Tomcat 下载及安装配置

manongba · 970浏览 · 2019-05-13 21:03:56
JAVA变量介绍

manongba · 963浏览 · 2019-05-13 21:05:52
什么是SpringBoot

iamitnan · 1087浏览 · 2019-05-14 22:20:36
加载中

0评论

评论
做自己,让别人去说,欢迎各位关注!
分类专栏
小鸟云服务器
扫码进入手机网页