Learn Python From 'Head First Python' [2] : Sharing

1.publish

2.update print_lol

 

PS:

for Step 1.

write the code in to a py file. put the py file into a folder named nester. new a py file named ‘setup‘ and the content as below:

setup(
        name = nester,
        version = 1.0.0,
        py_modules = [nester],
        author = myFirstPython,
        author_email = [email protected],
        url = http://XXXX,
        description = A Simple Demo of Python,
    )

 

put the folder nest upder the folder ‘Python34‘. run a windows command line and run the command: python setup.py sdist

get the screenshot as delow:

 

Finally, install the problem.

now, all we can go to IDLE and use this funtion.

>>> a=[asd,[wef,[ergre],wefw],asd]
>>> import nester
>>> nester.print_lol(a)
asd
wef
ergre
wefw
asd
>>> 

 

for function override. edit the source code file and put the code below into the file.

def print_lol(the_list,level=0):
    for each in the_list:
        if isinstance(each,list):
            print_lol(each,level+1)
        else:
            for each_tab in range(level):
                print(\t,end=‘‘)
            print(each)

the level=0 is the default argument. in other words print_lol(list) equals to print_lol(list,0)

finally, go to the windows command line and run script: python setup.py sdist upload. and dont forget to install the problem again( command: python setup.py sdist install )

 

To Be Continue !

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。