當我在C中定義一個結構時,我可以使用scanf
函數從標準輸入中獲取和格式化數據。如何在Python中過濾和格式化來自輸入函數的數據?
例如:
struct date { int day; int month; int year;};
struct date today;
scanf("%i/%i/%i", &today.day, &today.month, &today.year)
但我怎麼能在Python得到相同的功能,如果我已經定義了一個新的類?我試圖編寫代碼,但它太長了。你能介紹一個簡單的方法嗎?
這無論如何都不會涉及到C! –
將函數寫入文件並通過'import'使用它。這將在一定程度上簡化。 – MASh