1

我正在学习 python 并且对 ctype 和 ctypes 感到困惑。在讲座中,讲师使用 ctype,我搜索了它,但只有 ctypes 模块结果。所以我不确定 ctype 和 ctypes 在 python 中是否相同。在官方文档中,我必须 import ctypes,但是我没有导入它。

这是我的代码,

from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import cgi
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

def do_POST(self):
        try:
            if self.path.endswith('/edit'):
                ctype, pdict = cgi.parse_header(
                    self.headers.getheader('content-type')
                )
                if ctype=='multipart/form-data':
                    fields = cgi.parse_multipart(self.rfile, pdict)
                    messagecontent = fields.get('newRestaurantName')
                    restaurantIDPath = self.path.split("/")[2]
                    myRestaurantQuery= session.query(Restaurant).filter_by(
                        if=restaurantIDPath).one()
                    if myRestaurantQuery!=[]:
                        myRestaurantQuery.name = messagecontent[0]
                        session.add(myRestaurantQuery)
                        session.commit()
                        self.send_response(301)
                        self.send_header('Content-type','text/html')
                        self.send_header('Location','/restaurants')
                        self.end_headers()

如果它们不同,我应该寻找哪个类别来比较两者?提前致谢!

4

2 回答 2

4

ctypes 模块是一种与 C(语言)类型交互的方式,而您在问题中所指的 ctype 代表内容类型。见这里https://docs.python.org/2/library/cgi.html

于 2016-06-01T00:28:08.613 回答
0

在讲座中,讲师使用ctype,我搜索了它

在什么情况下?仅仅因为名称出现在某处的代码中并不意味着您将从网络搜索中获得有意义的结果。您需要知道为什么选择该名称以及该程序员的意图是什么。

于 2016-06-01T01:18:40.870 回答