def application(environ, start_response): results = [] results.append(str(moduletest.ageofqueen)) results.append(printhello()) results.append(hello()) helloWorld = HelloWorld() results.append(helloWorld.sayHello()) user = Users() results.append(user.sayHello()) article = Articles() results.append(article.sayHello()) output = "<br/>".join(results) print output # build the response body possibly using the environ dictionary response_body = output # HTTP response code and message status = '200 OK' # These are HTTP headers expected by the client. # They must be wrapped as a list of tupled pairs: # [(Header name, Header value)]. response_headers = [('Content-Type', 'text/html'), ('Content-Length', str(len(response_body)))] # Send them to the server using the supplied function start_response(status, response_headers) # Return the response body. # Notice it is wrapped in a list although it could be any iterable. return [response_body]
def test_module(): assert str(ageofqueen) == "78" assert printhello() == "hello"
# IMPORTS ANOTHER MODULE see moduletest.py import moduletest print(moduletest.ageofqueen) cfcpiano = moduletest.Piano() cfcpiano.printdetails() # Or one can import only the wanted objects from the module from moduletest import ageofqueen from moduletest import printhello # now try using them (with or without module name) print(ageofqueen) # prints: 78 print(moduletest.ageofqueen) # prints: 78 printhello() # prints: hello moduletest.printhello() # prints: hello # Attributes and module objects ''' __dict__ __name__ __file__ __doc__ ''' from moduletest import ageofqueen as AgeOfQueen # alias print(AgeOfQueen) # prints: 78 print(moduletest.__name__) # prints: moduletest print(moduletest.__file__) # prints: /..../moduletest.pyc print(moduletest.__dict__) # prints: #{'numberone': 1,
import os os.chdir('Lesson_2__workingFiles') sys.path.append(os.getcwd()) import moduletest print ageofqueen # Traceback (most recent call last): # File "<input>", line 1, in <module> # NameError: name 'ageofqueen' is not defined print moduletest.ageofqueen # 78 printhello() # Traceback (most recent call last): # File "<input>", line 1, in <module> # NameError: name 'printhello' is not defined moduletest.printhello() # hello Piano.printdetails() # Traceback (most recent call last): # File "<input>", line 1, in <module> # NameError: name 'Piano' is not defined moduletest.Piano.printdetails() # Traceback (most recent call last):
### mainprogam.py ### IMPORTS ANOTHER MODULE import moduletest print moduletest.ageofqueen cfcpiano = moduletest.Piano() cfcpiano.printdetails() ### IMPORT ITEMS DIRECTLY INTO YOUR PROGRAM # import them from moduletest import ageofqueen from moduletest import printhello # now try using them print ageofqueen printhello()
""" import moduletest print("Print Hello Value : " , moduletest.printhello()) print("Age of Queen : ", moduletest.ageofqueen) print("Multipled Value : ", moduletest.timesfour(100)) cfcpiano = moduletest.Piano("Electric", "100 Cms", 12000, 20) #Constructor or Creating Object cfcpiano.printdetails() """ from moduletest import ageofqueen from moduletest import printhello from moduletest import timesfour from moduletest import Piano # now try using them print("Age of Queen : ", ageofqueen) print("Print Hello Value : ", printhello()) print("Multipled Value : ", timesfour(100)) cfcpiano = Piano("Electric", "100 Cms", 12000, 20) #Constructor or Creating Object cfcpiano.printdetails()
#!/usr/bin/env python from moduletest import ageofqueen from moduletest import printhello from mod import shape as s import math if __name__ == '__main__': print(ageofqueen) printhello() rectangle = s.Shape(100, 45) print(rectangle.area()) print(rectangle.perimeter()) rectangle.describe("A wide rectangle, more than twice\ as wide as it is tall") rectangle.scaleSize(0.5) print(rectangle.area()) rectangle.showInfo() print(dir(math))
def test_module(): assert str(moduletest.ageofqueen) == "78" assert moduletest.printhello() == "hello" cfcpiano = moduletest.Piano() cfcpiano.printdetails()
""" import moduletest print("Print Hello Value : " , moduletest.printhello()) print("Age of Queen : ", moduletest.ageofqueen) print("Multipled Value : ", moduletest.timesfour(100)) cfcpiano = moduletest.Piano("Electric", "100 Cms", 12000, 20) #Constructor or Creating Object cfcpiano.printdetails() """ from moduletest import ageofqueen from moduletest import printhello from moduletest import timesfour from moduletest import Piano # now try using them print("Age of Queen : " , ageofqueen) print("Print Hello Value : " , printhello()) print("Multipled Value : ", timesfour(100)) cfcpiano = Piano("Electric", "100 Cms", 12000, 20) #Constructor or Creating Object cfcpiano.printdetails()
########################## import os os.chdir('Lesson_2__workingFiles') sys.path.append(os.getcwd()) import moduletest print ageofqueen # Traceback (most recent call last): # File "<input>", line 1, in <module> # NameError: name 'ageofqueen' is not defined print moduletest.ageofqueen # 78 printhello() # Traceback (most recent call last): # File "<input>", line 1, in <module> # NameError: name 'printhello' is not defined moduletest.printhello() # hello Piano.printdetails() # Traceback (most recent call last): # File "<input>", line 1, in <module> # NameError: name 'Piano' is not defined moduletest.Piano.printdetails() # Traceback (most recent call last): # File "<input>", line 1, in <module>