Skip to content

Add try import from google.colab import files .. except#6

Open
masaguaro wants to merge 1 commit into
masterfrom
google_colab
Open

Add try import from google.colab import files .. except#6
masaguaro wants to merge 1 commit into
masterfrom
google_colab

Conversation

@masaguaro

Copy link
Copy Markdown
Owner

Following the Mani's suggestion to make the notebook work on google colab. I wrapped the imports, uploading and select file steps in a try-except block. However, it is not working

try:
    from google.colab import files
    files.upload()
    uploaded_files = [f for f in uploaded.keys()]
    df = pd.read_csv(io.StringIO(uploaded[uploaded_files[0]].decode('utf-8')))
except:
    from selectfile import FileBrowser
    train_file_picker = FileBrowser()
    train_file_picker.widget()
    df = pd.read_csv(train_file_picker.path)

The train_file_picker.widget() intruction is not generating the file browser to select the file. I am trying to find out why.

@neomatrix369

Copy link
Copy Markdown
Collaborator

@masaguaro The issue is

train_file_picker.widget()  
df = pd.read_csv(train_file_picker.path)

train_file_picker.path only returns the path to the file but not the file name which is causing errors.
But the real problem is that the dialog is sometimes display and sometimes not displayed for the user to select the file - this needs to be enforced.

So there are two problem:

  • dialog not being displayed
  • only path is returned and not filename when a file is select

Both of these lead the below line to fail, hence its not working as per @masaguaro:

df = pd.read_csv(train_file_picker.path)

@masaguaro

masaguaro commented Oct 2, 2018

Copy link
Copy Markdown
Owner Author

@neomatrix369 Without the file browser, we can not select the file. I think in the following code is easier to see the core of the problem:

import ipywidgets as widgets

def widget(description):
    button = widgets.Button(description=description,layout={'width': '300px'})
    return button

try:
    print("Before widget_1")
    widget_1 = widget(description='Browser One')
    widget_1
    print("After widget_1")
except:
    pass

widget_2 = widget(description='Browser Two')
widget_2

After executing the Jupyter cell it will print " Before widget_1" and "After widget_1", and then widget_2 will show up. However, widget_1 does not show up. I have posted the question here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants