LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-19-2011, 06:46 AM   #1
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Rep: Reputation: 16
Python Package


I've written a Python package.

Relative to the module calling it there's a directory named say 'blob', inside that is an empty file named '__init__.py', and another file named 'blobby.py', in that is one function:
Code:
def test():
	print("hello")
	return
Hopefully it'll be obvious to you, but I can't remember... But why is it not working and i'm getting the following error?

Quote:
AttributeError: 'module' object has no attribute 'test'
 
Old 04-19-2011, 07:01 AM   #2
WackyDreamer
LQ Newbie
 
Registered: Mar 2011
Distribution: ubuntu
Posts: 5

Rep: Reputation: Disabled
import
 
Old 04-19-2011, 07:20 AM   #3
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Original Poster
Rep: Reputation: 16
Sorry, yes, import has been called, and it is indicated as found by the error.

Code:
import blob.blobby
Which works... if I use:

Code:
blob.blobby.test()
(this call didn't seem to work before, but is now)


However this is what i'm actually using:

Code:
b= __import__("blob.blobby")
b.test()
Which is still throwing the followong error:
Quote:
AttributeError: 'module' object has no attribute 'test'
 
Old 04-19-2011, 07:30 AM   #4
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Original Poster
Rep: Reputation: 16
This works!

Code:
b= __import__("blob.blobby")
b.blobby.test()
as so does this...
Code:
b = __import__('blob.blobby', globals(), locals(), [], -1)
http://docs.python.org/library/funct...tml#__import__
 
Old 04-19-2011, 08:19 AM   #5
brazilnut
Member
 
Registered: Nov 2007
Posts: 113

Original Poster
Rep: Reputation: 16
That may work but I can't use it...

I need it like this...
Code:
b= __import__("blob.blobby")
b.test()
Arh... This works...

Code:
p= __import__("blob.blobby")
exec ("p."+"blobby"+".test()")
Thanks to this thread...
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python package deployment tool tank junior Linux - Newbie 1 07-06-2010 01:57 PM
How can I uninstall a python package installed with python setup.py install? milomak Linux - Software 1 11-16-2009 09:22 PM
Do you know something about mandatory PYTHON package?? madani Linux - Software 1 03-13-2009 08:24 AM
Where can I get the python-uno package? ccico Debian 2 01-19-2006 03:14 AM
Uninstall a python package danesp Linux - Newbie 8 06-01-2005 11:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration