среда, 31 августа 2016 г., 14:09:16 UTC+7 пользователь ast написал:
> Hello
>
> I made few experiments about variables visibility
> for methods.
>
> class MyClass:
> a = 1
> def test(self):
> print(a)
>
> obj = MyClass()
> obj.test()
>
> Traceback (most recent call last):
> Fi
On Wednesday, August 31, 2016 at 12:09:16 AM UTC-7, ast wrote:
> Hello
>
> I made few experiments about variables visibility
> for methods.
>
> class MyClass:
> a = 1
> def test(self):
> print(a)
>
> obj = MyClass()
> obj.test()
>
> Traceback (most recent call last):
> File ""
"dieter" a écrit dans le message de
news:mailman.63.1472630594.24387.python-l...@python.org...
"ast" writes:
You are right. And it is documented this way.
Thank you
--
https://mail.python.org/mailman/listinfo/python-list
"ast" writes:
> ...
> So it seems that when an object's méthod is executed, variables
> in the scope outside the object's class can be read (2nd example),
> but not variables inside the class (1st example).
>
> For 1st example, I know that print(MyClass.a) or print(self.a)
> would have work.
>
> A
Op dinsdag 24 december 2013 17:23:43 UTC+1 schreef Jean-Michel Pichavant:
> - Original Message -
> > Hello, for the first time I'm trying te create a little Python
> > program. (on a raspberri Pi)
> >
> > I don't understand the handling of variables in a loop with Python.
> >
> >
> > Let
Hello everyone, I have been away for a while.
I have been reading all the good advises and want to explain why I want to read
the temperatures separately from the main script. It takes a long time to read
out 10 temperatures. About 10 seconds. So that’s the reason why I had the idea
to create a
On Thu, Dec 26, 2013 at 7:14 PM, Dave Angel wrote:
> On Thu, 26 Dec 2013 16:41:57 +1100, Steven D'Aprano
> wrote:
>>
>> Chris Angelico wrote:
>> > Does anyone else have the vague feeling that the OP's problem
> might be
>> > better served by simply importing the script (thus making those
> values
On Thu, 26 Dec 2013 16:41:57 +1100, Steven D'Aprano
wrote:
Chris Angelico wrote:
> Does anyone else have the vague feeling that the OP's problem
might be
> better served by simply importing the script (thus making those
values
> available to another Python script) than by any of these rat
On 12/24/2013 11:27 AM, vanommen.rob...@gmail.com wrote:
> Indeed this is code what I found on the web to read temperatures from
> 10 DS18B20 singlewire sensors.
>
> My only programming (little) experience is VBA (Excel mostly).
>
Definitely you'll want to learn python before you go much farther
Chris Angelico wrote:
> Does anyone else have the vague feeling that the OP's problem might be
> better served by simply importing the script (thus making those values
> available to another Python script) than by any of these rather more
> complicated theories?
Damn yes!
--
Steven
--
https
On Thu, Dec 26, 2013 at 12:01 PM, Cameron Simpson wrote:
> On 25Dec2013 15:27, Denis McMahon wrote:
>> On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote:
>> > On 25Dec2013 02:54, Denis McMahon wrote:
>> >> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote:
>> >> > In this script
On 25Dec2013 15:27, Denis McMahon wrote:
> On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote:
> > On 25Dec2013 02:54, Denis McMahon wrote:
> >> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote:
> >> > In this script i want to read the temperatures and make them
> >> > available t
On Wed, 25 Dec 2013 16:42:47 +1100, Cameron Simpson wrote:
> On 25Dec2013 02:54, Denis McMahon wrote:
>> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote:
>> > In this script i want to read the temperatures and make them
>> > available to other scripts. [...]
>> If you want this process
vanommen.rob...@gmail.com wrote:
> Indeed this is code what I found on the web to read temperatures from 10
> DS18B20 singlewire sensors.
>
> My only programming (little) experience is VBA (Excel mostly).
>
> avgtemperatures = [] is indeed from the original code where this line
>
> 'avgtemperat
On 12/24/2013 08:07 AM, vanommen.rob...@gmail.com wrote:
[snip...]
x = 1
while x <> 10
var x = x
x = x + 1
[snip...]
Besides the other valid answers you have received, I want to add one other minor nit. The
symbol <> for unequal is deprecated -- it's better to use != instead.
On 25Dec2013 02:54, Denis McMahon wrote:
> On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote:
> > In this script i want to read the temperatures and make them available
> > to other scripts. [...]
> If you want this process to provide data to other processes, you might
> want to look at u
On Tue, 24 Dec 2013 10:27:13 -0800, vanommen.robert wrote:
> In this script i want to read the temperatures and make them available
> to other scripts.
The "global" keyword doesn't do that.
"global" is used inside a function definition in python to tell the
function that it is working with a gl
On Tue, 24 Dec 2013 09:54:48 -0800 (PST), vanommen.rob...@gmail.com
wrote:
You should always start by mentioning python version and o.s.
import time
global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5,
Sens_Raw6, Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10
The global statement make
Indeed this is code what I found on the web to read temperatures from 10
DS18B20 singlewire sensors.
My only programming (little) experience is VBA (Excel mostly).
avgtemperatures = [] is indeed from the original code where this line
'avgtemperatures.append(sum(temperatures) / float(len(temper
On Tue, Dec 24, 2013 at 12:54 PM, wrote:
> import time
> global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6,
> Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10
> while True:
> sensorids = ["28-054c4932", "28-054c9454",
> "28-054c9fca", "28-054c4401", "28-00
import time
global Sens_Raw1, Sens_Raw2, Sens_Raw3, Sens_Raw4, Sens_Raw5, Sens_Raw6,
Sens_Raw7, Sens_Raw8, Sens_Raw9, Sens_Raw10
while True:
sensorids = ["28-054c4932", "28-054c9454", "28-054c9fca",
"28-054c4401", "28-054dab99", "28-054cf9b4", "28-054c8a03",
"
On 12/24/2013 11:07 AM, vanommen.rob...@gmail.com wrote:
Hello, for the first time I'm trying te create a little Python program. (on a
raspberri Pi)
I don't understand the handling of variables in a loop with Python.
Lets say i want something like this.
x = 1
while x <> 10
var x = x
vanommen.rob...@gmail.com wrote:
> Hello, for the first time I'm trying te create a little Python program.
> (on a raspberri Pi)
>
> I don't understand the handling of variables in a loop with Python.
>
>
> Lets say i want something like this.
>
> x = 1
> while x <> 10
> var x = x
> x = x + 1
On 24.12.2013 17:07, vanommen.rob...@gmail.com wrote:
Hello, for the first time I'm trying te create a little Python program. (on a
raspberri Pi)
I don't understand the handling of variables in a loop with Python.
Lets say i want something like this.
x = 1
while x <> 10
var x = x
- Original Message -
> Hello, for the first time I'm trying te create a little Python
> program. (on a raspberri Pi)
>
> I don't understand the handling of variables in a loop with Python.
>
>
> Lets say i want something like this.
>
> x = 1
> while x <> 10
> var x = x
> x =
On Tue, Dec 24, 2013 at 11:07 AM, wrote:
> Hello, for the first time I'm trying te create a little Python program.
> (on a raspberri Pi)
>
> I don't understand the handling of variables in a loop with Python.
>
>
> Lets say i want something like this.
>
> x = 1
> while x <> 10
> var x = x
Michael Torrie於 2013年6月20日星期四UTC+8下午2時01分11秒寫道:
>
> But since the LISP never really got a form beyond S-expressions,
>
> leaving us with lots of parenthesis everywhere, Python wins much as the
>
> Hitchhiker's Guide to the Galaxy wins.
Yep, a list is mutable even it's empty.
But constant integ
Νίκος schreef:
Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
Names are *always* linked to objects, not to other names.
a = []
b = a # Now a and b refer to the same list
a = {} # Now a refers to a dict, and b refers to the same list as before
I see, thank you Steven.
But since this is
On 06/19/2013 11:48 PM, Steven D'Aprano wrote:
> On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote:
>
>> The real power and expressivity of Python comes from embracing the
>> abstractions that Python provides to your advantage. There's a certain
>> elegance and beauty that comes from such
On Wed, 19 Jun 2013 23:16:51 -0600, Michael Torrie wrote:
> The real power and expressivity of Python comes from embracing the
> abstractions that Python provides to your advantage. There's a certain
> elegance and beauty that comes from such things, which I believe really
> comes from the elegan
On 06/19/2013 11:16 PM, Michael Torrie wrote:
> It turns out that lists, hashes (dicts), and classes can pretty much
> do anything with having to much about with C-style pointers and
> such.
Oh wow. Parse error. should read, "pretty much do anything without
having to muck about with C-style point
On 06/18/2013 03:51 AM, Νίκος wrote:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as before
>
> I see
On Tue, Jun 18, 2013 at 7:51 PM, Νίκος wrote:
> Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
>
>> Names are *always* linked to objects, not to other names.
>>
>> a = []
>> b = a # Now a and b refer to the same list
>> a = {} # Now a refers to a dict, and b refers to the same list as befor
Στις 18/6/2013 12:05 μμ, ο/η Steven D'Aprano έγραψε:
Names are *always* linked to objects, not to other names.
a = []
b = a # Now a and b refer to the same list
a = {} # Now a refers to a dict, and b refers to the same list as before
I see, thank you Steven.
But since this is a fact how do y
On Tue, 18 Jun 2013 11:49:36 +0300, Νίκος wrote:
> Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε:
>> Not quite: a and b _are_ memory addresses, At the same time, a and b
>> are references to the data (the objects) stored in those memory
>> locations.
>>
>> The distinction is probably more impo
Στις 18/6/2013 9:39 πμ, ο/η Larry Hudson έγραψε:
Not quite: a and b _are_ memory addresses, At the same time, a and b
are references to the data (the objects) stored in those memory locations.
The distinction is probably more important in languages like C/C++,
where the _language_ gives you di
On Mon, 17 Jun 2013 23:39:10 -0700, Larry Hudson wrote:
> On 06/17/2013 08:50 AM, Simpleton wrote:
>> On 17/6/2013 2:58 μμ, Michael Torrie wrote:
>>
>> a = 5
>> b = a
>>
>> a <---> memory address
>> b <---> memory address
>>
>> I like to think a and b as references to the same memory address
>>
>
On 06/17/2013 08:50 AM, Simpleton wrote:
On 17/6/2013 2:58 μμ, Michael Torrie wrote:
a = 5
b = a
a <---> memory address
b <---> memory address
I like to think a and b as references to the same memory address
Not quite: a and b _are_ memory addresses, At the same time, a and b are references
On Tue, 18 Jun 2013 00:12:34 -0400, Dave Angel wrote:
> On 06/17/2013 10:42 PM, Steven D'Aprano wrote:
>> On Mon, 17 Jun 2013 21:06:57 -0400, Dave Angel wrote:
>>
>>> On 06/17/2013 08:41 PM, Steven D'Aprano wrote:
In Python 3.2 and older, the data will be either UTF-4 or
On 06/17/2013 10:42 PM, Steven D'Aprano wrote:
On Mon, 17 Jun 2013 21:06:57 -0400, Dave Angel wrote:
On 06/17/2013 08:41 PM, Steven D'Aprano wrote:
In Python 3.2 and older, the data will be either UTF-4 or UTF-8,
selected when the Python compiler itself is compiled.
I think that was
> While you said to me to forget about memory locations, and that's indeed
> made things easy to follow i still keep wondering, how Python internally
> keeping tracks of 'x' and 'y' names as well as their referenced objects
> (i.e. number 6).
There is an excellent blog post about CPython intern
On Tue, 18 Jun 2013 02:38:20 +, Steven D'Aprano wrote:
> On Tue, 18 Jun 2013 00:41:53 +, Steven D'Aprano wrote:
>
>> In Python 3.2 and older, the data will be either UTF-4 or UTF-8,
>> selected when the Python compiler itself is compiled. In Python 3.3,
>> the data will be stored in eithe
On Mon, 17 Jun 2013 21:06:57 -0400, Dave Angel wrote:
> On 06/17/2013 08:41 PM, Steven D'Aprano wrote:
>>
>>
>>
>> In Python 3.2 and older, the data will be either UTF-4 or UTF-8,
>> selected when the Python compiler itself is compiled.
>
> I think that was a typo. Do you perhaps UCS-2 or U
On Tue, 18 Jun 2013 00:41:53 +, Steven D'Aprano wrote:
> In Python 3.2 and older, the data will be either UTF-4 or UTF-8,
> selected when the Python compiler itself is compiled. In Python 3.3, the
> data will be stored in either Latin-1, UTF-4, or UTF-8, depending on the
> contents of the stri
On 06/17/2013 08:41 PM, Steven D'Aprano wrote:
In Python 3.2 and older, the data will be either UTF-4 or UTF-8, selected
when the Python compiler itself is compiled.
I think that was a typo. Do you perhaps UCS-2 or UCS-4
In Python 3.3, the data will
be stored in either Latin-1, UTF-4,
On Tue, 18 Jun 2013 02:26:39 +0300, Νίκος wrote:
> Στις 18/6/2013 2:09 πμ, ο/η Steven D'Aprano έγραψε:
>> {"a": "Hello world"}
>>
>> Do you see a memory location there? There is no memory location. There
>> is the name, "a", and the object it is associated with, "Hello world".
>> Either the dict,
Στις 18/6/2013 2:09 πμ, ο/η Steven D'Aprano έγραψε:
{"a": "Hello world"}
Do you see a memory location there? There is no memory location. There is
the name, "a", and the object it is associated with, "Hello world".
Either the dict, or the string, may move around memory if the underlying
memory m
On Mon, 17 Jun 2013 14:34:57 +0300, Simpleton wrote:
> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>> Now, in languages like Python, Ruby, Java, and many others, there is no
>> table of memory addresses. Instead, there is a namespace, which is an
>> association between some name and some value:
>
On 6/17/2013 1:17 PM, Νίκος wrote:
On Mon, Jun 17, 2013 at 8:55 AM, Simpleton wrote:
On 17/6/2013 5:22 μμ, Terry Reedy wrote:
When you interpret Python code, do you put data in locations with
integer addresses?
I lost you here.
Memory in biological brains is not a linear series of bits,
On 17/6/2013 7:23 μμ, Benjamin Kaplan wrote:
On Mon, Jun 17, 2013 at 8:55 AM, Simpleton wrote:
On 17/6/2013 5:22 μμ, Terry Reedy wrote:
On 6/17/2013 7:34 AM, Simpleton wrote:
On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
Now, in languages like Python, Ruby, Java, and many others, there is
On Mon, Jun 17, 2013 at 8:55 AM, Simpleton wrote:
> On 17/6/2013 5:22 μμ, Terry Reedy wrote:
>>
>> On 6/17/2013 7:34 AM, Simpleton wrote:
>>>
>>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
Now, in languages like Python, Ruby, Java, and many others, there is no
table of memory addr
On Mon, Jun 17, 2013 at 11:55 AM, Simpleton wrote:
> On 17/6/2013 5:22 μμ, Terry Reedy wrote:
>
>> On 6/17/2013 7:34 AM, Simpleton wrote:
>>
>>> On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
>>>
Now, in languages like Python, Ruby, Java, and many others, there is no
table of memory addre
On 17/6/2013 5:22 μμ, Terry Reedy wrote:
On 6/17/2013 7:34 AM, Simpleton wrote:
On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
Now, in languages like Python, Ruby, Java, and many others, there is no
table of memory addresses. Instead, there is a namespace, which is an
association between some nam
On 17/6/2013 2:58 μμ, Michael Torrie wrote:
In python just think of assignment as making a name *be* an object. And
if you assign one name to another name, that makes both names be the
same object. When names are unbound (either they go out of scope or you
manually unbind them), the objects the
On 6/17/2013 7:34 AM, Simpleton wrote:
On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
Now, in languages like Python, Ruby, Java, and many others, there is no
table of memory addresses. Instead, there is a namespace, which is an
association between some name and some value:
global namespace:
On 06/17/2013 05:34 AM, Simpleton wrote:
> So is it safe to say that in Python a == &a ? (& stands for memory address)
>
> is the above correct?
It might be partially equivalent inside the interpreter, but it's not
something you should concern yourself with. And in general, no it's not
safe to s
On 17/6/2013 9:51 πμ, Steven D'Aprano wrote:
Now, in languages like Python, Ruby, Java, and many others, there is no
table of memory addresses. Instead, there is a namespace, which is an
association between some name and some value:
global namespace:
x --> 23
y --> "hello world"
Firs
Steven D'Aprano writes:
> On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote:
>
> > In [the hypothetical language] Python--, any time you use a name,
> > you have to prefix it with the word 'variable':
> > variable x = 4
> > print(variable x)
> >
> > Does Python-- have variables?
>
> O
On Thu, 23 Aug 2012 14:22:08 -0500, Evan Driscoll wrote:
> On 08/23/2012 12:56 PM, Steven D'Aprano wrote:
>> On Thu, 23 Aug 2012 12:17:03 -0500, Evan Driscoll wrote:
>>
>>> I definitely *wouldn't* say "Python
>>> classes aren't really classes" -- even though (I assert) Python
>>> classes are *far
On Fri, Aug 24, 2012 at 5:22 AM, Evan Driscoll wrote:
> In Python--, any time you use a name, you have to prefix it with the
> word 'variable':
> variable x = 4
> print(variable x)
That gets really unwieldy. You should shorten it to a single symbol.
And your language could be called Python Hy
On 12/1/2009 7:51 AM, Terry Reedy wrote:
In everyday life and natural languages, a single name can be used to
refer to multiple objects just by context without referring any
namespace.
Namespace are contexts. They were (re)invented in programming just to
make it easier to have single name could
Lie Ryan wrote:
On 11/30/2009 12:00 PM, Terry Reedy wrote:
Dennis Lee Bieber wrote:
In these languages, the names always refer to the same location.
Python confuses matters by having names that don't really refer to
location, but are attached to the objects.
In everyday life and natural lang
On 11/30/2009 12:00 PM, Terry Reedy wrote:
Dennis Lee Bieber wrote:
In these languages, the names always refer to the same location.
Python confuses matters by having names that don't really refer to
location, but are attached to the objects.
In everyday life and natural languages, names refe
Dennis Lee Bieber wrote:
In these languages, the names always refer to the same location.
Python confuses matters by having names that don't really refer to
location, but are attached to the objects.
In everyday life and natural languages, names refer to people, other
objects, roles,
Thanks Dennis and Steve,
This explains it all! I will discard using one.a and use one.myList[0]
directly, instead. I really appreciate your patience and the elaboration of
the concept.
Warm Regards,
Nitin Changlani.
On Sun, Nov 29, 2009 at 1:02 AM, Steven D'Aprano <
st...@remove-this-cybersource
On Sat, 28 Nov 2009 22:18:11 -0500, Nitin Changlani wrote:
> Thanks for the reply MRAB, Rami, Matt and Mel,
>
> I was assuming that since one.myList0] = one.a, the change in one.a will
> ultimately trickle down to myList[0] whenever myList[0] is printed or
> used in an expression. It doesn't come
Thanks for the reply MRAB, Rami, Matt and Mel,
I was assuming that since one.myList0] = one.a, the change in one.a will
ultimately trickle down to myList[0] whenever myList[0] is printed or used
in an expression. It doesn't come intuitively to me as to why that should
not happen. Can you kindly su
Thanks for the reply MRAB, Rami, Matt and Mel,
I was assuming that since one.myList0] = one.a, the change in one.a will
ultimately trickle down to myList[0] whenever myList[0] is printed or used
in an expression. It doesn't come intuitively to me as to why that should
not happen. Can you kindly su
Rami Chowdhury wrote:
> Hi Nitin,
>
> On Sat, Nov 28, 2009 at 14:36, MRAB wrote:
>> Nitin Changlani. wrote:
>>> three.py
>>>
>>> import one
>>> import two
>>>
>>> def argFunc():
>>> one.x = 'place_no_x'
>>> one.a = 'place_no_a'
>>> one.b = 'place_no_b'
>>>
>
> I think this is what
Rami Chowdhury
"Never assume malice when stupidity will suffice." -- Hanlon's Razor
408-597-7068 (US) / 07875-841-046 (UK) / 0189-245544 (BD)
On Sat, Nov 28, 2009 at 14:57, Matt Nordhoff wrote:
> Rami Chowdhury wrote:
>> Hi Nitin,
>>
>> On Sat, Nov 28, 2009 at 14:36, MRAB wrote:
>>> N
Rami Chowdhury wrote:
> Hi Nitin,
>
> On Sat, Nov 28, 2009 at 14:36, MRAB wrote:
>> Nitin Changlani. wrote:
>>> three.py
>>>
>>> import one
>>> import two
>>>
>>> def argFunc():
>>>one.x = 'place_no_x'
>>>one.a = 'place_no_a'
>>>one.b = 'place_no_b'
>>>
>
> I think this
Hi Nitin,
On Sat, Nov 28, 2009 at 14:36, MRAB wrote:
> Nitin Changlani. wrote:
>> three.py
>>
>> import one
>> import two
>>
>> def argFunc():
>> one.x = 'place_no_x'
>> one.a = 'place_no_a'
>> one.b = 'place_no_b'
>>
I think this is what is biting you. You might expect tha
Nitin Changlani. wrote:
Hello everyone,
I am fairly new to Python and occasionally run into problems that are
almost always resolved by referring to this mailing-list's archives.
However, I have this one issue which has got me stuck and I hope you
will be tolerant enough to help em out with i
On Sat, 12 Sep 2009 00:39:17 -0700, Miles Kaufmann wrote:
> On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote:
>> If an integer variable is an integer, and a string variable is a
>> string,
>> and float variable is a float, and a list variable is a list (there's a
>> pattern here), shouldn't a cl
On Apr 17, 2009, at 8:56 PM, Steven D'Aprano wrote:
If an integer variable is an integer, and a string variable is a
string,
and float variable is a float, and a list variable is a list
(there's a
pattern here), shouldn't a class variable be a class and an instance
variable be an instance?
I
In article ,
Chris Rebert wrote:
>
>class foo:
>def __init__(self, maxvalue):
>self.maxvalue =3D maxvalue
>self.value =3D 0
>
>def put(self, value=3DNone):
>self.value =3D self.value if value is None else value
Stylistic nit:
I'd make that
self.value = v
Chris Rebert a écrit :
(snip)
Default values are only evaluated once, when the class is defined,
s/class/function/
The function objects (defined in a class statement body...) are created
before the class object itself.
thus "self" is not defined at that point since the class is still
On Aug 27, 5:44 pm, Chris Rebert wrote:
> On Thu, Aug 27, 2009 at 2:37 PM, seanacais wrote:
> > I'm working on a program where I wish to define the default value of a
> > method as a value that was set in __init__. I get a compilation error
> > saying that self is undefined.
>
> > As always a cod
On Thu, Aug 27, 2009 at 11:37 PM, seanacais wrote:
> I'm working on a program where I wish to define the default value of a
> method as a value that was set in __init__. I get a compilation error
> saying that self is undefined.
>
> As always a code snippet helps :-)
>
> class foo:
> def __init
On Thu, Aug 27, 2009 at 2:37 PM, seanacais wrote:
> I'm working on a program where I wish to define the default value of a
> method as a value that was set in __init__. I get a compilation error
> saying that self is undefined.
>
> As always a code snippet helps :-)
>
> class foo:
> def __init_
> Steven D'Aprano (SD) wrote:
>SD> On Fri, 17 Apr 2009 17:48:55 +0200, Diez B. Roggisch wrote:
>>> No, because you are creating *classvariables* when declaring things like
>>> this:
>SD> ...
>>> OTOH, when assigning to an instance, this will create an
>>> *instance*-variable. Which is what
En Wed, 25 Feb 2009 21:24:33 -0200, escribió:
On Wed, Feb 25, 2009 at 05:05:28PM -0200, Gabriel Genellina wrote:
I'd try to move all the global stuff in that module into a function,
"init". Importing the module will always succeed - you have to manually
call init() after importing it.
i nor
On Wed, Feb 25, 2009 at 05:05:28PM -0200, Gabriel Genellina wrote:
> I'd try to move all the global stuff in that module into a function,
> "init". Importing the module will always succeed - you have to manually
> call init() after importing it.
i normally do that anyway and would also have do
En Wed, 25 Feb 2009 16:48:16 -0200, escribió:
update: i've found one, but this only works if the exception is raised
at a point determined by the outside.
to explain why this is applicable: in the examples, i used `1/0` to
raise a zero division exception inside the module whose scope i want to
On Tue, Feb 24, 2009 at 03:27:19PM +0100, chr...@fsfe.org wrote:
> * is there a workaround?
> * especially, is there a workaround that works w/o rewriting the
> modules that raise the exceptions? (otherwise, wrapping all the
> stuff called in the __name__=="__main__" wrapper into a
"Jose Ignacio Gisbert" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| I have one doubt, in my applciation I have a method (Method1) which has
| other method (Method2) inside of it.
You have a function inside a function. In Python, methods are functions
bound to classes.
|
At Thursday 14/12/2006 05:50, avlee wrote:
Is it possible to use in python variables with dynamicly created names ?
How ?
Use a dictionary:
d = {}
d[almost_arbitrary_key] = value
--
Gabriel Genellina
Softlab SRL
__
Correo Yahoo!
Espacio par
avlee <[EMAIL PROTECTED]> writes:
> Is it possible to use in python variables with dynamicly created names ?
Yes, but don't.
> How ?
You almost certainly want to use something like a dictionary instead.
--
http://mail.python.org/mailman/listinfo/python-list
avlee schrieb:
> Hello
>
> Is it possible to use in python variables with dynamicly created names ?
> How ?
In such cases, use a dictionary:
vars = {}
for some_name, some_value in some_values_generating_thing():
vars[some_name] = some_value
Diez
--
http://mail.python.org/mailman/listinf
Ben Cartwright wrote:
> The typical kludge is to wrap the variable in the outer function inside
> a mutable object, then pass it into the inner using a default argument:
>
> def outer():
> a = "outer"
> def inner(wrapa=[a]):
> print wrapa[0]
> wrapa[0] = "inner"
> retu
[EMAIL PROTECTED] wrote:
> Is it possible to change the value of a variable in the outer function
> if you are in a nested inner function?
Depends on what you mean by "changing the value". If you mean mutating a
mutable object, yes, it's possible. If you mean rebinding the name to a
different obje
[EMAIL PROTECTED] wrote:
> Is it possible to change the value of a variable in the outer function
> if you are in a nested inner function?
The typical kludge is to wrap the variable in the outer function inside
a mutable object, then pass it into the inner using a default argument:
def outer():
Yum, food for thoughts. Thanks Diez.
--
http://mail.python.org/mailman/listinfo/python-list
Thomas Girod wrote:
> Hello there.
>
> I recently started looking at turbogears and I found code such as :
>
> class Root(controllers.Root):
> @turbogears.expose(html="blog.templates.accueil")
> def index(self,**kw):
> return dict()
>
>
> What is this "@" ? I looked around
"Steve Holden" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Ivan Shevanski wrote:
>> python way to detect if a variable exsists? Say I had a program that
>> needed a certain variable to be set to run and the variable was not
>> found when it came time to use it. . .Would I just
Ivan Shevanski wrote:
> Alright first of all I'd like to say I'm a python noob.
>
Welcome to c.l.py.
> Now that thats over with, heres what I'd like to know about. Is there a
> python way to detect if a variable exsists? Say I had a program that
> needed a certain variable to be set to run an
On 1/20/06, Ivan Shevanski <[EMAIL PROTECTED]> wrote:
Alright first of all I'd like to say I'm a python noob.Now that thats over with, heres what I'd like to know about. Is there a python way to detect if a variable exsists? Say I had a program that needed a certain variable to be set to run and
Such a sweet and simple way.
Thanks.
tooper wrote:
> Use os.sep to get / or \ or whatever character used to build pathes on
> the os you're working on
>
--
http://mail.python.org/mailman/listinfo/python-list
Use os.sep to get / or \ or whatever character used to build pathes on
the os you're working on
--
http://mail.python.org/mailman/listinfo/python-list
Quoth Richard Blackwood <[EMAIL PROTECTED]>:
...
| Would you agree that the concept of variables differs in very important
| ways between the domains of math and programming?
No, if "math" means the elementary notions that I have been exposed to
and "very important" means "important to implemento
1 - 100 of 166 matches
Mail list logo