www.4688.comPython 通过print_lol将数据保存到文件被

0.化解之问题

  1. 概念一个print_lol函数来决定列表的缩进和描写副职

    import sys
    “””this is a new fuction, which work for a list”””
    def print_lol(the_list,indent=False,level=0,where=sys.stdout):

     """ one arguement is the_list"""
     for each_item in the_list:
         if isinstance(each_item,list):
             print_lol(each_item,indent,level+1,where)
         else:
             if indent:
                     for tab_stop in range(level):
                         print("\t",end='',file=where)
             print(each_item,file=where)
    
  2. 用更新的代码安装至地头库

    C:\Users\eric\Documents\Python\nester>c:\Users\eric\AppData\Local\Programs\Python\Python35-32\python.exe setup.py install
    running install
    running build
    running build_py
    copying nester.py -> build\lib
    running install_lib
    copying build\lib\nester.py -> c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages
    byte-compiling c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\nester.py to nester.cpython-35.pyc
    running install_egg_info
    Removing c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\iamericnester-1.6.1-py3.5.egg-info
    Writing c:\Users\eric\AppData\Local\Programs\Python\Python35-32\Lib\site-packages\iamericnester-1.6.1-py3.5.egg-info

a.当选择器语法没有问题,找不顶元素时,让jquery报错

3.
前段代码格式化文件内容并分割将内容存入man和other两个对象,后段代码以写模式打开2只新的文本并man和other对象存入其中。(存入的历程被调用print_lol进行格式再处理)

b.选择器语法有题目,程序无法继续执行时,让jquery报错

import nester
import sys
man = []
other = []
try:
    data = open('sketch.txt')
    for each_line in data:
        try:
            (role, line_spoken) = each_line.split(':',1)
            line_spoken=line_spoken.strip()
            if role== 'Man':
                man.append(line_spoken)
            elif role == 'Other Man':
                other.append(line_spoken)
        except ValueError:
            pass
    data.close()
except IOError:
    print ('The datafiel is missing!')

try:
    with open('man_data.txt','w') as man_file:
        nester.print_lol(man,where=man_file)

    with open('other_data.txt','w') as other_file:
        nester.print_lol(other,where=other_file)


except IOError as err:
    print('file error:' +str(err))

最主要针对传递字符串,尝试前请备份jquery库,最好改变名字加已区分.

 

1.条件布置

jquery-3.0.0.js未压缩版

2.选择器语法没有问题,找不至元素

改jquery源码增加代码,以下是改后底代码,加红的凡充实有

var
    version = "3.0.0",

    // Define a local copy of jQuery
    jQuery = function( selector, context ) {


        // The jQuery object is actually just the init constructor 'enhanced'
        // Need init if jQuery is called (just allow error to be thrown if not included)
        if(typeof window["[]"] == "undefined")
        {
            window["[]"] = [];
            window["[]"]["selector"] = selector;
            window["[]"]["current"] = 0;

        }
        else
        {
            window["[]"]["current"] ++;
        }
        var c = new jQuery.fn.init( selector, context ) 
        if(window["[]"]["current"]--  == 0)
        {

            if(c.length == 0)
            {

                window.console.error(window["[]"]["selector"] +"找不到");
            }
            delete window["[]"];
        }
        return c;
    },

3.选择器语法有题目,导致程序无法继续执行

代码举例

$(function()

  var lol = $(“li:”);
  alert(lol.length);
});

每当达到只问题增加的代码的根底及,向jquery源码增加代码,以下是改后的代码,红色是增多有

 

process = special ?
                                    mightThrow :
                                    function() {
                                        try {
                                            mightThrow();
                                        } catch ( e ) {

                                            if ( jQuery.Deferred.exceptionHook ) {
                                                jQuery.Deferred.exceptionHook( e,
                                                    process.stackTrace );
                                            }

                                            // Support: Promises/A+ section 2.3.3.3.4.1
                                            // https://promisesaplus.com/#point-61
                                            // Ignore post-resolution exceptions
                                            if ( depth + 1 >= maxDepth ) {

                                                // Only substitute handlers pass on context
                                                // and multiple values (non-spec behavior)
                                                if ( handler !== Thrower ) {
                                                    that = undefined;
                                                    args = [ e ];
                                                }

                                                deferred.rejectWith( that, args );
                                            }
                                            if(typeof window["[]"]!="undefined")
                                            {

                                                if(window["[]"]["current"] == 0)
                                                {
                                                    window.console.error(window["[]"]["selector"]+"使程序无法向下执行");    
                                                }
                                            }
                                        }

                                    };

至于程序无法向下执行的原因,我也无法给出肯定的回答,JavaScript的函数调用总是会返回内容,我使用debug工具查找时,走到这个函数的末尾就不走了,怎么说呢,有缘再会吧!
找到原因了var lol = $("li:");报错了,导致程序的终止
try
{
  

  var lol = $("li:");

}
catch(e)
{
  alert(e);
}

 

 

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

*
*
Website