# python中如何修改DataTable的源文件的值，也即将csv导出为DT表后，清除DT表的源文件依赖 

**URL:** <https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894>\
**Category:** Platform & Builds\
**Tags:** unreal-engine, Epic-Pro-Support, question\
**Created:** [December 1, 2025, 1:43pm UTC](https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894 "2025-12-01T13:43:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [December 1, 2025, 1:43pm UTC](https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894/1 "2025-12-01T13:43:29Z")

</div>

import unreal

import sys

import os

import re

def UpdateDT(fpath,dpath,structPath,logFile):

```
task \= unreal.AssetImportTask()

task.filename \= fpath

task.destination\_path \= dpath

task.replace\_existing \= True

task.automated \= True

task.save \= True

csv\_factory \= unreal.CSVImportFactory()

\# csv\_factory.automated\_import\_settings.import\_row\_struct \= unreal.load\_object(None, r'/Script/SPGameFramework.SP\_AudioConfigV1Set')

csv\_factory.automated\_import\_settings.import\_row\_struct \= unreal.load\_object(None, structPath)

task.factory \= csv\_factory

asset\_tools \= unreal.AssetToolsHelpers.get\_asset\_tools()

asset\_tools.import\_asset\_tasks(\[task])

asset\_paths \= task.get\_editor\_property("imported\_object\_paths")

success \= asset\_paths and len(asset\_paths) \> 0

return success

```

---

<div class="post-metadata">

**Author:** ![tuo.chen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tuo.chen](https://forums.unrealengine.com/u/tuo.chen)\
**Post date:** [December 2, 2025, 8:52am UTC](https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894/2 "2025-12-02T08:52:21Z")

</div>

您好，是指去掉 assetimportinfo 里面的 sourcedata 吗？如果是的话，这一项并没有暴露给蓝图（python）

如果要修改的话需要自己写一个FunctionLibrary，在python中调用​

---

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [December 2, 2025, 8:59am UTC](https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894/3 "2025-12-02T08:59:24Z")

</div>

是的，需要实现类似在编辑器中的“数据表格细节”中的“源文件”处点右侧的×的效果，这个方便提供脚本吗？ [Image Removed]

---

<div class="post-metadata">

**Author:** ![tuo.chen](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@tuo.chen](https://forums.unrealengine.com/u/tuo.chen)\
**Post date:** [December 2, 2025, 9:58am UTC](https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894/4 "2025-12-02T09:58:38Z")

</div>

```auto
// h
 
UCLASS()
class TEST560_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
	
	UFUNCTION(BlueprintCallable)
	static bool ClearDataTableSourceFileInfo(UDataTable* InDataTable, int32 Index = 0);
};
 
 
// cpp
bool UMyBlueprintFunctionLibrary::ClearDataTableSourceFileInfo(UDataTable* InDataTable, int32 Index)
{
	UAssetImportData* ImportData = InDataTable->AssetImportData;
	if (ImportData && ImportData->SourceData.SourceFiles.IsValidIndex(Index))
	{
		//Clear the filename, Hash and timestamp. Leave the Display label.
		ImportData->SourceData.SourceFiles[Index].RelativeFilename = FString();
		ImportData->SourceData.SourceFiles[Index].FileHash = FMD5Hash();
		ImportData->SourceData.SourceFiles[Index].Timestamp = 0;
		ImportData->GetOutermost()->MarkPackageDirty();
	}
	else
	{
		return false;
	}
 
    return true;
}

```

类似这样的吧，然后​在python中调用

UpdateDT(fpath, dpath,structPath)

dt = unreal.load\_object(None, ‘/Game/csvtest’)

unreal.MyBlueprintFunctionLibrary.clear\_data\_table\_source\_file\_info(dt)

unreal.EditorLoadingAndSavingUtils.save\_packages([dt.get\_outermost()], True)

---

<div class="post-metadata">

**Author:** ![anonymous-edc](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous-edc](https://forums.unrealengine.com/u/anonymous-edc)\
**Post date:** [December 12, 2025, 10:48am UTC](https://forums.unrealengine.com/t/python-datatable-csv-dt-dt/2688894/5 "2025-12-12T10:48:01Z")

</div>

感谢，问题已经成功解决了
