Re: [Tutor] (no subject)
Thank you for the responses. Some filenames I use are in Unicode in this script and there is no display or typing problem in Windows (Vista, 7 and 10). Filenames and text in word processing and text files are ALL displayed properly WITHOUT any errors by the Windows system. When I use a standard font in the local language there is no problem at all but I need to retype ALL display text in all the Python programs which is a tedious task. Having read all answers is there no way this can be done without modifing code on my computer? Thepurpose is to deliver a WIndows software for ALL Windows users. I am reading in a list of file names with the following code. def get_filelist(self): "" app = QtGui.QApplication(sys.argv) a = QtGui.QFileDialog.getOpenFileNames() filelist = [] if a: for name in a: a = unicode(name) filelist.append(a) return filelist mainprg.filelist = mainprg.get_filelist() filelist = mainprg.filelist for name in filelist: print name < THIS IS WHERE THE PROBLEM IS Thanks for feed back. On Mon, Jul 25, 2016 at 3:58 PM, Steven D'Aprano wrote: > On Fri, Jul 22, 2016 at 01:08:02PM +0530, DiliupG wrote: > > I am using Python 2.7.12 on Windows 10 > > Two errors: > > - first error is that Unicode strings in Python 2 need to be written as > unicode objects, with a "u" prefix in the delimiter: > > # ASCII byte string: > "Hello World" > > # Unicode string: > > u"මේක ත" > > ASCII strings "..." cannot give you the right results except by > accident. You must use unicode strings u"..." > > - Second possible problem: using Windows, which may not support the > characters you are trying to use. I don't know -- try it and see. If it > still doesn't work, then blame Windows. I know that Linux and Mac OS X > both use UTF-8 for filenames, and so support all of Unicode. But > Windows, I'm not sure. It might be localised to only use Latin-1 > (Western European) or similar. > > > -- > Steve > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- Kalasuri Diliup Gabadamudalige http://www.diliupg.com http://soft.diliupg.com/ ** This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. ** ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] (no subject)
Thanks for the support. Mu main problem was in the editor I was using which I did not mention. I was using Wing IDE Pro instead of the Python IDE. BY the answer given by erik sun I applied the same idea to th Wing IDE i/o to utf-8 and everything worked. Thanks for your support and pardon me for not supplying all the info. On Tue, Jul 26, 2016 at 10:11 AM, DiliupG wrote: > Thank you for the responses. > Some filenames I use are in Unicode in this script and there is no display > or typing problem in Windows (Vista, 7 and 10). Filenames and text in word > processing and text files are ALL displayed properly WITHOUT any errors by > the Windows system. > > When I use a standard font in the local language there is no problem at > all but I need to retype ALL display text in all the Python programs which > is a tedious task. > > Having read all answers is there no way this can be done without modifing > code on my computer? Thepurpose is to deliver a WIndows software for ALL > Windows users. > > I am reading in a list of file names with the following code. > > def get_filelist(self): > "" > app = QtGui.QApplication(sys.argv) > a = QtGui.QFileDialog.getOpenFileNames() > > filelist = [] > if a: > for name in a: > a = unicode(name) > > filelist.append(a) > > return filelist > > mainprg.filelist = mainprg.get_filelist() > > filelist = mainprg.filelist > > for name in filelist: > print name < THIS IS WHERE THE PROBLEM IS > > Thanks for feed back. > > On Mon, Jul 25, 2016 at 3:58 PM, Steven D'Aprano > wrote: > >> On Fri, Jul 22, 2016 at 01:08:02PM +0530, DiliupG wrote: >> > I am using Python 2.7.12 on Windows 10 >> >> Two errors: >> >> - first error is that Unicode strings in Python 2 need to be written as >> unicode objects, with a "u" prefix in the delimiter: >> >> # ASCII byte string: >> "Hello World" >> >> # Unicode string: >> >> u"මේක ත" >> >> ASCII strings "..." cannot give you the right results except by >> accident. You must use unicode strings u"..." >> >> - Second possible problem: using Windows, which may not support the >> characters you are trying to use. I don't know -- try it and see. If it >> still doesn't work, then blame Windows. I know that Linux and Mac OS X >> both use UTF-8 for filenames, and so support all of Unicode. But >> Windows, I'm not sure. It might be localised to only use Latin-1 >> (Western European) or similar. >> >> >> -- >> Steve >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> > > > > -- > Kalasuri Diliup Gabadamudalige > > http://www.diliupg.com > http://soft.diliupg.com/ > > > ** > This e-mail is confidential. It may also be legally privileged. If you are > not the intended recipient or have received it in error, please delete it > and all copies from your system and notify the sender immediately by return > e-mail. Any unauthorized reading, reproducing, printing or further > dissemination of this e-mail or its contents is strictly prohibited and may > be unlawful. Internet communications cannot be guaranteed to be timely, > secure, error or virus-free. The sender does not accept liability for any > errors or omissions. > > ** > > -- Kalasuri Diliup Gabadamudalige http://www.diliupg.com http://soft.diliupg.com/ ** This e-mail is confidential. It may also be legally privileged. If you are not the intended recipient or have received it in error, please delete it and all copies from your system and notify the sender immediately by return e-mail. Any unauthorized reading, reproducing, printing or further dissemination of this e-mail or its contents is strictly prohibited and may be unlawful. Internet communications cannot be guaranteed to be timely, secure, error or virus-free. The sender does not accept liability for any errors or omissions. ** ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Beautiful Soup
I am using Python 3 on Windows 7. However, I am unable to download some of the data listed in the web site as follows: 453.IMC 98.28M 18.44M 4.325.33 1499.Optiver 70.91M13.29M 3.125.34 7387.花旗环球 52.72M9.84M2.325.36 When I use Google Chrome and use 'View Page Source', the data does not show up at all. However, when I use 'Inspect', I can able to read the data. 1453.IMC 98.28M 18.44M 4.32 5.33 1499.Optiver 70.91M 13.29M 3.12 5.34 Please kindly explain to me if the data is hide in CSS Style sheet or is there any way to retrieve the data listed. Thank you Regards, Crusier from bs4 import BeautifulSoup import urllib import requests stock_code = ('00939', '0001') def web_scraper(stock_code): broker_url = 'http://data.tsci.com.cn/stock/' end_url = '/STK_Broker.htm' for code in stock_code: new_url = broker_url + code + end_url response = requests.get(new_url) html = response.content soup = BeautifulSoup(html, "html.parser") Buylist = soup.find_all('div', id ="BuyingSeats") Selllist = soup.find_all('div', id ="SellSeats") print(Buylist) print(Selllist) web_scraper(stock_code) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] OOP help needed
OOP has always driven me crazy. I read the material and follow the examples until I feel I understand them, but when I try to implement it I end up with an error filled mess. So I decided to give it another try. When I got to the chapter on tkinter I decided to solve all the exercises using OOP even though the book solutions did not use OOP. The first one went fine: #exer1.py import tkinter class Goodbye: def __init__(self): self.frame = tkinter.Frame(window) self.frame.pack() self.goodbye_button = tkinter.Button(self.frame, text='Goodbye', #command=quit) command=lambda: quit() ) self.goodbye_button.pack() def quit(): self.window.destroy() if __name__=='__main__': window = tkinter.Tk() myapp = Goodbye() window.mainloop() The second one was more trouble but I finally got it to work. # exer2.py import tkinter class Count: def __init__(self): ''' Increment a button labeled 0, by 1 with each click ''' self.frame = tkinter.Frame(window) self.frame.pack() self.label = tkinter.StringVar() self.label.set('0') self.count_btn = tkinter.Button(self.frame, textvariable=self.label, command=lambda: self.increment(self.label )) self.count_btn.pack() def increment(self, label): count = int(self.label.get()) self.label.set(str(count + 1)) if __name__ == '__main__': window = tkinter.Tk() myapp = Count() window.mainloop() I am having trouble understanding the difference between the two lines that contain lambda: command= .In exer1.py I can do command=lambda: quit(). In exer2.py if I do command=lambda: increment(self.label) I get this error: Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.4/tkinter/__init__.py", line 1536, in __call__ return self.func(*args) File "exer2.py", line 14, in command=lambda: increment(self.label )) NameError: name 'increment' is not defined Why do I get this error? The situations look the same to me but they must be different somehow and I just don't see the difference. Thanks, Jim ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] OOP help needed
Jim Byrnes writes: > So I decided to give it another try. When I got to the chapter on > tkinter I decided to solve all the exercises using OOP even though the > book solutions did not use OOP. Hmm, that sounds ill advised. OOP is one tool among many; trying to apply it where it's a poor fit will result in bad design and probably avoidable errors. When learning to use a hacksaw, trying to solve everything using that tool merely to learn it, would be a poor choice. > # exer2.py > > import tkinter > > class Count: > > def __init__(self): > ''' Increment a button labeled 0, by 1 with each click ''' > […] > self.count_btn = tkinter.Button(self.frame, textvariable=self.label, > command=lambda: self.increment(self.label )) Here you address the ‘self.increment’ name, which should work. > def increment(self, label): > count = int(self.label.get()) > self.label.set(str(count + 1)) This is the method that an instance will address via ‘self.increment’. > In exer2.py if I do command=lambda: increment(self.label) The lambda expression creates a function, and that function then behaves like any other function. Within that function, the name ‘increment’ is not defined; within the scope where the function was defined, the name ‘increment’ is also not defined. Within the global scope the name ‘increment’ is not defined. So yes, you'll get NameError from that code. > Why do I get this error? The situations look the same to me The difference is that when you invoke ‘self.instance’, the lookup of ‘self’ succeeds because it's defined within the function (you defined it in the parameters of ‘__init__’, so ‘__init__’ knows that name when it is running). You never defined the name ‘increment’ within the function, nor within the global scope. And you shouldn't because there's no need: you access the instance's own method by accessing the instance first: you ask for “the ‘instance’ attribute from the ‘self’ object”: ‘self.instance’. -- \ “I believe our future depends powerfully on how well we | `\ understand this cosmos, in which we float like a mote of dust | _o__) in the morning sky.” —Carl Sagan, _Cosmos_, 1980 | Ben Finney ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor