Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Stefan Fuhrmann Newsgroups: de.comp.lang.python Subject: [Python-de] function als value in einem dict Date: Sat, 10 Oct 2020 12:10:00 +0200 Lines: 53 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: news.uni-berlin.de pba8RWX7m9eb7VWQsn21ZAA9WWp9Qv7Q4qYlS10iSvPQ== Return-Path: X-Original-To: python-de@python.org Delivered-To: python-de@mail.python.org Authentication-Results: mail.python.org; dkim=none reason="no signature"; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at willy.nopanicsystems.net User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 Content-Language: en-US X-BeenThere: python-de@python.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Die Deutsche Python Mailingliste List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: Xref: csiph.com de.comp.lang.python:5693 Hallo zusammen, leider finde ich nichts, wie ich einen passwort generator, als value in einem dict aufrufen kann. Geht das überhaupt? ##### password_generator ############ 18 #def generator_pw(): 19 #    pwd = string.ascii_letters + string.digits + string.punctuation 20 #    return "".join(random.choice(pwd) for x in range(random.randint(1, 13))) 21 22 #print(generator_pw()) 23 24 ##################################### 25 26 27 with open('docker-compose.yml', "r") as f: 28     docker_compose  = yaml.full_load(f) 29 30 def generator_pw(): 31     pwd = string.ascii_letters + string.digits + string.punctuation 32     return "".join(random.choice(pwd) for x in range(random.randint(1, 13))) 33 34     print(generator_pw()) 35 36 #    docker_compose["services"]["db"]["environment"] = dict(MYSQL_ROOT_PASSWORD= "passingTest") 37     docker_compose["services"]["db"]["environment"] = dict(MYSQL_ROOT_PASSWORD= generator_pw) 38 39 with open('docker-compose.yml', "w") as f: 40     yaml.dump(docker_compose, f) momentan wird in der yaml "null" geliefert. Was ist hier die richtige Vorgehensweise? Kann jemand helfen? Danke! Gruß Stefan