Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #36517
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin2!goblin.stu.neva.ru!feeder1.cambriumusenet.nl!feed.tweaknews.nl!195.238.0.231.MISMATCH!news.skynet.be!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rodrick.brown@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'api.': 0.04; 'sys': 0.05; 'attributes': 0.07; 'python': 0.09; 'def': 0.10; 'host)': 0.16; 're-run': 0.16; 'self.client': 0.16; 'skip:? 40': 0.16; 'xmlrpclib': 0.16; 'to:name:python-list@python.org': 0.20; 'import': 0.21; 'wrote': 0.26; 'extend': 0.26; 'i.e.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'interface': 0.27; 'this?': 0.28; 'environment': 0.29; 'skip:_ 10': 0.29; 'class': 0.29; "i'm": 0.29; 'error': 0.30; 'code': 0.31; 'skip:s 30': 0.33; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'done': 0.34; 'received:209.85.220': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'but': 0.36; 'test': 0.36; 'does': 0.37; 'received:209': 0.37; 'sure': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'satellite': 0.65; 'url:api': 0.84; 'subject:Class': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=N0anvRIyZLfpQFg7n4BtqpNApLlGCKMW7kjdnp/hC6I=; b=zehPDaH0dFX7UoLh5LYItQ7x3/2p0OiWLgcMQzRbls8jqqnzXHku+rJGCiKqsZuSv7 M+LLl6z7cemYTPGI7cP7TCeuXdt9TB+SjHtvubbgR8c2JAwGg7CP4UQsAa1GBDpXlyoB 4e2t+o6G+XmI+tsRh/bajKNueEu1WkX+F29bSZ8OmuwXosCXkt+AqMZI31HNc0RQRrTj p3E+EUzQ73kviXQUacKPqzuZbEDYv+RHpFbPYteI+ozri6Nfpmr7dYgQ4livGv+9GBbY 9KoY+1r2UnW5V5RKagZqG421r8DAHeT7+gmyzL3K1w4qM54YLOGpMOnDDLuwtTcC7YeW ABHg== |
| MIME-Version | 1.0 |
| From | Rodrick Brown <rodrick.brown@gmail.com> |
| Date | Wed, 9 Jan 2013 15:13:30 -0500 |
| Subject | Class confusion |
| To | "python-list@python.org" <python-list@python.org> |
| Content-Type | multipart/alternative; boundary=e89a8ff1cae0f9b46004d2e0b3ed |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.337.1357762451.2939.python-list@python.org> (permalink) |
| Lines | 128 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1357762451 news.xs4all.nl 6937 [2001:888:2000:d::a6]:57038 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:36517 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
How can I make a class that has methods with attributes and other
functions?
I see a lot of code
I'm reading the documentation to Redhat's Satellite software which has a
XMLRPC interface and wrote the following code to test the api.
I would like to extend this code to support methods with methods? I see
this done a lot in python code but I'm not sure how to accomplish something
like this?
i.e.
sc = SatelliteConnect()
sc.get_systemlist().get_systemid() ?
or
sc.get_systemlist().get_running_kernel()
How does one chain methods and attributes like this with classes?
import xmlrpclib
import os
import sys
class SatelliteConnect(object):
SATELLITE_URL = "http://nebula.nydc.fxcorp.prv/rpc/api"
SATELLITE_LOGIN = os.environ['USER']
SATELLITE_PASS = os.environ.get('SATELLITE_PASS',None)
def __init__(self):
self.client = xmlrpclib.Server(self.SATELLITE_URL, verbose=0)
self._check_env('SATELLITE_PASS')
self.key = self.client.auth.login(self.SATELLITE_LOGIN,
self.SATELLITE_PASS)
def _check_env(self, env_var):
if not os.environ.get('SATELLITE_PASS'):
print("{} error please set environment varible {} and
re-run script".format(sys.argv[0], env_var))
sys.exit(-1)
def get_runningkernel(self, sysid):
self.get_systemid('somehost')
kernel = self.client.system.getRunningKernel(self.key, sysid)
if kernel:
return kernel
else:
return None
def get_systemlist(self):
systemlist = self.client.system.listSystems(self.key)
return([ system.get('name') for system in systemlist ])
self.client.auth.logout(self.key)
def get_systemid(self, host):
systemlist = self.client.system.getId(self.key, host)
for system in systemlist:
return system.get('id')
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Class confusion Rodrick Brown <rodrick.brown@gmail.com> - 2013-01-09 15:13 -0500
csiph-web