Пример #1
0
>>> def greeting(name):
	print('Hello, ' + name)
	import mymodule
	mymodule.greeting('Jonathan')
	person1 = {
	'name': 'John',
	'age': 36,
	'country': 'Norway'
	}
	import mymodule
	a = mymodule.person1['age']
	print(a)
Пример #2
0
# Create a Module
# To create a module just save the code you want in a file with the file extension .py:

# Save this code in a file named mymodule.py

>>> def greeting(name):
      print("Hello, " + name)

    
# Use a Module : Now we can use the module we just created, by using the import statement:

# Import the module named mymodule, and call the greeting function:
>>> import mymodule

>>> mymodule.greeting("Jonathan")

# Note: When using a function from a module, use the syntax: module_name.function_name.

# Variables in Module
# The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc):

# Save this code in the file mymodule.py

>>> person1 = {
      "name": "John",
      "age": 36,
      "country": "Norway"
    }
# Import the module named mymodule, and access the person1 dictionary:
Пример #3
0
    def __init__(self, name, age):
        self.name = name
        self.age = age


# python modules

    def myfunc(self):
        print("Hello my name is " + self.name)

p1 = Person("Reuben", 19)
p1.myfunc()

import mymodule

mymodule.greeting("penalope")
import mymodule

a = mymodule.person1["age"]
print(a)

import platform

x = platform.system()
print(x)

import platform

x = dir(platform)
print(x)
Пример #4
0
import mymodule

mymodule.greeting("Jonathan")

a = mymodule.person1['age']
print(a)

#Import only person1 dictionary from the module

from mymodule import person1

print(person1["age"])

#Create an alias for mymodule called mx:

import mymodule as mx

a = mx.person1["age"]
print(a)

#Built-in Modules
import platform

x = platform.system()
print(x)

##dir() function
#lists allfunction name in a module

import platform
import mymodule as mx

mx.greeting("Thomas")

a = mx.person["age"]
print(a)

# Naming a Module
# You can name the module file whatever you like, but it must have the file extension .py

# Re-naming a module
# you can create an alias when you import a module, by using the "as" keyboard

# Built-in Modules
# These are several built-in modules in python, which you can import whenever you like


print("\nTask 2")
# import and use the platform module
import platform

x = platform.system()
print(x)

# Using the dir() function names (or variable names) in a module. The dir() function
# The dir() function can be used on all modules, also the ones you create yourself
print("\nTask 3")
x = dir(platform)
print(x)

# tyring dir on my own python file
Пример #6
0
To create a module just save the code you want in a file with the file extension **.py**
"""

def greeting(name):
  print("Hello, " + name)

"""Save this code in a file named **mymodule.py**

##**Use a Module**

Now we can use the module we just created, by using the ** import ** statement:
"""

import mymodule

mymodule.greeting("Joey")

"""You can use any Python source file as a module by executing an import statement in some other Python source file. 

The import has the following syntax −

