Re: Same import lines again and again

Imports are generally done at the beginning of a script, are global, and don't need to be repeated. Once a module is imported it essentially increases the library of functions and classes you can create, and you can access it anywhere within your program, which makes re-importing it purely redundant. For example:

import os

#standalone
print(os.path)

#in a function
def path():
    print(os.path)

path()

#in a class
class example(object):
     def __init__(self):
         print(os.path)

a = example()

In every instance, whether its on its own, in a function, or in a class, I can use the OS module anywhere I choose without having to import it ever again beyond at the beginning of the script. In the case of the classes, you could re-initialize the classes by going "a = example()" to create an entirely new instance of that class every time, again no imports necessary.

-- 
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : ashleygrobler04 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : amerikranian via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : magurp244 via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ilya via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Rastislav Kiss via Audiogames-reflector
    • ... AudioGames . net Forum — Developers room : Ethin via Audiogames-reflector

Reply via email to