• ccc

    @DaveGadgeteer Perhaps the best approach would be to separate the data download from the data parsing as done in https://forum.omz-software.com/topic/4011/have-csv-file-s-url/6. That way, you do not have to hit the URL resource/server so often.

    You can then read the local file and convert it into a list of wearher_readings ...

    import collections, csv
    filename = 'YGa69ObX6WFj9mYa4EmW.csv'
    with open(filename, 'r') as in_file:
        data = []  # a list of weather_readings
        weather_reading = None
        for row in csv.reader(in_file):
            if weather_reading:
            else:  # create a custom datatype from the header record
                weather_reading = collections.namedtuple('weather_reading', row)
    print('\n'.join(str(x) for x in data))
    # weather_reading(time='1952', tips='773', timestamp='2017-04-30T20:42:59.017Z')

    posted in Pythonista read more
  • ccc

    Or if you want to do it all in RAM...

    #!/usr/bin/env python3
    import csv, io, requests
    url = 'http://data.sparkfun.com/output/YGa69ObX6WFj9mYa4EmW.csv'
    with io.StringIO(requests.get(url).text) as mem_file:
        for row in csv.reader(mem_file):
            print(', '.join(row))

    posted in Pythonista read more
  • ccc

    Always easier with requests...

    import csv, requests
    url = 'http://data.sparkfun.com/output/YGa69ObX6WFj9mYa4EmW.csv'
    filename = url.split('/')[-1]
    with open(filename, 'wb') as out_file:
    # _csv.Error: iterator should return strings, not bytes (did you open the file in text mode?)
    # change 'rb' to 'r'
    with open(filename, 'rb') as in_file:
        for row in csv.reader(in_file):
            print(', '.join(row))

    posted in Pythonista read more
  • ccc

    import csv
    with open(filename, newline='') as in_file:
        for row in csv.reader(in_file):
            print(', '.join(row))

    Like in https://github.com/cclauss/Ten-lines-or-less/blob/master/world_bank_data.py

    posted in Pythonista read more
  • ccc

    Tryhttp://pythonista3 with the 3 on the end.

    posted in Pythonista read more
  • ccc

    You can os.listdir('.') to see if the file is in the Current Working Directory.

    posted in Editorial read more
  • ccc

    import dropbox
    print(dropbox.__version__)  # '6.4.0'

    posted in Pythonista read more
  • ccc

    @ramvee This example is great!

    One of the things that I found when I first started using the ui module was that when I did not use .pyui files then my code got long and repetitive. Often I want all my ui elements to share a common look and feel (bg_color, border_color, border_width, etc.) and I only need to set a few unique values like name and frame. To reduce this code bloat, I recommend creating a make_label() function that puts all the common stuff inside and accepts as parameters from the outside the unique stuff...

    # Learning Alignment Options In UI
    # Pythonista
    # Flex LRTBWH
    import ui
    def make_label(name, frame):
        return ui.Label(
    w, h = ui.get_screen_size()
    h -= 64
    bh = bw = 80  # label height and button width
    mg = 10  # margin
    view = ui.View(name='Flex', bg_color='lightyellow', frame=(0, 0, w, h))
    view.add_subview(make_label(name='RB', frame=(mg, mg, bw, bh)))
    view.add_subview(make_label(name='LB', frame=(w - (bw + mg), mg, bw, bh)))
    view.add_subview(make_label(name='RT', frame=(mg, h - (bh + mg), bw, bh)))
                                frame=(w - (bw + mg), h - (bh + mg), bw, bh)))
                                frame=((w - bw) * .5, (h - bh) * .5, bw, bh)))

    posted in Pythonista read more
  • ccc

    Pythonista is iOS only. The feature are described at http://omz-software.com/pythonista/ and http://omz-software.com/pythonista/docs/ios/ The modules like ui, scene, and canvas allow you to build iOS apps in Python. The inclusion of NumPy, Matplotlib, Requests, BeautifulSoup, Flask, Jinja2, Pillow, etc. are also quite powerful.

    posted in Pythonista read more
  • ccc

    weird character that shows up at the end of the header text, a black box

    My bet is that is a carriage return (\n) at the end of your header text.
    If your header text ends in a variable then be sure to .rstrip() the text before putting it into that variable.
    In any case, make sure that the last character in the header text field is not \n.

    posted in Editorial read more

Internal error.

Oops! Looks like something went wrong!