您的位置:首页 > 编程语言 > Python开发

python 新手之 文件import问题

2011-03-02 21:32 429 查看
初学python不知如何引入py文件

 

 

我写的爬虫函数。catchInfo.py

# coding=gb2312

from lxml import *
import lxml.html
import urllib2
import lxml.html as H
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def catchInfoByUXpath(url,xstr):
c=urllib2.urlopen(url)
f=c.read()
doc=H.document_fromstring(f)
result=doc.xpath(xstr)
return result

url="http://www.baidu.cn"
xstr='/html/body/div/p[2]/a'


 

但是当我在console上运行python时,找不到文件里面的函数和变量

 

dir(catchInfo)
import catchInfo
url
#报错
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'url' is not defined


 

 

according  c++ coding experience,i find  maybe use  catchInfo reference

>>> catchInfo.url
'http://www.baidu.cn'
>>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息