1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Run python script with integer arguments & variables in Colab

Discussão em 'Python' iniciado por Stack, Setembro 12, 2024.

  1. Stack

    Stack Membro Participativo

    In Colab, I set variables outside and I want to pass them to a python script I call. Normal methods with {VAR} or $VAR do not work. What I understand, as it opens a new shell to run it, all is passed as strings and the python script does not have any conversion utilities.

    MYVAR=3

    !python3 myscript.py --int-arg {MYVAR}
    !python3 myscript.py --int-arg $MYVAR


    The first version complains:


    error: argument --int_arg: invalid int value: '{MYVAR}'
    ​

    The second version complains:


    error: argument --int_arg: expected one argument
    ​

    How can I handle this?

    EDIT: As indicated in the comment, the following question might seem similar, but as you can see, I've already tried more than the answer in that topic proposed, and the reason came out very different, at least in the Colab version at that time (2 1/2 years before). Run a python file with arguments in Colab

    It is usual in many programming languages to specify constants in capitals, like I did, but this caused the problem.

    Continue reading...

Compartilhe esta Página