Skip to content
Advertisement

Tag: file

Python Get File Length Of Keyboard Buffer

I am coding a text-based game, and I need to read key presses. For various reasons, I’m doing this by reading the keyboard buffer. This is my current code for that: The problem is, that the program will wait until it has read 45 bytes. I do not want this, because the program should do other stuff (like recharging mana).

Can you write to the middle of a file in python?

I would like to write to the middle of a line in a file. for exemple i have a file: Text.txt: Is is it possible to precise an index where: file.write() has to start writing? I have started with this: Answer I think what you can do is to substitute already existing characters with the same amount of other characters

How do I run another file in python?

So I know how to write in a file or read a file but how do I RUN another file? for example in a file I have this: a = 1 print(a) How do I run this using another file? Answer using subprocess standard lib or using os standard lib or extract python code from the file and run it

Reading file and counting repeated elements automation

I need help to solve a problem quickly. At work I have a file that has 18 characters per line (there are more than 600 lines). I need to read each line and on each line read 6 characters at a time. And in these 6 characters I want to count how many times it is repeated in this file.

How do I find duplicates and print the line in a text file?

I am trying to go through a .txt and find duplicate names in the file, but also print out the line that duplicate is located on. This is what I have so far for finding the duplicate names: But I am unsure of how to show what line they are located on. I read about finding a keyword in file

How to create a file object from a zipfile?

I want to create a file object from a file that is inside a zip. I don’t wanna extract that file. Actually I wanna use seek method on a file that is inside a zip. My code: But I can’t use seek method on it. I wanna make it like this but without extracting the file: Answer The documentation says

Advertisement