1
我試圖創建一個基本上是單詞列表的表。我更喜歡錶格格式,因爲它最終會進入excel。但是,通過我的代碼,我不斷在字符串之前獲得字母'b'的介紹。任何幫助,將不勝感激。創建基於字符串的數組在字符串前引入隨機'b'
我甚至在各個階段嘗試打印,看看他們在哪裏以及爲什麼要介紹。 代碼:
from xlwt import Workbook
import numpy as np
wb = Workbook()
Number_Of_Days = int(input('How many days do you want?'))
All_Sheets = np.chararray((Number_Of_Days,1))
All_Sheets = np.chararray(All_Sheets.shape, itemsize = 10)
All_Sheets[:] = ''
print(All_Sheets)
count = 0
while count < Number_Of_Days:
Sheet_Name = input(print('Enter the name of day', count+1))
All_Sheets [count,0] = Sheet_Name
count = count + 1
print(All_Sheets)
這表明你正在尋找一個字節的文字,而不是字符串:https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal – Jeremy
@Jeremy謝謝你的快速回復。無論如何,我可以使我的輸入字符串,並注意在這種情況下的字節文字? 而且當我把它放入時,excel會顯示b'...'或者會被忽略? – newbieintown
這將有助於轉換:https://stackoverflow.com/questions/606191/convert-bytes-to-a-python-string至於Excel會發生什麼,我真的不知道。 – Jeremy