Got a Doubt ! Wanting for your Help ! Plz make it ASAP !

B

Bharath Kummar

Hello Sir/Mam,

Could you please help me with my current research ? Am implementing the
concept in python language.
My doubts are :
1) Is it possible to Retrieve the address of a variable in python ?
2) Is it possible to Delete the Address of the Variable and create a new
dynamic address inside the compiler/interpreter itself ?
3) Is it easy to find the Binary equivalence of a given Alphanumeric
String ?
4) Is it possible to count the number of 1's in the Binary equivalence ?

Could you PLEASE provide me with the codes (codes only for the asked
queries) ?
Your reply counts a lot for me and my research ! I love to explore more in
python.

Awaiting for your Response (Please reply ASAP).

Best,
Bharath
(+91 9025338332)
 
R

Roy Smith

Bharath Kummar said:
Could you please help me with my current research ? Am implementing the
concept in python language.
My doubts are :

[Note to readers of American/British English; Indian English uses
"doubt" the same way we would use "question"]
1) Is it possible to Retrieve the address of a variable in python ?

No. One of the fundamental concepts of Python is that it completely
hides the physical memory. Sure, at some point, when you write

x = 42

it allocates some piece of memory and puts the integer 42 into it, but
all those details are hidden from you (and are implementation specific).

3) Is it easy to find the Binary equivalence of a given Alphanumeric
String ?

I think what you're talking about is the ord() function. Given a single
character (i.e. a string of length 1), it returns the unicode value for
that character. Thus:
88

You could iterate over the characters in a string to find that for each
one:
[77, 121, 32, 115, 116, 114, 105, 110, 103]

4) Is it possible to count the number of 1's in the Binary equivalence ?

This is starting to sound like a homework problem, or possibly an
interview question :)
 
S

Steven D'Aprano

1) Is it possible to Retrieve the address of a variable in python ?

No. Variables in Python are not at fixed addresses, like in Pascal or C,
they are names in a namespace.

You can read this post for some more information about the difference
between C variables and Python variables, and calling conventions across
different languages:

https://mail.python.org/pipermail/tutor/2010-December/080505.html

It's a long post, but to summarise the part about variables:

In languages like Pascal or C, the compiler keeps a table mapping
variable names to fixed memory addresses, like this:

Variable Address
======== =======
x 10234
y 10238
z 10242

The command "x = 42" stores the value 42 into memory address 10234. If
you ask the compiler for the address of x, it can say 10234. That's how
variables work in languages like Pascal, C, Fortran, and similar.

With the Pascal or C style variable, the variable address exists even
before you give it a value.

But languages like Python don't work that way. There is no table of
variable:address available to the compiler, and variables don't have an
address. Python's variables are *name bindings*, not fixed memory
addresses. The Python runtime keeps a global dictionary which maps names
to their values:

{'x': <integer object 42>,
'y': <string object 'hello world'>,
'z': <list object [1,2,3]>,
}

The general name for this is "namespace". In Python you can access the
global namespace with the globals() function, and a read-only copy of the
local namespace with the locals() function.

Entries in the namespace cannot be blank. So names don't exist before
they are bound to a value.

2)
Is it possible to Delete the Address of the Variable and create a new
dynamic address inside the compiler/interpreter itself ?

I don't understand this question.

Since variables don't have addresses, you can't delete what doesn't exist.

3) Is it easy
to find the Binary equivalence of a given Alphanumeric String ?

Which binary equivalence are you referring to? Again, I don't understand
your question. I can do this:

py> astring = "1234"
py> int(astring).to_bytes(4, 'big')
b'\x00\x00\x04\xd2'
py> int(astring).to_bytes(4, 'little')
b'\xd2\x04\x00\x00'


Or I can do this:

py> astring = "Alpha1234 δθЖ∞"
py> astring.encode('utf-8')
b'Alpha1234 \xce\xb4\xce\xb8\xd0\x96\xe2\x88\x9e'


Or I can do this:

py> import binascii
py> binascii.hexlify(b'Hello World!')
b'48656c6c6f20576f726c6421'


And many other string -> binary equivalences. Which ones did you have in
mind?

4) Is it possible to count the number of 1's in the Binary equivalence
?

Of course. First decide which binary equivalence you want, then decide
what you mean by "count the number of 1s" (do you mean the byte with
value 1, or the ASCII code for 1, or the bit 1?), then count them.

Could you PLEASE provide me with the codes (codes only for the asked
queries) ?

If you explain your question in more detail, we can give more detailed
answers.
 
R

rusi

