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