0

I have a strange problem that I don't understand. I have a file date_import.py with several functions in it. (I don't want to show these functions here because they all are quite long.) I would like to import these functions in Jupyter. So I write 'from date_import import func1' and it works. But if I write 'from date_import import func1, func2' I get the answer "cannot import name func2". Also if I write 'from date_import import func2' i get the same answer. I thought at first that python somehow cannot see the changes in my file. But if I change the code in func1 and use inspect.getsource then, I can see that python accept the changes. But I still cannot import other functions, only func1. Did somebody see such behavior and knows some way around? Thanks in advance.

PS. Here is the function 2.

def func2(stichtag_sql):

    sql = """(select distinct .....
)"""

    tab = sqlContext.read.jdbc(url=jdbcURL, table=sql, properties=prop).cache()
    totale_wbs = tab.toPandas()
    totale_wbs.columns = map(str.lower, totale_wbs.columns)

    totale_wbs.kdnr =totale_wbs.kdnr.astype(str)

    return totale_wbs
Logic_Problem_42
  • 229
  • 2
  • 11
  • 1
    Could you provide only source code of def func2(): ... How do you define that? – Artur Kasza Apr 13 '20 at 08:52
  • would func2 happen to be a class method or a function within another function or are you running into a circular dependency issue? https://stackoverflow.com/questions/9252543/importerror-cannot-import-name-x – Phillyclause89 Apr 13 '20 at 08:55
  • I have added the func2. All functions are simply functions, I don't use any classes. I don't have any circular dependencies also. – Logic_Problem_42 Apr 13 '20 at 09:00
  • Does this answer your question? [How to re import an updated package while in Python Interpreter?](https://stackoverflow.com/questions/684171/how-to-re-import-an-updated-package-while-in-python-interpreter) – mkrieger1 Apr 13 '20 at 14:51

2 Answers2

1

if you created your function func_2 after you have imported your module date_import you have to reimport your module:

import importlib
importlib.reload(date_import)
kederrac
  • 16,819
  • 6
  • 32
  • 55
-2

try:

from date_import import (func1, func2)
void
  • 1