I'm running a python2 script and a particular part of it showes NameError. This is the code:
enter image description here
I got this error:
File"pwd/run.py", line 579, in
cnslink,
NameError: name 'cnslink' is not defined
how can I fix this error without destroying the original code?!
'cnslink' is defined in another part of the code but I think it was defined in a particular class so it can't use it now.
Related
I am working on Android9 AOSP, when I add a permission in my platform_app.te (located in /system/sepolicy/public/platform_app.te), my build fails.
system/sepolicy/public/platform_app.te:10:"ERROR 'unknown type xyz_service' at token ';' on line "
The permission that am adding is allow platform_app xyz_service:binder { call transfer };
Background on xyz_service:-
It is a service started by init and its '.te' file is located in /system/sepolicy/vendor/xyz_service.te
One reason I could think of is that the xyz_service.te resides in /system/sepolicy/vendor while the other file is in /system/sepolicy/public. Moving it to /public from /vendor gives more issues. And of-course you cannot have the files in both locations as it results in 'Duplicate declaration of type' error. Can anyone please guide me, thanks!
xyz_service type is defined in /system/sepolicy/vendor/xyz_service.te and you are trying to access it from system/sepolicy/public/platform_app.te where it's not accessible. please check file.te available in system/sepolicy/public and defined xyz_service type in this file.te to get access in system/sepolicy/public/platform_app.te.
I am trying to write Python 2.7 code that will
Dynamically load a list / array of modules from a config file at startup
Call functions from those modules. Those functions are also designated in a config file (maybe the same config file, maybe a different one).
The idea is my code will have no idea until startup which modules to load. And the portion that calls the functions will have no idea which functions to call and which modules those functions belong to until runtime.
I'm not succeeding. A simple example of my situation is this:
The following is abc.py, a module that should be dynamically loaded (in my actual application I would have several such modules designated in a list / array in a config file):
def abc_fcn():
print("Hello World!")
def another_fcn():
print("BlahBlah")
The following is the .py code which should load abc.py (my actual code would need to import the entire list / array of modules from the config file). Both this .py file and abc.py are in the same folder / directory. Please note comments next to each statement.
module_to_import = "abc" #<- Will normally come from config file
fcn_to_call = "abc.abc_fcn" #<- Will normally come from config file
__import__(module_to_import) #<- No error
print(help(module_to_import)) #<- Works as expected
eval(fcn_to_call)() #<- NameError: name 'abc' is not defined
When I change the second line to the following...
fcn_to_call = "abc_fcn"
...the NameError changes to "name 'abc_fcn' is not defined".
What am I doing wrong? Thanks in advance for the help!
__import__ only returns the module specified, it does not add it to the global namespace. So to accomplish what you want, save the result as a variable, and then dynamically retrieve the function that you want. That could look like
fcn_to_call = 'abc_fcn'
mod = __import__(module_to_import)
func = getattr(mod, fcn_to_call)
func()
On a side note, abc is the name of name of the Abstract Base Classes builtin Python module, although I know you were probably just using this an example.
You should assign the returning value of __import__ to a variable abc so that you can actually use it as a module.
abc = __import__(module_to_import)
I'm working on a relatively large SML codebase. It was originally written to compile with MLton, but I'm now working with it under SML/NJ. I need to use RedBlackMapFn, which is defined in smlnj-lib.cm. However, I get an error:
elaborate/elaborate-bomenv.fun:9.20-9.27 Error: unbound signature: ORD_KEY
elaborate/elaborate-bomenv.fun:14.21-14.40 Error: unbound functor: RedBlackMapFn
elaborate/elaborate-bomenv.fun:32.20-32.27 Error: unbound signature: ORD_KEY
elaborate/elaborate-bomenv.fun:37.21-37.40 Error: unbound functor: RedBlackMapFn
So I assume that smlnj-lib.cm is not being pulled by CM. In an effort to fix this, I added $/smlnj-lib.cm to the sources.cm file in the directory that I'm working in. This causes a separate issue:
elaborate/sources.cm:25.1-25.18 Error: structure Random imported from $SMLNJ-LIB/Util/smlnj-lib.cm#243997(random.sml) and also from ./(sources.cm):lib/(sources.cm):basic/(sources.cm):random.sml
elaborate/sources.cm:25.1-25.18 Error: structure Queue imported from $SMLNJ-LIB/Util/smlnj-lib.cm#436143(queue.sml) and also from ./(sources.cm):lib/(sources.cm):basic/(sources.cm):two-list-queue.sml
No dice. I tried removing the Random structure that's coming from ./(sources.cm):lib/(sources.cm):basic/(sources.cm):random.sml, but it appears that it isn't equivalent to the one defined in the standard library, so I can't just substitute one for the other.
I'd like to use something like Python's import ... from ... as ...
mechanism to give a new name to the Random that's coming from the standard library, but CM's documentation doesn't offer any hints as to how I'd go about that.
How can I resolve a module naming conflict across multiple SML files?
I ended up splitting off the problematic file in to a separate .cm. The problem file here is elaborate-bomenv.{sig, fun}. The .cm file for this directory is sources.cm, which caused errors when it looked like:
Group
...
is
$/basis.cm
...
elaborate-bomenv.fun
elaborate-bomenv.sig
...
So instead, I made an elaborate-bomenv-sources.cm that looks like:
Group
signature ELABORATE_BOMENV
functor BOMEnv
is
$/smlnj-lib.cm
...
elaborate-bomenv.sig
elaborate-bomenv.fun
and changed the original sources.cm to read:
Group
...
is
$/basis.cm
...
./elaborate-bomenv-sources.cm
...
Which is ugly, but it works.
I am facing a weird error within my codebase currently. You can see the full ZF2s project code on my github right here. <- there's a link
I'm having a Module set up with two Entities (X and Y). Entity_X contains a reference to Entity_Y via (targetEntity="Entity_Y"). The Error persist with the FQCN or just the CN itself.
Entity_X:
id int PK,
id_Y int FK,
text varchar
Entity_Y:
id int PK,
text varchar
When loading Entity_Y first and then Entity_X everything is working fine. This remains true for both StandardAutoloader and ClassMapAutoloader. However: when loading Entity_X first with ClassMapAutoloader present, i will be seeing the following error:
Fatal error: Cannot redeclare class Kennzahlen\Entity\Referenzwert (Entity_Y)
in \module\Kennzahlen\src\Kennzahlen\Entity\Referenzwert.php
on line 13
Loading Entity_X first with StandardAutoloader works without any problems, too.
Update
The Problem appears to be within ZF2s ClassMapAutoloader (or Autoloading-Mechanism in General). My Module used the ClassMapAutoloader and using this i've gotten the above mentioned error. When removing the ClassMapAutoloader and simply using the StandardAutoloader, the error vanished into thin air. Thanks to #ocramius and all others i've botheres with this :)
I'm writing a failing test case to try and solve this in doctrine/common. The problem seems to be that silent autoloaders (as explained by #Xerkus) are not compatible with doctrine/common itself. To solve that, use a StandardAutoloader from ZF2 (or from composer) instead of using the ClassMapAutoloader. This will solve the issue until a patch is ready.
Update: patch is being suggested at doctrine/common#216
i have no knowledge of doctrine, but i browsed through source and i think i found issue:
https://github.com/doctrine/common/blob/master/lib/Doctrine/Common/ClassLoader.php#L224
here, this code expects that autoloader will return value evaluated to true, but that is not requirement of spl autoload mechanism, therefore autoloader can return NULL,
To check if i am correct, in in your project in doctrine replace line 224 in Doctrine/Common/ClassLoader.php
} else if ($loader[0]->{$loader[1]}($className)) {
with
} else if ($loader[0]->{$loader[1]}($className) && class_exists($className, false)) {
Ans see if issue is fixed, if i am correct - then report bug to doctrine project
I have a component named MyComponent with the following folder structure in RTC:
/MyProject
/MyProject/TestFile.txt
/MyProject/Folder1
/MyProject/Folder1/loadrules.txt
/MyProject/Folder1/TestFile2.txt
And this is what I have in my loadrules.txt file::
versionableName=/MyProject/TestFile.txt
I've specified the loadrules.txt file in my build definition for this component as the component load rule, but when the build runs, I'm getting the following exception when it tries to fetch the files:
com.ibm.team.repository.common.TeamRepositoryException: Unexpected line "versionableName=/MyProject/TestFile.txt" encountered in build load rules for component "MyComponent"
at com.ibm.team.filesystem.client.internal.load.LoadRule.getRules(LoadRule.java:176)
at com.ibm.team.filesystem.client.internal.load.LoadRule.addLoadRules(LoadRule.java:101)
at com.ibm.team.build.internal.scm.ComponentLoadRules.getLoadRules(ComponentLoadRules.java:134)
at com.ibm.team.build.internal.engine.JazzScmPreBuildParticipant.preBuild(JazzScmPreBuildParticipant.java:235)
at com.ibm.team.build.internal.engine.BuildLoop.invokePreBuildParticipants(BuildLoop.java:844)
at com.ibm.team.build.internal.engine.BuildLoop$2.run(BuildLoop.java:650)
at java.lang.Thread.run(Thread.java:662)
Any idea what I'm doing wrong? I've tried following the example here but I can't figure why it's not working for me. Regardless of what I put in the loadrules.txt file (nothing/empty string, random garbage text, etc.), I still get this exception for the first line of the file.
This is in RTC 3.0
This kind of error is likely to be an encoding issue.
One way to test that is to create the loadrules.txt through the scm command-line interface, as detailed in "Reference > Source control command line reference > scm > create"
scm create loadrules [options]
The OP holic87 confirms:
I just used Notepad++ to recreate the text file and it's working as expected now.