简体   繁体   中英

Scrapy Shell: How to execute multiple lines of code in shell?

You will see in the screenshot that pressing enter after pasting a multiline code doesnt run it but merely send each time a "...".

How can I run this multiline pasted code?

someone asked here , but did not get (the right) answer;

在此处输入图片说明

Did not work:

  • Backspace

  • Use the arrow key to move the cursor, then use the delete key

  • Escape

  • F2

Pressing enter twice when inside the Python interpreter executes a block of code, but you have an unmatched open parenthesis on the last line, so you haven't completed defining the block of code. Also, I'm not sure what dic is in the last line, because you haven't included its definition, so you may need to fix that as well.

Running

 a=[1,2]
 for x in a:
     print(x)

actually works (pressing 2 enters worked as expected). So I made a mistake in the code above. I aplogise, I should have checked that before.

I don't delete the question since the one on google can be confusing (the guy did not mentioned it was his mistake, so I though there was a trick to be found. The trick is to check the code).

you could use IPython link which simplifies the process, better yet you have access to every command line as if executed inside the shell. The other alternative is to encapsulate this inside a function

I know this answer is a bit late, but someone will need the information sometime: When you make a new line, ie title.quote.... you need to press the tab to create an indent, then it will work. Without indenting, you get the "expected an indent" error message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM