Hi,
First of all thank you for this module, it really makes it easy to do functional programming within python.
However, I have an issue, which appears to be in the .tolist() method. Here's the short code I have to reproduce the issue:
import os
from infixpy import *
from bisect import bisect
basePath = "/tmp"
def get_file_names(directory, file_name_prefix = None, file_name_suffix = None):
files = os.listdir(directory)
return (Seq(files)
.filter(lambda x: not file_name_prefix or x.startswith(file_name_prefix))
.filter(lambda x: not file_name_suffix or x.endswith(file_name_suffix))
.map(lambda x: x if not file_name_prefix else x.removeprefix(file_name_prefix))
.map(lambda x: x if not file_name_suffix else x.removesuffix(file_name_suffix))
.sort()
.tolist())
videos = get_file_names(f"{basePath}/videos", "video_", ".mkv")
events = get_file_names(f"{basePath}/events", "event_")
# here be dragons
print(videos)
...
it throws this:
Traceback (most recent call last):
File "/home/my/dev/src/test.py", line 20, in <module>
print(videos)
File "/home/my/dev/my-env/lib/python3.12/site-packages/infixpy/__init__.py", line 291, in __repr__
return self.listrepr(self._list)
^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: IList.listrepr() takes 1 positional argument but 2 were given
but when I change the code to this (basically removing .tolist() and wrapping the entire return value into a new list), then everything works:
import os
from infixpy import *
from bisect import bisect
basePath = "/tmp"
def get_file_names(directory, file_name_prefix = None, file_name_suffix = None):
files = os.listdir(directory)
return list(Seq(files)
.filter(lambda x: not file_name_prefix or x.startswith(file_name_prefix))
.filter(lambda x: not file_name_suffix or x.endswith(file_name_suffix))
.map(lambda x: x if not file_name_prefix else x.removeprefix(file_name_prefix))
.map(lambda x: x if not file_name_suffix else x.removesuffix(file_name_suffix))
.sort())
videos = get_file_names(f"{basePath}/videos", "video_", ".mkv")
events = get_file_names(f"{basePath}/events", "event_")
# print(vars(videos),vars(events))
# now, print works
print(videos)
...
I'm probably doing something obviously wrong, but I can't figure out what exactly it is...
Thanks in advance for any help :)
Cheers
Hi,
First of all thank you for this module, it really makes it easy to do functional programming within python.
However, I have an issue, which appears to be in the
.tolist()method. Here's the short code I have to reproduce the issue:it throws this:
but when I change the code to this (basically removing
.tolist()and wrapping the entire return value into a new list), then everything works:I'm probably doing something obviously wrong, but I can't figure out what exactly it is...
Thanks in advance for any help :)
Cheers