Re: How to solve the given problem?

2022-02-09 Thread Christian Gollwitzer
Am 10.02.22 um 07:40 schrieb NArshad: Assume that there is a pattern of feeding for a special fish in a day (10 hours a day) as below: 150100303030202010 55 Today, the fish is fed in the second hour 60 unit instead of 100 unit

How to solve the given problem?

2022-02-09 Thread NArshad
Assume that there is a pattern of feeding for a special fish in a day (10 hours a day) as below: 150100303030202010 55 Today, the fish is fed in the second hour 60 unit instead of 100 unit Accidently. Implement some methods to d

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread MRAB
On 2022-02-10 01:37, Jen Kris via Python-list wrote: I'm using Python 3.8 so I tried your second choice: pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem); but pSents is 0x0.  pSentMod and pListItem are valid pointers. 'PyObject_CallFunction' looks like a good one to use: """PyObjec

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
I'll do that and post back tomorrow.  The office is closing and I have to leave now (I'm in Seattle).  Thanks again for your help.  Feb 9, 2022, 17:40 by songofaca...@gmail.com: > On Thu, Feb 10, 2022 at 10:37 AM Jen Kris wrote: > >> >> I'm using Python 3.8 so I tried your second choice: >> >

Re: Best way to check if there is internet?

2022-02-09 Thread Avi Gross via Python-list
Actually, you may want a dynamic page. Pages may sometimes be delivered from some cache along the way perhaps within your own company firewall if someone else recently accessed them. Consider a page that returns the current time or like the following asks for an arithmetical calculation to add 5

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
On Thu, Feb 10, 2022 at 10:37 AM Jen Kris wrote: > > I'm using Python 3.8 so I tried your second choice: > > pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem); > > but pSents is 0x0. pSentMod and pListItem are valid pointers. > It means exception happened. If you are writing Python/C fu

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
I'm using Python 3.8 so I tried your second choice: pSents = PyObject_CallFunctionObjArgs(pSentMod, pListItem); but pSents is 0x0.  pSentMod and pListItem are valid pointers.  Feb 9, 2022, 17:23 by songofaca...@gmail.com: > // https://docs.python.org/3/c-api/call.html#c.PyObject_CallNoArgs >

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
// https://docs.python.org/3/c-api/call.html#c.PyObject_CallNoArgs // This function is only for one arg. Python >= 3.9 is required. pSents = PyObject_CallOneArg(pSentMod, pListItem); Or // https://docs.python.org/3/c-api/call.html#c.PyObject_CallFunctionObjArgs // This function can call function

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
Right you are.  In that case should I use Py_BuildValue and convert to tuple (because it won't return a tuple for a one-arg), or should I just convert pListStr to tuple?  Thanks for your help.  Feb 9, 2022, 17:08 by songofaca...@gmail.com: > On Thu, Feb 10, 2022 at 10:05 AM Jen Kris wrote: >

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
On Thu, Feb 10, 2022 at 10:05 AM Jen Kris wrote: > > Thanks for your reply. > > I eliminated the DECREF and now it doesn't segfault but it returns 0x0. Same > when I substitute pListStrE for pListStr. pListStr contains the string > representation of the fileid, so it seemed like the one to use

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
Thanks for your reply.  I eliminated the DECREF and now it doesn't segfault but it returns 0x0.  Same when I substitute pListStrE for pListStr.  pListStr contains the string representation of the fileid, so it seemed like the one to use.  According to  http://web.mit.edu/people/amliu/vrut/pyth

Re: C API PyObject_Call segfaults with string

2022-02-09 Thread Inada Naoki
On Thu, Feb 10, 2022 at 9:42 AM Jen Kris via Python-list wrote: > > I have everything finished down to the last line (sentences = > gutenberg.sents(fileid)) where I use PyObject_Call to call gutenberg.sents, > but it segfaults. The fileid is a string -- the first fileid in this corpus > is "a

C API PyObject_Call segfaults with string

2022-02-09 Thread Jen Kris via Python-list
This is a follow-on to a question I asked yesterday, which was answered by MRAB.   I'm using the Python C API to load the Gutenberg corpus from the nltk library and iterate through the sentences.  The Python code I am trying to replicate is: from nltk.corpus import gutenberg for i, fileid in en

Re: Unpacking lists in a f string

2022-02-09 Thread Kirill Ratkin
Hi. Try this: f"foo {','.join([f'{a} {b}' for a,b in list(zip(l1,l2))])} bar" 09.02.2022 21:13, Paulo da Silva пишет: Às 02:17 de 09/02/22, Paulo da Silva escreveu: Hi! Let's say I have two lists of equal length but with a variable number of elements. For ex.: l1=['a','b','c'] l2=['j','k'

Re: How do you log in your projects?

2022-02-09 Thread Martin Di Paola
- On a line per line basis? on a function/method basis? In general I prefer logging line by line instead per function. It is easy to add a bunch of decorators to the functions and get the logs of all the program but I most of the time I end up with very confusing logs. There are exceptions,

Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-09 Thread Dennis Lee Bieber
On Tue, 8 Feb 2022 23:46:15 -0800 (PST), NArshad declaimed the following: >When I enter data using Tkinter form in an Excel file when the excel file is >closed there is no error but when I enter data using Tkinter form when the >excel is already open following error comes: > >PermissionError:

Re: Unpacking lists in a f string

2022-02-09 Thread Paulo da Silva
Às 02:17 de 09/02/22, Paulo da Silva escreveu: Hi! Let's say I have two lists of equal length but with a variable number of elements. For ex.: l1=['a','b','c'] l2=['j','k','l'] I want to build a string like this "foo a j, b k, c l bar" Is it possible to achieve this with f strings or any ot

Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-09 Thread MRAB
On 2022-02-09 12:45, Christian Gollwitzer wrote: Am 09.02.22 um 08:46 schrieb NArshad: When I enter data using Tkinter form in an Excel file when the excel file is closed there is no error but when I enter data using Tkinter form when the excel is already open following error comes: Permiss

Re: Correct way to setup a package with both compiled C code and Python code?

2022-02-09 Thread Dieter Maurer
Christian Gollwitzer wrote at 2022-2-8 22:43 +0100: >Am 08.02.22 um 18:57 schrieb Dieter Maurer: >> Christian Gollwitzer wrote at 2022-2-7 20:33 +0100: >>> we've developed a Python pacakge which consists of both a compiled >>> extension module and some helper functions in Python. Is there a >>> tut

Re: Best way to check if there is internet?

2022-02-09 Thread Abdur-Rahmaan Janhangeer
> This won't work if you're behind a captive portal: every URL you try to get will return successfully, but the content will be the captive portal page. Yes agree a pretty common scenario if you are moving around ... The solution is to test against a webpage you know the content will always be the

Re: Best way to check if there is internet?

2022-02-09 Thread Abdur-Rahmaan Janhangeer
> Ah, but WHEN do those browsers report that? When attempting to connect to whatever the default "home" page has been set to? (Mine is configured to use https://www.google.com as the default page -- if my router is down, obviously the browser will time-out waiting for a response from Google, and r

Re: Unpacking lists in a f string

2022-02-09 Thread David Lowry-Duda
> l1=['a','b','c'] > l2=['j','k','l'] > > I want to build a string like this > "foo a j, b k, c l bar" > Is it possible to achieve this with f strings or any other > simple/efficient way? Here is a small list of things that want to be done (and natural ways to perform them) 1. pair items in th

Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-09 Thread jkn
On Wednesday, February 9, 2022 at 12:46:49 PM UTC, Christian Gollwitzer wrote: > Am 09.02.22 um 08:46 schrieb NArshad: > > When I enter data using Tkinter form in an Excel file when the excel file > > is closed there is no error but when I enter data using Tkinter form when > > the excel is alrea

Re: Can't get iterator in the C API

2022-02-09 Thread Jen Kris via Python-list
Thank you for clarifying that.  Now on to getting the iterator from the method.  Jen Feb 8, 2022, 18:10 by pyt...@mrabarnett.plus.com: > On 2022-02-09 01:12, Jen Kris via Python-list wrote: > >> I am using the Python C API to load the Gutenberg corpus from the nltk >> library and iterate thr

Re: Best way to check if there is internet?

2022-02-09 Thread Akkana Peck
Abdur-Rahmaan Janhangeer writes: > results = [] > with console.status("Checking internet ...", spinner="dots"): > for domain in domains: > try: > requests.get(domain) > results.append(1) > except Exception as e: > results.append(0) > if not any(results): > print('No internet connection') > sys.exit

Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-09 Thread Christian Gollwitzer
Am 09.02.22 um 08:46 schrieb NArshad: When I enter data using Tkinter form in an Excel file when the excel file is closed there is no error but when I enter data using Tkinter form when the excel is already open following error comes: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'

2022-02-09 Thread NArshad
When I enter data using Tkinter form in an Excel file when the excel file is closed there is no error but when I enter data using Tkinter form when the excel is already open following error comes: Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Dani Brothers\A

Re: Unpacking lists in a f string

2022-02-09 Thread Python
Paulo da Silva wrote: Hi! Let's say I have two lists of equal length but with a variable number of elements. For ex.: l1=['a','b','c'] l2=['j','k','l'] I want to build a string like this "foo a j, b k, c l bar" Is it possible to achieve this with f strings or any other simple/efficient way

Unpacking lists in a f string

2022-02-09 Thread Paulo da Silva
Hi! Let's say I have two lists of equal length but with a variable number of elements. For ex.: l1=['a','b','c'] l2=['j','k','l'] I want to build a string like this "foo a j, b k, c l bar" Is it possible to achieve this with f strings or any other simple/efficient way? Thanks for any help

Re: Best way to check if there is internet?

2022-02-09 Thread Gisle Vanem
Abdur-Rahmaan Janhangeer wrote: It's a demo to get the idea behind, uses requests and the rich library. I'd never heard of 'Rich'. But d/l it and playing with it, I came up with this version with fat green spinner-bar: import requests from rich.console import Console def ensure_internet():

Re: Best way to check if there is internet?

2022-02-09 Thread Abdur-Rahmaan Janhangeer
It's a demo to get the idea behind, uses requests and the rich library. Kind Regards, Abdur-Rahmaan Janhangeer about | blog github Mauritius On Wed, Feb 9, 2022 at 12:24 PM Gisle Vanem wrot

Re: Best way to check if there is internet?

2022-02-09 Thread Gisle Vanem
Abdur-Rahmaan Janhangeer wrote: Thanks everybody for the answers. It was very enlightening. Here's my solution: # using rich console def ensure_internet(): console = Console() domains = [ 'https://google.com', 'https://yahoo.com', 'https://bing.com', 'https://www.ecosia.org', 'https://www.wikip