【发布时间】:2016-09-02 16:38:16
【问题描述】:
我有 2 个 Python 3.5 脚本,boot.py 和 about.py。 boot.py 位于 /os,而 about.py 位于 /os/bin。 Boot.py 以 os.system(/path/about.py) 开头 about.py。问题是 about.py 需要 boot.py 中的变量,我不想重新重写它们。所以我需要以一种可以读取/使用 boot.py 中的变量的方式启动 about.py。如果不清楚,我将代码贴在下面。
boot.py:
#Boot.py
import os
import subprocess
import socket
import platform
import multiprocessing
import time
import datetime
from random import randint
#Create functions
def cls():
os.system('cls' if os.name=='nt' else 'clear')
#Set the variables
prj_name = 'boot.py'
prj_build = 1.01
prj_developer = 'RED'
#Bunch of print() and input() commands below
关于.py:
#Somehow get the variables and functions defined in boot.py
print('This project is made by ' + prj_developer)
print('Build: ' + prj_build)
print('Launched by: ' + prj_name)
【问题讨论】:
标签: python python-3.x variables import call