2016-02-05 64 views
0

當我導入具有類似內容的ReadFile內的字符串:Python的間距在文件處理和操作系統資源

user1 
aword 
anotherword.. 
etc 

我通常一個字內存儲他們喜歡的用戶名和密碼(在這裏):

for user in userfile: 
    for password in passwordfile: 


     c0 = 'curl -s --connect-timeout 2 https://somewebaddress -k --data username='+'"'+username+'"'+' --data password='+'"'+password+'"'+' --data mode=191 2>&1' 
     print (c0) 

     str0=str(os.popen(c0).readlines()) 
     print (str0) 

我得到一個嚴重的問題,並且print(c0)實際上佔用了整條線。 我試着用split函數編輯用戶和密碼字符串,並使用string.split [0]但是,那還不能解決問題。任何有關如何獲得字符串c0的想法完全像這樣打印

curl -s --connect-timeout 2 https:somewebaddress -k --data username="username_from_file" --data password="password_from_file" --data mode=191 2>&1 

沒有任何「\ n」。 這是因爲os.popen並且非常嚴格,至今沒有給我想要的結果。

回答

0

類str中的函數strip()可以從字符串中刪除前導和尾隨空白。字符串末尾的不需要的\ n將被刪除。

+0

很好。 4分鐘後,我發現使用string.striplines()可以做到這一點!不管怎麼說,還是要謝謝你 –

相關問題