简体   繁体   中英

How to import python code in Jupyter notebook

I'm trying to import a python code that has usernames, passwords, and auth keys saved to a Jupyter notebook without sharing that information directly in the code. These are just for tests but I've tried using:

   import sys 
   sys.path.insert(0, '/C:/user/phlf/saved_data/config.py')
   import file

I also tried

   %run "~/C:user/phlf/saved_data/Config.py"

Is there a way to import python file for Jupyter to use without posting the code directly in notebook?

sys.path contains directories, not paths to file.

You'd probably just want to use importlib if you know which file you want to import.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM