Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import .py in google Colaboratory?

I want to simplify code. so i make a utils.py , but Google Colaboratory directory is "/content" I read other questions. but this is not my solution

In Google's Colab notebook, How do I call a function from a Python file?

%%writefile example.py
def f():
 print 'This is a function defined in a Python source file.'
# Bring the file into the local Python environment.
execfile('example.py')
f()
This is a function defined in a Python source file.

It look likes just using def().
using this, i always write the code in cell.

but i want to this code

import example.py
example.f()
like image 423
이성령 Avatar asked Mar 01 '18 11:03

이성령


1 Answers

A sample maybe you want:

!wget https://raw.githubusercontent.com/tensorflow/models/master/samples/core/get_started/iris_data.py -P local_modules -nc

import sys
sys.path.append('local_modules')

import iris_data
iris_data.load_data()
like image 144
zhpger Avatar answered Sep 30 '22 22:09

zhpger