我有一个文本文件说
text1 text2 text text
text text text text
Run Code Online (Sandbox Code Playgroud)
我期待首先计算文件中的字符串数(全部由空格分隔),然后输出前两个文本.(正文1文字2)
有任何想法吗?
在此先感谢您的帮助
编辑:这是我到目前为止:
>>> f=open('test.txt')
>>> for line in f:
print line
text1 text2 text text text text hello
>>> words=line.split()
>>> words
['\xef\xbb\xbftext1', 'text2', 'text', 'text', 'text', 'text', 'hello']
>>> len(words)
7
if len(words) > 2:
print "there are more than 2 words"
Run Code Online (Sandbox Code Playgroud)
我遇到的第一个问题是,我的文本文件是:text1 text2文本文本文本
但当我拉出单词的输出时,我得到:['\ xef\xbb\xbftext1','text2','text','text','text','text','hello']
'\ xef\xbb\xbf来自哪里?
今天是我在Python的第一天,一直在经历问题.我正在研究的是"编写一个简短的程序,从操作系统中提取当前的日期和时间,然后按照以下格式将其打印在屏幕上:日,月,年,格林威治标准时间的当前时间.证明它有效. "
我打算使用pytz,所以使用easy_install pytz
它安装在我的网站包中(pytz-2012d-py2.7.egg)
这是我能够导入模块的正确目录吗?
在我的python shell中,我使用了pytz导入时区,
"ImportError: No module named pytz"
有任何想法吗?提前致谢
我无权更改 /etc/krb5.conf 中的文件,因此作为解决方案,我设置了 KRB5_CONFIG。
导出 KRB5_CONFIG=/home/user/keytab/krb5.conf
echo-ing 此变量验证此路径是否已设置,但当我尝试 kinit 时,它仍在使用 /etc/krb5.conf 文件。
我还需要设置什么吗?我需要设置任何特定权限或重新启动任何服务吗?
我这样做的原因是因为 Hadoop 不支持非默认领域。