Sign in to follow this  

python question

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am just starting my first python levels and I have to type exactly what it says to in the book...(here's the link)http://www.diveintopython.org/getting_to_know_python/index.html So here's what it says....>>> def buildConnectionString(params): ..."""Build a connection string from a dictionary of parameters. ... ... Returns string.""" IndentionError: expected an indented block It also points at the last ".... What am i doing wrong I am typing perfectly what it says thanks for any help.

Share this post


Link to post
Share on other sites
Are you actually typing those dots?

It should look like this:

def buildConnectionString(params):
"""Build a connection string from a dictionary of parameters.

Returns string."""

return ";".join(["%s=%s" % (k, v) for k, v in params.items()])

if __name__ == "__main__":
myParams = {"server":"mpilgrim", "database":"master", "uid":"sa", "pwd":"secret"}
print buildConnectionString(myParams)


You must indent where they have done so in the example.

Which development enviromnent are you using? If you're using IDLE you'll want to select File>New Window and type up the program in there rather than typing it into the interactive shell.

Share this post


Link to post
Share on other sites
Yeah since whitespace matters in Python it will give you that error if you code blocks are not aligned up properly when you type your code in so using a good IDE can help you out with that.

Share this post


Link to post
Share on other sites
I am not putting the dots in there while using Python interactive shell...it just puts them there when i hit enter to go to that line...I have also tried to do i in Wing IDE and still did not work in the python shell or a file>new....programing is confusing stuff...

Share this post


Link to post
Share on other sites
Quote:
Original post by jcheath33
I am not putting the dots in there while using Python interactive shell...it just puts them there when i hit enter to go to that line


Yes, that's to show that it's waiting for you to complete the command. You still need to *indent* the function body, though; hence "expected an indented block". Hit tab at the beginning of each line after the first.

Share this post


Link to post
Share on other sites

This topic is 3742 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this