Print statement
Please help me with this.
squares =input("\nSquares: ")
print(float((squares) *float(.15)) *(1.3))
Cant print answer.
print(float((squares) * float(.15)) *(1.3))
TypeError: can't multiply sequence by non-int of type 'float'
Thx
L Smit
--
https://mail.python.org/mailman/listinfo/python-list
Re: Clarification on Immutability please
Am 27.01.2020 15:23 schrieb Chris Angelico: The way execution works in Python, you first evaluate the object, then assign it to the target. The new object HAS to exist before the old one is replaced. There's no such thing as "atomic reassignment" that simultaneously destroys the old object and assigns a new one. The slicing will always happen first, and then the assignment. Hi Chris, I agree that that is how it's done because it makes sense. My completely academic question is this: If the Python compiler sees that the operation effectively just chops a few items off the end of a tuple which will be immediately discarded I can't see an issue with an implementation simply shortening the length of the tuple. In C this would be an ultra cheap operation, and the pointer to the tuple object (CPython's object ID) would indeed not change. A possible drawback would be waste of memory because the unused tuple items are still around in allocated memory. The introductory comment in tupleobject.h is clear on this subject: "[...] C code can change the tuple items (but not their number) [...]", so this is not how it's done in CPython 3.8.0, but IMO an implementation could legally do this. All this is beside the point of the OP's question. There is no connection between an object's mutability and its ID. -- https://mail.python.org/mailman/listinfo/python-list
Re: Print statement
On 2020-01-28 12:14 PM, L A Smit wrote:
Please help me with this.
squares =input("\nSquares: ")
print(float((squares) *float(.15)) *(1.3))
Cant print answer.
print(float((squares) * float(.15)) *(1.3))
TypeError: can't multiply sequence by non-int of type 'float'
You have some superfluous brackets around 'squares' and '1.3', which
hinder readability.
Remove them and you get -
float(squares * float(.15)) * 1.3
Now you can see that you have the brackets in the wrong place - you are
trying to multiply 'squares', which at this stage is still a string, by
float(.15).
You can multiply a string by an integer, but not by a float -
>>> 'abc' * 3
'abcabcabc'
>>>
>>> 'abc' * 1.5
Traceback (most recent call last):
File "", line 1, in
TypeError: can't multiply sequence by non-int of type 'float'
>>>
You probably meant
float(squares) * float(.15)
or more simply
float(squares) * .15
HTH
Frank Millman
--
https://mail.python.org/mailman/listinfo/python-list
Re: Clarification on Immutability please
On Tue, Jan 28, 2020 at 9:33 PM Daniel Haude wrote: > > Am 27.01.2020 15:23 schrieb Chris Angelico: > > > The way execution works in Python, you first evaluate the object, then > > assign it to the target. The new object HAS to exist before the old > > one is replaced. There's no such thing as "atomic reassignment" that > > simultaneously destroys the old object and assigns a new one. The > > slicing will always happen first, and then the assignment. > > Hi Chris, > > I agree that that is how it's done because it makes sense. My completely > academic question is this: If the Python compiler sees that the > operation effectively just chops a few items off the end of a tuple > which will be immediately discarded I can't see an issue with an > implementation simply shortening the length of the tuple. In C this > would be an ultra cheap operation, and the pointer to the tuple object > (CPython's object ID) would indeed not change. A possible drawback would > be waste of memory because the unused tuple items are still around in > allocated memory. This would be an optimization that would be highly vulnerable, as it would depend on a LOT of knowledge of what's going on. For instance, you would have to know for certain that the surrounding namespace wasn't doing any sort of extra management (eg logging before-and-after on any assignment), and you'd need to be 100% certain that there's no way an exception could occur between the truncation and the reassignment, etc, etc, etc. This is the sort of thing that PyPy might do, but it's not something the language definition supports. > The introductory comment in tupleobject.h is clear on this subject: > "[...] C code can change the tuple items (but not their number) [...]", > so this is not how it's done in CPython 3.8.0, but IMO an implementation > could legally do this. That's more a matter of "C code can violate the rules" than anything else. Nothing to do with language specification. Generally, once a tuple has been "released" into Python code, its members won't be changed. > All this is beside the point of the OP's question. There is no > connection between an object's mutability and its ID. Correct, beyond the fact that immutable objects are open to certain optimizations that are invalid for mutables (for instance, every "[]" in a program will create a new and unique list, but "()" will reference the same empty tuple). ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Clarification on Immutability please
On Wed, Jan 22, 2020, at 02:34, Stephen Tucker wrote: > Oh dear, I am sorry. I have created quite a storm. > > Moreover, I am sorry because I misremembered what I had typed into Idle. My > original tuple only had two elements, not three, so the slicing [:2] didn't > affect the tuple at all - and so the second id() gave the same address as > the first one. > > So, yes, I am stupid - or just having senior moments (I am 65, after all). > > Stephen. Regardless, this is interesting because, even though it is not in fact the case, this would be a valid optimization for an interpreter to perform, and while it's not done, something similar is done when concatenating strings. >>> s = 'asdfghjklmnop' >>> id(s); s += 'x'; id(s) 20405128 27766160 >>> id(s); s += 'x'; id(s) 27766160 27766160 # if this is done repeatedly, the two ids will not always be the same, but they will be quite a bit more often than not. The two tuples, if there are do not exist at the same time, therefore it does not violate any constraint if their ids are the same - ids are only required to be unique for simultaneously existing objects, not across the lifetime of the program. -- https://mail.python.org/mailman/listinfo/python-list
Re: Clarification on Immutability please
On Wed, Jan 29, 2020 at 1:50 AM Random832 wrote: > > On Wed, Jan 22, 2020, at 02:34, Stephen Tucker wrote: > > Oh dear, I am sorry. I have created quite a storm. > > > > Moreover, I am sorry because I misremembered what I had typed into Idle. My > > original tuple only had two elements, not three, so the slicing [:2] didn't > > affect the tuple at all - and so the second id() gave the same address as > > the first one. > > > > So, yes, I am stupid - or just having senior moments (I am 65, after all). > > > > Stephen. > > Regardless, this is interesting because, even though it is not in fact the > case, this would be a valid optimization for an interpreter to perform, and > while it's not done, something similar is done when concatenating strings. > > >>> s = 'asdfghjklmnop' > >>> id(s); s += 'x'; id(s) > 20405128 > 27766160 > >>> id(s); s += 'x'; id(s) > 27766160 > 27766160 > # if this is done repeatedly, the two ids will not always be the same, but > they will be quite a bit more often than not. > > The two tuples, if there are do not exist at the same time, therefore it > does not violate any constraint if their ids are the same - ids are only > required to be unique for simultaneously existing objects, not across the > lifetime of the program. > What you've demonstrated isn't actually the same, though. When you use augmented assignment, it actually CAN be an atomic operation (or, more commonly, a mutating operation - see eg lists); but the original question was about slicing, which can't be done in an augmented assignment statement. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Simple Python github library to push/pull files?
Any recommendations on a library providing a simple interface to Github for basic push/pull type of actions? I know there's a native GitHub RESTful API but wondering if anyone has placed a friendly Python wrapper on top of that interface? PyGithub supports a rich set of actions, but doesn't appear to provide support to push/pull files to/from a repo. Thank you, Malcolm -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple Python github library to push/pull files?
On Wed, Jan 29, 2020 at 3:38 AM Malcolm Greene wrote: > > Any recommendations on a library providing a simple interface to Github for basic push/pull type of actions? I know there's a native GitHub RESTful API but wondering if anyone has placed a friendly Python wrapper on top of that interface? PyGithub supports a rich set of actions, but doesn't appear to provide support to push/pull files to/from a repo. > Possibly because pulling and pushing aren't GitHub operations, they're simple git operations. You might be able to find a Python Git library, but it'd probably be just as easy to subprocess it out directly. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Dynamic Data type assignment
Hi
Please find below example and the compiler error,
when i'm assigning value dynamically and when we comparing in "if" loop it
is throwing compiler error. It should not throw error it should assign and
act as int why it is thinking as string.
*Code Snippet:*
print("Hello World")
num = input("Enter number ")
print(num)
if(num%3 == 0):
num+=num
print(num)
*Output in Console:*
Hello World
Enter number 15
15
Traceback (most recent call last):
File "main.py", line 15, in
if(num%3 == 0):
TypeError: not all arguments converted during string formatting
Created the issue:
msg 360865 created
issue 39476 created
--
Thanks & Regards,
-
Sushma
Mob:9740055884
--
https://mail.python.org/mailman/listinfo/python-list
Re: [docs] Dynamic Data type assignment
input() returns a string. If you want it to be treated as an int you need
to cast it, example:
num =int(input ("Enter number"))
On Tue, Jan 28, 2020, 5:13 AM sushma ms wrote:
> Hi
>
> Please find below example and the compiler error,
>
> when i'm assigning value dynamically and when we comparing in "if" loop it
> is throwing compiler error. It should not throw error it should assign and
> act as int why it is thinking as string.
>
> *Code Snippet:*
> print("Hello World")
>
> num = input("Enter number ")
>
> print(num)
>
> if(num%3 == 0):
> num+=num
> print(num)
>
> *Output in Console:*
> Hello World
> Enter number 15
> 15
> Traceback (most recent call last):
> File "main.py", line 15, in
>if(num%3 == 0):
> TypeError: not all arguments converted during string formatting
> Created the issue:
> msg 360865 created
> issue 39476 created
> --
> Thanks & Regards,
> -
> Sushma
> Mob:9740055884
> ___
> docs mailing list -- [email protected]
> To unsubscribe send an email to [email protected]
> https://mail.python.org/mailman3/lists/docs.python.org/
>
--
https://mail.python.org/mailman/listinfo/python-list
Re: Dynamic Data type assignment
On 28/01/2020 12:03, sushma ms wrote: Hi Please find below example and the compiler error, when i'm assigning value dynamically and when we comparing in "if" loop it is throwing compiler error. It should not throw error It absolutely should throw an error. it should assign and act as int why it is thinking as string. Because it is a string. The documentation of "input" is quite explicit about this: input([prompt]) If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: Simple Python github library to push/pull files?
> On 28 Jan 2020, at 16:40, Chris Angelico wrote: > > On Wed, Jan 29, 2020 at 3:38 AM Malcolm Greene wrote: >> >> Any recommendations on a library providing a simple interface to Github > for basic push/pull type of actions? I know there's a native GitHub RESTful > API but wondering if anyone has placed a friendly Python wrapper on top of > that interface? PyGithub supports a rich set of actions, but doesn't appear > to provide support to push/pull files to/from a repo. >> > > Possibly because pulling and pushing aren't GitHub operations, they're > simple git operations. You might be able to find a Python Git library, but > it'd probably be just as easy to subprocess it out directly. Agreed if you only want to push and pull then running git in a subprocess is what you should do. If you'r needing get more complex have a look at GitPython that's on PyPi. I found it was the best git python library when I did the research my SCM workbench app. Barry > > ChrisA > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Is asyncio.sleep() necessary when yielding?
I'm trying to figure out how the event loop handles switching tasks inside of an async generator, and consequently, the constraints on its calling code. For example: > async def > > > > > > -- https://mail.python.org/mailman/listinfo/python-list
Is asyncio.sleep() necessary when yielding?
(Sorry about the double submission) I'm trying to figure out how the event loop handles switching tasks inside of an async generator, and consequently, the constraints on its calling code. For example: > async def gen(): > for number in range(10 ** 7): > yield number > > > async def consumer(): > numbers = [] > async for number in gen(): > numbers.append(number) > return numbers > The gist of my question is: will consumer block the event loop if iterating over an async generator like the example gen()? In so requiring an await asyncio.sleep(0) call? Or, does the yield statement in an async generator cause the event loop to continue doing the rounds across its scheduled tasks without awaiting asyncio.sleep(0)? -- https://mail.python.org/mailman/listinfo/python-list
Interactively online Python learning environment freely available
Hi, I've made an online python learning environment available at https://p4kweb.appspot.com Please take a look and let me know what you think :-) -- https://mail.python.org/mailman/listinfo/python-list
Re: on sorting things
On 20/12/2019 18:59, Peter Otten wrote: Chris Angelico wrote: On Sat, Dec 21, 2019 at 5:03 AM Peter Otten <[email protected]> wrote: PS: If you are sorting files by size and checksum as part of a deduplication effort consider using dict-s instead: Yeah, I'd agree if that's the purpose. But let's say the point is to have a guaranteed-stable ordering of files that are primarily to be sorted by file size - in order to ensure that two files are in the same order every time you refresh the view, they get sorted by their checksums. One thing that struck me about Eli's example is that it features two key functions rather than a complex comparison. If sort() would accept a sequence of key functions each function could be used to sort slices that compare equal when using the previous key. You don't need a sequence of key functions : the sort algorithm used in Python (tim-sort) is stable - which means if two items (A &B) are in a given order in the sequence before the sort starts, and A & B compare equal during the sort, then after the sort A & B retain their ordering. So if you want to sort by file size as the primary and then by checksum if file sizes are equal - you sort by checksum first, and then by file size: this guarantees that the items will always be in file size order - and if file sizes are equal then they will be ordered by checksum. The rule to remember - is sort in the reverse order of criteria. There ARE good reasons to do weird things with sorting, and a custom key object (either with cmp_to_key or directly implemented) can do that. Indeed. -- https://mail.python.org/mailman/listinfo/python-list
Re: [docs] Dynamic Data type assignment
Thanks a lot.
But why can't we make output of input also dynamic data assignment.
Thanks & Regards,
Sushma MS
On Tue, Jan 28, 2020, 9:54 PM Mariatta wrote:
> input() returns a string. If you want it to be treated as an int you need
> to cast it, example:
>
> num =int(input ("Enter number"))
>
> On Tue, Jan 28, 2020, 5:13 AM sushma ms wrote:
>
>> Hi
>>
>> Please find below example and the compiler error,
>>
>> when i'm assigning value dynamically and when we comparing in "if" loop
>> it is throwing compiler error. It should not throw error it should assign
>> and act as int why it is thinking as string.
>>
>> *Code Snippet:*
>> print("Hello World")
>>
>> num = input("Enter number ")
>>
>> print(num)
>>
>> if(num%3 == 0):
>> num+=num
>> print(num)
>>
>> *Output in Console:*
>> Hello World
>> Enter number 15
>> 15
>> Traceback (most recent call last):
>> File "main.py", line 15, in
>>if(num%3 == 0):
>> TypeError: not all arguments converted during string formatting
>> Created the issue:
>> msg 360865 created
>> issue 39476 created
>> --
>> Thanks & Regards,
>> -
>> Sushma
>> Mob:9740055884
>> ___
>> docs mailing list -- [email protected]
>> To unsubscribe send an email to [email protected]
>> https://mail.python.org/mailman3/lists/docs.python.org/
>>
>
--
https://mail.python.org/mailman/listinfo/python-list
Re: [docs] Dynamic Data type assignment
On 29/01/20 4:51 PM, sushma ms wrote:
Thanks a lot.
But why can't we make output of input also dynamic data assignment.
1 please don't 'top post': the normal sequence of a conversation is
question THEN answer!
2 ambiguity! It is not possible for the input() mechanism to tell
whether you later intend to use the number as int(15) or as "15", ie
str(15).
Thinking about it, what if the user entered "abc" (there's nothing to
stop him/her!); how could that translate to a number? Hence, all input
(one assumes, from the keyboard) is taken to be a string. If you want to
use it otherwise, then programmatically convert the string into a number
(and take care of any errors which may arise).
WebRef: https://docs.python.org/3/library/functions.html#input
Thanks & Regards,
Sushma MS
On Tue, Jan 28, 2020, 9:54 PM Mariatta wrote:
input() returns a string. If you want it to be treated as an int you need
to cast it, example:
num =int(input ("Enter number"))
On Tue, Jan 28, 2020, 5:13 AM sushma ms wrote:
Hi
Please find below example and the compiler error,
when i'm assigning value dynamically and when we comparing in "if" loop
it is throwing compiler error. It should not throw error it should assign
and act as int why it is thinking as string.
*Code Snippet:*
print("Hello World")
num = input("Enter number ")
print(num)
if(num%3 == 0):
num+=num
print(num)
*Output in Console:*
Hello World
Enter number 15
15
Traceback (most recent call last):
File "main.py", line 15, in
if(num%3 == 0):
TypeError: not all arguments converted during string formatting
Created the issue:
msg 360865 created
issue 39476 created
--
Thanks & Regards,
-
Sushma
Mob:9740055884
___
docs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/docs.python.org/
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list
Is there a character that never appears in the output of zlib.compress?
Hi, I'd like to tell what part is zlib.compress data in an input stream. One way is to use some characters that never appear in zlib.compress output to denote the boundary. Are there such characters? Thanks. -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
How to read the original data line by line from stdin in python 3 just like python 2?
Suppose that I use this to read from stdin. But `line` contains decoded data in python 3. In python 2, it contains the original data. What is the best way to get the original data in python 3? Thanks. ``` for line in sys.stdin: ... ``` -- Regards, Peng -- https://mail.python.org/mailman/listinfo/python-list
Re: How to read the original data line by line from stdin in python 3 just like python 2?
On 29/01/20 6:27 pm, Peng Yu wrote: Suppose that I use this to read from stdin. But `line` contains decoded data in python 3. In python 2, it contains the original data. What is the best way to get the original data in python 3? Read from stdin.buffer, which is a stream of bytes. -- Greg -- https://mail.python.org/mailman/listinfo/python-list
