我在将值写入文件时遇到以下错误.你能帮我解决一下这里的问题以及如何解决这个问题吗?
row = 649
with open(r'\\loc\dev\Build_ver\build_ver.txt','r+') as f:
f.write(row)
print row
Run Code Online (Sandbox Code Playgroud)
错误:
Traceback (most recent call last):
File "latest_rev.py", line 6, in <module>
f.write(row)
TypeError: expected a character buffer object
Run Code Online (Sandbox Code Playgroud) 当我想安装Scrapy时遇到此错误:
warning: no previously-included files found matching '*.py'
Requirement already satisfied (use --upgrade to upgrade): pyOpenSSL in /usr/local/lib/python2.7/site-packages/pyOpenSSL-0.14-py2.7.egg (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): cssselect>=0.9 in /usr/local/lib/python2.7/site-packages/cssselect-0.9.1-py2.7.egg (from Scrapy)
Requirement already satisfied (use --upgrade to upgrade): six>=1.5.2 in /usr/local/lib/python2.7/site-packages/six-1.6.1-py2.7.egg (from Scrapy)
Downloading/unpacking zope.interface>=3.6.0 (from Twisted>=10.0.0->Scrapy)
Downloading zope.interface-4.1.1.tar.gz (864kB): 864kB downloaded
Running setup.py (path:/tmp/pip_build_root/zope.interface/setup.py) egg_info for package zope.interface
warning: no previously-included files matching '*.dll' found anywhere in distribution
warning: no previously-included files matching '*.pyc' found anywhere in distribution …Run Code Online (Sandbox Code Playgroud) 我正在使用pymongo 3.2,我想在multiporcess中使用它:
client = MongoClient(JD_SEARCH_MONGO_URI, connect=False)
db = client.jd_search
with concurrent.futures.ProcessPoolExecutor(max_workers=1) as executor:
for jd in db['sample_data'].find():
jdId = jd["jdId"]
for cv in db["sample_data"].find():
itemId = cv["itemId"]
executor.submit(intersect_compute, jdId, itemId)
# print "done {} => {}".format(jdId, itemId)
Run Code Online (Sandbox Code Playgroud)
但我得到错误:
UserWarning: MongoClient opened before fork. Create MongoClient with connect=False, or create client after forking. See PyMongo's documentation for details: http://api.mongodb.org/python/current/faq.html#using-pymongo-with-multiprocessing>
Run Code Online (Sandbox Code Playgroud)
根据该文件,我已经设置connect到False,你可以看到
tf.cond和if-else有什么区别?
import tensorflow as tf
x = 'x'
y = tf.cond(tf.equal(x, 'x'), lambda: 1, lambda: 0)
with tf.Session() as sess:
print(sess.run(y))
x = 'y'
with tf.Session() as sess:
print(sess.run(y))
Run Code Online (Sandbox Code Playgroud)
import tensorflow as tf
x = tf.Variable('x')
y = tf.cond(tf.equal(x, 'x'), lambda: 1, lambda: 0)
init = tf.global_variables_initializer()
with tf.Session() as sess:
init.run()
print(sess.run(y))
tf.assign(x, 'y')
with tf.Session() as sess:
init.run()
print(sess.run(y))
Run Code Online (Sandbox Code Playgroud)
输出都是1.
这是否意味着只有tf.placeholder可以工作,而不是所有张量,例如tf.variable?我什么时候应该选择if-else条件以及何时使用tf.cond?他们之间有什么不同?
我将使用以下代码写入TFRecord文件:
writer = tf.python_io.TFRecordWriter(output_filename)
print("Creating TFRecords file at {}...".format(output_filename))
for i, row in enumerate(create_csv_iter(input_filename)):
x = example_fn(row)
writer.write(x.SerializeToString())
writer.close()
Run Code Online (Sandbox Code Playgroud)
问题在于该过程非常缓慢,因此即使在几天内也无法编写大型数据集!它只是序列化到磁盘的写入器。为什么这么慢?另一个问题是输出文件的大小比原始文件大10倍!
您知道什么方法可以加快TFRecordWriter的过程并压缩结果吗?
我想以视觉方式查看下面的结果是否是我需要的:
import nltk
sentence = [("the", "DT"), ("little", "JJ"), ("yellow", "JJ"), ("dog", "NN"), ("barked","VBD"), ("at", "IN"), ("the", "DT"), ("cat", "NN")]
pattern = """NP: {<DT>?<JJ>*<NN>}
VBD: {<VBD>}
IN: {<IN>}"""
NPChunker = nltk.RegexpParser(pattern)
result = NPChunker.parse(sentence)
Run Code Online (Sandbox Code Playgroud)
来源:https : //stackoverflow.com/a/31937278/3552975
我不知道为什么我不能漂亮_打印result.
result.pretty_print()
Run Code Online (Sandbox Code Playgroud)
错误是这样写的TypeError: not all arguments converted during string formatting。我使用Python3.5,nltk3.3。