How to save the python program

To save the Python program, you can use the following method: use the editor to write the code and save

1、 Open Notepad++

2、 When you need to create a new text, click "Text" in the upper left corner, and click "New" in the pop-up menu bar.

3、 At the same time, you can also directly click the new icon under "Text".

4、 When saving, save it as a .py file, here it is saved as hello.py

Content expansion:

Temporary storage of python programs

#! /usr/bin/env python
# - *- coding:utf-8-*-
# Import regular module
import re
# Import the os module, this example uses it for file writing operations
import os
# Import log module
import logging
import logging.handlers
import xlwt
import xlrd
import MySQLdb
import pymysql

db = pymysql.connect("localhost","root","123456","my_db_hanchuan01")

# Iterate over files+Method of collecting mobile phone number
def count(dirname='D:/tmp/Temporary data source/sheet conversion/txtfiles'):
 #- - - - - - - - - - - - - - - - - - - - - - - Regular--------------------------------  #手机号Regular
 pattern_mob = re.compile('1[345789]\d{9}') 
 # pattern_mob_plus = re.sub('1[345789]\d{9}','1[345789]\d{9}+123')
 #- - - - - - - - - - - - - - - - - - - - - Statistics file------------------------------   #Variable to record the total number of files
 count=0
 num=0 #Variables that record the number of files containing mobile phone numbers
 for root, dirs, files in os.walk(dirname):
 # Get the number of files in each folder
 for filename in files:
  # Concatenate the file name and path into a full path
  f =open(dirname+'/'+filename,'r+', encoding='utf-8')      
  var1 =(filename) #Write file name to database
  result = pattern_mob.findall(f.read())  # result = pattern_mob_plus.findall(f.read()) # result = pattern_mob.findall # result = result+"123"for phonenames in result:      
  var2 =(phonenames)print(var1)print(var2)  
  cursor = db.cursor()  #Use cursor()Method to create a cursor object cursor
  cursor.execute("INSERT INTO 00_HEFEI_PHONES VALUES('%s', %s)"%(var1,var2)) #Execute sql statement
  db.commit()        
# Main function
   
if __name__ =='__main__':
# # Call count()h function
 count()
 db.close()

So far, this article on how to save python programs is introduced. For more related python program saving methods, please search for the previous articles of ZaLou.Cn or continue to browse the related articles below. I hope you will support ZaLou.Cn more in the future. !

Recommended Posts

How to save the python program
How to view the python module
How to save text files in python
How to debug python program using repr
How to learn the Python time module
How to use the round function in python
How to use the zip function in Python
How to program based on interfaces in Python
How to use the format function in python
How to enter python through the command line
How to switch the hosts file using python
How to install the downloaded module in python
How to write a confession program in python
Python how to move the code collectively right
How to comment python code
How to learn python quickly
How to uninstall python plugin
How to understand python objects
How to use python tuples
How to practice after the python file is written
How to understand the introduction of packages in Python
How to save IE as an attachment in python
How does python handle the program cannot be opened
python how to view webpage code
How to use python thread pool
How Python implements the mail function
How does python change the environment
How to write python configuration file
How to find the area of a circle in python
How to wrap in python code
How to omit parentheses in Python
How to install Python 3.8 on CentOS 8
How to install Python 3.8 on Ubuntu 18.04
How to write classes in python
How to filter numbers in python
How to read Excel in Python
How to install Python on CentOS 8
How to solve python dict garbled
How to view errors in python
How to write return in python
How Python implements the timer function
How to understand variables in Python
How to clear variables in python
How to understand python object-oriented programming
CentOS7 repairs python to save yum
How to use SQLite in Python
How to verify successful installation of python
How to make a globe with Python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How does python improve the calculation speed
How to represent null values in python
Python string to judge the password strength
How to use PYTHON to crawl news articles
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to write try statement in python
How to define private attributes in Python