Я провел много исследований, чтобы написать этот код. Я думаю, что мне нужно решить еще одну проблему, чтобы иметь возможность преобразовать сценарий в exe-файл. Я думаю, что нашел проблему (с некоторой помощью комментариев). Но я не могу понять, как это исправить. Будем благодарны за любую помощь.
Код: Выделить всё
Traceback (most recent call last):
File "D:\MyDesktop\Trading executions Conversions\Convert_TopStepX_Orders_to_Pinescript.py", line 126, in
modify_spreadsheet(os.path.join(script_dir, xlsx_file), output_file)
~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File "", line 139, in join
File "", line 188, in _check_arg_types
TypeError: join() argument must be str, bytes, or os.PathLike object, not 'list'
Намерение состоит в том, чтобы изменить все xlsx, а затем измените все имена файлов xlsx. Для этого, я думаю, код составляет список файлов, которые нужно изменить, а затем циклически просматривает этот список.
Но код не ищет список во второй раз — он ищет файл. Итак, я буду исследовать это, чтобы попытаться найти решение. Но если кто-нибудь здесь может помочь, это было бы здорово.
Спасибо Джону Гордону за то, что помог мне дойти до этого момента!
Вот раздел сценария, вызывающего проблемы:
Код: Выделить всё
# Get the script directory
script_dir = os.path.dirname(__file__)
# Create the output folder if it doesn't exist
output_folder = os.path.join(script_dir, "Trade Executions Scripts")
os.makedirs(output_folder, exist_ok=True)
def modify_spreadsheet(input_file, output_file):
# Read the Excel file
df = pd.read_excel(input_file)
# Remove rows with "cancelled by system" or "cancelled by trader" in any cell
df = df[~df.apply(lambda row: row.astype(str).str.contains('cancelled by system|cancelled by trader|Maximum position exceeded', case=False).any(), axis=1)]
# Convert the date and time column to the desired format
df.iloc[:, 9] = pd.to_datetime(df.iloc[:, 9]).apply(lambda x: f"{x.year}, {x.month}, {x.day}, {x.hour}, {x.minute}, {x.second}")
# Save the updated spreadsheet without header\title row
df.to_excel(output_file, index=False, header=False)
# Get the list of all xlsx files in the input directory
xlsx_file = [file for file in os.listdir(output_folder) if file.endswith(".xlsx")]
xlsx_files = [f for f in os.listdir(script_dir) if f.endswith(".xlsx")]
# Loop over the xlsx files and modify them
for xlsx_file in xlsx_files:
input_file = os.path.join(script_dir, xlsx_file)
output_file = os.path.join(output_folder, f"{os.path.splitext(xlsx_file)[0]}_modified.xlsx")
# Call the function
modify_spreadsheet(os.path.join(script_dir, xlsx_file), output_file)
print(f"Modified {xlsx_file} and saved to {output_file}")
Но у меня возникла проблема все еще остается. Изменения теперь привели к возникновению проблемы при запуске сценария на Python (что является бонусом, поскольку мне не нужно конвертировать его в exe-файл, чтобы воспроизвести ошибку).
Подробнее здесь: https://stackoverflow.com/questions/791 ... bytes-or-o