Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 使用大名命名文本文件时出错_Python 3.x_String_File_Text - Fatal编程技术网

Python 3.x 使用大名命名文本文件时出错

Python 3.x 使用大名命名文本文件时出错,python-3.x,string,file,text,Python 3.x,String,File,Text,我正在尝试重命名具有以下名称的文本文件: MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9, beta_2=0.999, early_stopping=True, epsilon=1e-08, hidden_layer_sizes=(181, 181, 181), learning_rate='constant', learning_rate_init

我正在尝试重命名具有以下名称的文本文件:

MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,
       beta_2=0.999, early_stopping=True, epsilon=1e-08,
       hidden_layer_sizes=(181, 181, 181), learning_rate='constant',
       learning_rate_init=0.05, max_iter=100, momentum=0.9,
       nesterovs_momentum=True, power_t=0.5, random_state=None,
       shuffle=True, solver='adam', tol=0.0001, validation_fraction=0.1,
       verbose=False, warm_start=False)
当我复制粘贴上面的名称并尝试重命名文件时,我可以重命名它,但使用Python程序尝试相同的操作会产生错误

FileNotFoundError: [Errno 2] No such file or directory: "MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,\n       beta_2=0.999, early_stopping=True, epsilon=1e-08,\n       hidden_layer_sizes=(181, 181, 181), learning_rate='constant',\n       learning_rate_init=0.05, max_iter=100, momentum=0.9,\n       nesterovs_momentum=True, power_t=0.5, random_state=None,\n       shuffle=True, solver='adam', tol=0.0001, validation_fraction=0.1,\n       verbose=False, warm_start=False).txt"
这是我的密码:

modelDetailsAndResults = modelName+'.txt'
output_file = open(modelDetailsAndResults,"w", encoding="utf8")
output_file.write("model details:")
output_file.write(modelName)
output_file.close()

这是因为您无法重命名超过特定字符数的文件。我猜大概是251左右,但不确定。您使用的字符数太多了

您确定要用换行符和一堆特殊字符来命名文件吗?如果没有特殊字符或新字符就可以了lines@AnthonySottile我可以知道如果我删除特殊字符和新行,我怎么做吗?可能可以做一些类似re.sub的事情[^a-zA-Z0-9\,=]”,文件名,以删除该字符以外的任何字符class@AnthonySottile实际上,这不是因为特殊字符,而是因为长度。我在下面放了一个randon字符串。如果您尝试在其中再放几个字符,它将在发回时出错