Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
Dear Michael Torrie, Thanks for pointing that out to me re: it not being a syntax problem. The thing is there is a file called 'EcologicalPyramid.html'. I put it in a folder called 'Soup' as the text advised on page 28. For what its worth I also shifted the Windows Command Prompt to that folder (re: cd Soup)as instructed on page 30, and put a duplicate file of 'EcologicalPyramid.html' in the python 2.8 directory. I therefore am wondering where I ought put this html file where the Python console will recognize it ? Thank you for your attention, Yours Simon -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 04/01/2015 12:49, Simon Evans wrote: Dear Michael Torrie, Thanks for pointing that out to me re: it not being a syntax problem. The thing is there is a file called 'EcologicalPyramid.html'. I put it in a folder called 'Soup' as the text advised on page 28. For what its worth I also shifted the Windows Command Prompt to that folder (re: cd Soup)as instructed on page 30, and put a duplicate file of 'EcologicalPyramid.html' in the python 2.8 directory. I therefore am wondering where I ought put this html file where the Python console will recognize it ? Thank you for your attention, Yours Simon You could put your file on the moon provided you give the code a complete path to it, something like r'c:\the\path\to\your\file\called\EcologicalPyramid.html' -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 01/04/2015 07:49 AM, Simon Evans wrote: Dear Michael Torrie, Thanks for pointing that out to me re: it not being a syntax problem. The thing is there is a file called 'EcologicalPyramid.html'. I put it in a folder called 'Soup' as the text advised on page 28. For what its worth I also shifted the Windows Command Prompt to that folder (re: cd Soup)as instructed on page 30, and put a duplicate file of 'EcologicalPyramid.html' in the python 2.8 directory. Never put any user files in the python 2.8 directory, whatever that is. I therefore am wondering where I ought put this html file where the Python console will recognize it ? Since your code expects it in the current directory, either change the code, or make sure it IS in the current directory. The only obvious thing I can see is that you didn't spell the name the same. But since Windows makes the error of ignoring case, it ought to be close enough. However, you're typing the name, not pasting it, so maybe there's some other subtle difference, like you have more than one Soup directory. Try the following, from the cmd.exe prompt: myprompt cd Soup myprompt dir *.html (something shows here) myprompt python (something shows here) from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup= next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... and see what happens. Paste the whole thing into a message if it doesn't make sense to you. And of course don't forget to include the traceback. -- DaveA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
@Steven D'Aprano, I input the following to Python 2.7, which got the following:- from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup= next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'ecologicalpyramid.html' - I kept to your instructions to input the 'Enter' after the fourth line and then before the fifth line, ie between the indented block and the unindented one, which as above, doesn't give me a chance to actually input the fifth line. If I do it both ways, ie: pressing enter after the fourth and before the fifth or just pressing enter after the fourth and then after the fifth line of input, which again it won't actually let me input because before I do, I still get an error return. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/18/2014 09:19 AM, Simon Evans wrote: @Steven D'Aprano, I input the following to Python 2.7, which got the following:- from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup= next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... Traceback (most recent call last): File stdin, line 1, in module IOError: [Errno 2] No such file or directory: 'ecologicalpyramid.html' ^^^ This is the problem here. And it's not a syntax error. - I kept to your instructions to input the 'Enter' after the fourth line and then before the fifth line, ie between the indented block and the unindented one, which as above, doesn't give me a chance to actually input the fifth line. If I do it both ways, ie: pressing enter after the fourth and before the fifth or just pressing enter after the fourth and then after the fifth line of input, which again it won't actually let me input because before I do, I still get an error return. Did you read the actual error message? In this case it's not a syntax error. Do you understand what the error actually is and why it's happening? (IE did your read what the error was? Hint. It's not the same as your previous errors.) -- https://mail.python.org/mailman/listinfo/python-list
Python console rejects an object reference, having made an object with that reference as its name in previous line
Dear Python programmers, Having input the line of code in text: cd Soup to the Windows console, and having put the file 'EcologicalPyramid.html' into the Directory 'Soup', on the C drive, in accordance with instructions I input the following code to the Python console, as given on page 30 of 'Getting Started with Beautiful Soup': Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = BeautifulSoup(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ^ SyntaxError: invalid syntax producer_entries = soup.find(ul) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'soup' is not defined ^ so I cannot proceed with the next line withh would 've been : print(producer_entries.li.div.string) which would've given (according to the book) the output: --- plants Maybe that is getting a bit far ahead, but I can't quite see where I have gone wrong - 'soup' has been defined as an object made of file 'EcologicalPyramid.html I hope you can help me on this point. Yours Simon -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/14/14 11:15 AM, Simon Evans wrote: Dear Python programmers, Having input the line of code in text: cd Soup to the Windows console, and having put the file 'EcologicalPyramid.html' into the Directory 'Soup', on the C drive, in accordance with instructions I input the following code to the Python console, as given on page 30 of 'Getting Started with Beautiful Soup': Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = BeautifulSoup(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ^ SyntaxError: invalid syntax This SyntaxError is indicating that none of the code you have just typed was run. The reason it's a syntax error is because the interactive prompt is a bit simplistic about how to handle multiple statements. It wants a blank line after the with-clause. Because none of these lines were run, you never opened your HTML file, never parsed it, and never assigned to the name soup. producer_entries = soup.find(ul) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'soup' is not defined ^ so I cannot proceed with the next line withh would 've been : print(producer_entries.li.div.string) which would've given (according to the book) the output: --- plants Maybe that is getting a bit far ahead, but I can't quite see where I have gone wrong - 'soup' has been defined as an object made of file 'EcologicalPyramid.html I hope you can help me on this point. For complex code experiments, it's better to put the code in a file, and run the file. But if you do want to use the interactive interpreter, enter code carefully, and watch out for the error messages. -- Ned Batchelder, http://nedbatchelder.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
I had another attempt at inputting the code perhaps with the right indentation, I still get an error return, but not one that indicates that the code has not been read, as you suggested. re:- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = BeautifulSoup(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) File stdin, line 3 producer_entries = soup.find(ul) ^ SyntaxError: invalid syntax from bs4 import BeautifulSoup File stdin, line 1 from bs4 import BeautifulSoup If, as you suggest I left a free line after the with open( etc line, console returns an error, if I leave a free line after the soup = etc line which comes after, again I get an error return, my only point is that with the above input, console return does not seem to infer that soup has not been defined. You recommend that I put all the code into a file then run it - how do I do that ? I am new to Python, as you might have gathered. Thank you for your help. Yours Simon -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
Simon Evans writes: I had another attempt at inputting the code perhaps with the right indentation, I still get an error return, but not one that indicates that the code has not been read, as you suggested. re:- -- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = BeautifulSoup(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) File stdin, line 3 producer_entries = soup.find(ul) ^ SyntaxError: invalid syntax It should look like this, except I'm using built-in functions to get a single line from a file I happened to have around, and naming it beef instead of soup: Python 2.7.3 (default, Sep 26 2013, 16:38:10) [GCC 4.7.2] on linux2 Type help, copyright, credits or license for more information. with open('let.scm') as whatever: ...beef = next(whatever) ... beef '(define-syntax lets ;let-values, attempt to mod\n' Note the line with only ... on it? That's where I pressed enter to let the interpreter know that I had written all the code I wanted it to handle at that point. I was rewarded with (1) no error message, (2) a new prompt, where I entered, er, the four letters b e e f and then pressed enter, and the interpreter printed the first line of my file for me. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
It looks like the last line (producer_entries...) is not indented at the same extent as the previous line. Maybe this is causing the issue? On Sun, Dec 14, 2014 at 10:15 AM, Simon Evans musicalhack...@yahoo.co.uk wrote: Dear Python programmers, Having input the line of code in text: cd Soup to the Windows console, and having put the file 'EcologicalPyramid.html' into the Directory 'Soup', on the C drive, in accordance with instructions I input the following code to the Python console, as given on page 30 of 'Getting Started with Beautiful Soup': Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = BeautifulSoup(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ^ SyntaxError: invalid syntax producer_entries = soup.find(ul) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'soup' is not defined ^ so I cannot proceed with the next line withh would 've been : print(producer_entries.li.div.string) which would've given (according to the book) the output: --- plants Maybe that is getting a bit far ahead, but I can't quite see where I have gone wrong - 'soup' has been defined as an object made of file 'EcologicalPyramid.html I hope you can help me on this point. Yours Simon -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
Dear Jussi, and Billy I have changed the input in accordance with your advice, re: -- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... print(producer_entries.li.div.string) File stdin, line 5 print(producer_entries.li.div.string) ^ SyntaxError: invalid syntax print (producer_entries.li.div.string) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'producer_entries' is not defined from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... As no doubt you can see, the last line, indented as it is, does not provide the output that the book's text says it will return - ie the word 'plants' If I do not indent it, it returns an 'invalid syntax error' stating that 'producer_entries' is not defined. Though code in the previous line is meant to do just that - isn't it ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
Simon Evans wrote: Dear Jussi, and Billy I have changed the input in accordance with your advice, re: -- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... print(producer_entries.li.div.string) Simon, you are not leaving a blank space between the indented block and the unindented line. The interactive interpreter is quite simple, and you MUST leave a blank line after indented blocks. You need to press the ENTER key *twice* at the end of the block: with open(ecologicalpyramid.html,r) as ecological_pyramid: ENTER TAB soup = next(ecological_pyramid,lxml) ENTER TAB producer_entries = soup.find(ul) ENTER TAB print(producer_entries.li.div.string) ENTER ENTER print(producer_entries.li.div.string) ENTER Don't type the letters E N T E R, press the ENTER key. The same goes for TAB. Note carefully that after the indented block, there is a blank line. It should look like this: with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... print(producer_entries.li.div.string) If you don't leave the blank line, then *nothing* in that with block will run and consequently the last print line will fail. Until you fix that, we cannot even begin to help with any other issues you might be having. -- Steven -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 15/12/14 10:21, Simon Evans wrote: Dear Jussi, and Billy I have changed the input in accordance with your advice, re: -- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win here the user is using python 2.7.6 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... print(producer_entries.li.div.string) File stdin, line 5 print(producer_entries.li.div.string) ^ and here he uses a python 3.x print syntax which triggers the following error message SyntaxError: invalid syntax print (producer_entries.li.div.string) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'producer_entries' is not defined from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... As no doubt you can see, the last line, indented as it is, does not provide the output that the book's text says it will return - ie the word 'plants' If I do not indent it, it returns an 'invalid syntax error' stating that 'producer_entries' is not defined. Though code in the previous line is meant to do just that - isn't it ? -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On Mon, Dec 15, 2014 at 1:32 PM, Chris Roy-Smith chris_roysm...@internode.on.net wrote: and here he uses a python 3.x print syntax which triggers the following error message On the contrary; parens around a single argument will work just fine in Py2 (they're simply redundant parentheses, in the same way that you can write i = (1) and it's the same as i = 1). The syntax error comes from unindenting without ending the block, as several have pointed out already. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 15/12/2014 02:32, Chris Roy-Smith wrote: On 15/12/14 10:21, Simon Evans wrote: Dear Jussi, and Billy I have changed the input in accordance with your advice, re: -- Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win here the user is using python 2.7.6 32 Type help, copyright, credits or license for more information. from bs4 import BeautifulSoup with open(ecologicalpyramid.html,r) as ecological_pyramid: ... soup = next(ecological_pyramid,lxml) ... producer_entries = soup.find(ul) ... print(producer_entries.li.div.string) ... print(producer_entries.li.div.string) File stdin, line 5 print(producer_entries.li.div.string) ^ and here he uses a python 3.x print syntax which triggers the following error message SyntaxError: invalid syntax print (producer_entries.li.div.string) Traceback (most recent call last): File stdin, line 1, in module NameError: name 'producer_entries' is not defined I didn't realise that Python was so smart. It can indicate a syntax error at the final 't' in print before it gets to the opening bracket that is required for the print function in Python 3 (and Python 2 if you're using from __future__ import print_function)? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/14/2014 07:47 PM, Mark Lawrence wrote: I didn't realise that Python was so smart. It can indicate a syntax error at the final 't' in print before it gets to the opening bracket that is required for the print function in Python 3 (and Python 2 if you're using from __future__ import print_function)? Not really. Python2 just interprets print (value) as an expression to the print statement. It's like saying a=(value) and then print a. Redundant but works. However print(value) is interpreted as a function call, and if you haven't imported it from future, it will error out on Python2. Python 3, on the other hand treats spaces between a function and its opening paren to be optional whitespace. Thus to python3, print(value) and print (value) are the same. So if you always put a space between print and (value) you can achieve some measure of cross-version compatibility with print. However by including print_function from __future__ you are guaranteeing you won't forget to add the parens. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On Mon, Dec 15, 2014 at 4:27 PM, Michael Torrie torr...@gmail.com wrote: On 12/14/2014 07:47 PM, Mark Lawrence wrote: I didn't realise that Python was so smart. It can indicate a syntax error at the final 't' in print before it gets to the opening bracket that is required for the print function in Python 3 (and Python 2 if you're using from __future__ import print_function)? Not really. Python2 just interprets print (value) as an expression to the print statement. It's like saying a=(value) and then print a. Redundant but works. However print(value) is interpreted as a function call, and if you haven't imported it from future, it will error out on Python2. Did you actually test that? Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. print(hello) hello Since print is a keyword when not imported from future, there's no way for print(value) to be parsed as a function call. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On 12/14/2014 10:32 PM, Chris Angelico wrote: Did you actually test that? Python 2.7.8 (default, Jun 30 2014, 16:03:49) [MSC v.1500 32 bit (Intel)] on win32 Type copyright, credits or license() for more information. print(hello) hello Since print is a keyword when not imported from future, there's no way for print(value) to be parsed as a function call. Thought I had indirectly, since I've been using this print technique for the last few days. Good to know it works either way, though. Guess the future import is only to make not having parens and error. -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On Sun, Dec 14, 2014 at 11:38 PM, Michael Torrie torr...@gmail.com wrote: Guess the future import is only to make not having parens and error. Python 2.7.8+ (default, Nov 2 2014, 00:32:19) [MSC v.1500 32 bit (Intel)] on win32 Type help, copyright, credits or license for more information. print(1, 2) (1, 2) from __future__ import print_function print(1, 2) 1 2 Also, without the future import you can't use the 'sep', 'end', and 'file' keyword arguments. -- Zach -- https://mail.python.org/mailman/listinfo/python-list
Re: Python console rejects an object reference, having made an object with that reference as its name in previous line
On Mon, Dec 15, 2014 at 4:38 PM, Michael Torrie torr...@gmail.com wrote: Thought I had indirectly, since I've been using this print technique for the last few days. Good to know it works either way, though. Guess the future import is only to make not having parens and error. Yeah. I usually recommend using parens and a single native-string argument, for maximum portability. That'll work even on pre-2.6 where the future import isn't supported. ChrisA -- https://mail.python.org/mailman/listinfo/python-list