Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Learning Python

Name: Anonymous 2011-06-24 4:47

I'm currently trying to learn Python. My background with programming is that I took 3 courses in Java during college and wrote a medical scheduling program by myself during high school using VB6 and Access.  I would love to be able to contribute to open source projects, hoping to build a reputation in those communities.

Anyhow, I'm using this text: http://openbookproject.net//thinkCSpy/ch04.html  Is this a good book to use to learn Python given my background?  Also, what's the best IDE for python.

otherwise, python general thread.

Name: Anonymous 2011-06-24 10:09

Hey guys, can you please help a beginner in Python programming?

Here's the bitch: I have this block with try/except and I trying to make one if in the except check if there's in a variable some string, and with this print the message of error. Well, here part of the code:


t = 0
while 1:
    try:
        v = int(raw_input(": "))
        t+=v
        print t
       
    except:
        if str in v:
            print "string, use just number mtf"
        elif ',' in v:
            print "bla bla bla bla"


What I do not understand is because the conditional does not work. Instead, the error message just appears with:

if str in v:
TypeError: argument of type 'int' is not iterable

Teach me how could I make this if at the except check if there's a string and say that must be type just numbers.

Thanks.

Sorry for the english, I'm still leaning.

Name: Anonymous 2011-06-24 10:29

>>5

In that if statement the value of v is still integer so you can'y iterate it.

And... why do you even want to check if str is in v? str is string object in Python, right?


t = 0
while 1:
    try:
        s = raw_input(": ")
        v = int(v)
        t+=v
        print t
       
    except:
        print "harp darp", s, v
        #wtf
        #if str in v:
        #    print "string, use just number mtf"
        if ',' in v:
            print "bla bla bla bla"

Name: 6 2011-06-24 10:30

>>6
and obviously you want to change the if clauese to
if ',' in s:

Name: 6,7 2011-06-24 10:31

ok, nevermind, i can't code shit
v = int(s)

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List