M
M
markanez2021-12-18 15:42:18
Python
markanez, 2021-12-18 15:42:18

TypeError: 'NoneType' object cannot be interpreted as an integer how to fix?

There is such a code

import os
import time

krik = os.startfile(r'звуки\крик.mp3')
time.sleep(5)
os.close(krik)


after compiling this error pops up
TypeError: 'NoneType' object cannot be interpreted as an integer

How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alan Gibizov, 2021-12-18
@phaggi

I think it returns None, so the variable krik contains None, so when this None is input to os.close(), you get an error. I would recommend that you first study the python object model so that you understand exactly what you are doing. Secondly, study the documentation regarding the libraries and methods used. In general, this is easy to do by issuing the and command. In particular, the os.close() method requires a file descriptor as input, i.e. number, int. So, you need to get the descriptor and feed it to the method. Ps Well, by the way, as the respected Vindicar pointed out, os.close does not close the running process. It is necessary to dig in the direction of the kill command, I think so. os.startfile(r'звуки\крик.mp3')
help(os.close)

V
Vindicar, 2021-12-18
@Vindicar

startfile() returns as soon as the associated application is launched. There is no option to wait for the application to close, and no way to retrieve the application's exit status.

You have no control over the application once you have started it with startfile(). The function returns None and only None.
os.close() is for closing file descriptors , why are you even trying to use it here?
In short, you are doing some kind of heresy, and the mistake here is not that None cannot be converted to an integer.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question