Nested lists in "P2" python list element output • Module package • Release upload (pigeon details)

Source: Internet
Author: User
Tags python list

If you are also learning Head first Python, you can learn from each other. The next step is to document how to complete this chapter of the book and How to solve the problems encountered.

first, simple access to list data "1"Access to specific data by location, 0 means the first bit "like"


"2" calculated list length "with Len" "3" list added at the end--delete element, append, pop Delete, note different usage append parentheses to add elements, list. Pop () can be deleted

"4" Extend add multiple elements "if you want to add 5,6,7 later", notice the difference between the append and the append keep the parentheses in the data item, defect
------------------------------------------------------------------------------------------extend successfully added elements.

"5" deletes a specific element, inserting an element in front of a specific position

second, nested list nums=[1,2,3,[44,55],6],isinstance () to check whether a particular identifier conforms to a particular type of dataThe For loop lets you output the list (including the elements in the nested list), and when the number of layers is too low, the for loop will be more and the amount of maintenance is much more.
"Error type-1" expected an indented block-------------indentation problem, check for extra spacesTherefore, you need to use the function "Def" instead of the code for the repeating part of the loop

iii. three usage of module code
(1) Module Direct use: Create a new. py module file (e.g. write function)1. Right-click on the desktop to create a new text document, the suffix txt is modified to py, clicking OK file to become like style
2. Right click on the file, select Edit with Idle (direct double click useless)
3. Write the function module in the file, here I still use nested list element input function module "Print_list" (Write well remember to save)


4. After writing the module save, select the function bar run or press F5 directly, will jump out of the new Window Python shell restart window


5. Next work in this pop-up window, which already has the function module, you can use the "Print_list" module method directly using the method, to obtain the answer
"defect" instantaneous, can only open and run the file with the function module before the use, in order to make themselves more convenient to use, the 2nd is to encapsulate the module, then as long as the use of import can use
(2) Build Release: Encapsulation module, import call        1. Create a new folder, copy the "text1.py" file you just wrote to the folder, and the folder is named Text1         

2. Build a setup.py file in the Text1 folder (how to build the above steps), edit the metadata that contains the publication"Note that every sentence, write a comma, the last sentence will not be used."

here, in our new Text1 folder, there are already text1.py files and setup.py files
3 Build the release file, open the Terminal window in the Text1 folder "The specific method is to place the folder blank, hold down the SHIFT key, and then right-click on the left-hand side of the options will be one more (Open command Window here, click to enter)"       
I'm using Windows7, and the command I typed here is "Python.exe's location setup.py sdist", The simple point is to find the Python.exe file and then drag directly into the CMD interface will automatically generate a location (refer to the previous post: p1), I python.exe here is D:\python\pythondrag in the end is this:Type the full command "Note that there are spaces in the middle"and the result is as follows:      
4 Install the publication to a local copy and then use it directly
the commands taught in the book are: sudo python3 setup.py install is for the Linus system, I use Windows,so the command used is: Python.exe position setup.py Install, note the Python location you have to see where you are, I have already said the Python position, so the command I typed is "D:\python\python\ python.exe setup.py Install "      
OK to here the module has been built and started to use the test. 1.1 Open the Idle editor, import the module, and use the module name + function name to call the method
        1.2 do not write in the idle editor, create a new. py file (don't say and not, then look at it), in the inside write, such as, pay attention to call method when must "module name + function name", or error Nameerror------------------- save after writing, run or F5 running will jump out of the window and run the answer directly.

(3) module sharing: Upload share.   as a standard small white, these three kinds of I only then understand. The first is through the file to run the interface, not very convenient, the second package into a module, in the future file or edit window can be directly import call, permanent; the first second is for their own use, the third is the sharing module, you can share their own can also learn from others of the module.          3.1 upload Posted in PyPI website: http://pypi.python.org/, so you need to login to register the site, remember the account password you set3.2 You need to register again via the command line, not the same as above. As before, open the terminal through the folder where the command is "Python.exe position setup.py Register"             If you are the first re-registration, the interface may be different from me, just said the re-registration of the password to enter the account will not appear after one time, your interface should be required to fill in username and password, where the account password is you previously registered on the Web page, Password input is not displayed, so do not doubt whether it is bad, just enter your password to determine the line. In the process of asking (y/n)? , type Y directly. until the interface appears, prove that you have succeeded. The next time you use this command, you won't be able to fill in your account password, just like my interface is so simple.
3.3 Start Publishing Web site, using the command "python.exe location setup.py sdist upload"        "NOTE 1:" Module name cannot be the same as the book, cannot be existing, otherwise it will show failure"NOTE 2:"use upload must be in a networked state, or302 Error:Moved temporarily ]        Until the interface appears, prove that you have succeeded.




Small white please learn, master please advise









Nested lists in "P2" python list element output • Module package • Release upload (pigeon details)

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.