关于python 2.7编码:我真的很困惑

时间:2018-08-13 13:21:29

标签: python python-2.7 encoding kivy

我由python 3.6编码,最近我将python 3.6版更改为2.7(因为我想将此文件转换为IOS应用程序,但到目前为止只有2.7version可以做到)。

这是问题。我在python3.6中测试了此代码,没有问题。 但是我在2.7 ..中运行它。出现了编码问题。

这是我的.py文件

#-*- coding: utf-8 -*-

import kivy
kivy.require('1.10.0')
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.animation import Animation
from kivy.clock import Clock
#from kivy.config import Config #윈도우크기고정
#Config.set('graphics', 'resizable', 0)
from kivy.core.window import Window #윈도우크기설정
Window.size = (486, 650) 

class Loading_Screen(Screen):
    def __init__(self, **kwargs):
        super(Loading_Screen, self).__init__(**kwargs)
        Clock.schedule_once(self.callNext, 2) 

    def callNext(self,dt): 
        self.manager.current = 'Before_First_Screen'

class Load_BusInfo():
    pass

class Before_First_Screen(Screen):
    pass

class First_Screen(Screen):
    pass

class Test_Screen(Screen):
    pass

###################목적지_역명#####################

class DTN_TECHNOPARK(Screen): 
    pass

class DTN_BITZONE(Screen): 
    pass

class DTN_INUSTATION(Screen): 
    pass

class Bus_Information(Screen):
    def __init__(self, **kwargs):
        super(Bus_Information, self).__init__(**kwargs)

        with open('C:/Users/mg/Desktop/Tubuc/station/동막역(1번출구)ICB164000039.txt') as businfo:
            Businfo= [] 
            nolinenum=businfo.readline()
            while nolinenum!='': 
                Businfo.append(nolinenum)
                leftstations = (businfo.readline().rstrip('\n') + ' 정거장'.rstrip('\n'))
                lefttime = (businfo.readline().rstrip('\n') + ' 초'.rstrip('\n'))
                nolinenum = businfo.readline().rstrip('\n')
                Businfo.append(leftstations)
                Businfo.append(lefttime)
            self.businfolist = Businfo
            self.lenbil = int(len(Businfo))
            self.numberoflist = int(len(Businfo)/3)

class ScreenManagement(ScreenManager):
    pass

presentation = Builder.load_file("testmain.kv")

class TubucApp(App):
    def build(self):
        return presentation

TubucApp().run()

这是错误内容。

 Traceback (most recent call last):
   File "C:\Users\mg\Desktop\TubucTest\testtubuc.py", line 71, in <module>
     presentation = Builder.load_file("testmain.kv")
   File "C:\Users\mg\Anaconda2\lib\site-packages\kivy\lang\builder.py", line 301, in load_file
     return self.load_string(data, **kwargs)
   File "C:\Users\mg\Anaconda2\lib\site-packages\kivy\lang\builder.py", line 400, in load_string
     self._apply_rule(widget, parser.root, parser.root)
   File "C:\Users\mg\Anaconda2\lib\site-packages\kivy\lang\builder.py", line 582, in _apply_rule
     child = cls(__no_builder=True)
   File "C:\Users\mg\Desktop\TubucTest\testtubuc.py", line 54, in __init__
     with open('C:/Users/mg/Desktop/Tubuc/station/동막역(1번출구)ICB164000039.txt') as businfo:
 IOError: [Errno 2] No such file or directory: 'C:/Users/mg/Desktop/Tubuc/station/\xeb\x8f\x99\xeb\xa7\x89\xec\x97\xad(1\xeb\xb2\x88\xec\xb6\x9c\xea\xb5\xac)ICB164000039.txt'

동막역(1번출구)被视为\ xeb \ x8f \ x99 \ xeb \ xa7 \ x89 \ xec \ x97 \ xad(1 \ xeb \ xb2 \ x88 \ xec \ xb6 \ x9c \ xea \ xb5 \ xac )在最后一行。

我该如何解决?谢谢您的阅读。

0 个答案:

没有答案