python39.dll not found

2021-09-30 Thread jitendrabeura001
   Please someone help me to find the solution for the problem
   Whenever I am trying to run python idle after installing, it is showing
   me-
   [1]python.exe - Syntax Error
   The code execution cannot proceed because [2]python39.dll was not found.
   Re-installing the program may fix the problem.

References

   Visible links
   1. http://python.exe/
   2. http://python39.dll/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to pass a method as argument?

2021-09-30 Thread Mats Wichmann

On 9/29/21 23:11, Anil Anvesh wrote:

I want to write a python calculator program that has different methods to add, 
subtract, multiply which takes 2 parameters. I need to have an execute method 
when passed with 3 parameters, should call respective method and perform the 
operation. How can I achieve that?




let me add - this is probably not the place you are in your Python 
learning, so don't worry about this, but the operator module is designed 
for these kind of usages, when you want to pass an operator like + - 
etc. but of course can't pass the op itself to take actions because it's 
not a callable - the operator module has callables that can be used.



--
https://mail.python.org/mailman/listinfo/python-list


Re: How to pass a method as argument?

2021-09-30 Thread dn via Python-list
On 30/09/2021 18.11, Anil Anvesh wrote:
> I want to write a python calculator program that has different methods to 
> add, subtract, multiply which takes 2 parameters. I need to have an execute 
> method when passed with 3 parameters, should call respective method and 
> perform the operation. How can I achieve that?
> 
> 
> 
> class calc():
> def __init__(self,a,b):
> self.a=a
> self.b=b
> 
> def ex(self,fun):
> self.fun=fun
> if fun=="add":
> self.add()
> 
> def add(self):
> return self.a+self.b
> def sub(self):
> return self.a-self.b
> def mul(self):
> return self.a*self.b
> def div (self):
> return self.a/self.b
> def execu(
> obj1=calc()
> obj1.execu("add",1,,2)
>

This is a common course-assignment.

NB the code-examples below are incomplete. You may need to research
these techniques further, and thus learn how 'it' all fits-together
(I set 'homework' rather than doing it!)


There are several techniques which can be employed and/or combined here.
1 if-elif 'ladder'
2 dict[ionary] as select/case construct
3 functions as 'first-class objects'

The basic problem is to take a 'command' which is formatted as a
str[ing], and decide which of several options to choose:

1 if-elif is a simple and easy-to-read solution:

if command == "add":
do_this...
elif command == "sub":
do_that...
...
else:
# oops: "I'm afraid I can't do that, Dave"
# don't forget to add a 'catch-all' to handle user-error!

2 using a dict is shorter and avoids some of the 'boiler-plate'
repetition which causes many of us to rebel against using the above. We
use the command received from the user as a key into the dict.

3 a function and/or its name is as much data as the 'variable' "command"
or indeed the str-constant "add" - once it has been defined! Thus it is
possible to treat functions like anything else:

data_as_string = "my string"
# can be likened to:-
def my_function(): pass
data_as_function = my_function

Note that (like most else), the function must be defined before it can
be 'used'!

Returning to the stated-problem:

def add( etc ): ...

then using the if-elif 'ladder' above as a framework create a dict which
'links' the input command (as str) to the applicable function:

calculator = { "add": add,
   "sub": sub,
# indeed we can become rather more 'creative'
   "+" " add,
   ...
   }

Thereafter, we can apply the dict to solve the problem:

calculator.get( command,
"Error message/advice, eg mentioning add, or + etc"
)


NB it has been left to you to perfect the technique so that the value(s)
to be calculated are properly communicated to the chosen function.

PS you may find the Python-Tutor Discussion List helpful
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


RE: How to pass a method as argument?

2021-09-30 Thread Avi Gross via Python-list
Sounds like an excellent homework question.

But your method of using an object is not what first comes to mind based on
your cursory description.

There is a python idiom using functional programming that looks like this:

def doit(a, b, fun): return(fun(a,b))

So make up your own functions like:

def addit(a,b): return(a+b)

And make up others doing multiply and whatever and call something like this:

doit(3,5, addit)

 Now if you want a user to put in text like "add" that is another story. If
you want this in the context of an object, ditto.


-Original Message-
From: Python-list  On
Behalf Of Anil Anvesh
Sent: Thursday, September 30, 2021 1:11 AM
To: python-list@python.org
Subject: How to pass a method as argument?

I want to write a python calculator program that has different methods to
add, subtract, multiply which takes 2 parameters. I need to have an execute
method when passed with 3 parameters, should call respective method and
perform the operation. How can I achieve that?



class calc():
def __init__(self,a,b):
self.a=a
self.b=b

def ex(self,fun):
self.fun=fun
if fun=="add":
self.add()

def add(self):
return self.a+self.b
def sub(self):
return self.a-self.b
def mul(self):
return self.a*self.b
def div (self):
return self.a/self.b
def execu(
obj1=calc()
obj1.execu("add",1,,2)
-- 
https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definitive guide for Regex

2021-09-30 Thread Barry Scott



> On 30 Sep 2021, at 19:35, dn via Python-list  wrote:
> 
> On 01/10/2021 06.16, Barry Scott wrote:
>> 
>> 
>>> On 30 Sep 2021, at 12:29, Shaozhong SHI  wrote:
>>> 
>>> Dear All,
>>> 
>>> I am trying to look for a definitive guide for Regex in Python.
>>> Can anyone help?
>> 
>> Have you read the python docs for the re module?
> 
> 
> I learned from Jeffrey Friedl's book "Mastering Regular Expressions",
> but that was in a land far away, last century, and under a different
> language (and the original version - I see it's now up to its third
> edition).
> 
> Despite their concise exercise of power (and the fact that in my
> Python-life I've never been put into a corner where I absolutely must
> use one), I'm no longer a fan...

Agreed, regex is the last tool I reach for in python code.
I find I use split() a lot to break up strings for processing.
But there are cases where a regex is the best tool for a particular job
and I then use the re module. But it costs in maintainability.

I speak as the author of a regex engine and know how to write scary
regex's when the need arises.

Barry


> -- 
> Regards,
> =dn
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definitive guide for Regex

2021-09-30 Thread dn via Python-list
On 01/10/2021 06.16, Barry Scott wrote:
> 
> 
>> On 30 Sep 2021, at 12:29, Shaozhong SHI  wrote:
>>
>> Dear All,
>>
>> I am trying to look for a definitive guide for Regex in Python.
>> Can anyone help?
> 
> Have you read the python docs for the re module?


I learned from Jeffrey Friedl's book "Mastering Regular Expressions",
but that was in a land far away, last century, and under a different
language (and the original version - I see it's now up to its third
edition).

Despite their concise exercise of power (and the fact that in my
Python-life I've never been put into a corner where I absolutely must
use one), I'm no longer a fan...
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


python.exe - System Error

2021-09-30 Thread jitendrabeura001
   please guide me to out from this difficulties, whenever I'm trying to
   install python idle it is showing me the error called [1]python.exe -
   System Error
   I have tried couple of ways to get rid out of this but failed every time,
   please please help me to find the exact solution for this problem. Thank
   You

References

   Visible links
   1. http://python.exe/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Definitive guide for Regex

2021-09-30 Thread Barry Scott



> On 30 Sep 2021, at 12:29, Shaozhong SHI  wrote:
> 
> Dear All,
> 
> I am trying to look for a definitive guide for Regex in Python.
> Can anyone help?

Have you read the python docs for the re module?

Barry

> 
> Regards,
> 
> David
> -- 
> https://mail.python.org/mailman/listinfo/python-list
> 

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to pass a method as argument?

2021-09-30 Thread jitendrabeura001
   Please help me to out from this difficulties, whenever I'm trying to
   install python idle it is showing me the error called "[1]python.exe -
   System Error"**
   I have tried couple of ways to get rid out of this but failed every time,
   please please help me to find the exact solution for this problem. Thank
   You
   Sent from OPPO Mail
   On Edmondo Giovannozzi , 30 Sep 2021 20:34
   wrote:

References

   Visible links
   1. http://python.exe/
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to pass a method as argument?

2021-09-30 Thread Edmondo Giovannozzi
Il giorno giovedì 30 settembre 2021 alle 07:11:28 UTC+2 anila...@gmail.com ha 
scritto:
> I want to write a python calculator program that has different methods to 
> add, subtract, multiply which takes 2 parameters. I need to have an execute 
> method when passed with 3 parameters, should call respective method and 
> perform the operation. How can I achieve that? 
> 
> 
> 
> class calc(): 
> def __init__(self,a,b): 
> self.a=a 
> self.b=b 
> 
> def ex(self,fun): 
> self.fun=fun 
> if fun=="add": 
> self.add() 
> 
> def add(self): 
> return self.a+self.b 
> def sub(self): 
> return self.a-self.b 
> def mul(self): 
> return self.a*self.b 
> def div (self): 
> return self.a/self.b 
> def execu( 
> obj1=calc() 
> obj1.execu("add",1,,2)

For example:

|def ex(self, fun):
|getattr(self, fun)()
-- 
https://mail.python.org/mailman/listinfo/python-list


How to pass a method as argument?

2021-09-30 Thread Anil Anvesh
I want to write a python calculator program that has different methods to add, 
subtract, multiply which takes 2 parameters. I need to have an execute method 
when passed with 3 parameters, should call respective method and perform the 
operation. How can I achieve that?



class calc():
def __init__(self,a,b):
self.a=a
self.b=b

def ex(self,fun):
self.fun=fun
if fun=="add":
self.add()

def add(self):
return self.a+self.b
def sub(self):
return self.a-self.b
def mul(self):
return self.a*self.b
def div (self):
return self.a/self.b
def execu(
obj1=calc()
obj1.execu("add",1,,2)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: XLRDError: Unsupported format, or corrupt file: Expected BOF record; found b'\r\n\r\n\r\n\r\n'

2021-09-30 Thread hongy...@gmail.com
On Thursday, September 30, 2021 at 9:20:37 AM UTC+8, hongy...@gmail.com wrote:
> On Thursday, September 30, 2021 at 5:20:04 AM UTC+8, Peter J. Holzer wrote: 
> > On 2021-09-29 01:22:03 -0700, hongy...@gmail.com wrote: 
> > > I tried to convert a xls file into csv with the following command, but 
> > > failed: 
> > > 
> > > $ in2csv --sheet 'Sheet1' 2021-2022-1.xls 
> > > XLRDError: Unsupported format, or corrupt file: Expected BOF record; 
> > > found b'\r\n\r\n\r\n\r\n' 
> > > 
> > > The above testing file is located at here [1]. 
> > > 
> > > [1] https://github.com/hongyi-zhao/temp/blob/master/2021-2022-1.xls 
> > Why is that file name .xls when it's obviously an HTML file?
> Good catch! Thank you for pointing this out. This file is automatically 
> exported from my university's teaching management system, and it was assigned 
> the .xls extension by default. 

According to the above comment, after I change the extension to html, the 
following python code will do the trick:


import sys
import pandas as pd

if len(sys.argv) != 2:
print('Usage: ' + sys.argv[0] + ' input-file')
exit(1)

myhtml_pd = pd.read_html(sys.argv[1])
#In [25]: len(myhtml_pd)
#Out[25]: 3

for i in myhtml_pd[2].index:
if i > 0:
for j in myhtml_pd[2].columns:
if j >1 and not pd.isnull(myhtml_pd[2].loc[i][j]):
print(myhtml_pd[2].loc[i][j])

HZ
-- 
https://mail.python.org/mailman/listinfo/python-list


python.exe - System Error

2021-09-30 Thread jitendrabeura001
   Hello Sir/Madam, please help me to out from this difficulties, whenever
   I'm trying to install python idle it is showing me the error called
   "[1]python.exe - System Error"**
   I have tried couple of ways to get rid out of this but failed every time,
   please please help me to find the exact solution for this problem. Thank
   You.

References

   Visible links
   1. http://python.exe/
-- 
https://mail.python.org/mailman/listinfo/python-list


Definitive guide for Regex

2021-09-30 Thread Shaozhong SHI
Dear All,

I am trying to look for a definitive guide for Regex in Python.
Can anyone help?

Regards,

David
-- 
https://mail.python.org/mailman/listinfo/python-list