简体   繁体   中英

cannot import function name

All my files are in a same directory

I'm fresh in python and I'm trying to code functions in a Preprocessing file like this:

#Preprocessing file
from dateutil import parser
def dropOutcomeSubtype(DataFrame):
    DataFrame.drop('OutcomeSubtype',axis=1,inplace='True')

def convertTimestampToTime(Serie):
    for i in range(0,len(Serie)):
        parser.parse(Serie[i]).time()

And then I'm trying to use it in a Exporting file like this:

#Import external librairies 
import pandas as pd
import numpy as np
import re

#import our librairy
from Preprocessing import convertTimestampToTime, dropOutcomeSubtype

#Reading
Datas = pd.read_csv("../Csv/train.csv", sep=",", na_values=['NaN'])

dropOutcomeSubtype(Datas)
convertTimestampToTime(Datas.DateTime)

And when i try to run the code in my OSX shell with this config: Python 3.5.2 |Anaconda 4.2.0 (x86_64)| IPython 5.1.0

I have get this error: cannot import name 'convertTimestampToTime'

and if change my import statement like this:

from Preprocessing import *

I get this error: name 'convertTimestampToTime' is not defined

Can you explain me why please ?

Thank you in advance

In this case you can add mod path to sys.path. if both in same dir add this code at first of main code

import os
import sys
here = os.path.abspath(os.path.dirname(__file__))
sys.path.append(here)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM