On 7 September 2010 08:55, Steven D'Aprano wrote:
> On Mon, 6 Sep 2010 09:03:30 pm Rasjid Wilcox wrote:
>> I've been using
>>
>> for attr_name in name_list:
>> setattr(a, attr_name, getattr(b, attr_name))
>>
>> to copy the attributes from one type of class to another, and it is
>> not quite as
Alrighty! Thanks, everyone!
On Mon, Sep 6, 2010 at 6:48 PM, Steven D'Aprano wrote:
> On Tue, 7 Sep 2010 02:08:27 am Hugo Arts wrote:
>
> > sys.argv is a list of all arguments from the command line. However,
> > you'll rarely deal with it directly, there's various modules that
> > deal with hand
On 2:59 PM, Dominique wrote:
=
but it's really not fun working with this bloody windows console where cut and
paste is impossible...
Cut and paste work fine in a Windows DOS console. Using Properties,
the Options tab, turn on Quick-Edit mode. Once you've done that, you
can select a recta
On Mon, 6 Sep 2010 09:03:30 pm Rasjid Wilcox wrote:
> I've been using
>
> for attr_name in name_list:
> setattr(a, attr_name, getattr(b, attr_name))
>
> to copy the attributes from one type of class to another, and it is
> not quite as readable as I would like.
The one-liner in the for loop is
On Tue, Sep 7, 2010 at 12:44 AM, lists wrote:
>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
>>> doesn't work (as I expected it to) but that mytext[::-1] does.
>>>
>>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work?
>>
>> How does it not "work"? What did
On Tue, 7 Sep 2010 02:08:27 am Hugo Arts wrote:
> sys.argv is a list of all arguments from the command line. However,
> you'll rarely deal with it directly, there's various modules that
> deal with handling arguments. I believe the current one is argparse:
> http://docs.python.org/library/argparse
On Tue, 7 Sep 2010 06:02:39 am ALAN GAULD wrote:
> I wonder if we could create a module that would make v2.7 simulate v3
> to a close degree? hmm... And is it sensible to try, should we not
> perhaps just accept the difference?
from __future__ import print_function, unicode_literals
from future_bu
On Tue, 7 Sep 2010 08:14:59 am lists wrote:
> Hi guys,
>
> Continuing my Python learning, I came across an exercise which asks
> me to take a string and reverse it.
>
> I understand that there is a function to do this i.e mytext.reverse()
You understand wrong :)
There is a function reversed() whi
>>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
>>> doesn't work (as I expected it to) but that mytext[::-1] does.
>>>
>>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work?
>>
>> How does it not "work"? What did you expect to happen? What did it do
>> inste
>> Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
>> doesn't work (as I expected it to) but that mytext[::-1] does.
>>
>> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work?
>
> How does it not "work"? What did you expect to happen? What did it do instead?
>
> Gr
"lists" wrote
Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
doesn't work (as I expected it to) but that mytext[::-1] does.
While that's fine, I just wondered why mytext[-1:-4:-1] doesn't
work?
It does work.
But remember that slices give you the first item to one less
tha
"Dominique" wrote
So, I tried to load the normal 2.5 Idle and unload ('remove')
everything related
to 2.6 from sys.path, but it's strangely not working completely.
How do you start IDLE? Is it via a desktop or start menu shortcut?
If so what is the startin folder specified as?
What happens
"Roelof Wobben" wrote
#
def index_of(val, seq, start=0):
"""
>>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
6
"""
But I get this message :
Failed example:
index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
Expected:
6
Got:
3
#
But in that tuple 5 is
On 7 September 2010 00:14, lists wrote:
> Assuming that mytext is "test", I've found that mytext[-1:-4:-1]
> doesn't work (as I expected it to) but that mytext[::-1] does.
>
> While that's fine, I just wondered why mytext[-1:-4:-1] doesn't work?
How does it not "work"? What did you expect to happ
Hi guys,
Continuing my Python learning, I came across an exercise which asks me
to take a string and reverse it.
I understand that there is a function to do this i.e mytext.reverse()
I imagine that the exercise author would rather I did this the hard
way however. ;-)
Assuming that mytext is "te
On 6 September 2010 21:45, Sander Sweers wrote:
>> Is the exercise here wrong ?
>
> Looks like it, or it's a typo.
Now that I had a better look the test is correct. Now it is up to you
to figure out why your index_of() fails. Walter gave you a good hint.
Greets
Sander
___
>Other than changing the input() to raw_input() for Python 2 compatibility,
>
>
> And of course you can do that using
>
> input = raw_input
>
>
> > the following statement could be added to the beginning of the program
> > to allow your Python 2 program to use the Python 3 style print function.
>
>
On 6 September 2010 22:28, Roelof Wobben wrote:
> As far as I know index is not a part of tuple so I have to convert it to a
> list so I can use index.
As of version 2.6/3 a tuple does have index(). Not sure which version
you are using.
Greets
Sander
_
> Date: Mon, 6 Sep 2010 21:45:17 +0200
> Subject: Re: [Tutor] exercise correct ??
> From: sander.swe...@gmail.com
> To: rwob...@hotmail.com
> CC: tutor@python.org
>
> On 6 September 2010 19:32, Roelof Wobben wrote:
> > def index_of(val, seq, start=0):
> > """
> > >>> index_of(9, [1
> > I think there is a trick in V2.7 to make it act more like v3 but someone
> > else will need to tell you what it is... :-)
>Other than changing the input() to raw_input() for Python 2 compatibility,
And of course you can do that using
input = raw_input
> the following statement could be a
Hi Roelof,
On 6 September 2010 18:32, Roelof Wobben wrote:
>>>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
> 6
>
> But in that tuple 5 is on position 3.
>
> Is the exercise here wrong ?
>
>
Not neccesarily... I notice that the call is similar to the previous test
case, but has an
On 6 September 2010 19:32, Roelof Wobben wrote:
> def index_of(val, seq, start=0):
> """
> >>> index_of(9, [1, 7, 11, 9, 10])
> 3
> >>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5))
> 3
> >>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
> 6
> >>> index_of('y', '
On Mon, Sep 6, 2010 at 1:46 PM, Dominique wrote:
> Hello,
>
> I usually use python 2.6 and several packages. Everything's fine.
>
> At present, I'm trying to run a package which is only available with python
> 2.5.
> So, i installed 2.5 and the various dependencies needed to run this package:
> P
>
>
> Python 2.7 (r27:82525, Jul 4 2010, 09:01:59) [MSC v.1500 32 bit (Intel)]
>> on win32 Type
>> "copyright", "credits" or "license()" for more information.
>>
>>> RESTART
>
What is your name? Keith
>>
>
> I think there
On 06/09/2010 8.34, Roelof Wobben wrote:
Hello,
I have this programm:
...
def make_empty(seq):
"""
>>> make_empty([1, 2, 3, 4])
[]
>>> make_empty(('a', 'b', 'c'))
()
>>> make_empty("No, not me!")
''
"""
word2=""
teller=0
if type(seq) == type([]):
teller=0
while teller < len(seq):
seq[teller]=
"Keith Lucas" wrote
What is wrong with the following, apparently almost straight out of
Python Programming
by Michael Dawson?
You are using Python v2, the tutorial seems to be written for v3.
There are big diffeernces in syntax between them, v3 is NOT
backwards compatible with v2.
# Get
Hello,
I usually use python 2.6 and several packages. Everything's fine.
At present, I'm trying to run a package which is only available with python 2.5.
So, i installed 2.5 and the various dependencies needed to run this package:
PIL, numpy... which were already installed in my 2.6 site-packages
What is wrong with the following, apparently almost straight out of Python
Programming
by Michael Dawson?
# Declare variable and initialise (overkill!).
name = "ABCDEFG"
# Get value.
name = input("What is your name? ")
# Echo value
print(name)
# Issue greeting
print("Hi ", name)
Python 2.7
Hello,
I have this programm :
def index_of(val, seq, start=0):
"""
>>> index_of(9, [1, 7, 11, 9, 10])
3
>>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5))
3
>>> index_of(5, (1, 2, 4, 5, 6, 10, 5, 5), 4)
6
>>> index_of('y', 'happy birthday')
4
On 9/6/2010 11:48 AM, aug dawg wrote:
I've seen Python programs that can be activated from the command line.
For example:
hg
This displays a list of commands for the Mercurial revision control
system. But another command is this:
hg commit "This is a commit name"
Mercurial is written in P
I think you're looking for this:
http://docs.python.org/library/argparse.html
you'll also want to read up on sys.argv
http://docs.python.org/library/sys.html#sys.argv
On Mon, Sep 6, 2010 at 8:48 AM, aug dawg wrote:
> I've seen Python programs that can be activated from the command line. For
On Mon, Sep 6, 2010 at 5:48 PM, aug dawg wrote:
> I've seen Python programs that can be activated from the command line. For
> example:
> hg
>
> This displays a list of commands for the Mercurial revision control system.
> But another command is this:
> hg commit "This is a commit name"
> Mercuria
I've seen Python programs that can be activated from the command line. For
example:
hg
This displays a list of commands for the Mercurial revision control system.
But another command is this:
hg commit "This is a commit name"
Mercurial is written in Python. I know that commit is a function that
On 6 September 2010 19:55, Hugo Arts wrote:
> On Mon, Sep 6, 2010 at 9:27 AM, Rasjid Wilcox wrote:
>> Hi all,
>>
>> Suppose we have
>>
>> class A(object):
>> pass
>>
>> a = A()
>>
>> Is there any difference between
>>
>> setattr(a, 'foo', 'bar)
>>
>> and
>>
>> a.__setattr__['foo'] = 'bar'
>>
>
On Mon, Sep 6, 2010 at 9:27 AM, Rasjid Wilcox wrote:
> Hi all,
>
> Suppose we have
>
> class A(object):
> pass
>
> a = A()
>
> Is there any difference between
>
> setattr(a, 'foo', 'bar)
>
> and
>
> a.__setattr__['foo'] = 'bar'
>
Did you mean a.__setattr__('foo', 'bar')? That's the same thing,
On Mon, Sep 6, 2010 at 9:41 AM, Roelof Wobben wrote:
>
>
>> To: tutor@python.org
>> From: alan.ga...@btinternet.com
>> Date: Mon, 6 Sep 2010 08:27:31 +0100
>> Subject: Re: [Tutor] why do i get None as output
>>
>>
>> "Roelof Wobben" wrote
>>
>> def make_empty(seq):
>> word2=""
>> teller=0
>> if t
> To: tutor@python.org
> From: alan.ga...@btinternet.com
> Date: Mon, 6 Sep 2010 08:27:31 +0100
> Subject: Re: [Tutor] why do i get None as output
>
>
> "Roelof Wobben" wrote
>
> def make_empty(seq):
> word2=""
> teller=0
> if type(seq) == type([]):
> teller=0
> while teller < len(seq):
Hi all,
Suppose we have
class A(object):
pass
a = A()
Is there any difference between
setattr(a, 'foo', 'bar)
and
a.__setattr__['foo'] = 'bar'
other than syntax?
And which is considered 'better' form in Python?
Cheers,
Rasjid.
___
Tutor mai
"Roelof Wobben" wrote
def make_empty(seq):
word2=""
teller=0
if type(seq) == type([]):
teller=0
while teller < len(seq):
seq[teller]=""
teller = teller + 1
elif type(seq) == type(()):
tup2 = list (seq)
while teller > tup2.len()
On Mon, Sep 6, 2010 at 8:34 AM, Roelof Wobben wrote:
> Hello,
>
> I have this programm:
>
> def encapsulate(val, seq):
> if type(seq) == type(""):
> return str(val)
> if type(seq) == type([]):
> return [val]
> return (val,)
>
> def insert_in_middle(val, seq):
> midd
40 matches
Mail list logo