Example #1
0
from utility import multiply, divide
from shopping import shopping_cart

if __name__ == "__main__":
    print(shopping_cart.buy('apple'))
    print(divide(5, 2))
    print(multiply(5, 2))
    print(max([1, 2, 3]))
Example #2
0
# modules and packages
from shopping.shopping_cart import buy
from shopping.items import products

print(dir(products))
help(shopping)
# print(help(buy))

if __name__ == '__main__':
    print(buy(10, 20))
    print(products.add_to_wish_list('Bread'))

print(__name__)
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 22 11:53:21 2020

@author: saura
"""
from utilities import mult, divide
from shopping.shopping_cart import buy

# print(utilities)  # gives error
print(mult)

print(mult(44, 5))
print(divide(115, 3))

# print(shopping)  # gives error
# print(shopping.shopping_cart)  # gives error
print(buy('apple'))
Example #4
0
import utility
import shopping.shopping_cart as shopping_cart

print(utility.divide(10, 2))
print(shopping_cart.buy(1))
Example #5
0
print(__name__)

import module_utilities
# from shopping import shopping_cart
from shopping.shopping_cart import buy

if __name__ == "__main__":
    print(module_utilities.multiply(10, 2))
    print(module_utilities.divide(100, 2))

    # print(shopping_cart.buy("apple"))

    #cleaner version
    print(buy("apple"))
Example #6
0
import shopping.shopping_cart
# or to access functions directly use from package.module import functioname

from shopping.shopping_cart import buy
from utility import multiply, divide
# use * syntax to import every function
from utility import *

# prints the filepath
print(utility)
# use . syntax to run methods
print(utility.divide(10, 5))
print(multiply(2, 5))
# use . syntax to go down a directory to run methods
print(shopping.shopping_cart.buy('apple'))
print(buy('banana'))

# imported files return their name when they contain print(__name__)
# when the statement is not imported, but run directly from the file it will return "__main__"

# wont run because buy method was imported from shopping cart and not the main module
if __name__ == "__main__":
    buy('strawberry pi')


def add(num1, num2):
    return num1 + num2


# will run because add method was not imported, but run from main file
if __name__ == "__main__":
Example #7
0
import utility
import shopping.shopping_cart as shop
from shopping.shopping_cart import buy
import random


def multiply2(item):
    return item**2


if __name__ == '__main__':
    print('changes made')

else:
    print(__name__)
    print(buy('shoes'))
    print(utility.multiply2(25))

print(utility.multiply2(10))
print(random.randint(1, 100))
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 22 11:48:09 2020

@author: saura
"""
from utilities import *
from shopping import shopping_cart



# print(utilities)    # gives error
print(mult(4,10))
print(divide(52,3))

# print(shopping)    # gives error
print(shopping_cart)
print(shopping_cart.buy('banana'))