Weird import problem of other files in the src

A forum for general discussion of the Python programming language.

Weird import problem of other files in the src

Postby BapeNAsians » Fri Jan 03, 2014 4:32 am

I have a directory of py src files that depend on each other.

I barely know python but will know it fully in a few hours or so from pythons main tutorial. I already know a few languages and I messed with this language for a few days a few years ago when I was 19.

Anyways, the code says

Code: Select all
from . import blahblah


Blahblah is modules or py files in the directory of the directory I'm in

When compiling it can't find these. Anyways I know from shell experience that "." Means current directory.

Any help?
BapeNAsians
 
Posts: 46
Joined: Fri Jan 03, 2014 4:25 am

Re: Weird import problem of other files in the src

Postby metulburr » Fri Jan 03, 2014 4:57 am

When compiling it can't find these

what is the full traceback?
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1509
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Weird import problem of other files in the src

Postby Tcll » Fri Jan 03, 2014 6:18 am

I thought '.' was the parent directory... (I could be very wrong as I don't use it much)

what I use...
I have API.py which calls it's modules from data/
so for all the import statements of the modules in the data/ directory, I have to use 'import data.module as module'
(the initialization level is from the directory of API.py)

oh yea, and if you don't, make sure you have '__init__.py' in your directory
User avatar
Tcll
 
Posts: 100
Joined: Wed Jan 01, 2014 6:36 pm

Re: Weird import problem of other files in the src

Postby stranac » Fri Jan 03, 2014 11:54 am

You shouldn't be using relative imports at all.
I recommend you read this:
Python Packages and You

Also note that a directory is only a package if it has an __init__.py file
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1212
Joined: Thu Feb 07, 2013 3:42 pm


Return to General Discussions

Who is online

Users browsing this forum: W3C [Linkcheck] and 1 guest