python程序如何進(jìn)行保存
保存Python程序,可以使用以下方法:使用編輯器編寫(xiě)代碼并保存
1、打開(kāi)Notepad++
2、需要新建文本時(shí),點(diǎn)擊左上角”文本“,在彈出的菜單欄點(diǎn)擊”新建“。
3、同時(shí)也可以直接點(diǎn)擊”文本“下的新建圖標(biāo)即可.
4、保存的時(shí)候,保存為.py文件,這里保存為hello.py
內(nèi)容擴(kuò)展:
臨時(shí)存放python程序
#!/usr/bin/env python# -*- coding:utf-8 -*-#導(dǎo)入正則模塊import re#導(dǎo)入os模塊,本例用它來(lái)做文件寫(xiě)入操作import os#導(dǎo)入日志模塊import loggingimport logging.handlersimport xlwtimport xlrdimport MySQLdbimport pymysqldb = pymysql.connect('localhost','root','123456','my_db_hanchuan01' )# 遍歷文件+采集手機(jī)號(hào)的方法def count(dirname=’D:/tmp/臨時(shí)數(shù)據(jù)源/sheet轉(zhuǎn)換/txtfiles’): #-----------------------正則-------------------------------- #手機(jī)號(hào)正則 pattern_mob = re.compile(’1[345789]d{9}’) # pattern_mob_plus = re.sub(’1[345789]d{9}’,’1[345789]d{9}+123’) #---------------------統(tǒng)計(jì)文件------------------------------ # 記錄文件總數(shù)的變量 count=0 num=0 # 記錄含手機(jī)號(hào)文件數(shù)的變量 for root, dirs, files in os.walk(dirname): # 得到每個(gè)文件夾下文件數(shù)量 for filename in files: # 將文件名與路徑拼接成全路徑 f = open(dirname+’/’+filename,’r+’, encoding=’utf-8’) var1 = (filename) # 將文件名寫(xiě)入數(shù)據(jù)庫(kù) 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() # 使用 cursor() 方法創(chuàng)建一個(gè)游標(biāo)對(duì)象 cursor cursor.execute('INSERT INTO 00_HEFEI_PHONES VALUES(’%s’, %s)' % (var1,var2)) # 執(zhí)行sql語(yǔ)句 db.commit()# 主函數(shù) if __name__ == ’__main__’:# # 調(diào)用count()h函數(shù) count() db.close()
到此這篇關(guān)于python程序如何進(jìn)行保存的文章就介紹到這了,更多相關(guān)python程序保存的方法內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. PHP VS ASP2. python裝飾器三種裝飾模式的簡(jiǎn)單分析3. 詳解JS ES6編碼規(guī)范4. 詳解Python模塊化編程與裝飾器5. JavaScript中的AOP編程的基本實(shí)現(xiàn)6. JavaScript Reduce使用詳解7. Spring security 自定義過(guò)濾器實(shí)現(xiàn)Json參數(shù)傳遞并兼容表單參數(shù)(實(shí)例代碼)8. python使用ctypes庫(kù)調(diào)用DLL動(dòng)態(tài)鏈接庫(kù)9. 淺談JavaScript中等號(hào)、雙等號(hào)、 三等號(hào)的區(qū)別10. Python如何進(jìn)行時(shí)間處理
