Python Forum
Can copyright be applied python scripts?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can copyright be applied python scripts?
#4
You can work with importlib.ressources, which is not so painful.

C:\Users\Admin\Desktop\example_with_ressources    
λ tree /F                                         
Auflistung der Ordnerpfade                        
Volumeseriennummer : 6CC1-07AC                    
C:.                                               
│   test.py                                       
│   test.spec                                     
│                                                 
└───data                                          
        test1.txt                                 
        test2.txt                                 
        test3.txt                                 
        __init__.py                               
                                                  
test.py
from importlib import resources
import data # <- import of package with data files


with resources.path(data, 'test1.txt') as p:
    print(p, type(p)) # <- pathlib object
    print(p.read_text())
    

print(resources.read_text(data, 'test2.txt'))
print(resources.read_text(data, 'test3.txt'))
test.spec
# -*- mode: python ; coding: utf-8 -*-                        
                                                              
block_cipher = None                                           
                                                              
                                                              
a = Analysis(['test.py'],                                     
             pathex=['.'],                                    
             binaries=[],                                     
             datas=[                                          
                ('data/test1.txt', 'data'),                   
                ('data/test2.txt', 'data'),                   
                ('data/test3.txt', 'data'),                   
             ],                                               
             hiddenimports=[],                                
             hookspath=[],                                    
             runtime_hooks=[],                                
             excludes=[],                                     
             win_no_prefer_redirects=False,                   
             win_private_assemblies=False,                    
             cipher=block_cipher,                             
             noarchive=False)                                 
pyz = PYZ(a.pure, a.zipped_data,                              
             cipher=block_cipher)                             
exe = EXE(pyz,                                                
          a.scripts,                                          
          a.binaries,                                         
          a.zipfiles,                                         
          a.datas,                                            
          [],                                                 
          name='test',                                        
          debug=False,                                        
          bootloader_ignore_signals=False,                    
          strip=False,                                        
          upx=True,                                           
          upx_exclude=[],                                     
          runtime_tmpdir=None,                                
          console=True )                                      
                                                              
The variable datas must be edited to copy non-python files into the executable file.
Running the creation of exe-file:

Result:
Output:
C:\Users\Admin\Desktop\example_with_ressources λ dist\test.exe C:\Users\Admin\AppData\Local\Temp\_MEI110682\data\test1.txt <class 'pathlib.WindowsPath'> test x Hi
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
RE: Can copyright be applied python scripts? - by DeaD_EyE - Sep-04-2019, 12:20 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  embedded Python scripts - is it worthwhile Skaperen 3 677 Feb-21-2024, 01:25 AM
Last Post: Skaperen
  images and pixels in typical Python scripts Skaperen 0 1,244 Oct-14-2021, 12:29 AM
Last Post: Skaperen
  copyright in docstr? Skaperen 5 2,565 Apr-30-2021, 01:52 PM
Last Post: Gribouillis
  Creating Python scripts in Visual Studio Code Sanjish 4 2,606 Dec-22-2020, 12:32 PM
Last Post: snippsat
  suid scripts in python? Skaperen 0 2,157 Sep-29-2019, 10:28 PM
Last Post: Skaperen
  Finding Scripts for Python Johnny1998 1 2,208 Jul-31-2019, 08:07 PM
Last Post: Yoriz
  embedding Python script in shell scripts Skaperen 5 8,291 Mar-23-2018, 01:07 AM
Last Post: Skaperen
  Python 2.7.14 install on Windows missing Scripts directory and pip #bug bluejedi 4 16,494 Dec-15-2017, 04:12 PM
Last Post: bluejedi

Forum Jump:

User Panel Messages

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