Hello Sir/Mam, 
Could you please help me with my current research ?  Am implementing the concept in python language. 
My doubts are :
1)  Is it possible to Retrieve the address of a variable in python ?
2)  Is it possible to Delete the Address of the Variable and create a new dynamic address inside the compiler/interpreter itself ? 
3)  Is it easy to find the Binary equivalence of a given Alphanumeric String ?
4)  Is it possible to count the number of 1's in the Binary equivalence? 
Could you PLEASE provide me with the codes (codes only for the asked queries) ? 
Your reply counts a lot for me and my research !  I love to explore more in python.

1) id will give you addresses. Except that
- not portable ie not guaranteed to be a m/c address
- its of an object not a variable
- if you are thinking C, its mostly useless

2) del will delete objects -- like free in C
Except that like above, thinking in C will cause more problems than it solves

3,4 I cant make out what you mean
 
G

Grant Edwards

No. Variables in Python are not at fixed addresses, like in Pascal or C,
they are names in a namespace.

You can read this post for some more information about the difference
between C variables and Python variables, and calling conventions across
different languages:

https://mail.python.org/pipermail/tutor/2010-December/080505.html

It's a long post, but to summarise the part about variables:

In languages like Pascal or C, the compiler keeps a table mapping
variable names to fixed memory addresses, like this:

Variable Address
======== =======
x 10234
y 10238
z 10242

FWIW, that's only true for some sorts of variables. Other variables
have an address that is relative to a stack or frame pointer.
 
I

Ian Kelly

2) del will delete objects -- like free in C
Except that like above, thinking in C will cause more problems than it solves

No, del will only delete name bindings. Whether the bound object is
also deleted depends on whether it is still referenced, and the timing
by which the bound object may be deleted varies between
implementations.
 
N

Ned Batchelder

1) id will give you addresses. Except that
- not portable ie not guaranteed to be a m/c address
- its of an object not a variable
- if you are thinking C, its mostly useless

2) del will delete objects -- like free in C
Except that like above, thinking in C will cause more problems than itsolves

Not true: del doesn't delete objects. It merely removes references to objects. Only if the object has no more references is the object deleted.

I tried my hand at explaining how names and values work in Python: http://nedbatchelder.com/text/names.html Some people have found it helpful.

--Ned.
 
D

Denis McMahon

Could you please help me with my current research ? Am implementing the
concept in python language.
My doubts are :
1) Is it possible to Retrieve the address of a variable in python ?
2) Is it possible to Delete the Address of the Variable and create a
new dynamic address inside the compiler/interpreter itself ?
3) Is it easy to find the Binary equivalence of a given Alphanumeric
String ?
4) Is it possible to count the number of 1's in the Binary equivalence
?
Could you PLEASE provide me with the codes (codes only for the asked
queries) ?

The codes are:

1) 7373a28109a7c4473a475b2137aa92d5
2) f2fae9a4ad5ded75e4d8ac34b90d5c9c
3) 935544894ca6ad7239e0df048b9ec3e5
4) b1bc9942d029a4a67e4b368a1ff8d883

Please contact your local government eavesdropping agency for assistance
on decoding the codes.
 
S

Steven D'Aprano

The codes are:

1) 7373a28109a7c4473a475b2137aa92d5
2) f2fae9a4ad5ded75e4d8ac34b90d5c9c
3) 935544894ca6ad7239e0df048b9ec3e5
4) b1bc9942d029a4a67e4b368a1ff8d883

Please contact your local government eavesdropping agency for assistance
on decoding the codes.

I'm not an expert on Indian English, but I understand that in that
dialect it is grammatically correct to say "the codes", just as in UK and
US English it is grammatically correct to say "the programs".

In other words, in UK/US English, "code" in the sense of programming code
is an uncountable noun, like "rice" or "air", while in Indian English it
is a countable noun like cats or programs. We have to say "give me two
samples of code", or perhaps "two code samples", while an Indian speaker
might say "give me two codes".

As this is an international forum, it behoves us all to make allowances
for slight difference in dialect.

Aside: I love the fact that pea, as in green peas or black-eyed peas, is
a back-formation from an uncountable noun. Originally English had the
word "pease", as in "pease porridge hot" from the nursery rhyme. Like
wheat, rice, barley and others, You would have to say something like
"give me a grain of pease" if you only wanted one. Eventually, people
began to assume that "pease", or "peas", was the plural and therefore
"pea" must be the singular. I look forward to the day that "rice" is the
plural of "ri" :)
 
D

Dennis Lee Bieber

Aside: I love the fact that pea, as in green peas or black-eyed peas, is
a back-formation from an uncountable noun. Originally English had the
word "pease", as in "pease porridge hot" from the nursery rhyme. Like
wheat, rice, barley and others, You would have to say something like
"give me a grain of pease" if you only wanted one. Eventually, people
began to assume that "pease", or "peas", was the plural and therefore
"pea" must be the singular. I look forward to the day that "rice" is the
plural of "ri" :)

