• Create
    • Ask a question
    • Create an article
    • Topics
    • Questions
    • Articles
    • Users
    • Badges
  • Sign in
  • Home /
avatar image
1

How to import local python file in notebook?

python
Question by lakshmana1980 · Feb 06, 2018 at 04:45 PM ·

In python notebook I have some code like below in cell.

---------------

%%file Person.py

class Person(object):

def init(self, name, company):

self.name = name

self.company = company

------------

I execute the above cell code then seen the output like this.

Writing Person.py

-----------

Above file Person.py is stored in data bricks unix file system.

%sh pwd

Ouput : /databricks/driver

----------

%sh ls

Output: Person.py

-------------

Now I want to load this file and import Person class ?

I tried to execute below statements at seperate cells and no use. Please let me know what is missing and why I am unable import that local file into my note book and use!

----------

%load /databricks/driver/Person.py

%load /databricks/driver/Person

%load Person

%run "/databricks/driver/Person.py"

%run "/databricks/driver/Person

etc ......

--------

people = [Person("lak", "tcs"), Person("nag", "cent"), Person("anu", "home")] person_rdd = sc.parallelize(people)

-------

PicklingError: Can't pickle <class 'main.Person'>: attribute lookup main.Person failed

Add comment
Comment
10 |600 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Sort

  • Votes
  • Created
  • Oldest

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why are Python custom UDFs (registerFunction) showing Arrays with java.lang.Object references? 1 Answer

While running a application in Apache Spark, gave WARN message 0 Answers

Goose-extractor 0 Answers

How to concatenate/append multiple Spark dataframes column wise in Pyspark? 0 Answers

GDAL installation 1 Answer

  • Product
    • Databricks Cloud
    • FAQ
  • Spark
    • About Spark
    • Developer Resources
    • Community + Events
  • Services
    • Certification
    • Spark Support
    • Spark Training
  • Company
    • About Us
    • Team
    • News
    • Contact
  • Careers
  • Blog

Databricks Inc.
160 Spear Street, 13th Floor
San Francisco, CA 94105

info@databricks.com
1-866-330-0121

  • Twitter
  • LinkedIn
  • Facebook
  • Facebook

© Databricks 2015. All rights reserved. Apache Spark and the Apache Spark Logo are trademarks of the Apache Software Foundation.

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Create an article
  • Explore
  • Topics
  • Questions
  • Articles
  • Users
  • Badges