форкнуто от main/python-labs
Родитель
8c3d0dda94
Сommit
1b0cbe9074
@ -1,359 +1,400 @@
|
|||||||
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
|
Python 3.11.5 (tags/v3.11.5:cce6ba9, Aug 24 2023, 14:38:34) [MSC v.1936 64 bit (AMD64)] on win32
|
||||||
Type "help", "copyright", "credits" or "license()" for more information.
|
Type "help", "copyright", "credits" or "license()" for more information.
|
||||||
stroka='Автоматизированная система управления'
|
stroka='Автоматизированная система управления'
|
||||||
stroka
|
stroka
|
||||||
'Автоматизированная система управления'
|
'Автоматизированная система управления'
|
||||||
fff=234.5;gg='Значение температуры = '
|
fff=234.5;gg='Значение температуры = '
|
||||||
print(gg, fff)
|
print(gg, fff)
|
||||||
Значение температуры = 234.5
|
Значение температуры = 234.5
|
||||||
print(gg, fff, sep='/')
|
print(gg, fff, sep='/')
|
||||||
Значение температуры = /234.5
|
Значение температуры = /234.5
|
||||||
print(gg, fff,sep='/',end='***'); print('____')
|
print(gg, fff,sep='/',end='***'); print('____')
|
||||||
Значение температуры = /234.5***____
|
Значение температуры = /234.5***____
|
||||||
print()
|
print()
|
||||||
|
|
||||||
print(""" Здесь может выводиться
|
print(""" Здесь может выводиться
|
||||||
большой текст,
|
большой текст,
|
||||||
занимающий несколько строк""")
|
занимающий несколько строк""")
|
||||||
Здесь может выводиться
|
Здесь может выводиться
|
||||||
большой текст,
|
большой текст,
|
||||||
занимающий несколько строк
|
занимающий несколько строк
|
||||||
print("Здесь может выводиться",
|
print("Здесь может выводиться",
|
||||||
"большой текст,",
|
"большой текст,",
|
||||||
"занимающий несколько строк")
|
"занимающий несколько строк")
|
||||||
Здесь может выводиться большой текст, занимающий несколько строк
|
Здесь может выводиться большой текст, занимающий несколько строк
|
||||||
import sys
|
import sys
|
||||||
sys.stdout.write('Функция write')
|
sys.stdout.write('Функция write')
|
||||||
Функция write13
|
Функция write13
|
||||||
sys.stdout.write('Функция write')
|
sys.stdout.write('Функция write')
|
||||||
Функция write13
|
Функция write13
|
||||||
sys.stdout.write('Функция write\n')
|
sys.stdout.write('Функция write\n')
|
||||||
Функция write
|
Функция write
|
||||||
14
|
14
|
||||||
psw=input('Введите пароль:')
|
psw=input('Введите пароль:')
|
||||||
Введите пароль:a
|
Введите пароль:a
|
||||||
psw
|
psw
|
||||||
'a'
|
'a'
|
||||||
type(psw)
|
type(psw)
|
||||||
<class 'str'>
|
<class 'str'>
|
||||||
while True:
|
while True:
|
||||||
znach=float(input('Задайте коэф.усиления = '))
|
znach=float(input('Задайте коэф.усиления = '))
|
||||||
if znach<17.5 or znach>23.8:
|
if znach<17.5 or znach>23.8:
|
||||||
print('Ошибка!')
|
print('Ошибка!')
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
SyntaxError: inconsistent use of tabs and spaces in indentation
|
SyntaxError: inconsistent use of tabs and spaces in indentation
|
||||||
while True:
|
while True:
|
||||||
znach=float(input('Задайте коэф.усиления = '))
|
znach=float(input('Задайте коэф.усиления = '))
|
||||||
if znach<17.5 or znach>23.8:
|
if znach<17.5 or znach>23.8:
|
||||||
print('Ошибка!')
|
print('Ошибка!')
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
Задайте коэф.усиления = 15.4
|
Задайте коэф.усиления = 15.4
|
||||||
Ошибка!
|
Ошибка!
|
||||||
Задайте коэф.усиления = 21.6
|
Задайте коэф.усиления = 21.6
|
||||||
import math
|
import math
|
||||||
print(eval(input('введите выражение для расчета = ')))
|
print(eval(input('введите выражение для расчета = ')))
|
||||||
введите выражение для расчета = math.log10(23/(1+math.exp(-3.24)))
|
введите выражение для расчета = math.log10(23/(1+math.exp(-3.24)))
|
||||||
1.34504378689765
|
1.34504378689765
|
||||||
import os
|
import os
|
||||||
os.chdir('L:\\III курс\\А-3-23\\Korneev')
|
os.chdir('L:\\III курс\\А-3-23\\Korneev')
|
||||||
os.getcwd()
|
os.getcwd()
|
||||||
'L:\\III курс\\А-3-23\\Korneev'
|
'L:\\III курс\\А-3-23\\Korneev'
|
||||||
korneev = os.getcwd()
|
korneev = os.getcwd()
|
||||||
print(korneev)
|
print(korneev)
|
||||||
L:\III курс\А-3-23\Korneev
|
L:\III курс\А-3-23\Korneev
|
||||||
help(os.mkdir)
|
help(os.mkdir)
|
||||||
Help on built-in function mkdir in module nt:
|
Help on built-in function mkdir in module nt:
|
||||||
|
|
||||||
mkdir(path, mode=511, *, dir_fd=None)
|
mkdir(path, mode=511, *, dir_fd=None)
|
||||||
Create a directory.
|
Create a directory.
|
||||||
|
|
||||||
If dir_fd is not None, it should be a file descriptor open to a directory,
|
If dir_fd is not None, it should be a file descriptor open to a directory,
|
||||||
and path should be relative; path will then be relative to that directory.
|
and path should be relative; path will then be relative to that directory.
|
||||||
dir_fd may not be implemented on your platform.
|
dir_fd may not be implemented on your platform.
|
||||||
If it is unavailable, using it will raise a NotImplementedError.
|
If it is unavailable, using it will raise a NotImplementedError.
|
||||||
|
|
||||||
The mode argument is ignored on Windows. Where it is used, the current umask
|
The mode argument is ignored on Windows. Where it is used, the current umask
|
||||||
value is first masked out.
|
value is first masked out.
|
||||||
|
|
||||||
os.mkdir()
|
os.mkdir()
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<pyshell#28>", line 1, in <module>
|
File "<pyshell#28>", line 1, in <module>
|
||||||
os.mkdir()
|
os.mkdir()
|
||||||
TypeError: mkdir() missing required argument 'path' (pos 1)
|
TypeError: mkdir() missing required argument 'path' (pos 1)
|
||||||
os.mkdir('a')
|
os.mkdir('a')
|
||||||
help(os.rmdir)
|
help(os.rmdir)
|
||||||
Help on built-in function rmdir in module nt:
|
Help on built-in function rmdir in module nt:
|
||||||
|
|
||||||
rmdir(path, *, dir_fd=None)
|
rmdir(path, *, dir_fd=None)
|
||||||
Remove a directory.
|
Remove a directory.
|
||||||
|
|
||||||
If dir_fd is not None, it should be a file descriptor open to a directory,
|
If dir_fd is not None, it should be a file descriptor open to a directory,
|
||||||
and path should be relative; path will then be relative to that directory.
|
and path should be relative; path will then be relative to that directory.
|
||||||
dir_fd may not be implemented on your platform.
|
dir_fd may not be implemented on your platform.
|
||||||
If it is unavailable, using it will raise a NotImplementedError.
|
If it is unavailable, using it will raise a NotImplementedError.
|
||||||
|
|
||||||
os.rmdir('a')
|
os.rmdir('a')
|
||||||
os.listdir()
|
os.listdir()
|
||||||
['Lab Raboty IT', 'poas', 'shemotehnika', 'vichmetod']
|
['Lab Raboty IT', 'poas', 'shemotehnika', 'vichmetod']
|
||||||
help(os.path.isdir)
|
help(os.path.isdir)
|
||||||
Help on function isdir in module genericpath:
|
Help on function isdir in module genericpath:
|
||||||
|
|
||||||
isdir(s)
|
isdir(s)
|
||||||
Return true if the pathname refers to an existing directory.
|
Return true if the pathname refers to an existing directory.
|
||||||
|
|
||||||
os.path.isdir('poas')
|
os.path.isdir('poas')
|
||||||
True
|
True
|
||||||
fil=os.path.abspath("oplata.dbf")
|
fil=os.path.abspath("oplata.dbf")
|
||||||
fil
|
fil
|
||||||
'L:\\III курс\\А-3-23\\Korneev\\oplata.dbf'
|
'L:\\III курс\\А-3-23\\Korneev\\oplata.dbf'
|
||||||
fil=os.path.abspath("text.txt")
|
fil=os.path.abspath("text.txt")
|
||||||
fil
|
fil
|
||||||
'L:\\III курс\\А-3-23\\Korneev\\text.txt'
|
'L:\\III курс\\А-3-23\\Korneev\\text.txt'
|
||||||
drkt=os.path.dirname(fil)
|
drkt=os.path.dirname(fil)
|
||||||
drkt
|
drkt
|
||||||
'L:\\III курс\\А-3-23\\Korneev'
|
'L:\\III курс\\А-3-23\\Korneev'
|
||||||
os.path.basename(fil)
|
os.path.basename(fil)
|
||||||
'text.txt'
|
'text.txt'
|
||||||
help(os.path.split)
|
help(os.path.split)
|
||||||
Help on function split in module ntpath:
|
Help on function split in module ntpath:
|
||||||
|
|
||||||
split(p)
|
split(p)
|
||||||
Split a pathname.
|
Split a pathname.
|
||||||
|
|
||||||
Return tuple (head, tail) where tail is everything after the final slash.
|
Return tuple (head, tail) where tail is everything after the final slash.
|
||||||
Either part may be empty.
|
Either part may be empty.
|
||||||
|
|
||||||
os.path.split(fil)
|
os.path.split(fil)
|
||||||
('L:\\III курс\\А-3-23\\Korneev', 'text.txt')
|
('L:\\III курс\\А-3-23\\Korneev', 'text.txt')
|
||||||
os.path.exists(fil)
|
os.path.exists(fil)
|
||||||
True
|
True
|
||||||
os.path.exists('L:\\III курс\\А-3-23\\Korneev\\hello.txt')
|
os.path.exists('L:\\III курс\\А-3-23\\Korneev\\hello.txt')
|
||||||
False
|
False
|
||||||
os.path.isfile(fil)
|
os.path.isfile(fil)
|
||||||
True
|
True
|
||||||
fp=open(file=drkt+'\\text.txt',mode='w')
|
fp=open(file=drkt+'\\text.txt',mode='w')
|
||||||
type(fp)
|
type(fp)
|
||||||
<class '_io.TextIOWrapper'>
|
<class '_io.TextIOWrapper'>
|
||||||
dir(fp)
|
dir(fp)
|
||||||
['_CHUNK_SIZE', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_finalizing', 'buffer', 'close', 'closed', 'detach', 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'line_buffering', 'mode', 'name', 'newlines', 'read', 'readable', 'readline', 'readlines', 'reconfigure', 'seek', 'seekable', 'tell', 'truncate', 'writable', 'write', 'write_through', 'writelines']
|
['_CHUNK_SIZE', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__enter__', '__eq__', '__exit__', '__format__', '__ge__', '__getattribute__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__lt__', '__ne__', '__new__', '__next__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_checkClosed', '_checkReadable', '_checkSeekable', '_checkWritable', '_finalizing', 'buffer', 'close', 'closed', 'detach', 'encoding', 'errors', 'fileno', 'flush', 'isatty', 'line_buffering', 'mode', 'name', 'newlines', 'read', 'readable', 'readline', 'readlines', 'reconfigure', 'seek', 'seekable', 'tell', 'truncate', 'writable', 'write', 'write_through', 'writelines']
|
||||||
fp1=open(drkt+'\\zapis2.bin',mode='wb+')
|
fp1=open(drkt+'\\zapis2.bin',mode='wb+')
|
||||||
fp.close()
|
fp.close()
|
||||||
fpl.close()
|
fpl.close()
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<pyshell#52>", line 1, in <module>
|
File "<pyshell#52>", line 1, in <module>
|
||||||
fpl.close()
|
fpl.close()
|
||||||
NameError: name 'fpl' is not defined. Did you mean: 'fil'?
|
NameError: name 'fpl' is not defined. Did you mean: 'fil'?
|
||||||
fp1.close()
|
fp1.close()
|
||||||
sps=list(range(1,13))
|
sps=list(range(1,13))
|
||||||
fp2=open('zapis3.txt','w')
|
fp2=open('zapis3.txt','w')
|
||||||
fp2.write(str(sps[:4])+'\n')
|
fp2.write(str(sps[:4])+'\n')
|
||||||
13
|
13
|
||||||
fp2.write(str(sps[4:8])+'\n')
|
fp2.write(str(sps[4:8])+'\n')
|
||||||
13
|
13
|
||||||
fp2.write(str(sps[8:])+'\n')
|
fp2.write(str(sps[8:])+'\n')
|
||||||
16
|
16
|
||||||
fp2.close()
|
fp2.close()
|
||||||
sps3=[['Иванов И.',1],['Петров П.',2],['Сидоров С.',3]]
|
sps3=[['Иванов И.',1],['Петров П.',2],['Сидоров С.',3]]
|
||||||
fp3=open('zapis4.txt','w')
|
fp3=open('zapis4.txt','w')
|
||||||
for i in range(len(sps3)):
|
for i in range(len(sps3)):
|
||||||
stroka4=sps3[i][0]+' '+str(sps3[i][1])fp3.write(stroka4)
|
stroka4=sps3[i][0]+' '+str(sps3[i][1])fp3.write(stroka4)
|
||||||
|
|
||||||
SyntaxError: invalid syntax
|
SyntaxError: invalid syntax
|
||||||
for i in range(len(sps3)):
|
for i in range(len(sps3)):
|
||||||
stroka4=sps3[i][0]+' '+str(sps3[i][1])fp3.write(stroka4)
|
stroka4=sps3[i][0]+' '+str(sps3[i][1])fp3.write(stroka4)
|
||||||
|
|
||||||
SyntaxError: invalid syntax
|
SyntaxError: invalid syntax
|
||||||
for i in range(len(sps3)):
|
for i in range(len(sps3)):
|
||||||
stroka4=sps3[i][0]+' '+str(sps3[i][1])
|
stroka4=sps3[i][0]+' '+str(sps3[i][1])
|
||||||
fp3.write(stroka4)
|
fp3.write(stroka4)
|
||||||
|
|
||||||
|
|
||||||
11
|
11
|
||||||
11
|
11
|
||||||
12
|
12
|
||||||
fp3.close()
|
fp3.close()
|
||||||
gh=open('zapis5.txt','w')
|
gh=open('zapis5.txt','w')
|
||||||
for r in sps3:
|
for r in sps3:
|
||||||
gh.write(r[0]+' '+str(r[1])+'\n')
|
gh.write(r[0]+' '+str(r[1])+'\n')
|
||||||
|
|
||||||
|
|
||||||
12
|
12
|
||||||
12
|
12
|
||||||
13
|
13
|
||||||
gh.close()
|
gh.close()
|
||||||
sps1=[]
|
sps1=[]
|
||||||
fp=open('zapis3.txt')
|
fp=open('zapis3.txt')
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
stroka=stroka.rstrip('\n')
|
stroka=stroka.rstrip('\n')
|
||||||
stroka=stroka.replace('[','')
|
stroka=stroka.replace('[','')
|
||||||
stroka=stroka.replace(']','')
|
stroka=stroka.replace(']','')
|
||||||
sps1=sps1+stroka.split(',')
|
sps1=sps1+stroka.split(',')
|
||||||
|
|
||||||
|
|
||||||
fp.close()
|
fp.close()
|
||||||
stroka
|
stroka
|
||||||
'9, 10, 11, 12'
|
'9, 10, 11, 12'
|
||||||
sps
|
sps
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||||
sps1
|
sps1
|
||||||
['1', ' 2', ' 3', ' 4', '5', ' 6', ' 7', ' 8', '9', ' 10', ' 11', ' 12']
|
['1', ' 2', ' 3', ' 4', '5', ' 6', ' 7', ' 8', '9', ' 10', ' 11', ' 12']
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
stroka=stroka.rstrip('\n')
|
stroka=stroka.rstrip('\n')
|
||||||
stroka=stroka.replace('[','')
|
stroka=stroka.replace('[','')
|
||||||
stroka=stroka.replace(']','')
|
stroka=stroka.replace(']','')
|
||||||
stroka=stroka.replace(' ','')
|
stroka=stroka.replace(' ','')
|
||||||
sps2=stroka.split(',')
|
sps2=stroka.split(',')
|
||||||
for i in sps2:
|
for i in sps2:
|
||||||
sps1 = sps1 + int(i)
|
sps1 = sps1 + int(i)
|
||||||
|
|
||||||
|
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<pyshell#85>", line 1, in <module>
|
File "<pyshell#85>", line 1, in <module>
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
ValueError: I/O operation on closed file.
|
ValueError: I/O operation on closed file.
|
||||||
fp=open('zapis3.txt')
|
fp=open('zapis3.txt')
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
stroka=stroka.rstrip('\n')
|
stroka=stroka.rstrip('\n')
|
||||||
stroka=stroka.replace('[','')
|
stroka=stroka.replace('[','')
|
||||||
stroka=stroka.replace(']','')
|
stroka=stroka.replace(']','')
|
||||||
stroka=stroka.replace(' ','')
|
stroka=stroka.replace(' ','')
|
||||||
sps2=stroka.split(',')
|
sps2=stroka.split(',')
|
||||||
for i in sps2:
|
for i in sps2:
|
||||||
sps1 = sps1 + int(i)
|
sps1 = sps1 + int(i)
|
||||||
|
|
||||||
|
|
||||||
Traceback (most recent call last):
|
Traceback (most recent call last):
|
||||||
File "<pyshell#88>", line 8, in <module>
|
File "<pyshell#88>", line 8, in <module>
|
||||||
sps1 = sps1 + int(i)
|
sps1 = sps1 + int(i)
|
||||||
TypeError: can only concatenate list (not "int") to list
|
TypeError: can only concatenate list (not "int") to list
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
stroka=stroka.rstrip('\n')
|
stroka=stroka.rstrip('\n')
|
||||||
stroka=stroka.replace('[','')
|
stroka=stroka.replace('[','')
|
||||||
stroka=stroka.replace(']','')
|
stroka=stroka.replace(']','')
|
||||||
stroka=stroka.replace(' ','')
|
stroka=stroka.replace(' ','')
|
||||||
sps2=stroka.split(',')
|
sps2=stroka.split(',')
|
||||||
for i in sps2:
|
for i in sps2:
|
||||||
sps1 = sps1 + [int(i)]
|
sps1 = sps1 + [int(i)]
|
||||||
|
|
||||||
|
|
||||||
sps1
|
sps1
|
||||||
['1', ' 2', ' 3', ' 4', '5', ' 6', ' 7', ' 8', '9', ' 10', ' 11', ' 12', 5, 6, 7, 8, 9, 10, 11, 12]
|
['1', ' 2', ' 3', ' 4', '5', ' 6', ' 7', ' 8', '9', ' 10', ' 11', ' 12', 5, 6, 7, 8, 9, 10, 11, 12]
|
||||||
sps1=[]
|
sps1=[]
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
stroka=stroka.rstrip('\n')
|
stroka=stroka.rstrip('\n')
|
||||||
stroka=stroka.replace('[','')
|
stroka=stroka.replace('[','')
|
||||||
stroka=stroka.replace(']','')
|
stroka=stroka.replace(']','')
|
||||||
stroka=stroka.replace(' ','')
|
stroka=stroka.replace(' ','')
|
||||||
sps2=stroka.split(',')
|
sps2=stroka.split(',')
|
||||||
for i in sps2:
|
for i in sps2:
|
||||||
sps1 = sps1 + [int(i)]
|
sps1 = sps1 + [int(i)]
|
||||||
|
|
||||||
|
|
||||||
fp.close()
|
fp.close()
|
||||||
sps1
|
sps1
|
||||||
[]
|
[]
|
||||||
fp=open('zapis3.txt')
|
fp=open('zapis3.txt')
|
||||||
for stroka in fp:
|
for stroka in fp:
|
||||||
stroka=stroka.rstrip('\n')
|
stroka=stroka.rstrip('\n')
|
||||||
stroka=stroka.replace('[','')
|
stroka=stroka.replace('[','')
|
||||||
stroka=stroka.replace(']','')
|
stroka=stroka.replace(']','')
|
||||||
stroka=stroka.replace(' ','')
|
stroka=stroka.replace(' ','')
|
||||||
sps2=stroka.split(',')
|
sps2=stroka.split(',')
|
||||||
for i in sps2:
|
for i in sps2:
|
||||||
sps1 = sps1 + [int(i)]
|
sps1 = sps1 + [int(i)]
|
||||||
|
|
||||||
|
|
||||||
sps1
|
sps1
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||||
fp.close()
|
fp.close()
|
||||||
sps1
|
sps1
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||||
sps2
|
sps2
|
||||||
['9', '10', '11', '12']
|
['9', '10', '11', '12']
|
||||||
sps
|
sps
|
||||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
|
||||||
fp=open('zapis3.txt')
|
fp=open('zapis3.txt')
|
||||||
stroka1=fp.read(12)
|
stroka1=fp.read(12)
|
||||||
stroka2=fp.read()
|
stroka2=fp.read()
|
||||||
fp.close()
|
fp.close()
|
||||||
stroka1
|
stroka1
|
||||||
'[1, 2, 3, 4]'
|
'[1, 2, 3, 4]'
|
||||||
stroka
|
stroka
|
||||||
'9,10,11,12'
|
'9,10,11,12'
|
||||||
fp=open('zapis3.txt')
|
fp=open('zapis3.txt')
|
||||||
stroka3=fp.readline()
|
stroka3=fp.readline()
|
||||||
stroka4=fp.readlines()
|
stroka4=fp.readlines()
|
||||||
fp.close()
|
fp.close()
|
||||||
stroka3
|
stroka3
|
||||||
'[1, 2, 3, 4]\n'
|
'[1, 2, 3, 4]\n'
|
||||||
stroka4
|
stroka4
|
||||||
['[5, 6, 7, 8]\n', '[9, 10, 11, 12]\n']
|
['[5, 6, 7, 8]\n', '[9, 10, 11, 12]\n']
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
mnoz1={'pen','book','pen','iPhone','table','book'}
|
mnoz1={'pen','book','pen','iPhone','table','book'}
|
||||||
fp=open('zapis6.mnz','wb')
|
fp=open('zapis6.mnz','wb')
|
||||||
pickle.dump(mnoz1,fp)
|
pickle.dump(mnoz1,fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
fp=open('zapis6.mnz','rb')
|
fp=open('zapis6.mnz','rb')
|
||||||
mnoz2=pickle.load(fp)
|
mnoz2=pickle.load(fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
mnoz1
|
mnoz1
|
||||||
{'iPhone', 'pen', 'table', 'book'}
|
{'iPhone', 'pen', 'table', 'book'}
|
||||||
mnoz2
|
mnoz2
|
||||||
{'iPhone', 'pen', 'table', 'book'}
|
{'iPhone', 'pen', 'table', 'book'}
|
||||||
mnoz1 is mnoz2
|
mnoz1 is mnoz2
|
||||||
False
|
False
|
||||||
fp=open('zapis7.2ob','wb')
|
fp=open('zapis7.2ob','wb')
|
||||||
pickle.dump(mnoz1,fp)
|
pickle.dump(mnoz1,fp)
|
||||||
pickle.dump(sps3,fp)
|
pickle.dump(sps3,fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
fp=open('zapis7.2ob','rb')
|
fp=open('zapis7.2ob','rb')
|
||||||
obj1=pickle.load(fp)
|
obj1=pickle.load(fp)
|
||||||
obj2=pickle.load(fp)
|
obj2=pickle.load(fp)
|
||||||
fp.close()
|
fp.close()
|
||||||
obj1
|
obj1
|
||||||
{'iPhone', 'pen', 'table', 'book'}
|
{'iPhone', 'pen', 'table', 'book'}
|
||||||
mnoz1
|
mnoz1
|
||||||
{'iPhone', 'pen', 'table', 'book'}
|
{'iPhone', 'pen', 'table', 'book'}
|
||||||
obj2
|
obj2
|
||||||
[['Иванов И.', 1], ['Петров П.', 2], ['Сидоров С.', 3]]
|
[['Иванов И.', 1], ['Петров П.', 2], ['Сидоров С.', 3]]
|
||||||
sps3
|
sps3
|
||||||
[['Иванов И.', 1], ['Петров П.', 2], ['Сидоров С.', 3]]
|
[['Иванов И.', 1], ['Петров П.', 2], ['Сидоров С.', 3]]
|
||||||
mnoz1 is obj1
|
mnoz1 is obj1
|
||||||
False
|
False
|
||||||
mnoz1 == obj1
|
mnoz1 == obj1
|
||||||
True
|
True
|
||||||
mnoz1 == mnoz2
|
mnoz1 == mnoz2
|
||||||
True
|
True
|
||||||
sps3 == obj2
|
sps3 == obj2
|
||||||
True
|
True
|
||||||
import sys
|
import sys
|
||||||
vr_out=sys.stdout
|
vr_out=sys.stdout
|
||||||
fc=open('Stroka.txt','w')
|
fc=open('Stroka.txt','w')
|
||||||
sys.stdout=fc
|
sys.stdout=fc
|
||||||
print('запись строки в файл')
|
print('запись строки в файл')
|
||||||
sys.stdout=vr_out
|
sys.stdout=vr_out
|
||||||
print('запись строки на экран')
|
print('запись строки на экран')
|
||||||
запись строки на экран
|
запись строки на экран
|
||||||
fc.close()
|
fc.close()
|
||||||
tmp_in = sys.stdin
|
tmp_in = sys.stdin
|
||||||
fd = open("Stroka.txt", "r")
|
fd = open("Stroka.txt", "r")
|
||||||
sys.stdin = fd
|
sys.stdin = fd
|
||||||
sys.stdin
|
sys.stdin
|
||||||
<_io.TextIOWrapper name='Stroka.txt' mode='r' encoding='cp1251'>
|
<_io.TextIOWrapper name='Stroka.txt' mode='r' encoding='cp1251'>
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
line = input ()
|
line = input ()
|
||||||
print(line)
|
print(line)
|
||||||
except EOFError:
|
except EOFError:
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
запись строки в файл
|
запись строки в файл
|
||||||
fd.close()
|
fd.close()
|
||||||
sys.stdin=tmp_in
|
sys.stdin=tmp_in
|
||||||
|
fp = open('file.py', 'w')
|
||||||
|
import random
|
||||||
|
kort = tuple(random.randint(6,56))
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<pyshell#163>", line 1, in <module>
|
||||||
|
kort = tuple(random.randint(6,56))
|
||||||
|
TypeError: 'int' object is not iterable
|
||||||
|
kort = tuple(random.randint(6,56) for _ in range(125))
|
||||||
|
kort
|
||||||
|
(38, 22, 36, 14, 32, 26, 6, 17, 40, 48, 10, 49, 26, 39, 32, 32, 6, 55, 50, 9, 51, 20, 47, 10, 54, 10, 27, 54, 47, 27, 21, 15, 22, 43, 42, 40, 55, 34, 46, 50, 51, 29, 43, 21, 10, 35, 26, 13, 47, 10, 54, 54, 20, 56, 18, 35, 11, 22, 43, 56, 47, 28, 8, 32, 37, 36, 54, 43, 47, 49, 49, 18, 41, 21, 40, 6, 38, 18, 39, 47, 18, 34, 23, 18, 41, 39, 33, 34, 37, 46, 50, 51, 10, 38, 9, 15, 34, 47, 7, 50, 7, 7, 6, 56, 53, 26, 15, 16, 15, 20, 23, 15, 37, 9, 27, 29, 20, 9, 53, 12, 6, 27, 35, 22, 24)
|
||||||
|
spis=['Корнеев', 'Немецкий', 'Гордиевских', 'Огарков', 'Васильев']
|
||||||
|
fp.close()
|
||||||
|
fp = open('file.py', 'wb')
|
||||||
|
fp.write(kort)
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<pyshell#169>", line 1, in <module>
|
||||||
|
fp.write(kort)
|
||||||
|
TypeError: a bytes-like object is required, not 'tuple'
|
||||||
|
pickle.dump(kort,fp)
|
||||||
|
pickle.dump(spis,fp)
|
||||||
|
fp.close()
|
||||||
|
fp = open('file.py')
|
||||||
|
obj1=pickle.load(fp)
|
||||||
|
Traceback (most recent call last):
|
||||||
|
File "<pyshell#174>", line 1, in <module>
|
||||||
|
obj1=pickle.load(fp)
|
||||||
|
TypeError: a bytes-like object is required, not 'str'
|
||||||
|
fp.close()
|
||||||
|
fp = open('file.py', 'rb')
|
||||||
|
obj1=pickle.load(fp)
|
||||||
|
obj2=pickle.load(fp)
|
||||||
|
if obj1 == kort:
|
||||||
|
print('Объекты совпадают')
|
||||||
|
else: print('Объекты не совпадают')
|
||||||
|
|
||||||
|
Объекты совпадают
|
||||||
|
if obj2 == spis:
|
||||||
|
print('Объекты совпадают')
|
||||||
|
else: print('Объекты не совпадают')
|
||||||
|
|
||||||
|
Объекты совпадают
|
||||||
|
|||||||
Загрузка…
Ссылка в новой задаче