Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
关于Python2.7编码:我真的很困惑_Python_Python 2.7_Encoding_Kivy - Fatal编程技术网

关于Python2.7编码:我真的很困惑

关于Python2.7编码:我真的很困惑,python,python-2.7,encoding,kivy,Python,Python 2.7,Encoding,Kivy,我使用Python3.6编写代码,最近我将Python3.6版更改为2.7版(因为我想将此文件转换为IOS应用程序,但到目前为止只有2.7版可以做到这一点) 这是一个问题。我在python3.6中测试了这段代码,没有问题。 但是我在2.7中运行了这个。出现了编码问题 这是我的.py文件 #-*- coding: utf-8 -*- import kivy kivy.require('1.10.0') from kivy.app import App from kivy.lang import

我使用Python3.6编写代码,最近我将Python3.6版更改为2.7版(因为我想将此文件转换为IOS应用程序,但到目前为止只有2.7版可以做到这一点)

这是一个问题。我在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'
回溯(最近一次呼叫最后一次):
文件“C:\Users\mg\Desktop\TubucTest\testtubuc.py”,第71行,在
presentation=Builder.load_文件(“testmain.kv”)
文件“C:\Users\mg\Anaconda2\lib\site packages\kivy\lang\builder.py”,第301行,在load\U文件中
返回self.load_字符串(数据,**kwargs)
文件“C:\Users\mg\Anaconda2\lib\site packages\kivy\lang\builder.py”,第400行,加载字符串
self.\u应用规则(小部件、parser.root、parser.root)
文件“C:\Users\mg\Anaconda2\lib\site packages\kivy\lang\builder.py”,第582行,在应用规则中
child=cls(\uuuu no\u builder=True)
文件“C:\Users\mg\Desktop\TubucTest\testtubuc.py”,第54行,在\uuu init中__
打开('C:/Users/mg/Desktop/Tubuc/station/동막역(1번출구)ICB164000039.txt”)作为业务信息:
IOError:[Errno 2]没有这样的文件或目录:“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)。
我怎样才能解决这个问题?谢谢您的阅读。

更改
'C:/Users/mg/Desktop/Tubuc/station/동막역(1번출구)ICB164000039.txt'
u'C:/Users/mg/Desktop/Tubuc/station/동막역(1번출구)ICB164000039.txt'
@AzatIbrakov已经尝试过了。但是仍然发生了类似的错误。IOError:[Errno 2]没有这样的文件或目录:u'C:/Users/mg/Desktop/Tubuc/station/\ub3d9\ub9c9\uc5ed(1\ubc88\ucd9c\uad6c)ICB164000039.txt'这是另一个错误,请尝试导入操作系统;打印(os.path.exists)(u'C:/Users/mg/Desktop/Tubuc/station)/동막역(1번출구)ICB164000039.txt')并检查输出是否为
@AzatIbrakov我很抱歉打扰您,但输出为假。啊,没关系!我拼错了路径!!谢谢!!