While and If loop in one line












0















I have created a client server app, where when i am in need to update the Client code, i am pushing an update using a string match and whenever that string matches the infinitely running client code process that.
The update is nothing but a string that contains python code in it, let's say this:



while True:
if data == "exit":
connection_status = 'Exit Request Received, Exiting'
MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP)
break


And in my client main code, i have something like this:



if 'update' in data:
new_source = data.split('###_CODEBLOCK_###')
exec(new_source[1])


From the server, i am sending something like this:



Enter you Message  : update code is here ###_CODEBLOCK_###while True : if data == "mad": connection_status = "Exit Request Received, Exiting" ; MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP) ; break


Problem :




  1. CLI doesn't like new line, therefore i have to use one-liner python code to achieve this


  2. Because, it's a one-liner and while and if loop are compound statements, i can't use them the way i put in, so i need to know how can i achieve it in one-line code


  3. Is this really a good hack to send updates? This is bonus question for me, if you don't answer it, that's fine











share|improve this question

























  • You have basically reinvented a trojan.

    – Andrew Cheong
    Nov 22 '18 at 7:25











  • You can create a function with your code and call it when you need it.

    – bhawesh chandola
    Nov 22 '18 at 7:31
















0















I have created a client server app, where when i am in need to update the Client code, i am pushing an update using a string match and whenever that string matches the infinitely running client code process that.
The update is nothing but a string that contains python code in it, let's say this:



while True:
if data == "exit":
connection_status = 'Exit Request Received, Exiting'
MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP)
break


And in my client main code, i have something like this:



if 'update' in data:
new_source = data.split('###_CODEBLOCK_###')
exec(new_source[1])


From the server, i am sending something like this:



Enter you Message  : update code is here ###_CODEBLOCK_###while True : if data == "mad": connection_status = "Exit Request Received, Exiting" ; MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP) ; break


Problem :




  1. CLI doesn't like new line, therefore i have to use one-liner python code to achieve this


  2. Because, it's a one-liner and while and if loop are compound statements, i can't use them the way i put in, so i need to know how can i achieve it in one-line code


  3. Is this really a good hack to send updates? This is bonus question for me, if you don't answer it, that's fine











share|improve this question

























  • You have basically reinvented a trojan.

    – Andrew Cheong
    Nov 22 '18 at 7:25











  • You can create a function with your code and call it when you need it.

    – bhawesh chandola
    Nov 22 '18 at 7:31














0












0








0








I have created a client server app, where when i am in need to update the Client code, i am pushing an update using a string match and whenever that string matches the infinitely running client code process that.
The update is nothing but a string that contains python code in it, let's say this:



while True:
if data == "exit":
connection_status = 'Exit Request Received, Exiting'
MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP)
break


And in my client main code, i have something like this:



if 'update' in data:
new_source = data.split('###_CODEBLOCK_###')
exec(new_source[1])


From the server, i am sending something like this:



Enter you Message  : update code is here ###_CODEBLOCK_###while True : if data == "mad": connection_status = "Exit Request Received, Exiting" ; MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP) ; break


Problem :




  1. CLI doesn't like new line, therefore i have to use one-liner python code to achieve this


  2. Because, it's a one-liner and while and if loop are compound statements, i can't use them the way i put in, so i need to know how can i achieve it in one-line code


  3. Is this really a good hack to send updates? This is bonus question for me, if you don't answer it, that's fine











share|improve this question
















I have created a client server app, where when i am in need to update the Client code, i am pushing an update using a string match and whenever that string matches the infinitely running client code process that.
The update is nothing but a string that contains python code in it, let's say this:



while True:
if data == "exit":
connection_status = 'Exit Request Received, Exiting'
MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP)
break


And in my client main code, i have something like this:



if 'update' in data:
new_source = data.split('###_CODEBLOCK_###')
exec(new_source[1])


From the server, i am sending something like this:



Enter you Message  : update code is here ###_CODEBLOCK_###while True : if data == "mad": connection_status = "Exit Request Received, Exiting" ; MessageBox(None, connection_status, "Connection Status", 0x40000 | MB_OK | ICON_STOP) ; break


Problem :




  1. CLI doesn't like new line, therefore i have to use one-liner python code to achieve this


  2. Because, it's a one-liner and while and if loop are compound statements, i can't use them the way i put in, so i need to know how can i achieve it in one-line code


  3. Is this really a good hack to send updates? This is bonus question for me, if you don't answer it, that's fine








python python-2.7






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 7:23









eyllanesc

79.6k103258




79.6k103258










asked Nov 22 '18 at 7:18









PetPanPetPan

1239




1239













  • You have basically reinvented a trojan.

    – Andrew Cheong
    Nov 22 '18 at 7:25











  • You can create a function with your code and call it when you need it.

    – bhawesh chandola
    Nov 22 '18 at 7:31



















  • You have basically reinvented a trojan.

    – Andrew Cheong
    Nov 22 '18 at 7:25











  • You can create a function with your code and call it when you need it.

    – bhawesh chandola
    Nov 22 '18 at 7:31

















You have basically reinvented a trojan.

– Andrew Cheong
Nov 22 '18 at 7:25





You have basically reinvented a trojan.

– Andrew Cheong
Nov 22 '18 at 7:25













You can create a function with your code and call it when you need it.

– bhawesh chandola
Nov 22 '18 at 7:31





You can create a function with your code and call it when you need it.

– bhawesh chandola
Nov 22 '18 at 7:31












1 Answer
1






active

oldest

votes


















1














You can use exec() function in Python and convert that multiline code into a single line string to be used as exec() argument. Make sure you use n to indicate newline and still keep the proper spacing to indicate indentation.






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425699%2fwhile-and-if-loop-in-one-line%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You can use exec() function in Python and convert that multiline code into a single line string to be used as exec() argument. Make sure you use n to indicate newline and still keep the proper spacing to indicate indentation.






    share|improve this answer




























      1














      You can use exec() function in Python and convert that multiline code into a single line string to be used as exec() argument. Make sure you use n to indicate newline and still keep the proper spacing to indicate indentation.






      share|improve this answer


























        1












        1








        1







        You can use exec() function in Python and convert that multiline code into a single line string to be used as exec() argument. Make sure you use n to indicate newline and still keep the proper spacing to indicate indentation.






        share|improve this answer













        You can use exec() function in Python and convert that multiline code into a single line string to be used as exec() argument. Make sure you use n to indicate newline and still keep the proper spacing to indicate indentation.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 22 '18 at 7:28









        AndreasAndreas

        1,99931218




        1,99931218
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53425699%2fwhile-and-if-loop-in-one-line%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            MongoDB - Not Authorized To Execute Command

            in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith

            How to fix TextFormField cause rebuild widget in Flutter