Python模块打印

时间:2016-06-16 01:06:02

标签: python

我的功能是在运行时打印,但我想从我的主文件打印或创建单独的打印功能。我不知道如何将返回值传递给我的打印。

Master.py:

import main
import split
import password

main.py:

import split

def main():

  #  first_name = raw_input('please enter Your Name: ')
  #  family_name = raw_input('Please enter Your Surname: ')
  #  student_ID = raw_input('Please enter your Student ID number: ')

    first_name = 'Benjamin'
    family_name = 'Montgomery'
    student_ID = '1000036317'

    login = split.letters(first_name, family_name, student_ID)
    print login  
    return login

main()

split.py:

# import main

def letters(first_name,family_name,student_ID):
    name = first_name[:3]
    lastname = family_name[:3]
    ID_tree = student_ID[:3]
    login = name+lastname+ID_tree
    #   print login
    return str(login)

# letters(first_name,family_name,student_ID)

1 个答案:

答案 0 :(得分:0)

您的功能看起来不错,但要注意创建与常用功能和方法共享相同名称的模块。 “split”是一种字符串方法。我测试了你的代码并进行了微小的修改,打印得很好(这就是我得到的):

  

登录 - > BenMon100

#msplit.py
def letters(first_name,family_name,student_ID):
    name = first_name[:3]
    lastname = family_name[:3]
    ID_tree = student_ID[:3]
    login = name+lastname+ID_tree
    #   print login
    return str(login)

#main.py
import msplit

def main():

#  first_name = raw_input('please enter Your Name: ')
#  family_name = raw_input('Please enter Your Surname: ')
#  student_ID = raw_input('Please enter your Student ID number: ')

    first_name = 'Benjamin'
    family_name = 'Montgomery'
    student_ID = '1000036317'
    login = msplit.letters(first_name, family_name, student_ID)
    print 'login ->', login
    return login

main()