Here is my working python code that Im trying to replicate in nim. Getting an error.
Working python code -
#Collect information from user input.
old_file_name = input("Enter the path and name of the file name to change >") new_file_name = input("Enter the new file name >")
#Create an fstring and save the values to these variables. Use @ to separte them. change_file_name = (f"{old_file_name}@{new_file_name}")
#Extract the values from the fstring and put them into new variable names. oldname, newname = archive_file.split("@")
#Display their values. print("Old file name:", oldname) print("New File name:", newname)
nim code -
import os, strutils
echo "Enter a file's path > " let file_path = readLine(stdin)
let filesize = "fast" let filename = "image
let mydata = filename & "@" & filesize
let (newname, newsize) = mydata.split("@", 2)
echo "filename: ", newname, " filesize: ", newsize
Compiler error:
C:UsersuserDocumentsnimcodefstring.nim(11, 5) Error: 'tuple' expected
Well, split does not return a tuple, it returns a seq. So it can return any amount, and cannot ensure that it would be two.
Also, echo "Enter a file's path > " let file_path = readLine(stdin) should not be together on the same line
let splitData = mydata.split("@", 2)
let (newname, newsize) = (splitData[0], splitData[1])
Thanks, that solved the problem!
import strutils
var names = "nate@john@sally" let name_list = names.split('@') let name1 = name_list[0] let name2 = name_list[1] let name3 = name_list[2]
echo name1 echo name2 echo name3