CodeFree中文文档

项目声明


本项目仅供python爱好者学习使用, 禁止用于商业用途, 希望大家合理利用该项目🙂

安装codefree

环境配置

  • 操作系统: Linux or macOS or Windows

  • Python版本: Python3.6+

PIP安装(推荐)

在终端运行如下命令即可(请保证python在环境变量中):

pip install codefree --upgrade

源代码安装

1.在线安装

运行如下命令即可在线安装:

pip install git+https://github.com/CharlesPikachu/codefree.git@master

2.离线安装

利用如下命令下载codefree源代码到本地:

git clone https://github.com/CharlesPikachu/codefree.git

接着, 切到codefree目录下:

cd codefree

最后运行如下命令进行安装:

python setup.py install

快速开始

代码搜索

示例代码如下:

from codefree import codefree

engine = codefree.CodeFree(keyword='quick sort')
code = engine(return_code=True)
print(code)

CodeFree实例化时的参数解释如下:

  • keyword: 搜索的关键词;

  • source: 使用的代码源, 目前只支持”stackoverflow”;

  • proxies: 使用的代理, 代理格式同Requests

run函数支持的参数如下:

  • return_code: 是否返回代码, 代码搜索时必须设为True。

代码运行

示例代码如下:

from codefree import codefree

engine = codefree.CodeFree(keyword='quick sort')
lst = [2, 5, 1, 4, 6, 10, 3]
g = {'lst': lst}
engine(return_code=False, globals=g, following_code='result = quickSort(lst)')
print(g['result'])
  • following_code: 添加的补充代码, 用于保证搜索到的代码可以正常运行;

  • globals: 字典类型, 用于定义代码中的未知变量;

  • return_code: 是否返回代码, 代码运行时必须设为False。

效果如下:


开发日志

2022-03-19

  • 版本号: v0.1.0-0.1.1,

  • 更新内容: 支持Stackoverflow作为代码源。

2022-03-24

  • 版本号: v0.1.2,

  • 更新内容: 添加作者信息。

项目推荐

关于作者

学生党, 主要研究方向是计算机视觉, 顺便对信息安全感兴趣。

我的个人微信公众号是: Charles_pikachu (欢迎搜索关注,或者搜”Charles的皮卡丘”)

我的Github账号是: https://github.com/CharlesPikachu (欢迎搜索关注)

我的知乎账号是: https://www.zhihu.com/people/charles_pikachu (欢迎搜索关注)

我的B站账号是: https://space.bilibili.com/406756145 (欢迎搜索关注)

个人邮箱: charlesblwx@gmail.com