Python Forum
get state code, state name and state abbreviation
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
get state code, state name and state abbreviation
#5
DeaD_EyE thanks, I'll use this.
I didn't even know this had been built into python (since 3.4) until you mentioned it.
It's worth exploring what's there, here's a sample that just touches the surface
(I could have made this look exactly like Linux ls, but I'm too tired to do so now).
from pathlib import Path


class SetPath:
    def __init__(self):
        self.make_paths()

    def make_paths(self):
        self.homepath = Path('.')
        self.show_contents(self.homepath)
        self.datapath = self.homepath / 'data'
        self.show_contents(self.datapath)
        self.zippath = self.homepath / '../ZipcodeData'
        self.show_contents(self.zippath)
        self.addrpath = self.zippath / 'ADDR'
        # print([f'{x}\n' for x in addrpath.iterdir()])
        self.show_contents(self.addrpath)


    @staticmethod
    def show_contents(folder):
        print(f'\ndir {folder.name}')
        for item in folder.iterdir():
            if item.is_dir():
                print(f'    d..{item}')
            else:
                print(f'    ...{item}')


if __name__ == '__main__':
    SetPath()
gives:
Output:
directory Name:     ...CreateStateCdJsonFile.py     d..data     ...FetchTiger2016AddrFiles.py     ...MakeCensusNameJson.py     ...SetPath.py     ...snippet.py     ...__init__.py directory Name: data     ...data\addrfiles.txt     ...data\StateByName.json directory Name: ZipcodeData     .....\ZipcodeData\4c90ea7b-1c0b-4ace-9eb0-a9eb01602f18.json     d....\ZipcodeData\ADDR     d....\ZipcodeData\ByState     .....\ZipcodeData\ea323919-fe1e-41e8-a53d-7404e0801116.json     .....\ZipcodeData\free-zipcode-database-Primary.csv     .....\ZipcodeData\free-zipcode-database.csv     .....\ZipcodeData\tlgdb_2017_a_us_addr.gdb.zip     d....\ZipcodeData\zcat directory Name: ADDR     d....\ZipcodeData\ADDR\AK_02     d....\ZipcodeData\ADDR\AL_01     d....\ZipcodeData\ADDR\AR_05     d....\ZipcodeData\ADDR\AS_03     d....\ZipcodeData\ADDR\AS_60     d....\ZipcodeData\ADDR\AZ_04     d....\ZipcodeData\ADDR\CA_06     d....\ZipcodeData\ADDR\CO_08     d....\ZipcodeData\ADDR\CT_09     d....\ZipcodeData\ADDR\CZ_07     d....\ZipcodeData\ADDR\DC_11     d....\ZipcodeData\ADDR\DE_10     .....\ZipcodeData\ADDR\dirs.txt     d....\ZipcodeData\ADDR\FL_12     d....\ZipcodeData\ADDR\FM_64     d....\ZipcodeData\ADDR\GA_13     .....\ZipcodeData\ADDR\GetAllAddr.bat     .....\ZipcodeData\ADDR\makeDir.bat     .....\ZipcodeData\ADDR\tl_2016_01001_addr.zip     d....\ZipcodeData\ADDR\TN_47     d....\ZipcodeData\ADDR\TX_48     d....\ZipcodeData\ADDR\UM_74     d....\ZipcodeData\ADDR\UT_49     d....\ZipcodeData\ADDR\VA_51     d....\ZipcodeData\ADDR\VI_52     d....\ZipcodeData\ADDR\VI_78     d....\ZipcodeData\ADDR\VT_50     d....\ZipcodeData\ADDR\WA_53     d....\ZipcodeData\ADDR\WI_55     d....\ZipcodeData\ADDR\WV_54     d....\ZipcodeData\ADDR\WY_56
Reply


Messages In This Thread
RE: get state code, state name and state abbreviation - by Larz60+ - Oct-12-2017, 11:56 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Brick 3 features for python flask state. aaronxiongli 0 2,689 Nov-09-2020, 03:19 AM
Last Post: aaronxiongli
Lightbulb I built a state monitor using Python+Flask! (for new user) aaronxiongli 0 1,744 Nov-04-2020, 08:11 AM
Last Post: aaronxiongli
  JSON file with links for each US state Open Data Page Larz60+ 5 5,794 Mar-05-2017, 11:19 AM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020