(*args **kwargs) how do I use' em?

T

TheSaint

Hello,
I'm seldomly writng python code, nothing but a beginner code.

I wrote these lines >>

=============================================================
_log_in= mhandler.ConnectHandler(lmbox, _logger, accs)
multhr= sttng['multithread']
if multhr:
_log_in= mhandler.mThreadSession(lmbox, _logger, accs)

for svr in servrs:
nmsvr, user, pwd, ptcl = servrs[svr]
al, dn= sttng['Cfilter']; er= sttng['filter']
try:
rx.append( _log_in.connect((nmsvr, user, pwd, ptcl, (al, dn, er))))
except ProtocolError:
print(svr+ errors['SerProb'])
except KeyboardInterrupt:
raise SystemExit(errors['YouStop'])
if multhr:
for s in rx:
try: s.start()
except (ProtocolError, AttributeError):
print(svr+ errors['SerProb'])
except KeyboardInterrupt:
raise SystemExit(errors['YouStop'])
for s in rx:
try: s.join() # waiting all threads to finish
except (ProtocolError, AttributeError):
print(svr+ errors['SerProb'])
except KeyboardInterrupt:
raise SystemExit(errors['YouStop'])

=============================================================

Surely ugly and I believe that would be a better way to pass the arguments
as I mention on the subject.
Then it should give a dictionary of keywords and some function or a
callable. I don't know how to put down these code lines.
I think I should restructure many points of my data.

Any suggestion will make me happier :)
 
O

OliDa

Hello,
I'm seldomly writng python code, nothing but a beginner code.

I wrote these lines >>

=============================================================
_log_in= mhandler.ConnectHandler(lmbox, _logger, accs)
multhr= sttng['multithread']
if multhr:
    _log_in= mhandler.mThreadSession(lmbox, _logger, accs)

for svr in servrs:
    nmsvr, user, pwd, ptcl = servrs[svr]
    al, dn= sttng['Cfilter']; er= sttng['filter']
    try:
         rx.append( _log_in.connect((nmsvr, user, pwd, ptcl, (al, dn, er))))
    except ProtocolError:
         print(svr+ errors['SerProb'])
    except KeyboardInterrupt:
        raise SystemExit(errors['YouStop'])
if multhr:
    for s in rx:
        try: s.start()
        except (ProtocolError, AttributeError):
            print(svr+ errors['SerProb'])
        except KeyboardInterrupt:
            raise SystemExit(errors['YouStop'])
    for s in rx:
        try: s.join() # waiting all threads to finish
        except (ProtocolError, AttributeError):
            print(svr+ errors['SerProb'])
        except KeyboardInterrupt:
            raise SystemExit(errors['YouStop'])

=============================================================

Surely ugly and I believe that would be a better way to pass the arguments
as I mention on the subject.
Then it should give a dictionary of keywords and some function or a
callable. I don't know how to put down these code lines.
I think I should restructure many points of my data.

Any suggestion will make me happier :)

could you check the Alex Martelli comments here ?
maybe some clarification about kwargs...

http://stackoverflow.com/questions/1098549/proper-way-to-use-kwargs-in-python

OliDa
 

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
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top