需要将相应数值转换为相应英文类别

转换前的图:

转换后的图

错误代码:

f = open('/home/xbwang/Desktop/intend.txt','r')
trans = 'Error'
for lines in f:if(line=='1'):
        trans = 'Weather'
    if(line=='2'):
        trans = 'Good'
    if(line=='3'):
        trans = 'Greeting'
    if(line=='4'):
        trans = 'HowTo_AddOfficialBot'
    if(line=='5'):
        trans = 'HowTo_AddPersonalBot'
    if(line=='6'):
        trans = 'HowTo_AutoReply'
    if(line=='7'):
        trans = 'HowTo_BotUsage'
    if(line=='8'):
        trans = 'HowTo_Buy'
    if(line=='9'):
        trans = 'HowTo_ChangeBotProfile'
    if(line=='10'):
        trans = 'HowTo_ChangeLogo'
    if(line=='11'):
        trans = 'HowTo_Complaint'
    if(line=='12'):
        trans = 'HowTo_CreateBot'
    if(line=='13'):
        trans = 'HowTo_DeleteBot'
    if(line=='14'):
        trans = 'HowTo_GetBackControl'
    if(line=='15'):
        trans = 'HowTo_Kickout'
    if(line=='16'):
        trans = 'HowTo_Stat'
    if(line=='17'):
        trans = 'HowTo_Subscribe'
    if(line=='18'):
        trans = 'IsAvailable'
    if(line=='19'):
        trans = 'IWillTry'
    if(line=='20'):
        trans = 'Ok'
    if(line=='21'):
        trans = 'Problem_BotNotWork'
    if(line=='22'):
        trans = 'Problem_FailedToAddBot'
    if(line=='23'):
        trans = 'Problem_FailedToChat'
    if(line=='24'):
        trans = 'Problem_FailedToKickout'
    if(line=='25'):
        trans = 'Problem_FailedToScanQRCode'
    if(line=='26'):
        trans = 'Question_Gongzhonghao'
    if(line=='27'):
        trans = 'Question_Hongbao'
    if(line=='28'):
        trans = 'Question_WhenCharge'
    if(line=='29'):
        trans = 'Problem_BotNotApproved'
    if(line=='30'):
        trans = 'ThankYou'
    f1 = open('/home/xbwang/Desktop/trans.txt','a')
    f1.write(trans+'\n')

文件中每行都写的Error

正确代码:

f = open('/home/xbwang/Desktop/intend.txt','r')
trans = 'Error'
for lines in f:
    line = lines[0]
    if(line=='1'):
        trans = 'Weather'
    if(line=='2'):
        trans = 'Good'
    if(line=='3'):
        trans = 'Greeting'
    if(line=='4'):
        trans = 'HowTo_AddOfficialBot'
    if(line=='5'):
        trans = 'HowTo_AddPersonalBot'
    if(line=='6'):
        trans = 'HowTo_AutoReply'
    if(line=='7'):
        trans = 'HowTo_BotUsage'
    if(line=='8'):
        trans = 'HowTo_Buy'
    if(line=='9'):
        trans = 'HowTo_ChangeBotProfile'
    if(line=='10'):
        trans = 'HowTo_ChangeLogo'
    if(line=='11'):
        trans = 'HowTo_Complaint'
    if(line=='12'):
        trans = 'HowTo_CreateBot'
    if(line=='13'):
        trans = 'HowTo_DeleteBot'
    if(line=='14'):
        trans = 'HowTo_GetBackControl'
    if(line=='15'):
        trans = 'HowTo_Kickout'
    if(line=='16'):
        trans = 'HowTo_Stat'
    if(line=='17'):
        trans = 'HowTo_Subscribe'
    if(line=='18'):
        trans = 'IsAvailable'
    if(line=='19'):
        trans = 'IWillTry'
    if(line=='20'):
        trans = 'Ok'
    if(line=='21'):
        trans = 'Problem_BotNotWork'
    if(line=='22'):
        trans = 'Problem_FailedToAddBot'
    if(line=='23'):
        trans = 'Problem_FailedToChat'
    if(line=='24'):
        trans = 'Problem_FailedToKickout'
    if(line=='25'):
        trans = 'Problem_FailedToScanQRCode'
    if(line=='26'):
        trans = 'Question_Gongzhonghao'
    if(line=='27'):
        trans = 'Question_Hongbao'
    if(line=='28'):
        trans = 'Question_WhenCharge'
    if(line=='29'):
        trans = 'Problem_BotNotApproved'
    if(line=='30'):
        trans = 'ThankYou'
    f1 = open('/home/xbwang/Desktop/trans.txt','a')
    f1.write(trans+'\n')


正确代码只比错误代码多了一行,因为从转换前文件读出的是字符串'数字'+'\n',必须将\n处理掉或者在判断中加上\n

优质内容筛选与推荐>>
1、如何在控件Button写属性Text
2、项目 02 图片上传和展示
3、IDEA插件之 Sudoku Plugin
4、MySQL中的数据类型-----日期时间
5、模块


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号





    联系我们

    欢迎来到TinyMind。

    关于TinyMind的内容或商务合作、网站建议,举报不良信息等均可联系我们。

    TinyMind客服邮箱:support@tinymind.net.cn