string-formatting

    3熱度

    3回答

    我想從原始文件中讀取數據並替換文本中的格式。 比如...在一個原始文件是這樣的: hello {0}, my name id {1}, my age is {2}.... 當我使用的String.format,如下圖所示,文字失去了它的縮進。 String data = readTextFile(this, R.raw.input); data = String.format(data, "

    1熱度

    1回答

    我有一個名爲dataOrder的數據框,其中列對應於樣本名稱(n = 384),行對應於基因實體(n = 180200)。 sample1 sample2 sample3 sample4 sample5 sample6 ENST00000000233 9 0 3499.51 0 0 0 ENST00000000412 0 0 0.00 0 0 0 EN

    0熱度

    2回答

    以下代碼將UUID轉換爲「字符串化的十六進制格式」。我不太明白它的作用,以及我如何用新的str.format風格重寫它。 if not isinstance(value, uuid.UUID): return "%.32x" % uuid.UUID(value).int else: # hexstring return "%.32x" % value.

    -1熱度

    1回答

    我的代碼: new_account = sys.argv[1] confirm_new = input("Would you like to add {} to the dictionary?" + "\ny or n\n".format(new_account)) 這不格式化字符串放置變量替代{}。這是怎麼回事?

    0熱度

    1回答

    我試圖使用新樣式格式(「PyFormat」)和打印一般變量一個DateTime對象,它可能是一個字符串,浮點型,布爾或DateTime對象。 似乎罰款直接的格式: import datetime "{0}".format(datetime.datetime.now()) 然而,試圖截斷{0:.300}混合時,它失敗: import datetime "{0:.300}".format(da

    2熱度

    1回答

    隨着datetime對象,你可以在一個特殊的方式使用.format: from datetime import datetime '{:%Y-%m-%d %H:%M}'.format(datetime(1990, 4, 28, 22, 30)) 這些都是the usual formatters爲datetime對象。 我可以給任何類自定義的方式來格式化它們嗎?怎麼樣?

    0熱度

    5回答

    一個Python新手問題: 我想在Python與C格式的參數列表打印: agrs = [1,2,3,"hello"] string = "This is a test %d, %d, %d, %s" 如何打印使用Python爲: 這是一個測試1,2,3,你好 感謝。

    1熱度

    2回答

    「不是所有的參數,而字符串格式化轉換」當我執行以下程序 import MySQLdb cn = MySQLdb.connect(host="localhost", user="root", passwd="mysqlroot", db="sv_data") cursor = cn.cursor() cursor.execute("select addressline1, zipcode f

    1熱度

    1回答

    現在已經到了將所有打印轉換爲我所維護的庫中的日誌記錄調用的時候了。一些打印話費使用str.format,像這樣(簡化): >>> n = 4000000 >>> print(f"this bird wouldn't voom if you put {n:,} volts through it!") this bird wouldn't voom if you put 4,000,000 vol

    1熱度

    3回答

    我有0範圍內的整數直到(包括)100.我想將它們轉換爲固定長度爲3的字符串,用空格填充和對齊到對。 我試圖使用以下格式的字符串,但它增加了三位數的另一個空間,這使得3 fmt = lambda x: "{: 3d}".format(x) [fmt(99), fmt(100)] # produces [' 99', ' 100'] instead of [' 99', '100'] 有趣的是它