472,358 Members | 1,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

referencing an object attribute sort of indirectly from within list

Is there anything that would get in the way of me being able to reference an object attribute, from within a list.

I have:
# one class here

class BackupSet:
fileGroupList = []

# another class here

class FileGroup:
sourceDir = ''
destinDir = ''
def __init__(self):
self.sourceDir = 'c:\folder'
self.destinDir = 'd:\folder'
fileGroup = FileGroup()

backupSet = BackUpSet()

backupSet.fileGroupList.append(fileGroup)

# when i try to reference an attribute here, I just get 'none'

print bkset.fileGroupList[0].sourceDir or
print "%s" % bkset.fileGroupList[0].sourceDir


thanks
Steve
Jul 18 '05 #1
4 1775
On Sun, 30 Nov 2003 01:32:05 GMT, "python newbie" <me*******@hotmail.com> wrote:
This is a multi-part message in MIME format. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- So far, so annoying
[...]
Is there anything that would get in the way of me being able to =
reference an object attribute, from within a list.

I have: Where do you have it? This is not an actual verbatim example of something you tried.
# one class here

class BackupSet: ^--- this is different from your constructor call below at [1] fileGroupList =3D []
=20
# another class here

class FileGroup:
sourceDir =3D ''
destinDir =3D ''
def __init__(self):
self.sourceDir =3D 'c:\folder'
self.destinDir =3D 'd:\folder' =20
fileGroup =3D FileGroup()

backupSet =3D BackUpSet() ^----- [1] So I know you didn't do this.
backupSet.fileGroupList.append(fileGroup)

# when i try to reference an attribute here, I just get 'none' Maybe you have some old code that reads
self.sourceDir = 'none'
in class FileGroup. Who can tell?

print bkset.fileGroupList[0].sourceDir or ^^^^^-- what the heck is that?
print "%s" % bkset.fileGroupList[0].sourceDir
=20

thanks
Steve
------=_NextPart_000_0025_01C3B69E.E2B92BA0
Content-Type: text/html;

<grr>
Two things:
1. Don't post HTML
2. Do post verbatim copy/pasted examples from the window where you
actually tried what you are talking about. It's not that much more typing.
</grr>
I'm hungry. I don't know why I'm putting off food even a minute to do this ;-/

Regards,
Bengt Richter
Jul 18 '05 #2
Hi.
I've made some small changes to your code. It appears to be doing what
you're looking for now.
HTH,
Sean
class BackupSet:
fileGroupList = []

class FileGroup:
sourceDir = ''
destinDir = ''
def __init__(self):
self.sourceDir = r'c:\folder' # use a raw string or escape the
'\'
self.destinDir = r'd:\folder' # like so, 'c:\\folder'

fileGroup = FileGroup()

# backupSet = BackUpSet() <-- NameError!
backupSet = BackupSet()

backupSet.fileGroupList.append(fileGroup)

# print bkset.fileGroupList[0].sourceDir <-- where did 'bkset' come from?
# using backupSet instead ....
print backupSet.fileGroupList[0].sourceDir

# outputs "c:\folder"

Jul 18 '05 #3
Thanks for the help both of you. Got that under control.
"python newbie" <me*******@hotmail.com> wrote in message news:pM*******************@newssvr25.news.prodigy. com...
Is there anything that would get in the way of me being able to reference an object attribute, from within a list.

I have:
# one class here

class BackupSet:
fileGroupList = []

# another class here

class FileGroup:
sourceDir = ''
destinDir = ''
def __init__(self):
self.sourceDir = 'c:\folder'
self.destinDir = 'd:\folder'
fileGroup = FileGroup()

backupSet = BackUpSet()

backupSet.fileGroupList.append(fileGroup)

# when i try to reference an attribute here, I just get 'none'

print bkset.fileGroupList[0].sourceDir or
print "%s" % bkset.fileGroupList[0].sourceDir


thanks
Steve
Jul 18 '05 #4
Sorry about that, I retyped it because I was actually using dom to import an
xml file, and the nodes were used to populate the object attributes, not
the literal strings I was using. I didn't want to put the xml code in this
post. I also set my email to text only, so no more html.
"Bengt Richter" <bo**@oz.net> wrote in message
news:bq**********@216.39.172.122...
On Sun, 30 Nov 2003 01:32:05 GMT, "python newbie" <me*******@hotmail.com> wrote:
This is a multi-part message in MIME format. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-- So far, so annoying
[...]

Is there anything that would get in the way of me being able to =
reference an object attribute, from within a list.

I have:

Where do you have it? This is not an actual verbatim example of something

you tried.
# one class here

class BackupSet: ^--- this is different from your constructor call below at

[1]
fileGroupList =3D []
=20
# another class here

class FileGroup:
sourceDir =3D ''
destinDir =3D ''
def __init__(self):
self.sourceDir =3D 'c:\folder'
self.destinDir =3D 'd:\folder' =20
fileGroup =3D FileGroup()

backupSet =3D BackUpSet()

^----- [1] So I know you didn't do this.

backupSet.fileGroupList.append(fileGroup)

# when i try to reference an attribute here, I just get 'none'

Maybe you have some old code that reads
self.sourceDir = 'none'
in class FileGroup. Who can tell?

print bkset.fileGroupList[0].sourceDir or

^^^^^-- what the heck is that?
print "%s" % bkset.fileGroupList[0].sourceDir
=20

thanks
Steve
------=_NextPart_000_0025_01C3B69E.E2B92BA0
Content-Type: text/html;

<grr>
Two things:
1. Don't post HTML
2. Do post verbatim copy/pasted examples from the window where you
actually tried what you are talking about. It's not that much more

typing. </grr>
I'm hungry. I don't know why I'm putting off food even a minute to do this ;-/
Regards,
Bengt Richter

Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

80
by: Neal | last post by:
Been searching around, and found http://www.w3.org/WAI/ER/IG/ert/iso639.htm which is great, as I've been looking for a guide to what codes are acceptable. I see stuff like lang="en-us" - that...
4
by: Jian H. Li | last post by:
Hello, What's the essential differences between the two ways of "class::member" & "object.member"(or object_pointer->member)? class C{ public: void f() {} int i; };
4
by: Arjen | last post by:
Hi, I have a class with some attributes. For example class person with name as attribute. I have add multiple persons in an arraylist. Now I need a function to get/find a person by the name...
6
by: martin | last post by:
Hi, I am a web page and a web user control. My web user control is placed in my web page using the following directive <%@ Register TagPrefix="uc1" TagName="Header"...
10
by: Jon Noring | last post by:
Out of curiosity, may a CDATA section appear within an attribute value with datatype CDATA? And if so, how about other attribute value datatypes which accept the XML markup characters? To me,...
3
by: gary | last post by:
Hi, I am trying to reference an anchor in a user control with a url. This worked in 1.1 but no longer works in 2.0. The ascx control is located in a "/include" folder If you have a...
5
by: Russell Warren | last post by:
I just ran across a case which seems like an odd exception to either what I understand as the "normal" variable lookup scheme in an instance/object heirarchy, or to the rules regarding variable...
1
by: Doug_J_W | last post by:
I have a Visual Basic (2005) project that contains around twenty embedded text files as resources. The text files contain two columns of real numbers that are separated by tab deliminator, and are...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.