Похожие чаты

Hi guys i have very strange problem with .read() here is my

code:

myfile = open('D:/myfile.txt', 'r+')

myfile.write('my name is yousef')
print (myfile.read())
myfile.close()

if i run this code the result is nothing. then i have to assign a parameter for read() for example read(n)
and excute the code and then clear that parameter and then this codes returns that line. but this code repeats that string b times in the myfile.txt. for example if i write myfile.read(3) that string comes triple times in the file

what is wrong. where is my problem?

3 ответов

13 просмотров

Sorry friend. I'm not allowed to answer your question.

[anti-anti-spam trigger text] Imagine file operations like you have a carrige. You can read and write with the same carrige. After you wrote a few characters, your carrige will be at the end of the file, so when you call read() you won't read anything. If you want to read back what you just wrote, you have to position the carrige back at the beginning of the text to be able to read it. you can do this by calling myfile.seek(0,0) before reading. [anti-anti-spam trigger text]

Yousef- Автор вопроса

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта