Sponsored Content
Operating Systems OS X (Apple) Back on python for the AMIGA again and discovered this little gem... Post 303036705 by wisecracker on Monday 8th of July 2019 11:46:52 AM
Old 07-08-2019
As an addendum to this thread assigning 'sys' to 'os.sys' opens up 'sys' without wasting namespace by importing 'sys' at all IF 'os' is already imported.
Demo code:
Code:
import os
print("")
print(dir(os.sys))
# import sys    # This is not needed if os is imported!

# Instead of taking up namespace by import[ing] sys, assign sys to os.sys in its place.
sys = os.sys

# A few simple 'sys' functions in action.
print("")
print(sys.platform)
print("")
print(sys.version)
print("")
print(sys.builtin_module_names)
print("")
sys.stdout.write("Hello unix.com!")
print("")
print("")
print(sys.modules)
print("")
sys.exit(10)

Results, OSX 10.14.3, default bash terminal calling python3.5...
Code:
Last login: Mon Jul  8 16:30:25 on ttys000
AMIGA:amiga~> cd Desktop/Code/Python
AMIGA:amiga~/Desktop/Code/Python> python3.5 os_sys.py

['__displayhook__', '__doc__', '__excepthook__', '__interactivehook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__', '__stdin__', '__stdout__', '_clear_type_cache', '_current_frames', '_debugmallocstats', '_getframe', '_home', '_mercurial', '_xoptions', 'abiflags', 'api_version', 'argv', 'base_exec_prefix', 'base_prefix', 'builtin_module_names', 'byteorder', 'call_tracing', 'callstats', 'copyright', 'displayhook', 'dont_write_bytecode', 'exc_info', 'excepthook', 'exec_prefix', 'executable', 'exit', 'flags', 'float_info', 'float_repr_style', 'get_coroutine_wrapper', 'getallocatedblocks', 'getcheckinterval', 'getdefaultencoding', 'getdlopenflags', 'getfilesystemencoding', 'getprofile', 'getrecursionlimit', 'getrefcount', 'getsizeof', 'getswitchinterval', 'gettrace', 'hash_info', 'hexversion', 'implementation', 'int_info', 'intern', 'is_finalizing', 'maxsize', 'maxunicode', 'meta_path', 'modules', 'path', 'path_hooks', 'path_importer_cache', 'platform', 'prefix', 'set_coroutine_wrapper', 'setcheckinterval', 'setdlopenflags', 'setprofile', 'setrecursionlimit', 'setswitchinterval', 'settrace', 'stderr', 'stdin', 'stdout', 'thread_info', 'version', 'version_info', 'warnoptions']

darwin

3.5.2 (v3.5.2:4def2a2901a5, Jun 26 2016, 10:47:25) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)]

('_ast', '_codecs', '_collections', '_functools', '_imp', '_io', '_locale', '_operator', '_signal', '_sre', '_stat', '_string', '_symtable', '_thread', '_tracemalloc', '_warnings', '_weakref', 'atexit', 'builtins', 'errno', 'faulthandler', 'gc', 'itertools', 'marshal', 'posix', 'pwd', 'sys', 'time', 'xxsubtype', 'zipimport')

Hello unix.com!

