I know it's one of those programming languages thought of as an easy thing to learn (or so it seems like it). My problem is not with the difficulty of learning the language, rather the outdated guides and the problems with Python 3.2.

So I looked into a book called Diving into Python. It's free and I thought I would give it a go. It directed me to a website with a download to Python 3.2. I downloaded it and now I'm regretting of trying to learn Python. I don't like to give up easily, but I think this might be the only exception. I have no coding knowledge (well I did learn a bit of C++) so I can't really mess with anything. I'm trying to write this code

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)

but I get a syntax error at

buildconnectionstring(myParams)

When I try to run it, it says syntax error occurs at that part.

I'm not sure (since I'm no geek when it comes to Programming), but I'm thinking that maybe because the book I'm using is old, some thing might not be compatible with Python 3.2.

I'm sorry if it seems like I'm an incompetent fool who needs someone to hold his hands, but as dumb as this may sound, programming kinda scares me.
I'm hoping someone nice enough to show a rookie anything can help me out. I'm trying to look for an up-to-date tutorial that wont give me problems in Python 3.2. Or if it's highly unlikely, I would like if someone recommended me an older version of Python and an older tutorial.

I read this topic
http://www.daniweb.com/forums/thread20774.html

But I really don't know which version I should download.

Again I apologize if I did something wrong (probably be too stupid to search even more) but I'm so new to this.

I would like to add that I am a very dedicated learner (as hard as that is to believe), so I will proceed with learning Python even if it takes me 10 years. So please help a new person out.

Edited 6 Years Ago by Tenck: n/a

The book teaches Python 2.x. In Python 3.x, print is a function, so the last line would be
print(buildConnectionString(myParams))
In the future please include the actual error message, as it is almost impossible to debug when a program is larger, without knowing exactly what is wrong. Dive Into Python 3 is the only online book on Python 3.X that I know of.

Edited 6 Years Ago by woooee: n/a

Comments
Thanks

The book teaches Python 2.x. In Python 3.x, print is a function, so the last line would be
print(buildConnectionString(myParams))
In the future please include the actual error message, as it is almost impossible to debug when a program is larger, without knowing exactly what is wrong.

Thanks for the info. I'll get back to work now.

It was a bit confusing since I still don't know what a function is. The book takes you from the Hello World program to this.

Edit: I'm taking a guess here, but if I ever stumble upon a problem that is function related, would I need to add () to try and fix it?

Edited 6 Years Ago by Tenck: n/a

Another beginner tutorial that might make more sense is [URL=http://www.freenetpages.co.uk/hp/alan.gauld/tutcont.htm[/URL]Learning To Program[/URL]

Had to right click on your link to get it to work.

Anyways thanks for everything. You have made my day, and possibly my life .:Grin:.

Edit: I see you fixed the link.

Edited 6 Years Ago by Tenck: n/a

Byte of python has also a python 3.x.
The best advice is to stay with 2.7 for now,and later switch to python 3.
Most pepole stay with python 2.x,because off many famous 3.party moduls has to be rewritten.
There are many books tutorials that are really good for beginner and the are most in python 2.x.
Dont worry when you learn python 2.x you also learn python 3.x
That you will understad later,and python 3.x is the future(but not quite yet)

Edited 6 Years Ago by snippsat: n/a

Seems to me like it would be good to use both concurrently. I've all ready written a few scripts that can run with both 2.x and 3.x.

Python packages and modules are open source. If you ever want them for a new version you can always refactor the old version. In fact, I think their creators and the community at large would be appreciative of such an effort.

Doing so would be a great opportunity to prove that you are not only a programmer capable of implementing useful Python packages and modules but that you are also well versed in the relevant Python versions.

First of all Python 3.2 is a alpha release for testing by experts.
Use a stable production release like 3.1.2 or even better Python 2.7

First of all Python 3.2 is a alpha release for testing by experts.
Use a stable production release like 3.1.2 or even better Python 2.7

Thanks for the suggestion. I'll download it right away.

>>> python helloworld.py
SyntaxError: invalid syntax

Why is it that I can't run my program like this? It says that the invalid syntax is helloworld

You can do that in IDLE(python shell),you most du that in cmd(windows) or terminal(linux)
If you shall run code in IDLE you have to import it.

Or when in IDLE file->new window(write code) or open code(..py)
Save and run it with F5.
Or as most off do use and editor when running code pyscripter is good for windows or SPE(for linux)

Example.

#save as hello.py,just save it in python27 folder
def foo(your_name=None):
    return 'Hello world from %s' % your_name

my_name = 'Mical'
print foo(my_name)

Run it from cmd
C:\python27>python hello.py
Hello world from Mical

You can import hello.py py in IDLE and use it as an module.

>>> import hello
Hello world from Mical
>>> dir(hello)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'foo', 'my_name']

>>> hello.foo
<function foo at 0x02A950F0>  #Just show an memory adress
>>> hello.foo()               #Use it with no argument
'Hello world from None'
>>> my_name = 'Tom'
>>> hello.foo(my_name)        #Give it and argument
'Hello world from Tom'
>>>

Edited 6 Years Ago by snippsat: n/a

This question has already been answered. Start a new discussion instead.