此代碼無誤地運行。但是在函數find_available_filenumber
中,變量render_folder
未被聲明。所以我的問題是爲什麼這不會產生錯誤?爲什麼我的一個變量不需要聲明而另一個呢?
如果我刪除full_filename
作爲參數,我得到的錯誤:
UnboundLocalError: local variable 'full_filename' referenced before assignment.
我不明白爲什麼這不也與render_folder
發生,下面我的代碼示例:
import bpy
import os
#Functions
def find_available_filenumber(full_filename):
file_number = 1
while os.path.exists(render_folder + "\\" + full_filename):
file_number += 1
full_filename = create_full_filename(filename, file_number)
return file_number
def create_full_filename(filename, file_number):
file_extension = ".avi"
full_filename = filename + "_" + str(file_number) + file_extension
return full_filename
#Paths and names
project_folder = "F:\\06_MotionPath_Dev\\"
os.chdir(project_folder)
render_folder = "Render\\QuickRenderAddon"
filename = bpy.context.scene.name #Returns "QuickRenderAddon"
full_filename = create_full_filename(filename, 1)
filepath = render_folder + "\\" + full_filename
available_number = find_available_filenumber(full_filename)
print("Avail nmb: " + str(available_number))