#🔒 Using a variable in a command

14 messages · Page 1 of 1 (latest)

lyric harbor
#

Hell, i am new to python and i am coding a minecraft launcher using the portablemc library. To connect i need the email of the player which is found with a variable and then i execute a command using the email, how do i use a variable inside of another command ? It keeps telling me there's a syntax error.

The code :

def login():
    
    #crée une fênetre de login
    login = tk.Tk()
    login.title("Se Connecter")
    login.geometry("600x375")
    
    #ajout un label pour l'email
    label_email = tk.Label(login, text="Saissez votre email (les pseudonymes ne fonctionnent pas)")
    label_email.pack(pady=10)

    #champ de saisie pseudo et email
    global email_entry
    email_entry = tk.Entry(login)
    email_entry.pack(pady=10)

    #ajoute un bouton de connexion sur l'écran de connexion
    log_button = tk.Button(login, text="Connexion", command=loginbuttononclick)
    log_button.pack(pady=20)

def loginbuttononclick():
    # donne que l'email entré à une fonction 
    entered_email = email_entry.get().strip()
    #lance la fênetre de connexion
    portablemc --login entered_email
lethal sageBOT
#

@lyric harbor

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

lyric harbor
#

the problem is in the entered_email in the last line

vocal lodge
#

portablemc --login entered_email
this is a shell command, I assume? you can't just write it literally in Python and have it work

#

!d subprocess

lethal sageBOT
#

Source code: Lib/subprocess.py

The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes. This module intends to replace several older modules and functions:

os.system
os.spawn*
```  Information about how the [`subprocess`](https://docs.python.org/3/library/subprocess.html#module-subprocess) module can be used to replace these modules and functions can be found in the following sections.
vocal lodge
#

^use this

urban fog
#

!d subprocess.run

lethal sageBOT
#
subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, ...)```
Run the command described by *args*. Wait for command to complete, then return a [`CompletedProcess`](https://docs.python.org/3/library/subprocess.html#subprocess.CompletedProcess) instance.

The arguments shown above are merely the most common ones, described below in [Frequently Used Arguments](https://docs.python.org/3/library/subprocess.html#frequently-used-arguments) (hence the use of keyword\-only notation in the abbreviated signature). The full function signature is largely the same as that of the [`Popen`](https://docs.python.org/3/library/subprocess.html#subprocess.Popen) constructor \- most of the arguments to this function are passed through to that interface. (*timeout*, *input*, *check*, and *capture\_output* are not.)
lyric harbor
#

how do i use the entered_email in the subprocess then ?

vocal lodge
#

provide it as one of the arguments. have you checked out the examples for subprocess.run?

lethal sageBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

🔒 Using a variable in a command