Python3 : import

Andrew Z formisc at gmail.com
Fri Jul 7 16:12:46 EDT 2017


On Friday, July 7, 2017 at 4:00:51 PM UTC-4, Andrew Z wrote:
> this has bee driving me nutz for the past few hours.
> 2 modules are in the same directory. I want to be able to use them both:
>> [code]
>> [az at hp tst1]$ pwd
> /home/az/Dropbox/work/Prjs/tst1
>> [az at hp tst1]$ ls -l
> total 16
> -rw-rw-r--. 1 az az 66 Jul 7 12:58 db.py
> -rw-rw-r--. 1 az az 182 Jul 7 15:54 uno.py
> [az at hp tst1]$ 
> [az at hp tst1]$ 
> [az at hp tst1]$ cat ./db.py 
>> class DB():
> 	def __init__(self):
> 		print("I'm DB")
>> [az at hp tst1]$ cat ./uno.py 
> from . import db
>> class Uno():
> 	def __init__(self):
> 		print("I'm uno")
> 		self.db = db.DB()
>> 	def printing(self):
> 		print("Uno.printing DB")
>>> if __name__ == '__main__':
> 	uno = Uno()
>> [az at hp tst1]$ 
> [az at hp tst1]$ 
> [az at hp tst1]$ python3 ./uno.py 
> Traceback (most recent call last):
> File "./uno.py", line 1, in <module>
> from . import db
> SystemError: Parent module '' not loaded, cannot perform relative import
>> [/code]
>>> Much obliged.

[az at hp tst1]$ python3 --version
Python 3.5.3


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /