-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[xdoctest][task 330] reformat example code with google style in python/paddle/base/data_feed_desc.py #57137
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
python/paddle/base/data_feed_desc.py
Outdated
.. code-block:: python | ||
|
||
import paddle.base as base | ||
f = open("data.proto", "w") | ||
print >> f, 'name: "MultiSlotDataFeed"' | ||
print >> f, 'batch_size: 2' | ||
print >> f, 'multi_slot_desc {' | ||
print >> f, ' slots {' | ||
print >> f, ' name: "words"' | ||
print >> f, ' type: "uint64"' | ||
print >> f, ' is_dense: false' | ||
print >> f, ' is_used: true' | ||
print >> f, ' }' | ||
print >> f, ' slots {' | ||
print >> f, ' name: "label"' | ||
print >> f, ' type: "uint64"' | ||
print >> f, ' is_dense: false' | ||
print >> f, ' is_used: true' | ||
print >> f, ' }' | ||
print >> f, '}' | ||
f.close() | ||
data_feed = base.DataFeedDesc('data.proto') | ||
>>> import paddle.base as base | ||
>>> f = open("data.proto", "w") | ||
>>> print >> f, 'name: "MultiSlotDataFeed"' | ||
>>> print >> f, 'batch_size: 2' | ||
>>> print >> f, 'multi_slot_desc {' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "words"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "label"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, '}' | ||
>>> f.close() | ||
>>> data_feed = base.DataFeedDesc('data.proto') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段应该不能算是示例,把 .. code-block:: python
改为 .. code-block:: text
,原来代码的地方不用加 >>>
,保持原样就行,即使加了也没法运行 ~
python/paddle/base/data_feed_desc.py
Outdated
.. code-block:: python | ||
|
||
import paddle.base as base | ||
data_feed = base.DataFeedDesc('data.proto') | ||
data_feed.set_batch_size(128) | ||
data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense | ||
data_feed.set_use_slots('wd') # The slot named 'wd' will be used | ||
>>> import paddle.base as base | ||
>>> data_feed = base.DataFeedDesc('data.proto') | ||
>>> data_feed.set_batch_size(128) | ||
>>> data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense | ||
>>> data_feed.set_use_slots('wd') # The slot named 'wd' will be used | ||
|
||
Finally, the content can be dumped out for debugging purpose: | ||
|
||
.. code-block:: python | ||
|
||
print(data_feed.desc()) | ||
>>> print(data_feed.desc()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上 ~
python/paddle/base/data_feed_desc.py
Outdated
Example: | ||
.. code-block:: python | ||
|
||
import paddle.base as base | ||
f = open("data.proto", "w") | ||
print >> f, 'name: "MultiSlotDataFeed"' | ||
print >> f, 'batch_size: 2' | ||
print >> f, 'multi_slot_desc {' | ||
print >> f, ' slots {' | ||
print >> f, ' name: "words"' | ||
print >> f, ' type: "uint64"' | ||
print >> f, ' is_dense: false' | ||
print >> f, ' is_used: true' | ||
print >> f, ' }' | ||
print >> f, ' slots {' | ||
print >> f, ' name: "label"' | ||
print >> f, ' type: "uint64"' | ||
print >> f, ' is_dense: false' | ||
print >> f, ' is_used: true' | ||
print >> f, ' }' | ||
print >> f, '}' | ||
f.close() | ||
data_feed = base.DataFeedDesc('data.proto') | ||
data_feed.set_batch_size(128) | ||
>>> import paddle.base as base | ||
>>> f = open("data.proto", "w") | ||
>>> print >> f, 'name: "MultiSlotDataFeed"' | ||
>>> print >> f, 'batch_size: 2' | ||
>>> print >> f, 'multi_slot_desc {' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "words"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "label"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, '}' | ||
>>> f.close() | ||
>>> data_feed = base.DataFeedDesc('data.proto') | ||
>>> data_feed.set_batch_size(128) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果这里作为示例出现的话,需要把里面的这些 print 修改一下,改为正常 python 的写文件语句~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
统一一下吧,改成可以跑的
我一小时前 review 一半干别的去了,结果回来后你已经 review 了 😂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github 时好时坏 ... ... 趁着好用 review 一下 ~
python/paddle/base/data_feed_desc.py
Outdated
>>> import paddle.base as base | ||
>>> f = open("data.proto", "w") | ||
>>> print >> f, 'name: "MultiSlotDataFeed"' | ||
>>> print >> f, 'batch_size: 2' | ||
>>> print >> f, 'multi_slot_desc {' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "words"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "label"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, '}' | ||
>>> f.close() | ||
>>> data_feed = base.DataFeedDesc('data.proto') | ||
>>> data_feed.set_dense_slots(['words']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/base/data_feed_desc.py
Outdated
>>> import paddle.base as base | ||
>>> f = open("data.proto", "w") | ||
>>> print >> f, 'name: "MultiSlotDataFeed"' | ||
>>> print >> f, 'batch_size: 2' | ||
>>> print >> f, 'multi_slot_desc {' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "words"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "label"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, '}' | ||
>>> f.close() | ||
>>> data_feed = base.DataFeedDesc('data.proto') | ||
>>> data_feed.set_use_slots(['words']) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/base/data_feed_desc.py
Outdated
>>> import paddle.base as base | ||
>>> f = open("data.proto", "w") | ||
>>> print >> f, 'name: "MultiSlotDataFeed"' | ||
>>> print >> f, 'batch_size: 2' | ||
>>> print >> f, 'multi_slot_desc {' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "words"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, ' slots {' | ||
>>> print >> f, ' name: "label"' | ||
>>> print >> f, ' type: "uint64"' | ||
>>> print >> f, ' is_dense: false' | ||
>>> print >> f, ' is_used: true' | ||
>>> print >> f, ' }' | ||
>>> print >> f, '}' | ||
>>> f.close() | ||
>>> data_feed = base.DataFeedDesc('data.proto') | ||
>>> print(data_feed.desc()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
python/paddle/base/data_feed_desc.py
Outdated
@@ -33,26 +33,26 @@ class DataFeedDesc: | |||
|
|||
.. code-block:: python |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放在 Examples:
之下吧,记得整体加缩进
python/paddle/base/data_feed_desc.py
Outdated
>>> print >> f, ' }' | ||
>>> print >> f, '}' | ||
>>> f.close() | ||
>>> data_feed = base.DataFeedDesc('data.proto') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这段代码换成 python3 写法吧
with open(xxx) as f:
f.write('')
f.write('')
Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
python/paddle/base/data_feed_desc.py
Outdated
>>> import paddle.base as base | ||
>>> with open("data.proto", "w") as f: | ||
... f.write('name: "MultiSlotDataFeed"') | ||
... f.write('batch_size: 2') | ||
... f.write('multi_slot_desc {') | ||
... f.write(' slots {') | ||
... f.write(' name: "words"') | ||
... f.write(' type: "uint64"') | ||
... f.write(' is_dense: false') | ||
... f.write(' is_used: true') | ||
... f.write(' }') | ||
... f.write(' slots {') | ||
... f.write(' name: "label"') | ||
... f.write(' type: "uint64"') | ||
... f.write(' is_dense: false') | ||
... f.write(' is_used: true') | ||
... f.write(' }') | ||
... f.write('}') | ||
>>> data_feed = base.DataFeedDesc('data.proto') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
写文件少写了换行符 ~~~ 🤣
python/paddle/base/data_feed_desc.py
Outdated
... f.write(' is_dense: false') | ||
... f.write(' is_used: true') | ||
... f.write(' }') | ||
... f.write('name: "MultiSlotDataFeed"\\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
咦?为啥要 \\n
呀,\\n
最后呈现的不是 \n
么?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我这边试了下可以过呀,直接使用 convert-doctest doctest python/paddle/base/data_feed_desc.py
我这边直接改好啦
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
喔喔我知道了
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convert-doctest 和 CI 提取 docstring 原理不同,一个是字符串裁剪,一个是运行时通过 __doc__
获取,所以 \n
自然就是换行了,这里用 r
raw string 即可两者都能跑(大概?看看 CI 结果)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
正解! \n
在 docstring 中是要用 r
~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢大佬们!学到嘞~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTMeow 🐾
…n/paddle/base/data_feed_desc.py (PaddlePaddle#57137) * [Doctest]fix No.330, test=docs_preview * Update python/paddle/base/data_feed_desc.py Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com> * [Doctest]fix No.330, test=docs_preview * [Doctest]fix No.330, test=docs_preview * [Doctest]fix No.330, test=docs_preview * `\\n` -> `\n` * use raw string --------- Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
PR types
Others
PR changes
Others
Description
修改如下文件的示例代码,使其通过
xdoctest
检查:python/paddle/base/data_feed_desc.py
预览:
Related links
@sunzhongkai588 @SigureMo @megemini