-1

from A.py to B.py file

A.py file

def ticket():
    .
    .
    .
    tickets = child + student + senior + adult
    total_price = child * Child_price + student * student_price + senior * senior_price + adult * adult_price

How can i import total_price from A.py file to B.py file

7
  • What does file B.py contains? Commented Jan 7, 2020 at 7:35
  • just want to print the output in B.py file Commented Jan 7, 2020 at 7:37
  • total_price is inside ticket function?? Commented Jan 7, 2020 at 7:38
  • yeah it is inside ticket function Commented Jan 7, 2020 at 7:42
  • Does the below solution works? Commented Jan 7, 2020 at 7:49

1 Answer 1

2

Check out the below solution:

You need to import file A in file B and return the value from file B

File A.py contains:

def ticket():
    .
    .
    .
    .
    tickets = child + student + senior + adult
    total_price = child * Child_price + student * student_price + senior * senior_price + adult * adult_price
    return(tickets,total_price)

Contents of file B.py:

from A import ticket
tickets,total_price= ticket()
print(tickets,total_price)

OR

import A
print(A.ticket())

OR

from A import ticket
print(ticket())
Sign up to request clarification or add additional context in comments.

12 Comments

Does this solution works?
Obviously it will !
@sunilghimire check the updated solution. You can only import function ticket from A.py
You have to return the values from the function. Are you using classes?
Return tickets too then
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.