Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.8k views
in Technique[技术] by (71.8m points)

google app engine - Using Twill from Python to open a link: " 'module' object has no attribute 'Popen' " What is it?

I have downloaded and installed Python 2.5.4 on my computer (my OS is Windows XP), downloaded “Goggle App Engine Software Development Kit” and created my first application in Python, which was a directory named helloworld that contained a small python file with the same name (helloworld.py). Here are the contents of that small file:


print 'Content-Type: text/plain'
print ''
print 'Hello, world!' 

Whenever I ran this application locally on my computer with “Goggle App Engine Software Development Kit”, my browser (FireFox) always showed me a white window with Hello, world! written in it.

Then I downloaded Twill and unpacked it into helloworld directory. Having installed Twill properly, I was able to execute some small commands from Twill shell. For example, I could turn to a web page by some link:

alt text

Then I wanted to perform the same operation directly from Python (i.e. by means of using Twill from Python.) Here is what the Twill documentation page says about it:


twill's Python API

Using TwillBrowser Making extensions

twill is essentially a thin shell around the mechanize package. All twill commands are implemented in the commands.py file, and pyparsing does the work of parsing the input and converting it into Python commands (see parse.py). Interactive shell work and readline support is implemented via the cmd module (from the standard Python library).

Using twill from Python

There are two fairly simple ways to use twill from Python. (They are compatible with each other, so you don't need to choose between them; just use whichever is appropriate.)

The first is to simply import all of the commands in commands.py and use them directly from Python. For example,

from twill.commands import *
go("http://www.python.org/")
showforms()

This has the advantage of being very simple, as well as being tied directly to the documented set of commands in the commands reference.


So I decided to use this way. I deleted the previous contents of helloworld.py and gave it the new contents:


from twill.commands import *
go("http://www.python.org/")
showforms()

But when I tried to run that file on my computer with “Goggle App Engine Software Development Kit”, my browser, instead of depicting the contents of www.python.org web site, gives me an error message: 'module' object has no attribute 'Popen' :

alt text

Please, take a look at the whole page here.

Here are the last three lines of that page:


: 'module' object has no attribute 'Popen'

  args = ("'module' object has no attribute 'Popen'",)

  message = "'module' object has no attribute 'Popen'" 

Can anybody, please, explain to me what this Popen attribute is all about and what I am doing wrong here?

Thank you all in advance.


Update 1

(this update is my response to the second answer provided below by leoluk)

Hello, leoluk!!!

I tried doing it this way:

config use_tidy 0
from twill.commands import *
go("http://www.python.org/")

but it didn't work. I received this error message:

<type 'exceptions.SyntaxError'>: invalid syntax (helloworld.py, line 1)
      args = ('invalid syntax', (r'E:helloworldhelloworld.py', 1, 15, 'config use_tidy 0
'))
      filename = r'E:helloworldhelloworld.py'
      lineno = 1
      message = ''
      msg = 'invalid syntax'
      offset = 15
      print_file_and_line = None
      text = 'config use_tidy 0
'

(You can see the whole page HERE)

Do You have any idea what it means and what went wrong?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...