Re: REPL with multiple function definitions

2022-06-26 Thread Roel Schroeven

Rob Cliffe via Python-list schreef op 27/06/2022 om 0:14:

This 2-line program

def f(): pass
def g(): pass

runs silently (no Exception).  But:

23:07:02 c:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
  >>> def f(): pass
... def g(): pass
    File "", line 2
      def g(): pass
      ^
SyntaxError: invalid syntax
  >>>

Is there a good reason for this?
The REPL requires an extra empty line to indicate the end of multi-line 
constructs. You can see it by the prompt: as long as the REPL prints 
'... '  as prompt, that means it puts everything you type in the same 
multi-line construct. To enter a new multi-line construct (such as a 
function definition, a for-loop, an if-statement, ...), press enter 
directly at the prompt; the REPL should than use '>>> ' as the prompt again.


(Alternatives like IPython (https://ipython.readthedocs.io/en/stable/) 
are a bit more loose regarding how to enter multi-line constructs)


--
"Iceland is the place you go to remind yourself that planet Earth is a
machine... and that all organic life that has ever existed amounts to a greasy
film that has survived on the exterior of that machine thanks to furious
improvisation."
-- Sam Hughes, Ra

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


Re: REPL with multiple function definitions

2022-06-26 Thread Chris Angelico
On Mon, 27 Jun 2022 at 08:15, Rob Cliffe via Python-list
 wrote:
>
> This 2-line program
>
> def f(): pass
> def g(): pass
>
> runs silently (no Exception).  But:
>
> 23:07:02 c:\>python
> Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32
> bit (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>  >>> def f(): pass
> ... def g(): pass
>File "", line 2
>  def g(): pass
>  ^
> SyntaxError: invalid syntax
>  >>>
>
> Is there a good reason for this?

The REPL compiles one statement at a time. A file is allowed to
contain multiple statements.

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


REPL with multiple function definitions

2022-06-26 Thread Rob Cliffe via Python-list

This 2-line program

def f(): pass
def g(): pass

runs silently (no Exception).  But:

23:07:02 c:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 
bit (Intel)] on win32

Type "help", "copyright", "credits" or "license" for more information.
>>> def f(): pass
... def g(): pass
  File "", line 2
    def g(): pass
    ^
SyntaxError: invalid syntax
>>>

Is there a good reason for this?
Thanks
Rob Cliffe
--
https://mail.python.org/mailman/listinfo/python-list


Re: why this code giving recursion error????

2022-06-26 Thread dn
On 26/06/2022 23.00, נתי שטרן wrote:
> I FIXED THE CODE 

For the benefit of future-readers: how did you go about fixing it? What
was wrong?

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


Re: why this code giving recursion error????

2022-06-26 Thread נתי שטרן
I FIXED THE CODE

‫בתאריך יום א׳, 26 ביוני 2022 ב-13:57 מאת ‪dn‬‏ <‪
pythonl...@danceswithmice.info‬‏>:‬

> On 26/06/2022 22.48, נתי שטרן wrote:
> > def compile(p, flags=0):
> > # internal: convert pattern list to internal format
> >
> > if (isinstance(p,str)):
> > pattern = p
> > p = sre_parse.parse(p, flags)
> > else:
> > pattern = None
> >
> > code = _code(p, flags)
> >
> > if flags & SRE_FLAG_DEBUG:
> > print()
> > dis(code)
> >
> > # map in either direction
> > groupindex = p.state.groupdict
> > indexgroup = [None] * p.state.groups
> > for k, i in groupindex.items():
> > indexgroup[i] = k
> >
> > return sre_compile.compile(
> > pattern, flags | p.state.flags, code,
> > p.state.groups-1,
> > groupindex, tuple(indexgroup)
> > )
>
>
> Why would any code give a recursion error?
>
> With recursion problems, the first question to ask is: how does this
> thing stop?
>
> Have you built some test-data with only a handful of items, and thus a
> predictable result. Does that result occur? If not, where are the
> differences occurring?
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>


-- 

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


Re: why this code giving recursion error????

2022-06-26 Thread נתי שטרן
and i ask also what's the problem with this function:


def _code(p, flags):

flags = p.state.flags | flags
code = []

# compile info block
sre_compile._compile_info(code, p, flags)

# compile the pattern
sre_compile._compile(code, p.data, flags)

code.append(SUCCESS)

return code


‫בתאריך יום א׳, 26 ביוני 2022 ב-13:48 מאת נתי שטרן <‪nsh...@gmail.com‬‏>:‬

> def compile(p, flags=0):
> # internal: convert pattern list to internal format
>
> if (isinstance(p,str)):
> pattern = p
> p = sre_parse.parse(p, flags)
> else:
> pattern = None
>
> code = _code(p, flags)
>
> if flags & SRE_FLAG_DEBUG:
> print()
> dis(code)
>
> # map in either direction
> groupindex = p.state.groupdict
> indexgroup = [None] * p.state.groups
> for k, i in groupindex.items():
> indexgroup[i] = k
>
> return sre_compile.compile(
> pattern, flags | p.state.flags, code,
> p.state.groups-1,
> groupindex, tuple(indexgroup)
> )
>
>
> --
> 
>


-- 

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


Re: why this code giving recursion error????

2022-06-26 Thread dn
On 26/06/2022 22.48, נתי שטרן wrote:
> def compile(p, flags=0):
> # internal: convert pattern list to internal format
> 
> if (isinstance(p,str)):
> pattern = p
> p = sre_parse.parse(p, flags)
> else:
> pattern = None
> 
> code = _code(p, flags)
> 
> if flags & SRE_FLAG_DEBUG:
> print()
> dis(code)
> 
> # map in either direction
> groupindex = p.state.groupdict
> indexgroup = [None] * p.state.groups
> for k, i in groupindex.items():
> indexgroup[i] = k
> 
> return sre_compile.compile(
> pattern, flags | p.state.flags, code,
> p.state.groups-1,
> groupindex, tuple(indexgroup)
> )


Why would any code give a recursion error?

With recursion problems, the first question to ask is: how does this
thing stop?

Have you built some test-data with only a handful of items, and thus a
predictable result. Does that result occur? If not, where are the
differences occurring?
-- 
Regards,
=dn
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: why this code giving recursion error????

2022-06-26 Thread נתי שטרן
stack trace:



 File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5387, in 
class bottle:
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5694, in bottle
class Router(object):
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 5736, in Router
rule_syntax = re.compile('(*)'
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 375, in compile
return sre_compile.compile(pattern, flags)
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2752, in compile
return sre_compile.compile(
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2752, in compile
return sre_compile.compile(
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2752, in compile
return sre_compile.compile(
  [Previous line repeated 1005 more times]
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 2736, in compile
p = sre_parse.parse(p, flags)
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1822, in parse
p = sre_parse._parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1234, in _parse_sub
itemsappend(sre_parse._parse(source, state, verbose, nested + 1,
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1708, in _parse
p = sre_parse._parse_sub(source, state, sub_verbose, nested + 1)
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1234, in _parse_sub
itemsappend(sre_parse._parse(source, state, verbose, nested + 1,
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1708, in _parse
p = sre_parse._parse_sub(source, state, sub_verbose, nested + 1)
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1234, in _parse_sub
itemsappend(sre_parse._parse(source, state, verbose, nested + 1,
  File "\\Weank-fs\users$\NetanelST\ORACLE\RTR.py", line 1707, in _parse
not (del_flags & SRE_FLAG_VERBOSE))
  File "C:\Program
Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.1520.0_x64__qbz5n2kfra8p0\lib\enum.py",
line 987, in __and__
if not isinstance(other, (self.__class__, int)):

‫בתאריך יום א׳, 26 ביוני 2022 ב-13:48 מאת נתי שטרן <‪nsh...@gmail.com‬‏>:‬

> def compile(p, flags=0):
> # internal: convert pattern list to internal format
>
> if (isinstance(p,str)):
> pattern = p
> p = sre_parse.parse(p, flags)
> else:
> pattern = None
>
> code = _code(p, flags)
>
> if flags & SRE_FLAG_DEBUG:
> print()
> dis(code)
>
> # map in either direction
> groupindex = p.state.groupdict
> indexgroup = [None] * p.state.groups
> for k, i in groupindex.items():
> indexgroup[i] = k
>
> return sre_compile.compile(
> pattern, flags | p.state.flags, code,
> p.state.groups-1,
> groupindex, tuple(indexgroup)
> )
>
>
> --
> 
>


-- 

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


why this code giving recursion error????

2022-06-26 Thread נתי שטרן
def compile(p, flags=0):
# internal: convert pattern list to internal format

if (isinstance(p,str)):
pattern = p
p = sre_parse.parse(p, flags)
else:
pattern = None

code = _code(p, flags)

if flags & SRE_FLAG_DEBUG:
print()
dis(code)

# map in either direction
groupindex = p.state.groupdict
indexgroup = [None] * p.state.groups
for k, i in groupindex.items():
indexgroup[i] = k

return sre_compile.compile(
pattern, flags | p.state.flags, code,
p.state.groups-1,
groupindex, tuple(indexgroup)
)


-- 

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