如何使用私密代码共享Google Colab [英] How to share Google colab with private code

查看:328
本文介绍了如何使用私密代码共享Google Colab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想共享一个Google colab笔记本,但需要隐藏部分代码.是否可以将私有代码放在单独的.py或Colab笔记本中,然后将其导入,以便那些有权访问公共Colab笔记本的人看不到私有.py或Colab笔记本?

I am wanting to share a Google colab notebook, but needs to hide part of the code. Is it possible to put the private code in a separate .py or Colab notebook, and import it, so that those who have access to the public Colab notebook cannot see the private .py or Colab notebook?

非常感谢.

推荐答案

不是真的;您隐藏代码的能力仅与用户无法对其进行检查的能力一样好:

Not really; your ability to hide code is only as good as your users' inability to inspect it:

import some_file # your private .py

from inspect import getsource
print(getsource(some_file))

无论文件如何导入,最底行都会显示文件的整个源代码.

The bottom line will print the file's entire source code - no matter how it was imported.

如果您不希望用户知道或知道这一点(不是安全的选择),那么可以,您可以通过自我验证请求将导入运行到存储设备(例如,云端硬盘)用户无法访问的Google Cloud Bucket),但这将涉及很多步骤(我不知道这些步骤).

If you don't expect your users to know or figure this (not a safe bet), then yes, you could run an import via a self-authenticating request to a storage (e.g. Drive, Google Cloud Bucket) that the user cannot access, but that'll involve lots of steps (of which I wouldn't know).

有关隐藏代码的更多信息,请参见此SO 难以检查的方法.

See this SO for more info on hiding code, and some specific methods for making inspection harder.

更新:一种解决方法是在只读模式下共享,该模式下可以执行但不能编辑单元格-请参见

Update: a workaround is to share in read-only mode, where cells can be executed but not edited - see this SO for several methods. Note that this still doesn't make your code fully private, but some of the methods in the link can be very difficult to circumvent (require hacking) - effectively, success.

这篇关于如何使用私密代码共享Google Colab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