0
ファイル内に何も存在しなければ、基本的に特定のコードセットをf.writeしようとしています。これは私が使用しているコードです:ファイルが空でないかどうかをチェックし、それがf.writeの場合
import sys
import os
from string import *
userType = raw_input("Enter text: ")
bigtable = '''<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
</style>
</head>
<body>
<table style="width:50%">
<tr>
<th>Server</th>
<th>Address</th>
<th>Name</th>
<th>Address2</th>
</tr>'''
if userType == 'file -n' or userType == 'file --nice':
with open('Pass.html', 'r') as f:
if str(f) != 0 :
print('butters')
else:
f.write(bigtable)
これが動作しない理由を誰が説明することができ、ファイルをスキャンし、それに特定の情報を書き込むことが可能ですか?それはで動作するようにする方法を見つけた
:
with open('Pass.html', 'a') as f:
if os.path.getsize('C:\Python26\Pass.html') != 0 :
print('butters')
else:
f.write(bigtable)
一方、読んだファイルに書き込むことはできません。また、str()とintを比較します。しかし、「うまくいかない」ということはどういう意味ですか? –
はコード自体に関係するものではありません。なぜ私は間違っていたのですか?コードが文字通り間違っているという事実の外で、文字列をintと比較しているという事実は問題です – Cry2Senpai