Reputation: 30737
I'm trying to use docstrings
w/ triple-quotes in my Jupyter notebooks using Python 2.7 .
I can disable the autoclose brackets/quotes thing but I'm quite keen on them; major increase in workflow.
Does anyone know how to do triple quotes without over-quoting while keeping the autoclose feature?
If I press the "
key 3x
I get """"""
;
If I press it 3x
and delete
once, I get """"
pressing; and
If I press it 3x
and delete
twice, I get ""
Annoying, right? How can I have the best of both worlds (autoclose | docstrings) ?
Upvotes: 2
Views: 3328
Reputation: 5
import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import random import time
def generate_otp(): """Generates a random 6-digit OTP.""" return random.randint(100000, 999999)
def send_otp(email_recipient, otp): """ Simulates sending an OTP to the user's email. Connects to the email server and sends the OTP. """ sender_email = "[email protected]" sender_password = "your_password_or_app_specific_password" smtp_server = "smtp.gmail.com" smtp_port = 587
subject = "Your OTP Code"
body = f"Your OTP code is: {otp}. Please use this to verify your access."
# Setting up the email message
message = MIMEMultipart()
message["From"] = sender_email
message["To"] = email_recipient
message["Subject"] = subject
message.attach(MIMEText(body, "plain"))
try:
# Connect to the SMTP server
server = smtplib.SMTP(smtp_server, smtp_port)
server.starttls() # Secure connection
server.login(sender_email, sender_password)
server.send_message(message)
print("OTP sent successfully to the email!")
except Exception as e:
print(f"Failed to send OTP: {e}")
finally:
server.quit()
def get_user_otp_input(): """Prompts the user to enter the OTP.""" return input("Enter the OTP sent to your email: ").strip()
def validate_otp(generated_otp, entered_otp, retries=3): """ Validates the OTP entered by the user. Allows the user to retry up to 'retries' times if the input is incorrect. """ while retries > 0: if entered_otp == str(generated_otp): print("Access granted! OTP verified successfully.") return True else: retries -= 1 if retries > 0: print(f"Incorrect OTP. You have {retries} attempts left.") entered_otp = get_user_otp_input() else: print("Access denied! Too many incorrect attempts.") return False
if name == "main": print("Welcome to the OTP Verification System")
# Step 1: Generate OTP
otp = generate_otp()
# Step 2: Send OTP
recipient_email = input("Enter your email address: ").strip()
send_otp(recipient_email, otp)
# Step 3: Prompt user for OTP entry
print("An OTP has been sent to your email. Please check your inbox.")
entered_otp = get_user_otp_input()
# Step 4: Validate OTP
validate_otp(otp, entered_otp)
Upvotes: -2
Reputation: 1433
Nothing is wrong. When you type three " your cursor is at the middle of the resulting six. Thus, anything you type is within the string and has been auto-closed.
Type this exact string of characters: """This is working
without clicking or otherwise moving the cursor. The result will be a correcly formatted string, because it will have auto-closed the string. Therefore you have both strings and autoclose.
Upvotes: 1