Rice is the plural of rouse
 
I

Ian Kelly

I'm not an expert on Indian English, but I understand that in that
dialect it is grammatically correct to say "the codes", just as in UK and
US English it is grammatically correct to say "the programs".

I wouldn't necessarily even consider it an Indian thing, as I've known
Americans to use the same phrase.


Rice is the plural of rouse

Not according to the dictionary. But it does seem a more likely
candidate for a hypothetical back formation than "ri", which perhaps
was your point.
 
D

Dennis Lee Bieber

Not according to the dictionary. But it does seem a more likely
candidate for a hypothetical back formation than "ri", which perhaps
was your point.

Mice/Mouse <> Rice/*Rouse
 
S

Steve Simmons

By the same logic the plural of spouse is spice and most men that have had more than one wife will tell you that, whilst it may be the expectation, it ain't necessarily so&nbsp; ;-)
&nbsp;


On 23/11/2013 16:44, Dennis Lee Bieber wrote:




On Fri, 22 Nov 2013 23:42:44 -0700, Ian Kelly &lt;[email protected]&gt; declaimed the following:



On Fri, Nov 22, 2013 at 8:47 PM, Dennis Lee Bieber &lt;[email protected]&gt; wrote:



Rice is the plural of rouse



Not according to the dictionary. But it does seem a more likely candidate for a hypothetical back formation than "ri", which perhaps was your point.



Mice/Mouse &lt;&gt; Rice/*Rouse
 
D

Denis McMahon

I'm not an expert on Indian English, but I understand that in that
dialect it is grammatically correct to say "the codes", just as in UK
and US English it is grammatically correct to say "the programs".

Sorry, I should obviously have replied to the OP as follows:

We don't write your python code for you, we help you to fix your python
code. Please post the code you have developed to solve your problem, and
explain what you expect it to do, and then we will try and explain to you
why it's doing what it does instead of what you want it to.
 
R

Rick Johnson

[snip] I look forward to the day that "rice" is the plural of "ri"

Yes and i look forward to the day when "thread hijacking" perpetrated under the guise of "exploring linguistic minutia" perpetrated under the guise of "vanity" is frowned upon.

PS: The only method chaining going on here is via the .brown_nosing() method.
 
R

Rick Johnson

As this is an international forum, it behoves us all to make allowances
for slight difference in dialect.

I don't thank so. What purpose does that serve?

If we allow people to speak INCORRECT English under the
guise of "political correctness" then no one will benefit.
The speaker will continue using the language improperly and
his audience will continue to be confused.

"But Rick, we don't want to offend people!"

Piss off you spineless invertebrate!I would be more offended
if people did NOT correct me. People "correct" you when they
WANT you to learn, likewise, people "tolerate" you when they
want you to remain inferior.

"Tolerance and apathy are the last virtues of a dying society"

Only those societies with a vision for the future will
survive, that is, until they inevitably grow tired from the
intense competition and lose their vision THEN apathy sets
in and a NEW society steps in to fill the vacuum.

"Competition is the engine that drives the cogs of evolution"

You are all but pawns in a greater game. It is better to die
fighting for SOMETHING, then to wither away intolerant of
NOTHING. There exists no utopia. And any pursuit of such
ends is foolish.

Have you ever even considered what sort of disgusting filth
humans would degenerate into if we achieved a utopia free
from competition? What would we do all day? What purpose
would our lives fulfill?

"Would you eat if you were never hungry?"

Evolution will NEVER allow such a dismal state to prosper,
no, it will stamp out every attempt by convincing the strong
to conquer the weak -- and to do so with extreme prejudice!

The system abhors the weak; the system ridicules the weak;
because the weak serve no end but their own selfish and feeble
attempts to convince themselves they are not but lowly pawns.

"Time to pull your head out of the sand!"

People like you don't want to accept the truth, you want to
believe that "living in harmony" is the answer. No, harmony
is a death wish. If you wish to reach a state of harmony,
then not only are you suicidal but you're homicidal also
because you obviously don't care about your fellow human
beings future progression.

If however, you cared about what really matters, you would
advise our Indian friend to speak better English. By
learning proper English he can become a productive member of
this society -- maybe one day even contributing something
remarkable.

But until his communication can rise above the level of a
3rd grade public school student in rural Kentucky, he is
draining resources instead of creating them!I WANT our Indian
friend to become proficient so that he *might* one day be a
*worthy* advisory for me to challenge.

Anyone can defeat the weak, only the strong have a snowballs
chance in hell to defeat the strong.

"Who said chivalry was dead?"
 
T

Tim Chase

I don't thank so. What purpose does that serve?

If we allow people to speak INCORRECT English under the
guise of "political correctness" then no one will benefit.

"I don't thank so"?

talk about the plank in your own eye...

-tkc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top