{'zipimport': <module 'zipimport' (built-in)>, '_sitebuiltins': <module '_sitebuiltins' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_sitebuiltins.py'>, 'encodings.latin_1': <module 'encodings.latin_1' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/latin_1.py'>, 'codecs': <module 'codecs' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/codecs.py'>, 'sre_compile': <module 'sre_compile' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_compile.py'>, 'os': <module 'os' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/os.py'>, '_warnings': <module '_warnings' (built-in)>, '_signal': <module '_signal' (built-in)>, 'encodings': <module 'encodings' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/__init__.py'>, '_weakrefset': <module '_weakrefset' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_weakrefset.py'>, 'builtins': <module 'builtins' (built-in)>, '_locale': <module '_locale' (built-in)>, '_imp': <module '_imp' (built-in)>, '_stat': <module '_stat' (built-in)>, 'os.path': <module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/posixpath.py'>, 'sre_parse': <module 'sre_parse' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_parse.py'>, 'genericpath': <module 'genericpath' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/genericpath.py'>, 'stat': <module 'stat' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/stat.py'>, 'sys': <module 'sys' (built-in)>, '_frozen_importlib_external': <module '_frozen_importlib_external' (frozen)>, '_codecs': <module '_codecs' (built-in)>, 'sysconfig': <module 'sysconfig' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sysconfig.py'>, '_osx_support': <module '_osx_support' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_osx_support.py'>, '_frozen_importlib': <module '_frozen_importlib' (frozen)>, '_sre': <module '_sre' (built-in)>, 'abc': <module 'abc' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/abc.py'>, 'encodings.aliases': <module 'encodings.aliases' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/aliases.py'>, '_bootlocale': <module '_bootlocale' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_bootlocale.py'>, '_io': <module 'io' (built-in)>, 're': <module 're' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/re.py'>, 'marshal': <module 'marshal' (built-in)>, '_sysconfigdata': <module '_sysconfigdata' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_sysconfigdata.py'>, 'copyreg': <module 'copyreg' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/copyreg.py'>, '_thread': <module '_thread' (built-in)>, 'encodings.utf_8': <module 'encodings.utf_8' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/encodings/utf_8.py'>, 'posixpath': <module 'posixpath' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/posixpath.py'>, 'io': <module 'io' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/io.py'>, 'sre_constants': <module 'sre_constants' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/sre_constants.py'>, 'errno': <module 'errno' (built-in)>, '__main__': <module '__main__' from 'os_sys.py'>, 'posix': <module 'posix' (built-in)>, '_weakref': <module '_weakref' (built-in)>, 'site': <module 'site' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site.py'>, '_collections_abc': <module '_collections_abc' from '/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/_collections_abc.py'>}

AMIGA:amiga~/Desktop/Code/Python> echo $?
10
AMIGA:amiga~/Desktop/Code/Python> _

 

5 More Discussions You Might Find Interesting

1. What is on Your Mind?

A journey down memory lane - AMIGA...

Hi guys and gals... Who still plays with the AMIGA in any of its guises? I have a classic A1200(HD) on 24/7 and still build and code for it... Also _clones_ of the same machine using WinUAE and E-UAE... It still has that one major beauty for this 62 year old - moi - it is FUN! ;o) (2 Replies)
Discussion started by: wisecracker
2 Replies

2. What is on Your Mind?

Ah, the AMIGA, (another poem I wrote in 2005).

Well I wrote this in 2005 and uploaded to AMINET.as a commemoration of a machine that is still in use today. It is now 29 years since this machne came into being. Phenominal and it is still being supported- WOW! My A1200 is on 24/7 and I use it to test code developed on AMIGA emulators... ... (0 Replies)
Discussion started by: wisecracker
0 Replies

3. News, Links, Events and Announcements

GCC for tha AMIGA...

Hi guys... For the AMIGA fans out there... Not sure if this is the right forum but someone has done a successful working port of gcc for the classic AMIGA A1200. It contains a very large subset of *NIX commands and now AMIGA fanatics like me can include another platform, within the... (0 Replies)
Discussion started by: wisecracker
0 Replies

4. OS X (Apple)

FFT for the AMIGA through ksh88 shell.

I don't know if anyone is interested but I have been meddling with FFT for the AMIGA. (Sadly we AMIGAns don't have these luxuries through any scripting language. Below is a Python snippet that uses the builtin 'cmath' module to work with the lowly Python 2.0.1 for the AMIGA. It is part of a... (0 Replies)
Discussion started by: wisecracker
0 Replies

5. What is on Your Mind?

The AMIGA, great or flop. Your memories...

Hi everybody... Anyone who sees posts from me see the word AMIGA on my machines' terminal prompts. AMINET is the oldest Internet SW repository and currently holds 82,800+ freely available SW packages. About Aminet - AminetWiki I am a member of LAG, (Linclonshire Amiga Group), in the... (5 Replies)
Discussion started by: wisecracker
5 Replies
All times are GMT -4. The time now is 10:46 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy