Python Forum
NEWBIE HELP: How to tell Python when to use a function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
NEWBIE HELP: How to tell Python when to use a function
#3
A simple demo that is close to what you want.
#rand_pick.py
import webbrowser
import random
import os

def rand_numb():
   numb = random.randrange(1, 6)
   return numb

def pics(numb):
   for img in os.listdir():
       if numb in img:
           webbrowser.open(img)

if __name__ == '__main__':
   numb = str(rand_numb())
   pics(numb)
So in folder 5 images(pic_1.jpg, pic_2.jpg..ect).
No path is given so you have the script rand_pick.py in same folder as images.
Will random pick 1 image,and show it it browser or OS image viewer.
Reply


Messages In This Thread
RE: NEWBIE HELP: How to tell Python when to use a function - by snippsat - Dec-17-2016, 07:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python newbie laleebee 2 1,349 May-24-2022, 01:39 PM
Last Post: laleebee
  Newbie on Python syntax rud0lp20 6 2,979 Apr-21-2020, 04:26 PM
Last Post: jefsummers
  python newbie marcush929 2 2,620 Jan-01-2020, 08:06 AM
Last Post: marcush929
Smile Help needed. Python Newbie!, it will be fun. knightdea 3 2,659 Oct-13-2019, 08:50 AM
Last Post: perfringo
  Python Linting (newbie) LieveHeer 2 2,648 Jan-24-2019, 05:36 PM
Last Post: LieveHeer
  Python newbie is asking Marcus_Gondwe 4 3,448 Apr-04-2018, 11:08 AM
Last Post: Marcus_Gondwe
  Newbie ? Python 3 Input() jlgrunr 1 2,474 Feb-17-2018, 10:26 PM
Last Post: Gribouillis
  Python Newbie phylon 1 33,259 Jan-09-2018, 10:46 AM
Last Post: Gribouillis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020