I'm using regular expressions to get a URL from a string
Here is my code:
import re
class ProcessWebsite(object):
def __init__(self, *args, **kwargs):
print "Test"
def set_orden(self, command):
self.command = command
return self.getURL()
def getURL(self):
regex = re.compile("([0-9A-Za-z]{2,}\.[0-9A-Za-z]{2,3}\.[0-9A-Za-z]{2,3}|[0-9A-Za-z]{2,}\.[0-9A-Za-z]{2,3})$")
return regex.findall(str(self.command))
I call the method "getURL" from here:
# -*- coding: utf-8 -*-
import Tkinter as tk
import tkFont
from Tkinter import StringVar
from Tkinter import Label
from processor.processwebsite import ProcessWebsite
def changeText(newText):
var.set(newText)
def on_return_release(event):
pr = ProcessWebsite()
changeText(pr.set_orden(text.get("1.0", "end")))
app = tk.Tk()
var = StringVar()
label = Label(app, textvariable=var)
font = tkFont.Font(family='Helvetica', size=36, weight='bold')
label.pack()
text = tk.Text(app, width=50, font=font)
text.config(width=35, height=2)
text.pack()
text.bind("<KeyRelease-Return>", on_return_release)
app.mainloop()
This returns me "None", but if I change this line of the method "getURL" then it works
def getURL(self):
regex = re.compile("([0-9A-Za-z]{2,}\.[0-9A-Za-z]{2,3}\.[0-9A-Za-z]{2,3}|[0-9A-Za-z]{2,}\.[0-9A-Za-z]{2,3})$")
return regex.findall("Test with google.com")
Does anyone know what could be happening?
Thanks
text.get("1.0", "end")is not returning what you expect it to. Can you confirm that this produces the desired output?