On 23/06/13 16:18, Jack Little wrote:
I am trying to use random.choice for a text based game. I am using windows 7,
64-bit python. Here is my code:
def lvl2():
print "COMMANDER: Who should you train with?"
trn=random.choice(1,2)
[...]
Here is my error:
File "C:\Users\Jack\Deskto
I am trying to use random.choice for a text based game. I am using windows 7,
64-bit python. Here is my code:
def lvl2():
print "COMMANDER: Who should you train with?"
trn=random.choice(1,2)
if trn==1:
lvl2_1()
print "Squad One!"
elif trn==2:
lvl2_2()
On 23/06/13 05:59, Albert-Jan Roskam wrote:
I was playing around with this a bit and arrived at the following surprising (for me at
least) result. I thought the global/local/nonlocal keywords could be used to get values
from another scope. Though this could also happen implicitly, e.g. if only
On Sun, Jun 23, 2013 at 2:45 AM, Mark Lawrence wrote:
> On 22/06/2013 19:29, Jim Mooney wrote:
>
>> On 22 June 2013 04:00, Steven D'Aprano wrote:
>>
>>
>> Speaking of Java, I get a kick out of this article and love to link to
>>> it on
>>> every possible opportunity:
>>>
>>> http://steve-yegge.b
On 06/22/2013 07:03 PM, Jim Byrnes wrote:
On 06/22/2013 05:10 PM, David Rock wrote:
* Jim Byrnes [2013-06-22 16:01]:
I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.
>>> a = 060713
>>> a[:2]
Traceback (most recent call last):
Fil
On 06/22/2013 05:10 PM, David Rock wrote:
* Jim Byrnes [2013-06-22 16:01]:
I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.
>>> a = 060713
>>> a[:2]
Traceback (most recent call last):
File "", line 1, in
TypeError: 'int' object h
On 06/22/2013 05:01 PM, Jim Byrnes wrote:
I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.
Where is this series of digits coming from? Is it in the source code,
or in a file, or coming from the user, or what? If it's in source code,
a
On Sat, Jun 22, 2013 at 3:59 PM, Albert-Jan Roskam wrote:
>
> I was playing around with this a bit and arrived at the following
> surprising (for me at least) result. I thought the global/local/nonlocal
> keywords could be used to get values from another scope. Though this
> could also happen impl
* Jim Byrnes [2013-06-22 16:01]:
> I need to convert a series of digits like 060713 to a string so I can
> make it look like a date 06-07-13.
>
> >>> a = 060713
> >>> a[:2]
> Traceback (most recent call last):
>File "", line 1, in
> TypeError: 'int' object has no attribute '__getitem__'
>
On 22/06/2013 22:44, Albert-Jan Roskam wrote:
--- Original Message -
From: Jim Byrnes
To: tutor@python.org
Cc:
Sent: Saturday, June 22, 2013 11:01 PM
Subject: [Tutor] How convert an int to a string
I need to convert a series of digits like 060713 to a string so I can
make it look like a
--- Original Message -
> From: Jim Byrnes
> To: tutor@python.org
> Cc:
> Sent: Saturday, June 22, 2013 11:01 PM
> Subject: [Tutor] How convert an int to a string
>
> I need to convert a series of digits like 060713 to a string so I can
> make it look like a date 06-07-13.
>
a = 06
Jim Byrnes wrote:
> I need to convert a series of digits like 060713 to a string so I can
> make it look like a date 06-07-13.
>
> >>> a = 060713
> >>> a[:2]
> Traceback (most recent call last):
>File "", line 1, in
> TypeError: 'int' object has no attribute '__getitem__'
> >>> b = str(a)
On 22/06/13 16:58, eryksun wrote:
In contrast, DIR on CP/M used options in square
brackets, such as the following example:
DIR [DRIVE=B,USER=ALL,EXCLUDE,NOSORT] *.DAT
You are right, CP/M did use square brackets for flags,
I'd forgotten those. But it did have some / switches too.
(or at le
On 22/06/2013 19:29, Jim Mooney wrote:
On 22 June 2013 04:00, Steven D'Aprano wrote:
Speaking of Java, I get a kick out of this article and love to link to it on
every possible opportunity:
http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html
Funny. Speaking of Jav
On 22/06/13 17:56, Sivaram Neelakantan wrote:
list.append(b.get('a'),'c')
Lets look at what this is doing in simplistic terms.
'list' is the class and 'append' is a method of the class.
When we call a method via the class we have to provide the 'self'
argument explicitly so in this case sel
On 22/06/13 12:00, Steven D'Aprano wrote:
Speaking of Java, I get a kick out of this article and love to link to
it on every possible opportunity:
http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html
This could get seriously OT here...
I found that an interesting bl
I need to convert a series of digits like 060713 to a string so I can
make it look like a date 06-07-13.
>>> a = 060713
>>> a[:2]
Traceback (most recent call last):
File "", line 1, in
TypeError: 'int' object has no attribute '__getitem__'
>>> b = str(a)
>>> b[:2]
'25'
>>> b
'25035'
>>>
I wa
> One catch with Python nested scopes is that binding a name defaults to
> the local scope. You can get around this by using a mutable container,
> just as was done with globals before the "global" keyword was added in
> version 0.9.4 (1991). The better solution is a new keyword, but adding
>
> From: Sivaram Neelakantan
>To: tutor@python.org
>Sent: Saturday, June 22, 2013 7:52 PM
>Subject: Re: [Tutor] appending/updating values dict key value pairs
>
>
>On Sat, Jun 22 2013,Mark Lawrence wrote:
>
>
>[snipped 7 lines]
>
>> b = { 'a': [4, 5]}
>>
On 22 June 2013 04:00, Steven D'Aprano wrote:
> Speaking of Java, I get a kick out of this article and love to link to it on
> every possible opportunity:
>
> http://steve-yegge.blogspot.com.au/2006/03/execution-in-kingdom-of-nouns.html
Funny. Speaking of Java, I saw a used book on design patte
On Sat, Jun 22 2013,Mark Lawrence wrote:
[snipped 7 lines]
> b = { 'a': [4, 5]}
> list.append(b.get('a'),'c')
> b
>> {'a': [4, 5, 'c']}
>
>>
>>
>> as in, shouldn't it be
>>
>> b['a'] = list.append(b.get('a'),'c')
>>
>> which doesn't seem to work.
>>
>> sivaram
>> --
>
> b['a'
On 22/06/2013 17:56, Sivaram Neelakantan wrote:
What's the best way to append to the list which is the value to a dict
key?
I did the following based on the docs and I'm not sure why it works
b = { 'a': [4, 5]}
list.append(b.get('a'),'c')
b
{'a': [4, 5, 'c']}
as in, shouldn't it be
b['
What's the best way to append to the list which is the value to a dict
key?
I did the following based on the docs and I'm not sure why it works
>>> b = { 'a': [4, 5]}
>>> list.append(b.get('a'),'c')
>>> b
{'a': [4, 5, 'c']}
>>>
as in, shouldn't it be
b['a'] = list.append(b.get('a'),'c')
wh
On Wed, Jun 19, 2013 at 6:58 PM, Alan Gauld wrote:
> On 19/06/13 17:41, Jim Mooney wrote:
>
>> you should use forward slashes. I have no idea why Bill Gates thought
>> backslashes were kewl
>
> Because MS DOS was copying CP/M which didn't have directory paths
> (it was used with 180K floppy disks
On Sat, Jun 22, 2013 at 7:10 AM, Steven D'Aprano wrote:
> The function attribute "__closure__" is set to None for regular functions.
> For closures, it is set to a bunch of stuff needed for the inner function to
> work correctly. (No user serviceable parts inside.) Basically, the inner
> function
On 06/22/2013 03:47 AM, Alan Gauld wrote:
> On 22/06/13 02:42, Matt D wrote:
>
>> if dlg.ShowModal() == wx.ID_OK:
>> path = dlg.GetPath()
>> mypath = os.path.basename(path)
>> with open(mypath, "a") as f:
>> f.writeli
On 22/06/13 04:17, Matt D wrote:
Hey guys!
Have decided that it is probably going to be better for my purposes to
simply crack open a terminal, cd into the appropriate directory, and do
the 'python test_code.py' or whatever the file name is from the command
line. I feel it is better for me to le
On 22/06/13 12:26, Jim Mooney wrote:
On 21 June 2013 16:56, ALAN GAULD wrote:
if isinstance(dict(),typein):
try: newdict = dict(zip(dl[::2],dl[1::2]))
except TypeError:
raise ValueError("input lists must be an even length")
Not sure why TypeError and ValueError is used. I would
On 22/06/13 17:04, Peter Otten wrote:
This technique of nesting a function inside another function ("closure")
To be pedantic, not all nested functions are closures. Here's one which is not:
def outer(arg):
def inner(x):
return x + 1
assert inner.__closure__ is None
return
On 22/06/13 09:00, Jim Mooney wrote:
On 21 June 2013 14:59, ALAN GAULD wrote:
Give us a clue, show us your code!
I was hoping you wouldn't say that since it's another of my insane
Lazy Typer programs to avoid typing, which are no doubt considered
frivolous. Although I'm learning a lot doing
On 22/06/13 18:09, Jack Little wrote:
Is there a way to keep a global throughout multiple def statements?
Oh, a further thought! Perhaps you mean something like this?
x = 42 # Global value.
def function_one():
global x # Define it once.
code using global x goes here...
def functio
On 22/06/13 11:10, Jim Mooney wrote:
The ultimate in laziness would be to get the program to
append to itself so I,don't have to cut and paste from the
interpreter, but I'm running into some tacky problems. Although some
of them are from the IDE. But others might be from the OS, and there
are di
On 22/06/13 00:32, Wolfgang Maier wrote:
Arijit Ukil tcs.com> writes:
I have following random number generation
function
def
rand_int ():
rand_num = int(math.ceil
(random.random()*1000))
return
rand_num
I like to make the value of rand_num
(return of rand_int) static/ unchanged afte
On 22/06/13 18:09, Jack Little wrote:
Is there a way to keep a global throughout multiple def statements?
I don't understand the question. The only way to *not* keep a global through
multiple def statements is if you delete the global:
x = 1 # Global.
def function_one():
code goes here
Is there a way to keep a global throughout multiple def statements?
___
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
On 22/06/13 02:42, Matt D wrote:
if dlg.ShowModal() == wx.ID_OK:
path = dlg.GetPath()
mypath = os.path.basename(path)
with open(mypath, "a") as f:
f.writelines(self.log_array)
so thats how i used what you said, "wi
On 22/06/13 03:26, Jim Mooney wrote:
if isinstance(dict(),typein):
try: newdict = dict(zip(dl[::2],dl[1::2]))
except TypeError:
raise ValueError("input lists must be an even length")
Not sure why TypeError and ValueError is used.
I used them because that's what I got in my testi
Jim Mooney wrote:
> dictnumfarkadoodle = listnumfarkadoodle = setnumfarkadoodle = 0
> # Since these are global I'm using words not likely to be duplicated
> until I figure a different way and
> # replace 'farkadoodle' with '' ;')
Name clashes are generally not a problem if
(1) you keep module s
38 matches
Mail list logo