首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加密字符串4

加密字符串4
EN

Stack Overflow用户
提问于 2014-04-05 11:14:46
回答 2查看 47关注 0票数 0
代码语言:javascript
复制
def main():
  inFile = open ('input.txt', 'r')
  fileContent = inFile.read()
  choice = input('Do you want to encrypt or decrypt? (E / D): ')
  for i in fileContent:
    if (choice == 'E'):
      for i in range(0, len(str), 2):
        even_str = str[i]
      for i in range(1, len(str), 2):
        odd_str = str[i]
      outFile = open("output.txt", "w")
      outFile.write(even_str)
      outFile.write(odd_str)
      outFile.write(encrypted_str)
      print('even_str = ',even_str)
      print('odd_string = ',odd_str)
      print('encrypted_str = ',encrypted_str)
      outfile.close()
    if (choice != 'E' and choice != 'D'):
      print ('')
      print ('Wrong input. Bye.')
      return
  inFile.close()
main()

尝试加密字符串并将奇数和偶数字符加在一起,但我一直收到此错误。我设置了一个要测试的文件,但它似乎无法工作。

代码语言:javascript
复制
Traceback (most recent call last):
  File "C:/Python33/CS303E/Cipher.py", line 41, in <module>
    main()
  File "C:/Python33/CS303E/Cipher.py", line 24, in main
    for i in range(0, len(str), 2):
TypeError: object of type 'type' has no len()
EN

回答 2

Stack Overflow用户

发布于 2014-04-05 11:17:22

当您应该使用fileContent (包含输入字符串的变量的名称)时,您可以继续使用str (表示字符串的类型的名称)。

票数 1
EN

Stack Overflow用户

发布于 2014-04-05 11:16:55

str是一种类型(字符串,你也可以把它看作是构造函数),它是语言的一部分,你没有这样的变量。也许你想要这样的东西:

代码语言:javascript
复制
for i in range(0, len(fileContent), 2):
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22876122

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档