Discover learning python fifth edition, include the articles, news, trends, analysis and practical advice about learning python fifth edition on alibabacloud.com
and downloading remote filesSftpclientFor connecting to a remote server and performing an upload downloadUpload and download based on user name password:Import Paramiko transport = Paramiko. Transport (' 172.16.2.234 ', ()) Transport.connect (username= ' root ', password= ' 123345 ') sftp = Paramiko. Sftpclient.from_transport (transport) # upload location.py to Server/tmp/test.pysftp.put ('/data/local/location.py ', '/data/ remote/test.py ') # download Remove_path to local local_pathsftp.get
5.1 How to introduce modulesUsing the keyword import in Python to introduce a module, such as referencing module math, can be introduced with import math at the very beginning of the file. When you call a function in the math module, you must refer to this:Module name. function name Sometimes we just need to use a function in the module, we just need to introduce the function, at this point we can pass the statementFrom Module name Import function
socketimport os tran = Paramiko. Transport ((host,port)) #连接服务器, host and Port Custom tran.start_client () Default_path = Os.path.join (os.environ[' HOME '), '. SSH ', ' id_rsa ') key = Paramiko. Rsakey.from_private_key_file (Default_path) tran.auth_publickey (' root ', key) Chan = Tran.open_session () # Open a channel chan.get_pty () #获取一个终端chan. Invoke_shell () #激活器 f = open (' Log.log ', ' a ') #打开一个文件用于写入执行的 Operation while True: # Monitor user input and server return data # Sys.stdin proce
Previous four days course review1.python Introduction2.python Basic data typesClass: Int: integral type | str: string | List: Listing |tuple: Tuples |dict: Dictionaries | Set: Collection object: Li = [11,22,33] #列表的一个对象s = "MoHan" #字符串的一个对象3. Functional programming4. Decorative Device@ Decorator function name def func (): pass where @ Adorner functions the name, the program executes to this, will do the f
Function Call functionFunction names can be passed as argumentsfunction name () execution functionFunction name refers to the function itself#!/usr/bin/env python#-*-coding:utf-8-*-defF1 ():return "F1"#f1 = function#F1 = The surrogate function#f1 () = Execute functiondefF2 (ARG): Arg ()return "F2"#x = 123#f1 = F1 function#F2 = F2 function#F2 (x)#Execute F2 function, F1 function as argumentF2 (F1)Python Full
While loop#第50次不打印, 第60-80次 prints the square of the corresponding value1Count =02 3 whileCount :4 ifCount = = 50:5 Pass6 elifCount >= 60 andCount :7 Print(count*count)8 Else:9 Print("Loop", Count)Ten OneCount + = 1 A - Print("------Loop is ended-------")Dead loop (Dead Loop)Count = 0 while true:#true itself is true print(" Forever-------", Count) + = 1Break is used to completely end a loop, jumping out of the loop body to execute the statement b
Python2 default to Unicode required before string plus uCycle through each lineLoop print the entire file content way twoTake one line at the same time belowFirst define and then executeWhen a function is defined, only syntax errors are detected and not executedfunction return value, default is tuple modeReturn can only be returned onceform participates in the actual parameterFormal parameters are variable namesArguments are valuesBreaking the order limitFrequently changing values are used with
={'nid': Self.id})View CodeGets the URL information for the successful request match: Request.resolver_match5, according to the app routing rules classificationurl(r‘^web/‘,include(‘web.urls‘)), 分发6. NamespacesA. project.urls.py fromDjango.conf.urlsImporturl,include urlpatterns=[url (r'^a/', Include ('App01.urls', namespace='Author-polls')), url (r'^b/', Include ('App01.urls', namespace='Publisher-polls')),]B. app01.urls.py from Import URL from Import 'app01'= [ url (r'^ (? p', Views.detail
All the logical structures are organized around branches and loops, such as login registration, payment success, and so on, with branching if usage and while usageIf age>30:Print ("www.96net.com.cn")ElsePrint ("www.dc3688.com")If score>90:Print ("good")Elif score>70 and scorePrint ("G")ElsePrint ("false")While usage tells, output 1-100 numbersCount=1While countPrint (count)Count+=1While mates break and continue useBreak terminates this cycle, continue terminates this cycle and continues the next
Chapter One: Basic knowledge1. Double slash: The operator that implements the divide>>>1//20Even if it is a floating-point number, the slash will perform the divide>>>1.0//2.00.02. Power (exponentiation) operator: Double star>>>2**38Tip: You can use the function POW instead of the operator, pow (2,3)3.16 Binary and octalHex: Front plus 0x, first is number 0>>>0xaf175Octal: Add 0o to Python in version 3.0, the first number is 0, the second is the lette
#列表可修改, the Yuan Zu cannota=['sdsd',]b=['SDS',]c=[a,b]#分片 :-#list函数#分片赋值#列表方法Lst.append (4) X.count (1) x.count ([up]) A.extend (b) a.index ("w" ) A.insert (3, "all")X.removeX.reverseX.sort#pop removes the list element and returns a value. Implementation data structure-stack, LIFO (LIFO), X.append (X.pop ()), FIFO, X.insert (X.pop (0)#sortX.sort (Key=len)y=sorted (x)#y元祖No list-like methods(a)#tuple函数# become a meta-ancestorPython Basic Learning Note
#模块#包#模块中有什么Dir L List features#文档Print range.__doc__#阅读源代码Print copy.__file__#标准库Sysosfileinput#集合, heap and double-ended queuesSet (range) Thecollection heap data structure is not independent of only one module containing some heap operations, called HEAPQ (6 functions) Double-ended queue#time#random#shelve#re# contains support for regular expressionsPython Basic Learning Note--python Basic Tutorial (2nd
functions. For example: POW is used to calculate standard functions such as Solutionkeys GT;GT;GT;2**38GT;GT;GT;POW (2.3) 8pow, called built-in functions, or you can customize functions. The 1.9 module can be thought of as an extension that imports into Python to enhance its functionality and is imported using the Import command. For example: Import the Math module with import and use >>>importmath>>>math.floor (32.9) in the format "module. function"
Basic Python Tutorial (second edition) Learning Note Strings (Chapter 3rd)All basic sequence Operations (index, Shard, multiply, Judge membership, seek length, maximum minimum) also apply to strings.The string is not to be changed;The left side is the format string, and the right side is the value that needs to be formattedprint '%s=%d '% (' x ', ') ==> x=100% in
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.