Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #94171
| Path | csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.026 |
| X-Spam-Evidence | '*H*': 0.95; '*S*': 0.00; 'nasty': 0.07; 'cc:addr :python-list': 0.09; 'core,': 0.09; 'credentials,': 0.09; 'identifier,': 0.09; 'instances.': 0.09; 'optional': 0.09; 'url:github': 0.09; 'argument': 0.15; "(it's": 0.16; 'accounts?': 0.16; 'circumvent': 0.16; 'core.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'multiple,': 0.16; 'subject:exception': 0.16; 'url:py': 0.16; 'wrote:': 0.16; 'module,': 0.18; '(in': 0.18; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'suggested': 0.20; 'am,': 0.23; 'code.': 0.23; 'references': 0.23; 'sets': 0.23; 'second': 0.24; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; 'module': 0.25; 'appear': 0.26; 'parameters': 0.27; 'separate': 0.27; 'message-id:@mail.gmail.com': 0.27; 'issue,': 0.27; 'module.': 0.27; 'function': 0.28; 'if,': 0.29; 'initialized': 0.29; 'itself,': 0.29; 'code': 0.30; 'core': 0.32; 'problem': 0.33; 'know.': 0.34; 'this?': 0.34; 'received:google.com': 0.35; 'could': 0.35; "isn't": 0.35; 'but': 0.36; 'should': 0.36; 'there': 0.36; 'possible': 0.36; 'keyword': 0.36; 'modules': 0.36; 'subject:work': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'agree': 0.37; 'expect': 0.37; 'several': 0.38; 'someone': 0.38; 'mean': 0.38; 'why': 0.39; 'does': 0.39; 'takes': 0.39; 'subject:with': 0.40; 'your': 0.60; "you'll": 0.61; 'default': 0.61; 'success': 0.62; 'more': 0.63; 'different': 0.63; '20,': 0.66; 'accounts': 0.66; 'account': 0.66; 'choose': 0.68; 'accounts.': 0.72; 'jul': 0.72; 'yourself': 0.73; 'cecil': 0.84; 'chrisa': 0.84; 'style:': 0.84; 'subject:good': 0.84; 'url:cecilwesterhof': 0.84; 'url:master': 0.84; 'westerhof': 0.84; 'subject:this': 0.85; 'to:none': 0.91; 'choose.': 0.91 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=gRQhlqW/i1ZrdfCvG/XIZ+JqEQqEcz5mN3s72lls5tg=; b=m7gULgZZ5Gxs3tGUuYJYVrK/NP2r80X5B1s9U990EVUV53O20glRBXQSqOPx9idenJ QcWXd/rtbSlA4fUW7n9BGJcuoHimIk7q0JXakmR0Z7YWZzjczUhe/k6S8+ZK5X24IO6M zsTuORxvIN6tSD4ps0Ue5+CfSCP6iGlz9QLPXKSWw2HOPTtb0fKRzDJawcLaXqdGwdPL aNye477RxvKLBFyg5rseSIWQ1eK1/NC0YG8x5ruDL63offuSh+kyKpcQS/FIfWZo309C Ss4UfZBvbNyQb3RApiUCerKKVuNsv0cFonJDf2owYAMtCJoQS5iRDRoNmRmjnjiTG6HF hpPw== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.132.7 with SMTP id g7mr31343131iod.9.1437345636508; Sun, 19 Jul 2015 15:40:36 -0700 (PDT) |
| In-Reply-To | <87615fyem2.fsf@Equus.decebal.nl> |
| References | <87380kzb8b.fsf@Equus.decebal.nl> <mailman.711.1437310769.3674.python-list@python.org> <87r3o4xfhx.fsf@Equus.decebal.nl> <mailman.733.1437329515.3674.python-list@python.org> <87io9gx8tb.fsf@Equus.decebal.nl> <mailman.743.1437340103.3674.python-list@python.org> <87615fyem2.fsf@Equus.decebal.nl> |
| Date | Mon, 20 Jul 2015 08:40:36 +1000 |
| Subject | Re: Is this a good way to work with init and exception |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.748.1437345644.3674.python-list@python.org> (permalink) |
| Lines | 34 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1437345644 news.xs4all.nl 2945 [2001:888:2000:d::a6]:38145 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:94171 |
Show key headers only | View raw
On Mon, Jul 20, 2015 at 8:19 AM, Cecil Westerhof <Cecil@decebal.nl> wrote: >> If two modules import the same module, they get two references to >> that same module, not two separate module instances. Since your >> parameters appear only to affect the initialization itself, this is >> not likely to be a problem (it's not like you'll need to >> authenticate with two different sets of credentials, for instance), >> but it will mean that the second one will import an >> already-initialized module. That's why I suggested the try_init >> function which would quietly return an immediate success if the >> module had already been initialized. But if this isn't going to be >> an issue, then your code's fine. > > Good to know. I would expect two different instances. > > I agree that in my case it would not be a problem, but I put the code > on GitHub: > https://github.com/CecilWesterhof/PythonLibrary/blob/master/twitterDecebal.py > I should do my best to circumvent nasty surprises for users of the > code. Someone else could use several Twitter accounts at the same > time. Is there a way to do this? Does the instantiation of Core() involve authentication? Is it possible to call Core() more than once and use different accounts? Your send_message() takes an account identifier, so it might be you don't need separate accounts. But if, just very occasionally, you do need multiple, here's a possible design style: Have init() return the Core as well as stashing it in _core, and then have send_message() take an optional keyword argument (in 3.x, keyword-only) to choose a different core. That way, it'll by default use the most recently initialized core, but you can create multiple and manage them yourself if you so choose. (Obviously you'd use reinit_allowed=True for all the initializations.) ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-19 12:35 +0200
Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-19 22:59 +1000
Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-19 18:46 +0200
Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-20 04:11 +1000
Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-19 21:10 +0200
Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-20 07:08 +1000
Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-20 00:19 +0200
Re: Is this a good way to work with init and exception Chris Angelico <rosuav@gmail.com> - 2015-07-20 08:40 +1000
Re: Is this a good way to work with init and exception Cecil Westerhof <Cecil@decebal.nl> - 2015-07-20 01:27 +0200
csiph-web