Python Forum
Python Open And Read It Get Into A Var
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Open And Read It Get Into A Var
#1
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
minnumbers = 3
minletter = 2
minhex = 2
Reply


Messages In This Thread
Python Open And Read It Get Into A Var - by Harshil - Aug-10-2020, 06:10 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Open and read multiple text files and match words kozaizsvemira 3 6,771 Jul-07-2021, 11:27 AM
Last Post: Larz60+
  Can't open/read txt file in C extension for Python Rad226 8 4,823 Jun-26-2020, 04:08 PM
Last Post: Rad226
  open, read and replace a string in a file Reims 0 1,818 Oct-02-2019, 01:30 PM
Last Post: Reims
  How to write a code to open and read text file by clicking on the "text file" kavindu 4 4,154 Jul-06-2018, 06:55 PM
Last Post: buran
  Having issues with open,write,read dudeisbrendan03 11 7,815 Apr-10-2017, 01:02 AM
Last Post: Low_Ki_
  Open previous csv file to read value under column for comparison DBS 3 3,929 Jan-13-2017, 07:09 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020