**import module1[, module2[,... moduleN]**


When the interpreter encounters an import statement, it imports the module if the module is present in the search path. A search path is a list of directories that the interpreter searches before importing a module. For example, to import the module support.py, you need to put the following command at the top of the script

##**Variables in Module**

The module can contain functions, as already described, but also variables of all types (arrays, dictionaries, objects etc)
"""
Пример #7
0
import mymodule

mymodule.greeting("ALi")
Пример #8
0
import mymodule, function

mymodule.greeting("Awan")

function.my_function("Muhammad", "Farhan")

function.my_function2("Farhan", "Andi", "Awan")

print(mymodule.nama)

mymodule.greeting(mymodule.nama)
Пример #9
0
import mymodule
import mymodule as mx
from mymodule import person1

# There are several built-in modules in Python, which you can import whenever you like.
# Import and use the platform module
import platform

mymodule.greeting("Jonathan")  # Hello Jonathan

a = mymodule.person1["age"]
print(a)  # 36

a = mx.person1["age"]  # Using aliasing
print(a)

x = platform.system()
print(x)  # Windows

# There is a built-in function to list all the function names (or variable names) in a module.
x = dir(platform)
print(x)

print(person1['age'])  # 36
Пример #10
0
import mymodule as mm
mm.greeting("Surendra")
import mymodule

mymodule.greeting('Jeferson!')

Пример #12
0
#Use a Module

import mymodule

mymodule.greeting("George")
Пример #13
0
#!/usr/bin/env python3.7

import mymodule

mymodule.greeting("jona")

a = mymodule.person1["age"]

print(a)
Пример #14
0
# Python Modules - Part 1

# Use a Module
import mymodule

mymodule.greeting("Zinab")

print(mymodule.person["name"])
Пример #15
0
import mymodule as m
from mymodule import person1
import datetime as d
m.greeting("pin")
print(person1["country"])
x = d.datetime.now()
print(x)
Пример #16
0
from mymodule import person1, greeting
import platform
import datetime
import json

x = platform.system()
y = dir(platform)
print(x)
# print(y)
print(greeting("Brajesh"))
print("Hey, " + person1["name"])
print(datetime.datetime.now())
print(json.dumps(person1))
Пример #17
0
cookbook = int(
    input("What recipe would you like to make? (Please state the number)\n"))
if cookbook == 1:
    import mymodule as mx
    mx.greeting("Nana")

    a = mx.person1["age"]
    print(a)

    mx.omin(2)

    mx.tmin(4)

    mx.cmin(10)

    mx.smallest(0)
else:
    print("Updates pending")
Пример #18
0
def module_greetings(name):
        greeting = mymodule.greeting(name)

        return greeting
Пример #19
0
import mymodule
mymodule.greeting("John")

a = mymodule.person1["age"]
print(a)
Пример #20
0
import mymodule
print(mymodule.greeting("simran"))
from mymodule import greeting
print(greeting("simran"))
from mymodule import greeting,age
print(greeting("simran"),"Age=",age)


Пример #21
0
    global z
    z = 300

myfuncGKeyW()
print(z)

z=200
def myfuncGKeyW1():
    global z
    z = 350
myfuncGKeyW1()
print(z)

# Day 50:Modules
import mymodule
mymodule.greeting("Razan")
print(mymodule.person["Age"])

# Day 51:Modules
import mymodule as mx
print(mx.person["Name"])

import platform
print(platform.system())
print(platform.python_version())
print(dir(platform))

# Day 52:Datetime
import datetime

date=datetime.datetime.now()
import mymodule

mymodule.greeting("Aniket")
Пример #23
0
from mymodule import greeting
greeting()










Пример #24
0
import mymodule
mymodule.greeting("Deepa")

Пример #25
0
import mymodule, function

# mymodule.greeting("Farhan")

# function.my_function("Farhan", "Mardadi")

print(mymodule.nama)

mymodule.greeting(mymodule.nama)
Пример #26
0
import mymodule as mx
import platform
#import only part from a module
from mymodule import greeting

a = mx.info["name"]
print(a)

#device sysytem
a = platform.system()
print(a)

#sow all the function and var
b = dir(platform)
print(b)

greeting("Sara")
Пример #27
0
    return x


myclass = MyNumbers()
myiter = iter(myclass)

print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))
print(next(myiter))

#This is a module example
import mymodule

mymodule.greeting("Leo")

#This is a math example
import math

x = math.pi
print(x)

#This is an example from Converting python object to JSON
import json

x = {
    "name":
    "John",
    "age":
    30,
Пример #28
0
import mymodule

mymodule.greeting("Sahil Rajput.")

print("Hello, world!")
print("Hello, world!")
print("Hello, world!")
x = 1
if x == 1:
    # indented four spaces;
    print("Boom")
Пример #29
0
import mymodule
import platform
from mymodule import person1

print(person1["age"])
x = platform.system()
print(x)
mymodule.greeting("Nancy")
Пример #30
0
import mymodule

mymodule.greeting("Simran")