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