Re: [Tutor] Project tree

2014-11-10 Thread Danny Yoo
> Traceback (most recent call last):
>   File "E:\tests\project_name\start.py", line 1, in 
> from src import moda
>   File "E:\tests\project_name\src\moda.py", line 1, in 
> import modb
> ImportError: No module named 'modb'


Hi Wiktor,


In Python 3, imports are not relative by default.  You might need to
adjust your imports to be explicitly relative.

Concretely, within moda.py, you'll want to change:

import modb

to:

from . import modb

See: https://docs.python.org/3/tutorial/modules.html#intra-package-references
for more details.

If you have more questions, please feel free to ask!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Project tree

2014-11-10 Thread Wiktor Matuszewski

Hi,
let's assume I have this project tree:

project_name/
 |-src/
 |  |- __init__.py
 |  |- moda.py
 |  '- modb.py
 '- start.py

And individual files contain:

- modb.py: -
def hello(txt):
return "Hello " + txt + "!"

def plus1(num):
return num + 1


- moda.py: -
import modb

def hello_world():
return modb.hello("World")


- start.py: -
from src import moda, modb

print(moda.hello_world())
print(modb.plus1(41))


__init__.py is empty

(it's project for my purpose - I don't want to distribute it with pypi, 
I pulled out start.py form src folder to just run everything without 
opening src folder)


Ok, so now executing start.py works in Python 2.7(*), but doesn't work 
in Python 3.4(**). Can someone, please, explain me why? What changed 
between 2.x and 3.x versions?


*) - gives output:
Hello World!
42

**) - gives error message:
Traceback (most recent call last):
  File "E:\tests\project_name\start.py", line 1, in 
from src import moda
  File "E:\tests\project_name\src\moda.py", line 1, in 
import modb
ImportError: No module named 'modb'

--
Best regards,
Wiktor Matuszewski
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor