我在from functools import partial
def chunkify(pfin, max_lines=1500):
with open(pfin, 'r', encoding='utf-8') as f:
chunk_start = f.tell()
chunk_size = 0
done = True
for idx, l in enumerate(iter(f.readline, '')):
chunk_size += len(l)
done = False
if idx != 0 and idx % max_lines == 0:
yield chunk_start, chunk_size
done = True
chunk_start = f.tell()
chunk_size = 0
if not done:
yield chunk_start, chunk_size
def process_batch(pfin, chunk_start, chunk_size):
with open(pfin, 'r', encoding='utf-8') as f:
f.seek(chunk_start)
chunk = f.read(chunk_size).splitlines()
batch = list(filter(None, chunk))
return batch
if __name__ == '__main__':
fin = r'data/100000-ep+gutenberg+news+wiki.txt'
process_func = partial(process_batch, fin)
lines_n = 0
prev_last = ''
for start, size in chunkify(fin):
lines = process_func(start, size)
if not lines:
continue
# print first and last ten sentences of batch
for line in lines[:10]:
print(line)
print('...')
for line in lines[-10:]:
print(line)
print('\n')
lines_n += len(lines)
print(lines_n)
文件中设置了1024M:
php.ini
我已将其设置在memory_limit = 1024M
文件中:
.htaccess
我已将其设置在<IfModule mod_php7.c>
php_value memory_limit 1024M
</IfModule>
文件中:
wp-config.php
但是我在Wordpress管理区域的插件页面上仍然出现以下错误:
define( 'WP_MAX_MEMORY_LIMIT' , '1024M');
define( 'WP_MEMORY_LIMIT', '1024M' );
是的,所有文件都在我的Wordpress安装的根目录中。
答案 0 :(得分:0)
有时主机会控制这些文件,即使您对其进行更新,在某些情况下它们也永远不会执行,因此它们最好还原为原始文件,因此最好与您的主机联系并要求它们为您提供服务器控制权或增加其存储限制结束。
答案 1 :(得分:0)
您是否重新启动了Web服务?是问题。
答案 2 :(得分:0)
要检查是否成功增加了php.ini文件中的memory_limit,可以创建phpinfo()函数来查看您的php设置。请参考此链接https://www.a2hosting.com/kb/developer-corner/php/view-php-settings