Python

Python

Files has 15 Questions
To open a file c:\scores.txt for reading, we use?

infile = open("c:\scores.txt"?, "r"?)
infile = open("c:\\scores.txt"?, "r"?)
infile = open(file = "c:\scores.txt"?, "r"?)
infile = open(file = "c:\\scores.txt"?, "r"?)
To open a file c:\scores.txt for writing, we use?

outfile = open("c:\scores.txt"?, "w"?)
outfile = open("c:\\scores.txt"?, "w"?)
outfile = open(file = "c:\scores.txt"?, "w"?)
outfile = open(file = "c:\\scores.txt"?, "w"?)
To open a file c:\scores.txt for appending data, we use?

outfile = open("c:\\scores.txt"?, "a"?)
outfile = open("c:\\scores.txt"?, "rw"?)
outfile = open(file = "c:\scores.txt"?, "w"?)
outfile = open(file = "c:\\scores.txt"?, "w"?)
To read two characters from a file object infile, we use?

infile.read(2)
infile.read()
infile.readline()
infile.readlines()
To read the entire remaining contents of the file as a string from a file object infile, we use

infile.read(2)
infile.read()
infile.readline()
infile.readlines()
What is the output?
  1. f = None
  2. ?
  3. for i in range (5):
  4.     with open("data.txt", "w") as f:
  5.         if i > 2:
  6.             break
  7. ?
  8. print f.closed

True
False
None
Error
To read the next line of the file from a file object infile, we use?

infile.read(2)
infile.read()
infile.readline()
infile.readlines()
To read the remaining lines of the file from a file object infile, we use?

infile.read(2)
infile.read()
infile.readline()
infile.readlines()
The readlines() method returns

str
a list of lines
a list of single characters
a list of integers
What is the output of this program?
  1. str = raw_input("Enter your input: ");
  2. print "Received input is : ", str

Enter your input: Hello Python Received input is : Hello Python
Enter your input: Hello Python Received input is : Hello
Enter your input: Hello Python Received input is : Python
None of the mentioned
What is the output of this program?
  1. str = input("Enter your input: ");
  2. print "Received input is : ", str

Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 20, 30, 40]
Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 30, 20, 40]
Enter your input: [x*5 for x in range(2,10,2)] Received input is : [10, 10, 30, 40]
None of the mentioned
Which one of the following is not attributes of file?

closed
softspace
rename
mode
. Which is/are the basic I/O connections in file?

Standard Input
Standard Output
Standard Errors
All of the above e) None of the above
What is the output of this program?
  1. import sys
  2. print 'Enter your name: ',
  3. ?
  4. name = ''
  5. ?
  6. while True:
  7.    c = sys.stdin.read(1)
  8.    if c == '\n':
  9.       break
  10.    name = name + c
  11. ?
  12. print 'Your name is:', name

If entered name is sanfound


sanfoundry
sanfoundry, sanfoundry
San
None of the mentioned
What is the output of this program?
  1. import sys
  2. ?
  3. sys.stdout.write(' Hello\n')
  4. sys.stdout.write('Python\n')


Compilation Error
Runtime Error
Hello Python
Hello Python