Python Python random oluşturulan kelimeyi txt dosyasına kayıt etmek.

Chakirantsi

Femtopat
Katılım
20 Şubat 2023
Mesajlar
11
Daha fazla  
Cinsiyet
Erkek
Dostlar Python'da bir proje üstünde çalışıyorum. Aşağı kısıma ekleyeceğim üzere iki kısım var birinci kısım mail ikinci kısım şifre oluşturuyor tamamen random komutunu kullanarak ben ise burada oluşturulan mail ve şifreyi txt dosyasına otomatik olarak her oluşturduğunda kayıt etmesini istiyorum fakat başaramadım. Birkaç kod buldum fakat random üretilen maili ve şifreyi yazmak yerine kendisi üretilen dışında random mail ve şifre yazıyor. Desteklerinizi bekliyorum, kodlar şu şekilde;


def generate_random_email():
random_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))
random_domain = ''.join(random.choice(string.ascii_letters) for _ in range(5))
random_tld = random.choice(['com'])
random_email = random_string + '@' + 'gmail' + '.' + random_tld
return random_email


def generate_random_password():
random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(12))
while (not any(c.isupper() for c in random_password)) or (not any(c.islower() for c in random_password)) or (not any(c.isdigit() for c in random_password)) or (not any(c in string.punctuation for c in random_password)):
random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(8))
return random_password



Bu kodlarda random şifre ve mail oluşturuluyor oluşturulan mail ve şifreyi kayıt etmek istiyorum.
 
Python:
import random
import string

def generate_random_email():
    random_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))
    random_domain = ''.join(random.choice(string.ascii_letters) for _ in range(5))
    random_tld = random.choice(['com'])
    random_email = random_string + '@' + 'gmail' + '.' + random_tld
    return random_email

def generate_random_password():
    random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(12))
    while (not any(c.isupper() for c in random_password)) or (not any(c.islower() for c in random_password)) or (not any(c.isdigit() for c in random_password)) or (not any(c in string.punctuation for c in random_password)):
        random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(8)
)
    return random_password

# Kaç tane e-posta ve şifre oluşturmak istediğinizi belirtin
num_accounts = 10

# Dosyaya yazma işlemini gerçekleştirin
with open("accounts.txt", "a") as file:
    for _ in range(num_accounts):
        random_email = generate_random_email()
        random_password = generate_random_password()
        file.write(f"Email: {random_email}, Password: {random_password}\n")

print(f"{num_accounts} adet hesap oluşturulup accounts.txt dosyasına kaydedildi.")

Bu kod, belirlediğiniz sayıda e-posta ve şifre oluşturacak ve bunları "accounts.txt" adlı bir metin dosyasına kaydedecektir. Siz num_accounts değişkenini istediğiniz hesap sayısıyla değiştirebilirsiniz. Dosya "a" modunda açıldığı için her çalıştırmada yeni hesap bilgileri dosyaya eklenir.
 
Python:
import random.
import string.

def generate_random_email():
 random_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))
 random_domain = ''.join(random.choice(string.ascii_letters) for _ in range(5))
 random_tld = random.choice(['com'])
 random_email = random_string + '@' + 'gmail' + '.' + random_tld.
 return random_email.

def generate_random_password():
 random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(12))
 while (not any(c.isupper() for c in random_password)) or (not any(c.islower() for c in random_password)) or (not any(c.isdigit() for c in random_password)) or (not any(c in string.punctuation for c in random_password)):
 random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(8)
)
 return random_password.

# Kaç tane e-posta ve şifre oluşturmak istediğinizi belirtin.
num_accounts = 10.

# Dosyaya yazma işlemini gerçekleştirin.
with open("accounts.txt", "a") as file:
 for _ in range(num_accounts):
 random_email = generate_random_email()
 random_password = generate_random_password()
 file.write(f"Email: {random_email}, Password: {random_password}\n")

print(f"{num_accounts} adet hesap oluşturulup accounts.txt dosyasına kaydedildi.")

Bu kod, belirlediğiniz sayıda e-posta ve şifre oluşturacak ve bunları "accounts.txt" adlı bir metin dosyasına kaydedecektir. Siz num_accounts değişkenini istediğiniz hesap sayısıyla değiştirebilirsiniz. Dosya "a" modunda açıldığı için her çalıştırmada yeni hesap bilgileri dosyaya eklenir.

