Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50263 > unrolled thread
| Started by | "L O'Shea" <lo0446@my.bristol.ac.uk> |
|---|---|
| First post | 2013-07-09 10:03 -0700 |
| Last post | 2013-07-10 01:23 -0700 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.python
Help with 'self' and 'set_usage' "L O'Shea" <lo0446@my.bristol.ac.uk> - 2013-07-09 10:03 -0700
Re: Help with 'self' and 'set_usage' Ethan Furman <ethan@stoneleaf.us> - 2013-07-09 10:19 -0700
Re: Help with 'self' and 'set_usage' Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2013-07-09 19:24 +0200
Re: Help with 'self' and 'set_usage' Andrew Berg <robotsondrugs@gmail.com> - 2013-07-09 12:32 -0500
Re: Help with 'self' and 'set_usage' "L O'Shea" <lo0446@my.bristol.ac.uk> - 2013-07-10 01:23 -0700
| From | "L O'Shea" <lo0446@my.bristol.ac.uk> |
|---|---|
| Date | 2013-07-09 10:03 -0700 |
| Subject | Help with 'self' and 'set_usage' |
| Message-ID | <de7c4d2c-817e-4237-b312-0795c1c43888@googlegroups.com> |
Hi all,
I'm interning and have been given the job of extending a program that has been written by someone else. I've never used Python before so it's a bit of a struggle but I've got to say I'm loving the language so far.
In on of the scripts there is
def set_usage(self,s):
self.usage_str = s
Could anyone shed some light on this? I can't find mention of this anywhere in any Python documentation or anywhere else in the code where usage_str might be defined. Can you just create variables in that object by writing self.name = "david" self.hobby = "fishing"??
If this is any help it is used later in the program (or in other scripts) like
prog.set_usage("""%prog <command> [options] ....""")
Thanks for your help, I have spent a good while googling python docs, code snippets and reading through a Python book I have on my desk to no avail.
Cheers in advance.
[toc] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2013-07-09 10:19 -0700 |
| Message-ID | <mailman.4463.1373390374.3114.python-list@python.org> |
| In reply to | #50263 |
On 07/09/2013 10:03 AM, L O'Shea wrote: > > Hi all, Howdy! > I'm interning and have been given the job of extending a program that has been written by someone else. I've never used Python before so it's a bit of a struggle but I've got to say I'm loving the language so far. Excellent way to start a question! :) > In one of the scripts there is > > def set_usage(self,s): > self.usage_str = s Careful of whitespace when posting (I fixed that one for you). > Can you just create variables in that object by writing self.name = "david" self.hobby = "fishing"?? Yup, you sure can. -- ~Ethan~
[toc] | [prev] | [next] | [standalone]
| From | Antoon Pardon <antoon.pardon@rece.vub.ac.be> |
|---|---|
| Date | 2013-07-09 19:24 +0200 |
| Message-ID | <mailman.4464.1373390763.3114.python-list@python.org> |
| In reply to | #50263 |
Op 09-07-13 19:03, L O'Shea schreef: > Hi all, > I'm interning and have been given the job of extending a program that > has been written by someone else. I've never used Python before so it's > a bit of a struggle but I've got to say I'm loving the language so far. > > In on of the scripts there is > > def set_usage(self,s): > self.usage_str = s > > Could anyone shed some light on this? I can't find mention of this > anywhere in any Python documentation or anywhere else in the code > where usage_str might be defined. Can you just create variables in > that object by writing self.name = "david" self.hobby = "fishing"?? Yes you can. -- Antoon Pardon
[toc] | [prev] | [next] | [standalone]
| From | Andrew Berg <robotsondrugs@gmail.com> |
|---|---|
| Date | 2013-07-09 12:32 -0500 |
| Message-ID | <mailman.4465.1373391134.3114.python-list@python.org> |
| In reply to | #50263 |
On 2013.07.09 12:03, L O'Shea wrote: > Could anyone shed some light on this? I can't find mention of this anywhere in any Python documentation or anywhere else in the code where usage_str might be defined. In Python, you don't declare or initialize variables before using them. In the example you gave, that is where usage_str is defined. You simply assign an object to a name or attribute (which may or may not have existed previously). You can then change it to anything else you want; Python is dynamically typed, so the object you assign to it can be of any type. Note: a class with __slots__ defined is the exception to this, but that's a bit of an advanced topic. BTW, you can play with objects in the interactive interpreter. It's a great way to quickly learn how certain things work. -- CPython 3.3.2 | Windows NT 6.2.9200 / FreeBSD 9.1
[toc] | [prev] | [next] | [standalone]
| From | "L O'Shea" <lo0446@my.bristol.ac.uk> |
|---|---|
| Date | 2013-07-10 01:23 -0700 |
| Message-ID | <729a285e-497f-4a04-a141-438ebc96997f@googlegroups.com> |
| In reply to | #50263 |
On Tuesday, 9 July 2013 18:03:41 UTC+1, L O'Shea wrote:
> Hi all,
>
> I'm interning and have been given the job of extending a program that has been written by someone else. I've never used Python before so it's a bit of a struggle but I've got to say I'm loving the language so far.
>
>
>
> In on of the scripts there is
>
>
>
> def set_usage(self,s):
>
> self.usage_str = s
>
>
>
> Could anyone shed some light on this? I can't find mention of this anywhere in any Python documentation or anywhere else in the code where usage_str might be defined. Can you just create variables in that object by writing self.name = "david" self.hobby = "fishing"??
>
>
>
> If this is any help it is used later in the program (or in other scripts) like
>
>
>
> prog.set_usage("""%prog <command> [options] ....""")
>
>
>
> Thanks for your help, I have spent a good while googling python docs, code snippets and reading through a Python book I have on my desk to no avail.
>
>
>
> Cheers in advance.
Thanks for the advice everyone that was really helpful! Gotta love the USA/UK time difference I can post a question here at the end of the day and it be answered by morning - Not that it took any of you very long!
Stay tuned for more Python questions :)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web