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