• ronjeffries

    press the plus thing at top right, select Documentation.

    posted in Editorial read more
  • ronjeffries

    Just got Editorial. Looks great! Kind of backed into the built-in Documentation. What's the quick way to open Documentation in Editorial, please? Thanks!

    posted in Editorial read more
  • ronjeffries

    Thanks @omz I had hoped that was the case.
    Thanks @Webmaster4o maybe I'll have a look at that, though I am thinking that I need to go another way and maybe talk to the thing from Safari or something. Or maybe just work on the core in Pythonista and then do the real work with the App Engine launcher on the Mac.

    Thanks!

    posted in Pythonista read more
  • ronjeffries

    Thanks @omz, I'll try that ... in other news, how do i do a control-C in Pythonista? Thanks!

    posted in Pythonista read more
  • ronjeffries

    Thanks @Phuket2 I'll check that out.

    Here's my new problem, I have this code

    # coding: utf-8
    # example from https://docs.python.org/2/library/socketserver.html
    
    import SocketServer
    
    class MyTCPHandler(SocketServer.BaseRequestHandler):
        """
        The request handler class for our server.
    
        It is instantiated once per connection to the server, and must
        override the handle() method to implement communication to the
        client.
        """
    
        def handle(self):
            # self.request is the TCP socket connected to the client
            self.data = self.request.recv(1024).strip()
            print "ron jeffries has gotten something working part 2"
            print "{} wrote:".format(self.client_address[0])
            print self.data
            # just send back the same data, but upper-cased
            back = "here you go\n" + self.data.upper()
            self.request.sendall(back)
    
    if __name__ == "__main__":
        HOST, PORT = "localhost", 9999
    
        # Create the server, binding to localhost on port 9999
        server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)
    
        # Activate the server; this will keep running until you
        # interrupt the program with Ctrl-C
        server.serve_forever()
    

    So when I run this code, the server is running, and if I go into Safari I can send like

    localhost:9999/?add&key=k1&val=v1

    And get back sensible stuff from my server. So my soon-to-be app engine code would be in the server above. Which means I need to stop it, modify it, start it up again, then test again on the Safari side.

    However, if I press the [x] box to stop the thing, edit it, and restart it, I get the message

    [Errno 48] Address already in use.

    I can stop Pythonista and restart it to run again but that seems wrong. So how do I, within Pythonista, stop this server, edit it, and restart it on the same address?

    Thanks!

    posted in Pythonista read more
  • ronjeffries

    Ah, begins to look like I can't really run a server and a client at the same time with Pythonista. I guess what I'll do is just rig up a class or function and call it with unittest to get it working, paste it into the internet on the Mac.

    If I'm missing some obvious idea let me know ... thanks!

    posted in Pythonista read more
  • ronjeffries

    Thanks @Phuket2 and @omz ... i will look up the requests module right away.

    yes i know i can't get all the way to writing or running the app engine stuff. what i'm thinking i might do is roughly this:

    get a server running in Pythonista on some port; get a client set up to talk to that port; debug the protocol i plan to use with app engine and the parsing and such that I do.

    i've now experimented with some of the server / client examples in the Python docs and with a little demo I found here. They sort of worked :) what would help would be a very simple example of a server.py and client.py that talk to each other.

    what i'm not seeing right now is more about Pythonista itself. suppose i have those two scripts. How do i get them to run at the same time, and talk to each other? I've not figured out how to get two tabs worth of code in the same "run". So at least some of my trouble is I'm so new I don't get the drift of how Pythonista itself is set up. Happy to be told to "go read X", preferably with a decent value of X that i can find.

    Thanks,

    posted in Pythonista read more
  • ronjeffries

    Woot, ran unittest demo:

    import unittest

    class TestStringMethods(unittest.TestCase):

    def test_upper(self):
        self.assertEqual('foo'.upper(), 'FOO')
    
    def test_isupper(self):
        self.assertTrue('FOO'.isupper())
        self.assertFalse('Foo'.isupper())
    
    def test_split(self):
        s = 'hello world'
        self.assertEqual(s.split(), ['hello', 'world'])
        # check that s.split fails when the separator is not a string
        with self.assertRaises(TypeError):
            s.split(2)
    

    if name == 'main':
    unittest.main()

    life is good so far ...

    posted in Pythonista read more
  • ronjeffries

    Hi, new member, old programmer. Just starting with Pythonista (and Python). I need to write a very simple web service kind of thing for Google App Engine. Can do it with the Google launcher on my Mac, of course, but most days I just do things on my iPad.

    The app just takes an http query line like?add,key=foo&val=bar and parses it down, creates a record, stores in App Engine, other queries read records and other fairly simple stuff. I see there's some good parsing stuff in Python, just the thing for what I need. So I can clearly do some of the prep work in Pythonista and that's cool.

    However I could use some pointers on these things:

    First, can I set up a little HTML page, have Pythonista server it and run my Python code in response to it, in the internal browser, or in Safari? If so, a pointer to an example would be helpful: I've not found one yet.

    Second, is there a unit-testing framework here? I see there is a package unittest, haven't tried loading it as so far all I've done is run a couple of the samples and modify them.

    Very early days with Pythonista for me and I promise to do my homework but there's a lot to take in and a couple of pointers, especially to simple examples, would be great. Thanks!

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!