Ejemplo n.º 1
0
#!/usr/bin/env python

# Module import demo

# Basic module import demo

import module1, module2         # comma separated list of modules (we can also use multiple import statements)

s = "a quick brown fox jumped over a lazy dog"

# Now we can use functions from imported modules.
# We must refer to modules' individual namespaces
# followed by the dot (.) operator and the function name

print s
print module1.reverse(s)
print module1.split(s)
print module2.bracket(s)
print module2.titlecase(s)
Ejemplo n.º 2
0
#!/usr/bin/env python

from module1 import split,reverse       # puts module1.split, module1.reverse into the current namespace
from module2 import titlecase           # puts module2.titlecase into the current namespace

s = "a quick brown fox jumped over a lazy dog"

print s
print reverse(s)            # module1. before reverse() would now be an error!
print split(s)              # no module1.split() anymore
print titlecase(s)          # no module2.titlecase() anymore