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