TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login CONVERT LENGTH
login CONVERT TEMPERATURE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login WORK CALCULATOR
login CALCULATE LIFE

Python 3 programming language, learn python, tutorial

Previous articlePage bottomNext article  ALL TOPICS

Python 3. extentions, modules

 1. Module file - module.py. The file is inthe same folder as hello.py file:
# Fibonacci numbers module

def fib(n):   
# write Fibonacci series up to n
    a, b = 0, 1
    while b < n:
        print(b, end=' ')
        a, b = b, a+b
    print()

def fib2(n):
# return Fibonacci series up to n
    result = []
    a, b = 0, 1
    while b < n:
        result.append(b)
        a, b = b, a+b
    return result

2. Import of module. hello.py file:
import module

print ( "module.fib: ") ;  module.fib(1000);

print ( "module.fib2: " ,  module.fib2(100));

print ("module name: "  ,  module.__name__);

Result:
module.fib:
1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987
module.fib2:  [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
module name:  module

3. More import examples. Importing names directly:
from module import fib, fib2

fib(500)

4. Full set of functions:
from module import *

fib(500)

Task 1. Please import two modules with overlapping functions. What will happen when calling these functions?
 
5. Exampe. The list contains the names of all the modules, variables and functions that are defined in a module:
import module, sys

print (dir(module))

print (dir(sys)) 

6. Reload module, if changed:
import sys

print (sys.path)

reload (sys)

print (sys.path)

#reload (sys.path)


Previous articlePage topNext article  ALL TOPICS


Vitalij:
import winsound
import time
for x in range(1,11):
print("TURN ON SOUND")
soundfile = "c:/Windows/Media/Windows Unlock.wav"
winsound.PlaySound(soundfile, winsound.SND_FILENAME|winsound.SND_ASYNC)
time.sleep(1)

winsound.Beep(440, 500)
winsound.Beep(440, 500)
winsound.Beep(440, 500)
winsound.Beep(349, 350)
winsound.Beep(523, 150)
winsound.Beep(440, 500)
winsound.Beep(349, 350)
winsound.Beep(523, 150)
winsound.Beep(440, 1000)
winsound.Beep(659, 500)
winsound.Beep(659, 500)
winsound.Beep(659, 500)
winsound.Beep(698, 350)
winsound.Beep(523, 150)
winsound.Beep(415, 500)
winsound.Beep(349, 350)
winsound.Beep(523, 150)
winsound.Beep(440, 1000)


2015-11-18 11:40:07
Andrius:
1. 
def sum( arg1, arg2 ):
   total = arg1 + arg2
   return total
----------------------------------------------------
import module
arg1=int(input("Iveskite pirmaji nari: "))
arg2=int(input("Iveskite antraji nari: "))
print(module.sum(arg1,arg2))

2.
import os
os.system('#pasirinkta spalva')


2015-11-19 07:55:49

 Use username: Guest, Anonymous, Programmer






QUOTES:
The person who makes a success of living is the one who see his goal steadily and aims for it unswervingly. That is dedication.
Cecil B. DeMille
Older men declare war. But it is youth that must fight and die.
Herbert Clark Hoover
Let your heart guide you. It whispers, so listen closely.
The Land Before Time