0

A very simple question, in my program i use:

import resources

resources.py is a file were i load all my assets and then i must write :

example = resources.image1

if i load my image in the main file i just write :

example = image1

My question is : is there a simple way to avoid writing each time example = resources.image1, so just write example = image1

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
GabrielT
  • 397
  • 6
  • 17

1 Answers1

0

Yes.

from resources import *

Should make

example = image1

work just fine. However, as someone commented, this isn’t the best method. It makes it a nightmare to work out what libraries everything came from, and the code becomes harder to understand. Another way to reduce typing is:

import resources as r

This will allow you to type:

example = r.image1

If you only want to access image1, then you can just do:

from resources import image1
example=image1
Programmer S
  • 429
  • 7
  • 21
  • 1
    You shouldn't use wildcard imports if you want to comply with PEP 8: https://legacy.python.org/dev/peps/pep-0008/#imports – user3483203 Apr 18 '18 at 18:56
  • I agree, but wildcard imports answered the question. Answering the question should take priority over advice and explanation. – Programmer S Apr 19 '18 at 05:33
  • A better answer would have been: `from resources import image1` That answers the question and is correct code. – user3483203 Apr 19 '18 at 13:12
  • @chrisz I know, but you already gave that answer as a comment to the question. I’m not sure why you didn’t give it as an answer, but there is no point giving duplicate answers without any extra explanation. – Programmer S Apr 19 '18 at 15:47
  • Then maybe no point in answering at all :) – user3483203 Apr 19 '18 at 15:48