python - My file has no length? Even though it does -
def file_contents(): global file_encrypt encryption_file = input("what name of file?") file_encrypt = open(encryption_file, 'r') contents = file_encrypt.read() print (contents) ask_sure = input("is file encrypt?") if ask_sure == "no": the_menu()
this part of code opens file user enters, right? there no real problems here.
def key_offset(): key_word = '' count = 0 total = 0 while count < 8: num = random.randint (33, 126) letter = chr(num) key_word = key_word + letter count = count + 1 offset = ord(letter) total = total + offset print("make sure copy key decryption.") if count == 8: total = total/8 total = math.floor(total) total = total - 32 print(key_word) return total
this part calculates offset , etc etc. once again no problems here.
def encrypting(): file = file_contents() total = key_offset() encrypted = '' character_number = 0 length = len(file_encrypt)
and problem appears, have made variable file_encrypt global in first block of code, therefore should work. have tried calling under variable file_en = file_encrypt , used file_en in length calculating, keeps saying has no length... have tried asking friends , teacher, seem clueless. problem every time part says file_encrypt has no length or other way tried it, file_en has no length, textwrapper.io.
file_encrypt
file pointer, indeed not have length. contents of file in contents
, variable local file_contents
function.
really should not using global variables; there isn't reason here. instead, return actual data - contents
- file_contents
, can use in calling function.
Comments
Post a Comment