Python Forum
Typical beginner needing some help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Typical beginner needing some help
#1
Hey there. So I'm fairly a beginner when it comes to python and I'm trying to reverse engineer this script to learn something
more advanced but I can't really get thru it, mainly the ((createGenericAsset Function)) bit. I can identify what's being used - function, tuple, if statement, but I can't break it apart to really understand what it's doing. If anyone could help and possibly give tips on how to break it apart and run it piece by piece to help figure it out would be amazing. I'll settle for some good documentation as well, typical if statement and tuple documentation doesn't get me far enough. Alas,...

def createGenericAsset(asset_path='', unique_name=True, asset_class=None, asset_factory=None):
    if unique_name:
        asset_path, asset_name = unreal.AssetToolsHelpers.get_asset_tools().create_unique_asset_name(base_package_name=asset_path, suffix='')
    if not unreal.EditorAssetLibrary.does_asset_exist(asset_path=asset_path):
        path = asset_path.rsplit('/', 1)[0]
        name = asset_path.rsplit('/', 1)[1]
        return unreal.AssetToolsHelpers.get_asset_tools().create_asset(asset_name=name, package_path=path, asset_class=asset_class, factory=asset_factory)
    return unreal.load_asset(asset_path)

def createGenericAsset_EXAMPLE():
    base_path = '/Game/user/tom/'
    generic_assets = [
        [base_path + 'sequence',        unreal.LevelSequence,  unreal.LevelSequenceFactoryNew()],
        [base_path + 'material',        unreal.Material,       unreal.MaterialFactoryNew()],
        [base_path + 'world',           unreal.World,          unreal.WorldFactory()],
        [base_path + 'particle_system', unreal.ParticleSystem, unreal.ParticleSystemFactoryNew()],
        [base_path + 'paper_flipbook',  unreal.PaperFlipbook,  unreal.PaperFlipbookFactory()],
        [base_path + 'data_table',      unreal.DataTable,      unreal.DataTableFactory()], # Will not work
    ]
    for asset in generic_assets:
        print createGenericAsset(asset[0], True, asset[1], asset[2])
#FootNote: Original Script written by Alex Quevillon posted on GitHub
Reply
#2
Hi, to stop the code execution at specific point you can insert the following line wherever you need:
import pdb; pdb.set_trace()
This will allow you to stop the code within the function and examine variables.


E.g.
def createGenericAsset(asset_path='', unique_name=True, asset_class=None, asset_factory=None):
    import pdb; pdb.set_trace()
    if unique_name:
Once the code stops you can type "help" command which will print available commands.
To print some variable just type it the same way you'd do in interpretter session.
If your variable is the same as some pdb command then preceed it with exclamation mark "!", for example:
!c

Here example usage once you run the program and the code stops:

Output:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 21:26:53) [MSC v.1916 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> = RESTART: C:\Users\michal\Desktop\python\3\help_regex_email\regex_email.py = > c:\users\michal\desktop\python\3\help_regex_email\regex_email.py(5)<module>() -> text = f.read() (Pdb) help Documented commands (type help <topic>): ======================================== EOF c d h list q rv undisplay a cl debug help ll quit s unt alias clear disable ignore longlist r source until args commands display interact n restart step up b condition down j next return tbreak w break cont enable jump p retval u whatis bt continue exit l pp run unalias where Miscellaneous help topics: ========================== exec pdb (Pdb) help c c(ont(inue)) Continue execution, only stop when a breakpoint is encountered. (Pdb) help q q(uit) exit Quit from the debugger. The program being executed is aborted. (Pdb) help s s(tep) Execute the current line, stop at the first possible occasion (either in a function that is called or in the current function). (Pdb) help n n(ext) Continue execution until the next line in the current function is reached or it returns. (Pdb) print("hello world") hello world (Pdb)
So I did the following after it stopped:
1. Executed "help" command
2. Executed few "help cmd" commands to output usage info about commonly used commands.
3. Executed print("hello world") just to show that you can use it just like interpretter session.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  needing some help to write some code for a game calculator rymdaksel 1 400 Jan-02-2024, 09:56 AM
Last Post: deanhystad
  Needing to Check Every Quarter Hour bill_z 10 2,987 Feb-09-2022, 07:23 PM
Last Post: menator01
  while loop typical code codefreak 2 1,954 Apr-30-2021, 01:35 PM
Last Post: Marbelous
  Noob needing guidance.... bako 0 1,852 Mar-29-2020, 06:55 PM
Last Post: bako
  Global Variables - Some Points Needing Clarification. adt 4 2,950 Nov-30-2019, 01:23 PM
Last Post: adt
  Beginner needing advice with data files JFI2019 2 2,192 Nov-06-2019, 04:56 PM
Last Post: JFI2019
  New user/beginner needing help oldDog 3 3,209 Apr-17-2018, 02:31 PM
Last Post: oldDog
  Beginner needing help! Franco 2 3,230 Jul-29-2017, 12:56 PM
Last Post: Franco

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020