Skip to content

How to import data from other files within a .k file? #1809

Closed Answered by He1pa
kubernegit asked this question in Q&A
Discussion options

You must be logged in to vote

If you want to enforce data type with a schema, you can define the data object

config: Config = Config {...} # Config is a schema

In the design of KCL, normal "variables" are all exported variables, and exported variables are immutable. So you can't config = config.config.
In addition, if you don't want to output config in the result, but reference it elsewhere, you can add the prefix '_'. So you can modify the code

_config: Config = Config {} # Config is a schema

and

import config as cfg
config = cfg._config

Does this solve your problem?

Replies: 3 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@kubernegit
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by kubernegit
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants