def add():
import add_coffee_record
import imp
imp.reload(add_coffee_record)
def show():
import show_coffee_records
import imp
imp.reload(show_coffee_records)
def search():
import search_coffee_records
import imp
imp.reload(search_coffee_records)
def modify():
import modify_coffee_records
import imp
imp.reload(modify_coffee_records)
def delete():
import delete_coffee_record
import imp
imp.reload(delete_coffee_record)
def main():
num=input('\nEnter the number on the menu: ')
while num != '6':
if num == '1':
print()
add()
if num == '2':
print()
show()
if num == '3':
print()
search()
if num == '4':
print()
modify()
if num == '5':
print()
delete()
num=input('\nEnter the number on the menu: ')
main()
我的输出如下:
Enter the number on the menu: 2
Description: Thanksgiving Blend
Quantity: 300.0
Description: Christmas Blend
Quantity: 100.0
Description: Thanksgiving Blend
Quantity: 300.0
Description: Christmas Blend
Quantity: 100.0
Enter the number on the menu: 2
Description: Thanksgiving Blend
Quantity: 300.0
Description: Christmas Blend
Quantity: 100.0
Enter the number on the menu: 2
Description: Thanksgiving Blend
Quantity: 300.0
Description: Christmas Blend
Quantity: 100.0
如果第一个输出不会复制,我会喜欢它。有没有办法构建程序,在第一个实例上只使用“import”,在连续的实例上使用“reload”?注意:我无法复制粘贴程序文件而不是导入。我需要使用导入。谢谢。
答案 0 :(得分:0)
您可以在导入之前从imp.load_module
删除该模块:
def add():
imp.load_module("add_coffee_record", *imp.find_module("add_coffee_record"))
另一种选择是直接致电 <FlipView x:Name="flip" Grid.Row="1" Grid.ColumnSpan="4" Grid.Column="0" Margin="0,0,0,0.333" Grid.RowSpan="2">
<FlipViewItem>
<Button Foreground="White" Background="Black" x:Name="btnAdd" Content="Add" Grid.Row="1" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Tapped="btnAdd_Tapped" ></Button>
</FlipViewItem>
<FlipViewItem>
<Button x:Name="btny2" Content="mov" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" Tapped="btny2_Tapped" ></Button>
</FlipViewItem>
<FlipViewItem>
<Button x:Name="btnUpdate" Content="Upd" Grid.Row="1" Grid.Column="2" HorizontalAlignment="Right" Tapped="btnupdate_Tapped" ></Button>
</FlipViewItem>
<FlipViewItem>
<Button x:Name="btnRemove" Content="Rem" Grid.Row="1" Grid.Column="3" HorizontalAlignment="Center" Tapped="btnRemove_Tapped" ></Button>
</FlipViewItem>
</FlipView>
private void btnAdd_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
private void btnupdate_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
private void btny2_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
private void btnRemove_Tapped(object sender, TappedRoutedEventArgs e)
{
flip.SelectedIndex++;
}
:
function addQuestionField() {
var get = $("#ques").val();
for (var i = 1; i < get; i++) {
答案 1 :(得分:0)
您需要进入要导入的程序,并将函数名称从main更改为add之类的其他名称。然后注释掉调用该函数,以便您可以在菜单程序中对其进行调用,然后导入该函数的名称。
from add_coffee_record import add
from delete_coffee_record import delete
from modify_coffee_records import mod
from search_coffee_records import search
from show_coffee_records import show
def main():
choice = -1
print("Welcome!")
while choice != 9:
print ('Select 1 to add records,')
print('Select 2 to show coffee records')
print('Select 3 to search coffee records,')
print('Select 4 to modify coffee records')
print('Select 5 to delete coffee records.')
print (' or 9 to quit.')
choice = int(input('Enter your choice: '))
if choice == 1:
add()
elif choice==2:
show()
elif choice==3:
search()
elif choice==4:
mod()
elif choice==5:
delete()
elif choice==9:
print('Thank you.')
main()