Python Forum
Need help (very... very new to python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help (very... very new to python
#1
So, I have this script below (single dashed line below). I want it to prompt for the file and it does. But rather than changes all the words to Uppercase, I only want to change those in the file such as: words = ['select', 'from', 'where']

So, I want all wording in the program (see all the wording below the dashed line), but want just change those words in the file to uppercase.

However, not sure where or how what I need to do to change the coding below. Any help would be great.

Thanks,
Vince
-----------------------------------------------------------------------------------------------------------------------------------------------------

words = ['select', 'from', 'where']

totContent = ""
print(end="Enter the Name of File: ")
fileName = str(input())

try:
    fileHandle = open(fileName, "r")
    for content in fileHandle:
        newContent = content.upper()
        totContent = totContent + newContent
    fileHandle.close()
	
    try:
        fileHandle = open(fileName, "w")
        fileHandle.write(totContent)
        print("\nAll Words in \"" + fileName + "\" Capitalized Successfully!")
        print(end="\nWant to see the Content of File (y/n): ")
        ch = input()
        if ch=='y':
            fileHandle = open(fileName, "r")
            for content in fileHandle:
                print(end=content)
        else:
            print("Exiting...")
        fileHandle.close()
        print()
    except IOError:
        print("Error Occurred!")
		
except IOError:
    print("\nThe \"" + fileName + "\" is not Exist!")
    print("Exiting...")


============================================================================

Select distinct p."First", p."Last", trim(p."First") || '_' || trim(p."Last") || '_' || to_char(p."Birth", 'yyyyymmdd') LinkingField, null SSN, null RegistrationCode, p."Address1", p."Address2",
    null Address3, "City", "Province" State, substr("Postal", 1, 5) ZipCode, Case when v.FirstDate is null or v.FirstDate >= QStart then 'Y' Else 'N' End NewPatient, 
--    Case when pol."PlanType" in (0, 1, 2, 3, 4,  5, 14, 16, 18, 22, 25, 26) then 'N' else 'Y' End PrivateInsurance, 
    Case when pol."PolicyId" is null then 'N' Else 'Y' End Insurance, --per Erin 11/16/21 - any type of insurance
    pol.Company
    from appoint a
    left outer join (select "Patient", min(t."TreatmentDate") FirstDate
        from trx t
        join njds_isvisit v on t."Type" = v."Type" and t."Id" = v."Id" and t."Treatment" = v."Treatment"
        where v.IsVisit = 1
        and exists (select null from trx t2
            join njds_isvisit v2  on t2."Type" = v2."Type" and t2."Id" = v2."Id" and t2."Treatment" = v2."Treatment"
            where v2.Isvisit = 1
            and t2."TreatmentDate" between QStart and QEnd  -- >= '01 Sep 2021'
            and t."Patient" = t2."Patient")

        Group by "Patient") v on a."Patient" = v."Patient"
    left outer join (select "Family" Patient, pol."PlanType", i."Name" Company, pol."PolicyId"
        from policy pol
        join insuranc i on pol."Company" = i."Company"
        where pol."Deleted" = 0
        and pol."Company" not in (select null from NJDS_NOT_INSURANCE ni where pol."Company" = ni.Company)
        and (pol."EndDate" is null or pol."EndDate" >= QStart)) pol on a."Patient" = pol.Patient
    join patient p on a."Patient" = p."Patient"
    where a."Date" between QStart and QEnd
Larz60+ write Jun-22-2022, 10:34 AM:
(As suggested by deanhystad):
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
I have fixed this for you this time. Please use BBCode tags on future posts.
Reply
#2
Please wrap code in Python tags. There is a button in the editor for doing ths.
ndc85430 likes this post
Reply
#3
Thanks Larz60+ and Dean. I appreciate it. I hope this is okay. Please know it is not so much of an error as it is I do not know how to code for finding words like 'select', 'from', 'where' in the file and then converting them to uppercase. Thus, I have no errors since I am not sure how to accomplish that. Again, I am literally new to Python. Like this is my first ever script I am trying to create.

Vince



words = ['select', 'from', 'where']

totContent = ""
print(end="Enter the Name of File: ")
fileName = str(input())

try:
    fileHandle = open(fileName, "r")
    for content in fileHandle:
        newContent = content.upper()
        totContent = totContent + newContent
    fileHandle.close()
	
    try:
        fileHandle = open(fileName, "w")
        fileHandle.write(totContent)
        print("\nAll Words in \"" + fileName + "\" Capitalized Successfully!")
        print(end="\nWant to see the Content of File (y/n): ")
        ch = input()
        if ch=='y':
            fileHandle = open(fileName, "r")
            for content in fileHandle:
                print(end=content)
        else:
            print("Exiting...")
        fileHandle.close()
        print()
    except IOError:
        print("Error Occurred!")
		
except IOError:
    print("\nThe \"" + fileName + "\" is not Exist!")
    print("Exiting...")
Reply
#4
Start by finding capitalizing "select" in
"I would like to capitalize select in this sentence."

Next try it in
"I would like to capitalize all occurrences of select."

and
"Please select an item from the selection".

If you can do those you should be able to do it for a file. Start small. Work up to big.
Reply


Forum Jump:

User Panel Messages

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