unexpected behavior: did i create a pointer?
hi to all!
after two days debugging my code, i've come to the point that the
problem was caused by an unexpected behaviour of python. or by lack of
some information about the program, of course! i've stripped down the
code to reproduce the problem:
a = {}
for x in range(10):
for y in range(10):
a[x,y] = "0"
copyOfA = a
def functionA(x,y):
print a[x,y],
copyOfA[x,y] = "*"
print a[x,y],copyOfA[x,y]
for x in range(10):
for y in range(10):
functionA(x,y)
now, in the second "for" cycle and in functionA() i only 'touch' copyOfA
(altering it). as i don't touch the variable "a", i expect it not to be
affected by any change, but copyOfA acts like a pointer to a and
altering copyOfA's values result in altering the values of "a", so the
result that i expect is:
0 0 *
0 0 *
0 0 *
0 0 *
[..]
but i get:
0 * *
0 * *
0 * *
0 * *
[..]
what's going on?
thanks in advance.
--
http://mail.python.org/mailman/listinfo/python-list
Class behaving like a static class
Hi to all,
i have a module (a single .py file, actually), with a class called
HashedDir.
when i import the file and instanciate 2 instances of that class, when i
check the object's fields they're always the same, even if the two
objects should be different.
Eg:
h1 = HashedDir('someValue')
print h1.value # someValue
h2 = HashedDir('someOtherValue')
print h1.value # someOtherValue
print h2.value # someOtherValue
Any idea?
Thanks in advance
--
http://mail.python.org/mailman/listinfo/python-list
Line completion with custom commands
Hi, my Python program can be launched with a range of different options (or subcommands) like: $ myProgram doSomething $ myProgram doSomethingElse $ myProgram nowDoSomethingDifferent I want it to use auto-completion with so that if i type "myProgram d" it returns "myProgram doSomething" and if i type "myProgram n" it renders "myProgram nowDoSomethingDifferent". This is similar to the average use of the module rlcompleter, but it does not pick possible completion options from the filesystem (or from history) but from a custom set of strings (that correspond to the available options for my program) Any idea on how to implement this? I'm aware of the variable PYTHONSTARTUP (that should point to a file I don't know how to write). As a working example, django-admin (from the django package) has the same exact feature i'm looking for -- http://mail.python.org/mailman/listinfo/python-list
Re: Line completion with custom commands
Steve Holden wrote: gu wrote: Hi, my Python program can be launched with a range of different options (or subcommands) like: $ myProgram doSomething $ myProgram doSomethingElse $ myProgram nowDoSomethingDifferent I want it to use auto-completion with so that if i type "myProgram d" it returns "myProgram doSomething" and if i type "myProgram n" it renders "myProgram nowDoSomethingDifferent". This is similar to the average use of the module rlcompleter, but it does not pick possible completion options from the filesystem (or from history) but from a custom set of strings (that correspond to the available options for my program) Any idea on how to implement this? I'm aware of the variable PYTHONSTARTUP (that should point to a file I don't know how to write). As a working example, django-admin (from the django package) has the same exact feature i'm looking for The issue here is that Python doesn't get control until afer you've hit RETURN on the command line. so nothing you can do in your program or interpreter setup will have any effect on how the command shell behaves. regards Steve I see, but how does django-admin work, then? -- http://mail.python.org/mailman/listinfo/python-list
Re: Line completion with custom commands
Marco Mariani wrote: gu wrote: I see, but how does django-admin work, then? from bash: complete -W "doSomething doSomethingElse doSomethingDifferent" myProgram This worked like a charm, thank you so much. Is this available for bash only or any shell? -- http://mail.python.org/mailman/listinfo/python-list
