精华内容
下载资源
问答
  • for..in loops iterate over the entire prototype chain, which is virtually never what you want. 意思是使用for..in会遍历整个原型链,这样不是很好的实现方法,推荐使用Object.keys formRules:{ name:true,...

    for..in loops iterate over the entire prototype chain, which is virtually never what you want. 

    意思是使用for..in会遍历整个原型链,这样不是很好的实现方法,推荐使用Object.keys

    formRules: {
      name: true,
      cardType: true,
      certificateNo: true
     },
     formData: {
      name: '',
      certificateType: '',
      certificateNo: ''
     }

    源代码:

    for (const key in this.formData) {
    	 if (!this.formData[key]) { this.formRules[key] = false; valid = false }
    	 if (this.formData[key]) this.formRules[key] = true
    }

    修改后的代码:

    Object.keys(this.formData).forEach(key => {
     if (!this.formData[key]) { this.formRules[key] = false; valid = false }
     if (this.formData[key]) this.formRules[key] = true
    })

     

    展开全文
  • pyhton 总提示 name ‘XXX’ is not defined 的解决办法 language_survey.py #-*-coding:GBK -*- #11.5 from survey import AnonymousSurvey #定义一个问题,并创建一个表示调查的AnonymousSurvey对象 question =...

    pyhton 总提示 name ‘XXX’ is not defined 的解决办法

    language_survey.py

    #-*-coding:GBK -*- 
    #11.5
    
    from survey import AnonymousSurvey 
    #定义一个问题,并创建一个表示调查的AnonymousSurvey对象
    question = "What language did you first learn to speak?" 
    my_survey = AnonymousSurvey(question)
    
    #显示问题并存储答案
    my_survey.show_question()
    print("Enter 'q' at any time to quit.\n") 
    while True: 
    	response = input("Language: ") 
    	if response == 'q':
    		break 
    	my_survey.store_response(response) 
    # 显示调查结果
    print("\nThank you to everyone who participated in the survey!") 
    my_survey.show_results()
    
    

    调用的survey

    #-*-coding:GBK -*- 
    #11.4
    class AnonymousSurvey():
    	"""收集匿名调查问卷的答案"""
    	def __init__(self,question):
    		"""存储一个问题,并为存储答案做准备""" 
    		self.question=question
    		self.responses=[]
    	
    	def show_question(self):
    		"""显示调查问卷""" 
    		print(question)	
    	
    	def store_response(self,new_response):
    		"""存储单份调查答卷""" 
    		self.responses.append(new_response)
    		
    	def show_results(self):
    		"""显示收集到的所有答卷""" 
    		print("Survey results:")
    		for response in responses:
    			print('- '+ response)
    
    

    如果把language_survey.py的代码放入survey.py中,提示
    name ‘responses’ is not defined

    首先以为是代码中间有空格,找了两天,结果不时,不定时在哪个文件中出错,
    总是提示
    name ‘responses’ is not defined
    name ‘question’ is not defined

    后来经过网上询问,结果是这里出的问题:

        def show_question(self):
                """显示调查问卷""" 
                print(question)          -- self.question
    
        def show_results(self):
                """显示收集到的所有答卷""" 
                print("Survey results:")
                for response in responses:   -- self.responses
                        print('- '+ response)
    

    在定义class中,需要用self声明的,下面用到的,一定要带self.

    希望大家不要犯同样的错误。

    展开全文
  • NameError: name 'question' is not defined Process finished with exit code 1 异常分析:名称question未被定义 异常处理:不能直接引用或者遍历形参, question在代码段一第9行已经定义为变量形参,引用输出...

    代码段一:

    """
    Author:  yeahthon
    Date   :  2019-08-09  12:28:47
    E-mail:  yeahthon@163.com
    """
    class AnonymousSurvey():
        """收集匿名调查问卷的答案"""
    
        def  __init__(self, question):
            """储存一个问题,并为储存答案做准备"""
            self.question = question
            self.responses = []
    
        def  show_question(self):
            """显示调查问卷"""
            print(question)
    
        def  store_response(self,new_response):
            """储存单份调查问卷"""
            self.responses.append(new_response)
    
        def  show_results(self):
            """显示收集到的所有答案"""
            print("Survey result:")
            for  response in responses:
                print('- ' + response)
    

    代码段二:

    """
    Author:  yeahthon
    Date   :  2019-08-09  12:50:20
    E-mail:  yeahthon@163.com
    """
    from survey import  AnonymousSurvey
    
    #定义一个问题,并创建一个表示调查的AnonymousSurvey对象
    question = "what language did you first learn to speak?"
    my_survey = AnonymousSurvey(question)
    
    #显示问题并储存答案
    my_survey.show_question()
    print("Enter 'q' at any time to quit.\n")
    while True:
        response = input("Language: ")
        if  response == 'q':
            break
        my_survey.store_response(response)
    
    #显示调查结果
    print("\nThink you to everyone cho participated in the survey!")
    my_survey.show_results()
    

    运行时显示异常:

    G:\python\untitled1\venv\Scripts\python.exe G:/python/untitled1/language_survey.py
    Traceback (most recent call last):
      File "G:/python/untitled1/language_survey.py", line 13, in <module>
        my_survey.show_question()
      File "G:\python\untitled1\survey.py", line 16, in show_question
        print(question)
    NameError: name 'question' is not defined
    
    Process finished with exit code 1
    

    异常分析:名称question未被定义
    异常处理:不能直接引用或者遍历形参, question在代码段一第9行已经定义为变量形参,引用输出时应当填入相应实参,即将代码段一第16行 question 改为 self.question,第25行 responses 改为 self.responses。

    展开全文
  • web server:What you get is what I put

    千次阅读 2011-10-21 17:10:07
    def getChild(self,name,request): self.filename = name #print name if name == "b": print "name:b" request.setHeader("Cache-Control", "max-age=100") return self def render_GET(self,request): ...
    #!/usr/bin/env python
    from twisted.web import server,resource
    from twisted.internet import reactor
    import twisted
    import time
    import mimetypes
    import os
    from cStringIO import StringIO
    
    class Root(resource.Resource):
      def __init__(self):
        fd = open("google.jpg" , "rb")
        self.jpg = fd.read()
        resource.Resource.__init__(self)
        fd.close()
      def getChild(self,name,request):
        self.filename = name
        #print name
        if name == "b": 
          print "name:b"
          request.setHeader("Cache-Control", "max-age=100")
        return self
      def render_GET(self,request):
        content_type = "text/html"
        #request.setHeader("Cache-Control", "max-age=1000")
        request.setHeader("Cache-Control", "private")
        request.setHeader("Cache-Control", "no-cache")
        data = StringIO()
        print "in request 1"
        print "file:%s"%(self.filename)
        if self.filename != "":
          filename_len = len(self.filename)
          #print filename_len
          if filename_len > 4:
            #print filename_len
            filename_ext = self.filename[filename_len-4:filename_len]
            if filename_ext == ".jpg":
              request.setHeader("Content-Type", "image/jpeg")
              #print filename_ext
              data.write(self.jpg)
            else:
              if filename_ext == ".htm":
                #data.write("is htm")
                filename_pre = self.filename[0:filename_len-4]
                html = self.gen_img_request(filename_pre) 
                data.write(html)
              else:
                if filename_len > 5:
                  filename_ext = self.filename[filename_len-5:filename_len]
                  if filename_ext == ".html":
                    filename_pre = self.filename[0:filename_len-5]
                    #print filename_pre
                    html = self.gen_img_request(filename_pre) 
                    data.write(html)
    
            #if filename_ext == ".html":
          else:
            request.setHeader("Content-Type", content_type)
            data.write("test abc")
        else:
          request.setHeader("Content-Type", content_type)
          data.write("test abc")
    
        #print request
        print "in request 2"
        return data.getvalue()
      
      def gen_img_request(self, filename_pre):
        data = ""
        try:
          value = int(filename_pre)
          cnt = value 
          while cnt > 0:
            #data += """<img src= %d.jpg height=10 weight=10 />"""%(cnt)
            #data += """<img src= %d.jpg height=0 weight=0 />"""%(cnt)
            data += """<img src= %d.jpg />"""%(cnt)
            data += """<h1> %d </h1>"""%(cnt)
            cnt -= 5
        except:
          data = "this is a test page"
        return data
    
      def render_POST(self,request):
        return self.render_GET(request)
    
    root = Root()
    site = server.Site(root)
    reactor.listenTCP(80, site)
    reactor.run()


    展开全文
  • 流利说 Level 3 全文

    万次阅读 多人点赞 2019-05-22 10:51:17
    Greasy foods have a lot of calories, so don’t eat them if you want to lose weight. Healthy foods are usually nature and don’t include dangerous chemical. Fruits and vegetables are examples of ...
  • Hi guys, I want to share things what I know about windows azure, thank very much!  ---This is an article about Microsoft Public Cloud- Windows Azure's knowledge sharing, thanks. 1. Compute: Web ...
  • 跟web端经常打交道,难免遇到一些难懂的名词...看看uri:A URI can be further classified as a locator, a name, or both. The term "Uniform Resource Locator" (URL) refers to the subset of URIs that, in additio
  • 关于samba的作用在这里我就不作详细的解说了,由于这几天重装了ubuntu...The specified network name is no longer available”这样的一个小问题,卸载,重新安装samba,又重新配置文件,问题依然存在,但是在windows
  • When It comes to a handsome men, I want to introduce a famous singer, whose name is Jay zhou, a pop music singer. When I was studying in middle school, I listened his music. At the beginning, I did .....
  • NameError: global name 'reduce' is not defined

    千次阅读 2018-09-14 15:20:18
    I'm new to Python. Would you please tell me what's wrong with the following code? When I run it, I got an error ...NameError: global name 'reduce' is not defined". I asked Goolge but it's use...
  • docker run --name mysql -p 3306:3306 -v /root/bo/data/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 -it wzj/mysql docker: Error response from daemon: Conflict. The container name "/mysql&...
  • What is DDS? 什么是DDS?(Data Distribute Service,数据分发服务) 关键字:数据分发服务 DDS The Proven Data Connectivity Standard for the Industrial Interet of Things 经验证的工业物联网数据连接标准 ...
  • In your opinion, what is the most important characteristic (for example, honesty,intelligence, a sense of humor) that a person can have to be successful in life?
  • what is RCS/RCS-e

    千次阅读 2014-02-07 18:24:22
    but it would be hard to get a 'short/tangible' understanding of what it really is. Is RCS a kind of specification ? Is it a kind of software package ? Is it a kind of name for a technology ?   ...
  • What Is NXDOMAIN?

    千次阅读 2015-04-06 13:39:02
    What is NXDOMAIN? How does nxdomain affects my browsing? Explains the relationship between NXDOMAIN and DNS Hijacking. A DNS server is used to translate a domain name into an IP address or vise ver
  • I’ve previously written an article on how to network two computers together that are running Windows ... I’ve also written about a cool program called WiPeer that lets you connect two computers wir
  • 转载地址:https://code.google.com/p/volatility/wiki/FullInstallation... In this post I will share with you my first experiences working with Volatility 2.4. As first use I installed it on a OS X machine
  • http://stackoverflow.com/questions/26993903/a-virtualbox-machine-with-the-name-homestead-already-exists If you're planning to use multiple VMs ...
  • 严重: Servlet.service() for servlet action threw exception...java.lang.RuntimeException: file name '....' is too long ( > 100 bytes) at org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.p
  • What is 4K, UHD, QFHD, FHD, and HD ?

    万次阅读 2018-01-14 21:07:42
    SMARTGADGETSHUB.COM Home Cameras Computers Drones Storage Devices About Us Technical Information ...What is 4K, UHD, QFHD, FHD, and HD ? June 2, 2015by Smart
  • Ubuntu 16.04 虚拟机安装 VMware Tools

    千次阅读 2018-10-29 21:31:15
    Ubuntu 16.04 虚拟机安装 VMware Tools 1. 虚拟机 -> 安装 VMware Tools 2. 开启虚拟机 -> 虚拟机 -> 安装 VMware Tools ...open-vm-tools is a set of services and modules that enable sever
  • What is The Rule of Three?

    千次阅读 2012-07-01 11:48:43
    首先摆明问题: 1、拷贝一个对象是什么意思? 2、拷贝构造函数和拷贝赋值运算符又都是什么?... std::string name;...http://stackoverflow.com/questions/4172722/what-is-the-rule-of-three
  • 通常我们在 info.plist 中,可以看到类似如下配置:Bundle Display Name - ${PRODUCT_NAME} Executable File - ${EXECUTABLE_NAME} ... Bundle nameis folder name, where your app (including ex
  • Even though you only specified one, what is likely happening is that there is one specified in a .config file in a parent directory. Since .config files inherit configuration from parents, it's seeing...
  • 超基础的用Python处理文本实例

    万次阅读 2014-12-01 16:08:15
    girl:my name is lebaishi,what about you? boy:my name is wahaha. girl:i like your name. ============================================== girl:how old are you? boy:I'm 16 years old,and you? girl:I'm 14....
  • What is Vmware vCPU ?

    千次阅读 2011-07-27 15:08:19
    What is Vmware vCPU ?vmware doesn't care how many physical CPU's you have, it'll register the total core count as virtual CPU's. vCPU stands
  • However, you may simply not be aware that a more recent version is available, and that is what this lint check helps find. 参考: http://www.apkbus.com/android-246037-1-1.html?_dsign=361a7403 ...
  • 《Java语言程序设计(基础篇)原书第10版》第1...1.1 What are hardware and software? A computer is an electronic device that stores and processes data. A computer includes both hardware and software. In...
  • fs.default.name和fs.defaultFS

    万次阅读 2019-03-08 09:49:38
    在hadoop的配置文件 core-site.xml中,需要设置fs.default.name或fs.defaultFS ,具体应该使用哪一个,会造什么样的...We need to have only one of the two (fs.default.name or fs.defaultFS, and the former is d...
  • 最近在一次MySQL数据迁移的过程中遭遇了字符集的问题,提示为"Character set 'utf8mb4' is not a compiled character set"。即是字符集utf8mb4不是一个编译的字符集以及没有在Index.xml文件里指定。下面是其处理过程...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 183,702
精华内容 73,480
关键字:

isnamewhatyou