Compare commits
3 Commits
8b45621a19
...
55dee42376
Author | SHA1 | Date |
---|---|---|
Fierelier | 55dee42376 | |
Fierelier | 9d5e6948a7 | |
Fierelier | f97cd553a7 |
10
example.py
10
example.py
|
@ -6,13 +6,13 @@ def main():
|
|||
# Some example code to test the functionality
|
||||
testpy = mfp.require("test")
|
||||
testpy.st = "Hello world"
|
||||
testpy.echo()
|
||||
testpy.echo() # "Hello world"
|
||||
testpy["st"] = "Hello world 2"
|
||||
testpy.echo()
|
||||
testpy.echo() # "Hello world 2"
|
||||
testpy = mfp.require("test")
|
||||
testpy.echo()
|
||||
testpy.echo() # Will still be "Hello world 2", since the library has been required before.
|
||||
testpy = mfp.dofile(mfp.p(mfp.sd,"module","test.py")) # Same file as used for mfp.require
|
||||
testpy.echo()
|
||||
testpy.echo() # Will be None, as it's a new instance of the library (dofile does not care)
|
||||
|
||||
def bootstrap(name,modName):
|
||||
if name in globals(): return
|
||||
|
@ -32,4 +32,4 @@ def bootstrap(name,modName):
|
|||
bootstrap("mfp","me.fier.python")
|
||||
init()
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
|
|
@ -34,7 +34,7 @@ def docode(st,name = "Unknown"):
|
|||
return glb
|
||||
|
||||
def dofile(path):
|
||||
return docode(open(path,encoding="utf-8").read(),path)
|
||||
return docode(open(path,"rb").read(),path)
|
||||
|
||||
def dorequire(name,*args,**kwargs):
|
||||
for path in paths:
|
||||
|
@ -78,4 +78,4 @@ def init(mod,modl,sp,d):
|
|||
programNameSet = False
|
||||
|
||||
paths.append(p(modl.sd,"module","?.py"))
|
||||
paths.append(p(modl.sd,"module","?","_main.py"))
|
||||
paths.append(p(modl.sd,"module","?","_main.py"))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
print("Running " +mfpl.s)
|
||||
print("Running new instance of " +mfpl.s)
|
||||
st = None
|
||||
def echo():
|
||||
print(st)
|
||||
print(st)
|
||||
|
|
Loading…
Reference in New Issue