Search Results
|
Post |
Author |
Forum |
Replies |
Views |
Posted
[asc]
|
|
|
Thread: Object and type class
Post: Object and type class
Hi, i'm a bit confused about type class and object class. I know that every normal class and built-in type are instance of type class and inherit from object class (is that correct? please correct me ... |
|
Uchikago |
General Coding Help |
2 |
2,239 |
Jul-28-2019, 07:47 AM |
|
|
Thread: Bound method
Post: Bound method
Hi, i'm new to python and i have a quesition about method:
When i try this:
class Test:
def test1():
pass
a=Test()
print(Test.test1)
print(a.test1)It printed out:
<function Test.test1... |
|
Uchikago |
General Coding Help |
1 |
2,144 |
Jul-26-2019, 03:57 PM |
|
|
Thread: List comprehension
Post: List comprehension
Please explain why this doesn't work
seq=[1,2,3]
def a(): return x+2
x=[a() for x in seq]I thought a list comprehension create a new local scope for the expression itself, and when we use a(), x is se... |
|
Uchikago |
General Coding Help |
3 |
2,475 |
Jul-17-2019, 02:46 AM |
|
|
Thread: Lambda function
Post: Lambda function
Hi, i'm a bit confused with this code
x=10
x=lambda : x+2
print(x())because the right side of the '=' is evaluated first so this should have returned 12 rather than reported an error as it did
error:
... |
|
Uchikago |
General Coding Help |
3 |
2,707 |
Jul-16-2019, 02:24 AM |
|
|
Thread: Closure function
Post: RE: Closure function
But, how can python know a function is a closure function and retain the required information ?. I didn't call the multiplier in make_multiplier_of so python doesn't know that i'll use an enclosing sc... |
|
Uchikago |
General Coding Help |
3 |
2,252 |
Jul-11-2019, 10:36 AM |
|
|
Thread: Closure function
Post: Closure function
Closure function doesn't make sense:
def make_multiplier_of(n):
def multiplier(x):
return x * n
return multiplier
times3 = make_multiplier_of(3)
times5 = make_multiplier_of(5)Can any... |
|
Uchikago |
General Coding Help |
3 |
2,252 |
Jul-11-2019, 09:06 AM |
|
|
Thread: Cyclic reference
Post: Cyclic reference
Hi, today i came across this code:
#test1.py
x=1
def change():
import test1
test1.x=2
change()
print(x)output is:
2
1I want to ask why this doesn't make a cyclic reference, since change ... |
|
Uchikago |
General Coding Help |
2 |
2,106 |
Jul-11-2019, 07:17 AM |
|
|
Thread: Sys module
Post: RE: Sys module
(Jul-11-2019, 05:17 AM)Gribouillis Wrote: Why do you want to do this?I'm just experimenting alternative way to use global variable |
|
Uchikago |
General Coding Help |
3 |
2,589 |
Jul-11-2019, 05:30 AM |
|
|
Thread: Sys module
Post: Sys module
can any body explain why this didn't work
#test1.py
var=99
def glob3():
var=0
import sys
glob=sys.modules['test1']
glob.var+=1
glob3()
print(var) #python report an errorBut when i... |
|
Uchikago |
General Coding Help |
3 |
2,589 |
Jul-11-2019, 05:02 AM |
|
|
Thread: Object attribute
Post: RE: Object attribute
Also, if i define a name in a function like this:
def func():
a=2i can't access a from outside even with func.a syntax , but if i define like this
def func():
func.a=2i can access the name wit... |
|
Uchikago |
General Coding Help |
9 |
4,040 |
Jul-06-2019, 11:55 AM |
|
|
Thread: Object attribute
Post: Object attribute
Hi, i'm just a new beginer, so please help me! Today i've come across this syntax module.attribute, i'm wondering what this use for ? And it's syntax looks like when we call method such as list.append... |
|
Uchikago |
General Coding Help |
9 |
4,040 |
Jul-06-2019, 10:31 AM |
|
|
Thread: Namespace and scope difference
Post: RE: Namespace and scope difference
x=50
def func(x):
print(f'X is {x}')
x=200
print(x)
func(x)What about this, it worked because we have a parameter which create a local variable, so when we say Quote:print(f'X is {x}')
... |
|
Uchikago |
General Coding Help |
9 |
4,606 |
Jul-03-2019, 03:36 PM |
|
|
Thread: Namespace and scope difference
Post: RE: Namespace and scope difference
I came accross this:
Quote:In Python, these non-local variables are read only by default and we must declare them explicitly as non-local (using nonlocal keyword) in order to modify them.
This isn't q... |
|
Uchikago |
General Coding Help |
9 |
4,606 |
Jul-03-2019, 03:17 PM |
|
|
Thread: Namespace and scope difference
Post: RE: Namespace and scope difference
(Jul-03-2019, 01:09 PM)ichabod801 Wrote: One function can't access the namespace of the function that called it, as is possible in some other programming languages.I don't understand ! Isn't this a ... |
|
Uchikago |
General Coding Help |
9 |
4,606 |
Jul-03-2019, 01:32 PM |
|
|
Thread: Namespace and scope difference
Post: Namespace and scope difference
I have read through a number of article about this but still can't get a sastified answer, can you guys help me!
What is the relationship between "Namespace" and "scope" can we say a scope is a super... |
|
Uchikago |
General Coding Help |
9 |
4,606 |
Jul-03-2019, 12:57 PM |
|
|
Thread: string slicing default value
Post: string slicing default value
If a slice with positive step like [::1] then the default value of starting point and ending point is [0:len(list):1] but the default values for negative step like [::-1] is [len(list)-1:None:-1] Is t... |
|
Uchikago |
General Coding Help |
1 |
2,820 |
Jul-01-2019, 09:30 AM |
|
|
Thread: string formatting
Post: string formatting
Hi, i want to ask that when using string formatting:
>>> b={1:'a','1':'c'}
>>> print('%(1)s abcd' % b)
c abcdHow can we refer to the keys 1 (has value 'a') not the key '1' (has 'c' v... |
|
Uchikago |
General Coding Help |
1 |
1,933 |
Jun-28-2019, 03:17 PM |
|
|
Thread: string slicing
Post: string slicing
Hi, i just want to ask what is the default begining point and the ending point of a slice with negative step like this
X='123456789'
print(X[::-1])I try to find what exactly begining point and ending... |
|
Uchikago |
General Coding Help |
2 |
2,399 |
Jun-28-2019, 03:01 AM |
|
|
Thread: python cache for small integer
Post: python cache for small integer
I know there is a cache to hold for small integers [-5,256] but when i try to get reference count for a big number like:
>>> import sys
>>> sys.getrefcount(2323232323)
3
>>>... |
|
Uchikago |
General Coding Help |
1 |
2,499 |
Jun-27-2019, 04:30 PM |
|
|
Thread: Escape sequences display in python
Post: Escape sequences display in python
Can you guys explain why both \n and \b are escape sequences but why \n displays as '\n' but \b displays as '\x08'
>>> '\n'
'\n'
>>> '\b'
'\x08' |
|
Uchikago |
General Coding Help |
1 |
2,432 |
Jun-27-2019, 02:57 PM |