## Python Programming Tutorial – 21 – Modules

GitHub – https://github.com/buckyroberts
reddit – https://www.reddit.com/r/thenewboston/
Support – https://www.patreon.com/thenewboston
thenewboston – https://thenewboston.com/

• Views:201,460 views
• Rating:
• Categories:
• Tags:

Christopher Sullivan says:

Love all the videos and I use them to learn a lot thank you very much! But, I have to ask what’s with using tuna all the time? lol

Dark Seid says:

Is random a library file? I see its directory is lib. Why is it a module instead?

Illuminati242 says:

Ok got my program to work great in Python 2.7.12 but not on 3.5.2.

here is my program.

#lottery number generator for pick 4!!
#First we import sample from the random library
import random
from random import sample

#Now we create our group/list on numbers to draw from!

numbers = (1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,)

#Create and input for users to request number of draws they need.

x = input(‘How many numbers would you like today? : ‘)

#Now we define how many balls to draw by creating our defination generate_draw

def generate_draw(balls=4,population=numbers):
return (sample(population,k=balls))

#now we create a defination for multiple draws and call it.

def multiple_draws(count=x):
results = []
for i in range(count):
results.append(generate_draw())
return results

#now we simply print the desired results!
print multiple_draws()

can you please lend some insight on what is suposed to be done? I know print is now a function but i can not get the result to print! please help if you can.

Paweł Brysch says:

import skrypt
skrypt.funkcja()
//
random.randrange(a1,a2) – losowa liczba z przedziału

Vaarunay Kaushal says:

bucky’s gotta be obsessed with tuna or something

Vishal Vashistha says:

How to share my code with you, if I am facing some problem while loading .mat file and using it for loop.

candylantis says:

I have a problem, my configurations are all messed up and everytime I want to use something, I have to make a configuration for it, and then switch to it, and I think its affecting my modules because they never work.

Ashish Kumar says:

Reached to 21. 😀
Cant wait to complete it as soon as possible 🙂

harsh soni says:

whenever i use specific function from another file it also takes all print functions from that file i don’t know why this things happen!!

Hazem gamal says:

5 min untill pycharm starts

anand pandya says:

Do the modules have to be under the same project file (in the directory) to import them?

miyaclaire says:

great tutorial,and he really likes tuna!:)

Dorio Gee says:

i wrote:
import random
x = random.randrange(1, 1000)
print(x)

and it shows error like
“C:Program FilesPython 3.5python.exe” C:/Users/User/PycharmProjects/untitled3/mainn.py
Traceback (most recent call last):
File “C:/Users/User/PycharmProjects/untitled3/mainn.py”, line 1, in
import random
File “C:Program FilesPython 3.5librandom.py”, line 40, in

from types import MethodType as _MethodType, BuiltinMethodType as _BuiltinMethodType
File “C:Program FilesPython 3.5libtypes.py”, line 166, in

import functools as _functools
File “C:Program FilesPython 3.5libfunctools.py”, line 21, in

from collections import namedtuple
File “C:Program FilesPython 3.5libcollections__init__.py”, line 11, in

from keyword import iskeyword as _iskeyword
ImportError: cannot import name ‘iskeyword’

Process finished with exit code 1

Younes PhD Henni says:

can anyone write a code to check how many tuna is there is these tutorials ?!

Michael Wang says:

what if the file name has spaces and nuumbers in iT?

vinay vanteddu says:

cant wait to know how tuna fish tastes like

robert aspelin says:

figured out the tuna.fish before bucky said it. feeling so smart!

Batman says:

I created two file level2 and level3 when I import the function level2 file in level3

like this:

import Level2

Level2.printo()

it says ImportError: No module named ‘Level2’

Raptr3x says:

He forgot to say that if import filename doesn’t work you can use module os so just say import os and when you want to import file just say os.system(“python filename.py”) and it will import the file just as he show

Nick Pangburn says:

Just wondering, if you did random.randrange(1,100)… Out of those numbers, are there any you would never see? Like how unity 3d’s random function will never select the last number, (e.g. Random.Range(0,2); it would never select 0)

Thuy Vuong says:

I typed this code but I didn’t get a random number, it asked me for a number and then I enter one, and then it ends? What am I doing wrong?

import tuna
import random

tuna.fish()
x= random.randrange(1,1000)
print(x)

Akhil Reghunath says:

Hey bucky i reached #21 but am having the following error for this same module lesseon

Traceback (most recent call last):
File “C:/MyPycharm/Files/main.py”, line 3, in
tuna.fish()
AttributeError: module ‘tuna’ has no attribute ‘fish’

pls help me out to figure it out

Ruben S says:

hero

maheema gajaraj says:

Could someone please explain the difference between randrange and randint?

poop :3

Yarden Altmann says:

someone must check how meny times bucky use the word tuna in all this videos lol

Abhi Patel says:

I named new python file as ‘try’ and it shows error in importing the file, Is there any specific reason for this?
Other names are working as normal.

Mahfoudh Abdu says:

Hi sir , i have problem with my code it run correctly without any errors but i do not get an image as appears with you!!

Nitin Sharma says:

Can you recommend me some Econometrics packages and libraries

Satya Prakash says:

hey bucky please increase the font size …

Russian Retard says:

You must really like tuna.

Andrei Florea says:

list = array
module = library

deal with it.

Soufiane Kre says:

do you like tuna this much?

Fernando Maxwell says:

Is there anyone here know, how to import another module from different folder in python?

crownkiwifactoryNZ says:

Bucky is Awesome!

Amha Aygoda says:

i tried importing the file but its not working on my mac. i did exactly the same thing that you did but it’s not working for me. yellp

Samuel Kariuki says:

The font is too small! its difficult to see.

Raptr3x says:

Did he just wrote “feesh”? :”D

Mark van Brummelen says:

This is so much fun! So tempting to do another one ahhh!!! I need to sleep 2!

Andy Kim says:

1. Do files that you import need to be in the same directory as main?

2. Can main be called anything else without messing up the program?

Mister D says:

C:UsersDanielAppDataLocalProgramsPythonPython36-32python.exe C:/Users/Daniel/PycharmProjects/test2/main.py
Traceback (most recent call last):
File “C:/Users/Daniel/PycharmProjects/test2/main.py”, line 1, in
import tuna
ModuleNotFoundError: No module named ‘tuna’

Process finished with exit code 1

Darryl Mann says:

Not very random. Gets the same number 236 every time I watch this video,.