[Beginner] Spliting input
I try to split input numbers, for example: 12 so I cant add them, I
tried separated split(' ') but it's not working.
Any ideas how to do this?
*
numb1,numb2=input("enter 1st and 2nd no ").split()
Avg=(int(numb1) + int(numb2)) / 2
print(Avg)
*
--
Thanks
--
https://mail.python.org/mailman/listinfo/python-list
Re: [Beginner] Spliting input
Without knowing the problem you're having, it's hard to answer.
This seems generally correct.
On Thu, Jun 25, 2020 at 7:57 AM Bischoop wrote:
> I try to split input numbers, for example: 12 so I cant add them, I
> tried separated split(' ') but it's not working.
> Any ideas how to do this?
>
> *
> numb1,numb2=input("enter 1st and 2nd no ").split()
> Avg=(int(numb1) + int(numb2)) / 2
> print(Avg)
>
--
Andrew Bell
[email protected]
--
https://mail.python.org/mailman/listinfo/python-list
Re: [Beginner] Spliting input
On 2020-06-25, Andrew Bell wrote:
> Without knowing the problem you're having, it's hard to answer.
> This seems generally correct.
>
>
Error track:
Traceback (most recent call last):
File "splitting.py", line 1, in
numb1,numb2=input("enter 1st and 2nd no ").split()
ValueError: not enough values to unpack (expected 2, got 1)
--
https://mail.python.org/mailman/listinfo/python-list
Re: [Beginner] Spliting input
On 2020-06-25 2:13 PM, Bischoop wrote:
On 2020-06-25, Andrew Bell wrote:
Without knowing the problem you're having, it's hard to answer.
This seems generally correct.
Error track:
Traceback (most recent call last):
File "splitting.py", line 1, in
numb1,numb2=input("enter 1st and 2nd no ").split()
ValueError: not enough values to unpack (expected 2, got 1)
Without arguments, split() splits on whitespace.
If you entered 2 numbers separated by a comma, but no spaces, there is
no split.
Maybe you meant split(',') which will split on a comma.
Frank Millman
--
https://mail.python.org/mailman/listinfo/python-list
Re: [Beginner] Spliting input
Bischoop wrote:
> I try to split input numbers, for example: 12 so I cant add them, I
> tried separated split(' ') but it's not working.
> Any ideas how to do this?
>
> *
> numb1,numb2=input("enter 1st and 2nd no ").split()
> Avg=(int(numb1) + int(numb2)) / 2
> print(Avg)
> *
>
> --
> Thanks
To split the string "12" into its characters (i. e. the digits "1" and "2")
you don't need the split() method which only works with separators.
Instead you can unpack the digits directly:
>>> a, b = input("enter two digits> ")
enter two digits> 12
>>> a
'1'
>>> b
'2'
>>> (int(a) + int(b)) / 2
1.5
--
https://mail.python.org/mailman/listinfo/python-list
Re: Pycharm offers only implementation of an abstract getter but not an abstract setter
On 24/06/2020 22:46, [email protected] wrote: Why Pycharm didn't offer a setter as well as getter? This is a general Python mailing list. If you have specific questions/complaints about PyCharm, they are probably better addressed directly to the makers of PyCharm. -- Rhodri James *-* Kynesim Ltd -- https://mail.python.org/mailman/listinfo/python-list
Re: Pycharm offers only implementation of an abstract getter but not an abstract setter
You can freely leave Pycharm out of equation. In that case, there is a question how to force subclass to implement setter method? -- https://mail.python.org/mailman/listinfo/python-list
Re: Pycharm Won't Do Long Underscore
On 6/24/20 7:38 PM, Grant Edwards wrote: > On 2020-06-24, Peter J. Holzer wrote: > >> There is U+FF3F Fullwidth Low Line. >> >>> If there were, Python would not know what to do with it >> >> You can use it in variable names, but not at the beginning, and it isn't >> equivalent to two underscores, of course: > > Ouch. Anybody caught using that should be fed to a large snake. Even allowing unicode letters in variable names period is questionable, but that loud debate was over years ago. Fortunately I have never seen any python code in the wild with non-latin characters for variable names. Would make editing code very painful for developers from different locales and keyboards. Even if it might seem novel at first to have π be a variable name. -- https://mail.python.org/mailman/listinfo/python-list
Re: [Beginner] Spliting input
Hi,
On 25/06/2020 12:50, Bischoop wrote:
I try to split input numbers, for example: 12 so I cant add them, I
tried separated split(' ') but it's not working.
Any ideas how to do this?
*
numb1,numb2=input("enter 1st and 2nd no ").split()
Avg=(int(numb1) + int(numb2)) / 2
print(Avg)
So, this is an opportunity to do (and learn) some debugging!
One problem is that the first line does two things at once -- it reads
the input and tries to split it into numb1 and numb2. Similarly for the
"average" line.
You could instead try:
input_string = input("enter 1st and 2nd no ")
print(input_string)
numb1_as_string, numb2_as_string = input_string.split()
print(numb1_as_string, numb2_as_string)
numb1 = int(numb1)
numb2 = int(numb2)
print(numb1, numb2)
avg = (numb1 + numb2) / 2
print(avg)
Now, when if fails on input_string.split() (which I think is what
happens) you can then be sure that you know what the input is. Let's say
it's "17,3". Since you know that, you can experiment:
"17, 3".split() -> "17,", "3" (note extra space)
"17 3".split() -> "17" "3" (aha, getting somewhere)
... and same results for both of these with split(' '), which should
indicate that it's splitting on the space, and you didn't supply a space.
So now maybe try "17,3".split(',') -> "17", "3" (bingo!)
Bonus question: what happens with "17, 3".split(',')?
*
--
Thanks
--
https://mail.python.org/mailman/listinfo/python-list
Re: [Python-ideas] asyncio: return from multiple coroutines
(Resending this email since it didn't originally go through to
python-list, sorry for the duplicate Pablo)
> Yes, I want to have multiple results: the connections listening forever,
> returning a result for each message received.
> I forgot to mention thatI did try to use asyncio.wait with `FIRST_COMPLETED`;
> however, the problem is that it seems to evict the not-completed coroutines,
> so the messenger that arrives second does not send the message. To check it,
> I have run that script without the random sleep. just msgr1 waits 1s and
> msgr2 waits 2s, so msgr1 always ends first. I expect a result like this
> (which I am currently getting with queues):
FYI, the other coroutines are not evicted or cancelled, they are
simply in the "pending" set of the "done, pending" tuple returned by
`asyncio.wait()` and were not returned. I misunderstood what you were
actually looking for, but I think that I understand now.
Since it seems like you want to be able to receive the results out of
order from both "messengers" and have them continuously listen to
their respective socket (without affecting the other), a queue is
likely going to be the best approach. I think you had the right
general idea with your example, but here's a way to make it
significantly less cumbersome and easy to expand upon (such as
expanding the number of websockets to listen to):
```
import asyncio
class MessengerQueue:
def __init__(self):
self._queue = asyncio.Queue()
async def get(self):
return await self._queue.get()
async def start_messengers(self):
# Could be easily modified to create any number of
"messengers" set to
# listen on specific websockets, by passing a list and
creating a task for
# each one.
asyncio.create_task(self._messenger("Messenger 1", 1))
asyncio.create_task(self._messender("Messenger 2", 2))
async def _messenger(self, message: str, sleep_time: int):
while True:
await asyncio.sleep(sleep_time)
await self._queue.put(f'{message} awaited for {sleep_time:.2f}s')
async def main():
mqueue = MessengerQueue()
asyncio.create_task(mqueue.start_messengers())
while True:
result = await mqueue.get()
print(result)
asyncio.run(main())
```
This results in your desired output:
Messenger 1 awaited for 1.00s
Messenger 2 awaited for 2.00s
Messenger 1 awaited for 1.00s
Messenger 1 awaited for 1.00s
Messenger 2 awaited for 2.00s
Messenger 1 awaited for 1.00s
Messenger 1 awaited for 1.00s
Messenger 2 awaited for 2.00s
Note: it would probably be more idiomatic to call these "consumers" or
"listeners" rather than "messengers"/"messagers" (the websocket docs
refer to them as "consumer handlers"), but I used "messengers" to make
it a bit more easily comparable to the original queue example from the
OP: https://pastebin.com/BzaxRbtF.
I hope the above example is of some use. :-)
Regards,
Kyle Stanley
On Thu, Jun 25, 2020 at 1:28 AM Kyle Stanley wrote:
>
> > Yes, I want to have multiple results: the connections listening forever,
> > returning a result for each message received.
>
> > I forgot to mention thatI did try to use asyncio.wait with
> > `FIRST_COMPLETED`; however, the problem is that it seems to evict the
> > not-completed coroutines, so the messenger that arrives second does not
> > send the message. To check it, I have run that script without the random
> > sleep. just msgr1 waits 1s and msgr2 waits 2s, so msgr1 always ends first.
> > I expect a result like this (which I am currently getting with queues):
>
> FYI, the other coroutines are not evicted or cancelled, they are
> simply in the "pending" set of the "done, pending" tuple returned by
> `asyncio.wait()` and were not returned. I misunderstood what you were
> actually looking for, but I think that I understand now.
>
> Since it seems like you want to be able to receive the results out of
> order from both "messengers" and have them continuously listen to
> their respective socket (without affecting the other), a queue is
> likely going to be the best approach. I think you had the right
> general idea with your example, but here's a way to make it
> significantly less cumbersome and easy to expand upon (such as
> expanding the number of websockets to listen to):
>
> ```
> import asyncio
>
> class MessengerQueue:
> def __init__(self):
> self._queue = asyncio.Queue()
>
> async def get(self):
> return await self._queue.get()
>
> async def start_messengers(self):
> # Could be easily modified to create any number of
> "messengers" set to
> # listen on specific websockets, by passing a list and
> creating a task for
> # each one.
> asyncio.create_task(self._messenger("Messenger 1", 1))
> asyncio.create_task(self._messender("Messenger 2", 2))
>
> async def _messenger(self, message: str, sleep_time: int):
> while True:
> await asyncio.sleep(sl
I need to study Python
Hey, I'm a completely noob. I want to learn python, how can i or where can i study python? -- https://mail.python.org/mailman/listinfo/python-list
Re: I need to study Python
Hi, Just sign-up for a local community college. Will be easier and u will keep motivation... Thank you. On Thu, Jun 25, 2020, 6:49 PM wrote: > Hey, I'm a completely noob. > I want to learn python, how can i or where can i study python? > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Regarding error code 9
Sir/Mam; While installing matplotlib in python i face this issue that it shows error : erro no 9 please reply with some solution for this error i am beginner so please explain in detail about this error and guide me to fix this error. Thank you -- https://mail.python.org/mailman/listinfo/python-list
