Python Open And Read It Get Into A Var - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python Open And Read It Get Into A Var (/thread-28943.html) |
Python Open And Read It Get Into A Var - Harshil - Aug-10-2020 import secrets import sys import time import string from tenacity import (retry , stop_after_attempt) #Required Defs var = open('conf.txt','r+') content = var.read() print(content) def get_random_string(length): letters = string.ascii_lowercase num = string.ascii_uppercase punc = string.punctuation spec = string.hexdigits one = str(num) + str(punc) + str(spec) result_str = ''.join(secrets.choice(one) for i in range(length)) print("Random string of length", length, "is:", result_str) #CLosing All Defs Here @retry(stop=stop_after_attempt(5)) def start(): pasw = input("Do YOu Want A Random Password: y/n: ") if pasw == 'y': leng = input("Please Type The Length Of The Password You Want: ") try: len1 = int(leng) get_random_string(len1) time.sleep(4) except ValueError: print("Only Numbers Accepted") time.sleep(4) elif pasw == 'n': sys.exit("You Don't Want TO Run The Program") time.sleep(3) else: raise Exception("Choose Only From 'y' or 'n'") start()Conf.txt Quote:minchars = 1 RE: Python Open And Read It Get Into A Var - bowlofred - Aug-10-2020 Do you have a question about the code? RE: Python Open And Read It Get Into A Var - ndc85430 - Aug-10-2020 Do you have a question? Is your code not doing what you expect? If so, what have you done to debug the problem? Help us out here. RE: Python Open And Read It Get Into A Var - buran - Aug-10-2020 have a look at configparser of course one can always parse the file themselves RE: Python Open And Read It Get Into A Var - Harshil - Aug-11-2020 Let me explain: I want to make a file conf.txt Now this is used for configration of password generator 2nd problem I want to take the contents of file into variable and treat as Example if in conf.txt uf i have minhex == 1 then i should include only 1 hex number how cab i get this any one (Aug-10-2020, 06:25 PM)ndc85430 Wrote: Do you have a question? Is your code not doing what you expect? If so, what have you done to debug the problem? Help us out here. This is the thing i want thanks RE: Python Open And Read It Get Into A Var - buran - Aug-11-2020 Did you look at configparser as suggested? RE: Python Open And Read It Get Into A Var - Harshil - Aug-11-2020 (Aug-11-2020, 04:29 AM)buran Wrote: Did you look at configparser as suggested?Yeah! RE: Python Open And Read It Get Into A Var - buran - Aug-11-2020 (Aug-11-2020, 06:13 AM)Harshil Wrote: Yeah!So, now you know what to do, right? RE: Python Open And Read It Get Into A Var - Harshil - Aug-11-2020 (Aug-11-2020, 07:13 AM)buran Wrote:(Aug-11-2020, 06:13 AM)Harshil Wrote: Yeah!So, now you know what to do, right? Yes And It Was Done! Hey! Bro I Want To Make More Projects in Python Would you like to help? |