婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 聊一聊python常用的編程模塊

聊一聊python常用的編程模塊

熱門標簽:騰訊外呼線路 廣告地圖標注app 陜西金融外呼系統 公司電話機器人 激戰2地圖標注 白銀外呼系統 哈爾濱ai外呼系統定制 唐山智能外呼系統一般多少錢 海南400電話如何申請

文件流的讀寫

讀取保存數據為數組的txt文件

使用try進行異常發現,使用while檢測文件末尾進行讀取

file_to_read = raw_input("Enter file name of tests (empty string to end program):")
try:
    infile = open(file_to_read, 'r')
    while file_to_read != " ":
        file_to_write = raw_input("Enter output file name (.csv will be appended to it):")
        file_to_write = file_to_write + ".csv"
        outfile = open(file_to_write, "w")
        readings = (infile.readline())
        print readings
        while readings != 0:
            global count
            readings = int(readings)
            minimum = (infile.readline())
            maximum = (infile.readline())

使用for遍歷讀取的每一行,進行一次性的讀取和輸入

下面調用的程序讀取的數據是

result = list()
    with open('../test/parameter.txt') as  f:
        for line in f.readlines():
            temp = list()
            # 逐個遍歷對應每一行元素,將之轉為對應的數據
            b = line.strip(",][").split(',')
            if(len(b) >= 5):
                b.pop()
            for a in b:
                a = a.replace('[','').replace(']','')
                temp.append(float(a))
            result.append(temp)
            #print("中途打印的temp是",temp)
            #print("加入到result中的結果是",result)

刪除str中的特定字符

刪除字符串首尾的多余字符串strip()

# 刪除字符串中多余字符
def string_remove():
   str1 = ' abc     \n'
   print str1.strip()   # abc

   str2 = '----abcdf++++'
   print str2.strip('-+')  # abcdf

replace函數,刪除字符串中某一個所有的字符串

ss = 'old old string'
ret = ss.replace('old', 'new', 1)
print(ret)

sub函數,同時刪除多個字符串,這里使用了正則表達式

str2 = '\nabc\nwrt22\t666\t'  # 刪除字符串中的所有\n,\t
import re
print(re.sub('[\n\t]','',str2))   # abcwrt22666

以上就是聊一聊python常用的編程模塊的詳細內容,更多關于python編程模塊的資料請關注腳本之家其它相關文章!

您可能感興趣的文章:
  • python—sys模塊之獲取參數的操作
  • Python協程asyncio模塊的演變及高級用法
  • python process模塊的使用簡介
  • python文件目錄操作之os模塊
  • Python collections模塊的使用技巧
  • Python使用random模塊實現擲骰子游戲的示例代碼
  • Python爬蟲基礎之requestes模塊
  • Python多線程編程之threading模塊詳解
  • python通配符之glob模塊的使用詳解
  • Python基礎之模塊相關知識總結

標簽:黔西 常德 黑龍江 惠州 益陽 鷹潭 上海 四川

巨人網絡通訊聲明:本文標題《聊一聊python常用的編程模塊》,本文關鍵詞  聊,一聊,python,常用的,常,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《聊一聊python常用的編程模塊》相關的同類信息!
  • 本頁收集關于聊一聊python常用的編程模塊的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 清河县| 清苑县| 增城市| 伊通| 开鲁县| 弋阳县| 锡林郭勒盟| 芜湖县| 六盘水市| 乌兰浩特市| 独山县| 当阳市| 东乌珠穆沁旗| 淅川县| 额济纳旗| 合江县| 东城区| 色达县| 宣威市| 贵阳市| 托克托县| 泾川县| 贵南县| 万源市| 新蔡县| 贡嘎县| 闽清县| 新干县| 长顺县| 乐业县| 晋宁县| 黄浦区| 娱乐| 永福县| 平南县| 鹤岗市| 犍为县| 定远县| 溆浦县| 桂阳县| 临海市|