1
$\begingroup$

I’m coming from a math background and learning some data science. I am very new to some details of this stuff.

Working with colab, I’m trying to organize my sample simulating functions in such a way that I can reach them even in different files/notebooks - and have not been able to find any working tutorials or explanations of how it works in colab.

The only things I’ve found have suggested using options that don’t seem to exist anymore - finding filepaths in it doesn’t seem to work as it once did.

Anyway, if anyone could guide me to a tutorial (or give some direct guidance), that would be greatly appreciated!!

Thanks a ton all, Paul

$\endgroup$

3 Answers 3

1
$\begingroup$

I would suggest you put your Python files as .py files in a folder on your Google drive. You then need to mount this folder.

from google.colab import drive
drive.mount('/content/drive/<path_to_your_dir>')

And then you should be able to import them:

from <your lib(without .py)> import *
$\endgroup$
0
$\begingroup$

I want to initiate a colab file rather than use it's function. From another

However my organisation doesn't allow me to mount my drive how can I do this?

$\endgroup$
-1
$\begingroup$

I think you are trying to access a particular dataset/files inside a google colab notebooks of your wish. You can do that by simply uploading your data to your google drive from where you can access them inside your colab.

Once you have uploaded your data to your google drive of your google colab registered account (only accessible from your registered account), the run the following code in a code cell:

from google.colab import drive
drive.mount('/content/drive')

This will allow you to access your google drive contents from google colab notebook. You can access the drive files directly from the side-bar or simply using the python os library to manipulate the files as you wish.

$\endgroup$
1
  • $\begingroup$ The question is clearly asking how to put functions in multiple files: -File 1: function1 -File 2: function2 Your answer is redundant. If you cannot or you you don't know the answer, then put it as a comment. $\endgroup$
    – Ash
    Commented Dec 6, 2023 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.