我有以下段落,我正在尝试计算python中的行数,单词数和char数。 Зython新手。我也试过但是向我展示了一些行:1
Gene expression in mammals is regulated by noncoding elements that can affect physiology and disease, yet the functions and target genes of most noncoding elements remain unknown. We present a high-throughput approach that uses clustered regularly interspaced short palindromic repeats (CRISPR) interference (CRISPRi) to discover regulatory elements and identify their target genes. We assess >1 megabase of sequence in the vicinity of two essential transcription factors, MYC and GATA1, and identify nine distal enhancers that control gene expression and cellular proliferation. Quantitative features of chromatin state and chromosome conformation distinguish the seven enhancers that regulate MYC from other elements that do not, suggesting a strategy for predicting enhancer–promoter connectivity. This CRISPRi-based approach can be applied to dissect transcriptional networks and interpret the contributions of noncoding genetic variation to human disease.
这是我的代码:我想计算段落中的行数。
的
的file_to_load = "raw_data/paragraph_1.txt"
with open(file_to_load, 'r') as reader:
num_line = 0
num_word = 0
num_letter = 0
for row in reader:
print(row)
wordsList = row.split()
num_line += 1
num_word += len(wordsList)
num_letter += len(row)
print(num_line)
print(num_word)
print(num_letter)
的
答案 0 :(得分:0)
你的问题是:
我想计算段落中的行数。
我直接运行您的代码而没有更改,并输出:
1
130
968
您粘贴的文字是一行文字,因此行数= 1是准确的。如果您在文本中添加了一个硬回车\n
,那么它将输出2。
答案 1 :(得分:0)
您提供的段落包含1行。文本文档中的行数等于“换行符”('\ n')的数量。因此,在您的情况下,段落的全部内容都存储在文件的第一行。
答案 2 :(得分:-1)
import re
NumberOfLines=len(re.split('\n',yourFile))
NumberOfWords=len(re.split(' ',yourFile))
NumberOfChars=len(yourFile)