Python study Note 10: path and file of the standard library (OS. path package, glob package ),One OS. path packageCheck the Code:
Import OS. pathpath = "/home/User/Document/test.txt" print (OS. path. basename (path) # query the fi
table to return. Therefore, glob. glob () is a good way to query files in a directory.
The syntax of this file name expression is different from the regular expression of Python itself (you can check the fnmatch package at the same time. Its function is to check whether a file name conforms to the Linux File Name format expression ). As follows:
Filename pattern expression Python Regular Expression
*.*
? .
Linux, in particular, has more than one python, sometimes no absolute path to Python, sometimes a Django, and no way to find where Django is installed. Of course there are a number of ways to look at, here are a few, for inexperienced people to refer to.
Copy the Code code as follows:
G:\code\moniter>python-c "from
This article is mainly about looking at the Python installation path and installation package path tips, this article uses the command line to run the Python code method to detect the installation path and installation package path
The default terminal launcher Python in Python is in the/usr/bin/directory.
The default system library path in Python is in the/usr/lib/pythonx.x/directory.
The default Third-party library path in Python is in the/usr/local/lib/
When using Python, you will always encounter the use of path switching, such as the test.py under folder test to invoke the Data.txt file under the Data folder:
.
└──folder
├──data
│ └──data.txt
└──test
└──test.py
A method can be added to the data file __init__.py then import data in the test.py can invoke Data.txt file;
Another way to manipulate the directory structure with the hel
Types of Python
CpythonThe official version of Python, implemented using the C language, is the most widely used, and the CPython implementation converts the source file (py file) into a bytecode file (PYc file) and then runs on the Python virtual machine.
JyhtonPython Java implementation, Jython will dynamically compile
FHexadecimal vs. Binary relations:Binary conversion Hex:Binary conversion to 16 binary method is to take four-in-one method, that is, from the decimal point of the binary points to the left (or to the right) every four bits (can not be made up four bits, the left (or rightmost) of the decimal point 0, the conversion)16 Notation of the binary:suffix: H Example: BH represents 16 binary 11Prefix: 0x* Example:0X23 is the Binary conversion Hex:A point four, that is, a hexadecimal number is divided
element# setMySet = Set ([1,2,3,3,3])print myset #Set ([+)]; Three. Python's loops and judgments.Python does not like C # and Java this will put some code snippets with {} expansion, for Python with: number implementation of the parentheses function.Note:print and if are not in the same column, which actually indicates that print is the sub-code of the If column, within the IF {}. It is not clear why this design, but used to the parentheses in C
This has a lapse of time, I can not remember the specific statements, and now summarize.First, get the current file pathSecond, get the previous level file pathHere you can imagine getting the path to your own sibling file, so write:That is to get the parent directory first, and then through the join function to put the sibling directory test in.Third, get all the file names under the current pathGet the data for a list, which is the name of all the f
Python learning paths and practiced hand project collections Wayne Shi• 2 months agoReference: https://zhuanlan.zhihu.com/p/23561159More articles welcome to the Attention column: Learning programming.This series of Python technology paths includes seven modules for getting started, Python basics, Web frameworks, infrastructure projects, network programming, data
Python expert path [5] python-based regular expressions and python Regular Expressions
Lists the Python-supported regular expression metacharacters and syntaxes:
Character point: match any character
import rest = 'python'result = re.findall('p.t',st)print(result)
Character
position, such as:
Cursor.scroll (1,mode= ' relative ') # moves relative to the current position
Cursor.scroll (2,mode= ' absolute ') # relative absolute position movement
4. Fetch data type The data that is obtained by default is the Ganso type, if desired or the dictionary type of data, i.e.: #!/usr/bin/env python
#-*-coding:utf-8-*-
import pymysql
conn = pymysql.connect (host= ' 127.0.0.1 ', port= 3306, user= ' root ', pass
.2cto.comBukkit:/home/adalia/security/pythonwrapper # pythonPython 2.7.2 (default, Aug 19 2011, 20:41:43) [GCC] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> Help ('modules ')Please wait a moment while I gather a list of all available modules...... The specific module is omitted here...>>> Exit ()/// After some examples of modules, the nmap permission is changed to rws. It can also be executed with the owen permission of nmap. The original/root/. ssh/authoriz
How to Learn: python learning path (1): python source code installation Preface
Python is a versatile language, especially in Linux. The general Linux system also comes with Python. However, it is still necessary to learn how to install
Python path [Article 2]: Python basics, python Article 2For Python, everything is an object, and objects are created based on classes.
Therefore, the following values are all objects: "zhurui", 22, ['beijing', 'shanghai', 'shenzhen'], and are generated based on different cla
Theoretical Basis of Day1-python, path to python day11. Introduction to pythonThe founder of Python is Guido van rosum. Guido was invented in 1989 to pass the fun of Christmas. It was designed by the National Institute of mathematics and computer science in the Netherlands (as an inheritance of the ABC language) and na
RET:# Print (i)# 33# 66# ############ ret = filter (lambda x:x > 22, [22,33,66])# for I in RET:# Print (i)# 33# 66###################################################### map (func=,iter1=,iter2=) iterates through each element of the Iterable object, executes the function# Returns a new value# def func (x):# return x + 10# Ret1 = Map (func,[1,2,3,])# for I in Ret1:# Print (i)# 11# 12# 13# Simple functions can also be used with lambda expressions####################################################
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.