Hi there! You are currently browsing as a guest. Why not create an account? Then you get less ads, can thank creators, post feedback, keep a list of your favourites, and more!
Test Subject
Original Poster
#1 Old 30th Sep 2014 at 10:15 AM
Python script to automate packaging of script mods.
Here is a simply utility I made for myself.

Place it in a directory with your .py script or scripts, double-click, and create packages with optimized .pyo code, no fuss.

Creates one .zip package per one .py script. If PACK_WITH_CODE is set to True (default), includes the .py sources.

If a .txt file is present with the same name as the .py script, the .txt file is included in the created .zip package as well.

Source: (save with a .pyw extension, otherwise it will create a package for itself)

Code:
#!python3.3
import glob
import os.path
import zipfile

PACK_WITH_CODE = True

if (__name__ == '__main__'):
    file_list = glob.glob('*.py')
    file_list.sort()
    for file_py in file_list:
        file_zip = file_py.replace('.py', '.zip')
        file_txt = file_py.replace('.py', '.txt')
        
        arch_zip = zipfile.PyZipFile(file_zip, 'w', zipfile.ZIP_DEFLATED, False, 1)
        
        if (PACK_WITH_CODE):
            arch_zip.write(file_py)
        
        arch_zip.writepy(file_py)

        if (os.path.isfile(file_txt)):
            arch_zip.write(file_txt)
        
        arch_zip.close()
1 users say thanks for this. (Who?)
Advertisement
Pettifogging Legalist!
retired moderator
#2 Old 1st Oct 2014 at 3:07 PM
Moving to Tools.

Stuff for TS2 · TS3 · TS4 | Please do not PM me with technical questions – we have Create forums for that.

In the kingdom of the blind, do as the Romans do.
Mad Poster
#3 Old 8th Jul 2016 at 12:50 AM
Sorry to revive an old thread but I am brand new to python and I am trying to compile a .py file to .pyo. I cannot for the life of me understand what I am supposed to do. I do not speak computer code.
How am I supposed to make the code, given here, function? I don't understand how to create the .pyw file to begin with. I tried copying the code into IDLE and saving it but when I double click the resulting file, nothing happens.
I should have gone to bed over an hour ago.

My deviantART, MTS Yearbook Origin ID = Alistu
Ms. Byte (Deceased)
#4 Old 9th Jul 2016 at 1:34 PM
I know zilch about Python myself but found this: http://www.thecodingforums.com/thre...from-py.346147/

Questions about Python are more likely to be answered in the Modding Discussion forum.

Please do not PM me with mod, tutorial, or general modding questions or problems; post them in the thread for the mod or tutorial or post them in the appropriate forum.

Visit my blogs for other Sims content:
Online Sims - general mods for Sims 3
Offline Sims - adult mods for Sims 3 and Sims 4
Mad Poster
#5 Old 9th Jul 2016 at 3:52 PM
Doesn't seem to matter how I enter the command, I just get Syntax errors returned to me.
I'll see if I can find help in the Modding Discussion forum.

My deviantART, MTS Yearbook Origin ID = Alistu
Instructor
#6 Old 9th Jul 2016 at 4:35 PM Last edited by azoresman : 9th Jul 2016 at 5:07 PM.
Quote: Originally posted by Menaceman44
Doesn't seem to matter how I enter the command, I just get Syntax errors returned to me.
I'll see if I can find help in the Modding Discussion forum.

@Menaceman44 Here take it make a folder somewhere extract this inside and any py file you wish to compile... double click pytopyo and you'l have a zip with compiled code and the source code too.

If your code contains errors compiler will fail.
Attached files:
File Type: rar  pytopyo.rar (376 Bytes, 218 downloads) - View custom content
Mad Poster
#7 Old 10th Jul 2016 at 8:18 PM Last edited by Menaceman44 : 10th Jul 2016 at 8:28 PM.
I have python 3.5 installed and this won't run because it tells me it can't find python 3.3. I have no idea how to get version 3.3 and, for the time being at least, have come to the end of my tether with this so I'm giving up. I do appreciate the help though.

My deviantART, MTS Yearbook Origin ID = Alistu
Instructor
#8 Old 10th Jul 2016 at 11:41 PM Last edited by azoresman : 11th Jul 2016 at 12:02 AM.
Quote: Originally posted by Menaceman44
I have python 3.5 installed and this won't run because it tells me it can't find python 3.3. I have no idea how to get version 3.3 and, for the time being at least, have come to the end of my tether with this so I'm giving up. I do appreciate the help though.

It should work with 3.5.
Question: Did you set up the working path for python?

Look at the picture: Go to My computer > Properties > Advanced > System Variables

Append your python installation path to the existing list.... That's it.

For Python 3.3.4 go here Python 3.3.4

And remember to never give up
Screenshots
Mad Poster
#9 Old 11th Jul 2016 at 6:01 PM
I didn't know anything about needing to change or set up working paths. I have never worked with coding in my life before attempting to use python recently.

My deviantART, MTS Yearbook Origin ID = Alistu
Instructor
#10 Old 11th Jul 2016 at 9:54 PM
Quote: Originally posted by Menaceman44
I didn't know anything about needing to change or set up working paths. I have never worked with coding in my life before attempting to use python recently.

Yeah, tell me if it started working after that
By the way python is at 3.3.6 version for 3.3 series so ignore when i said 3.3.4 it has some bug corrections so install the latest 3.3.x
Test Subject
#11 Old 14th Jan 2017 at 4:41 PM
non-working the script after the mod is not working
Test Subject
#12 Old 24th Sep 2017 at 2:56 AM
This post helped me very much, but i had to change the code to make it work for me (Python 3.6).

To be fair, i had just to change the required version.

In addition i have added:
  • Pack all code files in the directory in 1 archive
  • Name the archive "MyModName" (can be edited by changing the global)
  • Instad of using .zip, use .ts4script as extension
I hope this helps someone as much as it did me. You do not have to change anything to make it work for you, as long as you have python 3.6.x installed.
Attached files:
File Type: zip  compileProject.zip (491 Bytes, 130 downloads) - View custom content
Back to top