getting started

H

Harvey Greenberg

elementary ques...I set
s.name = ["a","b"]
s.value = [3,5]

I get error that s is not defined. How do I define s and proceed to
give its attributes?
 
M

Miki Tebeka

s.name = ["a","b"]
s.value = [3,5]

I get error that s is not defined. How do I define s and proceed to
give its attributes?
Either you create a class and use __init__:
class S:
def __init__(self, name, value):
self.name = name
self.value = value

or create a generic object and stick attributes to it:
class Object(object):
pass

s = Object()
s.name = ["a","b"]
s.value = [3,5]

I highly recommend going over the tutorial - http://docs.python.org/tutorial/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,146
Messages
2,570,832
Members
47,374
Latest member
EmeliaBryc

Latest Threads

Top