get_asset_type_v001.py
import re
def get_asset_type(filename):
"""Check filename for asset type"""
global is_vfx_file, is_edit_file, proj_yy, client, show, edit_version, edit_stage, tv, pv, date, seq_nr, seq_name, shot_nr, shot_name
is_vfx_file = False
is_edit_file = False
if re.match(edit_pattern, filename): # Check if file is a edit prev
print("\nFile is an Edit prev. Filename: {}".format(filename))
proj_yy, client, show, edit_version, edit_stage, tv, pv, date, *_ = filename.split("_")
is_edit_file = True
if re.match(vfx_pattern, filename): # Check if file is a VFX prev
print("\nFile is a VFX prev. Filename: {}".format(filename))
seq_nr, seq_name, shot_nr, shot_name, *_ = filename.split("_")
is_vfx_file = True
# get_asset_type(sample_vfx_filename) # Call function to return is vfx file and print result
# print(is_vfx_file) # Check if it's a vfx file
Printing the function in the same file works like charm.
print('_'.join(list((seq_nr, seq_name, shot_nr, shot_name))))
main_programm_file_v001.py
from get_asset_type_v001 import * # Import function ti check what asset type it is
filename = sample_vfx_filename
get_asset_type(filename) # Code workes fine till this line
print('_'.join(list((seq_nr, seq_name, shot_nr, shot_name)))) # The variables in this line "seq_nr..." are making the problem
But trying to use the code from the imported function in another file raises the following error. Seems like I can't access the global var.
NameError: name 'seq_nr' is not defined
seq_nris only defined ifre.match(vfx_pattern, filename)succeeds. Did it? Check the value ofis_vfx_file.get_asset_typeshould return an object that encapsulates the information returned byfilename.split("_").is_vfx_fileinmain_programm_file_v001.pyimported from the module andis_vfx_file.seq_nritself.