[Tutor] String Problem
Dear All, I have used the urllib.request and download some of the information from a site. I am currently using Python 3.4. My program is as follows: import urllib.request response = urllib.request.urlopen(' http://www.hkex.com.hk/eng/ddp/Contract_Details.asp?PId=175') saveFile = open('HKEX.txt','w') saveFile.write(str(response.read())) saveFile.close() And the result is as follows: d align=right - /tdtd align=right0/tdtd align=right8.56/tdtd align=rightN/A/tdtd align=right1/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr56 class=tableHdrB1 align=centertd align=centreC Jul-15 - 23.00/tdtd align=right - /tdtd align=right - /tdtd align=right0.01/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right0.01/tdtd align=rightN/A/tdtd align=right467/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr57 class=tableHdrB2 align=centertd align=centreP Jul-15 - 23.00/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right9.56/tdtd align=rightN/A/tdtd align=right0/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr58 class=tableHdrB1 align=centertd align=centreC Jul-15 - 24.00/tdtd align=right - /tdtd align=right - /tdtd align=right0.01/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right0.01/tdtd align=rightN/A/tdtd align=right156/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr59 class=tableHdrB2 align=centertd align=centreP Jul-15 - 24.00/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right10.56/tdtd align=rightN/A/tdtd align=right0/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr60 class=tableHdrB1 align=centertd align=centreC Jul-15 - 25.00/tdtd align=right - /tdtd align=right - /tdtd align=right0.01/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right0.01/tdtd align=rightN/A/tdtd align=right6/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr61 class=tableHdrB2 align=centertd align=centreP Jul-15 - 25.00/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right11.56/tdtd align=rightN/A/tdtd align=right0/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr62 class=tableHdrB1 align=centertd align=centreC Aug-15 - 8.75/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right4.71/tdtd align=rightN/A/tdtd align=right0/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr63 class=tableHdrB2 align=centertd align=centreP Aug-15 - 8.75/tdtd align=right - /tdtd align=right0.03/tdtd align=right0.05/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right0/tdtd align=right0.01/tdtd align=rightN/A/tdtd align=right35/td/tr\r\n\t\t\t\t\t\t\t\ttr id=tr64 class=tableHdrB1 align=centertd align=centreC Aug-15 - 9.00/tdtd align=right - /tdtd align=right - /tdtd align=right - /tdtd align=right - /tdt Please let me know how to deal with this string. I hope I could put onto a table first. Eventually, I am hoping that I can able to put all this database. I need some guidance of which area of coding I should look into. Thank you Hank ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String Problem
On 06Jul2015 15:44, Crusier crus...@gmail.com wrote: Dear All, I have used the urllib.request and download some of the information from a site. I am currently using Python 3.4. My program is as follows: import urllib.request response = urllib.request.urlopen(' http://www.hkex.com.hk/eng/ddp/Contract_Details.asp?PId=175') saveFile = open('HKEX.txt','w') saveFile.write(str(response.read())) saveFile.close() And the result is as follows: d align=right - /tdtd align=right0/tdtd [...] Please let me know how to deal with this string. I hope I could put onto a table first. Eventually, I am hoping that I can able to put all this database. I need some guidance of which area of coding I should look into. Look into the BeautifulSoup library, which will parse HTML. That will let you locate the TABLE element and extract the content by walking the rows (TR) and cells (TD). Start here: http://www.crummy.com/software/BeautifulSoup/bs4/doc/ You can install bs4 using pip, or in other ways: http://www.crummy.com/software/BeautifulSoup/bs4/doc/#installing-beautiful-soup Cheers, Cameron Simpson c...@zip.com.au 30 years ago, I made some outrageous promises about AI. I didn't deliver. Neither did you. This is all your fault. - Marvin Minsky, IJCAI'91 (summary) ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] String Problem
On 06/07/2015 08:44, Crusier wrote: Dear All, I have used the urllib.request and download some of the information from a site. I am currently using Python 3.4. My program is as follows: import urllib.request response = urllib.request.urlopen(' http://www.hkex.com.hk/eng/ddp/Contract_Details.asp?PId=175') saveFile = open('HKEX.txt','w') saveFile.write(str(response.read())) saveFile.close() And the result is as follows: [snipped] Please let me know how to deal with this string. I hope I could put onto a table first. Eventually, I am hoping that I can able to put all this database. I need some guidance of which area of coding I should look into. Thank you Hank Start here https://docs.python.org/3/library/html.parser.html#example-html-parser-application -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] python help
I am looking for help on getting started with Python. This link says it all: http://raleigh.craigslist.org/cpg/5108772711.html Any help (and response to the CL post) would be truly appreciated. Thanks. -Roger ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
On 06/07/2015 15:24, Cary Developer wrote: Welcome. I am looking for help on getting started with Python. You've come to the right place, that's always a good start. This link says it all: http://raleigh.craigslist.org/cpg/5108772711.html Any help (and response to the CL post) would be truly appreciated. Thanks. -Roger For someone with programming experience try this http://www.diveintopython3.net/ Anybody suggesting to you starting with Django before they've learnt basic Python needs a really good psychiatrist, although I understand that they're rather more expensive in the USA than the UK :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Variable reference
Hello everyone I want to know about the variables dereference Code is in python 27 Let my variable be foo=hello python Print foo del foo What del command here actually doing , is it dereferencing or deleting the variable along with value it stored? Thank you Suresh Nagulavancha ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
On 06/07/15 15:24, Cary Developer wrote: I am looking for help on getting started with Python. This link says it all: http://raleigh.craigslist.org/cpg/5108772711.html It would be more helpful to post the content of the query, not all mail subscribers can access web pages at the time of reading the mail. Any help (and response to the CL post) would be truly appreciated. Thanks. Since you are experienced in web development and PHP/SQL you should go straight to the official Python tutorial. It will take you through the basics in a few hours - less than a full day for sure. You could then look at the Django tutorial if you want to go down the web route. (Other frameworks exist - lots of them - but Django is powerful, and very popular and has good support from its own community) Python 3.4 is the preferred version for newbies these days unless you know that your target framework/toolset only runs on v2 If you have more specific questions ask here... -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable reference
On 06/07/15 14:55, Suresh Nagulavancha wrote: Hello everyone I want to know about the variables dereference Code is in python 27 Let my variable be foo=hello python Print foo del foo What del command here actually doing Python variables are stored internally in a dictionary. del removes the name/value pair from the dictionary. If there are no more references to the object then the garbage collector will eventually remove it from memory. But you shouldn't need to worry too much about that. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable reference
I'd also add that the 'del' statement has near-zero utility. 'del' is a language blemish. It should not be used by beginners, because it asks them to try to manually manage the lifetime of their variable names. That's an unreasonable and ridiculous burden. Functions have local variables for a reason. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
Personally I would start with Python 2.7, and start with simple scripts. The standard library in Python is very wide, and having a good understanding of what is already there is very useful. As to GUI/ Web/ etc. - I think it depends on what you want to do. However, you will need the basics before then. You don't say what your background is, but if you've done some programming before then the basics should be pretty quick. Once you've done the basics, some more intermediate level stuff is useful. Personally, I find reading source code useful (there is a tonne on the PPI). There are some other resources listed here: https://news.ycombinator.com/item?id=5998750 HTH, M On 6 July 2015 at 15:24, Cary Developer carydevelo...@gmail.com wrote: I am looking for help on getting started with Python. This link says it all: http://raleigh.craigslist.org/cpg/5108772711.html Any help (and response to the CL post) would be truly appreciated. Thanks. -Roger ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] python help
On 06/07/2015 22:09, Matt Williams wrote: Personally I would start with Python 2.7, and start with simple scripts. I think it makes much more sense to learn Python 3 and if you need code to run on both 2 and 3 take the advice here https://docs.python.org/3/howto/pyporting.html By the way, please don't top post here, in can get irritating trying to follow long threads, thanks. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable reference
On 07/07/15 01:18, Danny Yoo wrote: I'd also add that the 'del' statement has near-zero utility. 'del' is a language blemish. It should not be used by beginners, because it asks them to try to manually manage the lifetime of their variable names. That's an unreasonable and ridiculous burden. Functions have local variables for a reason. I don't know that I'd go that far. There are valid uses for it in deleting things from dictionaries and the like. But I agree its not needed very often and can lead to users over-managing their data. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable reference
On Mon, Jul 06, 2015 at 05:18:16PM -0700, Danny Yoo wrote: I'd also add that the 'del' statement has near-zero utility. 'del' is a language blemish. It should not be used by beginners, because it asks them to try to manually manage the lifetime of their variable names. That's an unreasonable and ridiculous burden. Functions have local variables for a reason. Not all variables are local variables, and del exists to manage more than just name bindings. Deleting attributes and items from sequences are good uses for it, as is deleting global names which are not needed. You are right that del should not, generally, be used by beginners, and especially not for manually managing names. Fortunately, beginners are not usually inclined to write code like this: def spam(s): a = s.upper() b = s + s process(a, b) return do_something_else(a, b) del a, b, s as that would be both pointless and silly. Not only is the del line never reached by Python, but the local variables are automatically deleted when the function returns, so it is a waste of programmer time and effort to manually delete them. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Variable reference
On Mon, Jul 06, 2015 at 07:25:10PM +0530, Suresh Nagulavancha wrote: Hello everyone I want to know about the variables dereference First you need to know how variables reference. When you assign a value to a variable, we say that we bind the value to the variable's name: spam = 42 tells Python to bind 42 to the name spam, which associates the value 42 with the name spam. Every program has a global scope and local scopes for each function. We call those namespaces, and that is where Python tracks the association between names and values. In practice, Python often uses a dict for such namespaces, but not always. 99.9% of the time, you don't need to care about that, just let Python manage the variable names. Code is in python 27 There is no Python 27. I think you mean Python 2.7 (two point seven). Let my variable be foo=hello python Print foo That is a syntax error. As a programmer, you must be precise and accurate about what you say. foo and Foo and FOO are not the same thing, neither is print and Print and PRINT. del foo What del command here actually doing , is it dereferencing or deleting the variable along with value it stored? del unbinds the value from the name and removes the name from the current namespace. To put it another way, it deletes *the variable* but not the value. Here is another example: spam = Hello world! eggs = spam # these 2 lines can be written as 1: spam = eggs = Hello world! At this point, there are two references to the string Hello world!: the two names (variables), spam and eggs. We can print them, pass them to functions, etc. del spam This removes the binding from variable spam to the string. The string itself is not deleted, only the name binding (the variable spam). At this point, we can still write: print eggs which is okay, because the variable eggs still exists and is still bound to the string. But this line: print spam raises an exception, since the variable spam no longer exists. The string itself, Hello world!, is not deleted until the last reference to it is gone. Hope this is clear. -- Steve ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor