[Tutor] Tutor Digest, Vol 141, Issue 11

Burhan ul haq ulhaqz at gmail.com
Wed Nov 11 07:18:06 EST 2015


Continuing "Run Python 2.7 on Android Tablet"

Hi,

I am constrained to install anything on my official laptop, therefore I
need to have an "online life saver" for Python Learning.

I have already tried "pythonanywhere" but could not get it going, even for
a basic "hello world" script. I could not locate any basic documentation to
help me with. The basic help tab "I want to start learning Python
<https://www.pythonanywhere.com/task_helpers/start/1-start_python/>" bring
you back to the main dashboard.

Can anybody share a basic how to get started ...

Many Thanks /



On Wed, Nov 11, 2015 at 1:34 PM, <tutor-request at python.org> wrote:

> Send Tutor mailing list submissions to
>         tutor at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>         https://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>         tutor-request at python.org
>
> You can reach the person managing the list at
>         tutor-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>    1. Run Python 2.7 on Android Tablet (Ken Hammer)
>    2. Re: Run Python 2.7 on Android Tablet (Alan Gauld)
>    3. Re: Run Python 2.7 on Android Tablet (Laura Creighton)
>    4. Re: Run Python 2.7 on Android Tablet (memilanuk)
>    5. Re: question about descriptors (Albert-Jan Roskam)
>    6. Re: question about descriptors (Albert-Jan Roskam)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 10 Nov 2015 12:38:27 -0500
> From: "Ken Hammer"<kfh777 at earthlink.net>
> To: tutor at python.org
> Subject: [Tutor] Run Python 2.7 on Android Tablet
> Message-ID: <E1ZwCsE-0004bN-71 at elasmtp-dupuy.atl.sa.earthlink.net>
>
>
> My MIT OCW 6.00SC course is installed on a Windows 8.1 desktop machine.
>
> I'd like to study and explore away from my office and desk on my tablet
> running Android 4.2.2.  Possible?
>
> thanks,  Ken
>
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 10 Nov 2015 21:07:07 +0000
> From: Alan Gauld <alan.gauld at btinternet.com>
> To: tutor at python.org
> Subject: Re: [Tutor] Run Python 2.7 on Android Tablet
> Message-ID: <n1tm9p$6ah$1 at ger.gmane.org>
> Content-Type: text/plain; charset=utf-8; format=flowed
>
> On 10/11/15 17:38, Ken Hammer wrote:
> >
> > My MIT OCW 6.00SC course is installed on a Windows 8.1 desktop machine.
> >
> > I'd like to study and explore away from my office and desk on my tablet
> running Android 4.2.2.  Possible?
>
> I can't comment on your course but you can install Python on Android and
> for basic programming tasks it works just like any other Python.
> I use QPython FWIW but I think there are others too.
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
>
>
> ------------------------------
>
> Message: 3
> Date: Tue, 10 Nov 2015 22:32:27 +0100
> From: Laura Creighton <lac at openend.se>
> To: Ken Hammer <kfh777 at earthlink.net>
> Cc: tutor at python.org, lac at openend.se
> Subject: Re: [Tutor] Run Python 2.7 on Android Tablet
> Message-ID: <201511102132.tAALWRtP022562 at fido.openend.se>
> Content-Type: text/plain; charset="us-ascii"
>
> In a message of Tue, 10 Nov 2015 12:38:27 -0500, "Ken Hammer" writes:
> >
> >
> >My MIT OCW 6.00SC course is installed on a Windows 8.1 desktop machine.
> >
> >I'd like to study and explore away from my office and desk on my tablet
> running Android 4.2.2.  Possible?
> >
> >thanks,  Ken
>
> Yes.
> use Python Anywhere in a browser on your tablet.
>
> https://www.pythonanywhere.com/
>
> Laura
>
>
> ------------------------------
>
> Message: 4
> Date: Tue, 10 Nov 2015 14:10:04 -0800
> From: memilanuk <memilanuk at gmail.com>
> To: tutor at python.org
> Subject: Re: [Tutor] Run Python 2.7 on Android Tablet
> Message-ID: <n1tpvs$3bf$1 at ger.gmane.org>
> Content-Type: text/plain; charset=windows-1252; format=flowed
>
> On 11/10/2015 01:32 PM, Laura Creighton wrote:
> > In a message of Tue, 10 Nov 2015 12:38:27 -0500, "Ken Hammer" writes:
> >>
> >>
> >> My MIT OCW 6.00SC course is installed on a Windows 8.1 desktop machine.
> >>
> >> I'd like to study and explore away from my office and desk on my tablet
> running Android 4.2.2.  Possible?
> >>
> >> thanks,  Ken
> >
> > Yes.
> > use Python Anywhere in a browser on your tablet.
> >
> > https://www.pythonanywhere.com/
> >
>
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
> Or koding.io... but PythonAnywhere is nicer for straight-up python.
>
> --
> Shiny!  Let's be bad guys.
>
> Reach me @ memilanuk (at) gmail dot com
>
>
>
> ------------------------------
>
> Message: 5
> Date: Wed, 11 Nov 2015 08:08:46 +0000
> From: Albert-Jan Roskam <sjeik_appie at hotmail.com>
> To: Peter Otten <__peter__ at web.de>, "tutor at python.org"
>         <tutor at python.org>
> Subject: Re: [Tutor] question about descriptors
> Message-ID: <DUB123-W25AB3FA3E2A36A7C9BBCCE83130 at phx.gbl>
> Content-Type: text/plain; charset="windows-1256"
>
>
> <snip>
>
> > I think the basic misunderstandings are that
> >
> > (1) the __get__() method has to be implemented by the descriptor class
> > (2) the descriptor instances should be attributes of the class that is
> > supposed to invoke __get__(). E. g.:
> >
> > class C(object):
> >    x = decriptor()
> >
> > c = C()
> >
> > c.x # invoke c.x.__get__(c, C) under the hood.
>
> Exactly right, that was indeed my misunderstanding! I was thinking about
> __get__ and __set__ in the same terms as e.g. __getitem__ and __setitem__
>
>
> > As a consequence you need one class per set of attributes, instantiating
> the
> > same AttrAccess for csv files with differing layouts won't work.
>
> That is no problem at all for me. One instance per file will be fine.
>
>
> > Here's how to do it all by yourself:
> >
> > class ReadColumn(object):
> >     def __init__(self, index):
> >         self._index = index
> >     def __get__(self, obj, type=None):
> >         return obj._row[self._index]
> >     def __set__(self, obj, value):
> >         raise AttributeError("oops")
>
> This appears to return one value, whereas I wanted I wanted to return all
> values of a column, ie as many values as there are rows.
> But the logic probably won't change. Same applies to the use of
> namedtuple, I suppose (?). I have never used namedtuple like
> namedtuple("Column", self.header)(*self.columns).
>
>
> > def first_row(instream):
> >     reader = csv.reader(instream, delimiter=";")
> >
> >     class Row(object):
> >         def __init__(self, row):
> >             self._row = row
> >
> >     for i, header in enumerate(next(reader)):
> >         setattr(Row, header, ReadColumn(i))
> >
> >     return Row(next(reader))
> >
> >
> > f = StringIO("a;b;c\n1;2;3\n4;5;6\n7;8;9\n")
> > row = first_row(f)
> > print row.a
> > row.a = 42
> >
> > Instead of a custom descriptor you can of course use the built-in
> property:
> >
> >     for i, header in enumerate(next(reader)):
> >         setattr(Row, header, property(lambda self, i=i: self._row[i]))
>
> This seems most attractive/straightforward to me.
>
> > In many cases you don't care about the specifics of the row class and use
> > collections.namedtuple:
> >
> >
> > def rows(instream):
> >     reader = csv.reader(instream, delimiter=";")
> >     Row = collections.namedtuple("Row", next(reader))
> >     return itertools.imap(Row._make, reader)
> >
> >
> > f = StringIO("a;b;c\n1;2;3\n4;5;6\n7;8;9\n")
> > row = next(rows(f))
> > print row.a
> > row.a = 42
>
> Thanks a lot for helping me!
>
>
>
>
> ------------------------------
>
> Message: 6
> Date: Wed, 11 Nov 2015 08:33:17 +0000
> From: Albert-Jan Roskam <sjeik_appie at hotmail.com>
> To: Steven D'Aprano <steve at pearwood.info>, "tutor at python.org"
>         <tutor at python.org>
> Subject: Re: [Tutor] question about descriptors
> Message-ID: <DUB123-W199C562DE5BEA8094CE89883130 at phx.gbl>
> Content-Type: text/plain; charset="windows-1256"
>
> > Date: Sun, 8 Nov 2015 01:24:58 +1100
> > From: steve at pearwood.info
> > To: tutor at python.org
> > Subject: Re: [Tutor] question about descriptors
> >
> > On Sat, Nov 07, 2015 at 12:53:11PM +0000, Albert-Jan Roskam wrote:
> >
> > [...]
> > > Ok, now to my question. I want to create a class with read-only
> > > attribute access to the columns of a .csv file. E.g. when a file has a
> > > column named 'a', that column should be returned as list by using
> > > instance.a. At first I thought I could do this with the builtin
> > > 'property' class, but I am not sure how.
> >
> > 90% of problems involving computed attributes (including "read-only"
> > attributes) are most conveniently solved with `property`, but I think
> > this may be an exception. Nevertheless, I'll give you a solution in
> > terms of `property` first.
> >
> > I'm too busy/lazy to handle reading from a CSV file, so I'll fake it
> > with a dict of columns.
>
> Actually, I want to make this work for any iterable, as long as I can get
> the header names and as long as it returns one record per iteration.
>
>
> > class ColumnView(object):
> >     _data = {'a': [1, 2, 3, 4, 5, 6],
> >              'b': [1, 2, 4, 8, 16, 32],
> >              'c': [1, 10, 100, 1000, 10000, 100000],
> >              }
> >     @property
> >     def a(self):
> >         return self._data['a'][:]
> >     @property
> >     def b(self):
> >         return self._data['b'][:]
> >     @property
> >     def c(self):
> >         return self._data['c'][:]
>
> Interesting. I never would have thought to define a separate class for
> this.
>
>
> > And in use:
> >
> > py> cols = ColumnView()
> > py> cols.a
> > [1, 2, 3, 4, 5, 6]
> > py> cols.a = []
> > Traceback (most recent call last):
> >   File "<stdin>", line 1, in ?
> > AttributeError: can't set attribute
> >
> >
> >
> > Now, some comments:
> >
> > (1) You must inherit from `object` for this to work. (Or use Python 3.)
> > It won't work if you just say "class ColumnView:", which would make it a
> > so-called "classic" or "old-style" class. You don't want that.
>
> Are there any use cases left where one still must use old-style classes?
> Or should new code always inherit from object (unless one want to inherit
> from another "true" class, of course).
>
>
> > (2) Inside the property getter functions, I make a copy of the lists
> > before returning them. That is, I do:
> >
> >     return self._data['c'][:]
> >
> > rather than:
> >
> >     return self._data['c']
> >
> >
> > The empty slice [:] makes a copy. If I did not do this, you could mutate
> > the list (say, by appending a value to it, or deleting items from it)
> > and that mutation would show up the next time you looked at the column.
>
> These mutability problems always make me pull my hair out! :-) I like the
> [:] notation, but:
>
> In [1]: giant = range(10 ** 7)
>
> In [2]: %timeit copy1 = giant[:]
> 10 loops, best of 3: 97 ms per loop
>
> In [3]: from copy import copy
>
> In [4]: %timeit copy2 = copy(giant)
> 10 loops, best of 3: 90 ms per loop
>
> In [5]: import copy
>
> In [6]: %timeit copy2 = copy.copy(giant)
> 10 loops, best of 3: 88.6 ms per loop
>
> Hmmm, wicked, when I looked earlier this week the difference appear to be
> bigger.
>
>
> > (3) It's very tedious having to create a property for each column ahead
> > of time. But we can do this instead:
> >
> >
> > def make_getter(key):
> >     def inner(self):
> >         return self._data[key][:]
> >     inner.__name__ = key
> >     return property(inner)
> >
> >
> > class ColumnView(object):
> >     _data = {'a': [1, 2, 3, 4, 5, 6],
> >              'b': [1, 2, 4, 8, 16, 32],
> >              'c': [1, 10, 100, 1000, 10000, 100000],
> >              }
> >     for key in _data:
> >         locals()[key] = make_getter(key)
> >     del key
> >
> >
> > and it works as above, but without all the tedious manual creation of
> > property getters.
> >
> > Do you understand how this operates? If not, ask, and someone will
> > explain. (And yes, this is one of the few times that writing to locals()
> > actually works!)
>
> I think so. I still plan to write several working implementations to get a
> better idea about which strategy to  choose.
>
> > (4) But what if you don't know what the columns are called ahead of
> > time? You can't use property, or descriptors, because you don't know
> > what to call the damn things until you know what the column headers are,
> > and by the time you know that, the class is already well and truly
> > created. You might think you can do this:
> >
> > class ColumnView(object):
> >     def __init__(self):
> >         # read the columns from the CSV file
> >         self._data = ...
> >         # now create properties to suit
> >         for key in self._data:
> >             setattr(self, key, property( ... ))
> >
> >
> > but that doesn't work. Properties only perform their "magic" when they
> > are attached to the class itself. By setting them as attributes on the
> > instance (self), they lose their power and just get treated as ordinary
> > attributes. To be technical, we say that the descriptor protocol is only
> > enacted when the attribute is found in the class, not in the instance.
>
> Ha! That is indeed exactly what I tried! :-))
>
> > You might be tempted to write this instead:
> >
> >             setattr(self.__class__, key, property( ... ))
>
> I thought about defining a classmethod, then inside it do setattr(cls,
> key, property( ... ))
> But that is probably the same?
>
> > but that's even worse. Now, every time you create a new ColumnView
> > instance, *all the other instances will change*. They will grown new
> > properties, or overwrite existing properties. You don't want that.
> >
> > Fortunately, Python has an mechanism for solving this problem:
> > the `__getattr__` method and friends.
> >
> >
> > class ColumnView(object):
> >     _data = {'a': [1, 2, 3, 4, 5, 6],
> >              'b': [1, 2, 4, 8, 16, 32],
> >              'c': [1, 10, 100, 1000, 10000, 100000],
> >              }
> >     def __getattr__(self, name):
> >         if name in self._data:
> >             return self._data[name][:]
> >         else:
> >             raise AttributeError
> >     def __setattr__(self, name, value):
> >         if name in self._data:
> >             raise AttributeError('read-only attribute')
> >         super(ColumnView, self).__setattr__(name, value)
> >     def __delattr__(self, name):
> >         if name in self._data:
> >             raise AttributeError('read-only attribute')
> >         super(ColumnView, self).__delattr__(name)
>
> That also seems very straightforward. Why does "if name in self._data:"
> not cause a recursion? self._data calls __getattr__, which has self._data
> in it, which...etc.
>
>
>
> ------------------------------
>
> Subject: Digest Footer
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ------------------------------
>
> End of Tutor Digest, Vol 141, Issue 11
> **************************************
>


More information about the Tutor mailing list