我无法测试运行我想使用的use解析器。
test.py
from css.parse import parse
data = """
em {
padding: 2px;
margin: 1em;
border-width: medium;
border-style: dashed;
line-height: 2.4em;
}
p { color: red; font-size: 12pt }
p:first-letter { color: green; font-size: 200% }
p:first-line { color: blue }"""
for rule in parse(data):
print (rule)..gives a error:
Traceback (most recent call last):
method <module> in test.py at line 1
from css.parse import parse
method <module> in test.py at line 6
from . import css, csslex, cssyacc
method <module> in test.py at line 8
from . import serialize
method <module> in test.py at line 6
from . import css
ImportError: cannot import name css目录结构(/User/nimbuz/Documents/python31 31):
/Users/nimbuz/Documents/python31/**csspy**/
|
+-- css/ (*has __init__.py*)
|
+-- uri/ (*has __init__.py*)
|
+-- test.pyprint(sys.path)显示:
['/Users/nimbuz/Documents/python31/csspy', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python31.zip', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/plat-darwin', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/lib-dynload', '/Library/Frameworks/Python.framework/Versions/3.1/lib/python3.1/site-packages']发布于 2009-11-22 05:11:07
下面是我刚刚测试过的几个步骤。
C:/TEST/C:/TEST/,因此现在存在C:/TEST/css/和C:/TEST/uri/文件夹。ply文件夹到C:/TEST/css/中,因此C:/TEST/css/ply/文件夹现在存在。C:/TEST/中创建了包含以下内容的C:/TEST/
从css.parse导入解析打印dir(解析)C:\TEST>test.py
['__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__doc__', '__format__', '__get__', '__getattribute__', '__globals__', '__hash__', '__init__', '__module__', '__name__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'func_closure', 'func_code', 'func_defaults', 'func_dict', 'func_doc', 'func_globals', 'func_name']希望这能有所帮助。对不起,如果我的解释是错误的。
发布于 2009-11-22 04:49:59
您有__init__.py文件在cssparser和css目录中,以将目录转换为包吗?其中是否有一个函数或类名为css/parse.py的parse文件?当您执行sys.path时,您的test.py上是什么,当前目录是什么?所有这些问题都可能很重要,你没有给我们答案,所以很难有任何具体的帮助!-)
发布于 2009-11-22 06:09:31
python 3版本的css-py
http://ifile.it/v32n70s/css.zip
https://stackoverflow.com/questions/1777838
复制相似问题