Level 9 : What happens if the file is not found in the following Python code?


a=False
while not a:
    try:
        f_n = input("Enter file name")
        i_f = open(f_n, 'r')
    except:
        print("Input file not found")

Author: SandhyaR | Tags: file-handling | 1859+ Python FAQs | Share
identity-operators-(is,-is-not) | encapsulation | class-and-inheritance | data-structures-in-python | class-and-object | regex | list-method | literal-characters-and-special-characters | expression | method-overloading | exponentiation | methods | max-min | global | logical-operators | filter-function | match | filter | conditional-statements | file-handling | list-slicing | multiprocessing | enumerate() | __all__-attribute | comprehension | asyncio | class-and-instance-variable | swapping | arbitrary-arguments-(*args,-**kwargs) | data-structure | string | lists | exception-handling | namedtuple | file | type-conversion | recursion | sets | comparison | context-manager | dataframe-and-series-objects | __future__ | datatype | exception | return-statement | loop-control-statements | thread-synchronization | file-handling | logical-operator | mathematics | mathematical-function | multithreading | multiple-inheritance | membership-operators-(in,-not-in) | working-with-file-paths | else-statement | functional-programming | application | __init_subclass__ | module | map-function | list-operation | loop | goto-function | logical-operator | creating-and-starting-threads | feature | using-the-threading-module | comment | fabs-function | file_handling | list-vs-tuple | design-principle | using-os-and-pathlib-modules | using-yield-in-functions | encoding | head-and-tail | dictionaries | reading:-read(),-readline(),-readlines() | method | input-function | sum() | floats | global-variable | using-join()-and-is_alive()-methods | loops | objects | string-formatting | software-design | precedence-and-associativity | single-inheritance | data-type | data-structures | loop-control | regular-expressions | type-conversion-and-casting | odd-number | thread-safe-data-structures-(queue.queue) | decorator | heap-memory | dictionary-methods | parsing-with-strptime | control-flow | choice | syntaxerror | static-method | operator-and | generators | key-value-pairs | indexing | constructor | escape-operator | round | syntax-error | benefit | reading-and-writing-files | introduction-to-multiprocessing | command-line-parsing | managing-directories-with-os-and-shutil | access-modifier | mysql | immutable-data-type | integers | rollback | data-structure | round-function | lambdas | inheritance | python-django | decimal | for | update | built-in-function | set-operation | default-arguments | magic-method | working-with-binary-files-(rb,-wb) | logical-operation | inherit | indexing:-loc-vs-iloc | object-attribute | boolean-and-non-boolean | tuple-methods | function-argument | matrix-list-comprehension | error-handling | string-slicing | list-comprehension | data-type | zip-function | function | bitwise | data-type-conversions | using-map()-for-transformations | tuples | package-management | name-mangling | string-concatenation | slice | multiple-inheritance | input-function | attribute | collection | math | list | conditional-statement | collections | yield | copy | oop | list,-set,-and-dictionary-comprehensions | threading | input | string-iteration | using-assertions-(assertequal,-assertraises) | bitwise-operator | thread | async | while-else-loop | booleans | writing:-write(),-writelines() | defining-functions | installation | sum-function | virtual-environment | else | while-loop | datetime.date,-datetime.time,-datetime.datetime | walking-through-directories-using-os.walk() | creating-custom-modules | operator-or | string-slicing | anchors-(^,-$) | opening-files-(open()) | min-function | interpreter | recurssion | operand | pseudocode | typeerror | using-else-and-finally | intering | sys-module | with-statement | polymorphism | while-loops | id-function | iterable | invalid-list | using-lists-as-stacks | syntax-error | memory | init | deep-copy | directory-operations | python | zfill-function | datetime | list-join | boolean | string-method | format | string-manipulation | while-and-for-loop | generators-in-python | default-mutable-argument | regular-expression | random-function | oops | operator-overloading | identifier | introduction-to-threads | multiple-except-blocks | dictionary | operations | frozenset | joining-and-merging-dataframes | built-in-function | keyword | functions | list-methods-and-slicing | namespace | exception-handling | slicing | staticmethod | version | string-methods | numpy | arithmetic-operation | pandas | why-use-multiprocessing-over-threading?-(gil) | working-with-temporary-files-using-tempfile | advanced-file-operations | lambda-function | binary | math-copysign | generator | debugging | import-method | min-max-function | sorting | list-mutation | destructor | quantifiers-(*,-+,-?,-{}) | list-comprehensions | sorting-and-ranking | array | type-conversion | dicts | higher-order-function | python_version | turtle | mutable | basic | lambda | sys | introduction-to-python | compute | formal-and-actual-parameter | memory-management | function-and-scope | complex-number | matplotlib | append | matrix | functional-programming | docstring | operator | iterators | version-check | data-types | def | classes | print-statement | python-module | asyncio-module | tuple-unpacking | lambda-functions | scientific-notation | raise | dictionary-comprehensions | python-repl | time-series-with-pandas | join | list-indexing | bitwise-operator | virtual-environment | handling-missing-values-(fillna,-dropna) | indentation | raise-statement | unit-testing | set | binary-operation | type_conversion | error-handling | tuple | floating-point-precision | variable | zip | pass | list-comprehension | gil | arithmetic-expression | complex | data_structure | touples | implementation | stack | descriptors | print | python-history | sorted | python-operators | test-discovery | working-with-dates-and-times | overflow | string-method | built-in-modules | global-variable | overriding-methods | strings | range | shallow-copy | identity-operator | postfix | assignment-operator | global-keyword | precedence | filtering-and-indexing | control-flow | string-formatting | class | reading-and-writing-large-files-efficiently | python-syntax-and-structure | assert | mapping-function | formatting-with-strftime | parameter | conversion | random | immutability | conditional-statement | nested-loop | boolean-masking | syntax | condition | difference-between-threads-and-processes | operators | split | counter-function | library | numeric | factorial-function | statement | pep | pickling--unpickling | control-statement | built-in | error | int | counter | expand-tab | center | assignment-operators | iterator | identity-operator | integer | call | class-decorators | aggregating-data-with-functools.reduce() ...