Python从一个函数中导​​入多个函数

时间:2017-04-24 16:55:03

标签: python

您好我正在尝试从另一个文件中导入我的函数。我使用from my_script import *从我脚本顶部的该文件中导入了所有内容。但是,由于我想从另一个函数中调用这些导入的函数,我已经从函数中单独导入它们; from my_script import function_1 - 这是正常的。但是当我尝试导入我需要的所有函数而不只是一个函数from my_script import function_1, function_2, function_3然后调用它时,Python会抛出错误:无法导入名称' function_1'。

def iphone_5_routine():
from create_files import create_display_file_5
print('Please state the issue using one of the following keywords', keywords)
issue = str(input('Issue: '))

if issue == keywords[0]:
    f = open('displaysolutions.txt','r')  #Make a text file with the iPhone display solutions
    lines = f.readlines()
    print(lines[0])
    issue = input('Has the issue been solved?').lower()

    if issue == 'no':
            print(lines[1])
    else:
            print('Thanks for using the phone diagnostics tool')

    issue = input('Has the issue been solved?').lower()
    if issue == 'no':
            print(lines[2])
            create_display_file_5()

    else:
            print('Thanks for using the phone diagnostics tool')

from create_files import create_speaker_file_5
if issue == keywords[1]:
    f = open('speakersolutions.txt','r')  #Make a text file with the iPhone display solutions
    lines = f.readlines()
    print(lines[0])
    issue = input('Has the issue been solved?').lower()

    if issue == 'no':
            print(lines[1])
    else:
            print('Thanks for using the phone diagnostics tool')

    issue = input('Has the issue been solved?').lower()
    if issue == 'no':
            print(lines[2])
            create_speaker_file_5()

    else:
            print('Thanks for using the phone diagnostics tool')

这是我试图在另一个脚本中调用的函数:

     from Task_3_developed_script import *

     def create_display_file_5():
     global case_number
     case_number += 1
     global case_numbers
     case_numbers.append(case_number)
     f = open('{0}.txt'.format(case_numbers[0]),"w")
     f.write("Device: Phone  Model: iPhone 5 Problem: Display")
     f.close()
     print('The case has been exported to a file ready for the technician')
     print('The case number is: ',case_number)

    def create_speaker_file_5():
    global case_number
    case_number += 1
    global case_numbers
    case_numbers.append(case_number)
    f = open('{0}.txt'.format(case_numbers[0]),"w")
    f.write("Device: Phone  Model: iPhone 5 Problem: Speakers")
    f.close()
    print('The case has been exported to a file ready for the technician')
    print('The case number is: ',case_number)

0 个答案:

没有答案