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