Arkadaşın paylaştığı kod işinize yarayacaktır.
 
Python:
import random.
import string.

def generate_random_email():
 random_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))
 random_domain = ''.join(random.choice(string.ascii_letters) for _ in range(5))
 random_tld = random.choice(['com'])
 random_email = random_string + '@' + 'gmail' + '.' + random_tld.
 return random_email.

def generate_random_password():
 random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(12))
 while (not any(c.isupper() for c in random_password)) or (not any(c.islower() for c in random_password)) or (not any(c.isdigit() for c in random_password)) or (not any(c in string.punctuation for c in random_password)):
 random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(8)
)
 return random_password.

# Kaç tane e-posta ve şifre oluşturmak istediğinizi belirtin.
num_accounts = 10.

# Dosyaya yazma işlemini gerçekleştirin.
with open("accounts.txt", "a") as file:
 for _ in range(num_accounts):
 random_email = generate_random_email()
 random_password = generate_random_password()
 file.write(f"Email: {random_email}, Password: {random_password}\n")

print(f"{num_accounts} adet hesap oluşturulup accounts.txt dosyasına kaydedildi.")

Bu kod, belirlediğiniz sayıda e-posta ve şifre oluşturacak ve bunları "accounts.txt" adlı bir metin dosyasına kaydedecektir. Siz num_accounts değişkenini istediğiniz hesap sayısıyla değiştirebilirsiniz. Dosya "a" modunda açıldığı için her çalıştırmada yeni hesap bilgileri dosyaya eklenir.

Çok teşekkür ederim dostum benim için büyük bir iyilik yaptın çözememiştim <3<3<3

Python:
import random
import string

def generate_random_email():
 random_string = ''.join(random.choice(string.ascii_letters + string.digits) for _ in range(10))
 random_domain = ''.join(random.choice(string.ascii_letters) for _ in range(5))
 random_tld = random.choice(['com'])
 random_email = random_string + '@' + 'gmail' + '.' + random_tld
 return random_email

def generate_random_password():
 random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(12))
 while (not any(c.isupper() for c in random_password)) or (not any(c.islower() for c in random_password)) or (not any(c.isdigit() for c in random_password)) or (not any(c in string.punctuation for c in random_password)):
 random_password = ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(8)
)
 return random_password

# Kaç tane e-posta ve şifre oluşturmak istediğinizi belirtin
num_accounts = 10

# Dosyaya yazma işlemini gerçekleştirin
with open("accounts.txt", "a") as file:
 for _ in range(num_accounts):
 random_email = generate_random_email()
 random_password = generate_random_password()
 file.write(f"Email: {random_email}, Password: {random_password}\n")

print(f"{num_accounts} adet hesap oluşturulup accounts.txt dosyasına kaydedildi.")

Bu kod, belirlediğiniz sayıda e-posta ve şifre oluşturacak ve bunları "accounts.txt" adlı bir metin dosyasına kaydedecektir. Siz num_accounts değişkenini istediğiniz hesap sayısıyla değiştirebilirsiniz. Dosya "a" modunda açıldığı için her çalıştırmada yeni hesap bilgileri dosyaya eklenir.

Hocam şimdi denedim fakat istediğim olmadı şu an evet 1 hesap oluşturup kayıt ediyor size kodun tamamını atsam bakar mısınız proje şu şekilde web sayfasını açıyor ve oradaki mail kısmına oluşturulan maili şifre kısmına şifreyi falan giriyor fakat sorun şu an şu random mail ve şifre oluşuturuluyor dosyaya kayıt ediyor ama siteye girdiği mail ve şifrelerden farklı mail şifreyi kayıt ediyor

Çok teşekkür ederim dostum benim için büyük bir iyilik yaptın çözememiştim <3<3<3



Hocam şimdi denedim fakat istediğim olmadı şu an evet 1 hesap oluşturup kayıt ediyor size kodun tamamını atsam bakar mısınız proje şu şekilde web sayfasını açıyor ve oradaki mail kısmına oluşturulan maili şifre kısmına şifreyi falan giriyor fakat sorun şu an şu random mail ve şifre oluşuturuluyor dosyaya kayıt ediyor ama siteye girdiği mail ve şifrelerden farklı mail şifreyi kayıt ediyor
kısacası yine farklı mail ve şifre kayıt ediyor siteye başka mail ve şifreyi giriyor
 
Son düzenleme:

Yeni konular

Geri
Yukarı