Skip to content
Advertisement

Multiple problems generating a text file

I am making my first interface with Pyqt, using “designer” and Python to configure it.The function def clickconector return the form fill and def radio_value return if the job is pending or finished (“pendiente” or “terminado”). clickconector and radio_value* functions are written correctly, but I have problems with def text_file function.

Problem #1 : For some reason the generated file has the same inside as the title, which would come if the radio_value function, being that it specifies in the algorithm that It was the other function clickconector.

Problem #2 : The title is not being written as I want. I get this: ('Terminado', 'MT16'). txt, (It is writing .txt in the title). When it should be: Terminado MT16. Also, the file type does not appear to me as .txt, I have to select to open it like this with the mouse

JavaScript

Advertisement

Answer

The return type of radio_value is a tuple. You are converting a tuple to a string, so it is going to be printed in the form of a tuple, i.e., "(value_a, value_b, value_c)" and not value_a value_b value_c. You can use join to join each value of the tuple with a space, like so:

JavaScript

You also wrote ". txt" and not ".txt" in f = open(str(Bloc_title)+'. txt', 'w'). That is why . txt was in the file name. With all of this in mind, your text_file function should look something like this:

JavaScript

Note the use of with/open instead of just open. Using with/open is highly recommended for readability and overall ease-of-use.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement