您好,欢迎访问一九零五行业门户网

ChatGPT 的五大功能可以帮助你提高代码质量

chatgpt 目前彻底改变了开发代码的方式,然而,大多数软件开发人员和数据专家仍然没有使用 chatgpt 来改进和简化他们的工作。
这就是为什么我在这里概述 5 个不同的功能,以提高我们的日常工作速度和质量。
我们可以在日常工作中使用它们。现在,我们一起来了解一下吧。
注意:切勿在 chatgpt 中使用关键代码或信息。
01.生成项目代码的框架从头开始构建新项目时,chatgpt 是我的秘密武器。只需几个提示,它就可以生成我需要的代码框架,包括我选择的技术、框架和版本。它不仅为我节省了至少一个小时左右的工作时间,而且还有助于使我的文档(或团队的文档)井井有条并保持最新,这就好像在给团队加外挂,感觉无形之中多了一双手!
例如,假设我想使用一些外部 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(//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[@]).text location = driver.find_element_by_xpath(//span[@]).text print(name) print(location) # close the browser driver.quit()
很容易,对吧?尝试用您能想象到的任何项目来挑战 chatgpt。
02.研究和比较就如何实施某些事情做出决定可能很困难,尤其是当有多种选择可供选择时。我的首选方法是为每种方法创建一个基本的概念证明,然后将它们进行比较。但是,在 chatgpt 的帮助下,这个过程变得简单多了。
我现在可以直接询问它的专家意见,了解哪个选项或库最适合我的代码开发。这节省了我在决策过程中的时间和精力,并确保我使用最好的工具来完成工作。
假设我想处理地理空间数据,但不确定是否应该使用 geopandas 或 plotly。我可以让 chatgpt 为我进行比较——包含一个类型 ;它会立即回答两个库之间的主要区别。
屏幕截图来源与chatgpt 聊天,chatgpt 向我解释了 geopandas 和 plotly 之间的区别
如果现在我想抓取一个网站,我可以问问最好的库是什么。chatgpt 使用 python 中最流行的网络抓取库来回答。
屏幕截图来源与chatgpt 聊天,chatgpt 解释最流行的抓取网站
你甚至可以询问你想要抓取的网站的最佳选择是什么——尽管 chatgpt 很可能会警告你这将违反该网站的内容政策——所以要小心。
抓取社交网络的最佳选择是什么?
03.理解代码我们都去过那里,努力理解不是我们创建的代码库。浏览复杂且组织不当的代码(也称为意大利面条代码)可能是一项令人沮丧且耗时的任务。
但是,有了 chatgpt,理解新的代码库就变得容易多了。我现在可以简单地要求它解释代码的功能并立即理解它。无需再浪费宝贵的时间和精力来破译糟糕的代码。
假设我正在尝试抓取 linkedin,我在互联网上发现了一个随机代码,该代码应该可以向下滚动 linkedin 工作机会网站。
以下代码的作用是什么? #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 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 不仅是理解陌生代码的宝贵工具,而且还可以帮助我们确保自己的代码遵循行业标准和惯例,通过要求它更正我们的代码以符合 pep-8 约定,或者甚至为我们的编码风格创建自定义约定,我们可以避免在合并来自不同存储库或团队的代码时进行昂贵且耗时的重构。
这有助于简化协作流程并提高效率,总的来说,chatgpt 是一个多功能工具,可以提高我们代码库的质量和可维护性。
如果我们让chatgpt用pep-8标准写之前的代码,它会直接给我们重构后的代码。
你能用 pep8 标准重写下面的代码吗 ?
屏幕截图 chatgpt 聊天,chatgpt 按照 pep8 标准提供我们的代码
总结我希望读完本文后,您会意识到 chatgpt 可以帮助我们提高工作效率并创造更高质量的输出。我知道很容易陷入认为人工智能最终会接管我们工作的陷阱,但正确的人工智能可以成为一种强大的资产,想办法让它可以为我们所用。
然而,重要的是要记住,批判性思维在与 ai 合作时仍然是关键,就像在与我们的人类同事合作时一样。
因此,在您急于实施 ai 生成的响应之前,请确保先花时间审查和评估它们。相信我,这最终是值得的!
如果 chatgpt 的其他一些优秀功能让您感到惊讶,请您在留言区告诉我,让我们一起努力让人工智能为我们服务。
以上就是chatgpt 的五大功能可以帮助你提高代码质量的详细内容。
其它类似信息

推荐信息