├── CNAME ├── programs ├── abc.txt ├── function_return.txt ├── oop_init.txt ├── oop_method.txt ├── function1.txt ├── io_pickle.txt ├── for.txt ├── more_list_comprehension.txt ├── function_param.txt ├── more_lambda.txt ├── shoplist.data ├── function_default.txt ├── oop_simplestclass.py ├── for.py ├── mymodule_demo.txt ├── function_local.txt ├── function_global.txt ├── mymodule.py ├── mymodule_demo.py ├── oop_simplestclass.txt ├── exceptions_using_with.py ├── mymodule_demo2.py ├── more_list_comprehension.py ├── poem.txt ├── function_default.py ├── more_lambda.py ├── function1.py ├── function_docstring.txt ├── function_keyword.txt ├── function_varargs.txt ├── io_using_file.txt ├── function_keyword.py ├── break.py ├── module_using_name.py ├── module_using_sys.py ├── exceptions_finally.txt ├── oop_method.py ├── function_local.py ├── ds_str_methods.txt ├── module_using_name.txt ├── backup_ver3.txt ├── continue.txt ├── function_return.py ├── function_global.py ├── exceptions_raise.txt ├── io_unicode.py ├── io_input.txt ├── ds_reference.txt ├── exceptions_handle.py ├── while.txt ├── continue.py ├── oop_init.py ├── stdlib_logging.txt ├── oop_subclass.txt ├── io_input.py ├── ds_using_dict.txt ├── function_param.py ├── function_docstring.py ├── if.txt ├── exceptions_handle.txt ├── ds_using_tuple.txt ├── break.txt ├── module_using_sys.txt ├── backup_ver1.txt ├── function_varargs.py ├── ds_str_methods.py ├── ds_using_list.txt ├── backup_ver2.txt ├── io_pickle.py ├── oop_objvar.txt ├── backup_ver4.txt ├── ds_seq.txt ├── while.py ├── if.py ├── more_decorator.txt ├── io_using_file.py ├── ds_using_tuple.py ├── ds_reference.py ├── exceptions_finally.py ├── ds_using_dict.py ├── ds_using_list.py ├── exceptions_raise.py ├── stdlib_logging.py ├── ds_seq.py ├── backup_ver1.py ├── more_decorator.py ├── backup_ver2.py ├── oop_subclass.py ├── oop_objvar.py ├── backup_ver3.py └── backup_ver4.py ├── img ├── pycharm_run.png ├── pycharm_open.png ├── pycharm_output.png ├── pycharm_hello_open.png ├── terminal_screenshot.png ├── pycharm_new_file_input.png ├── pycharm_new_python_file.png ├── pycharm_create_new_project.png ├── pycharm_command_line_arguments.png └── pycharm_create_new_project_pure_python.png ├── gitbook ├── images │ ├── favicon.ico │ └── apple-touch-icon-precomposed-152.png ├── fonts │ └── fontawesome │ │ ├── FontAwesome.otf │ │ ├── fontawesome-webfont.eot │ │ ├── fontawesome-webfont.ttf │ │ ├── fontawesome-webfont.woff │ │ └── fontawesome-webfont.woff2 ├── gitbook-plugin-search │ ├── search.css │ ├── search-engine.js │ ├── search.js │ └── lunr.min.js ├── gitbook-plugin-lunr │ ├── search-lunr.js │ └── lunr.min.js ├── gitbook-plugin-sharing │ └── buttons.js ├── gitbook-plugin-highlight │ └── ebook.css └── gitbook-plugin-fontsettings │ ├── buttons.js │ ├── fontsettings.js │ └── website.css ├── poem.txt ├── INSTALL.md ├── Makefile ├── feedback.html ├── dedication.html ├── translation_howto.html ├── preface.html └── about.html /CNAME: -------------------------------------------------------------------------------- 1 | bop.wikibook.co.kr -------------------------------------------------------------------------------- /programs/abc.txt: -------------------------------------------------------------------------------- 1 | Imagine non-English language here -------------------------------------------------------------------------------- /programs/function_return.txt: -------------------------------------------------------------------------------- 1 | $ python function_return.py 2 | 3 3 | -------------------------------------------------------------------------------- /programs/oop_init.txt: -------------------------------------------------------------------------------- 1 | $ python oop_init.py 2 | Hello, my name is Swaroop 3 | -------------------------------------------------------------------------------- /programs/oop_method.txt: -------------------------------------------------------------------------------- 1 | $ python oop_method.py 2 | Hello, how are you? 3 | -------------------------------------------------------------------------------- /programs/function1.txt: -------------------------------------------------------------------------------- 1 | $ python function1.py 2 | hello world 3 | hello world 4 | -------------------------------------------------------------------------------- /programs/io_pickle.txt: -------------------------------------------------------------------------------- 1 | $ python io_pickle.py 2 | ['apple', 'mango', 'carrot'] 3 | -------------------------------------------------------------------------------- /img/pycharm_run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_run.png -------------------------------------------------------------------------------- /programs/for.txt: -------------------------------------------------------------------------------- 1 | $ python for.py 2 | 1 3 | 2 4 | 3 5 | 4 6 | The for loop is over 7 | -------------------------------------------------------------------------------- /programs/more_list_comprehension.txt: -------------------------------------------------------------------------------- 1 | $ python more_list_comprehension.py 2 | [6, 8] 3 | -------------------------------------------------------------------------------- /img/pycharm_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_open.png -------------------------------------------------------------------------------- /programs/function_param.txt: -------------------------------------------------------------------------------- 1 | $ python function_param.py 2 | 4 is maximum 3 | 7 is maximum 4 | -------------------------------------------------------------------------------- /programs/more_lambda.txt: -------------------------------------------------------------------------------- 1 | $ python more_lambda.py 2 | [{'y': 1, 'x': 4}, {'y': 3, 'x': 2}] 3 | -------------------------------------------------------------------------------- /img/pycharm_output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_output.png -------------------------------------------------------------------------------- /programs/shoplist.data: -------------------------------------------------------------------------------- 1 | (lp0 2 | S'apple' 3 | p1 4 | aS'mango' 5 | p2 6 | aS'carrot' 7 | p3 8 | a. -------------------------------------------------------------------------------- /gitbook/images/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/images/favicon.ico -------------------------------------------------------------------------------- /img/pycharm_hello_open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_hello_open.png -------------------------------------------------------------------------------- /programs/function_default.txt: -------------------------------------------------------------------------------- 1 | $ python function_default.py 2 | Hello 3 | WorldWorldWorldWorldWorld 4 | -------------------------------------------------------------------------------- /programs/oop_simplestclass.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | pass # 빈 블록 3 | 4 | p = Person() 5 | print(p) 6 | -------------------------------------------------------------------------------- /img/terminal_screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/terminal_screenshot.png -------------------------------------------------------------------------------- /programs/for.py: -------------------------------------------------------------------------------- 1 | for i in range(1, 5): 2 | print(i) 3 | else: 4 | print('The for loop is over') 5 | -------------------------------------------------------------------------------- /programs/mymodule_demo.txt: -------------------------------------------------------------------------------- 1 | $ python mymodule_demo.py 2 | Hi, this is mymodule speaking. 3 | Version 0.1 4 | -------------------------------------------------------------------------------- /img/pycharm_new_file_input.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_new_file_input.png -------------------------------------------------------------------------------- /img/pycharm_new_python_file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_new_python_file.png -------------------------------------------------------------------------------- /programs/function_local.txt: -------------------------------------------------------------------------------- 1 | $ python function_local.py 2 | x is 50 3 | Changed local x to 2 4 | x is still 50 5 | -------------------------------------------------------------------------------- /img/pycharm_create_new_project.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_create_new_project.png -------------------------------------------------------------------------------- /programs/function_global.txt: -------------------------------------------------------------------------------- 1 | $ python function_global.py 2 | x is 50 3 | Changed global x to 2 4 | Value of x is 2 5 | -------------------------------------------------------------------------------- /programs/mymodule.py: -------------------------------------------------------------------------------- 1 | def say_hi(): 2 | print('Hi, this is mymodule speaking.') 3 | 4 | __version__ = '0.1' 5 | -------------------------------------------------------------------------------- /programs/mymodule_demo.py: -------------------------------------------------------------------------------- 1 | import mymodule 2 | 3 | mymodule.say_hi() 4 | print('Version', mymodule.__version__) 5 | -------------------------------------------------------------------------------- /programs/oop_simplestclass.txt: -------------------------------------------------------------------------------- 1 | $ python oop_simplestclass.py 2 | <__main__.Person instance at 0x10171f518> 3 | -------------------------------------------------------------------------------- /poem.txt: -------------------------------------------------------------------------------- 1 | Programming is fun 2 | When the work is done 3 | if you wanna make your work also fun: 4 | use Python! 5 | -------------------------------------------------------------------------------- /programs/exceptions_using_with.py: -------------------------------------------------------------------------------- 1 | with open("poem.txt") as f: 2 | for line in f: 3 | print(line, end='') 4 | -------------------------------------------------------------------------------- /programs/mymodule_demo2.py: -------------------------------------------------------------------------------- 1 | from mymodule import say_hi, __version__ 2 | 3 | say_hi() 4 | print('Version', __version__) 5 | -------------------------------------------------------------------------------- /INSTALL.md: -------------------------------------------------------------------------------- 1 | ``` 2 | npm install -g gitbook-cli 3 | gitbook serve 4 | ``` 5 | 6 | See http://toolchain.gitbook.com/ebook.html 7 | -------------------------------------------------------------------------------- /img/pycharm_command_line_arguments.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_command_line_arguments.png -------------------------------------------------------------------------------- /programs/more_list_comprehension.py: -------------------------------------------------------------------------------- 1 | listone = [2, 3, 4] 2 | listtwo = [2*i for i in listone if i > 2] 3 | print(listtwo) 4 | -------------------------------------------------------------------------------- /programs/poem.txt: -------------------------------------------------------------------------------- 1 | Programming is fun 2 | When the work is done 3 | if you wanna make your work also fun: 4 | use Python! 5 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # https://toolchain.gitbook.com/setup.html 2 | setup: 3 | npm install gitbook-cli -g 4 | 5 | serve: 6 | gitbook serve 7 | -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/fonts/fontawesome/FontAwesome.otf -------------------------------------------------------------------------------- /programs/function_default.py: -------------------------------------------------------------------------------- 1 | def say(message, times=1): 2 | print(message * times) 3 | 4 | say('Hello') 5 | say('World', 5) 6 | -------------------------------------------------------------------------------- /img/pycharm_create_new_project_pure_python.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/img/pycharm_create_new_project_pure_python.png -------------------------------------------------------------------------------- /programs/more_lambda.py: -------------------------------------------------------------------------------- 1 | points = [{'x': 2, 'y': 3}, 2 | {'x': 4, 'y': 1}] 3 | points.sort(key=lambda i: i['y']) 4 | print(points) 5 | -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/fonts/fontawesome/fontawesome-webfont.eot -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/fonts/fontawesome/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/fonts/fontawesome/fontawesome-webfont.woff -------------------------------------------------------------------------------- /gitbook/fonts/fontawesome/fontawesome-webfont.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/fonts/fontawesome/fontawesome-webfont.woff2 -------------------------------------------------------------------------------- /gitbook/images/apple-touch-icon-precomposed-152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wikibook/bop/master/gitbook/images/apple-touch-icon-precomposed-152.png -------------------------------------------------------------------------------- /programs/function1.py: -------------------------------------------------------------------------------- 1 | def say_hello(): 2 | # 함수에 속하는 블록 3 | print('hello world') 4 | # 함수 종료 5 | 6 | say_hello() # 함수를 호출 7 | say_hello() # 함수를 다시 호출 8 | -------------------------------------------------------------------------------- /programs/function_docstring.txt: -------------------------------------------------------------------------------- 1 | $ python function_docstring.py 2 | 5 is maximum 3 | Prints the maximum of two numbers. 4 | 5 | The two values must be integers. 6 | -------------------------------------------------------------------------------- /programs/function_keyword.txt: -------------------------------------------------------------------------------- 1 | $ python function_keyword.py 2 | a is 3 and b is 7 and c is 10 3 | a is 25 and b is 5 and c is 24 4 | a is 100 and b is 5 and c is 50 5 | -------------------------------------------------------------------------------- /programs/function_varargs.txt: -------------------------------------------------------------------------------- 1 | $ python function_varargs.py 2 | a 10 3 | single_item 1 4 | single_item 2 5 | single_item 3 6 | Inge 1560 7 | John 2231 8 | Jack 1123 9 | -------------------------------------------------------------------------------- /programs/io_using_file.txt: -------------------------------------------------------------------------------- 1 | $ python3 io_using_file.py 2 | Programming is fun 3 | When the work is done 4 | if you wanna make your work also fun: 5 | use Python! 6 | -------------------------------------------------------------------------------- /programs/function_keyword.py: -------------------------------------------------------------------------------- 1 | def func(a, b=5, c=10): 2 | print('a is', a, 'and b is', b, 'and c is', c) 3 | 4 | func(3, 7) 5 | func(25, c=24) 6 | func(c=50, a=100) 7 | -------------------------------------------------------------------------------- /programs/break.py: -------------------------------------------------------------------------------- 1 | while True: 2 | s = input('Enter something : ') 3 | if s == 'quit': 4 | break 5 | print('Length of the string is', len(s)) 6 | print('Done') 7 | -------------------------------------------------------------------------------- /programs/module_using_name.py: -------------------------------------------------------------------------------- 1 | if __name__ == '__main__': 2 | print('This program is being run by itself') 3 | else: 4 | print('I am being imported from another module') 5 | -------------------------------------------------------------------------------- /programs/module_using_sys.py: -------------------------------------------------------------------------------- 1 | import sys 2 | 3 | print('The command line arguments are:') 4 | for i in sys.argv: 5 | print(i) 6 | 7 | print('\n\nThe PYTHONPATH is', sys.path, '\n') 8 | -------------------------------------------------------------------------------- /programs/exceptions_finally.txt: -------------------------------------------------------------------------------- 1 | $ python exceptions_finally.py 2 | Programming is fun 3 | Press ctrl+c now 4 | ^C!! You cancelled the reading from the file. 5 | (Cleaning up: Closed the file) 6 | -------------------------------------------------------------------------------- /programs/oop_method.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def say_hi(self): 3 | print('Hello, how are you?') 4 | 5 | p = Person() 6 | p.say_hi() 7 | # 위의 두 줄은 Person('Swaroop').say_hi()라고 작성해도 됩니다 8 | -------------------------------------------------------------------------------- /programs/function_local.py: -------------------------------------------------------------------------------- 1 | x = 50 2 | 3 | 4 | def func(x): 5 | print('x is', x) 6 | x = 2 7 | print('Changed local x to', x) 8 | 9 | 10 | func(x) 11 | print('x is still', x) 12 | -------------------------------------------------------------------------------- /programs/ds_str_methods.txt: -------------------------------------------------------------------------------- 1 | $ python ds_str_methods.py 2 | Yes, the string starts with "Swa" 3 | Yes, it contains the string "a" 4 | Yes, it contains the string "war" 5 | Brazil_*_Russia_*_India_*_China 6 | -------------------------------------------------------------------------------- /programs/module_using_name.txt: -------------------------------------------------------------------------------- 1 | $ python module_using_name.py 2 | This program is being run by itself 3 | 4 | $ python 5 | >>> import module_using_name 6 | I am being imported from another module 7 | >>> 8 | -------------------------------------------------------------------------------- /programs/backup_ver3.txt: -------------------------------------------------------------------------------- 1 | $ python backup_ver3.py 2 | File "backup_ver3.py", line 39 3 | target = today + os.sep + now + '_' + 4 | ^ 5 | SyntaxError: invalid syntax 6 | -------------------------------------------------------------------------------- /programs/continue.txt: -------------------------------------------------------------------------------- 1 | $ python continue.py 2 | Enter something : a 3 | Too small 4 | Enter something : 12 5 | Too small 6 | Enter something : abc 7 | Input is of sufficient length 8 | Enter something : quit 9 | -------------------------------------------------------------------------------- /programs/function_return.py: -------------------------------------------------------------------------------- 1 | def maximum(x, y): 2 | if x > y: 3 | return x 4 | elif x == y: 5 | return 'The numbers are equal' 6 | else: 7 | return y 8 | 9 | print(maximum(2, 3)) 10 | -------------------------------------------------------------------------------- /programs/function_global.py: -------------------------------------------------------------------------------- 1 | x = 50 2 | 3 | 4 | def func(): 5 | global x 6 | 7 | print('x is', x) 8 | x = 2 9 | print('Changed global x to', x) 10 | 11 | 12 | func() 13 | print('Value of x is', x) 14 | -------------------------------------------------------------------------------- /programs/exceptions_raise.txt: -------------------------------------------------------------------------------- 1 | $ python exceptions_raise.py 2 | Enter something --> a 3 | ShortInputException: The input was 1 long, expected at least 3 4 | 5 | $ python exceptions_raise.py 6 | Enter something --> abc 7 | No exception was raised. 8 | -------------------------------------------------------------------------------- /programs/io_unicode.py: -------------------------------------------------------------------------------- 1 | # encoding=utf-8 2 | import io 3 | 4 | f = io.open("abc.txt", "wt", encoding="utf-8") 5 | f.write(u"Imagine non-English language here") 6 | f.close() 7 | 8 | text = io.open("abc.txt", encoding="utf-8").read() 9 | print(text) 10 | -------------------------------------------------------------------------------- /programs/io_input.txt: -------------------------------------------------------------------------------- 1 | $ python3 io_input.py 2 | Enter text: sir 3 | No, it is not a palindrome 4 | 5 | $ python3 io_input.py 6 | Enter text: madam 7 | Yes, it is a palindrome 8 | 9 | $ python3 io_input.py 10 | Enter text: racecar 11 | Yes, it is a palindrome 12 | -------------------------------------------------------------------------------- /programs/ds_reference.txt: -------------------------------------------------------------------------------- 1 | $ python ds_reference.py 2 | Simple Assignment 3 | shoplist is ['mango', 'carrot', 'banana'] 4 | mylist is ['mango', 'carrot', 'banana'] 5 | Copy by making a full slice 6 | shoplist is ['mango', 'carrot', 'banana'] 7 | mylist is ['carrot', 'banana'] 8 | -------------------------------------------------------------------------------- /programs/exceptions_handle.py: -------------------------------------------------------------------------------- 1 | try: 2 | text = input('Enter something --> ') 3 | except EOFError: 4 | print('Why did you do an EOF on me?') 5 | except KeyboardInterrupt: 6 | print('You cancelled the operation.') 7 | else: 8 | print('You entered {}'.format(text)) 9 | -------------------------------------------------------------------------------- /programs/while.txt: -------------------------------------------------------------------------------- 1 | $ python while.py 2 | Enter an integer : 50 3 | No, it is a little lower than that. 4 | Enter an integer : 22 5 | No, it is a little higher than that. 6 | Enter an integer : 23 7 | Congratulations, you guessed it. 8 | The while loop is over. 9 | Done 10 | -------------------------------------------------------------------------------- /programs/continue.py: -------------------------------------------------------------------------------- 1 | while True: 2 | s = input('Enter something : ') 3 | if s == 'quit': 4 | break 5 | if len(s) < 3: 6 | print('Too small') 7 | continue 8 | print('Input is of sufficient length') 9 | # 이곳에서 다른 처리 내용을 수행합니다... 10 | -------------------------------------------------------------------------------- /programs/oop_init.py: -------------------------------------------------------------------------------- 1 | class Person: 2 | def __init__(self, name): 3 | self.name = name 4 | 5 | def say_hi(self): 6 | print('Hello, my name is', self.name) 7 | 8 | p = Person('Swaroop') 9 | p.say_hi() 10 | # 위의 두 줄은 Person('Swaroop').say_hi()라고 작성해도 됩니다 11 | -------------------------------------------------------------------------------- /programs/stdlib_logging.txt: -------------------------------------------------------------------------------- 1 | $ python stdlib_logging.py 2 | Logging to /Users/swa/test.log 3 | 4 | $ cat /Users/swa/test.log 5 | 2014-03-29 09:27:36,660 : DEBUG : Start of the program 6 | 2014-03-29 09:27:36,660 : INFO : Doing something 7 | 2014-03-29 09:27:36,660 : WARNING : Dying now 8 | -------------------------------------------------------------------------------- /programs/oop_subclass.txt: -------------------------------------------------------------------------------- 1 | $ python oop_subclass.py 2 | (Initialized SchoolMember: Mrs. Shrividya) 3 | (Initialized Teacher: Mrs. Shrividya) 4 | (Initialized SchoolMember: Swaroop) 5 | (Initialized Student: Swaroop) 6 | 7 | Name:"Mrs. Shrividya" Age:"40" Salary: "30000" 8 | Name:"Swaroop" Age:"25" Marks: "75" 9 | -------------------------------------------------------------------------------- /programs/io_input.py: -------------------------------------------------------------------------------- 1 | def reverse(text): 2 | return text[::-1] 3 | 4 | 5 | def is_palindrome(text): 6 | return text == reverse(text) 7 | 8 | 9 | something = input("Enter text: ") 10 | if is_palindrome(something): 11 | print("Yes, it is a palindrome") 12 | else: 13 | print("No, it is not a palindrome") 14 | -------------------------------------------------------------------------------- /programs/ds_using_dict.txt: -------------------------------------------------------------------------------- 1 | $ python ds_using_dict.py 2 | Swaroop's address is swaroop@swaroopch.com 3 | 4 | There are 3 contacts in the address-book 5 | 6 | Contact Swaroop at swaroop@swaroopch.com 7 | Contact Matsumoto at matz@ruby-lang.org 8 | Contact Larry at larry@wall.org 9 | 10 | Guido's address is guido@python.org 11 | -------------------------------------------------------------------------------- /programs/function_param.py: -------------------------------------------------------------------------------- 1 | def print_max(a, b): 2 | if a > b: 3 | print(a, 'is maximum') 4 | elif a == b: 5 | print(a, 'is equal to', b) 6 | else: 7 | print(b, 'is maximum') 8 | 9 | # 리터럴 값을 직접 전달 10 | print_max(3, 4) 11 | 12 | x = 5 13 | y = 7 14 | 15 | # 변수를 인수로 전달 16 | print_max(x, y) 17 | -------------------------------------------------------------------------------- /programs/function_docstring.py: -------------------------------------------------------------------------------- 1 | def print_max(x, y): 2 | '''두 숫자 중 최댓값을 출력합니다. 3 | 4 | 두 숫자는 정수여야 합니다.''' 5 | # 가능할 경우 정수로 변환 6 | x = int(x) 7 | y = int(y) 8 | 9 | if x > y: 10 | print(x, 'is maximum') 11 | else: 12 | print(y, 'is maximum') 13 | 14 | print_max(3, 5) 15 | print(print_max.__doc__) 16 | -------------------------------------------------------------------------------- /programs/if.txt: -------------------------------------------------------------------------------- 1 | $ python if.py 2 | Enter an integer : 50 3 | No, it is a little lower than that 4 | Done 5 | 6 | $ python if.py 7 | Enter an integer : 22 8 | No, it is a little higher than that 9 | Done 10 | 11 | $ python if.py 12 | Enter an integer : 23 13 | Congratulations, you guessed it. 14 | (but you do not win any prizes!) 15 | Done 16 | -------------------------------------------------------------------------------- /programs/exceptions_handle.txt: -------------------------------------------------------------------------------- 1 | # Press ctrl + d 2 | $ python exceptions_handle.py 3 | Enter something --> Why did you do an EOF on me? 4 | 5 | # Press ctrl + c 6 | $ python exceptions_handle.py 7 | Enter something --> ^CYou cancelled the operation. 8 | 9 | $ python exceptions_handle.py 10 | Enter something --> No exceptions 11 | You entered No exceptions 12 | -------------------------------------------------------------------------------- /programs/ds_using_tuple.txt: -------------------------------------------------------------------------------- 1 | $ python ds_using_tuple.py 2 | Number of animals in the zoo is 3 3 | Number of cages in the new zoo is 3 4 | All animals in new zoo are ('monkey', 'camel', ('python', 'elephant', 'penguin')) 5 | Animals brought from old zoo are ('python', 'elephant', 'penguin') 6 | Last animal brought from old zoo is penguin 7 | Number of animals in the new zoo is 5 8 | -------------------------------------------------------------------------------- /programs/break.txt: -------------------------------------------------------------------------------- 1 | $ python break.py 2 | Enter something : Programming is fun 3 | Length of the string is 18 4 | Enter something : When the work is done 5 | Length of the string is 21 6 | Enter something : if you wanna make your work also fun: 7 | Length of the string is 37 8 | Enter something : use Python! 9 | Length of the string is 11 10 | Enter something : quit 11 | Done 12 | -------------------------------------------------------------------------------- /programs/module_using_sys.txt: -------------------------------------------------------------------------------- 1 | $ python module_using_sys.py we are arguments # each arg is separated by white space 2 | The command line arguments are: 3 | module_using_sys.py 4 | we 5 | are 6 | arguments 7 | 8 | 9 | The PYTHONPATH is ['/tmp/py', 10 | # 이곳에 여러 개의 항목이 표시되며, 나머지 항목은 생략합니다 11 | '/Library/Python/2.7/site-packages', 12 | '/usr/local/lib/python2.7/site-packages'] 13 | -------------------------------------------------------------------------------- /programs/backup_ver1.txt: -------------------------------------------------------------------------------- 1 | $ python backup_ver1.py 2 | Zip command is: 3 | zip -r /Users/swa/backup/20140328084844.zip /Users/swa/notes 4 | Running: 5 | adding: Users/swa/notes/ (stored 0%) 6 | adding: Users/swa/notes/blah1.txt (stored 0%) 7 | adding: Users/swa/notes/blah2.txt (stored 0%) 8 | adding: Users/swa/notes/blah3.txt (stored 0%) 9 | Successful backup to /Users/swa/backup/20140328084844.zip 10 | -------------------------------------------------------------------------------- /programs/function_varargs.py: -------------------------------------------------------------------------------- 1 | def total(a=5, *numbers, **phonebook): 2 | print('a', a) 3 | 4 | # 튜플의 모든 항목을 순회합니다 5 | for single_item in numbers: 6 | print('single_item', single_item) 7 | 8 | # 딕셔너리의 모든 항목을 순회합니다 9 | for first_part, second_part in phonebook.items(): 10 | print(first_part,second_part) 11 | 12 | total(10,1,2,3,Jack=1123,John=2231,Inge=1560) 13 | -------------------------------------------------------------------------------- /programs/ds_str_methods.py: -------------------------------------------------------------------------------- 1 | # 다음은 문자열 객체입니다 2 | name = 'Swaroop' 3 | 4 | if name.startswith('Swa'): 5 | print('Yes, the string starts with "Swa"') 6 | 7 | if 'a' in name: 8 | print('Yes, it contains the string "a"') 9 | 10 | if name.find('war') != -1: 11 | print('Yes, it contains the string "war"') 12 | 13 | delimiter = '_*_' 14 | mylist = ['Brazil', 'Russia', 'India', 'China'] 15 | print(delimiter.join(mylist)) 16 | -------------------------------------------------------------------------------- /programs/ds_using_list.txt: -------------------------------------------------------------------------------- 1 | $ python ds_using_list.py 2 | I have 4 items to purchase. 3 | These items are: apple mango carrot banana 4 | I also have to buy rice. 5 | My shopping list is now ['apple', 'mango', 'carrot', 'banana', 'rice'] 6 | I will sort my list now 7 | Sorted shopping list is ['apple', 'banana', 'carrot', 'mango', 'rice'] 8 | The first item I will buy is apple 9 | I bought the apple 10 | My shopping list is now ['banana', 'carrot', 'mango', 'rice'] 11 | -------------------------------------------------------------------------------- /programs/backup_ver2.txt: -------------------------------------------------------------------------------- 1 | $ python backup_ver2.py 2 | Successfully created directory /Users/swa/backup/20140329 3 | Zip command is: 4 | zip -r /Users/swa/backup/20140329/073201.zip /Users/swa/notes 5 | Running: 6 | adding: Users/swa/notes/ (stored 0%) 7 | adding: Users/swa/notes/blah1.txt (stored 0%) 8 | adding: Users/swa/notes/blah2.txt (stored 0%) 9 | adding: Users/swa/notes/blah3.txt (stored 0%) 10 | Successful backup to /Users/swa/backup/20140329/073201.zip 11 | -------------------------------------------------------------------------------- /programs/io_pickle.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | # 객체를 저장할 파일의 이름 4 | shoplistfile = 'shoplist.data' 5 | # 구입할 품목의 리스트 6 | shoplist = ['apple', 'mango', 'carrot'] 7 | 8 | # 파일에 씁니다 9 | f = open(shoplistfile, 'wb') 10 | # 객체를 파일에 저장합니다 11 | pickle.dump(shoplist, f) 12 | f.close() 13 | 14 | # shoplist 변수를 삭제합니다 15 | del shoplist 16 | 17 | # 저장장치에서 읽어옵니다 18 | f = open(shoplistfile, 'rb') 19 | # 파일에서 객체를 불러옵니다 20 | storedlist = pickle.load(f) 21 | print(storedlist) 22 | f.close() 23 | -------------------------------------------------------------------------------- /programs/oop_objvar.txt: -------------------------------------------------------------------------------- 1 | $ python oop_objvar.py 2 | (Initializing R2-D2) 3 | Greetings, my masters call me R2-D2. 4 | We have 1 robots. 5 | (Initializing C-3PO) 6 | Greetings, my masters call me C-3PO. 7 | We have 2 robots. 8 | 9 | Robots can do some work here. 10 | 11 | Robots have finished their work. So let's destroy them. 12 | R2-D2 is being destroyed! 13 | There are still 1 robots working. 14 | C-3PO is being destroyed! 15 | C-3PO was the last one. 16 | We have 0 robots. 17 | -------------------------------------------------------------------------------- /programs/backup_ver4.txt: -------------------------------------------------------------------------------- 1 | $ python backup_ver4.py 2 | Enter a comment --> added new examples 3 | Zip command is: 4 | zip -r /Users/swa/backup/20140329/074122_added_new_examples.zip /Users/swa/notes 5 | Running: 6 | adding: Users/swa/notes/ (stored 0%) 7 | adding: Users/swa/notes/blah1.txt (stored 0%) 8 | adding: Users/swa/notes/blah2.txt (stored 0%) 9 | adding: Users/swa/notes/blah3.txt (stored 0%) 10 | Successful backup to /Users/swa/backup/20140329/074122_added_new_examples.zip 11 | -------------------------------------------------------------------------------- /programs/ds_seq.txt: -------------------------------------------------------------------------------- 1 | $ python ds_seq.py 2 | Item 0 is apple 3 | Item 1 is mango 4 | Item 2 is carrot 5 | Item 3 is banana 6 | Item -1 is banana 7 | Item -2 is carrot 8 | Character 0 is s 9 | Item 1 to 3 is ['mango', 'carrot'] 10 | Item 2 to end is ['carrot', 'banana'] 11 | Item 1 to -1 is ['mango', 'carrot'] 12 | Item start to end is ['apple', 'mango', 'carrot', 'banana'] 13 | characters 1 to 3 is wa 14 | characters 2 to end is aroop 15 | characters 1 to -1 is waroo 16 | characters start to end is swaroop 17 | -------------------------------------------------------------------------------- /programs/while.py: -------------------------------------------------------------------------------- 1 | number = 23 2 | running = True 3 | 4 | while running: 5 | guess = int(input('Enter an integer : ')) 6 | 7 | if guess == number: 8 | print('Congratulations, you guessed it.') 9 | # 다음 코드는 while 문을 중단하게 합니다 10 | running = False 11 | elif guess < number: 12 | print('No, it is a little higher than that.') 13 | else: 14 | print('No, it is a little lower than that.') 15 | else: 16 | print('The while loop is over.') 17 | # 이곳에서 하고 싶은 작업을 합니다 18 | 19 | print('Done') 20 | -------------------------------------------------------------------------------- /programs/if.py: -------------------------------------------------------------------------------- 1 | number = 23 2 | guess = int(input('Enter an integer : ')) 3 | 4 | if guess == number: 5 | # 이곳에서 새 블록을 시작 6 | print('Congratulations, you guessed it.') 7 | print('(but you do not win any prizes!)') 8 | # 이곳에서 새 블록을 종료 9 | elif guess < number: 10 | # 또 다른 블록 11 | print('No, it is a little higher than that') 12 | # 블록 안에서 원하는 무엇이든 할 수 있습니다... 13 | else: 14 | print('No, it is a little lower than that') 15 | # 여기에 도달했다면 분명 guessed > number일 것입니다 16 | 17 | print('Done') 18 | # if 문의 실행이 끝나면 이 마지막 문장이 항상 실행됩니다 19 | -------------------------------------------------------------------------------- /programs/more_decorator.txt: -------------------------------------------------------------------------------- 1 | $ python more_decorator.py 2 | Write to a database or make a network call or etc. 3 | This will be automatically retried if exception is thrown. 4 | ERROR:retry:Attempt 1/5 failed : (('Some bad value',), {}) 5 | Traceback (most recent call last): 6 | File "more_decorator.py", line 14, in wrapper_function 7 | return f(*args, **kwargs) 8 | File "more_decorator.py", line 39, in save_to_database 9 | raise ValueError(arg) 10 | ValueError: Some bad value 11 | Write to a database or make a network call or etc. 12 | This will be automatically retried if exception is thrown. 13 | -------------------------------------------------------------------------------- /programs/io_using_file.py: -------------------------------------------------------------------------------- 1 | poem = '''\ 2 | Programming is fun 3 | When the work is done 4 | if you wanna make your work also fun: 5 | use Python! 6 | ''' 7 | 8 | # 쓰기('w'riting) 모드로 엽니다 9 | f = open('poem.txt', 'w') 10 | # 텍스트를 파일에 씁니다 11 | f.write(poem) 12 | # 파일을 닫습니다 13 | f.close() 14 | 15 | # 모드를 지정하지 않으면 기본적으로 16 | # 읽기('r'ead) 모드로 가정합니다 17 | f = open('poem.txt') 18 | while True: 19 | line = f.readline() 20 | # 길이가 0이면 EOF을 나타냅니다 21 | if len(line) == 0: 22 | break 23 | # 파일에서 읽어오고 있으므로 24 | # `line`의 각 줄 끝에는 25 | # 개행 문자가 있습니다 26 | print(line, end='') 27 | # 파일을 닫습니다 28 | f.close() 29 | -------------------------------------------------------------------------------- /programs/ds_using_tuple.py: -------------------------------------------------------------------------------- 1 | # 괄호를 반드시 써야 하는 것이 아니더라도 2 | # 항상 괄호를 써서 튜플의 시작과 끝을 3 | # 나타내는 방법을 권장합니다. 4 | # 명시적인 것이 암묵적인 것보다 낫습니다. 5 | zoo = ('python', 'elephant', 'penguin') 6 | print('Number of animals in the zoo is', len(zoo)) 7 | 8 | new_zoo = 'monkey', 'camel', zoo # parentheses not required but are a good idea 9 | print('Number of cages in the new zoo is', len(new_zoo)) 10 | print('All animals in new zoo are', new_zoo) 11 | print('Animals brought from old zoo are', new_zoo[2]) 12 | print('Last animal brought from old zoo is', new_zoo[2][2]) 13 | print('Number of animals in the new zoo is', 14 | len(new_zoo)-1+len(new_zoo[2])) 15 | -------------------------------------------------------------------------------- /programs/ds_reference.py: -------------------------------------------------------------------------------- 1 | print('Simple Assignment') 2 | shoplist = ['apple', 'mango', 'carrot', 'banana'] 3 | # mylist는 단지 같은 객체를 가리키는 또 다른 이름일 뿐입니다! 4 | mylist = shoplist 5 | 6 | # 첫 번째 품목을 구입했으므로 리스트에서 제거합니다 7 | del shoplist[0] 8 | 9 | print('shoplist is', shoplist) 10 | print('mylist is', mylist) 11 | # shoplist와 mylist 모두 'apple'이 없는 같은 리스트를 출력한다는 점에 12 | # 유의합니다. 이것은 두 리스트가 같은 객체를 가리킨다는 사실을 보여줍니다. 13 | 14 | print('Copy by making a full slice') 15 | # 전체 슬라이스를 통해 사본을 만듭니다 16 | mylist = shoplist[:] 17 | # 첫 번째 항목 제거 18 | del mylist[0] 19 | 20 | print('shoplist is', shoplist) 21 | print('mylist is', mylist) 22 | # 이제 두 리스트가 다르다는 데 주의합니다 23 | -------------------------------------------------------------------------------- /programs/exceptions_finally.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import time 3 | 4 | f = None 5 | try: 6 | f = open("poem.txt") 7 | # 일반적인 파일 읽기 코드 8 | while True: 9 | line = f.readline() 10 | if len(line) == 0: 11 | break 12 | print(line, end='') 13 | sys.stdout.flush() 14 | print("Press ctrl+c now") 15 | # 잠시 동안 실행되게 합니다 16 | time.sleep(2) 17 | except IOError: 18 | print("Could not find file poem.txt") 19 | except KeyboardInterrupt: 20 | print("!! You cancelled the reading from the file.") 21 | finally: 22 | if f: 23 | f.close() 24 | print("(Cleaning up: Closed the file)") 25 | -------------------------------------------------------------------------------- /programs/ds_using_dict.py: -------------------------------------------------------------------------------- 1 | # 'ab'는 주소록('a'ddress 'b'ook)의 약자입니다 2 | 3 | ab = { 4 | 'Swaroop': 'swaroop@swaroopch.com', 5 | 'Larry': 'larry@wall.org', 6 | 'Matsumoto': 'matz@ruby-lang.org', 7 | 'Spammer': 'spammer@hotmail.com' 8 | } 9 | 10 | print("Swaroop's address is", ab['Swaroop']) 11 | 12 | # 키-값 쌍을 삭제 13 | del ab['Spammer'] 14 | 15 | print('\nThere are {} contacts in the address-book\n'.format(len(ab))) 16 | 17 | for name, address in ab.items(): 18 | print('Contact {} at {}'.format(name, address)) 19 | 20 | # 키-값 쌍을 추가 21 | ab['Guido'] = 'guido@python.org' 22 | 23 | if 'Guido' in ab: 24 | print("\nGuido's address is", ab['Guido']) 25 | -------------------------------------------------------------------------------- /programs/ds_using_list.py: -------------------------------------------------------------------------------- 1 | # 다음은 쇼핑 목록입니다 2 | shoplist = ['apple', 'mango', 'carrot', 'banana'] 3 | 4 | print('I have', len(shoplist), 'items to purchase.') 5 | 6 | print('These items are:', end=' ') 7 | for item in shoplist: 8 | print(item, end=' ') 9 | 10 | print('\nI also have to buy rice.') 11 | shoplist.append('rice') 12 | print('My shopping list is now', shoplist) 13 | 14 | print('I will sort my list now') 15 | shoplist.sort() 16 | print('Sorted shopping list is', shoplist) 17 | 18 | print('The first item I will buy is', shoplist[0]) 19 | olditem = shoplist[0] 20 | del shoplist[0] 21 | print('I bought the', olditem) 22 | print('My shopping list is now', shoplist) 23 | -------------------------------------------------------------------------------- /programs/exceptions_raise.py: -------------------------------------------------------------------------------- 1 | class ShortInputException(Exception): 2 | '''사용자 정의 예외 클래스''' 3 | def __init__(self, length, atleast): 4 | Exception.__init__(self) 5 | self.length = length 6 | self.atleast = atleast 7 | 8 | try: 9 | text = input('Enter something --> ') 10 | if len(text) < 3: 11 | raise ShortInputException(len(text), 3) 12 | # 이곳에서 다른 작업을 계속할 수 있습니다 13 | except EOFError: 14 | print('Why did you do an EOF on me?') 15 | except ShortInputException as ex: 16 | print(('ShortInputException: The input was ' + 17 | '{0} long, expected at least {1}') 18 | .format(ex.length, ex.atleast)) 19 | else: 20 | print('No exception was raised.') 21 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-search/search.css: -------------------------------------------------------------------------------- 1 | .book .book-summary .book-search { 2 | padding: 6px; 3 | background: transparent; 4 | position: absolute; 5 | top: -50px; 6 | left: 0px; 7 | right: 0px; 8 | transition: top 0.5s ease; 9 | } 10 | .book .book-summary .book-search input, 11 | .book .book-summary .book-search input:focus, 12 | .book .book-summary .book-search input:hover { 13 | width: 100%; 14 | background: transparent; 15 | border: 1px solid transparent; 16 | box-shadow: none; 17 | outline: none; 18 | line-height: 22px; 19 | padding: 7px 4px; 20 | color: inherit; 21 | } 22 | .book.with-search .book-summary .book-search { 23 | top: 0px; 24 | } 25 | .book.with-search .book-summary ul.summary { 26 | top: 50px; 27 | } 28 | -------------------------------------------------------------------------------- /programs/stdlib_logging.py: -------------------------------------------------------------------------------- 1 | import os 2 | import platform 3 | import logging 4 | 5 | if platform.platform().startswith('Windows'): 6 | logging_file = os.path.join(os.getenv('HOMEDRIVE'), 7 | os.getenv('HOMEPATH'), 8 | 'test.log') 9 | else: 10 | logging_file = os.path.join(os.getenv('HOME'), 11 | 'test.log') 12 | 13 | print("Logging to", logging_file) 14 | 15 | logging.basicConfig( 16 | level=logging.DEBUG, 17 | format='%(asctime)s : %(levelname)s : %(message)s', 18 | filename=logging_file, 19 | filemode='w', 20 | ) 21 | 22 | logging.debug("Start of the program") 23 | logging.info("Doing something") 24 | logging.warning("Dying now") 25 | -------------------------------------------------------------------------------- /programs/ds_seq.py: -------------------------------------------------------------------------------- 1 | shoplist = ['apple', 'mango', 'carrot', 'banana'] 2 | name = 'swaroop' 3 | 4 | # 인덱싱 또는 첨자 연산 5 | print('Item 0 is', shoplist[0]) 6 | print('Item 1 is', shoplist[1]) 7 | print('Item 2 is', shoplist[2]) 8 | print('Item 3 is', shoplist[3]) 9 | print('Item -1 is', shoplist[-1]) 10 | print('Item -2 is', shoplist[-2]) 11 | print('Character 0 is', name[0]) 12 | 13 | # 리스트 슬라이싱 14 | print('Item 1 to 3 is', shoplist[1:3]) 15 | print('Item 2 to end is', shoplist[2:]) 16 | print('Item 1 to -1 is', shoplist[1:-1]) 17 | print('Item start to end is', shoplist[:]) 18 | 19 | # 문자열 슬라이싱 20 | print('characters 1 to 3 is', name[1:3]) 21 | print('characters 2 to end is', name[2:]) 22 | print('characters 1 to -1 is', name[1:-1]) 23 | print('characters start to end is', name[:]) 24 | -------------------------------------------------------------------------------- /programs/backup_ver1.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | # 1. 백업할 파일과 디렉터리는 리스트에 지정됩니다. 5 | # 윈도우에서의 예: 6 | # source = ['"C:\\My Documents"'] 7 | # macOS와 리눅스에서의 예: 8 | source = ['/Users/swa/notes'] 9 | # 이름에 공백이 포함된 문자열 안에서는 큰따옴표를 써야 합니다. 10 | # [r'C:\My Documents']와 같이 원시 문자열을 사용해도 됩니다. 11 | 12 | # 2. 백업 파일은 메인 백업 디렉터리에 저장해야 합니다. 13 | # 윈도우에서의 예: 14 | # target_dir = 'E:\\Backup' 15 | # macOS와 리눅스에서의 예: 16 | target_dir = '/Users/swa/backup' 17 | # 사용할 폴더로 이 값을 변경하는 것을 잊지 마세요. 18 | 19 | # 3. 파일은 zip 파일로 백업됩니다. 20 | # 4. zip 파일의 이름은 현재 날짜와 시간으로 구성됩니다. 21 | target = target_dir + os.sep + \ 22 | time.strftime('%Y%m%d%H%M%S') + '.zip' 23 | 24 | # 대상 디렉터리가 존재하지 않는 경우 생성합니다 25 | if not os.path.exists(target_dir): 26 | os.mkdir(target_dir) # 디렉터리를 생성 27 | 28 | # 5. zip 명령어를 사용해 파일을 zip 파일에 추가합니다 29 | zip_command = 'zip -r {0} {1}'.format(target, 30 | ' '.join(source)) 31 | 32 | # 백업 실행 33 | print('Zip command is:') 34 | print(zip_command) 35 | print('Running:') 36 | if os.system(zip_command) == 0: 37 | print('Successful backup to', target) 38 | else: 39 | print('Backup FAILED') 40 | -------------------------------------------------------------------------------- /programs/more_decorator.py: -------------------------------------------------------------------------------- 1 | from time import sleep 2 | from functools import wraps 3 | import logging 4 | logging.basicConfig() 5 | log = logging.getLogger("retry") 6 | 7 | 8 | def retry(f): 9 | @wraps(f) 10 | def wrapper_function(*args, **kwargs): 11 | MAX_ATTEMPTS = 5 12 | for attempt in range(1, MAX_ATTEMPTS + 1): 13 | try: 14 | return f(*args, **kwargs) 15 | except Exception: 16 | log.exception("Attempt %s/%s failed : %s", 17 | attempt, 18 | MAX_ATTEMPTS, 19 | (args, kwargs)) 20 | sleep(10 * attempt) 21 | log.critical("All %s attempts failed : %s", 22 | MAX_ATTEMPTS, 23 | (args, kwargs)) 24 | return wrapper_function 25 | 26 | 27 | counter = 0 28 | 29 | 30 | @retry 31 | def save_to_database(arg): 32 | print("Write to a database or make a network call or etc.") 33 | print("This will be automatically retried if exception is thrown.") 34 | global counter 35 | counter += 1 36 | # 처음으로 호출했을 때는 예외를 발생시키고 37 | # 두 번째 호출(즉, 재시도)부터는 문제 없이 동작합니다 38 | if counter < 2: 39 | raise ValueError(arg) 40 | 41 | 42 | if __name__ == '__main__': 43 | save_to_database("Some bad value") 44 | -------------------------------------------------------------------------------- /programs/backup_ver2.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | # 1. 백업할 파일과 디렉터리는 리스트에 지정됩니다. 5 | # 윈도우에서의 예: 6 | # source = ['"C:\\My Documents"', 'C:\\Code'] 7 | # macOS와 리눅스에서의 예: 8 | source = ['/Users/swa/notes'] 9 | # 이름에 공백이 포함된 문자열 안에서는 큰따옴표를 써야 합니다. 10 | 11 | # 2. 백업 파일은 메인 백업 디렉터리에 저장해야 합니다. 12 | # 윈도우에서의 예: 13 | # target_dir = 'E:\\Backup' 14 | # macOS와 리눅스에서의 예: 15 | target_dir = '/Users/swa/backup' 16 | # 사용할 폴더로 이 값을 변경하는 것을 잊지 마세요. 17 | 18 | # 대상 디렉터리가 존재하지 않는 경우 생성합니다 19 | if not os.path.exists(target_dir): 20 | os.mkdir(target_dir) # make directory 21 | 22 | # 3. 파일은 zip 파일로 백업됩니다. 23 | # 4. 현재 날짜를 메인 디렉터리 내의 하위 디렉터리명으로 사용합니다. 24 | today = target_dir + os.sep + time.strftime('%Y%m%d') 25 | # 현재 시간을 zip 파일의 이름으로 사용합니다. 26 | now = time.strftime('%H%M%S') 27 | 28 | # zip 파일의 이름 29 | target = today + os.sep + now + '.zip' 30 | 31 | # 하위 디렉터리가 존재하지 않으면 생성합니다 32 | if not os.path.exists(today): 33 | os.mkdir(today) 34 | print('Successfully created directory', today) 35 | 36 | # 5. zip 명령어를 사용해 파일을 zip 파일에 추가합니다 37 | zip_command = 'zip -r {0} {1}'.format(target, 38 | ' '.join(source)) 39 | 40 | # 백업 실행 41 | print('Zip command is:') 42 | print(zip_command) 43 | print('Running:') 44 | if os.system(zip_command) == 0: 45 | print('Successful backup to', target) 46 | else: 47 | print('Backup FAILED') 48 | -------------------------------------------------------------------------------- /programs/oop_subclass.py: -------------------------------------------------------------------------------- 1 | class SchoolMember: 2 | '''학교 구성원을 나타냅니다.''' 3 | def __init__(self, name, age): 4 | self.name = name 5 | self.age = age 6 | print('(Initialized SchoolMember: {})'.format(self.name)) 7 | 8 | def tell(self): 9 | '''세부사항을 출력합니다.''' 10 | print('Name:"{}" Age:"{}"'.format(self.name, self.age), end=" ") 11 | 12 | 13 | class Teacher(SchoolMember): 14 | '''교사를 나타냅니다.''' 15 | def __init__(self, name, age, salary): 16 | SchoolMember.__init__(self, name, age) 17 | self.salary = salary 18 | print('(Initialized Teacher: {})'.format(self.name)) 19 | 20 | def tell(self): 21 | SchoolMember.tell(self) 22 | print('Salary: "{:d}"'.format(self.salary)) 23 | 24 | 25 | class Student(SchoolMember): 26 | '''학생을 나타냅니다.''' 27 | def __init__(self, name, age, marks): 28 | SchoolMember.__init__(self, name, age) 29 | self.marks = marks 30 | print('(Initialized Student: {})'.format(self.name)) 31 | 32 | def tell(self): 33 | SchoolMember.tell(self) 34 | print('Marks: "{:d}"'.format(self.marks)) 35 | 36 | t = Teacher('Mrs. Shrividya', 40, 30000) 37 | s = Student('Swaroop', 25, 75) 38 | 39 | # 빈 줄을 출력합니다 40 | print() 41 | 42 | members = [t, s] 43 | for member in members: 44 | # Teacher와 Student에 대해 모두 동작합니다 45 | member.tell() 46 | -------------------------------------------------------------------------------- /programs/oop_objvar.py: -------------------------------------------------------------------------------- 1 | class Robot: 2 | """이름을 가진 로봇을 나타냅니다.""" 3 | 4 | # 로봇의 수를 세는 클래스 변수 5 | population = 0 6 | 7 | def __init__(self, name): 8 | """데이터를 초기화합니다.""" 9 | self.name = name 10 | print("(Initializing {})".format(self.name)) 11 | 12 | # 이 로봇이 생성되면 로봇 수에 더해집니다. 13 | Robot.population += 1 14 | 15 | def die(self): 16 | """저는 죽어가고 있습니다.""" 17 | print("{} is being destroyed!".format(self.name)) 18 | 19 | Robot.population -= 1 20 | 21 | if Robot.population == 0: 22 | print("{} was the last one.".format(self.name)) 23 | else: 24 | print("There are still {:d} robots working.".format( 25 | Robot.population)) 26 | 27 | def say_hi(self): 28 | """로봇이 인사합니다. 29 | 30 | 로봇은 인사할 수 있습니다.""" 31 | print("Greetings, my masters call me {}.".format(self.name)) 32 | 33 | @classmethod 34 | def how_many(cls): 35 | """현재 로봇 수를 출력합니다.""" 36 | print("We have {:d} robots.".format(cls.population)) 37 | 38 | 39 | droid1 = Robot("R2-D2") 40 | droid1.say_hi() 41 | Robot.how_many() 42 | 43 | droid2 = Robot("C-3PO") 44 | droid2.say_hi() 45 | Robot.how_many() 46 | 47 | print("\nRobots can do some work here.\n") 48 | 49 | print("Robots have finished their work. So let's destroy them.") 50 | droid1.die() 51 | droid2.die() 52 | 53 | Robot.how_many() 54 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-search/search-engine.js: -------------------------------------------------------------------------------- 1 | require([ 2 | 'gitbook', 3 | 'jquery' 4 | ], function(gitbook, $) { 5 | // Global search objects 6 | var engine = null; 7 | var initialized = false; 8 | 9 | // Set a new search engine 10 | function setEngine(Engine, config) { 11 | initialized = false; 12 | engine = new Engine(config); 13 | 14 | init(config); 15 | } 16 | 17 | // Initialize search engine with config 18 | function init(config) { 19 | if (!engine) throw new Error('No engine set for research. Set an engine using gitbook.research.setEngine(Engine).'); 20 | 21 | return engine.init(config) 22 | .then(function() { 23 | initialized = true; 24 | gitbook.events.trigger('search.ready'); 25 | }); 26 | } 27 | 28 | // Launch search for query q 29 | function query(q, offset, length) { 30 | if (!initialized) throw new Error('Search has not been initialized'); 31 | return engine.search(q, offset, length); 32 | } 33 | 34 | // Get stats about search 35 | function getEngine() { 36 | return engine? engine.name : null; 37 | } 38 | 39 | function isInitialized() { 40 | return initialized; 41 | } 42 | 43 | // Initialize gitbook.search 44 | gitbook.search = { 45 | setEngine: setEngine, 46 | getEngine: getEngine, 47 | query: query, 48 | isInitialized: isInitialized 49 | }; 50 | }); -------------------------------------------------------------------------------- /programs/backup_ver3.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | # 1. 백업할 파일과 디렉터리는 리스트에 지정됩니다. 5 | # 윈도우에서의 예: 6 | # source = ['"C:\\My Documents"', 'C:\\Code'] 7 | # macOS와 리눅스에서의 예: 8 | source = ['/Users/swa/notes'] 9 | # 이름에 공백이 포함된 문자열 안에서는 큰따옴표를 써야 합니다. 10 | 11 | # 2. 백업 파일은 메인 백업 디렉터리에 저장해야 합니다. 12 | # 윈도우에서의 예: 13 | # target_dir = 'E:\\Backup' 14 | # macOS와 리눅스에서의 예: 15 | target_dir = '/Users/swa/backup' 16 | # 사용할 폴더로 이 값을 변경하는 것을 잊지 마세요. 17 | 18 | # 대상 디렉터리가 존재하지 않는 경우 생성합니다 19 | if not os.path.exists(target_dir): 20 | os.mkdir(target_dir) # make directory 21 | 22 | # 3. 파일은 zip 파일로 백업됩니다. 23 | # 4. 현재 날짜를 메인 디렉터리 내의 하위 디렉터리명으로 사용합니다. 24 | today = target_dir + os.sep + time.strftime('%Y%m%d') 25 | # 현재 시간을 zip 파일의 이름으로 사용합니다. 26 | now = time.strftime('%H%M%S') 27 | 28 | # 사용자에게서 텍스트를 입력받아 zip 파일의 이름을 만듭니다. 29 | comment = input('Enter a comment --> ') 30 | # 텍스트를 입력했는지 검사합니다. 31 | if len(comment) == 0: 32 | target = today + os.sep + now + '.zip' 33 | else: 34 | target = today + os.sep + now + '_' + 35 | comment.replace(' ', '_') + '.zip' 36 | 37 | # 하위 디렉터리가 존재하지 않으면 생성합니다 38 | if not os.path.exists(today): 39 | os.mkdir(today) 40 | print('Successfully created directory', today) 41 | 42 | # 5. zip 명령어를 사용해 파일을 zip 파일에 추가합니다 43 | zip_command = "zip -r {0} {1}".format(target, 44 | ' '.join(source)) 45 | 46 | # 백업 실행 47 | print('Zip command is:') 48 | print(zip_command) 49 | print('Running:') 50 | if os.system(zip_command) == 0: 51 | print('Successful backup to', target) 52 | else: 53 | print('Backup FAILED') 54 | -------------------------------------------------------------------------------- /programs/backup_ver4.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | # 1. 백업할 파일과 디렉터리는 리스트에 지정됩니다. 5 | # 윈도우에서의 예: 6 | # source = ['"C:\\My Documents"', 'C:\\Code'] 7 | # macOS와 리눅스에서의 예: 8 | source = ['/Users/swa/notes'] 9 | # 이름에 공백이 포함된 문자열 안에서는 큰따옴표를 써야 합니다. 10 | 11 | # 2. 백업 파일은 메인 백업 디렉터리에 저장해야 합니다. 12 | # 윈도우에서의 예: 13 | # target_dir = 'E:\\Backup' 14 | # macOS와 리눅스에서의 예: 15 | target_dir = '/Users/swa/backup' 16 | # 사용할 폴더로 이 값을 변경하는 것을 잊지 마세요. 17 | 18 | # 대상 디렉터리가 존재하지 않는 경우 생성합니다 19 | if not os.path.exists(target_dir): 20 | os.mkdir(target_dir) # make directory 21 | 22 | # 3. 파일은 zip 파일로 백업됩니다. 23 | # 4. 현재 날짜를 메인 디렉터리 내의 하위 디렉터리명으로 사용합니다. 24 | today = target_dir + os.sep + time.strftime('%Y%m%d') 25 | # 현재 시간을 zip 파일의 이름으로 사용합니다. 26 | now = time.strftime('%H%M%S') 27 | 28 | # 사용자에게서 텍스트를 입력받아 zip 파일의 이름을 만듭니다. 29 | comment = input('Enter a comment --> ') 30 | # 텍스트를 입력했는지 검사합니다. 31 | if len(comment) == 0: 32 | target = today + os.sep + now + '.zip' 33 | else: 34 | target = today + os.sep + now + '_' + \ 35 | comment.replace(' ', '_') + '.zip' 36 | 37 | # 하위 디렉터리가 존재하지 않으면 생성합니다 38 | if not os.path.exists(today): 39 | os.mkdir(today) 40 | print('Successfully created directory', today) 41 | 42 | # 5. zip 명령어를 사용해 파일을 zip 파일에 추가합니다 43 | zip_command = 'zip -r {0} {1}'.format(target, 44 | ' '.join(source)) 45 | 46 | # 백업 실행 47 | print('Zip command is:') 48 | print(zip_command) 49 | print('Running:') 50 | if os.system(zip_command) == 0: 51 | print('Successful backup to', target) 52 | else: 53 | print('Backup FAILED') 54 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-lunr/search-lunr.js: -------------------------------------------------------------------------------- 1 | require([ 2 | 'gitbook', 3 | 'jquery' 4 | ], function(gitbook, $) { 5 | // Define global search engine 6 | function LunrSearchEngine() { 7 | this.index = null; 8 | this.store = {}; 9 | this.name = 'LunrSearchEngine'; 10 | } 11 | 12 | // Initialize lunr by fetching the search index 13 | LunrSearchEngine.prototype.init = function() { 14 | var that = this; 15 | var d = $.Deferred(); 16 | 17 | $.getJSON(gitbook.state.basePath+'/search_index.json') 18 | .then(function(data) { 19 | // eslint-disable-next-line no-undef 20 | that.index = lunr.Index.load(data.index); 21 | that.store = data.store; 22 | d.resolve(); 23 | }); 24 | 25 | return d.promise(); 26 | }; 27 | 28 | // Search for a term and return results 29 | LunrSearchEngine.prototype.search = function(q, offset, length) { 30 | var that = this; 31 | var results = []; 32 | 33 | if (this.index) { 34 | results = $.map(this.index.search(q), function(result) { 35 | var doc = that.store[result.ref]; 36 | 37 | return { 38 | title: doc.title, 39 | url: doc.url, 40 | body: doc.summary || doc.body 41 | }; 42 | }); 43 | } 44 | 45 | return $.Deferred().resolve({ 46 | query: q, 47 | results: results.slice(0, length), 48 | count: results.length 49 | }).promise(); 50 | }; 51 | 52 | // Set gitbook research 53 | gitbook.events.bind('start', function(e, config) { 54 | var engine = gitbook.search.getEngine(); 55 | if (!engine) { 56 | gitbook.search.setEngine(LunrSearchEngine, config); 57 | } 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-sharing/buttons.js: -------------------------------------------------------------------------------- 1 | require(["gitbook", "lodash"], function(gitbook, _) { 2 | var SITES = { 3 | 'facebook': { 4 | 'label': 'Facebook', 5 | 'icon': 'fa fa-facebook', 6 | 'onClick': function(e) { 7 | e.preventDefault(); 8 | window.open("http://www.facebook.com/sharer/sharer.php?s=100&p[url]="+encodeURIComponent(location.href)); 9 | } 10 | }, 11 | 'twitter': { 12 | 'label': 'Twitter', 13 | 'icon': 'fa fa-twitter', 14 | 'onClick': function(e) { 15 | e.preventDefault(); 16 | window.open("http://twitter.com/home?status="+encodeURIComponent(document.title+" "+location.href)); 17 | } 18 | }, 19 | 'google': { 20 | 'label': 'Google+', 21 | 'icon': 'fa fa-google-plus', 22 | 'onClick': function(e) { 23 | e.preventDefault(); 24 | window.open("https://plus.google.com/share?url="+encodeURIComponent(location.href)); 25 | } 26 | }, 27 | 'weibo': { 28 | 'label': 'Weibo', 29 | 'icon': 'fa fa-weibo', 30 | 'onClick': function(e) { 31 | e.preventDefault(); 32 | window.open("http://service.weibo.com/share/share.php?content=utf-8&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title)); 33 | } 34 | }, 35 | 'instapaper': { 36 | 'label': 'Instapaper', 37 | 'icon': 'fa fa-instapaper', 38 | 'onClick': function(e) { 39 | e.preventDefault(); 40 | window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href)); 41 | } 42 | }, 43 | 'vk': { 44 | 'label': 'VK', 45 | 'icon': 'fa fa-vk', 46 | 'onClick': function(e) { 47 | e.preventDefault(); 48 | window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href)); 49 | } 50 | } 51 | }; 52 | 53 | 54 | 55 | gitbook.events.bind("start", function(e, config) { 56 | var opts = config.sharing; 57 | 58 | // Create dropdown menu 59 | var menu = _.chain(opts.all) 60 | .map(function(id) { 61 | var site = SITES[id]; 62 | 63 | return { 64 | text: site.label, 65 | onClick: site.onClick 66 | }; 67 | }) 68 | .compact() 69 | .value(); 70 | 71 | // Create main button with dropdown 72 | if (menu.length > 0) { 73 | gitbook.toolbar.createButton({ 74 | icon: 'fa fa-share-alt', 75 | label: 'Share', 76 | position: 'right', 77 | dropdown: [menu] 78 | }); 79 | } 80 | 81 | // Direct actions to share 82 | _.each(SITES, function(site, sideId) { 83 | if (!opts[sideId]) return; 84 | 85 | gitbook.toolbar.createButton({ 86 | icon: site.icon, 87 | label: site.text, 88 | position: 'right', 89 | onClick: site.onClick 90 | }); 91 | }); 92 | }); 93 | }); 94 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-highlight/ebook.css: -------------------------------------------------------------------------------- 1 | pre, 2 | code { 3 | /* http://jmblog.github.io/color-themes-for-highlightjs */ 4 | /* Tomorrow Comment */ 5 | /* Tomorrow Red */ 6 | /* Tomorrow Orange */ 7 | /* Tomorrow Yellow */ 8 | /* Tomorrow Green */ 9 | /* Tomorrow Aqua */ 10 | /* Tomorrow Blue */ 11 | /* Tomorrow Purple */ 12 | } 13 | pre .hljs-comment, 14 | code .hljs-comment, 15 | pre .hljs-title, 16 | code .hljs-title { 17 | color: #8e908c; 18 | } 19 | pre .hljs-variable, 20 | code .hljs-variable, 21 | pre .hljs-attribute, 22 | code .hljs-attribute, 23 | pre .hljs-tag, 24 | code .hljs-tag, 25 | pre .hljs-regexp, 26 | code .hljs-regexp, 27 | pre .ruby .hljs-constant, 28 | code .ruby .hljs-constant, 29 | pre .xml .hljs-tag .hljs-title, 30 | code .xml .hljs-tag .hljs-title, 31 | pre .xml .hljs-pi, 32 | code .xml .hljs-pi, 33 | pre .xml .hljs-doctype, 34 | code .xml .hljs-doctype, 35 | pre .html .hljs-doctype, 36 | code .html .hljs-doctype, 37 | pre .css .hljs-id, 38 | code .css .hljs-id, 39 | pre .css .hljs-class, 40 | code .css .hljs-class, 41 | pre .css .hljs-pseudo, 42 | code .css .hljs-pseudo { 43 | color: #c82829; 44 | } 45 | pre .hljs-number, 46 | code .hljs-number, 47 | pre .hljs-preprocessor, 48 | code .hljs-preprocessor, 49 | pre .hljs-pragma, 50 | code .hljs-pragma, 51 | pre .hljs-built_in, 52 | code .hljs-built_in, 53 | pre .hljs-literal, 54 | code .hljs-literal, 55 | pre .hljs-params, 56 | code .hljs-params, 57 | pre .hljs-constant, 58 | code .hljs-constant { 59 | color: #f5871f; 60 | } 61 | pre .ruby .hljs-class .hljs-title, 62 | code .ruby .hljs-class .hljs-title, 63 | pre .css .hljs-rules .hljs-attribute, 64 | code .css .hljs-rules .hljs-attribute { 65 | color: #eab700; 66 | } 67 | pre .hljs-string, 68 | code .hljs-string, 69 | pre .hljs-value, 70 | code .hljs-value, 71 | pre .hljs-inheritance, 72 | code .hljs-inheritance, 73 | pre .hljs-header, 74 | code .hljs-header, 75 | pre .ruby .hljs-symbol, 76 | code .ruby .hljs-symbol, 77 | pre .xml .hljs-cdata, 78 | code .xml .hljs-cdata { 79 | color: #718c00; 80 | } 81 | pre .css .hljs-hexcolor, 82 | code .css .hljs-hexcolor { 83 | color: #3e999f; 84 | } 85 | pre .hljs-function, 86 | code .hljs-function, 87 | pre .python .hljs-decorator, 88 | code .python .hljs-decorator, 89 | pre .python .hljs-title, 90 | code .python .hljs-title, 91 | pre .ruby .hljs-function .hljs-title, 92 | code .ruby .hljs-function .hljs-title, 93 | pre .ruby .hljs-title .hljs-keyword, 94 | code .ruby .hljs-title .hljs-keyword, 95 | pre .perl .hljs-sub, 96 | code .perl .hljs-sub, 97 | pre .javascript .hljs-title, 98 | code .javascript .hljs-title, 99 | pre .coffeescript .hljs-title, 100 | code .coffeescript .hljs-title { 101 | color: #4271ae; 102 | } 103 | pre .hljs-keyword, 104 | code .hljs-keyword, 105 | pre .javascript .hljs-function, 106 | code .javascript .hljs-function { 107 | color: #8959a8; 108 | } 109 | pre .hljs, 110 | code .hljs { 111 | display: block; 112 | background: white; 113 | color: #4d4d4c; 114 | padding: 0.5em; 115 | } 116 | pre .coffeescript .javascript, 117 | code .coffeescript .javascript, 118 | pre .javascript .xml, 119 | code .javascript .xml, 120 | pre .tex .hljs-formula, 121 | code .tex .hljs-formula, 122 | pre .xml .javascript, 123 | code .xml .javascript, 124 | pre .xml .vbscript, 125 | code .xml .vbscript, 126 | pre .xml .css, 127 | code .xml .css, 128 | pre .xml .hljs-cdata, 129 | code .xml .hljs-cdata { 130 | opacity: 0.5; 131 | } 132 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-search/search.js: -------------------------------------------------------------------------------- 1 | require([ 2 | "gitbook", 3 | "lodash" 4 | ], function(gitbook, _) { 5 | var index = null; 6 | var $searchInput, $searchForm; 7 | 8 | // Use a specific index 9 | function loadIndex(data) { 10 | index = lunr.Index.load(data); 11 | } 12 | 13 | // Fetch the search index 14 | function fetchIndex() { 15 | $.getJSON(gitbook.state.basePath+"/search_index.json") 16 | .then(loadIndex); 17 | } 18 | 19 | // Search for a term and return results 20 | function search(q) { 21 | if (!index) return; 22 | 23 | var results = _.chain(index.search(q)) 24 | .map(function(result) { 25 | var parts = result.ref.split("#") 26 | return { 27 | path: parts[0], 28 | hash: parts[1] 29 | } 30 | }) 31 | .value(); 32 | 33 | return results; 34 | } 35 | 36 | // Create search form 37 | function createForm(value) { 38 | if ($searchForm) $searchForm.remove(); 39 | 40 | $searchForm = $('
', { 41 | 'class': 'book-search', 42 | 'role': 'search' 43 | }); 44 | 45 | $searchInput = $('', { 46 | 'type': 'text', 47 | 'class': 'form-control', 48 | 'val': value, 49 | 'placeholder': 'Type to search' 50 | }); 51 | 52 | $searchInput.appendTo($searchForm); 53 | $searchForm.prependTo(gitbook.state.$book.find('.book-summary')); 54 | } 55 | 56 | // Return true if search is open 57 | function isSearchOpen() { 58 | return gitbook.state.$book.hasClass("with-search"); 59 | } 60 | 61 | // Toggle the search 62 | function toggleSearch(_state) { 63 | if (isSearchOpen() === _state) return; 64 | 65 | gitbook.state.$book.toggleClass("with-search", _state); 66 | 67 | // If search bar is open: focus input 68 | if (isSearchOpen()) { 69 | gitbook.sidebar.toggle(true); 70 | $searchInput.focus(); 71 | } else { 72 | $searchInput.blur(); 73 | $searchInput.val(""); 74 | gitbook.sidebar.filter(null); 75 | } 76 | } 77 | 78 | // Recover current search when page changed 79 | function recoverSearch() { 80 | var keyword = gitbook.storage.get("keyword", ""); 81 | 82 | createForm(keyword); 83 | 84 | if (keyword.length > 0) { 85 | if(!isSearchOpen()) { 86 | toggleSearch(); 87 | } 88 | gitbook.sidebar.filter(_.pluck(search(keyword), "path")); 89 | } 90 | }; 91 | 92 | 93 | gitbook.events.bind("start", function(config) { 94 | // Pre-fetch search index and create the form 95 | fetchIndex(); 96 | createForm(); 97 | 98 | // Type in search bar 99 | $(document).on("keyup", ".book-search input", function(e) { 100 | var key = (e.keyCode ? e.keyCode : e.which); 101 | var q = $(this).val(); 102 | 103 | if (key == 27) { 104 | e.preventDefault(); 105 | toggleSearch(false); 106 | return; 107 | } 108 | if (q.length == 0) { 109 | gitbook.sidebar.filter(null); 110 | gitbook.storage.remove("keyword"); 111 | } else { 112 | var results = search(q); 113 | gitbook.sidebar.filter( 114 | _.pluck(results, "path") 115 | ); 116 | gitbook.storage.set("keyword", q); 117 | } 118 | }); 119 | 120 | // Create the toggle search button 121 | gitbook.toolbar.createButton({ 122 | icon: 'fa fa-search', 123 | label: 'Search', 124 | position: 'left', 125 | onClick: toggleSearch 126 | }); 127 | 128 | // Bind keyboard to toggle search 129 | gitbook.keyboard.bind(['f'], toggleSearch) 130 | }); 131 | 132 | gitbook.events.bind("page.change", recoverSearch); 133 | }); 134 | 135 | 136 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-fontsettings/buttons.js: -------------------------------------------------------------------------------- 1 | require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) { 2 | var fontState; 3 | 4 | var THEMES = { 5 | "white": 0, 6 | "sepia": 1, 7 | "night": 2 8 | }; 9 | 10 | var FAMILY = { 11 | "serif": 0, 12 | "sans": 1 13 | }; 14 | 15 | // Save current font settings 16 | function saveFontSettings() { 17 | gitbook.storage.set("fontState", fontState); 18 | update(); 19 | } 20 | 21 | // Increase font size 22 | function enlargeFontSize(e) { 23 | e.preventDefault(); 24 | if (fontState.size >= 4) return; 25 | 26 | fontState.size++; 27 | saveFontSettings(); 28 | }; 29 | 30 | // Decrease font size 31 | function reduceFontSize(e) { 32 | e.preventDefault(); 33 | if (fontState.size <= 0) return; 34 | 35 | fontState.size--; 36 | saveFontSettings(); 37 | }; 38 | 39 | // Change font family 40 | function changeFontFamily(index, e) { 41 | e.preventDefault(); 42 | 43 | fontState.family = index; 44 | saveFontSettings(); 45 | }; 46 | 47 | // Change type of color 48 | function changeColorTheme(index, e) { 49 | e.preventDefault(); 50 | 51 | var $book = $(".book"); 52 | 53 | if (fontState.theme !== 0) 54 | $book.removeClass("color-theme-"+fontState.theme); 55 | 56 | fontState.theme = index; 57 | if (fontState.theme !== 0) 58 | $book.addClass("color-theme-"+fontState.theme); 59 | 60 | saveFontSettings(); 61 | }; 62 | 63 | function update() { 64 | var $book = gitbook.state.$book; 65 | 66 | $(".font-settings .font-family-list li").removeClass("active"); 67 | $(".font-settings .font-family-list li:nth-child("+(fontState.family+1)+")").addClass("active"); 68 | 69 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); 70 | $book.addClass("font-size-"+fontState.size); 71 | $book.addClass("font-family-"+fontState.family); 72 | 73 | if(fontState.theme !== 0) { 74 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); 75 | $book.addClass("color-theme-"+fontState.theme); 76 | } 77 | }; 78 | 79 | function init(config) { 80 | var $bookBody, $book; 81 | 82 | //Find DOM elements. 83 | $book = gitbook.state.$book; 84 | $bookBody = $book.find(".book-body"); 85 | 86 | // Instantiate font state object 87 | fontState = gitbook.storage.get("fontState", { 88 | size: config.size || 2, 89 | family: FAMILY[config.family || "sans"], 90 | theme: THEMES[config.theme || "white"] 91 | }); 92 | 93 | update(); 94 | }; 95 | 96 | 97 | gitbook.events.bind("start", function(e, config) { 98 | var opts = config.fontsettings; 99 | 100 | // Create buttons in toolbar 101 | gitbook.toolbar.createButton({ 102 | icon: 'fa fa-font', 103 | label: 'Font Settings', 104 | className: 'font-settings', 105 | dropdown: [ 106 | [ 107 | { 108 | text: 'A', 109 | className: 'font-reduce', 110 | onClick: reduceFontSize 111 | }, 112 | { 113 | text: 'A', 114 | className: 'font-enlarge', 115 | onClick: enlargeFontSize 116 | } 117 | ], 118 | [ 119 | { 120 | text: 'Serif', 121 | onClick: _.partial(changeFontFamily, 0) 122 | }, 123 | { 124 | text: 'Sans', 125 | onClick: _.partial(changeFontFamily, 1) 126 | } 127 | ], 128 | [ 129 | { 130 | text: 'White', 131 | onClick: _.partial(changeColorTheme, 0) 132 | }, 133 | { 134 | text: 'Sepia', 135 | onClick: _.partial(changeColorTheme, 1) 136 | }, 137 | { 138 | text: 'Night', 139 | onClick: _.partial(changeColorTheme, 2) 140 | } 141 | ] 142 | ] 143 | }); 144 | 145 | 146 | // Init current settings 147 | init(opts); 148 | }); 149 | }); 150 | 151 | 152 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-fontsettings/fontsettings.js: -------------------------------------------------------------------------------- 1 | require(['gitbook', 'jquery'], function(gitbook, $) { 2 | // Configuration 3 | var MAX_SIZE = 4, 4 | MIN_SIZE = 0, 5 | BUTTON_ID; 6 | 7 | // Current fontsettings state 8 | var fontState; 9 | 10 | // Default themes 11 | var THEMES = [ 12 | { 13 | config: 'white', 14 | text: 'White', 15 | id: 0 16 | }, 17 | { 18 | config: 'sepia', 19 | text: 'Sepia', 20 | id: 1 21 | }, 22 | { 23 | config: 'night', 24 | text: 'Night', 25 | id: 2 26 | } 27 | ]; 28 | 29 | // Default font families 30 | var FAMILIES = [ 31 | { 32 | config: 'serif', 33 | text: 'Serif', 34 | id: 0 35 | }, 36 | { 37 | config: 'sans', 38 | text: 'Sans', 39 | id: 1 40 | } 41 | ]; 42 | 43 | // Return configured themes 44 | function getThemes() { 45 | return THEMES; 46 | } 47 | 48 | // Modify configured themes 49 | function setThemes(themes) { 50 | THEMES = themes; 51 | updateButtons(); 52 | } 53 | 54 | // Return configured font families 55 | function getFamilies() { 56 | return FAMILIES; 57 | } 58 | 59 | // Modify configured font families 60 | function setFamilies(families) { 61 | FAMILIES = families; 62 | updateButtons(); 63 | } 64 | 65 | // Save current font settings 66 | function saveFontSettings() { 67 | gitbook.storage.set('fontState', fontState); 68 | update(); 69 | } 70 | 71 | // Increase font size 72 | function enlargeFontSize(e) { 73 | e.preventDefault(); 74 | if (fontState.size >= MAX_SIZE) return; 75 | 76 | fontState.size++; 77 | saveFontSettings(); 78 | } 79 | 80 | // Decrease font size 81 | function reduceFontSize(e) { 82 | e.preventDefault(); 83 | if (fontState.size <= MIN_SIZE) return; 84 | 85 | fontState.size--; 86 | saveFontSettings(); 87 | } 88 | 89 | // Change font family 90 | function changeFontFamily(configName, e) { 91 | if (e && e instanceof Event) { 92 | e.preventDefault(); 93 | } 94 | 95 | var familyId = getFontFamilyId(configName); 96 | fontState.family = familyId; 97 | saveFontSettings(); 98 | } 99 | 100 | // Change type of color theme 101 | function changeColorTheme(configName, e) { 102 | if (e && e instanceof Event) { 103 | e.preventDefault(); 104 | } 105 | 106 | var $book = gitbook.state.$book; 107 | 108 | // Remove currently applied color theme 109 | if (fontState.theme !== 0) 110 | $book.removeClass('color-theme-'+fontState.theme); 111 | 112 | // Set new color theme 113 | var themeId = getThemeId(configName); 114 | fontState.theme = themeId; 115 | if (fontState.theme !== 0) 116 | $book.addClass('color-theme-'+fontState.theme); 117 | 118 | saveFontSettings(); 119 | } 120 | 121 | // Return the correct id for a font-family config key 122 | // Default to first font-family 123 | function getFontFamilyId(configName) { 124 | // Search for plugin configured font family 125 | var configFamily = $.grep(FAMILIES, function(family) { 126 | return family.config == configName; 127 | })[0]; 128 | // Fallback to default font family 129 | return (!!configFamily)? configFamily.id : 0; 130 | } 131 | 132 | // Return the correct id for a theme config key 133 | // Default to first theme 134 | function getThemeId(configName) { 135 | // Search for plugin configured theme 136 | var configTheme = $.grep(THEMES, function(theme) { 137 | return theme.config == configName; 138 | })[0]; 139 | // Fallback to default theme 140 | return (!!configTheme)? configTheme.id : 0; 141 | } 142 | 143 | function update() { 144 | var $book = gitbook.state.$book; 145 | 146 | $('.font-settings .font-family-list li').removeClass('active'); 147 | $('.font-settings .font-family-list li:nth-child('+(fontState.family+1)+')').addClass('active'); 148 | 149 | $book[0].className = $book[0].className.replace(/\bfont-\S+/g, ''); 150 | $book.addClass('font-size-'+fontState.size); 151 | $book.addClass('font-family-'+fontState.family); 152 | 153 | if(fontState.theme !== 0) { 154 | $book[0].className = $book[0].className.replace(/\bcolor-theme-\S+/g, ''); 155 | $book.addClass('color-theme-'+fontState.theme); 156 | } 157 | } 158 | 159 | function init(config) { 160 | // Search for plugin configured font family 161 | var configFamily = getFontFamilyId(config.family), 162 | configTheme = getThemeId(config.theme); 163 | 164 | // Instantiate font state object 165 | fontState = gitbook.storage.get('fontState', { 166 | size: config.size || 2, 167 | family: configFamily, 168 | theme: configTheme 169 | }); 170 | 171 | update(); 172 | } 173 | 174 | function updateButtons() { 175 | // Remove existing fontsettings buttons 176 | if (!!BUTTON_ID) { 177 | gitbook.toolbar.removeButton(BUTTON_ID); 178 | } 179 | 180 | // Create buttons in toolbar 181 | BUTTON_ID = gitbook.toolbar.createButton({ 182 | icon: 'fa fa-font', 183 | label: 'Font Settings', 184 | className: 'font-settings', 185 | dropdown: [ 186 | [ 187 | { 188 | text: 'A', 189 | className: 'font-reduce', 190 | onClick: reduceFontSize 191 | }, 192 | { 193 | text: 'A', 194 | className: 'font-enlarge', 195 | onClick: enlargeFontSize 196 | } 197 | ], 198 | $.map(FAMILIES, function(family) { 199 | family.onClick = function(e) { 200 | return changeFontFamily(family.config, e); 201 | }; 202 | 203 | return family; 204 | }), 205 | $.map(THEMES, function(theme) { 206 | theme.onClick = function(e) { 207 | return changeColorTheme(theme.config, e); 208 | }; 209 | 210 | return theme; 211 | }) 212 | ] 213 | }); 214 | } 215 | 216 | // Init configuration at start 217 | gitbook.events.bind('start', function(e, config) { 218 | var opts = config.fontsettings; 219 | 220 | // Generate buttons at start 221 | updateButtons(); 222 | 223 | // Init current settings 224 | init(opts); 225 | }); 226 | 227 | // Expose API 228 | gitbook.fontsettings = { 229 | enlargeFontSize: enlargeFontSize, 230 | reduceFontSize: reduceFontSize, 231 | setTheme: changeColorTheme, 232 | setFamily: changeFontFamily, 233 | getThemes: getThemes, 234 | setThemes: setThemes, 235 | getFamilies: getFamilies, 236 | setFamilies: setFamilies 237 | }; 238 | }); 239 | 240 | 241 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-fontsettings/website.css: -------------------------------------------------------------------------------- 1 | /* 2 | * Theme 1 3 | */ 4 | .color-theme-1 .dropdown-menu { 5 | background-color: #111111; 6 | border-color: #7e888b; 7 | } 8 | .color-theme-1 .dropdown-menu .dropdown-caret .caret-inner { 9 | border-bottom: 9px solid #111111; 10 | } 11 | .color-theme-1 .dropdown-menu .buttons { 12 | border-color: #7e888b; 13 | } 14 | .color-theme-1 .dropdown-menu .button { 15 | color: #afa790; 16 | } 17 | .color-theme-1 .dropdown-menu .button:hover { 18 | color: #73553c; 19 | } 20 | /* 21 | * Theme 2 22 | */ 23 | .color-theme-2 .dropdown-menu { 24 | background-color: #2d3143; 25 | border-color: #272a3a; 26 | } 27 | .color-theme-2 .dropdown-menu .dropdown-caret .caret-inner { 28 | border-bottom: 9px solid #2d3143; 29 | } 30 | .color-theme-2 .dropdown-menu .buttons { 31 | border-color: #272a3a; 32 | } 33 | .color-theme-2 .dropdown-menu .button { 34 | color: #62677f; 35 | } 36 | .color-theme-2 .dropdown-menu .button:hover { 37 | color: #f4f4f5; 38 | } 39 | .book .book-header .font-settings .font-enlarge { 40 | line-height: 30px; 41 | font-size: 1.4em; 42 | } 43 | .book .book-header .font-settings .font-reduce { 44 | line-height: 30px; 45 | font-size: 1em; 46 | } 47 | .book.color-theme-1 .book-body { 48 | color: #704214; 49 | background: #f3eacb; 50 | } 51 | .book.color-theme-1 .book-body .page-wrapper .page-inner section { 52 | background: #f3eacb; 53 | } 54 | .book.color-theme-2 .book-body { 55 | color: #bdcadb; 56 | background: #1c1f2b; 57 | } 58 | .book.color-theme-2 .book-body .page-wrapper .page-inner section { 59 | background: #1c1f2b; 60 | } 61 | .book.font-size-0 .book-body .page-inner section { 62 | font-size: 1.2rem; 63 | } 64 | .book.font-size-1 .book-body .page-inner section { 65 | font-size: 1.4rem; 66 | } 67 | .book.font-size-2 .book-body .page-inner section { 68 | font-size: 1.6rem; 69 | } 70 | .book.font-size-3 .book-body .page-inner section { 71 | font-size: 2.2rem; 72 | } 73 | .book.font-size-4 .book-body .page-inner section { 74 | font-size: 4rem; 75 | } 76 | .book.font-family-0 { 77 | font-family: Georgia, serif; 78 | } 79 | .book.font-family-1 { 80 | font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; 81 | } 82 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal { 83 | color: #704214; 84 | } 85 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal a { 86 | color: inherit; 87 | } 88 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 89 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2, 90 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h3, 91 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h4, 92 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h5, 93 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 94 | color: inherit; 95 | } 96 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h1, 97 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h2 { 98 | border-color: inherit; 99 | } 100 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal h6 { 101 | color: inherit; 102 | } 103 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal hr { 104 | background-color: inherit; 105 | } 106 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal blockquote { 107 | border-color: inherit; 108 | } 109 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal pre, 110 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal code { 111 | background: #fdf6e3; 112 | color: #657b83; 113 | border-color: #f8df9c; 114 | } 115 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal .highlight { 116 | background-color: inherit; 117 | } 118 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table th, 119 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table td { 120 | border-color: #f5d06c; 121 | } 122 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr { 123 | color: inherit; 124 | background-color: #fdf6e3; 125 | border-color: #444444; 126 | } 127 | .book.color-theme-1 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 128 | background-color: #fbeecb; 129 | } 130 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal { 131 | color: #bdcadb; 132 | } 133 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal a { 134 | color: #3eb1d0; 135 | } 136 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 137 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2, 138 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h3, 139 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h4, 140 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h5, 141 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 142 | color: #fffffa; 143 | } 144 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h1, 145 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h2 { 146 | border-color: #373b4e; 147 | } 148 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal h6 { 149 | color: #373b4e; 150 | } 151 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal hr { 152 | background-color: #373b4e; 153 | } 154 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal blockquote { 155 | border-color: #373b4e; 156 | } 157 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal pre, 158 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal code { 159 | color: #9dbed8; 160 | background: #2d3143; 161 | border-color: #2d3143; 162 | } 163 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal .highlight { 164 | background-color: #282a39; 165 | } 166 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table th, 167 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table td { 168 | border-color: #3b3f54; 169 | } 170 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr { 171 | color: #b6c2d2; 172 | background-color: #2d3143; 173 | border-color: #3b3f54; 174 | } 175 | .book.color-theme-2 .book-body .page-wrapper .page-inner section.normal table tr:nth-child(2n) { 176 | background-color: #35394b; 177 | } 178 | .book.color-theme-1 .book-header { 179 | color: #afa790; 180 | background: transparent; 181 | } 182 | .book.color-theme-1 .book-header .btn { 183 | color: #afa790; 184 | } 185 | .book.color-theme-1 .book-header .btn:hover { 186 | color: #73553c; 187 | background: none; 188 | } 189 | .book.color-theme-1 .book-header h1 { 190 | color: #704214; 191 | } 192 | .book.color-theme-2 .book-header { 193 | color: #7e888b; 194 | background: transparent; 195 | } 196 | .book.color-theme-2 .book-header .btn { 197 | color: #3b3f54; 198 | } 199 | .book.color-theme-2 .book-header .btn:hover { 200 | color: #fffff5; 201 | background: none; 202 | } 203 | .book.color-theme-2 .book-header h1 { 204 | color: #bdcadb; 205 | } 206 | .book.color-theme-1 .book-body .navigation { 207 | color: #afa790; 208 | } 209 | .book.color-theme-1 .book-body .navigation:hover { 210 | color: #73553c; 211 | } 212 | .book.color-theme-2 .book-body .navigation { 213 | color: #383f52; 214 | } 215 | .book.color-theme-2 .book-body .navigation:hover { 216 | color: #fffff5; 217 | } 218 | /* 219 | * Theme 1 220 | */ 221 | .book.color-theme-1 .book-summary { 222 | color: #afa790; 223 | background: #111111; 224 | border-right: 1px solid rgba(0, 0, 0, 0.07); 225 | } 226 | .book.color-theme-1 .book-summary .book-search { 227 | background: transparent; 228 | } 229 | .book.color-theme-1 .book-summary .book-search input, 230 | .book.color-theme-1 .book-summary .book-search input:focus { 231 | border: 1px solid transparent; 232 | } 233 | .book.color-theme-1 .book-summary ul.summary li.divider { 234 | background: #7e888b; 235 | box-shadow: none; 236 | } 237 | .book.color-theme-1 .book-summary ul.summary li i.fa-check { 238 | color: #33cc33; 239 | } 240 | .book.color-theme-1 .book-summary ul.summary li.done > a { 241 | color: #877f6a; 242 | } 243 | .book.color-theme-1 .book-summary ul.summary li a, 244 | .book.color-theme-1 .book-summary ul.summary li span { 245 | color: #877f6a; 246 | background: transparent; 247 | font-weight: normal; 248 | } 249 | .book.color-theme-1 .book-summary ul.summary li.active > a, 250 | .book.color-theme-1 .book-summary ul.summary li a:hover { 251 | color: #704214; 252 | background: transparent; 253 | font-weight: normal; 254 | } 255 | /* 256 | * Theme 2 257 | */ 258 | .book.color-theme-2 .book-summary { 259 | color: #bcc1d2; 260 | background: #2d3143; 261 | border-right: none; 262 | } 263 | .book.color-theme-2 .book-summary .book-search { 264 | background: transparent; 265 | } 266 | .book.color-theme-2 .book-summary .book-search input, 267 | .book.color-theme-2 .book-summary .book-search input:focus { 268 | border: 1px solid transparent; 269 | } 270 | .book.color-theme-2 .book-summary ul.summary li.divider { 271 | background: #272a3a; 272 | box-shadow: none; 273 | } 274 | .book.color-theme-2 .book-summary ul.summary li i.fa-check { 275 | color: #33cc33; 276 | } 277 | .book.color-theme-2 .book-summary ul.summary li.done > a { 278 | color: #62687f; 279 | } 280 | .book.color-theme-2 .book-summary ul.summary li a, 281 | .book.color-theme-2 .book-summary ul.summary li span { 282 | color: #c1c6d7; 283 | background: transparent; 284 | font-weight: 600; 285 | } 286 | .book.color-theme-2 .book-summary ul.summary li.active > a, 287 | .book.color-theme-2 .book-summary ul.summary li a:hover { 288 | color: #f4f4f5; 289 | background: #252737; 290 | font-weight: 600; 291 | } 292 | -------------------------------------------------------------------------------- /gitbook/gitbook-plugin-lunr/lunr.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * lunr - http://lunrjs.com - A bit like Solr, but much smaller and not as bright - 0.5.12 3 | * Copyright (C) 2015 Oliver Nightingale 4 | * MIT Licensed 5 | * @license 6 | */ 7 | !function(){var t=function(e){var n=new t.Index;return n.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),e&&e.call(n,n),n};t.version="0.5.12",t.utils={},t.utils.warn=function(t){return function(e){t.console&&console.warn&&console.warn(e)}}(this),t.EventEmitter=function(){this.events={}},t.EventEmitter.prototype.addListener=function(){var t=Array.prototype.slice.call(arguments),e=t.pop(),n=t;if("function"!=typeof e)throw new TypeError("last argument must be a function");n.forEach(function(t){this.hasHandler(t)||(this.events[t]=[]),this.events[t].push(e)},this)},t.EventEmitter.prototype.removeListener=function(t,e){if(this.hasHandler(t)){var n=this.events[t].indexOf(e);this.events[t].splice(n,1),this.events[t].length||delete this.events[t]}},t.EventEmitter.prototype.emit=function(t){if(this.hasHandler(t)){var e=Array.prototype.slice.call(arguments,1);this.events[t].forEach(function(t){t.apply(void 0,e)})}},t.EventEmitter.prototype.hasHandler=function(t){return t in this.events},t.tokenizer=function(t){return arguments.length&&null!=t&&void 0!=t?Array.isArray(t)?t.map(function(t){return t.toLowerCase()}):t.toString().trim().toLowerCase().split(/[\s\-]+/):[]},t.Pipeline=function(){this._stack=[]},t.Pipeline.registeredFunctions={},t.Pipeline.registerFunction=function(e,n){n in this.registeredFunctions&&t.utils.warn("Overwriting existing registered function: "+n),e.label=n,t.Pipeline.registeredFunctions[e.label]=e},t.Pipeline.warnIfFunctionNotRegistered=function(e){var n=e.label&&e.label in this.registeredFunctions;n||t.utils.warn("Function is not registered with pipeline. This may cause problems when serialising the index.\n",e)},t.Pipeline.load=function(e){var n=new t.Pipeline;return e.forEach(function(e){var i=t.Pipeline.registeredFunctions[e];if(!i)throw new Error("Cannot load un-registered function: "+e);n.add(i)}),n},t.Pipeline.prototype.add=function(){var e=Array.prototype.slice.call(arguments);e.forEach(function(e){t.Pipeline.warnIfFunctionNotRegistered(e),this._stack.push(e)},this)},t.Pipeline.prototype.after=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");i+=1,this._stack.splice(i,0,n)},t.Pipeline.prototype.before=function(e,n){t.Pipeline.warnIfFunctionNotRegistered(n);var i=this._stack.indexOf(e);if(-1==i)throw new Error("Cannot find existingFn");this._stack.splice(i,0,n)},t.Pipeline.prototype.remove=function(t){var e=this._stack.indexOf(t);-1!=e&&this._stack.splice(e,1)},t.Pipeline.prototype.run=function(t){for(var e=[],n=t.length,i=this._stack.length,o=0;n>o;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(en.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t1;){if(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]h[o]&&o++:(n.add(a[i]),i++,o++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(l),p=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,y=/^(.+?)(ed|ing)$/,g=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=y,s.test(n)){var T=s.exec(n);s=u,s.test(T[1])&&(s=g,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,l=x,a.test(n)?n+="e":h.test(n)?(s=g,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=g,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==e?e:void 0},t.stopWordFilter.stopWords={a:"a",able:"able",about:"about",across:"across",after:"after",all:"all",almost:"almost",also:"also",am:"am",among:"among",an:"an",and:"and",any:"any",are:"are",as:"as",at:"at",be:"be",because:"because",been:"been",but:"but",by:"by",can:"can",cannot:"cannot",could:"could",dear:"dear",did:"did","do":"do",does:"does",either:"either","else":"else",ever:"ever",every:"every","for":"for",from:"from",get:"get",got:"got",had:"had",has:"has",have:"have",he:"he",her:"her",hers:"hers",him:"him",his:"his",how:"how",however:"however",i:"i","if":"if","in":"in",into:"into",is:"is",it:"it",its:"its",just:"just",least:"least",let:"let",like:"like",likely:"likely",may:"may",me:"me",might:"might",most:"most",must:"must",my:"my",neither:"neither",no:"no",nor:"nor",not:"not",of:"of",off:"off",often:"often",on:"on",only:"only",or:"or",other:"other",our:"our",own:"own",rather:"rather",said:"said",say:"say",says:"says",she:"she",should:"should",since:"since",so:"so",some:"some",than:"than",that:"that",the:"the",their:"their",them:"them",then:"then",there:"there",these:"these",they:"they","this":"this",tis:"tis",to:"to",too:"too",twas:"twas",us:"us",wants:"wants",was:"was",we:"we",were:"were",what:"what",when:"when",where:"where",which:"which","while":"while",who:"who",whom:"whom",why:"why",will:"will","with":"with",would:"would",yet:"yet",you:"you",your:"your"},t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){var e=t.replace(/^\W+/,"").replace(/\W+$/,"");return""===e?void 0:e},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;no;o++){for(var r=t[o],s=0;i>s&&(r=this._stack[s](r,o,t),void 0!==r);s++);void 0!==r&&e.push(r)}return e},t.Pipeline.prototype.reset=function(){this._stack=[]},t.Pipeline.prototype.toJSON=function(){return this._stack.map(function(e){return t.Pipeline.warnIfFunctionNotRegistered(e),e.label})},t.Vector=function(){this._magnitude=null,this.list=void 0,this.length=0},t.Vector.Node=function(t,e,n){this.idx=t,this.val=e,this.next=n},t.Vector.prototype.insert=function(e,n){this._magnitude=void 0;var i=this.list;if(!i)return this.list=new t.Vector.Node(e,n,i),this.length++;if(en.idx?n=n.next:(i+=e.val*n.val,e=e.next,n=n.next);return i},t.Vector.prototype.similarity=function(t){return this.dot(t)/(this.magnitude()*t.magnitude())},t.SortedSet=function(){this.length=0,this.elements=[]},t.SortedSet.load=function(t){var e=new this;return e.elements=t,e.length=t.length,e},t.SortedSet.prototype.add=function(){var t,e;for(t=0;t1;){if(r===t)return o;t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o]}return r===t?o:-1},t.SortedSet.prototype.locationFor=function(t){for(var e=0,n=this.elements.length,i=n-e,o=e+Math.floor(i/2),r=this.elements[o];i>1;)t>r&&(e=o),r>t&&(n=o),i=n-e,o=e+Math.floor(i/2),r=this.elements[o];return r>t?o:t>r?o+1:void 0},t.SortedSet.prototype.intersect=function(e){for(var n=new t.SortedSet,i=0,o=0,r=this.length,s=e.length,a=this.elements,h=e.elements;;){if(i>r-1||o>s-1)break;a[i]!==h[o]?a[i]h[o]&&o++:(n.add(a[i]),i++,o++)}return n},t.SortedSet.prototype.clone=function(){var e=new t.SortedSet;return e.elements=this.toArray(),e.length=e.elements.length,e},t.SortedSet.prototype.union=function(t){var e,n,i;return this.length>=t.length?(e=this,n=t):(e=t,n=this),i=e.clone(),i.add.apply(i,n.toArray()),i},t.SortedSet.prototype.toJSON=function(){return this.toArray()},t.Index=function(){this._fields=[],this._ref="id",this.pipeline=new t.Pipeline,this.documentStore=new t.Store,this.tokenStore=new t.TokenStore,this.corpusTokens=new t.SortedSet,this.eventEmitter=new t.EventEmitter,this._idfCache={},this.on("add","remove","update",function(){this._idfCache={}}.bind(this))},t.Index.prototype.on=function(){var t=Array.prototype.slice.call(arguments);return this.eventEmitter.addListener.apply(this.eventEmitter,t)},t.Index.prototype.off=function(t,e){return this.eventEmitter.removeListener(t,e)},t.Index.load=function(e){e.version!==t.version&&t.utils.warn("version mismatch: current "+t.version+" importing "+e.version);var n=new this;return n._fields=e.fields,n._ref=e.ref,n.documentStore=t.Store.load(e.documentStore),n.tokenStore=t.TokenStore.load(e.tokenStore),n.corpusTokens=t.SortedSet.load(e.corpusTokens),n.pipeline=t.Pipeline.load(e.pipeline),n},t.Index.prototype.field=function(t,e){var e=e||{},n={name:t,boost:e.boost||1};return this._fields.push(n),this},t.Index.prototype.ref=function(t){return this._ref=t,this},t.Index.prototype.add=function(e,n){var i={},o=new t.SortedSet,r=e[this._ref],n=void 0===n?!0:n;this._fields.forEach(function(n){var r=this.pipeline.run(t.tokenizer(e[n.name]));i[n.name]=r,t.SortedSet.prototype.add.apply(o,r)},this),this.documentStore.set(r,o),t.SortedSet.prototype.add.apply(this.corpusTokens,o.toArray());for(var s=0;s0&&(i=1+Math.log(this.documentStore.length/n)),this._idfCache[e]=i},t.Index.prototype.search=function(e){var n=this.pipeline.run(t.tokenizer(e)),i=new t.Vector,o=[],r=this._fields.reduce(function(t,e){return t+e.boost},0),s=n.some(function(t){return this.tokenStore.has(t)},this);if(!s)return[];n.forEach(function(e,n,s){var a=1/s.length*this._fields.length*r,h=this,l=this.tokenStore.expand(e).reduce(function(n,o){var r=h.corpusTokens.indexOf(o),s=h.idf(o),l=1,u=new t.SortedSet;if(o!==e){var c=Math.max(3,o.length-e.length);l=1/Math.log(c)}return r>-1&&i.insert(r,a*s*l),Object.keys(h.tokenStore.get(o)).forEach(function(t){u.add(t)}),n.union(u)},new t.SortedSet);o.push(l)},this);var a=o.reduce(function(t,e){return t.intersect(e)});return a.map(function(t){return{ref:t,score:i.similarity(this.documentVector(t))}},this).sort(function(t,e){return e.score-t.score})},t.Index.prototype.documentVector=function(e){for(var n=this.documentStore.get(e),i=n.length,o=new t.Vector,r=0;i>r;r++){var s=n.elements[r],a=this.tokenStore.get(s)[e].tf,h=this.idf(s);o.insert(this.corpusTokens.indexOf(s),a*h)}return o},t.Index.prototype.toJSON=function(){return{version:t.version,fields:this._fields,ref:this._ref,documentStore:this.documentStore.toJSON(),tokenStore:this.tokenStore.toJSON(),corpusTokens:this.corpusTokens.toJSON(),pipeline:this.pipeline.toJSON()}},t.Index.prototype.use=function(t){var e=Array.prototype.slice.call(arguments,1);e.unshift(this),t.apply(this,e)},t.Store=function(){this.store={},this.length=0},t.Store.load=function(e){var n=new this;return n.length=e.length,n.store=Object.keys(e.store).reduce(function(n,i){return n[i]=t.SortedSet.load(e.store[i]),n},{}),n},t.Store.prototype.set=function(t,e){this.has(t)||this.length++,this.store[t]=e},t.Store.prototype.get=function(t){return this.store[t]},t.Store.prototype.has=function(t){return t in this.store},t.Store.prototype.remove=function(t){this.has(t)&&(delete this.store[t],this.length--)},t.Store.prototype.toJSON=function(){return{store:this.store,length:this.length}},t.stemmer=function(){var t={ational:"ate",tional:"tion",enci:"ence",anci:"ance",izer:"ize",bli:"ble",alli:"al",entli:"ent",eli:"e",ousli:"ous",ization:"ize",ation:"ate",ator:"ate",alism:"al",iveness:"ive",fulness:"ful",ousness:"ous",aliti:"al",iviti:"ive",biliti:"ble",logi:"log"},e={icate:"ic",ative:"",alize:"al",iciti:"ic",ical:"ic",ful:"",ness:""},n="[^aeiou]",i="[aeiouy]",o=n+"[^aeiouy]*",r=i+"[aeiou]*",s="^("+o+")?"+r+o,a="^("+o+")?"+r+o+"("+r+")?$",h="^("+o+")?"+r+o+r+o,l="^("+o+")?"+i,u=new RegExp(s),c=new RegExp(h),f=new RegExp(a),d=new RegExp(l),p=/^(.+?)(ss|i)es$/,m=/^(.+?)([^s])s$/,v=/^(.+?)eed$/,y=/^(.+?)(ed|ing)$/,g=/.$/,S=/(at|bl|iz)$/,w=new RegExp("([^aeiouylsz])\\1$"),x=new RegExp("^"+o+i+"[^aeiouwxy]$"),k=/^(.+?[^aeiou])y$/,b=/^(.+?)(ational|tional|enci|anci|izer|bli|alli|entli|eli|ousli|ization|ation|ator|alism|iveness|fulness|ousness|aliti|iviti|biliti|logi)$/,E=/^(.+?)(icate|ative|alize|iciti|ical|ful|ness)$/,_=/^(.+?)(al|ance|ence|er|ic|able|ible|ant|ement|ment|ent|ou|ism|ate|iti|ous|ive|ize)$/,F=/^(.+?)(s|t)(ion)$/,O=/^(.+?)e$/,P=/ll$/,N=new RegExp("^"+o+i+"[^aeiouwxy]$"),T=function(n){var i,o,r,s,a,h,l;if(n.length<3)return n;if(r=n.substr(0,1),"y"==r&&(n=r.toUpperCase()+n.substr(1)),s=p,a=m,s.test(n)?n=n.replace(s,"$1$2"):a.test(n)&&(n=n.replace(a,"$1$2")),s=v,a=y,s.test(n)){var T=s.exec(n);s=u,s.test(T[1])&&(s=g,n=n.replace(s,""))}else if(a.test(n)){var T=a.exec(n);i=T[1],a=d,a.test(i)&&(n=i,a=S,h=w,l=x,a.test(n)?n+="e":h.test(n)?(s=g,n=n.replace(s,"")):l.test(n)&&(n+="e"))}if(s=k,s.test(n)){var T=s.exec(n);i=T[1],n=i+"i"}if(s=b,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+t[o])}if(s=E,s.test(n)){var T=s.exec(n);i=T[1],o=T[2],s=u,s.test(i)&&(n=i+e[o])}if(s=_,a=F,s.test(n)){var T=s.exec(n);i=T[1],s=c,s.test(i)&&(n=i)}else if(a.test(n)){var T=a.exec(n);i=T[1]+T[2],a=c,a.test(i)&&(n=i)}if(s=O,s.test(n)){var T=s.exec(n);i=T[1],s=c,a=f,h=N,(s.test(i)||a.test(i)&&!h.test(i))&&(n=i)}return s=P,a=c,s.test(n)&&a.test(n)&&(s=g,n=n.replace(s,"")),"y"==r&&(n=r.toLowerCase()+n.substr(1)),n};return T}(),t.Pipeline.registerFunction(t.stemmer,"stemmer"),t.stopWordFilter=function(e){return e&&t.stopWordFilter.stopWords[e]!==e?e:void 0},t.stopWordFilter.stopWords={a:"a",able:"able",about:"about",across:"across",after:"after",all:"all",almost:"almost",also:"also",am:"am",among:"among",an:"an",and:"and",any:"any",are:"are",as:"as",at:"at",be:"be",because:"because",been:"been",but:"but",by:"by",can:"can",cannot:"cannot",could:"could",dear:"dear",did:"did","do":"do",does:"does",either:"either","else":"else",ever:"ever",every:"every","for":"for",from:"from",get:"get",got:"got",had:"had",has:"has",have:"have",he:"he",her:"her",hers:"hers",him:"him",his:"his",how:"how",however:"however",i:"i","if":"if","in":"in",into:"into",is:"is",it:"it",its:"its",just:"just",least:"least",let:"let",like:"like",likely:"likely",may:"may",me:"me",might:"might",most:"most",must:"must",my:"my",neither:"neither",no:"no",nor:"nor",not:"not",of:"of",off:"off",often:"often",on:"on",only:"only",or:"or",other:"other",our:"our",own:"own",rather:"rather",said:"said",say:"say",says:"says",she:"she",should:"should",since:"since",so:"so",some:"some",than:"than",that:"that",the:"the",their:"their",them:"them",then:"then",there:"there",these:"these",they:"they","this":"this",tis:"tis",to:"to",too:"too",twas:"twas",us:"us",wants:"wants",was:"was",we:"we",were:"were",what:"what",when:"when",where:"where",which:"which","while":"while",who:"who",whom:"whom",why:"why",will:"will","with":"with",would:"would",yet:"yet",you:"you",your:"your"},t.Pipeline.registerFunction(t.stopWordFilter,"stopWordFilter"),t.trimmer=function(t){var e=t.replace(/^\W+/,"").replace(/\W+$/,"");return""===e?void 0:e},t.Pipeline.registerFunction(t.trimmer,"trimmer"),t.TokenStore=function(){this.root={docs:{}},this.length=0},t.TokenStore.load=function(t){var e=new this;return e.root=t.root,e.length=t.length,e},t.TokenStore.prototype.add=function(t,e,n){var n=n||this.root,i=t[0],o=t.slice(1);return i in n||(n[i]={docs:{}}),0===o.length?(n[i].docs[e.ref]=e,void(this.length+=1)):this.add(o,e,n[i])},t.TokenStore.prototype.has=function(t){if(!t)return!1;for(var e=this.root,n=0;n 3 | 4 | 5 | 6 | 7 | 피드백 · GitBook 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | 425 | 426 | 427 |
428 | 429 |
430 | 431 |
432 | 433 | 434 | 435 | 444 | 445 | 446 | 447 | 448 |
449 |
450 | 451 |
452 | 453 |

피드백

454 |

이 책에서 마음에 들지 않거나 이해하기 어렵거나 또는 단순히 잘못된 부분을 지적해줄 여러분과 같은 독자분들의 도움이 필요합니다. 의견이나 제안 사항을 이 책의 저자에게 알려주시거나 이 책의 번역자에게 보내주세요.

455 |

한국어 번역판에 대한 의견은 wikibook@wikibook.co.kr로 보내주시기 바랍니다.

456 | 457 | 458 |
459 | 460 |
461 |
462 | 463 |
464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 |
475 | 476 | 482 |
483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | -------------------------------------------------------------------------------- /dedication.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 헌사 · GitBook 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 73 | 74 | 427 | 428 | 429 |
430 | 431 |
432 | 433 |
434 | 435 | 436 | 437 | 446 | 447 | 448 | 449 | 450 |
451 |
452 | 453 |
454 | 455 |

헌사

456 |

저희에게 GNU/리눅스와 오픈소스의 세계를 소개해 주신 Kalyan VarmaPESIT의 다른 여러 시니어 분들께 이 책을 바칩니다.

457 |

저의 벗이자 저를 이끌어주셨던 그리운 Atul Chitnis를 기리며 이 책을 바칩니다.

458 |

인터넷을 탄생시킨 선구자분들께 이 책을 바칩니다. 이 책은 2003년에 처음 씌였습니다만 여전히 인기를 누리고 있는데, 이것은 그분들이 상상하셨던 인터넷을 통한 지식 공유라는 특성 덕분입니다.

459 | 460 | 461 |
462 | 463 |
464 |
465 | 466 |
467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 |
482 | 483 | 489 |
490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | -------------------------------------------------------------------------------- /translation_howto.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 부록: 번역 방법 · GitBook 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 73 | 74 | 427 | 428 | 429 |
430 | 431 |
432 | 433 |
434 | 435 | 436 | 437 | 446 | 447 | 448 | 449 | 450 |
451 |
452 | 453 |
454 | 455 |

번역 방법

456 |
    457 |
  1. https://github.com/swaroopch/byte-of-python에서 이 책의 전체 소스를 내려받을 수 있습니다.
  2. 458 |
  3. 저장소를 포크합니다.
  4. 459 |
  5. 그런 다음, 저장소를 컴퓨터로 가져옵니다. 그러려면 Git 사용법을 알아야 합니다.
  6. 460 |
  7. GitBook 문서를 읽어보세요. 특히 Markdown 절을 읽어보시기 바랍니다.
  8. 461 |
  9. 번역하고자 하는 언어로 번역하기 위해 .md 파일을 편집합니다.
  10. 462 |
  11. GitBook.com에 가입해서, 책을 생성하면 PDF, EPUB 등을 다운로드할 수 있는 링크가 포함된 깔끔한 웹사이트가 만들어집니다.
  12. 463 |
464 | 465 | 466 |
467 | 468 |
469 |
470 | 471 |
472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 |
487 | 488 | 494 |
495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | -------------------------------------------------------------------------------- /preface.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 들어가며 · GitBook 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 73 | 74 | 427 | 428 | 429 |
430 | 431 |
432 | 433 |
434 | 435 | 436 | 437 | 446 | 447 | 448 | 449 | 450 |
451 |
452 | 453 |
454 | 455 |

들어가며

456 |

파이썬(Python)은 아마 단순하면서 강력한 몇 안 되는 프로그래밍 언어 중 하나일 것입니다. 파이썬은 초보자뿐만 아니라 전문가가 사용하기에 좋고, 그리고 더 중요한 건 파이썬을 이용하면 재미있게 프로그래밍할 수 있다는 것입니다. 이 책은 이처럼 멋진 언어를 배우는 것을 돕고 업무를 빠르고 고통 없이 처리하는 방법을 보여줌으로써 사실상 '프로그래밍 문제에 대한 해독제' 역할을 하는 데 목적이 있습니다.

457 |

대상 독자

458 |

이 책은 파이썬 프로그래밍 언어에 대한 가이드 또는 자습서 역할을 합니다. 이 책은 주로 초심자를 대상으로 하며, 숙련된 프로그래머에게도 유용합니다.

459 |

컴퓨터에 관한 지식으로 텍스트 파일을 저장하는 방법 정도만 아는 분이라도 이 책을 통해 파이썬을 배울 수 있습니다. 이전에 프로그래밍해본 경험이 있더라도 이 책을 통해 파이썬을 배울 수 있습니다.

460 |

이전에 프로그래밍해본 경험이 있다면 파이썬과 여러분이 즐겨 쓰는 프로그래밍 언어와의 차이점이 무엇인지 궁금할 것입니다. 저는 그러한 여러 차이점을 강조해 왔습니다. 그럼에도 조심스럽게 경고하자면 파이썬은 금방 여러분이 즐겨쓰는 프로그래밍 언어가 될 것입니다.

461 |

공식 웹사이트

462 |

이 책의 공식 웹사이트는 https://python.swaroopch.com/이며, 이곳에서 책 전체를 읽거나 최신 버전의 책을 내려받거나 종이책을 구입할 수 있으며, 저에게 피드백을 주실 수 있습니다.

463 |

생각해 볼 문제

464 |
465 |

소프트웨어를 설계하는 두 가지 방법이 있다. 하나는 아주 단순하게 만들어서 분명하게 눈에 띄는 결함이 없게 하는 것이고, 다른 하나는 아주 복잡하게 만들어서 분명하게 눈에 띄는 결함이 없게 하는 것이다. -- C. A. R. 호어(Hoare)

466 | 467 |

인생의 성공은 재능과 기회보다는 집중력과 인내의 문제다. -- C. W. 웬드(Wendte)

468 |
469 | 470 | 471 |
472 | 473 |
474 |
475 | 476 |
477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 |
492 | 493 | 499 |
500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | -------------------------------------------------------------------------------- /about.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 부록: 이 책에 관해 · GitBook 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 |
70 |
71 | 72 | 73 | 74 | 427 | 428 | 429 |
430 | 431 |
432 | 433 |
434 | 435 | 436 | 437 | 446 | 447 | 448 | 449 | 450 |
451 |
452 | 453 |
454 | 455 |

부록: 이 책에 관해

456 |

이 책을 만드는 데 사용한 거의 모든 소프트웨어는 FLOSS입니다.

457 |

이 책의 탄생

458 |

이 책의 초판에서는 레드햇 9.0 리눅스를 이 책의 기본 집필 환경으로 활용했고, 이 책의 6차 개정판에서는 페도라 코어 3 리눅스를 이 책의 기본 집필 환경으로 활용했습니다.

459 |

초기에는 이 책을 쓰는 데 KWord를 이용했습니다(개정 이력에서 설명하고 있습니다).

460 |

10대 시절

461 |

이후로 Kate를 이용한 DocBook XML으로 바꿨는데 너무 지루하다고 느꼈습니다. 그래서 서식을 제어하기가 좋고 PDF 생성이 가능한 OpenOffice로 바꿨는데 문서에서 만들어지는 HTML이 너무 엉성했습니다.

462 |

최종적으로 XEmacs를 발견하고 DocBook XML 형식이 장기적인 관점에서 가장 나은 방법이라 판단하고 이 책을 DocBook XML(다시 한번)로 처음부터 다시 썼습니다.

463 |

6차 개정판에서는 Quanta+를 이용해 모든 편집 작업을 처리하기로 마음먹었습니다. 페도라 코어 3 리눅스에 포함된 표준 XSL 스타일시트가 사용되고 있었습니다. 그러나 HTML 페이지에 색상과 스타일을 지정하는 CSS 문서를 작성했고, 모든 프로그램 코드에 문법 강조를 자동으로 적용하는 렉시컬 분석기도 파이썬으로 대충 작성했습니다.

464 |

7차 개정판에서는 MediaWiki를 기본 집필 환경으로 사용했습니다. 저는 모든 것을 온라인에서 편집하고 독자분들이 직접 위키 웹사이트 내에서 읽고/편집하고/논의할 수 있었지만 결국 글을 쓰는 것보다 스팸을 처리하는 데 더 많은 시간을 보내게 됐습니다.

465 |

8차 개정판에서는 Vim, Pandoc, Mac OS X을 사용했습니다.

466 |

9차 개정판에서는 AsciiDoc 포맷으로 바꾸고 Emacs 24.3, 467 | tomorrow 테마, 468 | Fira Mono 글꼴, adoc-mode를 사용해 책을 썼습니다.

469 |

현재

470 |

2016: AsciiDoctor에서 C/C++++가 사라지는 것과 같은 갖가지 자잘한 렌더링 문제를 처리하는 데 지쳤고 사소한 사항들을 이스케이프하는 것을 관리하기가 어려웠습니다. 게다가 복잡한 Asciidoc 형식 때문에 텍스트를 편집하기가 꺼려졌습니다.

471 |

10차 개정판에서는 Spacemacs 에디터를 이용해 Markdown + GitBook 포맷으로 쓰는 방식으로 바꿨습니다.

472 |

저자 소개

473 |

https://www.swaroopch.com/about/을 참고하세요.

474 | 475 | 476 |
477 | 478 |
479 |
480 | 481 |
482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 |
497 | 498 | 504 |
505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | --------------------------------------------------------------------------------