Answered step by step
Verified Expert Solution
Question
1 Approved Answer
aaa Notrpad | localhostaggaotebooks/Untitled27ipynb?kernel name-python2 Jupyter Untitled27 Last Checkpolnt: 8 minutes ago (unsaved changes) le Edit i InsertlKee Widgets Help File Edit Format View Help
aaa Notrpad | localhostaggaotebooks/Untitled27ipynb?kernel name-python2 Jupyter Untitled27 Last Checkpolnt: 8 minutes ago (unsaved changes) le Edit i InsertlKee Widgets Help File Edit Format View Help est a line 1 line 2 line 3 In [1 def open function(P): f-open(P, 'r') first_line f.readline) rest - f.readlines) these are the files itPatxt itPbbb. txt returnfirst line a rest f.close resta rest rest b rest In [21: a rest-open function aaa.txt') bbb Notepad File Edit Format View Help test b ine 1 line 2 h Traceback (nost cent call last) NameError ipython-input-2-d8eb85022996 in () ---> 1 a_rest-open_function(aaa.txt) line 3 line 4 ipython-input-1-2fc85f292f in open function(P) if P a.txt: rest-a rest if P 'bbb.txt: rest-b rest NameError : name . a rest' is not defined tnis tunctuon opens a rile takes tne top ine of the file and calls it first line and takes the rest of the file and calls it 'rest' i would like to be able to differentiate between the 'rest' that can be extracted from the two files. so if rest came from aaa.txt i call rest a_rest and if im loading it from bbb.txt i call it b_rest which i try to do with if p'aaa.txt' if p'bbb.txt': return first line, a rest resta rest rest-b rest however it doesnt work e_rest t-open function aaa.txt Traceback (most cent call last) > Nametrror in > 1 arest->en-function(' aaa.txt.) in open function(P) if p"aaa.txt'; rest - a rest if p "bbb.txt rest b rest NameError: name 'a rest' is not defined how can i make this open_function work the way i want
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started