如何解决“集合”模块中找不到“ nametuple”的问题?

时间:2019-08-21 01:23:26

标签: python python-3.x python-2.7 kivy kivy-language

我正在运行python 3.7的

im,我正在尝试创建一个文件,用作我制作的loginpage.py的运算符,但是当我运行operator.py文件时,它给出了很多错误,但未指定问题指定的一个问题是AttributeError:模块'collections'没有属性'namedtuple'

我尝试在pycharm制作的环境中运行它 检查所有语法可能一切看起来不错 我尝试在pything 2.2至3.6中运行

from kivy.uix.boxlayout import BoxLayout


class OperatorWindow(BoxLayout):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)


class OperatorApp(App):
    def build(self):
        return OperatorWindow()


if __name__ == "__main__":
    oa = OperatorApp()
    oa.run()

#code ends here

Traceback (most recent call last):
  File "D:/OneDrive/Udemy/My own apps/pos/operator/operator.py", line 1, in <module>
    from kivy.app import App
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\__init__.py", line 32, in <module>
    import shutil
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\shutil.py", line 10, in <module>
    import fnmatch
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\fnmatch.py", line 14, in <module>
    import re
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\re.py", line 125, in <module>
    import functools
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\functools.py", line 21, in <module>
    from collections import namedtuple
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\collections\__init__.py", line 21, in <module>
    from operator import itemgetter as _itemgetter, eq as _eq
  File "D:\OneDrive\Udemy\My own apps\pos\operator\operator.py", line 1, in <module>
    from kivy.app import App
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\site-packages\kivy\app.py", line 316, in <module>
    from inspect import getfile
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\inspect.py", line 35, in <module>
    import dis
  File "C:\Users\T\AppData\Local\Programs\Python\Python37-32\lib\dis.py", line 184, in <module>
    _Instruction = collections.namedtuple("_Instruction",
AttributeError: module 'collections' has no attribute 'namedtuple'

从此开始的期望是打开一个名为operator的窗口,该窗口将为空白,但不会打开

我在上面的代码中输入的错误消息

1 个答案:

答案 0 :(得分:3)

调用模块<table class="table table-bordered table-sm small"> <thead class="thead-dark"> <tr> <th>Jan</th> <th>Feb</th> <th>Mar</th> <th>Apr</th> <th>May</th> <th>Jun</th> <th>Jul</th> <th>Aug</th> <th>Sep</th> <th>Oct</th> <th>Nov</th> <th>Dec</th> </thead> </tr> <?php $html = ""; require 'db.php'; $sqlview="SELECT * FROM booking"; $myData = mysqli_query($con, $sqlview); //loop thru the dates (in your case the SQL results) while($viewrecord = mysqli_fetch_array($myData)){ //get the month number (Jan = 1, Feb = 2 etc.) $monthNumber = date_parse_from_format("y-m-d", $viewrecord['date'])['month']; //return A tr for each result $html .= '<tr>'; //a td for each month for($i = 0; $i < 12; $i++){ $html .= '<td>'; //if column is current month, display date $html .= ($monthNumber === ($i+1)) ? $viewrecord['date'] : ""; $html .= '</td>'; } $html .= '<tr>'; } echo $html; ?> <table> 并不是一个好的选择。 它在标准库中隐藏了一个模块。

关键困难在于operator 现在将不会启用通常的功能。

考虑将所有内容下推一级, 因此您以import operator的身份访问模块 而不只是myapp.operator。 或者,您可以重命名为operator, 或重命名operator1.py目录。