0

I have tried every online formatter, I could find and every which way to indent but I continuously am getting an error on from data.find_pending_records. Here is my code:

"""Start Point"""

from data.find_pending_records
import FindPendingRecords
from vital.vital_entry
import VitalEntry

if __name__ == "__main__":
    try:
        # Instantiates FindPendingRecords then gets records to process
        for PENDING_RECORDS = FindPendingRecords().get_excel_data()

    # Reads excel to map data from excel to vital
    MAP_DATA = FindPendingRecords().get_mapping_data()

    # Configures Driver
    for vital
    VITAL_ENTRY = VitalEntry()

    # Start chrome and navigate to vital website
    VITAL_ENTRY.instantiate_chrome()

    # Begin processing Records
    VITAL_ENTRY.process_records(PENDING_RECORDS, MAP_DATA)

    print(PENDING_RECORDS)
    print("All done")
except Exception as exc:
    print(exc)  

The error in the Anaconda prompt isn't very informative. It's just giving:

SyntaxError: invalid syntax

(base) C:\Python>python main.py
  File "main.py", line 4
    from data.find_pending_records

Also, in Visual Studio Code it's just a red squiggly line under the same from, no details either.

Any ideas?

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
Dr Upvote
  • 8,023
  • 24
  • 91
  • 204

2 Answers2

4

The import needs to go on the same line as the from:

from data.find_pending_records import FindPendingRecords
from vital.vital_entry import VitalEntry
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
2

Indicating that the line is not terminated you could use \

from data.find_pending_records \
import FindPendingRecords

You could also indent to make it more readable

from data.find_pending_records \
    import FindPendingRecords
mad_
  • 8,121
  • 2
  • 25
  • 40
  • 1
    Yes, this also works. The point is that the `from` part can't stand on its own without a corresponding `import` part. In my opinion this version is harder to read and less clear than the one line version, but it's valid. – ChrisGPT was on strike Mar 18 '19 at 14:32
  • 1
    At the very least the second line should be indented to make it clear that it’s a continuation of the previous line. – Konrad Rudolph Mar 18 '19 at 14:35
  • @Chris Everything has pros and cons. If you have limited number of imports then I will prefer your method as it is readable and crisp. But, if you have lets say 100 imports from a single module then it will be a mess while trying to write everything in a single line. What you could do is indent the lines following the `from` statement. Will update the answer – mad_ Mar 18 '19 at 14:36
  • If you have 100 imports from a single module a common idiom is to put the first import on the same line as the `from` and wrap the list of imports in parentheses. I don't see a good reason to breaking after `from`, this idiom doesn't appear in the official style guide, and it forces you to add extra syntax just to be valid. IMO it's not a good choice for many reasons but, as I said before, it's valid. I did upvote this answer, for what it's worth. I just don't recommend using it. – ChrisGPT was on strike Mar 18 '19 at 14:39
  • Note that one statement giving 100 imports from a single module would have only one `import`. It makes a lot more sense to keep the single `import` with the single `from` rather than with the n-ary list of imported names. (I.e., what would the next line look like if you're importing two things from `data.find_printing_records`?) – ChrisGPT was on strike Mar 18 '19 at 14:41
  • @Chris Sorry my bad. There will be a single import but what I meant by the above statement is if you have 100 entities to import then it will be more readable to break it into multiple lines – mad_ Mar 18 '19 at 14:44
  • @mad_, right, but the `import` should still go on the same line as `from`. Otherwise you have one line with `from`, another line with `import`, and possibly `n` lines without either, just naming things to be imported. Something like [this](https://stackoverflow.com/a/14377271/354577) is a common idiom that I definitely prefer. But your version is valid, and at the end of the day this is opinion. Adhere to style guides for the project if they're available, be consistent with other developers if not, and if you're on your own do whatever you like (but still be consistent). – ChrisGPT was on strike Mar 18 '19 at 14:45