Hello, Peter.
I checked my sys.stdout.encoding and it prints:
>>> import sys
>>> sys.stdout.encoding
'cp1252'
Sometimes IDLE tells me I'm using characters that might not work
if I don't place this at the beginning of my script:
# -*- coding: cp1252 -*-
Other than that, I have not made any change
Alex Baraibar wrote:
> I just wish I understood better what happened and why. I've looked into
> the Unicode section of the official docs, but I probably need to study it
> more in order to fully understand it, so...
Just in case you didn't come across it, there's a howto that covers the
basics:
Hi all,
I have a card class. A card object simply consists of a pair of
numbers; 0,0 might be the ace of clubs, for example. I have a toString
method in my card class. Is there a way to just say str(card) instead
of card.toString()? Maybe some sort of basic, built-in function to
override? TIA. Oh,
On Thu, Aug 5, 2010 at 12:37 AM, Alex Hall wrote:
> Hi all,
> I have a card class. A card object simply consists of a pair of
> numbers; 0,0 might be the ace of clubs, for example. I have a toString
> method in my card class. Is there a way to just say str(card) instead
> of card.toString()? Maybe
You could write __str__ function
>>> class card(object):
... def __init__(self, card1, card2):
... self.card1, self.card2 = card1, card2
... def __str__(self):
... return str(str(self.card1)+','+str(self.card2))
...
>>> a = card(0,0)
>>> str(a)
'0,0'
On Wed, Aug 4,
It worked, thanks. Is there a list of these functions somewhere? That
is, the functions that map implicitly to operators or implied uses?
For example, printing will call __str__, as will a cal to str(). What
about math or comparison operators? I have heard of __eq__, __gt__,
and so on, but I tried
Am 04.08.2010 17:37, schrieb Alex Hall:
It worked, thanks. Is there a list of these functions somewhere? That
is, the functions that map implicitly to operators or implied uses?
For example, printing will call __str__, as will a cal to str(). What
about math or comparison operators? I have heard
These are special method names.
View section 3.4 and below here
http://docs.python.org/reference/datamodel.html
On Wed, Aug 4, 2010 at 11:37 AM, Alex Hall wrote:
> It worked, thanks. Is there a list of these functions somewhere? That
> is, the functions that map implicitly to operators or impl
Thanks, and I also see what I did wrong with my __eq__ function.
On 8/4/10, Huy Ton That wrote:
> These are special method names.
>
> View section 3.4 and below here
>
> http://docs.python.org/reference/datamodel.html
>
> On Wed, Aug 4, 2010 at 11:37 AM, Alex Hall wrote:
>
>> It worked, thanks.
Hi,
I'm trying to understand the syntax for reflection in python. I was wondering
about this.
From the example on diveintopython:
http://diveintopython.org/power_of_introspection/index.html
import statsout
def output(data, format="text"):
output_function = getattr(statsout, "output_%s"
I'm trying this example from python docs:
from time import gmtime, strftime
strftime("%a, %d %b %Y %H:%M:%S +", gmtime())
Output = 'Wed, 04 Aug 2010 17:58:42 +'
Is not there a string formatting option for the day without a leading
zero? Like: 'Wed, 4 Aug 2010 17:58:42 +'
It looks like
There are a few solutions here:
http://stackoverflow.com/questions/904928/python-strftime-date-decimal-remove-0
Eric
On Wed, Aug 4, 2010 at 1:30 PM, Eduardo Vieira wrote:
> I'm trying this example from python docs:
> from time import gmtime, strftime
> strftime("%a, %d %b %Y %H:%M:%S +", g
Hey Huy,
thanks. But what is the first parameter in this case? (Note there is nothing
here I'm trying to accomplish except understand).
In the original example, 'statsout' is the name of the module. In this case
there is no module so why can you substitute 'output_text'?
thanks,
Pete
On 2010
On Wed, Aug 4, 2010 at 2:45 PM, Eric Hamiter wrote:
> There are a few solutions here:
>
>
> http://stackoverflow.com/questions/904928/python-strftime-date-decimal-remove-0
>
> Eric
>
>
>
> On Wed, Aug 4, 2010 at 1:30 PM, Eduardo Vieira wrote:
>
>> I'm trying this example from python docs:
>> from
*You can do like below Pete. Where globals has a reference to all
functions in this space.*
def output(data, format="text"):
output_function = getattr(globals()['FUNCTION'], "output_%s" %
format, statsout.output_text)
return output_function(data)
On Wed, Aug 4, 2010 at 3:18 PM, Pete wr
On 8/4/2010 1:23 PM, Pete wrote:
Hi,
I'm trying to understand the syntax for reflection in python. I was
wondering about this.
From the example on diveintopython:
http://diveintopython.org/power_of_introspection/index.html
import statsout
def output(data, format="text"):
output_func
Oh, that's right, I should have tried to example in the interpreter instead
of in my head:P
Say Bob,
Is that the preferred method over something like:
>>> import __main__ as main
On Wed, Aug 4, 2010 at 3:32 PM, bob gailer wrote:
> On 8/4/2010 1:23 PM, Pete wrote:
>
> Hi,
>
> I'm trying to u
On 8/4/2010 3:44 PM, Huy Ton That wrote:
Oh, that's right, I should have tried to example in the interpreter
instead of in my head:P
Say Bob,
Is that the preferred method over something like:
I would prefer to create a class and make these functions class methods.
class A:
def output_text
On Wed, Aug 4, 2010 at 12:45 PM, Eric Hamiter wrote:
> There are a few solutions here:
>
> http://stackoverflow.com/questions/904928/python-strftime-date-decimal-remove-0
>
> Eric
>
>
> On Wed, Aug 4, 2010 at 1:30 PM, Eduardo Vieira
> wrote:
>>
>> I'm trying this example from python docs:
>> from
On 8/4/2010 4:04 PM, bob gailer wrote:
On 8/4/2010 3:44 PM, Huy Ton That wrote:
Oh, that's right, I should have tried to example in the interpreter
instead of in my head:P
Say Bob,
Is that the preferred method over something like:
I would prefer to create a class and make these functions cl
Hi all,
Further to my questions about overriding builtin methods earlier, how
would I make a class able to be accessed and changed using index
notation? For example, take the following:
deck=CardPile(52) #creates a new deck of cards
print(len(deck)) #prints 52, thanks to my __len__ function
for c i
> Hi all,
> Further to my questions about overriding builtin methods earlier, how
> would I make a class able to be accessed and changed using index
> notation? For example, take the following:
> deck=CardPile(52) #creates a new deck of cards
> print(len(deck)) #prints 52, thanks to my __len__ func
I have a side question,
I am using python 2.7.
Why do you use class A: instead of class A(object): ?
-Huy
On Wed, Aug 4, 2010 at 4:08 PM, bob gailer wrote:
> On 8/4/2010 4:04 PM, bob gailer wrote:
>
>> On 8/4/2010 3:44 PM, Huy Ton That wrote:
>>
>>> Oh, that's right, I should have tried to ex
class A:
def call_by_name(self, func, data):
f = A.__dict__.get(func, self.output_text)
return f(data)
def output_text(self, data):return data
def output_hex(self, data):return '\\x' + data
a = A()
data = 'bar'
print a.call_by_name('output_text', data)
print a.call_by_name('output_he
On Wed, Aug 4, 2010 at 4:17 PM, Alex Hall wrote:
> Hi all,
> Further to my questions about overriding builtin methods earlier, how
> would I make a class able to be accessed and changed using index
> notation? For example, take the following:
> deck=CardPile(52) #creates a new deck of cards
> pri
On 8/4/10, Jerry Hill wrote:
> On Wed, Aug 4, 2010 at 4:17 PM, Alex Hall wrote:
>
>> Hi all,
>> Further to my questions about overriding builtin methods earlier, how
>> would I make a class able to be accessed and changed using index
>> notation? For example, take the following:
>> deck=CardPile(
>>> Further to my questions about overriding builtin methods earlier, how
>>> would I make a class able to be accessed and changed using index
>>> notation? For example, take the following:
>>> deck=CardPile(52) #creates a new deck of cards
>>> print(len(deck)) #prints 52, thanks to my __len__ func
On 8/4/10, Evert Rol wrote:
Further to my questions about overriding builtin methods earlier, how
would I make a class able to be accessed and changed using index
notation? For example, take the following:
deck=CardPile(52) #creates a new deck of cards
print(len(deck)) #pr
On 4 Aug 2010, at 23:28 , Alex Hall wrote:
> On 8/4/10, Evert Rol wrote:
> Further to my questions about overriding builtin methods earlier, how
> would I make a class able to be accessed and changed using index
> notation? For example, take the following:
> deck=CardPile(52) #cr
On Wed, Aug 4, 2010 at 5:28 PM, Alex Hall wrote:
> Here is my init, not half as pretty as yours, but it should work.
> Maybe this will explain the problem.
>
> def __init__(self, size, cards=None, fill=False):
> #creates a pile of cards. If "fill"==true, it will auto-fill the
> pile starting fro
Alex Hall wrote:
On 8/4/10, Evert Rol wrote:
That depends how you create the Pile of 52 cards: list(52) also doesn't
generate 52 (random) items.
If you override __init__ to accept an integer that generates the cards for
you, this should work.
Here is my init, not half as pretty as you
> > But, the issue is, I have many places where I write to the database and
> > would have to embed each of these in a try/except block. I can do that,
> > but wondered if there is a "global" way to catch this 'database is locked'
> > error? I found someone asking this sort of question onlin
On 8/4/10, Dave Angel wrote:
> Alex Hall wrote:
>> On 8/4/10, Evert Rol wrote:
>>
>>>
>>> That depends how you create the Pile of 52 cards: list(52) also doesn't
>>> generate 52 (random) items.
>>> If you override __init__ to accept an integer that generates the cards
>>> for
>>> you, this shoul
Suppose i have this string:
z = 'AT/CG'
How do i get this list:
zlist = ['A','T/C','G']
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
34 matches
Mail list logo