• resserone13

    @ccc i depends on how you wanted to go about it. the teacher mention that some students used csv module. its a really basic class. i used what was explained in class.

    posted in Pythonista read more
  • resserone13

    @JonB your right. i submitted the wrong file types and the files were named incorrectly. ill have to pay more attention to things like that.. the were now working on a dice rolling exerecise and a mystery door game show ... ill make sure to submit the proper file types..

    posted in Pythonista read more
  • resserone13

    this was what i turned in for my homework. my teach said there was some name errors and that the file didnt run completely. maybe he was talking about the type of file i uploaded. it worked fine in my comp. i was using spyder only cus im on my comp. here was the homework and my code

    Create a single Python script (.py) that completes the following steps:

    Read the "US_state_populations.csv" file into Python using any method you like.
    Create a new file called "alphabetic.csv". This file should contain the same 3 columns (state names, 2019 populations, and 2010 populations) separated by commas, but they should sorted alphabetically by the state name. You may write to this file using any method you like. Hint: When you sort the state names, make sure the 2010 and 2019 populations are sorted with their respective states.
    Calculate the change in population between 2010 and 2019 (change = pop2019 - pop2010). Create a new file called "popchange.txt". This file should contain 2 columns: state names and population change, separated by a blank space. The file should contain a header line. You should write to this file manually using a for loop (not numpy, pandas, or any other library).
    Upload your Python script, "alphabetic.csv" and "popchange.txt" to this Canvas assignment.

    
    list_of_list = []
    #variable with file name.
    file_name = 'C:/Users/resse/Desktop/projects/poptest/US_state_populations2.csv'
    new_file = 'C:/Users/resse/Desktop/projects/poptest/abc2.csv'
    pop_diff = 'C:/Users/resse/Desktop/projects/poptest/pdiff.csv'
    
    #opens and closes file.
    with open(file_name, 'r') as f:
        #loops over file line by line.
        f.seek(23)
        for line in f:
            #saves each line as a list
            items = line.strip().split(',')
            #adds each list to a list
            list_of_list.append(items)
            
    #sorts the list
    s = sorted(list_of_list)
    
    #prints the sorted list
    print(s)
    
    #opens the new file and adds a sorted list to it.
    with open(new_file, 'w') as n_f:
        for i in s:
            n_f.write(f'\n {i[0]}, {i[1]}, {i[2]}')
                      
            
    with open(pop_diff, 'w') as d_f:
        #writess the colum headers
        d_f.write(f'p19, p10, pdiff')
        #loops through a sorted list of states and population numbers
        for i in s:
            #calculates the population difference
            diff = int(i[1]) - int(i[2])
            #writes each years population to a colum and 
            #writes the population difference
            d_f.write(f'\n{i[1]}, {i[2]}, {diff}')
    
    

    posted in Pythonista read more
  • resserone13

    @JonB thanks for the heads up on the backslashes. i havent worked with file that much and i never noticed.. thanks the isssue was a typo new it too but i had copied and pasted then i typed it. that along with the backslash error it was all mixed up... thanks for all you advice as always.

    posted in Pythonista read more
  • resserone13

    @JonB i got it to find the file with the full path and now in using just the file name... i think i was missing a '' at the beginning of the file name now im getting

    SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 0-1: truncated \UXXXXXXXX escape

    with this code

    with open('\US_state_populations2.csv', 'r') as f:
        pass
    
    
    

    posted in Pythonista read more
  • resserone13

    @cvp im laughing so hard right now. if i turned your code in the teach would be wanting to learn from me(technically you) hahahahah to funny. once i figure out the file not found im going to tryout your code gonna finish mine too. i was gonna get each line and seprate the different parts into a list and pick the items from the list.

    posted in Pythonista read more
  • resserone13

    @cvp im using a windows laptop. here is the code. i need to sort the states and save a new file with the sorted states and populations in colums. it should be easy ive been figuring out most of it and i have the class video as a guide. im trying not to copy the class video. i had it woring but now it stopped.

    #List
    cities = []
    pop_2019 = []
    pop_2010 = []
    
    #opens and closes file 
    with open('US_state_populations.csv', 'r'):
       
       #iterates over the file. 
       for Line in f:
            #c = f.readline().strip().split(',')
            city = c[0]
            p_2019 = c[1]
            p_2010 = c[2]
            print(str(city))
            print(p_2019)
            print(p_2010)
        
        
    #abc_file = open('alphabetic.csv', 'w',)```

    posted in Pythonista read more
  • resserone13

    long time no see. im trying to do some homework for a cis class im taking at my community college. i need to open a file and its saying file not found. another bull fn ish error that i cant figure out. keeps saying file not found.. i have the .py file in the same folder as the .csv and i have copied and pasted the file name to avoid any misspellings. any suggestions on what else can be the issue..

    posted in Pythonista read more
  • resserone13

    @cvp @ccc @mikael Here is the UI version of the personal protective equipment app. It looks kind of plain. Any suggestions to spruce up how it looks?

    https://github.com/resserone13/PPEasy-ui-only

    posted in Pythonista read more
  • resserone13

    Thanks @cvp @ccc and @mikael for the help. I was able to get past the hang up and move forward on the app development. I ended up using @ccc suggestion because i was using code very similar to what I already had. I’m finishing up a few more things then I will post on GitHub.

    
        def add_btn(self, btn_names, actions_list):
            for i, (n, a) in enumerate(zip(btn_names, actions_list)):
                btn= ui.Button()
                btn.background_color=btn_clr
                btn.title=n
                btn.font=(btn_fnt, btn_txt_sz)
                btn.tint_color=txt_clr
                btn.border_width=2
                btn.border_color=txt_clr
                btn.frame=(width * 0.15, height * (0.12 + i * 0.1), width * 0.7, height * 0.05)
                btn.corner_radius= btn_corner_radius
                btn.action=a
                self.add_subview(btn)
    
    

    posted in Pythonista read more
  • resserone13

    I have a for loop that loops over btn names and creates a button for each name. How do I make it loop over a list of btns and a list of actions so that the each button gets a name and an action?
    I’m using enumerate to help space the btns out. I tired switching to zip but then I loose the i variable for the enumerate function?

    
        def add_btn(self, btn_names, actions_list):
            for i, name, a in enumerate((btn_names)):
                btn= ui.Button()
                btn.background_color=btn_clr
                btn.title=name
                btn.font=(btn_fnt, btn_txt_sz)
                btn.tint_color=txt_clr
                btn.border_width=2
                btn.border_color=txt_clr
                btn.frame=(width * 0.15, height * (0.12 + i * 0.1), width * 0.7, height * 0.05)
                btn.corner_radius= btn_corner_radius
                btn.action='?????'
                self.add_subview(btn)
                
    
    

    posted in Pythonista read more
  • resserone13

    Creat ui objects. then set the parameters to that object. Present the objects using. View. Present().

    posted in Pythonista read more
  • resserone13

    @cvp. Thanks for all your input and advice. I am reviewing everything and re-writing the script. Hopefully everything will be functions. I am going to try classes as well but I might have mainly functions. I’m going to work on it and I will keep you updated. Thanks for all your help it’s really allowing me to get a lot done and learn a lot. Hopefully when I keep showing you these updates you’ll see that I’m learning from what you’re showing me.

    posted in Pythonista read more
  • resserone13

    @mikael I just have my iPhone 11 with Pythonista. I don’t know if I have ui3. I’ve had trouble using stash to import and pip install modules. The web view is working OK for me. I just need to add some navigational buttons at the top. But it does look nice. I will probably have questions on objc In the near future. Once I figure out UI I will dive into objective c.

    posted in Pythonista read more
  • resserone13

    @cvp said:

    @resserone13 did you try my code to open a web view?
    Yes I got the web view working. Thanks.

    posted in Pythonista read more
  • resserone13

    @cvp the imported file ppeasy_text.py is in the same folder as the main.py file.

    from ppeasy_text import text
    
    

    posted in Pythonista read more
  • resserone13

    @resserone13 I would like them to be directed to the website in Safari.

    posted in Pythonista read more
  • resserone13

    @cvp page_info() is like any_scene() class I used when I made the app with scene. I modeled page_info() after any_scene(). Page_info() is a generic function to display the page. Kinda like your myview().

    I’ve also created make_btn() and make_title() for making buttons and creating titles.

    posted in Pythonista read more
  • resserone13

    @cvp ok be been trying to do more of that. That why I have the page_info(). I need to make a few more classes to cut down on the code.

    How can I make the text on the links page be able to receive touches and take the user to the websites.

    posted in Pythonista read more
  • resserone13

    @mikael and @cvp Thanks for the help as always. I ended up using the @cvp suggestion. I’m redoing the personal protective equipment app using the ui module instead of scene. Coming along well.

    I hve an issue with displaying hyperlinks in a text view and getting the ui.path.rounde_rect to draw to the screen I a for loop.

    
    import console
    import ui
    from ppeasy_text import text
    
    app_title = 'PPEasy'
    app_title_font = 'Didot'
    btn_font = 'Didot'
    text_font = '<System>'
    text_color = '1D3557'
    bg_color = 'CAF0F8'
    btn_border_color = '0077B6'
    btn_color = 'CAF0F8'
    btn_shadow=('gray', 0, 7, 2)
    btn_corner_radius = 10
    
    screen_size = ui.get_window_size()
    
    links ='\n\nwww.cdv.gov \n\nwww.fda.gov \n\nwww.coronavirus.gov \n\nwww.covid19.healthdata.org'
    
    
    v = ui.View()
    v.background_color=bg_color    
    
    def make_title(text):
        title = ui.Label()
        title.font= app_title_font, 30
        title.text = text
        title.alignment= ui.ALIGN_CENTER
        title.frame=(screen_size.w * 0.10, screen_size.h * 0.05, screen_size.w * 0.75, screen_size.h * 0.05)
        return  title
    
    def make_button(title, locale, text_param, image_param,dwell_time_param, desc_param, action=None):
        btn= ui.Button()
        btn.background_color='white'
        btn.title=title
        btn.font=(btn_font, 18)
        btn.background_color=bg_color
        btn.tint_color='black'
        btn.border_width=2
        btn.border_color='black'
        btn.frame=(screen_size.w * 0.15, screen_size.h * locale, screen_size.w * 0.7, screen_size.h * 0.07)
        btn.corner_radius= btn_corner_radius
        btn.text_param = text_param
        btn.image_param = image_param
        btn.dwell_time_param = dwell_time_param
        btn.desc_param = desc_param
        btn.action = action
       # v.add_subview(btn_1)
        return  btn
    
    def page_info(text, image, dwell_time, desc):
        
        v = ui.View()
        v.background_color=bg_color
        title= make_title(text)
    
        for x, y in (screen_size.w/2, screen_size.h * 0.8), (screen_size.w/2, screen_size.h * 0.4), (screen_size.w/2, screen_size.h * 0.1):
            line = ui.Path()
            line = ui.Path.rounded_rect(x, y, screen_size.w * 0.8, 0, 50)
            line.line_width=3
            #display.add_subview(line)
        
        img = ui.ImageView()
        img.image = ui.Image.named(image)
        img.frame=(screen_size.w * 0.15, screen_size.h * 0.15, 300, 300)
        img.content_mode = ui.CONTENT_SCALE_ASPECT_FIT
    
        dwell = ui.Label()
        dwell.font= app_title_font, 25
        dwell.text = dwell_time
        dwell.alignment= ui.ALIGN_CENTER
        dwell.frame=screen_size.w * 0.10, screen_size.h * 0.45, screen_size.w * 0.75, screen_size.h * 0.05
    
        description = ui.TextView()
        description.editable=False
        description.scroll_enabled=True
        description.auto_content_inset=True
        description.background_color=bg_color
        description.alignment= ui.ALIGN_LEFT
        description.number_of_lines=0
        description.line_break_mode=ui.LB_CHAR_WRAP
        description.font=(text_font, 17)
        description.frame=(screen_size.w * 0.12, screen_size.h * 0.60, screen_size.w * 0.75, screen_size.h * 0.60)
        description.text=desc
        
        v.add_subview(title)
        v.add_subview(img)
        v.add_subview(dwell)
        v.add_subview(description)
        v.present('sheet', hide_title_bar=True)  
    
    def mask_page(sender):
        v = ui.View()
        v.background_color=bg_color
        
        title=make_title('mask')
        
        level_1_btn = make_button('Level 1', 0.12, 'Level 1', 'Level1Mask.PNG', '', level_1_desc, info_page)
        level_3_btn = make_button('Level 3', 0.22, 'Level 3', 'Level3Mask.PNG', '', level_3_desc, info_page)
        k_n95_btn = make_button('K-N95', 0.32, 'K-N95', 'Kn95Mask.PNG', '', k_n95_desc, info_page)
        n95_btn = make_button('N95', 0.42, 'N95', 'N95Mask.PNG', '', n95_desc, info_page)
        papr_btn = make_button('Papr', 0.52, 'Papr', 'PaprMask.PNG', '', papr_desc, info_page)
    
        v.add_subview(title)
        v.add_subview(level_1_btn)
        v.add_subview(level_3_btn)
        v.add_subview(k_n95_btn)
        v.add_subview(n95_btn)
        v.add_subview(papr_btn)
        v.present('sheet', hide_title_bar=True)
        
    def info_page(sender):
        page_info(sender.text_param, sender.image_param, sender.dwell_time_param, sender.desc_param)
     
    def gowns_page(sender):
        v = ui.View()
        v.background_color=bg_color
        title= make_title('Gowns')
        
        cloth_btn = make_button('Cloth', 0.12, 'Cloth', 'ClothGown.PNG', '', cloth_desc, info_page)
        plastic_btn = make_button('Plastic', 0.22, 'Plastic', 'PlasticGown.PNG', '', plastic_desc, info_page)
        
        v.add_subview(title)
        v.add_subview(cloth_btn)
        v.add_subview(plastic_btn)
        v.present('sheet', hide_title_bar=True)
        
    def wipes_page(sender):
        v = ui.View()
        v.background_color=bg_color
        v.present('sheet', hide_title_bar=True)
        
    def faq_page(sender):
        v = ui.View()
        v.background_color=bg_color
        
        title = ui.Label()
        title.font= text_font, 25
        title.text = "FAQ"
        title.alignment= ui.ALIGN_CENTER
        title.frame=screen_size.w * 0.1, screen_size.h * 0.02, screen_size.w * 0.75, screen_size.h * 0.05
        tv = ui.TextView()
        tv.editable=False
        tv.scroll_enabled=True
        tv.auto_content_inset=True
        tv.background_color=bg_color
        tv.alignment= ui.ALIGN_LEFT
        tv.number_of_lines= 0
        tv.line_break_mode = ui.LB_CHAR_WRAP
        tv.font= text_font, 17
        tv.frame= screen_size.w * 0.07, screen_size.h * 0.08, screen_size.w * 0.87, screen_size.h * 0.85
        tv.text = "Q. What is the difference between a K-N96 and a N95? \n\nA. Both products are said to filter 95 percent of aerosol particulates. K-N95 respirators differ from N95 respirators because they meet the Chinese standard but are not regulated by U.S. agencies. \n\nQ. Do mask really work? \n\nA. Yes. It stops the transmission of saliva and mucus from person to person "
        v.add_subview(title)
        v.add_subview(tv)
        v.present('sheet', hide_title_bar=True)
    
    def dd_page(sender):
        v = ui.View()
        v.background_color=bg_color
        
        title = ui.Label()
        title.font= text_font, 25
        title.text = "Dos and Don'ts"
        title.alignment= ui.ALIGN_CENTER
        title.frame=screen_size.w * 0.1, screen_size.h * 0.02, screen_size.w * 0.75, screen_size.h * 0.05
        
        tv = ui.TextView()
        tv.editable=False
        tv.scroll_enabled=True
        tv.auto_content_inset=True
        tv.background_color=bg_color
        tv.alignment= ui.ALIGN_LEFT
        tv.number_of_lines= 0
        tv.line_break_mode = ui.LB_CHAR_WRAP
        tv.font= text_font, 17
        tv.frame= screen_size.w * 0.07, screen_size.h* 0.08, screen_size.w * 0.85, screen_size.h * 0.85
        tv.text = "DO wear your cask correctly. Cover you mouth and nose. \nDON'T improperly wear your mask. Make sure you mouth and nose is covered.  \n\nDO keep you mask clean. \nDON'T touch mask with your hands. \n\nDO change your mask regulary. \nDON'T wear a dirty mask' \n\nDO wear your mask while talking. \nDON'T remove your mask to talk. \n\nDO wear masks that fit well and trap your breath. \nDON'T ware masks with vents. They allow your breath to escape and spread to others. \n\nDo keep 6 feet apart when out in public even while wearing a mask. \nDON'T beark social distancing even if your wearing a mask. \n\nDO"
        v.add_subview(title)
        v.add_subview(tv)
        v.present(hide_title_bar=True)
         
    def covid_page(sender):
        v= ui.View()
        v.background_color=bg_color
        
        title = ui.Label()
        title.font= app_title_font, 25
        title.text = 'Covid Information'
        title.alignment= ui.ALIGN_CENTER
        title.frame=screen_size.w * 0.1, screen_size.h * 0.02, screen_size.w * 0.75, screen_size.h * 0.05
        
        tv = ui.TextView()
        tv.editable=False
        tv.scroll_enabled=True
        tv.background_color=bg_color
        tv.alignment= ui.ALIGN_LEFT
        tv.number_of_lines= 0
        tv.line_break_mode = ui.LB_CHAR_WRAP
        tv.font= app_title_font, 17
        tv.frame= screen_size.w * 0.07, screen_size.h * 0.08, screen_size.w * 0.87, screen_size.h * 0.85
        tv.text = 'COVID-19 is caused by a coronavirus called SARS-CoV-2. Older adults and people who have severe underlying medical conditions like heart or lung disease or diabetes seem to be at higher risk for developing more serious complications from COVID-19 illness. \n\nSymptoms may appear 2-14 days after exposure to the virus. People with these symptoms may have COVID-19:\n\n•Fever or chills\n•Cough\n•Shortness of breath or difficulty breathing\n•Fatigue\n•Muscle or body aches\n•Headache\n•New loss of taste or smell\n•Sore throat\n•Congestion or runny nose\n•Nausea or vomiting\n•Diarrhea \n\nEmergency warning signs. If someone is showing any of these signs, seek emergency medical care immediately:\n\n•Trouble breathing\n•Persistent pain or pressure in the chest\n•New confusion\n•Inability to wake or stay awake\n•Bluish lips or face \n\nCOVID-19 most commonly spreads during close contact. People who are physically near (within 6 feet) a person with COVID-19 or have direct contact with that person are at greatest risk of infection. \n\nWhen people with COVID-19 cough, sneeze, sing, talk, or breathe they produce respiratory droplets. These droplets can range in size from larger droplets (some of which are visible) to smaller droplets. Small droplets can also form particles when they dry very quickly in the airstream. \n\nInfections occur mainly through exposure to respiratory droplets when a person is in close contact with someone who has COVID-19. Respiratory droplets cause infection when they are inhaled or deposited on mucous membranes, such as those that line the inside of the nose and mouth. \n\nAs the respiratory droplets travel further from the person with COVID-19, the concentration of these droplets decreases. Larger droplets fall out of the air due to gravity. Smaller droplets and particles spread apart in the air.With passing time, the amount of infectious virus in respiratory droplets also decreases.'
        v.add_subview(title)
        v.add_subview(tv)
        v.present(hide_title_bar=True)
          
    def links_page(sender):
        v = ui.View()
        v.background_color=bg_color
        
        v= ui.View()
        v.background_color=bg_color
        title = ui.Label()
        title.font= text_font, 25
        title.text = "Links"
        title.alignment= ui.ALIGN_CENTER
        title.frame=screen_size.w * 0.1, screen_size.h * 0.02, screen_size.w * 0.75, screen_size.h * 0.05
        
        tv = ui.TextView()
        tv.editable=False
        tv.scroll_enabled=True
        tv.auto_content_inset=True
        tv.background_color=bg_color
        tv.alignment= ui.ALIGN_CENTER
        tv.number_of_lines= 0
        tv.line_break_mode = ui.LB_CHAR_WRAP
        tv.font= text_font, 22
        tv.frame= screen_size.w * 0.07, screen_size.h * 0.08, screen_size.w * 0.87, screen_size.h * 0.85
        tv.text ='https://www.who.int/'
        v.add_subview(title)
        v.add_subview(tv)
        v.present('sheet', hide_title_bar=True)
          
    title = make_title(app_title)
        
    mask_btn = make_button('Mask', 0.12, '', '', '', '', mask_page)
    shield_btn = make_button('Shield', 0.22, 'Face Shield', 'FaceShield.JPG', '',fs_desc, info_page)
    gowns_btn = make_button('Gowns', 0.32,'', '', '', '', gowns_page)
    wipes_btn = make_button('Wipes', 0.42, '', '', '', '', wipes_page)
    faq_btn = make_button('FAQ', 0.52, '','','','',faq_page)
    dd_btn = make_button('Dos/Donts', 0.62, '', '', '', '', dd_page)
    covid_btn = make_button('Covid Info', 0.72, '', '', '', '', covid_page)
    links_btn = make_button('Links', 0.82, '', '', '', '', links_page)
    
    v.add_subview(title)
    v.add_subview(mask_btn)
    v.add_subview(shield_btn)
    v.add_subview(gowns_btn)
    v.add_subview(wipes_btn)
    v.add_subview(faq_btn)
    v.add_subview(dd_btn)
    v.add_subview(covid_btn)
    v.add_subview(links_btn)
    
    v.present('full_screen', orientations='portrait', hide_title_bar=True)
    
    

    I also have Trouble importing text from another file. I tried to set it up like the brick breaker levels and colors example but it’s not working.

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!