omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


    Trouble getting started with Pythonista

    Pythonista
    4
    10
    4274
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • paulgottlieb
      paulgottlieb last edited by

      I'm a retired programmer and I'm new to python. My question is so simple it's embarrassing. I installed python on my desktop and I also installed Pythonista on my iPad. The following simple program works perfectly on the desk top, but not on my iPad:

      input_var = ("enter your name: ")
      print("Hello! " + input_var)

      on the PC this works, but in Pythonista on the iPad, when I enter my name, Paul, the print statement fails with "NameError: name 'Paul' is not defined." I must be doing something stupid, but I don't see what. Any help?

      1 Reply Last reply Reply Quote 1
      • chriswilson
        chriswilson last edited by

        @paulgottlieb

        Hi Paul,
        I'm a Python novice as well, so I'll defer to those more experienced on the forum.

        It seems that your whole code is running at once, with input_var being set equal to the string on line 1, then everything being printed at line 2. When you enter "Paul" it is like entering "Paul" as a statement, which is not recognised.

        The code below will work. raw_input() sets input_var equal to the users input.

        input_var = raw_input("enter your name: ")
        print("Hello! " + input_var)
        
        1 Reply Last reply Reply Quote 0
        • paulgottlieb
          paulgottlieb last edited by

          thanks, I'll give it a try.

          chriswilson 1 Reply Last reply Reply Quote 0
          • chriswilson
            chriswilson @paulgottlieb last edited by

            @paulgottlieb

            As for why it's behaving differently on the PC, I'm not sure! :)

            1 Reply Last reply Reply Quote 0
            • TutorialDoctor
              TutorialDoctor last edited by TutorialDoctor

              I am not exactly sure of the syntax in Python 3.0+ but the current version of Python that Pythonista uses is 2.7. Perhaps this is the reason?

              Also, I believe in Python 3.0 the input() function is used for strings and integers and the raw_input() function has been deprecated in 3.0.

              paulgottlieb 1 Reply Last reply Reply Quote 1
              • paulgottlieb
                paulgottlieb @TutorialDoctor last edited by

                @TutorialDoctor That's a good point. As a neophyte I really wasn't conscious of he differences between releases. I'm running 3.51 on the PC

                1 Reply Last reply Reply Quote 0
                • paulgottlieb
                  paulgottlieb last edited by

                  Thanks to everyone. that raw_input function did the trick. I think the Beginning Python book I had out of the library was geared to release 3. I'm sure I'll back with more questions. This is a far cry from assembler language programming on the old IBM mainframes!

                  1 Reply Last reply Reply Quote 1
                  • dgelessus
                    dgelessus last edited by

                    Python 2 and 3 incompatibility is something you'll have to get used to. Python 2 is the backwards-compatible legacy version, and Python 3 is the actively developed but backwards-incompatible version. Which means that you have strange differences like with input.

                    Under Python 3, there is just input, which asks the user for a line of text input and returns it. Under Python 2 that is done with raw_input. The Python 2 input is different - it takes user input like raw_input, but then reads it as a Python expression and returns it. This is cumbersome to use and a security risk, which is why in Python 3, raw_input was renamed to input.

                    paulgottlieb 1 Reply Last reply Reply Quote 0
                    • paulgottlieb
                      paulgottlieb @dgelessus last edited by

                      @dgelessus In your opinion, should I be concentrating on 3.0? Is that going to be the standard going forward?

                      1 Reply Last reply Reply Quote 0
                      • dgelessus
                        dgelessus last edited by

                        @paulgottlieb Python 3 is generally the better choice, if you have the choice. Sometimes you have to use Python 2 because you're using some other component that only supports Python 2, such as Pythonista in this case.

                        But if you do have the choice, I strongly recommend Python 3, as it has far less special cases that exist only for backwards compatibility, like print being a special statement instead of a function, input/raw_input, bytes/str/unicode conversion, old-style and new-style classes, etc. If you're going to work with Python 2, you'll need to learn about these things at some point, but if you're just starting with Python I'd recommend Python 3 - it's a lot cleaner and easier to understand in a few cases.

                        The current version of Pythonista only supports Python 2, but a version with both Python 2 and 3 is currently in beta (if you're interested in testing it, see the forum thread on the topic). As far as I know it will be released as a separate app once it's finished.

                        1 Reply Last reply Reply Quote 3
                        • First post
                          Last post
                        Powered by NodeBB Forums | Contributors