Qt LineTextEdit [duplicate] - python

This question already has answers here:
Get plain text from QLineEdit
(2 answers)
Closed 7 years ago.
I am using PyQt and want to get string from text field. I found below solution but it returns a QString. I just want to avoid writing extra code to extract string further. Can anyone suggest a simple solution to retrieve text from text field.
text = self.your_plugin_dlg.ui.yourLineEdit.text()
Thanks.

The only way to get the text is converting the QString into a String
text = str(self.your_plugin_dlg.ui.yourLineEdit.text())

Related

Extract email from string variable using find() [duplicate]

This question already has answers here:
Extract email sub-strings from large document
(14 answers)
Closed 3 years ago.
Do you guys know how I'll be able to extract an email from a string using find()
info = "message email#gmail.com"
I want to be able to get the entire "email#gmail.com" and output only that to the screen.
You can do this by using regex:
import re
emails_list = re.findall('\S+#\S+', info)

Split string when ";" appears [duplicate]

This question already has answers here:
How can I split and parse a string in Python? [duplicate]
(3 answers)
Closed 5 years ago.
I need to split the string everytime ; shows up.
words = "LightOn;LightOff;LightStatus;LightClientHello;"
Output should be something like this:
LightOn
LightOff
LightStatus
LightClientHello
Simply, everytime it finds ; in a string, it has to split it.
Thank you for help
res = words.split(";")
Refer to this link for more information on split.

Converting text to format string [duplicate]

This question already has an answer here:
Int conversion not working [duplicate]
(1 answer)
Closed 6 years ago.
Is there some python way to convert a text (from a file for example) into a format string?
I mean for a text file:
this is a {format}
string.
Load it in python and have it become like the triple quotes format string:
var = """this is a {format}
string."""
I know how to just read the file and replace the curly braces, but I was wondering if there is already something that does this.
Thanks
Edit:
This is the code I've tried:
with open('file.txt', 'r') as rs:
lines = rs.readlines()
text = ','.join(lines)
print(text)
text.format(format='something_else')
print(text)
It just prints the text file.
I'm looking to know if there is a more pythonic way then me having to write a class that does this.
Thanks
variable.format() returns the formatted text and does not change the content of variable. Try
print(text.format(format="bla"))
or
text = text.format(format="bla")

What is a two part xml tag? [duplicate]

This question already has answers here:
What are XML namespaces for?
(10 answers)
Closed 6 years ago.
I'm trying to read in some xml and want to find the tag names.
For example if I read <dc:title>, I want to get "title".
Can someone tell me what the "dc" part is and what the "title" part is?
I'm using Python and when I iterate over the nodes and print out
node.tag, it returns "{http://purl.org/dc/elements/1.1/}title". I really don't know what the url stuff is or why it's returning with my node tag.
Ok, I found this and it seems to work.
item.tag.split("}")[1][0:]

Qt TextLineEdit: Retrieve string instead of QString [duplicate]

This question already has answers here:
Get plain text from QLineEdit
(2 answers)
Closed 7 years ago.
I am using Qt and want to get string from text field. I found below solution but it returns a QString. I just want to avoid writing extra code to extract string further. Can anyone suggest a simple solution to retrieve text from text field.
text = self.your_plugin_dlg.ui.yourLineEdit.text()
Well, you will have to add some code to get a string from a QLineEdit object. Simplest solution: use the str() method.
text = str( self.your_plugin_dlg.ui.yourLineEdit.text() )
for example http://forums.devshed.com/python-programming-11/qstring-normal-python-string-127725.html says:
text = str(self.your_plugin_dlg.ui.yourLineEdit.text())
But i agree, it's a pitty we cant use strings easily in Qt.
other hints with Qt and strings: http://pyqt.sourceforge.net/Docs/PyQt4/gotchas.html

Categories