471,348 Members | 1,189 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,348 software developers and data experts.

Accessing a variable

9
I am a beginner using python2.5.1.
In my project, I have a views.py in uscom.users which has
uid=2
def disp_list():
return uid

In another module forms.py , also in uscom.users, I am trying to access that value.
from uscom.users.views import *
def id_val():
key_id = views.disp_list()
return key_id

This doesn't work. Returns error that views is not defined. Am I doing something wrong? Please help.
Sep 12 '07 #1
4 1077
ilikepython
844 Expert 512MB
I am a beginner using python2.5.1.
In my project, I have a views.py in uscom.users which has
uid=2
def disp_list():
return uid

In another module forms.py , also in uscom.users, I am trying to access that value.
from uscom.users.views import *
def id_val():
key_id = views.disp_list()
return key_id

This doesn't work. Returns error that views is not defined. Am I doing something wrong? Please help.
Yes, since you import everything (*), you don't need to acces it with the module name:
Expand|Select|Wrap|Line Numbers
  1.     key_id = disp_list()
  2.  
If you want to use "views.disp_list()":
Expand|Select|Wrap|Line Numbers
  1. import uscom.user.views as views
  2.  
If you don't have the as part you will have to use this:
Expand|Select|Wrap|Line Numbers
  1. key_id = uscom.users.views.disp_list()
  2.  
Sep 12 '07 #2
anitn
9
Hi..
thanks for the reply. Am i posting in the wrong forum? If yes please forgive. I am learning django and these methods I did try. All return errors.
Exception Value: cannot import name views
thank you once again
Sep 12 '07 #3
ilikepython
844 Expert 512MB
Hi..
thanks for the reply. Am i posting in the wrong forum? If yes please forgive. I am learning django and these methods I did try. All return errors.
Exception Value: cannot import name views
thank you once again
Try just:
Expand|Select|Wrap|Line Numbers
  1. import views
  2.  
I think since the file is in uscom.user you don't need to specify that.

Btw, you are not posting in the wrong forum.
Sep 13 '07 #4
anitn
9
Thank you alot for the reply. yes Its working now...
Sep 13 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Jurek Dabrowski | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.